From patchwork Thu Jun 26 14:30:07 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jens Freimann X-Patchwork-Id: 364569 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 1BCCC14008B for ; Fri, 27 Jun 2014 00:39:26 +1000 (EST) Received: from localhost ([::1]:45051 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1X0ApY-0000ww-9V for incoming@patchwork.ozlabs.org; Thu, 26 Jun 2014 10:39:16 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:50250) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1X0AhG-0006cf-0f for qemu-devel@nongnu.org; Thu, 26 Jun 2014 10:30:51 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1X0Ah1-0001ld-D9 for qemu-devel@nongnu.org; Thu, 26 Jun 2014 10:30:41 -0400 Received: from e06smtp12.uk.ibm.com ([195.75.94.108]:60373) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1X0Ah0-0001l1-G7 for qemu-devel@nongnu.org; Thu, 26 Jun 2014 10:30:26 -0400 Received: from /spool/local by e06smtp12.uk.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Thu, 26 Jun 2014 15:30:25 +0100 Received: from d06dlp03.portsmouth.uk.ibm.com (9.149.20.15) by e06smtp12.uk.ibm.com (192.168.101.142) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Thu, 26 Jun 2014 15:30:24 +0100 Received: from b06cxnps4076.portsmouth.uk.ibm.com (d06relay13.portsmouth.uk.ibm.com [9.149.109.198]) by d06dlp03.portsmouth.uk.ibm.com (Postfix) with ESMTP id AC4161B08051 for ; Thu, 26 Jun 2014 15:30:56 +0100 (BST) Received: from d06av12.portsmouth.uk.ibm.com (d06av12.portsmouth.uk.ibm.com [9.149.37.247]) by b06cxnps4076.portsmouth.uk.ibm.com (8.13.8/8.13.8/NCO v10.0) with ESMTP id s5QEUOMO26804454 for ; Thu, 26 Jun 2014 14:30:24 GMT Received: from d06av12.portsmouth.uk.ibm.com (localhost [127.0.0.1]) by d06av12.portsmouth.uk.ibm.com (8.14.4/8.14.4/NCO v10.0 AVout) with ESMTP id s5QEUMK8021905 for ; Thu, 26 Jun 2014 08:30:23 -0600 Received: from tuxmaker.boeblingen.de.ibm.com (tuxmaker.boeblingen.de.ibm.com [9.152.85.9]) by d06av12.portsmouth.uk.ibm.com (8.14.4/8.14.4/NCO v10.0 AVin) with ESMTP id s5QEUMp2021894; Thu, 26 Jun 2014 08:30:22 -0600 Received: by tuxmaker.boeblingen.de.ibm.com (Postfix, from userid 1122) id 9797D1224439; Thu, 26 Jun 2014 16:30:22 +0200 (CEST) From: Jens Freimann To: Christian Borntraeger , Alexander Graf , Cornelia Huck Date: Thu, 26 Jun 2014 16:30:07 +0200 Message-Id: <1403793009-54176-9-git-send-email-jfrei@linux.vnet.ibm.com> X-Mailer: git-send-email 1.8.5.5 In-Reply-To: <1403793009-54176-1-git-send-email-jfrei@linux.vnet.ibm.com> References: <1403793009-54176-1-git-send-email-jfrei@linux.vnet.ibm.com> X-TM-AS-MML: disable X-Content-Scanned: Fidelis XPS MAILER x-cbid: 14062614-8372-0000-0000-000000560D5C X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 195.75.94.108 Cc: "Eugene \(jno\) Dvurechenski" , Jens Freimann , qemu-devel@nongnu.org Subject: [Qemu-devel] [PATCH 08/10] pc-bios/s390-ccw: IPL from CDL-formatted ECKD DASD X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org From: "Eugene (jno) Dvurechenski" 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. Signed-off-by: Eugene (jno) Dvurechenski Signed-off-by: Jens Freimann --- pc-bios/s390-ccw/bootmap.c | 168 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 168 insertions(+) diff --git a/pc-bios/s390-ccw/bootmap.c b/pc-bios/s390-ccw/bootmap.c index 992c9aa..6f73ffc 100644 --- a/pc-bios/s390-ccw/bootmap.c +++ b/pc-bios/s390-ccw/bootmap.c @@ -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"); }