From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from [140.186.70.92] (port=33200 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1Q6lhf-0001xy-LW for qemu-devel@nongnu.org; Mon, 04 Apr 2011 11:28:33 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Q6lhX-0001mv-WB for qemu-devel@nongnu.org; Mon, 04 Apr 2011 11:28:24 -0400 Received: from mx1.redhat.com ([209.132.183.28]:25197) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Q6lhX-0001mW-LC for qemu-devel@nongnu.org; Mon, 04 Apr 2011 11:28:23 -0400 Received: from int-mx12.intmail.prod.int.phx2.redhat.com (int-mx12.intmail.prod.int.phx2.redhat.com [10.5.11.25]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id p34FSMhS007474 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Mon, 4 Apr 2011 11:28:22 -0400 Received: from cleopatra.tlv.redhat.com (cleopatra.tlv.redhat.com [10.35.255.11]) by int-mx12.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id p34FSMtB016066 for ; Mon, 4 Apr 2011 11:28:22 -0400 From: Avi Kivity Date: Mon, 4 Apr 2011 18:27:58 +0300 Message-Id: <1301930887-20705-2-git-send-email-avi@redhat.com> In-Reply-To: <1301930887-20705-1-git-send-email-avi@redhat.com> References: <1301930887-20705-1-git-send-email-avi@redhat.com> Subject: [Qemu-devel] [PATCH 01/10] pci: add pci_register_bar_simple() API List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: "Michael S. Tsirkin" Cc: qemu-devel@nongnu.org This is similar to pci_register_bar(), but automatically registers a single memory region spanning the entire BAR. Signed-off-by: Avi Kivity --- hw/pci.c | 17 +++++++++++++++++ hw/pci.h | 3 +++ 2 files changed, 20 insertions(+), 0 deletions(-) diff --git a/hw/pci.c b/hw/pci.c index 6b577e1..65ae196 100644 --- a/hw/pci.c +++ b/hw/pci.c @@ -859,6 +859,7 @@ void pci_register_bar(PCIDevice *pci_dev, int region_num, r->filtered_size = size; r->type = type; r->map_func = map_func; + r->ram_addr = IO_MEM_UNASSIGNED; wmask = ~(size - 1); addr = pci_bar(pci_dev, region_num); @@ -877,6 +878,22 @@ void pci_register_bar(PCIDevice *pci_dev, int region_num, } } +static void pci_simple_bar_mapfunc(PCIDevice *pci_dev, int region_num, + pcibus_t addr, pcibus_t size, int type) +{ + cpu_register_physical_memory(addr, size, + pci_dev->io_regions[region_num].ram_addr); +} + +void pci_register_bar_simple(PCIDevice *pci_dev, int region_num, + pcibus_t size, uint8_t attr, ram_addr_t ram_addr) +{ + pci_register_bar(pci_dev, region_num, size, + PCI_BASE_ADDRESS_SPACE_MEMORY | attr, + pci_simple_bar_mapfunc); + pci_dev->io_regions[region_num].ram_addr = ram_addr; +} + static void pci_bridge_filter(PCIDevice *d, pcibus_t *addr, pcibus_t *size, uint8_t type) { diff --git a/hw/pci.h b/hw/pci.h index 52ee8c9..3230764 100644 --- a/hw/pci.h +++ b/hw/pci.h @@ -92,6 +92,7 @@ typedef struct PCIIORegion { pcibus_t filtered_size; uint8_t type; PCIMapIORegionFunc *map_func; + ram_addr_t ram_addr; } PCIIORegion; #define PCI_ROM_SLOT 6 @@ -200,6 +201,8 @@ PCIDevice *pci_register_device(PCIBus *bus, const char *name, void pci_register_bar(PCIDevice *pci_dev, int region_num, pcibus_t size, uint8_t type, PCIMapIORegionFunc *map_func); +void pci_register_bar_simple(PCIDevice *pci_dev, int region_num, + pcibus_t size, uint8_t attr, ram_addr_t ram_addr); int pci_add_capability(PCIDevice *pdev, uint8_t cap_id, uint8_t offset, uint8_t size); -- 1.7.1