From nobody Tue Nov 4 22:03:34 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 153356627118128.872025597272795; Mon, 6 Aug 2018 07:37:51 -0700 (PDT) Received: from localhost ([::1]:34361 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fmgdp-0006wC-RF for importer@patchew.org; Mon, 06 Aug 2018 10:37:49 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:35499) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fmgar-0004kl-L6 for qemu-devel@nongnu.org; Mon, 06 Aug 2018 10:34:47 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fmgap-0000n7-La for qemu-devel@nongnu.org; Mon, 06 Aug 2018 10:34:45 -0400 Received: from mail-ed1-x543.google.com ([2a00:1450:4864:20::543]:37418) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1fmgap-0000ml-Bk for qemu-devel@nongnu.org; Mon, 06 Aug 2018 10:34:43 -0400 Received: by mail-ed1-x543.google.com with SMTP id b10-v6so5256430eds.4 for ; Mon, 06 Aug 2018 07:34:43 -0700 (PDT) Received: from localhost.localdomain ([194.230.159.126]) by smtp.gmail.com with ESMTPSA id x13-v6sm14615157edx.17.2018.08.06.07.34.41 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 06 Aug 2018 07:34:41 -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=l156AVeXs0/rkIHjw0HoXega5Crw/oWNhtQ4JeT8mi8=; b=LPY8+s4md708YIIdbSCBL5aACfI8HfN8TiEfnMwr9ptU+cLmfe/kb6jjgeT6x+a5jB NZ6FQW6Xf5bSKSWv6lVHO1ks6auQT+N0cgsrZbdNQWj3b7bVxTPxBI1+LNpcGo2cgACM s4C/9CnT5ozHVyukgkThDAVHLI1ZfaplU1bhLayVhi9V10ByTA03FNkJzjxXlCGaV+EB TSS6qdvchSwLcrDnk4hnB/GEUt5tRAlXo4ZL6+uSFDQzSeHSff9YkEd306X3q0eBWy+W JeZstt5lMEpgwx+5decN1otJ5qT/VJ816CUoZVYaAoeDqY9CzO8Mx5iGDQXLuoVxNTBP 7wcQ== 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=l156AVeXs0/rkIHjw0HoXega5Crw/oWNhtQ4JeT8mi8=; b=Wz/yisvICVENEMCTc2sRC3coDK+29OggezS0MGYp6K7MV7bMeX4abVaCeH/hIcficL vDpFbq7KyRkCDPs1HT3D8Kkqn2nMabaQV5Vh9FrD4s4d6yhL9VEzvsOHwNHuYnE4vndZ bm2xSZr0jlejVny+VAK1GM5YyjVxDg4qNmlCLWuxDm94B+8yKMvNWqlDTqQbrct34ftx noM1vu3z/q3zRc6VHGhX5tjVc6VHiV6kvQhxNKHHvnoB4j5i5fB622b/L9rNs/VfYVdf tzff9Cbory+jgEPlF2Xk/ISOcAKuflgm+/Wk8yFCLvNt4g8m3vhTQVLzWUihgcvKxPF+ iwlQ== X-Gm-Message-State: AOUpUlHxdwNM5xjtqVqZMaq9YL0ojTOYFkCOvIygg080ASvX7TP9e8yN PSV5TgnCP94pzsrVDIdeWMc= X-Google-Smtp-Source: AAOMgpdsMY/lTjzLLTO3NApKi8DpEHTY7ClX4kD5STEZRVw4VDOtlWO5Lm5DL60UZPRPNElupgV4qw== X-Received: by 2002:a50:ca83:: with SMTP id x3-v6mr18897322edh.287.1533566082318; Mon, 06 Aug 2018 07:34:42 -0700 (PDT) From: Emanuele Giuseppe Esposito To: Paolo Bonzini Date: Mon, 6 Aug 2018 16:33:43 +0200 Message-Id: <20180806143412.27722-6-e.emanuelegiuseppe@gmail.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20180806143412.27722-1-e.emanuelegiuseppe@gmail.com> References: <20180806143412.27722-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 v2 05/34] 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 , Stefan Hajnoczi , 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: RDMRC_1 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 | 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 4e7b4bb614..be00fb71ec 100644 --- a/tests/Makefile.include +++ b/tests/Makefile.include @@ -775,6 +775,7 @@ libqgraph-machines-obj-y =3D tests/libqos/x86_64_pc-mac= hine.o =20 libqgraph-pci-obj-y =3D $(libqos-pc-obj-y) libqgraph-pci-obj-y +=3D $(libqgraph-machines-obj-y) +libqgraph-pci-obj-y +=3D 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..f5eb2c5459 --- /dev/null +++ b/tests/libqos/sdhci.c @@ -0,0 +1,163 @@ +/* + * 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 "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 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_init_sdhci_mm(QSDHCI_MemoryMapped *sdhci, uint32_t addr, + QSDHCIProperties *common) +{ + sdhci->obj.get_driver =3D sdhci_mm_get_driver; + sdhci->sdhci.readw =3D sdhci_mm_readw; + sdhci->sdhci.readq =3D sdhci_mm_readq; + 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_start_hw(QOSGraphObject *obj) +{ + QSDHCI_PCI *spci =3D (QSDHCI_PCI *)obj; + qpci_device_enable(&spci->dev); +} + +static void sdhci_destroy(QOSGraphObject *obj) +{ + QSDHCI_PCI *spci =3D (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 =3D g_new0(QSDHCI_PCI, 1); + QPCIBus *bus =3D pci_bus; + uint64_t barsize; + + qpci_device_init(&spci->dev, bus, addr); + spci->mem_bar =3D qpci_iomap(&spci->dev, 0, &barsize); + spci->sdhci.readw =3D sdhci_pci_readw; + spci->sdhci.readq =3D sdhci_readq; + spci->sdhci.writeq =3D sdhci_writeq; + set_qsdhci_fields(&spci->sdhci, 2, 0, 1, 0x057834b4); + + spci->obj.get_driver =3D sdhci_pci_get_driver; + spci->obj.start_hw =3D sdhci_start_hw; + spci->obj.destructor =3D sdhci_destroy; + return &spci->obj; +} + +static void qsdhci(void) +{ + QPCIAddress addr =3D { + .devfn =3D QPCI_DEVFN(4, 0), + .vendor_id =3D PCI_VENDOR_ID_REDHAT, + .device_id =3D PCI_DEVICE_ID_REDHAT_SDHCI, + }; + + QOSGraphEdgeOptions opts =3D { + .extra_device_opts =3D "addr=3D04.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); diff --git a/tests/libqos/sdhci.h b/tests/libqos/sdhci.h new file mode 100644 index 0000000000..57e8134dee --- /dev/null +++ b/tests/libqos/sdhci.h @@ -0,0 +1,69 @@ +/* + * 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 "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_mm(): external constructor used by all drivers/machines + * that "contain" a #QSDHCI_MemoryMapped driver + */ +void qos_init_sdhci_mm(QSDHCI_MemoryMapped *sdhci, uint32_t addr, + QSDHCIProperties *common); + +#endif --=20 2.17.1