hw/arm: Add MMC device for NPCM7XX boards
v3 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 v2:
1. Fix an error use of strcmp in qtest.
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.1.1089.g2158813163f-goog
PATCH v3 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.1.1089.g2158813163f-goog
PATCH v3 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.1.1089.g2158813163f-goog
PATCH v3 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.1.1089.g2158813163f-goog
PATCH v3 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.1.1089.g2158813163f-goog
PATCH v3 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.1.1089.g2158813163f-goog