Received: from eggs.gnu.org ([2001:4830:134:3::10]:41746) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1X0UHs-0001me-FY for qemu-devel@nongnu.org; Fri, 27 Jun 2014 07:25:57 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1X0UHj-0007Lp-Dp for qemu-devel@nongnu.org; Fri, 27 Jun 2014 07:25:48 -0400 Received: from e06smtp12.uk.ibm.com ([195.75.94.108]:48689) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1X0UHj-0007LY-2v for qemu-devel@nongnu.org; Fri, 27 Jun 2014 07:25:39 -0400 Received: from /spool/local by e06smtp12.uk.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Fri, 27 Jun 2014 12:25:38 +0100 Received: from b06cxnps3075.portsmouth.uk.ibm.com (d06relay10.portsmouth.uk.ibm.com [9.149.109.195]) by d06dlp01.portsmouth.uk.ibm.com (Postfix) with ESMTP id D476017D8042 for ; Fri, 27 Jun 2014 12:27:03 +0100 (BST) Received: from d06av10.portsmouth.uk.ibm.com (d06av10.portsmouth.uk.ibm.com [9.149.37.251]) by b06cxnps3075.portsmouth.uk.ibm.com (8.13.8/8.13.8/NCO v10.0) with ESMTP id s5RBPZek33947664 for ; Fri, 27 Jun 2014 11:25:35 GMT Received: from d06av10.portsmouth.uk.ibm.com (localhost [127.0.0.1]) by d06av10.portsmouth.uk.ibm.com (8.14.4/8.14.4/NCO v10.0 AVout) with ESMTP id s5RBPYhT006010 for ; Fri, 27 Jun 2014 05:25:35 -0600 From: Cornelia Huck Date: Fri, 27 Jun 2014 13:25:23 +0200 Message-Id: <1403868326-7718-8-git-send-email-cornelia.huck@de.ibm.com> In-Reply-To: <1403868326-7718-1-git-send-email-cornelia.huck@de.ibm.com> References: <1403868326-7718-1-git-send-email-cornelia.huck@de.ibm.com> Subject: [Qemu-devel] [PULL 07/10] pc-bios/s390-ccw: factor out ipl code List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: peter.maydell@linaro.org, agraf@suse.de, borntraeger@de.ibm.com, jfrei@linux.vnet.ibm.com, aliguori@amazon.com, Cornelia Huck , "Eugene (jno) Dvurechenski" From: "Eugene (jno) Dvurechenski" 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. Acked-by: Christian Borntraeger Signed-off-by: Eugene (jno) Dvurechenski Signed-off-by: Jens Freimann Signed-off-by: Cornelia Huck --- pc-bios/s390-ccw/bootmap.c | 83 ++++++++++++++++++++++++-------------------- 1 file changed, 45 insertions(+), 38 deletions(-) diff --git a/pc-bios/s390-ccw/bootmap.c b/pc-bios/s390-ccw/bootmap.c index 1866a20..3c08f82 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,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"); +} -- 1.7.9.5