From: Emanuele Giuseppe Esposito <e.emanuelegiuseppe@gmail.com>
To: qemu-devel@nongnu.org
Cc: "Paolo Bonzini" <pbonzini@redhat.com>,
"Alexander Graf" <agraf@suse.de>,
"Philippe Mathieu-Daudé" <f4bug@amsat.org>,
qemu-block@nongnu.org, "Fam Zheng" <famz@redhat.com>,
"Michael S. Tsirkin" <mst@redhat.com>,
"Jason Wang" <jasowang@redhat.com>,
"David Gibson" <david@gibson.dropbear.id.au>,
"Laurent Vivier" <lvivier@redhat.com>,
qemu-ppc@nongnu.org, "John Snow" <jsnow@redhat.com>,
"Amit Shah" <amit@kernel.org>,
"Stefan Hajnoczi" <stefanha@redhat.com>,
"Gerd Hoffmann" <kraxel@redhat.com>, "Greg Kurz" <groug@kaod.org>,
"Emanuele Giuseppe Esposito" <e.emanuelegiuseppe@gmail.com>
Subject: [Qemu-devel] [PATCH 05/33] tests/qgraph: sdhci driver and interface nodes
Date: Mon, 13 Aug 2018 12:14:25 +0200 [thread overview]
Message-ID: <20180813101453.10200-6-e.emanuelegiuseppe@gmail.com> (raw)
In-Reply-To: <20180813101453.10200-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 | 163 +++++++++++++++++++++++++++++++++++++++++
tests/libqos/sdhci.h | 69 +++++++++++++++++
3 files changed, 233 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 2154e53944..90a74854b8 100644
--- a/tests/Makefile.include
+++ b/tests/Makefile.include
@@ -775,6 +775,7 @@ libqgraph-machines-obj-y = tests/libqos/x86_64_pc-machine.o
libqgraph-pci-obj-y = $(libqos-pc-obj-y)
libqgraph-pci-obj-y += $(libqgraph-machines-obj-y)
+libqgraph-pci-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..65b407d741
--- /dev/null
+++ b/tests/libqos/sdhci.c
@@ -0,0 +1,163 @@
+/*
+ * 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 "libqos/qgraph.h"
+#include "pci.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 *smm = obj;
+ if (!g_strcmp0(interface, "sdhci")) {
+ return &smm->sdhci;
+ }
+ fprintf(stderr, "%s not present in generic-sdhci\n", interface);
+ g_assert_not_reached();
+}
+
+void qos_init_sdhci_smm(QSDHCI_MemoryMapped *sdhci, uint32_t addr,
+ QSDHCIProperties *common)
+{
+ sdhci->obj.get_driver = sdhci_mm_get_driver;
+ sdhci->sdhci.readw = sdhci_mm_readw;
+ sdhci->sdhci.readq = sdhci_mm_readq;
+ 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_pci_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_pci_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;
+ }
+
+ fprintf(stderr, "%s not present in sdhci-pci\n", interface);
+ g_assert_not_reached();
+}
+
+static void sdhci_pci_start_hw(QOSGraphObject *obj)
+{
+ QSDHCI_PCI *spci = (QSDHCI_PCI *)obj;
+ qpci_device_enable(&spci->dev);
+}
+
+static void sdhci_destructor(QOSGraphObject *obj)
+{
+ QSDHCI_PCI *spci = (QSDHCI_PCI *)obj;
+ qpci_iounmap(&spci->dev, spci->mem_bar);
+ g_free(spci);
+}
+
+static void *sdhci_pci_create(void *pci_bus, QGuestAllocator *alloc, void *addr)
+{
+ QSDHCI_PCI *spci = g_new0(QSDHCI_PCI, 1);
+ QPCIBus *bus = pci_bus;
+ uint64_t barsize;
+
+ qpci_device_init(&spci->dev, bus, addr);
+ spci->mem_bar = qpci_iomap(&spci->dev, 0, &barsize);
+ spci->sdhci.readw = sdhci_pci_readw;
+ spci->sdhci.readq = sdhci_pci_readq;
+ spci->sdhci.writeq = sdhci_pci_writeq;
+ set_qsdhci_fields(&spci->sdhci, 2, 0, 1, 0x057834b4);
+
+ spci->obj.get_driver = sdhci_pci_get_driver;
+ spci->obj.start_hw = sdhci_pci_start_hw;
+ spci->obj.destructor = sdhci_destructor;
+ return &spci->obj;
+}
+
+static void qsdhci_register_nodes(void)
+{
+ QPCIAddress addr = {
+ .devfn = QPCI_DEVFN(4, 0),
+ .vendor_id = PCI_VENDOR_ID_REDHAT,
+ .device_id = PCI_DEVICE_ID_REDHAT_SDHCI,
+ };
+
+ QOSGraphEdgeOptions opts = {
+ .extra_device_opts = "addr=04.0",
+ };
+
+ /* generic-sdhci */
+ qos_node_create_driver("generic-sdhci", NULL);
+ qos_node_produces("generic-sdhci", "sdhci");
+
+ /* sdhci-pci */
+ add_qpci_address(&opts, &addr);
+ qos_node_create_driver("sdhci-pci", sdhci_pci_create);
+ qos_node_produces("sdhci-pci", "sdhci");
+ qos_node_consumes("sdhci-pci", "pci-bus", &opts);
+
+}
+
+libqos_init(qsdhci_register_nodes);
diff --git a/tests/libqos/sdhci.h b/tests/libqos/sdhci.h
new file mode 100644
index 0000000000..d8d2b2eecf
--- /dev/null
+++ b/tests/libqos/sdhci.h
@@ -0,0 +1,69 @@
+/*
+ * 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 "libqos/qgraph.h"
+#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 {
+ uint16_t (*readw)(QSDHCI *s, uint32_t reg);
+ uint64_t (*readq)(QSDHCI *s, uint32_t reg);
+ void (*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_init_sdhci_smm(): external constructor used by all drivers/machines
+ * that "contain" a #QSDHCI_MemoryMapped driver
+ */
+void qos_init_sdhci_smm(QSDHCI_MemoryMapped *sdhci, uint32_t addr,
+ QSDHCIProperties *common);
+
+#endif
--
2.17.1
next prev parent reply other threads:[~2018-08-13 10:15 UTC|newest]
Thread overview: 39+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-08-13 10:14 [Qemu-devel] [PATCH 00/33] Qtest driver framework Emanuele Giuseppe Esposito
2018-08-13 10:14 ` [Qemu-devel] [PATCH 01/33] tests: qgraph API for the qtest " Emanuele Giuseppe Esposito
2018-08-13 10:14 ` [Qemu-devel] [PATCH 02/33] tests/qgraph: rename qpci_init_pc and qpci_init_spapr functions Emanuele Giuseppe Esposito
2018-08-13 10:14 ` [Qemu-devel] [PATCH 03/33] tests/qgraph: pci-pc driver and interface nodes Emanuele Giuseppe Esposito
2018-08-13 10:14 ` [Qemu-devel] [PATCH 04/33] tests/qgraph: x86_64/pc machine node Emanuele Giuseppe Esposito
2018-08-13 10:14 ` Emanuele Giuseppe Esposito [this message]
2018-08-13 10:14 ` [Qemu-devel] [PATCH 06/33] tests/qgraph: sdhci test node Emanuele Giuseppe Esposito
2018-08-13 10:14 ` [Qemu-devel] [PATCH 07/33] tests/qgraph: arm/raspi2 machine node Emanuele Giuseppe Esposito
2018-08-13 10:14 ` [Qemu-devel] [PATCH 08/33] tests/qgraph: pci-spapr driver and interface nodes Emanuele Giuseppe Esposito
2018-08-13 10:14 ` [Qemu-devel] [PATCH 09/33] tests/qgraph: ppc64/pseries machine node Emanuele Giuseppe Esposito
2018-08-13 10:14 ` [Qemu-devel] [PATCH 10/33] tests/qgraph: has_buggy_msi flag Emanuele Giuseppe Esposito
2018-08-13 10:14 ` [Qemu-devel] [PATCH 11/33] tests/qgraph: e1000e driver and interface nodes Emanuele Giuseppe Esposito
2018-08-13 10:14 ` [Qemu-devel] [PATCH 12/33] tests/qgraph: e1000e-test node Emanuele Giuseppe Esposito
2018-08-13 10:14 ` [Qemu-devel] [PATCH 13/33] tests/qgraph: virtio_start_device function Emanuele Giuseppe Esposito
2018-08-13 10:14 ` [Qemu-devel] [PATCH 14/33] tests/qgraph: virtio-pci driver and interface nodes Emanuele Giuseppe Esposito
2018-08-13 10:14 ` [Qemu-devel] [PATCH 15/33] tests/qgraph: virtio-mmio " Emanuele Giuseppe Esposito
2018-08-13 10:14 ` [Qemu-devel] [PATCH 16/33] tests/qgraph: arm/virt machine node Emanuele Giuseppe Esposito
2018-08-13 10:14 ` [Qemu-devel] [PATCH 17/33] tests: virtio: separate ccw tests from libqos Emanuele Giuseppe Esposito
2018-08-13 10:14 ` [Qemu-devel] [PATCH 18/33] tests/qgraph: virtio-serial driver and interface nodes Emanuele Giuseppe Esposito
2018-08-13 10:14 ` [Qemu-devel] [PATCH 19/33] tests/qgraph: virtio-console test node Emanuele Giuseppe Esposito
2018-08-13 10:14 ` [Qemu-devel] [PATCH 20/33] tests/qgraph: virtio-serial " Emanuele Giuseppe Esposito
2018-08-13 10:14 ` [Qemu-devel] [PATCH 21/33] tests/qgraph: virtio-9p driver and interface nodes Emanuele Giuseppe Esposito
2018-08-13 10:14 ` [Qemu-devel] [PATCH 22/33] tests/qgraph: virtio-9p test node Emanuele Giuseppe Esposito
2018-08-13 10:14 ` [Qemu-devel] [PATCH 23/33] tests/qgraph: virtio-balloon driver and interface nodes Emanuele Giuseppe Esposito
2018-08-13 10:14 ` [Qemu-devel] [PATCH 24/33] tests/qgraph: virtio-balloon test node Emanuele Giuseppe Esposito
2018-08-13 10:14 ` [Qemu-devel] [PATCH 25/33] tests/qgraph: virtio-rng driver and interface nodes Emanuele Giuseppe Esposito
2018-08-13 10:14 ` [Qemu-devel] [PATCH 26/33] tests/qgraph: virtio-rng test node Emanuele Giuseppe Esposito
2018-08-13 10:14 ` [Qemu-devel] [PATCH 27/33] tests/qgraph: virtio-blk driver and interface nodes Emanuele Giuseppe Esposito
2018-08-13 10:14 ` [Qemu-devel] [PATCH 28/33] tests/qgraph: virtio-blk test node Emanuele Giuseppe Esposito
2018-08-13 10:14 ` [Qemu-devel] [PATCH 29/33] tests/qgraph: virtio-net driver and interface nodes Emanuele Giuseppe Esposito
2018-08-13 10:14 ` [Qemu-devel] [PATCH 30/33] tests/qgraph: virtio-net test node Emanuele Giuseppe Esposito
2018-08-13 10:14 ` [Qemu-devel] [PATCH 31/33] tests/qgraph: virtio-scsi driver and interface nodes Emanuele Giuseppe Esposito
2018-08-13 10:14 ` [Qemu-devel] [PATCH 32/33] tests/qgraph: virtio-scsi test node Emanuele Giuseppe Esposito
2018-08-13 10:14 ` [Qemu-devel] [PATCH 33/33] tests/qgraph: temporarly commented vhost-user-test Emanuele Giuseppe Esposito
2018-08-13 11:15 ` Michael S. Tsirkin
2018-08-13 11:22 ` Paolo Bonzini
2018-08-13 12:02 ` [Qemu-devel] [PATCH 00/33] Qtest driver framework Michael S. Tsirkin
2018-08-15 12:38 ` Markus Armbruster
2018-08-16 18:16 ` Emanuele
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=20180813101453.10200-6-e.emanuelegiuseppe@gmail.com \
--to=e.emanuelegiuseppe@gmail.com \
--cc=agraf@suse.de \
--cc=amit@kernel.org \
--cc=david@gibson.dropbear.id.au \
--cc=f4bug@amsat.org \
--cc=famz@redhat.com \
--cc=groug@kaod.org \
--cc=jasowang@redhat.com \
--cc=jsnow@redhat.com \
--cc=kraxel@redhat.com \
--cc=lvivier@redhat.com \
--cc=mst@redhat.com \
--cc=pbonzini@redhat.com \
--cc=qemu-block@nongnu.org \
--cc=qemu-devel@nongnu.org \
--cc=qemu-ppc@nongnu.org \
--cc=stefanha@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).