Skip to contentSkip to conversation

hw/arm: add Faraday A369 SoC platform support

PATCH Superseded Kuo-Jung Su 3 participants 15 messages Mar 15, 2013 – Mar 19, 2013

v8 of 9 Superseded Latest is v9 →

lore
Share & tools
lore
#0 lore raw

v8 cover hw/arm: add Faraday A369 SoC platform support

From: Kuo-Jung Su <[email protected]>

These patches introduce Faraday A369 SoC platform support.

Here are some public documents for your reference.

http://www.faraday-tech.com/html/documentation/index.html

The partial version of faraday cpu datasheet with only the CP15 and MPU description are available at my Google Drive:

https://docs.google.com/folder/d/0BwfiewvSmUgAalh5TkxyZWtlWEE/edit?usp=sharing

The pre-built A369 images are also available at my Google Drive:

https://docs.google.com/folder/d/0BwfiewvSmUgAX2pTTmtUMGFCZW8/edit

Here is the image file list:

1. android-4.0.4/zImage: A369 linux-3.0.31
2. android-4.0.4/romfs-4.0.4.tar.bz2: android-4.0.4
3. nand.img.bz2: A369 nand flash image
4. rom.img.bz2: A369 embedded ROM image
5. u-boot: A369 u-boot-2012.10 ELF file
6. zImage: A369 linux-3.4.12 + initramfs
7. README

If you want to re-build the image from scratch, try my Faraday Linux BSP/SDK: falinux.

1. Download the falinux

   $ git clone https://github.com/dantesu1218/falinux.git

2. Download all the required software packages:

   $ cd falinux
   $ make setup

3. Launch the menuconfig of falinux, and enable 'QEMU Support'

   $ make menuconfig

4. Re-build the packages

   $ make

5. Laungh the qemu-1.3.0 with the generated falinux images.

   $ make qemu

Changes for v7 -> v8:
1. [hw/arm/ftintc020.c] (Addressed by Peter)
'uint32_t mask = BIT(irq % 32);' -> 'uint32_t mask = BIT(irq & 0x1f);'
2. [hw/arm/*.c] (Addressed by Peter)
Drop '#include "faraday.h"', and define DPRINTF() at per-file basis exit(1) -> abort()
SysBusDeviceClass::init() -> Device::realize()

Changes for v6 -> v7:

1. hw/arm/ftwdt010: (Addressed by Paolo)
Replace 'qemu_system_reset_request()' with 'watchdog_perform_action()'.
2. hw/arm/ftrtc011: (Addressed by Paolo)
Replace 'get_clock_realtime()' with 'qemu_get_clock_ns(rtc_clock)'. Replace 'qemu_new_timer_ms(rt_clock...)' with 'qemu_new_timer_ms(rtc_clock...)' Rename 'ftrtc011_timer_resync' -> 'ftrtc011_timer_rebase'
Add ftrtc011_timer_resche()
Add QTest support
3. hw/arm/faraday_a369_soc: (Addressed by Paolo)
Remove redundant device reset from a369soc_system_reset(...)
4. include/qemu/bitops.h: (Addressed by Paolo)
Update bitrev8() to use a kind of divide and conquer algorithm.
5. hw/arm/ftahb020,ftddrii030,ftapbbrg020,faraday_a369_soc:
Drop FARADAY_SOC_GET_CORE(), replaced with device to device QOM link.
6. hw/wm8731,wm8750,marvell_88w8618_audio,spitz,z2:
Add AudioCodecClass for wm87xx audio class abstration.
7. hw/arm/ftnandc021:
Drop nand_init(), replaced with device to device QOM link.
8. hw/arm/ftsdc010:
Bug fixed to write operation: remove sd_data_ready() in write path.
9. hw/arm/ftgmac100,ftmac110,ftwdt010:
rt-clock -> vm_clock
10. hw/nand.c:
Drop [hw/nand.c: correct the sense of the BUSY/READY], since it's already applied. Drop [hw/nand.c: bug fix to erase operation], since Peter has a better solution.

Changes for v5 -> v6:

1. hw/arm/Makefile.objs:
Shift to the next line only after current line length is > 80 characters.
2. hw/arm/faraday.h:
Update debug macro format per discussions at the link bellow:
http://thread.gmane.org/gmane.comp.emulators.qemu/195996/focus=196975
3. hw/arm/faraday.h:

       TYPE_FARADAY_SOC: 'faraday/soc' -> 'faraday.soc'
   4. hw/arm/*.c:
       Replace '%llx' with '%HWADDR_PRIx'
   5. hw/arm/*.h:
       Add '#include "qemu/bitops.h"'
   6. hw/arm/faraday_a369_soc.c:
       Typo fix: salve4 -> slave4, salve6 -> slave6
   7. hw/arm/*.c:
       Drop FROM_SYSBUS().
   8. hw/arm/ftintc020.c:
       Re-write the source file with pl190.c as template.
   9. hw/arm/ftintc020.h:
       Rename the registers to improve readibility.
   10. hw/arm/faraday.h:
       Add dedicated spi flash pointer array (DeviceState *spi_fl[2]).
   11. hw/arm/faraday.h:
       Add 'qemu_irq pic[64]'.
   12. hw/arm/*c:
       Replace the complex conversion in XXX_REG32() with directly array indexing.
   13. hw/arm/*c:
       Update the error message output from 'hw_error(...)' into 'fprintf(stderr, ...)'
   14. hw/arm/faraday_a369.c, hw/arm/faraday_a369_soc.c:
       Move the external AHB device init from faraday_a369_soc.c to faraday_a369.c
   15. include/qemu/bitops.h:
       Move bitrev() from bitrev.[ch] into bitops.h
   16. hw/nand.c:
       Remove the clear/set SR[6] code in read/erase/write, because
       it's not possible to be observed by a guest.
   17. hw/arm/faraday_a369_kpd.c:
       Function prefix: 'ftkbc010' -> 'a369kpd' 
       Name of struct:  'FTKBC010State' -> 'A369KPDState'.
       QOM: 'FTKBC010' -> 'A369KPD'
   18. hw/arm/ftddrii030.c:
       'case REG_MCR ... 0x4c' -> 'case REG_MCR ... (CFG_REGSIZE - 1) * 4'

19. hw/arm/ftahbc020.c:
Add comments to fall-through path. (i.e. /* fall-through - skip slave6 */)
20. hw/arm/faraday_a369.c:
Update spi flash init code to use the new QOM classes of m25p80.

Changes for v3 -> v5:

1. [cpu] Add the unapplied patches for faraday ARMv5TE cores.
2. [nand] Add the unapplied patches for hw/nand.c.
3. [audio] Add the unapplied patches for wm8731.
4. [Global] Replace redundant statement in xxx_update_irq() with

            qemu_set_irq(s->irq, !!(xxxx));
   5. [Global] Introduce 'case xxx ... xxx' statement in switch { }
            to replace the 'if {} else {}' statement.
   6. [Global] Replace complex bitwise operation with functions defined in bitops.h
   7. [Global] Introduce array register caches (i.e. s->regs[]) implementation
            to fttsc010, ftrtc011, ftmac110, ftgmac100, ftddrii030
            faraday_a369_kpd and faraday_a369_soc.
   8. [Global] Add qemu_log_mask(LOG_GUEST_ERROR...) on undefined memory accesses.
   9. [Global] Add missing register access size constraint to
            faraday_a369_kpd, faraday_a369_soc, ftahbc020.c, ftddrii030.c,
            ftintc020.c, ftlcdc200.c, ftpwmtmr010.c, ftspi020.c, fttmr010.c
            and fttsc010.c.

10. [Global] Add more register and bitmask descriptions to all the chips.
11. [Global] Rename all the MemoryRegionOps variables to 'mmio_ops'
12. [Global] Update all non-system header includes from '<>' into '""'
13. [bitrev] Port bitrev.[ch] from linux kernel into QEMU.
14. [ftapbbrg020] Replace cpu_physical_memory_read()/cpu_physical_memory_write() with dma_memory_read()/dma_memory_write()
15. [ftdmac020] Replace cpu_physical_memory_read()/cpu_physical_memory_write() with dma_memory_read()/dma_memory_write()
16. [ftgmac100/ftmac110] Replace cpu_physical_memory_read()/cpu_physical_memory_write() with dma_memory_read()/dma_memory_write()
17. [ftgmac100/ftmac110] Add a 10ms timer for polling the owner bit of descriptors to call qemu_flush_queued_packets() when it's necessary.
18. [ftgmac100/ftmac110] Replace hw_error() with qemu_log_mask(LOG_GUEST_ERROR, ) for programmer errors.
19. [ftgmac100/ftmac110] Update descriptor struct for big endian QEMU host support.
20. [ftgmac100/ftmac110] Typo fix ('FTMAC_H' --> 'HW_ARM_FTMAC110_H') to the header files.
21. [ftmac110] Update mdio phy response emulation from Marvell into Davicom PHY.
22. [ftwdt010/fttsc010] Switch to a slower timer. (i.e. rt_clock)

23. [faraday_a360] Removed. The ftmac110 and fttmr010 has been moved to
A369 as external AHB devices.
24. [faraday_a369] Add register caches for AHB/APB slave devices.
25. [faraday_a369] Remember (arm_boot_info *) when launching in direct boot mode.
26. [faraday_a369] Replace pointer to (mach *) with QOM APIs. (i.e. no more DEFINE_PROP_PTR())
27. [faraday_a369] Add a error message for ROM mode when it failed to load image.
28. [faraday_a369] Add the missing AHB remap process into direct boot mode.
29. [faraday_a369] Bug fix to ROM and RAM memory overlap issue.
30. [faraday_a369] Remove system reset order dependency from ftddrii030 and ftahbc020
31. [faraday_a369] Separate the a369 platform implementation into 2 different parts:

              board=faraday_a369.c, and soc=faraday_a369_soc.c

32. [faraday_a369] Copy all the un-used register values from read hardware into QEMU model.
33. [ftssp010] Add address alignment checker.
34. [ftssp010] Move the audio codec initialization code to faraday_a369.c.
35. [ftspi020] Use a constant (CFG_NR_CSLINES) for the number of cs lines.
36. [ftspi020] Replace 's->datacnt <= 0' with '!s->datacnt', because s->datacnt is unsigned.
37. [ftspi020] Replace 's->datacnt' with 's->cmd[2]'
38. [ftspi020] Remove redundant M25P80s command opcodes from the header file.
39. [ftspi020] Replace 'g_new' with 'g_new0' for cs_lines allocation.
This fix the bug which crash the QEMU when de-activating an unattached spi flash chip select. Thanks to Peter.

Changes for v3:

1. [global] review all commit log make sure it correctly describe the QEMU model.
2. [global] reformat the entire patch series to be compilable on its own. Thanks to Andreas and Igor.
3. [global] move all files from 'hw' into 'hw/arm', and rename a36x.c to faraday_a36x.c
4. [global] update lisence to GPLv2+
5. [global] rename both struct and typedef names to CamelCase.
6. [global] turn printfs into DPRINTF() which is controlled by 'DEBUG_FARADAY'
7. [global] remove disabled code.
8. [global] add header files with descriptive defines to

               ftintc020, ftrtc011, fttmr010 ... etc.
   9. [global] update all header file to have a 'HW_ARM_' prefix 
               to header guards.
  10. [faraday.h] add parameter names to ftmac110_init() and
                  ftgmac100_init()

11. [a360/a369] remove printf("xxx %dMB ram.\n"...);
12. [a360/a369] add 'arm926' as a fail-safe cpu model.
13. [a360/a369] add DEFAULT_MACHINE_OPTIONS.
14. [a360/a369] remove USB-EHCI support, it's now a standalone patch.
15. [a360] replace ftlcdc200 init from sysbus_create_varargs() to sysbus_create_simple().
16. [a360] make PMU a standalone file. (faraday_a360_pmu.c)
17. [a369] make SCU a standalone file. (faraday_a369_pcu.c)
18. [a369] make AHBC a standalone file. (ftahbc020.c)
19. [a369] make DDRC a standalone file. (ftddrii030.c)
20. [a369] rename ftkbc010 to faraday_a369_keypad.c
21. [a369] replace ROM emulation with PFLASH.(rom.c is deleted)
22. [ftsdc010] add sd_data_ready() to data R/W.
23. [ftsdc010] check 'datacnt' at each read/write to make sure buffer would not overflow/underflow and also prevent 'datacnt' from underflow by subtracted by a 4.
24. [ftgmac100] add 802.1Q VLAN tag insertion/removal support.
25. [ftgmac100] replace the dumb timer code with bottom half.
26. [ftgmac100] rename the struct name of descriptors to CamelCase.
27. [ftgmac100] replace 'void *' with 'Ftgmac100RXD *' and 'Ftgmac100TXD *' for descriptor read/write.
28. [ftgmac100] add buffer overflow check in ftgmac100_transmit()
29. [ftgmac100] add buffer alignment check
30. [ftmac110] replace the dumb timer code with bottom half.
31. [ftmac110] rename the struct name of descriptors to CamelCase.
32. [ftmac110] replace 'void *' with 'Ftmac110RXD *' and 'Ftmac110TXD *' for descriptor read/write.
33. [ftmac110] add buffer overflow check in ftmac110_transmit()
34. [ftmac110] add buffer alignment check
35. [ftdmac020] replace the dumb timer code with bottom half.
36. [ftdmac020] replace cpu_physical_memory_map() with cpu_physical_memory_read/write() for both simplicity and security enhancement which caused by the un-checked return mapped length from cpu_physical_memory_map().
37. [ftapbbrg020] replace the dumb timer code with bottom half.
38. [ftapbbrg020] replace cpu_physical_memory_map() with cpu_physical_memory_read/write() for both simplicity and security enhancement which caused by the un-checked return mapped length from cpu_physical_memory_map().
39. [ftrtc011] switch to a slower timer with msec resolution. (i.e. rt_clock)
40. [ftrtc011] re-calculate RTC counters from host timestamp upon register read/write and also vm save/restore.

Changes for v2:

1. coding style fixes (verified with checkpatch.pl)
2. add Faraday A360 support
3. add Faraday USB 2.0 EHCI support
4. merge a369_scu.c into a369.c
5. introduce QOM coding style
6. remove lowercase Macros: min(), max()
7. name all struct as CamelCase style
8. move function prototypes from .c to faraday.h
9. use switch instead of if statement in a369_ahbc_write
10. remove debug prints
11. update all uarts in A36x to DEVICE_LITTLE_ENDIAN.
12. move the variable definitions to the start of the function, instead of inside a do { } while(0)
13. remove disabled and commented out code.
14. use hw_error() and exit() upon pflash register failed.
15. add const prior to TypeInfo (i.e. static *const* TypeInfo ftrtc011_info)
16. add le32_to_cpu/cpu_to_le32 to the descriptor processing in

      FTGMAC100/FTMAC110.

17. update the GPL license to GPL v2 (except for FTLCDC200, it's based on pl110.c which is LGPL.)
18. add const to src_* in the DMA controllers (FTAPBBRG020/FTDMAC020)

Kuo-Jung Su (24):
target-arm: add Faraday ARMv5TE processors support hw/arm: add Faraday a369 SoC platform support hw/arm: add FTINTC020 interrupt controller support hw/arm: add FTAHBC020 AHB controller support hw/arm: add FTDDRII030 DDRII controller support hw/arm: add FTPWMTMR010 timer support
hw/arm: add FTWDT010 watchdog timer support hw/arm: add FTRTC011 RTC timer support
tests: add QTest for FTRTC011
hw/arm: add FTDMAC020 AHB DMA support
hw/arm: add FTAPBBRG020 APB DMA support
hw/arm: add FTNANDC021 nand flash controller support hw/arm: add FTI2C010 I2C controller support
hw: Add AudioCodecClass for wm87xx audio class abstration.
hw: add WM8731 audio codec support
hw/arm: add FTSSP010 multi-function controller support qemu/bitops.h: add the bit ordering reversal functions hw/arm: add FTGMAC100 1Gbps ethernet support hw/arm: add FTLCDC200 LCD controller support hw/arm: add FTTSC010 touchscreen controller support hw/arm: add FTSDC010 MMC/SD controller support hw/arm: add FTMAC110 10/100Mbps ethernet support hw/arm: add FTTMR010 timer support
hw/arm: add FTSPI020 SPI flash controller support

 default-configs/arm-softmmu.mak |    1 +
 hw/Makefile.objs                |    2 +
 hw/arm/Makefile.objs            |   21 ++
 hw/arm/faraday.h                |   61 ++++
 hw/arm/faraday_a369.c           |  174 ++++++++++
 hw/arm/faraday_a369_kpd.c       |  231 +++++++++++++
 hw/arm/faraday_a369_scu.c       |  182 ++++++++++
 hw/arm/faraday_a369_soc.c       |  342 +++++++++++++++++++
 hw/arm/ftahbc020.c              |  202 +++++++++++
 hw/arm/ftapbbrg020.c            |  468 ++++++++++++++++++++++++++
 hw/arm/ftapbbrg020.h            |   44 +++
 hw/arm/ftddrii030.c             |  183 ++++++++++
 hw/arm/ftdmac020.c              |  595 ++++++++++++++++++++++++++++++++
 hw/arm/ftdmac020.h              |  107 ++++++
 hw/arm/ftgmac100.c              |  708 +++++++++++++++++++++++++++++++++++++++
 hw/arm/ftgmac100.h              |  239 +++++++++++++
 hw/arm/fti2c010.c               |  212 ++++++++++++
 hw/arm/fti2c010.h               |   71 ++++
 hw/arm/ftintc020.c              |  302 +++++++++++++++++
 hw/arm/ftintc020.h              |   57 ++++
 hw/arm/ftkbc010.h               |   44 +++
 hw/arm/ftlcdc200.c              |  510 ++++++++++++++++++++++++++++
 hw/arm/ftlcdc200.h              |  112 +++++++
 hw/arm/ftlcdc200_template.h     |  439 ++++++++++++++++++++++++
 hw/arm/ftmac110.c               |  661 ++++++++++++++++++++++++++++++++++++
 hw/arm/ftmac110.h               |  168 ++++++++++
 hw/arm/ftnandc021.c             |  516 ++++++++++++++++++++++++++++
 hw/arm/ftnandc021.h             |   84 +++++
 hw/arm/ftpwmtmr010.c            |  258 ++++++++++++++
 hw/arm/ftpwmtmr010.h            |   31 ++
 hw/arm/ftrtc011.c               |  383 +++++++++++++++++++++
 hw/arm/ftrtc011.h               |   53 +++
 hw/arm/ftsdc010.c               |  354 ++++++++++++++++++++
 hw/arm/ftsdc010.h               |   90 +++++
 hw/arm/ftspi020.c               |  337 +++++++++++++++++++
 hw/arm/ftspi020.h               |   81 +++++
 hw/arm/ftssp010.c               |  494 +++++++++++++++++++++++++++
 hw/arm/ftssp010.h               |   98 ++++++
 hw/arm/fttmr010.c               |  445 ++++++++++++++++++++++++
 hw/arm/fttmr010.h               |   41 +++
 hw/arm/fttsc010.c               |  260 ++++++++++++++
 hw/arm/fttsc010.h               |   39 +++
 hw/arm/ftwdt010.c               |  209 ++++++++++++
 hw/arm/ftwdt010.h               |   35 ++
 hw/arm/spitz.c                  |    9 +-
 hw/arm/z2.c                     |    9 +-
 hw/audio_codec.c                |   81 +++++
 hw/audio_codec.h                |   56 ++++
 hw/i2c.h                        |    9 -
 hw/marvell_88w8618_audio.c      |   23 +-
 hw/wm8731.c                     |  505 ++++++++++++++++++++++++++++
 hw/wm8750.c                     |   91 ++---
 include/qemu/bitops.h           |   59 +++-
 target-arm/cpu.c                |   52 +++
 target-arm/cpu.h                |    6 +-
 target-arm/helper.c             |   84 +++++
 target-arm/machine.c            |    4 +
 tests/Makefile                  |    3 +
 tests/ftrtc011-test.c           |  410 +++++++++++++++++++++++
 59 files changed, 11275 insertions(+), 70 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/audio_codec.c
 create mode 100644 hw/audio_codec.h
 create mode 100644 hw/wm8731.c
 create mode 100644 tests/ftrtc011-test.c
Signature · 1 line
1.7.9.5
#1 lore raw

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

From: Kuo-Jung Su <[email protected]>

This patch includes the single core support to FA606TE, FA626TE, FA616TE and FA726TE with CP15 Faraday extensions (AUX and I/D-Scratchpad).

---
 target-arm/cpu.c     |   52 +++++++++++++++++++++++++++++++
 target-arm/cpu.h     |    6 +++-
 target-arm/helper.c  |   84 ++++++++++++++++++++++++++++++++++++++++++++++++++
 target-arm/machine.c |    4 +++
 4 files changed, 145 insertions(+), 1 deletion(-)
target-arm/cpu.c +52 -0
index a1e9093..aed97b0 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);
@@ -766,6 +814,10 @@ typedef struct ARMCPUInfo {
 
 static const ARMCPUInfo arm_cpus[] = {
     { .name = "arm926",      .initfn = arm926_initfn },
+    { .name = "fa606te",     .initfn = fa606te_initfn },
+    { .name = "fa616te",     .initfn = fa616te_initfn },
+    { .name = "fa626te",     .initfn = fa626te_initfn },
+    { .name = "fa726te",     .initfn = fa726te_initfn },
     { .name = "arm946",      .initfn = arm946_initfn },
     { .name = "arm1026",     .initfn = arm1026_initfn },
     /* What QEMU calls "arm1136-r2" is actually the 1136 r0p2, i.e. an
target-arm/cpu.h +5 -1
index 2b97221..dd27e80 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 {
@@ -392,6 +394,8 @@ enum arm_features {
     ARM_FEATURE_MPIDR, /* has cp15 MPIDR */
     ARM_FEATURE_PXN, /* has Privileged Execute Never bit */
     ARM_FEATURE_LPAE, /* has Large Physical Address Extension */
+    ARM_FEATURE_TCM_FARADAY, /* Faraday Scratchpad(TCM) */
+    ARM_FEATURE_MPU_FARADAY, /* Faraday MPU */
 };
 
 static inline int arm_feature(CPUARMState *env, int feature)
@@ -640,7 +644,7 @@ static inline CPUARMState *cpu_init(const char *cpu_model)
 #define cpu_signal_handler cpu_arm_signal_handler
 #define cpu_list arm_cpu_list
 
-#define CPU_SAVE_VERSION 9
+#define CPU_SAVE_VERSION 10
 
 /* MMU modes definitions */
 #define MMU_MODE0_SUFFIX _kernel
target-arm/helper.c +84 -0

96 lines not on this page · raw message

target-arm/machine.c +4 -0
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 v8 2/24 hw/arm: add Faraday a369 SoC platform support

In reply to Kuo-Jung Su

From: Kuo-Jung Su <[email protected]>

The Faraday A369 EVB is a Faraday SoC platform evalution board used for Faraday IP functional verification based on the well-known ARM AMBA 2.0 architecture.

---
 hw/arm/Makefile.objs      |    3 +
 hw/arm/faraday.h          |   52 ++++++++++
 hw/arm/faraday_a369.c     |   98 +++++++++++++++++++
 hw/arm/faraday_a369_kpd.c |  231 +++++++++++++++++++++++++++++++++++++++++++++
 hw/arm/faraday_a369_scu.c |  182 +++++++++++++++++++++++++++++++++++
 hw/arm/faraday_a369_soc.c |  190 +++++++++++++++++++++++++++++++++++++
 hw/arm/ftkbc010.h         |   44 +++++++++
 7 files changed, 800 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 +3 -0
index f5f7d0e..104e0e7 100644
@@ -34,3 +34,6 @@ obj-y += tosa.o versatilepb.o vexpress.o xilinx_zynq.o z2.o
 
 obj-y += armv7m.o exynos4210.o pxa2xx.o pxa2xx_gpio.o pxa2xx_pic.o
 obj-y += omap1.o omap2.o
+
+obj-y += faraday_a369.o faraday_a369_soc.o faraday_a369_scu.o \
+            faraday_a369_kpd.o
hw/arm/faraday.h new file +52 -0

52 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 +231 -0

231 lines not on this page · raw message

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

182 lines not on this page · raw message

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

190 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 v8 3/24 hw/arm: add FTINTC020 interrupt controller support

In reply to Kuo-Jung Su

From: Kuo-Jung Su <[email protected]>

The FTINTC020 interrupt controller supports both FIQ and IRQ signals to the microprocessor.
It can handle up to 64 configurable IRQ sources and 64 FIQ sources. The output signals to the microprocessor can be configured as level-high/low active or edge-rising/falling triggered.

---
 hw/arm/Makefile.objs      |    1 +
 hw/arm/faraday_a369_soc.c |   11 ++
 hw/arm/ftintc020.c        |  302 +++++++++++++++++++++++++++++++++++++++++++++
 hw/arm/ftintc020.h        |   57 +++++++++
 4 files changed, 371 insertions(+)
 create mode 100644 hw/arm/ftintc020.c
 create mode 100644 hw/arm/ftintc020.h
hw/arm/Makefile.objs +1 -0
index 104e0e7..536d6cf 100644
@@ -37,3 +37,4 @@ obj-y += omap1.o omap2.o
 
 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 4e19c7e..eab05dc 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)
         abort();
     }
 
+    /* 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 +302 -0

302 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

PATCH v8 4/24 hw/arm: add FTAHBC020 AHB controller support

In reply to Kuo-Jung Su

From: Kuo-Jung Su <[email protected]>

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 |   10 +++
 hw/arm/ftahbc020.c        |  202 +++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 213 insertions(+)
 create mode 100644 hw/arm/ftahbc020.c
hw/arm/Makefile.objs +1 -0
index 536d6cf..af36b01 100644
@@ -38,3 +38,4 @@ obj-y += omap1.o omap2.o
 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 +10 -0
index eab05dc..01b4395 100644
@@ -70,6 +70,7 @@ static void a369soc_reset(DeviceState *ds)
 static void
 a369soc_device_init(FaradaySoCState *s)
 {
+    Error *local_errp = NULL;
     DriveInfo *dinfo;
     DeviceState *ds;
     qemu_irq *cpu_pic;
@@ -148,6 +149,15 @@ 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;
+    object_property_set_link(OBJECT(ds), OBJECT(s), "soc", &local_errp);
+    if (local_errp) {
+        fprintf(stderr, "a369soc: Unable to set soc link for FTAHBC020\n");
+        abort();
+    }
 }
 
 static void a369soc_realize(DeviceState *dev, Error **errp)
hw/arm/ftahbc020.c new file +202 -0

202 lines not on this page · raw message

Signature · 1 line
1.7.9.5
#5 lore raw

PATCH v8 5/24 hw/arm: add FTDDRII030 DDRII controller support

In reply to Kuo-Jung Su

From: Kuo-Jung Su <[email protected]>

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 |    9 +++
 hw/arm/ftddrii030.c       |  183 +++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 193 insertions(+)
 create mode 100644 hw/arm/ftddrii030.c
hw/arm/Makefile.objs +1 -0
index af36b01..0bbf838 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 +9 -0
index 01b4395..e8a63bb 100644
@@ -158,6 +158,15 @@ a369soc_device_init(FaradaySoCState *s)
         fprintf(stderr, "a369soc: Unable to set soc link for FTAHBC020\n");
         abort();
     }
+
+    /* ftddrii030 */
+    ds = sysbus_create_simple("ftddrii030", 0x93100000, NULL);
+    s->ddrc = ds;
+    object_property_set_link(OBJECT(ds), OBJECT(s), "soc", &local_errp);
+    if (local_errp) {
+        fprintf(stderr, "a369soc: Unable to set soc link for FTDDRII030\n");
+        abort();
+    }
 }
 
 static void a369soc_realize(DeviceState *dev, Error **errp)
hw/arm/ftddrii030.c new file +183 -0

183 lines not on this page · raw message

Signature · 1 line
1.7.9.5
#6 lore raw

Re: [Qemu-devel] [PATCH v8 05/24] hw/arm: add FTDDRII030 DDRII controller support

Hi Kuo-Jung,

Quoted 124 lines · Kuo-Jung Su

From: Kuo-Jung Su <[email protected]>

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 |    9 +++
 hw/arm/ftddrii030.c       |  183 +++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 193 insertions(+)
 create mode 100644 hw/arm/ftddrii030.c
hw/arm/Makefile.objs +1 -0
index af36b01..0bbf838 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 +9 -0
index 01b4395..e8a63bb 100644
@@ -158,6 +158,15 @@ a369soc_device_init(FaradaySoCState *s)
         fprintf(stderr, "a369soc: Unable to set soc link for FTAHBC020\n");
         abort();
     }
+
+    /* ftddrii030 */
+    ds = sysbus_create_simple("ftddrii030", 0x93100000, NULL);
+    s->ddrc = ds;
+    object_property_set_link(OBJECT(ds), OBJECT(s), "soc", &local_errp);
+    if (local_errp) {
+        fprintf(stderr, "a369soc: Unable to set soc link for FTDDRII030\n");
+        abort();
+    }
 }
 
 static void a369soc_realize(DeviceState *dev, Error **errp)
hw/arm/ftddrii030.c new file +75 -0
new file mode 100644
index 0000000..90a5842
@@ -0,0 +1,183 @@
+/*
+ * Faraday DDRII controller
+ *
+ * Copyright (c) 2012 Faraday Technology
+ * Written by Dante Su <[email protected]>
+ *
+ * This code is licensed under GNU GPL v2+
+ */
+
+#include "hw/hw.h"
+#include "hw/sysbus.h"
+#include "hw/devices.h"
+#include "sysemu/sysemu.h"
+
+#include "faraday.h"
+
+#define REG_MCR             0x00    /* memory configuration register */
+#define REG_MSR             0x04    /* memory status register */
+#define REG_REVR            0x50    /* revision register */
+
+#define MSR_INIT_OK         BIT(8)  /* DDR2 initial is completed */
+#define MSR_CMD_MRS         BIT(0)  /* start MRS command */
+
+#define CFG_REGSIZE         (0x50 / 4)
+
+#define TYPE_FTDDRII030     "ftddrii030"
+
+typedef struct Ftddrii030State {
+    SysBusDevice busdev;
+    MemoryRegion iomem;
+
+    FaradaySoCState *soc;
+    /* HW register cache */
+    uint32_t regs[CFG_REGSIZE];
+} Ftddrii030State;
+
+#define FTDDRII030(obj) \
+    OBJECT_CHECK(Ftddrii030State, obj, TYPE_FTDDRII030)
+
+#define DDR_REG32(s, off) \
+    ((s)->regs[(off) / 4])
+
+static uint64_t
+ftddrii030_mem_read(void *opaque, hwaddr addr, unsigned size)
+{
+    Ftddrii030State *s = FTDDRII030(opaque);
+    uint64_t ret = 0;
+
+    if (s->soc->ddr_inited) {
+        DDR_REG32(s, REG_MSR) |= MSR_INIT_OK;
+    }
+
+    switch (addr) {
+    case REG_MCR ... (CFG_REGSIZE - 1) * 4:
+        ret = s->regs[addr / 4];
+        break;
+    case REG_REVR:
+        ret = 0x100;    /* rev. = 0.1.0 */
+        break;
+    default:
+        qemu_log_mask(LOG_GUEST_ERROR,
+            "ftddrii030: undefined memory access@%#" HWADDR_PRIx "\n", addr);
+        break;
+    }
+
+    return ret;
+}
+
+static void
+ftddrii030_mem_write(void *opaque, hwaddr addr, uint64_t val, unsigned size)
+{
+    Ftddrii030State *s = FTDDRII030(opaque);
+
+    switch (addr) {
+    case REG_MCR:

hw/arm/ftddrii030.c line 85

Quoted 10 lines
hw/arm/ftddrii030.c new file +10 -0
+        DDR_REG32(s, REG_MCR) = (uint32_t)val & 0xffff;
+        break;
+    case REG_MSR:
+        val = (val & 0x3f) | (DDR_REG32(s, REG_MSR) & MSR_INIT_OK);
+        if (!s->soc->ddr_inited && (val & MSR_CMD_MRS)) {
+            val &= ~MSR_CMD_MRS;
+            val |= MSR_INIT_OK;
+            memory_region_add_subregion(s->soc->as,
+                                        s->soc->ram_base,
+                                        s->soc->ram);

I feel like this is overstepping the bounds of the device. Its modifying the internals of the parent device (the SoC itself). AFAICT, this device does not need awareness of where the RAM is to live in the address map, thats the responsibility of the machine model. It might be cleaner to model the actual RAM as a second sysbus memory region then leave it up the machine model to decide where in the address map it should live. This device just adds/removes the ram from the second region without knowing where it lives and the machine model maps the RAM to its actual location. Keeps .as .ram_base and .ram private to the SoC device.

hw/arm/ftddrii030.c line 86

Quoted 1 line
hw/arm/ftddrii030.c new file +1 -0
+            s->soc->ddr_inited = true;

I'm still trying to figure out the physical analogue of this. Is there a genuine hardware linkage from the DDR controller to other devices that says "hey i'm inited" or is this faking firmware activity? In the former case, this ddr_inited should be a GPIO from DDR controller to whatever devices care. In the latter case, its trickier, and we should discuss bootloader based solutions to get your tiny little bit of firmware in, without having to model non-existent hardware.

Regards,
Peter

Quoted 101 lines
hw/arm/ftddrii030.c new file +97 -1
+        }
+        DDR_REG32(s, REG_MSR) = (uint32_t)val;
+        break;
+    case 0x08 ... (CFG_REGSIZE - 1) * 4: /* DDRII Timing, ECC ...etc. */
+        s->regs[addr / 4] = (uint32_t)val;
+        break;
+    default:
+        qemu_log_mask(LOG_GUEST_ERROR,
+            "ftddrii030: undefined memory access@%#" HWADDR_PRIx "\n", addr);
+        break;
+    }
+}
+
+static const MemoryRegionOps mmio_ops = {
+    .read  = ftddrii030_mem_read,
+    .write = ftddrii030_mem_write,
+    .endianness = DEVICE_LITTLE_ENDIAN,
+    .valid = {
+        .min_access_size = 4,
+        .max_access_size = 4,
+    }
+};
+
+static void ftddrii030_reset(DeviceState *ds)
+{
+    Ftddrii030State *s = FTDDRII030(SYS_BUS_DEVICE(ds));
+    Error *local_errp = NULL;
+
+    s->soc = FARADAY_SOC(object_property_get_link(OBJECT(s),
+                                                  "soc",
+                                                  &local_errp));
+    if (local_errp) {
+        fprintf(stderr, "ftahbc020: Unable to get soc link\n");
+        abort();
+    }
+
+    if (s->soc->ddr_inited && !s->soc->bi) {
+        memory_region_del_subregion(s->soc->as, s->soc->ram);
+        s->soc->ddr_inited = false;
+    }
+
+    memset(s->regs, 0, sizeof(s->regs));
+}
+
+static void ftddrii030_realize(DeviceState *dev, Error **errp)
+{
+    Ftddrii030State *s = FTDDRII030(dev);
+
+    memory_region_init_io(&s->iomem,
+                          &mmio_ops,
+                          s,
+                          TYPE_FTDDRII030,
+                          0x1000);
+    sysbus_init_mmio(SYS_BUS_DEVICE(dev), &s->iomem);
+
+    object_property_add_link(OBJECT(dev),
+                             "soc",
+                             TYPE_FARADAY_SOC,
+                             (Object **) &s->soc,
+                             errp);
+}
+
+static const VMStateDescription vmstate_ftddrii030 = {
+    .name = TYPE_FTDDRII030,
+    .version_id = 1,
+    .minimum_version_id = 1,
+    .minimum_version_id_old = 1,
+    .fields = (VMStateField[]) {
+        VMSTATE_UINT32_ARRAY(regs, Ftddrii030State, CFG_REGSIZE),
+        VMSTATE_END_OF_LIST(),
+    }
+};
+
+static void ftddrii030_class_init(ObjectClass *klass, void *data)
+{
+    DeviceClass *dc = DEVICE_CLASS(klass);
+
+    dc->desc  = TYPE_FTDDRII030;
+    dc->vmsd  = &vmstate_ftddrii030;
+    dc->reset = ftddrii030_reset;
+    dc->realize = ftddrii030_realize;
+    dc->no_user = 1;
+}
+
+static const TypeInfo ftddrii030_info = {
+    .name          = TYPE_FTDDRII030,
+    .parent        = TYPE_SYS_BUS_DEVICE,
+    .instance_size = sizeof(Ftddrii030State),
+    .class_init    = ftddrii030_class_init,
+};
+
+static void ftddrii030_register_types(void)
+{
+    type_register_static(&ftddrii030_info);
+}
+
+type_init(ftddrii030_register_types)
--

1.7.9.5

#7 lore raw

Re: [Qemu-devel] [PATCH v8 05/24] hw/arm: add FTDDRII030 DDRII controller support

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

Quoted 140 lines

Hi Kuo-Jung,

Quoted 124 lines · Kuo-Jung Su

From: Kuo-Jung Su <[email protected]>

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 |    9 +++
 hw/arm/ftddrii030.c       |  183 +++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 193 insertions(+)
 create mode 100644 hw/arm/ftddrii030.c
hw/arm/Makefile.objs +1 -0
index af36b01..0bbf838 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 +9 -0
index 01b4395..e8a63bb 100644
@@ -158,6 +158,15 @@ a369soc_device_init(FaradaySoCState *s)
         fprintf(stderr, "a369soc: Unable to set soc link for FTAHBC020\n");
         abort();
     }
+
+    /* ftddrii030 */
+    ds = sysbus_create_simple("ftddrii030", 0x93100000, NULL);
+    s->ddrc = ds;
+    object_property_set_link(OBJECT(ds), OBJECT(s), "soc", &local_errp);
+    if (local_errp) {
+        fprintf(stderr, "a369soc: Unable to set soc link for FTDDRII030\n");
+        abort();
+    }
 }
 
 static void a369soc_realize(DeviceState *dev, Error **errp)
hw/arm/ftddrii030.c new file +75 -0
new file mode 100644
index 0000000..90a5842
@@ -0,0 +1,183 @@
+/*
+ * Faraday DDRII controller
+ *
+ * Copyright (c) 2012 Faraday Technology
+ * Written by Dante Su <[email protected]>
+ *
+ * This code is licensed under GNU GPL v2+
+ */
+
+#include "hw/hw.h"
+#include "hw/sysbus.h"
+#include "hw/devices.h"
+#include "sysemu/sysemu.h"
+
+#include "faraday.h"
+
+#define REG_MCR             0x00    /* memory configuration register */
+#define REG_MSR             0x04    /* memory status register */
+#define REG_REVR            0x50    /* revision register */
+
+#define MSR_INIT_OK         BIT(8)  /* DDR2 initial is completed */
+#define MSR_CMD_MRS         BIT(0)  /* start MRS command */
+
+#define CFG_REGSIZE         (0x50 / 4)
+
+#define TYPE_FTDDRII030     "ftddrii030"
+
+typedef struct Ftddrii030State {
+    SysBusDevice busdev;
+    MemoryRegion iomem;
+
+    FaradaySoCState *soc;
+    /* HW register cache */
+    uint32_t regs[CFG_REGSIZE];
+} Ftddrii030State;
+
+#define FTDDRII030(obj) \
+    OBJECT_CHECK(Ftddrii030State, obj, TYPE_FTDDRII030)
+
+#define DDR_REG32(s, off) \
+    ((s)->regs[(off) / 4])
+
+static uint64_t
+ftddrii030_mem_read(void *opaque, hwaddr addr, unsigned size)
+{
+    Ftddrii030State *s = FTDDRII030(opaque);
+    uint64_t ret = 0;
+
+    if (s->soc->ddr_inited) {
+        DDR_REG32(s, REG_MSR) |= MSR_INIT_OK;
+    }
+
+    switch (addr) {
+    case REG_MCR ... (CFG_REGSIZE - 1) * 4:
+        ret = s->regs[addr / 4];
+        break;
+    case REG_REVR:
+        ret = 0x100;    /* rev. = 0.1.0 */
+        break;
+    default:
+        qemu_log_mask(LOG_GUEST_ERROR,
+            "ftddrii030: undefined memory access@%#" HWADDR_PRIx "\n", addr);
+        break;
+    }
+
+    return ret;
+}
+
+static void
+ftddrii030_mem_write(void *opaque, hwaddr addr, uint64_t val, unsigned size)
+{
+    Ftddrii030State *s = FTDDRII030(opaque);
+
+    switch (addr) {
+    case REG_MCR:

hw/arm/ftddrii030.c line 85

Quoted 10 lines
hw/arm/ftddrii030.c new file +10 -0
+        DDR_REG32(s, REG_MCR) = (uint32_t)val & 0xffff;
+        break;
+    case REG_MSR:
+        val = (val & 0x3f) | (DDR_REG32(s, REG_MSR) & MSR_INIT_OK);
+        if (!s->soc->ddr_inited && (val & MSR_CMD_MRS)) {
+            val &= ~MSR_CMD_MRS;
+            val |= MSR_INIT_OK;
+            memory_region_add_subregion(s->soc->as,
+                                        s->soc->ram_base,
+                                        s->soc->ram);

I feel like this is overstepping the bounds of the device. Its modifying the internals of the parent device (the SoC itself). AFAICT,

Quoted 9 lines

this device does not need awareness of where the RAM is to live in the address map, thats the responsibility of the machine model. It might be cleaner to model the actual RAM as a second sysbus memory region then leave it up the machine model to decide where in the address map it should live. This device just adds/removes the ram from the second region without knowing where it lives and the machine model maps the RAM to its actual location. Keeps .as .ram_base and .ram private to the SoC device.

Thanks for the comments,
I'll try to implement a cleaner model in the way suggested in the above comments.

Quoted 10 lines

hw/arm/ftddrii030.c line 86

Quoted 1 line
hw/arm/ftddrii030.c new file +1 -0
+            s->soc->ddr_inited = true;

I'm still trying to figure out the physical analogue of this. Is there a genuine hardware linkage from the DDR controller to other devices that says "hey i'm inited" or is this faking firmware activity? In the former case, this ddr_inited should be a GPIO from DDR controller to whatever devices care. In the latter case, its trickier, and we should discuss bootloader based solutions to get your tiny little bit of firmware in, without having to model non-existent hardware.

Thanks for the comments.
It's the 1st one, it's used to inform the FTAHBC020 of the presence of DRAM in QEMU model. And thus it could be replaced by a GPIO implementation.
However in this way, it would slightly disobey the real hardware design. I'll see if I could find a better way or not. If no luck, I'll try the GPIO way as you suggested.

Kuo-Jung

Quoted 96 lines

Regards,
Peter

Quoted 93 lines
hw/arm/ftddrii030.c new file +93 -0
+        }
+        DDR_REG32(s, REG_MSR) = (uint32_t)val;
+        break;
+    case 0x08 ... (CFG_REGSIZE - 1) * 4: /* DDRII Timing, ECC ...etc. */
+        s->regs[addr / 4] = (uint32_t)val;
+        break;
+    default:
+        qemu_log_mask(LOG_GUEST_ERROR,
+            "ftddrii030: undefined memory access@%#" HWADDR_PRIx "\n", addr);
+        break;
+    }
+}
+
+static const MemoryRegionOps mmio_ops = {
+    .read  = ftddrii030_mem_read,
+    .write = ftddrii030_mem_write,
+    .endianness = DEVICE_LITTLE_ENDIAN,
+    .valid = {
+        .min_access_size = 4,
+        .max_access_size = 4,
+    }
+};
+
+static void ftddrii030_reset(DeviceState *ds)
+{
+    Ftddrii030State *s = FTDDRII030(SYS_BUS_DEVICE(ds));
+    Error *local_errp = NULL;
+
+    s->soc = FARADAY_SOC(object_property_get_link(OBJECT(s),
+                                                  "soc",
+                                                  &local_errp));
+    if (local_errp) {
+        fprintf(stderr, "ftahbc020: Unable to get soc link\n");
+        abort();
+    }
+
+    if (s->soc->ddr_inited && !s->soc->bi) {
+        memory_region_del_subregion(s->soc->as, s->soc->ram);
+        s->soc->ddr_inited = false;
+    }
+
+    memset(s->regs, 0, sizeof(s->regs));
+}
+
+static void ftddrii030_realize(DeviceState *dev, Error **errp)
+{
+    Ftddrii030State *s = FTDDRII030(dev);
+
+    memory_region_init_io(&s->iomem,
+                          &mmio_ops,
+                          s,
+                          TYPE_FTDDRII030,
+                          0x1000);
+    sysbus_init_mmio(SYS_BUS_DEVICE(dev), &s->iomem);
+
+    object_property_add_link(OBJECT(dev),
+                             "soc",
+                             TYPE_FARADAY_SOC,
+                             (Object **) &s->soc,
+                             errp);
+}
+
+static const VMStateDescription vmstate_ftddrii030 = {
+    .name = TYPE_FTDDRII030,
+    .version_id = 1,
+    .minimum_version_id = 1,
+    .minimum_version_id_old = 1,
+    .fields = (VMStateField[]) {
+        VMSTATE_UINT32_ARRAY(regs, Ftddrii030State, CFG_REGSIZE),
+        VMSTATE_END_OF_LIST(),
+    }
+};
+
+static void ftddrii030_class_init(ObjectClass *klass, void *data)
+{
+    DeviceClass *dc = DEVICE_CLASS(klass);
+
+    dc->desc  = TYPE_FTDDRII030;
+    dc->vmsd  = &vmstate_ftddrii030;
+    dc->reset = ftddrii030_reset;
+    dc->realize = ftddrii030_realize;
+    dc->no_user = 1;
+}
+
+static const TypeInfo ftddrii030_info = {
+    .name          = TYPE_FTDDRII030,
+    .parent        = TYPE_SYS_BUS_DEVICE,
+    .instance_size = sizeof(Ftddrii030State),
+    .class_init    = ftddrii030_class_init,
+};
+
+static void ftddrii030_register_types(void)
+{
Quoted 8 lines
Quoted 8 lines
hw/arm/ftddrii030.c new file +4 -1
+    type_register_static(&ftddrii030_info);
+}
+
+type_init(ftddrii030_register_types)
--

1.7.9.5

--
Best wishes,
Kuo-Jung Su

#8 lore raw

Re: [Qemu-devel] [PATCH v8 05/24] hw/arm: add FTDDRII030 DDRII controller support

Quoted 166 lines · Kuo-Jung Su

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

Quoted 140 lines

Hi Kuo-Jung,

Quoted 124 lines · Kuo-Jung Su

From: Kuo-Jung Su <[email protected]>

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 |    9 +++
 hw/arm/ftddrii030.c       |  183 +++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 193 insertions(+)
 create mode 100644 hw/arm/ftddrii030.c
hw/arm/Makefile.objs +1 -0
index af36b01..0bbf838 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 +9 -0
index 01b4395..e8a63bb 100644
@@ -158,6 +158,15 @@ a369soc_device_init(FaradaySoCState *s)
         fprintf(stderr, "a369soc: Unable to set soc link for FTAHBC020\n");
         abort();
     }
+
+    /* ftddrii030 */
+    ds = sysbus_create_simple("ftddrii030", 0x93100000, NULL);
+    s->ddrc = ds;
+    object_property_set_link(OBJECT(ds), OBJECT(s), "soc", &local_errp);
+    if (local_errp) {
+        fprintf(stderr, "a369soc: Unable to set soc link for FTDDRII030\n");
+        abort();
+    }
 }
 
 static void a369soc_realize(DeviceState *dev, Error **errp)
hw/arm/ftddrii030.c new file +75 -0
new file mode 100644
index 0000000..90a5842
@@ -0,0 +1,183 @@
+/*
+ * Faraday DDRII controller
+ *
+ * Copyright (c) 2012 Faraday Technology
+ * Written by Dante Su <[email protected]>
+ *
+ * This code is licensed under GNU GPL v2+
+ */
+
+#include "hw/hw.h"
+#include "hw/sysbus.h"
+#include "hw/devices.h"
+#include "sysemu/sysemu.h"
+
+#include "faraday.h"
+
+#define REG_MCR             0x00    /* memory configuration register */
+#define REG_MSR             0x04    /* memory status register */
+#define REG_REVR            0x50    /* revision register */
+
+#define MSR_INIT_OK         BIT(8)  /* DDR2 initial is completed */
+#define MSR_CMD_MRS         BIT(0)  /* start MRS command */
+
+#define CFG_REGSIZE         (0x50 / 4)
+
+#define TYPE_FTDDRII030     "ftddrii030"
+
+typedef struct Ftddrii030State {
+    SysBusDevice busdev;
+    MemoryRegion iomem;
+
+    FaradaySoCState *soc;
+    /* HW register cache */
+    uint32_t regs[CFG_REGSIZE];
+} Ftddrii030State;
+
+#define FTDDRII030(obj) \
+    OBJECT_CHECK(Ftddrii030State, obj, TYPE_FTDDRII030)
+
+#define DDR_REG32(s, off) \
+    ((s)->regs[(off) / 4])
+
+static uint64_t
+ftddrii030_mem_read(void *opaque, hwaddr addr, unsigned size)
+{
+    Ftddrii030State *s = FTDDRII030(opaque);
+    uint64_t ret = 0;
+
+    if (s->soc->ddr_inited) {
+        DDR_REG32(s, REG_MSR) |= MSR_INIT_OK;
+    }
+
+    switch (addr) {
+    case REG_MCR ... (CFG_REGSIZE - 1) * 4:
+        ret = s->regs[addr / 4];
+        break;
+    case REG_REVR:
+        ret = 0x100;    /* rev. = 0.1.0 */
+        break;
+    default:
+        qemu_log_mask(LOG_GUEST_ERROR,
+            "ftddrii030: undefined memory access@%#" HWADDR_PRIx "\n", addr);
+        break;
+    }
+
+    return ret;
+}
+
+static void
+ftddrii030_mem_write(void *opaque, hwaddr addr, uint64_t val, unsigned size)
+{
+    Ftddrii030State *s = FTDDRII030(opaque);
+
+    switch (addr) {
+    case REG_MCR:

hw/arm/ftddrii030.c line 85

Quoted 10 lines
hw/arm/ftddrii030.c new file +10 -0
+        DDR_REG32(s, REG_MCR) = (uint32_t)val & 0xffff;
+        break;
+    case REG_MSR:
+        val = (val & 0x3f) | (DDR_REG32(s, REG_MSR) & MSR_INIT_OK);
+        if (!s->soc->ddr_inited && (val & MSR_CMD_MRS)) {
+            val &= ~MSR_CMD_MRS;
+            val |= MSR_INIT_OK;
+            memory_region_add_subregion(s->soc->as,
+                                        s->soc->ram_base,
+                                        s->soc->ram);

I feel like this is overstepping the bounds of the device. Its modifying the internals of the parent device (the SoC itself). AFAICT,

Quoted 9 lines

this device does not need awareness of where the RAM is to live in the address map, thats the responsibility of the machine model. It might be cleaner to model the actual RAM as a second sysbus memory region then leave it up the machine model to decide where in the address map it should live. This device just adds/removes the ram from the second region without knowing where it lives and the machine model maps the RAM to its actual location. Keeps .as .ram_base and .ram private to the SoC device.

Thanks for the comments,
I'll try to implement a cleaner model in the way suggested in the above comments.

Quoted 10 lines

hw/arm/ftddrii030.c line 86

Quoted 1 line
hw/arm/ftddrii030.c new file +1 -0
+            s->soc->ddr_inited = true;

I'm still trying to figure out the physical analogue of this. Is there a genuine hardware linkage from the DDR controller to other devices that says "hey i'm inited" or is this faking firmware activity? In the former case, this ddr_inited should be a GPIO from DDR controller to whatever devices care. In the latter case, its trickier, and we should discuss bootloader based solutions to get your tiny little bit of firmware in, without having to model non-existent hardware.

Quoted 4 lines

Thanks for the comments.
It's the 1st one, it's used to inform the FTAHBC020 of the presence of DRAM in QEMU model. And thus it could be replaced by a GPIO implementation.

But what's the underlying transport mechanism for this information this in silicon? Is there a wire from the DDR controller to the AHB controller? Or is it some sort of other linkage? Do you have some data-sheets for these two you could quickly link me? Might me able to give a better suggestion with a quick scan of specs.

Regards,
Peter

#9 lore raw

Re: [Qemu-devel] [PATCH v8 05/24] hw/arm: add FTDDRII030 DDRII controller support

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

Quoted 172 lines · Kuo-Jung Su
Quoted 166 lines

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

Quoted 140 lines

Hi Kuo-Jung,

Quoted 124 lines · Kuo-Jung Su

From: Kuo-Jung Su <[email protected]>

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 |    9 +++
 hw/arm/ftddrii030.c       |  183 +++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 193 insertions(+)
 create mode 100644 hw/arm/ftddrii030.c
hw/arm/Makefile.objs +1 -0
index af36b01..0bbf838 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 +9 -0
index 01b4395..e8a63bb 100644
@@ -158,6 +158,15 @@ a369soc_device_init(FaradaySoCState *s)
         fprintf(stderr, "a369soc: Unable to set soc link for FTAHBC020\n");
         abort();
     }
+
+    /* ftddrii030 */
+    ds = sysbus_create_simple("ftddrii030", 0x93100000, NULL);
+    s->ddrc = ds;
+    object_property_set_link(OBJECT(ds), OBJECT(s), "soc", &local_errp);
+    if (local_errp) {
+        fprintf(stderr, "a369soc: Unable to set soc link for FTDDRII030\n");
+        abort();
+    }
 }
 
 static void a369soc_realize(DeviceState *dev, Error **errp)
hw/arm/ftddrii030.c new file +75 -0
new file mode 100644
index 0000000..90a5842
@@ -0,0 +1,183 @@
+/*
+ * Faraday DDRII controller
+ *
+ * Copyright (c) 2012 Faraday Technology
+ * Written by Dante Su <[email protected]>
+ *
+ * This code is licensed under GNU GPL v2+
+ */
+
+#include "hw/hw.h"
+#include "hw/sysbus.h"
+#include "hw/devices.h"
+#include "sysemu/sysemu.h"
+
+#include "faraday.h"
+
+#define REG_MCR             0x00    /* memory configuration register */
+#define REG_MSR             0x04    /* memory status register */
+#define REG_REVR            0x50    /* revision register */
+
+#define MSR_INIT_OK         BIT(8)  /* DDR2 initial is completed */
+#define MSR_CMD_MRS         BIT(0)  /* start MRS command */
+
+#define CFG_REGSIZE         (0x50 / 4)
+
+#define TYPE_FTDDRII030     "ftddrii030"
+
+typedef struct Ftddrii030State {
+    SysBusDevice busdev;
+    MemoryRegion iomem;
+
+    FaradaySoCState *soc;
+    /* HW register cache */
+    uint32_t regs[CFG_REGSIZE];
+} Ftddrii030State;
+
+#define FTDDRII030(obj) \
+    OBJECT_CHECK(Ftddrii030State, obj, TYPE_FTDDRII030)
+
+#define DDR_REG32(s, off) \
+    ((s)->regs[(off) / 4])
+
+static uint64_t
+ftddrii030_mem_read(void *opaque, hwaddr addr, unsigned size)
+{
+    Ftddrii030State *s = FTDDRII030(opaque);
+    uint64_t ret = 0;
+
+    if (s->soc->ddr_inited) {
+        DDR_REG32(s, REG_MSR) |= MSR_INIT_OK;
+    }
+
+    switch (addr) {
+    case REG_MCR ... (CFG_REGSIZE - 1) * 4:
+        ret = s->regs[addr / 4];
+        break;
+    case REG_REVR:
+        ret = 0x100;    /* rev. = 0.1.0 */
+        break;
+    default:
+        qemu_log_mask(LOG_GUEST_ERROR,
+            "ftddrii030: undefined memory access@%#" HWADDR_PRIx "\n", addr);
+        break;
+    }
+
+    return ret;
+}
+
+static void
+ftddrii030_mem_write(void *opaque, hwaddr addr, uint64_t val, unsigned size)
+{
+    Ftddrii030State *s = FTDDRII030(opaque);
+
+    switch (addr) {
+    case REG_MCR:

hw/arm/ftddrii030.c line 85

Quoted 10 lines
hw/arm/ftddrii030.c new file +10 -0
+        DDR_REG32(s, REG_MCR) = (uint32_t)val & 0xffff;
+        break;
+    case REG_MSR:
+        val = (val & 0x3f) | (DDR_REG32(s, REG_MSR) & MSR_INIT_OK);
+        if (!s->soc->ddr_inited && (val & MSR_CMD_MRS)) {
+            val &= ~MSR_CMD_MRS;
+            val |= MSR_INIT_OK;
+            memory_region_add_subregion(s->soc->as,
+                                        s->soc->ram_base,
+                                        s->soc->ram);

I feel like this is overstepping the bounds of the device. Its modifying the internals of the parent device (the SoC itself). AFAICT,

Quoted 9 lines

this device does not need awareness of where the RAM is to live in the address map, thats the responsibility of the machine model. It might be cleaner to model the actual RAM as a second sysbus memory region then leave it up the machine model to decide where in the address map it should live. This device just adds/removes the ram from the second region without knowing where it lives and the machine model maps the RAM to its actual location. Keeps .as .ram_base and .ram private to the SoC device.

Thanks for the comments,
I'll try to implement a cleaner model in the way suggested in the above comments.

Quoted 10 lines

hw/arm/ftddrii030.c line 86

Quoted 1 line
hw/arm/ftddrii030.c new file +1 -0
+            s->soc->ddr_inited = true;

I'm still trying to figure out the physical analogue of this. Is there a genuine hardware linkage from the DDR controller to other devices that says "hey i'm inited" or is this faking firmware activity? In the former case, this ddr_inited should be a GPIO from DDR controller to whatever devices care. In the latter case, its trickier, and we should discuss bootloader based solutions to get your tiny little bit of firmware in, without having to model non-existent hardware.

Quoted 4 lines

Thanks for the comments.
It's the 1st one, it's used to inform the FTAHBC020 of the presence of DRAM in QEMU model. And thus it could be replaced by a GPIO implementation.

Quoted 6 lines

But what's the underlying transport mechanism for this information this in silicon? Is there a wire from the DDR controller to the AHB controller? Or is it some sort of other linkage? Do you have some data-sheets for these two you could quickly link me? Might me able to give a better suggestion with a quick scan of specs.

It's not an issue from the real hardware spec.

It's an issue about the RAM model remapping in QEMU.

The FTDDRII030 is responsible for SDRAM initialization.
Which means the DDRII SDRAM would not be stabilized until the SDRAM is correctly initialized.
=>
In QEMU, the memory_region_add_subregion() is used to perform this emulation.

The FTAHBC030 is responsible for AHB device management (base + window size) and also the special case for AHB remap of slave4 and slave6. =>
In QEMU,
1. If SDRAM is initialized before activating AHB remap:
memory_region_del_subregion() must be called prior to
memory_region_add_subregion().
And this is the reason why I need '.ddr_inited' and
'.ahb_remapped' in SoC struct.
2. If SDRAM is not yet initialized while activating AHB remap:
Only memory_region_add_subregion() needs to be invoked.

So there is no any underlying transport mechanism in the hardware. It's simply about the way how I implement the model of HW emulation.

Quoted 2 lines

Regards,
Peter

--
Best wishes,
Kuo-Jung Su

#10 lore raw

Re: [Qemu-devel] [PATCH v8 05/24] hw/arm: add FTDDRII030 DDRII controller support

Quoted 5 lines · Kuo-Jung Su

The FTDDRII030 is responsible for SDRAM initialization.
Which means the DDRII SDRAM would not be stabilized until the SDRAM is correctly initialized.
=>
In QEMU, the memory_region_add_subregion() is used to perform this emulation.

If you want to model "sdram doesn't work unless it's inited" (which is optional, often for qemu it's fine to just have the RAM always work), then the right way to do this is probably to have this device provide a memory region which is a container and which the SoC always maps. Then this device just maps the RAM into the container when the guest does the DDR init. Having the device mess with its parent's address space is a red flag that you're not modelling things right.

Quoted 11 lines

The FTAHBC030 is responsible for AHB device management (base + window size) and also the special case for AHB remap of slave4 and slave6. =>
In QEMU,
1. If SDRAM is initialized before activating AHB remap:
memory_region_del_subregion() must be called prior to
memory_region_add_subregion().
And this is the reason why I need '.ddr_inited' and
'.ahb_remapped' in SoC struct.
2. If SDRAM is not yet initialized while activating AHB remap:
Only memory_region_add_subregion() needs to be invoked.

If you're handling add/del subregion then you need to model this so that the device that does the add/del is working on a memory region container that it controls. Then it can have a private data structure field which tracks what the state of the mapped subregions is. This almost always turns out to be the same way the hardware design is structured.

At the moment you have add/del going on in this device but fields relating to what state the subregions are in are at the top level soc state.

-- PMM

#11 lore raw

Re: [Qemu-devel] [PATCH v8 05/24] hw/arm: add FTDDRII030 DDRII controller support

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

Quoted 7 lines · Kuo-Jung Su
Quoted 5 lines

The FTDDRII030 is responsible for SDRAM initialization.
Which means the DDRII SDRAM would not be stabilized until the SDRAM is correctly initialized.
=>
In QEMU, the memory_region_add_subregion() is used to perform this emulation.

Quoted 9 lines

If you want to model "sdram doesn't work unless it's inited" (which is optional, often for qemu it's fine to just have the RAM always work), then the right way to do this is probably to have this device provide a memory region which is a container and which the SoC always maps. Then this device just maps the RAM into the container when the guest does the DDR init. Having the device mess with its parent's address space is a red flag that you're not modelling things right.

Got it, thanks.
It sounds like a good idea to me, I'll try to model the ftddrii030 in that way.

Quoted 19 lines
Quoted 11 lines

The FTAHBC030 is responsible for AHB device management (base + window size) and also the special case for AHB remap of slave4 and slave6. =>
In QEMU,
1. If SDRAM is initialized before activating AHB remap:
memory_region_del_subregion() must be called prior to
memory_region_add_subregion().
And this is the reason why I need '.ddr_inited' and
'.ahb_remapped' in SoC struct.
2. If SDRAM is not yet initialized while activating AHB remap:
Only memory_region_add_subregion() needs to be invoked.

If you're handling add/del subregion then you need to model this so that the device that does the add/del is working on a memory region container that it controls. Then it can have a private data structure field which tracks what the state of the mapped subregions is. This almost always turns out to be the same way the hardware design is structured.

Quoted 4 lines

At the moment you have add/del going on in this device but fields relating to what state the subregions are in are at the top level soc state.

Got it, thanks

Quoted 1 line

-- PMM

--
Best wishes,
Kuo-Jung Su

#12 lore raw

PATCH v8 6/24 hw/arm: add FTPWMTMR010 timer support

In reply to Kuo-Jung Su

From: Kuo-Jung Su <[email protected]>

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      |  258 +++++++++++++++++++++++++++++++++++++++++++++
 hw/arm/ftpwmtmr010.h      |   31 ++++++
 4 files changed, 300 insertions(+)
 create mode 100644 hw/arm/ftpwmtmr010.c
 create mode 100644 hw/arm/ftpwmtmr010.h
hw/arm/Makefile.objs +1 -0
index 0bbf838..bc18e22 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 e8a63bb..874dc74 100644
@@ -167,6 +167,16 @@ a369soc_device_init(FaradaySoCState *s)
         fprintf(stderr, "a369soc: Unable to set soc link for FTDDRII030\n");
         abort();
     }
+
+    /* Timer */
+    ds = qdev_create(NULL, "ftpwmtmr010");
+    qdev_prop_set_uint32(ds, "freq", 66 * 1000000);
+    qdev_init_nofail(ds);
+    sysbus_mmio_map(SYS_BUS_DEVICE(ds), 0, 0x92300000);
+    sysbus_connect_irq(SYS_BUS_DEVICE(ds), 0, s->pic[8]);
+    sysbus_connect_irq(SYS_BUS_DEVICE(ds), 1, s->pic[9]);
+    sysbus_connect_irq(SYS_BUS_DEVICE(ds), 2, s->pic[10]);
+    sysbus_connect_irq(SYS_BUS_DEVICE(ds), 3, s->pic[11]);
 }
 
 static void a369soc_realize(DeviceState *dev, Error **errp)
hw/arm/ftpwmtmr010.c new file +258 -0

258 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
#13 lore raw

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

In reply to Kuo-Jung Su

From: Kuo-Jung Su <[email protected]>

The FTWDT010 is used to prevent system from infinite loop while software gets trapped in the deadlock.

Under the normal operation, users should restart FTWDT010 at the regular intervals before counter counts down to 0.

If the counter does reach 0, FTWDT010 will try to reset the system by generating one or a combination of signals, system reset, system interrupt, and external interrupt.

---
 hw/arm/Makefile.objs      |    1 +
 hw/arm/faraday_a369_soc.c |   14 +++
 hw/arm/ftwdt010.c         |  209 +++++++++++++++++++++++++++++++++++++++++++++
 hw/arm/ftwdt010.h         |   35 ++++++++
 4 files changed, 259 insertions(+)
 create mode 100644 hw/arm/ftwdt010.c
 create mode 100644 hw/arm/ftwdt010.h
hw/arm/Makefile.objs +1 -0
index bc18e22..bd330f2 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 +14 -0
index 874dc74..2ec066d 100644
@@ -68,6 +68,16 @@ static void a369soc_reset(DeviceState *ds)
 }
 
 static void
+a369soc_system_reset(void *opaque)
+{
+    FaradaySoCState *s = FARADAY_SOC(opaque);
+
+    if (s->cpu) {
+        cpu_reset(CPU(s->cpu));
+    }
+}
+
+static void
 a369soc_device_init(FaradaySoCState *s)
 {
     Error *local_errp = NULL;
@@ -177,6 +187,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 void a369soc_realize(DeviceState *dev, Error **errp)
hw/arm/ftwdt010.c new file +209 -0

209 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
#14 lore raw

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

In reply to Kuo-Jung Su

From: Kuo-Jung Su <[email protected]>

It provides separate second, minute, hour, and day counters. The second counter is toggled each second, the minute counter is toggled each minute, the hour counter is toggled each hour, and the day counter is toggled each day.

The FTRTC011 provides a programmable auto-alarm function. When the second auto-alarm function is turned on, the RTC will automatically trigger an interrupt each second. The automatic minute and hour alarms can be turned on as well.

---
 hw/arm/Makefile.objs      |    1 +
 hw/arm/faraday_a369_soc.c |   18 +++
 hw/arm/ftrtc011.c         |  383 +++++++++++++++++++++++++++++++++++++++++++++
 hw/arm/ftrtc011.h         |   53 +++++++
 4 files changed, 455 insertions(+)
 create mode 100644 hw/arm/ftrtc011.c
 create mode 100644 hw/arm/ftrtc011.h
hw/arm/Makefile.objs +1 -0
index bd330f2..b01da9d 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 +18 -0
index 2ec066d..7d90079 100644
@@ -191,6 +191,24 @@ a369soc_device_init(FaradaySoCState *s)
     /* ftwdt010 */
     sysbus_create_simple("ftwdt010", 0x92200000, s->pic[46]);
     qemu_register_reset(a369soc_system_reset, s);
+
+    /* ftrtc011 */
+    ds = qdev_create(NULL, "ftrtc011");
+    /* Setup QOM path for QTest */
+    object_property_add_child(OBJECT(s),
+                              "ftrtc011",
+                              OBJECT(ds),
+                              NULL);
+    qdev_init_nofail(ds);
+    sysbus_mmio_map(SYS_BUS_DEVICE(ds), 0, 0x92100000);
+    /* Alarm (Edge) */
+    sysbus_connect_irq(SYS_BUS_DEVICE(ds), 1, s->pic[42]);
+    /* Second (Edge) */
+    sysbus_connect_irq(SYS_BUS_DEVICE(ds), 2, s->pic[43]);
+    /* Minute (Edge) */
+    sysbus_connect_irq(SYS_BUS_DEVICE(ds), 3, s->pic[44]);
+    /* Hour (Edge) */
+    sysbus_connect_irq(SYS_BUS_DEVICE(ds), 4, s->pic[45]);
 }
 
 static void a369soc_realize(DeviceState *dev, Error **errp)
hw/arm/ftrtc011.c new file +383 -0

383 lines not on this page · raw message

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

53 lines not on this page · raw message

Signature · 1 line
1.7.9.5