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 */ 122a6a4076SMarkus Armbruster 132a6a4076SMarkus Armbruster #ifndef HW_SPAPR_DRC_H 142a6a4076SMarkus Armbruster #define HW_SPAPR_DRC_H 15bbf5c878SMichael Roth 16a9c94277SMarkus Armbruster #include <libfdt.h> 17bbf5c878SMichael Roth #include "qom/object.h" 1854d31236SMarkus Armbruster #include "sysemu/runstate.h" 19a27bd6c7SMarkus Armbruster #include "hw/qdev-core.h" 20d9c95c71SGreg Kurz #include "qapi/error.h" 21bbf5c878SMichael Roth 22bbf5c878SMichael Roth #define TYPE_SPAPR_DR_CONNECTOR "spapr-dr-connector" 23bbf5c878SMichael Roth #define SPAPR_DR_CONNECTOR_GET_CLASS(obj) \ 24ce2918cbSDavid Gibson OBJECT_GET_CLASS(SpaprDrcClass, obj, TYPE_SPAPR_DR_CONNECTOR) 25bbf5c878SMichael Roth #define SPAPR_DR_CONNECTOR_CLASS(klass) \ 26ce2918cbSDavid Gibson OBJECT_CLASS_CHECK(SpaprDrcClass, klass, \ 27bbf5c878SMichael Roth TYPE_SPAPR_DR_CONNECTOR) 28ce2918cbSDavid Gibson #define SPAPR_DR_CONNECTOR(obj) OBJECT_CHECK(SpaprDrc, (obj), \ 29bbf5c878SMichael Roth TYPE_SPAPR_DR_CONNECTOR) 30bbf5c878SMichael Roth 312d335818SDavid Gibson #define TYPE_SPAPR_DRC_PHYSICAL "spapr-drc-physical" 322d335818SDavid Gibson #define SPAPR_DRC_PHYSICAL_GET_CLASS(obj) \ 33ce2918cbSDavid Gibson OBJECT_GET_CLASS(SpaprDrcClass, obj, TYPE_SPAPR_DRC_PHYSICAL) 342d335818SDavid Gibson #define SPAPR_DRC_PHYSICAL_CLASS(klass) \ 35ce2918cbSDavid Gibson OBJECT_CLASS_CHECK(SpaprDrcClass, klass, \ 362d335818SDavid Gibson TYPE_SPAPR_DRC_PHYSICAL) 37ce2918cbSDavid Gibson #define SPAPR_DRC_PHYSICAL(obj) OBJECT_CHECK(SpaprDrcPhysical, (obj), \ 382d335818SDavid Gibson TYPE_SPAPR_DRC_PHYSICAL) 392d335818SDavid Gibson 402d335818SDavid Gibson #define TYPE_SPAPR_DRC_LOGICAL "spapr-drc-logical" 412d335818SDavid Gibson #define SPAPR_DRC_LOGICAL_GET_CLASS(obj) \ 42ce2918cbSDavid Gibson OBJECT_GET_CLASS(SpaprDrcClass, obj, TYPE_SPAPR_DRC_LOGICAL) 432d335818SDavid Gibson #define SPAPR_DRC_LOGICAL_CLASS(klass) \ 44ce2918cbSDavid Gibson OBJECT_CLASS_CHECK(SpaprDrcClass, klass, \ 452d335818SDavid Gibson TYPE_SPAPR_DRC_LOGICAL) 46ce2918cbSDavid Gibson #define SPAPR_DRC_LOGICAL(obj) OBJECT_CHECK(SpaprDrc, (obj), \ 472d335818SDavid Gibson TYPE_SPAPR_DRC_LOGICAL) 482d335818SDavid Gibson 492d335818SDavid Gibson #define TYPE_SPAPR_DRC_CPU "spapr-drc-cpu" 502d335818SDavid Gibson #define SPAPR_DRC_CPU_GET_CLASS(obj) \ 51ce2918cbSDavid Gibson OBJECT_GET_CLASS(SpaprDrcClass, obj, TYPE_SPAPR_DRC_CPU) 522d335818SDavid Gibson #define SPAPR_DRC_CPU_CLASS(klass) \ 53ce2918cbSDavid Gibson OBJECT_CLASS_CHECK(SpaprDrcClass, klass, TYPE_SPAPR_DRC_CPU) 54ce2918cbSDavid Gibson #define SPAPR_DRC_CPU(obj) OBJECT_CHECK(SpaprDrc, (obj), \ 552d335818SDavid Gibson TYPE_SPAPR_DRC_CPU) 562d335818SDavid Gibson 572d335818SDavid Gibson #define TYPE_SPAPR_DRC_PCI "spapr-drc-pci" 582d335818SDavid Gibson #define SPAPR_DRC_PCI_GET_CLASS(obj) \ 59ce2918cbSDavid Gibson OBJECT_GET_CLASS(SpaprDrcClass, obj, TYPE_SPAPR_DRC_PCI) 602d335818SDavid Gibson #define SPAPR_DRC_PCI_CLASS(klass) \ 61ce2918cbSDavid Gibson OBJECT_CLASS_CHECK(SpaprDrcClass, klass, TYPE_SPAPR_DRC_PCI) 62ce2918cbSDavid Gibson #define SPAPR_DRC_PCI(obj) OBJECT_CHECK(SpaprDrc, (obj), \ 632d335818SDavid Gibson TYPE_SPAPR_DRC_PCI) 642d335818SDavid Gibson 652d335818SDavid Gibson #define TYPE_SPAPR_DRC_LMB "spapr-drc-lmb" 662d335818SDavid Gibson #define SPAPR_DRC_LMB_GET_CLASS(obj) \ 67ce2918cbSDavid Gibson OBJECT_GET_CLASS(SpaprDrcClass, obj, TYPE_SPAPR_DRC_LMB) 682d335818SDavid Gibson #define SPAPR_DRC_LMB_CLASS(klass) \ 69ce2918cbSDavid Gibson OBJECT_CLASS_CHECK(SpaprDrcClass, klass, TYPE_SPAPR_DRC_LMB) 70ce2918cbSDavid Gibson #define SPAPR_DRC_LMB(obj) OBJECT_CHECK(SpaprDrc, (obj), \ 712d335818SDavid Gibson TYPE_SPAPR_DRC_LMB) 722d335818SDavid Gibson 73962b6c36SMichael Roth #define TYPE_SPAPR_DRC_PHB "spapr-drc-phb" 74962b6c36SMichael Roth #define SPAPR_DRC_PHB_GET_CLASS(obj) \ 75ce2918cbSDavid Gibson OBJECT_GET_CLASS(SpaprDrcClass, obj, TYPE_SPAPR_DRC_PHB) 76962b6c36SMichael Roth #define SPAPR_DRC_PHB_CLASS(klass) \ 77ce2918cbSDavid Gibson OBJECT_CLASS_CHECK(SpaprDrcClass, klass, TYPE_SPAPR_DRC_PHB) 78ce2918cbSDavid Gibson #define SPAPR_DRC_PHB(obj) OBJECT_CHECK(SpaprDrc, (obj), \ 79962b6c36SMichael Roth TYPE_SPAPR_DRC_PHB) 80962b6c36SMichael Roth 81*ee3a71e3SShivaprasad G Bhat #define TYPE_SPAPR_DRC_PMEM "spapr-drc-pmem" 82*ee3a71e3SShivaprasad G Bhat #define SPAPR_DRC_PMEM_GET_CLASS(obj) \ 83*ee3a71e3SShivaprasad G Bhat OBJECT_GET_CLASS(SpaprDrcClass, obj, TYPE_SPAPR_DRC_PMEM) 84*ee3a71e3SShivaprasad G Bhat #define SPAPR_DRC_PMEM_CLASS(klass) \ 85*ee3a71e3SShivaprasad G Bhat OBJECT_CLASS_CHECK(SpaprDrcClass, klass, TYPE_SPAPR_DRC_PMEM) 86*ee3a71e3SShivaprasad G Bhat #define SPAPR_DRC_PMEM(obj) OBJECT_CHECK(SpaprDrc, (obj), \ 87*ee3a71e3SShivaprasad G Bhat TYPE_SPAPR_DRC_PMEM) 88bbf5c878SMichael Roth /* 89ce2918cbSDavid Gibson * Various hotplug types managed by SpaprDrc 90bbf5c878SMichael Roth * 91bbf5c878SMichael Roth * these are somewhat arbitrary, but to make things easier 92bbf5c878SMichael Roth * when generating DRC indexes later we've aligned the bit 93bbf5c878SMichael Roth * positions with the values used to assign DRC indexes on 94bbf5c878SMichael Roth * pSeries. we use those values as bit shifts to allow for 95bbf5c878SMichael Roth * the OR'ing of these values in various QEMU routines, but 96bbf5c878SMichael Roth * for values exposed to the guest (via DRC indexes for 97bbf5c878SMichael Roth * instance) we will use the shift amounts. 98bbf5c878SMichael Roth */ 99bbf5c878SMichael Roth typedef enum { 100bbf5c878SMichael Roth SPAPR_DR_CONNECTOR_TYPE_SHIFT_CPU = 1, 101bbf5c878SMichael Roth SPAPR_DR_CONNECTOR_TYPE_SHIFT_PHB = 2, 102bbf5c878SMichael Roth SPAPR_DR_CONNECTOR_TYPE_SHIFT_VIO = 3, 103bbf5c878SMichael Roth SPAPR_DR_CONNECTOR_TYPE_SHIFT_PCI = 4, 104bbf5c878SMichael Roth SPAPR_DR_CONNECTOR_TYPE_SHIFT_LMB = 8, 105*ee3a71e3SShivaprasad G Bhat SPAPR_DR_CONNECTOR_TYPE_SHIFT_PMEM = 9, 106ce2918cbSDavid Gibson } SpaprDrcTypeShift; 107bbf5c878SMichael Roth 108bbf5c878SMichael Roth typedef enum { 109bbf5c878SMichael Roth SPAPR_DR_CONNECTOR_TYPE_ANY = ~0, 110bbf5c878SMichael Roth SPAPR_DR_CONNECTOR_TYPE_CPU = 1 << SPAPR_DR_CONNECTOR_TYPE_SHIFT_CPU, 111bbf5c878SMichael Roth SPAPR_DR_CONNECTOR_TYPE_PHB = 1 << SPAPR_DR_CONNECTOR_TYPE_SHIFT_PHB, 112bbf5c878SMichael Roth SPAPR_DR_CONNECTOR_TYPE_VIO = 1 << SPAPR_DR_CONNECTOR_TYPE_SHIFT_VIO, 113bbf5c878SMichael Roth SPAPR_DR_CONNECTOR_TYPE_PCI = 1 << SPAPR_DR_CONNECTOR_TYPE_SHIFT_PCI, 114bbf5c878SMichael Roth SPAPR_DR_CONNECTOR_TYPE_LMB = 1 << SPAPR_DR_CONNECTOR_TYPE_SHIFT_LMB, 115*ee3a71e3SShivaprasad G Bhat SPAPR_DR_CONNECTOR_TYPE_PMEM = 1 << SPAPR_DR_CONNECTOR_TYPE_SHIFT_PMEM, 116ce2918cbSDavid Gibson } SpaprDrcType; 117bbf5c878SMichael Roth 118bbf5c878SMichael Roth /* 119bbf5c878SMichael Roth * set via set-indicator RTAS calls 120bbf5c878SMichael Roth * as documented by PAPR+ 2.7 13.5.3.4, Table 177 121bbf5c878SMichael Roth * 122bbf5c878SMichael Roth * isolated: put device under firmware control 123bbf5c878SMichael Roth * unisolated: claim OS control of device (may or may not be in use) 124bbf5c878SMichael Roth */ 125bbf5c878SMichael Roth typedef enum { 126bbf5c878SMichael Roth SPAPR_DR_ISOLATION_STATE_ISOLATED = 0, 127bbf5c878SMichael Roth SPAPR_DR_ISOLATION_STATE_UNISOLATED = 1 128ce2918cbSDavid Gibson } SpaprDRIsolationState; 129bbf5c878SMichael Roth 130bbf5c878SMichael Roth /* 131bbf5c878SMichael Roth * set via set-indicator RTAS calls 132bbf5c878SMichael Roth * as documented by PAPR+ 2.7 13.5.3.4, Table 177 133bbf5c878SMichael Roth * 134bbf5c878SMichael Roth * unusable: mark device as unavailable to OS 135bbf5c878SMichael Roth * usable: mark device as available to OS 136bbf5c878SMichael Roth * exchange: (currently unused) 137bbf5c878SMichael Roth * recover: (currently unused) 138bbf5c878SMichael Roth */ 139bbf5c878SMichael Roth typedef enum { 140bbf5c878SMichael Roth SPAPR_DR_ALLOCATION_STATE_UNUSABLE = 0, 141bbf5c878SMichael Roth SPAPR_DR_ALLOCATION_STATE_USABLE = 1, 142bbf5c878SMichael Roth SPAPR_DR_ALLOCATION_STATE_EXCHANGE = 2, 143bbf5c878SMichael Roth SPAPR_DR_ALLOCATION_STATE_RECOVER = 3 144ce2918cbSDavid Gibson } SpaprDRAllocationState; 145bbf5c878SMichael Roth 146bbf5c878SMichael Roth /* 147cd74d27eSDavid Gibson * DR-indicator (LED/visual indicator) 148bbf5c878SMichael Roth * 149bbf5c878SMichael Roth * set via set-indicator RTAS calls 150bbf5c878SMichael Roth * as documented by PAPR+ 2.7 13.5.3.4, Table 177, 151bbf5c878SMichael Roth * and PAPR+ 2.7 13.5.4.1, Table 180 152bbf5c878SMichael Roth * 153bbf5c878SMichael Roth * inactive: hotpluggable entity inactive and safely removable 154bbf5c878SMichael Roth * active: hotpluggable entity in use and not safely removable 155bbf5c878SMichael Roth * identify: (currently unused) 156bbf5c878SMichael Roth * action: (currently unused) 157bbf5c878SMichael Roth */ 158bbf5c878SMichael Roth typedef enum { 159cd74d27eSDavid Gibson SPAPR_DR_INDICATOR_INACTIVE = 0, 160cd74d27eSDavid Gibson SPAPR_DR_INDICATOR_ACTIVE = 1, 161cd74d27eSDavid Gibson SPAPR_DR_INDICATOR_IDENTIFY = 2, 162cd74d27eSDavid Gibson SPAPR_DR_INDICATOR_ACTION = 3, 163ce2918cbSDavid Gibson } SpaprDRIndicatorState; 164bbf5c878SMichael Roth 165bbf5c878SMichael Roth /* 166bbf5c878SMichael Roth * returned via get-sensor-state RTAS calls 167bbf5c878SMichael Roth * as documented by PAPR+ 2.7 13.5.3.3, Table 175: 168bbf5c878SMichael Roth * 169bbf5c878SMichael Roth * empty: connector slot empty (e.g. empty hotpluggable PCI slot) 170bbf5c878SMichael Roth * present: connector slot populated and device available to OS 171bbf5c878SMichael Roth * unusable: device not currently available to OS 172bbf5c878SMichael Roth * exchange: (currently unused) 173bbf5c878SMichael Roth * recover: (currently unused) 174bbf5c878SMichael Roth */ 175bbf5c878SMichael Roth typedef enum { 176bbf5c878SMichael Roth SPAPR_DR_ENTITY_SENSE_EMPTY = 0, 177bbf5c878SMichael Roth SPAPR_DR_ENTITY_SENSE_PRESENT = 1, 178bbf5c878SMichael Roth SPAPR_DR_ENTITY_SENSE_UNUSABLE = 2, 179bbf5c878SMichael Roth SPAPR_DR_ENTITY_SENSE_EXCHANGE = 3, 180bbf5c878SMichael Roth SPAPR_DR_ENTITY_SENSE_RECOVER = 4, 181ce2918cbSDavid Gibson } SpaprDREntitySense; 182bbf5c878SMichael Roth 183bbf5c878SMichael Roth typedef enum { 184bbf5c878SMichael Roth SPAPR_DR_CC_RESPONSE_NEXT_SIB = 1, /* currently unused */ 185bbf5c878SMichael Roth SPAPR_DR_CC_RESPONSE_NEXT_CHILD = 2, 186bbf5c878SMichael Roth SPAPR_DR_CC_RESPONSE_NEXT_PROPERTY = 3, 187bbf5c878SMichael Roth SPAPR_DR_CC_RESPONSE_PREV_PARENT = 4, 188bbf5c878SMichael Roth SPAPR_DR_CC_RESPONSE_SUCCESS = 0, 189bbf5c878SMichael Roth SPAPR_DR_CC_RESPONSE_ERROR = -1, 190bbf5c878SMichael Roth SPAPR_DR_CC_RESPONSE_CONTINUE = -2, 191e6fc9568SBharata B Rao SPAPR_DR_CC_RESPONSE_NOT_CONFIGURABLE = -9003, 192ce2918cbSDavid Gibson } SpaprDRCCResponse; 193bbf5c878SMichael Roth 1949d4c0f4fSDavid Gibson typedef enum { 1959d4c0f4fSDavid Gibson /* 1969d4c0f4fSDavid Gibson * Values come from Fig. 12 in LoPAPR section 13.4 1979d4c0f4fSDavid Gibson * 1989d4c0f4fSDavid Gibson * These are exposed in the migration stream, so don't change 1999d4c0f4fSDavid Gibson * them. 2009d4c0f4fSDavid Gibson */ 2019d4c0f4fSDavid Gibson SPAPR_DRC_STATE_INVALID = 0, 2029d4c0f4fSDavid Gibson SPAPR_DRC_STATE_LOGICAL_UNUSABLE = 1, 2039d4c0f4fSDavid Gibson SPAPR_DRC_STATE_LOGICAL_AVAILABLE = 2, 2049d4c0f4fSDavid Gibson SPAPR_DRC_STATE_LOGICAL_UNISOLATE = 3, 2059d4c0f4fSDavid Gibson SPAPR_DRC_STATE_LOGICAL_CONFIGURED = 4, 2069d4c0f4fSDavid Gibson SPAPR_DRC_STATE_PHYSICAL_AVAILABLE = 5, 2079d4c0f4fSDavid Gibson SPAPR_DRC_STATE_PHYSICAL_POWERON = 6, 2089d4c0f4fSDavid Gibson SPAPR_DRC_STATE_PHYSICAL_UNISOLATE = 7, 2099d4c0f4fSDavid Gibson SPAPR_DRC_STATE_PHYSICAL_CONFIGURED = 8, 210ce2918cbSDavid Gibson } SpaprDrcState; 2119d4c0f4fSDavid Gibson 212ce2918cbSDavid Gibson typedef struct SpaprDrc { 213bbf5c878SMichael Roth /*< private >*/ 214bbf5c878SMichael Roth DeviceState parent; 215bbf5c878SMichael Roth 216bbf5c878SMichael Roth uint32_t id; 217bbf5c878SMichael Roth Object *owner; 218bbf5c878SMichael Roth 2199d4c0f4fSDavid Gibson uint32_t state; 220bbf5c878SMichael Roth 2214445b1d2SDavid Gibson /* RTAS ibm,configure-connector state */ 2224445b1d2SDavid Gibson /* (only valid in UNISOLATE state) */ 2234445b1d2SDavid Gibson int ccs_offset; 2244445b1d2SDavid Gibson int ccs_depth; 225bbf5c878SMichael Roth 226bbf5c878SMichael Roth /* device pointer, via link property */ 227bbf5c878SMichael Roth DeviceState *dev; 228f1c52354SDavid Gibson bool unplug_requested; 2294445b1d2SDavid Gibson void *fdt; 2304445b1d2SDavid Gibson int fdt_start_offset; 231ce2918cbSDavid Gibson } SpaprDrc; 232bbf5c878SMichael Roth 233ce2918cbSDavid Gibson struct SpaprMachineState; 234d9c95c71SGreg Kurz 235ce2918cbSDavid Gibson typedef struct SpaprDrcClass { 236bbf5c878SMichael Roth /*< private >*/ 237bbf5c878SMichael Roth DeviceClass parent; 238ce2918cbSDavid Gibson SpaprDrcState empty_state; 239ce2918cbSDavid Gibson SpaprDrcState ready_state; 240bbf5c878SMichael Roth 241bbf5c878SMichael Roth /*< public >*/ 242ce2918cbSDavid Gibson SpaprDrcTypeShift typeshift; 2431693ea16SDavid Gibson const char *typename; /* used in device tree, PAPR 13.5.2.6 & C.6.1 */ 24479808336SDavid Gibson const char *drc_name_prefix; /* used other places in device tree */ 245bbf5c878SMichael Roth 246ce2918cbSDavid Gibson SpaprDREntitySense (*dr_entity_sense)(SpaprDrc *drc); 247ce2918cbSDavid Gibson uint32_t (*isolate)(SpaprDrc *drc); 248ce2918cbSDavid Gibson uint32_t (*unisolate)(SpaprDrc *drc); 2496b762f29SDavid Gibson void (*release)(DeviceState *dev); 250d9c95c71SGreg Kurz 251ce2918cbSDavid Gibson int (*dt_populate)(SpaprDrc *drc, struct SpaprMachineState *spapr, 252d9c95c71SGreg Kurz void *fdt, int *fdt_start_offset, Error **errp); 253ce2918cbSDavid Gibson } SpaprDrcClass; 254bbf5c878SMichael Roth 255ce2918cbSDavid Gibson typedef struct SpaprDrcPhysical { 25667fea71bSDavid Gibson /*< private >*/ 257ce2918cbSDavid Gibson SpaprDrc parent; 25867fea71bSDavid Gibson 25967fea71bSDavid Gibson /* DR-indicator */ 26067fea71bSDavid Gibson uint32_t dr_indicator; 261ce2918cbSDavid Gibson } SpaprDrcPhysical; 26267fea71bSDavid Gibson 26394fd9cbaSLaurent Vivier static inline bool spapr_drc_hotplugged(DeviceState *dev) 26494fd9cbaSLaurent Vivier { 26594fd9cbaSLaurent Vivier return dev->hotplugged && !runstate_check(RUN_STATE_INMIGRATE); 26694fd9cbaSLaurent Vivier } 26794fd9cbaSLaurent Vivier 268ce2918cbSDavid Gibson void spapr_drc_reset(SpaprDrc *drc); 26994fd9cbaSLaurent Vivier 270ce2918cbSDavid Gibson uint32_t spapr_drc_index(SpaprDrc *drc); 271ce2918cbSDavid Gibson SpaprDrcType spapr_drc_type(SpaprDrc *drc); 2720b55aa91SDavid Gibson 273ce2918cbSDavid Gibson SpaprDrc *spapr_dr_connector_new(Object *owner, const char *type, 274bbf5c878SMichael Roth uint32_t id); 275ce2918cbSDavid Gibson SpaprDrc *spapr_drc_by_index(uint32_t index); 276ce2918cbSDavid Gibson SpaprDrc *spapr_drc_by_id(const char *type, uint32_t id); 2779e7d38e8SDavid Gibson int spapr_dt_drc(void *fdt, int offset, Object *owner, uint32_t drc_type_mask); 278bbf5c878SMichael Roth 279ce2918cbSDavid Gibson void spapr_drc_attach(SpaprDrc *drc, DeviceState *d, Error **errp); 280ce2918cbSDavid Gibson void spapr_drc_detach(SpaprDrc *drc); 28110f12e64SDaniel Henrique Barboza bool spapr_drc_needed(void *opaque); 2820be4e886SDavid Gibson 283ce2918cbSDavid Gibson static inline bool spapr_drc_unplug_requested(SpaprDrc *drc) 284f1c52354SDavid Gibson { 285f1c52354SDavid Gibson return drc->unplug_requested; 286f1c52354SDavid Gibson } 287f1c52354SDavid Gibson 2882a6a4076SMarkus Armbruster #endif /* HW_SPAPR_DRC_H */ 289