From patchwork Wed Jun 18 12:16:45 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jens Freimann X-Patchwork-Id: 361443 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 111F5140084 for ; Wed, 18 Jun 2014 22:18:05 +1000 (EST) Received: from localhost ([::1]:56914 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WxEoV-0006Jc-4s for incoming@patchwork.ozlabs.org; Wed, 18 Jun 2014 08:18:03 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:40998) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WxEno-00054l-Vx for qemu-devel@nongnu.org; Wed, 18 Jun 2014 08:17:30 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1WxEnf-0003Ic-VI for qemu-devel@nongnu.org; Wed, 18 Jun 2014 08:17:20 -0400 Received: from e06smtp11.uk.ibm.com ([195.75.94.107]:55398) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WxEnf-0003IY-Nb for qemu-devel@nongnu.org; Wed, 18 Jun 2014 08:17:11 -0400 Received: from /spool/local by e06smtp11.uk.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Wed, 18 Jun 2014 13:17:10 +0100 Received: from d06dlp03.portsmouth.uk.ibm.com (9.149.20.15) by e06smtp11.uk.ibm.com (192.168.101.141) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Wed, 18 Jun 2014 13:17:09 +0100 Received: from b06cxnps4074.portsmouth.uk.ibm.com (d06relay11.portsmouth.uk.ibm.com [9.149.109.196]) by d06dlp03.portsmouth.uk.ibm.com (Postfix) with ESMTP id 2AD5B1B0806E for ; Wed, 18 Jun 2014 13:17:38 +0100 (BST) Received: from d06av10.portsmouth.uk.ibm.com (d06av10.portsmouth.uk.ibm.com [9.149.37.251]) by b06cxnps4074.portsmouth.uk.ibm.com (8.13.8/8.13.8/NCO v10.0) with ESMTP id s5ICH8hZ33620208 for ; Wed, 18 Jun 2014 12:17:08 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 s5ICH8W5024812 for ; Wed, 18 Jun 2014 06:17:08 -0600 Received: from tuxmaker.boeblingen.de.ibm.com (tuxmaker.boeblingen.de.ibm.com [9.152.85.9]) by d06av10.portsmouth.uk.ibm.com (8.14.4/8.14.4/NCO v10.0 AVin) with ESMTP id s5ICH8jH024809; Wed, 18 Jun 2014 06:17:08 -0600 Received: by tuxmaker.boeblingen.de.ibm.com (Postfix, from userid 1122) id 4932F1224439; Wed, 18 Jun 2014 14:17:08 +0200 (CEST) From: Jens Freimann To: Christian Borntraeger , Alexander Graf , Cornelia Huck Date: Wed, 18 Jun 2014 14:16:45 +0200 Message-Id: <1403093807-32836-3-git-send-email-jfrei@linux.vnet.ibm.com> X-Mailer: git-send-email 1.8.5.5 In-Reply-To: <1403093807-32836-1-git-send-email-jfrei@linux.vnet.ibm.com> References: <1403093807-32836-1-git-send-email-jfrei@linux.vnet.ibm.com> X-TM-AS-MML: disable X-Content-Scanned: Fidelis XPS MAILER x-cbid: 14061812-5024-0000-0000-0000006BCF6B X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 195.75.94.107 Cc: Jens Freimann , qemu-devel@nongnu.org Subject: [Qemu-devel] [PATCH 2/4] pc-bios/s390-ccw: do a subsystem reset before running the guest 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: Christian Borntraeger The loader BIOS has already activated several devices. Let's do a subsystem reset before jumping into the guest. As there is no direct way of doing so, we use diagnose 308 to bring the system in a defined state. This is similar to what kdump on s390 uses. We have to define a small trampoline function that restores the low bytes to whatever the bootmap has written there. Signed-off-by: Christian Borntraeger Signed-off-by: Jens Freimann --- pc-bios/s390-ccw/bootmap.c | 55 +++++++++++++++++++++++++++++++++++++++------- 1 file changed, 47 insertions(+), 8 deletions(-) diff --git a/pc-bios/s390-ccw/bootmap.c b/pc-bios/s390-ccw/bootmap.c index 53a460d..c07553b 100644 --- a/pc-bios/s390-ccw/bootmap.c +++ b/pc-bios/s390-ccw/bootmap.c @@ -58,6 +58,52 @@ struct mbr { /* Scratch space */ static uint8_t sec[SECTOR_SIZE] __attribute__((__aligned__(SECTOR_SIZE))); +typedef struct ResetInfo { + uint32_t ipl_mask; + uint32_t ipl_addr; + uint32_t ipl_continue; +} ResetInfo; + +ResetInfo save; + +static void jump_to_IPL_2(void) +{ + ResetInfo *current = 0; + + void (*ipl)(void) = (void *) (uint64_t) current->ipl_continue; + debug_print_addr("set IPL addr to", ipl); + + /* Ensure the guest output starts fresh */ + sclp_print("\n"); + + *current = save; + ipl(); /* should not return */ +} + +static void jump_to_IPL_code(uint64_t address) +{ + /* + * The IPL PSW is at address 0. We also must not overwrite the + * content of non-BIOS memory after we loaded the guest, so we + * save the original content and restore it in jump_to_IPL_2. + */ + ResetInfo *current = 0; + + save = *current; + current->ipl_addr = (uint32_t) (uint64_t) &jump_to_IPL_2; + current->ipl_continue = address & 0x7fffffff; + + /* + * HACK ALERT. + * We use the load normal reset to keep r15 unchanged. jump_to_IPL_2 + * can then use r15 as its stack pointer. + */ + asm volatile("lghi 1,1\n\t" + "diag 1,1,0x308\n\t" + : : : "1", "memory"); + virtio_panic("\n! IPL returns !\n"); +} + /* Check for ZIPL magic. Returns 0 if not matched. */ static int zipl_magic(uint8_t *ptr) { @@ -123,7 +169,6 @@ static int zipl_run(struct scsi_blockptr *pte) { struct component_header *header; struct component_entry *entry; - void (*ipl)(void); uint8_t tmp_sec[SECTOR_SIZE]; virtio_read(pte->blockno, tmp_sec); @@ -157,14 +202,8 @@ static int zipl_run(struct scsi_blockptr *pte) goto fail; } - /* Ensure the guest output starts fresh */ - sclp_print("\n"); - - /* And run the OS! */ - ipl = (void*)(entry->load_address & 0x7fffffff); - debug_print_addr("set IPL addr to", ipl); /* should not return */ - ipl(); + jump_to_IPL_code(entry->load_address); return 0;