From: Damien Hedde <damien.hedde@greensocs.com>
To: qemu-devel@nongnu.org
Cc: Damien Hedde <damien.hedde@greensocs.com>,
ehabkost@redhat.com, mark.burton@greensocs.com,
armbru@redhat.com, sakisp@xilinx.com, edgari@xilinx.com,
crosa@redhat.com, pbonzini@redhat.com, luc.michel@greensocs.com,
rth@twiddle.net
Subject: [Qemu-devel] [RFC PATCH 2/5] introduce a qmp command to set gpios
Date: Fri, 28 Jun 2019 14:45:31 +0200 [thread overview]
Message-ID: <20190628124534.10679-3-damien.hedde@greensocs.com> (raw)
In-Reply-To: <20190628124534.10679-1-damien.hedde@greensocs.com>
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 <damien.hedde@greensocs.com>
---
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
next prev parent reply other threads:[~2019-06-28 13:15 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-06-28 12:45 [Qemu-devel] [RFC PATCH 0/5] FAULT INJECTION FRAMEWORK Damien Hedde
2019-06-28 12:45 ` [Qemu-devel] [RFC PATCH 1/5] introduce [p]mem(read|write) qmp commands Damien Hedde
2019-06-28 12:45 ` Damien Hedde [this message]
2019-06-28 12:45 ` [Qemu-devel] [RFC PATCH 3/5] add qmp time-notify event triggering system Damien Hedde
2019-06-28 12:45 ` [Qemu-devel] [RFC PATCH 4/5] fault_injection: introduce Python scripting framework Damien Hedde
2019-06-28 12:45 ` [Qemu-devel] [RFC PATCH 5/5] docs: add fault injection framework documentation Damien Hedde
2019-07-01 8:37 ` [Qemu-devel] [RFC PATCH 0/5] FAULT INJECTION FRAMEWORK Stefan Hajnoczi
2019-07-01 10:16 ` Philippe Mathieu-Daudé
2019-07-03 9:29 ` Stefan Hajnoczi
2019-07-03 15:47 ` Damien Hedde
2019-07-09 13:42 ` Stefan Hajnoczi
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20190628124534.10679-3-damien.hedde@greensocs.com \
--to=damien.hedde@greensocs.com \
--cc=armbru@redhat.com \
--cc=crosa@redhat.com \
--cc=edgari@xilinx.com \
--cc=ehabkost@redhat.com \
--cc=luc.michel@greensocs.com \
--cc=mark.burton@greensocs.com \
--cc=pbonzini@redhat.com \
--cc=qemu-devel@nongnu.org \
--cc=rth@twiddle.net \
--cc=sakisp@xilinx.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).