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