onenand, omap_gpmc fixes, features
v2 cover onenand, omap_gpmc fixes, features
This patchset is primarily features and bugfixes for the omap_gpmc device from the Meego tree.
We start by adding a new sysbus function to get the MemoryRegion* for a sysbus MMIO region. This was discussed in
http://www.mail-archive.com/[email protected]/msg59535.html
and as noted there can also be used to clean up other things, so it's not just an omap_gpmc thing.
The bulk of the onenand qdevification patch was in an earlier series I posted; this update makes it work with MemoryRegions.
The patches from "omap_gpmc: Take omap_mpu_state* in omap_gpmc_init" onwards are omap3 preparation; the features they add aren't used in the omap2 models currently in master. However I'd rather get things reviewed in more manageable chunks than save them all up for when I have omap3.c ready for commit...
Changes v1->v2:
* split out the onenand_command() change from qdevify patch
* dropped onenand_init() in favour of just doing the qdev create, configure,realize inline in nseries.c. This turns out to look better, I think, because you can see what that string of integer arguments to onenand_init() are actually doing.
(patch 1 and the old 3..17, now 4..18, are unchanged)
I've updated (rebased!) the git branch:
git://git.linaro.org/people/pmaydell/qemu-arm.git omap-for-upstream
which should be suitable for pulling if desired.
Juha Riihimäki (6):
hw/onenand: Remove unnecessary argument from onenand_command() hw/onenand: Qdevify
hw/onenand: Minor spacing fixes
omap_gpmc: Take omap_mpu_state* in omap_gpmc_init
omap_gpmc: Calculate revision from OMAP model
omap_gpmc: Accept a zero mask field on omap3630
Peter Maydell (12):
hw/sysbus: Add sysbus_mmio_get_region()
omap_gpmc: Clean up omap_gpmc_attach MemoryRegion conversion
omap_gpmc: Refactor omap_gpmc_cs_map and omap_gpmc_cs_unmap
omap_gpmc: GPMC_IRQSTATUS is write-one-to-clear
omap_gpmc: Wire up the GPMC IRQ correctly
omap_gpmc: Fix handling of FIFOTHRESHOLDSTATUS bit
omap_gpmc: Reindent misindented switch statements
omap_gpmc: Support NAND devices
hw/omap.h: Add OMAP 3630 to omap_mpu_model enumeration
omap_gpmc: Pull prefetch engine data into sub-struct
omap: Wire up the DMA request line to the GPMC
omap_gpmc: Implement prefetch engine
hw/flash.h | 7 +- hw/nseries.c | 29 ++- hw/omap.h | 14 +- hw/omap2.c | 3 +- hw/omap_gpmc.c | 713 +++++++++++++++++++++++++++++++++++++++++++++----------- hw/onenand.c | 164 ++++++++++---- hw/sysbus.c | 5 + hw/sysbus.h | 1 + 8 files changed, 733 insertions(+), 203 deletions(-)
PATCH v2 1/18 hw/sysbus: Add sysbus_mmio_get_region()
Add a sysbus_mmio_get_region() which allows users of sysbus devices to turn a (SysBusDevice*, mmioidx) tuple into a MemoryRegion*. This enables some useful simplifications of devices which pass through another device's mmio region (either directly or by implementing some kind of memory controller device).
--- hw/sysbus.c | 5 +++++ hw/sysbus.h | 1 + 2 files changed, 6 insertions(+), 0 deletions(-)
hw/sysbus.c +5 -0
@@ -131,6 +131,11 @@ void sysbus_init_mmio_region(SysBusDevice *dev, MemoryRegion *memory) dev->mmio[n].memory = memory; } +MemoryRegion *sysbus_mmio_get_region (SysBusDevice *dev,int n) +{ +return dev->mmio[n].memory; +} +void sysbus_init_ioports (SysBusDevice *dev,pio_addr_t ioport,pio_addr_t size) {pio_addr_t i;
hw/sysbus.h +1 -0
@@ -50,6 +50,7 @@ void sysbus_init_mmio(SysBusDevice *dev, target_phys_addr_t size,void sysbus_init_mmio_cb2 (SysBusDevice *dev,mmio_mapfunc cb,mmio_mapfunc unmap);void sysbus_init_mmio_region (SysBusDevice *dev,MemoryRegion *memory); +MemoryRegion *sysbus_mmio_get_region (SysBusDevice *dev,int n);void sysbus_init_irq (SysBusDevice *dev,qemu_irq *p);void sysbus_pass_irq (SysBusDevice *dev,SysBusDevice *target);void sysbus_init_ioports (SysBusDevice *dev,pio_addr_t ioport,pio_addr_t size);
Signature · 1 line
1.7.1
PATCH v2 2/18 hw/onenand: Remove unnecessary argument from onenand_command()
In reply to Peter MaydellFrom: Juha Riihimäki <[email protected]>
Refactor onenand_command() -- since it is essentially a method of the device object, it doesn't make sense to pass in something as an argument which is one of the object's own member fields.
--- hw/onenand.c | 8 ++++---- 1 files changed, 4 insertions(+), 4 deletions(-)
hw/onenand.c +4 -4
@@ -326,7 +326,7 @@ fail:return 1 ; } -static void onenand_command (OneNANDState *s,int cmd) +static void onenand_command (OneNANDState *s) {int b;int sec;
@@ -346,7 +346,7 @@ static void onenand_command(OneNANDState *s, int cmd) s->data[(s->bufaddr >> 2) & 1][1] : s->boot[1]; \ buf += (s->bufaddr &3 ) <<4 ; -switch (cmd) { +switch (s->command) {case 0x00 :/* Load single/multiple sector data unit into buffer */ SETADDR (ONEN_BUF_BLOCK ,ONEN_BUF_PAGE )
@@ -527,7 +527,7 @@ static void onenand_command(OneNANDState *s, int cmd) s->status |=ONEN_ERR_CMD ; s->intstatus |=ONEN_INT ;fprintf (stderr,"%s: unknown OneNAND command %x\n" , - __FUNCTION__, cmd); + __func__, s->command); }onenand_intr_update (s);
@@ -659,7 +659,7 @@ static void onenand_write(void *opaque, target_phys_addr_t addr,if (s->intstatus & (1 <<15 ))break ; s->command = value; -onenand_command (s, s->command); +onenand_command (s);break ;case 0xf221 :/* System Configuration 1 */ s->config[0 ] = value;
Signature · 1 line
1.7.1
PATCH v2 3/18 hw/onenand: Qdevify
In reply to Peter MaydellFrom: Juha Riihimäki <[email protected]>
Qdevify the ONENAND device.
--- hw/flash.h | 7 +--- hw/nseries.c | 25 +++++++--- hw/onenand.c | 142 ++++++++++++++++++++++++++++++++++++++++++++-------------- 3 files changed, 127 insertions(+), 47 deletions(-)
hw/flash.h +1 -6
@@ -36,12 +36,7 @@ uint32_t nand_getbuswidth(DeviceState *dev);#define NAND_MFR_MICRON 0x2c/* onenand.c */ -void onenand_base_update (void *opaque,target_phys_addr_t new); -void onenand_base_unmap (void *opaque); -void *onenand_init (BlockDriverState *bdrv, -uint16_t man_id,uint16_t dev_id,uint16_t ver_id, -int regshift,qemu_irq irq); -void *onenand_raw_otp (void *opaque); +void *onenand_raw_otp (DeviceState *onenand_device);/* ecc.c */ typedef struct {
hw/nseries.c +18 -7
@@ -33,6 +33,7 @@#include "loader.h" #include "blockdev.h" #include "tusb6010.h" +#include "sysbus.h" /* Nokia N8x0 support */ struct n800_s {
@@ -52,7 +53,7 @@ struct n800_s {TUSBState *usb;void *retu;void *tahvo; -void *nand; +DeviceState *nand; };/* GPIO pins */
@@ -167,13 +168,23 @@ static void n8x0_nand_setup(struct n800_s *s)char *otp_region;DriveInfo *dinfo; - dinfo =drive_get (IF_MTD ,0 ,0 ); + s->nand =qdev_create (NULL ,"onenand" ); +qdev_prop_set_uint16 (s->nand,"manufacturer_id" ,NAND_MFR_SAMSUNG );/* Either 0x40 or 0x48 are OK for the device ID */ - s->nand =onenand_init (dinfo ? dinfo->bdrv :0 , -NAND_MFR_SAMSUNG ,0x48 ,0 ,1 , -qdev_get_gpio_in (s->cpu->gpio,N8X0_ONENAND_GPIO )); -omap_gpmc_attach (s->cpu->gpmc,N8X0_ONENAND_CS ,0 , onenand_base_update, - onenand_base_unmap, s->nand); +qdev_prop_set_uint16 (s->nand,"device_id" ,0x48 ); +qdev_prop_set_uint16 (s->nand,"version_id" ,0 ); +qdev_prop_set_int32 (s->nand,"shift" ,1 ); + dinfo =drive_get (IF_MTD ,0 ,0 ); +if (dinfo && dinfo->bdrv) { +qdev_prop_set_drive_nofail (s->nand,"drive" , dinfo->bdrv); + } +qdev_init_nofail (s->nand); +sysbus_connect_irq (sysbus_from_qdev (s->nand),0 , +qdev_get_gpio_in (s->cpu->gpio,N8X0_ONENAND_GPIO )); +omap_gpmc_attach (s->cpu->gpmc,N8X0_ONENAND_CS , +sysbus_mmio_get_region (sysbus_from_qdev (s->nand),0 ), +NULL ,NULL , + s->nand); otp_region =onenand_raw_otp (s->nand);memcpy (otp_region +0x000 , n8x0_cal_wlan_mac,sizeof (n8x0_cal_wlan_mac));
hw/onenand.c +108 -34
209 lines not on this page · raw message
Signature · 1 line
1.7.1
PATCH v2 4/18 hw/onenand: Minor spacing fixes
In reply to Peter MaydellFrom: Juha Riihimäki <[email protected]>
Minor whitespace-only cleanup (separated out from the qdevifying patch for clarity).
--- hw/onenand.c | 14 +++++++------- 1 files changed, 7 insertions(+), 7 deletions(-)
hw/onenand.c +7 -7
@@ -245,8 +245,8 @@ static inline int onenand_prog_main(OneNANDState *s, int sec, int secn,int result =0 ;if (secn >0 ) { -uint32_t size = (uint32_t ) secn *512 ; -const uint8_t *sp = (const uint8_t *) src; +uint32_t size = (uint32_t )secn *512 ; +const uint8_t *sp = (const uint8_t *)src;uint8_t *dp =0 ;if (s->bdrv_cur) { dp =g_malloc (size);
@@ -257,7 +257,7 @@ static inline int onenand_prog_main(OneNANDState *s, int sec, int secn,if (sec + secn > s->secs_cur) { result =1 ; }else { - dp = (uint8_t *) s->current + (sec <<9 ); + dp = (uint8_t *)s->current + (sec <<9 ); } }if (!result) {
@@ -299,13 +299,13 @@ static inline int onenand_prog_spare(OneNANDState *s, int sec, int secn, {int result =0 ;if (secn >0 ) { -const uint8_t *sp = (const uint8_t *) src; +const uint8_t *sp = (const uint8_t *)src;uint8_t *dp =0 , *dpp =0 ;if (s->bdrv_cur) { dp =g_malloc (512 );if (!dp ||bdrv_read (s->bdrv_cur, - s->secs_cur + (sec >>5 ), - dp,1 ) <0 ) { + s->secs_cur + (sec >>5 ), + dp,1 ) <0 ) { result =1 ; }else { dpp = dp + ((sec &31 ) <<4 );
@@ -324,7 +324,7 @@ static inline int onenand_prog_spare(OneNANDState *s, int sec, int secn, }if (s->bdrv_cur) { result =bdrv_write (s->bdrv_cur, s->secs_cur + (sec >>5 ), - dp,1 ) <0 ; + dp,1 ) <0 ; } }if (dp) {
Signature · 1 line
1.7.1
PATCH v2 5/18 omap_gpmc: Clean up omap_gpmc_attach MemoryRegion conversion
In reply to Peter MaydellNow that all callers of omap_gpmc_attach pass in a MemoryRegion*, we can remove the base_update and unmap function pointer arguments, and the opaque pointer that was passed into these callbacks.
We can also remove the base and size fields from omap_gpmc_cs_file_s as these are no longer necessary (you don't need the base/size to unmap a MemoryRegion the way you did to undo a mapping made with cpu_register_physical_memory()).
--- hw/nseries.c | 10 ++------ hw/omap.h | 4 +-- hw/omap_gpmc.c | 59 ++++++++++++++++++++----------------------------------- 3 files changed, 26 insertions(+), 47 deletions(-)
hw/nseries.c +3 -7
@@ -182,9 +182,7 @@ static void n8x0_nand_setup(struct n800_s *s)sysbus_connect_irq (sysbus_from_qdev (s->nand),0 ,qdev_get_gpio_in (s->cpu->gpio,N8X0_ONENAND_GPIO ));omap_gpmc_attach (s->cpu->gpmc,N8X0_ONENAND_CS , -sysbus_mmio_get_region (sysbus_from_qdev (s->nand),0 ), -NULL ,NULL , - s->nand); +sysbus_mmio_get_region (sysbus_from_qdev (s->nand),0 )); otp_region =onenand_raw_otp (s->nand);memcpy (otp_region +0x000 , n8x0_cal_wlan_mac,sizeof (n8x0_cal_wlan_mac));
@@ -781,10 +779,8 @@ static void n8x0_usb_setup(struct n800_s *s)TUSBState *tusb =tusb6010_init (tusb_irq);/* Using the NOR interface */ -omap_gpmc_attach (s->cpu->gpmc,N8X0_USB_ASYNC_CS , -tusb6010_async_io (tusb),NULL ,NULL , tusb); -omap_gpmc_attach (s->cpu->gpmc,N8X0_USB_SYNC_CS , -tusb6010_sync_io (tusb),NULL ,NULL , tusb); +omap_gpmc_attach (s->cpu->gpmc,N8X0_USB_ASYNC_CS ,tusb6010_async_io (tusb)); +omap_gpmc_attach (s->cpu->gpmc,N8X0_USB_SYNC_CS ,tusb6010_sync_io (tusb)); s->usb = tusb;qdev_connect_gpio_out (s->cpu->gpio,N8X0_TUSB_ENABLE_GPIO , tusb_pwr);
hw/omap.h +1 -3
@@ -120,9 +120,7 @@ void omap_sdrc_reset(struct omap_sdrc_s *s);struct omap_gpmc_s ;struct omap_gpmc_s *omap_gpmc_init (target_phys_addr_t base,qemu_irq irq);void omap_gpmc_reset (struct omap_gpmc_s *s); -void omap_gpmc_attach (struct omap_gpmc_s *s,int cs,MemoryRegion *iomem, -void (*base_upd)(void *opaque,target_phys_addr_t new), -void (*unmap)(void *opaque),void *opaque); +void omap_gpmc_attach (struct omap_gpmc_s *s,int cs,MemoryRegion *iomem);/* * Common IRQ numbers for level 1 interrupt handler
hw/omap_gpmc.c +22 -37
108 lines not on this page · raw message
Signature · 1 line
1.7.1
PATCH v2 6/18 omap_gpmc: Refactor omap_gpmc_cs_map and omap_gpmc_cs_unmap
In reply to Peter MaydellRefactor the omap_gpmc_cs_map/unmap functions:
* take the omap_gpmc_s* and a chipselect id rather than the omap_gpmc_cs_file_s*, so they have access to the general gpmc member fields
* extract the base and mask from the config registers in the functions rather than at every callsite
* check for CSVALID in the functions rather than at every callsite
--- hw/omap_gpmc.c | 56 +++++++++++++++++++++++++++++++++++--------------------- 1 files changed, 35 insertions(+), 21 deletions(-)
hw/omap_gpmc.c +35 -21
@@ -54,18 +54,25 @@ static void omap_gpmc_int_update(struct omap_gpmc_s *s)qemu_set_irq (s->irq, s->irqen & s->irqst); } -static void omap_gpmc_cs_map (struct omap_gpmc_cs_file_s *f,int base,int mask) +static void omap_gpmc_cs_map (struct omap_gpmc_s *s,int cs) { +struct omap_gpmc_cs_file_s *f = &s->cs_file[cs]; +uint32_t mask = (f->config[6 ] >>8 ) &0xf ; +uint32_t base = f->config[6 ] &0x3f ;uint32_t size;if (!f->iomem) {return ; } +if (!(f->config[6 ] & (1 <<6 ))) { +/* Do nothing unless CSVALID */ +return ; + } +/* TODO: check for overlapping regions and report access errors */ if ((mask !=0x8 && mask !=0xc && mask !=0xe && mask !=0xf ) || - (base <0 || base >=0x40 ) || - (base &0x0f & ~mask)) { + (base &0x0f & ~mask)) {fprintf (stderr,"%s: wrong cs address mapping/decoding!\n" , __FUNCTION__);return ;
@@ -83,8 +90,13 @@ static void omap_gpmc_cs_map(struct omap_gpmc_cs_file_s *f, int base, int mask) &f->container); } -static void omap_gpmc_cs_unmap (struct omap_gpmc_cs_file_s *f) +static void omap_gpmc_cs_unmap (struct omap_gpmc_s *s,int cs) { +struct omap_gpmc_cs_file_s *f = &s->cs_file[cs]; +if (!(f->config[6 ] & (1 <<6 ))) { +/* Do nothing unless CSVALID */ +return ; + }if (!f->iomem) {return ; }
@@ -110,19 +122,26 @@ void omap_gpmc_reset(struct omap_gpmc_s *s) s->preffifo =0 ; s->prefcount =0 ;for (i =0 ; i <8 ; i ++) { -if (s->cs_file[i].config[6 ] & (1 <<6 ))/* CSVALID */ -omap_gpmc_cs_unmap (s->cs_file + i); - s->cs_file[i].config[0 ] = i ?1 <<12 :0 ; +omap_gpmc_cs_unmap (s, i); s->cs_file[i].config[1 ] =0x101001 ; s->cs_file[i].config[2 ] =0x020201 ; s->cs_file[i].config[3 ] =0x10031003 ; s->cs_file[i].config[4 ] =0x10f1111 ; s->cs_file[i].config[5 ] =0 ; s->cs_file[i].config[6 ] =0xf00 | (i ?0 :1 <<6 ); -if (s->cs_file[i].config[6 ] & (1 <<6 ))/* CSVALID */ -omap_gpmc_cs_map (&s->cs_file[i], - s->cs_file[i].config[6 ] &0x1f ,/* MASKADDR */ - (s->cs_file[i].config[6 ] >>8 &0xf ));/* BASEADDR */ + + s->cs_file[i].config[6 ] =0xf00 ; +/* In theory we could probe attached devices for some CFG1 +* bits here, but we just retain them across resets as they +* were set initially by omap_gpmc_attach(). +*/ +if (i ==0 ) { + s->cs_file[i].config[0 ] &=0x00433e00 ; + s->cs_file[i].config[6 ] |=1 <<6 ;/* CSVALID */ +omap_gpmc_cs_map (s, i); + }else { + s->cs_file[i].config[0 ] &=0x00403c00 ; + } } s->ecc_cs =0 ; s->ecc_ptr =0 ;
@@ -311,13 +330,10 @@ static void omap_gpmc_write(void *opaque, target_phys_addr_t addr,break ;case 0x78 :/* GPMC_CONFIG7 */ if ((f->config[6 ] ^ value) &0xf7f ) { -if (f->config[6 ] & (1 <<6 ))/* CSVALID */ -omap_gpmc_cs_unmap (f); -if (value & (1 <<6 ))/* CSVALID */ -omap_gpmc_cs_map (f, value &0x1f ,/* MASKADDR */ - (value >>8 &0xf ));/* BASEADDR */ +omap_gpmc_cs_unmap (s, cs); + f->config[6 ] = value &0x00000f7f ; +omap_gpmc_cs_map (s, cs); } - f->config[6 ] = value &0x00000f7f ;break ;case 0x7c :/* GPMC_NAND_COMMAND */ case 0x80 :/* GPMC_NAND_ADDRESS */
@@ -407,9 +423,7 @@ void omap_gpmc_attach(struct omap_gpmc_s *s, int cs, MemoryRegion *iomem) } f = &s->cs_file[cs]; +omap_gpmc_cs_unmap (s, cs); f->iomem = iomem; - -if (f->config[6 ] & (1 <<6 ))/* CSVALID */ -omap_gpmc_cs_map (f, f->config[6 ] &0x1f ,/* MASKADDR */ - (f->config[6 ] >>8 &0xf ));/* BASEADDR */ +omap_gpmc_cs_map (s, cs); }
Signature · 1 line
1.7.1
PATCH v2 7/18 omap_gpmc: GPMC_IRQSTATUS is write-one-to-clear
In reply to Peter MaydellFix a bug in the handling of writes to GPMC_IRQSTATUS:
it behaves as "write one to clear, writing zero is ignored".
--- hw/omap_gpmc.c | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-)
hw/omap_gpmc.c +1 -1
@@ -284,7 +284,7 @@ static void omap_gpmc_write(void *opaque, target_phys_addr_t addr,break ;case 0x018 :/* GPMC_IRQSTATUS */ - s->irqen = ~value; + s->irqen &= ~value;omap_gpmc_int_update (s);break ;
Signature · 1 line
1.7.1
Re: [Qemu-devel] [PATCH v2 07/18] omap_gpmc: GPMC_IRQSTATUS is write-one-to-clear
Quoted 15 lines · Peter Maydell
Fix a bug in the handling of writes to
GPMC_IRQSTATUS:
it behaves as "write one to clear, writing zero is ignored".Signed-off-by Peter Maydell <[email protected]>---
hw/omap_gpmc.c | 2 +-1 files changed, 1 insertions(+), 1 deletions(-)hw/omap_gpmc.c +0
-0@@ -284,7 +284,7 @@ static void omap_gpmc_write(void *opaque, target_phys_addr_t addr, break;
Quoted 3 lines
case
0x018: /*GPMC_IRQSTATUS*/
- s->irqen = ~value;
+ s->irqen &= ~value;
Should we be clearing s->irqst here instead of irqen? Good catch though.
Cheers
Re: [Qemu-devel] [PATCH v2 07/18] omap_gpmc: GPMC_IRQSTATUS is write-one-to-clear
Quoted 10 lines · andrzej zaborowski
Quoted 8 lines
hw/omap_gpmc.c +0
-0@@ -284,7 +284,7 @@ static void omap_gpmc_write(void *opaque, target_phys_addr_t addr, break;case
0x018: /*GPMC_IRQSTATUS*/
- s->irqen = ~value;
+ s->irqen &= ~value;Should we be clearing
s->irqsthere instead of irqen?
Oops, you're right... (IIRC this change was a spotted-while-reading-code one, not a response to a behavioural issue with the model.)
-- PMM
PATCH v2 8/18 omap_gpmc: Wire up the GPMC IRQ correctly
In reply to Peter MaydellThe omap_gpmc wasn't actually wiring up its IRQ, so anything that provoked an interrupt would be using uninitialised data for its IRQ number.
--- hw/omap_gpmc.c | 1 + 1 files changed, 1 insertions(+), 0 deletions(-)
hw/omap_gpmc.c +1 -0
@@ -407,6 +407,7 @@ struct omap_gpmc_s *omap_gpmc_init(target_phys_addr_t base, qemu_irq irq)memory_region_init_io (&s->iomem, &omap_gpmc_ops, s,"omap-gpmc" ,0x1000 );memory_region_add_subregion (get_system_memory (), base, &s->iomem); + s->irq = irq;omap_gpmc_reset (s);return s;
Signature · 1 line
1.7.1
PATCH v2 9/18 omap_gpmc: Fix handling of FIFOTHRESHOLDSTATUS bit
In reply to Peter MaydellThe OMAP3 TRM is inconsistent about whether the GPMC FIFOTHRESHOLDSTATUS bit should be set when FIFOPOINTER > FIFOTHRESHOLD or when it is >= FIFOTHRESHOLD. Apparently the underlying functional spec from which the TRM was created states that the behaviour is ">=", and this also makes more conceptual sense.
--- hw/omap_gpmc.c | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-)
hw/omap_gpmc.c +1 -1
@@ -222,7 +222,7 @@ static uint64_t omap_gpmc_read(void *opaque, target_phys_addr_t addr,return s->prefcontrol;case 0x1f0 :/* GPMC_PREFETCH_STATUS */ return (s->preffifo <<24 ) | - ((s->preffifo > + ((s->preffifo >= ((s->prefconfig[0 ] >>8 ) &0x7f ) ?1 :0 ) <<16 ) | s->prefcount;
Signature · 1 line
1.7.1
Re: [Qemu-devel] [PATCH v2 09/18] omap_gpmc: Fix handling of FIFOTHRESHOLDSTATUS bit
Quoted 5 lines · Peter Maydell
The OMAP3 TRM is inconsistent about whether the GPMC FIFOTHRESHOLDSTATUS bit should be set when FIFOPOINTER > FIFOTHRESHOLD or when it is >= FIFOTHRESHOLD. Apparently the underlying functional spec from which the TRM was created states that the behaviour is ">=", and this also makes more conceptual sense.
It would be good to have a comment about this in the code.
Cheers
PATCH v2 10/18 omap_gpmc: Take omap_mpu_state* in omap_gpmc_init
In reply to Peter MaydellFrom: Juha Riihimäki <[email protected]>
Take a pointer to the omap mpu state struct in omap_gpmc_init. Some details of GPMC behaviour depend on the OMAP version we are a part of.
--- hw/omap.h | 3 ++- hw/omap2.c | 2 +- hw/omap_gpmc.c | 3 ++- 3 files changed, 5 insertions(+), 3 deletions(-)
hw/omap.h +2 -1
@@ -118,7 +118,8 @@ void omap_sdrc_reset(struct omap_sdrc_s *s);/* OMAP2 general purpose memory controller */ struct omap_gpmc_s ; -struct omap_gpmc_s *omap_gpmc_init (target_phys_addr_t base,qemu_irq irq); +struct omap_gpmc_s *omap_gpmc_init (struct omap_mpu_state_s *mpu, +target_phys_addr_t base,qemu_irq irq);void omap_gpmc_reset (struct omap_gpmc_s *s);void omap_gpmc_attach (struct omap_gpmc_s *s,int cs,MemoryRegion *iomem);
hw/omap2.c +1 -1
@@ -2402,7 +2402,7 @@ struct omap_mpu_state_s *omap2420_mpu_init(unsigned long sdram_size,sysbus_mmio_map (busdev,4 ,omap_l4_region_base (ta,5 )); s->sdrc =omap_sdrc_init (0x68009000 ); - s->gpmc =omap_gpmc_init (0x6800a000 , s->irq[0 ][OMAP_INT_24XX_GPMC_IRQ ]); + s->gpmc =omap_gpmc_init (s,0x6800a000 , s->irq[0 ][OMAP_INT_24XX_GPMC_IRQ ]); dinfo =drive_get (IF_SD ,0 ,0 );if (!dinfo) {
hw/omap_gpmc.c +2 -1
@@ -399,7 +399,8 @@ static const MemoryRegionOps omap_gpmc_ops = { .endianness = DEVICE_NATIVE_ENDIAN, }; -struct omap_gpmc_s *omap_gpmc_init (target_phys_addr_t base,qemu_irq irq) +struct omap_gpmc_s *omap_gpmc_init (struct omap_mpu_state_s *mpu, +target_phys_addr_t base,qemu_irq irq) {struct omap_gpmc_s *s = (struct omap_gpmc_s *)g_malloc0 (sizeof (struct omap_gpmc_s ));
Signature · 1 line
1.7.1
PATCH v2 11/18 omap_gpmc: Calculate revision from OMAP model
In reply to Peter MaydellFrom: Juha Riihimäki <[email protected]>
--- hw/omap_gpmc.c | 4 +++- 1 files changed, 3 insertions(+), 1 deletions(-)
hw/omap_gpmc.c +3 -1
@@ -29,6 +29,7 @@ struct omap_gpmc_s {qemu_irq irq;MemoryRegion iomem; +uint8_t revision;uint8_t sysconfig;uint16_t irqst;uint16_t irqen;
@@ -163,7 +164,7 @@ static uint64_t omap_gpmc_read(void *opaque, target_phys_addr_t addr,switch (addr) {case 0x000 :/* GPMC_REVISION */ -return 0x20 ; +return s->revision;case 0x010 :/* GPMC_SYSCONFIG */ return s->sysconfig;
@@ -409,6 +410,7 @@ struct omap_gpmc_s *omap_gpmc_init(struct omap_mpu_state_s *mpu,memory_region_add_subregion (get_system_memory (), base, &s->iomem); s->irq = irq; + s->revision =cpu_class_omap3 (mpu) ?0x50 :0x20 ;omap_gpmc_reset (s);return s;
Signature · 1 line
1.7.1
PATCH v2 12/18 omap_gpmc: Reindent misindented switch statements
In reply to Peter MaydellWhitespace-only change fixing indentation.
--- hw/omap_gpmc.c | 96 ++++++++++++++++++++++++++++---------------------------- 1 files changed, 48 insertions(+), 48 deletions(-)
hw/omap_gpmc.c +48 -48
@@ -196,22 +196,22 @@ static uint64_t omap_gpmc_read(void *opaque, target_phys_addr_t addr, addr -= cs *0x30 ; f = s->cs_file + cs;switch (addr) { -case 0x60 :/* GPMC_CONFIG1 */ -return f->config[0 ]; -case 0x64 :/* GPMC_CONFIG2 */ -return f->config[1 ]; -case 0x68 :/* GPMC_CONFIG3 */ -return f->config[2 ]; -case 0x6c :/* GPMC_CONFIG4 */ -return f->config[3 ]; -case 0x70 :/* GPMC_CONFIG5 */ -return f->config[4 ]; -case 0x74 :/* GPMC_CONFIG6 */ -return f->config[5 ]; -case 0x78 :/* GPMC_CONFIG7 */ -return f->config[6 ]; -case 0x84 :/* GPMC_NAND_DATA */ -return 0 ; +case 0x60 :/* GPMC_CONFIG1 */ +return f->config[0 ]; +case 0x64 :/* GPMC_CONFIG2 */ +return f->config[1 ]; +case 0x68 :/* GPMC_CONFIG3 */ +return f->config[2 ]; +case 0x6c :/* GPMC_CONFIG4 */ +return f->config[3 ]; +case 0x70 :/* GPMC_CONFIG5 */ +return f->config[4 ]; +case 0x74 :/* GPMC_CONFIG6 */ +return f->config[5 ]; +case 0x78 :/* GPMC_CONFIG7 */ +return f->config[6 ]; +case 0x84 :/* GPMC_NAND_DATA */ +return 0 ; }break ;
@@ -311,38 +311,38 @@ static void omap_gpmc_write(void *opaque, target_phys_addr_t addr, addr -= cs *0x30 ; f = s->cs_file + cs;switch (addr) { -case 0x60 :/* GPMC_CONFIG1 */ - f->config[0 ] = value &0xffef3e13 ; -break ; -case 0x64 :/* GPMC_CONFIG2 */ - f->config[1 ] = value &0x001f1f8f ; -break ; -case 0x68 :/* GPMC_CONFIG3 */ - f->config[2 ] = value &0x001f1f8f ; -break ; -case 0x6c :/* GPMC_CONFIG4 */ - f->config[3 ] = value &0x1f8f1f8f ; -break ; -case 0x70 :/* GPMC_CONFIG5 */ - f->config[4 ] = value &0x0f1f1f1f ; -break ; -case 0x74 :/* GPMC_CONFIG6 */ - f->config[5 ] = value &0x00000fcf ; -break ; -case 0x78 :/* GPMC_CONFIG7 */ -if ((f->config[6 ] ^ value) &0xf7f ) { -omap_gpmc_cs_unmap (s, cs); - f->config[6 ] = value &0x00000f7f ; -omap_gpmc_cs_map (s, cs); - } -break ; -case 0x7c :/* GPMC_NAND_COMMAND */ -case 0x80 :/* GPMC_NAND_ADDRESS */ -case 0x84 :/* GPMC_NAND_DATA */ -break ; - -default : - goto bad_reg; +case 0x60 :/* GPMC_CONFIG1 */ + f->config[0 ] = value &0xffef3e13 ; +break ; +case 0x64 :/* GPMC_CONFIG2 */ + f->config[1 ] = value &0x001f1f8f ; +break ; +case 0x68 :/* GPMC_CONFIG3 */ + f->config[2 ] = value &0x001f1f8f ; +break ; +case 0x6c :/* GPMC_CONFIG4 */ + f->config[3 ] = value &0x1f8f1f8f ; +break ; +case 0x70 :/* GPMC_CONFIG5 */ + f->config[4 ] = value &0x0f1f1f1f ; +break ; +case 0x74 :/* GPMC_CONFIG6 */ + f->config[5 ] = value &0x00000fcf ; +break ; +case 0x78 :/* GPMC_CONFIG7 */ +if ((f->config[6 ] ^ value) &0xf7f ) { +omap_gpmc_cs_unmap (s, cs); + f->config[6 ] = value &0x00000f7f ; +omap_gpmc_cs_map (s, cs); + } +break ; +case 0x7c :/* GPMC_NAND_COMMAND */ +case 0x80 :/* GPMC_NAND_ADDRESS */ +case 0x84 :/* GPMC_NAND_DATA */ +break ; + +default : + goto bad_reg; }break ;
Signature · 1 line
1.7.1
PATCH v2 13/18 omap_gpmc: Support NAND devices
In reply to Peter MaydellSupport accesses to NAND devices, both by mapping them into the GPMC address space, and via the NAND_COMMAND, NAND_ADDRESS and NAND_DATA GPMC registers.
--- hw/omap.h | 1 + hw/omap_gpmc.c | 219 ++++++++++++++++++++++++++++++++++++++++++++++++++++--- 2 files changed, 208 insertions(+), 12 deletions(-)
hw/omap.h +1 -0
@@ -122,6 +122,7 @@ struct omap_gpmc_s *omap_gpmc_init(struct omap_mpu_state_s *mpu, target_phys_addr_t base, qemu_irq irq);void omap_gpmc_reset (struct omap_gpmc_s *s);void omap_gpmc_attach (struct omap_gpmc_s *s,int cs,MemoryRegion *iomem); +void omap_gpmc_attach_nand (struct omap_gpmc_s *s,int cs,DeviceState *nand);/* * Common IRQ numbers for level 1 interrupt handler
hw/omap_gpmc.c +207 -12
306 lines not on this page · raw message
Signature · 1 line
1.7.1
PATCH v2 14/18 hw/omap.h: Add OMAP 3630 to omap_mpu_model enumeration
In reply to Peter MaydellAdd the OMAP 3630 to the omap_mpu_model enumeration, and add the corresponding cpu_is_omap3630() function.
(OMAP3 isn't supported yet but this is useful in upgrading common components to be "OMAP3 ready". We already have this for OMAP3430.)
--- hw/omap.h | 5 ++++- 1 files changed, 4 insertions(+), 1 deletions(-)
hw/omap.h +4 -1
@@ -788,6 +788,7 @@ i2c_bus *omap_i2c_bus(struct omap_i2c_s *s);# define cpu_is_omap2420 (cpu) (cpu->mpu_model == omap2420)# define cpu_is_omap2430 (cpu) (cpu->mpu_model == omap2430)# define cpu_is_omap3430 (cpu) (cpu->mpu_model == omap3430) +# define cpu_is_omap3630 (cpu) (cpu->mpu_model == omap3630)# define cpu_is_omap15xx (cpu) \ (cpu_is_omap310(cpu) || cpu_is_omap1510(cpu))
@@ -799,7 +800,8 @@ i2c_bus *omap_i2c_bus(struct omap_i2c_s *s);# define cpu_class_omap1 (cpu) \ (cpu_is_omap15xx(cpu) || cpu_is_omap16xx(cpu))# define cpu_class_omap2 (cpu) cpu_is_omap24xx(cpu) -# define cpu_class_omap3 (cpu) cpu_is_omap3430(cpu) +# define cpu_class_omap3 (cpu) \ + (cpu_is_omap3430(cpu) || cpu_is_omap3630(cpu)) struct omap_mpu_state_s { enum omap_mpu_model {
@@ -813,6 +815,7 @@ struct omap_mpu_state_s { omap2423, omap2430, omap3430, + omap3630, } mpu_model;CPUState *env;
Signature · 1 line
1.7.1
v2 cover onenand, omap_gpmc fixes, features
In reply to Peter MaydellThis patchset is primarily features and bugfixes for the omap_gpmc device from the Meego tree.
We start by adding a new sysbus function to get the MemoryRegion* for a sysbus MMIO region. This was discussed in
http://www.mail-archive.com/[email protected]/msg59535.html
and as noted there can also be used to clean up other things, so it's not just an omap_gpmc thing.
The bulk of the onenand qdevification patch was in an earlier series I posted; this update makes it work with MemoryRegions.
The patches from "omap_gpmc: Take omap_mpu_state* in omap_gpmc_init" onwards are omap3 preparation; the features they add aren't used in the omap2 models currently in master. However I'd rather get things reviewed in more manageable chunks than save them all up for when I have omap3.c ready for commit...
Changes v1->v2:
* split out the onenand_command() change from qdevify patch
* dropped onenand_init() in favour of just doing the qdev create, configure,realize inline in nseries.c. This turns out to look better, I think, because you can see what that string of integer arguments to onenand_init() are actually doing.
I've updated (rebased!) the git branch:
git://git.linaro.org/people/pmaydell/qemu-arm.git omap-for-upstream
which should be suitable for pulling if desired.
Juha Riihimäki (6):
hw/onenand: Remove unnecessary argument from onenand_command() hw/onenand: Qdevify
hw/onenand: Minor spacing fixes
omap_gpmc: Take omap_mpu_state* in omap_gpmc_init
omap_gpmc: Calculate revision from OMAP model
omap_gpmc: Accept a zero mask field on omap3630
Peter Maydell (12):
hw/sysbus: Add sysbus_mmio_get_region()
omap_gpmc: Clean up omap_gpmc_attach MemoryRegion conversion
omap_gpmc: Refactor omap_gpmc_cs_map and omap_gpmc_cs_unmap
omap_gpmc: GPMC_IRQSTATUS is write-one-to-clear
omap_gpmc: Wire up the GPMC IRQ correctly
omap_gpmc: Fix handling of FIFOTHRESHOLDSTATUS bit
omap_gpmc: Reindent misindented switch statements
omap_gpmc: Support NAND devices
hw/omap.h: Add OMAP 3630 to omap_mpu_model enumeration
omap_gpmc: Pull prefetch engine data into sub-struct
omap: Wire up the DMA request line to the GPMC
omap_gpmc: Implement prefetch engine
hw/flash.h | 7 +- hw/nseries.c | 29 ++- hw/omap.h | 14 +- hw/omap2.c | 3 +- hw/omap_gpmc.c | 713 +++++++++++++++++++++++++++++++++++++++++++++----------- hw/onenand.c | 164 ++++++++++---- hw/sysbus.c | 5 + hw/sysbus.h | 1 + 8 files changed, 733 insertions(+), 203 deletions(-)
PATCH v2 15/18 omap_gpmc: Accept a zero mask field on omap3630
In reply to Peter MaydellFrom: Juha Riihimäki <[email protected]>
OMAP3630 adds an extra bit of address masking, so a mask of 0xb1111 is valid. Unfortunately the GPMC_REVISION is the same as on the OMAP3430 which only has three bits of address masking, so we have to derive this feature directly from the OMAP revision rather than from the GPMC revision.
--- hw/omap_gpmc.c | 11 ++++++----- 1 files changed, 6 insertions(+), 5 deletions(-)
hw/omap_gpmc.c +6 -5
@@ -28,6 +28,7 @@struct omap_gpmc_s {qemu_irq irq;MemoryRegion iomem; +int accept_256;uint8_t revision;uint8_t sysconfig;
@@ -198,11 +199,10 @@ static void omap_gpmc_cs_map(struct omap_gpmc_s *s, int cs) }/* TODO: check for overlapping regions and report access errors */ -if ((mask !=0x8 && mask !=0xc && mask !=0xe && mask !=0xf ) || - (base &0x0f & ~mask)) { -fprintf (stderr,"%s: wrong cs address mapping/decoding!\n" , - __FUNCTION__); -return ; +if (mask !=0x8 && mask !=0xc && mask !=0xe && mask !=0xf + && !(s->accept_256 && !mask)) { +fprintf (stderr,"%s: invalid chip-select mask address (0x%x)\n" , + __func__, mask); } base <<=24 ;
@@ -570,6 +570,7 @@ struct omap_gpmc_s *omap_gpmc_init(struct omap_mpu_state_s *mpu,memory_region_add_subregion (get_system_memory (), base, &s->iomem); s->irq = irq; + s->accept_256 =cpu_is_omap3630 (mpu); s->revision =cpu_class_omap3 (mpu) ?0x50 :0x20 ;omap_gpmc_reset (s);
Signature · 1 line
1.7.1
PATCH v2 16/18 omap_gpmc: Pull prefetch engine data into sub-struct
In reply to Peter MaydellRefactor the gpmc state structure so items relating to the prefetch engine are in their own sub-struct and have more useful names.
--- hw/omap_gpmc.c | 52 ++++++++++++++++++++++++++++------------------------ 1 files changed, 28 insertions(+), 24 deletions(-)
hw/omap_gpmc.c +28 -24
@@ -36,10 +36,6 @@ struct omap_gpmc_s {uint16_t irqen;uint16_t timeout;uint16_t config; -uint32_t prefconfig[2 ]; -int prefcontrol; -int preffifo; -int prefcount;struct omap_gpmc_cs_file_s {uint32_t config[7 ];MemoryRegion *iomem;
@@ -51,6 +47,13 @@ struct omap_gpmc_s {int ecc_ptr;uint32_t ecc_cfg;ECCState ecc[9 ]; +struct prefetch { +uint32_t config1;/* GPMC_PREFETCH_CONFIG1 */ +uint32_t transfercount;/* GPMC_PREFETCH_CONFIG2:TRANSFERCOUNT */ +int startengine;/* GPMC_PREFETCH_CONTROL:STARTENGINE */ +int fifopointer;/* GPMC_PREFETCH_STATUS:FIFOPOINTER */ +int count;/* GPMC_PREFETCH_STATUS:COUNTVALUE */ + } prefetch; };#define OMAP_GPMC_8BIT 0
@@ -243,11 +246,11 @@ void omap_gpmc_reset(struct omap_gpmc_s *s)omap_gpmc_int_update (s); s->timeout =0 ; s->config =0xa00 ; - s->prefconfig[0 ] =0x00004000 ; - s->prefconfig[1 ] =0x00000000 ; - s->prefcontrol =0 ; - s->preffifo =0 ; - s->prefcount =0 ; + s->prefetch.config1 =0x00004000 ; + s->prefetch.transfercount =0x00000000 ; + s->prefetch.startengine =0 ; + s->prefetch.fifopointer =0 ; + s->prefetch.count =0 ;for (i =0 ; i <8 ; i ++) {omap_gpmc_cs_unmap (s, i); s->cs_file[i].config[1 ] =0x101001 ;
@@ -363,16 +366,16 @@ static uint64_t omap_gpmc_read(void *opaque, target_phys_addr_t addr,break ;case 0x1e0 :/* GPMC_PREFETCH_CONFIG1 */ -return s->prefconfig[0 ]; +return s->prefetch.config1;case 0x1e4 :/* GPMC_PREFETCH_CONFIG2 */ -return s->prefconfig[1 ]; +return s->prefetch.transfercount;case 0x1ec :/* GPMC_PREFETCH_CONTROL */ -return s->prefcontrol; +return s->prefetch.startengine;case 0x1f0 :/* GPMC_PREFETCH_STATUS */ -return (s->preffifo <<24 ) | - ((s->preffifo >= - ((s->prefconfig[0 ] >>8 ) &0x7f ) ?1 :0 ) <<16 ) | - s->prefcount; +return (s->prefetch.fifopointer <<24 ) | + ((s->prefetch.fifopointer >= + ((s->prefetch.config1 >>8 ) &0x7f ) ?1 :0 ) <<16 ) | + s->prefetch.count;case 0x1f4 :/* GPMC_ECC_CONFIG */ return s->ecc_cs;
@@ -506,21 +509,22 @@ static void omap_gpmc_write(void *opaque, target_phys_addr_t addr,break ;case 0x1e0 :/* GPMC_PREFETCH_CONFIG1 */ - s->prefconfig[0 ] = value &0x7f8f7fbf ; + s->prefetch.config1 = value &0x7f8f7fbf ;/* TODO: update interrupts, fifos, dmas */ break ;case 0x1e4 :/* GPMC_PREFETCH_CONFIG2 */ - s->prefconfig[1 ] = value &0x3fff ; + s->prefetch.transfercount = value &0x3fff ;break ;case 0x1ec :/* GPMC_PREFETCH_CONTROL */ - s->prefcontrol = value &1 ; -if (s->prefcontrol) { -if (s->prefconfig[0 ] &1 ) - s->preffifo =0x40 ; -else - s->preffifo =0x00 ; + s->prefetch.startengine = value &1 ; +if (s->prefetch.startengine) { +if (s->prefetch.config1 &1 ) { + s->prefetch.fifopointer =0x40 ; + }else { + s->prefetch.fifopointer =0x00 ; + } }/* TODO: start */ break ;
Signature · 1 line
1.7.1
PATCH v2 17/18 omap: Wire up the DMA request line to the GPMC
In reply to Peter Maydell--- hw/omap.h | 3 ++- hw/omap2.c | 3 ++- hw/omap_gpmc.c | 5 ++++- 3 files changed, 8 insertions(+), 3 deletions(-)
hw/omap.h +2 -1
@@ -119,7 +119,8 @@ void omap_sdrc_reset(struct omap_sdrc_s *s);/* OMAP2 general purpose memory controller */ struct omap_gpmc_s ;struct omap_gpmc_s *omap_gpmc_init (struct omap_mpu_state_s *mpu, -target_phys_addr_t base,qemu_irq irq); +target_phys_addr_t base, +qemu_irq irq,qemu_irq drq);void omap_gpmc_reset (struct omap_gpmc_s *s);void omap_gpmc_attach (struct omap_gpmc_s *s,int cs,MemoryRegion *iomem);void omap_gpmc_attach_nand (struct omap_gpmc_s *s,int cs,DeviceState *nand);
hw/omap2.c +2 -1
@@ -2402,7 +2402,8 @@ struct omap_mpu_state_s *omap2420_mpu_init(unsigned long sdram_size,sysbus_mmio_map (busdev,4 ,omap_l4_region_base (ta,5 )); s->sdrc =omap_sdrc_init (0x68009000 ); - s->gpmc =omap_gpmc_init (s,0x6800a000 , s->irq[0 ][OMAP_INT_24XX_GPMC_IRQ ]); + s->gpmc =omap_gpmc_init (s,0x6800a000 , s->irq[0 ][OMAP_INT_24XX_GPMC_IRQ ], + s->drq[OMAP24XX_DMA_GPMC ]); dinfo =drive_get (IF_SD ,0 ,0 );if (!dinfo) {
hw/omap_gpmc.c +4 -1
@@ -27,6 +27,7 @@/* General-Purpose Memory Controller */ struct omap_gpmc_s {qemu_irq irq; +qemu_irq drq;MemoryRegion iomem;int accept_256;
@@ -564,7 +565,8 @@ static const MemoryRegionOps omap_gpmc_ops = { };struct omap_gpmc_s *omap_gpmc_init (struct omap_mpu_state_s *mpu, -target_phys_addr_t base,qemu_irq irq) +target_phys_addr_t base, +qemu_irq irq,qemu_irq drq) {int cs; struct omap_gpmc_s *s = (struct omap_gpmc_s *)
@@ -574,6 +576,7 @@ struct omap_gpmc_s *omap_gpmc_init(struct omap_mpu_state_s *mpu,memory_region_add_subregion (get_system_memory (), base, &s->iomem); s->irq = irq; + s->drq = drq; s->accept_256 =cpu_is_omap3630 (mpu); s->revision =cpu_class_omap3 (mpu) ?0x50 :0x20 ;omap_gpmc_reset (s);
Signature · 1 line
1.7.1
PATCH v2 18/18 omap_gpmc: Implement prefetch engine
In reply to Peter MaydellThis commit implements the prefetch engine feature of the GPMC which can be used for NAND devices. This includes both interrupt driven and DMA-filling modes.
--- hw/omap_gpmc.c | 257 +++++++++++++++++++++++++++++++++++++++++++++++++++++-- 1 files changed, 247 insertions(+), 10 deletions(-)
hw/omap_gpmc.c +247 -10
@@ -35,6 +35,7 @@ struct omap_gpmc_s {uint8_t sysconfig;uint16_t irqst;uint16_t irqen; +uint16_t lastirq;uint16_t timeout;uint16_t config;struct omap_gpmc_cs_file_s {
@@ -54,6 +55,8 @@ struct omap_gpmc_s {int startengine;/* GPMC_PREFETCH_CONTROL:STARTENGINE */ int fifopointer;/* GPMC_PREFETCH_STATUS:FIFOPOINTER */ int count;/* GPMC_PREFETCH_STATUS:COUNTVALUE */ +MemoryRegion iomem; +uint8_t fifo[64 ]; } prefetch; };
@@ -76,9 +79,42 @@ static int omap_gpmc_devsize(struct omap_gpmc_cs_file_s *f)return (f->config[0 ] >>12 ) &1 ; } +/* Extract the chip-select value from the prefetch config1 register */ +static int prefetch_cs (uint32_t config1) +{ +return (config1 >>24 ) &7 ; +} + +static int prefetch_threshold (uint32_t config1) +{ +return (config1 >>8 ) &0x7f ; +} +static void omap_gpmc_int_update (struct omap_gpmc_s *s) { -qemu_set_irq (s->irq, s->irqen & s->irqst); +/* The TRM is a bit unclear, but it seems to say that +* the TERMINALCOUNTSTATUS bit is set only on the +* transition when the prefetch engine goes from +* active to inactive, whereas the FIFOEVENTSTATUS +* bit is held high as long as the fifo has at +* least THRESHOLD bytes available. +* So we do the latter here, but TERMINALCOUNTSTATUS +* is set elsewhere. +*/ +if (s->prefetch.fifopointer >=prefetch_threshold (s->prefetch.config1)) { + s->irqst |=1 ; + } +if ((s->irqen & s->irqst) != s->lastirq) { + s->lastirq = s->irqen & s->irqst; +qemu_set_irq (s->irq, s->lastirq); + } +} + +static void omap_gpmc_dma_update (struct omap_gpmc_s *s,int value) +{ +if (s->prefetch.config1 &4 ) { +qemu_set_irq (s->drq, value); + } }/* Access functions for when a NAND-like device is mapped into memory:
@@ -176,6 +212,161 @@ static const MemoryRegionOps omap_nand_ops = { .endianness = DEVICE_NATIVE_ENDIAN, }; +static void fill_prefetch_fifo (struct omap_gpmc_s *s) +{ +/* Fill the prefetch FIFO by reading data from NAND. +* We do this synchronously, unlike the hardware which +* will do this asynchronously. We refill when the +* FIFO has THRESHOLD bytes free, and we always refill +* as much data as possible starting at the top end +* of the FIFO. +* (We have to refill at THRESHOLD rather than waiting +* for the FIFO to empty to allow for the case where +* the FIFO size isn't an exact multiple of THRESHOLD +* and we're doing DMA transfers.) +* This means we never need to handle wrap-around in +* the fifo-reading code, and the next byte of data +* to read is always fifo[63 - fifopointer]. +*/ +int fptr; +int cs =prefetch_cs (s->prefetch.config1); +int is16bit = (((s->cs_file[cs].config[0 ] >>12 ) &3 ) !=0 ); +int bytes; +/* Don't believe the bit of the OMAP TRM that says that COUNTVALUE +* and TRANSFERCOUNT are in units of 16 bit words for 16 bit NAND. +* Instead believe the bit that says it is always a byte count. +*/ + bytes =64 - s->prefetch.fifopointer; +if (bytes > s->prefetch.count) { + bytes = s->prefetch.count; + } + s->prefetch.count -= bytes; + s->prefetch.fifopointer += bytes; + fptr =64 - s->prefetch.fifopointer; +/* Move the existing data in the FIFO so it sits just +* before what we're about to read in +*/ +while (fptr < (64 - bytes)) { + s->prefetch.fifo[fptr] = s->prefetch.fifo[fptr + bytes]; + fptr++; + } +while (fptr <64 ) { +if (is16bit) { +uint32_t v =omap_nand_read (&s->cs_file[cs],0 ,2 ); + s->prefetch.fifo[fptr++] = v &0xff ; + s->prefetch.fifo[fptr++] = (v >>8 ) &0xff ; + }else { + s->prefetch.fifo[fptr++] =omap_nand_read (&s->cs_file[cs],0 ,1 ); + } + } +if (s->prefetch.startengine && (s->prefetch.count ==0 )) { +/* This was the final transfer: raise TERMINALCOUNTSTATUS */ + s->irqst |=2 ; + s->prefetch.startengine =0 ; + } +/* If there are any bytes in the FIFO at this point then +* we must raise a DMA request (either this is a final part +* transfer, or we filled the FIFO in which case we certainly +* have THRESHOLD bytes available) +*/ +if (s->prefetch.fifopointer !=0 ) { +omap_gpmc_dma_update (s,1 ); + } +omap_gpmc_int_update (s); +} + +/* Access functions for a NAND-like device when the prefetch/postwrite +* engine is enabled -- all addresses in the region behave alike: +* data is read or written to the FIFO. +*/ +static uint64_t omap_gpmc_prefetch_read (void *opaque,target_phys_addr_t addr, +unsigned size) +{ +struct omap_gpmc_s *s = (struct omap_gpmc_s *) opaque; +uint32_t data; +if (s->prefetch.config1 &1 ) { +/* The TRM doesn't define the behaviour if you read from the +* FIFO when the prefetch engine is in write mode. We choose +* to always return zero. +*/ +return 0 ; + } +/* Note that trying to read an empty fifo repeats the last byte */ +if (s->prefetch.fifopointer) { + s->prefetch.fifopointer--; + } + data = s->prefetch.fifo[63 - s->prefetch.fifopointer]; +if (s->prefetch.fifopointer == + (64 -prefetch_threshold (s->prefetch.config1))) { +/* We've drained THRESHOLD bytes now. So deassert the +* DMA request, then refill the FIFO (which will probably +* assert it again.) +*/ +omap_gpmc_dma_update (s,0 ); +fill_prefetch_fifo (s); + } +omap_gpmc_int_update (s); +return data; +} + +static void omap_gpmc_prefetch_write (void *opaque,target_phys_addr_t addr, +uint64_t value,unsigned size) +{ +struct omap_gpmc_s *s = (struct omap_gpmc_s *) opaque; +int cs =prefetch_cs (s->prefetch.config1); +if ((s->prefetch.config1 &1 ) ==0 ) { +/* The TRM doesn't define the behaviour of writing to the +* FIFO when the prefetch engine is in read mode. We +* choose to ignore the write. +*/ +return ; + } +if (s->prefetch.count ==0 ) { +/* The TRM doesn't define the behaviour of writing to the +* FIFO if the transfer is complete. We choose to ignore. +*/ +return ; + } +/* The only reason we do any data buffering in postwrite +* mode is if we are talking to a 16 bit NAND device, in +* which case we need to buffer the first byte of the +* 16 bit word until the other byte arrives. +*/ +int is16bit = (((s->cs_file[cs].config[0 ] >>12 ) &3 ) !=0 ); +if (is16bit) { +/* fifopointer alternates between 64 (waiting for first +* byte of word) and 63 (waiting for second byte) +*/ +if (s->prefetch.fifopointer ==64 ) { + s->prefetch.fifo[0 ] = value; + s->prefetch.fifopointer--; + }else { + value = (value <<8 ) | s->prefetch.fifo[0 ]; +omap_nand_write (&s->cs_file[cs],0 , value,2 ); + s->prefetch.count--; + s->prefetch.fifopointer =64 ; + } + }else { +/* Just write the byte : fifopointer remains 64 at all times */ +omap_nand_write (&s->cs_file[cs],0 , value,1 ); + s->prefetch.count--; + } +if (s->prefetch.count ==0 ) { +/* Final transfer: raise TERMINALCOUNTSTATUS */ + s->irqst |=2 ; + s->prefetch.startengine =0 ; + } +omap_gpmc_int_update (s); +} + +static const MemoryRegionOps omap_prefetch_ops = { + .read = omap_gpmc_prefetch_read, + .write = omap_gpmc_prefetch_write, + .endianness =DEVICE_NATIVE_ENDIAN , + .impl.min_access_size =1 , + .impl.max_access_size =1 , +}; +static MemoryRegion *omap_gpmc_cs_memregion (struct omap_gpmc_s *s,int cs) {/* Return the MemoryRegion* to map/unmap for this chipselect */
@@ -183,6 +374,11 @@ static MemoryRegion *omap_gpmc_cs_memregion(struct omap_gpmc_s *s, int cs)if (omap_gpmc_devtype (f) ==OMAP_GPMC_NOR ) {return f->iomem; } +if ((s->prefetch.config1 &0x80 ) && + (prefetch_cs (s->prefetch.config1) == cs)) { +/* The prefetch engine is enabled for this CS: map the FIFO */ +return &s->prefetch.iomem; + }return &f->nandiomem; }
@@ -510,24 +706,61 @@ static void omap_gpmc_write(void *opaque, target_phys_addr_t addr,break ;case 0x1e0 :/* GPMC_PREFETCH_CONFIG1 */ - s->prefetch.config1 = value &0x7f8f7fbf ; -/* TODO: update interrupts, fifos, dmas */ +if (!s->prefetch.startengine) { +uint32_t oldconfig1 = s->prefetch.config1; +uint32_t changed; + s->prefetch.config1 = value &0x7f8f7fbf ; + changed = oldconfig1 ^ s->prefetch.config1; +if (changed & (0x80 |0x7000000 )) { +/* Turning the engine on or off, or mapping it somewhere else. +* cs_map() and cs_unmap() check the prefetch config and +* overall CSVALID bits, so it is sufficient to unmap-and-map +* both the old cs and the new one. +*/ +int oldcs =prefetch_cs (oldconfig1); +int newcs =prefetch_cs (s->prefetch.config1); +omap_gpmc_cs_unmap (s, oldcs); +omap_gpmc_cs_map (s, oldcs); +if (newcs != oldcs) { +omap_gpmc_cs_unmap (s, newcs); +omap_gpmc_cs_map (s, newcs); + } + } + }break ;case 0x1e4 :/* GPMC_PREFETCH_CONFIG2 */ - s->prefetch.transfercount = value &0x3fff ; +if (!s->prefetch.startengine) { + s->prefetch.transfercount = value &0x3fff ; + }break ;case 0x1ec :/* GPMC_PREFETCH_CONTROL */ - s->prefetch.startengine = value &1 ; -if (s->prefetch.startengine) { -if (s->prefetch.config1 &1 ) { - s->prefetch.fifopointer =0x40 ; +if (s->prefetch.startengine != (value &1 )) { + s->prefetch.startengine = value &1 ; +if (s->prefetch.startengine) { +/* Prefetch engine start */ + s->prefetch.count = s->prefetch.transfercount; +if (s->prefetch.config1 &1 ) { +/* Write */ + s->prefetch.fifopointer =64 ; + }else { +/* Read */ + s->prefetch.fifopointer =0 ; +fill_prefetch_fifo (s); + } }else { - s->prefetch.fifopointer =0x00 ; +/* Prefetch engine forcibly stopped. The TRM +* doesn't define the behaviour if you do this. +* We clear the prefetch count, which means that +* we permit no more writes, and don't read any +* more data from NAND. The CPU can still drain +* the FIFO of unread data. +*/ + s->prefetch.count =0 ; } +omap_gpmc_int_update (s); } -/* TODO: start */ break ;case 0x1f4 :/* GPMC_ECC_CONFIG */
@@ -579,6 +812,7 @@ struct omap_gpmc_s *omap_gpmc_init(struct omap_mpu_state_s *mpu, s->drq = drq; s->accept_256 =cpu_is_omap3630 (mpu); s->revision =cpu_class_omap3 (mpu) ?0x50 :0x20 ; + s->lastirq =0 ;omap_gpmc_reset (s);/* We have to register a different IO memory handler for each
@@ -594,6 +828,9 @@ struct omap_gpmc_s *omap_gpmc_init(struct omap_mpu_state_s *mpu,"omap-nand" , 256 * 1024 * 1024); } + +memory_region_init_io (&s->prefetch.iomem, &omap_prefetch_ops, s, +"omap-gpmc-prefetch" ,256 *1024 *1024 );return s; }
Signature · 1 line
1.7.1
Edgar E. Iglesias
AppliedQuoted 26 lines · Peter Maydell
This patchset is primarily features and bugfixes for the
omap_gpmcdevice from the Meego tree.We start by adding a new sysbus function to get the MemoryRegion* for a sysbus MMIO region. This was discussed in
http://www.mail-archive.com/[email protected]/msg59535.html
and as noted there can also be used to clean up other things, so it's not just anomap_gpmcthing.The bulk of the onenand qdevification patch was in an earlier series I posted; this update makes it work with MemoryRegions.
The patches from "
omap_gpmc: Take omap_mpu_state* inomap_gpmc_init" onwards are omap3 preparation; the features they add aren't used in the omap2 models currently in master. However I'd rather get things reviewed in more manageable chunks than save them all up for when I haveomap3.cready for commit...Changes
v1->v2:
* split out theonenand_command()change from qdevify patch
* droppedonenand_init()in favour of just doing the qdev create, configure,realize inline innseries.c. This turns out to look better, I think, because you can see what that string of integer arguments toonenand_init()are actually doing.
(patch 1 and the old 3..17, now 4..18, are unchanged)
Quoted 3 lines
I've updated (rebased!) the git branch:
git://git.linaro.org/people/pmaydell/qemu-arm.gitomap-for-upstream
which should be suitable for pulling if desired.
I've applied the series, thanks!
Cheers