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
13 #include "s390-arch.h"
19 char stack
[PAGE_SIZE
* 8] __attribute__((__aligned__(PAGE_SIZE
)));
20 static SubChannelId blk_schid
= { .one
= 1 };
21 static char loadparm_str
[LOADPARM_LEN
+ 1];
22 QemuIplParameters qipl
;
23 IplParameterBlock iplb
__attribute__((__aligned__(PAGE_SIZE
)));
24 static bool have_iplb
;
25 static uint16_t cutype
;
26 LowCore
*lowcore
; /* Yes, this *is* a pointer to address 0 */
28 #define LOADPARM_PROMPT "PROMPT "
29 #define LOADPARM_EMPTY " "
30 #define BOOT_MENU_FLAG_MASK (QIPL_FLAG_BM_OPTS_CMD | QIPL_FLAG_BM_OPTS_ZIPL)
33 * Principles of Operations (SA22-7832-09) chapter 17 requires that
34 * a subsystem-identification is at 184-187 and bytes 188-191 are zero
35 * after list-directed-IPL and ccw-IPL.
37 void write_subsystem_identification(void)
39 lowcore
->subchannel_id
= blk_schid
.sch_id
;
40 lowcore
->subchannel_nr
= blk_schid
.sch_no
;
41 lowcore
->io_int_parm
= 0;
44 void write_iplb_location(void)
46 lowcore
->ptr_iplb
= ptr2u32(&iplb
);
49 unsigned int get_loadparm_index(void)
51 return atoui(loadparm_str
);
54 static int is_dev_possibly_bootable(int dev_no
, int sch_no
)
60 blk_schid
.sch_no
= sch_no
;
61 r
= stsch_err(blk_schid
, &schib
);
62 if (r
== 3 || r
== -EIO
) {
65 if (!schib
.pmcw
.dnv
) {
69 enable_subchannel(blk_schid
);
70 cutype
= cu_type(blk_schid
);
73 * Note: we always have to run virtio_is_supported() here to make
74 * sure that the vdev.senseid data gets pre-initialized correctly
76 is_virtio
= virtio_is_supported(blk_schid
);
78 /* No specific devno given, just return whether the device is possibly bootable */
84 * Skip net devices since no IPLB is created and therefore
85 * no network bootloader has been loaded
87 if (virtio_get_device_type() != VIRTIO_ID_NET
) {
92 case CU_TYPE_DASD_3990
:
93 case CU_TYPE_DASD_2107
:
100 /* Caller asked for a specific devno */
101 if (schib
.pmcw
.dev
== dev_no
) {
109 * Find the subchannel connected to the given device (dev_no) and fill in the
110 * subchannel information block (schib) with the connected subchannel's info.
111 * NOTE: The global variable blk_schid is updated to contain the subchannel
114 * If the caller gives dev_no=-1 then the user did not specify a boot device.
115 * In this case we'll just use the first potentially bootable device we find.
117 static bool find_subch(int dev_no
)
121 for (i
= 0; i
< 0x10000; i
++) {
122 r
= is_dev_possibly_bootable(dev_no
, i
);
134 static void menu_setup(void)
136 if (memcmp(loadparm_str
, LOADPARM_PROMPT
, LOADPARM_LEN
) == 0) {
137 menu_set_parms(QIPL_FLAG_BM_OPTS_CMD
, 0);
141 /* If loadparm was set to any other value, then do not enable menu */
142 if (memcmp(loadparm_str
, LOADPARM_EMPTY
, LOADPARM_LEN
) != 0) {
147 case S390_IPL_TYPE_CCW
:
148 case S390_IPL_TYPE_QEMU_SCSI
:
149 menu_set_parms(qipl
.qipl_flags
& BOOT_MENU_FLAG_MASK
,
150 qipl
.boot_menu_timeout
);
156 * Initialize the channel I/O subsystem so we can talk to our ipl/boot device.
158 static void css_setup(void)
161 * Unconditionally enable mss support. In every sane configuration this
162 * will succeed; and even if it doesn't, stsch_err() can handle it.
164 enable_mss_facility();
168 * Collect various pieces of information from the hypervisor/hardware that
169 * we'll use to determine exactly how we'll boot.
171 static void boot_setup(void)
173 char lpmsg
[] = "LOADPARM=[________]\n";
175 sclp_get_loadparm_ascii(loadparm_str
);
176 memcpy(lpmsg
+ 10, loadparm_str
, 8);
179 have_iplb
= store_iplb(&iplb
);
182 static void find_boot_device(void)
184 VDev
*vdev
= virtio_get_device();
188 case S390_IPL_TYPE_CCW
:
189 debug_print_int("device no. ", iplb
.ccw
.devno
);
190 blk_schid
.ssid
= iplb
.ccw
.ssid
& 0x3;
191 debug_print_int("ssid ", blk_schid
.ssid
);
192 found
= find_subch(iplb
.ccw
.devno
);
194 case S390_IPL_TYPE_QEMU_SCSI
:
195 vdev
->scsi_device_selected
= true;
196 vdev
->selected_scsi_device
.channel
= iplb
.scsi
.channel
;
197 vdev
->selected_scsi_device
.target
= iplb
.scsi
.target
;
198 vdev
->selected_scsi_device
.lun
= iplb
.scsi
.lun
;
199 blk_schid
.ssid
= iplb
.scsi
.ssid
& 0x3;
200 found
= find_subch(iplb
.scsi
.devno
);
203 panic("List-directed IPL not supported yet!\n");
206 IPL_assert(found
, "Boot device not found\n");
209 static int virtio_setup(void)
211 VDev
*vdev
= virtio_get_device();
212 QemuIplParameters
*early_qipl
= (QemuIplParameters
*)QIPL_ADDRESS
;
214 memcpy(&qipl
, early_qipl
, sizeof(QemuIplParameters
));
220 if (virtio_get_device_type() == VIRTIO_ID_NET
) {
221 sclp_print("Network boot device detected\n");
222 vdev
->netboot_start_addr
= qipl
.netboot_start_addr
;
224 int ret
= virtio_blk_setup_device(blk_schid
);
228 IPL_assert(virtio_ipl_disk_is_valid(), "No valid IPL device detected");
234 static void ipl_boot_device(void)
237 case CU_TYPE_DASD_3990
:
238 case CU_TYPE_DASD_2107
:
239 dasd_ipl(blk_schid
, cutype
); /* no return */
242 if (virtio_setup() == 0) {
243 zipl_load(); /* Only returns in case of errors */
247 print_int("Attempting to boot from unexpected device type", cutype
);
248 panic("\nBoot failed.\n");
253 * No boot device has been specified, so we have to scan through the
254 * channels to find one.
256 static void probe_boot_device(void)
258 int ssid
, sch_no
, ret
;
260 for (ssid
= 0; ssid
< 0x3; ssid
++) {
261 blk_schid
.ssid
= ssid
;
262 for (sch_no
= 0; sch_no
< 0x10000; sch_no
++) {
263 ret
= is_dev_possibly_bootable(-1, sch_no
);
268 ipl_boot_device(); /* Only returns if unsuccessful */
273 sclp_print("Could not find a suitable boot device (none specified)\n");
288 panic("Failed to load OS from hard disk\n");
289 return 0; /* make compiler happy */