From: "Philippe Mathieu-Daudé" <f4bug@amsat.org>
To: Alistair Francis <alistair.francis@xilinx.com>,
Peter Maydell <peter.maydell@linaro.org>,
Eric Blake <eblake@redhat.com>,
Paolo Bonzini <pbonzini@redhat.com>,
Kevin Wolf <kwolf@redhat.com>,
Stefan Hajnoczi <stefanha@redhat.com>
Cc: "Philippe Mathieu-Daudé" <f4bug@amsat.org>,
qemu-devel@nongnu.org,
"Edgar E . Iglesias" <edgar.iglesias@xilinx.com>,
"Markus Armbruster" <armbru@redhat.com>,
"Thomas Huth" <thuth@redhat.com>,
"Marc-André Lureau" <marcandre.lureau@redhat.com>
Subject: [Qemu-devel] [RFC PATCH v2 2/4] libqos: add a sdbus API
Date: Wed, 3 Jan 2018 18:49:23 -0300 [thread overview]
Message-ID: <20180103214925.16677-3-f4bug@amsat.org> (raw)
In-Reply-To: <20180103214925.16677-1-f4bug@amsat.org>
Signed-off-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
---
tests/libqos/sdbus.h | 45 ++++++++++++++++++++++++++++++
tests/libqos/sdbus.c | 74 ++++++++++++++++++++++++++++++++++++++++++++++++++
tests/Makefile.include | 1 +
3 files changed, 120 insertions(+)
create mode 100644 tests/libqos/sdbus.h
create mode 100644 tests/libqos/sdbus.c
diff --git a/tests/libqos/sdbus.h b/tests/libqos/sdbus.h
new file mode 100644
index 0000000000..2057faf176
--- /dev/null
+++ b/tests/libqos/sdbus.h
@@ -0,0 +1,45 @@
+/*
+ * SD/MMC Bus libqos
+ *
+ * Copyright (c) 2017 Philippe Mathieu-Daudé
+ *
+ * This work is licensed under the terms of the GNU GPL, version 2 or later.
+ * See the COPYING file in the top-level directory.
+ */
+#ifndef LIBQOS_SDBUS_H
+#define LIBQOS_SDBUS_H
+
+enum NCmd {
+ GO_IDLE_STATE = 0,
+ ALL_SEND_CID = 2,
+ SEND_RELATIVE_ADDR = 3,
+ SELECT_CARD = 7,
+ SEND_IF_COND = 8,
+ SEND_CSD = 9,
+};
+
+enum ACmd {
+ SEND_STATUS = 13,
+ SEND_OP_COND = 41,
+ SEND_SCR = 51,
+};
+
+typedef struct SDBusAdapter SDBusAdapter;
+struct SDBusAdapter {
+
+ ssize_t (*do_command)(SDBusAdapter *adapter, enum NCmd cmd, uint32_t arg,
+ uint8_t **response);
+ void (*write_byte)(SDBusAdapter *adapter, uint8_t value);
+ uint8_t (*read_byte)(SDBusAdapter *adapter);
+};
+
+ssize_t sdbus_do_cmd(SDBusAdapter *adapter, enum NCmd cmd, uint32_t arg,
+ uint8_t **response);
+ssize_t sdbus_do_acmd(SDBusAdapter *adapter, enum ACmd acmd, uint32_t arg,
+ uint16_t address, uint8_t **response);
+void sdbus_write_byte(SDBusAdapter *adapter, uint8_t value);
+uint8_t sdbus_read_byte(SDBusAdapter *adapter);
+
+SDBusAdapter *qmp_sdbus_create(const char *bus_name);
+
+#endif
diff --git a/tests/libqos/sdbus.c b/tests/libqos/sdbus.c
new file mode 100644
index 0000000000..15f38c2bb8
--- /dev/null
+++ b/tests/libqos/sdbus.c
@@ -0,0 +1,74 @@
+/*
+ * QTest SD/MMC Bus driver
+ *
+ * Copyright (c) 2017 Philippe Mathieu-Daudé
+ *
+ * This work is licensed under the terms of the GNU GPL, version 2 or later.
+ * See the COPYING file in the top-level directory.
+ */
+#include "qemu/osdep.h"
+#include "libqos/sdbus.h"
+#include "libqtest.h"
+#include "qemu-common.h"
+
+static bool verbose;
+#define DPRINTF(fmt, ...) \
+ do { \
+ if (verbose) { \
+ fprintf(stderr, fmt, ## __VA_ARGS__); \
+ } \
+ } while (0)
+
+static ssize_t do_cmd(SDBusAdapter *adapter, enum NCmd cmd, uint32_t arg,
+ uint8_t **response, bool is_app_cmd)
+{
+ const char *s_cmd = is_app_cmd ? "ACMD" : "CMD";
+ ssize_t sz;
+
+ verbose = !!getenv("V");
+ if (verbose && !is_app_cmd && (cmd == 55)) {
+ verbose = false;
+ }
+
+ DPRINTF("-> %s%02u (0x%08x)\n", s_cmd, cmd, arg);
+ sz = adapter->do_command(adapter, cmd, arg, response);
+ if (response) {
+ if (sz < 0) {
+ DPRINTF("<- %s%02u (len: %ld)\n", s_cmd, cmd, sz);
+ } else if (verbose) {
+ char *pfx = g_strdup_printf("<- %s%02u (len: %ld)", s_cmd, cmd, sz);
+
+ qemu_hexdump((const char *)*response, stderr, pfx, sz);
+ g_free(pfx);
+ }
+ } else {
+ DPRINTF("<- %s%02u\n", s_cmd, cmd);
+ }
+
+ return sz;
+}
+
+ssize_t sdbus_do_cmd(SDBusAdapter *adapter, enum NCmd cmd, uint32_t arg,
+ uint8_t **response)
+{
+ return do_cmd(adapter, cmd, arg, response, false);
+}
+
+ssize_t sdbus_do_acmd(SDBusAdapter *adapter, enum ACmd acmd, uint32_t arg,
+ uint16_t address, uint8_t **response)
+{
+ do_cmd(adapter, 55, address << 16, NULL, false);
+ // TODO check rv?
+
+ return do_cmd(adapter, acmd, arg, response, true);
+}
+
+void sdbus_write_byte(SDBusAdapter *adapter, uint8_t value)
+{
+ adapter->write_byte(adapter, value);
+}
+
+uint8_t sdbus_read_byte(SDBusAdapter *adapter)
+{
+ return adapter->read_byte(adapter);
+}
diff --git a/tests/Makefile.include b/tests/Makefile.include
index cd18ab4519..c22925d4db 100644
--- a/tests/Makefile.include
+++ b/tests/Makefile.include
@@ -715,6 +715,7 @@ tests/test-crypto-block$(EXESUF): tests/test-crypto-block.o $(test-crypto-obj-y)
libqos-obj-y = tests/libqos/pci.o tests/libqos/fw_cfg.o tests/libqos/malloc.o
libqos-obj-y += tests/libqos/i2c.o tests/libqos/libqos.o
+libqos-obj-y += tests/libqos/sdbus.o
libqos-spapr-obj-y = $(libqos-obj-y) tests/libqos/malloc-spapr.o
libqos-spapr-obj-y += tests/libqos/libqos-spapr.o
libqos-spapr-obj-y += tests/libqos/rtas.o
--
2.15.1
next prev parent reply other threads:[~2018-01-03 21:49 UTC|newest]
Thread overview: 22+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-01-03 21:49 [Qemu-devel] [RFC PATCH v2 0/4] sdbus: testing sdcards Philippe Mathieu-Daudé
2018-01-03 21:49 ` [Qemu-devel] [PATCH v2 1/4] sdbus: add a QMP command to access a SDBus Philippe Mathieu-Daudé
2018-01-05 15:11 ` Stefan Hajnoczi
2018-01-05 15:29 ` Eric Blake
2018-01-05 16:06 ` Philippe Mathieu-Daudé
2018-01-05 16:10 ` Eric Blake
2018-01-05 21:28 ` Philippe Mathieu-Daudé
2019-03-08 16:11 ` Philippe Mathieu-Daudé
2019-03-11 11:49 ` Thomas Huth
2019-03-11 13:43 ` Eduardo Habkost
2019-03-11 13:48 ` Peter Maydell
2019-03-11 15:52 ` Markus Armbruster
2018-01-03 21:49 ` Philippe Mathieu-Daudé [this message]
2018-01-05 15:18 ` [Qemu-devel] [RFC PATCH v2 2/4] libqos: add a sdbus API Stefan Hajnoczi
2018-01-03 21:49 ` [Qemu-devel] [RFC PATCH v2 3/4] libqos: implement sdbus QMP driver Philippe Mathieu-Daudé
2018-01-05 15:25 ` Stefan Hajnoczi
2018-01-03 21:49 ` [Qemu-devel] [RFC PATCH v2 4/4] tests: add some sdcard qtest Philippe Mathieu-Daudé
2018-01-05 15:31 ` Stefan Hajnoczi
2018-01-05 15:55 ` Philippe Mathieu-Daudé
2018-01-08 14:32 ` Stefan Hajnoczi
2018-01-03 22:17 ` [Qemu-devel] [RFC PATCH v2 0/4] sdbus: testing sdcards no-reply
2018-01-05 15:32 ` 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=20180103214925.16677-3-f4bug@amsat.org \
--to=f4bug@amsat.org \
--cc=alistair.francis@xilinx.com \
--cc=armbru@redhat.com \
--cc=eblake@redhat.com \
--cc=edgar.iglesias@xilinx.com \
--cc=kwolf@redhat.com \
--cc=marcandre.lureau@redhat.com \
--cc=pbonzini@redhat.com \
--cc=peter.maydell@linaro.org \
--cc=qemu-devel@nongnu.org \
--cc=stefanha@redhat.com \
--cc=thuth@redhat.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).