From: "Philippe Mathieu-Daudé" <f4bug@amsat.org>
To: "Alistair Francis" <alistair.francis@xilinx.com>,
"Edgar E . Iglesias" <edgar.iglesias@xilinx.com>,
"Peter Maydell" <peter.maydell@linaro.org>,
"Markus Armbruster" <armbru@redhat.com>,
"Michael Roth" <mdroth@linux.vnet.ibm.com>,
"Andrey Smirnov" <andrew.smirnov@gmail.com>,
"Andrey Yurovsky" <yurovsky@gmail.com>,
"Eduardo Habkost" <ehabkost@redhat.com>,
"Daniel P . Berrange" <berrange@redhat.com>,
"Eric Blake" <eblake@redhat.com>, "Fam Zheng" <famz@redhat.com>,
"Thomas Huth" <thuth@redhat.com>,
"Marc-André Lureau" <marcandre.lureau@redhat.com>,
"Paolo Bonzini" <pbonzini@redhat.com>
Cc: "Philippe Mathieu-Daudé" <f4bug@amsat.org>, qemu-devel@nongnu.org
Subject: [Qemu-devel] [PATCH 01/26] sdbus: add a QMP command to access a SDBus
Date: Wed, 13 Dec 2017 20:20:00 -0300 [thread overview]
Message-ID: <20171213232025.24503-2-f4bug@amsat.org> (raw)
In-Reply-To: <20171213232025.24503-1-f4bug@amsat.org>
Use Base64 to serialize the binary blobs in JSON.
So far at most 512 bytes will be transfered, which result
in a 684 bytes payload.
Since this command is intented for qtesting, this is acceptable.
Signed-off-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
---
qapi-schema.json | 41 +++++++++++++++++++++++++++++++++++++++++
hw/sd/core.c | 43 +++++++++++++++++++++++++++++++++++++++++++
stubs/qmp_sdbus.c | 11 +++++++++++
stubs/Makefile.objs | 1 +
4 files changed, 96 insertions(+)
create mode 100644 stubs/qmp_sdbus.c
diff --git a/qapi-schema.json b/qapi-schema.json
index 18457954a8..9b0fd90fed 100644
--- a/qapi-schema.json
+++ b/qapi-schema.json
@@ -3200,3 +3200,44 @@
# Since: 2.11
##
{ 'command': 'watchdog-set-action', 'data' : {'action': 'WatchdogAction'} }
+
+##
+# @SDBusCommandResponse:
+#
+# SD Bus command response.
+#
+# @base64: the command response encoded as a Base64 string, if any (optional)
+#
+# Since: 2.11
+##
+{ 'struct': 'SDBusCommandResponse', 'data': {'*base64': 'str'} }
+
+##
+# @sdbus-command:
+#
+# Execute a command on a SD Bus return the response (if any).
+#
+# @qom-path: the SD Bus path
+# @command: the SD protocol command to execute in the bus
+# @arg: a 64-bit command argument (optional)
+# @crc: the command/argument CRC (optional)
+#
+# Returns: the response of the command encoded as a Base64 string
+#
+# Since: 2.11
+#
+# -> { "execute": "sdbus-command",
+# "arguments": { "qom-path": "/machine/unattached/device[32]/sd.0",
+# "command": 0x01
+# }
+# }
+# <- { "return": {'base64': 'A='} }
+#
+##
+{ 'command': 'sdbus-command',
+ 'data': { 'qom-path': 'str',
+ 'command': 'uint8',
+ '*arg': 'uint64',
+ '*crc': 'uint16' },
+ 'returns': 'SDBusCommandResponse'
+}
diff --git a/hw/sd/core.c b/hw/sd/core.c
index da3a7e0efa..c546db2b22 100644
--- a/hw/sd/core.c
+++ b/hw/sd/core.c
@@ -22,6 +22,7 @@
#include "qemu/osdep.h"
#include "hw/sd/sd.h"
#include "qemu/cutils.h"
+#include "qmp-commands.h"
#include "sd-internal.h"
#include "trace.h"
@@ -220,3 +221,45 @@ SDBus *sdbus_create_bus(DeviceState *parent, const char *name)
{
return SD_BUS(qbus_create(TYPE_SD_BUS, parent, name));
}
+
+SDBusCommandResponse *qmp_sdbus_command(const char *qom_path,
+ uint8_t command,
+ bool has_arg, uint64_t arg,
+ bool has_crc, uint16_t crc,
+ Error **errp)
+{
+ uint8_t response[16 + 1];
+ SDBusCommandResponse *res;
+ bool ambiguous = false;
+ Object *obj;
+ SDBus *sdbus;
+ int sz;
+
+ obj = object_resolve_path(qom_path, &ambiguous);
+ if (obj == NULL) {
+ if (ambiguous) {
+ error_setg(errp, "Path '%s' is ambiguous", qom_path);
+ } else {
+ error_set(errp, ERROR_CLASS_DEVICE_NOT_FOUND,
+ "Device '%s' not found", qom_path);
+ }
+ return NULL;
+ }
+ sdbus = (SDBus *)object_dynamic_cast(obj, TYPE_SD_BUS);
+ if (sdbus == NULL) {
+ error_set(errp, ERROR_CLASS_GENERIC_ERROR,
+ "Device '%s' not a sd-bus", qom_path);
+ return NULL;
+ }
+
+ res = g_new0(SDBusCommandResponse, 1);
+ sz = sdbus_do_command(sdbus,
+ &(SDRequest){ command, arg, has_crc ? crc : -1 },
+ response);
+ if (sz > 0) {
+ res->has_base64 = true;
+ res->base64 = g_base64_encode(response, sz);
+ }
+
+ return res;
+}
diff --git a/stubs/qmp_sdbus.c b/stubs/qmp_sdbus.c
new file mode 100644
index 0000000000..50f9f1410d
--- /dev/null
+++ b/stubs/qmp_sdbus.c
@@ -0,0 +1,11 @@
+#include "qemu/osdep.h"
+#include "qmp-commands.h"
+#include "hw/sd/sd.h"
+
+SDBusCommandResponse *qmp_sdbus_command(const char *qom_path, uint8_t command,
+ bool has_arg, uint64_t arg,
+ bool has_crc, uint16_t crc,
+ Error **errp)
+{
+ return NULL;
+}
diff --git a/stubs/Makefile.objs b/stubs/Makefile.objs
index 8cfe34328a..a46cb3b992 100644
--- a/stubs/Makefile.objs
+++ b/stubs/Makefile.objs
@@ -35,6 +35,7 @@ stub-obj-y += vm-stop.o
stub-obj-y += vmstate.o
stub-obj-$(CONFIG_WIN32) += fd-register.o
stub-obj-y += qmp_pc_dimm.o
+stub-obj-y += qmp_sdbus.o
stub-obj-y += target-monitor-defs.o
stub-obj-y += target-get-monitor-def.o
stub-obj-y += pc_madt_cpu_entry.o
--
2.15.1
next prev parent reply other threads:[~2017-12-13 23:21 UTC|newest]
Thread overview: 37+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-12-13 23:19 [Qemu-devel] [PATCH 00/26] SDCard housekeeping Philippe Mathieu-Daudé
2017-12-13 23:20 ` Philippe Mathieu-Daudé [this message]
2017-12-14 9:06 ` [Qemu-devel] [PATCH 01/26] sdbus: add a QMP command to access a SDBus Kevin Wolf
2017-12-14 9:34 ` Paolo Bonzini
2017-12-14 13:25 ` Philippe Mathieu-Daudé
2017-12-15 8:13 ` Paolo Bonzini
2017-12-14 13:18 ` Philippe Mathieu-Daudé
2017-12-15 19:53 ` Eric Blake
2017-12-13 23:20 ` [Qemu-devel] [RFC PATCH 02/26] sdcard: add a Python qtest Philippe Mathieu-Daudé
2017-12-14 9:34 ` Paolo Bonzini
2017-12-13 23:20 ` [Qemu-devel] [PATCH 03/26] sdcard: use ldst API Philippe Mathieu-Daudé
2017-12-13 23:20 ` [Qemu-devel] [PATCH 04/26] sdcard: replace fprintf() -> qemu_log_mask() Philippe Mathieu-Daudé
2017-12-13 23:20 ` [Qemu-devel] [PATCH 05/26] sdcard: rename sd_set_mode() -> sd_update_mode() Philippe Mathieu-Daudé
2017-12-13 23:20 ` [Qemu-devel] [PATCH 06/26] sdcard: add sd_set_mode() Philippe Mathieu-Daudé
2017-12-13 23:20 ` [Qemu-devel] [PATCH 07/26] sdcard: add sdcard_set_mode() trace event Philippe Mathieu-Daudé
2017-12-13 23:20 ` [Qemu-devel] [PATCH 08/26] sdcard: add sd_set_state() Philippe Mathieu-Daudé
2017-12-13 23:20 ` [Qemu-devel] [PATCH 09/26] sdcard: add a sdcard_set_state() trace event Philippe Mathieu-Daudé
2017-12-13 23:20 ` [Qemu-devel] [PATCH 10/26] sdcard: use more detailled state/mode trace events Philippe Mathieu-Daudé
2017-12-13 23:20 ` [Qemu-devel] [PATCH 11/26] sdcard: use warn_report() instead of fprintf() Philippe Mathieu-Daudé
2017-12-13 23:20 ` [Qemu-devel] [PATCH 12/26] sdcard: replace DPRINTF() by trace events Philippe Mathieu-Daudé
2017-12-13 23:20 ` [Qemu-devel] [PATCH 13/26] sdcard: add more " Philippe Mathieu-Daudé
2017-12-13 23:20 ` [Qemu-devel] [RFC PATCH 14/26] sdcard: use qemu_hexbuf_strdup() to trace command response Philippe Mathieu-Daudé
2017-12-13 23:20 ` [Qemu-devel] [PATCH 15/26] sdcard: use PW_LEN define instead of '16' magic Philippe Mathieu-Daudé
2017-12-13 23:20 ` [Qemu-devel] [PATCH 16/26] sdcard: let cmd_valid_while_locked() returns a bool Philippe Mathieu-Daudé
2017-12-13 23:20 ` [Qemu-devel] [PATCH 17/26] sdcard: rename sd_set_REG() functions called by sd_reset() as sd_reset_REG() Philippe Mathieu-Daudé
2017-12-13 23:20 ` [Qemu-devel] [PATCH 18/26] sdcard: move Memory Card registers together Philippe Mathieu-Daudé
2017-12-13 23:20 ` [Qemu-devel] [PATCH 19/26] sdcard: add DSR register Philippe Mathieu-Daudé
2017-12-13 23:20 ` [Qemu-devel] [PATCH 20/26] sdcard: add/use SD_CMD_MAX to check valid SD commands Philippe Mathieu-Daudé
2017-12-13 23:20 ` [Qemu-devel] [PATCH 21/26] sdcard: add sd_cmd_abbreviation() to resolve the SD command id Philippe Mathieu-Daudé
2017-12-13 23:20 ` [Qemu-devel] [PATCH 22/26] sdcard: reduce sd_cmd traces Philippe Mathieu-Daudé
2017-12-13 23:20 ` [Qemu-devel] [PATCH 23/26] sdcard: add ACMD trace events Philippe Mathieu-Daudé
2017-12-13 23:20 ` [Qemu-devel] [PATCH 24/26] sdcard: use a 16-bit type for the 16-bit RCA register Philippe Mathieu-Daudé
2017-12-13 23:20 ` [Qemu-devel] [PATCH 25/26] sdcard: add/use a SDCardCommandClass enum instead of magic numbers Philippe Mathieu-Daudé
2017-12-13 23:20 ` [Qemu-devel] [PATCH 26/26] sdcard: add/use a ccc_spi enum for the commands supported in SPI mode Philippe Mathieu-Daudé
2017-12-14 1:29 ` [Qemu-devel] [PATCH 00/26] SDCard housekeeping Philippe Mathieu-Daudé
2017-12-16 0:13 ` Alistair Francis
2018-01-02 16:40 ` Philippe Mathieu-Daudé
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=20171213232025.24503-2-f4bug@amsat.org \
--to=f4bug@amsat.org \
--cc=alistair.francis@xilinx.com \
--cc=andrew.smirnov@gmail.com \
--cc=armbru@redhat.com \
--cc=berrange@redhat.com \
--cc=eblake@redhat.com \
--cc=edgar.iglesias@xilinx.com \
--cc=ehabkost@redhat.com \
--cc=famz@redhat.com \
--cc=marcandre.lureau@redhat.com \
--cc=mdroth@linux.vnet.ibm.com \
--cc=pbonzini@redhat.com \
--cc=peter.maydell@linaro.org \
--cc=qemu-devel@nongnu.org \
--cc=thuth@redhat.com \
--cc=yurovsky@gmail.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).