summaryrefslogtreecommitdiff
path: root/hw/qdev-properties.c
diff options
context:
space:
mode:
authorGerd Hoffmann <kraxel@redhat.com>2009-07-15 13:59:22 +0200
committerAnthony Liguori <aliguori@us.ibm.com>2009-07-27 08:39:29 -0500
commit05cb5fe442dd9574895427f8ea02aec73550b6db (patch)
treea87e65427c77f24a720bcf8ab806a48f14361e2d /hw/qdev-properties.c
parent95747581341443e337cb0b485d96432bb414be8f (diff)
downloadqemu-05cb5fe442dd9574895427f8ea02aec73550b6db.tar.gz
qemu-05cb5fe442dd9574895427f8ea02aec73550b6db.tar.bz2
qemu-05cb5fe442dd9574895427f8ea02aec73550b6db.zip
qdev/prop: add pci devfn property
So we can parse "$slot.$fn" strings into devfn numbers. Signed-off-by: Gerd Hoffmann <kraxel@redhat.com> Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
Diffstat (limited to 'hw/qdev-properties.c')
-rw-r--r--hw/qdev-properties.c43
1 files changed, 43 insertions, 0 deletions
diff --git a/hw/qdev-properties.c b/hw/qdev-properties.c
index 4f35f06628..0e4878ee8f 100644
--- a/hw/qdev-properties.c
+++ b/hw/qdev-properties.c
@@ -198,6 +198,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)