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
12 #include "s390-arch.h"
18 char stack
[PAGE_SIZE
* 8] __attribute__((__aligned__(PAGE_SIZE
)));
19 static SubChannelId blk_schid
= { .one
= 1 };
20 static char loadparm_str
[LOADPARM_LEN
+ 1] = { 0, 0, 0, 0, 0, 0, 0, 0, 0 };
21 QemuIplParameters qipl
;
22 IplParameterBlock iplb
__attribute__((__aligned__(PAGE_SIZE
)));
23 static bool have_iplb
;
24 static uint16_t cutype
;
25 LowCore
const *lowcore
; /* Yes, this *is* a pointer to address 0 */
27 #define LOADPARM_PROMPT "PROMPT "
28 #define LOADPARM_EMPTY " "
29 #define BOOT_MENU_FLAG_MASK (QIPL_FLAG_BM_OPTS_CMD | QIPL_FLAG_BM_OPTS_ZIPL)
32 * Principles of Operations (SA22-7832-09) chapter 17 requires that
33 * a subsystem-identification is at 184-187 and bytes 188-191 are zero
34 * after list-directed-IPL and ccw-IPL.
36 void write_subsystem_identification(void)
38 SubChannelId
*schid
= (SubChannelId
*) 184;
39 uint32_t *zeroes
= (uint32_t *) 188;
45 void panic(const char *string
)
52 unsigned int get_loadparm_index(void)
54 return atoui(loadparm_str
);
58 * Find the subchannel connected to the given device (dev_no) and fill in the
59 * subchannel information block (schib) with the connected subchannel's info.
60 * NOTE: The global variable blk_schid is updated to contain the subchannel
63 * If the caller gives dev_no=-1 then the user did not specify a boot device.
64 * In this case we'll just use the first potentially bootable device we find.
66 static bool find_subch(int dev_no
)
72 for (i
= 0; i
< 0x10000; i
++) {
74 r
= stsch_err(blk_schid
, &schib
);
75 if ((r
== 3) || (r
== -EIO
)) {
78 if (!schib
.pmcw
.dnv
) {
82 enable_subchannel(blk_schid
);
83 cutype
= cu_type(blk_schid
);
86 * Note: we always have to run virtio_is_supported() here to make
87 * sure that the vdev.senseid data gets pre-initialized correctly
89 is_virtio
= virtio_is_supported(blk_schid
);
91 /* No specific devno given, just return 1st possibly bootable device */
97 * Skip net devices since no IPLB is created and therefore
98 * no network bootloader has been loaded
100 if (virtio_get_device_type() != VIRTIO_ID_NET
) {
105 case CU_TYPE_DASD_3990
:
106 case CU_TYPE_DASD_2107
:
113 /* Caller asked for a specific devno */
114 if (schib
.pmcw
.dev
== dev_no
) {
122 static void menu_setup(void)
124 if (memcmp(loadparm_str
, LOADPARM_PROMPT
, LOADPARM_LEN
) == 0) {
125 menu_set_parms(QIPL_FLAG_BM_OPTS_CMD
, 0);
129 /* If loadparm was set to any other value, then do not enable menu */
130 if (memcmp(loadparm_str
, LOADPARM_EMPTY
, LOADPARM_LEN
) != 0) {
135 case S390_IPL_TYPE_CCW
:
136 case S390_IPL_TYPE_QEMU_SCSI
:
137 menu_set_parms(qipl
.qipl_flags
& BOOT_MENU_FLAG_MASK
,
138 qipl
.boot_menu_timeout
);
144 * Initialize the channel I/O subsystem so we can talk to our ipl/boot device.
146 static void css_setup(void)
149 * Unconditionally enable mss support. In every sane configuration this
150 * will succeed; and even if it doesn't, stsch_err() can handle it.
152 enable_mss_facility();
156 * Collect various pieces of information from the hypervisor/hardware that
157 * we'll use to determine exactly how we'll boot.
159 static void boot_setup(void)
161 char lpmsg
[] = "LOADPARM=[________]\n";
163 sclp_get_loadparm_ascii(loadparm_str
);
164 memcpy(lpmsg
+ 10, loadparm_str
, 8);
167 have_iplb
= store_iplb(&iplb
);
170 static void find_boot_device(void)
172 VDev
*vdev
= virtio_get_device();
177 for (ssid
= 0; ssid
< 0x3; ssid
++) {
178 blk_schid
.ssid
= ssid
;
179 found
= find_subch(-1);
184 panic("Could not find a suitable boot device (none specified)\n");
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 void 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 virtio_blk_setup_device(blk_schid
);
225 IPL_assert(virtio_ipl_disk_is_valid(), "No valid IPL device detected");
235 enable_subchannel(blk_schid
);
238 case CU_TYPE_DASD_3990
:
239 case CU_TYPE_DASD_2107
:
240 dasd_ipl(blk_schid
, cutype
); /* no return */
244 zipl_load(); /* no return */
247 print_int("Attempting to boot from unexpected device type", cutype
);
251 panic("Failed to load OS from hard disk\n");
252 return 0; /* make compiler happy */