Merge remote-tracking branch 'remotes/cody/tags/block-pull-request' into staging
[qemu.git] / pc-bios / s390-ccw / main.c
1 /*
2 * S390 virtio-ccw loading program
3 *
4 * Copyright (c) 2013 Alexander Graf <agraf@suse.de>
5 *
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 */
10
11 #include "s390-ccw.h"
12 #include "virtio.h"
13
14 char stack[PAGE_SIZE * 8] __attribute__((__aligned__(PAGE_SIZE)));
15 static SubChannelId blk_schid = { .one = 1 };
16 IplParameterBlock iplb __attribute__((__aligned__(PAGE_SIZE)));
17
18 /*
19 * Priniciples of Operations (SA22-7832-09) chapter 17 requires that
20 * a subsystem-identification is at 184-187 and bytes 188-191 are zero
21 * after list-directed-IPL and ccw-IPL.
22 */
23 void write_subsystem_identification(void)
24 {
25 SubChannelId *schid = (SubChannelId *) 184;
26 uint32_t *zeroes = (uint32_t *) 188;
27
28 *schid = blk_schid;
29 *zeroes = 0;
30 }
31
32
33 void panic(const char *string)
34 {
35 sclp_print(string);
36 disabled_wait();
37 while (1) { }
38 }
39
40 static bool find_dev(Schib *schib, int dev_no)
41 {
42 int i, r;
43
44 for (i = 0; i < 0x10000; i++) {
45 blk_schid.sch_no = i;
46 r = stsch_err(blk_schid, schib);
47 if ((r == 3) || (r == -EIO)) {
48 break;
49 }
50 if (!schib->pmcw.dnv) {
51 continue;
52 }
53 if (!virtio_is_supported(blk_schid)) {
54 continue;
55 }
56 /* Skip net devices since no IPLB is created and therefore no
57 * no network bootloader has been loaded
58 */
59 if (virtio_get_device_type() == VIRTIO_ID_NET && dev_no < 0) {
60 continue;
61 }
62 if ((dev_no < 0) || (schib->pmcw.dev == dev_no)) {
63 return true;
64 }
65 }
66
67 return false;
68 }
69
70 static void virtio_setup(void)
71 {
72 Schib schib;
73 int ssid;
74 bool found = false;
75 uint16_t dev_no;
76 VDev *vdev = virtio_get_device();
77
78 /*
79 * We unconditionally enable mss support. In every sane configuration,
80 * this will succeed; and even if it doesn't, stsch_err() can deal
81 * with the consequences.
82 */
83 enable_mss_facility();
84
85 if (store_iplb(&iplb)) {
86 switch (iplb.pbt) {
87 case S390_IPL_TYPE_CCW:
88 dev_no = iplb.ccw.devno;
89 debug_print_int("device no. ", dev_no);
90 blk_schid.ssid = iplb.ccw.ssid & 0x3;
91 debug_print_int("ssid ", blk_schid.ssid);
92 found = find_dev(&schib, dev_no);
93 break;
94 case S390_IPL_TYPE_QEMU_SCSI:
95 vdev->scsi_device_selected = true;
96 vdev->selected_scsi_device.channel = iplb.scsi.channel;
97 vdev->selected_scsi_device.target = iplb.scsi.target;
98 vdev->selected_scsi_device.lun = iplb.scsi.lun;
99 blk_schid.ssid = iplb.scsi.ssid & 0x3;
100 found = find_dev(&schib, iplb.scsi.devno);
101 break;
102 default:
103 panic("List-directed IPL not supported yet!\n");
104 }
105 } else {
106 for (ssid = 0; ssid < 0x3; ssid++) {
107 blk_schid.ssid = ssid;
108 found = find_dev(&schib, -1);
109 if (found) {
110 break;
111 }
112 }
113 }
114
115 IPL_assert(found, "No virtio device found");
116
117 if (virtio_get_device_type() == VIRTIO_ID_NET) {
118 sclp_print("Network boot device detected\n");
119 vdev->netboot_start_addr = iplb.ccw.netboot_start_addr;
120 } else {
121 virtio_setup_device(blk_schid);
122
123 IPL_assert(virtio_ipl_disk_is_valid(), "No valid IPL device detected");
124 }
125 }
126
127 int main(void)
128 {
129 sclp_setup();
130 virtio_setup();
131
132 zipl_load(); /* no return */
133
134 panic("Failed to load OS from hard disk\n");
135 return 0; /* make compiler happy */
136 }