s390-ccw: move auxiliary IPL data to separate location
[qemu/ar7.git] / pc-bios / s390-ccw / main.c
blobe41b264a6fcb9a850a88f29d9be5b4365d335fc9
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[8] = { 0, 0, 0, 0, 0, 0, 0, 0 };
19 QemuIplParameters qipl;
22 * Priniciples of Operations (SA22-7832-09) chapter 17 requires that
23 * a subsystem-identification is at 184-187 and bytes 188-191 are zero
24 * after list-directed-IPL and ccw-IPL.
26 void write_subsystem_identification(void)
28 SubChannelId *schid = (SubChannelId *) 184;
29 uint32_t *zeroes = (uint32_t *) 188;
31 *schid = blk_schid;
32 *zeroes = 0;
35 void panic(const char *string)
37 sclp_print(string);
38 disabled_wait();
39 while (1) { }
42 unsigned int get_loadparm_index(void)
44 return atoui(loadparm);
47 static bool find_dev(Schib *schib, int dev_no)
49 int i, r;
51 for (i = 0; i < 0x10000; i++) {
52 blk_schid.sch_no = i;
53 r = stsch_err(blk_schid, schib);
54 if ((r == 3) || (r == -EIO)) {
55 break;
57 if (!schib->pmcw.dnv) {
58 continue;
60 if (!virtio_is_supported(blk_schid)) {
61 continue;
63 /* Skip net devices since no IPLB is created and therefore no
64 * no network bootloader has been loaded
66 if (virtio_get_device_type() == VIRTIO_ID_NET && dev_no < 0) {
67 continue;
69 if ((dev_no < 0) || (schib->pmcw.dev == dev_no)) {
70 return true;
74 return false;
77 static void virtio_setup(void)
79 Schib schib;
80 int ssid;
81 bool found = false;
82 uint16_t dev_no;
83 char ldp[] = "LOADPARM=[________]\n";
84 VDev *vdev = virtio_get_device();
85 QemuIplParameters *early_qipl = (QemuIplParameters *)QIPL_ADDRESS;
88 * We unconditionally enable mss support. In every sane configuration,
89 * this will succeed; and even if it doesn't, stsch_err() can deal
90 * with the consequences.
92 enable_mss_facility();
94 sclp_get_loadparm_ascii(loadparm);
95 memcpy(ldp + 10, loadparm, 8);
96 sclp_print(ldp);
98 memcpy(&qipl, early_qipl, sizeof(QemuIplParameters));
100 if (store_iplb(&iplb)) {
101 switch (iplb.pbt) {
102 case S390_IPL_TYPE_CCW:
103 dev_no = iplb.ccw.devno;
104 debug_print_int("device no. ", dev_no);
105 blk_schid.ssid = iplb.ccw.ssid & 0x3;
106 debug_print_int("ssid ", blk_schid.ssid);
107 found = find_dev(&schib, dev_no);
108 break;
109 case S390_IPL_TYPE_QEMU_SCSI:
110 vdev->scsi_device_selected = true;
111 vdev->selected_scsi_device.channel = iplb.scsi.channel;
112 vdev->selected_scsi_device.target = iplb.scsi.target;
113 vdev->selected_scsi_device.lun = iplb.scsi.lun;
114 blk_schid.ssid = iplb.scsi.ssid & 0x3;
115 found = find_dev(&schib, iplb.scsi.devno);
116 break;
117 default:
118 panic("List-directed IPL not supported yet!\n");
120 } else {
121 for (ssid = 0; ssid < 0x3; ssid++) {
122 blk_schid.ssid = ssid;
123 found = find_dev(&schib, -1);
124 if (found) {
125 break;
130 IPL_assert(found, "No virtio device found");
132 if (virtio_get_device_type() == VIRTIO_ID_NET) {
133 sclp_print("Network boot device detected\n");
134 vdev->netboot_start_addr = qipl.netboot_start_addr;
135 } else {
136 virtio_blk_setup_device(blk_schid);
138 IPL_assert(virtio_ipl_disk_is_valid(), "No valid IPL device detected");
142 int main(void)
144 sclp_setup();
145 virtio_setup();
147 zipl_load(); /* no return */
149 panic("Failed to load OS from hard disk\n");
150 return 0; /* make compiler happy */