xref: /qemu/include/hw/s390x/sclp.h (revision 8cba80c3a0331926c9c412c4c1e07896de29aab6)
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 
17f6c98f92SHeinz Graalfs #include <hw/sysbus.h>
18f6c98f92SHeinz Graalfs #include <hw/qdev.h>
19f6c98f92SHeinz Graalfs 
205f04c14aSJason J. Herne #define SCLP_CMD_CODE_MASK                      0xffff00ff
215f04c14aSJason J. Herne 
22f6c98f92SHeinz Graalfs /* SCLP command codes */
23f6c98f92SHeinz Graalfs #define SCLP_CMDW_READ_SCP_INFO                 0x00020001
24f6c98f92SHeinz Graalfs #define SCLP_CMDW_READ_SCP_INFO_FORCED          0x00120001
25234eef51SMatthew Rosato #define SCLP_READ_STORAGE_ELEMENT_INFO          0x00040001
26234eef51SMatthew Rosato #define SCLP_ATTACH_STORAGE_ELEMENT             0x00080001
27234eef51SMatthew Rosato #define SCLP_ASSIGN_STORAGE                     0x000D0001
28234eef51SMatthew Rosato #define SCLP_UNASSIGN_STORAGE                   0x000C0001
29559a17a1SHeinz Graalfs #define SCLP_CMD_READ_EVENT_DATA                0x00770005
30559a17a1SHeinz Graalfs #define SCLP_CMD_WRITE_EVENT_DATA               0x00760005
31559a17a1SHeinz Graalfs #define SCLP_CMD_WRITE_EVENT_MASK               0x00780005
32f6c98f92SHeinz Graalfs 
33234eef51SMatthew Rosato /* SCLP Memory hotplug codes */
34234eef51SMatthew Rosato #define SCLP_FC_ASSIGN_ATTACH_READ_STOR         0xE00000000000ULL
35234eef51SMatthew Rosato #define SCLP_STARTING_SUBINCREMENT_ID           0x10001
36234eef51SMatthew Rosato #define SCLP_INCREMENT_UNIT                     0x10000
37234eef51SMatthew Rosato #define MAX_AVAIL_SLOTS                         32
380844df77SMatthew Rosato #define MAX_STORAGE_INCREMENTS                  1020
39234eef51SMatthew Rosato 
405f04c14aSJason J. Herne /* CPU hotplug SCLP codes */
415f04c14aSJason J. Herne #define SCLP_HAS_CPU_INFO                       0x0C00000000000000ULL
425f04c14aSJason J. Herne #define SCLP_CMDW_READ_CPU_INFO                 0x00010001
435f04c14aSJason J. Herne #define SCLP_CMDW_CONFIGURE_CPU                 0x00110001
445f04c14aSJason J. Herne #define SCLP_CMDW_DECONFIGURE_CPU               0x00100001
455f04c14aSJason J. Herne 
46*8cba80c3SFrank Blaschka /* SCLP PCI codes */
47*8cba80c3SFrank Blaschka #define SCLP_HAS_PCI_RECONFIG                   0x0000000040000000ULL
48*8cba80c3SFrank Blaschka #define SCLP_CMDW_CONFIGURE_PCI                 0x001a0001
49*8cba80c3SFrank Blaschka #define SCLP_CMDW_DECONFIGURE_PCI               0x001b0001
50*8cba80c3SFrank Blaschka #define SCLP_RECONFIG_PCI_ATPYE                 2
51*8cba80c3SFrank Blaschka 
52f6c98f92SHeinz Graalfs /* SCLP response codes */
53f6c98f92SHeinz Graalfs #define SCLP_RC_NORMAL_READ_COMPLETION          0x0010
54559a17a1SHeinz Graalfs #define SCLP_RC_NORMAL_COMPLETION               0x0020
55234eef51SMatthew Rosato #define SCLP_RC_SCCB_BOUNDARY_VIOLATION         0x0100
56*8cba80c3SFrank Blaschka #define SCLP_RC_NO_ACTION_REQUIRED              0x0120
57f6c98f92SHeinz Graalfs #define SCLP_RC_INVALID_SCLP_COMMAND            0x01f0
58559a17a1SHeinz Graalfs #define SCLP_RC_CONTAINED_EQUIPMENT_CHECK       0x0340
59559a17a1SHeinz Graalfs #define SCLP_RC_INSUFFICIENT_SCCB_LENGTH        0x0300
60234eef51SMatthew Rosato #define SCLP_RC_STANDBY_READ_COMPLETION         0x0410
61*8cba80c3SFrank Blaschka #define SCLP_RC_ADAPTER_ID_NOT_RECOGNIZED       0x09f0
62559a17a1SHeinz Graalfs #define SCLP_RC_INVALID_FUNCTION                0x40f0
63559a17a1SHeinz Graalfs #define SCLP_RC_NO_EVENT_BUFFERS_STORED         0x60f0
64559a17a1SHeinz Graalfs #define SCLP_RC_INVALID_SELECTION_MASK          0x70f0
65559a17a1SHeinz Graalfs #define SCLP_RC_INCONSISTENT_LENGTHS            0x72f0
66559a17a1SHeinz Graalfs #define SCLP_RC_EVENT_BUFFER_SYNTAX_ERROR       0x73f0
67559a17a1SHeinz Graalfs #define SCLP_RC_INVALID_MASK_LENGTH             0x74f0
68559a17a1SHeinz Graalfs 
69f6c98f92SHeinz Graalfs 
70f6c98f92SHeinz Graalfs /* Service Call Control Block (SCCB) and its elements */
71f6c98f92SHeinz Graalfs 
72f6c98f92SHeinz Graalfs #define SCCB_SIZE 4096
73f6c98f92SHeinz Graalfs 
74559a17a1SHeinz Graalfs #define SCLP_VARIABLE_LENGTH_RESPONSE           0x80
75559a17a1SHeinz Graalfs #define SCLP_EVENT_BUFFER_ACCEPTED              0x80
76559a17a1SHeinz Graalfs 
77559a17a1SHeinz Graalfs #define SCLP_FC_NORMAL_WRITE                    0
78559a17a1SHeinz Graalfs 
79f6c98f92SHeinz Graalfs /*
80f6c98f92SHeinz Graalfs  * Normally packed structures are not the right thing to do, since all code
818367a14fSStefan Weil  * must take care of endianness. We cannot use ldl_phys and friends for two
82f6c98f92SHeinz Graalfs  * reasons, though:
83f6c98f92SHeinz Graalfs  * - some of the embedded structures below the SCCB can appear multiple times
84f6c98f92SHeinz Graalfs  *   at different locations, so there is no fixed offset
85f6c98f92SHeinz Graalfs  * - we work on a private copy of the SCCB, since there are several length
86f6c98f92SHeinz Graalfs  *   fields, that would cause a security nightmare if we allow the guest to
87f6c98f92SHeinz Graalfs  *   alter the structure while we parse it. We cannot use ldl_p and friends
88f6c98f92SHeinz Graalfs  *   either without doing pointer arithmetics
89f6c98f92SHeinz Graalfs  * So we have to double check that all users of sclp data structures use the
908367a14fSStefan Weil  * right endianness wrappers.
91f6c98f92SHeinz Graalfs  */
92f6c98f92SHeinz Graalfs typedef struct SCCBHeader {
93f6c98f92SHeinz Graalfs     uint16_t length;
94f6c98f92SHeinz Graalfs     uint8_t function_code;
95f6c98f92SHeinz Graalfs     uint8_t control_mask[3];
96f6c98f92SHeinz Graalfs     uint16_t response_code;
97f6c98f92SHeinz Graalfs } QEMU_PACKED SCCBHeader;
98f6c98f92SHeinz Graalfs 
99f6c98f92SHeinz Graalfs #define SCCB_DATA_LEN (SCCB_SIZE - sizeof(SCCBHeader))
100f6c98f92SHeinz Graalfs 
1018cc3aecfSJason J. Herne /* CPU information */
1028cc3aecfSJason J. Herne typedef struct CPUEntry {
1038cc3aecfSJason J. Herne     uint8_t address;
1048cc3aecfSJason J. Herne     uint8_t reserved0[13];
1058cc3aecfSJason J. Herne     uint8_t type;
1068cc3aecfSJason J. Herne     uint8_t reserved1;
1078cc3aecfSJason J. Herne } QEMU_PACKED CPUEntry;
1088cc3aecfSJason J. Herne 
109f6c98f92SHeinz Graalfs typedef struct ReadInfo {
110f6c98f92SHeinz Graalfs     SCCBHeader h;
111f6c98f92SHeinz Graalfs     uint16_t rnmax;
112f6c98f92SHeinz Graalfs     uint8_t rnsize;
1138cc3aecfSJason J. Herne     uint8_t  _reserved1[16 - 11];       /* 11-15 */
1148cc3aecfSJason J. Herne     uint16_t entries_cpu;               /* 16-17 */
1158cc3aecfSJason J. Herne     uint16_t offset_cpu;                /* 18-19 */
1168cc3aecfSJason J. Herne     uint8_t  _reserved2[24 - 20];       /* 20-23 */
1178cc3aecfSJason J. Herne     uint8_t  loadparm[8];               /* 24-31 */
1188cc3aecfSJason J. Herne     uint8_t  _reserved3[48 - 32];       /* 32-47 */
1198cc3aecfSJason J. Herne     uint64_t facilities;                /* 48-55 */
1208cc3aecfSJason J. Herne     uint8_t  _reserved0[100 - 56];
1218cc3aecfSJason J. Herne     uint32_t rnsize2;
1228cc3aecfSJason J. Herne     uint64_t rnmax2;
1238cc3aecfSJason J. Herne     uint8_t  _reserved4[120-112];       /* 112-119 */
1248cc3aecfSJason J. Herne     uint16_t highest_cpu;
1258cc3aecfSJason J. Herne     uint8_t  _reserved5[128 - 122];     /* 122-127 */
1268cc3aecfSJason J. Herne     struct CPUEntry entries[0];
127f6c98f92SHeinz Graalfs } QEMU_PACKED ReadInfo;
128f6c98f92SHeinz Graalfs 
1298cc3aecfSJason J. Herne typedef struct ReadCpuInfo {
1308cc3aecfSJason J. Herne     SCCBHeader h;
1318cc3aecfSJason J. Herne     uint16_t nr_configured;         /* 8-9 */
1328cc3aecfSJason J. Herne     uint16_t offset_configured;     /* 10-11 */
1338cc3aecfSJason J. Herne     uint16_t nr_standby;            /* 12-13 */
1348cc3aecfSJason J. Herne     uint16_t offset_standby;        /* 14-15 */
1358cc3aecfSJason J. Herne     uint8_t reserved0[24-16];       /* 16-23 */
1368cc3aecfSJason J. Herne     struct CPUEntry entries[0];
1378cc3aecfSJason J. Herne } QEMU_PACKED ReadCpuInfo;
1388cc3aecfSJason J. Herne 
139234eef51SMatthew Rosato typedef struct ReadStorageElementInfo {
140234eef51SMatthew Rosato     SCCBHeader h;
141234eef51SMatthew Rosato     uint16_t max_id;
142234eef51SMatthew Rosato     uint16_t assigned;
143234eef51SMatthew Rosato     uint16_t standby;
144234eef51SMatthew Rosato     uint8_t _reserved0[16 - 14]; /* 14-15 */
145234eef51SMatthew Rosato     uint32_t entries[0];
146234eef51SMatthew Rosato } QEMU_PACKED ReadStorageElementInfo;
147234eef51SMatthew Rosato 
148234eef51SMatthew Rosato typedef struct AttachStorageElement {
149234eef51SMatthew Rosato     SCCBHeader h;
150234eef51SMatthew Rosato     uint8_t _reserved0[10 - 8];  /* 8-9 */
151234eef51SMatthew Rosato     uint16_t assigned;
152234eef51SMatthew Rosato     uint8_t _reserved1[16 - 12]; /* 12-15 */
153234eef51SMatthew Rosato     uint32_t entries[0];
154234eef51SMatthew Rosato } QEMU_PACKED AttachStorageElement;
155234eef51SMatthew Rosato 
156234eef51SMatthew Rosato typedef struct AssignStorage {
157234eef51SMatthew Rosato     SCCBHeader h;
158234eef51SMatthew Rosato     uint16_t rn;
159234eef51SMatthew Rosato } QEMU_PACKED AssignStorage;
160234eef51SMatthew Rosato 
161f6c98f92SHeinz Graalfs typedef struct SCCB {
162f6c98f92SHeinz Graalfs     SCCBHeader h;
163f6c98f92SHeinz Graalfs     char data[SCCB_DATA_LEN];
164f6c98f92SHeinz Graalfs  } QEMU_PACKED SCCB;
165f6c98f92SHeinz Graalfs 
1660844df77SMatthew Rosato typedef struct sclpMemoryHotplugDev sclpMemoryHotplugDev;
1670844df77SMatthew Rosato 
1680844df77SMatthew Rosato #define TYPE_SCLP_MEMORY_HOTPLUG_DEV "sclp-memory-hotplug-dev"
1690844df77SMatthew Rosato #define SCLP_MEMORY_HOTPLUG_DEV(obj) \
1700844df77SMatthew Rosato   OBJECT_CHECK(sclpMemoryHotplugDev, (obj), TYPE_SCLP_MEMORY_HOTPLUG_DEV)
1710844df77SMatthew Rosato 
1720844df77SMatthew Rosato struct sclpMemoryHotplugDev {
1730844df77SMatthew Rosato     SysBusDevice parent;
1740844df77SMatthew Rosato     ram_addr_t standby_mem_size;
1750844df77SMatthew Rosato     ram_addr_t padded_ram_size;
1760844df77SMatthew Rosato     ram_addr_t pad_size;
1770844df77SMatthew Rosato     ram_addr_t standby_subregion_size;
1780844df77SMatthew Rosato     ram_addr_t rzm;
1790844df77SMatthew Rosato     int increment_size;
1800844df77SMatthew Rosato     char *standby_state_map;
1810844df77SMatthew Rosato };
1820844df77SMatthew Rosato 
183559a17a1SHeinz Graalfs static inline int sccb_data_len(SCCB *sccb)
184559a17a1SHeinz Graalfs {
185559a17a1SHeinz Graalfs     return be16_to_cpu(sccb->h.length) - sizeof(sccb->h);
186559a17a1SHeinz Graalfs }
187559a17a1SHeinz Graalfs 
188f6c98f92SHeinz Graalfs 
189559a17a1SHeinz Graalfs void s390_sclp_init(void);
1900844df77SMatthew Rosato sclpMemoryHotplugDev *init_sclp_memory_hotplug_dev(void);
1910844df77SMatthew Rosato sclpMemoryHotplugDev *get_sclp_memory_hotplug_dev(void);
192f6c98f92SHeinz Graalfs void sclp_service_interrupt(uint32_t sccb);
19349204458SJason J. Herne void raise_irq_cpu_hotplug(void);
194f6c98f92SHeinz Graalfs 
195f6c98f92SHeinz Graalfs #endif
196