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 };
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;
34 void panic(const char *string
)
41 unsigned int get_loadparm_index(void)
43 const char *lp
= loadparm
;
47 for (i
= 0; i
< 8; i
++) {
50 if (c
< '0' || c
> '9') {
61 static bool find_dev(Schib
*schib
, int dev_no
)
65 for (i
= 0; i
< 0x10000; i
++) {
67 r
= stsch_err(blk_schid
, schib
);
68 if ((r
== 3) || (r
== -EIO
)) {
71 if (!schib
->pmcw
.dnv
) {
74 if (!virtio_is_supported(blk_schid
)) {
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) {
83 if ((dev_no
< 0) || (schib
->pmcw
.dev
== dev_no
)) {
91 static void virtio_setup(void)
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);
111 if (store_iplb(&iplb
)) {
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
);
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
);
129 panic("List-directed IPL not supported yet!\n");
132 for (ssid
= 0; ssid
< 0x3; ssid
++) {
133 blk_schid
.ssid
= ssid
;
134 found
= find_dev(&schib
, -1);
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
;
147 virtio_blk_setup_device(blk_schid
);
149 IPL_assert(virtio_ipl_disk_is_valid(), "No valid IPL device detected");
158 zipl_load(); /* no return */
160 panic("Failed to load OS from hard disk\n");
161 return 0; /* make compiler happy */