From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1NUdhK-0004JE-Op for qemu-devel@nongnu.org; Tue, 12 Jan 2010 05:10:02 -0500 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1NUdhF-0004GM-Pa for qemu-devel@nongnu.org; Tue, 12 Jan 2010 05:10:02 -0500 Received: from [199.232.76.173] (port=51591 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1NUdhF-0004GD-Hl for qemu-devel@nongnu.org; Tue, 12 Jan 2010 05:09:57 -0500 Received: from mx20.gnu.org ([199.232.41.8]:60798) by monty-python.gnu.org with esmtps (TLS-1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.60) (envelope-from ) id 1NUdhF-0000wK-6A for qemu-devel@nongnu.org; Tue, 12 Jan 2010 05:09:57 -0500 Received: from mx1.redhat.com ([209.132.183.28]) by mx20.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1NUdhD-0002g2-ME for qemu-devel@nongnu.org; Tue, 12 Jan 2010 05:09:56 -0500 Date: Tue, 12 Jan 2010 12:06:53 +0200 From: "Michael S. Tsirkin" Message-ID: <20100112100653.GC29926@redhat.com> References: <1263286378-10398-1-git-send-email-yamahata@valinux.co.jp> <1263286378-10398-6-git-send-email-yamahata@valinux.co.jp> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1263286378-10398-6-git-send-email-yamahata@valinux.co.jp> Subject: [Qemu-devel] Re: [PATCH 5/6] pci: introduce PCIAddress, PCIConfigAddress and helper functions. List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Isaku Yamahata Cc: qemu-devel@nongnu.org, agraf@suse.de On Tue, Jan 12, 2010 at 05:52:57PM +0900, Isaku Yamahata wrote: > 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; Hang on, this is wrong. Domain is the root complex, if you need the bus pointer just pass it to pci_data_read directly. > + 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; > -- > 1.6.5.4