hw/arm: Add MMC device for NPCM7XX boards
v2 cover hw/arm: Add MMC device for NPCM7XX boards
This patch set implements the Nuvoton MMC device
for NPCM7XX boards.
The MMC device is compatible with the SDHCI interface in QEMU. It allows the user to attach an SD card image to it.
Changes since v1:
1. Rearrange the "add SDHCI commands" to just before when it's actually used.
2. Add standrad SDHCI MMIO as subregion, similar to cadence_sdhci. e. Add a vmstate for NPCM7XX SDHCI.
4. Address various minor fixes suggested by Peter Maydell.
Shengtan Mao (5):
hw/sd: add nuvoton MMC
hw/arm: Add Nuvoton SD module to board
hw/arm: Attach MMC to quanta-gbs-bmc
tests/qtest/libqos: add SDHCI commands
tests/qtest: add qtests for npcm7xx sdhci
hw/arm/npcm7xx.c | 12 +- hw/arm/npcm7xx_boards.c | 20 +++ hw/sd/meson.build | 1 + hw/sd/npcm7xx_sdhci.c | 182 +++++++++++++++++++++++++++ include/hw/arm/npcm7xx.h | 2 + include/hw/sd/npcm7xx_sdhci.h | 65 ++++++++++ tests/qtest/libqos/meson.build | 1 + tests/qtest/libqos/sdhci-cmd.c | 116 +++++++++++++++++ tests/qtest/libqos/sdhci-cmd.h | 70 +++++++++++ tests/qtest/meson.build | 1 + tests/qtest/npcm7xx_sdhci-test.c | 209 +++++++++++++++++++++++++++++++ 11 files changed, 678 insertions(+), 1 deletion(-) create mode 100644 hw/sd/npcm7xx_sdhci.c create mode 100644 include/hw/sd/npcm7xx_sdhci.h create mode 100644 tests/qtest/libqos/sdhci-cmd.c create mode 100644 tests/qtest/libqos/sdhci-cmd.h create mode 100644 tests/qtest/npcm7xx_sdhci-test.c
Signature · 1 line
2.33.0.882.g93a45727a2-goog
PATCH v2 1/5 hw/sd: add nuvoton MMC
From: Shengtan Mao <[email protected]>
--- hw/sd/meson.build | 1 + hw/sd/npcm7xx_sdhci.c | 182 ++++++++++++++++++++++++++++++++++ include/hw/sd/npcm7xx_sdhci.h | 65 ++++++++++++ 3 files changed, 248 insertions(+) create mode 100644 hw/sd/npcm7xx_sdhci.c create mode 100644 include/hw/sd/npcm7xx_sdhci.h
hw/sd/meson.build +1 -0
@@ -9,4 +9,5 @@ softmmu_ss.add(when: 'CONFIG_PXA2XX', if_true: files('pxa2xx_mmci.c')) softmmu_ss.add(when: 'CONFIG_RASPI', if_true: files('bcm2835_sdhost.c')) softmmu_ss.add(when: 'CONFIG_ASPEED_SOC', if_true: files('aspeed_sdhci.c')) softmmu_ss.add(when: 'CONFIG_ALLWINNER_H3', if_true: files('allwinner-sdhost.c')) +softmmu_ss.add(when: 'CONFIG_NPCM7XX', if_true: files('npcm7xx_sdhci.c')) softmmu_ss.add(when: 'CONFIG_CADENCE_SDHCI', if_true: files('cadence_sdhci.c'))
hw/sd/npcm7xx_sdhci.c new file +182 -0
182 lines not on this page · raw message
include/hw/sd/npcm7xx_sdhci.h new file +65 -0
65 lines not on this page · raw message
Signature · 1 line
2.33.0.882.g93a45727a2-goog
Re: [PATCH v2 1/5] hw/sd: add nuvoton MMC
hw/sd/npcm7xx_sdhci.c line 42
Quoted 12 lines · Hao Wu
From: Shengtan Mao <[email protected]>
Signed-off-by Shengtan Mao <[email protected]>Reviewed-by Hao Wu <[email protected]>Reviewed-by Chris Rauer <[email protected]>Reviewed-by Tyrone Ting <[email protected]>Signed-off-by Hao Wu <[email protected]>---
hw/sd/npcm7xx_sdhci.c new file +2
-0+default : + qemu_log_mask(LOG_GUEST_ERROR, "SDHCI read of nonexist reg: 0x%02"
"nonexistent"
Quoted 8 lines
hw/sd/npcm7xx_sdhci.c new file +8
-0+ HWADDR_PRIx, addr); +break ; + } + +return val; +} + +static void npcm7xx_sdhci_write(void *opaque, hwaddr addr, uint64_t val,
hw/sd/npcm7xx_sdhci.c line 60
Quoted 10 lines
hw/sd/npcm7xx_sdhci.c new file +10
-0+ unsigned int size) +{ +NPCM7xxSDHCIState *s = opaque; + +switch (addr) { +case NPCM7XX_BOOTTOCTRL : + s->regs.boottoctrl = val; +break ; +default : + qemu_log_mask(LOG_GUEST_ERROR, "SDHCI write of nonexist reg: 0x%02"
ditto
Otherwise
thanks
-- PMM
Re: [PATCH v2 1/5] hw/sd: add nuvoton MMC
Quoted 28 lines · Peter Maydell
hw/sd/npcm7xx_sdhci.c line 42
Quoted 12 lines · Hao Wu
From: Shengtan Mao <[email protected]>
Signed-off-by Shengtan Mao <[email protected]>Reviewed-by Hao Wu <[email protected]>Reviewed-by Chris Rauer <[email protected]>Reviewed-by Tyrone Ting <[email protected]>Signed-off-by Hao Wu <[email protected]>---
hw/sd/npcm7xx_sdhci.c new file +2
-0+default : + qemu_log_mask(LOG_GUEST_ERROR, "SDHCI read of nonexist reg: 0x%02""nonexistent"
Quoted 12 lines
hw/sd/npcm7xx_sdhci.c new file +12
-0+ HWADDR_PRIx, addr); +break ; + } + +return val; +} + +static void npcm7xx_sdhci_write (void *opaque,hwaddr addr,uint64_t val, +unsigned int size) +{ +NPCM7xxSDHCIState *s = opaque; +
Quoted 8 lines
hw/sd/npcm7xx_sdhci.c line 60
Quoted 6 lines
hw/sd/npcm7xx_sdhci.c new file +6
-0+switch (addr) { +case NPCM7XX_BOOTTOCTRL : + s->regs.boottoctrl = val; +break ; +default : + qemu_log_mask(LOG_GUEST_ERROR, "SDHCI write of nonexist reg: 0x%02"ditto
Fixed while applying.
r~
PATCH v2 2/5 hw/arm: Add Nuvoton SD module to board
In reply to Hao WuFrom: Shengtan Mao <[email protected]>
--- hw/arm/npcm7xx.c | 12 +++++++++++- include/hw/arm/npcm7xx.h | 2 ++ 2 files changed, 13 insertions(+), 1 deletion(-)
hw/arm/npcm7xx.c +11 -1
@@ -63,6 +63,8 @@#define NPCM7XX_ROM_BA (0xffff0000)#define NPCM7XX_ROM_SZ (64 * KiB) +/* SDHCI Modules */ +#define NPCM7XX_MMC_BA (0xf0842000)/* Clock configuration values to be fixed up when bypassing bootloader */
@@ -83,6 +85,7 @@ enum NPCM7xxInterrupt {NPCM7XX_UART3_IRQ ,NPCM7XX_EMC1RX_IRQ =15 ,NPCM7XX_EMC1TX_IRQ , +NPCM7XX_MMC_IRQ =26 ,NPCM7XX_TIMER0_IRQ =32 ,/* Timer Module 0 */ NPCM7XX_TIMER1_IRQ , NPCM7XX_TIMER2_IRQ,
@@ -443,6 +446,8 @@ static void npcm7xx_init(Object *obj)for (i =0 ; i <ARRAY_SIZE (s->emc); i++) {object_initialize_child (obj,"emc[*]" , &s->emc[i],TYPE_NPCM7XX_EMC ); } + +object_initialize_child (obj,"mmc" , &s->mmc,TYPE_NPCM7XX_SDHCI ); }static void npcm7xx_realize (DeviceState *dev,Error **errp)
@@ -707,6 +712,12 @@ static void npcm7xx_realize(DeviceState *dev, Error **errp) &error_abort);memory_region_add_subregion (get_system_memory (),NPCM7XX_ROM_BA , &s->irom); +/* SDHCI */ +sysbus_realize (SYS_BUS_DEVICE (&s->mmc), &error_abort); +sysbus_mmio_map (SYS_BUS_DEVICE (&s->mmc),0 ,NPCM7XX_MMC_BA ); +sysbus_connect_irq (SYS_BUS_DEVICE (&s->mmc),0 , +npcm7xx_irq (s,NPCM7XX_MMC_IRQ )); +create_unimplemented_device ("npcm7xx.shm" ,0xc0001000 ,4 * KiB);create_unimplemented_device ("npcm7xx.vdmx" ,0xe0800000 ,4 * KiB);create_unimplemented_device ("npcm7xx.pcierc" ,0xe1000000 ,64 * KiB);
@@ -736,7 +747,6 @@ static void npcm7xx_realize(DeviceState *dev, Error **errp)create_unimplemented_device ("npcm7xx.usbd[8]" ,0xf0838000 ,4 * KiB);create_unimplemented_device ("npcm7xx.usbd[9]" ,0xf0839000 ,4 * KiB);create_unimplemented_device ("npcm7xx.sd" ,0xf0840000 ,8 * KiB); -create_unimplemented_device ("npcm7xx.mmc" ,0xf0842000 ,8 * KiB);create_unimplemented_device ("npcm7xx.pcimbx" ,0xf0848000 ,512 * KiB);create_unimplemented_device ("npcm7xx.aes" ,0xf0858000 ,4 * KiB);create_unimplemented_device ("npcm7xx.des" ,0xf0859000 ,4 * KiB);
include/hw/arm/npcm7xx.h +2 -0
@@ -35,6 +35,7 @@#include "hw/usb/hcd-ehci.h" #include "hw/usb/hcd-ohci.h" #include "target/arm/cpu.h" +#include "hw/sd/npcm7xx_sdhci.h" #define NPCM7XX_MAX_NUM_CPUS (2)
@@ -103,6 +104,7 @@ typedef struct NPCM7xxState {OHCISysBusState ohci;NPCM7xxFIUState fiu[2 ];NPCM7xxEMCState emc[2 ]; +NPCM7xxSDHCIState mmc; } NPCM7xxState;#define TYPE_NPCM7XX "npcm7xx"
Signature · 1 line
2.33.0.882.g93a45727a2-goog
Re: [PATCH v2 2/5] hw/arm: Add Nuvoton SD module to board
Quoted 8 lines · Hao Wu
From: Shengtan Mao <[email protected]>
Signed-off-by Shengtan Mao <[email protected]>Reviewed-by Hao Wu <[email protected]>Reviewed-by Chris Rauer <[email protected]>Reviewed-by Tyrone Ting <[email protected]>Signed-off-by Hao Wu <[email protected]>
thanks
-- PMM
PATCH v2 3/5 hw/arm: Attach MMC to quanta-gbs-bmc
In reply to Hao WuFrom: Shengtan Mao <[email protected]>
--- hw/arm/npcm7xx_boards.c | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+)
hw/arm/npcm7xx_boards.c +20 -0
@@ -27,6 +27,9 @@#include "qemu-common.h" #include "qemu/datadir.h" #include "qemu/units.h" +#include "sysemu/blockdev.h" +#include "sysemu/sysemu.h" +#include "sysemu/block-backend.h" #define NPCM750_EVB_POWER_ON_STRAPS 0x00001ff7#define QUANTA_GSJ_POWER_ON_STRAPS 0x00001fff
@@ -81,6 +84,22 @@ static void npcm7xx_connect_dram(NPCM7xxState *soc, MemoryRegion *dram) &error_abort); } +static void sdhci_attach_drive (SDHCIState *sdhci) +{ +DriveInfo *di =drive_get_next (IF_SD ); +BlockBackend *blk = di ?blk_by_legacy_dinfo (di) :NULL ; + +BusState *bus =qdev_get_child_bus (DEVICE (sdhci),"sd-bus" ); +if (bus ==NULL ) { +error_report ("No SD bus found in SOC object" ); +exit (1 ); + } + +DeviceState *carddev =qdev_new (TYPE_SD_CARD ); +qdev_prop_set_drive_err (carddev,"drive" , blk, &error_fatal); +qdev_realize_and_unref (carddev, bus, &error_fatal); +} +static NPCM7xxState *npcm7xx_create_soc (MachineState *machine,uint32_t hw_straps) {
@@ -355,6 +374,7 @@ static void quanta_gbs_init(MachineState *machine) drive_get(IF_MTD, 0, 0));quanta_gbs_i2c_init (soc); +sdhci_attach_drive (&soc->mmc.sdhci);npcm7xx_load_kernel (machine, soc); }
Signature · 1 line
2.33.0.882.g93a45727a2-goog
PATCH v2 4/5 tests/qtest/libqos: add SDHCI commands
In reply to Hao WuFrom: Shengtan Mao <[email protected]>
--- tests/qtest/libqos/meson.build | 1 + tests/qtest/libqos/sdhci-cmd.c | 116 +++++++++++++++++++++++++++++++++ tests/qtest/libqos/sdhci-cmd.h | 70 ++++++++++++++++++++ 3 files changed, 187 insertions(+) create mode 100644 tests/qtest/libqos/sdhci-cmd.c create mode 100644 tests/qtest/libqos/sdhci-cmd.h
tests/qtest/libqos/meson.build +1 -0
@@ -5,6 +5,7 @@ libqos_srcs = files('../libqtest.c', 'fw_cfg.c', 'malloc.c', 'libqos.c', + 'sdhci-cmd.c', # spapr 'malloc-spapr.c',
tests/qtest/libqos/sdhci-cmd.c new file +116 -0
116 lines not on this page · raw message
tests/qtest/libqos/sdhci-cmd.h new file +70 -0
70 lines not on this page · raw message
Signature · 1 line
2.33.0.882.g93a45727a2-goog
Re: [PATCH v2 4/5] tests/qtest/libqos: add SDHCI commands
Quoted 8 lines · Hao Wu
From: Shengtan Mao <[email protected]>
Signed-off-by Shengtan Mao <[email protected]>Reviewed-by Hao Wu <[email protected]>Reviewed-by Chris Rauer <[email protected]>Reviewed-by Tyrone Ting <[email protected]>Signed-off-by Hao Wu <[email protected]>
Quoted 7 lines
--- tests/qtest/libqos/meson.build | 1 + tests/qtest/libqos/sdhci-cmd.c | 116 +++++++++++++++++++++++++++++++++ tests/qtest/libqos/sdhci-cmd.h | 70 ++++++++++++++++++++ 3 files changed, 187 insertions(+) create mode 100644 tests/qtest/libqos/sdhci-cmd.c create mode 100644 tests/qtest/libqos/sdhci-cmd.h
thanks
-- PMM
PATCH v2 5/5 tests/qtest: add qtests for npcm7xx sdhci
In reply to Hao WuFrom: Shengtan Mao <[email protected]>
--- tests/qtest/meson.build | 1 + tests/qtest/npcm7xx_sdhci-test.c | 209 +++++++++++++++++++++++++++++++ 2 files changed, 210 insertions(+) create mode 100644 tests/qtest/npcm7xx_sdhci-test.c
tests/qtest/meson.build +1 -0
@@ -157,6 +157,7 @@ qtests_npcm7xx = \ 'npcm7xx_gpio-test', 'npcm7xx_pwm-test', 'npcm7xx_rng-test', + 'npcm7xx_sdhci-test', 'npcm7xx_smbus-test', 'npcm7xx_timer-test', 'npcm7xx_watchdog_timer-test'] + \
tests/qtest/npcm7xx_sdhci-test.c new file +209 -0
209 lines not on this page · raw message
Signature · 1 line
2.33.0.882.g93a45727a2-goog
Re: [PATCH v2 5/5] tests/qtest: add qtests for npcm7xx sdhci
Quoted 8 lines · Hao Wu
From: Shengtan Mao <[email protected]>
Signed-off-by Shengtan Mao <[email protected]>Reviewed-by Hao Wu <[email protected]>Reviewed-by Chris Rauer <[email protected]>Reviewed-by Tyrone Ting <[email protected]>Signed-off-by Hao Wu <[email protected]>
thanks
-- PMM
Re: [PATCH v2 5/5] tests/qtest: add qtests for npcm7xx sdhci
In reply to Hao WuQuoted 9 lines · Hao Wu
tests/qtest/npcm7xx_sdhci-test.c new file +9
-0+static void write_sdread (QTestState *qts,const char *msg) +{ +size_t len =strlen (msg); +char *rmsg =g_malloc (len); + +/* write message to sd */ +int fd =open (sd_path,O_WRONLY ); +int ret; +
tests/qtest/npcm7xx_sdhci-test.c line 70
Quoted 10 lines
tests/qtest/npcm7xx_sdhci-test.c new file +10
-0+g_assert (fd >0 ); + ret =write (fd, msg, len); +g_assert (ret == len); + ret =close (fd); +g_assert (ret ==0 ); + +/* read message using sdhci */ + ret =sdhci_read_cmd (qts,NPCM7XX_MMC_BA , rmsg, len); +g_assert (ret == len); +g_assert (!strcmp (rmsg, msg));
Test case bug: you're not including the terminating 0 in len, which means that strcmp cannot be expected to work.
Either use memcmp or add 1 to len at the top.
Quoted 9 lines
tests/qtest/npcm7xx_sdhci-test.c new file +9
-0+static void sdwrite_read (QTestState *qts,const char *msg) +{ +size_t len =strlen (msg); +char *rmsg =g_malloc (len); + +/* write message using sdhci */ +sdhci_write_cmd (qts,NPCM7XX_MMC_BA , msg, len,NPCM7XX_BLK_SIZE ); + +/* read message from sd */
tests/qtest/npcm7xx_sdhci-test.c line 104
Quoted 10 lines
tests/qtest/npcm7xx_sdhci-test.c new file +10
-0+int fd =open (sd_path,O_RDONLY ); +int ret; + +g_assert (fd >0 ); + ret =read (fd, rmsg, len); +g_assert (ret == len); + ret =close (fd); +g_assert (ret ==0 ); + +g_assert (!strcmp (rmsg, msg));
Likewise.
https://app.travis-ci.com/gitlab/qemu-project/qemu/jobs/546307442#L9369
r~