]> git.proxmox.com Git - mirror_qemu.git/blob - include/hw/ppc/spapr_drc.h
spapr/drc: Drop spapr_drc_attach() fdt argument
[mirror_qemu.git] / include / hw / ppc / spapr_drc.h
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
13 #ifndef HW_SPAPR_DRC_H
14 #define HW_SPAPR_DRC_H
15
16 #include <libfdt.h>
17 #include "qapi/qapi-types-run-state.h"
18 #include "qom/object.h"
19 #include "sysemu/sysemu.h"
20 #include "hw/qdev.h"
21 #include "qapi/error.h"
22
23 #define TYPE_SPAPR_DR_CONNECTOR "spapr-dr-connector"
24 #define SPAPR_DR_CONNECTOR_GET_CLASS(obj) \
25 OBJECT_GET_CLASS(sPAPRDRConnectorClass, obj, TYPE_SPAPR_DR_CONNECTOR)
26 #define SPAPR_DR_CONNECTOR_CLASS(klass) \
27 OBJECT_CLASS_CHECK(sPAPRDRConnectorClass, klass, \
28 TYPE_SPAPR_DR_CONNECTOR)
29 #define SPAPR_DR_CONNECTOR(obj) OBJECT_CHECK(sPAPRDRConnector, (obj), \
30 TYPE_SPAPR_DR_CONNECTOR)
31
32 #define TYPE_SPAPR_DRC_PHYSICAL "spapr-drc-physical"
33 #define SPAPR_DRC_PHYSICAL_GET_CLASS(obj) \
34 OBJECT_GET_CLASS(sPAPRDRConnectorClass, obj, TYPE_SPAPR_DRC_PHYSICAL)
35 #define SPAPR_DRC_PHYSICAL_CLASS(klass) \
36 OBJECT_CLASS_CHECK(sPAPRDRConnectorClass, klass, \
37 TYPE_SPAPR_DRC_PHYSICAL)
38 #define SPAPR_DRC_PHYSICAL(obj) OBJECT_CHECK(sPAPRDRCPhysical, (obj), \
39 TYPE_SPAPR_DRC_PHYSICAL)
40
41 #define TYPE_SPAPR_DRC_LOGICAL "spapr-drc-logical"
42 #define SPAPR_DRC_LOGICAL_GET_CLASS(obj) \
43 OBJECT_GET_CLASS(sPAPRDRConnectorClass, obj, TYPE_SPAPR_DRC_LOGICAL)
44 #define SPAPR_DRC_LOGICAL_CLASS(klass) \
45 OBJECT_CLASS_CHECK(sPAPRDRConnectorClass, klass, \
46 TYPE_SPAPR_DRC_LOGICAL)
47 #define SPAPR_DRC_LOGICAL(obj) OBJECT_CHECK(sPAPRDRConnector, (obj), \
48 TYPE_SPAPR_DRC_LOGICAL)
49
50 #define TYPE_SPAPR_DRC_CPU "spapr-drc-cpu"
51 #define SPAPR_DRC_CPU_GET_CLASS(obj) \
52 OBJECT_GET_CLASS(sPAPRDRConnectorClass, obj, TYPE_SPAPR_DRC_CPU)
53 #define SPAPR_DRC_CPU_CLASS(klass) \
54 OBJECT_CLASS_CHECK(sPAPRDRConnectorClass, klass, TYPE_SPAPR_DRC_CPU)
55 #define SPAPR_DRC_CPU(obj) OBJECT_CHECK(sPAPRDRConnector, (obj), \
56 TYPE_SPAPR_DRC_CPU)
57
58 #define TYPE_SPAPR_DRC_PCI "spapr-drc-pci"
59 #define SPAPR_DRC_PCI_GET_CLASS(obj) \
60 OBJECT_GET_CLASS(sPAPRDRConnectorClass, obj, TYPE_SPAPR_DRC_PCI)
61 #define SPAPR_DRC_PCI_CLASS(klass) \
62 OBJECT_CLASS_CHECK(sPAPRDRConnectorClass, klass, TYPE_SPAPR_DRC_PCI)
63 #define SPAPR_DRC_PCI(obj) OBJECT_CHECK(sPAPRDRConnector, (obj), \
64 TYPE_SPAPR_DRC_PCI)
65
66 #define TYPE_SPAPR_DRC_LMB "spapr-drc-lmb"
67 #define SPAPR_DRC_LMB_GET_CLASS(obj) \
68 OBJECT_GET_CLASS(sPAPRDRConnectorClass, obj, TYPE_SPAPR_DRC_LMB)
69 #define SPAPR_DRC_LMB_CLASS(klass) \
70 OBJECT_CLASS_CHECK(sPAPRDRConnectorClass, klass, TYPE_SPAPR_DRC_LMB)
71 #define SPAPR_DRC_LMB(obj) OBJECT_CHECK(sPAPRDRConnector, (obj), \
72 TYPE_SPAPR_DRC_LMB)
73
74 /*
75 * Various hotplug types managed by sPAPRDRConnector
76 *
77 * these are somewhat arbitrary, but to make things easier
78 * when generating DRC indexes later we've aligned the bit
79 * positions with the values used to assign DRC indexes on
80 * pSeries. we use those values as bit shifts to allow for
81 * the OR'ing of these values in various QEMU routines, but
82 * for values exposed to the guest (via DRC indexes for
83 * instance) we will use the shift amounts.
84 */
85 typedef enum {
86 SPAPR_DR_CONNECTOR_TYPE_SHIFT_CPU = 1,
87 SPAPR_DR_CONNECTOR_TYPE_SHIFT_PHB = 2,
88 SPAPR_DR_CONNECTOR_TYPE_SHIFT_VIO = 3,
89 SPAPR_DR_CONNECTOR_TYPE_SHIFT_PCI = 4,
90 SPAPR_DR_CONNECTOR_TYPE_SHIFT_LMB = 8,
91 } sPAPRDRConnectorTypeShift;
92
93 typedef enum {
94 SPAPR_DR_CONNECTOR_TYPE_ANY = ~0,
95 SPAPR_DR_CONNECTOR_TYPE_CPU = 1 << SPAPR_DR_CONNECTOR_TYPE_SHIFT_CPU,
96 SPAPR_DR_CONNECTOR_TYPE_PHB = 1 << SPAPR_DR_CONNECTOR_TYPE_SHIFT_PHB,
97 SPAPR_DR_CONNECTOR_TYPE_VIO = 1 << SPAPR_DR_CONNECTOR_TYPE_SHIFT_VIO,
98 SPAPR_DR_CONNECTOR_TYPE_PCI = 1 << SPAPR_DR_CONNECTOR_TYPE_SHIFT_PCI,
99 SPAPR_DR_CONNECTOR_TYPE_LMB = 1 << SPAPR_DR_CONNECTOR_TYPE_SHIFT_LMB,
100 } sPAPRDRConnectorType;
101
102 /*
103 * set via set-indicator RTAS calls
104 * as documented by PAPR+ 2.7 13.5.3.4, Table 177
105 *
106 * isolated: put device under firmware control
107 * unisolated: claim OS control of device (may or may not be in use)
108 */
109 typedef enum {
110 SPAPR_DR_ISOLATION_STATE_ISOLATED = 0,
111 SPAPR_DR_ISOLATION_STATE_UNISOLATED = 1
112 } sPAPRDRIsolationState;
113
114 /*
115 * set via set-indicator RTAS calls
116 * as documented by PAPR+ 2.7 13.5.3.4, Table 177
117 *
118 * unusable: mark device as unavailable to OS
119 * usable: mark device as available to OS
120 * exchange: (currently unused)
121 * recover: (currently unused)
122 */
123 typedef enum {
124 SPAPR_DR_ALLOCATION_STATE_UNUSABLE = 0,
125 SPAPR_DR_ALLOCATION_STATE_USABLE = 1,
126 SPAPR_DR_ALLOCATION_STATE_EXCHANGE = 2,
127 SPAPR_DR_ALLOCATION_STATE_RECOVER = 3
128 } sPAPRDRAllocationState;
129
130 /*
131 * DR-indicator (LED/visual indicator)
132 *
133 * set via set-indicator RTAS calls
134 * as documented by PAPR+ 2.7 13.5.3.4, Table 177,
135 * and PAPR+ 2.7 13.5.4.1, Table 180
136 *
137 * inactive: hotpluggable entity inactive and safely removable
138 * active: hotpluggable entity in use and not safely removable
139 * identify: (currently unused)
140 * action: (currently unused)
141 */
142 typedef enum {
143 SPAPR_DR_INDICATOR_INACTIVE = 0,
144 SPAPR_DR_INDICATOR_ACTIVE = 1,
145 SPAPR_DR_INDICATOR_IDENTIFY = 2,
146 SPAPR_DR_INDICATOR_ACTION = 3,
147 } sPAPRDRIndicatorState;
148
149 /*
150 * returned via get-sensor-state RTAS calls
151 * as documented by PAPR+ 2.7 13.5.3.3, Table 175:
152 *
153 * empty: connector slot empty (e.g. empty hotpluggable PCI slot)
154 * present: connector slot populated and device available to OS
155 * unusable: device not currently available to OS
156 * exchange: (currently unused)
157 * recover: (currently unused)
158 */
159 typedef enum {
160 SPAPR_DR_ENTITY_SENSE_EMPTY = 0,
161 SPAPR_DR_ENTITY_SENSE_PRESENT = 1,
162 SPAPR_DR_ENTITY_SENSE_UNUSABLE = 2,
163 SPAPR_DR_ENTITY_SENSE_EXCHANGE = 3,
164 SPAPR_DR_ENTITY_SENSE_RECOVER = 4,
165 } sPAPRDREntitySense;
166
167 typedef enum {
168 SPAPR_DR_CC_RESPONSE_NEXT_SIB = 1, /* currently unused */
169 SPAPR_DR_CC_RESPONSE_NEXT_CHILD = 2,
170 SPAPR_DR_CC_RESPONSE_NEXT_PROPERTY = 3,
171 SPAPR_DR_CC_RESPONSE_PREV_PARENT = 4,
172 SPAPR_DR_CC_RESPONSE_SUCCESS = 0,
173 SPAPR_DR_CC_RESPONSE_ERROR = -1,
174 SPAPR_DR_CC_RESPONSE_CONTINUE = -2,
175 SPAPR_DR_CC_RESPONSE_NOT_CONFIGURABLE = -9003,
176 } sPAPRDRCCResponse;
177
178 typedef enum {
179 /*
180 * Values come from Fig. 12 in LoPAPR section 13.4
181 *
182 * These are exposed in the migration stream, so don't change
183 * them.
184 */
185 SPAPR_DRC_STATE_INVALID = 0,
186 SPAPR_DRC_STATE_LOGICAL_UNUSABLE = 1,
187 SPAPR_DRC_STATE_LOGICAL_AVAILABLE = 2,
188 SPAPR_DRC_STATE_LOGICAL_UNISOLATE = 3,
189 SPAPR_DRC_STATE_LOGICAL_CONFIGURED = 4,
190 SPAPR_DRC_STATE_PHYSICAL_AVAILABLE = 5,
191 SPAPR_DRC_STATE_PHYSICAL_POWERON = 6,
192 SPAPR_DRC_STATE_PHYSICAL_UNISOLATE = 7,
193 SPAPR_DRC_STATE_PHYSICAL_CONFIGURED = 8,
194 } sPAPRDRCState;
195
196 typedef struct sPAPRDRConnector {
197 /*< private >*/
198 DeviceState parent;
199
200 uint32_t id;
201 Object *owner;
202
203 uint32_t state;
204
205 /* RTAS ibm,configure-connector state */
206 /* (only valid in UNISOLATE state) */
207 int ccs_offset;
208 int ccs_depth;
209
210 /* device pointer, via link property */
211 DeviceState *dev;
212 bool unplug_requested;
213 void *fdt;
214 int fdt_start_offset;
215 } sPAPRDRConnector;
216
217 struct sPAPRMachineState;
218
219 typedef struct sPAPRDRConnectorClass {
220 /*< private >*/
221 DeviceClass parent;
222 sPAPRDRCState empty_state;
223 sPAPRDRCState ready_state;
224
225 /*< public >*/
226 sPAPRDRConnectorTypeShift typeshift;
227 const char *typename; /* used in device tree, PAPR 13.5.2.6 & C.6.1 */
228 const char *drc_name_prefix; /* used other places in device tree */
229
230 sPAPRDREntitySense (*dr_entity_sense)(sPAPRDRConnector *drc);
231 uint32_t (*isolate)(sPAPRDRConnector *drc);
232 uint32_t (*unisolate)(sPAPRDRConnector *drc);
233 void (*release)(DeviceState *dev);
234
235 int (*dt_populate)(sPAPRDRConnector *drc, struct sPAPRMachineState *spapr,
236 void *fdt, int *fdt_start_offset, Error **errp);
237 } sPAPRDRConnectorClass;
238
239 typedef struct sPAPRDRCPhysical {
240 /*< private >*/
241 sPAPRDRConnector parent;
242
243 /* DR-indicator */
244 uint32_t dr_indicator;
245 } sPAPRDRCPhysical;
246
247 static inline bool spapr_drc_hotplugged(DeviceState *dev)
248 {
249 return dev->hotplugged && !runstate_check(RUN_STATE_INMIGRATE);
250 }
251
252 void spapr_drc_reset(sPAPRDRConnector *drc);
253
254 uint32_t spapr_drc_index(sPAPRDRConnector *drc);
255 sPAPRDRConnectorType spapr_drc_type(sPAPRDRConnector *drc);
256
257 sPAPRDRConnector *spapr_dr_connector_new(Object *owner, const char *type,
258 uint32_t id);
259 sPAPRDRConnector *spapr_drc_by_index(uint32_t index);
260 sPAPRDRConnector *spapr_drc_by_id(const char *type, uint32_t id);
261 int spapr_drc_populate_dt(void *fdt, int fdt_offset, Object *owner,
262 uint32_t drc_type_mask);
263
264 void spapr_drc_attach(sPAPRDRConnector *drc, DeviceState *d, Error **errp);
265 void spapr_drc_detach(sPAPRDRConnector *drc);
266 bool spapr_drc_needed(void *opaque);
267
268 static inline bool spapr_drc_unplug_requested(sPAPRDRConnector *drc)
269 {
270 return drc->unplug_requested;
271 }
272
273 #endif /* HW_SPAPR_DRC_H */