1f6c98f92SHeinz Graalfs /* 2f6c98f92SHeinz Graalfs * SCLP Support 3f6c98f92SHeinz Graalfs * 4f6c98f92SHeinz Graalfs * Copyright IBM, Corp. 2012 5f6c98f92SHeinz Graalfs * 6f6c98f92SHeinz Graalfs * Authors: 7f6c98f92SHeinz Graalfs * Christian Borntraeger <borntraeger@de.ibm.com> 8f6c98f92SHeinz Graalfs * 9f6c98f92SHeinz Graalfs * This work is licensed under the terms of the GNU GPL, version 2 or (at your 10f6c98f92SHeinz Graalfs * option) any later version. See the COPYING file in the top-level directory. 11f6c98f92SHeinz Graalfs * 12f6c98f92SHeinz Graalfs */ 13f6c98f92SHeinz Graalfs 14f6c98f92SHeinz Graalfs #ifndef HW_S390_SCLP_H 15f6c98f92SHeinz Graalfs #define HW_S390_SCLP_H 16f6c98f92SHeinz Graalfs 17a9c94277SMarkus Armbruster #include "hw/sysbus.h" 18a9c94277SMarkus Armbruster #include "hw/qdev.h" 19*53d8e91dSDavid Hildenbrand #include "target/s390x/cpu-qom.h" 20f6c98f92SHeinz Graalfs 215f04c14aSJason J. Herne #define SCLP_CMD_CODE_MASK 0xffff00ff 225f04c14aSJason J. Herne 23f6c98f92SHeinz Graalfs /* SCLP command codes */ 24f6c98f92SHeinz Graalfs #define SCLP_CMDW_READ_SCP_INFO 0x00020001 25f6c98f92SHeinz Graalfs #define SCLP_CMDW_READ_SCP_INFO_FORCED 0x00120001 26234eef51SMatthew Rosato #define SCLP_READ_STORAGE_ELEMENT_INFO 0x00040001 27234eef51SMatthew Rosato #define SCLP_ATTACH_STORAGE_ELEMENT 0x00080001 28234eef51SMatthew Rosato #define SCLP_ASSIGN_STORAGE 0x000D0001 29234eef51SMatthew Rosato #define SCLP_UNASSIGN_STORAGE 0x000C0001 30559a17a1SHeinz Graalfs #define SCLP_CMD_READ_EVENT_DATA 0x00770005 31559a17a1SHeinz Graalfs #define SCLP_CMD_WRITE_EVENT_DATA 0x00760005 32559a17a1SHeinz Graalfs #define SCLP_CMD_WRITE_EVENT_MASK 0x00780005 33f6c98f92SHeinz Graalfs 34234eef51SMatthew Rosato /* SCLP Memory hotplug codes */ 35234eef51SMatthew Rosato #define SCLP_FC_ASSIGN_ATTACH_READ_STOR 0xE00000000000ULL 36234eef51SMatthew Rosato #define SCLP_STARTING_SUBINCREMENT_ID 0x10001 37234eef51SMatthew Rosato #define SCLP_INCREMENT_UNIT 0x10000 38234eef51SMatthew Rosato #define MAX_AVAIL_SLOTS 32 390844df77SMatthew Rosato #define MAX_STORAGE_INCREMENTS 1020 40234eef51SMatthew Rosato 415f04c14aSJason J. Herne /* CPU hotplug SCLP codes */ 425f04c14aSJason J. Herne #define SCLP_HAS_CPU_INFO 0x0C00000000000000ULL 435f04c14aSJason J. Herne #define SCLP_CMDW_READ_CPU_INFO 0x00010001 445f04c14aSJason J. Herne #define SCLP_CMDW_CONFIGURE_CPU 0x00110001 455f04c14aSJason J. Herne #define SCLP_CMDW_DECONFIGURE_CPU 0x00100001 465f04c14aSJason J. Herne 478cba80c3SFrank Blaschka /* SCLP PCI codes */ 4880b7a265SCornelia Huck #define SCLP_HAS_IOA_RECONFIG 0x0000000040000000ULL 4980b7a265SCornelia Huck #define SCLP_CMDW_CONFIGURE_IOA 0x001a0001 5080b7a265SCornelia Huck #define SCLP_CMDW_DECONFIGURE_IOA 0x001b0001 5180b7a265SCornelia Huck #define SCLP_RECONFIG_PCI_ATYPE 2 528cba80c3SFrank Blaschka 53f6c98f92SHeinz Graalfs /* SCLP response codes */ 54f6c98f92SHeinz Graalfs #define SCLP_RC_NORMAL_READ_COMPLETION 0x0010 55559a17a1SHeinz Graalfs #define SCLP_RC_NORMAL_COMPLETION 0x0020 56234eef51SMatthew Rosato #define SCLP_RC_SCCB_BOUNDARY_VIOLATION 0x0100 578cba80c3SFrank Blaschka #define SCLP_RC_NO_ACTION_REQUIRED 0x0120 58f6c98f92SHeinz Graalfs #define SCLP_RC_INVALID_SCLP_COMMAND 0x01f0 59559a17a1SHeinz Graalfs #define SCLP_RC_CONTAINED_EQUIPMENT_CHECK 0x0340 60559a17a1SHeinz Graalfs #define SCLP_RC_INSUFFICIENT_SCCB_LENGTH 0x0300 61234eef51SMatthew Rosato #define SCLP_RC_STANDBY_READ_COMPLETION 0x0410 625d1abf23SYi Min Zhao #define SCLP_RC_ADAPTER_IN_RESERVED_STATE 0x05f0 635838d657SCornelia Huck #define SCLP_RC_ADAPTER_TYPE_NOT_RECOGNIZED 0x06f0 648cba80c3SFrank Blaschka #define SCLP_RC_ADAPTER_ID_NOT_RECOGNIZED 0x09f0 65559a17a1SHeinz Graalfs #define SCLP_RC_INVALID_FUNCTION 0x40f0 66559a17a1SHeinz Graalfs #define SCLP_RC_NO_EVENT_BUFFERS_STORED 0x60f0 67559a17a1SHeinz Graalfs #define SCLP_RC_INVALID_SELECTION_MASK 0x70f0 68559a17a1SHeinz Graalfs #define SCLP_RC_INCONSISTENT_LENGTHS 0x72f0 69559a17a1SHeinz Graalfs #define SCLP_RC_EVENT_BUFFER_SYNTAX_ERROR 0x73f0 70559a17a1SHeinz Graalfs #define SCLP_RC_INVALID_MASK_LENGTH 0x74f0 71559a17a1SHeinz Graalfs 72f6c98f92SHeinz Graalfs 73f6c98f92SHeinz Graalfs /* Service Call Control Block (SCCB) and its elements */ 74f6c98f92SHeinz Graalfs 75f6c98f92SHeinz Graalfs #define SCCB_SIZE 4096 76f6c98f92SHeinz Graalfs 77559a17a1SHeinz Graalfs #define SCLP_VARIABLE_LENGTH_RESPONSE 0x80 78559a17a1SHeinz Graalfs #define SCLP_EVENT_BUFFER_ACCEPTED 0x80 79559a17a1SHeinz Graalfs 80559a17a1SHeinz Graalfs #define SCLP_FC_NORMAL_WRITE 0 81559a17a1SHeinz Graalfs 82f6c98f92SHeinz Graalfs /* 83f6c98f92SHeinz Graalfs * Normally packed structures are not the right thing to do, since all code 848367a14fSStefan Weil * must take care of endianness. We cannot use ldl_phys and friends for two 85f6c98f92SHeinz Graalfs * reasons, though: 86f6c98f92SHeinz Graalfs * - some of the embedded structures below the SCCB can appear multiple times 87f6c98f92SHeinz Graalfs * at different locations, so there is no fixed offset 88f6c98f92SHeinz Graalfs * - we work on a private copy of the SCCB, since there are several length 89f6c98f92SHeinz Graalfs * fields, that would cause a security nightmare if we allow the guest to 90f6c98f92SHeinz Graalfs * alter the structure while we parse it. We cannot use ldl_p and friends 91f6c98f92SHeinz Graalfs * either without doing pointer arithmetics 92f6c98f92SHeinz Graalfs * So we have to double check that all users of sclp data structures use the 938367a14fSStefan Weil * right endianness wrappers. 94f6c98f92SHeinz Graalfs */ 95f6c98f92SHeinz Graalfs typedef struct SCCBHeader { 96f6c98f92SHeinz Graalfs uint16_t length; 97f6c98f92SHeinz Graalfs uint8_t function_code; 98f6c98f92SHeinz Graalfs uint8_t control_mask[3]; 99f6c98f92SHeinz Graalfs uint16_t response_code; 100f6c98f92SHeinz Graalfs } QEMU_PACKED SCCBHeader; 101f6c98f92SHeinz Graalfs 102f6c98f92SHeinz Graalfs #define SCCB_DATA_LEN (SCCB_SIZE - sizeof(SCCBHeader)) 1031c07e01bSDavid Hildenbrand #define SCCB_CPU_FEATURE_LEN 6 104f6c98f92SHeinz Graalfs 1058cc3aecfSJason J. Herne /* CPU information */ 1068cc3aecfSJason J. Herne typedef struct CPUEntry { 1078cc3aecfSJason J. Herne uint8_t address; 1081c07e01bSDavid Hildenbrand uint8_t reserved0; 1091c07e01bSDavid Hildenbrand uint8_t features[SCCB_CPU_FEATURE_LEN]; 1101c07e01bSDavid Hildenbrand uint8_t reserved2[6]; 1118cc3aecfSJason J. Herne uint8_t type; 1128cc3aecfSJason J. Herne uint8_t reserved1; 1138cc3aecfSJason J. Herne } QEMU_PACKED CPUEntry; 1148cc3aecfSJason J. Herne 115f6c98f92SHeinz Graalfs typedef struct ReadInfo { 116f6c98f92SHeinz Graalfs SCCBHeader h; 117f6c98f92SHeinz Graalfs uint16_t rnmax; 118f6c98f92SHeinz Graalfs uint8_t rnsize; 1198cc3aecfSJason J. Herne uint8_t _reserved1[16 - 11]; /* 11-15 */ 1208cc3aecfSJason J. Herne uint16_t entries_cpu; /* 16-17 */ 1218cc3aecfSJason J. Herne uint16_t offset_cpu; /* 18-19 */ 1228cc3aecfSJason J. Herne uint8_t _reserved2[24 - 20]; /* 20-23 */ 1238cc3aecfSJason J. Herne uint8_t loadparm[8]; /* 24-31 */ 1248cc3aecfSJason J. Herne uint8_t _reserved3[48 - 32]; /* 32-47 */ 1258cc3aecfSJason J. Herne uint64_t facilities; /* 48-55 */ 126059be520SDavid Hildenbrand uint8_t _reserved0[76 - 56]; /* 56-75 */ 127059be520SDavid Hildenbrand uint32_t ibc_val; 1286da5c593SJason J. Herne uint8_t conf_char[99 - 80]; /* 80-98 */ 1293fad3252SDavid Hildenbrand uint8_t mha_pow; 1308cc3aecfSJason J. Herne uint32_t rnsize2; 1318cc3aecfSJason J. Herne uint64_t rnmax2; 1321c07e01bSDavid Hildenbrand uint8_t _reserved6[116 - 112]; /* 112-115 */ 1331c07e01bSDavid Hildenbrand uint8_t conf_char_ext[120 - 116]; /* 116-119 */ 1348cc3aecfSJason J. Herne uint16_t highest_cpu; 135a3669307SDavid Hildenbrand uint8_t _reserved5[124 - 122]; /* 122-123 */ 136a3669307SDavid Hildenbrand uint32_t hmfai; 1378cc3aecfSJason J. Herne struct CPUEntry entries[0]; 138f6c98f92SHeinz Graalfs } QEMU_PACKED ReadInfo; 139f6c98f92SHeinz Graalfs 1408cc3aecfSJason J. Herne typedef struct ReadCpuInfo { 1418cc3aecfSJason J. Herne SCCBHeader h; 1428cc3aecfSJason J. Herne uint16_t nr_configured; /* 8-9 */ 1438cc3aecfSJason J. Herne uint16_t offset_configured; /* 10-11 */ 1448cc3aecfSJason J. Herne uint16_t nr_standby; /* 12-13 */ 1458cc3aecfSJason J. Herne uint16_t offset_standby; /* 14-15 */ 1468cc3aecfSJason J. Herne uint8_t reserved0[24-16]; /* 16-23 */ 1478cc3aecfSJason J. Herne struct CPUEntry entries[0]; 1488cc3aecfSJason J. Herne } QEMU_PACKED ReadCpuInfo; 1498cc3aecfSJason J. Herne 150234eef51SMatthew Rosato typedef struct ReadStorageElementInfo { 151234eef51SMatthew Rosato SCCBHeader h; 152234eef51SMatthew Rosato uint16_t max_id; 153234eef51SMatthew Rosato uint16_t assigned; 154234eef51SMatthew Rosato uint16_t standby; 155234eef51SMatthew Rosato uint8_t _reserved0[16 - 14]; /* 14-15 */ 156234eef51SMatthew Rosato uint32_t entries[0]; 157234eef51SMatthew Rosato } QEMU_PACKED ReadStorageElementInfo; 158234eef51SMatthew Rosato 159234eef51SMatthew Rosato typedef struct AttachStorageElement { 160234eef51SMatthew Rosato SCCBHeader h; 161234eef51SMatthew Rosato uint8_t _reserved0[10 - 8]; /* 8-9 */ 162234eef51SMatthew Rosato uint16_t assigned; 163234eef51SMatthew Rosato uint8_t _reserved1[16 - 12]; /* 12-15 */ 164234eef51SMatthew Rosato uint32_t entries[0]; 165234eef51SMatthew Rosato } QEMU_PACKED AttachStorageElement; 166234eef51SMatthew Rosato 167234eef51SMatthew Rosato typedef struct AssignStorage { 168234eef51SMatthew Rosato SCCBHeader h; 169234eef51SMatthew Rosato uint16_t rn; 170234eef51SMatthew Rosato } QEMU_PACKED AssignStorage; 171234eef51SMatthew Rosato 17280b7a265SCornelia Huck typedef struct IoaCfgSccb { 17380b7a265SCornelia Huck SCCBHeader header; 17480b7a265SCornelia Huck uint8_t atype; 17580b7a265SCornelia Huck uint8_t reserved1; 17680b7a265SCornelia Huck uint16_t reserved2; 17780b7a265SCornelia Huck uint32_t aid; 17880b7a265SCornelia Huck } QEMU_PACKED IoaCfgSccb; 17980b7a265SCornelia Huck 180f6c98f92SHeinz Graalfs typedef struct SCCB { 181f6c98f92SHeinz Graalfs SCCBHeader h; 182f6c98f92SHeinz Graalfs char data[SCCB_DATA_LEN]; 183f6c98f92SHeinz Graalfs } QEMU_PACKED SCCB; 184f6c98f92SHeinz Graalfs 185515190d9SDavid Hildenbrand #define TYPE_SCLP "sclp" 186515190d9SDavid Hildenbrand #define SCLP(obj) OBJECT_CHECK(SCLPDevice, (obj), TYPE_SCLP) 187515190d9SDavid Hildenbrand #define SCLP_CLASS(oc) OBJECT_CLASS_CHECK(SCLPDeviceClass, (oc), TYPE_SCLP) 188515190d9SDavid Hildenbrand #define SCLP_GET_CLASS(obj) OBJECT_GET_CLASS(SCLPDeviceClass, (obj), TYPE_SCLP) 189515190d9SDavid Hildenbrand 190515190d9SDavid Hildenbrand typedef struct SCLPEventFacility SCLPEventFacility; 191515190d9SDavid Hildenbrand 192515190d9SDavid Hildenbrand typedef struct SCLPDevice { 193515190d9SDavid Hildenbrand /* private */ 194515190d9SDavid Hildenbrand DeviceState parent_obj; 195515190d9SDavid Hildenbrand SCLPEventFacility *event_facility; 19671a2fd35SDavid Hildenbrand int increment_size; 197515190d9SDavid Hildenbrand 198515190d9SDavid Hildenbrand /* public */ 199515190d9SDavid Hildenbrand } SCLPDevice; 200515190d9SDavid Hildenbrand 201515190d9SDavid Hildenbrand typedef struct SCLPDeviceClass { 202515190d9SDavid Hildenbrand /* private */ 203515190d9SDavid Hildenbrand DeviceClass parent_class; 20425a3c5afSDavid Hildenbrand void (*read_SCP_info)(SCLPDevice *sclp, SCCB *sccb); 20525a3c5afSDavid Hildenbrand void (*read_storage_element0_info)(SCLPDevice *sclp, SCCB *sccb); 20625a3c5afSDavid Hildenbrand void (*read_storage_element1_info)(SCLPDevice *sclp, SCCB *sccb); 20725a3c5afSDavid Hildenbrand void (*attach_storage_element)(SCLPDevice *sclp, SCCB *sccb, 20825a3c5afSDavid Hildenbrand uint16_t element); 20925a3c5afSDavid Hildenbrand void (*assign_storage)(SCLPDevice *sclp, SCCB *sccb); 21025a3c5afSDavid Hildenbrand void (*unassign_storage)(SCLPDevice *sclp, SCCB *sccb); 21125a3c5afSDavid Hildenbrand void (*read_cpu_info)(SCLPDevice *sclp, SCCB *sccb); 212515190d9SDavid Hildenbrand 213515190d9SDavid Hildenbrand /* public */ 21425a3c5afSDavid Hildenbrand void (*execute)(SCLPDevice *sclp, SCCB *sccb, uint32_t code); 2151723a1b6SDavid Hildenbrand void (*service_interrupt)(SCLPDevice *sclp, uint32_t sccb); 216515190d9SDavid Hildenbrand } SCLPDeviceClass; 217515190d9SDavid Hildenbrand 2180844df77SMatthew Rosato typedef struct sclpMemoryHotplugDev sclpMemoryHotplugDev; 2190844df77SMatthew Rosato 2200844df77SMatthew Rosato #define TYPE_SCLP_MEMORY_HOTPLUG_DEV "sclp-memory-hotplug-dev" 2210844df77SMatthew Rosato #define SCLP_MEMORY_HOTPLUG_DEV(obj) \ 2220844df77SMatthew Rosato OBJECT_CHECK(sclpMemoryHotplugDev, (obj), TYPE_SCLP_MEMORY_HOTPLUG_DEV) 2230844df77SMatthew Rosato 2240844df77SMatthew Rosato struct sclpMemoryHotplugDev { 2250844df77SMatthew Rosato SysBusDevice parent; 2260844df77SMatthew Rosato ram_addr_t standby_mem_size; 2270844df77SMatthew Rosato ram_addr_t padded_ram_size; 2280844df77SMatthew Rosato ram_addr_t pad_size; 2290844df77SMatthew Rosato ram_addr_t standby_subregion_size; 2300844df77SMatthew Rosato ram_addr_t rzm; 2310844df77SMatthew Rosato int increment_size; 2320844df77SMatthew Rosato char *standby_state_map; 2330844df77SMatthew Rosato }; 2340844df77SMatthew Rosato 235559a17a1SHeinz Graalfs static inline int sccb_data_len(SCCB *sccb) 236559a17a1SHeinz Graalfs { 237559a17a1SHeinz Graalfs return be16_to_cpu(sccb->h.length) - sizeof(sccb->h); 238559a17a1SHeinz Graalfs } 239559a17a1SHeinz Graalfs 240f6c98f92SHeinz Graalfs 241559a17a1SHeinz Graalfs void s390_sclp_init(void); 2420844df77SMatthew Rosato sclpMemoryHotplugDev *init_sclp_memory_hotplug_dev(void); 2430844df77SMatthew Rosato sclpMemoryHotplugDev *get_sclp_memory_hotplug_dev(void); 244f6c98f92SHeinz Graalfs void sclp_service_interrupt(uint32_t sccb); 24549204458SJason J. Herne void raise_irq_cpu_hotplug(void); 246*53d8e91dSDavid Hildenbrand int sclp_service_call(CPUS390XState *env, uint64_t sccb, uint32_t code); 247f6c98f92SHeinz Graalfs 248f6c98f92SHeinz Graalfs #endif 249