2 * S390 virtio-ccw loading program
4 * Copyright (c) 2013 Alexander Graf <agraf@suse.de>
6 * This work is licensed under the terms of the GNU GPL, version 2 or (at
7 * your option) any later version. See the COPYING file in the top-level
15 char stack
[PAGE_SIZE
* 8] __attribute__((__aligned__(PAGE_SIZE
)));
16 static SubChannelId blk_schid
= { .one
= 1 };
17 IplParameterBlock iplb
__attribute__((__aligned__(PAGE_SIZE
)));
18 static char loadparm_str
[LOADPARM_LEN
+ 1] = { 0, 0, 0, 0, 0, 0, 0, 0, 0 };
19 QemuIplParameters qipl
;
21 #define LOADPARM_PROMPT "PROMPT "
22 #define LOADPARM_EMPTY " "
23 #define BOOT_MENU_FLAG_MASK (QIPL_FLAG_BM_OPTS_CMD | QIPL_FLAG_BM_OPTS_ZIPL)
26 * Priniciples of Operations (SA22-7832-09) chapter 17 requires that
27 * a subsystem-identification is at 184-187 and bytes 188-191 are zero
28 * after list-directed-IPL and ccw-IPL.
30 void write_subsystem_identification(void)
32 SubChannelId
*schid
= (SubChannelId
*) 184;
33 uint32_t *zeroes
= (uint32_t *) 188;
39 void panic(const char *string
)
46 unsigned int get_loadparm_index(void)
48 return atoui(loadparm_str
);
51 static bool find_dev(Schib
*schib
, int dev_no
)
55 for (i
= 0; i
< 0x10000; i
++) {
57 r
= stsch_err(blk_schid
, schib
);
58 if ((r
== 3) || (r
== -EIO
)) {
61 if (!schib
->pmcw
.dnv
) {
64 if (!virtio_is_supported(blk_schid
)) {
67 /* Skip net devices since no IPLB is created and therefore no
68 * no network bootloader has been loaded
70 if (virtio_get_device_type() == VIRTIO_ID_NET
&& dev_no
< 0) {
73 if ((dev_no
< 0) || (schib
->pmcw
.dev
== dev_no
)) {
81 static void menu_setup(void)
83 if (memcmp(loadparm_str
, LOADPARM_PROMPT
, LOADPARM_LEN
) == 0) {
84 menu_set_parms(QIPL_FLAG_BM_OPTS_CMD
, 0);
88 /* If loadparm was set to any other value, then do not enable menu */
89 if (memcmp(loadparm_str
, LOADPARM_EMPTY
, LOADPARM_LEN
) != 0) {
94 case S390_IPL_TYPE_CCW
:
95 case S390_IPL_TYPE_QEMU_SCSI
:
96 menu_set_parms(qipl
.qipl_flags
& BOOT_MENU_FLAG_MASK
,
97 qipl
.boot_menu_timeout
);
102 static void virtio_setup(void)
108 char ldp
[] = "LOADPARM=[________]\n";
109 VDev
*vdev
= virtio_get_device();
110 QemuIplParameters
*early_qipl
= (QemuIplParameters
*)QIPL_ADDRESS
;
113 * We unconditionally enable mss support. In every sane configuration,
114 * this will succeed; and even if it doesn't, stsch_err() can deal
115 * with the consequences.
117 enable_mss_facility();
119 sclp_get_loadparm_ascii(loadparm_str
);
120 memcpy(ldp
+ 10, loadparm_str
, LOADPARM_LEN
);
123 memcpy(&qipl
, early_qipl
, sizeof(QemuIplParameters
));
125 if (store_iplb(&iplb
)) {
127 case S390_IPL_TYPE_CCW
:
128 dev_no
= iplb
.ccw
.devno
;
129 debug_print_int("device no. ", dev_no
);
130 blk_schid
.ssid
= iplb
.ccw
.ssid
& 0x3;
131 debug_print_int("ssid ", blk_schid
.ssid
);
132 found
= find_dev(&schib
, dev_no
);
134 case S390_IPL_TYPE_QEMU_SCSI
:
135 vdev
->scsi_device_selected
= true;
136 vdev
->selected_scsi_device
.channel
= iplb
.scsi
.channel
;
137 vdev
->selected_scsi_device
.target
= iplb
.scsi
.target
;
138 vdev
->selected_scsi_device
.lun
= iplb
.scsi
.lun
;
139 blk_schid
.ssid
= iplb
.scsi
.ssid
& 0x3;
140 found
= find_dev(&schib
, iplb
.scsi
.devno
);
143 panic("List-directed IPL not supported yet!\n");
147 for (ssid
= 0; ssid
< 0x3; ssid
++) {
148 blk_schid
.ssid
= ssid
;
149 found
= find_dev(&schib
, -1);
156 IPL_assert(found
, "No virtio device found");
158 if (virtio_get_device_type() == VIRTIO_ID_NET
) {
159 sclp_print("Network boot device detected\n");
160 vdev
->netboot_start_addr
= qipl
.netboot_start_addr
;
162 virtio_blk_setup_device(blk_schid
);
164 IPL_assert(virtio_ipl_disk_is_valid(), "No valid IPL device detected");
173 zipl_load(); /* no return */
175 panic("Failed to load OS from hard disk\n");
176 return 0; /* make compiler happy */