]>
Commit | Line | Data |
---|---|---|
92f2ca38 AG |
1 | /* |
2 | * S390 virtio-ccw loading program | |
3 | * | |
4 | * Copyright (c) 2013 Alexander Graf <[email protected]> | |
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 | ||
90806fec | 11 | #include "libc.h" |
92f2ca38 | 12 | #include "s390-ccw.h" |
60612d5c | 13 | #include "virtio.h" |
92f2ca38 | 14 | |
92f2ca38 | 15 | char stack[PAGE_SIZE * 8] __attribute__((__aligned__(PAGE_SIZE))); |
b88d7fa5 | 16 | static SubChannelId blk_schid = { .one = 1 }; |
d046c51d | 17 | IplParameterBlock iplb __attribute__((__aligned__(PAGE_SIZE))); |
95fa1af8 | 18 | static char loadparm[8] = { 0, 0, 0, 0, 0, 0, 0, 0 }; |
118ee80f | 19 | QemuIplParameters qipl; |
f2879a5c | 20 | |
9eaa654a CW |
21 | #define LOADPARM_PROMPT "PROMPT " |
22 | #define LOADPARM_EMPTY "........" | |
53b310ce | 23 | #define BOOT_MENU_FLAG_MASK (QIPL_FLAG_BM_OPTS_CMD | QIPL_FLAG_BM_OPTS_ZIPL) |
9eaa654a | 24 | |
f2879a5c CB |
25 | /* |
26 | * Priniciples of Operations (SA22-7832-09) chapter 17 requires that | |
27 | * a subsystem-identification is at 184-187 and bytes 188-191 are zero | |
28 | * after list-directed-IPL and ccw-IPL. | |
29 | */ | |
30 | void write_subsystem_identification(void) | |
31 | { | |
b88d7fa5 | 32 | SubChannelId *schid = (SubChannelId *) 184; |
f2879a5c CB |
33 | uint32_t *zeroes = (uint32_t *) 188; |
34 | ||
35 | *schid = blk_schid; | |
36 | *zeroes = 0; | |
37 | } | |
38 | ||
c9262e8a | 39 | void panic(const char *string) |
92f2ca38 AG |
40 | { |
41 | sclp_print(string); | |
7f61cbc1 | 42 | disabled_wait(); |
92f2ca38 AG |
43 | while (1) { } |
44 | } | |
45 | ||
95fa1af8 FA |
46 | unsigned int get_loadparm_index(void) |
47 | { | |
fc0e2087 | 48 | return atoui(loadparm); |
95fa1af8 FA |
49 | } |
50 | ||
b88d7fa5 | 51 | static bool find_dev(Schib *schib, int dev_no) |
0f79b89b AY |
52 | { |
53 | int i, r; | |
54 | ||
55 | for (i = 0; i < 0x10000; i++) { | |
56 | blk_schid.sch_no = i; | |
57 | r = stsch_err(blk_schid, schib); | |
58 | if ((r == 3) || (r == -EIO)) { | |
59 | break; | |
60 | } | |
61 | if (!schib->pmcw.dnv) { | |
62 | continue; | |
63 | } | |
a1102ceb | 64 | if (!virtio_is_supported(blk_schid)) { |
0f79b89b AY |
65 | continue; |
66 | } | |
99b72e0f FA |
67 | /* Skip net devices since no IPLB is created and therefore no |
68 | * no network bootloader has been loaded | |
69 | */ | |
70 | if (virtio_get_device_type() == VIRTIO_ID_NET && dev_no < 0) { | |
71 | continue; | |
72 | } | |
0f79b89b AY |
73 | if ((dev_no < 0) || (schib->pmcw.dev == dev_no)) { |
74 | return true; | |
75 | } | |
76 | } | |
77 | ||
78 | return false; | |
79 | } | |
80 | ||
9eaa654a CW |
81 | static void menu_setup(void) |
82 | { | |
83 | if (memcmp(loadparm, LOADPARM_PROMPT, 8) == 0) { | |
84 | menu_set_parms(QIPL_FLAG_BM_OPTS_CMD, 0); | |
85 | return; | |
86 | } | |
87 | ||
88 | /* If loadparm was set to any other value, then do not enable menu */ | |
89 | if (memcmp(loadparm, LOADPARM_EMPTY, 8) != 0) { | |
90 | return; | |
91 | } | |
92 | ||
93 | switch (iplb.pbt) { | |
94 | case S390_IPL_TYPE_CCW: | |
ffb4a1c8 | 95 | case S390_IPL_TYPE_QEMU_SCSI: |
53b310ce | 96 | menu_set_parms(qipl.qipl_flags & BOOT_MENU_FLAG_MASK, |
9eaa654a CW |
97 | qipl.boot_menu_timeout); |
98 | return; | |
99 | } | |
100 | } | |
101 | ||
d046c51d | 102 | static void virtio_setup(void) |
92f2ca38 | 103 | { |
b88d7fa5 | 104 | Schib schib; |
0f79b89b | 105 | int ssid; |
92f2ca38 | 106 | bool found = false; |
0f79b89b | 107 | uint16_t dev_no; |
95fa1af8 | 108 | char ldp[] = "LOADPARM=[________]\n"; |
99b72e0f | 109 | VDev *vdev = virtio_get_device(); |
118ee80f | 110 | QemuIplParameters *early_qipl = (QemuIplParameters *)QIPL_ADDRESS; |
0f79b89b AY |
111 | |
112 | /* | |
113 | * We unconditionally enable mss support. In every sane configuration, | |
114 | * this will succeed; and even if it doesn't, stsch_err() can deal | |
115 | * with the consequences. | |
116 | */ | |
117 | enable_mss_facility(); | |
92f2ca38 | 118 | |
95fa1af8 FA |
119 | sclp_get_loadparm_ascii(loadparm); |
120 | memcpy(ldp + 10, loadparm, 8); | |
121 | sclp_print(ldp); | |
122 | ||
118ee80f CW |
123 | memcpy(&qipl, early_qipl, sizeof(QemuIplParameters)); |
124 | ||
d046c51d AY |
125 | if (store_iplb(&iplb)) { |
126 | switch (iplb.pbt) { | |
127 | case S390_IPL_TYPE_CCW: | |
128 | dev_no = iplb.ccw.devno; | |
129 | debug_print_int("device no. ", dev_no); | |
130 | blk_schid.ssid = iplb.ccw.ssid & 0x3; | |
131 | debug_print_int("ssid ", blk_schid.ssid); | |
132 | found = find_dev(&schib, dev_no); | |
133 | break; | |
b39b7718 | 134 | case S390_IPL_TYPE_QEMU_SCSI: |
b39b7718 ED |
135 | vdev->scsi_device_selected = true; |
136 | vdev->selected_scsi_device.channel = iplb.scsi.channel; | |
137 | vdev->selected_scsi_device.target = iplb.scsi.target; | |
138 | vdev->selected_scsi_device.lun = iplb.scsi.lun; | |
139 | blk_schid.ssid = iplb.scsi.ssid & 0x3; | |
140 | found = find_dev(&schib, iplb.scsi.devno); | |
141 | break; | |
d046c51d AY |
142 | default: |
143 | panic("List-directed IPL not supported yet!\n"); | |
144 | } | |
9eaa654a | 145 | menu_setup(); |
0f79b89b AY |
146 | } else { |
147 | for (ssid = 0; ssid < 0x3; ssid++) { | |
148 | blk_schid.ssid = ssid; | |
149 | found = find_dev(&schib, -1); | |
150 | if (found) { | |
151 | break; | |
92f2ca38 AG |
152 | } |
153 | } | |
154 | } | |
155 | ||
80ba3e24 | 156 | IPL_assert(found, "No virtio device found"); |
92f2ca38 | 157 | |
99b72e0f FA |
158 | if (virtio_get_device_type() == VIRTIO_ID_NET) { |
159 | sclp_print("Network boot device detected\n"); | |
118ee80f | 160 | vdev->netboot_start_addr = qipl.netboot_start_addr; |
99b72e0f | 161 | } else { |
867e039a | 162 | virtio_blk_setup_device(blk_schid); |
60612d5c | 163 | |
99b72e0f FA |
164 | IPL_assert(virtio_ipl_disk_is_valid(), "No valid IPL device detected"); |
165 | } | |
92f2ca38 AG |
166 | } |
167 | ||
168 | int main(void) | |
169 | { | |
170 | sclp_setup(); | |
d046c51d | 171 | virtio_setup(); |
ff151f4e | 172 | |
60612d5c ED |
173 | zipl_load(); /* no return */ |
174 | ||
c9262e8a | 175 | panic("Failed to load OS from hard disk\n"); |
60612d5c | 176 | return 0; /* make compiler happy */ |
92f2ca38 | 177 | } |