From nobody Tue Nov 4 22:00:41 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=gmail.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1531127871882446.22408676679754; Mon, 9 Jul 2018 02:17:51 -0700 (PDT) Received: from localhost ([::1]:40008 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fcSIm-0000g3-LX for importer@patchew.org; Mon, 09 Jul 2018 05:17:48 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:38410) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fcSDz-0005RB-W0 for qemu-devel@nongnu.org; Mon, 09 Jul 2018 05:12:53 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fcSDy-0007IX-Fi for qemu-devel@nongnu.org; Mon, 09 Jul 2018 05:12:51 -0400 Received: from mail-ed1-x543.google.com ([2a00:1450:4864:20::543]:38462) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1fcSDx-0007I4-Vf for qemu-devel@nongnu.org; Mon, 09 Jul 2018 05:12:50 -0400 Received: by mail-ed1-x543.google.com with SMTP id a5-v6so13346650edt.5 for ; Mon, 09 Jul 2018 02:12:49 -0700 (PDT) Received: from localhost.localdomain ([194.230.159.64]) by smtp.gmail.com with ESMTPSA id c6-v6sm6865091edt.41.2018.07.09.02.12.47 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 09 Jul 2018 02:12:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=tEfedZKczeSk2U5xtlxu0lvx3hYJMd2Wwwdtq72a6cs=; b=PQQ+bTRLi6qErPz3FPEc267VJujUNpwFQXPoLW62CuHVCDmTUXWUvmnIVIbtCjN3Vb BH9w5FkCnuEUkA2z1gvPfrm2ZLXIEH1Mspvl05lY5P+HvQtGhIfXWm/vBmEGDqZJAAAD 2kzLxbzr2+ksScytOje94W98FXUZ62TS9rzHdsBS59qgurGs0uzj0434OyWXv4hhHlct b3HCGVy3kZO9PO01bwYik+/VmpdOyRmLXgi780lrwjJ0VmNG20r/NkBU8r8LhC49vGmI wsG9RML34V03lI6RHm7OJir/LglRnQmWzwwKPztggt3hkyd8hnADFLMiuLVK+zEBqt+y gySw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=tEfedZKczeSk2U5xtlxu0lvx3hYJMd2Wwwdtq72a6cs=; b=e2gFO4NrK04FuGVKC4P/nq82YaNgSBxt+scR1han6WSornYw93mVcdOaM7e6rXTPZn de+P2feFwVSzj6Xt65Y8ByjD6ZxK7QS6uBJxrbHsMOxO/bEkeYbJBlhSNMtJ5YfhM1ng SZn8jMr5r748IufpzWTmjMENl/7mqMX6OMPLwWZngFbb2fuRTDRy1cB2zWI1l5OxBTRd HGvIqANgxS207vutgwJFuuaOwGMn4EfZeMiLPcNdMmHbaUiIu1/Zbg2izwcAZ18408Rr Ej5Wggv2RFy72doupCzxcra23Y7BX//QwPENHLT4QOOZLI0j2sAbSD40HOZEDDOYNj1r O+Ew== X-Gm-Message-State: APt69E3GRGF2U3x9F1bSBdIMFBy5B9cQGZ9xXnY1hEzR4zInom9lafpN 76uee8UxOh+CQjJnb0pN4Dg= X-Google-Smtp-Source: AAOMgpcAbtW5pwpf6l7A3yvK8h70Y7Y0XSohGQ8WFDGVOP/W//fAs+hE9YysGoF7Dvwr0+db2T3t+g== X-Received: by 2002:a50:87a8:: with SMTP id a37-v6mr21301049eda.31.1531127569003; Mon, 09 Jul 2018 02:12:49 -0700 (PDT) From: Emanuele Giuseppe Esposito To: Paolo Bonzini Date: Mon, 9 Jul 2018 11:11:32 +0200 Message-Id: <20180709091136.28849-4-e.emanuelegiuseppe@gmail.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20180709091136.28849-1-e.emanuelegiuseppe@gmail.com> References: <20180709091136.28849-1-e.emanuelegiuseppe@gmail.com> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:4864:20::543 Subject: [Qemu-devel] [PATCH 3/7] tests/qgraph: sdhci driver and interface nodes X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Laurent Vivier , Emanuele Giuseppe Esposito , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , qemu-devel@nongnu.org Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZohoMail: RDKM_2 RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" 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 --- 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 =3D $(libqos-spapr-obj-y) $(libqos-pc-= obj-y) tests/libqos/usb.o libqos-virtio-obj-y =3D $(libqos-spapr-obj-y) $(libqos-pc-obj-y) tests/lib= qos/virtio.o tests/libqos/virtio-pci.o tests/libqos/virtio-mmio.o tests/lib= qos/malloc-generic.o =20 libqgraph-obj-y =3D tests/libqos/qgraph.o +libqgraph-pc-obj-y =3D $(libqos-pc-obj-y) tests/libqos/sdhci.o =20 check-unit-y +=3D 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 + * + * 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 + */ + +#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 basecloc= k, + bool sdma, uint64_t reg) +{ + s->props.version =3D version; + s->props.baseclock =3D baseclock; + s->props.capab.sdma =3D sdma; + s->props.capab.reg =3D reg; +} + +/* Memory mapped implementation of QSDHCI */ + +static uint16_t sdhci_mm_readw(QSDHCI *s, uint32_t reg) +{ + QSDHCI_MemoryMapped *smm =3D container_of(s, QSDHCI_MemoryMapped, sdhc= i); + return qtest_readw(global_qtest, smm->addr + reg); +} + +static uint64_t sdhci_mm_readq(QSDHCI *s, uint32_t reg) +{ + QSDHCI_MemoryMapped *smm =3D container_of(s, QSDHCI_MemoryMapped, sdhc= i); + return qtest_readq(global_qtest, smm->addr + reg); +} + +static void sdhci_mm_writeq(QSDHCI *s, uint32_t reg, uint64_t val) +{ + QSDHCI_MemoryMapped *smm =3D container_of(s, QSDHCI_MemoryMapped, sdhc= i); + qtest_writeq(global_qtest, smm->addr + reg, val); +} + +static void *sdhci_mm_get_driver(void *obj, const char *interface) +{ + QSDHCI_MemoryMapped *spci =3D 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 =3D sdhci_mm_get_driver; + sdhci->sdhci.sdhci_readw =3D sdhci_mm_readw; + sdhci->sdhci.sdhci_readq =3D sdhci_mm_readq; + sdhci->sdhci.sdhci_writeq =3D sdhci_mm_writeq; + memcpy(&sdhci->sdhci.props, common, sizeof(QSDHCIProperties)); + sdhci->addr =3D addr; +} + +/* PCI implementation of QSDHCI */ + +static uint16_t sdhci_pci_readw(QSDHCI *s, uint32_t reg) +{ + QSDHCI_PCI *spci =3D 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 =3D 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 =3D 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 =3D 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 =3D g_new0(QSDHCI_PCI, 1); + QPCIBus *bus =3D pci_bus; + uint64_t barsize; + + qpci_device_init(&spci->dev, bus, QPCI_DEVFN(4, 0)); + if (bus) { + spci->mem_bar =3D qpci_iomap(&spci->dev, 0, &barsize); + } + spci->obj.get_driver =3D sdhci_pci_get_driver; + spci->obj.destructor =3D sdhci_destroy; + spci->sdhci.sdhci_readw =3D sdhci_pci_readw; + spci->sdhci.sdhci_readq =3D sdhci_readq; + spci->sdhci.sdhci_writeq =3D 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=3D04.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 + * + * 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 + */ + +#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 --=20 2.17.1