]>
Commit | Line | Data |
---|---|---|
92f2ca38 AG |
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" | |
60612d5c | 12 | #include "virtio.h" |
92f2ca38 | 13 | |
92f2ca38 | 14 | char stack[PAGE_SIZE * 8] __attribute__((__aligned__(PAGE_SIZE))); |
2be9d292 | 15 | char ring_area[PAGE_SIZE * 8] __attribute__((__aligned__(PAGE_SIZE))); |
ff151f4e | 16 | uint64_t boot_value; |
f17a8430 | 17 | static struct subchannel_id blk_schid = { .one = 1 }; |
f2879a5c CB |
18 | |
19 | /* | |
20 | * Priniciples of Operations (SA22-7832-09) chapter 17 requires that | |
21 | * a subsystem-identification is at 184-187 and bytes 188-191 are zero | |
22 | * after list-directed-IPL and ccw-IPL. | |
23 | */ | |
24 | void write_subsystem_identification(void) | |
25 | { | |
26 | struct subchannel_id *schid = (struct subchannel_id *) 184; | |
27 | uint32_t *zeroes = (uint32_t *) 188; | |
28 | ||
29 | *schid = blk_schid; | |
30 | *zeroes = 0; | |
31 | } | |
32 | ||
92f2ca38 AG |
33 | |
34 | void virtio_panic(const char *string) | |
35 | { | |
36 | sclp_print(string); | |
7f61cbc1 | 37 | disabled_wait(); |
92f2ca38 AG |
38 | while (1) { } |
39 | } | |
40 | ||
0f79b89b AY |
41 | static bool find_dev(struct schib *schib, int dev_no) |
42 | { | |
43 | int i, r; | |
44 | ||
45 | for (i = 0; i < 0x10000; i++) { | |
46 | blk_schid.sch_no = i; | |
47 | r = stsch_err(blk_schid, schib); | |
48 | if ((r == 3) || (r == -EIO)) { | |
49 | break; | |
50 | } | |
51 | if (!schib->pmcw.dnv) { | |
52 | continue; | |
53 | } | |
54 | if (!virtio_is_blk(blk_schid)) { | |
55 | continue; | |
56 | } | |
57 | if ((dev_no < 0) || (schib->pmcw.dev == dev_no)) { | |
58 | return true; | |
59 | } | |
60 | } | |
61 | ||
62 | return false; | |
63 | } | |
64 | ||
ff151f4e | 65 | static void virtio_setup(uint64_t dev_info) |
92f2ca38 | 66 | { |
22d67ab5 | 67 | struct schib schib; |
0f79b89b | 68 | int ssid; |
92f2ca38 | 69 | bool found = false; |
0f79b89b AY |
70 | uint16_t dev_no; |
71 | ||
72 | /* | |
73 | * We unconditionally enable mss support. In every sane configuration, | |
74 | * this will succeed; and even if it doesn't, stsch_err() can deal | |
75 | * with the consequences. | |
76 | */ | |
77 | enable_mss_facility(); | |
92f2ca38 | 78 | |
ff151f4e | 79 | if (dev_info != -1) { |
ff151f4e DD |
80 | dev_no = dev_info & 0xffff; |
81 | debug_print_int("device no. ", dev_no); | |
c8cda874 | 82 | blk_schid.ssid = (dev_info >> 16) & 0x3; |
0f79b89b AY |
83 | debug_print_int("ssid ", blk_schid.ssid); |
84 | found = find_dev(&schib, dev_no); | |
85 | } else { | |
86 | for (ssid = 0; ssid < 0x3; ssid++) { | |
87 | blk_schid.ssid = ssid; | |
88 | found = find_dev(&schib, -1); | |
89 | if (found) { | |
90 | break; | |
92f2ca38 AG |
91 | } |
92 | } | |
93 | } | |
94 | ||
95 | if (!found) { | |
96 | virtio_panic("No virtio-blk device found!\n"); | |
97 | } | |
98 | ||
99 | virtio_setup_block(blk_schid); | |
60612d5c ED |
100 | |
101 | if (!virtio_ipl_disk_is_valid()) { | |
102 | virtio_panic("No valid hard disk detected.\n"); | |
103 | } | |
92f2ca38 AG |
104 | } |
105 | ||
106 | int main(void) | |
107 | { | |
108 | sclp_setup(); | |
ff151f4e DD |
109 | debug_print_int("boot reg[7] ", boot_value); |
110 | virtio_setup(boot_value); | |
111 | ||
60612d5c ED |
112 | zipl_load(); /* no return */ |
113 | ||
114 | virtio_panic("Failed to load OS from hard disk\n"); | |
115 | return 0; /* make compiler happy */ | |
92f2ca38 | 116 | } |