All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Michael S. Tsirkin" <mst@redhat.com>
To: Isaku Yamahata <yamahata@valinux.co.jp>
Cc: qemu-devel@nongnu.org
Subject: [Qemu-devel] Re: [PATCH 2/3] pci: use devfn for pci_find_device() instead of (slot, fn) pair
Date: Wed, 26 Jan 2011 15:38:48 +0200	[thread overview]
Message-ID: <20110126133848.GC12805@redhat.com> (raw)
In-Reply-To: <d38a20936b9cce8f0c7e8c100076b72e7a449191.1296034717.git.yamahata@valinux.co.jp>

On Wed, Jan 26, 2011 at 06:45:19PM +0900, Isaku Yamahata wrote:
> (slot, fn) pair is somewhat confusing because of ARI.
> So use devfn for pci_find_device() instead of (slot, fn).
> 
> Signed-off-by: Isaku Yamahata <yamahata@valinux.co.jp>

I'd prefer using uint8_t for devfn. This way we don't need
to bother to range-check it either.

> ---
>  hw/pci-hotplug.c |    5 +++--
>  hw/pci.c         |    5 +++--
>  hw/pci.h         |    2 +-
>  hw/pci_host.c    |    2 +-
>  hw/pcie_host.c   |    3 +--
>  5 files changed, 9 insertions(+), 8 deletions(-)
> 
> diff --git a/hw/pci-hotplug.c b/hw/pci-hotplug.c
> index 270a982..9715235 100644
> --- a/hw/pci-hotplug.c
> +++ b/hw/pci-hotplug.c
> @@ -126,7 +126,8 @@ void drive_hot_add(Monitor *mon, const QDict *qdict)
>          if (pci_read_devaddr(mon, pci_addr, &dom, &pci_bus, &slot)) {
>              goto err;
>          }
> -        dev = pci_find_device(pci_find_root_bus(dom), pci_bus, slot, 0);
> +        dev = pci_find_device(pci_find_root_bus(dom), pci_bus,
> +                              PCI_DEVFN(slot, 0));
>          if (!dev) {
>              monitor_printf(mon, "no pci device with address %s\n", pci_addr);
>              goto err;
> @@ -276,7 +277,7 @@ static int pci_device_hot_remove(Monitor *mon, const char *pci_addr)
>          return -1;
>      }
>  
> -    d = pci_find_device(pci_find_root_bus(dom), bus, slot, 0);
> +    d = pci_find_device(pci_find_root_bus(dom), bus, PCI_DEVFN(slot, 0));
>      if (!d) {
>          monitor_printf(mon, "slot %d empty\n", slot);
>          return -1;
> diff --git a/hw/pci.c b/hw/pci.c
> index 79a46e7..ac16029 100644
> --- a/hw/pci.c
> +++ b/hw/pci.c
> @@ -1599,14 +1599,15 @@ PCIBus *pci_find_bus(PCIBus *bus, int bus_num)
>      return NULL;
>  }
>  
> -PCIDevice *pci_find_device(PCIBus *bus, int bus_num, int slot, int function)
> +PCIDevice *pci_find_device(PCIBus *bus, int bus_num, int devfn)
>  {
> +    assert(devfn < PCI_DEVFN_MAX);
>      bus = pci_find_bus(bus, bus_num);
>  
>      if (!bus)
>          return NULL;
>  
> -    return bus->devices[PCI_DEVFN(slot, function)];
> +    return bus->devices[devfn];
>  }
>  
>  static int pci_qdev_init(DeviceState *qdev, DeviceInfo *base)
> diff --git a/hw/pci.h b/hw/pci.h
> index ffb04e8..f6d20f6 100644
> --- a/hw/pci.h
> +++ b/hw/pci.h
> @@ -253,7 +253,7 @@ void pci_for_each_device(PCIBus *bus, int bus_num, void (*fn)(PCIBus *bus, PCIDe
>  PCIBus *pci_find_root_bus(int domain);
>  int pci_find_domain(const PCIBus *bus);
>  PCIBus *pci_find_bus(PCIBus *bus, int bus_num);
> -PCIDevice *pci_find_device(PCIBus *bus, int bus_num, int slot, int function);
> +PCIDevice *pci_find_device(PCIBus *bus, int bus_num, int devfn);
>  int pci_qdev_find_device(const char *id, PCIDevice **pdev);
>  PCIBus *pci_get_bus_devfn(int *devfnp, const char *devaddr);
>  
> diff --git a/hw/pci_host.c b/hw/pci_host.c
> index 7c40155..728e2d4 100644
> --- a/hw/pci_host.c
> +++ b/hw/pci_host.c
> @@ -44,7 +44,7 @@ static inline PCIDevice *pci_dev_find_by_addr(PCIBus *bus, uint32_t addr)
>      uint8_t bus_num = addr >> 16;
>      uint8_t devfn = addr >> 8;
>  
> -    return pci_find_device(bus, bus_num, PCI_SLOT(devfn), PCI_FUNC(devfn));
> +    return pci_find_device(bus, bus_num, devfn);
>  }
>  
>  void pci_data_write(PCIBus *s, uint32_t addr, uint32_t val, int len)
> diff --git a/hw/pcie_host.c b/hw/pcie_host.c
> index 21069ee..b749865 100644
> --- a/hw/pcie_host.c
> +++ b/hw/pcie_host.c
> @@ -49,8 +49,7 @@ static inline PCIDevice *pcie_dev_find_by_mmcfg_addr(PCIBus *s,
>                                                       uint32_t mmcfg_addr)
>  {
>      return pci_find_device(s, PCIE_MMCFG_BUS(mmcfg_addr),
> -                           PCI_SLOT(PCIE_MMCFG_DEVFN(mmcfg_addr)),
> -                           PCI_FUNC(PCIE_MMCFG_DEVFN(mmcfg_addr)));
> +                           PCIE_MMCFG_DEVFN(mmcfg_addr));
>  }
>  
>  static void pcie_mmcfg_data_write(PCIBus *s,
> -- 
> 1.7.1.1

  reply	other threads:[~2011-01-26 13:39 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-01-26  9:45 [Qemu-devel] [PATCH 0/3] pci/pcie: implement ARI enable bit correctly Isaku Yamahata
2011-01-26  9:45 ` [Qemu-devel] [PATCH 1/3] pci: replace the magic, 256, for the maximum of devfn Isaku Yamahata
2011-01-26 13:37   ` [Qemu-devel] " Michael S. Tsirkin
2011-01-26  9:45 ` [Qemu-devel] [PATCH 2/3] pci: use devfn for pci_find_device() instead of (slot, fn) pair Isaku Yamahata
2011-01-26 13:38   ` Michael S. Tsirkin [this message]
2011-01-26  9:45 ` [Qemu-devel] [PATCH 3/3] pci/pcie: make pci_find_device() ARI aware Isaku Yamahata
2011-01-26 13:40   ` [Qemu-devel] " Michael S. Tsirkin

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=20110126133848.GC12805@redhat.com \
    --to=mst@redhat.com \
    --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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.