From nobody Wed Nov 5 10:47:37 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 1534155656143539.8338180834214; Mon, 13 Aug 2018 03:20:56 -0700 (PDT) Received: from localhost ([::1]:38514 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fp9xp-0002LL-GR for importer@patchew.org; Mon, 13 Aug 2018 06:20:41 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:43437) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fp9sb-00077Z-3e for qemu-devel@nongnu.org; Mon, 13 Aug 2018 06:15:19 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fp9sZ-0001xP-Cv for qemu-devel@nongnu.org; Mon, 13 Aug 2018 06:15:17 -0400 Received: from mail-ed1-x544.google.com ([2a00:1450:4864:20::544]:41403) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1fp9sY-0001uc-Dr; Mon, 13 Aug 2018 06:15:14 -0400 Received: by mail-ed1-x544.google.com with SMTP id s24-v6so7939381edr.8; Mon, 13 Aug 2018 03:15:14 -0700 (PDT) Received: from localhost.localdomain ([194.230.159.125]) by smtp.gmail.com with ESMTPSA id s27-v6sm11670006edb.73.2018.08.13.03.15.11 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 13 Aug 2018 03:15:12 -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=WlSI3ImPlyKg7z4GwTrnSntEVmmweg+FJXMvSzaRRK8=; b=kdmBnzazcSXgatKzJY2jCsgp/bV9ahhnO1EdvhHhBZVCCgm0hr+25Kv1p/jJnpYgi4 +uj0IHcnWfJOn+mlz8l+z4BQ4DJVPq+PZ/kJ3Db9TzaIpbJEr3bBZF22EGsYjTXg2pen 9a8QVPfVK6LF+5PK6/MuC82RPAKseOOt1UmfzWCIetLMRxw8zR7u90pMJbLvwVs+rTv1 97sehBtvwoMWJg1TlCtQq/a6CCAqiPa4IH/3ii3zOVfisV6qI/DWC9WliaJ5zz4icGtK XIvYzuBILg8aP/yUxFILuDP+FZLVWlCrfcGde/T56MUqiuLLoJ4eYEhOd3o+SISfTkVm O/gA== 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=WlSI3ImPlyKg7z4GwTrnSntEVmmweg+FJXMvSzaRRK8=; b=fryusJmxC3SlIhM5U3nN7HFVcr2nunK264O464Ql63Dh83RJVSif4W4ujyxNrDrG1m 9kNh6DOy8Mxrs01IjFyrDY/b4MjNMP0Of3r3zLxSx301BcRii9fes8Hynn2qY1zZGfaa 3BsOD3+eQbqleOqKkrEhOpFFo9VxTFFgUihnjsDoMdBgAqLQ9elRuBfBHtP7K9s/rW/C KrFtpxzl0tOqFliO0tXonlPUvv7x0396XyWxntxcQLLyBWL9Pv82svpvqwlJNGuAjaiU I3A4Zlr9QWfV8N0c9tY6/apNNy/Hr5E3wiikaC2jazG0CBuftgEr5i8PcTVSqoOrLfPF Qjig== X-Gm-Message-State: AOUpUlGMZ+4AA6KEoV1nX5+RdV4GFoMMpjAqzgQh6SHudoHy7AKPrg/B Qm1Ex/IhwqYXEEt3zQ+0pOD/L1ia6DU= X-Google-Smtp-Source: AA+uWPyEI4rKW960TvnfTVGbAA+wJFBE8V3Y9IpBElYMPceJHzkXM9r6r+6mFO5ujcBzRxjImjIscQ== X-Received: by 2002:aa7:d91a:: with SMTP id a26-v6mr21881197edr.102.1534155313035; Mon, 13 Aug 2018 03:15:13 -0700 (PDT) From: Emanuele Giuseppe Esposito To: qemu-devel@nongnu.org Date: Mon, 13 Aug 2018 12:14:25 +0200 Message-Id: <20180813101453.10200-6-e.emanuelegiuseppe@gmail.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20180813101453.10200-1-e.emanuelegiuseppe@gmail.com> References: <20180813101453.10200-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::544 Subject: [Qemu-devel] [PATCH 05/33] 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 , Fam Zheng , qemu-block@nongnu.org, "Michael S. Tsirkin" , Jason Wang , Amit Shah , Emanuele Giuseppe Esposito , Alexander Graf , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Greg Kurz , qemu-ppc@nongnu.org, Gerd Hoffmann , Stefan Hajnoczi , Paolo Bonzini , John Snow , David Gibson 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 2154e53944..90a74854b8 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..65b407d741 --- /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 *smm =3D 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 =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_pci_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_pci_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; + } + + 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 =3D (QSDHCI_PCI *)obj; + qpci_device_enable(&spci->dev); +} + +static void sdhci_destructor(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_pci_readq; + spci->sdhci.writeq =3D sdhci_pci_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_pci_start_hw; + spci->obj.destructor =3D sdhci_destructor; + return &spci->obj; +} + +static void qsdhci_register_nodes(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_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 + * + * 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_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 --=20 2.17.1