Skip to contentSkip to conversation

Standard SD host controller model

PATCH Superseded Peter A. G. Crosthwaite 3 participants 13 messages Jul 5, 2012 – Jul 18, 2012

Subsystems (2)

v5 of 6 Superseded Latest is v6 →

lore
Share & tools
lore
#0 lore raw

v5 cover Standard SD host controller model

[Original cover by Igor]
First patch introduces standard SD host controller model. This is accumulated version of my previous patch I sent a while ago and a recent SDHCI patch by Peter A. G. Crosthwaite. Second patch introduces Exynos4210-specific SDHCI built on top of standard SDHCI model.

[New]
Third patch changes the -sd command line argument to be repeatable, to support multiple SD controllers in one system. Fourth patch adds 2x SDHCI controllers to the Xilinx Zynq machine

This revision is typo fixes and rebasing only.

Changelog:
Changed from v4:
Igors changes re PMM review (P1/2)
Typo in commit msg (P3)
removed redundant braces in P4
Changed from v3:
Rebased for new Makefile system
Fixed include guard in sdhci.h
Typos in commit messages
Changed from v2:
corrected typo errors in ADMA1 support
added patches 3-4
v1->v2
PATCH1:
add support for ADMA1 (I havn't tested it though).
fixed s->prnsts <-> s->pwrcon typo (thanks to Peter, strange that it even worked before).
PATCH2:
change header prefix from "target-arm" to "exynos4210".

Peter A. G. Crosthwaite (2):
vl.c: allow for repeated -sd arguments
xilinx_zynq: Added SD controllers

 default-configs/arm-softmmu.mak |    1 +
 hw/Makefile.objs                |    1 +
 hw/arm/Makefile.objs            |    1 +
 hw/exynos4210.c                 |   20 +
 hw/exynos4210_sdhci.c           |  443 +++++++++++++
 hw/sdhci.c                      | 1313 +++++++++++++++++++++++++++++++++++++++
 hw/sdhci.h                      |  310 +++++++++
 hw/xilinx_zynq.c                |   10 +
 vl.c                            |    2 +-
 9 files changed, 2100 insertions(+), 1 deletions(-)
 create mode 100644 hw/exynos4210_sdhci.c
 create mode 100644 hw/sdhci.c
 create mode 100644 hw/sdhci.h
Signature · 1 line
1.7.3.2
#1 lore raw

PATCH v5 1/4 hw: introduce standard SD host controller

From: Igor Mitsyanko <[email protected]>

Device model for standard SD Host Controller Interface (SDHCI) compliant with version 2.00 of SD association specification.

---
changed from v4 (Igor):
s/sdhc_not_stoped/sdhc_not_stopped/ s/stoped_state/stopped_state/
s/stoped_adma/stopped_adma/
stop insert timer when host controller resets;
stop and free insert timer, free eject_cb and ro_cb in deinit function; drop redundant "(s->trnmod & SDHC_TRNS_MULTI)" clause;
add comment to Property struct;
changed from v1:
Fixed include guard (Andreas review)
Rebased for new Makefile system
changed from v2:
Typographical fixes for adma implementation

 default-configs/arm-softmmu.mak |    1 +
 hw/Makefile.objs                |    1 +
 hw/sdhci.c                      | 1313 +++++++++++++++++++++++++++++++++++++++
 hw/sdhci.h                      |  310 +++++++++
 4 files changed, 1625 insertions(+), 0 deletions(-)
 create mode 100644 hw/sdhci.c
 create mode 100644 hw/sdhci.h
default-configs/arm-softmmu.mak +1 -0
index e542b4f..314784b 100644
@@ -27,3 +27,4 @@ CONFIG_SMC91C111=y
 CONFIG_DS1338=y
 CONFIG_PFLASH_CFI01=y
 CONFIG_PFLASH_CFI02=y
+CONFIG_SDHCI=y
hw/Makefile.objs +1 -0
index 3d77259..8d51954 100644
@@ -35,6 +35,7 @@ hw-obj-$(CONFIG_APPLESMC) += applesmc.o
 hw-obj-$(CONFIG_SMARTCARD) += ccid-card-passthru.o
 hw-obj-$(CONFIG_SMARTCARD_NSS) += ccid-card-emulated.o
 hw-obj-$(CONFIG_I8259) += i8259_common.o i8259.o
+hw-obj-$(CONFIG_SDHCI) += sdhci.o
 
 # PPC devices
 hw-obj-$(CONFIG_PREP_PCI) += prep_pci.o
hw/sdhci.c new file +1313 -0

1,313 lines not on this page · raw message

hw/sdhci.h new file +310 -0

310 lines not on this page · raw message

Signature · 1 line
1.7.3.2
#2 lore raw

PATCH v5 2/4 exynos4210: Added SD host controller model

In reply to Peter A. G. Crosthwaite

From: Igor Mitsyanko <[email protected]>

Custom Exynos4210 SD/MMC host controller, based on SD association standard host controller ver. 2.00.

---
changed from v4 (Igor):
set irq on SLOTINT status instead of interrupt registers status; instead;
conditional in exynos4210_sdhci_can_issue_command() made more readable and documented;
add a comment to exynos4210_sdhci_writefn()'s SDHC_CLKCON case statement;
do not override superclass property in exynos4210.sdhci class, set properties to required value in realize function changed from v3:
rebased for new Makefile system
fixed commit msg typo (Andreas review)

 hw/arm/Makefile.objs  |    1 +
 hw/exynos4210.c       |   20 +++
 hw/exynos4210_sdhci.c |  443 +++++++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 464 insertions(+), 0 deletions(-)
 create mode 100644 hw/exynos4210_sdhci.c
hw/arm/Makefile.objs +1 -0
index 88ff47d..c3afb6e 100644
@@ -11,6 +11,7 @@ obj-y += realview_gic.o realview.o arm_sysctl.o arm11mpcore.o a9mpcore.o
 obj-y += exynos4210_gic.o exynos4210_combiner.o exynos4210.o
 obj-y += exynos4_boards.o exynos4210_uart.o exynos4210_pwm.o
 obj-y += exynos4210_pmu.o exynos4210_mct.o exynos4210_fimd.o
+obj-y += exynos4210_sdhci.o
 obj-y += arm_l2x0.o
 obj-y += arm_mptimer.o a15mpcore.o
 obj-y += armv7m.o armv7m_nvic.o stellaris.o pl022.o stellaris_enet.o
hw/exynos4210.c +20 -0
index 9c20b3f..1a2e3d9 100644
@@ -56,6 +56,12 @@
 #define EXYNOS4210_EXT_COMBINER_BASE_ADDR   0x10440000
 #define EXYNOS4210_INT_COMBINER_BASE_ADDR   0x10448000
 
+/* SD/MMC host controllers SFR base addresses */
+#define EXYNOS4210_SDHC0_BASE_ADDR          0x12510000
+#define EXYNOS4210_SDHC1_BASE_ADDR          0x12520000
+#define EXYNOS4210_SDHC2_BASE_ADDR          0x12530000
+#define EXYNOS4210_SDHC3_BASE_ADDR          0x12540000
+
 /* PMU SFR base address */
 #define EXYNOS4210_PMU_BASE_ADDR            0x10020000
 
@@ -292,6 +298,20 @@ Exynos4210State *exynos4210_init(MemoryRegion *system_mem,
                            EXYNOS4210_UART3_FIFO_SIZE, 3, NULL,
                   s->irq_table[exynos4210_get_irq(EXYNOS4210_UART_INT_GRP, 3)]);
 
+    /*** SD/MMC host controllers ***/
+
+    sysbus_create_simple("exynos4210.sdhci", EXYNOS4210_SDHC0_BASE_ADDR,
+            s->irq_table[exynos4210_get_irq(29, 0)]);
+
+    sysbus_create_simple("exynos4210.sdhci", EXYNOS4210_SDHC1_BASE_ADDR,
+            s->irq_table[exynos4210_get_irq(29, 1)]);
+
+    sysbus_create_simple("exynos4210.sdhci", EXYNOS4210_SDHC2_BASE_ADDR,
+            s->irq_table[exynos4210_get_irq(29, 2)]);
+
+    sysbus_create_simple("exynos4210.sdhci", EXYNOS4210_SDHC3_BASE_ADDR,
+            s->irq_table[exynos4210_get_irq(29, 3)]);
+
     /*** Display controller (FIMD) ***/
     sysbus_create_varargs("exynos4210.fimd", EXYNOS4210_FIMD0_BASE_ADDR,
             s->irq_table[exynos4210_get_irq(11, 0)],
hw/exynos4210_sdhci.c new file +443 -0

443 lines not on this page · raw message

Signature · 1 line
1.7.3.2
#3 lore raw

Re: [Qemu-devel] [PATCH v5 2/4] exynos4210: Added SD host controller model

Quoted 9 lines · Peter A. G. Crosthwaite

From: Igor Mitsyanko <[email protected]>

Custom Exynos4210 SD/MMC host controller, based on SD association standard host controller ver. 2.00.

---
changed from v4 (Igor):
set irq on SLOTINT status instead of interrupt registers status; instead;

The IRQ handling code still looks really weird. I would expect that the code would be:
[code which updates various kinds of irq related state] sdhci_update_irq();

where sdhci_update_irq() calls qemu_set_irq() based on the state.

At the moment it looks as if you're using slotint as a cached value of the expression
"((s->norintsts & s->norintsigen) || (s->errintsts & s->errintsigen) ||
((s->norintsts & SDHC_NIS_INSERT) && (s->wakcon & SDHC_WKUP_ON_INS)) || ((s->norintsts & SDHC_NIS_REMOVE) && (s->wakcon & SDHC_WKUP_ON_RMV)))"

[can these two ever have different values?] and also attempting to shortcut by manually updating slotint in codepaths which change only parts of the state which this expression is testing. Why not just do things the simple and straightforward way and get rid of slotint completely?

-- PMM

#4 lore raw

Re: [Qemu-devel] [PATCH v5 2/4] exynos4210: Added SD host controller model

Quoted 24 lines · Peter Maydell
Quoted 9 lines · Peter A. G. Crosthwaite

From: Igor Mitsyanko <[email protected]>

Custom Exynos4210 SD/MMC host controller, based on SD association standard host controller ver. 2.00.

---
changed from v4 (Igor):
set irq on SLOTINT status instead of interrupt registers status; instead;

The IRQ handling code still looks really weird. I would expect that the code would be:
[code which updates various kinds of irq related state] sdhci_update_irq();

where sdhci_update_irq() calls qemu_set_irq() based on the state.

At the moment it looks as if you're using slotint as a cached value of the expression
"((s->norintsts & s->norintsigen) || (s->errintsts & s->errintsigen) ||
((s->norintsts & SDHC_NIS_INSERT) && (s->wakcon & SDHC_WKUP_ON_INS)) || ((s->norintsts & SDHC_NIS_REMOVE) && (s->wakcon & SDHC_WKUP_ON_RMV)))"

Quoted 8 lines

[can these two ever have different values?] and also attempting to shortcut by manually updating slotint in codepaths which change only parts of the state which this expression is testing. Why not just do things the simple and straightforward way and get rid of slotint completely?

-- PMM

Linux seems to ignore SLOTINT status register, probably because it only supports single slot configuration while SLOTINT really required for multislot controllers only, so I think we can remove it completely and simply return 0 on reads. Same for status of WAKCON register, nobody cares about controller's wakeup functionality. Then update irq function could be simplified to

"qemu_set_irq(s->irq, (s->norintsts & s->norintsigen) || (s->errintsts
& s->errintsigen))"

I think thats how it was done originally. I'll send incremental patch to Peter off-list, if he and everyone else agree to handle interrupts this way.

#5 lore raw

Re: [Qemu-devel] [PATCH v5 2/4] exynos4210: Added SD host controller model

Quoted 27 lines · Igor Mitsyanko
Quoted 13 lines · Peter Maydell

The IRQ handling code still looks really weird. I would expect that the code would be:
[code which updates various kinds of irq related state] sdhci_update_irq();

where sdhci_update_irq() calls qemu_set_irq() based on the state.

At the moment it looks as if you're using slotint as a cached value of the expression
"((s->norintsts & s->norintsigen) || (s->errintsts & s->errintsigen) ||
((s->norintsts & SDHC_NIS_INSERT) && (s->wakcon & SDHC_WKUP_ON_INS)) || ((s->norintsts & SDHC_NIS_REMOVE) && (s->wakcon & SDHC_WKUP_ON_RMV)))"

Quoted 5 lines

[can these two ever have different values?] and also attempting to shortcut by manually updating slotint in codepaths which change only parts of the state which this expression is testing. Why not just do things the simple and straightforward way and get rid of slotint completely?

Linux seems to ignore SLOTINT status register, probably because it only supports single slot configuration while SLOTINT really required for multislot controllers only, so I think we can remove it completely and simply return 0 on reads. Same for status of WAKCON register, nobody cares about controller's wakeup functionality. Then update irq function could be simplified to

Quoted 2 lines

"qemu_set_irq(s->irq, (s->norintsts & s->norintsigen) || (s->errintsts &
s->errintsigen))"

We should be modelling what the hardware does, not just what Linux happens to use.

I've now gone and found the SDHCI specification. (figure 1-6 and table 1-6 in the simplified spec v3.00 are relevant here.) What happens is that the SLOTINT bit tracks the external interrupt line's state, and that interrupt line is the logical combination of the various *sts/*sigen registers. I would suggest two functions:

int sdhci_slotint(SDHCIState *s)
which just calculates and returns the external interrupt line state (might be able to make this 'static'), and

void sdhci_update_irq(SDHCIState *s)

{
    qemu_set_irq(sdhci_slotint(s));
}

Then just call sdhci_update_irq() any time you update state that can affect the interrupt line.

The 'read the SLOTINT register' implementation just calls sdhci_slotint(), obviously.

This approach:
* doesn't store any extra state in our state struct that the hardware doesn't also have as stored state
* doesn't prematurely optimise the calculation of the interrupt line state, so it's nice and clear how the irq line works and that it follows the spec

-- PMM

#6 lore raw

Re: [Qemu-devel] [PATCH v5 2/4] exynos4210: Added SD host controller model

Quoted 53 lines · Peter Maydell
Quoted 26 lines · Igor Mitsyanko
Quoted 13 lines · Peter Maydell

The IRQ handling code still looks really weird. I would expect that the code would be:
[code which updates various kinds of irq related state] sdhci_update_irq();

where sdhci_update_irq() calls qemu_set_irq() based on the state.

At the moment it looks as if you're using slotint as a cached value of the expression
"((s->norintsts & s->norintsigen) || (s->errintsts & s->errintsigen) ||
((s->norintsts & SDHC_NIS_INSERT) && (s->wakcon & SDHC_WKUP_ON_INS)) || ((s->norintsts & SDHC_NIS_REMOVE) && (s->wakcon & SDHC_WKUP_ON_RMV)))"

Quoted 5 lines

[can these two ever have different values?] and also attempting to shortcut by manually updating slotint in codepaths which change only parts of the state which this expression is testing. Why not just do things the simple and straightforward way and get rid of slotint completely?

Linux seems to ignore SLOTINT status register, probably because it only supports single slot configuration while SLOTINT really required for multislot controllers only, so I think we can remove it completely and simply return 0 on reads. Same for status of WAKCON register, nobody cares about controller's wakeup functionality. Then update irq function could be simplified to

Quoted 2 lines

"qemu_set_irq(s->irq, (s->norintsts & s->norintsigen) || (s->errintsts &
s->errintsigen))"

We should be modelling what the hardware does, not just what Linux happens to use.

I've now gone and found the SDHCI specification. (figure 1-6 and table 1-6 in the simplified spec v3.00 are relevant here.) What happens is that the SLOTINT bit tracks the external interrupt line's state, and that interrupt line is the logical combination of the various *sts/*sigen registers. I would suggest two functions:

int sdhci_slotint(SDHCIState *s)
which just calculates and returns the external interrupt line state (might be able to make this 'static'), and

void sdhci_update_irq(SDHCIState *s)

{
     qemu_set_irq(sdhci_slotint(s));
}

Then just call sdhci_update_irq() any time you update state that can affect the interrupt line.

The 'read the SLOTINT register' implementation just calls sdhci_slotint(), obviously.

Quoted 9 lines

This approach:
* doesn't store any extra state in our state struct that the hardware doesn't also have as stored state
* doesn't prematurely optimise the calculation of the interrupt line state, so it's nice and clear how the irq line works and that it follows the spec

-- PMM

Ok, but I'd rather make sdhci_slotint() return uint8_t, to emphasize that this function returns a value of hardware SLOTINT register.

#7 lore raw

Re: [Qemu-devel] [PATCH v5 2/4] exynos4210: Added SD host controller model

Quoted 9 lines · Igor Mitsyanko
Quoted 5 lines · Peter Maydell

I would suggest two functions:

int sdhci_slotint(SDHCIState *s)
which just calculates and returns the external interrupt line state (might be able to make this 'static'), and

Ok, but I'd rather make sdhci_slotint() return uint8_t, to emphasize that this function returns a value of hardware SLOTINT register.

That's fine; the thing I want to avoid is having by-hand updates of slotint all over the code.

-- PMM

#8 lore raw

Re: [Qemu-devel] [PATCH v5 2/4] exynos4210: Added SD host controller model

Will merge Igors corrections into v6

Regards,
Peter

Quoted 15 lines · Peter Maydell
Quoted 9 lines · Igor Mitsyanko
Quoted 5 lines · Peter Maydell

I would suggest two functions:

int sdhci_slotint(SDHCIState *s)
which just calculates and returns the external interrupt line state (might be able to make this 'static'), and

Ok, but I'd rather make sdhci_slotint() return uint8_t, to emphasize that this function returns a value of hardware SLOTINT register.

That's fine; the thing I want to avoid is having by-hand updates of slotint all over the code.

-- PMM

#9 lore raw

PATCH v5 3/4 vl.c: allow for repeated -sd arguments

In reply to Peter A. G. Crosthwaite

Allows for repeating of -sd arguments in the same way as -pflash and -mtdblock.

---
changed from v4:
fixed (another) commit msg typo
changed from v3:
fixed commit msg typo

 vl.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
vl.c +1 -1
index 1329c30..fe1f33b 100644
@@ -2431,7 +2431,7 @@ int main(int argc, char **argv, char **envp)
                 drive_add(IF_MTD, -1, optarg, MTD_OPTS);
                 break;
             case QEMU_OPTION_sd:
-                drive_add(IF_SD, 0, optarg, SD_OPTS);
+                drive_add(IF_SD, -1, optarg, SD_OPTS);
                 break;
             case QEMU_OPTION_pflash:
                 drive_add(IF_PFLASH, -1, optarg, PFLASH_OPTS);
Signature · 1 line
1.7.3.2
#11 lore raw

PATCH v5 4/4 xilinx_zynq: Added SD controllers

In reply to Peter A. G. Crosthwaite

The Xilinx Zynq device has two SDHCI controllers. Added to the machine model.

---
changed from v4:
removed redundant braces
changed from v3:
fixed indentation
tweaked commit msg

 hw/xilinx_zynq.c |   10 ++++++++++
 1 files changed, 10 insertions(+), 0 deletions(-)
hw/xilinx_zynq.c +10 -0
index 7e6c273..a7feabe 100644
@@ -130,6 +130,16 @@ static void zynq_init(ram_addr_t ram_size, const char *boot_device,
         }
     }
 
+    dev = qdev_create(NULL, "sdhci");
+    qdev_init_nofail(dev);
+    sysbus_mmio_map(sysbus_from_qdev(dev), 0, 0xE0100000);
+    sysbus_connect_irq(sysbus_from_qdev(dev), 0, pic[56-IRQ_OFFSET]);
+
+    dev = qdev_create(NULL, "sdhci");
+    qdev_init_nofail(dev);
+    sysbus_mmio_map(sysbus_from_qdev(dev), 0, 0xE0101000);
+    sysbus_connect_irq(sysbus_from_qdev(dev), 0, pic[79-IRQ_OFFSET]);
+
     zynq_binfo.ram_size = ram_size;
     zynq_binfo.kernel_filename = kernel_filename;
     zynq_binfo.kernel_cmdline = kernel_cmdline;
Signature · 1 line
1.7.3.2