From patchwork Sun Jul 17 11:14:22 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Avi Kivity X-Patchwork-Id: 105019 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 80209B6F75 for ; Sun, 17 Jul 2011 21:51:28 +1000 (EST) Received: from localhost ([::1]:53599 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1QiPsY-0006dX-Vc for incoming@patchwork.ozlabs.org; Sun, 17 Jul 2011 07:51:23 -0400 Received: from eggs.gnu.org ([140.186.70.92]:42847) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1QiPJ3-0005ZP-CJ for qemu-devel@nongnu.org; Sun, 17 Jul 2011 07:14:54 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1QiPIv-0007js-SV for qemu-devel@nongnu.org; Sun, 17 Jul 2011 07:14:40 -0400 Received: from mx1.redhat.com ([209.132.183.28]:51477) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1QiPIu-0007hR-VI for qemu-devel@nongnu.org; Sun, 17 Jul 2011 07:14:33 -0400 Received: from int-mx10.intmail.prod.int.phx2.redhat.com (int-mx10.intmail.prod.int.phx2.redhat.com [10.5.11.23]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id p6HBEWNt028507 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Sun, 17 Jul 2011 07:14:32 -0400 Received: from cleopatra.tlv.redhat.com (cleopatra.tlv.redhat.com [10.35.255.11]) by int-mx10.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id p6HBEUKL031404; Sun, 17 Jul 2011 07:14:32 -0400 Received: from s01.tlv.redhat.com (s01.tlv.redhat.com [10.35.255.8]) by cleopatra.tlv.redhat.com (Postfix) with ESMTP id 7B6FEB0665; Sun, 17 Jul 2011 14:14:27 +0300 (IDT) From: Avi Kivity To: qemu-devel@nongnu.org Date: Sun, 17 Jul 2011 14:14:22 +0300 Message-Id: <1310901265-32051-56-git-send-email-avi@redhat.com> In-Reply-To: <1310901265-32051-1-git-send-email-avi@redhat.com> References: <1310901265-32051-1-git-send-email-avi@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.23 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 209.132.183.28 Cc: kvm@vger.kernel.org Subject: [Qemu-devel] [RFC v4 55/58] pci: convert pci rom to memory API 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 Signed-off-by: Avi Kivity --- hw/pci.c | 20 +++++++------------- hw/pci.h | 3 ++- 2 files changed, 9 insertions(+), 14 deletions(-) diff --git a/hw/pci.c b/hw/pci.c index 9db6fc8..8c7a418 100644 --- a/hw/pci.c +++ b/hw/pci.c @@ -1858,11 +1858,6 @@ 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); -} - /* Patch the PCI vendor and device ids in a PCI rom image if necessary. This is needed for an option rom which is used for more than one device. */ static void pci_patch_ids(PCIDevice *pdev, uint8_t *ptr, int size) @@ -1966,9 +1961,9 @@ static int pci_add_option_rom(PCIDevice *pdev, bool is_default_rom) snprintf(name, sizeof(name), "%s.rom", pdev->qdev.info->vmsd->name); else snprintf(name, sizeof(name), "%s.rom", pdev->qdev.info->name); - pdev->rom_offset = qemu_ram_alloc(&pdev->qdev, name, size); - - ptr = qemu_get_ram_ptr(pdev->rom_offset); + pdev->has_rom = true; + memory_region_init_ram(&pdev->rom, &pdev->qdev, name, size); + ptr = memory_region_get_ram_ptr(&pdev->rom); load_image(path, ptr); qemu_free(path); @@ -1979,19 +1974,18 @@ static int pci_add_option_rom(PCIDevice *pdev, bool is_default_rom) qemu_put_ram_ptr(ptr); - pci_register_bar(pdev, PCI_ROM_SLOT, size, - 0, pci_map_option_rom); + pci_register_bar_region(pdev, PCI_ROM_SLOT, 0, &pdev->rom); return 0; } static void pci_del_option_rom(PCIDevice *pdev) { - if (!pdev->rom_offset) + if (!pdev->has_rom) return; - qemu_ram_free(pdev->rom_offset); - pdev->rom_offset = 0; + memory_region_destroy(&pdev->rom); + pdev->has_rom = false; } /* diff --git a/hw/pci.h b/hw/pci.h index 5209964..c5174bd 100644 --- a/hw/pci.h +++ b/hw/pci.h @@ -192,7 +192,8 @@ struct PCIDevice { /* Location of option rom */ char *romfile; - ram_addr_t rom_offset; + bool has_rom; + MemoryRegion rom; uint32_t rom_bar; };