From nobody Sun Nov 9 22:39:43 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.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 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1551981407770843.5446504506352; Thu, 7 Mar 2019 09:56:47 -0800 (PST) Received: from localhost ([127.0.0.1]:56454 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1h1xG7-0007f6-LP for importer@patchew.org; Thu, 07 Mar 2019 12:56:43 -0500 Received: from eggs.gnu.org ([209.51.188.92]:39267) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1h1wqX-0002tD-GC for qemu-devel@nongnu.org; Thu, 07 Mar 2019 12:30:19 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1h1wqV-0007tD-W0 for qemu-devel@nongnu.org; Thu, 07 Mar 2019 12:30:17 -0500 Received: from mail-wr1-x42c.google.com ([2a00:1450:4864:20::42c]:35869) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1h1wqV-0007sN-Ky for qemu-devel@nongnu.org; Thu, 07 Mar 2019 12:30:15 -0500 Received: by mail-wr1-x42c.google.com with SMTP id o17so18418897wrw.3 for ; Thu, 07 Mar 2019 09:30:15 -0800 (PST) Received: from 640k.localdomain ([93.56.166.5]) by smtp.gmail.com with ESMTPSA id d206sm9979753wmc.11.2019.03.07.09.30.13 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 07 Mar 2019 09:30:13 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references; bh=MqLceWYo/1aDeyMKe7IYbzY2aLftA8ogYskRfKhqnGI=; b=e8k88tvXsG+FSgqZzM4ySSmxHyC00L6Yv/zPkd1Do6/dWBFdSArQ77x4D9kmXI6dIx G9TjjhRQaDMyUlR5YSV448JplVMEe/VZxA+FjmHKWxR38+D1kOWGXxak9hBICuHA+6J7 b0IFsyUC7LVQ5N9MDr900E/7phI00muQ/qNHkzP0zTDHsy1CchHz1lgI6FTutTA+Nph5 SL25/p0Mck6v07N9etdsEB75z/q/N3/y8L4BICl8Wo2M3UwrOjyEp1aafKQRMehsRlx4 mLAosxrrqNNzot7rWmsNrLy2NINpAnRA3BP0feJSn3Mvt44lXe2ejurV54LUeFkJSl0b cz2w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references; bh=MqLceWYo/1aDeyMKe7IYbzY2aLftA8ogYskRfKhqnGI=; b=burZA7kcZNKMxuJZq1KU/ONdYm9S3Hucckt4Wj8LXy99oTtCwcrVlWQp6rrDNebeqC qFJltWIayN+SFQYZGLig+5JAQqZPvAK5AD65iu67kKlzA5hK3vYsDgD2i9xTALM6lze9 Hu5vOFWSmvYWU8tIJnQySpjWTHHWNDnzB2W5er+d3mQHm9Xdsm1eeB7SkIvSf2ZmToIn AhCCXUVf9PBB4Oe6AmIpN2DJmQsPc+5sAJYV/wrqooV21vqCdec4F2lxoMXxLQQ4Z+p8 D8qJGoZEdCCI4FnnWMXhuAtVnU8uRq53nlPD6U99FeAj2orj0U4UHUo10H620satOiQ2 55IQ== X-Gm-Message-State: APjAAAXAgpNjiyIOeJbTQSlsiHdbiae25s51J4m72CmAFbx8t5i9Dyzy 2Ai1WLYtv4YbDz9Et21nAqGjSBEs X-Google-Smtp-Source: APXvYqzXJxvAs3RX/58ObVDKhnHzkJlrCRwGep7UmJJQB+YgZvWevdtknhHwotkJLWbuMIvvd+FerQ== X-Received: by 2002:a5d:4145:: with SMTP id c5mr7586776wrq.256.1551979814233; Thu, 07 Mar 2019 09:30:14 -0800 (PST) From: Paolo Bonzini To: qemu-devel@nongnu.org Date: Thu, 7 Mar 2019 18:29:15 +0100 Message-Id: <1551979804-6060-9-git-send-email-pbonzini@redhat.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1551979804-6060-1-git-send-email-pbonzini@redhat.com> References: <1551979804-6060-1-git-send-email-pbonzini@redhat.com> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:4864:20::42c Subject: [Qemu-devel] [PULL 08/57] tests/libqos: 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: thuth@redhat.com, Emanuele Giuseppe Esposito , lviver@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" From: Emanuele Giuseppe Esposito 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 Signed-off-by: Paolo Bonzini --- tests/Makefile.include | 1 + tests/libqos/sdhci.c | 163 +++++++++++++++++++++++++++++++++++++++++++++= ++++ tests/libqos/sdhci.h | 70 +++++++++++++++++++++ 3 files changed, 234 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 8a760bd..b1b03e6 100644 --- a/tests/Makefile.include +++ b/tests/Makefile.include @@ -752,6 +752,7 @@ libqos-virtio-obj-y =3D $(libqos-spapr-obj-y) $(libqos-= pc-obj-y) tests/libqos/virt # Devices qos-test-obj-y =3D tests/qos-test.o $(libqgraph-obj-y) qos-test-obj-y +=3D $(libqos-pc-obj-y) +qos-test-obj-y +=3D tests/libqos/sdhci.o =20 # Machines qos-test-obj-y +=3D tests/libqos/x86_64_pc-machine.o diff --git a/tests/libqos/sdhci.c b/tests/libqos/sdhci.c new file mode 100644 index 0000000..22c33de --- /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(smm->qts, 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(smm->qts, 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(smm->qts, 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_mm(QSDHCI_MemoryMapped *sdhci, QTestState *qts, + 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; + sdhci->qts =3D qts; +} + +/* 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); +} + +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 0000000..032d815 --- /dev/null +++ b/tests/libqos/sdhci.h @@ -0,0 +1,70 @@ +/* + * 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; + QTestState *qts; + 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, QTestState *qts, + uint32_t addr, QSDHCIProperties *common); + +#endif --=20 1.8.3.1