1
2
3
4
5
6
7
8
9
10
11
12
13#include "qemu/osdep.h"
14#include "qapi/error.h"
15#include "cpu.h"
16#include "qemu/cutils.h"
17#include "hw/ppc/spapr_drc.h"
18#include "qom/object.h"
19#include "hw/qdev.h"
20#include "qapi/visitor.h"
21#include "qemu/error-report.h"
22#include "hw/ppc/spapr.h"
23
24
25
26#ifdef DEBUG_SPAPR_DRC
27#define DPRINTF(fmt, ...) \
28 do { fprintf(stderr, fmt, ## __VA_ARGS__); } while (0)
29#define DPRINTFN(fmt, ...) \
30 do { DPRINTF(fmt, ## __VA_ARGS__); fprintf(stderr, "\n"); } while (0)
31#else
32#define DPRINTF(fmt, ...) \
33 do { } while (0)
34#define DPRINTFN(fmt, ...) \
35 do { } while (0)
36#endif
37
38#define DRC_CONTAINER_PATH "/dr-connector"
39#define DRC_INDEX_TYPE_SHIFT 28
40#define DRC_INDEX_ID_MASK ((1ULL << DRC_INDEX_TYPE_SHIFT) - 1)
41
42static sPAPRDRConnectorTypeShift get_type_shift(sPAPRDRConnectorType type)
43{
44 uint32_t shift = 0;
45
46
47
48
49 g_assert(is_power_of_2(type));
50
51 while (type != (1 << shift)) {
52 shift++;
53 }
54 return shift;
55}
56
57static uint32_t get_index(sPAPRDRConnector *drc)
58{
59
60
61
62
63 return (get_type_shift(drc->type) << DRC_INDEX_TYPE_SHIFT) |
64 (drc->id & DRC_INDEX_ID_MASK);
65}
66
67static uint32_t set_isolation_state(sPAPRDRConnector *drc,
68 sPAPRDRIsolationState state)
69{
70 sPAPRDRConnectorClass *drck = SPAPR_DR_CONNECTOR_GET_CLASS(drc);
71
72 DPRINTFN("drc: %x, set_isolation_state: %x", get_index(drc), state);
73
74 if (state == SPAPR_DR_ISOLATION_STATE_UNISOLATED) {
75
76
77
78 if (!drc->dev ||
79 drc->allocation_state == SPAPR_DR_ALLOCATION_STATE_UNUSABLE) {
80 return RTAS_OUT_NO_SUCH_INDICATOR;
81 }
82 }
83
84 drc->isolation_state = state;
85
86 if (drc->isolation_state == SPAPR_DR_ISOLATION_STATE_ISOLATED) {
87
88
89
90
91
92
93
94
95 if (drc->awaiting_release) {
96 if (drc->configured) {
97 DPRINTFN("finalizing device removal");
98 drck->detach(drc, DEVICE(drc->dev), drc->detach_cb,
99 drc->detach_cb_opaque, NULL);
100 } else {
101 DPRINTFN("deferring device removal on unconfigured device\n");
102 }
103 }
104 drc->configured = false;
105 }
106
107 return RTAS_OUT_SUCCESS;
108}
109
110static uint32_t set_indicator_state(sPAPRDRConnector *drc,
111 sPAPRDRIndicatorState state)
112{
113 DPRINTFN("drc: %x, set_indicator_state: %x", get_index(drc), state);
114 drc->indicator_state = state;
115 return RTAS_OUT_SUCCESS;
116}
117
118static uint32_t set_allocation_state(sPAPRDRConnector *drc,
119 sPAPRDRAllocationState state)
120{
121 sPAPRDRConnectorClass *drck = SPAPR_DR_CONNECTOR_GET_CLASS(drc);
122
123 DPRINTFN("drc: %x, set_allocation_state: %x", get_index(drc), state);
124
125 if (state == SPAPR_DR_ALLOCATION_STATE_USABLE) {
126
127
128
129
130
131 if (!drc->dev) {
132 return RTAS_OUT_NO_SUCH_INDICATOR;
133 }
134 }
135
136 if (drc->type != SPAPR_DR_CONNECTOR_TYPE_PCI) {
137 drc->allocation_state = state;
138 if (drc->awaiting_release &&
139 drc->allocation_state == SPAPR_DR_ALLOCATION_STATE_UNUSABLE) {
140 DPRINTFN("finalizing device removal");
141 drck->detach(drc, DEVICE(drc->dev), drc->detach_cb,
142 drc->detach_cb_opaque, NULL);
143 }
144 }
145 return RTAS_OUT_SUCCESS;
146}
147
148static uint32_t get_type(sPAPRDRConnector *drc)
149{
150 return drc->type;
151}
152
153static const char *get_name(sPAPRDRConnector *drc)
154{
155 return drc->name;
156}
157
158static const void *get_fdt(sPAPRDRConnector *drc, int *fdt_start_offset)
159{
160 if (fdt_start_offset) {
161 *fdt_start_offset = drc->fdt_start_offset;
162 }
163 return drc->fdt;
164}
165
166static void set_configured(sPAPRDRConnector *drc)
167{
168 DPRINTFN("drc: %x, set_configured", get_index(drc));
169
170 if (drc->isolation_state != SPAPR_DR_ISOLATION_STATE_UNISOLATED) {
171
172 DPRINTFN("drc: %x, set_configured: skipping isolated device",
173 get_index(drc));
174 return;
175 }
176 drc->configured = true;
177}
178
179
180static void set_signalled(sPAPRDRConnector *drc)
181{
182 drc->signalled = true;
183}
184
185
186
187
188
189
190
191
192static uint32_t entity_sense(sPAPRDRConnector *drc, sPAPRDREntitySense *state)
193{
194 if (drc->dev) {
195 if (drc->type != SPAPR_DR_CONNECTOR_TYPE_PCI &&
196 drc->allocation_state == SPAPR_DR_ALLOCATION_STATE_UNUSABLE) {
197
198
199
200
201
202 *state = SPAPR_DR_ENTITY_SENSE_UNUSABLE;
203 } else {
204
205
206
207
208
209
210 *state = SPAPR_DR_ENTITY_SENSE_PRESENT;
211 }
212 } else {
213 if (drc->type == SPAPR_DR_CONNECTOR_TYPE_PCI) {
214
215
216
217 *state = SPAPR_DR_ENTITY_SENSE_EMPTY;
218 } else {
219 *state = SPAPR_DR_ENTITY_SENSE_UNUSABLE;
220 }
221 }
222
223 DPRINTFN("drc: %x, entity_sense: %x", get_index(drc), state);
224 return RTAS_OUT_SUCCESS;
225}
226
227static void prop_get_index(Object *obj, Visitor *v, const char *name,
228 void *opaque, Error **errp)
229{
230 sPAPRDRConnector *drc = SPAPR_DR_CONNECTOR(obj);
231 sPAPRDRConnectorClass *drck = SPAPR_DR_CONNECTOR_GET_CLASS(drc);
232 uint32_t value = (uint32_t)drck->get_index(drc);
233 visit_type_uint32(v, name, &value, errp);
234}
235
236static void prop_get_type(Object *obj, Visitor *v, const char *name,
237 void *opaque, Error **errp)
238{
239 sPAPRDRConnector *drc = SPAPR_DR_CONNECTOR(obj);
240 sPAPRDRConnectorClass *drck = SPAPR_DR_CONNECTOR_GET_CLASS(drc);
241 uint32_t value = (uint32_t)drck->get_type(drc);
242 visit_type_uint32(v, name, &value, errp);
243}
244
245static char *prop_get_name(Object *obj, Error **errp)
246{
247 sPAPRDRConnector *drc = SPAPR_DR_CONNECTOR(obj);
248 sPAPRDRConnectorClass *drck = SPAPR_DR_CONNECTOR_GET_CLASS(drc);
249 return g_strdup(drck->get_name(drc));
250}
251
252static void prop_get_entity_sense(Object *obj, Visitor *v, const char *name,
253 void *opaque, Error **errp)
254{
255 sPAPRDRConnector *drc = SPAPR_DR_CONNECTOR(obj);
256 sPAPRDRConnectorClass *drck = SPAPR_DR_CONNECTOR_GET_CLASS(drc);
257 uint32_t value;
258
259 drck->entity_sense(drc, &value);
260 visit_type_uint32(v, name, &value, errp);
261}
262
263static void prop_get_fdt(Object *obj, Visitor *v, const char *name,
264 void *opaque, Error **errp)
265{
266 sPAPRDRConnector *drc = SPAPR_DR_CONNECTOR(obj);
267 Error *err = NULL;
268 int fdt_offset_next, fdt_offset, fdt_depth;
269 void *fdt;
270
271 if (!drc->fdt) {
272 visit_start_struct(v, name, NULL, 0, &err);
273 if (!err) {
274 visit_end_struct(v, &err);
275 }
276 error_propagate(errp, err);
277 return;
278 }
279
280 fdt = drc->fdt;
281 fdt_offset = drc->fdt_start_offset;
282 fdt_depth = 0;
283
284 do {
285 const char *name = NULL;
286 const struct fdt_property *prop = NULL;
287 int prop_len = 0, name_len = 0;
288 uint32_t tag;
289
290 tag = fdt_next_tag(fdt, fdt_offset, &fdt_offset_next);
291 switch (tag) {
292 case FDT_BEGIN_NODE:
293 fdt_depth++;
294 name = fdt_get_name(fdt, fdt_offset, &name_len);
295 visit_start_struct(v, name, NULL, 0, &err);
296 if (err) {
297 error_propagate(errp, err);
298 return;
299 }
300 break;
301 case FDT_END_NODE:
302
303 g_assert(fdt_depth > 0);
304 visit_end_struct(v, &err);
305 if (err) {
306 error_propagate(errp, err);
307 return;
308 }
309 fdt_depth--;
310 break;
311 case FDT_PROP: {
312 int i;
313 prop = fdt_get_property_by_offset(fdt, fdt_offset, &prop_len);
314 name = fdt_string(fdt, fdt32_to_cpu(prop->nameoff));
315 visit_start_list(v, name, &err);
316 if (err) {
317 error_propagate(errp, err);
318 return;
319 }
320 for (i = 0; i < prop_len; i++) {
321 visit_type_uint8(v, NULL, (uint8_t *)&prop->data[i], &err);
322 if (err) {
323 error_propagate(errp, err);
324 return;
325 }
326 }
327 visit_end_list(v);
328 break;
329 }
330 default:
331 error_setg(&error_abort, "device FDT in unexpected state: %d", tag);
332 }
333 fdt_offset = fdt_offset_next;
334 } while (fdt_depth != 0);
335}
336
337static void attach(sPAPRDRConnector *drc, DeviceState *d, void *fdt,
338 int fdt_start_offset, bool coldplug, Error **errp)
339{
340 DPRINTFN("drc: %x, attach", get_index(drc));
341
342 if (drc->isolation_state != SPAPR_DR_ISOLATION_STATE_ISOLATED) {
343 error_setg(errp, "an attached device is still awaiting release");
344 return;
345 }
346 if (drc->type == SPAPR_DR_CONNECTOR_TYPE_PCI) {
347 g_assert(drc->allocation_state == SPAPR_DR_ALLOCATION_STATE_USABLE);
348 }
349 g_assert(fdt || coldplug);
350
351
352
353
354
355
356
357
358 if (drc->type == SPAPR_DR_CONNECTOR_TYPE_PCI) {
359 drc->isolation_state = SPAPR_DR_ISOLATION_STATE_UNISOLATED;
360 }
361 drc->indicator_state = SPAPR_DR_INDICATOR_STATE_ACTIVE;
362
363 drc->dev = d;
364 drc->fdt = fdt;
365 drc->fdt_start_offset = fdt_start_offset;
366 drc->configured = coldplug;
367
368
369
370
371
372
373
374
375
376 drc->signalled = (drc->type != SPAPR_DR_CONNECTOR_TYPE_PCI)
377 ? true : coldplug;
378
379 object_property_add_link(OBJECT(drc), "device",
380 object_get_typename(OBJECT(drc->dev)),
381 (Object **)(&drc->dev),
382 NULL, 0, NULL);
383}
384
385static void detach(sPAPRDRConnector *drc, DeviceState *d,
386 spapr_drc_detach_cb *detach_cb,
387 void *detach_cb_opaque, Error **errp)
388{
389 DPRINTFN("drc: %x, detach", get_index(drc));
390
391 drc->detach_cb = detach_cb;
392 drc->detach_cb_opaque = detach_cb_opaque;
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407 if (!drc->signalled && !drc->configured) {
408
409
410
411 drc->isolation_state = SPAPR_DR_ISOLATION_STATE_ISOLATED;
412 }
413
414 if (drc->isolation_state != SPAPR_DR_ISOLATION_STATE_ISOLATED) {
415 DPRINTFN("awaiting transition to isolated state before removal");
416 drc->awaiting_release = true;
417 return;
418 }
419
420 if (drc->type != SPAPR_DR_CONNECTOR_TYPE_PCI &&
421 drc->allocation_state != SPAPR_DR_ALLOCATION_STATE_UNUSABLE) {
422 DPRINTFN("awaiting transition to unusable state before removal");
423 drc->awaiting_release = true;
424 return;
425 }
426
427 drc->indicator_state = SPAPR_DR_INDICATOR_STATE_INACTIVE;
428
429 if (drc->detach_cb) {
430 drc->detach_cb(drc->dev, drc->detach_cb_opaque);
431 }
432
433 drc->awaiting_release = false;
434 g_free(drc->fdt);
435 drc->fdt = NULL;
436 drc->fdt_start_offset = 0;
437 object_property_del(OBJECT(drc), "device", NULL);
438 drc->dev = NULL;
439 drc->detach_cb = NULL;
440 drc->detach_cb_opaque = NULL;
441}
442
443static bool release_pending(sPAPRDRConnector *drc)
444{
445 return drc->awaiting_release;
446}
447
448static void reset(DeviceState *d)
449{
450 sPAPRDRConnector *drc = SPAPR_DR_CONNECTOR(d);
451 sPAPRDRConnectorClass *drck = SPAPR_DR_CONNECTOR_GET_CLASS(drc);
452 sPAPRDREntitySense state;
453
454 DPRINTFN("drc reset: %x", drck->get_index(drc));
455
456
457
458
459
460
461 if (drc->awaiting_release) {
462 drck->set_isolation_state(drc, SPAPR_DR_ISOLATION_STATE_ISOLATED);
463
464
465
466
467
468
469 if (drc->awaiting_release) {
470 drck->detach(drc, DEVICE(drc->dev), drc->detach_cb,
471 drc->detach_cb_opaque, NULL);
472 }
473
474
475 if (drc->type != SPAPR_DR_CONNECTOR_TYPE_PCI &&
476 drc->awaiting_release) {
477 drck->set_allocation_state(drc, SPAPR_DR_ALLOCATION_STATE_UNUSABLE);
478 }
479 }
480
481 drck->entity_sense(drc, &state);
482 if (state == SPAPR_DR_ENTITY_SENSE_PRESENT) {
483 drck->set_signalled(drc);
484 }
485}
486
487static void realize(DeviceState *d, Error **errp)
488{
489 sPAPRDRConnector *drc = SPAPR_DR_CONNECTOR(d);
490 sPAPRDRConnectorClass *drck = SPAPR_DR_CONNECTOR_GET_CLASS(drc);
491 Object *root_container;
492 char link_name[256];
493 gchar *child_name;
494 Error *err = NULL;
495
496 DPRINTFN("drc realize: %x", drck->get_index(drc));
497
498
499
500
501
502
503
504 root_container = container_get(object_get_root(), DRC_CONTAINER_PATH);
505 snprintf(link_name, sizeof(link_name), "%x", drck->get_index(drc));
506 child_name = object_get_canonical_path_component(OBJECT(drc));
507 DPRINTFN("drc child name: %s", child_name);
508 object_property_add_alias(root_container, link_name,
509 drc->owner, child_name, &err);
510 if (err) {
511 error_report_err(err);
512 object_unref(OBJECT(drc));
513 }
514 g_free(child_name);
515 DPRINTFN("drc realize complete");
516}
517
518static void unrealize(DeviceState *d, Error **errp)
519{
520 sPAPRDRConnector *drc = SPAPR_DR_CONNECTOR(d);
521 sPAPRDRConnectorClass *drck = SPAPR_DR_CONNECTOR_GET_CLASS(drc);
522 Object *root_container;
523 char name[256];
524 Error *err = NULL;
525
526 DPRINTFN("drc unrealize: %x", drck->get_index(drc));
527 root_container = container_get(object_get_root(), DRC_CONTAINER_PATH);
528 snprintf(name, sizeof(name), "%x", drck->get_index(drc));
529 object_property_del(root_container, name, &err);
530 if (err) {
531 error_report_err(err);
532 object_unref(OBJECT(drc));
533 }
534}
535
536sPAPRDRConnector *spapr_dr_connector_new(Object *owner,
537 sPAPRDRConnectorType type,
538 uint32_t id)
539{
540 sPAPRDRConnector *drc =
541 SPAPR_DR_CONNECTOR(object_new(TYPE_SPAPR_DR_CONNECTOR));
542 char *prop_name;
543
544 g_assert(type);
545
546 drc->type = type;
547 drc->id = id;
548 drc->owner = owner;
549 prop_name = g_strdup_printf("dr-connector[%"PRIu32"]", get_index(drc));
550 object_property_add_child(owner, prop_name, OBJECT(drc), NULL);
551 object_property_set_bool(OBJECT(drc), true, "realized", NULL);
552 g_free(prop_name);
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575 switch (drc->type) {
576 case SPAPR_DR_CONNECTOR_TYPE_CPU:
577 drc->name = g_strdup_printf("CPU %d", id);
578 break;
579 case SPAPR_DR_CONNECTOR_TYPE_PHB:
580 drc->name = g_strdup_printf("PHB %d", id);
581 break;
582 case SPAPR_DR_CONNECTOR_TYPE_VIO:
583 case SPAPR_DR_CONNECTOR_TYPE_PCI:
584 drc->name = g_strdup_printf("C%d", id);
585 break;
586 case SPAPR_DR_CONNECTOR_TYPE_LMB:
587 drc->name = g_strdup_printf("LMB %d", id);
588 break;
589 default:
590 g_assert(false);
591 }
592
593
594 if (drc->type == SPAPR_DR_CONNECTOR_TYPE_PCI) {
595 drc->allocation_state = SPAPR_DR_ALLOCATION_STATE_USABLE;
596 }
597
598 return drc;
599}
600
601static void spapr_dr_connector_instance_init(Object *obj)
602{
603 sPAPRDRConnector *drc = SPAPR_DR_CONNECTOR(obj);
604
605 object_property_add_uint32_ptr(obj, "isolation-state",
606 &drc->isolation_state, NULL);
607 object_property_add_uint32_ptr(obj, "indicator-state",
608 &drc->indicator_state, NULL);
609 object_property_add_uint32_ptr(obj, "allocation-state",
610 &drc->allocation_state, NULL);
611 object_property_add_uint32_ptr(obj, "id", &drc->id, NULL);
612 object_property_add(obj, "index", "uint32", prop_get_index,
613 NULL, NULL, NULL, NULL);
614 object_property_add(obj, "connector_type", "uint32", prop_get_type,
615 NULL, NULL, NULL, NULL);
616 object_property_add_str(obj, "name", prop_get_name, NULL, NULL);
617 object_property_add(obj, "entity-sense", "uint32", prop_get_entity_sense,
618 NULL, NULL, NULL, NULL);
619 object_property_add(obj, "fdt", "struct", prop_get_fdt,
620 NULL, NULL, NULL, NULL);
621}
622
623static void spapr_dr_connector_class_init(ObjectClass *k, void *data)
624{
625 DeviceClass *dk = DEVICE_CLASS(k);
626 sPAPRDRConnectorClass *drck = SPAPR_DR_CONNECTOR_CLASS(k);
627
628 dk->reset = reset;
629 dk->realize = realize;
630 dk->unrealize = unrealize;
631 drck->set_isolation_state = set_isolation_state;
632 drck->set_indicator_state = set_indicator_state;
633 drck->set_allocation_state = set_allocation_state;
634 drck->get_index = get_index;
635 drck->get_type = get_type;
636 drck->get_name = get_name;
637 drck->get_fdt = get_fdt;
638 drck->set_configured = set_configured;
639 drck->entity_sense = entity_sense;
640 drck->attach = attach;
641 drck->detach = detach;
642 drck->release_pending = release_pending;
643 drck->set_signalled = set_signalled;
644
645
646
647 dk->cannot_instantiate_with_device_add_yet = true;
648}
649
650static const TypeInfo spapr_dr_connector_info = {
651 .name = TYPE_SPAPR_DR_CONNECTOR,
652 .parent = TYPE_DEVICE,
653 .instance_size = sizeof(sPAPRDRConnector),
654 .instance_init = spapr_dr_connector_instance_init,
655 .class_size = sizeof(sPAPRDRConnectorClass),
656 .class_init = spapr_dr_connector_class_init,
657};
658
659static void spapr_drc_register_types(void)
660{
661 type_register_static(&spapr_dr_connector_info);
662}
663
664type_init(spapr_drc_register_types)
665
666
667
668sPAPRDRConnector *spapr_dr_connector_by_index(uint32_t index)
669{
670 Object *obj;
671 char name[256];
672
673 snprintf(name, sizeof(name), "%s/%x", DRC_CONTAINER_PATH, index);
674 obj = object_resolve_path(name, NULL);
675
676 return !obj ? NULL : SPAPR_DR_CONNECTOR(obj);
677}
678
679sPAPRDRConnector *spapr_dr_connector_by_id(sPAPRDRConnectorType type,
680 uint32_t id)
681{
682 return spapr_dr_connector_by_index(
683 (get_type_shift(type) << DRC_INDEX_TYPE_SHIFT) |
684 (id & DRC_INDEX_ID_MASK));
685}
686
687
688
689
690
691
692static const char *spapr_drc_get_type_str(sPAPRDRConnectorType type)
693{
694 switch (type) {
695 case SPAPR_DR_CONNECTOR_TYPE_CPU:
696 return "CPU";
697 case SPAPR_DR_CONNECTOR_TYPE_PHB:
698 return "PHB";
699 case SPAPR_DR_CONNECTOR_TYPE_VIO:
700 return "SLOT";
701 case SPAPR_DR_CONNECTOR_TYPE_PCI:
702 return "28";
703 case SPAPR_DR_CONNECTOR_TYPE_LMB:
704 return "MEM";
705 default:
706 g_assert(false);
707 }
708
709 return NULL;
710}
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726int spapr_drc_populate_dt(void *fdt, int fdt_offset, Object *owner,
727 uint32_t drc_type_mask)
728{
729 Object *root_container;
730 ObjectProperty *prop;
731 ObjectPropertyIterator iter;
732 uint32_t drc_count = 0;
733 GArray *drc_indexes, *drc_power_domains;
734 GString *drc_names, *drc_types;
735 int ret;
736
737
738
739
740
741
742
743 drc_indexes = g_array_new(false, true, sizeof(uint32_t));
744 drc_indexes = g_array_set_size(drc_indexes, 1);
745 drc_power_domains = g_array_new(false, true, sizeof(uint32_t));
746 drc_power_domains = g_array_set_size(drc_power_domains, 1);
747 drc_names = g_string_set_size(g_string_new(NULL), sizeof(uint32_t));
748 drc_types = g_string_set_size(g_string_new(NULL), sizeof(uint32_t));
749
750
751
752
753 root_container = container_get(object_get_root(), DRC_CONTAINER_PATH);
754
755 object_property_iter_init(&iter, root_container);
756 while ((prop = object_property_iter_next(&iter))) {
757 Object *obj;
758 sPAPRDRConnector *drc;
759 sPAPRDRConnectorClass *drck;
760 uint32_t drc_index, drc_power_domain;
761
762 if (!strstart(prop->type, "link<", NULL)) {
763 continue;
764 }
765
766 obj = object_property_get_link(root_container, prop->name, NULL);
767 drc = SPAPR_DR_CONNECTOR(obj);
768 drck = SPAPR_DR_CONNECTOR_GET_CLASS(drc);
769
770 if (owner && (drc->owner != owner)) {
771 continue;
772 }
773
774 if ((drc->type & drc_type_mask) == 0) {
775 continue;
776 }
777
778 drc_count++;
779
780
781 drc_index = cpu_to_be32(drck->get_index(drc));
782 g_array_append_val(drc_indexes, drc_index);
783
784
785 drc_power_domain = cpu_to_be32(-1);
786 g_array_append_val(drc_power_domains, drc_power_domain);
787
788
789 drc_names = g_string_append(drc_names, drck->get_name(drc));
790 drc_names = g_string_insert_len(drc_names, -1, "\0", 1);
791
792
793 drc_types = g_string_append(drc_types,
794 spapr_drc_get_type_str(drc->type));
795 drc_types = g_string_insert_len(drc_types, -1, "\0", 1);
796 }
797
798
799
800
801 *(uint32_t *)drc_indexes->data = cpu_to_be32(drc_count);
802 *(uint32_t *)drc_power_domains->data = cpu_to_be32(drc_count);
803 *(uint32_t *)drc_names->str = cpu_to_be32(drc_count);
804 *(uint32_t *)drc_types->str = cpu_to_be32(drc_count);
805
806 ret = fdt_setprop(fdt, fdt_offset, "ibm,drc-indexes",
807 drc_indexes->data,
808 drc_indexes->len * sizeof(uint32_t));
809 if (ret) {
810 fprintf(stderr, "Couldn't create ibm,drc-indexes property\n");
811 goto out;
812 }
813
814 ret = fdt_setprop(fdt, fdt_offset, "ibm,drc-power-domains",
815 drc_power_domains->data,
816 drc_power_domains->len * sizeof(uint32_t));
817 if (ret) {
818 fprintf(stderr, "Couldn't finalize ibm,drc-power-domains property\n");
819 goto out;
820 }
821
822 ret = fdt_setprop(fdt, fdt_offset, "ibm,drc-names",
823 drc_names->str, drc_names->len);
824 if (ret) {
825 fprintf(stderr, "Couldn't finalize ibm,drc-names property\n");
826 goto out;
827 }
828
829 ret = fdt_setprop(fdt, fdt_offset, "ibm,drc-types",
830 drc_types->str, drc_types->len);
831 if (ret) {
832 fprintf(stderr, "Couldn't finalize ibm,drc-types property\n");
833 goto out;
834 }
835
836out:
837 g_array_free(drc_indexes, true);
838 g_array_free(drc_power_domains, true);
839 g_string_free(drc_names, true);
840 g_string_free(drc_types, true);
841
842 return ret;
843}
844