s390-bios: decouple cio setup from virtio
[qemu/ar7.git] / pc-bios / s390-ccw / main.c
blobe82fe2ce23150731b8c09fcf52bbe39352e4ef1a
1 /*
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
8 * directory.
9 */
11 #include "libc.h"
12 #include "s390-ccw.h"
13 #include "virtio.h"
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;
35 *schid = blk_schid;
36 *zeroes = 0;
39 void panic(const char *string)
41 sclp_print(string);
42 disabled_wait();
43 while (1) { }
46 unsigned int get_loadparm_index(void)
48 return atoui(loadparm_str);
51 static bool find_dev(Schib *schib, int dev_no)
53 int i, r;
55 for (i = 0; i < 0x10000; i++) {
56 blk_schid.sch_no = i;
57 r = stsch_err(blk_schid, schib);
58 if ((r == 3) || (r == -EIO)) {
59 break;
61 if (!schib->pmcw.dnv) {
62 continue;
64 if (!virtio_is_supported(blk_schid)) {
65 continue;
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) {
71 continue;
73 if ((dev_no < 0) || (schib->pmcw.dev == dev_no)) {
74 return true;
78 return false;
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);
85 return;
88 /* If loadparm was set to any other value, then do not enable menu */
89 if (memcmp(loadparm_str, LOADPARM_EMPTY, LOADPARM_LEN) != 0) {
90 return;
93 switch (iplb.pbt) {
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);
98 return;
103 * Initialize the channel I/O subsystem so we can talk to our ipl/boot device.
105 static void css_setup(void)
108 * Unconditionally enable mss support. In every sane configuration this
109 * will succeed; and even if it doesn't, stsch_err() can handle it.
111 enable_mss_facility();
114 static void virtio_setup(void)
116 Schib schib;
117 int ssid;
118 bool found = false;
119 uint16_t dev_no;
120 char ldp[] = "LOADPARM=[________]\n";
121 VDev *vdev = virtio_get_device();
122 QemuIplParameters *early_qipl = (QemuIplParameters *)QIPL_ADDRESS;
124 sclp_get_loadparm_ascii(loadparm_str);
125 memcpy(ldp + 10, loadparm_str, LOADPARM_LEN);
126 sclp_print(ldp);
128 memcpy(&qipl, early_qipl, sizeof(QemuIplParameters));
130 if (store_iplb(&iplb)) {
131 switch (iplb.pbt) {
132 case S390_IPL_TYPE_CCW:
133 dev_no = iplb.ccw.devno;
134 debug_print_int("device no. ", dev_no);
135 blk_schid.ssid = iplb.ccw.ssid & 0x3;
136 debug_print_int("ssid ", blk_schid.ssid);
137 found = find_dev(&schib, dev_no);
138 break;
139 case S390_IPL_TYPE_QEMU_SCSI:
140 vdev->scsi_device_selected = true;
141 vdev->selected_scsi_device.channel = iplb.scsi.channel;
142 vdev->selected_scsi_device.target = iplb.scsi.target;
143 vdev->selected_scsi_device.lun = iplb.scsi.lun;
144 blk_schid.ssid = iplb.scsi.ssid & 0x3;
145 found = find_dev(&schib, iplb.scsi.devno);
146 break;
147 default:
148 panic("List-directed IPL not supported yet!\n");
150 menu_setup();
151 } else {
152 for (ssid = 0; ssid < 0x3; ssid++) {
153 blk_schid.ssid = ssid;
154 found = find_dev(&schib, -1);
155 if (found) {
156 break;
161 IPL_assert(found, "No virtio device found");
163 if (virtio_get_device_type() == VIRTIO_ID_NET) {
164 sclp_print("Network boot device detected\n");
165 vdev->netboot_start_addr = qipl.netboot_start_addr;
166 } else {
167 virtio_blk_setup_device(blk_schid);
169 IPL_assert(virtio_ipl_disk_is_valid(), "No valid IPL device detected");
173 int main(void)
175 sclp_setup();
176 css_setup();
177 virtio_setup();
179 zipl_load(); /* no return */
181 panic("Failed to load OS from hard disk\n");
182 return 0; /* make compiler happy */