qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: "Michael S. Tsirkin" <mst@redhat.com>
To: Isaku Yamahata <yamahata@valinux.co.jp>
Cc: qemu-devel@nongnu.org, agraf@suse.de
Subject: [Qemu-devel] Re: [PATCH 5/6] pci: introduce PCIAddress, PCIConfigAddress and helper functions.
Date: Tue, 12 Jan 2010 12:06:53 +0200	[thread overview]
Message-ID: <20100112100653.GC29926@redhat.com> (raw)
In-Reply-To: <1263286378-10398-6-git-send-email-yamahata@valinux.co.jp>

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 <agraf@suse.de>
> Signed-off-by: Isaku Yamahata <yamahata@valinux.co.jp>
> ---
>  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

  parent reply	other threads:[~2010-01-12 10:10 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-01-12  8:52 [Qemu-devel] [PATCH 0/6] pci: pci_data_{write, read}() clean up Isaku Yamahata
2010-01-12  8:52 ` [Qemu-devel] [PATCH 1/6] sh_pci: use PCIHostState instead of PCIBus Isaku Yamahata
2010-01-12  8:52 ` [Qemu-devel] [PATCH 2/6] sh_pci: s/sh_pci_data_write/sh_pci_mem_write/g for consistency Isaku Yamahata
2010-01-12  8:52 ` [Qemu-devel] [PATCH 3/6] versatile_pci: user PCIHostState instead of PCIBus Isaku Yamahata
2010-01-13 13:02   ` Paul Brook
2010-01-13 13:04     ` Michael S. Tsirkin
2010-01-12  8:52 ` [Qemu-devel] [PATCH 4/6] pci_host: remove code duplication in pci_host_template.h Isaku Yamahata
2010-01-12  8:52 ` [Qemu-devel] [PATCH 5/6] pci: introduce PCIAddress, PCIConfigAddress and helper functions Isaku Yamahata
2010-01-12 10:04   ` [Qemu-devel] " Michael S. Tsirkin
2010-01-12 10:06   ` Michael S. Tsirkin [this message]
2010-01-12  8:52 ` [Qemu-devel] [PATCH 6/6] pci host: make pci_data_{write, read}() get PCIConfigAddress Isaku Yamahata
2010-01-12 10:12   ` [Qemu-devel] " Michael S. Tsirkin
2010-01-12 10:43     ` Isaku Yamahata
2010-01-12 17:54       ` Alexander Graf
2010-01-13 13:08     ` Paul Brook
2010-01-12 17:54   ` [Qemu-devel] " Alexander Graf
2010-01-12 18:33     ` Michael S. Tsirkin
2010-01-13 12:09       ` Alexander Graf
2010-01-12 10:18 ` [Qemu-devel] Re: [PATCH 0/6] pci: pci_data_{write, read}() clean up Michael S. Tsirkin
2010-01-12 10:31   ` Alexander Graf
2010-01-12 10:39   ` Alexander Graf

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20100112100653.GC29926@redhat.com \
    --to=mst@redhat.com \
    --cc=agraf@suse.de \
    --cc=qemu-devel@nongnu.org \
    --cc=yamahata@valinux.co.jp \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).