1
2
3
4
5
6
7
8
9
10
11
12
13#ifndef HW_SPAPR_DRC_H
14#define HW_SPAPR_DRC_H
15
16#include <libfdt.h>
17#include "qom/object.h"
18#include "sysemu/runstate.h"
19#include "hw/qdev-core.h"
20#include "qapi/error.h"
21
22#define TYPE_SPAPR_DR_CONNECTOR "spapr-dr-connector"
23#define SPAPR_DR_CONNECTOR_GET_CLASS(obj) \
24 OBJECT_GET_CLASS(SpaprDrcClass, obj, TYPE_SPAPR_DR_CONNECTOR)
25#define SPAPR_DR_CONNECTOR_CLASS(klass) \
26 OBJECT_CLASS_CHECK(SpaprDrcClass, klass, \
27 TYPE_SPAPR_DR_CONNECTOR)
28#define SPAPR_DR_CONNECTOR(obj) OBJECT_CHECK(SpaprDrc, (obj), \
29 TYPE_SPAPR_DR_CONNECTOR)
30
31#define TYPE_SPAPR_DRC_PHYSICAL "spapr-drc-physical"
32#define SPAPR_DRC_PHYSICAL(obj) OBJECT_CHECK(SpaprDrcPhysical, (obj), \
33 TYPE_SPAPR_DRC_PHYSICAL)
34
35#define TYPE_SPAPR_DRC_LOGICAL "spapr-drc-logical"
36
37#define TYPE_SPAPR_DRC_CPU "spapr-drc-cpu"
38
39#define TYPE_SPAPR_DRC_PCI "spapr-drc-pci"
40
41#define TYPE_SPAPR_DRC_LMB "spapr-drc-lmb"
42
43#define TYPE_SPAPR_DRC_PHB "spapr-drc-phb"
44
45#define TYPE_SPAPR_DRC_PMEM "spapr-drc-pmem"
46
47
48
49
50
51
52
53
54
55
56
57
58typedef enum {
59 SPAPR_DR_CONNECTOR_TYPE_SHIFT_CPU = 1,
60 SPAPR_DR_CONNECTOR_TYPE_SHIFT_PHB = 2,
61 SPAPR_DR_CONNECTOR_TYPE_SHIFT_VIO = 3,
62 SPAPR_DR_CONNECTOR_TYPE_SHIFT_PCI = 4,
63 SPAPR_DR_CONNECTOR_TYPE_SHIFT_LMB = 8,
64 SPAPR_DR_CONNECTOR_TYPE_SHIFT_PMEM = 9,
65} SpaprDrcTypeShift;
66
67typedef enum {
68 SPAPR_DR_CONNECTOR_TYPE_ANY = ~0,
69 SPAPR_DR_CONNECTOR_TYPE_CPU = 1 << SPAPR_DR_CONNECTOR_TYPE_SHIFT_CPU,
70 SPAPR_DR_CONNECTOR_TYPE_PHB = 1 << SPAPR_DR_CONNECTOR_TYPE_SHIFT_PHB,
71 SPAPR_DR_CONNECTOR_TYPE_VIO = 1 << SPAPR_DR_CONNECTOR_TYPE_SHIFT_VIO,
72 SPAPR_DR_CONNECTOR_TYPE_PCI = 1 << SPAPR_DR_CONNECTOR_TYPE_SHIFT_PCI,
73 SPAPR_DR_CONNECTOR_TYPE_LMB = 1 << SPAPR_DR_CONNECTOR_TYPE_SHIFT_LMB,
74 SPAPR_DR_CONNECTOR_TYPE_PMEM = 1 << SPAPR_DR_CONNECTOR_TYPE_SHIFT_PMEM,
75} SpaprDrcType;
76
77
78
79
80
81
82
83
84typedef enum {
85 SPAPR_DR_ISOLATION_STATE_ISOLATED = 0,
86 SPAPR_DR_ISOLATION_STATE_UNISOLATED = 1
87} SpaprDRIsolationState;
88
89
90
91
92
93
94
95
96
97
98typedef enum {
99 SPAPR_DR_ALLOCATION_STATE_UNUSABLE = 0,
100 SPAPR_DR_ALLOCATION_STATE_USABLE = 1,
101 SPAPR_DR_ALLOCATION_STATE_EXCHANGE = 2,
102 SPAPR_DR_ALLOCATION_STATE_RECOVER = 3
103} SpaprDRAllocationState;
104
105
106
107
108
109
110
111
112
113
114
115
116
117typedef enum {
118 SPAPR_DR_INDICATOR_INACTIVE = 0,
119 SPAPR_DR_INDICATOR_ACTIVE = 1,
120 SPAPR_DR_INDICATOR_IDENTIFY = 2,
121 SPAPR_DR_INDICATOR_ACTION = 3,
122} SpaprDRIndicatorState;
123
124
125
126
127
128
129
130
131
132
133
134typedef enum {
135 SPAPR_DR_ENTITY_SENSE_EMPTY = 0,
136 SPAPR_DR_ENTITY_SENSE_PRESENT = 1,
137 SPAPR_DR_ENTITY_SENSE_UNUSABLE = 2,
138 SPAPR_DR_ENTITY_SENSE_EXCHANGE = 3,
139 SPAPR_DR_ENTITY_SENSE_RECOVER = 4,
140} SpaprDREntitySense;
141
142typedef enum {
143 SPAPR_DR_CC_RESPONSE_NEXT_SIB = 1,
144 SPAPR_DR_CC_RESPONSE_NEXT_CHILD = 2,
145 SPAPR_DR_CC_RESPONSE_NEXT_PROPERTY = 3,
146 SPAPR_DR_CC_RESPONSE_PREV_PARENT = 4,
147 SPAPR_DR_CC_RESPONSE_SUCCESS = 0,
148 SPAPR_DR_CC_RESPONSE_ERROR = -1,
149 SPAPR_DR_CC_RESPONSE_CONTINUE = -2,
150 SPAPR_DR_CC_RESPONSE_NOT_CONFIGURABLE = -9003,
151} SpaprDRCCResponse;
152
153typedef enum {
154
155
156
157
158
159
160 SPAPR_DRC_STATE_INVALID = 0,
161 SPAPR_DRC_STATE_LOGICAL_UNUSABLE = 1,
162 SPAPR_DRC_STATE_LOGICAL_AVAILABLE = 2,
163 SPAPR_DRC_STATE_LOGICAL_UNISOLATE = 3,
164 SPAPR_DRC_STATE_LOGICAL_CONFIGURED = 4,
165 SPAPR_DRC_STATE_PHYSICAL_AVAILABLE = 5,
166 SPAPR_DRC_STATE_PHYSICAL_POWERON = 6,
167 SPAPR_DRC_STATE_PHYSICAL_UNISOLATE = 7,
168 SPAPR_DRC_STATE_PHYSICAL_CONFIGURED = 8,
169} SpaprDrcState;
170
171typedef struct SpaprDrc {
172
173 DeviceState parent;
174
175 uint32_t id;
176 Object *owner;
177
178 uint32_t state;
179
180
181
182 int ccs_offset;
183 int ccs_depth;
184
185
186 DeviceState *dev;
187 bool unplug_requested;
188 void *fdt;
189 int fdt_start_offset;
190} SpaprDrc;
191
192struct SpaprMachineState;
193
194typedef struct SpaprDrcClass {
195
196 DeviceClass parent;
197 SpaprDrcState empty_state;
198 SpaprDrcState ready_state;
199
200
201 SpaprDrcTypeShift typeshift;
202 const char *typename;
203 const char *drc_name_prefix;
204
205 SpaprDREntitySense (*dr_entity_sense)(SpaprDrc *drc);
206 uint32_t (*isolate)(SpaprDrc *drc);
207 uint32_t (*unisolate)(SpaprDrc *drc);
208 void (*release)(DeviceState *dev);
209
210 int (*dt_populate)(SpaprDrc *drc, struct SpaprMachineState *spapr,
211 void *fdt, int *fdt_start_offset, Error **errp);
212} SpaprDrcClass;
213
214typedef struct SpaprDrcPhysical {
215
216 SpaprDrc parent;
217
218
219 uint32_t dr_indicator;
220} SpaprDrcPhysical;
221
222static inline bool spapr_drc_hotplugged(DeviceState *dev)
223{
224 return dev->hotplugged && !runstate_check(RUN_STATE_INMIGRATE);
225}
226
227
228bool spapr_drc_reset(SpaprDrc *drc);
229
230uint32_t spapr_drc_index(SpaprDrc *drc);
231SpaprDrcType spapr_drc_type(SpaprDrc *drc);
232
233SpaprDrc *spapr_dr_connector_new(Object *owner, const char *type,
234 uint32_t id);
235SpaprDrc *spapr_drc_by_index(uint32_t index);
236SpaprDrc *spapr_drc_by_id(const char *type, uint32_t id);
237int spapr_dt_drc(void *fdt, int offset, Object *owner, uint32_t drc_type_mask);
238
239
240
241
242
243
244
245void spapr_drc_attach(SpaprDrc *drc, DeviceState *d);
246void spapr_drc_unplug_request(SpaprDrc *drc);
247
248
249
250
251
252void spapr_drc_reset_all(struct SpaprMachineState *spapr);
253
254static inline bool spapr_drc_unplug_requested(SpaprDrc *drc)
255{
256 return drc->unplug_requested;
257}
258
259#endif
260