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