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