From: Gerd Hoffmann <kraxel@redhat.com>
To: qemu-devel@nongnu.org
Cc: Gerd Hoffmann <kraxel@redhat.com>
Subject: [Qemu-devel] [PATCH 1/6] qdev/prop: add pci devfn property
Date: Wed, 15 Jul 2009 13:59:22 +0200 [thread overview]
Message-ID: <1247659167-1177-2-git-send-email-kraxel@redhat.com> (raw)
In-Reply-To: <1247659167-1177-1-git-send-email-kraxel@redhat.com>
So we can parse "$slot.$fn" strings into devfn numbers.
Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
---
hw/qdev-properties.c | 43 +++++++++++++++++++++++++++++++++++++++++++
hw/qdev.h | 1 +
2 files changed, 44 insertions(+), 0 deletions(-)
diff --git a/hw/qdev-properties.c b/hw/qdev-properties.c
index 06c25af..cd3ee8b 100644
--- a/hw/qdev-properties.c
+++ b/hw/qdev-properties.c
@@ -145,6 +145,49 @@ PropertyInfo qdev_prop_macaddr = {
.print = print_mac,
};
+/* --- pci address --- */
+
+/*
+ * bus-local address, i.e. "$slot" or "$slot.$fn"
+ */
+static int parse_pci_devfn(DeviceState *dev, Property *prop, const char *str)
+{
+ uint32_t *ptr = qdev_get_prop_ptr(dev, prop);
+ unsigned int slot, fn, n;
+
+ if (sscanf(str, "%x.%x%n", &slot, &fn, &n) != 2) {
+ fn = 0;
+ if (sscanf(str, "%x%n", &slot, &n) != 1) {
+ return -1;
+ }
+ }
+ if (str[n] != '\0')
+ return -1;
+ if (fn > 7)
+ return -1;
+ *ptr = slot << 3 | fn;
+ return 0;
+}
+
+static int print_pci_devfn(DeviceState *dev, Property *prop, char *dest, size_t len)
+{
+ uint32_t *ptr = qdev_get_prop_ptr(dev, prop);
+
+ if (-1 == *ptr) {
+ return snprintf(dest, len, "<unset>");
+ } else {
+ return snprintf(dest, len, "%02x.%x", *ptr >> 3, *ptr & 7);
+ }
+}
+
+PropertyInfo qdev_prop_pci_devfn = {
+ .name = "pci-devfn",
+ .type = PROP_TYPE_UINT32,
+ .size = sizeof(uint32_t),
+ .parse = parse_pci_devfn,
+ .print = print_pci_devfn,
+};
+
/* --- public helpers --- */
static Property *qdev_prop_walk(Property *props, const char *name)
diff --git a/hw/qdev.h b/hw/qdev.h
index 11744fa..a9a229e 100644
--- a/hw/qdev.h
+++ b/hw/qdev.h
@@ -148,6 +148,7 @@ extern PropertyInfo qdev_prop_uint32;
extern PropertyInfo qdev_prop_hex32;
extern PropertyInfo qdev_prop_ptr;
extern PropertyInfo qdev_prop_macaddr;
+extern PropertyInfo qdev_prop_pci_devfn;
/* Set properties between creation and init. */
void *qdev_get_prop_ptr(DeviceState *dev, Property *prop);
--
1.6.2.5
next prev parent reply other threads:[~2009-07-15 11:59 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-07-15 11:59 [Qemu-devel] [PATCH 0/6] qdev: -device switch patches Gerd Hoffmann
2009-07-15 11:59 ` Gerd Hoffmann [this message]
2009-07-15 11:59 ` [Qemu-devel] [PATCH 2/6] qdev/pci: use qdev_prop_pci_devfn Gerd Hoffmann
2009-07-15 11:59 ` [Qemu-devel] [PATCH 3/6] qdev: create default bus names Gerd Hoffmann
2009-07-15 11:59 ` [Qemu-devel] [PATCH 4/6] qdev: bus walker + qdev_device_add() Gerd Hoffmann
2009-07-15 11:59 ` [Qemu-devel] [PATCH 5/6] qdev: add -device command line option Gerd Hoffmann
2009-07-15 11:59 ` [Qemu-devel] [PATCH 6/6] switch balloon initialization to -device Gerd Hoffmann
2009-07-22 15:02 ` [Qemu-devel] [PATCH 0/6] qdev: -device switch patches Markus Armbruster
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=1247659167-1177-2-git-send-email-kraxel@redhat.com \
--to=kraxel@redhat.com \
--cc=qemu-devel@nongnu.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).