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
);
55 * Find the subchannel connected to the given device (dev_no) and fill in the
56 * subchannel information block (schib) with the connected subchannel's info.
57 * NOTE: The global variable blk_schid is updated to contain the subchannel
60 * If the caller gives dev_no=-1 then the user did not specify a boot device.
61 * In this case we'll just use the first potentially bootable device we find.
63 static bool find_subch(int dev_no
)
69 for (i
= 0; i
< 0x10000; i
++) {
71 r
= stsch_err(blk_schid
, &schib
);
72 if ((r
== 3) || (r
== -EIO
)) {
75 if (!schib
.pmcw
.dnv
) {
79 enable_subchannel(blk_schid
);
80 cutype
= cu_type(blk_schid
);
83 * Note: we always have to run virtio_is_supported() here to make
84 * sure that the vdev.senseid data gets pre-initialized correctly
86 is_virtio
= virtio_is_supported(blk_schid
);
88 /* No specific devno given, just return 1st possibly bootable device */
94 * Skip net devices since no IPLB is created and therefore
95 * no network bootloader has been loaded
97 if (virtio_get_device_type() != VIRTIO_ID_NET
) {
102 case CU_TYPE_DASD_3990
:
103 case CU_TYPE_DASD_2107
:
110 /* Caller asked for a specific devno */
111 if (schib
.pmcw
.dev
== dev_no
) {
119 static void menu_setup(void)
121 if (memcmp(loadparm_str
, LOADPARM_PROMPT
, LOADPARM_LEN
) == 0) {
122 menu_set_parms(QIPL_FLAG_BM_OPTS_CMD
, 0);
126 /* If loadparm was set to any other value, then do not enable menu */
127 if (memcmp(loadparm_str
, LOADPARM_EMPTY
, LOADPARM_LEN
) != 0) {
132 case S390_IPL_TYPE_CCW
:
133 case S390_IPL_TYPE_QEMU_SCSI
:
134 menu_set_parms(qipl
.qipl_flags
& BOOT_MENU_FLAG_MASK
,
135 qipl
.boot_menu_timeout
);
141 * Initialize the channel I/O subsystem so we can talk to our ipl/boot device.
143 static void css_setup(void)
146 * Unconditionally enable mss support. In every sane configuration this
147 * will succeed; and even if it doesn't, stsch_err() can handle it.
149 enable_mss_facility();
153 * Collect various pieces of information from the hypervisor/hardware that
154 * we'll use to determine exactly how we'll boot.
156 static void boot_setup(void)
158 char lpmsg
[] = "LOADPARM=[________]\n";
160 sclp_get_loadparm_ascii(loadparm_str
);
161 memcpy(lpmsg
+ 10, loadparm_str
, 8);
164 have_iplb
= store_iplb(&iplb
);
167 static void find_boot_device(void)
169 VDev
*vdev
= virtio_get_device();
174 for (ssid
= 0; ssid
< 0x3; ssid
++) {
175 blk_schid
.ssid
= ssid
;
176 found
= find_subch(-1);
181 panic("Could not find a suitable boot device (none specified)\n");
185 case S390_IPL_TYPE_CCW
:
186 debug_print_int("device no. ", iplb
.ccw
.devno
);
187 blk_schid
.ssid
= iplb
.ccw
.ssid
& 0x3;
188 debug_print_int("ssid ", blk_schid
.ssid
);
189 found
= find_subch(iplb
.ccw
.devno
);
191 case S390_IPL_TYPE_QEMU_SCSI
:
192 vdev
->scsi_device_selected
= true;
193 vdev
->selected_scsi_device
.channel
= iplb
.scsi
.channel
;
194 vdev
->selected_scsi_device
.target
= iplb
.scsi
.target
;
195 vdev
->selected_scsi_device
.lun
= iplb
.scsi
.lun
;
196 blk_schid
.ssid
= iplb
.scsi
.ssid
& 0x3;
197 found
= find_subch(iplb
.scsi
.devno
);
200 panic("List-directed IPL not supported yet!\n");
203 IPL_assert(found
, "Boot device not found\n");
206 static void virtio_setup(void)
208 VDev
*vdev
= virtio_get_device();
209 QemuIplParameters
*early_qipl
= (QemuIplParameters
*)QIPL_ADDRESS
;
211 memcpy(&qipl
, early_qipl
, sizeof(QemuIplParameters
));
217 if (virtio_get_device_type() == VIRTIO_ID_NET
) {
218 sclp_print("Network boot device detected\n");
219 vdev
->netboot_start_addr
= qipl
.netboot_start_addr
;
221 virtio_blk_setup_device(blk_schid
);
222 IPL_assert(virtio_ipl_disk_is_valid(), "No valid IPL device detected");
232 enable_subchannel(blk_schid
);
235 case CU_TYPE_DASD_3990
:
236 case CU_TYPE_DASD_2107
:
237 dasd_ipl(blk_schid
, cutype
); /* no return */
241 zipl_load(); /* no return */
244 print_int("Attempting to boot from unexpected device type", cutype
);
248 panic("Failed to load OS from hard disk\n");
249 return 0; /* make compiler happy */