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
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
;
22 * Priniciples of Operations (SA22-7832-09) chapter 17 requires that
23 * a subsystem-identification is at 184-187 and bytes 188-191 are zero
24 * after list-directed-IPL and ccw-IPL.
26 void write_subsystem_identification(void)
28 SubChannelId
*schid
= (SubChannelId
*) 184;
29 uint32_t *zeroes
= (uint32_t *) 188;
35 void panic(const char *string
)
42 unsigned int get_loadparm_index(void)
44 return atoui(loadparm
);
47 static bool find_dev(Schib
*schib
, int dev_no
)
51 for (i
= 0; i
< 0x10000; i
++) {
53 r
= stsch_err(blk_schid
, schib
);
54 if ((r
== 3) || (r
== -EIO
)) {
57 if (!schib
->pmcw
.dnv
) {
60 if (!virtio_is_supported(blk_schid
)) {
63 /* Skip net devices since no IPLB is created and therefore no
64 * no network bootloader has been loaded
66 if (virtio_get_device_type() == VIRTIO_ID_NET
&& dev_no
< 0) {
69 if ((dev_no
< 0) || (schib
->pmcw
.dev
== dev_no
)) {
77 static void virtio_setup(void)
83 char ldp
[] = "LOADPARM=[________]\n";
84 VDev
*vdev
= virtio_get_device();
85 QemuIplParameters
*early_qipl
= (QemuIplParameters
*)QIPL_ADDRESS
;
88 * We unconditionally enable mss support. In every sane configuration,
89 * this will succeed; and even if it doesn't, stsch_err() can deal
90 * with the consequences.
92 enable_mss_facility();
94 sclp_get_loadparm_ascii(loadparm
);
95 memcpy(ldp
+ 10, loadparm
, 8);
98 memcpy(&qipl
, early_qipl
, sizeof(QemuIplParameters
));
100 if (store_iplb(&iplb
)) {
102 case S390_IPL_TYPE_CCW
:
103 dev_no
= iplb
.ccw
.devno
;
104 debug_print_int("device no. ", dev_no
);
105 blk_schid
.ssid
= iplb
.ccw
.ssid
& 0x3;
106 debug_print_int("ssid ", blk_schid
.ssid
);
107 found
= find_dev(&schib
, dev_no
);
109 case S390_IPL_TYPE_QEMU_SCSI
:
110 vdev
->scsi_device_selected
= true;
111 vdev
->selected_scsi_device
.channel
= iplb
.scsi
.channel
;
112 vdev
->selected_scsi_device
.target
= iplb
.scsi
.target
;
113 vdev
->selected_scsi_device
.lun
= iplb
.scsi
.lun
;
114 blk_schid
.ssid
= iplb
.scsi
.ssid
& 0x3;
115 found
= find_dev(&schib
, iplb
.scsi
.devno
);
118 panic("List-directed IPL not supported yet!\n");
121 for (ssid
= 0; ssid
< 0x3; ssid
++) {
122 blk_schid
.ssid
= ssid
;
123 found
= find_dev(&schib
, -1);
130 IPL_assert(found
, "No virtio device found");
132 if (virtio_get_device_type() == VIRTIO_ID_NET
) {
133 sclp_print("Network boot device detected\n");
134 vdev
->netboot_start_addr
= qipl
.netboot_start_addr
;
136 virtio_blk_setup_device(blk_schid
);
138 IPL_assert(virtio_ipl_disk_is_valid(), "No valid IPL device detected");
147 zipl_load(); /* no return */
149 panic("Failed to load OS from hard disk\n");
150 return 0; /* make compiler happy */