Merge tag 'pull-loongarch-20241016' of https://gitlab.com/gaosong/qemu into staging
[qemu/armbru.git] / include / hw / ppc / spapr_drc.h
blob02a63b366668e063d2043007f31b5f1ac7af9685
1 /*
2 * QEMU SPAPR Dynamic Reconfiguration Connector Implementation
4 * Copyright IBM Corp. 2014
6 * Authors:
7 * Michael Roth <mdroth@linux.vnet.ibm.com>
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.
13 #ifndef HW_SPAPR_DRC_H
14 #define HW_SPAPR_DRC_H
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"
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)
31 #define TYPE_SPAPR_DRC_PHYSICAL "spapr-drc-physical"
32 #define SPAPR_DRC_PHYSICAL(obj) OBJECT_CHECK(SpaprDrcPhysical, (obj), \
33 TYPE_SPAPR_DRC_PHYSICAL)
35 #define TYPE_SPAPR_DRC_LOGICAL "spapr-drc-logical"
37 #define TYPE_SPAPR_DRC_CPU "spapr-drc-cpu"
39 #define TYPE_SPAPR_DRC_PCI "spapr-drc-pci"
41 #define TYPE_SPAPR_DRC_LMB "spapr-drc-lmb"
43 #define TYPE_SPAPR_DRC_PHB "spapr-drc-phb"
45 #define TYPE_SPAPR_DRC_PMEM "spapr-drc-pmem"
48 * Various hotplug types managed by SpaprDrc
50 * these are somewhat arbitrary, but to make things easier
51 * when generating DRC indexes later we've aligned the bit
52 * positions with the values used to assign DRC indexes on
53 * pSeries. we use those values as bit shifts to allow for
54 * the OR'ing of these values in various QEMU routines, but
55 * for values exposed to the guest (via DRC indexes for
56 * instance) we will use the shift amounts.
58 typedef 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;
67 typedef 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;
78 * set via set-indicator RTAS calls
79 * as documented by PAPR+ 2.7 13.5.3.4, Table 177
81 * isolated: put device under firmware control
82 * unisolated: claim OS control of device (may or may not be in use)
84 typedef enum {
85 SPAPR_DR_ISOLATION_STATE_ISOLATED = 0,
86 SPAPR_DR_ISOLATION_STATE_UNISOLATED = 1
87 } SpaprDRIsolationState;
90 * set via set-indicator RTAS calls
91 * as documented by PAPR+ 2.7 13.5.3.4, Table 177
93 * unusable: mark device as unavailable to OS
94 * usable: mark device as available to OS
95 * exchange: (currently unused)
96 * recover: (currently unused)
98 typedef 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;
106 * DR-indicator (LED/visual indicator)
108 * set via set-indicator RTAS calls
109 * as documented by PAPR+ 2.7 13.5.3.4, Table 177,
110 * and PAPR+ 2.7 13.5.4.1, Table 180
112 * inactive: hotpluggable entity inactive and safely removable
113 * active: hotpluggable entity in use and not safely removable
114 * identify: (currently unused)
115 * action: (currently unused)
117 typedef 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;
125 * returned via get-sensor-state RTAS calls
126 * as documented by PAPR+ 2.7 13.5.3.3, Table 175:
128 * empty: connector slot empty (e.g. empty hotpluggable PCI slot)
129 * present: connector slot populated and device available to OS
130 * unusable: device not currently available to OS
131 * exchange: (currently unused)
132 * recover: (currently unused)
134 typedef 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;
142 typedef enum {
143 SPAPR_DR_CC_RESPONSE_NEXT_SIB = 1, /* currently unused */
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;
153 typedef enum {
155 * Values come from Fig. 12 in LoPAPR section 13.4
157 * These are exposed in the migration stream, so don't change
158 * them.
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;
171 typedef struct SpaprDrc {
172 /*< private >*/
173 DeviceState parent;
175 uint32_t id;
176 Object *owner;
178 uint32_t state;
180 /* RTAS ibm,configure-connector state */
181 /* (only valid in UNISOLATE state) */
182 int ccs_offset;
183 int ccs_depth;
185 /* device pointer, via link property */
186 DeviceState *dev;
187 bool unplug_requested;
188 void *fdt;
189 int fdt_start_offset;
190 } SpaprDrc;
192 struct SpaprMachineState;
194 typedef struct SpaprDrcClass {
195 /*< private >*/
196 DeviceClass parent;
197 SpaprDrcState empty_state;
198 SpaprDrcState ready_state;
200 /*< public >*/
201 SpaprDrcTypeShift typeshift;
202 const char *typename; /* used in device tree, PAPR 13.5.2.6 & C.6.1 */
203 const char *drc_name_prefix; /* used other places in device tree */
205 SpaprDREntitySense (*dr_entity_sense)(SpaprDrc *drc);
206 uint32_t (*isolate)(SpaprDrc *drc);
207 uint32_t (*unisolate)(SpaprDrc *drc);
208 void (*release)(DeviceState *dev);
210 int (*dt_populate)(SpaprDrc *drc, struct SpaprMachineState *spapr,
211 void *fdt, int *fdt_start_offset, Error **errp);
212 } SpaprDrcClass;
214 typedef struct SpaprDrcPhysical {
215 /*< private >*/
216 SpaprDrc parent;
218 /* DR-indicator */
219 uint32_t dr_indicator;
220 } SpaprDrcPhysical;
222 static inline bool spapr_drc_hotplugged(DeviceState *dev)
224 return dev->hotplugged && !runstate_check(RUN_STATE_INMIGRATE);
227 /* Returns true if an unplug request completed */
228 bool spapr_drc_reset(SpaprDrc *drc);
230 uint32_t spapr_drc_index(SpaprDrc *drc);
231 SpaprDrcType spapr_drc_type(SpaprDrc *drc);
233 SpaprDrc *spapr_dr_connector_new(Object *owner, const char *type,
234 uint32_t id);
235 SpaprDrc *spapr_drc_by_index(uint32_t index);
236 SpaprDrc *spapr_drc_by_id(const char *type, uint32_t id);
237 int spapr_dt_drc(void *fdt, int offset, Object *owner, uint32_t drc_type_mask);
240 * These functions respectively abort if called with a device already
241 * attached or no device attached. In the case of spapr_drc_attach(),
242 * this means that the attachability of the DRC *must* be checked
243 * beforehand (eg. check drc->dev at pre-plug).
245 void spapr_drc_attach(SpaprDrc *drc, DeviceState *d);
246 void spapr_drc_unplug_request(SpaprDrc *drc);
249 * Reset all DRCs, causing pending hot-plug/unplug requests to complete.
250 * Safely handles potential DRC removal (eg. PHBs or PCI bridges).
252 void spapr_drc_reset_all(struct SpaprMachineState *spapr);
254 static inline bool spapr_drc_unplug_requested(SpaprDrc *drc)
256 return drc->unplug_requested;
259 #endif /* HW_SPAPR_DRC_H */