From: "Philippe Mathieu-Daudé" <f4bug@amsat.org>
To: "Alistair Francis" <alistair.francis@xilinx.com>,
"Peter Maydell" <peter.maydell@linaro.org>,
"Eduardo Habkost" <ehabkost@redhat.com>,
"Andreas Färber" <afaerber@suse.de>
Cc: "Philippe Mathieu-Daudé" <f4bug@amsat.org>,
qemu-devel@nongnu.org,
"Edgar E . Iglesias" <edgar.iglesias@xilinx.com>,
"Andrzej Zaborowski" <balrogg@gmail.com>,
"Michael Walle" <michael@walle.cc>,
"Stefan Weil" <sw@weilnetz.de>,
"open list:ARM PrimeCell and..." <qemu-arm@nongnu.org>
Subject: [Qemu-devel] [RFC PATCH v3 5/7] hw/sd/pl181: expose a SDBus and connect the SDCard to it
Date: Thu, 15 Feb 2018 23:29:30 -0300 [thread overview]
Message-ID: <20180216022933.10945-6-f4bug@amsat.org> (raw)
In-Reply-To: <20180216022933.10945-1-f4bug@amsat.org>
using the sdbus_*() API.
Signed-off-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
---
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;
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 = s->cmd & PL181_CMD_INDEX;
request.arg = s->cmdarg;
DPRINTF("Command %d %08x\n", request.cmd, request.arg);
- rlen = sd_do_command(s->card, &request, response);
+ rlen = 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;
is_read = (s->datactrl & PL181_DATA_DIRECTION) != 0;
- if (s->datacnt != 0 && (!is_read || sd_data_ready(s->card))
+ if (s->datacnt != 0 && (!is_read || sdbus_data_ready(&s->sdbus))
&& !s->linux_hack) {
if (is_read) {
n = 0;
while (s->datacnt && s->fifo_len < PL181_FIFO_LEN) {
- value |= (uint32_t)sd_read_data(s->card) << (n * 8);
+ value |= (uint32_t)sdbus_read_data(&s->sdbus) << (n * 8);
s->datacnt--;
n++;
if (n == 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 >>= 8;
}
}
@@ -477,13 +477,6 @@ static void pl181_reset(DeviceState *d)
s->linux_hack = 0;
s->mask[0] = 0;
s->mask[1] = 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));
}
static void pl181_init(Object *obj)
@@ -499,16 +492,52 @@ static void pl181_init(Object *obj)
qdev_init_gpio_out(dev, s->cardstatus, 2);
}
+static void pl181_set_readonly(DeviceState *dev, bool level)
+{
+ PL181State *s = (PL181State *)dev;
+
+ qemu_set_irq(s->cardstatus[0], level);
+}
+
+static void pl181_set_inserted(DeviceState *dev, bool level)
+{
+ PL181State *s = (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 = SD_BUS_GET_CLASS(sdbus);
+ sbc->set_inserted = pl181_set_inserted;
+ sbc->set_readonly = pl181_set_readonly;
+}
+
static void pl181_realize(DeviceState *dev, Error **errp)
{
PL181State *s = PL181(dev);
+ DeviceState *carddev;
DriveInfo *dinfo;
+ Error *err = NULL;
+
+ pl181_sdbus_create_inplace(&s->sdbus, dev);
+ /* Create and plug in the sd card */
/* FIXME use a qdev drive property instead of drive_get_next() */
dinfo = drive_get_next(IF_SD);
- s->card = sd_init(dinfo ? blk_by_legacy_dinfo(dinfo) : NULL, false);
- if (s->card == NULL) {
- error_setg(errp, "sd_init failed");
+ carddev = 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(err));
+ return;
}
}
--
2.16.1
next prev parent reply other threads:[~2018-02-16 2:30 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-02-16 2:29 [Qemu-devel] [PATCH v3 0/7] SDHCI: convert legacy devices to the SDBus API (part 6) Philippe Mathieu-Daudé
2018-02-16 2:29 ` [Qemu-devel] [PATCH v3 1/7] hw/sd/milkymist-memcard: use qemu_log_mask() Philippe Mathieu-Daudé
2018-02-16 2:29 ` [Qemu-devel] [PATCH v3 2/7] hw/sd/milkymist-memcard: split realize() out of SysBusDevice init() Philippe Mathieu-Daudé
2018-02-16 2:29 ` [Qemu-devel] [PATCH v3 3/7] hw/sd/milkymist-memcard: expose a SDBus and connect the SDCard to it Philippe Mathieu-Daudé
2018-02-16 2:29 ` [Qemu-devel] [PATCH v3 4/7] hw/sd/ssi-sd: use the SDBus API, connect the SDCard to the bus Philippe Mathieu-Daudé
2018-02-16 2:29 ` Philippe Mathieu-Daudé [this message]
2018-02-22 9:06 ` [Qemu-devel] [RFC PATCH v3 5/7] hw/sd/pl181: expose a SDBus and connect the SDCard to it Philippe Mathieu-Daudé
2018-02-22 11:46 ` Peter Maydell
2018-02-16 2:29 ` [Qemu-devel] [PATCH v3 6/7] hw/sd: make sd_data_ready() static Philippe Mathieu-Daudé
2018-02-16 21:02 ` Alistair Francis
2018-02-16 2:29 ` [Qemu-devel] [PATCH v3 7/7] hw/sd: move sdcard legacy API to "hw/sd/sdcard_legacy.h" Philippe Mathieu-Daudé
2018-02-16 21:04 ` Alistair Francis
2018-02-22 11:47 ` [Qemu-devel] [PATCH v3 0/7] SDHCI: convert legacy devices to the SDBus API (part 6) Peter Maydell
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20180216022933.10945-6-f4bug@amsat.org \
--to=f4bug@amsat.org \
--cc=afaerber@suse.de \
--cc=alistair.francis@xilinx.com \
--cc=balrogg@gmail.com \
--cc=edgar.iglesias@xilinx.com \
--cc=ehabkost@redhat.com \
--cc=michael@walle.cc \
--cc=peter.maydell@linaro.org \
--cc=qemu-arm@nongnu.org \
--cc=qemu-devel@nongnu.org \
--cc=sw@weilnetz.de \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).