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"
21 #define TYPE_SPAPR_DR_CONNECTOR "spapr-dr-connector"
22 #define SPAPR_DR_CONNECTOR_GET_CLASS(obj) \
23 OBJECT_GET_CLASS(sPAPRDRConnectorClass, obj, TYPE_SPAPR_DR_CONNECTOR)
24 #define SPAPR_DR_CONNECTOR_CLASS(klass) \
25 OBJECT_CLASS_CHECK(sPAPRDRConnectorClass, klass, \
26 TYPE_SPAPR_DR_CONNECTOR)
27 #define SPAPR_DR_CONNECTOR(obj) OBJECT_CHECK(sPAPRDRConnector, (obj), \
28 TYPE_SPAPR_DR_CONNECTOR)
30 #define TYPE_SPAPR_DRC_PHYSICAL "spapr-drc-physical"
31 #define SPAPR_DRC_PHYSICAL_GET_CLASS(obj) \
32 OBJECT_GET_CLASS(sPAPRDRConnectorClass, obj, TYPE_SPAPR_DRC_PHYSICAL)
33 #define SPAPR_DRC_PHYSICAL_CLASS(klass) \
34 OBJECT_CLASS_CHECK(sPAPRDRConnectorClass, klass, \
35 TYPE_SPAPR_DRC_PHYSICAL)
36 #define SPAPR_DRC_PHYSICAL(obj) OBJECT_CHECK(sPAPRDRConnector, (obj), \
37 TYPE_SPAPR_DRC_PHYSICAL)
39 #define TYPE_SPAPR_DRC_LOGICAL "spapr-drc-logical"
40 #define SPAPR_DRC_LOGICAL_GET_CLASS(obj) \
41 OBJECT_GET_CLASS(sPAPRDRConnectorClass, obj, TYPE_SPAPR_DRC_LOGICAL)
42 #define SPAPR_DRC_LOGICAL_CLASS(klass) \
43 OBJECT_CLASS_CHECK(sPAPRDRConnectorClass, klass, \
44 TYPE_SPAPR_DRC_LOGICAL)
45 #define SPAPR_DRC_LOGICAL(obj) OBJECT_CHECK(sPAPRDRConnector, (obj), \
46 TYPE_SPAPR_DRC_LOGICAL)
48 #define TYPE_SPAPR_DRC_CPU "spapr-drc-cpu"
49 #define SPAPR_DRC_CPU_GET_CLASS(obj) \
50 OBJECT_GET_CLASS(sPAPRDRConnectorClass, obj, TYPE_SPAPR_DRC_CPU)
51 #define SPAPR_DRC_CPU_CLASS(klass) \
52 OBJECT_CLASS_CHECK(sPAPRDRConnectorClass, klass, TYPE_SPAPR_DRC_CPU)
53 #define SPAPR_DRC_CPU(obj) OBJECT_CHECK(sPAPRDRConnector, (obj), \
56 #define TYPE_SPAPR_DRC_PCI "spapr-drc-pci"
57 #define SPAPR_DRC_PCI_GET_CLASS(obj) \
58 OBJECT_GET_CLASS(sPAPRDRConnectorClass, obj, TYPE_SPAPR_DRC_PCI)
59 #define SPAPR_DRC_PCI_CLASS(klass) \
60 OBJECT_CLASS_CHECK(sPAPRDRConnectorClass, klass, TYPE_SPAPR_DRC_PCI)
61 #define SPAPR_DRC_PCI(obj) OBJECT_CHECK(sPAPRDRConnector, (obj), \
64 #define TYPE_SPAPR_DRC_LMB "spapr-drc-lmb"
65 #define SPAPR_DRC_LMB_GET_CLASS(obj) \
66 OBJECT_GET_CLASS(sPAPRDRConnectorClass, obj, TYPE_SPAPR_DRC_LMB)
67 #define SPAPR_DRC_LMB_CLASS(klass) \
68 OBJECT_CLASS_CHECK(sPAPRDRConnectorClass, klass, TYPE_SPAPR_DRC_LMB)
69 #define SPAPR_DRC_LMB(obj) OBJECT_CHECK(sPAPRDRConnector, (obj), \
73 * Various hotplug types managed by sPAPRDRConnector
75 * these are somewhat arbitrary, but to make things easier
76 * when generating DRC indexes later we've aligned the bit
77 * positions with the values used to assign DRC indexes on
78 * pSeries. we use those values as bit shifts to allow for
79 * the OR'ing of these values in various QEMU routines, but
80 * for values exposed to the guest (via DRC indexes for
81 * instance) we will use the shift amounts.
84 SPAPR_DR_CONNECTOR_TYPE_SHIFT_CPU
= 1,
85 SPAPR_DR_CONNECTOR_TYPE_SHIFT_PHB
= 2,
86 SPAPR_DR_CONNECTOR_TYPE_SHIFT_VIO
= 3,
87 SPAPR_DR_CONNECTOR_TYPE_SHIFT_PCI
= 4,
88 SPAPR_DR_CONNECTOR_TYPE_SHIFT_LMB
= 8,
89 } sPAPRDRConnectorTypeShift
;
92 SPAPR_DR_CONNECTOR_TYPE_ANY
= ~0,
93 SPAPR_DR_CONNECTOR_TYPE_CPU
= 1 << SPAPR_DR_CONNECTOR_TYPE_SHIFT_CPU
,
94 SPAPR_DR_CONNECTOR_TYPE_PHB
= 1 << SPAPR_DR_CONNECTOR_TYPE_SHIFT_PHB
,
95 SPAPR_DR_CONNECTOR_TYPE_VIO
= 1 << SPAPR_DR_CONNECTOR_TYPE_SHIFT_VIO
,
96 SPAPR_DR_CONNECTOR_TYPE_PCI
= 1 << SPAPR_DR_CONNECTOR_TYPE_SHIFT_PCI
,
97 SPAPR_DR_CONNECTOR_TYPE_LMB
= 1 << SPAPR_DR_CONNECTOR_TYPE_SHIFT_LMB
,
98 } sPAPRDRConnectorType
;
101 * set via set-indicator RTAS calls
102 * as documented by PAPR+ 2.7 13.5.3.4, Table 177
104 * isolated: put device under firmware control
105 * unisolated: claim OS control of device (may or may not be in use)
108 SPAPR_DR_ISOLATION_STATE_ISOLATED
= 0,
109 SPAPR_DR_ISOLATION_STATE_UNISOLATED
= 1
110 } sPAPRDRIsolationState
;
113 * set via set-indicator RTAS calls
114 * as documented by PAPR+ 2.7 13.5.3.4, Table 177
116 * unusable: mark device as unavailable to OS
117 * usable: mark device as available to OS
118 * exchange: (currently unused)
119 * recover: (currently unused)
122 SPAPR_DR_ALLOCATION_STATE_UNUSABLE
= 0,
123 SPAPR_DR_ALLOCATION_STATE_USABLE
= 1,
124 SPAPR_DR_ALLOCATION_STATE_EXCHANGE
= 2,
125 SPAPR_DR_ALLOCATION_STATE_RECOVER
= 3
126 } sPAPRDRAllocationState
;
129 * DR-indicator (LED/visual indicator)
131 * set via set-indicator RTAS calls
132 * as documented by PAPR+ 2.7 13.5.3.4, Table 177,
133 * and PAPR+ 2.7 13.5.4.1, Table 180
135 * inactive: hotpluggable entity inactive and safely removable
136 * active: hotpluggable entity in use and not safely removable
137 * identify: (currently unused)
138 * action: (currently unused)
141 SPAPR_DR_INDICATOR_INACTIVE
= 0,
142 SPAPR_DR_INDICATOR_ACTIVE
= 1,
143 SPAPR_DR_INDICATOR_IDENTIFY
= 2,
144 SPAPR_DR_INDICATOR_ACTION
= 3,
145 } sPAPRDRIndicatorState
;
148 * returned via get-sensor-state RTAS calls
149 * as documented by PAPR+ 2.7 13.5.3.3, Table 175:
151 * empty: connector slot empty (e.g. empty hotpluggable PCI slot)
152 * present: connector slot populated and device available to OS
153 * unusable: device not currently available to OS
154 * exchange: (currently unused)
155 * recover: (currently unused)
158 SPAPR_DR_ENTITY_SENSE_EMPTY
= 0,
159 SPAPR_DR_ENTITY_SENSE_PRESENT
= 1,
160 SPAPR_DR_ENTITY_SENSE_UNUSABLE
= 2,
161 SPAPR_DR_ENTITY_SENSE_EXCHANGE
= 3,
162 SPAPR_DR_ENTITY_SENSE_RECOVER
= 4,
163 } sPAPRDREntitySense
;
166 SPAPR_DR_CC_RESPONSE_NEXT_SIB
= 1, /* currently unused */
167 SPAPR_DR_CC_RESPONSE_NEXT_CHILD
= 2,
168 SPAPR_DR_CC_RESPONSE_NEXT_PROPERTY
= 3,
169 SPAPR_DR_CC_RESPONSE_PREV_PARENT
= 4,
170 SPAPR_DR_CC_RESPONSE_SUCCESS
= 0,
171 SPAPR_DR_CC_RESPONSE_ERROR
= -1,
172 SPAPR_DR_CC_RESPONSE_CONTINUE
= -2,
173 SPAPR_DR_CC_RESPONSE_NOT_CONFIGURABLE
= -9003,
176 /* rtas-configure-connector state */
177 typedef struct sPAPRConfigureConnectorState
{
180 } sPAPRConfigureConnectorState
;
182 typedef struct sPAPRDRConnector
{
190 uint32_t dr_indicator
;
192 /* sensor/indicator states */
193 uint32_t isolation_state
;
194 uint32_t allocation_state
;
196 /* configure-connector state */
198 int fdt_start_offset
;
200 sPAPRConfigureConnectorState
*ccs
;
202 bool awaiting_release
;
204 /* device pointer, via link property */
208 typedef struct sPAPRDRConnectorClass
{
213 sPAPRDRConnectorTypeShift typeshift
;
214 const char *typename
; /* used in device tree, PAPR 13.5.2.6 & C.6.1 */
215 const char *drc_name_prefix
; /* used other places in device tree */
217 sPAPRDREntitySense (*dr_entity_sense
)(sPAPRDRConnector
*drc
);
218 uint32_t (*isolate
)(sPAPRDRConnector
*drc
);
219 uint32_t (*unisolate
)(sPAPRDRConnector
*drc
);
220 void (*release
)(DeviceState
*dev
);
222 /* QEMU interfaces for managing hotplug operations */
223 bool (*release_pending
)(sPAPRDRConnector
*drc
);
224 } sPAPRDRConnectorClass
;
226 static inline bool spapr_drc_hotplugged(DeviceState
*dev
)
228 return dev
->hotplugged
&& !runstate_check(RUN_STATE_INMIGRATE
);
231 void spapr_drc_reset(sPAPRDRConnector
*drc
);
233 uint32_t spapr_drc_index(sPAPRDRConnector
*drc
);
234 sPAPRDRConnectorType
spapr_drc_type(sPAPRDRConnector
*drc
);
236 sPAPRDRConnector
*spapr_dr_connector_new(Object
*owner
, const char *type
,
238 sPAPRDRConnector
*spapr_drc_by_index(uint32_t index
);
239 sPAPRDRConnector
*spapr_drc_by_id(const char *type
, uint32_t id
);
240 int spapr_drc_populate_dt(void *fdt
, int fdt_offset
, Object
*owner
,
241 uint32_t drc_type_mask
);
243 void spapr_drc_attach(sPAPRDRConnector
*drc
, DeviceState
*d
, void *fdt
,
244 int fdt_start_offset
, Error
**errp
);
245 void spapr_drc_detach(sPAPRDRConnector
*drc
);
247 #endif /* HW_SPAPR_DRC_H */