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" 1894fd9cbaSLaurent Vivier #include "sysemu/sysemu.h" 19bbf5c878SMichael Roth #include "hw/qdev.h" 20bbf5c878SMichael Roth 21bbf5c878SMichael Roth #define TYPE_SPAPR_DR_CONNECTOR "spapr-dr-connector" 22bbf5c878SMichael Roth #define SPAPR_DR_CONNECTOR_GET_CLASS(obj) \ 23bbf5c878SMichael Roth OBJECT_GET_CLASS(sPAPRDRConnectorClass, obj, TYPE_SPAPR_DR_CONNECTOR) 24bbf5c878SMichael Roth #define SPAPR_DR_CONNECTOR_CLASS(klass) \ 25bbf5c878SMichael Roth OBJECT_CLASS_CHECK(sPAPRDRConnectorClass, klass, \ 26bbf5c878SMichael Roth TYPE_SPAPR_DR_CONNECTOR) 27bbf5c878SMichael Roth #define SPAPR_DR_CONNECTOR(obj) OBJECT_CHECK(sPAPRDRConnector, (obj), \ 28bbf5c878SMichael Roth TYPE_SPAPR_DR_CONNECTOR) 29bbf5c878SMichael Roth 302d335818SDavid Gibson #define TYPE_SPAPR_DRC_PHYSICAL "spapr-drc-physical" 312d335818SDavid Gibson #define SPAPR_DRC_PHYSICAL_GET_CLASS(obj) \ 322d335818SDavid Gibson OBJECT_GET_CLASS(sPAPRDRConnectorClass, obj, TYPE_SPAPR_DRC_PHYSICAL) 332d335818SDavid Gibson #define SPAPR_DRC_PHYSICAL_CLASS(klass) \ 342d335818SDavid Gibson OBJECT_CLASS_CHECK(sPAPRDRConnectorClass, klass, \ 352d335818SDavid Gibson TYPE_SPAPR_DRC_PHYSICAL) 362d335818SDavid Gibson #define SPAPR_DRC_PHYSICAL(obj) OBJECT_CHECK(sPAPRDRConnector, (obj), \ 372d335818SDavid Gibson TYPE_SPAPR_DRC_PHYSICAL) 382d335818SDavid Gibson 392d335818SDavid Gibson #define TYPE_SPAPR_DRC_LOGICAL "spapr-drc-logical" 402d335818SDavid Gibson #define SPAPR_DRC_LOGICAL_GET_CLASS(obj) \ 412d335818SDavid Gibson OBJECT_GET_CLASS(sPAPRDRConnectorClass, obj, TYPE_SPAPR_DRC_LOGICAL) 422d335818SDavid Gibson #define SPAPR_DRC_LOGICAL_CLASS(klass) \ 432d335818SDavid Gibson OBJECT_CLASS_CHECK(sPAPRDRConnectorClass, klass, \ 442d335818SDavid Gibson TYPE_SPAPR_DRC_LOGICAL) 452d335818SDavid Gibson #define SPAPR_DRC_LOGICAL(obj) OBJECT_CHECK(sPAPRDRConnector, (obj), \ 462d335818SDavid Gibson TYPE_SPAPR_DRC_LOGICAL) 472d335818SDavid Gibson 482d335818SDavid Gibson #define TYPE_SPAPR_DRC_CPU "spapr-drc-cpu" 492d335818SDavid Gibson #define SPAPR_DRC_CPU_GET_CLASS(obj) \ 502d335818SDavid Gibson OBJECT_GET_CLASS(sPAPRDRConnectorClass, obj, TYPE_SPAPR_DRC_CPU) 512d335818SDavid Gibson #define SPAPR_DRC_CPU_CLASS(klass) \ 522d335818SDavid Gibson OBJECT_CLASS_CHECK(sPAPRDRConnectorClass, klass, TYPE_SPAPR_DRC_CPU) 532d335818SDavid Gibson #define SPAPR_DRC_CPU(obj) OBJECT_CHECK(sPAPRDRConnector, (obj), \ 542d335818SDavid Gibson TYPE_SPAPR_DRC_CPU) 552d335818SDavid Gibson 562d335818SDavid Gibson #define TYPE_SPAPR_DRC_PCI "spapr-drc-pci" 572d335818SDavid Gibson #define SPAPR_DRC_PCI_GET_CLASS(obj) \ 582d335818SDavid Gibson OBJECT_GET_CLASS(sPAPRDRConnectorClass, obj, TYPE_SPAPR_DRC_PCI) 592d335818SDavid Gibson #define SPAPR_DRC_PCI_CLASS(klass) \ 602d335818SDavid Gibson OBJECT_CLASS_CHECK(sPAPRDRConnectorClass, klass, TYPE_SPAPR_DRC_PCI) 612d335818SDavid Gibson #define SPAPR_DRC_PCI(obj) OBJECT_CHECK(sPAPRDRConnector, (obj), \ 622d335818SDavid Gibson TYPE_SPAPR_DRC_PCI) 632d335818SDavid Gibson 642d335818SDavid Gibson #define TYPE_SPAPR_DRC_LMB "spapr-drc-lmb" 652d335818SDavid Gibson #define SPAPR_DRC_LMB_GET_CLASS(obj) \ 662d335818SDavid Gibson OBJECT_GET_CLASS(sPAPRDRConnectorClass, obj, TYPE_SPAPR_DRC_LMB) 672d335818SDavid Gibson #define SPAPR_DRC_LMB_CLASS(klass) \ 682d335818SDavid Gibson OBJECT_CLASS_CHECK(sPAPRDRConnectorClass, klass, TYPE_SPAPR_DRC_LMB) 692d335818SDavid Gibson #define SPAPR_DRC_LMB(obj) OBJECT_CHECK(sPAPRDRConnector, (obj), \ 702d335818SDavid Gibson TYPE_SPAPR_DRC_LMB) 712d335818SDavid Gibson 72bbf5c878SMichael Roth /* 73bbf5c878SMichael Roth * Various hotplug types managed by sPAPRDRConnector 74bbf5c878SMichael Roth * 75bbf5c878SMichael Roth * these are somewhat arbitrary, but to make things easier 76bbf5c878SMichael Roth * when generating DRC indexes later we've aligned the bit 77bbf5c878SMichael Roth * positions with the values used to assign DRC indexes on 78bbf5c878SMichael Roth * pSeries. we use those values as bit shifts to allow for 79bbf5c878SMichael Roth * the OR'ing of these values in various QEMU routines, but 80bbf5c878SMichael Roth * for values exposed to the guest (via DRC indexes for 81bbf5c878SMichael Roth * instance) we will use the shift amounts. 82bbf5c878SMichael Roth */ 83bbf5c878SMichael Roth typedef enum { 84bbf5c878SMichael Roth SPAPR_DR_CONNECTOR_TYPE_SHIFT_CPU = 1, 85bbf5c878SMichael Roth SPAPR_DR_CONNECTOR_TYPE_SHIFT_PHB = 2, 86bbf5c878SMichael Roth SPAPR_DR_CONNECTOR_TYPE_SHIFT_VIO = 3, 87bbf5c878SMichael Roth SPAPR_DR_CONNECTOR_TYPE_SHIFT_PCI = 4, 88bbf5c878SMichael Roth SPAPR_DR_CONNECTOR_TYPE_SHIFT_LMB = 8, 89bbf5c878SMichael Roth } sPAPRDRConnectorTypeShift; 90bbf5c878SMichael Roth 91bbf5c878SMichael Roth typedef enum { 92bbf5c878SMichael Roth SPAPR_DR_CONNECTOR_TYPE_ANY = ~0, 93bbf5c878SMichael Roth SPAPR_DR_CONNECTOR_TYPE_CPU = 1 << SPAPR_DR_CONNECTOR_TYPE_SHIFT_CPU, 94bbf5c878SMichael Roth SPAPR_DR_CONNECTOR_TYPE_PHB = 1 << SPAPR_DR_CONNECTOR_TYPE_SHIFT_PHB, 95bbf5c878SMichael Roth SPAPR_DR_CONNECTOR_TYPE_VIO = 1 << SPAPR_DR_CONNECTOR_TYPE_SHIFT_VIO, 96bbf5c878SMichael Roth SPAPR_DR_CONNECTOR_TYPE_PCI = 1 << SPAPR_DR_CONNECTOR_TYPE_SHIFT_PCI, 97bbf5c878SMichael Roth SPAPR_DR_CONNECTOR_TYPE_LMB = 1 << SPAPR_DR_CONNECTOR_TYPE_SHIFT_LMB, 98bbf5c878SMichael Roth } sPAPRDRConnectorType; 99bbf5c878SMichael Roth 100bbf5c878SMichael Roth /* 101bbf5c878SMichael Roth * set via set-indicator RTAS calls 102bbf5c878SMichael Roth * as documented by PAPR+ 2.7 13.5.3.4, Table 177 103bbf5c878SMichael Roth * 104bbf5c878SMichael Roth * isolated: put device under firmware control 105bbf5c878SMichael Roth * unisolated: claim OS control of device (may or may not be in use) 106bbf5c878SMichael Roth */ 107bbf5c878SMichael Roth typedef enum { 108bbf5c878SMichael Roth SPAPR_DR_ISOLATION_STATE_ISOLATED = 0, 109bbf5c878SMichael Roth SPAPR_DR_ISOLATION_STATE_UNISOLATED = 1 110bbf5c878SMichael Roth } sPAPRDRIsolationState; 111bbf5c878SMichael Roth 112bbf5c878SMichael Roth /* 113bbf5c878SMichael Roth * set via set-indicator RTAS calls 114bbf5c878SMichael Roth * as documented by PAPR+ 2.7 13.5.3.4, Table 177 115bbf5c878SMichael Roth * 116bbf5c878SMichael Roth * unusable: mark device as unavailable to OS 117bbf5c878SMichael Roth * usable: mark device as available to OS 118bbf5c878SMichael Roth * exchange: (currently unused) 119bbf5c878SMichael Roth * recover: (currently unused) 120bbf5c878SMichael Roth */ 121bbf5c878SMichael Roth typedef enum { 122bbf5c878SMichael Roth SPAPR_DR_ALLOCATION_STATE_UNUSABLE = 0, 123bbf5c878SMichael Roth SPAPR_DR_ALLOCATION_STATE_USABLE = 1, 124bbf5c878SMichael Roth SPAPR_DR_ALLOCATION_STATE_EXCHANGE = 2, 125bbf5c878SMichael Roth SPAPR_DR_ALLOCATION_STATE_RECOVER = 3 126bbf5c878SMichael Roth } sPAPRDRAllocationState; 127bbf5c878SMichael Roth 128bbf5c878SMichael Roth /* 129cd74d27eSDavid Gibson * DR-indicator (LED/visual indicator) 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 * and PAPR+ 2.7 13.5.4.1, Table 180 134bbf5c878SMichael Roth * 135bbf5c878SMichael Roth * inactive: hotpluggable entity inactive and safely removable 136bbf5c878SMichael Roth * active: hotpluggable entity in use and not safely removable 137bbf5c878SMichael Roth * identify: (currently unused) 138bbf5c878SMichael Roth * action: (currently unused) 139bbf5c878SMichael Roth */ 140bbf5c878SMichael Roth typedef enum { 141cd74d27eSDavid Gibson SPAPR_DR_INDICATOR_INACTIVE = 0, 142cd74d27eSDavid Gibson SPAPR_DR_INDICATOR_ACTIVE = 1, 143cd74d27eSDavid Gibson SPAPR_DR_INDICATOR_IDENTIFY = 2, 144cd74d27eSDavid Gibson SPAPR_DR_INDICATOR_ACTION = 3, 145bbf5c878SMichael Roth } sPAPRDRIndicatorState; 146bbf5c878SMichael Roth 147bbf5c878SMichael Roth /* 148bbf5c878SMichael Roth * returned via get-sensor-state RTAS calls 149bbf5c878SMichael Roth * as documented by PAPR+ 2.7 13.5.3.3, Table 175: 150bbf5c878SMichael Roth * 151bbf5c878SMichael Roth * empty: connector slot empty (e.g. empty hotpluggable PCI slot) 152bbf5c878SMichael Roth * present: connector slot populated and device available to OS 153bbf5c878SMichael Roth * unusable: device not currently available to OS 154bbf5c878SMichael Roth * exchange: (currently unused) 155bbf5c878SMichael Roth * recover: (currently unused) 156bbf5c878SMichael Roth */ 157bbf5c878SMichael Roth typedef enum { 158bbf5c878SMichael Roth SPAPR_DR_ENTITY_SENSE_EMPTY = 0, 159bbf5c878SMichael Roth SPAPR_DR_ENTITY_SENSE_PRESENT = 1, 160bbf5c878SMichael Roth SPAPR_DR_ENTITY_SENSE_UNUSABLE = 2, 161bbf5c878SMichael Roth SPAPR_DR_ENTITY_SENSE_EXCHANGE = 3, 162bbf5c878SMichael Roth SPAPR_DR_ENTITY_SENSE_RECOVER = 4, 163bbf5c878SMichael Roth } sPAPRDREntitySense; 164bbf5c878SMichael Roth 165bbf5c878SMichael Roth typedef enum { 166bbf5c878SMichael Roth SPAPR_DR_CC_RESPONSE_NEXT_SIB = 1, /* currently unused */ 167bbf5c878SMichael Roth SPAPR_DR_CC_RESPONSE_NEXT_CHILD = 2, 168bbf5c878SMichael Roth SPAPR_DR_CC_RESPONSE_NEXT_PROPERTY = 3, 169bbf5c878SMichael Roth SPAPR_DR_CC_RESPONSE_PREV_PARENT = 4, 170bbf5c878SMichael Roth SPAPR_DR_CC_RESPONSE_SUCCESS = 0, 171bbf5c878SMichael Roth SPAPR_DR_CC_RESPONSE_ERROR = -1, 172bbf5c878SMichael Roth SPAPR_DR_CC_RESPONSE_CONTINUE = -2, 173e6fc9568SBharata B Rao SPAPR_DR_CC_RESPONSE_NOT_CONFIGURABLE = -9003, 174bbf5c878SMichael Roth } sPAPRDRCCResponse; 175bbf5c878SMichael Roth 1769d4c0f4fSDavid Gibson typedef enum { 1779d4c0f4fSDavid Gibson /* 1789d4c0f4fSDavid Gibson * Values come from Fig. 12 in LoPAPR section 13.4 1799d4c0f4fSDavid Gibson * 1809d4c0f4fSDavid Gibson * These are exposed in the migration stream, so don't change 1819d4c0f4fSDavid Gibson * them. 1829d4c0f4fSDavid Gibson */ 1839d4c0f4fSDavid Gibson SPAPR_DRC_STATE_INVALID = 0, 1849d4c0f4fSDavid Gibson SPAPR_DRC_STATE_LOGICAL_UNUSABLE = 1, 1859d4c0f4fSDavid Gibson SPAPR_DRC_STATE_LOGICAL_AVAILABLE = 2, 1869d4c0f4fSDavid Gibson SPAPR_DRC_STATE_LOGICAL_UNISOLATE = 3, 1879d4c0f4fSDavid Gibson SPAPR_DRC_STATE_LOGICAL_CONFIGURED = 4, 1889d4c0f4fSDavid Gibson SPAPR_DRC_STATE_PHYSICAL_AVAILABLE = 5, 1899d4c0f4fSDavid Gibson SPAPR_DRC_STATE_PHYSICAL_POWERON = 6, 1909d4c0f4fSDavid Gibson SPAPR_DRC_STATE_PHYSICAL_UNISOLATE = 7, 1919d4c0f4fSDavid Gibson SPAPR_DRC_STATE_PHYSICAL_CONFIGURED = 8, 1929d4c0f4fSDavid Gibson } sPAPRDRCState; 1939d4c0f4fSDavid Gibson 194bbf5c878SMichael Roth typedef struct sPAPRDRConnector { 195bbf5c878SMichael Roth /*< private >*/ 196bbf5c878SMichael Roth DeviceState parent; 197bbf5c878SMichael Roth 198bbf5c878SMichael Roth uint32_t id; 199bbf5c878SMichael Roth Object *owner; 200bbf5c878SMichael Roth 201cd74d27eSDavid Gibson /* DR-indicator */ 202cd74d27eSDavid Gibson uint32_t dr_indicator; 203cd74d27eSDavid Gibson 2049d4c0f4fSDavid Gibson uint32_t state; 205bbf5c878SMichael Roth 206*4445b1d2SDavid Gibson /* RTAS ibm,configure-connector state */ 207*4445b1d2SDavid Gibson /* (only valid in UNISOLATE state) */ 208*4445b1d2SDavid Gibson int ccs_offset; 209*4445b1d2SDavid Gibson int ccs_depth; 210bbf5c878SMichael Roth 211bbf5c878SMichael Roth /* device pointer, via link property */ 212bbf5c878SMichael Roth DeviceState *dev; 213f1c52354SDavid Gibson bool unplug_requested; 214*4445b1d2SDavid Gibson void *fdt; 215*4445b1d2SDavid Gibson int fdt_start_offset; 216bbf5c878SMichael Roth } sPAPRDRConnector; 217bbf5c878SMichael Roth 218bbf5c878SMichael Roth typedef struct sPAPRDRConnectorClass { 219bbf5c878SMichael Roth /*< private >*/ 220bbf5c878SMichael Roth DeviceClass parent; 2219d4c0f4fSDavid Gibson sPAPRDRCState empty_state; 2229d4c0f4fSDavid Gibson sPAPRDRCState ready_state; 223bbf5c878SMichael Roth 224bbf5c878SMichael Roth /*< public >*/ 2252d335818SDavid Gibson sPAPRDRConnectorTypeShift typeshift; 2261693ea16SDavid Gibson const char *typename; /* used in device tree, PAPR 13.5.2.6 & C.6.1 */ 22779808336SDavid Gibson const char *drc_name_prefix; /* used other places in device tree */ 228bbf5c878SMichael Roth 229f224d35bSDavid Gibson sPAPRDREntitySense (*dr_entity_sense)(sPAPRDRConnector *drc); 2300dfabd39SDavid Gibson uint32_t (*isolate)(sPAPRDRConnector *drc); 2310dfabd39SDavid Gibson uint32_t (*unisolate)(sPAPRDRConnector *drc); 2326b762f29SDavid Gibson void (*release)(DeviceState *dev); 233bbf5c878SMichael Roth } sPAPRDRConnectorClass; 234bbf5c878SMichael Roth 23594fd9cbaSLaurent Vivier static inline bool spapr_drc_hotplugged(DeviceState *dev) 23694fd9cbaSLaurent Vivier { 23794fd9cbaSLaurent Vivier return dev->hotplugged && !runstate_check(RUN_STATE_INMIGRATE); 23894fd9cbaSLaurent Vivier } 23994fd9cbaSLaurent Vivier 24094fd9cbaSLaurent Vivier void spapr_drc_reset(sPAPRDRConnector *drc); 24194fd9cbaSLaurent Vivier 2420b55aa91SDavid Gibson uint32_t spapr_drc_index(sPAPRDRConnector *drc); 2430b55aa91SDavid Gibson sPAPRDRConnectorType spapr_drc_type(sPAPRDRConnector *drc); 2440b55aa91SDavid Gibson 2452d335818SDavid Gibson sPAPRDRConnector *spapr_dr_connector_new(Object *owner, const char *type, 246bbf5c878SMichael Roth uint32_t id); 247fbf55397SDavid Gibson sPAPRDRConnector *spapr_drc_by_index(uint32_t index); 248fbf55397SDavid Gibson sPAPRDRConnector *spapr_drc_by_id(const char *type, uint32_t id); 249e4b798bbSMichael Roth int spapr_drc_populate_dt(void *fdt, int fdt_offset, Object *owner, 250e4b798bbSMichael Roth uint32_t drc_type_mask); 251bbf5c878SMichael Roth 2520be4e886SDavid Gibson void spapr_drc_attach(sPAPRDRConnector *drc, DeviceState *d, void *fdt, 2535c1da812SDavid Gibson int fdt_start_offset, Error **errp); 254a8dc47fdSDavid Gibson void spapr_drc_detach(sPAPRDRConnector *drc); 2550be4e886SDavid Gibson 256f1c52354SDavid Gibson static inline bool spapr_drc_unplug_requested(sPAPRDRConnector *drc) 257f1c52354SDavid Gibson { 258f1c52354SDavid Gibson return drc->unplug_requested; 259f1c52354SDavid Gibson } 260f1c52354SDavid Gibson 2612a6a4076SMarkus Armbruster #endif /* HW_SPAPR_DRC_H */ 262