From nobody Fri Oct 24 20:17:15 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 Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 151874852322510.482799187824071; Thu, 15 Feb 2018 18:35:23 -0800 (PST) Received: from localhost ([::1]:57332 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1emVru-0001WZ-DX for importer@patchew.org; Thu, 15 Feb 2018 21:35:22 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:60385) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1emVmv-0005dp-RD for qemu-devel@nongnu.org; Thu, 15 Feb 2018 21:30:15 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1emVms-0002b8-MQ for qemu-devel@nongnu.org; Thu, 15 Feb 2018 21:30:13 -0500 Received: from mail-vk0-x241.google.com ([2607:f8b0:400c:c05::241]:41771) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1emVms-0002ah-Hp; Thu, 15 Feb 2018 21:30:10 -0500 Received: by mail-vk0-x241.google.com with SMTP id t201so1060403vke.8; Thu, 15 Feb 2018 18:30:10 -0800 (PST) Received: from x1.lan ([138.117.48.219]) by smtp.gmail.com with ESMTPSA id q5sm6295200uaj.17.2018.02.15.18.30.05 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 15 Feb 2018 18:30:09 -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 :mime-version:content-transfer-encoding; bh=bQ/WLf/gj3SLLZYXbCfd+kVPfJ6iBrMRkq8+ucUmfU8=; b=s7Z05+7lvk8Gqhk/VR/PQCnNMXhvIB/SAjtzM9zbEy1aFWUXgvR0z7i2Z5WkrkRKnl BsWm563T3FiWnBccgSC5b8o5+p3xRTUWh0l0CB8aR/XIDqqsBarkIwQtJji3J9Ekqn5p BE6EK4E60j98ImPT8T4UA2OHY4fmyIiZnlYIx+URcQgQDX7EjDBwkkUOcOVu+w4TN1SY N7run7+mdamp1hpZAaOY+wVq8Cys7VzX8H4MY6L91e1U9bMW7Ch95H2vAg8PfPfe504V +ijnHTe88Z9dM8lz7g4XMFQH2GZE0A6bh9Diezuojak3RzEdZazYGM1wHj8yoyvj+7aF 1s2w== 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:mime-version:content-transfer-encoding; bh=bQ/WLf/gj3SLLZYXbCfd+kVPfJ6iBrMRkq8+ucUmfU8=; b=dQx6/dXYCb4PYZtF+KOt6gHqHp5KMWF5MOrhyh4vHqa7Y8GxDGmVInghaMnRfP+iyH BLYqSvWKYYc6TI+IPWtIgKN/KExJavrsL6FzHnwBzypsoD7splA6yaCNt5IwvSuMRyes 88SkhzcFTtODIGaaPMAGY4HAT7UDFYrhtkSBW6B3ZhiJgFi5y9R7WQkkmanN+H/gbo/i JtFrXTyX9m9O6tO8JuU6v77V2KJ96+jynIna4FM9ugWR4H6wNXa9ZFhhNqhpMwv9xDhC JmT137xdUUibbXbom97EIfZ3TScc7noEZHWIiJvgA7NRZtsHuIpVpBFoXWjxqSAW4r9v fNtw== X-Gm-Message-State: APf1xPB+QK1c7LU7uLryVXmnYr3cRjjRdR5Y/l1aLk/8K3rSRYcoHTAt lx4Mp0ffJvw5Qecg1pEQIXw= X-Google-Smtp-Source: AH8x227a4gANwSylKI8ITpXqBn2XKVPg5hW5CI0XHF2I8nykhvY4b73OPfwxgklXVrTAXduXycv0Wg== X-Received: by 10.31.199.198 with SMTP id x189mr3627801vkf.154.1518748209977; Thu, 15 Feb 2018 18:30:09 -0800 (PST) From: =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= To: Alistair Francis , Peter Maydell , Eduardo Habkost , =?UTF-8?q?Andreas=20F=C3=A4rber?= Date: Thu, 15 Feb 2018 23:29:30 -0300 Message-Id: <20180216022933.10945-6-f4bug@amsat.org> X-Mailer: git-send-email 2.16.1 In-Reply-To: <20180216022933.10945-1-f4bug@amsat.org> References: <20180216022933.10945-1-f4bug@amsat.org> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:400c:c05::241 Subject: [Qemu-devel] [RFC PATCH v3 5/7] hw/sd/pl181: expose a SDBus and connect the SDCard to it 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: "Edgar E . Iglesias" , Stefan Weil , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , qemu-devel@nongnu.org, Michael Walle , "open list:ARM PrimeCell and..." 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 using the sdbus_*() API. Signed-off-by: Philippe Mathieu-Daud=C3=A9 --- RFC because how pl181_sdbus_create_inplace() doing class_init(SDBus) in realize(pl181) seems weird... from http://lists.nongnu.org/archive/html/qemu-devel/2018-02/msg01268.html: I think you have to change that sd_set_cb() code now. If you look at sd_cardchange() it uses "is this SD card object on an SDBus" to determine whether to notify the controller via the old-API IRQ lines, or using the set_inserted() and set_readonly() callbacks on the SDBusClass. This previous series intended to enforce a cleaner OOP design, adding a TYPE_SD_BUS_MASTER_INTERFACE TypeInfo: http://lists.nongnu.org/archive/html/qemu-devel/2017-12/msg02322.html http://lists.nongnu.org/archive/html/qemu-devel/2017-12/msg02326.html http://lists.nongnu.org/archive/html/qemu-devel/2017-12/msg02327.html --- hw/sd/pl181.c | 59 ++++++++++++++++++++++++++++++++++++++++++++-----------= ---- 1 file changed, 44 insertions(+), 15 deletions(-) diff --git a/hw/sd/pl181.c b/hw/sd/pl181.c index 3ba1f7dd23..97e85e4a64 100644 --- a/hw/sd/pl181.c +++ b/hw/sd/pl181.c @@ -33,7 +33,7 @@ typedef struct PL181State { SysBusDevice parent_obj; =20 MemoryRegion iomem; - SDState *card; + SDBus sdbus; uint32_t clock; uint32_t power; uint32_t cmdarg; @@ -179,7 +179,7 @@ static void pl181_send_command(PL181State *s) request.cmd =3D s->cmd & PL181_CMD_INDEX; request.arg =3D s->cmdarg; DPRINTF("Command %d %08x\n", request.cmd, request.arg); - rlen =3D sd_do_command(s->card, &request, response); + rlen =3D sdbus_do_command(&s->sdbus, &request, response); if (rlen < 0) goto error; if (s->cmd & PL181_CMD_RESPONSE) { @@ -223,12 +223,12 @@ static void pl181_fifo_run(PL181State *s) int is_read; =20 is_read =3D (s->datactrl & PL181_DATA_DIRECTION) !=3D 0; - if (s->datacnt !=3D 0 && (!is_read || sd_data_ready(s->card)) + if (s->datacnt !=3D 0 && (!is_read || sdbus_data_ready(&s->sdbus)) && !s->linux_hack) { if (is_read) { n =3D 0; while (s->datacnt && s->fifo_len < PL181_FIFO_LEN) { - value |=3D (uint32_t)sd_read_data(s->card) << (n * 8); + value |=3D (uint32_t)sdbus_read_data(&s->sdbus) << (n * 8); s->datacnt--; n++; if (n =3D=3D 4) { @@ -249,7 +249,7 @@ static void pl181_fifo_run(PL181State *s) } n--; s->datacnt--; - sd_write_data(s->card, value & 0xff); + sdbus_write_data(&s->sdbus, value & 0xff); value >>=3D 8; } } @@ -477,13 +477,6 @@ static void pl181_reset(DeviceState *d) s->linux_hack =3D 0; s->mask[0] =3D 0; s->mask[1] =3D 0; - - /* We can assume our GPIO outputs have been wired up now */ - sd_set_cb(s->card, s->cardstatus[0], s->cardstatus[1]); - /* Since we're still using the legacy SD API the card is not plugged - * into any bus, and we must reset it manually. - */ - device_reset(DEVICE(s->card)); } =20 static void pl181_init(Object *obj) @@ -499,16 +492,52 @@ static void pl181_init(Object *obj) qdev_init_gpio_out(dev, s->cardstatus, 2); } =20 +static void pl181_set_readonly(DeviceState *dev, bool level) +{ + PL181State *s =3D (PL181State *)dev; + + qemu_set_irq(s->cardstatus[0], level); +} + +static void pl181_set_inserted(DeviceState *dev, bool level) +{ + PL181State *s =3D (PL181State *)dev; + + qemu_set_irq(s->cardstatus[1], level); +} + +static void pl181_sdbus_create_inplace(SDBus *sdbus, DeviceState *dev) +{ + SDBusClass *sbc; + + qbus_create_inplace(sdbus, sizeof(SDBus), TYPE_SD_BUS, dev, "sd-bus"); + + /* pl181_sdbus_class_init */ + sbc =3D SD_BUS_GET_CLASS(sdbus); + sbc->set_inserted =3D pl181_set_inserted; + sbc->set_readonly =3D pl181_set_readonly; +} + static void pl181_realize(DeviceState *dev, Error **errp) { PL181State *s =3D PL181(dev); + DeviceState *carddev; DriveInfo *dinfo; + Error *err =3D NULL; + + pl181_sdbus_create_inplace(&s->sdbus, dev); =20 + /* Create and plug in the sd card */ /* FIXME use a qdev drive property instead of drive_get_next() */ dinfo =3D drive_get_next(IF_SD); - s->card =3D sd_init(dinfo ? blk_by_legacy_dinfo(dinfo) : NULL, false); - if (s->card =3D=3D NULL) { - error_setg(errp, "sd_init failed"); + carddev =3D qdev_create(&s->sdbus.qbus, TYPE_SD_CARD); + if (dinfo) { + qdev_prop_set_drive(carddev, "drive", blk_by_legacy_dinfo(dinfo), = &err); + } + object_property_set_bool(OBJECT(carddev), true, "realized", &err); + if (err) { + error_setg(errp, "failed to init SD card: %s", error_get_pretty(er= r)); + return; } } =20 --=20 2.16.1