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