2 * QEMU SPAPR Dynamic Reconfiguration Connector Implementation
4 * Copyright IBM Corp. 2014
7 * Michael Roth <mdroth@linux.vnet.ibm.com>
9 * This work is licensed under the terms of the GNU GPL, version 2 or later.
10 * See the COPYING file in the top-level directory.
13 #ifndef HW_SPAPR_DRC_H
14 #define HW_SPAPR_DRC_H
17 #include "qom/object.h"
18 #include "sysemu/sysemu.h"
19 #include "hw/qdev-core.h"
20 #include "qapi/error.h"
22 #define TYPE_SPAPR_DR_CONNECTOR "spapr-dr-connector"
23 #define SPAPR_DR_CONNECTOR_GET_CLASS(obj) \
24 OBJECT_GET_CLASS(SpaprDrcClass, obj, TYPE_SPAPR_DR_CONNECTOR)
25 #define SPAPR_DR_CONNECTOR_CLASS(klass) \
26 OBJECT_CLASS_CHECK(SpaprDrcClass, klass, \
27 TYPE_SPAPR_DR_CONNECTOR)
28 #define SPAPR_DR_CONNECTOR(obj) OBJECT_CHECK(SpaprDrc, (obj), \
29 TYPE_SPAPR_DR_CONNECTOR)
31 #define TYPE_SPAPR_DRC_PHYSICAL "spapr-drc-physical"
32 #define SPAPR_DRC_PHYSICAL_GET_CLASS(obj) \
33 OBJECT_GET_CLASS(SpaprDrcClass, obj, TYPE_SPAPR_DRC_PHYSICAL)
34 #define SPAPR_DRC_PHYSICAL_CLASS(klass) \
35 OBJECT_CLASS_CHECK(SpaprDrcClass, klass, \
36 TYPE_SPAPR_DRC_PHYSICAL)
37 #define SPAPR_DRC_PHYSICAL(obj) OBJECT_CHECK(SpaprDrcPhysical, (obj), \
38 TYPE_SPAPR_DRC_PHYSICAL)
40 #define TYPE_SPAPR_DRC_LOGICAL "spapr-drc-logical"
41 #define SPAPR_DRC_LOGICAL_GET_CLASS(obj) \
42 OBJECT_GET_CLASS(SpaprDrcClass, obj, TYPE_SPAPR_DRC_LOGICAL)
43 #define SPAPR_DRC_LOGICAL_CLASS(klass) \
44 OBJECT_CLASS_CHECK(SpaprDrcClass, klass, \
45 TYPE_SPAPR_DRC_LOGICAL)
46 #define SPAPR_DRC_LOGICAL(obj) OBJECT_CHECK(SpaprDrc, (obj), \
47 TYPE_SPAPR_DRC_LOGICAL)
49 #define TYPE_SPAPR_DRC_CPU "spapr-drc-cpu"
50 #define SPAPR_DRC_CPU_GET_CLASS(obj) \
51 OBJECT_GET_CLASS(SpaprDrcClass, obj, TYPE_SPAPR_DRC_CPU)
52 #define SPAPR_DRC_CPU_CLASS(klass) \
53 OBJECT_CLASS_CHECK(SpaprDrcClass, klass, TYPE_SPAPR_DRC_CPU)
54 #define SPAPR_DRC_CPU(obj) OBJECT_CHECK(SpaprDrc, (obj), \
57 #define TYPE_SPAPR_DRC_PCI "spapr-drc-pci"
58 #define SPAPR_DRC_PCI_GET_CLASS(obj) \
59 OBJECT_GET_CLASS(SpaprDrcClass, obj, TYPE_SPAPR_DRC_PCI)
60 #define SPAPR_DRC_PCI_CLASS(klass) \
61 OBJECT_CLASS_CHECK(SpaprDrcClass, klass, TYPE_SPAPR_DRC_PCI)
62 #define SPAPR_DRC_PCI(obj) OBJECT_CHECK(SpaprDrc, (obj), \
65 #define TYPE_SPAPR_DRC_LMB "spapr-drc-lmb"
66 #define SPAPR_DRC_LMB_GET_CLASS(obj) \
67 OBJECT_GET_CLASS(SpaprDrcClass, obj, TYPE_SPAPR_DRC_LMB)
68 #define SPAPR_DRC_LMB_CLASS(klass) \
69 OBJECT_CLASS_CHECK(SpaprDrcClass, klass, TYPE_SPAPR_DRC_LMB)
70 #define SPAPR_DRC_LMB(obj) OBJECT_CHECK(SpaprDrc, (obj), \
73 #define TYPE_SPAPR_DRC_PHB "spapr-drc-phb"
74 #define SPAPR_DRC_PHB_GET_CLASS(obj) \
75 OBJECT_GET_CLASS(SpaprDrcClass, obj, TYPE_SPAPR_DRC_PHB)
76 #define SPAPR_DRC_PHB_CLASS(klass) \
77 OBJECT_CLASS_CHECK(SpaprDrcClass, klass, TYPE_SPAPR_DRC_PHB)
78 #define SPAPR_DRC_PHB(obj) OBJECT_CHECK(SpaprDrc, (obj), \
82 * Various hotplug types managed by SpaprDrc
84 * these are somewhat arbitrary, but to make things easier
85 * when generating DRC indexes later we've aligned the bit
86 * positions with the values used to assign DRC indexes on
87 * pSeries. we use those values as bit shifts to allow for
88 * the OR'ing of these values in various QEMU routines, but
89 * for values exposed to the guest (via DRC indexes for
90 * instance) we will use the shift amounts.
93 SPAPR_DR_CONNECTOR_TYPE_SHIFT_CPU
= 1,
94 SPAPR_DR_CONNECTOR_TYPE_SHIFT_PHB
= 2,
95 SPAPR_DR_CONNECTOR_TYPE_SHIFT_VIO
= 3,
96 SPAPR_DR_CONNECTOR_TYPE_SHIFT_PCI
= 4,
97 SPAPR_DR_CONNECTOR_TYPE_SHIFT_LMB
= 8,
101 SPAPR_DR_CONNECTOR_TYPE_ANY
= ~0,
102 SPAPR_DR_CONNECTOR_TYPE_CPU
= 1 << SPAPR_DR_CONNECTOR_TYPE_SHIFT_CPU
,
103 SPAPR_DR_CONNECTOR_TYPE_PHB
= 1 << SPAPR_DR_CONNECTOR_TYPE_SHIFT_PHB
,
104 SPAPR_DR_CONNECTOR_TYPE_VIO
= 1 << SPAPR_DR_CONNECTOR_TYPE_SHIFT_VIO
,
105 SPAPR_DR_CONNECTOR_TYPE_PCI
= 1 << SPAPR_DR_CONNECTOR_TYPE_SHIFT_PCI
,
106 SPAPR_DR_CONNECTOR_TYPE_LMB
= 1 << SPAPR_DR_CONNECTOR_TYPE_SHIFT_LMB
,
110 * set via set-indicator RTAS calls
111 * as documented by PAPR+ 2.7 13.5.3.4, Table 177
113 * isolated: put device under firmware control
114 * unisolated: claim OS control of device (may or may not be in use)
117 SPAPR_DR_ISOLATION_STATE_ISOLATED
= 0,
118 SPAPR_DR_ISOLATION_STATE_UNISOLATED
= 1
119 } SpaprDRIsolationState
;
122 * set via set-indicator RTAS calls
123 * as documented by PAPR+ 2.7 13.5.3.4, Table 177
125 * unusable: mark device as unavailable to OS
126 * usable: mark device as available to OS
127 * exchange: (currently unused)
128 * recover: (currently unused)
131 SPAPR_DR_ALLOCATION_STATE_UNUSABLE
= 0,
132 SPAPR_DR_ALLOCATION_STATE_USABLE
= 1,
133 SPAPR_DR_ALLOCATION_STATE_EXCHANGE
= 2,
134 SPAPR_DR_ALLOCATION_STATE_RECOVER
= 3
135 } SpaprDRAllocationState
;
138 * DR-indicator (LED/visual indicator)
140 * set via set-indicator RTAS calls
141 * as documented by PAPR+ 2.7 13.5.3.4, Table 177,
142 * and PAPR+ 2.7 13.5.4.1, Table 180
144 * inactive: hotpluggable entity inactive and safely removable
145 * active: hotpluggable entity in use and not safely removable
146 * identify: (currently unused)
147 * action: (currently unused)
150 SPAPR_DR_INDICATOR_INACTIVE
= 0,
151 SPAPR_DR_INDICATOR_ACTIVE
= 1,
152 SPAPR_DR_INDICATOR_IDENTIFY
= 2,
153 SPAPR_DR_INDICATOR_ACTION
= 3,
154 } SpaprDRIndicatorState
;
157 * returned via get-sensor-state RTAS calls
158 * as documented by PAPR+ 2.7 13.5.3.3, Table 175:
160 * empty: connector slot empty (e.g. empty hotpluggable PCI slot)
161 * present: connector slot populated and device available to OS
162 * unusable: device not currently available to OS
163 * exchange: (currently unused)
164 * recover: (currently unused)
167 SPAPR_DR_ENTITY_SENSE_EMPTY
= 0,
168 SPAPR_DR_ENTITY_SENSE_PRESENT
= 1,
169 SPAPR_DR_ENTITY_SENSE_UNUSABLE
= 2,
170 SPAPR_DR_ENTITY_SENSE_EXCHANGE
= 3,
171 SPAPR_DR_ENTITY_SENSE_RECOVER
= 4,
172 } SpaprDREntitySense
;
175 SPAPR_DR_CC_RESPONSE_NEXT_SIB
= 1, /* currently unused */
176 SPAPR_DR_CC_RESPONSE_NEXT_CHILD
= 2,
177 SPAPR_DR_CC_RESPONSE_NEXT_PROPERTY
= 3,
178 SPAPR_DR_CC_RESPONSE_PREV_PARENT
= 4,
179 SPAPR_DR_CC_RESPONSE_SUCCESS
= 0,
180 SPAPR_DR_CC_RESPONSE_ERROR
= -1,
181 SPAPR_DR_CC_RESPONSE_CONTINUE
= -2,
182 SPAPR_DR_CC_RESPONSE_NOT_CONFIGURABLE
= -9003,
187 * Values come from Fig. 12 in LoPAPR section 13.4
189 * These are exposed in the migration stream, so don't change
192 SPAPR_DRC_STATE_INVALID
= 0,
193 SPAPR_DRC_STATE_LOGICAL_UNUSABLE
= 1,
194 SPAPR_DRC_STATE_LOGICAL_AVAILABLE
= 2,
195 SPAPR_DRC_STATE_LOGICAL_UNISOLATE
= 3,
196 SPAPR_DRC_STATE_LOGICAL_CONFIGURED
= 4,
197 SPAPR_DRC_STATE_PHYSICAL_AVAILABLE
= 5,
198 SPAPR_DRC_STATE_PHYSICAL_POWERON
= 6,
199 SPAPR_DRC_STATE_PHYSICAL_UNISOLATE
= 7,
200 SPAPR_DRC_STATE_PHYSICAL_CONFIGURED
= 8,
203 typedef struct SpaprDrc
{
212 /* RTAS ibm,configure-connector state */
213 /* (only valid in UNISOLATE state) */
217 /* device pointer, via link property */
219 bool unplug_requested
;
221 int fdt_start_offset
;
224 struct SpaprMachineState
;
226 typedef struct SpaprDrcClass
{
229 SpaprDrcState empty_state
;
230 SpaprDrcState ready_state
;
233 SpaprDrcTypeShift typeshift
;
234 const char *typename
; /* used in device tree, PAPR 13.5.2.6 & C.6.1 */
235 const char *drc_name_prefix
; /* used other places in device tree */
237 SpaprDREntitySense (*dr_entity_sense
)(SpaprDrc
*drc
);
238 uint32_t (*isolate
)(SpaprDrc
*drc
);
239 uint32_t (*unisolate
)(SpaprDrc
*drc
);
240 void (*release
)(DeviceState
*dev
);
242 int (*dt_populate
)(SpaprDrc
*drc
, struct SpaprMachineState
*spapr
,
243 void *fdt
, int *fdt_start_offset
, Error
**errp
);
246 typedef struct SpaprDrcPhysical
{
251 uint32_t dr_indicator
;
254 static inline bool spapr_drc_hotplugged(DeviceState
*dev
)
256 return dev
->hotplugged
&& !runstate_check(RUN_STATE_INMIGRATE
);
259 void spapr_drc_reset(SpaprDrc
*drc
);
261 uint32_t spapr_drc_index(SpaprDrc
*drc
);
262 SpaprDrcType
spapr_drc_type(SpaprDrc
*drc
);
264 SpaprDrc
*spapr_dr_connector_new(Object
*owner
, const char *type
,
266 SpaprDrc
*spapr_drc_by_index(uint32_t index
);
267 SpaprDrc
*spapr_drc_by_id(const char *type
, uint32_t id
);
268 int spapr_dt_drc(void *fdt
, int offset
, Object
*owner
, uint32_t drc_type_mask
);
270 void spapr_drc_attach(SpaprDrc
*drc
, DeviceState
*d
, Error
**errp
);
271 void spapr_drc_detach(SpaprDrc
*drc
);
272 bool spapr_drc_needed(void *opaque
);
274 static inline bool spapr_drc_unplug_requested(SpaprDrc
*drc
)
276 return drc
->unplug_requested
;
279 #endif /* HW_SPAPR_DRC_H */