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