Skip to contentSkip to conversation

Add Faraday A369 SoC platform support

PATCH Superseded Kuo-Jung Su 6 participants 48 messages Mar 6, 2013 – Mar 12, 2013

v6 of 9 Superseded Latest is v9 →

lore
Share & tools
lore
#0 lore raw

v6 cover Add Faraday A369 SoC platform support

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 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 Faraday FTINTC020 interrupt controller support hw/arm: add Faraday FTAHBC020 support
hw/arm: add Faraday FTDDRII030 support
hw/arm: add Faraday FTPWMTMR010 timer support
hw/arm: add Faraday FTWDT010 watchdog timer support hw/arm: add Faraday FTRTC011 RTC timer support
hw/arm: add Faraday FTDMAC020 AHB DMA support
hw/arm: add Faraday FTAPBBRG020 APB DMA support hw/nand.c: correct the sense of the BUSY/READY status bit hw/nand.c: bug fix to erase operation
hw/arm: add Faraday FTNANDC021 nand flash controller support hw/arm: add Faraday FTI2C010 I2C controller support
hw: add WM8731 codec support
hw/arm: add Faraday FTSSP010 multi-function controller support qemu/bitops.h: add the bit ordering reversal functions stolen from
linux
hw/arm: add Faraday FTGMAC100 1Gbps ethernet support hw/arm: add Faraday FTLCDC200 LCD controller support hw/arm: add Faraday FTTSC010 touchscreen controller support hw/arm: add Faraday FTSDC010 MMC/SD controller support hw/arm: add Faraday FTMAC110 10/100Mbps ethernet support hw/arm: add Faraday FTTMR010 timer support
hw/arm: add Faraday FTSPI020 SPI flash controller support

 default-configs/arm-softmmu.mak |    1 +
 hw/Makefile.objs                |    1 +
 hw/arm/Makefile.objs            |   20 ++
 hw/arm/faraday.h                |   73 ++++
 hw/arm/faraday_a369.c           |  151 +++++++++
 hw/arm/faraday_a369_kpd.c       |  235 +++++++++++++
 hw/arm/faraday_a369_scu.c       |  186 +++++++++++
 hw/arm/faraday_a369_soc.c       |  328 ++++++++++++++++++
 hw/arm/ftahbc020.c              |  190 +++++++++++
 hw/arm/ftapbbrg020.c            |  457 +++++++++++++++++++++++++
 hw/arm/ftapbbrg020.h            |   44 +++
 hw/arm/ftddrii030.c             |  170 ++++++++++
 hw/arm/ftdmac020.c              |  599 +++++++++++++++++++++++++++++++++
 hw/arm/ftdmac020.h              |  107 ++++++
 hw/arm/ftgmac100.c              |  696 +++++++++++++++++++++++++++++++++++++++
 hw/arm/ftgmac100.h              |  239 ++++++++++++++
 hw/arm/fti2c010.c               |  216 ++++++++++++
 hw/arm/fti2c010.h               |   71 ++++
 hw/arm/ftintc020.c              |  306 +++++++++++++++++
 hw/arm/ftintc020.h              |   57 ++++
 hw/arm/ftkbc010.h               |   44 +++
 hw/arm/ftlcdc200.c              |  513 +++++++++++++++++++++++++++++
 hw/arm/ftlcdc200.h              |  112 +++++++
 hw/arm/ftlcdc200_template.h     |  439 ++++++++++++++++++++++++
 hw/arm/ftmac110.c               |  649 ++++++++++++++++++++++++++++++++++++
 hw/arm/ftmac110.h               |  168 ++++++++++
 hw/arm/ftnandc021.c             |  512 ++++++++++++++++++++++++++++
 hw/arm/ftnandc021.h             |   84 +++++
 hw/arm/ftpwmtmr010.c            |  264 +++++++++++++++
 hw/arm/ftpwmtmr010.h            |   31 ++
 hw/arm/ftrtc011.c               |  346 +++++++++++++++++++
 hw/arm/ftrtc011.h               |   49 +++
 hw/arm/ftsdc010.c               |  358 ++++++++++++++++++++
 hw/arm/ftsdc010.h               |   90 +++++
 hw/arm/ftspi020.c               |  340 +++++++++++++++++++
 hw/arm/ftspi020.h               |   81 +++++
 hw/arm/ftssp010.c               |  492 +++++++++++++++++++++++++++
 hw/arm/ftssp010.h               |   98 ++++++
 hw/arm/fttmr010.c               |  451 +++++++++++++++++++++++++
 hw/arm/fttmr010.h               |   41 +++
 hw/arm/fttsc010.c               |  264 +++++++++++++++
 hw/arm/fttsc010.h               |   39 +++
 hw/arm/ftwdt010.c               |  212 ++++++++++++
 hw/arm/ftwdt010.h               |   35 ++
 hw/i2c.h                        |    6 +
 hw/nand.c                       |    4 +-
 hw/wm8731.c                     |  499 ++++++++++++++++++++++++++++
 include/qemu/bitops.h           |   63 +++-
 target-arm/cpu.c                |   52 +++
 target-arm/cpu.h                |    6 +-
 target-arm/helper.c             |   84 +++++
 target-arm/machine.c            |    4 +
 52 files changed, 10574 insertions(+), 3 deletions(-)
 create mode 100644 hw/arm/faraday.h
 create mode 100644 hw/arm/faraday_a369.c
 create mode 100644 hw/arm/faraday_a369_kpd.c
 create mode 100644 hw/arm/faraday_a369_scu.c
 create mode 100644 hw/arm/faraday_a369_soc.c
 create mode 100644 hw/arm/ftahbc020.c
 create mode 100644 hw/arm/ftapbbrg020.c
 create mode 100644 hw/arm/ftapbbrg020.h
 create mode 100644 hw/arm/ftddrii030.c
 create mode 100644 hw/arm/ftdmac020.c
 create mode 100644 hw/arm/ftdmac020.h
 create mode 100644 hw/arm/ftgmac100.c
 create mode 100644 hw/arm/ftgmac100.h
 create mode 100644 hw/arm/fti2c010.c
 create mode 100644 hw/arm/fti2c010.h
 create mode 100644 hw/arm/ftintc020.c
 create mode 100644 hw/arm/ftintc020.h
 create mode 100644 hw/arm/ftkbc010.h
 create mode 100644 hw/arm/ftlcdc200.c
 create mode 100644 hw/arm/ftlcdc200.h
 create mode 100644 hw/arm/ftlcdc200_template.h
 create mode 100644 hw/arm/ftmac110.c
 create mode 100644 hw/arm/ftmac110.h
 create mode 100644 hw/arm/ftnandc021.c
 create mode 100644 hw/arm/ftnandc021.h
 create mode 100644 hw/arm/ftpwmtmr010.c
 create mode 100644 hw/arm/ftpwmtmr010.h
 create mode 100644 hw/arm/ftrtc011.c
 create mode 100644 hw/arm/ftrtc011.h
 create mode 100644 hw/arm/ftsdc010.c
 create mode 100644 hw/arm/ftsdc010.h
 create mode 100644 hw/arm/ftspi020.c
 create mode 100644 hw/arm/ftspi020.h
 create mode 100644 hw/arm/ftssp010.c
 create mode 100644 hw/arm/ftssp010.h
 create mode 100644 hw/arm/fttmr010.c
 create mode 100644 hw/arm/fttmr010.h
 create mode 100644 hw/arm/fttsc010.c
 create mode 100644 hw/arm/fttsc010.h
 create mode 100644 hw/arm/ftwdt010.c
 create mode 100644 hw/arm/ftwdt010.h
 create mode 100644 hw/wm8731.c
Signature · 1 line
1.7.9.5
#1 lore raw

PATCH v6 1/24 target-arm: add Faraday ARMv5TE processors support

From: Dante <[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
index 5dfcb74..99b7244 100644
@@ -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);
@@ -756,6 +804,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
index c28a0d9..e4c43ef 100644
@@ -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 {
@@ -393,6 +395,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)
@@ -641,7 +645,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
index 68dca7f..ed63614 100644
@@ -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
#2 lore raw

PATCH v6 2/24 hw/arm: add Faraday a369 SoC platform support

In reply to Kuo-Jung Su

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/faraday.h          |   64 ++++++++++++
 hw/arm/faraday_a369.c     |   98 +++++++++++++++++++
 hw/arm/faraday_a369_kpd.c |  235 +++++++++++++++++++++++++++++++++++++++++++++
 hw/arm/faraday_a369_scu.c |  186 +++++++++++++++++++++++++++++++++++
 hw/arm/faraday_a369_soc.c |  193 +++++++++++++++++++++++++++++++++++++
 hw/arm/ftkbc010.h         |   44 +++++++++
 7 files changed, 822 insertions(+)
 create mode 100644 hw/arm/faraday.h
 create mode 100644 hw/arm/faraday_a369.c
 create mode 100644 hw/arm/faraday_a369_kpd.c
 create mode 100644 hw/arm/faraday_a369_scu.c
 create mode 100644 hw/arm/faraday_a369_soc.c
 create mode 100644 hw/arm/ftkbc010.h
hw/arm/Makefile.objs +2 -0
index 0e7df60..eaeeb3e 100644
@@ -35,3 +35,5 @@ obj-$(CONFIG_FDT) += ../device_tree.o
 obj-$(CONFIG_KVM) += kvm/arm_gic.o
 
 obj-y := $(addprefix ../,$(obj-y))
+obj-y += faraday_a369.o faraday_a369_soc.o faraday_a369_scu.o \
+				faraday_a369_kpd.o
hw/arm/faraday.h new file +64 -0

64 lines not on this page · raw message

hw/arm/faraday_a369.c new file +98 -0

98 lines not on this page · raw message

hw/arm/faraday_a369_kpd.c new file +235 -0

235 lines not on this page · raw message

hw/arm/faraday_a369_scu.c new file +186 -0

186 lines not on this page · raw message

hw/arm/faraday_a369_soc.c new file +193 -0

193 lines not on this page · raw message

hw/arm/ftkbc010.h new file +44 -0

44 lines not on this page · raw message

Signature · 1 line
1.7.9.5
#3 lore raw

PATCH v6 3/24 hw/arm: add Faraday FTINTC020 interrupt controller support

In reply to Kuo-Jung Su

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/faraday_a369_soc.c |   11 ++
 hw/arm/ftintc020.c        |  306 +++++++++++++++++++++++++++++++++++++++++++++
 hw/arm/ftintc020.h        |   57 +++++++++
 4 files changed, 375 insertions(+)
 create mode 100644 hw/arm/ftintc020.c
 create mode 100644 hw/arm/ftintc020.h
hw/arm/Makefile.objs +1 -0
index eaeeb3e..1d7ced8 100644
@@ -37,3 +37,4 @@ obj-$(CONFIG_KVM) += kvm/arm_gic.o
 obj-y := $(addprefix ../,$(obj-y))
 obj-y += faraday_a369.o faraday_a369_soc.o faraday_a369_scu.o \
 				faraday_a369_kpd.o
+obj-y += ftintc020.o
hw/arm/faraday_a369_soc.c +11 -0
index c0309e3..d3187b2 100644
@@ -72,6 +72,8 @@ a369soc_device_init(FaradaySoCState *s)
 {
     DriveInfo *dinfo;
     DeviceState *ds;
+    qemu_irq *cpu_pic;
+    int i;
 
     s->as = get_system_memory();
     s->ram = g_new(MemoryRegion, 1);
@@ -111,6 +113,15 @@ a369soc_device_init(FaradaySoCState *s)
         exit(1);
     }
 
+    /* Interrupt Controller */
+    cpu_pic = arm_pic_init_cpu(s->cpu);
+    ds = sysbus_create_varargs("ftintc020", 0x90100000,
+                               cpu_pic[ARM_PIC_CPU_IRQ],
+                               cpu_pic[ARM_PIC_CPU_FIQ], NULL);
+    for (i = 0; i < ARRAY_SIZE(s->pic); ++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/arm/ftintc020.c new file +306 -0

306 lines not on this page · raw message

hw/arm/ftintc020.h new file +57 -0

57 lines not on this page · raw message

Signature · 1 line
1.7.9.5
#4 lore raw

Re: [Qemu-devel] [PATCH v6 03/24] hw/arm: add Faraday FTINTC020 interrupt controller support

Hi Kuo-Jung,

Quoted 63 lines · Kuo-Jung Su

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/faraday_a369_soc.c |   11 ++
 hw/arm/ftintc020.c        |  306 +++++++++++++++++++++++++++++++++++++++++++++
 hw/arm/ftintc020.h        |   57 +++++++++
 4 files changed, 375 insertions(+)
 create mode 100644 hw/arm/ftintc020.c
 create mode 100644 hw/arm/ftintc020.h
hw/arm/Makefile.objs +1 -0
index eaeeb3e..1d7ced8 100644
@@ -37,3 +37,4 @@ obj-$(CONFIG_KVM) += kvm/arm_gic.o
 obj-y := $(addprefix ../,$(obj-y))
 obj-y += faraday_a369.o faraday_a369_soc.o faraday_a369_scu.o \
                                faraday_a369_kpd.o
+obj-y += ftintc020.o
hw/arm/faraday_a369_soc.c +11 -0
index c0309e3..d3187b2 100644
@@ -72,6 +72,8 @@ a369soc_device_init(FaradaySoCState *s)
 {
     DriveInfo *dinfo;
     DeviceState *ds;
+    qemu_irq *cpu_pic;
+    int i;
 
     s->as = get_system_memory();
     s->ram = g_new(MemoryRegion, 1);
@@ -111,6 +113,15 @@ a369soc_device_init(FaradaySoCState *s)
         exit(1);
     }
 
+    /* Interrupt Controller */
+    cpu_pic = arm_pic_init_cpu(s->cpu);
+    ds = sysbus_create_varargs("ftintc020", 0x90100000,
+                               cpu_pic[ARM_PIC_CPU_IRQ],
+                               cpu_pic[ARM_PIC_CPU_FIQ], NULL);
+    for (i = 0; i < ARRAY_SIZE(s->pic); ++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/arm/ftintc020.c new file +3 -0
new file mode 100644
index 0000000..3ee26b9
@@ -0,0 +1,306 @@
+/*
+ * Faraday FTINTC020 Programmable Interrupt Controller.
+ *

hw/arm/ftintc020.c line 13

Quoted 10 lines
hw/arm/ftintc020.c new file +10 -0
+ * 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 "faraday.h"

Why? I think with your v5->v6 refactorings this device model is now self contained as just a pure sysbus device (a good thing). It shouldn't require any awareness of its inclusion in the faraday SoC. Is this header needed, and is it possible to rework any local usages or its definitions?

Quoted 46 lines
hw/arm/ftintc020.c new file +46 -0
+#include "ftintc020.h"
+
+#define TYPE_FTINTC020  "ftintc020"
+
+#define CFG_REGSIZE     (0x100 / 4)
+
+typedef struct Ftintc020State {
+    SysBusDevice busdev;
+    MemoryRegion iomem;
+
+    qemu_irq irq;
+    qemu_irq fiq;
+
+    uint32_t irq_ps[2]; /* IRQ pin state */
+    uint32_t fiq_ps[2]; /* FIQ pin state */
+
+    /* HW register caches */
+    uint32_t regs[CFG_REGSIZE];
+} Ftintc020State;
+
+#define FTINTC020(obj) \
+    OBJECT_CHECK(Ftintc020State, obj, TYPE_FTINTC020)
+
+#define PIC_REG32(s, off) \
+    ((s)->regs[(off) / 4])
+
+#define IRQ_REG32(s, n, off) \
+    ((s)->regs[(REG_IRQ(n) + ((off) & REG_MASK)) / 4])
+
+#define FIQ_REG32(s, n, off) \
+    ((s)->regs[(REG_FIQ(n) + ((off) & REG_MASK)) / 4])
+
+static void
+ftintc020_update_irq(Ftintc020State *s)
+{
+    uint32_t mask[2];
+
+    /* FIQ */
+    mask[0] = PIC_REG32(s, REG_FIQ32SRC) & PIC_REG32(s, REG_FIQ32ENA);
+    mask[1] = PIC_REG32(s, REG_FIQ64SRC) & PIC_REG32(s, REG_FIQ64ENA);
+    qemu_set_irq(s->fiq, !!(mask[0] || mask[1]));
+
+    /* IRQ */
+    mask[0] = PIC_REG32(s, REG_IRQ32SRC) & PIC_REG32(s, REG_IRQ32ENA);
+    mask[1] = PIC_REG32(s, REG_IRQ64SRC) & PIC_REG32(s, REG_IRQ64ENA);
+    qemu_set_irq(s->irq, !!(mask[0] || mask[1]));

hw/arm/ftintc020.c line 69

Quoted 10 lines
hw/arm/ftintc020.c new file +10 -0
+}
+
+/* Note: Here level means state of the signal on a pin */
+static void
+ftintc020_set_irq(void *opaque, int irq, int level)
+{
+    Ftintc020State *s = FTINTC020(opaque);
+    uint32_t i = irq / 32;
+    uint32_t mask = BIT(irq % 32);
+

masking is generally cleaner and more self documenting using & rather than a power-of-two %

Quoted 70 lines
hw/arm/ftintc020.c new file +70 -0
+    switch (irq) {
+    case 0  ... 63:
+        /* IRQ */
+        if (IRQ_REG32(s, irq, REG_MDR) & mask) {
+            /* Edge Triggered */
+            if (IRQ_REG32(s, irq, REG_LVR) & mask) {
+                /* Falling Active */
+                if ((s->irq_ps[i] & mask) && !level) {
+                    IRQ_REG32(s, irq, REG_SRC) |= mask;
+                }
+            } else {
+                /* Rising Active */
+                if (!(s->irq_ps[i] & mask) && level) {
+                    IRQ_REG32(s, irq, REG_SRC) |= mask;
+                }
+            }
+        } else {
+            /* Level Triggered */
+            if (IRQ_REG32(s, irq, REG_LVR) & mask) {
+                /* Low Active */
+                if (level) {
+                    IRQ_REG32(s, irq, REG_SRC) &= ~mask;
+                } else {
+                    IRQ_REG32(s, irq, REG_SRC) |= mask;
+                }
+            } else {
+                /* High Active */
+                if (level) {
+                    IRQ_REG32(s, irq, REG_SRC) |= mask;
+                } else {
+                    IRQ_REG32(s, irq, REG_SRC) &= ~mask;
+                }
+            }
+        }
+
+        /* FIQ */
+        if (FIQ_REG32(s, irq, REG_MDR) & mask) {
+            /* Edge Triggered */
+            if (FIQ_REG32(s, irq, REG_LVR) & mask) {
+                /* Falling Active */
+                if ((s->fiq_ps[i] & mask) && !level) {
+                    FIQ_REG32(s, irq, REG_SRC) |= mask;
+                }
+            } else {
+                /* Rising Active */
+                if (!(s->fiq_ps[i] & mask) && level) {
+                    FIQ_REG32(s, irq, REG_SRC) |= mask;
+                }
+            }
+        } else {
+            /* Level Triggered */
+            if (FIQ_REG32(s, irq, REG_LVR) & mask) {
+                /* Low Active */
+                if (level) {
+                    FIQ_REG32(s, irq, REG_SRC) &= ~mask;
+                } else {
+                    FIQ_REG32(s, irq, REG_SRC) |= mask;
+                }
+            } else {
+                /* High Active */
+                if (level) {
+                    FIQ_REG32(s, irq, REG_SRC) |= mask;
+                } else {
+                    FIQ_REG32(s, irq, REG_SRC) &= ~mask;
+                }
+            }
+        }
+        /* update IRQ/FIQ pin states */
+        if (level) {
+            s->irq_ps[i] |= mask;

hw/arm/ftintc020.c line 149

Quoted 10 lines
hw/arm/ftintc020.c new file +10 -0
+            s->fiq_ps[i] |= mask;
+        } else {
+            s->irq_ps[i] &= ~mask;
+            s->fiq_ps[i] &= ~mask;
+        }
+        break;
+
+    default:
+        fprintf(stderr, "ftintc020: undefined irq=%d\n", irq);
+        exit(1);

abort() is generally more helpful for these hard error cases. Although theres probably a more modern solution using the error framework.

Quoted 126 lines
hw/arm/ftintc020.c new file +126 -0
+    }
+
+    ftintc020_update_irq(s);
+}
+
+static uint64_t
+ftintc020_mem_read(void *opaque, hwaddr addr, unsigned size)
+{
+    Ftintc020State *s = FTINTC020(opaque);
+    uint32_t ret = 0;
+
+    if (addr > REG_FIQ64SR) {
+        qemu_log_mask(LOG_GUEST_ERROR,
+            "ftintc020: undefined memory access@%#" HWADDR_PRIx "\n", addr);
+        return ret;
+    }
+
+    switch (addr) {
+    case REG_IRQ32SR:
+        ret = PIC_REG32(s, REG_IRQ32SRC) & PIC_REG32(s, REG_IRQ32ENA);
+        break;
+    case REG_IRQ64SR:
+        ret = PIC_REG32(s, REG_IRQ64SRC) & PIC_REG32(s, REG_IRQ64ENA);
+        break;
+    case REG_FIQ32SR:
+        ret = PIC_REG32(s, REG_FIQ32SRC) & PIC_REG32(s, REG_FIQ32ENA);
+        break;
+    case REG_FIQ64SR:
+        ret = PIC_REG32(s, REG_FIQ64SRC) & PIC_REG32(s, REG_FIQ64ENA);
+        break;
+    default:
+        ret = s->regs[addr / 4];
+        break;
+    }
+
+    return ret;
+}
+
+static void
+ftintc020_mem_write(void *opaque, hwaddr addr, uint64_t value, unsigned size)
+{
+    Ftintc020State *s = FTINTC020(opaque);
+
+    if (addr > REG_FIQ64SR) {
+        qemu_log_mask(LOG_GUEST_ERROR,
+            "ftintc020: undefined memory access@%#" HWADDR_PRIx "\n", addr);
+        return;
+    }
+
+    switch (addr) {
+    case REG_IRQ32SCR:
+        /* clear edge triggered interrupts only */
+        value = ~(value & PIC_REG32(s, REG_IRQ32MDR));
+        PIC_REG32(s, REG_IRQ32SRC) &= (uint32_t)value;
+        break;
+    case REG_IRQ64SCR:
+        /* clear edge triggered interrupts only */
+        value = ~(value & PIC_REG32(s, REG_IRQ64MDR));
+        PIC_REG32(s, REG_IRQ64SRC) &= (uint32_t)value;
+        break;
+    case REG_FIQ32SCR:
+        /* clear edge triggered interrupts only */
+        value = ~(value & PIC_REG32(s, REG_FIQ32MDR));
+        PIC_REG32(s, REG_FIQ32SRC) &= (uint32_t)value;
+        break;
+    case REG_FIQ64SCR:
+        /* clear edge triggered interrupts only */
+        value = ~(value & PIC_REG32(s, REG_FIQ64MDR));
+        PIC_REG32(s, REG_FIQ64SRC) &= (uint32_t)value;
+        break;
+    default:
+        s->regs[addr / 4] = (uint32_t)value;
+        break;
+    }
+
+    ftintc020_update_irq(s);
+}
+
+static const MemoryRegionOps mmio_ops = {
+    .read  = ftintc020_mem_read,
+    .write = ftintc020_mem_write,
+    .endianness = DEVICE_LITTLE_ENDIAN,
+    .valid = {
+        .min_access_size = 4,
+        .max_access_size = 4,
+    }
+};
+
+static void ftintc020_reset(DeviceState *ds)
+{
+    Ftintc020State *s = FTINTC020(SYS_BUS_DEVICE(ds));
+
+    s->irq_ps[0] = 0;
+    s->irq_ps[1] = 0;
+    s->fiq_ps[0] = 0;
+    s->fiq_ps[1] = 0;
+    memset(s->regs, 0, sizeof(s->regs));
+
+    ftintc020_update_irq(s);
+}
+
+static VMStateDescription vmstate_ftintc020 = {
+    .name = TYPE_FTINTC020,
+    .version_id = 1,
+    .minimum_version_id = 1,
+    .minimum_version_id_old = 1,
+    .fields = (VMStateField[]) {
+        VMSTATE_UINT32_ARRAY(regs, Ftintc020State, CFG_REGSIZE),
+        VMSTATE_UINT32_ARRAY(irq_ps, Ftintc020State, 2),
+        VMSTATE_UINT32_ARRAY(fiq_ps, Ftintc020State, 2),
+        VMSTATE_END_OF_LIST(),
+    },
+};
+
+static int ftintc020_init(SysBusDevice *dev)
+{
+    Ftintc020State *s = FTINTC020(dev);
+
+    /* Enable IC memory-mapped registers access.  */
+    memory_region_init_io(&s->iomem,
+                          &mmio_ops,
+                          s,
+                          TYPE_FTINTC020,
+                          0x1000);
+    sysbus_init_mmio(dev, &s->iomem);
+

hw/arm/ftintc020.c line 285

Quoted 10 lines
hw/arm/ftintc020.c new file +10 -0
+    qdev_init_gpio_in(&dev->qdev, ftintc020_set_irq, 64);
+    sysbus_init_irq(dev, &s->irq);
+    sysbus_init_irq(dev, &s->fiq);
+
+    return 0;
+}
+
+static void ftintc020_class_init(ObjectClass *klass, void *data)
+{
+    SysBusDeviceClass *k = SYS_BUS_DEVICE_CLASS(klass);

Please do not use SysBusDeviceClass::init, use object::init and Device::realize instead.

Regards,
Peter

Quoted 88 lines
hw/arm/ftintc020.c new file +21 -0
+    DeviceClass *dc = DEVICE_CLASS(klass);
+
+    k->init     = ftintc020_init;
+    dc->vmsd    = &vmstate_ftintc020;
+    dc->reset   = ftintc020_reset;
+    dc->no_user = 1;
+}
+
+static const TypeInfo ftintc020_info = {
+    .name          = TYPE_FTINTC020,
+    .parent        = TYPE_SYS_BUS_DEVICE,
+    .instance_size = sizeof(Ftintc020State),
+    .class_init    = ftintc020_class_init,
+};
+
+static void ftintc020_register_types(void)
+{
+    type_register_static(&ftintc020_info);
+}
+
+type_init(ftintc020_register_types)
hw/arm/ftintc020.h new file +57 -1
new file mode 100644
index 0000000..20d300c
@@ -0,0 +1,57 @@
+/*
+ * Faraday FTINTC020 Programmable Interrupt Controller.
+ *
+ * Copyright (c) 2012 Faraday Technology
+ * Written by Dante Su <[email protected]>
+ *
+ * This code is licensed under GNU GPL v2+.
+ */
+
+#ifndef HW_ARM_FTINTC020_H
+#define HW_ARM_FTINTC020_H
+
+#include "qemu/bitops.h"
+
+/* IRQ/FIO: 0 ~ 31 */
+#define REG_IRQ32SRC    0x00    /* IRQ source register */
+#define REG_IRQ32ENA    0x04    /* IRQ enable register */
+#define REG_IRQ32SCR    0x08    /* IRQ status clear register */
+#define REG_IRQ32MDR    0x0C    /* IRQ trigger mode register */
+#define REG_IRQ32LVR    0x10    /* IRQ trigger level register */
+#define REG_IRQ32SR     0x14    /* IRQ status register */
+
+#define REG_FIQ32SRC    0x20    /* FIQ source register */
+#define REG_FIQ32ENA    0x24    /* FIQ enable register */
+#define REG_FIQ32SCR    0x28    /* FIQ status clear register */
+#define REG_FIQ32MDR    0x2C    /* FIQ trigger mode register */
+#define REG_FIQ32LVR    0x30    /* FIQ trigger level register */
+#define REG_FIQ32SR     0x34    /* FIQ status register */
+
+/* Extended IRQ/FIO: 32 ~ 63 */
+#define REG_IRQ64SRC    0x60    /* Extended IRQ source register */
+#define REG_IRQ64ENA    0x64    /* Extended IRQ enable register */
+#define REG_IRQ64SCR    0x68    /* Extended IRQ status clear register */
+#define REG_IRQ64MDR    0x6C    /* Extended IRQ trigger mode register */
+#define REG_IRQ64LVR    0x70    /* Extended IRQ trigger level register */
+#define REG_IRQ64SR     0x74    /* Extended IRQ status register */
+
+#define REG_FIQ64SRC    0x80    /* Extended FIQ source register */
+#define REG_FIQ64ENA    0x84    /* Extended FIQ enable register */
+#define REG_FIQ64SCR    0x88    /* Extended FIQ status clear register */
+#define REG_FIQ64MDR    0x8C    /* Extended FIQ trigger mode register */
+#define REG_FIQ64LVR    0x90    /* Extended FIQ trigger level register */
+#define REG_FIQ64SR     0x94    /* Extended FIQ status register */
+
+/* Common register offset to IRQ/FIQ */
+#define REG_SRC         0x00    /* Source register */
+#define REG_ENA         0x04    /* Enable register */
+#define REG_SCR         0x08    /* Status clear register */
+#define REG_MDR         0x0C    /* Trigger mode register */
+#define REG_LVR         0x10    /* Trigger level register */
+#define REG_SR          0x14    /* Status register */
+#define REG_MASK        0x1f
+
+#define REG_IRQ(n)      (((n) < 32) ? REG_IRQ32SRC : REG_IRQ64SRC)
+#define REG_FIQ(n)      (((n) < 32) ? REG_FIQ32SRC : REG_FIQ64SRC)
+
+#endif
--

1.7.9.5

#5 lore raw

PATCH v6 4/24 hw/arm: add Faraday FTAHBC020 support

In reply to Kuo-Jung Su

It's used to perform AHB remap and QEMU RAM initialization when the SDRAM is initialized before AHB remap process activated.

---
 hw/arm/Makefile.objs      |    1 +
 hw/arm/faraday_a369_soc.c |    4 +
 hw/arm/ftahbc020.c        |  190 +++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 195 insertions(+)
 create mode 100644 hw/arm/ftahbc020.c
hw/arm/Makefile.objs +1 -0
index 1d7ced8..925f050 100644
@@ -38,3 +38,4 @@ obj-y := $(addprefix ../,$(obj-y))
 obj-y += faraday_a369.o faraday_a369_soc.o faraday_a369_scu.o \
 				faraday_a369_kpd.o
 obj-y += ftintc020.o
+obj-y += ftahbc020.o
hw/arm/faraday_a369_soc.c +4 -0
index d3187b2..847fe05 100644
@@ -148,6 +148,10 @@ a369soc_device_init(FaradaySoCState *s)
 
     /* ftkbc010 */
     ds = sysbus_create_simple("a369.kpd", 0x92f00000, s->pic[21]);
+
+    /* ftahbc020 */
+    ds = sysbus_create_simple("ftahbc020", 0x94000000, NULL);
+    s->ahbc = ds;
 }
 
 static int a369soc_init(SysBusDevice *dev)
hw/arm/ftahbc020.c new file +190 -0

190 lines not on this page · raw message

Signature · 1 line
1.7.9.5
#6 lore raw

PATCH v6 5/24 hw/arm: add Faraday FTDDRII030 support

In reply to Kuo-Jung Su

The FTDDRII030 is a DDRII SDRAM controller which is responsible for SDRAM initialization.
In QEMU we emulate only the SDRAM enable function.

---
 hw/arm/Makefile.objs      |    1 +
 hw/arm/faraday_a369_soc.c |    4 ++
 hw/arm/ftddrii030.c       |  170 +++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 175 insertions(+)
 create mode 100644 hw/arm/ftddrii030.c
hw/arm/Makefile.objs +1 -0
index 925f050..6354155 100644
@@ -39,3 +39,4 @@ obj-y += faraday_a369.o faraday_a369_soc.o faraday_a369_scu.o \
 				faraday_a369_kpd.o
 obj-y += ftintc020.o
 obj-y += ftahbc020.o
+obj-y += ftddrii030.o
hw/arm/faraday_a369_soc.c +4 -0
index 847fe05..d612dea 100644
@@ -152,6 +152,10 @@ a369soc_device_init(FaradaySoCState *s)
     /* ftahbc020 */
     ds = sysbus_create_simple("ftahbc020", 0x94000000, NULL);
     s->ahbc = ds;
+
+    /* ftddrii030 */
+    ds = sysbus_create_simple("ftddrii030", 0x93100000, NULL);
+    s->ddrc = ds;
 }
 
 static int a369soc_init(SysBusDevice *dev)
hw/arm/ftddrii030.c new file +170 -0

170 lines not on this page · raw message

Signature · 1 line
1.7.9.5
#7 lore raw

PATCH v6 6/24 hw/arm: add Faraday FTPWMTMR010 timer support

In reply to Kuo-Jung Su

The FTPWMTMR010 is an APB device which provides up to 8 independent timers.

---
 hw/arm/Makefile.objs      |    1 +
 hw/arm/faraday_a369_soc.c |   10 ++
 hw/arm/ftpwmtmr010.c      |  264 +++++++++++++++++++++++++++++++++++++++++++++
 hw/arm/ftpwmtmr010.h      |   31 ++++++
 4 files changed, 306 insertions(+)
 create mode 100644 hw/arm/ftpwmtmr010.c
 create mode 100644 hw/arm/ftpwmtmr010.h
hw/arm/Makefile.objs +1 -0
index 6354155..2190edd 100644
@@ -40,3 +40,4 @@ obj-y += faraday_a369.o faraday_a369_soc.o faraday_a369_scu.o \
 obj-y += ftintc020.o
 obj-y += ftahbc020.o
 obj-y += ftddrii030.o
+obj-y += ftpwmtmr010.o
hw/arm/faraday_a369_soc.c +10 -0
index d612dea..66d9891 100644
@@ -156,6 +156,16 @@ a369soc_device_init(FaradaySoCState *s)
     /* ftddrii030 */
     ds = sysbus_create_simple("ftddrii030", 0x93100000, NULL);
     s->ddrc = ds;
+
+    /* 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 int a369soc_init(SysBusDevice *dev)
hw/arm/ftpwmtmr010.c new file +264 -0

264 lines not on this page · raw message

hw/arm/ftpwmtmr010.h new file +31 -0
new file mode 100644
index 0000000..a435a70
@@ -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
#8 lore raw

PATCH v6 7/24 hw/arm: add Faraday FTWDT010 watchdog timer support

In reply to Kuo-Jung Su

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      |    1 +
 hw/arm/faraday_a369_soc.c |   23 +++++
 hw/arm/ftwdt010.c         |  212 +++++++++++++++++++++++++++++++++++++++++++++
 hw/arm/ftwdt010.h         |   35 ++++++++
 4 files changed, 271 insertions(+)
 create mode 100644 hw/arm/ftwdt010.c
 create mode 100644 hw/arm/ftwdt010.h
hw/arm/Makefile.objs +1 -0
index 2190edd..bc8e2de 100644
@@ -41,3 +41,4 @@ obj-y += ftintc020.o
 obj-y += ftahbc020.o
 obj-y += ftddrii030.o
 obj-y += ftpwmtmr010.o
+obj-y += ftwdt010.o
hw/arm/faraday_a369_soc.c +23 -0
index 66d9891..1bf64d4 100644
@@ -68,6 +68,25 @@ static void a369soc_reset(DeviceState *ds)
 }
 
 static void
+a369soc_system_reset(void *opaque)
+{
+    FaradaySoCState *s = FARADAY_SOC(opaque);
+
+    if (s->scu) {
+        device_reset(s->scu);
+    }
+    if (s->ddrc) {
+        device_reset(s->ddrc);
+    }
+    if (s->ahbc) {
+        device_reset(s->ahbc);
+    }
+    if (s->cpu) {
+        cpu_reset(CPU(s->cpu));
+    }
+}
+
+static void
 a369soc_device_init(FaradaySoCState *s)
 {
     DriveInfo *dinfo;
@@ -166,6 +185,10 @@ a369soc_device_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]);
+    qemu_register_reset(a369soc_system_reset, s);
 }
 
 static int a369soc_init(SysBusDevice *dev)
hw/arm/ftwdt010.c new file +212 -0

212 lines not on this page · raw message

hw/arm/ftwdt010.h new file +35 -0
new file mode 100644
index 0000000..46c0871
@@ -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
#9 lore raw

Re: [Qemu-devel] [PATCH v6 07/24] hw/arm: add Faraday FTWDT010 watchdog timer support

Il 06/03/2013 08:27, Kuo-Jung Su ha scritto:

Quoted 44 lines

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      |    1 +
 hw/arm/faraday_a369_soc.c |   23 +++++
 hw/arm/ftwdt010.c         |  212 +++++++++++++++++++++++++++++++++++++++++++++
 hw/arm/ftwdt010.h         |   35 ++++++++
 4 files changed, 271 insertions(+)
 create mode 100644 hw/arm/ftwdt010.c
 create mode 100644 hw/arm/ftwdt010.h
hw/arm/Makefile.objs +1 -0
index 2190edd..bc8e2de 100644
@@ -41,3 +41,4 @@ obj-y += ftintc020.o
 obj-y += ftahbc020.o
 obj-y += ftddrii030.o
 obj-y += ftpwmtmr010.o
+obj-y += ftwdt010.o
hw/arm/faraday_a369_soc.c +7 -0
index 66d9891..1bf64d4 100644
@@ -68,6 +68,25 @@ static void a369soc_reset(DeviceState *ds)
 }
 
 static void
+a369soc_system_reset(void *opaque)
+{
+    FaradaySoCState *s = FARADAY_SOC(opaque);
+
+    if (s->scu) {
+        device_reset(s->scu);
+    }

hw/arm/faraday_a369_soc.c static void a369soc_reset(DeviceState *ds) · line 87

Quoted 10 lines
hw/arm/faraday_a369_soc.c +10 -0
+    if (s->ddrc) {
+        device_reset(s->ddrc);
+    }
+    if (s->ahbc) {
+        device_reset(s->ahbc);
+    }
+    if (s->cpu) {
+        cpu_reset(CPU(s->cpu));
+    }
+}

Why is this needed? Aren't they called already by

    qemu_register_reset(qbus_reset_all_fn, sysbus_get_default());

?

Quoted 145 lines
hw/arm/faraday_a369_soc.c +4 -0
 a369soc_device_init(FaradaySoCState *s)
 {
     DriveInfo *dinfo;
@@ -166,6 +185,10 @@ a369soc_device_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]);
+    qemu_register_reset(a369soc_system_reset, s);
 }
 
 static int a369soc_init(SysBusDevice *dev)
hw/arm/ftwdt010.c new file +125 -0
new file mode 100644
index 0000000..361f16e
@@ -0,0 +1,212 @@
+/*
+ * 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+.
+ */
+
+#include "hw/sysbus.h"
+#include "sysemu/sysemu.h"
+#include "qemu/timer.h"
+
+#include "faraday.h"
+#include "ftwdt010.h"
+
+#define TYPE_FTWDT010   "ftwdt010"
+
+typedef struct Ftwdt010State {
+    SysBusDevice busdev;
+    MemoryRegion mmio;
+
+    qemu_irq irq;
+
+    QEMUTimer *qtimer;
+
+    uint64_t timeout;
+    uint64_t freq;        /* desired source clock */
+    uint64_t step;        /* get_ticks_per_sec() / freq */
+    bool running;
+
+    /* HW register cache */
+    uint32_t load;
+    uint32_t cr;
+    uint32_t sr;
+} Ftwdt010State;
+
+#define FTWDT010(obj) \
+    OBJECT_CHECK(Ftwdt010State, obj, TYPE_FTWDT010)
+
+static uint64_t
+ftwdt010_mem_read(void *opaque, hwaddr addr, unsigned size)
+{
+    Ftwdt010State *s = FTWDT010(opaque);
+    uint32_t ret = 0;
+
+    switch (addr) {
+    case REG_COUNTER:
+        if (s->cr & CR_EN) {
+            ret = s->timeout - qemu_get_clock_ms(rt_clock);
+            ret = MIN(s->load, ret * 1000000ULL / s->step);
+        } else {
+            ret = s->load;
+        }
+        break;
+    case REG_LOAD:
+        return s->load;
+    case REG_CR:
+        return s->cr;
+    case REG_SR:
+        return s->sr;
+    case REG_REVR:
+        return 0x00010601;  /* rev. 1.6.1 */
+    default:
+        qemu_log_mask(LOG_GUEST_ERROR,
+            "ftwdt010: undefined memory access@%#" HWADDR_PRIx "\n", addr);
+        break;
+    }
+
+    return ret;
+}
+
+static void
+ftwdt010_mem_write(void *opaque, hwaddr addr, uint64_t val, unsigned size)
+{
+    Ftwdt010State *s = FTWDT010(opaque);
+
+    switch (addr) {
+    case REG_LOAD:
+        s->load = (uint32_t)val;
+        break;
+    case REG_RESTART:
+        if ((s->cr & CR_EN) && (val == WDT_MAGIC)) {
+            s->timeout = (s->step * (uint64_t)s->load) / 1000000ULL;
+            s->timeout = qemu_get_clock_ms(rt_clock) + MAX(s->timeout, 1);
+            qemu_mod_timer(s->qtimer, s->timeout);
+        }
+        break;
+    case REG_CR:
+        s->cr = (uint32_t)val;
+        if (s->cr & CR_EN) {
+            if (s->running) {
+                break;
+            }
+            s->running = true;
+            s->timeout = (s->step * (uint64_t)s->load) / 1000000ULL;
+            s->timeout = qemu_get_clock_ms(rt_clock) + MAX(s->timeout, 1);
+            qemu_mod_timer(s->qtimer, s->timeout);
+        } else {
+            s->running = false;
+            qemu_del_timer(s->qtimer);
+        }
+        break;
+    case REG_SCR:
+        s->sr &= ~(uint32_t)val;
+        break;
+    default:
+        qemu_log_mask(LOG_GUEST_ERROR,
+            "ftwdt010: undefined memory access@%#" HWADDR_PRIx "\n", addr);
+        break;
+    }
+}
+
+static const MemoryRegionOps mmio_ops = {
+    .read  = ftwdt010_mem_read,
+    .write = ftwdt010_mem_write,
+    .endianness = DEVICE_LITTLE_ENDIAN,
+    .valid = {
+        .min_access_size = 4,
+        .max_access_size = 4
+    }
+};
+
+static void ftwdt010_timer_tick(void *opaque)
+{

hw/arm/ftwdt010.c line 135

Quoted 10 lines
hw/arm/ftwdt010.c new file +10 -0
+    Ftwdt010State *s = FTWDT010(opaque);
+
+    s->sr = SR_SRST;
+
+    /* send interrupt signal */
+    qemu_set_irq(s->irq, (s->cr & CR_INTR) ? 1 : 0);
+
+    /* send system reset */
+    if (s->cr & CR_SRST) {
+        qemu_system_reset_request();

Please use watchdog_perform_action() instead.

Paolo

Quoted 119 lines
hw/arm/ftwdt010.c new file +77 -0
+    }
+}
+
+static void ftwdt010_reset(DeviceState *ds)
+{
+    Ftwdt010State *s = FTWDT010(SYS_BUS_DEVICE(ds));
+
+    s->cr      = 0;
+    s->sr      = 0;
+    s->load    = 0x3ef1480;
+    s->timeout = 0;
+}
+
+static int ftwdt010_init(SysBusDevice *dev)
+{
+    Ftwdt010State *s = FTWDT010(dev);
+
+    s->step = (uint64_t)get_ticks_per_sec() / s->freq;
+    s->qtimer = qemu_new_timer_ms(rt_clock, ftwdt010_timer_tick, s);
+
+    memory_region_init_io(&s->mmio,
+                          &mmio_ops,
+                          s,
+                          TYPE_FTWDT010,
+                          0x1000);
+    sysbus_init_mmio(dev, &s->mmio);
+    sysbus_init_irq(dev, &s->irq);
+
+    return 0;
+}
+
+static const VMStateDescription vmstate_ftwdt010 = {
+    .name = TYPE_FTWDT010,
+    .version_id = 1,
+    .minimum_version_id = 1,
+    .minimum_version_id_old = 1,
+    .fields = (VMStateField[]) {
+        VMSTATE_UINT64(timeout, Ftwdt010State),
+        VMSTATE_UINT64(freq, Ftwdt010State),
+        VMSTATE_UINT64(step, Ftwdt010State),
+        VMSTATE_UINT32(load, Ftwdt010State),
+        VMSTATE_UINT32(cr, Ftwdt010State),
+        VMSTATE_UINT32(sr, Ftwdt010State),
+        VMSTATE_END_OF_LIST()
+    }
+};
+
+static Property ftwdt010_properties[] = {
+    DEFINE_PROP_UINT64("freq", Ftwdt010State, freq, 66000000ULL),
+    DEFINE_PROP_END_OF_LIST(),
+};
+
+static void ftwdt010_class_init(ObjectClass *klass, void *data)
+{
+    SysBusDeviceClass *k = SYS_BUS_DEVICE_CLASS(klass);
+    DeviceClass *dc = DEVICE_CLASS(klass);
+
+    k->init     = ftwdt010_init;
+    dc->vmsd    = &vmstate_ftwdt010;
+    dc->props   = ftwdt010_properties;
+    dc->reset   = ftwdt010_reset;
+    dc->no_user = 1;
+}
+
+static const TypeInfo ftwdt010_info = {
+    .name           = TYPE_FTWDT010,
+    .parent         = TYPE_SYS_BUS_DEVICE,
+    .instance_size  = sizeof(Ftwdt010State),
+    .class_init     = ftwdt010_class_init,
+};
+
+static void ftwdt010_register_types(void)
+{
+    type_register_static(&ftwdt010_info);
+}
+
+type_init(ftwdt010_register_types)
hw/arm/ftwdt010.h new file +35 -0
new file mode 100644
index 0000000..46c0871
@@ -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
#10 lore raw

Re: [Qemu-devel] [PATCH v6 07/24] hw/arm: add Faraday FTWDT010 watchdog timer support

2013/3/6 Paolo Bonzini <[email protected]>:

Quoted 58 lines

Il 06/03/2013 08:27, Kuo-Jung Su ha scritto:

Quoted 44 lines

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      |    1 +
 hw/arm/faraday_a369_soc.c |   23 +++++
 hw/arm/ftwdt010.c         |  212 +++++++++++++++++++++++++++++++++++++++++++++
 hw/arm/ftwdt010.h         |   35 ++++++++
 4 files changed, 271 insertions(+)
 create mode 100644 hw/arm/ftwdt010.c
 create mode 100644 hw/arm/ftwdt010.h
hw/arm/Makefile.objs +1 -0
index 2190edd..bc8e2de 100644
@@ -41,3 +41,4 @@ obj-y += ftintc020.o
 obj-y += ftahbc020.o
 obj-y += ftddrii030.o
 obj-y += ftpwmtmr010.o
+obj-y += ftwdt010.o
hw/arm/faraday_a369_soc.c +7 -0
index 66d9891..1bf64d4 100644
@@ -68,6 +68,25 @@ static void a369soc_reset(DeviceState *ds)
 }
 
 static void
+a369soc_system_reset(void *opaque)
+{
+    FaradaySoCState *s = FARADAY_SOC(opaque);
+
+    if (s->scu) {
+        device_reset(s->scu);
+    }

hw/arm/faraday_a369_soc.c static void a369soc_reset(DeviceState *ds) · line 87

Quoted 10 lines
hw/arm/faraday_a369_soc.c +10 -0
+    if (s->ddrc) {
+        device_reset(s->ddrc);
+    }
+    if (s->ahbc) {
+        device_reset(s->ahbc);
+    }
+    if (s->cpu) {
+        cpu_reset(CPU(s->cpu));
+    }
+}

Why is this needed? Aren't they called already by

Quoted 4 lines
    qemu_register_reset(qbus_reset_all_fn, sysbus_get_default());

?

It doesn't work while running under ROM mode. ( no -kernel ) Because Faraday SoC Platform usually designed to boot from ROM and followed by an AHB remapping process (i.e. remap ROM/RAM address).

Quoted 158 lines
Quoted 145 lines
hw/arm/faraday_a369_soc.c +4 -0
 a369soc_device_init(FaradaySoCState *s)
 {
     DriveInfo *dinfo;
@@ -166,6 +185,10 @@ a369soc_device_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]);
+    qemu_register_reset(a369soc_system_reset, s);
 }
 
 static int a369soc_init(SysBusDevice *dev)
hw/arm/ftwdt010.c new file +125 -0
new file mode 100644
index 0000000..361f16e
@@ -0,0 +1,212 @@
+/*
+ * 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+.
+ */
+
+#include "hw/sysbus.h"
+#include "sysemu/sysemu.h"
+#include "qemu/timer.h"
+
+#include "faraday.h"
+#include "ftwdt010.h"
+
+#define TYPE_FTWDT010   "ftwdt010"
+
+typedef struct Ftwdt010State {
+    SysBusDevice busdev;
+    MemoryRegion mmio;
+
+    qemu_irq irq;
+
+    QEMUTimer *qtimer;
+
+    uint64_t timeout;
+    uint64_t freq;        /* desired source clock */
+    uint64_t step;        /* get_ticks_per_sec() / freq */
+    bool running;
+
+    /* HW register cache */
+    uint32_t load;
+    uint32_t cr;
+    uint32_t sr;
+} Ftwdt010State;
+
+#define FTWDT010(obj) \
+    OBJECT_CHECK(Ftwdt010State, obj, TYPE_FTWDT010)
+
+static uint64_t
+ftwdt010_mem_read(void *opaque, hwaddr addr, unsigned size)
+{
+    Ftwdt010State *s = FTWDT010(opaque);
+    uint32_t ret = 0;
+
+    switch (addr) {
+    case REG_COUNTER:
+        if (s->cr & CR_EN) {
+            ret = s->timeout - qemu_get_clock_ms(rt_clock);
+            ret = MIN(s->load, ret * 1000000ULL / s->step);
+        } else {
+            ret = s->load;
+        }
+        break;
+    case REG_LOAD:
+        return s->load;
+    case REG_CR:
+        return s->cr;
+    case REG_SR:
+        return s->sr;
+    case REG_REVR:
+        return 0x00010601;  /* rev. 1.6.1 */
+    default:
+        qemu_log_mask(LOG_GUEST_ERROR,
+            "ftwdt010: undefined memory access@%#" HWADDR_PRIx "\n", addr);
+        break;
+    }
+
+    return ret;
+}
+
+static void
+ftwdt010_mem_write(void *opaque, hwaddr addr, uint64_t val, unsigned size)
+{
+    Ftwdt010State *s = FTWDT010(opaque);
+
+    switch (addr) {
+    case REG_LOAD:
+        s->load = (uint32_t)val;
+        break;
+    case REG_RESTART:
+        if ((s->cr & CR_EN) && (val == WDT_MAGIC)) {
+            s->timeout = (s->step * (uint64_t)s->load) / 1000000ULL;
+            s->timeout = qemu_get_clock_ms(rt_clock) + MAX(s->timeout, 1);
+            qemu_mod_timer(s->qtimer, s->timeout);
+        }
+        break;
+    case REG_CR:
+        s->cr = (uint32_t)val;
+        if (s->cr & CR_EN) {
+            if (s->running) {
+                break;
+            }
+            s->running = true;
+            s->timeout = (s->step * (uint64_t)s->load) / 1000000ULL;
+            s->timeout = qemu_get_clock_ms(rt_clock) + MAX(s->timeout, 1);
+            qemu_mod_timer(s->qtimer, s->timeout);
+        } else {
+            s->running = false;
+            qemu_del_timer(s->qtimer);
+        }
+        break;
+    case REG_SCR:
+        s->sr &= ~(uint32_t)val;
+        break;
+    default:
+        qemu_log_mask(LOG_GUEST_ERROR,
+            "ftwdt010: undefined memory access@%#" HWADDR_PRIx "\n", addr);
+        break;
+    }
+}
+
+static const MemoryRegionOps mmio_ops = {
+    .read  = ftwdt010_mem_read,
+    .write = ftwdt010_mem_write,
+    .endianness = DEVICE_LITTLE_ENDIAN,
+    .valid = {
+        .min_access_size = 4,
+        .max_access_size = 4
+    }
+};
+
+static void ftwdt010_timer_tick(void *opaque)
+{

hw/arm/ftwdt010.c line 135

Quoted 10 lines
hw/arm/ftwdt010.c new file +10 -0
+    Ftwdt010State *s = FTWDT010(opaque);
+
+    s->sr = SR_SRST;
+
+    /* send interrupt signal */
+    qemu_set_irq(s->irq, (s->cr & CR_INTR) ? 1 : 0);
+
+    /* send system reset */
+    if (s->cr & CR_SRST) {
+        qemu_system_reset_request();

Please use watchdog_perform_action() instead.

Quoted 2 lines

Paolo

Got it, thanks

Quoted 111 lines
Quoted 111 lines
hw/arm/ftwdt010.c new file +77 -0
+    }
+}
+
+static void ftwdt010_reset(DeviceState *ds)
+{
+    Ftwdt010State *s = FTWDT010(SYS_BUS_DEVICE(ds));
+
+    s->cr      = 0;
+    s->sr      = 0;
+    s->load    = 0x3ef1480;
+    s->timeout = 0;
+}
+
+static int ftwdt010_init(SysBusDevice *dev)
+{
+    Ftwdt010State *s = FTWDT010(dev);
+
+    s->step = (uint64_t)get_ticks_per_sec() / s->freq;
+    s->qtimer = qemu_new_timer_ms(rt_clock, ftwdt010_timer_tick, s);
+
+    memory_region_init_io(&s->mmio,
+                          &mmio_ops,
+                          s,
+                          TYPE_FTWDT010,
+                          0x1000);
+    sysbus_init_mmio(dev, &s->mmio);
+    sysbus_init_irq(dev, &s->irq);
+
+    return 0;
+}
+
+static const VMStateDescription vmstate_ftwdt010 = {
+    .name = TYPE_FTWDT010,
+    .version_id = 1,
+    .minimum_version_id = 1,
+    .minimum_version_id_old = 1,
+    .fields = (VMStateField[]) {
+        VMSTATE_UINT64(timeout, Ftwdt010State),
+        VMSTATE_UINT64(freq, Ftwdt010State),
+        VMSTATE_UINT64(step, Ftwdt010State),
+        VMSTATE_UINT32(load, Ftwdt010State),
+        VMSTATE_UINT32(cr, Ftwdt010State),
+        VMSTATE_UINT32(sr, Ftwdt010State),
+        VMSTATE_END_OF_LIST()
+    }
+};
+
+static Property ftwdt010_properties[] = {
+    DEFINE_PROP_UINT64("freq", Ftwdt010State, freq, 66000000ULL),
+    DEFINE_PROP_END_OF_LIST(),
+};
+
+static void ftwdt010_class_init(ObjectClass *klass, void *data)
+{
+    SysBusDeviceClass *k = SYS_BUS_DEVICE_CLASS(klass);
+    DeviceClass *dc = DEVICE_CLASS(klass);
+
+    k->init     = ftwdt010_init;
+    dc->vmsd    = &vmstate_ftwdt010;
+    dc->props   = ftwdt010_properties;
+    dc->reset   = ftwdt010_reset;
+    dc->no_user = 1;
+}
+
+static const TypeInfo ftwdt010_info = {
+    .name           = TYPE_FTWDT010,
+    .parent         = TYPE_SYS_BUS_DEVICE,
+    .instance_size  = sizeof(Ftwdt010State),
+    .class_init     = ftwdt010_class_init,
+};
+
+static void ftwdt010_register_types(void)
+{
+    type_register_static(&ftwdt010_info);
+}
+
+type_init(ftwdt010_register_types)
hw/arm/ftwdt010.h new file +28 -0
new file mode 100644
index 0000000..46c0871
@@ -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 */
Quoted 9 lines

hw/arm/ftwdt010.h line 35

Quoted 8 lines
hw/arm/ftwdt010.h new file +7 -0
+#define CR_EN           BIT(0)  /* chip enabled */
+
+#define SR_SRST         BIT(1)  /* system reset */
+
+#define WDT_MAGIC       0x5ab9  /* magic for watchdog restart */
+
+#endif

--
Best wishes,
Kuo-Jung Su

#11 lore raw

Re: [Qemu-devel] [PATCH v6 07/24] hw/arm: add Faraday FTWDT010 watchdog timer support

Quoted 22 lines
Quoted 8 lines
Quoted 3 lines

It doesn't work while running under ROM mode. ( no -kernel ) Because Faraday SoC Platform usually designed to boot from ROM and followed by an AHB remapping process (i.e. remap ROM/RAM address).

What doesn't work exactly? Why aren't these called? Or are you forcing a particular reset order?

Paolo

While booting from ROM, the faraday soc usually remap the ROM / RAM before jumping into linux.

In other words, the system mapping is:

1. Power-On:

    ROM: 0x00000000
    RAM: N/A
    SRAM: 0xA0000000

2. AHB Remap (u-boot/linux)

Quoted 7 lines
    ROM: 0x20000000
    RAM: 0x00000000

So I have to register my own reset handler to

1. Undo the ROM/RAM remap (i.e. device_reset(s->ahbc))
2. Reset CPU

----- Messaggio originale -----

Quoted 96 lines

Da: "Kuo-Jung Su" <[email protected]>
A: "Paolo Bonzini" <[email protected]>
Inviato: Mercoledì, 6 marzo 2013 11:00:49
Oggetto: Re: [PATCH v6 07/24] hw/arm: add Faraday FTWDT010 watchdog timer support

2013/3/6 Paolo Bonzini <[email protected]>:

Quoted 68 lines
Quoted 68 lines

2013/3/6 Paolo Bonzini <[email protected]>:

Quoted 65 lines

Il 06/03/2013 08:27, Kuo-Jung Su ha scritto:

Quoted 46 lines

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      |    1 +
 hw/arm/faraday_a369_soc.c |   23 +++++
 hw/arm/ftwdt010.c         |  212
 +++++++++++++++++++++++++++++++++++++++++++++
 hw/arm/ftwdt010.h         |   35 ++++++++
 4 files changed, 271 insertions(+)
 create mode 100644 hw/arm/ftwdt010.c
 create mode 100644 hw/arm/ftwdt010.h
hw/arm/Makefile.objs +1 -0
index 2190edd..bc8e2de 100644
@@ -41,3 +41,4 @@ obj-y += ftintc020.o
 obj-y += ftahbc020.o
 obj-y += ftddrii030.o
 obj-y += ftpwmtmr010.o
+obj-y += ftwdt010.o
hw/arm/faraday_a369_soc.c +7 -0
index 66d9891..1bf64d4 100644
@@ -68,6 +68,25 @@ static void a369soc_reset(DeviceState *ds)
 }
 
 static void
+a369soc_system_reset(void *opaque)
+{
+    FaradaySoCState *s = FARADAY_SOC(opaque);
+
+    if (s->scu) {
+        device_reset(s->scu);
+    }

hw/arm/faraday_a369_soc.c static void a369soc_reset(DeviceState *ds) · line 87

Quoted 10 lines
hw/arm/faraday_a369_soc.c +10 -0
+    if (s->ddrc) {
+        device_reset(s->ddrc);
+    }
+    if (s->ahbc) {
+        device_reset(s->ahbc);
+    }
+    if (s->cpu) {
+        cpu_reset(CPU(s->cpu));
+    }
+}

Why is this needed? Aren't they called already by

    qemu_register_reset(qbus_reset_all_fn,
    sysbus_get_default());

?

Quoted 8 lines
Quoted 3 lines

It doesn't work while running under ROM mode. ( no -kernel ) Because Faraday SoC Platform usually designed to boot from ROM and followed by an AHB remapping process (i.e. remap ROM/RAM address).

What doesn't work exactly? Why aren't these called? Or are you forcing a particular reset order?

Paolo

While booting from ROM, the faraday soc usually remap the ROM / RAM before jumping into linux.

In other words, the system mapping is:

1. Power-On:

    ROM: 0x00000000
    RAM: N/A
    SRAM: 0xA0000000

2. AHB Remap (u-boot/linux)

Quoted 7 lines
    ROM: 0x20000000
    RAM: 0x00000000

So I have to register my own reset handler to

1. Undo the ROM/RAM remap (i.e. device_reset(s->ahbc))
2. Reset CPU

I understand that. What I'm missing is, why these reset handlers aren't called anyway when QEMU does qemu_devices_reset(), for example from qemu_system_reset().

Also, I do not understand who performs this again:

+        /* Remap AHB slave 4 (ROM) & slave 6 (RAM) */
+        /* 1. Remap RAM to base of ROM */
+        s->ram_base = s->ahb_slave[4] & 0xfff00000;
+        s->ahb_slave[6] = s->ram_base | (s->ahb_slave[6] & 0x000f0000);
+        /* 2. Remap ROM to base of ROM + size of RAM */
+        s->rom_base = s->ram_base

+ + ((1 << extract32(s->ahb_slave[6], 16, 4)) << 20);
+ s->ahb_slave[4] = s->rom_base | (s->ahb_slave[4] & 0x000f0000);

when you do a system_reset and the board was started in kernel mode.

Paolo

#12 lore raw

Re: [Qemu-devel] [PATCH v6 07/24] hw/arm: add Faraday FTWDT010 watchdog timer support

2013/3/6 Paolo Bonzini <[email protected]>:

Quoted 130 lines
Quoted 22 lines
Quoted 8 lines
Quoted 3 lines

It doesn't work while running under ROM mode. ( no -kernel ) Because Faraday SoC Platform usually designed to boot from ROM and followed by an AHB remapping process (i.e. remap ROM/RAM address).

What doesn't work exactly? Why aren't these called? Or are you forcing a particular reset order?

Paolo

While booting from ROM, the faraday soc usually remap the ROM / RAM before jumping into linux.

In other words, the system mapping is:

1. Power-On:

    ROM: 0x00000000
    RAM: N/A
    SRAM: 0xA0000000

2. AHB Remap (u-boot/linux)

Quoted 7 lines
    ROM: 0x20000000
    RAM: 0x00000000

So I have to register my own reset handler to

1. Undo the ROM/RAM remap (i.e. device_reset(s->ahbc))
2. Reset CPU

----- Messaggio originale -----

Quoted 99 lines

Da: "Kuo-Jung Su" <[email protected]>
A: "Paolo Bonzini" <[email protected]>
Inviato: Mercoledì, 6 marzo 2013 11:00:49
Oggetto: Re: [PATCH v6 07/24] hw/arm: add Faraday FTWDT010 watchdog timer support

2013/3/6 Paolo Bonzini <[email protected]>:

Quoted 68 lines
Quoted 68 lines

2013/3/6 Paolo Bonzini <[email protected]>:

Quoted 65 lines

Il 06/03/2013 08:27, Kuo-Jung Su ha scritto:

Quoted 46 lines

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      |    1 +
 hw/arm/faraday_a369_soc.c |   23 +++++
 hw/arm/ftwdt010.c         |  212
 +++++++++++++++++++++++++++++++++++++++++++++
 hw/arm/ftwdt010.h         |   35 ++++++++
 4 files changed, 271 insertions(+)
 create mode 100644 hw/arm/ftwdt010.c
 create mode 100644 hw/arm/ftwdt010.h
hw/arm/Makefile.objs +1 -0
index 2190edd..bc8e2de 100644
@@ -41,3 +41,4 @@ obj-y += ftintc020.o
 obj-y += ftahbc020.o
 obj-y += ftddrii030.o
 obj-y += ftpwmtmr010.o
+obj-y += ftwdt010.o
hw/arm/faraday_a369_soc.c +7 -0
index 66d9891..1bf64d4 100644
@@ -68,6 +68,25 @@ static void a369soc_reset(DeviceState *ds)
 }
 
 static void
+a369soc_system_reset(void *opaque)
+{
+    FaradaySoCState *s = FARADAY_SOC(opaque);
+
+    if (s->scu) {
+        device_reset(s->scu);
+    }

hw/arm/faraday_a369_soc.c static void a369soc_reset(DeviceState *ds) · line 87

Quoted 10 lines
hw/arm/faraday_a369_soc.c +10 -0
+    if (s->ddrc) {
+        device_reset(s->ddrc);
+    }
+    if (s->ahbc) {
+        device_reset(s->ahbc);
+    }
+    if (s->cpu) {
+        cpu_reset(CPU(s->cpu));
+    }
+}

Why is this needed? Aren't they called already by

    qemu_register_reset(qbus_reset_all_fn,
    sysbus_get_default());

?

Quoted 8 lines
Quoted 3 lines

It doesn't work while running under ROM mode. ( no -kernel ) Because Faraday SoC Platform usually designed to boot from ROM and followed by an AHB remapping process (i.e. remap ROM/RAM address).

What doesn't work exactly? Why aren't these called? Or are you forcing a particular reset order?

Paolo

While booting from ROM, the faraday soc usually remap the ROM / RAM before jumping into linux.

In other words, the system mapping is:

1. Power-On:

    ROM: 0x00000000
    RAM: N/A
    SRAM: 0xA0000000

2. AHB Remap (u-boot/linux)

    ROM: 0x20000000
    RAM: 0x00000000
Quoted 9 lines
Quoted 4 lines

So I have to register my own reset handler to

1. Undo the ROM/RAM remap (i.e. device_reset(s->ahbc))
2. Reset CPU

I understand that. What I'm missing is, why these reset handlers aren't called anyway when QEMU does qemu_devices_reset(), for example from qemu_system_reset().

1. arm_cpu_reset() is never be invoked from the default reset handler.

2. Undo ROM/RAM remap would make bus become unstable there is no guaranty when the bus would be stabilized.
(It looks to me that it's true for both QEMU and real hardware)

3. In QEMU, my guess is without arm_cpu_reset(), when the AHB remap process activated upon watchdog counts down to zero.
The PC (r15) could be anywhere, and so does the stack & bss. Which means the CPU would likely suffers from UNKNOWN INSTRUCTION, DATA ABORT... etc.

Quoted 2 lines

Also, I do not understand who performs this again:

It's performed at my ROM code:

https://github.com/dantesu1218/virgil/blob/master/arch/mach-a369/board.c

line 200 ~ 220

#ifndef CONFIG_SKIP_SYSINIT
/* Skip AHB remap if the jump address is not inside SDRAM address space */ "ldr r4, =0x10000000\n"
"cmp %2, r4\n"
"movhs pc, %2\n" /* jump without AHB remapped */
/* AHB remap
* REG32(CONFIG_IOBASE_DDR + 0x10) &= 0x00FFFFFF
* REG32(CONFIG_IOBASE_AHB + 0x88) = 0x00100F01
*/
"ldr r4, [%0, #0x10]\n"
"bic r4, #0xff000000\n"
"ldr r5, =0x00100f01\n"
".ALIGN 5\n" /* Make sure all the following codes to be fetched in a single 32-bytes cache line */
"str r4, [%0, #0x10]\n" /* REG32(CONFIG_IOBASE_DDR + 0x10) &= 0x00FFFFFF */ "str r5, [%1, #0x88]\n" /* REG32(CONFIG_IOBASE_AHB + 0x88) = 0x00100F01 */ "5:\n"
"ldr r4, [%2, #0]\n" /* while(magic != REG32(addr)) */
"teq r4, %3\n"
"bne 5b\n"
#endif
"mov pc, %2\n" /* jump */

Quoted 11 lines
(quoted diff) +8 -0
+        /* Remap AHB slave 4 (ROM) & slave 6 (RAM) */
+        /* 1. Remap RAM to base of ROM */
+        s->ram_base = s->ahb_slave[4] & 0xfff00000;
+        s->ahb_slave[6] = s->ram_base | (s->ahb_slave[6] & 0x000f0000);
+        /* 2. Remap ROM to base of ROM + size of RAM */
+        s->rom_base = s->ram_base
+                    + ((1 << extract32(s->ahb_slave[6], 16, 4)) << 20);
+        s->ahb_slave[4] = s->rom_base | (s->ahb_slave[4] & 0x000f0000);

when you do a system_reset and the board was started in kernel mode.

The problem is not about the kernel mode. In my words, I call them:

1. RAM Mode Emulation (Launching QEMU with -kernel) :
The emulator would assume that the SDRAM has been remapped to 0x00000000.

2. ROM Mode Emulation (Without -kernel):

    The emulator would map the 6KB ROM (pflash) to 0x00000000, 32KB SRAM
    to 0xA0000000, but no SDRAM

P.S:

In A369, the the boot sequence of ROM mode is:

1. Power-on
2. ROM code execution on ROM @ 0x00000000
3. 2nd bootstrap on SRAM @ 0xA0000000
4. General software (Linux/U-boot) execution on SDRAM @ 0x00000000

In newer design, (from 2010, after my referenced ROM code is reay) the the boot sequence of ROM mode becomes:

1. Power-on
2. ROM code execution on ROM @ 0x00000000
3. General software (Linux/U-boot) execution on SDRAM @ 0x00000000

Currently I have a kw9505 QEMU model ready for this, and since it's a customer ASIC,
it shall never be merged into open source.
But if you want, I could provide the kw9505.c with lots of coding style issues for function test.

Quoted 1 line

Paolo

--
Best wishes,
Kuo-Jung Su

#13 lore raw

Re: [Qemu-devel] [PATCH v6 07/24] hw/arm: add Faraday FTWDT010 watchdog timer support

2013/3/7 Kuo-Jung Su <[email protected]>:

Quoted 176 lines

2013/3/6 Paolo Bonzini <[email protected]>:

Quoted 130 lines
Quoted 22 lines
Quoted 8 lines
Quoted 3 lines

It doesn't work while running under ROM mode. ( no -kernel ) Because Faraday SoC Platform usually designed to boot from ROM and followed by an AHB remapping process (i.e. remap ROM/RAM address).

What doesn't work exactly? Why aren't these called? Or are you forcing a particular reset order?

Paolo

While booting from ROM, the faraday soc usually remap the ROM / RAM before jumping into linux.

In other words, the system mapping is:

1. Power-On:

    ROM: 0x00000000
    RAM: N/A
    SRAM: 0xA0000000

2. AHB Remap (u-boot/linux)

Quoted 7 lines
    ROM: 0x20000000
    RAM: 0x00000000

So I have to register my own reset handler to

1. Undo the ROM/RAM remap (i.e. device_reset(s->ahbc))
2. Reset CPU

----- Messaggio originale -----

Quoted 99 lines

Da: "Kuo-Jung Su" <[email protected]>
A: "Paolo Bonzini" <[email protected]>
Inviato: Mercoledì, 6 marzo 2013 11:00:49
Oggetto: Re: [PATCH v6 07/24] hw/arm: add Faraday FTWDT010 watchdog timer support

2013/3/6 Paolo Bonzini <[email protected]>:

Quoted 68 lines
Quoted 68 lines

2013/3/6 Paolo Bonzini <[email protected]>:

Quoted 65 lines

Il 06/03/2013 08:27, Kuo-Jung Su ha scritto:

Quoted 46 lines

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      |    1 +
 hw/arm/faraday_a369_soc.c |   23 +++++
 hw/arm/ftwdt010.c         |  212
 +++++++++++++++++++++++++++++++++++++++++++++
 hw/arm/ftwdt010.h         |   35 ++++++++
 4 files changed, 271 insertions(+)
 create mode 100644 hw/arm/ftwdt010.c
 create mode 100644 hw/arm/ftwdt010.h
hw/arm/Makefile.objs +1 -0
index 2190edd..bc8e2de 100644
@@ -41,3 +41,4 @@ obj-y += ftintc020.o
 obj-y += ftahbc020.o
 obj-y += ftddrii030.o
 obj-y += ftpwmtmr010.o
+obj-y += ftwdt010.o
hw/arm/faraday_a369_soc.c +7 -0
index 66d9891..1bf64d4 100644
@@ -68,6 +68,25 @@ static void a369soc_reset(DeviceState *ds)
 }
 
 static void
+a369soc_system_reset(void *opaque)
+{
+    FaradaySoCState *s = FARADAY_SOC(opaque);
+
+    if (s->scu) {
+        device_reset(s->scu);
+    }

hw/arm/faraday_a369_soc.c static void a369soc_reset(DeviceState *ds) · line 87

Quoted 10 lines
hw/arm/faraday_a369_soc.c +10 -0
+    if (s->ddrc) {
+        device_reset(s->ddrc);
+    }
+    if (s->ahbc) {
+        device_reset(s->ahbc);
+    }
+    if (s->cpu) {
+        cpu_reset(CPU(s->cpu));
+    }
+}

Why is this needed? Aren't they called already by

    qemu_register_reset(qbus_reset_all_fn,
    sysbus_get_default());

?

Quoted 8 lines
Quoted 3 lines

It doesn't work while running under ROM mode. ( no -kernel ) Because Faraday SoC Platform usually designed to boot from ROM and followed by an AHB remapping process (i.e. remap ROM/RAM address).

What doesn't work exactly? Why aren't these called? Or are you forcing a particular reset order?

Paolo

While booting from ROM, the faraday soc usually remap the ROM / RAM before jumping into linux.

In other words, the system mapping is:

1. Power-On:

    ROM: 0x00000000
    RAM: N/A
    SRAM: 0xA0000000

2. AHB Remap (u-boot/linux)

    ROM: 0x20000000
    RAM: 0x00000000
Quoted 9 lines
Quoted 4 lines

So I have to register my own reset handler to

1. Undo the ROM/RAM remap (i.e. device_reset(s->ahbc))
2. Reset CPU

I understand that. What I'm missing is, why these reset handlers aren't called anyway when QEMU does qemu_devices_reset(), for example from qemu_system_reset().

1. arm_cpu_reset() is never be invoked from the default reset handler.

2. Undo ROM/RAM remap would make bus become unstable there is no guaranty when the bus would be stabilized.
(It looks to me that it's true for both QEMU and real hardware)

3. In QEMU, my guess is without arm_cpu_reset(), when the AHB remap process activated upon watchdog counts down to zero.
The PC (r15) could be anywhere, and so does the stack & bss. Which means the CPU would likely suffers from UNKNOWN INSTRUCTION, DATA ABORT... etc.

Quoted 2 lines

Also, I do not understand who performs this again:

It's performed at my ROM code:

https://github.com/dantesu1218/virgil/blob/master/arch/mach-a369/board.c

line 200 ~ 220

#ifndef CONFIG_SKIP_SYSINIT
/* Skip AHB remap if the jump address is not inside SDRAM address space */ "ldr r4, =0x10000000\n"
"cmp %2, r4\n"
"movhs pc, %2\n" /* jump without AHB remapped */
/* AHB remap
* REG32(CONFIG_IOBASE_DDR + 0x10) &= 0x00FFFFFF
* REG32(CONFIG_IOBASE_AHB + 0x88) = 0x00100F01
*/
"ldr r4, [%0, #0x10]\n"
"bic r4, #0xff000000\n"
"ldr r5, =0x00100f01\n"
".ALIGN 5\n" /* Make sure all the following codes to be fetched in a single 32-bytes cache line */

Quoted 10 lines

"str r4, [%0, #0x10]\n" /* REG32(CONFIG_IOBASE_DDR + 0x10) &= 0x00FFFFFF */ "str r5, [%1, #0x88]\n" /* REG32(CONFIG_IOBASE_AHB + 0x88) = 0x00100F01 */ "5:\n"
"ldr r4, [%2, #0]\n" /* while(magic != REG32(addr)) */
"teq r4, %3\n"
"bne 5b\n"
#endif
"mov pc, %2\n" /* jump */

Sorry, if I get you wrong, and what you're actually asking is:
Where or which module is responsible for SDRAM init and AHB remap?

The answer is:

1. ftahbc020: It's responsible for AHB remap, please check this:

   static void ftahbc020_mem_write()
   {
        ......
        if (!soc->ahb_remapped && (s->cr & CR_REMAP)) {
            /* Remap AHB slave 4 (ROM) & slave 6 (RAM) */
            /* 1. Remap RAM to base of ROM */
            soc->ram_base = soc->ahb_slave[4] & 0xfff00000;
            /* 2. Remap ROM to base of ROM + size of RAM */
            soc->rom_base = soc->ram_base
                          + ((1 << extract32(soc->ahb_slave[6], 16, 4)) << 20);
            /* 3. Update ROM memory map */
            sysbus_mmio_map(SYS_BUS_DEVICE(soc->rom), 0, soc->rom_base);
            /* 4. Update RAM memory map if it has been initialized. */
            if (soc->ddr_inited) {
                memory_region_del_subregion(soc->as, soc->ram);
                memory_region_add_subregion(soc->as, soc->ram_base, soc->ram);
            }
            soc->ahb_remapped = true;
        }
        ......
   }

2. ftddrii030: It's responsible for SDRAM init, please check this:

static void ftddrii030_mem_write()

{
    ......
        if (!soc->ddr_inited && (val & MSR_CMD_MRS)) {
            val &= ~MSR_CMD_MRS;
            val |= MSR_INIT_OK;
            memory_region_add_subregion(soc->as, soc->ram_base, soc->ram);
            soc->ddr_inited = true;
        }
    ......
}
Quoted 44 lines
Quoted 11 lines
(quoted diff) +8 -0
+        /* Remap AHB slave 4 (ROM) & slave 6 (RAM) */
+        /* 1. Remap RAM to base of ROM */
+        s->ram_base = s->ahb_slave[4] & 0xfff00000;
+        s->ahb_slave[6] = s->ram_base | (s->ahb_slave[6] & 0x000f0000);
+        /* 2. Remap ROM to base of ROM + size of RAM */
+        s->rom_base = s->ram_base
+                    + ((1 << extract32(s->ahb_slave[6], 16, 4)) << 20);
+        s->ahb_slave[4] = s->rom_base | (s->ahb_slave[4] & 0x000f0000);

when you do a system_reset and the board was started in kernel mode.

The problem is not about the kernel mode. In my words, I call them:

1. RAM Mode Emulation (Launching QEMU with -kernel) :
The emulator would assume that the SDRAM has been remapped to 0x00000000.

2. ROM Mode Emulation (Without -kernel):

    The emulator would map the 6KB ROM (pflash) to 0x00000000, 32KB SRAM
    to 0xA0000000, but no SDRAM

P.S:

In A369, the the boot sequence of ROM mode is:

1. Power-on
2. ROM code execution on ROM @ 0x00000000
3. 2nd bootstrap on SRAM @ 0xA0000000
4. General software (Linux/U-boot) execution on SDRAM @ 0x00000000

In newer design, (from 2010, after my referenced ROM code is reay) the the boot sequence of ROM mode becomes:

1. Power-on
2. ROM code execution on ROM @ 0x00000000
3. General software (Linux/U-boot) execution on SDRAM @ 0x00000000

Currently I have a kw9505 QEMU model ready for this, and since it's a customer ASIC,
it shall never be merged into open source.
But if you want, I could provide the kw9505.c with lots of coding style issues for function test.

Quoted 7 lines
Quoted 1 line

Paolo

--
Best wishes,
Kuo-Jung Su

--
Best wishes,
Kuo-Jung Su

#14 lore raw

PATCH v6 8/24 hw/arm: add Faraday FTRTC011 RTC timer support

In reply to Kuo-Jung Su

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      |    1 +
 hw/arm/faraday_a369_soc.c |   10 ++
 hw/arm/ftrtc011.c         |  346 +++++++++++++++++++++++++++++++++++++++++++++
 hw/arm/ftrtc011.h         |   49 +++++++
 4 files changed, 406 insertions(+)
 create mode 100644 hw/arm/ftrtc011.c
 create mode 100644 hw/arm/ftrtc011.h
hw/arm/Makefile.objs +1 -0
index bc8e2de..6dbac2f 100644
@@ -42,3 +42,4 @@ obj-y += ftahbc020.o
 obj-y += ftddrii030.o
 obj-y += ftpwmtmr010.o
 obj-y += ftwdt010.o
+obj-y += ftrtc011.o
hw/arm/faraday_a369_soc.c +10 -0
index 1bf64d4..4371a3a 100644
@@ -189,6 +189,16 @@ a369soc_device_init(FaradaySoCState *s)
     /* ftwdt010 */
     sysbus_create_simple("ftwdt010", 0x92200000, s->pic[46]);
     qemu_register_reset(a369soc_system_reset, s);
+
+    /* ftrtc011 */
+    sysbus_create_varargs("ftrtc011",
+                          0x92100000,
+                          s->pic[0],     /* Alarm (Level): NC in A369 */
+                          s->pic[42],    /* Alarm (Edge) */
+                          s->pic[43],    /* Second (Edge) */
+                          s->pic[44],    /* Minute (Edge) */
+                          s->pic[45],    /* Hour (Edge) */
+                          NULL);
 }
 
 static int a369soc_init(SysBusDevice *dev)
hw/arm/ftrtc011.c new file +346 -0

346 lines not on this page · raw message

hw/arm/ftrtc011.h new file +49 -0

49 lines not on this page · raw message

Signature · 1 line
1.7.9.5
#15 lore raw

Re: [Qemu-devel] [PATCH v6 08/24] hw/arm: add Faraday FTRTC011 RTC timer support

Il 06/03/2013 08:27, Kuo-Jung Su ha scritto:

Quoted 127 lines

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      |    1 +
 hw/arm/faraday_a369_soc.c |   10 ++
 hw/arm/ftrtc011.c         |  346 +++++++++++++++++++++++++++++++++++++++++++++
 hw/arm/ftrtc011.h         |   49 +++++++
 4 files changed, 406 insertions(+)
 create mode 100644 hw/arm/ftrtc011.c
 create mode 100644 hw/arm/ftrtc011.h
hw/arm/Makefile.objs +1 -0
index bc8e2de..6dbac2f 100644
@@ -42,3 +42,4 @@ obj-y += ftahbc020.o
 obj-y += ftddrii030.o
 obj-y += ftpwmtmr010.o
 obj-y += ftwdt010.o
+obj-y += ftrtc011.o
hw/arm/faraday_a369_soc.c +10 -0
index 1bf64d4..4371a3a 100644
@@ -189,6 +189,16 @@ a369soc_device_init(FaradaySoCState *s)
     /* ftwdt010 */
     sysbus_create_simple("ftwdt010", 0x92200000, s->pic[46]);
     qemu_register_reset(a369soc_system_reset, s);
+
+    /* ftrtc011 */
+    sysbus_create_varargs("ftrtc011",
+                          0x92100000,
+                          s->pic[0],     /* Alarm (Level): NC in A369 */
+                          s->pic[42],    /* Alarm (Edge) */
+                          s->pic[43],    /* Second (Edge) */
+                          s->pic[44],    /* Minute (Edge) */
+                          s->pic[45],    /* Hour (Edge) */
+                          NULL);
 }
 
 static int a369soc_init(SysBusDevice *dev)
hw/arm/ftrtc011.c new file +72 -0
new file mode 100644
index 0000000..2e8776e
@@ -0,0 +1,346 @@
+/*
+ * QEMU model of the FTRTC011 RTC Timer
+ *
+ * Copyright (C) 2012 Faraday Technology
+ * Written by Dante Su <[email protected]>
+ *
+ * This file is licensed under GNU GPL v2+.
+ */
+
+#include "hw/sysbus.h"
+#include "qemu/timer.h"
+#include "sysemu/sysemu.h"
+
+#include "faraday.h"
+#include "ftrtc011.h"
+
+enum ftrtc011_irqpin {
+    IRQ_ALARM_LEVEL = 0,
+    IRQ_ALARM_EDGE,
+    IRQ_SEC,
+    IRQ_MIN,
+    IRQ_HOUR,
+    IRQ_DAY,
+};
+
+#define TYPE_FTRTC011   "ftrtc011"
+
+#define CFG_REGSIZE     (0x3c / 4)
+
+typedef struct Ftrtc011State {
+    SysBusDevice busdev;
+    MemoryRegion mmio;
+
+    qemu_irq irq[6];
+
+    QEMUTimer *qtimer;
+    int64_t rtc_start;
+
+    /* HW register caches */
+    uint32_t regs[CFG_REGSIZE];
+} Ftrtc011State;
+
+#define FTRTC011(obj) \
+    OBJECT_CHECK(Ftrtc011State, obj, TYPE_FTRTC011)
+
+#define RTC_REG32(s, off) \
+    ((s)->regs[(off) / 4])
+
+/* Update interrupts.  */
+static void ftrtc011_update_irq(Ftrtc011State *s)
+{
+    uint32_t mask = extract32(RTC_REG32(s, REG_CR), 1, 5)
+                  & RTC_REG32(s, REG_ISR);
+
+    qemu_set_irq(s->irq[IRQ_ALARM_LEVEL], (mask & ISR_ALARM) ? 1 : 0);
+
+    if (mask) {
+        if (mask & ISR_SEC) {
+            qemu_irq_pulse(s->irq[IRQ_SEC]);
+        }
+        if (mask & ISR_MIN) {
+            qemu_irq_pulse(s->irq[IRQ_MIN]);
+        }
+        if (mask & ISR_HOUR) {
+            qemu_irq_pulse(s->irq[IRQ_HOUR]);
+        }
+        if (mask & ISR_DAY) {
+            qemu_irq_pulse(s->irq[IRQ_DAY]);
+        }
+        if (mask & ISR_ALARM) {
+            qemu_irq_pulse(s->irq[IRQ_ALARM_EDGE]);
+        }

hw/arm/ftrtc011.c line 82

Quoted 10 lines
hw/arm/ftrtc011.c new file +10 -0
+    }
+}
+
+static void ftrtc011_timer_resync(Ftrtc011State *s)
+{
+    int64_t elapsed = RTC_REG32(s, REG_SEC)
+                    + (60 * RTC_REG32(s, REG_MIN))
+                    + (3600 * RTC_REG32(s, REG_HOUR))
+                    + (86400 * RTC_REG32(s, REG_DAY));
+    s->rtc_start = get_clock_realtime() - elapsed * 1000000000LL;

Please use instead qemu_get_clock_ns(rtc_clock).

In general, use rtc_clock instead of rt_clock. This way a) you can control the clock with -clock; b) you can write testcases.

Please add a testcase for the RTC clock, since we have other examples of tested devices like this one.

Paolo

Quoted 320 lines
hw/arm/ftrtc011.c new file +264 -0
+}
+
+static void ftrtc011_timer_update(Ftrtc011State *s)
+{
+    int64_t elapsed;
+    uint8_t sec, min, hr;
+    uint32_t day;
+
+    if (!(RTC_REG32(s, REG_CR) & CR_EN)) {
+        return;
+    }
+
+    /*
+     * Although the timer is supposed to tick per second,
+     * there is no guarantee that the tick interval is
+     * exactly 1 second, and the system might even be
+     * suspend/resume which cause large time drift here.
+     */
+    elapsed = (get_clock_realtime() - s->rtc_start) / 1000000000LL;
+    sec = (uint8_t)(elapsed % 60LL);
+    min = (uint8_t)((elapsed / 60LL) % 60LL);
+    hr = (uint8_t)((elapsed / 3600LL) % 24LL);
+    day = (uint32_t)(elapsed / 86400LL);
+
+    /* sec interrupt */
+    if ((RTC_REG32(s, REG_SEC) != sec)
+        && (RTC_REG32(s, REG_CR) & CR_INTR_SEC)) {
+        RTC_REG32(s, REG_ISR) |= ISR_SEC;
+    }
+    /* min interrupt */
+    if ((RTC_REG32(s, REG_MIN) != min)
+        && (RTC_REG32(s, REG_CR) & CR_INTR_MIN)) {
+        RTC_REG32(s, REG_ISR) |= ISR_MIN;
+    }
+    /* hr interrupt */
+    if ((RTC_REG32(s, REG_HOUR) != hr)
+        && (RTC_REG32(s, REG_CR) & CR_INTR_HOUR)) {
+        RTC_REG32(s, REG_ISR) |= ISR_HOUR;
+    }
+    /* day interrupt */
+    if ((RTC_REG32(s, REG_DAY) != day)
+        && (RTC_REG32(s, REG_CR) & CR_INTR_DAY)) {
+        RTC_REG32(s, REG_ISR) |= ISR_DAY;
+    }
+    /* alarm interrupt */
+    if (RTC_REG32(s, REG_CR) & CR_INTR_ALARM) {
+        if ((RTC_REG32(s, REG_SEC)
+            | (RTC_REG32(s, REG_MIN) << 8)
+            | (RTC_REG32(s, REG_HOUR) << 16)) ==
+                (RTC_REG32(s, REG_ALARM_SEC)
+                | (RTC_REG32(s, REG_ALARM_MIN) << 8)
+                | (RTC_REG32(s, REG_ALARM_HOUR) << 16))) {
+            RTC_REG32(s, REG_ISR) |= ISR_ALARM;
+        }
+    }
+
+    /* send interrupt signal */
+    ftrtc011_update_irq(s);
+
+    /* update RTC registers */
+    RTC_REG32(s, REG_SEC) = (uint8_t)sec;
+    RTC_REG32(s, REG_MIN) = (uint8_t)min;
+    RTC_REG32(s, REG_HOUR) = (uint8_t)hr;
+    RTC_REG32(s, REG_DAY) = (uint16_t)day;
+}
+
+static uint64_t ftrtc011_mem_read(void *opaque, hwaddr addr, unsigned size)
+{
+    Ftrtc011State *s = FTRTC011(opaque);
+    uint32_t ret = 0;
+
+    switch (addr) {
+    case REG_SEC ... REG_DAY:
+        ftrtc011_timer_update(s);
+    case REG_ALARM_SEC ... REG_ISR:
+        ret = s->regs[addr / 4];
+        break;
+    case REG_REVR:
+        ret = 0x00010000;  /* rev. 1.0.0 */
+        break;
+    case REG_CURRENT:
+        ftrtc011_timer_update(s);
+        ret |= RTC_REG32(s, REG_DAY) << 17;
+        ret |= RTC_REG32(s, REG_HOUR) << 12;
+        ret |= RTC_REG32(s, REG_MIN) << 6;
+        ret |= RTC_REG32(s, REG_SEC);
+        break;
+    default:
+        qemu_log_mask(LOG_GUEST_ERROR,
+            "ftrtc011: undefined memory access@%#" HWADDR_PRIx "\n", addr);
+        break;
+    }
+
+    return ret;
+}
+
+static void
+ftrtc011_mem_write(void *opaque, hwaddr addr, uint64_t val, unsigned size)
+{
+    Ftrtc011State *s = FTRTC011(opaque);
+
+    switch (addr) {
+    case REG_ALARM_SEC ... REG_ALARM_HOUR:
+    case REG_WSEC ... REG_WHOUR:
+        s->regs[addr / 4] = (uint32_t)val & 0x3f;
+        break;
+    case REG_WDAY:
+        s->regs[addr / 4] = (uint32_t)val & 0xffff;
+        break;
+    case REG_CR:
+        /* update the RTC counter with the user supplied values */
+        if (val & CR_LOAD) {
+            RTC_REG32(s, REG_SEC) = RTC_REG32(s, REG_WSEC);
+            RTC_REG32(s, REG_MIN) = RTC_REG32(s, REG_WMIN);
+            RTC_REG32(s, REG_HOUR) = RTC_REG32(s, REG_WHOUR);
+            RTC_REG32(s, REG_DAY) = RTC_REG32(s, REG_WDAY);
+            val &= ~CR_LOAD;
+            ftrtc011_timer_resync(s);
+        }
+        /* check if RTC enabled */
+        if (val & CR_EN) {
+            if (!(RTC_REG32(s, REG_CR) & CR_EN)) {
+                ftrtc011_timer_resync(s);
+            }
+            qemu_mod_timer(s->qtimer, qemu_get_clock_ms(rt_clock) + 1000);
+        } else {
+            qemu_del_timer(s->qtimer);
+        }
+        RTC_REG32(s, REG_CR) = (uint32_t)val;
+        break;
+    case REG_ISR:
+        RTC_REG32(s, REG_ISR) &= ~((uint32_t)val);
+        ftrtc011_update_irq(s);
+        break;
+    default:
+        qemu_log_mask(LOG_GUEST_ERROR,
+            "ftrtc011: undefined memory access@%#" HWADDR_PRIx "\n", addr);
+        break;
+    }
+
+    if (RTC_REG32(s, REG_ALARM_SEC) > 59
+        || RTC_REG32(s, REG_ALARM_MIN) > 59
+        || RTC_REG32(s, REG_ALARM_HOUR) > 23
+        || RTC_REG32(s, REG_WSEC) > 59
+        || RTC_REG32(s, REG_WMIN) > 59
+        || RTC_REG32(s, REG_WHOUR) > 23) {
+        goto werr;
+    }
+
+    return;
+
+werr:
+    fprintf(stderr, "ftrtc011: %u is an invalid value.\n", (uint32_t)val);
+    exit(1);
+}
+
+static const MemoryRegionOps mmio_ops = {
+    .read  = ftrtc011_mem_read,
+    .write = ftrtc011_mem_write,
+    .endianness = DEVICE_LITTLE_ENDIAN,
+    .valid = {
+        .min_access_size = 4,
+        .max_access_size = 4
+    }
+};
+
+static void ftrtc011_timer_tick(void *opaque)
+{
+    Ftrtc011State *s = FTRTC011(opaque);
+    ftrtc011_timer_update(s);
+    qemu_mod_timer(s->qtimer, qemu_get_clock_ms(rt_clock) + 1000);
+}
+
+static void ftrtc011_reset(DeviceState *ds)
+{
+    Ftrtc011State *s = FTRTC011(SYS_BUS_DEVICE(ds));
+
+    qemu_del_timer(s->qtimer);
+    memset(s->regs, 0, sizeof(s->regs));
+    ftrtc011_update_irq(s);
+}
+
+static void ftrtc011_save(QEMUFile *f, void *opaque)
+{
+    int i;
+    Ftrtc011State *s = FTRTC011(opaque);
+
+    for (i = 0; i < sizeof(s->regs) / 4; ++i) {
+        qemu_put_be32(f, s->regs[i]);
+    }
+}
+
+static int ftrtc011_load(QEMUFile *f, void *opaque, int version_id)
+{
+    int i;
+    Ftrtc011State *s = FTRTC011(opaque);
+
+    for (i = 0; i < sizeof(s->regs) / 4; ++i) {
+        s->regs[i] = qemu_get_be32(f);
+    }
+
+    return 0;
+}
+
+static int ftrtc011_init(SysBusDevice *dev)
+{
+    Ftrtc011State *s = FTRTC011(dev);
+
+    s->qtimer = qemu_new_timer_ms(rt_clock, ftrtc011_timer_tick, s);
+
+    memory_region_init_io(&s->mmio,
+                          &mmio_ops,
+                          s,
+                          TYPE_FTRTC011,
+                          0x1000);
+    sysbus_init_mmio(dev, &s->mmio);
+    sysbus_init_irq(dev, &s->irq[IRQ_ALARM_LEVEL]);
+    sysbus_init_irq(dev, &s->irq[IRQ_ALARM_EDGE]);
+    sysbus_init_irq(dev, &s->irq[IRQ_SEC]);
+    sysbus_init_irq(dev, &s->irq[IRQ_MIN]);
+    sysbus_init_irq(dev, &s->irq[IRQ_HOUR]);
+    sysbus_init_irq(dev, &s->irq[IRQ_DAY]);
+
+    register_savevm(&dev->qdev, TYPE_FTRTC011, -1, 0,
+                    ftrtc011_save, ftrtc011_load, s);
+
+    return 0;
+}
+
+static const VMStateDescription vmstate_ftrtc011 = {
+    .name = TYPE_FTRTC011,
+    .version_id = 1,
+    .minimum_version_id = 1,
+    .minimum_version_id_old = 1,
+    .fields = (VMStateField[]) {
+        VMSTATE_UINT32_ARRAY(regs, Ftrtc011State, CFG_REGSIZE),
+        VMSTATE_END_OF_LIST()
+    }
+};
+
+static void ftrtc011_class_init(ObjectClass *klass, void *data)
+{
+    SysBusDeviceClass *k = SYS_BUS_DEVICE_CLASS(klass);
+    DeviceClass *dc = DEVICE_CLASS(klass);
+
+    k->init     = ftrtc011_init;
+    dc->vmsd    = &vmstate_ftrtc011;
+    dc->reset   = ftrtc011_reset;
+    dc->no_user = 1;
+}
+
+static const TypeInfo ftrtc011_info = {
+    .name           = TYPE_FTRTC011,
+    .parent         = TYPE_SYS_BUS_DEVICE,
+    .instance_size  = sizeof(Ftrtc011State),
+    .class_init     = ftrtc011_class_init,
+};
+
+static void ftrtc011_register_types(void)
+{
+    type_register_static(&ftrtc011_info);
+}
+
+type_init(ftrtc011_register_types)
hw/arm/ftrtc011.h new file +49 -0
new file mode 100644
index 0000000..feb8aab
@@ -0,0 +1,49 @@
+/*
+ * QEMU model of the FTRTC011 RTC Timer
+ *
+ * Copyright (C) 2012 Faraday Technology
+ * Written by Dante Su <[email protected]>
+ *
+ * This file is licensed under GNU GPL v2+.
+ */
+#ifndef HW_ARM_FTRTC011_H
+#define HW_ARM_FTRTC011_H
+
+#include "qemu/bitops.h"
+
+/* Hardware registers */
+#define REG_SEC         0x00
+#define REG_MIN         0x04
+#define REG_HOUR        0x08
+#define REG_DAY         0x0C
+
+#define REG_ALARM_SEC   0x10    /* Alarm: sec */
+#define REG_ALARM_MIN   0x14    /* Alarm: min */
+#define REG_ALARM_HOUR  0x18    /* Alarm: hour */
+
+#define REG_CR          0x20    /* Control Register */
+#define REG_WSEC        0x24    /* Write SEC Register */
+#define REG_WMIN        0x28    /* Write MIN Register */
+#define REG_WHOUR       0x2C    /* Write HOUR Register */
+#define REG_WDAY        0x30    /* Write DAY Register */
+#define REG_ISR         0x34    /* Interrupt Status Register */
+
+#define REG_REVR        0x3C    /* Revision Register */
+#define REG_CURRENT     0x44    /* Group-up day/hour/min/sec as a register */
+
+#define CR_LOAD         BIT(6)  /* Update counters by Wxxx registers */
+#define CR_INTR_ALARM   BIT(5)  /* Alarm interrupt enabled */
+#define CR_INTR_DAY     BIT(4)  /* DDAY interrupt enabled */
+#define CR_INTR_HOUR    BIT(3)  /* HOUR interrupt enabled */
+#define CR_INTR_MIN     BIT(2)  /* MIN interrupt enabled */
+#define CR_INTR_SEC     BIT(1)  /* SEC interrupt enabled */
+#define CR_EN           BIT(0)  /* RTC enabled */
+
+#define ISR_LOAD        BIT(5)  /* CR_LOAD finished (no interrupt occurs) */
+#define ISR_ALARM       BIT(4)
+#define ISR_DAY         BIT(3)
+#define ISR_HOUR        BIT(2)
+#define ISR_MIN         BIT(1)
+#define ISR_SEC         BIT(0)
+
+#endif
#16 lore raw

Re: [Qemu-devel] [PATCH v6 08/24] hw/arm: add Faraday FTRTC011 RTC timer support

2013/3/6 Paolo Bonzini <[email protected]>:

Quoted 141 lines

Il 06/03/2013 08:27, Kuo-Jung Su ha scritto:

Quoted 127 lines

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      |    1 +
 hw/arm/faraday_a369_soc.c |   10 ++
 hw/arm/ftrtc011.c         |  346 +++++++++++++++++++++++++++++++++++++++++++++
 hw/arm/ftrtc011.h         |   49 +++++++
 4 files changed, 406 insertions(+)
 create mode 100644 hw/arm/ftrtc011.c
 create mode 100644 hw/arm/ftrtc011.h
hw/arm/Makefile.objs +1 -0
index bc8e2de..6dbac2f 100644
@@ -42,3 +42,4 @@ obj-y += ftahbc020.o
 obj-y += ftddrii030.o
 obj-y += ftpwmtmr010.o
 obj-y += ftwdt010.o
+obj-y += ftrtc011.o
hw/arm/faraday_a369_soc.c +10 -0
index 1bf64d4..4371a3a 100644
@@ -189,6 +189,16 @@ a369soc_device_init(FaradaySoCState *s)
     /* ftwdt010 */
     sysbus_create_simple("ftwdt010", 0x92200000, s->pic[46]);
     qemu_register_reset(a369soc_system_reset, s);
+
+    /* ftrtc011 */
+    sysbus_create_varargs("ftrtc011",
+                          0x92100000,
+                          s->pic[0],     /* Alarm (Level): NC in A369 */
+                          s->pic[42],    /* Alarm (Edge) */
+                          s->pic[43],    /* Second (Edge) */
+                          s->pic[44],    /* Minute (Edge) */
+                          s->pic[45],    /* Hour (Edge) */
+                          NULL);
 }
 
 static int a369soc_init(SysBusDevice *dev)
hw/arm/ftrtc011.c new file +72 -0
new file mode 100644
index 0000000..2e8776e
@@ -0,0 +1,346 @@
+/*
+ * QEMU model of the FTRTC011 RTC Timer
+ *
+ * Copyright (C) 2012 Faraday Technology
+ * Written by Dante Su <[email protected]>
+ *
+ * This file is licensed under GNU GPL v2+.
+ */
+
+#include "hw/sysbus.h"
+#include "qemu/timer.h"
+#include "sysemu/sysemu.h"
+
+#include "faraday.h"
+#include "ftrtc011.h"
+
+enum ftrtc011_irqpin {
+    IRQ_ALARM_LEVEL = 0,
+    IRQ_ALARM_EDGE,
+    IRQ_SEC,
+    IRQ_MIN,
+    IRQ_HOUR,
+    IRQ_DAY,
+};
+
+#define TYPE_FTRTC011   "ftrtc011"
+
+#define CFG_REGSIZE     (0x3c / 4)
+
+typedef struct Ftrtc011State {
+    SysBusDevice busdev;
+    MemoryRegion mmio;
+
+    qemu_irq irq[6];
+
+    QEMUTimer *qtimer;
+    int64_t rtc_start;
+
+    /* HW register caches */
+    uint32_t regs[CFG_REGSIZE];
+} Ftrtc011State;
+
+#define FTRTC011(obj) \
+    OBJECT_CHECK(Ftrtc011State, obj, TYPE_FTRTC011)
+
+#define RTC_REG32(s, off) \
+    ((s)->regs[(off) / 4])
+
+/* Update interrupts.  */
+static void ftrtc011_update_irq(Ftrtc011State *s)
+{
+    uint32_t mask = extract32(RTC_REG32(s, REG_CR), 1, 5)
+                  & RTC_REG32(s, REG_ISR);
+
+    qemu_set_irq(s->irq[IRQ_ALARM_LEVEL], (mask & ISR_ALARM) ? 1 : 0);
+
+    if (mask) {
+        if (mask & ISR_SEC) {
+            qemu_irq_pulse(s->irq[IRQ_SEC]);
+        }
+        if (mask & ISR_MIN) {
+            qemu_irq_pulse(s->irq[IRQ_MIN]);
+        }
+        if (mask & ISR_HOUR) {
+            qemu_irq_pulse(s->irq[IRQ_HOUR]);
+        }
+        if (mask & ISR_DAY) {
+            qemu_irq_pulse(s->irq[IRQ_DAY]);
+        }
+        if (mask & ISR_ALARM) {
+            qemu_irq_pulse(s->irq[IRQ_ALARM_EDGE]);
+        }

hw/arm/ftrtc011.c line 82

Quoted 10 lines
hw/arm/ftrtc011.c new file +10 -0
+    }
+}
+
+static void ftrtc011_timer_resync(Ftrtc011State *s)
+{
+    int64_t elapsed = RTC_REG32(s, REG_SEC)
+                    + (60 * RTC_REG32(s, REG_MIN))
+                    + (3600 * RTC_REG32(s, REG_HOUR))
+                    + (86400 * RTC_REG32(s, REG_DAY));
+    s->rtc_start = get_clock_realtime() - elapsed * 1000000000LL;

Please use instead qemu_get_clock_ns(rtc_clock).

Quoted 3 lines

In general, use rtc_clock instead of rt_clock. This way a) you can control the clock with -clock; b) you can write testcases.

Got it, thanks

Quoted 3 lines

Please add a testcase for the RTC clock, since we have other examples of tested devices like this one.

Excuse me, could you please show me the way how to build the test cases and launch the test case.

I do have found a web page to qtest at the following link:
http://wiki.qemu.org/Features/QTest

But it's wrong at both 'build/example usage' and 'Additional Details/Status', please see the logs bellow:

dante@vmware:/pub/qemu$ ./configure --target-list=arm-softmmu
--audio-drv-list="oss alsa sdl" --enable-qtest
ERROR: unknown option --enable-qtest
dante@vmware:/pub/qemu$ ./arm-softmmu/qemu-system-arm -test ?
qemu-system-arm: -test: invalid option
Quoted 314 lines

Paolo

Quoted 312 lines
hw/arm/ftrtc011.c new file +264 -0
+}
+
+static void ftrtc011_timer_update(Ftrtc011State *s)
+{
+    int64_t elapsed;
+    uint8_t sec, min, hr;
+    uint32_t day;
+
+    if (!(RTC_REG32(s, REG_CR) & CR_EN)) {
+        return;
+    }
+
+    /*
+     * Although the timer is supposed to tick per second,
+     * there is no guarantee that the tick interval is
+     * exactly 1 second, and the system might even be
+     * suspend/resume which cause large time drift here.
+     */
+    elapsed = (get_clock_realtime() - s->rtc_start) / 1000000000LL;
+    sec = (uint8_t)(elapsed % 60LL);
+    min = (uint8_t)((elapsed / 60LL) % 60LL);
+    hr = (uint8_t)((elapsed / 3600LL) % 24LL);
+    day = (uint32_t)(elapsed / 86400LL);
+
+    /* sec interrupt */
+    if ((RTC_REG32(s, REG_SEC) != sec)
+        && (RTC_REG32(s, REG_CR) & CR_INTR_SEC)) {
+        RTC_REG32(s, REG_ISR) |= ISR_SEC;
+    }
+    /* min interrupt */
+    if ((RTC_REG32(s, REG_MIN) != min)
+        && (RTC_REG32(s, REG_CR) & CR_INTR_MIN)) {
+        RTC_REG32(s, REG_ISR) |= ISR_MIN;
+    }
+    /* hr interrupt */
+    if ((RTC_REG32(s, REG_HOUR) != hr)
+        && (RTC_REG32(s, REG_CR) & CR_INTR_HOUR)) {
+        RTC_REG32(s, REG_ISR) |= ISR_HOUR;
+    }
+    /* day interrupt */
+    if ((RTC_REG32(s, REG_DAY) != day)
+        && (RTC_REG32(s, REG_CR) & CR_INTR_DAY)) {
+        RTC_REG32(s, REG_ISR) |= ISR_DAY;
+    }
+    /* alarm interrupt */
+    if (RTC_REG32(s, REG_CR) & CR_INTR_ALARM) {
+        if ((RTC_REG32(s, REG_SEC)
+            | (RTC_REG32(s, REG_MIN) << 8)
+            | (RTC_REG32(s, REG_HOUR) << 16)) ==
+                (RTC_REG32(s, REG_ALARM_SEC)
+                | (RTC_REG32(s, REG_ALARM_MIN) << 8)
+                | (RTC_REG32(s, REG_ALARM_HOUR) << 16))) {
+            RTC_REG32(s, REG_ISR) |= ISR_ALARM;
+        }
+    }
+
+    /* send interrupt signal */
+    ftrtc011_update_irq(s);
+
+    /* update RTC registers */
+    RTC_REG32(s, REG_SEC) = (uint8_t)sec;
+    RTC_REG32(s, REG_MIN) = (uint8_t)min;
+    RTC_REG32(s, REG_HOUR) = (uint8_t)hr;
+    RTC_REG32(s, REG_DAY) = (uint16_t)day;
+}
+
+static uint64_t ftrtc011_mem_read(void *opaque, hwaddr addr, unsigned size)
+{
+    Ftrtc011State *s = FTRTC011(opaque);
+    uint32_t ret = 0;
+
+    switch (addr) {
+    case REG_SEC ... REG_DAY:
+        ftrtc011_timer_update(s);
+    case REG_ALARM_SEC ... REG_ISR:
+        ret = s->regs[addr / 4];
+        break;
+    case REG_REVR:
+        ret = 0x00010000;  /* rev. 1.0.0 */
+        break;
+    case REG_CURRENT:
+        ftrtc011_timer_update(s);
+        ret |= RTC_REG32(s, REG_DAY) << 17;
+        ret |= RTC_REG32(s, REG_HOUR) << 12;
+        ret |= RTC_REG32(s, REG_MIN) << 6;
+        ret |= RTC_REG32(s, REG_SEC);
+        break;
+    default:
+        qemu_log_mask(LOG_GUEST_ERROR,
+            "ftrtc011: undefined memory access@%#" HWADDR_PRIx "\n", addr);
+        break;
+    }
+
+    return ret;
+}
+
+static void
+ftrtc011_mem_write(void *opaque, hwaddr addr, uint64_t val, unsigned size)
+{
+    Ftrtc011State *s = FTRTC011(opaque);
+
+    switch (addr) {
+    case REG_ALARM_SEC ... REG_ALARM_HOUR:
+    case REG_WSEC ... REG_WHOUR:
+        s->regs[addr / 4] = (uint32_t)val & 0x3f;
+        break;
+    case REG_WDAY:
+        s->regs[addr / 4] = (uint32_t)val & 0xffff;
+        break;
+    case REG_CR:
+        /* update the RTC counter with the user supplied values */
+        if (val & CR_LOAD) {
+            RTC_REG32(s, REG_SEC) = RTC_REG32(s, REG_WSEC);
+            RTC_REG32(s, REG_MIN) = RTC_REG32(s, REG_WMIN);
+            RTC_REG32(s, REG_HOUR) = RTC_REG32(s, REG_WHOUR);
+            RTC_REG32(s, REG_DAY) = RTC_REG32(s, REG_WDAY);
+            val &= ~CR_LOAD;
+            ftrtc011_timer_resync(s);
+        }
+        /* check if RTC enabled */
+        if (val & CR_EN) {
+            if (!(RTC_REG32(s, REG_CR) & CR_EN)) {
+                ftrtc011_timer_resync(s);
+            }
+            qemu_mod_timer(s->qtimer, qemu_get_clock_ms(rt_clock) + 1000);
+        } else {
+            qemu_del_timer(s->qtimer);
+        }
+        RTC_REG32(s, REG_CR) = (uint32_t)val;
+        break;
+    case REG_ISR:
+        RTC_REG32(s, REG_ISR) &= ~((uint32_t)val);
+        ftrtc011_update_irq(s);
+        break;
+    default:
+        qemu_log_mask(LOG_GUEST_ERROR,
+            "ftrtc011: undefined memory access@%#" HWADDR_PRIx "\n", addr);
+        break;
+    }
+
+    if (RTC_REG32(s, REG_ALARM_SEC) > 59
+        || RTC_REG32(s, REG_ALARM_MIN) > 59
+        || RTC_REG32(s, REG_ALARM_HOUR) > 23
+        || RTC_REG32(s, REG_WSEC) > 59
+        || RTC_REG32(s, REG_WMIN) > 59
+        || RTC_REG32(s, REG_WHOUR) > 23) {
+        goto werr;
+    }
+
+    return;
+
+werr:
+    fprintf(stderr, "ftrtc011: %u is an invalid value.\n", (uint32_t)val);
+    exit(1);
+}
+
+static const MemoryRegionOps mmio_ops = {
+    .read  = ftrtc011_mem_read,
+    .write = ftrtc011_mem_write,
+    .endianness = DEVICE_LITTLE_ENDIAN,
+    .valid = {
+        .min_access_size = 4,
+        .max_access_size = 4
+    }
+};
+
+static void ftrtc011_timer_tick(void *opaque)
+{
+    Ftrtc011State *s = FTRTC011(opaque);
+    ftrtc011_timer_update(s);
+    qemu_mod_timer(s->qtimer, qemu_get_clock_ms(rt_clock) + 1000);
+}
+
+static void ftrtc011_reset(DeviceState *ds)
+{
+    Ftrtc011State *s = FTRTC011(SYS_BUS_DEVICE(ds));
+
+    qemu_del_timer(s->qtimer);
+    memset(s->regs, 0, sizeof(s->regs));
+    ftrtc011_update_irq(s);
+}
+
+static void ftrtc011_save(QEMUFile *f, void *opaque)
+{
+    int i;
+    Ftrtc011State *s = FTRTC011(opaque);
+
+    for (i = 0; i < sizeof(s->regs) / 4; ++i) {
+        qemu_put_be32(f, s->regs[i]);
+    }
+}
+
+static int ftrtc011_load(QEMUFile *f, void *opaque, int version_id)
+{
+    int i;
+    Ftrtc011State *s = FTRTC011(opaque);
+
+    for (i = 0; i < sizeof(s->regs) / 4; ++i) {
+        s->regs[i] = qemu_get_be32(f);
+    }
+
+    return 0;
+}
+
+static int ftrtc011_init(SysBusDevice *dev)
+{
+    Ftrtc011State *s = FTRTC011(dev);
+
+    s->qtimer = qemu_new_timer_ms(rt_clock, ftrtc011_timer_tick, s);
+
+    memory_region_init_io(&s->mmio,
+                          &mmio_ops,
+                          s,
+                          TYPE_FTRTC011,
+                          0x1000);
+    sysbus_init_mmio(dev, &s->mmio);
+    sysbus_init_irq(dev, &s->irq[IRQ_ALARM_LEVEL]);
+    sysbus_init_irq(dev, &s->irq[IRQ_ALARM_EDGE]);
+    sysbus_init_irq(dev, &s->irq[IRQ_SEC]);
+    sysbus_init_irq(dev, &s->irq[IRQ_MIN]);
+    sysbus_init_irq(dev, &s->irq[IRQ_HOUR]);
+    sysbus_init_irq(dev, &s->irq[IRQ_DAY]);
+
+    register_savevm(&dev->qdev, TYPE_FTRTC011, -1, 0,
+                    ftrtc011_save, ftrtc011_load, s);
+
+    return 0;
+}
+
+static const VMStateDescription vmstate_ftrtc011 = {
+    .name = TYPE_FTRTC011,
+    .version_id = 1,
+    .minimum_version_id = 1,
+    .minimum_version_id_old = 1,
+    .fields = (VMStateField[]) {
+        VMSTATE_UINT32_ARRAY(regs, Ftrtc011State, CFG_REGSIZE),
+        VMSTATE_END_OF_LIST()
+    }
+};
+
+static void ftrtc011_class_init(ObjectClass *klass, void *data)
+{
+    SysBusDeviceClass *k = SYS_BUS_DEVICE_CLASS(klass);
+    DeviceClass *dc = DEVICE_CLASS(klass);
+
+    k->init     = ftrtc011_init;
+    dc->vmsd    = &vmstate_ftrtc011;
+    dc->reset   = ftrtc011_reset;
+    dc->no_user = 1;
+}
+
+static const TypeInfo ftrtc011_info = {
+    .name           = TYPE_FTRTC011,
+    .parent         = TYPE_SYS_BUS_DEVICE,
+    .instance_size  = sizeof(Ftrtc011State),
+    .class_init     = ftrtc011_class_init,
+};
+
+static void ftrtc011_register_types(void)
+{
+    type_register_static(&ftrtc011_info);
+}
+
+type_init(ftrtc011_register_types)
hw/arm/ftrtc011.h new file +42 -0
new file mode 100644
index 0000000..feb8aab
@@ -0,0 +1,49 @@
+/*
+ * QEMU model of the FTRTC011 RTC Timer
+ *
+ * Copyright (C) 2012 Faraday Technology
+ * Written by Dante Su <[email protected]>
+ *
+ * This file is licensed under GNU GPL v2+.
+ */
+#ifndef HW_ARM_FTRTC011_H
+#define HW_ARM_FTRTC011_H
+
+#include "qemu/bitops.h"
+
+/* Hardware registers */
+#define REG_SEC         0x00
+#define REG_MIN         0x04
+#define REG_HOUR        0x08
+#define REG_DAY         0x0C
+
+#define REG_ALARM_SEC   0x10    /* Alarm: sec */
+#define REG_ALARM_MIN   0x14    /* Alarm: min */
+#define REG_ALARM_HOUR  0x18    /* Alarm: hour */
+
+#define REG_CR          0x20    /* Control Register */
+#define REG_WSEC        0x24    /* Write SEC Register */
+#define REG_WMIN        0x28    /* Write MIN Register */
+#define REG_WHOUR       0x2C    /* Write HOUR Register */
+#define REG_WDAY        0x30    /* Write DAY Register */
+#define REG_ISR         0x34    /* Interrupt Status Register */
+
+#define REG_REVR        0x3C    /* Revision Register */
+#define REG_CURRENT     0x44    /* Group-up day/hour/min/sec as a register */
+
+#define CR_LOAD         BIT(6)  /* Update counters by Wxxx registers */
+#define CR_INTR_ALARM   BIT(5)  /* Alarm interrupt enabled */
+#define CR_INTR_DAY     BIT(4)  /* DDAY interrupt enabled */
+#define CR_INTR_HOUR    BIT(3)  /* HOUR interrupt enabled */
+#define CR_INTR_MIN     BIT(2)  /* MIN interrupt enabled */
+#define CR_INTR_SEC     BIT(1)  /* SEC interrupt enabled */
+#define CR_EN           BIT(0)  /* RTC enabled */
+
+#define ISR_LOAD        BIT(5)  /* CR_LOAD finished (no interrupt occurs) */
Quoted 9 lines

hw/arm/ftrtc011.h line 49

Quoted 8 lines
hw/arm/ftrtc011.h new file +7 -0
+#define ISR_ALARM       BIT(4)
+#define ISR_DAY         BIT(3)
+#define ISR_HOUR        BIT(2)
+#define ISR_MIN         BIT(1)
+#define ISR_SEC         BIT(0)
+
+#endif

--
Best wishes,
Kuo-Jung Su

#17 lore raw

Re: [Qemu-devel] [PATCH v6 08/24] hw/arm: add Faraday FTRTC011 RTC timer support

Il 07/03/2013 07:39, Kuo-Jung Su ha scritto:

Quoted 6 lines

I do have found a web page to qtest at the following link:
http://wiki.qemu.org/Features/QTest

But it's wrong at both 'build/example usage' and 'Additional Details/Status', please see the logs bellow:

Quoted 6 lines
dante@vmware:/pub/qemu$ ./configure --target-list=arm-softmmu
--audio-drv-list="oss alsa sdl" --enable-qtest
ERROR: unknown option --enable-qtest
dante@vmware:/pub/qemu$ ./arm-softmmu/qemu-system-arm -test ?
qemu-system-arm: -test: invalid option

It's much simpler than that. You can look at commit f91837a7f173e0334539024e4d8ba10c19a78bb7 for example.

Paolo

#18 lore raw

Re: [Qemu-devel] [PATCH v6 08/24] hw/arm: add Faraday FTRTC011 RTC timer support

In reply to Kuo-Jung Su
Quoted 9 lines

Excuse me, could you please show me the way how to build the test cases and launch the test case.

I do have found a web page to qtest at the following link:
http://wiki.qemu.org/Features/QTest

But it's wrong at both 'build/example usage' and 'Additional Details/Status', please see the logs bellow:

Quoted 6 lines
dante@vmware:/pub/qemu$ ./configure --target-list=arm-softmmu
--audio-drv-list="oss alsa sdl" --enable-qtest
ERROR: unknown option --enable-qtest
dante@vmware:/pub/qemu$ ./arm-softmmu/qemu-system-arm -test ?
qemu-system-arm: -test: invalid option

From Makefile.target, qtest is built when you build softmmu target.
I guess there is no need to add "--enable-qtest" option. However, I don't know how to run qtest...

Stefan (Cc'ed), I think we should cleanup QTest wiki page, right? ;)

Regards,
chenwj

Signature · 5 lines
Wei-Ren Chen (陳韋任)
Computer Systems Lab, Institute of Information Science,
Academia Sinica, Taiwan (R.O.C.)
Tel:886-2-2788-3799 #1667
Homepage: http://people.cs.nctu.edu.tw/~chenwj
#19 lore raw

Re: [Qemu-devel] [PATCH v6 08/24] hw/arm: add Faraday FTRTC011 RTC timer support

Quoted 4 lines

From Makefile.target, qtest is built when you build softmmu target.
I guess there is no need to add "--enable-qtest" option. However, I don't know how to run qtest...

make check-qtest-arm

Paolo

#20 lore raw

Re: [Qemu-devel] [PATCH v6 08/24] hw/arm: add Faraday FTRTC011 RTC timer support

Quoted 6 lines · Paolo Bonzini
Quoted 4 lines

From Makefile.target, qtest is built when you build softmmu target.
I guess there is no need to add "--enable-qtest" option. However, I don't know how to run qtest...

make check-qtest-arm

O.K., let me try to summarize the working flow..

  $ ../configure --target-list=i386-softmmu
  $ make; make install
  $ make check-qtest-i386
  $ cd tests
  $ export QTEST_QEMU_BINARY=/path/to/qemu-system-i386
  $ ./rtc-test
  /i386/rtc/check-time/bcd: OK
  /i386/rtc/check-time/dec: OK
  /i386/rtc/alarm/interrupt: OK

...

  Developers should add their test into ${QEMU_SRC}/tests . Am I right?

Regards,
chenwj

Signature · 5 lines
Wei-Ren Chen (陳韋任)
Computer Systems Lab, Institute of Information Science,
Academia Sinica, Taiwan (R.O.C.)
Tel:886-2-2788-3799 #1667
Homepage: http://people.cs.nctu.edu.tw/~chenwj
#21 lore raw

Re: [Qemu-devel] [PATCH v6 08/24] hw/arm: add Faraday FTRTC011 RTC timer support

In reply to Paolo Bonzini

2013/3/7 Paolo Bonzini <[email protected]>:

Quoted 8 lines
Quoted 4 lines

From Makefile.target, qtest is built when you build softmmu target.
I guess there is no need to add "--enable-qtest" option. However, I don't know how to run qtest...

make check-qtest-arm

Paolo

Got it, thanks.

Signature · 2 lines
Best wishes,
Kuo-Jung Su
#22 lore raw

PATCH v6 9/24 hw/arm: add Faraday FTDMAC020 AHB DMA support

In reply to Kuo-Jung Su

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      |    1 +
 hw/arm/faraday_a369_soc.c |   14 ++
 hw/arm/ftdmac020.c        |  599 +++++++++++++++++++++++++++++++++++++++++++++
 hw/arm/ftdmac020.h        |  107 ++++++++
 4 files changed, 721 insertions(+)
 create mode 100644 hw/arm/ftdmac020.c
 create mode 100644 hw/arm/ftdmac020.h
hw/arm/Makefile.objs +1 -0
index 6dbac2f..5acdaf9 100644
@@ -43,3 +43,4 @@ obj-y += ftddrii030.o
 obj-y += ftpwmtmr010.o
 obj-y += ftwdt010.o
 obj-y += ftrtc011.o
+obj-y += ftdmac020.o
hw/arm/faraday_a369_soc.c +14 -0
index 4371a3a..9d3e7a1 100644
@@ -199,6 +199,20 @@ a369soc_device_init(FaradaySoCState *s)
                           s->pic[44],    /* Minute (Edge) */
                           s->pic[45],    /* Hour (Edge) */
                           NULL);
+
+    /* 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 int a369soc_init(SysBusDevice *dev)
hw/arm/ftdmac020.c new file +599 -0

599 lines not on this page · raw message

hw/arm/ftdmac020.h new file +107 -0

107 lines not on this page · raw message

Signature · 1 line
1.7.9.5
#23 lore raw

PATCH v6 10/24 hw/arm: add Faraday FTAPBBRG020 APB DMA support

In reply to Kuo-Jung Su

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      |    1 +
 hw/arm/faraday_a369_soc.c |    3 +
 hw/arm/ftapbbrg020.c      |  457 +++++++++++++++++++++++++++++++++++++++++++++
 hw/arm/ftapbbrg020.h      |   44 +++++
 4 files changed, 505 insertions(+)
 create mode 100644 hw/arm/ftapbbrg020.c
 create mode 100644 hw/arm/ftapbbrg020.h
hw/arm/Makefile.objs +1 -0
index 5acdaf9..15aac06 100644
@@ -44,3 +44,4 @@ obj-y += ftpwmtmr010.o
 obj-y += ftwdt010.o
 obj-y += ftrtc011.o
 obj-y += ftdmac020.o
+obj-y += ftapbbrg020.o
hw/arm/faraday_a369_soc.c +3 -0
index 9d3e7a1..8566716 100644
@@ -213,6 +213,9 @@ a369soc_device_init(FaradaySoCState *s)
                                        s->pic[17], /* TC */
                                        s->pic[18], /* ERR */
                                        NULL);
+
+    /* ftapbbrg020 */
+    s->pdma[0] = sysbus_create_simple("ftapbbrg020", 0x90f00000, s->pic[14]);
 }
 
 static int a369soc_init(SysBusDevice *dev)
hw/arm/ftapbbrg020.c new file +457 -0

457 lines not on this page · raw message

hw/arm/ftapbbrg020.h new file +44 -0

44 lines not on this page · raw message

Signature · 1 line
1.7.9.5
#24 lore raw

PATCH v6 11/24 hw/nand.c: correct the sense of the BUSY/READY status bit

In reply to Kuo-Jung Su

The BIT6 of Status Register(SR):

SR[6] behaves the same as R/B# pin
SR[6] = 0 indicates the device is busy;
SR[6] = 1 means the device is ready

Some NAND flash controller (i.e. ftnandc021) relies on the SR[6] to determine if the NAND flash erase/program is success or error timeout.

P.S:
The exmaple NAND flash datasheet could be found at following link:
http://www.mxic.com.tw/QuickPlace/hq/PageLibrary4825740B00298A3B.nsf/h_Index/8FEA549237D2F7674825795800104C26/$File/MX30LF1G08AA,%203V,%201Gb,%20v1.1.pdf

---
 hw/nand.c |    3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
hw/nand.c +2 -1
index 4a71265..61e918f 100644
@@ -46,7 +46,7 @@
 # define NAND_IOSTATUS_PLANE1	(1 << 2)
 # define NAND_IOSTATUS_PLANE2	(1 << 3)
 # define NAND_IOSTATUS_PLANE3	(1 << 4)
-# define NAND_IOSTATUS_BUSY	(1 << 6)
+# define NAND_IOSTATUS_READY    (1 << 6)
 # define NAND_IOSTATUS_UNPROTCT	(1 << 7)
 
 # define MAX_PAGE		0x800
@@ -231,6 +231,7 @@ static void nand_reset(DeviceState *dev)
     s->iolen = 0;
     s->offset = 0;
     s->status &= NAND_IOSTATUS_UNPROTCT;
+    s->status |= NAND_IOSTATUS_READY;
 }
 
 static inline void nand_pushio_byte(NANDFlashState *s, uint8_t value)
Signature · 1 line
1.7.9.5
Reviewed-by on v6 11/24
#25 lore raw

Re: [Qemu-devel] [PATCH v6 11/24] hw/nand.c: correct the sense of the BUSY/READY status bit

Hi Kuo Jung, Peter,

This patch fixes bugs for us in Zynq Nand (cc Wendy Liang). Can we get a cherry pick of this?

Regards,
Peter

Quoted 6 lines · Kuo-Jung Su

The BIT6 of Status Register(SR):

SR[6] behaves the same as R/B# pin
SR[6] = 0 indicates the device is busy;
SR[6] = 1 means the device is ready

Quoted 8 lines

Some NAND flash controller (i.e. ftnandc021) relies on the SR[6] to determine if the NAND flash erase/program is success or error timeout.

P.S:
The exmaple NAND flash datasheet could be found at following link:
http://www.mxic.com.tw/QuickPlace/hq/PageLibrary4825740B00298A3B.nsf/h_Index/8FEA549237D2F7674825795800104C26/$File/MX30LF1G08AA,%203V,%201Gb,%20v1.1.pdf

Quoted 29 lines
---
 hw/nand.c |    3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
hw/nand.c +2 -2
index 4a71265..61e918f 100644
@@ -46,7 +46,7 @@
 # define NAND_IOSTATUS_PLANE1  (1 << 2)
 # define NAND_IOSTATUS_PLANE2  (1 << 3)
 # define NAND_IOSTATUS_PLANE3  (1 << 4)
-# define NAND_IOSTATUS_BUSY    (1 << 6)
+# define NAND_IOSTATUS_READY    (1 << 6)
 # define NAND_IOSTATUS_UNPROTCT        (1 << 7)
 
 # define MAX_PAGE              0x800
@@ -231,6 +231,7 @@ static void nand_reset(DeviceState *dev)
     s->iolen = 0;
     s->offset = 0;
     s->status &= NAND_IOSTATUS_UNPROTCT;
+    s->status |= NAND_IOSTATUS_READY;
 }
 
 static inline void nand_pushio_byte(NANDFlashState *s, uint8_t value)
--

1.7.9.5

#26 lore raw

Re: [Qemu-devel] [PATCH v6 11/24] hw/nand.c: correct the sense of the BUSY/READY status bit

2013/3/7 Peter Crosthwaite <[email protected]>:

Quoted 5 lines

Hi Kuo Jung, Peter,

This patch fixes bugs for us in Zynq Nand (cc Wendy Liang). Can we get a cherry pick of this?

Why not? Please go ahead.

Quoted 45 lines

Regards,
Peter

Quoted 6 lines · Kuo-Jung Su

The BIT6 of Status Register(SR):

SR[6] behaves the same as R/B# pin
SR[6] = 0 indicates the device is busy;
SR[6] = 1 means the device is ready

Quoted 8 lines

Some NAND flash controller (i.e. ftnandc021) relies on the SR[6] to determine if the NAND flash erase/program is success or error timeout.

P.S:
The exmaple NAND flash datasheet could be found at following link:
http://www.mxic.com.tw/QuickPlace/hq/PageLibrary4825740B00298A3B.nsf/h_Index/8FEA549237D2F7674825795800104C26/$File/MX30LF1G08AA,%203V,%201Gb,%20v1.1.pdf

Quoted 24 lines
---
 hw/nand.c |    3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
hw/nand.c +2 -1
index 4a71265..61e918f 100644
@@ -46,7 +46,7 @@
 # define NAND_IOSTATUS_PLANE1  (1 << 2)
 # define NAND_IOSTATUS_PLANE2  (1 << 3)
 # define NAND_IOSTATUS_PLANE3  (1 << 4)
-# define NAND_IOSTATUS_BUSY    (1 << 6)
+# define NAND_IOSTATUS_READY    (1 << 6)
 # define NAND_IOSTATUS_UNPROTCT        (1 << 7)
 
 # define MAX_PAGE              0x800
@@ -231,6 +231,7 @@ static void nand_reset(DeviceState *dev)
     s->iolen = 0;
     s->offset = 0;
     s->status &= NAND_IOSTATUS_UNPROTCT;
+    s->status |= NAND_IOSTATUS_READY;
 }
 
Quoted 5 lines
Quoted 5 lines
hw/nand.c +0 -1
 static inline void nand_pushio_byte(NANDFlashState *s, uint8_t value)
--

1.7.9.5

--
Best wishes,
Kuo-Jung Su

#27 lore raw

Re: [Qemu-devel] [PATCH v6 11/24] hw/nand.c: correct the sense of the BUSY/READY status bit

In reply to Peter Crosthwaite
Quoted 4 lines · Peter Crosthwaite

Hi Kuo Jung, Peter,

This patch fixes bugs for us in Zynq Nand (cc Wendy Liang). Can we get a cherry pick of this?

I've applied this one.

Thanks,
Edgar

Quoted 51 lines

Regards,
Peter

Quoted 6 lines · Kuo-Jung Su

The BIT6 of Status Register(SR):

SR[6] behaves the same as R/B# pin
SR[6] = 0 indicates the device is busy;
SR[6] = 1 means the device is ready

Quoted 8 lines

Some NAND flash controller (i.e. ftnandc021) relies on the SR[6] to determine if the NAND flash erase/program is success or error timeout.

P.S:
The exmaple NAND flash datasheet could be found at following link:
http://www.mxic.com.tw/QuickPlace/hq/PageLibrary4825740B00298A3B.nsf/h_Index/8FEA549237D2F7674825795800104C26/$File/MX30LF1G08AA,%203V,%201Gb,%20v1.1.pdf

Quoted 29 lines
---
 hw/nand.c |    3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
hw/nand.c +2 -2
index 4a71265..61e918f 100644
@@ -46,7 +46,7 @@
 # define NAND_IOSTATUS_PLANE1  (1 << 2)
 # define NAND_IOSTATUS_PLANE2  (1 << 3)
 # define NAND_IOSTATUS_PLANE3  (1 << 4)
-# define NAND_IOSTATUS_BUSY    (1 << 6)
+# define NAND_IOSTATUS_READY    (1 << 6)
 # define NAND_IOSTATUS_UNPROTCT        (1 << 7)
 
 # define MAX_PAGE              0x800
@@ -231,6 +231,7 @@ static void nand_reset(DeviceState *dev)
     s->iolen = 0;
     s->offset = 0;
     s->status &= NAND_IOSTATUS_UNPROTCT;
+    s->status |= NAND_IOSTATUS_READY;
 }
 
 static inline void nand_pushio_byte(NANDFlashState *s, uint8_t value)
--

1.7.9.5

#28 lore raw

PATCH v6 12/24 hw/nand.c: bug fix to erase operation

In reply to Kuo-Jung Su

The s->addr should be reset along with the s->addrlen, or it might have the previous address shifted to MSB and then causes problem to nand erase operation.

---
 hw/nand.c |    1 +
 1 file changed, 1 insertion(+)
hw/nand.c +1 -0
index 61e918f..6b2f2b8 100644
@@ -511,6 +511,7 @@ void nand_setio(DeviceState *dev, uint32_t value)
             nand_command(s);
 
         if (s->cmd != NAND_CMD_RANDOMREAD2) {
+            s->addr = 0;
             s->addrlen = 0;
         }
     }
Signature · 1 line
1.7.9.5
Acked-by on v6 12/24
#29 lore raw

Re: [Qemu-devel] [PATCH v6 12/24] hw/nand.c: bug fix to erase operation

Hi Kuo Jung, Peter,

This fixes a no-boot bug in u-boot for us as well. RE PMMs comments in v5, I realise the desire to fix this properly by rewriting that if-else mess, but can we get a merge on this one more immediately to get QEMU working again? Rewriting this is probably not at the top of either mine or Kuo Jungs priority list but at the same time we would like a working boot.

Regards,
Peter

Quoted 5 lines · Kuo-Jung Su

The s->addr should be reset along with the s->addrlen, or it might have the previous address shifted to MSB and then causes problem to nand erase operation.

Quoted 20 lines
---
 hw/nand.c |    1 +
 1 file changed, 1 insertion(+)
hw/nand.c +1 -1
index 61e918f..6b2f2b8 100644
@@ -511,6 +511,7 @@ void nand_setio(DeviceState *dev, uint32_t value)
             nand_command(s);
 
         if (s->cmd != NAND_CMD_RANDOMREAD2) {
+            s->addr = 0;
             s->addrlen = 0;
         }
     }
--

1.7.9.5

#30 lore raw

Re: [Qemu-devel] [PATCH v6 12/24] hw/nand.c: bug fix to erase operation

Quoted 6 lines · Peter Crosthwaite

This fixes a no-boot bug in u-boot for us as well. RE PMMs comments in v5, I realise the desire to fix this properly by rewriting that if-else mess, but can we get a merge on this one more immediately to get QEMU working again? Rewriting this is probably not at the top of either mine or Kuo Jungs priority list but at the same time we would like a working boot.

The trouble is that the control flow is so complicated that I don't feel comfortable saying "yes, this change doesn't break operation of any of the other commands". That's why I didn't give it a reviewed-by tag. If you can provide a reasonably coherent explanation of why it doesn't break anything else with reference to a decent datasheet, you could convince me it's OK.

-- PMM

#31 lore raw

Re: [Qemu-devel] [PATCH v6 12/24] hw/nand.c: bug fix to erase operation

Hi Peter, Kuo-Jung,

Quoted 11 lines · Peter Maydell
Quoted 6 lines · Peter Crosthwaite

This fixes a no-boot bug in u-boot for us as well. RE PMMs comments in v5, I realise the desire to fix this properly by rewriting that if-else mess, but can we get a merge on this one more immediately to get QEMU working again? Rewriting this is probably not at the top of either mine or Kuo Jungs priority list but at the same time we would like a working boot.

The trouble is that the control flow is so complicated that I don't feel comfortable saying "yes, this change doesn't break operation of any of the other commands".

There may be a complication with NAND_CMD_COPYBACKPRG1, this code may truncate a currently in use address there although I confess I too am confused by the control flow here. Kuo Jungs patch could be more defensive by not trampling the address on this command. But rather than trawl through 100 datasheets looking for all the corner cases RE Nand addressing, Wendy (independently of this discussion) fixed this issue in our tree with a lower impact change. I'll post a full patch to list for review - it may be what you are looking for in that it is a direct approach to solve the issue of the broken BLOCK_ERASE command (which i believe was Kuo Jungs motivation to begin with) without changing the shared address construction logic:

hw/nand.c +1 -0
@@ -296,10 +296,14 @@ static void nand_command(NANDFlashState *s)
         break;
 
     case NAND_CMD_BLOCKERASE2:
+	s->addr &= 0xffffff;
 

Regards,
Peter

That's why I didn't give it a

Quoted 6 lines

reviewed-by tag. If you can provide a reasonably coherent explanation of why it doesn't break anything else with reference to a decent datasheet, you could convince me it's OK.

-- PMM

#32 lore raw

Re: [Qemu-devel] [PATCH v6 12/24] hw/nand.c: bug fix to erase operation

2013/3/7 Peter Crosthwaite <[email protected]>:

Quoted 36 lines

Hi Peter, Kuo-Jung,

Quoted 11 lines · Peter Maydell
Quoted 6 lines · Peter Crosthwaite

This fixes a no-boot bug in u-boot for us as well. RE PMMs comments in v5, I realise the desire to fix this properly by rewriting that if-else mess, but can we get a merge on this one more immediately to get QEMU working again? Rewriting this is probably not at the top of either mine or Kuo Jungs priority list but at the same time we would like a working boot.

The trouble is that the control flow is so complicated that I don't feel comfortable saying "yes, this change doesn't break operation of any of the other commands".

There may be a complication with NAND_CMD_COPYBACKPRG1, this code may truncate a currently in use address there although I confess I too am confused by the control flow here. Kuo Jungs patch could be more defensive by not trampling the address on this command. But rather than trawl through 100 datasheets looking for all the corner cases RE Nand addressing, Wendy (independently of this discussion) fixed this issue in our tree with a lower impact change. I'll post a full patch to list for review - it may be what you are looking for in that it is a direct approach to solve the issue of the broken BLOCK_ERASE command (which i believe was Kuo Jungs motivation to begin with) without changing the shared address construction logic:

hw/nand.c +1 -0
@@ -296,10 +296,14 @@ static void nand_command(NANDFlashState *s)
         break;
 
     case NAND_CMD_BLOCKERASE2:
+       s->addr &= 0xffffff;
 
 Regards,
Quoted 2 lines

Peter

I've verified that it works to me, too. So it's should be a replacement of my buggy one.

Quoted 7 lines

That's why I didn't give it a

Quoted 6 lines

reviewed-by tag. If you can provide a reasonably coherent explanation of why it doesn't break anything else with reference to a decent datasheet, you could convince me it's OK.

-- PMM

--
Best wishes,
Kuo-Jung Su

#33 lore raw

Re: [Qemu-devel] [PATCH v6 12/24] hw/nand.c: bug fix to erase operation

In reply to Peter Maydell

2013/3/7 Peter Maydell <[email protected]>:

Quoted 8 lines · Peter Crosthwaite
Quoted 6 lines

This fixes a no-boot bug in u-boot for us as well. RE PMMs comments in v5, I realise the desire to fix this properly by rewriting that if-else mess, but can we get a merge on this one more immediately to get QEMU working again? Rewriting this is probably not at the top of either mine or Kuo Jungs priority list but at the same time we would like a working boot.

Quoted 8 lines

The trouble is that the control flow is so complicated that I don't feel comfortable saying "yes, this change doesn't break operation of any of the other commands". That's why I didn't give it a reviewed-by tag. If you can provide a reasonably coherent explanation of why it doesn't break anything else with reference to a decent datasheet, you could convince me it's OK.

-- PMM

I've checked the history of hw/nand.c, it might be bug-free before the patch 'hw/nand: Support large NAND devices' being applied.
Because it modifies the data type of addr from uint32_t into uint64_t, and combined with
the problematic address clear (clear only address length), which then leads to a bug of this.

BTW, if you're looking for the datasheet on which the nand.c based, please refer to the link bellow:

http://www.datasheetcatalog.org/datasheet/SamsungElectronic/mXvvrxx.pdf

P.S:
The u-boot / linux suffers this bug because of the BBT, which stands for Bad Block Table.
In other words, the u-boot / linux usually starts with a bunch of bad block scan on block boundary (i.e. 64KB, 128KB).
While the addr is a uint32_t, right-shift 24 bits would always clear address long enough for the incoming new address, but things would go mad, if it's a uint64_t.

--
Best wishes,
Kuo-Jung Su

#34 lore raw

PATCH v6 13/24 hw/arm: add Faraday FTNANDC021 nand flash controller support

In reply to Kuo-Jung Su

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      |    1 +
 hw/arm/faraday_a369_soc.c |    8 +
 hw/arm/ftnandc021.c       |  512 +++++++++++++++++++++++++++++++++++++++++++++
 hw/arm/ftnandc021.h       |   84 ++++++++
 4 files changed, 605 insertions(+)
 create mode 100644 hw/arm/ftnandc021.c
 create mode 100644 hw/arm/ftnandc021.h
hw/arm/Makefile.objs +1 -0
index 15aac06..1ae6d0e 100644
@@ -45,3 +45,4 @@ obj-y += ftwdt010.o
 obj-y += ftrtc011.o
 obj-y += ftdmac020.o
 obj-y += ftapbbrg020.o
+obj-y += ftnandc021.o
hw/arm/faraday_a369_soc.c +8 -0
index 8566716..f08fe85 100644
@@ -92,6 +92,7 @@ a369soc_device_init(FaradaySoCState *s)
     DriveInfo *dinfo;
     DeviceState *ds;
     qemu_irq *cpu_pic;
+    qemu_irq ack, req;
     int i;
 
     s->as = get_system_memory();
@@ -216,6 +217,13 @@ a369soc_device_init(FaradaySoCState *s)
 
     /* ftapbbrg020 */
     s->pdma[0] = sysbus_create_simple("ftapbbrg020", 0x90f00000, s->pic[14]);
+
+    /* ftnandc021 */
+    ds = sysbus_create_simple("ftnandc021", 0x90200000, s->pic[30]);
+    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 int a369soc_init(SysBusDevice *dev)
hw/arm/ftnandc021.c new file +512 -0

512 lines not on this page · raw message

hw/arm/ftnandc021.h new file +84 -0

84 lines not on this page · raw message

Signature · 1 line
1.7.9.5
#35 lore raw

PATCH v6 14/24 hw/arm: add Faraday FTI2C010 I2C controller support

In reply to Kuo-Jung Su

The FTI2C010 is a simple I2C master controller.

---
 hw/arm/Makefile.objs      |    1 +
 hw/arm/faraday_a369_soc.c |    6 ++
 hw/arm/fti2c010.c         |  216 +++++++++++++++++++++++++++++++++++++++++++++
 hw/arm/fti2c010.h         |   71 +++++++++++++++
 4 files changed, 294 insertions(+)
 create mode 100644 hw/arm/fti2c010.c
 create mode 100644 hw/arm/fti2c010.h
hw/arm/Makefile.objs +1 -0
index 1ae6d0e..767a5e1 100644
@@ -46,3 +46,4 @@ obj-y += ftrtc011.o
 obj-y += ftdmac020.o
 obj-y += ftapbbrg020.o
 obj-y += ftnandc021.o
+obj-y += fti2c010.o
hw/arm/faraday_a369_soc.c +6 -0
index f08fe85..ef191d0 100644
@@ -224,6 +224,12 @@ a369soc_device_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 int a369soc_init(SysBusDevice *dev)
hw/arm/fti2c010.c new file +216 -0

216 lines not on this page · raw message

hw/arm/fti2c010.h new file +71 -0

71 lines not on this page · raw message

Signature · 1 line
1.7.9.5
#36 lore raw

PATCH v6 15/24 hw: add WM8731 codec support

In reply to Kuo-Jung Su

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/i2c.h                        |    6 +
 hw/wm8731.c                     |  499 +++++++++++++++++++++++++++++++++++++++
 4 files changed, 507 insertions(+)
 create mode 100644 hw/wm8731.c
default-configs/arm-softmmu.mak +1 -0
index 68b2045..131f85b 100644
@@ -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
index 40ebe46..33c128d 100644
@@ -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-$(CONFIG_WM8731) += wm8731.o
 common-obj-$(CONFIG_WM8750) += wm8750.o
 common-obj-$(CONFIG_TWL92230) += twl92230.o
 common-obj-$(CONFIG_TSC2005) += tsc2005.o
hw/i2c.h +6 -0
index 0e80d5a..f03edc5 100644
@@ -63,6 +63,12 @@ int i2c_recv(i2c_bus *bus);
 
 DeviceState *i2c_create_slave(i2c_bus *bus, const char *name, uint8_t addr);
 
+/* wm8731.c */
+void wm8731_data_req_set(DeviceState *dev,
+                void (*data_req)(void *, int, int), void *opaque);
+void wm8731_dac_dat(void *opaque, uint32_t sample);
+uint32_t wm8731_adc_dat(void *opaque);
+
 /* wm8750.c */
 void wm8750_data_req_set(DeviceState *dev,
                 void (*data_req)(void *, int, int), void *opaque);
hw/wm8731.c new file +499 -0

499 lines not on this page · raw message

Signature · 1 line
1.7.9.5
#37 lore raw

PATCH v6 16/24 hw/arm: add Faraday FTSSP010 multi-function controller support

In reply to Kuo-Jung Su

The FTSSP010 is a multi-function synchronous serial port interface controller which supports SSP, SPI, I2S, AC97 and SPDIF.

Only I2S and SPI protocol have been implemented in this patch.

---
 hw/arm/Makefile.objs      |    1 +
 hw/arm/faraday.h          |    3 +
 hw/arm/faraday_a369.c     |   22 ++
 hw/arm/faraday_a369_soc.c |   17 ++
 hw/arm/ftssp010.c         |  492 +++++++++++++++++++++++++++++++++++++++++++++
 hw/arm/ftssp010.h         |   98 +++++++++
 6 files changed, 633 insertions(+)
 create mode 100644 hw/arm/ftssp010.c
 create mode 100644 hw/arm/ftssp010.h
hw/arm/Makefile.objs +1 -0
index 767a5e1..575c563 100644
@@ -47,3 +47,4 @@ obj-y += ftdmac020.o
 obj-y += ftapbbrg020.o
 obj-y += ftnandc021.o
 obj-y += fti2c010.o
+obj-y += ftssp010.o
hw/arm/faraday.h +3 -0
index d1a3e0f..3c11ff7 100644
@@ -61,4 +61,7 @@ typedef struct FaradaySoCState {
     FARADAY_SOC(object_resolve_path_component(qdev_get_machine(), \
                                               TYPE_FARADAY_SOC))
 
+/* ftssp010.c */
+void ftssp010_i2s_data_req(void *opaque, int tx, int rx);
+
 #endif
hw/arm/faraday_a369.c +22 -0
index 8f8ea4f..2172451 100644
@@ -23,6 +23,7 @@
 static void
 a369_board_init(QEMUMachineInitArgs *args)
 {
+    int i, nr_flash;
     DeviceState *ds;
     FaradaySoCState *s;
 
@@ -46,6 +47,27 @@ a369_board_init(QEMUMachineInitArgs *args)
 
     s = FARADAY_SOC(ds);
 
+    /* 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");
+        s->codec = i2c_create_slave(i2c, "wm8731", 0x1B);
+        s->codec_out = wm8731_dac_dat;
+        s->codec_in  = wm8731_adc_dat;
+        wm8731_data_req_set(s->codec, ftssp010_i2s_data_req, s->i2s[0]);
+    }
+
     /* System start-up */
 
     if (args->kernel_filename) {
hw/arm/faraday_a369_soc.c +17 -0
index ef191d0..9860630 100644
@@ -230,6 +230,23 @@ a369soc_device_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 int a369soc_init(SysBusDevice *dev)
hw/arm/ftssp010.c new file +492 -0

492 lines not on this page · raw message

hw/arm/ftssp010.h new file +98 -0

98 lines not on this page · raw message

Signature · 1 line
1.7.9.5
#38 lore raw

PATCH v6 17/24 qemu/bitops.h: add the bit ordering reversal functions stolen from linux

In reply to Kuo-Jung Su
---
 include/qemu/bitops.h |   63 ++++++++++++++++++++++++++++++++++++++++++++++++-
 1 file changed, 62 insertions(+), 1 deletion(-)
include/qemu/bitops.h +62 -1
index affcc96..920d028 100644
@@ -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,64 @@ 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)
+{
+    int i;
+    uint8_t ret = 0;
+    for (i = 0; i < 8; ++i) {
+        if (value & BIT(i)) {
+            ret |= BIT(7 - i);
+        }
+    }
+    return ret;
+}
+
+/**
+ * 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
#39 lore raw

Re: [Qemu-devel] [PATCH v6 17/24] qemu/bitops.h: add the bit ordering reversal functions stolen from linux

Il 06/03/2013 08:27, Kuo-Jung Su ha scritto:

Quoted 30 lines
---
 include/qemu/bitops.h |   63 ++++++++++++++++++++++++++++++++++++++++++++++++-
 1 file changed, 62 insertions(+), 1 deletion(-)
include/qemu/bitops.h +9 -1
index affcc96..920d028 100644
@@ -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,64 @@ 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

include/qemu/bitops.h static inline uint64_t deposit64(uint64_t value, int start, int length, · line 293

Quoted 10 lines
include/qemu/bitops.h +10 -0
+ */
+static inline uint8_t bitrev8(uint8_t value)
+{
+    int i;
+    uint8_t ret = 0;
+    for (i = 0; i < 8; ++i) {
+        if (value & BIT(i)) {
+            ret |= BIT(7 - i);
+        }
+    }

Please use instead

   value = ((value & 0xAA) >> 1) | ((value & 0x55) << 1);
   value = ((value & 0xCC) >> 2) | ((value & 0x33) << 2);
   value = ((value & 0xF0) >> 4) | ((value & 0x0F) << 4);

return value;

Paolo

Quoted 45 lines
include/qemu/bitops.h +43 -0
+    return ret;
+}
+
+/**
+ * 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
#40 lore raw

Re: [Qemu-devel] [PATCH v6 17/24] qemu/bitops.h: add the bit ordering reversal functions stolen from linux

2013/3/6 Paolo Bonzini <[email protected]>:

Quoted 44 lines

Il 06/03/2013 08:27, Kuo-Jung Su ha scritto:

Quoted 30 lines
---
 include/qemu/bitops.h |   63 ++++++++++++++++++++++++++++++++++++++++++++++++-
 1 file changed, 62 insertions(+), 1 deletion(-)
include/qemu/bitops.h +9 -1
index affcc96..920d028 100644
@@ -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,64 @@ 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

include/qemu/bitops.h static inline uint64_t deposit64(uint64_t value, int start, int length, · line 293

Quoted 10 lines
include/qemu/bitops.h +10 -0
+ */
+static inline uint8_t bitrev8(uint8_t value)
+{
+    int i;
+    uint8_t ret = 0;
+    for (i = 0; i < 8; ++i) {
+        if (value & BIT(i)) {
+            ret |= BIT(7 - i);
+        }
+    }

Please use instead

Quoted 7 lines
   value = ((value & 0xAA) >> 1) | ((value & 0x55) << 1);
   value = ((value & 0xCC) >> 2) | ((value & 0x33) << 2);
   value = ((value & 0xF0) >> 4) | ((value & 0x0F) << 4);

return value;

Paolo

Got it, thanks

Quoted 46 lines
Quoted 45 lines
include/qemu/bitops.h +43 -0
+    return ret;
+}
+
+/**
+ * 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 · 2 lines
Best wishes,
Kuo-Jung Su
#41 lore raw

PATCH v6 18/24 hw/arm: add Faraday FTGMAC100 1Gbps ethernet support

In reply to Kuo-Jung Su

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      |    1 +
 hw/arm/faraday.h          |    3 +
 hw/arm/faraday_a369_soc.c |    5 +
 hw/arm/ftgmac100.c        |  696 +++++++++++++++++++++++++++++++++++++++++++++
 hw/arm/ftgmac100.h        |  239 ++++++++++++++++
 5 files changed, 944 insertions(+)
 create mode 100644 hw/arm/ftgmac100.c
 create mode 100644 hw/arm/ftgmac100.h
hw/arm/Makefile.objs +1 -0
index 575c563..f13ab77 100644
@@ -48,3 +48,4 @@ obj-y += ftapbbrg020.o
 obj-y += ftnandc021.o
 obj-y += fti2c010.o
 obj-y += ftssp010.o
+obj-y += ftgmac100.o
hw/arm/faraday.h +3 -0
index 3c11ff7..f8e2a64 100644
@@ -64,4 +64,7 @@ typedef struct FaradaySoCState {
 /* 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/arm/faraday_a369_soc.c +5 -0
index 9860630..62837ca 100644
@@ -247,6 +247,11 @@ a369soc_device_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 int a369soc_init(SysBusDevice *dev)
hw/arm/ftgmac100.c new file +696 -0

696 lines not on this page · raw message

hw/arm/ftgmac100.h new file +239 -0

239 lines not on this page · raw message

Signature · 1 line
1.7.9.5
#42 lore raw

PATCH v6 19/24 hw/arm: add Faraday FTLCDC200 LCD controller support

In reply to Kuo-Jung Su

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        |    1 +
 hw/arm/faraday_a369_soc.c   |   10 +
 hw/arm/ftlcdc200.c          |  513 +++++++++++++++++++++++++++++++++++++++++++
 hw/arm/ftlcdc200.h          |  112 ++++++++++
 hw/arm/ftlcdc200_template.h |  439 ++++++++++++++++++++++++++++++++++++
 5 files changed, 1075 insertions(+)
 create mode 100644 hw/arm/ftlcdc200.c
 create mode 100644 hw/arm/ftlcdc200.h
 create mode 100644 hw/arm/ftlcdc200_template.h
hw/arm/Makefile.objs +1 -0
index f13ab77..5d5e36c 100644
@@ -49,3 +49,4 @@ obj-y += ftnandc021.o
 obj-y += fti2c010.o
 obj-y += ftssp010.o
 obj-y += ftgmac100.o
+obj-y += ftlcdc200.o
hw/arm/faraday_a369_soc.c +10 -0
index 62837ca..2b2f31d 100644
@@ -252,6 +252,16 @@ a369soc_device_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 int a369soc_init(SysBusDevice *dev)
hw/arm/ftlcdc200.c new file +513 -0

513 lines not on this page · raw message

hw/arm/ftlcdc200.h new file +112 -0

112 lines not on this page · raw message

hw/arm/ftlcdc200_template.h new file +439 -0

439 lines not on this page · raw message

Signature · 1 line
1.7.9.5
#43 lore raw

PATCH v6 20/24 hw/arm: add Faraday FTTSC010 touchscreen controller support

In reply to Kuo-Jung Su

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      |    1 +
 hw/arm/faraday_a369_soc.c |    3 +
 hw/arm/fttsc010.c         |  264 +++++++++++++++++++++++++++++++++++++++++++++
 hw/arm/fttsc010.h         |   39 +++++++
 4 files changed, 307 insertions(+)
 create mode 100644 hw/arm/fttsc010.c
 create mode 100644 hw/arm/fttsc010.h
hw/arm/Makefile.objs +1 -0
index 5d5e36c..8c12beb 100644
@@ -50,3 +50,4 @@ obj-y += fti2c010.o
 obj-y += ftssp010.o
 obj-y += ftgmac100.o
 obj-y += ftlcdc200.o
+obj-y += fttsc010.o
hw/arm/faraday_a369_soc.c +3 -0
index 2b2f31d..0265f4e 100644
@@ -262,6 +262,9 @@ a369soc_device_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 int a369soc_init(SysBusDevice *dev)
hw/arm/fttsc010.c new file +264 -0

264 lines not on this page · raw message

hw/arm/fttsc010.h new file +39 -0
new file mode 100644
index 0000000..b600645
@@ -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
#44 lore raw

PATCH v6 21/24 hw/arm: add Faraday FTSDC010 MMC/SD controller support

In reply to Kuo-Jung Su

The FTSDC010 is a simple MMC/SD host controller and many of its registers are similar to Arm PrimeCell PL181.

---
 hw/arm/Makefile.objs      |    1 +
 hw/arm/faraday_a369_soc.c |    7 +
 hw/arm/ftsdc010.c         |  358 +++++++++++++++++++++++++++++++++++++++++++++
 hw/arm/ftsdc010.h         |   90 ++++++++++++
 4 files changed, 456 insertions(+)
 create mode 100644 hw/arm/ftsdc010.c
 create mode 100644 hw/arm/ftsdc010.h
hw/arm/Makefile.objs +1 -0
index 8c12beb..5cef17b 100644
@@ -51,3 +51,4 @@ obj-y += ftssp010.o
 obj-y += ftgmac100.o
 obj-y += ftlcdc200.o
 obj-y += fttsc010.o
+obj-y += ftsdc010.o
hw/arm/faraday_a369_soc.c +7 -0
index 0265f4e..581af4d 100644
@@ -265,6 +265,13 @@ a369soc_device_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 int a369soc_init(SysBusDevice *dev)
hw/arm/ftsdc010.c new file +358 -0

358 lines not on this page · raw message

hw/arm/ftsdc010.h new file +90 -0

90 lines not on this page · raw message

Signature · 1 line
1.7.9.5
#45 lore raw

PATCH v6 22/24 hw/arm: add Faraday FTMAC110 10/100Mbps ethernet support

In reply to Kuo-Jung Su

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  |    1 +
 hw/arm/faraday.h      |    3 +
 hw/arm/faraday_a369.c |    7 +
 hw/arm/ftmac110.c     |  649 +++++++++++++++++++++++++++++++++++++++++++++++++
 hw/arm/ftmac110.h     |  168 +++++++++++++
 5 files changed, 828 insertions(+)
 create mode 100644 hw/arm/ftmac110.c
 create mode 100644 hw/arm/ftmac110.h
hw/arm/Makefile.objs +1 -0
index 5cef17b..2560b3c 100644
@@ -52,3 +52,4 @@ obj-y += ftgmac100.o
 obj-y += ftlcdc200.o
 obj-y += fttsc010.o
 obj-y += ftsdc010.o
+obj-y += ftmac110.o
hw/arm/faraday.h +3 -0
index f8e2a64..77eaad6 100644
@@ -67,4 +67,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/arm/faraday_a369.c +7 -0
index 2172451..71e4233 100644
@@ -68,6 +68,13 @@ a369_board_init(QEMUMachineInitArgs *args)
         wm8731_data_req_set(s->codec, ftssp010_i2s_data_req, 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/arm/ftmac110.c new file +649 -0

649 lines not on this page · raw message

hw/arm/ftmac110.h new file +168 -0

168 lines not on this page · raw message

Signature · 1 line
1.7.9.5
#46 lore raw

PATCH v6 23/24 hw/arm: add Faraday FTTMR010 timer support

In reply to Kuo-Jung Su

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  |    1 +
 hw/arm/faraday_a369.c |    8 +
 hw/arm/fttmr010.c     |  451 +++++++++++++++++++++++++++++++++++++++++++++++++
 hw/arm/fttmr010.h     |   41 +++++
 4 files changed, 501 insertions(+)
 create mode 100644 hw/arm/fttmr010.c
 create mode 100644 hw/arm/fttmr010.h
hw/arm/Makefile.objs +1 -0
index 2560b3c..1cbb58f 100644
@@ -53,3 +53,4 @@ obj-y += ftlcdc200.o
 obj-y += fttsc010.o
 obj-y += ftsdc010.o
 obj-y += ftmac110.o
+obj-y += fttmr010.o
hw/arm/faraday_a369.c +8 -0
index 71e4233..0e75b02 100644
@@ -75,6 +75,14 @@ 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/arm/fttmr010.c new file +451 -0

451 lines not on this page · raw message

hw/arm/fttmr010.h new file +41 -0

41 lines not on this page · raw message

Signature · 1 line
1.7.9.5
#47 lore raw

PATCH v6 24/24 hw/arm: add Faraday FTSPI020 SPI flash controller support

In reply to Kuo-Jung Su

The FTSPI020 is an integrated SPI Flash controller which supports up to 4 flash chips.

---
 hw/arm/Makefile.objs  |    1 +
 hw/arm/faraday_a369.c |   16 +++
 hw/arm/ftspi020.c     |  340 +++++++++++++++++++++++++++++++++++++++++++++++++
 hw/arm/ftspi020.h     |   81 ++++++++++++
 4 files changed, 438 insertions(+)
 create mode 100644 hw/arm/ftspi020.c
 create mode 100644 hw/arm/ftspi020.h
hw/arm/Makefile.objs +1 -0
index 1cbb58f..9bb3076 100644
@@ -54,3 +54,4 @@ obj-y += fttsc010.o
 obj-y += ftsdc010.o
 obj-y += ftmac110.o
 obj-y += fttmr010.o
+obj-y += ftspi020.o
hw/arm/faraday_a369.c +16 -0
index 0e75b02..5d66b31 100644
@@ -83,6 +83,22 @@ 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/arm/ftspi020.c new file +340 -0

340 lines not on this page · raw message

hw/arm/ftspi020.h new file +81 -0

81 lines not on this page · raw message

Signature · 1 line
1.7.9.5