From patchwork Tue Jan 12 08:52:57 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Isaku Yamahata X-Patchwork-Id: 42696 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 3A4C81007D2 for ; Tue, 12 Jan 2010 20:22:51 +1100 (EST) Received: from localhost ([127.0.0.1]:60961 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1NUce4-0006BO-8v for incoming@patchwork.ozlabs.org; Tue, 12 Jan 2010 04:02:36 -0500 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1NUcUh-0003ID-ID for qemu-devel@nongnu.org; Tue, 12 Jan 2010 03:52:55 -0500 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1NUcUc-0003Es-7k for qemu-devel@nongnu.org; Tue, 12 Jan 2010 03:52:54 -0500 Received: from [199.232.76.173] (port=52554 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1NUcUb-0003EZ-Sd for qemu-devel@nongnu.org; Tue, 12 Jan 2010 03:52:49 -0500 Received: from mail.valinux.co.jp ([210.128.90.3]:41480) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1NUcUa-000188-Q5 for qemu-devel@nongnu.org; Tue, 12 Jan 2010 03:52:49 -0500 Received: from ps.local.valinux.co.jp (vagw.valinux.co.jp [210.128.90.14]) by mail.valinux.co.jp (Postfix) with SMTP id D9605182AC; Tue, 12 Jan 2010 17:52:44 +0900 (JST) Received: (nullmailer pid 10438 invoked by uid 1000); Tue, 12 Jan 2010 08:52:59 -0000 From: Isaku Yamahata To: qemu-devel@nongnu.org Date: Tue, 12 Jan 2010 17:52:57 +0900 Message-Id: <1263286378-10398-6-git-send-email-yamahata@valinux.co.jp> X-Mailer: git-send-email 1.6.5.4 In-Reply-To: <1263286378-10398-1-git-send-email-yamahata@valinux.co.jp> References: <1263286378-10398-1-git-send-email-yamahata@valinux.co.jp> X-Virus-Scanned: clamav-milter 0.95.2 at va-mail.local.valinux.co.jp X-Virus-Status: Clean X-detected-operating-system: by monty-python.gnu.org: GNU/Linux 2.6 (newer, 3) Cc: yamahata@valinux.co.jp, agraf@suse.de, mst@redhat.com Subject: [Qemu-devel] [PATCH 5/6] pci: introduce PCIAddress, PCIConfigAddress and helper functions. 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 Introduce PCIAddress, PCIConfigAddress and helper functions. They will be used later to clean up pci_data_{read, write}(). Cc: Alexander Graf Signed-off-by: Isaku Yamahata --- hw/pci.h | 7 +++++++ hw/pci_host.c | 32 ++++++++++++++++++++++++++++++++ hw/pci_host.h | 16 ++++++++++++++++ qemu-common.h | 2 ++ 4 files changed, 57 insertions(+), 0 deletions(-) diff --git a/hw/pci.h b/hw/pci.h index ed048f5..eb87762 100644 --- a/hw/pci.h +++ b/hw/pci.h @@ -10,6 +10,13 @@ /* PCI bus */ +struct PCIAddress { + PCIBus *domain; + uint8_t bus; + uint8_t slot; + uint8_t fn; +}; + #define PCI_DEVFN(slot, func) ((((slot) & 0x1f) << 3) | ((func) & 0x07)) #define PCI_SLOT(devfn) (((devfn) >> 3) & 0x1f) #define PCI_FUNC(devfn) ((devfn) & 0x07) diff --git a/hw/pci_host.c b/hw/pci_host.c index 307f7d4..fa194e2 100644 --- a/hw/pci_host.c +++ b/hw/pci_host.c @@ -39,6 +39,38 @@ do { printf("pci_host_data: " fmt , ## __VA_ARGS__); } while (0) * bit 0 - 7: offset in configuration space of a given pci device */ +static void pci_host_decode_config_addr(const PCIHostState *s, + uint32_t config_reg, + PCIConfigAddress *decoded) +{ + uint32_t devfn; + + decoded->addr.domain = s->bus; + decoded->addr.bus = (config_reg >> 16) & 0xff; + devfn = (config_reg >> 8) & 0xff; + decoded->addr.slot = PCI_SLOT(devfn); + decoded->addr.fn = PCI_FUNC(devfn); + decoded->offset = config_reg & (PCI_CONFIG_SPACE_SIZE - 1); + decoded->addr_mask = 3; +} + +#define PCI_HOST_CFGE (1u << 31) /* configuration enable */ +void pci_host_decode_config_addr_cfge(const PCIHostState *s, + uint32_t config_reg, + PCIConfigAddress *decoded) +{ + pci_host_decode_config_addr(s, config_reg, decoded); + decoded->valid = (config_reg & PCI_HOST_CFGE) ? true : false; +} + +void pci_host_decode_config_addr_valid(const PCIHostState *s, + uint32_t config_reg, + PCIConfigAddress *decoded) +{ + pci_host_decode_config_addr(s, config_reg, decoded); + decoded->valid = true; +} + /* the helper functio to get a PCIDeice* for a given pci address */ static inline PCIDevice *pci_dev_find_by_addr(PCIBus *bus, uint32_t addr) { diff --git a/hw/pci_host.h b/hw/pci_host.h index a006687..ebc95f2 100644 --- a/hw/pci_host.h +++ b/hw/pci_host.h @@ -30,12 +30,28 @@ #include "sysbus.h" +/* for config space access */ +struct PCIConfigAddress { + PCIAddress addr; + uint32_t addr_mask; + uint16_t offset; + bool valid; +}; + struct PCIHostState { SysBusDevice busdev; uint32_t config_reg; PCIBus *bus; }; +void pci_host_decode_config_addr_cfge(const PCIHostState *s, + uint32_t config_reg, + PCIConfigAddress *decoded); + +void pci_host_decode_config_addr_valid(const PCIHostState *s, + uint32_t config_reg, + PCIConfigAddress *decoded); + void pci_data_write(PCIBus *s, uint32_t addr, uint32_t val, int len); uint32_t pci_data_read(PCIBus *s, uint32_t addr, int len); diff --git a/qemu-common.h b/qemu-common.h index 8630f8c..14e9205 100644 --- a/qemu-common.h +++ b/qemu-common.h @@ -207,6 +207,8 @@ typedef struct SMBusDevice SMBusDevice; typedef struct QEMUTimer QEMUTimer; typedef struct PCIHostState PCIHostState; typedef struct PCIExpressHost PCIExpressHost; +typedef struct PCIAddress PCIAddress; +typedef struct PCIConfigAddress PCIConfigAddress; typedef struct PCIBus PCIBus; typedef struct PCIDevice PCIDevice; typedef struct SerialState SerialState;