1 /* 2 * QEMU SPAPR Dynamic Reconfiguration Connector Implementation 3 * 4 * Copyright IBM Corp. 2014 5 * 6 * Authors: 7 * Michael Roth <mdroth@linux.vnet.ibm.com> 8 * 9 * This work is licensed under the terms of the GNU GPL, version 2 or later. 10 * See the COPYING file in the top-level directory. 11 */ 12 13 #include "qemu/osdep.h" 14 #include "qapi/error.h" 15 #include "qapi/qmp/qnull.h" 16 #include "cpu.h" 17 #include "qemu/cutils.h" 18 #include "hw/ppc/spapr_drc.h" 19 #include "qom/object.h" 20 #include "hw/qdev.h" 21 #include "qapi/visitor.h" 22 #include "qemu/error-report.h" 23 #include "hw/ppc/spapr.h" /* for RTAS return codes */ 24 #include "hw/pci-host/spapr.h" /* spapr_phb_remove_pci_device_cb callback */ 25 #include "sysemu/device_tree.h" 26 #include "sysemu/reset.h" 27 #include "trace.h" 28 29 #define DRC_CONTAINER_PATH "/dr-connector" 30 #define DRC_INDEX_TYPE_SHIFT 28 31 #define DRC_INDEX_ID_MASK ((1ULL << DRC_INDEX_TYPE_SHIFT) - 1) 32 33 SpaprDrcType spapr_drc_type(SpaprDrc *drc) 34 { 35 SpaprDrcClass *drck = SPAPR_DR_CONNECTOR_GET_CLASS(drc); 36 37 return 1 << drck->typeshift; 38 } 39 40 uint32_t spapr_drc_index(SpaprDrc *drc) 41 { 42 SpaprDrcClass *drck = SPAPR_DR_CONNECTOR_GET_CLASS(drc); 43 44 /* no set format for a drc index: it only needs to be globally 45 * unique. this is how we encode the DRC type on bare-metal 46 * however, so might as well do that here 47 */ 48 return (drck->typeshift << DRC_INDEX_TYPE_SHIFT) 49 | (drc->id & DRC_INDEX_ID_MASK); 50 } 51 52 static uint32_t drc_isolate_physical(SpaprDrc *drc) 53 { 54 switch (drc->state) { 55 case SPAPR_DRC_STATE_PHYSICAL_POWERON: 56 return RTAS_OUT_SUCCESS; /* Nothing to do */ 57 case SPAPR_DRC_STATE_PHYSICAL_CONFIGURED: 58 break; /* see below */ 59 case SPAPR_DRC_STATE_PHYSICAL_UNISOLATE: 60 return RTAS_OUT_PARAM_ERROR; /* not allowed */ 61 default: 62 g_assert_not_reached(); 63 } 64 65 drc->state = SPAPR_DRC_STATE_PHYSICAL_POWERON; 66 67 if (drc->unplug_requested) { 68 uint32_t drc_index = spapr_drc_index(drc); 69 trace_spapr_drc_set_isolation_state_finalizing(drc_index); 70 spapr_drc_detach(drc); 71 } 72 73 return RTAS_OUT_SUCCESS; 74 } 75 76 static uint32_t drc_unisolate_physical(SpaprDrc *drc) 77 { 78 switch (drc->state) { 79 case SPAPR_DRC_STATE_PHYSICAL_UNISOLATE: 80 case SPAPR_DRC_STATE_PHYSICAL_CONFIGURED: 81 return RTAS_OUT_SUCCESS; /* Nothing to do */ 82 case SPAPR_DRC_STATE_PHYSICAL_POWERON: 83 break; /* see below */ 84 default: 85 g_assert_not_reached(); 86 } 87 88 /* cannot unisolate a non-existent resource, and, or resources 89 * which are in an 'UNUSABLE' allocation state. (PAPR 2.7, 90 * 13.5.3.5) 91 */ 92 if (!drc->dev) { 93 return RTAS_OUT_NO_SUCH_INDICATOR; 94 } 95 96 drc->state = SPAPR_DRC_STATE_PHYSICAL_UNISOLATE; 97 drc->ccs_offset = drc->fdt_start_offset; 98 drc->ccs_depth = 0; 99 100 return RTAS_OUT_SUCCESS; 101 } 102 103 static uint32_t drc_isolate_logical(SpaprDrc *drc) 104 { 105 switch (drc->state) { 106 case SPAPR_DRC_STATE_LOGICAL_AVAILABLE: 107 case SPAPR_DRC_STATE_LOGICAL_UNUSABLE: 108 return RTAS_OUT_SUCCESS; /* Nothing to do */ 109 case SPAPR_DRC_STATE_LOGICAL_CONFIGURED: 110 break; /* see below */ 111 case SPAPR_DRC_STATE_LOGICAL_UNISOLATE: 112 return RTAS_OUT_PARAM_ERROR; /* not allowed */ 113 default: 114 g_assert_not_reached(); 115 } 116 117 /* 118 * Fail any requests to ISOLATE the LMB DRC if this LMB doesn't 119 * belong to a DIMM device that is marked for removal. 120 * 121 * Currently the guest userspace tool drmgr that drives the memory 122 * hotplug/unplug will just try to remove a set of 'removable' LMBs 123 * in response to a hot unplug request that is based on drc-count. 124 * If the LMB being removed doesn't belong to a DIMM device that is 125 * actually being unplugged, fail the isolation request here. 126 */ 127 if (spapr_drc_type(drc) == SPAPR_DR_CONNECTOR_TYPE_LMB 128 && !drc->unplug_requested) { 129 return RTAS_OUT_HW_ERROR; 130 } 131 132 drc->state = SPAPR_DRC_STATE_LOGICAL_AVAILABLE; 133 134 /* if we're awaiting release, but still in an unconfigured state, 135 * it's likely the guest is still in the process of configuring 136 * the device and is transitioning the devices to an ISOLATED 137 * state as a part of that process. so we only complete the 138 * removal when this transition happens for a device in a 139 * configured state, as suggested by the state diagram from PAPR+ 140 * 2.7, 13.4 141 */ 142 if (drc->unplug_requested) { 143 uint32_t drc_index = spapr_drc_index(drc); 144 trace_spapr_drc_set_isolation_state_finalizing(drc_index); 145 spapr_drc_detach(drc); 146 } 147 return RTAS_OUT_SUCCESS; 148 } 149 150 static uint32_t drc_unisolate_logical(SpaprDrc *drc) 151 { 152 switch (drc->state) { 153 case SPAPR_DRC_STATE_LOGICAL_UNISOLATE: 154 case SPAPR_DRC_STATE_LOGICAL_CONFIGURED: 155 return RTAS_OUT_SUCCESS; /* Nothing to do */ 156 case SPAPR_DRC_STATE_LOGICAL_AVAILABLE: 157 break; /* see below */ 158 case SPAPR_DRC_STATE_LOGICAL_UNUSABLE: 159 return RTAS_OUT_NO_SUCH_INDICATOR; /* not allowed */ 160 default: 161 g_assert_not_reached(); 162 } 163 164 /* Move to AVAILABLE state should have ensured device was present */ 165 g_assert(drc->dev); 166 167 drc->state = SPAPR_DRC_STATE_LOGICAL_UNISOLATE; 168 drc->ccs_offset = drc->fdt_start_offset; 169 drc->ccs_depth = 0; 170 171 return RTAS_OUT_SUCCESS; 172 } 173 174 static uint32_t drc_set_usable(SpaprDrc *drc) 175 { 176 switch (drc->state) { 177 case SPAPR_DRC_STATE_LOGICAL_AVAILABLE: 178 case SPAPR_DRC_STATE_LOGICAL_UNISOLATE: 179 case SPAPR_DRC_STATE_LOGICAL_CONFIGURED: 180 return RTAS_OUT_SUCCESS; /* Nothing to do */ 181 case SPAPR_DRC_STATE_LOGICAL_UNUSABLE: 182 break; /* see below */ 183 default: 184 g_assert_not_reached(); 185 } 186 187 /* if there's no resource/device associated with the DRC, there's 188 * no way for us to put it in an allocation state consistent with 189 * being 'USABLE'. PAPR 2.7, 13.5.3.4 documents that this should 190 * result in an RTAS return code of -3 / "no such indicator" 191 */ 192 if (!drc->dev) { 193 return RTAS_OUT_NO_SUCH_INDICATOR; 194 } 195 if (drc->unplug_requested) { 196 /* Don't allow the guest to move a device away from UNUSABLE 197 * state when we want to unplug it */ 198 return RTAS_OUT_NO_SUCH_INDICATOR; 199 } 200 201 drc->state = SPAPR_DRC_STATE_LOGICAL_AVAILABLE; 202 203 return RTAS_OUT_SUCCESS; 204 } 205 206 static uint32_t drc_set_unusable(SpaprDrc *drc) 207 { 208 switch (drc->state) { 209 case SPAPR_DRC_STATE_LOGICAL_UNUSABLE: 210 return RTAS_OUT_SUCCESS; /* Nothing to do */ 211 case SPAPR_DRC_STATE_LOGICAL_AVAILABLE: 212 break; /* see below */ 213 case SPAPR_DRC_STATE_LOGICAL_UNISOLATE: 214 case SPAPR_DRC_STATE_LOGICAL_CONFIGURED: 215 return RTAS_OUT_NO_SUCH_INDICATOR; /* not allowed */ 216 default: 217 g_assert_not_reached(); 218 } 219 220 drc->state = SPAPR_DRC_STATE_LOGICAL_UNUSABLE; 221 if (drc->unplug_requested) { 222 uint32_t drc_index = spapr_drc_index(drc); 223 trace_spapr_drc_set_allocation_state_finalizing(drc_index); 224 spapr_drc_detach(drc); 225 } 226 227 return RTAS_OUT_SUCCESS; 228 } 229 230 static const char *spapr_drc_name(SpaprDrc *drc) 231 { 232 SpaprDrcClass *drck = SPAPR_DR_CONNECTOR_GET_CLASS(drc); 233 234 /* human-readable name for a DRC to encode into the DT 235 * description. this is mainly only used within a guest in place 236 * of the unique DRC index. 237 * 238 * in the case of VIO/PCI devices, it corresponds to a "location 239 * code" that maps a logical device/function (DRC index) to a 240 * physical (or virtual in the case of VIO) location in the system 241 * by chaining together the "location label" for each 242 * encapsulating component. 243 * 244 * since this is more to do with diagnosing physical hardware 245 * issues than guest compatibility, we choose location codes/DRC 246 * names that adhere to the documented format, but avoid encoding 247 * the entire topology information into the label/code, instead 248 * just using the location codes based on the labels for the 249 * endpoints (VIO/PCI adaptor connectors), which is basically just 250 * "C" followed by an integer ID. 251 * 252 * DRC names as documented by PAPR+ v2.7, 13.5.2.4 253 * location codes as documented by PAPR+ v2.7, 12.3.1.5 254 */ 255 return g_strdup_printf("%s%d", drck->drc_name_prefix, drc->id); 256 } 257 258 /* 259 * dr-entity-sense sensor value 260 * returned via get-sensor-state RTAS calls 261 * as expected by state diagram in PAPR+ 2.7, 13.4 262 * based on the current allocation/indicator/power states 263 * for the DR connector. 264 */ 265 static SpaprDREntitySense physical_entity_sense(SpaprDrc *drc) 266 { 267 /* this assumes all PCI devices are assigned to a 'live insertion' 268 * power domain, where QEMU manages power state automatically as 269 * opposed to the guest. present, non-PCI resources are unaffected 270 * by power state. 271 */ 272 return drc->dev ? SPAPR_DR_ENTITY_SENSE_PRESENT 273 : SPAPR_DR_ENTITY_SENSE_EMPTY; 274 } 275 276 static SpaprDREntitySense logical_entity_sense(SpaprDrc *drc) 277 { 278 switch (drc->state) { 279 case SPAPR_DRC_STATE_LOGICAL_UNUSABLE: 280 return SPAPR_DR_ENTITY_SENSE_UNUSABLE; 281 case SPAPR_DRC_STATE_LOGICAL_AVAILABLE: 282 case SPAPR_DRC_STATE_LOGICAL_UNISOLATE: 283 case SPAPR_DRC_STATE_LOGICAL_CONFIGURED: 284 g_assert(drc->dev); 285 return SPAPR_DR_ENTITY_SENSE_PRESENT; 286 default: 287 g_assert_not_reached(); 288 } 289 } 290 291 static void prop_get_index(Object *obj, Visitor *v, const char *name, 292 void *opaque, Error **errp) 293 { 294 SpaprDrc *drc = SPAPR_DR_CONNECTOR(obj); 295 uint32_t value = spapr_drc_index(drc); 296 visit_type_uint32(v, name, &value, errp); 297 } 298 299 static void prop_get_fdt(Object *obj, Visitor *v, const char *name, 300 void *opaque, Error **errp) 301 { 302 SpaprDrc *drc = SPAPR_DR_CONNECTOR(obj); 303 QNull *null = NULL; 304 Error *err = NULL; 305 int fdt_offset_next, fdt_offset, fdt_depth; 306 void *fdt; 307 308 if (!drc->fdt) { 309 visit_type_null(v, NULL, &null, errp); 310 qobject_unref(null); 311 return; 312 } 313 314 fdt = drc->fdt; 315 fdt_offset = drc->fdt_start_offset; 316 fdt_depth = 0; 317 318 do { 319 const char *name = NULL; 320 const struct fdt_property *prop = NULL; 321 int prop_len = 0, name_len = 0; 322 uint32_t tag; 323 324 tag = fdt_next_tag(fdt, fdt_offset, &fdt_offset_next); 325 switch (tag) { 326 case FDT_BEGIN_NODE: 327 fdt_depth++; 328 name = fdt_get_name(fdt, fdt_offset, &name_len); 329 visit_start_struct(v, name, NULL, 0, &err); 330 if (err) { 331 error_propagate(errp, err); 332 return; 333 } 334 break; 335 case FDT_END_NODE: 336 /* shouldn't ever see an FDT_END_NODE before FDT_BEGIN_NODE */ 337 g_assert(fdt_depth > 0); 338 visit_check_struct(v, &err); 339 visit_end_struct(v, NULL); 340 if (err) { 341 error_propagate(errp, err); 342 return; 343 } 344 fdt_depth--; 345 break; 346 case FDT_PROP: { 347 int i; 348 prop = fdt_get_property_by_offset(fdt, fdt_offset, &prop_len); 349 name = fdt_string(fdt, fdt32_to_cpu(prop->nameoff)); 350 visit_start_list(v, name, NULL, 0, &err); 351 if (err) { 352 error_propagate(errp, err); 353 return; 354 } 355 for (i = 0; i < prop_len; i++) { 356 visit_type_uint8(v, NULL, (uint8_t *)&prop->data[i], &err); 357 if (err) { 358 error_propagate(errp, err); 359 return; 360 } 361 } 362 visit_check_list(v, &err); 363 visit_end_list(v, NULL); 364 if (err) { 365 error_propagate(errp, err); 366 return; 367 } 368 break; 369 } 370 default: 371 error_report("device FDT in unexpected state: %d", tag); 372 abort(); 373 } 374 fdt_offset = fdt_offset_next; 375 } while (fdt_depth != 0); 376 } 377 378 void spapr_drc_attach(SpaprDrc *drc, DeviceState *d, Error **errp) 379 { 380 trace_spapr_drc_attach(spapr_drc_index(drc)); 381 382 if (drc->dev) { 383 error_setg(errp, "an attached device is still awaiting release"); 384 return; 385 } 386 g_assert((drc->state == SPAPR_DRC_STATE_LOGICAL_UNUSABLE) 387 || (drc->state == SPAPR_DRC_STATE_PHYSICAL_POWERON)); 388 389 drc->dev = d; 390 391 object_property_add_link(OBJECT(drc), "device", 392 object_get_typename(OBJECT(drc->dev)), 393 (Object **)(&drc->dev), 394 NULL, 0, NULL); 395 } 396 397 static void spapr_drc_release(SpaprDrc *drc) 398 { 399 SpaprDrcClass *drck = SPAPR_DR_CONNECTOR_GET_CLASS(drc); 400 401 drck->release(drc->dev); 402 403 drc->unplug_requested = false; 404 g_free(drc->fdt); 405 drc->fdt = NULL; 406 drc->fdt_start_offset = 0; 407 object_property_del(OBJECT(drc), "device", &error_abort); 408 drc->dev = NULL; 409 } 410 411 void spapr_drc_detach(SpaprDrc *drc) 412 { 413 SpaprDrcClass *drck = SPAPR_DR_CONNECTOR_GET_CLASS(drc); 414 415 trace_spapr_drc_detach(spapr_drc_index(drc)); 416 417 g_assert(drc->dev); 418 419 drc->unplug_requested = true; 420 421 if (drc->state != drck->empty_state) { 422 trace_spapr_drc_awaiting_quiesce(spapr_drc_index(drc)); 423 return; 424 } 425 426 spapr_drc_release(drc); 427 } 428 429 void spapr_drc_reset(SpaprDrc *drc) 430 { 431 SpaprDrcClass *drck = SPAPR_DR_CONNECTOR_GET_CLASS(drc); 432 433 trace_spapr_drc_reset(spapr_drc_index(drc)); 434 435 /* immediately upon reset we can safely assume DRCs whose devices 436 * are pending removal can be safely removed. 437 */ 438 if (drc->unplug_requested) { 439 spapr_drc_release(drc); 440 } 441 442 if (drc->dev) { 443 /* A device present at reset is ready to go, same as coldplugged */ 444 drc->state = drck->ready_state; 445 /* 446 * Ensure that we are able to send the FDT fragment again 447 * via configure-connector call if the guest requests. 448 */ 449 drc->ccs_offset = drc->fdt_start_offset; 450 drc->ccs_depth = 0; 451 } else { 452 drc->state = drck->empty_state; 453 drc->ccs_offset = -1; 454 drc->ccs_depth = -1; 455 } 456 } 457 458 bool spapr_drc_needed(void *opaque) 459 { 460 SpaprDrc *drc = (SpaprDrc *)opaque; 461 SpaprDrcClass *drck = SPAPR_DR_CONNECTOR_GET_CLASS(drc); 462 463 /* If no dev is plugged in there is no need to migrate the DRC state */ 464 if (!drc->dev) { 465 return false; 466 } 467 468 /* 469 * We need to migrate the state if it's not equal to the expected 470 * long-term state, which is the same as the coldplugged initial 471 * state */ 472 return (drc->state != drck->ready_state); 473 } 474 475 static const VMStateDescription vmstate_spapr_drc = { 476 .name = "spapr_drc", 477 .version_id = 1, 478 .minimum_version_id = 1, 479 .needed = spapr_drc_needed, 480 .fields = (VMStateField []) { 481 VMSTATE_UINT32(state, SpaprDrc), 482 VMSTATE_END_OF_LIST() 483 } 484 }; 485 486 static void realize(DeviceState *d, Error **errp) 487 { 488 SpaprDrc *drc = SPAPR_DR_CONNECTOR(d); 489 Object *root_container; 490 gchar *link_name; 491 gchar *child_name; 492 Error *err = NULL; 493 494 trace_spapr_drc_realize(spapr_drc_index(drc)); 495 /* NOTE: we do this as part of realize/unrealize due to the fact 496 * that the guest will communicate with the DRC via RTAS calls 497 * referencing the global DRC index. By unlinking the DRC 498 * from DRC_CONTAINER_PATH/<drc_index> we effectively make it 499 * inaccessible by the guest, since lookups rely on this path 500 * existing in the composition tree 501 */ 502 root_container = container_get(object_get_root(), DRC_CONTAINER_PATH); 503 link_name = g_strdup_printf("%x", spapr_drc_index(drc)); 504 child_name = object_get_canonical_path_component(OBJECT(drc)); 505 trace_spapr_drc_realize_child(spapr_drc_index(drc), child_name); 506 object_property_add_alias(root_container, link_name, 507 drc->owner, child_name, &err); 508 g_free(child_name); 509 g_free(link_name); 510 if (err) { 511 error_propagate(errp, err); 512 return; 513 } 514 vmstate_register(DEVICE(drc), spapr_drc_index(drc), &vmstate_spapr_drc, 515 drc); 516 trace_spapr_drc_realize_complete(spapr_drc_index(drc)); 517 } 518 519 static void unrealize(DeviceState *d, Error **errp) 520 { 521 SpaprDrc *drc = SPAPR_DR_CONNECTOR(d); 522 Object *root_container; 523 gchar *name; 524 525 trace_spapr_drc_unrealize(spapr_drc_index(drc)); 526 vmstate_unregister(DEVICE(drc), &vmstate_spapr_drc, drc); 527 root_container = container_get(object_get_root(), DRC_CONTAINER_PATH); 528 name = g_strdup_printf("%x", spapr_drc_index(drc)); 529 object_property_del(root_container, name, errp); 530 g_free(name); 531 } 532 533 SpaprDrc *spapr_dr_connector_new(Object *owner, const char *type, 534 uint32_t id) 535 { 536 SpaprDrc *drc = SPAPR_DR_CONNECTOR(object_new(type)); 537 char *prop_name; 538 539 drc->id = id; 540 drc->owner = owner; 541 prop_name = g_strdup_printf("dr-connector[%"PRIu32"]", 542 spapr_drc_index(drc)); 543 object_property_add_child(owner, prop_name, OBJECT(drc), &error_abort); 544 object_unref(OBJECT(drc)); 545 object_property_set_bool(OBJECT(drc), true, "realized", NULL); 546 g_free(prop_name); 547 548 return drc; 549 } 550 551 static void spapr_dr_connector_instance_init(Object *obj) 552 { 553 SpaprDrc *drc = SPAPR_DR_CONNECTOR(obj); 554 SpaprDrcClass *drck = SPAPR_DR_CONNECTOR_GET_CLASS(drc); 555 556 object_property_add_uint32_ptr(obj, "id", &drc->id, NULL); 557 object_property_add(obj, "index", "uint32", prop_get_index, 558 NULL, NULL, NULL, NULL); 559 object_property_add(obj, "fdt", "struct", prop_get_fdt, 560 NULL, NULL, NULL, NULL); 561 drc->state = drck->empty_state; 562 } 563 564 static void spapr_dr_connector_class_init(ObjectClass *k, void *data) 565 { 566 DeviceClass *dk = DEVICE_CLASS(k); 567 568 dk->realize = realize; 569 dk->unrealize = unrealize; 570 /* 571 * Reason: it crashes FIXME find and document the real reason 572 */ 573 dk->user_creatable = false; 574 } 575 576 static bool drc_physical_needed(void *opaque) 577 { 578 SpaprDrcPhysical *drcp = (SpaprDrcPhysical *)opaque; 579 SpaprDrc *drc = SPAPR_DR_CONNECTOR(drcp); 580 581 if ((drc->dev && (drcp->dr_indicator == SPAPR_DR_INDICATOR_ACTIVE)) 582 || (!drc->dev && (drcp->dr_indicator == SPAPR_DR_INDICATOR_INACTIVE))) { 583 return false; 584 } 585 return true; 586 } 587 588 static const VMStateDescription vmstate_spapr_drc_physical = { 589 .name = "spapr_drc/physical", 590 .version_id = 1, 591 .minimum_version_id = 1, 592 .needed = drc_physical_needed, 593 .fields = (VMStateField []) { 594 VMSTATE_UINT32(dr_indicator, SpaprDrcPhysical), 595 VMSTATE_END_OF_LIST() 596 } 597 }; 598 599 static void drc_physical_reset(void *opaque) 600 { 601 SpaprDrc *drc = SPAPR_DR_CONNECTOR(opaque); 602 SpaprDrcPhysical *drcp = SPAPR_DRC_PHYSICAL(drc); 603 604 if (drc->dev) { 605 drcp->dr_indicator = SPAPR_DR_INDICATOR_ACTIVE; 606 } else { 607 drcp->dr_indicator = SPAPR_DR_INDICATOR_INACTIVE; 608 } 609 } 610 611 static void realize_physical(DeviceState *d, Error **errp) 612 { 613 SpaprDrcPhysical *drcp = SPAPR_DRC_PHYSICAL(d); 614 Error *local_err = NULL; 615 616 realize(d, &local_err); 617 if (local_err) { 618 error_propagate(errp, local_err); 619 return; 620 } 621 622 vmstate_register(DEVICE(drcp), spapr_drc_index(SPAPR_DR_CONNECTOR(drcp)), 623 &vmstate_spapr_drc_physical, drcp); 624 qemu_register_reset(drc_physical_reset, drcp); 625 } 626 627 static void unrealize_physical(DeviceState *d, Error **errp) 628 { 629 SpaprDrcPhysical *drcp = SPAPR_DRC_PHYSICAL(d); 630 Error *local_err = NULL; 631 632 unrealize(d, &local_err); 633 if (local_err) { 634 error_propagate(errp, local_err); 635 return; 636 } 637 638 vmstate_unregister(DEVICE(drcp), &vmstate_spapr_drc_physical, drcp); 639 qemu_unregister_reset(drc_physical_reset, drcp); 640 } 641 642 static void spapr_drc_physical_class_init(ObjectClass *k, void *data) 643 { 644 DeviceClass *dk = DEVICE_CLASS(k); 645 SpaprDrcClass *drck = SPAPR_DR_CONNECTOR_CLASS(k); 646 647 dk->realize = realize_physical; 648 dk->unrealize = unrealize_physical; 649 drck->dr_entity_sense = physical_entity_sense; 650 drck->isolate = drc_isolate_physical; 651 drck->unisolate = drc_unisolate_physical; 652 drck->ready_state = SPAPR_DRC_STATE_PHYSICAL_CONFIGURED; 653 drck->empty_state = SPAPR_DRC_STATE_PHYSICAL_POWERON; 654 } 655 656 static void spapr_drc_logical_class_init(ObjectClass *k, void *data) 657 { 658 SpaprDrcClass *drck = SPAPR_DR_CONNECTOR_CLASS(k); 659 660 drck->dr_entity_sense = logical_entity_sense; 661 drck->isolate = drc_isolate_logical; 662 drck->unisolate = drc_unisolate_logical; 663 drck->ready_state = SPAPR_DRC_STATE_LOGICAL_CONFIGURED; 664 drck->empty_state = SPAPR_DRC_STATE_LOGICAL_UNUSABLE; 665 } 666 667 static void spapr_drc_cpu_class_init(ObjectClass *k, void *data) 668 { 669 SpaprDrcClass *drck = SPAPR_DR_CONNECTOR_CLASS(k); 670 671 drck->typeshift = SPAPR_DR_CONNECTOR_TYPE_SHIFT_CPU; 672 drck->typename = "CPU"; 673 drck->drc_name_prefix = "CPU "; 674 drck->release = spapr_core_release; 675 drck->dt_populate = spapr_core_dt_populate; 676 } 677 678 static void spapr_drc_pci_class_init(ObjectClass *k, void *data) 679 { 680 SpaprDrcClass *drck = SPAPR_DR_CONNECTOR_CLASS(k); 681 682 drck->typeshift = SPAPR_DR_CONNECTOR_TYPE_SHIFT_PCI; 683 drck->typename = "28"; 684 drck->drc_name_prefix = "C"; 685 drck->release = spapr_phb_remove_pci_device_cb; 686 drck->dt_populate = spapr_pci_dt_populate; 687 } 688 689 static void spapr_drc_lmb_class_init(ObjectClass *k, void *data) 690 { 691 SpaprDrcClass *drck = SPAPR_DR_CONNECTOR_CLASS(k); 692 693 drck->typeshift = SPAPR_DR_CONNECTOR_TYPE_SHIFT_LMB; 694 drck->typename = "MEM"; 695 drck->drc_name_prefix = "LMB "; 696 drck->release = spapr_lmb_release; 697 drck->dt_populate = spapr_lmb_dt_populate; 698 } 699 700 static void spapr_drc_phb_class_init(ObjectClass *k, void *data) 701 { 702 SpaprDrcClass *drck = SPAPR_DR_CONNECTOR_CLASS(k); 703 704 drck->typeshift = SPAPR_DR_CONNECTOR_TYPE_SHIFT_PHB; 705 drck->typename = "PHB"; 706 drck->drc_name_prefix = "PHB "; 707 drck->release = spapr_phb_release; 708 drck->dt_populate = spapr_phb_dt_populate; 709 } 710 711 static const TypeInfo spapr_dr_connector_info = { 712 .name = TYPE_SPAPR_DR_CONNECTOR, 713 .parent = TYPE_DEVICE, 714 .instance_size = sizeof(SpaprDrc), 715 .instance_init = spapr_dr_connector_instance_init, 716 .class_size = sizeof(SpaprDrcClass), 717 .class_init = spapr_dr_connector_class_init, 718 .abstract = true, 719 }; 720 721 static const TypeInfo spapr_drc_physical_info = { 722 .name = TYPE_SPAPR_DRC_PHYSICAL, 723 .parent = TYPE_SPAPR_DR_CONNECTOR, 724 .instance_size = sizeof(SpaprDrcPhysical), 725 .class_init = spapr_drc_physical_class_init, 726 .abstract = true, 727 }; 728 729 static const TypeInfo spapr_drc_logical_info = { 730 .name = TYPE_SPAPR_DRC_LOGICAL, 731 .parent = TYPE_SPAPR_DR_CONNECTOR, 732 .class_init = spapr_drc_logical_class_init, 733 .abstract = true, 734 }; 735 736 static const TypeInfo spapr_drc_cpu_info = { 737 .name = TYPE_SPAPR_DRC_CPU, 738 .parent = TYPE_SPAPR_DRC_LOGICAL, 739 .class_init = spapr_drc_cpu_class_init, 740 }; 741 742 static const TypeInfo spapr_drc_pci_info = { 743 .name = TYPE_SPAPR_DRC_PCI, 744 .parent = TYPE_SPAPR_DRC_PHYSICAL, 745 .class_init = spapr_drc_pci_class_init, 746 }; 747 748 static const TypeInfo spapr_drc_lmb_info = { 749 .name = TYPE_SPAPR_DRC_LMB, 750 .parent = TYPE_SPAPR_DRC_LOGICAL, 751 .class_init = spapr_drc_lmb_class_init, 752 }; 753 754 static const TypeInfo spapr_drc_phb_info = { 755 .name = TYPE_SPAPR_DRC_PHB, 756 .parent = TYPE_SPAPR_DRC_LOGICAL, 757 .instance_size = sizeof(SpaprDrc), 758 .class_init = spapr_drc_phb_class_init, 759 }; 760 761 /* helper functions for external users */ 762 763 SpaprDrc *spapr_drc_by_index(uint32_t index) 764 { 765 Object *obj; 766 gchar *name; 767 768 name = g_strdup_printf("%s/%x", DRC_CONTAINER_PATH, index); 769 obj = object_resolve_path(name, NULL); 770 g_free(name); 771 772 return !obj ? NULL : SPAPR_DR_CONNECTOR(obj); 773 } 774 775 SpaprDrc *spapr_drc_by_id(const char *type, uint32_t id) 776 { 777 SpaprDrcClass *drck 778 = SPAPR_DR_CONNECTOR_CLASS(object_class_by_name(type)); 779 780 return spapr_drc_by_index(drck->typeshift << DRC_INDEX_TYPE_SHIFT 781 | (id & DRC_INDEX_ID_MASK)); 782 } 783 784 /** 785 * spapr_dt_drc 786 * 787 * @fdt: libfdt device tree 788 * @path: path in the DT to generate properties 789 * @owner: parent Object/DeviceState for which to generate DRC 790 * descriptions for 791 * @drc_type_mask: mask of SpaprDrcType values corresponding 792 * to the types of DRCs to generate entries for 793 * 794 * generate OF properties to describe DRC topology/indices to guests 795 * 796 * as documented in PAPR+ v2.1, 13.5.2 797 */ 798 int spapr_dt_drc(void *fdt, int offset, Object *owner, uint32_t drc_type_mask) 799 { 800 Object *root_container; 801 ObjectProperty *prop; 802 ObjectPropertyIterator iter; 803 uint32_t drc_count = 0; 804 GArray *drc_indexes, *drc_power_domains; 805 GString *drc_names, *drc_types; 806 int ret; 807 808 /* the first entry of each properties is a 32-bit integer encoding 809 * the number of elements in the array. we won't know this until 810 * we complete the iteration through all the matching DRCs, but 811 * reserve the space now and set the offsets accordingly so we 812 * can fill them in later. 813 */ 814 drc_indexes = g_array_new(false, true, sizeof(uint32_t)); 815 drc_indexes = g_array_set_size(drc_indexes, 1); 816 drc_power_domains = g_array_new(false, true, sizeof(uint32_t)); 817 drc_power_domains = g_array_set_size(drc_power_domains, 1); 818 drc_names = g_string_set_size(g_string_new(NULL), sizeof(uint32_t)); 819 drc_types = g_string_set_size(g_string_new(NULL), sizeof(uint32_t)); 820 821 /* aliases for all DRConnector objects will be rooted in QOM 822 * composition tree at DRC_CONTAINER_PATH 823 */ 824 root_container = container_get(object_get_root(), DRC_CONTAINER_PATH); 825 826 object_property_iter_init(&iter, root_container); 827 while ((prop = object_property_iter_next(&iter))) { 828 Object *obj; 829 SpaprDrc *drc; 830 SpaprDrcClass *drck; 831 uint32_t drc_index, drc_power_domain; 832 833 if (!strstart(prop->type, "link<", NULL)) { 834 continue; 835 } 836 837 obj = object_property_get_link(root_container, prop->name, NULL); 838 drc = SPAPR_DR_CONNECTOR(obj); 839 drck = SPAPR_DR_CONNECTOR_GET_CLASS(drc); 840 841 if (owner && (drc->owner != owner)) { 842 continue; 843 } 844 845 if ((spapr_drc_type(drc) & drc_type_mask) == 0) { 846 continue; 847 } 848 849 drc_count++; 850 851 /* ibm,drc-indexes */ 852 drc_index = cpu_to_be32(spapr_drc_index(drc)); 853 g_array_append_val(drc_indexes, drc_index); 854 855 /* ibm,drc-power-domains */ 856 drc_power_domain = cpu_to_be32(-1); 857 g_array_append_val(drc_power_domains, drc_power_domain); 858 859 /* ibm,drc-names */ 860 drc_names = g_string_append(drc_names, spapr_drc_name(drc)); 861 drc_names = g_string_insert_len(drc_names, -1, "\0", 1); 862 863 /* ibm,drc-types */ 864 drc_types = g_string_append(drc_types, drck->typename); 865 drc_types = g_string_insert_len(drc_types, -1, "\0", 1); 866 } 867 868 /* now write the drc count into the space we reserved at the 869 * beginning of the arrays previously 870 */ 871 *(uint32_t *)drc_indexes->data = cpu_to_be32(drc_count); 872 *(uint32_t *)drc_power_domains->data = cpu_to_be32(drc_count); 873 *(uint32_t *)drc_names->str = cpu_to_be32(drc_count); 874 *(uint32_t *)drc_types->str = cpu_to_be32(drc_count); 875 876 ret = fdt_setprop(fdt, offset, "ibm,drc-indexes", 877 drc_indexes->data, 878 drc_indexes->len * sizeof(uint32_t)); 879 if (ret) { 880 error_report("Couldn't create ibm,drc-indexes property"); 881 goto out; 882 } 883 884 ret = fdt_setprop(fdt, offset, "ibm,drc-power-domains", 885 drc_power_domains->data, 886 drc_power_domains->len * sizeof(uint32_t)); 887 if (ret) { 888 error_report("Couldn't finalize ibm,drc-power-domains property"); 889 goto out; 890 } 891 892 ret = fdt_setprop(fdt, offset, "ibm,drc-names", 893 drc_names->str, drc_names->len); 894 if (ret) { 895 error_report("Couldn't finalize ibm,drc-names property"); 896 goto out; 897 } 898 899 ret = fdt_setprop(fdt, offset, "ibm,drc-types", 900 drc_types->str, drc_types->len); 901 if (ret) { 902 error_report("Couldn't finalize ibm,drc-types property"); 903 goto out; 904 } 905 906 out: 907 g_array_free(drc_indexes, true); 908 g_array_free(drc_power_domains, true); 909 g_string_free(drc_names, true); 910 g_string_free(drc_types, true); 911 912 return ret; 913 } 914 915 /* 916 * RTAS calls 917 */ 918 919 static uint32_t rtas_set_isolation_state(uint32_t idx, uint32_t state) 920 { 921 SpaprDrc *drc = spapr_drc_by_index(idx); 922 SpaprDrcClass *drck; 923 924 if (!drc) { 925 return RTAS_OUT_NO_SUCH_INDICATOR; 926 } 927 928 trace_spapr_drc_set_isolation_state(spapr_drc_index(drc), state); 929 930 drck = SPAPR_DR_CONNECTOR_GET_CLASS(drc); 931 932 switch (state) { 933 case SPAPR_DR_ISOLATION_STATE_ISOLATED: 934 return drck->isolate(drc); 935 936 case SPAPR_DR_ISOLATION_STATE_UNISOLATED: 937 return drck->unisolate(drc); 938 939 default: 940 return RTAS_OUT_PARAM_ERROR; 941 } 942 } 943 944 static uint32_t rtas_set_allocation_state(uint32_t idx, uint32_t state) 945 { 946 SpaprDrc *drc = spapr_drc_by_index(idx); 947 948 if (!drc || !object_dynamic_cast(OBJECT(drc), TYPE_SPAPR_DRC_LOGICAL)) { 949 return RTAS_OUT_NO_SUCH_INDICATOR; 950 } 951 952 trace_spapr_drc_set_allocation_state(spapr_drc_index(drc), state); 953 954 switch (state) { 955 case SPAPR_DR_ALLOCATION_STATE_USABLE: 956 return drc_set_usable(drc); 957 958 case SPAPR_DR_ALLOCATION_STATE_UNUSABLE: 959 return drc_set_unusable(drc); 960 961 default: 962 return RTAS_OUT_PARAM_ERROR; 963 } 964 } 965 966 static uint32_t rtas_set_dr_indicator(uint32_t idx, uint32_t state) 967 { 968 SpaprDrc *drc = spapr_drc_by_index(idx); 969 970 if (!drc || !object_dynamic_cast(OBJECT(drc), TYPE_SPAPR_DRC_PHYSICAL)) { 971 return RTAS_OUT_NO_SUCH_INDICATOR; 972 } 973 if ((state != SPAPR_DR_INDICATOR_INACTIVE) 974 && (state != SPAPR_DR_INDICATOR_ACTIVE) 975 && (state != SPAPR_DR_INDICATOR_IDENTIFY) 976 && (state != SPAPR_DR_INDICATOR_ACTION)) { 977 return RTAS_OUT_PARAM_ERROR; /* bad state parameter */ 978 } 979 980 trace_spapr_drc_set_dr_indicator(idx, state); 981 SPAPR_DRC_PHYSICAL(drc)->dr_indicator = state; 982 return RTAS_OUT_SUCCESS; 983 } 984 985 static void rtas_set_indicator(PowerPCCPU *cpu, SpaprMachineState *spapr, 986 uint32_t token, 987 uint32_t nargs, target_ulong args, 988 uint32_t nret, target_ulong rets) 989 { 990 uint32_t type, idx, state; 991 uint32_t ret = RTAS_OUT_SUCCESS; 992 993 if (nargs != 3 || nret != 1) { 994 ret = RTAS_OUT_PARAM_ERROR; 995 goto out; 996 } 997 998 type = rtas_ld(args, 0); 999 idx = rtas_ld(args, 1); 1000 state = rtas_ld(args, 2); 1001 1002 switch (type) { 1003 case RTAS_SENSOR_TYPE_ISOLATION_STATE: 1004 ret = rtas_set_isolation_state(idx, state); 1005 break; 1006 case RTAS_SENSOR_TYPE_DR: 1007 ret = rtas_set_dr_indicator(idx, state); 1008 break; 1009 case RTAS_SENSOR_TYPE_ALLOCATION_STATE: 1010 ret = rtas_set_allocation_state(idx, state); 1011 break; 1012 default: 1013 ret = RTAS_OUT_NOT_SUPPORTED; 1014 } 1015 1016 out: 1017 rtas_st(rets, 0, ret); 1018 } 1019 1020 static void rtas_get_sensor_state(PowerPCCPU *cpu, SpaprMachineState *spapr, 1021 uint32_t token, uint32_t nargs, 1022 target_ulong args, uint32_t nret, 1023 target_ulong rets) 1024 { 1025 uint32_t sensor_type; 1026 uint32_t sensor_index; 1027 uint32_t sensor_state = 0; 1028 SpaprDrc *drc; 1029 SpaprDrcClass *drck; 1030 uint32_t ret = RTAS_OUT_SUCCESS; 1031 1032 if (nargs != 2 || nret != 2) { 1033 ret = RTAS_OUT_PARAM_ERROR; 1034 goto out; 1035 } 1036 1037 sensor_type = rtas_ld(args, 0); 1038 sensor_index = rtas_ld(args, 1); 1039 1040 if (sensor_type != RTAS_SENSOR_TYPE_ENTITY_SENSE) { 1041 /* currently only DR-related sensors are implemented */ 1042 trace_spapr_rtas_get_sensor_state_not_supported(sensor_index, 1043 sensor_type); 1044 ret = RTAS_OUT_NOT_SUPPORTED; 1045 goto out; 1046 } 1047 1048 drc = spapr_drc_by_index(sensor_index); 1049 if (!drc) { 1050 trace_spapr_rtas_get_sensor_state_invalid(sensor_index); 1051 ret = RTAS_OUT_PARAM_ERROR; 1052 goto out; 1053 } 1054 drck = SPAPR_DR_CONNECTOR_GET_CLASS(drc); 1055 sensor_state = drck->dr_entity_sense(drc); 1056 1057 out: 1058 rtas_st(rets, 0, ret); 1059 rtas_st(rets, 1, sensor_state); 1060 } 1061 1062 /* configure-connector work area offsets, int32_t units for field 1063 * indexes, bytes for field offset/len values. 1064 * 1065 * as documented by PAPR+ v2.7, 13.5.3.5 1066 */ 1067 #define CC_IDX_NODE_NAME_OFFSET 2 1068 #define CC_IDX_PROP_NAME_OFFSET 2 1069 #define CC_IDX_PROP_LEN 3 1070 #define CC_IDX_PROP_DATA_OFFSET 4 1071 #define CC_VAL_DATA_OFFSET ((CC_IDX_PROP_DATA_OFFSET + 1) * 4) 1072 #define CC_WA_LEN 4096 1073 1074 static void configure_connector_st(target_ulong addr, target_ulong offset, 1075 const void *buf, size_t len) 1076 { 1077 cpu_physical_memory_write(ppc64_phys_to_real(addr + offset), 1078 buf, MIN(len, CC_WA_LEN - offset)); 1079 } 1080 1081 static void rtas_ibm_configure_connector(PowerPCCPU *cpu, 1082 SpaprMachineState *spapr, 1083 uint32_t token, uint32_t nargs, 1084 target_ulong args, uint32_t nret, 1085 target_ulong rets) 1086 { 1087 uint64_t wa_addr; 1088 uint64_t wa_offset; 1089 uint32_t drc_index; 1090 SpaprDrc *drc; 1091 SpaprDrcClass *drck; 1092 SpaprDRCCResponse resp = SPAPR_DR_CC_RESPONSE_CONTINUE; 1093 int rc; 1094 1095 if (nargs != 2 || nret != 1) { 1096 rtas_st(rets, 0, RTAS_OUT_PARAM_ERROR); 1097 return; 1098 } 1099 1100 wa_addr = ((uint64_t)rtas_ld(args, 1) << 32) | rtas_ld(args, 0); 1101 1102 drc_index = rtas_ld(wa_addr, 0); 1103 drc = spapr_drc_by_index(drc_index); 1104 if (!drc) { 1105 trace_spapr_rtas_ibm_configure_connector_invalid(drc_index); 1106 rc = RTAS_OUT_PARAM_ERROR; 1107 goto out; 1108 } 1109 1110 if ((drc->state != SPAPR_DRC_STATE_LOGICAL_UNISOLATE) 1111 && (drc->state != SPAPR_DRC_STATE_PHYSICAL_UNISOLATE) 1112 && (drc->state != SPAPR_DRC_STATE_LOGICAL_CONFIGURED) 1113 && (drc->state != SPAPR_DRC_STATE_PHYSICAL_CONFIGURED)) { 1114 /* 1115 * Need to unisolate the device before configuring 1116 * or it should already be in configured state to 1117 * allow configure-connector be called repeatedly. 1118 */ 1119 rc = SPAPR_DR_CC_RESPONSE_NOT_CONFIGURABLE; 1120 goto out; 1121 } 1122 1123 drck = SPAPR_DR_CONNECTOR_GET_CLASS(drc); 1124 1125 if (!drc->fdt) { 1126 Error *local_err = NULL; 1127 void *fdt; 1128 int fdt_size; 1129 1130 fdt = create_device_tree(&fdt_size); 1131 1132 if (drck->dt_populate(drc, spapr, fdt, &drc->fdt_start_offset, 1133 &local_err)) { 1134 g_free(fdt); 1135 error_free(local_err); 1136 rc = SPAPR_DR_CC_RESPONSE_ERROR; 1137 goto out; 1138 } 1139 1140 drc->fdt = fdt; 1141 drc->ccs_offset = drc->fdt_start_offset; 1142 drc->ccs_depth = 0; 1143 } 1144 1145 do { 1146 uint32_t tag; 1147 const char *name; 1148 const struct fdt_property *prop; 1149 int fdt_offset_next, prop_len; 1150 1151 tag = fdt_next_tag(drc->fdt, drc->ccs_offset, &fdt_offset_next); 1152 1153 switch (tag) { 1154 case FDT_BEGIN_NODE: 1155 drc->ccs_depth++; 1156 name = fdt_get_name(drc->fdt, drc->ccs_offset, NULL); 1157 1158 /* provide the name of the next OF node */ 1159 wa_offset = CC_VAL_DATA_OFFSET; 1160 rtas_st(wa_addr, CC_IDX_NODE_NAME_OFFSET, wa_offset); 1161 configure_connector_st(wa_addr, wa_offset, name, strlen(name) + 1); 1162 resp = SPAPR_DR_CC_RESPONSE_NEXT_CHILD; 1163 break; 1164 case FDT_END_NODE: 1165 drc->ccs_depth--; 1166 if (drc->ccs_depth == 0) { 1167 uint32_t drc_index = spapr_drc_index(drc); 1168 1169 /* done sending the device tree, move to configured state */ 1170 trace_spapr_drc_set_configured(drc_index); 1171 drc->state = drck->ready_state; 1172 /* 1173 * Ensure that we are able to send the FDT fragment 1174 * again via configure-connector call if the guest requests. 1175 */ 1176 drc->ccs_offset = drc->fdt_start_offset; 1177 drc->ccs_depth = 0; 1178 fdt_offset_next = drc->fdt_start_offset; 1179 resp = SPAPR_DR_CC_RESPONSE_SUCCESS; 1180 } else { 1181 resp = SPAPR_DR_CC_RESPONSE_PREV_PARENT; 1182 } 1183 break; 1184 case FDT_PROP: 1185 prop = fdt_get_property_by_offset(drc->fdt, drc->ccs_offset, 1186 &prop_len); 1187 name = fdt_string(drc->fdt, fdt32_to_cpu(prop->nameoff)); 1188 1189 /* provide the name of the next OF property */ 1190 wa_offset = CC_VAL_DATA_OFFSET; 1191 rtas_st(wa_addr, CC_IDX_PROP_NAME_OFFSET, wa_offset); 1192 configure_connector_st(wa_addr, wa_offset, name, strlen(name) + 1); 1193 1194 /* provide the length and value of the OF property. data gets 1195 * placed immediately after NULL terminator of the OF property's 1196 * name string 1197 */ 1198 wa_offset += strlen(name) + 1, 1199 rtas_st(wa_addr, CC_IDX_PROP_LEN, prop_len); 1200 rtas_st(wa_addr, CC_IDX_PROP_DATA_OFFSET, wa_offset); 1201 configure_connector_st(wa_addr, wa_offset, prop->data, prop_len); 1202 resp = SPAPR_DR_CC_RESPONSE_NEXT_PROPERTY; 1203 break; 1204 case FDT_END: 1205 resp = SPAPR_DR_CC_RESPONSE_ERROR; 1206 default: 1207 /* keep seeking for an actionable tag */ 1208 break; 1209 } 1210 if (drc->ccs_offset >= 0) { 1211 drc->ccs_offset = fdt_offset_next; 1212 } 1213 } while (resp == SPAPR_DR_CC_RESPONSE_CONTINUE); 1214 1215 rc = resp; 1216 out: 1217 rtas_st(rets, 0, rc); 1218 } 1219 1220 static void spapr_drc_register_types(void) 1221 { 1222 type_register_static(&spapr_dr_connector_info); 1223 type_register_static(&spapr_drc_physical_info); 1224 type_register_static(&spapr_drc_logical_info); 1225 type_register_static(&spapr_drc_cpu_info); 1226 type_register_static(&spapr_drc_pci_info); 1227 type_register_static(&spapr_drc_lmb_info); 1228 type_register_static(&spapr_drc_phb_info); 1229 1230 spapr_rtas_register(RTAS_SET_INDICATOR, "set-indicator", 1231 rtas_set_indicator); 1232 spapr_rtas_register(RTAS_GET_SENSOR_STATE, "get-sensor-state", 1233 rtas_get_sensor_state); 1234 spapr_rtas_register(RTAS_IBM_CONFIGURE_CONNECTOR, "ibm,configure-connector", 1235 rtas_ibm_configure_connector); 1236 } 1237 type_init(spapr_drc_register_types) 1238