From: "Michael S. Tsirkin" <mst@redhat.com>
To: Anthony PERARD <anthony.perard@citrix.com>
Cc: Jan Kiszka <jan.kiszka@siemens.com>,
Anthony Liguori <aliguori@us.ibm.com>,
Stefano Stabellini <stefano.stabellini@eu.citrix.com>,
QEMU-devel <qemu-devel@nongnu.org>,
Xen Devel <xen-devel@lists.xen.org>
Subject: Re: [Qemu-devel] [PATCH V13 5/9] qdev-properties: Introduce pci-host-devaddr.
Date: Thu, 14 Jun 2012 22:39:35 +0300 [thread overview]
Message-ID: <20120614193935.GE19807@redhat.com> (raw)
In-Reply-To: <1339693309-15192-6-git-send-email-anthony.perard@citrix.com>
On Thu, Jun 14, 2012 at 06:01:45PM +0100, Anthony PERARD wrote:
> This new property will be used to specify a host pci device address.
>
> Signed-off-by: Anthony PERARD <anthony.perard@citrix.com>
Acked-by: Michael S. Tsirkin <mst@redhat.com>
> ---
> hw/qdev-properties.c | 107 ++++++++++++++++++++++++++++++++++++++++++++++++++
> hw/qdev.h | 3 +
> qemu-common.h | 7 +++
> 3 files changed, 117 insertions(+), 0 deletions(-)
>
> diff --git a/hw/qdev-properties.c b/hw/qdev-properties.c
> index 9ae3187..43e1964 100644
> --- a/hw/qdev-properties.c
> +++ b/hw/qdev-properties.c
> @@ -899,6 +899,113 @@ PropertyInfo qdev_prop_blocksize = {
> .set = set_blocksize,
> };
>
> +/* --- pci host address --- */
> +
> +static void get_pci_host_devaddr(Object *obj, Visitor *v, void *opaque,
> + const char *name, Error **errp)
> +{
> + DeviceState *dev = DEVICE(obj);
> + Property *prop = opaque;
> + PCIHostDeviceAddress *addr = qdev_get_prop_ptr(dev, prop);
> + char buffer[] = "xxxx:xx:xx.x";
> + char *p = buffer;
> + int rc = 0;
> +
> + rc = snprintf(buffer, sizeof(buffer), "%04x:%02x:%02x.%d",
> + addr->domain, addr->bus, addr->slot, addr->function);
> + assert(rc == sizeof(buffer) - 1);
> +
> + visit_type_str(v, &p, name, errp);
> +}
> +
> +/*
> + * Parse [<domain>:]<bus>:<slot>.<func>
> + * if <domain> is not supplied, it's assumed to be 0.
> + */
> +static void set_pci_host_devaddr(Object *obj, Visitor *v, void *opaque,
> + const char *name, Error **errp)
> +{
> + DeviceState *dev = DEVICE(obj);
> + Property *prop = opaque;
> + PCIHostDeviceAddress *addr = qdev_get_prop_ptr(dev, prop);
> + Error *local_err = NULL;
> + char *str, *p;
> + char *e;
> + unsigned long val;
> + unsigned long dom = 0, bus = 0;
> + unsigned int slot = 0, func = 0;
> +
> + if (dev->state != DEV_STATE_CREATED) {
> + error_set(errp, QERR_PERMISSION_DENIED);
> + return;
> + }
> +
> + visit_type_str(v, &str, name, &local_err);
> + if (local_err) {
> + error_propagate(errp, local_err);
> + return;
> + }
> +
> + p = str;
> + val = strtoul(p, &e, 16);
> + if (e == p || *e != ':') {
> + goto inval;
> + }
> + bus = val;
> +
> + p = e + 1;
> + val = strtoul(p, &e, 16);
> + if (e == p) {
> + goto inval;
> + }
> + if (*e == ':') {
> + dom = bus;
> + bus = val;
> + p = e + 1;
> + val = strtoul(p, &e, 16);
> + if (e == p) {
> + goto inval;
> + }
> + }
> + slot = val;
> +
> + if (*e != '.') {
> + goto inval;
> + }
> + p = e + 1;
> + val = strtoul(p, &e, 10);
> + if (e == p) {
> + goto inval;
> + }
> + func = val;
> +
> + if (dom > 0xffff || bus > 0xff || slot > 0x1f || func > 7) {
> + goto inval;
> + }
> +
> + if (*e) {
> + goto inval;
> + }
> +
> + addr->domain = dom;
> + addr->bus = bus;
> + addr->slot = slot;
> + addr->function = func;
> +
> + g_free(str);
> + return;
> +
> +inval:
> + error_set_from_qdev_prop_error(errp, EINVAL, dev, prop, str);
> + g_free(str);
> +}
> +
> +PropertyInfo qdev_prop_pci_host_devaddr = {
> + .name = "pci-host-devaddr",
> + .get = get_pci_host_devaddr,
> + .set = set_pci_host_devaddr,
> +};
> +
> /* --- public helpers --- */
>
> static Property *qdev_prop_walk(Property *props, const char *name)
> diff --git a/hw/qdev.h b/hw/qdev.h
> index 5386b16..8746f84 100644
> --- a/hw/qdev.h
> +++ b/hw/qdev.h
> @@ -223,6 +223,7 @@ extern PropertyInfo qdev_prop_netdev;
> extern PropertyInfo qdev_prop_vlan;
> extern PropertyInfo qdev_prop_pci_devfn;
> extern PropertyInfo qdev_prop_blocksize;
> +extern PropertyInfo qdev_prop_pci_host_devaddr;
>
> #define DEFINE_PROP(_name, _state, _field, _prop, _type) { \
> .name = (_name), \
> @@ -286,6 +287,8 @@ extern PropertyInfo qdev_prop_blocksize;
> LostTickPolicy)
> #define DEFINE_PROP_BLOCKSIZE(_n, _s, _f, _d) \
> DEFINE_PROP_DEFAULT(_n, _s, _f, _d, qdev_prop_blocksize, uint16_t)
> +#define DEFINE_PROP_PCI_HOST_DEVADDR(_n, _s, _f) \
> + DEFINE_PROP(_n, _s, _f, qdev_prop_pci_host_devaddr, PCIHostDeviceAddress)
>
> #define DEFINE_PROP_END_OF_LIST() \
> {}
> diff --git a/qemu-common.h b/qemu-common.h
> index 91e0562..0d6e51c 100644
> --- a/qemu-common.h
> +++ b/qemu-common.h
> @@ -274,6 +274,13 @@ typedef enum LostTickPolicy {
> LOST_TICK_MAX
> } LostTickPolicy;
>
> +typedef struct PCIHostDeviceAddress {
> + unsigned int domain;
> + unsigned int bus;
> + unsigned int slot;
> + unsigned int function;
> +} PCIHostDeviceAddress;
> +
> void tcg_exec_init(unsigned long tb_size);
> bool tcg_enabled(void);
>
> --
> Anthony PERARD
next prev parent reply other threads:[~2012-06-14 19:39 UTC|newest]
Thread overview: 19+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-06-14 17:01 [Qemu-devel] [PATCH V13 0/9] Xen PCI Passthrough Anthony PERARD
2012-06-14 17:01 ` [Qemu-devel] [PATCH V13 1/9] pci_ids: Add INTEL_82599_SFP_VF id Anthony PERARD
2012-06-14 19:37 ` Michael S. Tsirkin
2012-06-14 19:52 ` [Qemu-devel] [Xen-devel] " Konrad Rzeszutek Wilk
2012-06-14 17:01 ` [Qemu-devel] [PATCH V13 2/9] configure: Introduce --enable-xen-pci-passthrough Anthony PERARD
2012-06-14 17:01 ` [Qemu-devel] [PATCH V13 3/9] Introduce XenHostPCIDevice to access a pci device on the host Anthony PERARD
2012-06-14 19:53 ` [Qemu-devel] [Xen-devel] " Konrad Rzeszutek Wilk
2012-06-14 17:01 ` [Qemu-devel] [PATCH V13 4/9] pci.c: Add opaque argument to pci_for_each_device Anthony PERARD
2012-06-14 19:38 ` Michael S. Tsirkin
2012-06-14 19:54 ` [Qemu-devel] [Xen-devel] " Konrad Rzeszutek Wilk
2012-06-14 17:01 ` [Qemu-devel] [PATCH V13 5/9] qdev-properties: Introduce pci-host-devaddr Anthony PERARD
2012-06-14 19:39 ` Michael S. Tsirkin [this message]
2012-06-14 17:01 ` [Qemu-devel] [PATCH V13 6/9] Introduce Xen PCI Passthrough, qdevice (1/3) Anthony PERARD
2012-06-14 17:01 ` [Qemu-devel] [PATCH V13 7/9] Introduce Xen PCI Passthrough, PCI config space helpers (2/3) Anthony PERARD
2012-06-14 17:01 ` [Qemu-devel] [PATCH V13 8/9] Introduce apic-msidef.h Anthony PERARD
2012-06-14 19:40 ` Michael S. Tsirkin
2012-06-14 17:01 ` [Qemu-devel] [PATCH V13 9/9] Introduce Xen PCI Passthrough, MSI (3/3) Anthony PERARD
2012-06-14 19:41 ` [Qemu-devel] [PATCH V13 0/9] Xen PCI Passthrough Michael S. Tsirkin
2012-06-15 11:05 ` Stefano Stabellini
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=20120614193935.GE19807@redhat.com \
--to=mst@redhat.com \
--cc=aliguori@us.ibm.com \
--cc=anthony.perard@citrix.com \
--cc=jan.kiszka@siemens.com \
--cc=qemu-devel@nongnu.org \
--cc=stefano.stabellini@eu.citrix.com \
--cc=xen-devel@lists.xen.org \
/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).