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 "hw/qdev.h"
19
20#define TYPE_SPAPR_DR_CONNECTOR "spapr-dr-connector"
21#define SPAPR_DR_CONNECTOR_GET_CLASS(obj) \
22 OBJECT_GET_CLASS(sPAPRDRConnectorClass, obj, TYPE_SPAPR_DR_CONNECTOR)
23#define SPAPR_DR_CONNECTOR_CLASS(klass) \
24 OBJECT_CLASS_CHECK(sPAPRDRConnectorClass, klass, \
25 TYPE_SPAPR_DR_CONNECTOR)
26#define SPAPR_DR_CONNECTOR(obj) OBJECT_CHECK(sPAPRDRConnector, (obj), \
27 TYPE_SPAPR_DR_CONNECTOR)
28
29
30
31
32
33
34
35
36
37
38
39
40typedef enum {
41 SPAPR_DR_CONNECTOR_TYPE_SHIFT_CPU = 1,
42 SPAPR_DR_CONNECTOR_TYPE_SHIFT_PHB = 2,
43 SPAPR_DR_CONNECTOR_TYPE_SHIFT_VIO = 3,
44 SPAPR_DR_CONNECTOR_TYPE_SHIFT_PCI = 4,
45 SPAPR_DR_CONNECTOR_TYPE_SHIFT_LMB = 8,
46} sPAPRDRConnectorTypeShift;
47
48typedef enum {
49 SPAPR_DR_CONNECTOR_TYPE_ANY = ~0,
50 SPAPR_DR_CONNECTOR_TYPE_CPU = 1 << SPAPR_DR_CONNECTOR_TYPE_SHIFT_CPU,
51 SPAPR_DR_CONNECTOR_TYPE_PHB = 1 << SPAPR_DR_CONNECTOR_TYPE_SHIFT_PHB,
52 SPAPR_DR_CONNECTOR_TYPE_VIO = 1 << SPAPR_DR_CONNECTOR_TYPE_SHIFT_VIO,
53 SPAPR_DR_CONNECTOR_TYPE_PCI = 1 << SPAPR_DR_CONNECTOR_TYPE_SHIFT_PCI,
54 SPAPR_DR_CONNECTOR_TYPE_LMB = 1 << SPAPR_DR_CONNECTOR_TYPE_SHIFT_LMB,
55} sPAPRDRConnectorType;
56
57
58
59
60
61
62
63
64typedef enum {
65 SPAPR_DR_ISOLATION_STATE_ISOLATED = 0,
66 SPAPR_DR_ISOLATION_STATE_UNISOLATED = 1
67} sPAPRDRIsolationState;
68
69
70
71
72
73
74
75
76
77
78typedef enum {
79 SPAPR_DR_ALLOCATION_STATE_UNUSABLE = 0,
80 SPAPR_DR_ALLOCATION_STATE_USABLE = 1,
81 SPAPR_DR_ALLOCATION_STATE_EXCHANGE = 2,
82 SPAPR_DR_ALLOCATION_STATE_RECOVER = 3
83} sPAPRDRAllocationState;
84
85
86
87
88
89
90
91
92
93
94
95
96
97typedef enum {
98 SPAPR_DR_INDICATOR_STATE_INACTIVE = 0,
99 SPAPR_DR_INDICATOR_STATE_ACTIVE = 1,
100 SPAPR_DR_INDICATOR_STATE_IDENTIFY = 2,
101 SPAPR_DR_INDICATOR_STATE_ACTION = 3,
102} sPAPRDRIndicatorState;
103
104
105
106
107
108
109
110
111
112
113
114typedef enum {
115 SPAPR_DR_ENTITY_SENSE_EMPTY = 0,
116 SPAPR_DR_ENTITY_SENSE_PRESENT = 1,
117 SPAPR_DR_ENTITY_SENSE_UNUSABLE = 2,
118 SPAPR_DR_ENTITY_SENSE_EXCHANGE = 3,
119 SPAPR_DR_ENTITY_SENSE_RECOVER = 4,
120} sPAPRDREntitySense;
121
122typedef enum {
123 SPAPR_DR_CC_RESPONSE_NEXT_SIB = 1,
124 SPAPR_DR_CC_RESPONSE_NEXT_CHILD = 2,
125 SPAPR_DR_CC_RESPONSE_NEXT_PROPERTY = 3,
126 SPAPR_DR_CC_RESPONSE_PREV_PARENT = 4,
127 SPAPR_DR_CC_RESPONSE_SUCCESS = 0,
128 SPAPR_DR_CC_RESPONSE_ERROR = -1,
129 SPAPR_DR_CC_RESPONSE_CONTINUE = -2,
130 SPAPR_DR_CC_RESPONSE_NOT_CONFIGURABLE = -9003,
131} sPAPRDRCCResponse;
132
133typedef void (spapr_drc_detach_cb)(DeviceState *d, void *opaque);
134
135typedef struct sPAPRDRConnector {
136
137 DeviceState parent;
138
139 sPAPRDRConnectorType type;
140 uint32_t id;
141 Object *owner;
142 const char *name;
143
144
145 uint32_t isolation_state;
146 uint32_t allocation_state;
147 uint32_t indicator_state;
148
149
150 void *fdt;
151 int fdt_start_offset;
152 bool configured;
153
154 bool awaiting_release;
155 bool signalled;
156 bool awaiting_allocation;
157
158
159 DeviceState *dev;
160 spapr_drc_detach_cb *detach_cb;
161 void *detach_cb_opaque;
162} sPAPRDRConnector;
163
164typedef struct sPAPRDRConnectorClass {
165
166 DeviceClass parent;
167
168
169
170
171 uint32_t (*set_isolation_state)(sPAPRDRConnector *drc,
172 sPAPRDRIsolationState state);
173 uint32_t (*set_indicator_state)(sPAPRDRConnector *drc,
174 sPAPRDRIndicatorState state);
175 uint32_t (*set_allocation_state)(sPAPRDRConnector *drc,
176 sPAPRDRAllocationState state);
177 uint32_t (*get_index)(sPAPRDRConnector *drc);
178 uint32_t (*get_type)(sPAPRDRConnector *drc);
179 const char *(*get_name)(sPAPRDRConnector *drc);
180
181 uint32_t (*entity_sense)(sPAPRDRConnector *drc, sPAPRDREntitySense *state);
182
183
184 const void *(*get_fdt)(sPAPRDRConnector *drc, int *fdt_start_offset);
185 void (*set_configured)(sPAPRDRConnector *drc);
186
187
188 void (*attach)(sPAPRDRConnector *drc, DeviceState *d, void *fdt,
189 int fdt_start_offset, bool coldplug, Error **errp);
190 void (*detach)(sPAPRDRConnector *drc, DeviceState *d,
191 spapr_drc_detach_cb *detach_cb,
192 void *detach_cb_opaque, Error **errp);
193 bool (*release_pending)(sPAPRDRConnector *drc);
194 void (*set_signalled)(sPAPRDRConnector *drc);
195} sPAPRDRConnectorClass;
196
197sPAPRDRConnector *spapr_dr_connector_new(Object *owner,
198 sPAPRDRConnectorType type,
199 uint32_t id);
200sPAPRDRConnector *spapr_dr_connector_by_index(uint32_t index);
201sPAPRDRConnector *spapr_dr_connector_by_id(sPAPRDRConnectorType type,
202 uint32_t id);
203int spapr_drc_populate_dt(void *fdt, int fdt_offset, Object *owner,
204 uint32_t drc_type_mask);
205
206#endif
207