Fix MMC card detection for Realview boards
cover Fix MMC card detection for Realview boards
This patchset fixes a number of problems which were preventing Linux on Realview boards (EB926, EB 11MPCore, PB-A8 and PBX) from recognising the presence of an MMC card. Basically the PL181 needs to export some output pins for card status, which we can then wire up to both a system register and a PL061 GPIO module. However we weren't actually instantiating the PL061 and in any case the ID registers weren't correct for Linux to detect it.
Combined with the SD card model patch I posted earlier
(http://patchwork.ozlabs.org/patch/83594/) these patches allow Linux on a PBX to detect and mount an SD card rootfs.
(I'm doing this work not for the sake of the realview boards, but because it's also mostly necessary for the Versatile Express model patchset I'm cleaning up and hope to post shortly.)
Peter Maydell (5):
hw/pl181: Implement GPIO output pins for card status hw/arm_sysctl.c: Wire MCI register MMC card status bits to GPIO inputs hw/pl061.c: Implement ARM PL061 as well as Luminary one hw/irq: Add qemu_irq_split() so one GPIO output can feed two inputs hw/realview: Wire up the MMC card status
hw/arm_sysctl.c | 47 ++++++++++++++++++++++++++++++++++++++++++++++- hw/irq.c | 15 +++++++++++++++ hw/irq.h | 3 +++ hw/pl061.c | 23 +++++++++++++++++++---- hw/pl181.c | 6 ++++++ hw/primecell.h | 4 ++++ hw/realview.c | 29 ++++++++++++++++++++++++++--- hw/stellaris.c | 2 +- 8 files changed, 120 insertions(+), 9 deletions(-)
PATCH 1/5 hw/pl181: Implement GPIO output pins for card status
Add two GPIO output pins to the PL181 model to indicate the card present and readonly status information. On ARM boards these usually are reflected in a system register.
--- hw/pl181.c | 6 ++++++ 1 files changed, 6 insertions(+), 0 deletions(-)
hw/pl181.c +6 -0
@@ -47,6 +47,8 @@ typedef struct {int linux_hack;uint32_t fifo[PL181_FIFO_LEN ];qemu_irq irq[2 ]; +/* GPIO outputs for 'card is readonly' and 'card inserted' */ +qemu_irq cardstatus[2 ]; } pl181_state;#define PL181_CMD_INDEX 0x3f
@@ -444,6 +446,9 @@ static void pl181_reset(void *opaque) s->linux_hack =0 ; s->mask[0 ] =0 ; s->mask[1 ] =0 ; + +/* We can assume our GPIO outputs have been wired up now */ +sd_set_cb (s->card, s->cardstatus[0 ], s->cardstatus[1 ]); }static int pl181_init (SysBusDevice *dev)
@@ -457,6 +462,7 @@ static int pl181_init(SysBusDevice *dev)sysbus_init_mmio (dev,0x1000 , iomemtype);sysbus_init_irq (dev, &s->irq[0 ]);sysbus_init_irq (dev, &s->irq[1 ]); +qdev_init_gpio_out (&s->busdev.qdev, s->cardstatus,2 ); dinfo =drive_get_next (IF_SD ); s->card =sd_init (dinfo ? dinfo->bdrv :NULL ,0 );qemu_register_reset (pl181_reset, s);
Signature · 1 line
1.7.1
PATCH 2/5 hw/arm_sysctl.c: Wire MCI register MMC card status bits to GPIO inputs
In reply to Peter MaydellImplement some GPIO inputs which a board can connect up to set the MMC card status bits in the MCI register.
--- hw/arm_sysctl.c | 47 ++++++++++++++++++++++++++++++++++++++++++++++- hw/primecell.h | 4 ++++ 2 files changed, 50 insertions(+), 1 deletions(-)
hw/arm_sysctl.c +46 -1
@@ -26,6 +26,7 @@ typedef struct {uint32_t nvflags;uint32_t resetlevel;uint32_t proc_id; +uint32_t sys_mci; } arm_sysctl_state;static const VMStateDescription vmstate_arm_sysctl = {
@@ -44,6 +45,21 @@ static const VMStateDescription vmstate_arm_sysctl = { } }; +/* The PB926 actually uses a different format for +* its SYS_ID register. Fortunately the bits which are +* board type on later boards are distinct. +*/ +#define BOARD_ID_PB926 0x100 +#define BOARD_ID_EB 0x140 +#define BOARD_ID_PBA8 0x178 +#define BOARD_ID_PBX 0x182 + +static int board_id (arm_sysctl_state *s) +{ +/* Extract the board ID field from the SYS_ID register value */ +return (s->sys_id >>16 ) &0xfff ; +} +static void arm_sysctl_reset (DeviceState *d) {arm_sysctl_state *s =FROM_SYSBUS (arm_sysctl_state,sysbus_from_qdev (d));
@@ -92,7 +108,7 @@ static uint32_t arm_sysctl_read(void *opaque, target_phys_addr_t offset)case 0x44 :/* PCICTL */ return 1 ;case 0x48 :/* MCI */ -return 0 ; +return s->sys_mci;case 0x4c :/* FLASH */ return 0 ;case 0x50 :/* CLCD */
@@ -218,6 +234,34 @@ static CPUWriteMemoryFunc * const arm_sysctl_writefn[] = {arm_sysctl_write }; +static void arm_sysctl_gpio_set (void *opaque,int line,int level) +{ +arm_sysctl_state *s = (arm_sysctl_state *)opaque; +switch (line) { +case ARM_SYSCTL_GPIO_MMC_WPROT : + { +/* For PB926 and EB write-protect is bit 2 of SYS_MCI; +* for all later boards it is bit 1. +*/ +int bit =2 ; +if ((board_id (s) ==BOARD_ID_PB926 ) || (board_id (s) ==BOARD_ID_EB )) { + bit =4 ; + } + s->sys_mci &= ~bit; +if (level) { + s->sys_mci |= bit; + } +break ; + } +case ARM_SYSCTL_GPIO_MMC_CARDIN : + s->sys_mci &= ~1 ; +if (level) { + s->sys_mci |=1 ; + } +break ; + } +} +static int arm_sysctl_init1 (SysBusDevice *dev) {arm_sysctl_state *s =FROM_SYSBUS (arm_sysctl_state, dev);
@@ -227,6 +271,7 @@ static int arm_sysctl_init1(SysBusDevice *dev) arm_sysctl_writefn, s, DEVICE_NATIVE_ENDIAN);sysbus_init_mmio (dev,0x1000 , iomemtype); +qdev_init_gpio_in (&s->busdev.qdev, arm_sysctl_gpio_set,2 );/* ??? Save/restore. */ return 0 ; }
hw/primecell.h +4 -0
@@ -11,4 +11,8 @@ void *pl080_init(uint32_t base, qemu_irq irq, int nchannels);/* arm_sysctl.c */ void arm_sysctl_init (uint32_t base,uint32_t sys_id,uint32_t proc_id); +/* arm_sysctl GPIO lines */ +#define ARM_SYSCTL_GPIO_MMC_WPROT 0 +#define ARM_SYSCTL_GPIO_MMC_CARDIN 1 +#endif
Signature · 1 line
1.7.1
PATCH 3/5 hw/pl061.c: Implement ARM PL061 as well as Luminary one
In reply to Peter MaydellARM's PL061 has a different set of ID registers to the one in the Luminary Stellaris; implement this so that the Linux driver can identify the Realview PBX PL061 correctly.
--- hw/pl061.c | 23 +++++++++++++++++++---- hw/stellaris.c | 2 +- 2 files changed, 20 insertions(+), 5 deletions(-)
hw/pl061.c +19 -4
@@ -24,6 +24,8 @@ do { fprintf(stderr, "pl061: error: " fmt , ## __VA_ARGS__);} while (0)#endif static const uint8_t pl061_id[12 ] = + {0x00 ,0x00 ,0x00 ,0x00 ,0x61 ,0x10 ,0x04 ,0x00 ,0x0d ,0xf0 ,0x05 ,0xb1 }; +static const uint8_t pl061_id_luminary[12 ] = {0x00 ,0x00 ,0x00 ,0x00 ,0x61 ,0x00 ,0x18 ,0x01 ,0x0d ,0xf0 ,0x05 ,0xb1 }; typedef struct {
@@ -50,6 +52,7 @@ typedef struct {uint8_t float_high;qemu_irq irq;qemu_irq out[8 ]; +const unsigned char *id; } pl061_state;static void pl061_update (pl061_state *s)
@@ -83,7 +86,7 @@ static uint32_t pl061_read(void *opaque, target_phys_addr_t offset)pl061_state *s = (pl061_state *)opaque;if (offset >=0xfd0 && offset <0x1000 ) { -return pl061_id[(offset -0xfd0 ) >>2 ]; +return s->id[(offset -0xfd0 ) >>2 ]; }if (offset <0x400 ) {return s->data & (offset >>2 );
@@ -291,11 +294,11 @@ static int pl061_load(QEMUFile *f, void *opaque, int version_id)return 0 ; } -static int pl061_init (SysBusDevice *dev) +static int pl061_init (SysBusDevice *dev,const unsigned char *id) {int iomemtype;pl061_state *s =FROM_SYSBUS (pl061_state, dev); - + s->id = id; iomemtype =cpu_register_io_memory (pl061_readfn, pl061_writefn, s,DEVICE_NATIVE_ENDIAN );
@@ -308,10 +311,22 @@ static int pl061_init(SysBusDevice *dev)return 0 ; } +static int pl061_init_luminary (SysBusDevice *dev) +{ +return pl061_init (dev, pl061_id_luminary); +} + +static int pl061_init_arm (SysBusDevice *dev) +{ +return pl061_init (dev, pl061_id); +} +static void pl061_register_devices (void ) {sysbus_register_dev ("pl061" ,sizeof (pl061_state), - pl061_init); + pl061_init_arm); +sysbus_register_dev ("pl061_luminary" ,sizeof (pl061_state), + pl061_init_luminary); }device_init (pl061_register_devices)
hw/stellaris.c +1 -1
@@ -1338,7 +1338,7 @@ static void stellaris_init(const char *kernel_filename, const char *cpu_model,for (i =0 ; i <7 ; i++) {if (board->dc4 & (1 << i)) { - gpio_dev[i] =sysbus_create_simple ("pl061" , gpio_addr[i], + gpio_dev[i] =sysbus_create_simple ("pl061_luminary" , gpio_addr[i], pic[gpio_irq[i]]);for (j =0 ; j <8 ; j++) { gpio_in[i][j] =qdev_get_gpio_in (gpio_dev[i], j);
Signature · 1 line
1.7.1
PATCH 4/5 hw/irq: Add qemu_irq_split() so one GPIO output can feed two inputs
In reply to Peter MaydellAdd a qemu_irq_split() function which allows a board to wire a single GPIO output up to two GPIO inputs. This is needed for realview boards, where the MMC card status is visible both in a system register and via a PL061 GPIO module.
--- hw/irq.c | 15 +++++++++++++++ hw/irq.h | 3 +++ 2 files changed, 18 insertions(+), 0 deletions(-)
hw/irq.c +15 -0
@@ -75,3 +75,18 @@ qemu_irq qemu_irq_invert(qemu_irq irq)qemu_irq_raise (irq);return qemu_allocate_irqs (qemu_notirq, irq,1 )[0 ]; } + +static void qemu_splitirq (void *opaque,int line,int level) +{ +struct IRQState **irq = opaque; + irq[0 ]->handler (irq[0 ]->opaque, irq[0 ]->n, level); + irq[1 ]->handler (irq[1 ]->opaque, irq[1 ]->n, level); +} + +qemu_irq qemu_irq_split (qemu_irq irq1,qemu_irq irq2) +{ +qemu_irq *s =qemu_mallocz (2 *sizeof (qemu_irq)); + s[0 ] = irq1; + s[1 ] = irq2; +return qemu_allocate_irqs (qemu_splitirq, s,1 )[0 ]; +}
hw/irq.h +3 -0
@@ -30,4 +30,7 @@ void qemu_free_irqs(qemu_irq *s);/* Returns a new IRQ with opposite polarity. */ qemu_irq qemu_irq_invert (qemu_irq irq); +/* Returns a new IRQ which feeds into both the passed IRQs */ +qemu_irq qemu_irq_split (qemu_irq irq1,qemu_irq irq2); +#endif
Signature · 1 line
1.7.1
PATCH 5/5 hw/realview: Wire up the MMC card status
In reply to Peter MaydellInstantiate the three PL061 GPIO modules the realview boards have. Connect the MMC card status outputs of the PL181 MMC controller to both the system registers and the GPIO module which handles internal devices.
--- hw/realview.c | 29 ++++++++++++++++++++++++++--- 1 files changed, 26 insertions(+), 3 deletions(-)
hw/realview.c +26 -3
@@ -138,10 +138,11 @@ static void realview_init(ram_addr_t ram_size, {CPUState *env =NULL ;ram_addr_t ram_offset; -DeviceState *dev; +DeviceState *dev, *sysctl, *gpio2;SysBusDevice *busdev;qemu_irq *irqp;qemu_irq pic[64 ]; +qemu_irq mmc_irq[2 ];PCIBus *pci_bus;NICInfo *nd;i2c_bus *i2c;
@@ -218,7 +219,11 @@ static void realview_init(ram_addr_t ram_size, } sys_id = is_pb ?0x01780500 :0xc1400400 ; -arm_sysctl_init (0x10000000 , sys_id, proc_id); + sysctl =qdev_create (NULL ,"realview_sysctl" ); +qdev_prop_set_uint32 (sysctl,"sys_id" , sys_id); +qdev_init_nofail (sysctl); +qdev_prop_set_uint32 (sysctl,"proc_id" , proc_id); +sysbus_mmio_map (sysbus_from_qdev (sysctl),0 ,0x10000000 );if (is_mpcore) { dev =qdev_create (NULL , is_pb ?"a9mpcore_priv" :"realview_mpcore" );
@@ -257,9 +262,27 @@ static void realview_init(ram_addr_t ram_size,sysbus_create_simple ("sp804" ,0x10011000 , pic[4 ]);sysbus_create_simple ("sp804" ,0x10012000 , pic[5 ]); +sysbus_create_simple ("pl061" ,0x10013000 , pic[6 ]); +sysbus_create_simple ("pl061" ,0x10014000 , pic[7 ]); + gpio2 =sysbus_create_simple ("pl061" ,0x10015000 , pic[8 ]); +sysbus_create_simple ("pl110_versatile" ,0x10020000 , pic[23 ]); -sysbus_create_varargs ("pl181" ,0x10005000 , pic[17 ], pic[18 ],NULL ); + dev =sysbus_create_varargs ("pl181" ,0x10005000 , pic[17 ], pic[18 ],NULL ); +/* Wire up MMC card detect and read-only signals. These have +* to go to both the PL061 GPIO and the sysctl register. +* Note that the PL181 orders these lines (readonly,inserted) +* and the PL061 has them the other way about. Also the card +* detect line is inverted. +*/ + mmc_irq[0 ] =qemu_irq_split ( +qdev_get_gpio_in (sysctl,ARM_SYSCTL_GPIO_MMC_WPROT ), +qdev_get_gpio_in (gpio2,1 )); + mmc_irq[1 ] =qemu_irq_split ( +qdev_get_gpio_in (sysctl,ARM_SYSCTL_GPIO_MMC_CARDIN ), +qemu_irq_invert (qdev_get_gpio_in (gpio2,0 ))); +qdev_connect_gpio_out (dev,0 , mmc_irq[0 ]); +qdev_connect_gpio_out (dev,1 , mmc_irq[1 ]);sysbus_create_simple ("pl031" ,0x10017000 , pic[10 ]);
Signature · 1 line
1.7.1
Quoted 24 lines · Peter Maydell
This patchset fixes a number of problems which were preventing Linux on Realview boards (EB926, EB 11MPCore, PB-A8 and PBX) from recognising the presence of an MMC card. Basically the PL181 needs to export some output pins for card status, which we can then wire up to both a system register and a PL061 GPIO module. However we weren't actually instantiating the PL061 and in any case the ID registers weren't correct for Linux to detect it.
Combined with the SD card model patch I posted earlier
(http://patchwork.ozlabs.org/patch/83594/) these patches allow Linux on a PBX to detect and mount an SD card rootfs.(I'm doing this work not for the sake of the realview boards, but because it's also mostly necessary for the Versatile Express model patchset I'm cleaning up and hope to post shortly.)
Peter Maydell (5):
hw/pl181: Implement GPIO output pins for card statushw/arm_sysctl.c: Wire MCI register MMC card status bits to GPIO inputshw/pl061.c: Implement ARM PL061 as well as Luminary one hw/irq: Addqemu_irq_split()so one GPIO output can feed two inputs hw/realview: Wire up the MMC card status
Quoted 10 lines
hw/arm_sysctl.c | 47 ++++++++++++++++++++++++++++++++++++++++++++++- hw/irq.c | 15 +++++++++++++++ hw/irq.h | 3 +++ hw/pl061.c | 23 +++++++++++++++++++---- hw/pl181.c | 6 ++++++ hw/primecell.h | 4 ++++ hw/realview.c | 29 ++++++++++++++++++++++++++--- hw/stellaris.c | 2 +- 8 files changed, 120 insertions(+), 9 deletions(-)
Thanks all applied.
Signature · 2 lines
Aurelien Jarno GPG: 1024D/F1BCDB73 [email protected] http://www.aurel32.net