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 "hw/ppc/spapr_drc.h"
14 #include "qom/object.h"
16 #include "qapi/visitor.h"
17 #include "qemu/error-report.h"
19 /* #define DEBUG_SPAPR_DRC */
21 #ifdef DEBUG_SPAPR_DRC
22 #define DPRINTF(fmt, ...) \
23 do { fprintf(stderr, fmt, ## __VA_ARGS__); } while (0)
24 #define DPRINTFN(fmt, ...) \
25 do { DPRINTF(fmt, ## __VA_ARGS__); fprintf(stderr, "\n"); } while (0)
27 #define DPRINTF(fmt, ...) \
29 #define DPRINTFN(fmt, ...) \
33 #define DRC_CONTAINER_PATH "/dr-connector"
34 #define DRC_INDEX_TYPE_SHIFT 28
35 #define DRC_INDEX_ID_MASK (~(~0 << DRC_INDEX_TYPE_SHIFT))
37 static sPAPRDRConnectorTypeShift
get_type_shift(sPAPRDRConnectorType type
)
41 /* make sure this isn't SPAPR_DR_CONNECTOR_TYPE_ANY, or some
44 g_assert(is_power_of_2(type
));
46 while (type
!= (1 << shift
)) {
52 static uint32_t get_index(sPAPRDRConnector
*drc
)
54 /* no set format for a drc index: it only needs to be globally
55 * unique. this is how we encode the DRC type on bare-metal
56 * however, so might as well do that here
58 return (get_type_shift(drc
->type
) << DRC_INDEX_TYPE_SHIFT
) |
59 (drc
->id
& DRC_INDEX_ID_MASK
);
62 static int set_isolation_state(sPAPRDRConnector
*drc
,
63 sPAPRDRIsolationState state
)
65 sPAPRDRConnectorClass
*drck
= SPAPR_DR_CONNECTOR_GET_CLASS(drc
);
67 DPRINTFN("drc: %x, set_isolation_state: %x", get_index(drc
), state
);
69 drc
->isolation_state
= state
;
71 if (drc
->isolation_state
== SPAPR_DR_ISOLATION_STATE_ISOLATED
) {
72 /* if we're awaiting release, but still in an unconfigured state,
73 * it's likely the guest is still in the process of configuring
74 * the device and is transitioning the devices to an ISOLATED
75 * state as a part of that process. so we only complete the
76 * removal when this transition happens for a device in a
77 * configured state, as suggested by the state diagram from
80 if (drc
->awaiting_release
) {
81 if (drc
->configured
) {
82 DPRINTFN("finalizing device removal");
83 drck
->detach(drc
, DEVICE(drc
->dev
), drc
->detach_cb
,
84 drc
->detach_cb_opaque
, NULL
);
86 DPRINTFN("deferring device removal on unconfigured device\n");
89 drc
->configured
= false;
95 static int set_indicator_state(sPAPRDRConnector
*drc
,
96 sPAPRDRIndicatorState state
)
98 DPRINTFN("drc: %x, set_indicator_state: %x", get_index(drc
), state
);
99 drc
->indicator_state
= state
;
103 static int set_allocation_state(sPAPRDRConnector
*drc
,
104 sPAPRDRAllocationState state
)
106 sPAPRDRConnectorClass
*drck
= SPAPR_DR_CONNECTOR_GET_CLASS(drc
);
108 DPRINTFN("drc: %x, set_allocation_state: %x", get_index(drc
), state
);
110 if (drc
->type
!= SPAPR_DR_CONNECTOR_TYPE_PCI
) {
111 drc
->allocation_state
= state
;
112 if (drc
->awaiting_release
&&
113 drc
->allocation_state
== SPAPR_DR_ALLOCATION_STATE_UNUSABLE
) {
114 DPRINTFN("finalizing device removal");
115 drck
->detach(drc
, DEVICE(drc
->dev
), drc
->detach_cb
,
116 drc
->detach_cb_opaque
, NULL
);
122 static uint32_t get_type(sPAPRDRConnector
*drc
)
127 static const char *get_name(sPAPRDRConnector
*drc
)
132 static const void *get_fdt(sPAPRDRConnector
*drc
, int *fdt_start_offset
)
134 if (fdt_start_offset
) {
135 *fdt_start_offset
= drc
->fdt_start_offset
;
140 static void set_configured(sPAPRDRConnector
*drc
)
142 DPRINTFN("drc: %x, set_configured", get_index(drc
));
144 if (drc
->isolation_state
!= SPAPR_DR_ISOLATION_STATE_UNISOLATED
) {
145 /* guest should be not configuring an isolated device */
146 DPRINTFN("drc: %x, set_configured: skipping isolated device",
150 drc
->configured
= true;
154 * dr-entity-sense sensor value
155 * returned via get-sensor-state RTAS calls
156 * as expected by state diagram in PAPR+ 2.7, 13.4
157 * based on the current allocation/indicator/power states
158 * for the DR connector.
160 static sPAPRDREntitySense
entity_sense(sPAPRDRConnector
*drc
)
162 sPAPRDREntitySense state
;
165 if (drc
->type
!= SPAPR_DR_CONNECTOR_TYPE_PCI
&&
166 drc
->allocation_state
== SPAPR_DR_ALLOCATION_STATE_UNUSABLE
) {
167 /* for logical DR, we return a state of UNUSABLE
168 * iff the allocation state UNUSABLE.
169 * Otherwise, report the state as USABLE/PRESENT,
170 * as we would for PCI.
172 state
= SPAPR_DR_ENTITY_SENSE_UNUSABLE
;
174 /* this assumes all PCI devices are assigned to
175 * a 'live insertion' power domain, where QEMU
176 * manages power state automatically as opposed
177 * to the guest. present, non-PCI resources are
178 * unaffected by power state.
180 state
= SPAPR_DR_ENTITY_SENSE_PRESENT
;
183 if (drc
->type
== SPAPR_DR_CONNECTOR_TYPE_PCI
) {
184 /* PCI devices, and only PCI devices, use EMPTY
185 * in cases where we'd otherwise use UNUSABLE
187 state
= SPAPR_DR_ENTITY_SENSE_EMPTY
;
189 state
= SPAPR_DR_ENTITY_SENSE_UNUSABLE
;
193 DPRINTFN("drc: %x, entity_sense: %x", get_index(drc
), state
);
197 static void prop_get_index(Object
*obj
, Visitor
*v
, void *opaque
,
198 const char *name
, Error
**errp
)
200 sPAPRDRConnector
*drc
= SPAPR_DR_CONNECTOR(obj
);
201 sPAPRDRConnectorClass
*drck
= SPAPR_DR_CONNECTOR_GET_CLASS(drc
);
202 uint32_t value
= (uint32_t)drck
->get_index(drc
);
203 visit_type_uint32(v
, &value
, name
, errp
);
206 static void prop_get_type(Object
*obj
, Visitor
*v
, void *opaque
,
207 const char *name
, Error
**errp
)
209 sPAPRDRConnector
*drc
= SPAPR_DR_CONNECTOR(obj
);
210 sPAPRDRConnectorClass
*drck
= SPAPR_DR_CONNECTOR_GET_CLASS(drc
);
211 uint32_t value
= (uint32_t)drck
->get_type(drc
);
212 visit_type_uint32(v
, &value
, name
, errp
);
215 static char *prop_get_name(Object
*obj
, Error
**errp
)
217 sPAPRDRConnector
*drc
= SPAPR_DR_CONNECTOR(obj
);
218 sPAPRDRConnectorClass
*drck
= SPAPR_DR_CONNECTOR_GET_CLASS(drc
);
219 return g_strdup(drck
->get_name(drc
));
222 static void prop_get_entity_sense(Object
*obj
, Visitor
*v
, void *opaque
,
223 const char *name
, Error
**errp
)
225 sPAPRDRConnector
*drc
= SPAPR_DR_CONNECTOR(obj
);
226 sPAPRDRConnectorClass
*drck
= SPAPR_DR_CONNECTOR_GET_CLASS(drc
);
227 uint32_t value
= (uint32_t)drck
->entity_sense(drc
);
228 visit_type_uint32(v
, &value
, name
, errp
);
231 static void prop_get_fdt(Object
*obj
, Visitor
*v
, void *opaque
,
232 const char *name
, Error
**errp
)
234 sPAPRDRConnector
*drc
= SPAPR_DR_CONNECTOR(obj
);
235 int fdt_offset_next
, fdt_offset
, fdt_depth
;
243 fdt_offset
= drc
->fdt_start_offset
;
247 const char *name
= NULL
;
248 const struct fdt_property
*prop
= NULL
;
249 int prop_len
= 0, name_len
= 0;
252 tag
= fdt_next_tag(fdt
, fdt_offset
, &fdt_offset_next
);
256 name
= fdt_get_name(fdt
, fdt_offset
, &name_len
);
257 visit_start_struct(v
, NULL
, NULL
, name
, 0, NULL
);
260 /* shouldn't ever see an FDT_END_NODE before FDT_BEGIN_NODE */
261 g_assert(fdt_depth
> 0);
262 visit_end_struct(v
, NULL
);
267 prop
= fdt_get_property_by_offset(fdt
, fdt_offset
, &prop_len
);
268 name
= fdt_string(fdt
, fdt32_to_cpu(prop
->nameoff
));
269 visit_start_list(v
, name
, NULL
);
270 for (i
= 0; i
< prop_len
; i
++) {
271 visit_type_uint8(v
, (uint8_t *)&prop
->data
[i
], NULL
, NULL
);
274 visit_end_list(v
, NULL
);
278 error_setg(&error_abort
, "device FDT in unexpected state: %d", tag
);
280 fdt_offset
= fdt_offset_next
;
281 } while (fdt_depth
!= 0);
284 static void attach(sPAPRDRConnector
*drc
, DeviceState
*d
, void *fdt
,
285 int fdt_start_offset
, bool coldplug
, Error
**errp
)
287 DPRINTFN("drc: %x, attach", get_index(drc
));
289 if (drc
->isolation_state
!= SPAPR_DR_ISOLATION_STATE_ISOLATED
) {
290 error_setg(errp
, "an attached device is still awaiting release");
293 if (drc
->type
== SPAPR_DR_CONNECTOR_TYPE_PCI
) {
294 g_assert(drc
->allocation_state
== SPAPR_DR_ALLOCATION_STATE_USABLE
);
296 g_assert(fdt
|| coldplug
);
298 /* NOTE: setting initial isolation state to UNISOLATED means we can't
299 * detach unless guest has a userspace/kernel that moves this state
300 * back to ISOLATED in response to an unplug event, or this is done
301 * manually by the admin prior. if we force things while the guest
302 * may be accessing the device, we can easily crash the guest, so we
303 * we defer completion of removal in such cases to the reset() hook.
305 if (drc
->type
== SPAPR_DR_CONNECTOR_TYPE_PCI
) {
306 drc
->isolation_state
= SPAPR_DR_ISOLATION_STATE_UNISOLATED
;
308 drc
->indicator_state
= SPAPR_DR_INDICATOR_STATE_ACTIVE
;
312 drc
->fdt_start_offset
= fdt_start_offset
;
313 drc
->configured
= false;
315 object_property_add_link(OBJECT(drc
), "device",
316 object_get_typename(OBJECT(drc
->dev
)),
317 (Object
**)(&drc
->dev
),
321 static void detach(sPAPRDRConnector
*drc
, DeviceState
*d
,
322 spapr_drc_detach_cb
*detach_cb
,
323 void *detach_cb_opaque
, Error
**errp
)
325 DPRINTFN("drc: %x, detach", get_index(drc
));
327 drc
->detach_cb
= detach_cb
;
328 drc
->detach_cb_opaque
= detach_cb_opaque
;
330 if (drc
->isolation_state
!= SPAPR_DR_ISOLATION_STATE_ISOLATED
) {
331 DPRINTFN("awaiting transition to isolated state before removal");
332 drc
->awaiting_release
= true;
336 if (drc
->type
!= SPAPR_DR_CONNECTOR_TYPE_PCI
&&
337 drc
->allocation_state
!= SPAPR_DR_ALLOCATION_STATE_UNUSABLE
) {
338 DPRINTFN("awaiting transition to unusable state before removal");
339 drc
->awaiting_release
= true;
343 drc
->indicator_state
= SPAPR_DR_INDICATOR_STATE_INACTIVE
;
345 if (drc
->detach_cb
) {
346 drc
->detach_cb(drc
->dev
, drc
->detach_cb_opaque
);
349 drc
->awaiting_release
= false;
352 drc
->fdt_start_offset
= 0;
353 object_property_del(OBJECT(drc
), "device", NULL
);
355 drc
->detach_cb
= NULL
;
356 drc
->detach_cb_opaque
= NULL
;
359 static bool release_pending(sPAPRDRConnector
*drc
)
361 return drc
->awaiting_release
;
364 static void reset(DeviceState
*d
)
366 sPAPRDRConnector
*drc
= SPAPR_DR_CONNECTOR(d
);
367 sPAPRDRConnectorClass
*drck
= SPAPR_DR_CONNECTOR_GET_CLASS(drc
);
369 DPRINTFN("drc reset: %x", drck
->get_index(drc
));
370 /* immediately upon reset we can safely assume DRCs whose devices
371 * are pending removal can be safely removed, and that they will
372 * subsequently be left in an ISOLATED state. move the DRC to this
373 * state in these cases (which will in turn complete any pending
376 if (drc
->awaiting_release
) {
377 drck
->set_isolation_state(drc
, SPAPR_DR_ISOLATION_STATE_ISOLATED
);
378 /* generally this should also finalize the removal, but if the device
379 * hasn't yet been configured we normally defer removal under the
380 * assumption that this transition is taking place as part of device
381 * configuration. so check if we're still waiting after this, and
382 * force removal if we are
384 if (drc
->awaiting_release
) {
385 drck
->detach(drc
, DEVICE(drc
->dev
), drc
->detach_cb
,
386 drc
->detach_cb_opaque
, NULL
);
389 /* non-PCI devices may be awaiting a transition to UNUSABLE */
390 if (drc
->type
!= SPAPR_DR_CONNECTOR_TYPE_PCI
&&
391 drc
->awaiting_release
) {
392 drck
->set_allocation_state(drc
, SPAPR_DR_ALLOCATION_STATE_UNUSABLE
);
397 static void realize(DeviceState
*d
, Error
**errp
)
399 sPAPRDRConnector
*drc
= SPAPR_DR_CONNECTOR(d
);
400 sPAPRDRConnectorClass
*drck
= SPAPR_DR_CONNECTOR_GET_CLASS(drc
);
401 Object
*root_container
;
406 DPRINTFN("drc realize: %x", drck
->get_index(drc
));
407 /* NOTE: we do this as part of realize/unrealize due to the fact
408 * that the guest will communicate with the DRC via RTAS calls
409 * referencing the global DRC index. By unlinking the DRC
410 * from DRC_CONTAINER_PATH/<drc_index> we effectively make it
411 * inaccessible by the guest, since lookups rely on this path
412 * existing in the composition tree
414 root_container
= container_get(object_get_root(), DRC_CONTAINER_PATH
);
415 snprintf(link_name
, sizeof(link_name
), "%x", drck
->get_index(drc
));
416 child_name
= object_get_canonical_path_component(OBJECT(drc
));
417 DPRINTFN("drc child name: %s", child_name
);
418 object_property_add_alias(root_container
, link_name
,
419 drc
->owner
, child_name
, &err
);
421 error_report("%s", error_get_pretty(err
));
423 object_unref(OBJECT(drc
));
426 DPRINTFN("drc realize complete");
429 static void unrealize(DeviceState
*d
, Error
**errp
)
431 sPAPRDRConnector
*drc
= SPAPR_DR_CONNECTOR(d
);
432 sPAPRDRConnectorClass
*drck
= SPAPR_DR_CONNECTOR_GET_CLASS(drc
);
433 Object
*root_container
;
437 DPRINTFN("drc unrealize: %x", drck
->get_index(drc
));
438 root_container
= container_get(object_get_root(), DRC_CONTAINER_PATH
);
439 snprintf(name
, sizeof(name
), "%x", drck
->get_index(drc
));
440 object_property_del(root_container
, name
, &err
);
442 error_report("%s", error_get_pretty(err
));
444 object_unref(OBJECT(drc
));
448 sPAPRDRConnector
*spapr_dr_connector_new(Object
*owner
,
449 sPAPRDRConnectorType type
,
452 sPAPRDRConnector
*drc
=
453 SPAPR_DR_CONNECTOR(object_new(TYPE_SPAPR_DR_CONNECTOR
));
460 object_property_add_child(owner
, "dr-connector[*]", OBJECT(drc
), NULL
);
461 object_property_set_bool(OBJECT(drc
), true, "realized", NULL
);
463 /* human-readable name for a DRC to encode into the DT
464 * description. this is mainly only used within a guest in place
465 * of the unique DRC index.
467 * in the case of VIO/PCI devices, it corresponds to a
468 * "location code" that maps a logical device/function (DRC index)
469 * to a physical (or virtual in the case of VIO) location in the
470 * system by chaining together the "location label" for each
471 * encapsulating component.
473 * since this is more to do with diagnosing physical hardware
474 * issues than guest compatibility, we choose location codes/DRC
475 * names that adhere to the documented format, but avoid encoding
476 * the entire topology information into the label/code, instead
477 * just using the location codes based on the labels for the
478 * endpoints (VIO/PCI adaptor connectors), which is basically
479 * just "C" followed by an integer ID.
481 * DRC names as documented by PAPR+ v2.7, 13.5.2.4
482 * location codes as documented by PAPR+ v2.7, 12.3.1.5
485 case SPAPR_DR_CONNECTOR_TYPE_CPU
:
486 drc
->name
= g_strdup_printf("CPU %d", id
);
488 case SPAPR_DR_CONNECTOR_TYPE_PHB
:
489 drc
->name
= g_strdup_printf("PHB %d", id
);
491 case SPAPR_DR_CONNECTOR_TYPE_VIO
:
492 case SPAPR_DR_CONNECTOR_TYPE_PCI
:
493 drc
->name
= g_strdup_printf("C%d", id
);
495 case SPAPR_DR_CONNECTOR_TYPE_LMB
:
496 drc
->name
= g_strdup_printf("LMB %d", id
);
502 /* PCI slot always start in a USABLE state, and stay there */
503 if (drc
->type
== SPAPR_DR_CONNECTOR_TYPE_PCI
) {
504 drc
->allocation_state
= SPAPR_DR_ALLOCATION_STATE_USABLE
;
510 static void spapr_dr_connector_instance_init(Object
*obj
)
512 sPAPRDRConnector
*drc
= SPAPR_DR_CONNECTOR(obj
);
514 object_property_add_uint32_ptr(obj
, "isolation-state",
515 &drc
->isolation_state
, NULL
);
516 object_property_add_uint32_ptr(obj
, "indicator-state",
517 &drc
->indicator_state
, NULL
);
518 object_property_add_uint32_ptr(obj
, "allocation-state",
519 &drc
->allocation_state
, NULL
);
520 object_property_add_uint32_ptr(obj
, "id", &drc
->id
, NULL
);
521 object_property_add(obj
, "index", "uint32", prop_get_index
,
522 NULL
, NULL
, NULL
, NULL
);
523 object_property_add(obj
, "connector_type", "uint32", prop_get_type
,
524 NULL
, NULL
, NULL
, NULL
);
525 object_property_add_str(obj
, "name", prop_get_name
, NULL
, NULL
);
526 object_property_add(obj
, "entity-sense", "uint32", prop_get_entity_sense
,
527 NULL
, NULL
, NULL
, NULL
);
528 object_property_add(obj
, "fdt", "struct", prop_get_fdt
,
529 NULL
, NULL
, NULL
, NULL
);
532 static void spapr_dr_connector_class_init(ObjectClass
*k
, void *data
)
534 DeviceClass
*dk
= DEVICE_CLASS(k
);
535 sPAPRDRConnectorClass
*drck
= SPAPR_DR_CONNECTOR_CLASS(k
);
538 dk
->realize
= realize
;
539 dk
->unrealize
= unrealize
;
540 drck
->set_isolation_state
= set_isolation_state
;
541 drck
->set_indicator_state
= set_indicator_state
;
542 drck
->set_allocation_state
= set_allocation_state
;
543 drck
->get_index
= get_index
;
544 drck
->get_type
= get_type
;
545 drck
->get_name
= get_name
;
546 drck
->get_fdt
= get_fdt
;
547 drck
->set_configured
= set_configured
;
548 drck
->entity_sense
= entity_sense
;
549 drck
->attach
= attach
;
550 drck
->detach
= detach
;
551 drck
->release_pending
= release_pending
;
554 static const TypeInfo spapr_dr_connector_info
= {
555 .name
= TYPE_SPAPR_DR_CONNECTOR
,
556 .parent
= TYPE_DEVICE
,
557 .instance_size
= sizeof(sPAPRDRConnector
),
558 .instance_init
= spapr_dr_connector_instance_init
,
559 .class_size
= sizeof(sPAPRDRConnectorClass
),
560 .class_init
= spapr_dr_connector_class_init
,
563 static void spapr_drc_register_types(void)
565 type_register_static(&spapr_dr_connector_info
);
568 type_init(spapr_drc_register_types
)
570 /* helper functions for external users */
572 sPAPRDRConnector
*spapr_dr_connector_by_index(uint32_t index
)
577 snprintf(name
, sizeof(name
), "%s/%x", DRC_CONTAINER_PATH
, index
);
578 obj
= object_resolve_path(name
, NULL
);
580 return !obj
? NULL
: SPAPR_DR_CONNECTOR(obj
);
583 sPAPRDRConnector
*spapr_dr_connector_by_id(sPAPRDRConnectorType type
,
586 return spapr_dr_connector_by_index(
587 (get_type_shift(type
) << DRC_INDEX_TYPE_SHIFT
) |
588 (id
& DRC_INDEX_ID_MASK
));
591 /* generate a string the describes the DRC to encode into the
594 * as documented by PAPR+ v2.7, 13.5.2.6 and C.6.1
596 static const char *spapr_drc_get_type_str(sPAPRDRConnectorType type
)
599 case SPAPR_DR_CONNECTOR_TYPE_CPU
:
601 case SPAPR_DR_CONNECTOR_TYPE_PHB
:
603 case SPAPR_DR_CONNECTOR_TYPE_VIO
:
605 case SPAPR_DR_CONNECTOR_TYPE_PCI
:
607 case SPAPR_DR_CONNECTOR_TYPE_LMB
:
617 * spapr_drc_populate_dt
619 * @fdt: libfdt device tree
620 * @path: path in the DT to generate properties
621 * @owner: parent Object/DeviceState for which to generate DRC
623 * @drc_type_mask: mask of sPAPRDRConnectorType values corresponding
624 * to the types of DRCs to generate entries for
626 * generate OF properties to describe DRC topology/indices to guests
628 * as documented in PAPR+ v2.1, 13.5.2
630 int spapr_drc_populate_dt(void *fdt
, int fdt_offset
, Object
*owner
,
631 uint32_t drc_type_mask
)
633 Object
*root_container
;
634 ObjectProperty
*prop
;
635 uint32_t drc_count
= 0;
636 GArray
*drc_indexes
, *drc_power_domains
;
637 GString
*drc_names
, *drc_types
;
640 /* the first entry of each properties is a 32-bit integer encoding
641 * the number of elements in the array. we won't know this until
642 * we complete the iteration through all the matching DRCs, but
643 * reserve the space now and set the offsets accordingly so we
644 * can fill them in later.
646 drc_indexes
= g_array_new(false, true, sizeof(uint32_t));
647 drc_indexes
= g_array_set_size(drc_indexes
, 1);
648 drc_power_domains
= g_array_new(false, true, sizeof(uint32_t));
649 drc_power_domains
= g_array_set_size(drc_power_domains
, 1);
650 drc_names
= g_string_set_size(g_string_new(NULL
), sizeof(uint32_t));
651 drc_types
= g_string_set_size(g_string_new(NULL
), sizeof(uint32_t));
653 /* aliases for all DRConnector objects will be rooted in QOM
654 * composition tree at DRC_CONTAINER_PATH
656 root_container
= container_get(object_get_root(), DRC_CONTAINER_PATH
);
658 QTAILQ_FOREACH(prop
, &root_container
->properties
, node
) {
660 sPAPRDRConnector
*drc
;
661 sPAPRDRConnectorClass
*drck
;
662 uint32_t drc_index
, drc_power_domain
;
664 if (!strstart(prop
->type
, "link<", NULL
)) {
668 obj
= object_property_get_link(root_container
, prop
->name
, NULL
);
669 drc
= SPAPR_DR_CONNECTOR(obj
);
670 drck
= SPAPR_DR_CONNECTOR_GET_CLASS(drc
);
672 if (owner
&& (drc
->owner
!= owner
)) {
676 if ((drc
->type
& drc_type_mask
) == 0) {
682 /* ibm,drc-indexes */
683 drc_index
= cpu_to_be32(drck
->get_index(drc
));
684 g_array_append_val(drc_indexes
, drc_index
);
686 /* ibm,drc-power-domains */
687 drc_power_domain
= cpu_to_be32(-1);
688 g_array_append_val(drc_power_domains
, drc_power_domain
);
691 drc_names
= g_string_append(drc_names
, drck
->get_name(drc
));
692 drc_names
= g_string_insert_len(drc_names
, -1, "\0", 1);
695 drc_types
= g_string_append(drc_types
,
696 spapr_drc_get_type_str(drc
->type
));
697 drc_types
= g_string_insert_len(drc_types
, -1, "\0", 1);
700 /* now write the drc count into the space we reserved at the
701 * beginning of the arrays previously
703 *(uint32_t *)drc_indexes
->data
= cpu_to_be32(drc_count
);
704 *(uint32_t *)drc_power_domains
->data
= cpu_to_be32(drc_count
);
705 *(uint32_t *)drc_names
->str
= cpu_to_be32(drc_count
);
706 *(uint32_t *)drc_types
->str
= cpu_to_be32(drc_count
);
708 ret
= fdt_setprop(fdt
, fdt_offset
, "ibm,drc-indexes",
710 drc_indexes
->len
* sizeof(uint32_t));
712 fprintf(stderr
, "Couldn't create ibm,drc-indexes property\n");
716 ret
= fdt_setprop(fdt
, fdt_offset
, "ibm,drc-power-domains",
717 drc_power_domains
->data
,
718 drc_power_domains
->len
* sizeof(uint32_t));
720 fprintf(stderr
, "Couldn't finalize ibm,drc-power-domains property\n");
724 ret
= fdt_setprop(fdt
, fdt_offset
, "ibm,drc-names",
725 drc_names
->str
, drc_names
->len
);
727 fprintf(stderr
, "Couldn't finalize ibm,drc-names property\n");
731 ret
= fdt_setprop(fdt
, fdt_offset
, "ibm,drc-types",
732 drc_types
->str
, drc_types
->len
);
734 fprintf(stderr
, "Couldn't finalize ibm,drc-types property\n");
739 g_array_free(drc_indexes
, true);
740 g_array_free(drc_power_domains
, true);
741 g_string_free(drc_names
, true);
742 g_string_free(drc_types
, true);