2 * QEMU SPAPR Dynamic Reconfiguration Connector Implementation
4 * Copyright IBM Corp. 2014
7 * Michael Roth <mdroth@linux.vnet.ibm.com>
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.
13 #include "qemu/osdep.h"
14 #include "hw/ppc/spapr_drc.h"
15 #include "qom/object.h"
17 #include "qapi/visitor.h"
18 #include "qemu/error-report.h"
19 #include "hw/ppc/spapr.h" /* for RTAS return codes */
21 /* #define DEBUG_SPAPR_DRC */
23 #ifdef DEBUG_SPAPR_DRC
24 #define DPRINTF(fmt, ...) \
25 do { fprintf(stderr, fmt, ## __VA_ARGS__); } while (0)
26 #define DPRINTFN(fmt, ...) \
27 do { DPRINTF(fmt, ## __VA_ARGS__); fprintf(stderr, "\n"); } while (0)
29 #define DPRINTF(fmt, ...) \
31 #define DPRINTFN(fmt, ...) \
35 #define DRC_CONTAINER_PATH "/dr-connector"
36 #define DRC_INDEX_TYPE_SHIFT 28
37 #define DRC_INDEX_ID_MASK ((1ULL << DRC_INDEX_TYPE_SHIFT) - 1)
39 static sPAPRDRConnectorTypeShift
get_type_shift(sPAPRDRConnectorType type
)
43 /* make sure this isn't SPAPR_DR_CONNECTOR_TYPE_ANY, or some
46 g_assert(is_power_of_2(type
));
48 while (type
!= (1 << shift
)) {
54 static uint32_t get_index(sPAPRDRConnector
*drc
)
56 /* no set format for a drc index: it only needs to be globally
57 * unique. this is how we encode the DRC type on bare-metal
58 * however, so might as well do that here
60 return (get_type_shift(drc
->type
) << DRC_INDEX_TYPE_SHIFT
) |
61 (drc
->id
& DRC_INDEX_ID_MASK
);
64 static uint32_t set_isolation_state(sPAPRDRConnector
*drc
,
65 sPAPRDRIsolationState state
)
67 sPAPRDRConnectorClass
*drck
= SPAPR_DR_CONNECTOR_GET_CLASS(drc
);
69 DPRINTFN("drc: %x, set_isolation_state: %x", get_index(drc
), state
);
71 if (state
== SPAPR_DR_ISOLATION_STATE_UNISOLATED
) {
72 /* cannot unisolate a non-existant resource, and, or resources
73 * which are in an 'UNUSABLE' allocation state. (PAPR 2.7, 13.5.3.5)
76 drc
->allocation_state
== SPAPR_DR_ALLOCATION_STATE_UNUSABLE
) {
77 return RTAS_OUT_NO_SUCH_INDICATOR
;
81 drc
->isolation_state
= state
;
83 if (drc
->isolation_state
== SPAPR_DR_ISOLATION_STATE_ISOLATED
) {
84 /* if we're awaiting release, but still in an unconfigured state,
85 * it's likely the guest is still in the process of configuring
86 * the device and is transitioning the devices to an ISOLATED
87 * state as a part of that process. so we only complete the
88 * removal when this transition happens for a device in a
89 * configured state, as suggested by the state diagram from
92 if (drc
->awaiting_release
) {
93 if (drc
->configured
) {
94 DPRINTFN("finalizing device removal");
95 drck
->detach(drc
, DEVICE(drc
->dev
), drc
->detach_cb
,
96 drc
->detach_cb_opaque
, NULL
);
98 DPRINTFN("deferring device removal on unconfigured device\n");
101 drc
->configured
= false;
104 return RTAS_OUT_SUCCESS
;
107 static uint32_t set_indicator_state(sPAPRDRConnector
*drc
,
108 sPAPRDRIndicatorState state
)
110 DPRINTFN("drc: %x, set_indicator_state: %x", get_index(drc
), state
);
111 drc
->indicator_state
= state
;
112 return RTAS_OUT_SUCCESS
;
115 static uint32_t set_allocation_state(sPAPRDRConnector
*drc
,
116 sPAPRDRAllocationState state
)
118 sPAPRDRConnectorClass
*drck
= SPAPR_DR_CONNECTOR_GET_CLASS(drc
);
120 DPRINTFN("drc: %x, set_allocation_state: %x", get_index(drc
), state
);
122 if (state
== SPAPR_DR_ALLOCATION_STATE_USABLE
) {
123 /* if there's no resource/device associated with the DRC, there's
124 * no way for us to put it in an allocation state consistent with
125 * being 'USABLE'. PAPR 2.7, 13.5.3.4 documents that this should
126 * result in an RTAS return code of -3 / "no such indicator"
129 return RTAS_OUT_NO_SUCH_INDICATOR
;
133 if (drc
->type
!= SPAPR_DR_CONNECTOR_TYPE_PCI
) {
134 drc
->allocation_state
= state
;
135 if (drc
->awaiting_release
&&
136 drc
->allocation_state
== SPAPR_DR_ALLOCATION_STATE_UNUSABLE
) {
137 DPRINTFN("finalizing device removal");
138 drck
->detach(drc
, DEVICE(drc
->dev
), drc
->detach_cb
,
139 drc
->detach_cb_opaque
, NULL
);
142 return RTAS_OUT_SUCCESS
;
145 static uint32_t get_type(sPAPRDRConnector
*drc
)
150 static const char *get_name(sPAPRDRConnector
*drc
)
155 static const void *get_fdt(sPAPRDRConnector
*drc
, int *fdt_start_offset
)
157 if (fdt_start_offset
) {
158 *fdt_start_offset
= drc
->fdt_start_offset
;
163 static void set_configured(sPAPRDRConnector
*drc
)
165 DPRINTFN("drc: %x, set_configured", get_index(drc
));
167 if (drc
->isolation_state
!= SPAPR_DR_ISOLATION_STATE_UNISOLATED
) {
168 /* guest should be not configuring an isolated device */
169 DPRINTFN("drc: %x, set_configured: skipping isolated device",
173 drc
->configured
= true;
177 * dr-entity-sense sensor value
178 * returned via get-sensor-state RTAS calls
179 * as expected by state diagram in PAPR+ 2.7, 13.4
180 * based on the current allocation/indicator/power states
181 * for the DR connector.
183 static uint32_t entity_sense(sPAPRDRConnector
*drc
, sPAPRDREntitySense
*state
)
186 if (drc
->type
!= SPAPR_DR_CONNECTOR_TYPE_PCI
&&
187 drc
->allocation_state
== SPAPR_DR_ALLOCATION_STATE_UNUSABLE
) {
188 /* for logical DR, we return a state of UNUSABLE
189 * iff the allocation state UNUSABLE.
190 * Otherwise, report the state as USABLE/PRESENT,
191 * as we would for PCI.
193 *state
= SPAPR_DR_ENTITY_SENSE_UNUSABLE
;
195 /* this assumes all PCI devices are assigned to
196 * a 'live insertion' power domain, where QEMU
197 * manages power state automatically as opposed
198 * to the guest. present, non-PCI resources are
199 * unaffected by power state.
201 *state
= SPAPR_DR_ENTITY_SENSE_PRESENT
;
204 if (drc
->type
== SPAPR_DR_CONNECTOR_TYPE_PCI
) {
205 /* PCI devices, and only PCI devices, use EMPTY
206 * in cases where we'd otherwise use UNUSABLE
208 *state
= SPAPR_DR_ENTITY_SENSE_EMPTY
;
210 *state
= SPAPR_DR_ENTITY_SENSE_UNUSABLE
;
214 DPRINTFN("drc: %x, entity_sense: %x", get_index(drc
), state
);
215 return RTAS_OUT_SUCCESS
;
218 static void prop_get_index(Object
*obj
, Visitor
*v
, const char *name
,
219 void *opaque
, Error
**errp
)
221 sPAPRDRConnector
*drc
= SPAPR_DR_CONNECTOR(obj
);
222 sPAPRDRConnectorClass
*drck
= SPAPR_DR_CONNECTOR_GET_CLASS(drc
);
223 uint32_t value
= (uint32_t)drck
->get_index(drc
);
224 visit_type_uint32(v
, name
, &value
, errp
);
227 static void prop_get_type(Object
*obj
, Visitor
*v
, const char *name
,
228 void *opaque
, Error
**errp
)
230 sPAPRDRConnector
*drc
= SPAPR_DR_CONNECTOR(obj
);
231 sPAPRDRConnectorClass
*drck
= SPAPR_DR_CONNECTOR_GET_CLASS(drc
);
232 uint32_t value
= (uint32_t)drck
->get_type(drc
);
233 visit_type_uint32(v
, name
, &value
, errp
);
236 static char *prop_get_name(Object
*obj
, Error
**errp
)
238 sPAPRDRConnector
*drc
= SPAPR_DR_CONNECTOR(obj
);
239 sPAPRDRConnectorClass
*drck
= SPAPR_DR_CONNECTOR_GET_CLASS(drc
);
240 return g_strdup(drck
->get_name(drc
));
243 static void prop_get_entity_sense(Object
*obj
, Visitor
*v
, const char *name
,
244 void *opaque
, Error
**errp
)
246 sPAPRDRConnector
*drc
= SPAPR_DR_CONNECTOR(obj
);
247 sPAPRDRConnectorClass
*drck
= SPAPR_DR_CONNECTOR_GET_CLASS(drc
);
250 drck
->entity_sense(drc
, &value
);
251 visit_type_uint32(v
, name
, &value
, errp
);
254 static void prop_get_fdt(Object
*obj
, Visitor
*v
, const char *name
,
255 void *opaque
, Error
**errp
)
257 sPAPRDRConnector
*drc
= SPAPR_DR_CONNECTOR(obj
);
259 int fdt_offset_next
, fdt_offset
, fdt_depth
;
263 visit_start_struct(v
, name
, NULL
, 0, &err
);
265 visit_end_struct(v
, &err
);
267 error_propagate(errp
, err
);
272 fdt_offset
= drc
->fdt_start_offset
;
276 const char *name
= NULL
;
277 const struct fdt_property
*prop
= NULL
;
278 int prop_len
= 0, name_len
= 0;
281 tag
= fdt_next_tag(fdt
, fdt_offset
, &fdt_offset_next
);
285 name
= fdt_get_name(fdt
, fdt_offset
, &name_len
);
286 visit_start_struct(v
, name
, NULL
, 0, &err
);
288 error_propagate(errp
, err
);
293 /* shouldn't ever see an FDT_END_NODE before FDT_BEGIN_NODE */
294 g_assert(fdt_depth
> 0);
295 visit_end_struct(v
, &err
);
297 error_propagate(errp
, err
);
304 prop
= fdt_get_property_by_offset(fdt
, fdt_offset
, &prop_len
);
305 name
= fdt_string(fdt
, fdt32_to_cpu(prop
->nameoff
));
306 visit_start_list(v
, name
, &err
);
308 error_propagate(errp
, err
);
311 for (i
= 0; i
< prop_len
; i
++) {
312 visit_type_uint8(v
, NULL
, (uint8_t *)&prop
->data
[i
], &err
);
314 error_propagate(errp
, err
);
322 error_setg(&error_abort
, "device FDT in unexpected state: %d", tag
);
324 fdt_offset
= fdt_offset_next
;
325 } while (fdt_depth
!= 0);
328 static void attach(sPAPRDRConnector
*drc
, DeviceState
*d
, void *fdt
,
329 int fdt_start_offset
, bool coldplug
, Error
**errp
)
331 DPRINTFN("drc: %x, attach", get_index(drc
));
333 if (drc
->isolation_state
!= SPAPR_DR_ISOLATION_STATE_ISOLATED
) {
334 error_setg(errp
, "an attached device is still awaiting release");
337 if (drc
->type
== SPAPR_DR_CONNECTOR_TYPE_PCI
) {
338 g_assert(drc
->allocation_state
== SPAPR_DR_ALLOCATION_STATE_USABLE
);
340 g_assert(fdt
|| coldplug
);
342 /* NOTE: setting initial isolation state to UNISOLATED means we can't
343 * detach unless guest has a userspace/kernel that moves this state
344 * back to ISOLATED in response to an unplug event, or this is done
345 * manually by the admin prior. if we force things while the guest
346 * may be accessing the device, we can easily crash the guest, so we
347 * we defer completion of removal in such cases to the reset() hook.
349 if (drc
->type
== SPAPR_DR_CONNECTOR_TYPE_PCI
) {
350 drc
->isolation_state
= SPAPR_DR_ISOLATION_STATE_UNISOLATED
;
352 drc
->indicator_state
= SPAPR_DR_INDICATOR_STATE_ACTIVE
;
356 drc
->fdt_start_offset
= fdt_start_offset
;
357 drc
->configured
= coldplug
;
359 object_property_add_link(OBJECT(drc
), "device",
360 object_get_typename(OBJECT(drc
->dev
)),
361 (Object
**)(&drc
->dev
),
365 static void detach(sPAPRDRConnector
*drc
, DeviceState
*d
,
366 spapr_drc_detach_cb
*detach_cb
,
367 void *detach_cb_opaque
, Error
**errp
)
369 DPRINTFN("drc: %x, detach", get_index(drc
));
371 drc
->detach_cb
= detach_cb
;
372 drc
->detach_cb_opaque
= detach_cb_opaque
;
374 if (drc
->isolation_state
!= SPAPR_DR_ISOLATION_STATE_ISOLATED
) {
375 DPRINTFN("awaiting transition to isolated state before removal");
376 drc
->awaiting_release
= true;
380 if (drc
->type
!= SPAPR_DR_CONNECTOR_TYPE_PCI
&&
381 drc
->allocation_state
!= SPAPR_DR_ALLOCATION_STATE_UNUSABLE
) {
382 DPRINTFN("awaiting transition to unusable state before removal");
383 drc
->awaiting_release
= true;
387 drc
->indicator_state
= SPAPR_DR_INDICATOR_STATE_INACTIVE
;
389 if (drc
->detach_cb
) {
390 drc
->detach_cb(drc
->dev
, drc
->detach_cb_opaque
);
393 drc
->awaiting_release
= false;
396 drc
->fdt_start_offset
= 0;
397 object_property_del(OBJECT(drc
), "device", NULL
);
399 drc
->detach_cb
= NULL
;
400 drc
->detach_cb_opaque
= NULL
;
403 static bool release_pending(sPAPRDRConnector
*drc
)
405 return drc
->awaiting_release
;
408 static void reset(DeviceState
*d
)
410 sPAPRDRConnector
*drc
= SPAPR_DR_CONNECTOR(d
);
411 sPAPRDRConnectorClass
*drck
= SPAPR_DR_CONNECTOR_GET_CLASS(drc
);
413 DPRINTFN("drc reset: %x", drck
->get_index(drc
));
414 /* immediately upon reset we can safely assume DRCs whose devices
415 * are pending removal can be safely removed, and that they will
416 * subsequently be left in an ISOLATED state. move the DRC to this
417 * state in these cases (which will in turn complete any pending
420 if (drc
->awaiting_release
) {
421 drck
->set_isolation_state(drc
, SPAPR_DR_ISOLATION_STATE_ISOLATED
);
422 /* generally this should also finalize the removal, but if the device
423 * hasn't yet been configured we normally defer removal under the
424 * assumption that this transition is taking place as part of device
425 * configuration. so check if we're still waiting after this, and
426 * force removal if we are
428 if (drc
->awaiting_release
) {
429 drck
->detach(drc
, DEVICE(drc
->dev
), drc
->detach_cb
,
430 drc
->detach_cb_opaque
, NULL
);
433 /* non-PCI devices may be awaiting a transition to UNUSABLE */
434 if (drc
->type
!= SPAPR_DR_CONNECTOR_TYPE_PCI
&&
435 drc
->awaiting_release
) {
436 drck
->set_allocation_state(drc
, SPAPR_DR_ALLOCATION_STATE_UNUSABLE
);
441 static void realize(DeviceState
*d
, Error
**errp
)
443 sPAPRDRConnector
*drc
= SPAPR_DR_CONNECTOR(d
);
444 sPAPRDRConnectorClass
*drck
= SPAPR_DR_CONNECTOR_GET_CLASS(drc
);
445 Object
*root_container
;
450 DPRINTFN("drc realize: %x", drck
->get_index(drc
));
451 /* NOTE: we do this as part of realize/unrealize due to the fact
452 * that the guest will communicate with the DRC via RTAS calls
453 * referencing the global DRC index. By unlinking the DRC
454 * from DRC_CONTAINER_PATH/<drc_index> we effectively make it
455 * inaccessible by the guest, since lookups rely on this path
456 * existing in the composition tree
458 root_container
= container_get(object_get_root(), DRC_CONTAINER_PATH
);
459 snprintf(link_name
, sizeof(link_name
), "%x", drck
->get_index(drc
));
460 child_name
= object_get_canonical_path_component(OBJECT(drc
));
461 DPRINTFN("drc child name: %s", child_name
);
462 object_property_add_alias(root_container
, link_name
,
463 drc
->owner
, child_name
, &err
);
465 error_report_err(err
);
466 object_unref(OBJECT(drc
));
469 DPRINTFN("drc realize complete");
472 static void unrealize(DeviceState
*d
, Error
**errp
)
474 sPAPRDRConnector
*drc
= SPAPR_DR_CONNECTOR(d
);
475 sPAPRDRConnectorClass
*drck
= SPAPR_DR_CONNECTOR_GET_CLASS(drc
);
476 Object
*root_container
;
480 DPRINTFN("drc unrealize: %x", drck
->get_index(drc
));
481 root_container
= container_get(object_get_root(), DRC_CONTAINER_PATH
);
482 snprintf(name
, sizeof(name
), "%x", drck
->get_index(drc
));
483 object_property_del(root_container
, name
, &err
);
485 error_report_err(err
);
486 object_unref(OBJECT(drc
));
490 sPAPRDRConnector
*spapr_dr_connector_new(Object
*owner
,
491 sPAPRDRConnectorType type
,
494 sPAPRDRConnector
*drc
=
495 SPAPR_DR_CONNECTOR(object_new(TYPE_SPAPR_DR_CONNECTOR
));
503 prop_name
= g_strdup_printf("dr-connector[%"PRIu32
"]", get_index(drc
));
504 object_property_add_child(owner
, prop_name
, OBJECT(drc
), NULL
);
505 object_property_set_bool(OBJECT(drc
), true, "realized", NULL
);
508 /* human-readable name for a DRC to encode into the DT
509 * description. this is mainly only used within a guest in place
510 * of the unique DRC index.
512 * in the case of VIO/PCI devices, it corresponds to a
513 * "location code" that maps a logical device/function (DRC index)
514 * to a physical (or virtual in the case of VIO) location in the
515 * system by chaining together the "location label" for each
516 * encapsulating component.
518 * since this is more to do with diagnosing physical hardware
519 * issues than guest compatibility, we choose location codes/DRC
520 * names that adhere to the documented format, but avoid encoding
521 * the entire topology information into the label/code, instead
522 * just using the location codes based on the labels for the
523 * endpoints (VIO/PCI adaptor connectors), which is basically
524 * just "C" followed by an integer ID.
526 * DRC names as documented by PAPR+ v2.7, 13.5.2.4
527 * location codes as documented by PAPR+ v2.7, 12.3.1.5
530 case SPAPR_DR_CONNECTOR_TYPE_CPU
:
531 drc
->name
= g_strdup_printf("CPU %d", id
);
533 case SPAPR_DR_CONNECTOR_TYPE_PHB
:
534 drc
->name
= g_strdup_printf("PHB %d", id
);
536 case SPAPR_DR_CONNECTOR_TYPE_VIO
:
537 case SPAPR_DR_CONNECTOR_TYPE_PCI
:
538 drc
->name
= g_strdup_printf("C%d", id
);
540 case SPAPR_DR_CONNECTOR_TYPE_LMB
:
541 drc
->name
= g_strdup_printf("LMB %d", id
);
547 /* PCI slot always start in a USABLE state, and stay there */
548 if (drc
->type
== SPAPR_DR_CONNECTOR_TYPE_PCI
) {
549 drc
->allocation_state
= SPAPR_DR_ALLOCATION_STATE_USABLE
;
555 static void spapr_dr_connector_instance_init(Object
*obj
)
557 sPAPRDRConnector
*drc
= SPAPR_DR_CONNECTOR(obj
);
559 object_property_add_uint32_ptr(obj
, "isolation-state",
560 &drc
->isolation_state
, NULL
);
561 object_property_add_uint32_ptr(obj
, "indicator-state",
562 &drc
->indicator_state
, NULL
);
563 object_property_add_uint32_ptr(obj
, "allocation-state",
564 &drc
->allocation_state
, NULL
);
565 object_property_add_uint32_ptr(obj
, "id", &drc
->id
, NULL
);
566 object_property_add(obj
, "index", "uint32", prop_get_index
,
567 NULL
, NULL
, NULL
, NULL
);
568 object_property_add(obj
, "connector_type", "uint32", prop_get_type
,
569 NULL
, NULL
, NULL
, NULL
);
570 object_property_add_str(obj
, "name", prop_get_name
, NULL
, NULL
);
571 object_property_add(obj
, "entity-sense", "uint32", prop_get_entity_sense
,
572 NULL
, NULL
, NULL
, NULL
);
573 object_property_add(obj
, "fdt", "struct", prop_get_fdt
,
574 NULL
, NULL
, NULL
, NULL
);
577 static void spapr_dr_connector_class_init(ObjectClass
*k
, void *data
)
579 DeviceClass
*dk
= DEVICE_CLASS(k
);
580 sPAPRDRConnectorClass
*drck
= SPAPR_DR_CONNECTOR_CLASS(k
);
583 dk
->realize
= realize
;
584 dk
->unrealize
= unrealize
;
585 drck
->set_isolation_state
= set_isolation_state
;
586 drck
->set_indicator_state
= set_indicator_state
;
587 drck
->set_allocation_state
= set_allocation_state
;
588 drck
->get_index
= get_index
;
589 drck
->get_type
= get_type
;
590 drck
->get_name
= get_name
;
591 drck
->get_fdt
= get_fdt
;
592 drck
->set_configured
= set_configured
;
593 drck
->entity_sense
= entity_sense
;
594 drck
->attach
= attach
;
595 drck
->detach
= detach
;
596 drck
->release_pending
= release_pending
;
598 * Reason: it crashes FIXME find and document the real reason
600 dk
->cannot_instantiate_with_device_add_yet
= true;
603 static const TypeInfo spapr_dr_connector_info
= {
604 .name
= TYPE_SPAPR_DR_CONNECTOR
,
605 .parent
= TYPE_DEVICE
,
606 .instance_size
= sizeof(sPAPRDRConnector
),
607 .instance_init
= spapr_dr_connector_instance_init
,
608 .class_size
= sizeof(sPAPRDRConnectorClass
),
609 .class_init
= spapr_dr_connector_class_init
,
612 static void spapr_drc_register_types(void)
614 type_register_static(&spapr_dr_connector_info
);
617 type_init(spapr_drc_register_types
)
619 /* helper functions for external users */
621 sPAPRDRConnector
*spapr_dr_connector_by_index(uint32_t index
)
626 snprintf(name
, sizeof(name
), "%s/%x", DRC_CONTAINER_PATH
, index
);
627 obj
= object_resolve_path(name
, NULL
);
629 return !obj
? NULL
: SPAPR_DR_CONNECTOR(obj
);
632 sPAPRDRConnector
*spapr_dr_connector_by_id(sPAPRDRConnectorType type
,
635 return spapr_dr_connector_by_index(
636 (get_type_shift(type
) << DRC_INDEX_TYPE_SHIFT
) |
637 (id
& DRC_INDEX_ID_MASK
));
640 /* generate a string the describes the DRC to encode into the
643 * as documented by PAPR+ v2.7, 13.5.2.6 and C.6.1
645 static const char *spapr_drc_get_type_str(sPAPRDRConnectorType type
)
648 case SPAPR_DR_CONNECTOR_TYPE_CPU
:
650 case SPAPR_DR_CONNECTOR_TYPE_PHB
:
652 case SPAPR_DR_CONNECTOR_TYPE_VIO
:
654 case SPAPR_DR_CONNECTOR_TYPE_PCI
:
656 case SPAPR_DR_CONNECTOR_TYPE_LMB
:
666 * spapr_drc_populate_dt
668 * @fdt: libfdt device tree
669 * @path: path in the DT to generate properties
670 * @owner: parent Object/DeviceState for which to generate DRC
672 * @drc_type_mask: mask of sPAPRDRConnectorType values corresponding
673 * to the types of DRCs to generate entries for
675 * generate OF properties to describe DRC topology/indices to guests
677 * as documented in PAPR+ v2.1, 13.5.2
679 int spapr_drc_populate_dt(void *fdt
, int fdt_offset
, Object
*owner
,
680 uint32_t drc_type_mask
)
682 Object
*root_container
;
683 ObjectProperty
*prop
;
684 ObjectPropertyIterator iter
;
685 uint32_t drc_count
= 0;
686 GArray
*drc_indexes
, *drc_power_domains
;
687 GString
*drc_names
, *drc_types
;
690 /* the first entry of each properties is a 32-bit integer encoding
691 * the number of elements in the array. we won't know this until
692 * we complete the iteration through all the matching DRCs, but
693 * reserve the space now and set the offsets accordingly so we
694 * can fill them in later.
696 drc_indexes
= g_array_new(false, true, sizeof(uint32_t));
697 drc_indexes
= g_array_set_size(drc_indexes
, 1);
698 drc_power_domains
= g_array_new(false, true, sizeof(uint32_t));
699 drc_power_domains
= g_array_set_size(drc_power_domains
, 1);
700 drc_names
= g_string_set_size(g_string_new(NULL
), sizeof(uint32_t));
701 drc_types
= g_string_set_size(g_string_new(NULL
), sizeof(uint32_t));
703 /* aliases for all DRConnector objects will be rooted in QOM
704 * composition tree at DRC_CONTAINER_PATH
706 root_container
= container_get(object_get_root(), DRC_CONTAINER_PATH
);
708 object_property_iter_init(&iter
, root_container
);
709 while ((prop
= object_property_iter_next(&iter
))) {
711 sPAPRDRConnector
*drc
;
712 sPAPRDRConnectorClass
*drck
;
713 uint32_t drc_index
, drc_power_domain
;
715 if (!strstart(prop
->type
, "link<", NULL
)) {
719 obj
= object_property_get_link(root_container
, prop
->name
, NULL
);
720 drc
= SPAPR_DR_CONNECTOR(obj
);
721 drck
= SPAPR_DR_CONNECTOR_GET_CLASS(drc
);
723 if (owner
&& (drc
->owner
!= owner
)) {
727 if ((drc
->type
& drc_type_mask
) == 0) {
733 /* ibm,drc-indexes */
734 drc_index
= cpu_to_be32(drck
->get_index(drc
));
735 g_array_append_val(drc_indexes
, drc_index
);
737 /* ibm,drc-power-domains */
738 drc_power_domain
= cpu_to_be32(-1);
739 g_array_append_val(drc_power_domains
, drc_power_domain
);
742 drc_names
= g_string_append(drc_names
, drck
->get_name(drc
));
743 drc_names
= g_string_insert_len(drc_names
, -1, "\0", 1);
746 drc_types
= g_string_append(drc_types
,
747 spapr_drc_get_type_str(drc
->type
));
748 drc_types
= g_string_insert_len(drc_types
, -1, "\0", 1);
751 /* now write the drc count into the space we reserved at the
752 * beginning of the arrays previously
754 *(uint32_t *)drc_indexes
->data
= cpu_to_be32(drc_count
);
755 *(uint32_t *)drc_power_domains
->data
= cpu_to_be32(drc_count
);
756 *(uint32_t *)drc_names
->str
= cpu_to_be32(drc_count
);
757 *(uint32_t *)drc_types
->str
= cpu_to_be32(drc_count
);
759 ret
= fdt_setprop(fdt
, fdt_offset
, "ibm,drc-indexes",
761 drc_indexes
->len
* sizeof(uint32_t));
763 fprintf(stderr
, "Couldn't create ibm,drc-indexes property\n");
767 ret
= fdt_setprop(fdt
, fdt_offset
, "ibm,drc-power-domains",
768 drc_power_domains
->data
,
769 drc_power_domains
->len
* sizeof(uint32_t));
771 fprintf(stderr
, "Couldn't finalize ibm,drc-power-domains property\n");
775 ret
= fdt_setprop(fdt
, fdt_offset
, "ibm,drc-names",
776 drc_names
->str
, drc_names
->len
);
778 fprintf(stderr
, "Couldn't finalize ibm,drc-names property\n");
782 ret
= fdt_setprop(fdt
, fdt_offset
, "ibm,drc-types",
783 drc_types
->str
, drc_types
->len
);
785 fprintf(stderr
, "Couldn't finalize ibm,drc-types property\n");
790 g_array_free(drc_indexes
, true);
791 g_array_free(drc_power_domains
, true);
792 g_string_free(drc_names
, true);
793 g_string_free(drc_types
, true);