]> git.proxmox.com Git - mirror_qemu.git/blame - include/hw/ppc/spapr_drc.h
spapr/drc: Drop spapr_drc_attach() fdt argument
[mirror_qemu.git] / include / hw / ppc / spapr_drc.h
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 */
2a6a4076
MA
12
13#ifndef HW_SPAPR_DRC_H
14#define HW_SPAPR_DRC_H
bbf5c878 15
a9c94277 16#include <libfdt.h>
9af23989 17#include "qapi/qapi-types-run-state.h"
bbf5c878 18#include "qom/object.h"
94fd9cba 19#include "sysemu/sysemu.h"
bbf5c878 20#include "hw/qdev.h"
d9c95c71 21#include "qapi/error.h"
bbf5c878
MR
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
2d335818
DG
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)
67fea71b 38#define SPAPR_DRC_PHYSICAL(obj) OBJECT_CHECK(sPAPRDRCPhysical, (obj), \
2d335818
DG
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
bbf5c878
MR
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 */
85typedef 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
93typedef 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 */
109typedef 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 */
123typedef 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/*
cd74d27e 131 * DR-indicator (LED/visual indicator)
bbf5c878
MR
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 */
142typedef enum {
cd74d27e
DG
143 SPAPR_DR_INDICATOR_INACTIVE = 0,
144 SPAPR_DR_INDICATOR_ACTIVE = 1,
145 SPAPR_DR_INDICATOR_IDENTIFY = 2,
146 SPAPR_DR_INDICATOR_ACTION = 3,
bbf5c878
MR
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 */
159typedef 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
167typedef enum {
e6fc9568
BR
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,
bbf5c878
MR
176} sPAPRDRCCResponse;
177
9d4c0f4f
DG
178typedef 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
bbf5c878
MR
196typedef struct sPAPRDRConnector {
197 /*< private >*/
198 DeviceState parent;
199
bbf5c878
MR
200 uint32_t id;
201 Object *owner;
bbf5c878 202
9d4c0f4f 203 uint32_t state;
bbf5c878 204
4445b1d2
DG
205 /* RTAS ibm,configure-connector state */
206 /* (only valid in UNISOLATE state) */
207 int ccs_offset;
208 int ccs_depth;
bbf5c878 209
bbf5c878
MR
210 /* device pointer, via link property */
211 DeviceState *dev;
f1c52354 212 bool unplug_requested;
4445b1d2
DG
213 void *fdt;
214 int fdt_start_offset;
bbf5c878
MR
215} sPAPRDRConnector;
216
d9c95c71
GK
217struct sPAPRMachineState;
218
bbf5c878
MR
219typedef struct sPAPRDRConnectorClass {
220 /*< private >*/
221 DeviceClass parent;
9d4c0f4f
DG
222 sPAPRDRCState empty_state;
223 sPAPRDRCState ready_state;
bbf5c878
MR
224
225 /*< public >*/
2d335818 226 sPAPRDRConnectorTypeShift typeshift;
1693ea16 227 const char *typename; /* used in device tree, PAPR 13.5.2.6 & C.6.1 */
79808336 228 const char *drc_name_prefix; /* used other places in device tree */
bbf5c878 229
f224d35b 230 sPAPRDREntitySense (*dr_entity_sense)(sPAPRDRConnector *drc);
0dfabd39
DG
231 uint32_t (*isolate)(sPAPRDRConnector *drc);
232 uint32_t (*unisolate)(sPAPRDRConnector *drc);
6b762f29 233 void (*release)(DeviceState *dev);
d9c95c71
GK
234
235 int (*dt_populate)(sPAPRDRConnector *drc, struct sPAPRMachineState *spapr,
236 void *fdt, int *fdt_start_offset, Error **errp);
bbf5c878
MR
237} sPAPRDRConnectorClass;
238
67fea71b
DG
239typedef struct sPAPRDRCPhysical {
240 /*< private >*/
241 sPAPRDRConnector parent;
242
243 /* DR-indicator */
244 uint32_t dr_indicator;
245} sPAPRDRCPhysical;
246
94fd9cba
LV
247static inline bool spapr_drc_hotplugged(DeviceState *dev)
248{
249 return dev->hotplugged && !runstate_check(RUN_STATE_INMIGRATE);
250}
251
252void spapr_drc_reset(sPAPRDRConnector *drc);
253
0b55aa91
DG
254uint32_t spapr_drc_index(sPAPRDRConnector *drc);
255sPAPRDRConnectorType spapr_drc_type(sPAPRDRConnector *drc);
256
2d335818 257sPAPRDRConnector *spapr_dr_connector_new(Object *owner, const char *type,
bbf5c878 258 uint32_t id);
fbf55397
DG
259sPAPRDRConnector *spapr_drc_by_index(uint32_t index);
260sPAPRDRConnector *spapr_drc_by_id(const char *type, uint32_t id);
e4b798bb
MR
261int spapr_drc_populate_dt(void *fdt, int fdt_offset, Object *owner,
262 uint32_t drc_type_mask);
bbf5c878 263
09d876ce 264void spapr_drc_attach(sPAPRDRConnector *drc, DeviceState *d, Error **errp);
a8dc47fd 265void spapr_drc_detach(sPAPRDRConnector *drc);
10f12e64 266bool spapr_drc_needed(void *opaque);
0be4e886 267
f1c52354
DG
268static inline bool spapr_drc_unplug_requested(sPAPRDRConnector *drc)
269{
270 return drc->unplug_requested;
271}
272
2a6a4076 273#endif /* HW_SPAPR_DRC_H */