From patchwork Thu Dec 17 12:32:44 2009 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gerd Hoffmann X-Patchwork-Id: 41313 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [199.232.76.165]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id BFDFCB6F12 for ; Thu, 17 Dec 2009 23:38:36 +1100 (EST) Received: from localhost ([127.0.0.1]:41637 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1NLFcm-0000G3-Af for incoming@patchwork.ozlabs.org; Thu, 17 Dec 2009 07:38:32 -0500 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1NLFXS-0006TV-77 for qemu-devel@nongnu.org; Thu, 17 Dec 2009 07:33:02 -0500 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1NLFXN-0006SA-4I for qemu-devel@nongnu.org; Thu, 17 Dec 2009 07:33:01 -0500 Received: from [199.232.76.173] (port=37126 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1NLFXM-0006S5-WC for qemu-devel@nongnu.org; Thu, 17 Dec 2009 07:32:57 -0500 Received: from mx1.redhat.com ([209.132.183.28]:13760) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1NLFXM-0008Ed-CJ for qemu-devel@nongnu.org; Thu, 17 Dec 2009 07:32:56 -0500 Received: from int-mx04.intmail.prod.int.phx2.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.17]) by mx1.redhat.com (8.13.8/8.13.8) with ESMTP id nBHCWt88027228 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Thu, 17 Dec 2009 07:32:55 -0500 Received: from zweiblum.home.kraxel.org (vpn2-10-48.ams2.redhat.com [10.36.10.48]) by int-mx04.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id nBHCWngB011271; Thu, 17 Dec 2009 07:32:50 -0500 Received: by zweiblum.home.kraxel.org (Postfix, from userid 500) id BA1B370FC9; Thu, 17 Dec 2009 13:32:48 +0100 (CET) From: Gerd Hoffmann To: qemu-devel@nongnu.org Date: Thu, 17 Dec 2009 13:32:44 +0100 Message-Id: <1261053168-8079-3-git-send-email-kraxel@redhat.com> In-Reply-To: <1261053168-8079-1-git-send-email-kraxel@redhat.com> References: <1261053168-8079-1-git-send-email-kraxel@redhat.com> X-Scanned-By: MIMEDefang 2.67 on 10.5.11.17 X-detected-operating-system: by monty-python.gnu.org: Genre and OS details not recognized. Cc: Anthony Liguori , Gerd Hoffmann Subject: [Qemu-devel] [PATCH 2/6] Support PCI based option rom loading X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org From: Anthony Liguori Currently, we preload option roms into the option rom space in memory. This prevents DDIM from functioning correctly which severely limits the number of roms we can support. This patch introduces a pci_add_option_rom() which registers the PCI_ROM_ADDRESS bar which points to our option rom. It also converts over the cirrus vga adapter, the rtl8139, virtio, and the e1000 to use this new mechanism. The result is that PXE boot functions even with three unique types of cards. Signed-off-by: Anthony Liguori Signed-off-by: Gerd Hoffmann --- hw/cirrus_vga.c | 2 +- hw/e1000.c | 2 +- hw/pci.c | 35 +++++++++++++++++++++++++++++++++++ hw/pci.h | 5 +++++ hw/rtl8139.c | 2 +- hw/virtio-pci.c | 2 +- 6 files changed, 44 insertions(+), 4 deletions(-) diff --git a/hw/cirrus_vga.c b/hw/cirrus_vga.c index 24af81c..b08d2ae 100644 --- a/hw/cirrus_vga.c +++ b/hw/cirrus_vga.c @@ -3211,7 +3211,7 @@ static int pci_cirrus_vga_initfn(PCIDevice *dev) } /* ROM BIOS */ - rom_add_vga(VGABIOS_CIRRUS_FILENAME); + pci_add_option_rom((PCIDevice *)d, VGABIOS_CIRRUS_FILENAME); return 0; } diff --git a/hw/e1000.c b/hw/e1000.c index 8566fe3..f795601 100644 --- a/hw/e1000.c +++ b/hw/e1000.c @@ -1125,7 +1125,7 @@ static int pci_e1000_init(PCIDevice *pci_dev) if (!pci_dev->qdev.hotplugged) { static int loaded = 0; if (!loaded) { - rom_add_option("pxe-e1000.bin"); + pci_add_option_rom(&d->dev, "pxe-e1000.bin"); loaded = 1; } } diff --git a/hw/pci.c b/hw/pci.c index 404eead..dbdfdbf 100644 --- a/hw/pci.c +++ b/hw/pci.c @@ -26,6 +26,7 @@ #include "monitor.h" #include "net.h" #include "sysemu.h" +#include "loader.h" //#define DEBUG_PCI #ifdef DEBUG_PCI @@ -1463,6 +1464,40 @@ static uint8_t pci_find_capability_list(PCIDevice *pdev, uint8_t cap_id, return next; } +static void pci_map_option_rom(PCIDevice *pdev, int region_num, pcibus_t addr, pcibus_t size, int type) +{ + cpu_register_physical_memory(addr, size, pdev->rom_offset); +} + +/* Add an option rom for the device */ +int pci_add_option_rom(PCIDevice *pdev, const char *name) +{ + int size; + char *path; + void *ptr; + + path = qemu_find_file(QEMU_FILE_TYPE_BIOS, name); + if (path == NULL) { + path = qemu_strdup(name); + } + + size = get_image_size(path); + if (size & (size - 1)) { + size = 1 << qemu_fls(size); + } + + pdev->rom_offset = qemu_ram_alloc(size); + + ptr = qemu_get_ram_ptr(pdev->rom_offset); + load_image(path, ptr); + qemu_free(path); + + pci_register_bar(pdev, PCI_ROM_SLOT, size, + 0, pci_map_option_rom); + + return 0; +} + /* Reserve space and add capability to the linked list in pci config space */ int pci_add_capability(PCIDevice *pdev, uint8_t cap_id, uint8_t size) { diff --git a/hw/pci.h b/hw/pci.h index d279e3f..89b3f55 100644 --- a/hw/pci.h +++ b/hw/pci.h @@ -243,6 +243,9 @@ struct PCIDevice { uint32_t msix_bar_size; /* Version id needed for VMState */ int32_t version_id; + + /* Location of option rom */ + ram_addr_t rom_offset; }; PCIDevice *pci_register_device(PCIBus *bus, const char *name, @@ -254,6 +257,8 @@ void pci_register_bar(PCIDevice *pci_dev, int region_num, pcibus_t size, int type, PCIMapIORegionFunc *map_func); +int pci_add_option_rom(PCIDevice *pdev, const char *name); + int pci_add_capability(PCIDevice *pci_dev, uint8_t cap_id, uint8_t cap_size); void pci_del_capability(PCIDevice *pci_dev, uint8_t cap_id, uint8_t cap_size); diff --git a/hw/rtl8139.c b/hw/rtl8139.c index 9fd05a8..2cee97b 100644 --- a/hw/rtl8139.c +++ b/hw/rtl8139.c @@ -3357,7 +3357,7 @@ static int pci_rtl8139_init(PCIDevice *dev) if (!dev->qdev.hotplugged) { static int loaded = 0; if (!loaded) { - rom_add_option("pxe-rtl8139.bin"); + pci_add_option_rom(&s->dev, "pxe-rtl8139.bin"); loaded = 1; } } diff --git a/hw/virtio-pci.c b/hw/virtio-pci.c index 4500130..85f14a2 100644 --- a/hw/virtio-pci.c +++ b/hw/virtio-pci.c @@ -522,7 +522,7 @@ static int virtio_net_init_pci(PCIDevice *pci_dev) if (!pci_dev->qdev.hotplugged) { static int loaded = 0; if (!loaded) { - rom_add_option("pxe-virtio.bin"); + pci_add_option_rom(pci_dev, "pxe-virtio.bin"); loaded = 1; } }