From: Emanuele Giuseppe Esposito <e.emanuelegiuseppe@gmail.com>
To: Paolo Bonzini <pbonzini@redhat.com>
Cc: "Laurent Vivier" <lvivier@redhat.com>,
"Philippe Mathieu-Daudé" <f4bug@amsat.org>,
qemu-devel@nongnu.org,
"Emanuele Giuseppe Esposito" <e.emanuelegiuseppe@gmail.com>
Subject: [Qemu-devel] [PATCH 3/7] tests/qgraph: sdhci driver and interface nodes
Date: Mon, 9 Jul 2018 11:11:32 +0200 [thread overview]
Message-ID: <20180709091136.28849-4-e.emanuelegiuseppe@gmail.com> (raw)
In-Reply-To: <20180709091136.28849-1-e.emanuelegiuseppe@gmail.com>
Add qgraph nodes for sdhci-pci and generic-sdhci (memory mapped) drivers.
Both drivers implement (produce) the same interface sdhci, that provides the
readw - readq - writeq functions.
Signed-off-by: Emanuele Giuseppe Esposito <e.emanuelegiuseppe@gmail.com>
---
tests/Makefile.include | 1 +
tests/libqos/sdhci.c | 142 +++++++++++++++++++++++++++++++++++++++++
tests/libqos/sdhci.h | 68 ++++++++++++++++++++
3 files changed, 211 insertions(+)
create mode 100644 tests/libqos/sdhci.c
create mode 100644 tests/libqos/sdhci.h
diff --git a/tests/Makefile.include b/tests/Makefile.include
index b16bbd55df..acbf704a8a 100644
--- a/tests/Makefile.include
+++ b/tests/Makefile.include
@@ -770,6 +770,7 @@ libqos-usb-obj-y = $(libqos-spapr-obj-y) $(libqos-pc-obj-y) tests/libqos/usb.o
libqos-virtio-obj-y = $(libqos-spapr-obj-y) $(libqos-pc-obj-y) tests/libqos/virtio.o tests/libqos/virtio-pci.o tests/libqos/virtio-mmio.o tests/libqos/malloc-generic.o
libqgraph-obj-y = tests/libqos/qgraph.o
+libqgraph-pc-obj-y = $(libqos-pc-obj-y) tests/libqos/sdhci.o
check-unit-y += tests/test-qgraph$(EXESUF)
tests/test-qgraph$(EXESUF): tests/test-qgraph.o $(libqgraph-obj-y)
diff --git a/tests/libqos/sdhci.c b/tests/libqos/sdhci.c
new file mode 100644
index 0000000000..213c2657c3
--- /dev/null
+++ b/tests/libqos/sdhci.c
@@ -0,0 +1,142 @@
+/*
+ * libqos driver framework
+ *
+ * Copyright (c) 2018 Emanuele Giuseppe Esposito <e.emanuelegiuseppe@gmail.com>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License version 2 as published by the Free Software Foundation.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, see <http://www.gnu.org/licenses/>
+ */
+
+#include "qemu/osdep.h"
+#include "libqtest.h"
+#include "pci.h"
+#include "pci-pc.h"
+#include "qgraph.h"
+#include "sdhci.h"
+#include "hw/pci/pci.h"
+
+static void set_qsdhci_fields(QSDHCI *s, uint8_t version, uint8_t baseclock,
+ bool sdma, uint64_t reg)
+{
+ s->props.version = version;
+ s->props.baseclock = baseclock;
+ s->props.capab.sdma = sdma;
+ s->props.capab.reg = reg;
+}
+
+/* Memory mapped implementation of QSDHCI */
+
+static uint16_t sdhci_mm_readw(QSDHCI *s, uint32_t reg)
+{
+ QSDHCI_MemoryMapped *smm = container_of(s, QSDHCI_MemoryMapped, sdhci);
+ return qtest_readw(global_qtest, smm->addr + reg);
+}
+
+static uint64_t sdhci_mm_readq(QSDHCI *s, uint32_t reg)
+{
+ QSDHCI_MemoryMapped *smm = container_of(s, QSDHCI_MemoryMapped, sdhci);
+ return qtest_readq(global_qtest, smm->addr + reg);
+}
+
+static void sdhci_mm_writeq(QSDHCI *s, uint32_t reg, uint64_t val)
+{
+ QSDHCI_MemoryMapped *smm = container_of(s, QSDHCI_MemoryMapped, sdhci);
+ qtest_writeq(global_qtest, smm->addr + reg, val);
+}
+
+static void *sdhci_mm_get_driver(void *obj, const char *interface)
+{
+ QSDHCI_MemoryMapped *spci = obj;
+ if (!g_strcmp0(interface, "sdhci")) {
+ return &spci->sdhci;
+ }
+ printf("%s not present in generic-sdhci\n", interface);
+ abort();
+}
+
+void qos_create_sdhci_mm(QSDHCI_MemoryMapped *sdhci, uint32_t addr,
+ QSDHCIProperties *common)
+{
+ sdhci->obj.get_driver = sdhci_mm_get_driver;
+ sdhci->sdhci.sdhci_readw = sdhci_mm_readw;
+ sdhci->sdhci.sdhci_readq = sdhci_mm_readq;
+ sdhci->sdhci.sdhci_writeq = sdhci_mm_writeq;
+ memcpy(&sdhci->sdhci.props, common, sizeof(QSDHCIProperties));
+ sdhci->addr = addr;
+}
+
+/* PCI implementation of QSDHCI */
+
+static uint16_t sdhci_pci_readw(QSDHCI *s, uint32_t reg)
+{
+ QSDHCI_PCI *spci = container_of(s, QSDHCI_PCI, sdhci);
+ return qpci_io_readw(&spci->dev, spci->mem_bar, reg);
+}
+
+static uint64_t sdhci_readq(QSDHCI *s, uint32_t reg)
+{
+ QSDHCI_PCI *spci = container_of(s, QSDHCI_PCI, sdhci);
+ return qpci_io_readq(&spci->dev, spci->mem_bar, reg);
+}
+
+static void sdhci_writeq(QSDHCI *s, uint32_t reg, uint64_t val)
+{
+ QSDHCI_PCI *spci = container_of(s, QSDHCI_PCI, sdhci);
+ return qpci_io_writeq(&spci->dev, spci->mem_bar, reg, val);
+}
+
+static void *sdhci_pci_get_driver(void *object, const char *interface)
+{
+ QSDHCI_PCI *spci = object;
+ if (!g_strcmp0(interface, "sdhci")) {
+ return &spci->sdhci;
+ }
+
+ printf("%s not present in sdhci-pci\n", interface);
+ abort();
+}
+
+static void sdhci_destroy(QOSGraphObject *obj)
+{
+ g_free(obj);
+}
+
+static void *sdhci_pci_create(void *pci_bus, QOSGraphObject *alloc)
+{
+ QSDHCI_PCI *spci = g_new0(QSDHCI_PCI, 1);
+ QPCIBus *bus = pci_bus;
+ uint64_t barsize;
+
+ qpci_device_init(&spci->dev, bus, QPCI_DEVFN(4, 0));
+ if (bus) {
+ spci->mem_bar = qpci_iomap(&spci->dev, 0, &barsize);
+ }
+ spci->obj.get_driver = sdhci_pci_get_driver;
+ spci->obj.destructor = sdhci_destroy;
+ spci->sdhci.sdhci_readw = sdhci_pci_readw;
+ spci->sdhci.sdhci_readq = sdhci_readq;
+ spci->sdhci.sdhci_writeq = sdhci_writeq;
+ set_qsdhci_fields(&spci->sdhci, 2, 0, 1, 0x057834b4);
+ return &spci->obj;
+}
+
+static void qsdhci(void)
+{
+ qos_node_create_interface("sdhci");
+ qos_node_create_driver("generic-sdhci", NULL);
+ qos_node_produces("generic-sdhci", "sdhci");
+ qos_node_create_driver("sdhci-pci", sdhci_pci_create);
+ qos_node_produces("sdhci-pci", "sdhci");
+ qos_node_consumes_arg("sdhci-pci", "pci-bus", "addr=04.0");
+}
+
+libqos_init(qsdhci);
diff --git a/tests/libqos/sdhci.h b/tests/libqos/sdhci.h
new file mode 100644
index 0000000000..dfd043f160
--- /dev/null
+++ b/tests/libqos/sdhci.h
@@ -0,0 +1,68 @@
+/*
+ * libqos driver framework
+ *
+ * Copyright (c) 2018 Emanuele Giuseppe Esposito <e.emanuelegiuseppe@gmail.com>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License version 2 as published by the Free Software Foundation.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, see <http://www.gnu.org/licenses/>
+ */
+
+#ifndef QGRAPH_QSDHCI
+#define QGRAPH_QSDHCI
+#include "pci.h"
+
+typedef struct QSDHCI QSDHCI;
+typedef struct QSDHCI_MemoryMapped QSDHCI_MemoryMapped;
+typedef struct QSDHCI_PCI QSDHCI_PCI;
+typedef struct QSDHCIProperties QSDHCIProperties;
+
+/* Properties common to all QSDHCI devices */
+struct QSDHCIProperties {
+ uint8_t version;
+ uint8_t baseclock;
+ struct {
+ bool sdma;
+ uint64_t reg;
+ } capab;
+};
+
+struct QSDHCI {
+ QOSGraphObject obj;
+ uint16_t (*sdhci_readw)(QSDHCI *s, uint32_t reg);
+ uint64_t (*sdhci_readq)(QSDHCI *s, uint32_t reg);
+ void (*sdhci_writeq)(QSDHCI *s, uint32_t reg, uint64_t val);
+ QSDHCIProperties props;
+};
+
+/* Memory Mapped implementation of QSDHCI */
+struct QSDHCI_MemoryMapped {
+ QOSGraphObject obj;
+ QSDHCI sdhci;
+ uint64_t addr;
+};
+
+/* PCI implementation of QSDHCI */
+struct QSDHCI_PCI {
+ QOSGraphObject obj;
+ QPCIDevice dev;
+ QSDHCI sdhci;
+ QPCIBar mem_bar;
+};
+
+/**
+ * qos_create_sdhci_mm(): external constructor used by all drivers/machines
+ * that "contain" a #QSDHCI_MemoryMapped driver
+ */
+void qos_create_sdhci_mm(QSDHCI_MemoryMapped *sdhci, uint32_t addr,
+ QSDHCIProperties *common);
+
+#endif
--
2.17.1
next prev parent reply other threads:[~2018-07-09 9:12 UTC|newest]
Thread overview: 39+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-07-09 9:11 [Qemu-devel] [PATCH 0/7] Qtest driver framework Emanuele Giuseppe Esposito
2018-07-09 9:11 ` [Qemu-devel] [PATCH 1/7] tests: qgraph API for the qtest " Emanuele Giuseppe Esposito
2018-07-11 14:28 ` Stefan Hajnoczi
2018-07-11 14:58 ` Paolo Bonzini
2018-07-18 14:23 ` Stefan Hajnoczi
2018-07-18 18:05 ` Emanuele
2018-07-18 19:28 ` Paolo Bonzini
2018-07-18 21:13 ` Emanuele
2018-07-27 12:54 ` Stefan Hajnoczi
2018-07-09 9:11 ` [Qemu-devel] [PATCH 2/7] tests/qgraph: pci-pc driver and interface nodes Emanuele Giuseppe Esposito
2018-07-11 14:49 ` Stefan Hajnoczi
2018-07-11 15:18 ` Paolo Bonzini
2018-07-18 14:29 ` Stefan Hajnoczi
2018-07-18 18:29 ` Emanuele
2018-07-18 19:33 ` Paolo Bonzini
2018-07-18 20:49 ` Emanuele
2018-07-11 17:46 ` Emanuele
2018-07-18 15:02 ` Stefan Hajnoczi
2018-07-18 19:38 ` Paolo Bonzini
2018-07-11 20:05 ` Philippe Mathieu-Daudé
2018-07-09 9:11 ` Emanuele Giuseppe Esposito [this message]
2018-07-11 20:13 ` [Qemu-devel] [PATCH 3/7] tests/qgraph: sdhci " Philippe Mathieu-Daudé
2018-07-11 20:44 ` Emanuele
2018-07-09 9:11 ` [Qemu-devel] [PATCH 4/7] tests/qgraph: arm/raspi2 machine node Emanuele Giuseppe Esposito
2018-07-11 14:59 ` Stefan Hajnoczi
2018-07-11 15:30 ` Paolo Bonzini
2018-07-11 20:19 ` Philippe Mathieu-Daudé
2018-07-09 9:11 ` [Qemu-devel] [PATCH 5/7] tests/qgraph: x86_64/pc " Emanuele Giuseppe Esposito
2018-07-09 9:11 ` [Qemu-devel] [PATCH 6/7] tests/qgraph: gtest integration Emanuele Giuseppe Esposito
2018-07-11 15:02 ` Stefan Hajnoczi
2018-07-09 9:11 ` [Qemu-devel] [PATCH 7/7] tests/qgraph: sdhci test node Emanuele Giuseppe Esposito
2018-07-11 15:15 ` Stefan Hajnoczi
2018-07-11 17:52 ` Emanuele
2018-07-12 12:07 ` Paolo Bonzini
2018-07-11 14:00 ` [Qemu-devel] [PATCH 0/7] Qtest driver framework Stefan Hajnoczi
2018-07-11 14:17 ` Emanuele
2018-07-11 15:27 ` Stefan Hajnoczi
2018-07-18 17:14 ` Markus Armbruster
2018-07-18 19:35 ` Paolo Bonzini
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=20180709091136.28849-4-e.emanuelegiuseppe@gmail.com \
--to=e.emanuelegiuseppe@gmail.com \
--cc=f4bug@amsat.org \
--cc=lvivier@redhat.com \
--cc=pbonzini@redhat.com \
--cc=qemu-devel@nongnu.org \
/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).