sdhci: pending insert quirk for raspberry pi
v4 cover sdhci: pending insert quirk for raspberry pi
This is a small series to correctly implement a quirk modelling the behaviour of the card insert interrupt bit on Raspberry Pi, and on which Windows' UEFI loader sadly depends.
This should be the last change required to support Windows on Pi2, outside of adding devices and enabling the quirk, which I hope to do shortly in a new patch series.
Thanks,
Andrew
Andrew Baumann (2):
sdhci: Revert "add optional quirk property to disable card
insertion/removal interrupts"
sdhci: add quirk property for card insert interrupt status on
Raspberry Pi
hw/sd/sdhci.c | 47 ++++++++++++++++++++++++++++++++++++++++------- include/hw/sd/sdhci.h | 3 ++- 2 files changed, 42 insertions(+), 8 deletions(-)
Signature · 1 line
2.5.3
PATCH v4 1/2 sdhci: Revert "add optional quirk property to disable card insertion/removal interrupts"
This reverts commit 723697551a7e926abe7d3c7f2966012b8075143d.
This change was poorly tested on my part. It squelched card insertion interrupts on reset, but that was not necessary because sdhci_reset() clears all the registers (via the call to memset), so the subsequent sdhci_insert_eject_cb() call never sees the card insert interrupt enabled. However, not calling the insert_eject_cb results in prnsts remaining 0, when it actually needs to be updated to indicate card presence and R/O status.
--- hw/sd/sdhci.c | 9 +++------ include/hw/sd/sdhci.h | 1 - 2 files changed, 3 insertions(+), 7 deletions(-)
hw/sd/sdhci.c +3 -6
@@ -198,11 +198,9 @@ static void sdhci_reset(SDHCIState *s)* initialization */ memset (&s->sdmasysad,0 , (uintptr_t )&s->capareg - (uintptr_t )&s->sdmasysad); -if (!s->noeject_quirk) { -/* Reset other state based on current card insertion/readonly status */ -sdhci_set_inserted (dev,sdbus_get_inserted (&s->sdbus)); -sdhci_set_readonly (dev,sdbus_get_readonly (&s->sdbus)); - } +/* Reset other state based on current card insertion/readonly status */ +sdhci_set_inserted (dev,sdbus_get_inserted (&s->sdbus)); +sdhci_set_readonly (dev,sdbus_get_readonly (&s->sdbus)); s->data_count =0 ; s->stopped_state = sdhc_not_stopped;
@@ -1275,7 +1273,6 @@ static Property sdhci_sysbus_properties[] = {DEFINE_PROP_UINT32 ("capareg" , SDHCIState, capareg,SDHC_CAPAB_REG_DEFAULT ),DEFINE_PROP_UINT32 ("maxcurr" , SDHCIState, maxcurr,0 ), -DEFINE_PROP_BOOL ("noeject-quirk" , SDHCIState, noeject_quirk, false), DEFINE_PROP_END_OF_LIST(), };
include/hw/sd/sdhci.h +0 -1
@@ -76,7 +76,6 @@ typedef struct SDHCIState {uint32_t buf_maxsz;uint16_t data_count;/* current element in FIFO buffer */ uint8_t stopped_state;/* Current SDHC state */ -bool noeject_quirk;/* Quirk to disable card insert/remove interrupts */ /* Buffer Data Port Register - virtual access point to R and W buffers */ /* Software Reset Register - always reads as 0 */ /* Force Event Auto CMD12 Error Interrupt Reg - write only */
Signature · 1 line
2.5.3
PATCH v4 2/2 sdhci: add quirk property for card insert interrupt status on Raspberry Pi
In reply to Andrew BaumannThis quirk is a workaround for the following hardware behaviour, on which UEFI (specifically, the bootloader for Windows on Pi2) depends:
1. at boot with an SD card present, the interrupt status/enable registers are initially zero
2. upon enabling it in the interrupt enable register, the card insert bit in the interrupt status register is immediately set
3. after a subsequent controller reset, the card insert interrupt does not fire, even if enabled in the interrupt enable register
---
Notes:
There's a fairly extensive discussion of the hardware behaviour that this patch seeks to model in the thread at:
https://lists.gnu.org/archive/html/qemu-devel/2016-01/msg00605.html
v4: split pending_insert bool into to separate flags:
pending_insert_quirk for the property that enables the quirk, pending_insert_state to record whether an insert is pending (and which is cleared on delivery/reset)
v3: changed to use subsection for vmstate, to preserve backward compatibility
v2: changed implementation to use pending_insert bool rather than masking norintsts at read time, since the older version diverges from actual hardware behaviour when an interrupt is masked without being acked
hw/sd/sdhci.c | 38 +++++++++++++++++++++++++++++++++++++- include/hw/sd/sdhci.h | 2 ++ 2 files changed, 39 insertions(+), 1 deletion(-)
hw/sd/sdhci.c +37 -1
@@ -204,6 +204,7 @@ static void sdhci_reset(SDHCIState *s) s->data_count =0 ; s->stopped_state = sdhc_not_stopped; + s->pending_insert_state = false; }static void sdhci_data_transfer (void *opaque);
@@ -1095,6 +1096,13 @@ sdhci_write(void *opaque, hwaddr offset, uint64_t val, unsigned size) }else { s->norintsts &= ~SDHC_NIS_ERR ; } +/* Quirk for Raspberry Pi: pending card insert interrupt +* appears when first enabled after power on */ +if ((s->norintstsen &SDHC_NISEN_INSERT ) && s->pending_insert_state) { +assert (s->pending_insert_quirk); + s->norintsts |=SDHC_NIS_INSERT ; + s->pending_insert_state = false; + }sdhci_update_irq (s);break ;case SDHC_NORINTSIGEN :
@@ -1181,6 +1189,24 @@ static void sdhci_uninitfn(SDHCIState *s) s->fifo_buffer =NULL ; } +static bool sdhci_pending_insert_vmstate_needed (void *opaque) +{ +SDHCIState *s = opaque; + +return s->pending_insert_state; +} + +static const VMStateDescription sdhci_pending_insert_vmstate = { + .name ="sdhci/pending-insert" , + .version_id =1 , + .minimum_version_id =1 , + .needed = sdhci_pending_insert_vmstate_needed, + .fields = (VMStateField []) { +VMSTATE_BOOL (pending_insert_state, SDHCIState), +VMSTATE_END_OF_LIST () + }, +}; +const VMStateDescription sdhci_vmstate = { .name ="sdhci" , .version_id =1 ,
@@ -1215,7 +1241,11 @@ const VMStateDescription sdhci_vmstate = { VMSTATE_TIMER_PTR(insert_timer, SDHCIState), VMSTATE_TIMER_PTR(transfer_timer, SDHCIState),VMSTATE_END_OF_LIST () - } + }, + .subsections = (const VMStateDescription *[]) { + &sdhci_pending_insert_vmstate, +NULL + }, };/* Capabilities registers provide information on supported features of this
@@ -1273,6 +1303,8 @@ static Property sdhci_sysbus_properties[] = {DEFINE_PROP_UINT32 ("capareg" , SDHCIState, capareg,SDHC_CAPAB_REG_DEFAULT ),DEFINE_PROP_UINT32 ("maxcurr" , SDHCIState, maxcurr,0 ), +DEFINE_PROP_BOOL ("pending-insert-quirk" , SDHCIState, pending_insert_quirk, + false), DEFINE_PROP_END_OF_LIST(), };
@@ -1300,6 +1332,10 @@ 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)
include/hw/sd/sdhci.h +2 -0
@@ -76,6 +76,8 @@ typedef struct SDHCIState {uint32_t buf_maxsz;uint16_t data_count;/* current element in FIFO buffer */ uint8_t stopped_state;/* Current SDHC state */ +bool pending_insert_quirk;/* Quirk for Raspberry Pi card insert int */ +bool pending_insert_state;/* Buffer Data Port Register - virtual access point to R and W buffers */ /* Software Reset Register - always reads as 0 */ /* Force Event Auto CMD12 Error Interrupt Reg - write only */
Signature · 1 line
2.5.3
Peter Maydell
AppliedQuoted 7 lines · Andrew Baumann
This is a small series to correctly implement a quirk modelling the behaviour of the card insert interrupt bit on Raspberry Pi, and on which Windows' UEFI loader sadly depends.
This should be the last change required to support Windows on Pi2, outside of adding devices and enabling the quirk, which I hope to do shortly in a new patch series.
Applied to target-arm.next, thanks.
-- PMM