2 * QEMU SPAPR Dynamic Reconfiguration Connector Implementation
4 * Copyright IBM Corp. 2014
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.
12 #if !defined(__HW_SPAPR_DRC_H__)
13 #define __HW_SPAPR_DRC_H__
15 #include "qom/object.h"
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)
29 * Various hotplug types managed by sPAPRDRConnector
31 * these are somewhat arbitrary, but to make things easier
32 * when generating DRC indexes later we've aligned the bit
33 * positions with the values used to assign DRC indexes on
34 * pSeries. we use those values as bit shifts to allow for
35 * the OR'ing of these values in various QEMU routines, but
36 * for values exposed to the guest (via DRC indexes for
37 * instance) we will use the shift amounts.
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;
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;
57 * set via set-indicator RTAS calls
58 * as documented by PAPR+ 2.7 13.5.3.4, Table 177
60 * isolated: put device under firmware control
61 * unisolated: claim OS control of device (may or may not be in use)
64 SPAPR_DR_ISOLATION_STATE_ISOLATED = 0,
65 SPAPR_DR_ISOLATION_STATE_UNISOLATED = 1
66 } sPAPRDRIsolationState;
69 * set via set-indicator RTAS calls
70 * as documented by PAPR+ 2.7 13.5.3.4, Table 177
72 * unusable: mark device as unavailable to OS
73 * usable: mark device as available to OS
74 * exchange: (currently unused)
75 * recover: (currently unused)
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;
85 * LED/visual indicator state
87 * set via set-indicator RTAS calls
88 * as documented by PAPR+ 2.7 13.5.3.4, Table 177,
89 * and PAPR+ 2.7 13.5.4.1, Table 180
91 * inactive: hotpluggable entity inactive and safely removable
92 * active: hotpluggable entity in use and not safely removable
93 * identify: (currently unused)
94 * action: (currently unused)
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;
104 * returned via get-sensor-state RTAS calls
105 * as documented by PAPR+ 2.7 13.5.3.3, Table 175:
107 * empty: connector slot empty (e.g. empty hotpluggable PCI slot)
108 * present: connector slot populated and device available to OS
109 * unusable: device not currently available to OS
110 * exchange: (currently unused)
111 * recover: (currently unused)
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;
122 SPAPR_DR_CC_RESPONSE_NEXT_SIB = 1, /* currently unused */
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,
131 typedef void (spapr_drc_detach_cb)(DeviceState *d, void *opaque);
133 typedef struct sPAPRDRConnector {
137 sPAPRDRConnectorType type;
142 /* sensor/indicator states */
143 uint32_t isolation_state;
144 uint32_t allocation_state;
145 uint32_t indicator_state;
147 /* configure-connector state */
149 int fdt_start_offset;
152 bool awaiting_release;
154 /* device pointer, via link property */
156 spapr_drc_detach_cb *detach_cb;
157 void *detach_cb_opaque;
160 typedef struct sPAPRDRConnectorClass {
166 /* accessors for guest-visible (generally via RTAS) DR state */
167 int (*set_isolation_state)(sPAPRDRConnector *drc,
168 sPAPRDRIsolationState state);
169 int (*set_indicator_state)(sPAPRDRConnector *drc,
170 sPAPRDRIndicatorState state);
171 int (*set_allocation_state)(sPAPRDRConnector *drc,
172 sPAPRDRAllocationState state);
173 uint32_t (*get_index)(sPAPRDRConnector *drc);
174 uint32_t (*get_type)(sPAPRDRConnector *drc);
175 const char *(*get_name)(sPAPRDRConnector *drc);
177 sPAPRDREntitySense (*entity_sense)(sPAPRDRConnector *drc);
179 /* QEMU interfaces for managing FDT/configure-connector */
180 const void *(*get_fdt)(sPAPRDRConnector *drc, int *fdt_start_offset);
181 void (*set_configured)(sPAPRDRConnector *drc);
183 /* QEMU interfaces for managing hotplug operations */
184 void (*attach)(sPAPRDRConnector *drc, DeviceState *d, void *fdt,
185 int fdt_start_offset, bool coldplug, Error **errp);
186 void (*detach)(sPAPRDRConnector *drc, DeviceState *d,
187 spapr_drc_detach_cb *detach_cb,
188 void *detach_cb_opaque, Error **errp);
189 bool (*release_pending)(sPAPRDRConnector *drc);
190 } sPAPRDRConnectorClass;
192 sPAPRDRConnector *spapr_dr_connector_new(Object *owner,
193 sPAPRDRConnectorType type,
195 sPAPRDRConnector *spapr_dr_connector_by_index(uint32_t index);
196 sPAPRDRConnector *spapr_dr_connector_by_id(sPAPRDRConnectorType type,
198 int spapr_drc_populate_dt(void *fdt, int fdt_offset, Object *owner,
199 uint32_t drc_type_mask);
201 #endif /* __HW_SPAPR_DRC_H__ */