qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Jens Freimann <jfrei@linux.vnet.ibm.com>
To: Christian Borntraeger <borntraeger@de.ibm.com>,
	Alexander Graf <agraf@suse.de>,
	Cornelia Huck <cornelia.huck@de.ibm.com>
Cc: "Eugene (jno) Dvurechenski" <jno@linux.vnet.ibm.com>,
	Jens Freimann <jfrei@linux.vnet.ibm.com>,
	qemu-devel@nongnu.org
Subject: [Qemu-devel] [PATCH 07/10] pc-bios/s390-ccw: factor out ipl code
Date: Thu, 26 Jun 2014 16:30:06 +0200	[thread overview]
Message-ID: <1403793009-54176-8-git-send-email-jfrei@linux.vnet.ibm.com> (raw)
In-Reply-To: <1403793009-54176-1-git-send-email-jfrei@linux.vnet.ibm.com>

From: "Eugene (jno) Dvurechenski" <jno@linux.vnet.ibm.com>

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.

Signed-off-by: Eugene (jno) Dvurechenski <jno@linux.vnet.ibm.com>
Signed-off-by: Jens Freimann <jfrei@linux.vnet.ibm.com>
---
 pc-bios/s390-ccw/bootmap.c | 82 +++++++++++++++++++++++++---------------------
 1 file changed, 45 insertions(+), 37 deletions(-)

diff --git a/pc-bios/s390-ccw/bootmap.c b/pc-bios/s390-ccw/bootmap.c
index 9e342c9..992c9aa 100644
--- a/pc-bios/s390-ccw/bootmap.c
+++ b/pc-bios/s390-ccw/bootmap.c
@@ -12,7 +12,9 @@
 #include "bootmap.h"
 #include "virtio.h"
 
+#ifdef DEBUG
 /* #define DEBUG_FALLBACK */
+#endif
 
 #ifdef DEBUG_FALLBACK
 #define dputs(txt) \
@@ -23,7 +25,7 @@
 #endif
 
 /* Scratch space */
-static uint8_t sec[SECTOR_SIZE] __attribute__((__aligned__(SECTOR_SIZE)));
+static uint8_t sec[SECTOR_SIZE*4] __attribute__((__aligned__(PAGE_SIZE)));
 
 typedef struct ResetInfo {
     uint32_t ipl_mask;
@@ -71,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)
 {
@@ -91,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;
@@ -102,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) {
@@ -131,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);
 }
@@ -143,13 +137,11 @@ static void zipl_run(ScsiBlockPtr *pte)
     ComponentEntry *entry;
     uint8_t tmp_sec[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");
 
@@ -161,17 +153,16 @@ static void zipl_run(ScsiBlockPtr *pte)
         entry++;
 
         IPL_assert((uint8_t *)(&entry[1]) <= (tmp_sec + 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;
@@ -179,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++) {
@@ -206,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 */
 
@@ -214,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");
+}
-- 
1.8.5.5

  parent reply	other threads:[~2014-06-26 14:30 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-06-26 14:29 [Qemu-devel] [PATCH 00/10] pc-bios/s390-ccw: Add DASD IPL support Jens Freimann
2014-06-26 14:30 ` [Qemu-devel] [PATCH 01/10] pc-bios/s390-ccw: make checkpatch happy Jens Freimann
2014-06-26 14:30 ` [Qemu-devel] [PATCH 02/10] pc-bios/s390-ccw: cleanup and enhance bootmap defintions Jens Freimann
2014-06-26 14:30 ` [Qemu-devel] [PATCH 03/10] pc-bios/s390-ccw: handle different sector sizes Jens Freimann
2014-06-26 14:35   ` Alexander Graf
2014-06-26 15:08     ` Eugene "jno" Dvurechenski
2014-06-26 15:10       ` Alexander Graf
2014-06-26 14:30 ` [Qemu-devel] [PATCH 04/10] pc-bios/s390-ccw: add some utility code Jens Freimann
2014-06-26 14:30 ` [Qemu-devel] [PATCH 05/10] pc-bios/s390-ccw: Unify error handling Jens Freimann
2014-06-26 14:30 ` [Qemu-devel] [PATCH 06/10] pc-bios/s390-ccw: Add fill_hex_val func to provide better msgs Jens Freimann
2014-06-26 14:30 ` Jens Freimann [this message]
2014-06-26 14:30 ` [Qemu-devel] [PATCH 08/10] pc-bios/s390-ccw: IPL from CDL-formatted ECKD DASD Jens Freimann
2014-06-26 14:30 ` [Qemu-devel] [PATCH 09/10] pc-bios/s390-ccw: IPL from LDL/CMS-formatted " Jens Freimann
2014-06-26 14:30 ` [Qemu-devel] [PATCH 10/10] pc-bios/s390-ccw: update binary Jens Freimann
2014-06-26 14:42 ` [Qemu-devel] [PATCH 00/10] pc-bios/s390-ccw: Add DASD IPL support Alexander Graf
2014-06-27  7:53   ` Christian Borntraeger
2014-06-27  9:05     ` Alexander Graf
2014-06-27  9:27       ` Christian Borntraeger
2014-06-27  9:47         ` Cornelia Huck

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1403793009-54176-8-git-send-email-jfrei@linux.vnet.ibm.com \
    --to=jfrei@linux.vnet.ibm.com \
    --cc=agraf@suse.de \
    --cc=borntraeger@de.ibm.com \
    --cc=cornelia.huck@de.ibm.com \
    --cc=jno@linux.vnet.ibm.com \
    --cc=qemu-devel@nongnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).