From patchwork Wed Jan 25 21:01:26 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gerhard Wiesinger X-Patchwork-Id: 137861 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [140.186.70.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 854DFB6F65 for ; Thu, 26 Jan 2012 08:03:26 +1100 (EST) Received: from localhost ([::1]:57357 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RqA03-000094-Je for incoming@patchwork.ozlabs.org; Wed, 25 Jan 2012 16:03:23 -0500 Received: from eggs.gnu.org ([140.186.70.92]:37153) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Rq9zt-0008MO-4w for qemu-devel@nongnu.org; Wed, 25 Jan 2012 16:03:18 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Rq9zn-0001OS-IV for qemu-devel@nongnu.org; Wed, 25 Jan 2012 16:03:11 -0500 Received: from chello084112167138.7.11.vie.surfer.at ([84.112.167.138]:58761 helo=wiesinger.com) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Rq9zm-0001LK-8v for qemu-devel@nongnu.org; Wed, 25 Jan 2012 16:03:06 -0500 Received: from bbs.intern (localhost [127.0.0.1]) by wiesinger.com (8.14.4/8.14.4) with ESMTP id q0PL1Q7h009447 for ; Wed, 25 Jan 2012 22:01:26 +0100 Received: from localhost (gerhard@localhost) by bbs.intern (8.14.4/8.14.4/Submit) with ESMTP id q0PL1QHl009443 for ; Wed, 25 Jan 2012 22:01:26 +0100 Date: Wed, 25 Jan 2012 22:01:26 +0100 (CET) From: Gerhard Wiesinger To: qemu-devel@nongnu.org Message-ID: User-Agent: Alpine 2.02 (LFD 1266 2009-07-14) MIME-Version: 1.0 X-MailScanner-Information-wiesinger-com: Please contact the ISP for more information X-wiesinger-com-MailScanner-ID: q0PL1Q7h009447 X-MailScanner-wiesinger-com: Found to be clean X-MailScanner-SpamCheck-wiesinger-com: not spam, SpamAssassin (not cached, score=-4.399, required 4.5, autolearn=not spam, ALL_TRUSTED -1.80, BAYES_00 -2.60) X-MailScanner-From: lists@wiesinger.com X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 84.112.167.138 Subject: [Qemu-devel] [PATCH] network: Added option to disable NIC option roms 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 Option ROM for network interface cards (NICs) can now explicitly disabled with romfile=disabled (or romfile=no or romfile=none) parameter. With hotplugable NICs (currently NE2000, PCNET) romfile=(empty) didn't work. This patch disables Option ROMs for iPXE for alls supported NICs (hotplugable and non hotplugable). Examples with 2 NICs with disabled Option ROM (separated on different lines for readabi$ -device rtl8139,mac=1a:46:0b:ca:bc:7c,vlan=0,romfile=disabled -net tap,ifname=tap0,script=no,downscript=no,vlan=0 -device pcnet,mac=1a:46:0b:ca:bc:7e,vlan=1,romfile=disabled -net tap,ifname=tap1,script=no,downscript=no,vlan=1 Signed-off-by: Gerhard Wiesinger --- hw/ne2000.c | 2 +- hw/pci.c | 39 ++++++++++++++++++++++++++++++++++++--- hw/pci.h | 7 +++++++ hw/pcnet-pci.c | 2 +- 4 files changed, 45 insertions(+), 5 deletions(-) diff --git a/hw/ne2000.c b/hw/ne2000.c index 62e082f..67bf458 100644 --- a/hw/ne2000.c +++ b/hw/ne2000.c @@ -765,7 +765,7 @@ static int pci_ne2000_init(PCIDevice *pci_dev) if (!pci_dev->qdev.hotplugged) { static int loaded = 0; - if (!loaded) { + if (!loaded && pci_has_not_explicitly_disabled_option_romfile(pci_dev)) { rom_add_option("pxe-ne2k_pci.rom", -1); loaded = 1; } diff --git a/hw/pci.c b/hw/pci.c index c3082bc..a9e0758 100644 --- a/hw/pci.c +++ b/hw/pci.c @@ -126,6 +126,41 @@ static void pci_change_irq_level(PCIDevice *pci_dev, int irq_num, int change) bus->set_irq(bus->irq_opaque, irq_num, bus->irq_count[irq_num] != 0); } +static int pci_is_disabled_romfile_string(const char *s) +{ + if (strcmp(s, PCI_DEVICE_DISABLED_OPTION_ROMFILE) == 0) + return 1; + if (strcmp(s, PCI_DEVICE_DISABLED_OPTION_ROMFILE_ALTERNATE1) == 0) + return 1; + if (strcmp(s, PCI_DEVICE_DISABLED_OPTION_ROMFILE_ALTERNATE2) == 0) + return 1; + return 0; +} + +int pci_has_enabled_option_romfile(PCIDevice *pdev) +{ + PCI_DPRINTF("pci_has_enabled_option_romfile: device=%s, romfile=%s\n", pdev->name, pdev->romfile); + if (pdev->romfile == NULL) + return 0; + if (strlen(pdev->romfile) == 0) + return 0; + if (pci_is_disabled_romfile_string(pdev->romfile)) + return 0; + return 1; +} + +int pci_has_not_explicitly_disabled_option_romfile(PCIDevice *pdev) +{ + PCI_DPRINTF("pci_has_not_explicitly_disabled_option_romfile: device=%s, romfile=%s\n", pdev->name, pdev->romfile); + + /* No romfile is present for hotplugged devices, therefore dynamic codes decides */ + if (pdev->romfile == NULL) + return 1; + if (pci_is_disabled_romfile_string(pdev->romfile)) + return 0; + return 1; +} + int pci_bus_get_irq_level(PCIBus *bus, int irq_num) { assert(irq_num >= 0); @@ -1725,9 +1760,7 @@ static int pci_add_option_rom(PCIDevice *pdev, bool is_default_rom) void *ptr; char name[32]; - if (!pdev->romfile) - return 0; - if (strlen(pdev->romfile) == 0) + if (!pci_has_enabled_option_romfile(pdev)) return 0; if (!pdev->rom_bar) { diff --git a/hw/pci.h b/hw/pci.h index 625e717..c5d071d 100644 --- a/hw/pci.h +++ b/hw/pci.h @@ -78,6 +78,10 @@ #define FMT_PCIBUS PRIx64 +#define PCI_DEVICE_DISABLED_OPTION_ROMFILE "disabled" +#define PCI_DEVICE_DISABLED_OPTION_ROMFILE_ALTERNATE1 "none" +#define PCI_DEVICE_DISABLED_OPTION_ROMFILE_ALTERNATE2 "no" + typedef void PCIConfigWriteFunc(PCIDevice *pci_dev, uint32_t address, uint32_t data, int len); typedef uint32_t PCIConfigReadFunc(PCIDevice *pci_dev, @@ -275,6 +279,9 @@ int pci_read_devaddr(Monitor *mon, const char *addr, int *domp, int *busp, void pci_device_deassert_intx(PCIDevice *dev); +int pci_has_enabled_option_romfile(PCIDevice *pdev); +int pci_has_not_explicitly_disabled_option_romfile(PCIDevice *pdev); + static inline void pci_set_byte(uint8_t *config, uint8_t val) { diff --git a/hw/pcnet-pci.c b/hw/pcnet-pci.c index 4e164da..e65745f 100644 --- a/hw/pcnet-pci.c +++ b/hw/pcnet-pci.c @@ -332,7 +332,7 @@ static int pci_pcnet_init(PCIDevice *pci_dev) if (!pci_dev->qdev.hotplugged) { static int loaded = 0; - if (!loaded) { + if (!loaded && pci_has_not_explicitly_disabled_option_romfile(pci_dev)) { rom_add_option("pxe-pcnet.rom", -1); loaded = 1; }