qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Qemu-devel] [RFC PATCH 2/5] introduce a qmp command to set gpios


From: Damien Hedde
Subject: [Qemu-devel] [RFC PATCH 2/5] introduce a qmp command to set gpios
Date: Fri, 28 Jun 2019 14:45:31 +0200

This adds the "gpio-set" qmp command.

Taking the device path, the gpio name and number, the command set the
value (true or false) of the gpio.
It works only on gpio input line.

This is based on Frederic Konrad's work.

Signed-off-by: Damien Hedde <address@hidden>
---
 cpus.c             |  4 ++--
 monitor/qmp-cmds.c | 30 ++++++++++++++++++++++++++++++
 qapi/misc.json     | 29 +++++++++++++++++++++++++++++
 3 files changed, 61 insertions(+), 2 deletions(-)

diff --git a/cpus.c b/cpus.c
index 7aae35c098..3688550c55 100644
--- a/cpus.c
+++ b/cpus.c
@@ -2580,8 +2580,8 @@ static void memwrite(int64_t addr, uint8List *bytes, 
CPUState *cpu,
         MemTxResult r = address_space_write(&address_space_memory, addr,
                                             MEMTXATTRS_UNSPECIFIED, buf, l);
         if (r != MEMTX_OK) {
-            error_setg(errp, "Invalid addr 0x%016" PRIx64 "/size %" PRId64
-                             " specified", addr, size);
+            error_setg(errp, "Invalid addr 0x%016" PRIx64 "/size %" PRIu32
+                             " specified", addr, l);
             return;
         }
     }
diff --git a/monitor/qmp-cmds.c b/monitor/qmp-cmds.c
index 01ce77e129..6bf0204edd 100644
--- a/monitor/qmp-cmds.c
+++ b/monitor/qmp-cmds.c
@@ -726,3 +726,33 @@ MemoryInfo *qmp_query_memory_size_summary(Error **errp)
 
     return mem_info;
 }
+
+void qmp_gpio_set(const char *path, bool has_gpio, const char *gpio,
+                  bool has_number, int64_t number, bool value, Error **errp)
+{
+    DeviceState *dev;
+    qemu_irq irq;
+
+    dev = DEVICE(object_resolve_path(path, NULL));
+    if (!dev) {
+        error_set(errp, ERROR_CLASS_DEVICE_NOT_FOUND,
+                  "Cannot find device '%s'", path);
+        return;
+    }
+
+    if (!has_gpio) {
+        gpio = NULL;
+    }
+    if (!has_number) {
+        number = 0;
+    }
+    irq = qdev_get_gpio_in_named(dev, gpio, number);
+    if (!irq) {
+        error_set(errp, ERROR_CLASS_GENERIC_ERROR,
+                  "GPIO input '%s[%"PRId64"]' does not exists",
+                  has_gpio ? gpio : "unnamed", number);
+        return;
+    }
+
+    qemu_set_irq(irq, value);
+}
diff --git a/qapi/misc.json b/qapi/misc.json
index 3aca91b4ac..255236b96f 100644
--- a/qapi/misc.json
+++ b/qapi/misc.json
@@ -3166,3 +3166,32 @@
 { 'command': 'pmemwrite',
   'data': {'addr': 'int', 'bytes': ['uint8']}
 }
+
+##
+# @gpio-set:
+#
+# @path: Path to the device.
+#
+# @gpio: Name of the GPIO will be unnamed-gpio if omitted.
+#
+# @number: Number of the GPIO line, 0 if omitted.
+#
+# @value: Value (boolean) to be set for the GPIO.
+#
+# Returns: nothing in case of success
+#
+# Since 4.1
+#
+# Example:
+#
+# -> { "execute": "gpio-set",
+#      "arguments": { "path": "/machine/unattached/device[5]",
+#                     "gpio": "ssi-gpio-cs",
+#                     "number": 0,
+#                     "value": true } }
+# <- { "return": {} }
+#
+##
+{ 'command': 'gpio-set',
+  'data': { 'path': 'str', '*gpio': 'str', '*number': 'int', 'value': 'bool' }
+}
-- 
2.22.0




reply via email to

[Prev in Thread] Current Thread [Next in Thread]