4 * Copyright 2015, 2020 IBM Corp.
8 * This work is licensed under the terms of the GNU GPL, version 2 or (at
9 * your option) any later version. See the COPYING file in the top-level
17 #include "exec/address-spaces.h"
18 #include "hw/qdev-core.h"
19 #include "qom/object.h"
21 struct IPLBlockPVComp {
26 typedef struct IPLBlockPVComp IPLBlockPVComp;
29 uint8_t reserved18[87]; /* 0x18 */
30 uint8_t version; /* 0x6f */
31 uint32_t reserved70; /* 0x70 */
32 uint32_t num_comp; /* 0x74 */
33 uint64_t pv_header_addr; /* 0x78 */
34 uint64_t pv_header_len; /* 0x80 */
35 struct IPLBlockPVComp components[0];
37 typedef struct IPLBlockPV IPLBlockPV;
40 uint8_t reserved0[85];
50 typedef struct IplBlockCcw IplBlockCcw;
53 uint8_t reserved1[305 - 1];
62 uint8_t reserved5[12];
64 uint32_t scp_data_len;
65 uint8_t reserved6[260];
68 typedef struct IplBlockFcp IplBlockFcp;
70 struct IplBlockQemuScsi {
74 uint8_t reserved0[77];
78 typedef struct IplBlockQemuScsi IplBlockQemuScsi;
80 #define DIAG308_FLAGS_LP_VALID 0x80
82 union IplParameterBlock {
96 IplBlockQemuScsi scsi;
100 uint8_t reserved1[110];
102 uint8_t reserved2[88];
103 uint8_t reserved_ext[4096 - 200];
106 typedef union IplParameterBlock IplParameterBlock;
108 int s390_ipl_set_loadparm(uint8_t *loadparm);
109 void s390_ipl_update_diag308(IplParameterBlock *iplb);
110 int s390_ipl_prepare_pv_header(void);
111 int s390_ipl_pv_unpack(void);
112 void s390_ipl_prepare_cpu(S390CPU *cpu);
113 IplParameterBlock *s390_ipl_get_iplb(void);
114 IplParameterBlock *s390_ipl_get_iplb_pv(void);
117 /* default is a reset not triggered by a CPU e.g. issued by QMP */
118 S390_RESET_EXTERNAL = 0,
120 S390_RESET_MODIFIED_CLEAR,
121 S390_RESET_LOAD_NORMAL,
124 void s390_ipl_reset_request(CPUState *cs, enum s390_reset reset_type);
125 void s390_ipl_get_reset_request(CPUState **cs, enum s390_reset *reset_type);
126 void s390_ipl_clear_reset_request(void);
128 #define QIPL_ADDRESS 0xcc
130 /* Boot Menu flags */
131 #define QIPL_FLAG_BM_OPTS_CMD 0x80
132 #define QIPL_FLAG_BM_OPTS_ZIPL 0x40
135 * The QEMU IPL Parameters will be stored at absolute address
136 * 204 (0xcc) which means it is 32-bit word aligned but not
137 * double-word aligned.
138 * Placement of data fields in this area must account for
139 * their alignment needs. E.g., netboot_start_address must
140 * have an offset of 4 + n * 8 bytes within the struct in order
141 * to keep it double-word aligned.
142 * The total size of the struct must never exceed 28 bytes.
143 * This definition must be kept in sync with the defininition
144 * in pc-bios/s390-ccw/iplb.h.
146 struct QemuIplParameters {
148 uint8_t reserved1[3];
149 uint64_t netboot_start_addr;
150 uint32_t boot_menu_timeout;
151 uint8_t reserved2[12];
153 typedef struct QemuIplParameters QemuIplParameters;
155 #define TYPE_S390_IPL "s390-ipl"
156 OBJECT_DECLARE_SIMPLE_TYPE(S390IPLState, S390_IPL)
158 struct S390IPLState {
160 DeviceState parent_obj;
161 IplParameterBlock iplb;
162 IplParameterBlock iplb_pv;
163 QemuIplParameters qipl;
165 uint64_t compat_start_addr;
166 uint64_t bios_start_addr;
167 uint64_t compat_bios_start_addr;
172 /* reset related properties don't have to be migrated or reset */
173 enum s390_reset reset_type;
185 bool iplbext_migration;
187 QEMU_BUILD_BUG_MSG(offsetof(S390IPLState, iplb) & 3, "alignment of iplb wrong");
189 #define DIAG_308_RC_OK 0x0001
190 #define DIAG_308_RC_NO_CONF 0x0102
191 #define DIAG_308_RC_INVALID 0x0402
192 #define DIAG_308_RC_NO_PV_CONF 0x0902
193 #define DIAG_308_RC_INVAL_FOR_PV 0x0a02
195 #define DIAG308_RESET_MOD_CLR 0
196 #define DIAG308_RESET_LOAD_NORM 1
197 #define DIAG308_LOAD_CLEAR 3
198 #define DIAG308_LOAD_NORMAL_DUMP 4
199 #define DIAG308_SET 5
200 #define DIAG308_STORE 6
201 #define DIAG308_PV_SET 8
202 #define DIAG308_PV_STORE 9
203 #define DIAG308_PV_START 10
205 #define S390_IPL_TYPE_FCP 0x00
206 #define S390_IPL_TYPE_CCW 0x02
207 #define S390_IPL_TYPE_PV 0x05
208 #define S390_IPL_TYPE_QEMU_SCSI 0xff
210 #define S390_IPLB_HEADER_LEN 8
211 #define S390_IPLB_MIN_PV_LEN 148
212 #define S390_IPLB_MIN_CCW_LEN 200
213 #define S390_IPLB_MIN_FCP_LEN 384
214 #define S390_IPLB_MIN_QEMU_SCSI_LEN 200
216 static inline bool iplb_valid_len(IplParameterBlock *iplb)
218 return be32_to_cpu(iplb->len) <= sizeof(IplParameterBlock);
221 static inline bool ipl_valid_pv_components(IplParameterBlock *iplb)
223 IPLBlockPV *ipib_pv = &iplb->pv;
226 if (ipib_pv->num_comp == 0) {
230 for (i = 0; i < ipib_pv->num_comp; i++) {
231 /* Addr must be 4k aligned */
232 if (ipib_pv->components[i].addr & ~TARGET_PAGE_MASK) {
236 /* Tweak prefix is monotonically increasing with each component */
237 if (i < ipib_pv->num_comp - 1 &&
238 ipib_pv->components[i].tweak_pref >=
239 ipib_pv->components[i + 1].tweak_pref) {
246 static inline bool ipl_valid_pv_header(IplParameterBlock *iplb)
248 IPLBlockPV *ipib_pv = &iplb->pv;
250 if (ipib_pv->pv_header_len > 2 * TARGET_PAGE_SIZE) {
254 if (!address_space_access_valid(&address_space_memory,
255 ipib_pv->pv_header_addr,
256 ipib_pv->pv_header_len,
258 MEMTXATTRS_UNSPECIFIED)) {
265 static inline bool iplb_valid_pv(IplParameterBlock *iplb)
267 if (iplb->pbt != S390_IPL_TYPE_PV ||
268 be32_to_cpu(iplb->len) < S390_IPLB_MIN_PV_LEN) {
271 if (!ipl_valid_pv_header(iplb)) {
274 return ipl_valid_pv_components(iplb);
277 static inline bool iplb_valid(IplParameterBlock *iplb)
280 case S390_IPL_TYPE_FCP:
281 return be32_to_cpu(iplb->len) >= S390_IPLB_MIN_FCP_LEN;
282 case S390_IPL_TYPE_CCW:
283 return be32_to_cpu(iplb->len) >= S390_IPLB_MIN_CCW_LEN;