Skip to contentSkip to conversation

hw/sd/sdhci: Set reset value of interrupt registers

PATCH Superseded BALATON Zoltan 3 participants 8 messages Jan 15, 2025 – Feb 9, 2025

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 hw/sd/sdhci: Set reset value of interrupt registers

The interrupt enable registers are not reset to 0 but some bits are enabled on reset. At least some U-Boot versions seem to expect this and not initialise these registers before expecting interrupts. The numbers in this patch match what QorIQ P1022 has on reset and fix U-Boot for this SoC and should not break other drivers that initialise (and thus overwrite) these reset values.

---
I've also noticed that the work around marked with an XXX comment near line 600 breaks the U-Boot I've tested so I need to disable it:
if ((s->sdmasysad % boundary_chk) == 0) {
- page_aligned = true;
+// page_aligned = true;
}
What should this hack fix and could it be now removed or somehow restricted to cases where it's needed?

hw/sd/sdhci.c | 2 ++

 1 file changed, 2 insertions(+)
hw/sd/sdhci.c +2 -0
index 58375483e3..88eb0bfcb2 100644
@@ -303,6 +303,8 @@ static void sdhci_reset(SDHCIState *s)
     s->data_count = 0;
     s->stopped_state = sdhc_not_stopped;
     s->pending_insert_state = false;
+    s->norintstsen = 0x013f;
+    s->errintstsen = 0x117f;
 }
 
 static void sdhci_poweron_reset(DeviceState *dev)
Signature · 1 line
2.30.9
#1 lore raw
Quoted 6 lines · BALATON Zoltan

The interrupt enable registers are not reset to 0 but some bits are enabled on reset. At least some U-Boot versions seem to expect this and not initialise these registers before expecting interrupts. The numbers in this patch match what QorIQ P1022 has on reset and fix U-Boot for this SoC and should not break other drivers that initialise (and thus overwrite) these reset values.

Ping?

Quoted 28 lines

---
I've also noticed that the work around marked with an XXX comment near line 600 breaks the U-Boot I've tested so I need to disable it:
if ((s->sdmasysad % boundary_chk) == 0) {

(quoted diff) +1 -1
-        page_aligned = true;
+//        page_aligned = true;

}
What should this hack fix and could it be now removed or somehow restricted to cases where it's needed?

hw/sd/sdhci.c | 2 ++

1 file changed, 2 insertions(+)
hw/sd/sdhci.c +2 -0
index 58375483e3..88eb0bfcb2 100644
@@ -303,6 +303,8 @@ static void sdhci_reset(SDHCIState *s)
    s->data_count = 0;
    s->stopped_state = sdhc_not_stopped;
    s->pending_insert_state = false;
+    s->norintstsen = 0x013f;
+    s->errintstsen = 0x117f;
 }
 
 static void sdhci_poweron_reset(DeviceState *dev)
#2 lore raw
In reply to BALATON Zoltan
Quoted 14 lines · BALATON Zoltan

The interrupt enable registers are not reset to 0 but some bits are enabled on reset. At least some U-Boot versions seem to expect this and not initialise these registers before expecting interrupts. The numbers in this patch match what QorIQ P1022 has on reset and fix U-Boot for this SoC and should not break other drivers that initialise (and thus overwrite) these reset values.

---
I've also noticed that the work around marked with an XXX comment near line 600 breaks the U-Boot I've tested so I need to disable it:
if ((s->sdmasysad % boundary_chk) == 0) {

(quoted diff) +1 -1
-        page_aligned = true;
+//        page_aligned = true;
Quoted 3 lines

}
What should this hack fix and could it be now removed or somehow restricted to cases where it's needed?

Cc'ing Jamin for
https://lore.kernel.org/qemu-devel/[email protected]/

Quoted 9 lines

hw/sd/sdhci.c | 2 ++

  1 file changed, 2 insertions(+)
hw/sd/sdhci.c +0 -0
index 58375483e3..88eb0bfcb2 100644

hw/sd/sdhci.c static void sdhci_reset(SDHCIState *s) · line 307

Quoted 5 lines
hw/sd/sdhci.c +2 -0
@@ -303,6 +303,8 @@ static void sdhci_reset(SDHCIState *s)
      s->data_count = 0;
      s->stopped_state = sdhc_not_stopped;
      s->pending_insert_state = false;
+    s->norintstsen = 0x013f;
+    s->errintstsen = 0x117f;

I guess the problem is earlier:

/*
* Set all registers to 0. Capabilities/Version registers are not
cleared
* and assumed to always preserve their value, given to them during
* initialization
*/
memset(&s->sdmasysad, 0, (uintptr_t)&s->capareg -
(uintptr_t)&s->sdmasysad);

Not all registers have to be reset.

#3 lore raw
Quoted 47 lines · Philippe Mathieu-Daudé
Quoted 14 lines · BALATON Zoltan

The interrupt enable registers are not reset to 0 but some bits are enabled on reset. At least some U-Boot versions seem to expect this and not initialise these registers before expecting interrupts. The numbers in this patch match what QorIQ P1022 has on reset and fix U-Boot for this SoC and should not break other drivers that initialise (and thus overwrite) these reset values.

---
I've also noticed that the work around marked with an XXX comment near line 600 breaks the U-Boot I've tested so I need to disable it:
if ((s->sdmasysad % boundary_chk) == 0) {

(quoted diff) +1 -1
-        page_aligned = true;
+//        page_aligned = true;
Quoted 3 lines

}
What should this hack fix and could it be now removed or somehow restricted to cases where it's needed?

Cc'ing Jamin for
https://lore.kernel.org/qemu-devel/[email protected]/

Quoted 9 lines

hw/sd/sdhci.c | 2 ++

  1 file changed, 2 insertions(+)
hw/sd/sdhci.c +0 -0
index 58375483e3..88eb0bfcb2 100644

hw/sd/sdhci.c static void sdhci_reset(SDHCIState *s) · line 307

Quoted 5 lines
hw/sd/sdhci.c +2 -0
@@ -303,6 +303,8 @@ static void sdhci_reset(SDHCIState *s)
      s->data_count = 0;
      s->stopped_state = sdhc_not_stopped;
      s->pending_insert_state = false;
+    s->norintstsen = 0x013f;
+    s->errintstsen = 0x117f;

I guess the problem is earlier:

/*
* Set all registers to 0. Capabilities/Version registers are not cleared
* and assumed to always preserve their value, given to them during
* initialization
*/
memset(&s->sdmasysad, 0, (uintptr_t)&s->capareg -
(uintptr_t)&s->sdmasysad);

Quoted 1 line

Not all registers have to be reset.

Nothing seems to program those registers before reset but the reset values are documented (for Freescale eSDHCI) to be the above so just not zeroing them does not seem to be enough. Bernhard has similar patch in his branch, not sure if he came up with that separately or took this one. Do you have some docs on which regs should not be reset?

Regards,
BALATON Zoltan

#4 lore raw
Quoted 46 lines · BALATON Zoltan
Quoted 45 lines · Philippe Mathieu-Daudé
Quoted 8 lines · BALATON Zoltan

The interrupt enable registers are not reset to 0 but some bits are enabled on reset. At least some U-Boot versions seem to expect this and not initialise these registers before expecting interrupts. The numbers in this patch match what QorIQ P1022 has on reset and fix U-Boot for this SoC and should not break other drivers that initialise (and thus overwrite) these reset values.

Quoted 9 lines

---
I've also noticed that the work around marked with an XXX comment near line 600 breaks the U-Boot I've tested so I need to disable it:
if ((s->sdmasysad % boundary_chk) == 0) {
-        page_aligned = true;
+//        page_aligned = true;
}
What should this hack fix and could it be now removed or somehow restricted to cases where it's needed?

Cc'ing Jamin for
https://lore.kernel.org/qemu-devel/20241213031205.641009-2- [email protected]/

Quoted 9 lines

hw/sd/sdhci.c | 2 ++

  1 file changed, 2 insertions(+)
hw/sd/sdhci.c +0 -0
index 58375483e3..88eb0bfcb2 100644

hw/sd/sdhci.c static void sdhci_reset(SDHCIState *s) · line 307

Quoted 5 lines
hw/sd/sdhci.c +2 -0
@@ -303,6 +303,8 @@ static void sdhci_reset(SDHCIState *s)
       s->data_count = 0;
       s->stopped_state = sdhc_not_stopped;
       s->pending_insert_state = false;
+    s->norintstsen = 0x013f;
+    s->errintstsen = 0x117f;

I guess the problem is earlier:

   /*
    * Set all registers to 0. Capabilities/Version registers are not cleared
    * and assumed to always preserve their value, given to them during
    * initialization
    */
   memset(&s->sdmasysad, 0, (uintptr_t)&s->capareg - (uintptr_t)&s-

Quoted 5 lines
Quoted 3 lines

hw/sd/sdhci.c static void sdhci_reset(SDHCIState *s) · line 308

Quoted 1 line
hw/sd/sdhci.c +0 -0
 sdmasysad);

Not all registers have to be reset.

Nothing seems to program those registers before reset but the reset values are documented (for Freescale eSDHCI) to be the above so just not zeroing them does not seem to be enough. Bernhard has similar patch in his branch, not sure if he came up with that separately or took this one. Do you have some docs on which regs should not be reset?

The header precises what is being modeled here:

* SD Association Host Standard Specification v2.0 controller emulation *
* Datasheet:
PartA2_SD_Host_Controller_Simplified_Specification_Ver2.00.pdf

I can not see the reset values you mentioned there.

What is wrong with adding a TYPE_FREESCALE_ESDHC, like the TYPE_IMX_USDHC / TYPE_S3C_SDHCI types? Then you can add your reset handler fixing your fields after sdhci_poweron_reset().

#5 lore raw
Quoted 59 lines · Philippe Mathieu-Daudé
Quoted 46 lines · BALATON Zoltan
Quoted 45 lines · Philippe Mathieu-Daudé
Quoted 8 lines · BALATON Zoltan

The interrupt enable registers are not reset to 0 but some bits are enabled on reset. At least some U-Boot versions seem to expect this and not initialise these registers before expecting interrupts. The numbers in this patch match what QorIQ P1022 has on reset and fix U-Boot for this SoC and should not break other drivers that initialise (and thus overwrite) these reset values.

Quoted 9 lines

---
I've also noticed that the work around marked with an XXX comment near line 600 breaks the U-Boot I've tested so I need to disable it:
if ((s->sdmasysad % boundary_chk) == 0) {
-        page_aligned = true;
+//        page_aligned = true;
}
What should this hack fix and could it be now removed or somehow restricted to cases where it's needed?

Cc'ing Jamin for
https://lore.kernel.org/qemu-devel/20241213031205.641009-2- [email protected]/

Quoted 9 lines

hw/sd/sdhci.c | 2 ++

  1 file changed, 2 insertions(+)
hw/sd/sdhci.c +0 -0
index 58375483e3..88eb0bfcb2 100644

hw/sd/sdhci.c static void sdhci_reset(SDHCIState *s) · line 307

Quoted 5 lines
hw/sd/sdhci.c +2 -0
@@ -303,6 +303,8 @@ static void sdhci_reset(SDHCIState *s)
       s->data_count = 0;
       s->stopped_state = sdhc_not_stopped;
       s->pending_insert_state = false;
+    s->norintstsen = 0x013f;
+    s->errintstsen = 0x117f;

I guess the problem is earlier:

   /*
    * Set all registers to 0. Capabilities/Version registers are not cleared
    * and assumed to always preserve their value, given to them during
    * initialization
    */
   memset(&s->sdmasysad, 0, (uintptr_t)&s->capareg - (uintptr_t)&s-

Quoted 5 lines
Quoted 3 lines

hw/sd/sdhci.c static void sdhci_reset(SDHCIState *s) · line 308

Quoted 1 line
hw/sd/sdhci.c +0 -0
 sdmasysad);

Not all registers have to be reset.

Nothing seems to program those registers before reset but the reset values are documented (for Freescale eSDHCI) to be the above so just not zeroing them does not seem to be enough. Bernhard has similar patch in his branch, not sure if he came up with that separately or took this one. Do you have some docs on which regs should not be reset?

The header precises what is being modeled here:

* SD Association Host Standard Specification v2.0 controller emulation *
* Datasheet: PartA2_SD_Host_Controller_Simplified_Specification_Ver2.00.pdf

Quoted 5 lines

I can not see the reset values you mentioned there.

What is wrong with adding a TYPE_FREESCALE_ESDHC, like the TYPE_IMX_USDHC / TYPE_S3C_SDHCI types? Then you can add your reset handler fixing your fields after sdhci_poweron_reset().

Nothing's wrong with that, I just did not notice those existing variants. Maybe that's the way to go then with this too. Bernhard, do you plan to do that when cleaning up your tree or should I do another version?

Regards,
BALATON Zoltan

#6 lore raw
Quoted 60 lines · BALATON Zoltan
Quoted 59 lines · Philippe Mathieu-Daudé
Quoted 46 lines · BALATON Zoltan
Quoted 45 lines · Philippe Mathieu-Daudé
Quoted 8 lines · BALATON Zoltan

The interrupt enable registers are not reset to 0 but some bits are enabled on reset. At least some U-Boot versions seem to expect this and not initialise these registers before expecting interrupts. The numbers in this patch match what QorIQ P1022 has on reset and fix U-Boot for this SoC and should not break other drivers that initialise (and thus overwrite) these reset values.

Quoted 9 lines

---
I've also noticed that the work around marked with an XXX comment near line 600 breaks the U-Boot I've tested so I need to disable it:
if ((s->sdmasysad % boundary_chk) == 0) {
-        page_aligned = true;
+//        page_aligned = true;
}
What should this hack fix and could it be now removed or somehow restricted to cases where it's needed?

Cc'ing Jamin for
https://lore.kernel.org/qemu-devel/20241213031205.641009-2- [email protected]/

Quoted 9 lines

hw/sd/sdhci.c | 2 ++

  1 file changed, 2 insertions(+)
hw/sd/sdhci.c +0 -0
index 58375483e3..88eb0bfcb2 100644

hw/sd/sdhci.c static void sdhci_reset(SDHCIState *s) · line 307

Quoted 5 lines
hw/sd/sdhci.c +2 -0
@@ -303,6 +303,8 @@ static void sdhci_reset(SDHCIState *s)
       s->data_count = 0;
       s->stopped_state = sdhc_not_stopped;
       s->pending_insert_state = false;
+    s->norintstsen = 0x013f;
+    s->errintstsen = 0x117f;

I guess the problem is earlier:

   /*
    * Set all registers to 0. Capabilities/Version registers are not cleared
    * and assumed to always preserve their value, given to them during
    * initialization
    */
   memset(&s->sdmasysad, 0, (uintptr_t)&s->capareg - (uintptr_t)&s-

Quoted 5 lines
Quoted 3 lines

hw/sd/sdhci.c static void sdhci_reset(SDHCIState *s) · line 308

Quoted 1 line
hw/sd/sdhci.c +0 -0
 sdmasysad);

Not all registers have to be reset.

Nothing seems to program those registers before reset but the reset values are documented (for Freescale eSDHCI) to be the above so just not zeroing them does not seem to be enough. Bernhard has similar patch in his branch, not sure if he came up with that separately or took this one. Do you have some docs on which regs should not be reset?

The header precises what is being modeled here:

* SD Association Host Standard Specification v2.0 controller emulation *
* Datasheet: PartA2_SD_Host_Controller_Simplified_Specification_Ver2.00.pdf

Quoted 7 lines
Quoted 5 lines

I can not see the reset values you mentioned there.

What is wrong with adding a TYPE_FREESCALE_ESDHC, like the TYPE_IMX_USDHC / TYPE_S3C_SDHCI types? Then you can add your reset handler fixing your fields after sdhci_poweron_reset().

Nothing's wrong with that, I just did not notice those existing variants. Maybe that's the way to go then with this too. Bernhard, do you plan to do that when cleaning up your tree or should I do another version?

I'm not sure this is the best way to do what you need, but it'd be one with less impacts on other SDHCI-based models IMO.

#7 lore raw
In reply to BALATON Zoltan

Am 6. Februar 2025 13:49:38 UTC schrieb BALATON Zoltan <[email protected]>:

Quoted 59 lines · Philippe Mathieu-Daudé
Quoted 58 lines · BALATON Zoltan
Quoted 47 lines · Philippe Mathieu-Daudé
Quoted 46 lines · BALATON Zoltan
Quoted 8 lines

The interrupt enable registers are not reset to 0 but some bits are enabled on reset. At least some U-Boot versions seem to expect this and not initialise these registers before expecting interrupts. The numbers in this patch match what QorIQ P1022 has on reset and fix U-Boot for this SoC and should not break other drivers that initialise (and thus overwrite) these reset values.

Quoted 9 lines

---
I've also noticed that the work around marked with an XXX comment near line 600 breaks the U-Boot I've tested so I need to disable it:
if ((s->sdmasysad % boundary_chk) == 0) {
-        page_aligned = true;
+//        page_aligned = true;
}
What should this hack fix and could it be now removed or somehow restricted to cases where it's needed?

Cc'ing Jamin for
https://lore.kernel.org/qemu-devel/20241213031205.641009-2- [email protected]/

Quoted 9 lines

hw/sd/sdhci.c | 2 ++

  1 file changed, 2 insertions(+)
hw/sd/sdhci.c +0 -0
index 58375483e3..88eb0bfcb2 100644

hw/sd/sdhci.c static void sdhci_reset(SDHCIState *s) · line 307

Quoted 5 lines
hw/sd/sdhci.c +2 -0
@@ -303,6 +303,8 @@ static void sdhci_reset(SDHCIState *s)
       s->data_count = 0;
       s->stopped_state = sdhc_not_stopped;
       s->pending_insert_state = false;
+    s->norintstsen = 0x013f;
+    s->errintstsen = 0x117f;

I guess the problem is earlier:

   /*
    * Set all registers to 0. Capabilities/Version registers are not cleared
    * and assumed to always preserve their value, given to them during
    * initialization
    */
   memset(&s->sdmasysad, 0, (uintptr_t)&s->capareg - (uintptr_t)&s- >sdmasysad);

Quoted 3 lines
Quoted 1 line

Not all registers have to be reset.

Nothing seems to program those registers before reset but the reset values are documented (for Freescale eSDHCI) to be the above so just not zeroing them does not seem to be enough. Bernhard has similar patch in his branch, not sure if he came up with that separately or took this one. Do you have some docs on which regs should not be reset?

The header precises what is being modeled here:

* SD Association Host Standard Specification v2.0 controller emulation *
* Datasheet: PartA2_SD_Host_Controller_Simplified_Specification_Ver2.00.pdf

Quoted 7 lines
Quoted 5 lines

I can not see the reset values you mentioned there.

What is wrong with adding a TYPE_FREESCALE_ESDHC, like the TYPE_IMX_USDHC / TYPE_S3C_SDHCI types? Then you can add your reset handler fixing your fields after sdhci_poweron_reset().

Nothing's wrong with that, I just did not notice those existing variants. Maybe that's the way to go then with this too. Bernhard, do you plan to do that when cleaning up your tree or should I do another version?

Feel free to submit a patch. I'm actually in favor of a dedicated device model which was also my first approach: <https://lore.kernel.org/qemu-devel/[email protected]/> Perhaps we could have dedicated source files as well.

Best regards,
Bernhard

Quoted 3 lines

Regards,
BALATON Zoltan