omap patches (gpio, nand, onenand, lm832x)
This pull request gathers up my recent omap patches:
* omap-gpio qdevification
* nand bugfixes and qdevification
* onenand bugfixes
* fix crash bug in n810/lm832x when key is pressed
I have omitted patch 11/12 from the nand/onenand patchset
(http://patchwork.ozlabs.org/patch/104841/
"hw/sysbus: Add sysbus_mmio_unmap() for unmapping a region")
because it needs updating now Avi's memory API changes have landed, and 12/12 (hw/onenand: qdevify) because that depends on 11/12. I'll post newer versions of those next week, probably.
The following changes since commit c62f6d1d76aea587556c85b6b7b5c44167006264:
monitor: fix build breakage with --disable-vnc (2011-07-29 09:33:56 -0500)
are available in the git repository at:
git://git.linaro.org/people/pmaydell/qemu-arm.git omap-for-upstream
Juha Riihimäki (9):
hw/omap_l4.c: Add helper function omap_l4_region_base hw/omap_gpio.c: Convert to qdev
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
Peter Maydell (6):
hw/omap_gpio.c: Don't complain about some writes to r/o registers hw/omap_clk: Add the clock for the OMAP2430-specific fifth GPIO module
lm832x: Take DeviceState pointer in lm832x_key_event() 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 | 17 ++-- hw/i2c.h | 2 +- hw/lm832x.c | 4 +- hw/nand.c | 345 +++++++++++++++++++++++++++++++++++-------------------- hw/nseries.c | 63 +++++----- hw/omap.h | 22 +--- hw/omap1.c | 10 +- hw/omap2.c | 34 ++++-- hw/omap_clk.c | 6 +- hw/omap_gpio.c | 263 ++++++++++++++++++++++++------------------ hw/omap_l4.c | 6 + hw/onenand.c | 183 ++++++++++++++++++++++------- hw/palm.c | 26 ++-- hw/spitz.c | 6 +- hw/tc6393xb.c | 7 +- 16 files changed, 627 insertions(+), 375 deletions(-)
PATCH 1/15 hw/omap_l4.c: Add helper function omap_l4_region_base
From: Juha Riihimäki <[email protected]>
Add helper function omap_l4_region_base() to return the base address of a particular region of an L4 target agent.
--- hw/omap.h | 2 ++ hw/omap_l4.c | 6 ++++++ 2 files changed, 8 insertions(+), 0 deletions(-)
hw/omap.h +2 -0
@@ -93,6 +93,8 @@ struct omap_target_agent_s *omap_l4ta_get( int cs);target_phys_addr_t omap_l4_attach (struct omap_target_agent_s *ta,int region,int iotype); +target_phys_addr_t omap_l4_region_base (struct omap_target_agent_s *ta, +int region);int l4_register_io_memory (CPUReadMemoryFunc *const *mem_read,CPUWriteMemoryFunc *const *mem_write,void *opaque);
hw/omap_l4.c +6 -0
@@ -146,6 +146,12 @@ struct omap_l4_s *omap_l4_init(target_phys_addr_t base, int ta_num)return bus; } +target_phys_addr_t omap_l4_region_base (struct omap_target_agent_s *ta, +int region) +{ +return ta->bus->base + ta->start[region].offset; +} +static uint32_t omap_l4ta_read (void *opaque,target_phys_addr_t addr) {struct omap_target_agent_s *s = (struct omap_target_agent_s *) opaque;
Signature · 1 line
1.7.1
PATCH 2/15 hw/omap_gpio.c: Don't complain about some writes to r/o registers
In reply to Peter MaydellDon't complain about some writes to r/o OMAP2 GPIO registers, because the kernel will do them anyway.
--- hw/omap_gpio.c | 4 ++-- 1 files changed, 2 insertions(+), 2 deletions(-)
hw/omap_gpio.c +2 -2
@@ -385,7 +385,7 @@ static void omap2_gpio_module_write(void *opaque, target_phys_addr_t addr,case 0x00 :/* GPIO_REVISION */ case 0x14 :/* GPIO_SYSSTATUS */ case 0x38 :/* GPIO_DATAIN */ -OMAP_RO_REG (addr); +/* read-only, ignore quietly */ break ;case 0x10 :/* GPIO_SYSCONFIG */
@@ -531,7 +531,7 @@ static void omap2_gpio_module_writep(void *opaque, target_phys_addr_t addr,case 0x00 :/* GPIO_REVISION */ case 0x14 :/* GPIO_SYSSTATUS */ case 0x38 :/* GPIO_DATAIN */ -OMAP_RO_REG (addr); +/* read-only, ignore quietly */ break ;case 0x10 :/* GPIO_SYSCONFIG */
Signature · 1 line
1.7.1
Re: [Qemu-devel] [PATCH 02/15] hw/omap_gpio.c: Don't complain about some writes to r/o registers
Hi,
I went ahead and pushed the series with the exception of this patch and 14/15 because I think these are the types of patches that should remain in downstream as a reminder, is there an argument for not fixing these things in Linux?
In patch 04 I renamed omap2_gpio_module_set to omap2_gpio_set because the parameter is no longer the module pointer. By the way I think we should also pass the target agent pointer on creation the same way clocks are passed and use omap_l4_attach.
In patch 07 I bumped the vmstate version because the structure seems to have changed.
In patch 12 I removed the
else {
s->bdrv_cur = s->bdrv;
} part because there seemed to be no reason to add it, please checkthat I haven't broken something.
Cheers
Quoted 34 lines · Peter Maydell
Don't complain about some writes to r/o OMAP2 GPIO registers, because the kernel will do them anyway.
Signed-off-by Peter Maydell <[email protected]>---
hw/omap_gpio.c | 4 ++--1 files changed, 2 insertions(+), 2 deletions(-)hw/omap_gpio.c +0
-0@@ -385,7 +385,7 @@ static void omap2_gpio_module_write(void *opaque, target_phys_addr_t addr,case
0x00: /*GPIO_REVISION*/
case0x14: /*GPIO_SYSSTATUS*/
case0x38: /*GPIO_DATAIN*/
- OMAP_RO_REG(addr);
+ /* read-only, ignore quietly */
break;case
0x10: /*GPIO_SYSCONFIG*/hw/omap_gpio.c +0
-0@@ -531,7 +531,7 @@ static void omap2_gpio_module_writep(void *opaque, target_phys_addr_t addr,case
0x00: /*GPIO_REVISION*/
case0x14: /*GPIO_SYSSTATUS*/
case0x38: /*GPIO_DATAIN*/
- OMAP_RO_REG(addr);
+ /* read-only, ignore quietly */
break;case
0x10: /*GPIO_SYSCONFIG*/
--
1.7.1
Re: [Qemu-devel] [PATCH 02/15] hw/omap_gpio.c: Don't complain about some writes to r/o registers
Quoted 1 line · andrzej zaborowski
I went ahead and pushed the series
Thanks.
Quoted 4 lines
with the exception of this patch
and 14/15 because I think these are the types of patches that should remain in downstream as a reminder, is there an argument for not fixing these things in Linux?
I think the only arguments are "it's too hard" and "I'd like to run legacy images without having qemu constantly complaining and making '-serial stdio' unusable" :-) [have you seen how much chatter you get out of n810 running a meego image?] I think I've said before that really we ought to have this kind of message more consistently and conveniently enablable/disablable.
I'll leave this sort of change out of future patches; when I get down to the point where they're the only thing left in my patch stack (a) I'll be very happy and (b) I might look at a nicer way to handle them.
Quoted 4 lines
In patch 04 I renamed
omap2_gpio_module_settoomap2_gpio_setbecause the parameter is no longer the module pointer. By the way I think we should also pass the target agent pointer on creation the same way clocks are passed and useomap_l4_attach.
The clock passing thing is (as per comments) a bit nasty; at the moment sysbus is the closest we have to a nice way of exposing "I have some MMIO regions" so I'm a bit reluctant to hide it behind another magic pointer property. I'll have a think about this, though.
Quoted 2 lines
In patch 07 I bumped the vmstate version because the structure seems to have changed.
Oops, yes. I had a note at some point to look more carefully at the vmstate change but I must have forgotten about it :-( I agree we can just bump the version.
Quoted 5 lines
In patch 12 I removed the
else {
s->bdrv_cur =s->bdrv;
} part because there seemed to be no reason to add it, please check that I haven't broken something.
That looks like it should be OK, we'll always call onenand_reset() which will set bdrv_cur to bdrv.
-- PMM
PATCH 3/15 hw/omap_clk: Add the clock for the OMAP2430-specific fifth GPIO module
In reply to Peter MaydellThe OMAP2430 has a fifth GPIO module which earlier OMAP2 models lack; add the clock definition for it.
--- hw/omap_clk.c | 6 +++++- 1 files changed, 5 insertions(+), 1 deletions(-)
hw/omap_clk.c +5 -1
@@ -836,7 +836,7 @@ static struct clk i2c2_iclk = { .parent = &core_l4_iclk, }; -static struct clk gpio_dbclk[4 ] = { +static struct clk gpio_dbclk[5 ] = { { .name ="gpio1_dbclk" , .flags =CLOCK_IN_OMAP242X |CLOCK_IN_OMAP243X ,
@@ -853,6 +853,10 @@ static struct clk gpio_dbclk[4] = { .name = "gpio4_dbclk", .flags = CLOCK_IN_OMAP242X | CLOCK_IN_OMAP243X, .parent = &wu_32k_clk, + }, { + .name = "gpio5_dbclk", + .flags = CLOCK_IN_OMAP243X, + .parent = &wu_32k_clk, }, };
Signature · 1 line
1.7.1
PATCH 4/15 hw/omap_gpio.c: Convert to qdev
In reply to Peter MaydellFrom: Juha Riihimäki <[email protected]>
Convert the OMAP GPIO module to qdev.
--- hw/nseries.c | 47 +++++----- hw/omap.h | 20 +---- hw/omap1.c | 10 ++- hw/omap2.c | 34 ++++++-- hw/omap_gpio.c | 259 ++++++++++++++++++++++++++++++++----------------------- hw/palm.c | 26 +++--- 6 files changed, 220 insertions(+), 176 deletions(-)
hw/nseries.c +23 -24
@@ -134,9 +134,9 @@ static void n800_mmc_cs_cb(void *opaque, int line, int level)static void n8x0_gpio_setup (struct n800_s *s) {qemu_irq *mmc_cs =qemu_allocate_irqs (n800_mmc_cs_cb, s->cpu->mmc,1 ); -omap2_gpio_out_set (s->cpu->gpif,N8X0_MMC_CS_GPIO , mmc_cs[0 ]); +qdev_connect_gpio_out (s->cpu->gpio,N8X0_MMC_CS_GPIO , mmc_cs[0 ]); -qemu_irq_lower (omap2_gpio_in_get (s->cpu->gpif,N800_BAT_COVER_GPIO )[0 ]); +qemu_irq_lower (qdev_get_gpio_in (s->cpu->gpio,N800_BAT_COVER_GPIO )); }#define MAEMO_CAL_HEADER (...) \
@@ -168,8 +168,8 @@ static void n8x0_nand_setup(struct n800_s *s)omap_gpmc_attach (s->cpu->gpmc,N8X0_ONENAND_CS ,0 , onenand_base_update, onenand_base_unmap, (s->nand =onenand_init (0xec4800 ,1 , -omap2_gpio_in_get (s->cpu->gpif, -N8X0_ONENAND_GPIO )[0 ]))); +qdev_get_gpio_in (s->cpu->gpio, +N8X0_ONENAND_GPIO )))); otp_region =onenand_raw_otp (s->nand);memcpy (otp_region +0x000 , n8x0_cal_wlan_mac,sizeof (n8x0_cal_wlan_mac));
@@ -180,7 +180,7 @@ static void n8x0_nand_setup(struct n800_s *s)static void n8x0_i2c_setup (struct n800_s *s) {DeviceState *dev; -qemu_irq tmp_irq =omap2_gpio_in_get (s->cpu->gpif,N8X0_TMP105_GPIO )[0 ]; +qemu_irq tmp_irq =qdev_get_gpio_in (s->cpu->gpio,N8X0_TMP105_GPIO );/* Attach the CPU on one end of our I2C bus. */ s->i2c =omap_i2c_bus (s->cpu->i2c[0 ]);
@@ -249,8 +249,8 @@ static void n800_tsc_kbd_setup(struct n800_s *s)/* XXX: are the three pins inverted inside the chip between the * tsc and the cpu (N4111)? */ qemu_irq penirq =NULL ;/* NC */ -qemu_irq kbirq =omap2_gpio_in_get (s->cpu->gpif,N800_TSC_KP_IRQ_GPIO )[0 ]; -qemu_irq dav =omap2_gpio_in_get (s->cpu->gpif,N800_TSC_TS_GPIO )[0 ]; +qemu_irq kbirq =qdev_get_gpio_in (s->cpu->gpio,N800_TSC_KP_IRQ_GPIO ); +qemu_irq dav =qdev_get_gpio_in (s->cpu->gpio,N800_TSC_TS_GPIO ); s->ts.chip =tsc2301_init (penirq, kbirq, dav); s->ts.opaque = s->ts.chip->opaque;
@@ -269,7 +269,7 @@ static void n800_tsc_kbd_setup(struct n800_s *s)static void n810_tsc_setup (struct n800_s *s) { -qemu_irq pintdav =omap2_gpio_in_get (s->cpu->gpif,N810_TSC_TS_GPIO )[0 ]; +qemu_irq pintdav =qdev_get_gpio_in (s->cpu->gpio,N810_TSC_TS_GPIO ); s->ts.opaque =tsc2005_init (pintdav); s->ts.txrx = tsc2005_txrx;
@@ -361,7 +361,7 @@ static int n810_keys[0x80] = {static void n810_kbd_setup (struct n800_s *s) { -qemu_irq kbd_irq =omap2_gpio_in_get (s->cpu->gpif,N810_KEYBOARD_GPIO )[0 ]; +qemu_irq kbd_irq =qdev_get_gpio_in (s->cpu->gpio,N810_KEYBOARD_GPIO );DeviceState *dev;int i;
@@ -726,15 +726,15 @@ static void n8x0_dss_setup(struct n800_s *s)static void n8x0_cbus_setup (struct n800_s *s) { -qemu_irq dat_out =omap2_gpio_in_get (s->cpu->gpif,N8X0_CBUS_DAT_GPIO )[0 ]; -qemu_irq retu_irq =omap2_gpio_in_get (s->cpu->gpif,N8X0_RETU_GPIO )[0 ]; -qemu_irq tahvo_irq =omap2_gpio_in_get (s->cpu->gpif,N8X0_TAHVO_GPIO )[0 ]; +qemu_irq dat_out =qdev_get_gpio_in (s->cpu->gpio,N8X0_CBUS_DAT_GPIO ); +qemu_irq retu_irq =qdev_get_gpio_in (s->cpu->gpio,N8X0_RETU_GPIO ); +qemu_irq tahvo_irq =qdev_get_gpio_in (s->cpu->gpio,N8X0_TAHVO_GPIO );CBus *cbus =cbus_init (dat_out); -omap2_gpio_out_set (s->cpu->gpif,N8X0_CBUS_CLK_GPIO , cbus->clk); -omap2_gpio_out_set (s->cpu->gpif,N8X0_CBUS_DAT_GPIO , cbus->dat); -omap2_gpio_out_set (s->cpu->gpif,N8X0_CBUS_SEL_GPIO , cbus->sel); +qdev_connect_gpio_out (s->cpu->gpio,N8X0_CBUS_CLK_GPIO , cbus->clk); +qdev_connect_gpio_out (s->cpu->gpio,N8X0_CBUS_DAT_GPIO , cbus->dat); +qdev_connect_gpio_out (s->cpu->gpio,N8X0_CBUS_SEL_GPIO , cbus->sel);cbus_attach (cbus, s->retu =retu_init (retu_irq,1 ));cbus_attach (cbus, s->tahvo =tahvo_init (tahvo_irq,1 ));
@@ -743,13 +743,12 @@ static void n8x0_cbus_setup(struct n800_s *s)static void n8x0_uart_setup (struct n800_s *s) {CharDriverState *radio =uart_hci_init ( -omap2_gpio_in_get (s->cpu->gpif, -N8X0_BT_HOST_WKUP_GPIO )[0 ]); +qdev_get_gpio_in (s->cpu->gpio,N8X0_BT_HOST_WKUP_GPIO )); -omap2_gpio_out_set (s->cpu->gpif,N8X0_BT_RESET_GPIO , -csrhci_pins_get (radio)[csrhci_pin_reset]); -omap2_gpio_out_set (s->cpu->gpif,N8X0_BT_WKUP_GPIO , -csrhci_pins_get (radio)[csrhci_pin_wakeup]); +qdev_connect_gpio_out (s->cpu->gpio,N8X0_BT_RESET_GPIO , +csrhci_pins_get (radio)[csrhci_pin_reset]); +qdev_connect_gpio_out (s->cpu->gpio,N8X0_BT_WKUP_GPIO , +csrhci_pins_get (radio)[csrhci_pin_wakeup]);omap_uart_attach (s->cpu->uart[BT_UART ], radio); }
@@ -763,7 +762,7 @@ static void n8x0_usb_power_cb(void *opaque, int line, int level)static void n8x0_usb_setup (struct n800_s *s) { -qemu_irq tusb_irq =omap2_gpio_in_get (s->cpu->gpif,N8X0_TUSB_INT_GPIO )[0 ]; +qemu_irq tusb_irq =qdev_get_gpio_in (s->cpu->gpio,N8X0_TUSB_INT_GPIO );qemu_irq tusb_pwr =qemu_allocate_irqs (n8x0_usb_power_cb, s,1 )[0 ];TUSBState *tusb =tusb6010_init (tusb_irq);
@@ -774,7 +773,7 @@ static void n8x0_usb_setup(struct n800_s *s) tusb6010_sync_io(tusb), NULL, NULL, tusb); s->usb = tusb; -omap2_gpio_out_set (s->cpu->gpif,N8X0_TUSB_ENABLE_GPIO , tusb_pwr); +qdev_connect_gpio_out (s->cpu->gpio,N8X0_TUSB_ENABLE_GPIO , tusb_pwr); }/* Setup done before the main bootloader starts by some early setup code
@@ -1020,7 +1019,7 @@ static void n8x0_boot_init(void *opaque)/* If the machine has a slided keyboard, open it */ if (s->kbd) -qemu_irq_raise (omap2_gpio_in_get (s->cpu->gpif,N810_SLIDE_GPIO )[0 ]); +qemu_irq_raise (qdev_get_gpio_in (s->cpu->gpio,N810_SLIDE_GPIO )); }#define OMAP_TAG_NOKIA_BT 0x4e01
hw/omap.h +1 -19
@@ -683,22 +683,6 @@ qemu_irq *omap_mpuio_in_get(struct omap_mpuio_s *s);void omap_mpuio_out_set (struct omap_mpuio_s *s,int line,qemu_irq handler);void omap_mpuio_key (struct omap_mpuio_s *s,int row,int col,int down); -/* omap1 gpio module interface */ -struct omap_gpio_s ; -struct omap_gpio_s *omap_gpio_init (target_phys_addr_t base, -qemu_irq irq,omap_clk clk); -void omap_gpio_reset (struct omap_gpio_s *s); -qemu_irq *omap_gpio_in_get (struct omap_gpio_s *s); -void omap_gpio_out_set (struct omap_gpio_s *s,int line,qemu_irq handler); - -/* omap2 gpio interface */ -struct omap_gpif_s ; -struct omap_gpif_s *omap2_gpio_init (struct omap_target_agent_s *ta, -qemu_irq *irq,omap_clk *fclk,omap_clk iclk,int modules); -void omap_gpif_reset (struct omap_gpif_s *s); -qemu_irq *omap2_gpio_in_get (struct omap_gpif_s *s,int start); -void omap2_gpio_out_set (struct omap_gpif_s *s,int line,qemu_irq handler); -struct uWireSlave {uint16_t (*receive)(void *opaque);void (*send)(void *opaque,uint16_t data);
@@ -852,7 +836,7 @@ struct omap_mpu_state_s {/* MPUI-TIPB peripherals */ struct omap_uart_s *uart[3 ]; -struct omap_gpio_s *gpio; +DeviceState *gpio;struct omap_mcbsp_s *mcbsp1;struct omap_mcbsp_s *mcbsp3;
@@ -950,8 +934,6 @@ struct omap_mpu_state_s {struct omap_gpmc_s *gpmc;struct omap_sysctl_s *sysc; -struct omap_gpif_s *gpif; -struct omap_mcspi_s *mcspi[2 ];struct omap_dss_s *dss;
hw/omap1.c +7 -3
@@ -27,6 +27,7 @@#include "pc.h" #include "blockdev.h" #include "range.h" +#include "sysbus.h" /* Should signal the TCMI/GPMC */ uint32_t omap_badwidth_read8 (void *opaque,target_phys_addr_t addr)
@@ -3585,7 +3586,6 @@ static void omap1_mpu_reset(void *opaque)omap_uart_reset (mpu->uart[2 ]);omap_mmc_reset (mpu->mmc);omap_mpuio_reset (mpu->mpuio); -omap_gpio_reset (mpu->gpio);omap_uwire_reset (mpu->microwire);omap_pwl_reset (mpu);omap_pwt_reset (mpu);
@@ -3845,8 +3845,12 @@ struct omap_mpu_state_s *omap310_mpu_init(unsigned long sdram_size, s->irq[1 ][OMAP_INT_KEYBOARD ], s->irq[1 ][OMAP_INT_MPUIO ], s->wakeup, omap_findclk(s, "clk32-kHz")); - s->gpio =omap_gpio_init (0xfffce000 , s->irq[0 ][OMAP_INT_GPIO_BANK1 ], -omap_findclk (s,"arm_gpio_ck" )); + s->gpio =qdev_create (NULL ,"omap-gpio" ); +qdev_prop_set_int32 (s->gpio,"mpu_model" , s->mpu_model); +qdev_init_nofail (s->gpio); +sysbus_connect_irq (sysbus_from_qdev (s->gpio),0 , + s->irq[0 ][OMAP_INT_GPIO_BANK1 ]); +sysbus_mmio_map (sysbus_from_qdev (s->gpio),0 ,0xfffce000 ); s->microwire =omap_uwire_init (0xfffb3000 , &s->irq[1 ][OMAP_INT_uWireTX], s->drq[OMAP_DMA_UWIRE_TX ],omap_findclk (s,"mpuper_ck" ));
hw/omap2.c +25 -9
@@ -27,6 +27,7 @@#include "qemu-char.h" #include "flash.h" #include "soc_dma.h" +#include "sysbus.h" #include "audio/audio.h" /* Enhanced Audio Controller (CODEC only) */
@@ -2203,7 +2204,6 @@ static void omap2_mpu_reset(void *opaque)omap_uart_reset (mpu->uart[1 ]);omap_uart_reset (mpu->uart[2 ]);omap_mmc_reset (mpu->mmc); -omap_gpif_reset (mpu->gpif);omap_mcspi_reset (mpu->mcspi[0 ]);omap_mcspi_reset (mpu->mcspi[1 ]);omap_i2c_reset (mpu->i2c[0 ]);
@@ -2232,9 +2232,10 @@ struct omap_mpu_state_s *omap2420_mpu_init(unsigned long sdram_size,ram_addr_t sram_base, q2_base;qemu_irq *cpu_irq;qemu_irq dma_irqs[4 ]; -omap_clk gpio_clks[4 ];DriveInfo *dinfo;int i; +SysBusDevice *busdev; +struct omap_target_agent_s *ta;/* Core */ s->mpu_model = omap2420;
@@ -2377,13 +2378,28 @@ struct omap_mpu_state_s *omap2420_mpu_init(unsigned long sdram_size,omap_findclk (s,"i2c2.fclk" ), omap_findclk(s, "i2c2.iclk")); - gpio_clks[0 ] =omap_findclk (s,"gpio1_dbclk" ); - gpio_clks[1 ] =omap_findclk (s,"gpio2_dbclk" ); - gpio_clks[2 ] =omap_findclk (s,"gpio3_dbclk" ); - gpio_clks[3 ] =omap_findclk (s,"gpio4_dbclk" ); - s->gpif =omap2_gpio_init (omap_l4ta (s->l4,3 ), - &s->irq[0 ][OMAP_INT_24XX_GPIO_BANK1 ], - gpio_clks,omap_findclk (s,"gpio_iclk" ),4 ); + s->gpio =qdev_create (NULL ,"omap2-gpio" ); +qdev_prop_set_int32 (s->gpio,"mpu_model" , s->mpu_model); +qdev_prop_set_ptr (s->gpio,"iclk" ,omap_findclk (s,"gpio_iclk" )); +qdev_prop_set_ptr (s->gpio,"fclk0" ,omap_findclk (s,"gpio1_dbclk" )); +qdev_prop_set_ptr (s->gpio,"fclk1" ,omap_findclk (s,"gpio2_dbclk" )); +qdev_prop_set_ptr (s->gpio,"fclk2" ,omap_findclk (s,"gpio3_dbclk" )); +qdev_prop_set_ptr (s->gpio,"fclk3" ,omap_findclk (s,"gpio4_dbclk" )); +if (s->mpu_model == omap2430) { +qdev_prop_set_ptr (s->gpio,"fclk4" ,omap_findclk (s,"gpio5_dbclk" )); + } +qdev_init_nofail (s->gpio); + busdev =sysbus_from_qdev (s->gpio); +sysbus_connect_irq (busdev,0 , s->irq[0 ][OMAP_INT_24XX_GPIO_BANK1 ]); +sysbus_connect_irq (busdev,3 , s->irq[0 ][OMAP_INT_24XX_GPIO_BANK2 ]); +sysbus_connect_irq (busdev,6 , s->irq[0 ][OMAP_INT_24XX_GPIO_BANK3 ]); +sysbus_connect_irq (busdev,9 , s->irq[0 ][OMAP_INT_24XX_GPIO_BANK4 ]); + ta =omap_l4ta (s->l4,3 ); +sysbus_mmio_map (busdev,0 ,omap_l4_region_base (ta,1 )); +sysbus_mmio_map (busdev,1 ,omap_l4_region_base (ta,0 )); +sysbus_mmio_map (busdev,2 ,omap_l4_region_base (ta,2 )); +sysbus_mmio_map (busdev,3 ,omap_l4_region_base (ta,4 )); +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 ]);
hw/omap_gpio.c +151 -108
355 lines not on this page · raw message
hw/palm.c +13 -13
@@ -94,7 +94,7 @@ static void palmte_microwire_setup(struct omap_mpu_state_s *cpu) {uWireSlave *tsc; - tsc =tsc2102_init (omap_gpio_in_get (cpu->gpio)[PALMTE_PINTDAV_GPIO ]); + tsc =tsc2102_init (qdev_get_gpio_in (cpu->gpio,PALMTE_PINTDAV_GPIO ));omap_uwire_attach (cpu->microwire, tsc,0 );omap_mcbsp_i2s_attach (cpu->mcbsp1,tsc210x_codec (tsc));
@@ -163,24 +163,24 @@ static void palmte_gpio_setup(struct omap_mpu_state_s *cpu)qemu_irq *misc_gpio;omap_mmc_handlers (cpu->mmc, -omap_gpio_in_get (cpu->gpio)[PALMTE_MMC_WP_GPIO ], -qemu_irq_invert (omap_mpuio_in_get (cpu->mpuio) - [PALMTE_MMC_SWITCH_GPIO ])); +qdev_get_gpio_in (cpu->gpio,PALMTE_MMC_WP_GPIO ), +qemu_irq_invert (omap_mpuio_in_get (cpu->mpuio) + [PALMTE_MMC_SWITCH_GPIO ])); misc_gpio =qemu_allocate_irqs (palmte_onoff_gpios, cpu,7 ); -omap_gpio_out_set (cpu->gpio,PALMTE_MMC_POWER_GPIO , misc_gpio[0 ]); -omap_gpio_out_set (cpu->gpio,PALMTE_SPEAKER_GPIO , misc_gpio[1 ]); -omap_gpio_out_set (cpu->gpio,11 , misc_gpio[2 ]); -omap_gpio_out_set (cpu->gpio,12 , misc_gpio[3 ]); -omap_gpio_out_set (cpu->gpio,13 , misc_gpio[4 ]); +qdev_connect_gpio_out (cpu->gpio,PALMTE_MMC_POWER_GPIO , misc_gpio[0 ]); +qdev_connect_gpio_out (cpu->gpio,PALMTE_SPEAKER_GPIO , misc_gpio[1 ]); +qdev_connect_gpio_out (cpu->gpio,11 , misc_gpio[2 ]); +qdev_connect_gpio_out (cpu->gpio,12 , misc_gpio[3 ]); +qdev_connect_gpio_out (cpu->gpio,13 , misc_gpio[4 ]);omap_mpuio_out_set (cpu->mpuio,1 , misc_gpio[5 ]);omap_mpuio_out_set (cpu->mpuio,3 , misc_gpio[6 ]);/* Reset some inputs to initial state. */ -qemu_irq_lower (omap_gpio_in_get (cpu->gpio)[PALMTE_USBDETECT_GPIO ]); -qemu_irq_lower (omap_gpio_in_get (cpu->gpio)[PALMTE_USB_OR_DC_GPIO ]); -qemu_irq_lower (omap_gpio_in_get (cpu->gpio)[4 ]); -qemu_irq_lower (omap_gpio_in_get (cpu->gpio)[PALMTE_HEADPHONES_GPIO ]); +qemu_irq_lower (qdev_get_gpio_in (cpu->gpio,PALMTE_USBDETECT_GPIO )); +qemu_irq_lower (qdev_get_gpio_in (cpu->gpio,PALMTE_USB_OR_DC_GPIO )); +qemu_irq_lower (qdev_get_gpio_in (cpu->gpio,4 )); +qemu_irq_lower (qdev_get_gpio_in (cpu->gpio,PALMTE_HEADPHONES_GPIO ));qemu_irq_lower (omap_mpuio_in_get (cpu->mpuio)[PALMTE_DC_GPIO ]);qemu_irq_raise (omap_mpuio_in_get (cpu->mpuio)[6 ]);qemu_irq_raise (omap_mpuio_in_get (cpu->mpuio)[7 ]);
Signature · 1 line
1.7.1
PATCH 5/15 lm832x: Take DeviceState pointer in lm832x_key_event()
In reply to Peter MaydellSince lm832x has been qdev'ified, its users will generally have a DeviceState pointer rather than an i2c_slave pointer, so adjust lm832x_key_event's prototype to suit.
This allows the n810 (its only user) to actually pass a correct pointer to it rather than NULL. The effect is that we no longer segfault when a key is pressed.
--- hw/i2c.h | 2 +- hw/lm832x.c | 4 ++-- hw/nseries.c | 7 +++---- 3 files changed, 6 insertions(+), 7 deletions(-)
hw/i2c.h +1 -1
@@ -72,6 +72,6 @@ void wm8750_set_bclk_in(void *opaque, int new_hz);void tmp105_set (i2c_slave *i2c,int temp);/* lm832x.c */ -void lm832x_key_event (i2c_slave *i2c,int key,int state); +void lm832x_key_event (DeviceState *dev,int key,int state);#endif
hw/lm832x.c +2 -2
@@ -474,9 +474,9 @@ static int lm8323_init(i2c_slave *i2c)return 0 ; } -void lm832x_key_event (struct i2c_slave *i2c,int key,int state) +void lm832x_key_event (DeviceState *dev,int key,int state) { -LM823KbdState *s = (LM823KbdState *) i2c; +LM823KbdState *s =FROM_I2C_SLAVE (LM823KbdState,I2C_SLAVE_FROM_QDEV (dev));if ((s->status &INT_ERROR ) && (s->error &ERR_FIFOOVR ))return ;
hw/nseries.c +3 -4
@@ -45,7 +45,7 @@ struct n800_s {i2c_bus *i2c;int keymap[0x80 ]; -i2c_slave *kbd; +DeviceState *kbd;TUSBState *usb;void *retu;
@@ -362,7 +362,6 @@ static int n810_keys[0x80] = {static void n810_kbd_setup (struct n800_s *s) {qemu_irq kbd_irq =qdev_get_gpio_in (s->cpu->gpio,N810_KEYBOARD_GPIO ); -DeviceState *dev;int i;for (i =0 ; i <0x80 ; i ++)
@@ -375,8 +374,8 @@ static void n810_kbd_setup(struct n800_s *s)/* Attach the LM8322 keyboard to the I2C bus, * should happen in n8x0_i2c_setup and s->kbd be initialised here. */ - dev =i2c_create_slave (s->i2c,"lm8323" ,N810_LM8323_ADDR ); -qdev_connect_gpio_out (dev,0 , kbd_irq); + s->kbd =i2c_create_slave (s->i2c,"lm8323" ,N810_LM8323_ADDR ); +qdev_connect_gpio_out (s->kbd,0 , kbd_irq); }/* LCD MIPI DBI-C controller (URAL) */
Signature · 1 line
1.7.1
PATCH 6/15 hw/nand: Pass block device state to init function
In reply to Peter MaydellPass 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 7/15 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 8/15 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 9/15 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 10/15 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 11/15 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 12/15 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 13/15 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 14/15 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 15/15 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
Re: [Qemu-devel] [PATCH 15/15] hw/onenand: program actions can only clear bits
Quoted 18 lines · Peter Maydell
From: Juha Riihimäki <[email protected]>
The program actions
onenand_prog_main()andonenand_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.Signed-off-by Juha Riihimäki <[email protected]>[Riku Voipio: Fixes and restructuring patchset]Signed-off-by Riku Voipio <[email protected]>[Peter Maydell: More fixes and cleanups for upstream submission]Signed-off-by Peter Maydell <[email protected]>---
hw/onenand.c | 135 +++++++++++++++++++++++++++++++++++++++++++++------------1 files changed, 106 insertions(+), 29 deletions(-)hw/onenand.c +0
-0
...
Quoted 27 lines
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;
Quoted 8 lines
+ }
+ 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;
+ }
By the way it seems that this can be optimised to require just one read for the entire erase.
Cheers