2 * S390 virtio-ccw loading program
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[8] = { 0, 0, 0, 0, 0, 0, 0, 0 };
19 QemuIplParameters qipl;
21 #define LOADPARM_PROMPT "PROMPT "
22 #define LOADPARM_EMPTY "........"
25 * Priniciples of Operations (SA22-7832-09) chapter 17 requires that
26 * a subsystem-identification is at 184-187 and bytes 188-191 are zero
27 * after list-directed-IPL and ccw-IPL.
29 void write_subsystem_identification(void)
31 SubChannelId *schid = (SubChannelId *) 184;
32 uint32_t *zeroes = (uint32_t *) 188;
38 void panic(const char *string)
45 unsigned int get_loadparm_index(void)
47 return atoui(loadparm);
50 static bool find_dev(Schib *schib, int dev_no)
54 for (i = 0; i < 0x10000; i++) {
56 r = stsch_err(blk_schid, schib);
57 if ((r == 3) || (r == -EIO)) {
60 if (!schib->pmcw.dnv) {
63 if (!virtio_is_supported(blk_schid)) {
66 /* Skip net devices since no IPLB is created and therefore no
67 * no network bootloader has been loaded
69 if (virtio_get_device_type() == VIRTIO_ID_NET && dev_no < 0) {
72 if ((dev_no < 0) || (schib->pmcw.dev == dev_no)) {
80 static void menu_setup(void)
82 if (memcmp(loadparm, LOADPARM_PROMPT, 8) == 0) {
83 menu_set_parms(QIPL_FLAG_BM_OPTS_CMD, 0);
87 /* If loadparm was set to any other value, then do not enable menu */
88 if (memcmp(loadparm, LOADPARM_EMPTY, 8) != 0) {
93 case S390_IPL_TYPE_CCW:
94 menu_set_parms(qipl.qipl_flags & QIPL_FLAG_BM_OPTS_CMD,
95 qipl.boot_menu_timeout);
100 static void virtio_setup(void)
106 char ldp[] = "LOADPARM=[________]\n";
107 VDev *vdev = virtio_get_device();
108 QemuIplParameters *early_qipl = (QemuIplParameters *)QIPL_ADDRESS;
111 * We unconditionally enable mss support. In every sane configuration,
112 * this will succeed; and even if it doesn't, stsch_err() can deal
113 * with the consequences.
115 enable_mss_facility();
117 sclp_get_loadparm_ascii(loadparm);
118 memcpy(ldp + 10, loadparm, 8);
121 memcpy(&qipl, early_qipl, sizeof(QemuIplParameters));
123 if (store_iplb(&iplb)) {
125 case S390_IPL_TYPE_CCW:
126 dev_no = iplb.ccw.devno;
127 debug_print_int("device no. ", dev_no);
128 blk_schid.ssid = iplb.ccw.ssid & 0x3;
129 debug_print_int("ssid ", blk_schid.ssid);
130 found = find_dev(&schib, dev_no);
132 case S390_IPL_TYPE_QEMU_SCSI:
133 vdev->scsi_device_selected = true;
134 vdev->selected_scsi_device.channel = iplb.scsi.channel;
135 vdev->selected_scsi_device.target = iplb.scsi.target;
136 vdev->selected_scsi_device.lun = iplb.scsi.lun;
137 blk_schid.ssid = iplb.scsi.ssid & 0x3;
138 found = find_dev(&schib, iplb.scsi.devno);
141 panic("List-directed IPL not supported yet!\n");
145 for (ssid = 0; ssid < 0x3; ssid++) {
146 blk_schid.ssid = ssid;
147 found = find_dev(&schib, -1);
154 IPL_assert(found, "No virtio device found");
156 if (virtio_get_device_type() == VIRTIO_ID_NET) {
157 sclp_print("Network boot device detected\n");
158 vdev->netboot_start_addr = qipl.netboot_start_addr;
160 virtio_blk_setup_device(blk_schid);
162 IPL_assert(virtio_ipl_disk_is_valid(), "No valid IPL device detected");
171 zipl_load(); /* no return */
173 panic("Failed to load OS from hard disk\n");
174 return 0; /* make compiler happy */