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 "qapi/qapi-types-run-state.h"
18 #include "qom/object.h"
19 #include "sysemu/sysemu.h"
22 #define TYPE_SPAPR_DR_CONNECTOR "spapr-dr-connector"
23 #define SPAPR_DR_CONNECTOR_GET_CLASS(obj) \
24 OBJECT_GET_CLASS(sPAPRDRConnectorClass, obj, TYPE_SPAPR_DR_CONNECTOR)
25 #define SPAPR_DR_CONNECTOR_CLASS(klass) \
26 OBJECT_CLASS_CHECK(sPAPRDRConnectorClass, klass, \
27 TYPE_SPAPR_DR_CONNECTOR)
28 #define SPAPR_DR_CONNECTOR(obj) OBJECT_CHECK(sPAPRDRConnector, (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(sPAPRDRConnectorClass, obj, TYPE_SPAPR_DRC_PHYSICAL)
34 #define SPAPR_DRC_PHYSICAL_CLASS(klass) \
35 OBJECT_CLASS_CHECK(sPAPRDRConnectorClass, 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(sPAPRDRConnectorClass, obj, TYPE_SPAPR_DRC_LOGICAL)
43 #define SPAPR_DRC_LOGICAL_CLASS(klass) \
44 OBJECT_CLASS_CHECK(sPAPRDRConnectorClass, klass, \
45 TYPE_SPAPR_DRC_LOGICAL)
46 #define SPAPR_DRC_LOGICAL(obj) OBJECT_CHECK(sPAPRDRConnector, (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(sPAPRDRConnectorClass, obj, TYPE_SPAPR_DRC_CPU)
52 #define SPAPR_DRC_CPU_CLASS(klass) \
53 OBJECT_CLASS_CHECK(sPAPRDRConnectorClass, klass, TYPE_SPAPR_DRC_CPU)
54 #define SPAPR_DRC_CPU(obj) OBJECT_CHECK(sPAPRDRConnector, (obj), \
57 #define TYPE_SPAPR_DRC_PCI "spapr-drc-pci"
58 #define SPAPR_DRC_PCI_GET_CLASS(obj) \
59 OBJECT_GET_CLASS(sPAPRDRConnectorClass, obj, TYPE_SPAPR_DRC_PCI)
60 #define SPAPR_DRC_PCI_CLASS(klass) \
61 OBJECT_CLASS_CHECK(sPAPRDRConnectorClass, klass, TYPE_SPAPR_DRC_PCI)
62 #define SPAPR_DRC_PCI(obj) OBJECT_CHECK(sPAPRDRConnector, (obj), \
65 #define TYPE_SPAPR_DRC_LMB "spapr-drc-lmb"
66 #define SPAPR_DRC_LMB_GET_CLASS(obj) \
67 OBJECT_GET_CLASS(sPAPRDRConnectorClass, obj, TYPE_SPAPR_DRC_LMB)
68 #define SPAPR_DRC_LMB_CLASS(klass) \
69 OBJECT_CLASS_CHECK(sPAPRDRConnectorClass, klass, TYPE_SPAPR_DRC_LMB)
70 #define SPAPR_DRC_LMB(obj) OBJECT_CHECK(sPAPRDRConnector, (obj), \
74 * Various hotplug types managed by sPAPRDRConnector
76 * these are somewhat arbitrary, but to make things easier
77 * when generating DRC indexes later we've aligned the bit
78 * positions with the values used to assign DRC indexes on
79 * pSeries. we use those values as bit shifts to allow for
80 * the OR'ing of these values in various QEMU routines, but
81 * for values exposed to the guest (via DRC indexes for
82 * instance) we will use the shift amounts.
85 SPAPR_DR_CONNECTOR_TYPE_SHIFT_CPU
= 1,
86 SPAPR_DR_CONNECTOR_TYPE_SHIFT_PHB
= 2,
87 SPAPR_DR_CONNECTOR_TYPE_SHIFT_VIO
= 3,
88 SPAPR_DR_CONNECTOR_TYPE_SHIFT_PCI
= 4,
89 SPAPR_DR_CONNECTOR_TYPE_SHIFT_LMB
= 8,
90 } sPAPRDRConnectorTypeShift
;
93 SPAPR_DR_CONNECTOR_TYPE_ANY
= ~0,
94 SPAPR_DR_CONNECTOR_TYPE_CPU
= 1 << SPAPR_DR_CONNECTOR_TYPE_SHIFT_CPU
,
95 SPAPR_DR_CONNECTOR_TYPE_PHB
= 1 << SPAPR_DR_CONNECTOR_TYPE_SHIFT_PHB
,
96 SPAPR_DR_CONNECTOR_TYPE_VIO
= 1 << SPAPR_DR_CONNECTOR_TYPE_SHIFT_VIO
,
97 SPAPR_DR_CONNECTOR_TYPE_PCI
= 1 << SPAPR_DR_CONNECTOR_TYPE_SHIFT_PCI
,
98 SPAPR_DR_CONNECTOR_TYPE_LMB
= 1 << SPAPR_DR_CONNECTOR_TYPE_SHIFT_LMB
,
99 } sPAPRDRConnectorType
;
102 * set via set-indicator RTAS calls
103 * as documented by PAPR+ 2.7 13.5.3.4, Table 177
105 * isolated: put device under firmware control
106 * unisolated: claim OS control of device (may or may not be in use)
109 SPAPR_DR_ISOLATION_STATE_ISOLATED
= 0,
110 SPAPR_DR_ISOLATION_STATE_UNISOLATED
= 1
111 } sPAPRDRIsolationState
;
114 * set via set-indicator RTAS calls
115 * as documented by PAPR+ 2.7 13.5.3.4, Table 177
117 * unusable: mark device as unavailable to OS
118 * usable: mark device as available to OS
119 * exchange: (currently unused)
120 * recover: (currently unused)
123 SPAPR_DR_ALLOCATION_STATE_UNUSABLE
= 0,
124 SPAPR_DR_ALLOCATION_STATE_USABLE
= 1,
125 SPAPR_DR_ALLOCATION_STATE_EXCHANGE
= 2,
126 SPAPR_DR_ALLOCATION_STATE_RECOVER
= 3
127 } sPAPRDRAllocationState
;
130 * DR-indicator (LED/visual indicator)
132 * set via set-indicator RTAS calls
133 * as documented by PAPR+ 2.7 13.5.3.4, Table 177,
134 * and PAPR+ 2.7 13.5.4.1, Table 180
136 * inactive: hotpluggable entity inactive and safely removable
137 * active: hotpluggable entity in use and not safely removable
138 * identify: (currently unused)
139 * action: (currently unused)
142 SPAPR_DR_INDICATOR_INACTIVE
= 0,
143 SPAPR_DR_INDICATOR_ACTIVE
= 1,
144 SPAPR_DR_INDICATOR_IDENTIFY
= 2,
145 SPAPR_DR_INDICATOR_ACTION
= 3,
146 } sPAPRDRIndicatorState
;
149 * returned via get-sensor-state RTAS calls
150 * as documented by PAPR+ 2.7 13.5.3.3, Table 175:
152 * empty: connector slot empty (e.g. empty hotpluggable PCI slot)
153 * present: connector slot populated and device available to OS
154 * unusable: device not currently available to OS
155 * exchange: (currently unused)
156 * recover: (currently unused)
159 SPAPR_DR_ENTITY_SENSE_EMPTY
= 0,
160 SPAPR_DR_ENTITY_SENSE_PRESENT
= 1,
161 SPAPR_DR_ENTITY_SENSE_UNUSABLE
= 2,
162 SPAPR_DR_ENTITY_SENSE_EXCHANGE
= 3,
163 SPAPR_DR_ENTITY_SENSE_RECOVER
= 4,
164 } sPAPRDREntitySense
;
167 SPAPR_DR_CC_RESPONSE_NEXT_SIB
= 1, /* currently unused */
168 SPAPR_DR_CC_RESPONSE_NEXT_CHILD
= 2,
169 SPAPR_DR_CC_RESPONSE_NEXT_PROPERTY
= 3,
170 SPAPR_DR_CC_RESPONSE_PREV_PARENT
= 4,
171 SPAPR_DR_CC_RESPONSE_SUCCESS
= 0,
172 SPAPR_DR_CC_RESPONSE_ERROR
= -1,
173 SPAPR_DR_CC_RESPONSE_CONTINUE
= -2,
174 SPAPR_DR_CC_RESPONSE_NOT_CONFIGURABLE
= -9003,
179 * Values come from Fig. 12 in LoPAPR section 13.4
181 * These are exposed in the migration stream, so don't change
184 SPAPR_DRC_STATE_INVALID
= 0,
185 SPAPR_DRC_STATE_LOGICAL_UNUSABLE
= 1,
186 SPAPR_DRC_STATE_LOGICAL_AVAILABLE
= 2,
187 SPAPR_DRC_STATE_LOGICAL_UNISOLATE
= 3,
188 SPAPR_DRC_STATE_LOGICAL_CONFIGURED
= 4,
189 SPAPR_DRC_STATE_PHYSICAL_AVAILABLE
= 5,
190 SPAPR_DRC_STATE_PHYSICAL_POWERON
= 6,
191 SPAPR_DRC_STATE_PHYSICAL_UNISOLATE
= 7,
192 SPAPR_DRC_STATE_PHYSICAL_CONFIGURED
= 8,
195 typedef struct sPAPRDRConnector
{
204 /* RTAS ibm,configure-connector state */
205 /* (only valid in UNISOLATE state) */
209 /* device pointer, via link property */
211 bool unplug_requested
;
213 int fdt_start_offset
;
216 typedef struct sPAPRDRConnectorClass
{
219 sPAPRDRCState empty_state
;
220 sPAPRDRCState ready_state
;
223 sPAPRDRConnectorTypeShift typeshift
;
224 const char *typename
; /* used in device tree, PAPR 13.5.2.6 & C.6.1 */
225 const char *drc_name_prefix
; /* used other places in device tree */
227 sPAPRDREntitySense (*dr_entity_sense
)(sPAPRDRConnector
*drc
);
228 uint32_t (*isolate
)(sPAPRDRConnector
*drc
);
229 uint32_t (*unisolate
)(sPAPRDRConnector
*drc
);
230 void (*release
)(DeviceState
*dev
);
231 } sPAPRDRConnectorClass
;
233 typedef struct sPAPRDRCPhysical
{
235 sPAPRDRConnector parent
;
238 uint32_t dr_indicator
;
241 static inline bool spapr_drc_hotplugged(DeviceState
*dev
)
243 return dev
->hotplugged
&& !runstate_check(RUN_STATE_INMIGRATE
);
246 void spapr_drc_reset(sPAPRDRConnector
*drc
);
248 uint32_t spapr_drc_index(sPAPRDRConnector
*drc
);
249 sPAPRDRConnectorType
spapr_drc_type(sPAPRDRConnector
*drc
);
251 sPAPRDRConnector
*spapr_dr_connector_new(Object
*owner
, const char *type
,
253 sPAPRDRConnector
*spapr_drc_by_index(uint32_t index
);
254 sPAPRDRConnector
*spapr_drc_by_id(const char *type
, uint32_t id
);
255 int spapr_drc_populate_dt(void *fdt
, int fdt_offset
, Object
*owner
,
256 uint32_t drc_type_mask
);
258 void spapr_drc_attach(sPAPRDRConnector
*drc
, DeviceState
*d
, void *fdt
,
259 int fdt_start_offset
, Error
**errp
);
260 void spapr_drc_detach(sPAPRDRConnector
*drc
);
261 bool spapr_drc_needed(void *opaque
);
263 static inline bool spapr_drc_unplug_requested(sPAPRDRConnector
*drc
)
265 return drc
->unplug_requested
;
268 #endif /* HW_SPAPR_DRC_H */