xref: /qemu/hw/s390x/ipl.h (revision 52ea63de)
1 /*
2  * s390 IPL device
3  *
4  * Copyright 2015 IBM Corp.
5  * Author(s): Zhang Fan <bjfanzh@cn.ibm.com>
6  *
7  * This work is licensed under the terms of the GNU GPL, version 2 or (at
8  * your option) any later version. See the COPYING file in the top-level
9  * directory.
10  */
11 
12 #ifndef HW_S390_IPL_H
13 #define HW_S390_IPL_H
14 
15 #include "hw/qdev.h"
16 #include "cpu.h"
17 
18 struct IplBlockCcw {
19     uint8_t  reserved0[85];
20     uint8_t  ssid;
21     uint16_t devno;
22     uint8_t  vm_flags;
23     uint8_t  reserved3[3];
24     uint32_t vm_parm_len;
25     uint8_t  nss_name[8];
26     uint8_t  vm_parm[64];
27     uint8_t  reserved4[8];
28 } QEMU_PACKED;
29 typedef struct IplBlockCcw IplBlockCcw;
30 
31 struct IplBlockFcp {
32     uint8_t  reserved1[305 - 1];
33     uint8_t  opt;
34     uint8_t  reserved2[3];
35     uint16_t reserved3;
36     uint16_t devno;
37     uint8_t  reserved4[4];
38     uint64_t wwpn;
39     uint64_t lun;
40     uint32_t bootprog;
41     uint8_t  reserved5[12];
42     uint64_t br_lba;
43     uint32_t scp_data_len;
44     uint8_t  reserved6[260];
45     uint8_t  scp_data[];
46 } QEMU_PACKED;
47 typedef struct IplBlockFcp IplBlockFcp;
48 
49 union IplParameterBlock {
50     struct {
51         uint32_t len;
52         uint8_t  reserved0[3];
53         uint8_t  version;
54         uint32_t blk0_len;
55         uint8_t  pbt;
56         uint8_t  flags;
57         uint16_t reserved01;
58         uint8_t  loadparm[8];
59         union {
60             IplBlockCcw ccw;
61             IplBlockFcp fcp;
62         };
63     } QEMU_PACKED;
64     struct {
65         uint8_t  reserved1[110];
66         uint16_t devno;
67         uint8_t  reserved2[88];
68         uint8_t  reserved_ext[4096 - 200];
69     } QEMU_PACKED;
70 } QEMU_PACKED;
71 typedef union IplParameterBlock IplParameterBlock;
72 
73 void s390_ipl_update_diag308(IplParameterBlock *iplb);
74 void s390_ipl_prepare_cpu(S390CPU *cpu);
75 IplParameterBlock *s390_ipl_get_iplb(void);
76 void s390_reipl_request(void);
77 
78 #define TYPE_S390_IPL "s390-ipl"
79 #define S390_IPL(obj) OBJECT_CHECK(S390IPLState, (obj), TYPE_S390_IPL)
80 
81 struct S390IPLState {
82     /*< private >*/
83     DeviceState parent_obj;
84     uint64_t start_addr;
85     uint64_t bios_start_addr;
86     bool enforce_bios;
87     IplParameterBlock iplb;
88     bool iplb_valid;
89     bool reipl_requested;
90 
91     /*< public >*/
92     char *kernel;
93     char *initrd;
94     char *cmdline;
95     char *firmware;
96     uint8_t cssid;
97     uint8_t ssid;
98     uint16_t devno;
99     bool iplbext_migration;
100 };
101 typedef struct S390IPLState S390IPLState;
102 
103 #define S390_IPL_TYPE_FCP 0x00
104 #define S390_IPL_TYPE_CCW 0x02
105 
106 #define S390_IPLB_HEADER_LEN 8
107 #define S390_IPLB_MIN_CCW_LEN 200
108 #define S390_IPLB_MIN_FCP_LEN 384
109 
110 static inline bool iplb_valid_len(IplParameterBlock *iplb)
111 {
112     return be32_to_cpu(iplb->len) <= sizeof(IplParameterBlock);
113 }
114 
115 static inline bool iplb_valid_ccw(IplParameterBlock *iplb)
116 {
117     return be32_to_cpu(iplb->len) >= S390_IPLB_MIN_CCW_LEN &&
118            iplb->pbt == S390_IPL_TYPE_CCW;
119 }
120 
121 static inline bool iplb_valid_fcp(IplParameterBlock *iplb)
122 {
123     return be32_to_cpu(iplb->len) >= S390_IPLB_MIN_FCP_LEN &&
124            iplb->pbt == S390_IPL_TYPE_FCP;
125 }
126 
127 #endif
128