From: "Philippe Mathieu-Daudé" <philmd@linaro.org>
To: qemu-devel@nongnu.org
Cc: "Richard Henderson" <richard.henderson@linaro.org>,
"Daniel P . Berrange" <berrange@redhat.com>,
"Eduardo Habkost" <eduardo@habkost.net>,
"Alistair Francis" <alistair@alistair23.me>,
"Paolo Bonzini" <pbonzini@redhat.com>,
"Anton Johansson" <anjo@rev.ng>,
"Edgar E . Iglesias" <edgar.iglesias@gmail.com>,
"Markus Armbruster" <armbru@redhat.com>,
"Alex Bennée" <alex.bennee@linaro.org>,
"Cédric Le Goater" <clg@kaod.org>,
"Mark Cave-Ayland" <mark.cave-ayland@ilande.co.uk>,
"Bernhard Beschow" <shentey@gmail.com>,
"Peter Maydell" <peter.maydell@linaro.org>,
"Alessandro Di Federico" <ale@rev.ng>,
qemu-arm@nongnu.org, "Luc Michel" <luc@lmichel.fr>,
"Philippe Mathieu-Daudé" <philmd@linaro.org>
Subject: [PATCH 1/2] hw/sd/omap_mmc: Do not reset SDCard until being fully realized
Date: Mon, 18 Sep 2023 12:17:35 +0200 [thread overview]
Message-ID: <20230918101736.23905-2-philmd@linaro.org> (raw)
In-Reply-To: <20230918101736.23905-1-philmd@linaro.org>
We shouldn't call QDev DeviceReset() before DeviceRealize().
Since the OMAP MMC model is not QDev'ified, it has to manually
call the SDCard reset() handler. This breaks QDev assumptions
that DeviceReset() is never called before a device is fully
realized. In order to avoid that, pass a 'realized' argument
to omap_mmc_reset(). All cases are explicit manual resets,
except in omap_mmc_write() where we expect the sdcard to be
realized.
Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
---
include/hw/arm/omap.h | 2 +-
hw/arm/omap1.c | 2 +-
hw/arm/omap2.c | 2 +-
hw/sd/omap_mmc.c | 21 ++++++++++++---------
4 files changed, 15 insertions(+), 12 deletions(-)
diff --git a/include/hw/arm/omap.h b/include/hw/arm/omap.h
index 067e9419f7..d331467946 100644
--- a/include/hw/arm/omap.h
+++ b/include/hw/arm/omap.h
@@ -808,7 +808,7 @@ struct omap_mmc_s *omap_mmc_init(hwaddr base,
struct omap_mmc_s *omap2_mmc_init(struct omap_target_agent_s *ta,
BlockBackend *blk, qemu_irq irq, qemu_irq dma[],
omap_clk fclk, omap_clk iclk);
-void omap_mmc_reset(struct omap_mmc_s *s);
+void omap_mmc_reset(struct omap_mmc_s *s, bool realized);
void omap_mmc_handlers(struct omap_mmc_s *s, qemu_irq ro, qemu_irq cover);
void omap_mmc_enable(struct omap_mmc_s *s, int enable);
diff --git a/hw/arm/omap1.c b/hw/arm/omap1.c
index d5438156ee..3afeba6f86 100644
--- a/hw/arm/omap1.c
+++ b/hw/arm/omap1.c
@@ -3728,7 +3728,7 @@ static void omap1_mpu_reset(void *opaque)
omap_uart_reset(mpu->uart[0]);
omap_uart_reset(mpu->uart[1]);
omap_uart_reset(mpu->uart[2]);
- omap_mmc_reset(mpu->mmc);
+ omap_mmc_reset(mpu->mmc, false);
omap_mpuio_reset(mpu->mpuio);
omap_uwire_reset(mpu->microwire);
omap_pwl_reset(mpu->pwl);
diff --git a/hw/arm/omap2.c b/hw/arm/omap2.c
index d5a2ae7af6..ef9b0dd60a 100644
--- a/hw/arm/omap2.c
+++ b/hw/arm/omap2.c
@@ -2253,7 +2253,7 @@ static void omap2_mpu_reset(void *opaque)
omap_uart_reset(mpu->uart[0]);
omap_uart_reset(mpu->uart[1]);
omap_uart_reset(mpu->uart[2]);
- omap_mmc_reset(mpu->mmc);
+ omap_mmc_reset(mpu->mmc, false);
omap_mcspi_reset(mpu->mcspi[0]);
omap_mcspi_reset(mpu->mcspi[1]);
cpu_reset(CPU(mpu->cpu));
diff --git a/hw/sd/omap_mmc.c b/hw/sd/omap_mmc.c
index edd3cf2a1e..3c906993eb 100644
--- a/hw/sd/omap_mmc.c
+++ b/hw/sd/omap_mmc.c
@@ -287,7 +287,7 @@ static void omap_mmc_pseudo_reset(struct omap_mmc_s *host)
host->fifo_len = 0;
}
-void omap_mmc_reset(struct omap_mmc_s *host)
+void omap_mmc_reset(struct omap_mmc_s *host, bool realized)
{
host->last_cmd = 0;
memset(host->rsp, 0, sizeof(host->rsp));
@@ -314,11 +314,14 @@ void omap_mmc_reset(struct omap_mmc_s *host)
omap_mmc_pseudo_reset(host);
- /* Since we're still using the legacy SD API the card is not plugged
- * into any bus, and we must reset it manually. When omap_mmc is
- * QOMified this must move into the QOM reset function.
- */
- device_cold_reset(DEVICE(host->card));
+ if (realized) {
+ /*
+ * Since we're still using the legacy SD API the card is not plugged
+ * into any bus, and we must reset it manually. When omap_mmc is
+ * QOMified this must move into the QOM reset function.
+ */
+ device_cold_reset(DEVICE(host->card));
+ }
}
static uint64_t omap_mmc_read(void *opaque, hwaddr offset, unsigned size)
@@ -556,7 +559,7 @@ static void omap_mmc_write(void *opaque, hwaddr offset,
break;
case 0x64: /* MMC_SYSC */
if (value & (1 << 2)) /* SRTS */
- omap_mmc_reset(s);
+ omap_mmc_reset(s, true);
break;
case 0x68: /* MMC_SYSS */
OMAP_RO_REG(offset);
@@ -613,7 +616,7 @@ struct omap_mmc_s *omap_mmc_init(hwaddr base,
exit(1);
}
- omap_mmc_reset(s);
+ omap_mmc_reset(s, false);
return s;
}
@@ -643,7 +646,7 @@ struct omap_mmc_s *omap2_mmc_init(struct omap_target_agent_s *ta,
s->cdet = qemu_allocate_irq(omap_mmc_cover_cb, s, 0);
sd_set_cb(s->card, NULL, s->cdet);
- omap_mmc_reset(s);
+ omap_mmc_reset(s, false);
return s;
}
--
2.41.0
next prev parent reply other threads:[~2023-09-18 10:18 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-09-18 10:17 [PATCH 0/2] qdev: Ensure devices are fully realized when calling DeviceReset handler Philippe Mathieu-Daudé
2023-09-18 10:17 ` Philippe Mathieu-Daudé [this message]
2023-09-18 11:00 ` [PATCH 1/2] hw/sd/omap_mmc: Do not reset SDCard until being fully realized Peter Maydell
2023-09-18 15:22 ` Philippe Mathieu-Daudé
2023-09-18 10:17 ` [PATCH 2/2] qdev: Ensure devices are fully realized when calling DeviceReset handler Philippe Mathieu-Daudé
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=20230918101736.23905-2-philmd@linaro.org \
--to=philmd@linaro.org \
--cc=ale@rev.ng \
--cc=alex.bennee@linaro.org \
--cc=alistair@alistair23.me \
--cc=anjo@rev.ng \
--cc=armbru@redhat.com \
--cc=berrange@redhat.com \
--cc=clg@kaod.org \
--cc=edgar.iglesias@gmail.com \
--cc=eduardo@habkost.net \
--cc=luc@lmichel.fr \
--cc=mark.cave-ayland@ilande.co.uk \
--cc=pbonzini@redhat.com \
--cc=peter.maydell@linaro.org \
--cc=qemu-arm@nongnu.org \
--cc=qemu-devel@nongnu.org \
--cc=richard.henderson@linaro.org \
--cc=shentey@gmail.com \
/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).