1 /* 2 * S390 virtio-ccw loading program 3 * 4 * Copyright (c) 2013 Alexander Graf <agraf@suse.de> 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 "s390-ccw.h" 12 #include "virtio.h" 13 14 char stack[PAGE_SIZE * 8] __attribute__((__aligned__(PAGE_SIZE))); 15 uint64_t boot_value; 16 17 void virtio_panic(const char *string) 18 { 19 sclp_print(string); 20 disabled_wait(); 21 while (1) { } 22 } 23 24 static void virtio_setup(uint64_t dev_info) 25 { 26 struct subchannel_id blk_schid = { .one = 1 }; 27 struct schib schib; 28 int i; 29 int r; 30 bool found = false; 31 bool check_devno = false; 32 uint16_t dev_no = -1; 33 34 if (dev_info != -1) { 35 check_devno = true; 36 dev_no = dev_info & 0xffff; 37 debug_print_int("device no. ", dev_no); 38 blk_schid.ssid = (dev_info >> 16) & 0x3; 39 if (blk_schid.ssid != 0) { 40 debug_print_int("ssid ", blk_schid.ssid); 41 if (enable_mss_facility() != 0) { 42 virtio_panic("Failed to enable mss facility\n"); 43 } 44 } 45 } 46 47 for (i = 0; i < 0x10000; i++) { 48 blk_schid.sch_no = i; 49 r = stsch_err(blk_schid, &schib); 50 if (r == 3) { 51 break; 52 } 53 if (schib.pmcw.dnv) { 54 if (!check_devno || (schib.pmcw.dev == dev_no)) { 55 if (virtio_is_blk(blk_schid)) { 56 found = true; 57 break; 58 } 59 } 60 } 61 } 62 63 if (!found) { 64 virtio_panic("No virtio-blk device found!\n"); 65 } 66 67 virtio_setup_block(blk_schid); 68 69 if (!virtio_ipl_disk_is_valid()) { 70 virtio_panic("No valid hard disk detected.\n"); 71 } 72 } 73 74 int main(void) 75 { 76 sclp_setup(); 77 debug_print_int("boot reg[7] ", boot_value); 78 virtio_setup(boot_value); 79 80 zipl_load(); /* no return */ 81 82 virtio_panic("Failed to load OS from hard disk\n"); 83 return 0; /* make compiler happy */ 84 } 85