summaryrefslogtreecommitdiffstats
path: root/hw
diff options
context:
space:
mode:
authorGerd Hoffmann2009-10-21 15:25:24 +0200
committerAnthony Liguori2009-10-27 18:28:37 +0100
commit2ef924b416edb55f9d87b0f53d78c9fb78f0ec52 (patch)
treef4fcf8502cdc9acd2a591ecf4e70cddd0a762ddd /hw
parentqdev: mac addr property fixups (diff)
downloadqemu-2ef924b416edb55f9d87b0f53d78c9fb78f0ec52.tar.gz
qemu-2ef924b416edb55f9d87b0f53d78c9fb78f0ec52.tar.xz
qemu-2ef924b416edb55f9d87b0f53d78c9fb78f0ec52.zip
qdev: add netdev property
Signed-off-by: Gerd Hoffmann <kraxel@redhat.com> Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
Diffstat (limited to 'hw')
-rw-r--r--hw/qdev-properties.c36
-rw-r--r--hw/qdev.h4
2 files changed, 40 insertions, 0 deletions
diff --git a/hw/qdev-properties.c b/hw/qdev-properties.c
index 28d7b87873..992631895c 100644
--- a/hw/qdev-properties.c
+++ b/hw/qdev-properties.c
@@ -279,6 +279,37 @@ PropertyInfo qdev_prop_chr = {
.print = print_chr,
};
+/* --- netdev device --- */
+
+static int parse_netdev(DeviceState *dev, Property *prop, const char *str)
+{
+ VLANClientState **ptr = qdev_get_prop_ptr(dev, prop);
+
+ *ptr = qemu_find_netdev(str);
+ if (*ptr == NULL)
+ return -1;
+ return 0;
+}
+
+static int print_netdev(DeviceState *dev, Property *prop, char *dest, size_t len)
+{
+ VLANClientState **ptr = qdev_get_prop_ptr(dev, prop);
+
+ if (*ptr && (*ptr)->name) {
+ return snprintf(dest, len, "%s", (*ptr)->name);
+ } else {
+ return snprintf(dest, len, "<null>");
+ }
+}
+
+PropertyInfo qdev_prop_netdev = {
+ .name = "netdev",
+ .type = PROP_TYPE_NETDEV,
+ .size = sizeof(VLANClientState*),
+ .parse = parse_netdev,
+ .print = print_netdev,
+};
+
/* --- pointer --- */
static int print_ptr(DeviceState *dev, Property *prop, char *dest, size_t len)
@@ -488,6 +519,11 @@ void qdev_prop_set_chr(DeviceState *dev, const char *name, CharDriverState *valu
qdev_prop_set(dev, name, &value, PROP_TYPE_CHR);
}
+void qdev_prop_set_netdev(DeviceState *dev, const char *name, VLANClientState *value)
+{
+ qdev_prop_set(dev, name, &value, PROP_TYPE_NETDEV);
+}
+
void qdev_prop_set_macaddr(DeviceState *dev, const char *name, uint8_t *value)
{
qdev_prop_set(dev, name, value, PROP_TYPE_MACADDR);
diff --git a/hw/qdev.h b/hw/qdev.h
index 4d2decd854..ecb9b0911d 100644
--- a/hw/qdev.h
+++ b/hw/qdev.h
@@ -80,6 +80,7 @@ enum PropertyType {
PROP_TYPE_DRIVE,
PROP_TYPE_CHR,
PROP_TYPE_STRING,
+ PROP_TYPE_NETDEV,
PROP_TYPE_PTR,
};
@@ -231,6 +232,8 @@ extern PropertyInfo qdev_prop_pci_devfn;
DEFINE_PROP(_n, _s, _f, qdev_prop_chr, CharDriverState*)
#define DEFINE_PROP_STRING(_n, _s, _f) \
DEFINE_PROP(_n, _s, _f, qdev_prop_string, char*)
+#define DEFINE_PROP_NETDEV(_n, _s, _f) \
+ DEFINE_PROP(_n, _s, _f, qdev_prop_netdev, VLANClientState*)
#define DEFINE_PROP_DRIVE(_n, _s, _f) \
DEFINE_PROP(_n, _s, _f, qdev_prop_drive, DriveInfo*)
#define DEFINE_PROP_MACADDR(_n, _s, _f) \
@@ -249,6 +252,7 @@ void qdev_prop_set_uint32(DeviceState *dev, const char *name, uint32_t value);
void qdev_prop_set_int32(DeviceState *dev, const char *name, int32_t value);
void qdev_prop_set_uint64(DeviceState *dev, const char *name, uint64_t value);
void qdev_prop_set_chr(DeviceState *dev, const char *name, CharDriverState *value);
+void qdev_prop_set_netdev(DeviceState *dev, const char *name, VLANClientState *value);
void qdev_prop_set_drive(DeviceState *dev, const char *name, DriveInfo *value);
void qdev_prop_set_macaddr(DeviceState *dev, const char *name, uint8_t *value);
/* FIXME: Remove opaque pointer properties. */