xref: /openbmc/qemu/include/hw/ppc/spapr_drc.h (revision e6fc9568c865f2f81499475a4e322cd563fdfd90)
1bbf5c878SMichael Roth /*
2bbf5c878SMichael Roth  * QEMU SPAPR Dynamic Reconfiguration Connector Implementation
3bbf5c878SMichael Roth  *
4bbf5c878SMichael Roth  * Copyright IBM Corp. 2014
5bbf5c878SMichael Roth  *
6bbf5c878SMichael Roth  * Authors:
7bbf5c878SMichael Roth  *  Michael Roth      <mdroth@linux.vnet.ibm.com>
8bbf5c878SMichael Roth  *
9bbf5c878SMichael Roth  * This work is licensed under the terms of the GNU GPL, version 2 or later.
10bbf5c878SMichael Roth  * See the COPYING file in the top-level directory.
11bbf5c878SMichael Roth  */
12bbf5c878SMichael Roth #if !defined(__HW_SPAPR_DRC_H__)
13bbf5c878SMichael Roth #define __HW_SPAPR_DRC_H__
14bbf5c878SMichael Roth 
15bbf5c878SMichael Roth #include "qom/object.h"
16bbf5c878SMichael Roth #include "hw/qdev.h"
17bbf5c878SMichael Roth #include "libfdt.h"
18bbf5c878SMichael Roth 
19bbf5c878SMichael Roth #define TYPE_SPAPR_DR_CONNECTOR "spapr-dr-connector"
20bbf5c878SMichael Roth #define SPAPR_DR_CONNECTOR_GET_CLASS(obj) \
21bbf5c878SMichael Roth         OBJECT_GET_CLASS(sPAPRDRConnectorClass, obj, TYPE_SPAPR_DR_CONNECTOR)
22bbf5c878SMichael Roth #define SPAPR_DR_CONNECTOR_CLASS(klass) \
23bbf5c878SMichael Roth         OBJECT_CLASS_CHECK(sPAPRDRConnectorClass, klass, \
24bbf5c878SMichael Roth                            TYPE_SPAPR_DR_CONNECTOR)
25bbf5c878SMichael Roth #define SPAPR_DR_CONNECTOR(obj) OBJECT_CHECK(sPAPRDRConnector, (obj), \
26bbf5c878SMichael Roth                                              TYPE_SPAPR_DR_CONNECTOR)
27bbf5c878SMichael Roth 
28bbf5c878SMichael Roth /*
29bbf5c878SMichael Roth  * Various hotplug types managed by sPAPRDRConnector
30bbf5c878SMichael Roth  *
31bbf5c878SMichael Roth  * these are somewhat arbitrary, but to make things easier
32bbf5c878SMichael Roth  * when generating DRC indexes later we've aligned the bit
33bbf5c878SMichael Roth  * positions with the values used to assign DRC indexes on
34bbf5c878SMichael Roth  * pSeries. we use those values as bit shifts to allow for
35bbf5c878SMichael Roth  * the OR'ing of these values in various QEMU routines, but
36bbf5c878SMichael Roth  * for values exposed to the guest (via DRC indexes for
37bbf5c878SMichael Roth  * instance) we will use the shift amounts.
38bbf5c878SMichael Roth  */
39bbf5c878SMichael Roth typedef enum {
40bbf5c878SMichael Roth     SPAPR_DR_CONNECTOR_TYPE_SHIFT_CPU = 1,
41bbf5c878SMichael Roth     SPAPR_DR_CONNECTOR_TYPE_SHIFT_PHB = 2,
42bbf5c878SMichael Roth     SPAPR_DR_CONNECTOR_TYPE_SHIFT_VIO = 3,
43bbf5c878SMichael Roth     SPAPR_DR_CONNECTOR_TYPE_SHIFT_PCI = 4,
44bbf5c878SMichael Roth     SPAPR_DR_CONNECTOR_TYPE_SHIFT_LMB = 8,
45bbf5c878SMichael Roth } sPAPRDRConnectorTypeShift;
46bbf5c878SMichael Roth 
47bbf5c878SMichael Roth typedef enum {
48bbf5c878SMichael Roth     SPAPR_DR_CONNECTOR_TYPE_ANY = ~0,
49bbf5c878SMichael Roth     SPAPR_DR_CONNECTOR_TYPE_CPU = 1 << SPAPR_DR_CONNECTOR_TYPE_SHIFT_CPU,
50bbf5c878SMichael Roth     SPAPR_DR_CONNECTOR_TYPE_PHB = 1 << SPAPR_DR_CONNECTOR_TYPE_SHIFT_PHB,
51bbf5c878SMichael Roth     SPAPR_DR_CONNECTOR_TYPE_VIO = 1 << SPAPR_DR_CONNECTOR_TYPE_SHIFT_VIO,
52bbf5c878SMichael Roth     SPAPR_DR_CONNECTOR_TYPE_PCI = 1 << SPAPR_DR_CONNECTOR_TYPE_SHIFT_PCI,
53bbf5c878SMichael Roth     SPAPR_DR_CONNECTOR_TYPE_LMB = 1 << SPAPR_DR_CONNECTOR_TYPE_SHIFT_LMB,
54bbf5c878SMichael Roth } sPAPRDRConnectorType;
55bbf5c878SMichael Roth 
56bbf5c878SMichael Roth /*
57bbf5c878SMichael Roth  * set via set-indicator RTAS calls
58bbf5c878SMichael Roth  * as documented by PAPR+ 2.7 13.5.3.4, Table 177
59bbf5c878SMichael Roth  *
60bbf5c878SMichael Roth  * isolated: put device under firmware control
61bbf5c878SMichael Roth  * unisolated: claim OS control of device (may or may not be in use)
62bbf5c878SMichael Roth  */
63bbf5c878SMichael Roth typedef enum {
64bbf5c878SMichael Roth     SPAPR_DR_ISOLATION_STATE_ISOLATED   = 0,
65bbf5c878SMichael Roth     SPAPR_DR_ISOLATION_STATE_UNISOLATED = 1
66bbf5c878SMichael Roth } sPAPRDRIsolationState;
67bbf5c878SMichael Roth 
68bbf5c878SMichael Roth /*
69bbf5c878SMichael Roth  * set via set-indicator RTAS calls
70bbf5c878SMichael Roth  * as documented by PAPR+ 2.7 13.5.3.4, Table 177
71bbf5c878SMichael Roth  *
72bbf5c878SMichael Roth  * unusable: mark device as unavailable to OS
73bbf5c878SMichael Roth  * usable: mark device as available to OS
74bbf5c878SMichael Roth  * exchange: (currently unused)
75bbf5c878SMichael Roth  * recover: (currently unused)
76bbf5c878SMichael Roth  */
77bbf5c878SMichael Roth typedef enum {
78bbf5c878SMichael Roth     SPAPR_DR_ALLOCATION_STATE_UNUSABLE  = 0,
79bbf5c878SMichael Roth     SPAPR_DR_ALLOCATION_STATE_USABLE    = 1,
80bbf5c878SMichael Roth     SPAPR_DR_ALLOCATION_STATE_EXCHANGE  = 2,
81bbf5c878SMichael Roth     SPAPR_DR_ALLOCATION_STATE_RECOVER   = 3
82bbf5c878SMichael Roth } sPAPRDRAllocationState;
83bbf5c878SMichael Roth 
84bbf5c878SMichael Roth /*
85bbf5c878SMichael Roth  * LED/visual indicator state
86bbf5c878SMichael Roth  *
87bbf5c878SMichael Roth  * set via set-indicator RTAS calls
88bbf5c878SMichael Roth  * as documented by PAPR+ 2.7 13.5.3.4, Table 177,
89bbf5c878SMichael Roth  * and PAPR+ 2.7 13.5.4.1, Table 180
90bbf5c878SMichael Roth  *
91bbf5c878SMichael Roth  * inactive: hotpluggable entity inactive and safely removable
92bbf5c878SMichael Roth  * active: hotpluggable entity in use and not safely removable
93bbf5c878SMichael Roth  * identify: (currently unused)
94bbf5c878SMichael Roth  * action: (currently unused)
95bbf5c878SMichael Roth  */
96bbf5c878SMichael Roth typedef enum {
97bbf5c878SMichael Roth     SPAPR_DR_INDICATOR_STATE_INACTIVE   = 0,
98bbf5c878SMichael Roth     SPAPR_DR_INDICATOR_STATE_ACTIVE     = 1,
99bbf5c878SMichael Roth     SPAPR_DR_INDICATOR_STATE_IDENTIFY   = 2,
100bbf5c878SMichael Roth     SPAPR_DR_INDICATOR_STATE_ACTION     = 3,
101bbf5c878SMichael Roth } sPAPRDRIndicatorState;
102bbf5c878SMichael Roth 
103bbf5c878SMichael Roth /*
104bbf5c878SMichael Roth  * returned via get-sensor-state RTAS calls
105bbf5c878SMichael Roth  * as documented by PAPR+ 2.7 13.5.3.3, Table 175:
106bbf5c878SMichael Roth  *
107bbf5c878SMichael Roth  * empty: connector slot empty (e.g. empty hotpluggable PCI slot)
108bbf5c878SMichael Roth  * present: connector slot populated and device available to OS
109bbf5c878SMichael Roth  * unusable: device not currently available to OS
110bbf5c878SMichael Roth  * exchange: (currently unused)
111bbf5c878SMichael Roth  * recover: (currently unused)
112bbf5c878SMichael Roth  */
113bbf5c878SMichael Roth typedef enum {
114bbf5c878SMichael Roth     SPAPR_DR_ENTITY_SENSE_EMPTY     = 0,
115bbf5c878SMichael Roth     SPAPR_DR_ENTITY_SENSE_PRESENT   = 1,
116bbf5c878SMichael Roth     SPAPR_DR_ENTITY_SENSE_UNUSABLE  = 2,
117bbf5c878SMichael Roth     SPAPR_DR_ENTITY_SENSE_EXCHANGE  = 3,
118bbf5c878SMichael Roth     SPAPR_DR_ENTITY_SENSE_RECOVER   = 4,
119bbf5c878SMichael Roth } sPAPRDREntitySense;
120bbf5c878SMichael Roth 
121bbf5c878SMichael Roth typedef enum {
122bbf5c878SMichael Roth     SPAPR_DR_CC_RESPONSE_NEXT_SIB         = 1, /* currently unused */
123bbf5c878SMichael Roth     SPAPR_DR_CC_RESPONSE_NEXT_CHILD       = 2,
124bbf5c878SMichael Roth     SPAPR_DR_CC_RESPONSE_NEXT_PROPERTY    = 3,
125bbf5c878SMichael Roth     SPAPR_DR_CC_RESPONSE_PREV_PARENT      = 4,
126bbf5c878SMichael Roth     SPAPR_DR_CC_RESPONSE_SUCCESS          = 0,
127bbf5c878SMichael Roth     SPAPR_DR_CC_RESPONSE_ERROR            = -1,
128bbf5c878SMichael Roth     SPAPR_DR_CC_RESPONSE_CONTINUE         = -2,
129*e6fc9568SBharata B Rao     SPAPR_DR_CC_RESPONSE_NOT_CONFIGURABLE = -9003,
130bbf5c878SMichael Roth } sPAPRDRCCResponse;
131bbf5c878SMichael Roth 
132bbf5c878SMichael Roth typedef void (spapr_drc_detach_cb)(DeviceState *d, void *opaque);
133bbf5c878SMichael Roth 
134bbf5c878SMichael Roth typedef struct sPAPRDRConnector {
135bbf5c878SMichael Roth     /*< private >*/
136bbf5c878SMichael Roth     DeviceState parent;
137bbf5c878SMichael Roth 
138bbf5c878SMichael Roth     sPAPRDRConnectorType type;
139bbf5c878SMichael Roth     uint32_t id;
140bbf5c878SMichael Roth     Object *owner;
141bbf5c878SMichael Roth     const char *name;
142bbf5c878SMichael Roth 
143bbf5c878SMichael Roth     /* sensor/indicator states */
144bbf5c878SMichael Roth     uint32_t isolation_state;
145bbf5c878SMichael Roth     uint32_t allocation_state;
146bbf5c878SMichael Roth     uint32_t indicator_state;
147bbf5c878SMichael Roth 
148bbf5c878SMichael Roth     /* configure-connector state */
149bbf5c878SMichael Roth     void *fdt;
150bbf5c878SMichael Roth     int fdt_start_offset;
151bbf5c878SMichael Roth     bool configured;
152bbf5c878SMichael Roth 
153bbf5c878SMichael Roth     bool awaiting_release;
154bbf5c878SMichael Roth 
155bbf5c878SMichael Roth     /* device pointer, via link property */
156bbf5c878SMichael Roth     DeviceState *dev;
157bbf5c878SMichael Roth     spapr_drc_detach_cb *detach_cb;
158bbf5c878SMichael Roth     void *detach_cb_opaque;
159bbf5c878SMichael Roth } sPAPRDRConnector;
160bbf5c878SMichael Roth 
161bbf5c878SMichael Roth typedef struct sPAPRDRConnectorClass {
162bbf5c878SMichael Roth     /*< private >*/
163bbf5c878SMichael Roth     DeviceClass parent;
164bbf5c878SMichael Roth 
165bbf5c878SMichael Roth     /*< public >*/
166bbf5c878SMichael Roth 
167bbf5c878SMichael Roth     /* accessors for guest-visible (generally via RTAS) DR state */
168bbf5c878SMichael Roth     int (*set_isolation_state)(sPAPRDRConnector *drc,
169bbf5c878SMichael Roth                                sPAPRDRIsolationState state);
170bbf5c878SMichael Roth     int (*set_indicator_state)(sPAPRDRConnector *drc,
171bbf5c878SMichael Roth                                sPAPRDRIndicatorState state);
172bbf5c878SMichael Roth     int (*set_allocation_state)(sPAPRDRConnector *drc,
173bbf5c878SMichael Roth                                 sPAPRDRAllocationState state);
174bbf5c878SMichael Roth     uint32_t (*get_index)(sPAPRDRConnector *drc);
175bbf5c878SMichael Roth     uint32_t (*get_type)(sPAPRDRConnector *drc);
176bbf5c878SMichael Roth     const char *(*get_name)(sPAPRDRConnector *drc);
177bbf5c878SMichael Roth 
178bbf5c878SMichael Roth     sPAPRDREntitySense (*entity_sense)(sPAPRDRConnector *drc);
179bbf5c878SMichael Roth 
180bbf5c878SMichael Roth     /* QEMU interfaces for managing FDT/configure-connector */
181bbf5c878SMichael Roth     const void *(*get_fdt)(sPAPRDRConnector *drc, int *fdt_start_offset);
182bbf5c878SMichael Roth     void (*set_configured)(sPAPRDRConnector *drc);
183bbf5c878SMichael Roth 
184bbf5c878SMichael Roth     /* QEMU interfaces for managing hotplug operations */
185bbf5c878SMichael Roth     void (*attach)(sPAPRDRConnector *drc, DeviceState *d, void *fdt,
186bbf5c878SMichael Roth                    int fdt_start_offset, bool coldplug, Error **errp);
187bbf5c878SMichael Roth     void (*detach)(sPAPRDRConnector *drc, DeviceState *d,
188bbf5c878SMichael Roth                    spapr_drc_detach_cb *detach_cb,
189bbf5c878SMichael Roth                    void *detach_cb_opaque, Error **errp);
190bbf5c878SMichael Roth     bool (*release_pending)(sPAPRDRConnector *drc);
191bbf5c878SMichael Roth } sPAPRDRConnectorClass;
192bbf5c878SMichael Roth 
193bbf5c878SMichael Roth sPAPRDRConnector *spapr_dr_connector_new(Object *owner,
194bbf5c878SMichael Roth                                          sPAPRDRConnectorType type,
195bbf5c878SMichael Roth                                          uint32_t id);
196bbf5c878SMichael Roth sPAPRDRConnector *spapr_dr_connector_by_index(uint32_t index);
197bbf5c878SMichael Roth sPAPRDRConnector *spapr_dr_connector_by_id(sPAPRDRConnectorType type,
198bbf5c878SMichael Roth                                            uint32_t id);
199e4b798bbSMichael Roth int spapr_drc_populate_dt(void *fdt, int fdt_offset, Object *owner,
200e4b798bbSMichael Roth                           uint32_t drc_type_mask);
201bbf5c878SMichael Roth 
202bbf5c878SMichael Roth #endif /* __HW_SPAPR_DRC_H__ */
203