[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PULL 05/23] hw/sd/milkymist: Do not create SD card within the SD host c
From: |
Philippe Mathieu-Daudé |
Subject: |
[PULL 05/23] hw/sd/milkymist: Do not create SD card within the SD host controller |
Date: |
Fri, 21 Aug 2020 19:28:58 +0200 |
SD/MMC host controllers provide a SD Bus to plug SD cards,
but don't come with SD card plugged in :) Let the machine/board
model create and plug the SD cards when required.
Signed-off-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
Reviewed-by: Alistair Francis <alistair.francis@wdc.com>
Message-Id: <20200705211016.15241-5-f4bug@amsat.org>
---
hw/lm32/milkymist.c | 13 +++++++++
hw/sd/milkymist-memcard.c | 55 +++++++++++++++++++++++----------------
2 files changed, 45 insertions(+), 23 deletions(-)
diff --git a/hw/lm32/milkymist.c b/hw/lm32/milkymist.c
index 469e3c43225..9f8fe9fef15 100644
--- a/hw/lm32/milkymist.c
+++ b/hw/lm32/milkymist.c
@@ -34,6 +34,7 @@
#include "elf.h"
#include "milkymist-hw.h"
#include "hw/display/milkymist_tmu2.h"
+#include "hw/sd/sd.h"
#include "lm32.h"
#include "exec/address-spaces.h"
#include "qemu/cutils.h"
@@ -83,11 +84,23 @@ static void main_cpu_reset(void *opaque)
static DeviceState *milkymist_memcard_create(hwaddr base)
{
DeviceState *dev;
+ DriveInfo *dinfo;
dev = qdev_new("milkymist-memcard");
sysbus_realize_and_unref(SYS_BUS_DEVICE(dev), &error_fatal);
sysbus_mmio_map(SYS_BUS_DEVICE(dev), 0, base);
+ dinfo = drive_get_next(IF_SD);
+ if (dinfo) {
+ DeviceState *card;
+
+ card = qdev_new(TYPE_SD_CARD);
+ qdev_prop_set_drive_err(card, "drive", blk_by_legacy_dinfo(dinfo),
+ &error_fatal);
+ qdev_realize_and_unref(card, qdev_get_child_bus(dev, "sd-bus"),
+ &error_fatal);
+ }
+
return dev;
}
diff --git a/hw/sd/milkymist-memcard.c b/hw/sd/milkymist-memcard.c
index 747c5c6136b..e9f5db5e22d 100644
--- a/hw/sd/milkymist-memcard.c
+++ b/hw/sd/milkymist-memcard.c
@@ -66,6 +66,8 @@ enum {
#define MILKYMIST_MEMCARD(obj) \
OBJECT_CHECK(MilkymistMemcardState, (obj), TYPE_MILKYMIST_MEMCARD)
+#define TYPE_MILKYMIST_SDBUS "milkymist-sdbus"
+
struct MilkymistMemcardState {
SysBusDevice parent_obj;
@@ -253,6 +255,19 @@ static void milkymist_memcard_reset(DeviceState *d)
}
}
+static void milkymist_memcard_set_readonly(DeviceState *dev, bool level)
+{
+ qemu_log_mask(LOG_UNIMP,
+ "milkymist_memcard: read-only mode not supported\n");
+}
+
+static void milkymist_memcard_set_inserted(DeviceState *dev, bool level)
+{
+ MilkymistMemcardState *s = MILKYMIST_MEMCARD(dev);
+
+ s->enabled = !!level;
+}
+
static void milkymist_memcard_init(Object *obj)
{
MilkymistMemcardState *s = MILKYMIST_MEMCARD(obj);
@@ -266,27 +281,6 @@ static void milkymist_memcard_init(Object *obj)
DEVICE(obj), "sd-bus");
}
-static void milkymist_memcard_realize(DeviceState *dev, Error **errp)
-{
- MilkymistMemcardState *s = MILKYMIST_MEMCARD(dev);
- DeviceState *carddev;
- BlockBackend *blk;
- DriveInfo *dinfo;
- Error *err = NULL;
-
- /* Create and plug in the sd card */
- /* FIXME use a qdev drive property instead of drive_get_next() */
- dinfo = drive_get_next(IF_SD);
- blk = dinfo ? blk_by_legacy_dinfo(dinfo) : NULL;
- carddev = qdev_new(TYPE_SD_CARD);
- qdev_prop_set_drive(carddev, "drive", blk);
- if (!qdev_realize_and_unref(carddev, BUS(&s->sdbus), &err)) {
- error_propagate_prepend(errp, err, "failed to init SD card");
- return;
- }
- s->enabled = blk && blk_is_inserted(blk);
-}
-
static const VMStateDescription vmstate_milkymist_memcard = {
.name = "milkymist-memcard",
.version_id = 1,
@@ -308,10 +302,9 @@ static void milkymist_memcard_class_init(ObjectClass
*klass, void *data)
{
DeviceClass *dc = DEVICE_CLASS(klass);
- dc->realize = milkymist_memcard_realize;
dc->reset = milkymist_memcard_reset;
dc->vmsd = &vmstate_milkymist_memcard;
- /* Reason: init() method uses drive_get_next() */
+ /* Reason: output IRQs should be wired up */
dc->user_creatable = false;
}
@@ -323,9 +316,25 @@ static const TypeInfo milkymist_memcard_info = {
.class_init = milkymist_memcard_class_init,
};
+static void milkymist_sdbus_class_init(ObjectClass *klass, void *data)
+{
+ SDBusClass *sbc = SD_BUS_CLASS(klass);
+
+ sbc->set_inserted = milkymist_memcard_set_inserted;
+ sbc->set_readonly = milkymist_memcard_set_readonly;
+}
+
+static const TypeInfo milkymist_sdbus_info = {
+ .name = TYPE_MILKYMIST_SDBUS,
+ .parent = TYPE_SD_BUS,
+ .instance_size = sizeof(SDBus),
+ .class_init = milkymist_sdbus_class_init,
+};
+
static void milkymist_memcard_register_types(void)
{
type_register_static(&milkymist_memcard_info);
+ type_register_static(&milkymist_sdbus_info);
}
type_init(milkymist_memcard_register_types)
--
2.26.2
- [PULL 00/23] SD/MMC patches for 2020-08-21, Philippe Mathieu-Daudé, 2020/08/21
- [PULL 01/23] hw/sd/pxa2xx_mmci: Do not create SD card within the SD host controller, Philippe Mathieu-Daudé, 2020/08/21
- [PULL 02/23] hw/sd/pxa2xx_mmci: Trivial simplification, Philippe Mathieu-Daudé, 2020/08/21
- [PULL 03/23] hw/lm32/milkymist: Un-inline milkymist_memcard_create(), Philippe Mathieu-Daudé, 2020/08/21
- [PULL 04/23] hw/sd/milkymist: Create the SDBus at init(), Philippe Mathieu-Daudé, 2020/08/21
- [PULL 05/23] hw/sd/milkymist: Do not create SD card within the SD host controller,
Philippe Mathieu-Daudé <=
- [PULL 06/23] hw/sd/pl181: Replace fprintf(stderr, "*\n") with error_report(), Philippe Mathieu-Daudé, 2020/08/21
- [PULL 07/23] hw/sd/pl181: Rename pl181_send_command() as pl181_do_command(), Philippe Mathieu-Daudé, 2020/08/21
- [PULL 08/23] hw/sd/pl181: Add TODO to use Fifo32 API, Philippe Mathieu-Daudé, 2020/08/21
- [PULL 09/23] hw/sd/pl181: Use named GPIOs, Philippe Mathieu-Daudé, 2020/08/21
- [PULL 11/23] hw/sd/pl181: Do not create SD card within the SD host controller, Philippe Mathieu-Daudé, 2020/08/21
- [PULL 10/23] hw/sd/pl181: Expose a SDBus and connect the SDCard to it, Philippe Mathieu-Daudé, 2020/08/21
- [PULL 12/23] hw/sd/pl181: Replace disabled fprintf()s by trace events, Philippe Mathieu-Daudé, 2020/08/21
- [PULL 13/23] hw/sd/sdcard: Make sd_data_ready() static, Philippe Mathieu-Daudé, 2020/08/21
- [PULL 14/23] hw/sd: Move sdcard legacy API to 'hw/sd/sdcard_legacy.h', Philippe Mathieu-Daudé, 2020/08/21
- [PULL 15/23] hw/sd: Rename read/write_data() as read/write_byte(), Philippe Mathieu-Daudé, 2020/08/21