Added 64-bit MMIO accessors for ARMv8
Subsystems (5)
PATCH v3 1/4 Added 64-bit MMIO accessors for ARMv8
From: "J. German Rivera" <[email protected]>
This is needed for accessing peripherals with 64-bit MMIO registers, from ARMv8 processors.
---
Change log:
v3: No change. The blank line mentioned in review is in the other patch.
arch/arm/include/asm/io.h | 8 ++++++++ 1 file changed, 8 insertions(+)
arch/arm/include/asm/io.h +8 -0
@@ -70,10 +70,12 @@ static inline phys_addr_t virt_to_phys(void * vaddr)#define __arch_getb (a) (*(volatile unsigned char *)(a))#define __arch_getw (a) (*(volatile unsigned short *)(a))#define __arch_getl (a) (*(volatile unsigned int *)(a)) +#define __arch_getq (a) (*(volatile unsigned long long *)(a))#define __arch_putb (v,a) (*(volatile unsigned char *)(a) = (v))#define __arch_putw (v,a) (*(volatile unsigned short *)(a) = (v))#define __arch_putl (v,a) (*(volatile unsigned int *)(a) = (v)) +#define __arch_putq (v,a) (*(volatile unsigned long long *)(a) = (v))extern inline void __raw_writesb (unsigned long addr,const void *data,int bytelen)
@@ -123,10 +125,12 @@ extern inline void __raw_readsl(unsigned long addr, void *data, int longlen)#define __raw_writeb (v,a) __arch_putb(v,a)#define __raw_writew (v,a) __arch_putw(v,a)#define __raw_writel (v,a) __arch_putl(v,a) +#define __raw_writeq (v,a) __arch_putq(v,a)#define __raw_readb (a) __arch_getb(a)#define __raw_readw (a) __arch_getw(a)#define __raw_readl (a) __arch_getl(a) +#define __raw_readq (a) __arch_getq(a)/* * TODO: The kernel offers some more advanced versions of barriers, it might
@@ -139,10 +143,12 @@ extern inline void __raw_readsl(unsigned long addr, void *data, int longlen)#define writeb (v,c) ({ u8 __v = v; __iowmb(); __arch_putb(__v,c); __v; })#define writew (v,c) ({ u16 __v = v; __iowmb(); __arch_putw(__v,c); __v; })#define writel (v,c) ({ u32 __v = v; __iowmb(); __arch_putl(__v,c); __v; }) +#define writeq (v,c) ({ u64 __v = v; __iowmb(); __arch_putq(__v,c); __v; })#define readb (c) ({ u8 __v = __arch_getb(c); __iormb(); __v; })#define readw (c) ({ u16 __v = __arch_getw(c); __iormb(); __v; })#define readl (c) ({ u32 __v = __arch_getl(c); __iormb(); __v; }) +#define readq (c) ({ u64 __v = __arch_getq(c); __iormb(); __v; })/* * The compiler seems to be incapable of optimising constants
@@ -168,9 +174,11 @@ extern inline void __raw_readsl(unsigned long addr, void *data, int longlen)#define out_arch (type,endian,a,v) __raw_write##type(cpu_to_##endian(v),a)#define in_arch (type,endian,a) endian##_to_cpu(__raw_read##type(a)) +#define out_le64 (a,v) out_arch(q,le64,a,v)#define out_le32 (a,v) out_arch(l,le32,a,v)#define out_le16 (a,v) out_arch(w,le16,a,v) +#define in_le64 (a) in_arch(q,le64,a)#define in_le32 (a) in_arch(l,le32,a)#define in_le16 (a) in_arch(w,le16,a)
Signature · 1 line
1.7.9.5
PATCH v3 2/4 ARMv8/FSL_LSCH3: Add FSL_LSCH3 SoC
Freescale LayerScape with Chassis Generation 3 is a set of SoCs with ARMv8 cores and 3rd generation of Chassis. We use different MMU setup to support memory map and cache attribute for these SoCs. MMU and cache are enabled very early to bootst performance, especially for early development on emulators. After u-boot relocates to DDR, a new MMU table with QBMan cache access is created in DDR. SMMU pagesize is set in SMMU_sACR register. Both DDR3 and DDR4 are supported.
---
Change log:
v3: Remove blank lines at the of files
Fix cluster PLL GSR register for accessing beyond array size Update final MMU table to support QBMan memory with cache Set SMMU pagesize in SMMU_sACR register in lowlevel init. Add DDR4 support
Remove forcing L3 cache flusing
Update GICv3 redistributor base address
Some of these changes are caused by model change.
arch/arm/cpu/armv8/cache_v8.c | 7 +- arch/arm/cpu/armv8/fsl-lsch3/Makefile | 10 + arch/arm/cpu/armv8/fsl-lsch3/README | 10 + arch/arm/cpu/armv8/fsl-lsch3/cpu.c | 474 +++++++++++++++++++++ arch/arm/cpu/armv8/fsl-lsch3/cpu.h | 7 + arch/arm/cpu/armv8/fsl-lsch3/lowlevel.S | 65 +++ arch/arm/cpu/armv8/fsl-lsch3/speed.c | 176 ++++++++ arch/arm/cpu/armv8/fsl-lsch3/speed.h | 7 + arch/arm/cpu/armv8/fsl-lsch3/timer.c | 62 +++ arch/arm/include/asm/arch-fsl-lsch3/clock.h | 23 + arch/arm/include/asm/arch-fsl-lsch3/config.h | 65 +++ arch/arm/include/asm/arch-fsl-lsch3/gpio.h | 9 + arch/arm/include/asm/arch-fsl-lsch3/immap_lsch3.h | 116 +++++ arch/arm/include/asm/arch-fsl-lsch3/imx-regs.h | 13 + arch/arm/include/asm/arch-fsl-lsch3/mmu.h | 10 + arch/arm/include/asm/config.h | 4 + arch/arm/include/asm/system.h | 2 + drivers/i2c/mxc_i2c.c | 5 + include/common.h | 5 +- 19 files changed, 1066 insertions(+), 4 deletions(-) create mode 100644 arch/arm/cpu/armv8/fsl-lsch3/Makefile create mode 100644 arch/arm/cpu/armv8/fsl-lsch3/README create mode 100644 arch/arm/cpu/armv8/fsl-lsch3/cpu.c create mode 100644 arch/arm/cpu/armv8/fsl-lsch3/cpu.h create mode 100644 arch/arm/cpu/armv8/fsl-lsch3/lowlevel.S create mode 100644 arch/arm/cpu/armv8/fsl-lsch3/speed.c create mode 100644 arch/arm/cpu/armv8/fsl-lsch3/speed.h create mode 100644 arch/arm/cpu/armv8/fsl-lsch3/timer.c create mode 100644 arch/arm/include/asm/arch-fsl-lsch3/clock.h create mode 100644 arch/arm/include/asm/arch-fsl-lsch3/config.h create mode 100644 arch/arm/include/asm/arch-fsl-lsch3/gpio.h create mode 100644 arch/arm/include/asm/arch-fsl-lsch3/immap_lsch3.h create mode 100644 arch/arm/include/asm/arch-fsl-lsch3/imx-regs.h create mode 100644 arch/arm/include/asm/arch-fsl-lsch3/mmu.h
arch/arm/cpu/armv8/cache_v8.c +6 -1
@@ -83,12 +83,17 @@ void invalidate_dcache_all(void)__asm_invalidate_dcache_all (); } +void __weak flush_l3_cache (void ) +{ +} +/* * Performs a clean & invalidation of the entire data cache at all levels */ void flush_dcache_all (void ) {__asm_flush_dcache_all (); +flush_l3_cache (); }/*
@@ -221,7 +226,7 @@ void invalidate_icache_all(void)* Enable dCache & iCache, whether cache is actually enabled * depend on CONFIG_SYS_DCACHE_OFF and CONFIG_SYS_ICACHE_OFF */ -void enable_caches (void ) +void __weak enable_caches (void ) {icache_enable ();dcache_enable ();
arch/arm/cpu/armv8/fsl-lsch3/Makefile new file +10 -0
@@ -0,0 +1,10 @@ +# +# Copyright 2014, Freescale Semiconductor +# +# SPDX-License-Identifier: GPL-2.0+ +# + +obj-y += cpu.o +obj-y += timer.o +obj-y += lowlevel.o +obj-y += speed.o
arch/arm/cpu/armv8/fsl-lsch3/README new file +10 -0
@@ -0,0 +1,10 @@ +# +# Copyright 2014 Freescale Semiconductor +# +# SPDX-License-Identifier: GPL-2.0+ +# + +Freescale LayerScape with Chassis Generation 3 + +This architecture supports Freescale ARMv8 SoCs with Chassis generation 3, +for example LS2100A.
arch/arm/cpu/armv8/fsl-lsch3/cpu.c new file +474 -0
474 lines not on this page · raw message
arch/arm/cpu/armv8/fsl-lsch3/cpu.h new file +7 -0
@@ -0,0 +1,7 @@ +/* +* Copyright 2014, Freescale Semiconductor +* +* SPDX-License-Identifier: GPL-2.0+ +*/ + +int fsl_qoriq_core_to_cluster (unsigned int core);
arch/arm/cpu/armv8/fsl-lsch3/lowlevel.S new file +65 -0
65 lines not on this page · raw message
arch/arm/cpu/armv8/fsl-lsch3/speed.c new file +176 -0
176 lines not on this page · raw message
arch/arm/cpu/armv8/fsl-lsch3/speed.h new file +7 -0
@@ -0,0 +1,7 @@ +/* +* Copyright 2014, Freescale Semiconductor, Inc. +* +* SPDX-License-Identifier: GPL-2.0+ +*/ + +void get_sys_info (struct sys_info *sys_info);
arch/arm/cpu/armv8/fsl-lsch3/timer.c new file +62 -0
62 lines not on this page · raw message
arch/arm/include/asm/arch-fsl-lsch3/clock.h new file +23 -0
@@ -0,0 +1,23 @@ +/* +* Copyright 2014 Freescale Semiconductor, Inc. +* +* SPDX-License-Identifier: GPL-2.0+ +* +*/ + +#ifndef __ASM_ARCH_FSL_LSCH3_CLOCK_H_ +#define __ASM_ARCH_FSL_LSCH3_CLOCK_H_ + +#include <common.h> + +enum mxc_clock { +MXC_ARM_CLK =0 , +MXC_BUS_CLK , +MXC_UART_CLK , +MXC_ESDHC_CLK , +MXC_I2C_CLK , +}; + +unsigned int mxc_get_clock (enum mxc_clock clk); + +#endif /* __ASM_ARCH_FSL_LSCH3_CLOCK_H_ */
arch/arm/include/asm/arch-fsl-lsch3/config.h new file +65 -0
65 lines not on this page · raw message
arch/arm/include/asm/arch-fsl-lsch3/gpio.h new file +9 -0
@@ -0,0 +1,9 @@ +/* +* Copyright 2014, Freescale Semiconductor +* +* SPDX-License-Identifier: GPL-2.0+ +*/ + +#ifndef _ASM_ARMV8_FSL_LSCH3_GPIO_H_ +#define _ASM_ARMV8_FSL_LSCH3_GPIO_H_ +#endif /* _ASM_ARMV8_FSL_LSCH3_GPIO_H_ */
arch/arm/include/asm/arch-fsl-lsch3/immap_lsch3.h new file +116 -0
116 lines not on this page · raw message
arch/arm/include/asm/arch-fsl-lsch3/imx-regs.h new file +13 -0
@@ -0,0 +1,13 @@ +/* +* Copyright 2014 Freescale Semiconductor, Inc. +* +* SPDX-License-Identifier: GPL-2.0+ +* +*/ + +#ifndef __ASM_ARCH_FSL_LSCH3_IMX_REGS_H_ +#define __ASM_ARCH_FSL_LSCH3_IMX_REGS_H_ + +#define I2C_QUIRK_REG /* enable 8-bit driver */ + +#endif /* __ASM_ARCH_FSL_LSCH3_IMX_REGS_H_ */
arch/arm/include/asm/arch-fsl-lsch3/mmu.h new file +10 -0
@@ -0,0 +1,10 @@ +/* +* Copyright 2014, Freescale Semiconductor +* +* SPDX-License-Identifier: GPL-2.0+ +*/ + +#ifndef _ASM_ARMV8_FSL_LSCH3_MMU_H_ +#define _ASM_ARMV8_FSL_LSCH3_MMU_H_ +#include <asm/arch-armv8/mmu.h> +#endif /* _ASM_ARMV8_FSL_LSCH3_MMU_H_ */
arch/arm/include/asm/config.h +4 -0
@@ -17,4 +17,8 @@#define CONFIG_STATIC_RELA #endif +#ifdef CONFIG_FSL_LSCH3 +#include <asm/arch-fsl-lsch3/config.h> +#endif +#endif
arch/arm/include/asm/system.h +2 -0
@@ -78,6 +78,8 @@ void gic_send_sgi(unsigned long sgino);void wait_for_wakeup (void );void smp_kick_all_cpus (void ); +void flush_l3_cache (void ); +#endif /* __ASSEMBLY__ */ #else /* CONFIG_ARM64 */
drivers/i2c/mxc_i2c.c +5 -0
@@ -429,6 +429,11 @@ static void * const i2c_bases[] = { (void *)I2C3_BASE_ADDR#elif defined(CONFIG_VF610 ) (void *)I2C0_BASE_ADDR +#elif defined(CONFIG_FSL_LSCH3 ) + (void *)I2C1_BASE_ADDR , + (void *)I2C2_BASE_ADDR , + (void *)I2C3_BASE_ADDR , + (void *)I2C4_BASE_ADDR#else #error "architecture not supported"#endif
include/common.h +2 -3
@@ -693,9 +693,6 @@ ulong get_PERCLK3(void);ulong get_bus_freq (ulong );int get_serial_clock (void ); -#if defined(CONFIG_MPC83xx) || defined(CONFIG_MPC85xx) -ulong get_ddr_freq (ulong ); -#endif #if defined(CONFIG_MPC85xx)typedef MPC85xx_SYS_INFO sys_info_t ;void get_sys_info (sys_info_t * );
@@ -711,6 +708,8 @@ static inline ulong get_ddr_freq(ulong dummy) {return get_bus_freq (dummy); } +#else +ulong get_ddr_freq (ulong );#endif #if defined(CONFIG_4xx)
Signature · 1 line
1.7.9.5
PATCH v3 3/4 armv8/fsl-lsch3: Add support to load and start MC Firmware
In reply to York SunFrom: "J. German Rivera" <[email protected]>
Adding supoort to load and start the Layerscape Management Complex (MC) firmware. First, the MC GCR register is set to 0 to reset all cores. MC firmware and DPL images are copied from their location in NOR flash to DDR. MC registers are updated with the location of these images. Deasserting the reset bit of MC GCR register releases core 0 to run. Core 1 will be released by MC firmware. Stop bits are not touched for this step. U-boot waits for MC until it boots up. In case of a failure, device tree is updated accordingly. The MC firmware image uses FIT format.
---
Change log:
v3: Add error detection and update device tree if failure
Revise loading address to avoid overlap
Use FIT image for the firmware
Remove blank lines at the end of files
README | 27 ++++ arch/arm/cpu/armv8/fsl-lsch3/cpu.c | 11 ++ drivers/net/Makefile | 1 + drivers/net/fsl_mc/Makefile | 8 ++ drivers/net/fsl_mc/mc.c | 274 ++++++++++++++++++++++++++++++++++++ include/fdt_support.h | 14 +- include/fsl_mc.h | 59 ++++++++ 7 files changed, 391 insertions(+), 3 deletions(-) create mode 100644 drivers/net/fsl_mc/Makefile create mode 100644 drivers/net/fsl_mc/mc.c create mode 100644 include/fsl_mc.h
README +27 -0
@@ -4640,6 +4640,33 @@ within that device. window->master inbound window->master LAW->the ucode address in master's memory space. +Freescale Layerscape Management Complex Firmware Support: +--------------------------------------------------------- +The Freescale Layerscape Management Complex (MC) supports the loading of +"firmware". +This firmware often needs to be loaded during U-Boot booting, so macros +are used to identify the storage device (NOR flash, SPI, etc) and the address +within that device. + +- CONFIG_FSL_MC_ENET + Enable the MC driver for Layerscape SoCs. + +- CONFIG_SYS_LS_MC_FW_ADDR + The address in the storage device where the firmware is located. The + meaning of this address depends on which CONFIG_SYS_LS_MC_FW_IN_xxx macro + is also specified. + +- CONFIG_SYS_LS_MC_FW_LENGTH + The maximum possible size of the firmware. The firmware binary format + has a field that specifies the actual size of the firmware, but it + might not be possible to read any part of the firmware unless some + local storage is allocated to hold the entire firmware first. + +- CONFIG_SYS_LS_MC_FW_IN_NOR + Specifies that MC firmware is located in NOR flash, mapped as + normal addressable memory via the LBC. CONFIG_SYS_LS_MC_FW_ADDR is the + virtual address in NOR flash. + Building the Software: ======================
arch/arm/cpu/armv8/fsl-lsch3/cpu.c +11 -0
@@ -12,6 +12,7 @@#include <asm/arch-fsl-lsch3/immap_lsch3.h> #include "cpu.h" #include "speed.h" +#include <fsl_mc.h> DECLARE_GLOBAL_DATA_PTR ;
@@ -472,3 +473,13 @@ int print_cpuinfo(void) return 0; }#endif + +int cpu_eth_init (bd_t *bis) +{ +int error =0 ; + +#ifdef CONFIG_FSL_MC_ENET + error =mc_init (bis); +#endif +return error; +}
drivers/net/Makefile +1 -0
@@ -64,3 +64,4 @@ obj-$(CONFIG_XILINX_EMACLITE) += xilinx_emaclite.o obj-$(CONFIG_XILINX_LL_TEMAC) += xilinx_ll_temac.o xilinx_ll_temac_mdio.o \ xilinx_ll_temac_fifo.o xilinx_ll_temac_sdma.o obj-$(CONFIG_ZYNQ_GEM) += zynq_gem.o +obj-$(CONFIG_FSL_MC_ENET) += fsl_mc/
drivers/net/fsl_mc/Makefile new file +8 -0
@@ -0,0 +1,8 @@ +# +# Copyright 2014 Freescale Semiconductor, Inc. +# +# SPDX-License-Identifier: GPL-2.0+ +# + +# Layerscape MC driver +obj-y += mc.o
drivers/net/fsl_mc/mc.c new file +274 -0
274 lines not on this page · raw message
include/fdt_support.h +11 -3
@@ -113,17 +113,25 @@ static inline int fdt_status_disabled(void *fdt, int nodeoffset) {return fdt_set_node_status (fdt, nodeoffset,FDT_STATUS_DISABLED ,0 ); } +static inline int fdt_status_fail (void *fdt,int nodeoffset) +{ +return fdt_set_node_status (fdt, nodeoffset,FDT_STATUS_FAIL ,0 ); +} -int fdt_set_status_by_alias (void *fdt,const char * alias, +int fdt_set_status_by_alias (void *fdt,const char *alias,enum fdt_status status,unsigned int error_code); -static inline int fdt_status_okay_by_alias (void *fdt,const char * alias) +static inline int fdt_status_okay_by_alias (void *fdt,const char *alias) {return fdt_set_status_by_alias (fdt, alias,FDT_STATUS_OKAY ,0 ); } -static inline int fdt_status_disabled_by_alias (void *fdt,const char * alias) +static inline int fdt_status_disabled_by_alias (void *fdt,const char *alias) {return fdt_set_status_by_alias (fdt, alias,FDT_STATUS_DISABLED ,0 ); } +static inline int fdt_status_fail_by_alias (void *fdt,const char *alias) +{ +return fdt_set_status_by_alias (fdt, alias,FDT_STATUS_FAIL ,0 ); +}#endif /* ifdef CONFIG_OF_LIBFDT */
include/fsl_mc.h new file +59 -0
59 lines not on this page · raw message
Signature · 1 line
1.7.9.5
PATCH v3 4/4 ARMv8/ls2100a_emu: Add LS2100A emulator and simulator board support
In reply to York SunLS2100A is an ARMv8 implementation. This adds board support for emulator and simulator:
Two DDR controllers
UART2 is used as the console
IFC timing is tightened for speedy booting
Support DDR3 and DDR4 as separated targets
Management Complex (MC) is enabled
---
Change log:
v3: Add support for DDR4 target and simulator target
Squash Manage complex patch (previous 5/5) into this
Reserve last 512MB memory for MC use
Change MC firmware location in NOR flash
Fix UART clock source speed
Update IFC address mux
Use generic board
Disable DDR memory beyound 39 physical address space due to Linux limitation
Some of these changes are caused by model changing.
board/freescale/ls2100a/Makefile | 8 ++ board/freescale/ls2100a/README | 16 +++ board/freescale/ls2100a/ddr.c | 175 ++++++++++++++++++++++++++++ board/freescale/ls2100a/ddr.h | 57 ++++++++++ board/freescale/ls2100a/ls2100a.c | 100 ++++++++++++++++ boards.cfg | 3 + include/configs/ls2100a_common.h | 226 +++++++++++++++++++++++++++++++++++++ include/configs/ls2100a_emu.h | 19 ++++ include/configs/ls2100a_simu.h | 16 +++ 9 files changed, 620 insertions(+) create mode 100644 board/freescale/ls2100a/Makefile create mode 100644 board/freescale/ls2100a/README create mode 100644 board/freescale/ls2100a/ddr.c create mode 100644 board/freescale/ls2100a/ddr.h create mode 100644 board/freescale/ls2100a/ls2100a.c create mode 100644 include/configs/ls2100a_common.h create mode 100644 include/configs/ls2100a_emu.h create mode 100644 include/configs/ls2100a_simu.h
board/freescale/ls2100a/Makefile new file +8 -0
@@ -0,0 +1,8 @@ +# +# Copyright 2014 Freescale Semiconductor +# +# SPDX-License-Identifier: GPL-2.0+ +# + +obj-y += ls2100a.o +obj-y += ddr.o
board/freescale/ls2100a/README new file +16 -0
@@ -0,0 +1,16 @@ +Freescale ls2100a_emu + +This is a emulator target with limited peripherals. + +Memory map from core's view + +0x00_0000_0000 .. 0x00_000F_FFFF Boot Rom +0x00_0100_0000 .. 0x00_0FFF_FFFF CCSR +0x00_1800_0000 .. 0x00_181F_FFFF OCRAM +0x00_3000_0000 .. 0x00_3FFF_FFFF IFC region #1 +0x00_8000_0000 .. 0x00_FFFF_FFFF DDR region #1 +0x05_1000_0000 .. 0x05_FFFF_FFFF IFC region #2 +0x80_8000_0000 .. 0xFF_FFFF_FFFF DDR region #2 + +Other addresses are either reserved, or not used directly by u-boot. +This list should be updated when more addresses are used.
board/freescale/ls2100a/ddr.c new file +175 -0
175 lines not on this page · raw message
board/freescale/ls2100a/ddr.h new file +57 -0
57 lines not on this page · raw message
board/freescale/ls2100a/ls2100a.c new file +100 -0
100 lines not on this page · raw message
boards.cfg +3 -0
@@ -44,6 +44,9 @@ ########################################################################################################### Active aarch64 armv8 - armltd vexpress64 vexpress_aemv8a vexpress_aemv8a:ARM64 David Feng <[email protected]> +Active aarch64 armv8 fsl-lsch3 freescale ls2100a ls2100a_emu ls2100a_emu:ARM64,EMU York Sun <[email protected]> +Active aarch64 armv8 fsl-lsch3 freescale ls2100a ls2100a_emu_D4 ls2100a_emu:ARM64,EMU,SYS_FSL_DDR4 York Sun <[email protected]> +Active aarch64 armv8 fsl-lsch3 freescale ls2100a ls2100a_simu ls2100a_simu:ARM64,SIMU York Sun <[email protected]> Active arc arc700 - synopsys - axs101 - Alexey Brodkin <[email protected]> Active arc arc700 - synopsys <none> arcangel4 - Alexey Brodkin <[email protected]> Active arc arc700 - synopsys <none> arcangel4-be - Alexey Brodkin <[email protected]>
include/configs/ls2100a_common.h new file +226 -0
226 lines not on this page · raw message
include/configs/ls2100a_emu.h new file +19 -0
@@ -0,0 +1,19 @@ +/* +* Copyright 2014 Freescale Semiconductor +* +* SPDX-License-Identifier: GPL-2.0+ +*/ + +#ifndef __LS2_EMU_H +#define __LS2_EMU_H + +#include "ls2100a_common.h" + +#define CONFIG_DDR_SPD +#define CONFIG_SYS_FSL_DDR_EMU /* Support emulator */ +#define SPD_EEPROM_ADDRESS1 0x51 +#define SPD_EEPROM_ADDRESS2 0x52 +#define SPD_EEPROM_ADDRESS SPD_EEPROM_ADDRESS1 +#define CONFIG_SYS_SPD_BUS_NUM 1/* SPD on I2C bus 1 */ + +#endif /* __LS2_EMU_H */
include/configs/ls2100a_simu.h new file +16 -0
@@ -0,0 +1,16 @@ +/* +* Copyright (C) 2014 Freescale Semiconductor +* +* SPDX-License-Identifier: GPL-2.0+ +*/ + +#ifndef __LS2_SIMU_H +#define __LS2_SIMU_H + +#include "ls2100a_common.h" + +/* SMSC 91C111 ethernet configuration */ +#define CONFIG_SMC91111 +#define CONFIG_SMC91111_BASE (0x2210000) + +#endif /* __LS2_SIMU_H */
Signature · 1 line
1.7.9.5
PATCH v3 2/4 ARMv8/FSL_LSCH3: Add FSL_LSCH3 SoC
In reply to York SunQuoted 196 lines · York Sun
Freescale LayerScape with Chassis Generation 3 is a set of SoCs with ARMv8 cores and 3rd generation of Chassis. We use different MMU setup to support memory map and cache attribute for these SoCs. MMU and cache are enabled very early to bootst performance, especially for early development on emulators. After u-boot relocates to DDR, a new MMU table with QBMan cache access is created in DDR. SMMU pagesize is set in
SMMU_sACRregister. Both DDR3 and DDR4 are supported.Signed-off-by York Sun <[email protected]>Signed-off-by Varun Sethi <[email protected]>Signed-off-by Arnab Basu <[email protected]>---
Change log:
v3: Remove blank lines at the of files
Fix cluster PLL GSR register for accessing beyond array size Update final MMU table to support QBMan memory with cache Set SMMU pagesize inSMMU_sACRregister in lowlevel init. Add DDR4 support
Remove forcing L3 cache flusing
Update GICv3 redistributor base addressSome of these changes are caused by model change.
arch/arm/cpu/armv8/cache_v8.c | 7 +- arch/arm/cpu/armv8/fsl-lsch3/Makefile | 10 + arch/arm/cpu/armv8/fsl-lsch3/README | 10 + arch/arm/cpu/armv8/fsl-lsch3/cpu.c | 474 +++++++++++++++++++++ arch/arm/cpu/armv8/fsl-lsch3/cpu.h | 7 + arch/arm/cpu/armv8/fsl-lsch3/lowlevel.S | 65 +++ arch/arm/cpu/armv8/fsl-lsch3/speed.c | 176 ++++++++ arch/arm/cpu/armv8/fsl-lsch3/speed.h | 7 + arch/arm/cpu/armv8/fsl-lsch3/timer.c | 62 +++ arch/arm/include/asm/arch-fsl-lsch3/clock.h | 23 + arch/arm/include/asm/arch-fsl-lsch3/config.h | 65 +++ arch/arm/include/asm/arch-fsl-lsch3/gpio.h | 9 + arch/arm/include/asm/arch-fsl-lsch3/immap_lsch3.h | 116 +++++ arch/arm/include/asm/arch-fsl-lsch3/imx-regs.h | 13 + arch/arm/include/asm/arch-fsl-lsch3/mmu.h | 10 + arch/arm/include/asm/config.h | 4 + arch/arm/include/asm/system.h | 2 + drivers/i2c/mxc_i2c.c | 5 + include/common.h | 5 +- 19 files changed, 1066 insertions(+), 4 deletions(-) create mode 100644 arch/arm/cpu/armv8/fsl-lsch3/Makefile create mode 100644 arch/arm/cpu/armv8/fsl-lsch3/README create mode 100644 arch/arm/cpu/armv8/fsl-lsch3/cpu.c create mode 100644 arch/arm/cpu/armv8/fsl-lsch3/cpu.h create mode 100644 arch/arm/cpu/armv8/fsl-lsch3/lowlevel.S create mode 100644 arch/arm/cpu/armv8/fsl-lsch3/speed.c create mode 100644 arch/arm/cpu/armv8/fsl-lsch3/speed.h create mode 100644 arch/arm/cpu/armv8/fsl-lsch3/timer.c create mode 100644 arch/arm/include/asm/arch-fsl-lsch3/clock.h create mode 100644 arch/arm/include/asm/arch-fsl-lsch3/config.h create mode 100644 arch/arm/include/asm/arch-fsl-lsch3/gpio.h create mode 100644 arch/arm/include/asm/arch-fsl-lsch3/immap_lsch3.h create mode 100644 arch/arm/include/asm/arch-fsl-lsch3/imx-regs.h create mode 100644 arch/arm/include/asm/arch-fsl-lsch3/mmu.harch/arm/cpu/armv8/cache_v8.c +6
-1@@ -83,12 +83,17 @@ void invalidate_dcache_all(void)__asm_invalidate_dcache_all (); } +void __weak flush_l3_cache (void ) +{ +} +/* * Performs a clean & invalidation of the entire data cache at all levels */ void flush_dcache_all (void ) {__asm_flush_dcache_all (); +flush_l3_cache (); }/* @@ -221,7 +226,7 @@ void invalidate_icache_all(void)* Enable dCache & iCache, whether cache is actually enabled * depend on CONFIG_SYS_DCACHE_OFF and CONFIG_SYS_ICACHE_OFF */ -void enable_caches (void ) +void __weak enable_caches (void ) {icache_enable ();dcache_enable ();arch/arm/cpu/armv8/fsl-lsch3/Makefile new file +10
-0@@ -0,0 +1,10 @@ +# +# Copyright 2014, Freescale Semiconductor +# +# SPDX-License-Identifier: GPL-2.0+ +# + +obj-y += cpu.o +obj-y += timer.o +obj-y += lowlevel.o +obj-y += speed.oarch/arm/cpu/armv8/fsl-lsch3/README new file +10
-0@@ -0,0 +1,10 @@ +# +# Copyright 2014 Freescale Semiconductor +# +# SPDX-License-Identifier: GPL-2.0+ +# + +Freescale LayerScape with Chassis Generation 3 + +This architecture supports Freescale ARMv8 SoCs with Chassis generation 3, +for example LS2100A.arch/arm/cpu/armv8/fsl-lsch3/cpu.c new file +69
-0@@ -0,0 +1,474 @@ +/* +* Copyright 2014 Freescale Semiconductor, Inc. +* +* SPDX-License-Identifier: GPL-2.0+ +*/ + +#include <common.h> +#include <asm/io.h> +#include <asm/system.h> +#include <asm/armv8/mmu.h> +#include <asm/io.h> +#include <asm/arch-fsl-lsch3/immap_lsch3.h> +#include "cpu.h" +#include "speed.h" + +DECLARE_GLOBAL_DATA_PTR ; + +#ifndef CONFIG_SYS_DCACHE_OFF +/* +* To start MMU before DDR is available, we create MMU table in SRAM. +* The base address of SRAM is CONFIG_SYS_FSL_OCRAM_BASE. We use three +* levels of translation tables here to cover 40-bit address space. +* We use 4KB granule size, with 40 bits physical address, T0SZ=24 +* Level 0 IA[39], table address @0 +* Level 1 IA[31:30], table address @01000, 0x2000 +* Level 2 IA[29:21], table address @0x3000 +*/ + +#define EARLY_SECTION_SHIFT_L0 39UL +#define EARLY_SECTION_SHIFT_L1 30UL +#define EARLY_SECTION_SHIFT_L2 21UL +#define EARLY_BLOCK_SIZE_L0 0x8000000000UL +#define EARLY_BLOCK_SIZE_L1 (1 << EARLY_SECTION_SHIFT_L1) +#define EARLY_BLOCK_SIZE_L2 (1 << EARLY_SECTION_SHIFT_L2) +#define CONFIG_SYS_IFC_BASE 0x30000000 +#define CONFIG_SYS_IFC_SIZE 0x10000000 +#define CONFIG_SYS_IFC_BASE2 0x500000000 +#define CONFIG_SYS_IFC_SIZE2 0x100000000 +#define TCR_EL2_PS_40BIT (2 << 16) +#define EARLY_VA_BITS (40) +#define EARLY_TCR (TCR_TG0_4K | \ + TCR_EL2_PS_40BIT | \ + TCR_SHARED_NON | \ + TCR_ORGN_NC | \ + TCR_IRGN_NC | \ + TCR_T0SZ(EARLY_VA_BITS)) + +/* +* Final MMU +* Let's start from the same layout as early MMU and modify as needed. +* IFC regions will be cache-inhibit. +*/ +#define FINAL_SECTION_SHIFT_L0 39UL +#define FINAL_SECTION_SHIFT_L1 30UL +#define FINAL_SECTION_SHIFT_L2 21UL +#define FINAL_BLOCK_SIZE_L0 0x8000000000UL +#define FINAL_BLOCK_SIZE_L1 (1 << FINAL_SECTION_SHIFT_L1) +#define FINAL_BLOCK_SIZE_L2 (1 << FINAL_SECTION_SHIFT_L2) +#define FINAL_QBMAN_CACHED_MEM 0x818000000UL +#define FINAL_QBMAN_CACHED_SIZE 0x4000000 +#define TCR_EL2_PS_40BIT (2 << 16) +#define FINAL_VA_BITS (40) +#define FINAL_TCR (TCR_TG0_4K | \ + TCR_EL2_PS_40BIT | \ + TCR_SHARED_NON | \ + TCR_ORGN_NC | \ + TCR_IRGN_NC | \ + TCR_T0SZ(FINAL_VA_BITS)) +
arch/arm/cpu/armv8/fsl-lsch3/cpu.c line 79
Quoted 10 lines
arch/arm/cpu/armv8/fsl-lsch3/cpu.c new file +10
-0+ +static void set_pgtable_section (u64 *page_table,u64 index,u64 section, +u8 memory_type) +{ +u64 value; + + value = section |PMD_TYPE_SECT |PMD_SECT_AF ; + value |=PMD_ATTRINDX (memory_type); + page_table[index] = value; +}
This function looks like it should be common.
Quoted 53 lines
arch/arm/cpu/armv8/fsl-lsch3/cpu.c new file +53
-0+ +static inline void early_mmu_setup (void ) +{ +int el; +u64 i; +u64 section_l1t0, section_l1t1, section_l2; +u64 *level0_table = (u64 *)CONFIG_SYS_FSL_OCRAM_BASE ; +u64 *level1_table_0 = (u64 *)(CONFIG_SYS_FSL_OCRAM_BASE +0x1000 ); +u64 *level1_table_1 = (u64 *)(CONFIG_SYS_FSL_OCRAM_BASE +0x2000 ); +u64 *level2_table = (u64 *)(CONFIG_SYS_FSL_OCRAM_BASE +0x3000 ); + + + level0_table[0 ] = + (u64 )level1_table_0 |PMD_TYPE_TABLE ; + level0_table[1 ] = + (u64 )level1_table_1 |PMD_TYPE_TABLE ; + +/* +* set level 1 table 0 to cache_inhibit, covering 0 to 512GB +* set level 1 table 1 to cache enabled, covering 512GB to 1TB +* set level 2 table to cache-inhibit, covering 0 to 1GB +*/ + section_l1t0 =0 ; + section_l1t1 =EARLY_BLOCK_SIZE_L0 ; + section_l2 =0 ; +for (i =0 ; i <512 ; i++) { +set_pgtable_section (level1_table_0, i, section_l1t0, +MT_DEVICE_NGNRNE ); +set_pgtable_section (level1_table_1, i, section_l1t1, +MT_NORMAL ); +set_pgtable_section (level2_table, i, section_l2, +MT_DEVICE_NGNRNE ); + section_l1t0 +=EARLY_BLOCK_SIZE_L1 ; + section_l1t1 +=EARLY_BLOCK_SIZE_L1 ; + section_l2 +=EARLY_BLOCK_SIZE_L2 ; + } + + level1_table_0[0 ] = + (u64 )level2_table |PMD_TYPE_TABLE ; + level1_table_0[1 ] = +0x40000000 |PMD_SECT_AF |PMD_TYPE_SECT | +PMD_ATTRINDX (MT_DEVICE_NGNRNE ); + level1_table_0[2 ] = +0x80000000 |PMD_SECT_AF |PMD_TYPE_SECT | +PMD_ATTRINDX (MT_NORMAL ); + level1_table_0[3 ] = +0xc0000000 |PMD_SECT_AF |PMD_TYPE_SECT | +PMD_ATTRINDX (MT_NORMAL ); + +/* Rewrite table to enable cache */ + set_pgtable_section(level2_table, + CONFIG_SYS_FSL_OCRAM_BASE >> EARLY_SECTION_SHIFT_L2, + CONFIG_SYS_FSL_OCRAM_BASE,
arch/arm/cpu/armv8/fsl-lsch3/cpu.c line 142
Quoted 10 lines
arch/arm/cpu/armv8/fsl-lsch3/cpu.c new file +10
-0+ MT_NORMAL); +for (i =CONFIG_SYS_IFC_BASE >>EARLY_SECTION_SHIFT_L2 ; + i < (CONFIG_SYS_IFC_BASE +CONFIG_SYS_IFC_SIZE ) + >>EARLY_SECTION_SHIFT_L2 ; i++) { + section_l2 = i <<EARLY_SECTION_SHIFT_L2 ; +set_pgtable_section (level2_table, i, + section_l2,MT_NORMAL ); + } + + el =current_el ();
We really can't have u-boot running at random ELs in v8 for different platforms. It's a mess on v7. You should never be at EL3. u-boot could be defined to run at EL1, but then you need to be able to go back to EL2 to boot the kernel. So really u-boot should always run at EL2 unless you are running in a VM, but that would be a different platform.
arch/arm/cpu/armv8/fsl-lsch3/cpu.c line 150
Quoted 8 lines
arch/arm/cpu/armv8/fsl-lsch3/cpu.c new file +8
-0+if (el ==1 ) { + asmvolatile ("dsb sy;isb" ); + asmvolatile ("msr ttbr0_el1, %0" + : :"r" ((u64 )level0_table) :"memory" ); + asmvolatile ("msr tcr_el1, %0" + : :"r" (EARLY_TCR ) :"memory" ); + asmvolatile ("msr mair_el1, %0" + : :"r" (MEMORY_ATTRIBUTES ) :"memory" );
These should all be inline functions or macros.
Quoted 14 lines
arch/arm/cpu/armv8/fsl-lsch3/cpu.c new file +14
-0+ }else if (el ==2 ) { + asmvolatile ("dsb sy;isb" ); + asmvolatile ("msr ttbr0_el2, %0" + : :"r" ((u64 )level0_table) :"memory" ); + asmvolatile ("msr tcr_el2, %0" + : :"r" (EARLY_TCR ) :"memory" ); + asmvolatile ("msr mair_el2, %0" + : :"r" (MEMORY_ATTRIBUTES ) :"memory" ); + }else if (el ==3 ) { + asmvolatile ("dsb sy;isb" ); + asmvolatile ("msr ttbr0_el3, %0" + : :"r" ((u64 )level0_table) :"memory" ); + asmvolatile ("msr tcr_el3, %0" + : :"r" (EARLY_TCR ) :"memory" );
arch/arm/cpu/armv8/fsl-lsch3/cpu.c line 174
Quoted 10 lines
arch/arm/cpu/armv8/fsl-lsch3/cpu.c new file +10
-0+ asmvolatile ("msr mair_el3, %0" + : :"r" (MEMORY_ATTRIBUTES ) :"memory" ); + }else { +hang (); + } + +set_sctlr (get_sctlr () |CR_M ); +} + +static inline void final_mmu_setup (void )
Looks like nearly the same code repeated...
Quoted 111 lines
arch/arm/cpu/armv8/fsl-lsch3/cpu.c new file +111
-0+{ +int el; +u64 i, tbl_base, tbl_limit, section_base; +u64 section_l1t0, section_l1t1, section_l2; +u64 *level0_table = (u64 *)gd->arch.tlb_addr; +u64 *level1_table_0 = (u64 *)(gd->arch.tlb_addr +0x1000 ); +u64 *level1_table_1 = (u64 *)(gd->arch.tlb_addr +0x2000 ); +u64 *level2_table_0 = (u64 *)(gd->arch.tlb_addr +0x3000 ); +u64 *level2_table_1 = (u64 *)(gd->arch.tlb_addr +0x4000 ); + + + level0_table[0 ] = + (u64 )level1_table_0 |PMD_TYPE_TABLE ; + level0_table[1 ] = + (u64 )level1_table_1 |PMD_TYPE_TABLE ; + +/* +* set level 1 table 0 to cache_inhibit, covering 0 to 512GB +* set level 1 table 1 to cache enabled, covering 512GB to 1TB +* set level 2 table 0 to cache-inhibit, covering 0 to 1GB +*/ + section_l1t0 =0 ; + section_l1t1 =FINAL_BLOCK_SIZE_L0 ; + section_l2 =0 ; +for (i =0 ; i <512 ; i++) { +set_pgtable_section (level1_table_0, i, section_l1t0, +MT_DEVICE_NGNRNE ); +set_pgtable_section (level1_table_1, i, section_l1t1, +MT_NORMAL ); +set_pgtable_section (level2_table_0, i, section_l2, +MT_DEVICE_NGNRNE ); + section_l1t0 +=FINAL_BLOCK_SIZE_L1 ; + section_l1t1 +=FINAL_BLOCK_SIZE_L1 ; + section_l2 +=FINAL_BLOCK_SIZE_L2 ; + } + + level1_table_0[0 ] = + (u64 )level2_table_0 |PMD_TYPE_TABLE ; + level1_table_0[2 ] = +0x80000000 |PMD_SECT_AF |PMD_TYPE_SECT | +PMD_ATTRINDX (MT_NORMAL ); + level1_table_0[3 ] = +0xc0000000 |PMD_SECT_AF |PMD_TYPE_SECT | +PMD_ATTRINDX (MT_NORMAL ); + +/* Rewrite table to enable cache */ +set_pgtable_section (level2_table_0, +CONFIG_SYS_FSL_OCRAM_BASE >>FINAL_SECTION_SHIFT_L2 , +CONFIG_SYS_FSL_OCRAM_BASE , +MT_NORMAL ); + +/* +* Fill in other part of tables if cache is needed +* If finer granularity than 1GB is needed, sub table +* should be created. +*/ + section_base =FINAL_QBMAN_CACHED_MEM & ~(FINAL_BLOCK_SIZE_L1 -1 ); + i = section_base >>FINAL_SECTION_SHIFT_L1 ; + level1_table_0[i] = (u64 )level2_table_1 |PMD_TYPE_TABLE ; + section_l2 = section_base; +for (i =0 ; i <512 ; i++) { +set_pgtable_section (level2_table_1, i, section_l2, +MT_DEVICE_NGNRNE ); + section_l2 +=FINAL_BLOCK_SIZE_L2 ; + } + tbl_base =FINAL_QBMAN_CACHED_MEM & (FINAL_BLOCK_SIZE_L1 -1 ); + tbl_limit = (FINAL_QBMAN_CACHED_MEM +FINAL_QBMAN_CACHED_SIZE ) & + (FINAL_BLOCK_SIZE_L1 -1 ); +for (i = tbl_base >>FINAL_SECTION_SHIFT_L2 ; + i < tbl_limit >>FINAL_SECTION_SHIFT_L2 ; i++) { + section_l2 = section_base + (i <<FINAL_SECTION_SHIFT_L2 ); +set_pgtable_section (level2_table_1, i, + section_l2,MT_NORMAL ); + } + + el =current_el (); +if (el ==1 ) { + asmvolatile ("dsb sy;isb" ); + asmvolatile ("msr ttbr0_el1, %0" + : :"r" ((u64 )level0_table) :"memory" ); + asmvolatile ("msr tcr_el1, %0" + : :"r" (FINAL_TCR ) :"memory" ); + asmvolatile ("msr mair_el1, %0" + : :"r" (MEMORY_ATTRIBUTES ) :"memory" ); + }else if (el ==2 ) { + asmvolatile ("dsb sy;isb" ); + asmvolatile ("msr ttbr0_el2, %0" + : :"r" ((u64 )level0_table) :"memory" ); + asmvolatile ("msr tcr_el2, %0" + : :"r" (FINAL_TCR ) :"memory" ); + asmvolatile ("msr mair_el2, %0" + : :"r" (MEMORY_ATTRIBUTES ) :"memory" ); + }else if (el ==3 ) { + asmvolatile ("dsb sy;isb" ); + asmvolatile ("msr ttbr0_el3, %0" + : :"r" ((u64 )level0_table) :"memory" ); + asmvolatile ("msr tcr_el3, %0" + : :"r" (FINAL_TCR ) :"memory" ); + asmvolatile ("msr mair_el3, %0" + : :"r" (MEMORY_ATTRIBUTES ) :"memory" ); + }else { +hang (); + } + +set_sctlr (get_sctlr () |CR_M ); +} + +int arch_cpu_init (void ) +{ +icache_enable (); +__asm_invalidate_dcache_all ();
arch/arm/cpu/armv8/fsl-lsch3/cpu.c line 295
Quoted 10 lines
arch/arm/cpu/armv8/fsl-lsch3/cpu.c new file +10
-0+__asm_invalidate_tlb_all (); +early_mmu_setup (); +set_sctlr (get_sctlr () |CR_C ); +return 0 ; +} + +/* +* flush_l3_cache +* Dickens L3 cache can be flushed by transitioning from FAM to SFONLY power +* state, by writing to HP-F P-state request register.
Other SOCs will have Dickens. Are these registers FSL specific? If not, this should be common.
Also, I believe the proper way to flush Dickens is using the architected cache flushing method where you walk the levels out to level 3.
Quoted 52 lines
arch/arm/cpu/armv8/fsl-lsch3/cpu.c new file +52
-0+*/ +#define HNF0_PSTATE_REQ 0x04200010 +#define HNF1_PSTATE_REQ 0x04210010 +#define HNF2_PSTATE_REQ 0x04220010 +#define HNF3_PSTATE_REQ 0x04230010 +#define HNF4_PSTATE_REQ 0x04240010 +#define HNF5_PSTATE_REQ 0x04250010 +#define HNF6_PSTATE_REQ 0x04260010 +#define HNF7_PSTATE_REQ 0x04270010 +#define HNFPSTAT_MASK (0xFFFFFFFFFFFFFFFC) +#define HNFPSTAT_FAM 0x3 +#define HNFPSTAT_SFONLY 0x01 + +static void hnf_pstate_req (u64 *ptr,u64 state) +{ +int timeout =1000 ; +out_le64 (ptr, (in_le64 (ptr) &HNFPSTAT_MASK ) | (state &0x3 )); + ptr++; +/* checking if the transition is completed */ +while (timeout >0 ) { +if (((in_le64 (ptr) &0x0c ) >>2 ) == (state &0x3 )) +break ; +udelay (100 ); + timeout--; + } +} + +void flush_l3_cache (void ) +{ +hnf_pstate_req ((u64 *)HNF0_PSTATE_REQ ,HNFPSTAT_SFONLY ); +hnf_pstate_req ((u64 *)HNF1_PSTATE_REQ ,HNFPSTAT_SFONLY ); +hnf_pstate_req ((u64 *)HNF2_PSTATE_REQ ,HNFPSTAT_SFONLY ); +hnf_pstate_req ((u64 *)HNF3_PSTATE_REQ ,HNFPSTAT_SFONLY ); +hnf_pstate_req ((u64 *)HNF4_PSTATE_REQ ,HNFPSTAT_SFONLY ); +hnf_pstate_req ((u64 *)HNF5_PSTATE_REQ ,HNFPSTAT_SFONLY ); +hnf_pstate_req ((u64 *)HNF6_PSTATE_REQ ,HNFPSTAT_SFONLY ); +hnf_pstate_req ((u64 *)HNF7_PSTATE_REQ ,HNFPSTAT_SFONLY ); +hnf_pstate_req ((u64 *)HNF0_PSTATE_REQ ,HNFPSTAT_FAM ); +hnf_pstate_req ((u64 *)HNF1_PSTATE_REQ ,HNFPSTAT_FAM ); +hnf_pstate_req ((u64 *)HNF2_PSTATE_REQ ,HNFPSTAT_FAM ); +hnf_pstate_req ((u64 *)HNF3_PSTATE_REQ ,HNFPSTAT_FAM ); +hnf_pstate_req ((u64 *)HNF4_PSTATE_REQ ,HNFPSTAT_FAM ); +hnf_pstate_req ((u64 *)HNF5_PSTATE_REQ ,HNFPSTAT_FAM ); +hnf_pstate_req ((u64 *)HNF6_PSTATE_REQ ,HNFPSTAT_FAM ); +hnf_pstate_req ((u64 *)HNF7_PSTATE_REQ ,HNFPSTAT_FAM ); +} + +/* +* This function is called from lib/board.c. +* It recreates MMU table in main memory. MMU and d-cache are enabled earlier. +* There is no need to disable d-cache for this operation. +*/
arch/arm/cpu/armv8/fsl-lsch3/cpu.c line 357
Quoted 10 lines
arch/arm/cpu/armv8/fsl-lsch3/cpu.c new file +10
-0+void enable_caches (void ) +{ +final_mmu_setup (); +flush_dcache_range (gd->arch.tlb_addr, + gd->arch.tlb_addr + gd->arch.tlb_size); +__asm_invalidate_tlb_all (); +} +#endif + +static inline u32 init_type (u32 cluster,int init_id)
init_type? That's a great name.
Quoted 78 lines
arch/arm/cpu/armv8/fsl-lsch3/cpu.c new file +78
-0+{ +struct ccsr_gur *gur = (void *)(CONFIG_SYS_FSL_GUTS_ADDR ); +u32 idx = (cluster >> (init_id *8 )) &TP_CLUSTER_INIT_MASK ; +u32 type =in_le32 (&gur->tp_ityp[idx]); + +if (type &TP_ITYP_AV ) +return type; + +return 0 ; +} + +u32 cpu_mask (void ) +{ +struct ccsr_gur __iomem *gur = (void *)(CONFIG_SYS_FSL_GUTS_ADDR ); +int i =0 , count =0 ; +u32 cluster, type, mask =0 ; + +do { +int j; + cluster =in_le32 (&gur->tp_cluster[i].lower); +for (j =0 ; j <TP_INIT_PER_CLUSTER ; j++) { + type =init_type (cluster, j); +if (type) { +if (TP_ITYP_TYPE (type) ==TP_ITYP_TYPE_ARM ) + mask |=1 << count; + count++; + } + } + i++; + }while ((cluster &TP_CLUSTER_EOC ) !=TP_CLUSTER_EOC ); + +return mask; +} + +/* +* Return the number of cores on this SOC. +*/ +int cpu_numcores (void ) +{ +return hweight32 (cpu_mask ()); +} + +int fsl_qoriq_core_to_cluster (unsigned int core) +{ +struct ccsr_gur __iomem *gur = + (void __iomem *)(CONFIG_SYS_FSL_GUTS_ADDR ); +int i =0 , count =0 ; +u32 cluster; + +do { +int j; + cluster =in_le32 (&gur->tp_cluster[i].lower); +for (j =0 ; j <TP_INIT_PER_CLUSTER ; j++) { +if (init_type (cluster, j)) { +if (count == core) +return i; + count++; + } + } + i++; + }while ((cluster &TP_CLUSTER_EOC ) !=TP_CLUSTER_EOC ); + +return -1 ;/* cannot identify the cluster */ +} + +u32 fsl_qoriq_core_to_type (unsigned int core) +{ +struct ccsr_gur __iomem *gur = + (void __iomem *)(CONFIG_SYS_FSL_GUTS_ADDR ); +int i =0 , count =0 ; +u32 cluster, type; + + do { + int j; + cluster = in_le32(&gur->tp_cluster[i].lower); + for (j = 0; j < TP_INIT_PER_CLUSTER; j++) { + type = init_type(cluster, j); + if (type) {
arch/arm/cpu/armv8/fsl-lsch3/cpu.c line 445
Quoted 10 lines
arch/arm/cpu/armv8/fsl-lsch3/cpu.c new file +10
-0+if (count == core) +return type; + count++; + } + } + i++; + }while ((cluster &TP_CLUSTER_EOC ) !=TP_CLUSTER_EOC ); + +return -1 ;/* cannot identify the cluster */ +}
Do you plan on supporting PSCI because all this core and cluster stuff belongs there.
Quoted 61 lines
arch/arm/cpu/armv8/fsl-lsch3/cpu.c new file +29
-0+ +#ifdef CONFIG_DISPLAY_CPUINFO +int print_cpuinfo (void ) +{ +struct sys_info sysinfo; +char buf[32 ]; +unsigned int i, core; +u32 type; + +get_sys_info (&sysinfo); +puts ("Clock Configuration:" ); +for_each_cpu (i, core,cpu_numcores (),cpu_mask ()) { +if (!(i %3 )) +puts ("\n " ); + type =TP_ITYP_VER (fsl_qoriq_core_to_type (core)); +printf ("CPU%d(%s):%-4s MHz " , core, + type ==TY_ITYP_VER_A7 ?"A7 " : + (type ==TY_ITYP_VER_A53 ?"A53" : + (type ==TY_ITYP_VER_A57 ?"A57" :" " )), +strmhz (buf, sysinfo.freq_processor[core])); + } +printf ("\n Bus: %-4s MHz " , +strmhz (buf, sysinfo.freq_systembus)); +printf ("DDR: %-4s MHz" ,strmhz (buf, sysinfo.freq_ddrbus)); +puts ("\n" ); + +return 0 ; +} +#endif arch/arm/cpu/armv8/fsl-lsch3/cpu.h new file +7
-0@@ -0,0 +1,7 @@ +/* +* Copyright 2014, Freescale Semiconductor +* +* SPDX-License-Identifier: GPL-2.0+ +*/ + +int fsl_qoriq_core_to_cluster (unsigned int core);arch/arm/cpu/armv8/fsl-lsch3/lowlevel.S new file +13
-0@@ -0,0 +1,65 @@ +/* + * (C) Copyright 2014 Freescale Semiconductor + * + * SPDX-License-Identifier: GPL-2.0+ + * + * Extracted from armv8/start.S + */ + +#include <config.h> +#include <linux/linkage.h> +#include <asm/macro.h> + +ENTRY(lowlevel_init)
arch/arm/cpu/armv8/fsl-lsch3/lowlevel.S line 23
Quoted 10 lines
arch/arm/cpu/armv8/fsl-lsch3/lowlevel.S new file +10
-0+ /* Initialize GIC Secure Bank Status */ + mov x29, lr /* Save LR */ + + /* Set the SMMU page size in the sACR register */ + ldr x1, =SMMU_BASE + ldr w0, [x1, #0x10] + orr w0, w0, #1 << 16 /* set sACR.pagesize to indicate 64K page */ + str w0, [x1, #0x10] + +#if defined(CONFIG_GICV2) || defined(CONFIG_GICV3)
You can have either v2 or v3?
Quoted 26 lines
arch/arm/cpu/armv8/fsl-lsch3/lowlevel.S new file +26
-0+ branch_if_slave x0, 1f + ldr x0, =GICD_BASE + bl gic_init_secure +1: +#if defined(CONFIG_GICV3) + ldr x0, =GICR_BASE + bl gic_init_secure_percpu +#elif defined(CONFIG_GICV2) + ldr x0, =GICD_BASE + ldr x1, =GICC_BASE + bl gic_init_secure_percpu +#endif +#endif + + branch_if_master x0, x1, 1f + + /* + * Slave should wait for master clearing spin table. + * This sync prevent salves observing incorrect + * value of spin table and jumping to wrong place. + */ +#if defined(CONFIG_GICV2) || defined(CONFIG_GICV3) +#ifdef CONFIG_GICV2 + ldr x0, =GICC_BASE +#endif + bl gic_wait_for_interrupt
arch/arm/cpu/armv8/fsl-lsch3/lowlevel.S line 59
Quoted 10 lines
arch/arm/cpu/armv8/fsl-lsch3/lowlevel.S new file +10
-0+#endif + + /* + * All processors will enter EL2 and optionally EL1. + */ + bl armv8_switch_to_el2 +#ifdef CONFIG_ARMV8_SWITCH_TO_EL1 + bl armv8_switch_to_el1 +#endif + b 2f
This all looks like cut and paste from existing startup code. Can't you refactor things?
Quoted 259 lines
arch/arm/cpu/armv8/fsl-lsch3/lowlevel.S new file +6
-0+ +1: +2: + mov lr, x29 /* Restore LR */ + ret +ENDPROC(lowlevel_init)arch/arm/cpu/armv8/fsl-lsch3/speed.c new file +176
-0@@ -0,0 +1,176 @@ +/* +* Copyright 2014, Freescale Semiconductor, Inc. +* +* SPDX-License-Identifier: GPL-2.0+ +* +* Derived from arch/power/cpu/mpc85xx/speed.c +*/ + +#include <common.h> +#include <linux/compiler.h> +#include <fsl_ifc.h> +#include <asm/processor.h> +#include <asm/io.h> +#include <asm/arch-fsl-lsch3/immap_lsch3.h> +#include <asm/arch/clock.h> +#include "cpu.h" + +DECLARE_GLOBAL_DATA_PTR ; + +#ifndef CONFIG_SYS_FSL_NUM_CC_PLLS +#define CONFIG_SYS_FSL_NUM_CC_PLLS 6 +#endif + + +void get_sys_info (struct sys_info *sys_info) +{ +struct ccsr_gur __iomem *gur = (void *)(CONFIG_SYS_FSL_GUTS_ADDR ); +#ifdef CONFIG_FSL_IFC +struct fsl_ifc *ifc_regs = (void *)CONFIG_SYS_IFC_ADDR ; +u32 ccr; +#endif +struct ccsr_clk_cluster_group __iomem *clk_grp[2 ] = { + (void *)(CONFIG_SYS_FSL_CH3_CLK_GRPA_ADDR ), + (void *)(CONFIG_SYS_FSL_CH3_CLK_GRPB_ADDR ) + }; +struct ccsr_clk_ctrl __iomem *clk_ctrl = + (void *)(CONFIG_SYS_FSL_CH3_CLK_CTRL_ADDR ); +unsigned int cpu; +const u8 core_cplx_pll[16 ] = { + [0 ] =0 ,/* CC1 PPL / 1 */ + [1 ] =0 ,/* CC1 PPL / 2 */ + [2 ] =0 ,/* CC1 PPL / 4 */ + [4 ] =1 ,/* CC2 PPL / 1 */ + [5 ] =1 ,/* CC2 PPL / 2 */ + [6 ] =1 ,/* CC2 PPL / 4 */ + [8 ] =2 ,/* CC3 PPL / 1 */ + [9 ] =2 ,/* CC3 PPL / 2 */ + [10 ] =2 ,/* CC3 PPL / 4 */ + [12 ] =3 ,/* CC4 PPL / 1 */ + [13 ] =3 ,/* CC4 PPL / 2 */ + [14 ] =3 ,/* CC4 PPL / 4 */ + }; + +const u8 core_cplx_pll_div[16 ] = { + [0 ] =1 ,/* CC1 PPL / 1 */ + [1 ] =2 ,/* CC1 PPL / 2 */ + [2 ] =4 ,/* CC1 PPL / 4 */ + [4 ] =1 ,/* CC2 PPL / 1 */ + [5 ] =2 ,/* CC2 PPL / 2 */ + [6 ] =4 ,/* CC2 PPL / 4 */ + [8 ] =1 ,/* CC3 PPL / 1 */ + [9 ] =2 ,/* CC3 PPL / 2 */ + [10 ] =4 ,/* CC3 PPL / 4 */ + [12 ] =1 ,/* CC4 PPL / 1 */ + [13 ] =2 ,/* CC4 PPL / 2 */ + [14 ] =4 ,/* CC4 PPL / 4 */ + }; + +uint i, cluster; +uint freq_c_pll[CONFIG_SYS_FSL_NUM_CC_PLLS ]; +uint ratio[CONFIG_SYS_FSL_NUM_CC_PLLS ]; +unsigned long sysclk =CONFIG_SYS_CLK_FREQ ; +int cc_group[12 ] =CONFIG_SYS_FSL_CLUSTER_CLOCKS ; +u32 c_pll_sel, cplx_pll; +void *offset; + + sys_info->freq_systembus = sysclk; +#ifdef CONFIG_DDR_CLK_FREQ + sys_info->freq_ddrbus =CONFIG_DDR_CLK_FREQ ; +#else + sys_info->freq_ddrbus = sysclk; +#endif + + sys_info->freq_systembus *= (in_le32 (&gur->rcwsr[0 ]) >> +FSL_CHASSIS3_RCWSR0_SYS_PLL_RAT_SHIFT ) & +FSL_CHASSIS3_RCWSR0_SYS_PLL_RAT_MASK ; + sys_info->freq_ddrbus *= (in_le32 (&gur->rcwsr[0 ]) >> +FSL_CHASSIS3_RCWSR0_MEM_PLL_RAT_SHIFT ) & +FSL_CHASSIS3_RCWSR0_MEM_PLL_RAT_MASK ; + +for (i =0 ; i <CONFIG_SYS_FSL_NUM_CC_PLLS ; i++) { +/* +* fixme: prefer to combine the following into one line, but +* cannot pass compiling without warning about in_le32. +*/ + offset = (void *)((size_t )clk_grp[i/3 ] + + offsetof(struct ccsr_clk_cluster_group , + pllngsr[i%3].gsr)); + ratio[i] = (in_le32 (offset) >>1 ) &0x3f ; +if (ratio[i] >4 ) + freq_c_pll[i] = sysclk * ratio[i]; +else + freq_c_pll[i] = sys_info->freq_systembus * ratio[i]; + } + +for_each_cpu (i, cpu,cpu_numcores (),cpu_mask ()) { + cluster =fsl_qoriq_core_to_cluster (cpu); + c_pll_sel = (in_le32 (&clk_ctrl->clkcncsr[cluster].csr) >>27 ) + &0xf ; + cplx_pll = core_cplx_pll[c_pll_sel]; + cplx_pll += cc_group[cluster] -1 ; + sys_info->freq_processor[cpu] = + freq_c_pll[cplx_pll] / core_cplx_pll_div[c_pll_sel]; + } + +#if defined(CONFIG_FSL_IFC ) + ccr =in_le32 (&ifc_regs->ifc_ccr); + ccr = ((ccr &IFC_CCR_CLK_DIV_MASK ) >>IFC_CCR_CLK_DIV_SHIFT ) +1 ; + + sys_info->freq_localbus = sys_info->freq_systembus / ccr; +#endif +} + + +int get_clocks (void ) +{ +struct sys_info sys_info; +get_sys_info (&sys_info); + gd->cpu_clk = sys_info.freq_processor[0 ]; + gd->bus_clk = sys_info.freq_systembus; + gd->mem_clk = sys_info.freq_ddrbus; + +#if defined(CONFIG_FSL_ESDHC ) + gd->arch.sdhc_clk = gd->bus_clk /2 ; +#endif /* defined(CONFIG_FSL_ESDHC) */ + +if (gd->cpu_clk !=0 ) +return 0 ; +else +return 1 ; +} + +/******************************************** +* get_bus_freq +* return system bus freq in Hz +*********************************************/ +ulong get_bus_freq (ulong dummy) +{ +if (!gd->bus_clk) +get_clocks (); + +return gd->bus_clk; +} + +/******************************************** +* get_ddr_freq +* return ddr bus freq in Hz +*********************************************/ +ulong get_ddr_freq (ulong dummy) +{ +if (!gd->mem_clk) +get_clocks (); + +return gd->mem_clk; +} + +unsigned int mxc_get_clock (enum mxc_clock clk) +{ +switch (clk) { +case MXC_I2C_CLK : +return get_bus_freq (0 ) /2 ; +default : +printf ("Unsupported clock\n" ); + } +return 0 ; +}arch/arm/cpu/armv8/fsl-lsch3/speed.h new file +7
-0@@ -0,0 +1,7 @@ +/* +* Copyright 2014, Freescale Semiconductor, Inc. +* +* SPDX-License-Identifier: GPL-2.0+ +*/ + +void get_sys_info (struct sys_info *sys_info);arch/arm/cpu/armv8/fsl-lsch3/timer.c new file +52
-0@@ -0,0 +1,62 @@ +/* +* Copyright 2014, Freescale Semiconductor +* +* SPDX-License-Identifier: GPL-2.0+ +*/ + +#include <common.h> +#include <div64.h> +#include <linux/compiler.h> + +static inline u64 get_cntfrq (void ) +{ +u64 cntfrq; + asmvolatile ("mrs %0, cntfrq_el0" :"=r" (cntfrq)); +return cntfrq; +} + +static inline u64 tick_to_time (u64 tick) +{ + tick *=CONFIG_SYS_HZ ; +do_div (tick,get_cntfrq ()); +return tick; +} + +static inline u64 time_to_tick (u64 time) +{ + time *=get_cntfrq (); +do_div (time,CONFIG_SYS_HZ ); +return time; +} + +static inline u64 us_to_tick (unsigned long long usec) +{ + usec = usec *get_cntfrq () +999999 ; +do_div (usec,1000000 ); + +return usec; +} + +u64 get_ticks (void ) +{ +u64 cval; + + asmvolatile ("isb;mrs %0, cntpct_el0" :"=r" (cval)); + +return cval; +} + +ulong get_timer (ulong base) +{ +return tick_to_time (get_ticks ()) - base; +}
arch/arm/cpu/armv8/fsl-lsch3/timer.c line 62
Quoted 10 lines
arch/arm/cpu/armv8/fsl-lsch3/timer.c new file +10
-0+ +void __udelay (unsigned long usec) +{ +u64 start, tmo; + + start =get_ticks (); + tmo =us_to_tick (usec); +while (get_ticks () < (start + tmo)) + ; +}
What's wrong with the existing arch timer code?
Rob
PATCH v3 2/4 ARMv8/FSL_LSCH3: Add FSL_LSCH3 SoC
Quoted 1 line · Rob Herring
On Wed, May 28, 2014 at 6:46 PM, York Sun <[email protected]> wrote:
<snip>
Quoted 12 lines
arch/arm/cpu/armv8/fsl-lsch3/cpu.c line 79
Quoted 9 lines
arch/arm/cpu/armv8/fsl-lsch3/cpu.c new file +9
-0+static void set_pgtable_section (u64 *page_table,u64 index,u64 section, +u8 memory_type) +{ +u64 value; + + value = section |PMD_TYPE_SECT |PMD_SECT_AF ; + value |=PMD_ATTRINDX (memory_type); + page_table[index] = value; +}This function looks like it should be common.
There is a common version in arch/arm/cpu/armv8/cache_v8.c. This version has more flexibility. I am not sure which one will be used as common.
Quoted 62 lines
Quoted 62 lines
arch/arm/cpu/armv8/fsl-lsch3/cpu.c new file +62
-0+ +static inline void early_mmu_setup (void ) +{ +int el; +u64 i; +u64 section_l1t0, section_l1t1, section_l2; +u64 *level0_table = (u64 *)CONFIG_SYS_FSL_OCRAM_BASE ; +u64 *level1_table_0 = (u64 *)(CONFIG_SYS_FSL_OCRAM_BASE +0x1000 ); +u64 *level1_table_1 = (u64 *)(CONFIG_SYS_FSL_OCRAM_BASE +0x2000 ); +u64 *level2_table = (u64 *)(CONFIG_SYS_FSL_OCRAM_BASE +0x3000 ); + + + level0_table[0 ] = + (u64 )level1_table_0 |PMD_TYPE_TABLE ; + level0_table[1 ] = + (u64 )level1_table_1 |PMD_TYPE_TABLE ; + +/* +* set level 1 table 0 to cache_inhibit, covering 0 to 512GB +* set level 1 table 1 to cache enabled, covering 512GB to 1TB +* set level 2 table to cache-inhibit, covering 0 to 1GB +*/ + section_l1t0 =0 ; + section_l1t1 =EARLY_BLOCK_SIZE_L0 ; + section_l2 =0 ; +for (i =0 ; i <512 ; i++) { +set_pgtable_section (level1_table_0, i, section_l1t0, +MT_DEVICE_NGNRNE ); +set_pgtable_section (level1_table_1, i, section_l1t1, +MT_NORMAL ); +set_pgtable_section (level2_table, i, section_l2, +MT_DEVICE_NGNRNE ); + section_l1t0 +=EARLY_BLOCK_SIZE_L1 ; + section_l1t1 +=EARLY_BLOCK_SIZE_L1 ; + section_l2 +=EARLY_BLOCK_SIZE_L2 ; + } + + level1_table_0[0 ] = + (u64 )level2_table |PMD_TYPE_TABLE ; + level1_table_0[1 ] = +0x40000000 |PMD_SECT_AF |PMD_TYPE_SECT | +PMD_ATTRINDX (MT_DEVICE_NGNRNE ); + level1_table_0[2 ] = +0x80000000 |PMD_SECT_AF |PMD_TYPE_SECT | +PMD_ATTRINDX (MT_NORMAL ); + level1_table_0[3 ] = +0xc0000000 |PMD_SECT_AF |PMD_TYPE_SECT | +PMD_ATTRINDX (MT_NORMAL ); + +/* Rewrite table to enable cache */ +set_pgtable_section (level2_table, +CONFIG_SYS_FSL_OCRAM_BASE >>EARLY_SECTION_SHIFT_L2 , +CONFIG_SYS_FSL_OCRAM_BASE , +MT_NORMAL ); +for (i =CONFIG_SYS_IFC_BASE >>EARLY_SECTION_SHIFT_L2 ; + i < (CONFIG_SYS_IFC_BASE +CONFIG_SYS_IFC_SIZE ) + >>EARLY_SECTION_SHIFT_L2 ; i++) { + section_l2 = i <<EARLY_SECTION_SHIFT_L2 ; +set_pgtable_section (level2_table, i, + section_l2,MT_NORMAL ); + } +
Quoted 8 lines
Quoted 1 line
+ el =
current_el();We really can't have u-boot running at random ELs in v8 for different platforms. It's a mess on v7. You should never be at EL3. u-boot could be defined to run at EL1, but then you need to be able to go back to EL2 to boot the kernel. So really u-boot should always run at EL2 unless you are running in a VM, but that would be a different platform.
I have to run u-boot at EL3. Otherwise I can't access Dickens. I vaguely remember other reasons. I will have to dig it out if needed.
Quoted 11 lines
arch/arm/cpu/armv8/fsl-lsch3/cpu.c line 150
Quoted 9 lines
arch/arm/cpu/armv8/fsl-lsch3/cpu.c new file +8
-0+if (el ==1 ) { + asmvolatile ("dsb sy;isb" ); + asmvolatile ("msr ttbr0_el1, %0" + : :"r" ((u64 )level0_table) :"memory" ); + asmvolatile ("msr tcr_el1, %0" + : :"r" (EARLY_TCR ) :"memory" ); + asmvolatile ("msr mair_el1, %0" + : :"r" (MEMORY_ATTRIBUTES ) :"memory" );These should all be inline functions or macros.
Sure.
Quoted 19 lines
Quoted 19 lines
arch/arm/cpu/armv8/fsl-lsch3/cpu.c new file +18
-0+ }else if (el ==2 ) { + asmvolatile ("dsb sy;isb" ); + asmvolatile ("msr ttbr0_el2, %0" + : :"r" ((u64 )level0_table) :"memory" ); + asmvolatile ("msr tcr_el2, %0" + : :"r" (EARLY_TCR ) :"memory" ); + asmvolatile ("msr mair_el2, %0" + : :"r" (MEMORY_ATTRIBUTES ) :"memory" ); + }else if (el ==3 ) { + asmvolatile ("dsb sy;isb" ); + asmvolatile ("msr ttbr0_el3, %0" + : :"r" ((u64 )level0_table) :"memory" ); + asmvolatile ("msr tcr_el3, %0" + : :"r" (EARLY_TCR ) :"memory" ); + asmvolatile ("msr mair_el3, %0" + : :"r" (MEMORY_ATTRIBUTES ) :"memory" ); + }else { +hang ();
Quoted 8 lines
arch/arm/cpu/armv8/fsl-lsch3/cpu.c line 174
Quoted 6 lines
arch/arm/cpu/armv8/fsl-lsch3/cpu.c new file +6
-0+ } + +set_sctlr (get_sctlr () |CR_M ); +} + +static inline void final_mmu_setup (void )Looks like nearly the same code repeated...
It is similar but different. The final_mmu_setup has different content in the table. I can reorganize to use as much common code as possible.
Quoted 117 lines
Quoted 117 lines
arch/arm/cpu/armv8/fsl-lsch3/cpu.c new file +116
-0+{ +int el; +u64 i, tbl_base, tbl_limit, section_base; +u64 section_l1t0, section_l1t1, section_l2; +u64 *level0_table = (u64 *)gd->arch.tlb_addr; +u64 *level1_table_0 = (u64 *)(gd->arch.tlb_addr +0x1000 ); +u64 *level1_table_1 = (u64 *)(gd->arch.tlb_addr +0x2000 ); +u64 *level2_table_0 = (u64 *)(gd->arch.tlb_addr +0x3000 ); +u64 *level2_table_1 = (u64 *)(gd->arch.tlb_addr +0x4000 ); + + + level0_table[0 ] = + (u64 )level1_table_0 |PMD_TYPE_TABLE ; + level0_table[1 ] = + (u64 )level1_table_1 |PMD_TYPE_TABLE ; + +/* +* set level 1 table 0 to cache_inhibit, covering 0 to 512GB +* set level 1 table 1 to cache enabled, covering 512GB to 1TB +* set level 2 table 0 to cache-inhibit, covering 0 to 1GB +*/ + section_l1t0 =0 ; + section_l1t1 =FINAL_BLOCK_SIZE_L0 ; + section_l2 =0 ; +for (i =0 ; i <512 ; i++) { +set_pgtable_section (level1_table_0, i, section_l1t0, +MT_DEVICE_NGNRNE ); +set_pgtable_section (level1_table_1, i, section_l1t1, +MT_NORMAL ); +set_pgtable_section (level2_table_0, i, section_l2, +MT_DEVICE_NGNRNE ); + section_l1t0 +=FINAL_BLOCK_SIZE_L1 ; + section_l1t1 +=FINAL_BLOCK_SIZE_L1 ; + section_l2 +=FINAL_BLOCK_SIZE_L2 ; + } + + level1_table_0[0 ] = + (u64 )level2_table_0 |PMD_TYPE_TABLE ; + level1_table_0[2 ] = +0x80000000 |PMD_SECT_AF |PMD_TYPE_SECT | +PMD_ATTRINDX (MT_NORMAL ); + level1_table_0[3 ] = +0xc0000000 |PMD_SECT_AF |PMD_TYPE_SECT | +PMD_ATTRINDX (MT_NORMAL ); + +/* Rewrite table to enable cache */ +set_pgtable_section (level2_table_0, +CONFIG_SYS_FSL_OCRAM_BASE >>FINAL_SECTION_SHIFT_L2 , +CONFIG_SYS_FSL_OCRAM_BASE , +MT_NORMAL ); + +/* +* Fill in other part of tables if cache is needed +* If finer granularity than 1GB is needed, sub table +* should be created. +*/ + section_base =FINAL_QBMAN_CACHED_MEM & ~(FINAL_BLOCK_SIZE_L1 -1 ); + i = section_base >>FINAL_SECTION_SHIFT_L1 ; + level1_table_0[i] = (u64 )level2_table_1 |PMD_TYPE_TABLE ; + section_l2 = section_base; +for (i =0 ; i <512 ; i++) { +set_pgtable_section (level2_table_1, i, section_l2, +MT_DEVICE_NGNRNE ); + section_l2 +=FINAL_BLOCK_SIZE_L2 ; + } + tbl_base =FINAL_QBMAN_CACHED_MEM & (FINAL_BLOCK_SIZE_L1 -1 ); + tbl_limit = (FINAL_QBMAN_CACHED_MEM +FINAL_QBMAN_CACHED_SIZE ) & + (FINAL_BLOCK_SIZE_L1 -1 ); +for (i = tbl_base >>FINAL_SECTION_SHIFT_L2 ; + i < tbl_limit >>FINAL_SECTION_SHIFT_L2 ; i++) { + section_l2 = section_base + (i <<FINAL_SECTION_SHIFT_L2 ); +set_pgtable_section (level2_table_1, i, + section_l2,MT_NORMAL ); + } + + el =current_el (); +if (el ==1 ) { + asmvolatile ("dsb sy;isb" ); + asmvolatile ("msr ttbr0_el1, %0" + : :"r" ((u64 )level0_table) :"memory" ); + asmvolatile ("msr tcr_el1, %0" + : :"r" (FINAL_TCR ) :"memory" ); + asmvolatile ("msr mair_el1, %0" + : :"r" (MEMORY_ATTRIBUTES ) :"memory" ); + }else if (el ==2 ) { + asmvolatile ("dsb sy;isb" ); + asmvolatile ("msr ttbr0_el2, %0" + : :"r" ((u64 )level0_table) :"memory" ); + asmvolatile ("msr tcr_el2, %0" + : :"r" (FINAL_TCR ) :"memory" ); + asmvolatile ("msr mair_el2, %0" + : :"r" (MEMORY_ATTRIBUTES ) :"memory" ); + }else if (el ==3 ) { + asmvolatile ("dsb sy;isb" ); + asmvolatile ("msr ttbr0_el3, %0" + : :"r" ((u64 )level0_table) :"memory" ); + asmvolatile ("msr tcr_el3, %0" + : :"r" (FINAL_TCR ) :"memory" ); + asmvolatile ("msr mair_el3, %0" + : :"r" (MEMORY_ATTRIBUTES ) :"memory" ); + }else { +hang (); + } + +set_sctlr (get_sctlr () |CR_M ); +} + +int arch_cpu_init (void ) +{ +icache_enable (); +__asm_invalidate_dcache_all (); +__asm_invalidate_tlb_all (); +early_mmu_setup (); +set_sctlr (get_sctlr () |CR_C ); +return 0 ; +}
Quoted 8 lines
arch/arm/cpu/armv8/fsl-lsch3/cpu.c line 295
Quoted 5 lines
arch/arm/cpu/armv8/fsl-lsch3/cpu.c new file +5
-0+ +/* +* flush_l3_cache +* Dickens L3 cache can be flushed by transitioning from FAM to SFONLY power +* state, by writing to HP-F P-state request register. Other SOCs will have Dickens. Are these registers FSL specific? If not, this should be common.
I don't think they are FSL specific. But I haven't found a proper place to host it. Can you share what other SoCs have Dickens? If they are not supported yet, we can keep the code here until we are clear then move it out.
Quoted 4 lines
Also, I believe the proper way to flush Dickens is using the architected cache flushing method where you walk the levels out to level 3.
False. L3 cache gets flushed with instruction DCCIVAC. So if we flush the cache by range, it works OK. But it doesn't work with DCISW or DCCISW. If we flush cache by walking the levels, it doesn't work. We can only walk level 1 and level 2.
Quoted 57 lines
Quoted 57 lines
+ */
arch/arm/cpu/armv8/fsl-lsch3/cpu.c new file +55
-0+#define HNF0_PSTATE_REQ 0x04200010 +#define HNF1_PSTATE_REQ 0x04210010 +#define HNF2_PSTATE_REQ 0x04220010 +#define HNF3_PSTATE_REQ 0x04230010 +#define HNF4_PSTATE_REQ 0x04240010 +#define HNF5_PSTATE_REQ 0x04250010 +#define HNF6_PSTATE_REQ 0x04260010 +#define HNF7_PSTATE_REQ 0x04270010 +#define HNFPSTAT_MASK (0xFFFFFFFFFFFFFFFC) +#define HNFPSTAT_FAM 0x3 +#define HNFPSTAT_SFONLY 0x01 + +static void hnf_pstate_req (u64 *ptr,u64 state) +{ +int timeout =1000 ; +out_le64 (ptr, (in_le64 (ptr) &HNFPSTAT_MASK ) | (state &0x3 )); + ptr++; +/* checking if the transition is completed */ +while (timeout >0 ) { +if (((in_le64 (ptr) &0x0c ) >>2 ) == (state &0x3 )) +break ; +udelay (100 ); + timeout--; + } +} + +void flush_l3_cache (void ) +{ +hnf_pstate_req ((u64 *)HNF0_PSTATE_REQ ,HNFPSTAT_SFONLY ); +hnf_pstate_req ((u64 *)HNF1_PSTATE_REQ ,HNFPSTAT_SFONLY ); +hnf_pstate_req ((u64 *)HNF2_PSTATE_REQ ,HNFPSTAT_SFONLY ); +hnf_pstate_req ((u64 *)HNF3_PSTATE_REQ ,HNFPSTAT_SFONLY ); +hnf_pstate_req ((u64 *)HNF4_PSTATE_REQ ,HNFPSTAT_SFONLY ); +hnf_pstate_req ((u64 *)HNF5_PSTATE_REQ ,HNFPSTAT_SFONLY ); +hnf_pstate_req ((u64 *)HNF6_PSTATE_REQ ,HNFPSTAT_SFONLY ); +hnf_pstate_req ((u64 *)HNF7_PSTATE_REQ ,HNFPSTAT_SFONLY ); +hnf_pstate_req ((u64 *)HNF0_PSTATE_REQ ,HNFPSTAT_FAM ); +hnf_pstate_req ((u64 *)HNF1_PSTATE_REQ ,HNFPSTAT_FAM ); +hnf_pstate_req ((u64 *)HNF2_PSTATE_REQ ,HNFPSTAT_FAM ); +hnf_pstate_req ((u64 *)HNF3_PSTATE_REQ ,HNFPSTAT_FAM ); +hnf_pstate_req ((u64 *)HNF4_PSTATE_REQ ,HNFPSTAT_FAM ); +hnf_pstate_req ((u64 *)HNF5_PSTATE_REQ ,HNFPSTAT_FAM ); +hnf_pstate_req ((u64 *)HNF6_PSTATE_REQ ,HNFPSTAT_FAM ); +hnf_pstate_req ((u64 *)HNF7_PSTATE_REQ ,HNFPSTAT_FAM ); +} + +/* +* This function is called from lib/board.c. +* It recreates MMU table in main memory. MMU and d-cache are enabled earlier. +* There is no need to disable d-cache for this operation. +*/ +void enable_caches (void ) +{ +final_mmu_setup (); + flush_dcache_range(gd->arch.tlb_addr,
Quoted 8 lines
arch/arm/cpu/armv8/fsl-lsch3/cpu.c line 357
Quoted 6 lines
arch/arm/cpu/armv8/fsl-lsch3/cpu.c new file +6
-0+ gd->arch.tlb_addr + gd->arch.tlb_size); + __asm_invalidate_tlb_all(); +} +#endif + +static inline u32 init_type (u32 cluster,int init_id)
init_type? That's a great name.
That is initiator type. It is a funny name used by many FSL SoCs.
Quoted 84 lines
Quoted 84 lines
arch/arm/cpu/armv8/fsl-lsch3/cpu.c new file +83
-0+{ +struct ccsr_gur *gur = (void *)(CONFIG_SYS_FSL_GUTS_ADDR ); +u32 idx = (cluster >> (init_id *8 )) &TP_CLUSTER_INIT_MASK ; +u32 type =in_le32 (&gur->tp_ityp[idx]); + +if (type &TP_ITYP_AV ) +return type; + +return 0 ; +} + +u32 cpu_mask (void ) +{ +struct ccsr_gur __iomem *gur = (void *)(CONFIG_SYS_FSL_GUTS_ADDR ); +int i =0 , count =0 ; +u32 cluster, type, mask =0 ; + +do { +int j; + cluster =in_le32 (&gur->tp_cluster[i].lower); +for (j =0 ; j <TP_INIT_PER_CLUSTER ; j++) { + type =init_type (cluster, j); +if (type) { +if (TP_ITYP_TYPE (type) ==TP_ITYP_TYPE_ARM ) + mask |=1 << count; + count++; + } + } + i++; + }while ((cluster &TP_CLUSTER_EOC ) !=TP_CLUSTER_EOC ); + +return mask; +} + +/* +* Return the number of cores on this SOC. +*/ +int cpu_numcores (void ) +{ +return hweight32 (cpu_mask ()); +} + +int fsl_qoriq_core_to_cluster (unsigned int core) +{ +struct ccsr_gur __iomem *gur = + (void __iomem *)(CONFIG_SYS_FSL_GUTS_ADDR ); +int i =0 , count =0 ; +u32 cluster; + +do { +int j; + cluster =in_le32 (&gur->tp_cluster[i].lower); +for (j =0 ; j <TP_INIT_PER_CLUSTER ; j++) { +if (init_type (cluster, j)) { +if (count == core) +return i; + count++; + } + } + i++; + }while ((cluster &TP_CLUSTER_EOC ) !=TP_CLUSTER_EOC ); + +return -1 ;/* cannot identify the cluster */ +} + +u32 fsl_qoriq_core_to_type (unsigned int core) +{ +struct ccsr_gur __iomem *gur = + (void __iomem *)(CONFIG_SYS_FSL_GUTS_ADDR ); +int i =0 , count =0 ; +u32 cluster, type; + + do { + int j; + cluster = in_le32(&gur->tp_cluster[i].lower); + for (j = 0; j < TP_INIT_PER_CLUSTER; j++) { + type = init_type(cluster, j); + if (type) { + if (count == core) + return type; + count++; + } + }
Quoted 8 lines
arch/arm/cpu/armv8/fsl-lsch3/cpu.c line 421
Quoted 5 lines
arch/arm/cpu/armv8/fsl-lsch3/cpu.c new file +5
-0+ i++; + }while ((cluster &TP_CLUSTER_EOC ) !=TP_CLUSTER_EOC ); + +return -1 ;/* cannot identify the cluster */ +}Do you plan on supporting PSCI because all this core and cluster stuff belongs there.
What's PSCI?
This code is similar to FSL chassis generation 2 code, but it is for chassis generation 3. I plan to move it to a common place once we have another platform using chassis generation 3.
Quoted 67 lines
Quoted 67 lines
arch/arm/cpu/armv8/fsl-lsch3/cpu.c new file +29
-0+ +#ifdef CONFIG_DISPLAY_CPUINFO +int print_cpuinfo (void ) +{ +struct sys_info sysinfo; +char buf[32 ]; +unsigned int i, core; +u32 type; + +get_sys_info (&sysinfo); +puts ("Clock Configuration:" ); +for_each_cpu (i, core,cpu_numcores (),cpu_mask ()) { +if (!(i %3 )) +puts ("\n " ); + type =TP_ITYP_VER (fsl_qoriq_core_to_type (core)); +printf ("CPU%d(%s):%-4s MHz " , core, + type ==TY_ITYP_VER_A7 ?"A7 " : + (type ==TY_ITYP_VER_A53 ?"A53" : + (type ==TY_ITYP_VER_A57 ?"A57" :" " )), +strmhz (buf, sysinfo.freq_processor[core])); + } +printf ("\n Bus: %-4s MHz " , +strmhz (buf, sysinfo.freq_systembus)); +printf ("DDR: %-4s MHz" ,strmhz (buf, sysinfo.freq_ddrbus)); +puts ("\n" ); + +return 0 ; +} +#endif arch/arm/cpu/armv8/fsl-lsch3/cpu.h new file +7
-0@@ -0,0 +1,7 @@ +/* +* Copyright 2014, Freescale Semiconductor +* +* SPDX-License-Identifier: GPL-2.0+ +*/ + +int fsl_qoriq_core_to_cluster (unsigned int core);arch/arm/cpu/armv8/fsl-lsch3/lowlevel.S new file +17
-0@@ -0,0 +1,65 @@ +/* + * (C) Copyright 2014 Freescale Semiconductor + * + * SPDX-License-Identifier: GPL-2.0+ + * + * Extracted from armv8/start.S + */ + +#include <config.h> +#include <linux/linkage.h> +#include <asm/macro.h> + +ENTRY(lowlevel_init) + /* Initialize GIC Secure Bank Status */ + mov x29, lr /* Save LR */ + + /* Set the SMMU page size in the sACR register */
Quoted 8 lines
arch/arm/cpu/armv8/fsl-lsch3/lowlevel.S line 23
Quoted 6 lines
arch/arm/cpu/armv8/fsl-lsch3/lowlevel.S new file +6
-0+ ldr x1, =SMMU_BASE + ldr w0, [x1, #0x10] + orr w0, w0, #1 << 16 /* set sACR.pagesize to indicate 64K page */ + str w0, [x1, #0x10] + +#if defined(CONFIG_GICV2) || defined(CONFIG_GICV3)You can have either v2 or v3?
We do in the model. Since we don't have the final SoC yet, and I don't know how many varities will exist, I am reluctant to remove v2.
Quoted 32 lines
Quoted 32 lines
arch/arm/cpu/armv8/fsl-lsch3/lowlevel.S new file +31
-0+ branch_if_slave x0, 1f + ldr x0, =GICD_BASE + bl gic_init_secure +1: +#if defined(CONFIG_GICV3) + ldr x0, =GICR_BASE + bl gic_init_secure_percpu +#elif defined(CONFIG_GICV2) + ldr x0, =GICD_BASE + ldr x1, =GICC_BASE + bl gic_init_secure_percpu +#endif +#endif + + branch_if_master x0, x1, 1f + + /* + * Slave should wait for master clearing spin table. + * This sync prevent salves observing incorrect + * value of spin table and jumping to wrong place. + */ +#if defined(CONFIG_GICV2) || defined(CONFIG_GICV3) +#ifdef CONFIG_GICV2 + ldr x0, =GICC_BASE +#endif + bl gic_wait_for_interrupt +#endif + + /* + * All processors will enter EL2 and optionally EL1. + */
Quoted 8 lines
arch/arm/cpu/armv8/fsl-lsch3/lowlevel.S line 59
Quoted 5 lines
arch/arm/cpu/armv8/fsl-lsch3/lowlevel.S new file +5
-0+ bl armv8_switch_to_el2 +#ifdef CONFIG_ARMV8_SWITCH_TO_EL1 + bl armv8_switch_to_el1 +#endif + b 2fThis all looks like cut and paste from existing startup code. Can't you refactor things?
Right. We have added some code which only applies to this SoC. That's why the copy-n-paste then modify. I am also holding other patches which add a lot more code into this file.
Quoted 264 lines
Quoted 264 lines
arch/arm/cpu/armv8/fsl-lsch3/lowlevel.S new file +6
-0+ +1: +2: + mov lr, x29 /* Restore LR */ + ret +ENDPROC(lowlevel_init)arch/arm/cpu/armv8/fsl-lsch3/speed.c new file +176
-0@@ -0,0 +1,176 @@ +/* +* Copyright 2014, Freescale Semiconductor, Inc. +* +* SPDX-License-Identifier: GPL-2.0+ +* +* Derived from arch/power/cpu/mpc85xx/speed.c +*/ + +#include <common.h> +#include <linux/compiler.h> +#include <fsl_ifc.h> +#include <asm/processor.h> +#include <asm/io.h> +#include <asm/arch-fsl-lsch3/immap_lsch3.h> +#include <asm/arch/clock.h> +#include "cpu.h" + +DECLARE_GLOBAL_DATA_PTR ; + +#ifndef CONFIG_SYS_FSL_NUM_CC_PLLS +#define CONFIG_SYS_FSL_NUM_CC_PLLS 6 +#endif + + +void get_sys_info (struct sys_info *sys_info) +{ +struct ccsr_gur __iomem *gur = (void *)(CONFIG_SYS_FSL_GUTS_ADDR ); +#ifdef CONFIG_FSL_IFC +struct fsl_ifc *ifc_regs = (void *)CONFIG_SYS_IFC_ADDR ; +u32 ccr; +#endif +struct ccsr_clk_cluster_group __iomem *clk_grp[2 ] = { + (void *)(CONFIG_SYS_FSL_CH3_CLK_GRPA_ADDR ), + (void *)(CONFIG_SYS_FSL_CH3_CLK_GRPB_ADDR ) + }; +struct ccsr_clk_ctrl __iomem *clk_ctrl = + (void *)(CONFIG_SYS_FSL_CH3_CLK_CTRL_ADDR ); +unsigned int cpu; +const u8 core_cplx_pll[16 ] = { + [0 ] =0 ,/* CC1 PPL / 1 */ + [1 ] =0 ,/* CC1 PPL / 2 */ + [2 ] =0 ,/* CC1 PPL / 4 */ + [4 ] =1 ,/* CC2 PPL / 1 */ + [5 ] =1 ,/* CC2 PPL / 2 */ + [6 ] =1 ,/* CC2 PPL / 4 */ + [8 ] =2 ,/* CC3 PPL / 1 */ + [9 ] =2 ,/* CC3 PPL / 2 */ + [10 ] =2 ,/* CC3 PPL / 4 */ + [12 ] =3 ,/* CC4 PPL / 1 */ + [13 ] =3 ,/* CC4 PPL / 2 */ + [14 ] =3 ,/* CC4 PPL / 4 */ + }; + +const u8 core_cplx_pll_div[16 ] = { + [0 ] =1 ,/* CC1 PPL / 1 */ + [1 ] =2 ,/* CC1 PPL / 2 */ + [2 ] =4 ,/* CC1 PPL / 4 */ + [4 ] =1 ,/* CC2 PPL / 1 */ + [5 ] =2 ,/* CC2 PPL / 2 */ + [6 ] =4 ,/* CC2 PPL / 4 */ + [8 ] =1 ,/* CC3 PPL / 1 */ + [9 ] =2 ,/* CC3 PPL / 2 */ + [10 ] =4 ,/* CC3 PPL / 4 */ + [12 ] =1 ,/* CC4 PPL / 1 */ + [13 ] =2 ,/* CC4 PPL / 2 */ + [14 ] =4 ,/* CC4 PPL / 4 */ + }; + +uint i, cluster; +uint freq_c_pll[CONFIG_SYS_FSL_NUM_CC_PLLS ]; +uint ratio[CONFIG_SYS_FSL_NUM_CC_PLLS ]; +unsigned long sysclk =CONFIG_SYS_CLK_FREQ ; +int cc_group[12 ] =CONFIG_SYS_FSL_CLUSTER_CLOCKS ; +u32 c_pll_sel, cplx_pll; +void *offset; + + sys_info->freq_systembus = sysclk; +#ifdef CONFIG_DDR_CLK_FREQ + sys_info->freq_ddrbus =CONFIG_DDR_CLK_FREQ ; +#else + sys_info->freq_ddrbus = sysclk; +#endif + + sys_info->freq_systembus *= (in_le32 (&gur->rcwsr[0 ]) >> +FSL_CHASSIS3_RCWSR0_SYS_PLL_RAT_SHIFT ) & +FSL_CHASSIS3_RCWSR0_SYS_PLL_RAT_MASK ; + sys_info->freq_ddrbus *= (in_le32 (&gur->rcwsr[0 ]) >> +FSL_CHASSIS3_RCWSR0_MEM_PLL_RAT_SHIFT ) & +FSL_CHASSIS3_RCWSR0_MEM_PLL_RAT_MASK ; + +for (i =0 ; i <CONFIG_SYS_FSL_NUM_CC_PLLS ; i++) { +/* +* fixme: prefer to combine the following into one line, but +* cannot pass compiling without warning about in_le32. +*/ + offset = (void *)((size_t )clk_grp[i/3 ] + + offsetof(struct ccsr_clk_cluster_group , + pllngsr[i%3].gsr)); + ratio[i] = (in_le32 (offset) >>1 ) &0x3f ; +if (ratio[i] >4 ) + freq_c_pll[i] = sysclk * ratio[i]; +else + freq_c_pll[i] = sys_info->freq_systembus * ratio[i]; + } + +for_each_cpu (i, cpu,cpu_numcores (),cpu_mask ()) { + cluster =fsl_qoriq_core_to_cluster (cpu); + c_pll_sel = (in_le32 (&clk_ctrl->clkcncsr[cluster].csr) >>27 ) + &0xf ; + cplx_pll = core_cplx_pll[c_pll_sel]; + cplx_pll += cc_group[cluster] -1 ; + sys_info->freq_processor[cpu] = + freq_c_pll[cplx_pll] / core_cplx_pll_div[c_pll_sel]; + } + +#if defined(CONFIG_FSL_IFC ) + ccr =in_le32 (&ifc_regs->ifc_ccr); + ccr = ((ccr &IFC_CCR_CLK_DIV_MASK ) >>IFC_CCR_CLK_DIV_SHIFT ) +1 ; + + sys_info->freq_localbus = sys_info->freq_systembus / ccr; +#endif +} + + +int get_clocks (void ) +{ +struct sys_info sys_info; +get_sys_info (&sys_info); + gd->cpu_clk = sys_info.freq_processor[0 ]; + gd->bus_clk = sys_info.freq_systembus; + gd->mem_clk = sys_info.freq_ddrbus; + +#if defined(CONFIG_FSL_ESDHC ) + gd->arch.sdhc_clk = gd->bus_clk /2 ; +#endif /* defined(CONFIG_FSL_ESDHC) */ + +if (gd->cpu_clk !=0 ) +return 0 ; +else +return 1 ; +} + +/******************************************** +* get_bus_freq +* return system bus freq in Hz +*********************************************/ +ulong get_bus_freq (ulong dummy) +{ +if (!gd->bus_clk) +get_clocks (); + +return gd->bus_clk; +} + +/******************************************** +* get_ddr_freq +* return ddr bus freq in Hz +*********************************************/ +ulong get_ddr_freq (ulong dummy) +{ +if (!gd->mem_clk) +get_clocks (); + +return gd->mem_clk; +} + +unsigned int mxc_get_clock (enum mxc_clock clk) +{ +switch (clk) { +case MXC_I2C_CLK : +return get_bus_freq (0 ) /2 ; +default : +printf ("Unsupported clock\n" ); + } +return 0 ; +}arch/arm/cpu/armv8/fsl-lsch3/speed.h new file +7
-0@@ -0,0 +1,7 @@ +/* +* Copyright 2014, Freescale Semiconductor, Inc. +* +* SPDX-License-Identifier: GPL-2.0+ +*/ + +void get_sys_info (struct sys_info *sys_info);arch/arm/cpu/armv8/fsl-lsch3/timer.c new file +56
-0@@ -0,0 +1,62 @@ +/* +* Copyright 2014, Freescale Semiconductor +* +* SPDX-License-Identifier: GPL-2.0+ +*/ + +#include <common.h> +#include <div64.h> +#include <linux/compiler.h> + +static inline u64 get_cntfrq (void ) +{ +u64 cntfrq; + asmvolatile ("mrs %0, cntfrq_el0" :"=r" (cntfrq)); +return cntfrq; +} + +static inline u64 tick_to_time (u64 tick) +{ + tick *=CONFIG_SYS_HZ ; +do_div (tick,get_cntfrq ()); +return tick; +} + +static inline u64 time_to_tick (u64 time) +{ + time *=get_cntfrq (); +do_div (time,CONFIG_SYS_HZ ); +return time; +} + +static inline u64 us_to_tick (unsigned long long usec) +{ + usec = usec *get_cntfrq () +999999 ; +do_div (usec,1000000 ); + +return usec; +} + +u64 get_ticks (void ) +{ +u64 cval; + + asmvolatile ("isb;mrs %0, cntpct_el0" :"=r" (cval)); + +return cval; +} + +ulong get_timer (ulong base) +{ +return tick_to_time (get_ticks ()) - base; +} + +void __udelay (unsigned long usec) +{ +u64 start, tmo;
Quoted 9 lines
arch/arm/cpu/armv8/fsl-lsch3/timer.c line 62
Quoted 6 lines
arch/arm/cpu/armv8/fsl-lsch3/timer.c new file +6
-0+ + start =get_ticks (); + tmo =us_to_tick (usec); +while (get_ticks () < (start + tmo)) + ; +}What's wrong with the existing arch timer code?
It was created before the common armv8 code was settled. At time, the generic code didn't work for this SoC. Now things has changed. I need reexamine this part.
I really appreciate your effort reviewing this patch. A new version will be sent soon. I may have to split this patch to separate the common part.
York
PATCH v3 2/4 ARMv8/FSL_LSCH3: Add FSL_LSCH3 SoC
Quoted 18 lines · York Sun
Quoted 1 line · Rob Herring
On Wed, May 28, 2014 at 6:46 PM, York Sun <[email protected]> wrote:
<snip>
Quoted 12 lines
arch/arm/cpu/armv8/fsl-lsch3/cpu.c line 79
Quoted 9 lines
arch/arm/cpu/armv8/fsl-lsch3/cpu.c new file +9
-0+static void set_pgtable_section (u64 *page_table,u64 index,u64 section, +u8 memory_type) +{ +u64 value; + + value = section |PMD_TYPE_SECT |PMD_SECT_AF ; + value |=PMD_ATTRINDX (memory_type); + page_table[index] = value; +}This function looks like it should be common.
Quoted 2 lines
There is a common version in
arch/arm/cpu/armv8/cache_v8.c. This version has more flexibility. I am not sure which one will be used as common.
Then add the flexibility to the common one.
Quoted 11 lines
Quoted 8 lines
Quoted 1 line
+ el =
current_el();We really can't have u-boot running at random ELs in v8 for different platforms. It's a mess on v7. You should never be at EL3. u-boot could be defined to run at EL1, but then you need to be able to go back to EL2 to boot the kernel. So really u-boot should always run at EL2 unless you are running in a VM, but that would be a different platform.
I have to run u-boot at EL3. Otherwise I can't access Dickens. I vaguely remember other reasons. I will have to dig it out if needed.
You may start in EL3, but then the early init code should drop to EL2. If you need EL3 later on for something PSCI does not address, then you are probably doing things wrong.
Quoted 10 lines
Quoted 6 lines
Quoted 3 lines
+ *
flush_l3_cache
+ * Dickens L3 cache can be flushed by transitioning from FAM to SFONLY power
+ * state, by writing to HP-F P-state request register.Other SOCs will have Dickens. Are these registers FSL specific? If not, this should be common.
I don't think they are FSL specific. But I haven't found a proper place to host it. Can you share what other SoCs have Dickens? If they are not supported yet, we can keep the code here until we are clear then move it out.
It is safe to say most if not all SOCs based on A53 and/or A57 will also be based on Dickens aka CCN-504.
Quoted 7 lines
Quoted 3 lines
Also, I believe the proper way to flush Dickens is using the architected cache flushing method where you walk the levels out to level 3.
False. L3 cache gets flushed with instruction DCCIVAC. So if we flush the cache by range, it works OK. But it doesn't work with DCISW or DCCISW. If we flush cache by walking the levels, it doesn't work. We can only walk level 1 and level 2.
So the EL3 boot code should do any one-time invalidate all operations and u-boot in EL2 should only use range operations. There are limitations in the by way operations such as they are not SMP safe. If the by way operations are EL3 only, then that's probably a sign you are not doing things as intended. Or it could be an oversight and we need to figure out a common way to handle this across SOCs.
Quoted 160 lines
Quoted 56 lines
Quoted 56 lines
+ */
arch/arm/cpu/armv8/fsl-lsch3/cpu.c new file +55
-0+#define HNF0_PSTATE_REQ 0x04200010 +#define HNF1_PSTATE_REQ 0x04210010 +#define HNF2_PSTATE_REQ 0x04220010 +#define HNF3_PSTATE_REQ 0x04230010 +#define HNF4_PSTATE_REQ 0x04240010 +#define HNF5_PSTATE_REQ 0x04250010 +#define HNF6_PSTATE_REQ 0x04260010 +#define HNF7_PSTATE_REQ 0x04270010 +#define HNFPSTAT_MASK (0xFFFFFFFFFFFFFFFC) +#define HNFPSTAT_FAM 0x3 +#define HNFPSTAT_SFONLY 0x01 + +static void hnf_pstate_req (u64 *ptr,u64 state) +{ +int timeout =1000 ; +out_le64 (ptr, (in_le64 (ptr) &HNFPSTAT_MASK ) | (state &0x3 )); + ptr++; +/* checking if the transition is completed */ +while (timeout >0 ) { +if (((in_le64 (ptr) &0x0c ) >>2 ) == (state &0x3 )) +break ; +udelay (100 ); + timeout--; + } +} + +void flush_l3_cache (void ) +{ +hnf_pstate_req ((u64 *)HNF0_PSTATE_REQ ,HNFPSTAT_SFONLY ); +hnf_pstate_req ((u64 *)HNF1_PSTATE_REQ ,HNFPSTAT_SFONLY ); +hnf_pstate_req ((u64 *)HNF2_PSTATE_REQ ,HNFPSTAT_SFONLY ); +hnf_pstate_req ((u64 *)HNF3_PSTATE_REQ ,HNFPSTAT_SFONLY ); +hnf_pstate_req ((u64 *)HNF4_PSTATE_REQ ,HNFPSTAT_SFONLY ); +hnf_pstate_req ((u64 *)HNF5_PSTATE_REQ ,HNFPSTAT_SFONLY ); +hnf_pstate_req ((u64 *)HNF6_PSTATE_REQ ,HNFPSTAT_SFONLY ); +hnf_pstate_req ((u64 *)HNF7_PSTATE_REQ ,HNFPSTAT_SFONLY ); +hnf_pstate_req ((u64 *)HNF0_PSTATE_REQ ,HNFPSTAT_FAM ); +hnf_pstate_req ((u64 *)HNF1_PSTATE_REQ ,HNFPSTAT_FAM ); +hnf_pstate_req ((u64 *)HNF2_PSTATE_REQ ,HNFPSTAT_FAM ); +hnf_pstate_req ((u64 *)HNF3_PSTATE_REQ ,HNFPSTAT_FAM ); +hnf_pstate_req ((u64 *)HNF4_PSTATE_REQ ,HNFPSTAT_FAM ); +hnf_pstate_req ((u64 *)HNF5_PSTATE_REQ ,HNFPSTAT_FAM ); +hnf_pstate_req ((u64 *)HNF6_PSTATE_REQ ,HNFPSTAT_FAM ); +hnf_pstate_req ((u64 *)HNF7_PSTATE_REQ ,HNFPSTAT_FAM ); +} + +/* +* This function is called from lib/board.c. +* It recreates MMU table in main memory. MMU and d-cache are enabled earlier. +* There is no need to disable d-cache for this operation. +*/ +void enable_caches (void ) +{ +final_mmu_setup (); + flush_dcache_range(gd->arch.tlb_addr,Quoted 8 lines
arch/arm/cpu/armv8/fsl-lsch3/cpu.c line 357
Quoted 6 lines
arch/arm/cpu/armv8/fsl-lsch3/cpu.c new file +6
-0+ gd->arch.tlb_addr + gd->arch.tlb_size); + __asm_invalidate_tlb_all(); +} +#endif + +static inline u32 init_type (u32 cluster,int init_id)
init_type? That's a great name.That is initiator type. It is a funny name used by many FSL SoCs.
Quoted 84 lines
Quoted 84 lines
arch/arm/cpu/armv8/fsl-lsch3/cpu.c new file +83
-0+{ +struct ccsr_gur *gur = (void *)(CONFIG_SYS_FSL_GUTS_ADDR ); +u32 idx = (cluster >> (init_id *8 )) &TP_CLUSTER_INIT_MASK ; +u32 type =in_le32 (&gur->tp_ityp[idx]); + +if (type &TP_ITYP_AV ) +return type; + +return 0 ; +} + +u32 cpu_mask (void ) +{ +struct ccsr_gur __iomem *gur = (void *)(CONFIG_SYS_FSL_GUTS_ADDR ); +int i =0 , count =0 ; +u32 cluster, type, mask =0 ; + +do { +int j; + cluster =in_le32 (&gur->tp_cluster[i].lower); +for (j =0 ; j <TP_INIT_PER_CLUSTER ; j++) { + type =init_type (cluster, j); +if (type) { +if (TP_ITYP_TYPE (type) ==TP_ITYP_TYPE_ARM ) + mask |=1 << count; + count++; + } + } + i++; + }while ((cluster &TP_CLUSTER_EOC ) !=TP_CLUSTER_EOC ); + +return mask; +} + +/* +* Return the number of cores on this SOC. +*/ +int cpu_numcores (void ) +{ +return hweight32 (cpu_mask ()); +} + +int fsl_qoriq_core_to_cluster (unsigned int core) +{ +struct ccsr_gur __iomem *gur = + (void __iomem *)(CONFIG_SYS_FSL_GUTS_ADDR ); +int i =0 , count =0 ; +u32 cluster; + +do { +int j; + cluster =in_le32 (&gur->tp_cluster[i].lower); +for (j =0 ; j <TP_INIT_PER_CLUSTER ; j++) { +if (init_type (cluster, j)) { +if (count == core) +return i; + count++; + } + } + i++; + }while ((cluster &TP_CLUSTER_EOC ) !=TP_CLUSTER_EOC ); + +return -1 ;/* cannot identify the cluster */ +} + +u32 fsl_qoriq_core_to_type (unsigned int core) +{ +struct ccsr_gur __iomem *gur = + (void __iomem *)(CONFIG_SYS_FSL_GUTS_ADDR ); +int i =0 , count =0 ; +u32 cluster, type; + + do { + int j; + cluster = in_le32(&gur->tp_cluster[i].lower); + for (j = 0; j < TP_INIT_PER_CLUSTER; j++) { + type = init_type(cluster, j); + if (type) { + if (count == core) + return type; + count++; + } + }Quoted 8 lines
arch/arm/cpu/armv8/fsl-lsch3/cpu.c line 421
Quoted 5 lines
arch/arm/cpu/armv8/fsl-lsch3/cpu.c new file +5
-0+ i++; + }while ((cluster &TP_CLUSTER_EOC ) !=TP_CLUSTER_EOC ); + +return -1 ;/* cannot identify the cluster */ +}Do you plan on supporting PSCI because all this core and cluster stuff belongs there.
Quoted 1 line
What's PSCI?
Power State Coordination Interface, a spec from ARM to do cpu and cluster power/boot control. It's strongly encouraged for v8 and good luck with upstream kernel support without it.
There are patches for v7 to add PSCI implementation to u-boot from Marc Zyngier on the list. It is debatable whether u-boot is the right place for it rather than separate secure firmware. There is also ARM Trusted Firmware which implements PSCI and you should look at.
Quoted 3 lines
This code is similar to FSL chassis generation 2 code, but it is for chassis generation 3. I plan to move it to a common place once we have another platform using chassis generation 3.
Gen2 would be PowerPC, right? Not sure how that is relevant.
Quoted 24 lines
Quoted 15 lines
Quoted 15 lines
arch/arm/cpu/armv8/fsl-lsch3/lowlevel.S new file +15
-0+ /* + * Slave should wait for master clearing spin table. + * This sync prevent salves observing incorrect + * value of spin table and jumping to wrong place. + */ +#if defined(CONFIG_GICV2) || defined(CONFIG_GICV3) +#ifdef CONFIG_GICV2 + ldr x0, =GICC_BASE +#endif + bl gic_wait_for_interrupt +#endif + + /* + * All processors will enter EL2 and optionally EL1. + */Quoted 8 lines
arch/arm/cpu/armv8/fsl-lsch3/lowlevel.S line 59
Quoted 5 lines
arch/arm/cpu/armv8/fsl-lsch3/lowlevel.S new file +5
-0+ bl armv8_switch_to_el2 +#ifdef CONFIG_ARMV8_SWITCH_TO_EL1 + bl armv8_switch_to_el1 +#endif + b 2fThis all looks like cut and paste from existing startup code. Can't you refactor things?
Quoted 3 lines
Right. We have added some code which only applies to this SoC. That's why the copy-n-paste then modify. I am also holding other patches which add a lot more code into this file.
Then add callouts so you can add SOC specific initialization.
Rob
PATCH v3 2/4 ARMv8/FSL_LSCH3: Add FSL_LSCH3 SoC
Quoted 19 lines · Rob Herring
Quoted 18 lines · York Sun
Quoted 1 line · Rob Herring
On Wed, May 28, 2014 at 6:46 PM, York Sun <[email protected]> wrote:
<snip>
Quoted 12 lines
arch/arm/cpu/armv8/fsl-lsch3/cpu.c line 79
Quoted 9 lines
arch/arm/cpu/armv8/fsl-lsch3/cpu.c new file +9
-0+static void set_pgtable_section (u64 *page_table,u64 index,u64 section, +u8 memory_type) +{ +u64 value; + + value = section |PMD_TYPE_SECT |PMD_SECT_AF ; + value |=PMD_ATTRINDX (memory_type); + page_table[index] = value; +}This function looks like it should be common.
Quoted 5 lines
Quoted 2 lines
There is a common version in
arch/arm/cpu/armv8/cache_v8.c. This version has more flexibility. I am not sure which one will be used as common.Then add the flexibility to the common one.
Will do.
Quoted 10 lines
Quoted 10 lines
Quoted 9 lines
Quoted 2 lines
+ el =
current_el();We really can't have u-boot running at random ELs in v8 for different platforms. It's a mess on v7. You should never be at EL3. u-boot could be defined to run at EL1, but then you need to be able to go back to EL2 to boot the kernel. So really u-boot should always run at EL2 unless you are running in a VM, but that would be a different platform.
Quoted 6 lines
Quoted 2 lines
I have to run u-boot at EL3. Otherwise I can't access Dickens. I vaguely remember other reasons. I will have to dig it out if needed.
You may start in EL3, but then the early init code should drop to EL2. If you need EL3 later on for something PSCI does not address, then you are probably doing things wrong.
This part code supports all ELs. I think it is not wrong here. There is something planned to have a secure monitor before u-boot and call it when special access is needed. I am going to reorganize the code here to reuse more.
Is the general ARMv8 code already dropping to EL2?
Quoted 8 lines
Quoted 8 lines
Quoted 7 lines
Quoted 4 lines
+ *
flush_l3_cache
+ * Dickens L3 cache can be flushed by transitioning from FAM to SFONLY power
+ * state, by writing to HP-F P-state request register.Other SOCs will have Dickens. Are these registers FSL specific? If not, this should be common.
Quoted 6 lines
Quoted 3 lines
I don't think they are FSL specific. But I haven't found a proper place to host it. Can you share what other SoCs have Dickens? If they are not supported yet, we can keep the code here until we are clear then move it out.
It is safe to say most if not all SOCs based on A53 and/or A57 will also be based on Dickens aka CCN-504.
Great. But in order to to access CCN-504 register to flush L3 cache, it needs to be EL3. At least for the SoC I am debugging. Please suggest a location to host CCN-504 code. Should it go to drivers/misc?
Quoted 9 lines
Quoted 8 lines
Quoted 4 lines
Also, I believe the proper way to flush Dickens is using the architected cache flushing method where you walk the levels out to level 3.
False. L3 cache gets flushed with instruction DCCIVAC. So if we flush the cache by range, it works OK. But it doesn't work with DCISW or DCCISW. If we flush cache by walking the levels, it doesn't work. We can only walk level 1 and level 2.
Quoted 73 lines
So the EL3 boot code should do any one-time invalidate all operations and u-boot in EL2 should only use range operations. There are limitations in the by way operations such as they are not SMP safe. If the by way operations are EL3 only, then that's probably a sign you are not doing things as intended. Or it could be an oversight and we need to figure out a common way to handle this across SOCs.
Quoted 66 lines
Quoted 56 lines
Quoted 56 lines
+ */
arch/arm/cpu/armv8/fsl-lsch3/cpu.c new file +55
-0+#define HNF0_PSTATE_REQ 0x04200010 +#define HNF1_PSTATE_REQ 0x04210010 +#define HNF2_PSTATE_REQ 0x04220010 +#define HNF3_PSTATE_REQ 0x04230010 +#define HNF4_PSTATE_REQ 0x04240010 +#define HNF5_PSTATE_REQ 0x04250010 +#define HNF6_PSTATE_REQ 0x04260010 +#define HNF7_PSTATE_REQ 0x04270010 +#define HNFPSTAT_MASK (0xFFFFFFFFFFFFFFFC) +#define HNFPSTAT_FAM 0x3 +#define HNFPSTAT_SFONLY 0x01 + +static void hnf_pstate_req (u64 *ptr,u64 state) +{ +int timeout =1000 ; +out_le64 (ptr, (in_le64 (ptr) &HNFPSTAT_MASK ) | (state &0x3 )); + ptr++; +/* checking if the transition is completed */ +while (timeout >0 ) { +if (((in_le64 (ptr) &0x0c ) >>2 ) == (state &0x3 )) +break ; +udelay (100 ); + timeout--; + } +} + +void flush_l3_cache (void ) +{ +hnf_pstate_req ((u64 *)HNF0_PSTATE_REQ ,HNFPSTAT_SFONLY ); +hnf_pstate_req ((u64 *)HNF1_PSTATE_REQ ,HNFPSTAT_SFONLY ); +hnf_pstate_req ((u64 *)HNF2_PSTATE_REQ ,HNFPSTAT_SFONLY ); +hnf_pstate_req ((u64 *)HNF3_PSTATE_REQ ,HNFPSTAT_SFONLY ); +hnf_pstate_req ((u64 *)HNF4_PSTATE_REQ ,HNFPSTAT_SFONLY ); +hnf_pstate_req ((u64 *)HNF5_PSTATE_REQ ,HNFPSTAT_SFONLY ); +hnf_pstate_req ((u64 *)HNF6_PSTATE_REQ ,HNFPSTAT_SFONLY ); +hnf_pstate_req ((u64 *)HNF7_PSTATE_REQ ,HNFPSTAT_SFONLY ); +hnf_pstate_req ((u64 *)HNF0_PSTATE_REQ ,HNFPSTAT_FAM ); +hnf_pstate_req ((u64 *)HNF1_PSTATE_REQ ,HNFPSTAT_FAM ); +hnf_pstate_req ((u64 *)HNF2_PSTATE_REQ ,HNFPSTAT_FAM ); +hnf_pstate_req ((u64 *)HNF3_PSTATE_REQ ,HNFPSTAT_FAM ); +hnf_pstate_req ((u64 *)HNF4_PSTATE_REQ ,HNFPSTAT_FAM ); +hnf_pstate_req ((u64 *)HNF5_PSTATE_REQ ,HNFPSTAT_FAM ); +hnf_pstate_req ((u64 *)HNF6_PSTATE_REQ ,HNFPSTAT_FAM ); +hnf_pstate_req ((u64 *)HNF7_PSTATE_REQ ,HNFPSTAT_FAM ); +} + +/* +* This function is called from lib/board.c. +* It recreates MMU table in main memory. MMU and d-cache are enabled earlier. +* There is no need to disable d-cache for this operation. +*/ +void enable_caches (void ) +{ +final_mmu_setup (); + flush_dcache_range(gd->arch.tlb_addr,Quoted 8 lines
arch/arm/cpu/armv8/fsl-lsch3/cpu.c line 357
Quoted 6 lines
arch/arm/cpu/armv8/fsl-lsch3/cpu.c new file +6
-0+ gd->arch.tlb_addr + gd->arch.tlb_size); + __asm_invalidate_tlb_all(); +} +#endif + +static inline u32 init_type (u32 cluster,int init_id)
init_type? That's a great name.That is initiator type. It is a funny name used by many FSL SoCs.
By the way, I am changing the name to initiator_type.
Quoted 96 lines
Quoted 94 lines
Quoted 85 lines
Quoted 85 lines
arch/arm/cpu/armv8/fsl-lsch3/cpu.c new file +83
-0+{ +struct ccsr_gur *gur = (void *)(CONFIG_SYS_FSL_GUTS_ADDR ); +u32 idx = (cluster >> (init_id *8 )) &TP_CLUSTER_INIT_MASK ; +u32 type =in_le32 (&gur->tp_ityp[idx]); + +if (type &TP_ITYP_AV ) +return type; + +return 0 ; +} + +u32 cpu_mask (void ) +{ +struct ccsr_gur __iomem *gur = (void *)(CONFIG_SYS_FSL_GUTS_ADDR ); +int i =0 , count =0 ; +u32 cluster, type, mask =0 ; + +do { +int j; + cluster =in_le32 (&gur->tp_cluster[i].lower); +for (j =0 ; j <TP_INIT_PER_CLUSTER ; j++) { + type =init_type (cluster, j); +if (type) { +if (TP_ITYP_TYPE (type) ==TP_ITYP_TYPE_ARM ) + mask |=1 << count; + count++; + } + } + i++; + }while ((cluster &TP_CLUSTER_EOC ) !=TP_CLUSTER_EOC ); + +return mask; +} + +/* +* Return the number of cores on this SOC. +*/ +int cpu_numcores (void ) +{ +return hweight32 (cpu_mask ()); +} + +int fsl_qoriq_core_to_cluster (unsigned int core) +{ +struct ccsr_gur __iomem *gur = + (void __iomem *)(CONFIG_SYS_FSL_GUTS_ADDR ); +int i =0 , count =0 ; +u32 cluster; + +do { +int j; + cluster =in_le32 (&gur->tp_cluster[i].lower); +for (j =0 ; j <TP_INIT_PER_CLUSTER ; j++) { +if (init_type (cluster, j)) { +if (count == core) +return i; + count++; + } + } + i++; + }while ((cluster &TP_CLUSTER_EOC ) !=TP_CLUSTER_EOC ); + +return -1 ;/* cannot identify the cluster */ +} + +u32 fsl_qoriq_core_to_type (unsigned int core) +{ +struct ccsr_gur __iomem *gur = + (void __iomem *)(CONFIG_SYS_FSL_GUTS_ADDR ); +int i =0 , count =0 ; +u32 cluster, type; + + do { + int j; + cluster = in_le32(&gur->tp_cluster[i].lower); + for (j = 0; j < TP_INIT_PER_CLUSTER; j++) { + type = init_type(cluster, j); + if (type) { + if (count == core) + return type; + count++; + } + }Quoted 8 lines
arch/arm/cpu/armv8/fsl-lsch3/cpu.c line 421
Quoted 5 lines
arch/arm/cpu/armv8/fsl-lsch3/cpu.c new file +5
-0+ i++; + }while ((cluster &TP_CLUSTER_EOC ) !=TP_CLUSTER_EOC ); + +return -1 ;/* cannot identify the cluster */ +}Do you plan on supporting PSCI because all this core and cluster stuff belongs there.
Quoted 1 line
What's PSCI?
Quoted 8 lines
Power State Coordination Interface, a spec from ARM to do cpu and cluster power/boot control. It's strongly encouraged for v8 and good luck with upstream kernel support without it.
There are patches for v7 to add PSCI implementation to u-boot from Marc Zyngier on the list. It is debatable whether u-boot is the right place for it rather than separate secure firmware. There is also ARM Trusted Firmware which implements PSCI and you should look at.
Thanks for the explanation. The above code is to probe the number of cores, to support SMP.
Quoted 6 lines
Quoted 4 lines
This code is similar to FSL chassis generation 2 code, but it is for chassis generation 3. I plan to move it to a common place once we have another platform using chassis generation 3.
Gen2 would be PowerPC, right? Not sure how that is relevant.
It is not relevant to ARM.
Quoted 25 lines
Quoted 25 lines
Quoted 24 lines
Quoted 11 lines
arch/arm/cpu/armv8/fsl-lsch3/lowlevel.S new file +10
-0+ /* + * Slave should wait for master clearing spin table. + * This sync prevent salves observing incorrect + * value of spin table and jumping to wrong place. + */ +#if defined(CONFIG_GICV2) || defined(CONFIG_GICV3) +#ifdef CONFIG_GICV2 + ldr x0, =GICC_BASE +#endif + bl gic_wait_for_interruptarch/arm/cpu/armv8/fsl-lsch3/lowlevel.S line 59
Quoted 10 lines
arch/arm/cpu/armv8/fsl-lsch3/lowlevel.S new file +10
-0+#endif + + /* + * All processors will enter EL2 and optionally EL1. + */ + bl armv8_switch_to_el2 +#ifdef CONFIG_ARMV8_SWITCH_TO_EL1 + bl armv8_switch_to_el1 +#endif + b 2fThis all looks like cut and paste from existing startup code. Can't you refactor things?
Quoted 6 lines
Quoted 3 lines
Right. We have added some code which only applies to this SoC. That's why the copy-n-paste then modify. I am also holding other patches which add a lot more code into this file.
Then add callouts so you can add SOC specific initialization.
There is a reason to use weak for lowlevel_init. It would be easier to implement real low level init without adding callout here and there. I am cleaning up the GICv2 macro here so it will look cleaner. If we end up the same code when we have the real SoC, I will cleanup this function. For now, I prefer the separate one.
York
PATCH v3 2/4 ARMv8/FSL_LSCH3: Add FSL_LSCH3 SoC
In reply to Rob HerringQuoted 63 lines · Rob Herring
Quoted 18 lines · York Sun
Quoted 1 line · Rob Herring
On Wed, May 28, 2014 at 6:46 PM, York Sun <[email protected]> wrote:
<snip>
Quoted 12 lines
arch/arm/cpu/armv8/fsl-lsch3/cpu.c line 79
Quoted 9 lines
arch/arm/cpu/armv8/fsl-lsch3/cpu.c new file +9
-0+static void set_pgtable_section (u64 *page_table,u64 index,u64 section, +u8 memory_type) +{ +u64 value; + + value = section |PMD_TYPE_SECT |PMD_SECT_AF ; + value |=PMD_ATTRINDX (memory_type); + page_table[index] = value; +}This function looks like it should be common.
Quoted 2 lines
There is a common version in
arch/arm/cpu/armv8/cache_v8.c. This version has more flexibility. I am not sure which one will be used as common.Then add the flexibility to the common one.
Quoted 11 lines
Quoted 8 lines
Quoted 1 line
+ el =
current_el();We really can't have u-boot running at random ELs in v8 for different platforms. It's a mess on v7. You should never be at EL3. u-boot could be defined to run at EL1, but then you need to be able to go back to EL2 to boot the kernel. So really u-boot should always run at EL2 unless you are running in a VM, but that would be a different platform.
I have to run u-boot at EL3. Otherwise I can't access Dickens. I vaguely remember other reasons. I will have to dig it out if needed.
You may start in EL3, but then the early init code should drop to EL2. If you need EL3 later on for something PSCI does not address, then you are probably doing things wrong.
Quoted 10 lines
Quoted 6 lines
Quoted 3 lines
+ *
flush_l3_cache
+ * Dickens L3 cache can be flushed by transitioning from FAM to SFONLY power
+ * state, by writing to HP-F P-state request register.Other SOCs will have Dickens. Are these registers FSL specific? If not, this should be common.
I don't think they are FSL specific. But I haven't found a proper place to host it. Can you share what other SoCs have Dickens? If they are not supported yet, we can keep the code here until we are clear then move it out.
It is safe to say most if not all SOCs based on A53 and/or A57 will also be based on Dickens aka CCN-504.
Quoted 7 lines
Quoted 3 lines
Also, I believe the proper way to flush Dickens is using the architected cache flushing method where you walk the levels out to level 3.
False. L3 cache gets flushed with instruction DCCIVAC. So if we flush the cache by range, it works OK. But it doesn't work with DCISW or DCCISW. If we flush cache by walking the levels, it doesn't work. We can only walk level 1 and level 2.
Quoted 6 lines
So the EL3 boot code should do any one-time invalidate all operations and u-boot in EL2 should only use range operations. There are limitations in the by way operations such as they are not SMP safe. If the by way operations are EL3 only, then that's probably a sign you are not doing things as intended. Or it could be an oversight and we need to figure out a common way to handle this across SOCs.
This is the only sane way of doing things.
The set/way operations can only be used for two things:
* One-off IMPLEMENTATION DEFINED cache initialisation (for power on).
* Emptying of a given CPU's architected cache levels (which is only necessary for power off).
In neither of these cases are the operations used to provide any sort of visibility guarantee (i.e. they do not make uncached data visible to CPUs, or cached data visible to other observers). In both of these cases if you have PSCI this is hidden by the implementation.
It should be entirely possible to flush/clean the data/area you care about by VA.
Given that this L3 cache and (IIRC the APM L3) can handle VA operations, I would rather that U-boot and general purposes OSs assume that there is such a cache present always, which is outside of our control and already enabled. While this necessitates some cache flushing before turning the MMU and caches on, it will otherwise be transparent.
This is what we exepect in Linux since c218bca74eea (arm64: Relax the kernel cache requirements for boot). It makes a single image possible in the presnce of system caches, and makes things consistent for KVM, kexec, and chain-loading U-Boot.
Cheers,
Mark.