From patchwork Mon Aug 15 14:17:25 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Avi Kivity X-Patchwork-Id: 1067752 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by demeter1.kernel.org (8.14.4/8.14.4) with ESMTP id p7FEI1GJ026614 for ; Mon, 15 Aug 2011 14:18:37 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753559Ab1HOOSW (ORCPT ); Mon, 15 Aug 2011 10:18:22 -0400 Received: from mx1.redhat.com ([209.132.183.28]:11899 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753556Ab1HOORp (ORCPT ); Mon, 15 Aug 2011 10:17:45 -0400 Received: from int-mx09.intmail.prod.int.phx2.redhat.com (int-mx09.intmail.prod.int.phx2.redhat.com [10.5.11.22]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id p7FEHhQh002880 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Mon, 15 Aug 2011 10:17:43 -0400 Received: from cleopatra.tlv.redhat.com (cleopatra.tlv.redhat.com [10.35.255.11]) by int-mx09.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id p7FEHgca001061; Mon, 15 Aug 2011 10:17:42 -0400 Received: from s01.tlv.redhat.com (s01.tlv.redhat.com [10.35.255.8]) by cleopatra.tlv.redhat.com (Postfix) with ESMTP id 9B48B250B53; Mon, 15 Aug 2011 17:17:40 +0300 (IDT) From: Avi Kivity To: Anthony Liguori , qemu-devel@nongnu.org Cc: kvm@vger.kernel.org Subject: [PATCH v2 11/24] pcie_host: convert to memory API Date: Mon, 15 Aug 2011 17:17:25 +0300 Message-Id: <1313417858-6454-12-git-send-email-avi@redhat.com> In-Reply-To: <1313417858-6454-1-git-send-email-avi@redhat.com> References: <1313417858-6454-1-git-send-email-avi@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.22 Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org X-Greylist: IP, sender and recipient auto-whitelisted, not delayed by milter-greylist-4.2.6 (demeter1.kernel.org [140.211.167.41]); Mon, 15 Aug 2011 14:18:37 +0000 (UTC) Assuming that mmcfg size cannot change at runtime. Signed-off-by: Avi Kivity --- hw/pcie_host.c | 98 ++++++++++++++----------------------------------------- hw/pcie_host.h | 12 +++--- 2 files changed, 31 insertions(+), 79 deletions(-) diff --git a/hw/pcie_host.c b/hw/pcie_host.c index f9fea3d..28bbe72 100644 --- a/hw/pcie_host.c +++ b/hw/pcie_host.c @@ -22,6 +22,7 @@ #include "hw.h" #include "pci.h" #include "pcie_host.h" +#include "exec-memory.h" /* * PCI express mmcfig address @@ -52,9 +53,11 @@ static inline PCIDevice *pcie_dev_find_by_mmcfg_addr(PCIBus *s, PCIE_MMCFG_DEVFN(mmcfg_addr)); } -static void pcie_mmcfg_data_write(PCIBus *s, - uint32_t mmcfg_addr, uint32_t val, int len) +static void pcie_mmcfg_data_write(void *opaque, target_phys_addr_t mmcfg_addr, + uint64_t val, unsigned len) { + PCIExpressHost *e = opaque; + PCIBus *s = e->pci.bus; PCIDevice *pci_dev = pcie_dev_find_by_mmcfg_addr(s, mmcfg_addr); uint32_t addr; uint32_t limit; @@ -72,8 +75,12 @@ static void pcie_mmcfg_data_write(PCIBus *s, pci_host_config_write_common(pci_dev, addr, limit, val, len); } -static uint32_t pcie_mmcfg_data_read(PCIBus *s, uint32_t mmcfg_addr, int len) +static uint64_t pcie_mmcfg_data_read(void *opaque, + target_phys_addr_t mmcfg_addr, + unsigned len) { + PCIExpressHost *e = opaque; + PCIBus *s = e->pci.bus; PCIDevice *pci_dev = pcie_dev_find_by_mmcfg_addr(s, mmcfg_addr); uint32_t addr; uint32_t limit; @@ -91,72 +98,23 @@ static uint32_t pcie_mmcfg_data_read(PCIBus *s, uint32_t mmcfg_addr, int len) return pci_host_config_read_common(pci_dev, addr, limit, len); } -static void pcie_mmcfg_data_writeb(void *opaque, - target_phys_addr_t addr, uint32_t value) -{ - PCIExpressHost *e = opaque; - pcie_mmcfg_data_write(e->pci.bus, addr - e->base_addr, value, 1); -} - -static void pcie_mmcfg_data_writew(void *opaque, - target_phys_addr_t addr, uint32_t value) -{ - PCIExpressHost *e = opaque; - pcie_mmcfg_data_write(e->pci.bus, addr - e->base_addr, value, 2); -} - -static void pcie_mmcfg_data_writel(void *opaque, - target_phys_addr_t addr, uint32_t value) -{ - PCIExpressHost *e = opaque; - pcie_mmcfg_data_write(e->pci.bus, addr - e->base_addr, value, 4); -} - -static uint32_t pcie_mmcfg_data_readb(void *opaque, target_phys_addr_t addr) -{ - PCIExpressHost *e = opaque; - return pcie_mmcfg_data_read(e->pci.bus, addr - e->base_addr, 1); -} - -static uint32_t pcie_mmcfg_data_readw(void *opaque, target_phys_addr_t addr) -{ - PCIExpressHost *e = opaque; - return pcie_mmcfg_data_read(e->pci.bus, addr - e->base_addr, 2); -} - -static uint32_t pcie_mmcfg_data_readl(void *opaque, target_phys_addr_t addr) -{ - PCIExpressHost *e = opaque; - return pcie_mmcfg_data_read(e->pci.bus, addr - e->base_addr, 4); -} - - -static CPUWriteMemoryFunc * const pcie_mmcfg_write[] = -{ - pcie_mmcfg_data_writeb, - pcie_mmcfg_data_writew, - pcie_mmcfg_data_writel, -}; - -static CPUReadMemoryFunc * const pcie_mmcfg_read[] = -{ - pcie_mmcfg_data_readb, - pcie_mmcfg_data_readw, - pcie_mmcfg_data_readl, +static const MemoryRegionOps pcie_mmcfg_ops = { + .read = pcie_mmcfg_data_read, + .write = pcie_mmcfg_data_write, + .endianness = DEVICE_NATIVE_ENDIAN, }; /* pcie_host::base_addr == PCIE_BASE_ADDR_UNMAPPED when it isn't mapped. */ #define PCIE_BASE_ADDR_UNMAPPED ((target_phys_addr_t)-1ULL) -int pcie_host_init(PCIExpressHost *e) +int pcie_host_init(PCIExpressHost *e, uint32_t size) { + assert(!(size & (size - 1))); /* power of 2 */ + assert(size >= PCIE_MMCFG_SIZE_MIN); + assert(size <= PCIE_MMCFG_SIZE_MAX); e->base_addr = PCIE_BASE_ADDR_UNMAPPED; - e->mmio_index = - cpu_register_io_memory(pcie_mmcfg_read, pcie_mmcfg_write, e, - DEVICE_NATIVE_ENDIAN); - if (e->mmio_index < 0) { - return -1; - } + e->size = size; + memory_region_init_io(&e->mmio, &pcie_mmcfg_ops, e, "pcie-mmcfg", e->size); return 0; } @@ -164,29 +122,23 @@ int pcie_host_init(PCIExpressHost *e) void pcie_host_mmcfg_unmap(PCIExpressHost *e) { if (e->base_addr != PCIE_BASE_ADDR_UNMAPPED) { - cpu_register_physical_memory(e->base_addr, e->size, IO_MEM_UNASSIGNED); + memory_region_del_subregion(get_system_memory(), &e->mmio); e->base_addr = PCIE_BASE_ADDR_UNMAPPED; } } -void pcie_host_mmcfg_map(PCIExpressHost *e, - target_phys_addr_t addr, uint32_t size) +void pcie_host_mmcfg_map(PCIExpressHost *e, target_phys_addr_t addr) { - assert(!(size & (size - 1))); /* power of 2 */ - assert(size >= PCIE_MMCFG_SIZE_MIN); - assert(size <= PCIE_MMCFG_SIZE_MAX); - e->base_addr = addr; - e->size = size; - cpu_register_physical_memory(e->base_addr, e->size, e->mmio_index); + memory_region_add_subregion(get_system_memory(), e->base_addr, &e->mmio); } void pcie_host_mmcfg_update(PCIExpressHost *e, int enable, - target_phys_addr_t addr, uint32_t size) + target_phys_addr_t addr) { pcie_host_mmcfg_unmap(e); if (enable) { - pcie_host_mmcfg_map(e, addr, size); + pcie_host_mmcfg_map(e, addr); } } diff --git a/hw/pcie_host.h b/hw/pcie_host.h index a202661..0074508 100644 --- a/hw/pcie_host.h +++ b/hw/pcie_host.h @@ -22,6 +22,7 @@ #define PCIE_HOST_H #include "pci_host.h" +#include "memory.h" struct PCIExpressHost { PCIHostState pci; @@ -34,16 +35,15 @@ struct PCIExpressHost { /* the size of MMCONFIG area. It's host bridge dependent */ target_phys_addr_t size; - /* result of cpu_register_io_memory() to map MMCONFIG area */ - int mmio_index; + /* MMCONFIG mmio area */ + MemoryRegion mmio; }; -int pcie_host_init(PCIExpressHost *e); +int pcie_host_init(PCIExpressHost *e, uint32_t size); void pcie_host_mmcfg_unmap(PCIExpressHost *e); -void pcie_host_mmcfg_map(PCIExpressHost *e, - target_phys_addr_t addr, uint32_t size); +void pcie_host_mmcfg_map(PCIExpressHost *e, target_phys_addr_t addr); void pcie_host_mmcfg_update(PCIExpressHost *e, int enable, - target_phys_addr_t addr, uint32_t size); + target_phys_addr_t addr); #endif /* PCIE_HOST_H */