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: skandasa@cisco.com, adnan@khaleel.us, wexu2@cisco.com,
	gleb@redhat.com, qemu-devel@nongnu.org, etmartin@cisco.com
Subject: [Qemu-devel] Re: [PATCH v8 07/11] pci: introduce a parser for pci device path
Date: Mon, 15 Nov 2010 10:06:13 +0200	[thread overview]
Message-ID: <20101115080613.GE22248@redhat.com> (raw)
In-Reply-To: <3404152716bc65ee54b1c906b2435089a6200092.1289805831.git.yamahata@valinux.co.jp>

On Mon, Nov 15, 2010 at 04:30:43PM +0900, Isaku Yamahata wrote:
> introduce a function to parse pci device path of
> the format, [Domain:]Slot.Function:Slot.Function....:Slot.Function.
> 
> Signed-off-by: Isaku Yamahata <yamahata@valinux.co.jp>

Hmm.
How about we use openfirmware path like what Gleb's patch does,
with a fallback to bus:dev.fn for when it's unambiguous?

> ---
>  hw/pci.c |   87 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
>  hw/pci.h |    1 +
>  2 files changed, 88 insertions(+), 0 deletions(-)
> 
> diff --git a/hw/pci.c b/hw/pci.c
> index fba765b..6a9a5ef 100644
> --- a/hw/pci.c
> +++ b/hw/pci.c
> @@ -433,6 +433,93 @@ static void pci_set_default_subsystem_id(PCIDevice *pci_dev)
>  }
>  
>  /*
> + * Parse format [Domain:]Slot.Function:Slot.Function....:Slot.Function
> + * and get PCIDevice
> + * return 0 on success
> + *       -1 on error: format is invalid or device isn't found.
> + */
> +int pci_parse_dev_path(const char *addr, PCIDevice **pdev)
> +{
> +    unsigned long domain;
> +    unsigned long slot;
> +    unsigned long func;
> +    const char *p;
> +    char *e;
> +    unsigned long val;
> +    PCIBus *bus;
> +    PCIBus *child_bus;
> +    PCIDevice *d;
> +
> +    p = addr;
> +    val = strtoul(p, &e, 0);
> +    if (e == p) {
> +        return -1;
> +    }
> +    if (*e == ':') {
> +        domain = val;
> +        p = e + 1;
> +        val = strtoul(p, &e, 0);
> +        if (e == p) {
> +            return -1;
> +        }
> +    } else if (*e == '.'){
> +        domain = 0;
> +    } else {
> +        return -1;
> +    }
> +    if (domain > 0xffff) {
> +        return -1;
> +    }
> +
> +    bus = pci_find_root_bus(domain);
> +    if (!bus) {
> +        return -1;
> +    }
> +
> +    for (;;) {
> +        slot = val;
> +        if (*e != '.') {
> +            return -1;
> +        }
> +        p = e + 1;
> +        val = strtoul(p, &e, 0);
> +        if (e == p) {
> +            return -1;
> +        }
> +        func = val;
> +        if (slot > 0x1f || func >= PCI_FUNC_MAX) {
> +            return -1;
> +        }
> +        d = bus->devices[PCI_DEVFN(slot, func)];
> +        if (!d) {
> +            return -1;
> +        }
> +        if (*e == '\0') {
> +            break;
> +        }
> +
> +        if (*e != ':') {
> +            return -1;
> +        }
> +        p = e + 1;
> +        val = strtoul(p, &e, 0);
> +        if (e == p) {
> +            return -1;
> +        }
> +        QLIST_FOREACH(child_bus, &bus->child, sibling) {
> +            if (child_bus->parent_dev == d) {
> +                bus = child_bus;
> +                continue;
> +            }
> +        }
> +        return -1;
> +    }
> +
> +    *pdev = d;
> +    return 0;
> +}
> +
> +/*
>   * Parse [[<domain>:]<bus>:]<slot>, return -1 on error if funcp == NULL
>   *       [[<domain>:]<bus>:]<slot>.<func>, return -1 on error
>   */
> diff --git a/hw/pci.h b/hw/pci.h
> index 7100804..8c16f91 100644
> --- a/hw/pci.h
> +++ b/hw/pci.h
> @@ -239,6 +239,7 @@ PCIBus *pci_find_bus(PCIBus *bus, int bus_num);
>  PCIDevice *pci_find_device(PCIBus *bus, int bus_num, int slot, int function);
>  PCIBus *pci_get_bus_devfn(int *devfnp, const char *devaddr);
>  
> +int pci_parse_dev_path(const char *addr, PCIDevice **pdev);
>  int pci_parse_devaddr(const char *addr, int *domp, int *busp,
>                        unsigned int *slotp, unsigned int *funcp);
>  int pci_read_devaddr(Monitor *mon, const char *addr, int *domp, int *busp,
> -- 
> 1.7.1.1

  reply	other threads:[~2010-11-15  8:07 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-11-15  7:30 [Qemu-devel] [PATCH v8 00/11] pcie port switch emulators Isaku Yamahata
2010-11-15  7:30 ` [Qemu-devel] [PATCH v8 01/11] pci: revise pci command register initialization Isaku Yamahata
2010-11-15  8:09   ` [Qemu-devel] " Michael S. Tsirkin
2010-11-15  7:30 ` [Qemu-devel] [PATCH v8 02/11] pci: clean up pci command register io/memory bit initialization Isaku Yamahata
2010-11-15  7:30 ` [Qemu-devel] [PATCH v8 03/11] pci: fix accesses to pci status register Isaku Yamahata
2010-11-15  7:30 ` [Qemu-devel] [PATCH v8 04/11] pci: clean up of " Isaku Yamahata
2010-11-15  7:30 ` [Qemu-devel] [PATCH v8 05/11] pcie_regs.h: more constants Isaku Yamahata
2010-11-15  7:30 ` [Qemu-devel] [PATCH v8 06/11] pcie/aer: helper functions for pcie aer capability Isaku Yamahata
2010-11-15  7:30 ` [Qemu-devel] [PATCH v8 07/11] pci: introduce a parser for pci device path Isaku Yamahata
2010-11-15  8:06   ` Michael S. Tsirkin [this message]
2010-11-15  8:57     ` [Qemu-devel] " Isaku Yamahata
2010-11-15  9:03       ` Gleb Natapov
2010-11-15  7:30 ` [Qemu-devel] [PATCH v8 08/11] pcie/aer: glue aer error injection into qemu monitor Isaku Yamahata
2010-11-15  7:30 ` [Qemu-devel] [PATCH v8 09/11] ioh3420: support aer Isaku Yamahata
2010-11-15  7:30 ` [Qemu-devel] [PATCH v8 10/11] x3130/upstream: " Isaku Yamahata
2010-11-15  7:30 ` [Qemu-devel] [PATCH v8 11/11] x3130/downstream: " Isaku Yamahata

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=20101115080613.GE22248@redhat.com \
    --to=mst@redhat.com \
    --cc=adnan@khaleel.us \
    --cc=etmartin@cisco.com \
    --cc=gleb@redhat.com \
    --cc=qemu-devel@nongnu.org \
    --cc=skandasa@cisco.com \
    --cc=wexu2@cisco.com \
    --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.