]> git.ipfire.org Git - thirdparty/qemu.git/blame - include/hw/ppc/spapr_drc.h
Include less of the generated modular QAPI headers
[thirdparty/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"
bbf5c878
MR
21
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)
30
2d335818
DG
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)
67fea71b 37#define SPAPR_DRC_PHYSICAL(obj) OBJECT_CHECK(sPAPRDRCPhysical, (obj), \
2d335818
DG
38 TYPE_SPAPR_DRC_PHYSICAL)
39
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)
48
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), \
55 TYPE_SPAPR_DRC_CPU)
56
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), \
63 TYPE_SPAPR_DRC_PCI)
64
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), \
71 TYPE_SPAPR_DRC_LMB)
72
bbf5c878
MR
73/*
74 * Various hotplug types managed by sPAPRDRConnector
75 *
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.
83 */
84typedef enum {
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;
91
92typedef enum {
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;
100
101/*
102 * set via set-indicator RTAS calls
103 * as documented by PAPR+ 2.7 13.5.3.4, Table 177
104 *
105 * isolated: put device under firmware control
106 * unisolated: claim OS control of device (may or may not be in use)
107 */
108typedef enum {
109 SPAPR_DR_ISOLATION_STATE_ISOLATED = 0,
110 SPAPR_DR_ISOLATION_STATE_UNISOLATED = 1
111} sPAPRDRIsolationState;
112
113/*
114 * set via set-indicator RTAS calls
115 * as documented by PAPR+ 2.7 13.5.3.4, Table 177
116 *
117 * unusable: mark device as unavailable to OS
118 * usable: mark device as available to OS
119 * exchange: (currently unused)
120 * recover: (currently unused)
121 */
122typedef enum {
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;
128
129/*
cd74d27e 130 * DR-indicator (LED/visual indicator)
bbf5c878
MR
131 *
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
135 *
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)
140 */
141typedef enum {
cd74d27e
DG
142 SPAPR_DR_INDICATOR_INACTIVE = 0,
143 SPAPR_DR_INDICATOR_ACTIVE = 1,
144 SPAPR_DR_INDICATOR_IDENTIFY = 2,
145 SPAPR_DR_INDICATOR_ACTION = 3,
bbf5c878
MR
146} sPAPRDRIndicatorState;
147
148/*
149 * returned via get-sensor-state RTAS calls
150 * as documented by PAPR+ 2.7 13.5.3.3, Table 175:
151 *
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)
157 */
158typedef enum {
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;
165
166typedef enum {
e6fc9568
BR
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,
bbf5c878
MR
175} sPAPRDRCCResponse;
176
9d4c0f4f
DG
177typedef enum {
178 /*
179 * Values come from Fig. 12 in LoPAPR section 13.4
180 *
181 * These are exposed in the migration stream, so don't change
182 * them.
183 */
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,
193} sPAPRDRCState;
194
bbf5c878
MR
195typedef struct sPAPRDRConnector {
196 /*< private >*/
197 DeviceState parent;
198
bbf5c878
MR
199 uint32_t id;
200 Object *owner;
bbf5c878 201
9d4c0f4f 202 uint32_t state;
bbf5c878 203
4445b1d2
DG
204 /* RTAS ibm,configure-connector state */
205 /* (only valid in UNISOLATE state) */
206 int ccs_offset;
207 int ccs_depth;
bbf5c878 208
bbf5c878
MR
209 /* device pointer, via link property */
210 DeviceState *dev;
f1c52354 211 bool unplug_requested;
4445b1d2
DG
212 void *fdt;
213 int fdt_start_offset;
bbf5c878
MR
214} sPAPRDRConnector;
215
216typedef struct sPAPRDRConnectorClass {
217 /*< private >*/
218 DeviceClass parent;
9d4c0f4f
DG
219 sPAPRDRCState empty_state;
220 sPAPRDRCState ready_state;
bbf5c878
MR
221
222 /*< public >*/
2d335818 223 sPAPRDRConnectorTypeShift typeshift;
1693ea16 224 const char *typename; /* used in device tree, PAPR 13.5.2.6 & C.6.1 */
79808336 225 const char *drc_name_prefix; /* used other places in device tree */
bbf5c878 226
f224d35b 227 sPAPRDREntitySense (*dr_entity_sense)(sPAPRDRConnector *drc);
0dfabd39
DG
228 uint32_t (*isolate)(sPAPRDRConnector *drc);
229 uint32_t (*unisolate)(sPAPRDRConnector *drc);
6b762f29 230 void (*release)(DeviceState *dev);
bbf5c878
MR
231} sPAPRDRConnectorClass;
232
67fea71b
DG
233typedef struct sPAPRDRCPhysical {
234 /*< private >*/
235 sPAPRDRConnector parent;
236
237 /* DR-indicator */
238 uint32_t dr_indicator;
239} sPAPRDRCPhysical;
240
94fd9cba
LV
241static inline bool spapr_drc_hotplugged(DeviceState *dev)
242{
243 return dev->hotplugged && !runstate_check(RUN_STATE_INMIGRATE);
244}
245
246void spapr_drc_reset(sPAPRDRConnector *drc);
247
0b55aa91
DG
248uint32_t spapr_drc_index(sPAPRDRConnector *drc);
249sPAPRDRConnectorType spapr_drc_type(sPAPRDRConnector *drc);
250
2d335818 251sPAPRDRConnector *spapr_dr_connector_new(Object *owner, const char *type,
bbf5c878 252 uint32_t id);
fbf55397
DG
253sPAPRDRConnector *spapr_drc_by_index(uint32_t index);
254sPAPRDRConnector *spapr_drc_by_id(const char *type, uint32_t id);
e4b798bb
MR
255int spapr_drc_populate_dt(void *fdt, int fdt_offset, Object *owner,
256 uint32_t drc_type_mask);
bbf5c878 257
0be4e886 258void spapr_drc_attach(sPAPRDRConnector *drc, DeviceState *d, void *fdt,
5c1da812 259 int fdt_start_offset, Error **errp);
a8dc47fd 260void spapr_drc_detach(sPAPRDRConnector *drc);
10f12e64 261bool spapr_drc_needed(void *opaque);
0be4e886 262
f1c52354
DG
263static inline bool spapr_drc_unplug_requested(sPAPRDRConnector *drc)
264{
265 return drc->unplug_requested;
266}
267
2a6a4076 268#endif /* HW_SPAPR_DRC_H */