[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PATCH 03/22] qdev: add netdev property
From: |
Gerd Hoffmann |
Subject: |
[Qemu-devel] [PATCH 03/22] qdev: add netdev property |
Date: |
Wed, 21 Oct 2009 15:25:24 +0200 |
Signed-off-by: Gerd Hoffmann <address@hidden>
---
hw/qdev-properties.c | 36 ++++++++++++++++++++++++++++++++++++
hw/qdev.h | 4 ++++
net.c | 2 +-
net.h | 1 +
4 files changed, 42 insertions(+), 1 deletions(-)
diff --git a/hw/qdev-properties.c b/hw/qdev-properties.c
index 1d68125..76925c8 100644
--- a/hw/qdev-properties.c
+++ b/hw/qdev-properties.c
@@ -251,6 +251,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)
@@ -460,6 +491,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 118e886..c0d59bc 100644
--- a/hw/qdev.h
+++ b/hw/qdev.h
@@ -79,6 +79,7 @@ enum PropertyType {
PROP_TYPE_MACADDR,
PROP_TYPE_DRIVE,
PROP_TYPE_CHR,
+ PROP_TYPE_NETDEV,
PROP_TYPE_PTR,
};
@@ -227,6 +228,8 @@ extern PropertyInfo qdev_prop_pci_devfn;
DEFINE_PROP(_n, _s, _f, qdev_prop_ptr, void*)
#define DEFINE_PROP_CHR(_n, _s, _f) \
DEFINE_PROP(_n, _s, _f, qdev_prop_chr, CharDriverState*)
+#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) \
@@ -245,6 +248,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. */
diff --git a/net.c b/net.c
index 3b69d3b..75a01d2 100644
--- a/net.c
+++ b/net.c
@@ -2363,7 +2363,7 @@ VLANState *qemu_find_vlan(int id, int allocate)
return vlan;
}
-static VLANClientState *qemu_find_netdev(const char *id)
+VLANClientState *qemu_find_netdev(const char *id)
{
VLANClientState *vc;
diff --git a/net.h b/net.h
index 605092a..6a24f55 100644
--- a/net.h
+++ b/net.h
@@ -47,6 +47,7 @@ struct VLANState {
};
VLANState *qemu_find_vlan(int id, int allocate);
+VLANClientState *qemu_find_netdev(const char *id);
VLANClientState *qemu_new_vlan_client(VLANState *vlan,
VLANClientState *peer,
const char *model,
--
1.6.2.5
- [Qemu-devel] [PATCH 01/22] qdev-ify network cards, Gerd Hoffmann, 2009/10/21
- [Qemu-devel] [PATCH 04/22] qdev: add vlan property, Gerd Hoffmann, 2009/10/21
- [Qemu-devel] [PATCH 03/22] qdev: add netdev property,
Gerd Hoffmann <=
- [Qemu-devel] [PATCH 01/22] net: add macaddr type., Gerd Hoffmann, 2009/10/21
- [Qemu-devel] [PATCH 02/22] qdev: mac addr property fixups, Gerd Hoffmann, 2009/10/21
- [Qemu-devel] [PATCH 07/22] qdev: add qdev_prop_exists(), Gerd Hoffmann, 2009/10/21
- [Qemu-devel] [PATCH 08/22] prepare pci nic init path for qdev property configuration., Gerd Hoffmann, 2009/10/21
- [Qemu-devel] [PATCH 05/22] qdev/net: common nic property bits, Gerd Hoffmann, 2009/10/21
- [Qemu-devel] [PATCH 09/22] ne2k_pci: use qdev properties for configuration., Gerd Hoffmann, 2009/10/21
- [Qemu-devel] [PATCH 06/22] ne2k_isa: use qdev properties for configuration., Gerd Hoffmann, 2009/10/21
- [Qemu-devel] [PATCH 11/22] pcnet: use qdev properties for configuration., Gerd Hoffmann, 2009/10/21
- [Qemu-devel] [PATCH 10/22] e1000: use qdev properties for configuration., Gerd Hoffmann, 2009/10/21
- [Qemu-devel] [PATCH 13/22] rtl8139: use qdev properties for configuration., Gerd Hoffmann, 2009/10/21