9ae3a8
From 74c36c49f488579f224013cddfc753c21ce4829e Mon Sep 17 00:00:00 2001
9ae3a8
From: Tarun Gupta <tgupta@redhat.com>
9ae3a8
Date: Wed, 20 Jun 2018 18:54:22 +0200
9ae3a8
Subject: [PATCH 14/17] qdev: New DEFINE_PROP_ON_OFF_AUTO
9ae3a8
MIME-Version: 1.0
9ae3a8
Content-Type: text/plain; charset=UTF-8
9ae3a8
Content-Transfer-Encoding: 8bit
9ae3a8
9ae3a8
RH-Author: Tarun Gupta <tgupta@redhat.com>
9ae3a8
Message-id: <1529520865-18127-9-git-send-email-tgupta@redhat.com>
9ae3a8
Patchwork-id: 80916
9ae3a8
O-Subject: [RHEL7.6 qemu-kvm PATCH v3 08/11] qdev: New DEFINE_PROP_ON_OFF_AUTO
9ae3a8
Bugzilla: 1555246
9ae3a8
RH-Acked-by: Alex Williamson <alex.williamson@redhat.com>
9ae3a8
RH-Acked-by: Gerd Hoffmann <kraxel@redhat.com>
9ae3a8
RH-Acked-by: Miroslav Rezanina <mrezanin@redhat.com>
9ae3a8
9ae3a8
Signed-off-by: Markus Armbruster <armbru@redhat.com>
9ae3a8
Reviewed-by: Marc-André Lureau <marcandre.lureau@redhat.com>
9ae3a8
9ae3a8
(cherry picked from 55e8a154359be12ca4c9730c562d1e3d4b1bd2a1)
9ae3a8
9ae3a8
Conflict: qemu-kvm does not have the json based framework to define
9ae3a8
properties, so using the exting enum based framework here.
9ae3a8
9ae3a8
Signed-off-by: Miroslav Rezanina <mrezanin@redhat.com>
9ae3a8
---
9ae3a8
 hw/core/qdev-properties.c    | 17 +++++++++++++++++
9ae3a8
 include/hw/qdev-properties.h |  3 +++
9ae3a8
 include/qemu-common.h        |  7 +++++++
9ae3a8
 3 files changed, 27 insertions(+)
9ae3a8
9ae3a8
diff --git a/hw/core/qdev-properties.c b/hw/core/qdev-properties.c
9ae3a8
index a61250e..71ba10e 100644
9ae3a8
--- a/hw/core/qdev-properties.c
9ae3a8
+++ b/hw/core/qdev-properties.c
9ae3a8
@@ -568,6 +568,23 @@ PropertyInfo qdev_prop_macaddr = {
9ae3a8
     .set   = set_mac,
9ae3a8
 };
9ae3a8
 
9ae3a8
+/* --- on/off/auto --- */
9ae3a8
+static const char *on_off_auto_table[ON_OFF_AUTO_MAX+1] = {
9ae3a8
+    [ON_OFF_AUTO_AUTO] = "auto",
9ae3a8
+    [ON_OFF_AUTO_ON] = "on",
9ae3a8
+    [ON_OFF_AUTO_OFF] = "off",
9ae3a8
+    [ON_OFF_AUTO_MAX] = NULL,
9ae3a8
+};
9ae3a8
+
9ae3a8
+PropertyInfo qdev_prop_on_off_auto = {
9ae3a8
+    .name = "OnOffAuto",
9ae3a8
+    .enum_table = on_off_auto_table,
9ae3a8
+    .get = get_enum,
9ae3a8
+    .set = set_enum,
9ae3a8
+};
9ae3a8
+
9ae3a8
+QEMU_BUILD_BUG_ON(sizeof(OnOffAuto) != sizeof(int));
9ae3a8
+
9ae3a8
 /* --- lost tick policy --- */
9ae3a8
 
9ae3a8
 static const char *lost_tick_policy_table[LOST_TICK_MAX+1] = {
9ae3a8
diff --git a/include/hw/qdev-properties.h b/include/hw/qdev-properties.h
9ae3a8
index 77c6f7c..90eaf8f 100644
9ae3a8
--- a/include/hw/qdev-properties.h
9ae3a8
+++ b/include/hw/qdev-properties.h
9ae3a8
@@ -20,6 +20,7 @@ extern PropertyInfo qdev_prop_string;
9ae3a8
 extern PropertyInfo qdev_prop_chr;
9ae3a8
 extern PropertyInfo qdev_prop_ptr;
9ae3a8
 extern PropertyInfo qdev_prop_macaddr;
9ae3a8
+extern PropertyInfo qdev_prop_on_off_auto;
9ae3a8
 extern PropertyInfo qdev_prop_losttickpolicy;
9ae3a8
 extern PropertyInfo qdev_prop_bios_chs_trans;
9ae3a8
 extern PropertyInfo qdev_prop_drive;
9ae3a8
@@ -153,6 +154,8 @@ extern PropertyInfo qdev_prop_arraylen;
9ae3a8
     DEFINE_PROP(_n, _s, _f, qdev_prop_drive, BlockDriverState *)
9ae3a8
 #define DEFINE_PROP_MACADDR(_n, _s, _f)         \
9ae3a8
     DEFINE_PROP(_n, _s, _f, qdev_prop_macaddr, MACAddr)
9ae3a8
+#define DEFINE_PROP_ON_OFF_AUTO(_n, _s, _f, _d) \
9ae3a8
+    DEFINE_PROP_DEFAULT(_n, _s, _f, _d, qdev_prop_on_off_auto, OnOffAuto)
9ae3a8
 #define DEFINE_PROP_LOSTTICKPOLICY(_n, _s, _f, _d) \
9ae3a8
     DEFINE_PROP_DEFAULT(_n, _s, _f, _d, qdev_prop_losttickpolicy, \
9ae3a8
                         LostTickPolicy)
9ae3a8
diff --git a/include/qemu-common.h b/include/qemu-common.h
9ae3a8
index 4569d52..d0c74e3 100644
9ae3a8
--- a/include/qemu-common.h
9ae3a8
+++ b/include/qemu-common.h
9ae3a8
@@ -258,6 +258,13 @@ typedef int (*DMA_transfer_handler) (void *opaque, int nchan, int pos, int size)
9ae3a8
 
9ae3a8
 typedef uint64_t pcibus_t;
9ae3a8
 
9ae3a8
+typedef enum OnOffAuto {
9ae3a8
+    ON_OFF_AUTO_AUTO,
9ae3a8
+    ON_OFF_AUTO_ON,
9ae3a8
+    ON_OFF_AUTO_OFF,
9ae3a8
+    ON_OFF_AUTO_MAX,
9ae3a8
+} OnOffAuto;
9ae3a8
+
9ae3a8
 typedef enum LostTickPolicy {
9ae3a8
     LOST_TICK_DISCARD,
9ae3a8
     LOST_TICK_DELAY,
9ae3a8
-- 
9ae3a8
1.8.3.1
9ae3a8