From nobody Sat May 18 06:04:10 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1547813600859841.2972355379956; Fri, 18 Jan 2019 04:13:20 -0800 (PST) Received: from localhost ([127.0.0.1]:37374 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gkT1T-0007Em-QR for importer@patchew.org; Fri, 18 Jan 2019 07:13:19 -0500 Received: from eggs.gnu.org ([209.51.188.92]:49791) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gkSzI-0005yd-HY for qemu-devel@nongnu.org; Fri, 18 Jan 2019 07:11:05 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gkSzH-0005MN-Sp for qemu-devel@nongnu.org; Fri, 18 Jan 2019 07:11:04 -0500 Received: from mx1.redhat.com ([209.132.183.28]:51452) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gkSzH-0005Lb-Mj for qemu-devel@nongnu.org; Fri, 18 Jan 2019 07:11:03 -0500 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 9A45A9C17B; Fri, 18 Jan 2019 12:01:56 +0000 (UTC) Received: from steredhat.redhat.com (ovpn-117-61.ams2.redhat.com [10.36.117.61]) by smtp.corp.redhat.com (Postfix) with ESMTP id AC014600C2; Fri, 18 Jan 2019 12:01:53 +0000 (UTC) From: Stefano Garzarella To: qemu-devel@nongnu.org Date: Fri, 18 Jan 2019 13:01:39 +0100 Message-Id: <20190118120143.21631-2-sgarzare@redhat.com> In-Reply-To: <20190118120143.21631-1-sgarzare@redhat.com> References: <20190118120143.21631-1-sgarzare@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.26]); Fri, 18 Jan 2019 12:01:56 +0000 (UTC) Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH v5 1/5] linuxboot_dma: remove duplicate definitions of FW_CFG X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Eduardo Habkost , Maran Wilson , "Michael S. Tsirkin" , George Kennedy , Stefan Hajnoczi , Paolo Bonzini , Boris Ostrovsky , Richard Henderson Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" FW_CFG_DMA_CTL_* bits and struct fw_cfg_dma_access are defined in the qemu_fw_cfg.h header file already included in linuxboot_dma.c, so we can remove the definition of BIOS_CFG_DMA_CTL_* and struct FWCfgDmaAccess. Signed-off-by: Stefano Garzarella Reviewed-by: Stefan Hajnoczi Reviewed-by: Liam Merwick --- pc-bios/optionrom/linuxboot_dma.c | 20 ++++---------------- 1 file changed, 4 insertions(+), 16 deletions(-) diff --git a/pc-bios/optionrom/linuxboot_dma.c b/pc-bios/optionrom/linuxboo= t_dma.c index d856d41b55..f728dc839f 100644 --- a/pc-bios/optionrom/linuxboot_dma.c +++ b/pc-bios/optionrom/linuxboot_dma.c @@ -58,12 +58,6 @@ asm( " jmp load_kernel\n" ); =20 -/* QEMU_CFG_DMA_CONTROL bits */ -#define BIOS_CFG_DMA_CTL_ERROR 0x01 -#define BIOS_CFG_DMA_CTL_READ 0x02 -#define BIOS_CFG_DMA_CTL_SKIP 0x04 -#define BIOS_CFG_DMA_CTL_SELECT 0x08 - #define BIOS_CFG_DMA_ADDR_HIGH 0x514 #define BIOS_CFG_DMA_ADDR_LOW 0x518 =20 @@ -75,12 +69,6 @@ asm( =20 #define barrier() asm("" : : : "memory") =20 -typedef struct FWCfgDmaAccess { - uint32_t control; - uint32_t length; - uint64_t address; -} __attribute__((packed)) FWCfgDmaAccess; - static inline void outl(uint32_t value, uint16_t port) { asm("outl %0, %w1" : : "a"(value), "Nd"(port)); @@ -153,9 +141,9 @@ static inline uint32_t be32_to_cpu(uint32_t x) static __attribute__((__noinline__)) void bios_cfg_read_entry(void *buf, uint16_t entry, uint32_t len) { - FWCfgDmaAccess access; - uint32_t control =3D (entry << 16) | BIOS_CFG_DMA_CTL_SELECT - | BIOS_CFG_DMA_CTL_READ; + struct fw_cfg_dma_access access; + uint32_t control =3D (entry << 16) | FW_CFG_DMA_CTL_SELECT + | FW_CFG_DMA_CTL_READ; =20 access.address =3D cpu_to_be64((uint64_t)(uint32_t)buf); access.length =3D cpu_to_be32(len); @@ -165,7 +153,7 @@ void bios_cfg_read_entry(void *buf, uint16_t entry, uin= t32_t len) =20 outl(cpu_to_be32((uint32_t)&access), BIOS_CFG_DMA_ADDR_LOW); =20 - while (be32_to_cpu(access.control) & ~BIOS_CFG_DMA_CTL_ERROR) { + while (be32_to_cpu(access.control) & ~FW_CFG_DMA_CTL_ERROR) { barrier(); } } --=20 2.20.1 From nobody Sat May 18 06:04:10 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 154781378328372.4689572431339; Fri, 18 Jan 2019 04:16:23 -0800 (PST) Received: from localhost ([127.0.0.1]:37452 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gkT4Q-0002Mt-48 for importer@patchew.org; Fri, 18 Jan 2019 07:16:22 -0500 Received: from eggs.gnu.org ([209.51.188.92]:49927) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gkT00-0006Xm-KH for qemu-devel@nongnu.org; Fri, 18 Jan 2019 07:11:50 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gkSzy-00064N-Q6 for qemu-devel@nongnu.org; Fri, 18 Jan 2019 07:11:48 -0500 Received: from mx1.redhat.com ([209.132.183.28]:59740) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gkSzx-0005kq-C8 for qemu-devel@nongnu.org; Fri, 18 Jan 2019 07:11:46 -0500 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id DA0B5355A; Fri, 18 Jan 2019 12:01:59 +0000 (UTC) Received: from steredhat.redhat.com (ovpn-117-61.ams2.redhat.com [10.36.117.61]) by smtp.corp.redhat.com (Postfix) with ESMTP id EFAED600C9; Fri, 18 Jan 2019 12:01:56 +0000 (UTC) From: Stefano Garzarella To: qemu-devel@nongnu.org Date: Fri, 18 Jan 2019 13:01:40 +0100 Message-Id: <20190118120143.21631-3-sgarzare@redhat.com> In-Reply-To: <20190118120143.21631-1-sgarzare@redhat.com> References: <20190118120143.21631-1-sgarzare@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.30]); Fri, 18 Jan 2019 12:02:00 +0000 (UTC) Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH v5 2/5] linuxboot_dma: move common functions in a new header X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Eduardo Habkost , Maran Wilson , "Michael S. Tsirkin" , George Kennedy , Stefan Hajnoczi , Paolo Bonzini , Boris Ostrovsky , Richard Henderson Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" In order to allow other option roms to use these common useful functions and definitions, this patch put them in two new C header files called optrom.h and optrom_fw_cfg.h. We also add useful out*() in*() functions for different size, and new fw_cfg functions to use when DMA feature is not available. Signed-off-by: Stefano Garzarella Reviewed-by: Stefan Hajnoczi Reviewed-by: Liam Merwick --- pc-bios/optionrom/linuxboot_dma.c | 102 ++++++--------------------- pc-bios/optionrom/optrom.h | 110 ++++++++++++++++++++++++++++++ pc-bios/optionrom/optrom_fw_cfg.h | 92 +++++++++++++++++++++++++ 3 files changed, 221 insertions(+), 83 deletions(-) create mode 100644 pc-bios/optionrom/optrom.h create mode 100644 pc-bios/optionrom/optrom_fw_cfg.h diff --git a/pc-bios/optionrom/linuxboot_dma.c b/pc-bios/optionrom/linuxboo= t_dma.c index f728dc839f..cbcf6679d9 100644 --- a/pc-bios/optionrom/linuxboot_dma.c +++ b/pc-bios/optionrom/linuxboot_dma.c @@ -58,21 +58,13 @@ asm( " jmp load_kernel\n" ); =20 -#define BIOS_CFG_DMA_ADDR_HIGH 0x514 -#define BIOS_CFG_DMA_ADDR_LOW 0x518 - -#define uint64_t unsigned long long -#define uint32_t unsigned int -#define uint16_t unsigned short - -#include "../../include/standard-headers/linux/qemu_fw_cfg.h" - -#define barrier() asm("" : : : "memory") - -static inline void outl(uint32_t value, uint16_t port) -{ - asm("outl %0, %w1" : : "a"(value), "Nd"(port)); -} +/* + * The includes of C headers must be after the asm block to avoid compiler + * errors. + */ +#include +#include "optrom.h" +#include "optrom_fw_cfg.h" =20 static inline void set_es(void *addr) { @@ -80,12 +72,6 @@ static inline void set_es(void *addr) asm("movl %0, %%es" : : "r"(seg)); } =20 -#ifdef __clang__ -#define ADDR32 -#else -#define ADDR32 "addr32 " -#endif - static inline uint16_t readw_es(uint16_t offset) { uint16_t val; @@ -108,56 +94,6 @@ static inline void writel_es(uint16_t offset, uint32_t = val) asm(ADDR32 "movl %0, %%es:(%1)" : : "r"(val), "r"((uint32_t)offset)); } =20 -static inline uint32_t bswap32(uint32_t x) -{ - asm("bswapl %0" : "=3Dr" (x) : "0" (x)); - return x; -} - -static inline uint64_t bswap64(uint64_t x) -{ - asm("bswapl %%eax; bswapl %%edx; xchg %%eax, %%edx" : "=3DA" (x) : "0"= (x)); - return x; -} - -static inline uint64_t cpu_to_be64(uint64_t x) -{ - return bswap64(x); -} - -static inline uint32_t cpu_to_be32(uint32_t x) -{ - return bswap32(x); -} - -static inline uint32_t be32_to_cpu(uint32_t x) -{ - return bswap32(x); -} - -/* clang is happy to inline this function, and bloats the - * ROM. - */ -static __attribute__((__noinline__)) -void bios_cfg_read_entry(void *buf, uint16_t entry, uint32_t len) -{ - struct fw_cfg_dma_access access; - uint32_t control =3D (entry << 16) | FW_CFG_DMA_CTL_SELECT - | FW_CFG_DMA_CTL_READ; - - access.address =3D cpu_to_be64((uint64_t)(uint32_t)buf); - access.length =3D cpu_to_be32(len); - access.control =3D cpu_to_be32(control); - - barrier(); - - outl(cpu_to_be32((uint32_t)&access), BIOS_CFG_DMA_ADDR_LOW); - - while (be32_to_cpu(access.control) & ~FW_CFG_DMA_CTL_ERROR) { - barrier(); - } -} - /* Return top of memory using BIOS function E801. */ static uint32_t get_e801_addr(void) { @@ -211,9 +147,9 @@ void load_kernel(void) uint32_t initrd_end_page, max_allowed_page; uint32_t segment_addr, stack_addr; =20 - bios_cfg_read_entry(&setup_addr, FW_CFG_SETUP_ADDR, 4); - bios_cfg_read_entry(&setup_size, FW_CFG_SETUP_SIZE, 4); - bios_cfg_read_entry(setup_addr, FW_CFG_SETUP_DATA, setup_size); + bios_cfg_read_entry_dma(&setup_addr, FW_CFG_SETUP_ADDR, 4); + bios_cfg_read_entry_dma(&setup_size, FW_CFG_SETUP_SIZE, 4); + bios_cfg_read_entry_dma(setup_addr, FW_CFG_SETUP_DATA, setup_size); =20 set_es(setup_addr); =20 @@ -223,8 +159,8 @@ void load_kernel(void) writel_es(0x22c, 0x37ffffff); } =20 - bios_cfg_read_entry(&initrd_addr, FW_CFG_INITRD_ADDR, 4); - bios_cfg_read_entry(&initrd_size, FW_CFG_INITRD_SIZE, 4); + bios_cfg_read_entry_dma(&initrd_addr, FW_CFG_INITRD_ADDR, 4); + bios_cfg_read_entry_dma(&initrd_size, FW_CFG_INITRD_SIZE, 4); =20 initrd_end_page =3D ((uint32_t)(initrd_addr + initrd_size) & -4096); max_allowed_page =3D (readl_es(0x22c) & -4096); @@ -239,15 +175,15 @@ void load_kernel(void) =20 } =20 - bios_cfg_read_entry(initrd_addr, FW_CFG_INITRD_DATA, initrd_size); + bios_cfg_read_entry_dma(initrd_addr, FW_CFG_INITRD_DATA, initrd_size); =20 - bios_cfg_read_entry(&kernel_addr, FW_CFG_KERNEL_ADDR, 4); - bios_cfg_read_entry(&kernel_size, FW_CFG_KERNEL_SIZE, 4); - bios_cfg_read_entry(kernel_addr, FW_CFG_KERNEL_DATA, kernel_size); + bios_cfg_read_entry_dma(&kernel_addr, FW_CFG_KERNEL_ADDR, 4); + bios_cfg_read_entry_dma(&kernel_size, FW_CFG_KERNEL_SIZE, 4); + bios_cfg_read_entry_dma(kernel_addr, FW_CFG_KERNEL_DATA, kernel_size); =20 - bios_cfg_read_entry(&cmdline_addr, FW_CFG_CMDLINE_ADDR, 4); - bios_cfg_read_entry(&cmdline_size, FW_CFG_CMDLINE_SIZE, 4); - bios_cfg_read_entry(cmdline_addr, FW_CFG_CMDLINE_DATA, cmdline_size); + bios_cfg_read_entry_dma(&cmdline_addr, FW_CFG_CMDLINE_ADDR, 4); + bios_cfg_read_entry_dma(&cmdline_size, FW_CFG_CMDLINE_SIZE, 4); + bios_cfg_read_entry_dma(cmdline_addr, FW_CFG_CMDLINE_DATA, cmdline_siz= e); =20 /* Boot linux */ segment_addr =3D ((uint32_t)setup_addr >> 4); diff --git a/pc-bios/optionrom/optrom.h b/pc-bios/optionrom/optrom.h new file mode 100644 index 0000000000..c5c8caa22f --- /dev/null +++ b/pc-bios/optionrom/optrom.h @@ -0,0 +1,110 @@ +/* + * Common Option ROM Functions for C code + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, see . + * + * Copyright (c) 2015-2019 Red Hat Inc. + * Authors: + * Marc Mar=C3=AD + * Richard W.M. Jones + * Stefano Garzarella + */ + +#ifndef OPTROM_H +#define OPTROM_H + +#include +#include "../../include/standard-headers/linux/qemu_fw_cfg.h" + +#define barrier() asm("" : : : "memory") + +#ifdef __clang__ +#define ADDR32 +#else +#define ADDR32 "addr32 " +#endif + +static inline void outb(uint8_t value, uint16_t port) +{ + asm volatile("outb %0, %w1" : : "a"(value), "Nd"(port)); +} + +static inline void outw(uint16_t value, uint16_t port) +{ + asm volatile("outw %0, %w1" : : "a"(value), "Nd"(port)); +} + +static inline void outl(uint32_t value, uint16_t port) +{ + asm volatile("outl %0, %w1" : : "a"(value), "Nd"(port)); +} + +static inline uint8_t inb(uint16_t port) +{ + uint8_t value; + + asm volatile("outl %w1, %0" : : "a"(value), "Nd"(port)); + return value; +} + +static inline uint16_t inw(uint16_t port) +{ + uint16_t value; + + asm volatile("outl %w1, %0" : : "a"(value), "Nd"(port)); + return value; +} + +static inline uint32_t inl(uint16_t port) +{ + uint32_t value; + + asm volatile("outl %w1, %0" : : "a"(value), "Nd"(port)); + return value; +} + +static inline void insb(uint16_t port, uint8_t *buf, uint32_t len) +{ + asm volatile("rep insb (%%dx), %%es:(%%edi)" + : "+c"(len), "+D"(buf) : "d"(port) : "memory"); +} + +static inline uint32_t bswap32(uint32_t x) +{ + asm("bswapl %0" : "=3Dr" (x) : "0" (x)); + return x; +} + +static inline uint64_t bswap64(uint64_t x) +{ + asm("bswapl %%eax; bswapl %%edx; xchg %%eax, %%edx" : "=3DA" (x) : "0"= (x)); + return x; +} + +static inline uint64_t cpu_to_be64(uint64_t x) +{ + return bswap64(x); +} + +static inline uint32_t cpu_to_be32(uint32_t x) +{ + return bswap32(x); +} + +static inline uint32_t be32_to_cpu(uint32_t x) +{ + return bswap32(x); +} + +#endif /* OPTROM_H */ diff --git a/pc-bios/optionrom/optrom_fw_cfg.h b/pc-bios/optionrom/optrom_f= w_cfg.h new file mode 100644 index 0000000000..a3660a5200 --- /dev/null +++ b/pc-bios/optionrom/optrom_fw_cfg.h @@ -0,0 +1,92 @@ +/* + * Common Option ROM Functions for fw_cfg + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, see . + * + * Copyright (c) 2015-2019 Red Hat Inc. + * Authors: + * Marc Mar=C3=AD + * Richard W.M. Jones + * Stefano Garzarella + */ + +#ifndef OPTROM_FW_CFG_H +#define OPTROM_FW_CFG_H + +#include "../../include/standard-headers/linux/qemu_fw_cfg.h" + +#define BIOS_CFG_IOPORT_CFG 0x510 +#define BIOS_CFG_IOPORT_DATA 0x511 +#define BIOS_CFG_DMA_ADDR_HIGH 0x514 +#define BIOS_CFG_DMA_ADDR_LOW 0x518 + +static __attribute__((unused)) +void bios_cfg_select(uint16_t key) +{ + outw(key, BIOS_CFG_IOPORT_CFG); +} + +static __attribute__((unused)) +void bios_cfg_read_entry_io(void *buf, uint16_t entry, uint32_t len) +{ + bios_cfg_select(entry); + insb(BIOS_CFG_IOPORT_DATA, buf, len); +} + +/* + * clang is happy to inline this function, and bloats the + * ROM. + */ +static __attribute__((__noinline__)) __attribute__((unused)) +void bios_cfg_read_entry_dma(void *buf, uint16_t entry, uint32_t len) +{ + struct fw_cfg_dma_access access; + uint32_t control =3D (entry << 16) | FW_CFG_DMA_CTL_SELECT + | FW_CFG_DMA_CTL_READ; + + access.address =3D cpu_to_be64((uint64_t)(uint32_t)buf); + access.length =3D cpu_to_be32(len); + access.control =3D cpu_to_be32(control); + + barrier(); + + outl(cpu_to_be32((uint32_t)&access), BIOS_CFG_DMA_ADDR_LOW); + + while (be32_to_cpu(access.control) & ~FW_CFG_DMA_CTL_ERROR) { + barrier(); + } +} + +static __attribute__((unused)) +void bios_cfg_read_entry(void *buf, uint16_t entry, uint32_t len, + uint32_t version) +{ + if (version & FW_CFG_VERSION_DMA) { + bios_cfg_read_entry_dma(buf, entry, len); + } else { + bios_cfg_read_entry_io(buf, entry, len); + } +} + +static __attribute__((unused)) +uint32_t bios_cfg_version(void) +{ + uint32_t version; + + bios_cfg_read_entry_io(&version, FW_CFG_ID, sizeof(version)); + + return version; +} + +#endif /* OPTROM_FW_CFG_H */ --=20 2.20.1 From nobody Sat May 18 06:04:10 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1547814303090740.273643013069; Fri, 18 Jan 2019 04:25:03 -0800 (PST) Received: from localhost ([127.0.0.1]:37578 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gkTCn-0000MR-Vl for importer@patchew.org; Fri, 18 Jan 2019 07:25:02 -0500 Received: from eggs.gnu.org ([209.51.188.92]:48964) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gkSxH-00034G-Dr for qemu-devel@nongnu.org; Fri, 18 Jan 2019 07:09:01 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gkSxD-0002xy-UE for qemu-devel@nongnu.org; Fri, 18 Jan 2019 07:08:58 -0500 Received: from mx1.redhat.com ([209.132.183.28]:41590) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gkSxD-0002wT-Lx for qemu-devel@nongnu.org; Fri, 18 Jan 2019 07:08:55 -0500 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 42C577FD52; Fri, 18 Jan 2019 12:02:03 +0000 (UTC) Received: from steredhat.redhat.com (ovpn-117-61.ams2.redhat.com [10.36.117.61]) by smtp.corp.redhat.com (Postfix) with ESMTP id 406CF600C9; Fri, 18 Jan 2019 12:02:00 +0000 (UTC) From: Stefano Garzarella To: qemu-devel@nongnu.org Date: Fri, 18 Jan 2019 13:01:41 +0100 Message-Id: <20190118120143.21631-4-sgarzare@redhat.com> In-Reply-To: <20190118120143.21631-1-sgarzare@redhat.com> References: <20190118120143.21631-1-sgarzare@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.27]); Fri, 18 Jan 2019 12:02:03 +0000 (UTC) Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH v5 3/5] optionrom: add new PVH option rom X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Eduardo Habkost , Maran Wilson , "Michael S. Tsirkin" , George Kennedy , Stefan Hajnoczi , Paolo Bonzini , Boris Ostrovsky , Richard Henderson Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" The new pvh.bin option rom can be used with SeaBIOS to boot uncompressed kernel using the x86/HVM direct boot ABI. pvh.S contains the entry point of the option rom. It runs in real mode, loads the e820 table querying the BIOS, and then it switches to 32bit protected mode and jumps to the pvh_load_kernel() written in pvh_main.c. pvh_load_kernel() loads the cmdline and kernel entry_point using fw_cfg, then it looks for RSDP, fills the hvm_start_info required by x86/HVM ABI, and finally jumps to the kernel entry_point. Signed-off-by: Stefano Garzarella Reviewed-by: Stefan Hajnoczi Reviewed-by: Liam Merwick --- .gitignore | 4 + Makefile | 2 +- pc-bios/optionrom/Makefile | 5 +- pc-bios/optionrom/pvh.S | 200 +++++++++++++++++++++++++++++++++++ pc-bios/optionrom/pvh_main.c | 116 ++++++++++++++++++++ pc-bios/pvh.bin | Bin 0 -> 1536 bytes 6 files changed, 325 insertions(+), 2 deletions(-) create mode 100644 pc-bios/optionrom/pvh.S create mode 100644 pc-bios/optionrom/pvh_main.c create mode 100644 pc-bios/pvh.bin diff --git a/.gitignore b/.gitignore index 0430257313..321095bf1a 100644 --- a/.gitignore +++ b/.gitignore @@ -103,6 +103,10 @@ /pc-bios/optionrom/linuxboot_dma.bin /pc-bios/optionrom/linuxboot_dma.raw /pc-bios/optionrom/linuxboot_dma.img +/pc-bios/optionrom/pvh.asm +/pc-bios/optionrom/pvh.bin +/pc-bios/optionrom/pvh.raw +/pc-bios/optionrom/pvh.img /pc-bios/optionrom/multiboot.asm /pc-bios/optionrom/multiboot.bin /pc-bios/optionrom/multiboot.raw diff --git a/Makefile b/Makefile index a9ac16d94e..dd6d477fb1 100644 --- a/Makefile +++ b/Makefile @@ -668,7 +668,7 @@ efi-pcnet.rom efi-rtl8139.rom efi-virtio.rom \ efi-e1000e.rom efi-vmxnet3.rom \ qemu-icon.bmp qemu_logo_no_text.svg \ bamboo.dtb canyonlands.dtb petalogix-s3adsp1800.dtb petalogix-ml605.dtb \ -multiboot.bin linuxboot.bin linuxboot_dma.bin kvmvapic.bin \ +multiboot.bin linuxboot.bin linuxboot_dma.bin kvmvapic.bin pvh.bin \ s390-ccw.img s390-netboot.img \ spapr-rtas.bin slof.bin skiboot.lid \ palcode-clipper \ diff --git a/pc-bios/optionrom/Makefile b/pc-bios/optionrom/Makefile index a9a9e5e7eb..e33a24da0d 100644 --- a/pc-bios/optionrom/Makefile +++ b/pc-bios/optionrom/Makefile @@ -37,7 +37,7 @@ Wa =3D -Wa, ASFLAGS +=3D -32 QEMU_CFLAGS +=3D $(call cc-c-option, $(QEMU_CFLAGS), $(Wa)-32) =20 -build-all: multiboot.bin linuxboot.bin linuxboot_dma.bin kvmvapic.bin +build-all: multiboot.bin linuxboot.bin linuxboot_dma.bin kvmvapic.bin pvh.= bin =20 # suppress auto-removal of intermediate files .SECONDARY: @@ -46,6 +46,9 @@ build-all: multiboot.bin linuxboot.bin linuxboot_dma.bin = kvmvapic.bin %.o: %.S $(call quiet-command,$(CPP) $(QEMU_INCLUDES) $(QEMU_DGFLAGS) -c -o - $< |= $(AS) $(ASFLAGS) -o $@,"AS","$(TARGET_DIR)$@") =20 +pvh.img: pvh.o pvh_main.o + $(call quiet-command,$(LD) $(LDFLAGS_NOPIE) -m $(LD_I386_EMULATION) -T $(= SRC_PATH)/pc-bios/optionrom/flat.lds -s -o $@ $^,"BUILD","$(TARGET_DIR)$@") + %.img: %.o $(call quiet-command,$(LD) $(LDFLAGS_NOPIE) -m $(LD_I386_EMULATION) -T $(= SRC_PATH)/pc-bios/optionrom/flat.lds -s -o $@ $<,"BUILD","$(TARGET_DIR)$@") =20 diff --git a/pc-bios/optionrom/pvh.S b/pc-bios/optionrom/pvh.S new file mode 100644 index 0000000000..e1d7f4a7a7 --- /dev/null +++ b/pc-bios/optionrom/pvh.S @@ -0,0 +1,200 @@ +/* + * PVH Option ROM + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, see . + * + * Copyright Novell Inc, 2009 + * Authors: Alexander Graf + * + * Copyright (c) 2019 Red Hat Inc. + * Authors: Stefano Garzarella + */ + +#include "optionrom.h" + +#define BOOT_ROM_PRODUCT "PVH loader" + +#define GS_PROT_JUMP 0 +#define GS_GDT_DESC 6 + +#ifdef OPTION_ROM_START +#undef OPTION_ROM_START +#endif +#ifdef OPTION_ROM_END +#undef OPTION_ROM_END +#endif + +/* + * Redefine OPTION_ROM_START and OPTION_ROM_END, because this rom is produ= ced + * linking multiple objects. + * signrom.py will add padding. + */ +#define OPTION_ROM_START \ + .code16; \ + .text; \ + .global _start; \ + _start:; \ + .short 0xaa55; \ + .byte 3; /* desired size in 512 units */ + +#define OPTION_ROM_END \ + _end: + +BOOT_ROM_START + +run_pvhboot: + + cli + cld + + mov %cs, %eax + shl $0x4, %eax + + /* set up a long jump descriptor that is PC relative */ + + /* move stack memory to %gs */ + mov %ss, %ecx + shl $0x4, %ecx + mov %esp, %ebx + add %ebx, %ecx + sub $0x20, %ecx + sub $0x30, %esp + shr $0x4, %ecx + mov %cx, %gs + + /* now push the indirect jump descriptor there */ + mov (prot_jump), %ebx + add %eax, %ebx + movl %ebx, %gs:GS_PROT_JUMP + mov $8, %bx + movw %bx, %gs:GS_PROT_JUMP + 4 + + /* fix the gdt descriptor to be PC relative */ + movw (gdt_desc), %bx + movw %bx, %gs:GS_GDT_DESC + movl (gdt_desc+2), %ebx + add %eax, %ebx + movl %ebx, %gs:GS_GDT_DESC + 2 + + /* initialize HVM memmap table using int 0x15(e820) */ + + /* ES =3D pvh_e820 struct */ + mov $pvh_e820, %eax + shr $4, %eax + mov %ax, %es + + /* start storing memmap table at %es:8 (pvh_e820.table) */ + mov $8,%edi + xor %ebx, %ebx + jmp memmap_loop + +memmap_loop_check: + /* pvh_e820 can contains up to 128 entries */ + cmp $128, %ebx + je memmap_done + +memmap_loop: + /* entry size (hvm_memmap_table_entry) & max buffer size (int15) */ + movl $24, %ecx + /* e820 */ + movl $0x0000e820, %eax + /* 'SMAP' magic */ + movl $0x534d4150, %edx + /* store counter value at %es:0 (pvh_e820.entries) */ + movl %ebx, %es:0 + + int $0x15 + /* error or last entry already done? */ + jb memmap_err + + /* %edi +=3D entry size (hvm_memmap_table_entry) */ + add $24, %edi + + /* continuation value 0 means last entry */ + test %ebx, %ebx + jnz memmap_loop_check + + /* increase pvh_e820.entries to save the last entry */ + movl %es:0, %ebx + inc %ebx + +memmap_done: + movl %ebx, %es:0 + +memmap_err: + + /* load the GDT before going into protected mode */ +lgdt: + data32 lgdt %gs:GS_GDT_DESC + + /* get us to protected mode now */ + movl $1, %eax + movl %eax, %cr0 + + /* the LJMP sets CS for us and gets us to 32-bit */ +ljmp: + data32 ljmp *%gs:GS_PROT_JUMP + +prot_mode: +.code32 + + /* initialize all other segments */ + movl $0x10, %eax + movl %eax, %ss + movl %eax, %ds + movl %eax, %es + movl %eax, %fs + movl %eax, %gs + + jmp pvh_load_kernel + +/* Variables */ +.align 4, 0 +prot_jump: .long prot_mode + .short 8 + +.align 4, 0 +gdt: + /* 0x00 */ +.byte 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 + + /* + * 0x08: code segment + * (base=3D0, limit=3D0xfffff, type=3D32bit code exec/read, DPL=3D0, 4k) + */ +.byte 0xff, 0xff, 0x00, 0x00, 0x00, 0x9a, 0xcf, 0x00 + + /* + * 0x10: data segment + * (base=3D0, limit=3D0xfffff, type=3D32bit data read/write, DPL=3D0, 4k) + */ +.byte 0xff, 0xff, 0x00, 0x00, 0x00, 0x92, 0xcf, 0x00 + + /* + * 0x18: code segment + * (base=3D0, limit=3D0x0ffff, type=3D16bit code exec/read/conf, DPL=3D0,= 1b) + */ +.byte 0xff, 0xff, 0x00, 0x00, 0x00, 0x9e, 0x00, 0x00 + + /* + * 0x20: data segment + * (base=3D0, limit=3D0x0ffff, type=3D16bit data read/write, DPL=3D0, 1b) + */ +.byte 0xff, 0xff, 0x00, 0x00, 0x00, 0x92, 0x00, 0x00 + +gdt_desc: +.short (5 * 8) - 1 +.long gdt + +BOOT_ROM_END diff --git a/pc-bios/optionrom/pvh_main.c b/pc-bios/optionrom/pvh_main.c new file mode 100644 index 0000000000..f355476e68 --- /dev/null +++ b/pc-bios/optionrom/pvh_main.c @@ -0,0 +1,116 @@ +/* + * PVH Option ROM for fw_cfg DMA + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, see . + * + * Copyright (c) 2019 Red Hat Inc. + * Authors: + * Stefano Garzarella + */ + +asm (".code32"); /* this code will be executed in protected mode */ + +#include +#include +#include "optrom.h" +#include "optrom_fw_cfg.h" +#include "../../include/hw/xen/start_info.h" + +#define RSDP_SIGNATURE 0x2052545020445352LL /* "RSD PTR " */ +#define RSDP_AREA_ADDR 0x000E0000 +#define RSDP_AREA_SIZE 2048 +#define EBDA_BASE_ADDR 0x0000040E +#define EBDA_SIZE 1024 + +#define E820_MAXENTRIES 128 +#define CMDLINE_BUFSIZE 4096 + +/* e820 table filled in pvh.S using int 0x15 */ +struct pvh_e820_table { + uint32_t entries; + uint32_t reserved; + struct hvm_memmap_table_entry table[E820_MAXENTRIES]; +}; + +struct pvh_e820_table pvh_e820 __attribute__ ((aligned)); + +static struct hvm_start_info start_info; +static uint8_t cmdline_buffer[CMDLINE_BUFSIZE]; + + +/* Search RSDP signature. */ +static uintptr_t search_rsdp(uint32_t start_addr, uint32_t end_addr) +{ + uint64_t *rsdp_p; + + /* RSDP signature is always on a 16 byte boundary */ + for (rsdp_p =3D (uint64_t *)start_addr; rsdp_p < (uint64_t *)end_addr; + rsdp_p +=3D 2) { + if (*rsdp_p =3D=3D RSDP_SIGNATURE) { + return (uintptr_t)rsdp_p; + } + } + + return 0; +} + +/* Force the asm name without leading underscore, even on Win32. */ +extern void pvh_load_kernel(void) asm("pvh_load_kernel"); + +void pvh_load_kernel(void) +{ + void *cmdline_addr =3D &cmdline_buffer; + void *kernel_entry; + uint32_t cmdline_size, fw_cfg_version =3D bios_cfg_version(); + + start_info.magic =3D XEN_HVM_START_MAGIC_VALUE; + start_info.version =3D 1; + + /* + * pvh_e820 is filled in the pvh.S before to switch in protected mode, + * because we can use int 0x15 only in real mode. + */ + start_info.memmap_entries =3D pvh_e820.entries; + start_info.memmap_paddr =3D (uintptr_t)pvh_e820.table; + + /* + * Search RSDP in the main BIOS area below 1 MB. + * SeaBIOS store the RSDP in this area, so we try it first. + */ + start_info.rsdp_paddr =3D search_rsdp(RSDP_AREA_ADDR, + RSDP_AREA_ADDR + RSDP_AREA_SIZE); + + /* Search RSDP in the EBDA if it is not found */ + if (!start_info.rsdp_paddr) { + /* + * Th EBDA address is stored at EBDA_BASE_ADDR. It contains 2 bytes + * segment pointer to EBDA, so we must convert it to a linear addr= ess. + */ + uint32_t ebda_paddr =3D ((uint32_t)*((uint16_t *)EBDA_BASE_ADDR)) = << 4; + if (ebda_paddr > 0x400) { + uint32_t *ebda =3D (uint32_t *)ebda_paddr; + + start_info.rsdp_paddr =3D search_rsdp(*ebda, *ebda + EBDA_SIZE= ); + } + } + + bios_cfg_read_entry(&cmdline_size, FW_CFG_CMDLINE_SIZE, 4, fw_cfg_vers= ion); + bios_cfg_read_entry(cmdline_addr, FW_CFG_CMDLINE_DATA, cmdline_size, + fw_cfg_version); + start_info.cmdline_paddr =3D (uintptr_t)cmdline_addr; + + bios_cfg_read_entry(&kernel_entry, FW_CFG_KERNEL_ENTRY, 4, fw_cfg_vers= ion); + + asm volatile("jmp *%1" : : "b"(&start_info), "c"(kernel_entry)); +} diff --git a/pc-bios/pvh.bin b/pc-bios/pvh.bin new file mode 100644 index 0000000000000000000000000000000000000000..38a41761014957d50eb55d790b6= 957888cbeee0a GIT binary patch literal 1536 zcmeHFO=3DuHA6n6(H}8AjdpoTU zx4nc-R}e_ND=3Dt*H!BfH+!No@%FjUZISAWu>0?idgIy6ml^CD#nRCq@fD@>KeLo{cJ zx<%EHEKnhzpezJ1;e`YXiJ*q+1O(dw!^hpQ7pT$a2cWrlj?Wv^Sfe_CWwc zMo)jE&+1vdsF$n<=3DmMch!vS2`2j zK!@F5v$80&x6v7?AWe<181b?evP*iw8i<%%klA}>YNs^C{Dc*yLMGq=3DSW-nI6_nz7 z%BQ6w;Ckur%B0+$A8tL@hLl04m5hw{>C(7}61AJepV^K6N>WV`zv-#NDc*SAb=3DdU8 z5b@4O`C!McqcH|Kx{Aj1B+>F^0QgY1D)%opHOIngz1aUP-qIAVoR)6wz;q=3Dm*Mipv z=3D?|voayiHJbe2&xOGkaE10O;y;NEju1??_JHTm9Z>j)BPk9irSsmV*X_u;`NrP9Ud z%ot~9Rh(Jtfr&cgU_oNW2m;LiR3Q!ALGXk(Z}9T$GhKShTmL->w!D%ws>&g?f%w@+ zeuT4BTZlMz-YL+5)_DUw-%XYIy$L=3D$Oq1<-Wir@)@zRC7_9%jMI3GvdpT4aQ+qTO=3D z{<(%7q70X%#fZPOwr1O0K*musTl&iVe`IVV@%M;Ha;boqtX@vs1JUeX6R{T8otMbP NY^|*c{O<$?e*uLwDi8nw literal 0 HcmV?d00001 --=20 2.20.1 From nobody Sat May 18 06:04:10 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1547814765941937.349605950436; Fri, 18 Jan 2019 04:32:45 -0800 (PST) Received: from localhost ([127.0.0.1]:37809 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gkTKG-00079y-UJ for importer@patchew.org; Fri, 18 Jan 2019 07:32:44 -0500 Received: from eggs.gnu.org ([209.51.188.92]:49793) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gkSzI-0005yi-IB for qemu-devel@nongnu.org; Fri, 18 Jan 2019 07:11:05 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gkSzH-0005MT-UB for qemu-devel@nongnu.org; Fri, 18 Jan 2019 07:11:04 -0500 Received: from mx1.redhat.com ([209.132.183.28]:51460) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gkSzH-0005Le-No for qemu-devel@nongnu.org; Fri, 18 Jan 2019 07:11:03 -0500 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 7F1A0B0CC2; Fri, 18 Jan 2019 12:02:08 +0000 (UTC) Received: from steredhat.redhat.com (ovpn-117-61.ams2.redhat.com [10.36.117.61]) by smtp.corp.redhat.com (Postfix) with ESMTP id 84A3B600C2; Fri, 18 Jan 2019 12:02:03 +0000 (UTC) From: Stefano Garzarella To: qemu-devel@nongnu.org Date: Fri, 18 Jan 2019 13:01:42 +0100 Message-Id: <20190118120143.21631-5-sgarzare@redhat.com> In-Reply-To: <20190118120143.21631-1-sgarzare@redhat.com> References: <20190118120143.21631-1-sgarzare@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.26]); Fri, 18 Jan 2019 12:02:08 +0000 (UTC) Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH v5 4/5] hw/i386/pc: use PVH option rom X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Eduardo Habkost , Maran Wilson , "Michael S. Tsirkin" , George Kennedy , Stefan Hajnoczi , Paolo Bonzini , Boris Ostrovsky , Richard Henderson Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" Use pvh.bin option rom when we are booting an uncompressed kernel using the x86/HVM direct boot ABI. Signed-off-by: Stefano Garzarella Reviewed-by: Stefan Hajnoczi Reviewed-by: Liam Merwick --- hw/i386/pc.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/hw/i386/pc.c b/hw/i386/pc.c index 9ed5063de8..2833b130ba 100644 --- a/hw/i386/pc.c +++ b/hw/i386/pc.c @@ -1252,6 +1252,10 @@ static void load_linux(PCMachineState *pcms, initrd_size); } =20 + option_rom[nb_option_roms].bootindex =3D 0; + option_rom[nb_option_roms].name =3D "pvh.bin"; + nb_option_roms++; + return; } /* This looks like a multiboot kernel. If it is, let's stop @@ -1703,6 +1707,7 @@ void xen_load_linux(PCMachineState *pcms) for (i =3D 0; i < nb_option_roms; i++) { assert(!strcmp(option_rom[i].name, "linuxboot.bin") || !strcmp(option_rom[i].name, "linuxboot_dma.bin") || + !strcmp(option_rom[i].name, "pvh.bin") || !strcmp(option_rom[i].name, "multiboot.bin")); rom_add_option(option_rom[i].name, option_rom[i].bootindex); } --=20 2.20.1 From nobody Sat May 18 06:04:10 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1547813832780771.1889602899275; Fri, 18 Jan 2019 04:17:12 -0800 (PST) Received: from localhost ([127.0.0.1]:37460 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gkT5D-0002w7-Lw for importer@patchew.org; Fri, 18 Jan 2019 07:17:11 -0500 Received: from eggs.gnu.org ([209.51.188.92]:49797) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gkSzI-0005zh-Qi for qemu-devel@nongnu.org; Fri, 18 Jan 2019 07:11:07 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gkSzI-0005Mb-09 for qemu-devel@nongnu.org; Fri, 18 Jan 2019 07:11:04 -0500 Received: from mx1.redhat.com ([209.132.183.28]:51454) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gkSzH-0005Lc-Nz for qemu-devel@nongnu.org; Fri, 18 Jan 2019 07:11:03 -0500 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 14D32B280F; Fri, 18 Jan 2019 12:02:14 +0000 (UTC) Received: from steredhat.redhat.com (ovpn-117-61.ams2.redhat.com [10.36.117.61]) by smtp.corp.redhat.com (Postfix) with ESMTP id D8E67600C2; Fri, 18 Jan 2019 12:02:08 +0000 (UTC) From: Stefano Garzarella To: qemu-devel@nongnu.org Date: Fri, 18 Jan 2019 13:01:43 +0100 Message-Id: <20190118120143.21631-6-sgarzare@redhat.com> In-Reply-To: <20190118120143.21631-1-sgarzare@redhat.com> References: <20190118120143.21631-1-sgarzare@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.26]); Fri, 18 Jan 2019 12:02:14 +0000 (UTC) Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH v5 5/5] optionrom/pvh: load initrd from fw_cfg X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Eduardo Habkost , Maran Wilson , "Michael S. Tsirkin" , George Kennedy , Stefan Hajnoczi , Paolo Bonzini , Boris Ostrovsky , Richard Henderson Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" If we found initrd through fw_cfg, we can load it and use the first module of hvm_start_info to pass initrd address and size to the kernel. Signed-off-by: Stefano Garzarella Reviewed-by: Stefan Hajnoczi Reviewed-by: Liam Merwick --- pc-bios/optionrom/pvh_main.c | 21 +++++++++++++++++++-- pc-bios/pvh.bin | Bin 1536 -> 1536 bytes 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/pc-bios/optionrom/pvh_main.c b/pc-bios/optionrom/pvh_main.c index f355476e68..d1b8b4b96e 100644 --- a/pc-bios/optionrom/pvh_main.c +++ b/pc-bios/optionrom/pvh_main.c @@ -46,6 +46,7 @@ struct pvh_e820_table { struct pvh_e820_table pvh_e820 __attribute__ ((aligned)); =20 static struct hvm_start_info start_info; +static struct hvm_modlist_entry ramdisk_mod; static uint8_t cmdline_buffer[CMDLINE_BUFSIZE]; =20 =20 @@ -71,8 +72,8 @@ extern void pvh_load_kernel(void) asm("pvh_load_kernel"); void pvh_load_kernel(void) { void *cmdline_addr =3D &cmdline_buffer; - void *kernel_entry; - uint32_t cmdline_size, fw_cfg_version =3D bios_cfg_version(); + void *kernel_entry, *initrd_addr; + uint32_t cmdline_size, initrd_size, fw_cfg_version =3D bios_cfg_versio= n(); =20 start_info.magic =3D XEN_HVM_START_MAGIC_VALUE; start_info.version =3D 1; @@ -110,6 +111,22 @@ void pvh_load_kernel(void) fw_cfg_version); start_info.cmdline_paddr =3D (uintptr_t)cmdline_addr; =20 + /* Check if we have the initrd to load */ + bios_cfg_read_entry(&initrd_size, FW_CFG_INITRD_SIZE, 4, fw_cfg_versio= n); + if (initrd_size) { + bios_cfg_read_entry(&initrd_addr, FW_CFG_INITRD_ADDR, 4, + fw_cfg_version); + bios_cfg_read_entry(initrd_addr, FW_CFG_INITRD_DATA, initrd_size, + fw_cfg_version); + + ramdisk_mod.paddr =3D (uintptr_t)initrd_addr; + ramdisk_mod.size =3D initrd_size; + + /* The first module is always ramdisk. */ + start_info.modlist_paddr =3D (uintptr_t)&ramdisk_mod; + start_info.nr_modules =3D 1; + } + bios_cfg_read_entry(&kernel_entry, FW_CFG_KERNEL_ENTRY, 4, fw_cfg_vers= ion); =20 asm volatile("jmp *%1" : : "b"(&start_info), "c"(kernel_entry)); diff --git a/pc-bios/pvh.bin b/pc-bios/pvh.bin index 38a41761014957d50eb55d790b6957888cbeee0a..8033080ada2db4c4613fdc3bb5a= 69d79c7b0c0ca 100644 GIT binary patch delta 735 zcmZqRY2cYKndyM&#;Nv<`Y|dZ$5|Uh85k;#<{2MnZ2__v85kHA9sn{HZvYZIPJmb| zfW&duHKLQ5nUrMIfhw902-q@k@G+F$J|Cout)f{N^UIC!Q4iTVG=3Dc}~$y9I%~ogfvxH7Wv~w?60W5Uq#G zb^8ECzJtWNSyZ}1R9F_z0NXGJNbcZV*bKQ3xZ=3DQ(yf415}LN%^5^G8scV%O`y;R+Qji<3DDe^<^K@j Z2no&!h6hlR%ga4L7i~VsEX~MR4FFIY;aUIy delta 434 zcmZqRY2cYKnW;f!<5YV_{Sp>3=3D9kl8-R?(1wdj)2Z)sc zB#yJ@h)iZ?Qj%c@s%SnSV9UV4$549rIBNn>5(JL3rie^-WRk9*!N9`6V0pM)?4=3Dn{ zY40|WBv6CpVg5E%pg^}k~;W} z(J7;H+(iY*0P26n#NRp{$k;2u3Un37%Fb75@AnA;c{@QWdTUffIzN5R*&&(+mFxBa zirfc@b+f2+hp4bDjsV*b10;6{Ko!CC3V_t@289Gro525v%|~RS