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