xref: /openbmc/qemu/hw/ppc/spapr_drc.c (revision c63ca4ff)
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     int fdt_offset_next, fdt_offset, fdt_depth;
306     void *fdt;
307 
308     if (!drc->fdt) {
309         visit_type_null(v, NULL, &null, errp);
310         qobject_unref(null);
311         return;
312     }
313 
314     fdt = drc->fdt;
315     fdt_offset = drc->fdt_start_offset;
316     fdt_depth = 0;
317 
318     do {
319         const char *name = NULL;
320         const struct fdt_property *prop = NULL;
321         int prop_len = 0, name_len = 0;
322         uint32_t tag;
323         bool ok;
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, errp)) {
331                 return;
332             }
333             break;
334         case FDT_END_NODE:
335             /* shouldn't ever see an FDT_END_NODE before FDT_BEGIN_NODE */
336             g_assert(fdt_depth > 0);
337             ok = visit_check_struct(v, errp);
338             visit_end_struct(v, NULL);
339             if (!ok) {
340                 return;
341             }
342             fdt_depth--;
343             break;
344         case FDT_PROP: {
345             int i;
346             prop = fdt_get_property_by_offset(fdt, fdt_offset, &prop_len);
347             name = fdt_string(fdt, fdt32_to_cpu(prop->nameoff));
348             if (!visit_start_list(v, name, NULL, 0, errp)) {
349                 return;
350             }
351             for (i = 0; i < prop_len; i++) {
352                 if (!visit_type_uint8(v, NULL, (uint8_t *)&prop->data[i],
353                                       errp)) {
354                     return;
355                 }
356             }
357             ok = visit_check_list(v, errp);
358             visit_end_list(v, NULL);
359             if (!ok) {
360                 return;
361             }
362             break;
363         }
364         default:
365             error_report("device FDT in unexpected state: %d", tag);
366             abort();
367         }
368         fdt_offset = fdt_offset_next;
369     } while (fdt_depth != 0);
370 }
371 
372 void spapr_drc_attach(SpaprDrc *drc, DeviceState *d)
373 {
374     trace_spapr_drc_attach(spapr_drc_index(drc));
375 
376     g_assert(!drc->dev);
377     g_assert((drc->state == SPAPR_DRC_STATE_LOGICAL_UNUSABLE)
378              || (drc->state == SPAPR_DRC_STATE_PHYSICAL_POWERON));
379 
380     drc->dev = d;
381 
382     object_property_add_link(OBJECT(drc), "device",
383                              object_get_typename(OBJECT(drc->dev)),
384                              (Object **)(&drc->dev),
385                              NULL, 0);
386 }
387 
388 static void spapr_drc_release(SpaprDrc *drc)
389 {
390     SpaprDrcClass *drck = SPAPR_DR_CONNECTOR_GET_CLASS(drc);
391 
392     drck->release(drc->dev);
393 
394     drc->unplug_requested = false;
395     g_free(drc->fdt);
396     drc->fdt = NULL;
397     drc->fdt_start_offset = 0;
398     object_property_del(OBJECT(drc), "device");
399     drc->dev = NULL;
400 }
401 
402 void spapr_drc_detach(SpaprDrc *drc)
403 {
404     SpaprDrcClass *drck = SPAPR_DR_CONNECTOR_GET_CLASS(drc);
405 
406     trace_spapr_drc_detach(spapr_drc_index(drc));
407 
408     g_assert(drc->dev);
409 
410     drc->unplug_requested = true;
411 
412     if (drc->state != drck->empty_state) {
413         trace_spapr_drc_awaiting_quiesce(spapr_drc_index(drc));
414         return;
415     }
416 
417     spapr_drc_release(drc);
418 }
419 
420 void spapr_drc_reset(SpaprDrc *drc)
421 {
422     SpaprDrcClass *drck = SPAPR_DR_CONNECTOR_GET_CLASS(drc);
423 
424     trace_spapr_drc_reset(spapr_drc_index(drc));
425 
426     /* immediately upon reset we can safely assume DRCs whose devices
427      * are pending removal can be safely removed.
428      */
429     if (drc->unplug_requested) {
430         spapr_drc_release(drc);
431     }
432 
433     if (drc->dev) {
434         /* A device present at reset is ready to go, same as coldplugged */
435         drc->state = drck->ready_state;
436         /*
437          * Ensure that we are able to send the FDT fragment again
438          * via configure-connector call if the guest requests.
439          */
440         drc->ccs_offset = drc->fdt_start_offset;
441         drc->ccs_depth = 0;
442     } else {
443         drc->state = drck->empty_state;
444         drc->ccs_offset = -1;
445         drc->ccs_depth = -1;
446     }
447 }
448 
449 static bool spapr_drc_unplug_requested_needed(void *opaque)
450 {
451     return spapr_drc_unplug_requested(opaque);
452 }
453 
454 static const VMStateDescription vmstate_spapr_drc_unplug_requested = {
455     .name = "spapr_drc/unplug_requested",
456     .version_id = 1,
457     .minimum_version_id = 1,
458     .needed = spapr_drc_unplug_requested_needed,
459     .fields  = (VMStateField []) {
460         VMSTATE_BOOL(unplug_requested, SpaprDrc),
461         VMSTATE_END_OF_LIST()
462     }
463 };
464 
465 bool spapr_drc_transient(SpaprDrc *drc)
466 {
467     SpaprDrcClass *drck = SPAPR_DR_CONNECTOR_GET_CLASS(drc);
468 
469     /*
470      * If no dev is plugged in there is no need to migrate the DRC state
471      * nor to reset the DRC at CAS.
472      */
473     if (!drc->dev) {
474         return false;
475     }
476 
477     /*
478      * We need to reset the DRC at CAS or to migrate the DRC state if it's
479      * not equal to the expected long-term state, which is the same as the
480      * coldplugged initial state, or if an unplug request is pending.
481      */
482     return drc->state != drck->ready_state ||
483         spapr_drc_unplug_requested(drc);
484 }
485 
486 static bool spapr_drc_needed(void *opaque)
487 {
488     return spapr_drc_transient(opaque);
489 }
490 
491 static const VMStateDescription vmstate_spapr_drc = {
492     .name = "spapr_drc",
493     .version_id = 1,
494     .minimum_version_id = 1,
495     .needed = spapr_drc_needed,
496     .fields  = (VMStateField []) {
497         VMSTATE_UINT32(state, SpaprDrc),
498         VMSTATE_END_OF_LIST()
499     },
500     .subsections = (const VMStateDescription * []) {
501         &vmstate_spapr_drc_unplug_requested,
502         NULL
503     }
504 };
505 
506 static void realize(DeviceState *d, Error **errp)
507 {
508     SpaprDrc *drc = SPAPR_DR_CONNECTOR(d);
509     Object *root_container;
510     gchar *link_name;
511     const char *child_name;
512 
513     trace_spapr_drc_realize(spapr_drc_index(drc));
514     /* NOTE: we do this as part of realize/unrealize due to the fact
515      * that the guest will communicate with the DRC via RTAS calls
516      * referencing the global DRC index. By unlinking the DRC
517      * from DRC_CONTAINER_PATH/<drc_index> we effectively make it
518      * inaccessible by the guest, since lookups rely on this path
519      * existing in the composition tree
520      */
521     root_container = container_get(object_get_root(), DRC_CONTAINER_PATH);
522     link_name = g_strdup_printf("%x", spapr_drc_index(drc));
523     child_name = object_get_canonical_path_component(OBJECT(drc));
524     trace_spapr_drc_realize_child(spapr_drc_index(drc), child_name);
525     object_property_add_alias(root_container, link_name,
526                               drc->owner, child_name);
527     g_free(link_name);
528     vmstate_register(VMSTATE_IF(drc), spapr_drc_index(drc), &vmstate_spapr_drc,
529                      drc);
530     trace_spapr_drc_realize_complete(spapr_drc_index(drc));
531 }
532 
533 static void unrealize(DeviceState *d)
534 {
535     SpaprDrc *drc = SPAPR_DR_CONNECTOR(d);
536     Object *root_container;
537     gchar *name;
538 
539     trace_spapr_drc_unrealize(spapr_drc_index(drc));
540     vmstate_unregister(VMSTATE_IF(drc), &vmstate_spapr_drc, drc);
541     root_container = container_get(object_get_root(), DRC_CONTAINER_PATH);
542     name = g_strdup_printf("%x", spapr_drc_index(drc));
543     object_property_del(root_container, name);
544     g_free(name);
545 }
546 
547 SpaprDrc *spapr_dr_connector_new(Object *owner, const char *type,
548                                          uint32_t id)
549 {
550     SpaprDrc *drc = SPAPR_DR_CONNECTOR(object_new(type));
551     char *prop_name;
552 
553     drc->id = id;
554     drc->owner = owner;
555     prop_name = g_strdup_printf("dr-connector[%"PRIu32"]",
556                                 spapr_drc_index(drc));
557     object_property_add_child(owner, prop_name, OBJECT(drc));
558     object_unref(OBJECT(drc));
559     qdev_realize(DEVICE(drc), NULL, NULL);
560     g_free(prop_name);
561 
562     return drc;
563 }
564 
565 static void spapr_dr_connector_instance_init(Object *obj)
566 {
567     SpaprDrc *drc = SPAPR_DR_CONNECTOR(obj);
568     SpaprDrcClass *drck = SPAPR_DR_CONNECTOR_GET_CLASS(drc);
569 
570     object_property_add_uint32_ptr(obj, "id", &drc->id, OBJ_PROP_FLAG_READ);
571     object_property_add(obj, "index", "uint32", prop_get_index,
572                         NULL, NULL, NULL);
573     object_property_add(obj, "fdt", "struct", prop_get_fdt,
574                         NULL, NULL, NULL);
575     drc->state = drck->empty_state;
576 }
577 
578 static void spapr_dr_connector_class_init(ObjectClass *k, void *data)
579 {
580     DeviceClass *dk = DEVICE_CLASS(k);
581 
582     dk->realize = realize;
583     dk->unrealize = unrealize;
584     /*
585      * Reason: DR connector needs to be wired to either the machine or to a
586      * PHB in spapr_dr_connector_new().
587      */
588     dk->user_creatable = false;
589 }
590 
591 static bool drc_physical_needed(void *opaque)
592 {
593     SpaprDrcPhysical *drcp = (SpaprDrcPhysical *)opaque;
594     SpaprDrc *drc = SPAPR_DR_CONNECTOR(drcp);
595 
596     if ((drc->dev && (drcp->dr_indicator == SPAPR_DR_INDICATOR_ACTIVE))
597         || (!drc->dev && (drcp->dr_indicator == SPAPR_DR_INDICATOR_INACTIVE))) {
598         return false;
599     }
600     return true;
601 }
602 
603 static const VMStateDescription vmstate_spapr_drc_physical = {
604     .name = "spapr_drc/physical",
605     .version_id = 1,
606     .minimum_version_id = 1,
607     .needed = drc_physical_needed,
608     .fields  = (VMStateField []) {
609         VMSTATE_UINT32(dr_indicator, SpaprDrcPhysical),
610         VMSTATE_END_OF_LIST()
611     }
612 };
613 
614 static void drc_physical_reset(void *opaque)
615 {
616     SpaprDrc *drc = SPAPR_DR_CONNECTOR(opaque);
617     SpaprDrcPhysical *drcp = SPAPR_DRC_PHYSICAL(drc);
618 
619     if (drc->dev) {
620         drcp->dr_indicator = SPAPR_DR_INDICATOR_ACTIVE;
621     } else {
622         drcp->dr_indicator = SPAPR_DR_INDICATOR_INACTIVE;
623     }
624 }
625 
626 static void realize_physical(DeviceState *d, Error **errp)
627 {
628     SpaprDrcPhysical *drcp = SPAPR_DRC_PHYSICAL(d);
629     Error *local_err = NULL;
630 
631     realize(d, &local_err);
632     if (local_err) {
633         error_propagate(errp, local_err);
634         return;
635     }
636 
637     vmstate_register(VMSTATE_IF(drcp),
638                      spapr_drc_index(SPAPR_DR_CONNECTOR(drcp)),
639                      &vmstate_spapr_drc_physical, drcp);
640     qemu_register_reset(drc_physical_reset, drcp);
641 }
642 
643 static void unrealize_physical(DeviceState *d)
644 {
645     SpaprDrcPhysical *drcp = SPAPR_DRC_PHYSICAL(d);
646 
647     unrealize(d);
648     vmstate_unregister(VMSTATE_IF(drcp), &vmstate_spapr_drc_physical, drcp);
649     qemu_unregister_reset(drc_physical_reset, drcp);
650 }
651 
652 static void spapr_drc_physical_class_init(ObjectClass *k, void *data)
653 {
654     DeviceClass *dk = DEVICE_CLASS(k);
655     SpaprDrcClass *drck = SPAPR_DR_CONNECTOR_CLASS(k);
656 
657     dk->realize = realize_physical;
658     dk->unrealize = unrealize_physical;
659     drck->dr_entity_sense = physical_entity_sense;
660     drck->isolate = drc_isolate_physical;
661     drck->unisolate = drc_unisolate_physical;
662     drck->ready_state = SPAPR_DRC_STATE_PHYSICAL_CONFIGURED;
663     drck->empty_state = SPAPR_DRC_STATE_PHYSICAL_POWERON;
664 }
665 
666 static void spapr_drc_logical_class_init(ObjectClass *k, void *data)
667 {
668     SpaprDrcClass *drck = SPAPR_DR_CONNECTOR_CLASS(k);
669 
670     drck->dr_entity_sense = logical_entity_sense;
671     drck->isolate = drc_isolate_logical;
672     drck->unisolate = drc_unisolate_logical;
673     drck->ready_state = SPAPR_DRC_STATE_LOGICAL_CONFIGURED;
674     drck->empty_state = SPAPR_DRC_STATE_LOGICAL_UNUSABLE;
675 }
676 
677 static void spapr_drc_cpu_class_init(ObjectClass *k, void *data)
678 {
679     SpaprDrcClass *drck = SPAPR_DR_CONNECTOR_CLASS(k);
680 
681     drck->typeshift = SPAPR_DR_CONNECTOR_TYPE_SHIFT_CPU;
682     drck->typename = "CPU";
683     drck->drc_name_prefix = "CPU ";
684     drck->release = spapr_core_release;
685     drck->dt_populate = spapr_core_dt_populate;
686 }
687 
688 static void spapr_drc_pci_class_init(ObjectClass *k, void *data)
689 {
690     SpaprDrcClass *drck = SPAPR_DR_CONNECTOR_CLASS(k);
691 
692     drck->typeshift = SPAPR_DR_CONNECTOR_TYPE_SHIFT_PCI;
693     drck->typename = "28";
694     drck->drc_name_prefix = "C";
695     drck->release = spapr_phb_remove_pci_device_cb;
696     drck->dt_populate = spapr_pci_dt_populate;
697 }
698 
699 static void spapr_drc_lmb_class_init(ObjectClass *k, void *data)
700 {
701     SpaprDrcClass *drck = SPAPR_DR_CONNECTOR_CLASS(k);
702 
703     drck->typeshift = SPAPR_DR_CONNECTOR_TYPE_SHIFT_LMB;
704     drck->typename = "MEM";
705     drck->drc_name_prefix = "LMB ";
706     drck->release = spapr_lmb_release;
707     drck->dt_populate = spapr_lmb_dt_populate;
708 }
709 
710 static void spapr_drc_phb_class_init(ObjectClass *k, void *data)
711 {
712     SpaprDrcClass *drck = SPAPR_DR_CONNECTOR_CLASS(k);
713 
714     drck->typeshift = SPAPR_DR_CONNECTOR_TYPE_SHIFT_PHB;
715     drck->typename = "PHB";
716     drck->drc_name_prefix = "PHB ";
717     drck->release = spapr_phb_release;
718     drck->dt_populate = spapr_phb_dt_populate;
719 }
720 
721 static void spapr_drc_pmem_class_init(ObjectClass *k, void *data)
722 {
723     SpaprDrcClass *drck = SPAPR_DR_CONNECTOR_CLASS(k);
724 
725     drck->typeshift = SPAPR_DR_CONNECTOR_TYPE_SHIFT_PMEM;
726     drck->typename = "PMEM";
727     drck->drc_name_prefix = "PMEM ";
728     drck->release = NULL;
729     drck->dt_populate = spapr_pmem_dt_populate;
730 }
731 
732 static const TypeInfo spapr_dr_connector_info = {
733     .name          = TYPE_SPAPR_DR_CONNECTOR,
734     .parent        = TYPE_DEVICE,
735     .instance_size = sizeof(SpaprDrc),
736     .instance_init = spapr_dr_connector_instance_init,
737     .class_size    = sizeof(SpaprDrcClass),
738     .class_init    = spapr_dr_connector_class_init,
739     .abstract      = true,
740 };
741 
742 static const TypeInfo spapr_drc_physical_info = {
743     .name          = TYPE_SPAPR_DRC_PHYSICAL,
744     .parent        = TYPE_SPAPR_DR_CONNECTOR,
745     .instance_size = sizeof(SpaprDrcPhysical),
746     .class_init    = spapr_drc_physical_class_init,
747     .abstract      = true,
748 };
749 
750 static const TypeInfo spapr_drc_logical_info = {
751     .name          = TYPE_SPAPR_DRC_LOGICAL,
752     .parent        = TYPE_SPAPR_DR_CONNECTOR,
753     .class_init    = spapr_drc_logical_class_init,
754     .abstract      = true,
755 };
756 
757 static const TypeInfo spapr_drc_cpu_info = {
758     .name          = TYPE_SPAPR_DRC_CPU,
759     .parent        = TYPE_SPAPR_DRC_LOGICAL,
760     .class_init    = spapr_drc_cpu_class_init,
761 };
762 
763 static const TypeInfo spapr_drc_pci_info = {
764     .name          = TYPE_SPAPR_DRC_PCI,
765     .parent        = TYPE_SPAPR_DRC_PHYSICAL,
766     .class_init    = spapr_drc_pci_class_init,
767 };
768 
769 static const TypeInfo spapr_drc_lmb_info = {
770     .name          = TYPE_SPAPR_DRC_LMB,
771     .parent        = TYPE_SPAPR_DRC_LOGICAL,
772     .class_init    = spapr_drc_lmb_class_init,
773 };
774 
775 static const TypeInfo spapr_drc_phb_info = {
776     .name          = TYPE_SPAPR_DRC_PHB,
777     .parent        = TYPE_SPAPR_DRC_LOGICAL,
778     .instance_size = sizeof(SpaprDrc),
779     .class_init    = spapr_drc_phb_class_init,
780 };
781 
782 static const TypeInfo spapr_drc_pmem_info = {
783     .name          = TYPE_SPAPR_DRC_PMEM,
784     .parent        = TYPE_SPAPR_DRC_LOGICAL,
785     .class_init    = spapr_drc_pmem_class_init,
786 };
787 
788 /* helper functions for external users */
789 
790 SpaprDrc *spapr_drc_by_index(uint32_t index)
791 {
792     Object *obj;
793     gchar *name;
794 
795     name = g_strdup_printf("%s/%x", DRC_CONTAINER_PATH, index);
796     obj = object_resolve_path(name, NULL);
797     g_free(name);
798 
799     return !obj ? NULL : SPAPR_DR_CONNECTOR(obj);
800 }
801 
802 SpaprDrc *spapr_drc_by_id(const char *type, uint32_t id)
803 {
804     SpaprDrcClass *drck
805         = SPAPR_DR_CONNECTOR_CLASS(object_class_by_name(type));
806 
807     return spapr_drc_by_index(drck->typeshift << DRC_INDEX_TYPE_SHIFT
808                               | (id & DRC_INDEX_ID_MASK));
809 }
810 
811 /**
812  * spapr_dt_drc
813  *
814  * @fdt: libfdt device tree
815  * @path: path in the DT to generate properties
816  * @owner: parent Object/DeviceState for which to generate DRC
817  *         descriptions for
818  * @drc_type_mask: mask of SpaprDrcType values corresponding
819  *   to the types of DRCs to generate entries for
820  *
821  * generate OF properties to describe DRC topology/indices to guests
822  *
823  * as documented in PAPR+ v2.1, 13.5.2
824  */
825 int spapr_dt_drc(void *fdt, int offset, Object *owner, uint32_t drc_type_mask)
826 {
827     Object *root_container;
828     ObjectProperty *prop;
829     ObjectPropertyIterator iter;
830     uint32_t drc_count = 0;
831     GArray *drc_indexes, *drc_power_domains;
832     GString *drc_names, *drc_types;
833     int ret;
834 
835     /* the first entry of each properties is a 32-bit integer encoding
836      * the number of elements in the array. we won't know this until
837      * we complete the iteration through all the matching DRCs, but
838      * reserve the space now and set the offsets accordingly so we
839      * can fill them in later.
840      */
841     drc_indexes = g_array_new(false, true, sizeof(uint32_t));
842     drc_indexes = g_array_set_size(drc_indexes, 1);
843     drc_power_domains = g_array_new(false, true, sizeof(uint32_t));
844     drc_power_domains = g_array_set_size(drc_power_domains, 1);
845     drc_names = g_string_set_size(g_string_new(NULL), sizeof(uint32_t));
846     drc_types = g_string_set_size(g_string_new(NULL), sizeof(uint32_t));
847 
848     /* aliases for all DRConnector objects will be rooted in QOM
849      * composition tree at DRC_CONTAINER_PATH
850      */
851     root_container = container_get(object_get_root(), DRC_CONTAINER_PATH);
852 
853     object_property_iter_init(&iter, root_container);
854     while ((prop = object_property_iter_next(&iter))) {
855         Object *obj;
856         SpaprDrc *drc;
857         SpaprDrcClass *drck;
858         char *drc_name = NULL;
859         uint32_t drc_index, drc_power_domain;
860 
861         if (!strstart(prop->type, "link<", NULL)) {
862             continue;
863         }
864 
865         obj = object_property_get_link(root_container, prop->name,
866                                        &error_abort);
867         drc = SPAPR_DR_CONNECTOR(obj);
868         drck = SPAPR_DR_CONNECTOR_GET_CLASS(drc);
869 
870         if (owner && (drc->owner != owner)) {
871             continue;
872         }
873 
874         if ((spapr_drc_type(drc) & drc_type_mask) == 0) {
875             continue;
876         }
877 
878         drc_count++;
879 
880         /* ibm,drc-indexes */
881         drc_index = cpu_to_be32(spapr_drc_index(drc));
882         g_array_append_val(drc_indexes, drc_index);
883 
884         /* ibm,drc-power-domains */
885         drc_power_domain = cpu_to_be32(-1);
886         g_array_append_val(drc_power_domains, drc_power_domain);
887 
888         /* ibm,drc-names */
889         drc_name = spapr_drc_name(drc);
890         drc_names = g_string_append(drc_names, drc_name);
891         drc_names = g_string_insert_len(drc_names, -1, "\0", 1);
892         g_free(drc_name);
893 
894         /* ibm,drc-types */
895         drc_types = g_string_append(drc_types, drck->typename);
896         drc_types = g_string_insert_len(drc_types, -1, "\0", 1);
897     }
898 
899     /* now write the drc count into the space we reserved at the
900      * beginning of the arrays previously
901      */
902     *(uint32_t *)drc_indexes->data = cpu_to_be32(drc_count);
903     *(uint32_t *)drc_power_domains->data = cpu_to_be32(drc_count);
904     *(uint32_t *)drc_names->str = cpu_to_be32(drc_count);
905     *(uint32_t *)drc_types->str = cpu_to_be32(drc_count);
906 
907     ret = fdt_setprop(fdt, offset, "ibm,drc-indexes",
908                       drc_indexes->data,
909                       drc_indexes->len * sizeof(uint32_t));
910     if (ret) {
911         error_report("Couldn't create ibm,drc-indexes property");
912         goto out;
913     }
914 
915     ret = fdt_setprop(fdt, offset, "ibm,drc-power-domains",
916                       drc_power_domains->data,
917                       drc_power_domains->len * sizeof(uint32_t));
918     if (ret) {
919         error_report("Couldn't finalize ibm,drc-power-domains property");
920         goto out;
921     }
922 
923     ret = fdt_setprop(fdt, offset, "ibm,drc-names",
924                       drc_names->str, drc_names->len);
925     if (ret) {
926         error_report("Couldn't finalize ibm,drc-names property");
927         goto out;
928     }
929 
930     ret = fdt_setprop(fdt, offset, "ibm,drc-types",
931                       drc_types->str, drc_types->len);
932     if (ret) {
933         error_report("Couldn't finalize ibm,drc-types property");
934         goto out;
935     }
936 
937 out:
938     g_array_free(drc_indexes, true);
939     g_array_free(drc_power_domains, true);
940     g_string_free(drc_names, true);
941     g_string_free(drc_types, true);
942 
943     return ret;
944 }
945 
946 /*
947  * RTAS calls
948  */
949 
950 static uint32_t rtas_set_isolation_state(uint32_t idx, uint32_t state)
951 {
952     SpaprDrc *drc = spapr_drc_by_index(idx);
953     SpaprDrcClass *drck;
954 
955     if (!drc) {
956         return RTAS_OUT_NO_SUCH_INDICATOR;
957     }
958 
959     trace_spapr_drc_set_isolation_state(spapr_drc_index(drc), state);
960 
961     drck = SPAPR_DR_CONNECTOR_GET_CLASS(drc);
962 
963     switch (state) {
964     case SPAPR_DR_ISOLATION_STATE_ISOLATED:
965         return drck->isolate(drc);
966 
967     case SPAPR_DR_ISOLATION_STATE_UNISOLATED:
968         return drck->unisolate(drc);
969 
970     default:
971         return RTAS_OUT_PARAM_ERROR;
972     }
973 }
974 
975 static uint32_t rtas_set_allocation_state(uint32_t idx, uint32_t state)
976 {
977     SpaprDrc *drc = spapr_drc_by_index(idx);
978 
979     if (!drc || !object_dynamic_cast(OBJECT(drc), TYPE_SPAPR_DRC_LOGICAL)) {
980         return RTAS_OUT_NO_SUCH_INDICATOR;
981     }
982 
983     trace_spapr_drc_set_allocation_state(spapr_drc_index(drc), state);
984 
985     switch (state) {
986     case SPAPR_DR_ALLOCATION_STATE_USABLE:
987         return drc_set_usable(drc);
988 
989     case SPAPR_DR_ALLOCATION_STATE_UNUSABLE:
990         return drc_set_unusable(drc);
991 
992     default:
993         return RTAS_OUT_PARAM_ERROR;
994     }
995 }
996 
997 static uint32_t rtas_set_dr_indicator(uint32_t idx, uint32_t state)
998 {
999     SpaprDrc *drc = spapr_drc_by_index(idx);
1000 
1001     if (!drc || !object_dynamic_cast(OBJECT(drc), TYPE_SPAPR_DRC_PHYSICAL)) {
1002         return RTAS_OUT_NO_SUCH_INDICATOR;
1003     }
1004     if ((state != SPAPR_DR_INDICATOR_INACTIVE)
1005         && (state != SPAPR_DR_INDICATOR_ACTIVE)
1006         && (state != SPAPR_DR_INDICATOR_IDENTIFY)
1007         && (state != SPAPR_DR_INDICATOR_ACTION)) {
1008         return RTAS_OUT_PARAM_ERROR; /* bad state parameter */
1009     }
1010 
1011     trace_spapr_drc_set_dr_indicator(idx, state);
1012     SPAPR_DRC_PHYSICAL(drc)->dr_indicator = state;
1013     return RTAS_OUT_SUCCESS;
1014 }
1015 
1016 static void rtas_set_indicator(PowerPCCPU *cpu, SpaprMachineState *spapr,
1017                                uint32_t token,
1018                                uint32_t nargs, target_ulong args,
1019                                uint32_t nret, target_ulong rets)
1020 {
1021     uint32_t type, idx, state;
1022     uint32_t ret = RTAS_OUT_SUCCESS;
1023 
1024     if (nargs != 3 || nret != 1) {
1025         ret = RTAS_OUT_PARAM_ERROR;
1026         goto out;
1027     }
1028 
1029     type = rtas_ld(args, 0);
1030     idx = rtas_ld(args, 1);
1031     state = rtas_ld(args, 2);
1032 
1033     switch (type) {
1034     case RTAS_SENSOR_TYPE_ISOLATION_STATE:
1035         ret = rtas_set_isolation_state(idx, state);
1036         break;
1037     case RTAS_SENSOR_TYPE_DR:
1038         ret = rtas_set_dr_indicator(idx, state);
1039         break;
1040     case RTAS_SENSOR_TYPE_ALLOCATION_STATE:
1041         ret = rtas_set_allocation_state(idx, state);
1042         break;
1043     default:
1044         ret = RTAS_OUT_NOT_SUPPORTED;
1045     }
1046 
1047 out:
1048     rtas_st(rets, 0, ret);
1049 }
1050 
1051 static void rtas_get_sensor_state(PowerPCCPU *cpu, SpaprMachineState *spapr,
1052                                   uint32_t token, uint32_t nargs,
1053                                   target_ulong args, uint32_t nret,
1054                                   target_ulong rets)
1055 {
1056     uint32_t sensor_type;
1057     uint32_t sensor_index;
1058     uint32_t sensor_state = 0;
1059     SpaprDrc *drc;
1060     SpaprDrcClass *drck;
1061     uint32_t ret = RTAS_OUT_SUCCESS;
1062 
1063     if (nargs != 2 || nret != 2) {
1064         ret = RTAS_OUT_PARAM_ERROR;
1065         goto out;
1066     }
1067 
1068     sensor_type = rtas_ld(args, 0);
1069     sensor_index = rtas_ld(args, 1);
1070 
1071     if (sensor_type != RTAS_SENSOR_TYPE_ENTITY_SENSE) {
1072         /* currently only DR-related sensors are implemented */
1073         trace_spapr_rtas_get_sensor_state_not_supported(sensor_index,
1074                                                         sensor_type);
1075         ret = RTAS_OUT_NOT_SUPPORTED;
1076         goto out;
1077     }
1078 
1079     drc = spapr_drc_by_index(sensor_index);
1080     if (!drc) {
1081         trace_spapr_rtas_get_sensor_state_invalid(sensor_index);
1082         ret = RTAS_OUT_PARAM_ERROR;
1083         goto out;
1084     }
1085     drck = SPAPR_DR_CONNECTOR_GET_CLASS(drc);
1086     sensor_state = drck->dr_entity_sense(drc);
1087 
1088 out:
1089     rtas_st(rets, 0, ret);
1090     rtas_st(rets, 1, sensor_state);
1091 }
1092 
1093 /* configure-connector work area offsets, int32_t units for field
1094  * indexes, bytes for field offset/len values.
1095  *
1096  * as documented by PAPR+ v2.7, 13.5.3.5
1097  */
1098 #define CC_IDX_NODE_NAME_OFFSET 2
1099 #define CC_IDX_PROP_NAME_OFFSET 2
1100 #define CC_IDX_PROP_LEN 3
1101 #define CC_IDX_PROP_DATA_OFFSET 4
1102 #define CC_VAL_DATA_OFFSET ((CC_IDX_PROP_DATA_OFFSET + 1) * 4)
1103 #define CC_WA_LEN 4096
1104 
1105 static void configure_connector_st(target_ulong addr, target_ulong offset,
1106                                    const void *buf, size_t len)
1107 {
1108     cpu_physical_memory_write(ppc64_phys_to_real(addr + offset),
1109                               buf, MIN(len, CC_WA_LEN - offset));
1110 }
1111 
1112 static void rtas_ibm_configure_connector(PowerPCCPU *cpu,
1113                                          SpaprMachineState *spapr,
1114                                          uint32_t token, uint32_t nargs,
1115                                          target_ulong args, uint32_t nret,
1116                                          target_ulong rets)
1117 {
1118     uint64_t wa_addr;
1119     uint64_t wa_offset;
1120     uint32_t drc_index;
1121     SpaprDrc *drc;
1122     SpaprDrcClass *drck;
1123     SpaprDRCCResponse resp = SPAPR_DR_CC_RESPONSE_CONTINUE;
1124     int rc;
1125 
1126     if (nargs != 2 || nret != 1) {
1127         rtas_st(rets, 0, RTAS_OUT_PARAM_ERROR);
1128         return;
1129     }
1130 
1131     wa_addr = ((uint64_t)rtas_ld(args, 1) << 32) | rtas_ld(args, 0);
1132 
1133     drc_index = rtas_ld(wa_addr, 0);
1134     drc = spapr_drc_by_index(drc_index);
1135     if (!drc) {
1136         trace_spapr_rtas_ibm_configure_connector_invalid(drc_index);
1137         rc = RTAS_OUT_PARAM_ERROR;
1138         goto out;
1139     }
1140 
1141     if ((drc->state != SPAPR_DRC_STATE_LOGICAL_UNISOLATE)
1142         && (drc->state != SPAPR_DRC_STATE_PHYSICAL_UNISOLATE)
1143         && (drc->state != SPAPR_DRC_STATE_LOGICAL_CONFIGURED)
1144         && (drc->state != SPAPR_DRC_STATE_PHYSICAL_CONFIGURED)) {
1145         /*
1146          * Need to unisolate the device before configuring
1147          * or it should already be in configured state to
1148          * allow configure-connector be called repeatedly.
1149          */
1150         rc = SPAPR_DR_CC_RESPONSE_NOT_CONFIGURABLE;
1151         goto out;
1152     }
1153 
1154     drck = SPAPR_DR_CONNECTOR_GET_CLASS(drc);
1155 
1156     if (!drc->fdt) {
1157         void *fdt;
1158         int fdt_size;
1159 
1160         fdt = create_device_tree(&fdt_size);
1161 
1162         if (drck->dt_populate(drc, spapr, fdt, &drc->fdt_start_offset,
1163                               NULL)) {
1164             g_free(fdt);
1165             rc = SPAPR_DR_CC_RESPONSE_ERROR;
1166             goto out;
1167         }
1168 
1169         drc->fdt = fdt;
1170         drc->ccs_offset = drc->fdt_start_offset;
1171         drc->ccs_depth = 0;
1172     }
1173 
1174     do {
1175         uint32_t tag;
1176         const char *name;
1177         const struct fdt_property *prop;
1178         int fdt_offset_next, prop_len;
1179 
1180         tag = fdt_next_tag(drc->fdt, drc->ccs_offset, &fdt_offset_next);
1181 
1182         switch (tag) {
1183         case FDT_BEGIN_NODE:
1184             drc->ccs_depth++;
1185             name = fdt_get_name(drc->fdt, drc->ccs_offset, NULL);
1186 
1187             /* provide the name of the next OF node */
1188             wa_offset = CC_VAL_DATA_OFFSET;
1189             rtas_st(wa_addr, CC_IDX_NODE_NAME_OFFSET, wa_offset);
1190             configure_connector_st(wa_addr, wa_offset, name, strlen(name) + 1);
1191             resp = SPAPR_DR_CC_RESPONSE_NEXT_CHILD;
1192             break;
1193         case FDT_END_NODE:
1194             drc->ccs_depth--;
1195             if (drc->ccs_depth == 0) {
1196                 uint32_t drc_index = spapr_drc_index(drc);
1197 
1198                 /* done sending the device tree, move to configured state */
1199                 trace_spapr_drc_set_configured(drc_index);
1200                 drc->state = drck->ready_state;
1201                 /*
1202                  * Ensure that we are able to send the FDT fragment
1203                  * again via configure-connector call if the guest requests.
1204                  */
1205                 drc->ccs_offset = drc->fdt_start_offset;
1206                 drc->ccs_depth = 0;
1207                 fdt_offset_next = drc->fdt_start_offset;
1208                 resp = SPAPR_DR_CC_RESPONSE_SUCCESS;
1209             } else {
1210                 resp = SPAPR_DR_CC_RESPONSE_PREV_PARENT;
1211             }
1212             break;
1213         case FDT_PROP:
1214             prop = fdt_get_property_by_offset(drc->fdt, drc->ccs_offset,
1215                                               &prop_len);
1216             name = fdt_string(drc->fdt, fdt32_to_cpu(prop->nameoff));
1217 
1218             /* provide the name of the next OF property */
1219             wa_offset = CC_VAL_DATA_OFFSET;
1220             rtas_st(wa_addr, CC_IDX_PROP_NAME_OFFSET, wa_offset);
1221             configure_connector_st(wa_addr, wa_offset, name, strlen(name) + 1);
1222 
1223             /* provide the length and value of the OF property. data gets
1224              * placed immediately after NULL terminator of the OF property's
1225              * name string
1226              */
1227             wa_offset += strlen(name) + 1,
1228             rtas_st(wa_addr, CC_IDX_PROP_LEN, prop_len);
1229             rtas_st(wa_addr, CC_IDX_PROP_DATA_OFFSET, wa_offset);
1230             configure_connector_st(wa_addr, wa_offset, prop->data, prop_len);
1231             resp = SPAPR_DR_CC_RESPONSE_NEXT_PROPERTY;
1232             break;
1233         case FDT_END:
1234             resp = SPAPR_DR_CC_RESPONSE_ERROR;
1235         default:
1236             /* keep seeking for an actionable tag */
1237             break;
1238         }
1239         if (drc->ccs_offset >= 0) {
1240             drc->ccs_offset = fdt_offset_next;
1241         }
1242     } while (resp == SPAPR_DR_CC_RESPONSE_CONTINUE);
1243 
1244     rc = resp;
1245 out:
1246     rtas_st(rets, 0, rc);
1247 }
1248 
1249 static void spapr_drc_register_types(void)
1250 {
1251     type_register_static(&spapr_dr_connector_info);
1252     type_register_static(&spapr_drc_physical_info);
1253     type_register_static(&spapr_drc_logical_info);
1254     type_register_static(&spapr_drc_cpu_info);
1255     type_register_static(&spapr_drc_pci_info);
1256     type_register_static(&spapr_drc_lmb_info);
1257     type_register_static(&spapr_drc_phb_info);
1258     type_register_static(&spapr_drc_pmem_info);
1259 
1260     spapr_rtas_register(RTAS_SET_INDICATOR, "set-indicator",
1261                         rtas_set_indicator);
1262     spapr_rtas_register(RTAS_GET_SENSOR_STATE, "get-sensor-state",
1263                         rtas_get_sensor_state);
1264     spapr_rtas_register(RTAS_IBM_CONFIGURE_CONNECTOR, "ibm,configure-connector",
1265                         rtas_ibm_configure_connector);
1266 }
1267 type_init(spapr_drc_register_types)
1268