xref: /openbmc/qemu/pc-bios/s390-ccw/main.c (revision bfb27e60)
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 uint64_t boot_value;
16 struct subchannel_id blk_schid = { .one = 1 };
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     struct subchannel_id *schid = (struct subchannel_id *) 184;
26     uint32_t *zeroes = (uint32_t *) 188;
27 
28     *schid = blk_schid;
29     *zeroes = 0;
30 }
31 
32 
33 void virtio_panic(const char *string)
34 {
35     sclp_print(string);
36     disabled_wait();
37     while (1) { }
38 }
39 
40 static void virtio_setup(uint64_t dev_info)
41 {
42     struct schib schib;
43     int i;
44     int r;
45     bool found = false;
46     bool check_devno = false;
47     uint16_t dev_no = -1;
48 
49     if (dev_info != -1) {
50         check_devno = true;
51         dev_no = dev_info & 0xffff;
52         debug_print_int("device no. ", dev_no);
53         blk_schid.ssid = (dev_info >> 16) & 0x3;
54         if (blk_schid.ssid != 0) {
55             debug_print_int("ssid ", blk_schid.ssid);
56             if (enable_mss_facility() != 0) {
57                 virtio_panic("Failed to enable mss facility\n");
58             }
59         }
60     }
61 
62     for (i = 0; i < 0x10000; i++) {
63         blk_schid.sch_no = i;
64         r = stsch_err(blk_schid, &schib);
65         if (r == 3) {
66             break;
67         }
68         if (schib.pmcw.dnv) {
69             if (!check_devno || (schib.pmcw.dev == dev_no)) {
70                 if (virtio_is_blk(blk_schid)) {
71                     found = true;
72                     break;
73                 }
74             }
75         }
76     }
77 
78     if (!found) {
79         virtio_panic("No virtio-blk device found!\n");
80     }
81 
82     virtio_setup_block(blk_schid);
83 
84     if (!virtio_ipl_disk_is_valid()) {
85         virtio_panic("No valid hard disk detected.\n");
86     }
87 }
88 
89 int main(void)
90 {
91     sclp_setup();
92     debug_print_int("boot reg[7] ", boot_value);
93     virtio_setup(boot_value);
94 
95     zipl_load(); /* no return */
96 
97     virtio_panic("Failed to load OS from hard disk\n");
98     return 0; /* make compiler happy */
99 }
100