]> git.proxmox.com Git - mirror_qemu.git/blame - hw/ppc/spapr_drc.c
pseries: Correct panic behaviour for pseries machine type
[mirror_qemu.git] / hw / ppc / spapr_drc.c
CommitLineData
bbf5c878
MR
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
0d75590d 13#include "qemu/osdep.h"
da34e65c 14#include "qapi/error.h"
4771d756 15#include "cpu.h"
f348b6d1 16#include "qemu/cutils.h"
bbf5c878
MR
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"
0cb688d2 22#include "hw/ppc/spapr.h" /* for RTAS return codes */
31834723 23#include "hw/pci-host/spapr.h" /* spapr_phb_remove_pci_device_cb callback */
24ac7755 24#include "trace.h"
bbf5c878
MR
25
26#define DRC_CONTAINER_PATH "/dr-connector"
27#define DRC_INDEX_TYPE_SHIFT 28
627c2ef7 28#define DRC_INDEX_ID_MASK ((1ULL << DRC_INDEX_TYPE_SHIFT) - 1)
bbf5c878 29
2d335818
DG
30sPAPRDRConnectorType spapr_drc_type(sPAPRDRConnector *drc)
31{
32 sPAPRDRConnectorClass *drck = SPAPR_DR_CONNECTOR_GET_CLASS(drc);
33
34 return 1 << drck->typeshift;
35}
36
0b55aa91 37uint32_t spapr_drc_index(sPAPRDRConnector *drc)
bbf5c878 38{
2d335818
DG
39 sPAPRDRConnectorClass *drck = SPAPR_DR_CONNECTOR_GET_CLASS(drc);
40
bbf5c878
MR
41 /* no set format for a drc index: it only needs to be globally
42 * unique. this is how we encode the DRC type on bare-metal
43 * however, so might as well do that here
44 */
2d335818
DG
45 return (drck->typeshift << DRC_INDEX_TYPE_SHIFT)
46 | (drc->id & DRC_INDEX_ID_MASK);
bbf5c878
MR
47}
48
0cb688d2
MR
49static uint32_t set_isolation_state(sPAPRDRConnector *drc,
50 sPAPRDRIsolationState state)
bbf5c878
MR
51{
52 sPAPRDRConnectorClass *drck = SPAPR_DR_CONNECTOR_GET_CLASS(drc);
53
0b55aa91 54 trace_spapr_drc_set_isolation_state(spapr_drc_index(drc), state);
bbf5c878 55
b8fdd530
DG
56 /* if the guest is configuring a device attached to this DRC, we
57 * should reset the configuration state at this point since it may
58 * no longer be reliable (guest released device and needs to start
59 * over, or unplug occurred so the FDT is no longer valid)
60 */
61 if (state == SPAPR_DR_ISOLATION_STATE_ISOLATED) {
62 g_free(drc->ccs);
63 drc->ccs = NULL;
64 }
65
9d1852ce 66 if (state == SPAPR_DR_ISOLATION_STATE_UNISOLATED) {
b12227af 67 /* cannot unisolate a non-existent resource, and, or resources
9d1852ce
MR
68 * which are in an 'UNUSABLE' allocation state. (PAPR 2.7, 13.5.3.5)
69 */
70 if (!drc->dev ||
71 drc->allocation_state == SPAPR_DR_ALLOCATION_STATE_UNUSABLE) {
72 return RTAS_OUT_NO_SUCH_INDICATOR;
73 }
74 }
75
cf632463
BR
76 /*
77 * Fail any requests to ISOLATE the LMB DRC if this LMB doesn't
78 * belong to a DIMM device that is marked for removal.
79 *
80 * Currently the guest userspace tool drmgr that drives the memory
81 * hotplug/unplug will just try to remove a set of 'removable' LMBs
82 * in response to a hot unplug request that is based on drc-count.
83 * If the LMB being removed doesn't belong to a DIMM device that is
84 * actually being unplugged, fail the isolation request here.
85 */
2d335818 86 if (spapr_drc_type(drc) == SPAPR_DR_CONNECTOR_TYPE_LMB) {
cf632463
BR
87 if ((state == SPAPR_DR_ISOLATION_STATE_ISOLATED) &&
88 !drc->awaiting_release) {
89 return RTAS_OUT_HW_ERROR;
90 }
91 }
92
bbf5c878
MR
93 drc->isolation_state = state;
94
95 if (drc->isolation_state == SPAPR_DR_ISOLATION_STATE_ISOLATED) {
96 /* if we're awaiting release, but still in an unconfigured state,
97 * it's likely the guest is still in the process of configuring
98 * the device and is transitioning the devices to an ISOLATED
99 * state as a part of that process. so we only complete the
100 * removal when this transition happens for a device in a
101 * configured state, as suggested by the state diagram from
102 * PAPR+ 2.7, 13.4
103 */
104 if (drc->awaiting_release) {
0b55aa91 105 uint32_t drc_index = spapr_drc_index(drc);
bbf5c878 106 if (drc->configured) {
0b55aa91 107 trace_spapr_drc_set_isolation_state_finalizing(drc_index);
31834723 108 drck->detach(drc, DEVICE(drc->dev), NULL);
bbf5c878 109 } else {
0b55aa91 110 trace_spapr_drc_set_isolation_state_deferring(drc_index);
bbf5c878
MR
111 }
112 }
113 drc->configured = false;
114 }
115
0cb688d2 116 return RTAS_OUT_SUCCESS;
bbf5c878
MR
117}
118
0cb688d2
MR
119static uint32_t set_indicator_state(sPAPRDRConnector *drc,
120 sPAPRDRIndicatorState state)
bbf5c878 121{
0b55aa91 122 trace_spapr_drc_set_indicator_state(spapr_drc_index(drc), state);
bbf5c878 123 drc->indicator_state = state;
0cb688d2 124 return RTAS_OUT_SUCCESS;
bbf5c878
MR
125}
126
0cb688d2
MR
127static uint32_t set_allocation_state(sPAPRDRConnector *drc,
128 sPAPRDRAllocationState state)
bbf5c878
MR
129{
130 sPAPRDRConnectorClass *drck = SPAPR_DR_CONNECTOR_GET_CLASS(drc);
131
0b55aa91 132 trace_spapr_drc_set_allocation_state(spapr_drc_index(drc), state);
bbf5c878 133
9d1852ce
MR
134 if (state == SPAPR_DR_ALLOCATION_STATE_USABLE) {
135 /* if there's no resource/device associated with the DRC, there's
136 * no way for us to put it in an allocation state consistent with
137 * being 'USABLE'. PAPR 2.7, 13.5.3.4 documents that this should
138 * result in an RTAS return code of -3 / "no such indicator"
139 */
140 if (!drc->dev) {
141 return RTAS_OUT_NO_SUCH_INDICATOR;
142 }
fe6824d1
LV
143 if (drc->awaiting_release && drc->awaiting_allocation) {
144 /* kernel is acknowledging a previous hotplug event
145 * while we are already removing it.
146 * it's safe to ignore awaiting_allocation here since we know the
147 * situation is predicated on the guest either already having done
148 * so (boot-time hotplug), or never being able to acquire in the
149 * first place (hotplug followed by immediate unplug).
150 */
151 drc->awaiting_allocation_skippable = true;
152 return RTAS_OUT_NO_SUCH_INDICATOR;
153 }
9d1852ce
MR
154 }
155
2d335818 156 if (spapr_drc_type(drc) != SPAPR_DR_CONNECTOR_TYPE_PCI) {
bbf5c878
MR
157 drc->allocation_state = state;
158 if (drc->awaiting_release &&
159 drc->allocation_state == SPAPR_DR_ALLOCATION_STATE_UNUSABLE) {
0b55aa91
DG
160 uint32_t drc_index = spapr_drc_index(drc);
161 trace_spapr_drc_set_allocation_state_finalizing(drc_index);
31834723 162 drck->detach(drc, DEVICE(drc->dev), NULL);
aab99135
BR
163 } else if (drc->allocation_state == SPAPR_DR_ALLOCATION_STATE_USABLE) {
164 drc->awaiting_allocation = false;
bbf5c878
MR
165 }
166 }
0cb688d2 167 return RTAS_OUT_SUCCESS;
bbf5c878
MR
168}
169
bbf5c878
MR
170static const char *get_name(sPAPRDRConnector *drc)
171{
172 return drc->name;
173}
174
f40eb921
MR
175/* has the guest been notified of device attachment? */
176static void set_signalled(sPAPRDRConnector *drc)
177{
178 drc->signalled = true;
179}
180
bbf5c878
MR
181/*
182 * dr-entity-sense sensor value
183 * returned via get-sensor-state RTAS calls
184 * as expected by state diagram in PAPR+ 2.7, 13.4
185 * based on the current allocation/indicator/power states
186 * for the DR connector.
187 */
0cb688d2 188static uint32_t entity_sense(sPAPRDRConnector *drc, sPAPRDREntitySense *state)
bbf5c878 189{
bbf5c878 190 if (drc->dev) {
2d335818 191 if (spapr_drc_type(drc) != SPAPR_DR_CONNECTOR_TYPE_PCI &&
bbf5c878
MR
192 drc->allocation_state == SPAPR_DR_ALLOCATION_STATE_UNUSABLE) {
193 /* for logical DR, we return a state of UNUSABLE
194 * iff the allocation state UNUSABLE.
195 * Otherwise, report the state as USABLE/PRESENT,
196 * as we would for PCI.
197 */
0cb688d2 198 *state = SPAPR_DR_ENTITY_SENSE_UNUSABLE;
bbf5c878
MR
199 } else {
200 /* this assumes all PCI devices are assigned to
201 * a 'live insertion' power domain, where QEMU
202 * manages power state automatically as opposed
203 * to the guest. present, non-PCI resources are
204 * unaffected by power state.
205 */
0cb688d2 206 *state = SPAPR_DR_ENTITY_SENSE_PRESENT;
bbf5c878
MR
207 }
208 } else {
2d335818 209 if (spapr_drc_type(drc) == SPAPR_DR_CONNECTOR_TYPE_PCI) {
bbf5c878
MR
210 /* PCI devices, and only PCI devices, use EMPTY
211 * in cases where we'd otherwise use UNUSABLE
212 */
0cb688d2 213 *state = SPAPR_DR_ENTITY_SENSE_EMPTY;
bbf5c878 214 } else {
0cb688d2 215 *state = SPAPR_DR_ENTITY_SENSE_UNUSABLE;
bbf5c878
MR
216 }
217 }
218
0b55aa91 219 trace_spapr_drc_entity_sense(spapr_drc_index(drc), *state);
0cb688d2 220 return RTAS_OUT_SUCCESS;
bbf5c878
MR
221}
222
d7bce999
EB
223static void prop_get_index(Object *obj, Visitor *v, const char *name,
224 void *opaque, Error **errp)
bbf5c878
MR
225{
226 sPAPRDRConnector *drc = SPAPR_DR_CONNECTOR(obj);
0b55aa91 227 uint32_t value = spapr_drc_index(drc);
51e72bc1 228 visit_type_uint32(v, name, &value, errp);
bbf5c878
MR
229}
230
bbf5c878
MR
231static char *prop_get_name(Object *obj, Error **errp)
232{
233 sPAPRDRConnector *drc = SPAPR_DR_CONNECTOR(obj);
234 sPAPRDRConnectorClass *drck = SPAPR_DR_CONNECTOR_GET_CLASS(drc);
235 return g_strdup(drck->get_name(drc));
236}
237
d7bce999
EB
238static void prop_get_fdt(Object *obj, Visitor *v, const char *name,
239 void *opaque, Error **errp)
bbf5c878
MR
240{
241 sPAPRDRConnector *drc = SPAPR_DR_CONNECTOR(obj);
c75304a1 242 Error *err = NULL;
bbf5c878
MR
243 int fdt_offset_next, fdt_offset, fdt_depth;
244 void *fdt;
245
246 if (!drc->fdt) {
a543a554 247 visit_type_null(v, NULL, errp);
bbf5c878
MR
248 return;
249 }
250
251 fdt = drc->fdt;
252 fdt_offset = drc->fdt_start_offset;
253 fdt_depth = 0;
254
255 do {
256 const char *name = NULL;
257 const struct fdt_property *prop = NULL;
258 int prop_len = 0, name_len = 0;
259 uint32_t tag;
260
261 tag = fdt_next_tag(fdt, fdt_offset, &fdt_offset_next);
262 switch (tag) {
263 case FDT_BEGIN_NODE:
264 fdt_depth++;
265 name = fdt_get_name(fdt, fdt_offset, &name_len);
337283df 266 visit_start_struct(v, name, NULL, 0, &err);
c75304a1
MA
267 if (err) {
268 error_propagate(errp, err);
269 return;
270 }
bbf5c878
MR
271 break;
272 case FDT_END_NODE:
273 /* shouldn't ever see an FDT_END_NODE before FDT_BEGIN_NODE */
274 g_assert(fdt_depth > 0);
15c2f669 275 visit_check_struct(v, &err);
1158bb2a 276 visit_end_struct(v, NULL);
c75304a1
MA
277 if (err) {
278 error_propagate(errp, err);
279 return;
280 }
bbf5c878
MR
281 fdt_depth--;
282 break;
283 case FDT_PROP: {
284 int i;
285 prop = fdt_get_property_by_offset(fdt, fdt_offset, &prop_len);
286 name = fdt_string(fdt, fdt32_to_cpu(prop->nameoff));
d9f62dde 287 visit_start_list(v, name, NULL, 0, &err);
c75304a1
MA
288 if (err) {
289 error_propagate(errp, err);
290 return;
291 }
bbf5c878 292 for (i = 0; i < prop_len; i++) {
51e72bc1 293 visit_type_uint8(v, NULL, (uint8_t *)&prop->data[i], &err);
c75304a1
MA
294 if (err) {
295 error_propagate(errp, err);
296 return;
297 }
298 }
a4a1c70d 299 visit_check_list(v, &err);
1158bb2a 300 visit_end_list(v, NULL);
a4a1c70d
MA
301 if (err) {
302 error_propagate(errp, err);
303 return;
304 }
bbf5c878
MR
305 break;
306 }
307 default:
308 error_setg(&error_abort, "device FDT in unexpected state: %d", tag);
309 }
310 fdt_offset = fdt_offset_next;
311 } while (fdt_depth != 0);
312}
313
314static void attach(sPAPRDRConnector *drc, DeviceState *d, void *fdt,
315 int fdt_start_offset, bool coldplug, Error **errp)
316{
0b55aa91 317 trace_spapr_drc_attach(spapr_drc_index(drc));
bbf5c878
MR
318
319 if (drc->isolation_state != SPAPR_DR_ISOLATION_STATE_ISOLATED) {
320 error_setg(errp, "an attached device is still awaiting release");
321 return;
322 }
2d335818 323 if (spapr_drc_type(drc) == SPAPR_DR_CONNECTOR_TYPE_PCI) {
bbf5c878
MR
324 g_assert(drc->allocation_state == SPAPR_DR_ALLOCATION_STATE_USABLE);
325 }
326 g_assert(fdt || coldplug);
327
328 /* NOTE: setting initial isolation state to UNISOLATED means we can't
329 * detach unless guest has a userspace/kernel that moves this state
330 * back to ISOLATED in response to an unplug event, or this is done
331 * manually by the admin prior. if we force things while the guest
332 * may be accessing the device, we can easily crash the guest, so we
333 * we defer completion of removal in such cases to the reset() hook.
334 */
2d335818 335 if (spapr_drc_type(drc) == SPAPR_DR_CONNECTOR_TYPE_PCI) {
bbf5c878
MR
336 drc->isolation_state = SPAPR_DR_ISOLATION_STATE_UNISOLATED;
337 }
338 drc->indicator_state = SPAPR_DR_INDICATOR_STATE_ACTIVE;
339
340 drc->dev = d;
341 drc->fdt = fdt;
342 drc->fdt_start_offset = fdt_start_offset;
785652dc 343 drc->configured = coldplug;
df18b2db
MR
344 /* 'logical' DR resources such as memory/cpus are in some cases treated
345 * as a pool of resources from which the guest is free to choose from
346 * based on only a count. for resources that can be assigned in this
347 * fashion, we must assume the resource is signalled immediately
348 * since a single hotplug request might make an arbitrary number of
349 * such attached resources available to the guest, as opposed to
350 * 'physical' DR resources such as PCI where each device/resource is
351 * signalled individually.
352 */
2d335818 353 drc->signalled = (spapr_drc_type(drc) != SPAPR_DR_CONNECTOR_TYPE_PCI)
df18b2db 354 ? true : coldplug;
bbf5c878 355
2d335818 356 if (spapr_drc_type(drc) != SPAPR_DR_CONNECTOR_TYPE_PCI) {
aab99135
BR
357 drc->awaiting_allocation = true;
358 }
359
bbf5c878
MR
360 object_property_add_link(OBJECT(drc), "device",
361 object_get_typename(OBJECT(drc->dev)),
362 (Object **)(&drc->dev),
363 NULL, 0, NULL);
364}
365
31834723 366static void detach(sPAPRDRConnector *drc, DeviceState *d, Error **errp)
bbf5c878 367{
0b55aa91 368 trace_spapr_drc_detach(spapr_drc_index(drc));
bbf5c878 369
f40eb921
MR
370 /* if we've signalled device presence to the guest, or if the guest
371 * has gone ahead and configured the device (via manually-executed
372 * device add via drmgr in guest, namely), we need to wait
373 * for the guest to quiesce the device before completing detach.
374 * Otherwise, we can assume the guest hasn't seen it and complete the
375 * detach immediately. Note that there is a small race window
376 * just before, or during, configuration, which is this context
377 * refers mainly to fetching the device tree via RTAS.
378 * During this window the device access will be arbitrated by
379 * associated DRC, which will simply fail the RTAS calls as invalid.
380 * This is recoverable within guest and current implementations of
381 * drmgr should be able to cope.
382 */
383 if (!drc->signalled && !drc->configured) {
384 /* if the guest hasn't seen the device we can't rely on it to
385 * set it back to an isolated state via RTAS, so do it here manually
386 */
387 drc->isolation_state = SPAPR_DR_ISOLATION_STATE_ISOLATED;
388 }
389
bbf5c878 390 if (drc->isolation_state != SPAPR_DR_ISOLATION_STATE_ISOLATED) {
0b55aa91 391 trace_spapr_drc_awaiting_isolated(spapr_drc_index(drc));
bbf5c878
MR
392 drc->awaiting_release = true;
393 return;
394 }
395
2d335818 396 if (spapr_drc_type(drc) != SPAPR_DR_CONNECTOR_TYPE_PCI &&
bbf5c878 397 drc->allocation_state != SPAPR_DR_ALLOCATION_STATE_UNUSABLE) {
0b55aa91 398 trace_spapr_drc_awaiting_unusable(spapr_drc_index(drc));
bbf5c878
MR
399 drc->awaiting_release = true;
400 return;
401 }
402
aab99135 403 if (drc->awaiting_allocation) {
fe6824d1
LV
404 if (!drc->awaiting_allocation_skippable) {
405 drc->awaiting_release = true;
0b55aa91 406 trace_spapr_drc_awaiting_allocation(spapr_drc_index(drc));
fe6824d1
LV
407 return;
408 }
aab99135
BR
409 }
410
bbf5c878
MR
411 drc->indicator_state = SPAPR_DR_INDICATOR_STATE_INACTIVE;
412
2d335818
DG
413 /* Calling release callbacks based on spapr_drc_type(drc). */
414 switch (spapr_drc_type(drc)) {
31834723
DHB
415 case SPAPR_DR_CONNECTOR_TYPE_CPU:
416 spapr_core_release(drc->dev);
417 break;
418 case SPAPR_DR_CONNECTOR_TYPE_PCI:
419 spapr_phb_remove_pci_device_cb(drc->dev);
420 break;
421 case SPAPR_DR_CONNECTOR_TYPE_LMB:
422 spapr_lmb_release(drc->dev);
423 break;
424 case SPAPR_DR_CONNECTOR_TYPE_PHB:
425 case SPAPR_DR_CONNECTOR_TYPE_VIO:
426 default:
427 g_assert(false);
bbf5c878
MR
428 }
429
430 drc->awaiting_release = false;
fe6824d1 431 drc->awaiting_allocation_skippable = false;
bbf5c878
MR
432 g_free(drc->fdt);
433 drc->fdt = NULL;
434 drc->fdt_start_offset = 0;
435 object_property_del(OBJECT(drc), "device", NULL);
436 drc->dev = NULL;
bbf5c878
MR
437}
438
439static bool release_pending(sPAPRDRConnector *drc)
440{
441 return drc->awaiting_release;
442}
443
444static void reset(DeviceState *d)
445{
446 sPAPRDRConnector *drc = SPAPR_DR_CONNECTOR(d);
447 sPAPRDRConnectorClass *drck = SPAPR_DR_CONNECTOR_GET_CLASS(drc);
f40eb921 448 sPAPRDREntitySense state;
bbf5c878 449
0b55aa91 450 trace_spapr_drc_reset(spapr_drc_index(drc));
b8fdd530
DG
451
452 g_free(drc->ccs);
453 drc->ccs = NULL;
454
bbf5c878
MR
455 /* immediately upon reset we can safely assume DRCs whose devices
456 * are pending removal can be safely removed, and that they will
457 * subsequently be left in an ISOLATED state. move the DRC to this
458 * state in these cases (which will in turn complete any pending
459 * device removals)
460 */
461 if (drc->awaiting_release) {
462 drck->set_isolation_state(drc, SPAPR_DR_ISOLATION_STATE_ISOLATED);
463 /* generally this should also finalize the removal, but if the device
464 * hasn't yet been configured we normally defer removal under the
465 * assumption that this transition is taking place as part of device
466 * configuration. so check if we're still waiting after this, and
467 * force removal if we are
468 */
469 if (drc->awaiting_release) {
31834723 470 drck->detach(drc, DEVICE(drc->dev), NULL);
bbf5c878
MR
471 }
472
473 /* non-PCI devices may be awaiting a transition to UNUSABLE */
2d335818 474 if (spapr_drc_type(drc) != SPAPR_DR_CONNECTOR_TYPE_PCI &&
bbf5c878
MR
475 drc->awaiting_release) {
476 drck->set_allocation_state(drc, SPAPR_DR_ALLOCATION_STATE_UNUSABLE);
477 }
478 }
f40eb921
MR
479
480 drck->entity_sense(drc, &state);
481 if (state == SPAPR_DR_ENTITY_SENSE_PRESENT) {
482 drck->set_signalled(drc);
483 }
bbf5c878
MR
484}
485
a50919dd
DHB
486static bool spapr_drc_needed(void *opaque)
487{
488 sPAPRDRConnector *drc = (sPAPRDRConnector *)opaque;
489 sPAPRDRConnectorClass *drck = SPAPR_DR_CONNECTOR_GET_CLASS(drc);
490 bool rc = false;
491 sPAPRDREntitySense value;
492 drck->entity_sense(drc, &value);
493
494 /* If no dev is plugged in there is no need to migrate the DRC state */
495 if (value != SPAPR_DR_ENTITY_SENSE_PRESENT) {
496 return false;
497 }
498
499 /*
500 * If there is dev plugged in, we need to migrate the DRC state when
501 * it is different from cold-plugged state
502 */
2d335818 503 switch (spapr_drc_type(drc)) {
a50919dd 504 case SPAPR_DR_CONNECTOR_TYPE_PCI:
a50919dd
DHB
505 case SPAPR_DR_CONNECTOR_TYPE_CPU:
506 case SPAPR_DR_CONNECTOR_TYPE_LMB:
a32e900b
GK
507 rc = !((drc->isolation_state == SPAPR_DR_ISOLATION_STATE_UNISOLATED) &&
508 (drc->allocation_state == SPAPR_DR_ALLOCATION_STATE_USABLE) &&
a50919dd
DHB
509 drc->configured && drc->signalled && !drc->awaiting_release);
510 break;
511 case SPAPR_DR_CONNECTOR_TYPE_PHB:
512 case SPAPR_DR_CONNECTOR_TYPE_VIO:
513 default:
a32e900b 514 g_assert_not_reached();
a50919dd
DHB
515 }
516 return rc;
517}
518
519static const VMStateDescription vmstate_spapr_drc = {
520 .name = "spapr_drc",
521 .version_id = 1,
522 .minimum_version_id = 1,
523 .needed = spapr_drc_needed,
524 .fields = (VMStateField []) {
525 VMSTATE_UINT32(isolation_state, sPAPRDRConnector),
526 VMSTATE_UINT32(allocation_state, sPAPRDRConnector),
527 VMSTATE_UINT32(indicator_state, sPAPRDRConnector),
528 VMSTATE_BOOL(configured, sPAPRDRConnector),
529 VMSTATE_BOOL(awaiting_release, sPAPRDRConnector),
530 VMSTATE_BOOL(awaiting_allocation, sPAPRDRConnector),
531 VMSTATE_BOOL(signalled, sPAPRDRConnector),
532 VMSTATE_END_OF_LIST()
533 }
534};
535
bbf5c878
MR
536static void realize(DeviceState *d, Error **errp)
537{
538 sPAPRDRConnector *drc = SPAPR_DR_CONNECTOR(d);
bbf5c878
MR
539 Object *root_container;
540 char link_name[256];
541 gchar *child_name;
542 Error *err = NULL;
543
0b55aa91 544 trace_spapr_drc_realize(spapr_drc_index(drc));
bbf5c878
MR
545 /* NOTE: we do this as part of realize/unrealize due to the fact
546 * that the guest will communicate with the DRC via RTAS calls
547 * referencing the global DRC index. By unlinking the DRC
548 * from DRC_CONTAINER_PATH/<drc_index> we effectively make it
549 * inaccessible by the guest, since lookups rely on this path
550 * existing in the composition tree
551 */
552 root_container = container_get(object_get_root(), DRC_CONTAINER_PATH);
0b55aa91 553 snprintf(link_name, sizeof(link_name), "%x", spapr_drc_index(drc));
bbf5c878 554 child_name = object_get_canonical_path_component(OBJECT(drc));
0b55aa91 555 trace_spapr_drc_realize_child(spapr_drc_index(drc), child_name);
bbf5c878
MR
556 object_property_add_alias(root_container, link_name,
557 drc->owner, child_name, &err);
558 if (err) {
4fffeb5e 559 error_report_err(err);
bbf5c878
MR
560 object_unref(OBJECT(drc));
561 }
586d2142 562 g_free(child_name);
0b55aa91 563 vmstate_register(DEVICE(drc), spapr_drc_index(drc), &vmstate_spapr_drc,
a50919dd 564 drc);
0b55aa91 565 trace_spapr_drc_realize_complete(spapr_drc_index(drc));
bbf5c878
MR
566}
567
568static void unrealize(DeviceState *d, Error **errp)
569{
570 sPAPRDRConnector *drc = SPAPR_DR_CONNECTOR(d);
bbf5c878
MR
571 Object *root_container;
572 char name[256];
573 Error *err = NULL;
574
0b55aa91 575 trace_spapr_drc_unrealize(spapr_drc_index(drc));
bbf5c878 576 root_container = container_get(object_get_root(), DRC_CONTAINER_PATH);
0b55aa91 577 snprintf(name, sizeof(name), "%x", spapr_drc_index(drc));
bbf5c878
MR
578 object_property_del(root_container, name, &err);
579 if (err) {
4fffeb5e 580 error_report_err(err);
bbf5c878
MR
581 object_unref(OBJECT(drc));
582 }
583}
584
2d335818 585sPAPRDRConnector *spapr_dr_connector_new(Object *owner, const char *type,
bbf5c878
MR
586 uint32_t id)
587{
2d335818 588 sPAPRDRConnector *drc = SPAPR_DR_CONNECTOR(object_new(type));
94649d42 589 char *prop_name;
bbf5c878 590
bbf5c878
MR
591 drc->id = id;
592 drc->owner = owner;
0b55aa91
DG
593 prop_name = g_strdup_printf("dr-connector[%"PRIu32"]",
594 spapr_drc_index(drc));
94649d42 595 object_property_add_child(owner, prop_name, OBJECT(drc), NULL);
bbf5c878 596 object_property_set_bool(OBJECT(drc), true, "realized", NULL);
94649d42 597 g_free(prop_name);
bbf5c878
MR
598
599 /* human-readable name for a DRC to encode into the DT
600 * description. this is mainly only used within a guest in place
601 * of the unique DRC index.
602 *
603 * in the case of VIO/PCI devices, it corresponds to a
604 * "location code" that maps a logical device/function (DRC index)
605 * to a physical (or virtual in the case of VIO) location in the
606 * system by chaining together the "location label" for each
607 * encapsulating component.
608 *
609 * since this is more to do with diagnosing physical hardware
610 * issues than guest compatibility, we choose location codes/DRC
611 * names that adhere to the documented format, but avoid encoding
612 * the entire topology information into the label/code, instead
613 * just using the location codes based on the labels for the
614 * endpoints (VIO/PCI adaptor connectors), which is basically
615 * just "C" followed by an integer ID.
616 *
617 * DRC names as documented by PAPR+ v2.7, 13.5.2.4
618 * location codes as documented by PAPR+ v2.7, 12.3.1.5
619 */
2d335818 620 switch (spapr_drc_type(drc)) {
bbf5c878
MR
621 case SPAPR_DR_CONNECTOR_TYPE_CPU:
622 drc->name = g_strdup_printf("CPU %d", id);
623 break;
624 case SPAPR_DR_CONNECTOR_TYPE_PHB:
625 drc->name = g_strdup_printf("PHB %d", id);
626 break;
627 case SPAPR_DR_CONNECTOR_TYPE_VIO:
628 case SPAPR_DR_CONNECTOR_TYPE_PCI:
629 drc->name = g_strdup_printf("C%d", id);
630 break;
631 case SPAPR_DR_CONNECTOR_TYPE_LMB:
632 drc->name = g_strdup_printf("LMB %d", id);
633 break;
634 default:
635 g_assert(false);
636 }
637
638 /* PCI slot always start in a USABLE state, and stay there */
2d335818 639 if (spapr_drc_type(drc) == SPAPR_DR_CONNECTOR_TYPE_PCI) {
bbf5c878
MR
640 drc->allocation_state = SPAPR_DR_ALLOCATION_STATE_USABLE;
641 }
642
643 return drc;
644}
645
646static void spapr_dr_connector_instance_init(Object *obj)
647{
648 sPAPRDRConnector *drc = SPAPR_DR_CONNECTOR(obj);
649
bbf5c878
MR
650 object_property_add_uint32_ptr(obj, "id", &drc->id, NULL);
651 object_property_add(obj, "index", "uint32", prop_get_index,
652 NULL, NULL, NULL, NULL);
bbf5c878 653 object_property_add_str(obj, "name", prop_get_name, NULL, NULL);
bbf5c878
MR
654 object_property_add(obj, "fdt", "struct", prop_get_fdt,
655 NULL, NULL, NULL, NULL);
656}
657
658static void spapr_dr_connector_class_init(ObjectClass *k, void *data)
659{
660 DeviceClass *dk = DEVICE_CLASS(k);
661 sPAPRDRConnectorClass *drck = SPAPR_DR_CONNECTOR_CLASS(k);
662
663 dk->reset = reset;
664 dk->realize = realize;
665 dk->unrealize = unrealize;
666 drck->set_isolation_state = set_isolation_state;
667 drck->set_indicator_state = set_indicator_state;
668 drck->set_allocation_state = set_allocation_state;
bbf5c878 669 drck->get_name = get_name;
bbf5c878
MR
670 drck->entity_sense = entity_sense;
671 drck->attach = attach;
672 drck->detach = detach;
673 drck->release_pending = release_pending;
f40eb921 674 drck->set_signalled = set_signalled;
c401ae8c
MA
675 /*
676 * Reason: it crashes FIXME find and document the real reason
677 */
e90f2a8c 678 dk->user_creatable = false;
bbf5c878
MR
679}
680
2d335818
DG
681static void spapr_drc_cpu_class_init(ObjectClass *k, void *data)
682{
683 sPAPRDRConnectorClass *drck = SPAPR_DR_CONNECTOR_CLASS(k);
684
685 drck->typeshift = SPAPR_DR_CONNECTOR_TYPE_SHIFT_CPU;
1693ea16 686 drck->typename = "CPU";
2d335818
DG
687}
688
689static void spapr_drc_pci_class_init(ObjectClass *k, void *data)
690{
691 sPAPRDRConnectorClass *drck = SPAPR_DR_CONNECTOR_CLASS(k);
692
693 drck->typeshift = SPAPR_DR_CONNECTOR_TYPE_SHIFT_PCI;
1693ea16 694 drck->typename = "28";
2d335818
DG
695}
696
697static void spapr_drc_lmb_class_init(ObjectClass *k, void *data)
698{
699 sPAPRDRConnectorClass *drck = SPAPR_DR_CONNECTOR_CLASS(k);
700
701 drck->typeshift = SPAPR_DR_CONNECTOR_TYPE_SHIFT_LMB;
1693ea16 702 drck->typename = "MEM";
2d335818
DG
703}
704
bbf5c878
MR
705static const TypeInfo spapr_dr_connector_info = {
706 .name = TYPE_SPAPR_DR_CONNECTOR,
707 .parent = TYPE_DEVICE,
708 .instance_size = sizeof(sPAPRDRConnector),
709 .instance_init = spapr_dr_connector_instance_init,
710 .class_size = sizeof(sPAPRDRConnectorClass),
711 .class_init = spapr_dr_connector_class_init,
2d335818
DG
712 .abstract = true,
713};
714
715static const TypeInfo spapr_drc_physical_info = {
716 .name = TYPE_SPAPR_DRC_PHYSICAL,
717 .parent = TYPE_SPAPR_DR_CONNECTOR,
718 .instance_size = sizeof(sPAPRDRConnector),
719 .abstract = true,
720};
721
722static const TypeInfo spapr_drc_logical_info = {
723 .name = TYPE_SPAPR_DRC_LOGICAL,
724 .parent = TYPE_SPAPR_DR_CONNECTOR,
725 .instance_size = sizeof(sPAPRDRConnector),
726 .abstract = true,
727};
728
729static const TypeInfo spapr_drc_cpu_info = {
730 .name = TYPE_SPAPR_DRC_CPU,
731 .parent = TYPE_SPAPR_DRC_LOGICAL,
732 .instance_size = sizeof(sPAPRDRConnector),
733 .class_init = spapr_drc_cpu_class_init,
734};
735
736static const TypeInfo spapr_drc_pci_info = {
737 .name = TYPE_SPAPR_DRC_PCI,
738 .parent = TYPE_SPAPR_DRC_PHYSICAL,
739 .instance_size = sizeof(sPAPRDRConnector),
740 .class_init = spapr_drc_pci_class_init,
741};
742
743static const TypeInfo spapr_drc_lmb_info = {
744 .name = TYPE_SPAPR_DRC_LMB,
745 .parent = TYPE_SPAPR_DRC_LOGICAL,
746 .instance_size = sizeof(sPAPRDRConnector),
747 .class_init = spapr_drc_lmb_class_init,
bbf5c878
MR
748};
749
bbf5c878
MR
750/* helper functions for external users */
751
fbf55397 752sPAPRDRConnector *spapr_drc_by_index(uint32_t index)
bbf5c878
MR
753{
754 Object *obj;
755 char name[256];
756
757 snprintf(name, sizeof(name), "%s/%x", DRC_CONTAINER_PATH, index);
758 obj = object_resolve_path(name, NULL);
759
760 return !obj ? NULL : SPAPR_DR_CONNECTOR(obj);
761}
762
fbf55397 763sPAPRDRConnector *spapr_drc_by_id(const char *type, uint32_t id)
bbf5c878 764{
fbf55397
DG
765 sPAPRDRConnectorClass *drck
766 = SPAPR_DR_CONNECTOR_CLASS(object_class_by_name(type));
767
768 return spapr_drc_by_index(drck->typeshift << DRC_INDEX_TYPE_SHIFT
769 | (id & DRC_INDEX_ID_MASK));
bbf5c878 770}
e4b798bb 771
e4b798bb
MR
772/**
773 * spapr_drc_populate_dt
774 *
775 * @fdt: libfdt device tree
776 * @path: path in the DT to generate properties
777 * @owner: parent Object/DeviceState for which to generate DRC
778 * descriptions for
779 * @drc_type_mask: mask of sPAPRDRConnectorType values corresponding
780 * to the types of DRCs to generate entries for
781 *
782 * generate OF properties to describe DRC topology/indices to guests
783 *
784 * as documented in PAPR+ v2.1, 13.5.2
785 */
786int spapr_drc_populate_dt(void *fdt, int fdt_offset, Object *owner,
787 uint32_t drc_type_mask)
788{
789 Object *root_container;
790 ObjectProperty *prop;
7746abd8 791 ObjectPropertyIterator iter;
e4b798bb
MR
792 uint32_t drc_count = 0;
793 GArray *drc_indexes, *drc_power_domains;
794 GString *drc_names, *drc_types;
795 int ret;
796
797 /* the first entry of each properties is a 32-bit integer encoding
798 * the number of elements in the array. we won't know this until
799 * we complete the iteration through all the matching DRCs, but
800 * reserve the space now and set the offsets accordingly so we
801 * can fill them in later.
802 */
803 drc_indexes = g_array_new(false, true, sizeof(uint32_t));
804 drc_indexes = g_array_set_size(drc_indexes, 1);
805 drc_power_domains = g_array_new(false, true, sizeof(uint32_t));
806 drc_power_domains = g_array_set_size(drc_power_domains, 1);
807 drc_names = g_string_set_size(g_string_new(NULL), sizeof(uint32_t));
808 drc_types = g_string_set_size(g_string_new(NULL), sizeof(uint32_t));
809
810 /* aliases for all DRConnector objects will be rooted in QOM
811 * composition tree at DRC_CONTAINER_PATH
812 */
813 root_container = container_get(object_get_root(), DRC_CONTAINER_PATH);
814
7746abd8
DB
815 object_property_iter_init(&iter, root_container);
816 while ((prop = object_property_iter_next(&iter))) {
e4b798bb
MR
817 Object *obj;
818 sPAPRDRConnector *drc;
819 sPAPRDRConnectorClass *drck;
820 uint32_t drc_index, drc_power_domain;
821
822 if (!strstart(prop->type, "link<", NULL)) {
823 continue;
824 }
825
826 obj = object_property_get_link(root_container, prop->name, NULL);
827 drc = SPAPR_DR_CONNECTOR(obj);
828 drck = SPAPR_DR_CONNECTOR_GET_CLASS(drc);
829
830 if (owner && (drc->owner != owner)) {
831 continue;
832 }
833
2d335818 834 if ((spapr_drc_type(drc) & drc_type_mask) == 0) {
e4b798bb
MR
835 continue;
836 }
837
838 drc_count++;
839
840 /* ibm,drc-indexes */
0b55aa91 841 drc_index = cpu_to_be32(spapr_drc_index(drc));
e4b798bb
MR
842 g_array_append_val(drc_indexes, drc_index);
843
844 /* ibm,drc-power-domains */
845 drc_power_domain = cpu_to_be32(-1);
846 g_array_append_val(drc_power_domains, drc_power_domain);
847
848 /* ibm,drc-names */
849 drc_names = g_string_append(drc_names, drck->get_name(drc));
850 drc_names = g_string_insert_len(drc_names, -1, "\0", 1);
851
852 /* ibm,drc-types */
1693ea16 853 drc_types = g_string_append(drc_types, drck->typename);
e4b798bb
MR
854 drc_types = g_string_insert_len(drc_types, -1, "\0", 1);
855 }
856
857 /* now write the drc count into the space we reserved at the
858 * beginning of the arrays previously
859 */
860 *(uint32_t *)drc_indexes->data = cpu_to_be32(drc_count);
861 *(uint32_t *)drc_power_domains->data = cpu_to_be32(drc_count);
862 *(uint32_t *)drc_names->str = cpu_to_be32(drc_count);
863 *(uint32_t *)drc_types->str = cpu_to_be32(drc_count);
864
865 ret = fdt_setprop(fdt, fdt_offset, "ibm,drc-indexes",
866 drc_indexes->data,
867 drc_indexes->len * sizeof(uint32_t));
868 if (ret) {
ce9863b7 869 error_report("Couldn't create ibm,drc-indexes property");
e4b798bb
MR
870 goto out;
871 }
872
873 ret = fdt_setprop(fdt, fdt_offset, "ibm,drc-power-domains",
874 drc_power_domains->data,
875 drc_power_domains->len * sizeof(uint32_t));
876 if (ret) {
ce9863b7 877 error_report("Couldn't finalize ibm,drc-power-domains property");
e4b798bb
MR
878 goto out;
879 }
880
881 ret = fdt_setprop(fdt, fdt_offset, "ibm,drc-names",
882 drc_names->str, drc_names->len);
883 if (ret) {
ce9863b7 884 error_report("Couldn't finalize ibm,drc-names property");
e4b798bb
MR
885 goto out;
886 }
887
888 ret = fdt_setprop(fdt, fdt_offset, "ibm,drc-types",
889 drc_types->str, drc_types->len);
890 if (ret) {
ce9863b7 891 error_report("Couldn't finalize ibm,drc-types property");
e4b798bb
MR
892 goto out;
893 }
894
895out:
896 g_array_free(drc_indexes, true);
897 g_array_free(drc_power_domains, true);
898 g_string_free(drc_names, true);
899 g_string_free(drc_types, true);
900
901 return ret;
902}
b89b3d39
DG
903
904/*
905 * RTAS calls
906 */
907
908static bool sensor_type_is_dr(uint32_t sensor_type)
909{
910 switch (sensor_type) {
911 case RTAS_SENSOR_TYPE_ISOLATION_STATE:
912 case RTAS_SENSOR_TYPE_DR:
913 case RTAS_SENSOR_TYPE_ALLOCATION_STATE:
914 return true;
915 }
916
917 return false;
918}
919
920static void rtas_set_indicator(PowerPCCPU *cpu, sPAPRMachineState *spapr,
921 uint32_t token, uint32_t nargs,
922 target_ulong args, uint32_t nret,
923 target_ulong rets)
924{
925 uint32_t sensor_type;
926 uint32_t sensor_index;
927 uint32_t sensor_state;
928 uint32_t ret = RTAS_OUT_SUCCESS;
929 sPAPRDRConnector *drc;
930 sPAPRDRConnectorClass *drck;
931
932 if (nargs != 3 || nret != 1) {
933 ret = RTAS_OUT_PARAM_ERROR;
934 goto out;
935 }
936
937 sensor_type = rtas_ld(args, 0);
938 sensor_index = rtas_ld(args, 1);
939 sensor_state = rtas_ld(args, 2);
940
941 if (!sensor_type_is_dr(sensor_type)) {
942 goto out_unimplemented;
943 }
944
945 /* if this is a DR sensor we can assume sensor_index == drc_index */
fbf55397 946 drc = spapr_drc_by_index(sensor_index);
b89b3d39
DG
947 if (!drc) {
948 trace_spapr_rtas_set_indicator_invalid(sensor_index);
949 ret = RTAS_OUT_PARAM_ERROR;
950 goto out;
951 }
952 drck = SPAPR_DR_CONNECTOR_GET_CLASS(drc);
953
954 switch (sensor_type) {
955 case RTAS_SENSOR_TYPE_ISOLATION_STATE:
b89b3d39
DG
956 ret = drck->set_isolation_state(drc, sensor_state);
957 break;
958 case RTAS_SENSOR_TYPE_DR:
959 ret = drck->set_indicator_state(drc, sensor_state);
960 break;
961 case RTAS_SENSOR_TYPE_ALLOCATION_STATE:
962 ret = drck->set_allocation_state(drc, sensor_state);
963 break;
964 default:
965 goto out_unimplemented;
966 }
967
968out:
969 rtas_st(rets, 0, ret);
970 return;
971
972out_unimplemented:
973 /* currently only DR-related sensors are implemented */
974 trace_spapr_rtas_set_indicator_not_supported(sensor_index, sensor_type);
975 rtas_st(rets, 0, RTAS_OUT_NOT_SUPPORTED);
976}
977
978static void rtas_get_sensor_state(PowerPCCPU *cpu, sPAPRMachineState *spapr,
979 uint32_t token, uint32_t nargs,
980 target_ulong args, uint32_t nret,
981 target_ulong rets)
982{
983 uint32_t sensor_type;
984 uint32_t sensor_index;
985 uint32_t sensor_state = 0;
986 sPAPRDRConnector *drc;
987 sPAPRDRConnectorClass *drck;
988 uint32_t ret = RTAS_OUT_SUCCESS;
989
990 if (nargs != 2 || nret != 2) {
991 ret = RTAS_OUT_PARAM_ERROR;
992 goto out;
993 }
994
995 sensor_type = rtas_ld(args, 0);
996 sensor_index = rtas_ld(args, 1);
997
998 if (sensor_type != RTAS_SENSOR_TYPE_ENTITY_SENSE) {
999 /* currently only DR-related sensors are implemented */
1000 trace_spapr_rtas_get_sensor_state_not_supported(sensor_index,
1001 sensor_type);
1002 ret = RTAS_OUT_NOT_SUPPORTED;
1003 goto out;
1004 }
1005
fbf55397 1006 drc = spapr_drc_by_index(sensor_index);
b89b3d39
DG
1007 if (!drc) {
1008 trace_spapr_rtas_get_sensor_state_invalid(sensor_index);
1009 ret = RTAS_OUT_PARAM_ERROR;
1010 goto out;
1011 }
1012 drck = SPAPR_DR_CONNECTOR_GET_CLASS(drc);
1013 ret = drck->entity_sense(drc, &sensor_state);
1014
1015out:
1016 rtas_st(rets, 0, ret);
1017 rtas_st(rets, 1, sensor_state);
1018}
1019
1020/* configure-connector work area offsets, int32_t units for field
1021 * indexes, bytes for field offset/len values.
1022 *
1023 * as documented by PAPR+ v2.7, 13.5.3.5
1024 */
1025#define CC_IDX_NODE_NAME_OFFSET 2
1026#define CC_IDX_PROP_NAME_OFFSET 2
1027#define CC_IDX_PROP_LEN 3
1028#define CC_IDX_PROP_DATA_OFFSET 4
1029#define CC_VAL_DATA_OFFSET ((CC_IDX_PROP_DATA_OFFSET + 1) * 4)
1030#define CC_WA_LEN 4096
1031
1032static void configure_connector_st(target_ulong addr, target_ulong offset,
1033 const void *buf, size_t len)
1034{
1035 cpu_physical_memory_write(ppc64_phys_to_real(addr + offset),
1036 buf, MIN(len, CC_WA_LEN - offset));
1037}
1038
b89b3d39
DG
1039static void rtas_ibm_configure_connector(PowerPCCPU *cpu,
1040 sPAPRMachineState *spapr,
1041 uint32_t token, uint32_t nargs,
1042 target_ulong args, uint32_t nret,
1043 target_ulong rets)
1044{
1045 uint64_t wa_addr;
1046 uint64_t wa_offset;
1047 uint32_t drc_index;
1048 sPAPRDRConnector *drc;
b89b3d39
DG
1049 sPAPRConfigureConnectorState *ccs;
1050 sPAPRDRCCResponse resp = SPAPR_DR_CC_RESPONSE_CONTINUE;
1051 int rc;
b89b3d39
DG
1052
1053 if (nargs != 2 || nret != 1) {
1054 rtas_st(rets, 0, RTAS_OUT_PARAM_ERROR);
1055 return;
1056 }
1057
1058 wa_addr = ((uint64_t)rtas_ld(args, 1) << 32) | rtas_ld(args, 0);
1059
1060 drc_index = rtas_ld(wa_addr, 0);
fbf55397 1061 drc = spapr_drc_by_index(drc_index);
b89b3d39
DG
1062 if (!drc) {
1063 trace_spapr_rtas_ibm_configure_connector_invalid(drc_index);
1064 rc = RTAS_OUT_PARAM_ERROR;
1065 goto out;
1066 }
1067
88af6ea5 1068 if (!drc->fdt) {
b89b3d39
DG
1069 trace_spapr_rtas_ibm_configure_connector_missing_fdt(drc_index);
1070 rc = SPAPR_DR_CC_RESPONSE_NOT_CONFIGURABLE;
1071 goto out;
1072 }
1073
b8fdd530 1074 ccs = drc->ccs;
b89b3d39
DG
1075 if (!ccs) {
1076 ccs = g_new0(sPAPRConfigureConnectorState, 1);
88af6ea5 1077 ccs->fdt_offset = drc->fdt_start_offset;
b8fdd530 1078 drc->ccs = ccs;
b89b3d39
DG
1079 }
1080
1081 do {
1082 uint32_t tag;
1083 const char *name;
1084 const struct fdt_property *prop;
1085 int fdt_offset_next, prop_len;
1086
88af6ea5 1087 tag = fdt_next_tag(drc->fdt, ccs->fdt_offset, &fdt_offset_next);
b89b3d39
DG
1088
1089 switch (tag) {
1090 case FDT_BEGIN_NODE:
1091 ccs->fdt_depth++;
88af6ea5 1092 name = fdt_get_name(drc->fdt, ccs->fdt_offset, NULL);
b89b3d39
DG
1093
1094 /* provide the name of the next OF node */
1095 wa_offset = CC_VAL_DATA_OFFSET;
1096 rtas_st(wa_addr, CC_IDX_NODE_NAME_OFFSET, wa_offset);
1097 configure_connector_st(wa_addr, wa_offset, name, strlen(name) + 1);
1098 resp = SPAPR_DR_CC_RESPONSE_NEXT_CHILD;
1099 break;
1100 case FDT_END_NODE:
1101 ccs->fdt_depth--;
1102 if (ccs->fdt_depth == 0) {
4f65ce00 1103 sPAPRDRIsolationState state = drc->isolation_state;
0b55aa91 1104 uint32_t drc_index = spapr_drc_index(drc);
b89b3d39
DG
1105 /* done sending the device tree, don't need to track
1106 * the state anymore
1107 */
0b55aa91 1108 trace_spapr_drc_set_configured(drc_index);
4f65ce00
DG
1109 if (state == SPAPR_DR_ISOLATION_STATE_UNISOLATED) {
1110 drc->configured = true;
1111 } else {
1112 /* guest should be not configuring an isolated device */
0b55aa91 1113 trace_spapr_drc_set_configured_skipping(drc_index);
4f65ce00 1114 }
b8fdd530
DG
1115 g_free(ccs);
1116 drc->ccs = NULL;
b89b3d39
DG
1117 ccs = NULL;
1118 resp = SPAPR_DR_CC_RESPONSE_SUCCESS;
1119 } else {
1120 resp = SPAPR_DR_CC_RESPONSE_PREV_PARENT;
1121 }
1122 break;
1123 case FDT_PROP:
88af6ea5 1124 prop = fdt_get_property_by_offset(drc->fdt, ccs->fdt_offset,
b89b3d39 1125 &prop_len);
88af6ea5 1126 name = fdt_string(drc->fdt, fdt32_to_cpu(prop->nameoff));
b89b3d39
DG
1127
1128 /* provide the name of the next OF property */
1129 wa_offset = CC_VAL_DATA_OFFSET;
1130 rtas_st(wa_addr, CC_IDX_PROP_NAME_OFFSET, wa_offset);
1131 configure_connector_st(wa_addr, wa_offset, name, strlen(name) + 1);
1132
1133 /* provide the length and value of the OF property. data gets
1134 * placed immediately after NULL terminator of the OF property's
1135 * name string
1136 */
1137 wa_offset += strlen(name) + 1,
1138 rtas_st(wa_addr, CC_IDX_PROP_LEN, prop_len);
1139 rtas_st(wa_addr, CC_IDX_PROP_DATA_OFFSET, wa_offset);
1140 configure_connector_st(wa_addr, wa_offset, prop->data, prop_len);
1141 resp = SPAPR_DR_CC_RESPONSE_NEXT_PROPERTY;
1142 break;
1143 case FDT_END:
1144 resp = SPAPR_DR_CC_RESPONSE_ERROR;
1145 default:
1146 /* keep seeking for an actionable tag */
1147 break;
1148 }
1149 if (ccs) {
1150 ccs->fdt_offset = fdt_offset_next;
1151 }
1152 } while (resp == SPAPR_DR_CC_RESPONSE_CONTINUE);
1153
1154 rc = resp;
1155out:
1156 rtas_st(rets, 0, rc);
1157}
1158
1159static void spapr_drc_register_types(void)
1160{
1161 type_register_static(&spapr_dr_connector_info);
2d335818
DG
1162 type_register_static(&spapr_drc_physical_info);
1163 type_register_static(&spapr_drc_logical_info);
1164 type_register_static(&spapr_drc_cpu_info);
1165 type_register_static(&spapr_drc_pci_info);
1166 type_register_static(&spapr_drc_lmb_info);
b89b3d39
DG
1167
1168 spapr_rtas_register(RTAS_SET_INDICATOR, "set-indicator",
1169 rtas_set_indicator);
1170 spapr_rtas_register(RTAS_GET_SENSOR_STATE, "get-sensor-state",
1171 rtas_get_sensor_state);
1172 spapr_rtas_register(RTAS_IBM_CONFIGURE_CONNECTOR, "ibm,configure-connector",
1173 rtas_ibm_configure_connector);
1174}
1175type_init(spapr_drc_register_types)