apb: replace OBIO interrupt numbers in pci_pbmA_map_irq() with constants
[qemu/ar7.git] / pc-bios / s390-ccw / main.c
blob401e9dbb5feccc147d62e93767c6bac924484e3c
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 "libc.h"
12 #include "s390-ccw.h"
13 #include "virtio.h"
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 };
21 * Priniciples of Operations (SA22-7832-09) chapter 17 requires that
22 * a subsystem-identification is at 184-187 and bytes 188-191 are zero
23 * after list-directed-IPL and ccw-IPL.
25 void write_subsystem_identification(void)
27 SubChannelId *schid = (SubChannelId *) 184;
28 uint32_t *zeroes = (uint32_t *) 188;
30 *schid = blk_schid;
31 *zeroes = 0;
34 void panic(const char *string)
36 sclp_print(string);
37 disabled_wait();
38 while (1) { }
41 unsigned int get_loadparm_index(void)
43 const char *lp = loadparm;
44 int i;
45 unsigned int idx = 0;
47 for (i = 0; i < 8; i++) {
48 char c = lp[i];
50 if (c < '0' || c > '9') {
51 break;
54 idx *= 10;
55 idx += c - '0';
58 return idx;
61 static bool find_dev(Schib *schib, int dev_no)
63 int i, r;
65 for (i = 0; i < 0x10000; i++) {
66 blk_schid.sch_no = i;
67 r = stsch_err(blk_schid, schib);
68 if ((r == 3) || (r == -EIO)) {
69 break;
71 if (!schib->pmcw.dnv) {
72 continue;
74 if (!virtio_is_supported(blk_schid)) {
75 continue;
77 /* Skip net devices since no IPLB is created and therefore no
78 * no network bootloader has been loaded
80 if (virtio_get_device_type() == VIRTIO_ID_NET && dev_no < 0) {
81 continue;
83 if ((dev_no < 0) || (schib->pmcw.dev == dev_no)) {
84 return true;
88 return false;
91 static void virtio_setup(void)
93 Schib schib;
94 int ssid;
95 bool found = false;
96 uint16_t dev_no;
97 char ldp[] = "LOADPARM=[________]\n";
98 VDev *vdev = virtio_get_device();
101 * We unconditionally enable mss support. In every sane configuration,
102 * this will succeed; and even if it doesn't, stsch_err() can deal
103 * with the consequences.
105 enable_mss_facility();
107 sclp_get_loadparm_ascii(loadparm);
108 memcpy(ldp + 10, loadparm, 8);
109 sclp_print(ldp);
111 if (store_iplb(&iplb)) {
112 switch (iplb.pbt) {
113 case S390_IPL_TYPE_CCW:
114 dev_no = iplb.ccw.devno;
115 debug_print_int("device no. ", dev_no);
116 blk_schid.ssid = iplb.ccw.ssid & 0x3;
117 debug_print_int("ssid ", blk_schid.ssid);
118 found = find_dev(&schib, dev_no);
119 break;
120 case S390_IPL_TYPE_QEMU_SCSI:
121 vdev->scsi_device_selected = true;
122 vdev->selected_scsi_device.channel = iplb.scsi.channel;
123 vdev->selected_scsi_device.target = iplb.scsi.target;
124 vdev->selected_scsi_device.lun = iplb.scsi.lun;
125 blk_schid.ssid = iplb.scsi.ssid & 0x3;
126 found = find_dev(&schib, iplb.scsi.devno);
127 break;
128 default:
129 panic("List-directed IPL not supported yet!\n");
131 } else {
132 for (ssid = 0; ssid < 0x3; ssid++) {
133 blk_schid.ssid = ssid;
134 found = find_dev(&schib, -1);
135 if (found) {
136 break;
141 IPL_assert(found, "No virtio device found");
143 if (virtio_get_device_type() == VIRTIO_ID_NET) {
144 sclp_print("Network boot device detected\n");
145 vdev->netboot_start_addr = iplb.ccw.netboot_start_addr;
146 } else {
147 virtio_blk_setup_device(blk_schid);
149 IPL_assert(virtio_ipl_disk_is_valid(), "No valid IPL device detected");
153 int main(void)
155 sclp_setup();
156 virtio_setup();
158 zipl_load(); /* no return */
160 panic("Failed to load OS from hard disk\n");
161 return 0; /* make compiler happy */