Skip to contentSkip to conversation

for-2.1: s390-ccw bios patches

GIT PULL Applied Cornelia Huck 5 participants 18 messages Jun 27, 2014 – Jun 29, 2014

lore
Share & tools
lore
#0 lore raw

Here are some s390-ccw bios patches I'd like to see in 2.1. Being able to finally boot from dasd is quite a useful feature. Please consider pulling.

The following changes since commit ff4873cb8c81db89668d8b56e19e57b852edb5f5:

coroutine-win32.c: Add noinline attribute to work around gcc bug (2014-06-26 14:08:14 +0100)

are available in the git repository at:

git://github.com/cohuck/qemu.git tags/s390x-20140627

for you to fetch changes up to 77416f4075a673a27cfe5a7a34e93c0fa9810e35:

pc-bios/s390-ccw: update binary (2014-06-27 12:11:53 +0200)

----------------------------------------------------------------
A series of patches to the s390-ccw bios:
- code cleanup
- improved error reporting
- most important, support to ipl (boot) from ECKD DASD (CDL, LDL or CMS formatted)

----------------------------------------------------------------

Eugene (jno) Dvurechenski (9):
pc-bios/s390-ccw: make checkpatch happy pc-bios/s390-ccw: cleanup and enhance bootmap defintions pc-bios/s390-ccw: handle different sector sizes pc-bios/s390-ccw: add some utility code pc-bios/s390-ccw: Unify error handling pc-bios/s390-ccw: Add fill_hex_val func to provide better msgs pc-bios/s390-ccw: factor out ipl code pc-bios/s390-ccw: IPL from CDL-formatted ECKD DASD pc-bios/s390-ccw: IPL from LDL/CMS-formatted ECKD DASD

Jens Freimann (1):
pc-bios/s390-ccw: update binary

 pc-bios/s390-ccw.img          |  Bin 9432 -> 17624 bytes
 pc-bios/s390-ccw/bootmap.c    |  445 ++++++++++++++++++++++++++++-------------
 pc-bios/s390-ccw/bootmap.h    |  344 +++++++++++++++++++++++++++++++
 pc-bios/s390-ccw/main.c       |   13 +-
 pc-bios/s390-ccw/s390-ccw.h   |   38 ++--
 pc-bios/s390-ccw/sclp-ascii.c |    4 +-
 pc-bios/s390-ccw/virtio.c     |  122 +++++++++--
 pc-bios/s390-ccw/virtio.h     |   50 ++++-
 8 files changed, 837 insertions(+), 179 deletions(-)
 create mode 100644 pc-bios/s390-ccw/bootmap.h
Signature · 1 line
1.7.9.5
#1 lore raw

[Qemu-devel] [PULL 02/10] pc-bios/s390-ccw: cleanup and enhance bootmap defintions

From: "Eugene (jno) Dvurechenski" <[email protected]>

Add declarations to describe structure of different dasd IPL sources (eckd and fba). Move the structure definitions to a new header bootmap.h. While we are at it, change structs to typedefs.

---
 pc-bios/s390-ccw/bootmap.c |   66 +++---------
 pc-bios/s390-ccw/bootmap.h |  254 ++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 269 insertions(+), 51 deletions(-)
 create mode 100644 pc-bios/s390-ccw/bootmap.h
pc-bios/s390-ccw/bootmap.c +15 -51
index 753c288..c216030 100644
@@ -9,6 +9,7 @@
  */
 
 #include "s390-ccw.h"
+#include "bootmap.h"
 
 /* #define DEBUG_FALLBACK */
 
@@ -20,41 +21,6 @@
     do { } while (0)
 #endif
 
-struct scsi_blockptr {
-    uint64_t blockno;
-    uint16_t size;
-    uint16_t blockct;
-    uint8_t reserved[4];
-} __attribute__ ((packed));
-
-struct component_entry {
-    struct scsi_blockptr data;
-    uint8_t pad[7];
-    uint8_t component_type;
-    uint64_t load_address;
-} __attribute((packed));
-
-struct component_header {
-    uint8_t magic[4];
-    uint8_t type;
-    uint8_t reserved[27];
-} __attribute((packed));
-
-struct mbr {
-    uint8_t magic[4];
-    uint32_t version_id;
-    uint8_t reserved[8];
-    struct scsi_blockptr blockptr;
-} __attribute__ ((packed));
-
-#define ZIPL_MAGIC              "zIPL"
-
-#define ZIPL_COMP_HEADER_IPL    0x00
-#define ZIPL_COMP_HEADER_DUMP   0x01
-
-#define ZIPL_COMP_ENTRY_LOAD    0x02
-#define ZIPL_COMP_ENTRY_EXEC    0x01
-
 /* Scratch space */
 static uint8_t sec[SECTOR_SIZE] __attribute__((__aligned__(SECTOR_SIZE)));
 
@@ -118,8 +84,6 @@ static int zipl_magic(uint8_t *ptr)
     return 1;
 }
 
-#define FREE_SPACE_FILLER '\xAA'
-
 static inline bool unused_space(const void *p, unsigned int size)
 {
     int i;
@@ -133,10 +97,10 @@ static inline bool unused_space(const void *p, unsigned int size)
     return true;
 }
 
-static int zipl_load_segment(struct component_entry *entry)
+static int zipl_load_segment(ComponentEntry *entry)
 {
-    const int max_entries = (SECTOR_SIZE / sizeof(struct scsi_blockptr));
-    struct scsi_blockptr *bprs = (void *)sec;
+    const int max_entries = (SECTOR_SIZE / sizeof(ScsiBlockPtr));
+    ScsiBlockPtr *bprs = (void *)sec;
     const int bprs_size = sizeof(sec);
     uint64_t blockno;
     long address;
@@ -170,7 +134,7 @@ static int zipl_load_segment(struct component_entry *entry)
             }
 
             if (bprs[i].blockct == 0 && unused_space(&bprs[i + 1],
-                sizeof(struct scsi_blockptr))) {
+                sizeof(ScsiBlockPtr))) {
                 /* This is a "continue" pointer.
                  * This ptr is the last one in the current script section.
                  * I.e. the next ptr must point to the unused memory area.
@@ -195,14 +159,14 @@ fail:
 }
 
 /* Run a zipl program */
-static int zipl_run(struct scsi_blockptr *pte)
+static int zipl_run(ScsiBlockPtr *pte)
 {
-    struct component_header *header;
-    struct component_entry *entry;
+    ComponentHeader *header;
+    ComponentEntry *entry;
     uint8_t tmp_sec[SECTOR_SIZE];
 
     virtio_read(pte->blockno, tmp_sec);
-    header = (struct component_header *)tmp_sec;
+    header = (ComponentHeader *)tmp_sec;
 
     if (!zipl_magic(tmp_sec)) {
         goto fail;
@@ -215,7 +179,7 @@ static int zipl_run(struct scsi_blockptr *pte)
     dputs("start loading images\n");
 
     /* Load image(s) into RAM */
-    entry = (struct component_entry *)(&header[1]);
+    entry = (ComponentEntry *)(&header[1]);
     while (entry->component_type == ZIPL_COMP_ENTRY_LOAD) {
         if (zipl_load_segment(entry) < 0) {
             goto fail;
@@ -244,11 +208,11 @@ fail:
 
 int zipl_load(void)
 {
-    struct mbr *mbr = (void *)sec;
+    ScsiMbr *mbr = (void *)sec;
     uint8_t *ns, *ns_end;
     int program_table_entries = 0;
-    int pte_len = sizeof(struct scsi_blockptr);
-    struct scsi_blockptr *prog_table_entry;
+    const int pte_len = sizeof(ScsiBlockPtr);
+    ScsiBlockPtr *prog_table_entry;
     const char *error = "";
 
     /* Grab the MBR */
@@ -276,7 +240,7 @@ int zipl_load(void)
 
     ns_end = sec + SECTOR_SIZE;
     for (ns = (sec + pte_len); (ns + pte_len) < ns_end; ns++) {
-        prog_table_entry = (struct scsi_blockptr *)ns;
+        prog_table_entry = (ScsiBlockPtr *)ns;
         if (!prog_table_entry->blockno) {
             break;
         }
@@ -292,7 +256,7 @@ int zipl_load(void)
 
     /* Run the default entry */
 
-    prog_table_entry = (struct scsi_blockptr *)(sec + pte_len);
+    prog_table_entry = (ScsiBlockPtr *)(sec + pte_len);
 
     return zipl_run(prog_table_entry);
 
pc-bios/s390-ccw/bootmap.h new file +254 -0

254 lines not on this page · raw message

Signature · 1 line
1.7.9.5
#2 lore raw

[Qemu-devel] [PULL 04/10] pc-bios/s390-ccw: add some utility code

In reply to Cornelia Huck

From: "Eugene (jno) Dvurechenski" <[email protected]>

IPL_assert(term,message) is introduced to handle error conditions. ebcdic_to_ascii() to convert chars (mostly to print VOLSERs). read_block() provision for unified block-number handling.

---
 pc-bios/s390-ccw/bootmap.c |   15 +-------
 pc-bios/s390-ccw/bootmap.h |   83 ++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 84 insertions(+), 14 deletions(-)
pc-bios/s390-ccw/bootmap.c +1 -14
index fa2ca26..bb8dd69 100644
@@ -86,25 +86,12 @@ static int zipl_magic(uint8_t *ptr)
     return 1;
 }
 
-static inline bool unused_space(const void *p, unsigned int size)
-{
-    int i;
-    const unsigned char *m = p;
-
-    for (i = 0; i < size; i++) {
-        if (m[i] != FREE_SPACE_FILLER) {
-            return false;
-        }
-    }
-    return true;
-}
-
 static int zipl_load_segment(ComponentEntry *entry)
 {
     const int max_entries = (MAX_SECTOR_SIZE / sizeof(ScsiBlockPtr));
     ScsiBlockPtr *bprs = (void *)sec;
     const int bprs_size = sizeof(sec);
-    uint64_t blockno;
+    block_number_t blockno;
     long address;
     int i;
 
pc-bios/s390-ccw/bootmap.h +83 -0

93 lines not on this page · raw message

Signature · 1 line
1.7.9.5
#3 lore raw

[Qemu-devel] [PULL 05/10] pc-bios/s390-ccw: Unify error handling

In reply to Cornelia Huck

From: "Eugene (jno) Dvurechenski" <[email protected]>

Convert to IPL_assert and friends

---
 pc-bios/s390-ccw/bootmap.c  |   82 +++++++++++--------------------------------
 pc-bios/s390-ccw/main.c     |   13 ++++---
 pc-bios/s390-ccw/s390-ccw.h |    2 +-
 3 files changed, 31 insertions(+), 66 deletions(-)
pc-bios/s390-ccw/bootmap.c +21 -61
index bb8dd69..1866a20 100644
@@ -86,7 +86,7 @@ static int zipl_magic(uint8_t *ptr)
     return 1;
 }
 
-static int zipl_load_segment(ComponentEntry *entry)
+static void zipl_load_segment(ComponentEntry *entry)
 {
     const int max_entries = (MAX_SECTOR_SIZE / sizeof(ScsiBlockPtr));
     ScsiBlockPtr *bprs = (void *)sec;
@@ -103,10 +103,8 @@ static int zipl_load_segment(ComponentEntry *entry)
 
     do {
         memset(bprs, FREE_SPACE_FILLER, bprs_size);
-        if (virtio_read(blockno, (uint8_t *)bprs)) {
-            debug_print_int("failed reading bprs at", blockno);
-            goto fail;
-        }
+        debug_print_int("reading bprs at", blockno);
+        read_block(blockno, bprs, "zipl_load_segment: cannot read block");
 
         for (i = 0;; i++) {
             u64 *cur_desc = (void *)&bprs[i];
@@ -134,21 +132,13 @@ static int zipl_load_segment(ComponentEntry *entry)
             }
             address = virtio_load_direct(cur_desc[0], cur_desc[1], 0,
                                          (void *)address);
-            if (address == -1) {
-                goto fail;
-            }
+            IPL_assert(address != -1, "zipl_load_segment: wrong IPL address");
         }
     } while (blockno);
-
-    return 0;
-
-fail:
-    sclp_print("failed loading segment\n");
-    return -1;
 }
 
 /* Run a zipl program */
-static int zipl_run(ScsiBlockPtr *pte)
+static void zipl_run(ScsiBlockPtr *pte)
 {
     ComponentHeader *header;
     ComponentEntry *entry;
@@ -157,75 +147,53 @@ static int zipl_run(ScsiBlockPtr *pte)
     virtio_read(pte->blockno, tmp_sec);
     header = (ComponentHeader *)tmp_sec;
 
-    if (!zipl_magic(tmp_sec)) {
-        goto fail;
-    }
+    IPL_assert(zipl_magic(tmp_sec), "zipl_run: zipl_magic");
 
-    if (header->type != ZIPL_COMP_HEADER_IPL) {
-        goto fail;
-    }
+    IPL_assert(header->type == ZIPL_COMP_HEADER_IPL,
+               "zipl_run: wrong header type");
 
     dputs("start loading images\n");
 
     /* Load image(s) into RAM */
     entry = (ComponentEntry *)(&header[1]);
     while (entry->component_type == ZIPL_COMP_ENTRY_LOAD) {
-        if (zipl_load_segment(entry) < 0) {
-            goto fail;
-        }
+        zipl_load_segment(entry);
 
         entry++;
 
-        if ((uint8_t *)(&entry[1]) > (tmp_sec + MAX_SECTOR_SIZE)) {
-            goto fail;
-        }
+        IPL_assert((uint8_t *)(&entry[1]) <= (tmp_sec + MAX_SECTOR_SIZE),
+                   "zipl_run: wrong entry size");
     }
 
-    if (entry->component_type != ZIPL_COMP_ENTRY_EXEC) {
-        goto fail;
-    }
+    IPL_assert(entry->component_type == ZIPL_COMP_ENTRY_EXEC,
+               "zipl_run: no EXEC entry");
 
     /* should not return */
     jump_to_IPL_code(entry->load_address);
-
-    return 0;
-
-fail:
-    sclp_print("failed running zipl\n");
-    return -1;
 }
 
-int zipl_load(void)
+void zipl_load(void)
 {
     ScsiMbr *mbr = (void *)sec;
     uint8_t *ns, *ns_end;
     int program_table_entries = 0;
     const int pte_len = sizeof(ScsiBlockPtr);
     ScsiBlockPtr *prog_table_entry;
-    const char *error = "";
 
     /* Grab the MBR */
-    virtio_read(0, (void *)mbr);
+    read_block(0, mbr, "zipl_load: cannot read block 0");
 
     dputs("checking magic\n");
 
-    if (!zipl_magic(mbr->magic)) {
-        error = "zipl_magic 1";
-        goto fail;
-    }
+    IPL_assert(zipl_magic(mbr->magic), "zipl_load: zipl_magic 1");
 
     debug_print_int("program table", mbr->blockptr.blockno);
 
     /* Parse the program table */
-    if (virtio_read(mbr->blockptr.blockno, sec)) {
-        error = "virtio_read";
-        goto fail;
-    }
+    read_block(mbr->blockptr.blockno, sec,
+               "zipl_load: cannot read program table");
 
-    if (!zipl_magic(sec)) {
-        error = "zipl_magic 2";
-        goto fail;
-    }
+    IPL_assert(zipl_magic(sec), "zipl_load: zipl_magic 2");
 
     ns_end = sec + virtio_get_block_size();
     for (ns = (sec + pte_len); (ns + pte_len) < ns_end; ns++) {
@@ -239,19 +207,11 @@ int zipl_load(void)
 
     debug_print_int("program table entries", program_table_entries);
 
-    if (!program_table_entries) {
-        goto fail;
-    }
+    IPL_assert(program_table_entries, "zipl_load: no program table");
 
     /* Run the default entry */
 
     prog_table_entry = (ScsiBlockPtr *)(sec + pte_len);
 
-    return zipl_run(prog_table_entry);
-
-fail:
-    sclp_print("failed loading zipl: ");
-    sclp_print(error);
-    sclp_print("\n");
-    return -1;
+    zipl_run(prog_table_entry); /* no return */
 }
pc-bios/s390-ccw/main.c +9 -4
index 5c33766..dbfb40e 100644
@@ -9,6 +9,7 @@
  */
 
 #include "s390-ccw.h"
+#include "virtio.h"
 
 char stack[PAGE_SIZE * 8] __attribute__((__aligned__(PAGE_SIZE)));
 uint64_t boot_value;
@@ -64,6 +65,10 @@ static void virtio_setup(uint64_t dev_info)
     }
 
     virtio_setup_block(blk_schid);
+
+    if (!virtio_ipl_disk_is_valid()) {
+        virtio_panic("No valid hard disk detected.\n");
+    }
 }
 
 int main(void)
@@ -72,8 +77,8 @@ int main(void)
     debug_print_int("boot reg[7] ", boot_value);
     virtio_setup(boot_value);
 
-    if (zipl_load() < 0)
-        sclp_print("Failed to load OS from hard disk\n");
-    disabled_wait();
-    while (1) { }
+    zipl_load(); /* no return */
+
+    virtio_panic("Failed to load OS from hard disk\n");
+    return 0; /* make compiler happy */
 }
pc-bios/s390-ccw/s390-ccw.h +1 -1
index b6c0a5b..29468fb 100644
@@ -64,7 +64,7 @@ int virtio_read(ulong sector, void *load_addr);
 int enable_mss_facility(void);
 
 /* bootmap.c */
-int zipl_load(void);
+void zipl_load(void);
 
 static inline void *memset(void *s, int c, size_t n)
 {
Signature · 1 line
1.7.9.5
#4 lore raw

[Qemu-devel] [PULL 01/10] pc-bios/s390-ccw: make checkpatch happy

In reply to Cornelia Huck

From: "Eugene (jno) Dvurechenski" <[email protected]>

Remove tabs, tweak whitespace and comments.

---
 pc-bios/s390-ccw/bootmap.c    |   37 ++++++++++++++++++++-----------------
 pc-bios/s390-ccw/s390-ccw.h   |   20 ++++++++++----------
 pc-bios/s390-ccw/sclp-ascii.c |    4 ++--
 pc-bios/s390-ccw/virtio.c     |   26 +++++++++++++-------------
 pc-bios/s390-ccw/virtio.h     |    2 +-
 5 files changed, 46 insertions(+), 43 deletions(-)
pc-bios/s390-ccw/bootmap.c +20 -17
index 5ee3fcb..753c288 100644
@@ -10,7 +10,7 @@
 
 #include "s390-ccw.h"
 
-// #define DEBUG_FALLBACK
+/* #define DEBUG_FALLBACK */
 
 #ifdef DEBUG_FALLBACK
 #define dputs(txt) \
@@ -47,13 +47,13 @@ struct mbr {
     struct scsi_blockptr blockptr;
 } __attribute__ ((packed));
 
-#define ZIPL_MAGIC			"zIPL"
+#define ZIPL_MAGIC              "zIPL"
 
-#define ZIPL_COMP_HEADER_IPL		0x00
-#define ZIPL_COMP_HEADER_DUMP		0x01
+#define ZIPL_COMP_HEADER_IPL    0x00
+#define ZIPL_COMP_HEADER_DUMP   0x01
 
-#define ZIPL_COMP_ENTRY_LOAD		0x02
-#define ZIPL_COMP_ENTRY_EXEC		0x01
+#define ZIPL_COMP_ENTRY_LOAD    0x02
+#define ZIPL_COMP_ENTRY_EXEC    0x01
 
 /* Scratch space */
 static uint8_t sec[SECTOR_SIZE] __attribute__((__aligned__(SECTOR_SIZE)));
@@ -107,8 +107,8 @@ static void jump_to_IPL_code(uint64_t address)
 /* Check for ZIPL magic. Returns 0 if not matched. */
 static int zipl_magic(uint8_t *ptr)
 {
-    uint32_t *p = (void*)ptr;
-    uint32_t *z = (void*)ZIPL_MAGIC;
+    uint32_t *p = (void *)ptr;
+    uint32_t *z = (void *)ZIPL_MAGIC;
 
     if (*p != *z) {
         debug_print_int("invalid magic", *p);
@@ -136,7 +136,7 @@ static inline bool unused_space(const void *p, unsigned int size)
 static int zipl_load_segment(struct component_entry *entry)
 {
     const int max_entries = (SECTOR_SIZE / sizeof(struct scsi_blockptr));
-    struct scsi_blockptr *bprs = (void*)sec;
+    struct scsi_blockptr *bprs = (void *)sec;
     const int bprs_size = sizeof(sec);
     uint64_t blockno;
     long address;
@@ -156,16 +156,18 @@ static int zipl_load_segment(struct component_entry *entry)
         }
 
         for (i = 0;; i++) {
-            u64 *cur_desc = (void*)&bprs[i];
+            u64 *cur_desc = (void *)&bprs[i];
 
             blockno = bprs[i].blockno;
-            if (!blockno)
+            if (!blockno) {
                 break;
+            }
 
             /* we need the updated blockno for the next indirect entry in the
                chain, but don't want to advance address */
-            if (i == (max_entries - 1))
+            if (i == (max_entries - 1)) {
                 break;
+            }
 
             if (bprs[i].blockct == 0 && unused_space(&bprs[i + 1],
                 sizeof(struct scsi_blockptr))) {
@@ -178,9 +180,10 @@ static int zipl_load_segment(struct component_entry *entry)
                 break;
             }
             address = virtio_load_direct(cur_desc[0], cur_desc[1], 0,
-                                         (void*)address);
-            if (address == -1)
+                                         (void *)address);
+            if (address == -1) {
                 goto fail;
+            }
         }
     } while (blockno);
 
@@ -220,7 +223,7 @@ static int zipl_run(struct scsi_blockptr *pte)
 
         entry++;
 
-        if ((uint8_t*)(&entry[1]) > (tmp_sec + SECTOR_SIZE)) {
+        if ((uint8_t *)(&entry[1]) > (tmp_sec + SECTOR_SIZE)) {
             goto fail;
         }
     }
@@ -241,7 +244,7 @@ fail:
 
 int zipl_load(void)
 {
-    struct mbr *mbr = (void*)sec;
+    struct mbr *mbr = (void *)sec;
     uint8_t *ns, *ns_end;
     int program_table_entries = 0;
     int pte_len = sizeof(struct scsi_blockptr);
@@ -249,7 +252,7 @@ int zipl_load(void)
     const char *error = "";
 
     /* Grab the MBR */
-    virtio_read(0, (void*)mbr);
+    virtio_read(0, (void *)mbr);
 
     dputs("checking magic\n");
 
pc-bios/s390-ccw/s390-ccw.h +10 -10
index 5e871ac..fe1dd22 100644
@@ -34,10 +34,10 @@ typedef unsigned long long __u64;
 #define PAGE_SIZE 4096
 
 #ifndef EIO
-#define EIO	1
+#define EIO     1
 #endif
 #ifndef EBUSY
-#define EBUSY	2
+#define EBUSY   2
 #endif
 #ifndef NULL
 #define NULL    0
@@ -57,7 +57,7 @@ void sclp_setup(void);
 
 /* virtio.c */
 unsigned long virtio_load_direct(ulong rec_list1, ulong rec_list2,
-				 ulong subchan_id, void *load_addr);
+                                 ulong subchan_id, void *load_addr);
 bool virtio_is_blk(struct subchannel_id schid);
 void virtio_setup_block(struct subchannel_id schid);
 int virtio_read(ulong sector, void *load_addr);
@@ -88,7 +88,7 @@ static inline void fill_hex(char *out, unsigned char val)
 
 static inline void print_int(const char *desc, u64 addr)
 {
-    unsigned char *addr_c = (unsigned char*)&addr;
+    unsigned char *addr_c = (unsigned char *)&addr;
     char out[] = ": 0xffffffffffffffff\n";
     unsigned int i;
 
@@ -118,16 +118,16 @@ static inline void debug_print_addr(const char *desc, void *p)
  *           Hypercall functions               *
  ***********************************************/
 
-#define KVM_S390_VIRTIO_NOTIFY		0
-#define KVM_S390_VIRTIO_RESET		1
-#define KVM_S390_VIRTIO_SET_STATUS	2
+#define KVM_S390_VIRTIO_NOTIFY          0
+#define KVM_S390_VIRTIO_RESET           1
+#define KVM_S390_VIRTIO_SET_STATUS      2
 #define KVM_S390_VIRTIO_CCW_NOTIFY      3
 
 static inline void yield(void)
 {
-	asm volatile ("diag 0,0,0x44"
-                      : :
-		      : "memory", "cc");
+    asm volatile ("diag 0,0,0x44"
+                  : :
+                  : "memory", "cc");
 }
 
 #define SECTOR_SIZE 512
pc-bios/s390-ccw/sclp-ascii.c +2 -2
index 1c93937..761fb44 100644
@@ -33,7 +33,7 @@ static int sclp_service_call(unsigned int command, void *sccb)
 
 static void sclp_set_write_mask(void)
 {
-    WriteEventMask *sccb = (void*)_sccb;
+    WriteEventMask *sccb = (void *)_sccb;
 
     sccb->h.length = sizeof(WriteEventMask);
     sccb->mask_length = sizeof(unsigned int);
@@ -68,7 +68,7 @@ static void _memcpy(char *dest, const char *src, int len)
 void sclp_print(const char *str)
 {
     int len = _strlen(str);
-    WriteEventData *sccb = (void*)_sccb;
+    WriteEventData *sccb = (void *)_sccb;
 
     sccb->h.length = sizeof(WriteEventData) + len;
     sccb->h.function_code = SCLP_FC_NORMAL_WRITE;
pc-bios/s390-ccw/virtio.c +13 -13
index bbb3c4f..c845b14 100644
@@ -18,22 +18,22 @@ static char chsc_page[PAGE_SIZE] __attribute__((__aligned__(PAGE_SIZE)));
 static long kvm_hypercall(unsigned long nr, unsigned long param1,
                           unsigned long param2)
 {
-	register ulong r_nr asm("1") = nr;
-	register ulong r_param1 asm("2") = param1;
-	register ulong r_param2 asm("3") = param2;
-	register long retval asm("2");
+    register ulong r_nr asm("1") = nr;
+    register ulong r_param1 asm("2") = param1;
+    register ulong r_param2 asm("3") = param2;
+    register long retval asm("2");
 
-	asm volatile ("diag 2,4,0x500"
-		      : "=d" (retval)
-		      : "d" (r_nr), "0" (r_param1), "r"(r_param2)
-		      : "memory", "cc");
+    asm volatile ("diag 2,4,0x500"
+                  : "=d" (retval)
+                  : "d" (r_nr), "0" (r_param1), "r"(r_param2)
+                  : "memory", "cc");
 
-	return retval;
+    return retval;
 }
 
 static void virtio_notify(struct subchannel_id schid)
 {
-    kvm_hypercall(KVM_S390_VIRTIO_CCW_NOTIFY, *(u32*)&schid, 0);
+    kvm_hypercall(KVM_S390_VIRTIO_CCW_NOTIFY, *(u32 *)&schid, 0);
 }
 
 /***********************************************
@@ -236,7 +236,7 @@ static int virtio_read_many(ulong sector, void *load_addr, int sec_num)
 }
 
 unsigned long virtio_load_direct(ulong rec_list1, ulong rec_list2,
-				 ulong subchan_id, void *load_addr)
+                                 ulong subchan_id, void *load_addr)
 {
     u8 status;
     int sec = rec_list1;
@@ -249,7 +249,7 @@ unsigned long virtio_load_direct(ulong rec_list1, ulong rec_list2,
     }
 
     sclp_print(".");
-    status = virtio_read_many(sec, (void*)addr, sec_num);
+    status = virtio_read_many(sec, (void *)addr, sec_num);
     if (status) {
         virtio_panic("I/O Error");
     }
@@ -274,7 +274,7 @@ void virtio_setup_block(struct subchannel_id schid)
     if (run_ccw(schid, CCW_CMD_READ_VQ_CONF, &config, sizeof(config))) {
         virtio_panic("Could not get block device configuration\n");
     }
-    vring_init(&block, config.num, (void*)(100 * 1024 * 1024),
+    vring_init(&block, config.num, (void *)(100 * 1024 * 1024),
                KVM_S390_VIRTIO_RING_ALIGN);
 
     info.queue = (100ULL * 1024ULL* 1024ULL);
pc-bios/s390-ccw/virtio.h +1 -1
index 772a63f..c2990ea 100644
@@ -66,7 +66,7 @@ struct virtio_dev {
     char *config;
 };
 
-#define KVM_S390_VIRTIO_RING_ALIGN	4096
+#define KVM_S390_VIRTIO_RING_ALIGN  4096
 
 #define VRING_USED_F_NO_NOTIFY  1
 
Signature · 1 line
1.7.9.5
#5 lore raw

[Qemu-devel] [PULL 03/10] pc-bios/s390-ccw: handle different sector sizes

In reply to Cornelia Huck

From: "Eugene (jno) Dvurechenski" <[email protected]>

Use the virtio device's configuration to figure out the disk geometry and use a sector size based upon the layout.

---
 pc-bios/s390-ccw/bootmap.c  |   12 +++---
 pc-bios/s390-ccw/s390-ccw.h |    2 +-
 pc-bios/s390-ccw/virtio.c   |   96 ++++++++++++++++++++++++++++++++++++++++---
 pc-bios/s390-ccw/virtio.h   |   48 ++++++++++++++++++++++
 4 files changed, 147 insertions(+), 11 deletions(-)
pc-bios/s390-ccw/bootmap.c +7 -5
index c216030..fa2ca26 100644
@@ -10,6 +10,7 @@
 
 #include "s390-ccw.h"
 #include "bootmap.h"
+#include "virtio.h"
 
 /* #define DEBUG_FALLBACK */
 
@@ -22,7 +23,8 @@
 #endif
 
 /* Scratch space */
-static uint8_t sec[SECTOR_SIZE] __attribute__((__aligned__(SECTOR_SIZE)));
+static uint8_t sec[MAX_SECTOR_SIZE]
+__attribute__((__aligned__(MAX_SECTOR_SIZE)));
 
 typedef struct ResetInfo {
     uint32_t ipl_mask;
@@ -99,7 +101,7 @@ static inline bool unused_space(const void *p, unsigned int size)
 
 static int zipl_load_segment(ComponentEntry *entry)
 {
-    const int max_entries = (SECTOR_SIZE / sizeof(ScsiBlockPtr));
+    const int max_entries = (MAX_SECTOR_SIZE / sizeof(ScsiBlockPtr));
     ScsiBlockPtr *bprs = (void *)sec;
     const int bprs_size = sizeof(sec);
     uint64_t blockno;
@@ -163,7 +165,7 @@ static int zipl_run(ScsiBlockPtr *pte)
 {
     ComponentHeader *header;
     ComponentEntry *entry;
-    uint8_t tmp_sec[SECTOR_SIZE];
+    uint8_t tmp_sec[MAX_SECTOR_SIZE];
 
     virtio_read(pte->blockno, tmp_sec);
     header = (ComponentHeader *)tmp_sec;
@@ -187,7 +189,7 @@ static int zipl_run(ScsiBlockPtr *pte)
 
         entry++;
 
-        if ((uint8_t *)(&entry[1]) > (tmp_sec + SECTOR_SIZE)) {
+        if ((uint8_t *)(&entry[1]) > (tmp_sec + MAX_SECTOR_SIZE)) {
             goto fail;
         }
     }
@@ -238,7 +240,7 @@ int zipl_load(void)
         goto fail;
     }
 
-    ns_end = sec + SECTOR_SIZE;
+    ns_end = sec + virtio_get_block_size();
     for (ns = (sec + pte_len); (ns + pte_len) < ns_end; ns++) {
         prog_table_entry = (ScsiBlockPtr *)ns;
         if (!prog_table_entry->blockno) {
pc-bios/s390-ccw/s390-ccw.h +1 -1
index fe1dd22..b6c0a5b 100644
@@ -130,6 +130,6 @@ static inline void yield(void)
                   : "memory", "cc");
 }
 
-#define SECTOR_SIZE 512
+#define MAX_SECTOR_SIZE 4096
 
 #endif /* S390_CCW_H */
pc-bios/s390-ccw/virtio.c +91 -5

145 lines not on this page · raw message

pc-bios/s390-ccw/virtio.h +48 -0

52 lines not on this page · raw message

Signature · 1 line
1.7.9.5
#6 lore raw

Re: [Qemu-devel] [PULL 03/10] pc-bios/s390-ccw: handle different sector sizes

Quoted 40 lines · Cornelia Huck

From: "Eugene (jno) Dvurechenski" <[email protected]>

Use the virtio device's configuration to figure out the disk geometry and use a sector size based upon the layout.

---
  pc-bios/s390-ccw/bootmap.c  |   12 +++---
  pc-bios/s390-ccw/s390-ccw.h |    2 +-
  pc-bios/s390-ccw/virtio.c   |   96 ++++++++++++++++++++++++++++++++++++++++---
  pc-bios/s390-ccw/virtio.h   |   48 ++++++++++++++++++++++
  4 files changed, 147 insertions(+), 11 deletions(-)
pc-bios/s390-ccw/bootmap.c +3 -1
index c216030..fa2ca26 100644
@@ -10,6 +10,7 @@
 
  #include "s390-ccw.h"
  #include "bootmap.h"
+#include "virtio.h"
 
  /* #define DEBUG_FALLBACK */
 
@@ -22,7 +23,8 @@
  #endif
 
  /* Scratch space */
-static uint8_t sec[SECTOR_SIZE] __attribute__((__aligned__(SECTOR_SIZE)));
+static uint8_t sec[MAX_SECTOR_SIZE]
+__attribute__((__aligned__(MAX_SECTOR_SIZE)));
 
  typedef struct ResetInfo {
      uint32_t ipl_mask;

pc-bios/s390-ccw/bootmap.c static inline bool unused_space(const void *p, unsigned int size) · line 104

Quoted 5 lines
pc-bios/s390-ccw/bootmap.c +1 -1
@@ -99,7 +101,7 @@ static inline bool unused_space(const void *p, unsigned int size)
 
  static int zipl_load_segment(ComponentEntry *entry)
  {
-    const int max_entries = (SECTOR_SIZE / sizeof(ScsiBlockPtr));
+    const int max_entries = (MAX_SECTOR_SIZE / sizeof(ScsiBlockPtr));

Is this really safe to increase? Doesn't max_entries depend on the real sector size?

Alex

#7 lore raw

Re: [Qemu-devel] [PULL 03/10] pc-bios/s390-ccw: handle different sector sizes

Quoted 35 lines · Alexander Graf
Quoted 33 lines · Cornelia Huck

From: "Eugene (jno) Dvurechenski" <[email protected]>

Use the virtio device's configuration to figure out the disk geometry and use a sector size based upon the layout.

---
  pc-bios/s390-ccw/bootmap.c  |   12 +++---
  pc-bios/s390-ccw/s390-ccw.h |    2 +-
  pc-bios/s390-ccw/virtio.c   |   96 ++++++++++++++++++++++++++++++++++++++++---
  pc-bios/s390-ccw/virtio.h   |   48 ++++++++++++++++++++++
  4 files changed, 147 insertions(+), 11 deletions(-)
pc-bios/s390-ccw/bootmap.c +3 -1
index c216030..fa2ca26 100644
@@ -10,6 +10,7 @@
    #include "s390-ccw.h"
  #include "bootmap.h"
+#include "virtio.h"
    /* #define DEBUG_FALLBACK */
  @@ -22,7 +23,8 @@
  #endif
    /* Scratch space */
-static uint8_t sec[SECTOR_SIZE] __attribute__((__aligned__(SECTOR_SIZE)));
+static uint8_t sec[MAX_SECTOR_SIZE]
+__attribute__((__aligned__(MAX_SECTOR_SIZE)));
    typedef struct ResetInfo {
Quoted 8 lines

pc-bios/s390-ccw/bootmap.c static inline bool unused_space(const void *p, unsigned int size) · line 103

Quoted 6 lines
      uint32_t ipl_mask;
pc-bios/s390-ccw/bootmap.c +1 -1
@@ -99,7 +101,7 @@ static inline bool unused_space(const void *p, unsigned int size)
    static int zipl_load_segment(ComponentEntry *entry)
  {
-    const int max_entries = (SECTOR_SIZE / sizeof(ScsiBlockPtr));
+    const int max_entries = (MAX_SECTOR_SIZE / sizeof(ScsiBlockPtr));

Is this really safe to increase? Doesn't max_entries depend on the real sector size?

I think this is now covered by this if statement:

            if (bprs[i].blockct == 0 && unused_space(&bprs[i + 1],
                sizeof(ScsiBlockPtr))) {

which was introduced by commit c77cd87cf54f003748f29c14ea1ddaecfc5c653f (pc-bios/s390-ccw: fix for fragmented SCSI bootmap).

So strictly speaking this if statement might not be needed any more:

        if (i == (max_entries - 1)) {

Eugene, can you confirm? If yes we could add this patch later on as a cleanup:

pc-bios/s390-ccw/bootmap.c +0 -7
@@ -303,7 +303,6 @@ static void ipl_eckd(ECKD_IPL_mode_t mode)
 
 static void zipl_load_segment(ComponentEntry *entry)
 {
-    const int max_entries = (SECTOR_SIZE / sizeof(ScsiBlockPtr));
     ScsiBlockPtr *bprs = (void *)sec;
     const int bprs_size = sizeof(sec);
     block_number_t blockno;
@@ -331,12 +330,6 @@ static void zipl_load_segment(ComponentEntry *entry)
                 break;
             }
 
-            /* we need the updated blockno for the next indirect entry in the
-               chain, but don't want to advance address */
-            if (i == (max_entries - 1)) {
-                break;
-            }
-
             if (bprs[i].blockct == 0 && unused_space(&bprs[i + 1],
                 sizeof(ScsiBlockPtr))) {
                 /* This is a "continue" pointer.
#8 lore raw

Re: [Qemu-devel] [PULL 03/10] pc-bios/s390-ccw: handle different sector sizes

Quoted 9 lines · Christian Borntraeger
Quoted 4 lines

Review

Quoted 2 lines
(quoted diff) +1 -1
-    const int max_entries = (SECTOR_SIZE / sizeof(ScsiBlockPtr));
+    const int max_entries = (MAX_SECTOR_SIZE / sizeof(ScsiBlockPtr));

Is this really safe to increase? Doesn't max_entries depend on the real sector size?

I think this is now covered by this if statement:

            if (bprs[i].blockct == 0 && unused_space(&bprs[i + 1],
                sizeof(ScsiBlockPtr))) {
Quoted 6 lines

which was introduced by commit c77cd87cf54f003748f29c14ea1ddaecfc5c653f (pc-bios/s390-ccw: fix for fragmented SCSI bootmap).

So strictly speaking this if statement might not be needed any more:

        if (i == (max_entries - 1)) {

Eugene, can you confirm? If yes we could add this patch later on as a cleanup:

I'd preserve both checks.
In theory, we may catch a table that consumes all scratch space and leave no unused entry.

Plus, this check for zero counter and last entry is for "continuation" pointer, not for end-of-table by itself.

I think now, this code may need even few more checks to cover more cases...

Signature · 5 lines
Best Regards,
Eugene "jno" Dvurechenski
zLinux (KVM) Development - Software Engineer
IBM Russia - Science & Technology Center
phone: +7 (495) 660 8940 ext. 1021

begin:vcard
fn:Eugene Dvurechenski
n:Dvurechenski;Eugene
org:IBM Systems & Technology Group;IBM S&T Center, Russia adr:;;Obrucheva st., bld.30/1, E2V, floor 4;Moscow;;117485;Russia email;internet:[email protected]
title:Software Engineer
tel;work:+7 (495) 660 8940 ext. 1021
tel;cell:+7 (903) 790-07-49
x-mozilla-html:FALSE
url:http://fsw.su/
version:2.1
end:vcard

#9 lore raw

Re: [Qemu-devel] [PULL 03/10] pc-bios/s390-ccw: handle different sector sizes

Quoted 19 lines · Eugene "jno" Dvurechenski
Quoted 9 lines · Christian Borntraeger
Quoted 4 lines

Review

Quoted 2 lines
(quoted diff) +1 -1
-    const int max_entries = (SECTOR_SIZE / sizeof(ScsiBlockPtr));
+    const int max_entries = (MAX_SECTOR_SIZE / sizeof(ScsiBlockPtr));

Is this really safe to increase? Doesn't max_entries depend on the real sector size?

I think this is now covered by this if statement:

            if (bprs[i].blockct == 0 && unused_space(&bprs[i + 1],
                sizeof(ScsiBlockPtr))) {
Quoted 6 lines

which was introduced by commit c77cd87cf54f003748f29c14ea1ddaecfc5c653f (pc-bios/s390-ccw: fix for fragmented SCSI bootmap).

So strictly speaking this if statement might not be needed any more:

        if (i == (max_entries - 1)) {

Eugene, can you confirm? If yes we could add this patch later on as a cleanup:

Quoted 9 lines

I'd preserve both checks.
In theory, we may catch a table that consumes all scratch space and leave no unused entry.

Plus, this check for zero counter and last entry is for "continuation" pointer, not for end-of-table by itself.

I think now, this code may need even few more checks to cover more cases...

Ok. That means, that this patch as is, doesnt make anything worse. Correct?

I am expecting more fixes and cleanups for the bios code anyway, so as long as we dont add a regression here this should be good to go as it makes the whole code more flexible.

Christian

#10 lore raw

Re: [Qemu-devel] [PULL 03/10] pc-bios/s390-ccw: handle different sector sizes

Yes, this patch doesn't make the code worse.

Quoted 35 lines · Christian Borntraeger
Quoted 19 lines · Eugene "jno" Dvurechenski
Quoted 9 lines · Christian Borntraeger
Quoted 4 lines

Review

Quoted 2 lines
(quoted diff) +1 -1
-    const int max_entries = (SECTOR_SIZE / sizeof(ScsiBlockPtr));
+    const int max_entries = (MAX_SECTOR_SIZE / sizeof(ScsiBlockPtr));

Is this really safe to increase? Doesn't max_entries depend on the real sector size?

I think this is now covered by this if statement:

            if (bprs[i].blockct == 0 && unused_space(&bprs[i + 1],
                sizeof(ScsiBlockPtr))) {
Quoted 6 lines

which was introduced by commit c77cd87cf54f003748f29c14ea1ddaecfc5c653f (pc-bios/s390-ccw: fix for fragmented SCSI bootmap).

So strictly speaking this if statement might not be needed any more:

        if (i == (max_entries - 1)) {

Eugene, can you confirm? If yes we could add this patch later on as a cleanup:

Quoted 9 lines

I'd preserve both checks.
In theory, we may catch a table that consumes all scratch space and leave no unused entry.

Plus, this check for zero counter and last entry is for "continuation" pointer, not for end-of-table by itself.

I think now, this code may need even few more checks to cover more cases...

Ok. That means, that this patch as is, doesnt make anything worse. Correct?

I am expecting more fixes and cleanups for the bios code anyway, so as long as we dont add a regression here this should be good to go as it makes the whole code more flexible.

Christian

Signature · 5 lines
Best Regards,
Eugene "jno" Dvurechenski
zLinux (KVM) Development - Software Engineer
IBM Russia - Science & Technology Center
phone: +7 (495) 660 8940 ext. 1021

begin:vcard
fn:Eugene Dvurechenski
n:Dvurechenski;Eugene
org:IBM Systems & Technology Group;IBM S&T Center, Russia adr:;;Obrucheva st., bld.30/1, E2V, floor 4;Moscow;;117485;Russia email;internet:[email protected]
title:Software Engineer
tel;work:+7 (495) 660 8940 ext. 1021
tel;cell:+7 (903) 790-07-49
x-mozilla-html:FALSE
url:http://fsw.su/
version:2.1
end:vcard

#11 lore raw

Re: [Qemu-devel] [PULL 03/10] pc-bios/s390-ccw: handle different sector sizes

In reply to Alexander Graf
Quoted 6 lines · Alexander Graf

pc-bios/s390-ccw/bootmap.c static inline bool unused_space(const void *p, unsigned int size) · line 104

Quoted 3 lines
  {
pc-bios/s390-ccw/bootmap.c +1 -1
-    const int max_entries = (SECTOR_SIZE / sizeof(ScsiBlockPtr));
+    const int max_entries = (MAX_SECTOR_SIZE / sizeof(ScsiBlockPtr));

Is this really safe to increase? Doesn't max_entries depend on the real sector size?

This is the top limit for a table that takes entire block. Real end-of-table is being handled by the code.

Signature · 5 lines
Best Regards,
Eugene "jno" Dvurechenski
zLinux (KVM) Development - Software Engineer
IBM Russia - Science & Technology Center
phone: +7 (495) 660 8940 ext. 1021

begin:vcard
fn:Eugene Dvurechenski
n:Dvurechenski;Eugene
org:IBM Systems & Technology Group;IBM S&T Center, Russia adr:;;Obrucheva st., bld.30/1, E2V, floor 4;Moscow;;117485;Russia email;internet:[email protected]
title:Software Engineer
tel;work:+7 (495) 660 8940 ext. 1021
tel;cell:+7 (903) 790-07-49
x-mozilla-html:FALSE
url:http://fsw.su/
version:2.1
end:vcard

#12 lore raw

[Qemu-devel] [PULL 07/10] pc-bios/s390-ccw: factor out ipl code

In reply to Cornelia Huck

From: "Eugene (jno) Dvurechenski" <[email protected]>

Move the scsi-disk specific ipl code from zipl_load() into a new function ipl_scsi(). This makes it easier to add ipl routines for other disk types.

---
 pc-bios/s390-ccw/bootmap.c |   83 ++++++++++++++++++++++++--------------------
 1 file changed, 45 insertions(+), 38 deletions(-)
pc-bios/s390-ccw/bootmap.c +45 -38
index 1866a20..3c08f82 100644
@@ -12,7 +12,9 @@
 #include "bootmap.h"
 #include "virtio.h"
 
+#ifdef DEBUG
 /* #define DEBUG_FALLBACK */
+#endif
 
 #ifdef DEBUG_FALLBACK
 #define dputs(txt) \
@@ -23,8 +25,7 @@
 #endif
 
 /* Scratch space */
-static uint8_t sec[MAX_SECTOR_SIZE]
-__attribute__((__aligned__(MAX_SECTOR_SIZE)));
+static uint8_t sec[MAX_SECTOR_SIZE*4] __attribute__((__aligned__(PAGE_SIZE)));
 
 typedef struct ResetInfo {
     uint32_t ipl_mask;
@@ -72,19 +73,9 @@ static void jump_to_IPL_code(uint64_t address)
     virtio_panic("\n! IPL returns !\n");
 }
 
-/* Check for ZIPL magic. Returns 0 if not matched. */
-static int zipl_magic(uint8_t *ptr)
-{
-    uint32_t *p = (void *)ptr;
-    uint32_t *z = (void *)ZIPL_MAGIC;
-
-    if (*p != *z) {
-        debug_print_int("invalid magic", *p);
-        virtio_panic("invalid magic");
-    }
-
-    return 1;
-}
+/***********************************************************************
+ * IPL a SCSI disk
+ */
 
 static void zipl_load_segment(ComponentEntry *entry)
 {
@@ -92,8 +83,10 @@ static void zipl_load_segment(ComponentEntry *entry)
     ScsiBlockPtr *bprs = (void *)sec;
     const int bprs_size = sizeof(sec);
     block_number_t blockno;
-    long address;
+    uint64_t address;
     int i;
+    char err_msg[] = "zIPL failed to read BPRS at 0xZZZZZZZZZZZZZZZZ";
+    char *blk_no = &err_msg[30]; /* where to print blockno in (those ZZs) */
 
     blockno = entry->data.blockno;
     address = entry->load_address;
@@ -103,11 +96,11 @@ static void zipl_load_segment(ComponentEntry *entry)
 
     do {
         memset(bprs, FREE_SPACE_FILLER, bprs_size);
-        debug_print_int("reading bprs at", blockno);
-        read_block(blockno, bprs, "zipl_load_segment: cannot read block");
+        fill_hex_val(blk_no, &blockno, sizeof(blockno));
+        read_block(blockno, bprs, err_msg);
 
         for (i = 0;; i++) {
-            u64 *cur_desc = (void *)&bprs[i];
+            uint64_t *cur_desc = (void *)&bprs[i];
 
             blockno = bprs[i].blockno;
             if (!blockno) {
@@ -132,7 +125,7 @@ static void zipl_load_segment(ComponentEntry *entry)
             }
             address = virtio_load_direct(cur_desc[0], cur_desc[1], 0,
                                          (void *)address);
-            IPL_assert(address != -1, "zipl_load_segment: wrong IPL address");
+            IPL_assert(address != -1, "zIPL load segment failed");
         }
     } while (blockno);
 }
@@ -144,13 +137,11 @@ static void zipl_run(ScsiBlockPtr *pte)
     ComponentEntry *entry;
     uint8_t tmp_sec[MAX_SECTOR_SIZE];
 
-    virtio_read(pte->blockno, tmp_sec);
+    read_block(pte->blockno, tmp_sec, "Cannot read header");
     header = (ComponentHeader *)tmp_sec;
 
-    IPL_assert(zipl_magic(tmp_sec), "zipl_run: zipl_magic");
-
-    IPL_assert(header->type == ZIPL_COMP_HEADER_IPL,
-               "zipl_run: wrong header type");
+    IPL_assert(magic_match(tmp_sec, ZIPL_MAGIC), "No zIPL magic");
+    IPL_assert(header->type == ZIPL_COMP_HEADER_IPL, "Bad header type");
 
     dputs("start loading images\n");
 
@@ -162,17 +153,16 @@ static void zipl_run(ScsiBlockPtr *pte)
         entry++;
 
         IPL_assert((uint8_t *)(&entry[1]) <= (tmp_sec + MAX_SECTOR_SIZE),
-                   "zipl_run: wrong entry size");
+                   "Wrong entry value");
     }
 
-    IPL_assert(entry->component_type == ZIPL_COMP_ENTRY_EXEC,
-               "zipl_run: no EXEC entry");
+    IPL_assert(entry->component_type == ZIPL_COMP_ENTRY_EXEC, "No EXEC entry");
 
     /* should not return */
     jump_to_IPL_code(entry->load_address);
 }
 
-void zipl_load(void)
+static void ipl_scsi(void)
 {
     ScsiMbr *mbr = (void *)sec;
     uint8_t *ns, *ns_end;
@@ -180,20 +170,16 @@ void zipl_load(void)
     const int pte_len = sizeof(ScsiBlockPtr);
     ScsiBlockPtr *prog_table_entry;
 
-    /* Grab the MBR */
-    read_block(0, mbr, "zipl_load: cannot read block 0");
-
-    dputs("checking magic\n");
-
-    IPL_assert(zipl_magic(mbr->magic), "zipl_load: zipl_magic 1");
+    /* The 0-th block (MBR) was already read into sec[] */
 
+    sclp_print("Using SCSI scheme.\n");
     debug_print_int("program table", mbr->blockptr.blockno);
 
     /* Parse the program table */
     read_block(mbr->blockptr.blockno, sec,
-               "zipl_load: cannot read program table");
+               "Error reading Program Table");
 
-    IPL_assert(zipl_magic(sec), "zipl_load: zipl_magic 2");
+    IPL_assert(magic_match(sec, ZIPL_MAGIC), "No zIPL magic");
 
     ns_end = sec + virtio_get_block_size();
     for (ns = (sec + pte_len); (ns + pte_len) < ns_end; ns++) {
@@ -207,7 +193,7 @@ void zipl_load(void)
 
     debug_print_int("program table entries", program_table_entries);
 
-    IPL_assert(program_table_entries, "zipl_load: no program table");
+    IPL_assert(program_table_entries != 0, "Empty Program Table");
 
     /* Run the default entry */
 
@@ -215,3 +201,24 @@ void zipl_load(void)
 
     zipl_run(prog_table_entry); /* no return */
 }
+
+/***********************************************************************
+ * IPL starts here
+ */
+
+void zipl_load(void)
+{
+    ScsiMbr *mbr = (void *)sec;
+
+    /* Grab the MBR */
+    memset(sec, FREE_SPACE_FILLER, sizeof(sec));
+    read_block(0, mbr, "Cannot read block 0");
+
+    dputs("checking magic\n");
+
+    if (magic_match(mbr->magic, ZIPL_MAGIC)) {
+        ipl_scsi(); /* no return */
+    }
+
+    virtio_panic("\n* invalid MBR magic *\n");
+}
Signature · 1 line
1.7.9.5
#13 lore raw

[Qemu-devel] [PULL 09/10] pc-bios/s390-ccw: IPL from LDL/CMS-formatted ECKD DASD

In reply to Cornelia Huck

From: "Eugene (jno) Dvurechenski" <[email protected]>

Add code that allows us to start from two further ECKD DASD disk
layouts: LDL (Linux disk layout) and CMS (cms-formatted disk).

---
 pc-bios/s390-ccw/bootmap.c |   92 ++++++++++++++++++++++++++++++++++++++++----
 pc-bios/s390-ccw/bootmap.h |    7 ++++
 2 files changed, 92 insertions(+), 7 deletions(-)
pc-bios/s390-ccw/bootmap.c +85 -7
index beda4d6..fa54abb 100644
@@ -80,6 +80,17 @@ static void jump_to_IPL_code(uint64_t address)
 static unsigned char _bprs[8*1024]; /* guessed "max" ECKD sector size */
 const int max_bprs_entries = sizeof(_bprs) / sizeof(ExtEckdBlockPtr);
 
+static inline void verify_boot_info(BootInfo *bip)
+{
+    IPL_assert(magic_match(bip->magic, ZIPL_MAGIC), "No zIPL magic");
+    IPL_assert(bip->version == BOOT_INFO_VERSION, "Wrong zIPL version");
+    IPL_assert(bip->bp_type == BOOT_INFO_BP_TYPE_IPL, "DASD is not for IPL");
+    IPL_assert(bip->dev_type == BOOT_INFO_DEV_TYPE_ECKD, "DASD is not ECKD");
+    IPL_assert(bip->flags == BOOT_INFO_FLAGS_ARCH, "Not for this arch");
+    IPL_assert(block_size_ok(bip->bp.ipl.bm_ptr.eckd.bptr.size),
+               "Bad block size in zIPL section of the 1st record.");
+}
+
 static bool eckd_valid_address(BootMapPointer *p)
 {
     const uint64_t cylinder = p->eckd.cylinder
@@ -198,19 +209,15 @@ static void run_eckd_boot_script(block_number_t mbr_block_nr)
     jump_to_IPL_code(bms->entry[i].address.load_address); /* no return */
 }
 
-static void ipl_eckd(void)
+static void ipl_eckd_cdl(void)
 {
     XEckdMbr *mbr;
     Ipl2 *ipl2 = (void *)sec;
     IplVolumeLabel *vlbl = (void *)sec;
     block_number_t block_nr;
 
-    sclp_print("Using ECKD scheme.\n");
-    if (virtio_guessed_disk_nature()) {
-        sclp_print("Using guessed DASD geometry.\n");
-        virtio_assume_eckd();
-    }
     /* we have just read the block #0 and recognized it as "IPL1" */
+    sclp_print("CDL\n");
 
     memset(sec, FREE_SPACE_FILLER, sizeof(sec));
     read_block(1, ipl2, "Cannot read IPL2 record at block 1");
@@ -238,6 +245,57 @@ static void ipl_eckd(void)
     /* no return */
 }
 
+static void ipl_eckd_ldl(ECKD_IPL_mode_t mode)
+{
+    LDL_VTOC *vlbl = (void *)sec; /* already read, 3rd block */
+    char msg[4] = { '?', '.', '\n', '\0' };
+    block_number_t block_nr;
+    BootInfo *bip;
+
+    sclp_print((mode == ECKD_CMS) ? "CMS" : "LDL");
+    sclp_print(" version ");
+    switch (vlbl->LDL_version) {
+    case LDL1_VERSION:
+        msg[0] = '1';
+        break;
+    case LDL2_VERSION:
+        msg[0] = '2';
+        break;
+    default:
+        msg[0] = vlbl->LDL_version;
+        msg[0] &= 0x0f; /* convert EBCDIC   */
+        msg[0] |= 0x30; /* to ASCII (digit) */
+        msg[1] = '?';
+        break;
+    }
+    sclp_print(msg);
+    print_volser(vlbl->volser);
+
+    /* DO NOT read BootMap pointer (only one, xECKD) at block #2 */
+
+    memset(sec, FREE_SPACE_FILLER, sizeof(sec));
+    read_block(0, sec, "Cannot read block 0");
+    bip = (void *)(sec + 0x70); /* "boot info" is "eckd mbr" for LDL */
+    verify_boot_info(bip);
+
+    block_nr = eckd_block_num((void *)&(bip->bp.ipl.bm_ptr.eckd.bptr));
+    run_eckd_boot_script(block_nr);
+    /* no return */
+}
+
+static void ipl_eckd(ECKD_IPL_mode_t mode)
+{
+    switch (mode) {
+    case ECKD_CDL:
+        ipl_eckd_cdl(); /* no return */
+    case ECKD_CMS:
+    case ECKD_LDL:
+        ipl_eckd_ldl(mode); /* no return */
+    default:
+        virtio_panic("\n! Unknown ECKD IPL mode !\n");
+    }
+}
+
 /***********************************************************************
  * IPL a SCSI disk
  */
@@ -374,6 +432,7 @@ static void ipl_scsi(void)
 void zipl_load(void)
 {
     ScsiMbr *mbr = (void *)sec;
+    LDL_VTOC *vlbl = (void *)sec;
 
     /* Grab the MBR */
     memset(sec, FREE_SPACE_FILLER, sizeof(sec));
@@ -384,8 +443,27 @@ void zipl_load(void)
     if (magic_match(mbr->magic, ZIPL_MAGIC)) {
         ipl_scsi(); /* no return */
     }
+
+    /* We have failed to follow the SCSI scheme, so */
+    sclp_print("Using ECKD scheme.\n");
+    if (virtio_guessed_disk_nature()) {
+        sclp_print("Using guessed DASD geometry.\n");
+        virtio_assume_eckd();
+    }
+
     if (magic_match(mbr->magic, IPL1_MAGIC)) {
-        ipl_eckd(); /* CDL ECKD; no return */
+        ipl_eckd(ECKD_CDL); /* no return */
+    }
+
+    /* LDL/CMS? */
+    memset(sec, FREE_SPACE_FILLER, sizeof(sec));
+    read_block(2, vlbl, "Cannot read block 2");
+
+    if (magic_match(vlbl->magic, CMS1_MAGIC)) {
+        ipl_eckd(ECKD_CMS); /* no return */
+    }
+    if (magic_match(vlbl->magic, LNX1_MAGIC)) {
+        ipl_eckd(ECKD_LDL); /* no return */
     }
 
     virtio_panic("\n* invalid MBR magic *\n");
pc-bios/s390-ccw/bootmap.h +7 -0
index 1846632..30ef22f 100644
@@ -255,6 +255,13 @@ typedef struct IplVolumeLabel {
     };
 } __attribute__((packed)) IplVolumeLabel;
 
+typedef enum {
+    ECKD_NO_IPL,
+    ECKD_CDL,
+    ECKD_CMS,
+    ECKD_LDL,
+} ECKD_IPL_mode_t;
+
 /* utility code below */
 
 static inline void IPL_assert(bool term, const char *message)
Signature · 1 line
1.7.9.5
#14 lore raw

[Qemu-devel] [PULL 06/10] pc-bios/s390-ccw: Add fill_hex_val func to provide better msgs

In reply to Cornelia Huck

From: "Eugene (jno) Dvurechenski" <[email protected]>

Factor out helper function for dumping a hex value into a buffer.

---
 pc-bios/s390-ccw/s390-ccw.h |   16 +++++++++++-----
 1 file changed, 11 insertions(+), 5 deletions(-)
pc-bios/s390-ccw/s390-ccw.h +11 -5
index 29468fb..959aed0 100644
@@ -86,15 +86,21 @@ static inline void fill_hex(char *out, unsigned char val)
     out[1] = hex[val & 0xf];
 }
 
-static inline void print_int(const char *desc, u64 addr)
+static inline void fill_hex_val(char *out, void *ptr, unsigned size)
 {
-    unsigned char *addr_c = (unsigned char *)&addr;
-    char out[] = ": 0xffffffffffffffff\n";
+    unsigned char *value = ptr;
     unsigned int i;
 
-    for (i = 0; i < sizeof(addr); i++) {
-        fill_hex(&out[4 + (i*2)], addr_c[i]);
+    for (i = 0; i < size; i++) {
+        fill_hex(&out[i*2], value[i]);
     }
+}
+
+static inline void print_int(const char *desc, u64 addr)
+{
+    char out[] = ": 0xffffffffffffffff\n";
+
+    fill_hex_val(&out[4], &addr, sizeof(addr));
 
     sclp_print(desc);
     sclp_print(out);
Signature · 1 line
1.7.9.5
#15 lore raw

[Qemu-devel] [PULL 10/10] pc-bios/s390-ccw: update binary

In reply to Cornelia Huck

From: Jens Freimann <[email protected]>

---
 pc-bios/s390-ccw.img |  Bin 9432 -> 17624 bytes
 1 file changed, 0 insertions(+), 0 deletions(-)
pc-bios/s390-ccw.img binary +0 -0
index 1c7f7640fc0c5f2505c4f1114a21b3b712852dbc..603e19e003d574b24bb3b97bacda2bf38077e8fd 100644
GIT binary patch
Signature · 1 line
1.7.9.5
#16 lore raw

[Qemu-devel] [PULL 08/10] pc-bios/s390-ccw: IPL from CDL-formatted ECKD DASD

In reply to Cornelia Huck

From: "Eugene (jno) Dvurechenski" <[email protected]>

Add code that allows us to start from ECKD DASD using the z/OS compatible disk layout (CDL), which is the most common format for ECKD DASD.

---
 pc-bios/s390-ccw/bootmap.c |  168 ++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 168 insertions(+)
pc-bios/s390-ccw/bootmap.c +168 -0
index 3c08f82..beda4d6 100644
@@ -74,6 +74,171 @@ static void jump_to_IPL_code(uint64_t address)
 }
 
 /***********************************************************************
+ * IPL an ECKD DASD (CDL or LDL/CMS format)
+ */
+
+static unsigned char _bprs[8*1024]; /* guessed "max" ECKD sector size */
+const int max_bprs_entries = sizeof(_bprs) / sizeof(ExtEckdBlockPtr);
+
+static bool eckd_valid_address(BootMapPointer *p)
+{
+    const uint64_t cylinder = p->eckd.cylinder
+                            + ((p->eckd.head & 0xfff0) << 12);
+    const uint64_t head = p->eckd.head & 0x000f;
+
+    if (head >= virtio_get_heads()
+        ||  p->eckd.sector > virtio_get_sectors()
+        ||  p->eckd.sector <= 0) {
+        return false;
+    }
+
+    if (!virtio_guessed_disk_nature() && cylinder >= virtio_get_cylinders()) {
+        return false;
+    }
+
+    return true;
+}
+
+static block_number_t eckd_block_num(BootMapPointer *p)
+{
+    const uint64_t sectors = virtio_get_sectors();
+    const uint64_t heads = virtio_get_heads();
+    const uint64_t cylinder = p->eckd.cylinder
+                            + ((p->eckd.head & 0xfff0) << 12);
+    const uint64_t head = p->eckd.head & 0x000f;
+    const block_number_t block = sectors * heads * cylinder
+                               + sectors * head
+                               + p->eckd.sector
+                               - 1; /* block nr starts with zero */
+    return block;
+}
+
+static block_number_t load_eckd_segments(block_number_t blk, uint64_t *address)
+{
+    block_number_t block_nr;
+    int j, rc;
+    BootMapPointer *bprs = (void *)_bprs;
+    bool more_data;
+
+    memset(_bprs, FREE_SPACE_FILLER, sizeof(_bprs));
+    read_block(blk, bprs, "BPRS read failed");
+
+    do {
+        more_data = false;
+        for (j = 0;; j++) {
+            block_nr = eckd_block_num((void *)&(bprs[j].xeckd));
+            if (is_null_block_number(block_nr)) { /* end of chunk */
+                break;
+            }
+
+            /* we need the updated blockno for the next indirect entry
+             * in the chain, but don't want to advance address
+             */
+            if (j == (max_bprs_entries - 1)) {
+                break;
+            }
+
+            IPL_assert(block_size_ok(bprs[j].xeckd.bptr.size),
+                       "bad chunk block size");
+            IPL_assert(eckd_valid_address(&bprs[j]), "bad chunk ECKD addr");
+
+            if ((bprs[j].xeckd.bptr.count == 0) && unused_space(&(bprs[j+1]),
+                sizeof(EckdBlockPtr))) {
+                /* This is a "continue" pointer.
+                 * This ptr should be the last one in the current
+                 * script section.
+                 * I.e. the next ptr must point to the unused memory area
+                 */
+                memset(_bprs, FREE_SPACE_FILLER, sizeof(_bprs));
+                read_block(block_nr, bprs, "BPRS continuation read failed");
+                more_data = true;
+                break;
+            }
+
+            /* Load (count+1) blocks of code at (block_nr)
+             * to memory (address).
+             */
+            rc = virtio_read_many(block_nr, (void *)(*address),
+                                  bprs[j].xeckd.bptr.count+1);
+            IPL_assert(rc == 0, "code chunk read failed");
+
+            *address += (bprs[j].xeckd.bptr.count+1) * virtio_get_block_size();
+        }
+    } while (more_data);
+    return block_nr;
+}
+
+static void run_eckd_boot_script(block_number_t mbr_block_nr)
+{
+    int i;
+    block_number_t block_nr;
+    uint64_t address;
+    ScsiMbr *scsi_mbr = (void *)sec;
+    BootMapScript *bms = (void *)sec;
+
+    memset(sec, FREE_SPACE_FILLER, sizeof(sec));
+    read_block(mbr_block_nr, sec, "Cannot read MBR");
+
+    block_nr = eckd_block_num((void *)&(scsi_mbr->blockptr));
+
+    memset(sec, FREE_SPACE_FILLER, sizeof(sec));
+    read_block(block_nr, sec, "Cannot read Boot Map Script");
+
+    for (i = 0; bms->entry[i].type == BOOT_SCRIPT_LOAD; i++) {
+        address = bms->entry[i].address.load_address;
+        block_nr = eckd_block_num(&(bms->entry[i].blkptr));
+
+        do {
+            block_nr = load_eckd_segments(block_nr, &address);
+        } while (block_nr != -1);
+    }
+
+    IPL_assert(bms->entry[i].type == BOOT_SCRIPT_EXEC,
+               "Unknown script entry type");
+    jump_to_IPL_code(bms->entry[i].address.load_address); /* no return */
+}
+
+static void ipl_eckd(void)
+{
+    XEckdMbr *mbr;
+    Ipl2 *ipl2 = (void *)sec;
+    IplVolumeLabel *vlbl = (void *)sec;
+    block_number_t block_nr;
+
+    sclp_print("Using ECKD scheme.\n");
+    if (virtio_guessed_disk_nature()) {
+        sclp_print("Using guessed DASD geometry.\n");
+        virtio_assume_eckd();
+    }
+    /* we have just read the block #0 and recognized it as "IPL1" */
+
+    memset(sec, FREE_SPACE_FILLER, sizeof(sec));
+    read_block(1, ipl2, "Cannot read IPL2 record at block 1");
+    IPL_assert(magic_match(ipl2, IPL2_MAGIC), "No IPL2 record");
+
+    mbr = &ipl2->u.x.mbr;
+    IPL_assert(magic_match(mbr, ZIPL_MAGIC), "No zIPL section in IPL2 record.");
+    IPL_assert(block_size_ok(mbr->blockptr.xeckd.bptr.size),
+               "Bad block size in zIPL section of IPL2 record.");
+    IPL_assert(mbr->dev_type == DEV_TYPE_ECKD,
+               "Non-ECKD device type in zIPL section of IPL2 record.");
+
+    /* save pointer to Boot Script */
+    block_nr = eckd_block_num((void *)&(mbr->blockptr));
+
+    memset(sec, FREE_SPACE_FILLER, sizeof(sec));
+    read_block(2, vlbl, "Cannot read Volume Label at block 2");
+    IPL_assert(magic_match(vlbl->key, VOL1_MAGIC),
+               "Invalid magic of volume label block");
+    IPL_assert(magic_match(vlbl->f.key, VOL1_MAGIC),
+               "Invalid magic of volser block");
+    print_volser(vlbl->f.volser);
+
+    run_eckd_boot_script(block_nr);
+    /* no return */
+}
+
+/***********************************************************************
  * IPL a SCSI disk
  */
 
@@ -219,6 +384,9 @@ void zipl_load(void)
     if (magic_match(mbr->magic, ZIPL_MAGIC)) {
         ipl_scsi(); /* no return */
     }
+    if (magic_match(mbr->magic, IPL1_MAGIC)) {
+        ipl_eckd(); /* CDL ECKD; no return */
+    }
 
     virtio_panic("\n* invalid MBR magic *\n");
 }
Signature · 1 line
1.7.9.5
#17 lore raw
In reply to Cornelia Huck
Quoted 15 lines · Cornelia Huck

Here are some s390-ccw bios patches I'd like to see in 2.1. Being able to finally boot from dasd is quite a useful feature. Please consider pulling.

The following changes since commit ff4873cb8c81db89668d8b56e19e57b852edb5f5:

coroutine-win32.c: Add noinline attribute to work around gcc bug (2014-06-26 14:08:14 +0100)

are available in the git repository at:

git://github.com/cohuck/qemu.git tags/s390x-20140627

for you to fetch changes up to 77416f4075a673a27cfe5a7a34e93c0fa9810e35:

pc-bios/s390-ccw: update binary (2014-06-27 12:11:53 +0200)

Quoted 7 lines

----------------------------------------------------------------
A series of patches to the s390-ccw bios:
- code cleanup
- improved error reporting

- most important, support to ipl (boot) from ECKD DASD (CDL, LDL or CMS formatted)

I love these IBM acronyms :-)

Applied, thanks.

-- PMM