* [Qemu-devel] [PATCH 0/2] sdhci: Implement device reset
@ 2016-02-26 13:24 Peter Maydell
2016-02-26 13:24 ` [Qemu-devel] [PATCH 1/2] sd.c: Handle NULL block backend in sd_get_inserted() Peter Maydell
2016-02-26 13:24 ` [Qemu-devel] [PATCH 2/2] sdhci: Implement DeviceClass reset Peter Maydell
0 siblings, 2 replies; 5+ messages in thread
From: Peter Maydell @ 2016-02-26 13:24 UTC (permalink / raw)
To: qemu-devel
Cc: Peter Crosthwaite, patches, Andrew Baumann, Alistair Francis,
qemu-arm, Edgar E. Iglesias
This patchset implements the DeviceClass reset method for
the sdhci devices, so that on QEMU system reset they are
reset. (Mostly guests didn't notice this was missing I
think because they tend to do a commanded reset via the
device register as part of driver initialization.)
For the reset patch to work and not crash QEMU on startup,
we need to fix a missing NULL pointer check in sd.c's
sd_get_inserted() function.
These patchsets apply on top of Andrew's rpi quirk
patchset which is in target-arm.next.
Review/testing appreciated.
Peter Maydell (2):
sd.c: Handle NULL block backend in sd_get_inserted()
sdhci: Implement DeviceClass reset
hw/sd/sd.c | 2 +-
hw/sd/sdhci.c | 21 +++++++++++++++++----
2 files changed, 18 insertions(+), 5 deletions(-)
--
1.9.1
^ permalink raw reply [flat|nested] 5+ messages in thread
* [Qemu-devel] [PATCH 1/2] sd.c: Handle NULL block backend in sd_get_inserted()
2016-02-26 13:24 [Qemu-devel] [PATCH 0/2] sdhci: Implement device reset Peter Maydell
@ 2016-02-26 13:24 ` Peter Maydell
2016-02-26 22:35 ` Alistair Francis
2016-02-26 13:24 ` [Qemu-devel] [PATCH 2/2] sdhci: Implement DeviceClass reset Peter Maydell
1 sibling, 1 reply; 5+ messages in thread
From: Peter Maydell @ 2016-02-26 13:24 UTC (permalink / raw)
To: qemu-devel
Cc: Peter Crosthwaite, patches, Andrew Baumann, Alistair Francis,
qemu-arm, Edgar E. Iglesias
The sd.c SD card emulation code can be in a state where the
SDState BlockBackend pointer is NULL; this is treated as
"card not present". Add a missing check to sd_get_inserted()
so that we don't segfault in this situation.
(This could be provoked by the guest writing to the SDHCI
register to do a reset on a xilinx-zynq-a9 board; it will
also happen at startup when sdhci implements its DeviceClass
reset method.)
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
---
hw/sd/sd.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/hw/sd/sd.c b/hw/sd/sd.c
index edb6b32..00c320d 100644
--- a/hw/sd/sd.c
+++ b/hw/sd/sd.c
@@ -449,7 +449,7 @@ static void sd_reset(DeviceState *dev)
static bool sd_get_inserted(SDState *sd)
{
- return blk_is_inserted(sd->blk);
+ return sd->blk && blk_is_inserted(sd->blk);
}
static bool sd_get_readonly(SDState *sd)
--
1.9.1
^ permalink raw reply related [flat|nested] 5+ messages in thread
* [Qemu-devel] [PATCH 2/2] sdhci: Implement DeviceClass reset
2016-02-26 13:24 [Qemu-devel] [PATCH 0/2] sdhci: Implement device reset Peter Maydell
2016-02-26 13:24 ` [Qemu-devel] [PATCH 1/2] sd.c: Handle NULL block backend in sd_get_inserted() Peter Maydell
@ 2016-02-26 13:24 ` Peter Maydell
2016-02-26 17:47 ` Andrew Baumann
1 sibling, 1 reply; 5+ messages in thread
From: Peter Maydell @ 2016-02-26 13:24 UTC (permalink / raw)
To: qemu-devel
Cc: Peter Crosthwaite, patches, Andrew Baumann, Alistair Francis,
qemu-arm, Edgar E. Iglesias
The sdhci device was missing a DeviceClass reset method;
implement it. Poweron reset looks the same as reset commanded
by the guest via the device registers, apart from modelling of
the rpi 'pending insert interrupt on powerup' quirk.
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
---
hw/sd/sdhci.c | 21 +++++++++++++++++----
1 file changed, 17 insertions(+), 4 deletions(-)
diff --git a/hw/sd/sdhci.c b/hw/sd/sdhci.c
index e087c17..d28b587 100644
--- a/hw/sd/sdhci.c
+++ b/hw/sd/sdhci.c
@@ -207,6 +207,21 @@ static void sdhci_reset(SDHCIState *s)
s->pending_insert_state = false;
}
+static void sdhci_poweron_reset(DeviceState *dev)
+{
+ /* QOM (ie power-on) reset. This is identical to reset
+ * commanded via device register apart from handling of the
+ * 'pending insert on powerup' quirk.
+ */
+ SDHCIState *s = (SDHCIState *)dev;
+
+ sdhci_reset(s);
+
+ if (s->pending_insert_quirk) {
+ s->pending_insert_state = true;
+ }
+}
+
static void sdhci_data_transfer(void *opaque);
static void sdhci_send_command(SDHCIState *s)
@@ -1290,6 +1305,7 @@ static void sdhci_pci_class_init(ObjectClass *klass, void *data)
set_bit(DEVICE_CATEGORY_STORAGE, dc->categories);
dc->vmsd = &sdhci_vmstate;
dc->props = sdhci_pci_properties;
+ dc->reset = sdhci_poweron_reset;
}
static const TypeInfo sdhci_pci_info = {
@@ -1332,10 +1348,6 @@ static void sdhci_sysbus_realize(DeviceState *dev, Error ** errp)
memory_region_init_io(&s->iomem, OBJECT(s), &sdhci_mmio_ops, s, "sdhci",
SDHC_REGISTERS_MAP_SIZE);
sysbus_init_mmio(sbd, &s->iomem);
-
- if (s->pending_insert_quirk) {
- s->pending_insert_state = true;
- }
}
static void sdhci_sysbus_class_init(ObjectClass *klass, void *data)
@@ -1345,6 +1357,7 @@ static void sdhci_sysbus_class_init(ObjectClass *klass, void *data)
dc->vmsd = &sdhci_vmstate;
dc->props = sdhci_sysbus_properties;
dc->realize = sdhci_sysbus_realize;
+ dc->reset = sdhci_poweron_reset;
}
static const TypeInfo sdhci_sysbus_info = {
--
1.9.1
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [Qemu-devel] [PATCH 2/2] sdhci: Implement DeviceClass reset
2016-02-26 13:24 ` [Qemu-devel] [PATCH 2/2] sdhci: Implement DeviceClass reset Peter Maydell
@ 2016-02-26 17:47 ` Andrew Baumann
0 siblings, 0 replies; 5+ messages in thread
From: Andrew Baumann @ 2016-02-26 17:47 UTC (permalink / raw)
To: Peter Maydell, qemu-devel
Cc: Edgar E. Iglesias, Peter Crosthwaite, qemu-arm, Alistair Francis,
patches
> From: Peter Maydell [mailto:peter.maydell@linaro.org]
> Sent: Friday, 26 February 2016 5:24 AM
>
> The sdhci device was missing a DeviceClass reset method;
> implement it. Poweron reset looks the same as reset commanded
> by the guest via the device registers, apart from modelling of
> the rpi 'pending insert interrupt on powerup' quirk.
>
> Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
> ---
> hw/sd/sdhci.c | 21 +++++++++++++++++----
> 1 file changed, 17 insertions(+), 4 deletions(-)
>
> diff --git a/hw/sd/sdhci.c b/hw/sd/sdhci.c
> index e087c17..d28b587 100644
> --- a/hw/sd/sdhci.c
> +++ b/hw/sd/sdhci.c
> @@ -207,6 +207,21 @@ static void sdhci_reset(SDHCIState *s)
> s->pending_insert_state = false;
> }
>
> +static void sdhci_poweron_reset(DeviceState *dev)
> +{
> + /* QOM (ie power-on) reset. This is identical to reset
> + * commanded via device register apart from handling of the
> + * 'pending insert on powerup' quirk.
> + */
> + SDHCIState *s = (SDHCIState *)dev;
> +
> + sdhci_reset(s);
> +
> + if (s->pending_insert_quirk) {
> + s->pending_insert_state = true;
> + }
> +}
> +
> static void sdhci_data_transfer(void *opaque);
>
> static void sdhci_send_command(SDHCIState *s)
> @@ -1290,6 +1305,7 @@ static void sdhci_pci_class_init(ObjectClass *klass,
> void *data)
> set_bit(DEVICE_CATEGORY_STORAGE, dc->categories);
> dc->vmsd = &sdhci_vmstate;
> dc->props = sdhci_pci_properties;
> + dc->reset = sdhci_poweron_reset;
> }
>
> static const TypeInfo sdhci_pci_info = {
> @@ -1332,10 +1348,6 @@ static void sdhci_sysbus_realize(DeviceState *dev,
> Error ** errp)
> memory_region_init_io(&s->iomem, OBJECT(s), &sdhci_mmio_ops, s,
> "sdhci",
> SDHC_REGISTERS_MAP_SIZE);
> sysbus_init_mmio(sbd, &s->iomem);
> -
> - if (s->pending_insert_quirk) {
> - s->pending_insert_state = true;
> - }
> }
>
> static void sdhci_sysbus_class_init(ObjectClass *klass, void *data)
> @@ -1345,6 +1357,7 @@ static void sdhci_sysbus_class_init(ObjectClass
> *klass, void *data)
> dc->vmsd = &sdhci_vmstate;
> dc->props = sdhci_sysbus_properties;
> dc->realize = sdhci_sysbus_realize;
> + dc->reset = sdhci_poweron_reset;
> }
>
> static const TypeInfo sdhci_sysbus_info = {
Not tested, but the handling of the Pi quirk looks good to me, and it's trivial.
Reviewed-by: Andrew Baumann <Andrew.Baumann@microsoft.com>
BTW, now that you've done this, we could unify sdhci_pci_properties and sdhci_sysbus_properties. Let me know if you'd like a patch for that.
Cheers,
Andrew
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [Qemu-devel] [PATCH 1/2] sd.c: Handle NULL block backend in sd_get_inserted()
2016-02-26 13:24 ` [Qemu-devel] [PATCH 1/2] sd.c: Handle NULL block backend in sd_get_inserted() Peter Maydell
@ 2016-02-26 22:35 ` Alistair Francis
0 siblings, 0 replies; 5+ messages in thread
From: Alistair Francis @ 2016-02-26 22:35 UTC (permalink / raw)
To: Peter Maydell
Cc: Patch Tracking, Peter Crosthwaite,
qemu-devel@nongnu.org Developers, Andrew Baumann,
Alistair Francis, qemu-arm, Edgar E. Iglesias
On Fri, Feb 26, 2016 at 5:24 AM, Peter Maydell <peter.maydell@linaro.org> wrote:
> The sd.c SD card emulation code can be in a state where the
> SDState BlockBackend pointer is NULL; this is treated as
> "card not present". Add a missing check to sd_get_inserted()
> so that we don't segfault in this situation.
>
> (This could be provoked by the guest writing to the SDHCI
> register to do a reset on a xilinx-zynq-a9 board; it will
> also happen at startup when sdhci implements its DeviceClass
> reset method.)
>
> Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
Reviewed-by: Alistair Francis <alistair.francis@xilinx.com>
Thanks,
Alistair
> ---
> hw/sd/sd.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/hw/sd/sd.c b/hw/sd/sd.c
> index edb6b32..00c320d 100644
> --- a/hw/sd/sd.c
> +++ b/hw/sd/sd.c
> @@ -449,7 +449,7 @@ static void sd_reset(DeviceState *dev)
>
> static bool sd_get_inserted(SDState *sd)
> {
> - return blk_is_inserted(sd->blk);
> + return sd->blk && blk_is_inserted(sd->blk);
> }
>
> static bool sd_get_readonly(SDState *sd)
> --
> 1.9.1
>
>
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2016-02-26 22:35 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-02-26 13:24 [Qemu-devel] [PATCH 0/2] sdhci: Implement device reset Peter Maydell
2016-02-26 13:24 ` [Qemu-devel] [PATCH 1/2] sd.c: Handle NULL block backend in sd_get_inserted() Peter Maydell
2016-02-26 22:35 ` Alistair Francis
2016-02-26 13:24 ` [Qemu-devel] [PATCH 2/2] sdhci: Implement DeviceClass reset Peter Maydell
2016-02-26 17:47 ` Andrew Baumann
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.