hw/arm: add Faraday A369 SoC platform support
v9 cover hw/arm: add Faraday A369 SoC platform support
From: Kuo-Jung Su <[email protected]>
These patches introduce Faraday A369 SoC platform support.
Here are some public documents for your reference.
http://www.faraday-tech.com/html/documentation/index.html
The partial version of faraday cpu datasheet with only the CP15 and MPU description are available at my Google Drive:
https://docs.google.com/folder/d/0BwfiewvSmUgAalh5TkxyZWtlWEE/edit?usp=sharing
The pre-built A369 images are also available at my Google Drive:
https://docs.google.com/folder/d/0BwfiewvSmUgAX2pTTmtUMGFCZW8/edit
Here is the image file list:
1. android-4.0.4/zImage: A369 linux-3.0.31
2. android-4.0.4/romfs-4.0.4.tar.bz2: android-4.0.4
3. nand.img.bz2: A369 nand flash image
4. rom.img.bz2: A369 embedded ROM image
5. u-boot: A369 u-boot-2012.10 ELF file
6. zImage: A369 linux-3.4.12 + initramfs
7. README
If you want to re-build the image from scratch, try my Faraday Linux BSP/SDK: falinux.
1. Download the falinux
$ git clone https://github.com/dantesu1218/falinux.git
2. Download all the required software packages:
$ cd falinux $ make setup
3. Launch the menuconfig of falinux, and enable 'QEMU Support'
$ make menuconfig
4. Re-build the packages
$ make
5. Laungh the qemu-1.3.0 with the generated falinux images.
$ make qemu
Changes for v8 -> v9:
1. hw/arm: Update the file directory structure (Addressed by Peter.M) hw/arm: top level board models and things directly reference the CPU only
hw: otherwise
2. hw/arm: Rename SoC platform specific files:
hw/arm/faraday_a369.c -> hw/arm/ftplat_a369.c
hw/arm/faraday_a369_soc.c -> hw/arm/ftplat_a369soc.c hw/arm/faraday_a369_scu.c -> hw/arm/ftplat_a369scu.c hw/arm/faraday_a369_kpd.c -> hw/arm/ftplat_a369kpd.c
3. hw: audio_codec.[ch] -> audio.[ch]
4. hw/fti2c010: Drop .addr from Fti2c010State. (Addressed by Peter.C)
5. hw/fti2c010: Add qemu_log_mask(LOG_UNIMP, ) to slave mode. (Addressed by Peter.C)
6. hw/fti2c010: Update data type of Fti2c010State.recv from 'uint8_t' into 'bool'.
7. hw/*.c: QOM Coding Conventions (Addressed by Peter.C)
8. hw/*.h: Inlcudes bitops only if they need it. (Addressed by Peter.C)
9. hw/ftplat_a369soc: Add a container memory region for remappable devices. (i.e. ROM, RAM) (Addressed by Peter.C and Peter.M)
10. hw/faraday.h: Drop cpu, cpu_model, ahb_remapped, ddr_inited, rom_size, ram_size scu, ahbc, ddrc from FaradaySoCState.
11. hw/faraday.h: Replace FaradaySoCState.bi with FaradaySoCState.ram_boot
12. hw/arm/ftplat_a369soc: Move customized system reset to ftplat_a369.c
13. hw/faraday.h: Add faraday_soc_ahb_remap() and faraday_soc_ram_setup() for ftddrii030, ftahbc020, ftplat_a369soc and ftplat_a369.
14. hw/ftahbc020, ftapbbrg020, ftddrii030, ftnandc021, ftssp010.c:
Move object_property_add_link() to object::instance_init()
Changes for v7 -> v8:
1. [hw/arm/ftintc020.c] (Addressed by Peter)
'uint32_t mask = BIT(irq % 32);' -> 'uint32_t mask = BIT(irq & 0x1f);'
2. [hw/arm/*.c] (Addressed by Peter)
Drop '#include "faraday.h"', and define DPRINTF() at per-file basis exit(1) -> abort()
SysBusDeviceClass::init() -> Device::realize()
Changes for v6 -> v7:
1. hw/arm/ftwdt010: (Addressed by Paolo)
Replace 'qemu_system_reset_request()' with 'watchdog_perform_action()'.
2. hw/arm/ftrtc011: (Addressed by Paolo)
Replace 'get_clock_realtime()' with 'qemu_get_clock_ns(rtc_clock)'. Replace 'qemu_new_timer_ms(rt_clock...)' with 'qemu_new_timer_ms(rtc_clock...)' Rename 'ftrtc011_timer_resync' -> 'ftrtc011_timer_rebase'
Add ftrtc011_timer_resche()
Add QTest support
3. hw/arm/faraday_a369_soc: (Addressed by Paolo)
Remove redundant device reset from a369soc_system_reset(...)
4. include/qemu/bitops.h: (Addressed by Paolo)
Update bitrev8() to use a kind of divide and conquer algorithm.
5. hw/arm/ftahb020,ftddrii030,ftapbbrg020,faraday_a369_soc:
Drop FARADAY_SOC_GET_CORE(), replaced with device to device QOM link.
6. hw/wm8731,wm8750,marvell_88w8618_audio,spitz,z2:
Add AudioCodecClass for wm87xx audio class abstration.
7. hw/arm/ftnandc021:
Drop nand_init(), replaced with device to device QOM link.
8. hw/arm/ftsdc010:
Bug fixed to write operation: remove sd_data_ready() in write path.
9. hw/arm/ftgmac100,ftmac110,ftwdt010:
rt-clock -> vm_clock
10. hw/nand.c:
Drop [hw/nand.c: correct the sense of the BUSY/READY], since it's already applied. Drop [hw/nand.c: bug fix to erase operation], since Peter has a better solution.
Changes for v5 -> v6:
1. hw/arm/Makefile.objs:
Shift to the next line only after current line length is > 80 characters.
2. hw/arm/faraday.h:
Update debug macro format per discussions at the link bellow:
http://thread.gmane.org/gmane.comp.emulators.qemu/195996/focus=196975
3. hw/arm/faraday.h:
TYPE_FARADAY_SOC: 'faraday/soc' -> 'faraday.soc'
4. hw/arm/*.c:
Replace '%llx' with '%HWADDR_PRIx'
5. hw/arm/*.h:
Add '#include "qemu/bitops.h"'
6. hw/arm/faraday_a369_soc.c:
Typo fix: salve4 -> slave4, salve6 -> slave6
7. hw/arm/*.c:
Drop FROM_SYSBUS().
8. hw/arm/ftintc020.c:
Re-write the source file with pl190.c as template.
9. hw/arm/ftintc020.h:
Rename the registers to improve readibility.
10. hw/arm/faraday.h:
Add dedicated spi flash pointer array (DeviceState *spi_fl[2]).
11. hw/arm/faraday.h:
Add 'qemu_irq pic[64]'.
12. hw/arm/*c:
Replace the complex conversion in XXX_REG32() with directly array indexing.
13. hw/arm/*c:
Update the error message output from 'hw_error(...)' into 'fprintf(stderr, ...)'
14. hw/arm/faraday_a369.c, hw/arm/faraday_a369_soc.c:
Move the external AHB device init from faraday_a369_soc.c to faraday_a369.c
15. include/qemu/bitops.h:
Move bitrev() from bitrev.[ch] into bitops.h
16. hw/nand.c:
Remove the clear/set SR[6] code in read/erase/write, because
it's not possible to be observed by a guest.
17. hw/arm/faraday_a369_kpd.c:
Function prefix: 'ftkbc010' -> 'a369kpd'
Name of struct: 'FTKBC010State' -> 'A369KPDState'.
QOM: 'FTKBC010' -> 'A369KPD'
18. hw/arm/ftddrii030.c:
'case REG_MCR ... 0x4c' -> 'case REG_MCR ... (CFG_REGSIZE - 1) * 4' 19. hw/arm/ftahbc020.c:
Add comments to fall-through path. (i.e. /* fall-through - skip slave6 */)
20. hw/arm/faraday_a369.c:
Update spi flash init code to use the new QOM classes of m25p80.
Changes for v3 -> v5:
1. [cpu] Add the unapplied patches for faraday ARMv5TE cores.
2. [nand] Add the unapplied patches for hw/nand.c.
3. [audio] Add the unapplied patches for wm8731.
4. [Global] Replace redundant statement in xxx_update_irq() with
qemu_set_irq(s->irq, !!(xxxx));
5. [Global] Introduce 'case xxx ... xxx' statement in switch { }
to replace the 'if {} else {}' statement.
6. [Global] Replace complex bitwise operation with functions defined in bitops.h
7. [Global] Introduce array register caches (i.e. s->regs[]) implementation
to fttsc010, ftrtc011, ftmac110, ftgmac100, ftddrii030
faraday_a369_kpd and faraday_a369_soc.
8. [Global] Add qemu_log_mask(LOG_GUEST_ERROR...) on undefined memory accesses.
9. [Global] Add missing register access size constraint to
faraday_a369_kpd, faraday_a369_soc, ftahbc020.c, ftddrii030.c,
ftintc020.c, ftlcdc200.c, ftpwmtmr010.c, ftspi020.c, fttmr010.c
and fttsc010.c. 10. [Global] Add more register and bitmask descriptions to all the chips.
11. [Global] Rename all the MemoryRegionOps variables to 'mmio_ops'
12. [Global] Update all non-system header includes from '<>' into '""'
13. [bitrev] Port bitrev.[ch] from linux kernel into QEMU.
14. [ftapbbrg020] Replace cpu_physical_memory_read()/cpu_physical_memory_write() with dma_memory_read()/dma_memory_write()
15. [ftdmac020] Replace cpu_physical_memory_read()/cpu_physical_memory_write() with dma_memory_read()/dma_memory_write()
16. [ftgmac100/ftmac110] Replace cpu_physical_memory_read()/cpu_physical_memory_write() with dma_memory_read()/dma_memory_write()
17. [ftgmac100/ftmac110] Add a 10ms timer for polling the owner bit of descriptors to call qemu_flush_queued_packets() when it's necessary.
18. [ftgmac100/ftmac110] Replace hw_error() with qemu_log_mask(LOG_GUEST_ERROR, ) for programmer errors.
19. [ftgmac100/ftmac110] Update descriptor struct for big endian QEMU host support.
20. [ftgmac100/ftmac110] Typo fix ('FTMAC_H' --> 'HW_ARM_FTMAC110_H') to the header files.
21. [ftmac110] Update mdio phy response emulation from Marvell into Davicom PHY.
22. [ftwdt010/fttsc010] Switch to a slower timer. (i.e. rt_clock)
23. [faraday_a360] Removed. The ftmac110 and fttmr010 has been moved to
A369 as external AHB devices.
24. [faraday_a369] Add register caches for AHB/APB slave devices.
25. [faraday_a369] Remember (arm_boot_info *) when launching in direct boot mode.
26. [faraday_a369] Replace pointer to (mach *) with QOM APIs. (i.e. no more DEFINE_PROP_PTR())
27. [faraday_a369] Add a error message for ROM mode when it failed to load image.
28. [faraday_a369] Add the missing AHB remap process into direct boot mode.
29. [faraday_a369] Bug fix to ROM and RAM memory overlap issue.
30. [faraday_a369] Remove system reset order dependency from ftddrii030 and ftahbc020
31. [faraday_a369] Separate the a369 platform implementation into 2 different parts:
board=faraday_a369.c, and soc=faraday_a369_soc.c
32. [faraday_a369] Copy all the un-used register values from read hardware into QEMU model.
33. [ftssp010] Add address alignment checker.
34. [ftssp010] Move the audio codec initialization code to faraday_a369.c.
35. [ftspi020] Use a constant (CFG_NR_CSLINES) for the number of cs lines.
36. [ftspi020] Replace 's->datacnt <= 0' with '!s->datacnt', because s->datacnt is unsigned.
37. [ftspi020] Replace 's->datacnt' with 's->cmd[2]'
38. [ftspi020] Remove redundant M25P80s command opcodes from the header file.
39. [ftspi020] Replace 'g_new' with 'g_new0' for cs_lines allocation.
This fix the bug which crash the QEMU when de-activating an unattached spi flash chip select. Thanks to Peter.
Changes for v3:
1. [global] review all commit log make sure it correctly describe the QEMU model.
2. [global] reformat the entire patch series to be compilable on its own. Thanks to Andreas and Igor.
3. [global] move all files from 'hw' into 'hw/arm', and rename a36x.c to faraday_a36x.c
4. [global] update lisence to GPLv2+
5. [global] rename both struct and typedef names to CamelCase.
6. [global] turn printfs into DPRINTF() which is controlled by 'DEBUG_FARADAY'
7. [global] remove disabled code.
8. [global] add header files with descriptive defines to
ftintc020, ftrtc011, fttmr010 ... etc.
9. [global] update all header file to have a 'HW_ARM_' prefix
to header guards.
10. [faraday.h] add parameter names to ftmac110_init() and
ftgmac100_init() 11. [a360/a369] remove printf("xxx %dMB ram.\n"...);
12. [a360/a369] add 'arm926' as a fail-safe cpu model.
13. [a360/a369] add DEFAULT_MACHINE_OPTIONS.
14. [a360/a369] remove USB-EHCI support, it's now a standalone patch.
15. [a360] replace ftlcdc200 init from sysbus_create_varargs() to sysbus_create_simple().
16. [a360] make PMU a standalone file. (faraday_a360_pmu.c)
17. [a369] make SCU a standalone file. (faraday_a369_pcu.c)
18. [a369] make AHBC a standalone file. (ftahbc020.c)
19. [a369] make DDRC a standalone file. (ftddrii030.c)
20. [a369] rename ftkbc010 to faraday_a369_keypad.c
21. [a369] replace ROM emulation with PFLASH.(rom.c is deleted)
22. [ftsdc010] add sd_data_ready() to data R/W.
23. [ftsdc010] check 'datacnt' at each read/write to make sure buffer would not overflow/underflow and also prevent 'datacnt' from underflow by subtracted by a 4.
24. [ftgmac100] add 802.1Q VLAN tag insertion/removal support.
25. [ftgmac100] replace the dumb timer code with bottom half.
26. [ftgmac100] rename the struct name of descriptors to CamelCase.
27. [ftgmac100] replace 'void *' with 'Ftgmac100RXD *' and 'Ftgmac100TXD *' for descriptor read/write.
28. [ftgmac100] add buffer overflow check in ftgmac100_transmit()
29. [ftgmac100] add buffer alignment check
30. [ftmac110] replace the dumb timer code with bottom half.
31. [ftmac110] rename the struct name of descriptors to CamelCase.
32. [ftmac110] replace 'void *' with 'Ftmac110RXD *' and 'Ftmac110TXD *' for descriptor read/write.
33. [ftmac110] add buffer overflow check in ftmac110_transmit()
34. [ftmac110] add buffer alignment check
35. [ftdmac020] replace the dumb timer code with bottom half.
36. [ftdmac020] replace cpu_physical_memory_map() with cpu_physical_memory_read/write() for both simplicity and security enhancement which caused by the un-checked return mapped length from cpu_physical_memory_map().
37. [ftapbbrg020] replace the dumb timer code with bottom half.
38. [ftapbbrg020] replace cpu_physical_memory_map() with cpu_physical_memory_read/write() for both simplicity and security enhancement which caused by the un-checked return mapped length from cpu_physical_memory_map().
39. [ftrtc011] switch to a slower timer with msec resolution. (i.e. rt_clock)
40. [ftrtc011] re-calculate RTC counters from host timestamp upon register read/write and also vm save/restore.
Changes for v2:
1. coding style fixes (verified with checkpatch.pl)
2. add Faraday A360 support
3. add Faraday USB 2.0 EHCI support
4. merge a369_scu.c into a369.c
5. introduce QOM coding style
6. remove lowercase Macros: min(), max()
7. name all struct as CamelCase style
8. move function prototypes from .c to faraday.h
9. use switch instead of if statement in a369_ahbc_write
10. remove debug prints
11. update all uarts in A36x to DEVICE_LITTLE_ENDIAN.
12. move the variable definitions to the start of the function, instead of inside a do { } while(0)
13. remove disabled and commented out code.
14. use hw_error() and exit() upon pflash register failed.
15. add const prior to TypeInfo (i.e. static *const* TypeInfo ftrtc011_info)
16. add le32_to_cpu/cpu_to_le32 to the descriptor processing in
FTGMAC100/FTMAC110.
17. update the GPL license to GPL v2 (except for FTLCDC200, it's based on pl110.c which is LGPL.)
18. add const to src_* in the DMA controllers (FTAPBBRG020/FTDMAC020)
Kuo-Jung Su (24):
target-arm: add Faraday ARMv5TE processors support hw/arm: add Faraday a369 SoC platform support
hw/arm: add FTINTC020 interrupt controller support hw/arm: add FTAHBC020 AHB controller support
hw/arm: add FTDDRII030 DDRII controller support
hw/arm: add FTPWMTMR010 timer support
hw/arm: add FTWDT010 watchdog timer support
hw/arm: add FTRTC011 RTC timer support
tests: add QTest for FTRTC011
hw/arm: add FTDMAC020 AHB DMA support
hw/arm: add FTAPBBRG020 APB DMA support
hw/arm: add FTNANDC021 nand flash controller support hw/arm: add FTI2C010 I2C controller support
hw: Add AudioCodecClass for wm87xx audio class abstration.
hw: add WM8731 audio codec support
The FTSSP010 is a multi-function synchronous serial port interface
controller which supports SSP, SPI, I2S, AC97 and SPDIF.
qemu/bitops.h: add the bit ordering reversal functions hw/arm: add FTGMAC100 1Gbps ethernet support
hw/arm: add FTLCDC200 LCD controller support
hw/arm: add FTTSC010 touchscreen controller support hw/arm: add FTSDC010 MMC/SD controller support
hw/arm: add FTMAC110 10/100Mbps ethernet support hw/arm: add FTTMR010 timer support
hw/arm: add FTSPI020 SPI flash controller support
default-configs/arm-softmmu.mak | 1 + hw/Makefile.objs | 2 + hw/arm/Makefile.objs | 6 + hw/arm/ftplat_a369.c | 180 ++++++++++ hw/arm/ftplat_a369kpd.c | 235 +++++++++++++ hw/arm/ftplat_a369scu.c | 186 ++++++++++ hw/arm/ftplat_a369soc.c | 294 ++++++++++++++++ hw/arm/spitz.c | 9 +- hw/arm/z2.c | 9 +- hw/audio.c | 81 +++++ hw/audio.h | 56 +++ hw/faraday.h | 133 ++++++++ hw/ftahbc020.c | 216 ++++++++++++ hw/ftapbbrg020.c | 478 ++++++++++++++++++++++++++ hw/ftapbbrg020.h | 44 +++ hw/ftddrii030.c | 192 +++++++++++ hw/ftdmac020.c | 599 ++++++++++++++++++++++++++++++++ hw/ftdmac020.h | 107 ++++++ hw/ftgmac100.c | 712 +++++++++++++++++++++++++++++++++++++++ hw/ftgmac100.h | 237 +++++++++++++ hw/fti2c010.c | 224 ++++++++++++ hw/fti2c010.h | 74 ++++ hw/ftintc020.c | 307 +++++++++++++++++ hw/ftintc020.h | 55 +++ hw/ftkbc010.h | 44 +++ hw/ftlcdc200.c | 516 ++++++++++++++++++++++++++++ hw/ftlcdc200.h | 110 ++++++ hw/ftlcdc200_template.h | 439 ++++++++++++++++++++++++ hw/ftmac110.c | 665 ++++++++++++++++++++++++++++++++++++ hw/ftmac110.h | 166 +++++++++ hw/ftnandc021.c | 526 +++++++++++++++++++++++++++++ hw/ftnandc021.h | 84 +++++ hw/ftpwmtmr010.c | 261 ++++++++++++++ hw/ftpwmtmr010.h | 31 ++ hw/ftrtc011.c | 387 +++++++++++++++++++++ hw/ftrtc011.h | 53 +++ hw/ftsdc010.c | 359 ++++++++++++++++++++ hw/ftsdc010.h | 88 +++++ hw/ftspi020.c | 341 +++++++++++++++++++ hw/ftspi020.h | 81 +++++ hw/ftssp010.c | 504 +++++++++++++++++++++++++++ hw/ftssp010.h | 96 ++++++ hw/fttmr010.c | 449 ++++++++++++++++++++++++ hw/fttmr010.h | 39 +++ hw/fttsc010.c | 264 +++++++++++++++ hw/fttsc010.h | 39 +++ hw/ftwdt010.c | 213 ++++++++++++ hw/ftwdt010.h | 35 ++ hw/i2c.h | 9 - hw/marvell_88w8618_audio.c | 23 +- hw/wm8731.c | 505 +++++++++++++++++++++++++++ hw/wm8750.c | 91 ++--- include/qemu/bitops.h | 59 +++- target-arm/cpu.c | 52 +++ target-arm/cpu.h | 6 +- target-arm/helper.c | 84 +++++ target-arm/machine.c | 4 + tests/Makefile | 3 + tests/ftrtc011-test.c | 410 ++++++++++++++++++++++ 59 files changed, 11403 insertions(+), 70 deletions(-) create mode 100644 hw/arm/ftplat_a369.c create mode 100644 hw/arm/ftplat_a369kpd.c create mode 100644 hw/arm/ftplat_a369scu.c create mode 100644 hw/arm/ftplat_a369soc.c create mode 100644 hw/audio.c create mode 100644 hw/audio.h create mode 100644 hw/faraday.h create mode 100644 hw/ftahbc020.c create mode 100644 hw/ftapbbrg020.c create mode 100644 hw/ftapbbrg020.h create mode 100644 hw/ftddrii030.c create mode 100644 hw/ftdmac020.c create mode 100644 hw/ftdmac020.h create mode 100644 hw/ftgmac100.c create mode 100644 hw/ftgmac100.h create mode 100644 hw/fti2c010.c create mode 100644 hw/fti2c010.h create mode 100644 hw/ftintc020.c create mode 100644 hw/ftintc020.h create mode 100644 hw/ftkbc010.h create mode 100644 hw/ftlcdc200.c create mode 100644 hw/ftlcdc200.h create mode 100644 hw/ftlcdc200_template.h create mode 100644 hw/ftmac110.c create mode 100644 hw/ftmac110.h create mode 100644 hw/ftnandc021.c create mode 100644 hw/ftnandc021.h create mode 100644 hw/ftpwmtmr010.c create mode 100644 hw/ftpwmtmr010.h create mode 100644 hw/ftrtc011.c create mode 100644 hw/ftrtc011.h create mode 100644 hw/ftsdc010.c create mode 100644 hw/ftsdc010.h create mode 100644 hw/ftspi020.c create mode 100644 hw/ftspi020.h create mode 100644 hw/ftssp010.c create mode 100644 hw/ftssp010.h create mode 100644 hw/fttmr010.c create mode 100644 hw/fttmr010.h create mode 100644 hw/fttsc010.c create mode 100644 hw/fttsc010.h create mode 100644 hw/ftwdt010.c create mode 100644 hw/ftwdt010.h create mode 100644 hw/wm8731.c create mode 100644 tests/ftrtc011-test.c
Signature · 1 line
1.7.9.5
PATCH v9 1/24 target-arm: add Faraday ARMv5TE processors support
From: Kuo-Jung Su <[email protected]>
This patch includes the single core support to FA606TE, FA626TE, FA616TE and FA726TE with CP15 Faraday extensions (AUX and I/D-Scratchpad).
--- target-arm/cpu.c | 52 +++++++++++++++++++++++++++++++ target-arm/cpu.h | 6 +++- target-arm/helper.c | 84 ++++++++++++++++++++++++++++++++++++++++++++++++++ target-arm/machine.c | 4 +++ 4 files changed, 145 insertions(+), 1 deletion(-)
target-arm/cpu.c +52 -0
@@ -244,6 +244,54 @@ static void arm926_initfn(Object *obj) cpu->reset_sctlr =0x00090078 ; } +static void fa606te_initfn (Object *obj) +{ +ARMCPU *cpu =ARM_CPU (obj); +set_feature (&cpu->env,ARM_FEATURE_V5 ); +set_feature (&cpu->env,ARM_FEATURE_DUMMY_C15_REGS ); +set_feature (&cpu->env,ARM_FEATURE_MPU_FARADAY ); + cpu->midr =0x66056061 ;/* CR0-0 Identification Code Register (ID) */ + cpu->ctr =0x00000000 ;/* CR0-1 Cache Type Register (CTR) */ + cpu->reset_sctlr =0x00000078 ;/* CR1-0 Configuration Register (CFG) */ +} + +static void fa616te_initfn (Object *obj) +{ +ARMCPU *cpu =ARM_CPU (obj); +set_feature (&cpu->env,ARM_FEATURE_V5 ); +set_feature (&cpu->env,ARM_FEATURE_DUMMY_C15_REGS ); +set_feature (&cpu->env,ARM_FEATURE_CACHE_TEST_CLEAN ); +set_feature (&cpu->env,ARM_FEATURE_TCM_FARADAY ); + cpu->midr =0x66056161 ;/* CR0-0 Identification Code Register (ID) */ + cpu->ctr =0x1d152152 ;/* CR0-1 Cache Type Register (CTR) */ + cpu->reset_sctlr =0x00050078 ;/* CR1-0 Configuration Register (CFG) */ +} + +static void fa626te_initfn (Object *obj) +{ +ARMCPU *cpu =ARM_CPU (obj); +set_feature (&cpu->env,ARM_FEATURE_V5 ); +set_feature (&cpu->env,ARM_FEATURE_DUMMY_C15_REGS ); +set_feature (&cpu->env,ARM_FEATURE_CACHE_TEST_CLEAN ); +set_feature (&cpu->env,ARM_FEATURE_TCM_FARADAY ); +set_feature (&cpu->env,ARM_FEATURE_AUXCR ); + cpu->midr =0x66056261 ;/* CR0-0 Identification Code Register (ID) */ + cpu->ctr =0x0f192192 ;/* CR0-1 Cache Type Register (CTR) */ + cpu->reset_sctlr =0x00000078 ;/* CR1-0 Configuration Register (CFG) */ +} + +static void fa726te_initfn (Object *obj) +{ +ARMCPU *cpu =ARM_CPU (obj); +set_feature (&cpu->env,ARM_FEATURE_V5 ); +set_feature (&cpu->env,ARM_FEATURE_DUMMY_C15_REGS ); +set_feature (&cpu->env,ARM_FEATURE_CACHE_TEST_CLEAN ); +set_feature (&cpu->env,ARM_FEATURE_TCM_FARADAY ); + cpu->midr =0x66057261 ;/* CR0-0 Identification Code Register (ID) */ + cpu->ctr =0x1d192192 ;/* CR0-1 Cache Type Register (CTR) */ + cpu->reset_sctlr =0x00050078 ;/* CR1-0 Configuration Register (CFG) */ +} +static void arm946_initfn (Object *obj) {ARMCPU *cpu =ARM_CPU (obj);
@@ -766,6 +814,10 @@ typedef struct ARMCPUInfo {static const ARMCPUInfo arm_cpus[] = { { .name ="arm926" , .initfn = arm926_initfn }, + { .name ="fa606te" , .initfn = fa606te_initfn }, + { .name ="fa616te" , .initfn = fa616te_initfn }, + { .name ="fa626te" , .initfn = fa626te_initfn }, + { .name ="fa726te" , .initfn = fa726te_initfn }, { .name ="arm946" , .initfn = arm946_initfn }, { .name ="arm1026" , .initfn = arm1026_initfn },/* What QEMU calls "arm1136-r2" is actually the 1136 r0p2, i.e. an
target-arm/cpu.h +5 -1
@@ -152,6 +152,8 @@ typedef struct CPUARMState {uint32_t c15_diagnostic;/* diagnostic register */ uint32_t c15_power_diagnostic;uint32_t c15_power_control;/* power control */ +uint32_t c15_tcm_data;/* Data TCM region register */ +uint32_t c15_tcm_inst;/* Instruction TCM region register */ } cp15;struct {
@@ -392,6 +394,8 @@ enum arm_features {ARM_FEATURE_MPIDR ,/* has cp15 MPIDR */ ARM_FEATURE_PXN ,/* has Privileged Execute Never bit */ ARM_FEATURE_LPAE ,/* has Large Physical Address Extension */ +ARM_FEATURE_TCM_FARADAY ,/* Faraday Scratchpad(TCM) */ + ARM_FEATURE_MPU_FARADAY, /* Faraday MPU */ };static inline int arm_feature (CPUARMState *env,int feature)
@@ -640,7 +644,7 @@ static inline CPUARMState *cpu_init(const char *cpu_model)#define cpu_signal_handler cpu_arm_signal_handler#define cpu_list arm_cpu_list -#define CPU_SAVE_VERSION 9 +#define CPU_SAVE_VERSION 10/* MMU modes definitions */ #define MMU_MODE0_SUFFIX _kernel
target-arm/helper.c +84 -0
96 lines not on this page · raw message
target-arm/machine.c +4 -0
@@ -62,6 +62,8 @@ void cpu_save(QEMUFile *f, void *opaque)qemu_put_be32 (f, env->cp15.c15_power_control);qemu_put_be32 (f, env->cp15.c15_diagnostic);qemu_put_be32 (f, env->cp15.c15_power_diagnostic); +qemu_put_be32 (f, env->cp15.c15_tcm_data); +qemu_put_be32 (f, env->cp15.c15_tcm_inst);qemu_put_be64 (f, env->features);
@@ -182,6 +184,8 @@ int cpu_load(QEMUFile *f, void *opaque, int version_id) env->cp15.c15_power_control =qemu_get_be32 (f); env->cp15.c15_diagnostic =qemu_get_be32 (f); env->cp15.c15_power_diagnostic =qemu_get_be32 (f); + env->cp15.c15_tcm_data =qemu_get_be32 (f); + env->cp15.c15_tcm_inst =qemu_get_be32 (f); env->features =qemu_get_be64 (f);
Signature · 1 line
1.7.9.5
PATCH v9 2/24 hw/arm: add Faraday a369 SoC platform support
In reply to Kuo-Jung SuFrom: Kuo-Jung Su <[email protected]>
The Faraday A369 EVB is a Faraday SoC platform evalution board used for Faraday IP functional verification based on the well-known ARM AMBA 2.0 architecture.
--- hw/arm/Makefile.objs | 2 + hw/arm/ftplat_a369.c | 96 +++++++++++++++++++ hw/arm/ftplat_a369kpd.c | 235 +++++++++++++++++++++++++++++++++++++++++++++++ hw/arm/ftplat_a369scu.c | 186 +++++++++++++++++++++++++++++++++++++ hw/arm/ftplat_a369soc.c | 155 +++++++++++++++++++++++++++++++ hw/faraday.h | 124 +++++++++++++++++++++++++ hw/ftkbc010.h | 44 +++++++++ 7 files changed, 842 insertions(+) create mode 100644 hw/arm/ftplat_a369.c create mode 100644 hw/arm/ftplat_a369kpd.c create mode 100644 hw/arm/ftplat_a369scu.c create mode 100644 hw/arm/ftplat_a369soc.c create mode 100644 hw/faraday.h create mode 100644 hw/ftkbc010.h
hw/arm/Makefile.objs +2 -0
@@ -34,3 +34,5 @@ obj-y += tosa.o versatilepb.o vexpress.o xilinx_zynq.o z2.o obj-y += armv7m.o exynos4210.o pxa2xx.o pxa2xx_gpio.o pxa2xx_pic.o obj-y += omap1.o omap2.o + +obj-y += ftplat_a369.o ftplat_a369soc.o ftplat_a369scu.o ftplat_a369kpd.o
hw/arm/ftplat_a369.c new file +96 -0
96 lines not on this page · raw message
hw/arm/ftplat_a369kpd.c new file +235 -0
235 lines not on this page · raw message
hw/arm/ftplat_a369scu.c new file +186 -0
186 lines not on this page · raw message
hw/arm/ftplat_a369soc.c new file +155 -0
155 lines not on this page · raw message
hw/faraday.h new file +124 -0
124 lines not on this page · raw message
hw/ftkbc010.h new file +44 -0
44 lines not on this page · raw message
Signature · 1 line
1.7.9.5
PATCH v9 3/24 hw/arm: add FTINTC020 interrupt controller support
In reply to Kuo-Jung SuFrom: Kuo-Jung Su <[email protected]>
The FTINTC020 interrupt controller supports both FIQ and IRQ signals to the microprocessor.
It can handle up to 64 configurable IRQ sources and 64 FIQ sources. The output signals to the microprocessor can be configured as level-high/low active or edge-rising/falling triggered.
--- hw/arm/Makefile.objs | 1 + hw/arm/ftplat_a369soc.c | 11 ++ hw/ftintc020.c | 307 +++++++++++++++++++++++++++++++++++++++++++++++ hw/ftintc020.h | 55 +++++++++ 4 files changed, 374 insertions(+) create mode 100644 hw/ftintc020.c create mode 100644 hw/ftintc020.h
hw/arm/Makefile.objs +1 -0
@@ -24,6 +24,7 @@ obj-y += framebuffer.o obj-y += strongarm.o obj-y += imx_serial.o imx_ccm.o imx_timer.o imx_avic.o obj-$(CONFIG_KVM) += kvm/arm_gic.o +obj-y += ftintc020.o obj-y := $(addprefix ../,$(obj-y))
hw/arm/ftplat_a369soc.c +11 -0
@@ -51,6 +51,8 @@ static void a369soc_reset(DeviceState *ds)static void a369soc_chip_init (FaradaySoCState *s) { +int i; +DeviceState *ds;DriveInfo *dinfo;/* Remappable Memory Region Init */
@@ -84,6 +86,15 @@ static void a369soc_chip_init(FaradaySoCState *s)memory_region_add_subregion (s->rmr, s->rom_base,sysbus_mmio_get_region (SYS_BUS_DEVICE (s->rom),0 )); +/* Interrupt Controller */ + ds =sysbus_create_varargs ("ftintc020" ,0x90100000 , + s->cpu_pic[ARM_PIC_CPU_IRQ ], + s->cpu_pic[ARM_PIC_CPU_FIQ ],NULL ); + s->pic =g_new0 (qemu_irq,64 ); +for (i =0 ; i <64 ; ++i) { + s->pic[i] =qdev_get_gpio_in (ds, i); + } +/* Serial (FTUART010 which is 16550A compatible) */ if (serial_hds[0 ]) { serial_mm_init(s->as,
hw/ftintc020.c new file +307 -0
307 lines not on this page · raw message
hw/ftintc020.h new file +55 -0
55 lines not on this page · raw message
Signature · 1 line
1.7.9.5
PATCH v9 4/24 hw/arm: add FTAHBC020 AHB controller support
In reply to Kuo-Jung SuFrom: Kuo-Jung Su <[email protected]>
It's used to manage AHB slave devices
and also the AHB remap function for slave4 & slave6.
--- hw/arm/Makefile.objs | 2 +- hw/arm/ftplat_a369soc.c | 9 ++ hw/ftahbc020.c | 216 +++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 226 insertions(+), 1 deletion(-) create mode 100644 hw/ftahbc020.c
hw/arm/Makefile.objs +1 -1
@@ -24,7 +24,7 @@ obj-y += framebuffer.o obj-y += strongarm.o obj-y += imx_serial.o imx_ccm.o imx_timer.o imx_avic.o obj-$(CONFIG_KVM) += kvm/arm_gic.o -obj-y += ftintc020.o +obj-y += ftintc020.o ftahbc020.o obj-y := $(addprefix ../,$(obj-y))
hw/arm/ftplat_a369soc.c +9 -0
@@ -54,6 +54,7 @@ static void a369soc_chip_init(FaradaySoCState *s)int i;DeviceState *ds;DriveInfo *dinfo; +Error *local_errp =NULL ;/* Remappable Memory Region Init */ s->rmr =g_new0 (MemoryRegion,1 );
@@ -120,6 +121,14 @@ static void a369soc_chip_init(FaradaySoCState *s)/* ftkbc010 */ sysbus_create_simple ("a369-kpd" ,0x92f00000 , s->pic[21 ]); + +/* ftahbc020 */ + ds =sysbus_create_simple ("ftahbc020" ,0x94000000 ,NULL ); +object_property_set_link (OBJECT (ds),OBJECT (s),"soc" , &local_errp); +if (local_errp) { +fprintf (stderr,"a369soc: Unable to set soc link for FTAHBC020\n" ); +abort (); + } }static void a369soc_realize (DeviceState *dev,Error **errp)
hw/ftahbc020.c new file +216 -0
216 lines not on this page · raw message
Signature · 1 line
1.7.9.5
PATCH v9 5/24 hw/arm: add FTDDRII030 DDRII controller support
In reply to Kuo-Jung SuFrom: Kuo-Jung Su <[email protected]>
The FTDDRII030 is a DDRII SDRAM controller which is responsible for SDRAM initialization.
--- hw/arm/Makefile.objs | 2 +- hw/arm/ftplat_a369soc.c | 8 ++ hw/ftddrii030.c | 192 +++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 201 insertions(+), 1 deletion(-) create mode 100644 hw/ftddrii030.c
hw/arm/Makefile.objs +1 -1
@@ -24,7 +24,7 @@ obj-y += framebuffer.o obj-y += strongarm.o obj-y += imx_serial.o imx_ccm.o imx_timer.o imx_avic.o obj-$(CONFIG_KVM) += kvm/arm_gic.o -obj-y += ftintc020.o ftahbc020.o +obj-y += ftintc020.o ftahbc020.o ftddrii030.o obj-y := $(addprefix ../,$(obj-y))
hw/arm/ftplat_a369soc.c +8 -0
@@ -129,6 +129,14 @@ static void a369soc_chip_init(FaradaySoCState *s)fprintf (stderr,"a369soc: Unable to set soc link for FTAHBC020\n" );abort (); } + +/* ftddrii030 */ + ds =sysbus_create_simple ("ftddrii030" ,0x93100000 ,NULL ); +object_property_set_link (OBJECT (ds),OBJECT (s),"soc" , &local_errp); +if (local_errp) { +fprintf (stderr,"a369soc: Unable to set soc link for FTDDRII030\n" ); +abort (); + } }static void a369soc_realize (DeviceState *dev,Error **errp)
hw/ftddrii030.c new file +192 -0
192 lines not on this page · raw message
Signature · 1 line
1.7.9.5
Re: [Qemu-devel] [PATCH v9 05/24] hw/arm: add FTDDRII030 DDRII controller support
Hi Kuo-Jung,
Quoted 77 lines · Kuo-Jung Su
From: Kuo-Jung Su <[email protected]>
The FTDDRII030 is a DDRII SDRAM controller which is responsible for SDRAM initialization.
Signed-off-by Kuo-Jung Su <[email protected]>--- hw/arm/Makefile.objs | 2 +- hw/arm/ftplat_a369soc.c | 8 ++ hw/ftddrii030.c | 192 +++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 201 insertions(+), 1 deletion(-) create mode 100644 hw/ftddrii030.chw/arm/Makefile.objs +1
-1@@ -24,7 +24,7 @@ obj-y += framebuffer.o obj-y += strongarm.o obj-y += imx_serial.o imx_ccm.o imx_timer.o imx_avic.o obj-$(CONFIG_KVM) += kvm/arm_gic.o -obj-y += ftintc020.o ftahbc020.o +obj-y += ftintc020.o ftahbc020.o ftddrii030.o obj-y := $(addprefix ../,$(obj-y))hw/arm/ftplat_a369soc.c +8
-0@@ -129,6 +129,14 @@ static void a369soc_chip_init(FaradaySoCState *s)fprintf (stderr,"a369soc: Unable to set soc link for FTAHBC020\n" );abort (); } + +/* ftddrii030 */ + ds =sysbus_create_simple ("ftddrii030" ,0x93100000 ,NULL ); +object_property_set_link (OBJECT (ds),OBJECT (s),"soc" , &local_errp); +if (local_errp) { +fprintf (stderr,"a369soc: Unable to set soc link for FTDDRII030\n" ); +abort (); + } }static void a369soc_realize (DeviceState *dev,Error **errp)hw/ftddrii030.c new file +26
-0@@ -0,0 +1,192 @@ +/* +* Faraday DDRII controller +* +* Copyright (c) 2012 Faraday Technology +* Written by Dante Su <[email protected]> +* +* This code is licensed under GNU GPL v2+ +*/ + +#include "hw/hw.h" +#include "hw/sysbus.h" +#include "hw/devices.h" +#include "sysemu/sysemu.h" + +#include "hw/faraday.h" + +#define REG_MCR 0x00/* memory configuration register */ +#define REG_MSR 0x04/* memory status register */ +#define REG_REVR 0x50/* revision register */ + +#define MSR_INIT_OK BIT(8)/* initialization finished */ +#define MSR_CMD_MRS BIT(0)/* start MRS command (init. seq.) */ + +#define CFG_REGSIZE (REG_REVR / 4) + +#define TYPE_FTDDRII030 "ftddrii030"
hw/ftddrii030.c line 36
Quoted 10 lines
hw/ftddrii030.c new file +10
-0+ +typedef struct Ftddrii030State { + /*< private >*/ + SysBusDevice parent; + + /*< public >*/ + MemoryRegion iomem; + + FaradaySoCState *soc; +
This new implementation still has many of the same encapsulation issues discussed in v8. If you go with the suggestion myself and Peter came up with you could make this device completely self contained - it should have no awareness that it is part of the Faraday SoC. If you model as a second MemoryRegion you can push all the Faraday specific foo up to the SoC. Interdiff would go something like this:
- FaradaySoCState *soc;
+ MemoryRegion ram;
Quoted 43 lines
hw/ftddrii030.c new file +43
-0+/* HW register cache */ +uint32_t regs[CFG_REGSIZE ]; +} Ftddrii030State; + +#define FTDDRII030 (obj) \ + OBJECT_CHECK(Ftddrii030State, obj, TYPE_FTDDRII030) + +#define DDR_REG32 (s, off) \ + ((s)->regs[(off) / 4]) + +static uint64_t +ftddrii030_mem_read (void *opaque,hwaddr addr,unsigned size) +{ +Ftddrii030State *s =FTDDRII030 (opaque); +FaradaySoCState *soc = s->soc; +uint64_t ret =0 ; + +if (soc->ram_visible) { +DDR_REG32 (s,REG_MSR ) |=MSR_INIT_OK ; + }else { +DDR_REG32 (s,REG_MSR ) &= ~MSR_INIT_OK ; + } + +switch (addr) { + case REG_MCR ... REG_REVR - 4: + ret =DDR_REG32 (s, addr); +break ; +case REG_REVR : + ret =0x100 ;/* rev. = 0.1.0 */ +break ; +default : +qemu_log_mask (LOG_GUEST_ERROR , +"ftddrii030: undefined memory access@%#" HWADDR_PRIx"\n" , addr); +break ; + } + +return ret; +} + +static void +ftddrii030_mem_write (void *opaque,hwaddr addr,uint64_t val,unsigned size) +{ +Ftddrii030State *s =FTDDRII030 (opaque);
hw/ftddrii030.c line 89
Quoted 10 lines
hw/ftddrii030.c new file +10
-0+FaradaySoCState *soc = s->soc; + +switch (addr) { +case REG_MCR : +DDR_REG32 (s, addr) = (uint32_t )val &0xffff ; +break ; +case REG_MSR : +if (!soc->ram_visible && (val &MSR_CMD_MRS )) { + val &= ~MSR_CMD_MRS ; +faraday_soc_ram_setup (soc, true);
This function (added earlier in this series) then becomes local to this device model and the memory_region_add_subregion() happens with the new ram Memory region instead. AFAICT that function only requires the ram size which strikes me as something that should be a QOM property to the device.
Quoted 44 lines
hw/ftddrii030.c new file +44
-0+ } +DDR_REG32 (s, addr) = (uint32_t )val; +break ; +/* SDRAM Timing, ECC ...etc. */ + case REG_MSR + 4 ... REG_REVR - 4: +DDR_REG32 (s, addr) = (uint32_t )val; +break ; +case REG_REVR : +break ; +default : +qemu_log_mask (LOG_GUEST_ERROR , +"ftddrii030: undefined memory access@%#" HWADDR_PRIx"\n" , addr); +break ; + } +} + +static const MemoryRegionOps mmio_ops = { + .read = ftddrii030_mem_read, + .write = ftddrii030_mem_write, + .endianness =DEVICE_LITTLE_ENDIAN , + .valid = { + .min_access_size =4 , + .max_access_size =4 , + } +}; + +static void ftddrii030_reset (DeviceState *ds) +{ +Ftddrii030State *s =FTDDRII030 (SYS_BUS_DEVICE (ds)); +Error *local_errp =NULL ; + + s->soc =FARADAY_SOC (object_property_get_link (OBJECT (s), +"soc" , + &local_errp)); +if (local_errp) { +fprintf (stderr,"ftahbc020: Unable to get soc link\n" ); +abort (); + } + +faraday_soc_ram_setup (s->soc, false); +memset (s->regs,0 ,sizeof (s->regs)); +} + +static void ftddrii030_realize (DeviceState *dev,Error **errp)
hw/ftddrii030.c line 143
Quoted 10 lines
hw/ftddrii030.c new file +10
-0+{ +Ftddrii030State *s =FTDDRII030 (dev); +SysBusDevice *sbd =SYS_BUS_DEVICE (dev); + +memory_region_init_io (&s->iomem, + &mmio_ops, + s, +TYPE_FTDDRII030 , +0x1000 ); +sysbus_init_mmio (sbd, &s->iomem);
Init the new ram memory region here.
I could use a second opinion on all this QOM stuff though - you are on the bleeding edge with the QOM SoC stuff. I suggest giving it some list time for others to reply before a remake.
Regards,
Peter
Quoted 53 lines
hw/ftddrii030.c new file +49
-1+} + +static const VMStateDescription vmstate_ftddrii030 = { + .name =TYPE_FTDDRII030 , + .version_id =1 , + .minimum_version_id =1 , + .minimum_version_id_old =1 , + .fields = (VMStateField []) { +VMSTATE_UINT32_ARRAY (regs, Ftddrii030State,CFG_REGSIZE ), +VMSTATE_END_OF_LIST (), + } +}; + +static void ftddrii030_instance_init (Object *obj) +{ +Ftddrii030State *s =FTDDRII030 (obj); + +object_property_add_link (obj, +"soc" , +TYPE_FARADAY_SOC , + (Object **) &s->soc, +NULL ); +} + +static void ftddrii030_class_init (ObjectClass *klass,void *data) +{ +DeviceClass *dc =DEVICE_CLASS (klass); + + dc->desc =TYPE_FTDDRII030 ; + dc->vmsd = &vmstate_ftddrii030; + dc->reset = ftddrii030_reset; + dc->realize = ftddrii030_realize; + dc->no_user =1 ; +} + +static const TypeInfo ftddrii030_info = { + .name =TYPE_FTDDRII030 , + .parent =TYPE_SYS_BUS_DEVICE , + .instance_size =sizeof (Ftddrii030State), + .instance_init = ftddrii030_instance_init, + .class_init = ftddrii030_class_init, +}; + +static void ftddrii030_register_types (void ) +{ +type_register_static (&ftddrii030_info); +} + +type_init (ftddrii030_register_types) --1.7.9.5
Re: [Qemu-devel] [PATCH v9 05/24] hw/arm: add FTDDRII030 DDRII controller support
2013/3/28 Peter Crosthwaite <[email protected]>:
Quoted 99 lines
Hi Kuo-Jung,
Quoted 77 lines · Kuo-Jung Su
From: Kuo-Jung Su <[email protected]>
The FTDDRII030 is a DDRII SDRAM controller which is responsible for SDRAM initialization.
Signed-off-by Kuo-Jung Su <[email protected]>--- hw/arm/Makefile.objs | 2 +- hw/arm/ftplat_a369soc.c | 8 ++ hw/ftddrii030.c | 192 +++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 201 insertions(+), 1 deletion(-) create mode 100644 hw/ftddrii030.chw/arm/Makefile.objs +1
-1@@ -24,7 +24,7 @@ obj-y += framebuffer.o obj-y += strongarm.o obj-y += imx_serial.o imx_ccm.o imx_timer.o imx_avic.o obj-$(CONFIG_KVM) += kvm/arm_gic.o -obj-y += ftintc020.o ftahbc020.o +obj-y += ftintc020.o ftahbc020.o ftddrii030.o obj-y := $(addprefix ../,$(obj-y))hw/arm/ftplat_a369soc.c +8
-0@@ -129,6 +129,14 @@ static void a369soc_chip_init(FaradaySoCState *s)fprintf (stderr,"a369soc: Unable to set soc link for FTAHBC020\n" );abort (); } + +/* ftddrii030 */ + ds =sysbus_create_simple ("ftddrii030" ,0x93100000 ,NULL ); +object_property_set_link (OBJECT (ds),OBJECT (s),"soc" , &local_errp); +if (local_errp) { +fprintf (stderr,"a369soc: Unable to set soc link for FTDDRII030\n" ); +abort (); + } }static void a369soc_realize (DeviceState *dev,Error **errp)hw/ftddrii030.c new file +26
-0@@ -0,0 +1,192 @@ +/* +* Faraday DDRII controller +* +* Copyright (c) 2012 Faraday Technology +* Written by Dante Su <[email protected]> +* +* This code is licensed under GNU GPL v2+ +*/ + +#include "hw/hw.h" +#include "hw/sysbus.h" +#include "hw/devices.h" +#include "sysemu/sysemu.h" + +#include "hw/faraday.h" + +#define REG_MCR 0x00/* memory configuration register */ +#define REG_MSR 0x04/* memory status register */ +#define REG_REVR 0x50/* revision register */ + +#define MSR_INIT_OK BIT(8)/* initialization finished */ +#define MSR_CMD_MRS BIT(0)/* start MRS command (init. seq.) */ + +#define CFG_REGSIZE (REG_REVR / 4) + +#define TYPE_FTDDRII030 "ftddrii030"hw/ftddrii030.c line 36
Quoted 10 lines
hw/ftddrii030.c new file +10
-0+ +typedef struct Ftddrii030State { + /*< private >*/ + SysBusDevice parent; + + /*< public >*/ + MemoryRegion iomem; + + FaradaySoCState *soc; +This new implementation still has many of the same encapsulation issues discussed in v8. If you go with the suggestion myself and Peter came up with you could make this device completely self contained - it should have no awareness that it is part of the Faraday SoC. If you model as a second MemoryRegion you can push all the Faraday specific foo up to the SoC. Interdiff would go something like this:
Review
Quoted 2 lines
(quoted diff) +1
-1- FaradaySoCState *soc; + MemoryRegion ram;
Sorry, but I think it might not work in that way.
Because there is an AHB remap function is Faraday SoC,
which would alter the base address of both ROM and RAM.
So the ram instance should never be a local variable to FTDDRII030 only.
The first thing solution spring up in my mind is to add a QOM link in FTDDRII030, and then pass the ram instance as a QOM link from device model. However it turns out that it's also not possible, since the ram instance (MemoryRegion) is not a Object *.
So I turn out to implement both the 'AHB remap' and 'RAM initialization' as common routines
to Faraday SoC, and also create a remappable memory region for both ROM and RAM.
Quoted 51 lines
Quoted 51 lines
hw/ftddrii030.c new file +51
-0+/* HW register cache */ +uint32_t regs[CFG_REGSIZE ]; +} Ftddrii030State; + +#define FTDDRII030 (obj) \ + OBJECT_CHECK(Ftddrii030State, obj, TYPE_FTDDRII030) + +#define DDR_REG32 (s, off) \ + ((s)->regs[(off) / 4]) + +static uint64_t +ftddrii030_mem_read (void *opaque,hwaddr addr,unsigned size) +{ +Ftddrii030State *s =FTDDRII030 (opaque); +FaradaySoCState *soc = s->soc; +uint64_t ret =0 ; + +if (soc->ram_visible) { +DDR_REG32 (s,REG_MSR ) |=MSR_INIT_OK ; + }else { +DDR_REG32 (s,REG_MSR ) &= ~MSR_INIT_OK ; + } + +switch (addr) { + case REG_MCR ... REG_REVR - 4: + ret =DDR_REG32 (s, addr); +break ; +case REG_REVR : + ret =0x100 ;/* rev. = 0.1.0 */ +break ; +default : +qemu_log_mask (LOG_GUEST_ERROR , +"ftddrii030: undefined memory access@%#" HWADDR_PRIx"\n" , addr); +break ; + } + +return ret; +} + +static void +ftddrii030_mem_write (void *opaque,hwaddr addr,uint64_t val,unsigned size) +{ +Ftddrii030State *s =FTDDRII030 (opaque); +FaradaySoCState *soc = s->soc; + +switch (addr) { +case REG_MCR : +DDR_REG32 (s, addr) = (uint32_t )val &0xffff ; +break ; +case REG_MSR : +if (!soc->ram_visible && (val &MSR_CMD_MRS )) {
Quoted 9 lines
hw/ftddrii030.c line 89
Quoted 2 lines
hw/ftddrii030.c new file +2
-0+ val &= ~MSR_CMD_MRS ; +faraday_soc_ram_setup (soc, true);This function (added earlier in this series) then becomes local to this device model and the
memory_region_add_subregion()happens with the new ram Memory region instead. AFAICT that function only requires the ram size which strikes me as something that should be a QOM property to the device.
Please see the comments above.
Quoted 48 lines
Quoted 48 lines
hw/ftddrii030.c new file +48
-0+ } +DDR_REG32 (s, addr) = (uint32_t )val; +break ; +/* SDRAM Timing, ECC ...etc. */ + case REG_MSR + 4 ... REG_REVR - 4: +DDR_REG32 (s, addr) = (uint32_t )val; +break ; +case REG_REVR : +break ; +default : +qemu_log_mask (LOG_GUEST_ERROR , +"ftddrii030: undefined memory access@%#" HWADDR_PRIx"\n" , addr); +break ; + } +} + +static const MemoryRegionOps mmio_ops = { + .read = ftddrii030_mem_read, + .write = ftddrii030_mem_write, + .endianness =DEVICE_LITTLE_ENDIAN , + .valid = { + .min_access_size =4 , + .max_access_size =4 , + } +}; + +static void ftddrii030_reset (DeviceState *ds) +{ +Ftddrii030State *s =FTDDRII030 (SYS_BUS_DEVICE (ds)); +Error *local_errp =NULL ; + + s->soc =FARADAY_SOC (object_property_get_link (OBJECT (s), +"soc" , + &local_errp)); +if (local_errp) { +fprintf (stderr,"ftahbc020: Unable to get soc link\n" ); +abort (); + } + +faraday_soc_ram_setup (s->soc, false); +memset (s->regs,0 ,sizeof (s->regs)); +} + +static void ftddrii030_realize (DeviceState *dev,Error **errp) +{ +Ftddrii030State *s =FTDDRII030 (dev); +SysBusDevice *sbd =SYS_BUS_DEVICE (dev); +
Quoted 9 lines
hw/ftddrii030.c line 143
Quoted 6 lines
hw/ftddrii030.c new file +6
-0+memory_region_init_io (&s->iomem, + &mmio_ops, + s, +TYPE_FTDDRII030 , +0x1000 ); +sysbus_init_mmio (sbd, &s->iomem);Init the new ram memory region here.
Please see the comments above.
Quoted 4 lines
I could use a second opinion on all this QOM stuff though - you are on the bleeding edge with the QOM SoC stuff. I suggest giving it some list time for others to reply before a remake.
Got it, thanks.
Quoted 48 lines
Regards,
PeterQuoted 45 lines
hw/ftddrii030.c new file +45
-0+} + +static const VMStateDescription vmstate_ftddrii030 = { + .name =TYPE_FTDDRII030 , + .version_id =1 , + .minimum_version_id =1 , + .minimum_version_id_old =1 , + .fields = (VMStateField []) { +VMSTATE_UINT32_ARRAY (regs, Ftddrii030State,CFG_REGSIZE ), +VMSTATE_END_OF_LIST (), + } +}; + +static void ftddrii030_instance_init (Object *obj) +{ +Ftddrii030State *s =FTDDRII030 (obj); + +object_property_add_link (obj, +"soc" , +TYPE_FARADAY_SOC , + (Object **) &s->soc, +NULL ); +} + +static void ftddrii030_class_init (ObjectClass *klass,void *data) +{ +DeviceClass *dc =DEVICE_CLASS (klass); + + dc->desc =TYPE_FTDDRII030 ; + dc->vmsd = &vmstate_ftddrii030; + dc->reset = ftddrii030_reset; + dc->realize = ftddrii030_realize; + dc->no_user =1 ; +} + +static const TypeInfo ftddrii030_info = { + .name =TYPE_FTDDRII030 , + .parent =TYPE_SYS_BUS_DEVICE , + .instance_size =sizeof (Ftddrii030State), + .instance_init = ftddrii030_instance_init, + .class_init = ftddrii030_class_init, +}; + +static void ftddrii030_register_types (void ) +{
Quoted 8 lines
Quoted 8 lines
hw/ftddrii030.c new file +4
-1+type_register_static (&ftddrii030_info); +} + +type_init (ftddrii030_register_types) --1.7.9.5
--
Best wishes,
Kuo-Jung Su
Re: [Qemu-devel] [PATCH v9 05/24] hw/arm: add FTDDRII030 DDRII controller support
Hi Kuo Jung,
Quoted 99 lines · Kuo-Jung Su
2013/3/28 Peter Crosthwaite <[email protected]>:
Quoted 98 lines
Hi Kuo-Jung,
Quoted 77 lines · Kuo-Jung Su
From: Kuo-Jung Su <[email protected]>
The FTDDRII030 is a DDRII SDRAM controller which is responsible for SDRAM initialization.
Signed-off-by Kuo-Jung Su <[email protected]>--- hw/arm/Makefile.objs | 2 +- hw/arm/ftplat_a369soc.c | 8 ++ hw/ftddrii030.c | 192 +++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 201 insertions(+), 1 deletion(-) create mode 100644 hw/ftddrii030.chw/arm/Makefile.objs +1
-1@@ -24,7 +24,7 @@ obj-y += framebuffer.o obj-y += strongarm.o obj-y += imx_serial.o imx_ccm.o imx_timer.o imx_avic.o obj-$(CONFIG_KVM) += kvm/arm_gic.o -obj-y += ftintc020.o ftahbc020.o +obj-y += ftintc020.o ftahbc020.o ftddrii030.o obj-y := $(addprefix ../,$(obj-y))hw/arm/ftplat_a369soc.c +8
-0@@ -129,6 +129,14 @@ static void a369soc_chip_init(FaradaySoCState *s)fprintf (stderr,"a369soc: Unable to set soc link for FTAHBC020\n" );abort (); } + +/* ftddrii030 */ + ds =sysbus_create_simple ("ftddrii030" ,0x93100000 ,NULL ); +object_property_set_link (OBJECT (ds),OBJECT (s),"soc" , &local_errp); +if (local_errp) { +fprintf (stderr,"a369soc: Unable to set soc link for FTDDRII030\n" ); +abort (); + } }static void a369soc_realize (DeviceState *dev,Error **errp)hw/ftddrii030.c new file +26
-0@@ -0,0 +1,192 @@ +/* +* Faraday DDRII controller +* +* Copyright (c) 2012 Faraday Technology +* Written by Dante Su <[email protected]> +* +* This code is licensed under GNU GPL v2+ +*/ + +#include "hw/hw.h" +#include "hw/sysbus.h" +#include "hw/devices.h" +#include "sysemu/sysemu.h" + +#include "hw/faraday.h" + +#define REG_MCR 0x00/* memory configuration register */ +#define REG_MSR 0x04/* memory status register */ +#define REG_REVR 0x50/* revision register */ + +#define MSR_INIT_OK BIT(8)/* initialization finished */ +#define MSR_CMD_MRS BIT(0)/* start MRS command (init. seq.) */ + +#define CFG_REGSIZE (REG_REVR / 4) + +#define TYPE_FTDDRII030 "ftddrii030"hw/ftddrii030.c line 36
Quoted 10 lines
hw/ftddrii030.c new file +10
-0+ +typedef struct Ftddrii030State { + /*< private >*/ + SysBusDevice parent; + + /*< public >*/ + MemoryRegion iomem; + + FaradaySoCState *soc; +This new implementation still has many of the same encapsulation issues discussed in v8. If you go with the suggestion myself and Peter came up with you could make this device completely self contained - it should have no awareness that it is part of the Faraday SoC. If you model as a second MemoryRegion you can push all the Faraday specific foo up to the SoC. Interdiff would go something like this:
Quoted 9 lines
Review
Quoted 3 lines
(quoted diff) +1
-1- FaradaySoCState *soc; + MemoryRegion ram;Sorry, but I think it might not work in that way.
Because there is an AHB remap function is Faraday SoC,
which would alter the base address of both ROM and RAM.
So the ram instance should never be a local variable to FTDDRII030 only.
The new RAM region would have no awareness of its base address. It is just a remappable container. The SoC can still do the remapping part. This device model is then oblivous to the fact that the SoC and other devices are remapping its base address.
Quoted 5 lines
The first thing solution spring up in my mind is to add a QOM link in FTDDRII030, and then pass the ram instance as a QOM link from device model. However it turns out that it's also not possible, since the ram instance (MemoryRegion) is not a Object *.
calling sysbus_mmio_get_region() on the SoC level should do the trick. If you init the container region as proposed, this function can be used by the SoC to get a handle to it.
I think we are on similar timezones (+10:00 here) if you want to try and clarify on the IRC sometime today as well.
Regards,
Peter
Quoted 197 lines
So I turn out to implement both the 'AHB remap' and 'RAM initialization' as common routines
to Faraday SoC, and also create a remappable memory region for both ROM and RAM.Quoted 51 lines
Quoted 51 lines
hw/ftddrii030.c new file +51
-0+/* HW register cache */ +uint32_t regs[CFG_REGSIZE ]; +} Ftddrii030State; + +#define FTDDRII030 (obj) \ + OBJECT_CHECK(Ftddrii030State, obj, TYPE_FTDDRII030) + +#define DDR_REG32 (s, off) \ + ((s)->regs[(off) / 4]) + +static uint64_t +ftddrii030_mem_read (void *opaque,hwaddr addr,unsigned size) +{ +Ftddrii030State *s =FTDDRII030 (opaque); +FaradaySoCState *soc = s->soc; +uint64_t ret =0 ; + +if (soc->ram_visible) { +DDR_REG32 (s,REG_MSR ) |=MSR_INIT_OK ; + }else { +DDR_REG32 (s,REG_MSR ) &= ~MSR_INIT_OK ; + } + +switch (addr) { + case REG_MCR ... REG_REVR - 4: + ret =DDR_REG32 (s, addr); +break ; +case REG_REVR : + ret =0x100 ;/* rev. = 0.1.0 */ +break ; +default : +qemu_log_mask (LOG_GUEST_ERROR , +"ftddrii030: undefined memory access@%#" HWADDR_PRIx"\n" , addr); +break ; + } + +return ret; +} + +static void +ftddrii030_mem_write (void *opaque,hwaddr addr,uint64_t val,unsigned size) +{ +Ftddrii030State *s =FTDDRII030 (opaque); +FaradaySoCState *soc = s->soc; + +switch (addr) { +case REG_MCR : +DDR_REG32 (s, addr) = (uint32_t )val &0xffff ; +break ; +case REG_MSR : +if (!soc->ram_visible && (val &MSR_CMD_MRS )) {Quoted 9 lines
hw/ftddrii030.c line 89
Quoted 2 lines
hw/ftddrii030.c new file +2
-0+ val &= ~MSR_CMD_MRS ; +faraday_soc_ram_setup (soc, true);This function (added earlier in this series) then becomes local to this device model and the
memory_region_add_subregion()happens with the new ram Memory region instead. AFAICT that function only requires the ram size which strikes me as something that should be a QOM property to the device.Please see the comments above.
Quoted 48 lines
Quoted 48 lines
hw/ftddrii030.c new file +48
-0+ } +DDR_REG32 (s, addr) = (uint32_t )val; +break ; +/* SDRAM Timing, ECC ...etc. */ + case REG_MSR + 4 ... REG_REVR - 4: +DDR_REG32 (s, addr) = (uint32_t )val; +break ; +case REG_REVR : +break ; +default : +qemu_log_mask (LOG_GUEST_ERROR , +"ftddrii030: undefined memory access@%#" HWADDR_PRIx"\n" , addr); +break ; + } +} + +static const MemoryRegionOps mmio_ops = { + .read = ftddrii030_mem_read, + .write = ftddrii030_mem_write, + .endianness =DEVICE_LITTLE_ENDIAN , + .valid = { + .min_access_size =4 , + .max_access_size =4 , + } +}; + +static void ftddrii030_reset (DeviceState *ds) +{ +Ftddrii030State *s =FTDDRII030 (SYS_BUS_DEVICE (ds)); +Error *local_errp =NULL ; + + s->soc =FARADAY_SOC (object_property_get_link (OBJECT (s), +"soc" , + &local_errp)); +if (local_errp) { +fprintf (stderr,"ftahbc020: Unable to get soc link\n" ); +abort (); + } + +faraday_soc_ram_setup (s->soc, false); +memset (s->regs,0 ,sizeof (s->regs)); +} + +static void ftddrii030_realize (DeviceState *dev,Error **errp) +{ +Ftddrii030State *s =FTDDRII030 (dev); +SysBusDevice *sbd =SYS_BUS_DEVICE (dev); +Quoted 9 lines
hw/ftddrii030.c line 143
Quoted 6 lines
hw/ftddrii030.c new file +6
-0+memory_region_init_io (&s->iomem, + &mmio_ops, + s, +TYPE_FTDDRII030 , +0x1000 ); +sysbus_init_mmio (sbd, &s->iomem);Init the new ram memory region here.
Please see the comments above.
Quoted 4 lines
I could use a second opinion on all this QOM stuff though - you are on the bleeding edge with the QOM SoC stuff. I suggest giving it some list time for others to reply before a remake.
Got it, thanks.
Quoted 48 lines
Regards,
PeterQuoted 45 lines
hw/ftddrii030.c new file +45
-0+} + +static const VMStateDescription vmstate_ftddrii030 = { + .name =TYPE_FTDDRII030 , + .version_id =1 , + .minimum_version_id =1 , + .minimum_version_id_old =1 , + .fields = (VMStateField []) { +VMSTATE_UINT32_ARRAY (regs, Ftddrii030State,CFG_REGSIZE ), +VMSTATE_END_OF_LIST (), + } +}; + +static void ftddrii030_instance_init (Object *obj) +{ +Ftddrii030State *s =FTDDRII030 (obj); + +object_property_add_link (obj, +"soc" , +TYPE_FARADAY_SOC , + (Object **) &s->soc, +NULL ); +} + +static void ftddrii030_class_init (ObjectClass *klass,void *data) +{ +DeviceClass *dc =DEVICE_CLASS (klass); + + dc->desc =TYPE_FTDDRII030 ; + dc->vmsd = &vmstate_ftddrii030; + dc->reset = ftddrii030_reset; + dc->realize = ftddrii030_realize; + dc->no_user =1 ; +} + +static const TypeInfo ftddrii030_info = { + .name =TYPE_FTDDRII030 , + .parent =TYPE_SYS_BUS_DEVICE , + .instance_size =sizeof (Ftddrii030State), + .instance_init = ftddrii030_instance_init, + .class_init = ftddrii030_class_init, +}; + +static void ftddrii030_register_types (void ) +{Quoted 8 lines
Quoted 8 lines
hw/ftddrii030.c new file +4
-1+type_register_static (&ftddrii030_info); +} + +type_init (ftddrii030_register_types) --1.7.9.5
--
Best wishes,
Kuo-Jung Su
Re: [Qemu-devel] [PATCH v9 05/24] hw/arm: add FTDDRII030 DDRII controller support
2013/3/28 Peter Crosthwaite <[email protected]>:
Quoted 123 lines
Hi Kuo Jung,
Quoted 99 lines · Kuo-Jung Su
2013/3/28 Peter Crosthwaite <[email protected]>:
Quoted 98 lines
Hi Kuo-Jung,
Quoted 77 lines · Kuo-Jung Su
From: Kuo-Jung Su <[email protected]>
The FTDDRII030 is a DDRII SDRAM controller which is responsible for SDRAM initialization.
Signed-off-by Kuo-Jung Su <[email protected]>--- hw/arm/Makefile.objs | 2 +- hw/arm/ftplat_a369soc.c | 8 ++ hw/ftddrii030.c | 192 +++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 201 insertions(+), 1 deletion(-) create mode 100644 hw/ftddrii030.chw/arm/Makefile.objs +1
-1@@ -24,7 +24,7 @@ obj-y += framebuffer.o obj-y += strongarm.o obj-y += imx_serial.o imx_ccm.o imx_timer.o imx_avic.o obj-$(CONFIG_KVM) += kvm/arm_gic.o -obj-y += ftintc020.o ftahbc020.o +obj-y += ftintc020.o ftahbc020.o ftddrii030.o obj-y := $(addprefix ../,$(obj-y))hw/arm/ftplat_a369soc.c +8
-0@@ -129,6 +129,14 @@ static void a369soc_chip_init(FaradaySoCState *s)fprintf (stderr,"a369soc: Unable to set soc link for FTAHBC020\n" );abort (); } + +/* ftddrii030 */ + ds =sysbus_create_simple ("ftddrii030" ,0x93100000 ,NULL ); +object_property_set_link (OBJECT (ds),OBJECT (s),"soc" , &local_errp); +if (local_errp) { +fprintf (stderr,"a369soc: Unable to set soc link for FTDDRII030\n" ); +abort (); + } }static void a369soc_realize (DeviceState *dev,Error **errp)hw/ftddrii030.c new file +26
-0@@ -0,0 +1,192 @@ +/* +* Faraday DDRII controller +* +* Copyright (c) 2012 Faraday Technology +* Written by Dante Su <[email protected]> +* +* This code is licensed under GNU GPL v2+ +*/ + +#include "hw/hw.h" +#include "hw/sysbus.h" +#include "hw/devices.h" +#include "sysemu/sysemu.h" + +#include "hw/faraday.h" + +#define REG_MCR 0x00/* memory configuration register */ +#define REG_MSR 0x04/* memory status register */ +#define REG_REVR 0x50/* revision register */ + +#define MSR_INIT_OK BIT(8)/* initialization finished */ +#define MSR_CMD_MRS BIT(0)/* start MRS command (init. seq.) */ + +#define CFG_REGSIZE (REG_REVR / 4) + +#define TYPE_FTDDRII030 "ftddrii030"hw/ftddrii030.c line 36
Quoted 10 lines
hw/ftddrii030.c new file +10
-0+ +typedef struct Ftddrii030State { + /*< private >*/ + SysBusDevice parent; + + /*< public >*/ + MemoryRegion iomem; + + FaradaySoCState *soc; +This new implementation still has many of the same encapsulation issues discussed in v8. If you go with the suggestion myself and Peter came up with you could make this device completely self contained - it should have no awareness that it is part of the Faraday SoC. If you model as a second MemoryRegion you can push all the Faraday specific foo up to the SoC. Interdiff would go something like this:
Quoted 9 lines
Review
Quoted 3 lines
(quoted diff) +1
-1- FaradaySoCState *soc; + MemoryRegion ram;Sorry, but I think it might not work in that way.
Because there is an AHB remap function is Faraday SoC,
which would alter the base address of both ROM and RAM.
So the ram instance should never be a local variable to FTDDRII030 only.The new RAM region would have no awareness of its base address. It is just a remappable container. The SoC can still do the remapping part. This device model is then oblivous to the fact that the SoC and other devices are remapping its base address.
Quoted 5 lines
The first thing solution spring up in my mind is to add a QOM link in FTDDRII030, and then pass the ram instance as a QOM link from device model. However it turns out that it's also not possible, since the ram instance (MemoryRegion) is not a Object *.
Quoted 4 lines
calling
sysbus_mmio_get_region()on the SoC level should do the trick. If you init the container region as proposed, this function can be used by the SoC to get a handle to it.
It sounds like pretty good idea to me, I think I know what to do now. Thanks
Quoted 3 lines
I think we are on similar timezones (+10:00 here) if you want to try and clarify on the IRC sometime today as well.
Thanks for the invitation, but the IRQ is banned in my company...
Quoted 200 lines
Regards,
PeterQuoted 197 lines
So I turn out to implement both the 'AHB remap' and 'RAM initialization' as common routines
to Faraday SoC, and also create a remappable memory region for both ROM and RAM.Quoted 51 lines
Quoted 51 lines
hw/ftddrii030.c new file +51
-0+/* HW register cache */ +uint32_t regs[CFG_REGSIZE ]; +} Ftddrii030State; + +#define FTDDRII030 (obj) \ + OBJECT_CHECK(Ftddrii030State, obj, TYPE_FTDDRII030) + +#define DDR_REG32 (s, off) \ + ((s)->regs[(off) / 4]) + +static uint64_t +ftddrii030_mem_read (void *opaque,hwaddr addr,unsigned size) +{ +Ftddrii030State *s =FTDDRII030 (opaque); +FaradaySoCState *soc = s->soc; +uint64_t ret =0 ; + +if (soc->ram_visible) { +DDR_REG32 (s,REG_MSR ) |=MSR_INIT_OK ; + }else { +DDR_REG32 (s,REG_MSR ) &= ~MSR_INIT_OK ; + } + +switch (addr) { + case REG_MCR ... REG_REVR - 4: + ret =DDR_REG32 (s, addr); +break ; +case REG_REVR : + ret =0x100 ;/* rev. = 0.1.0 */ +break ; +default : +qemu_log_mask (LOG_GUEST_ERROR , +"ftddrii030: undefined memory access@%#" HWADDR_PRIx"\n" , addr); +break ; + } + +return ret; +} + +static void +ftddrii030_mem_write (void *opaque,hwaddr addr,uint64_t val,unsigned size) +{ +Ftddrii030State *s =FTDDRII030 (opaque); +FaradaySoCState *soc = s->soc; + +switch (addr) { +case REG_MCR : +DDR_REG32 (s, addr) = (uint32_t )val &0xffff ; +break ; +case REG_MSR : +if (!soc->ram_visible && (val &MSR_CMD_MRS )) {Quoted 9 lines
hw/ftddrii030.c line 89
Quoted 2 lines
hw/ftddrii030.c new file +2
-0+ val &= ~MSR_CMD_MRS ; +faraday_soc_ram_setup (soc, true);This function (added earlier in this series) then becomes local to this device model and the
memory_region_add_subregion()happens with the new ram Memory region instead. AFAICT that function only requires the ram size which strikes me as something that should be a QOM property to the device.Please see the comments above.
Quoted 48 lines
Quoted 48 lines
hw/ftddrii030.c new file +48
-0+ } +DDR_REG32 (s, addr) = (uint32_t )val; +break ; +/* SDRAM Timing, ECC ...etc. */ + case REG_MSR + 4 ... REG_REVR - 4: +DDR_REG32 (s, addr) = (uint32_t )val; +break ; +case REG_REVR : +break ; +default : +qemu_log_mask (LOG_GUEST_ERROR , +"ftddrii030: undefined memory access@%#" HWADDR_PRIx"\n" , addr); +break ; + } +} + +static const MemoryRegionOps mmio_ops = { + .read = ftddrii030_mem_read, + .write = ftddrii030_mem_write, + .endianness =DEVICE_LITTLE_ENDIAN , + .valid = { + .min_access_size =4 , + .max_access_size =4 , + } +}; + +static void ftddrii030_reset (DeviceState *ds) +{ +Ftddrii030State *s =FTDDRII030 (SYS_BUS_DEVICE (ds)); +Error *local_errp =NULL ; + + s->soc =FARADAY_SOC (object_property_get_link (OBJECT (s), +"soc" , + &local_errp)); +if (local_errp) { +fprintf (stderr,"ftahbc020: Unable to get soc link\n" ); +abort (); + } + +faraday_soc_ram_setup (s->soc, false); +memset (s->regs,0 ,sizeof (s->regs)); +} + +static void ftddrii030_realize (DeviceState *dev,Error **errp) +{ +Ftddrii030State *s =FTDDRII030 (dev); +SysBusDevice *sbd =SYS_BUS_DEVICE (dev); +Quoted 9 lines
hw/ftddrii030.c line 143
Quoted 6 lines
hw/ftddrii030.c new file +6
-0+memory_region_init_io (&s->iomem, + &mmio_ops, + s, +TYPE_FTDDRII030 , +0x1000 ); +sysbus_init_mmio (sbd, &s->iomem);Init the new ram memory region here.
Please see the comments above.
Quoted 4 lines
I could use a second opinion on all this QOM stuff though - you are on the bleeding edge with the QOM SoC stuff. I suggest giving it some list time for others to reply before a remake.
Got it, thanks.
Quoted 48 lines
Regards,
PeterQuoted 45 lines
hw/ftddrii030.c new file +45
-0+} + +static const VMStateDescription vmstate_ftddrii030 = { + .name =TYPE_FTDDRII030 , + .version_id =1 , + .minimum_version_id =1 , + .minimum_version_id_old =1 , + .fields = (VMStateField []) { +VMSTATE_UINT32_ARRAY (regs, Ftddrii030State,CFG_REGSIZE ), +VMSTATE_END_OF_LIST (), + } +}; + +static void ftddrii030_instance_init (Object *obj) +{ +Ftddrii030State *s =FTDDRII030 (obj); + +object_property_add_link (obj, +"soc" , +TYPE_FARADAY_SOC , + (Object **) &s->soc, +NULL ); +} + +static void ftddrii030_class_init (ObjectClass *klass,void *data) +{ +DeviceClass *dc =DEVICE_CLASS (klass); + + dc->desc =TYPE_FTDDRII030 ; + dc->vmsd = &vmstate_ftddrii030; + dc->reset = ftddrii030_reset; + dc->realize = ftddrii030_realize; + dc->no_user =1 ; +} + +static const TypeInfo ftddrii030_info = { + .name =TYPE_FTDDRII030 , + .parent =TYPE_SYS_BUS_DEVICE , + .instance_size =sizeof (Ftddrii030State), + .instance_init = ftddrii030_instance_init, + .class_init = ftddrii030_class_init, +}; + +static void ftddrii030_register_types (void ) +{Quoted 8 lines
Quoted 8 lines
hw/ftddrii030.c new file +4
-1+type_register_static (&ftddrii030_info); +} + +type_init (ftddrii030_register_types) --1.7.9.5
--
Best wishes,
Kuo-Jung Su
--
Best wishes,
Kuo-Jung Su
PATCH v9 6/24 hw/arm: add FTPWMTMR010 timer support
In reply to Kuo-Jung SuFrom: Kuo-Jung Su <[email protected]>
The FTPWMTMR010 is an APB device which provides up to 8 independent timers.
--- hw/arm/Makefile.objs | 2 +- hw/arm/ftplat_a369soc.c | 10 ++ hw/ftpwmtmr010.c | 261 +++++++++++++++++++++++++++++++++++++++++++++++ hw/ftpwmtmr010.h | 31 ++++++ 4 files changed, 303 insertions(+), 1 deletion(-) create mode 100644 hw/ftpwmtmr010.c create mode 100644 hw/ftpwmtmr010.h
hw/arm/Makefile.objs +1 -1
@@ -24,7 +24,7 @@ obj-y += framebuffer.o obj-y += strongarm.o obj-y += imx_serial.o imx_ccm.o imx_timer.o imx_avic.o obj-$(CONFIG_KVM) += kvm/arm_gic.o -obj-y += ftintc020.o ftahbc020.o ftddrii030.o +obj-y += ftintc020.o ftahbc020.o ftddrii030.o ftpwmtmr010.o obj-y := $(addprefix ../,$(obj-y))
hw/arm/ftplat_a369soc.c +10 -0
@@ -137,6 +137,16 @@ static void a369soc_chip_init(FaradaySoCState *s)fprintf (stderr,"a369soc: Unable to set soc link for FTDDRII030\n" );abort (); } + +/* Timer */ + ds =qdev_create (NULL ,"ftpwmtmr010" ); +qdev_prop_set_uint32 (ds,"freq" ,66 *1000000 ); +qdev_init_nofail (ds); +sysbus_mmio_map (SYS_BUS_DEVICE (ds),0 ,0x92300000 ); +sysbus_connect_irq (SYS_BUS_DEVICE (ds),0 , s->pic[8 ]); +sysbus_connect_irq (SYS_BUS_DEVICE (ds),1 , s->pic[9 ]); +sysbus_connect_irq (SYS_BUS_DEVICE (ds),2 , s->pic[10 ]); +sysbus_connect_irq (SYS_BUS_DEVICE (ds),3 , s->pic[11 ]); }static void a369soc_realize (DeviceState *dev,Error **errp)
hw/ftpwmtmr010.c new file +261 -0
261 lines not on this page · raw message
hw/ftpwmtmr010.h new file +31 -0
@@ -0,0 +1,31 @@ +/* +* Faraday FTPWMTMR010 Timer. +* +* Copyright (c) 2012 Faraday Technology +* Written by Dante Su <[email protected]> +* +* This code is licensed under GNU GPL v2+. +*/ + +#ifndef HW_ARM_FTPWMTMR010_H +#define HW_ARM_FTPWMTMR010_H + +#include "qemu/bitops.h" + +#define REG_SR 0x00/* status register */ +#define REG_REVR 0x90/* revision register */ + +#define REG_TIMER_BASE (id) (0x00 + ((id) << 4)) +#define REG_TIMER_CTRL 0x00 +#define REG_TIMER_CNTB 0x04 +#define REG_TIMER_CMPB 0x08 +#define REG_TIMER_CNTO 0x0C + +#define TIMER_CTRL_EXTCK BIT(0)/* external clock */ +#define TIMER_CTRL_START BIT(1) +#define TIMER_CTRL_UPDATE BIT(2) +#define TIMER_CTRL_AUTORELOAD BIT(4) +#define TIMER_CTRL_INTR BIT(5)/* interrupt enabled */ +#define TIMER_CTRL_INTR_EDGE BIT(6)/* interrupt type: 1=edge 0=level */ + +#endif
Signature · 1 line
1.7.9.5
PATCH v9 7/24 hw/arm: add FTWDT010 watchdog timer support
In reply to Kuo-Jung SuFrom: Kuo-Jung Su <[email protected]>
The FTWDT010 is used to prevent system from infinite loop while software gets trapped in the deadlock.
Under the normal operation, users should restart FTWDT010 at the regular intervals before counter counts down to 0.
If the counter does reach 0, FTWDT010 will try to reset the system by generating one or a combination of signals, system reset, system interrupt, and external interrupt.
--- hw/arm/Makefile.objs | 2 +- hw/arm/ftplat_a369.c | 8 ++ hw/arm/ftplat_a369soc.c | 3 + hw/ftwdt010.c | 213 +++++++++++++++++++++++++++++++++++++++++++++++ hw/ftwdt010.h | 35 ++++++++ 5 files changed, 260 insertions(+), 1 deletion(-) create mode 100644 hw/ftwdt010.c create mode 100644 hw/ftwdt010.h
hw/arm/Makefile.objs +1 -1
@@ -24,7 +24,7 @@ obj-y += framebuffer.o obj-y += strongarm.o obj-y += imx_serial.o imx_ccm.o imx_timer.o imx_avic.o obj-$(CONFIG_KVM) += kvm/arm_gic.o -obj-y += ftintc020.o ftahbc020.o ftddrii030.o ftpwmtmr010.o +obj-y += ftintc020.o ftahbc020.o ftddrii030.o ftpwmtmr010.o ftwdt010.o obj-y := $(addprefix ../,$(obj-y))
hw/arm/ftplat_a369.c +8 -0
@@ -19,6 +19,11 @@#include "hw/faraday.h" +static void a369_system_reset (void *opaque) +{ +cpu_reset (CPU (opaque)); +} +/* Board init. */ static void a369_board_init (QEMUMachineInitArgs *args)
@@ -57,6 +62,9 @@ static void a369_board_init(QEMUMachineInitArgs *args)vmstate_register_ram_global (s->ram);qdev_init_nofail (ds); +/* Customized system reset */ +qemu_register_reset (a369_system_reset, cpu); +/* System start-up */ if (args->kernel_filename) {
hw/arm/ftplat_a369soc.c +3 -0
@@ -147,6 +147,9 @@ static void a369soc_chip_init(FaradaySoCState *s)sysbus_connect_irq (SYS_BUS_DEVICE (ds),1 , s->pic[9 ]);sysbus_connect_irq (SYS_BUS_DEVICE (ds),2 , s->pic[10 ]);sysbus_connect_irq (SYS_BUS_DEVICE (ds),3 , s->pic[11 ]); + +/* ftwdt010 */ +sysbus_create_simple ("ftwdt010" ,0x92200000 , s->pic[46 ]); }static void a369soc_realize (DeviceState *dev,Error **errp)
hw/ftwdt010.c new file +213 -0
213 lines not on this page · raw message
hw/ftwdt010.h new file +35 -0
@@ -0,0 +1,35 @@ +/* +* QEMU model of the FTWDT010 WatchDog Timer +* +* Copyright (C) 2012 Faraday Technology +* Written by Dante Su <[email protected]> +* +* This file is licensed under GNU GPL v2+. +*/ + +#ifndef HW_ARM_FTWDT010_H +#define HW_ARM_FTWDT010_H + +#include "qemu/bitops.h" + +/* Hardware registers */ +#define REG_COUNTER 0x00/* counter register */ +#define REG_LOAD 0x04/* (re)load register */ +#define REG_RESTART 0x08/* restart register */ +#define REG_CR 0x0C/* control register */ +#define REG_SR 0x10/* status register */ +#define REG_SCR 0x14/* status clear register */ +#define REG_INTR_LEN 0x18/* interrupt length register */ +#define REG_REVR 0x1C/* revision register */ + +#define CR_CLKS BIT(4)/* clock source */ +#define CR_ESIG BIT(3)/* external signal enabled */ +#define CR_INTR BIT(2)/* system reset interrupt enabled */ +#define CR_SRST BIT(1)/* system reset enabled */ +#define CR_EN BIT(0)/* chip enabled */ + +#define SR_SRST BIT(1)/* system reset */ + +#define WDT_MAGIC 0x5ab9/* magic for watchdog restart */ + +#endif
Signature · 1 line
1.7.9.5
PATCH v9 8/24 hw/arm: add FTRTC011 RTC timer support
In reply to Kuo-Jung SuFrom: Kuo-Jung Su <[email protected]>
It provides separate second, minute, hour, and day counters. The second counter is toggled each second, the minute counter is toggled each minute, the hour counter is toggled each hour, and the day counter is toggled each day.
The FTRTC011 provides a programmable auto-alarm function. When the second auto-alarm function is turned on, the RTC will automatically trigger an interrupt each second. The automatic minute and hour alarms can be turned on as well.
--- hw/arm/Makefile.objs | 3 +- hw/arm/ftplat_a369soc.c | 18 +++ hw/ftrtc011.c | 387 +++++++++++++++++++++++++++++++++++++++++++++++ hw/ftrtc011.h | 53 +++++++ 4 files changed, 460 insertions(+), 1 deletion(-) create mode 100644 hw/ftrtc011.c create mode 100644 hw/ftrtc011.h
hw/arm/Makefile.objs +2 -1
@@ -24,7 +24,8 @@ obj-y += framebuffer.o obj-y += strongarm.o obj-y += imx_serial.o imx_ccm.o imx_timer.o imx_avic.o obj-$(CONFIG_KVM) += kvm/arm_gic.o -obj-y += ftintc020.o ftahbc020.o ftddrii030.o ftpwmtmr010.o ftwdt010.o +obj-y += ftintc020.o ftahbc020.o ftddrii030.o ftpwmtmr010.o ftwdt010.o \ + ftrtc011.o obj-y := $(addprefix ../,$(obj-y))
hw/arm/ftplat_a369soc.c +18 -0
@@ -150,6 +150,24 @@ static void a369soc_chip_init(FaradaySoCState *s)/* ftwdt010 */ sysbus_create_simple ("ftwdt010" ,0x92200000 , s->pic[46 ]); + +/* ftrtc011 */ + ds =qdev_create (NULL ,"ftrtc011" ); +/* Setup QOM path for QTest */ +object_property_add_child (OBJECT (s), +"ftrtc011" , +OBJECT (ds), +NULL ); +qdev_init_nofail (ds); +sysbus_mmio_map (SYS_BUS_DEVICE (ds),0 ,0x92100000 ); +/* Alarm (Edge) */ +sysbus_connect_irq (SYS_BUS_DEVICE (ds),1 , s->pic[42 ]); +/* Second (Edge) */ +sysbus_connect_irq (SYS_BUS_DEVICE (ds),2 , s->pic[43 ]); +/* Minute (Edge) */ +sysbus_connect_irq (SYS_BUS_DEVICE (ds),3 , s->pic[44 ]); +/* Hour (Edge) */ +sysbus_connect_irq (SYS_BUS_DEVICE (ds),4 , s->pic[45 ]); }static void a369soc_realize (DeviceState *dev,Error **errp)
hw/ftrtc011.c new file +387 -0
387 lines not on this page · raw message
hw/ftrtc011.h new file +53 -0
53 lines not on this page · raw message
Signature · 1 line
1.7.9.5
PATCH v9 9/24 tests: add QTest for FTRTC011
In reply to Kuo-Jung SuFrom: Kuo-Jung Su <[email protected]>
The FTRTC011 QEMU model is implemented without calender functions. It acts in counter mode only, all the time & timezone conversion relies on the c runtime library. (i.e. mktime(), localtime() ...etc)
--- tests/Makefile | 3 + tests/ftrtc011-test.c | 410 +++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 413 insertions(+) create mode 100644 tests/ftrtc011-test.c
tests/Makefile +3 -0
@@ -75,6 +75,8 @@ gcov-files-sparc-y += hw/m48t59.c gcov-files-sparc64-y += hw/m48t59.c check-qtest-arm-y = tests/tmp105-test$(EXESUF) gcov-files-arm-y += hw/tmp105.c +check-qtest-arm-y = tests/ftrtc011-test$(EXESUF) +gcov-files-arm-y += hw/ftrtc011.c GENERATED_HEADERS += tests/test-qapi-types.h tests/test-qapi-visit.h tests/test-qmp-commands.h
@@ -133,6 +135,7 @@ tests/m48t59-test$(EXESUF): tests/m48t59-test.o tests/fdc-test$(EXESUF): tests/fdc-test.o tests/hd-geo-test$(EXESUF): tests/hd-geo-test.o tests/tmp105-test$(EXESUF): tests/tmp105-test.o +tests/ftrtc011-test$(EXESUF): tests/ftrtc011-test.o # QTest rules
tests/ftrtc011-test.c new file +410 -0
410 lines not on this page · raw message
Signature · 1 line
1.7.9.5
PATCH v9 10/24 hw/arm: add FTDMAC020 AHB DMA support
In reply to Kuo-Jung SuFrom: Kuo-Jung Su <[email protected]>
The Faraday FTDMAC020 provides eight configurable channels for the memory-to-memory, memory-to-peripheral, peripheral-to-peripheral, and peripheral-to-memory transfers.
Each DMA channel supports chain transfer and can be programmed to one of the 16 handshaking channels in the hardware handshake mode.
The main function of the hardware handshake mode is to provide an indication of the device status. Users can also disable the hardware handshake mode by programming the register when a DMA transfer is not necessary of referring to the handshaking channels.
--- hw/arm/Makefile.objs | 2 +- hw/arm/ftplat_a369soc.c | 14 ++ hw/ftdmac020.c | 599 +++++++++++++++++++++++++++++++++++++++++++++++ hw/ftdmac020.h | 107 +++++++++ 4 files changed, 721 insertions(+), 1 deletion(-) create mode 100644 hw/ftdmac020.c create mode 100644 hw/ftdmac020.h
hw/arm/Makefile.objs +1 -1
@@ -25,7 +25,7 @@ obj-y += strongarm.o obj-y += imx_serial.o imx_ccm.o imx_timer.o imx_avic.o obj-$(CONFIG_KVM) += kvm/arm_gic.o obj-y += ftintc020.o ftahbc020.o ftddrii030.o ftpwmtmr010.o ftwdt010.o \ - ftrtc011.o + ftrtc011.o ftdmac020.o obj-y := $(addprefix ../,$(obj-y))
hw/arm/ftplat_a369soc.c +14 -0
@@ -168,6 +168,20 @@ static void a369soc_chip_init(FaradaySoCState *s)sysbus_connect_irq (SYS_BUS_DEVICE (ds),3 , s->pic[44 ]);/* Hour (Edge) */ sysbus_connect_irq (SYS_BUS_DEVICE (ds),4 , s->pic[45 ]); + +/* ftdmac020 */ + s->hdma[0 ] =sysbus_create_varargs ("ftdmac020" , +0x90300000 , + s->pic[0 ],/* ALL (NC in A369) */ + s->pic[15 ],/* TC */ + s->pic[16 ],/* ERR */ +NULL ); + s->hdma[1 ] =sysbus_create_varargs ("ftdmac020" , +0x96100000 , + s->pic[0 ],/* ALL (NC in A369) */ + s->pic[17 ],/* TC */ + s->pic[18 ],/* ERR */ +NULL ); }static void a369soc_realize (DeviceState *dev,Error **errp)
hw/ftdmac020.c new file +599 -0
599 lines not on this page · raw message
hw/ftdmac020.h new file +107 -0
107 lines not on this page · raw message
Signature · 1 line
1.7.9.5
Re: [Qemu-devel] [PATCH v9 10/24] hw/arm: add FTDMAC020 AHB DMA support
Hi Kuo-Jung,
Quoted 232 lines · Kuo-Jung Su
From: Kuo-Jung Su <[email protected]>
The Faraday FTDMAC020 provides eight configurable channels for the memory-to-memory, memory-to-peripheral, peripheral-to-peripheral, and peripheral-to-memory transfers.
Each DMA channel supports chain transfer and can be programmed to one of the 16 handshaking channels in the hardware handshake mode.
The main function of the hardware handshake mode is to provide an indication of the device status. Users can also disable the hardware handshake mode by programming the register when a DMA transfer is not necessary of referring to the handshaking channels.
Signed-off-by Kuo-Jung Su <[email protected]>--- hw/arm/Makefile.objs | 2 +- hw/arm/ftplat_a369soc.c | 14 ++ hw/ftdmac020.c | 599 +++++++++++++++++++++++++++++++++++++++++++++++ hw/ftdmac020.h | 107 +++++++++ 4 files changed, 721 insertions(+), 1 deletion(-) create mode 100644 hw/ftdmac020.c create mode 100644 hw/ftdmac020.hhw/arm/Makefile.objs +1
-1@@ -25,7 +25,7 @@ obj-y += strongarm.o obj-y += imx_serial.o imx_ccm.o imx_timer.o imx_avic.o obj-$(CONFIG_KVM) += kvm/arm_gic.o obj-y += ftintc020.o ftahbc020.o ftddrii030.o ftpwmtmr010.o ftwdt010.o \ - ftrtc011.o + ftrtc011.o ftdmac020.o obj-y := $(addprefix ../,$(obj-y))hw/arm/ftplat_a369soc.c +14
-0@@ -168,6 +168,20 @@ static void a369soc_chip_init(FaradaySoCState *s)sysbus_connect_irq (SYS_BUS_DEVICE (ds),3 , s->pic[44 ]);/* Hour (Edge) */ sysbus_connect_irq (SYS_BUS_DEVICE (ds),4 , s->pic[45 ]); + +/* ftdmac020 */ + s->hdma[0 ] =sysbus_create_varargs ("ftdmac020" , +0x90300000 , + s->pic[0 ],/* ALL (NC in A369) */ + s->pic[15 ],/* TC */ + s->pic[16 ],/* ERR */ +NULL ); + s->hdma[1 ] =sysbus_create_varargs ("ftdmac020" , +0x96100000 , + s->pic[0 ],/* ALL (NC in A369) */ + s->pic[17 ],/* TC */ + s->pic[18 ],/* ERR */ +NULL ); }static void a369soc_realize (DeviceState *dev,Error **errp)hw/ftdmac020.c new file +164
-0@@ -0,0 +1,599 @@ +/* +* QEMU model of the FTDMAC020 DMA Controller +* +* Copyright (C) 2012 Faraday Technology +* Written by Dante Su <[email protected]> +* +* This file is licensed under GNU GPL v2+. +* +* Note: The FTDMAC020 descending address mode is not implemented. +*/ + +#include "hw/sysbus.h" +#include "sysemu/dma.h" +#include "sysemu/sysemu.h" +#include "sysemu/blockdev.h" + +#include "hw/ftdmac020.h" + +#define TYPE_FTDMAC020 "ftdmac020" + +enum ftdmac020_irqpin { +IRQ_ALL =0 , +IRQ_TC , +IRQ_ERR , +}; + +typedef struct Ftdmac020State Ftdmac020State ; + +/** +* struct Ftdmac020LLD - hardware link list descriptor. +* @src: source physical address +* @dst: destination physical addr +* @next: phsical address to the next link list descriptor +* @ctrl: control field +* @size: transfer size +* +* should be word aligned +*/ +typedef struct Ftdmac020LLD { +uint32_t src; +uint32_t dst; +uint32_t next; +uint32_t ctrl; +uint32_t size; +}Ftdmac020LLD ; + +typedef struct Ftdmac020Chan { +Ftdmac020State *chip; + +int id; +int burst; +int llp_cnt; +int src_bw; +int src_stride; +int dst_bw; +int dst_stride; + +/* HW register cache */ +uint32_t ccr; +uint32_t cfg; +uint32_t src; +uint32_t dst; +uint32_t llp; +uint32_t len; +}Ftdmac020Chan ; + +typedef struct Ftdmac020State { +/*< private >*/ +SysBusDevice parent; + +/*< public >*/ +MemoryRegion iomem; +qemu_irq irq[3 ]; + +Ftdmac020Chan chan[8 ]; +qemu_irq ack[16 ]; +uint32_t req; + +int busy;/* Busy Channel ID */ +int bh_owner; +QEMUBH *bh; +DMAContext *dma; + +/* HW register cache */ +uint32_t tcisr; +uint32_t eaisr; +uint32_t tcsr; +uint32_t easr; +uint32_t cesr; +uint32_t cbsr; +uint32_t csr; +uint32_t sync; +}Ftdmac020State ; + +#define FTDMAC020 (obj) \ + OBJECT_CHECK(Ftdmac020State, obj, TYPE_FTDMAC020) + +static void ftdmac020_update_irq (Ftdmac020State *s) +{ +uint32_t tc, err; + +/* 1. Checking TC interrupts */ + tc = s->tcisr &0xff ; +qemu_set_irq (s->irq[IRQ_TC ], tc ?1 :0 ); + +/* 2. Checking Error/Abort interrupts */ + err = s->eaisr &0x00ff00ff ; +qemu_set_irq (s->irq[IRQ_ERR ], err ?1 :0 ); + +/* 3. Checking interrupt summary (TC | Error | Abort) */ +qemu_set_irq (s->irq[IRQ_ALL ], (tc || err) ?1 :0 ); +} + +static void ftdmac020_chan_ccr_decode (Ftdmac020Chan *c) +{ +uint32_t tmp; + +/* 1. decode burst size */ + tmp =extract32 (c->ccr,16 ,3 ); + c->burst =1 << (tmp ? tmp +1 :0 ); + +/* 2. decode source width */ + tmp =extract32 (c->ccr,11 ,2 ); + c->src_bw =8 << tmp; + +/* 3. decode destination width */ + tmp =extract32 (c->ccr,8 ,2 ); + c->dst_bw =8 << tmp; + +/* 4. decode source address stride */ + tmp =extract32 (c->ccr,5 ,2 ); +if (tmp ==2 ) { + c->src_stride =0 ; + }else { + c->src_stride = c->src_bw >>3 ; + } + +/* 5. decode destination address stride */ + tmp =extract32 (c->ccr,3 ,2 ); +if (tmp ==2 ) { + c->dst_stride =0 ; + }else { + c->dst_stride = c->dst_bw >>3 ; + } +} + +static void ftdmac020_chan_start (Ftdmac020Chan *c) +{ +Ftdmac020State *s = c->chip; +Ftdmac020LLD desc; +hwaddr src, dst; + uint8_t buf[4096] __attribute__ ((aligned (8))); +int i, len, stride, src_hs, dst_hs; + +if (!(c->ccr &CCR_START )) { +return ; + } + + s->busy = c->id; + +/* DMA src/dst address */ + src = c->src; + dst = c->dst; +
hw/ftdmac020.c line 174
Quoted 10 lines
hw/ftdmac020.c new file +10
-0+/* DMA hardware handshake id */ + src_hs = (c->cfg &CFG_SRC_HANDSHAKE_EN ) ?extract32 (c->cfg,3 ,4 ) :-1 ; + dst_hs = (c->cfg &CFG_DST_HANDSHAKE_EN ) ?extract32 (c->cfg,9 ,4 ) :-1 ; + +/* DMA src/dst sanity check */ +if (cpu_physical_memory_is_io (src) && c->src_stride) { +fprintf (stderr, +"ftdmac020: src is an I/O device with non-fixed address?\n" ); +abort (); + }
This doesn't look like a QEMU fatal to me. Its seems like software usage policy of the DMA. Does the real hardware actually do any preventative action on striding io accesses? If not then I would either remove this assertion or at least demote it to a LOG_GUEST_ERROR. There may be corner case applications where this is valid. I think its also worthwhile trying to avoid use of cpu_physical_foo() functions from device land.
Quoted 128 lines
hw/ftdmac020.c new file +128
-0+if (cpu_physical_memory_is_io (dst) && c->dst_stride) { +fprintf (stderr, +"ftdmac020: dst is an I/O device with non-fixed address?\n" ); +abort (); + } + +while (c->len >0 ) { +/* +* Postpone this DMA action +* if the corresponding dma request is not asserted +*/ +if ((src_hs >=0 ) && !(s->req &BIT (src_hs))) { +break ; + } +if ((dst_hs >=0 ) && !(s->req &BIT (dst_hs))) { +break ; + } + + len =MIN (sizeof (buf), c->burst * (c->src_bw >>3 )); + +/* load data from source into local buffer */ +if (c->src_stride) { +dma_memory_read (s->dma, src, buf, len); + src += len; + }else { + stride = c->src_bw >>3 ; +for (i =0 ; i < len; i += stride) { +dma_memory_read (s->dma, src, buf + i, stride); + } + } + +/* DMA Hardware Handshake */ +if (src_hs >=0 ) { +qemu_set_irq (s->ack[src_hs],1 ); + } + +/* store data into destination from local buffer */ +if (c->dst_stride) { +dma_memory_write (s->dma, dst, buf, len); + dst += len; + }else { + stride = c->dst_bw >>3 ; +for (i =0 ; i < len; i += stride) { +dma_memory_write (s->dma, dst, buf + i, stride); + } + } + +/* DMA Hardware Handshake */ +if (dst_hs >=0 ) { +qemu_set_irq (s->ack[dst_hs],1 ); + } + +/* update the channel transfer size */ + c->len -= len / (c->src_bw >>3 ); + +if (c->len ==0 ) { +/* update the channel transfer status */ +if (!(c->ccr &CCR_MASK_TC )) { + s->tcsr |=BIT (c->id); +if (!(c->cfg &CFG_MASK_TCI )) { + s->tcisr |=BIT (c->id); + } +ftdmac020_update_irq (s); + } +/* try to load next lld */ +if (c->llp) { + c->llp_cnt +=1 ; +dma_memory_read (s->dma, c->llp, &desc,sizeof (desc)); + + desc.src =le32_to_cpu (desc.src); + desc.dst =le32_to_cpu (desc.dst); + desc.next =le32_to_cpu (desc.next); + desc.size =le32_to_cpu (desc.size); + desc.ctrl =le32_to_cpu (desc.ctrl); + + c->src = desc.src; + c->dst = desc.dst; + c->llp = desc.next &0xfffffffc ; + c->len = desc.size &0x003fffff ; + c->ccr = (c->ccr &0x78f8c081 ) + | (extract32 (desc.ctrl,29 ,3 ) <<24 ) + | ((desc.ctrl &BIT (28 )) ?CCR_MASK_TC :0 ) + | (extract32 (desc.ctrl,25 ,3 ) <<11 ) + | (extract32 (desc.ctrl,22 ,3 ) <<8 ) + | (extract32 (desc.ctrl,20 ,2 ) <<5 ) + | (extract32 (desc.ctrl,18 ,2 ) <<3 ) + | (extract32 (desc.ctrl,16 ,2 ) <<1 ); +ftdmac020_chan_ccr_decode (c); + + src = c->src; + dst = c->dst; + }else { +/* clear dma start bit */ + c->ccr &= ~CCR_START ; + } + } + } + +/* update dma src/dst address */ + c->src = src; + c->dst = dst; + + s->busy =-1 ; +} + +static void ftdmac020_chan_reset (Ftdmac020Chan *c) +{ + c->ccr =0 ; + c->cfg =0 ; + c->src =0 ; + c->dst =0 ; + c->llp =0 ; + c->len =0 ; +} + +static void ftdmac020_bh (void *opaque) +{ +Ftdmac020State *s =FTDMAC020 (opaque); +Ftdmac020Chan *c =NULL ; +int i, jobs, done; + + ++s->bh_owner; + jobs =0 ; + done =0 ; +for (i =0 ; i <8 ; ++i) { + c = s->chan + i; +if (c->ccr &CCR_START ) { + ++jobs;
hw/ftdmac020.c line 312
Quoted 10 lines
hw/ftdmac020.c new file +10
-0+ftdmac020_chan_start (c); +if (!(c->ccr &CCR_START )) { + ++done; + } + } + } + --s->bh_owner; + +/* +* Devices those with an infinite FIFO (always ready for R/W)
Grammar (- the "those"?).
Quoted 5 lines
hw/ftdmac020.c new file +5
-0+* would trigger a new DMA handshake transaction here. +* (i.e. ftnandc021, ftsdc010) +*/ +if ((jobs - done) && s->req) { +qemu_bh_schedule (s->bh);
hw/ftdmac020.c line 327
Quoted 10 lines
hw/ftdmac020.c new file +10
-0+ } +} + +static void ftdmac020_handle_req (void *opaque,int line,int level) +{ +Ftdmac020State *s =FTDMAC020 (opaque); + +if (level) { +/* +* Devices those wait for data from externaI/O
s/those/that
hw/ftdmac020.c line 329
Quoted 2 lines
hw/ftdmac020.c new file +2
-0+* would trigger a new DMA handshake transaction here. +* (i.e. ftssp010)
A nitpick, but do you mean e.g. instead of i.e.?
Regards,
Peter
Quoted 387 lines
hw/ftdmac020.c new file +270
-0+*/ +if (!(s->req &BIT (line))) { +/* a simple workaround for BH reentry issue */ +if (!s->bh_owner) { +qemu_bh_schedule (s->bh); + } + } + s->req |=BIT (line); + }else { + s->req &= ~BIT (line); +qemu_set_irq (s->ack[line],0 ); + } +} + +static void ftdmac020_chip_reset (Ftdmac020State *s) +{ +int i; + + s->tcisr =0 ; + s->eaisr =0 ; + s->tcsr =0 ; + s->easr =0 ; + s->cesr =0 ; + s->cbsr =0 ; + s->csr =0 ; + s->sync =0 ; + +for (i =0 ; i <8 ; ++i) { +ftdmac020_chan_reset (s->chan + i); + } + +/* We can assume our GPIO have been wired up now */ +for (i =0 ; i <16 ; ++i) { +qemu_set_irq (s->ack[i],0 ); + } + s->req =0 ; +} + +static uint64_t ftdmac020_mem_read (void *opaque,hwaddr addr,unsigned size) +{ +Ftdmac020State *s =FTDMAC020 (opaque); +Ftdmac020Chan *c =NULL ; +uint32_t i, ret =0 ; + +switch (addr) { +case REG_ISR : +/* 1. Checking TC interrupts */ + ret |= s->tcisr &0xff ; +/* 2. Checking Error interrupts */ + ret |= s->eaisr &0xff ; +/* 3. Checking Abort interrupts */ + ret |= (s->eaisr >>16 ) &0xff ; +break ; +case REG_TCISR : +return s->tcisr; +case REG_EAISR : +return s->eaisr; +case REG_TCSR : +return s->tcsr; +case REG_EASR : +return s->easr; +case REG_CESR : +for (i =0 ; i <8 ; ++i) { + c = s->chan + i; + ret |= (c->ccr &CCR_START ) ?BIT (i) :0 ; + } +break ; +case REG_CBSR : +return (s->busy >0 ) ?BIT (s->busy) :0 ; +case REG_CSR : +return s->csr; +case REG_SYNC : +return s->sync; +case REG_REVISION : +/* rev. = 1.13.0 */ +return 0x00011300 ; +case REG_FEATURE : +/* fifo = 32 bytes, support linked list, 8 channels, AHB0 only */ +return 0x00008105 ; + case REG_CHAN_BASE(0) ... REG_CHAN_BASE(7) + 0x14: + c = s->chan +REG_CHAN_ID (addr); +switch (addr &0x1f ) { +case REG_CHAN_CCR : +return c->ccr; +case REG_CHAN_CFG : + ret = c->cfg; + ret |= (s->busy == c->id) ? (1 <<8 ) :0 ; + ret |= (c->llp_cnt &0x0f ) <<16 ; +break ; +case REG_CHAN_SRC : +return c->src; +case REG_CHAN_DST : +return c->dst; +case REG_CHAN_LLP : +return c->llp; +case REG_CHAN_LEN : +return c->len; +default : +qemu_log_mask (LOG_GUEST_ERROR , +"ftdmac020: undefined memory access@%#" HWADDR_PRIx"\n" , + addr); +break ; + } +break ; +default : +qemu_log_mask (LOG_GUEST_ERROR , +"ftdmac020: undefined memory access@%#" HWADDR_PRIx"\n" , addr); +break ; + } + +return ret; +} + +static void ftdmac020_mem_write (void *opaque, +hwaddr addr, +uint64_t val, +unsigned size) +{ +Ftdmac020State *s =FTDMAC020 (opaque); +Ftdmac020Chan *c =NULL ; + +switch (addr) { +case REG_TCCLR : + s->tcisr &= ~((uint32_t )val); + s->tcsr &= ~((uint32_t )val); +ftdmac020_update_irq (s); +break ; +case REG_EACLR : + s->eaisr &= ~((uint32_t )val); + s->easr &= ~((uint32_t )val); +ftdmac020_update_irq (s); +break ; +case REG_CSR : + s->csr = (uint32_t )val; +break ; +case REG_SYNC : +/* In QEMU, devices are all in the same clock domain +* so there is nothing needs to be done. +*/ + s->sync = (uint32_t )val; +break ; + case REG_CHAN_BASE(0) ... REG_CHAN_BASE(7) + 0x14: + c = s->chan +REG_CHAN_ID (addr); +switch (addr &0x1f ) { +case REG_CHAN_CCR : +if (!(c->ccr &CCR_START ) && (val &CCR_START )) { + c->llp_cnt =0 ; + } + c->ccr = (uint32_t )val &0x87FFBFFF ; +if (c->ccr &CCR_START ) { +ftdmac020_chan_ccr_decode (c); +/* kick-off DMA engine */ +qemu_bh_schedule (s->bh); + } +break ; +case REG_CHAN_CFG : + c->cfg = (uint32_t )val &0x3eff ; +break ; +case REG_CHAN_SRC : + c->src = (uint32_t )val; +break ; +case REG_CHAN_DST : + c->dst = (uint32_t )val; +break ; +case REG_CHAN_LLP : + c->llp = (uint32_t )val &0xfffffffc ; +break ; +case REG_CHAN_LEN : + c->len = (uint32_t )val &0x003fffff ; +break ; +default : +qemu_log_mask (LOG_GUEST_ERROR , +"ftdmac020: undefined memory access@%#" HWADDR_PRIx"\n" , + addr); +break ; + } +break ; +default : +qemu_log_mask (LOG_GUEST_ERROR , +"ftdmac020: undefined memory access@%#" HWADDR_PRIx"\n" , addr); +break ; + } +} + +static const MemoryRegionOps mmio_ops = { + .read = ftdmac020_mem_read, + .write = ftdmac020_mem_write, + .endianness =DEVICE_LITTLE_ENDIAN , + .valid = { + .min_access_size =4 , + .max_access_size =4 + } +}; + +static void ftdmac020_reset (DeviceState *ds) +{ +Ftdmac020State *s =FTDMAC020 (SYS_BUS_DEVICE (ds)); + +ftdmac020_chip_reset (s); +} + +static void ftdmac020_realize (DeviceState *dev,Error **errp) +{ +Ftdmac020State *s =FTDMAC020 (dev); +SysBusDevice *sbd =SYS_BUS_DEVICE (dev); +int i; + +memory_region_init_io (&s->iomem, + &mmio_ops, + s, +TYPE_FTDMAC020 , +0x1000 ); +sysbus_init_mmio (sbd, &s->iomem); +for (i =0 ; i <3 ; ++i) { +sysbus_init_irq (sbd, &s->irq[i]); + } +qdev_init_gpio_in (&sbd->qdev, ftdmac020_handle_req,16 ); +qdev_init_gpio_out (&sbd->qdev, s->ack,16 ); + + s->busy =-1 ; + s->dma = &dma_context_memory; + s->bh =qemu_bh_new (ftdmac020_bh, s); +for (i =0 ; i <8 ; ++i) { +Ftdmac020Chan *c = s->chan + i; + c->id = i; + c->chip = s; + } +} + +static const VMStateDescription vmstate_ftdmac020 = { + .name =TYPE_FTDMAC020 , + .version_id =1 , + .minimum_version_id =1 , + .minimum_version_id_old =1 , + .fields = (VMStateField []) { +VMSTATE_UINT32 (tcisr, Ftdmac020State), +VMSTATE_UINT32 (eaisr, Ftdmac020State), +VMSTATE_UINT32 (tcsr, Ftdmac020State), +VMSTATE_UINT32 (easr, Ftdmac020State), +VMSTATE_UINT32 (cesr, Ftdmac020State), +VMSTATE_UINT32 (cbsr, Ftdmac020State), +VMSTATE_UINT32 (csr, Ftdmac020State), +VMSTATE_UINT32 (sync, Ftdmac020State), +VMSTATE_END_OF_LIST () + } +}; + +static void ftdmac020_class_init (ObjectClass *klass,void *data) +{ +DeviceClass *dc =DEVICE_CLASS (klass); + + dc->vmsd = &vmstate_ftdmac020; + dc->reset = ftdmac020_reset; + dc->realize = ftdmac020_realize; + dc->no_user =1 ; +} + +static const TypeInfo ftdmac020_info = { + .name =TYPE_FTDMAC020 , + .parent =TYPE_SYS_BUS_DEVICE , + .instance_size =sizeof (Ftdmac020State), + .class_init = ftdmac020_class_init, +}; + +static void ftdmac020_register_types (void ) +{ +type_register_static (&ftdmac020_info); +} + +type_init (ftdmac020_register_types)hw/ftdmac020.h new file +107
-1@@ -0,0 +1,107 @@ +/* +* QEMU model of the FTDMAC020 DMA Controller +* +* Copyright (C) 2012 Faraday Technology +* Written by Dante Su <[email protected]> +* +* This file is licensed under GNU GPL v2+. +* +* Note: The FTDMAC020 decreasing address mode is not implemented. +*/ + +#ifndef HW_ARM_FTDMAC020_H +#define HW_ARM_FTDMAC020_H + +#include "qemu/bitops.h" + +#define REG_ISR 0x00/* Interrupt Status Register */ +#define REG_TCISR 0x04/* Terminal Count Interrupt Status Register */ +#define REG_TCCLR 0x08/* Terminal Count Status Clear Register */ +#define REG_EAISR 0x0c/* Error/Abort Interrupt Status Register */ +#define REG_EACLR 0x10/* Error/Abort Status Clear Register */ +#define REG_TCSR 0x14/* Terminal Count Status Register */ +#define REG_EASR 0x18/* Error/Abort Status Register */ +#define REG_CESR 0x1c/* Channel Enable Status Register */ +#define REG_CBSR 0x20/* Channel Busy Status Register */ +#define REG_CSR 0x24/* Configuration Status Register */ +#define REG_SYNC 0x28/* Synchronization Register */ +#define REG_REVISION 0x30 +#define REG_FEATURE 0x34 + +#define REG_CHAN_ID (addr) (((addr) - 0x100) >> 5) +#define REG_CHAN_BASE (ch) (0x100 + ((ch) << 5)) + +#define REG_CHAN_CCR 0x00 +#define REG_CHAN_CFG 0x04 +#define REG_CHAN_SRC 0x08 +#define REG_CHAN_DST 0x0C +#define REG_CHAN_LLP 0x10 +#define REG_CHAN_LEN 0x14 + +/* +* Feature register +*/ +#define FEATURE_NCHAN (f) (((f) >> 12) & 0xF) +#define FEATURE_BRIDGE (f) ((f) & BIT(10)) +#define FEATURE_DUALBUS (f) ((f) & BIT(9)) +#define FEATURE_LLP (f) ((f) & BIT(8)) +#define FEATURE_FIFOAW (f) ((f) & 0xF) + +/* +* Channel control register +*/ +#define CCR_START BIT(0) +#define CCR_DST_M1 BIT(1)/* dst is a slave device of AHB1 */ +#define CCR_SRC_M1 BIT(2)/* src is a slave device of AHB1 */ +#define CCR_DST_INC (0 << 3)/* dst addr: next = curr++ */ +#define CCR_DST_DEC (1 << 3)/* dst addr: next = curr-- */ +#define CCR_DST_FIXED (2 << 3) +#define CCR_SRC_INC (0 << 5)/* src addr: next = curr++ */ +#define CCR_SRC_DEC (1 << 5)/* src addr: next = curr-- */ +#define CCR_SRC_FIXED (2 << 5) +#define CCR_HANDSHAKE BIT(7)/* DMA HW handshake enabled */ +#define CCR_DST_WIDTH_8 (0 << 8) +#define CCR_DST_WIDTH_16 (1 << 8) +#define CCR_DST_WIDTH_32 (2 << 8) +#define CCR_DST_WIDTH_64 (3 << 8) +#define CCR_SRC_WIDTH_8 (0 << 11) +#define CCR_SRC_WIDTH_16 (1 << 11) +#define CCR_SRC_WIDTH_32 (2 << 11) +#define CCR_SRC_WIDTH_64 (3 << 11) +#define CCR_ABORT BIT(15) +#define CCR_BURST_1 (0 << 16) +#define CCR_BURST_4 (1 << 16) +#define CCR_BURST_8 (2 << 16) +#define CCR_BURST_16 (3 << 16) +#define CCR_BURST_32 (4 << 16) +#define CCR_BURST_64 (5 << 16) +#define CCR_BURST_128 (6 << 16) +#define CCR_BURST_256 (7 << 16) +#define CCR_PRIVILEGED BIT(19) +#define CCR_BUFFERABLE BIT(20) +#define CCR_CACHEABLE BIT(21) +#define CCR_PRIO_0 (0 << 22) +#define CCR_PRIO_1 (1 << 22) +#define CCR_PRIO_2 (2 << 22) +#define CCR_PRIO_3 (3 << 22) +#define CCR_FIFOTH_1 (0 << 24) +#define CCR_FIFOTH_2 (1 << 24) +#define CCR_FIFOTH_4 (2 << 24) +#define CCR_FIFOTH_8 (3 << 24) +#define CCR_FIFOTH_16 (4 << 24) +#define CCR_MASK_TC BIT(31)/* DMA Transfer terminated(finished) */ + +/* +* Channel configuration register +*/ +#define CFG_MASK_TCI BIT(0)/* disable tc interrupt */ +#define CFG_MASK_EI BIT(1)/* disable error interrupt */ +#define CFG_MASK_AI BIT(2)/* disable abort interrupt */ +#define CFG_SRC_HANDSHAKE (x) (((x) & 0xf) << 3) +#define CFG_SRC_HANDSHAKE_EN BIT(7) +#define CFG_BUSY BIT(8) +#define CFG_DST_HANDSHAKE (x) (((x) & 0xf) << 9) +#define CFG_DST_HANDSHAKE_EN BIT(13) +#define CFG_LLP_CNT (cfg) (((cfg) >> 16) & 0xf) + +#endif /* HW_ARM_FTDMAC020_H */ --1.7.9.5
Re: [Qemu-devel] [PATCH v9 10/24] hw/arm: add FTDMAC020 AHB DMA support
2013/3/29 Peter Crosthwaite <[email protected]>:
Quoted 246 lines
Hi Kuo-Jung,
Quoted 232 lines · Kuo-Jung Su
From: Kuo-Jung Su <[email protected]>
The Faraday FTDMAC020 provides eight configurable channels for the memory-to-memory, memory-to-peripheral, peripheral-to-peripheral, and peripheral-to-memory transfers.
Each DMA channel supports chain transfer and can be programmed to one of the 16 handshaking channels in the hardware handshake mode.
The main function of the hardware handshake mode is to provide an indication of the device status. Users can also disable the hardware handshake mode by programming the register when a DMA transfer is not necessary of referring to the handshaking channels.
Signed-off-by Kuo-Jung Su <[email protected]>--- hw/arm/Makefile.objs | 2 +- hw/arm/ftplat_a369soc.c | 14 ++ hw/ftdmac020.c | 599 +++++++++++++++++++++++++++++++++++++++++++++++ hw/ftdmac020.h | 107 +++++++++ 4 files changed, 721 insertions(+), 1 deletion(-) create mode 100644 hw/ftdmac020.c create mode 100644 hw/ftdmac020.hhw/arm/Makefile.objs +1
-1@@ -25,7 +25,7 @@ obj-y += strongarm.o obj-y += imx_serial.o imx_ccm.o imx_timer.o imx_avic.o obj-$(CONFIG_KVM) += kvm/arm_gic.o obj-y += ftintc020.o ftahbc020.o ftddrii030.o ftpwmtmr010.o ftwdt010.o \ - ftrtc011.o + ftrtc011.o ftdmac020.o obj-y := $(addprefix ../,$(obj-y))hw/arm/ftplat_a369soc.c +14
-0@@ -168,6 +168,20 @@ static void a369soc_chip_init(FaradaySoCState *s)sysbus_connect_irq (SYS_BUS_DEVICE (ds),3 , s->pic[44 ]);/* Hour (Edge) */ sysbus_connect_irq (SYS_BUS_DEVICE (ds),4 , s->pic[45 ]); + +/* ftdmac020 */ + s->hdma[0 ] =sysbus_create_varargs ("ftdmac020" , +0x90300000 , + s->pic[0 ],/* ALL (NC in A369) */ + s->pic[15 ],/* TC */ + s->pic[16 ],/* ERR */ +NULL ); + s->hdma[1 ] =sysbus_create_varargs ("ftdmac020" , +0x96100000 , + s->pic[0 ],/* ALL (NC in A369) */ + s->pic[17 ],/* TC */ + s->pic[18 ],/* ERR */ +NULL ); }static void a369soc_realize (DeviceState *dev,Error **errp)hw/ftdmac020.c new file +164
-0@@ -0,0 +1,599 @@ +/* +* QEMU model of the FTDMAC020 DMA Controller +* +* Copyright (C) 2012 Faraday Technology +* Written by Dante Su <[email protected]> +* +* This file is licensed under GNU GPL v2+. +* +* Note: The FTDMAC020 descending address mode is not implemented. +*/ + +#include "hw/sysbus.h" +#include "sysemu/dma.h" +#include "sysemu/sysemu.h" +#include "sysemu/blockdev.h" + +#include "hw/ftdmac020.h" + +#define TYPE_FTDMAC020 "ftdmac020" + +enum ftdmac020_irqpin { +IRQ_ALL =0 , +IRQ_TC , +IRQ_ERR , +}; + +typedef struct Ftdmac020State Ftdmac020State ; + +/** +* struct Ftdmac020LLD - hardware link list descriptor. +* @src: source physical address +* @dst: destination physical addr +* @next: phsical address to the next link list descriptor +* @ctrl: control field +* @size: transfer size +* +* should be word aligned +*/ +typedef struct Ftdmac020LLD { +uint32_t src; +uint32_t dst; +uint32_t next; +uint32_t ctrl; +uint32_t size; +}Ftdmac020LLD ; + +typedef struct Ftdmac020Chan { +Ftdmac020State *chip; + +int id; +int burst; +int llp_cnt; +int src_bw; +int src_stride; +int dst_bw; +int dst_stride; + +/* HW register cache */ +uint32_t ccr; +uint32_t cfg; +uint32_t src; +uint32_t dst; +uint32_t llp; +uint32_t len; +}Ftdmac020Chan ; + +typedef struct Ftdmac020State { +/*< private >*/ +SysBusDevice parent; + +/*< public >*/ +MemoryRegion iomem; +qemu_irq irq[3 ]; + +Ftdmac020Chan chan[8 ]; +qemu_irq ack[16 ]; +uint32_t req; + +int busy;/* Busy Channel ID */ +int bh_owner; +QEMUBH *bh; +DMAContext *dma; + +/* HW register cache */ +uint32_t tcisr; +uint32_t eaisr; +uint32_t tcsr; +uint32_t easr; +uint32_t cesr; +uint32_t cbsr; +uint32_t csr; +uint32_t sync; +}Ftdmac020State ; + +#define FTDMAC020 (obj) \ + OBJECT_CHECK(Ftdmac020State, obj, TYPE_FTDMAC020) + +static void ftdmac020_update_irq (Ftdmac020State *s) +{ +uint32_t tc, err; + +/* 1. Checking TC interrupts */ + tc = s->tcisr &0xff ; +qemu_set_irq (s->irq[IRQ_TC ], tc ?1 :0 ); + +/* 2. Checking Error/Abort interrupts */ + err = s->eaisr &0x00ff00ff ; +qemu_set_irq (s->irq[IRQ_ERR ], err ?1 :0 ); + +/* 3. Checking interrupt summary (TC | Error | Abort) */ +qemu_set_irq (s->irq[IRQ_ALL ], (tc || err) ?1 :0 ); +} + +static void ftdmac020_chan_ccr_decode (Ftdmac020Chan *c) +{ +uint32_t tmp; + +/* 1. decode burst size */ + tmp =extract32 (c->ccr,16 ,3 ); + c->burst =1 << (tmp ? tmp +1 :0 ); + +/* 2. decode source width */ + tmp =extract32 (c->ccr,11 ,2 ); + c->src_bw =8 << tmp; + +/* 3. decode destination width */ + tmp =extract32 (c->ccr,8 ,2 ); + c->dst_bw =8 << tmp; + +/* 4. decode source address stride */ + tmp =extract32 (c->ccr,5 ,2 ); +if (tmp ==2 ) { + c->src_stride =0 ; + }else { + c->src_stride = c->src_bw >>3 ; + } + +/* 5. decode destination address stride */ + tmp =extract32 (c->ccr,3 ,2 ); +if (tmp ==2 ) { + c->dst_stride =0 ; + }else { + c->dst_stride = c->dst_bw >>3 ; + } +} + +static void ftdmac020_chan_start (Ftdmac020Chan *c) +{ +Ftdmac020State *s = c->chip; +Ftdmac020LLD desc; +hwaddr src, dst; + uint8_t buf[4096] __attribute__ ((aligned (8))); +int i, len, stride, src_hs, dst_hs; + +if (!(c->ccr &CCR_START )) { +return ; + } + + s->busy = c->id; + +/* DMA src/dst address */ + src = c->src; + dst = c->dst; +hw/ftdmac020.c line 174
Quoted 10 lines
hw/ftdmac020.c new file +10
-0+/* DMA hardware handshake id */ + src_hs = (c->cfg &CFG_SRC_HANDSHAKE_EN ) ?extract32 (c->cfg,3 ,4 ) :-1 ; + dst_hs = (c->cfg &CFG_DST_HANDSHAKE_EN ) ?extract32 (c->cfg,9 ,4 ) :-1 ; + +/* DMA src/dst sanity check */ +if (cpu_physical_memory_is_io (src) && c->src_stride) { +fprintf (stderr, +"ftdmac020: src is an I/O device with non-fixed address?\n" ); +abort (); + }
Quoted 8 lines
This doesn't look like a QEMU fatal to me. Its seems like software usage policy of the DMA. Does the real hardware actually do any preventative action on striding io accesses? If not then I would either remove this assertion or at least demote it to a
LOG_GUEST_ERROR. There may be corner case applications where this is valid. I think its also worthwhile trying to avoid use ofcpu_physical_foo()functions from device land.
It's a programming error, which is used to identify possible bug in driver. And I'll remove this sanity check in next release.
,>> + if (cpu_physical_memory_is_io(dst) && c->dst_stride) {
Quoted 131 lines
Quoted 131 lines
hw/ftdmac020.c new file +131
-0+fprintf (stderr, +"ftdmac020: dst is an I/O device with non-fixed address?\n" ); +abort (); + } + +while (c->len >0 ) { +/* +* Postpone this DMA action +* if the corresponding dma request is not asserted +*/ +if ((src_hs >=0 ) && !(s->req &BIT (src_hs))) { +break ; + } +if ((dst_hs >=0 ) && !(s->req &BIT (dst_hs))) { +break ; + } + + len =MIN (sizeof (buf), c->burst * (c->src_bw >>3 )); + +/* load data from source into local buffer */ +if (c->src_stride) { +dma_memory_read (s->dma, src, buf, len); + src += len; + }else { + stride = c->src_bw >>3 ; +for (i =0 ; i < len; i += stride) { +dma_memory_read (s->dma, src, buf + i, stride); + } + } + +/* DMA Hardware Handshake */ +if (src_hs >=0 ) { +qemu_set_irq (s->ack[src_hs],1 ); + } + +/* store data into destination from local buffer */ +if (c->dst_stride) { +dma_memory_write (s->dma, dst, buf, len); + dst += len; + }else { + stride = c->dst_bw >>3 ; +for (i =0 ; i < len; i += stride) { +dma_memory_write (s->dma, dst, buf + i, stride); + } + } + +/* DMA Hardware Handshake */ +if (dst_hs >=0 ) { +qemu_set_irq (s->ack[dst_hs],1 ); + } + +/* update the channel transfer size */ + c->len -= len / (c->src_bw >>3 ); + +if (c->len ==0 ) { +/* update the channel transfer status */ +if (!(c->ccr &CCR_MASK_TC )) { + s->tcsr |=BIT (c->id); +if (!(c->cfg &CFG_MASK_TCI )) { + s->tcisr |=BIT (c->id); + } +ftdmac020_update_irq (s); + } +/* try to load next lld */ +if (c->llp) { + c->llp_cnt +=1 ; +dma_memory_read (s->dma, c->llp, &desc,sizeof (desc)); + + desc.src =le32_to_cpu (desc.src); + desc.dst =le32_to_cpu (desc.dst); + desc.next =le32_to_cpu (desc.next); + desc.size =le32_to_cpu (desc.size); + desc.ctrl =le32_to_cpu (desc.ctrl); + + c->src = desc.src; + c->dst = desc.dst; + c->llp = desc.next &0xfffffffc ; + c->len = desc.size &0x003fffff ; + c->ccr = (c->ccr &0x78f8c081 ) + | (extract32 (desc.ctrl,29 ,3 ) <<24 ) + | ((desc.ctrl &BIT (28 )) ?CCR_MASK_TC :0 ) + | (extract32 (desc.ctrl,25 ,3 ) <<11 ) + | (extract32 (desc.ctrl,22 ,3 ) <<8 ) + | (extract32 (desc.ctrl,20 ,2 ) <<5 ) + | (extract32 (desc.ctrl,18 ,2 ) <<3 ) + | (extract32 (desc.ctrl,16 ,2 ) <<1 ); +ftdmac020_chan_ccr_decode (c); + + src = c->src; + dst = c->dst; + }else { +/* clear dma start bit */ + c->ccr &= ~CCR_START ; + } + } + } + +/* update dma src/dst address */ + c->src = src; + c->dst = dst; + + s->busy =-1 ; +} + +static void ftdmac020_chan_reset (Ftdmac020Chan *c) +{ + c->ccr =0 ; + c->cfg =0 ; + c->src =0 ; + c->dst =0 ; + c->llp =0 ; + c->len =0 ; +} + +static void ftdmac020_bh (void *opaque) +{ +Ftdmac020State *s =FTDMAC020 (opaque); +Ftdmac020Chan *c =NULL ; +int i, jobs, done; + + ++s->bh_owner; + jobs =0 ; + done =0 ; +for (i =0 ; i <8 ; ++i) { + c = s->chan + i; +if (c->ccr &CCR_START ) { + ++jobs; +ftdmac020_chan_start (c); +if (!(c->ccr &CCR_START )) { + ++done; + }
Quoted 9 lines
hw/ftdmac020.c line 312
Quoted 6 lines
hw/ftdmac020.c new file +6
-0+ } + } + --s->bh_owner; + +/* +* Devices those with an infinite FIFO (always ready for R/W) Grammar (- the "those"?).
Awkward, now you know my English really sucks. :P
Quoted 18 lines
Quoted 5 lines
hw/ftdmac020.c new file +5
-0+* would trigger a new DMA handshake transaction here. +* (i.e. ftnandc021, ftsdc010) +*/ +if ((jobs - done) && s->req) { +qemu_bh_schedule (s->bh);hw/ftdmac020.c line 327
Quoted 10 lines
hw/ftdmac020.c new file +10
-0+ } +} + +static void ftdmac020_handle_req (void *opaque,int line,int level) +{ +Ftdmac020State *s =FTDMAC020 (opaque); + +if (level) { +/* +* Devices those wait for data from externaI/O s/those/that
Quoted 5 lines
hw/ftdmac020.c line 328
Quoted 2 lines
hw/ftdmac020.c new file +2
-0+* would trigger a new DMA handshake transaction here. +* (i.e. ftssp010) A nitpick, but do you mean e.g. instead of i.e.?
Both, because FTSSP010 is the only one would trigger DMA in that way.
Quoted 382 lines
Regards,
PeterQuoted 379 lines
hw/ftdmac020.c new file +270
-0+*/ +if (!(s->req &BIT (line))) { +/* a simple workaround for BH reentry issue */ +if (!s->bh_owner) { +qemu_bh_schedule (s->bh); + } + } + s->req |=BIT (line); + }else { + s->req &= ~BIT (line); +qemu_set_irq (s->ack[line],0 ); + } +} + +static void ftdmac020_chip_reset (Ftdmac020State *s) +{ +int i; + + s->tcisr =0 ; + s->eaisr =0 ; + s->tcsr =0 ; + s->easr =0 ; + s->cesr =0 ; + s->cbsr =0 ; + s->csr =0 ; + s->sync =0 ; + +for (i =0 ; i <8 ; ++i) { +ftdmac020_chan_reset (s->chan + i); + } + +/* We can assume our GPIO have been wired up now */ +for (i =0 ; i <16 ; ++i) { +qemu_set_irq (s->ack[i],0 ); + } + s->req =0 ; +} + +static uint64_t ftdmac020_mem_read (void *opaque,hwaddr addr,unsigned size) +{ +Ftdmac020State *s =FTDMAC020 (opaque); +Ftdmac020Chan *c =NULL ; +uint32_t i, ret =0 ; + +switch (addr) { +case REG_ISR : +/* 1. Checking TC interrupts */ + ret |= s->tcisr &0xff ; +/* 2. Checking Error interrupts */ + ret |= s->eaisr &0xff ; +/* 3. Checking Abort interrupts */ + ret |= (s->eaisr >>16 ) &0xff ; +break ; +case REG_TCISR : +return s->tcisr; +case REG_EAISR : +return s->eaisr; +case REG_TCSR : +return s->tcsr; +case REG_EASR : +return s->easr; +case REG_CESR : +for (i =0 ; i <8 ; ++i) { + c = s->chan + i; + ret |= (c->ccr &CCR_START ) ?BIT (i) :0 ; + } +break ; +case REG_CBSR : +return (s->busy >0 ) ?BIT (s->busy) :0 ; +case REG_CSR : +return s->csr; +case REG_SYNC : +return s->sync; +case REG_REVISION : +/* rev. = 1.13.0 */ +return 0x00011300 ; +case REG_FEATURE : +/* fifo = 32 bytes, support linked list, 8 channels, AHB0 only */ +return 0x00008105 ; + case REG_CHAN_BASE(0) ... REG_CHAN_BASE(7) + 0x14: + c = s->chan +REG_CHAN_ID (addr); +switch (addr &0x1f ) { +case REG_CHAN_CCR : +return c->ccr; +case REG_CHAN_CFG : + ret = c->cfg; + ret |= (s->busy == c->id) ? (1 <<8 ) :0 ; + ret |= (c->llp_cnt &0x0f ) <<16 ; +break ; +case REG_CHAN_SRC : +return c->src; +case REG_CHAN_DST : +return c->dst; +case REG_CHAN_LLP : +return c->llp; +case REG_CHAN_LEN : +return c->len; +default : +qemu_log_mask (LOG_GUEST_ERROR , +"ftdmac020: undefined memory access@%#" HWADDR_PRIx"\n" , + addr); +break ; + } +break ; +default : +qemu_log_mask (LOG_GUEST_ERROR , +"ftdmac020: undefined memory access@%#" HWADDR_PRIx"\n" , addr); +break ; + } + +return ret; +} + +static void ftdmac020_mem_write (void *opaque, +hwaddr addr, +uint64_t val, +unsigned size) +{ +Ftdmac020State *s =FTDMAC020 (opaque); +Ftdmac020Chan *c =NULL ; + +switch (addr) { +case REG_TCCLR : + s->tcisr &= ~((uint32_t )val); + s->tcsr &= ~((uint32_t )val); +ftdmac020_update_irq (s); +break ; +case REG_EACLR : + s->eaisr &= ~((uint32_t )val); + s->easr &= ~((uint32_t )val); +ftdmac020_update_irq (s); +break ; +case REG_CSR : + s->csr = (uint32_t )val; +break ; +case REG_SYNC : +/* In QEMU, devices are all in the same clock domain +* so there is nothing needs to be done. +*/ + s->sync = (uint32_t )val; +break ; + case REG_CHAN_BASE(0) ... REG_CHAN_BASE(7) + 0x14: + c = s->chan +REG_CHAN_ID (addr); +switch (addr &0x1f ) { +case REG_CHAN_CCR : +if (!(c->ccr &CCR_START ) && (val &CCR_START )) { + c->llp_cnt =0 ; + } + c->ccr = (uint32_t )val &0x87FFBFFF ; +if (c->ccr &CCR_START ) { +ftdmac020_chan_ccr_decode (c); +/* kick-off DMA engine */ +qemu_bh_schedule (s->bh); + } +break ; +case REG_CHAN_CFG : + c->cfg = (uint32_t )val &0x3eff ; +break ; +case REG_CHAN_SRC : + c->src = (uint32_t )val; +break ; +case REG_CHAN_DST : + c->dst = (uint32_t )val; +break ; +case REG_CHAN_LLP : + c->llp = (uint32_t )val &0xfffffffc ; +break ; +case REG_CHAN_LEN : + c->len = (uint32_t )val &0x003fffff ; +break ; +default : +qemu_log_mask (LOG_GUEST_ERROR , +"ftdmac020: undefined memory access@%#" HWADDR_PRIx"\n" , + addr); +break ; + } +break ; +default : +qemu_log_mask (LOG_GUEST_ERROR , +"ftdmac020: undefined memory access@%#" HWADDR_PRIx"\n" , addr); +break ; + } +} + +static const MemoryRegionOps mmio_ops = { + .read = ftdmac020_mem_read, + .write = ftdmac020_mem_write, + .endianness =DEVICE_LITTLE_ENDIAN , + .valid = { + .min_access_size =4 , + .max_access_size =4 + } +}; + +static void ftdmac020_reset (DeviceState *ds) +{ +Ftdmac020State *s =FTDMAC020 (SYS_BUS_DEVICE (ds)); + +ftdmac020_chip_reset (s); +} + +static void ftdmac020_realize (DeviceState *dev,Error **errp) +{ +Ftdmac020State *s =FTDMAC020 (dev); +SysBusDevice *sbd =SYS_BUS_DEVICE (dev); +int i; + +memory_region_init_io (&s->iomem, + &mmio_ops, + s, +TYPE_FTDMAC020 , +0x1000 ); +sysbus_init_mmio (sbd, &s->iomem); +for (i =0 ; i <3 ; ++i) { +sysbus_init_irq (sbd, &s->irq[i]); + } +qdev_init_gpio_in (&sbd->qdev, ftdmac020_handle_req,16 ); +qdev_init_gpio_out (&sbd->qdev, s->ack,16 ); + + s->busy =-1 ; + s->dma = &dma_context_memory; + s->bh =qemu_bh_new (ftdmac020_bh, s); +for (i =0 ; i <8 ; ++i) { +Ftdmac020Chan *c = s->chan + i; + c->id = i; + c->chip = s; + } +} + +static const VMStateDescription vmstate_ftdmac020 = { + .name =TYPE_FTDMAC020 , + .version_id =1 , + .minimum_version_id =1 , + .minimum_version_id_old =1 , + .fields = (VMStateField []) { +VMSTATE_UINT32 (tcisr, Ftdmac020State), +VMSTATE_UINT32 (eaisr, Ftdmac020State), +VMSTATE_UINT32 (tcsr, Ftdmac020State), +VMSTATE_UINT32 (easr, Ftdmac020State), +VMSTATE_UINT32 (cesr, Ftdmac020State), +VMSTATE_UINT32 (cbsr, Ftdmac020State), +VMSTATE_UINT32 (csr, Ftdmac020State), +VMSTATE_UINT32 (sync, Ftdmac020State), +VMSTATE_END_OF_LIST () + } +}; + +static void ftdmac020_class_init (ObjectClass *klass,void *data) +{ +DeviceClass *dc =DEVICE_CLASS (klass); + + dc->vmsd = &vmstate_ftdmac020; + dc->reset = ftdmac020_reset; + dc->realize = ftdmac020_realize; + dc->no_user =1 ; +} + +static const TypeInfo ftdmac020_info = { + .name =TYPE_FTDMAC020 , + .parent =TYPE_SYS_BUS_DEVICE , + .instance_size =sizeof (Ftdmac020State), + .class_init = ftdmac020_class_init, +}; + +static void ftdmac020_register_types (void ) +{ +type_register_static (&ftdmac020_info); +} + +type_init (ftdmac020_register_types)hw/ftdmac020.h new file +103
-0@@ -0,0 +1,107 @@ +/* +* QEMU model of the FTDMAC020 DMA Controller +* +* Copyright (C) 2012 Faraday Technology +* Written by Dante Su <[email protected]> +* +* This file is licensed under GNU GPL v2+. +* +* Note: The FTDMAC020 decreasing address mode is not implemented. +*/ + +#ifndef HW_ARM_FTDMAC020_H +#define HW_ARM_FTDMAC020_H + +#include "qemu/bitops.h" + +#define REG_ISR 0x00/* Interrupt Status Register */ +#define REG_TCISR 0x04/* Terminal Count Interrupt Status Register */ +#define REG_TCCLR 0x08/* Terminal Count Status Clear Register */ +#define REG_EAISR 0x0c/* Error/Abort Interrupt Status Register */ +#define REG_EACLR 0x10/* Error/Abort Status Clear Register */ +#define REG_TCSR 0x14/* Terminal Count Status Register */ +#define REG_EASR 0x18/* Error/Abort Status Register */ +#define REG_CESR 0x1c/* Channel Enable Status Register */ +#define REG_CBSR 0x20/* Channel Busy Status Register */ +#define REG_CSR 0x24/* Configuration Status Register */ +#define REG_SYNC 0x28/* Synchronization Register */ +#define REG_REVISION 0x30 +#define REG_FEATURE 0x34 + +#define REG_CHAN_ID (addr) (((addr) - 0x100) >> 5) +#define REG_CHAN_BASE (ch) (0x100 + ((ch) << 5)) + +#define REG_CHAN_CCR 0x00 +#define REG_CHAN_CFG 0x04 +#define REG_CHAN_SRC 0x08 +#define REG_CHAN_DST 0x0C +#define REG_CHAN_LLP 0x10 +#define REG_CHAN_LEN 0x14 + +/* +* Feature register +*/ +#define FEATURE_NCHAN (f) (((f) >> 12) & 0xF) +#define FEATURE_BRIDGE (f) ((f) & BIT(10)) +#define FEATURE_DUALBUS (f) ((f) & BIT(9)) +#define FEATURE_LLP (f) ((f) & BIT(8)) +#define FEATURE_FIFOAW (f) ((f) & 0xF) + +/* +* Channel control register +*/ +#define CCR_START BIT(0) +#define CCR_DST_M1 BIT(1)/* dst is a slave device of AHB1 */ +#define CCR_SRC_M1 BIT(2)/* src is a slave device of AHB1 */ +#define CCR_DST_INC (0 << 3)/* dst addr: next = curr++ */ +#define CCR_DST_DEC (1 << 3)/* dst addr: next = curr-- */ +#define CCR_DST_FIXED (2 << 3) +#define CCR_SRC_INC (0 << 5)/* src addr: next = curr++ */ +#define CCR_SRC_DEC (1 << 5)/* src addr: next = curr-- */ +#define CCR_SRC_FIXED (2 << 5) +#define CCR_HANDSHAKE BIT(7)/* DMA HW handshake enabled */ +#define CCR_DST_WIDTH_8 (0 << 8) +#define CCR_DST_WIDTH_16 (1 << 8) +#define CCR_DST_WIDTH_32 (2 << 8) +#define CCR_DST_WIDTH_64 (3 << 8) +#define CCR_SRC_WIDTH_8 (0 << 11) +#define CCR_SRC_WIDTH_16 (1 << 11) +#define CCR_SRC_WIDTH_32 (2 << 11) +#define CCR_SRC_WIDTH_64 (3 << 11) +#define CCR_ABORT BIT(15) +#define CCR_BURST_1 (0 << 16) +#define CCR_BURST_4 (1 << 16) +#define CCR_BURST_8 (2 << 16) +#define CCR_BURST_16 (3 << 16) +#define CCR_BURST_32 (4 << 16) +#define CCR_BURST_64 (5 << 16) +#define CCR_BURST_128 (6 << 16) +#define CCR_BURST_256 (7 << 16) +#define CCR_PRIVILEGED BIT(19) +#define CCR_BUFFERABLE BIT(20) +#define CCR_CACHEABLE BIT(21) +#define CCR_PRIO_0 (0 << 22) +#define CCR_PRIO_1 (1 << 22) +#define CCR_PRIO_2 (2 << 22) +#define CCR_PRIO_3 (3 << 22) +#define CCR_FIFOTH_1 (0 << 24) +#define CCR_FIFOTH_2 (1 << 24) +#define CCR_FIFOTH_4 (2 << 24) +#define CCR_FIFOTH_8 (3 << 24) +#define CCR_FIFOTH_16 (4 << 24) +#define CCR_MASK_TC BIT(31)/* DMA Transfer terminated(finished) */ + +/* +* Channel configuration register +*/ +#define CFG_MASK_TCI BIT(0)/* disable tc interrupt */ +#define CFG_MASK_EI BIT(1)/* disable error interrupt */ +#define CFG_MASK_AI BIT(2)/* disable abort interrupt */ +#define CFG_SRC_HANDSHAKE (x) (((x) & 0xf) << 3) +#define CFG_SRC_HANDSHAKE_EN BIT(7) +#define CFG_BUSY BIT(8) +#define CFG_DST_HANDSHAKE (x) (((x) & 0xf) << 9)
Quoted 8 lines
Quoted 8 lines
hw/ftdmac020.h new file +4
-1+#define CFG_DST_HANDSHAKE_EN BIT(13) +#define CFG_LLP_CNT (cfg) (((cfg) >> 16) & 0xf) + +#endif /* HW_ARM_FTDMAC020_H */ --1.7.9.5
--
Best wishes,
Kuo-Jung Su
PATCH v9 11/24 hw/arm: add FTAPBBRG020 APB DMA support
In reply to Kuo-Jung SuFrom: Kuo-Jung Su <[email protected]>
The FTAPBBRG020 supports the DMA functions for the AHB-to-AHB, AHB-to-APB, APB-to-AHB, and APB-to-APB transactions.
The DMA engine can support up to 4 DMA channels (A, B, C, and D) and 15 handshaking channels. A DMA channel granted by the arbiter block is the only channel starts transfers. Each DMA channel can be programmed to one of the 15 handshaking channels in the hardware handshake mode to act as the source device or act as the destination device.
The main function of the hardware handshake mode is to provide an indication of the device status. Users can also disable the hardware handshake mode by programming the register when a DMA transfer is not necessary of referring to the handshaking channels.
--- hw/arm/Makefile.objs | 2 +- hw/arm/ftplat_a369soc.c | 9 + hw/ftapbbrg020.c | 478 +++++++++++++++++++++++++++++++++++++++++++++++ hw/ftapbbrg020.h | 44 +++++ 4 files changed, 532 insertions(+), 1 deletion(-) create mode 100644 hw/ftapbbrg020.c create mode 100644 hw/ftapbbrg020.h
hw/arm/Makefile.objs +1 -1
@@ -25,7 +25,7 @@ obj-y += strongarm.o obj-y += imx_serial.o imx_ccm.o imx_timer.o imx_avic.o obj-$(CONFIG_KVM) += kvm/arm_gic.o obj-y += ftintc020.o ftahbc020.o ftddrii030.o ftpwmtmr010.o ftwdt010.o \ - ftrtc011.o ftdmac020.o + ftrtc011.o ftdmac020.o ftapbbrg020.o obj-y := $(addprefix ../,$(obj-y))
hw/arm/ftplat_a369soc.c +9 -0
@@ -182,6 +182,15 @@ static void a369soc_chip_init(FaradaySoCState *s) s->pic[17 ],/* TC */ s->pic[18 ],/* ERR */ NULL); + +/* ftapbbrg020 */ + ds =sysbus_create_simple ("ftapbbrg020" ,0x90f00000 , s->pic[14 ]); + s->pdma[0 ] = ds; +object_property_set_link (OBJECT (ds),OBJECT (s),"soc" , &local_errp); +if (local_errp) { +fprintf (stderr,"a369soc: Unable to set soc link for FTAPBBRG020\n" ); +abort (); + } }static void a369soc_realize (DeviceState *dev,Error **errp)
hw/ftapbbrg020.c new file +478 -0
478 lines not on this page · raw message
hw/ftapbbrg020.h new file +44 -0
44 lines not on this page · raw message
Signature · 1 line
1.7.9.5
PATCH v9 12/24 hw/arm: add FTNANDC021 nand flash controller support
In reply to Kuo-Jung SuFrom: Kuo-Jung Su <[email protected]>
The FTNANDC021 is an integrated NAND flash controller which re-pack the NAND flash command set with a shorter built-in opcode. It also provides a register base interface for user to easily access the underlying NAND flash chips, and also supports HW ECC.
However the optional hardware ECC function is not implemented.
--- hw/arm/Makefile.objs | 2 +- hw/arm/ftplat_a369.c | 14 ++ hw/arm/ftplat_a369soc.c | 9 + hw/ftnandc021.c | 526 +++++++++++++++++++++++++++++++++++++++++++++++ hw/ftnandc021.h | 84 ++++++++ 5 files changed, 634 insertions(+), 1 deletion(-) create mode 100644 hw/ftnandc021.c create mode 100644 hw/ftnandc021.h
hw/arm/Makefile.objs +1 -1
@@ -25,7 +25,7 @@ obj-y += strongarm.o obj-y += imx_serial.o imx_ccm.o imx_timer.o imx_avic.o obj-$(CONFIG_KVM) += kvm/arm_gic.o obj-y += ftintc020.o ftahbc020.o ftddrii030.o ftpwmtmr010.o ftwdt010.o \ - ftrtc011.o ftdmac020.o ftapbbrg020.o + ftrtc011.o ftdmac020.o ftapbbrg020.o ftnandc021.o obj-y := $(addprefix ../,$(obj-y))
hw/arm/ftplat_a369.c +14 -0
@@ -31,6 +31,8 @@ static void a369_board_init(QEMUMachineInitArgs *args)ARMCPU *cpu;DeviceState *ds;FaradaySoCState *s; +DriveInfo *dinfo; +Error *local_errp =NULL ;if (!args->cpu_model) { args->cpu_model ="fa626te" ;
@@ -65,6 +67,18 @@ static void a369_board_init(QEMUMachineInitArgs *args)/* Customized system reset */ qemu_register_reset (a369_system_reset, cpu); +/* Attach the nand flash to ftnandc021 */ + dinfo =drive_get_next (IF_MTD ); + ds =nand_init (dinfo ? dinfo->bdrv :NULL ,NAND_MFR_SAMSUNG ,0xda ); +object_property_set_link (OBJECT (s->nandc[0 ]), +OBJECT (ds), +"flash" , + &local_errp); +if (local_errp) { +fprintf (stderr,"a369: Unable to set flash link for FTNANDC021\n" ); +abort (); + } +/* System start-up */ if (args->kernel_filename) {
hw/arm/ftplat_a369soc.c +9 -0
@@ -54,6 +54,7 @@ static void a369soc_chip_init(FaradaySoCState *s)int i;DeviceState *ds;DriveInfo *dinfo; +qemu_irq ack, req;Error *local_errp =NULL ;/* Remappable Memory Region Init */
@@ -191,6 +192,14 @@ static void a369soc_chip_init(FaradaySoCState *s)fprintf (stderr,"a369soc: Unable to set soc link for FTAPBBRG020\n" );abort (); } + +/* ftnandc021 */ + ds =sysbus_create_simple ("ftnandc021" ,0x90200000 , s->pic[30 ]); + s->nandc[0 ] = ds; + ack =qdev_get_gpio_in (ds,0 ); + req =qdev_get_gpio_in (s->hdma[0 ],15 ); +qdev_connect_gpio_out (s->hdma[0 ],15 , ack); +qdev_connect_gpio_out (ds,0 , req); }static void a369soc_realize (DeviceState *dev,Error **errp)
hw/ftnandc021.c new file +526 -0
526 lines not on this page · raw message
hw/ftnandc021.h new file +84 -0
84 lines not on this page · raw message
Signature · 1 line
1.7.9.5
PATCH v9 13/24 hw/arm: add FTI2C010 I2C controller support
In reply to Kuo-Jung SuFrom: Kuo-Jung Su <[email protected]>
The FTI2C010 is a simple I2C master controller.
--- hw/arm/Makefile.objs | 2 +- hw/arm/ftplat_a369soc.c | 6 ++ hw/fti2c010.c | 224 +++++++++++++++++++++++++++++++++++++++++++++++ hw/fti2c010.h | 74 ++++++++++++++++ 4 files changed, 305 insertions(+), 1 deletion(-) create mode 100644 hw/fti2c010.c create mode 100644 hw/fti2c010.h
hw/arm/Makefile.objs +1 -1
@@ -25,7 +25,7 @@ obj-y += strongarm.o obj-y += imx_serial.o imx_ccm.o imx_timer.o imx_avic.o obj-$(CONFIG_KVM) += kvm/arm_gic.o obj-y += ftintc020.o ftahbc020.o ftddrii030.o ftpwmtmr010.o ftwdt010.o \ - ftrtc011.o ftdmac020.o ftapbbrg020.o ftnandc021.o + ftrtc011.o ftdmac020.o ftapbbrg020.o ftnandc021.o fti2c010.o obj-y := $(addprefix ../,$(obj-y))
hw/arm/ftplat_a369soc.c +6 -0
@@ -200,6 +200,12 @@ static void a369soc_chip_init(FaradaySoCState *s) req =qdev_get_gpio_in (s->hdma[0 ],15 );qdev_connect_gpio_out (s->hdma[0 ],15 , ack);qdev_connect_gpio_out (ds,0 , req); + +/* fti2c010 */ + ds =sysbus_create_simple ("fti2c010" ,0x92900000 , s->pic[51 ]); + s->i2c[0 ] = ds; + ds =sysbus_create_simple ("fti2c010" ,0x92A00000 , s->pic[52 ]); + s->i2c[1 ] = ds; }static void a369soc_realize (DeviceState *dev,Error **errp)
hw/fti2c010.c new file +224 -0
224 lines not on this page · raw message
hw/fti2c010.h new file +74 -0
74 lines not on this page · raw message
Signature · 1 line
1.7.9.5
PATCH v9 14/24 hw: Add AudioCodecClass for wm87xx audio class abstration.
In reply to Kuo-Jung SuFrom: Kuo-Jung Su <[email protected]>
--- hw/Makefile.objs | 1 + hw/arm/spitz.c | 9 +++-- hw/arm/z2.c | 9 +++-- hw/audio.c | 81 +++++++++++++++++++++++++++++++++++++++ hw/audio.h | 56 +++++++++++++++++++++++++++ hw/i2c.h | 9 ----- hw/marvell_88w8618_audio.c | 23 +++++++---- hw/wm8750.c | 91 ++++++++++++++++++++++---------------------- 8 files changed, 211 insertions(+), 68 deletions(-) create mode 100644 hw/audio.c create mode 100644 hw/audio.h
hw/Makefile.objs +1 -0
@@ -168,6 +168,7 @@ common-obj-$(CONFIG_REALLY_VIRTFS) += 9pfs/ common-obj-y += usb/ common-obj-$(CONFIG_PTIMER) += ptimer.o common-obj-$(CONFIG_MAX7310) += max7310.o +common-obj-y += audio.o common-obj-$(CONFIG_WM8750) += wm8750.o common-obj-$(CONFIG_TWL92230) += twl92230.o common-obj-$(CONFIG_TSC2005) += tsc2005.o
hw/arm/spitz.c +6 -3
@@ -24,6 +24,7 @@#include "ui/console.h" #include "block/block.h" #include "audio/audio.h" +#include "hw/audio.h" #include "hw/boards.h" #include "sysemu/blockdev.h" #include "hw/sysbus.h"
@@ -739,9 +740,11 @@ static void spitz_i2c_setup(PXA2xxState *cpu) qemu_allocate_irqs(spitz_wm8750_addr, wm, 1)[0]);/* .. and to the sound interface. */ cpu->i2s->opaque = wm; - cpu->i2s->codec_out = wm8750_dac_dat; - cpu->i2s->codec_in = wm8750_adc_dat; -wm8750_data_req_set (wm, cpu->i2s->data_req, cpu->i2s); + cpu->i2s->codec_out = audio_codec_dac_dat; + cpu->i2s->codec_in = audio_codec_adc_dat; +audio_codec_data_req_set (DEVICE (wm), + cpu->i2s->data_req, + cpu->i2s); }static void spitz_akita_i2c_setup (PXA2xxState *cpu)
hw/arm/z2.c +6 -3
@@ -23,6 +23,7 @@#include "sysemu/blockdev.h" #include "ui/console.h" #include "audio/audio.h" +#include "hw/audio.h" #include "exec/address-spaces.h" #ifdef DEBUG_Z2
@@ -353,9 +354,11 @@ static void z2_init(QEMUMachineInitArgs *args)i2c_create_slave (bus,"aer915" ,0x55 ); wm =i2c_create_slave (bus,"wm8750" ,0x1b ); mpu->i2s->opaque = wm; - mpu->i2s->codec_out = wm8750_dac_dat; - mpu->i2s->codec_in = wm8750_adc_dat; -wm8750_data_req_set (wm, mpu->i2s->data_req, mpu->i2s); + mpu->i2s->codec_out = audio_codec_dac_dat; + mpu->i2s->codec_in = audio_codec_adc_dat; +audio_codec_data_req_set (DEVICE (wm), + mpu->i2s->data_req, + mpu->i2s);qdev_connect_gpio_out (mpu->gpio,Z2_GPIO_LCD_CS ,qemu_allocate_irqs (z2_lcd_cs, z2_lcd,1 )[0 ]);
hw/audio.c new file +81 -0
81 lines not on this page · raw message
hw/audio.h new file +56 -0
56 lines not on this page · raw message
hw/i2c.h +0 -9
@@ -63,15 +63,6 @@ int i2c_recv(i2c_bus *bus);DeviceState *i2c_create_slave (i2c_bus *bus,const char *name,uint8_t addr); -/* wm8750.c */ -void wm8750_data_req_set (DeviceState *dev, -void (*data_req)(void *,int ,int ),void *opaque); -void wm8750_dac_dat (void *opaque,uint32_t sample); -uint32_t wm8750_adc_dat (void *opaque); -void *wm8750_dac_buffer (void *opaque,int samples); -void wm8750_dac_commit (void *opaque); -void wm8750_set_bclk_in (void *opaque,int new_hz); -/* lm832x.c */ void lm832x_key_event (DeviceState *dev,int key,int state);
hw/marvell_88w8618_audio.c +15 -8
@@ -13,6 +13,7 @@#include "hw/hw.h" #include "hw/i2c.h" #include "hw/sysbus.h" +#include "hw/audio.h" #include "audio/audio.h" #define MP_AUDIO_SIZE 0x00001000
@@ -82,32 +83,36 @@ static void mv88w8618_audio_callback(void *opaque, int free_out, int free_in) mem_buffer = buf;if (s->playback_mode &MP_AUDIO_16BIT_SAMPLE ) {if (s->playback_mode &MP_AUDIO_MONO ) { - codec_buffer =wm8750_dac_buffer (s->wm, block_size >>1 ); + codec_buffer =audio_codec_dac_buffer (AUDIO_CODEC (s->wm), + block_size >>1 );for (pos =0 ; pos < block_size; pos +=2 ) { *codec_buffer++ = *(int16_t *)mem_buffer; *codec_buffer++ = *(int16_t *)mem_buffer; mem_buffer +=2 ; } }else { -memcpy (wm8750_dac_buffer (s->wm, block_size >>2 ), - (uint32_t *)mem_buffer, block_size); +memcpy (audio_codec_dac_buffer (AUDIO_CODEC (s->wm), + block_size >>2 ), + (uint32_t *)mem_buffer, + block_size); } }else {if (s->playback_mode &MP_AUDIO_MONO ) { - codec_buffer =wm8750_dac_buffer (s->wm, block_size); + codec_buffer =audio_codec_dac_buffer (s->wm, block_size);for (pos =0 ; pos < block_size; pos++) { *codec_buffer++ =cpu_to_le16 (256 * *mem_buffer); *codec_buffer++ =cpu_to_le16 (256 * *mem_buffer++); } }else { - codec_buffer =wm8750_dac_buffer (s->wm, block_size >>1 ); + codec_buffer =audio_codec_dac_buffer (AUDIO_CODEC (s->wm), + block_size >>1 );for (pos =0 ; pos < block_size; pos +=2 ) { *codec_buffer++ =cpu_to_le16 (256 * *mem_buffer++); *codec_buffer++ =cpu_to_le16 (256 * *mem_buffer++); } } } -wm8750_dac_commit (s->wm); +audio_codec_dac_commit (AUDIO_CODEC (s->wm)); s->last_free = free_out - block_size;
@@ -135,7 +140,7 @@ static void mv88w8618_audio_clock_update(mv88w8618_audio_state *s) } rate /= ((s->clock_div >>8 ) &0xff ) +1 ; -wm8750_set_bclk_in (s->wm, rate); +audio_codec_set_bclk_in (AUDIO_CODEC (s->wm), rate); } static uint64_t mv88w8618_audio_read(void *opaque, hwaddr offset,
@@ -244,7 +249,9 @@ static int mv88w8618_audio_init(SysBusDevice *dev)sysbus_init_irq (dev, &s->irq); -wm8750_data_req_set (s->wm, mv88w8618_audio_callback, s); +audio_codec_data_req_set (DEVICE (s->wm), + mv88w8618_audio_callback, + s);memory_region_init_io (&s->iomem, &mv88w8618_audio_ops, s,"audio" ,MP_AUDIO_SIZE );
hw/wm8750.c +46 -45
247 lines not on this page · raw message
Signature · 1 line
1.7.9.5
PATCH v9 15/24 hw: add WM8731 audio codec support
In reply to Kuo-Jung SuFrom: Kuo-Jung Su <[email protected]>
Wolfson WM8731 is a simple audio codec for embedded systems. It has 2 input and 1 output ports:
** Input **
1. Linue-In
2. Microphone
** Output **
1. Headphone out
BTW it's based on hw/wm8750.c with 16-bit I2S support by default.
--- default-configs/arm-softmmu.mak | 1 + hw/Makefile.objs | 1 + hw/wm8731.c | 505 +++++++++++++++++++++++++++++++++++++++ 3 files changed, 507 insertions(+) create mode 100644 hw/wm8731.c
default-configs/arm-softmmu.mak +1 -0
@@ -11,6 +11,7 @@ CONFIG_SERIAL=y CONFIG_PTIMER=y CONFIG_SD=y CONFIG_MAX7310=y +CONFIG_WM8731=y CONFIG_WM8750=y CONFIG_TWL92230=y CONFIG_TSC2005=y
hw/Makefile.objs +1 -0
@@ -169,6 +169,7 @@ common-obj-y += usb/ common-obj-$(CONFIG_PTIMER) += ptimer.o common-obj-$(CONFIG_MAX7310) += max7310.o common-obj-y += audio.o +common-obj-$(CONFIG_WM8731) += wm8731.o common-obj-$(CONFIG_WM8750) += wm8750.o common-obj-$(CONFIG_TWL92230) += twl92230.o common-obj-$(CONFIG_TSC2005) += tsc2005.o
hw/wm8731.c new file +505 -0
505 lines not on this page · raw message
Signature · 1 line
1.7.9.5
PATCH v9 16/24 The FTSSP010 is a multi-function synchronous serial port interface controller which supports SSP, SPI, I2S, AC97 and SPDIF.
In reply to Kuo-Jung SuFrom: Kuo-Jung Su <[email protected]>
Only I2S and SPI protocol have been implemented in this patch.
--- hw/arm/Makefile.objs | 3 +- hw/arm/ftplat_a369.c | 31 +++ hw/arm/ftplat_a369soc.c | 17 ++ hw/faraday.h | 3 + hw/ftssp010.c | 504 +++++++++++++++++++++++++++++++++++++++++++++++ hw/ftssp010.h | 96 +++++++++ 6 files changed, 653 insertions(+), 1 deletion(-) create mode 100644 hw/ftssp010.c create mode 100644 hw/ftssp010.h
hw/arm/Makefile.objs +2 -1
@@ -25,7 +25,8 @@ obj-y += strongarm.o obj-y += imx_serial.o imx_ccm.o imx_timer.o imx_avic.o obj-$(CONFIG_KVM) += kvm/arm_gic.o obj-y += ftintc020.o ftahbc020.o ftddrii030.o ftpwmtmr010.o ftwdt010.o \ - ftrtc011.o ftdmac020.o ftapbbrg020.o ftnandc021.o fti2c010.o + ftrtc011.o ftdmac020.o ftapbbrg020.o ftnandc021.o fti2c010.o \ + ftssp010.o obj-y := $(addprefix ../,$(obj-y))
hw/arm/ftplat_a369.c +31 -0
@@ -11,6 +11,7 @@#include "hw/arm-misc.h" #include "hw/devices.h" #include "hw/i2c.h" +#include "hw/audio.h" #include "hw/boards.h" #include "hw/ssi.h" #include "net/net.h"
@@ -28,6 +29,7 @@ static void a369_system_reset(void *opaque)static void a369_board_init (QEMUMachineInitArgs *args) { +int i, nr_flash;ARMCPU *cpu;DeviceState *ds;FaradaySoCState *s;
@@ -79,6 +81,35 @@ static void a369_board_init(QEMUMachineInitArgs *args)abort (); } +/* Attach the spi flash to ftssp010.0 */ + nr_flash =1 ; +for (i =0 ; i < nr_flash; i++) { +SSIBus *ssi = (SSIBus *)qdev_get_child_bus (s->spi[0 ],"spi" ); +DeviceState *fl =ssi_create_slave_no_init (ssi,"w25q64" ); +qemu_irq cs_line; + +qdev_init_nofail (fl); + cs_line =qdev_get_gpio_in (fl,0 ); +sysbus_connect_irq (SYS_BUS_DEVICE (s->spi[0 ]), i +1 , cs_line); + } + +/* Attach the wm8731 to fti2c010.0 & ftssp010.0 */ +for (i =0 ; i <1 ; ++i) { +i2c_bus *i2c = (i2c_bus *)qdev_get_child_bus (s->i2c[0 ],"i2c" ); + ds =i2c_create_slave (i2c,"wm8731" ,0x1B ); +object_property_set_link (OBJECT (s->i2s[0 ]), +OBJECT (ds), +"codec" , + &local_errp); +if (local_errp) { +fprintf (stderr,"a369: Unable to set codec link for FTSSP010\n" ); +abort (); + } +audio_codec_data_req_set (ds, + ftssp010_i2s_data_req, + s->i2s[0 ]); + } +/* System start-up */ if (args->kernel_filename) {
hw/arm/ftplat_a369soc.c +17 -0
@@ -206,6 +206,23 @@ static void a369soc_chip_init(FaradaySoCState *s) s->i2c[0 ] = ds; ds =sysbus_create_simple ("fti2c010" ,0x92A00000 , s->pic[52 ]); s->i2c[1 ] = ds; + +/* ftssp010 */ + ds =sysbus_create_simple ("ftssp010" ,0x92700000 , s->pic[49 ]); + s->spi[0 ] = ds; + s->i2s[0 ] = ds; + +/* ftssp010 - DMA (Tx) */ + ack =qdev_get_gpio_in (ds,0 ); + req =qdev_get_gpio_in (s->pdma[0 ],7 ); +qdev_connect_gpio_out (s->pdma[0 ],7 , ack); +qdev_connect_gpio_out (ds,0 , req); + +/* ftssp010 - DMA (Rx) */ + ack =qdev_get_gpio_in (ds,1 ); + req =qdev_get_gpio_in (s->pdma[0 ],8 ); +qdev_connect_gpio_out (s->pdma[0 ],8 , ack); +qdev_connect_gpio_out (ds,1 , req); }static void a369soc_realize (DeviceState *dev,Error **errp)
hw/faraday.h +3 -0
@@ -121,4 +121,7 @@ static inline void faraday_soc_ahb_remap(FaradaySoCState *s, bool active) } } +/* ftssp010.c */ +void ftssp010_i2s_data_req (void *opaque,int tx,int rx); +#endif
hw/ftssp010.c new file +504 -0
504 lines not on this page · raw message
hw/ftssp010.h new file +96 -0
96 lines not on this page · raw message
Signature · 1 line
1.7.9.5
Re: [Qemu-devel] [PATCH v9 16/24] The FTSSP010 is a multi-function synchronous serial port interface controller which supports SSP, SPI, I2S, AC97 and SPDIF.
Hi Kuo-Jung
I think you may have accidentally dropped your subject line and promoted your long commit message to subject line. Looks better in previous versions.
Quoted 167 lines · Kuo-Jung Su
From: Kuo-Jung Su <[email protected]>
Only I2S and SPI protocol have been implemented in this patch.
Signed-off-by Kuo-Jung Su <[email protected]>--- hw/arm/Makefile.objs | 3 +- hw/arm/ftplat_a369.c | 31 +++ hw/arm/ftplat_a369soc.c | 17 ++ hw/faraday.h | 3 + hw/ftssp010.c | 504 +++++++++++++++++++++++++++++++++++++++++++++++ hw/ftssp010.h | 96 +++++++++ 6 files changed, 653 insertions(+), 1 deletion(-) create mode 100644 hw/ftssp010.c create mode 100644 hw/ftssp010.hhw/arm/Makefile.objs +2
-1@@ -25,7 +25,8 @@ obj-y += strongarm.o obj-y += imx_serial.o imx_ccm.o imx_timer.o imx_avic.o obj-$(CONFIG_KVM) += kvm/arm_gic.o obj-y += ftintc020.o ftahbc020.o ftddrii030.o ftpwmtmr010.o ftwdt010.o \ - ftrtc011.o ftdmac020.o ftapbbrg020.o ftnandc021.o fti2c010.o + ftrtc011.o ftdmac020.o ftapbbrg020.o ftnandc021.o fti2c010.o \ + ftssp010.o obj-y := $(addprefix ../,$(obj-y))hw/arm/ftplat_a369.c +31
-0@@ -11,6 +11,7 @@#include "hw/arm-misc.h" #include "hw/devices.h" #include "hw/i2c.h" +#include "hw/audio.h" #include "hw/boards.h" #include "hw/ssi.h" #include "net/net.h" @@ -28,6 +29,7 @@ static void a369_system_reset(void *opaque)static void a369_board_init (QEMUMachineInitArgs *args) { +int i, nr_flash;ARMCPU *cpu;DeviceState *ds;FaradaySoCState *s;@@ -79,6 +81,35 @@ static void a369_board_init(QEMUMachineInitArgs *args)abort (); } +/* Attach the spi flash to ftssp010.0 */ + nr_flash =1 ; +for (i =0 ; i < nr_flash; i++) { +SSIBus *ssi = (SSIBus *)qdev_get_child_bus (s->spi[0 ],"spi" ); +DeviceState *fl =ssi_create_slave_no_init (ssi,"w25q64" ); +qemu_irq cs_line; + +qdev_init_nofail (fl); + cs_line =qdev_get_gpio_in (fl,0 ); +sysbus_connect_irq (SYS_BUS_DEVICE (s->spi[0 ]), i +1 , cs_line); + } + +/* Attach the wm8731 to fti2c010.0 & ftssp010.0 */ +for (i =0 ; i <1 ; ++i) { +i2c_bus *i2c = (i2c_bus *)qdev_get_child_bus (s->i2c[0 ],"i2c" ); + ds =i2c_create_slave (i2c,"wm8731" ,0x1B ); +object_property_set_link (OBJECT (s->i2s[0 ]), +OBJECT (ds), +"codec" , + &local_errp); +if (local_errp) { +fprintf (stderr,"a369: Unable to set codec link for FTSSP010\n" ); +abort (); + } +audio_codec_data_req_set (ds, + ftssp010_i2s_data_req, + s->i2s[0 ]); + } +/* System start-up */ if (args->kernel_filename) {hw/arm/ftplat_a369soc.c +17
-0@@ -206,6 +206,23 @@ static void a369soc_chip_init(FaradaySoCState *s) s->i2c[0 ] = ds; ds =sysbus_create_simple ("fti2c010" ,0x92A00000 , s->pic[52 ]); s->i2c[1 ] = ds; + +/* ftssp010 */ + ds =sysbus_create_simple ("ftssp010" ,0x92700000 , s->pic[49 ]); + s->spi[0 ] = ds; + s->i2s[0 ] = ds; + +/* ftssp010 - DMA (Tx) */ + ack =qdev_get_gpio_in (ds,0 ); + req =qdev_get_gpio_in (s->pdma[0 ],7 ); +qdev_connect_gpio_out (s->pdma[0 ],7 , ack); +qdev_connect_gpio_out (ds,0 , req); + +/* ftssp010 - DMA (Rx) */ + ack =qdev_get_gpio_in (ds,1 ); + req =qdev_get_gpio_in (s->pdma[0 ],8 ); +qdev_connect_gpio_out (s->pdma[0 ],8 , ack); +qdev_connect_gpio_out (ds,1 , req); }static void a369soc_realize (DeviceState *dev,Error **errp)hw/faraday.h +3
-0@@ -121,4 +121,7 @@ static inline void faraday_soc_ahb_remap(FaradaySoCState *s, bool active) } } +/* ftssp010.c */ +void ftssp010_i2s_data_req (void *opaque,int tx,int rx); +#endif hw/ftssp010.c new file +34
-0@@ -0,0 +1,504 @@ +/* +* QEMU model of the FTSSP010 Controller +* +* Copyright (C) 2012 Faraday Technology +* Written by Dante Su <[email protected]> +* +* This file is licensed under GNU GPL v2+. +*/ + +#include "hw/sysbus.h" +#include "hw/i2c.h" +#include "hw/ssi.h" +#include "hw/audio.h" +#include "sysemu/sysemu.h" +#include "qemu/fifo8.h" + +#include "hw/faraday.h" +#include "hw/ftssp010.h" + +#define CFG_FIFO_DEPTH 16 + +#define TYPE_FTSSP010 "ftssp010" + +typedef struct Ftssp010State { + /*< private >*/ + SysBusDevice parent; + + /*< public >*/ + MemoryRegion mmio; + + qemu_irq irq; + SSIBus *spi; + AudioCodecState *codec; +
hw/ftssp010.c line 44
Quoted 10 lines
hw/ftssp010.c new file +10
-0+uint8_t num_cs; +qemu_irq *cs_lines; + +Fifo8 rx_fifo; +Fifo8 tx_fifo; + +uint8_t tx_thres; +uint8_t rx_thres; + +int busy;
Constant 0 AFAICT. Every set of busy to 1 is followed by a clear before fn return. I cannot see a code path where anyone reads busy as 1? If there is such a code path then busy should be part of the VMSD as well.
hw/ftssp010.c line 51
Quoted 7 lines
hw/ftssp010.c new file +7
-0+uint8_t bw; + +/* DMA hardware handshake */ +qemu_irq req[2 ];/* 0 - Tx, 1 - Rx */ + +/* HW register caches */ +
Are they really caches?
Quoted 247 lines
hw/ftssp010.c new file +247
-0+uint32_t cr0; +uint32_t cr1; +uint32_t cr2; +uint32_t icr;/* interrupt control register */ +uint32_t isr;/* interrupt status register */ + +} Ftssp010State; + +#define FTSSP010 (obj) \ + OBJECT_CHECK(Ftssp010State, obj, TYPE_FTSSP010) + +/* Update interrupts. */ +static void ftssp010_update (Ftssp010State *s) +{ +if (!(s->cr2 &CR2_SSPEN )) { +return ; + } + +/* tx fifo status update */ +if ((s->tx_fifo.num / (s->bw >>3 )) <= s->tx_thres) { + s->isr |=ISR_TFTHI ; +if (s->icr &ICR_TFDMA ) { +qemu_set_irq (s->req[0 ],1 ); + } + }else { + s->isr &= ~ISR_TFTHI ; + } + +/* rx fifo status update */ +switch (s->cr0 &CR0_FFMT_MASK ) { +case CR0_FFMT_SPI : + s->isr |=ISR_RFTHI ; +if (s->icr &ICR_RFDMA ) { +qemu_set_irq (s->req[1 ],1 ); + } +break ; +default : +if ((s->rx_fifo.num / (s->bw >>3 )) >= s->rx_thres) { + s->isr |=ISR_RFTHI ; +if (s->icr &ICR_RFDMA ) { +qemu_set_irq (s->req[1 ],1 ); + } + }else { + s->isr &= ~ISR_RFTHI ; + } +break ; + } + +/* update the interrupt signal */ +qemu_set_irq (s->irq, (s->icr & s->isr) ?1 :0 ); +} + +static void ftssp010_handle_ack (void *opaque,int line,int level) +{ +Ftssp010State *s =FTSSP010 (opaque); + +switch (line) { +case 0 :/* Tx */ +if (s->icr &ICR_TFDMA ) { +if (level) { +qemu_set_irq (s->req[0 ],0 ); + }else if ((s->tx_fifo.num / (s->bw >>3 )) <= s->tx_thres) { +qemu_set_irq (s->req[0 ],1 ); + } + } +break ; +case 1 :/* Rx */ +if (s->icr &ICR_RFDMA ) { +if (level) { +qemu_set_irq (s->req[1 ],0 ); + }else { +switch (s->cr0 &CR0_FFMT_MASK ) { +case CR0_FFMT_SPI : +qemu_set_irq (s->req[1 ],1 ); +break ; +default : +if ((s->rx_fifo.num / (s->bw >>3 )) >= s->rx_thres) { +qemu_set_irq (s->req[1 ],1 ); + } +break ; + } + } + } +break ; +default : +break ; + } +} + +void ftssp010_i2s_data_req (void *opaque,int tx,int rx) +{ +int i, len; +uint32_t sample; +Ftssp010State *s =FTSSP010 (opaque); + +if (!(s->cr2 &CR2_SSPEN )) { +return ; + } + +if ((s->cr0 &CR0_FFMT_MASK ) !=CR0_FFMT_I2S ) { +return ; + } + + s->busy =1 ; + +if ((s->cr2 &CR2_TXEN ) && (s->cr2 &CR2_TXDOE )) { + len = tx * (s->bw /8 ); +while (!fifo8_is_empty (&s->tx_fifo) && len >0 ) { + sample =0 ; +for (i =0 ; i < (s->bw >>3 ) && len >0 ; i++, len--) { + sample =deposit32 (sample, i *8 ,8 ,fifo8_pop (&s->tx_fifo)); + } +audio_codec_dac_dat (s->codec, sample); + } + +if (fifo8_is_empty (&s->tx_fifo) && len >0 ) { + s->isr |=ISR_TFURI ; + } + } + +if (s->cr2 &CR2_RXEN ) { + len = rx * (s->bw /8 ); +while (!fifo8_is_full (&s->rx_fifo) && len >0 ) { + sample =audio_codec_adc_dat (s->codec); +for (i =0 ; i < (s->bw >>3 ) && len >0 ; i++, len--) { +fifo8_push (&s->rx_fifo,extract32 (sample, i *8 ,8 )); + } + } + +if (fifo8_is_full (&s->rx_fifo) && len >0 ) { + s->isr |=ISR_RFORI ; + } + } + + s->busy =0 ; + +ftssp010_update (s); +} + +static void ftssp010_spi_tx (Ftssp010State *s) +{ +if (!(s->cr2 &CR2_TXEN )) { +return ; + } + + s->busy =1 ; + +if (fifo8_is_empty (&s->tx_fifo)) { + s->isr |=ISR_TFURI ; + } + +while (!fifo8_is_empty (&s->tx_fifo)) { +ssi_transfer (s->spi,fifo8_pop (&s->tx_fifo)); + } + + s->busy =0 ; +} + +static uint64_t +ftssp010_mem_read (void *opaque,hwaddr addr,unsigned size) +{ +Ftssp010State *s =FTSSP010 (opaque); +uint32_t i, ret =0 ; + +if (addr &0x03 ) { +fprintf (stderr,"ftssp010: " +"Although ftssp010 supports byte/half-word access, " +"the target address still needs to be word aligned\n" ); +abort (); + } + +switch (addr) { +case REG_CR0 :/* Control Register 0 */ +return s->cr0; +case REG_CR1 :/* Control Register 1 */ +return s->cr1; +case REG_CR2 :/* Control Register 2 */ +return s->cr2; +case REG_SR :/* Status Register */ + ret |= s->busy ?SR_BUSY :0 ; +/* tx fifo status */ + ret |=SR_TFVE (s->tx_fifo.num / (s->bw >>3 )); +if (!fifo8_is_full (&s->tx_fifo)) { + ret |=SR_TFNF ; + } +/* rx fifo status */ +switch (s->cr0 &CR0_FFMT_MASK ) { +case CR0_FFMT_SPI : + ret |=SR_RFF |SR_RFVE (CFG_FIFO_DEPTH ); +break ; +case CR0_FFMT_I2S : + ret |=SR_RFVE (s->rx_fifo.num / (s->bw >>3 )); +if (fifo8_is_full (&s->rx_fifo)) { + ret |=SR_RFF ; + } +break ; +default : +break ; + } +break ; +case REG_ICR :/* Interrupt Control Register */ +return s->icr; +case REG_ISR :/* Interrupt Status Register */ + ret = s->isr; + s->isr &= ~ISR_RCMASK ; +ftssp010_update (s); +break ; +case REG_DR :/* Data Register */ +if (!(s->cr2 &CR2_SSPEN )) { +break ; + } +if (!(s->cr2 &CR2_RXEN )) { +break ; + } +switch (s->cr0 &CR0_FFMT_MASK ) { +case CR0_FFMT_SPI : +for (i =0 ; i < (s->bw >>3 ); i++) { + ret =deposit32 (ret, i *8 ,8 ,ssi_transfer (s->spi,0 )); + } +break ; +case CR0_FFMT_I2S : +for (i =0 ; i < (s->bw >>3 ); i++) { +if (fifo8_is_empty (&s->rx_fifo)) { +break ; + } + ret =deposit32 (ret, i *8 ,8 ,fifo8_pop (&s->rx_fifo)); + } +break ; +default : +break ; + } +ftssp010_update (s); +break ; +case REG_REVR : +return 0x00011901 ;/* ver. 1.19.1 */ +case REG_FEAR : +return 0x660f0f1f ;/* SPI+I2S, FIFO=16 */ +default : +qemu_log_mask (LOG_GUEST_ERROR , +"ftssp010: undefined memory access@%#" HWADDR_PRIx"\n" , addr); +break ; + } + +return ret; +} + +static void
hw/ftssp010.c line 308
Quoted 10 lines
hw/ftssp010.c new file +10
-0+ftssp010_mem_write(void *opaque, hwaddr addr, uint64_t val, unsigned size) +{ +int i; +Ftssp010State *s =FTSSP010 (opaque); + +if (addr &0x03 ) { +fprintf (stderr,"ftssp010: " +"Although ftssp010 supports byte/half-word access, " +"the target address still needs to be word aligned\n" ); +abort ();
Guest error. Buggy guests should not crash the VM.
Quoted 124 lines
hw/ftssp010.c new file +124
-0+ } + +switch (addr) { +case REG_CR0 :/* Control Register 0 */ + s->cr0 = (uint32_t )val; +break ; +case REG_CR1 :/* Control Register 1 */ + s->cr1 = (uint32_t )val; + s->bw =extract32 (s->cr1,16 ,7 ) +1 ; +break ; +case REG_CR2 :/* Control Register 2 */ + s->cr2 = (uint32_t )val; +if (s->cr2 &CR2_SSPRST ) { +fifo8_reset (&s->tx_fifo); +fifo8_reset (&s->rx_fifo); + s->busy =0 ; + s->cr2 &= ~(CR2_SSPRST |CR2_TXFCLR |CR2_RXFCLR ); +if (s->cr0 &CR0_FLASH ) { +int cs =extract32 (s->cr2,10 ,2 ); +qemu_set_irq (s->cs_lines[cs],1 ); + s->cr2 |=CR2_FS ; + }; + } +if (s->cr2 &CR2_TXFCLR ) { +fifo8_reset (&s->tx_fifo); + s->cr2 &= ~CR2_TXFCLR ; + } +if (s->cr2 &CR2_RXFCLR ) { +fifo8_reset (&s->rx_fifo); + s->cr2 &= ~CR2_RXFCLR ; + } +if (s->cr0 &CR0_FLASH ) { +int cs =extract32 (s->cr2,10 ,2 ); +qemu_set_irq (s->cs_lines[cs], (s->cr2 &CR2_FS ) ?1 :0 ); + } +if (s->cr2 &CR2_SSPEN ) { +switch (s->cr0 &CR0_FFMT_MASK ) { +case CR0_FFMT_SPI : +ftssp010_spi_tx (s); +break ; +default : +break ; + } + } +ftssp010_update (s); +break ; +case REG_ICR :/* Interrupt Control Register */ + s->icr = (uint32_t )val; + s->tx_thres =extract32 (s->icr,12 ,5 ); + s->rx_thres =extract32 (s->icr,7 ,5 ); +break ; +case REG_DR :/* Data Register */ +if (!(s->cr2 &CR2_SSPEN )) { +break ; + } +for (i =0 ; i < (s->bw >>3 ) && !fifo8_is_full (&s->tx_fifo); i++) { +fifo8_push (&s->tx_fifo,extract32 ((uint32_t )val, i *8 ,8 )); + } +switch (s->cr0 &CR0_FFMT_MASK ) { +case CR0_FFMT_SPI : +ftssp010_spi_tx (s); +break ; +default : +break ; + } +ftssp010_update (s); +break ; +default : +qemu_log_mask (LOG_GUEST_ERROR , +"ftssp010: undefined memory access@%#" HWADDR_PRIx"\n" , addr); +break ; + } +} + +static const MemoryRegionOps mmio_ops = { + .read = ftssp010_mem_read, + .write = ftssp010_mem_write, + .endianness =DEVICE_LITTLE_ENDIAN , + .valid = { + .min_access_size =1 , + .max_access_size =4 + } +}; + +static void ftssp010_reset (DeviceState *ds) +{ +Ftssp010State *s =FTSSP010 (SYS_BUS_DEVICE (ds)); +Error *local_errp =NULL ; + + s->codec =AUDIO_CODEC (object_property_get_link (OBJECT (s), +"codec" , &local_errp)); +if (local_errp) { +fprintf (stderr,"ftssp010: Unable to get codec link\n" ); +abort (); + } + + s->busy =0 ; + s->bw =8 ;/* 8-bit */ + + s->cr0 =0 ; + s->cr1 =0 ; + s->cr2 =0 ; + s->tx_thres =4 ; + s->rx_thres =4 ; + s->icr =ICR_TFTHOD (4 ) |ICR_RFTHOD (4 ); + s->isr =ISR_TFTHI ; + +fifo8_reset (&s->tx_fifo); +fifo8_reset (&s->rx_fifo); + +ftssp010_update (s); +} + +static void ftssp010_realize (DeviceState *dev,Error **errp) +{ +Ftssp010State *s =FTSSP010 (dev); +SysBusDevice *sbd =SYS_BUS_DEVICE (dev); +int i; + + s->spi =ssi_create_bus (&sbd->qdev,"spi" ); + +fifo8_create (&s->tx_fifo,CFG_FIFO_DEPTH *4 ); +fifo8_create (&s->rx_fifo,CFG_FIFO_DEPTH *4 ); +
hw/ftssp010.c line 442
Quoted 10 lines
hw/ftssp010.c new file +10
-0+memory_region_init_io (&s->mmio, + &mmio_ops, + s, +TYPE_FTSSP010 , +0x1000 ); +sysbus_init_mmio (sbd, &s->mmio); +sysbus_init_irq (sbd, &s->irq); + + s->num_cs =4 ; + s->cs_lines =g_new (qemu_irq, s->num_cs);
g_new0
Regards,
Peter
Quoted 168 lines
hw/ftssp010.c new file +62
-0+ssi_auto_connect_slaves (dev, s->cs_lines, s->spi); +for (i =0 ; i < s->num_cs; ++i) { +sysbus_init_irq (sbd, &s->cs_lines[i]); + } + +/* DMA hardware handshake */ +qdev_init_gpio_in (&sbd->qdev, ftssp010_handle_ack,2 ); +qdev_init_gpio_out (&sbd->qdev, s->req,2 ); +} + +static const VMStateDescription vmstate_ftssp010 = { + .name =TYPE_FTSSP010 , + .version_id =1 , + .minimum_version_id =1 , + .minimum_version_id_old =1 , + .fields = (VMStateField []) { +VMSTATE_UINT32 (cr0, Ftssp010State), +VMSTATE_UINT32 (cr1, Ftssp010State), +VMSTATE_UINT32 (cr2, Ftssp010State), +VMSTATE_UINT32 (icr, Ftssp010State), +VMSTATE_UINT32 (isr, Ftssp010State), +VMSTATE_FIFO8 (tx_fifo, Ftssp010State), +VMSTATE_FIFO8 (rx_fifo, Ftssp010State), +VMSTATE_END_OF_LIST () + } +}; + +static void ftssp010_instance_init (Object *obj) +{ +Ftssp010State *s =FTSSP010 (obj); + +object_property_add_link (obj, +"codec" , +TYPE_AUDIO_CODEC , + (Object **) &s->codec, +NULL ); +} + +static void ftssp010_class_init (ObjectClass *klass,void *data) +{ +DeviceClass *dc =DEVICE_CLASS (klass); + + dc->vmsd = &vmstate_ftssp010; + dc->reset = ftssp010_reset; + dc->realize = ftssp010_realize; + dc->no_user =1 ; +} + +static const TypeInfo ftssp010_info = { + .name =TYPE_FTSSP010 , + .parent =TYPE_SYS_BUS_DEVICE , + .instance_size =sizeof (Ftssp010State), + .instance_init = ftssp010_instance_init, + .class_init = ftssp010_class_init, +}; + +static void ftssp010_register_types (void ) +{ +type_register_static (&ftssp010_info); +} + +type_init (ftssp010_register_types)hw/ftssp010.h new file +96
-1@@ -0,0 +1,96 @@ +/* +* QEMU model of the FTSSP010 Controller +* +* Copyright (C) 2012 Faraday Technology +* Written by Dante Su <[email protected]> +* +* This file is licensed under GNU GPL v2+. +*/ + +#ifndef HW_ARM_FTSSP010_H +#define HW_ARM_FTSSP010_H + +/* FTSSP010: Registers */ +#define REG_CR0 0x00/* control register 0 */ +#define REG_CR1 0x04/* control register 1 */ +#define REG_CR2 0x08/* control register 2 */ +#define REG_SR 0x0C/* status register */ +#define REG_ICR 0X10/* interrupt control register */ +#define REG_ISR 0x14/* interrupt statis register */ +#define REG_DR 0x18/* data register */ +#define REG_REVR 0x60/* revision register */ +#define REG_FEAR 0x64/* feature register */ + +/* Control register 0 */ + +#define CR0_FFMT_MASK (7 << 12) +#define CR0_FFMT_SSP (0 << 12) +#define CR0_FFMT_SPI (1 << 12) +#define CR0_FFMT_MICROWIRE (2 << 12) +#define CR0_FFMT_I2S (3 << 12) +#define CR0_FFMT_AC97 (4 << 12) +#define CR0_FLASH (1 << 11) +#define CR0_FSDIST (x) (((x) & 0x03) << 8) +#define CR0_LBM (1 << 7)/* Loopback mode */ +#define CR0_LSB (1 << 6)/* LSB first */ +#define CR0_FSPO (1 << 5)/* Frame sync atcive low */ +#define CR0_FSJUSTIFY (1 << 4) +#define CR0_OPM_SLAVE (0 << 2) +#define CR0_OPM_MASTER (3 << 2) +#define CR0_OPM_I2S_MSST (3 << 2)/* Master stereo mode */ +#define CR0_OPM_I2S_MSMO (2 << 2)/* Master mono mode */ +#define CR0_OPM_I2S_SLST (1 << 2)/* Slave stereo mode */ +#define CR0_OPM_I2S_SLMO (0 << 2)/* Slave mono mode */ +#define CR0_SCLKPO (1 << 1)/* SCLK Remain HIGH */ +#define CR0_SCLKPH (1 << 0)/* Half CLK cycle */ + +/* Control Register 1 */ + +/* padding data length */ +#define CR1_PDL (x) (((x) & 0xff) << 24) +/* serial data length(actual data length-1) */ +#define CR1_SDL (x) ((((x) - 1) & 0x1f) << 16) +/* clk divider */ +#define CR1_CLKDIV (x) ((x) & 0xffff) + +/* Control Register 2 */ +#define CR2_FSOS (x) (((x) & 0x03) << 10)/* FS/CS Select */ +#define CR2_FS (1 << 9)/* FS/CS Signal Level */ +#define CR2_TXEN (1 << 8)/* Tx Enable */ +#define CR2_RXEN (1 << 7)/* Rx Enable */ +#define CR2_SSPRST (1 << 6)/* SSP reset */ +#define CR2_TXFCLR (1 << 3)/* TX FIFO Clear */ +#define CR2_RXFCLR (1 << 2)/* RX FIFO Clear */ +#define CR2_TXDOE (1 << 1)/* TX Data Output Enable */ +#define CR2_SSPEN (1 << 0)/* SSP Enable */ + +/* +* Status Register +*/ +#define SR_TFVE (reg) (((reg) & 0x1F) << 12) +#define SR_RFVE (reg) (((reg) & 0x1F) << 4) +#define SR_BUSY (1 << 2) +#define SR_TFNF (1 << 1)/* Tx FIFO Not Full */ +#define SR_RFF (1 << 0)/* Rx FIFO Full */ + +/* Interrupr Control Register */ +#define ICR_TFTHOD (x) (((x) & 0x1f) << 12)/* TX FIFO Threshold */ +#define ICR_RFTHOD (x) (((x) & 0x1f) << 7)/* RX FIFO Threshold */ +#define ICR_AC97I 0x40/* AC97 intr enable */ +#define ICR_TFDMA 0x20/* TX DMA enable */ +#define ICR_RFDMA 0x10/* RX DMA enable */ +#define ICR_TFTHI 0x08/* TX FIFO intr enable */ +#define ICR_RFTHI 0x04/* RX FIFO intr enable */ +#define ICR_TFURI 0x02/* TX FIFO Underrun intr enable */ +#define ICR_RFORI 0x01/* RX FIFO Overrun intr enable */ + +/* Interrupr Status Register */ +#define ISR_AC97I 0x10/* AC97 interrupt */ +#define ISR_TFTHI 0x08/* TX FIFO interrupt */ +#define ISR_RFTHI 0x04/* RX FIFO interrupt */ +#define ISR_TFURI 0x02/* TX FIFO Underrun interrupt */ +#define ISR_RFORI 0x01/* RX FIFO Overrun interrupt */ +/* Read-Clear status mask */ +#define ISR_RCMASK (ISR_RFORI | ISR_TFURI | ISR_AC97I) + +#endif --1.7.9.5
Re: [Qemu-devel] [PATCH v9 16/24] The FTSSP010 is a multi-function synchronous serial port interface controller which supports SSP, SPI, I2S, AC97 and SPDIF.
2013/3/31 Peter Crosthwaite <[email protected]>:
Quoted 6 lines
Hi Kuo-Jung
I think you may have accidentally dropped your subject line and promoted your long commit message to subject line. Looks better in previous versions.
Yes, it's an accident, I'll fix it later.
Quoted 175 lines · Kuo-Jung Su
Quoted 174 lines
From: Kuo-Jung Su <[email protected]>
Only I2S and SPI protocol have been implemented in this patch.
Signed-off-by Kuo-Jung Su <[email protected]>--- hw/arm/Makefile.objs | 3 +- hw/arm/ftplat_a369.c | 31 +++ hw/arm/ftplat_a369soc.c | 17 ++ hw/faraday.h | 3 + hw/ftssp010.c | 504 +++++++++++++++++++++++++++++++++++++++++++++++ hw/ftssp010.h | 96 +++++++++ 6 files changed, 653 insertions(+), 1 deletion(-) create mode 100644 hw/ftssp010.c create mode 100644 hw/ftssp010.hhw/arm/Makefile.objs +2
-1@@ -25,7 +25,8 @@ obj-y += strongarm.o obj-y += imx_serial.o imx_ccm.o imx_timer.o imx_avic.o obj-$(CONFIG_KVM) += kvm/arm_gic.o obj-y += ftintc020.o ftahbc020.o ftddrii030.o ftpwmtmr010.o ftwdt010.o \ - ftrtc011.o ftdmac020.o ftapbbrg020.o ftnandc021.o fti2c010.o + ftrtc011.o ftdmac020.o ftapbbrg020.o ftnandc021.o fti2c010.o \ + ftssp010.o obj-y := $(addprefix ../,$(obj-y))hw/arm/ftplat_a369.c +31
-0@@ -11,6 +11,7 @@#include "hw/arm-misc.h" #include "hw/devices.h" #include "hw/i2c.h" +#include "hw/audio.h" #include "hw/boards.h" #include "hw/ssi.h" #include "net/net.h" @@ -28,6 +29,7 @@ static void a369_system_reset(void *opaque)static void a369_board_init (QEMUMachineInitArgs *args) { +int i, nr_flash;ARMCPU *cpu;DeviceState *ds;FaradaySoCState *s;@@ -79,6 +81,35 @@ static void a369_board_init(QEMUMachineInitArgs *args)abort (); } +/* Attach the spi flash to ftssp010.0 */ + nr_flash =1 ; +for (i =0 ; i < nr_flash; i++) { +SSIBus *ssi = (SSIBus *)qdev_get_child_bus (s->spi[0 ],"spi" ); +DeviceState *fl =ssi_create_slave_no_init (ssi,"w25q64" ); +qemu_irq cs_line; + +qdev_init_nofail (fl); + cs_line =qdev_get_gpio_in (fl,0 ); +sysbus_connect_irq (SYS_BUS_DEVICE (s->spi[0 ]), i +1 , cs_line); + } + +/* Attach the wm8731 to fti2c010.0 & ftssp010.0 */ +for (i =0 ; i <1 ; ++i) { +i2c_bus *i2c = (i2c_bus *)qdev_get_child_bus (s->i2c[0 ],"i2c" ); + ds =i2c_create_slave (i2c,"wm8731" ,0x1B ); +object_property_set_link (OBJECT (s->i2s[0 ]), +OBJECT (ds), +"codec" , + &local_errp); +if (local_errp) { +fprintf (stderr,"a369: Unable to set codec link for FTSSP010\n" ); +abort (); + } +audio_codec_data_req_set (ds, + ftssp010_i2s_data_req, + s->i2s[0 ]); + } +/* System start-up */ if (args->kernel_filename) {hw/arm/ftplat_a369soc.c +17
-0@@ -206,6 +206,23 @@ static void a369soc_chip_init(FaradaySoCState *s) s->i2c[0 ] = ds; ds =sysbus_create_simple ("fti2c010" ,0x92A00000 , s->pic[52 ]); s->i2c[1 ] = ds; + +/* ftssp010 */ + ds =sysbus_create_simple ("ftssp010" ,0x92700000 , s->pic[49 ]); + s->spi[0 ] = ds; + s->i2s[0 ] = ds; + +/* ftssp010 - DMA (Tx) */ + ack =qdev_get_gpio_in (ds,0 ); + req =qdev_get_gpio_in (s->pdma[0 ],7 ); +qdev_connect_gpio_out (s->pdma[0 ],7 , ack); +qdev_connect_gpio_out (ds,0 , req); + +/* ftssp010 - DMA (Rx) */ + ack =qdev_get_gpio_in (ds,1 ); + req =qdev_get_gpio_in (s->pdma[0 ],8 ); +qdev_connect_gpio_out (s->pdma[0 ],8 , ack); +qdev_connect_gpio_out (ds,1 , req); }static void a369soc_realize (DeviceState *dev,Error **errp)hw/faraday.h +3
-0@@ -121,4 +121,7 @@ static inline void faraday_soc_ahb_remap(FaradaySoCState *s, bool active) } } +/* ftssp010.c */ +void ftssp010_i2s_data_req (void *opaque,int tx,int rx); +#endif hw/ftssp010.c new file +41
-0@@ -0,0 +1,504 @@ +/* +* QEMU model of the FTSSP010 Controller +* +* Copyright (C) 2012 Faraday Technology +* Written by Dante Su <[email protected]> +* +* This file is licensed under GNU GPL v2+. +*/ + +#include "hw/sysbus.h" +#include "hw/i2c.h" +#include "hw/ssi.h" +#include "hw/audio.h" +#include "sysemu/sysemu.h" +#include "qemu/fifo8.h" + +#include "hw/faraday.h" +#include "hw/ftssp010.h" + +#define CFG_FIFO_DEPTH 16 + +#define TYPE_FTSSP010 "ftssp010" + +typedef struct Ftssp010State { + /*< private >*/ + SysBusDevice parent; + + /*< public >*/ + MemoryRegion mmio; + + qemu_irq irq; + SSIBus *spi; + AudioCodecState *codec; + + uint8_t num_cs; + qemu_irq *cs_lines; + + Fifo8 rx_fifo; + Fifo8 tx_fifo; + + uint8_t tx_thres;
Quoted 9 lines
hw/ftssp010.c line 44
Quoted 3 lines
hw/ftssp010.c new file +3
-0+uint8_t rx_thres; + +int busy;Constant 0 AFAICT. Every set of busy to 1 is followed by a clear before fn return. I cannot see a code path where anyone reads busy as 1? If there is such a code path then busy should be part of the VMSD as well.
Yes, it should be a constant 0. It's going to be fixed in next version.
Quoted 261 lines
hw/ftssp010.c line 51
Quoted 7 lines
hw/ftssp010.c new file +7
-0+uint8_t bw; + +/* DMA hardware handshake */ +qemu_irq req[2 ];/* 0 - Tx, 1 - Rx */ + +/* HW register caches */ +Are they really caches?
Quoted 251 lines
hw/ftssp010.c new file +251
-0+uint32_t cr0; +uint32_t cr1; +uint32_t cr2; +uint32_t icr;/* interrupt control register */ +uint32_t isr;/* interrupt status register */ + +} Ftssp010State; + +#define FTSSP010 (obj) \ + OBJECT_CHECK(Ftssp010State, obj, TYPE_FTSSP010) + +/* Update interrupts. */ +static void ftssp010_update (Ftssp010State *s) +{ +if (!(s->cr2 &CR2_SSPEN )) { +return ; + } + +/* tx fifo status update */ +if ((s->tx_fifo.num / (s->bw >>3 )) <= s->tx_thres) { + s->isr |=ISR_TFTHI ; +if (s->icr &ICR_TFDMA ) { +qemu_set_irq (s->req[0 ],1 ); + } + }else { + s->isr &= ~ISR_TFTHI ; + } + +/* rx fifo status update */ +switch (s->cr0 &CR0_FFMT_MASK ) { +case CR0_FFMT_SPI : + s->isr |=ISR_RFTHI ; +if (s->icr &ICR_RFDMA ) { +qemu_set_irq (s->req[1 ],1 ); + } +break ; +default : +if ((s->rx_fifo.num / (s->bw >>3 )) >= s->rx_thres) { + s->isr |=ISR_RFTHI ; +if (s->icr &ICR_RFDMA ) { +qemu_set_irq (s->req[1 ],1 ); + } + }else { + s->isr &= ~ISR_RFTHI ; + } +break ; + } + +/* update the interrupt signal */ +qemu_set_irq (s->irq, (s->icr & s->isr) ?1 :0 ); +} + +static void ftssp010_handle_ack (void *opaque,int line,int level) +{ +Ftssp010State *s =FTSSP010 (opaque); + +switch (line) { +case 0 :/* Tx */ +if (s->icr &ICR_TFDMA ) { +if (level) { +qemu_set_irq (s->req[0 ],0 ); + }else if ((s->tx_fifo.num / (s->bw >>3 )) <= s->tx_thres) { +qemu_set_irq (s->req[0 ],1 ); + } + } +break ; +case 1 :/* Rx */ +if (s->icr &ICR_RFDMA ) { +if (level) { +qemu_set_irq (s->req[1 ],0 ); + }else { +switch (s->cr0 &CR0_FFMT_MASK ) { +case CR0_FFMT_SPI : +qemu_set_irq (s->req[1 ],1 ); +break ; +default : +if ((s->rx_fifo.num / (s->bw >>3 )) >= s->rx_thres) { +qemu_set_irq (s->req[1 ],1 ); + } +break ; + } + } + } +break ; +default : +break ; + } +} + +void ftssp010_i2s_data_req (void *opaque,int tx,int rx) +{ +int i, len; +uint32_t sample; +Ftssp010State *s =FTSSP010 (opaque); + +if (!(s->cr2 &CR2_SSPEN )) { +return ; + } + +if ((s->cr0 &CR0_FFMT_MASK ) !=CR0_FFMT_I2S ) { +return ; + } + + s->busy =1 ; + +if ((s->cr2 &CR2_TXEN ) && (s->cr2 &CR2_TXDOE )) { + len = tx * (s->bw /8 ); +while (!fifo8_is_empty (&s->tx_fifo) && len >0 ) { + sample =0 ; +for (i =0 ; i < (s->bw >>3 ) && len >0 ; i++, len--) { + sample =deposit32 (sample, i *8 ,8 ,fifo8_pop (&s->tx_fifo)); + } +audio_codec_dac_dat (s->codec, sample); + } + +if (fifo8_is_empty (&s->tx_fifo) && len >0 ) { + s->isr |=ISR_TFURI ; + } + } + +if (s->cr2 &CR2_RXEN ) { + len = rx * (s->bw /8 ); +while (!fifo8_is_full (&s->rx_fifo) && len >0 ) { + sample =audio_codec_adc_dat (s->codec); +for (i =0 ; i < (s->bw >>3 ) && len >0 ; i++, len--) { +fifo8_push (&s->rx_fifo,extract32 (sample, i *8 ,8 )); + } + } + +if (fifo8_is_full (&s->rx_fifo) && len >0 ) { + s->isr |=ISR_RFORI ; + } + } + + s->busy =0 ; + +ftssp010_update (s); +} + +static void ftssp010_spi_tx (Ftssp010State *s) +{ +if (!(s->cr2 &CR2_TXEN )) { +return ; + } + + s->busy =1 ; + +if (fifo8_is_empty (&s->tx_fifo)) { + s->isr |=ISR_TFURI ; + } + +while (!fifo8_is_empty (&s->tx_fifo)) { +ssi_transfer (s->spi,fifo8_pop (&s->tx_fifo)); + } + + s->busy =0 ; +} + +static uint64_t +ftssp010_mem_read (void *opaque,hwaddr addr,unsigned size) +{ +Ftssp010State *s =FTSSP010 (opaque); +uint32_t i, ret =0 ; + +if (addr &0x03 ) { +fprintf (stderr,"ftssp010: " +"Although ftssp010 supports byte/half-word access, " +"the target address still needs to be word aligned\n" ); +abort (); + } + +switch (addr) { +case REG_CR0 :/* Control Register 0 */ +return s->cr0; +case REG_CR1 :/* Control Register 1 */ +return s->cr1; +case REG_CR2 :/* Control Register 2 */ +return s->cr2; +case REG_SR :/* Status Register */ + ret |= s->busy ?SR_BUSY :0 ; +/* tx fifo status */ + ret |=SR_TFVE (s->tx_fifo.num / (s->bw >>3 )); +if (!fifo8_is_full (&s->tx_fifo)) { + ret |=SR_TFNF ; + } +/* rx fifo status */ +switch (s->cr0 &CR0_FFMT_MASK ) { +case CR0_FFMT_SPI : + ret |=SR_RFF |SR_RFVE (CFG_FIFO_DEPTH ); +break ; +case CR0_FFMT_I2S : + ret |=SR_RFVE (s->rx_fifo.num / (s->bw >>3 )); +if (fifo8_is_full (&s->rx_fifo)) { + ret |=SR_RFF ; + } +break ; +default : +break ; + } +break ; +case REG_ICR :/* Interrupt Control Register */ +return s->icr; +case REG_ISR :/* Interrupt Status Register */ + ret = s->isr; + s->isr &= ~ISR_RCMASK ; +ftssp010_update (s); +break ; +case REG_DR :/* Data Register */ +if (!(s->cr2 &CR2_SSPEN )) { +break ; + } +if (!(s->cr2 &CR2_RXEN )) { +break ; + } +switch (s->cr0 &CR0_FFMT_MASK ) { +case CR0_FFMT_SPI : +for (i =0 ; i < (s->bw >>3 ); i++) { + ret =deposit32 (ret, i *8 ,8 ,ssi_transfer (s->spi,0 )); + } +break ; +case CR0_FFMT_I2S : +for (i =0 ; i < (s->bw >>3 ); i++) { +if (fifo8_is_empty (&s->rx_fifo)) { +break ; + } + ret =deposit32 (ret, i *8 ,8 ,fifo8_pop (&s->rx_fifo)); + } +break ; +default : +break ; + } +ftssp010_update (s); +break ; +case REG_REVR : +return 0x00011901 ;/* ver. 1.19.1 */ +case REG_FEAR : +return 0x660f0f1f ;/* SPI+I2S, FIFO=16 */ +default : +qemu_log_mask (LOG_GUEST_ERROR , +"ftssp010: undefined memory access@%#" HWADDR_PRIx"\n" , addr); +break ; + } + +return ret; +} + +static void +ftssp010_mem_write (void *opaque,hwaddr addr,uint64_t val,unsigned size) +{ +int i; +Ftssp010State *s =FTSSP010 (opaque);
Quoted 9 lines
hw/ftssp010.c line 220
Quoted 6 lines
hw/ftssp010.c new file +6
-0+ +if (addr &0x03 ) { +fprintf (stderr,"ftssp010: " +"Although ftssp010 supports byte/half-word access, " +"the target address still needs to be word aligned\n" ); +abort ();Guest error. Buggy guests should not crash the VM.
Got it, thanks
Quoted 128 lines
Quoted 128 lines
hw/ftssp010.c new file +128
-0+ } + +switch (addr) { +case REG_CR0 :/* Control Register 0 */ + s->cr0 = (uint32_t )val; +break ; +case REG_CR1 :/* Control Register 1 */ + s->cr1 = (uint32_t )val; + s->bw =extract32 (s->cr1,16 ,7 ) +1 ; +break ; +case REG_CR2 :/* Control Register 2 */ + s->cr2 = (uint32_t )val; +if (s->cr2 &CR2_SSPRST ) { +fifo8_reset (&s->tx_fifo); +fifo8_reset (&s->rx_fifo); + s->busy =0 ; + s->cr2 &= ~(CR2_SSPRST |CR2_TXFCLR |CR2_RXFCLR ); +if (s->cr0 &CR0_FLASH ) { +int cs =extract32 (s->cr2,10 ,2 ); +qemu_set_irq (s->cs_lines[cs],1 ); + s->cr2 |=CR2_FS ; + }; + } +if (s->cr2 &CR2_TXFCLR ) { +fifo8_reset (&s->tx_fifo); + s->cr2 &= ~CR2_TXFCLR ; + } +if (s->cr2 &CR2_RXFCLR ) { +fifo8_reset (&s->rx_fifo); + s->cr2 &= ~CR2_RXFCLR ; + } +if (s->cr0 &CR0_FLASH ) { +int cs =extract32 (s->cr2,10 ,2 ); +qemu_set_irq (s->cs_lines[cs], (s->cr2 &CR2_FS ) ?1 :0 ); + } +if (s->cr2 &CR2_SSPEN ) { +switch (s->cr0 &CR0_FFMT_MASK ) { +case CR0_FFMT_SPI : +ftssp010_spi_tx (s); +break ; +default : +break ; + } + } +ftssp010_update (s); +break ; +case REG_ICR :/* Interrupt Control Register */ + s->icr = (uint32_t )val; + s->tx_thres =extract32 (s->icr,12 ,5 ); + s->rx_thres =extract32 (s->icr,7 ,5 ); +break ; +case REG_DR :/* Data Register */ +if (!(s->cr2 &CR2_SSPEN )) { +break ; + } +for (i =0 ; i < (s->bw >>3 ) && !fifo8_is_full (&s->tx_fifo); i++) { +fifo8_push (&s->tx_fifo,extract32 ((uint32_t )val, i *8 ,8 )); + } +switch (s->cr0 &CR0_FFMT_MASK ) { +case CR0_FFMT_SPI : +ftssp010_spi_tx (s); +break ; +default : +break ; + } +ftssp010_update (s); +break ; +default : +qemu_log_mask (LOG_GUEST_ERROR , +"ftssp010: undefined memory access@%#" HWADDR_PRIx"\n" , addr); +break ; + } +} + +static const MemoryRegionOps mmio_ops = { + .read = ftssp010_mem_read, + .write = ftssp010_mem_write, + .endianness =DEVICE_LITTLE_ENDIAN , + .valid = { + .min_access_size =1 , + .max_access_size =4 + } +}; + +static void ftssp010_reset (DeviceState *ds) +{ +Ftssp010State *s =FTSSP010 (SYS_BUS_DEVICE (ds)); +Error *local_errp =NULL ; + + s->codec =AUDIO_CODEC (object_property_get_link (OBJECT (s), +"codec" , &local_errp)); +if (local_errp) { +fprintf (stderr,"ftssp010: Unable to get codec link\n" ); +abort (); + } + + s->busy =0 ; + s->bw =8 ;/* 8-bit */ + + s->cr0 =0 ; + s->cr1 =0 ; + s->cr2 =0 ; + s->tx_thres =4 ; + s->rx_thres =4 ; + s->icr =ICR_TFTHOD (4 ) |ICR_RFTHOD (4 ); + s->isr =ISR_TFTHI ; + +fifo8_reset (&s->tx_fifo); +fifo8_reset (&s->rx_fifo); + +ftssp010_update (s); +} + +static void ftssp010_realize (DeviceState *dev,Error **errp) +{ +Ftssp010State *s =FTSSP010 (dev); +SysBusDevice *sbd =SYS_BUS_DEVICE (dev); +int i; + + s->spi =ssi_create_bus (&sbd->qdev,"spi" ); + +fifo8_create (&s->tx_fifo,CFG_FIFO_DEPTH *4 ); +fifo8_create (&s->rx_fifo,CFG_FIFO_DEPTH *4 ); + + memory_region_init_io(&s->mmio, + &mmio_ops, + s, + TYPE_FTSSP010,
Quoted 9 lines
hw/ftssp010.c line 442
Quoted 6 lines
hw/ftssp010.c new file +6
-0+ 0x1000); +sysbus_init_mmio (sbd, &s->mmio); +sysbus_init_irq (sbd, &s->irq); + + s->num_cs =4 ; + s->cs_lines =g_new (qemu_irq, s->num_cs);
g_new0
Got it, thanks
Best wishes,
Kuo-Jung Su
Quoted 171 lines
Regards,
PeterQuoted 168 lines
hw/ftssp010.c new file +62
-0+ssi_auto_connect_slaves (dev, s->cs_lines, s->spi); +for (i =0 ; i < s->num_cs; ++i) { +sysbus_init_irq (sbd, &s->cs_lines[i]); + } + +/* DMA hardware handshake */ +qdev_init_gpio_in (&sbd->qdev, ftssp010_handle_ack,2 ); +qdev_init_gpio_out (&sbd->qdev, s->req,2 ); +} + +static const VMStateDescription vmstate_ftssp010 = { + .name =TYPE_FTSSP010 , + .version_id =1 , + .minimum_version_id =1 , + .minimum_version_id_old =1 , + .fields = (VMStateField []) { +VMSTATE_UINT32 (cr0, Ftssp010State), +VMSTATE_UINT32 (cr1, Ftssp010State), +VMSTATE_UINT32 (cr2, Ftssp010State), +VMSTATE_UINT32 (icr, Ftssp010State), +VMSTATE_UINT32 (isr, Ftssp010State), +VMSTATE_FIFO8 (tx_fifo, Ftssp010State), +VMSTATE_FIFO8 (rx_fifo, Ftssp010State), +VMSTATE_END_OF_LIST () + } +}; + +static void ftssp010_instance_init (Object *obj) +{ +Ftssp010State *s =FTSSP010 (obj); + +object_property_add_link (obj, +"codec" , +TYPE_AUDIO_CODEC , + (Object **) &s->codec, +NULL ); +} + +static void ftssp010_class_init (ObjectClass *klass,void *data) +{ +DeviceClass *dc =DEVICE_CLASS (klass); + + dc->vmsd = &vmstate_ftssp010; + dc->reset = ftssp010_reset; + dc->realize = ftssp010_realize; + dc->no_user =1 ; +} + +static const TypeInfo ftssp010_info = { + .name =TYPE_FTSSP010 , + .parent =TYPE_SYS_BUS_DEVICE , + .instance_size =sizeof (Ftssp010State), + .instance_init = ftssp010_instance_init, + .class_init = ftssp010_class_init, +}; + +static void ftssp010_register_types (void ) +{ +type_register_static (&ftssp010_info); +} + +type_init (ftssp010_register_types)hw/ftssp010.h new file +96
-1@@ -0,0 +1,96 @@ +/* +* QEMU model of the FTSSP010 Controller +* +* Copyright (C) 2012 Faraday Technology +* Written by Dante Su <[email protected]> +* +* This file is licensed under GNU GPL v2+. +*/ + +#ifndef HW_ARM_FTSSP010_H +#define HW_ARM_FTSSP010_H + +/* FTSSP010: Registers */ +#define REG_CR0 0x00/* control register 0 */ +#define REG_CR1 0x04/* control register 1 */ +#define REG_CR2 0x08/* control register 2 */ +#define REG_SR 0x0C/* status register */ +#define REG_ICR 0X10/* interrupt control register */ +#define REG_ISR 0x14/* interrupt statis register */ +#define REG_DR 0x18/* data register */ +#define REG_REVR 0x60/* revision register */ +#define REG_FEAR 0x64/* feature register */ + +/* Control register 0 */ + +#define CR0_FFMT_MASK (7 << 12) +#define CR0_FFMT_SSP (0 << 12) +#define CR0_FFMT_SPI (1 << 12) +#define CR0_FFMT_MICROWIRE (2 << 12) +#define CR0_FFMT_I2S (3 << 12) +#define CR0_FFMT_AC97 (4 << 12) +#define CR0_FLASH (1 << 11) +#define CR0_FSDIST (x) (((x) & 0x03) << 8) +#define CR0_LBM (1 << 7)/* Loopback mode */ +#define CR0_LSB (1 << 6)/* LSB first */ +#define CR0_FSPO (1 << 5)/* Frame sync atcive low */ +#define CR0_FSJUSTIFY (1 << 4) +#define CR0_OPM_SLAVE (0 << 2) +#define CR0_OPM_MASTER (3 << 2) +#define CR0_OPM_I2S_MSST (3 << 2)/* Master stereo mode */ +#define CR0_OPM_I2S_MSMO (2 << 2)/* Master mono mode */ +#define CR0_OPM_I2S_SLST (1 << 2)/* Slave stereo mode */ +#define CR0_OPM_I2S_SLMO (0 << 2)/* Slave mono mode */ +#define CR0_SCLKPO (1 << 1)/* SCLK Remain HIGH */ +#define CR0_SCLKPH (1 << 0)/* Half CLK cycle */ + +/* Control Register 1 */ + +/* padding data length */ +#define CR1_PDL (x) (((x) & 0xff) << 24) +/* serial data length(actual data length-1) */ +#define CR1_SDL (x) ((((x) - 1) & 0x1f) << 16) +/* clk divider */ +#define CR1_CLKDIV (x) ((x) & 0xffff) + +/* Control Register 2 */ +#define CR2_FSOS (x) (((x) & 0x03) << 10)/* FS/CS Select */ +#define CR2_FS (1 << 9)/* FS/CS Signal Level */ +#define CR2_TXEN (1 << 8)/* Tx Enable */ +#define CR2_RXEN (1 << 7)/* Rx Enable */ +#define CR2_SSPRST (1 << 6)/* SSP reset */ +#define CR2_TXFCLR (1 << 3)/* TX FIFO Clear */ +#define CR2_RXFCLR (1 << 2)/* RX FIFO Clear */ +#define CR2_TXDOE (1 << 1)/* TX Data Output Enable */ +#define CR2_SSPEN (1 << 0)/* SSP Enable */ + +/* +* Status Register +*/ +#define SR_TFVE (reg) (((reg) & 0x1F) << 12) +#define SR_RFVE (reg) (((reg) & 0x1F) << 4) +#define SR_BUSY (1 << 2) +#define SR_TFNF (1 << 1)/* Tx FIFO Not Full */ +#define SR_RFF (1 << 0)/* Rx FIFO Full */ + +/* Interrupr Control Register */ +#define ICR_TFTHOD (x) (((x) & 0x1f) << 12)/* TX FIFO Threshold */ +#define ICR_RFTHOD (x) (((x) & 0x1f) << 7)/* RX FIFO Threshold */ +#define ICR_AC97I 0x40/* AC97 intr enable */ +#define ICR_TFDMA 0x20/* TX DMA enable */ +#define ICR_RFDMA 0x10/* RX DMA enable */ +#define ICR_TFTHI 0x08/* TX FIFO intr enable */ +#define ICR_RFTHI 0x04/* RX FIFO intr enable */ +#define ICR_TFURI 0x02/* TX FIFO Underrun intr enable */ +#define ICR_RFORI 0x01/* RX FIFO Overrun intr enable */ + +/* Interrupr Status Register */ +#define ISR_AC97I 0x10/* AC97 interrupt */ +#define ISR_TFTHI 0x08/* TX FIFO interrupt */ +#define ISR_RFTHI 0x04/* RX FIFO interrupt */ +#define ISR_TFURI 0x02/* TX FIFO Underrun interrupt */ +#define ISR_RFORI 0x01/* RX FIFO Overrun interrupt */ +/* Read-Clear status mask */ +#define ISR_RCMASK (ISR_RFORI | ISR_TFURI | ISR_AC97I) + +#endif --1.7.9.5
PATCH v9 17/24 qemu/bitops.h: add the bit ordering reversal functions
In reply to Kuo-Jung SuFrom: Kuo-Jung Su <[email protected]>
--- include/qemu/bitops.h | 59 ++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 58 insertions(+), 1 deletion(-)
include/qemu/bitops.h +58 -1
@@ -3,7 +3,8 @@* * Copyright (C) 2010 Corentin Chary <[email protected]> * -* Mostly inspired by (stolen from) linux/bitmap.h and linux/bitops.h +* Mostly inspired by (stolen from) linux/bitmap.h, linux/bitops.h +* and linux/bitrev.h * * This work is licensed under the terms of the GNU LGPL, version 2.1 or later. * See the COPYING.LIB file in the top-level directory.
@@ -273,4 +274,60 @@ static inline uint64_t deposit64(uint64_t value, int start, int length, return (value & ~mask) | ((fieldval << start) & mask); } +/** +* bitrev8: +* @value: the value to reverse bit ordering from +* +* Reverse the 8 bit input @value +* +* Returns: the input @value with reversed bit ordering +*/ +static inline uint8_t bitrev8 (uint8_t value) +{ + value = (value &0xF0 ) >>4 | (value &0x0F ) <<4 ; + value = (value &0xCC ) >>2 | (value &0x33 ) <<2 ; + value = (value &0xAA ) >>1 | (value &0x55 ) <<1 ; +return value; +} + +/** +* bitrev16: +* @value: the value to reverse bit ordering from +* +* Reverse the 16 bit input @value +* +* Returns: the input @value with reversed bit ordering +*/ +static inline uint16_t bitrev16 (uint16_t value) +{ +return (bitrev8 (value &0xff ) <<8 ) |bitrev8 (value >>8 ); +} + +/** +* bitrev32: +* @value: the value to reverse bit ordering from +* +* Reverse the 32 bit input @value +* +* Returns: the input @value with reversed bit ordering +*/ +static inline uint32_t bitrev32 (uint32_t value) +{ +return (bitrev16 (value &0xffff ) <<16 ) |bitrev16 (value >>16 ); +} + +/** +* bitrev64: +* @value: the value to reverse bit ordering from +* +* Reverse the 64 bit input @value +* +* Returns: the input @value with reversed bit ordering +*/ +static inline uint64_t bitrev64 (uint64_t value) +{ +return ((uint64_t )bitrev32 (value &0xffffffffULL ) <<32 ) + | (uint64_t )bitrev32 (value >>32 ); +} +#endif
Signature · 1 line
1.7.9.5
PATCH v9 18/24 hw/arm: add FTGMAC100 1Gbps ethernet support
In reply to Kuo-Jung SuFrom: Kuo-Jung Su <[email protected]>
The FTGMAC100 Ethernet controller has a DMA engine which handles all data transfers between the system memory and on-chip memories. Its DMA engine supports both 16-bits and 32-bits alignment, and thus make it possible to support zero-copy transfer at both Linux and WINCE.
It also has 802.1Q VLAN tagging support for both insertion and removal.
--- hw/arm/Makefile.objs | 2 +- hw/arm/ftplat_a369soc.c | 5 + hw/faraday.h | 3 + hw/ftgmac100.c | 712 +++++++++++++++++++++++++++++++++++++++++++++++ hw/ftgmac100.h | 237 ++++++++++++++++ 5 files changed, 958 insertions(+), 1 deletion(-) create mode 100644 hw/ftgmac100.c create mode 100644 hw/ftgmac100.h
hw/arm/Makefile.objs +1 -1
@@ -26,7 +26,7 @@ obj-y += imx_serial.o imx_ccm.o imx_timer.o imx_avic.o obj-$(CONFIG_KVM) += kvm/arm_gic.o obj-y += ftintc020.o ftahbc020.o ftddrii030.o ftpwmtmr010.o ftwdt010.o \ ftrtc011.o ftdmac020.o ftapbbrg020.o ftnandc021.o fti2c010.o \ - ftssp010.o + ftssp010.o ftgmac100.o obj-y := $(addprefix ../,$(obj-y))
hw/arm/ftplat_a369soc.c +5 -0
@@ -223,6 +223,11 @@ static void a369soc_chip_init(FaradaySoCState *s) req =qdev_get_gpio_in (s->pdma[0 ],8 );qdev_connect_gpio_out (s->pdma[0 ],8 , ack);qdev_connect_gpio_out (ds,1 , req); + +/* ftgmac100 */ +if (nb_nics >0 ) { +ftgmac100_init (&nd_table[0 ],0x90c00000 , s->pic[32 ]); + } }static void a369soc_realize (DeviceState *dev,Error **errp)
hw/faraday.h +3 -0
@@ -124,4 +124,7 @@ static inline void faraday_soc_ahb_remap(FaradaySoCState *s, bool active)/* ftssp010.c */ void ftssp010_i2s_data_req (void *opaque,int tx,int rx); +/* ftgmac100.c */ +void ftgmac100_init (NICInfo *nd,uint32_t base,qemu_irq irq); +#endif
hw/ftgmac100.c new file +712 -0
712 lines not on this page · raw message
hw/ftgmac100.h new file +237 -0
237 lines not on this page · raw message
Signature · 1 line
1.7.9.5
PATCH v9 19/24 hw/arm: add FTLCDC200 LCD controller support
In reply to Kuo-Jung SuFrom: Kuo-Jung Su <[email protected]>
The FTLCDC200 Color LCD controller performs translation of pixel-coded data into the required formats and timings to drive a variety of single/dual mono and color LCDs.
Depending on the LCD type and mode, the unpacked data can represent:
1. an actual true display gray or color value
2. an address to a 256 x 16 bit wide palette RAM gray or color value.
The FTLCDC200 generates 4 individual interrupts for:
1. DMA FIFO underflow
2. base address update
3. vertical status
4. bus error.
There is also a single combined interrupt that is raised when any of the individual interrupts become active.
--- hw/arm/Makefile.objs | 2 +- hw/arm/ftplat_a369soc.c | 10 + hw/ftlcdc200.c | 516 +++++++++++++++++++++++++++++++++++++++++++++++ hw/ftlcdc200.h | 110 ++++++++++ hw/ftlcdc200_template.h | 439 ++++++++++++++++++++++++++++++++++++++++ 5 files changed, 1076 insertions(+), 1 deletion(-) create mode 100644 hw/ftlcdc200.c create mode 100644 hw/ftlcdc200.h create mode 100644 hw/ftlcdc200_template.h
hw/arm/Makefile.objs +1 -1
@@ -26,7 +26,7 @@ obj-y += imx_serial.o imx_ccm.o imx_timer.o imx_avic.o obj-$(CONFIG_KVM) += kvm/arm_gic.o obj-y += ftintc020.o ftahbc020.o ftddrii030.o ftpwmtmr010.o ftwdt010.o \ ftrtc011.o ftdmac020.o ftapbbrg020.o ftnandc021.o fti2c010.o \ - ftssp010.o ftgmac100.o + ftssp010.o ftgmac100.o ftlcdc200.o obj-y := $(addprefix ../,$(obj-y))
hw/arm/ftplat_a369soc.c +10 -0
@@ -228,6 +228,16 @@ static void a369soc_chip_init(FaradaySoCState *s)if (nb_nics >0 ) {ftgmac100_init (&nd_table[0 ],0x90c00000 , s->pic[32 ]); } + +/* ftlcdc200 */ +sysbus_create_varargs ("ftlcdc200" , +0x94a00000 , + s->pic[0 ],/* ALL (NC in A369) */ + s->pic[25 ],/* VSTATUS */ + s->pic[24 ],/* Base Address Update */ + s->pic[23 ],/* FIFO Under-Run */ + s->pic[22 ],/* AHB Bus Error */ +NULL ); }static void a369soc_realize (DeviceState *dev,Error **errp)
hw/ftlcdc200.c new file +516 -0
516 lines not on this page · raw message
hw/ftlcdc200.h new file +110 -0
110 lines not on this page · raw message
hw/ftlcdc200_template.h new file +439 -0
439 lines not on this page · raw message
Signature · 1 line
1.7.9.5
PATCH v9 20/24 hw/arm: add FTTSC010 touchscreen controller support
In reply to Kuo-Jung SuFrom: Kuo-Jung Su <[email protected]>
The FTTSC010 provides two operation modes to sample the analog input voltage.
1. The manual operation mode needs to program and control the panel drivers by software step-by-step for the x-y position measurement.
2. The auto-scan mode provides a periodic sampling method to convert the analog input.
This patch only implements the auto-scan mode.
--- hw/arm/Makefile.objs | 2 +- hw/arm/ftplat_a369soc.c | 3 + hw/fttsc010.c | 264 +++++++++++++++++++++++++++++++++++++++++++++++ hw/fttsc010.h | 39 +++++++ 4 files changed, 307 insertions(+), 1 deletion(-) create mode 100644 hw/fttsc010.c create mode 100644 hw/fttsc010.h
hw/arm/Makefile.objs +1 -1
@@ -26,7 +26,7 @@ obj-y += imx_serial.o imx_ccm.o imx_timer.o imx_avic.o obj-$(CONFIG_KVM) += kvm/arm_gic.o obj-y += ftintc020.o ftahbc020.o ftddrii030.o ftpwmtmr010.o ftwdt010.o \ ftrtc011.o ftdmac020.o ftapbbrg020.o ftnandc021.o fti2c010.o \ - ftssp010.o ftgmac100.o ftlcdc200.o + ftssp010.o ftgmac100.o ftlcdc200.o fttsc010.o obj-y := $(addprefix ../,$(obj-y))
hw/arm/ftplat_a369soc.c +3 -0
@@ -238,6 +238,9 @@ static void a369soc_chip_init(FaradaySoCState *s) s->pic[23 ],/* FIFO Under-Run */ s->pic[22 ],/* AHB Bus Error */ NULL); + +/* fttsc010 */ +sysbus_create_simple ("fttsc010" ,0x92400000 , s->pic[19 ]); }static void a369soc_realize (DeviceState *dev,Error **errp)
hw/fttsc010.c new file +264 -0
264 lines not on this page · raw message
hw/fttsc010.h new file +39 -0
@@ -0,0 +1,39 @@ +/* +* Faraday FTTSC010 touchscreen driver +* +* Copyright (C) 2012 Faraday Technology +* Written by Dante Su <[email protected]> +* +* This file is licensed under GNU GPL v2+. +*/ + +#ifndef HW_ARM_FTTSC010_H +#define HW_ARM_FTTSC010_H + +#include "qemu/bitops.h" + +#define REG_CR 0x00/* Control Register */ +#define REG_ISR 0x04/* Interrupt Status Register */ +#define REG_IMR 0x08/* Interrupt Mask Register */ +#define REG_REVR 0x0C/* Revision Register */ +#define REG_CSR 0x30/* Clock & Sample Rate Register */ +#define REG_PFR 0x34/* Panel Function Register */ +#define REG_DCR 0x38/* Delay Control Register */ +#define REG_XYR 0x3C/* Touchscreen X,Y-Axis Register */ +#define REG_ZR 0x4C/* Touchscreen Z-Axis (Pressure) Register */ + +#define CR_AS BIT(31)/* Auto-scan enable */ +#define CR_RD1 BIT(30)/* Single read enabled */ +#define CR_CHDLY (x) BIT(16 + (x % 7))/* ADC channel x delay enabled */ +#define CR_APWRDN BIT(9)/* ADC auto power down mode */ +#define CR_PWRDN BIT(8)/* ADC and IPGA power down */ +#define CR_ICS (x) ((x) & 0xf)/* ADC analog input channel select */ + +#define CSR_SDIV (x) (((x) & 0xff) << 8)/* ADC sample clock divider */ +#define CSR_MDIV (x) (((x) & 0xff) << 0)/* ADC main clock divider */ + +#define DCR_DLY (x) ((x) & 0xffff)/* ADC conversion delay */ + +#define ISR_AS BIT(10)/* Auto-scan cpmplete */ + +#endif
Signature · 1 line
1.7.9.5
PATCH v9 21/24 hw/arm: add FTSDC010 MMC/SD controller support
In reply to Kuo-Jung SuFrom: Kuo-Jung Su <[email protected]>
The FTSDC010 is a simple MMC/SD host controller and many of its registers are similar to Arm PrimeCell PL181.
--- hw/arm/Makefile.objs | 2 +- hw/arm/ftplat_a369soc.c | 7 + hw/ftsdc010.c | 359 +++++++++++++++++++++++++++++++++++++++++++++++ hw/ftsdc010.h | 88 ++++++++++++ 4 files changed, 455 insertions(+), 1 deletion(-) create mode 100644 hw/ftsdc010.c create mode 100644 hw/ftsdc010.h
hw/arm/Makefile.objs +1 -1
@@ -26,7 +26,7 @@ obj-y += imx_serial.o imx_ccm.o imx_timer.o imx_avic.o obj-$(CONFIG_KVM) += kvm/arm_gic.o obj-y += ftintc020.o ftahbc020.o ftddrii030.o ftpwmtmr010.o ftwdt010.o \ ftrtc011.o ftdmac020.o ftapbbrg020.o ftnandc021.o fti2c010.o \ - ftssp010.o ftgmac100.o ftlcdc200.o fttsc010.o + ftssp010.o ftgmac100.o ftlcdc200.o fttsc010.o ftsdc010.o obj-y := $(addprefix ../,$(obj-y))
hw/arm/ftplat_a369soc.c +7 -0
@@ -241,6 +241,13 @@ static void a369soc_chip_init(FaradaySoCState *s)/* fttsc010 */ sysbus_create_simple ("fttsc010" ,0x92400000 , s->pic[19 ]); + +/* ftsdc010 */ + ds =sysbus_create_simple ("ftsdc010" ,0x90600000 , s->pic[39 ]); + ack =qdev_get_gpio_in (ds,0 ); + req =qdev_get_gpio_in (s->hdma[0 ],13 ); +qdev_connect_gpio_out (s->hdma[0 ],13 , ack); +qdev_connect_gpio_out (ds,0 , req); }static void a369soc_realize (DeviceState *dev,Error **errp)
hw/ftsdc010.c new file +359 -0
359 lines not on this page · raw message
hw/ftsdc010.h new file +88 -0
88 lines not on this page · raw message
Signature · 1 line
1.7.9.5
PATCH v9 22/24 hw/arm: add FTMAC110 10/100Mbps ethernet support
In reply to Kuo-Jung SuFrom: Kuo-Jung Su <[email protected]>
The FTMAC110 is an Ethernet controller that provides AHB master capability and is in full compliance with the IEEE 802.3 10/100 Mbps specifications. Its DMA controller handles all data transfers between system memory and on-chip memories.
It supports half-word data transfer for Linux. However it has a weird DMA alignment issue:
(1) Tx DMA Buffer Address:
1 bytes aligned: Invalid
2 bytes aligned: O.K
4 bytes aligned: O.K
(2) Rx DMA Buffer Address:
1 bytes aligned: Invalid
2 bytes aligned: O.K
4 bytes aligned: Invalid (It means 0x0, 0x4, 0x8, 0xC are invalid)
--- hw/arm/Makefile.objs | 3 +- hw/arm/ftplat_a369.c | 7 + hw/faraday.h | 3 + hw/ftmac110.c | 665 ++++++++++++++++++++++++++++++++++++++++++++++++++ hw/ftmac110.h | 166 +++++++++++++ 5 files changed, 843 insertions(+), 1 deletion(-) create mode 100644 hw/ftmac110.c create mode 100644 hw/ftmac110.h
hw/arm/Makefile.objs +2 -1
@@ -26,7 +26,8 @@ obj-y += imx_serial.o imx_ccm.o imx_timer.o imx_avic.o obj-$(CONFIG_KVM) += kvm/arm_gic.o obj-y += ftintc020.o ftahbc020.o ftddrii030.o ftpwmtmr010.o ftwdt010.o \ ftrtc011.o ftdmac020.o ftapbbrg020.o ftnandc021.o fti2c010.o \ - ftssp010.o ftgmac100.o ftlcdc200.o fttsc010.o ftsdc010.o + ftssp010.o ftgmac100.o ftlcdc200.o fttsc010.o ftsdc010.o \ + ftmac110.o obj-y := $(addprefix ../,$(obj-y))
hw/arm/ftplat_a369.c +7 -0
@@ -110,6 +110,13 @@ static void a369_board_init(QEMUMachineInitArgs *args) s->i2s[0]); } +/* External AHB devices */ + +/* Ethernet: FTMAC110 */ +if (nb_nics >1 ) { +ftmac110_init (&nd_table[1 ],0xC0100000 , s->pic[5 ]); + } +/* System start-up */ if (args->kernel_filename) {
hw/faraday.h +3 -0
@@ -127,4 +127,7 @@ void ftssp010_i2s_data_req(void *opaque, int tx, int rx);/* ftgmac100.c */ void ftgmac100_init (NICInfo *nd,uint32_t base,qemu_irq irq); +/* ftmac110.c */ +void ftmac110_init (NICInfo *nd,uint32_t base,qemu_irq irq); +#endif
hw/ftmac110.c new file +665 -0
665 lines not on this page · raw message
hw/ftmac110.h new file +166 -0
166 lines not on this page · raw message
Signature · 1 line
1.7.9.5
PATCH v9 23/24 hw/arm: add FTTMR010 timer support
In reply to Kuo-Jung SuFrom: Kuo-Jung Su <[email protected]>
The FTTMR010 provides three independent sets of sub-timers. Two match registers are provided for each sub-timer, whenever the value of the match registers equals any one value of the sub-timers, the timer interrupt will be immediately triggered. And it would also issue an interrupt when an overflow occurs.
--- hw/arm/Makefile.objs | 2 +- hw/arm/ftplat_a369.c | 8 + hw/fttmr010.c | 449 ++++++++++++++++++++++++++++++++++++++++++++++++++ hw/fttmr010.h | 39 +++++ 4 files changed, 497 insertions(+), 1 deletion(-) create mode 100644 hw/fttmr010.c create mode 100644 hw/fttmr010.h
hw/arm/Makefile.objs +1 -1
@@ -27,7 +27,7 @@ obj-$(CONFIG_KVM) += kvm/arm_gic.o obj-y += ftintc020.o ftahbc020.o ftddrii030.o ftpwmtmr010.o ftwdt010.o \ ftrtc011.o ftdmac020.o ftapbbrg020.o ftnandc021.o fti2c010.o \ ftssp010.o ftgmac100.o ftlcdc200.o fttsc010.o ftsdc010.o \ - ftmac110.o + ftmac110.o fttmr010.o obj-y := $(addprefix ../,$(obj-y))
hw/arm/ftplat_a369.c +8 -0
@@ -117,6 +117,14 @@ static void a369_board_init(QEMUMachineInitArgs *args)ftmac110_init (&nd_table[1 ],0xC0100000 , s->pic[5 ]); } +/* Timer: FTTMR010 */ + ds =qdev_create (NULL ,"fttmr010" ); +qdev_prop_set_uint32 (ds,"freq" ,33 *1000000 ); +qdev_init_nofail (ds); +sysbus_mmio_map (SYS_BUS_DEVICE (ds),0 ,0xC0200000 ); +sysbus_connect_irq (SYS_BUS_DEVICE (ds),1 , s->pic[6 ]); +sysbus_connect_irq (SYS_BUS_DEVICE (ds),2 , s->pic[7 ]); +/* System start-up */ if (args->kernel_filename) {
hw/fttmr010.c new file +449 -0
449 lines not on this page · raw message
hw/fttmr010.h new file +39 -0
@@ -0,0 +1,39 @@ +/* +* Faraday FTTMR010 Timer. +* +* Copyright (c) 2012 Faraday Technology +* Written by Dante Su <[email protected]> +* +* This code is licensed under GNU GPL v2+. +*/ + +#ifndef HW_ARM_FTTMR010_H +#define HW_ARM_FTTMR010_H + +#define REG_TMR_ID (off) ((off) >> 4) +#define REG_TMR_BASE (id) (0x00 + ((id) << 4)) +#define REG_TMR_COUNTER 0x00 +#define REG_TMR_RELOAD 0x04 +#define REG_TMR_MATCH1 0x08 +#define REG_TMR_MATCH2 0x0C + +#define REG_CR 0x30/* control register */ +#define REG_ISR 0x34/* interrupt status register */ +#define REG_IMR 0x38/* interrupt mask register */ +#define REG_REVR 0x3C/* revision register */ + +/* timer enable */ +#define CR_TMR_EN (id) (0x01 << ((id) * 3)) +/* timer overflow interrupt enable */ +#define CR_TMR_OFEN (id) (0x04 << ((id) * 3)) +/* timer count-up mode */ +#define CR_TMR_COUNTUP (id) (0x01 << (9 + (id))) + +/* timer match 1 */ +#define ISR_MATCH1 (id) (0x01 << ((id) * 3)) +/* timer match 2 */ +#define ISR_MATCH2 (id) (0x02 << ((id) * 3)) +/* timer overflow */ +#define ISR_OF (id) (0x04 << ((id) * 3)) + +#endif
Signature · 1 line
1.7.9.5
PATCH v9 24/24 hw/arm: add FTSPI020 SPI flash controller support
In reply to Kuo-Jung SuFrom: Kuo-Jung Su <[email protected]>
The FTSPI020 is an integrated SPI Flash controller which supports up to 4 flash chips.
--- hw/arm/Makefile.objs | 2 +- hw/arm/ftplat_a369.c | 16 +++ hw/ftspi020.c | 341 ++++++++++++++++++++++++++++++++++++++++++++++++++ hw/ftspi020.h | 81 ++++++++++++ 4 files changed, 439 insertions(+), 1 deletion(-) create mode 100644 hw/ftspi020.c create mode 100644 hw/ftspi020.h
hw/arm/Makefile.objs +1 -1
@@ -27,7 +27,7 @@ obj-$(CONFIG_KVM) += kvm/arm_gic.o obj-y += ftintc020.o ftahbc020.o ftddrii030.o ftpwmtmr010.o ftwdt010.o \ ftrtc011.o ftdmac020.o ftapbbrg020.o ftnandc021.o fti2c010.o \ ftssp010.o ftgmac100.o ftlcdc200.o fttsc010.o ftsdc010.o \ - ftmac110.o fttmr010.o + ftmac110.o fttmr010.o ftspi020.o obj-y := $(addprefix ../,$(obj-y))
hw/arm/ftplat_a369.c +16 -0
@@ -125,6 +125,22 @@ static void a369_board_init(QEMUMachineInitArgs *args)sysbus_connect_irq (SYS_BUS_DEVICE (ds),1 , s->pic[6 ]);sysbus_connect_irq (SYS_BUS_DEVICE (ds),2 , s->pic[7 ]); +/* SPI: FTSPI020 */ + ds =sysbus_create_simple ("ftspi020" ,0xC0000000 , s->pic[4 ]); + s->spi_fl[0 ] = ds; + +/* Attach the spi flash to ftspi020.0 */ + nr_flash =1 ; +for (i =0 ; i < nr_flash; i++) { +SSIBus *ssi = (SSIBus *)qdev_get_child_bus (s->spi_fl[0 ],"spi" ); +DeviceState *fl =ssi_create_slave_no_init (ssi,"w25q64" ); +qemu_irq cs_line; + +qdev_init_nofail (fl); + cs_line =qdev_get_gpio_in (fl,0 ); +sysbus_connect_irq (SYS_BUS_DEVICE (s->spi_fl[0 ]), i +1 , cs_line); + } +/* System start-up */ if (args->kernel_filename) {
hw/ftspi020.c new file +341 -0
341 lines not on this page · raw message
hw/ftspi020.h new file +81 -0
81 lines not on this page · raw message
Signature · 1 line
1.7.9.5
Re: [Qemu-devel] [PATCH v9 24/24] hw/arm: add FTSPI020 SPI flash controller support
Hi Kuo-Jung,
Quoted 35 lines · Kuo-Jung Su
From: Kuo-Jung Su <[email protected]>
The FTSPI020 is an integrated SPI Flash controller which supports up to 4 flash chips.
Signed-off-by Kuo-Jung Su <[email protected]>--- hw/arm/Makefile.objs | 2 +- hw/arm/ftplat_a369.c | 16 +++ hw/ftspi020.c | 341 ++++++++++++++++++++++++++++++++++++++++++++++++++ hw/ftspi020.h | 81 ++++++++++++ 4 files changed, 439 insertions(+), 1 deletion(-) create mode 100644 hw/ftspi020.c create mode 100644 hw/ftspi020.hhw/arm/Makefile.objs +1
-1@@ -27,7 +27,7 @@ obj-$(CONFIG_KVM) += kvm/arm_gic.o obj-y += ftintc020.o ftahbc020.o ftddrii030.o ftpwmtmr010.o ftwdt010.o \ ftrtc011.o ftdmac020.o ftapbbrg020.o ftnandc021.o fti2c010.o \ ftssp010.o ftgmac100.o ftlcdc200.o fttsc010.o ftsdc010.o \ - ftmac110.o fttmr010.o + ftmac110.o fttmr010.o ftspi020.o obj-y := $(addprefix ../,$(obj-y))hw/arm/ftplat_a369.c +0
-0@@ -125,6 +125,22 @@ static void a369_board_init(QEMUMachineInitArgs *args)sysbus_connect_irq (SYS_BUS_DEVICE (ds),1 , s->pic[6 ]);sysbus_connect_irq (SYS_BUS_DEVICE (ds),2 , s->pic[7 ]);
hw/arm/ftplat_a369.c static void a369_board_init(QEMUMachineInitArgs *args) · line 136
Quoted 10 lines
hw/arm/ftplat_a369.c +9
-0+/* SPI: FTSPI020 */ + ds =sysbus_create_simple ("ftspi020" ,0xC0000000 , s->pic[4 ]); + s->spi_fl[0 ] = ds; + +/* Attach the spi flash to ftspi020.0 */ + nr_flash =1 ; +for (i =0 ; i < nr_flash; i++) { +SSIBus *ssi = (SSIBus *)qdev_get_child_bus (s->spi_fl[0 ],"spi" ); +DeviceState *fl =ssi_create_slave_no_init (ssi,"w25q64" );
You qdev_init straight away, so you can just call ssi_create_slave. This is just a hangover from my recent m25p80 cleanup which made the original reason for create_slave_no_init redundant. I'll have to send some cleanup patches for my own machine models with the equivalent change. s/ssi_create_slave_no_init/ssi_create_slave and ...
hw/arm/ftplat_a369.c static void a369_board_init(QEMUMachineInitArgs *args) · line 139
Quoted 3 lines
hw/arm/ftplat_a369.c +3
-0+qemu_irq cs_line; + +qdev_init_nofail (fl);
... dump this.
Regards,
Peter
Quoted 445 lines
hw/arm/ftplat_a369.c +4
-0+ cs_line =qdev_get_gpio_in (fl,0 ); +sysbus_connect_irq (SYS_BUS_DEVICE (s->spi_fl[0 ]), i +1 , cs_line); + } +/* System start-up */ if (args->kernel_filename) {hw/ftspi020.c new file +341
-0@@ -0,0 +1,341 @@ +/* +* Faraday FTSPI020 Flash Controller +* +* Copyright (c) 2012 Faraday Technology +* Written by Dante Su <[email protected]> +* +* This code is licensed under GNU GPL v2+. +*/ + +#include "hw/hw.h" +#include "hw/sysbus.h" +#include "hw/ssi.h" +#include "sysemu/sysemu.h" + +#include "hw/ftspi020.h" + +#define TYPE_FTSPI020 "ftspi020" + +typedef struct Ftspi020State { +/*< private >*/ +SysBusDevice parent; + +/*< public >*/ +MemoryRegion iomem; +qemu_irq irq; + +/* DMA hardware handshake */ +qemu_irq req; + +SSIBus *spi; +qemu_irq *cs_lines; + +int wip;/* SPI Flash Status: Write In Progress BIT shift */ + +/* HW register caches */ +uint32_t cmd[4 ]; +uint32_t ctrl; +uint32_t timing; +uint32_t icr; +uint32_t isr; +uint32_t rdsr; +}Ftspi020State ; + +#define FTSPI020 (obj) \ + OBJECT_CHECK(Ftspi020State, obj, TYPE_FTSPI020) + +static void ftspi020_update_irq (Ftspi020State *s) +{ +qemu_set_irq (s->irq, s->isr ?1 :0 ); +} + +static void ftspi020_handle_ack (void *opaque,int line,int level) +{ +Ftspi020State *s =FTSPI020 (opaque); + +if (!(s->icr &ICR_DMA )) { +return ; + } + +if (level) { +qemu_set_irq (s->req,0 ); + }else if (s->cmd[2 ]) { +qemu_set_irq (s->req,1 ); + } +} + +static int ftspi020_do_command (Ftspi020State *s) +{ +uint32_t cs =extract32 (s->cmd[3 ],8 ,2 ); +uint32_t cmd =extract32 (s->cmd[3 ],24 ,8 ); +uint32_t ilen =extract32 (s->cmd[1 ],24 ,2 ); +uint32_t alen =extract32 (s->cmd[1 ],0 ,3 ); +uint32_t dcyc =extract32 (s->cmd[1 ],16 ,8 ); + +if (dcyc %8 ) { +fprintf (stderr,"ftspi020: bad dummy clock (%u) to QEMU\n" , dcyc); +abort (); + } + +/* activate the spi flash */ +qemu_set_irq (s->cs_lines[cs],0 ); + +/* if it's a SPI flash READ_STATUS command */ +if ((s->cmd[3 ] & (CMD3_RDSR |CMD3_WRITE )) ==CMD3_RDSR ) { +uint32_t rdsr; + +ssi_transfer (s->spi, cmd); +do { + rdsr =ssi_transfer (s->spi,0x00 ); +if (s->cmd[3 ] &CMD3_RDSR_SW ) { +break ; + } + }while (rdsr & (1 << s->wip)); + s->rdsr = rdsr; + }else { +/* otherwise */ +int i; + + ilen =MIN (ilen,2 ); + alen =MIN (alen,4 ); + +/* command cycles */ +for (i =0 ; i < ilen; ++i) { +ssi_transfer (s->spi, cmd); + } +/* address cycles */ +for (i = alen -1 ; i >=0 ; --i) { +ssi_transfer (s->spi,extract32 (s->cmd[0 ], i *8 ,8 )); + } +/* dummy cycles */ +for (i =0 ; i < (dcyc >>3 ); ++i) { +ssi_transfer (s->spi,0x00 ); + } + } + +if (!s->cmd[2 ]) { +qemu_set_irq (s->cs_lines[cs],1 ); + }else if (s->icr &ICR_DMA ) { +qemu_set_irq (s->req,1 ); + } + +if (s->cmd[3 ] &CMD3_INTR ) { + s->isr |=ISR_CMDFIN ; + } +ftspi020_update_irq (s); + +return 0 ; +} + +static void ftspi020_chip_reset (Ftspi020State *s) +{ +int i; + +for (i =0 ; i <4 ; ++i) { + s->cmd[i] =0 ; + } + s->wip =0 ; + s->ctrl =0 ; + s->timing =0 ; + s->icr =0 ; + s->isr =0 ; + s->rdsr =0 ; + +qemu_set_irq (s->irq,0 ); + +for (i =0 ; i <CFG_NR_CSLINES ; ++i) { +/* de-activate the spi flash */ +qemu_set_irq (s->cs_lines[i],1 ); + } +} + +static uint64_t +ftspi020_mem_read (void *opaque,hwaddr addr,unsigned size) +{ +Ftspi020State *s =FTSPI020 (opaque); +uint64_t ret =0 ; + +switch (addr) { + case REG_CMD0 ... REG_CMD3: +return s->cmd[(addr -REG_CMD0 ) /4 ]; +case REG_CR : +return s->ctrl; +case REG_TR : +return s->timing; +case REG_SR : +/* In QEMU, the data fifo is always ready for read/write */ +return SR_RX_READY |SR_TX_READY ; +case REG_ISR : +return s->isr; +case REG_ICR : +return s->icr; +case REG_RDSR : +return s->rdsr; +case REG_REVR : +return 0x00010001 ;/* rev. 1.0.1 */ +case REG_FEAR : +return FEAR_CLKM_SYNC + |FEAR_CMDQ (2 ) |FEAR_RXFIFO (32 ) |FEAR_TXFIFO (32 ); +case REG_DR : +if (!(s->cmd[3 ] &CMD3_WRITE )) { +int i; +uint32_t cs =extract32 (s->cmd[3 ],8 ,2 ); +for (i =0 ; i <4 && s->cmd[2 ]; i++, s->cmd[2 ]--) { + ret =deposit32 (ret, i *8 ,8 , +ssi_transfer (s->spi,0x00 ) &0xff ); + } +if (!s->cmd[2 ]) { +qemu_set_irq (s->cs_lines[cs],1 ); +if (s->cmd[3 ] &CMD3_INTR ) { + s->isr |=ISR_CMDFIN ; + } +ftspi020_update_irq (s); + } + } +break ; +/* we don't care */ +default : +qemu_log_mask (LOG_GUEST_ERROR , +"ftspi020: undefined memory access@%#" HWADDR_PRIx"\n" , addr); +break ; + } + +return ret; +} + +static void +ftspi020_mem_write (void *opaque,hwaddr addr,uint64_t val,unsigned size) +{ +Ftspi020State *s =FTSPI020 (opaque); + +switch (addr) { + case REG_CMD0 ... REG_CMD2: + s->cmd[(addr -REG_CMD0 ) /4 ] = (uint32_t )val; +break ; +case REG_CMD3 : + s->cmd[3 ] = (uint32_t )val; +ftspi020_do_command (s); +break ; +case REG_CR : +if (val &CR_ABORT ) { +ftspi020_chip_reset (s); + val &= ~CR_ABORT ; + } + s->ctrl = (uint32_t )val; + s->wip =extract32 (val,16 ,3 ); +break ; +case REG_TR : + s->timing = (uint32_t )val; +break ; +case REG_DR : +if (s->cmd[3 ] &CMD3_WRITE ) { +int i; +uint32_t cs =extract32 (s->cmd[3 ],8 ,2 ); +for (i =0 ; i <4 && s->cmd[2 ]; i++, s->cmd[2 ]--) { +ssi_transfer (s->spi,extract32 ((uint32_t )val, i *8 ,8 )); + } +if (!s->cmd[2 ]) { +qemu_set_irq (s->cs_lines[cs],1 ); +if (s->cmd[3 ] &CMD3_INTR ) { + s->isr |=ISR_CMDFIN ; + } +ftspi020_update_irq (s); + } + } +break ; +case REG_ISR : + s->isr &= ~((uint32_t )val); +ftspi020_update_irq (s); +break ; +case REG_ICR : + s->icr = (uint32_t )val; +break ; +/* we don't care */ +default : +qemu_log_mask (LOG_GUEST_ERROR , +"ftspi020: undefined memory access@%#" HWADDR_PRIx"\n" , addr); +break ; + } +} + +static const MemoryRegionOps mmio_ops = { + .read = ftspi020_mem_read, + .write = ftspi020_mem_write, + .endianness =DEVICE_LITTLE_ENDIAN , + .valid = { + .min_access_size =4 , + .max_access_size =4 , + } +}; + +static void ftspi020_reset (DeviceState *ds) +{ +Ftspi020State *s =FTSPI020 (SYS_BUS_DEVICE (ds)); + +ftspi020_chip_reset (s); +} + +static void ftspi020_realize (DeviceState *dev,Error **errp) +{ +Ftspi020State *s =FTSPI020 (dev); +SysBusDevice *sbd =SYS_BUS_DEVICE (dev); +int i; + +memory_region_init_io (&s->iomem, + &mmio_ops, + s, +TYPE_FTSPI020 , +0x1000 ); +sysbus_init_mmio (sbd, &s->iomem); +sysbus_init_irq (sbd, &s->irq); + + s->spi =ssi_create_bus (&sbd->qdev,"spi" ); + s->cs_lines =g_new0 (qemu_irq,CFG_NR_CSLINES ); +ssi_auto_connect_slaves (dev, s->cs_lines, s->spi); +for (i =0 ; i <CFG_NR_CSLINES ; ++i) { +sysbus_init_irq (sbd, &s->cs_lines[i]); + } + +qdev_init_gpio_in (&sbd->qdev, ftspi020_handle_ack,1 ); +qdev_init_gpio_out (&sbd->qdev, &s->req,1 ); +} + +static const VMStateDescription vmstate_ftspi020 = { + .name =TYPE_FTSPI020 , + .version_id =1 , + .minimum_version_id =1 , + .minimum_version_id_old =1 , + .fields = (VMStateField []) { +VMSTATE_UINT32_ARRAY (cmd, Ftspi020State,4 ), +VMSTATE_UINT32 (ctrl, Ftspi020State), +VMSTATE_UINT32 (timing, Ftspi020State), +VMSTATE_UINT32 (icr, Ftspi020State), +VMSTATE_UINT32 (isr, Ftspi020State), +VMSTATE_UINT32 (rdsr, Ftspi020State), +VMSTATE_END_OF_LIST (), + } +}; + +static void ftspi020_class_init (ObjectClass *klass,void *data) +{ +DeviceClass *dc =DEVICE_CLASS (klass); + + dc->vmsd = &vmstate_ftspi020; + dc->reset = ftspi020_reset; + dc->realize = ftspi020_realize; + dc->no_user =1 ; +} + +static const TypeInfo ftspi020_info = { + .name =TYPE_FTSPI020 , + .parent =TYPE_SYS_BUS_DEVICE , + .instance_size =sizeof (Ftspi020State), + .class_init = ftspi020_class_init, +}; + +static void ftspi020_register_types (void ) +{ +type_register_static (&ftspi020_info); +} + +type_init (ftspi020_register_types)hw/ftspi020.h new file +81
-1@@ -0,0 +1,81 @@ +/* +* Faraday FTSPI020 Flash Controller +* +* Copyright (c) 2012 Faraday Technology +* Written by Dante Su <[email protected]> +* +* This code is licensed under GNU GPL v2+. +*/ + +#ifndef HW_ARM_FTSPI020_H +#define HW_ARM_FTSPI020_H + +#include "qemu/bitops.h" + +/* Number of CS lines */ +#define CFG_NR_CSLINES 4 + +/****************************************************************************** +* FTSPI020 registers +*****************************************************************************/ +#define REG_CMD0 0x00/* Flash address */ +#define REG_CMD1 0x04 +#define REG_CMD2 0x08/* Flash data counter */ +#define REG_CMD3 0x0c +#define REG_CR 0x10/* Control Register */ +#define REG_TR 0x14/* AC Timing Register */ +#define REG_SR 0x18/* Status Register */ +#define REG_ICR 0x20/* Interrupt Control Register */ +#define REG_ISR 0x24/* Interrupt Status Register */ +#define REG_RDSR 0x28/* Read Status Register */ +#define REG_REVR 0x50/* Revision Register */ +#define REG_FEAR 0x54/* Feature Register */ +#define REG_DR 0x100/* Data Register */ + +#define CMD1_CTRD BIT(28)/* Enable 1 byte continuous read */ +#define CMD1_INST_LEN (x) (((x) & 0x03) << 24)/* instruction length */ +#define CMD1_DCLK_LEN (x) (((x) & 0xff) << 16)/* dummy clock length */ +#define CMD1_ADDR_LEN (x) (((x) & 0x07) << 0)/* address length */ + +#define CMD3_INST_OPC (x) (((x) & 0xff) << 24)/* instruction op code */ +#define CMD3_CTRD_OPC (x) (((x) & 0xff) << 16)/* cont. read op code */ +#define CMD3_CS (x) (((x) & 0x0f) << 8)/* chip select */ +#define CMD3_OPM_STD (0)/* standard 1-bit serial mode */ +#define CMD3_OPM_DUAL (1 << 5)/* fast read dual */ +#define CMD3_OPM_QUAD (2 << 5)/* fast read quad */ +#define CMD3_OPM_DUALIO (3 << 5)/* fast read dual io */ +#define CMD3_OPM_QUADIO (4 << 5)/* fast read quad io */ +#define CMD3_DTR BIT(4)/* Enable double transfer rate */ +#define CMD3_RDSR_HW (0)/* Enable HW polling RDSR */ +#define CMD3_RDSR_SW BIT(3)/* Disable HW polling RDSR */ +#define CMD3_RDSR BIT(2)/* Indicate it's a RDSR command */ +#define CMD3_READ 0/* Indicate it's a read command */ +#define CMD3_WRITE BIT(1)/* Indicate it's a write command */ +#define CMD3_INTR BIT(0)/* Enable interrupt and status update */ + +#define CR_BUSYBIT (x) (((x) & 0x07) << 16)/* Busy bit in the RDSR */ +#define CR_ABORT BIT(8) +#define CR_MODE0 0/* SPI MODE0 */ +#define CR_MODE3 BIT(4)/* SPI MODE3 */ +#define CR_CLKDIV (n) ((n) & 0x03)/* Clock divider = 2 * (n + 1) */ + +#define TR_TRACE (x) (((x) & 0x0f) << 4)/* trace delay */ +#define TR_CS (x) (((x) & 0x0f) << 0)/* cs delay */ + +#define SR_RX_READY BIT(1)/* Rx Ready */ +#define SR_TX_READY BIT(0)/* Tx Ready */ + +#define ICR_RX_THRES (x) (((x) & 0x03) << 12)/* rx interrupt threshold */ +#define ICR_TX_THRES (x) (((x) & 0x03) << 8)/* tx interrupt threshold */ +#define ICR_DMA BIT(0)/* Enable DMA HW handshake */ + +#define ISR_CMDFIN BIT(0)/* Command finished interrupt */ + +#define FEAR_CLKM_BYPORT 0/* clock mode = byport */ +#define FEAR_CLKM_SYNC BIT(25)/* clock mode = sync */ +#define FEAR_SUPP_DTR BIT(24)/* support double transfer rate */ +#define FEAR_CMDQ (x) (((x) & 0x07) << 16)/* cmd queue depth */ +#define FEAR_RXFIFO (x) (((x) & 0xff) << 8)/* rx fifo depth */ +#define FEAR_TXFIFO (x) (((x) & 0xff) << 0)/* tx fifo depth */ + +#endif /* HW_ARM_FTSPI020_H */ --1.7.9.5
Re: [Qemu-devel] [PATCH v9 24/24] hw/arm: add FTSPI020 SPI flash controller support
2013/3/29 Peter Crosthwaite <[email protected]>:
Quoted 39 lines
Hi Kuo-Jung,
Quoted 36 lines · Kuo-Jung Su
From: Kuo-Jung Su <[email protected]>
The FTSPI020 is an integrated SPI Flash controller which supports up to 4 flash chips.
Signed-off-by Kuo-Jung Su <[email protected]>--- hw/arm/Makefile.objs | 2 +- hw/arm/ftplat_a369.c | 16 +++ hw/ftspi020.c | 341 ++++++++++++++++++++++++++++++++++++++++++++++++++ hw/ftspi020.h | 81 ++++++++++++ 4 files changed, 439 insertions(+), 1 deletion(-) create mode 100644 hw/ftspi020.c create mode 100644 hw/ftspi020.hhw/arm/Makefile.objs +1
-1@@ -27,7 +27,7 @@ obj-$(CONFIG_KVM) += kvm/arm_gic.o obj-y += ftintc020.o ftahbc020.o ftddrii030.o ftpwmtmr010.o ftwdt010.o \ ftrtc011.o ftdmac020.o ftapbbrg020.o ftnandc021.o fti2c010.o \ ftssp010.o ftgmac100.o ftlcdc200.o fttsc010.o ftsdc010.o \ - ftmac110.o fttmr010.o + ftmac110.o fttmr010.o ftspi020.o obj-y := $(addprefix ../,$(obj-y))hw/arm/ftplat_a369.c +0
-0@@ -125,6 +125,22 @@ static void a369_board_init(QEMUMachineInitArgs *args)sysbus_connect_irq (SYS_BUS_DEVICE (ds),1 , s->pic[6 ]);sysbus_connect_irq (SYS_BUS_DEVICE (ds),2 , s->pic[7 ]);
Quoted 16 lines
hw/arm/ftplat_a369.c static void a369_board_init(QEMUMachineInitArgs *args) · line 136
Quoted 9 lines
hw/arm/ftplat_a369.c +9
-0+/* SPI: FTSPI020 */ + ds =sysbus_create_simple ("ftspi020" ,0xC0000000 , s->pic[4 ]); + s->spi_fl[0 ] = ds; + +/* Attach the spi flash to ftspi020.0 */ + nr_flash =1 ; +for (i =0 ; i < nr_flash; i++) { +SSIBus *ssi = (SSIBus *)qdev_get_child_bus (s->spi_fl[0 ],"spi" ); +DeviceState *fl =ssi_create_slave_no_init (ssi,"w25q64" );You
qdev_initstraight away, so you can just callssi_create_slave. This is just a hangover from my recent m25p80 cleanup which made the original reason forcreate_slave_no_initredundant. I'll have to send some cleanup patches for my own machine models with the equivalent change. s/ssi_create_slave_no_init/ssi_create_slave and ...
Got it, thanks
Quoted 446 lines
hw/arm/ftplat_a369.c static void a369_board_init(QEMUMachineInitArgs *args) · line 139
Quoted 3 lines
hw/arm/ftplat_a369.c +3
-0+qemu_irq cs_line; + +qdev_init_nofail (fl);... dump this.
Regards,
PeterQuoted 437 lines
hw/arm/ftplat_a369.c +4
-0+ cs_line =qdev_get_gpio_in (fl,0 ); +sysbus_connect_irq (SYS_BUS_DEVICE (s->spi_fl[0 ]), i +1 , cs_line); + } +/* System start-up */ if (args->kernel_filename) {hw/ftspi020.c new file +341
-0@@ -0,0 +1,341 @@ +/* +* Faraday FTSPI020 Flash Controller +* +* Copyright (c) 2012 Faraday Technology +* Written by Dante Su <[email protected]> +* +* This code is licensed under GNU GPL v2+. +*/ + +#include "hw/hw.h" +#include "hw/sysbus.h" +#include "hw/ssi.h" +#include "sysemu/sysemu.h" + +#include "hw/ftspi020.h" + +#define TYPE_FTSPI020 "ftspi020" + +typedef struct Ftspi020State { +/*< private >*/ +SysBusDevice parent; + +/*< public >*/ +MemoryRegion iomem; +qemu_irq irq; + +/* DMA hardware handshake */ +qemu_irq req; + +SSIBus *spi; +qemu_irq *cs_lines; + +int wip;/* SPI Flash Status: Write In Progress BIT shift */ + +/* HW register caches */ +uint32_t cmd[4 ]; +uint32_t ctrl; +uint32_t timing; +uint32_t icr; +uint32_t isr; +uint32_t rdsr; +}Ftspi020State ; + +#define FTSPI020 (obj) \ + OBJECT_CHECK(Ftspi020State, obj, TYPE_FTSPI020) + +static void ftspi020_update_irq (Ftspi020State *s) +{ +qemu_set_irq (s->irq, s->isr ?1 :0 ); +} + +static void ftspi020_handle_ack (void *opaque,int line,int level) +{ +Ftspi020State *s =FTSPI020 (opaque); + +if (!(s->icr &ICR_DMA )) { +return ; + } + +if (level) { +qemu_set_irq (s->req,0 ); + }else if (s->cmd[2 ]) { +qemu_set_irq (s->req,1 ); + } +} + +static int ftspi020_do_command (Ftspi020State *s) +{ +uint32_t cs =extract32 (s->cmd[3 ],8 ,2 ); +uint32_t cmd =extract32 (s->cmd[3 ],24 ,8 ); +uint32_t ilen =extract32 (s->cmd[1 ],24 ,2 ); +uint32_t alen =extract32 (s->cmd[1 ],0 ,3 ); +uint32_t dcyc =extract32 (s->cmd[1 ],16 ,8 ); + +if (dcyc %8 ) { +fprintf (stderr,"ftspi020: bad dummy clock (%u) to QEMU\n" , dcyc); +abort (); + } + +/* activate the spi flash */ +qemu_set_irq (s->cs_lines[cs],0 ); + +/* if it's a SPI flash READ_STATUS command */ +if ((s->cmd[3 ] & (CMD3_RDSR |CMD3_WRITE )) ==CMD3_RDSR ) { +uint32_t rdsr; + +ssi_transfer (s->spi, cmd); +do { + rdsr =ssi_transfer (s->spi,0x00 ); +if (s->cmd[3 ] &CMD3_RDSR_SW ) { +break ; + } + }while (rdsr & (1 << s->wip)); + s->rdsr = rdsr; + }else { +/* otherwise */ +int i; + + ilen =MIN (ilen,2 ); + alen =MIN (alen,4 ); + +/* command cycles */ +for (i =0 ; i < ilen; ++i) { +ssi_transfer (s->spi, cmd); + } +/* address cycles */ +for (i = alen -1 ; i >=0 ; --i) { +ssi_transfer (s->spi,extract32 (s->cmd[0 ], i *8 ,8 )); + } +/* dummy cycles */ +for (i =0 ; i < (dcyc >>3 ); ++i) { +ssi_transfer (s->spi,0x00 ); + } + } + +if (!s->cmd[2 ]) { +qemu_set_irq (s->cs_lines[cs],1 ); + }else if (s->icr &ICR_DMA ) { +qemu_set_irq (s->req,1 ); + } + +if (s->cmd[3 ] &CMD3_INTR ) { + s->isr |=ISR_CMDFIN ; + } +ftspi020_update_irq (s); + +return 0 ; +} + +static void ftspi020_chip_reset (Ftspi020State *s) +{ +int i; + +for (i =0 ; i <4 ; ++i) { + s->cmd[i] =0 ; + } + s->wip =0 ; + s->ctrl =0 ; + s->timing =0 ; + s->icr =0 ; + s->isr =0 ; + s->rdsr =0 ; + +qemu_set_irq (s->irq,0 ); + +for (i =0 ; i <CFG_NR_CSLINES ; ++i) { +/* de-activate the spi flash */ +qemu_set_irq (s->cs_lines[i],1 ); + } +} + +static uint64_t +ftspi020_mem_read (void *opaque,hwaddr addr,unsigned size) +{ +Ftspi020State *s =FTSPI020 (opaque); +uint64_t ret =0 ; + +switch (addr) { + case REG_CMD0 ... REG_CMD3: +return s->cmd[(addr -REG_CMD0 ) /4 ]; +case REG_CR : +return s->ctrl; +case REG_TR : +return s->timing; +case REG_SR : +/* In QEMU, the data fifo is always ready for read/write */ +return SR_RX_READY |SR_TX_READY ; +case REG_ISR : +return s->isr; +case REG_ICR : +return s->icr; +case REG_RDSR : +return s->rdsr; +case REG_REVR : +return 0x00010001 ;/* rev. 1.0.1 */ +case REG_FEAR : +return FEAR_CLKM_SYNC + |FEAR_CMDQ (2 ) |FEAR_RXFIFO (32 ) |FEAR_TXFIFO (32 ); +case REG_DR : +if (!(s->cmd[3 ] &CMD3_WRITE )) { +int i; +uint32_t cs =extract32 (s->cmd[3 ],8 ,2 ); +for (i =0 ; i <4 && s->cmd[2 ]; i++, s->cmd[2 ]--) { + ret =deposit32 (ret, i *8 ,8 , +ssi_transfer (s->spi,0x00 ) &0xff ); + } +if (!s->cmd[2 ]) { +qemu_set_irq (s->cs_lines[cs],1 ); +if (s->cmd[3 ] &CMD3_INTR ) { + s->isr |=ISR_CMDFIN ; + } +ftspi020_update_irq (s); + } + } +break ; +/* we don't care */ +default : +qemu_log_mask (LOG_GUEST_ERROR , +"ftspi020: undefined memory access@%#" HWADDR_PRIx"\n" , addr); +break ; + } + +return ret; +} + +static void +ftspi020_mem_write (void *opaque,hwaddr addr,uint64_t val,unsigned size) +{ +Ftspi020State *s =FTSPI020 (opaque); + +switch (addr) { + case REG_CMD0 ... REG_CMD2: + s->cmd[(addr -REG_CMD0 ) /4 ] = (uint32_t )val; +break ; +case REG_CMD3 : + s->cmd[3 ] = (uint32_t )val; +ftspi020_do_command (s); +break ; +case REG_CR : +if (val &CR_ABORT ) { +ftspi020_chip_reset (s); + val &= ~CR_ABORT ; + } + s->ctrl = (uint32_t )val; + s->wip =extract32 (val,16 ,3 ); +break ; +case REG_TR : + s->timing = (uint32_t )val; +break ; +case REG_DR : +if (s->cmd[3 ] &CMD3_WRITE ) { +int i; +uint32_t cs =extract32 (s->cmd[3 ],8 ,2 ); +for (i =0 ; i <4 && s->cmd[2 ]; i++, s->cmd[2 ]--) { +ssi_transfer (s->spi,extract32 ((uint32_t )val, i *8 ,8 )); + } +if (!s->cmd[2 ]) { +qemu_set_irq (s->cs_lines[cs],1 ); +if (s->cmd[3 ] &CMD3_INTR ) { + s->isr |=ISR_CMDFIN ; + } +ftspi020_update_irq (s); + } + } +break ; +case REG_ISR : + s->isr &= ~((uint32_t )val); +ftspi020_update_irq (s); +break ; +case REG_ICR : + s->icr = (uint32_t )val; +break ; +/* we don't care */ +default : +qemu_log_mask (LOG_GUEST_ERROR , +"ftspi020: undefined memory access@%#" HWADDR_PRIx"\n" , addr); +break ; + } +} + +static const MemoryRegionOps mmio_ops = { + .read = ftspi020_mem_read, + .write = ftspi020_mem_write, + .endianness =DEVICE_LITTLE_ENDIAN , + .valid = { + .min_access_size =4 , + .max_access_size =4 , + } +}; + +static void ftspi020_reset (DeviceState *ds) +{ +Ftspi020State *s =FTSPI020 (SYS_BUS_DEVICE (ds)); + +ftspi020_chip_reset (s); +} + +static void ftspi020_realize (DeviceState *dev,Error **errp) +{ +Ftspi020State *s =FTSPI020 (dev); +SysBusDevice *sbd =SYS_BUS_DEVICE (dev); +int i; + +memory_region_init_io (&s->iomem, + &mmio_ops, + s, +TYPE_FTSPI020 , +0x1000 ); +sysbus_init_mmio (sbd, &s->iomem); +sysbus_init_irq (sbd, &s->irq); + + s->spi =ssi_create_bus (&sbd->qdev,"spi" ); + s->cs_lines =g_new0 (qemu_irq,CFG_NR_CSLINES ); +ssi_auto_connect_slaves (dev, s->cs_lines, s->spi); +for (i =0 ; i <CFG_NR_CSLINES ; ++i) { +sysbus_init_irq (sbd, &s->cs_lines[i]); + } + +qdev_init_gpio_in (&sbd->qdev, ftspi020_handle_ack,1 ); +qdev_init_gpio_out (&sbd->qdev, &s->req,1 ); +} + +static const VMStateDescription vmstate_ftspi020 = { + .name =TYPE_FTSPI020 , + .version_id =1 , + .minimum_version_id =1 , + .minimum_version_id_old =1 , + .fields = (VMStateField []) { +VMSTATE_UINT32_ARRAY (cmd, Ftspi020State,4 ), +VMSTATE_UINT32 (ctrl, Ftspi020State), +VMSTATE_UINT32 (timing, Ftspi020State), +VMSTATE_UINT32 (icr, Ftspi020State), +VMSTATE_UINT32 (isr, Ftspi020State), +VMSTATE_UINT32 (rdsr, Ftspi020State), +VMSTATE_END_OF_LIST (), + } +}; + +static void ftspi020_class_init (ObjectClass *klass,void *data) +{ +DeviceClass *dc =DEVICE_CLASS (klass); + + dc->vmsd = &vmstate_ftspi020; + dc->reset = ftspi020_reset; + dc->realize = ftspi020_realize; + dc->no_user =1 ; +} + +static const TypeInfo ftspi020_info = { + .name =TYPE_FTSPI020 , + .parent =TYPE_SYS_BUS_DEVICE , + .instance_size =sizeof (Ftspi020State), + .class_init = ftspi020_class_init, +}; + +static void ftspi020_register_types (void ) +{ +type_register_static (&ftspi020_info); +} + +type_init (ftspi020_register_types)hw/ftspi020.h new file +77
-0@@ -0,0 +1,81 @@ +/* +* Faraday FTSPI020 Flash Controller +* +* Copyright (c) 2012 Faraday Technology +* Written by Dante Su <[email protected]> +* +* This code is licensed under GNU GPL v2+. +*/ + +#ifndef HW_ARM_FTSPI020_H +#define HW_ARM_FTSPI020_H + +#include "qemu/bitops.h" + +/* Number of CS lines */ +#define CFG_NR_CSLINES 4 + +/****************************************************************************** +* FTSPI020 registers +*****************************************************************************/ +#define REG_CMD0 0x00/* Flash address */ +#define REG_CMD1 0x04 +#define REG_CMD2 0x08/* Flash data counter */ +#define REG_CMD3 0x0c +#define REG_CR 0x10/* Control Register */ +#define REG_TR 0x14/* AC Timing Register */ +#define REG_SR 0x18/* Status Register */ +#define REG_ICR 0x20/* Interrupt Control Register */ +#define REG_ISR 0x24/* Interrupt Status Register */ +#define REG_RDSR 0x28/* Read Status Register */ +#define REG_REVR 0x50/* Revision Register */ +#define REG_FEAR 0x54/* Feature Register */ +#define REG_DR 0x100/* Data Register */ + +#define CMD1_CTRD BIT(28)/* Enable 1 byte continuous read */ +#define CMD1_INST_LEN (x) (((x) & 0x03) << 24)/* instruction length */ +#define CMD1_DCLK_LEN (x) (((x) & 0xff) << 16)/* dummy clock length */ +#define CMD1_ADDR_LEN (x) (((x) & 0x07) << 0)/* address length */ + +#define CMD3_INST_OPC (x) (((x) & 0xff) << 24)/* instruction op code */ +#define CMD3_CTRD_OPC (x) (((x) & 0xff) << 16)/* cont. read op code */ +#define CMD3_CS (x) (((x) & 0x0f) << 8)/* chip select */ +#define CMD3_OPM_STD (0)/* standard 1-bit serial mode */ +#define CMD3_OPM_DUAL (1 << 5)/* fast read dual */ +#define CMD3_OPM_QUAD (2 << 5)/* fast read quad */ +#define CMD3_OPM_DUALIO (3 << 5)/* fast read dual io */ +#define CMD3_OPM_QUADIO (4 << 5)/* fast read quad io */ +#define CMD3_DTR BIT(4)/* Enable double transfer rate */ +#define CMD3_RDSR_HW (0)/* Enable HW polling RDSR */ +#define CMD3_RDSR_SW BIT(3)/* Disable HW polling RDSR */ +#define CMD3_RDSR BIT(2)/* Indicate it's a RDSR command */ +#define CMD3_READ 0/* Indicate it's a read command */ +#define CMD3_WRITE BIT(1)/* Indicate it's a write command */ +#define CMD3_INTR BIT(0)/* Enable interrupt and status update */ + +#define CR_BUSYBIT (x) (((x) & 0x07) << 16)/* Busy bit in the RDSR */ +#define CR_ABORT BIT(8) +#define CR_MODE0 0/* SPI MODE0 */ +#define CR_MODE3 BIT(4)/* SPI MODE3 */ +#define CR_CLKDIV (n) ((n) & 0x03)/* Clock divider = 2 * (n + 1) */ + +#define TR_TRACE (x) (((x) & 0x0f) << 4)/* trace delay */ +#define TR_CS (x) (((x) & 0x0f) << 0)/* cs delay */ + +#define SR_RX_READY BIT(1)/* Rx Ready */ +#define SR_TX_READY BIT(0)/* Tx Ready */ + +#define ICR_RX_THRES (x) (((x) & 0x03) << 12)/* rx interrupt threshold */ +#define ICR_TX_THRES (x) (((x) & 0x03) << 8)/* tx interrupt threshold */ +#define ICR_DMA BIT(0)/* Enable DMA HW handshake */ + +#define ISR_CMDFIN BIT(0)/* Command finished interrupt */ + +#define FEAR_CLKM_BYPORT 0/* clock mode = byport */ +#define FEAR_CLKM_SYNC BIT(25)/* clock mode = sync */ +#define FEAR_SUPP_DTR BIT(24)/* support double transfer rate */ +#define FEAR_CMDQ (x) (((x) & 0x07) << 16)/* cmd queue depth */
Quoted 8 lines
Quoted 8 lines
hw/ftspi020.h new file +4
-1+#define FEAR_RXFIFO (x) (((x) & 0xff) << 8)/* rx fifo depth */ +#define FEAR_TXFIFO (x) (((x) & 0xff) << 0)/* tx fifo depth */ + +#endif /* HW_ARM_FTSPI020_H */ --1.7.9.5
--
Best wishes,
Kuo-Jung Su