pc-bios/s390-ccw: enable virtio-scsi
[qemu.git] / pc-bios / s390-ccw / main.c
blob1c9e0791abd09fa7231d000bbf340bda44cc9909
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 "s390-ccw.h"
12 #include "virtio.h"
14 char stack[PAGE_SIZE * 8] __attribute__((__aligned__(PAGE_SIZE)));
15 uint64_t boot_value;
16 static SubChannelId blk_schid = { .one = 1 };
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.
23 void write_subsystem_identification(void)
25 SubChannelId *schid = (SubChannelId *) 184;
26 uint32_t *zeroes = (uint32_t *) 188;
28 *schid = blk_schid;
29 *zeroes = 0;
33 void panic(const char *string)
35 sclp_print(string);
36 disabled_wait();
37 while (1) { }
40 static bool find_dev(Schib *schib, int dev_no)
42 int i, r;
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;
50 if (!schib->pmcw.dnv) {
51 continue;
53 if (!virtio_is_supported(blk_schid)) {
54 continue;
56 if ((dev_no < 0) || (schib->pmcw.dev == dev_no)) {
57 return true;
61 return false;
64 static void virtio_setup(uint64_t dev_info)
66 Schib schib;
67 int ssid;
68 bool found = false;
69 uint16_t dev_no;
72 * We unconditionally enable mss support. In every sane configuration,
73 * this will succeed; and even if it doesn't, stsch_err() can deal
74 * with the consequences.
76 enable_mss_facility();
78 if (dev_info != -1) {
79 dev_no = dev_info & 0xffff;
80 debug_print_int("device no. ", dev_no);
81 blk_schid.ssid = (dev_info >> 16) & 0x3;
82 debug_print_int("ssid ", blk_schid.ssid);
83 found = find_dev(&schib, dev_no);
84 } else {
85 for (ssid = 0; ssid < 0x3; ssid++) {
86 blk_schid.ssid = ssid;
87 found = find_dev(&schib, -1);
88 if (found) {
89 break;
94 IPL_assert(found, "No virtio device found");
96 virtio_setup_device(blk_schid);
98 IPL_assert(virtio_ipl_disk_is_valid(), "No valid IPL device detected");
101 int main(void)
103 sclp_setup();
104 debug_print_int("boot reg[7] ", boot_value);
105 virtio_setup(boot_value);
107 zipl_load(); /* no return */
109 panic("Failed to load OS from hard disk\n");
110 return 0; /* make compiler happy */