bugfix and qdevify NAND and ONENAND devices
cover bugfix and qdevify NAND and ONENAND devices
This patchseries is more goodies from the Meego tree. Specifically, various bug fixes to hw/nand and hw/onenand, plus conversion of both to sysbus.
[An advance note on the next thing due to come out of the pipe: qdeving nand and onenand allows us to move to qdevification of omap_gpmc, which takes both of those (and other things) as 'downstream' devices. That change will make it accept arbitrary SysBus devices as its 'downstream' devices rather than the current setup of taking an opaque pointer and a pair of resize/unmap function pointers. (There are also patches which add NAND support so you can tell omap_gpmc "this is a NAND device" and it then uses the nand_setpins/nand_getpins/nand_setio interface.) The rationale for using SysBus there rather than defining some new kind of bus is that you want to be able to plug any random thing into it; for instance the Overo board has a lan9118 ethernet controller hanging off the GPMC. ]
A note on dependencies:
* This patch depends on the omap gpio patchset (although more textually than seriously semantically)
* the six nand patches and the six onenand patches are broadly independent of each other
Juha Riihimäki (9):
hw/nand: Support large NAND devices
hw/nand: Support devices wider than 8 bits hw/nand: Support multiple reads following READ STATUS hw/nand: qdevify
onenand: Handle various ID fields separately
onenand: Ignore zero writes to boot command space hw/onenand: program actions can only clear bits hw/sysbus: Add sysbus_mmio_unmap() for unmapping a region hw/onenand: qdevify
Peter Maydell (3):
hw/nand: Pass block device state to init function hw/nand: Writing to NAND can only clear bits
onenand: Pass BlockDriverState to init function
hw/axis_dev88.c | 8 +- hw/flash.h | 19 ++-- hw/nand.c | 345 ++++++++++++++++++++++++++++++++------------------- hw/nseries.c | 13 ++- hw/onenand.c | 373 +++++++++++++++++++++++++++++++++++++++++++------------ hw/spitz.c | 6 +- hw/sysbus.c | 17 +++ hw/sysbus.h | 1 + hw/tc6393xb.c | 7 +- 9 files changed, 561 insertions(+), 228 deletions(-)
PATCH 1/12 hw/nand: Pass block device state to init function
Pass the BlockDeviceState to the nand_init() function rather than having it look it up via drive_get() itself.
--- hw/axis_dev88.c | 6 +++++- hw/flash.h | 2 +- hw/nand.c | 8 ++------ hw/spitz.c | 4 +++- hw/tc6393xb.c | 5 ++++- 5 files changed, 15 insertions(+), 10 deletions(-)
hw/axis_dev88.c +5 -1
@@ -30,6 +30,7 @@#include "loader.h" #include "elf.h" #include "cris-boot.h" +#include "blockdev.h" #define D (x)#define DNAND (x)
@@ -251,6 +252,7 @@ void axisdev88_init (ram_addr_t ram_size,CPUState *env;DeviceState *dev;SysBusDevice *s; +DriveInfo *nand;qemu_irq irq[30 ], nmi[2 ], *cpu_irq;void *etraxfs_dmac;struct etraxfs_dma_client *eth[2 ] = {NULL ,NULL };
@@ -278,7 +280,9 @@ void axisdev88_init (ram_addr_t ram_size,/* Attach a NAND flash to CS1. */ - nand_state.nand =nand_init (NAND_MFR_STMICRO ,0x39 ); + nand =drive_get (IF_MTD ,0 ,0 ); + nand_state.nand =nand_init (nand ? nand->bdrv :NULL , +NAND_MFR_STMICRO ,0x39 ); nand_regs =cpu_register_io_memory (nand_read, nand_write, &nand_state,DEVICE_NATIVE_ENDIAN );cpu_register_physical_memory (0x10000000 ,0x05000000 , nand_regs);
hw/flash.h +1 -1
@@ -19,7 +19,7 @@ pflash_t *pflash_cfi02_register(target_phys_addr_t base, ram_addr_t off,/* nand.c */ typedef struct NANDFlashState NANDFlashState ; -NANDFlashState *nand_init (int manf_id,int chip_id); +NANDFlashState *nand_init (BlockDriverState *bdrv,int manf_id,int chip_id);void nand_done (NANDFlashState *s);void nand_setpins (NANDFlashState *s,uint8_t cle,uint8_t ale,uint8_t ce,uint8_t wp,uint8_t gnd);
hw/nand.c +2 -6
@@ -14,7 +14,6 @@# include "hw.h" # include "flash.h" # include "blockdev.h" -/* FIXME: Pass block device as an argument. */ # define NAND_CMD_READ0 0x00# define NAND_CMD_READ1 0x01
@@ -451,20 +450,17 @@ uint8_t nand_getio(NANDFlashState *s)return *(s->ioaddr ++); } -NANDFlashState *nand_init (int manf_id,int chip_id) +NANDFlashState *nand_init (BlockDriverState *bdrv,int manf_id,int chip_id) {int pagesize;NANDFlashState *s; -DriveInfo *dinfo;if (nand_flash_ids[chip_id].size ==0 ) {hw_error ("%s: Unsupported NAND chip ID.\n" , __FUNCTION__); } s = (NANDFlashState *)qemu_mallocz (sizeof (NANDFlashState)); - dinfo =drive_get (IF_MTD ,0 ,0 ); -if (dinfo) - s->bdrv = dinfo->bdrv; + s->bdrv = bdrv; s->manf_id = manf_id; s->chip_id = chip_id; s->size = nand_flash_ids[s->chip_id].size <<20 ;
hw/spitz.c +3 -1
@@ -169,11 +169,13 @@ static void sl_flash_register(PXA2xxState *cpu, int size)static int sl_nand_init (SysBusDevice *dev) {int iomemtype;SLNANDState *s; +DriveInfo *nand; s =FROM_SYSBUS (SLNANDState, dev); s->ctl =0 ; - s->nand =nand_init (s->manf_id, s->chip_id); + nand =drive_get (IF_MTD ,0 ,0 ); + s->nand =nand_init (nand ? nand->bdrv :NULL , s->manf_id, s->chip_id); iomemtype =cpu_register_io_memory (sl_readfn, sl_writefn, s,DEVICE_NATIVE_ENDIAN );
hw/tc6393xb.c +4 -1
@@ -12,6 +12,7 @@#include "flash.h" #include "console.h" #include "pixel_ops.h" +#include "blockdev.h" #define IRQ_TC6393_NAND 0#define IRQ_TC6393_MMC 1
@@ -566,6 +567,7 @@ TC6393xbState *tc6393xb_init(uint32_t base, qemu_irq irq) {int iomemtype;TC6393xbState *s; +DriveInfo *nand;CPUReadMemoryFunc *const tc6393xb_readfn[] = { tc6393xb_readb, tc6393xb_readw,
@@ -586,7 +588,8 @@ TC6393xbState *tc6393xb_init(uint32_t base, qemu_irq irq) s->sub_irqs =qemu_allocate_irqs (tc6393xb_sub_irq, s,TC6393XB_NR_IRQS ); - s->flash =nand_init (NAND_MFR_TOSHIBA ,0x76 ); + nand =drive_get (IF_MTD ,0 ,0 ); + s->flash =nand_init (nand ? nand->bdrv :NULL ,NAND_MFR_TOSHIBA ,0x76 ); iomemtype =cpu_register_io_memory (tc6393xb_readfn, tc6393xb_writefn, s,DEVICE_NATIVE_ENDIAN );
Signature · 1 line
1.7.1
PATCH 2/12 hw/nand: Support large NAND devices
In reply to Peter MaydellFrom: Juha Riihimäki <[email protected]>
Add support for NAND devices of over 1Gb.
--- hw/nand.c | 48 +++++++++++++++++++++++++++--------------------- 1 files changed, 27 insertions(+), 21 deletions(-)
hw/nand.c +27 -21
@@ -6,6 +6,10 @@* Copyright (c) 2006 Openedhand Ltd. * Written by Andrzej Zaborowski <[email protected]> * +* Support for additional features based on "MT29F2G16ABCWP 2Gx16" +* datasheet from Micron Technology and "NAND02G-B2C" datasheet +* from ST Microelectronics. +* * This code is licensed under the GNU GPL v2. */
@@ -57,14 +61,15 @@ struct NANDFlashState {uint8_t *ioaddr;int iolen; -uint32_t cmd, addr; +uint32_t cmd; +uint64_t addr;int addrlen;int status;int offset;void (*blk_write)(NANDFlashState *s);void (*blk_erase)(NANDFlashState *s); -void (*blk_load)(NANDFlashState *s,uint32_t addr,int offset); +void (*blk_load)(NANDFlashState *s,uint64_t addr,int offset);uint32_t ioaddr_vmstate; };
@@ -318,7 +323,7 @@ static const VMStateDescription vmstate_nand = {VMSTATE_UINT32 (ioaddr_vmstate, NANDFlashState),VMSTATE_INT32 (iolen, NANDFlashState),VMSTATE_UINT32 (cmd, NANDFlashState), -VMSTATE_UINT32 (addr, NANDFlashState), +VMSTATE_UINT64 (addr, NANDFlashState),VMSTATE_INT32 (addrlen, NANDFlashState),VMSTATE_INT32 (status, NANDFlashState), VMSTATE_INT32(offset, NANDFlashState),
@@ -432,7 +437,7 @@ uint8_t nand_getio(NANDFlashState *s)/* Allow sequential reading */ if (!s->iolen && s->cmd ==NAND_CMD_READ0 ) { - offset = (s->addr & ((1 << s->addr_shift) -1 )) + s->offset; + offset = (int )(s->addr & ((1 << s->addr_shift) -1 )) + s->offset; s->offset =0 ; s->blk_load (s, s->addr, offset);
@@ -526,7 +531,7 @@ void nand_done(NANDFlashState *s)/* Program a single page */ static void glue (nand_blk_write_ ,PAGE_SIZE )(NANDFlashState *s) { -uint32_t off, page, sector, soff; +uint64_t off, page, sector, soff;uint8_t iobuf[(PAGE_SECTORS +2 ) *0x200 ];if (PAGE (s->addr) >= s->pages)return ;
@@ -539,7 +544,7 @@ static void glue(nand_blk_write_, PAGE_SIZE)(NANDFlashState *s) off = (s->addr &PAGE_MASK ) + s->offset; soff =SECTOR_OFFSET (s->addr);if (bdrv_read (s->bdrv, sector, iobuf,PAGE_SECTORS ) ==-1 ) { -printf ("%s: read error in sector %i\n" , __FUNCTION__, sector); +printf ("%s: read error in sector %" PRIu64"\n" , __func__, sector);return ; }
@@ -551,20 +556,20 @@ static void glue(nand_blk_write_, PAGE_SIZE)(NANDFlashState *s) }if (bdrv_write (s->bdrv, sector, iobuf,PAGE_SECTORS ) ==-1 ) -printf ("%s: write error in sector %i\n" , __FUNCTION__, sector); +printf ("%s: write error in sector %" PRIu64"\n" , __func__, sector); }else { off =PAGE_START (s->addr) + (s->addr &PAGE_MASK ) + s->offset; sector = off >>9 ; soff = off &0x1ff ;if (bdrv_read (s->bdrv, sector, iobuf,PAGE_SECTORS +2 ) ==-1 ) { -printf ("%s: read error in sector %i\n" , __FUNCTION__, sector); +printf ("%s: read error in sector %" PRIu64"\n" , __func__, sector);return ; }memcpy (iobuf + soff, s->io, s->iolen);if (bdrv_write (s->bdrv, sector, iobuf,PAGE_SECTORS +2 ) ==-1 ) -printf ("%s: write error in sector %i\n" , __FUNCTION__, sector); +printf ("%s: write error in sector %" PRIu64"\n" , __func__, sector); } s->offset =0 ; }
@@ -572,7 +577,7 @@ static void glue(nand_blk_write_, PAGE_SIZE)(NANDFlashState *s)/* Erase a single block */ static void glue (nand_blk_erase_ ,PAGE_SIZE )(NANDFlashState *s) { -uint32_t i, page, addr; +uint64_t i, page, addr;uint8_t iobuf[0x200 ] = { [0 ...0x1ff ] =0xff , }; addr = s->addr & ~((1 << (ADDR_SHIFT + s->erase_shift)) -1 );
@@ -589,34 +594,35 @@ static void glue(nand_blk_erase_, PAGE_SIZE)(NANDFlashState *s) page =SECTOR (addr + (ADDR_SHIFT + s->erase_shift));for (; i < page; i ++)if (bdrv_write (s->bdrv, i, iobuf,1 ) ==-1 ) -printf ("%s: write error in sector %i\n" , __FUNCTION__, i); +printf ("%s: write error in sector %" PRIu64"\n" , __func__, i); }else { addr =PAGE_START (addr); page = addr >>9 ;if (bdrv_read (s->bdrv, page, iobuf,1 ) ==-1 ) -printf ("%s: read error in sector %i\n" , __FUNCTION__, page); +printf ("%s: read error in sector %" PRIu64"\n" , __func__, page);memset (iobuf + (addr &0x1ff ),0xff , (~addr &0x1ff ) +1 );if (bdrv_write (s->bdrv, page, iobuf,1 ) ==-1 ) -printf ("%s: write error in sector %i\n" , __FUNCTION__, page); +printf ("%s: write error in sector %" PRIu64"\n" , __func__, page);memset (iobuf,0xff ,0x200 ); i = (addr & ~0x1ff ) +0x200 ;for (addr += ((PAGE_SIZE +OOB_SIZE ) << s->erase_shift) -0x200 ; i < addr; i +=0x200 )if (bdrv_write (s->bdrv, i >>9 , iobuf,1 ) ==-1 ) -printf ("%s: write error in sector %i\n" , __FUNCTION__, i >>9 ); +printf ("%s: write error in sector %" PRIu64"\n" , + __func__, i >>9 ); page = i >>9 ;if (bdrv_read (s->bdrv, page, iobuf,1 ) ==-1 ) -printf ("%s: read error in sector %i\n" , __FUNCTION__, page); +printf ("%s: read error in sector %" PRIu64"\n" , __func__, page);memset (iobuf,0xff , ((addr -1 ) &0x1ff ) +1 );if (bdrv_write (s->bdrv, page, iobuf,1 ) ==-1 ) -printf ("%s: write error in sector %i\n" , __FUNCTION__, page); +printf ("%s: write error in sector %" PRIu64"\n" , __func__, page); } }static void glue (nand_blk_load_ ,PAGE_SIZE )(NANDFlashState *s, -uint32_t addr,int offset) +uint64_t addr,int offset) {if (PAGE (addr) >= s->pages)return ;
@@ -624,8 +630,8 @@ static void glue(nand_blk_load_, PAGE_SIZE)(NANDFlashState *s,if (s->bdrv) {if (s->mem_oob) {if (bdrv_read (s->bdrv,SECTOR (addr), s->io,PAGE_SECTORS ) ==-1 ) -printf ("%s: read error in sector %i\n" , - __FUNCTION__,SECTOR (addr)); +printf ("%s: read error in sector %" PRIu64"\n" , + __func__,SECTOR (addr));memcpy (s->io +SECTOR_OFFSET (s->addr) +PAGE_SIZE , s->storage + (PAGE (s->addr) <<OOB_SHIFT ),OOB_SIZE );
@@ -633,8 +639,8 @@ static void glue(nand_blk_load_, PAGE_SIZE)(NANDFlashState *s, }else {if (bdrv_read (s->bdrv,PAGE_START (addr) >>9 , s->io, (PAGE_SECTORS +2 )) ==-1 ) -printf ("%s: read error in sector %i\n" , - __FUNCTION__,PAGE_START (addr) >>9 ); +printf ("%s: read error in sector %" PRIu64"\n" , + __func__,PAGE_START (addr) >>9 ); s->ioaddr = s->io + (PAGE_START (addr) &0x1ff ) + offset; } }else {
Signature · 1 line
1.7.1
PATCH 3/12 hw/nand: Support devices wider than 8 bits
In reply to Peter MaydellFrom: Juha Riihimäki <[email protected]>
Support NAND devices which are wider than 8 bits.
--- hw/flash.h | 5 ++- hw/nand.c | 119 +++++++++++++++++++++++++++++++++++++++++++----------------- 2 files changed, 89 insertions(+), 35 deletions(-)
hw/flash.h +3 -2
@@ -24,8 +24,9 @@ void nand_done(NANDFlashState *s);void nand_setpins (NANDFlashState *s,uint8_t cle,uint8_t ale,uint8_t ce,uint8_t wp,uint8_t gnd);void nand_getpins (NANDFlashState *s,int *rb); -void nand_setio (NANDFlashState *s,uint8_t value); -uint8_t nand_getio (NANDFlashState *s); +void nand_setio (NANDFlashState *s,uint32_t value); +uint32_t nand_getio (NANDFlashState *s); +uint32_t nand_getbuswidth (NANDFlashState *s);#define NAND_MFR_TOSHIBA 0x98#define NAND_MFR_SAMSUNG 0xec
hw/nand.c +86 -33
181 lines not on this page · raw message
Signature · 1 line
1.7.1
PATCH 4/12 hw/nand: Support multiple reads following READ STATUS
In reply to Peter MaydellFrom: Juha Riihimäki <[email protected]>
After receiving READ STATUS command all subsequent IO reads should return the status register value until another command is issued.
--- hw/nand.c | 11 ++++++++--- 1 files changed, 8 insertions(+), 3 deletions(-)
hw/nand.c +8 -3
@@ -496,9 +496,14 @@ uint32_t nand_getio(NANDFlashState *s)for (offset = s->buswidth; offset--;) { x |= s->ioaddr[offset] << (offset <<3 ); } - s->addr += s->buswidth; - s->ioaddr += s->buswidth; - s->iolen -= s->buswidth; +/* after receiving READ STATUS command all subsequent reads will +* return the status register value until another command is issued +*/ +if (s->cmd !=NAND_CMD_READSTATUS ) { + s->addr += s->buswidth; + s->ioaddr += s->buswidth; + s->iolen -= s->buswidth; + }return x; }
Signature · 1 line
1.7.1
PATCH 5/12 hw/nand: Writing to NAND can only clear bits
In reply to Peter MaydellWriting to a NAND device cannot set bits, it can only clear them; implement this rather than simply copying the data.
--- hw/nand.c | 17 +++++++++++++---- 1 files changed, 13 insertions(+), 4 deletions(-)
hw/nand.c +13 -4
@@ -75,6 +75,15 @@ struct NANDFlashState {uint32_t ioaddr_vmstate; }; +static void mem_and (uint8_t *dest,const uint8_t *src,size_t n) +{ +/* Like memcpy() but we logical-AND the data into the destination */ +int i; +for (i =0 ; i < n; i++) { + dest[i] &= src[i]; + } +} +# define NAND_NO_AUTOINCR 0x00000001# define NAND_BUSWIDTH_16 0x00000002# define NAND_NO_PADDING 0x00000004
@@ -595,7 +604,7 @@ static void glue(nand_blk_write_, PAGE_SIZE)(NANDFlashState *s)return ;if (!s->bdrv) { -memcpy (s->storage +PAGE_START (s->addr) + (s->addr &PAGE_MASK ) + +mem_and (s->storage +PAGE_START (s->addr) + (s->addr &PAGE_MASK ) + s->offset, s->io, s->iolen); }else if (s->mem_oob) { sector =SECTOR (s->addr);
@@ -606,10 +615,10 @@ static void glue(nand_blk_write_, PAGE_SIZE)(NANDFlashState *s)return ; } -memcpy (iobuf + (soff | off), s->io,MIN (s->iolen,PAGE_SIZE - off)); +mem_and (iobuf + (soff | off), s->io,MIN (s->iolen,PAGE_SIZE - off));if (off + s->iolen >PAGE_SIZE ) { page =PAGE (s->addr); -memcpy (s->storage + (page <<OOB_SHIFT ), s->io +PAGE_SIZE - off, +mem_and (s->storage + (page <<OOB_SHIFT ), s->io +PAGE_SIZE - off,MIN (OOB_SIZE , off + s->iolen -PAGE_SIZE )); }
@@ -624,7 +633,7 @@ static void glue(nand_blk_write_, PAGE_SIZE)(NANDFlashState *s)return ; } -memcpy (iobuf + soff, s->io, s->iolen); +mem_and (iobuf + soff, s->io, s->iolen);if (bdrv_write (s->bdrv, sector, iobuf,PAGE_SECTORS +2 ) ==-1 )printf ("%s: write error in sector %" PRIu64"\n" , __func__, sector);
Signature · 1 line
1.7.1
PATCH 6/12 hw/nand: qdevify
In reply to Peter MaydellFrom: Juha Riihimäki <[email protected]>
Qdevify the NAND device.
--- hw/axis_dev88.c | 2 +- hw/flash.h | 14 ++--- hw/nand.c | 164 +++++++++++++++++++++++++++++++------------------------ hw/spitz.c | 2 +- hw/tc6393xb.c | 2 +- 5 files changed, 102 insertions(+), 82 deletions(-)
hw/axis_dev88.c +1 -1
@@ -37,7 +37,7 @@struct nand_state_t { -NANDFlashState *nand; +DeviceState *nand;unsigned int rdy:1 ;unsigned int ale:1 ;unsigned int cle:1 ;
hw/flash.h +6 -8
@@ -18,15 +18,13 @@ pflash_t *pflash_cfi02_register(target_phys_addr_t base, ram_addr_t off, int be);/* nand.c */ -typedef struct NANDFlashState NANDFlashState ; -NANDFlashState *nand_init (BlockDriverState *bdrv,int manf_id,int chip_id); -void nand_done (NANDFlashState *s); -void nand_setpins (NANDFlashState *s,uint8_t cle,uint8_t ale, +DeviceState *nand_init (BlockDriverState *bdrv,int manf_id,int chip_id); +void nand_setpins (DeviceState *dev,uint8_t cle,uint8_t ale,uint8_t ce,uint8_t wp,uint8_t gnd); -void nand_getpins (NANDFlashState *s,int *rb); -void nand_setio (NANDFlashState *s,uint32_t value); -uint32_t nand_getio (NANDFlashState *s); -uint32_t nand_getbuswidth (NANDFlashState *s); +void nand_getpins (DeviceState *dev,int *rb); +void nand_setio (DeviceState *dev,uint32_t value); +uint32_t nand_getio (DeviceState *dev); +uint32_t nand_getbuswidth (DeviceState *dev);#define NAND_MFR_TOSHIBA 0x98#define NAND_MFR_SAMSUNG 0xec
hw/nand.c +93 -71
243 lines not on this page · raw message
hw/spitz.c +1 -1
@@ -48,7 +48,7 @@ typedef struct { SysBusDevice busdev; - NANDFlashState *nand; + DeviceState *nand; uint8_t ctl; uint8_t manf_id; uint8_t chip_id;
hw/tc6393xb.c +1 -1
@@ -118,7 +118,7 @@ struct TC6393xbState { } nand;int nand_enable;uint32_t nand_phys; -NANDFlashState *flash; +DeviceState *flash;ECCState ecc;DisplayState *ds;
Signature · 1 line
1.7.1
PATCH 7/12 onenand: Pass BlockDriverState to init function
In reply to Peter MaydellPass the BlockDriverState to the onenand init function so it doesn't need to look up the drive itself.
--- hw/flash.h | 3 ++- hw/nseries.c | 10 ++++++---- hw/onenand.c | 14 ++++++++------ 3 files changed, 16 insertions(+), 11 deletions(-)
hw/flash.h +2 -1
@@ -38,7 +38,8 @@ uint32_t nand_getbuswidth(DeviceState *dev);/* onenand.c */ void onenand_base_update (void *opaque,target_phys_addr_t new);void onenand_base_unmap (void *opaque); -void *onenand_init (uint32_t id,int regshift,qemu_irq irq); +void *onenand_init (BlockDriverState *bdrv,uint32_t id, +int regshift,qemu_irq irq);void *onenand_raw_otp (void *opaque);/* ecc.c */
hw/nseries.c +6 -4
@@ -31,6 +31,7 @@#include "hw.h" #include "bt.h" #include "loader.h" +#include "blockdev.h" /* Nokia N8x0 support */ struct n800_s {
@@ -163,13 +164,14 @@ static const uint8_t n8x0_cal_bt_id[] = {static void n8x0_nand_setup (struct n800_s *s) {char *otp_region; +DriveInfo *dinfo; + dinfo =drive_get (IF_MTD ,0 ,0 );/* Either ec40xx or ec48xx are OK for the ID */ + s->nand =onenand_init (dinfo ? dinfo->bdrv :0 ,0xec4800 ,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 =onenand_init (0xec4800 ,1 , -qdev_get_gpio_in (s->cpu->gpio, -N8X0_ONENAND_GPIO )))); + onenand_base_unmap, 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 +8 -6
@@ -615,10 +615,10 @@ static CPUWriteMemoryFunc * const onenand_writefn[] = { onenand_write, }; -void *onenand_init (uint32_t id,int regshift,qemu_irq irq) +void *onenand_init (BlockDriverState *bdrv,uint32_t id, +int regshift,qemu_irq irq) {OneNANDState *s = (OneNANDState *)qemu_mallocz (sizeof (*s)); -DriveInfo *dinfo =drive_get (IF_MTD ,0 ,0 );uint32_t size =1 << (24 + ((id >>12 ) &7 ));void *ram;
@@ -632,11 +632,13 @@ void *onenand_init(uint32_t id, int regshift, qemu_irq irq) s->density_mask = (id & (1 <<11 )) ? (1 << (6 + ((id >>12 ) &7 ))) :0 ; s->iomemtype =cpu_register_io_memory (onenand_readfn, onenand_writefn, s,DEVICE_NATIVE_ENDIAN ); -if (!dinfo) + s->bdrv = bdrv; +if (!s->bdrv) { s->image =memset (qemu_malloc (size + (size >>5 )), -0xff , size + (size >>5 )); -else - s->bdrv = dinfo->bdrv; +0xff , size + (size >>5 )); + }else { + s->bdrv_cur = s->bdrv; + } s->otp =memset (qemu_malloc ((64 +2 ) <<PAGE_SHIFT ),0xff , (64 +2 ) <<PAGE_SHIFT ); s->ram =qemu_ram_alloc (NULL ,"onenand.ram" ,0xc000 << s->shift);
Signature · 1 line
1.7.1
PATCH 8/12 onenand: Handle various ID fields separately
In reply to Peter MaydellFrom: Juha Riihimäki <[email protected]>
Handle the manufacturer, device and version IDs separately rather than smooshing them all together into a single uint32_t. Note that the ID registers are actually 16 bit, even though typically the top bits are 0 and the Read Identification Data command only returns the bottom 8 bits.
--- hw/flash.h | 3 ++- hw/nseries.c | 5 +++-- hw/onenand.c | 29 ++++++++++++++++++----------- 3 files changed, 23 insertions(+), 14 deletions(-)
hw/flash.h +2 -1
@@ -38,7 +38,8 @@ uint32_t nand_getbuswidth(DeviceState *dev);/* onenand.c */ void onenand_base_update (void *opaque,target_phys_addr_t new);void onenand_base_unmap (void *opaque); -void *onenand_init (BlockDriverState *bdrv,uint32_t id, +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);
hw/nseries.c +3 -2
@@ -167,8 +167,9 @@ static void n8x0_nand_setup(struct n800_s *s)DriveInfo *dinfo; dinfo =drive_get (IF_MTD ,0 ,0 ); -/* Either ec40xx or ec48xx are OK for the ID */ - s->nand =onenand_init (dinfo ? dinfo->bdrv :0 ,0xec4800 ,1 , +/* 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);
hw/onenand.c +18 -11
@@ -31,7 +31,11 @@#define BLOCK_SHIFT (PAGE_SHIFT + 6) typedef struct { - uint32_t id; + struct { + uint16_t man; + uint16_t dev; + uint16_t ver; + } id; int shift; target_phys_addr_t base; qemu_irq intr;
@@ -453,12 +457,12 @@ static uint32_t onenand_read(void *opaque, target_phys_addr_t addr)return lduw_le_p (s->boot[0 ] + addr);case 0xf000 :/* Manufacturer ID */ -return (s->id >>16 ) &0xff ; +return s->id.man;case 0xf001 :/* Device ID */ -return (s->id >>8 ) &0xff ; -/* TODO: get the following values from a real chip! */ +return s->id.dev;case 0xf002 :/* Version ID */ -return (s->id >>0 ) &0xff ; +return s->id.ver; +/* TODO: get the following values from a real chip! */ case 0xf003 :/* Data Buffer size */ return 1 <<PAGE_SHIFT ;case 0xf004 :/* Boot Buffer size */
@@ -541,8 +545,8 @@ static void onenand_write(void *opaque, target_phys_addr_t addr,case 0x0090 :/* Read Identification Data */ memset (s->boot[0 ],0 ,3 << s->shift); - s->boot[0 ][0 << s->shift] = (s->id >>16 ) &0xff ; - s->boot[0 ][1 << s->shift] = (s->id >>8 ) &0xff ; + s->boot[0 ][0 << s->shift] = s->id.man &0xff ; + s->boot[0 ][1 << s->shift] = s->id.dev &0xff ; s->boot[0 ][2 << s->shift] = s->wpstatus &0xff ;break ;
@@ -615,21 +619,24 @@ static CPUWriteMemoryFunc * const onenand_writefn[] = { onenand_write, }; -void *onenand_init (BlockDriverState *bdrv,uint32_t id, +void *onenand_init (BlockDriverState *bdrv, +uint16_t man_id,uint16_t dev_id,uint16_t ver_id,int regshift,qemu_irq irq) {OneNANDState *s = (OneNANDState *)qemu_mallocz (sizeof (*s)); -uint32_t size =1 << (24 + ((id >>12 ) &7 )); +uint32_t size =1 << (24 + ((dev_id >>4 ) &7 ));void *ram; s->shift = regshift; s->intr = irq; s->rdy =NULL ; - s->id = id; + s->id.man = man_id; + s->id.dev = dev_id; + s->id.ver = ver_id; s->blocks = size >>BLOCK_SHIFT ; s->secs = size >>9 ; s->blockwp =qemu_malloc (s->blocks); - s->density_mask = (id & (1 <<11 )) ? (1 << (6 + ((id >>12 ) &7 ))) :0 ; + s->density_mask = (dev_id &0x08 ) ? (1 << (6 + ((dev_id >>4 ) &7 ))) :0 ; s->iomemtype =cpu_register_io_memory (onenand_readfn, onenand_writefn, s,DEVICE_NATIVE_ENDIAN ); s->bdrv = bdrv;
Signature · 1 line
1.7.1
PATCH 9/12 onenand: Ignore zero writes to boot command space
In reply to Peter MaydellFrom: Juha Riihimäki <[email protected]>
Ignore zero writes to the boot command space; Linux will issue these in the powerdown/reset sequence.
--- hw/onenand.c | 7 +++++++ 1 files changed, 7 insertions(+), 0 deletions(-)
hw/onenand.c +7 -0
@@ -550,6 +550,13 @@ static void onenand_write(void *opaque, target_phys_addr_t addr, s->boot[0 ][2 << s->shift] = s->wpstatus &0xff ;break ; +case 0x0000 : +/* ignore zero writes without error messages, +* linux omap2/3 kernel will issue these upon +* powerdown/reset sequence. +*/ +break ; +default :fprintf (stderr,"%s: unknown OneNAND boot command %x\n" , __FUNCTION__, value);
Signature · 1 line
1.7.1
PATCH 10/12 hw/onenand: program actions can only clear bits
In reply to Peter MaydellFrom: Juha Riihimäki <[email protected]>
The program actions onenand_prog_main() and onenand_prog_spare() can only set bits.
This implies a rewrite of onenand_erase() to not use the program functions, since erase does need to set bits.
--- hw/onenand.c | 135 +++++++++++++++++++++++++++++++++++++++++++++------------ 1 files changed, 106 insertions(+), 29 deletions(-)
hw/onenand.c +106 -29
@@ -179,14 +179,39 @@ static inline int onenand_load_main(OneNANDState *s, int sec, int secn,static inline int onenand_prog_main (OneNANDState *s,int sec,int secn,void *src) { -if (s->bdrv_cur) -return bdrv_write (s->bdrv_cur, sec, src, secn) <0 ; -else if (sec + secn > s->secs_cur) -return 1 ; - -memcpy (s->current + (sec <<9 ), src, secn <<9 ); +int result =0 ; + +if (secn >0 ) { +uint32_t size = (uint32_t )secn *512 ; +const uint8_t *sp = (const uint8_t *)src; +uint8_t *dp =0 ; +if (s->bdrv_cur) { + dp =qemu_malloc (size); +if (!dp ||bdrv_read (s->bdrv_cur, sec, dp, secn) <0 ) { + result =1 ; + } + }else { +if (sec + secn > s->secs_cur) { + result =1 ; + }else { + dp = (uint8_t *)s->current + (sec <<9 ); + } + } +if (!result) { +uint32_t i; +for (i =0 ; i < size; i++) { + dp[i] &= sp[i]; + } +if (s->bdrv_cur) { + result =bdrv_write (s->bdrv_cur, sec, dp, secn) <0 ; + } + } +if (dp && s->bdrv_cur) { +qemu_free (dp); + } + } -return 0 ; +return result; } static inline int onenand_load_spare(OneNANDState *s, int sec, int secn,
@@ -209,35 +234,87 @@ static inline int onenand_load_spare(OneNANDState *s, int sec, int secn,static inline int onenand_prog_spare (OneNANDState *s,int sec,int secn,void *src) { -uint8_t buf[512 ]; - -if (s->bdrv_cur) { -if (bdrv_read (s->bdrv_cur, s->secs_cur + (sec >>5 ), buf,1 ) <0 ) -return 1 ; -memcpy (buf + ((sec &31 ) <<4 ), src, secn <<4 ); -return bdrv_write (s->bdrv_cur, s->secs_cur + (sec >>5 ), buf,1 ) <0 ; - }else if (sec + secn > s->secs_cur) -return 1 ; - -memcpy (s->current + (s->secs_cur <<9 ) + (sec <<4 ), src, secn <<4 ); - -return 0 ; +int result =0 ; +if (secn >0 ) { +const uint8_t *sp = (const uint8_t *)src; +uint8_t *dp =0 , *dpp =0 ; +if (s->bdrv_cur) { + dp =qemu_malloc (512 ); +if (!dp ||bdrv_read (s->bdrv_cur, + s->secs_cur + (sec >>5 ), + dp,1 ) <0 ) { + result =1 ; + }else { + dpp = dp + ((sec &31 ) <<4 ); + } + }else { +if (sec + secn > s->secs_cur) { + result =1 ; + }else { + dpp = s->current + (s->secs_cur <<9 ) + (sec <<4 ); + } + } +if (!result) { +uint32_t i; +for (i =0 ; i < (secn <<4 ); i++) { + dpp[i] &= sp[i]; + } +if (s->bdrv_cur) { + result =bdrv_write (s->bdrv_cur, s->secs_cur + (sec >>5 ), + dp,1 ) <0 ; + } + } +if (dp) { +qemu_free (dp); + } + } +return result; }static inline int onenand_erase (OneNANDState *s,int sec,int num) { -/* TODO: optimise */ -uint8_t buf[512 ]; - -memset (buf,0xff ,sizeof (buf)); -for (; num >0 ; num --, sec ++) { -if (onenand_prog_main (s, sec,1 , buf)) -return 1 ; -if (onenand_prog_spare (s, sec,1 , buf)) -return 1 ; +uint8_t *blankbuf, *tmpbuf; + blankbuf =qemu_malloc (512 ); +if (!blankbuf) { +return 1 ; + } + tmpbuf =qemu_malloc (512 ); +if (!tmpbuf) { +qemu_free (blankbuf); +return 1 ; + } +memset (blankbuf,0xff ,512 ); +for (; num >0 ; num--, sec++) { +if (s->bdrv_cur) { +int erasesec = s->secs_cur + (sec >>5 ); +if (bdrv_write (s->bdrv_cur, sec, blankbuf,1 )) { + goto fail; + } +if (bdrv_read (s->bdrv_cur, erasesec, tmpbuf,1 ) <0 ) { + goto fail; + } +memcpy (tmpbuf + ((sec &31 ) <<4 ), blankbuf,1 <<4 ); +if (bdrv_write (s->bdrv_cur, erasesec, tmpbuf,1 ) <0 ) { + goto fail; + } + }else { +if (sec +1 > s->secs_cur) { + goto fail; + } +memcpy (s->current + (sec <<9 ), blankbuf,512 ); +memcpy (s->current + (s->secs_cur <<9 ) + (sec <<4 ), + blankbuf,1 <<4 ); + } } +qemu_free (tmpbuf); +qemu_free (blankbuf);return 0 ; + +fail: +qemu_free (tmpbuf); +qemu_free (blankbuf); +return 1 ; }static void onenand_command (OneNANDState *s,int cmd)
Signature · 1 line
1.7.1
PATCH 11/12 hw/sysbus: Add sysbus_mmio_unmap() for unmapping a region
In reply to Peter MaydellFrom: Juha Riihimäki <[email protected]>
Add support for unmapping a SysBus device's mmio region, via a new function sysbus_mmio_unmap(). This simply reverses the effect of sysbus_mmio_map().
--- hw/sysbus.c | 17 +++++++++++++++++ hw/sysbus.h | 1 + 2 files changed, 18 insertions(+), 0 deletions(-)
hw/sysbus.c +17 -0
@@ -39,6 +39,23 @@ void sysbus_connect_irq(SysBusDevice *dev, int n, qemu_irq irq) } } +void sysbus_mmio_unmap (SysBusDevice *dev,int n) +{ +assert (n >=0 && n < dev->num_mmio); + +if (dev->mmio[n].addr == (target_phys_addr_t)-1 ) { +/* region already unmapped */ +return ; + } +if (dev->mmio[n].cb) { + dev->mmio[n].cb (dev, (target_phys_addr_t)-1 ); + }else { +cpu_register_physical_memory (dev->mmio[n].addr, dev->mmio[n].size, +IO_MEM_UNASSIGNED ); + } + dev->mmio[n].addr = (target_phys_addr_t)-1 ; +} +void sysbus_mmio_map (SysBusDevice *dev,int n,target_phys_addr_t addr) {assert (n >=0 && n < dev->num_mmio);
hw/sysbus.h +1 -0
@@ -53,6 +53,7 @@ void sysbus_init_ioports(SysBusDevice *dev, pio_addr_t ioport, pio_addr_t size);void sysbus_connect_irq (SysBusDevice *dev,int n,qemu_irq irq);void sysbus_mmio_map (SysBusDevice *dev,int n,target_phys_addr_t addr); +void sysbus_mmio_unmap (SysBusDevice *dev,int n);/* Legacy helper function for creating devices. */ DeviceState *sysbus_create_varargs(const char *name,
Signature · 1 line
1.7.1
PATCH 12/12 hw/onenand: qdevify
In reply to Peter MaydellFrom: Juha Riihimäki <[email protected]>
Qdevify the ONENAND device.
--- hw/flash.h | 8 +- hw/onenand.c | 208 +++++++++++++++++++++++++++++++++++++++++++++------------- 2 files changed, 167 insertions(+), 49 deletions(-)
hw/flash.h +4 -4
@@ -38,10 +38,10 @@ uint32_t nand_getbuswidth(DeviceState *dev);/* 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); +DeviceState *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 (DeviceState *onenand_device);/* ecc.c */ typedef struct {
hw/onenand.c +163 -45
306 lines not on this page · raw message
Signature · 1 line
1.7.1
Ping on this one too, since I'm nearly ready with the next chunk of patches (18 patches fixing bugs and adding NAND support to omap_gpmc) and they obviously depend on this set.
-- PMM
Quoted 47 lines · Peter Maydell
This patchseries is more goodies from the Meego tree. Specifically, various bug fixes to hw/nand and hw/onenand, plus conversion of both to sysbus.
[An advance note on the next thing due to come out of the pipe: qdeving nand and onenand allows us to move to qdevification of
omap_gpmc, which takes both of those (and other things) as 'downstream' devices. That change will make it accept arbitrary SysBus devices as its 'downstream' devices rather than the current setup of taking an opaque pointer and a pair of resize/unmap function pointers. (There are also patches which add NAND support so you can tellomap_gpmc"this is a NAND device" and it then uses the nand_setpins/nand_getpins/nand_setio interface.) The rationale for using SysBus there rather than defining some new kind of bus is that you want to be able to plug any random thing into it; for instance the Overo board has a lan9118 ethernet controller hanging off the GPMC. ]A note on dependencies:
* This patch depends on the omap gpio patchset (although more textually than seriously semantically)
* the six nand patches and the six onenand patches are broadly independent of each otherJuha Riihimäki (9):
hw/nand: Support large NAND devices
hw/nand: Support devices wider than 8 bits hw/nand: Support multiple reads following READ STATUS hw/nand: qdevify
onenand: Handle various ID fields separately
onenand: Ignore zero writes to boot command space hw/onenand: program actions can only clear bits hw/sysbus: Addsysbus_mmio_unmap()for unmapping a region hw/onenand: qdevifyPeter Maydell (3):
hw/nand: Pass block device state to init function hw/nand: Writing to NAND can only clear bits
onenand: Pass BlockDriverState to init functionhw/axis_dev88.c | 8 +-
hw/flash.h | 19 ++--
hw/nand.c | 345 ++++++++++++++++++++++++++++++++-------------------hw/nseries.c| 13 ++-
hw/onenand.c | 373 +++++++++++++++++++++++++++++++++++++++++++------------hw/spitz.c| 6 +-
hw/sysbus.c | 17 +++
hw/sysbus.h | 1 +
hw/tc6393xb.c | 7 +-9 files changed, 561 insertions(+), 228 deletions(-)