From: Bhupesh Sharma bhupesh.sharma@nxp.com
This patchset adds the support for NXP/FSL's LS1043A RDB platform.
The LS1043A RDB platform houses the 4-A53 core LS1043A SoC from NXP/FSL. Details about the LS1043A SoC and RDB board can be seen here:
SoC: --- http://www.nxp.com/products/microcontrollers-and-processors/arm-processors/ qoriq-arm-processors/qoriq-ls1043a-and-ls1023a-multicore-communications-processors:LS1043A?lang_cd=en
RDB board: --------- http://www.nxp.com/products/microcontrollers-and-processors/arm-processors/ qoriq-arm-processors/qoriq-ls1043a-reference-design-board:LS1043A-RDB#pspFeatures
UEFI firmware boot-flow on the NXP/FSL ARMv8 SoCs is different from the usual ATF (which runs in EL3) and UEFI (which runs entirely in EL2 mode) flow:
NXP/FSL ARMv8 SoCs currently use a EL3 platform and run-time security firmware which is called PPA (Primary Protected Application).
This firmware is placed on the flash device and is loaded into DDR and executed via a UEFI DXE driver. PPA does the initial platform EL3 settings and then returns the control back to UEFI in EL2 exception level.
Later implementations of PPA will allow it to start by itself in the EL3 level and start UEFI in EL2 exception level.
This patchset is rebased against the OpenPlatformPkg git tree (master branch).
Sakar Arora (14): Platforms/NXP: Add intial support for LS1043A RDB Board Platforms/NXP: Add support for DDR Controller initialization Platforms/NXP: Add support for CPLD controller access Platforms/NXP: Add initial support for LS1043a SOC Library Chips/NXP: Add support for DUART library Platforms/NXP: Add support for initialization of peripherals on LS1043A Platforms/NXP: Add support for system reset library Chips/NXP: Add PrePi initialization module that runs from XIP source Chips/NXP: Add I2C operations library Chips/NXP: Add I2C master driver based on I2C library Chips/NXP: Add support for execution of PPA for EL3 initialization Chips/NXP: Add support for DS1307 RTC library Platforms/NXP: Add support for Watchdog driver (LS1043A) Platforms/NXP: Add the fdf, dsc and dec files for LS1043aRdbPkg build
Chips/Nxp/QoriqLs/I2c/I2cDxe.c | 156 ++++ Chips/Nxp/QoriqLs/I2c/I2cDxe.inf | 52 ++ Chips/Nxp/QoriqLs/Include/Library/DUart.h | 133 ++++ Chips/Nxp/QoriqLs/Include/Library/I2c.h | 199 +++++ .../QoriqLs/Library/DUartPortLib/DUartPortLib.c | 321 ++++++++ .../QoriqLs/Library/DUartPortLib/DUartPortLib.inf | 43 ++ .../QoriqLs/Library/Ds1307RtcLib/Ds1307RtcLib.c | 250 +++++++ .../QoriqLs/Library/Ds1307RtcLib/Ds1307RtcLib.inf | 44 ++ Chips/Nxp/QoriqLs/Library/I2cLib/I2cLib.c | 513 +++++++++++++ Chips/Nxp/QoriqLs/Library/I2cLib/I2cLib.inf | 41 ++ .../Library/PrePiNor/AArch64/ModuleEntryPoint.S | 34 + Chips/Nxp/QoriqLs/Library/PrePiNor/PrePiNor.c | 52 ++ Chips/Nxp/QoriqLs/Library/PrePiNor/PrePiNor.inf | 48 ++ Chips/Nxp/QoriqLs/NxpQoriqLs.dec | 50 ++ Chips/Nxp/QoriqLs/PpaInitDxe/PpaInit.c | 117 +++ Chips/Nxp/QoriqLs/PpaInitDxe/PpaInitDxe.inf | 63 ++ Chips/Nxp/QoriqLs/PpaInitDxe/PpaInitHelper.S | 79 ++ Chips/Nxp/QoriqLs/PpaInitDxe/PpaItbParse.c | 144 ++++ Chips/Nxp/QoriqLs/PpaInitDxe/PpaItbParse.h | 52 ++ Platforms/Nxp/LS1043aRdb/Include/Library/Common.h | 68 ++ Platforms/Nxp/LS1043aRdb/Include/Library/CpldLib.h | 75 ++ Platforms/Nxp/LS1043aRdb/Include/Library/Ddr.h | 190 +++++ Platforms/Nxp/LS1043aRdb/Include/Library/FslIfc.h | 721 ++++++++++++++++++ .../Nxp/LS1043aRdb/Include/Library/Ls1043aSerDes.h | 89 +++ .../Nxp/LS1043aRdb/Include/Library/PlatformLib.h | 179 +++++ Platforms/Nxp/LS1043aRdb/Include/Library/SocLib.h | 509 +++++++++++++ Platforms/Nxp/LS1043aRdb/LS1043aRdbPkg.dec | 166 +++++ Platforms/Nxp/LS1043aRdb/LS1043aRdbPkg.dsc | 602 +++++++++++++++ Platforms/Nxp/LS1043aRdb/LS1043aRdbPkg.fdf | 311 ++++++++ .../LS1043aRdb/LS1043aWatchDog/LS1043aWatchDog.c | 355 +++++++++ .../LS1043aWatchDog/LS1043aWatchDogDxe.inf | 54 ++ Platforms/Nxp/LS1043aRdb/Library/CpldLib/CpldLib.c | 157 ++++ .../Nxp/LS1043aRdb/Library/CpldLib/CpldLib.inf | 33 + Platforms/Nxp/LS1043aRdb/Library/DdrLib/DdrLib.c | 188 +++++ Platforms/Nxp/LS1043aRdb/Library/DdrLib/DdrLib.inf | 41 ++ .../Nxp/LS1043aRdb/Library/LS1043aRdbLib/Common.c | 103 +++ .../LS1043aRdb/Library/LS1043aRdbLib/LS1043aRdb.c | 109 +++ .../Library/LS1043aRdbLib/LS1043aRdbHelper.S | 61 ++ .../Library/LS1043aRdbLib/LS1043aRdbLib.inf | 56 ++ .../Library/LS1043aRdbLib/LS1043aRdbMem.c | 149 ++++ .../Library/LS1043aSocLib/LS1043aSocLib.c | 819 +++++++++++++++++++++ .../Library/LS1043aSocLib/LS1043aSocLib.inf | 53 ++ .../LS1043aRdb/Library/LS1043aSocLib/LsSerDes.c | 195 +++++ .../Library/ResetSystemLib/ResetSystemLib.c | 87 +++ .../Library/ResetSystemLib/ResetSystemLib.inf | 50 ++ Platforms/Nxp/LS1043aRdb/build.sh | 72 ++ Platforms/Nxp/LS1043aRdb/ls1043a_env.cshrc | 2 + 47 files changed, 7885 insertions(+) create mode 100644 Chips/Nxp/QoriqLs/I2c/I2cDxe.c create mode 100644 Chips/Nxp/QoriqLs/I2c/I2cDxe.inf create mode 100644 Chips/Nxp/QoriqLs/Include/Library/DUart.h create mode 100644 Chips/Nxp/QoriqLs/Include/Library/I2c.h create mode 100644 Chips/Nxp/QoriqLs/Library/DUartPortLib/DUartPortLib.c create mode 100644 Chips/Nxp/QoriqLs/Library/DUartPortLib/DUartPortLib.inf create mode 100644 Chips/Nxp/QoriqLs/Library/Ds1307RtcLib/Ds1307RtcLib.c create mode 100644 Chips/Nxp/QoriqLs/Library/Ds1307RtcLib/Ds1307RtcLib.inf create mode 100644 Chips/Nxp/QoriqLs/Library/I2cLib/I2cLib.c create mode 100644 Chips/Nxp/QoriqLs/Library/I2cLib/I2cLib.inf create mode 100644 Chips/Nxp/QoriqLs/Library/PrePiNor/AArch64/ModuleEntryPoint.S create mode 100644 Chips/Nxp/QoriqLs/Library/PrePiNor/PrePiNor.c create mode 100644 Chips/Nxp/QoriqLs/Library/PrePiNor/PrePiNor.inf create mode 100644 Chips/Nxp/QoriqLs/NxpQoriqLs.dec create mode 100644 Chips/Nxp/QoriqLs/PpaInitDxe/PpaInit.c create mode 100644 Chips/Nxp/QoriqLs/PpaInitDxe/PpaInitDxe.inf create mode 100644 Chips/Nxp/QoriqLs/PpaInitDxe/PpaInitHelper.S create mode 100755 Chips/Nxp/QoriqLs/PpaInitDxe/PpaItbParse.c create mode 100755 Chips/Nxp/QoriqLs/PpaInitDxe/PpaItbParse.h create mode 100644 Platforms/Nxp/LS1043aRdb/Include/Library/Common.h create mode 100644 Platforms/Nxp/LS1043aRdb/Include/Library/CpldLib.h create mode 100644 Platforms/Nxp/LS1043aRdb/Include/Library/Ddr.h create mode 100644 Platforms/Nxp/LS1043aRdb/Include/Library/FslIfc.h create mode 100644 Platforms/Nxp/LS1043aRdb/Include/Library/Ls1043aSerDes.h create mode 100644 Platforms/Nxp/LS1043aRdb/Include/Library/PlatformLib.h create mode 100644 Platforms/Nxp/LS1043aRdb/Include/Library/SocLib.h create mode 100644 Platforms/Nxp/LS1043aRdb/LS1043aRdbPkg.dec create mode 100644 Platforms/Nxp/LS1043aRdb/LS1043aRdbPkg.dsc create mode 100644 Platforms/Nxp/LS1043aRdb/LS1043aRdbPkg.fdf create mode 100644 Platforms/Nxp/LS1043aRdb/LS1043aWatchDog/LS1043aWatchDog.c create mode 100644 Platforms/Nxp/LS1043aRdb/LS1043aWatchDog/LS1043aWatchDogDxe.inf create mode 100644 Platforms/Nxp/LS1043aRdb/Library/CpldLib/CpldLib.c create mode 100644 Platforms/Nxp/LS1043aRdb/Library/CpldLib/CpldLib.inf create mode 100644 Platforms/Nxp/LS1043aRdb/Library/DdrLib/DdrLib.c create mode 100644 Platforms/Nxp/LS1043aRdb/Library/DdrLib/DdrLib.inf create mode 100644 Platforms/Nxp/LS1043aRdb/Library/LS1043aRdbLib/Common.c create mode 100644 Platforms/Nxp/LS1043aRdb/Library/LS1043aRdbLib/LS1043aRdb.c create mode 100644 Platforms/Nxp/LS1043aRdb/Library/LS1043aRdbLib/LS1043aRdbHelper.S create mode 100644 Platforms/Nxp/LS1043aRdb/Library/LS1043aRdbLib/LS1043aRdbLib.inf create mode 100644 Platforms/Nxp/LS1043aRdb/Library/LS1043aRdbLib/LS1043aRdbMem.c create mode 100644 Platforms/Nxp/LS1043aRdb/Library/LS1043aSocLib/LS1043aSocLib.c create mode 100644 Platforms/Nxp/LS1043aRdb/Library/LS1043aSocLib/LS1043aSocLib.inf create mode 100644 Platforms/Nxp/LS1043aRdb/Library/LS1043aSocLib/LsSerDes.c create mode 100644 Platforms/Nxp/LS1043aRdb/Library/ResetSystemLib/ResetSystemLib.c create mode 100644 Platforms/Nxp/LS1043aRdb/Library/ResetSystemLib/ResetSystemLib.inf create mode 100755 Platforms/Nxp/LS1043aRdb/build.sh create mode 100644 Platforms/Nxp/LS1043aRdb/ls1043a_env.cshrc
From: Sakar Arora sakar.arora@nxp.com
This patch adds the basic support for NXP/FSL's LS1043A RDB board. LS1043A RDB board supports a number of on-board peripherals. This patch adds the basic framework for the same.
Further details about this board can be seen here: http://www.nxp.com/products/microcontrollers-and-processors/ arm-processors/qoriq-arm-processors/qoriq-ls1043a-reference-design-board:LS1043A-RDB
Signed-off-by: Sakar Arora sakar.arora@nxp.com Signed-off-by: Bhupesh Sharma bhupesh.sharma@nxp.com --- Platforms/Nxp/LS1043aRdb/Include/Library/Common.h | 68 ++++++++ .../Nxp/LS1043aRdb/Include/Library/PlatformLib.h | 178 +++++++++++++++++++++ .../Nxp/LS1043aRdb/Library/LS1043aRdbLib/Common.c | 103 ++++++++++++ .../LS1043aRdb/Library/LS1043aRdbLib/LS1043aRdb.c | 107 +++++++++++++ .../Library/LS1043aRdbLib/LS1043aRdbHelper.S | 61 +++++++ .../Library/LS1043aRdbLib/LS1043aRdbLib.inf | 56 +++++++ .../Library/LS1043aRdbLib/LS1043aRdbMem.c | 149 +++++++++++++++++ 7 files changed, 722 insertions(+) create mode 100644 Platforms/Nxp/LS1043aRdb/Include/Library/Common.h create mode 100644 Platforms/Nxp/LS1043aRdb/Include/Library/PlatformLib.h create mode 100644 Platforms/Nxp/LS1043aRdb/Library/LS1043aRdbLib/Common.c create mode 100644 Platforms/Nxp/LS1043aRdb/Library/LS1043aRdbLib/LS1043aRdb.c create mode 100644 Platforms/Nxp/LS1043aRdb/Library/LS1043aRdbLib/LS1043aRdbHelper.S create mode 100644 Platforms/Nxp/LS1043aRdb/Library/LS1043aRdbLib/LS1043aRdbLib.inf create mode 100644 Platforms/Nxp/LS1043aRdb/Library/LS1043aRdbLib/LS1043aRdbMem.c
diff --git a/Platforms/Nxp/LS1043aRdb/Include/Library/Common.h b/Platforms/Nxp/LS1043aRdb/Include/Library/Common.h new file mode 100644 index 0000000..192a249 --- /dev/null +++ b/Platforms/Nxp/LS1043aRdb/Include/Library/Common.h @@ -0,0 +1,68 @@ +/** @Common.h + Header defining the General Purpose Utilities + + Copyright (c) 2016, Freescale Semiconductor, Inc. All rights reserved. + + This program and the accompanying materials + are licensed and made available under the terms and conditions of the BSD License + which accompanies this distribution. The full text of the license may be found at + http://opensource.org/licenses/bsd-license.php + + THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, + WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. + +**/ + +#ifndef __COMMON_H__ +#define __COMMON_H__ + + + +#define DMA_MINALIGN 64 + +#define offsetof(TYPE, MEMBER) ((UINTN) &((TYPE *)0)->MEMBER) + + +typedef UINTN PhysAddrT; +typedef UINTN PhysSizeT; + +static inline PhysAddrT VirtToPhys(VOID * VAddr) +{ + return (PhysAddrT)(VAddr); +} + +/* + * The ALLOC_CACHE_ALIGN_BUF macro is used to allocate a buffer + * that meets the minimum architecture alignment requirements for DMA. + * + * The resulting buffer is aligned to the value of DMA_MINALIGN. + * + * The buffer variable created is a pointer to the specified type, and + * NOT an array. + * + * The size parameter is the number of array elements to allocate. + */ + +#define ALIGN_BUFF(x,a) ALIGN_MSK((x),(typeof(x))(a)-1) +#define ALIGN_MSK(x,mask) (((x)+(mask))&~(mask)) + +#define PAD_CNT(S, Pad) (((S) - 1) / (Pad) + 1) +#define PAD_SIZE(S, Pad) (PAD_CNT(S, Pad) * Pad) + +#define ROUND_OFF(a,b) (((a) + (b) - 1) & ~((b) - 1)) + +#define DMA_MINALIGN 64 + +#define ALLOC_ALIGN_BUF_PAD(Type, Name, Size, Align, Pad) \ + INT8 __##Name[ROUND_OFF(PAD_SIZE((Size) * sizeof(Type), Pad), Align) \ + + (Align - 1)]; \ + \ + Type *Name = (Type *) ALIGN_BUFF((UINTN)__##Name, Align) +#define ALLOC_ALIGN_BUF(Type, Name, Size, Align) \ + ALLOC_ALIGN_BUF_PAD(Type, Name, Size, Align, 1) +#define ALLOC_CACHE_ALIGN_BUF_PAD(Type, Name, Size, Pad) \ + ALLOC_ALIGN_BUF_PAD(Type, Name, size, DMA_MINALIGN, Pad) +#define ALLOC_CACHE_ALIGN_BUF(Type, Name, Size) \ + ALLOC_ALIGN_BUF(Type, Name, Size, DMA_MINALIGN) + +#endif diff --git a/Platforms/Nxp/LS1043aRdb/Include/Library/PlatformLib.h b/Platforms/Nxp/LS1043aRdb/Include/Library/PlatformLib.h new file mode 100644 index 0000000..39247e8 --- /dev/null +++ b/Platforms/Nxp/LS1043aRdb/Include/Library/PlatformLib.h @@ -0,0 +1,178 @@ +/** LS1043aRdb.h +* Header defining the LS1043aRdb constants (Base addresses, sizes, flags) +* +* Copyright (c) 2016, Freescale Semiconductor, Inc. All rights reserved. +* +* This program and the accompanying materials +* are licensed and made available under the terms and conditions of the BSD License +* which accompanies this distribution. The full text of the license may be found at +* http://opensource.org/licenses/bsd-license.php +* +* THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, +* WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. +* +**/ + +#ifndef __LS1043aRDB_PLATFORM_H__ +#define __LS1043aRDB_PLATFORM_H__ + +// Types +#define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0])) + +// DDR attributes +#define DDR_ATTRIBUTES_CACHED ARM_MEMORY_REGION_ATTRIBUTE_WRITE_BACK +#define DDR_ATTRIBUTES_UNCACHED ARM_MEMORY_REGION_ATTRIBUTE_UNCACHED_UNBUFFERED + +#define LS1043A_CACHELINE_SIZE 32 + +#define LS1043A_SECURE_BOOTROM_BASE_ADDR 0x00000000 +#define LS1043A_SECURE_BOOTROM_SIZE 0x00100000 /* 1MB */ +#define LS1043A_EXT_BOOTROM_BASE_ADDR 0x00100000 +#define LS1043A_EXT_BOOTROM_SIZE 0x00F00000 /* 15MB */ +#define LS1043A_CCSR_BASE_ADDR 0x01000000 +#define LS1043A_CCSR_SIZE 0x0F000000 /* 240MB */ + #define LS1043A_IMMR 0x01000000 + #define LS1043A_DDR_ADDR 0x01080000 + #define LS1043A_DSPI_ADDR 0x02100000 + #define LS1043A_SDXC_ADDR 0x01560000 + #define LS1043A_CCI400_ADDR (LS1043A_IMMR + 0x00180000) + #define LS1043A_TZASC380_ADDR (LS1043A_IMMR + 0x00500000) + #define LS1043A_CSU_ADDR (LS1043A_IMMR + 0x00510000) + #define LS1043A_GUTS_ADDR (LS1043A_IMMR + 0x00ee0000) + #define LS1043A_CLK_ADDR (LS1043A_IMMR + 0x00ee1000) + #define LS1043A_FMAN_ADDR (LS1043A_IMMR + 0x00a00000) + #define LS1043A_BMAN_ADDR (LS1043A_IMMR + 0x00890000) + #define LS1043A_QMAN_ADDR (LS1043A_IMMR + 0x00880000) + #define GIC_BASE_ADDR 0x01402000 + #define GIC_SIZE 0x1000 + #define GICDIST_BASE_ADDR 0x01401000 + #define GICDIST_SIZE 0x1000 + #define DUART1_BASE_ADDR 0x21C0000 + #define DUART1_SIZE 0x1000 + #define DUART2_BASE_ADDR 0x21D0000 + #define DUART2_SIZE 0x1000 + #define WDOG1_BASE_ADDR 0x02AD0000 + #define WDOG2_BASE_ADDR 0x02AE0000 + #define WDOG3_BASE_ADDR 0x02A70000 + #define WDOG4_BASE_ADDR 0x02A80000 + #define WDOG5_BASE_ADDR 0x02A90000 + #define WDOG_SIZE 0x1000 + #define WDOG_WCR_OFFSET 0 + #define WDOG_WSR_OFFSET 2 + #define WDOG_WRSR_OFFSET 4 + #define WDOG_WICR_OFFSET 6 + #define WDOG_WCR_WT (0xFF << 8) + #define WDOG_WCR_WDE (1 << 2) + #define WDOG_SERVICE_SEQ1 0x5555 + #define WDOG_SERVICE_SEQ2 0xAAAA + #define WDOG_WCR_WDZST 0x1 + #define WDOG_WCR_WRE (1 << 3) /* -> WDOG Reset Enable */ + + #define I2C0_BASE_ADDRESS 0x02180000 + #define I2C1_BASE_ADDRESS 0x02190000 + #define I2C2_BASE_ADDRESS 0x021A0000 + #define I2C3_BASE_ADDRESS 0x02183000 + #define I2C_SIZE 0x10000 + #define DSPI_MEMORY_SIZE 0x10000 + #define DDRC_MEMORY_SIZE 0x10000 + #define SDXC_MEMORY_SIZE 0x10000 + #define LS1043A_TIMER_ADDR 0x02b00000 + #define IFC_REG_BASE_ADDR 0x1530000 + #define IFC_REG_SIZE 0x0003000 + #define SCFG_BASE_ADDR 0x1570000 + #define SCFG_SIZE 0x0010000 + +/* SMMU Defintions */ +#define SMMU_BASE_ADDR 0x09000000 +#define SMMU_REG_SCR0 (SMMU_BASE_ADDR + 0x0) +#define SMMU_REG_SACR (SMMU_BASE_ADDR + 0x10) +#define SMMU_REG_IDR1 (SMMU_BASE_ADDR + 0x24) +#define SMMU_REG_NSCR0 (SMMU_BASE_ADDR + 0x400) +#define SMMU_REG_NSACR (SMMU_BASE_ADDR + 0x410) + +#define SCR0_USFCFG_MASK 0x00000400 +#define SCR0_CLIENTPD_MASK 0x00000001 +#define SACR_PAGESIZE_MASK 0x00010000 +#define IDR1_PAGESIZE_MASK 0x80000000 + +#define LS1043A_OCRAM1_BASE_ADDR 0x10000000 +#define LS1043A_OCRAM1_SIZE 0x00010000 /* 64KB */ +#define LS1043A_OCRAM2_BASE_ADDR 0x10010000 +#define LS1043A_OCRAM2_SIZE 0x00010000 /* 64KB */ +#define LS1043A_STM_BASE_ADDR 0x12000000 +#define LS1043A_STM_SIZE 0x01000000 /* 16MB */ +#define LS1043A_DCSR_BASE_ADDR 0x20000000 +#define LS1043A_DCSR_SIZE 0x04000000 /* 64MB */ +#define LS1043A_QSPI_BASE_ADDR 0x40000000 +#define LS1043A_QSPI_SIZE 0x20000000 /* 512MB */ +#define LS1043A_IFC_REGION1_BASE_ADDR 0x60000000 +#define LS1043A_IFC_REGION1_BASE_SIZE 0x20000000 /* 512MB */ +#define LS1043A_DRAM1_BASE_ADDR 0x0080000000 +#define LS1043A_DRAM1_SIZE 0x0080000000 /* 2GB */ +#define LS1043A_QMAN_SWP_BASE_ADDR 0x0500000000 +#define LS1043A_QMAN_SWP_SIZE 0x0080000000 /* 128MB */ +#define LS1043A_BMAN_SWP_BASE_ADDR 0x0508000000 +#define LS1043A_BMAN_SWP_SIZE 0x0080000000 /* 128MB */ +#define LS1043A_IFC_REGION2_BASE_ADDR 0x0620000000 +#define LS1043A_IFC_REGION2_BASE_SIZE 0x00E0000000 /* 3.5GB */ +#define LS1043A_DRAM2_BASE_ADDR 0x0880000000 +#define LS1043A_DRAM2_SIZE 0x0780000000 /* 30GB */ +#define LS1043A_SERDES_ADDR (LS1043A_IMMR + 0xEA0000) +#define LS1043A_SRDS_1 +#define LS1043A_PCI_EXP1_BASE_ADDR 0x4000000000 +#define LS1043A_PCI_EXP1_BASE_SIZE 0x800000000 /* 32GB */ +#define LS1043A_PCI_EXP2_BASE_ADDR 0x4800000000 +#define LS1043A_PCI_EXP2_BASE_SIZE 0x800000000 /* 32GB */ +#define LS1043A_PCI_EXP3_BASE_ADDR 0x5000000000 +#define LS1043A_PCI_EXP3_BASE_SIZE 0x800000000 /* 32GB */ +#define LS1043A_DRAM3_BASE_ADDR 0x8800000000 +#define LS1043A_DRAM3_SIZE 0x7800000000 /* 480GB */ + +/* + * CPLD + */ +#define LS1043A_CPLD_BASE 0x7fb00000 + +/* + * Global defines + */ +#define NOR_BOOT 0x0 +#define NAND_BOOT 0x1 +#define SD_BOOT 0x2 + +/* PCI controllers addresses */ +#define LS1043A_PCIE1_PHYS_BASE 0x5000000000ULL +#define LS1043A_PCIE2_PHYS_BASE 0x4800000000ULL +#define LS1043A_PCIE3_PHYS_BASE 0x5000000000ULL + +#define LS1043A_PCIE1_PHYS_ADDR 0x5000000000ULL +#define LS1043A_PCIE2_PHYS_ADDR 0x4800000000ULL +#define LS1043A_PCIE3_PHYS_ADDR 0x5000000000ULL + +#define LS1043A_PCIE1_ADDR 0x03600000 +#define LS1043A_PCIE2_ADDR 0x03500000 +#define LS1043A_PCIE3_ADDR 0x03600000 + +/* PCIe */ +#define LS1043A_LS_PCI /* Enable PCI/PCIE */ +#define LS1043A_LS_PCIE1 /* PCIE controler 1 */ +#define LS1043A_LS_PCIE2 /* PCIE controler 2 */ +#define LS1043A_LS_PCIE3 /* PCIE controler 2 */ +#define LS1043A_LS_PCIE_LAYERSCAPE /* Use common FSL Layerscape PCIe code */ + +#define LS1043A_LS_PCI_64BIT + +#define LS1043A_LS_PCIE_CFG0_PHYS_OFF 0x00000000 +#define LS1043A_LS_PCIE_CFG0_SIZE 0x00001000 /* 4k */ +#define LS1043A_LS_PCIE_CFG1_PHYS_OFF 0x00001000 +#define LS1043A_LS_PCIE_CFG1_SIZE 0x00001000 /* 4k */ + +#define LS1043A_LS_PCIE_IO_BUS 0x00000000 +#define LS1043A_LS_PCIE_IO_PHYS_OFF 0x00010000 +#define LS1043A_LS_PCIE_IO_SIZE 0x00010000 /* 64k */ + +#define LS1043A_LS_PCIE_MEM_BUS 0x40000000 +#define LS1043A_LS_PCIE_MEM_PHYS_OFF 0x40000000 +#define LS1043A_LS_PCIE_MEM_SIZE 0x40000000 /* 1 GB */ + +#endif diff --git a/Platforms/Nxp/LS1043aRdb/Library/LS1043aRdbLib/Common.c b/Platforms/Nxp/LS1043aRdb/Library/LS1043aRdbLib/Common.c new file mode 100644 index 0000000..7159749 --- /dev/null +++ b/Platforms/Nxp/LS1043aRdb/Library/LS1043aRdbLib/Common.c @@ -0,0 +1,103 @@ +/** Common.c +* +* Copyright (c) 2016, Freescale Ltd. All rights reserved. +* +* This program and the accompanying materials +* are licensed and made available under the terms and conditions of the BSD License +* which accompanies this distribution. The full text of the license may be found at +* http://opensource.org/licenses/bsd-license.php +* +* THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, +* WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. +* +**/ + +#include <Library/PlatformLib.h> +#include <Library/DebugLib.h> + +UINT32 +__Div64_32 ( + IN UINT64 *N, + IN UINT32 Base + ) +{ + UINT64 Rem = *N; + UINT64 b = Base; + UINT64 Res, d = 1; + UINT32 High = Rem >> 32; + + /** Reduce the thing a bit first */ + Res = 0; + if (High >= Base) { + High /= Base; + Res = (UINT64) High << 32; + Rem -= (UINT64) (High*Base) << 32; + } + + while ((UINTN)b > 0 && b < Rem) { + b = b+b; + d = d+d; + } + + do { + if (Rem >= b) { + Rem -= b; + Res += d; + } + b >>= 1; + d >>= 1; + } while (d); + + *N = Res; + return Rem; +} + +/* + * PrINT32 Sizes As "Xxx KiB", "Xxx.Y KiB", "Xxx MiB", "Xxx.Y MiB", + * Xxx GiB, Xxx.Y GiB, Etc As Needed; Allow for Optional Trailing String + * (Like "\n") + */ +VOID +PrintSize ( + IN UINT64 Size, + IN CONST INT8 *S + ) +{ + UINT64 M = 0, N; + UINT64 F; + static CONST INT8 Names[] = {'E', 'P', 'T', 'G', 'M', 'K'}; + UINT64 D = 10 * ARRAY_SIZE(Names); + CHAR8 C = 0; + UINT32 I; + + for (I = 0; I < ARRAY_SIZE(Names); I++, D -= 10) { + if (Size >> D) { + C = Names[I]; + break; + } + } + + if (!C) { + DEBUG((EFI_D_ERROR, "%Ld Bytes,\n %a", Size, S)); + return; + } + + N = Size >> D; + F = Size & ((1ULL << D) - 1); + + /* if There'S A Remainder, Deal With It */ + if (F) { + M = (10ULL * F + (1ULL << (D - 1))) >> D; + + if (M >= 10) { + M -= 10; + N += 1; + } + } + + DEBUG((EFI_D_ERROR, "%Ld", N)); + if (M) { + DEBUG((EFI_D_ERROR, ".%Ld", M)); + } + DEBUG((EFI_D_ERROR, " %ciB, %a ", C, S)); +} diff --git a/Platforms/Nxp/LS1043aRdb/Library/LS1043aRdbLib/LS1043aRdb.c b/Platforms/Nxp/LS1043aRdb/Library/LS1043aRdbLib/LS1043aRdb.c new file mode 100644 index 0000000..4fcb8a3 --- /dev/null +++ b/Platforms/Nxp/LS1043aRdb/Library/LS1043aRdbLib/LS1043aRdb.c @@ -0,0 +1,107 @@ +/** LS1043aRdb.c +* +* RDB specific Library for LS1043A SoC, containing functions to initialize +* RDB boards. +* +* Based on BeagleBoardPkg/Library/BeagleBoardLib/BeagleBoard.c +* +* Copyright (c) 2011-2012, ARM Limited. All rights reserved. +* Copyright (c) 2016, Freescale Semiconductor, Inc. All rights reserved. +* +* This program and the accompanying materials +* are licensed and made available under the terms and conditions of the BSD License +* which accompanies this distribution. The full text of the license may be found at +* http://opensource.org/licenses/bsd-license.php +* +* THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, +* WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. +* +**/ + +#include <Library/IoLib.h> +#include <Library/ArmPlatformLib.h> +#include <Library/DebugLib.h> +#include <Library/PcdLib.h> +#include <Ppi/ArmMpCoreInfo.h> +#include <Library/PlatformLib.h> + +/** + Return the current Boot Mode + + This function returns the boot reason on the platform + +**/ +EFI_BOOT_MODE +ArmPlatformGetBootMode ( + VOID + ) +{ + return BOOT_WITH_FULL_CONFIGURATION; +} + +/** + Placeholder for Platform Initialization +**/ +RETURN_STATUS +ArmPlatformInitialize ( + IN UINTN MpId + ) +{ + return RETURN_SUCCESS; +} + +ARM_CORE_INFO LS1043aMpCoreInfoCTA53x4[] = { + { + // Cluster 0, Core 0 + 0x0, 0x0, + + // MP Core MailBox Set/Get/Clear Addresses and Clear Value + (EFI_PHYSICAL_ADDRESS)0, + (EFI_PHYSICAL_ADDRESS)0, + (EFI_PHYSICAL_ADDRESS)0, + (UINT64)0xFFFFFFFF + }, +}; + +EFI_STATUS +PrePeiCoreGetMpCoreInfo ( + OUT UINTN *CoreCount, + OUT ARM_CORE_INFO **ArmCoreTable + ) +{ + *CoreCount = sizeof(LS1043aMpCoreInfoCTA53x4) / sizeof(ARM_CORE_INFO); + *ArmCoreTable = LS1043aMpCoreInfoCTA53x4; + + return EFI_SUCCESS; +} + +// Needs to be declared in the file. Otherwise gArmMpCoreInfoPpiGuid is undefined in the contect of PrePeiCore +EFI_GUID mArmMpCoreInfoPpiGuid = ARM_MP_CORE_INFO_PPI_GUID; +ARM_MP_CORE_INFO_PPI mMpCoreInfoPpi = { PrePeiCoreGetMpCoreInfo }; + +EFI_PEI_PPI_DESCRIPTOR gPlatformPpiTable[] = { + { + EFI_PEI_PPI_DESCRIPTOR_PPI, + &mArmMpCoreInfoPpiGuid, + &mMpCoreInfoPpi + } +}; + +VOID +ArmPlatformGetPlatformPpiList ( + OUT UINTN *PpiListSize, + OUT EFI_PEI_PPI_DESCRIPTOR **PpiList + ) +{ + *PpiListSize = sizeof(gPlatformPpiTable); + *PpiList = gPlatformPpiTable; +} + + +UINTN +ArmPlatformGetCorePosition ( + IN UINTN MpId + ) +{ + return 1; +} diff --git a/Platforms/Nxp/LS1043aRdb/Library/LS1043aRdbLib/LS1043aRdbHelper.S b/Platforms/Nxp/LS1043aRdb/Library/LS1043aRdbLib/LS1043aRdbHelper.S new file mode 100644 index 0000000..5d9807f --- /dev/null +++ b/Platforms/Nxp/LS1043aRdb/Library/LS1043aRdbLib/LS1043aRdbHelper.S @@ -0,0 +1,61 @@ +# @file +# +# Based on BeagleBoardPkg/Library/BeagleBoardLib/BeagleBoardHelper.S +# +# Copyright (c) 2012-2013, ARM Limited. All rights reserved. +# Copyright (c) 2016, Freescale Semiconductor, Inc. All rights reserved. +# +# This program and the accompanying materials +# are licensed and made available under the terms and conditions of the BSD License +# which accompanies this distribution. The full text of the license may be found at +# http://opensource.org/licenses/bsd-license.php +# +# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, +# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. +# +# + +#include <AsmMacroIoLib.h> +#include <AsmMacroIoLibV8.h> +#include <AutoGen.h> + +.text +.align 2 + +GCC_ASM_EXPORT(ArmPlatformIsPrimaryCore) +GCC_ASM_EXPORT(ArmPlatformGetPrimaryCoreMpId) +GCC_ASM_EXPORT(ArmPlatformPeiBootAction) + +GCC_ASM_IMPORT(ArmReadMpidr) + +//UINTN +//ArmPlatformIsPrimaryCore ( +// IN UINTN MpId +// ); +ASM_PFX(ArmPlatformIsPrimaryCore): + and x1, x0, #3 + mov x0, #0 + cbnz x1, 1f + mov x0, #1 +1: + ret + +ASM_PFX(ArmPlatformPeiBootAction): +EL1_OR_EL2_OR_EL3(x0) +1: +2: + ret +3: + LoadConstantToReg(FixedPcdGet32(PcdCounterFrequency), x0) + msr cntfrq_el0, x0 + + ret + +//UINTN +//ArmPlatformGetPrimaryCoreMpId ( +// VOID +// ); +ASM_PFX(ArmPlatformGetPrimaryCoreMpId): + LoadConstantToReg (FixedPcdGet32(PcdArmPrimaryCore), x0) + ldrh w0, [x0] + ret diff --git a/Platforms/Nxp/LS1043aRdb/Library/LS1043aRdbLib/LS1043aRdbLib.inf b/Platforms/Nxp/LS1043aRdb/Library/LS1043aRdbLib/LS1043aRdbLib.inf new file mode 100644 index 0000000..e09d940 --- /dev/null +++ b/Platforms/Nxp/LS1043aRdb/Library/LS1043aRdbLib/LS1043aRdbLib.inf @@ -0,0 +1,56 @@ +#/* @file +# Copyright (c) 2011-2013, ARM Limited. All rights reserved. +# Copyright (c) 2016, Freescale Semiconductor, Inc. All rights reserved. +# +# This program and the accompanying materials +# are licensed and made available under the terms and conditions of the BSD License +# which accompanies this distribution. The full text of the license may be found at +# http://opensource.org/licenses/bsd-license.php +# +# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, +# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. +# +#*/ + +[Defines] + INF_VERSION = 0x00010005 + BASE_NAME = LS1043aRdbLib + FILE_GUID = 736343a0-1d96-11e0-aaaa-0002a5d5c51b + MODULE_TYPE = BASE + VERSION_STRING = 1.0 + LIBRARY_CLASS = ArmPlatformLib + +[Packages] + MdePkg/MdePkg.dec + MdeModulePkg/MdeModulePkg.dec + EmbeddedPkg/EmbeddedPkg.dec + ArmPkg/ArmPkg.dec + ArmPlatformPkg/ArmPlatformPkg.dec + OpenPlatformPkg/Platforms/Nxp/LS1043aRdb/LS1043aRdbPkg.dec + +[LibraryClasses] + IoLib + ArmLib + MemoryAllocationLib + I2cLib + DdrLib + SocLib + +[Sources.common] + LS1043aRdbHelper.S | GCC + LS1043aRdb.c + LS1043aRdbMem.c + Common.c + +[FeaturePcd] + gEmbeddedTokenSpaceGuid.PcdCacheEnable + +[FixedPcd] + gArmTokenSpaceGuid.PcdArmPrimaryCore + gArmTokenSpaceGuid.PcdFdBaseAddress + gArmTokenSpaceGuid.PcdFdSize + + gArmTokenSpaceGuid.PcdSystemMemoryBase + gArmTokenSpaceGuid.PcdSystemMemorySize + + gArmPlatformTokenSpaceGuid.PcdCounterFrequency diff --git a/Platforms/Nxp/LS1043aRdb/Library/LS1043aRdbLib/LS1043aRdbMem.c b/Platforms/Nxp/LS1043aRdb/Library/LS1043aRdbLib/LS1043aRdbMem.c new file mode 100644 index 0000000..ef93623 --- /dev/null +++ b/Platforms/Nxp/LS1043aRdb/Library/LS1043aRdbLib/LS1043aRdbMem.c @@ -0,0 +1,149 @@ +/** LS1043aRdbMem.c +* +* RDB memory specific Library for LS1043A SoC. +* +* Based on BeagleBoardPkg/Library/BeagleBoardLib/BeagleBoardMem.c +* +* Copyright (c) 2011, ARM Limited. All rights reserved. +* Copyright (c) 2016, Freescale Semiconductor, Inc. All rights reserved. +* +* This program and the accompanying materials +* are licensed and made available under the terms and conditions of the BSD License +* which accompanies this distribution. The full text of the license may be found at +* http://opensource.org/licenses/bsd-license.php +* +* THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, +* WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. +* +**/ + +#include <Library/ArmPlatformLib.h> +#include <Library/DebugLib.h> +#include <Library/PcdLib.h> +#include <Library/MemoryAllocationLib.h> +#include <Library/IoLib.h> + +#include <Library/PlatformLib.h> + +#define MAX_VIRTUAL_MEMORY_MAP_DESCRIPTORS 25 + +/** + Return the Virtual Memory Map of your platform + + This Virtual Memory Map is used by MemoryInitPei Module to initialize the MMU on your platform. + + @param[out] VirtualMemoryMap Array of ARM_MEMORY_REGION_DESCRIPTOR describing a Physical-to- + Virtual Memory mapping. This array must be ended by a zero-filled + entry + +**/ +VOID +ArmPlatformGetVirtualMemoryMap ( + IN ARM_MEMORY_REGION_DESCRIPTOR** VirtualMemoryMap + ) +{ + ARM_MEMORY_REGION_ATTRIBUTES CacheAttributes; + UINTN Index = 0; + ARM_MEMORY_REGION_DESCRIPTOR *VirtualMemoryTable; + + ASSERT(VirtualMemoryMap != NULL); + + VirtualMemoryTable = (ARM_MEMORY_REGION_DESCRIPTOR*)AllocatePages(EFI_SIZE_TO_PAGES (sizeof(ARM_MEMORY_REGION_DESCRIPTOR) * MAX_VIRTUAL_MEMORY_MAP_DESCRIPTORS)); + if (VirtualMemoryTable == NULL) { + return; + } + + if (FeaturePcdGet(PcdCacheEnable) == TRUE) { + CacheAttributes = DDR_ATTRIBUTES_CACHED; + } else { + CacheAttributes = DDR_ATTRIBUTES_UNCACHED; + } + + // DRAM1 (Must be 1st entry) + VirtualMemoryTable[Index].PhysicalBase = LS1043A_DRAM1_BASE_ADDR; + VirtualMemoryTable[Index].VirtualBase = LS1043A_DRAM1_BASE_ADDR; + VirtualMemoryTable[Index].Length = LS1043A_DRAM1_SIZE; + VirtualMemoryTable[Index].Attributes = CacheAttributes; + + // CCSR Space + VirtualMemoryTable[++Index].PhysicalBase = LS1043A_CCSR_BASE_ADDR; + VirtualMemoryTable[Index].VirtualBase = LS1043A_CCSR_BASE_ADDR; + VirtualMemoryTable[Index].Length = LS1043A_CCSR_SIZE; + VirtualMemoryTable[Index].Attributes = ARM_MEMORY_REGION_ATTRIBUTE_DEVICE; + + // OCRAM1 Space + VirtualMemoryTable[++Index].PhysicalBase = LS1043A_OCRAM1_BASE_ADDR; + VirtualMemoryTable[Index].VirtualBase = LS1043A_OCRAM1_BASE_ADDR; + VirtualMemoryTable[Index].Length = LS1043A_OCRAM1_SIZE; + VirtualMemoryTable[Index].Attributes = CacheAttributes; + + // OCRAM2 Space + VirtualMemoryTable[++Index].PhysicalBase = LS1043A_OCRAM2_BASE_ADDR; + VirtualMemoryTable[Index].VirtualBase = LS1043A_OCRAM2_BASE_ADDR; + VirtualMemoryTable[Index].Length = LS1043A_OCRAM2_SIZE; + VirtualMemoryTable[Index].Attributes = CacheAttributes; + + // IFC region 1 + VirtualMemoryTable[++Index].PhysicalBase = LS1043A_IFC_REGION1_BASE_ADDR; + VirtualMemoryTable[Index].VirtualBase = LS1043A_IFC_REGION1_BASE_ADDR; + VirtualMemoryTable[Index].Length = LS1043A_IFC_REGION1_BASE_SIZE; + VirtualMemoryTable[Index].Attributes = ARM_MEMORY_REGION_ATTRIBUTE_UNCACHED_UNBUFFERED; + + // QMAN SWP + VirtualMemoryTable[++Index].PhysicalBase = LS1043A_QMAN_SWP_BASE_ADDR; + VirtualMemoryTable[Index].VirtualBase = LS1043A_QMAN_SWP_BASE_ADDR; + VirtualMemoryTable[Index].Length = LS1043A_QMAN_SWP_SIZE; + VirtualMemoryTable[Index].Attributes = ARM_MEMORY_REGION_ATTRIBUTE_UNCACHED_UNBUFFERED; + + // BMAN SWP + VirtualMemoryTable[++Index].PhysicalBase = LS1043A_BMAN_SWP_BASE_ADDR; + VirtualMemoryTable[Index].VirtualBase = LS1043A_BMAN_SWP_BASE_ADDR; + VirtualMemoryTable[Index].Length = LS1043A_BMAN_SWP_SIZE; + VirtualMemoryTable[Index].Attributes = ARM_MEMORY_REGION_ATTRIBUTE_UNCACHED_UNBUFFERED; + + // IFC region 2 + VirtualMemoryTable[++Index].PhysicalBase = LS1043A_IFC_REGION2_BASE_ADDR; + VirtualMemoryTable[Index].VirtualBase = LS1043A_IFC_REGION2_BASE_ADDR; + VirtualMemoryTable[Index].Length = LS1043A_IFC_REGION2_BASE_SIZE; + VirtualMemoryTable[Index].Attributes = CacheAttributes; + + // DRAM2 + VirtualMemoryTable[++Index].PhysicalBase = LS1043A_DRAM2_BASE_ADDR; + VirtualMemoryTable[Index].VirtualBase = LS1043A_DRAM2_BASE_ADDR; + VirtualMemoryTable[Index].Length = LS1043A_DRAM2_SIZE; + VirtualMemoryTable[Index].Attributes = CacheAttributes; + + // PCIe1 + VirtualMemoryTable[++Index].PhysicalBase = LS1043A_PCI_EXP1_BASE_ADDR; + VirtualMemoryTable[Index].VirtualBase = LS1043A_PCI_EXP1_BASE_ADDR; + VirtualMemoryTable[Index].Length = LS1043A_PCI_EXP1_BASE_SIZE; + VirtualMemoryTable[Index].Attributes = ARM_MEMORY_REGION_ATTRIBUTE_DEVICE; + + // PCIe2 + VirtualMemoryTable[++Index].PhysicalBase = LS1043A_PCI_EXP2_BASE_ADDR; + VirtualMemoryTable[Index].VirtualBase = LS1043A_PCI_EXP2_BASE_ADDR; + VirtualMemoryTable[Index].Length = LS1043A_PCI_EXP2_BASE_SIZE; + VirtualMemoryTable[Index].Attributes = ARM_MEMORY_REGION_ATTRIBUTE_DEVICE; + + // PCIe3 + VirtualMemoryTable[++Index].PhysicalBase = LS1043A_PCI_EXP3_BASE_ADDR; + VirtualMemoryTable[Index].VirtualBase = LS1043A_PCI_EXP3_BASE_ADDR; + VirtualMemoryTable[Index].Length = LS1043A_PCI_EXP3_BASE_SIZE; + VirtualMemoryTable[Index].Attributes = ARM_MEMORY_REGION_ATTRIBUTE_DEVICE; + + // DRAM3 + VirtualMemoryTable[++Index].PhysicalBase = LS1043A_DRAM3_BASE_ADDR; + VirtualMemoryTable[Index].VirtualBase = LS1043A_DRAM3_BASE_ADDR; + VirtualMemoryTable[Index].Length = LS1043A_DRAM3_SIZE; + VirtualMemoryTable[Index].Attributes = CacheAttributes; + + // End of Table + VirtualMemoryTable[++Index].PhysicalBase = 0; + VirtualMemoryTable[Index].VirtualBase = 0; + VirtualMemoryTable[Index].Length = 0; + VirtualMemoryTable[Index].Attributes = (ARM_MEMORY_REGION_ATTRIBUTES)0; + + ASSERT((Index + 1) <= MAX_VIRTUAL_MEMORY_MAP_DESCRIPTORS); + + *VirtualMemoryMap = VirtualMemoryTable; +}
On 17 October 2016 at 21:04, Bhupesh Sharma bhupesh.sharma@freescale.com wrote:
From: Sakar Arora sakar.arora@nxp.com
This patch adds the basic support for NXP/FSL's LS1043A RDB board. LS1043A RDB board supports a number of on-board peripherals. This patch adds the basic framework for the same.
Further details about this board can be seen here: http://www.nxp.com/products/microcontrollers-and-processors/ arm-processors/qoriq-arm-processors/qoriq-ls1043a-reference-design-board:LS1043A-RDB
Signed-off-by: Sakar Arora sakar.arora@nxp.com Signed-off-by: Bhupesh Sharma bhupesh.sharma@nxp.com
Platforms/Nxp/LS1043aRdb/Include/Library/Common.h | 68 ++++++++ .../Nxp/LS1043aRdb/Include/Library/PlatformLib.h | 178 +++++++++++++++++++++ .../Nxp/LS1043aRdb/Library/LS1043aRdbLib/Common.c | 103 ++++++++++++ .../LS1043aRdb/Library/LS1043aRdbLib/LS1043aRdb.c | 107 +++++++++++++ .../Library/LS1043aRdbLib/LS1043aRdbHelper.S | 61 +++++++ .../Library/LS1043aRdbLib/LS1043aRdbLib.inf | 56 +++++++ .../Library/LS1043aRdbLib/LS1043aRdbMem.c | 149 +++++++++++++++++ 7 files changed, 722 insertions(+) create mode 100644 Platforms/Nxp/LS1043aRdb/Include/Library/Common.h create mode 100644 Platforms/Nxp/LS1043aRdb/Include/Library/PlatformLib.h create mode 100644 Platforms/Nxp/LS1043aRdb/Library/LS1043aRdbLib/Common.c create mode 100644 Platforms/Nxp/LS1043aRdb/Library/LS1043aRdbLib/LS1043aRdb.c create mode 100644 Platforms/Nxp/LS1043aRdb/Library/LS1043aRdbLib/LS1043aRdbHelper.S create mode 100644 Platforms/Nxp/LS1043aRdb/Library/LS1043aRdbLib/LS1043aRdbLib.inf create mode 100644 Platforms/Nxp/LS1043aRdb/Library/LS1043aRdbLib/LS1043aRdbMem.c
diff --git a/Platforms/Nxp/LS1043aRdb/Include/Library/Common.h b/Platforms/Nxp/LS1043aRdb/Include/Library/Common.h new file mode 100644 index 0000000..192a249 --- /dev/null +++ b/Platforms/Nxp/LS1043aRdb/Include/Library/Common.h @@ -0,0 +1,68 @@ +/** @Common.h
- Header defining the General Purpose Utilities
- Copyright (c) 2016, Freescale Semiconductor, Inc. All rights reserved.
- This program and the accompanying materials
- are licensed and made available under the terms and conditions of the BSD License
- which accompanies this distribution. The full text of the license may be found at
- http://opensource.org/licenses/bsd-license.php
- THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
- WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
+**/
+#ifndef __COMMON_H__ +#define __COMMON_H__
+#define DMA_MINALIGN 64
+#define offsetof(TYPE, MEMBER) ((UINTN) &((TYPE *)0)->MEMBER)
+typedef UINTN PhysAddrT; +typedef UINTN PhysSizeT;
+static inline PhysAddrT VirtToPhys(VOID * VAddr) +{
return (PhysAddrT)(VAddr);
+}
+/*
- The ALLOC_CACHE_ALIGN_BUF macro is used to allocate a buffer
- that meets the minimum architecture alignment requirements for DMA.
- The resulting buffer is aligned to the value of DMA_MINALIGN.
- The buffer variable created is a pointer to the specified type, and
- NOT an array.
- The size parameter is the number of array elements to allocate.
- */
+#define ALIGN_BUFF(x,a) ALIGN_MSK((x),(typeof(x))(a)-1) +#define ALIGN_MSK(x,mask) (((x)+(mask))&~(mask))
+#define PAD_CNT(S, Pad) (((S) - 1) / (Pad) + 1) +#define PAD_SIZE(S, Pad) (PAD_CNT(S, Pad) * Pad)
+#define ROUND_OFF(a,b) (((a) + (b) - 1) & ~((b) - 1))
+#define DMA_MINALIGN 64
+#define ALLOC_ALIGN_BUF_PAD(Type, Name, Size, Align, Pad) \
INT8 __##Name[ROUND_OFF(PAD_SIZE((Size) * sizeof(Type), Pad), Align) \
+ (Align - 1)]; \
\
Type *Name = (Type *) ALIGN_BUFF((UINTN)__##Name, Align)
+#define ALLOC_ALIGN_BUF(Type, Name, Size, Align) \
ALLOC_ALIGN_BUF_PAD(Type, Name, Size, Align, 1)
+#define ALLOC_CACHE_ALIGN_BUF_PAD(Type, Name, Size, Pad) \
ALLOC_ALIGN_BUF_PAD(Type, Name, size, DMA_MINALIGN, Pad)
+#define ALLOC_CACHE_ALIGN_BUF(Type, Name, Size) \
ALLOC_ALIGN_BUF(Type, Name, Size, DMA_MINALIGN)
+#endif diff --git a/Platforms/Nxp/LS1043aRdb/Include/Library/PlatformLib.h b/Platforms/Nxp/LS1043aRdb/Include/Library/PlatformLib.h new file mode 100644 index 0000000..39247e8 --- /dev/null +++ b/Platforms/Nxp/LS1043aRdb/Include/Library/PlatformLib.h @@ -0,0 +1,178 @@ +/** LS1043aRdb.h +* Header defining the LS1043aRdb constants (Base addresses, sizes, flags) +* +* Copyright (c) 2016, Freescale Semiconductor, Inc. All rights reserved. +* +* This program and the accompanying materials +* are licensed and made available under the terms and conditions of the BSD License +* which accompanies this distribution. The full text of the license may be found at +* http://opensource.org/licenses/bsd-license.php +* +* THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, +* WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. +* +**/
+#ifndef __LS1043aRDB_PLATFORM_H__ +#define __LS1043aRDB_PLATFORM_H__
+// Types +#define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
+// DDR attributes +#define DDR_ATTRIBUTES_CACHED ARM_MEMORY_REGION_ATTRIBUTE_WRITE_BACK +#define DDR_ATTRIBUTES_UNCACHED ARM_MEMORY_REGION_ATTRIBUTE_UNCACHED_UNBUFFERED
+#define LS1043A_CACHELINE_SIZE 32
+#define LS1043A_SECURE_BOOTROM_BASE_ADDR 0x00000000 +#define LS1043A_SECURE_BOOTROM_SIZE 0x00100000 /* 1MB */ +#define LS1043A_EXT_BOOTROM_BASE_ADDR 0x00100000 +#define LS1043A_EXT_BOOTROM_SIZE 0x00F00000 /* 15MB */ +#define LS1043A_CCSR_BASE_ADDR 0x01000000 +#define LS1043A_CCSR_SIZE 0x0F000000 /* 240MB */
#define LS1043A_IMMR 0x01000000
#define LS1043A_DDR_ADDR 0x01080000
#define LS1043A_DSPI_ADDR 0x02100000
#define LS1043A_SDXC_ADDR 0x01560000
#define LS1043A_CCI400_ADDR (LS1043A_IMMR + 0x00180000)
#define LS1043A_TZASC380_ADDR (LS1043A_IMMR + 0x00500000)
#define LS1043A_CSU_ADDR (LS1043A_IMMR + 0x00510000)
#define LS1043A_GUTS_ADDR (LS1043A_IMMR + 0x00ee0000)
#define LS1043A_CLK_ADDR (LS1043A_IMMR + 0x00ee1000)
#define LS1043A_FMAN_ADDR (LS1043A_IMMR + 0x00a00000)
#define LS1043A_BMAN_ADDR (LS1043A_IMMR + 0x00890000)
#define LS1043A_QMAN_ADDR (LS1043A_IMMR + 0x00880000)
#define GIC_BASE_ADDR 0x01402000
#define GIC_SIZE 0x1000
#define GICDIST_BASE_ADDR 0x01401000
#define GICDIST_SIZE 0x1000
#define DUART1_BASE_ADDR 0x21C0000
#define DUART1_SIZE 0x1000
#define DUART2_BASE_ADDR 0x21D0000
#define DUART2_SIZE 0x1000
#define WDOG1_BASE_ADDR 0x02AD0000
#define WDOG2_BASE_ADDR 0x02AE0000
#define WDOG3_BASE_ADDR 0x02A70000
#define WDOG4_BASE_ADDR 0x02A80000
#define WDOG5_BASE_ADDR 0x02A90000
#define WDOG_SIZE 0x1000
#define WDOG_WCR_OFFSET 0
#define WDOG_WSR_OFFSET 2
#define WDOG_WRSR_OFFSET 4
#define WDOG_WICR_OFFSET 6
#define WDOG_WCR_WT (0xFF << 8)
#define WDOG_WCR_WDE (1 << 2)
#define WDOG_SERVICE_SEQ1 0x5555
#define WDOG_SERVICE_SEQ2 0xAAAA
#define WDOG_WCR_WDZST 0x1
#define WDOG_WCR_WRE (1 << 3) /* -> WDOG Reset Enable */
#define I2C0_BASE_ADDRESS 0x02180000
#define I2C1_BASE_ADDRESS 0x02190000
#define I2C2_BASE_ADDRESS 0x021A0000
#define I2C3_BASE_ADDRESS 0x02183000
#define I2C_SIZE 0x10000
#define DSPI_MEMORY_SIZE 0x10000
#define DDRC_MEMORY_SIZE 0x10000
#define SDXC_MEMORY_SIZE 0x10000
#define LS1043A_TIMER_ADDR 0x02b00000
#define IFC_REG_BASE_ADDR 0x1530000
#define IFC_REG_SIZE 0x0003000
#define SCFG_BASE_ADDR 0x1570000
#define SCFG_SIZE 0x0010000
+/* SMMU Defintions */ +#define SMMU_BASE_ADDR 0x09000000 +#define SMMU_REG_SCR0 (SMMU_BASE_ADDR + 0x0) +#define SMMU_REG_SACR (SMMU_BASE_ADDR + 0x10) +#define SMMU_REG_IDR1 (SMMU_BASE_ADDR + 0x24) +#define SMMU_REG_NSCR0 (SMMU_BASE_ADDR + 0x400) +#define SMMU_REG_NSACR (SMMU_BASE_ADDR + 0x410)
+#define SCR0_USFCFG_MASK 0x00000400 +#define SCR0_CLIENTPD_MASK 0x00000001 +#define SACR_PAGESIZE_MASK 0x00010000 +#define IDR1_PAGESIZE_MASK 0x80000000
+#define LS1043A_OCRAM1_BASE_ADDR 0x10000000 +#define LS1043A_OCRAM1_SIZE 0x00010000 /* 64KB */ +#define LS1043A_OCRAM2_BASE_ADDR 0x10010000 +#define LS1043A_OCRAM2_SIZE 0x00010000 /* 64KB */ +#define LS1043A_STM_BASE_ADDR 0x12000000 +#define LS1043A_STM_SIZE 0x01000000 /* 16MB */ +#define LS1043A_DCSR_BASE_ADDR 0x20000000 +#define LS1043A_DCSR_SIZE 0x04000000 /* 64MB */ +#define LS1043A_QSPI_BASE_ADDR 0x40000000 +#define LS1043A_QSPI_SIZE 0x20000000 /* 512MB */ +#define LS1043A_IFC_REGION1_BASE_ADDR 0x60000000 +#define LS1043A_IFC_REGION1_BASE_SIZE 0x20000000 /* 512MB */ +#define LS1043A_DRAM1_BASE_ADDR 0x0080000000 +#define LS1043A_DRAM1_SIZE 0x0080000000 /* 2GB */ +#define LS1043A_QMAN_SWP_BASE_ADDR 0x0500000000 +#define LS1043A_QMAN_SWP_SIZE 0x0080000000 /* 128MB */ +#define LS1043A_BMAN_SWP_BASE_ADDR 0x0508000000 +#define LS1043A_BMAN_SWP_SIZE 0x0080000000 /* 128MB */ +#define LS1043A_IFC_REGION2_BASE_ADDR 0x0620000000 +#define LS1043A_IFC_REGION2_BASE_SIZE 0x00E0000000 /* 3.5GB */ +#define LS1043A_DRAM2_BASE_ADDR 0x0880000000 +#define LS1043A_DRAM2_SIZE 0x0780000000 /* 30GB */ +#define LS1043A_SERDES_ADDR (LS1043A_IMMR + 0xEA0000) +#define LS1043A_SRDS_1 +#define LS1043A_PCI_EXP1_BASE_ADDR 0x4000000000 +#define LS1043A_PCI_EXP1_BASE_SIZE 0x800000000 /* 32GB */ +#define LS1043A_PCI_EXP2_BASE_ADDR 0x4800000000 +#define LS1043A_PCI_EXP2_BASE_SIZE 0x800000000 /* 32GB */ +#define LS1043A_PCI_EXP3_BASE_ADDR 0x5000000000 +#define LS1043A_PCI_EXP3_BASE_SIZE 0x800000000 /* 32GB */ +#define LS1043A_DRAM3_BASE_ADDR 0x8800000000 +#define LS1043A_DRAM3_SIZE 0x7800000000 /* 480GB */
+/*
- CPLD
- */
+#define LS1043A_CPLD_BASE 0x7fb00000
+/*
- Global defines
- */
+#define NOR_BOOT 0x0 +#define NAND_BOOT 0x1 +#define SD_BOOT 0x2
+/* PCI controllers addresses */ +#define LS1043A_PCIE1_PHYS_BASE 0x5000000000ULL +#define LS1043A_PCIE2_PHYS_BASE 0x4800000000ULL +#define LS1043A_PCIE3_PHYS_BASE 0x5000000000ULL
+#define LS1043A_PCIE1_PHYS_ADDR 0x5000000000ULL +#define LS1043A_PCIE2_PHYS_ADDR 0x4800000000ULL +#define LS1043A_PCIE3_PHYS_ADDR 0x5000000000ULL
+#define LS1043A_PCIE1_ADDR 0x03600000 +#define LS1043A_PCIE2_ADDR 0x03500000 +#define LS1043A_PCIE3_ADDR 0x03600000
+/* PCIe */ +#define LS1043A_LS_PCI /* Enable PCI/PCIE */ +#define LS1043A_LS_PCIE1 /* PCIE controler 1 */ +#define LS1043A_LS_PCIE2 /* PCIE controler 2 */ +#define LS1043A_LS_PCIE3 /* PCIE controler 2 */ +#define LS1043A_LS_PCIE_LAYERSCAPE /* Use common FSL Layerscape PCIe code */
+#define LS1043A_LS_PCI_64BIT
+#define LS1043A_LS_PCIE_CFG0_PHYS_OFF 0x00000000 +#define LS1043A_LS_PCIE_CFG0_SIZE 0x00001000 /* 4k */ +#define LS1043A_LS_PCIE_CFG1_PHYS_OFF 0x00001000 +#define LS1043A_LS_PCIE_CFG1_SIZE 0x00001000 /* 4k */
+#define LS1043A_LS_PCIE_IO_BUS 0x00000000 +#define LS1043A_LS_PCIE_IO_PHYS_OFF 0x00010000 +#define LS1043A_LS_PCIE_IO_SIZE 0x00010000 /* 64k */
+#define LS1043A_LS_PCIE_MEM_BUS 0x40000000 +#define LS1043A_LS_PCIE_MEM_PHYS_OFF 0x40000000 +#define LS1043A_LS_PCIE_MEM_SIZE 0x40000000 /* 1 GB */
+#endif diff --git a/Platforms/Nxp/LS1043aRdb/Library/LS1043aRdbLib/Common.c b/Platforms/Nxp/LS1043aRdb/Library/LS1043aRdbLib/Common.c new file mode 100644 index 0000000..7159749 --- /dev/null +++ b/Platforms/Nxp/LS1043aRdb/Library/LS1043aRdbLib/Common.c @@ -0,0 +1,103 @@ +/** Common.c +* +* Copyright (c) 2016, Freescale Ltd. All rights reserved. +* +* This program and the accompanying materials +* are licensed and made available under the terms and conditions of the BSD License +* which accompanies this distribution. The full text of the license may be found at +* http://opensource.org/licenses/bsd-license.php +* +* THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, +* WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. +* +**/
+#include <Library/PlatformLib.h> +#include <Library/DebugLib.h>
+UINT32 +__Div64_32 (
- IN UINT64 *N,
- IN UINT32 Base
- )
+{
- UINT64 Rem = *N;
- UINT64 b = Base;
- UINT64 Res, d = 1;
- UINT32 High = Rem >> 32;
- /** Reduce the thing a bit first */
- Res = 0;
- if (High >= Base) {
- High /= Base;
- Res = (UINT64) High << 32;
- Rem -= (UINT64) (High*Base) << 32;
- }
- while ((UINTN)b > 0 && b < Rem) {
- b = b+b;
- d = d+d;
- }
- do {
- if (Rem >= b) {
Rem -= b;
Res += d;
- }
- b >>= 1;
- d >>= 1;
- } while (d);
- *N = Res;
- return Rem;
+}
Why do we need this?
+/*
- PrINT32 Sizes As "Xxx KiB", "Xxx.Y KiB", "Xxx MiB", "Xxx.Y MiB",
- Xxx GiB, Xxx.Y GiB, Etc As Needed; Allow for Optional Trailing String
- (Like "\n")
- */
+VOID +PrintSize (
- IN UINT64 Size,
- IN CONST INT8 *S
- )
+{
- UINT64 M = 0, N;
- UINT64 F;
- static CONST INT8 Names[] = {'E', 'P', 'T', 'G', 'M', 'K'};
- UINT64 D = 10 * ARRAY_SIZE(Names);
- CHAR8 C = 0;
- UINT32 I;
- for (I = 0; I < ARRAY_SIZE(Names); I++, D -= 10) {
- if (Size >> D) {
C = Names[I];
break;
- }
- }
- if (!C) {
- DEBUG((EFI_D_ERROR, "%Ld Bytes,\n %a", Size, S));
- return;
- }
- N = Size >> D;
- F = Size & ((1ULL << D) - 1);
- /* if There'S A Remainder, Deal With It */
- if (F) {
- M = (10ULL * F + (1ULL << (D - 1))) >> D;
- if (M >= 10) {
M -= 10;
N += 1;
- }
- }
- DEBUG((EFI_D_ERROR, "%Ld", N));
- if (M) {
- DEBUG((EFI_D_ERROR, ".%Ld", M));
- }
- DEBUG((EFI_D_ERROR, " %ciB, %a ", C, S));
+} diff --git a/Platforms/Nxp/LS1043aRdb/Library/LS1043aRdbLib/LS1043aRdb.c b/Platforms/Nxp/LS1043aRdb/Library/LS1043aRdbLib/LS1043aRdb.c new file mode 100644 index 0000000..4fcb8a3 --- /dev/null +++ b/Platforms/Nxp/LS1043aRdb/Library/LS1043aRdbLib/LS1043aRdb.c @@ -0,0 +1,107 @@ +/** LS1043aRdb.c +* +* RDB specific Library for LS1043A SoC, containing functions to initialize +* RDB boards. +* +* Based on BeagleBoardPkg/Library/BeagleBoardLib/BeagleBoard.c +* +* Copyright (c) 2011-2012, ARM Limited. All rights reserved. +* Copyright (c) 2016, Freescale Semiconductor, Inc. All rights reserved. +* +* This program and the accompanying materials +* are licensed and made available under the terms and conditions of the BSD License +* which accompanies this distribution. The full text of the license may be found at +* http://opensource.org/licenses/bsd-license.php +* +* THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, +* WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. +* +**/
+#include <Library/IoLib.h> +#include <Library/ArmPlatformLib.h> +#include <Library/DebugLib.h> +#include <Library/PcdLib.h> +#include <Ppi/ArmMpCoreInfo.h> +#include <Library/PlatformLib.h>
+/**
- Return the current Boot Mode
- This function returns the boot reason on the platform
+**/ +EFI_BOOT_MODE +ArmPlatformGetBootMode (
- VOID
- )
+{
- return BOOT_WITH_FULL_CONFIGURATION;
+}
+/**
- Placeholder for Platform Initialization
+**/ +RETURN_STATUS +ArmPlatformInitialize (
- IN UINTN MpId
- )
+{
- return RETURN_SUCCESS;
+}
+ARM_CORE_INFO LS1043aMpCoreInfoCTA53x4[] = {
- {
- // Cluster 0, Core 0
- 0x0, 0x0,
- // MP Core MailBox Set/Get/Clear Addresses and Clear Value
- (EFI_PHYSICAL_ADDRESS)0,
- (EFI_PHYSICAL_ADDRESS)0,
- (EFI_PHYSICAL_ADDRESS)0,
- (UINT64)0xFFFFFFFF
- },
+};
+EFI_STATUS +PrePeiCoreGetMpCoreInfo (
- OUT UINTN *CoreCount,
- OUT ARM_CORE_INFO **ArmCoreTable
- )
+{
- *CoreCount = sizeof(LS1043aMpCoreInfoCTA53x4) / sizeof(ARM_CORE_INFO);
- *ArmCoreTable = LS1043aMpCoreInfoCTA53x4;
- return EFI_SUCCESS;
+}
+// Needs to be declared in the file. Otherwise gArmMpCoreInfoPpiGuid is undefined in the contect of PrePeiCore
This is not true, and has been fixed upstream. You simply need to add gArmMpCoreInfoPpiGuid to the [Guids] section of the .inf
+EFI_GUID mArmMpCoreInfoPpiGuid = ARM_MP_CORE_INFO_PPI_GUID;' +ARM_MP_CORE_INFO_PPI mMpCoreInfoPpi = { PrePeiCoreGetMpCoreInfo };
+EFI_PEI_PPI_DESCRIPTOR gPlatformPpiTable[] = {
- {
- EFI_PEI_PPI_DESCRIPTOR_PPI,
- &mArmMpCoreInfoPpiGuid,
- &mMpCoreInfoPpi
- }
+};
+VOID +ArmPlatformGetPlatformPpiList (
- OUT UINTN *PpiListSize,
- OUT EFI_PEI_PPI_DESCRIPTOR **PpiList
- )
+{
- *PpiListSize = sizeof(gPlatformPpiTable);
- *PpiList = gPlatformPpiTable;
+}
+UINTN +ArmPlatformGetCorePosition (
- IN UINTN MpId
- )
+{
- return 1;
+} diff --git a/Platforms/Nxp/LS1043aRdb/Library/LS1043aRdbLib/LS1043aRdbHelper.S b/Platforms/Nxp/LS1043aRdb/Library/LS1043aRdbLib/LS1043aRdbHelper.S new file mode 100644 index 0000000..5d9807f --- /dev/null +++ b/Platforms/Nxp/LS1043aRdb/Library/LS1043aRdbLib/LS1043aRdbHelper.S @@ -0,0 +1,61 @@ +# @file +# +# Based on BeagleBoardPkg/Library/BeagleBoardLib/BeagleBoardHelper.S +# +# Copyright (c) 2012-2013, ARM Limited. All rights reserved. +# Copyright (c) 2016, Freescale Semiconductor, Inc. All rights reserved. +# +# This program and the accompanying materials +# are licensed and made available under the terms and conditions of the BSD License +# which accompanies this distribution. The full text of the license may be found at +# http://opensource.org/licenses/bsd-license.php +# +# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, +# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. +# +#
+#include <AsmMacroIoLib.h> +#include <AsmMacroIoLibV8.h> +#include <AutoGen.h>
+.text +.align 2
+GCC_ASM_EXPORT(ArmPlatformIsPrimaryCore) +GCC_ASM_EXPORT(ArmPlatformGetPrimaryCoreMpId) +GCC_ASM_EXPORT(ArmPlatformPeiBootAction)
+GCC_ASM_IMPORT(ArmReadMpidr)
+//UINTN +//ArmPlatformIsPrimaryCore ( +// IN UINTN MpId +// ); +ASM_PFX(ArmPlatformIsPrimaryCore):
and x1, x0, #3
mov x0, #0
- cbnz x1, 1f
mov x0, #1
+1:
- ret
How about
tst x0, #3 cset x0, eq ret
+ASM_PFX(ArmPlatformPeiBootAction): +EL1_OR_EL2_OR_EL3(x0) +1: +2:
ret
+3:
LoadConstantToReg(FixedPcdGet32(PcdCounterFrequency), x0)
Please don't use LoadConstantToReg(), you can use MOV32() or MOV64 instead.
msr cntfrq_el0, x0
ret
+//UINTN +//ArmPlatformGetPrimaryCoreMpId ( +// VOID +// ); +ASM_PFX(ArmPlatformGetPrimaryCoreMpId):
- LoadConstantToReg (FixedPcdGet32(PcdArmPrimaryCore), x0)
- ldrh w0, [x0]
Same here. FixedPcdGet32(PcdArmPrimaryCore) resolves to a literal constant, no need for the ldr
- ret
diff --git a/Platforms/Nxp/LS1043aRdb/Library/LS1043aRdbLib/LS1043aRdbLib.inf b/Platforms/Nxp/LS1043aRdb/Library/LS1043aRdbLib/LS1043aRdbLib.inf new file mode 100644 index 0000000..e09d940 --- /dev/null +++ b/Platforms/Nxp/LS1043aRdb/Library/LS1043aRdbLib/LS1043aRdbLib.inf @@ -0,0 +1,56 @@ +#/* @file +# Copyright (c) 2011-2013, ARM Limited. All rights reserved. +# Copyright (c) 2016, Freescale Semiconductor, Inc. All rights reserved. +# +# This program and the accompanying materials +# are licensed and made available under the terms and conditions of the BSD License +# which accompanies this distribution. The full text of the license may be found at +# http://opensource.org/licenses/bsd-license.php +# +# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, +# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. +# +#*/
+[Defines]
- INF_VERSION = 0x00010005
- BASE_NAME = LS1043aRdbLib
- FILE_GUID = 736343a0-1d96-11e0-aaaa-0002a5d5c51b
Please use a fresh GUID here
- MODULE_TYPE = BASE
- VERSION_STRING = 1.0
- LIBRARY_CLASS = ArmPlatformLib
+[Packages]
- MdePkg/MdePkg.dec
- MdeModulePkg/MdeModulePkg.dec
- EmbeddedPkg/EmbeddedPkg.dec
- ArmPkg/ArmPkg.dec
- ArmPlatformPkg/ArmPlatformPkg.dec
- OpenPlatformPkg/Platforms/Nxp/LS1043aRdb/LS1043aRdbPkg.dec
+[LibraryClasses]
- IoLib
- ArmLib
- MemoryAllocationLib
- I2cLib
- DdrLib
- SocLib
+[Sources.common]
- LS1043aRdbHelper.S | GCC
- LS1043aRdb.c
- LS1043aRdbMem.c
- Common.c
+[FeaturePcd]
- gEmbeddedTokenSpaceGuid.PcdCacheEnable
+[FixedPcd]
- gArmTokenSpaceGuid.PcdArmPrimaryCore
- gArmTokenSpaceGuid.PcdFdBaseAddress
- gArmTokenSpaceGuid.PcdFdSize
- gArmTokenSpaceGuid.PcdSystemMemoryBase
- gArmTokenSpaceGuid.PcdSystemMemorySize
- gArmPlatformTokenSpaceGuid.PcdCounterFrequency
diff --git a/Platforms/Nxp/LS1043aRdb/Library/LS1043aRdbLib/LS1043aRdbMem.c b/Platforms/Nxp/LS1043aRdb/Library/LS1043aRdbLib/LS1043aRdbMem.c new file mode 100644 index 0000000..ef93623 --- /dev/null +++ b/Platforms/Nxp/LS1043aRdb/Library/LS1043aRdbLib/LS1043aRdbMem.c @@ -0,0 +1,149 @@ +/** LS1043aRdbMem.c +* +* RDB memory specific Library for LS1043A SoC. +* +* Based on BeagleBoardPkg/Library/BeagleBoardLib/BeagleBoardMem.c +* +* Copyright (c) 2011, ARM Limited. All rights reserved. +* Copyright (c) 2016, Freescale Semiconductor, Inc. All rights reserved. +* +* This program and the accompanying materials +* are licensed and made available under the terms and conditions of the BSD License +* which accompanies this distribution. The full text of the license may be found at +* http://opensource.org/licenses/bsd-license.php +* +* THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, +* WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. +* +**/
+#include <Library/ArmPlatformLib.h> +#include <Library/DebugLib.h> +#include <Library/PcdLib.h> +#include <Library/MemoryAllocationLib.h> +#include <Library/IoLib.h>
+#include <Library/PlatformLib.h>
+#define MAX_VIRTUAL_MEMORY_MAP_DESCRIPTORS 25
+/**
- Return the Virtual Memory Map of your platform
- This Virtual Memory Map is used by MemoryInitPei Module to initialize the MMU on your platform.
- @param[out] VirtualMemoryMap Array of ARM_MEMORY_REGION_DESCRIPTOR describing a Physical-to-
Virtual Memory mapping. This array must be ended by a zero-filled
entry
+**/ +VOID +ArmPlatformGetVirtualMemoryMap (
- IN ARM_MEMORY_REGION_DESCRIPTOR** VirtualMemoryMap
- )
+{
- ARM_MEMORY_REGION_ATTRIBUTES CacheAttributes;
- UINTN Index = 0;
- ARM_MEMORY_REGION_DESCRIPTOR *VirtualMemoryTable;
- ASSERT(VirtualMemoryMap != NULL);
- VirtualMemoryTable = (ARM_MEMORY_REGION_DESCRIPTOR*)AllocatePages(EFI_SIZE_TO_PAGES (sizeof(ARM_MEMORY_REGION_DESCRIPTOR) * MAX_VIRTUAL_MEMORY_MAP_DESCRIPTORS));
- if (VirtualMemoryTable == NULL) {
- return;
- }
- if (FeaturePcdGet(PcdCacheEnable) == TRUE) {
- CacheAttributes = DDR_ATTRIBUTES_CACHED;
- } else {
- CacheAttributes = DDR_ATTRIBUTES_UNCACHED;
- }
- // DRAM1 (Must be 1st entry)
Why? Because the regions overlap? If so, please document that more explicitly.
- VirtualMemoryTable[Index].PhysicalBase = LS1043A_DRAM1_BASE_ADDR;
- VirtualMemoryTable[Index].VirtualBase = LS1043A_DRAM1_BASE_ADDR;
- VirtualMemoryTable[Index].Length = LS1043A_DRAM1_SIZE;
- VirtualMemoryTable[Index].Attributes = CacheAttributes;
- // CCSR Space
- VirtualMemoryTable[++Index].PhysicalBase = LS1043A_CCSR_BASE_ADDR;
- VirtualMemoryTable[Index].VirtualBase = LS1043A_CCSR_BASE_ADDR;
- VirtualMemoryTable[Index].Length = LS1043A_CCSR_SIZE;
- VirtualMemoryTable[Index].Attributes = ARM_MEMORY_REGION_ATTRIBUTE_DEVICE;
- // OCRAM1 Space
- VirtualMemoryTable[++Index].PhysicalBase = LS1043A_OCRAM1_BASE_ADDR;
- VirtualMemoryTable[Index].VirtualBase = LS1043A_OCRAM1_BASE_ADDR;
- VirtualMemoryTable[Index].Length = LS1043A_OCRAM1_SIZE;
- VirtualMemoryTable[Index].Attributes = CacheAttributes;
- // OCRAM2 Space
- VirtualMemoryTable[++Index].PhysicalBase = LS1043A_OCRAM2_BASE_ADDR;
- VirtualMemoryTable[Index].VirtualBase = LS1043A_OCRAM2_BASE_ADDR;
- VirtualMemoryTable[Index].Length = LS1043A_OCRAM2_SIZE;
- VirtualMemoryTable[Index].Attributes = CacheAttributes;
- // IFC region 1
- VirtualMemoryTable[++Index].PhysicalBase = LS1043A_IFC_REGION1_BASE_ADDR;
- VirtualMemoryTable[Index].VirtualBase = LS1043A_IFC_REGION1_BASE_ADDR;
- VirtualMemoryTable[Index].Length = LS1043A_IFC_REGION1_BASE_SIZE;
- VirtualMemoryTable[Index].Attributes = ARM_MEMORY_REGION_ATTRIBUTE_UNCACHED_UNBUFFERED;
- // QMAN SWP
- VirtualMemoryTable[++Index].PhysicalBase = LS1043A_QMAN_SWP_BASE_ADDR;
- VirtualMemoryTable[Index].VirtualBase = LS1043A_QMAN_SWP_BASE_ADDR;
- VirtualMemoryTable[Index].Length = LS1043A_QMAN_SWP_SIZE;
- VirtualMemoryTable[Index].Attributes = ARM_MEMORY_REGION_ATTRIBUTE_UNCACHED_UNBUFFERED;
- // BMAN SWP
- VirtualMemoryTable[++Index].PhysicalBase = LS1043A_BMAN_SWP_BASE_ADDR;
- VirtualMemoryTable[Index].VirtualBase = LS1043A_BMAN_SWP_BASE_ADDR;
- VirtualMemoryTable[Index].Length = LS1043A_BMAN_SWP_SIZE;
- VirtualMemoryTable[Index].Attributes = ARM_MEMORY_REGION_ATTRIBUTE_UNCACHED_UNBUFFERED;
- // IFC region 2
- VirtualMemoryTable[++Index].PhysicalBase = LS1043A_IFC_REGION2_BASE_ADDR;
- VirtualMemoryTable[Index].VirtualBase = LS1043A_IFC_REGION2_BASE_ADDR;
- VirtualMemoryTable[Index].Length = LS1043A_IFC_REGION2_BASE_SIZE;
- VirtualMemoryTable[Index].Attributes = CacheAttributes;
- // DRAM2
- VirtualMemoryTable[++Index].PhysicalBase = LS1043A_DRAM2_BASE_ADDR;
- VirtualMemoryTable[Index].VirtualBase = LS1043A_DRAM2_BASE_ADDR;
- VirtualMemoryTable[Index].Length = LS1043A_DRAM2_SIZE;
- VirtualMemoryTable[Index].Attributes = CacheAttributes;
- // PCIe1
- VirtualMemoryTable[++Index].PhysicalBase = LS1043A_PCI_EXP1_BASE_ADDR;
- VirtualMemoryTable[Index].VirtualBase = LS1043A_PCI_EXP1_BASE_ADDR;
- VirtualMemoryTable[Index].Length = LS1043A_PCI_EXP1_BASE_SIZE;
- VirtualMemoryTable[Index].Attributes = ARM_MEMORY_REGION_ATTRIBUTE_DEVICE;
- // PCIe2
- VirtualMemoryTable[++Index].PhysicalBase = LS1043A_PCI_EXP2_BASE_ADDR;
- VirtualMemoryTable[Index].VirtualBase = LS1043A_PCI_EXP2_BASE_ADDR;
- VirtualMemoryTable[Index].Length = LS1043A_PCI_EXP2_BASE_SIZE;
- VirtualMemoryTable[Index].Attributes = ARM_MEMORY_REGION_ATTRIBUTE_DEVICE;
- // PCIe3
- VirtualMemoryTable[++Index].PhysicalBase = LS1043A_PCI_EXP3_BASE_ADDR;
- VirtualMemoryTable[Index].VirtualBase = LS1043A_PCI_EXP3_BASE_ADDR;
- VirtualMemoryTable[Index].Length = LS1043A_PCI_EXP3_BASE_SIZE;
- VirtualMemoryTable[Index].Attributes = ARM_MEMORY_REGION_ATTRIBUTE_DEVICE;
- // DRAM3
- VirtualMemoryTable[++Index].PhysicalBase = LS1043A_DRAM3_BASE_ADDR;
- VirtualMemoryTable[Index].VirtualBase = LS1043A_DRAM3_BASE_ADDR;
- VirtualMemoryTable[Index].Length = LS1043A_DRAM3_SIZE;
- VirtualMemoryTable[Index].Attributes = CacheAttributes;
- // End of Table
- VirtualMemoryTable[++Index].PhysicalBase = 0;
- VirtualMemoryTable[Index].VirtualBase = 0;
- VirtualMemoryTable[Index].Length = 0;
- VirtualMemoryTable[Index].Attributes = (ARM_MEMORY_REGION_ATTRIBUTES)0;
- ASSERT((Index + 1) <= MAX_VIRTUAL_MEMORY_MAP_DESCRIPTORS);
- *VirtualMemoryMap = VirtualMemoryTable;
+}
1.9.1
On Tue, Oct 18, 2016 at 10:15:41AM +0100, Ard Biesheuvel wrote:
diff --git a/Platforms/Nxp/LS1043aRdb/Library/LS1043aRdbLib/LS1043aRdbLib.inf b/Platforms/Nxp/LS1043aRdb/Library/LS1043aRdbLib/LS1043aRdbLib.inf new file mode 100644 index 0000000..e09d940 --- /dev/null +++ b/Platforms/Nxp/LS1043aRdb/Library/LS1043aRdbLib/LS1043aRdbLib.inf @@ -0,0 +1,56 @@ +#/* @file +# Copyright (c) 2011-2013, ARM Limited. All rights reserved. +# Copyright (c) 2016, Freescale Semiconductor, Inc. All rights reserved. +# +# This program and the accompanying materials +# are licensed and made available under the terms and conditions of the BSD License +# which accompanies this distribution. The full text of the license may be found at +# http://opensource.org/licenses/bsd-license.php +# +# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, +# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. +# +#*/
+[Defines]
- INF_VERSION = 0x00010005
- BASE_NAME = LS1043aRdbLib
- FILE_GUID = 736343a0-1d96-11e0-aaaa-0002a5d5c51b
Please use a fresh GUID here
For example using https://www.guidgenerator.com/online-guid-generator.aspx
It's important to use a generator that follows rfc 4122 (with the tweaks that make them GUIDs rather then UUIDs) in order to maintain the statistical uniqueness.
All kinds of things can go horribly wrong if GUIDs clash, whether it be in .inf, .dec or .c/.h files...
Regards,
Leif
Hi Leif,
Thanks for your review comments. Please see my replies inline.
From: Leif Lindholm [mailto:leif.lindholm@linaro.org] Sent: Tuesday, October 18, 2016 9:02 PM
On Tue, Oct 18, 2016 at 10:15:41AM +0100, Ard Biesheuvel wrote:
diff --git a/Platforms/Nxp/LS1043aRdb/Library/LS1043aRdbLib/LS1043aRdbLib.inf b/Platforms/Nxp/LS1043aRdb/Library/LS1043aRdbLib/LS1043aRdbLib.inf new file mode 100644 index 0000000..e09d940 --- /dev/null +++
b/Platforms/Nxp/LS1043aRdb/Library/LS1043aRdbLib/LS1043aRdbLib.i
+++ nf @@ -0,0 +1,56 @@ +#/* @file +# Copyright (c) 2011-2013, ARM Limited. All rights reserved. +# Copyright (c) 2016, Freescale Semiconductor, Inc. All rights
reserved.
+# +# This program and the accompanying materials # are licensed and +made available under the terms and conditions of the BSD License # +which accompanies this distribution. The full text of the license +may be found at # http://opensource.org/licenses/bsd-license.php +# +# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" +BASIS, # WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND,
EITHER EXPRESS OR IMPLIED.
+# +#*/
+[Defines]
- INF_VERSION = 0x00010005
- BASE_NAME = LS1043aRdbLib
- FILE_GUID = 736343a0-1d96-11e0-aaaa-
0002a5d5c51b
Please use a fresh GUID here
For example using https://www.guidgenerator.com/online-guid-generator.aspx
It's important to use a generator that follows rfc 4122 (with the tweaks that make them GUIDs rather then UUIDs) in order to maintain the statistical uniqueness.
All kinds of things can go horribly wrong if GUIDs clash, whether it be in .inf, .dec or .c/.h files...
Regards,
Understood. Thanks for the pointer. Will change this and other occurrences in v2.
Regards, Bhupesh
Hi Ard,
Please see my replies inline.
From: Ard Biesheuvel [mailto:ard.biesheuvel@linaro.org] Sent: Tuesday, October 18, 2016 2:46 PM
On 17 October 2016 at 21:04, Bhupesh Sharma bhupesh.sharma@freescale.com wrote:
From: Sakar Arora sakar.arora@nxp.com
This patch adds the basic support for NXP/FSL's LS1043A RDB board. LS1043A RDB board supports a number of on-board peripherals. This patch adds the basic framework for the same.
Further details about this board can be seen here: http://www.nxp.com/products/microcontrollers-and-processors/ arm-processors/qoriq-arm-processors/qoriq-ls1043a-reference-design-
boa
rd:LS1043A-RDB
Signed-off-by: Sakar Arora sakar.arora@nxp.com Signed-off-by: Bhupesh Sharma bhupesh.sharma@nxp.com
Platforms/Nxp/LS1043aRdb/Include/Library/Common.h | 68 ++++++++ .../Nxp/LS1043aRdb/Include/Library/PlatformLib.h | 178
+++++++++++++++++++++
.../Nxp/LS1043aRdb/Library/LS1043aRdbLib/Common.c | 103
++++++++++++
.../LS1043aRdb/Library/LS1043aRdbLib/LS1043aRdb.c | 107
+++++++++++++
.../Library/LS1043aRdbLib/LS1043aRdbHelper.S | 61 +++++++ .../Library/LS1043aRdbLib/LS1043aRdbLib.inf | 56 +++++++ .../Library/LS1043aRdbLib/LS1043aRdbMem.c | 149
+++++++++++++++++
7 files changed, 722 insertions(+) create mode 100644 Platforms/Nxp/LS1043aRdb/Include/Library/Common.h create mode 100644 Platforms/Nxp/LS1043aRdb/Include/Library/PlatformLib.h create mode 100644 Platforms/Nxp/LS1043aRdb/Library/LS1043aRdbLib/Common.c create mode 100644 Platforms/Nxp/LS1043aRdb/Library/LS1043aRdbLib/LS1043aRdb.c create mode 100644 Platforms/Nxp/LS1043aRdb/Library/LS1043aRdbLib/LS1043aRdbHelper.S create mode 100644 Platforms/Nxp/LS1043aRdb/Library/LS1043aRdbLib/LS1043aRdbLib.inf create mode 100644 Platforms/Nxp/LS1043aRdb/Library/LS1043aRdbLib/LS1043aRdbMem.c
diff --git a/Platforms/Nxp/LS1043aRdb/Include/Library/Common.h b/Platforms/Nxp/LS1043aRdb/Include/Library/Common.h new file mode 100644 index 0000000..192a249 --- /dev/null +++ b/Platforms/Nxp/LS1043aRdb/Include/Library/Common.h @@ -0,0 +1,68 @@ +/** @Common.h
- Header defining the General Purpose Utilities
- Copyright (c) 2016, Freescale Semiconductor, Inc. All rights
reserved.
- This program and the accompanying materials are licensed and made
- available under the terms and conditions of the BSD License which
- accompanies this distribution. The full text of the license may be
- found at http://opensource.org/licenses/bsd-license.php
- THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS"
- BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER
EXPRESS OR IMPLIED.
+**/
+#ifndef __COMMON_H__ +#define __COMMON_H__
+#define DMA_MINALIGN 64
+#define offsetof(TYPE, MEMBER) ((UINTN) &((TYPE *)0)->MEMBER)
+typedef UINTN PhysAddrT; +typedef UINTN PhysSizeT;
+static inline PhysAddrT VirtToPhys(VOID * VAddr) {
return (PhysAddrT)(VAddr);
+}
+/*
- The ALLOC_CACHE_ALIGN_BUF macro is used to allocate a buffer
- that meets the minimum architecture alignment requirements for
DMA.
- The resulting buffer is aligned to the value of DMA_MINALIGN.
- The buffer variable created is a pointer to the specified type,
+and
- NOT an array.
- The size parameter is the number of array elements to allocate.
- */
+#define ALIGN_BUFF(x,a) ALIGN_MSK((x),(typeof(x))(a)-1) +#define ALIGN_MSK(x,mask) (((x)+(mask))&~(mask))
+#define PAD_CNT(S, Pad) (((S) - 1) / (Pad) + 1) #define PAD_SIZE(S, +Pad) (PAD_CNT(S, Pad) * Pad)
+#define ROUND_OFF(a,b) (((a) + (b) - 1) & ~((b) - 1))
+#define DMA_MINALIGN 64
+#define ALLOC_ALIGN_BUF_PAD(Type, Name, Size, Align, Pad)
\
INT8 __##Name[ROUND_OFF(PAD_SIZE((Size) * sizeof(Type), Pad),
Align) \
+ (Align - 1)];
\
\
Type *Name = (Type *) ALIGN_BUFF((UINTN)__##Name, Align)
+#define ALLOC_ALIGN_BUF(Type, Name, Size, Align) \
ALLOC_ALIGN_BUF_PAD(Type, Name, Size, Align, 1)
+#define ALLOC_CACHE_ALIGN_BUF_PAD(Type, Name, Size, Pad)
\
ALLOC_ALIGN_BUF_PAD(Type, Name, size, DMA_MINALIGN, Pad)
+#define ALLOC_CACHE_ALIGN_BUF(Type, Name, Size)
\
ALLOC_ALIGN_BUF(Type, Name, Size, DMA_MINALIGN)
+#endif diff --git a/Platforms/Nxp/LS1043aRdb/Include/Library/PlatformLib.h b/Platforms/Nxp/LS1043aRdb/Include/Library/PlatformLib.h new file mode 100644 index 0000000..39247e8 --- /dev/null +++ b/Platforms/Nxp/LS1043aRdb/Include/Library/PlatformLib.h @@ -0,0 +1,178 @@ +/** LS1043aRdb.h +* Header defining the LS1043aRdb constants (Base addresses, sizes, +flags) +* +* Copyright (c) 2016, Freescale Semiconductor, Inc. All rights
reserved.
+* +* This program and the accompanying materials +* are licensed and made available under the terms and conditions of +the BSD License +* which accompanies this distribution. The full text of the
license
+may be found at +* http://opensource.org/licenses/bsd-license.php +* +* THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" +BASIS, +* WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS
OR IMPLIED.
+* +**/
+#ifndef __LS1043aRDB_PLATFORM_H__ +#define __LS1043aRDB_PLATFORM_H__
+// Types +#define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
+// DDR attributes +#define DDR_ATTRIBUTES_CACHED
ARM_MEMORY_REGION_ATTRIBUTE_WRITE_BACK
+#define DDR_ATTRIBUTES_UNCACHED
ARM_MEMORY_REGION_ATTRIBUTE_UNCACHED_UNBUFFERED
+#define LS1043A_CACHELINE_SIZE 32
+#define LS1043A_SECURE_BOOTROM_BASE_ADDR 0x00000000 +#define LS1043A_SECURE_BOOTROM_SIZE 0x00100000 /* 1MB */ +#define LS1043A_EXT_BOOTROM_BASE_ADDR 0x00100000 +#define LS1043A_EXT_BOOTROM_SIZE 0x00F00000 /*
15MB */
+#define LS1043A_CCSR_BASE_ADDR 0x01000000 +#define LS1043A_CCSR_SIZE 0x0F000000 /* 240MB
*/
#define LS1043A_IMMR 0x01000000
#define LS1043A_DDR_ADDR 0x01080000
#define LS1043A_DSPI_ADDR 0x02100000
#define LS1043A_SDXC_ADDR 0x01560000
#define LS1043A_CCI400_ADDR (LS1043A_IMMR +
0x00180000)
#define LS1043A_TZASC380_ADDR (LS1043A_IMMR + 0x00500000)
#define LS1043A_CSU_ADDR (LS1043A_IMMR +
0x00510000)
#define LS1043A_GUTS_ADDR (LS1043A_IMMR + 0x00ee0000)
#define LS1043A_CLK_ADDR (LS1043A_IMMR +
0x00ee1000)
#define LS1043A_FMAN_ADDR (LS1043A_IMMR + 0x00a00000)
#define LS1043A_BMAN_ADDR (LS1043A_IMMR + 0x00890000)
#define LS1043A_QMAN_ADDR (LS1043A_IMMR + 0x00880000)
#define GIC_BASE_ADDR 0x01402000
#define GIC_SIZE 0x1000
#define GICDIST_BASE_ADDR 0x01401000
#define GICDIST_SIZE 0x1000
#define DUART1_BASE_ADDR 0x21C0000
#define DUART1_SIZE 0x1000
#define DUART2_BASE_ADDR 0x21D0000
#define DUART2_SIZE 0x1000
#define WDOG1_BASE_ADDR 0x02AD0000
#define WDOG2_BASE_ADDR 0x02AE0000
#define WDOG3_BASE_ADDR 0x02A70000
#define WDOG4_BASE_ADDR 0x02A80000
#define WDOG5_BASE_ADDR 0x02A90000
#define WDOG_SIZE 0x1000
#define WDOG_WCR_OFFSET 0
#define WDOG_WSR_OFFSET 2
#define WDOG_WRSR_OFFSET 4
#define WDOG_WICR_OFFSET 6
#define WDOG_WCR_WT (0xFF << 8)
#define WDOG_WCR_WDE (1 << 2)
#define WDOG_SERVICE_SEQ1 0x5555
#define WDOG_SERVICE_SEQ2 0xAAAA
#define WDOG_WCR_WDZST 0x1
#define WDOG_WCR_WRE (1 << 3) /* -> WDOG Reset Enable */
#define I2C0_BASE_ADDRESS 0x02180000
#define I2C1_BASE_ADDRESS 0x02190000
#define I2C2_BASE_ADDRESS 0x021A0000
#define I2C3_BASE_ADDRESS 0x02183000
#define I2C_SIZE 0x10000
#define DSPI_MEMORY_SIZE 0x10000
#define DDRC_MEMORY_SIZE 0x10000
#define SDXC_MEMORY_SIZE 0x10000
#define LS1043A_TIMER_ADDR 0x02b00000
#define IFC_REG_BASE_ADDR 0x1530000
#define IFC_REG_SIZE 0x0003000
#define SCFG_BASE_ADDR 0x1570000
#define SCFG_SIZE 0x0010000
+/* SMMU Defintions */ +#define SMMU_BASE_ADDR 0x09000000 +#define SMMU_REG_SCR0 (SMMU_BASE_ADDR + 0x0) +#define SMMU_REG_SACR (SMMU_BASE_ADDR + 0x10) +#define SMMU_REG_IDR1 (SMMU_BASE_ADDR + 0x24) +#define SMMU_REG_NSCR0 (SMMU_BASE_ADDR + 0x400) +#define SMMU_REG_NSACR (SMMU_BASE_ADDR + 0x410)
+#define SCR0_USFCFG_MASK 0x00000400 +#define SCR0_CLIENTPD_MASK 0x00000001 +#define SACR_PAGESIZE_MASK 0x00010000 +#define IDR1_PAGESIZE_MASK 0x80000000
+#define LS1043A_OCRAM1_BASE_ADDR 0x10000000 +#define LS1043A_OCRAM1_SIZE 0x00010000 /* 64KB */ +#define LS1043A_OCRAM2_BASE_ADDR 0x10010000 +#define LS1043A_OCRAM2_SIZE 0x00010000 /* 64KB */ +#define LS1043A_STM_BASE_ADDR 0x12000000 +#define LS1043A_STM_SIZE 0x01000000 /*
16MB */
+#define LS1043A_DCSR_BASE_ADDR 0x20000000 +#define LS1043A_DCSR_SIZE 0x04000000 /* 64MB */ +#define LS1043A_QSPI_BASE_ADDR 0x40000000 +#define LS1043A_QSPI_SIZE 0x20000000 /* 512MB
*/
+#define LS1043A_IFC_REGION1_BASE_ADDR 0x60000000 +#define LS1043A_IFC_REGION1_BASE_SIZE 0x20000000 /* 512MB
*/
+#define LS1043A_DRAM1_BASE_ADDR 0x0080000000 +#define LS1043A_DRAM1_SIZE 0x0080000000 /* 2GB
*/
+#define LS1043A_QMAN_SWP_BASE_ADDR 0x0500000000 +#define LS1043A_QMAN_SWP_SIZE 0x0080000000 /* 128MB
*/
+#define LS1043A_BMAN_SWP_BASE_ADDR 0x0508000000 +#define LS1043A_BMAN_SWP_SIZE 0x0080000000 /* 128MB
*/
+#define LS1043A_IFC_REGION2_BASE_ADDR 0x0620000000 +#define LS1043A_IFC_REGION2_BASE_SIZE 0x00E0000000 /* 3.5GB
*/
+#define LS1043A_DRAM2_BASE_ADDR 0x0880000000 +#define LS1043A_DRAM2_SIZE 0x0780000000 /* 30GB
*/
+#define LS1043A_SERDES_ADDR (LS1043A_IMMR +
0xEA0000)
+#define LS1043A_SRDS_1 +#define LS1043A_PCI_EXP1_BASE_ADDR 0x4000000000 +#define LS1043A_PCI_EXP1_BASE_SIZE 0x800000000 /* 32GB
*/
+#define LS1043A_PCI_EXP2_BASE_ADDR 0x4800000000 +#define LS1043A_PCI_EXP2_BASE_SIZE 0x800000000 /* 32GB
*/
+#define LS1043A_PCI_EXP3_BASE_ADDR 0x5000000000 +#define LS1043A_PCI_EXP3_BASE_SIZE 0x800000000 /* 32GB
*/
+#define LS1043A_DRAM3_BASE_ADDR 0x8800000000 +#define LS1043A_DRAM3_SIZE 0x7800000000 /* 480GB
*/
+/*
- CPLD
- */
+#define LS1043A_CPLD_BASE 0x7fb00000
+/*
- Global defines
- */
+#define NOR_BOOT 0x0 +#define NAND_BOOT 0x1 +#define SD_BOOT 0x2
+/* PCI controllers addresses */ +#define LS1043A_PCIE1_PHYS_BASE 0x5000000000ULL +#define LS1043A_PCIE2_PHYS_BASE 0x4800000000ULL +#define LS1043A_PCIE3_PHYS_BASE 0x5000000000ULL
+#define LS1043A_PCIE1_PHYS_ADDR 0x5000000000ULL +#define LS1043A_PCIE2_PHYS_ADDR 0x4800000000ULL +#define LS1043A_PCIE3_PHYS_ADDR 0x5000000000ULL
+#define LS1043A_PCIE1_ADDR 0x03600000 +#define LS1043A_PCIE2_ADDR 0x03500000 +#define LS1043A_PCIE3_ADDR 0x03600000
+/* PCIe */ +#define LS1043A_LS_PCI /* Enable PCI/PCIE */ +#define LS1043A_LS_PCIE1 /* PCIE controler 1 */ +#define LS1043A_LS_PCIE2 /* PCIE controler 2 */ +#define LS1043A_LS_PCIE3 /* PCIE controler 2 */ +#define LS1043A_LS_PCIE_LAYERSCAPE /* Use common FSL Layerscape
PCIe
+code */
+#define LS1043A_LS_PCI_64BIT
+#define LS1043A_LS_PCIE_CFG0_PHYS_OFF 0x00000000 +#define LS1043A_LS_PCIE_CFG0_SIZE 0x00001000 /* 4k */ +#define LS1043A_LS_PCIE_CFG1_PHYS_OFF 0x00001000 +#define LS1043A_LS_PCIE_CFG1_SIZE 0x00001000 /* 4k */
+#define LS1043A_LS_PCIE_IO_BUS 0x00000000 +#define LS1043A_LS_PCIE_IO_PHYS_OFF 0x00010000 +#define LS1043A_LS_PCIE_IO_SIZE 0x00010000 /* 64k */
+#define LS1043A_LS_PCIE_MEM_BUS 0x40000000 +#define LS1043A_LS_PCIE_MEM_PHYS_OFF 0x40000000 +#define LS1043A_LS_PCIE_MEM_SIZE 0x40000000 /* 1 GB */
+#endif diff --git a/Platforms/Nxp/LS1043aRdb/Library/LS1043aRdbLib/Common.c b/Platforms/Nxp/LS1043aRdb/Library/LS1043aRdbLib/Common.c new file mode 100644 index 0000000..7159749 --- /dev/null +++ b/Platforms/Nxp/LS1043aRdb/Library/LS1043aRdbLib/Common.c @@ -0,0 +1,103 @@ +/** Common.c +* +* Copyright (c) 2016, Freescale Ltd. All rights reserved. +* +* This program and the accompanying materials +* are licensed and made available under the terms and conditions of +the BSD License +* which accompanies this distribution. The full text of the
license
+may be found at +* http://opensource.org/licenses/bsd-license.php +* +* THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" +BASIS, +* WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS
OR IMPLIED.
+* +**/
+#include <Library/PlatformLib.h> +#include <Library/DebugLib.h>
+UINT32 +__Div64_32 (
- IN UINT64 *N,
- IN UINT32 Base
- )
+{
- UINT64 Rem = *N;
- UINT64 b = Base;
- UINT64 Res, d = 1;
- UINT32 High = Rem >> 32;
- /** Reduce the thing a bit first */ Res = 0; if (High >= Base) {
- High /= Base;
- Res = (UINT64) High << 32;
- Rem -= (UINT64) (High*Base) << 32; }
- while ((UINTN)b > 0 && b < Rem) {
- b = b+b;
- d = d+d;
- }
- do {
- if (Rem >= b) {
Rem -= b;
Res += d;
- }
- b >>= 1;
- d >>= 1;
- } while (d);
- *N = Res;
- return Rem;
+}
Why do we need this?
+/*
- PrINT32 Sizes As "Xxx KiB", "Xxx.Y KiB", "Xxx MiB", "Xxx.Y MiB",
- Xxx GiB, Xxx.Y GiB, Etc As Needed; Allow for Optional Trailing
+String
- (Like "\n")
- */
+VOID +PrintSize (
- IN UINT64 Size,
- IN CONST INT8 *S
- )
+{
- UINT64 M = 0, N;
- UINT64 F;
- static CONST INT8 Names[] = {'E', 'P', 'T', 'G', 'M', 'K'};
- UINT64 D = 10 * ARRAY_SIZE(Names);
- CHAR8 C = 0;
- UINT32 I;
- for (I = 0; I < ARRAY_SIZE(Names); I++, D -= 10) {
- if (Size >> D) {
C = Names[I];
break;
- }
- }
- if (!C) {
- DEBUG((EFI_D_ERROR, "%Ld Bytes,\n %a", Size, S));
- return;
- }
- N = Size >> D;
- F = Size & ((1ULL << D) - 1);
- /* if There'S A Remainder, Deal With It */ if (F) {
- M = (10ULL * F + (1ULL << (D - 1))) >> D;
- if (M >= 10) {
M -= 10;
N += 1;
- }
- }
- DEBUG((EFI_D_ERROR, "%Ld", N));
- if (M) {
- DEBUG((EFI_D_ERROR, ".%Ld", M));
- }
- DEBUG((EFI_D_ERROR, " %ciB, %a ", C, S)); }
diff --git a/Platforms/Nxp/LS1043aRdb/Library/LS1043aRdbLib/LS1043aRdb.c b/Platforms/Nxp/LS1043aRdb/Library/LS1043aRdbLib/LS1043aRdb.c new file mode 100644 index 0000000..4fcb8a3 --- /dev/null +++ b/Platforms/Nxp/LS1043aRdb/Library/LS1043aRdbLib/LS1043aRdb.c @@ -0,0 +1,107 @@ +/** LS1043aRdb.c +* +* RDB specific Library for LS1043A SoC, containing functions to +initialize +* RDB boards. +* +* Based on BeagleBoardPkg/Library/BeagleBoardLib/BeagleBoard.c +* +* Copyright (c) 2011-2012, ARM Limited. All rights reserved. +* Copyright (c) 2016, Freescale Semiconductor, Inc. All rights
reserved.
+* +* This program and the accompanying materials +* are licensed and made available under the terms and conditions of +the BSD License +* which accompanies this distribution. The full text of the
license
+may be found at +* http://opensource.org/licenses/bsd-license.php +* +* THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" +BASIS, +* WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS
OR IMPLIED.
+* +**/
+#include <Library/IoLib.h> +#include <Library/ArmPlatformLib.h> +#include <Library/DebugLib.h> +#include <Library/PcdLib.h> +#include <Ppi/ArmMpCoreInfo.h> +#include <Library/PlatformLib.h>
+/**
- Return the current Boot Mode
- This function returns the boot reason on the platform
+**/ +EFI_BOOT_MODE +ArmPlatformGetBootMode (
- VOID
- )
+{
- return BOOT_WITH_FULL_CONFIGURATION; }
+/**
- Placeholder for Platform Initialization **/ RETURN_STATUS
+ArmPlatformInitialize (
- IN UINTN MpId
- )
+{
- return RETURN_SUCCESS;
+}
+ARM_CORE_INFO LS1043aMpCoreInfoCTA53x4[] = {
- {
- // Cluster 0, Core 0
- 0x0, 0x0,
- // MP Core MailBox Set/Get/Clear Addresses and Clear Value
- (EFI_PHYSICAL_ADDRESS)0,
- (EFI_PHYSICAL_ADDRESS)0,
- (EFI_PHYSICAL_ADDRESS)0,
- (UINT64)0xFFFFFFFF
- },
+};
+EFI_STATUS +PrePeiCoreGetMpCoreInfo (
- OUT UINTN *CoreCount,
- OUT ARM_CORE_INFO **ArmCoreTable
- )
+{
- *CoreCount = sizeof(LS1043aMpCoreInfoCTA53x4) /
sizeof(ARM_CORE_INFO);
- *ArmCoreTable = LS1043aMpCoreInfoCTA53x4;
- return EFI_SUCCESS;
+}
+// Needs to be declared in the file. Otherwise gArmMpCoreInfoPpiGuid +is undefined in the contect of PrePeiCore
This is not true, and has been fixed upstream. You simply need to add gArmMpCoreInfoPpiGuid to the [Guids] section of the .inf
Ok, will change this in v2.
+EFI_GUID mArmMpCoreInfoPpiGuid = ARM_MP_CORE_INFO_PPI_GUID;' +ARM_MP_CORE_INFO_PPI mMpCoreInfoPpi = { PrePeiCoreGetMpCoreInfo };
+EFI_PEI_PPI_DESCRIPTOR gPlatformPpiTable[] = {
- {
- EFI_PEI_PPI_DESCRIPTOR_PPI,
- &mArmMpCoreInfoPpiGuid,
- &mMpCoreInfoPpi
- }
+};
+VOID +ArmPlatformGetPlatformPpiList (
- OUT UINTN *PpiListSize,
- OUT EFI_PEI_PPI_DESCRIPTOR **PpiList
- )
+{
- *PpiListSize = sizeof(gPlatformPpiTable);
- *PpiList = gPlatformPpiTable;
+}
+UINTN +ArmPlatformGetCorePosition (
- IN UINTN MpId
- )
+{
- return 1;
+} diff --git a/Platforms/Nxp/LS1043aRdb/Library/LS1043aRdbLib/LS1043aRdbHelper.S b/Platforms/Nxp/LS1043aRdb/Library/LS1043aRdbLib/LS1043aRdbHelper.S new file mode 100644 index 0000000..5d9807f --- /dev/null +++
b/Platforms/Nxp/LS1043aRdb/Library/LS1043aRdbLib/LS1043aRdbHelper.
+++ S @@ -0,0 +1,61 @@ +# @file +# +# Based on
BeagleBoardPkg/Library/BeagleBoardLib/BeagleBoardHelper.S
+# +# Copyright (c) 2012-2013, ARM Limited. All rights reserved. +# Copyright (c) 2016, Freescale Semiconductor, Inc. All rights
reserved.
+# +# This program and the accompanying materials # are licensed and +made available under the terms and conditions of the BSD License # +which accompanies this distribution. The full text of the license +may be found at # http://opensource.org/licenses/bsd-license.php +# +# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" +BASIS, # WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER
EXPRESS OR IMPLIED.
+# +#
+#include <AsmMacroIoLib.h> +#include <AsmMacroIoLibV8.h> +#include <AutoGen.h>
+.text +.align 2
+GCC_ASM_EXPORT(ArmPlatformIsPrimaryCore) +GCC_ASM_EXPORT(ArmPlatformGetPrimaryCoreMpId) +GCC_ASM_EXPORT(ArmPlatformPeiBootAction)
+GCC_ASM_IMPORT(ArmReadMpidr)
+//UINTN +//ArmPlatformIsPrimaryCore ( +// IN UINTN MpId +// ); +ASM_PFX(ArmPlatformIsPrimaryCore):
and x1, x0, #3
mov x0, #0
- cbnz x1, 1f
mov x0, #1
+1:
- ret
How about
tst x0, #3 cset x0, eq ret
Ok.
+ASM_PFX(ArmPlatformPeiBootAction): +EL1_OR_EL2_OR_EL3(x0) +1: +2:
ret
+3:
LoadConstantToReg(FixedPcdGet32(PcdCounterFrequency), x0)
Please don't use LoadConstantToReg(), you can use MOV32() or MOV64 instead.
Ok.
msr cntfrq_el0, x0
ret
+//UINTN +//ArmPlatformGetPrimaryCoreMpId ( +// VOID +// ); +ASM_PFX(ArmPlatformGetPrimaryCoreMpId):
- LoadConstantToReg (FixedPcdGet32(PcdArmPrimaryCore), x0)
- ldrh w0, [x0]
Same here. FixedPcdGet32(PcdArmPrimaryCore) resolves to a literal constant, no need for the ldr
Ok.
- ret
diff --git a/Platforms/Nxp/LS1043aRdb/Library/LS1043aRdbLib/LS1043aRdbLib.inf b/Platforms/Nxp/LS1043aRdb/Library/LS1043aRdbLib/LS1043aRdbLib.inf new file mode 100644 index 0000000..e09d940 --- /dev/null +++
b/Platforms/Nxp/LS1043aRdb/Library/LS1043aRdbLib/LS1043aRdbLib.inf
@@ -0,0 +1,56 @@ +#/* @file +# Copyright (c) 2011-2013, ARM Limited. All rights reserved. +# Copyright (c) 2016, Freescale Semiconductor, Inc. All rights
reserved.
+# +# This program and the accompanying materials # are licensed and +made available under the terms and conditions of the BSD License # +which accompanies this distribution. The full text of the license +may be found at # http://opensource.org/licenses/bsd-license.php +# +# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" +BASIS, # WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER
EXPRESS OR IMPLIED.
+# +#*/
+[Defines]
- INF_VERSION = 0x00010005
- BASE_NAME = LS1043aRdbLib
- FILE_GUID = 736343a0-1d96-11e0-aaaa-
0002a5d5c51b
Please use a fresh GUID here
Ok.
- MODULE_TYPE = BASE
- VERSION_STRING = 1.0
- LIBRARY_CLASS = ArmPlatformLib
+[Packages]
- MdePkg/MdePkg.dec
- MdeModulePkg/MdeModulePkg.dec
- EmbeddedPkg/EmbeddedPkg.dec
- ArmPkg/ArmPkg.dec
- ArmPlatformPkg/ArmPlatformPkg.dec
- OpenPlatformPkg/Platforms/Nxp/LS1043aRdb/LS1043aRdbPkg.dec
+[LibraryClasses]
- IoLib
- ArmLib
- MemoryAllocationLib
- I2cLib
- DdrLib
- SocLib
+[Sources.common]
- LS1043aRdbHelper.S | GCC
- LS1043aRdb.c
- LS1043aRdbMem.c
- Common.c
+[FeaturePcd]
- gEmbeddedTokenSpaceGuid.PcdCacheEnable
+[FixedPcd]
- gArmTokenSpaceGuid.PcdArmPrimaryCore
- gArmTokenSpaceGuid.PcdFdBaseAddress
- gArmTokenSpaceGuid.PcdFdSize
- gArmTokenSpaceGuid.PcdSystemMemoryBase
- gArmTokenSpaceGuid.PcdSystemMemorySize
- gArmPlatformTokenSpaceGuid.PcdCounterFrequency
diff --git a/Platforms/Nxp/LS1043aRdb/Library/LS1043aRdbLib/LS1043aRdbMem.c b/Platforms/Nxp/LS1043aRdb/Library/LS1043aRdbLib/LS1043aRdbMem.c new file mode 100644 index 0000000..ef93623 --- /dev/null +++ b/Platforms/Nxp/LS1043aRdb/Library/LS1043aRdbLib/LS1043aRdbMem.c @@ -0,0 +1,149 @@ +/** LS1043aRdbMem.c +* +* RDB memory specific Library for LS1043A SoC. +* +* Based on BeagleBoardPkg/Library/BeagleBoardLib/BeagleBoardMem.c +* +* Copyright (c) 2011, ARM Limited. All rights reserved. +* Copyright (c) 2016, Freescale Semiconductor, Inc. All rights
reserved.
+* +* This program and the accompanying materials +* are licensed and made available under the terms and conditions of +the BSD License +* which accompanies this distribution. The full text of the license +may be found at +* http://opensource.org/licenses/bsd-license.php +* +* THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" +BASIS, +* WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS
OR IMPLIED.
+* +**/
+#include <Library/ArmPlatformLib.h> +#include <Library/DebugLib.h> +#include <Library/PcdLib.h> +#include <Library/MemoryAllocationLib.h> #include <Library/IoLib.h>
+#include <Library/PlatformLib.h>
+#define MAX_VIRTUAL_MEMORY_MAP_DESCRIPTORS 25
+/**
- Return the Virtual Memory Map of your platform
- This Virtual Memory Map is used by MemoryInitPei Module to
initialize the MMU on your platform.
- @param[out] VirtualMemoryMap Array of
ARM_MEMORY_REGION_DESCRIPTOR describing a Physical-to-
Virtual Memory mapping. This
array must be ended by a zero-filled
entry
+**/ +VOID +ArmPlatformGetVirtualMemoryMap (
- IN ARM_MEMORY_REGION_DESCRIPTOR** VirtualMemoryMap
- )
+{
- ARM_MEMORY_REGION_ATTRIBUTES CacheAttributes;
- UINTN Index = 0;
- ARM_MEMORY_REGION_DESCRIPTOR *VirtualMemoryTable;
- ASSERT(VirtualMemoryMap != NULL);
- VirtualMemoryTable =
- (ARM_MEMORY_REGION_DESCRIPTOR*)AllocatePages(EFI_SIZE_TO_PAGES
- (sizeof(ARM_MEMORY_REGION_DESCRIPTOR) *
- MAX_VIRTUAL_MEMORY_MAP_DESCRIPTORS));
- if (VirtualMemoryTable == NULL) {
- return;
- }
- if (FeaturePcdGet(PcdCacheEnable) == TRUE) {
- CacheAttributes = DDR_ATTRIBUTES_CACHED; } else {
- CacheAttributes = DDR_ATTRIBUTES_UNCACHED; }
- // DRAM1 (Must be 1st entry)
Why? Because the regions overlap? If so, please document that more explicitly.
No the DRAM regions do no overlap. But I noticed crashes in DXE phase if this is not the first entry.
I guess this first entry is passed via PEIM to DXE where the overall memory region availability is conveyed to DXE.
- VirtualMemoryTable[Index].PhysicalBase = LS1043A_DRAM1_BASE_ADDR;
- VirtualMemoryTable[Index].VirtualBase = LS1043A_DRAM1_BASE_ADDR;
- VirtualMemoryTable[Index].Length = LS1043A_DRAM1_SIZE;
- VirtualMemoryTable[Index].Attributes = CacheAttributes;
- // CCSR Space
- VirtualMemoryTable[++Index].PhysicalBase = LS1043A_CCSR_BASE_ADDR;
- VirtualMemoryTable[Index].VirtualBase = LS1043A_CCSR_BASE_ADDR;
- VirtualMemoryTable[Index].Length = LS1043A_CCSR_SIZE;
- VirtualMemoryTable[Index].Attributes =
ARM_MEMORY_REGION_ATTRIBUTE_DEVICE;
- // OCRAM1 Space
- VirtualMemoryTable[++Index].PhysicalBase =
- LS1043A_OCRAM1_BASE_ADDR; VirtualMemoryTable[Index].VirtualBase =
LS1043A_OCRAM1_BASE_ADDR;
- VirtualMemoryTable[Index].Length = LS1043A_OCRAM1_SIZE;
- VirtualMemoryTable[Index].Attributes = CacheAttributes;
- // OCRAM2 Space
- VirtualMemoryTable[++Index].PhysicalBase =
- LS1043A_OCRAM2_BASE_ADDR; VirtualMemoryTable[Index].VirtualBase =
LS1043A_OCRAM2_BASE_ADDR;
- VirtualMemoryTable[Index].Length = LS1043A_OCRAM2_SIZE;
- VirtualMemoryTable[Index].Attributes = CacheAttributes;
- // IFC region 1
- VirtualMemoryTable[++Index].PhysicalBase =
- LS1043A_IFC_REGION1_BASE_ADDR;
VirtualMemoryTable[Index].VirtualBase = LS1043A_IFC_REGION1_BASE_ADDR;
- VirtualMemoryTable[Index].Length =
LS1043A_IFC_REGION1_BASE_SIZE;
- VirtualMemoryTable[Index].Attributes =
ARM_MEMORY_REGION_ATTRIBUTE_UNCACHED_UNBUFFERED;
- // QMAN SWP
- VirtualMemoryTable[++Index].PhysicalBase =
- LS1043A_QMAN_SWP_BASE_ADDR; VirtualMemoryTable[Index].VirtualBase
= LS1043A_QMAN_SWP_BASE_ADDR;
- VirtualMemoryTable[Index].Length = LS1043A_QMAN_SWP_SIZE;
- VirtualMemoryTable[Index].Attributes =
ARM_MEMORY_REGION_ATTRIBUTE_UNCACHED_UNBUFFERED;
- // BMAN SWP
- VirtualMemoryTable[++Index].PhysicalBase =
- LS1043A_BMAN_SWP_BASE_ADDR; VirtualMemoryTable[Index].VirtualBase
= LS1043A_BMAN_SWP_BASE_ADDR;
- VirtualMemoryTable[Index].Length = LS1043A_BMAN_SWP_SIZE;
- VirtualMemoryTable[Index].Attributes =
ARM_MEMORY_REGION_ATTRIBUTE_UNCACHED_UNBUFFERED;
- // IFC region 2
- VirtualMemoryTable[++Index].PhysicalBase =
- LS1043A_IFC_REGION2_BASE_ADDR;
VirtualMemoryTable[Index].VirtualBase = LS1043A_IFC_REGION2_BASE_ADDR;
- VirtualMemoryTable[Index].Length =
LS1043A_IFC_REGION2_BASE_SIZE;
- VirtualMemoryTable[Index].Attributes = CacheAttributes;
- // DRAM2
- VirtualMemoryTable[++Index].PhysicalBase =
LS1043A_DRAM2_BASE_ADDR;
- VirtualMemoryTable[Index].VirtualBase = LS1043A_DRAM2_BASE_ADDR;
- VirtualMemoryTable[Index].Length = LS1043A_DRAM2_SIZE;
- VirtualMemoryTable[Index].Attributes = CacheAttributes;
- // PCIe1
- VirtualMemoryTable[++Index].PhysicalBase =
- LS1043A_PCI_EXP1_BASE_ADDR; VirtualMemoryTable[Index].VirtualBase
= LS1043A_PCI_EXP1_BASE_ADDR;
- VirtualMemoryTable[Index].Length =
LS1043A_PCI_EXP1_BASE_SIZE;
- VirtualMemoryTable[Index].Attributes =
ARM_MEMORY_REGION_ATTRIBUTE_DEVICE;
- // PCIe2
- VirtualMemoryTable[++Index].PhysicalBase =
- LS1043A_PCI_EXP2_BASE_ADDR; VirtualMemoryTable[Index].VirtualBase
= LS1043A_PCI_EXP2_BASE_ADDR;
- VirtualMemoryTable[Index].Length =
LS1043A_PCI_EXP2_BASE_SIZE;
- VirtualMemoryTable[Index].Attributes =
ARM_MEMORY_REGION_ATTRIBUTE_DEVICE;
- // PCIe3
- VirtualMemoryTable[++Index].PhysicalBase =
- LS1043A_PCI_EXP3_BASE_ADDR; VirtualMemoryTable[Index].VirtualBase
= LS1043A_PCI_EXP3_BASE_ADDR;
- VirtualMemoryTable[Index].Length =
LS1043A_PCI_EXP3_BASE_SIZE;
- VirtualMemoryTable[Index].Attributes =
ARM_MEMORY_REGION_ATTRIBUTE_DEVICE;
- // DRAM3
- VirtualMemoryTable[++Index].PhysicalBase =
LS1043A_DRAM3_BASE_ADDR;
- VirtualMemoryTable[Index].VirtualBase = LS1043A_DRAM3_BASE_ADDR;
- VirtualMemoryTable[Index].Length = LS1043A_DRAM3_SIZE;
- VirtualMemoryTable[Index].Attributes = CacheAttributes;
- // End of Table
- VirtualMemoryTable[++Index].PhysicalBase = 0;
- VirtualMemoryTable[Index].VirtualBase = 0;
- VirtualMemoryTable[Index].Length = 0;
- VirtualMemoryTable[Index].Attributes =
(ARM_MEMORY_REGION_ATTRIBUTES)0;
- ASSERT((Index + 1) <= MAX_VIRTUAL_MEMORY_MAP_DESCRIPTORS);
- *VirtualMemoryMap = VirtualMemoryTable; }
-- 1.9.1
Regards, Bhupesh
On 27 October 2016 at 08:46, Bhupesh Sharma bhupesh.sharma@nxp.com wrote:
Hi Ard,
Please see my replies inline.
From: Ard Biesheuvel [mailto:ard.biesheuvel@linaro.org] Sent: Tuesday, October 18, 2016 2:46 PM
On 17 October 2016 at 21:04, Bhupesh Sharma bhupesh.sharma@freescale.com wrote:
From: Sakar Arora sakar.arora@nxp.com
This patch adds the basic support for NXP/FSL's LS1043A RDB board. LS1043A RDB board supports a number of on-board peripherals. This patch adds the basic framework for the same.
Further details about this board can be seen here: http://www.nxp.com/products/microcontrollers-and-processors/ arm-processors/qoriq-arm-processors/qoriq-ls1043a-reference-design-
boa
rd:LS1043A-RDB
Signed-off-by: Sakar Arora sakar.arora@nxp.com Signed-off-by: Bhupesh Sharma bhupesh.sharma@nxp.com
[...]
diff --git a/Platforms/Nxp/LS1043aRdb/Library/LS1043aRdbLib/LS1043aRdbMem.c b/Platforms/Nxp/LS1043aRdb/Library/LS1043aRdbLib/LS1043aRdbMem.c new file mode 100644 index 0000000..ef93623 --- /dev/null +++ b/Platforms/Nxp/LS1043aRdb/Library/LS1043aRdbLib/LS1043aRdbMem.c @@ -0,0 +1,149 @@ +/** LS1043aRdbMem.c +* +* RDB memory specific Library for LS1043A SoC. +* +* Based on BeagleBoardPkg/Library/BeagleBoardLib/BeagleBoardMem.c +* +* Copyright (c) 2011, ARM Limited. All rights reserved. +* Copyright (c) 2016, Freescale Semiconductor, Inc. All rights
reserved.
+* +* This program and the accompanying materials +* are licensed and made available under the terms and conditions of +the BSD License +* which accompanies this distribution. The full text of the license +may be found at +* http://opensource.org/licenses/bsd-license.php +* +* THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" +BASIS, +* WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS
OR IMPLIED.
+* +**/
+#include <Library/ArmPlatformLib.h> +#include <Library/DebugLib.h> +#include <Library/PcdLib.h> +#include <Library/MemoryAllocationLib.h> #include <Library/IoLib.h>
+#include <Library/PlatformLib.h>
+#define MAX_VIRTUAL_MEMORY_MAP_DESCRIPTORS 25
+/**
- Return the Virtual Memory Map of your platform
- This Virtual Memory Map is used by MemoryInitPei Module to
initialize the MMU on your platform.
- @param[out] VirtualMemoryMap Array of
ARM_MEMORY_REGION_DESCRIPTOR describing a Physical-to-
Virtual Memory mapping. This
array must be ended by a zero-filled
entry
+**/ +VOID +ArmPlatformGetVirtualMemoryMap (
- IN ARM_MEMORY_REGION_DESCRIPTOR** VirtualMemoryMap
- )
+{
- ARM_MEMORY_REGION_ATTRIBUTES CacheAttributes;
- UINTN Index = 0;
- ARM_MEMORY_REGION_DESCRIPTOR *VirtualMemoryTable;
- ASSERT(VirtualMemoryMap != NULL);
- VirtualMemoryTable =
- (ARM_MEMORY_REGION_DESCRIPTOR*)AllocatePages(EFI_SIZE_TO_PAGES
- (sizeof(ARM_MEMORY_REGION_DESCRIPTOR) *
- MAX_VIRTUAL_MEMORY_MAP_DESCRIPTORS));
- if (VirtualMemoryTable == NULL) {
- return;
- }
- if (FeaturePcdGet(PcdCacheEnable) == TRUE) {
- CacheAttributes = DDR_ATTRIBUTES_CACHED; } else {
- CacheAttributes = DDR_ATTRIBUTES_UNCACHED; }
- // DRAM1 (Must be 1st entry)
Why? Because the regions overlap? If so, please document that more explicitly.
No the DRAM regions do no overlap. But I noticed crashes in DXE phase if this is not the first entry.
I guess this first entry is passed via PEIM to DXE where the overall memory region availability is conveyed to DXE.
No, this is not the case. If you are seeing crashes dependent on the ordering here, and the regions do not overlap, you may have uncovered a bug in the page table code, and we'd like to know about it.
- VirtualMemoryTable[Index].PhysicalBase = LS1043A_DRAM1_BASE_ADDR;
- VirtualMemoryTable[Index].VirtualBase = LS1043A_DRAM1_BASE_ADDR;
- VirtualMemoryTable[Index].Length = LS1043A_DRAM1_SIZE;
- VirtualMemoryTable[Index].Attributes = CacheAttributes;
- // CCSR Space
- VirtualMemoryTable[++Index].PhysicalBase = LS1043A_CCSR_BASE_ADDR;
- VirtualMemoryTable[Index].VirtualBase = LS1043A_CCSR_BASE_ADDR;
- VirtualMemoryTable[Index].Length = LS1043A_CCSR_SIZE;
- VirtualMemoryTable[Index].Attributes =
ARM_MEMORY_REGION_ATTRIBUTE_DEVICE;
- // OCRAM1 Space
- VirtualMemoryTable[++Index].PhysicalBase =
- LS1043A_OCRAM1_BASE_ADDR; VirtualMemoryTable[Index].VirtualBase =
LS1043A_OCRAM1_BASE_ADDR;
- VirtualMemoryTable[Index].Length = LS1043A_OCRAM1_SIZE;
- VirtualMemoryTable[Index].Attributes = CacheAttributes;
- // OCRAM2 Space
- VirtualMemoryTable[++Index].PhysicalBase =
- LS1043A_OCRAM2_BASE_ADDR; VirtualMemoryTable[Index].VirtualBase =
LS1043A_OCRAM2_BASE_ADDR;
- VirtualMemoryTable[Index].Length = LS1043A_OCRAM2_SIZE;
- VirtualMemoryTable[Index].Attributes = CacheAttributes;
- // IFC region 1
- VirtualMemoryTable[++Index].PhysicalBase =
- LS1043A_IFC_REGION1_BASE_ADDR;
VirtualMemoryTable[Index].VirtualBase = LS1043A_IFC_REGION1_BASE_ADDR;
- VirtualMemoryTable[Index].Length =
LS1043A_IFC_REGION1_BASE_SIZE;
- VirtualMemoryTable[Index].Attributes =
ARM_MEMORY_REGION_ATTRIBUTE_UNCACHED_UNBUFFERED;
- // QMAN SWP
- VirtualMemoryTable[++Index].PhysicalBase =
- LS1043A_QMAN_SWP_BASE_ADDR; VirtualMemoryTable[Index].VirtualBase
= LS1043A_QMAN_SWP_BASE_ADDR;
- VirtualMemoryTable[Index].Length = LS1043A_QMAN_SWP_SIZE;
- VirtualMemoryTable[Index].Attributes =
ARM_MEMORY_REGION_ATTRIBUTE_UNCACHED_UNBUFFERED;
- // BMAN SWP
- VirtualMemoryTable[++Index].PhysicalBase =
- LS1043A_BMAN_SWP_BASE_ADDR; VirtualMemoryTable[Index].VirtualBase
= LS1043A_BMAN_SWP_BASE_ADDR;
- VirtualMemoryTable[Index].Length = LS1043A_BMAN_SWP_SIZE;
- VirtualMemoryTable[Index].Attributes =
ARM_MEMORY_REGION_ATTRIBUTE_UNCACHED_UNBUFFERED;
- // IFC region 2
- VirtualMemoryTable[++Index].PhysicalBase =
- LS1043A_IFC_REGION2_BASE_ADDR;
VirtualMemoryTable[Index].VirtualBase = LS1043A_IFC_REGION2_BASE_ADDR;
- VirtualMemoryTable[Index].Length =
LS1043A_IFC_REGION2_BASE_SIZE;
- VirtualMemoryTable[Index].Attributes = CacheAttributes;
- // DRAM2
- VirtualMemoryTable[++Index].PhysicalBase =
LS1043A_DRAM2_BASE_ADDR;
- VirtualMemoryTable[Index].VirtualBase = LS1043A_DRAM2_BASE_ADDR;
- VirtualMemoryTable[Index].Length = LS1043A_DRAM2_SIZE;
- VirtualMemoryTable[Index].Attributes = CacheAttributes;
- // PCIe1
- VirtualMemoryTable[++Index].PhysicalBase =
- LS1043A_PCI_EXP1_BASE_ADDR; VirtualMemoryTable[Index].VirtualBase
= LS1043A_PCI_EXP1_BASE_ADDR;
- VirtualMemoryTable[Index].Length =
LS1043A_PCI_EXP1_BASE_SIZE;
- VirtualMemoryTable[Index].Attributes =
ARM_MEMORY_REGION_ATTRIBUTE_DEVICE;
- // PCIe2
- VirtualMemoryTable[++Index].PhysicalBase =
- LS1043A_PCI_EXP2_BASE_ADDR; VirtualMemoryTable[Index].VirtualBase
= LS1043A_PCI_EXP2_BASE_ADDR;
- VirtualMemoryTable[Index].Length =
LS1043A_PCI_EXP2_BASE_SIZE;
- VirtualMemoryTable[Index].Attributes =
ARM_MEMORY_REGION_ATTRIBUTE_DEVICE;
- // PCIe3
- VirtualMemoryTable[++Index].PhysicalBase =
- LS1043A_PCI_EXP3_BASE_ADDR; VirtualMemoryTable[Index].VirtualBase
= LS1043A_PCI_EXP3_BASE_ADDR;
- VirtualMemoryTable[Index].Length =
LS1043A_PCI_EXP3_BASE_SIZE;
- VirtualMemoryTable[Index].Attributes =
ARM_MEMORY_REGION_ATTRIBUTE_DEVICE;
- // DRAM3
- VirtualMemoryTable[++Index].PhysicalBase =
LS1043A_DRAM3_BASE_ADDR;
- VirtualMemoryTable[Index].VirtualBase = LS1043A_DRAM3_BASE_ADDR;
- VirtualMemoryTable[Index].Length = LS1043A_DRAM3_SIZE;
- VirtualMemoryTable[Index].Attributes = CacheAttributes;
- // End of Table
- VirtualMemoryTable[++Index].PhysicalBase = 0;
- VirtualMemoryTable[Index].VirtualBase = 0;
- VirtualMemoryTable[Index].Length = 0;
- VirtualMemoryTable[Index].Attributes =
(ARM_MEMORY_REGION_ATTRIBUTES)0;
- ASSERT((Index + 1) <= MAX_VIRTUAL_MEMORY_MAP_DESCRIPTORS);
- *VirtualMemoryMap = VirtualMemoryTable; }
-- 1.9.1
Regards, Bhupesh
Generic comment - there are quite a few tabs interspersed in the below. Apart from going against the coding style, it does not appear intentional (as freely mixed). BaseTools/Scripts/PatchCheck.py can help weed out minor formatting issues like this.
On Tue, Oct 18, 2016 at 01:34:00AM +0530, Bhupesh Sharma wrote:
From: Sakar Arora sakar.arora@nxp.com
This patch adds the basic support for NXP/FSL's LS1043A RDB board. LS1043A RDB board supports a number of on-board peripherals. This patch adds the basic framework for the same.
Further details about this board can be seen here: http://www.nxp.com/products/microcontrollers-and-processors/ arm-processors/qoriq-arm-processors/qoriq-ls1043a-reference-design-board:LS1043A-RDB
Signed-off-by: Sakar Arora sakar.arora@nxp.com Signed-off-by: Bhupesh Sharma bhupesh.sharma@nxp.com
Platforms/Nxp/LS1043aRdb/Include/Library/Common.h | 68 ++++++++ .../Nxp/LS1043aRdb/Include/Library/PlatformLib.h | 178 +++++++++++++++++++++ .../Nxp/LS1043aRdb/Library/LS1043aRdbLib/Common.c | 103 ++++++++++++ .../LS1043aRdb/Library/LS1043aRdbLib/LS1043aRdb.c | 107 +++++++++++++ .../Library/LS1043aRdbLib/LS1043aRdbHelper.S | 61 +++++++ .../Library/LS1043aRdbLib/LS1043aRdbLib.inf | 56 +++++++ .../Library/LS1043aRdbLib/LS1043aRdbMem.c | 149 +++++++++++++++++ 7 files changed, 722 insertions(+) create mode 100644 Platforms/Nxp/LS1043aRdb/Include/Library/Common.h create mode 100644 Platforms/Nxp/LS1043aRdb/Include/Library/PlatformLib.h create mode 100644 Platforms/Nxp/LS1043aRdb/Library/LS1043aRdbLib/Common.c create mode 100644 Platforms/Nxp/LS1043aRdb/Library/LS1043aRdbLib/LS1043aRdb.c create mode 100644 Platforms/Nxp/LS1043aRdb/Library/LS1043aRdbLib/LS1043aRdbHelper.S create mode 100644 Platforms/Nxp/LS1043aRdb/Library/LS1043aRdbLib/LS1043aRdbLib.inf create mode 100644 Platforms/Nxp/LS1043aRdb/Library/LS1043aRdbLib/LS1043aRdbMem.c
diff --git a/Platforms/Nxp/LS1043aRdb/Include/Library/Common.h b/Platforms/Nxp/LS1043aRdb/Include/Library/Common.h new file mode 100644 index 0000000..192a249 --- /dev/null +++ b/Platforms/Nxp/LS1043aRdb/Include/Library/Common.h @@ -0,0 +1,68 @@ +/** @Common.h
- Header defining the General Purpose Utilities
- Copyright (c) 2016, Freescale Semiconductor, Inc. All rights reserved.
- This program and the accompanying materials
- are licensed and made available under the terms and conditions of the BSD License
- which accompanies this distribution. The full text of the license may be found at
- http://opensource.org/licenses/bsd-license.php
- THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
- WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
+**/
+#ifndef __COMMON_H__ +#define __COMMON_H__
Feels like a very "common" name ... add the LS1043aRDB prefix like in later files?
+#define DMA_MINALIGN 64
+#define offsetof(TYPE, MEMBER) ((UINTN) &((TYPE *)0)->MEMBER)
+typedef UINTN PhysAddrT; +typedef UINTN PhysSizeT;
+static inline PhysAddrT VirtToPhys(VOID * VAddr) +{
return (PhysAddrT)(VAddr);
+}
+/*
- The ALLOC_CACHE_ALIGN_BUF macro is used to allocate a buffer
- that meets the minimum architecture alignment requirements for DMA.
- The resulting buffer is aligned to the value of DMA_MINALIGN.
- The buffer variable created is a pointer to the specified type, and
- NOT an array.
- The size parameter is the number of array elements to allocate.
- */
+#define ALIGN_BUFF(x,a) ALIGN_MSK((x),(typeof(x))(a)-1)
BUFF here, BUF later on.
+#define ALIGN_MSK(x,mask) (((x)+(mask))&~(mask))
+#define PAD_CNT(S, Pad) (((S) - 1) / (Pad) + 1) +#define PAD_SIZE(S, Pad) (PAD_CNT(S, Pad) * Pad)
+#define ROUND_OFF(a,b) (((a) + (b) - 1) & ~((b) - 1))
+#define DMA_MINALIGN 64
+#define ALLOC_ALIGN_BUF_PAD(Type, Name, Size, Align, Pad) \
- INT8 __##Name[ROUND_OFF(PAD_SIZE((Size) * sizeof(Type), Pad), Align) \
+ (Align - 1)]; \
\
- Type *Name = (Type *) ALIGN_BUFF((UINTN)__##Name, Align)
+#define ALLOC_ALIGN_BUF(Type, Name, Size, Align) \
- ALLOC_ALIGN_BUF_PAD(Type, Name, Size, Align, 1)
+#define ALLOC_CACHE_ALIGN_BUF_PAD(Type, Name, Size, Pad) \
- ALLOC_ALIGN_BUF_PAD(Type, Name, size, DMA_MINALIGN, Pad)
+#define ALLOC_CACHE_ALIGN_BUF(Type, Name, Size) \
- ALLOC_ALIGN_BUF(Type, Name, Size, DMA_MINALIGN)
+#endif
So, a generic comment/question on this file: It looks much like the kind of header used to glue a piece of OS-independent code into a specific codebase. Is this what is being done here? If so, a bit more leeway can be given in the interest of simplifying future updates from new OS-independent releases.
Otherwise, much of what is defined in this Common.h could be replaced with already-existing macros/helpers.
diff --git a/Platforms/Nxp/LS1043aRdb/Include/Library/PlatformLib.h b/Platforms/Nxp/LS1043aRdb/Include/Library/PlatformLib.h new file mode 100644 index 0000000..39247e8 --- /dev/null +++ b/Platforms/Nxp/LS1043aRdb/Include/Library/PlatformLib.h @@ -0,0 +1,178 @@ +/** LS1043aRdb.h +* Header defining the LS1043aRdb constants (Base addresses, sizes, flags) +* +* Copyright (c) 2016, Freescale Semiconductor, Inc. All rights reserved. +* +* This program and the accompanying materials +* are licensed and made available under the terms and conditions of the BSD License +* which accompanies this distribution. The full text of the license may be found at +* http://opensource.org/licenses/bsd-license.php +* +* THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, +* WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. +* +**/
+#ifndef __LS1043aRDB_PLATFORM_H__ +#define __LS1043aRDB_PLATFORM_H__
+// Types +#define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
+// DDR attributes +#define DDR_ATTRIBUTES_CACHED ARM_MEMORY_REGION_ATTRIBUTE_WRITE_BACK +#define DDR_ATTRIBUTES_UNCACHED ARM_MEMORY_REGION_ATTRIBUTE_UNCACHED_UNBUFFERED
+#define LS1043A_CACHELINE_SIZE 32
+#define LS1043A_SECURE_BOOTROM_BASE_ADDR 0x00000000 +#define LS1043A_SECURE_BOOTROM_SIZE 0x00100000 /* 1MB */
Could use SIZE_1M (and x * SIZE_1M below).
+#define LS1043A_EXT_BOOTROM_BASE_ADDR 0x00100000 +#define LS1043A_EXT_BOOTROM_SIZE 0x00F00000 /* 15MB */ +#define LS1043A_CCSR_BASE_ADDR 0x01000000 +#define LS1043A_CCSR_SIZE 0x0F000000 /* 240MB */
- #define LS1043A_IMMR 0x01000000
- #define LS1043A_DDR_ADDR 0x01080000
- #define LS1043A_DSPI_ADDR 0x02100000
- #define LS1043A_SDXC_ADDR 0x01560000
- #define LS1043A_CCI400_ADDR (LS1043A_IMMR + 0x00180000)
- #define LS1043A_TZASC380_ADDR (LS1043A_IMMR + 0x00500000)
- #define LS1043A_CSU_ADDR (LS1043A_IMMR + 0x00510000)
- #define LS1043A_GUTS_ADDR (LS1043A_IMMR + 0x00ee0000)
- #define LS1043A_CLK_ADDR (LS1043A_IMMR + 0x00ee1000)
- #define LS1043A_FMAN_ADDR (LS1043A_IMMR + 0x00a00000)
- #define LS1043A_BMAN_ADDR (LS1043A_IMMR + 0x00890000)
- #define LS1043A_QMAN_ADDR (LS1043A_IMMR + 0x00880000)
- #define GIC_BASE_ADDR 0x01402000
- #define GIC_SIZE 0x1000
SIZE_4KB? (and so on in further locations below?)
- #define GICDIST_BASE_ADDR 0x01401000
- #define GICDIST_SIZE 0x1000
- #define DUART1_BASE_ADDR 0x21C0000
- #define DUART1_SIZE 0x1000
- #define DUART2_BASE_ADDR 0x21D0000
- #define DUART2_SIZE 0x1000
- #define WDOG1_BASE_ADDR 0x02AD0000
- #define WDOG2_BASE_ADDR 0x02AE0000
- #define WDOG3_BASE_ADDR 0x02A70000
- #define WDOG4_BASE_ADDR 0x02A80000
- #define WDOG5_BASE_ADDR 0x02A90000
- #define WDOG_SIZE 0x1000
#define WDOG_WCR_OFFSET 0
#define WDOG_WSR_OFFSET 2
#define WDOG_WRSR_OFFSET 4
#define WDOG_WICR_OFFSET 6
#define WDOG_WCR_WT (0xFF << 8)
#define WDOG_WCR_WDE (1 << 2)
#define WDOG_SERVICE_SEQ1 0x5555
#define WDOG_SERVICE_SEQ2 0xAAAA
- #define WDOG_WCR_WDZST 0x1
- #define WDOG_WCR_WRE (1 << 3) /* -> WDOG Reset Enable */
- #define I2C0_BASE_ADDRESS 0x02180000
- #define I2C1_BASE_ADDRESS 0x02190000
- #define I2C2_BASE_ADDRESS 0x021A0000
- #define I2C3_BASE_ADDRESS 0x02183000
- #define I2C_SIZE 0x10000
- #define DSPI_MEMORY_SIZE 0x10000
- #define DDRC_MEMORY_SIZE 0x10000
- #define SDXC_MEMORY_SIZE 0x10000
- #define LS1043A_TIMER_ADDR 0x02b00000
- #define IFC_REG_BASE_ADDR 0x1530000
- #define IFC_REG_SIZE 0x0003000
- #define SCFG_BASE_ADDR 0x1570000
- #define SCFG_SIZE 0x0010000
+/* SMMU Defintions */ +#define SMMU_BASE_ADDR 0x09000000 +#define SMMU_REG_SCR0 (SMMU_BASE_ADDR + 0x0) +#define SMMU_REG_SACR (SMMU_BASE_ADDR + 0x10) +#define SMMU_REG_IDR1 (SMMU_BASE_ADDR + 0x24) +#define SMMU_REG_NSCR0 (SMMU_BASE_ADDR + 0x400) +#define SMMU_REG_NSACR (SMMU_BASE_ADDR + 0x410)
+#define SCR0_USFCFG_MASK 0x00000400 +#define SCR0_CLIENTPD_MASK 0x00000001 +#define SACR_PAGESIZE_MASK 0x00010000 +#define IDR1_PAGESIZE_MASK 0x80000000
+#define LS1043A_OCRAM1_BASE_ADDR 0x10000000 +#define LS1043A_OCRAM1_SIZE 0x00010000 /* 64KB */ +#define LS1043A_OCRAM2_BASE_ADDR 0x10010000 +#define LS1043A_OCRAM2_SIZE 0x00010000 /* 64KB */ +#define LS1043A_STM_BASE_ADDR 0x12000000 +#define LS1043A_STM_SIZE 0x01000000 /* 16MB */ +#define LS1043A_DCSR_BASE_ADDR 0x20000000 +#define LS1043A_DCSR_SIZE 0x04000000 /* 64MB */ +#define LS1043A_QSPI_BASE_ADDR 0x40000000 +#define LS1043A_QSPI_SIZE 0x20000000 /* 512MB */ +#define LS1043A_IFC_REGION1_BASE_ADDR 0x60000000 +#define LS1043A_IFC_REGION1_BASE_SIZE 0x20000000 /* 512MB */ +#define LS1043A_DRAM1_BASE_ADDR 0x0080000000 +#define LS1043A_DRAM1_SIZE 0x0080000000 /* 2GB */ +#define LS1043A_QMAN_SWP_BASE_ADDR 0x0500000000 +#define LS1043A_QMAN_SWP_SIZE 0x0080000000 /* 128MB */ +#define LS1043A_BMAN_SWP_BASE_ADDR 0x0508000000 +#define LS1043A_BMAN_SWP_SIZE 0x0080000000 /* 128MB */ +#define LS1043A_IFC_REGION2_BASE_ADDR 0x0620000000 +#define LS1043A_IFC_REGION2_BASE_SIZE 0x00E0000000 /* 3.5GB */ +#define LS1043A_DRAM2_BASE_ADDR 0x0880000000 +#define LS1043A_DRAM2_SIZE 0x0780000000 /* 30GB */ +#define LS1043A_SERDES_ADDR (LS1043A_IMMR + 0xEA0000) +#define LS1043A_SRDS_1 +#define LS1043A_PCI_EXP1_BASE_ADDR 0x4000000000 +#define LS1043A_PCI_EXP1_BASE_SIZE 0x800000000 /* 32GB */ +#define LS1043A_PCI_EXP2_BASE_ADDR 0x4800000000 +#define LS1043A_PCI_EXP2_BASE_SIZE 0x800000000 /* 32GB */ +#define LS1043A_PCI_EXP3_BASE_ADDR 0x5000000000 +#define LS1043A_PCI_EXP3_BASE_SIZE 0x800000000 /* 32GB */ +#define LS1043A_DRAM3_BASE_ADDR 0x8800000000 +#define LS1043A_DRAM3_SIZE 0x7800000000 /* 480GB */
+/*
- CPLD
- */
+#define LS1043A_CPLD_BASE 0x7fb00000
+/*
- Global defines
- */
+#define NOR_BOOT 0x0 +#define NAND_BOOT 0x1 +#define SD_BOOT 0x2
+/* PCI controllers addresses */ +#define LS1043A_PCIE1_PHYS_BASE 0x5000000000ULL +#define LS1043A_PCIE2_PHYS_BASE 0x4800000000ULL +#define LS1043A_PCIE3_PHYS_BASE 0x5000000000ULL
+#define LS1043A_PCIE1_PHYS_ADDR 0x5000000000ULL +#define LS1043A_PCIE2_PHYS_ADDR 0x4800000000ULL +#define LS1043A_PCIE3_PHYS_ADDR 0x5000000000ULL
+#define LS1043A_PCIE1_ADDR 0x03600000 +#define LS1043A_PCIE2_ADDR 0x03500000 +#define LS1043A_PCIE3_ADDR 0x03600000
+/* PCIe */ +#define LS1043A_LS_PCI /* Enable PCI/PCIE */ +#define LS1043A_LS_PCIE1 /* PCIE controler 1 */ +#define LS1043A_LS_PCIE2 /* PCIE controler 2 */ +#define LS1043A_LS_PCIE3 /* PCIE controler 2 */ +#define LS1043A_LS_PCIE_LAYERSCAPE /* Use common FSL Layerscape PCIe code */
+#define LS1043A_LS_PCI_64BIT
+#define LS1043A_LS_PCIE_CFG0_PHYS_OFF 0x00000000 +#define LS1043A_LS_PCIE_CFG0_SIZE 0x00001000 /* 4k */ +#define LS1043A_LS_PCIE_CFG1_PHYS_OFF 0x00001000 +#define LS1043A_LS_PCIE_CFG1_SIZE 0x00001000 /* 4k */
+#define LS1043A_LS_PCIE_IO_BUS 0x00000000 +#define LS1043A_LS_PCIE_IO_PHYS_OFF 0x00010000 +#define LS1043A_LS_PCIE_IO_SIZE 0x00010000 /* 64k */
+#define LS1043A_LS_PCIE_MEM_BUS 0x40000000 +#define LS1043A_LS_PCIE_MEM_PHYS_OFF 0x40000000 +#define LS1043A_LS_PCIE_MEM_SIZE 0x40000000 /* 1 GB */
+#endif diff --git a/Platforms/Nxp/LS1043aRdb/Library/LS1043aRdbLib/Common.c b/Platforms/Nxp/LS1043aRdb/Library/LS1043aRdbLib/Common.c new file mode 100644 index 0000000..7159749 --- /dev/null +++ b/Platforms/Nxp/LS1043aRdb/Library/LS1043aRdbLib/Common.c @@ -0,0 +1,103 @@ +/** Common.c +* +* Copyright (c) 2016, Freescale Ltd. All rights reserved. +* +* This program and the accompanying materials +* are licensed and made available under the terms and conditions of the BSD License +* which accompanies this distribution. The full text of the license may be found at +* http://opensource.org/licenses/bsd-license.php +* +* THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, +* WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. +* +**/
+#include <Library/PlatformLib.h> +#include <Library/DebugLib.h>
+UINT32 +__Div64_32 (
- IN UINT64 *N,
- IN UINT32 Base
- )
+{
- UINT64 Rem = *N;
- UINT64 b = Base;
- UINT64 Res, d = 1;
- UINT32 High = Rem >> 32;
- /** Reduce the thing a bit first */
- Res = 0;
- if (High >= Base) {
- High /= Base;
- Res = (UINT64) High << 32;
- Rem -= (UINT64) (High*Base) << 32;
- }
- while ((UINTN)b > 0 && b < Rem) {
- b = b+b;
- d = d+d;
- }
- do {
- if (Rem >= b) {
Rem -= b;
Res += d;
- }
- b >>= 1;
- d >>= 1;
- } while (d);
- *N = Res;
- return Rem;
+}
+/*
- PrINT32 Sizes As "Xxx KiB", "Xxx.Y KiB", "Xxx MiB", "Xxx.Y MiB",
- Xxx GiB, Xxx.Y GiB, Etc As Needed; Allow for Optional Trailing String
- (Like "\n")
- */
+VOID +PrintSize (
- IN UINT64 Size,
- IN CONST INT8 *S
- )
+{
- UINT64 M = 0, N;
- UINT64 F;
- static CONST INT8 Names[] = {'E', 'P', 'T', 'G', 'M', 'K'};
- UINT64 D = 10 * ARRAY_SIZE(Names);
- CHAR8 C = 0;
- UINT32 I;
- for (I = 0; I < ARRAY_SIZE(Names); I++, D -= 10) {
- if (Size >> D) {
C = Names[I];
break;
- }
- }
- if (!C) {
- DEBUG((EFI_D_ERROR, "%Ld Bytes,\n %a", Size, S));
- return;
- }
- N = Size >> D;
- F = Size & ((1ULL << D) - 1);
- /* if There'S A Remainder, Deal With It */
Capitalization above makes my forehead wrinkle slightly. Could just say "Deal with any remainder.".
- if (F) {
- M = (10ULL * F + (1ULL << (D - 1))) >> D;
- if (M >= 10) {
M -= 10;
N += 1;
- }
- }
- DEBUG((EFI_D_ERROR, "%Ld", N));
- if (M) {
- DEBUG((EFI_D_ERROR, ".%Ld", M));
- }
- DEBUG((EFI_D_ERROR, " %ciB, %a ", C, S));
+} diff --git a/Platforms/Nxp/LS1043aRdb/Library/LS1043aRdbLib/LS1043aRdb.c b/Platforms/Nxp/LS1043aRdb/Library/LS1043aRdbLib/LS1043aRdb.c new file mode 100644 index 0000000..4fcb8a3 --- /dev/null +++ b/Platforms/Nxp/LS1043aRdb/Library/LS1043aRdbLib/LS1043aRdb.c @@ -0,0 +1,107 @@ +/** LS1043aRdb.c +* +* RDB specific Library for LS1043A SoC, containing functions to initialize +* RDB boards. +* +* Based on BeagleBoardPkg/Library/BeagleBoardLib/BeagleBoard.c +* +* Copyright (c) 2011-2012, ARM Limited. All rights reserved. +* Copyright (c) 2016, Freescale Semiconductor, Inc. All rights reserved. +* +* This program and the accompanying materials +* are licensed and made available under the terms and conditions of the BSD License +* which accompanies this distribution. The full text of the license may be found at +* http://opensource.org/licenses/bsd-license.php +* +* THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, +* WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. +* +**/
+#include <Library/IoLib.h> +#include <Library/ArmPlatformLib.h> +#include <Library/DebugLib.h> +#include <Library/PcdLib.h> +#include <Ppi/ArmMpCoreInfo.h> +#include <Library/PlatformLib.h>
+/**
- Return the current Boot Mode
- This function returns the boot reason on the platform
+**/ +EFI_BOOT_MODE +ArmPlatformGetBootMode (
- VOID
- )
+{
- return BOOT_WITH_FULL_CONFIGURATION;
+}
+/**
- Placeholder for Platform Initialization
+**/ +RETURN_STATUS +ArmPlatformInitialize (
- IN UINTN MpId
- )
+{
- return RETURN_SUCCESS;
+}
+ARM_CORE_INFO LS1043aMpCoreInfoCTA53x4[] = {
- {
- // Cluster 0, Core 0
- 0x0, 0x0,
- // MP Core MailBox Set/Get/Clear Addresses and Clear Value
- (EFI_PHYSICAL_ADDRESS)0,
- (EFI_PHYSICAL_ADDRESS)0,
- (EFI_PHYSICAL_ADDRESS)0,
- (UINT64)0xFFFFFFFF
- },
+};
+EFI_STATUS +PrePeiCoreGetMpCoreInfo (
- OUT UINTN *CoreCount,
- OUT ARM_CORE_INFO **ArmCoreTable
- )
+{
- *CoreCount = sizeof(LS1043aMpCoreInfoCTA53x4) / sizeof(ARM_CORE_INFO);
- *ArmCoreTable = LS1043aMpCoreInfoCTA53x4;
- return EFI_SUCCESS;
+}
+// Needs to be declared in the file. Otherwise gArmMpCoreInfoPpiGuid is undefined in the contect of PrePeiCore +EFI_GUID mArmMpCoreInfoPpiGuid = ARM_MP_CORE_INFO_PPI_GUID; +ARM_MP_CORE_INFO_PPI mMpCoreInfoPpi = { PrePeiCoreGetMpCoreInfo };
+EFI_PEI_PPI_DESCRIPTOR gPlatformPpiTable[] = {
- {
- EFI_PEI_PPI_DESCRIPTOR_PPI,
- &mArmMpCoreInfoPpiGuid,
- &mMpCoreInfoPpi
- }
+};
+VOID +ArmPlatformGetPlatformPpiList (
- OUT UINTN *PpiListSize,
- OUT EFI_PEI_PPI_DESCRIPTOR **PpiList
- )
+{
- *PpiListSize = sizeof(gPlatformPpiTable);
- *PpiList = gPlatformPpiTable;
+}
+UINTN +ArmPlatformGetCorePosition (
- IN UINTN MpId
- )
+{
- return 1;
+} diff --git a/Platforms/Nxp/LS1043aRdb/Library/LS1043aRdbLib/LS1043aRdbHelper.S b/Platforms/Nxp/LS1043aRdb/Library/LS1043aRdbLib/LS1043aRdbHelper.S new file mode 100644 index 0000000..5d9807f --- /dev/null +++ b/Platforms/Nxp/LS1043aRdb/Library/LS1043aRdbLib/LS1043aRdbHelper.S @@ -0,0 +1,61 @@ +# @file +# +# Based on BeagleBoardPkg/Library/BeagleBoardLib/BeagleBoardHelper.S +# +# Copyright (c) 2012-2013, ARM Limited. All rights reserved. +# Copyright (c) 2016, Freescale Semiconductor, Inc. All rights reserved. +# +# This program and the accompanying materials +# are licensed and made available under the terms and conditions of the BSD License +# which accompanies this distribution. The full text of the license may be found at +# http://opensource.org/licenses/bsd-license.php +# +# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, +# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. +# +#
+#include <AsmMacroIoLib.h> +#include <AsmMacroIoLibV8.h> +#include <AutoGen.h>
+.text +.align 2
+GCC_ASM_EXPORT(ArmPlatformIsPrimaryCore) +GCC_ASM_EXPORT(ArmPlatformGetPrimaryCoreMpId) +GCC_ASM_EXPORT(ArmPlatformPeiBootAction)
+GCC_ASM_IMPORT(ArmReadMpidr)
+//UINTN +//ArmPlatformIsPrimaryCore ( +// IN UINTN MpId +// ); +ASM_PFX(ArmPlatformIsPrimaryCore):
- and x1, x0, #3
- mov x0, #0
- cbnz x1, 1f
- mov x0, #1
+1:
- ret
+ASM_PFX(ArmPlatformPeiBootAction): +EL1_OR_EL2_OR_EL3(x0) +1: +2:
- ret
+3:
- LoadConstantToReg(FixedPcdGet32(PcdCounterFrequency), x0)
- msr cntfrq_el0, x0
- ret
+//UINTN +//ArmPlatformGetPrimaryCoreMpId ( +// VOID +// ); +ASM_PFX(ArmPlatformGetPrimaryCoreMpId):
- LoadConstantToReg (FixedPcdGet32(PcdArmPrimaryCore), x0)
- ldrh w0, [x0]
- ret
diff --git a/Platforms/Nxp/LS1043aRdb/Library/LS1043aRdbLib/LS1043aRdbLib.inf b/Platforms/Nxp/LS1043aRdb/Library/LS1043aRdbLib/LS1043aRdbLib.inf new file mode 100644 index 0000000..e09d940 --- /dev/null +++ b/Platforms/Nxp/LS1043aRdb/Library/LS1043aRdbLib/LS1043aRdbLib.inf @@ -0,0 +1,56 @@ +#/* @file +# Copyright (c) 2011-2013, ARM Limited. All rights reserved. +# Copyright (c) 2016, Freescale Semiconductor, Inc. All rights reserved. +# +# This program and the accompanying materials +# are licensed and made available under the terms and conditions of the BSD License +# which accompanies this distribution. The full text of the license may be found at +# http://opensource.org/licenses/bsd-license.php +# +# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, +# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. +# +#*/
+[Defines]
- INF_VERSION = 0x00010005
- BASE_NAME = LS1043aRdbLib
- FILE_GUID = 736343a0-1d96-11e0-aaaa-0002a5d5c51b
- MODULE_TYPE = BASE
- VERSION_STRING = 1.0
- LIBRARY_CLASS = ArmPlatformLib
+[Packages]
- MdePkg/MdePkg.dec
- MdeModulePkg/MdeModulePkg.dec
- EmbeddedPkg/EmbeddedPkg.dec
- ArmPkg/ArmPkg.dec
- ArmPlatformPkg/ArmPlatformPkg.dec
- OpenPlatformPkg/Platforms/Nxp/LS1043aRdb/LS1043aRdbPkg.dec
+[LibraryClasses]
- IoLib
- ArmLib
- MemoryAllocationLib
- I2cLib
- DdrLib
- SocLib
+[Sources.common]
- LS1043aRdbHelper.S | GCC
- LS1043aRdb.c
- LS1043aRdbMem.c
- Common.c
+[FeaturePcd]
- gEmbeddedTokenSpaceGuid.PcdCacheEnable
+[FixedPcd]
- gArmTokenSpaceGuid.PcdArmPrimaryCore
- gArmTokenSpaceGuid.PcdFdBaseAddress
- gArmTokenSpaceGuid.PcdFdSize
- gArmTokenSpaceGuid.PcdSystemMemoryBase
- gArmTokenSpaceGuid.PcdSystemMemorySize
- gArmPlatformTokenSpaceGuid.PcdCounterFrequency
As a generic OCD comment on the above - could Packages, LibraryClasses and *Pcd be alphabetically sorted within each section please?
diff --git a/Platforms/Nxp/LS1043aRdb/Library/LS1043aRdbLib/LS1043aRdbMem.c b/Platforms/Nxp/LS1043aRdb/Library/LS1043aRdbLib/LS1043aRdbMem.c new file mode 100644 index 0000000..ef93623 --- /dev/null +++ b/Platforms/Nxp/LS1043aRdb/Library/LS1043aRdbLib/LS1043aRdbMem.c @@ -0,0 +1,149 @@ +/** LS1043aRdbMem.c +* +* RDB memory specific Library for LS1043A SoC. +* +* Based on BeagleBoardPkg/Library/BeagleBoardLib/BeagleBoardMem.c +* +* Copyright (c) 2011, ARM Limited. All rights reserved. +* Copyright (c) 2016, Freescale Semiconductor, Inc. All rights reserved. +* +* This program and the accompanying materials +* are licensed and made available under the terms and conditions of the BSD License +* which accompanies this distribution. The full text of the license may be found at +* http://opensource.org/licenses/bsd-license.php +* +* THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, +* WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. +* +**/
+#include <Library/ArmPlatformLib.h> +#include <Library/DebugLib.h> +#include <Library/PcdLib.h> +#include <Library/MemoryAllocationLib.h> +#include <Library/IoLib.h>
+#include <Library/PlatformLib.h>
+#define MAX_VIRTUAL_MEMORY_MAP_DESCRIPTORS 25
Since this value will always be known at compile time (and unlikely to change frequently), could this be a NUM_* instead of MAX_*, and the code then stick with the ASSERT that Index < at the end?
+/**
- Return the Virtual Memory Map of your platform
- This Virtual Memory Map is used by MemoryInitPei Module to initialize the MMU on your platform.
- @param[out] VirtualMemoryMap Array of ARM_MEMORY_REGION_DESCRIPTOR describing a Physical-to-
Virtual Memory mapping. This array must be ended by a zero-filled
entry
+**/ +VOID +ArmPlatformGetVirtualMemoryMap (
- IN ARM_MEMORY_REGION_DESCRIPTOR** VirtualMemoryMap
- )
+{
- ARM_MEMORY_REGION_ATTRIBUTES CacheAttributes;
- UINTN Index = 0;
- ARM_MEMORY_REGION_DESCRIPTOR *VirtualMemoryTable;
- ASSERT(VirtualMemoryMap != NULL);
- VirtualMemoryTable = (ARM_MEMORY_REGION_DESCRIPTOR*)AllocatePages(EFI_SIZE_TO_PAGES (sizeof(ARM_MEMORY_REGION_DESCRIPTOR) * MAX_VIRTUAL_MEMORY_MAP_DESCRIPTORS));
Why cast a VOID * to they type of the pointer it is being assigned to on assignment? This could benefit from a temporary variable to shorten line length.
- if (VirtualMemoryTable == NULL) {
- return;
- }
- if (FeaturePcdGet(PcdCacheEnable) == TRUE) {
If the cache is not enabled, I don't think the platform port can be specification compliant. I.e., if there is some particular reason for this, the Pcd should possibly be named for that reason.
- CacheAttributes = DDR_ATTRIBUTES_CACHED;
- } else {
- CacheAttributes = DDR_ATTRIBUTES_UNCACHED;
- }
- // DRAM1 (Must be 1st entry)
- VirtualMemoryTable[Index].PhysicalBase = LS1043A_DRAM1_BASE_ADDR;
- VirtualMemoryTable[Index].VirtualBase = LS1043A_DRAM1_BASE_ADDR;
- VirtualMemoryTable[Index].Length = LS1043A_DRAM1_SIZE;
- VirtualMemoryTable[Index].Attributes = CacheAttributes;
- // CCSR Space
- VirtualMemoryTable[++Index].PhysicalBase = LS1043A_CCSR_BASE_ADDR;
- VirtualMemoryTable[Index].VirtualBase = LS1043A_CCSR_BASE_ADDR;
- VirtualMemoryTable[Index].Length = LS1043A_CCSR_SIZE;
- VirtualMemoryTable[Index].Attributes = ARM_MEMORY_REGION_ATTRIBUTE_DEVICE;
- // OCRAM1 Space
- VirtualMemoryTable[++Index].PhysicalBase = LS1043A_OCRAM1_BASE_ADDR;
- VirtualMemoryTable[Index].VirtualBase = LS1043A_OCRAM1_BASE_ADDR;
- VirtualMemoryTable[Index].Length = LS1043A_OCRAM1_SIZE;
- VirtualMemoryTable[Index].Attributes = CacheAttributes;
- // OCRAM2 Space
- VirtualMemoryTable[++Index].PhysicalBase = LS1043A_OCRAM2_BASE_ADDR;
- VirtualMemoryTable[Index].VirtualBase = LS1043A_OCRAM2_BASE_ADDR;
- VirtualMemoryTable[Index].Length = LS1043A_OCRAM2_SIZE;
- VirtualMemoryTable[Index].Attributes = CacheAttributes;
- // IFC region 1
- VirtualMemoryTable[++Index].PhysicalBase = LS1043A_IFC_REGION1_BASE_ADDR;
- VirtualMemoryTable[Index].VirtualBase = LS1043A_IFC_REGION1_BASE_ADDR;
- VirtualMemoryTable[Index].Length = LS1043A_IFC_REGION1_BASE_SIZE;
- VirtualMemoryTable[Index].Attributes = ARM_MEMORY_REGION_ATTRIBUTE_UNCACHED_UNBUFFERED;
- // QMAN SWP
- VirtualMemoryTable[++Index].PhysicalBase = LS1043A_QMAN_SWP_BASE_ADDR;
- VirtualMemoryTable[Index].VirtualBase = LS1043A_QMAN_SWP_BASE_ADDR;
- VirtualMemoryTable[Index].Length = LS1043A_QMAN_SWP_SIZE;
- VirtualMemoryTable[Index].Attributes = ARM_MEMORY_REGION_ATTRIBUTE_UNCACHED_UNBUFFERED;
- // BMAN SWP
- VirtualMemoryTable[++Index].PhysicalBase = LS1043A_BMAN_SWP_BASE_ADDR;
- VirtualMemoryTable[Index].VirtualBase = LS1043A_BMAN_SWP_BASE_ADDR;
- VirtualMemoryTable[Index].Length = LS1043A_BMAN_SWP_SIZE;
- VirtualMemoryTable[Index].Attributes = ARM_MEMORY_REGION_ATTRIBUTE_UNCACHED_UNBUFFERED;
- // IFC region 2
- VirtualMemoryTable[++Index].PhysicalBase = LS1043A_IFC_REGION2_BASE_ADDR;
- VirtualMemoryTable[Index].VirtualBase = LS1043A_IFC_REGION2_BASE_ADDR;
- VirtualMemoryTable[Index].Length = LS1043A_IFC_REGION2_BASE_SIZE;
- VirtualMemoryTable[Index].Attributes = CacheAttributes;
- // DRAM2
- VirtualMemoryTable[++Index].PhysicalBase = LS1043A_DRAM2_BASE_ADDR;
- VirtualMemoryTable[Index].VirtualBase = LS1043A_DRAM2_BASE_ADDR;
- VirtualMemoryTable[Index].Length = LS1043A_DRAM2_SIZE;
- VirtualMemoryTable[Index].Attributes = CacheAttributes;
- // PCIe1
- VirtualMemoryTable[++Index].PhysicalBase = LS1043A_PCI_EXP1_BASE_ADDR;
- VirtualMemoryTable[Index].VirtualBase = LS1043A_PCI_EXP1_BASE_ADDR;
- VirtualMemoryTable[Index].Length = LS1043A_PCI_EXP1_BASE_SIZE;
- VirtualMemoryTable[Index].Attributes = ARM_MEMORY_REGION_ATTRIBUTE_DEVICE;
- // PCIe2
- VirtualMemoryTable[++Index].PhysicalBase = LS1043A_PCI_EXP2_BASE_ADDR;
- VirtualMemoryTable[Index].VirtualBase = LS1043A_PCI_EXP2_BASE_ADDR;
- VirtualMemoryTable[Index].Length = LS1043A_PCI_EXP2_BASE_SIZE;
- VirtualMemoryTable[Index].Attributes = ARM_MEMORY_REGION_ATTRIBUTE_DEVICE;
- // PCIe3
- VirtualMemoryTable[++Index].PhysicalBase = LS1043A_PCI_EXP3_BASE_ADDR;
- VirtualMemoryTable[Index].VirtualBase = LS1043A_PCI_EXP3_BASE_ADDR;
- VirtualMemoryTable[Index].Length = LS1043A_PCI_EXP3_BASE_SIZE;
- VirtualMemoryTable[Index].Attributes = ARM_MEMORY_REGION_ATTRIBUTE_DEVICE;
- // DRAM3
- VirtualMemoryTable[++Index].PhysicalBase = LS1043A_DRAM3_BASE_ADDR;
- VirtualMemoryTable[Index].VirtualBase = LS1043A_DRAM3_BASE_ADDR;
- VirtualMemoryTable[Index].Length = LS1043A_DRAM3_SIZE;
- VirtualMemoryTable[Index].Attributes = CacheAttributes;
- // End of Table
- VirtualMemoryTable[++Index].PhysicalBase = 0;
- VirtualMemoryTable[Index].VirtualBase = 0;
- VirtualMemoryTable[Index].Length = 0;
- VirtualMemoryTable[Index].Attributes = (ARM_MEMORY_REGION_ATTRIBUTES)0;
(Dou you even need to set the Attributes at this point? If so, maybe we should just create a REGION_ATTRIBUTE_INVALID?)
- ASSERT((Index + 1) <= MAX_VIRTUAL_MEMORY_MAP_DESCRIPTORS);
- *VirtualMemoryMap = VirtualMemoryTable;
+}
1.9.1
Hi Leif,
Thanks for the review comments.
From: Leif Lindholm [mailto:leif.lindholm@linaro.org] Sent: Monday, October 24, 2016 5:37 PM
Generic comment - there are quite a few tabs interspersed in the below. Apart from going against the coding style, it does not appear intentional (as freely mixed). BaseTools/Scripts/PatchCheck.py can help weed out minor formatting issues like this.
Ok.
On Tue, Oct 18, 2016 at 01:34:00AM +0530, Bhupesh Sharma wrote:
From: Sakar Arora sakar.arora@nxp.com
This patch adds the basic support for NXP/FSL's LS1043A RDB board. LS1043A RDB board supports a number of on-board peripherals. This patch adds the basic framework for the same.
Further details about this board can be seen here: http://www.nxp.com/products/microcontrollers-and-processors/ arm-processors/qoriq-arm-processors/qoriq-ls1043a-reference-design-
boa
rd:LS1043A-RDB
Signed-off-by: Sakar Arora sakar.arora@nxp.com Signed-off-by: Bhupesh Sharma bhupesh.sharma@nxp.com
Platforms/Nxp/LS1043aRdb/Include/Library/Common.h | 68 ++++++++ .../Nxp/LS1043aRdb/Include/Library/PlatformLib.h | 178
+++++++++++++++++++++
.../Nxp/LS1043aRdb/Library/LS1043aRdbLib/Common.c | 103
++++++++++++
.../LS1043aRdb/Library/LS1043aRdbLib/LS1043aRdb.c | 107
+++++++++++++
.../Library/LS1043aRdbLib/LS1043aRdbHelper.S | 61 +++++++ .../Library/LS1043aRdbLib/LS1043aRdbLib.inf | 56 +++++++ .../Library/LS1043aRdbLib/LS1043aRdbMem.c | 149
+++++++++++++++++
7 files changed, 722 insertions(+) create mode 100644 Platforms/Nxp/LS1043aRdb/Include/Library/Common.h create mode 100644 Platforms/Nxp/LS1043aRdb/Include/Library/PlatformLib.h create mode 100644 Platforms/Nxp/LS1043aRdb/Library/LS1043aRdbLib/Common.c create mode 100644 Platforms/Nxp/LS1043aRdb/Library/LS1043aRdbLib/LS1043aRdb.c create mode 100644 Platforms/Nxp/LS1043aRdb/Library/LS1043aRdbLib/LS1043aRdbHelper.S create mode 100644 Platforms/Nxp/LS1043aRdb/Library/LS1043aRdbLib/LS1043aRdbLib.inf create mode 100644 Platforms/Nxp/LS1043aRdb/Library/LS1043aRdbLib/LS1043aRdbMem.c
diff --git a/Platforms/Nxp/LS1043aRdb/Include/Library/Common.h b/Platforms/Nxp/LS1043aRdb/Include/Library/Common.h new file mode 100644 index 0000000..192a249 --- /dev/null +++ b/Platforms/Nxp/LS1043aRdb/Include/Library/Common.h @@ -0,0 +1,68 @@ +/** @Common.h
- Header defining the General Purpose Utilities
- Copyright (c) 2016, Freescale Semiconductor, Inc. All rights
reserved.
- This program and the accompanying materials are licensed and made
- available under the terms and conditions of the BSD License which
- accompanies this distribution. The full text of the license may be
- found at http://opensource.org/licenses/bsd-license.php
- THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS"
- BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER
EXPRESS OR IMPLIED.
+**/
+#ifndef __COMMON_H__ +#define __COMMON_H__
Feels like a very "common" name ... add the LS1043aRDB prefix like in later files?
Sure.
+#define DMA_MINALIGN 64
+#define offsetof(TYPE, MEMBER) ((UINTN) &((TYPE *)0)->MEMBER)
+typedef UINTN PhysAddrT; +typedef UINTN PhysSizeT;
+static inline PhysAddrT VirtToPhys(VOID * VAddr) {
return (PhysAddrT)(VAddr);
+}
+/*
- The ALLOC_CACHE_ALIGN_BUF macro is used to allocate a buffer
- that meets the minimum architecture alignment requirements for
DMA.
- The resulting buffer is aligned to the value of DMA_MINALIGN.
- The buffer variable created is a pointer to the specified type,
+and
- NOT an array.
- The size parameter is the number of array elements to allocate.
- */
+#define ALIGN_BUFF(x,a) ALIGN_MSK((x),(typeof(x))(a)-1)
BUFF here, BUF later on.
Ok. Will change in V2.
+#define ALIGN_MSK(x,mask) (((x)+(mask))&~(mask))
+#define PAD_CNT(S, Pad) (((S) - 1) / (Pad) + 1) #define PAD_SIZE(S, +Pad) (PAD_CNT(S, Pad) * Pad)
+#define ROUND_OFF(a,b) (((a) + (b) - 1) & ~((b) - 1))
+#define DMA_MINALIGN 64
+#define ALLOC_ALIGN_BUF_PAD(Type, Name, Size, Align, Pad)
\
- INT8 __##Name[ROUND_OFF(PAD_SIZE((Size) * sizeof(Type), Pad),
Align) \
+ (Align - 1)]; \
\
- Type *Name = (Type *) ALIGN_BUFF((UINTN)__##Name, Align)
+#define ALLOC_ALIGN_BUF(Type, Name, Size, Align) \
- ALLOC_ALIGN_BUF_PAD(Type, Name, Size, Align, 1)
+#define ALLOC_CACHE_ALIGN_BUF_PAD(Type, Name, Size, Pad) \
- ALLOC_ALIGN_BUF_PAD(Type, Name, size, DMA_MINALIGN, Pad)
+#define ALLOC_CACHE_ALIGN_BUF(Type, Name, Size) \
- ALLOC_ALIGN_BUF(Type, Name, Size, DMA_MINALIGN)
+#endif
So, a generic comment/question on this file: It looks much like the kind of header used to glue a piece of OS- independent code into a specific codebase. Is this what is being done here? If so, a bit more leeway can be given in the interest of simplifying future updates from new OS-independent releases.
Right.
Otherwise, much of what is defined in this Common.h could be replaced with already-existing macros/helpers.
diff --git a/Platforms/Nxp/LS1043aRdb/Include/Library/PlatformLib.h b/Platforms/Nxp/LS1043aRdb/Include/Library/PlatformLib.h new file mode 100644 index 0000000..39247e8 --- /dev/null +++ b/Platforms/Nxp/LS1043aRdb/Include/Library/PlatformLib.h @@ -0,0 +1,178 @@ +/** LS1043aRdb.h +* Header defining the LS1043aRdb constants (Base addresses, sizes, +flags) +* +* Copyright (c) 2016, Freescale Semiconductor, Inc. All rights
reserved.
+* +* This program and the accompanying materials +* are licensed and made available under the terms and conditions of +the BSD License +* which accompanies this distribution. The full text of the
license
+may be found at +* http://opensource.org/licenses/bsd-license.php +* +* THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" +BASIS, +* WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS
OR IMPLIED.
+* +**/
+#ifndef __LS1043aRDB_PLATFORM_H__ +#define __LS1043aRDB_PLATFORM_H__
+// Types +#define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
+// DDR attributes +#define DDR_ATTRIBUTES_CACHED
ARM_MEMORY_REGION_ATTRIBUTE_WRITE_BACK
+#define DDR_ATTRIBUTES_UNCACHED
ARM_MEMORY_REGION_ATTRIBUTE_UNCACHED_UNBUFFERED
+#define LS1043A_CACHELINE_SIZE 32
+#define LS1043A_SECURE_BOOTROM_BASE_ADDR 0x00000000 +#define LS1043A_SECURE_BOOTROM_SIZE 0x00100000 /* 1MB */
Could use SIZE_1M (and x * SIZE_1M below).
Ok. Will change in V2.
+#define LS1043A_EXT_BOOTROM_BASE_ADDR 0x00100000 +#define LS1043A_EXT_BOOTROM_SIZE 0x00F00000 /* 15MB */ +#define LS1043A_CCSR_BASE_ADDR 0x01000000 +#define LS1043A_CCSR_SIZE 0x0F000000 /* 240MB */
- #define LS1043A_IMMR 0x01000000
- #define LS1043A_DDR_ADDR 0x01080000
- #define LS1043A_DSPI_ADDR 0x02100000
- #define LS1043A_SDXC_ADDR 0x01560000
- #define LS1043A_CCI400_ADDR (LS1043A_IMMR + 0x00180000)
- #define LS1043A_TZASC380_ADDR (LS1043A_IMMR + 0x00500000)
- #define LS1043A_CSU_ADDR (LS1043A_IMMR + 0x00510000)
- #define LS1043A_GUTS_ADDR (LS1043A_IMMR + 0x00ee0000)
- #define LS1043A_CLK_ADDR (LS1043A_IMMR + 0x00ee1000)
- #define LS1043A_FMAN_ADDR (LS1043A_IMMR + 0x00a00000)
- #define LS1043A_BMAN_ADDR (LS1043A_IMMR + 0x00890000)
- #define LS1043A_QMAN_ADDR (LS1043A_IMMR + 0x00880000)
- #define GIC_BASE_ADDR 0x01402000
- #define GIC_SIZE 0x1000
SIZE_4KB? (and so on in further locations below?)
Ok. Will change in V2.
- #define GICDIST_BASE_ADDR 0x01401000
- #define GICDIST_SIZE 0x1000
- #define DUART1_BASE_ADDR 0x21C0000
- #define DUART1_SIZE 0x1000
- #define DUART2_BASE_ADDR 0x21D0000
- #define DUART2_SIZE 0x1000
- #define WDOG1_BASE_ADDR 0x02AD0000
- #define WDOG2_BASE_ADDR 0x02AE0000
- #define WDOG3_BASE_ADDR 0x02A70000
- #define WDOG4_BASE_ADDR 0x02A80000
- #define WDOG5_BASE_ADDR 0x02A90000
- #define WDOG_SIZE 0x1000
#define WDOG_WCR_OFFSET 0
#define WDOG_WSR_OFFSET 2
#define WDOG_WRSR_OFFSET 4
#define WDOG_WICR_OFFSET 6
#define WDOG_WCR_WT (0xFF << 8)
#define WDOG_WCR_WDE (1 << 2)
#define WDOG_SERVICE_SEQ1 0x5555
#define WDOG_SERVICE_SEQ2 0xAAAA
- #define WDOG_WCR_WDZST 0x1
- #define WDOG_WCR_WRE (1 << 3) /* -> WDOG Reset Enable */
- #define I2C0_BASE_ADDRESS 0x02180000
- #define I2C1_BASE_ADDRESS 0x02190000
- #define I2C2_BASE_ADDRESS 0x021A0000
- #define I2C3_BASE_ADDRESS 0x02183000
- #define I2C_SIZE 0x10000
- #define DSPI_MEMORY_SIZE 0x10000
- #define DDRC_MEMORY_SIZE 0x10000
- #define SDXC_MEMORY_SIZE 0x10000
- #define LS1043A_TIMER_ADDR 0x02b00000
- #define IFC_REG_BASE_ADDR 0x1530000
- #define IFC_REG_SIZE 0x0003000
- #define SCFG_BASE_ADDR 0x1570000
- #define SCFG_SIZE 0x0010000
+/* SMMU Defintions */ +#define SMMU_BASE_ADDR 0x09000000 +#define SMMU_REG_SCR0 (SMMU_BASE_ADDR + 0x0) +#define SMMU_REG_SACR (SMMU_BASE_ADDR + 0x10) +#define SMMU_REG_IDR1 (SMMU_BASE_ADDR + 0x24) +#define SMMU_REG_NSCR0 (SMMU_BASE_ADDR + 0x400) +#define SMMU_REG_NSACR (SMMU_BASE_ADDR + 0x410)
+#define SCR0_USFCFG_MASK 0x00000400 +#define SCR0_CLIENTPD_MASK 0x00000001 +#define SACR_PAGESIZE_MASK 0x00010000 +#define IDR1_PAGESIZE_MASK 0x80000000
+#define LS1043A_OCRAM1_BASE_ADDR 0x10000000 +#define LS1043A_OCRAM1_SIZE 0x00010000 /* 64KB */ +#define LS1043A_OCRAM2_BASE_ADDR 0x10010000 +#define LS1043A_OCRAM2_SIZE 0x00010000 /* 64KB */ +#define LS1043A_STM_BASE_ADDR 0x12000000 +#define LS1043A_STM_SIZE 0x01000000 /* 16MB */ +#define LS1043A_DCSR_BASE_ADDR 0x20000000 +#define LS1043A_DCSR_SIZE 0x04000000 /* 64MB */ +#define LS1043A_QSPI_BASE_ADDR 0x40000000 +#define LS1043A_QSPI_SIZE 0x20000000 /* 512MB */ +#define LS1043A_IFC_REGION1_BASE_ADDR 0x60000000 +#define LS1043A_IFC_REGION1_BASE_SIZE 0x20000000 /* 512MB */ +#define LS1043A_DRAM1_BASE_ADDR 0x0080000000 +#define LS1043A_DRAM1_SIZE 0x0080000000 /* 2GB */ +#define LS1043A_QMAN_SWP_BASE_ADDR 0x0500000000 +#define LS1043A_QMAN_SWP_SIZE 0x0080000000 /* 128MB
*/
+#define LS1043A_BMAN_SWP_BASE_ADDR 0x0508000000 +#define LS1043A_BMAN_SWP_SIZE 0x0080000000 /* 128MB
*/
+#define LS1043A_IFC_REGION2_BASE_ADDR 0x0620000000 +#define LS1043A_IFC_REGION2_BASE_SIZE 0x00E0000000 /* 3.5GB
*/
+#define LS1043A_DRAM2_BASE_ADDR 0x0880000000 +#define LS1043A_DRAM2_SIZE 0x0780000000 /* 30GB */ +#define LS1043A_SERDES_ADDR (LS1043A_IMMR +
0xEA0000)
+#define LS1043A_SRDS_1 +#define LS1043A_PCI_EXP1_BASE_ADDR 0x4000000000 +#define LS1043A_PCI_EXP1_BASE_SIZE 0x800000000 /* 32GB */ +#define LS1043A_PCI_EXP2_BASE_ADDR 0x4800000000 +#define LS1043A_PCI_EXP2_BASE_SIZE 0x800000000 /* 32GB */ +#define LS1043A_PCI_EXP3_BASE_ADDR 0x5000000000 +#define LS1043A_PCI_EXP3_BASE_SIZE 0x800000000 /* 32GB */ +#define LS1043A_DRAM3_BASE_ADDR 0x8800000000 +#define LS1043A_DRAM3_SIZE 0x7800000000 /* 480GB */
+/*
- CPLD
- */
+#define LS1043A_CPLD_BASE 0x7fb00000
+/*
- Global defines
- */
+#define NOR_BOOT 0x0 +#define NAND_BOOT 0x1 +#define SD_BOOT 0x2
+/* PCI controllers addresses */ +#define LS1043A_PCIE1_PHYS_BASE 0x5000000000ULL +#define LS1043A_PCIE2_PHYS_BASE 0x4800000000ULL +#define LS1043A_PCIE3_PHYS_BASE 0x5000000000ULL
+#define LS1043A_PCIE1_PHYS_ADDR 0x5000000000ULL +#define LS1043A_PCIE2_PHYS_ADDR 0x4800000000ULL +#define LS1043A_PCIE3_PHYS_ADDR 0x5000000000ULL
+#define LS1043A_PCIE1_ADDR 0x03600000 +#define LS1043A_PCIE2_ADDR 0x03500000 +#define LS1043A_PCIE3_ADDR 0x03600000
+/* PCIe */ +#define LS1043A_LS_PCI /* Enable PCI/PCIE */ +#define LS1043A_LS_PCIE1 /* PCIE controler 1 */ +#define LS1043A_LS_PCIE2 /* PCIE controler 2 */ +#define LS1043A_LS_PCIE3 /* PCIE controler 2 */ +#define LS1043A_LS_PCIE_LAYERSCAPE /* Use common FSL Layerscape
PCIe
+code */
+#define LS1043A_LS_PCI_64BIT
+#define LS1043A_LS_PCIE_CFG0_PHYS_OFF 0x00000000 +#define LS1043A_LS_PCIE_CFG0_SIZE 0x00001000 /* 4k */ +#define LS1043A_LS_PCIE_CFG1_PHYS_OFF 0x00001000 +#define LS1043A_LS_PCIE_CFG1_SIZE 0x00001000 /* 4k */
+#define LS1043A_LS_PCIE_IO_BUS 0x00000000 +#define LS1043A_LS_PCIE_IO_PHYS_OFF 0x00010000 +#define LS1043A_LS_PCIE_IO_SIZE 0x00010000 /* 64k */
+#define LS1043A_LS_PCIE_MEM_BUS 0x40000000 +#define LS1043A_LS_PCIE_MEM_PHYS_OFF 0x40000000 +#define LS1043A_LS_PCIE_MEM_SIZE 0x40000000 /* 1 GB */
+#endif diff --git a/Platforms/Nxp/LS1043aRdb/Library/LS1043aRdbLib/Common.c b/Platforms/Nxp/LS1043aRdb/Library/LS1043aRdbLib/Common.c new file mode 100644 index 0000000..7159749 --- /dev/null +++ b/Platforms/Nxp/LS1043aRdb/Library/LS1043aRdbLib/Common.c @@ -0,0 +1,103 @@ +/** Common.c +* +* Copyright (c) 2016, Freescale Ltd. All rights reserved. +* +* This program and the accompanying materials +* are licensed and made available under the terms and conditions of +the BSD License +* which accompanies this distribution. The full text of the
license
+may be found at +* http://opensource.org/licenses/bsd-license.php +* +* THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" +BASIS, +* WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS
OR IMPLIED.
+* +**/
+#include <Library/PlatformLib.h> +#include <Library/DebugLib.h>
+UINT32 +__Div64_32 (
- IN UINT64 *N,
- IN UINT32 Base
- )
+{
- UINT64 Rem = *N;
- UINT64 b = Base;
- UINT64 Res, d = 1;
- UINT32 High = Rem >> 32;
- /** Reduce the thing a bit first */ Res = 0; if (High >= Base) {
- High /= Base;
- Res = (UINT64) High << 32;
- Rem -= (UINT64) (High*Base) << 32; }
- while ((UINTN)b > 0 && b < Rem) {
- b = b+b;
- d = d+d;
- }
- do {
- if (Rem >= b) {
Rem -= b;
Res += d;
- }
- b >>= 1;
- d >>= 1;
- } while (d);
- *N = Res;
- return Rem;
+}
+/*
- PrINT32 Sizes As "Xxx KiB", "Xxx.Y KiB", "Xxx MiB", "Xxx.Y MiB",
- Xxx GiB, Xxx.Y GiB, Etc As Needed; Allow for Optional Trailing
+String
- (Like "\n")
- */
+VOID +PrintSize (
- IN UINT64 Size,
- IN CONST INT8 *S
- )
+{
- UINT64 M = 0, N;
- UINT64 F;
- static CONST INT8 Names[] = {'E', 'P', 'T', 'G', 'M', 'K'};
- UINT64 D = 10 * ARRAY_SIZE(Names);
- CHAR8 C = 0;
- UINT32 I;
- for (I = 0; I < ARRAY_SIZE(Names); I++, D -= 10) {
- if (Size >> D) {
C = Names[I];
break;
- }
- }
- if (!C) {
- DEBUG((EFI_D_ERROR, "%Ld Bytes,\n %a", Size, S));
- return;
- }
- N = Size >> D;
- F = Size & ((1ULL << D) - 1);
- /* if There'S A Remainder, Deal With It */
Capitalization above makes my forehead wrinkle slightly. Could just say "Deal with any remainder.".
Ok. Will change in V2.
- if (F) {
- M = (10ULL * F + (1ULL << (D - 1))) >> D;
- if (M >= 10) {
M -= 10;
N += 1;
- }
- }
- DEBUG((EFI_D_ERROR, "%Ld", N));
- if (M) {
- DEBUG((EFI_D_ERROR, ".%Ld", M));
- }
- DEBUG((EFI_D_ERROR, " %ciB, %a ", C, S)); }
diff --git a/Platforms/Nxp/LS1043aRdb/Library/LS1043aRdbLib/LS1043aRdb.c b/Platforms/Nxp/LS1043aRdb/Library/LS1043aRdbLib/LS1043aRdb.c new file mode 100644 index 0000000..4fcb8a3 --- /dev/null +++ b/Platforms/Nxp/LS1043aRdb/Library/LS1043aRdbLib/LS1043aRdb.c @@ -0,0 +1,107 @@ +/** LS1043aRdb.c +* +* RDB specific Library for LS1043A SoC, containing functions to +initialize +* RDB boards. +* +* Based on BeagleBoardPkg/Library/BeagleBoardLib/BeagleBoard.c +* +* Copyright (c) 2011-2012, ARM Limited. All rights reserved. +* Copyright (c) 2016, Freescale Semiconductor, Inc. All rights
reserved.
+* +* This program and the accompanying materials +* are licensed and made available under the terms and conditions of +the BSD License +* which accompanies this distribution. The full text of the
license
+may be found at +* http://opensource.org/licenses/bsd-license.php +* +* THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" +BASIS, +* WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS
OR IMPLIED.
+* +**/
+#include <Library/IoLib.h> +#include <Library/ArmPlatformLib.h> +#include <Library/DebugLib.h> +#include <Library/PcdLib.h> +#include <Ppi/ArmMpCoreInfo.h> +#include <Library/PlatformLib.h>
+/**
- Return the current Boot Mode
- This function returns the boot reason on the platform
+**/ +EFI_BOOT_MODE +ArmPlatformGetBootMode (
- VOID
- )
+{
- return BOOT_WITH_FULL_CONFIGURATION; }
+/**
- Placeholder for Platform Initialization **/ RETURN_STATUS
+ArmPlatformInitialize (
- IN UINTN MpId
- )
+{
- return RETURN_SUCCESS;
+}
+ARM_CORE_INFO LS1043aMpCoreInfoCTA53x4[] = {
- {
- // Cluster 0, Core 0
- 0x0, 0x0,
- // MP Core MailBox Set/Get/Clear Addresses and Clear Value
- (EFI_PHYSICAL_ADDRESS)0,
- (EFI_PHYSICAL_ADDRESS)0,
- (EFI_PHYSICAL_ADDRESS)0,
- (UINT64)0xFFFFFFFF
- },
+};
+EFI_STATUS +PrePeiCoreGetMpCoreInfo (
- OUT UINTN *CoreCount,
- OUT ARM_CORE_INFO **ArmCoreTable
- )
+{
- *CoreCount = sizeof(LS1043aMpCoreInfoCTA53x4) /
sizeof(ARM_CORE_INFO);
- *ArmCoreTable = LS1043aMpCoreInfoCTA53x4;
- return EFI_SUCCESS;
+}
+// Needs to be declared in the file. Otherwise gArmMpCoreInfoPpiGuid +is undefined in the contect of PrePeiCore EFI_GUID +mArmMpCoreInfoPpiGuid = ARM_MP_CORE_INFO_PPI_GUID; +ARM_MP_CORE_INFO_PPI mMpCoreInfoPpi = { PrePeiCoreGetMpCoreInfo };
+EFI_PEI_PPI_DESCRIPTOR gPlatformPpiTable[] = {
- {
- EFI_PEI_PPI_DESCRIPTOR_PPI,
- &mArmMpCoreInfoPpiGuid,
- &mMpCoreInfoPpi
- }
+};
+VOID +ArmPlatformGetPlatformPpiList (
- OUT UINTN *PpiListSize,
- OUT EFI_PEI_PPI_DESCRIPTOR **PpiList
- )
+{
- *PpiListSize = sizeof(gPlatformPpiTable);
- *PpiList = gPlatformPpiTable;
+}
+UINTN +ArmPlatformGetCorePosition (
- IN UINTN MpId
- )
+{
- return 1;
+} diff --git a/Platforms/Nxp/LS1043aRdb/Library/LS1043aRdbLib/LS1043aRdbHelper.S b/Platforms/Nxp/LS1043aRdb/Library/LS1043aRdbLib/LS1043aRdbHelper.S new file mode 100644 index 0000000..5d9807f --- /dev/null +++
b/Platforms/Nxp/LS1043aRdb/Library/LS1043aRdbLib/LS1043aRdbHelper.
+++ S @@ -0,0 +1,61 @@ +# @file +# +# Based on
BeagleBoardPkg/Library/BeagleBoardLib/BeagleBoardHelper.S
+# +# Copyright (c) 2012-2013, ARM Limited. All rights reserved. +# Copyright (c) 2016, Freescale Semiconductor, Inc. All rights
reserved.
+# +# This program and the accompanying materials # are licensed and +made available under the terms and conditions of the BSD License # +which accompanies this distribution. The full text of the license +may be found at # http://opensource.org/licenses/bsd-license.php +# +# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" +BASIS, # WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER
EXPRESS OR IMPLIED.
+# +#
+#include <AsmMacroIoLib.h> +#include <AsmMacroIoLibV8.h> +#include <AutoGen.h>
+.text +.align 2
+GCC_ASM_EXPORT(ArmPlatformIsPrimaryCore) +GCC_ASM_EXPORT(ArmPlatformGetPrimaryCoreMpId) +GCC_ASM_EXPORT(ArmPlatformPeiBootAction)
+GCC_ASM_IMPORT(ArmReadMpidr)
+//UINTN +//ArmPlatformIsPrimaryCore ( +// IN UINTN MpId +// ); +ASM_PFX(ArmPlatformIsPrimaryCore):
- and x1, x0, #3
- mov x0, #0
- cbnz x1, 1f
- mov x0, #1
+1:
- ret
+ASM_PFX(ArmPlatformPeiBootAction): +EL1_OR_EL2_OR_EL3(x0) +1: +2:
- ret
+3:
- LoadConstantToReg(FixedPcdGet32(PcdCounterFrequency), x0)
- msr cntfrq_el0, x0
- ret
+//UINTN +//ArmPlatformGetPrimaryCoreMpId ( +// VOID +// ); +ASM_PFX(ArmPlatformGetPrimaryCoreMpId):
- LoadConstantToReg (FixedPcdGet32(PcdArmPrimaryCore), x0)
- ldrh w0, [x0]
- ret
diff --git a/Platforms/Nxp/LS1043aRdb/Library/LS1043aRdbLib/LS1043aRdbLib.inf b/Platforms/Nxp/LS1043aRdb/Library/LS1043aRdbLib/LS1043aRdbLib.inf new file mode 100644 index 0000000..e09d940 --- /dev/null +++
b/Platforms/Nxp/LS1043aRdb/Library/LS1043aRdbLib/LS1043aRdbLib.inf
@@ -0,0 +1,56 @@ +#/* @file +# Copyright (c) 2011-2013, ARM Limited. All rights reserved. +# Copyright (c) 2016, Freescale Semiconductor, Inc. All rights
reserved.
+# +# This program and the accompanying materials # are licensed and +made available under the terms and conditions of the BSD License # +which accompanies this distribution. The full text of the license +may be found at # http://opensource.org/licenses/bsd-license.php +# +# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" +BASIS, # WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER
EXPRESS OR IMPLIED.
+# +#*/
+[Defines]
- INF_VERSION = 0x00010005
- BASE_NAME = LS1043aRdbLib
- FILE_GUID = 736343a0-1d96-11e0-aaaa-
0002a5d5c51b
- MODULE_TYPE = BASE
- VERSION_STRING = 1.0
- LIBRARY_CLASS = ArmPlatformLib
+[Packages]
- MdePkg/MdePkg.dec
- MdeModulePkg/MdeModulePkg.dec
- EmbeddedPkg/EmbeddedPkg.dec
- ArmPkg/ArmPkg.dec
- ArmPlatformPkg/ArmPlatformPkg.dec
- OpenPlatformPkg/Platforms/Nxp/LS1043aRdb/LS1043aRdbPkg.dec
+[LibraryClasses]
- IoLib
- ArmLib
- MemoryAllocationLib
- I2cLib
- DdrLib
- SocLib
+[Sources.common]
- LS1043aRdbHelper.S | GCC
- LS1043aRdb.c
- LS1043aRdbMem.c
- Common.c
+[FeaturePcd]
- gEmbeddedTokenSpaceGuid.PcdCacheEnable
+[FixedPcd]
- gArmTokenSpaceGuid.PcdArmPrimaryCore
- gArmTokenSpaceGuid.PcdFdBaseAddress
- gArmTokenSpaceGuid.PcdFdSize
- gArmTokenSpaceGuid.PcdSystemMemoryBase
- gArmTokenSpaceGuid.PcdSystemMemorySize
- gArmPlatformTokenSpaceGuid.PcdCounterFrequency
As a generic OCD comment on the above - could Packages, LibraryClasses and *Pcd be alphabetically sorted within each section please?
Ok. Will change in V2.
diff --git a/Platforms/Nxp/LS1043aRdb/Library/LS1043aRdbLib/LS1043aRdbMem.c b/Platforms/Nxp/LS1043aRdb/Library/LS1043aRdbLib/LS1043aRdbMem.c new file mode 100644 index 0000000..ef93623 --- /dev/null +++ b/Platforms/Nxp/LS1043aRdb/Library/LS1043aRdbLib/LS1043aRdbMem.c @@ -0,0 +1,149 @@ +/** LS1043aRdbMem.c +* +* RDB memory specific Library for LS1043A SoC. +* +* Based on BeagleBoardPkg/Library/BeagleBoardLib/BeagleBoardMem.c +* +* Copyright (c) 2011, ARM Limited. All rights reserved. +* Copyright (c) 2016, Freescale Semiconductor, Inc. All rights
reserved.
+* +* This program and the accompanying materials +* are licensed and made available under the terms and conditions of +the BSD License +* which accompanies this distribution. The full text of the license +may be found at +* http://opensource.org/licenses/bsd-license.php +* +* THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" +BASIS, +* WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS
OR IMPLIED.
+* +**/
+#include <Library/ArmPlatformLib.h> +#include <Library/DebugLib.h> +#include <Library/PcdLib.h> +#include <Library/MemoryAllocationLib.h> #include <Library/IoLib.h>
+#include <Library/PlatformLib.h>
+#define MAX_VIRTUAL_MEMORY_MAP_DESCRIPTORS 25
Since this value will always be known at compile time (and unlikely to change frequently), could this be a NUM_* instead of MAX_*, and the code then stick with the ASSERT that Index < at the end?
Ok. Will change in V2.
+/**
- Return the Virtual Memory Map of your platform
- This Virtual Memory Map is used by MemoryInitPei Module to
initialize the MMU on your platform.
- @param[out] VirtualMemoryMap Array of
ARM_MEMORY_REGION_DESCRIPTOR describing a Physical-to-
Virtual Memory mapping. This
array must be ended by a zero-filled
entry
+**/ +VOID +ArmPlatformGetVirtualMemoryMap (
- IN ARM_MEMORY_REGION_DESCRIPTOR** VirtualMemoryMap
- )
+{
- ARM_MEMORY_REGION_ATTRIBUTES CacheAttributes;
- UINTN Index = 0;
- ARM_MEMORY_REGION_DESCRIPTOR *VirtualMemoryTable;
- ASSERT(VirtualMemoryMap != NULL);
- VirtualMemoryTable =
- (ARM_MEMORY_REGION_DESCRIPTOR*)AllocatePages(EFI_SIZE_TO_PAGES
- (sizeof(ARM_MEMORY_REGION_DESCRIPTOR) *
- MAX_VIRTUAL_MEMORY_MAP_DESCRIPTORS));
Why cast a VOID * to they type of the pointer it is being assigned to on assignment? This could benefit from a temporary variable to shorten line length.
[Bhupesh] Ok.
- if (VirtualMemoryTable == NULL) {
- return;
- }
- if (FeaturePcdGet(PcdCacheEnable) == TRUE) {
If the cache is not enabled, I don't think the platform port can be specification compliant. I.e., if there is some particular reason for this, the Pcd should possibly be named for that reason.
Ok. Yes we support cache == enabled by default, so will remove this PCD based check and the PCD from the .dsc file.
- CacheAttributes = DDR_ATTRIBUTES_CACHED; } else {
- CacheAttributes = DDR_ATTRIBUTES_UNCACHED; }
- // DRAM1 (Must be 1st entry)
- VirtualMemoryTable[Index].PhysicalBase = LS1043A_DRAM1_BASE_ADDR;
- VirtualMemoryTable[Index].VirtualBase = LS1043A_DRAM1_BASE_ADDR;
- VirtualMemoryTable[Index].Length = LS1043A_DRAM1_SIZE;
- VirtualMemoryTable[Index].Attributes = CacheAttributes;
- // CCSR Space
- VirtualMemoryTable[++Index].PhysicalBase = LS1043A_CCSR_BASE_ADDR;
- VirtualMemoryTable[Index].VirtualBase = LS1043A_CCSR_BASE_ADDR;
- VirtualMemoryTable[Index].Length = LS1043A_CCSR_SIZE;
- VirtualMemoryTable[Index].Attributes =
ARM_MEMORY_REGION_ATTRIBUTE_DEVICE;
- // OCRAM1 Space
- VirtualMemoryTable[++Index].PhysicalBase =
- LS1043A_OCRAM1_BASE_ADDR; VirtualMemoryTable[Index].VirtualBase =
LS1043A_OCRAM1_BASE_ADDR;
- VirtualMemoryTable[Index].Length = LS1043A_OCRAM1_SIZE;
- VirtualMemoryTable[Index].Attributes = CacheAttributes;
- // OCRAM2 Space
- VirtualMemoryTable[++Index].PhysicalBase =
- LS1043A_OCRAM2_BASE_ADDR; VirtualMemoryTable[Index].VirtualBase =
LS1043A_OCRAM2_BASE_ADDR;
- VirtualMemoryTable[Index].Length = LS1043A_OCRAM2_SIZE;
- VirtualMemoryTable[Index].Attributes = CacheAttributes;
- // IFC region 1
- VirtualMemoryTable[++Index].PhysicalBase =
- LS1043A_IFC_REGION1_BASE_ADDR;
VirtualMemoryTable[Index].VirtualBase = LS1043A_IFC_REGION1_BASE_ADDR;
- VirtualMemoryTable[Index].Length =
LS1043A_IFC_REGION1_BASE_SIZE;
- VirtualMemoryTable[Index].Attributes =
ARM_MEMORY_REGION_ATTRIBUTE_UNCACHED_UNBUFFERED;
- // QMAN SWP
- VirtualMemoryTable[++Index].PhysicalBase =
- LS1043A_QMAN_SWP_BASE_ADDR; VirtualMemoryTable[Index].VirtualBase
= LS1043A_QMAN_SWP_BASE_ADDR;
- VirtualMemoryTable[Index].Length = LS1043A_QMAN_SWP_SIZE;
- VirtualMemoryTable[Index].Attributes =
ARM_MEMORY_REGION_ATTRIBUTE_UNCACHED_UNBUFFERED;
- // BMAN SWP
- VirtualMemoryTable[++Index].PhysicalBase =
- LS1043A_BMAN_SWP_BASE_ADDR; VirtualMemoryTable[Index].VirtualBase
= LS1043A_BMAN_SWP_BASE_ADDR;
- VirtualMemoryTable[Index].Length = LS1043A_BMAN_SWP_SIZE;
- VirtualMemoryTable[Index].Attributes =
ARM_MEMORY_REGION_ATTRIBUTE_UNCACHED_UNBUFFERED;
- // IFC region 2
- VirtualMemoryTable[++Index].PhysicalBase =
- LS1043A_IFC_REGION2_BASE_ADDR;
VirtualMemoryTable[Index].VirtualBase = LS1043A_IFC_REGION2_BASE_ADDR;
- VirtualMemoryTable[Index].Length =
LS1043A_IFC_REGION2_BASE_SIZE;
- VirtualMemoryTable[Index].Attributes = CacheAttributes;
- // DRAM2
- VirtualMemoryTable[++Index].PhysicalBase =
LS1043A_DRAM2_BASE_ADDR;
- VirtualMemoryTable[Index].VirtualBase = LS1043A_DRAM2_BASE_ADDR;
- VirtualMemoryTable[Index].Length = LS1043A_DRAM2_SIZE;
- VirtualMemoryTable[Index].Attributes = CacheAttributes;
- // PCIe1
- VirtualMemoryTable[++Index].PhysicalBase =
- LS1043A_PCI_EXP1_BASE_ADDR; VirtualMemoryTable[Index].VirtualBase
= LS1043A_PCI_EXP1_BASE_ADDR;
- VirtualMemoryTable[Index].Length =
LS1043A_PCI_EXP1_BASE_SIZE;
- VirtualMemoryTable[Index].Attributes =
ARM_MEMORY_REGION_ATTRIBUTE_DEVICE;
- // PCIe2
- VirtualMemoryTable[++Index].PhysicalBase =
- LS1043A_PCI_EXP2_BASE_ADDR; VirtualMemoryTable[Index].VirtualBase
= LS1043A_PCI_EXP2_BASE_ADDR;
- VirtualMemoryTable[Index].Length =
LS1043A_PCI_EXP2_BASE_SIZE;
- VirtualMemoryTable[Index].Attributes =
ARM_MEMORY_REGION_ATTRIBUTE_DEVICE;
- // PCIe3
- VirtualMemoryTable[++Index].PhysicalBase =
- LS1043A_PCI_EXP3_BASE_ADDR; VirtualMemoryTable[Index].VirtualBase
= LS1043A_PCI_EXP3_BASE_ADDR;
- VirtualMemoryTable[Index].Length =
LS1043A_PCI_EXP3_BASE_SIZE;
- VirtualMemoryTable[Index].Attributes =
ARM_MEMORY_REGION_ATTRIBUTE_DEVICE;
- // DRAM3
- VirtualMemoryTable[++Index].PhysicalBase =
LS1043A_DRAM3_BASE_ADDR;
- VirtualMemoryTable[Index].VirtualBase = LS1043A_DRAM3_BASE_ADDR;
- VirtualMemoryTable[Index].Length = LS1043A_DRAM3_SIZE;
- VirtualMemoryTable[Index].Attributes = CacheAttributes;
- // End of Table
- VirtualMemoryTable[++Index].PhysicalBase = 0;
- VirtualMemoryTable[Index].VirtualBase = 0;
- VirtualMemoryTable[Index].Length = 0;
- VirtualMemoryTable[Index].Attributes =
(ARM_MEMORY_REGION_ATTRIBUTES)0;
(Dou you even need to set the Attributes at this point? If so, maybe we should just create a REGION_ATTRIBUTE_INVALID?)
REGION_ATTRIBUTE_INVALID seems better. I will change this in V2.
- ASSERT((Index + 1) <= MAX_VIRTUAL_MEMORY_MAP_DESCRIPTORS);
- *VirtualMemoryMap = VirtualMemoryTable; }
-- 1.9.1
Regards, Bhupesh
From: Sakar Arora sakar.arora@nxp.com
NXP/FSL's LS1043A RDB board houses 2 GB DDR4 SDRAM.
There is a DDR controller IP which controls access to this SDRAM.
This patch adds a library which allows required initialization of this controller. This library executes out of the XIP NOR flash mememory.
Signed-off-by: Meenakshi Aggarwal meenakshi.aggarwal@nxp.com Signed-off-by: Bhupesh Sharma bhupesh.sharma@nxp.com --- Platforms/Nxp/LS1043aRdb/Include/Library/Ddr.h | 190 +++++++++++++++++++++ Platforms/Nxp/LS1043aRdb/Library/DdrLib/DdrLib.c | 188 ++++++++++++++++++++ Platforms/Nxp/LS1043aRdb/Library/DdrLib/DdrLib.inf | 41 +++++ 3 files changed, 419 insertions(+) create mode 100644 Platforms/Nxp/LS1043aRdb/Include/Library/Ddr.h create mode 100644 Platforms/Nxp/LS1043aRdb/Library/DdrLib/DdrLib.c create mode 100644 Platforms/Nxp/LS1043aRdb/Library/DdrLib/DdrLib.inf
diff --git a/Platforms/Nxp/LS1043aRdb/Include/Library/Ddr.h b/Platforms/Nxp/LS1043aRdb/Include/Library/Ddr.h new file mode 100644 index 0000000..0d715fb --- /dev/null +++ b/Platforms/Nxp/LS1043aRdb/Include/Library/Ddr.h @@ -0,0 +1,190 @@ +/** @Ddr.h + Header defining the Ddr controller constants (Base addresses, sizes, flags), + function prototype, structures etc + + Copyright (c) 2016, Freescale Semiconductor, Inc. All rights reserved. + + This program and the accompanying materials + are licensed and made available under the terms and conditions of the BSD License + which accompanies this distribution. The full text of the license may be found at + http://opensource.org/licenses/bsd-license.php + + THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, + WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. + +**/ + +#ifndef __DDR_H__ +#define __DDR_H__ + +#include <Library/DebugLib.h> +#include <Library/IoLib.h> +#include <Library/PlatformLib.h> + +/* DDR4 fixed timing */ +#define LS1043A_CS0_BNDS 0x0000007f /* 0x000 */ +#define LS1043A_CS0_CONFIG 0x80010322 /* 0x080 */ +#define LS1043A_TIMING_CFG_3 0x020C1000 /* 0x100 */ +#define LS1043A_TIMING_CFG_0 0xD0550018 /* 0x104 */ +#define LS1043A_TIMING_CFG_1 0xC2C68C42 /* 0x108 */ +#define LS1043A_TIMING_CFG_2 0x0048C114 /* 0x10c */ +#define LS1043A_DDR_SDRAM_CFG 0x450C000C /* 0x110 */ +#define LS1043A_DDR_SDRAM_CFG_2 0x00401010 /* 0x114 */ +#define LS1043A_DDR_SDRAM_MODE 0x01010214 /* 0x118 */ +#define LS1043A_DDR_SDRAM_INTERVAL 0x18600618 /* 0x124 */ +#define LS1043A_DDR_SDRAM_CLK_CNTL 0x02000000 /* 0x130 */ +#define LS1043A_TIMING_CFG_4 0x00000002 /* 0x160 */ +#define LS1043A_TIMING_CFG_5 0x04401400 /* 0x164 */ +#define LS1043A_TIMING_CFG_7 0x13300000 /* 0x16c */ +#define LS1043A_DDR_ZQ_CNTL 0x8A090705 /* 0x170 */ +#define LS1043A_DDR_WRLVL_CNTL 0x8655F606 /* 0x174 */ +#define LS1043A_DDR_WRLVL_CNTL_2 0x05070600 /* 0x190 */ +#define LS1043A_DDR_SDRAM_MODE_9 0x00000400 /* 0x220 */ +#define LS1043A_DDR_SDRAM_MODE_10 0x04000000 /* 0x224 */ +#define LS1043A_TIMING_CFG_8 0x03115600 /* 0x250 */ +#define LS1043A_DDRCDR_1 0x80040000 /* 0xb28 */ +#define LS1043A_DDRCDR_2 0x0000A181 /* 0xb2c */ + +#define LS1043A_DDR_SDRAM_CFG_MEM_EN 0x80000000 + +/** + DDR memory controller registers +**/ +struct CcsrDdr { + UINT32 Cs0Bnds; /** Chip Select 0 Memory Bounds */ + CHAR8 Res04[4]; + UINT32 Cs1Bnds; /** Chip Select 1 Memory Bounds */ + CHAR8 Res0c[4]; + UINT32 Cs2Bnds; /** Chip Select 2 Memory Bounds */ + CHAR8 Res14[4]; + UINT32 Cs3Bnds; /** Chip Select 3 Memory Bounds */ + CHAR8 Res1c[100]; + UINT32 Cs0Config; /** Chip Select Configuration */ + UINT32 Cs1Config; /** Chip Select Configuration */ + UINT32 Cs2Config; /** Chip Select Configuration */ + UINT32 Cs3Config; /** Chip Select Configuration */ + CHAR8 Res90[48]; + UINT32 Cs0Config2; /** Chip Select Configuration 2 */ + UINT32 Cs1Config2; /** Chip Select Configuration 2 */ + UINT32 Cs2Config2; /** Chip Select Configuration 2 */ + UINT32 Cs3Config2; /** Chip Select Configuration 2 */ + CHAR8 Resd0[48]; + UINT32 TimingCfg3; /** SDRAM Timing Configuration 3 */ + UINT32 TimingCfg0; /** SDRAM Timing Configuration 0 */ + UINT32 TimingCfg1; /** SDRAM Timing Configuration 1 */ + UINT32 TimingCfg2; /** SDRAM Timing Configuration 2 */ + UINT32 SdramCfg; /** SDRAM Control Configuration */ + UINT32 SdramCfg2; /** SDRAM Control Configuration 2 */ + UINT32 SdramMode; /** SDRAM Mode Configuration */ + UINT32 SdramMode2; /** SDRAM Mode Configuration 2 */ + UINT32 SdramMdCntl; /** SDRAM Mode Control */ + UINT32 SdramInterval; /** SDRAM Interval Configuration */ + UINT32 SdramDataInit; /** SDRAM Data initialization */ + CHAR8 Res12c[4]; + UINT32 SdramClkCntl; /** SDRAM Clock Control */ + CHAR8 Res134[20]; + UINT32 InitAddr; /** training init addr */ + UINT32 InitExtAddr; /** training init extended addr */ + CHAR8 Res150[16]; + UINT32 TimingCfg4; /** SDRAM Timing Configuration 4 */ + UINT32 TimingCfg5; /** SDRAM Timing Configuration 5 */ + UINT32 TimingCfg6; /** SDRAM Timing Configuration 6 */ + UINT32 TimingCfg7; /** SDRAM Timing Configuration 7 */ + UINT32 DdrZqCntl; /** ZQ calibration control*/ + UINT32 DdrWrlvlCntl; /** write leveling control*/ + CHAR8 Reg178[4]; + UINT32 DdrSrCntr; /** self refresh counter */ + UINT32 DdrSdramRcw1; /** Control Words 1 */ + UINT32 DdrSdramRcw2; /** Control Words 2 */ + CHAR8 Reg188[8]; + UINT32 DdrWrlvlCntl2; /** write leveling control 2 */ + UINT32 DdrWrlvlCntl3; /** write leveling control 3 */ + CHAR8 Res198[8]; + UINT32 DdrSdramRcw3; + UINT32 DdrSdramRcw4; + UINT32 DdrSdramRcw5; + UINT32 DdrSdramRcw6; + CHAR8 Res1b0[80]; + UINT32 SdramMode3; /** SDRAM Mode Configuration 3 */ + UINT32 SdramMode4; /** SDRAM Mode Configuration 4 */ + UINT32 SdramMode5; /** SDRAM Mode Configuration 5 */ + UINT32 SdramMode6; /** SDRAM Mode Configuration 6 */ + UINT32 SdramMode7; /** SDRAM Mode Configuration 7 */ + UINT32 SdramMode8; /** SDRAM Mode Configuration 8 */ + CHAR8 Res218[8]; + UINT32 SdramMode9; /** SDRAM Mode Configuration 9 */ + UINT32 SdramMode10; /** SDRAM Mode Configuration 10 */ + UINT32 SdramMode11; /** SDRAM Mode Configuration 11 */ + UINT32 SdramMode12; /** SDRAM Mode Configuration 12 */ + UINT32 SdramMode13; /** SDRAM Mode Configuration 13 */ + UINT32 SdramMode14; /** SDRAM Mode Configuration 14 */ + UINT32 SdramMode15; /** SDRAM Mode Configuration 15 */ + UINT32 SdramMode16; /** SDRAM Mode Configuration 16 */ + CHAR8 Res240[16]; + UINT32 TimingCfg8; /* SDRAM Timing Configuration 8 */ + CHAR8 Res254[12]; + UINT32 SdramCfg3; + CHAR8 Res264[412]; + UINT32 DqMap0; + UINT32 DqMap1; + UINT32 DqMap2; + UINT32 DqMap3; + CHAR8 Res410[1808]; + UINT32 DdrDsr1; /** Debug Status 1 */ + UINT32 DdrDsr2; /** Debug Status 2 */ + UINT32 DdrCdr1; /** Control Driver 1 */ + UINT32 DdrCdr2; /** Control Driver 2 */ + CHAR8 ResB30[200]; + UINT32 IpRev1; /** IP Block Revision 1 */ + UINT32 IpRev2; /** IP Block Revision 2 */ + UINT32 Eor; /** Enhanced Optimization Register */ + CHAR8 ResC04[252]; + UINT32 Mtcr; /** Memory Test Control Register */ + CHAR8 ResD04[28]; + UINT32 Mtp1; /** Memory Test Pattern 1 */ + UINT32 Mtp2; /** Memory Test Pattern 2 */ + UINT32 Mtp3; /** Memory Test Pattern 3 */ + UINT32 Mtp4; /** Memory Test Pattern 4 */ + UINT32 Mtp5; /** Memory Test Pattern 5 */ + UINT32 Mtp6; /** Memory Test Pattern 6 */ + UINT32 Mtp7; /** Memory Test Pattern 7 */ + UINT32 Mtp8; /** Memory Test Pattern 8 */ + UINT32 Mtp9; /** Memory Test Pattern 9 */ + UINT32 Mtp10; /** Memory Test Pattern 10 */ + CHAR8 ResD48[184]; + UINT32 DataErrInjectHi; /** Data Path Err Injection Mask High */ + UINT32 DataErrInjectLo; /** Data Path Err Injection Mask Low */ + UINT32 EccErrInject; /** Data Path Err Injection Mask ECC */ + CHAR8 ResE0c[20]; + UINT32 CaptureDataHi; /** Data Path Read Capture High */ + UINT32 CaptureDataLo; /** Data Path Read Capture Low */ + UINT32 CaptureEcc; /** Data Path Read Capture ECC */ + CHAR8 ResE2c[20]; + UINT32 ErrDetect; /** Error Detect */ + UINT32 ErrDisable; /** Error Disable */ + UINT32 ErrIntEn; + UINT32 CaptureAttributes; /** Error Attrs Capture */ + UINT32 CaptureAddress; /** Error Addr Capture */ + UINT32 CaptureExtAddress; /** Error Extended Addr Capture */ + UINT32 ErrSbe; /** Single-Bit ECC Error Management */ + CHAR8 ResE5c[164]; + UINT32 Debug[32]; /** Debug_1 to Debug_32 */ + CHAR8 ResF80[128]; +}; + +/** + Main function to initialize DDR + **/ +VOID +DramInit( + ); + +/** + Function to dump DDRC registers + +**/ +VOID +DdrRegDump ( + VOID + ); +#endif diff --git a/Platforms/Nxp/LS1043aRdb/Library/DdrLib/DdrLib.c b/Platforms/Nxp/LS1043aRdb/Library/DdrLib/DdrLib.c new file mode 100644 index 0000000..1c33de4 --- /dev/null +++ b/Platforms/Nxp/LS1043aRdb/Library/DdrLib/DdrLib.c @@ -0,0 +1,188 @@ +/** @DdrLib.c + Ddr Library containing functions to initialize ddr controller + + Copyright (c) 2016, Freescale Semiconductor, Inc. All rights reserved. + + This program and the accompanying materials + are licensed and made available under the terms and conditions of the BSD License + which accompanies this distribution. The full text of the license may be found at + http://opensource.org/licenses/bsd-license.php + + THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, + WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. + +**/ + +#include <Library/Ddr.h> +#include <Library/BaseLib.h> + +#define Uswap32(X) \ + ((((X) & 0xff000000) >> 24) | \ + (((X) & 0x00ff0000) >> 8) | \ + (((X) & 0x0000ff00) << 8) | \ + (((X) & 0x000000ff) << 24)) +#define DDRMC_DELAY 10000 + +/** + Function to dump DDRC registers + +**/ + +VOID +DdrRegDump ( + VOID + ) +{ + + struct CcsrDdr *Ddr = (VOID *)LS1043A_DDR_ADDR; + + DEBUG((EFI_D_INFO, "Cs0Bnds = 0x%x\n",MmioReadBe32((UINTN)&Ddr->Cs0Bnds))); + DEBUG((EFI_D_INFO, "Cs1Bnds = 0x%x\n",MmioReadBe32((UINTN)&Ddr->Cs1Bnds))); + DEBUG((EFI_D_INFO, "Cs2Bnds = 0x%x\n",MmioReadBe32((UINTN)&Ddr->Cs2Bnds))); + DEBUG((EFI_D_INFO, "Cs3Bnds = 0x%x\n",MmioReadBe32((UINTN)&Ddr->Cs3Bnds))); + DEBUG((EFI_D_INFO, "Cs0Config = 0x%x\n",MmioReadBe32((UINTN)&Ddr->Cs0Config))); + DEBUG((EFI_D_INFO, "Cs1Config = 0x%x\n",MmioReadBe32((UINTN)&Ddr->Cs1Config))); + DEBUG((EFI_D_INFO, "Cs2Config = 0x%x\n",MmioReadBe32((UINTN)&Ddr->Cs2Config))); + DEBUG((EFI_D_INFO, "Cs3Config = 0x%x\n",MmioReadBe32((UINTN)&Ddr->Cs3Config))); + DEBUG((EFI_D_INFO, "Cs0Config2 = 0x%x\n",MmioReadBe32((UINTN)&Ddr->Cs0Config2))); + DEBUG((EFI_D_INFO, "Cs1Config2 = 0x%x\n",MmioReadBe32((UINTN)&Ddr->Cs1Config2))); + DEBUG((EFI_D_INFO, "Cs2Config2 = 0x%x\n",MmioReadBe32((UINTN)&Ddr->Cs2Config2))); + DEBUG((EFI_D_INFO, "Cs3Config2 = 0x%x\n",MmioReadBe32((UINTN)&Ddr->Cs3Config2))); + DEBUG((EFI_D_INFO, "TimingCfg3 = 0x%x\n",MmioReadBe32((UINTN)&Ddr->TimingCfg3))); + DEBUG((EFI_D_INFO, "TimingCfg0 = 0x%x\n",MmioReadBe32((UINTN)&Ddr->TimingCfg0))); + DEBUG((EFI_D_INFO, "TimingCfg1 = 0x%x\n",MmioReadBe32((UINTN)&Ddr->TimingCfg1))); + DEBUG((EFI_D_INFO, "TimingCfg2 = 0x%x\n",MmioReadBe32((UINTN)&Ddr->TimingCfg2))); + DEBUG((EFI_D_INFO, "SdramCfg = 0x%x\n",MmioReadBe32((UINTN)&Ddr->SdramCfg))); + DEBUG((EFI_D_INFO, "SdramCfg2 = 0x%x\n",MmioReadBe32((UINTN)&Ddr->SdramCfg2))); + DEBUG((EFI_D_INFO, "SdramMode = 0x%x\n",MmioReadBe32((UINTN)&Ddr->SdramMode))); + DEBUG((EFI_D_INFO, "SdramMode2 = 0x%x\n",MmioReadBe32((UINTN)&Ddr->SdramMode2))); + DEBUG((EFI_D_INFO, "SdramMdCntl = 0x%x\n",MmioReadBe32((UINTN)&Ddr->SdramMdCntl))); + DEBUG((EFI_D_INFO, "SdramInterval = 0x%x\n",MmioReadBe32((UINTN)&Ddr->SdramInterval))); + DEBUG((EFI_D_INFO, "SdramDataInit = 0x%x\n",MmioReadBe32((UINTN)&Ddr->SdramDataInit))); + DEBUG((EFI_D_INFO, "SdramClkCntl = 0x%x\n",MmioReadBe32((UINTN)&Ddr->SdramClkCntl))); + DEBUG((EFI_D_INFO, "InitAddr = 0x%x\n",MmioReadBe32((UINTN)&Ddr->InitAddr))); + DEBUG((EFI_D_INFO, "InitExtAddr = 0x%x\n",MmioReadBe32((UINTN)&Ddr->InitExtAddr))); + DEBUG((EFI_D_INFO, "TimingCfg4 = 0x%x\n",MmioReadBe32((UINTN)&Ddr->TimingCfg4))); + DEBUG((EFI_D_INFO, "TimingCfg5 = 0x%x\n",MmioReadBe32((UINTN)&Ddr->TimingCfg5))); + DEBUG((EFI_D_INFO, "TimingCfg6 = 0x%x\n",MmioReadBe32((UINTN)&Ddr->TimingCfg6))); + DEBUG((EFI_D_INFO, "TimingCfg7 = 0x%x\n",MmioReadBe32((UINTN)&Ddr->TimingCfg7))); + DEBUG((EFI_D_INFO, "DdrZqCntl = 0x%x\n",MmioReadBe32((UINTN)&Ddr->DdrZqCntl))); + DEBUG((EFI_D_INFO, "DdrWrlvlCntl = 0x%x\n",MmioReadBe32((UINTN)&Ddr->DdrWrlvlCntl))); + DEBUG((EFI_D_INFO, "DdrSrCntr = 0x%x\n",MmioReadBe32((UINTN)&Ddr->DdrSrCntr))); + DEBUG((EFI_D_INFO, "DdrSdramRcw1 = 0x%x\n",MmioReadBe32((UINTN)&Ddr->DdrSdramRcw1))); + DEBUG((EFI_D_INFO, "DdrSdramRcw2 = 0x%x\n",MmioReadBe32((UINTN)&Ddr->DdrSdramRcw2))); + DEBUG((EFI_D_INFO, "DdrWrlvlCntl2 = 0x%x\n",MmioReadBe32((UINTN)&Ddr->DdrWrlvlCntl2))); + DEBUG((EFI_D_INFO, "DdrWrlvlCntl3 = 0x%x\n",MmioReadBe32((UINTN)&Ddr->DdrWrlvlCntl3))); + DEBUG((EFI_D_INFO, "DdrSdramRcw3 = 0x%x\n",MmioReadBe32((UINTN)&Ddr->DdrSdramRcw3))); + DEBUG((EFI_D_INFO, "DdrSdramRcw4 = 0x%x\n",MmioReadBe32((UINTN)&Ddr->DdrSdramRcw4))); + DEBUG((EFI_D_INFO, "DdrSdramRcw5 = 0x%x\n",MmioReadBe32((UINTN)&Ddr->DdrSdramRcw5))); + DEBUG((EFI_D_INFO, "DdrSdramRcw6 = 0x%x\n",MmioReadBe32((UINTN)&Ddr->DdrSdramRcw6))); + DEBUG((EFI_D_INFO, "SdramMode3 = 0x%x\n",MmioReadBe32((UINTN)&Ddr->SdramMode3))); + DEBUG((EFI_D_INFO, "SdramMode4 = 0x%x\n",MmioReadBe32((UINTN)&Ddr->SdramMode4))); + DEBUG((EFI_D_INFO, "SdramMode5 = 0x%x\n",MmioReadBe32((UINTN)&Ddr->SdramMode5))); + DEBUG((EFI_D_INFO, "SdramMode6 = 0x%x\n",MmioReadBe32((UINTN)&Ddr->SdramMode6))); + DEBUG((EFI_D_INFO, "SdramMode7 = 0x%x\n",MmioReadBe32((UINTN)&Ddr->SdramMode7))); + DEBUG((EFI_D_INFO, "SdramMode8 = 0x%x\n",MmioReadBe32((UINTN)&Ddr->SdramMode8))); + DEBUG((EFI_D_INFO, "SdramMode9 = 0x%x\n",MmioReadBe32((UINTN)&Ddr->SdramMode9))); + DEBUG((EFI_D_INFO, "SdramMode10 = 0x%x\n",MmioReadBe32((UINTN)&Ddr->SdramMode10))); + DEBUG((EFI_D_INFO, "SdramMode11 = 0x%x\n",MmioReadBe32((UINTN)&Ddr->SdramMode11))); + DEBUG((EFI_D_INFO, "SdramMode12 = 0x%x\n",MmioReadBe32((UINTN)&Ddr->SdramMode12))); + DEBUG((EFI_D_INFO, "SdramMode13 = 0x%x\n",MmioReadBe32((UINTN)&Ddr->SdramMode13))); + DEBUG((EFI_D_INFO, "SdramMode14 = 0x%x\n",MmioReadBe32((UINTN)&Ddr->SdramMode14))); + DEBUG((EFI_D_INFO, "SdramMode15 = 0x%x\n",MmioReadBe32((UINTN)&Ddr->SdramMode15))); + DEBUG((EFI_D_INFO, "SdramMode16 = 0x%x\n",MmioReadBe32((UINTN)&Ddr->SdramMode16))); + DEBUG((EFI_D_INFO, "TimingCfg8 = 0x%x\n",MmioReadBe32((UINTN)&Ddr->TimingCfg8))); + DEBUG((EFI_D_INFO, "SdramCfg3 = 0x%x\n",MmioReadBe32((UINTN)&Ddr->SdramCfg3))); + DEBUG((EFI_D_INFO, "DqMap0 = 0x%x\n",MmioReadBe32((UINTN)&Ddr->DqMap0))); + DEBUG((EFI_D_INFO, "DqMap1 = 0x%x\n",MmioReadBe32((UINTN)&Ddr->DqMap1))); + DEBUG((EFI_D_INFO, "DqMap2 = 0x%x\n",MmioReadBe32((UINTN)&Ddr->DqMap2))); + DEBUG((EFI_D_INFO, "DqMap3 = 0x%x\n",MmioReadBe32((UINTN)&Ddr->DqMap3))); + DEBUG((EFI_D_INFO, "DdrDsr1 = 0x%x\n",MmioReadBe32((UINTN)&Ddr->DdrDsr1))); + DEBUG((EFI_D_INFO, "DdrDsr2 = 0x%x\n",MmioReadBe32((UINTN)&Ddr->DdrDsr2))); + DEBUG((EFI_D_INFO, "DdrCdr1 = 0x%x\n",MmioReadBe32((UINTN)&Ddr->DdrCdr1))); + DEBUG((EFI_D_INFO, "DdrCdr2 = 0x%x\n",MmioReadBe32((UINTN)&Ddr->DdrCdr2))); + DEBUG((EFI_D_INFO, "IpRev1 = 0x%x\n",MmioReadBe32((UINTN)&Ddr->IpRev1))); + DEBUG((EFI_D_INFO, "IpRev2 = 0x%x\n",MmioReadBe32((UINTN)&Ddr->IpRev2))); + DEBUG((EFI_D_INFO, "Eor = 0x%x\n",MmioReadBe32((UINTN)&Ddr->Eor))); + DEBUG((EFI_D_INFO, "Mtcr = 0x%x\n",MmioReadBe32((UINTN)&Ddr->Mtcr))); + DEBUG((EFI_D_INFO, "Mtp1 = 0x%x\n",MmioReadBe32((UINTN)&Ddr->Mtp1))); + DEBUG((EFI_D_INFO, "Mtp2 = 0x%x\n",MmioReadBe32((UINTN)&Ddr->Mtp2))); + DEBUG((EFI_D_INFO, "Mtp3 = 0x%x\n",MmioReadBe32((UINTN)&Ddr->Mtp3))); + DEBUG((EFI_D_INFO, "Mtp4 = 0x%x\n",MmioReadBe32((UINTN)&Ddr->Mtp4))); + DEBUG((EFI_D_INFO, "Mtp5 = 0x%x\n",MmioReadBe32((UINTN)&Ddr->Mtp5))); + DEBUG((EFI_D_INFO, "Mtp6 = 0x%x\n",MmioReadBe32((UINTN)&Ddr->Mtp6))); + DEBUG((EFI_D_INFO, "Mtp7 = 0x%x\n",MmioReadBe32((UINTN)&Ddr->Mtp7))); + DEBUG((EFI_D_INFO, "Mtp8 = 0x%x\n",MmioReadBe32((UINTN)&Ddr->Mtp8))); + DEBUG((EFI_D_INFO, "Mtp9 = 0x%x\n",MmioReadBe32((UINTN)&Ddr->Mtp9))); + DEBUG((EFI_D_INFO, "Mtp10 = 0x%x\n",MmioReadBe32((UINTN)&Ddr->Mtp10))); + DEBUG((EFI_D_INFO, "DataErrInjectHi = 0x%x\n",MmioReadBe32((UINTN)&Ddr->DataErrInjectHi))); + DEBUG((EFI_D_INFO, "DataErrInjectLo = 0x%x\n",MmioReadBe32((UINTN)&Ddr->DataErrInjectLo))); + DEBUG((EFI_D_INFO, "EccErrInject = 0x%x\n",MmioReadBe32((UINTN)&Ddr->EccErrInject))); + DEBUG((EFI_D_INFO, "CaptureDataHi = 0x%x\n",MmioReadBe32((UINTN)&Ddr->CaptureDataHi))); + DEBUG((EFI_D_INFO, "CaptureDataLo = 0x%x\n",MmioReadBe32((UINTN)&Ddr->CaptureDataLo))); + DEBUG((EFI_D_INFO, "CaptureEcc = 0x%x\n",MmioReadBe32((UINTN)&Ddr->CaptureEcc))); + DEBUG((EFI_D_INFO, "ErrDetect = 0x%x\n",MmioReadBe32((UINTN)&Ddr->ErrDetect))); + DEBUG((EFI_D_INFO, "ErrDisable = 0x%x\n",MmioReadBe32((UINTN)&Ddr->ErrDisable))); + DEBUG((EFI_D_INFO, "ErrIntEn = 0x%x\n",MmioReadBe32((UINTN)&Ddr->ErrIntEn))); + DEBUG((EFI_D_INFO, "CaptureAttributes = 0x%x\n",MmioReadBe32((UINTN)&Ddr->CaptureAttributes))); + DEBUG((EFI_D_INFO, "CaptureAddress = 0x%x\n",MmioReadBe32((UINTN)&Ddr->CaptureAddress))); + DEBUG((EFI_D_INFO, "CaptureExtAddress = 0x%x\n",MmioReadBe32((UINTN)&Ddr->CaptureExtAddress))); + DEBUG((EFI_D_INFO, "ErrSbe = 0x%x\n",MmioReadBe32((UINTN)&Ddr->ErrSbe))); + DEBUG((EFI_D_ERROR,"\n")); +} + +/** + Function to initialize DDR + **/ +VOID +DramInit ( + ) +{ + struct CcsrDdr *Ddr; + UINT32 Count, Delay = DDRMC_DELAY; + Ddr = (VOID *)LS1043A_DDR_ADDR; + + MmioWriteBe32((UINTN)&Ddr->SdramCfg, LS1043A_DDR_SDRAM_CFG); + + MmioWriteBe32((UINTN)&Ddr->Cs0Bnds, LS1043A_CS0_BNDS); + MmioWriteBe32((UINTN)&Ddr->Cs0Config, LS1043A_CS0_CONFIG); + + MmioWriteBe32((UINTN)&Ddr->TimingCfg0, LS1043A_TIMING_CFG_0); + MmioWriteBe32((UINTN)&Ddr->TimingCfg1, LS1043A_TIMING_CFG_1); + MmioWriteBe32((UINTN)&Ddr->TimingCfg2, LS1043A_TIMING_CFG_2); + MmioWriteBe32((UINTN)&Ddr->TimingCfg3, LS1043A_TIMING_CFG_3); + MmioWriteBe32((UINTN)&Ddr->TimingCfg4, LS1043A_TIMING_CFG_4); + MmioWriteBe32((UINTN)&Ddr->TimingCfg5, LS1043A_TIMING_CFG_5); + MmioWriteBe32((UINTN)&Ddr->TimingCfg7, LS1043A_TIMING_CFG_7); + MmioWriteBe32((UINTN)&Ddr->TimingCfg8, LS1043A_TIMING_CFG_8); + + MmioWriteBe32((UINTN)&Ddr->SdramCfg2, LS1043A_DDR_SDRAM_CFG_2); + + MmioWriteBe32((UINTN)&Ddr->SdramMode, LS1043A_DDR_SDRAM_MODE); + MmioWriteBe32((UINTN)&Ddr->SdramMode2, 0); + MmioWriteBe32((UINTN)&Ddr->SdramInterval, LS1043A_DDR_SDRAM_INTERVAL); + + MmioWriteBe32((UINTN)&Ddr->DdrWrlvlCntl, LS1043A_DDR_WRLVL_CNTL); + MmioWriteBe32((UINTN)&Ddr->DdrWrlvlCntl2, LS1043A_DDR_WRLVL_CNTL_2); + MmioWriteBe32((UINTN)&Ddr->DdrWrlvlCntl3, 0); + + MmioWriteBe32((UINTN)&Ddr->DdrCdr1, LS1043A_DDRCDR_1); + MmioWriteBe32((UINTN)&Ddr->DdrCdr2, LS1043A_DDRCDR_2); + + MmioWriteBe32((UINTN)&Ddr->SdramClkCntl, LS1043A_DDR_SDRAM_CLK_CNTL); + + MmioWriteBe32((UINTN)&Ddr->DdrZqCntl, LS1043A_DDR_ZQ_CNTL); + + MmioWriteBe32((UINTN)&Ddr->SdramMode9, LS1043A_DDR_SDRAM_MODE_9); + MmioWriteBe32((UINTN)&Ddr->SdramMode10, LS1043A_DDR_SDRAM_MODE_10); + + MmioWriteBe32((UINTN)&Ddr->Cs0Config2, 0); + + for(Count = 0; Count < Delay; Count++) + ; + + MmioWriteBe32((UINTN)&Ddr->SdramCfg, LS1043A_DDR_SDRAM_CFG + | LS1043A_DDR_SDRAM_CFG_MEM_EN); + + return; +} diff --git a/Platforms/Nxp/LS1043aRdb/Library/DdrLib/DdrLib.inf b/Platforms/Nxp/LS1043aRdb/Library/DdrLib/DdrLib.inf new file mode 100644 index 0000000..e8e3aed --- /dev/null +++ b/Platforms/Nxp/LS1043aRdb/Library/DdrLib/DdrLib.inf @@ -0,0 +1,41 @@ +#/** DdrLib.inf +# +# Component description file for DdrLib module +# +# Copyright (c) 2016, Freescale Semiconductor, Inc. All rights reserved. +# +# This program and the accompanying materials +# are licensed and made available under the terms and conditions of the BSD License +# which accompanies this distribution. The full text of the license may be found at +# http://opensource.org/licenses/bsd-license.php +# +# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, +# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. +# +#**/ + +[Defines] + INF_VERSION = 0x00010005 + BASE_NAME = DdrLib + FILE_GUID = 8ecefc8f-a2c4-4091-b31f-20f7aeb0567f + MODULE_TYPE = BASE + VERSION_STRING = 1.0 + LIBRARY_CLASS = DdrLib + +[Sources.common] + DdrLib.c + +[LibraryClasses] + ArmLib + IoLib + BaseMemoryLib + BaseLib + SocLib + +[Packages] + EmbeddedPkg/EmbeddedPkg.dec + MdePkg/MdePkg.dec + MdeModulePkg/MdeModulePkg.dec + ArmPlatformPkg/ArmPlatformPkg.dec + OpenPlatformPkg/Platforms/Nxp/LS1043aRdb/LS1043aRdbPkg.dec + OpenPlatformPkg/Chips/Nxp/QoriqLs/NxpQoriqLs.dec
On 17 October 2016 at 21:04, Bhupesh Sharma bhupesh.sharma@freescale.com wrote:
From: Sakar Arora sakar.arora@nxp.com
NXP/FSL's LS1043A RDB board houses 2 GB DDR4 SDRAM.
There is a DDR controller IP which controls access to this SDRAM.
This patch adds a library which allows required initialization of this controller. This library executes out of the XIP NOR flash mememory.
Signed-off-by: Meenakshi Aggarwal meenakshi.aggarwal@nxp.com Signed-off-by: Bhupesh Sharma bhupesh.sharma@nxp.com
Platforms/Nxp/LS1043aRdb/Include/Library/Ddr.h | 190 +++++++++++++++++++++ Platforms/Nxp/LS1043aRdb/Library/DdrLib/DdrLib.c | 188 ++++++++++++++++++++ Platforms/Nxp/LS1043aRdb/Library/DdrLib/DdrLib.inf | 41 +++++ 3 files changed, 419 insertions(+) create mode 100644 Platforms/Nxp/LS1043aRdb/Include/Library/Ddr.h create mode 100644 Platforms/Nxp/LS1043aRdb/Library/DdrLib/DdrLib.c create mode 100644 Platforms/Nxp/LS1043aRdb/Library/DdrLib/DdrLib.inf
diff --git a/Platforms/Nxp/LS1043aRdb/Include/Library/Ddr.h b/Platforms/Nxp/LS1043aRdb/Include/Library/Ddr.h
Please declare this library class in the [LibraryClasses] section of the package .dec file
new file mode 100644 index 0000000..0d715fb --- /dev/null +++ b/Platforms/Nxp/LS1043aRdb/Include/Library/Ddr.h @@ -0,0 +1,190 @@ +/** @Ddr.h
- Header defining the Ddr controller constants (Base addresses, sizes, flags),
- function prototype, structures etc
- Copyright (c) 2016, Freescale Semiconductor, Inc. All rights reserved.
- This program and the accompanying materials
- are licensed and made available under the terms and conditions of the BSD License
- which accompanies this distribution. The full text of the license may be found at
- http://opensource.org/licenses/bsd-license.php
- THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
- WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
+**/
+#ifndef __DDR_H__ +#define __DDR_H__
+#include <Library/DebugLib.h> +#include <Library/IoLib.h> +#include <Library/PlatformLib.h>
+/* DDR4 fixed timing */ +#define LS1043A_CS0_BNDS 0x0000007f /* 0x000 */ +#define LS1043A_CS0_CONFIG 0x80010322 /* 0x080 */ +#define LS1043A_TIMING_CFG_3 0x020C1000 /* 0x100 */ +#define LS1043A_TIMING_CFG_0 0xD0550018 /* 0x104 */ +#define LS1043A_TIMING_CFG_1 0xC2C68C42 /* 0x108 */ +#define LS1043A_TIMING_CFG_2 0x0048C114 /* 0x10c */ +#define LS1043A_DDR_SDRAM_CFG 0x450C000C /* 0x110 */ +#define LS1043A_DDR_SDRAM_CFG_2 0x00401010 /* 0x114 */ +#define LS1043A_DDR_SDRAM_MODE 0x01010214 /* 0x118 */ +#define LS1043A_DDR_SDRAM_INTERVAL 0x18600618 /* 0x124 */ +#define LS1043A_DDR_SDRAM_CLK_CNTL 0x02000000 /* 0x130 */ +#define LS1043A_TIMING_CFG_4 0x00000002 /* 0x160 */ +#define LS1043A_TIMING_CFG_5 0x04401400 /* 0x164 */ +#define LS1043A_TIMING_CFG_7 0x13300000 /* 0x16c */ +#define LS1043A_DDR_ZQ_CNTL 0x8A090705 /* 0x170 */ +#define LS1043A_DDR_WRLVL_CNTL 0x8655F606 /* 0x174 */ +#define LS1043A_DDR_WRLVL_CNTL_2 0x05070600 /* 0x190 */ +#define LS1043A_DDR_SDRAM_MODE_9 0x00000400 /* 0x220 */ +#define LS1043A_DDR_SDRAM_MODE_10 0x04000000 /* 0x224 */ +#define LS1043A_TIMING_CFG_8 0x03115600 /* 0x250 */ +#define LS1043A_DDRCDR_1 0x80040000 /* 0xb28 */ +#define LS1043A_DDRCDR_2 0x0000A181 /* 0xb2c */
+#define LS1043A_DDR_SDRAM_CFG_MEM_EN 0x80000000
+/**
- DDR memory controller registers
+**/ +struct CcsrDdr {
- UINT32 Cs0Bnds; /** Chip Select 0 Memory Bounds */
- CHAR8 Res04[4];
- UINT32 Cs1Bnds; /** Chip Select 1 Memory Bounds */
- CHAR8 Res0c[4];
- UINT32 Cs2Bnds; /** Chip Select 2 Memory Bounds */
- CHAR8 Res14[4];
- UINT32 Cs3Bnds; /** Chip Select 3 Memory Bounds */
- CHAR8 Res1c[100];
- UINT32 Cs0Config; /** Chip Select Configuration */
- UINT32 Cs1Config; /** Chip Select Configuration */
- UINT32 Cs2Config; /** Chip Select Configuration */
- UINT32 Cs3Config; /** Chip Select Configuration */
- CHAR8 Res90[48];
- UINT32 Cs0Config2; /** Chip Select Configuration 2 */
- UINT32 Cs1Config2; /** Chip Select Configuration 2 */
- UINT32 Cs2Config2; /** Chip Select Configuration 2 */
- UINT32 Cs3Config2; /** Chip Select Configuration 2 */
- CHAR8 Resd0[48];
- UINT32 TimingCfg3; /** SDRAM Timing Configuration 3 */
- UINT32 TimingCfg0; /** SDRAM Timing Configuration 0 */
- UINT32 TimingCfg1; /** SDRAM Timing Configuration 1 */
- UINT32 TimingCfg2; /** SDRAM Timing Configuration 2 */
- UINT32 SdramCfg; /** SDRAM Control Configuration */
- UINT32 SdramCfg2; /** SDRAM Control Configuration 2 */
- UINT32 SdramMode; /** SDRAM Mode Configuration */
- UINT32 SdramMode2; /** SDRAM Mode Configuration 2 */
- UINT32 SdramMdCntl; /** SDRAM Mode Control */
- UINT32 SdramInterval; /** SDRAM Interval Configuration */
- UINT32 SdramDataInit; /** SDRAM Data initialization */
- CHAR8 Res12c[4];
- UINT32 SdramClkCntl; /** SDRAM Clock Control */
- CHAR8 Res134[20];
- UINT32 InitAddr; /** training init addr */
- UINT32 InitExtAddr; /** training init extended addr */
- CHAR8 Res150[16];
- UINT32 TimingCfg4; /** SDRAM Timing Configuration 4 */
- UINT32 TimingCfg5; /** SDRAM Timing Configuration 5 */
- UINT32 TimingCfg6; /** SDRAM Timing Configuration 6 */
- UINT32 TimingCfg7; /** SDRAM Timing Configuration 7 */
- UINT32 DdrZqCntl; /** ZQ calibration control*/
- UINT32 DdrWrlvlCntl; /** write leveling control*/
- CHAR8 Reg178[4];
- UINT32 DdrSrCntr; /** self refresh counter */
- UINT32 DdrSdramRcw1; /** Control Words 1 */
- UINT32 DdrSdramRcw2; /** Control Words 2 */
- CHAR8 Reg188[8];
- UINT32 DdrWrlvlCntl2; /** write leveling control 2 */
- UINT32 DdrWrlvlCntl3; /** write leveling control 3 */
- CHAR8 Res198[8];
- UINT32 DdrSdramRcw3;
- UINT32 DdrSdramRcw4;
- UINT32 DdrSdramRcw5;
- UINT32 DdrSdramRcw6;
- CHAR8 Res1b0[80];
- UINT32 SdramMode3; /** SDRAM Mode Configuration 3 */
- UINT32 SdramMode4; /** SDRAM Mode Configuration 4 */
- UINT32 SdramMode5; /** SDRAM Mode Configuration 5 */
- UINT32 SdramMode6; /** SDRAM Mode Configuration 6 */
- UINT32 SdramMode7; /** SDRAM Mode Configuration 7 */
- UINT32 SdramMode8; /** SDRAM Mode Configuration 8 */
- CHAR8 Res218[8];
- UINT32 SdramMode9; /** SDRAM Mode Configuration 9 */
- UINT32 SdramMode10; /** SDRAM Mode Configuration 10 */
- UINT32 SdramMode11; /** SDRAM Mode Configuration 11 */
- UINT32 SdramMode12; /** SDRAM Mode Configuration 12 */
- UINT32 SdramMode13; /** SDRAM Mode Configuration 13 */
- UINT32 SdramMode14; /** SDRAM Mode Configuration 14 */
- UINT32 SdramMode15; /** SDRAM Mode Configuration 15 */
- UINT32 SdramMode16; /** SDRAM Mode Configuration 16 */
- CHAR8 Res240[16];
- UINT32 TimingCfg8; /* SDRAM Timing Configuration 8 */
- CHAR8 Res254[12];
- UINT32 SdramCfg3;
- CHAR8 Res264[412];
- UINT32 DqMap0;
- UINT32 DqMap1;
- UINT32 DqMap2;
- UINT32 DqMap3;
- CHAR8 Res410[1808];
- UINT32 DdrDsr1; /** Debug Status 1 */
- UINT32 DdrDsr2; /** Debug Status 2 */
- UINT32 DdrCdr1; /** Control Driver 1 */
- UINT32 DdrCdr2; /** Control Driver 2 */
- CHAR8 ResB30[200];
- UINT32 IpRev1; /** IP Block Revision 1 */
- UINT32 IpRev2; /** IP Block Revision 2 */
- UINT32 Eor; /** Enhanced Optimization Register */
- CHAR8 ResC04[252];
- UINT32 Mtcr; /** Memory Test Control Register */
- CHAR8 ResD04[28];
- UINT32 Mtp1; /** Memory Test Pattern 1 */
- UINT32 Mtp2; /** Memory Test Pattern 2 */
- UINT32 Mtp3; /** Memory Test Pattern 3 */
- UINT32 Mtp4; /** Memory Test Pattern 4 */
- UINT32 Mtp5; /** Memory Test Pattern 5 */
- UINT32 Mtp6; /** Memory Test Pattern 6 */
- UINT32 Mtp7; /** Memory Test Pattern 7 */
- UINT32 Mtp8; /** Memory Test Pattern 8 */
- UINT32 Mtp9; /** Memory Test Pattern 9 */
- UINT32 Mtp10; /** Memory Test Pattern 10 */
- CHAR8 ResD48[184];
- UINT32 DataErrInjectHi; /** Data Path Err Injection Mask High */
- UINT32 DataErrInjectLo; /** Data Path Err Injection Mask Low */
- UINT32 EccErrInject; /** Data Path Err Injection Mask ECC */
- CHAR8 ResE0c[20];
- UINT32 CaptureDataHi; /** Data Path Read Capture High */
- UINT32 CaptureDataLo; /** Data Path Read Capture Low */
- UINT32 CaptureEcc; /** Data Path Read Capture ECC */
- CHAR8 ResE2c[20];
- UINT32 ErrDetect; /** Error Detect */
- UINT32 ErrDisable; /** Error Disable */
- UINT32 ErrIntEn;
- UINT32 CaptureAttributes; /** Error Attrs Capture */
- UINT32 CaptureAddress; /** Error Addr Capture */
- UINT32 CaptureExtAddress; /** Error Extended Addr Capture */
- UINT32 ErrSbe; /** Single-Bit ECC Error Management */
- CHAR8 ResE5c[164];
- UINT32 Debug[32]; /** Debug_1 to Debug_32 */
- CHAR8 ResF80[128];
+};
+/**
- Main function to initialize DDR
- **/
+VOID +DramInit(
- );
+/**
- Function to dump DDRC registers
+**/ +VOID +DdrRegDump (
- VOID
- );
+#endif diff --git a/Platforms/Nxp/LS1043aRdb/Library/DdrLib/DdrLib.c b/Platforms/Nxp/LS1043aRdb/Library/DdrLib/DdrLib.c new file mode 100644 index 0000000..1c33de4 --- /dev/null +++ b/Platforms/Nxp/LS1043aRdb/Library/DdrLib/DdrLib.c @@ -0,0 +1,188 @@ +/** @DdrLib.c
- Ddr Library containing functions to initialize ddr controller
- Copyright (c) 2016, Freescale Semiconductor, Inc. All rights reserved.
- This program and the accompanying materials
- are licensed and made available under the terms and conditions of the BSD License
- which accompanies this distribution. The full text of the license may be found at
- http://opensource.org/licenses/bsd-license.php
- THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
- WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
+**/
+#include <Library/Ddr.h> +#include <Library/BaseLib.h>
+#define Uswap32(X) \
((((X) & 0xff000000) >> 24) | \
(((X) & 0x00ff0000) >> 8) | \
(((X) & 0x0000ff00) << 8) | \
(((X) & 0x000000ff) << 24))
+#define DDRMC_DELAY 10000
+/**
- Function to dump DDRC registers
+**/
+VOID +DdrRegDump (
- VOID
- )
+{
- struct CcsrDdr *Ddr = (VOID *)LS1043A_DDR_ADDR;
- DEBUG((EFI_D_INFO, "Cs0Bnds = 0x%x\n",MmioReadBe32((UINTN)&Ddr->Cs0Bnds)));
- DEBUG((EFI_D_INFO, "Cs1Bnds = 0x%x\n",MmioReadBe32((UINTN)&Ddr->Cs1Bnds)));
- DEBUG((EFI_D_INFO, "Cs2Bnds = 0x%x\n",MmioReadBe32((UINTN)&Ddr->Cs2Bnds)));
- DEBUG((EFI_D_INFO, "Cs3Bnds = 0x%x\n",MmioReadBe32((UINTN)&Ddr->Cs3Bnds)));
- DEBUG((EFI_D_INFO, "Cs0Config = 0x%x\n",MmioReadBe32((UINTN)&Ddr->Cs0Config)));
- DEBUG((EFI_D_INFO, "Cs1Config = 0x%x\n",MmioReadBe32((UINTN)&Ddr->Cs1Config)));
- DEBUG((EFI_D_INFO, "Cs2Config = 0x%x\n",MmioReadBe32((UINTN)&Ddr->Cs2Config)));
- DEBUG((EFI_D_INFO, "Cs3Config = 0x%x\n",MmioReadBe32((UINTN)&Ddr->Cs3Config)));
- DEBUG((EFI_D_INFO, "Cs0Config2 = 0x%x\n",MmioReadBe32((UINTN)&Ddr->Cs0Config2)));
- DEBUG((EFI_D_INFO, "Cs1Config2 = 0x%x\n",MmioReadBe32((UINTN)&Ddr->Cs1Config2)));
- DEBUG((EFI_D_INFO, "Cs2Config2 = 0x%x\n",MmioReadBe32((UINTN)&Ddr->Cs2Config2)));
- DEBUG((EFI_D_INFO, "Cs3Config2 = 0x%x\n",MmioReadBe32((UINTN)&Ddr->Cs3Config2)));
- DEBUG((EFI_D_INFO, "TimingCfg3 = 0x%x\n",MmioReadBe32((UINTN)&Ddr->TimingCfg3)));
- DEBUG((EFI_D_INFO, "TimingCfg0 = 0x%x\n",MmioReadBe32((UINTN)&Ddr->TimingCfg0)));
- DEBUG((EFI_D_INFO, "TimingCfg1 = 0x%x\n",MmioReadBe32((UINTN)&Ddr->TimingCfg1)));
- DEBUG((EFI_D_INFO, "TimingCfg2 = 0x%x\n",MmioReadBe32((UINTN)&Ddr->TimingCfg2)));
- DEBUG((EFI_D_INFO, "SdramCfg = 0x%x\n",MmioReadBe32((UINTN)&Ddr->SdramCfg)));
- DEBUG((EFI_D_INFO, "SdramCfg2 = 0x%x\n",MmioReadBe32((UINTN)&Ddr->SdramCfg2)));
- DEBUG((EFI_D_INFO, "SdramMode = 0x%x\n",MmioReadBe32((UINTN)&Ddr->SdramMode)));
- DEBUG((EFI_D_INFO, "SdramMode2 = 0x%x\n",MmioReadBe32((UINTN)&Ddr->SdramMode2)));
- DEBUG((EFI_D_INFO, "SdramMdCntl = 0x%x\n",MmioReadBe32((UINTN)&Ddr->SdramMdCntl)));
- DEBUG((EFI_D_INFO, "SdramInterval = 0x%x\n",MmioReadBe32((UINTN)&Ddr->SdramInterval)));
- DEBUG((EFI_D_INFO, "SdramDataInit = 0x%x\n",MmioReadBe32((UINTN)&Ddr->SdramDataInit)));
- DEBUG((EFI_D_INFO, "SdramClkCntl = 0x%x\n",MmioReadBe32((UINTN)&Ddr->SdramClkCntl)));
- DEBUG((EFI_D_INFO, "InitAddr = 0x%x\n",MmioReadBe32((UINTN)&Ddr->InitAddr)));
- DEBUG((EFI_D_INFO, "InitExtAddr = 0x%x\n",MmioReadBe32((UINTN)&Ddr->InitExtAddr)));
- DEBUG((EFI_D_INFO, "TimingCfg4 = 0x%x\n",MmioReadBe32((UINTN)&Ddr->TimingCfg4)));
- DEBUG((EFI_D_INFO, "TimingCfg5 = 0x%x\n",MmioReadBe32((UINTN)&Ddr->TimingCfg5)));
- DEBUG((EFI_D_INFO, "TimingCfg6 = 0x%x\n",MmioReadBe32((UINTN)&Ddr->TimingCfg6)));
- DEBUG((EFI_D_INFO, "TimingCfg7 = 0x%x\n",MmioReadBe32((UINTN)&Ddr->TimingCfg7)));
- DEBUG((EFI_D_INFO, "DdrZqCntl = 0x%x\n",MmioReadBe32((UINTN)&Ddr->DdrZqCntl)));
- DEBUG((EFI_D_INFO, "DdrWrlvlCntl = 0x%x\n",MmioReadBe32((UINTN)&Ddr->DdrWrlvlCntl)));
- DEBUG((EFI_D_INFO, "DdrSrCntr = 0x%x\n",MmioReadBe32((UINTN)&Ddr->DdrSrCntr)));
- DEBUG((EFI_D_INFO, "DdrSdramRcw1 = 0x%x\n",MmioReadBe32((UINTN)&Ddr->DdrSdramRcw1)));
- DEBUG((EFI_D_INFO, "DdrSdramRcw2 = 0x%x\n",MmioReadBe32((UINTN)&Ddr->DdrSdramRcw2)));
- DEBUG((EFI_D_INFO, "DdrWrlvlCntl2 = 0x%x\n",MmioReadBe32((UINTN)&Ddr->DdrWrlvlCntl2)));
- DEBUG((EFI_D_INFO, "DdrWrlvlCntl3 = 0x%x\n",MmioReadBe32((UINTN)&Ddr->DdrWrlvlCntl3)));
- DEBUG((EFI_D_INFO, "DdrSdramRcw3 = 0x%x\n",MmioReadBe32((UINTN)&Ddr->DdrSdramRcw3)));
- DEBUG((EFI_D_INFO, "DdrSdramRcw4 = 0x%x\n",MmioReadBe32((UINTN)&Ddr->DdrSdramRcw4)));
- DEBUG((EFI_D_INFO, "DdrSdramRcw5 = 0x%x\n",MmioReadBe32((UINTN)&Ddr->DdrSdramRcw5)));
- DEBUG((EFI_D_INFO, "DdrSdramRcw6 = 0x%x\n",MmioReadBe32((UINTN)&Ddr->DdrSdramRcw6)));
- DEBUG((EFI_D_INFO, "SdramMode3 = 0x%x\n",MmioReadBe32((UINTN)&Ddr->SdramMode3)));
- DEBUG((EFI_D_INFO, "SdramMode4 = 0x%x\n",MmioReadBe32((UINTN)&Ddr->SdramMode4)));
- DEBUG((EFI_D_INFO, "SdramMode5 = 0x%x\n",MmioReadBe32((UINTN)&Ddr->SdramMode5)));
- DEBUG((EFI_D_INFO, "SdramMode6 = 0x%x\n",MmioReadBe32((UINTN)&Ddr->SdramMode6)));
- DEBUG((EFI_D_INFO, "SdramMode7 = 0x%x\n",MmioReadBe32((UINTN)&Ddr->SdramMode7)));
- DEBUG((EFI_D_INFO, "SdramMode8 = 0x%x\n",MmioReadBe32((UINTN)&Ddr->SdramMode8)));
- DEBUG((EFI_D_INFO, "SdramMode9 = 0x%x\n",MmioReadBe32((UINTN)&Ddr->SdramMode9)));
- DEBUG((EFI_D_INFO, "SdramMode10 = 0x%x\n",MmioReadBe32((UINTN)&Ddr->SdramMode10)));
- DEBUG((EFI_D_INFO, "SdramMode11 = 0x%x\n",MmioReadBe32((UINTN)&Ddr->SdramMode11)));
- DEBUG((EFI_D_INFO, "SdramMode12 = 0x%x\n",MmioReadBe32((UINTN)&Ddr->SdramMode12)));
- DEBUG((EFI_D_INFO, "SdramMode13 = 0x%x\n",MmioReadBe32((UINTN)&Ddr->SdramMode13)));
- DEBUG((EFI_D_INFO, "SdramMode14 = 0x%x\n",MmioReadBe32((UINTN)&Ddr->SdramMode14)));
- DEBUG((EFI_D_INFO, "SdramMode15 = 0x%x\n",MmioReadBe32((UINTN)&Ddr->SdramMode15)));
- DEBUG((EFI_D_INFO, "SdramMode16 = 0x%x\n",MmioReadBe32((UINTN)&Ddr->SdramMode16)));
- DEBUG((EFI_D_INFO, "TimingCfg8 = 0x%x\n",MmioReadBe32((UINTN)&Ddr->TimingCfg8)));
- DEBUG((EFI_D_INFO, "SdramCfg3 = 0x%x\n",MmioReadBe32((UINTN)&Ddr->SdramCfg3)));
- DEBUG((EFI_D_INFO, "DqMap0 = 0x%x\n",MmioReadBe32((UINTN)&Ddr->DqMap0)));
- DEBUG((EFI_D_INFO, "DqMap1 = 0x%x\n",MmioReadBe32((UINTN)&Ddr->DqMap1)));
- DEBUG((EFI_D_INFO, "DqMap2 = 0x%x\n",MmioReadBe32((UINTN)&Ddr->DqMap2)));
- DEBUG((EFI_D_INFO, "DqMap3 = 0x%x\n",MmioReadBe32((UINTN)&Ddr->DqMap3)));
- DEBUG((EFI_D_INFO, "DdrDsr1 = 0x%x\n",MmioReadBe32((UINTN)&Ddr->DdrDsr1)));
- DEBUG((EFI_D_INFO, "DdrDsr2 = 0x%x\n",MmioReadBe32((UINTN)&Ddr->DdrDsr2)));
- DEBUG((EFI_D_INFO, "DdrCdr1 = 0x%x\n",MmioReadBe32((UINTN)&Ddr->DdrCdr1)));
- DEBUG((EFI_D_INFO, "DdrCdr2 = 0x%x\n",MmioReadBe32((UINTN)&Ddr->DdrCdr2)));
- DEBUG((EFI_D_INFO, "IpRev1 = 0x%x\n",MmioReadBe32((UINTN)&Ddr->IpRev1)));
- DEBUG((EFI_D_INFO, "IpRev2 = 0x%x\n",MmioReadBe32((UINTN)&Ddr->IpRev2)));
- DEBUG((EFI_D_INFO, "Eor = 0x%x\n",MmioReadBe32((UINTN)&Ddr->Eor)));
- DEBUG((EFI_D_INFO, "Mtcr = 0x%x\n",MmioReadBe32((UINTN)&Ddr->Mtcr)));
- DEBUG((EFI_D_INFO, "Mtp1 = 0x%x\n",MmioReadBe32((UINTN)&Ddr->Mtp1)));
- DEBUG((EFI_D_INFO, "Mtp2 = 0x%x\n",MmioReadBe32((UINTN)&Ddr->Mtp2)));
- DEBUG((EFI_D_INFO, "Mtp3 = 0x%x\n",MmioReadBe32((UINTN)&Ddr->Mtp3)));
- DEBUG((EFI_D_INFO, "Mtp4 = 0x%x\n",MmioReadBe32((UINTN)&Ddr->Mtp4)));
- DEBUG((EFI_D_INFO, "Mtp5 = 0x%x\n",MmioReadBe32((UINTN)&Ddr->Mtp5)));
- DEBUG((EFI_D_INFO, "Mtp6 = 0x%x\n",MmioReadBe32((UINTN)&Ddr->Mtp6)));
- DEBUG((EFI_D_INFO, "Mtp7 = 0x%x\n",MmioReadBe32((UINTN)&Ddr->Mtp7)));
- DEBUG((EFI_D_INFO, "Mtp8 = 0x%x\n",MmioReadBe32((UINTN)&Ddr->Mtp8)));
- DEBUG((EFI_D_INFO, "Mtp9 = 0x%x\n",MmioReadBe32((UINTN)&Ddr->Mtp9)));
- DEBUG((EFI_D_INFO, "Mtp10 = 0x%x\n",MmioReadBe32((UINTN)&Ddr->Mtp10)));
- DEBUG((EFI_D_INFO, "DataErrInjectHi = 0x%x\n",MmioReadBe32((UINTN)&Ddr->DataErrInjectHi)));
- DEBUG((EFI_D_INFO, "DataErrInjectLo = 0x%x\n",MmioReadBe32((UINTN)&Ddr->DataErrInjectLo)));
- DEBUG((EFI_D_INFO, "EccErrInject = 0x%x\n",MmioReadBe32((UINTN)&Ddr->EccErrInject)));
- DEBUG((EFI_D_INFO, "CaptureDataHi = 0x%x\n",MmioReadBe32((UINTN)&Ddr->CaptureDataHi)));
- DEBUG((EFI_D_INFO, "CaptureDataLo = 0x%x\n",MmioReadBe32((UINTN)&Ddr->CaptureDataLo)));
- DEBUG((EFI_D_INFO, "CaptureEcc = 0x%x\n",MmioReadBe32((UINTN)&Ddr->CaptureEcc)));
- DEBUG((EFI_D_INFO, "ErrDetect = 0x%x\n",MmioReadBe32((UINTN)&Ddr->ErrDetect)));
- DEBUG((EFI_D_INFO, "ErrDisable = 0x%x\n",MmioReadBe32((UINTN)&Ddr->ErrDisable)));
- DEBUG((EFI_D_INFO, "ErrIntEn = 0x%x\n",MmioReadBe32((UINTN)&Ddr->ErrIntEn)));
- DEBUG((EFI_D_INFO, "CaptureAttributes = 0x%x\n",MmioReadBe32((UINTN)&Ddr->CaptureAttributes)));
- DEBUG((EFI_D_INFO, "CaptureAddress = 0x%x\n",MmioReadBe32((UINTN)&Ddr->CaptureAddress)));
- DEBUG((EFI_D_INFO, "CaptureExtAddress = 0x%x\n",MmioReadBe32((UINTN)&Ddr->CaptureExtAddress)));
- DEBUG((EFI_D_INFO, "ErrSbe = 0x%x\n",MmioReadBe32((UINTN)&Ddr->ErrSbe)));
- DEBUG((EFI_D_ERROR,"\n"));
+}
+/**
- Function to initialize DDR
- **/
+VOID +DramInit (
- )
+{
- struct CcsrDdr *Ddr;
UINT32 Count, Delay = DDRMC_DELAY;
- Ddr = (VOID *)LS1043A_DDR_ADDR;
- MmioWriteBe32((UINTN)&Ddr->SdramCfg, LS1043A_DDR_SDRAM_CFG);
Where is MmioWriteBe32() defined?
- MmioWriteBe32((UINTN)&Ddr->Cs0Bnds, LS1043A_CS0_BNDS);
- MmioWriteBe32((UINTN)&Ddr->Cs0Config, LS1043A_CS0_CONFIG);
- MmioWriteBe32((UINTN)&Ddr->TimingCfg0, LS1043A_TIMING_CFG_0);
- MmioWriteBe32((UINTN)&Ddr->TimingCfg1, LS1043A_TIMING_CFG_1);
- MmioWriteBe32((UINTN)&Ddr->TimingCfg2, LS1043A_TIMING_CFG_2);
- MmioWriteBe32((UINTN)&Ddr->TimingCfg3, LS1043A_TIMING_CFG_3);
- MmioWriteBe32((UINTN)&Ddr->TimingCfg4, LS1043A_TIMING_CFG_4);
- MmioWriteBe32((UINTN)&Ddr->TimingCfg5, LS1043A_TIMING_CFG_5);
- MmioWriteBe32((UINTN)&Ddr->TimingCfg7, LS1043A_TIMING_CFG_7);
- MmioWriteBe32((UINTN)&Ddr->TimingCfg8, LS1043A_TIMING_CFG_8);
- MmioWriteBe32((UINTN)&Ddr->SdramCfg2, LS1043A_DDR_SDRAM_CFG_2);
- MmioWriteBe32((UINTN)&Ddr->SdramMode, LS1043A_DDR_SDRAM_MODE);
- MmioWriteBe32((UINTN)&Ddr->SdramMode2, 0);
- MmioWriteBe32((UINTN)&Ddr->SdramInterval, LS1043A_DDR_SDRAM_INTERVAL);
- MmioWriteBe32((UINTN)&Ddr->DdrWrlvlCntl, LS1043A_DDR_WRLVL_CNTL);
- MmioWriteBe32((UINTN)&Ddr->DdrWrlvlCntl2, LS1043A_DDR_WRLVL_CNTL_2);
- MmioWriteBe32((UINTN)&Ddr->DdrWrlvlCntl3, 0);
- MmioWriteBe32((UINTN)&Ddr->DdrCdr1, LS1043A_DDRCDR_1);
- MmioWriteBe32((UINTN)&Ddr->DdrCdr2, LS1043A_DDRCDR_2);
- MmioWriteBe32((UINTN)&Ddr->SdramClkCntl, LS1043A_DDR_SDRAM_CLK_CNTL);
- MmioWriteBe32((UINTN)&Ddr->DdrZqCntl, LS1043A_DDR_ZQ_CNTL);
- MmioWriteBe32((UINTN)&Ddr->SdramMode9, LS1043A_DDR_SDRAM_MODE_9);
- MmioWriteBe32((UINTN)&Ddr->SdramMode10, LS1043A_DDR_SDRAM_MODE_10);
- MmioWriteBe32((UINTN)&Ddr->Cs0Config2, 0);
- for(Count = 0; Count < Delay; Count++)
;
- MmioWriteBe32((UINTN)&Ddr->SdramCfg, LS1043A_DDR_SDRAM_CFG
| LS1043A_DDR_SDRAM_CFG_MEM_EN);
- return;
No 'return's add the end of void functions please
+} diff --git a/Platforms/Nxp/LS1043aRdb/Library/DdrLib/DdrLib.inf b/Platforms/Nxp/LS1043aRdb/Library/DdrLib/DdrLib.inf new file mode 100644 index 0000000..e8e3aed --- /dev/null +++ b/Platforms/Nxp/LS1043aRdb/Library/DdrLib/DdrLib.inf @@ -0,0 +1,41 @@ +#/** DdrLib.inf +# +# Component description file for DdrLib module +# +# Copyright (c) 2016, Freescale Semiconductor, Inc. All rights reserved. +# +# This program and the accompanying materials +# are licensed and made available under the terms and conditions of the BSD License +# which accompanies this distribution. The full text of the license may be found at +# http://opensource.org/licenses/bsd-license.php +# +# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, +# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. +# +#**/
+[Defines]
- INF_VERSION = 0x00010005
- BASE_NAME = DdrLib
- FILE_GUID = 8ecefc8f-a2c4-4091-b31f-20f7aeb0567f
Please use a fresh GUID
- MODULE_TYPE = BASE
- VERSION_STRING = 1.0
- LIBRARY_CLASS = DdrLib
+[Sources.common]
- DdrLib.c
+[LibraryClasses]
- ArmLib
- IoLib
- BaseMemoryLib
- BaseLib
- SocLib
+[Packages]
- EmbeddedPkg/EmbeddedPkg.dec
- MdePkg/MdePkg.dec
- MdeModulePkg/MdeModulePkg.dec
- ArmPlatformPkg/ArmPlatformPkg.dec
- OpenPlatformPkg/Platforms/Nxp/LS1043aRdb/LS1043aRdbPkg.dec
- OpenPlatformPkg/Chips/Nxp/QoriqLs/NxpQoriqLs.dec
-- 1.9.1
Hi Ard,
Please see my replies inline.
From: Ard Biesheuvel [mailto:ard.biesheuvel@linaro.org] Sent: Tuesday, October 18, 2016 2:51 PM
On 17 October 2016 at 21:04, Bhupesh Sharma bhupesh.sharma@freescale.com wrote:
From: Sakar Arora sakar.arora@nxp.com
NXP/FSL's LS1043A RDB board houses 2 GB DDR4 SDRAM.
There is a DDR controller IP which controls access to this SDRAM.
This patch adds a library which allows required initialization of
this
controller. This library executes out of the XIP NOR flash mememory.
Signed-off-by: Meenakshi Aggarwal meenakshi.aggarwal@nxp.com Signed-off-by: Bhupesh Sharma bhupesh.sharma@nxp.com
Platforms/Nxp/LS1043aRdb/Include/Library/Ddr.h | 190
+++++++++++++++++++++
Platforms/Nxp/LS1043aRdb/Library/DdrLib/DdrLib.c | 188
++++++++++++++++++++
Platforms/Nxp/LS1043aRdb/Library/DdrLib/DdrLib.inf | 41 +++++ 3 files changed, 419 insertions(+) create mode 100644 Platforms/Nxp/LS1043aRdb/Include/Library/Ddr.h create mode 100644 Platforms/Nxp/LS1043aRdb/Library/DdrLib/DdrLib.c create mode 100644
Platforms/Nxp/LS1043aRdb/Library/DdrLib/DdrLib.inf
diff --git a/Platforms/Nxp/LS1043aRdb/Include/Library/Ddr.h b/Platforms/Nxp/LS1043aRdb/Include/Library/Ddr.h
Please declare this library class in the [LibraryClasses] section of the package .dec file
new file mode 100644 index 0000000..0d715fb --- /dev/null +++ b/Platforms/Nxp/LS1043aRdb/Include/Library/Ddr.h @@ -0,0 +1,190 @@ +/** @Ddr.h
- Header defining the Ddr controller constants (Base addresses,
+sizes, flags),
- function prototype, structures etc
- Copyright (c) 2016, Freescale Semiconductor, Inc. All rights
reserved.
- This program and the accompanying materials are licensed and made
- available under the terms and conditions of the BSD License which
- accompanies this distribution. The full text of the license may be
- found at http://opensource.org/licenses/bsd-license.php
- THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS"
- BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER
EXPRESS OR IMPLIED.
+**/
+#ifndef __DDR_H__ +#define __DDR_H__
+#include <Library/DebugLib.h> +#include <Library/IoLib.h> +#include <Library/PlatformLib.h>
+/* DDR4 fixed timing */ +#define LS1043A_CS0_BNDS 0x0000007f /* 0x000 */ +#define LS1043A_CS0_CONFIG 0x80010322 /* 0x080 */ +#define LS1043A_TIMING_CFG_3 0x020C1000 /* 0x100 */ +#define LS1043A_TIMING_CFG_0 0xD0550018 /* 0x104 */ +#define LS1043A_TIMING_CFG_1 0xC2C68C42 /* 0x108 */ +#define LS1043A_TIMING_CFG_2 0x0048C114 /* 0x10c */ +#define LS1043A_DDR_SDRAM_CFG 0x450C000C /* 0x110 */ +#define LS1043A_DDR_SDRAM_CFG_2 0x00401010 /* 0x114 */ +#define LS1043A_DDR_SDRAM_MODE 0x01010214 /* 0x118 */ +#define LS1043A_DDR_SDRAM_INTERVAL 0x18600618 /* 0x124 */ +#define LS1043A_DDR_SDRAM_CLK_CNTL 0x02000000 /* 0x130 */ +#define LS1043A_TIMING_CFG_4 0x00000002 /* 0x160 */ +#define LS1043A_TIMING_CFG_5 0x04401400 /* 0x164 */ +#define LS1043A_TIMING_CFG_7 0x13300000 /* 0x16c */ +#define LS1043A_DDR_ZQ_CNTL 0x8A090705 /* 0x170 */ +#define LS1043A_DDR_WRLVL_CNTL 0x8655F606 /* 0x174 */ +#define LS1043A_DDR_WRLVL_CNTL_2 0x05070600 /* 0x190 */ +#define LS1043A_DDR_SDRAM_MODE_9 0x00000400 /* 0x220 */ +#define LS1043A_DDR_SDRAM_MODE_10 0x04000000 /* 0x224 */ +#define LS1043A_TIMING_CFG_8 0x03115600 /* 0x250 */ +#define LS1043A_DDRCDR_1 0x80040000 /* 0xb28 */ +#define LS1043A_DDRCDR_2 0x0000A181 /* 0xb2c */
+#define LS1043A_DDR_SDRAM_CFG_MEM_EN 0x80000000
+/**
- DDR memory controller registers
+**/ +struct CcsrDdr {
- UINT32 Cs0Bnds; /** Chip Select 0 Memory
Bounds */
- CHAR8 Res04[4];
- UINT32 Cs1Bnds; /** Chip Select 1 Memory
Bounds */
- CHAR8 Res0c[4];
- UINT32 Cs2Bnds; /** Chip Select 2 Memory
Bounds */
- CHAR8 Res14[4];
- UINT32 Cs3Bnds; /** Chip Select 3 Memory
Bounds */
- CHAR8 Res1c[100];
- UINT32 Cs0Config; /** Chip Select Configuration
*/
- UINT32 Cs1Config; /** Chip Select Configuration
*/
- UINT32 Cs2Config; /** Chip Select Configuration
*/
- UINT32 Cs3Config; /** Chip Select Configuration
*/
- CHAR8 Res90[48];
- UINT32 Cs0Config2; /** Chip Select Configuration
2 */
- UINT32 Cs1Config2; /** Chip Select Configuration
2 */
- UINT32 Cs2Config2; /** Chip Select Configuration
2 */
- UINT32 Cs3Config2; /** Chip Select Configuration
2 */
- CHAR8 Resd0[48];
- UINT32 TimingCfg3; /** SDRAM Timing
Configuration 3 */
- UINT32 TimingCfg0; /** SDRAM Timing
Configuration 0 */
- UINT32 TimingCfg1; /** SDRAM Timing
Configuration 1 */
- UINT32 TimingCfg2; /** SDRAM Timing
Configuration 2 */
- UINT32 SdramCfg; /** SDRAM Control
Configuration */
- UINT32 SdramCfg2; /** SDRAM Control
Configuration 2 */
- UINT32 SdramMode; /** SDRAM Mode Configuration
*/
- UINT32 SdramMode2; /** SDRAM Mode Configuration
2 */
- UINT32 SdramMdCntl; /** SDRAM Mode Control */
- UINT32 SdramInterval; /** SDRAM Interval Configuration */
- UINT32 SdramDataInit; /** SDRAM Data initialization */
- CHAR8 Res12c[4];
- UINT32 SdramClkCntl; /** SDRAM Clock Control */
- CHAR8 Res134[20];
- UINT32 InitAddr; /** training init addr */
- UINT32 InitExtAddr; /** training init extended
addr */
- CHAR8 Res150[16];
- UINT32 TimingCfg4; /** SDRAM Timing
Configuration 4 */
- UINT32 TimingCfg5; /** SDRAM Timing
Configuration 5 */
- UINT32 TimingCfg6; /** SDRAM Timing
Configuration 6 */
- UINT32 TimingCfg7; /** SDRAM Timing
Configuration 7 */
- UINT32 DdrZqCntl; /** ZQ calibration control*/
- UINT32 DdrWrlvlCntl; /** write leveling control*/
- CHAR8 Reg178[4];
- UINT32 DdrSrCntr; /** self refresh counter */
- UINT32 DdrSdramRcw1; /** Control Words 1 */
- UINT32 DdrSdramRcw2; /** Control Words 2 */
- CHAR8 Reg188[8];
- UINT32 DdrWrlvlCntl2; /** write leveling control 2 */
- UINT32 DdrWrlvlCntl3; /** write leveling control 3 */
- CHAR8 Res198[8];
- UINT32 DdrSdramRcw3;
- UINT32 DdrSdramRcw4;
- UINT32 DdrSdramRcw5;
- UINT32 DdrSdramRcw6;
- CHAR8 Res1b0[80];
- UINT32 SdramMode3; /** SDRAM Mode Configuration
3 */
- UINT32 SdramMode4; /** SDRAM Mode Configuration
4 */
- UINT32 SdramMode5; /** SDRAM Mode Configuration
5 */
- UINT32 SdramMode6; /** SDRAM Mode Configuration
6 */
- UINT32 SdramMode7; /** SDRAM Mode Configuration
7 */
- UINT32 SdramMode8; /** SDRAM Mode Configuration
8 */
- CHAR8 Res218[8];
- UINT32 SdramMode9; /** SDRAM Mode Configuration
9 */
- UINT32 SdramMode10; /** SDRAM Mode Configuration
10 */
- UINT32 SdramMode11; /** SDRAM Mode Configuration
11 */
- UINT32 SdramMode12; /** SDRAM Mode Configuration
12 */
- UINT32 SdramMode13; /** SDRAM Mode Configuration
13 */
- UINT32 SdramMode14; /** SDRAM Mode Configuration
14 */
- UINT32 SdramMode15; /** SDRAM Mode Configuration
15 */
- UINT32 SdramMode16; /** SDRAM Mode Configuration
16 */
- CHAR8 Res240[16];
- UINT32 TimingCfg8; /* SDRAM Timing Configuration 8 */
- CHAR8 Res254[12];
- UINT32 SdramCfg3;
- CHAR8 Res264[412];
- UINT32 DqMap0;
- UINT32 DqMap1;
- UINT32 DqMap2;
- UINT32 DqMap3;
- CHAR8 Res410[1808];
- UINT32 DdrDsr1; /** Debug Status 1 */
- UINT32 DdrDsr2; /** Debug Status 2 */
- UINT32 DdrCdr1; /** Control Driver 1 */
- UINT32 DdrCdr2; /** Control Driver 2 */
- CHAR8 ResB30[200];
- UINT32 IpRev1; /** IP Block Revision 1 */
- UINT32 IpRev2; /** IP Block Revision 2 */
- UINT32 Eor; /** Enhanced Optimization
Register */
- CHAR8 ResC04[252];
- UINT32 Mtcr; /** Memory Test Control
Register */
- CHAR8 ResD04[28];
- UINT32 Mtp1; /** Memory Test Pattern 1 */
- UINT32 Mtp2; /** Memory Test Pattern 2 */
- UINT32 Mtp3; /** Memory Test Pattern 3 */
- UINT32 Mtp4; /** Memory Test Pattern 4 */
- UINT32 Mtp5; /** Memory Test Pattern 5 */
- UINT32 Mtp6; /** Memory Test Pattern 6 */
- UINT32 Mtp7; /** Memory Test Pattern 7 */
- UINT32 Mtp8; /** Memory Test Pattern 8 */
- UINT32 Mtp9; /** Memory Test Pattern 9 */
- UINT32 Mtp10; /** Memory Test Pattern 10 */
- CHAR8 ResD48[184];
- UINT32 DataErrInjectHi; /** Data Path Err Injection
Mask High */
- UINT32 DataErrInjectLo; /** Data Path Err Injection
Mask Low */
- UINT32 EccErrInject; /** Data Path Err Injection
Mask ECC */
- CHAR8 ResE0c[20];
- UINT32 CaptureDataHi; /** Data Path Read Capture High */
- UINT32 CaptureDataLo; /** Data Path Read Capture Low */
- UINT32 CaptureEcc; /** Data Path Read Capture
ECC */
- CHAR8 ResE2c[20];
- UINT32 ErrDetect; /** Error Detect */
- UINT32 ErrDisable; /** Error Disable */
- UINT32 ErrIntEn;
- UINT32 CaptureAttributes; /** Error Attrs Capture */
- UINT32 CaptureAddress; /** Error Addr Capture */
- UINT32 CaptureExtAddress; /** Error Extended Addr
Capture */
- UINT32 ErrSbe; /** Single-Bit ECC Error Management
*/
- CHAR8 ResE5c[164];
- UINT32 Debug[32]; /** Debug_1 to Debug_32 */
- CHAR8 ResF80[128];
+};
+/**
- Main function to initialize DDR
- **/
+VOID +DramInit(
- );
+/**
- Function to dump DDRC registers
+**/ +VOID +DdrRegDump (
- VOID
- );
+#endif diff --git a/Platforms/Nxp/LS1043aRdb/Library/DdrLib/DdrLib.c b/Platforms/Nxp/LS1043aRdb/Library/DdrLib/DdrLib.c new file mode 100644 index 0000000..1c33de4 --- /dev/null +++ b/Platforms/Nxp/LS1043aRdb/Library/DdrLib/DdrLib.c @@ -0,0 +1,188 @@ +/** @DdrLib.c
- Ddr Library containing functions to initialize ddr controller
- Copyright (c) 2016, Freescale Semiconductor, Inc. All rights
reserved.
- This program and the accompanying materials are licensed and made
- available under the terms and conditions of the BSD License which
- accompanies this distribution. The full text of the license may be
- found at http://opensource.org/licenses/bsd-license.php
- THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS"
- BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER
EXPRESS OR IMPLIED.
+**/
+#include <Library/Ddr.h> +#include <Library/BaseLib.h>
+#define Uswap32(X) \
((((X) & 0xff000000) >> 24) | \
(((X) & 0x00ff0000) >> 8) | \
(((X) & 0x0000ff00) << 8) | \
(((X) & 0x000000ff) << 24))
+#define DDRMC_DELAY 10000
+/**
- Function to dump DDRC registers
+**/
+VOID +DdrRegDump (
- VOID
- )
+{
- struct CcsrDdr *Ddr = (VOID *)LS1043A_DDR_ADDR;
- DEBUG((EFI_D_INFO, "Cs0Bnds =
+0x%x\n",MmioReadBe32((UINTN)&Ddr->Cs0Bnds)));
- DEBUG((EFI_D_INFO, "Cs1Bnds =
+0x%x\n",MmioReadBe32((UINTN)&Ddr->Cs1Bnds)));
- DEBUG((EFI_D_INFO, "Cs2Bnds =
+0x%x\n",MmioReadBe32((UINTN)&Ddr->Cs2Bnds)));
- DEBUG((EFI_D_INFO, "Cs3Bnds =
+0x%x\n",MmioReadBe32((UINTN)&Ddr->Cs3Bnds)));
- DEBUG((EFI_D_INFO, "Cs0Config =
+0x%x\n",MmioReadBe32((UINTN)&Ddr->Cs0Config)));
- DEBUG((EFI_D_INFO, "Cs1Config =
+0x%x\n",MmioReadBe32((UINTN)&Ddr->Cs1Config)));
- DEBUG((EFI_D_INFO, "Cs2Config =
+0x%x\n",MmioReadBe32((UINTN)&Ddr->Cs2Config)));
- DEBUG((EFI_D_INFO, "Cs3Config =
+0x%x\n",MmioReadBe32((UINTN)&Ddr->Cs3Config)));
- DEBUG((EFI_D_INFO, "Cs0Config2 =
+0x%x\n",MmioReadBe32((UINTN)&Ddr->Cs0Config2)));
- DEBUG((EFI_D_INFO, "Cs1Config2 =
+0x%x\n",MmioReadBe32((UINTN)&Ddr->Cs1Config2)));
- DEBUG((EFI_D_INFO, "Cs2Config2 =
+0x%x\n",MmioReadBe32((UINTN)&Ddr->Cs2Config2)));
- DEBUG((EFI_D_INFO, "Cs3Config2 =
+0x%x\n",MmioReadBe32((UINTN)&Ddr->Cs3Config2)));
- DEBUG((EFI_D_INFO, "TimingCfg3 =
+0x%x\n",MmioReadBe32((UINTN)&Ddr->TimingCfg3)));
- DEBUG((EFI_D_INFO, "TimingCfg0 =
+0x%x\n",MmioReadBe32((UINTN)&Ddr->TimingCfg0)));
- DEBUG((EFI_D_INFO, "TimingCfg1 =
+0x%x\n",MmioReadBe32((UINTN)&Ddr->TimingCfg1)));
- DEBUG((EFI_D_INFO, "TimingCfg2 =
+0x%x\n",MmioReadBe32((UINTN)&Ddr->TimingCfg2)));
- DEBUG((EFI_D_INFO, "SdramCfg =
+0x%x\n",MmioReadBe32((UINTN)&Ddr->SdramCfg)));
- DEBUG((EFI_D_INFO, "SdramCfg2 =
+0x%x\n",MmioReadBe32((UINTN)&Ddr->SdramCfg2)));
- DEBUG((EFI_D_INFO, "SdramMode =
+0x%x\n",MmioReadBe32((UINTN)&Ddr->SdramMode)));
- DEBUG((EFI_D_INFO, "SdramMode2 =
+0x%x\n",MmioReadBe32((UINTN)&Ddr->SdramMode2)));
- DEBUG((EFI_D_INFO, "SdramMdCntl =
+0x%x\n",MmioReadBe32((UINTN)&Ddr->SdramMdCntl)));
- DEBUG((EFI_D_INFO, "SdramInterval =
+0x%x\n",MmioReadBe32((UINTN)&Ddr->SdramInterval)));
- DEBUG((EFI_D_INFO, "SdramDataInit =
+0x%x\n",MmioReadBe32((UINTN)&Ddr->SdramDataInit)));
- DEBUG((EFI_D_INFO, "SdramClkCntl =
+0x%x\n",MmioReadBe32((UINTN)&Ddr->SdramClkCntl)));
- DEBUG((EFI_D_INFO, "InitAddr =
+0x%x\n",MmioReadBe32((UINTN)&Ddr->InitAddr)));
- DEBUG((EFI_D_INFO, "InitExtAddr =
+0x%x\n",MmioReadBe32((UINTN)&Ddr->InitExtAddr)));
- DEBUG((EFI_D_INFO, "TimingCfg4 =
+0x%x\n",MmioReadBe32((UINTN)&Ddr->TimingCfg4)));
- DEBUG((EFI_D_INFO, "TimingCfg5 =
+0x%x\n",MmioReadBe32((UINTN)&Ddr->TimingCfg5)));
- DEBUG((EFI_D_INFO, "TimingCfg6 =
+0x%x\n",MmioReadBe32((UINTN)&Ddr->TimingCfg6)));
- DEBUG((EFI_D_INFO, "TimingCfg7 =
+0x%x\n",MmioReadBe32((UINTN)&Ddr->TimingCfg7)));
- DEBUG((EFI_D_INFO, "DdrZqCntl =
+0x%x\n",MmioReadBe32((UINTN)&Ddr->DdrZqCntl)));
- DEBUG((EFI_D_INFO, "DdrWrlvlCntl =
+0x%x\n",MmioReadBe32((UINTN)&Ddr->DdrWrlvlCntl)));
- DEBUG((EFI_D_INFO, "DdrSrCntr =
+0x%x\n",MmioReadBe32((UINTN)&Ddr->DdrSrCntr)));
- DEBUG((EFI_D_INFO, "DdrSdramRcw1 =
+0x%x\n",MmioReadBe32((UINTN)&Ddr->DdrSdramRcw1)));
- DEBUG((EFI_D_INFO, "DdrSdramRcw2 =
+0x%x\n",MmioReadBe32((UINTN)&Ddr->DdrSdramRcw2)));
- DEBUG((EFI_D_INFO, "DdrWrlvlCntl2 =
+0x%x\n",MmioReadBe32((UINTN)&Ddr->DdrWrlvlCntl2)));
- DEBUG((EFI_D_INFO, "DdrWrlvlCntl3 =
+0x%x\n",MmioReadBe32((UINTN)&Ddr->DdrWrlvlCntl3)));
- DEBUG((EFI_D_INFO, "DdrSdramRcw3 =
+0x%x\n",MmioReadBe32((UINTN)&Ddr->DdrSdramRcw3)));
- DEBUG((EFI_D_INFO, "DdrSdramRcw4 =
+0x%x\n",MmioReadBe32((UINTN)&Ddr->DdrSdramRcw4)));
- DEBUG((EFI_D_INFO, "DdrSdramRcw5 =
+0x%x\n",MmioReadBe32((UINTN)&Ddr->DdrSdramRcw5)));
- DEBUG((EFI_D_INFO, "DdrSdramRcw6 =
+0x%x\n",MmioReadBe32((UINTN)&Ddr->DdrSdramRcw6)));
- DEBUG((EFI_D_INFO, "SdramMode3 =
+0x%x\n",MmioReadBe32((UINTN)&Ddr->SdramMode3)));
- DEBUG((EFI_D_INFO, "SdramMode4 =
+0x%x\n",MmioReadBe32((UINTN)&Ddr->SdramMode4)));
- DEBUG((EFI_D_INFO, "SdramMode5 =
+0x%x\n",MmioReadBe32((UINTN)&Ddr->SdramMode5)));
- DEBUG((EFI_D_INFO, "SdramMode6 =
+0x%x\n",MmioReadBe32((UINTN)&Ddr->SdramMode6)));
- DEBUG((EFI_D_INFO, "SdramMode7 =
+0x%x\n",MmioReadBe32((UINTN)&Ddr->SdramMode7)));
- DEBUG((EFI_D_INFO, "SdramMode8 =
+0x%x\n",MmioReadBe32((UINTN)&Ddr->SdramMode8)));
- DEBUG((EFI_D_INFO, "SdramMode9 =
+0x%x\n",MmioReadBe32((UINTN)&Ddr->SdramMode9)));
- DEBUG((EFI_D_INFO, "SdramMode10 =
+0x%x\n",MmioReadBe32((UINTN)&Ddr->SdramMode10)));
- DEBUG((EFI_D_INFO, "SdramMode11 =
+0x%x\n",MmioReadBe32((UINTN)&Ddr->SdramMode11)));
- DEBUG((EFI_D_INFO, "SdramMode12 =
+0x%x\n",MmioReadBe32((UINTN)&Ddr->SdramMode12)));
- DEBUG((EFI_D_INFO, "SdramMode13 =
+0x%x\n",MmioReadBe32((UINTN)&Ddr->SdramMode13)));
- DEBUG((EFI_D_INFO, "SdramMode14 =
+0x%x\n",MmioReadBe32((UINTN)&Ddr->SdramMode14)));
- DEBUG((EFI_D_INFO, "SdramMode15 =
+0x%x\n",MmioReadBe32((UINTN)&Ddr->SdramMode15)));
- DEBUG((EFI_D_INFO, "SdramMode16 =
+0x%x\n",MmioReadBe32((UINTN)&Ddr->SdramMode16)));
- DEBUG((EFI_D_INFO, "TimingCfg8 =
+0x%x\n",MmioReadBe32((UINTN)&Ddr->TimingCfg8)));
- DEBUG((EFI_D_INFO, "SdramCfg3 =
+0x%x\n",MmioReadBe32((UINTN)&Ddr->SdramCfg3)));
- DEBUG((EFI_D_INFO, "DqMap0 =
+0x%x\n",MmioReadBe32((UINTN)&Ddr->DqMap0)));
- DEBUG((EFI_D_INFO, "DqMap1 =
+0x%x\n",MmioReadBe32((UINTN)&Ddr->DqMap1)));
- DEBUG((EFI_D_INFO, "DqMap2 =
+0x%x\n",MmioReadBe32((UINTN)&Ddr->DqMap2)));
- DEBUG((EFI_D_INFO, "DqMap3 =
+0x%x\n",MmioReadBe32((UINTN)&Ddr->DqMap3)));
- DEBUG((EFI_D_INFO, "DdrDsr1 =
+0x%x\n",MmioReadBe32((UINTN)&Ddr->DdrDsr1)));
- DEBUG((EFI_D_INFO, "DdrDsr2 =
+0x%x\n",MmioReadBe32((UINTN)&Ddr->DdrDsr2)));
- DEBUG((EFI_D_INFO, "DdrCdr1 =
+0x%x\n",MmioReadBe32((UINTN)&Ddr->DdrCdr1)));
- DEBUG((EFI_D_INFO, "DdrCdr2 =
+0x%x\n",MmioReadBe32((UINTN)&Ddr->DdrCdr2)));
- DEBUG((EFI_D_INFO, "IpRev1 =
+0x%x\n",MmioReadBe32((UINTN)&Ddr->IpRev1)));
- DEBUG((EFI_D_INFO, "IpRev2 =
+0x%x\n",MmioReadBe32((UINTN)&Ddr->IpRev2)));
- DEBUG((EFI_D_INFO, "Eor = 0x%x\n",MmioReadBe32((UINTN)&Ddr-
Eor)));
- DEBUG((EFI_D_INFO, "Mtcr =
+0x%x\n",MmioReadBe32((UINTN)&Ddr->Mtcr)));
- DEBUG((EFI_D_INFO, "Mtp1 =
+0x%x\n",MmioReadBe32((UINTN)&Ddr->Mtp1)));
- DEBUG((EFI_D_INFO, "Mtp2 =
+0x%x\n",MmioReadBe32((UINTN)&Ddr->Mtp2)));
- DEBUG((EFI_D_INFO, "Mtp3 =
+0x%x\n",MmioReadBe32((UINTN)&Ddr->Mtp3)));
- DEBUG((EFI_D_INFO, "Mtp4 =
+0x%x\n",MmioReadBe32((UINTN)&Ddr->Mtp4)));
- DEBUG((EFI_D_INFO, "Mtp5 =
+0x%x\n",MmioReadBe32((UINTN)&Ddr->Mtp5)));
- DEBUG((EFI_D_INFO, "Mtp6 =
+0x%x\n",MmioReadBe32((UINTN)&Ddr->Mtp6)));
- DEBUG((EFI_D_INFO, "Mtp7 =
+0x%x\n",MmioReadBe32((UINTN)&Ddr->Mtp7)));
- DEBUG((EFI_D_INFO, "Mtp8 =
+0x%x\n",MmioReadBe32((UINTN)&Ddr->Mtp8)));
- DEBUG((EFI_D_INFO, "Mtp9 =
+0x%x\n",MmioReadBe32((UINTN)&Ddr->Mtp9)));
- DEBUG((EFI_D_INFO, "Mtp10 =
+0x%x\n",MmioReadBe32((UINTN)&Ddr->Mtp10)));
- DEBUG((EFI_D_INFO, "DataErrInjectHi =
+0x%x\n",MmioReadBe32((UINTN)&Ddr->DataErrInjectHi)));
- DEBUG((EFI_D_INFO, "DataErrInjectLo =
+0x%x\n",MmioReadBe32((UINTN)&Ddr->DataErrInjectLo)));
- DEBUG((EFI_D_INFO, "EccErrInject =
+0x%x\n",MmioReadBe32((UINTN)&Ddr->EccErrInject)));
- DEBUG((EFI_D_INFO, "CaptureDataHi =
+0x%x\n",MmioReadBe32((UINTN)&Ddr->CaptureDataHi)));
- DEBUG((EFI_D_INFO, "CaptureDataLo =
+0x%x\n",MmioReadBe32((UINTN)&Ddr->CaptureDataLo)));
- DEBUG((EFI_D_INFO, "CaptureEcc =
+0x%x\n",MmioReadBe32((UINTN)&Ddr->CaptureEcc)));
- DEBUG((EFI_D_INFO, "ErrDetect =
+0x%x\n",MmioReadBe32((UINTN)&Ddr->ErrDetect)));
- DEBUG((EFI_D_INFO, "ErrDisable =
+0x%x\n",MmioReadBe32((UINTN)&Ddr->ErrDisable)));
- DEBUG((EFI_D_INFO, "ErrIntEn =
+0x%x\n",MmioReadBe32((UINTN)&Ddr->ErrIntEn)));
- DEBUG((EFI_D_INFO, "CaptureAttributes =
+0x%x\n",MmioReadBe32((UINTN)&Ddr->CaptureAttributes)));
- DEBUG((EFI_D_INFO, "CaptureAddress =
+0x%x\n",MmioReadBe32((UINTN)&Ddr->CaptureAddress)));
- DEBUG((EFI_D_INFO, "CaptureExtAddress =
+0x%x\n",MmioReadBe32((UINTN)&Ddr->CaptureExtAddress)));
- DEBUG((EFI_D_INFO, "ErrSbe =
+0x%x\n",MmioReadBe32((UINTN)&Ddr->ErrSbe)));
- DEBUG((EFI_D_ERROR,"\n"));
+}
+/**
- Function to initialize DDR
- **/
+VOID +DramInit (
- )
+{
- struct CcsrDdr *Ddr;
UINT32 Count, Delay = DDRMC_DELAY;
- Ddr = (VOID *)LS1043A_DDR_ADDR;
- MmioWriteBe32((UINTN)&Ddr->SdramCfg, LS1043A_DDR_SDRAM_CFG);
Where is MmioWriteBe32() defined?
I sent a separate patch for ARM IoLib on EDK2 mailing list where we added the support for MmioWriteBe32: https://lists.01.org/pipermail/edk2-devel/2016-October/002791.html
Now that the discussion seems concluded, I will change the patch accordingly.
- MmioWriteBe32((UINTN)&Ddr->Cs0Bnds, LS1043A_CS0_BNDS);
- MmioWriteBe32((UINTN)&Ddr->Cs0Config, LS1043A_CS0_CONFIG);
- MmioWriteBe32((UINTN)&Ddr->TimingCfg0, LS1043A_TIMING_CFG_0);
- MmioWriteBe32((UINTN)&Ddr->TimingCfg1, LS1043A_TIMING_CFG_1);
- MmioWriteBe32((UINTN)&Ddr->TimingCfg2, LS1043A_TIMING_CFG_2);
- MmioWriteBe32((UINTN)&Ddr->TimingCfg3, LS1043A_TIMING_CFG_3);
- MmioWriteBe32((UINTN)&Ddr->TimingCfg4, LS1043A_TIMING_CFG_4);
- MmioWriteBe32((UINTN)&Ddr->TimingCfg5, LS1043A_TIMING_CFG_5);
- MmioWriteBe32((UINTN)&Ddr->TimingCfg7, LS1043A_TIMING_CFG_7);
- MmioWriteBe32((UINTN)&Ddr->TimingCfg8, LS1043A_TIMING_CFG_8);
- MmioWriteBe32((UINTN)&Ddr->SdramCfg2, LS1043A_DDR_SDRAM_CFG_2);
- MmioWriteBe32((UINTN)&Ddr->SdramMode, LS1043A_DDR_SDRAM_MODE);
- MmioWriteBe32((UINTN)&Ddr->SdramMode2, 0);
- MmioWriteBe32((UINTN)&Ddr->SdramInterval,
- LS1043A_DDR_SDRAM_INTERVAL);
- MmioWriteBe32((UINTN)&Ddr->DdrWrlvlCntl, LS1043A_DDR_WRLVL_CNTL);
- MmioWriteBe32((UINTN)&Ddr->DdrWrlvlCntl2,
LS1043A_DDR_WRLVL_CNTL_2);
- MmioWriteBe32((UINTN)&Ddr->DdrWrlvlCntl3, 0);
- MmioWriteBe32((UINTN)&Ddr->DdrCdr1, LS1043A_DDRCDR_1);
- MmioWriteBe32((UINTN)&Ddr->DdrCdr2, LS1043A_DDRCDR_2);
- MmioWriteBe32((UINTN)&Ddr->SdramClkCntl,
- LS1043A_DDR_SDRAM_CLK_CNTL);
- MmioWriteBe32((UINTN)&Ddr->DdrZqCntl, LS1043A_DDR_ZQ_CNTL);
- MmioWriteBe32((UINTN)&Ddr->SdramMode9, LS1043A_DDR_SDRAM_MODE_9);
- MmioWriteBe32((UINTN)&Ddr->SdramMode10, LS1043A_DDR_SDRAM_MODE_10);
- MmioWriteBe32((UINTN)&Ddr->Cs0Config2, 0);
- for(Count = 0; Count < Delay; Count++)
;
- MmioWriteBe32((UINTN)&Ddr->SdramCfg, LS1043A_DDR_SDRAM_CFG
| LS1043A_DDR_SDRAM_CFG_MEM_EN);
- return;
No 'return's add the end of void functions please
Ok.
+} diff --git a/Platforms/Nxp/LS1043aRdb/Library/DdrLib/DdrLib.inf b/Platforms/Nxp/LS1043aRdb/Library/DdrLib/DdrLib.inf new file mode 100644 index 0000000..e8e3aed --- /dev/null +++ b/Platforms/Nxp/LS1043aRdb/Library/DdrLib/DdrLib.inf @@ -0,0 +1,41 @@ +#/** DdrLib.inf +# +# Component description file for DdrLib module # # Copyright (c) +2016, Freescale Semiconductor, Inc. All rights reserved. +# +# This program and the accompanying materials # are licensed and +made available under the terms and conditions of the BSD License # +which accompanies this distribution. The full text of the license +may be found at # http://opensource.org/licenses/bsd-license.php +# +# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" +BASIS, # WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER
EXPRESS OR IMPLIED.
+# +#**/
+[Defines]
- INF_VERSION = 0x00010005
- BASE_NAME = DdrLib
- FILE_GUID = 8ecefc8f-a2c4-4091-b31f-
20f7aeb0567f
Please use a fresh GUID
Ok.
- MODULE_TYPE = BASE
- VERSION_STRING = 1.0
- LIBRARY_CLASS = DdrLib
+[Sources.common]
- DdrLib.c
+[LibraryClasses]
- ArmLib
- IoLib
- BaseMemoryLib
- BaseLib
- SocLib
+[Packages]
- EmbeddedPkg/EmbeddedPkg.dec
- MdePkg/MdePkg.dec
- MdeModulePkg/MdeModulePkg.dec
- ArmPlatformPkg/ArmPlatformPkg.dec
- OpenPlatformPkg/Platforms/Nxp/LS1043aRdb/LS1043aRdbPkg.dec
- OpenPlatformPkg/Chips/Nxp/QoriqLs/NxpQoriqLs.dec
-- 1.9.1
Regards, Bhupesh
On Tue, Oct 18, 2016 at 01:34:01AM +0530, Bhupesh Sharma wrote:
From: Sakar Arora sakar.arora@nxp.com
NXP/FSL's LS1043A RDB board houses 2 GB DDR4 SDRAM.
There is a DDR controller IP which controls access to this SDRAM.
This patch adds a library which allows required initialization of this controller. This library executes out of the XIP NOR flash mememory.
Signed-off-by: Meenakshi Aggarwal meenakshi.aggarwal@nxp.com Signed-off-by: Bhupesh Sharma bhupesh.sharma@nxp.com
Platforms/Nxp/LS1043aRdb/Include/Library/Ddr.h | 190 +++++++++++++++++++++ Platforms/Nxp/LS1043aRdb/Library/DdrLib/DdrLib.c | 188 ++++++++++++++++++++ Platforms/Nxp/LS1043aRdb/Library/DdrLib/DdrLib.inf | 41 +++++ 3 files changed, 419 insertions(+) create mode 100644 Platforms/Nxp/LS1043aRdb/Include/Library/Ddr.h create mode 100644 Platforms/Nxp/LS1043aRdb/Library/DdrLib/DdrLib.c create mode 100644 Platforms/Nxp/LS1043aRdb/Library/DdrLib/DdrLib.inf
diff --git a/Platforms/Nxp/LS1043aRdb/Include/Library/Ddr.h b/Platforms/Nxp/LS1043aRdb/Include/Library/Ddr.h new file mode 100644 index 0000000..0d715fb --- /dev/null +++ b/Platforms/Nxp/LS1043aRdb/Include/Library/Ddr.h @@ -0,0 +1,190 @@ +/** @Ddr.h
- Header defining the Ddr controller constants (Base addresses, sizes, flags),
- function prototype, structures etc
- Copyright (c) 2016, Freescale Semiconductor, Inc. All rights reserved.
- This program and the accompanying materials
- are licensed and made available under the terms and conditions of the BSD License
- which accompanies this distribution. The full text of the license may be found at
- http://opensource.org/licenses/bsd-license.php
- THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
- WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
+**/
+#ifndef __DDR_H__ +#define __DDR_H__
+#include <Library/DebugLib.h> +#include <Library/IoLib.h> +#include <Library/PlatformLib.h>
+/* DDR4 fixed timing */
OK, so I can see by the numbers in the comments column that there is some logical order by which the below is sorted ... but could we have a comment of what?
+#define LS1043A_CS0_BNDS 0x0000007f /* 0x000 */ +#define LS1043A_CS0_CONFIG 0x80010322 /* 0x080 */ +#define LS1043A_TIMING_CFG_3 0x020C1000 /* 0x100 */ +#define LS1043A_TIMING_CFG_0 0xD0550018 /* 0x104 */ +#define LS1043A_TIMING_CFG_1 0xC2C68C42 /* 0x108 */ +#define LS1043A_TIMING_CFG_2 0x0048C114 /* 0x10c */ +#define LS1043A_DDR_SDRAM_CFG 0x450C000C /* 0x110 */ +#define LS1043A_DDR_SDRAM_CFG_2 0x00401010 /* 0x114 */ +#define LS1043A_DDR_SDRAM_MODE 0x01010214 /* 0x118 */ +#define LS1043A_DDR_SDRAM_INTERVAL 0x18600618 /* 0x124 */ +#define LS1043A_DDR_SDRAM_CLK_CNTL 0x02000000 /* 0x130 */ +#define LS1043A_TIMING_CFG_4 0x00000002 /* 0x160 */ +#define LS1043A_TIMING_CFG_5 0x04401400 /* 0x164 */ +#define LS1043A_TIMING_CFG_7 0x13300000 /* 0x16c */ +#define LS1043A_DDR_ZQ_CNTL 0x8A090705 /* 0x170 */ +#define LS1043A_DDR_WRLVL_CNTL 0x8655F606 /* 0x174 */ +#define LS1043A_DDR_WRLVL_CNTL_2 0x05070600 /* 0x190 */ +#define LS1043A_DDR_SDRAM_MODE_9 0x00000400 /* 0x220 */ +#define LS1043A_DDR_SDRAM_MODE_10 0x04000000 /* 0x224 */ +#define LS1043A_TIMING_CFG_8 0x03115600 /* 0x250 */ +#define LS1043A_DDRCDR_1 0x80040000 /* 0xb28 */ +#define LS1043A_DDRCDR_2 0x0000A181 /* 0xb2c */
+#define LS1043A_DDR_SDRAM_CFG_MEM_EN 0x80000000
+/**
- DDR memory controller registers
+**/ +struct CcsrDdr {
- UINT32 Cs0Bnds; /** Chip Select 0 Memory Bounds */
- CHAR8 Res04[4];
Should not all of these by UCHAR8?
- UINT32 Cs1Bnds; /** Chip Select 1 Memory Bounds */
- CHAR8 Res0c[4];
- UINT32 Cs2Bnds; /** Chip Select 2 Memory Bounds */
- CHAR8 Res14[4];
- UINT32 Cs3Bnds; /** Chip Select 3 Memory Bounds */
- CHAR8 Res1c[100];
- UINT32 Cs0Config; /** Chip Select Configuration */
- UINT32 Cs1Config; /** Chip Select Configuration */
- UINT32 Cs2Config; /** Chip Select Configuration */
- UINT32 Cs3Config; /** Chip Select Configuration */
- CHAR8 Res90[48];
- UINT32 Cs0Config2; /** Chip Select Configuration 2 */
- UINT32 Cs1Config2; /** Chip Select Configuration 2 */
- UINT32 Cs2Config2; /** Chip Select Configuration 2 */
- UINT32 Cs3Config2; /** Chip Select Configuration 2 */
- CHAR8 Resd0[48];
- UINT32 TimingCfg3; /** SDRAM Timing Configuration 3 */
- UINT32 TimingCfg0; /** SDRAM Timing Configuration 0 */
- UINT32 TimingCfg1; /** SDRAM Timing Configuration 1 */
- UINT32 TimingCfg2; /** SDRAM Timing Configuration 2 */
- UINT32 SdramCfg; /** SDRAM Control Configuration */
- UINT32 SdramCfg2; /** SDRAM Control Configuration 2 */
- UINT32 SdramMode; /** SDRAM Mode Configuration */
- UINT32 SdramMode2; /** SDRAM Mode Configuration 2 */
- UINT32 SdramMdCntl; /** SDRAM Mode Control */
- UINT32 SdramInterval; /** SDRAM Interval Configuration */
- UINT32 SdramDataInit; /** SDRAM Data initialization */
- CHAR8 Res12c[4];
- UINT32 SdramClkCntl; /** SDRAM Clock Control */
- CHAR8 Res134[20];
- UINT32 InitAddr; /** training init addr */
- UINT32 InitExtAddr; /** training init extended addr */
- CHAR8 Res150[16];
- UINT32 TimingCfg4; /** SDRAM Timing Configuration 4 */
- UINT32 TimingCfg5; /** SDRAM Timing Configuration 5 */
- UINT32 TimingCfg6; /** SDRAM Timing Configuration 6 */
- UINT32 TimingCfg7; /** SDRAM Timing Configuration 7 */
- UINT32 DdrZqCntl; /** ZQ calibration control*/
- UINT32 DdrWrlvlCntl; /** write leveling control*/
- CHAR8 Reg178[4];
- UINT32 DdrSrCntr; /** self refresh counter */
- UINT32 DdrSdramRcw1; /** Control Words 1 */
- UINT32 DdrSdramRcw2; /** Control Words 2 */
- CHAR8 Reg188[8];
- UINT32 DdrWrlvlCntl2; /** write leveling control 2 */
- UINT32 DdrWrlvlCntl3; /** write leveling control 3 */
- CHAR8 Res198[8];
- UINT32 DdrSdramRcw3;
- UINT32 DdrSdramRcw4;
- UINT32 DdrSdramRcw5;
- UINT32 DdrSdramRcw6;
- CHAR8 Res1b0[80];
- UINT32 SdramMode3; /** SDRAM Mode Configuration 3 */
- UINT32 SdramMode4; /** SDRAM Mode Configuration 4 */
- UINT32 SdramMode5; /** SDRAM Mode Configuration 5 */
- UINT32 SdramMode6; /** SDRAM Mode Configuration 6 */
- UINT32 SdramMode7; /** SDRAM Mode Configuration 7 */
- UINT32 SdramMode8; /** SDRAM Mode Configuration 8 */
- CHAR8 Res218[8];
- UINT32 SdramMode9; /** SDRAM Mode Configuration 9 */
- UINT32 SdramMode10; /** SDRAM Mode Configuration 10 */
- UINT32 SdramMode11; /** SDRAM Mode Configuration 11 */
- UINT32 SdramMode12; /** SDRAM Mode Configuration 12 */
- UINT32 SdramMode13; /** SDRAM Mode Configuration 13 */
- UINT32 SdramMode14; /** SDRAM Mode Configuration 14 */
- UINT32 SdramMode15; /** SDRAM Mode Configuration 15 */
- UINT32 SdramMode16; /** SDRAM Mode Configuration 16 */
- CHAR8 Res240[16];
- UINT32 TimingCfg8; /* SDRAM Timing Configuration 8 */
- CHAR8 Res254[12];
- UINT32 SdramCfg3;
- CHAR8 Res264[412];
- UINT32 DqMap0;
- UINT32 DqMap1;
- UINT32 DqMap2;
- UINT32 DqMap3;
- CHAR8 Res410[1808];
- UINT32 DdrDsr1; /** Debug Status 1 */
- UINT32 DdrDsr2; /** Debug Status 2 */
- UINT32 DdrCdr1; /** Control Driver 1 */
- UINT32 DdrCdr2; /** Control Driver 2 */
- CHAR8 ResB30[200];
- UINT32 IpRev1; /** IP Block Revision 1 */
- UINT32 IpRev2; /** IP Block Revision 2 */
- UINT32 Eor; /** Enhanced Optimization Register */
- CHAR8 ResC04[252];
- UINT32 Mtcr; /** Memory Test Control Register */
- CHAR8 ResD04[28];
- UINT32 Mtp1; /** Memory Test Pattern 1 */
- UINT32 Mtp2; /** Memory Test Pattern 2 */
- UINT32 Mtp3; /** Memory Test Pattern 3 */
- UINT32 Mtp4; /** Memory Test Pattern 4 */
- UINT32 Mtp5; /** Memory Test Pattern 5 */
- UINT32 Mtp6; /** Memory Test Pattern 6 */
- UINT32 Mtp7; /** Memory Test Pattern 7 */
- UINT32 Mtp8; /** Memory Test Pattern 8 */
- UINT32 Mtp9; /** Memory Test Pattern 9 */
- UINT32 Mtp10; /** Memory Test Pattern 10 */
- CHAR8 ResD48[184];
- UINT32 DataErrInjectHi; /** Data Path Err Injection Mask High */
- UINT32 DataErrInjectLo; /** Data Path Err Injection Mask Low */
- UINT32 EccErrInject; /** Data Path Err Injection Mask ECC */
- CHAR8 ResE0c[20];
- UINT32 CaptureDataHi; /** Data Path Read Capture High */
- UINT32 CaptureDataLo; /** Data Path Read Capture Low */
- UINT32 CaptureEcc; /** Data Path Read Capture ECC */
- CHAR8 ResE2c[20];
- UINT32 ErrDetect; /** Error Detect */
- UINT32 ErrDisable; /** Error Disable */
- UINT32 ErrIntEn;
- UINT32 CaptureAttributes; /** Error Attrs Capture */
- UINT32 CaptureAddress; /** Error Addr Capture */
- UINT32 CaptureExtAddress; /** Error Extended Addr Capture */
- UINT32 ErrSbe; /** Single-Bit ECC Error Management */
- CHAR8 ResE5c[164];
- UINT32 Debug[32]; /** Debug_1 to Debug_32 */
- CHAR8 ResF80[128];
+};
+/**
- Main function to initialize DDR
- **/
+VOID +DramInit(
- );
+/**
- Function to dump DDRC registers
+**/ +VOID +DdrRegDump (
- VOID
- );
+#endif diff --git a/Platforms/Nxp/LS1043aRdb/Library/DdrLib/DdrLib.c b/Platforms/Nxp/LS1043aRdb/Library/DdrLib/DdrLib.c new file mode 100644 index 0000000..1c33de4 --- /dev/null +++ b/Platforms/Nxp/LS1043aRdb/Library/DdrLib/DdrLib.c @@ -0,0 +1,188 @@ +/** @DdrLib.c
- Ddr Library containing functions to initialize ddr controller
- Copyright (c) 2016, Freescale Semiconductor, Inc. All rights reserved.
- This program and the accompanying materials
- are licensed and made available under the terms and conditions of the BSD License
- which accompanies this distribution. The full text of the license may be found at
- http://opensource.org/licenses/bsd-license.php
- THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
- WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
+**/
+#include <Library/Ddr.h> +#include <Library/BaseLib.h>
+#define Uswap32(X) \
Use SwapBytes32 instead?
((((X) & 0xff000000) >> 24) | \
(((X) & 0x00ff0000) >> 8) | \
(((X) & 0x0000ff00) << 8) | \
(((X) & 0x000000ff) << 24))
+#define DDRMC_DELAY 10000
10000 what?
+/**
- Function to dump DDRC registers
+**/
+VOID +DdrRegDump (
- VOID
- )
+{
- struct CcsrDdr *Ddr = (VOID *)LS1043A_DDR_ADDR;
- DEBUG((EFI_D_INFO, "Cs0Bnds = 0x%x\n",MmioReadBe32((UINTN)&Ddr->Cs0Bnds)));
These all need a space after comma. Hmm, I get a bit nervous about those MmioReadBe32 though... Because struct CcsrDdr is defined as a little-endian structure. Too feel more comfortable, I would like to have a comment at the structure definition explaining why this is, and for what reasons this is not problematic.
- DEBUG((EFI_D_INFO, "Cs1Bnds = 0x%x\n",MmioReadBe32((UINTN)&Ddr->Cs1Bnds)));
Also ... this would be a lot cleaner as a macro: #define DUMP_DDR_REG(X, Y) \ DEBUG((EFI_D_INFO, "%s = 0x%x\n", #Y, MmioReadBe32((UINTN)&X->Y))) And called as: DUMP_DDR_REG(Ddr, Cs1Bnds);
Although I think it would be worth looking into checking current debug level before calling this function rather than for every register to be dumped.
- DEBUG((EFI_D_INFO, "Cs2Bnds = 0x%x\n",MmioReadBe32((UINTN)&Ddr->Cs2Bnds)));
- DEBUG((EFI_D_INFO, "Cs3Bnds = 0x%x\n",MmioReadBe32((UINTN)&Ddr->Cs3Bnds)));
- DEBUG((EFI_D_INFO, "Cs0Config = 0x%x\n",MmioReadBe32((UINTN)&Ddr->Cs0Config)));
- DEBUG((EFI_D_INFO, "Cs1Config = 0x%x\n",MmioReadBe32((UINTN)&Ddr->Cs1Config)));
- DEBUG((EFI_D_INFO, "Cs2Config = 0x%x\n",MmioReadBe32((UINTN)&Ddr->Cs2Config)));
- DEBUG((EFI_D_INFO, "Cs3Config = 0x%x\n",MmioReadBe32((UINTN)&Ddr->Cs3Config)));
- DEBUG((EFI_D_INFO, "Cs0Config2 = 0x%x\n",MmioReadBe32((UINTN)&Ddr->Cs0Config2)));
- DEBUG((EFI_D_INFO, "Cs1Config2 = 0x%x\n",MmioReadBe32((UINTN)&Ddr->Cs1Config2)));
- DEBUG((EFI_D_INFO, "Cs2Config2 = 0x%x\n",MmioReadBe32((UINTN)&Ddr->Cs2Config2)));
- DEBUG((EFI_D_INFO, "Cs3Config2 = 0x%x\n",MmioReadBe32((UINTN)&Ddr->Cs3Config2)));
- DEBUG((EFI_D_INFO, "TimingCfg3 = 0x%x\n",MmioReadBe32((UINTN)&Ddr->TimingCfg3)));
- DEBUG((EFI_D_INFO, "TimingCfg0 = 0x%x\n",MmioReadBe32((UINTN)&Ddr->TimingCfg0)));
- DEBUG((EFI_D_INFO, "TimingCfg1 = 0x%x\n",MmioReadBe32((UINTN)&Ddr->TimingCfg1)));
- DEBUG((EFI_D_INFO, "TimingCfg2 = 0x%x\n",MmioReadBe32((UINTN)&Ddr->TimingCfg2)));
- DEBUG((EFI_D_INFO, "SdramCfg = 0x%x\n",MmioReadBe32((UINTN)&Ddr->SdramCfg)));
- DEBUG((EFI_D_INFO, "SdramCfg2 = 0x%x\n",MmioReadBe32((UINTN)&Ddr->SdramCfg2)));
- DEBUG((EFI_D_INFO, "SdramMode = 0x%x\n",MmioReadBe32((UINTN)&Ddr->SdramMode)));
- DEBUG((EFI_D_INFO, "SdramMode2 = 0x%x\n",MmioReadBe32((UINTN)&Ddr->SdramMode2)));
- DEBUG((EFI_D_INFO, "SdramMdCntl = 0x%x\n",MmioReadBe32((UINTN)&Ddr->SdramMdCntl)));
- DEBUG((EFI_D_INFO, "SdramInterval = 0x%x\n",MmioReadBe32((UINTN)&Ddr->SdramInterval)));
- DEBUG((EFI_D_INFO, "SdramDataInit = 0x%x\n",MmioReadBe32((UINTN)&Ddr->SdramDataInit)));
- DEBUG((EFI_D_INFO, "SdramClkCntl = 0x%x\n",MmioReadBe32((UINTN)&Ddr->SdramClkCntl)));
- DEBUG((EFI_D_INFO, "InitAddr = 0x%x\n",MmioReadBe32((UINTN)&Ddr->InitAddr)));
- DEBUG((EFI_D_INFO, "InitExtAddr = 0x%x\n",MmioReadBe32((UINTN)&Ddr->InitExtAddr)));
- DEBUG((EFI_D_INFO, "TimingCfg4 = 0x%x\n",MmioReadBe32((UINTN)&Ddr->TimingCfg4)));
- DEBUG((EFI_D_INFO, "TimingCfg5 = 0x%x\n",MmioReadBe32((UINTN)&Ddr->TimingCfg5)));
- DEBUG((EFI_D_INFO, "TimingCfg6 = 0x%x\n",MmioReadBe32((UINTN)&Ddr->TimingCfg6)));
- DEBUG((EFI_D_INFO, "TimingCfg7 = 0x%x\n",MmioReadBe32((UINTN)&Ddr->TimingCfg7)));
- DEBUG((EFI_D_INFO, "DdrZqCntl = 0x%x\n",MmioReadBe32((UINTN)&Ddr->DdrZqCntl)));
- DEBUG((EFI_D_INFO, "DdrWrlvlCntl = 0x%x\n",MmioReadBe32((UINTN)&Ddr->DdrWrlvlCntl)));
- DEBUG((EFI_D_INFO, "DdrSrCntr = 0x%x\n",MmioReadBe32((UINTN)&Ddr->DdrSrCntr)));
- DEBUG((EFI_D_INFO, "DdrSdramRcw1 = 0x%x\n",MmioReadBe32((UINTN)&Ddr->DdrSdramRcw1)));
- DEBUG((EFI_D_INFO, "DdrSdramRcw2 = 0x%x\n",MmioReadBe32((UINTN)&Ddr->DdrSdramRcw2)));
- DEBUG((EFI_D_INFO, "DdrWrlvlCntl2 = 0x%x\n",MmioReadBe32((UINTN)&Ddr->DdrWrlvlCntl2)));
- DEBUG((EFI_D_INFO, "DdrWrlvlCntl3 = 0x%x\n",MmioReadBe32((UINTN)&Ddr->DdrWrlvlCntl3)));
- DEBUG((EFI_D_INFO, "DdrSdramRcw3 = 0x%x\n",MmioReadBe32((UINTN)&Ddr->DdrSdramRcw3)));
- DEBUG((EFI_D_INFO, "DdrSdramRcw4 = 0x%x\n",MmioReadBe32((UINTN)&Ddr->DdrSdramRcw4)));
- DEBUG((EFI_D_INFO, "DdrSdramRcw5 = 0x%x\n",MmioReadBe32((UINTN)&Ddr->DdrSdramRcw5)));
- DEBUG((EFI_D_INFO, "DdrSdramRcw6 = 0x%x\n",MmioReadBe32((UINTN)&Ddr->DdrSdramRcw6)));
- DEBUG((EFI_D_INFO, "SdramMode3 = 0x%x\n",MmioReadBe32((UINTN)&Ddr->SdramMode3)));
- DEBUG((EFI_D_INFO, "SdramMode4 = 0x%x\n",MmioReadBe32((UINTN)&Ddr->SdramMode4)));
- DEBUG((EFI_D_INFO, "SdramMode5 = 0x%x\n",MmioReadBe32((UINTN)&Ddr->SdramMode5)));
- DEBUG((EFI_D_INFO, "SdramMode6 = 0x%x\n",MmioReadBe32((UINTN)&Ddr->SdramMode6)));
- DEBUG((EFI_D_INFO, "SdramMode7 = 0x%x\n",MmioReadBe32((UINTN)&Ddr->SdramMode7)));
- DEBUG((EFI_D_INFO, "SdramMode8 = 0x%x\n",MmioReadBe32((UINTN)&Ddr->SdramMode8)));
- DEBUG((EFI_D_INFO, "SdramMode9 = 0x%x\n",MmioReadBe32((UINTN)&Ddr->SdramMode9)));
- DEBUG((EFI_D_INFO, "SdramMode10 = 0x%x\n",MmioReadBe32((UINTN)&Ddr->SdramMode10)));
- DEBUG((EFI_D_INFO, "SdramMode11 = 0x%x\n",MmioReadBe32((UINTN)&Ddr->SdramMode11)));
- DEBUG((EFI_D_INFO, "SdramMode12 = 0x%x\n",MmioReadBe32((UINTN)&Ddr->SdramMode12)));
- DEBUG((EFI_D_INFO, "SdramMode13 = 0x%x\n",MmioReadBe32((UINTN)&Ddr->SdramMode13)));
- DEBUG((EFI_D_INFO, "SdramMode14 = 0x%x\n",MmioReadBe32((UINTN)&Ddr->SdramMode14)));
- DEBUG((EFI_D_INFO, "SdramMode15 = 0x%x\n",MmioReadBe32((UINTN)&Ddr->SdramMode15)));
- DEBUG((EFI_D_INFO, "SdramMode16 = 0x%x\n",MmioReadBe32((UINTN)&Ddr->SdramMode16)));
- DEBUG((EFI_D_INFO, "TimingCfg8 = 0x%x\n",MmioReadBe32((UINTN)&Ddr->TimingCfg8)));
- DEBUG((EFI_D_INFO, "SdramCfg3 = 0x%x\n",MmioReadBe32((UINTN)&Ddr->SdramCfg3)));
- DEBUG((EFI_D_INFO, "DqMap0 = 0x%x\n",MmioReadBe32((UINTN)&Ddr->DqMap0)));
- DEBUG((EFI_D_INFO, "DqMap1 = 0x%x\n",MmioReadBe32((UINTN)&Ddr->DqMap1)));
- DEBUG((EFI_D_INFO, "DqMap2 = 0x%x\n",MmioReadBe32((UINTN)&Ddr->DqMap2)));
- DEBUG((EFI_D_INFO, "DqMap3 = 0x%x\n",MmioReadBe32((UINTN)&Ddr->DqMap3)));
- DEBUG((EFI_D_INFO, "DdrDsr1 = 0x%x\n",MmioReadBe32((UINTN)&Ddr->DdrDsr1)));
- DEBUG((EFI_D_INFO, "DdrDsr2 = 0x%x\n",MmioReadBe32((UINTN)&Ddr->DdrDsr2)));
- DEBUG((EFI_D_INFO, "DdrCdr1 = 0x%x\n",MmioReadBe32((UINTN)&Ddr->DdrCdr1)));
- DEBUG((EFI_D_INFO, "DdrCdr2 = 0x%x\n",MmioReadBe32((UINTN)&Ddr->DdrCdr2)));
- DEBUG((EFI_D_INFO, "IpRev1 = 0x%x\n",MmioReadBe32((UINTN)&Ddr->IpRev1)));
- DEBUG((EFI_D_INFO, "IpRev2 = 0x%x\n",MmioReadBe32((UINTN)&Ddr->IpRev2)));
- DEBUG((EFI_D_INFO, "Eor = 0x%x\n",MmioReadBe32((UINTN)&Ddr->Eor)));
- DEBUG((EFI_D_INFO, "Mtcr = 0x%x\n",MmioReadBe32((UINTN)&Ddr->Mtcr)));
- DEBUG((EFI_D_INFO, "Mtp1 = 0x%x\n",MmioReadBe32((UINTN)&Ddr->Mtp1)));
- DEBUG((EFI_D_INFO, "Mtp2 = 0x%x\n",MmioReadBe32((UINTN)&Ddr->Mtp2)));
- DEBUG((EFI_D_INFO, "Mtp3 = 0x%x\n",MmioReadBe32((UINTN)&Ddr->Mtp3)));
- DEBUG((EFI_D_INFO, "Mtp4 = 0x%x\n",MmioReadBe32((UINTN)&Ddr->Mtp4)));
- DEBUG((EFI_D_INFO, "Mtp5 = 0x%x\n",MmioReadBe32((UINTN)&Ddr->Mtp5)));
- DEBUG((EFI_D_INFO, "Mtp6 = 0x%x\n",MmioReadBe32((UINTN)&Ddr->Mtp6)));
- DEBUG((EFI_D_INFO, "Mtp7 = 0x%x\n",MmioReadBe32((UINTN)&Ddr->Mtp7)));
- DEBUG((EFI_D_INFO, "Mtp8 = 0x%x\n",MmioReadBe32((UINTN)&Ddr->Mtp8)));
- DEBUG((EFI_D_INFO, "Mtp9 = 0x%x\n",MmioReadBe32((UINTN)&Ddr->Mtp9)));
- DEBUG((EFI_D_INFO, "Mtp10 = 0x%x\n",MmioReadBe32((UINTN)&Ddr->Mtp10)));
- DEBUG((EFI_D_INFO, "DataErrInjectHi = 0x%x\n",MmioReadBe32((UINTN)&Ddr->DataErrInjectHi)));
- DEBUG((EFI_D_INFO, "DataErrInjectLo = 0x%x\n",MmioReadBe32((UINTN)&Ddr->DataErrInjectLo)));
- DEBUG((EFI_D_INFO, "EccErrInject = 0x%x\n",MmioReadBe32((UINTN)&Ddr->EccErrInject)));
- DEBUG((EFI_D_INFO, "CaptureDataHi = 0x%x\n",MmioReadBe32((UINTN)&Ddr->CaptureDataHi)));
- DEBUG((EFI_D_INFO, "CaptureDataLo = 0x%x\n",MmioReadBe32((UINTN)&Ddr->CaptureDataLo)));
- DEBUG((EFI_D_INFO, "CaptureEcc = 0x%x\n",MmioReadBe32((UINTN)&Ddr->CaptureEcc)));
- DEBUG((EFI_D_INFO, "ErrDetect = 0x%x\n",MmioReadBe32((UINTN)&Ddr->ErrDetect)));
- DEBUG((EFI_D_INFO, "ErrDisable = 0x%x\n",MmioReadBe32((UINTN)&Ddr->ErrDisable)));
- DEBUG((EFI_D_INFO, "ErrIntEn = 0x%x\n",MmioReadBe32((UINTN)&Ddr->ErrIntEn)));
- DEBUG((EFI_D_INFO, "CaptureAttributes = 0x%x\n",MmioReadBe32((UINTN)&Ddr->CaptureAttributes)));
- DEBUG((EFI_D_INFO, "CaptureAddress = 0x%x\n",MmioReadBe32((UINTN)&Ddr->CaptureAddress)));
- DEBUG((EFI_D_INFO, "CaptureExtAddress = 0x%x\n",MmioReadBe32((UINTN)&Ddr->CaptureExtAddress)));
- DEBUG((EFI_D_INFO, "ErrSbe = 0x%x\n",MmioReadBe32((UINTN)&Ddr->ErrSbe)));
- DEBUG((EFI_D_ERROR,"\n"));
Why the final _ERROR?
+}
+/**
- Function to initialize DDR
- **/
+VOID +DramInit (
- )
+{
- struct CcsrDdr *Ddr;
- UINT32 Count, Delay = DDRMC_DELAY;
- Ddr = (VOID *)LS1043A_DDR_ADDR;
- MmioWriteBe32((UINTN)&Ddr->SdramCfg, LS1043A_DDR_SDRAM_CFG);
- MmioWriteBe32((UINTN)&Ddr->Cs0Bnds, LS1043A_CS0_BNDS);
- MmioWriteBe32((UINTN)&Ddr->Cs0Config, LS1043A_CS0_CONFIG);
- MmioWriteBe32((UINTN)&Ddr->TimingCfg0, LS1043A_TIMING_CFG_0);
- MmioWriteBe32((UINTN)&Ddr->TimingCfg1, LS1043A_TIMING_CFG_1);
- MmioWriteBe32((UINTN)&Ddr->TimingCfg2, LS1043A_TIMING_CFG_2);
- MmioWriteBe32((UINTN)&Ddr->TimingCfg3, LS1043A_TIMING_CFG_3);
- MmioWriteBe32((UINTN)&Ddr->TimingCfg4, LS1043A_TIMING_CFG_4);
- MmioWriteBe32((UINTN)&Ddr->TimingCfg5, LS1043A_TIMING_CFG_5);
- MmioWriteBe32((UINTN)&Ddr->TimingCfg7, LS1043A_TIMING_CFG_7);
- MmioWriteBe32((UINTN)&Ddr->TimingCfg8, LS1043A_TIMING_CFG_8);
- MmioWriteBe32((UINTN)&Ddr->SdramCfg2, LS1043A_DDR_SDRAM_CFG_2);
- MmioWriteBe32((UINTN)&Ddr->SdramMode, LS1043A_DDR_SDRAM_MODE);
- MmioWriteBe32((UINTN)&Ddr->SdramMode2, 0);
- MmioWriteBe32((UINTN)&Ddr->SdramInterval, LS1043A_DDR_SDRAM_INTERVAL);
- MmioWriteBe32((UINTN)&Ddr->DdrWrlvlCntl, LS1043A_DDR_WRLVL_CNTL);
- MmioWriteBe32((UINTN)&Ddr->DdrWrlvlCntl2, LS1043A_DDR_WRLVL_CNTL_2);
- MmioWriteBe32((UINTN)&Ddr->DdrWrlvlCntl3, 0);
- MmioWriteBe32((UINTN)&Ddr->DdrCdr1, LS1043A_DDRCDR_1);
- MmioWriteBe32((UINTN)&Ddr->DdrCdr2, LS1043A_DDRCDR_2);
- MmioWriteBe32((UINTN)&Ddr->SdramClkCntl, LS1043A_DDR_SDRAM_CLK_CNTL);
- MmioWriteBe32((UINTN)&Ddr->DdrZqCntl, LS1043A_DDR_ZQ_CNTL);
- MmioWriteBe32((UINTN)&Ddr->SdramMode9, LS1043A_DDR_SDRAM_MODE_9);
- MmioWriteBe32((UINTN)&Ddr->SdramMode10, LS1043A_DDR_SDRAM_MODE_10);
- MmioWriteBe32((UINTN)&Ddr->Cs0Config2, 0);
- for(Count = 0; Count < Delay; Count++)
;
If we are waiting for some operation to take effect, then we badly need at least a MemoryBarrier() here. And if we do, do we still need the delay? If we do need a delay, it is much preferable to use something like gBs->Stall(), or MicroSecondDelay() than just an empty loop.
- MmioWriteBe32((UINTN)&Ddr->SdramCfg, LS1043A_DDR_SDRAM_CFG
| LS1043A_DDR_SDRAM_CFG_MEM_EN);
- return;
+} diff --git a/Platforms/Nxp/LS1043aRdb/Library/DdrLib/DdrLib.inf b/Platforms/Nxp/LS1043aRdb/Library/DdrLib/DdrLib.inf new file mode 100644 index 0000000..e8e3aed --- /dev/null +++ b/Platforms/Nxp/LS1043aRdb/Library/DdrLib/DdrLib.inf @@ -0,0 +1,41 @@ +#/** DdrLib.inf +# +# Component description file for DdrLib module +# +# Copyright (c) 2016, Freescale Semiconductor, Inc. All rights reserved. +# +# This program and the accompanying materials +# are licensed and made available under the terms and conditions of the BSD License +# which accompanies this distribution. The full text of the license may be found at +# http://opensource.org/licenses/bsd-license.php +# +# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, +# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. +# +#**/
+[Defines]
- INF_VERSION = 0x00010005
0x00010019 if we're following V1.25 of the specification, as published at https://github.com/tianocore/tianocore.github.io/wiki/EDK-II-Specifications
- BASE_NAME = DdrLib
- FILE_GUID = 8ecefc8f-a2c4-4091-b31f-20f7aeb0567f
- MODULE_TYPE = BASE
- VERSION_STRING = 1.0
- LIBRARY_CLASS = DdrLib
+[Sources.common]
- DdrLib.c
+[LibraryClasses]
- ArmLib
- IoLib
- BaseMemoryLib
- BaseLib
- SocLib
+[Packages]
- EmbeddedPkg/EmbeddedPkg.dec
- MdePkg/MdePkg.dec
- MdeModulePkg/MdeModulePkg.dec
- ArmPlatformPkg/ArmPlatformPkg.dec
- OpenPlatformPkg/Platforms/Nxp/LS1043aRdb/LS1043aRdbPkg.dec
- OpenPlatformPkg/Chips/Nxp/QoriqLs/NxpQoriqLs.dec
OCD sorting, please?
-- 1.9.1
Hi Leif,
Thanks for your review.
From: Leif Lindholm [mailto:leif.lindholm@linaro.org] Sent: Monday, October 24, 2016 8:01 PM
On Tue, Oct 18, 2016 at 01:34:01AM +0530, Bhupesh Sharma wrote:
From: Sakar Arora sakar.arora@nxp.com
NXP/FSL's LS1043A RDB board houses 2 GB DDR4 SDRAM.
There is a DDR controller IP which controls access to this SDRAM.
This patch adds a library which allows required initialization of
this
controller. This library executes out of the XIP NOR flash mememory.
Signed-off-by: Meenakshi Aggarwal meenakshi.aggarwal@nxp.com Signed-off-by: Bhupesh Sharma bhupesh.sharma@nxp.com
Platforms/Nxp/LS1043aRdb/Include/Library/Ddr.h | 190
+++++++++++++++++++++
Platforms/Nxp/LS1043aRdb/Library/DdrLib/DdrLib.c | 188
++++++++++++++++++++
Platforms/Nxp/LS1043aRdb/Library/DdrLib/DdrLib.inf | 41 +++++ 3 files changed, 419 insertions(+) create mode 100644 Platforms/Nxp/LS1043aRdb/Include/Library/Ddr.h create mode 100644 Platforms/Nxp/LS1043aRdb/Library/DdrLib/DdrLib.c create mode 100644
Platforms/Nxp/LS1043aRdb/Library/DdrLib/DdrLib.inf
diff --git a/Platforms/Nxp/LS1043aRdb/Include/Library/Ddr.h b/Platforms/Nxp/LS1043aRdb/Include/Library/Ddr.h new file mode 100644 index 0000000..0d715fb --- /dev/null +++ b/Platforms/Nxp/LS1043aRdb/Include/Library/Ddr.h @@ -0,0 +1,190 @@ +/** @Ddr.h
- Header defining the Ddr controller constants (Base addresses,
+sizes, flags),
- function prototype, structures etc
- Copyright (c) 2016, Freescale Semiconductor, Inc. All rights
reserved.
- This program and the accompanying materials are licensed and made
- available under the terms and conditions of the BSD License which
- accompanies this distribution. The full text of the license may be
- found at http://opensource.org/licenses/bsd-license.php
- THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS"
- BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER
EXPRESS OR IMPLIED.
+**/
+#ifndef __DDR_H__ +#define __DDR_H__
+#include <Library/DebugLib.h> +#include <Library/IoLib.h> +#include <Library/PlatformLib.h>
+/* DDR4 fixed timing */
OK, so I can see by the numbers in the comments column that there is some logical order by which the below is sorted ... but could we have a comment of what?
Sure, will add that in V2.
+#define LS1043A_CS0_BNDS 0x0000007f /* 0x000 */ +#define LS1043A_CS0_CONFIG 0x80010322 /* 0x080 */ +#define LS1043A_TIMING_CFG_3 0x020C1000 /* 0x100 */ +#define LS1043A_TIMING_CFG_0 0xD0550018 /* 0x104 */ +#define LS1043A_TIMING_CFG_1 0xC2C68C42 /* 0x108 */ +#define LS1043A_TIMING_CFG_2 0x0048C114 /* 0x10c */ +#define LS1043A_DDR_SDRAM_CFG 0x450C000C /* 0x110 */ +#define LS1043A_DDR_SDRAM_CFG_2 0x00401010 /* 0x114 */ +#define LS1043A_DDR_SDRAM_MODE 0x01010214 /* 0x118 */ +#define LS1043A_DDR_SDRAM_INTERVAL 0x18600618 /* 0x124 */ +#define LS1043A_DDR_SDRAM_CLK_CNTL 0x02000000 /* 0x130 */ +#define LS1043A_TIMING_CFG_4 0x00000002 /* 0x160 */ +#define LS1043A_TIMING_CFG_5 0x04401400 /* 0x164 */ +#define LS1043A_TIMING_CFG_7 0x13300000 /* 0x16c */ +#define LS1043A_DDR_ZQ_CNTL 0x8A090705 /* 0x170 */ +#define LS1043A_DDR_WRLVL_CNTL 0x8655F606 /* 0x174 */ +#define LS1043A_DDR_WRLVL_CNTL_2 0x05070600 /* 0x190 */ +#define LS1043A_DDR_SDRAM_MODE_9 0x00000400 /* 0x220 */ +#define LS1043A_DDR_SDRAM_MODE_10 0x04000000 /* 0x224 */ +#define LS1043A_TIMING_CFG_8 0x03115600 /* 0x250 */ +#define LS1043A_DDRCDR_1 0x80040000 /* 0xb28 */ +#define LS1043A_DDRCDR_2 0x0000A181 /* 0xb2c */
+#define LS1043A_DDR_SDRAM_CFG_MEM_EN 0x80000000
+/**
- DDR memory controller registers
+**/ +struct CcsrDdr {
- UINT32 Cs0Bnds; /** Chip Select 0 Memory Bounds */
- CHAR8 Res04[4];
Should not all of these by UCHAR8?
Ok, will change that in V2.
- UINT32 Cs1Bnds; /** Chip Select 1 Memory Bounds */
- CHAR8 Res0c[4];
- UINT32 Cs2Bnds; /** Chip Select 2 Memory Bounds */
- CHAR8 Res14[4];
- UINT32 Cs3Bnds; /** Chip Select 3 Memory Bounds */
- CHAR8 Res1c[100];
- UINT32 Cs0Config; /** Chip Select Configuration */
- UINT32 Cs1Config; /** Chip Select Configuration */
- UINT32 Cs2Config; /** Chip Select Configuration */
- UINT32 Cs3Config; /** Chip Select Configuration */
- CHAR8 Res90[48];
- UINT32 Cs0Config2; /** Chip Select Configuration 2 */
- UINT32 Cs1Config2; /** Chip Select Configuration 2 */
- UINT32 Cs2Config2; /** Chip Select Configuration 2 */
- UINT32 Cs3Config2; /** Chip Select Configuration 2 */
- CHAR8 Resd0[48];
- UINT32 TimingCfg3; /** SDRAM Timing Configuration 3 */
- UINT32 TimingCfg0; /** SDRAM Timing Configuration 0 */
- UINT32 TimingCfg1; /** SDRAM Timing Configuration 1 */
- UINT32 TimingCfg2; /** SDRAM Timing Configuration 2 */
- UINT32 SdramCfg; /** SDRAM Control Configuration */
- UINT32 SdramCfg2; /** SDRAM Control Configuration 2 */
- UINT32 SdramMode; /** SDRAM Mode Configuration */
- UINT32 SdramMode2; /** SDRAM Mode Configuration 2 */
- UINT32 SdramMdCntl; /** SDRAM Mode Control */
- UINT32 SdramInterval; /** SDRAM Interval Configuration */
- UINT32 SdramDataInit; /** SDRAM Data initialization */
- CHAR8 Res12c[4];
- UINT32 SdramClkCntl; /** SDRAM Clock Control */
- CHAR8 Res134[20];
- UINT32 InitAddr; /** training init addr */
- UINT32 InitExtAddr; /** training init extended addr */
- CHAR8 Res150[16];
- UINT32 TimingCfg4; /** SDRAM Timing Configuration 4 */
- UINT32 TimingCfg5; /** SDRAM Timing Configuration 5 */
- UINT32 TimingCfg6; /** SDRAM Timing Configuration 6 */
- UINT32 TimingCfg7; /** SDRAM Timing Configuration 7 */
- UINT32 DdrZqCntl; /** ZQ calibration control*/
- UINT32 DdrWrlvlCntl; /** write leveling control*/
- CHAR8 Reg178[4];
- UINT32 DdrSrCntr; /** self refresh counter */
- UINT32 DdrSdramRcw1; /** Control Words 1 */
- UINT32 DdrSdramRcw2; /** Control Words 2 */
- CHAR8 Reg188[8];
- UINT32 DdrWrlvlCntl2; /** write leveling control 2 */
- UINT32 DdrWrlvlCntl3; /** write leveling control 3 */
- CHAR8 Res198[8];
- UINT32 DdrSdramRcw3;
- UINT32 DdrSdramRcw4;
- UINT32 DdrSdramRcw5;
- UINT32 DdrSdramRcw6;
- CHAR8 Res1b0[80];
- UINT32 SdramMode3; /** SDRAM Mode Configuration 3 */
- UINT32 SdramMode4; /** SDRAM Mode Configuration 4 */
- UINT32 SdramMode5; /** SDRAM Mode Configuration 5 */
- UINT32 SdramMode6; /** SDRAM Mode Configuration 6 */
- UINT32 SdramMode7; /** SDRAM Mode Configuration 7 */
- UINT32 SdramMode8; /** SDRAM Mode Configuration 8 */
- CHAR8 Res218[8];
- UINT32 SdramMode9; /** SDRAM Mode Configuration 9 */
- UINT32 SdramMode10; /** SDRAM Mode Configuration 10 */
- UINT32 SdramMode11; /** SDRAM Mode Configuration 11 */
- UINT32 SdramMode12; /** SDRAM Mode Configuration 12 */
- UINT32 SdramMode13; /** SDRAM Mode Configuration 13 */
- UINT32 SdramMode14; /** SDRAM Mode Configuration 14 */
- UINT32 SdramMode15; /** SDRAM Mode Configuration 15 */
- UINT32 SdramMode16; /** SDRAM Mode Configuration 16 */
- CHAR8 Res240[16];
- UINT32 TimingCfg8; /* SDRAM Timing Configuration 8 */
- CHAR8 Res254[12];
- UINT32 SdramCfg3;
- CHAR8 Res264[412];
- UINT32 DqMap0;
- UINT32 DqMap1;
- UINT32 DqMap2;
- UINT32 DqMap3;
- CHAR8 Res410[1808];
- UINT32 DdrDsr1; /** Debug Status 1 */
- UINT32 DdrDsr2; /** Debug Status 2 */
- UINT32 DdrCdr1; /** Control Driver 1 */
- UINT32 DdrCdr2; /** Control Driver 2 */
- CHAR8 ResB30[200];
- UINT32 IpRev1; /** IP Block Revision 1 */
- UINT32 IpRev2; /** IP Block Revision 2 */
- UINT32 Eor; /** Enhanced Optimization Register */
- CHAR8 ResC04[252];
- UINT32 Mtcr; /** Memory Test Control Register */
- CHAR8 ResD04[28];
- UINT32 Mtp1; /** Memory Test Pattern 1 */
- UINT32 Mtp2; /** Memory Test Pattern 2 */
- UINT32 Mtp3; /** Memory Test Pattern 3 */
- UINT32 Mtp4; /** Memory Test Pattern 4 */
- UINT32 Mtp5; /** Memory Test Pattern 5 */
- UINT32 Mtp6; /** Memory Test Pattern 6 */
- UINT32 Mtp7; /** Memory Test Pattern 7 */
- UINT32 Mtp8; /** Memory Test Pattern 8 */
- UINT32 Mtp9; /** Memory Test Pattern 9 */
- UINT32 Mtp10; /** Memory Test Pattern 10 */
- CHAR8 ResD48[184];
- UINT32 DataErrInjectHi; /** Data Path Err Injection Mask High */
- UINT32 DataErrInjectLo; /** Data Path Err Injection Mask Low */
- UINT32 EccErrInject; /** Data Path Err Injection Mask
ECC */
- CHAR8 ResE0c[20];
- UINT32 CaptureDataHi; /** Data Path Read Capture High */
- UINT32 CaptureDataLo; /** Data Path Read Capture Low */
- UINT32 CaptureEcc; /** Data Path Read Capture ECC */
- CHAR8 ResE2c[20];
- UINT32 ErrDetect; /** Error Detect */
- UINT32 ErrDisable; /** Error Disable */
- UINT32 ErrIntEn;
- UINT32 CaptureAttributes; /** Error Attrs Capture */
- UINT32 CaptureAddress; /** Error Addr Capture */
- UINT32 CaptureExtAddress; /** Error Extended Addr Capture */
- UINT32 ErrSbe; /** Single-Bit ECC Error Management */
- CHAR8 ResE5c[164];
- UINT32 Debug[32]; /** Debug_1 to Debug_32 */
- CHAR8 ResF80[128];
+};
+/**
- Main function to initialize DDR
- **/
+VOID +DramInit(
- );
+/**
- Function to dump DDRC registers
+**/ +VOID +DdrRegDump (
- VOID
- );
+#endif diff --git a/Platforms/Nxp/LS1043aRdb/Library/DdrLib/DdrLib.c b/Platforms/Nxp/LS1043aRdb/Library/DdrLib/DdrLib.c new file mode 100644 index 0000000..1c33de4 --- /dev/null +++ b/Platforms/Nxp/LS1043aRdb/Library/DdrLib/DdrLib.c @@ -0,0 +1,188 @@ +/** @DdrLib.c
- Ddr Library containing functions to initialize ddr controller
- Copyright (c) 2016, Freescale Semiconductor, Inc. All rights
reserved.
- This program and the accompanying materials are licensed and made
- available under the terms and conditions of the BSD License which
- accompanies this distribution. The full text of the license may be
- found at http://opensource.org/licenses/bsd-license.php
- THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS"
- BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER
EXPRESS OR IMPLIED.
+**/
+#include <Library/Ddr.h> +#include <Library/BaseLib.h>
+#define Uswap32(X) \
Use SwapBytes32 instead?
Ok.
((((X) & 0xff000000) >> 24) | \
(((X) & 0x00ff0000) >> 8) | \
(((X) & 0x0000ff00) << 8) | \
(((X) & 0x000000ff) << 24))
+#define DDRMC_DELAY 10000
10000 what?
Ok, will add appropriate comment here.
+/**
- Function to dump DDRC registers
+**/
+VOID +DdrRegDump (
- VOID
- )
+{
- struct CcsrDdr *Ddr = (VOID *)LS1043A_DDR_ADDR;
- DEBUG((EFI_D_INFO, "Cs0Bnds =
- 0x%x\n",MmioReadBe32((UINTN)&Ddr->Cs0Bnds)));
These all need a space after comma. Hmm, I get a bit nervous about those MmioReadBe32 though... Because struct CcsrDdr is defined as a little-endian structure. Too feel more comfortable, I would like to have a comment at the structure definition explaining why this is, and for what reasons this is not problematic.
Sure, will add that in V2.
- DEBUG((EFI_D_INFO, "Cs1Bnds =
- 0x%x\n",MmioReadBe32((UINTN)&Ddr->Cs1Bnds)));
Also ... this would be a lot cleaner as a macro: #define DUMP_DDR_REG(X, Y) \ DEBUG((EFI_D_INFO, "%s = 0x%x\n", #Y, MmioReadBe32((UINTN)&X->Y))) And called as: DUMP_DDR_REG(Ddr, Cs1Bnds);
Although I think it would be worth looking into checking current debug level before calling this function rather than for every register to be dumped.
Fair enough.
- DEBUG((EFI_D_INFO, "Cs2Bnds =
- 0x%x\n",MmioReadBe32((UINTN)&Ddr->Cs2Bnds)));
- DEBUG((EFI_D_INFO, "Cs3Bnds =
- 0x%x\n",MmioReadBe32((UINTN)&Ddr->Cs3Bnds)));
- DEBUG((EFI_D_INFO, "Cs0Config =
- 0x%x\n",MmioReadBe32((UINTN)&Ddr->Cs0Config)));
- DEBUG((EFI_D_INFO, "Cs1Config =
- 0x%x\n",MmioReadBe32((UINTN)&Ddr->Cs1Config)));
- DEBUG((EFI_D_INFO, "Cs2Config =
- 0x%x\n",MmioReadBe32((UINTN)&Ddr->Cs2Config)));
- DEBUG((EFI_D_INFO, "Cs3Config =
- 0x%x\n",MmioReadBe32((UINTN)&Ddr->Cs3Config)));
- DEBUG((EFI_D_INFO, "Cs0Config2 =
- 0x%x\n",MmioReadBe32((UINTN)&Ddr->Cs0Config2)));
- DEBUG((EFI_D_INFO, "Cs1Config2 =
- 0x%x\n",MmioReadBe32((UINTN)&Ddr->Cs1Config2)));
- DEBUG((EFI_D_INFO, "Cs2Config2 =
- 0x%x\n",MmioReadBe32((UINTN)&Ddr->Cs2Config2)));
- DEBUG((EFI_D_INFO, "Cs3Config2 =
- 0x%x\n",MmioReadBe32((UINTN)&Ddr->Cs3Config2)));
- DEBUG((EFI_D_INFO, "TimingCfg3 =
- 0x%x\n",MmioReadBe32((UINTN)&Ddr->TimingCfg3)));
- DEBUG((EFI_D_INFO, "TimingCfg0 =
- 0x%x\n",MmioReadBe32((UINTN)&Ddr->TimingCfg0)));
- DEBUG((EFI_D_INFO, "TimingCfg1 =
- 0x%x\n",MmioReadBe32((UINTN)&Ddr->TimingCfg1)));
- DEBUG((EFI_D_INFO, "TimingCfg2 =
- 0x%x\n",MmioReadBe32((UINTN)&Ddr->TimingCfg2)));
- DEBUG((EFI_D_INFO, "SdramCfg =
- 0x%x\n",MmioReadBe32((UINTN)&Ddr->SdramCfg)));
- DEBUG((EFI_D_INFO, "SdramCfg2 =
- 0x%x\n",MmioReadBe32((UINTN)&Ddr->SdramCfg2)));
- DEBUG((EFI_D_INFO, "SdramMode =
- 0x%x\n",MmioReadBe32((UINTN)&Ddr->SdramMode)));
- DEBUG((EFI_D_INFO, "SdramMode2 =
- 0x%x\n",MmioReadBe32((UINTN)&Ddr->SdramMode2)));
- DEBUG((EFI_D_INFO, "SdramMdCntl =
- 0x%x\n",MmioReadBe32((UINTN)&Ddr->SdramMdCntl)));
- DEBUG((EFI_D_INFO, "SdramInterval =
- 0x%x\n",MmioReadBe32((UINTN)&Ddr->SdramInterval)));
- DEBUG((EFI_D_INFO, "SdramDataInit =
- 0x%x\n",MmioReadBe32((UINTN)&Ddr->SdramDataInit)));
- DEBUG((EFI_D_INFO, "SdramClkCntl =
- 0x%x\n",MmioReadBe32((UINTN)&Ddr->SdramClkCntl)));
- DEBUG((EFI_D_INFO, "InitAddr =
- 0x%x\n",MmioReadBe32((UINTN)&Ddr->InitAddr)));
- DEBUG((EFI_D_INFO, "InitExtAddr =
- 0x%x\n",MmioReadBe32((UINTN)&Ddr->InitExtAddr)));
- DEBUG((EFI_D_INFO, "TimingCfg4 =
- 0x%x\n",MmioReadBe32((UINTN)&Ddr->TimingCfg4)));
- DEBUG((EFI_D_INFO, "TimingCfg5 =
- 0x%x\n",MmioReadBe32((UINTN)&Ddr->TimingCfg5)));
- DEBUG((EFI_D_INFO, "TimingCfg6 =
- 0x%x\n",MmioReadBe32((UINTN)&Ddr->TimingCfg6)));
- DEBUG((EFI_D_INFO, "TimingCfg7 =
- 0x%x\n",MmioReadBe32((UINTN)&Ddr->TimingCfg7)));
- DEBUG((EFI_D_INFO, "DdrZqCntl =
- 0x%x\n",MmioReadBe32((UINTN)&Ddr->DdrZqCntl)));
- DEBUG((EFI_D_INFO, "DdrWrlvlCntl =
- 0x%x\n",MmioReadBe32((UINTN)&Ddr->DdrWrlvlCntl)));
- DEBUG((EFI_D_INFO, "DdrSrCntr =
- 0x%x\n",MmioReadBe32((UINTN)&Ddr->DdrSrCntr)));
- DEBUG((EFI_D_INFO, "DdrSdramRcw1 =
- 0x%x\n",MmioReadBe32((UINTN)&Ddr->DdrSdramRcw1)));
- DEBUG((EFI_D_INFO, "DdrSdramRcw2 =
- 0x%x\n",MmioReadBe32((UINTN)&Ddr->DdrSdramRcw2)));
- DEBUG((EFI_D_INFO, "DdrWrlvlCntl2 =
- 0x%x\n",MmioReadBe32((UINTN)&Ddr->DdrWrlvlCntl2)));
- DEBUG((EFI_D_INFO, "DdrWrlvlCntl3 =
- 0x%x\n",MmioReadBe32((UINTN)&Ddr->DdrWrlvlCntl3)));
- DEBUG((EFI_D_INFO, "DdrSdramRcw3 =
- 0x%x\n",MmioReadBe32((UINTN)&Ddr->DdrSdramRcw3)));
- DEBUG((EFI_D_INFO, "DdrSdramRcw4 =
- 0x%x\n",MmioReadBe32((UINTN)&Ddr->DdrSdramRcw4)));
- DEBUG((EFI_D_INFO, "DdrSdramRcw5 =
- 0x%x\n",MmioReadBe32((UINTN)&Ddr->DdrSdramRcw5)));
- DEBUG((EFI_D_INFO, "DdrSdramRcw6 =
- 0x%x\n",MmioReadBe32((UINTN)&Ddr->DdrSdramRcw6)));
- DEBUG((EFI_D_INFO, "SdramMode3 =
- 0x%x\n",MmioReadBe32((UINTN)&Ddr->SdramMode3)));
- DEBUG((EFI_D_INFO, "SdramMode4 =
- 0x%x\n",MmioReadBe32((UINTN)&Ddr->SdramMode4)));
- DEBUG((EFI_D_INFO, "SdramMode5 =
- 0x%x\n",MmioReadBe32((UINTN)&Ddr->SdramMode5)));
- DEBUG((EFI_D_INFO, "SdramMode6 =
- 0x%x\n",MmioReadBe32((UINTN)&Ddr->SdramMode6)));
- DEBUG((EFI_D_INFO, "SdramMode7 =
- 0x%x\n",MmioReadBe32((UINTN)&Ddr->SdramMode7)));
- DEBUG((EFI_D_INFO, "SdramMode8 =
- 0x%x\n",MmioReadBe32((UINTN)&Ddr->SdramMode8)));
- DEBUG((EFI_D_INFO, "SdramMode9 =
- 0x%x\n",MmioReadBe32((UINTN)&Ddr->SdramMode9)));
- DEBUG((EFI_D_INFO, "SdramMode10 =
- 0x%x\n",MmioReadBe32((UINTN)&Ddr->SdramMode10)));
- DEBUG((EFI_D_INFO, "SdramMode11 =
- 0x%x\n",MmioReadBe32((UINTN)&Ddr->SdramMode11)));
- DEBUG((EFI_D_INFO, "SdramMode12 =
- 0x%x\n",MmioReadBe32((UINTN)&Ddr->SdramMode12)));
- DEBUG((EFI_D_INFO, "SdramMode13 =
- 0x%x\n",MmioReadBe32((UINTN)&Ddr->SdramMode13)));
- DEBUG((EFI_D_INFO, "SdramMode14 =
- 0x%x\n",MmioReadBe32((UINTN)&Ddr->SdramMode14)));
- DEBUG((EFI_D_INFO, "SdramMode15 =
- 0x%x\n",MmioReadBe32((UINTN)&Ddr->SdramMode15)));
- DEBUG((EFI_D_INFO, "SdramMode16 =
- 0x%x\n",MmioReadBe32((UINTN)&Ddr->SdramMode16)));
- DEBUG((EFI_D_INFO, "TimingCfg8 =
- 0x%x\n",MmioReadBe32((UINTN)&Ddr->TimingCfg8)));
- DEBUG((EFI_D_INFO, "SdramCfg3 =
- 0x%x\n",MmioReadBe32((UINTN)&Ddr->SdramCfg3)));
- DEBUG((EFI_D_INFO, "DqMap0 =
- 0x%x\n",MmioReadBe32((UINTN)&Ddr->DqMap0)));
- DEBUG((EFI_D_INFO, "DqMap1 =
- 0x%x\n",MmioReadBe32((UINTN)&Ddr->DqMap1)));
- DEBUG((EFI_D_INFO, "DqMap2 =
- 0x%x\n",MmioReadBe32((UINTN)&Ddr->DqMap2)));
- DEBUG((EFI_D_INFO, "DqMap3 =
- 0x%x\n",MmioReadBe32((UINTN)&Ddr->DqMap3)));
- DEBUG((EFI_D_INFO, "DdrDsr1 =
- 0x%x\n",MmioReadBe32((UINTN)&Ddr->DdrDsr1)));
- DEBUG((EFI_D_INFO, "DdrDsr2 =
- 0x%x\n",MmioReadBe32((UINTN)&Ddr->DdrDsr2)));
- DEBUG((EFI_D_INFO, "DdrCdr1 =
- 0x%x\n",MmioReadBe32((UINTN)&Ddr->DdrCdr1)));
- DEBUG((EFI_D_INFO, "DdrCdr2 =
- 0x%x\n",MmioReadBe32((UINTN)&Ddr->DdrCdr2)));
- DEBUG((EFI_D_INFO, "IpRev1 =
- 0x%x\n",MmioReadBe32((UINTN)&Ddr->IpRev1)));
- DEBUG((EFI_D_INFO, "IpRev2 =
- 0x%x\n",MmioReadBe32((UINTN)&Ddr->IpRev2)));
- DEBUG((EFI_D_INFO, "Eor = 0x%x\n",MmioReadBe32((UINTN)&Ddr-
Eor)));
- DEBUG((EFI_D_INFO, "Mtcr =
- 0x%x\n",MmioReadBe32((UINTN)&Ddr->Mtcr)));
- DEBUG((EFI_D_INFO, "Mtp1 =
- 0x%x\n",MmioReadBe32((UINTN)&Ddr->Mtp1)));
- DEBUG((EFI_D_INFO, "Mtp2 =
- 0x%x\n",MmioReadBe32((UINTN)&Ddr->Mtp2)));
- DEBUG((EFI_D_INFO, "Mtp3 =
- 0x%x\n",MmioReadBe32((UINTN)&Ddr->Mtp3)));
- DEBUG((EFI_D_INFO, "Mtp4 =
- 0x%x\n",MmioReadBe32((UINTN)&Ddr->Mtp4)));
- DEBUG((EFI_D_INFO, "Mtp5 =
- 0x%x\n",MmioReadBe32((UINTN)&Ddr->Mtp5)));
- DEBUG((EFI_D_INFO, "Mtp6 =
- 0x%x\n",MmioReadBe32((UINTN)&Ddr->Mtp6)));
- DEBUG((EFI_D_INFO, "Mtp7 =
- 0x%x\n",MmioReadBe32((UINTN)&Ddr->Mtp7)));
- DEBUG((EFI_D_INFO, "Mtp8 =
- 0x%x\n",MmioReadBe32((UINTN)&Ddr->Mtp8)));
- DEBUG((EFI_D_INFO, "Mtp9 =
- 0x%x\n",MmioReadBe32((UINTN)&Ddr->Mtp9)));
- DEBUG((EFI_D_INFO, "Mtp10 =
- 0x%x\n",MmioReadBe32((UINTN)&Ddr->Mtp10)));
- DEBUG((EFI_D_INFO, "DataErrInjectHi =
- 0x%x\n",MmioReadBe32((UINTN)&Ddr->DataErrInjectHi)));
- DEBUG((EFI_D_INFO, "DataErrInjectLo =
- 0x%x\n",MmioReadBe32((UINTN)&Ddr->DataErrInjectLo)));
- DEBUG((EFI_D_INFO, "EccErrInject =
- 0x%x\n",MmioReadBe32((UINTN)&Ddr->EccErrInject)));
- DEBUG((EFI_D_INFO, "CaptureDataHi =
- 0x%x\n",MmioReadBe32((UINTN)&Ddr->CaptureDataHi)));
- DEBUG((EFI_D_INFO, "CaptureDataLo =
- 0x%x\n",MmioReadBe32((UINTN)&Ddr->CaptureDataLo)));
- DEBUG((EFI_D_INFO, "CaptureEcc =
- 0x%x\n",MmioReadBe32((UINTN)&Ddr->CaptureEcc)));
- DEBUG((EFI_D_INFO, "ErrDetect =
- 0x%x\n",MmioReadBe32((UINTN)&Ddr->ErrDetect)));
- DEBUG((EFI_D_INFO, "ErrDisable =
- 0x%x\n",MmioReadBe32((UINTN)&Ddr->ErrDisable)));
- DEBUG((EFI_D_INFO, "ErrIntEn =
- 0x%x\n",MmioReadBe32((UINTN)&Ddr->ErrIntEn)));
- DEBUG((EFI_D_INFO, "CaptureAttributes =
- 0x%x\n",MmioReadBe32((UINTN)&Ddr->CaptureAttributes)));
- DEBUG((EFI_D_INFO, "CaptureAddress =
- 0x%x\n",MmioReadBe32((UINTN)&Ddr->CaptureAddress)));
- DEBUG((EFI_D_INFO, "CaptureExtAddress =
- 0x%x\n",MmioReadBe32((UINTN)&Ddr->CaptureExtAddress)));
- DEBUG((EFI_D_INFO, "ErrSbe =
- 0x%x\n",MmioReadBe32((UINTN)&Ddr->ErrSbe)));
- DEBUG((EFI_D_ERROR,"\n"));
Why the final _ERROR?
This needs to be changed.
+}
+/**
- Function to initialize DDR
- **/
+VOID +DramInit (
- )
+{
- struct CcsrDdr *Ddr;
- UINT32 Count, Delay = DDRMC_DELAY;
- Ddr = (VOID *)LS1043A_DDR_ADDR;
- MmioWriteBe32((UINTN)&Ddr->SdramCfg, LS1043A_DDR_SDRAM_CFG);
- MmioWriteBe32((UINTN)&Ddr->Cs0Bnds, LS1043A_CS0_BNDS);
- MmioWriteBe32((UINTN)&Ddr->Cs0Config, LS1043A_CS0_CONFIG);
- MmioWriteBe32((UINTN)&Ddr->TimingCfg0, LS1043A_TIMING_CFG_0);
- MmioWriteBe32((UINTN)&Ddr->TimingCfg1, LS1043A_TIMING_CFG_1);
- MmioWriteBe32((UINTN)&Ddr->TimingCfg2, LS1043A_TIMING_CFG_2);
- MmioWriteBe32((UINTN)&Ddr->TimingCfg3, LS1043A_TIMING_CFG_3);
- MmioWriteBe32((UINTN)&Ddr->TimingCfg4, LS1043A_TIMING_CFG_4);
- MmioWriteBe32((UINTN)&Ddr->TimingCfg5, LS1043A_TIMING_CFG_5);
- MmioWriteBe32((UINTN)&Ddr->TimingCfg7, LS1043A_TIMING_CFG_7);
- MmioWriteBe32((UINTN)&Ddr->TimingCfg8, LS1043A_TIMING_CFG_8);
- MmioWriteBe32((UINTN)&Ddr->SdramCfg2, LS1043A_DDR_SDRAM_CFG_2);
- MmioWriteBe32((UINTN)&Ddr->SdramMode, LS1043A_DDR_SDRAM_MODE);
- MmioWriteBe32((UINTN)&Ddr->SdramMode2, 0);
- MmioWriteBe32((UINTN)&Ddr->SdramInterval,
- LS1043A_DDR_SDRAM_INTERVAL);
- MmioWriteBe32((UINTN)&Ddr->DdrWrlvlCntl, LS1043A_DDR_WRLVL_CNTL);
- MmioWriteBe32((UINTN)&Ddr->DdrWrlvlCntl2,
LS1043A_DDR_WRLVL_CNTL_2);
- MmioWriteBe32((UINTN)&Ddr->DdrWrlvlCntl3, 0);
- MmioWriteBe32((UINTN)&Ddr->DdrCdr1, LS1043A_DDRCDR_1);
- MmioWriteBe32((UINTN)&Ddr->DdrCdr2, LS1043A_DDRCDR_2);
- MmioWriteBe32((UINTN)&Ddr->SdramClkCntl,
- LS1043A_DDR_SDRAM_CLK_CNTL);
- MmioWriteBe32((UINTN)&Ddr->DdrZqCntl, LS1043A_DDR_ZQ_CNTL);
- MmioWriteBe32((UINTN)&Ddr->SdramMode9, LS1043A_DDR_SDRAM_MODE_9);
- MmioWriteBe32((UINTN)&Ddr->SdramMode10, LS1043A_DDR_SDRAM_MODE_10);
- MmioWriteBe32((UINTN)&Ddr->Cs0Config2, 0);
- for(Count = 0; Count < Delay; Count++)
;
If we are waiting for some operation to take effect, then we badly need at least a MemoryBarrier() here. And if we do, do we still need the delay? If we do need a delay, it is much preferable to use something like gBs->Stall(), or MicroSecondDelay() than just an empty loop.
Ok, will change this in V2.
- MmioWriteBe32((UINTN)&Ddr->SdramCfg, LS1043A_DDR_SDRAM_CFG
| LS1043A_DDR_SDRAM_CFG_MEM_EN);
- return;
+} diff --git a/Platforms/Nxp/LS1043aRdb/Library/DdrLib/DdrLib.inf b/Platforms/Nxp/LS1043aRdb/Library/DdrLib/DdrLib.inf new file mode 100644 index 0000000..e8e3aed --- /dev/null +++ b/Platforms/Nxp/LS1043aRdb/Library/DdrLib/DdrLib.inf @@ -0,0 +1,41 @@ +#/** DdrLib.inf +# +# Component description file for DdrLib module # # Copyright (c) +2016, Freescale Semiconductor, Inc. All rights reserved. +# +# This program and the accompanying materials # are licensed and +made available under the terms and conditions of the BSD License # +which accompanies this distribution. The full text of the license +may be found at # http://opensource.org/licenses/bsd-license.php +# +# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" +BASIS, # WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER
EXPRESS OR IMPLIED.
+# +#**/
+[Defines]
- INF_VERSION = 0x00010005
0x00010019 if we're following V1.25 of the specification, as published at https://github.com/tianocore/tianocore.github.io/wiki/EDK-II- Specifications
Ok.
- BASE_NAME = DdrLib
- FILE_GUID = 8ecefc8f-a2c4-4091-b31f-
20f7aeb0567f
- MODULE_TYPE = BASE
- VERSION_STRING = 1.0
- LIBRARY_CLASS = DdrLib
+[Sources.common]
- DdrLib.c
+[LibraryClasses]
- ArmLib
- IoLib
- BaseMemoryLib
- BaseLib
- SocLib
+[Packages]
- EmbeddedPkg/EmbeddedPkg.dec
- MdePkg/MdePkg.dec
- MdeModulePkg/MdeModulePkg.dec
- ArmPlatformPkg/ArmPlatformPkg.dec
- OpenPlatformPkg/Platforms/Nxp/LS1043aRdb/LS1043aRdbPkg.dec
- OpenPlatformPkg/Chips/Nxp/QoriqLs/NxpQoriqLs.dec
OCD sorting, please?
Ok.
-- 1.9.1
Regards, Bhupesh
From: Sakar Arora sakar.arora@nxp.com
NXP/FSL's LS1043A-RDB board houses a CPLD (FPGA) which can be used to control various pin-multiplexing options, which allows certain combinations of peripherals to be enabled on the board.
In addition this CPLD provides a mechanism to divide the NOR/NAND flash memory into primary and alternate regions. While golden images can be flashed on the primary bank, experimental images can be flashed on the alternate bank.
CPLD provides a way to switch from primary to alternate region (and vice-versa), thus protecting the board from damage if primary region is flashed with incorrect set of images.
Signed-off-by: Sakar Arora sakar.arora@nxp.com Signed-off-by: Bhupesh Sharma bhupesh.sharma@nxp.com --- Platforms/Nxp/LS1043aRdb/Include/Library/CpldLib.h | 75 +++ Platforms/Nxp/LS1043aRdb/Include/Library/FslIfc.h | 721 +++++++++++++++++++++ Platforms/Nxp/LS1043aRdb/Library/CpldLib/CpldLib.c | 157 +++++ .../Nxp/LS1043aRdb/Library/CpldLib/CpldLib.inf | 33 + 4 files changed, 986 insertions(+) create mode 100644 Platforms/Nxp/LS1043aRdb/Include/Library/CpldLib.h create mode 100644 Platforms/Nxp/LS1043aRdb/Include/Library/FslIfc.h create mode 100644 Platforms/Nxp/LS1043aRdb/Library/CpldLib/CpldLib.c create mode 100644 Platforms/Nxp/LS1043aRdb/Library/CpldLib/CpldLib.inf
diff --git a/Platforms/Nxp/LS1043aRdb/Include/Library/CpldLib.h b/Platforms/Nxp/LS1043aRdb/Include/Library/CpldLib.h new file mode 100644 index 0000000..56f47da --- /dev/null +++ b/Platforms/Nxp/LS1043aRdb/Include/Library/CpldLib.h @@ -0,0 +1,75 @@ +/** CpldLib.h +* Header defining the LS1043a Cpld specific constants (Base addresses, sizes, flags) +* +* Copyright (c) 2016, Freescale Semiconductor, Inc. All rights reserved. +* +* This program and the accompanying materials +* are licensed and made available under the terms and conditions of the BSD License +* which accompanies this distribution. The full text of the license may be found at +* http://opensource.org/licenses/bsd-license.php +* +* THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, +* WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. +* +**/ + +#ifndef __LS1043A_CPLD_H__ +#define __LS1043A_CPLD_H__ + +#include <Library/Common.h> + +/* + * CPLD register set of LS1043ARDB board-specific. + */ +struct CpldRegSet { + UINT8 CpldVersionMajor; /* 0x0 - CPLD Major Revision Register */ + UINT8 CpldVersionMinor; /* 0x1 - CPLD Minor Revision Register */ + UINT8 PcbaVersion; /* 0x2 - PCBA Revision Register */ + UINT8 SystemReset; /* 0x3 - system reset register */ + UINT8 SoftMuxOn; /* 0x4 - Switch Control Enable Register */ + UINT8 RcwSource1; /* 0x5 - Reset config word 1 */ + UINT8 RcwSource2; /* 0x6 - Reset config word 1 */ + UINT8 Vbank; /* 0x7 - Flash bank selection Control */ + UINT8 SysclkSelect; /* 0x8 - */ + UINT8 UartSel; /* 0x9 - */ + UINT8 Sd1RefClkSel; /* 0xA - */ + UINT8 TdmClkMuxSel; /* 0xB - */ + UINT8 SdhcSpiCsSel; /* 0xC - */ + UINT8 StatusLed; /* 0xD - */ + UINT8 GlobalReset; /* 0xE - */ +}; + +/* + * Reset the board, Reset to alternate bank or Dump registers: + * RESET - reset to default bank + * RESET_ALTBANK - reset to alternate bank + * DUMP_REGISTERS - display the CPLD registers + */ +typedef enum { + RESET = 0, + RESET_ALTBANK, + DUMP_REGISTERS +} CpldCmd; + +UINT8 CpldRead(UINTN Reg); +VOID CpldWrite(UINTN Reg, UINT8 Value); +VOID CpldRevBit(UINT8 *Value); +VOID DoCpld (CpldCmd Cmd); +VOID CpldInit (VOID); + +#define CPLD_READ(Reg) CpldRead(offsetof(struct CpldRegSet, Reg)) +#define CPLD_WRITE(Reg, Value) \ + CpldWrite(offsetof(struct CpldRegSet, Reg), Value) + +/* CPLD on IFC */ +#define CPLD_SW_MUX_BANK_SEL 0x40 +#define CPLD_BANK_SEL_MASK 0x07 +#define CPLD_BANK_SEL_ALTBANK 0x04 + +/* SDXC/DSPI CPLD Settings */ +#define ENABLE_SDXC_SOFT_MUX 0x30 +#define ENABLE_RCW_SOFT_MUX 0x01 +#define SELECT_SW4_SDXC 0x40 +#define SELECT_SW5_SDXC 0x01 + +#endif diff --git a/Platforms/Nxp/LS1043aRdb/Include/Library/FslIfc.h b/Platforms/Nxp/LS1043aRdb/Include/Library/FslIfc.h new file mode 100644 index 0000000..27c8295 --- /dev/null +++ b/Platforms/Nxp/LS1043aRdb/Include/Library/FslIfc.h @@ -0,0 +1,721 @@ +/** @FslIfc.h + + Copyright (c) 2008 - 2009, Apple Inc. All rights reserved.<BR> + Copyright (c) 2016, Freescale Semiconductor, Inc. All rights reserved. + + This program and the accompanying materials + are licensed and made available under the terms and conditions of the BSD License + which accompanies this distribution. The full text of the license may be found at + http://opensource.org/licenses/bsd-license.php + + THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, + WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. + +**/ + +#ifndef __FLASH_H__ +#define __FLASH_H__ + +#include <Uefi.h> + +#include <Library/BaseLib.h> +#include <Library/BaseMemoryLib.h> +#include <Library/MemoryAllocationLib.h> +#include <Library/DebugLib.h> +#include <Library/IoLib.h> +#include <Library/PcdLib.h> +#include <Library/UefiBootServicesTableLib.h> +#include <Library/IoLib.h> +#include <Library/PlatformLib.h> + +#include <Protocol/BlockIo.h> +#include <Protocol/Cpu.h> + +#define NOIBR + +#define FSL_IFC_BANK_COUNT 4 + +#define NAND_PAGE_SIZE_2K (2048) +#define NAND_SPARE_AREA_SIZE_64B (64) +#define NAND_BLOCK_SIZE_128K (128*1024) +#define NAND_BLOCK_COUNT (2048) +#define NAND_LAST_BLOCK (NAND_BLOCK_COUNT - 1) + + +//List of commands. +#define IFC_NAND_CMD_RESET 0xFF +#define IFC_NAND_CMD_READID 0x90 + +#define IFC_NAND_CMD_STATUS 0x70 + +#define IFC_NAND_CMD_READ0 0x00 +#define IFC_NAND_CMD_READSTART 0x30 + +#define IFC_NAND_CMD_ERASE1 0x60 +#define IFC_NAND_CMD_ERASE2 0xD0 + +#define IFC_NAND_CMD_SEQIN 0x80 +#define IFC_NAND_CMD_PAGEPROG 0x10 + +#define MAX_RETRY_COUNT 150000 + +#define FSL_IFC_REG_BASE 0x1530000 +#define FSL_IFC_NAND_BUF_BASE 0x70000000 +#define FSL_IFC_NOR_BUF_BASE 0x60000000 + +#define FSL_IFC_NOR_RESERVED_REGION_BASE 0x60700000 + +#define FSL_IFC_CSPR_REG_LEN 148 +#define FSL_IFC_AMASK_REG_LEN 144 +#define FSL_IFC_CSOR_REG_LEN 144 +#define FSL_IFC_FTIM_REG_LEN 576 + +#define FSL_IFC_NAND_SEQ_STRT_FIR_STRT 0x80000000 + +#define FSL_IFC_CSPR_USED_LEN sizeof(FSL_IFC_CSPR) * \ + FSL_IFC_BANK_COUNT +#define FSL_IFC_AMASK_USED_LEN sizeof(FSL_IFC_AMASK) * \ + FSL_IFC_BANK_COUNT +#define FSL_IFC_CSOR_USED_LEN sizeof(FSL_IFC_CSOR) * \ + FSL_IFC_BANK_COUNT +#define FSL_IFC_FTIM_USED_LEN sizeof(FSL_IFC_FTIM) * \ + FSL_IFC_BANK_COUNT + +/* + * NAND Event and Error Status Register (NAND_EVTER_STAT) + */ +/* Operation Complete */ +#define FSL_IFC_NAND_EVTER_STAT_OPC 0x80000000 +/* Flash Timeout Error */ +#define FSL_IFC_NAND_EVTER_STAT_FTOER 0x08000000 +/* Write Protect Error */ +#define FSL_IFC_NAND_EVTER_STAT_WPER 0x04000000 +/* ECC Error */ +#define FSL_IFC_NAND_EVTER_STAT_ECCER 0x02000000 + +/* + * NAND Flash Byte Count Register (NAND_BC) + */ +/* Byte Count for read/Write */ +#define FSL_IFC_NAND_BC 0x000001FF + +/* + * NAND Flash Instruction Registers (NAND_FIR0/NAND_FIR1/NAND_FIR2) + */ +/* NAND Machine specific opcodes OP0-OP14*/ +#define FSL_IFC_NAND_FIR0_OP0 0xFC000000 +#define FSL_IFC_NAND_FIR0_OP0_SHIFT 26 +#define FSL_IFC_NAND_FIR0_OP1 0x03F00000 +#define FSL_IFC_NAND_FIR0_OP1_SHIFT 20 +#define FSL_IFC_NAND_FIR0_OP2 0x000FC000 +#define FSL_IFC_NAND_FIR0_OP2_SHIFT 14 +#define FSL_IFC_NAND_FIR0_OP3 0x00003F00 +#define FSL_IFC_NAND_FIR0_OP3_SHIFT 8 +#define FSL_IFC_NAND_FIR0_OP4 0x000000FC +#define FSL_IFC_NAND_FIR0_OP4_SHIFT 2 +#define FSL_IFC_NAND_FIR1_OP5 0xFC000000 +#define FSL_IFC_NAND_FIR1_OP5_SHIFT 26 +#define FSL_IFC_NAND_FIR1_OP6 0x03F00000 +#define FSL_IFC_NAND_FIR1_OP6_SHIFT 20 +#define FSL_IFC_NAND_FIR1_OP7 0x000FC000 +#define FSL_IFC_NAND_FIR1_OP7_SHIFT 14 +#define FSL_IFC_NAND_FIR1_OP8 0x00003F00 +#define FSL_IFC_NAND_FIR1_OP8_SHIFT 8 +#define FSL_IFC_NAND_FIR1_OP9 0x000000FC +#define FSL_IFC_NAND_FIR1_OP9_SHIFT 2 +#define FSL_IFC_NAND_FIR2_OP10 0xFC000000 +#define FSL_IFC_NAND_FIR2_OP10_SHIFT 26 +#define FSL_IFC_NAND_FIR2_OP11 0x03F00000 +#define FSL_IFC_NAND_FIR2_OP11_SHIFT 20 +#define FSL_IFC_NAND_FIR2_OP12 0x000FC000 +#define FSL_IFC_NAND_FIR2_OP12_SHIFT 14 +#define FSL_IFC_NAND_FIR2_OP13 0x00003F00 +#define FSL_IFC_NAND_FIR2_OP13_SHIFT 8 +#define FSL_IFC_NAND_FIR2_OP14 0x000000FC +#define FSL_IFC_NAND_FIR2_OP14_SHIFT 2 + +/* + * NAND Flash Command Registers (NAND_FCR0/NAND_FCR1) + */ +/* General purpose FCM flash command bytes CMD0-CMD7 */ +#define FSL_IFC_NAND_FCR0_CMD0 0xFF000000 +#define FSL_IFC_NAND_FCR0_CMD0_SHIFT 24 +#define FSL_IFC_NAND_FCR0_CMD1 0x00FF0000 +#define FSL_IFC_NAND_FCR0_CMD1_SHIFT 16 +#define FSL_IFC_NAND_FCR0_CMD2 0x0000FF00 +#define FSL_IFC_NAND_FCR0_CMD2_SHIFT 8 +#define FSL_IFC_NAND_FCR0_CMD3 0x000000FF +#define FSL_IFC_NAND_FCR0_CMD3_SHIFT 0 +#define FSL_IFC_NAND_FCR1_CMD4 0xFF000000 +#define FSL_IFC_NAND_FCR1_CMD4_SHIFT 24 +#define FSL_IFC_NAND_FCR1_CMD5 0x00FF0000 +#define FSL_IFC_NAND_FCR1_CMD5_SHIFT 16 +#define FSL_IFC_NAND_FCR1_CMD6 0x0000FF00 +#define FSL_IFC_NAND_FCR1_CMD6_SHIFT 8 +#define FSL_IFC_NAND_FCR1_CMD7 0x000000FF +#define FSL_IFC_NAND_FCR1_CMD7_SHIFT 0 + +/* Timing registers for NAND Flash */ + +#define FSL_IFC_FTIM0_NAND_TCCST_SHIFT 25 +#define FSL_IFC_FTIM0_NAND_TCCST(n) ((n) << FSL_IFC_FTIM0_NAND_TCCST_SHIFT) +#define FSL_IFC_FTIM0_NAND_TWP_SHIFT 16 +#define FSL_IFC_FTIM0_NAND_TWP(n) ((n) << FSL_IFC_FTIM0_NAND_TWP_SHIFT) +#define FSL_IFC_FTIM0_NAND_TWCHT_SHIFT 8 +#define FSL_IFC_FTIM0_NAND_TWCHT(n) ((n) << FSL_IFC_FTIM0_NAND_TWCHT_SHIFT) +#define FSL_IFC_FTIM0_NAND_TWH_SHIFT 0 +#define FSL_IFC_FTIM0_NAND_TWH(n) ((n) << FSL_IFC_FTIM0_NAND_TWH_SHIFT) +#define FSL_IFC_FTIM1_NAND_TADLE_SHIFT 24 +#define FSL_IFC_FTIM1_NAND_TADLE(n) ((n) << FSL_IFC_FTIM1_NAND_TADLE_SHIFT) +#define FSL_IFC_FTIM1_NAND_TWBE_SHIFT 16 +#define FSL_IFC_FTIM1_NAND_TWBE(n) ((n) << FSL_IFC_FTIM1_NAND_TWBE_SHIFT) +#define FSL_IFC_FTIM1_NAND_TRR_SHIFT 8 +#define FSL_IFC_FTIM1_NAND_TRR(n) ((n) << FSL_IFC_FTIM1_NAND_TRR_SHIFT) +#define FSL_IFC_FTIM1_NAND_TRP_SHIFT 0 +#define FSL_IFC_FTIM1_NAND_TRP(n) ((n) << FSL_IFC_FTIM1_NAND_TRP_SHIFT) +#define FSL_IFC_FTIM2_NAND_TRAD_SHIFT 21 +#define FSL_IFC_FTIM2_NAND_TRAD(n) ((n) << FSL_IFC_FTIM2_NAND_TRAD_SHIFT) +#define FSL_IFC_FTIM2_NAND_TREH_SHIFT 11 +#define FSL_IFC_FTIM2_NAND_TREH(n) ((n) << FSL_IFC_FTIM2_NAND_TREH_SHIFT) +#define FSL_IFC_FTIM2_NAND_TWHRE_SHIFT 0 +#define FSL_IFC_FTIM2_NAND_TWHRE(n) ((n) << FSL_IFC_FTIM2_NAND_TWHRE_SHIFT) +#define FSL_IFC_FTIM3_NAND_TWW_SHIFT 24 +#define FSL_IFC_FTIM3_NAND_TWW(n) ((n) << FSL_IFC_FTIM3_NAND_TWW_SHIFT) + + + +/* + * Flash ROW and COL Address Register (ROWn, COLn) + */ +/* Main/spare region locator */ +#define FSL_IFC_NAND_COL_MS 0x80000000 +/* Column Address */ +#define FSL_IFC_NAND_COL_CA_MASK 0x00000FFF + +#define NAND_STATUS_WP 0x80 + +/* + * NAND Event and Error Enable Register (NAND_EVTER_EN) + */ +/* Operation complete event enable */ +#define FSL_IFC_NAND_EVTER_EN_OPC_EN 0x80000000 +/* Page read complete event enable */ +#define FSL_IFC_NAND_EVTER_EN_PGRDCMPL_EN 0x20000000 +/* Flash Timeout error enable */ +#define FSL_IFC_NAND_EVTER_EN_FTOER_EN 0x08000000 +/* Write Protect error enable */ +#define FSL_IFC_NAND_EVTER_EN_WPER_EN 0x04000000 +/* ECC error logging enable */ +#define FSL_IFC_NAND_EVTER_EN_ECCER_EN 0x02000000 + +/* + * CSPR - Chip Select Property Register + */ +#define IFC_CSPR_BA 0xFFFF0000 +#define IFC_CSPR_BA_SHIFT 16 +#define IFC_CSPR_PORT_SIZE 0x00000180 +#define IFC_CSPR_PORT_SIZE_SHIFT 7 +/* Port Size 8 bit */ +#define IFC_CSPR_PORT_SIZE_8 0x00000080 +/* Port Size 16 bit */ +#define IFC_CSPR_PORT_SIZE_16 0x00000100 +/* Port Size 32 bit */ +#define IFC_CSPR_PORT_SIZE_32 0x00000180 +/* Write Protect */ +#define IFC_CSPR_WP 0x00000040 +#define IFC_CSPR_WP_SHIFT 6 +/* Machine Select */ +#define IFC_CSPR_MSEL 0x00000006 +#define IFC_CSPR_MSEL_SHIFT 1 +/* NOR */ +#define IFC_CSPR_MSEL_NOR 0x00000000 +/* NAND */ +#define IFC_CSPR_MSEL_NAND 0x00000002 +/* GPCM */ +#define IFC_CSPR_MSEL_GPCM 0x00000004 +/* Bank Valid */ +#define IFC_CSPR_V 0x00000001 +#define IFC_CSPR_V_SHIFT 0 + +/* + * Chip Select Option Register - NOR Flash Mode + */ +/* Enable Address shift Mode */ +#define IFC_CSOR_NOR_ADM_SHFT_MODE_EN 0x80000000 +/* Page Read Enable from NOR device */ +#define IFC_CSOR_NOR_PGRD_EN 0x10000000 +/* AVD Toggle Enable during Burst Program */ +#define IFC_CSOR_NOR_AVD_TGL_PGM_EN 0x01000000 +/* Address Data Multiplexing Shift */ +#define IFC_CSOR_NOR_ADM_MASK 0x0003E000 +#define IFC_CSOR_NOR_ADM_SHIFT_SHIFT 13 +#define IFC_CSOR_NOR_ADM_SHIFT(n) ((n) << IFC_CSOR_NOR_ADM_SHIFT_SHIFT) +/* Type of the NOR device hooked */ +#define IFC_CSOR_NOR_NOR_MODE_AYSNC_NOR 0x00000000 +#define IFC_CSOR_NOR_NOR_MODE_AVD_NOR 0x00000020 +/* Time for Read Enable High to Output High Impedance */ +#define IFC_CSOR_NOR_TRHZ_MASK 0x0000001C +#define IFC_CSOR_NOR_TRHZ_SHIFT 2 +#define IFC_CSOR_NOR_TRHZ_20 0x00000000 +#define IFC_CSOR_NOR_TRHZ_40 0x00000004 +#define IFC_CSOR_NOR_TRHZ_60 0x00000008 +#define IFC_CSOR_NOR_TRHZ_80 0x0000000C +#define IFC_CSOR_NOR_TRHZ_100 0x00000010 +/* Buffer control disable */ +#define IFC_CSOR_NOR_BCTLD 0x00000001 + +/* + * Chip Select Option Register FSL_IFC_NAND Machine + */ +/* Enable ECC Encoder */ +#define IFC_CSOR_NAND_ECC_ENC_EN 0x80000000 +#define IFC_CSOR_NAND_ECC_MODE_MASK 0x30000000 +/* 4 bit correction per 520 Byte sector */ +#define IFC_CSOR_NAND_ECC_MODE_4 0x00000000 +/* 8 bit correction per 528 Byte sector */ +#define IFC_CSOR_NAND_ECC_MODE_8 0x10000000 +/* Enable ECC Decoder */ +#define IFC_CSOR_NAND_ECC_DEC_EN 0x04000000 +/* Row Address Length */ +#define IFC_CSOR_NAND_RAL_MASK 0x01800000 +#define IFC_CSOR_NAND_RAL_SHIFT 20 +#define IFC_CSOR_NAND_RAL_1 0x00000000 +#define IFC_CSOR_NAND_RAL_2 0x00800000 +#define IFC_CSOR_NAND_RAL_3 0x01000000 +#define IFC_CSOR_NAND_RAL_4 0x01800000 +/* Page Size 512b, 2k, 4k */ +#define IFC_CSOR_NAND_PGS_MASK 0x00180000 +#define IFC_CSOR_NAND_PGS_SHIFT 16 +#define IFC_CSOR_NAND_PGS_512 0x00000000 +#define IFC_CSOR_NAND_PGS_2K 0x00080000 +#define IFC_CSOR_NAND_PGS_4K 0x00100000 +#define IFC_CSOR_NAND_PGS_8K 0x00180000 +/* Spare region Size */ +#define IFC_CSOR_NAND_SPRZ_MASK 0x0000E000 +#define IFC_CSOR_NAND_SPRZ_SHIFT 13 +#define IFC_CSOR_NAND_SPRZ_16 0x00000000 +#define IFC_CSOR_NAND_SPRZ_64 0x00002000 +#define IFC_CSOR_NAND_SPRZ_128 0x00004000 +#define IFC_CSOR_NAND_SPRZ_210 0x00006000 +#define IFC_CSOR_NAND_SPRZ_218 0x00008000 +#define IFC_CSOR_NAND_SPRZ_224 0x0000A000 +#define IFC_CSOR_NAND_SPRZ_CSOR_EXT 0x0000C000 +/* Pages Per Block */ +#define IFC_CSOR_NAND_PB_MASK 0x00000700 +#define IFC_CSOR_NAND_PB_SHIFT 8 +#define IFC_CSOR_NAND_PB(n) (n-5) << IFC_CSOR_NAND_PB_SHIFT +/* Time for Read Enable High to Output High Impedance */ +#define IFC_CSOR_NAND_TRHZ_MASK 0x0000001C +#define IFC_CSOR_NAND_TRHZ_SHIFT 2 +#define IFC_CSOR_NAND_TRHZ_20 0x00000000 +#define IFC_CSOR_NAND_TRHZ_40 0x00000004 +#define IFC_CSOR_NAND_TRHZ_60 0x00000008 +#define IFC_CSOR_NAND_TRHZ_80 0x0000000C +#define IFC_CSOR_NAND_TRHZ_100 0x00000010 +/* Buffer control disable */ +#define IFC_CSOR_NAND_BCTLD 0x00000001 + +#define FSL_IFC_NAND_BUF_MASK 0xffff0000 +#define FSL_IFC_NOR_BUF_MASK 0xffff0000 + +#define FSL_IFC_NAND_CSPR ((FSL_IFC_NAND_BUF_BASE & FSL_IFC_NAND_BUF_MASK)\ + | IFC_CSPR_PORT_SIZE_8 \ + | IFC_CSPR_MSEL_NAND \ + | IFC_CSPR_V) +#define FSL_IFC_NAND_CSPR_EXT 0x0 +#define FSL_IFC_NAND_AMASK 0xFFFF0000 +#define FSL_IFC_NAND_CSOR (IFC_CSOR_NAND_ECC_ENC_EN /* ECC on encode */ \ + | IFC_CSOR_NAND_ECC_DEC_EN /* ECC on decode */ \ + | IFC_CSOR_NAND_ECC_MODE_4 /* 4-bit ECC */ \ + | IFC_CSOR_NAND_RAL_3 /* RAL = 3 Bytes */ \ + | IFC_CSOR_NAND_PGS_2K /* Page Size = 2K */ \ + | IFC_CSOR_NAND_SPRZ_64 /* Spare size = 64 */ \ + | IFC_CSOR_NAND_PB(6)) /* 2^6 Pages Per Block */ + +/* + * FTIM0 - NOR Flash Mode + */ +#define FSL_IFC_FTIM0_NOR 0xF03F3F3F +#define FSL_IFC_FTIM0_NOR_TACSE_SHIFT 28 +#define FSL_IFC_FTIM0_NOR_TACSE(n) ((n) << FSL_IFC_FTIM0_NOR_TACSE_SHIFT) +#define FSL_IFC_FTIM0_NOR_TEADC_SHIFT 16 +#define FSL_IFC_FTIM0_NOR_TEADC(n) ((n) << FSL_IFC_FTIM0_NOR_TEADC_SHIFT) +#define FSL_IFC_FTIM0_NOR_TAVDS_SHIFT 8 +#define FSL_IFC_FTIM0_NOR_TAVDS(n) ((n) << FSL_IFC_FTIM0_NOR_TAVDS_SHIFT) +#define FSL_IFC_FTIM0_NOR_TEAHC_SHIFT 0 +#define FSL_IFC_FTIM0_NOR_TEAHC(n) ((n) << FSL_IFC_FTIM0_NOR_TEAHC_SHIFT) +/* + * FTIM1 - NOR Flash Mode + */ +#define FSL_IFC_FTIM1_NOR 0xFF003F3F +#define FSL_IFC_FTIM1_NOR_TACO_SHIFT 24 +#define FSL_IFC_FTIM1_NOR_TACO(n) ((n) << FSL_IFC_FTIM1_NOR_TACO_SHIFT) +#define FSL_IFC_FTIM1_NOR_TRAD_NOR_SHIFT 8 +#define FSL_IFC_FTIM1_NOR_TRAD_NOR(n) ((n) << FSL_IFC_FTIM1_NOR_TRAD_NOR_SHIFT) +#define FSL_IFC_FTIM1_NOR_TSEQRAD_NOR_SHIFT 0 +#define FSL_IFC_FTIM1_NOR_TSEQRAD_NOR(n) ((n) << FSL_IFC_FTIM1_NOR_TSEQRAD_NOR_SHIFT) +/* + * FTIM2 - NOR Flash Mode + */ +#define FSL_IFC_FTIM2_NOR 0x0F3CFCFF +#define FSL_IFC_FTIM2_NOR_TCS_SHIFT 24 +#define FSL_IFC_FTIM2_NOR_TCS(n) ((n) << FSL_IFC_FTIM2_NOR_TCS_SHIFT) +#define FSL_IFC_FTIM2_NOR_TCH_SHIFT 18 +#define FSL_IFC_FTIM2_NOR_TCH(n) ((n) << FSL_IFC_FTIM2_NOR_TCH_SHIFT) +#define FSL_IFC_FTIM2_NOR_TWPH_SHIFT 10 +#define FSL_IFC_FTIM2_NOR_TWPH(n) ((n) << FSL_IFC_FTIM2_NOR_TWPH_SHIFT) +#define FSL_IFC_FTIM2_NOR_TWP_SHIFT 0 +#define FSL_IFC_FTIM2_NOR_TWP(n) ((n) << FSL_IFC_FTIM2_NOR_TWP_SHIFT) + +/* + * FTIM0 - Normal GPCM Mode + */ +#define FSL_IFC_FTIM0_GPCM 0xF03F3F3F +#define FSL_IFC_FTIM0_GPCM_TACSE_SHIFT 28 +#define FSL_IFC_FTIM0_GPCM_TACSE(n) ((n) << FSL_IFC_FTIM0_GPCM_TACSE_SHIFT) +#define FSL_IFC_FTIM0_GPCM_TEADC_SHIFT 16 +#define FSL_IFC_FTIM0_GPCM_TEADC(n) ((n) << FSL_IFC_FTIM0_GPCM_TEADC_SHIFT) +#define FSL_IFC_FTIM0_GPCM_TAVDS_SHIFT 8 +#define FSL_IFC_FTIM0_GPCM_TAVDS(n) ((n) << FSL_IFC_FTIM0_GPCM_TAVDS_SHIFT) +#define FSL_IFC_FTIM0_GPCM_TEAHC_SHIFT 0 +#define FSL_IFC_FTIM0_GPCM_TEAHC(n) ((n) << FSL_IFC_FTIM0_GPCM_TEAHC_SHIFT) +/* + * FTIM1 - Normal GPCM Mode + */ +#define FSL_IFC_FTIM1_GPCM 0xFF003F00 +#define FSL_IFC_FTIM1_GPCM_TACO_SHIFT 24 +#define FSL_IFC_FTIM1_GPCM_TACO(n) ((n) << FSL_IFC_FTIM1_GPCM_TACO_SHIFT) +#define FSL_IFC_FTIM1_GPCM_TRAD_SHIFT 8 +#define FSL_IFC_FTIM1_GPCM_TRAD(n) ((n) << FSL_IFC_FTIM1_GPCM_TRAD_SHIFT) +/* + * FTIM2 - Normal GPCM Mode + */ +#define FSL_IFC_FTIM2_GPCM 0x0F3C00FF +#define FSL_IFC_FTIM2_GPCM_TCS_SHIFT 24 +#define FSL_IFC_FTIM2_GPCM_TCS(n) ((n) << FSL_IFC_FTIM2_GPCM_TCS_SHIFT) +#define FSL_IFC_FTIM2_GPCM_TCH_SHIFT 18 +#define FSL_IFC_FTIM2_GPCM_TCH(n) ((n) << FSL_IFC_FTIM2_GPCM_TCH_SHIFT) +#define FSL_IFC_FTIM2_GPCM_TWP_SHIFT 0 +#define FSL_IFC_FTIM2_GPCM_TWP(n) ((n) << FSL_IFC_FTIM2_GPCM_TWP_SHIFT) + + +/** + * fls - find last (most-significant) bit set + * @x: the word to search + * + * This is defined the same way as ffs. + * Note fls(0) = 0, fls(1) = 1, fls(0x80000000) = 32. + */ +static inline int generic_fls(int x) +{ + int r = 32; + + if (!x) + return 0; + if (!(x & 0xffff0000u)) { + x <<= 16; + r -= 16; + } + if (!(x & 0xff000000u)) { + x <<= 8; + r -= 8; + } + if (!(x & 0xf0000000u)) { + x <<= 4; + r -= 4; + } + if (!(x & 0xc0000000u)) { + x <<= 2; + r -= 2; + } + if (!(x & 0x80000000u)) { + x <<= 1; + r -= 1; + } + return r; +} + +static inline int __ilog2(unsigned int x) +{ + return generic_fls(x) - 1; +} + +/* + * Address Mask Register + */ +#define FSL_IFC_AMASK_MASK 0xFFFF0000 +#define FSL_IFC_AMASK_SHIFT 16 +#define FSL_IFC_AMASK(n) (FSL_IFC_AMASK_MASK << \ + (__ilog2(n) - FSL_IFC_AMASK_SHIFT)) +#define FSL_IFC_NOR_AMASK FSL_IFC_AMASK(128*1024*1024) + +#define FSL_IFC_NOR_CSPR ((FSL_IFC_NOR_BUF_BASE & FSL_IFC_NOR_BUF_MASK)\ + | IFC_CSPR_PORT_SIZE_16 \ + | IFC_CSPR_MSEL_NOR \ + | IFC_CSPR_V) +#define FSL_IFC_NOR_CSPR_EXT 0x0 +#define FSL_IFC_NOR_CSOR (IFC_CSOR_NOR_ADM_SHIFT(4) | \ + IFC_CSOR_NOR_TRHZ_80) +#define FSL_IFC_NOR_FTIM0 (FSL_IFC_FTIM0_NOR_TACSE(0x1) | \ + FSL_IFC_FTIM0_NOR_TEADC(0x1) | \ + FSL_IFC_FTIM0_NOR_TAVDS(0x0) | \ + FSL_IFC_FTIM0_NOR_TEAHC(0xc)) +#define FSL_IFC_NOR_FTIM1 (FSL_IFC_FTIM1_NOR_TACO(0x1c) | \ + FSL_IFC_FTIM1_NOR_TRAD_NOR(0xb) |\ + FSL_IFC_FTIM1_NOR_TSEQRAD_NOR(0x9)) +#define FSL_IFC_NOR_FTIM2 (FSL_IFC_FTIM2_NOR_TCS(0x1) | \ + FSL_IFC_FTIM2_NOR_TCH(0x4) | \ + FSL_IFC_FTIM2_NOR_TWPH(0x8) | \ + FSL_IFC_FTIM2_NOR_TWP(0x10)) +#define FSL_IFC_NOR_FTIM3 0x0 + +#define FSL_IFC_NOR_CSPR0 FSL_IFC_NOR_CSPR +#define FSL_IFC_NOR_AMASK0 FSL_IFC_NOR_AMASK +#define FSL_IFC_NOR_CSOR0 FSL_IFC_NOR_CSOR + +#define FSL_IFC_SRAM_BUF_SIZE 0x4000 + +/* CPLD */ + +/* Convert an address into the right format for the CSPR Registers */ +#define IFC_CSPR_PHYS_ADDR(x) (((UINTN)x) & 0xffff0000) + +#define CPLD_BASE_PHYS LS1043A_CPLD_BASE + +#define FSL_IFC_CPLD_CSPR_EXT (0x0) +#define FSL_IFC_CPLD_CSPR (IFC_CSPR_PHYS_ADDR(CPLD_BASE_PHYS) | \ + IFC_CSPR_PORT_SIZE_8 | \ + IFC_CSPR_MSEL_GPCM | \ + IFC_CSPR_V) +#define FSL_IFC_CPLD_AMASK FSL_IFC_AMASK(64 * 1024) +#define FSL_IFC_CPLD_CSOR (IFC_CSOR_NOR_ADM_SHIFT(4) | \ + IFC_CSOR_NOR_NOR_MODE_AVD_NOR | \ + IFC_CSOR_NOR_TRHZ_80) + +/* CPLD Timing parameters for IFC GPCM */ +#define FSL_IFC_CPLD_FTIM0 (FSL_IFC_FTIM0_GPCM_TACSE(0xf) | \ + FSL_IFC_FTIM0_GPCM_TEADC(0xf) | \ + FSL_IFC_FTIM0_GPCM_TEAHC(0xf)) +#define FSL_IFC_CPLD_FTIM1 (FSL_IFC_FTIM1_GPCM_TACO(0xff) | \ + FSL_IFC_FTIM1_GPCM_TRAD(0x3f)) +#define FSL_IFC_CPLD_FTIM2 (FSL_IFC_FTIM2_GPCM_TCS(0xf) | \ + FSL_IFC_FTIM2_GPCM_TCH(0xf) | \ + FSL_IFC_FTIM2_GPCM_TWP(0xff)) +#define FSL_IFC_CPLD_FTIM3 0x0 + +typedef enum { + FSL_IFC_CS0 = 0, + FSL_IFC_CS1, + FSL_IFC_CS2, + FSL_IFC_CS3, + FSL_IFC_CS4, + FSL_IFC_CS5, + FSL_IFC_CS6, + FSL_IFC_CS7, +} FSL_IFC_CHIP_SEL; + +typedef enum { + FSL_IFC_FTIM0 = 0, + FSL_IFC_FTIM1, + FSL_IFC_FTIM2, + FSL_IFC_FTIM3, +} FSL_IFC_FTIMS; + +/* + * Instruction opcodes to be programmed + * in FIR registers- 6bits + */ + +enum ifc_nand_fir_opcodes { + FSL_IFC_FIR_OP_NOP, + FSL_IFC_FIR_OP_CA0, + FSL_IFC_FIR_OP_CA1, + FSL_IFC_FIR_OP_CA2, + FSL_IFC_FIR_OP_CA3, + FSL_IFC_FIR_OP_RA0, + FSL_IFC_FIR_OP_RA1, + FSL_IFC_FIR_OP_RA2, + FSL_IFC_FIR_OP_RA3, + FSL_IFC_FIR_OP_CMD0, + FSL_IFC_FIR_OP_CMD1, + FSL_IFC_FIR_OP_CMD2, + FSL_IFC_FIR_OP_CMD3, + FSL_IFC_FIR_OP_CMD4, + FSL_IFC_FIR_OP_CMD5, + FSL_IFC_FIR_OP_CMD6, + FSL_IFC_FIR_OP_CMD7, + FSL_IFC_FIR_OP_CW0, + FSL_IFC_FIR_OP_CW1, + FSL_IFC_FIR_OP_CW2, + FSL_IFC_FIR_OP_CW3, + FSL_IFC_FIR_OP_CW4, + FSL_IFC_FIR_OP_CW5, + FSL_IFC_FIR_OP_CW6, + FSL_IFC_FIR_OP_CW7, + FSL_IFC_FIR_OP_WBCD, + FSL_IFC_FIR_OP_RBCD, + FSL_IFC_FIR_OP_BTRD, + FSL_IFC_FIR_OP_RDSTAT, + FSL_IFC_FIR_OP_NWAIT, + FSL_IFC_FIR_OP_WFR, + FSL_IFC_FIR_OP_SBRD, + FSL_IFC_FIR_OP_UA, + FSL_IFC_FIR_OP_RB, +}; + +typedef struct { + UINT32 cspr_ext; + UINT32 cspr; + UINT32 res; +} FSL_IFC_CSPR; + +typedef struct { + UINT32 amask; + UINT32 res[0x2]; +} FSL_IFC_AMASK; + +typedef struct { + UINT32 csor; + UINT32 csor_ext; + UINT32 res; +} FSL_IFC_CSOR; + +typedef struct { + UINT32 ftim[4]; + UINT32 res[0x8]; +}FSL_IFC_FTIM ; + +typedef struct { + UINT32 ncfgr; + UINT32 res1[0x4]; + UINT32 nand_fcr0; + UINT32 nand_fcr1; + UINT32 res2[0x8]; + UINT32 row0; + UINT32 res3; + UINT32 col0; + UINT32 res4; + UINT32 row1; + UINT32 res5; + UINT32 col1; + UINT32 res6; + UINT32 row2; + UINT32 res7; + UINT32 col2; + UINT32 res8; + UINT32 row3; + UINT32 res9; + UINT32 col3; + UINT32 res10[0x24]; + UINT32 nand_fbcr; + UINT32 res11; + UINT32 nand_fir0; + UINT32 nand_fir1; + UINT32 nand_fir2; + UINT32 res12[0x10]; + UINT32 nand_csel; + UINT32 res13; + UINT32 nandseq_strt; + UINT32 res14; + UINT32 nand_evter_stat; + UINT32 res15; + UINT32 pgrdcmpl_evt_stat; + UINT32 res16[0x2]; + UINT32 nand_evter_en; + UINT32 res17[0x2]; + UINT32 nand_evter_intr_en; + UINT32 res18[0x2]; + UINT32 nand_erattr0; + UINT32 nand_erattr1; + UINT32 res19[0x10]; + UINT32 nand_fsr; + UINT32 res20; + UINT32 nand_eccstat[4]; + UINT32 res21[0x20]; + UINT32 nanndcr; + UINT32 res22[0x2]; + UINT32 nand_autoboot_trgr; + UINT32 res23; + UINT32 nand_mdr; + UINT32 res24[0x5C]; +} FSL_IFC_NAND; + +/* + * IFC controller NOR Machine registers + */ +typedef struct { + UINT32 nor_evter_stat; + UINT32 res1[0x2]; + UINT32 nor_evter_en; + UINT32 res2[0x2]; + UINT32 nor_evter_intr_en; + UINT32 res3[0x2]; + UINT32 nor_erattr0; + UINT32 nor_erattr1; + UINT32 nor_erattr2; + UINT32 res4[0x4]; + UINT32 norcr; + UINT32 res5[0xEF]; +} FSL_IFC_NOR; + +/* + * IFC controller GPCM Machine registers + */ +typedef struct { + UINT32 gpcm_evter_stat; + UINT32 res1[0x2]; + UINT32 gpcm_evter_en; + UINT32 res2[0x2]; + UINT32 gpcm_evter_intr_en; + UINT32 res3[0x2]; + UINT32 gpcm_erattr0; + UINT32 gpcm_erattr1; + UINT32 gpcm_erattr2; + UINT32 gpcm_stat; +} FSL_IFC_GPCM; + +/* + * IFC Controller Registers + */ +typedef struct { + UINT32 ifc_rev; + UINT32 res1[0x2]; + FSL_IFC_CSPR cspr_cs[FSL_IFC_BANK_COUNT]; + UINT8 res2[FSL_IFC_CSPR_REG_LEN - FSL_IFC_CSPR_USED_LEN]; + FSL_IFC_AMASK amask_cs[FSL_IFC_BANK_COUNT]; + UINT8 res3[FSL_IFC_AMASK_REG_LEN - FSL_IFC_AMASK_USED_LEN]; + FSL_IFC_CSOR csor_cs[FSL_IFC_BANK_COUNT]; + UINT8 res4[FSL_IFC_CSOR_REG_LEN - FSL_IFC_CSOR_USED_LEN]; + FSL_IFC_FTIM ftim_cs[FSL_IFC_BANK_COUNT]; + UINT8 res5[FSL_IFC_FTIM_REG_LEN - FSL_IFC_FTIM_USED_LEN]; + UINT32 rb_stat; + UINT32 rb_map; + UINT32 wp_map; + UINT32 ifc_gcr; + UINT32 res7[0x2]; + UINT32 cm_evter_stat; + UINT32 res8[0x2]; + UINT32 cm_evter_en; + UINT32 res9[0x2]; + UINT32 cm_evter_intr_en; + UINT32 res10[0x2]; + UINT32 cm_erattr0; + UINT32 cm_erattr1; + UINT32 res11[0x2]; + UINT32 ifc_ccr; + UINT32 ifc_csr; + UINT32 ddr_ccr_low; + UINT32 res12[0x2EA]; + FSL_IFC_NAND ifc_nand; + FSL_IFC_NOR ifc_nor; + FSL_IFC_GPCM ifc_gpcm; +} FSL_IFC_REGS; + +VOID IfcNorInit(VOID); + +VOID IfcNandInit(VOID); + +#define FSL_IFC_REGS_BASE \ + ((FSL_IFC_REGS *)FSL_IFC_REG_BASE) + +#endif //__FLASH_H__ diff --git a/Platforms/Nxp/LS1043aRdb/Library/CpldLib/CpldLib.c b/Platforms/Nxp/LS1043aRdb/Library/CpldLib/CpldLib.c new file mode 100644 index 0000000..fe115c8 --- /dev/null +++ b/Platforms/Nxp/LS1043aRdb/Library/CpldLib/CpldLib.c @@ -0,0 +1,157 @@ +/** @CpldLib.c + Cpld specific Library for LS1043A-RDB board, containing functions to + program and read the Cpld registers. + + Copyright (c) 2016, Freescale Semiconductor, Inc. All rights reserved. + + This program and the accompanying materials + are licensed and made available under the terms and conditions of the BSD License + which accompanies this distribution. The full text of the license may be found at + http://opensource.org/licenses/bsd-license.php + + THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, + WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. + +**/ + +#include <Base.h> +#include <PiPei.h> +#include <Uefi.h> + +#include <Library/BaseLib.h> +#include <Library/DebugLib.h> +#include <Library/IoLib.h> +#include <Library/PrintLib.h> +#include <Library/SerialPortLib.h> + +#include <Library/PlatformLib.h> +#include <Library/CpldLib.h> +#include <Library/FslIfc.h> + +UINT8 +CpldRead ( + OUT UINTN Reg + ) +{ + VOID *Base = (VOID *)LS1043A_CPLD_BASE; + + return MmioRead8((UINTN)(Base + Reg)); +} + +VOID +CpldWrite ( + IN UINTN Reg, + IN UINT8 Value + ) +{ + VOID *Base = (VOID *)LS1043A_CPLD_BASE; + + MmioWrite8((UINTN)(Base + Reg), Value); +} + +/* Set the boot bank to the alternate bank */ +VOID +CpldSetAlternatebank ( + VOID + ) +{ + UINT8 Reg4 = CPLD_READ(SoftMuxOn); + UINT8 Reg7 = CPLD_READ(Vbank); + + CPLD_WRITE(SoftMuxOn, Reg4 | CPLD_SW_MUX_BANK_SEL); + + Reg7 = (Reg7 & ~CPLD_BANK_SEL_MASK) | CPLD_BANK_SEL_ALTBANK; + CPLD_WRITE(Vbank, Reg7); + + CPLD_WRITE(SystemReset, 1); +} + +/* Set the boot bank to the default bank */ +VOID +CpldSetDefaultBank ( + VOID + ) +{ + CPLD_WRITE(GlobalReset, 1); +} + +VOID +CpldDumpRegs ( + VOID + ) +{ + DEBUG((EFI_D_INFO, "CpldVersionMajor = %x\n", CPLD_READ(CpldVersionMajor))); + DEBUG((EFI_D_INFO, "CpldVersionMinor = %x\n", CPLD_READ(CpldVersionMinor))); + DEBUG((EFI_D_INFO, "PcbaVersion = %x\n", CPLD_READ(PcbaVersion))); + DEBUG((EFI_D_INFO, "SoftMuxOn = %x\n", CPLD_READ(SoftMuxOn))); + DEBUG((EFI_D_INFO, "RcwSource1 = %x\n", CPLD_READ(RcwSource1))); + DEBUG((EFI_D_INFO, "RcwSource2 = %x\n", CPLD_READ(RcwSource2))); + DEBUG((EFI_D_INFO, "Vbank = %x\n", CPLD_READ(Vbank))); + DEBUG((EFI_D_INFO, "SysclkSelect = %x\n", CPLD_READ(SysclkSelect))); + DEBUG((EFI_D_INFO, "UartSel = %x\n", CPLD_READ(UartSel))); + DEBUG((EFI_D_INFO, "Sd1RefClkSel = %x\n", CPLD_READ(Sd1RefClkSel))); + DEBUG((EFI_D_INFO, "TdmClkMuxSel = %x\n", CPLD_READ(TdmClkMuxSel))); + DEBUG((EFI_D_INFO, "SdhcSpiCsSel = %x\n", CPLD_READ(SdhcSpiCsSel))); + DEBUG((EFI_D_INFO, "StatusLed = %x\n", CPLD_READ(StatusLed))); +} + +VOID +CpldRevBit ( + OUT UINT8 *Value + ) +{ + UINT8 Rev, Val; + UINTN Index; + + Val = *Value; + Rev = Val & 1; + for (Index = 1; Index <= 7; Index++) { + Val >>= 1; + Rev <<= 1; + Rev |= Val & 1; + } + + *Value = Rev; +} + +VOID +DoCpld ( + IN CpldCmd Cmd + ) +{ + switch (Cmd) { + case RESET: + CpldSetDefaultBank(); + break; + case RESET_ALTBANK: + CpldSetAlternatebank(); + break; + case DUMP_REGISTERS: + CpldDumpRegs(); + break; + default: + DEBUG((EFI_D_ERROR, "Error: Unknown Cpld Command!\n")); + break; + } +} + +VOID +CpldInit ( + VOID + ) +{ + MmioWriteBe32((UINTN) &(FSL_IFC_REGS_BASE)->cspr_cs[FSL_IFC_CS2].cspr_ext, FSL_IFC_CPLD_CSPR_EXT); + + MmioWriteBe32((UINTN) &(FSL_IFC_REGS_BASE)->ftim_cs[FSL_IFC_CS2].ftim[FSL_IFC_FTIM0], + FSL_IFC_CPLD_FTIM0); + MmioWriteBe32((UINTN) &(FSL_IFC_REGS_BASE)->ftim_cs[FSL_IFC_CS2].ftim[FSL_IFC_FTIM1], + FSL_IFC_CPLD_FTIM1); + MmioWriteBe32((UINTN) &(FSL_IFC_REGS_BASE)->ftim_cs[FSL_IFC_CS2].ftim[FSL_IFC_FTIM2], + FSL_IFC_CPLD_FTIM2); + MmioWriteBe32((UINTN) &(FSL_IFC_REGS_BASE)->ftim_cs[FSL_IFC_CS2].ftim[FSL_IFC_FTIM3], + FSL_IFC_CPLD_FTIM3); + + MmioWriteBe32((UINTN) &(FSL_IFC_REGS_BASE)->csor_cs[FSL_IFC_CS2].csor, FSL_IFC_CPLD_CSOR); + MmioWriteBe32((UINTN) &(FSL_IFC_REGS_BASE)->amask_cs[FSL_IFC_CS2].amask, FSL_IFC_CPLD_AMASK); + MmioWriteBe32((UINTN) &(FSL_IFC_REGS_BASE)->cspr_cs[FSL_IFC_CS2].cspr, FSL_IFC_CPLD_CSPR); +} diff --git a/Platforms/Nxp/LS1043aRdb/Library/CpldLib/CpldLib.inf b/Platforms/Nxp/LS1043aRdb/Library/CpldLib/CpldLib.inf new file mode 100644 index 0000000..f37d153 --- /dev/null +++ b/Platforms/Nxp/LS1043aRdb/Library/CpldLib/CpldLib.inf @@ -0,0 +1,33 @@ +#/* @CpldLib.inf +# Copyright (c) 2016, Freescale Semiconductor, Inc. All rights reserved. +# +# This program and the accompanying materials +# are licensed and made available under the terms and conditions of the BSD License +# which accompanies this distribution. The full text of the license may be found at +# http://opensource.org/licenses/bsd-license.php +# +# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, +# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. +# +#*/ + +[Defines] + INF_VERSION = 0x00010005 + BASE_NAME = CpldLib + FILE_GUID = 5962d040-8b8a-11df-9a71-0002a5d5c51b + MODULE_TYPE = BASE + VERSION_STRING = 1.0 + LIBRARY_CLASS = CpldLib + +[Sources.common] + CpldLib.c + +[Packages] + MdePkg/MdePkg.dec + ArmPkg/ArmPkg.dec + ArmPlatformPkg/ArmPlatformPkg.dec + OpenPlatformPkg/Platforms/Nxp/LS1043aRdb/LS1043aRdbPkg.dec + +[LibraryClasses] + BaseLib + IoLib
On 17 October 2016 at 21:04, Bhupesh Sharma bhupesh.sharma@freescale.com wrote:
From: Sakar Arora sakar.arora@nxp.com
NXP/FSL's LS1043A-RDB board houses a CPLD (FPGA) which can be used to control various pin-multiplexing options, which allows certain combinations of peripherals to be enabled on the board.
In addition this CPLD provides a mechanism to divide the NOR/NAND flash memory into primary and alternate regions. While golden images can be flashed on the primary bank, experimental images can be flashed on the alternate bank.
CPLD provides a way to switch from primary to alternate region (and vice-versa), thus protecting the board from damage if primary region is flashed with incorrect set of images.
Signed-off-by: Sakar Arora sakar.arora@nxp.com Signed-off-by: Bhupesh Sharma bhupesh.sharma@nxp.com
Platforms/Nxp/LS1043aRdb/Include/Library/CpldLib.h | 75 +++ Platforms/Nxp/LS1043aRdb/Include/Library/FslIfc.h | 721 +++++++++++++++++++++ Platforms/Nxp/LS1043aRdb/Library/CpldLib/CpldLib.c | 157 +++++ .../Nxp/LS1043aRdb/Library/CpldLib/CpldLib.inf | 33 + 4 files changed, 986 insertions(+) create mode 100644 Platforms/Nxp/LS1043aRdb/Include/Library/CpldLib.h create mode 100644 Platforms/Nxp/LS1043aRdb/Include/Library/FslIfc.h create mode 100644 Platforms/Nxp/LS1043aRdb/Library/CpldLib/CpldLib.c create mode 100644 Platforms/Nxp/LS1043aRdb/Library/CpldLib/CpldLib.inf
diff --git a/Platforms/Nxp/LS1043aRdb/Include/Library/CpldLib.h b/Platforms/Nxp/LS1043aRdb/Include/Library/CpldLib.h
Please add this library class to the package .dec file
new file mode 100644 index 0000000..56f47da --- /dev/null +++ b/Platforms/Nxp/LS1043aRdb/Include/Library/CpldLib.h @@ -0,0 +1,75 @@ +/** CpldLib.h +* Header defining the LS1043a Cpld specific constants (Base addresses, sizes, flags) +* +* Copyright (c) 2016, Freescale Semiconductor, Inc. All rights reserved. +* +* This program and the accompanying materials +* are licensed and made available under the terms and conditions of the BSD License +* which accompanies this distribution. The full text of the license may be found at +* http://opensource.org/licenses/bsd-license.php +* +* THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, +* WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. +* +**/
+#ifndef __LS1043A_CPLD_H__ +#define __LS1043A_CPLD_H__
+#include <Library/Common.h>
+/*
- CPLD register set of LS1043ARDB board-specific.
- */
+struct CpldRegSet {
UINT8 CpldVersionMajor; /* 0x0 - CPLD Major Revision Register */
UINT8 CpldVersionMinor; /* 0x1 - CPLD Minor Revision Register */
UINT8 PcbaVersion; /* 0x2 - PCBA Revision Register */
UINT8 SystemReset; /* 0x3 - system reset register */
UINT8 SoftMuxOn; /* 0x4 - Switch Control Enable Register */
UINT8 RcwSource1; /* 0x5 - Reset config word 1 */
UINT8 RcwSource2; /* 0x6 - Reset config word 1 */
UINT8 Vbank; /* 0x7 - Flash bank selection Control */
UINT8 SysclkSelect; /* 0x8 - */
UINT8 UartSel; /* 0x9 - */
UINT8 Sd1RefClkSel; /* 0xA - */
UINT8 TdmClkMuxSel; /* 0xB - */
UINT8 SdhcSpiCsSel; /* 0xC - */
UINT8 StatusLed; /* 0xD - */
UINT8 GlobalReset; /* 0xE - */
+};
+/*
- Reset the board, Reset to alternate bank or Dump registers:
- RESET - reset to default bank
- RESET_ALTBANK - reset to alternate bank
- DUMP_REGISTERS - display the CPLD registers
- */
+typedef enum {
RESET = 0,
RESET_ALTBANK,
DUMP_REGISTERS
+} CpldCmd;
+UINT8 CpldRead(UINTN Reg); +VOID CpldWrite(UINTN Reg, UINT8 Value); +VOID CpldRevBit(UINT8 *Value); +VOID DoCpld (CpldCmd Cmd); +VOID CpldInit (VOID);
+#define CPLD_READ(Reg) CpldRead(offsetof(struct CpldRegSet, Reg)) +#define CPLD_WRITE(Reg, Value) \
CpldWrite(offsetof(struct CpldRegSet, Reg), Value)
+/* CPLD on IFC */ +#define CPLD_SW_MUX_BANK_SEL 0x40 +#define CPLD_BANK_SEL_MASK 0x07 +#define CPLD_BANK_SEL_ALTBANK 0x04
+/* SDXC/DSPI CPLD Settings */ +#define ENABLE_SDXC_SOFT_MUX 0x30 +#define ENABLE_RCW_SOFT_MUX 0x01 +#define SELECT_SW4_SDXC 0x40 +#define SELECT_SW5_SDXC 0x01
+#endif diff --git a/Platforms/Nxp/LS1043aRdb/Include/Library/FslIfc.h b/Platforms/Nxp/LS1043aRdb/Include/Library/FslIfc.h
If this is an internal header, keep it with the .c files. Include/Library should only contain header files that define APIs that are exposed via LibraryClasses
new file mode 100644 index 0000000..27c8295 --- /dev/null +++ b/Platforms/Nxp/LS1043aRdb/Include/Library/FslIfc.h @@ -0,0 +1,721 @@ +/** @FslIfc.h
- Copyright (c) 2008 - 2009, Apple Inc. All rights reserved.<BR>
- Copyright (c) 2016, Freescale Semiconductor, Inc. All rights reserved.
- This program and the accompanying materials
- are licensed and made available under the terms and conditions of the BSD License
- which accompanies this distribution. The full text of the license may be found at
- http://opensource.org/licenses/bsd-license.php
- THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
- WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
+**/
+#ifndef __FLASH_H__ +#define __FLASH_H__
+#include <Uefi.h>
+#include <Library/BaseLib.h> +#include <Library/BaseMemoryLib.h> +#include <Library/MemoryAllocationLib.h> +#include <Library/DebugLib.h> +#include <Library/IoLib.h> +#include <Library/PcdLib.h> +#include <Library/UefiBootServicesTableLib.h> +#include <Library/IoLib.h> +#include <Library/PlatformLib.h>
+#include <Protocol/BlockIo.h> +#include <Protocol/Cpu.h>
+#define NOIBR
+#define FSL_IFC_BANK_COUNT 4
+#define NAND_PAGE_SIZE_2K (2048) +#define NAND_SPARE_AREA_SIZE_64B (64) +#define NAND_BLOCK_SIZE_128K (128*1024) +#define NAND_BLOCK_COUNT (2048) +#define NAND_LAST_BLOCK (NAND_BLOCK_COUNT - 1)
+//List of commands. +#define IFC_NAND_CMD_RESET 0xFF +#define IFC_NAND_CMD_READID 0x90
+#define IFC_NAND_CMD_STATUS 0x70
+#define IFC_NAND_CMD_READ0 0x00 +#define IFC_NAND_CMD_READSTART 0x30
+#define IFC_NAND_CMD_ERASE1 0x60 +#define IFC_NAND_CMD_ERASE2 0xD0
+#define IFC_NAND_CMD_SEQIN 0x80 +#define IFC_NAND_CMD_PAGEPROG 0x10
+#define MAX_RETRY_COUNT 150000
+#define FSL_IFC_REG_BASE 0x1530000 +#define FSL_IFC_NAND_BUF_BASE 0x70000000 +#define FSL_IFC_NOR_BUF_BASE 0x60000000
+#define FSL_IFC_NOR_RESERVED_REGION_BASE 0x60700000
+#define FSL_IFC_CSPR_REG_LEN 148 +#define FSL_IFC_AMASK_REG_LEN 144 +#define FSL_IFC_CSOR_REG_LEN 144 +#define FSL_IFC_FTIM_REG_LEN 576
+#define FSL_IFC_NAND_SEQ_STRT_FIR_STRT 0x80000000
+#define FSL_IFC_CSPR_USED_LEN sizeof(FSL_IFC_CSPR) * \
FSL_IFC_BANK_COUNT
+#define FSL_IFC_AMASK_USED_LEN sizeof(FSL_IFC_AMASK) * \
FSL_IFC_BANK_COUNT
+#define FSL_IFC_CSOR_USED_LEN sizeof(FSL_IFC_CSOR) * \
FSL_IFC_BANK_COUNT
+#define FSL_IFC_FTIM_USED_LEN sizeof(FSL_IFC_FTIM) * \
FSL_IFC_BANK_COUNT
+/*
- NAND Event and Error Status Register (NAND_EVTER_STAT)
- */
+/* Operation Complete */ +#define FSL_IFC_NAND_EVTER_STAT_OPC 0x80000000 +/* Flash Timeout Error */ +#define FSL_IFC_NAND_EVTER_STAT_FTOER 0x08000000 +/* Write Protect Error */ +#define FSL_IFC_NAND_EVTER_STAT_WPER 0x04000000 +/* ECC Error */ +#define FSL_IFC_NAND_EVTER_STAT_ECCER 0x02000000
+/*
- NAND Flash Byte Count Register (NAND_BC)
- */
+/* Byte Count for read/Write */ +#define FSL_IFC_NAND_BC 0x000001FF
+/*
- NAND Flash Instruction Registers (NAND_FIR0/NAND_FIR1/NAND_FIR2)
- */
+/* NAND Machine specific opcodes OP0-OP14*/ +#define FSL_IFC_NAND_FIR0_OP0 0xFC000000 +#define FSL_IFC_NAND_FIR0_OP0_SHIFT 26 +#define FSL_IFC_NAND_FIR0_OP1 0x03F00000 +#define FSL_IFC_NAND_FIR0_OP1_SHIFT 20 +#define FSL_IFC_NAND_FIR0_OP2 0x000FC000 +#define FSL_IFC_NAND_FIR0_OP2_SHIFT 14 +#define FSL_IFC_NAND_FIR0_OP3 0x00003F00 +#define FSL_IFC_NAND_FIR0_OP3_SHIFT 8 +#define FSL_IFC_NAND_FIR0_OP4 0x000000FC +#define FSL_IFC_NAND_FIR0_OP4_SHIFT 2 +#define FSL_IFC_NAND_FIR1_OP5 0xFC000000 +#define FSL_IFC_NAND_FIR1_OP5_SHIFT 26 +#define FSL_IFC_NAND_FIR1_OP6 0x03F00000 +#define FSL_IFC_NAND_FIR1_OP6_SHIFT 20 +#define FSL_IFC_NAND_FIR1_OP7 0x000FC000 +#define FSL_IFC_NAND_FIR1_OP7_SHIFT 14 +#define FSL_IFC_NAND_FIR1_OP8 0x00003F00 +#define FSL_IFC_NAND_FIR1_OP8_SHIFT 8 +#define FSL_IFC_NAND_FIR1_OP9 0x000000FC +#define FSL_IFC_NAND_FIR1_OP9_SHIFT 2 +#define FSL_IFC_NAND_FIR2_OP10 0xFC000000 +#define FSL_IFC_NAND_FIR2_OP10_SHIFT 26 +#define FSL_IFC_NAND_FIR2_OP11 0x03F00000 +#define FSL_IFC_NAND_FIR2_OP11_SHIFT 20 +#define FSL_IFC_NAND_FIR2_OP12 0x000FC000 +#define FSL_IFC_NAND_FIR2_OP12_SHIFT 14 +#define FSL_IFC_NAND_FIR2_OP13 0x00003F00 +#define FSL_IFC_NAND_FIR2_OP13_SHIFT 8 +#define FSL_IFC_NAND_FIR2_OP14 0x000000FC +#define FSL_IFC_NAND_FIR2_OP14_SHIFT 2
+/*
- NAND Flash Command Registers (NAND_FCR0/NAND_FCR1)
- */
+/* General purpose FCM flash command bytes CMD0-CMD7 */ +#define FSL_IFC_NAND_FCR0_CMD0 0xFF000000 +#define FSL_IFC_NAND_FCR0_CMD0_SHIFT 24 +#define FSL_IFC_NAND_FCR0_CMD1 0x00FF0000 +#define FSL_IFC_NAND_FCR0_CMD1_SHIFT 16 +#define FSL_IFC_NAND_FCR0_CMD2 0x0000FF00 +#define FSL_IFC_NAND_FCR0_CMD2_SHIFT 8 +#define FSL_IFC_NAND_FCR0_CMD3 0x000000FF +#define FSL_IFC_NAND_FCR0_CMD3_SHIFT 0 +#define FSL_IFC_NAND_FCR1_CMD4 0xFF000000 +#define FSL_IFC_NAND_FCR1_CMD4_SHIFT 24 +#define FSL_IFC_NAND_FCR1_CMD5 0x00FF0000 +#define FSL_IFC_NAND_FCR1_CMD5_SHIFT 16 +#define FSL_IFC_NAND_FCR1_CMD6 0x0000FF00 +#define FSL_IFC_NAND_FCR1_CMD6_SHIFT 8 +#define FSL_IFC_NAND_FCR1_CMD7 0x000000FF +#define FSL_IFC_NAND_FCR1_CMD7_SHIFT 0
+/* Timing registers for NAND Flash */
+#define FSL_IFC_FTIM0_NAND_TCCST_SHIFT 25 +#define FSL_IFC_FTIM0_NAND_TCCST(n) ((n) << FSL_IFC_FTIM0_NAND_TCCST_SHIFT) +#define FSL_IFC_FTIM0_NAND_TWP_SHIFT 16 +#define FSL_IFC_FTIM0_NAND_TWP(n) ((n) << FSL_IFC_FTIM0_NAND_TWP_SHIFT) +#define FSL_IFC_FTIM0_NAND_TWCHT_SHIFT 8 +#define FSL_IFC_FTIM0_NAND_TWCHT(n) ((n) << FSL_IFC_FTIM0_NAND_TWCHT_SHIFT) +#define FSL_IFC_FTIM0_NAND_TWH_SHIFT 0 +#define FSL_IFC_FTIM0_NAND_TWH(n) ((n) << FSL_IFC_FTIM0_NAND_TWH_SHIFT) +#define FSL_IFC_FTIM1_NAND_TADLE_SHIFT 24 +#define FSL_IFC_FTIM1_NAND_TADLE(n) ((n) << FSL_IFC_FTIM1_NAND_TADLE_SHIFT) +#define FSL_IFC_FTIM1_NAND_TWBE_SHIFT 16 +#define FSL_IFC_FTIM1_NAND_TWBE(n) ((n) << FSL_IFC_FTIM1_NAND_TWBE_SHIFT) +#define FSL_IFC_FTIM1_NAND_TRR_SHIFT 8 +#define FSL_IFC_FTIM1_NAND_TRR(n) ((n) << FSL_IFC_FTIM1_NAND_TRR_SHIFT) +#define FSL_IFC_FTIM1_NAND_TRP_SHIFT 0 +#define FSL_IFC_FTIM1_NAND_TRP(n) ((n) << FSL_IFC_FTIM1_NAND_TRP_SHIFT) +#define FSL_IFC_FTIM2_NAND_TRAD_SHIFT 21 +#define FSL_IFC_FTIM2_NAND_TRAD(n) ((n) << FSL_IFC_FTIM2_NAND_TRAD_SHIFT) +#define FSL_IFC_FTIM2_NAND_TREH_SHIFT 11 +#define FSL_IFC_FTIM2_NAND_TREH(n) ((n) << FSL_IFC_FTIM2_NAND_TREH_SHIFT) +#define FSL_IFC_FTIM2_NAND_TWHRE_SHIFT 0 +#define FSL_IFC_FTIM2_NAND_TWHRE(n) ((n) << FSL_IFC_FTIM2_NAND_TWHRE_SHIFT) +#define FSL_IFC_FTIM3_NAND_TWW_SHIFT 24 +#define FSL_IFC_FTIM3_NAND_TWW(n) ((n) << FSL_IFC_FTIM3_NAND_TWW_SHIFT)
+/*
- Flash ROW and COL Address Register (ROWn, COLn)
- */
+/* Main/spare region locator */ +#define FSL_IFC_NAND_COL_MS 0x80000000 +/* Column Address */ +#define FSL_IFC_NAND_COL_CA_MASK 0x00000FFF
+#define NAND_STATUS_WP 0x80
+/*
- NAND Event and Error Enable Register (NAND_EVTER_EN)
- */
+/* Operation complete event enable */ +#define FSL_IFC_NAND_EVTER_EN_OPC_EN 0x80000000 +/* Page read complete event enable */ +#define FSL_IFC_NAND_EVTER_EN_PGRDCMPL_EN 0x20000000 +/* Flash Timeout error enable */ +#define FSL_IFC_NAND_EVTER_EN_FTOER_EN 0x08000000 +/* Write Protect error enable */ +#define FSL_IFC_NAND_EVTER_EN_WPER_EN 0x04000000 +/* ECC error logging enable */ +#define FSL_IFC_NAND_EVTER_EN_ECCER_EN 0x02000000
+/*
- CSPR - Chip Select Property Register
- */
+#define IFC_CSPR_BA 0xFFFF0000 +#define IFC_CSPR_BA_SHIFT 16 +#define IFC_CSPR_PORT_SIZE 0x00000180 +#define IFC_CSPR_PORT_SIZE_SHIFT 7 +/* Port Size 8 bit */ +#define IFC_CSPR_PORT_SIZE_8 0x00000080 +/* Port Size 16 bit */ +#define IFC_CSPR_PORT_SIZE_16 0x00000100 +/* Port Size 32 bit */ +#define IFC_CSPR_PORT_SIZE_32 0x00000180 +/* Write Protect */ +#define IFC_CSPR_WP 0x00000040 +#define IFC_CSPR_WP_SHIFT 6 +/* Machine Select */ +#define IFC_CSPR_MSEL 0x00000006 +#define IFC_CSPR_MSEL_SHIFT 1 +/* NOR */ +#define IFC_CSPR_MSEL_NOR 0x00000000 +/* NAND */ +#define IFC_CSPR_MSEL_NAND 0x00000002 +/* GPCM */ +#define IFC_CSPR_MSEL_GPCM 0x00000004 +/* Bank Valid */ +#define IFC_CSPR_V 0x00000001 +#define IFC_CSPR_V_SHIFT 0
+/*
- Chip Select Option Register - NOR Flash Mode
- */
+/* Enable Address shift Mode */ +#define IFC_CSOR_NOR_ADM_SHFT_MODE_EN 0x80000000 +/* Page Read Enable from NOR device */ +#define IFC_CSOR_NOR_PGRD_EN 0x10000000 +/* AVD Toggle Enable during Burst Program */ +#define IFC_CSOR_NOR_AVD_TGL_PGM_EN 0x01000000 +/* Address Data Multiplexing Shift */ +#define IFC_CSOR_NOR_ADM_MASK 0x0003E000 +#define IFC_CSOR_NOR_ADM_SHIFT_SHIFT 13 +#define IFC_CSOR_NOR_ADM_SHIFT(n) ((n) << IFC_CSOR_NOR_ADM_SHIFT_SHIFT) +/* Type of the NOR device hooked */ +#define IFC_CSOR_NOR_NOR_MODE_AYSNC_NOR 0x00000000 +#define IFC_CSOR_NOR_NOR_MODE_AVD_NOR 0x00000020 +/* Time for Read Enable High to Output High Impedance */ +#define IFC_CSOR_NOR_TRHZ_MASK 0x0000001C +#define IFC_CSOR_NOR_TRHZ_SHIFT 2 +#define IFC_CSOR_NOR_TRHZ_20 0x00000000 +#define IFC_CSOR_NOR_TRHZ_40 0x00000004 +#define IFC_CSOR_NOR_TRHZ_60 0x00000008 +#define IFC_CSOR_NOR_TRHZ_80 0x0000000C +#define IFC_CSOR_NOR_TRHZ_100 0x00000010 +/* Buffer control disable */ +#define IFC_CSOR_NOR_BCTLD 0x00000001
+/*
- Chip Select Option Register FSL_IFC_NAND Machine
- */
+/* Enable ECC Encoder */ +#define IFC_CSOR_NAND_ECC_ENC_EN 0x80000000 +#define IFC_CSOR_NAND_ECC_MODE_MASK 0x30000000 +/* 4 bit correction per 520 Byte sector */ +#define IFC_CSOR_NAND_ECC_MODE_4 0x00000000 +/* 8 bit correction per 528 Byte sector */ +#define IFC_CSOR_NAND_ECC_MODE_8 0x10000000 +/* Enable ECC Decoder */ +#define IFC_CSOR_NAND_ECC_DEC_EN 0x04000000 +/* Row Address Length */ +#define IFC_CSOR_NAND_RAL_MASK 0x01800000 +#define IFC_CSOR_NAND_RAL_SHIFT 20 +#define IFC_CSOR_NAND_RAL_1 0x00000000 +#define IFC_CSOR_NAND_RAL_2 0x00800000 +#define IFC_CSOR_NAND_RAL_3 0x01000000 +#define IFC_CSOR_NAND_RAL_4 0x01800000 +/* Page Size 512b, 2k, 4k */ +#define IFC_CSOR_NAND_PGS_MASK 0x00180000 +#define IFC_CSOR_NAND_PGS_SHIFT 16 +#define IFC_CSOR_NAND_PGS_512 0x00000000 +#define IFC_CSOR_NAND_PGS_2K 0x00080000 +#define IFC_CSOR_NAND_PGS_4K 0x00100000 +#define IFC_CSOR_NAND_PGS_8K 0x00180000 +/* Spare region Size */ +#define IFC_CSOR_NAND_SPRZ_MASK 0x0000E000 +#define IFC_CSOR_NAND_SPRZ_SHIFT 13 +#define IFC_CSOR_NAND_SPRZ_16 0x00000000 +#define IFC_CSOR_NAND_SPRZ_64 0x00002000 +#define IFC_CSOR_NAND_SPRZ_128 0x00004000 +#define IFC_CSOR_NAND_SPRZ_210 0x00006000 +#define IFC_CSOR_NAND_SPRZ_218 0x00008000 +#define IFC_CSOR_NAND_SPRZ_224 0x0000A000 +#define IFC_CSOR_NAND_SPRZ_CSOR_EXT 0x0000C000 +/* Pages Per Block */ +#define IFC_CSOR_NAND_PB_MASK 0x00000700 +#define IFC_CSOR_NAND_PB_SHIFT 8 +#define IFC_CSOR_NAND_PB(n) (n-5) << IFC_CSOR_NAND_PB_SHIFT +/* Time for Read Enable High to Output High Impedance */ +#define IFC_CSOR_NAND_TRHZ_MASK 0x0000001C +#define IFC_CSOR_NAND_TRHZ_SHIFT 2 +#define IFC_CSOR_NAND_TRHZ_20 0x00000000 +#define IFC_CSOR_NAND_TRHZ_40 0x00000004 +#define IFC_CSOR_NAND_TRHZ_60 0x00000008 +#define IFC_CSOR_NAND_TRHZ_80 0x0000000C +#define IFC_CSOR_NAND_TRHZ_100 0x00000010 +/* Buffer control disable */ +#define IFC_CSOR_NAND_BCTLD 0x00000001
+#define FSL_IFC_NAND_BUF_MASK 0xffff0000 +#define FSL_IFC_NOR_BUF_MASK 0xffff0000
+#define FSL_IFC_NAND_CSPR ((FSL_IFC_NAND_BUF_BASE & FSL_IFC_NAND_BUF_MASK)\
| IFC_CSPR_PORT_SIZE_8 \
| IFC_CSPR_MSEL_NAND \
| IFC_CSPR_V)
+#define FSL_IFC_NAND_CSPR_EXT 0x0 +#define FSL_IFC_NAND_AMASK 0xFFFF0000 +#define FSL_IFC_NAND_CSOR (IFC_CSOR_NAND_ECC_ENC_EN /* ECC on encode */ \
| IFC_CSOR_NAND_ECC_DEC_EN /* ECC on decode */ \
| IFC_CSOR_NAND_ECC_MODE_4 /* 4-bit ECC */ \
| IFC_CSOR_NAND_RAL_3 /* RAL = 3 Bytes */ \
| IFC_CSOR_NAND_PGS_2K /* Page Size = 2K */ \
| IFC_CSOR_NAND_SPRZ_64 /* Spare size = 64 */ \
| IFC_CSOR_NAND_PB(6)) /* 2^6 Pages Per Block */
+/*
- FTIM0 - NOR Flash Mode
- */
+#define FSL_IFC_FTIM0_NOR 0xF03F3F3F +#define FSL_IFC_FTIM0_NOR_TACSE_SHIFT 28 +#define FSL_IFC_FTIM0_NOR_TACSE(n) ((n) << FSL_IFC_FTIM0_NOR_TACSE_SHIFT) +#define FSL_IFC_FTIM0_NOR_TEADC_SHIFT 16 +#define FSL_IFC_FTIM0_NOR_TEADC(n) ((n) << FSL_IFC_FTIM0_NOR_TEADC_SHIFT) +#define FSL_IFC_FTIM0_NOR_TAVDS_SHIFT 8 +#define FSL_IFC_FTIM0_NOR_TAVDS(n) ((n) << FSL_IFC_FTIM0_NOR_TAVDS_SHIFT) +#define FSL_IFC_FTIM0_NOR_TEAHC_SHIFT 0 +#define FSL_IFC_FTIM0_NOR_TEAHC(n) ((n) << FSL_IFC_FTIM0_NOR_TEAHC_SHIFT) +/*
- FTIM1 - NOR Flash Mode
- */
+#define FSL_IFC_FTIM1_NOR 0xFF003F3F +#define FSL_IFC_FTIM1_NOR_TACO_SHIFT 24 +#define FSL_IFC_FTIM1_NOR_TACO(n) ((n) << FSL_IFC_FTIM1_NOR_TACO_SHIFT) +#define FSL_IFC_FTIM1_NOR_TRAD_NOR_SHIFT 8 +#define FSL_IFC_FTIM1_NOR_TRAD_NOR(n) ((n) << FSL_IFC_FTIM1_NOR_TRAD_NOR_SHIFT) +#define FSL_IFC_FTIM1_NOR_TSEQRAD_NOR_SHIFT 0 +#define FSL_IFC_FTIM1_NOR_TSEQRAD_NOR(n) ((n) << FSL_IFC_FTIM1_NOR_TSEQRAD_NOR_SHIFT) +/*
- FTIM2 - NOR Flash Mode
- */
+#define FSL_IFC_FTIM2_NOR 0x0F3CFCFF +#define FSL_IFC_FTIM2_NOR_TCS_SHIFT 24 +#define FSL_IFC_FTIM2_NOR_TCS(n) ((n) << FSL_IFC_FTIM2_NOR_TCS_SHIFT) +#define FSL_IFC_FTIM2_NOR_TCH_SHIFT 18 +#define FSL_IFC_FTIM2_NOR_TCH(n) ((n) << FSL_IFC_FTIM2_NOR_TCH_SHIFT) +#define FSL_IFC_FTIM2_NOR_TWPH_SHIFT 10 +#define FSL_IFC_FTIM2_NOR_TWPH(n) ((n) << FSL_IFC_FTIM2_NOR_TWPH_SHIFT) +#define FSL_IFC_FTIM2_NOR_TWP_SHIFT 0 +#define FSL_IFC_FTIM2_NOR_TWP(n) ((n) << FSL_IFC_FTIM2_NOR_TWP_SHIFT)
+/*
- FTIM0 - Normal GPCM Mode
- */
+#define FSL_IFC_FTIM0_GPCM 0xF03F3F3F +#define FSL_IFC_FTIM0_GPCM_TACSE_SHIFT 28 +#define FSL_IFC_FTIM0_GPCM_TACSE(n) ((n) << FSL_IFC_FTIM0_GPCM_TACSE_SHIFT) +#define FSL_IFC_FTIM0_GPCM_TEADC_SHIFT 16 +#define FSL_IFC_FTIM0_GPCM_TEADC(n) ((n) << FSL_IFC_FTIM0_GPCM_TEADC_SHIFT) +#define FSL_IFC_FTIM0_GPCM_TAVDS_SHIFT 8 +#define FSL_IFC_FTIM0_GPCM_TAVDS(n) ((n) << FSL_IFC_FTIM0_GPCM_TAVDS_SHIFT) +#define FSL_IFC_FTIM0_GPCM_TEAHC_SHIFT 0 +#define FSL_IFC_FTIM0_GPCM_TEAHC(n) ((n) << FSL_IFC_FTIM0_GPCM_TEAHC_SHIFT) +/*
- FTIM1 - Normal GPCM Mode
- */
+#define FSL_IFC_FTIM1_GPCM 0xFF003F00 +#define FSL_IFC_FTIM1_GPCM_TACO_SHIFT 24 +#define FSL_IFC_FTIM1_GPCM_TACO(n) ((n) << FSL_IFC_FTIM1_GPCM_TACO_SHIFT) +#define FSL_IFC_FTIM1_GPCM_TRAD_SHIFT 8 +#define FSL_IFC_FTIM1_GPCM_TRAD(n) ((n) << FSL_IFC_FTIM1_GPCM_TRAD_SHIFT) +/*
- FTIM2 - Normal GPCM Mode
- */
+#define FSL_IFC_FTIM2_GPCM 0x0F3C00FF +#define FSL_IFC_FTIM2_GPCM_TCS_SHIFT 24 +#define FSL_IFC_FTIM2_GPCM_TCS(n) ((n) << FSL_IFC_FTIM2_GPCM_TCS_SHIFT) +#define FSL_IFC_FTIM2_GPCM_TCH_SHIFT 18 +#define FSL_IFC_FTIM2_GPCM_TCH(n) ((n) << FSL_IFC_FTIM2_GPCM_TCH_SHIFT) +#define FSL_IFC_FTIM2_GPCM_TWP_SHIFT 0 +#define FSL_IFC_FTIM2_GPCM_TWP(n) ((n) << FSL_IFC_FTIM2_GPCM_TWP_SHIFT)
+/**
- fls - find last (most-significant) bit set
- @x: the word to search
- This is defined the same way as ffs.
- Note fls(0) = 0, fls(1) = 1, fls(0x80000000) = 32.
- */
+static inline int generic_fls(int x) +{
int r = 32;
if (!x)
return 0;
if (!(x & 0xffff0000u)) {
x <<= 16;
r -= 16;
}
if (!(x & 0xff000000u)) {
x <<= 8;
r -= 8;
}
if (!(x & 0xf0000000u)) {
x <<= 4;
r -= 4;
}
if (!(x & 0xc0000000u)) {
x <<= 2;
r -= 2;
}
if (!(x & 0x80000000u)) {
x <<= 1;
r -= 1;
}
return r;
+}
+static inline int __ilog2(unsigned int x) +{
return generic_fls(x) - 1;
+}
+/*
- Address Mask Register
- */
+#define FSL_IFC_AMASK_MASK 0xFFFF0000 +#define FSL_IFC_AMASK_SHIFT 16 +#define FSL_IFC_AMASK(n) (FSL_IFC_AMASK_MASK << \
(__ilog2(n) - FSL_IFC_AMASK_SHIFT))
+#define FSL_IFC_NOR_AMASK FSL_IFC_AMASK(128*1024*1024)
+#define FSL_IFC_NOR_CSPR ((FSL_IFC_NOR_BUF_BASE & FSL_IFC_NOR_BUF_MASK)\
| IFC_CSPR_PORT_SIZE_16 \
| IFC_CSPR_MSEL_NOR \
| IFC_CSPR_V)
+#define FSL_IFC_NOR_CSPR_EXT 0x0 +#define FSL_IFC_NOR_CSOR (IFC_CSOR_NOR_ADM_SHIFT(4) | \
IFC_CSOR_NOR_TRHZ_80)
+#define FSL_IFC_NOR_FTIM0 (FSL_IFC_FTIM0_NOR_TACSE(0x1) | \
FSL_IFC_FTIM0_NOR_TEADC(0x1) | \
FSL_IFC_FTIM0_NOR_TAVDS(0x0) | \
FSL_IFC_FTIM0_NOR_TEAHC(0xc))
+#define FSL_IFC_NOR_FTIM1 (FSL_IFC_FTIM1_NOR_TACO(0x1c) | \
FSL_IFC_FTIM1_NOR_TRAD_NOR(0xb) |\
FSL_IFC_FTIM1_NOR_TSEQRAD_NOR(0x9))
+#define FSL_IFC_NOR_FTIM2 (FSL_IFC_FTIM2_NOR_TCS(0x1) | \
FSL_IFC_FTIM2_NOR_TCH(0x4) | \
FSL_IFC_FTIM2_NOR_TWPH(0x8) | \
FSL_IFC_FTIM2_NOR_TWP(0x10))
+#define FSL_IFC_NOR_FTIM3 0x0
+#define FSL_IFC_NOR_CSPR0 FSL_IFC_NOR_CSPR +#define FSL_IFC_NOR_AMASK0 FSL_IFC_NOR_AMASK +#define FSL_IFC_NOR_CSOR0 FSL_IFC_NOR_CSOR
+#define FSL_IFC_SRAM_BUF_SIZE 0x4000
+/* CPLD */
+/* Convert an address into the right format for the CSPR Registers */ +#define IFC_CSPR_PHYS_ADDR(x) (((UINTN)x) & 0xffff0000)
+#define CPLD_BASE_PHYS LS1043A_CPLD_BASE
+#define FSL_IFC_CPLD_CSPR_EXT (0x0) +#define FSL_IFC_CPLD_CSPR (IFC_CSPR_PHYS_ADDR(CPLD_BASE_PHYS) | \
IFC_CSPR_PORT_SIZE_8 | \
IFC_CSPR_MSEL_GPCM | \
IFC_CSPR_V)
+#define FSL_IFC_CPLD_AMASK FSL_IFC_AMASK(64 * 1024) +#define FSL_IFC_CPLD_CSOR (IFC_CSOR_NOR_ADM_SHIFT(4) | \
IFC_CSOR_NOR_NOR_MODE_AVD_NOR | \
IFC_CSOR_NOR_TRHZ_80)
+/* CPLD Timing parameters for IFC GPCM */ +#define FSL_IFC_CPLD_FTIM0 (FSL_IFC_FTIM0_GPCM_TACSE(0xf) | \
FSL_IFC_FTIM0_GPCM_TEADC(0xf) | \
FSL_IFC_FTIM0_GPCM_TEAHC(0xf))
+#define FSL_IFC_CPLD_FTIM1 (FSL_IFC_FTIM1_GPCM_TACO(0xff) | \
FSL_IFC_FTIM1_GPCM_TRAD(0x3f))
+#define FSL_IFC_CPLD_FTIM2 (FSL_IFC_FTIM2_GPCM_TCS(0xf) | \
FSL_IFC_FTIM2_GPCM_TCH(0xf) | \
FSL_IFC_FTIM2_GPCM_TWP(0xff))
+#define FSL_IFC_CPLD_FTIM3 0x0
+typedef enum {
FSL_IFC_CS0 = 0,
FSL_IFC_CS1,
FSL_IFC_CS2,
FSL_IFC_CS3,
FSL_IFC_CS4,
FSL_IFC_CS5,
FSL_IFC_CS6,
FSL_IFC_CS7,
+} FSL_IFC_CHIP_SEL;
+typedef enum {
FSL_IFC_FTIM0 = 0,
FSL_IFC_FTIM1,
FSL_IFC_FTIM2,
FSL_IFC_FTIM3,
+} FSL_IFC_FTIMS;
+/*
- Instruction opcodes to be programmed
- in FIR registers- 6bits
- */
+enum ifc_nand_fir_opcodes {
FSL_IFC_FIR_OP_NOP,
FSL_IFC_FIR_OP_CA0,
FSL_IFC_FIR_OP_CA1,
FSL_IFC_FIR_OP_CA2,
FSL_IFC_FIR_OP_CA3,
FSL_IFC_FIR_OP_RA0,
FSL_IFC_FIR_OP_RA1,
FSL_IFC_FIR_OP_RA2,
FSL_IFC_FIR_OP_RA3,
FSL_IFC_FIR_OP_CMD0,
FSL_IFC_FIR_OP_CMD1,
FSL_IFC_FIR_OP_CMD2,
FSL_IFC_FIR_OP_CMD3,
FSL_IFC_FIR_OP_CMD4,
FSL_IFC_FIR_OP_CMD5,
FSL_IFC_FIR_OP_CMD6,
FSL_IFC_FIR_OP_CMD7,
FSL_IFC_FIR_OP_CW0,
FSL_IFC_FIR_OP_CW1,
FSL_IFC_FIR_OP_CW2,
FSL_IFC_FIR_OP_CW3,
FSL_IFC_FIR_OP_CW4,
FSL_IFC_FIR_OP_CW5,
FSL_IFC_FIR_OP_CW6,
FSL_IFC_FIR_OP_CW7,
FSL_IFC_FIR_OP_WBCD,
FSL_IFC_FIR_OP_RBCD,
FSL_IFC_FIR_OP_BTRD,
FSL_IFC_FIR_OP_RDSTAT,
FSL_IFC_FIR_OP_NWAIT,
FSL_IFC_FIR_OP_WFR,
FSL_IFC_FIR_OP_SBRD,
FSL_IFC_FIR_OP_UA,
FSL_IFC_FIR_OP_RB,
+};
+typedef struct {
UINT32 cspr_ext;
UINT32 cspr;
UINT32 res;
+} FSL_IFC_CSPR;
+typedef struct {
UINT32 amask;
UINT32 res[0x2];
+} FSL_IFC_AMASK;
+typedef struct {
UINT32 csor;
UINT32 csor_ext;
UINT32 res;
+} FSL_IFC_CSOR;
+typedef struct {
UINT32 ftim[4];
UINT32 res[0x8];
+}FSL_IFC_FTIM ;
+typedef struct {
UINT32 ncfgr;
UINT32 res1[0x4];
UINT32 nand_fcr0;
UINT32 nand_fcr1;
UINT32 res2[0x8];
UINT32 row0;
UINT32 res3;
UINT32 col0;
UINT32 res4;
UINT32 row1;
UINT32 res5;
UINT32 col1;
UINT32 res6;
UINT32 row2;
UINT32 res7;
UINT32 col2;
UINT32 res8;
UINT32 row3;
UINT32 res9;
UINT32 col3;
UINT32 res10[0x24];
UINT32 nand_fbcr;
UINT32 res11;
UINT32 nand_fir0;
UINT32 nand_fir1;
UINT32 nand_fir2;
UINT32 res12[0x10];
UINT32 nand_csel;
UINT32 res13;
UINT32 nandseq_strt;
UINT32 res14;
UINT32 nand_evter_stat;
UINT32 res15;
UINT32 pgrdcmpl_evt_stat;
UINT32 res16[0x2];
UINT32 nand_evter_en;
UINT32 res17[0x2];
UINT32 nand_evter_intr_en;
UINT32 res18[0x2];
UINT32 nand_erattr0;
UINT32 nand_erattr1;
UINT32 res19[0x10];
UINT32 nand_fsr;
UINT32 res20;
UINT32 nand_eccstat[4];
UINT32 res21[0x20];
UINT32 nanndcr;
UINT32 res22[0x2];
UINT32 nand_autoboot_trgr;
UINT32 res23;
UINT32 nand_mdr;
UINT32 res24[0x5C];
+} FSL_IFC_NAND;
+/*
- IFC controller NOR Machine registers
- */
+typedef struct {
UINT32 nor_evter_stat;
UINT32 res1[0x2];
UINT32 nor_evter_en;
UINT32 res2[0x2];
UINT32 nor_evter_intr_en;
UINT32 res3[0x2];
UINT32 nor_erattr0;
UINT32 nor_erattr1;
UINT32 nor_erattr2;
UINT32 res4[0x4];
UINT32 norcr;
UINT32 res5[0xEF];
+} FSL_IFC_NOR;
+/*
- IFC controller GPCM Machine registers
- */
+typedef struct {
UINT32 gpcm_evter_stat;
UINT32 res1[0x2];
UINT32 gpcm_evter_en;
UINT32 res2[0x2];
UINT32 gpcm_evter_intr_en;
UINT32 res3[0x2];
UINT32 gpcm_erattr0;
UINT32 gpcm_erattr1;
UINT32 gpcm_erattr2;
UINT32 gpcm_stat;
+} FSL_IFC_GPCM;
+/*
- IFC Controller Registers
- */
+typedef struct {
UINT32 ifc_rev;
UINT32 res1[0x2];
FSL_IFC_CSPR cspr_cs[FSL_IFC_BANK_COUNT];
UINT8 res2[FSL_IFC_CSPR_REG_LEN - FSL_IFC_CSPR_USED_LEN];
FSL_IFC_AMASK amask_cs[FSL_IFC_BANK_COUNT];
UINT8 res3[FSL_IFC_AMASK_REG_LEN - FSL_IFC_AMASK_USED_LEN];
FSL_IFC_CSOR csor_cs[FSL_IFC_BANK_COUNT];
UINT8 res4[FSL_IFC_CSOR_REG_LEN - FSL_IFC_CSOR_USED_LEN];
FSL_IFC_FTIM ftim_cs[FSL_IFC_BANK_COUNT];
UINT8 res5[FSL_IFC_FTIM_REG_LEN - FSL_IFC_FTIM_USED_LEN];
UINT32 rb_stat;
UINT32 rb_map;
UINT32 wp_map;
UINT32 ifc_gcr;
UINT32 res7[0x2];
UINT32 cm_evter_stat;
UINT32 res8[0x2];
UINT32 cm_evter_en;
UINT32 res9[0x2];
UINT32 cm_evter_intr_en;
UINT32 res10[0x2];
UINT32 cm_erattr0;
UINT32 cm_erattr1;
UINT32 res11[0x2];
UINT32 ifc_ccr;
UINT32 ifc_csr;
UINT32 ddr_ccr_low;
UINT32 res12[0x2EA];
FSL_IFC_NAND ifc_nand;
FSL_IFC_NOR ifc_nor;
FSL_IFC_GPCM ifc_gpcm;
+} FSL_IFC_REGS;
+VOID IfcNorInit(VOID);
+VOID IfcNandInit(VOID);
+#define FSL_IFC_REGS_BASE \
((FSL_IFC_REGS *)FSL_IFC_REG_BASE)
+#endif //__FLASH_H__ diff --git a/Platforms/Nxp/LS1043aRdb/Library/CpldLib/CpldLib.c b/Platforms/Nxp/LS1043aRdb/Library/CpldLib/CpldLib.c new file mode 100644 index 0000000..fe115c8 --- /dev/null +++ b/Platforms/Nxp/LS1043aRdb/Library/CpldLib/CpldLib.c @@ -0,0 +1,157 @@ +/** @CpldLib.c
- Cpld specific Library for LS1043A-RDB board, containing functions to
- program and read the Cpld registers.
- Copyright (c) 2016, Freescale Semiconductor, Inc. All rights reserved.
- This program and the accompanying materials
- are licensed and made available under the terms and conditions of the BSD License
- which accompanies this distribution. The full text of the license may be found at
- http://opensource.org/licenses/bsd-license.php
- THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
- WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
+**/
+#include <Base.h> +#include <PiPei.h> +#include <Uefi.h>
+#include <Library/BaseLib.h> +#include <Library/DebugLib.h> +#include <Library/IoLib.h> +#include <Library/PrintLib.h> +#include <Library/SerialPortLib.h>
+#include <Library/PlatformLib.h> +#include <Library/CpldLib.h> +#include <Library/FslIfc.h>
+UINT8 +CpldRead (
- OUT UINTN Reg
- )
+{
VOID *Base = (VOID *)LS1043A_CPLD_BASE;
return MmioRead8((UINTN)(Base + Reg));
+}
+VOID +CpldWrite (
- IN UINTN Reg,
- IN UINT8 Value
- )
+{
VOID *Base = (VOID *)LS1043A_CPLD_BASE;
MmioWrite8((UINTN)(Base + Reg), Value);
+}
+/* Set the boot bank to the alternate bank */ +VOID +CpldSetAlternatebank (
- VOID
- )
+{
UINT8 Reg4 = CPLD_READ(SoftMuxOn);
UINT8 Reg7 = CPLD_READ(Vbank);
CPLD_WRITE(SoftMuxOn, Reg4 | CPLD_SW_MUX_BANK_SEL);
Reg7 = (Reg7 & ~CPLD_BANK_SEL_MASK) | CPLD_BANK_SEL_ALTBANK;
CPLD_WRITE(Vbank, Reg7);
CPLD_WRITE(SystemReset, 1);
+}
+/* Set the boot bank to the default bank */ +VOID +CpldSetDefaultBank (
- VOID
- )
+{
CPLD_WRITE(GlobalReset, 1);
+}
+VOID +CpldDumpRegs (
- VOID
- )
+{
DEBUG((EFI_D_INFO, "CpldVersionMajor = %x\n", CPLD_READ(CpldVersionMajor)));
DEBUG((EFI_D_INFO, "CpldVersionMinor = %x\n", CPLD_READ(CpldVersionMinor)));
DEBUG((EFI_D_INFO, "PcbaVersion = %x\n", CPLD_READ(PcbaVersion)));
DEBUG((EFI_D_INFO, "SoftMuxOn = %x\n", CPLD_READ(SoftMuxOn)));
DEBUG((EFI_D_INFO, "RcwSource1 = %x\n", CPLD_READ(RcwSource1)));
DEBUG((EFI_D_INFO, "RcwSource2 = %x\n", CPLD_READ(RcwSource2)));
DEBUG((EFI_D_INFO, "Vbank = %x\n", CPLD_READ(Vbank)));
DEBUG((EFI_D_INFO, "SysclkSelect = %x\n", CPLD_READ(SysclkSelect)));
DEBUG((EFI_D_INFO, "UartSel = %x\n", CPLD_READ(UartSel)));
DEBUG((EFI_D_INFO, "Sd1RefClkSel = %x\n", CPLD_READ(Sd1RefClkSel)));
DEBUG((EFI_D_INFO, "TdmClkMuxSel = %x\n", CPLD_READ(TdmClkMuxSel)));
DEBUG((EFI_D_INFO, "SdhcSpiCsSel = %x\n", CPLD_READ(SdhcSpiCsSel)));
DEBUG((EFI_D_INFO, "StatusLed = %x\n", CPLD_READ(StatusLed)));
+}
+VOID +CpldRevBit (
- OUT UINT8 *Value
- )
+{
UINT8 Rev, Val;
UINTN Index;
Val = *Value;
Rev = Val & 1;
for (Index = 1; Index <= 7; Index++) {
Val >>= 1;
Rev <<= 1;
Rev |= Val & 1;
}
*Value = Rev;
+}
+VOID +DoCpld (
- IN CpldCmd Cmd
- )
+{
switch (Cmd) {
case RESET:
CpldSetDefaultBank();
break;
case RESET_ALTBANK:
CpldSetAlternatebank();
break;
case DUMP_REGISTERS:
CpldDumpRegs();
break;
default:
DEBUG((EFI_D_ERROR, "Error: Unknown Cpld Command!\n"));
break;
}
+}
+VOID +CpldInit (
- VOID
- )
+{
MmioWriteBe32((UINTN) &(FSL_IFC_REGS_BASE)->cspr_cs[FSL_IFC_CS2].cspr_ext, FSL_IFC_CPLD_CSPR_EXT);
MmioWriteBe32((UINTN) &(FSL_IFC_REGS_BASE)->ftim_cs[FSL_IFC_CS2].ftim[FSL_IFC_FTIM0],
FSL_IFC_CPLD_FTIM0);
MmioWriteBe32((UINTN) &(FSL_IFC_REGS_BASE)->ftim_cs[FSL_IFC_CS2].ftim[FSL_IFC_FTIM1],
FSL_IFC_CPLD_FTIM1);
MmioWriteBe32((UINTN) &(FSL_IFC_REGS_BASE)->ftim_cs[FSL_IFC_CS2].ftim[FSL_IFC_FTIM2],
FSL_IFC_CPLD_FTIM2);
MmioWriteBe32((UINTN) &(FSL_IFC_REGS_BASE)->ftim_cs[FSL_IFC_CS2].ftim[FSL_IFC_FTIM3],
FSL_IFC_CPLD_FTIM3);
MmioWriteBe32((UINTN) &(FSL_IFC_REGS_BASE)->csor_cs[FSL_IFC_CS2].csor, FSL_IFC_CPLD_CSOR);
MmioWriteBe32((UINTN) &(FSL_IFC_REGS_BASE)->amask_cs[FSL_IFC_CS2].amask, FSL_IFC_CPLD_AMASK);
MmioWriteBe32((UINTN) &(FSL_IFC_REGS_BASE)->cspr_cs[FSL_IFC_CS2].cspr, FSL_IFC_CPLD_CSPR);
+} diff --git a/Platforms/Nxp/LS1043aRdb/Library/CpldLib/CpldLib.inf b/Platforms/Nxp/LS1043aRdb/Library/CpldLib/CpldLib.inf new file mode 100644 index 0000000..f37d153 --- /dev/null +++ b/Platforms/Nxp/LS1043aRdb/Library/CpldLib/CpldLib.inf @@ -0,0 +1,33 @@ +#/* @CpldLib.inf +# Copyright (c) 2016, Freescale Semiconductor, Inc. All rights reserved. +# +# This program and the accompanying materials +# are licensed and made available under the terms and conditions of the BSD License +# which accompanies this distribution. The full text of the license may be found at +# http://opensource.org/licenses/bsd-license.php +# +# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, +# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. +# +#*/
+[Defines]
- INF_VERSION = 0x00010005
- BASE_NAME = CpldLib
- FILE_GUID = 5962d040-8b8a-11df-9a71-0002a5d5c51b
Please use a fresh GUID
- MODULE_TYPE = BASE
- VERSION_STRING = 1.0
- LIBRARY_CLASS = CpldLib
+[Sources.common]
- CpldLib.c
+[Packages]
- MdePkg/MdePkg.dec
- ArmPkg/ArmPkg.dec
- ArmPlatformPkg/ArmPlatformPkg.dec
- OpenPlatformPkg/Platforms/Nxp/LS1043aRdb/LS1043aRdbPkg.dec
+[LibraryClasses]
- BaseLib
- IoLib
-- 1.9.1
Hi Ard,
Please see my replies inline.
From: Ard Biesheuvel [mailto:ard.biesheuvel@linaro.org] Sent: Tuesday, October 18, 2016 2:56 PM
On 17 October 2016 at 21:04, Bhupesh Sharma bhupesh.sharma@freescale.com wrote:
From: Sakar Arora sakar.arora@nxp.com
NXP/FSL's LS1043A-RDB board houses a CPLD (FPGA) which can be used to control various pin-multiplexing options, which allows certain combinations of peripherals to be enabled on the board.
In addition this CPLD provides a mechanism to divide the NOR/NAND flash memory into primary and alternate regions. While golden images can be flashed on the primary bank, experimental images can be
flashed
on the alternate bank.
CPLD provides a way to switch from primary to alternate region (and vice-versa), thus protecting the board from damage if primary region is flashed with incorrect set of images.
Signed-off-by: Sakar Arora sakar.arora@nxp.com Signed-off-by: Bhupesh Sharma bhupesh.sharma@nxp.com
Platforms/Nxp/LS1043aRdb/Include/Library/CpldLib.h | 75 +++ Platforms/Nxp/LS1043aRdb/Include/Library/FslIfc.h | 721 +++++++++++++++++++++
Platforms/Nxp/LS1043aRdb/Library/CpldLib/CpldLib.c | 157 +++++
.../Nxp/LS1043aRdb/Library/CpldLib/CpldLib.inf | 33 + 4 files changed, 986 insertions(+) create mode 100644
Platforms/Nxp/LS1043aRdb/Include/Library/CpldLib.h
create mode 100644 Platforms/Nxp/LS1043aRdb/Include/Library/FslIfc.h create mode 100644
Platforms/Nxp/LS1043aRdb/Library/CpldLib/CpldLib.c
create mode 100644 Platforms/Nxp/LS1043aRdb/Library/CpldLib/CpldLib.inf
diff --git a/Platforms/Nxp/LS1043aRdb/Include/Library/CpldLib.h b/Platforms/Nxp/LS1043aRdb/Include/Library/CpldLib.h
Please add this library class to the package .dec file
Ok.
new file mode 100644 index 0000000..56f47da --- /dev/null +++ b/Platforms/Nxp/LS1043aRdb/Include/Library/CpldLib.h @@ -0,0 +1,75 @@ +/** CpldLib.h +* Header defining the LS1043a Cpld specific constants (Base +addresses, sizes, flags) +* +* Copyright (c) 2016, Freescale Semiconductor, Inc. All rights
reserved.
+* +* This program and the accompanying materials +* are licensed and made available under the terms and conditions of +the BSD License +* which accompanies this distribution. The full text of the
license
+may be found at +* http://opensource.org/licenses/bsd-license.php +* +* THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" +BASIS, +* WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS
OR IMPLIED.
+* +**/
+#ifndef __LS1043A_CPLD_H__ +#define __LS1043A_CPLD_H__
+#include <Library/Common.h>
+/*
- CPLD register set of LS1043ARDB board-specific.
- */
+struct CpldRegSet {
UINT8 CpldVersionMajor; /* 0x0 - CPLD Major Revision Register
*/
UINT8 CpldVersionMinor; /* 0x1 - CPLD Minor Revision Register
*/
UINT8 PcbaVersion; /* 0x2 - PCBA Revision Register */
UINT8 SystemReset; /* 0x3 - system reset register */
UINT8 SoftMuxOn; /* 0x4 - Switch Control Enable
Register */
UINT8 RcwSource1; /* 0x5 - Reset config word 1 */
UINT8 RcwSource2; /* 0x6 - Reset config word 1 */
UINT8 Vbank; /* 0x7 - Flash bank selection Control
*/
UINT8 SysclkSelect; /* 0x8 - */
UINT8 UartSel; /* 0x9 - */
UINT8 Sd1RefClkSel; /* 0xA - */
UINT8 TdmClkMuxSel; /* 0xB - */
UINT8 SdhcSpiCsSel; /* 0xC - */
UINT8 StatusLed; /* 0xD - */
UINT8 GlobalReset; /* 0xE - */
+};
+/*
- Reset the board, Reset to alternate bank or Dump registers:
- RESET - reset to default bank
- RESET_ALTBANK - reset to alternate bank
- DUMP_REGISTERS - display the CPLD registers */ typedef enum {
RESET = 0,
RESET_ALTBANK,
DUMP_REGISTERS
+} CpldCmd;
+UINT8 CpldRead(UINTN Reg); +VOID CpldWrite(UINTN Reg, UINT8 Value); VOID CpldRevBit(UINT8 +*Value); VOID DoCpld (CpldCmd Cmd); VOID CpldInit (VOID);
+#define CPLD_READ(Reg) CpldRead(offsetof(struct CpldRegSet, Reg)) +#define CPLD_WRITE(Reg, Value) \
CpldWrite(offsetof(struct CpldRegSet, Reg), Value)
+/* CPLD on IFC */ +#define CPLD_SW_MUX_BANK_SEL 0x40 +#define CPLD_BANK_SEL_MASK 0x07 +#define CPLD_BANK_SEL_ALTBANK 0x04
+/* SDXC/DSPI CPLD Settings */ +#define ENABLE_SDXC_SOFT_MUX 0x30 +#define ENABLE_RCW_SOFT_MUX 0x01 +#define SELECT_SW4_SDXC 0x40 +#define SELECT_SW5_SDXC 0x01
+#endif diff --git a/Platforms/Nxp/LS1043aRdb/Include/Library/FslIfc.h b/Platforms/Nxp/LS1043aRdb/Include/Library/FslIfc.h
If this is an internal header, keep it with the .c files. Include/Library should only contain header files that define APIs that are exposed via LibraryClasses
Ok, will keep this with the .c files as this is an internal header.
new file mode 100644 index 0000000..27c8295 --- /dev/null +++ b/Platforms/Nxp/LS1043aRdb/Include/Library/FslIfc.h @@ -0,0 +1,721 @@ +/** @FslIfc.h
- Copyright (c) 2008 - 2009, Apple Inc. All rights reserved.<BR>
- Copyright (c) 2016, Freescale Semiconductor, Inc. All rights
reserved.
- This program and the accompanying materials are licensed and made
- available under the terms and conditions of the BSD License which
- accompanies this distribution. The full text of the license may be
- found at http://opensource.org/licenses/bsd-license.php
- THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS"
- BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER
EXPRESS OR IMPLIED.
+**/
+#ifndef __FLASH_H__ +#define __FLASH_H__
+#include <Uefi.h>
+#include <Library/BaseLib.h> +#include <Library/BaseMemoryLib.h> +#include <Library/MemoryAllocationLib.h> #include +<Library/DebugLib.h> #include <Library/IoLib.h> #include +<Library/PcdLib.h> #include <Library/UefiBootServicesTableLib.h> +#include <Library/IoLib.h> +#include <Library/PlatformLib.h>
+#include <Protocol/BlockIo.h> +#include <Protocol/Cpu.h>
+#define NOIBR
+#define FSL_IFC_BANK_COUNT 4
+#define NAND_PAGE_SIZE_2K (2048) +#define NAND_SPARE_AREA_SIZE_64B (64) +#define NAND_BLOCK_SIZE_128K (128*1024) +#define NAND_BLOCK_COUNT (2048) +#define NAND_LAST_BLOCK (NAND_BLOCK_COUNT - 1)
+//List of commands. +#define IFC_NAND_CMD_RESET 0xFF +#define IFC_NAND_CMD_READID 0x90
+#define IFC_NAND_CMD_STATUS 0x70
+#define IFC_NAND_CMD_READ0 0x00 +#define IFC_NAND_CMD_READSTART 0x30
+#define IFC_NAND_CMD_ERASE1 0x60 +#define IFC_NAND_CMD_ERASE2 0xD0
+#define IFC_NAND_CMD_SEQIN 0x80 +#define IFC_NAND_CMD_PAGEPROG 0x10
+#define MAX_RETRY_COUNT 150000
+#define FSL_IFC_REG_BASE 0x1530000 +#define FSL_IFC_NAND_BUF_BASE 0x70000000 +#define FSL_IFC_NOR_BUF_BASE 0x60000000
+#define FSL_IFC_NOR_RESERVED_REGION_BASE 0x60700000
+#define FSL_IFC_CSPR_REG_LEN 148 +#define FSL_IFC_AMASK_REG_LEN 144 +#define FSL_IFC_CSOR_REG_LEN 144 +#define FSL_IFC_FTIM_REG_LEN 576
+#define FSL_IFC_NAND_SEQ_STRT_FIR_STRT 0x80000000
+#define FSL_IFC_CSPR_USED_LEN sizeof(FSL_IFC_CSPR) * \
FSL_IFC_BANK_COUNT #define
+FSL_IFC_AMASK_USED_LEN sizeof(FSL_IFC_AMASK) * \
FSL_IFC_BANK_COUNT #define
+FSL_IFC_CSOR_USED_LEN sizeof(FSL_IFC_CSOR) * \
FSL_IFC_BANK_COUNT #define
+FSL_IFC_FTIM_USED_LEN sizeof(FSL_IFC_FTIM) * \
FSL_IFC_BANK_COUNT
+/*
- NAND Event and Error Status Register (NAND_EVTER_STAT) */
+/* Operation Complete */ +#define FSL_IFC_NAND_EVTER_STAT_OPC 0x80000000 +/* Flash Timeout Error */ +#define FSL_IFC_NAND_EVTER_STAT_FTOER 0x08000000 +/* Write Protect Error */ +#define FSL_IFC_NAND_EVTER_STAT_WPER 0x04000000 +/* ECC Error */ +#define FSL_IFC_NAND_EVTER_STAT_ECCER 0x02000000
+/*
- NAND Flash Byte Count Register (NAND_BC) */
+/* Byte Count for read/Write */ +#define FSL_IFC_NAND_BC 0x000001FF
+/*
- NAND Flash Instruction Registers (NAND_FIR0/NAND_FIR1/NAND_FIR2)
+*/ +/* NAND Machine specific opcodes OP0-OP14*/ +#define FSL_IFC_NAND_FIR0_OP0 0xFC000000 +#define FSL_IFC_NAND_FIR0_OP0_SHIFT 26 +#define FSL_IFC_NAND_FIR0_OP1 0x03F00000 +#define FSL_IFC_NAND_FIR0_OP1_SHIFT 20 +#define FSL_IFC_NAND_FIR0_OP2 0x000FC000 +#define FSL_IFC_NAND_FIR0_OP2_SHIFT 14 +#define FSL_IFC_NAND_FIR0_OP3 0x00003F00 +#define FSL_IFC_NAND_FIR0_OP3_SHIFT 8 +#define FSL_IFC_NAND_FIR0_OP4 0x000000FC +#define FSL_IFC_NAND_FIR0_OP4_SHIFT 2 +#define FSL_IFC_NAND_FIR1_OP5 0xFC000000 +#define FSL_IFC_NAND_FIR1_OP5_SHIFT 26 +#define FSL_IFC_NAND_FIR1_OP6 0x03F00000 +#define FSL_IFC_NAND_FIR1_OP6_SHIFT 20 +#define FSL_IFC_NAND_FIR1_OP7 0x000FC000 +#define FSL_IFC_NAND_FIR1_OP7_SHIFT 14 +#define FSL_IFC_NAND_FIR1_OP8 0x00003F00 +#define FSL_IFC_NAND_FIR1_OP8_SHIFT 8 +#define FSL_IFC_NAND_FIR1_OP9 0x000000FC +#define FSL_IFC_NAND_FIR1_OP9_SHIFT 2 +#define FSL_IFC_NAND_FIR2_OP10 0xFC000000 +#define FSL_IFC_NAND_FIR2_OP10_SHIFT 26 +#define FSL_IFC_NAND_FIR2_OP11 0x03F00000 +#define FSL_IFC_NAND_FIR2_OP11_SHIFT 20 +#define FSL_IFC_NAND_FIR2_OP12 0x000FC000 +#define FSL_IFC_NAND_FIR2_OP12_SHIFT 14 +#define FSL_IFC_NAND_FIR2_OP13 0x00003F00 +#define FSL_IFC_NAND_FIR2_OP13_SHIFT 8 +#define FSL_IFC_NAND_FIR2_OP14 0x000000FC +#define FSL_IFC_NAND_FIR2_OP14_SHIFT 2
+/*
- NAND Flash Command Registers (NAND_FCR0/NAND_FCR1) */
+/* General purpose FCM flash command bytes CMD0-CMD7 */ +#define FSL_IFC_NAND_FCR0_CMD0 0xFF000000 +#define FSL_IFC_NAND_FCR0_CMD0_SHIFT 24 +#define FSL_IFC_NAND_FCR0_CMD1 0x00FF0000 +#define FSL_IFC_NAND_FCR0_CMD1_SHIFT 16 +#define FSL_IFC_NAND_FCR0_CMD2 0x0000FF00 +#define FSL_IFC_NAND_FCR0_CMD2_SHIFT 8 +#define FSL_IFC_NAND_FCR0_CMD3 0x000000FF +#define FSL_IFC_NAND_FCR0_CMD3_SHIFT 0 +#define FSL_IFC_NAND_FCR1_CMD4 0xFF000000 +#define FSL_IFC_NAND_FCR1_CMD4_SHIFT 24 +#define FSL_IFC_NAND_FCR1_CMD5 0x00FF0000 +#define FSL_IFC_NAND_FCR1_CMD5_SHIFT 16 +#define FSL_IFC_NAND_FCR1_CMD6 0x0000FF00 +#define FSL_IFC_NAND_FCR1_CMD6_SHIFT 8 +#define FSL_IFC_NAND_FCR1_CMD7 0x000000FF +#define FSL_IFC_NAND_FCR1_CMD7_SHIFT 0
+/* Timing registers for NAND Flash */
+#define FSL_IFC_FTIM0_NAND_TCCST_SHIFT 25 +#define FSL_IFC_FTIM0_NAND_TCCST(n) ((n) <<
FSL_IFC_FTIM0_NAND_TCCST_SHIFT)
+#define FSL_IFC_FTIM0_NAND_TWP_SHIFT 16 +#define FSL_IFC_FTIM0_NAND_TWP(n) ((n) <<
FSL_IFC_FTIM0_NAND_TWP_SHIFT)
+#define FSL_IFC_FTIM0_NAND_TWCHT_SHIFT 8 +#define FSL_IFC_FTIM0_NAND_TWCHT(n) ((n) <<
FSL_IFC_FTIM0_NAND_TWCHT_SHIFT)
+#define FSL_IFC_FTIM0_NAND_TWH_SHIFT 0 +#define FSL_IFC_FTIM0_NAND_TWH(n) ((n) <<
FSL_IFC_FTIM0_NAND_TWH_SHIFT)
+#define FSL_IFC_FTIM1_NAND_TADLE_SHIFT 24 +#define FSL_IFC_FTIM1_NAND_TADLE(n) ((n) <<
FSL_IFC_FTIM1_NAND_TADLE_SHIFT)
+#define FSL_IFC_FTIM1_NAND_TWBE_SHIFT 16 +#define FSL_IFC_FTIM1_NAND_TWBE(n) ((n) <<
FSL_IFC_FTIM1_NAND_TWBE_SHIFT)
+#define FSL_IFC_FTIM1_NAND_TRR_SHIFT 8 +#define FSL_IFC_FTIM1_NAND_TRR(n) ((n) <<
FSL_IFC_FTIM1_NAND_TRR_SHIFT)
+#define FSL_IFC_FTIM1_NAND_TRP_SHIFT 0 +#define FSL_IFC_FTIM1_NAND_TRP(n) ((n) <<
FSL_IFC_FTIM1_NAND_TRP_SHIFT)
+#define FSL_IFC_FTIM2_NAND_TRAD_SHIFT 21 +#define FSL_IFC_FTIM2_NAND_TRAD(n) ((n) <<
FSL_IFC_FTIM2_NAND_TRAD_SHIFT)
+#define FSL_IFC_FTIM2_NAND_TREH_SHIFT 11 +#define FSL_IFC_FTIM2_NAND_TREH(n) ((n) <<
FSL_IFC_FTIM2_NAND_TREH_SHIFT)
+#define FSL_IFC_FTIM2_NAND_TWHRE_SHIFT 0 +#define FSL_IFC_FTIM2_NAND_TWHRE(n) ((n) <<
FSL_IFC_FTIM2_NAND_TWHRE_SHIFT)
+#define FSL_IFC_FTIM3_NAND_TWW_SHIFT 24 +#define FSL_IFC_FTIM3_NAND_TWW(n) ((n) <<
FSL_IFC_FTIM3_NAND_TWW_SHIFT)
+/*
- Flash ROW and COL Address Register (ROWn, COLn) */
+/* Main/spare region locator */ +#define FSL_IFC_NAND_COL_MS 0x80000000 +/* Column Address */ +#define FSL_IFC_NAND_COL_CA_MASK 0x00000FFF
+#define NAND_STATUS_WP 0x80
+/*
- NAND Event and Error Enable Register (NAND_EVTER_EN) */
+/* Operation complete event enable */ +#define FSL_IFC_NAND_EVTER_EN_OPC_EN 0x80000000 +/* Page read complete event enable */ +#define FSL_IFC_NAND_EVTER_EN_PGRDCMPL_EN 0x20000000 +/* Flash Timeout error enable */ +#define FSL_IFC_NAND_EVTER_EN_FTOER_EN 0x08000000 +/* Write Protect error enable */ +#define FSL_IFC_NAND_EVTER_EN_WPER_EN 0x04000000 +/* ECC error logging enable */ +#define FSL_IFC_NAND_EVTER_EN_ECCER_EN 0x02000000
+/*
- CSPR - Chip Select Property Register */
+#define IFC_CSPR_BA 0xFFFF0000 +#define IFC_CSPR_BA_SHIFT 16 +#define IFC_CSPR_PORT_SIZE 0x00000180 +#define IFC_CSPR_PORT_SIZE_SHIFT 7 +/* Port Size 8 bit */ +#define IFC_CSPR_PORT_SIZE_8 0x00000080 +/* Port Size 16 bit */ +#define IFC_CSPR_PORT_SIZE_16 0x00000100 +/* Port Size 32 bit */ +#define IFC_CSPR_PORT_SIZE_32 0x00000180 +/* Write Protect */ +#define IFC_CSPR_WP 0x00000040 +#define IFC_CSPR_WP_SHIFT 6 +/* Machine Select */ +#define IFC_CSPR_MSEL 0x00000006 +#define IFC_CSPR_MSEL_SHIFT 1 +/* NOR */ +#define IFC_CSPR_MSEL_NOR 0x00000000 +/* NAND */ +#define IFC_CSPR_MSEL_NAND 0x00000002 +/* GPCM */ +#define IFC_CSPR_MSEL_GPCM 0x00000004 +/* Bank Valid */ +#define IFC_CSPR_V 0x00000001 +#define IFC_CSPR_V_SHIFT 0
+/*
- Chip Select Option Register - NOR Flash Mode */
+/* Enable Address shift Mode */ +#define IFC_CSOR_NOR_ADM_SHFT_MODE_EN 0x80000000 +/* Page Read Enable from NOR device */ +#define IFC_CSOR_NOR_PGRD_EN 0x10000000 +/* AVD Toggle Enable during Burst Program */ +#define IFC_CSOR_NOR_AVD_TGL_PGM_EN 0x01000000 +/* Address Data Multiplexing Shift */ +#define IFC_CSOR_NOR_ADM_MASK 0x0003E000 +#define IFC_CSOR_NOR_ADM_SHIFT_SHIFT 13 +#define IFC_CSOR_NOR_ADM_SHIFT(n) ((n) <<
IFC_CSOR_NOR_ADM_SHIFT_SHIFT)
+/* Type of the NOR device hooked */ +#define IFC_CSOR_NOR_NOR_MODE_AYSNC_NOR 0x00000000 +#define IFC_CSOR_NOR_NOR_MODE_AVD_NOR 0x00000020 +/* Time for Read Enable High to Output High Impedance */ +#define IFC_CSOR_NOR_TRHZ_MASK 0x0000001C +#define IFC_CSOR_NOR_TRHZ_SHIFT 2 +#define IFC_CSOR_NOR_TRHZ_20 0x00000000 +#define IFC_CSOR_NOR_TRHZ_40 0x00000004 +#define IFC_CSOR_NOR_TRHZ_60 0x00000008 +#define IFC_CSOR_NOR_TRHZ_80 0x0000000C +#define IFC_CSOR_NOR_TRHZ_100 0x00000010 +/* Buffer control disable */ +#define IFC_CSOR_NOR_BCTLD 0x00000001
+/*
- Chip Select Option Register FSL_IFC_NAND Machine */
+/* Enable ECC Encoder */ +#define IFC_CSOR_NAND_ECC_ENC_EN 0x80000000 +#define IFC_CSOR_NAND_ECC_MODE_MASK 0x30000000 +/* 4 bit correction per 520 Byte sector */ +#define IFC_CSOR_NAND_ECC_MODE_4 0x00000000 +/* 8 bit correction per 528 Byte sector */ +#define IFC_CSOR_NAND_ECC_MODE_8 0x10000000 +/* Enable ECC Decoder */ +#define IFC_CSOR_NAND_ECC_DEC_EN 0x04000000 +/* Row Address Length */ +#define IFC_CSOR_NAND_RAL_MASK 0x01800000 +#define IFC_CSOR_NAND_RAL_SHIFT 20 +#define IFC_CSOR_NAND_RAL_1 0x00000000 +#define IFC_CSOR_NAND_RAL_2 0x00800000 +#define IFC_CSOR_NAND_RAL_3 0x01000000 +#define IFC_CSOR_NAND_RAL_4 0x01800000 +/* Page Size 512b, 2k, 4k */ +#define IFC_CSOR_NAND_PGS_MASK 0x00180000 +#define IFC_CSOR_NAND_PGS_SHIFT 16 +#define IFC_CSOR_NAND_PGS_512 0x00000000 +#define IFC_CSOR_NAND_PGS_2K 0x00080000 +#define IFC_CSOR_NAND_PGS_4K 0x00100000 +#define IFC_CSOR_NAND_PGS_8K 0x00180000 +/* Spare region Size */ +#define IFC_CSOR_NAND_SPRZ_MASK 0x0000E000 +#define IFC_CSOR_NAND_SPRZ_SHIFT 13 +#define IFC_CSOR_NAND_SPRZ_16 0x00000000 +#define IFC_CSOR_NAND_SPRZ_64 0x00002000 +#define IFC_CSOR_NAND_SPRZ_128 0x00004000 +#define IFC_CSOR_NAND_SPRZ_210 0x00006000 +#define IFC_CSOR_NAND_SPRZ_218 0x00008000 +#define IFC_CSOR_NAND_SPRZ_224 0x0000A000 +#define IFC_CSOR_NAND_SPRZ_CSOR_EXT 0x0000C000 +/* Pages Per Block */ +#define IFC_CSOR_NAND_PB_MASK 0x00000700 +#define IFC_CSOR_NAND_PB_SHIFT 8 +#define IFC_CSOR_NAND_PB(n) (n-5) <<
IFC_CSOR_NAND_PB_SHIFT
+/* Time for Read Enable High to Output High Impedance */ +#define IFC_CSOR_NAND_TRHZ_MASK 0x0000001C +#define IFC_CSOR_NAND_TRHZ_SHIFT 2 +#define IFC_CSOR_NAND_TRHZ_20 0x00000000 +#define IFC_CSOR_NAND_TRHZ_40 0x00000004 +#define IFC_CSOR_NAND_TRHZ_60 0x00000008 +#define IFC_CSOR_NAND_TRHZ_80 0x0000000C +#define IFC_CSOR_NAND_TRHZ_100 0x00000010 +/* Buffer control disable */ +#define IFC_CSOR_NAND_BCTLD 0x00000001
+#define FSL_IFC_NAND_BUF_MASK 0xffff0000 +#define FSL_IFC_NOR_BUF_MASK 0xffff0000
+#define FSL_IFC_NAND_CSPR ((FSL_IFC_NAND_BUF_BASE &
FSL_IFC_NAND_BUF_MASK)\
| IFC_CSPR_PORT_SIZE_8 \
| IFC_CSPR_MSEL_NAND \
| IFC_CSPR_V) #define
+FSL_IFC_NAND_CSPR_EXT 0x0 +#define FSL_IFC_NAND_AMASK 0xFFFF0000 +#define FSL_IFC_NAND_CSOR (IFC_CSOR_NAND_ECC_ENC_EN /* ECC on
encode */ \
| IFC_CSOR_NAND_ECC_DEC_EN /* ECC on
decode */ \
| IFC_CSOR_NAND_ECC_MODE_4 /* 4-bit
ECC */ \
| IFC_CSOR_NAND_RAL_3 /* RAL =
3 Bytes */ \
| IFC_CSOR_NAND_PGS_2K /* Page
Size = 2K */ \
| IFC_CSOR_NAND_SPRZ_64 /* Spare
size = 64 */ \
| IFC_CSOR_NAND_PB(6)) /* 2^6
Pages Per Block */
+/*
- FTIM0 - NOR Flash Mode
- */
+#define FSL_IFC_FTIM0_NOR 0xF03F3F3F +#define FSL_IFC_FTIM0_NOR_TACSE_SHIFT 28 +#define FSL_IFC_FTIM0_NOR_TACSE(n) ((n) <<
FSL_IFC_FTIM0_NOR_TACSE_SHIFT)
+#define FSL_IFC_FTIM0_NOR_TEADC_SHIFT 16 +#define FSL_IFC_FTIM0_NOR_TEADC(n) ((n) <<
FSL_IFC_FTIM0_NOR_TEADC_SHIFT)
+#define FSL_IFC_FTIM0_NOR_TAVDS_SHIFT 8 +#define FSL_IFC_FTIM0_NOR_TAVDS(n) ((n) <<
FSL_IFC_FTIM0_NOR_TAVDS_SHIFT)
+#define FSL_IFC_FTIM0_NOR_TEAHC_SHIFT 0 +#define FSL_IFC_FTIM0_NOR_TEAHC(n) ((n) <<
FSL_IFC_FTIM0_NOR_TEAHC_SHIFT)
+/*
- FTIM1 - NOR Flash Mode
- */
+#define FSL_IFC_FTIM1_NOR 0xFF003F3F +#define FSL_IFC_FTIM1_NOR_TACO_SHIFT 24 +#define FSL_IFC_FTIM1_NOR_TACO(n) ((n) <<
FSL_IFC_FTIM1_NOR_TACO_SHIFT)
+#define FSL_IFC_FTIM1_NOR_TRAD_NOR_SHIFT 8 +#define FSL_IFC_FTIM1_NOR_TRAD_NOR(n) ((n) <<
FSL_IFC_FTIM1_NOR_TRAD_NOR_SHIFT)
+#define FSL_IFC_FTIM1_NOR_TSEQRAD_NOR_SHIFT 0 +#define FSL_IFC_FTIM1_NOR_TSEQRAD_NOR(n) ((n) <<
FSL_IFC_FTIM1_NOR_TSEQRAD_NOR_SHIFT)
+/*
- FTIM2 - NOR Flash Mode
- */
+#define FSL_IFC_FTIM2_NOR 0x0F3CFCFF +#define FSL_IFC_FTIM2_NOR_TCS_SHIFT 24 +#define FSL_IFC_FTIM2_NOR_TCS(n) ((n) <<
FSL_IFC_FTIM2_NOR_TCS_SHIFT)
+#define FSL_IFC_FTIM2_NOR_TCH_SHIFT 18 +#define FSL_IFC_FTIM2_NOR_TCH(n) ((n) <<
FSL_IFC_FTIM2_NOR_TCH_SHIFT)
+#define FSL_IFC_FTIM2_NOR_TWPH_SHIFT 10 +#define FSL_IFC_FTIM2_NOR_TWPH(n) ((n) <<
FSL_IFC_FTIM2_NOR_TWPH_SHIFT)
+#define FSL_IFC_FTIM2_NOR_TWP_SHIFT 0 +#define FSL_IFC_FTIM2_NOR_TWP(n) ((n) <<
FSL_IFC_FTIM2_NOR_TWP_SHIFT)
+/*
- FTIM0 - Normal GPCM Mode
- */
+#define FSL_IFC_FTIM0_GPCM 0xF03F3F3F +#define FSL_IFC_FTIM0_GPCM_TACSE_SHIFT 28 +#define FSL_IFC_FTIM0_GPCM_TACSE(n) ((n) <<
FSL_IFC_FTIM0_GPCM_TACSE_SHIFT)
+#define FSL_IFC_FTIM0_GPCM_TEADC_SHIFT 16 +#define FSL_IFC_FTIM0_GPCM_TEADC(n) ((n) <<
FSL_IFC_FTIM0_GPCM_TEADC_SHIFT)
+#define FSL_IFC_FTIM0_GPCM_TAVDS_SHIFT 8 +#define FSL_IFC_FTIM0_GPCM_TAVDS(n) ((n) <<
FSL_IFC_FTIM0_GPCM_TAVDS_SHIFT)
+#define FSL_IFC_FTIM0_GPCM_TEAHC_SHIFT 0 +#define FSL_IFC_FTIM0_GPCM_TEAHC(n) ((n) <<
FSL_IFC_FTIM0_GPCM_TEAHC_SHIFT)
+/*
- FTIM1 - Normal GPCM Mode
- */
+#define FSL_IFC_FTIM1_GPCM 0xFF003F00 +#define FSL_IFC_FTIM1_GPCM_TACO_SHIFT 24 +#define FSL_IFC_FTIM1_GPCM_TACO(n) ((n) <<
FSL_IFC_FTIM1_GPCM_TACO_SHIFT)
+#define FSL_IFC_FTIM1_GPCM_TRAD_SHIFT 8 +#define FSL_IFC_FTIM1_GPCM_TRAD(n) ((n) <<
FSL_IFC_FTIM1_GPCM_TRAD_SHIFT)
+/*
- FTIM2 - Normal GPCM Mode
- */
+#define FSL_IFC_FTIM2_GPCM 0x0F3C00FF +#define FSL_IFC_FTIM2_GPCM_TCS_SHIFT 24 +#define FSL_IFC_FTIM2_GPCM_TCS(n) ((n) <<
FSL_IFC_FTIM2_GPCM_TCS_SHIFT)
+#define FSL_IFC_FTIM2_GPCM_TCH_SHIFT 18 +#define FSL_IFC_FTIM2_GPCM_TCH(n) ((n) <<
FSL_IFC_FTIM2_GPCM_TCH_SHIFT)
+#define FSL_IFC_FTIM2_GPCM_TWP_SHIFT 0 +#define FSL_IFC_FTIM2_GPCM_TWP(n) ((n) <<
FSL_IFC_FTIM2_GPCM_TWP_SHIFT)
+/**
- fls - find last (most-significant) bit set
- @x: the word to search
- This is defined the same way as ffs.
- Note fls(0) = 0, fls(1) = 1, fls(0x80000000) = 32.
- */
+static inline int generic_fls(int x) +{
int r = 32;
if (!x)
return 0;
if (!(x & 0xffff0000u)) {
x <<= 16;
r -= 16;
}
if (!(x & 0xff000000u)) {
x <<= 8;
r -= 8;
}
if (!(x & 0xf0000000u)) {
x <<= 4;
r -= 4;
}
if (!(x & 0xc0000000u)) {
x <<= 2;
r -= 2;
}
if (!(x & 0x80000000u)) {
x <<= 1;
r -= 1;
}
return r;
+}
+static inline int __ilog2(unsigned int x) {
return generic_fls(x) - 1;
+}
+/*
- Address Mask Register
- */
+#define FSL_IFC_AMASK_MASK 0xFFFF0000 +#define FSL_IFC_AMASK_SHIFT 16 +#define FSL_IFC_AMASK(n) (FSL_IFC_AMASK_MASK
<< \
(__ilog2(n) -
FSL_IFC_AMASK_SHIFT))
+#define FSL_IFC_NOR_AMASK FSL_IFC_AMASK(128*1024*1024)
+#define FSL_IFC_NOR_CSPR ((FSL_IFC_NOR_BUF_BASE &
FSL_IFC_NOR_BUF_MASK)\
| IFC_CSPR_PORT_SIZE_16 \
| IFC_CSPR_MSEL_NOR \
| IFC_CSPR_V)
+#define FSL_IFC_NOR_CSPR_EXT 0x0 +#define FSL_IFC_NOR_CSOR (IFC_CSOR_NOR_ADM_SHIFT(4) |
\
IFC_CSOR_NOR_TRHZ_80)
+#define FSL_IFC_NOR_FTIM0 (FSL_IFC_FTIM0_NOR_TACSE(0x1)
| \
FSL_IFC_FTIM0_NOR_TEADC(0x1) | \
FSL_IFC_FTIM0_NOR_TAVDS(0x0) | \
FSL_IFC_FTIM0_NOR_TEAHC(0xc))
+#define FSL_IFC_NOR_FTIM1 (FSL_IFC_FTIM1_NOR_TACO(0x1c)
| \
FSL_IFC_FTIM1_NOR_TRAD_NOR(0xb) |\
FSL_IFC_FTIM1_NOR_TSEQRAD_NOR(0x9))
+#define FSL_IFC_NOR_FTIM2 (FSL_IFC_FTIM2_NOR_TCS(0x1) |
\
FSL_IFC_FTIM2_NOR_TCH(0x4) | \
FSL_IFC_FTIM2_NOR_TWPH(0x8) | \
FSL_IFC_FTIM2_NOR_TWP(0x10))
+#define FSL_IFC_NOR_FTIM3 0x0
+#define FSL_IFC_NOR_CSPR0 FSL_IFC_NOR_CSPR +#define FSL_IFC_NOR_AMASK0 FSL_IFC_NOR_AMASK +#define FSL_IFC_NOR_CSOR0 FSL_IFC_NOR_CSOR
+#define FSL_IFC_SRAM_BUF_SIZE 0x4000
+/* CPLD */
+/* Convert an address into the right format for the CSPR Registers
*/
+#define IFC_CSPR_PHYS_ADDR(x) (((UINTN)x) & 0xffff0000)
+#define CPLD_BASE_PHYS LS1043A_CPLD_BASE
+#define FSL_IFC_CPLD_CSPR_EXT (0x0) +#define FSL_IFC_CPLD_CSPR
(IFC_CSPR_PHYS_ADDR(CPLD_BASE_PHYS) | \
IFC_CSPR_PORT_SIZE_8 | \
IFC_CSPR_MSEL_GPCM | \
IFC_CSPR_V)
+#define FSL_IFC_CPLD_AMASK FSL_IFC_AMASK(64 * 1024) +#define FSL_IFC_CPLD_CSOR (IFC_CSOR_NOR_ADM_SHIFT(4) |
\
IFC_CSOR_NOR_NOR_MODE_AVD_NOR | \
IFC_CSOR_NOR_TRHZ_80)
+/* CPLD Timing parameters for IFC GPCM */ +#define FSL_IFC_CPLD_FTIM0
(FSL_IFC_FTIM0_GPCM_TACSE(0xf) | \
FSL_IFC_FTIM0_GPCM_TEADC(0xf) | \
FSL_IFC_FTIM0_GPCM_TEAHC(0xf))
+#define FSL_IFC_CPLD_FTIM1
(FSL_IFC_FTIM1_GPCM_TACO(0xff) | \
FSL_IFC_FTIM1_GPCM_TRAD(0x3f))
+#define FSL_IFC_CPLD_FTIM2 (FSL_IFC_FTIM2_GPCM_TCS(0xf)
| \
FSL_IFC_FTIM2_GPCM_TCH(0xf) | \
FSL_IFC_FTIM2_GPCM_TWP(0xff))
+#define FSL_IFC_CPLD_FTIM3 0x0
+typedef enum {
FSL_IFC_CS0 = 0,
FSL_IFC_CS1,
FSL_IFC_CS2,
FSL_IFC_CS3,
FSL_IFC_CS4,
FSL_IFC_CS5,
FSL_IFC_CS6,
FSL_IFC_CS7,
+} FSL_IFC_CHIP_SEL;
+typedef enum {
FSL_IFC_FTIM0 = 0,
FSL_IFC_FTIM1,
FSL_IFC_FTIM2,
FSL_IFC_FTIM3,
+} FSL_IFC_FTIMS;
+/*
- Instruction opcodes to be programmed
- in FIR registers- 6bits
- */
+enum ifc_nand_fir_opcodes {
FSL_IFC_FIR_OP_NOP,
FSL_IFC_FIR_OP_CA0,
FSL_IFC_FIR_OP_CA1,
FSL_IFC_FIR_OP_CA2,
FSL_IFC_FIR_OP_CA3,
FSL_IFC_FIR_OP_RA0,
FSL_IFC_FIR_OP_RA1,
FSL_IFC_FIR_OP_RA2,
FSL_IFC_FIR_OP_RA3,
FSL_IFC_FIR_OP_CMD0,
FSL_IFC_FIR_OP_CMD1,
FSL_IFC_FIR_OP_CMD2,
FSL_IFC_FIR_OP_CMD3,
FSL_IFC_FIR_OP_CMD4,
FSL_IFC_FIR_OP_CMD5,
FSL_IFC_FIR_OP_CMD6,
FSL_IFC_FIR_OP_CMD7,
FSL_IFC_FIR_OP_CW0,
FSL_IFC_FIR_OP_CW1,
FSL_IFC_FIR_OP_CW2,
FSL_IFC_FIR_OP_CW3,
FSL_IFC_FIR_OP_CW4,
FSL_IFC_FIR_OP_CW5,
FSL_IFC_FIR_OP_CW6,
FSL_IFC_FIR_OP_CW7,
FSL_IFC_FIR_OP_WBCD,
FSL_IFC_FIR_OP_RBCD,
FSL_IFC_FIR_OP_BTRD,
FSL_IFC_FIR_OP_RDSTAT,
FSL_IFC_FIR_OP_NWAIT,
FSL_IFC_FIR_OP_WFR,
FSL_IFC_FIR_OP_SBRD,
FSL_IFC_FIR_OP_UA,
FSL_IFC_FIR_OP_RB,
+};
+typedef struct {
UINT32 cspr_ext;
UINT32 cspr;
UINT32 res;
+} FSL_IFC_CSPR;
+typedef struct {
UINT32 amask;
UINT32 res[0x2];
+} FSL_IFC_AMASK;
+typedef struct {
UINT32 csor;
UINT32 csor_ext;
UINT32 res;
+} FSL_IFC_CSOR;
+typedef struct {
UINT32 ftim[4];
UINT32 res[0x8];
+}FSL_IFC_FTIM ;
+typedef struct {
UINT32 ncfgr;
UINT32 res1[0x4];
UINT32 nand_fcr0;
UINT32 nand_fcr1;
UINT32 res2[0x8];
UINT32 row0;
UINT32 res3;
UINT32 col0;
UINT32 res4;
UINT32 row1;
UINT32 res5;
UINT32 col1;
UINT32 res6;
UINT32 row2;
UINT32 res7;
UINT32 col2;
UINT32 res8;
UINT32 row3;
UINT32 res9;
UINT32 col3;
UINT32 res10[0x24];
UINT32 nand_fbcr;
UINT32 res11;
UINT32 nand_fir0;
UINT32 nand_fir1;
UINT32 nand_fir2;
UINT32 res12[0x10];
UINT32 nand_csel;
UINT32 res13;
UINT32 nandseq_strt;
UINT32 res14;
UINT32 nand_evter_stat;
UINT32 res15;
UINT32 pgrdcmpl_evt_stat;
UINT32 res16[0x2];
UINT32 nand_evter_en;
UINT32 res17[0x2];
UINT32 nand_evter_intr_en;
UINT32 res18[0x2];
UINT32 nand_erattr0;
UINT32 nand_erattr1;
UINT32 res19[0x10];
UINT32 nand_fsr;
UINT32 res20;
UINT32 nand_eccstat[4];
UINT32 res21[0x20];
UINT32 nanndcr;
UINT32 res22[0x2];
UINT32 nand_autoboot_trgr;
UINT32 res23;
UINT32 nand_mdr;
UINT32 res24[0x5C];
+} FSL_IFC_NAND;
+/*
- IFC controller NOR Machine registers */ typedef struct {
UINT32 nor_evter_stat;
UINT32 res1[0x2];
UINT32 nor_evter_en;
UINT32 res2[0x2];
UINT32 nor_evter_intr_en;
UINT32 res3[0x2];
UINT32 nor_erattr0;
UINT32 nor_erattr1;
UINT32 nor_erattr2;
UINT32 res4[0x4];
UINT32 norcr;
UINT32 res5[0xEF];
+} FSL_IFC_NOR;
+/*
- IFC controller GPCM Machine registers
- */
+typedef struct {
UINT32 gpcm_evter_stat;
UINT32 res1[0x2];
UINT32 gpcm_evter_en;
UINT32 res2[0x2];
UINT32 gpcm_evter_intr_en;
UINT32 res3[0x2];
UINT32 gpcm_erattr0;
UINT32 gpcm_erattr1;
UINT32 gpcm_erattr2;
UINT32 gpcm_stat;
+} FSL_IFC_GPCM;
+/*
- IFC Controller Registers
- */
+typedef struct {
UINT32 ifc_rev;
UINT32 res1[0x2];
FSL_IFC_CSPR cspr_cs[FSL_IFC_BANK_COUNT];
UINT8 res2[FSL_IFC_CSPR_REG_LEN - FSL_IFC_CSPR_USED_LEN];
FSL_IFC_AMASK amask_cs[FSL_IFC_BANK_COUNT];
UINT8 res3[FSL_IFC_AMASK_REG_LEN - FSL_IFC_AMASK_USED_LEN];
FSL_IFC_CSOR csor_cs[FSL_IFC_BANK_COUNT];
UINT8 res4[FSL_IFC_CSOR_REG_LEN - FSL_IFC_CSOR_USED_LEN];
FSL_IFC_FTIM ftim_cs[FSL_IFC_BANK_COUNT];
UINT8 res5[FSL_IFC_FTIM_REG_LEN - FSL_IFC_FTIM_USED_LEN];
UINT32 rb_stat;
UINT32 rb_map;
UINT32 wp_map;
UINT32 ifc_gcr;
UINT32 res7[0x2];
UINT32 cm_evter_stat;
UINT32 res8[0x2];
UINT32 cm_evter_en;
UINT32 res9[0x2];
UINT32 cm_evter_intr_en;
UINT32 res10[0x2];
UINT32 cm_erattr0;
UINT32 cm_erattr1;
UINT32 res11[0x2];
UINT32 ifc_ccr;
UINT32 ifc_csr;
UINT32 ddr_ccr_low;
UINT32 res12[0x2EA];
FSL_IFC_NAND ifc_nand;
FSL_IFC_NOR ifc_nor;
FSL_IFC_GPCM ifc_gpcm;
+} FSL_IFC_REGS;
+VOID IfcNorInit(VOID);
+VOID IfcNandInit(VOID);
+#define FSL_IFC_REGS_BASE \
((FSL_IFC_REGS *)FSL_IFC_REG_BASE)
+#endif //__FLASH_H__ diff --git a/Platforms/Nxp/LS1043aRdb/Library/CpldLib/CpldLib.c
b/Platforms/Nxp/LS1043aRdb/Library/CpldLib/CpldLib.c
new file mode 100644 index 0000000..fe115c8 --- /dev/null +++ b/Platforms/Nxp/LS1043aRdb/Library/CpldLib/CpldLib.c @@ -0,0 +1,157 @@ +/** @CpldLib.c
- Cpld specific Library for LS1043A-RDB board, containing functions
to
- program and read the Cpld registers.
- Copyright (c) 2016, Freescale Semiconductor, Inc. All rights
reserved.
- This program and the accompanying materials
- are licensed and made available under the terms and conditions of
the BSD License
- which accompanies this distribution. The full text of the license
may be found at
- http://opensource.org/licenses/bsd-license.php
- THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS"
BASIS,
- WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS
OR IMPLIED.
+**/
+#include <Base.h> +#include <PiPei.h> +#include <Uefi.h>
+#include <Library/BaseLib.h> +#include <Library/DebugLib.h> +#include <Library/IoLib.h> +#include <Library/PrintLib.h> +#include <Library/SerialPortLib.h>
+#include <Library/PlatformLib.h> +#include <Library/CpldLib.h> +#include <Library/FslIfc.h>
+UINT8 +CpldRead (
- OUT UINTN Reg
- )
+{
VOID *Base = (VOID *)LS1043A_CPLD_BASE;
return MmioRead8((UINTN)(Base + Reg));
+}
+VOID +CpldWrite (
- IN UINTN Reg,
- IN UINT8 Value
- )
+{
VOID *Base = (VOID *)LS1043A_CPLD_BASE;
MmioWrite8((UINTN)(Base + Reg), Value);
+}
+/* Set the boot bank to the alternate bank */ +VOID +CpldSetAlternatebank (
- VOID
- )
+{
UINT8 Reg4 = CPLD_READ(SoftMuxOn);
UINT8 Reg7 = CPLD_READ(Vbank);
CPLD_WRITE(SoftMuxOn, Reg4 | CPLD_SW_MUX_BANK_SEL);
Reg7 = (Reg7 & ~CPLD_BANK_SEL_MASK) | CPLD_BANK_SEL_ALTBANK;
CPLD_WRITE(Vbank, Reg7);
CPLD_WRITE(SystemReset, 1);
+}
+/* Set the boot bank to the default bank */ +VOID +CpldSetDefaultBank (
- VOID
- )
+{
CPLD_WRITE(GlobalReset, 1);
+}
+VOID +CpldDumpRegs (
- VOID
- )
+{
DEBUG((EFI_D_INFO, "CpldVersionMajor = %x\n",
CPLD_READ(CpldVersionMajor)));
DEBUG((EFI_D_INFO, "CpldVersionMinor = %x\n",
CPLD_READ(CpldVersionMinor)));
DEBUG((EFI_D_INFO, "PcbaVersion = %x\n",
CPLD_READ(PcbaVersion)));
DEBUG((EFI_D_INFO, "SoftMuxOn = %x\n",
CPLD_READ(SoftMuxOn)));
DEBUG((EFI_D_INFO, "RcwSource1 = %x\n",
CPLD_READ(RcwSource1)));
DEBUG((EFI_D_INFO, "RcwSource2 = %x\n",
CPLD_READ(RcwSource2)));
DEBUG((EFI_D_INFO, "Vbank = %x\n",
CPLD_READ(Vbank)));
DEBUG((EFI_D_INFO, "SysclkSelect = %x\n",
CPLD_READ(SysclkSelect)));
DEBUG((EFI_D_INFO, "UartSel = %x\n",
CPLD_READ(UartSel)));
DEBUG((EFI_D_INFO, "Sd1RefClkSel = %x\n",
CPLD_READ(Sd1RefClkSel)));
DEBUG((EFI_D_INFO, "TdmClkMuxSel = %x\n",
CPLD_READ(TdmClkMuxSel)));
DEBUG((EFI_D_INFO, "SdhcSpiCsSel = %x\n",
CPLD_READ(SdhcSpiCsSel)));
DEBUG((EFI_D_INFO, "StatusLed = %x\n",
CPLD_READ(StatusLed)));
+}
+VOID +CpldRevBit (
- OUT UINT8 *Value
- )
+{
UINT8 Rev, Val;
UINTN Index;
Val = *Value;
Rev = Val & 1;
for (Index = 1; Index <= 7; Index++) {
Val >>= 1;
Rev <<= 1;
Rev |= Val & 1;
}
*Value = Rev;
+}
+VOID +DoCpld (
- IN CpldCmd Cmd
- )
+{
switch (Cmd) {
case RESET:
CpldSetDefaultBank();
break;
case RESET_ALTBANK:
CpldSetAlternatebank();
break;
case DUMP_REGISTERS:
CpldDumpRegs();
break;
default:
DEBUG((EFI_D_ERROR, "Error: Unknown Cpld
Command!\n"));
break;
}
+}
+VOID +CpldInit (
- VOID
- )
+{
MmioWriteBe32((UINTN) &(FSL_IFC_REGS_BASE)-
cspr_cs[FSL_IFC_CS2].cspr_ext, FSL_IFC_CPLD_CSPR_EXT);
MmioWriteBe32((UINTN) &(FSL_IFC_REGS_BASE)-
ftim_cs[FSL_IFC_CS2].ftim[FSL_IFC_FTIM0],
FSL_IFC_CPLD_FTIM0);
MmioWriteBe32((UINTN) &(FSL_IFC_REGS_BASE)-
ftim_cs[FSL_IFC_CS2].ftim[FSL_IFC_FTIM1],
FSL_IFC_CPLD_FTIM1);
MmioWriteBe32((UINTN) &(FSL_IFC_REGS_BASE)-
ftim_cs[FSL_IFC_CS2].ftim[FSL_IFC_FTIM2],
FSL_IFC_CPLD_FTIM2);
MmioWriteBe32((UINTN) &(FSL_IFC_REGS_BASE)-
ftim_cs[FSL_IFC_CS2].ftim[FSL_IFC_FTIM3],
FSL_IFC_CPLD_FTIM3);
MmioWriteBe32((UINTN) &(FSL_IFC_REGS_BASE)-
csor_cs[FSL_IFC_CS2].csor, FSL_IFC_CPLD_CSOR);
MmioWriteBe32((UINTN) &(FSL_IFC_REGS_BASE)-
amask_cs[FSL_IFC_CS2].amask, FSL_IFC_CPLD_AMASK);
MmioWriteBe32((UINTN) &(FSL_IFC_REGS_BASE)-
cspr_cs[FSL_IFC_CS2].cspr, FSL_IFC_CPLD_CSPR); +} diff --git a/Platforms/Nxp/LS1043aRdb/Library/CpldLib/CpldLib.inf
b/Platforms/Nxp/LS1043aRdb/Library/CpldLib/CpldLib.inf
new file mode 100644 index 0000000..f37d153 --- /dev/null +++ b/Platforms/Nxp/LS1043aRdb/Library/CpldLib/CpldLib.inf @@ -0,0 +1,33 @@ +#/* @CpldLib.inf +# Copyright (c) 2016, Freescale Semiconductor, Inc. All rights
reserved.
+# +# This program and the accompanying materials +# are licensed and made available under the terms and conditions of
the BSD License
+# which accompanies this distribution. The full text of the
license may be found at
+# http://opensource.org/licenses/bsd-license.php +# +# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS"
BASIS,
+# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS
OR IMPLIED.
+# +#*/
+[Defines]
- INF_VERSION = 0x00010005
- BASE_NAME = CpldLib
- FILE_GUID = 5962d040-8b8a-11df-9a71-
0002a5d5c51b
Please use a fresh GUID
Ok.
- MODULE_TYPE = BASE
- VERSION_STRING = 1.0
- LIBRARY_CLASS = CpldLib
+[Sources.common]
- CpldLib.c
+[Packages]
- MdePkg/MdePkg.dec
- ArmPkg/ArmPkg.dec
- ArmPlatformPkg/ArmPlatformPkg.dec
- OpenPlatformPkg/Platforms/Nxp/LS1043aRdb/LS1043aRdbPkg.dec
+[LibraryClasses]
- BaseLib
- IoLib
-- 1.9.1
Regards, Bhupesh
Apologies for lagging a bit on this review, I'll try to get through the rest of the series today, starting with this one.
On Tue, Oct 18, 2016 at 01:34:02AM +0530, Bhupesh Sharma wrote:
From: Sakar Arora sakar.arora@nxp.com
NXP/FSL's LS1043A-RDB board houses a CPLD (FPGA) which can be used to control various pin-multiplexing options, which allows certain combinations of peripherals to be enabled on the board.
In addition this CPLD provides a mechanism to divide the NOR/NAND flash memory into primary and alternate regions. While golden images can be flashed on the primary bank, experimental images can be flashed on the alternate bank.
CPLD provides a way to switch from primary to alternate region (and vice-versa), thus protecting the board from damage if primary region is flashed with incorrect set of images.
That's a very tidy and helpful commit message - thanks!
Signed-off-by: Sakar Arora sakar.arora@nxp.com Signed-off-by: Bhupesh Sharma bhupesh.sharma@nxp.com
Platforms/Nxp/LS1043aRdb/Include/Library/CpldLib.h | 75 +++ Platforms/Nxp/LS1043aRdb/Include/Library/FslIfc.h | 721 +++++++++++++++++++++ Platforms/Nxp/LS1043aRdb/Library/CpldLib/CpldLib.c | 157 +++++ .../Nxp/LS1043aRdb/Library/CpldLib/CpldLib.inf | 33 + 4 files changed, 986 insertions(+) create mode 100644 Platforms/Nxp/LS1043aRdb/Include/Library/CpldLib.h create mode 100644 Platforms/Nxp/LS1043aRdb/Include/Library/FslIfc.h create mode 100644 Platforms/Nxp/LS1043aRdb/Library/CpldLib/CpldLib.c create mode 100644 Platforms/Nxp/LS1043aRdb/Library/CpldLib/CpldLib.inf
diff --git a/Platforms/Nxp/LS1043aRdb/Include/Library/CpldLib.h b/Platforms/Nxp/LS1043aRdb/Include/Library/CpldLib.h new file mode 100644 index 0000000..56f47da --- /dev/null +++ b/Platforms/Nxp/LS1043aRdb/Include/Library/CpldLib.h @@ -0,0 +1,75 @@ +/** CpldLib.h +* Header defining the LS1043a Cpld specific constants (Base addresses, sizes, flags) +* +* Copyright (c) 2016, Freescale Semiconductor, Inc. All rights reserved.
Should this say NXP now? (If so, please revise all patches for v2.)
+* +* This program and the accompanying materials +* are licensed and made available under the terms and conditions of the BSD License +* which accompanies this distribution. The full text of the license may be found at +* http://opensource.org/licenses/bsd-license.php +* +* THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, +* WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. +* +**/
+#ifndef __LS1043A_CPLD_H__ +#define __LS1043A_CPLD_H__
+#include <Library/Common.h>
+/*
- CPLD register set of LS1043ARDB board-specific.
- */
+struct CpldRegSet {
- UINT8 CpldVersionMajor; /* 0x0 - CPLD Major Revision Register */
More tabs, but I think you'll be addressing that for v2?
- UINT8 CpldVersionMinor; /* 0x1 - CPLD Minor Revision Register */
- UINT8 PcbaVersion; /* 0x2 - PCBA Revision Register */
- UINT8 SystemReset; /* 0x3 - system reset register */
- UINT8 SoftMuxOn; /* 0x4 - Switch Control Enable Register */
- UINT8 RcwSource1; /* 0x5 - Reset config word 1 */
- UINT8 RcwSource2; /* 0x6 - Reset config word 1 */
Two questions: - Both comments say "word 1". Guessing one should say 2? - Both are UINT8. Why are they called "word"?
- UINT8 Vbank; /* 0x7 - Flash bank selection Control */
- UINT8 SysclkSelect; /* 0x8 - */
- UINT8 UartSel; /* 0x9 - */
- UINT8 Sd1RefClkSel; /* 0xA - */
- UINT8 TdmClkMuxSel; /* 0xB - */
- UINT8 SdhcSpiCsSel; /* 0xC - */
- UINT8 StatusLed; /* 0xD - */
- UINT8 GlobalReset; /* 0xE - */
+};
+/*
- Reset the board, Reset to alternate bank or Dump registers:
- RESET - reset to default bank
- RESET_ALTBANK - reset to alternate bank
- DUMP_REGISTERS - display the CPLD registers
- */
+typedef enum {
- RESET = 0,
- RESET_ALTBANK,
- DUMP_REGISTERS
+} CpldCmd;
+UINT8 CpldRead(UINTN Reg); +VOID CpldWrite(UINTN Reg, UINT8 Value); +VOID CpldRevBit(UINT8 *Value); +VOID DoCpld (CpldCmd Cmd); +VOID CpldInit (VOID);
+#define CPLD_READ(Reg) CpldRead(offsetof(struct CpldRegSet, Reg))
So, I missed the offsetof being added in 1/14. This is a very Linux specific macro, and while clearly useful, if we're going to have it, it should be in EDK2 coding style and defined somewhere centrally - not in a platform specific header.
+#define CPLD_WRITE(Reg, Value) \
- CpldWrite(offsetof(struct CpldRegSet, Reg), Value)
+/* CPLD on IFC */ +#define CPLD_SW_MUX_BANK_SEL 0x40 +#define CPLD_BANK_SEL_MASK 0x07 +#define CPLD_BANK_SEL_ALTBANK 0x04
+/* SDXC/DSPI CPLD Settings */ +#define ENABLE_SDXC_SOFT_MUX 0x30 +#define ENABLE_RCW_SOFT_MUX 0x01 +#define SELECT_SW4_SDXC 0x40 +#define SELECT_SW5_SDXC 0x01
+#endif diff --git a/Platforms/Nxp/LS1043aRdb/Include/Library/FslIfc.h b/Platforms/Nxp/LS1043aRdb/Include/Library/FslIfc.h new file mode 100644 index 0000000..27c8295 --- /dev/null +++ b/Platforms/Nxp/LS1043aRdb/Include/Library/FslIfc.h @@ -0,0 +1,721 @@ +/** @FslIfc.h
- Copyright (c) 2008 - 2009, Apple Inc. All rights reserved.<BR>
- Copyright (c) 2016, Freescale Semiconductor, Inc. All rights reserved.
- This program and the accompanying materials
- are licensed and made available under the terms and conditions of the BSD License
- which accompanies this distribution. The full text of the license may be found at
- http://opensource.org/licenses/bsd-license.php
- THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
- WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
+**/
+#ifndef __FLASH_H__ +#define __FLASH_H__
+#include <Uefi.h>
+#include <Library/BaseLib.h> +#include <Library/BaseMemoryLib.h> +#include <Library/MemoryAllocationLib.h> +#include <Library/DebugLib.h> +#include <Library/IoLib.h> +#include <Library/PcdLib.h> +#include <Library/UefiBootServicesTableLib.h> +#include <Library/IoLib.h>
Included twice.
+#include <Library/PlatformLib.h>
Please add alphabetically sorted.
+#include <Protocol/BlockIo.h> +#include <Protocol/Cpu.h>
+#define NOIBR
+#define FSL_IFC_BANK_COUNT 4
+#define NAND_PAGE_SIZE_2K (2048)
I'm thinking 2K of NAND is as big as 2K of anything. Better to use the existing definitions in Base.h, in this case SIZE_2KB.
+#define NAND_SPARE_AREA_SIZE_64B (64) +#define NAND_BLOCK_SIZE_128K (128*1024)
There's actually a SIZE_128KB too.
+#define NAND_BLOCK_COUNT (2048) +#define NAND_LAST_BLOCK (NAND_BLOCK_COUNT - 1)
+//List of commands. +#define IFC_NAND_CMD_RESET 0xFF +#define IFC_NAND_CMD_READID 0x90
+#define IFC_NAND_CMD_STATUS 0x70
+#define IFC_NAND_CMD_READ0 0x00 +#define IFC_NAND_CMD_READSTART 0x30
+#define IFC_NAND_CMD_ERASE1 0x60 +#define IFC_NAND_CMD_ERASE2 0xD0
+#define IFC_NAND_CMD_SEQIN 0x80 +#define IFC_NAND_CMD_PAGEPROG 0x10
+#define MAX_RETRY_COUNT 150000
+#define FSL_IFC_REG_BASE 0x1530000 +#define FSL_IFC_NAND_BUF_BASE 0x70000000 +#define FSL_IFC_NOR_BUF_BASE 0x60000000
+#define FSL_IFC_NOR_RESERVED_REGION_BASE 0x60700000
+#define FSL_IFC_CSPR_REG_LEN 148 +#define FSL_IFC_AMASK_REG_LEN 144 +#define FSL_IFC_CSOR_REG_LEN 144 +#define FSL_IFC_FTIM_REG_LEN 576
+#define FSL_IFC_NAND_SEQ_STRT_FIR_STRT 0x80000000
+#define FSL_IFC_CSPR_USED_LEN sizeof(FSL_IFC_CSPR) * \
FSL_IFC_BANK_COUNT
+#define FSL_IFC_AMASK_USED_LEN sizeof(FSL_IFC_AMASK) * \
FSL_IFC_BANK_COUNT
+#define FSL_IFC_CSOR_USED_LEN sizeof(FSL_IFC_CSOR) * \
FSL_IFC_BANK_COUNT
+#define FSL_IFC_FTIM_USED_LEN sizeof(FSL_IFC_FTIM) * \
FSL_IFC_BANK_COUNT
+/*
- NAND Event and Error Status Register (NAND_EVTER_STAT)
- */
+/* Operation Complete */ +#define FSL_IFC_NAND_EVTER_STAT_OPC 0x80000000 +/* Flash Timeout Error */ +#define FSL_IFC_NAND_EVTER_STAT_FTOER 0x08000000 +/* Write Protect Error */ +#define FSL_IFC_NAND_EVTER_STAT_WPER 0x04000000 +/* ECC Error */ +#define FSL_IFC_NAND_EVTER_STAT_ECCER 0x02000000
+/*
- NAND Flash Byte Count Register (NAND_BC)
- */
+/* Byte Count for read/Write */ +#define FSL_IFC_NAND_BC 0x000001FF
+/*
- NAND Flash Instruction Registers (NAND_FIR0/NAND_FIR1/NAND_FIR2)
- */
+/* NAND Machine specific opcodes OP0-OP14*/ +#define FSL_IFC_NAND_FIR0_OP0 0xFC000000 +#define FSL_IFC_NAND_FIR0_OP0_SHIFT 26 +#define FSL_IFC_NAND_FIR0_OP1 0x03F00000 +#define FSL_IFC_NAND_FIR0_OP1_SHIFT 20 +#define FSL_IFC_NAND_FIR0_OP2 0x000FC000 +#define FSL_IFC_NAND_FIR0_OP2_SHIFT 14 +#define FSL_IFC_NAND_FIR0_OP3 0x00003F00 +#define FSL_IFC_NAND_FIR0_OP3_SHIFT 8 +#define FSL_IFC_NAND_FIR0_OP4 0x000000FC +#define FSL_IFC_NAND_FIR0_OP4_SHIFT 2 +#define FSL_IFC_NAND_FIR1_OP5 0xFC000000 +#define FSL_IFC_NAND_FIR1_OP5_SHIFT 26 +#define FSL_IFC_NAND_FIR1_OP6 0x03F00000 +#define FSL_IFC_NAND_FIR1_OP6_SHIFT 20 +#define FSL_IFC_NAND_FIR1_OP7 0x000FC000 +#define FSL_IFC_NAND_FIR1_OP7_SHIFT 14 +#define FSL_IFC_NAND_FIR1_OP8 0x00003F00 +#define FSL_IFC_NAND_FIR1_OP8_SHIFT 8 +#define FSL_IFC_NAND_FIR1_OP9 0x000000FC +#define FSL_IFC_NAND_FIR1_OP9_SHIFT 2 +#define FSL_IFC_NAND_FIR2_OP10 0xFC000000 +#define FSL_IFC_NAND_FIR2_OP10_SHIFT 26 +#define FSL_IFC_NAND_FIR2_OP11 0x03F00000 +#define FSL_IFC_NAND_FIR2_OP11_SHIFT 20 +#define FSL_IFC_NAND_FIR2_OP12 0x000FC000 +#define FSL_IFC_NAND_FIR2_OP12_SHIFT 14 +#define FSL_IFC_NAND_FIR2_OP13 0x00003F00 +#define FSL_IFC_NAND_FIR2_OP13_SHIFT 8 +#define FSL_IFC_NAND_FIR2_OP14 0x000000FC +#define FSL_IFC_NAND_FIR2_OP14_SHIFT 2
+/*
- NAND Flash Command Registers (NAND_FCR0/NAND_FCR1)
- */
+/* General purpose FCM flash command bytes CMD0-CMD7 */ +#define FSL_IFC_NAND_FCR0_CMD0 0xFF000000 +#define FSL_IFC_NAND_FCR0_CMD0_SHIFT 24 +#define FSL_IFC_NAND_FCR0_CMD1 0x00FF0000 +#define FSL_IFC_NAND_FCR0_CMD1_SHIFT 16 +#define FSL_IFC_NAND_FCR0_CMD2 0x0000FF00 +#define FSL_IFC_NAND_FCR0_CMD2_SHIFT 8 +#define FSL_IFC_NAND_FCR0_CMD3 0x000000FF +#define FSL_IFC_NAND_FCR0_CMD3_SHIFT 0 +#define FSL_IFC_NAND_FCR1_CMD4 0xFF000000 +#define FSL_IFC_NAND_FCR1_CMD4_SHIFT 24 +#define FSL_IFC_NAND_FCR1_CMD5 0x00FF0000 +#define FSL_IFC_NAND_FCR1_CMD5_SHIFT 16 +#define FSL_IFC_NAND_FCR1_CMD6 0x0000FF00 +#define FSL_IFC_NAND_FCR1_CMD6_SHIFT 8 +#define FSL_IFC_NAND_FCR1_CMD7 0x000000FF +#define FSL_IFC_NAND_FCR1_CMD7_SHIFT 0
+/* Timing registers for NAND Flash */
+#define FSL_IFC_FTIM0_NAND_TCCST_SHIFT 25 +#define FSL_IFC_FTIM0_NAND_TCCST(n) ((n) << FSL_IFC_FTIM0_NAND_TCCST_SHIFT) +#define FSL_IFC_FTIM0_NAND_TWP_SHIFT 16 +#define FSL_IFC_FTIM0_NAND_TWP(n) ((n) << FSL_IFC_FTIM0_NAND_TWP_SHIFT) +#define FSL_IFC_FTIM0_NAND_TWCHT_SHIFT 8 +#define FSL_IFC_FTIM0_NAND_TWCHT(n) ((n) << FSL_IFC_FTIM0_NAND_TWCHT_SHIFT) +#define FSL_IFC_FTIM0_NAND_TWH_SHIFT 0 +#define FSL_IFC_FTIM0_NAND_TWH(n) ((n) << FSL_IFC_FTIM0_NAND_TWH_SHIFT) +#define FSL_IFC_FTIM1_NAND_TADLE_SHIFT 24 +#define FSL_IFC_FTIM1_NAND_TADLE(n) ((n) << FSL_IFC_FTIM1_NAND_TADLE_SHIFT) +#define FSL_IFC_FTIM1_NAND_TWBE_SHIFT 16 +#define FSL_IFC_FTIM1_NAND_TWBE(n) ((n) << FSL_IFC_FTIM1_NAND_TWBE_SHIFT) +#define FSL_IFC_FTIM1_NAND_TRR_SHIFT 8 +#define FSL_IFC_FTIM1_NAND_TRR(n) ((n) << FSL_IFC_FTIM1_NAND_TRR_SHIFT) +#define FSL_IFC_FTIM1_NAND_TRP_SHIFT 0 +#define FSL_IFC_FTIM1_NAND_TRP(n) ((n) << FSL_IFC_FTIM1_NAND_TRP_SHIFT) +#define FSL_IFC_FTIM2_NAND_TRAD_SHIFT 21 +#define FSL_IFC_FTIM2_NAND_TRAD(n) ((n) << FSL_IFC_FTIM2_NAND_TRAD_SHIFT) +#define FSL_IFC_FTIM2_NAND_TREH_SHIFT 11 +#define FSL_IFC_FTIM2_NAND_TREH(n) ((n) << FSL_IFC_FTIM2_NAND_TREH_SHIFT) +#define FSL_IFC_FTIM2_NAND_TWHRE_SHIFT 0 +#define FSL_IFC_FTIM2_NAND_TWHRE(n) ((n) << FSL_IFC_FTIM2_NAND_TWHRE_SHIFT) +#define FSL_IFC_FTIM3_NAND_TWW_SHIFT 24 +#define FSL_IFC_FTIM3_NAND_TWW(n) ((n) << FSL_IFC_FTIM3_NAND_TWW_SHIFT)
+/*
- Flash ROW and COL Address Register (ROWn, COLn)
- */
+/* Main/spare region locator */ +#define FSL_IFC_NAND_COL_MS 0x80000000 +/* Column Address */ +#define FSL_IFC_NAND_COL_CA_MASK 0x00000FFF
+#define NAND_STATUS_WP 0x80
+/*
- NAND Event and Error Enable Register (NAND_EVTER_EN)
- */
+/* Operation complete event enable */ +#define FSL_IFC_NAND_EVTER_EN_OPC_EN 0x80000000 +/* Page read complete event enable */ +#define FSL_IFC_NAND_EVTER_EN_PGRDCMPL_EN 0x20000000 +/* Flash Timeout error enable */ +#define FSL_IFC_NAND_EVTER_EN_FTOER_EN 0x08000000 +/* Write Protect error enable */ +#define FSL_IFC_NAND_EVTER_EN_WPER_EN 0x04000000 +/* ECC error logging enable */ +#define FSL_IFC_NAND_EVTER_EN_ECCER_EN 0x02000000
+/*
- CSPR - Chip Select Property Register
- */
+#define IFC_CSPR_BA 0xFFFF0000 +#define IFC_CSPR_BA_SHIFT 16 +#define IFC_CSPR_PORT_SIZE 0x00000180 +#define IFC_CSPR_PORT_SIZE_SHIFT 7 +/* Port Size 8 bit */ +#define IFC_CSPR_PORT_SIZE_8 0x00000080 +/* Port Size 16 bit */ +#define IFC_CSPR_PORT_SIZE_16 0x00000100 +/* Port Size 32 bit */ +#define IFC_CSPR_PORT_SIZE_32 0x00000180 +/* Write Protect */ +#define IFC_CSPR_WP 0x00000040 +#define IFC_CSPR_WP_SHIFT 6 +/* Machine Select */ +#define IFC_CSPR_MSEL 0x00000006 +#define IFC_CSPR_MSEL_SHIFT 1 +/* NOR */ +#define IFC_CSPR_MSEL_NOR 0x00000000 +/* NAND */ +#define IFC_CSPR_MSEL_NAND 0x00000002 +/* GPCM */ +#define IFC_CSPR_MSEL_GPCM 0x00000004 +/* Bank Valid */ +#define IFC_CSPR_V 0x00000001 +#define IFC_CSPR_V_SHIFT 0
+/*
- Chip Select Option Register - NOR Flash Mode
- */
+/* Enable Address shift Mode */ +#define IFC_CSOR_NOR_ADM_SHFT_MODE_EN 0x80000000 +/* Page Read Enable from NOR device */ +#define IFC_CSOR_NOR_PGRD_EN 0x10000000 +/* AVD Toggle Enable during Burst Program */ +#define IFC_CSOR_NOR_AVD_TGL_PGM_EN 0x01000000 +/* Address Data Multiplexing Shift */ +#define IFC_CSOR_NOR_ADM_MASK 0x0003E000 +#define IFC_CSOR_NOR_ADM_SHIFT_SHIFT 13 +#define IFC_CSOR_NOR_ADM_SHIFT(n) ((n) << IFC_CSOR_NOR_ADM_SHIFT_SHIFT) +/* Type of the NOR device hooked */ +#define IFC_CSOR_NOR_NOR_MODE_AYSNC_NOR 0x00000000 +#define IFC_CSOR_NOR_NOR_MODE_AVD_NOR 0x00000020 +/* Time for Read Enable High to Output High Impedance */ +#define IFC_CSOR_NOR_TRHZ_MASK 0x0000001C +#define IFC_CSOR_NOR_TRHZ_SHIFT 2 +#define IFC_CSOR_NOR_TRHZ_20 0x00000000 +#define IFC_CSOR_NOR_TRHZ_40 0x00000004 +#define IFC_CSOR_NOR_TRHZ_60 0x00000008 +#define IFC_CSOR_NOR_TRHZ_80 0x0000000C +#define IFC_CSOR_NOR_TRHZ_100 0x00000010 +/* Buffer control disable */ +#define IFC_CSOR_NOR_BCTLD 0x00000001
+/*
- Chip Select Option Register FSL_IFC_NAND Machine
- */
+/* Enable ECC Encoder */ +#define IFC_CSOR_NAND_ECC_ENC_EN 0x80000000 +#define IFC_CSOR_NAND_ECC_MODE_MASK 0x30000000 +/* 4 bit correction per 520 Byte sector */ +#define IFC_CSOR_NAND_ECC_MODE_4 0x00000000 +/* 8 bit correction per 528 Byte sector */ +#define IFC_CSOR_NAND_ECC_MODE_8 0x10000000 +/* Enable ECC Decoder */ +#define IFC_CSOR_NAND_ECC_DEC_EN 0x04000000 +/* Row Address Length */ +#define IFC_CSOR_NAND_RAL_MASK 0x01800000 +#define IFC_CSOR_NAND_RAL_SHIFT 20 +#define IFC_CSOR_NAND_RAL_1 0x00000000 +#define IFC_CSOR_NAND_RAL_2 0x00800000 +#define IFC_CSOR_NAND_RAL_3 0x01000000 +#define IFC_CSOR_NAND_RAL_4 0x01800000 +/* Page Size 512b, 2k, 4k */ +#define IFC_CSOR_NAND_PGS_MASK 0x00180000 +#define IFC_CSOR_NAND_PGS_SHIFT 16 +#define IFC_CSOR_NAND_PGS_512 0x00000000 +#define IFC_CSOR_NAND_PGS_2K 0x00080000 +#define IFC_CSOR_NAND_PGS_4K 0x00100000 +#define IFC_CSOR_NAND_PGS_8K 0x00180000 +/* Spare region Size */ +#define IFC_CSOR_NAND_SPRZ_MASK 0x0000E000 +#define IFC_CSOR_NAND_SPRZ_SHIFT 13 +#define IFC_CSOR_NAND_SPRZ_16 0x00000000 +#define IFC_CSOR_NAND_SPRZ_64 0x00002000 +#define IFC_CSOR_NAND_SPRZ_128 0x00004000 +#define IFC_CSOR_NAND_SPRZ_210 0x00006000 +#define IFC_CSOR_NAND_SPRZ_218 0x00008000 +#define IFC_CSOR_NAND_SPRZ_224 0x0000A000 +#define IFC_CSOR_NAND_SPRZ_CSOR_EXT 0x0000C000 +/* Pages Per Block */ +#define IFC_CSOR_NAND_PB_MASK 0x00000700 +#define IFC_CSOR_NAND_PB_SHIFT 8 +#define IFC_CSOR_NAND_PB(n) (n-5) << IFC_CSOR_NAND_PB_SHIFT +/* Time for Read Enable High to Output High Impedance */ +#define IFC_CSOR_NAND_TRHZ_MASK 0x0000001C +#define IFC_CSOR_NAND_TRHZ_SHIFT 2 +#define IFC_CSOR_NAND_TRHZ_20 0x00000000 +#define IFC_CSOR_NAND_TRHZ_40 0x00000004 +#define IFC_CSOR_NAND_TRHZ_60 0x00000008 +#define IFC_CSOR_NAND_TRHZ_80 0x0000000C +#define IFC_CSOR_NAND_TRHZ_100 0x00000010 +/* Buffer control disable */ +#define IFC_CSOR_NAND_BCTLD 0x00000001
+#define FSL_IFC_NAND_BUF_MASK 0xffff0000 +#define FSL_IFC_NOR_BUF_MASK 0xffff0000
+#define FSL_IFC_NAND_CSPR ((FSL_IFC_NAND_BUF_BASE & FSL_IFC_NAND_BUF_MASK)\
| IFC_CSPR_PORT_SIZE_8 \
| IFC_CSPR_MSEL_NAND \
| IFC_CSPR_V)
+#define FSL_IFC_NAND_CSPR_EXT 0x0 +#define FSL_IFC_NAND_AMASK 0xFFFF0000 +#define FSL_IFC_NAND_CSOR (IFC_CSOR_NAND_ECC_ENC_EN /* ECC on encode */ \
| IFC_CSOR_NAND_ECC_DEC_EN /* ECC on decode */ \
| IFC_CSOR_NAND_ECC_MODE_4 /* 4-bit ECC */ \
| IFC_CSOR_NAND_RAL_3 /* RAL = 3 Bytes */ \
| IFC_CSOR_NAND_PGS_2K /* Page Size = 2K */ \
| IFC_CSOR_NAND_SPRZ_64 /* Spare size = 64 */ \
| IFC_CSOR_NAND_PB(6)) /* 2^6 Pages Per Block */
+/*
- FTIM0 - NOR Flash Mode
- */
+#define FSL_IFC_FTIM0_NOR 0xF03F3F3F +#define FSL_IFC_FTIM0_NOR_TACSE_SHIFT 28 +#define FSL_IFC_FTIM0_NOR_TACSE(n) ((n) << FSL_IFC_FTIM0_NOR_TACSE_SHIFT) +#define FSL_IFC_FTIM0_NOR_TEADC_SHIFT 16 +#define FSL_IFC_FTIM0_NOR_TEADC(n) ((n) << FSL_IFC_FTIM0_NOR_TEADC_SHIFT) +#define FSL_IFC_FTIM0_NOR_TAVDS_SHIFT 8 +#define FSL_IFC_FTIM0_NOR_TAVDS(n) ((n) << FSL_IFC_FTIM0_NOR_TAVDS_SHIFT) +#define FSL_IFC_FTIM0_NOR_TEAHC_SHIFT 0 +#define FSL_IFC_FTIM0_NOR_TEAHC(n) ((n) << FSL_IFC_FTIM0_NOR_TEAHC_SHIFT) +/*
- FTIM1 - NOR Flash Mode
- */
+#define FSL_IFC_FTIM1_NOR 0xFF003F3F +#define FSL_IFC_FTIM1_NOR_TACO_SHIFT 24 +#define FSL_IFC_FTIM1_NOR_TACO(n) ((n) << FSL_IFC_FTIM1_NOR_TACO_SHIFT) +#define FSL_IFC_FTIM1_NOR_TRAD_NOR_SHIFT 8 +#define FSL_IFC_FTIM1_NOR_TRAD_NOR(n) ((n) << FSL_IFC_FTIM1_NOR_TRAD_NOR_SHIFT) +#define FSL_IFC_FTIM1_NOR_TSEQRAD_NOR_SHIFT 0 +#define FSL_IFC_FTIM1_NOR_TSEQRAD_NOR(n) ((n) << FSL_IFC_FTIM1_NOR_TSEQRAD_NOR_SHIFT) +/*
- FTIM2 - NOR Flash Mode
- */
+#define FSL_IFC_FTIM2_NOR 0x0F3CFCFF +#define FSL_IFC_FTIM2_NOR_TCS_SHIFT 24 +#define FSL_IFC_FTIM2_NOR_TCS(n) ((n) << FSL_IFC_FTIM2_NOR_TCS_SHIFT) +#define FSL_IFC_FTIM2_NOR_TCH_SHIFT 18 +#define FSL_IFC_FTIM2_NOR_TCH(n) ((n) << FSL_IFC_FTIM2_NOR_TCH_SHIFT) +#define FSL_IFC_FTIM2_NOR_TWPH_SHIFT 10 +#define FSL_IFC_FTIM2_NOR_TWPH(n) ((n) << FSL_IFC_FTIM2_NOR_TWPH_SHIFT) +#define FSL_IFC_FTIM2_NOR_TWP_SHIFT 0 +#define FSL_IFC_FTIM2_NOR_TWP(n) ((n) << FSL_IFC_FTIM2_NOR_TWP_SHIFT)
+/*
- FTIM0 - Normal GPCM Mode
- */
+#define FSL_IFC_FTIM0_GPCM 0xF03F3F3F +#define FSL_IFC_FTIM0_GPCM_TACSE_SHIFT 28 +#define FSL_IFC_FTIM0_GPCM_TACSE(n) ((n) << FSL_IFC_FTIM0_GPCM_TACSE_SHIFT) +#define FSL_IFC_FTIM0_GPCM_TEADC_SHIFT 16 +#define FSL_IFC_FTIM0_GPCM_TEADC(n) ((n) << FSL_IFC_FTIM0_GPCM_TEADC_SHIFT) +#define FSL_IFC_FTIM0_GPCM_TAVDS_SHIFT 8 +#define FSL_IFC_FTIM0_GPCM_TAVDS(n) ((n) << FSL_IFC_FTIM0_GPCM_TAVDS_SHIFT) +#define FSL_IFC_FTIM0_GPCM_TEAHC_SHIFT 0 +#define FSL_IFC_FTIM0_GPCM_TEAHC(n) ((n) << FSL_IFC_FTIM0_GPCM_TEAHC_SHIFT) +/*
- FTIM1 - Normal GPCM Mode
- */
+#define FSL_IFC_FTIM1_GPCM 0xFF003F00 +#define FSL_IFC_FTIM1_GPCM_TACO_SHIFT 24 +#define FSL_IFC_FTIM1_GPCM_TACO(n) ((n) << FSL_IFC_FTIM1_GPCM_TACO_SHIFT) +#define FSL_IFC_FTIM1_GPCM_TRAD_SHIFT 8 +#define FSL_IFC_FTIM1_GPCM_TRAD(n) ((n) << FSL_IFC_FTIM1_GPCM_TRAD_SHIFT) +/*
- FTIM2 - Normal GPCM Mode
- */
+#define FSL_IFC_FTIM2_GPCM 0x0F3C00FF +#define FSL_IFC_FTIM2_GPCM_TCS_SHIFT 24 +#define FSL_IFC_FTIM2_GPCM_TCS(n) ((n) << FSL_IFC_FTIM2_GPCM_TCS_SHIFT) +#define FSL_IFC_FTIM2_GPCM_TCH_SHIFT 18 +#define FSL_IFC_FTIM2_GPCM_TCH(n) ((n) << FSL_IFC_FTIM2_GPCM_TCH_SHIFT) +#define FSL_IFC_FTIM2_GPCM_TWP_SHIFT 0 +#define FSL_IFC_FTIM2_GPCM_TWP(n) ((n) << FSL_IFC_FTIM2_GPCM_TWP_SHIFT)
+/**
- fls - find last (most-significant) bit set
- @x: the word to search
- This is defined the same way as ffs.
- Note fls(0) = 0, fls(1) = 1, fls(0x80000000) = 32.
- */
+static inline int generic_fls(int x) +{
- int r = 32;
- if (!x)
return 0;
- if (!(x & 0xffff0000u)) {
x <<= 16;
r -= 16;
- }
- if (!(x & 0xff000000u)) {
x <<= 8;
r -= 8;
- }
- if (!(x & 0xf0000000u)) {
x <<= 4;
r -= 4;
- }
- if (!(x & 0xc0000000u)) {
x <<= 2;
r -= 2;
- }
- if (!(x & 0x80000000u)) {
x <<= 1;
r -= 1;
- }
- return r;
+}
First, and most importantly, this code (and even the header) is identical to include/asm-generic/bitops/fls.h in the Linux kernel. As part of the kernel, that code is licensed under GPLv2. This needs to go.
Fortunately, you can simply replace it with a call to HighBitSet32() from BaseLib.
+static inline int __ilog2(unsigned int x) +{
- return generic_fls(x) - 1;
+}
And should this function rather go into some helper library in EDK2? If not, just replace it with #define __ilog2(X) (HighBitSet32(X) - 1) for now.
+/*
- Address Mask Register
- */
+#define FSL_IFC_AMASK_MASK 0xFFFF0000 +#define FSL_IFC_AMASK_SHIFT 16 +#define FSL_IFC_AMASK(n) (FSL_IFC_AMASK_MASK << \
(__ilog2(n) - FSL_IFC_AMASK_SHIFT))
+#define FSL_IFC_NOR_AMASK FSL_IFC_AMASK(128*1024*1024)
SIZE_128MB?
+#define FSL_IFC_NOR_CSPR ((FSL_IFC_NOR_BUF_BASE & FSL_IFC_NOR_BUF_MASK)\
| IFC_CSPR_PORT_SIZE_16 \
| IFC_CSPR_MSEL_NOR \
| IFC_CSPR_V)
+#define FSL_IFC_NOR_CSPR_EXT 0x0 +#define FSL_IFC_NOR_CSOR (IFC_CSOR_NOR_ADM_SHIFT(4) | \
IFC_CSOR_NOR_TRHZ_80)
+#define FSL_IFC_NOR_FTIM0 (FSL_IFC_FTIM0_NOR_TACSE(0x1) | \
FSL_IFC_FTIM0_NOR_TEADC(0x1) | \
FSL_IFC_FTIM0_NOR_TAVDS(0x0) | \
FSL_IFC_FTIM0_NOR_TEAHC(0xc))
+#define FSL_IFC_NOR_FTIM1 (FSL_IFC_FTIM1_NOR_TACO(0x1c) | \
FSL_IFC_FTIM1_NOR_TRAD_NOR(0xb) |\
FSL_IFC_FTIM1_NOR_TSEQRAD_NOR(0x9))
+#define FSL_IFC_NOR_FTIM2 (FSL_IFC_FTIM2_NOR_TCS(0x1) | \
FSL_IFC_FTIM2_NOR_TCH(0x4) | \
FSL_IFC_FTIM2_NOR_TWPH(0x8) | \
FSL_IFC_FTIM2_NOR_TWP(0x10))
+#define FSL_IFC_NOR_FTIM3 0x0
+#define FSL_IFC_NOR_CSPR0 FSL_IFC_NOR_CSPR +#define FSL_IFC_NOR_AMASK0 FSL_IFC_NOR_AMASK +#define FSL_IFC_NOR_CSOR0 FSL_IFC_NOR_CSOR
+#define FSL_IFC_SRAM_BUF_SIZE 0x4000
SIZE_16KB?
+/* CPLD */
+/* Convert an address into the right format for the CSPR Registers */ +#define IFC_CSPR_PHYS_ADDR(x) (((UINTN)x) & 0xffff0000)
+#define CPLD_BASE_PHYS LS1043A_CPLD_BASE
+#define FSL_IFC_CPLD_CSPR_EXT (0x0) +#define FSL_IFC_CPLD_CSPR (IFC_CSPR_PHYS_ADDR(CPLD_BASE_PHYS) | \
IFC_CSPR_PORT_SIZE_8 | \
IFC_CSPR_MSEL_GPCM | \
IFC_CSPR_V)
+#define FSL_IFC_CPLD_AMASK FSL_IFC_AMASK(64 * 1024)
SIZE_64KB?
+#define FSL_IFC_CPLD_CSOR (IFC_CSOR_NOR_ADM_SHIFT(4) | \
IFC_CSOR_NOR_NOR_MODE_AVD_NOR | \
IFC_CSOR_NOR_TRHZ_80)
+/* CPLD Timing parameters for IFC GPCM */ +#define FSL_IFC_CPLD_FTIM0 (FSL_IFC_FTIM0_GPCM_TACSE(0xf) | \
FSL_IFC_FTIM0_GPCM_TEADC(0xf) | \
FSL_IFC_FTIM0_GPCM_TEAHC(0xf))
+#define FSL_IFC_CPLD_FTIM1 (FSL_IFC_FTIM1_GPCM_TACO(0xff) | \
FSL_IFC_FTIM1_GPCM_TRAD(0x3f))
+#define FSL_IFC_CPLD_FTIM2 (FSL_IFC_FTIM2_GPCM_TCS(0xf) | \
FSL_IFC_FTIM2_GPCM_TCH(0xf) | \
FSL_IFC_FTIM2_GPCM_TWP(0xff))
+#define FSL_IFC_CPLD_FTIM3 0x0
+typedef enum {
- FSL_IFC_CS0 = 0,
- FSL_IFC_CS1,
- FSL_IFC_CS2,
- FSL_IFC_CS3,
- FSL_IFC_CS4,
- FSL_IFC_CS5,
- FSL_IFC_CS6,
- FSL_IFC_CS7,
+} FSL_IFC_CHIP_SEL;
+typedef enum {
- FSL_IFC_FTIM0 = 0,
- FSL_IFC_FTIM1,
- FSL_IFC_FTIM2,
- FSL_IFC_FTIM3,
+} FSL_IFC_FTIMS;
+/*
- Instruction opcodes to be programmed
- in FIR registers- 6bits
- */
+enum ifc_nand_fir_opcodes {
- FSL_IFC_FIR_OP_NOP,
- FSL_IFC_FIR_OP_CA0,
- FSL_IFC_FIR_OP_CA1,
- FSL_IFC_FIR_OP_CA2,
- FSL_IFC_FIR_OP_CA3,
- FSL_IFC_FIR_OP_RA0,
- FSL_IFC_FIR_OP_RA1,
- FSL_IFC_FIR_OP_RA2,
- FSL_IFC_FIR_OP_RA3,
- FSL_IFC_FIR_OP_CMD0,
- FSL_IFC_FIR_OP_CMD1,
- FSL_IFC_FIR_OP_CMD2,
- FSL_IFC_FIR_OP_CMD3,
- FSL_IFC_FIR_OP_CMD4,
- FSL_IFC_FIR_OP_CMD5,
- FSL_IFC_FIR_OP_CMD6,
- FSL_IFC_FIR_OP_CMD7,
- FSL_IFC_FIR_OP_CW0,
- FSL_IFC_FIR_OP_CW1,
- FSL_IFC_FIR_OP_CW2,
- FSL_IFC_FIR_OP_CW3,
- FSL_IFC_FIR_OP_CW4,
- FSL_IFC_FIR_OP_CW5,
- FSL_IFC_FIR_OP_CW6,
- FSL_IFC_FIR_OP_CW7,
- FSL_IFC_FIR_OP_WBCD,
- FSL_IFC_FIR_OP_RBCD,
- FSL_IFC_FIR_OP_BTRD,
- FSL_IFC_FIR_OP_RDSTAT,
- FSL_IFC_FIR_OP_NWAIT,
- FSL_IFC_FIR_OP_WFR,
- FSL_IFC_FIR_OP_SBRD,
- FSL_IFC_FIR_OP_UA,
- FSL_IFC_FIR_OP_RB,
+};
+typedef struct {
- UINT32 cspr_ext;
- UINT32 cspr;
- UINT32 res;
+} FSL_IFC_CSPR;
+typedef struct {
- UINT32 amask;
- UINT32 res[0x2];
I don't think the coding style bans it, but hexadecimal array size specifiers are a bit unusual - is there a particular reason for them?
+} FSL_IFC_AMASK;
+typedef struct {
- UINT32 csor;
- UINT32 csor_ext;
- UINT32 res;
+} FSL_IFC_CSOR;
+typedef struct {
- UINT32 ftim[4];
- UINT32 res[0x8];
+}FSL_IFC_FTIM ;
+typedef struct {
- UINT32 ncfgr;
- UINT32 res1[0x4];
- UINT32 nand_fcr0;
- UINT32 nand_fcr1;
- UINT32 res2[0x8];
- UINT32 row0;
- UINT32 res3;
- UINT32 col0;
- UINT32 res4;
- UINT32 row1;
- UINT32 res5;
- UINT32 col1;
- UINT32 res6;
- UINT32 row2;
- UINT32 res7;
- UINT32 col2;
- UINT32 res8;
- UINT32 row3;
- UINT32 res9;
- UINT32 col3;
- UINT32 res10[0x24];
- UINT32 nand_fbcr;
- UINT32 res11;
- UINT32 nand_fir0;
- UINT32 nand_fir1;
- UINT32 nand_fir2;
- UINT32 res12[0x10];
- UINT32 nand_csel;
- UINT32 res13;
- UINT32 nandseq_strt;
- UINT32 res14;
- UINT32 nand_evter_stat;
- UINT32 res15;
- UINT32 pgrdcmpl_evt_stat;
- UINT32 res16[0x2];
- UINT32 nand_evter_en;
- UINT32 res17[0x2];
- UINT32 nand_evter_intr_en;
- UINT32 res18[0x2];
- UINT32 nand_erattr0;
- UINT32 nand_erattr1;
- UINT32 res19[0x10];
- UINT32 nand_fsr;
- UINT32 res20;
- UINT32 nand_eccstat[4];
- UINT32 res21[0x20];
- UINT32 nanndcr;
- UINT32 res22[0x2];
- UINT32 nand_autoboot_trgr;
- UINT32 res23;
- UINT32 nand_mdr;
- UINT32 res24[0x5C];
+} FSL_IFC_NAND;
+/*
- IFC controller NOR Machine registers
- */
+typedef struct {
- UINT32 nor_evter_stat;
- UINT32 res1[0x2];
- UINT32 nor_evter_en;
- UINT32 res2[0x2];
- UINT32 nor_evter_intr_en;
- UINT32 res3[0x2];
- UINT32 nor_erattr0;
- UINT32 nor_erattr1;
- UINT32 nor_erattr2;
- UINT32 res4[0x4];
- UINT32 norcr;
- UINT32 res5[0xEF];
+} FSL_IFC_NOR;
+/*
- IFC controller GPCM Machine registers
- */
+typedef struct {
- UINT32 gpcm_evter_stat;
- UINT32 res1[0x2];
- UINT32 gpcm_evter_en;
- UINT32 res2[0x2];
- UINT32 gpcm_evter_intr_en;
- UINT32 res3[0x2];
- UINT32 gpcm_erattr0;
- UINT32 gpcm_erattr1;
- UINT32 gpcm_erattr2;
- UINT32 gpcm_stat;
+} FSL_IFC_GPCM;
+/*
- IFC Controller Registers
- */
+typedef struct {
- UINT32 ifc_rev;
- UINT32 res1[0x2];
- FSL_IFC_CSPR cspr_cs[FSL_IFC_BANK_COUNT];
- UINT8 res2[FSL_IFC_CSPR_REG_LEN - FSL_IFC_CSPR_USED_LEN];
- FSL_IFC_AMASK amask_cs[FSL_IFC_BANK_COUNT];
- UINT8 res3[FSL_IFC_AMASK_REG_LEN - FSL_IFC_AMASK_USED_LEN];
- FSL_IFC_CSOR csor_cs[FSL_IFC_BANK_COUNT];
- UINT8 res4[FSL_IFC_CSOR_REG_LEN - FSL_IFC_CSOR_USED_LEN];
- FSL_IFC_FTIM ftim_cs[FSL_IFC_BANK_COUNT];
- UINT8 res5[FSL_IFC_FTIM_REG_LEN - FSL_IFC_FTIM_USED_LEN];
- UINT32 rb_stat;
- UINT32 rb_map;
- UINT32 wp_map;
- UINT32 ifc_gcr;
- UINT32 res7[0x2];
- UINT32 cm_evter_stat;
- UINT32 res8[0x2];
- UINT32 cm_evter_en;
- UINT32 res9[0x2];
- UINT32 cm_evter_intr_en;
- UINT32 res10[0x2];
- UINT32 cm_erattr0;
- UINT32 cm_erattr1;
- UINT32 res11[0x2];
- UINT32 ifc_ccr;
- UINT32 ifc_csr;
- UINT32 ddr_ccr_low;
- UINT32 res12[0x2EA];
- FSL_IFC_NAND ifc_nand;
- FSL_IFC_NOR ifc_nor;
- FSL_IFC_GPCM ifc_gpcm;
+} FSL_IFC_REGS;
+VOID IfcNorInit(VOID);
+VOID IfcNandInit(VOID);
+#define FSL_IFC_REGS_BASE \
- ((FSL_IFC_REGS *)FSL_IFC_REG_BASE)
+#endif //__FLASH_H__ diff --git a/Platforms/Nxp/LS1043aRdb/Library/CpldLib/CpldLib.c b/Platforms/Nxp/LS1043aRdb/Library/CpldLib/CpldLib.c new file mode 100644 index 0000000..fe115c8 --- /dev/null +++ b/Platforms/Nxp/LS1043aRdb/Library/CpldLib/CpldLib.c @@ -0,0 +1,157 @@ +/** @CpldLib.c
- Cpld specific Library for LS1043A-RDB board, containing functions to
- program and read the Cpld registers.
- Copyright (c) 2016, Freescale Semiconductor, Inc. All rights reserved.
- This program and the accompanying materials
- are licensed and made available under the terms and conditions of the BSD License
- which accompanies this distribution. The full text of the license may be found at
- http://opensource.org/licenses/bsd-license.php
- THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
- WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
+**/
+#include <Base.h> +#include <PiPei.h> +#include <Uefi.h>
+#include <Library/BaseLib.h> +#include <Library/DebugLib.h> +#include <Library/IoLib.h> +#include <Library/PrintLib.h> +#include <Library/SerialPortLib.h>
+#include <Library/PlatformLib.h> +#include <Library/CpldLib.h> +#include <Library/FslIfc.h>
Please sort the additions into the first block.
+UINT8 +CpldRead (
- OUT UINTN Reg
- )
+{
- VOID *Base = (VOID *)LS1043A_CPLD_BASE;
- return MmioRead8((UINTN)(Base + Reg));
Why not just return MmioRead8(LS1043A_CPLD_BASE + Reg); ?
+}
+VOID +CpldWrite (
- IN UINTN Reg,
- IN UINT8 Value
- )
+{
- VOID *Base = (VOID *)LS1043A_CPLD_BASE;
- MmioWrite8((UINTN)(Base + Reg), Value);
And similarly here.
+}
+/* Set the boot bank to the alternate bank */ +VOID +CpldSetAlternatebank (
- VOID
- )
+{
- UINT8 Reg4 = CPLD_READ(SoftMuxOn);
- UINT8 Reg7 = CPLD_READ(Vbank);
- CPLD_WRITE(SoftMuxOn, Reg4 | CPLD_SW_MUX_BANK_SEL);
- Reg7 = (Reg7 & ~CPLD_BANK_SEL_MASK) | CPLD_BANK_SEL_ALTBANK;
- CPLD_WRITE(Vbank, Reg7);
- CPLD_WRITE(SystemReset, 1);
I would prefer a define instead of that 1.
+}
+/* Set the boot bank to the default bank */ +VOID +CpldSetDefaultBank (
- VOID
- )
+{
- CPLD_WRITE(GlobalReset, 1);
I would prefer a define instead of that 1.
+}
+VOID +CpldDumpRegs (
- VOID
- )
+{
- DEBUG((EFI_D_INFO, "CpldVersionMajor = %x\n", CPLD_READ(CpldVersionMajor)));
- DEBUG((EFI_D_INFO, "CpldVersionMinor = %x\n", CPLD_READ(CpldVersionMinor)));
- DEBUG((EFI_D_INFO, "PcbaVersion = %x\n", CPLD_READ(PcbaVersion)));
- DEBUG((EFI_D_INFO, "SoftMuxOn = %x\n", CPLD_READ(SoftMuxOn)));
- DEBUG((EFI_D_INFO, "RcwSource1 = %x\n", CPLD_READ(RcwSource1)));
- DEBUG((EFI_D_INFO, "RcwSource2 = %x\n", CPLD_READ(RcwSource2)));
- DEBUG((EFI_D_INFO, "Vbank = %x\n", CPLD_READ(Vbank)));
- DEBUG((EFI_D_INFO, "SysclkSelect = %x\n", CPLD_READ(SysclkSelect)));
- DEBUG((EFI_D_INFO, "UartSel = %x\n", CPLD_READ(UartSel)));
- DEBUG((EFI_D_INFO, "Sd1RefClkSel = %x\n", CPLD_READ(Sd1RefClkSel)));
- DEBUG((EFI_D_INFO, "TdmClkMuxSel = %x\n", CPLD_READ(TdmClkMuxSel)));
- DEBUG((EFI_D_INFO, "SdhcSpiCsSel = %x\n", CPLD_READ(SdhcSpiCsSel)));
- DEBUG((EFI_D_INFO, "StatusLed = %x\n", CPLD_READ(StatusLed)));
+}
+VOID +CpldRevBit (
Again, this is something that could go into a core library. Perhaps as a BitFieldRev8 in BaseLib?
- OUT UINT8 *Value
- )
+{
- UINT8 Rev, Val;
- UINTN Index;
- Val = *Value;
- Rev = Val & 1;
- for (Index = 1; Index <= 7; Index++) {
Val >>= 1;
Rev <<= 1;
Rev |= Val & 1;
- }
- *Value = Rev;
+}
+VOID +DoCpld (
To keep to the namespace, could this function be renamed CpldAction (or similar)?
- IN CpldCmd Cmd
- )
+{
- switch (Cmd) {
- case RESET:
CpldSetDefaultBank();
break;
- case RESET_ALTBANK:
CpldSetAlternatebank();
break;
- case DUMP_REGISTERS:
CpldDumpRegs();
break;
- default:
DEBUG((EFI_D_ERROR, "Error: Unknown Cpld Command!\n"));
break;
- }
+}
+VOID +CpldInit (
- VOID
- )
+{
Could we have some comments on what the below does?
- MmioWriteBe32((UINTN) &(FSL_IFC_REGS_BASE)->cspr_cs[FSL_IFC_CS2].cspr_ext, FSL_IFC_CPLD_CSPR_EXT);
- MmioWriteBe32((UINTN) &(FSL_IFC_REGS_BASE)->ftim_cs[FSL_IFC_CS2].ftim[FSL_IFC_FTIM0],
FSL_IFC_CPLD_FTIM0);
- MmioWriteBe32((UINTN) &(FSL_IFC_REGS_BASE)->ftim_cs[FSL_IFC_CS2].ftim[FSL_IFC_FTIM1],
FSL_IFC_CPLD_FTIM1);
- MmioWriteBe32((UINTN) &(FSL_IFC_REGS_BASE)->ftim_cs[FSL_IFC_CS2].ftim[FSL_IFC_FTIM2],
FSL_IFC_CPLD_FTIM2);
- MmioWriteBe32((UINTN) &(FSL_IFC_REGS_BASE)->ftim_cs[FSL_IFC_CS2].ftim[FSL_IFC_FTIM3],
FSL_IFC_CPLD_FTIM3);
- MmioWriteBe32((UINTN) &(FSL_IFC_REGS_BASE)->csor_cs[FSL_IFC_CS2].csor, FSL_IFC_CPLD_CSOR);
- MmioWriteBe32((UINTN) &(FSL_IFC_REGS_BASE)->amask_cs[FSL_IFC_CS2].amask, FSL_IFC_CPLD_AMASK);
- MmioWriteBe32((UINTN) &(FSL_IFC_REGS_BASE)->cspr_cs[FSL_IFC_CS2].cspr, FSL_IFC_CPLD_CSPR);
+} diff --git a/Platforms/Nxp/LS1043aRdb/Library/CpldLib/CpldLib.inf b/Platforms/Nxp/LS1043aRdb/Library/CpldLib/CpldLib.inf new file mode 100644 index 0000000..f37d153 --- /dev/null +++ b/Platforms/Nxp/LS1043aRdb/Library/CpldLib/CpldLib.inf @@ -0,0 +1,33 @@ +#/* @CpldLib.inf +# Copyright (c) 2016, Freescale Semiconductor, Inc. All rights reserved. +# +# This program and the accompanying materials +# are licensed and made available under the terms and conditions of the BSD License +# which accompanies this distribution. The full text of the license may be found at +# http://opensource.org/licenses/bsd-license.php +# +# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, +# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. +# +#*/
+[Defines]
- INF_VERSION = 0x00010005
- BASE_NAME = CpldLib
To distinguish from the LIBRARY_CLASS, and to be more clear on how this is a hardware-specific library, could we call it LS1043CpldLib?
- FILE_GUID = 5962d040-8b8a-11df-9a71-0002a5d5c51b
- MODULE_TYPE = BASE
- VERSION_STRING = 1.0
- LIBRARY_CLASS = CpldLib
+[Sources.common]
- CpldLib.c
+[Packages]
- MdePkg/MdePkg.dec
- ArmPkg/ArmPkg.dec
- ArmPlatformPkg/ArmPlatformPkg.dec
- OpenPlatformPkg/Platforms/Nxp/LS1043aRdb/LS1043aRdbPkg.dec
Could these be sorted please?
+[LibraryClasses]
- BaseLib
- IoLib
-- 1.9.1
From: Sakar Arora sakar.arora@nxp.com
There are several early SoC/Board level initialization functions which need to be performed before the DXE phase can execute.
While some of these are more related to how the boot information looks on the console, others are related to setting up SoC/board components/mux'es in a way that a particular component can be used.
This patch adds the support for the same.
Signed-off-by: Sakar Arora sakar.arora@nxp.com Signed-off-by: Bhupesh Sharma bhupesh.sharma@nxp.com --- Platforms/Nxp/LS1043aRdb/Include/Library/SocLib.h | 308 +++++++++++++++++++++ .../Library/LS1043aSocLib/LS1043aSocLib.c | 140 ++++++++++ .../Library/LS1043aSocLib/LS1043aSocLib.inf | 40 +++ 3 files changed, 488 insertions(+) create mode 100644 Platforms/Nxp/LS1043aRdb/Include/Library/SocLib.h create mode 100644 Platforms/Nxp/LS1043aRdb/Library/LS1043aSocLib/LS1043aSocLib.c create mode 100644 Platforms/Nxp/LS1043aRdb/Library/LS1043aSocLib/LS1043aSocLib.inf
diff --git a/Platforms/Nxp/LS1043aRdb/Include/Library/SocLib.h b/Platforms/Nxp/LS1043aRdb/Include/Library/SocLib.h new file mode 100644 index 0000000..d1655d5 --- /dev/null +++ b/Platforms/Nxp/LS1043aRdb/Include/Library/SocLib.h @@ -0,0 +1,308 @@ +/** SoCLib.h +* Header defining the LS1043a SoC specific constants (Base addresses, sizes, flags) +* +* Copyright (c) 2016, Freescale Semiconductor, Inc. All rights reserved. +* +* This program and the accompanying materials +* are licensed and made available under the terms and conditions of the BSD License +* which accompanies this distribution. The full text of the license may be found at +* http://opensource.org/licenses/bsd-license.php +* +* THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, +* WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. +* +**/ + +#ifndef __LS1043A_SOC_H__ +#define __LS1043A_SOC_H__ + +#define LS1043A_NUM_CC_PLLS 2 +#define HWA_CGA_M1_CLK_SEL 0xe0000000 +#define HWA_CGA_M1_CLK_SHIFT 29 +#define HWA_CGA_M2_CLK_SEL 0x00000007 +#define HWA_CGA_M2_CLK_SHIFT 0 + +#define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0])) + +#define LS1043A_CLK_FREQ 100000000 +#define LS1043A_DDR_CLK_FREQ 100000000 + +#define LS1043A_MAX_CPUS 4 +#define LS1043A_NUM_FMAN 1 + + +struct SysInfo { + UINTN FreqProcessor[LS1043A_MAX_CPUS]; + UINTN FreqSystemBus; + UINTN FreqDdrBus; + UINTN FreqLocalBus; + UINTN FreqSdhc; + UINTN FreqFman[LS1043A_NUM_FMAN]; + UINTN FreqQman; +}; + +/* Device Configuration and Pin Control */ +struct CcsrGur { + UINT32 porsr1; /* POR status 1 */ + UINT32 porsr2; /* POR status 2 */ + UINT8 res_008[0x20-0x8]; + UINT32 gpporcr1; /* General-purpose POR configuration */ + UINT32 gpporcr2; + UINT32 dcfg_fusesr; /* Fuse status register */ + UINT8 res_02c[0x70-0x2c]; + UINT32 devdisr; /* Device disable control */ + UINT32 devdisr2; /* Device disable control 2 */ + UINT32 devdisr3; /* Device disable control 3 */ + UINT32 devdisr4; /* Device disable control 4 */ + UINT32 devdisr5; /* Device disable control 5 */ + UINT32 devdisr6; /* Device disable control 6 */ + UINT32 devdisr7; /* Device disable control 7 */ + UINT8 res_08c[0x94-0x8c]; + UINT32 coredisru; /* uppper portion for support of 64 cores */ + UINT32 coredisrl; /* lower portion for support of 64 cores */ + UINT8 res_09c[0xa0-0x9c]; + UINT32 pvr; /* Processor version */ + UINT32 svr; /* System version */ + UINT32 mvr; /* Manufacturing version */ + UINT8 res_0ac[0xb0-0xac]; + UINT32 rstcr; /* Reset control */ + UINT32 rstrqpblsr; /* Reset request preboot loader status */ + UINT8 res_0b8[0xc0-0xb8]; + UINT32 rstrqmr1; /* Reset request mask */ + UINT8 res_0c4[0xc8-0xc4]; + UINT32 rstrqsr1; /* Reset request status */ + UINT8 res_0cc[0xd4-0xcc]; + UINT32 rstrqwdtmrl; /* Reset request WDT mask */ + UINT8 res_0d8[0xdc-0xd8]; + UINT32 rstrqwdtsrl; /* Reset request WDT status */ + UINT8 res_0e0[0xe4-0xe0]; + UINT32 brrl; /* Boot release */ + UINT8 res_0e8[0x100-0xe8]; + UINT32 rcwsr[16]; /* Reset control word status */ +#define FSL_CHASSIS2_RCWSR0_SYS_PLL_RAT_SHIFT 25 +#define FSL_CHASSIS2_RCWSR0_SYS_PLL_RAT_MASK 0x1f +#define FSL_CHASSIS2_RCWSR0_MEM_PLL_RAT_SHIFT 16 +#define FSL_CHASSIS2_RCWSR0_MEM_PLL_RAT_MASK 0x3f + UINT8 res_140[0x200-0x140]; + UINT32 scratchrw[4]; /* Scratch Read/Write */ + UINT8 res_210[0x300-0x210]; + UINT32 scratchw1r[4]; /* Scratch Read (Write once) */ + UINT8 res_310[0x400-0x310]; + UINT32 crstsr[12]; + UINT8 res_430[0x500-0x430]; + + /* PCI Express n Logical I/O Device Number register */ + UINT32 dcfg_ccsr_pex1liodnr; + UINT32 dcfg_ccsr_pex2liodnr; + UINT32 dcfg_ccsr_pex3liodnr; + UINT32 dcfg_ccsr_pex4liodnr; + /* RIO n Logical I/O Device Number register */ + UINT32 dcfg_ccsr_rio1liodnr; + UINT32 dcfg_ccsr_rio2liodnr; + UINT32 dcfg_ccsr_rio3liodnr; + UINT32 dcfg_ccsr_rio4liodnr; + /* USB Logical I/O Device Number register */ + UINT32 dcfg_ccsr_usb1liodnr; + UINT32 dcfg_ccsr_usb2liodnr; + UINT32 dcfg_ccsr_usb3liodnr; + UINT32 dcfg_ccsr_usb4liodnr; + /* SD/MMC Logical I/O Device Number register */ + UINT32 dcfg_ccsr_sdmmc1liodnr; + UINT32 dcfg_ccsr_sdmmc2liodnr; + UINT32 dcfg_ccsr_sdmmc3liodnr; + UINT32 dcfg_ccsr_sdmmc4liodnr; + /* RIO Message Unit Logical I/O Device Number register */ + UINT32 dcfg_ccsr_riomaintliodnr; + + UINT8 res_544[0x550-0x544]; + UINT32 sataliodnr[4]; + UINT8 res_560[0x570-0x560]; + + UINT32 dcfg_ccsr_misc1liodnr; + UINT32 dcfg_ccsr_misc2liodnr; + UINT32 dcfg_ccsr_misc3liodnr; + UINT32 dcfg_ccsr_misc4liodnr; + UINT32 dcfg_ccsr_dma1liodnr; + UINT32 dcfg_ccsr_dma2liodnr; + UINT32 dcfg_ccsr_dma3liodnr; + UINT32 dcfg_ccsr_dma4liodnr; + UINT32 dcfg_ccsr_spare1liodnr; + UINT32 dcfg_ccsr_spare2liodnr; + UINT32 dcfg_ccsr_spare3liodnr; + UINT32 dcfg_ccsr_spare4liodnr; + UINT8 res_5a0[0x600-0x5a0]; + UINT32 dcfg_ccsr_pblsr; + + UINT32 pamubypenr; + UINT32 dmacr1; + + UINT8 res_60c[0x610-0x60c]; + UINT32 dcfg_ccsr_gensr1; + UINT32 dcfg_ccsr_gensr2; + UINT32 dcfg_ccsr_gensr3; + UINT32 dcfg_ccsr_gensr4; + UINT32 dcfg_ccsr_gencr1; + UINT32 dcfg_ccsr_gencr2; + UINT32 dcfg_ccsr_gencr3; + UINT32 dcfg_ccsr_gencr4; + UINT32 dcfg_ccsr_gencr5; + UINT32 dcfg_ccsr_gencr6; + UINT32 dcfg_ccsr_gencr7; + UINT8 res_63c[0x658-0x63c]; + UINT32 dcfg_ccsr_cgensr1; + UINT32 dcfg_ccsr_cgensr0; + UINT8 res_660[0x678-0x660]; + UINT32 dcfg_ccsr_cgencr1; + + UINT32 dcfg_ccsr_cgencr0; + UINT8 res_680[0x700-0x680]; + UINT32 dcfg_ccsr_sriopstecr; + UINT32 dcfg_ccsr_dcsrcr; + + UINT8 res_708[0x740-0x708]; /* add more registers when needed */ + UINT32 tp_ityp[64]; /* Topology Initiator Type Register */ + struct { + UINT32 upper; + UINT32 lower; + } tp_cluster[16]; + UINT8 res_8c0[0xa00-0x8c0]; /* add more registers when needed */ + UINT32 dcfg_ccsr_qmbm_warmrst; + UINT8 res_a04[0xa20-0xa04]; /* add more registers when needed */ + UINT32 dcfg_ccsr_reserved0; + UINT32 dcfg_ccsr_reserved1; +}; + +/* Supplemental Configuration Unit */ +struct CcsrScfg { + UINT8 res_000[0x100-0x000]; + UINT32 usb2_icid; + UINT32 usb3_icid; + UINT8 res_108[0x114-0x108]; + UINT32 dma_icid; + UINT32 sata_icid; + UINT32 usb1_icid; + UINT32 qe_icid; + UINT32 sdhc_icid; + UINT32 edma_icid; + UINT32 etr_icid; + UINT32 core0_sft_rst; + UINT32 core1_sft_rst; + UINT32 core2_sft_rst; + UINT32 core3_sft_rst; + UINT8 res_140[0x158-0x140]; + UINT32 altcbar; + UINT32 qspi_cfg; + UINT8 res_160[0x180-0x160]; + UINT32 dmamcr; + UINT8 res_184[0x18c-0x184]; + UINT32 debug_icid; + UINT8 res_190[0x1a4-0x190]; + UINT32 snpcnfgcr; + UINT8 res_1a8[0x1ac-0x1a8]; + UINT32 intpcr; + UINT8 res_1b0[0x204-0x1b0]; + UINT32 coresrencr; + UINT8 res_208[0x220-0x208]; + UINT32 rvbar0_0; + UINT32 rvbar0_1; + UINT32 rvbar1_0; + UINT32 rvbar1_1; + UINT32 rvbar2_0; + UINT32 rvbar2_1; + UINT32 rvbar3_0; + UINT32 rvbar3_1; + UINT32 lpmcsr; + UINT8 res_244[0x400-0x244]; + UINT32 qspidqscr; + UINT32 ecgtxcmcr; + UINT32 sdhciovselcr; + UINT32 rcwpmuxcr0; + UINT32 usbdrvvbus_selcr; + UINT32 usbpwrfault_selcr; + UINT32 usb_refclk_selcr1; + UINT32 usb_refclk_selcr2; + UINT32 usb_refclk_selcr3; + UINT8 res_424[0x600-0x424]; + UINT32 scratchrw[4]; + UINT8 res_610[0x680-0x610]; + UINT32 corebcr; + UINT8 res_684[0x1000-0x684]; + UINT32 pex1msiir; + UINT32 pex1msir; + UINT8 res_1008[0x2000-0x1008]; + UINT32 pex2; + UINT32 pex2msir; + UINT8 res_2008[0x3000-0x2008]; + UINT32 pex3msiir; + UINT32 pex3msir; +}; + +/* Clocking */ +struct CcsrClk { + struct { + UINT32 clkcncsr; /* core cluster n clock control status */ + UINT8 res_004[0x0c]; + UINT32 clkcghwacsr; /* Clock generator n hardware accelerator */ + UINT8 res_014[0x0c]; + } clkcsr[4]; + UINT8 res_040[0x780]; /* 0x100 */ + struct { + UINT32 pllcngsr; + UINT8 res_804[0x1c]; + } pllcgsr[2]; + UINT8 res_840[0x1c0]; + UINT32 clkpcsr; /* 0xa00 Platform clock domain control/status */ + UINT8 res_a04[0x1fc]; + UINT32 pllpgsr; /* 0xc00 Platform PLL General Status */ + UINT8 res_c04[0x1c]; + UINT32 plldgsr; /* 0xc20 DDR PLL General Status */ + UINT8 res_c24[0x3dc]; +}; + +/* CCI-400 registers */ +struct CcsrCci400 { + UINT32 ctrl_ord; /* Control Override */ + UINT32 spec_ctrl; /* Speculation Control */ + UINT32 secure_access; /* Secure Access */ + UINT32 status; /* Status */ + UINT32 impr_err; /* Imprecise Error */ + UINT8 res_14[0x100 - 0x14]; + UINT32 pmcr; /* Performance Monitor Control */ + UINT8 res_104[0xfd0 - 0x104]; + UINT32 pid[8]; /* Peripheral ID */ + UINT32 cid[4]; /* Component ID */ + struct { + UINT32 snoop_ctrl; /* Snoop Control */ + UINT32 sha_ord; /* Shareable Override */ + UINT8 res_1008[0x1100 - 0x1008]; + UINT32 rc_qos_ord; /* read channel QoS Value Override */ + UINT32 wc_qos_ord; /* read channel QoS Value Override */ + UINT8 res_1108[0x110c - 0x1108]; + UINT32 qos_ctrl; /* QoS Control */ + UINT32 max_ot; /* Max OT */ + UINT8 res_1114[0x1130 - 0x1114]; + UINT32 target_lat; /* Target Latency */ + UINT32 latency_regu; /* Latency Regulation */ + UINT32 qos_range; /* QoS Range */ + UINT8 res_113c[0x2000 - 0x113c]; + } slave[5]; /* Slave Interface */ + UINT8 res_6000[0x9004 - 0x6000]; + UINT32 cycle_counter; /* Cycle counter */ + UINT32 count_ctrl; /* Count Control */ + UINT32 overflow_status; /* Overflow Flag Status */ + UINT8 res_9010[0xa000 - 0x9010]; + struct { + UINT32 event_select; /* Event Select */ + UINT32 event_count; /* Event Count */ + UINT32 counter_ctrl; /* Counter Control */ + UINT32 overflow_status; /* Overflow Flag Status */ + UINT8 res_a010[0xb000 - 0xa010]; + } pcounter[4]; /* Performance Counter */ + UINT8 res_e004[0x10000 - 0xe004]; +}; + +UINT32 CalculateBaudDivisor(OUT UINT64 *BaudRate); +UINT32 CalculateI2cClockRate(VOID); + + +#endif /* __LS1043A_SOC_H__ */ diff --git a/Platforms/Nxp/LS1043aRdb/Library/LS1043aSocLib/LS1043aSocLib.c b/Platforms/Nxp/LS1043aRdb/Library/LS1043aSocLib/LS1043aSocLib.c new file mode 100644 index 0000000..fdeae08 --- /dev/null +++ b/Platforms/Nxp/LS1043aRdb/Library/LS1043aSocLib/LS1043aSocLib.c @@ -0,0 +1,140 @@ +/** @SoCLib.c + SoC specific Library for LS1043A SoC, containing functions to initialize various SoC components + + Copyright (c) 2016, Freescale Semiconductor, Inc. All rights reserved. + + This program and the accompanying materials + are licensed and made available under the terms and conditions of the BSD License + which accompanies this distribution. The full text of the license may be found at + http://opensource.org/licenses/bsd-license.php + + THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, + WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. + +**/ + +#include <Base.h> +#include <PiPei.h> +#include <Uefi.h> +#include <Library/BaseLib.h> +#include <Library/MemoryAllocationLib.h> +#include <Library/BaseMemoryLib/MemLibInternals.h> + +#include <Library/PrePiLib.h> +#include <Library/PcdLib.h> +#include <Library/DebugLib.h> +#include <Library/DebugAgentLib.h> +#include <Library/IoLib.h> +#include <Library/PrintLib.h> + + +#include <Library/PlatformLib.h> +#include <Library/SocLib.h> +#include <Library/CpldLib.h> + + +VOID +GetSysInfo ( + OUT struct SysInfo *PtrSysInfo + ) +{ + struct CcsrGur *GurBase = (void *)(LS1043A_FSL_GUTS_ADDR); + struct CcsrClk *ClkBase = (void *)(LS1043A_FSL_CLK_ADDR); + UINTN CpuIndex; + UINT32 TempRcw; + const UINT8 CoreCplxPll[8] = { + [0] = 0, /* CC1 PPL / 1 */ + [1] = 0, /* CC1 PPL / 2 */ + [4] = 1, /* CC2 PPL / 1 */ + [5] = 1, /* CC2 PPL / 2 */ + }; + + const UINT8 CoreCplxPllDivisor[8] = { + [0] = 1, /* CC1 PPL / 1 */ + [1] = 2, /* CC1 PPL / 2 */ + [4] = 1, /* CC2 PPL / 1 */ + [5] = 2, /* CC2 PPL / 2 */ + }; + + UINTN PllCount; + UINTN FreqCPll[LS1043A_FSL_NUM_CC_PLLS]; + UINTN PllRatio[LS1043A_FSL_NUM_CC_PLLS]; + UINTN SysClk = LS1043A_CLK_FREQ; + + PtrSysInfo->FreqSystemBus = SysClk; + PtrSysInfo->FreqDdrBus = SysClk; + + PtrSysInfo->FreqSystemBus *= (MmioReadBe32((UINTN)&GurBase->rcwsr[0]) >> + FSL_CHASSIS2_RCWSR0_SYS_PLL_RAT_SHIFT) & + FSL_CHASSIS2_RCWSR0_SYS_PLL_RAT_MASK; + PtrSysInfo->FreqDdrBus *= (MmioReadBe32((UINTN)&GurBase->rcwsr[0]) >> + FSL_CHASSIS2_RCWSR0_MEM_PLL_RAT_SHIFT) & + FSL_CHASSIS2_RCWSR0_MEM_PLL_RAT_MASK; + + for (PllCount = 0; PllCount < LS1043A_FSL_NUM_CC_PLLS; PllCount++) { + PllRatio[PllCount] = (MmioReadBe32((UINTN)&ClkBase->pllcgsr[PllCount].pllcngsr) >> 1) & 0xff; + if (PllRatio[PllCount] > 4) + FreqCPll[PllCount] = SysClk * PllRatio[PllCount]; + else + FreqCPll[PllCount] = PtrSysInfo->FreqSystemBus * PllRatio[PllCount]; + } + + for (CpuIndex = 0; CpuIndex < LS1043A_MAX_CPUS; CpuIndex++) { + UINT32 c_pll_sel = (MmioReadBe32((UINTN)&ClkBase->clkcsr[CpuIndex].clkcncsr) >> 27) + & 0xf; + UINT32 cplx_pll = CoreCplxPll[c_pll_sel]; + + PtrSysInfo->FreqProcessor[CpuIndex] = + FreqCPll[cplx_pll] / CoreCplxPllDivisor[c_pll_sel]; + } + + TempRcw = MmioReadBe32((UINTN)&GurBase->rcwsr[7]); + switch ((TempRcw & HWA_CGA_M1_CLK_SEL) >> HWA_CGA_M1_CLK_SHIFT) { + case 2: + PtrSysInfo->FreqFman[0] = FreqCPll[0] / 2; + break; + case 3: + PtrSysInfo->FreqFman[0] = FreqCPll[1] / 3; + break; + case 6: + PtrSysInfo->FreqFman[0] = FreqCPll[0] / 2; + break; + case 7: + PtrSysInfo->FreqFman[0] = FreqCPll[1] / 3; + break; + default: + DEBUG((EFI_D_WARN, "Error: Unknown FMan1 clock select!\n")); + break; + } + TempRcw = MmioReadBe32((UINTN)&GurBase->rcwsr[15]); + TempRcw = (TempRcw & HWA_CGA_M2_CLK_SEL) >> HWA_CGA_M2_CLK_SHIFT; + PtrSysInfo->FreqSdhc = FreqCPll[1] / TempRcw; + PtrSysInfo->FreqQman = PtrSysInfo->FreqSystemBus / 2; +} + + +UINT32 +CalculateBaudDivisor ( + OUT UINT64 *BaudRate + ) +{ + struct SysInfo SocSysInfo; + UINTN DUartClk; + + GetSysInfo(&SocSysInfo); + DUartClk = SocSysInfo.FreqSystemBus; + + return ((DUartClk)/(*BaudRate * 16)); +} + +UINT32 +CalculateI2cClockRate( + VOID + ) +{ + struct SysInfo SocSysInfo; + + GetSysInfo(&SocSysInfo); + return SocSysInfo.FreqSystemBus; + +} diff --git a/Platforms/Nxp/LS1043aRdb/Library/LS1043aSocLib/LS1043aSocLib.inf b/Platforms/Nxp/LS1043aRdb/Library/LS1043aSocLib/LS1043aSocLib.inf new file mode 100644 index 0000000..322fe34 --- /dev/null +++ b/Platforms/Nxp/LS1043aRdb/Library/LS1043aSocLib/LS1043aSocLib.inf @@ -0,0 +1,40 @@ +#/* @SoCLib.inf +# Copyright (c) 2016, Freescale Semiconductor, Inc. All rights reserved. +# +# This program and the accompanying materials +# are licensed and made available under the terms and conditions of the BSD License +# which accompanies this distribution. The full text of the license may be found at +# http://opensource.org/licenses/bsd-license.php +# +# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, +# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. +# +#*/ + +[Defines] + INF_VERSION = 0x00010005 + BASE_NAME = LS1043aSocLib + FILE_GUID = 736343a0-1d96-11e0-aaaa-0002a5d5c51b + MODULE_TYPE = BASE + VERSION_STRING = 1.0 + LIBRARY_CLASS = SocLib + +[Packages] + MdePkg/MdePkg.dec + MdeModulePkg/MdeModulePkg.dec + EmbeddedPkg/EmbeddedPkg.dec + ArmPkg/ArmPkg.dec + ArmPlatformPkg/ArmPlatformPkg.dec + OpenPlatformPkg/Platforms/Nxp/LS1043aRdb/LS1043aRdbPkg.dec + OpenPlatformPkg/Chips/Nxp/QoriqLs/NxpQoriqLs.dec + +[LibraryClasses] + BaseLib + CpldLib + DebugLib + DebugAgentLib + IoLib + ArmLib + +[Sources.common] + LS1043aSocLib.c
On 17 October 2016 at 21:04, Bhupesh Sharma bhupesh.sharma@freescale.com wrote:
From: Sakar Arora sakar.arora@nxp.com
There are several early SoC/Board level initialization functions which need to be performed before the DXE phase can execute.
While some of these are more related to how the boot information looks on the console, others are related to setting up SoC/board components/mux'es in a way that a particular component can be used.
This patch adds the support for the same.
Signed-off-by: Sakar Arora sakar.arora@nxp.com Signed-off-by: Bhupesh Sharma bhupesh.sharma@nxp.com
Platforms/Nxp/LS1043aRdb/Include/Library/SocLib.h | 308 +++++++++++++++++++++ .../Library/LS1043aSocLib/LS1043aSocLib.c | 140 ++++++++++ .../Library/LS1043aSocLib/LS1043aSocLib.inf | 40 +++ 3 files changed, 488 insertions(+) create mode 100644 Platforms/Nxp/LS1043aRdb/Include/Library/SocLib.h create mode 100644 Platforms/Nxp/LS1043aRdb/Library/LS1043aSocLib/LS1043aSocLib.c create mode 100644 Platforms/Nxp/LS1043aRdb/Library/LS1043aSocLib/LS1043aSocLib.inf
diff --git a/Platforms/Nxp/LS1043aRdb/Include/Library/SocLib.h b/Platforms/Nxp/LS1043aRdb/Include/Library/SocLib.h new file mode 100644 index 0000000..d1655d5 --- /dev/null +++ b/Platforms/Nxp/LS1043aRdb/Include/Library/SocLib.h
If this header defines the public API of the SocLib library class, please add this library to the [LibraryClasses] section of the package .dec file. If it is an internal header for the SocLib implementation, please keep it with the .c file. If it is both, please split it up.
@@ -0,0 +1,308 @@ +/** SoCLib.h +* Header defining the LS1043a SoC specific constants (Base addresses, sizes, flags) +* +* Copyright (c) 2016, Freescale Semiconductor, Inc. All rights reserved. +* +* This program and the accompanying materials +* are licensed and made available under the terms and conditions of the BSD License +* which accompanies this distribution. The full text of the license may be found at +* http://opensource.org/licenses/bsd-license.php +* +* THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, +* WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. +* +**/
+#ifndef __LS1043A_SOC_H__ +#define __LS1043A_SOC_H__
+#define LS1043A_NUM_CC_PLLS 2 +#define HWA_CGA_M1_CLK_SEL 0xe0000000 +#define HWA_CGA_M1_CLK_SHIFT 29 +#define HWA_CGA_M2_CLK_SEL 0x00000007 +#define HWA_CGA_M2_CLK_SHIFT 0
+#define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
+#define LS1043A_CLK_FREQ 100000000 +#define LS1043A_DDR_CLK_FREQ 100000000
+#define LS1043A_MAX_CPUS 4 +#define LS1043A_NUM_FMAN 1
+struct SysInfo {
UINTN FreqProcessor[LS1043A_MAX_CPUS];
UINTN FreqSystemBus;
UINTN FreqDdrBus;
UINTN FreqLocalBus;
UINTN FreqSdhc;
UINTN FreqFman[LS1043A_NUM_FMAN];
UINTN FreqQman;
+};
+/* Device Configuration and Pin Control */ +struct CcsrGur {
UINT32 porsr1; /* POR status 1 */
UINT32 porsr2; /* POR status 2 */
UINT8 res_008[0x20-0x8];
UINT32 gpporcr1; /* General-purpose POR configuration */
UINT32 gpporcr2;
UINT32 dcfg_fusesr; /* Fuse status register */
UINT8 res_02c[0x70-0x2c];
UINT32 devdisr; /* Device disable control */
UINT32 devdisr2; /* Device disable control 2 */
UINT32 devdisr3; /* Device disable control 3 */
UINT32 devdisr4; /* Device disable control 4 */
UINT32 devdisr5; /* Device disable control 5 */
UINT32 devdisr6; /* Device disable control 6 */
UINT32 devdisr7; /* Device disable control 7 */
UINT8 res_08c[0x94-0x8c];
UINT32 coredisru; /* uppper portion for support of 64 cores */
UINT32 coredisrl; /* lower portion for support of 64 cores */
UINT8 res_09c[0xa0-0x9c];
UINT32 pvr; /* Processor version */
UINT32 svr; /* System version */
UINT32 mvr; /* Manufacturing version */
UINT8 res_0ac[0xb0-0xac];
UINT32 rstcr; /* Reset control */
UINT32 rstrqpblsr; /* Reset request preboot loader status */
UINT8 res_0b8[0xc0-0xb8];
UINT32 rstrqmr1; /* Reset request mask */
UINT8 res_0c4[0xc8-0xc4];
UINT32 rstrqsr1; /* Reset request status */
UINT8 res_0cc[0xd4-0xcc];
UINT32 rstrqwdtmrl; /* Reset request WDT mask */
UINT8 res_0d8[0xdc-0xd8];
UINT32 rstrqwdtsrl; /* Reset request WDT status */
UINT8 res_0e0[0xe4-0xe0];
UINT32 brrl; /* Boot release */
UINT8 res_0e8[0x100-0xe8];
UINT32 rcwsr[16]; /* Reset control word status */
+#define FSL_CHASSIS2_RCWSR0_SYS_PLL_RAT_SHIFT 25 +#define FSL_CHASSIS2_RCWSR0_SYS_PLL_RAT_MASK 0x1f +#define FSL_CHASSIS2_RCWSR0_MEM_PLL_RAT_SHIFT 16 +#define FSL_CHASSIS2_RCWSR0_MEM_PLL_RAT_MASK 0x3f
UINT8 res_140[0x200-0x140];
UINT32 scratchrw[4]; /* Scratch Read/Write */
UINT8 res_210[0x300-0x210];
UINT32 scratchw1r[4]; /* Scratch Read (Write once) */
UINT8 res_310[0x400-0x310];
UINT32 crstsr[12];
UINT8 res_430[0x500-0x430];
/* PCI Express n Logical I/O Device Number register */
UINT32 dcfg_ccsr_pex1liodnr;
UINT32 dcfg_ccsr_pex2liodnr;
UINT32 dcfg_ccsr_pex3liodnr;
UINT32 dcfg_ccsr_pex4liodnr;
/* RIO n Logical I/O Device Number register */
UINT32 dcfg_ccsr_rio1liodnr;
UINT32 dcfg_ccsr_rio2liodnr;
UINT32 dcfg_ccsr_rio3liodnr;
UINT32 dcfg_ccsr_rio4liodnr;
/* USB Logical I/O Device Number register */
UINT32 dcfg_ccsr_usb1liodnr;
UINT32 dcfg_ccsr_usb2liodnr;
UINT32 dcfg_ccsr_usb3liodnr;
UINT32 dcfg_ccsr_usb4liodnr;
/* SD/MMC Logical I/O Device Number register */
UINT32 dcfg_ccsr_sdmmc1liodnr;
UINT32 dcfg_ccsr_sdmmc2liodnr;
UINT32 dcfg_ccsr_sdmmc3liodnr;
UINT32 dcfg_ccsr_sdmmc4liodnr;
/* RIO Message Unit Logical I/O Device Number register */
UINT32 dcfg_ccsr_riomaintliodnr;
UINT8 res_544[0x550-0x544];
UINT32 sataliodnr[4];
UINT8 res_560[0x570-0x560];
UINT32 dcfg_ccsr_misc1liodnr;
UINT32 dcfg_ccsr_misc2liodnr;
UINT32 dcfg_ccsr_misc3liodnr;
UINT32 dcfg_ccsr_misc4liodnr;
UINT32 dcfg_ccsr_dma1liodnr;
UINT32 dcfg_ccsr_dma2liodnr;
UINT32 dcfg_ccsr_dma3liodnr;
UINT32 dcfg_ccsr_dma4liodnr;
UINT32 dcfg_ccsr_spare1liodnr;
UINT32 dcfg_ccsr_spare2liodnr;
UINT32 dcfg_ccsr_spare3liodnr;
UINT32 dcfg_ccsr_spare4liodnr;
UINT8 res_5a0[0x600-0x5a0];
UINT32 dcfg_ccsr_pblsr;
UINT32 pamubypenr;
UINT32 dmacr1;
UINT8 res_60c[0x610-0x60c];
UINT32 dcfg_ccsr_gensr1;
UINT32 dcfg_ccsr_gensr2;
UINT32 dcfg_ccsr_gensr3;
UINT32 dcfg_ccsr_gensr4;
UINT32 dcfg_ccsr_gencr1;
UINT32 dcfg_ccsr_gencr2;
UINT32 dcfg_ccsr_gencr3;
UINT32 dcfg_ccsr_gencr4;
UINT32 dcfg_ccsr_gencr5;
UINT32 dcfg_ccsr_gencr6;
UINT32 dcfg_ccsr_gencr7;
UINT8 res_63c[0x658-0x63c];
UINT32 dcfg_ccsr_cgensr1;
UINT32 dcfg_ccsr_cgensr0;
UINT8 res_660[0x678-0x660];
UINT32 dcfg_ccsr_cgencr1;
UINT32 dcfg_ccsr_cgencr0;
UINT8 res_680[0x700-0x680];
UINT32 dcfg_ccsr_sriopstecr;
UINT32 dcfg_ccsr_dcsrcr;
UINT8 res_708[0x740-0x708]; /* add more registers when needed */
UINT32 tp_ityp[64]; /* Topology Initiator Type Register */
struct {
UINT32 upper;
UINT32 lower;
} tp_cluster[16];
UINT8 res_8c0[0xa00-0x8c0]; /* add more registers when needed */
UINT32 dcfg_ccsr_qmbm_warmrst;
UINT8 res_a04[0xa20-0xa04]; /* add more registers when needed */
UINT32 dcfg_ccsr_reserved0;
UINT32 dcfg_ccsr_reserved1;
+};
+/* Supplemental Configuration Unit */ +struct CcsrScfg {
UINT8 res_000[0x100-0x000];
UINT32 usb2_icid;
UINT32 usb3_icid;
UINT8 res_108[0x114-0x108];
UINT32 dma_icid;
UINT32 sata_icid;
UINT32 usb1_icid;
UINT32 qe_icid;
UINT32 sdhc_icid;
UINT32 edma_icid;
UINT32 etr_icid;
UINT32 core0_sft_rst;
UINT32 core1_sft_rst;
UINT32 core2_sft_rst;
UINT32 core3_sft_rst;
UINT8 res_140[0x158-0x140];
UINT32 altcbar;
UINT32 qspi_cfg;
UINT8 res_160[0x180-0x160];
UINT32 dmamcr;
UINT8 res_184[0x18c-0x184];
UINT32 debug_icid;
UINT8 res_190[0x1a4-0x190];
UINT32 snpcnfgcr;
UINT8 res_1a8[0x1ac-0x1a8];
UINT32 intpcr;
UINT8 res_1b0[0x204-0x1b0];
UINT32 coresrencr;
UINT8 res_208[0x220-0x208];
UINT32 rvbar0_0;
UINT32 rvbar0_1;
UINT32 rvbar1_0;
UINT32 rvbar1_1;
UINT32 rvbar2_0;
UINT32 rvbar2_1;
UINT32 rvbar3_0;
UINT32 rvbar3_1;
UINT32 lpmcsr;
UINT8 res_244[0x400-0x244];
UINT32 qspidqscr;
UINT32 ecgtxcmcr;
UINT32 sdhciovselcr;
UINT32 rcwpmuxcr0;
UINT32 usbdrvvbus_selcr;
UINT32 usbpwrfault_selcr;
UINT32 usb_refclk_selcr1;
UINT32 usb_refclk_selcr2;
UINT32 usb_refclk_selcr3;
UINT8 res_424[0x600-0x424];
UINT32 scratchrw[4];
UINT8 res_610[0x680-0x610];
UINT32 corebcr;
UINT8 res_684[0x1000-0x684];
UINT32 pex1msiir;
UINT32 pex1msir;
UINT8 res_1008[0x2000-0x1008];
UINT32 pex2;
UINT32 pex2msir;
UINT8 res_2008[0x3000-0x2008];
UINT32 pex3msiir;
UINT32 pex3msir;
+};
+/* Clocking */ +struct CcsrClk {
struct {
UINT32 clkcncsr; /* core cluster n clock control status */
UINT8 res_004[0x0c];
UINT32 clkcghwacsr; /* Clock generator n hardware accelerator */
UINT8 res_014[0x0c];
} clkcsr[4];
UINT8 res_040[0x780]; /* 0x100 */
struct {
UINT32 pllcngsr;
UINT8 res_804[0x1c];
} pllcgsr[2];
UINT8 res_840[0x1c0];
UINT32 clkpcsr; /* 0xa00 Platform clock domain control/status */
UINT8 res_a04[0x1fc];
UINT32 pllpgsr; /* 0xc00 Platform PLL General Status */
UINT8 res_c04[0x1c];
UINT32 plldgsr; /* 0xc20 DDR PLL General Status */
UINT8 res_c24[0x3dc];
+};
+/* CCI-400 registers */ +struct CcsrCci400 {
UINT32 ctrl_ord; /* Control Override */
UINT32 spec_ctrl; /* Speculation Control */
UINT32 secure_access; /* Secure Access */
UINT32 status; /* Status */
UINT32 impr_err; /* Imprecise Error */
UINT8 res_14[0x100 - 0x14];
UINT32 pmcr; /* Performance Monitor Control */
UINT8 res_104[0xfd0 - 0x104];
UINT32 pid[8]; /* Peripheral ID */
UINT32 cid[4]; /* Component ID */
struct {
UINT32 snoop_ctrl; /* Snoop Control */
UINT32 sha_ord; /* Shareable Override */
UINT8 res_1008[0x1100 - 0x1008];
UINT32 rc_qos_ord; /* read channel QoS Value Override */
UINT32 wc_qos_ord; /* read channel QoS Value Override */
UINT8 res_1108[0x110c - 0x1108];
UINT32 qos_ctrl; /* QoS Control */
UINT32 max_ot; /* Max OT */
UINT8 res_1114[0x1130 - 0x1114];
UINT32 target_lat; /* Target Latency */
UINT32 latency_regu; /* Latency Regulation */
UINT32 qos_range; /* QoS Range */
UINT8 res_113c[0x2000 - 0x113c];
} slave[5]; /* Slave Interface */
UINT8 res_6000[0x9004 - 0x6000];
UINT32 cycle_counter; /* Cycle counter */
UINT32 count_ctrl; /* Count Control */
UINT32 overflow_status; /* Overflow Flag Status */
UINT8 res_9010[0xa000 - 0x9010];
struct {
UINT32 event_select; /* Event Select */
UINT32 event_count; /* Event Count */
UINT32 counter_ctrl; /* Counter Control */
UINT32 overflow_status; /* Overflow Flag Status */
UINT8 res_a010[0xb000 - 0xa010];
} pcounter[4]; /* Performance Counter */
UINT8 res_e004[0x10000 - 0xe004];
+};
+UINT32 CalculateBaudDivisor(OUT UINT64 *BaudRate); +UINT32 CalculateI2cClockRate(VOID);
+#endif /* __LS1043A_SOC_H__ */ diff --git a/Platforms/Nxp/LS1043aRdb/Library/LS1043aSocLib/LS1043aSocLib.c b/Platforms/Nxp/LS1043aRdb/Library/LS1043aSocLib/LS1043aSocLib.c new file mode 100644 index 0000000..fdeae08 --- /dev/null +++ b/Platforms/Nxp/LS1043aRdb/Library/LS1043aSocLib/LS1043aSocLib.c @@ -0,0 +1,140 @@ +/** @SoCLib.c
- SoC specific Library for LS1043A SoC, containing functions to initialize various SoC components
- Copyright (c) 2016, Freescale Semiconductor, Inc. All rights reserved.
- This program and the accompanying materials
- are licensed and made available under the terms and conditions of the BSD License
- which accompanies this distribution. The full text of the license may be found at
- http://opensource.org/licenses/bsd-license.php
- THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
- WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
+**/
+#include <Base.h> +#include <PiPei.h> +#include <Uefi.h> +#include <Library/BaseLib.h> +#include <Library/MemoryAllocationLib.h> +#include <Library/BaseMemoryLib/MemLibInternals.h>
+#include <Library/PrePiLib.h> +#include <Library/PcdLib.h> +#include <Library/DebugLib.h> +#include <Library/DebugAgentLib.h> +#include <Library/IoLib.h> +#include <Library/PrintLib.h>
+#include <Library/PlatformLib.h> +#include <Library/SocLib.h> +#include <Library/CpldLib.h>
+VOID +GetSysInfo (
- OUT struct SysInfo *PtrSysInfo
- )
+{
struct CcsrGur *GurBase = (void *)(LS1043A_FSL_GUTS_ADDR);
struct CcsrClk *ClkBase = (void *)(LS1043A_FSL_CLK_ADDR);
UINTN CpuIndex;
UINT32 TempRcw;
const UINT8 CoreCplxPll[8] = {
[0] = 0, /* CC1 PPL / 1 */
[1] = 0, /* CC1 PPL / 2 */
[4] = 1, /* CC2 PPL / 1 */
[5] = 1, /* CC2 PPL / 2 */
};
const UINT8 CoreCplxPllDivisor[8] = {
[0] = 1, /* CC1 PPL / 1 */
[1] = 2, /* CC1 PPL / 2 */
[4] = 1, /* CC2 PPL / 1 */
[5] = 2, /* CC2 PPL / 2 */
};
please make these STATIC CONST and move out of the function
UINTN PllCount;
UINTN FreqCPll[LS1043A_FSL_NUM_CC_PLLS];
UINTN PllRatio[LS1043A_FSL_NUM_CC_PLLS];
UINTN SysClk = LS1043A_CLK_FREQ;
PtrSysInfo->FreqSystemBus = SysClk;
PtrSysInfo->FreqDdrBus = SysClk;
PtrSysInfo->FreqSystemBus *= (MmioReadBe32((UINTN)&GurBase->rcwsr[0]) >>
FSL_CHASSIS2_RCWSR0_SYS_PLL_RAT_SHIFT) &
FSL_CHASSIS2_RCWSR0_SYS_PLL_RAT_MASK;
PtrSysInfo->FreqDdrBus *= (MmioReadBe32((UINTN)&GurBase->rcwsr[0]) >>
FSL_CHASSIS2_RCWSR0_MEM_PLL_RAT_SHIFT) &
FSL_CHASSIS2_RCWSR0_MEM_PLL_RAT_MASK;
for (PllCount = 0; PllCount < LS1043A_FSL_NUM_CC_PLLS; PllCount++) {
PllRatio[PllCount] = (MmioReadBe32((UINTN)&ClkBase->pllcgsr[PllCount].pllcngsr) >> 1) & 0xff;
if (PllRatio[PllCount] > 4)
FreqCPll[PllCount] = SysClk * PllRatio[PllCount];
else
FreqCPll[PllCount] = PtrSysInfo->FreqSystemBus * PllRatio[PllCount];
}
for (CpuIndex = 0; CpuIndex < LS1043A_MAX_CPUS; CpuIndex++) {
UINT32 c_pll_sel = (MmioReadBe32((UINTN)&ClkBase->clkcsr[CpuIndex].clkcncsr) >> 27)
& 0xf;
UINT32 cplx_pll = CoreCplxPll[c_pll_sel];
PtrSysInfo->FreqProcessor[CpuIndex] =
FreqCPll[cplx_pll] / CoreCplxPllDivisor[c_pll_sel];
}
TempRcw = MmioReadBe32((UINTN)&GurBase->rcwsr[7]);
switch ((TempRcw & HWA_CGA_M1_CLK_SEL) >> HWA_CGA_M1_CLK_SHIFT) {
case 2:
PtrSysInfo->FreqFman[0] = FreqCPll[0] / 2;
break;
case 3:
PtrSysInfo->FreqFman[0] = FreqCPll[1] / 3;
break;
case 6:
PtrSysInfo->FreqFman[0] = FreqCPll[0] / 2;
break;
case 7:
PtrSysInfo->FreqFman[0] = FreqCPll[1] / 3;
break;
default:
DEBUG((EFI_D_WARN, "Error: Unknown FMan1 clock select!\n"));
break;
}
TempRcw = MmioReadBe32((UINTN)&GurBase->rcwsr[15]);
TempRcw = (TempRcw & HWA_CGA_M2_CLK_SEL) >> HWA_CGA_M2_CLK_SHIFT;
PtrSysInfo->FreqSdhc = FreqCPll[1] / TempRcw;
PtrSysInfo->FreqQman = PtrSysInfo->FreqSystemBus / 2;
+}
+UINT32 +CalculateBaudDivisor (
- OUT UINT64 *BaudRate
- )
+{
struct SysInfo SocSysInfo;
UINTN DUartClk;
GetSysInfo(&SocSysInfo);
DUartClk = SocSysInfo.FreqSystemBus;
return ((DUartClk)/(*BaudRate * 16));
+}
+UINT32 +CalculateI2cClockRate(
VOID
)
+{
struct SysInfo SocSysInfo;
GetSysInfo(&SocSysInfo);
return SocSysInfo.FreqSystemBus;
+} diff --git a/Platforms/Nxp/LS1043aRdb/Library/LS1043aSocLib/LS1043aSocLib.inf b/Platforms/Nxp/LS1043aRdb/Library/LS1043aSocLib/LS1043aSocLib.inf new file mode 100644 index 0000000..322fe34 --- /dev/null +++ b/Platforms/Nxp/LS1043aRdb/Library/LS1043aSocLib/LS1043aSocLib.inf @@ -0,0 +1,40 @@ +#/* @SoCLib.inf +# Copyright (c) 2016, Freescale Semiconductor, Inc. All rights reserved. +# +# This program and the accompanying materials +# are licensed and made available under the terms and conditions of the BSD License +# which accompanies this distribution. The full text of the license may be found at +# http://opensource.org/licenses/bsd-license.php +# +# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, +# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. +# +#*/
+[Defines]
- INF_VERSION = 0x00010005
- BASE_NAME = LS1043aSocLib
- FILE_GUID = 736343a0-1d96-11e0-aaaa-0002a5d5c51b
Use a fresh GUID
- MODULE_TYPE = BASE
- VERSION_STRING = 1.0
- LIBRARY_CLASS = SocLib
+[Packages]
- MdePkg/MdePkg.dec
- MdeModulePkg/MdeModulePkg.dec
- EmbeddedPkg/EmbeddedPkg.dec
- ArmPkg/ArmPkg.dec
- ArmPlatformPkg/ArmPlatformPkg.dec
- OpenPlatformPkg/Platforms/Nxp/LS1043aRdb/LS1043aRdbPkg.dec
- OpenPlatformPkg/Chips/Nxp/QoriqLs/NxpQoriqLs.dec
+[LibraryClasses]
- BaseLib
- CpldLib
- DebugLib
- DebugAgentLib
- IoLib
- ArmLib
+[Sources.common]
- LS1043aSocLib.c
-- 1.9.1
Hi Ard,
Thanks for the review comments.
-----Original Message----- From: Ard Biesheuvel [mailto:ard.biesheuvel@linaro.org] Sent: Tuesday, October 18, 2016 3:00 PM
On 17 October 2016 at 21:04, Bhupesh Sharma bhupesh.sharma@freescale.com wrote:
From: Sakar Arora sakar.arora@nxp.com
There are several early SoC/Board level initialization functions
which
need to be performed before the DXE phase can execute.
While some of these are more related to how the boot information
looks
on the console, others are related to setting up SoC/board components/mux'es in a way that a particular component can be used.
This patch adds the support for the same.
Signed-off-by: Sakar Arora sakar.arora@nxp.com Signed-off-by: Bhupesh Sharma bhupesh.sharma@nxp.com
Platforms/Nxp/LS1043aRdb/Include/Library/SocLib.h | 308
+++++++++++++++++++++
.../Library/LS1043aSocLib/LS1043aSocLib.c | 140 ++++++++++ .../Library/LS1043aSocLib/LS1043aSocLib.inf | 40 +++ 3 files changed, 488 insertions(+) create mode 100644 Platforms/Nxp/LS1043aRdb/Include/Library/SocLib.h create mode 100644 Platforms/Nxp/LS1043aRdb/Library/LS1043aSocLib/LS1043aSocLib.c create mode 100644 Platforms/Nxp/LS1043aRdb/Library/LS1043aSocLib/LS1043aSocLib.inf
diff --git a/Platforms/Nxp/LS1043aRdb/Include/Library/SocLib.h b/Platforms/Nxp/LS1043aRdb/Include/Library/SocLib.h new file mode 100644 index 0000000..d1655d5 --- /dev/null +++ b/Platforms/Nxp/LS1043aRdb/Include/Library/SocLib.h
If this header defines the public API of the SocLib library class, please add this library to the [LibraryClasses] section of the package .dec file. If it is an internal header for the SocLib implementation, please keep it with the .c file. If it is both, please split it up.
This is an internal header file for SoCLib. I will keep this with the .c file.
@@ -0,0 +1,308 @@ +/** SoCLib.h +* Header defining the LS1043a SoC specific constants (Base +addresses, sizes, flags) +* +* Copyright (c) 2016, Freescale Semiconductor, Inc. All rights
reserved.
+* +* This program and the accompanying materials +* are licensed and made available under the terms and conditions of +the BSD License +* which accompanies this distribution. The full text of the
license
+may be found at +* http://opensource.org/licenses/bsd-license.php +* +* THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" +BASIS, +* WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS
OR IMPLIED.
+* +**/
+#ifndef __LS1043A_SOC_H__ +#define __LS1043A_SOC_H__
+#define LS1043A_NUM_CC_PLLS 2 +#define HWA_CGA_M1_CLK_SEL 0xe0000000 +#define HWA_CGA_M1_CLK_SHIFT 29 +#define HWA_CGA_M2_CLK_SEL 0x00000007 +#define HWA_CGA_M2_CLK_SHIFT 0
+#define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
+#define LS1043A_CLK_FREQ 100000000 +#define LS1043A_DDR_CLK_FREQ 100000000
+#define LS1043A_MAX_CPUS 4 +#define LS1043A_NUM_FMAN 1
+struct SysInfo {
UINTN FreqProcessor[LS1043A_MAX_CPUS];
UINTN FreqSystemBus;
UINTN FreqDdrBus;
UINTN FreqLocalBus;
UINTN FreqSdhc;
UINTN FreqFman[LS1043A_NUM_FMAN];
UINTN FreqQman;
+};
+/* Device Configuration and Pin Control */ struct CcsrGur {
UINT32 porsr1; /* POR status 1 */
UINT32 porsr2; /* POR status 2 */
UINT8 res_008[0x20-0x8];
UINT32 gpporcr1; /* General-purpose POR
configuration */
UINT32 gpporcr2;
UINT32 dcfg_fusesr; /* Fuse status register */
UINT8 res_02c[0x70-0x2c];
UINT32 devdisr; /* Device disable control */
UINT32 devdisr2; /* Device disable control 2 */
UINT32 devdisr3; /* Device disable control 3 */
UINT32 devdisr4; /* Device disable control 4 */
UINT32 devdisr5; /* Device disable control 5 */
UINT32 devdisr6; /* Device disable control 6 */
UINT32 devdisr7; /* Device disable control 7 */
UINT8 res_08c[0x94-0x8c];
UINT32 coredisru; /* uppper portion for support of
64 cores */
UINT32 coredisrl; /* lower portion for support of 64
cores */
UINT8 res_09c[0xa0-0x9c];
UINT32 pvr; /* Processor version */
UINT32 svr; /* System version */
UINT32 mvr; /* Manufacturing version */
UINT8 res_0ac[0xb0-0xac];
UINT32 rstcr; /* Reset control */
UINT32 rstrqpblsr; /* Reset request preboot loader
status */
UINT8 res_0b8[0xc0-0xb8];
UINT32 rstrqmr1; /* Reset request mask */
UINT8 res_0c4[0xc8-0xc4];
UINT32 rstrqsr1; /* Reset request status */
UINT8 res_0cc[0xd4-0xcc];
UINT32 rstrqwdtmrl; /* Reset request WDT mask */
UINT8 res_0d8[0xdc-0xd8];
UINT32 rstrqwdtsrl; /* Reset request WDT status */
UINT8 res_0e0[0xe4-0xe0];
UINT32 brrl; /* Boot release */
UINT8 res_0e8[0x100-0xe8];
UINT32 rcwsr[16]; /* Reset control word status */
+#define FSL_CHASSIS2_RCWSR0_SYS_PLL_RAT_SHIFT 25 +#define FSL_CHASSIS2_RCWSR0_SYS_PLL_RAT_MASK 0x1f +#define FSL_CHASSIS2_RCWSR0_MEM_PLL_RAT_SHIFT 16 +#define FSL_CHASSIS2_RCWSR0_MEM_PLL_RAT_MASK 0x3f
UINT8 res_140[0x200-0x140];
UINT32 scratchrw[4]; /* Scratch Read/Write */
UINT8 res_210[0x300-0x210];
UINT32 scratchw1r[4]; /* Scratch Read (Write once) */
UINT8 res_310[0x400-0x310];
UINT32 crstsr[12];
UINT8 res_430[0x500-0x430];
/* PCI Express n Logical I/O Device Number register */
UINT32 dcfg_ccsr_pex1liodnr;
UINT32 dcfg_ccsr_pex2liodnr;
UINT32 dcfg_ccsr_pex3liodnr;
UINT32 dcfg_ccsr_pex4liodnr;
/* RIO n Logical I/O Device Number register */
UINT32 dcfg_ccsr_rio1liodnr;
UINT32 dcfg_ccsr_rio2liodnr;
UINT32 dcfg_ccsr_rio3liodnr;
UINT32 dcfg_ccsr_rio4liodnr;
/* USB Logical I/O Device Number register */
UINT32 dcfg_ccsr_usb1liodnr;
UINT32 dcfg_ccsr_usb2liodnr;
UINT32 dcfg_ccsr_usb3liodnr;
UINT32 dcfg_ccsr_usb4liodnr;
/* SD/MMC Logical I/O Device Number register */
UINT32 dcfg_ccsr_sdmmc1liodnr;
UINT32 dcfg_ccsr_sdmmc2liodnr;
UINT32 dcfg_ccsr_sdmmc3liodnr;
UINT32 dcfg_ccsr_sdmmc4liodnr;
/* RIO Message Unit Logical I/O Device Number register */
UINT32 dcfg_ccsr_riomaintliodnr;
UINT8 res_544[0x550-0x544];
UINT32 sataliodnr[4];
UINT8 res_560[0x570-0x560];
UINT32 dcfg_ccsr_misc1liodnr;
UINT32 dcfg_ccsr_misc2liodnr;
UINT32 dcfg_ccsr_misc3liodnr;
UINT32 dcfg_ccsr_misc4liodnr;
UINT32 dcfg_ccsr_dma1liodnr;
UINT32 dcfg_ccsr_dma2liodnr;
UINT32 dcfg_ccsr_dma3liodnr;
UINT32 dcfg_ccsr_dma4liodnr;
UINT32 dcfg_ccsr_spare1liodnr;
UINT32 dcfg_ccsr_spare2liodnr;
UINT32 dcfg_ccsr_spare3liodnr;
UINT32 dcfg_ccsr_spare4liodnr;
UINT8 res_5a0[0x600-0x5a0];
UINT32 dcfg_ccsr_pblsr;
UINT32 pamubypenr;
UINT32 dmacr1;
UINT8 res_60c[0x610-0x60c];
UINT32 dcfg_ccsr_gensr1;
UINT32 dcfg_ccsr_gensr2;
UINT32 dcfg_ccsr_gensr3;
UINT32 dcfg_ccsr_gensr4;
UINT32 dcfg_ccsr_gencr1;
UINT32 dcfg_ccsr_gencr2;
UINT32 dcfg_ccsr_gencr3;
UINT32 dcfg_ccsr_gencr4;
UINT32 dcfg_ccsr_gencr5;
UINT32 dcfg_ccsr_gencr6;
UINT32 dcfg_ccsr_gencr7;
UINT8 res_63c[0x658-0x63c];
UINT32 dcfg_ccsr_cgensr1;
UINT32 dcfg_ccsr_cgensr0;
UINT8 res_660[0x678-0x660];
UINT32 dcfg_ccsr_cgencr1;
UINT32 dcfg_ccsr_cgencr0;
UINT8 res_680[0x700-0x680];
UINT32 dcfg_ccsr_sriopstecr;
UINT32 dcfg_ccsr_dcsrcr;
UINT8 res_708[0x740-0x708]; /* add more registers when needed
*/
UINT32 tp_ityp[64]; /* Topology Initiator Type Register */
struct {
UINT32 upper;
UINT32 lower;
} tp_cluster[16];
UINT8 res_8c0[0xa00-0x8c0]; /* add more registers when needed
*/
UINT32 dcfg_ccsr_qmbm_warmrst;
UINT8 res_a04[0xa20-0xa04]; /* add more registers when needed
*/
UINT32 dcfg_ccsr_reserved0;
UINT32 dcfg_ccsr_reserved1;
+};
+/* Supplemental Configuration Unit */ struct CcsrScfg {
UINT8 res_000[0x100-0x000];
UINT32 usb2_icid;
UINT32 usb3_icid;
UINT8 res_108[0x114-0x108];
UINT32 dma_icid;
UINT32 sata_icid;
UINT32 usb1_icid;
UINT32 qe_icid;
UINT32 sdhc_icid;
UINT32 edma_icid;
UINT32 etr_icid;
UINT32 core0_sft_rst;
UINT32 core1_sft_rst;
UINT32 core2_sft_rst;
UINT32 core3_sft_rst;
UINT8 res_140[0x158-0x140];
UINT32 altcbar;
UINT32 qspi_cfg;
UINT8 res_160[0x180-0x160];
UINT32 dmamcr;
UINT8 res_184[0x18c-0x184];
UINT32 debug_icid;
UINT8 res_190[0x1a4-0x190];
UINT32 snpcnfgcr;
UINT8 res_1a8[0x1ac-0x1a8];
UINT32 intpcr;
UINT8 res_1b0[0x204-0x1b0];
UINT32 coresrencr;
UINT8 res_208[0x220-0x208];
UINT32 rvbar0_0;
UINT32 rvbar0_1;
UINT32 rvbar1_0;
UINT32 rvbar1_1;
UINT32 rvbar2_0;
UINT32 rvbar2_1;
UINT32 rvbar3_0;
UINT32 rvbar3_1;
UINT32 lpmcsr;
UINT8 res_244[0x400-0x244];
UINT32 qspidqscr;
UINT32 ecgtxcmcr;
UINT32 sdhciovselcr;
UINT32 rcwpmuxcr0;
UINT32 usbdrvvbus_selcr;
UINT32 usbpwrfault_selcr;
UINT32 usb_refclk_selcr1;
UINT32 usb_refclk_selcr2;
UINT32 usb_refclk_selcr3;
UINT8 res_424[0x600-0x424];
UINT32 scratchrw[4];
UINT8 res_610[0x680-0x610];
UINT32 corebcr;
UINT8 res_684[0x1000-0x684];
UINT32 pex1msiir;
UINT32 pex1msir;
UINT8 res_1008[0x2000-0x1008];
UINT32 pex2;
UINT32 pex2msir;
UINT8 res_2008[0x3000-0x2008];
UINT32 pex3msiir;
UINT32 pex3msir;
+};
+/* Clocking */ +struct CcsrClk {
struct {
UINT32 clkcncsr; /* core cluster n clock
control status */
UINT8 res_004[0x0c];
UINT32 clkcghwacsr; /* Clock generator n hardware
accelerator */
UINT8 res_014[0x0c];
} clkcsr[4];
UINT8 res_040[0x780]; /* 0x100 */
struct {
UINT32 pllcngsr;
UINT8 res_804[0x1c];
} pllcgsr[2];
UINT8 res_840[0x1c0];
UINT32 clkpcsr; /* 0xa00 Platform clock domain
control/status */
UINT8 res_a04[0x1fc];
UINT32 pllpgsr; /* 0xc00 Platform PLL General Status
*/
UINT8 res_c04[0x1c];
UINT32 plldgsr; /* 0xc20 DDR PLL General Status */
UINT8 res_c24[0x3dc];
+};
+/* CCI-400 registers */ +struct CcsrCci400 {
UINT32 ctrl_ord; /* Control Override
*/
UINT32 spec_ctrl; /* Speculation
Control */
UINT32 secure_access; /* Secure Access */
UINT32 status; /* Status */
UINT32 impr_err; /* Imprecise Error */
UINT8 res_14[0x100 - 0x14];
UINT32 pmcr; /* Performance Monitor
Control */
UINT8 res_104[0xfd0 - 0x104];
UINT32 pid[8]; /* Peripheral ID */
UINT32 cid[4]; /* Component ID */
struct {
UINT32 snoop_ctrl; /* Snoop Control */
UINT32 sha_ord; /* Shareable Override */
UINT8 res_1008[0x1100 - 0x1008];
UINT32 rc_qos_ord; /* read channel QoS
Value Override */
UINT32 wc_qos_ord; /* read channel QoS
Value Override */
UINT8 res_1108[0x110c - 0x1108];
UINT32 qos_ctrl; /* QoS Control */
UINT32 max_ot; /* Max OT */
UINT8 res_1114[0x1130 - 0x1114];
UINT32 target_lat; /* Target Latency */
UINT32 latency_regu; /* Latency Regulation */
UINT32 qos_range; /* QoS Range */
UINT8 res_113c[0x2000 - 0x113c];
} slave[5]; /* Slave Interface */
UINT8 res_6000[0x9004 - 0x6000];
UINT32 cycle_counter; /* Cycle counter */
UINT32 count_ctrl; /* Count Control */
UINT32 overflow_status; /* Overflow Flag Status */
UINT8 res_9010[0xa000 - 0x9010];
struct {
UINT32 event_select; /* Event Select */
UINT32 event_count; /* Event Count */
UINT32 counter_ctrl; /* Counter Control */
UINT32 overflow_status; /* Overflow Flag Status */
UINT8 res_a010[0xb000 - 0xa010];
} pcounter[4]; /* Performance Counter */
UINT8 res_e004[0x10000 - 0xe004]; };
+UINT32 CalculateBaudDivisor(OUT UINT64 *BaudRate); +UINT32 CalculateI2cClockRate(VOID);
+#endif /* __LS1043A_SOC_H__ */ diff --git a/Platforms/Nxp/LS1043aRdb/Library/LS1043aSocLib/LS1043aSocLib.c b/Platforms/Nxp/LS1043aRdb/Library/LS1043aSocLib/LS1043aSocLib.c new file mode 100644 index 0000000..fdeae08 --- /dev/null +++ b/Platforms/Nxp/LS1043aRdb/Library/LS1043aSocLib/LS1043aSocLib.c @@ -0,0 +1,140 @@ +/** @SoCLib.c
- SoC specific Library for LS1043A SoC, containing functions to
+initialize various SoC components
- Copyright (c) 2016, Freescale Semiconductor, Inc. All rights
reserved.
- This program and the accompanying materials are licensed and made
- available under the terms and conditions of the BSD License which
- accompanies this distribution. The full text of the license may be
- found at http://opensource.org/licenses/bsd-license.php
- THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS"
- BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER
EXPRESS OR IMPLIED.
+**/
+#include <Base.h> +#include <PiPei.h> +#include <Uefi.h> +#include <Library/BaseLib.h> +#include <Library/MemoryAllocationLib.h> #include +<Library/BaseMemoryLib/MemLibInternals.h>
+#include <Library/PrePiLib.h> +#include <Library/PcdLib.h> +#include <Library/DebugLib.h> +#include <Library/DebugAgentLib.h> +#include <Library/IoLib.h> +#include <Library/PrintLib.h>
+#include <Library/PlatformLib.h> +#include <Library/SocLib.h> +#include <Library/CpldLib.h>
+VOID +GetSysInfo (
- OUT struct SysInfo *PtrSysInfo
- )
+{
struct CcsrGur *GurBase = (void *)(LS1043A_FSL_GUTS_ADDR);
struct CcsrClk *ClkBase = (void *)(LS1043A_FSL_CLK_ADDR);
UINTN CpuIndex;
UINT32 TempRcw;
const UINT8 CoreCplxPll[8] = {
[0] = 0, /* CC1 PPL / 1 */
[1] = 0, /* CC1 PPL / 2 */
[4] = 1, /* CC2 PPL / 1 */
[5] = 1, /* CC2 PPL / 2 */
};
const UINT8 CoreCplxPllDivisor[8] = {
[0] = 1, /* CC1 PPL / 1 */
[1] = 2, /* CC1 PPL / 2 */
[4] = 1, /* CC2 PPL / 1 */
[5] = 2, /* CC2 PPL / 2 */
};
please make these STATIC CONST and move out of the function
Ok.
UINTN PllCount;
UINTN FreqCPll[LS1043A_FSL_NUM_CC_PLLS];
UINTN PllRatio[LS1043A_FSL_NUM_CC_PLLS];
UINTN SysClk = LS1043A_CLK_FREQ;
PtrSysInfo->FreqSystemBus = SysClk;
PtrSysInfo->FreqDdrBus = SysClk;
PtrSysInfo->FreqSystemBus *= (MmioReadBe32((UINTN)&GurBase-
rcwsr[0]) >>
FSL_CHASSIS2_RCWSR0_SYS_PLL_RAT_SHIFT) &
FSL_CHASSIS2_RCWSR0_SYS_PLL_RAT_MASK;
PtrSysInfo->FreqDdrBus *= (MmioReadBe32((UINTN)&GurBase-
rcwsr[0]) >>
FSL_CHASSIS2_RCWSR0_MEM_PLL_RAT_SHIFT) &
FSL_CHASSIS2_RCWSR0_MEM_PLL_RAT_MASK;
for (PllCount = 0; PllCount < LS1043A_FSL_NUM_CC_PLLS;
PllCount++) {
PllRatio[PllCount] = (MmioReadBe32((UINTN)&ClkBase-
pllcgsr[PllCount].pllcngsr) >> 1) & 0xff;
if (PllRatio[PllCount] > 4)
FreqCPll[PllCount] = SysClk *
PllRatio[PllCount];
else
FreqCPll[PllCount] = PtrSysInfo-
FreqSystemBus * PllRatio[PllCount];
}
for (CpuIndex = 0; CpuIndex < LS1043A_MAX_CPUS; CpuIndex++) {
UINT32 c_pll_sel = (MmioReadBe32((UINTN)&ClkBase-
clkcsr[CpuIndex].clkcncsr) >> 27)
& 0xf;
UINT32 cplx_pll = CoreCplxPll[c_pll_sel];
PtrSysInfo->FreqProcessor[CpuIndex] =
FreqCPll[cplx_pll] /
CoreCplxPllDivisor[c_pll_sel];
}
TempRcw = MmioReadBe32((UINTN)&GurBase->rcwsr[7]);
switch ((TempRcw & HWA_CGA_M1_CLK_SEL) >>
HWA_CGA_M1_CLK_SHIFT) {
case 2:
PtrSysInfo->FreqFman[0] = FreqCPll[0] / 2;
break;
case 3:
PtrSysInfo->FreqFman[0] = FreqCPll[1] / 3;
break;
case 6:
PtrSysInfo->FreqFman[0] = FreqCPll[0] / 2;
break;
case 7:
PtrSysInfo->FreqFman[0] = FreqCPll[1] / 3;
break;
default:
DEBUG((EFI_D_WARN, "Error: Unknown FMan1 clock
select!\n"));
break;
}
TempRcw = MmioReadBe32((UINTN)&GurBase->rcwsr[15]);
TempRcw = (TempRcw & HWA_CGA_M2_CLK_SEL) >>
HWA_CGA_M2_CLK_SHIFT;
PtrSysInfo->FreqSdhc = FreqCPll[1] / TempRcw;
PtrSysInfo->FreqQman = PtrSysInfo->FreqSystemBus / 2; }
+UINT32 +CalculateBaudDivisor (
- OUT UINT64 *BaudRate
- )
+{
struct SysInfo SocSysInfo;
UINTN DUartClk;
GetSysInfo(&SocSysInfo);
DUartClk = SocSysInfo.FreqSystemBus;
return ((DUartClk)/(*BaudRate * 16)); }
+UINT32 +CalculateI2cClockRate(
VOID
)
+{
struct SysInfo SocSysInfo;
GetSysInfo(&SocSysInfo);
return SocSysInfo.FreqSystemBus;
+} diff --git a/Platforms/Nxp/LS1043aRdb/Library/LS1043aSocLib/LS1043aSocLib.inf b/Platforms/Nxp/LS1043aRdb/Library/LS1043aSocLib/LS1043aSocLib.inf new file mode 100644 index 0000000..322fe34 --- /dev/null +++
b/Platforms/Nxp/LS1043aRdb/Library/LS1043aSocLib/LS1043aSocLib.inf
@@ -0,0 +1,40 @@ +#/* @SoCLib.inf +# Copyright (c) 2016, Freescale Semiconductor, Inc. All rights
reserved.
+# +# This program and the accompanying materials # are licensed and +made available under the terms and conditions of the BSD License # +which accompanies this distribution. The full text of the license +may be found at # http://opensource.org/licenses/bsd-license.php +# +# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" +BASIS, # WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER
EXPRESS OR IMPLIED.
+# +#*/
+[Defines]
- INF_VERSION = 0x00010005
- BASE_NAME = LS1043aSocLib
- FILE_GUID = 736343a0-1d96-11e0-aaaa-
0002a5d5c51b
Use a fresh GUID
Ok.
- MODULE_TYPE = BASE
- VERSION_STRING = 1.0
- LIBRARY_CLASS = SocLib
+[Packages]
- MdePkg/MdePkg.dec
- MdeModulePkg/MdeModulePkg.dec
- EmbeddedPkg/EmbeddedPkg.dec
- ArmPkg/ArmPkg.dec
- ArmPlatformPkg/ArmPlatformPkg.dec
- OpenPlatformPkg/Platforms/Nxp/LS1043aRdb/LS1043aRdbPkg.dec
- OpenPlatformPkg/Chips/Nxp/QoriqLs/NxpQoriqLs.dec
+[LibraryClasses]
- BaseLib
- CpldLib
- DebugLib
- DebugAgentLib
- IoLib
- ArmLib
+[Sources.common]
- LS1043aSocLib.c
-- 1.9.1
Regards, Bhupesh
On Tue, Oct 18, 2016 at 01:34:03AM +0530, Bhupesh Sharma wrote:
From: Sakar Arora sakar.arora@nxp.com
There are several early SoC/Board level initialization functions which need to be performed before the DXE phase can execute.
While some of these are more related to how the boot information looks on the console, others are related to setting up SoC/board components/mux'es in a way that a particular component can be used.
This patch adds the support for the same.
Signed-off-by: Sakar Arora sakar.arora@nxp.com Signed-off-by: Bhupesh Sharma bhupesh.sharma@nxp.com
Platforms/Nxp/LS1043aRdb/Include/Library/SocLib.h | 308 +++++++++++++++++++++ .../Library/LS1043aSocLib/LS1043aSocLib.c | 140 ++++++++++ .../Library/LS1043aSocLib/LS1043aSocLib.inf | 40 +++ 3 files changed, 488 insertions(+) create mode 100644 Platforms/Nxp/LS1043aRdb/Include/Library/SocLib.h create mode 100644 Platforms/Nxp/LS1043aRdb/Library/LS1043aSocLib/LS1043aSocLib.c create mode 100644 Platforms/Nxp/LS1043aRdb/Library/LS1043aSocLib/LS1043aSocLib.inf
diff --git a/Platforms/Nxp/LS1043aRdb/Include/Library/SocLib.h b/Platforms/Nxp/LS1043aRdb/Include/Library/SocLib.h new file mode 100644 index 0000000..d1655d5 --- /dev/null +++ b/Platforms/Nxp/LS1043aRdb/Include/Library/SocLib.h @@ -0,0 +1,308 @@ +/** SoCLib.h +* Header defining the LS1043a SoC specific constants (Base addresses, sizes, flags) +* +* Copyright (c) 2016, Freescale Semiconductor, Inc. All rights reserved. +* +* This program and the accompanying materials +* are licensed and made available under the terms and conditions of the BSD License +* which accompanies this distribution. The full text of the license may be found at +* http://opensource.org/licenses/bsd-license.php +* +* THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, +* WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. +* +**/
+#ifndef __LS1043A_SOC_H__ +#define __LS1043A_SOC_H__
+#define LS1043A_NUM_CC_PLLS 2 +#define HWA_CGA_M1_CLK_SEL 0xe0000000 +#define HWA_CGA_M1_CLK_SHIFT 29 +#define HWA_CGA_M2_CLK_SEL 0x00000007 +#define HWA_CGA_M2_CLK_SHIFT 0
+#define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
This has now been added to Base,h, so can (and must) be dropped for v2.
+#define LS1043A_CLK_FREQ 100000000 +#define LS1043A_DDR_CLK_FREQ 100000000
+#define LS1043A_MAX_CPUS 4 +#define LS1043A_NUM_FMAN 1
+struct SysInfo {
- UINTN FreqProcessor[LS1043A_MAX_CPUS];
- UINTN FreqSystemBus;
- UINTN FreqDdrBus;
- UINTN FreqLocalBus;
- UINTN FreqSdhc;
- UINTN FreqFman[LS1043A_NUM_FMAN];
- UINTN FreqQman;
+};
+/* Device Configuration and Pin Control */ +struct CcsrGur {
- UINT32 porsr1; /* POR status 1 */
- UINT32 porsr2; /* POR status 2 */
- UINT8 res_008[0x20-0x8];
OK, now the hex makes sense. I actually kind of approve.
- UINT32 gpporcr1; /* General-purpose POR configuration */
- UINT32 gpporcr2;
- UINT32 dcfg_fusesr; /* Fuse status register */
- UINT8 res_02c[0x70-0x2c];
- UINT32 devdisr; /* Device disable control */
- UINT32 devdisr2; /* Device disable control 2 */
- UINT32 devdisr3; /* Device disable control 3 */
- UINT32 devdisr4; /* Device disable control 4 */
- UINT32 devdisr5; /* Device disable control 5 */
- UINT32 devdisr6; /* Device disable control 6 */
- UINT32 devdisr7; /* Device disable control 7 */
- UINT8 res_08c[0x94-0x8c];
- UINT32 coredisru; /* uppper portion for support of 64 cores */
- UINT32 coredisrl; /* lower portion for support of 64 cores */
- UINT8 res_09c[0xa0-0x9c];
- UINT32 pvr; /* Processor version */
- UINT32 svr; /* System version */
- UINT32 mvr; /* Manufacturing version */
- UINT8 res_0ac[0xb0-0xac];
- UINT32 rstcr; /* Reset control */
- UINT32 rstrqpblsr; /* Reset request preboot loader status */
- UINT8 res_0b8[0xc0-0xb8];
- UINT32 rstrqmr1; /* Reset request mask */
- UINT8 res_0c4[0xc8-0xc4];
- UINT32 rstrqsr1; /* Reset request status */
- UINT8 res_0cc[0xd4-0xcc];
- UINT32 rstrqwdtmrl; /* Reset request WDT mask */
- UINT8 res_0d8[0xdc-0xd8];
- UINT32 rstrqwdtsrl; /* Reset request WDT status */
- UINT8 res_0e0[0xe4-0xe0];
- UINT32 brrl; /* Boot release */
- UINT8 res_0e8[0x100-0xe8];
- UINT32 rcwsr[16]; /* Reset control word status */
+#define FSL_CHASSIS2_RCWSR0_SYS_PLL_RAT_SHIFT 25 +#define FSL_CHASSIS2_RCWSR0_SYS_PLL_RAT_MASK 0x1f +#define FSL_CHASSIS2_RCWSR0_MEM_PLL_RAT_SHIFT 16 +#define FSL_CHASSIS2_RCWSR0_MEM_PLL_RAT_MASK 0x3f
- UINT8 res_140[0x200-0x140];
- UINT32 scratchrw[4]; /* Scratch Read/Write */
- UINT8 res_210[0x300-0x210];
- UINT32 scratchw1r[4]; /* Scratch Read (Write once) */
- UINT8 res_310[0x400-0x310];
- UINT32 crstsr[12];
- UINT8 res_430[0x500-0x430];
- /* PCI Express n Logical I/O Device Number register */
- UINT32 dcfg_ccsr_pex1liodnr;
- UINT32 dcfg_ccsr_pex2liodnr;
- UINT32 dcfg_ccsr_pex3liodnr;
- UINT32 dcfg_ccsr_pex4liodnr;
- /* RIO n Logical I/O Device Number register */
- UINT32 dcfg_ccsr_rio1liodnr;
- UINT32 dcfg_ccsr_rio2liodnr;
- UINT32 dcfg_ccsr_rio3liodnr;
- UINT32 dcfg_ccsr_rio4liodnr;
- /* USB Logical I/O Device Number register */
- UINT32 dcfg_ccsr_usb1liodnr;
- UINT32 dcfg_ccsr_usb2liodnr;
- UINT32 dcfg_ccsr_usb3liodnr;
- UINT32 dcfg_ccsr_usb4liodnr;
- /* SD/MMC Logical I/O Device Number register */
- UINT32 dcfg_ccsr_sdmmc1liodnr;
- UINT32 dcfg_ccsr_sdmmc2liodnr;
- UINT32 dcfg_ccsr_sdmmc3liodnr;
- UINT32 dcfg_ccsr_sdmmc4liodnr;
- /* RIO Message Unit Logical I/O Device Number register */
- UINT32 dcfg_ccsr_riomaintliodnr;
- UINT8 res_544[0x550-0x544];
- UINT32 sataliodnr[4];
- UINT8 res_560[0x570-0x560];
- UINT32 dcfg_ccsr_misc1liodnr;
- UINT32 dcfg_ccsr_misc2liodnr;
- UINT32 dcfg_ccsr_misc3liodnr;
- UINT32 dcfg_ccsr_misc4liodnr;
- UINT32 dcfg_ccsr_dma1liodnr;
- UINT32 dcfg_ccsr_dma2liodnr;
- UINT32 dcfg_ccsr_dma3liodnr;
- UINT32 dcfg_ccsr_dma4liodnr;
- UINT32 dcfg_ccsr_spare1liodnr;
- UINT32 dcfg_ccsr_spare2liodnr;
- UINT32 dcfg_ccsr_spare3liodnr;
- UINT32 dcfg_ccsr_spare4liodnr;
- UINT8 res_5a0[0x600-0x5a0];
- UINT32 dcfg_ccsr_pblsr;
- UINT32 pamubypenr;
- UINT32 dmacr1;
- UINT8 res_60c[0x610-0x60c];
- UINT32 dcfg_ccsr_gensr1;
- UINT32 dcfg_ccsr_gensr2;
- UINT32 dcfg_ccsr_gensr3;
- UINT32 dcfg_ccsr_gensr4;
- UINT32 dcfg_ccsr_gencr1;
- UINT32 dcfg_ccsr_gencr2;
- UINT32 dcfg_ccsr_gencr3;
- UINT32 dcfg_ccsr_gencr4;
- UINT32 dcfg_ccsr_gencr5;
- UINT32 dcfg_ccsr_gencr6;
- UINT32 dcfg_ccsr_gencr7;
- UINT8 res_63c[0x658-0x63c];
- UINT32 dcfg_ccsr_cgensr1;
- UINT32 dcfg_ccsr_cgensr0;
- UINT8 res_660[0x678-0x660];
- UINT32 dcfg_ccsr_cgencr1;
- UINT32 dcfg_ccsr_cgencr0;
- UINT8 res_680[0x700-0x680];
- UINT32 dcfg_ccsr_sriopstecr;
- UINT32 dcfg_ccsr_dcsrcr;
- UINT8 res_708[0x740-0x708]; /* add more registers when needed */
- UINT32 tp_ityp[64]; /* Topology Initiator Type Register */
- struct {
UINT32 upper;
UINT32 lower;
- } tp_cluster[16];
- UINT8 res_8c0[0xa00-0x8c0]; /* add more registers when needed */
- UINT32 dcfg_ccsr_qmbm_warmrst;
- UINT8 res_a04[0xa20-0xa04]; /* add more registers when needed */
- UINT32 dcfg_ccsr_reserved0;
- UINT32 dcfg_ccsr_reserved1;
+};
+/* Supplemental Configuration Unit */ +struct CcsrScfg {
- UINT8 res_000[0x100-0x000];
- UINT32 usb2_icid;
- UINT32 usb3_icid;
- UINT8 res_108[0x114-0x108];
- UINT32 dma_icid;
- UINT32 sata_icid;
- UINT32 usb1_icid;
- UINT32 qe_icid;
- UINT32 sdhc_icid;
- UINT32 edma_icid;
- UINT32 etr_icid;
- UINT32 core0_sft_rst;
- UINT32 core1_sft_rst;
- UINT32 core2_sft_rst;
- UINT32 core3_sft_rst;
- UINT8 res_140[0x158-0x140];
- UINT32 altcbar;
- UINT32 qspi_cfg;
- UINT8 res_160[0x180-0x160];
- UINT32 dmamcr;
- UINT8 res_184[0x18c-0x184];
- UINT32 debug_icid;
- UINT8 res_190[0x1a4-0x190];
- UINT32 snpcnfgcr;
- UINT8 res_1a8[0x1ac-0x1a8];
- UINT32 intpcr;
- UINT8 res_1b0[0x204-0x1b0];
- UINT32 coresrencr;
- UINT8 res_208[0x220-0x208];
- UINT32 rvbar0_0;
- UINT32 rvbar0_1;
- UINT32 rvbar1_0;
- UINT32 rvbar1_1;
- UINT32 rvbar2_0;
- UINT32 rvbar2_1;
- UINT32 rvbar3_0;
- UINT32 rvbar3_1;
- UINT32 lpmcsr;
- UINT8 res_244[0x400-0x244];
- UINT32 qspidqscr;
- UINT32 ecgtxcmcr;
- UINT32 sdhciovselcr;
- UINT32 rcwpmuxcr0;
- UINT32 usbdrvvbus_selcr;
- UINT32 usbpwrfault_selcr;
- UINT32 usb_refclk_selcr1;
- UINT32 usb_refclk_selcr2;
- UINT32 usb_refclk_selcr3;
- UINT8 res_424[0x600-0x424];
- UINT32 scratchrw[4];
- UINT8 res_610[0x680-0x610];
- UINT32 corebcr;
- UINT8 res_684[0x1000-0x684];
- UINT32 pex1msiir;
- UINT32 pex1msir;
- UINT8 res_1008[0x2000-0x1008];
- UINT32 pex2;
- UINT32 pex2msir;
- UINT8 res_2008[0x3000-0x2008];
- UINT32 pex3msiir;
- UINT32 pex3msir;
+};
+/* Clocking */ +struct CcsrClk {
- struct {
UINT32 clkcncsr; /* core cluster n clock control status */
UINT8 res_004[0x0c];
UINT32 clkcghwacsr; /* Clock generator n hardware accelerator */
UINT8 res_014[0x0c];
- } clkcsr[4];
- UINT8 res_040[0x780]; /* 0x100 */
- struct {
UINT32 pllcngsr;
UINT8 res_804[0x1c];
- } pllcgsr[2];
- UINT8 res_840[0x1c0];
- UINT32 clkpcsr; /* 0xa00 Platform clock domain control/status */
- UINT8 res_a04[0x1fc];
- UINT32 pllpgsr; /* 0xc00 Platform PLL General Status */
- UINT8 res_c04[0x1c];
- UINT32 plldgsr; /* 0xc20 DDR PLL General Status */
- UINT8 res_c24[0x3dc];
+};
+/* CCI-400 registers */ +struct CcsrCci400 {
- UINT32 ctrl_ord; /* Control Override */
- UINT32 spec_ctrl; /* Speculation Control */
- UINT32 secure_access; /* Secure Access */
- UINT32 status; /* Status */
- UINT32 impr_err; /* Imprecise Error */
- UINT8 res_14[0x100 - 0x14];
- UINT32 pmcr; /* Performance Monitor Control */
- UINT8 res_104[0xfd0 - 0x104];
- UINT32 pid[8]; /* Peripheral ID */
- UINT32 cid[4]; /* Component ID */
- struct {
UINT32 snoop_ctrl; /* Snoop Control */
UINT32 sha_ord; /* Shareable Override */
UINT8 res_1008[0x1100 - 0x1008];
UINT32 rc_qos_ord; /* read channel QoS Value Override */
UINT32 wc_qos_ord; /* read channel QoS Value Override */
UINT8 res_1108[0x110c - 0x1108];
UINT32 qos_ctrl; /* QoS Control */
UINT32 max_ot; /* Max OT */
UINT8 res_1114[0x1130 - 0x1114];
UINT32 target_lat; /* Target Latency */
UINT32 latency_regu; /* Latency Regulation */
UINT32 qos_range; /* QoS Range */
UINT8 res_113c[0x2000 - 0x113c];
- } slave[5]; /* Slave Interface */
- UINT8 res_6000[0x9004 - 0x6000];
- UINT32 cycle_counter; /* Cycle counter */
- UINT32 count_ctrl; /* Count Control */
- UINT32 overflow_status; /* Overflow Flag Status */
- UINT8 res_9010[0xa000 - 0x9010];
- struct {
UINT32 event_select; /* Event Select */
UINT32 event_count; /* Event Count */
UINT32 counter_ctrl; /* Counter Control */
UINT32 overflow_status; /* Overflow Flag Status */
UINT8 res_a010[0xb000 - 0xa010];
- } pcounter[4]; /* Performance Counter */
- UINT8 res_e004[0x10000 - 0xe004];
+};
+UINT32 CalculateBaudDivisor(OUT UINT64 *BaudRate); +UINT32 CalculateI2cClockRate(VOID);
+#endif /* __LS1043A_SOC_H__ */ diff --git a/Platforms/Nxp/LS1043aRdb/Library/LS1043aSocLib/LS1043aSocLib.c b/Platforms/Nxp/LS1043aRdb/Library/LS1043aSocLib/LS1043aSocLib.c new file mode 100644 index 0000000..fdeae08 --- /dev/null +++ b/Platforms/Nxp/LS1043aRdb/Library/LS1043aSocLib/LS1043aSocLib.c @@ -0,0 +1,140 @@ +/** @SoCLib.c
- SoC specific Library for LS1043A SoC, containing functions to initialize various SoC components
- Copyright (c) 2016, Freescale Semiconductor, Inc. All rights reserved.
- This program and the accompanying materials
- are licensed and made available under the terms and conditions of the BSD License
- which accompanies this distribution. The full text of the license may be found at
- http://opensource.org/licenses/bsd-license.php
- THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
- WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
+**/
+#include <Base.h> +#include <PiPei.h> +#include <Uefi.h> +#include <Library/BaseLib.h> +#include <Library/MemoryAllocationLib.h> +#include <Library/BaseMemoryLib/MemLibInternals.h>
+#include <Library/PrePiLib.h> +#include <Library/PcdLib.h> +#include <Library/DebugLib.h> +#include <Library/DebugAgentLib.h> +#include <Library/IoLib.h> +#include <Library/PrintLib.h>
+#include <Library/PlatformLib.h> +#include <Library/SocLib.h> +#include <Library/CpldLib.h>
Please sort the Library/ includes alphabetically.
+VOID +GetSysInfo (
This is a slightly too generic name for an exported function. SoCLibGetSysInfo would be more appropriate.
This comment applies to all of the function names in this file, really.
Actually, I guess this function could be made STATIC, but the others need addressing.
- OUT struct SysInfo *PtrSysInfo
- )
+{
- struct CcsrGur *GurBase = (void *)(LS1043A_FSL_GUTS_ADDR);
- struct CcsrClk *ClkBase = (void *)(LS1043A_FSL_CLK_ADDR);
- UINTN CpuIndex;
- UINT32 TempRcw;
- const UINT8 CoreCplxPll[8] = {
[0] = 0, /* CC1 PPL / 1 */
[1] = 0, /* CC1 PPL / 2 */
[4] = 1, /* CC2 PPL / 1 */
[5] = 1, /* CC2 PPL / 2 */
- };
- const UINT8 CoreCplxPllDivisor[8] = {
[0] = 1, /* CC1 PPL / 1 */
[1] = 2, /* CC1 PPL / 2 */
[4] = 1, /* CC2 PPL / 1 */
[5] = 2, /* CC2 PPL / 2 */
- };
- UINTN PllCount;
- UINTN FreqCPll[LS1043A_FSL_NUM_CC_PLLS];
- UINTN PllRatio[LS1043A_FSL_NUM_CC_PLLS];
- UINTN SysClk = LS1043A_CLK_FREQ;
- PtrSysInfo->FreqSystemBus = SysClk;
- PtrSysInfo->FreqDdrBus = SysClk;
- PtrSysInfo->FreqSystemBus *= (MmioReadBe32((UINTN)&GurBase->rcwsr[0]) >>
FSL_CHASSIS2_RCWSR0_SYS_PLL_RAT_SHIFT) &
FSL_CHASSIS2_RCWSR0_SYS_PLL_RAT_MASK;
- PtrSysInfo->FreqDdrBus *= (MmioReadBe32((UINTN)&GurBase->rcwsr[0]) >>
FSL_CHASSIS2_RCWSR0_MEM_PLL_RAT_SHIFT) &
FSL_CHASSIS2_RCWSR0_MEM_PLL_RAT_MASK;
- for (PllCount = 0; PllCount < LS1043A_FSL_NUM_CC_PLLS; PllCount++) {
PllRatio[PllCount] = (MmioReadBe32((UINTN)&ClkBase->pllcgsr[PllCount].pllcngsr) >> 1) & 0xff;
Can we have #defines for that 1 and 0xff?
if (PllRatio[PllCount] > 4)
Always braces with if/else in EDK2 code.
FreqCPll[PllCount] = SysClk * PllRatio[PllCount];
else
FreqCPll[PllCount] = PtrSysInfo->FreqSystemBus * PllRatio[PllCount];
- }
- for (CpuIndex = 0; CpuIndex < LS1043A_MAX_CPUS; CpuIndex++) {
UINT32 c_pll_sel = (MmioReadBe32((UINTN)&ClkBase->clkcsr[CpuIndex].clkcncsr) >> 27)
& 0xf;
Can we have #defines for that 27 and 0xff?
UINT32 cplx_pll = CoreCplxPll[c_pll_sel];
PtrSysInfo->FreqProcessor[CpuIndex] =
FreqCPll[cplx_pll] / CoreCplxPllDivisor[c_pll_sel];
- }
- TempRcw = MmioReadBe32((UINTN)&GurBase->rcwsr[7]);
- switch ((TempRcw & HWA_CGA_M1_CLK_SEL) >> HWA_CGA_M1_CLK_SHIFT) {
- case 2:
PtrSysInfo->FreqFman[0] = FreqCPll[0] / 2;
break;
- case 3:
PtrSysInfo->FreqFman[0] = FreqCPll[1] / 3;
break;
- case 6:
PtrSysInfo->FreqFman[0] = FreqCPll[0] / 2;
break;
- case 7:
PtrSysInfo->FreqFman[0] = FreqCPll[1] / 3;
break;
- default:
DEBUG((EFI_D_WARN, "Error: Unknown FMan1 clock select!\n"));
break;
- }
- TempRcw = MmioReadBe32((UINTN)&GurBase->rcwsr[15]);
- TempRcw = (TempRcw & HWA_CGA_M2_CLK_SEL) >> HWA_CGA_M2_CLK_SHIFT;
- PtrSysInfo->FreqSdhc = FreqCPll[1] / TempRcw;
- PtrSysInfo->FreqQman = PtrSysInfo->FreqSystemBus / 2;
+}
+UINT32 +CalculateBaudDivisor (
- OUT UINT64 *BaudRate
- )
+{
- struct SysInfo SocSysInfo;
- UINTN DUartClk;
- GetSysInfo(&SocSysInfo);
- DUartClk = SocSysInfo.FreqSystemBus;
- return ((DUartClk)/(*BaudRate * 16));
Why parentheses around DUartClk?
+}
+UINT32 +CalculateI2cClockRate(
VOID
- )
+{
- struct SysInfo SocSysInfo;
- GetSysInfo(&SocSysInfo);
- return SocSysInfo.FreqSystemBus;
+} diff --git a/Platforms/Nxp/LS1043aRdb/Library/LS1043aSocLib/LS1043aSocLib.inf b/Platforms/Nxp/LS1043aRdb/Library/LS1043aSocLib/LS1043aSocLib.inf new file mode 100644 index 0000000..322fe34 --- /dev/null +++ b/Platforms/Nxp/LS1043aRdb/Library/LS1043aSocLib/LS1043aSocLib.inf @@ -0,0 +1,40 @@ +#/* @SoCLib.inf +# Copyright (c) 2016, Freescale Semiconductor, Inc. All rights reserved. +# +# This program and the accompanying materials +# are licensed and made available under the terms and conditions of the BSD License +# which accompanies this distribution. The full text of the license may be found at +# http://opensource.org/licenses/bsd-license.php +# +# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, +# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. +# +#*/
+[Defines]
- INF_VERSION = 0x00010005
- BASE_NAME = LS1043aSocLib
- FILE_GUID = 736343a0-1d96-11e0-aaaa-0002a5d5c51b
- MODULE_TYPE = BASE
- VERSION_STRING = 1.0
- LIBRARY_CLASS = SocLib
+[Packages]
- MdePkg/MdePkg.dec
- MdeModulePkg/MdeModulePkg.dec
- EmbeddedPkg/EmbeddedPkg.dec
- ArmPkg/ArmPkg.dec
- ArmPlatformPkg/ArmPlatformPkg.dec
- OpenPlatformPkg/Platforms/Nxp/LS1043aRdb/LS1043aRdbPkg.dec
- OpenPlatformPkg/Chips/Nxp/QoriqLs/NxpQoriqLs.dec
+[LibraryClasses]
- BaseLib
- CpldLib
- DebugLib
- DebugAgentLib
- IoLib
- ArmLib
Could you sort the PAckages and LibraryClasses please?
+[Sources.common]
- LS1043aSocLib.c
-- 1.9.1
From: Sakar Arora sakar.arora@nxp.com
LS1043A SoC houses a DUART (Dual UART) IP which has two UART ports. One of these UART ports is connected to the A53 CPUs and is used for console in and out functionality.
This patch adds the support of the DUART IP as a PEI library.
Signed-off-by: Sakar Arora sakar.arora@nxp.com Signed-off-by: Bhupesh Sharma bhupesh.sharma@nxp.com --- Chips/Nxp/QoriqLs/Include/Library/DUart.h | 133 +++++++++ .../QoriqLs/Library/DUartPortLib/DUartPortLib.c | 321 +++++++++++++++++++++ .../QoriqLs/Library/DUartPortLib/DUartPortLib.inf | 43 +++ 3 files changed, 497 insertions(+) create mode 100644 Chips/Nxp/QoriqLs/Include/Library/DUart.h create mode 100644 Chips/Nxp/QoriqLs/Library/DUartPortLib/DUartPortLib.c create mode 100644 Chips/Nxp/QoriqLs/Library/DUartPortLib/DUartPortLib.inf
diff --git a/Chips/Nxp/QoriqLs/Include/Library/DUart.h b/Chips/Nxp/QoriqLs/Include/Library/DUart.h new file mode 100644 index 0000000..479f533 --- /dev/null +++ b/Chips/Nxp/QoriqLs/Include/Library/DUart.h @@ -0,0 +1,133 @@ +/** DUart.h +* Header defining the DUART constants (Base addresses, sizes, flags) +* +* Based on Serial I/O Port library headers available in PL011Uart.h +* +* Copyright (c) 2011-2012, ARM Limited. All rights reserved. +* Copyright (c) 2016, Freescale Semiconductor, Inc. All rights reserved. +* +* This program and the accompanying materials +* are licensed and made available under the terms and conditions of the BSD License +* which accompanies this distribution. The full text of the license may be found at +* http://opensource.org/licenses/bsd-license.php +* +* THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, +* WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. +* +**/ + +#ifndef __DUART_H__ +#define __DUART_H__ + +#include <Uefi.h> +#include <Protocol/SerialIo.h> + +/* Register Definitions */ + + +// FIFO Control Register +#define DUART_FCR_FIFO_EN 0x01 /* Fifo enable */ +#define DUART_FCR_CLEAR_RCVR 0x02 /* Clear the RCVR FIFO */ +#define DUART_FCR_CLEAR_XMIT 0x04 /* Clear the XMIT FIFO */ +#define DUART_FCR_DMA_SELECT 0x08 /* For DMA applications */ +#define DUART_FCR_TRIGGER_MASK 0xC0 /* Mask for the FIFO trigger range */ +#define DUART_FCR_TRIGGER_1 0x00 /* Mask for trigger set at 1 */ +#define DUART_FCR_TRIGGER_4 0x40 /* Mask for trigger set at 4 */ +#define DUART_FCR_TRIGGER_8 0x80 /* Mask for trigger set at 8 */ +#define DUART_FCR_TRIGGER_14 0xC0 /* Mask for trigger set at 14 */ + +#define DUART_FCR_RXSR 0x02 /* Receiver soft reset */ +#define DUART_FCR_TXSR 0x04 /* Transmitter soft reset */ + +// Modem Control Register +#define DUART_MCR_DTR 0x01 /* Reserved */ +#define DUART_MCR_RTS 0x02 /* RTS */ +#define DUART_MCR_OUT1 0x04 /* Reserved */ +#define DUART_MCR_OUT2 0x08 /* Reserved */ +#define DUART_MCR_LOOP 0x10 /* Enable loopback test mode */ +#define DUART_MCR_AFE 0x20 /* AFE (Auto Flow Control) */ + +#define DUART_MCR_DMA_EN 0x04 +#define DUART_MCR_TX_DFR 0x08 + + +// Line Control Register +/* +* Note: if the word length is 5 bits (DUART_LCR_WLEN5), then setting +* DUART_LCR_STOP will select 1.5 stop bits, not 2 stop bits. +*/ +#define DUART_LCR_WLS_MSK 0x03 /* character length select mask */ +#define DUART_LCR_WLS_5 0x00 /* 5 bit character length */ +#define DUART_LCR_WLS_6 0x01 /* 6 bit character length */ +#define DUART_LCR_WLS_7 0x02 /* 7 bit character length */ +#define DUART_LCR_WLS_8 0x03 /* 8 bit character length */ +#define DUART_LCR_STB 0x04 /* # stop Bits, off=1, on=1.5 or 2) */ +#define DUART_LCR_PEN 0x08 /* Parity eneble */ +#define DUART_LCR_EPS 0x10 /* Even Parity Select */ +#define DUART_LCR_STKP 0x20 /* Stick Parity */ +#define DUART_LCR_SBRK 0x40 /* Set Break */ +#define DUART_LCR_BKSE 0x80 /* Bank select enable */ +#define DUART_LCR_DLAB 0x80 /* Divisor latch access bit */ + +// Line Status Register +#define DUART_LSR_DR 0x01 /* Data ready */ +#define DUART_LSR_OE 0x02 /* Overrun */ +#define DUART_LSR_PE 0x04 /* Parity error */ +#define DUART_LSR_FE 0x08 /* Framing error */ +#define DUART_LSR_BI 0x10 /* Break */ +#define DUART_LSR_THRE 0x20 /* Xmit holding register empty */ +#define DUART_LSR_TEMT 0x40 /* Xmitter empty */ +#define DUART_LSR_ERR 0x80 /* Error */ + +// Modem Status Register +#define DUART_MSR_DCTS 0x01 /* Delta CTS */ +#define DUART_MSR_DDSR 0x02 /* Reserved */ +#define DUART_MSR_TERI 0x04 /* Reserved */ +#define DUART_MSR_DDCD 0x08 /* Reserved */ +#define DUART_MSR_CTS 0x10 /* Clear to Send */ +#define DUART_MSR_DSR 0x20 /* Reserved */ +#define DUART_MSR_RI 0x40 /* Reserved */ +#define DUART_MSR_DCD 0x80 /* Reserved */ + +// Interrupt Identification Register +#define DUART_IIR_NO_INT 0x01 /* No interrupts pending */ +#define DUART_IIR_ID 0x06 /* Mask for the interrupt ID */ + +#define DUART_IIR_MSI 0x00 /* Modem status interrupt */ +#define DUART_IIR_THRI 0x02 /* Transmitter holding register empty */ +#define DUART_IIR_RDI 0x04 /* Receiver data interrupt */ +#define DUART_IIR_RLSI 0x06 /* Receiver line status interrupt */ + +// Interrupt Enable Register +#define DUART_IER_MSI 0x08 /* Enable Modem status interrupt */ +#define DUART_IER_RLSI 0x04 /* Enable receiver line status interrupt */ +#define DUART_IER_THRI 0x02 /* Enable Transmitter holding register int. */ +#define DUART_IER_RDI 0x01 /* Enable receiver data interrupt */ + +// LCR defaults +#define DUART_LCR_8N1 0x03 + +#define DUART_LCRVAL DUART_LCR_8N1 /* 8 data, 1 stop, no parity */ +#define DUART_MCRVAL (DUART_MCR_DTR | \ + DUART_MCR_RTS) /* RTS/DTR */ +#define DUART_FCRVAL (DUART_FCR_FIFO_EN | \ + DUART_FCR_RXSR | \ + DUART_FCR_TXSR) /* Clear & enable FIFOs */ + + +#define URBR 0x0 +#define UTHR 0x0 +#define UDLB 0x0 +#define UDMB 0x1 +#define UIER 0x1 +#define UIIR 0x2 +#define UFCR 0x2 +#define UAFR 0x2 +#define ULCR 0x3 +#define UMCR 0x4 +#define ULSR 0x5 +#define UMSR 0x6 +#define USCR 0x7 +#define UDSR 0x10 + +#endif /* __DUART_H__ */ diff --git a/Chips/Nxp/QoriqLs/Library/DUartPortLib/DUartPortLib.c b/Chips/Nxp/QoriqLs/Library/DUartPortLib/DUartPortLib.c new file mode 100644 index 0000000..8e999b4 --- /dev/null +++ b/Chips/Nxp/QoriqLs/Library/DUartPortLib/DUartPortLib.c @@ -0,0 +1,321 @@ +/** DuartPortLib.c + DUART (NS16550) library functions + + Based on Serial I/O Port library functions available in PL011SerialPortLib.c + + Copyright (c) 2008 - 2010, Apple Inc. All rights reserved.<BR> + Copyright (c) 2012 - 2013, ARM Ltd. All rights reserved.<BR> + Copyright (c) 2016, Freescale Semiconductor, Inc. All rights reserved. + + This program and the accompanying materials + are licensed and made available under the terms and conditions of the BSD License + which accompanies this distribution. The full text of the license may be found at + http://opensource.org/licenses/bsd-license.php + + THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, + WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. + +**/ + +#include <Base.h> + +#include <Library/IoLib.h> +#include <Library/PcdLib.h> +#include <Library/SerialPortLib.h> +#include <Library/DUart.h> + +extern UINT32 CalculateBaudDivisor(UINT64 *BaudRate); +STATIC CONST UINT32 mInvalidControlBits = (EFI_SERIAL_SOFTWARE_LOOPBACK_ENABLE | \ + EFI_SERIAL_DATA_TERMINAL_READY); + + +/** + + Assert or deassert the control signals on a serial port. + The following control signals are set according their bit settings : + . Request to Send + . Data Terminal Ready + + @param[in] Control The following bits are taken into account : + . EFI_SERIAL_REQUEST_TO_SEND : assert/deassert the + "Request To Send" control signal if this bit is + equal to one/zero. + . EFI_SERIAL_DATA_TERMINAL_READY : assert/deassert + the "Data Terminal Ready" control signal if this + bit is equal to one/zero. + . EFI_SERIAL_HARDWARE_LOOPBACK_ENABLE : enable/disable + the hardware loopback if this bit is equal to + one/zero. + . EFI_SERIAL_SOFTWARE_LOOPBACK_ENABLE : not supported. + . EFI_SERIAL_HARDWARE_FLOW_CONTROL_ENABLE : enable/ + disable the hardware flow control based on CTS (Clear + To Send) and RTS (Ready To Send) control signals. + + @retval RETURN_SUCCESS The new control bits were set on the device. + @retval RETURN_UNSUPPORTED The device does not support this operation. + +**/ +RETURN_STATUS +EFIAPI +SerialPortSetControl ( + IN UINT32 Control + ) +{ + UINT32 McrBits; + UINTN UartBase = (UINTN)PcdGet64 (PcdSerialRegisterBase); + + if (Control & (mInvalidControlBits)) { + return RETURN_UNSUPPORTED; + } + + McrBits = MmioRead8 (UartBase + UMCR); + + if (Control & EFI_SERIAL_REQUEST_TO_SEND) { + McrBits |= DUART_MCR_RTS; + } else { + McrBits &= ~DUART_MCR_RTS; + } + + if (Control & EFI_SERIAL_HARDWARE_LOOPBACK_ENABLE) { + McrBits |= DUART_MCR_LOOP; + } else { + McrBits &= ~DUART_MCR_LOOP; + } + + if (Control & EFI_SERIAL_HARDWARE_FLOW_CONTROL_ENABLE) { + McrBits |= DUART_MCR_AFE; + } else { + McrBits &= ~DUART_MCR_AFE; + } + + MmioWrite32 (UartBase + UMCR, McrBits); + + return RETURN_SUCCESS; +} + +/** + + Retrieve the status of the control bits on a serial device. + + @param[out] Control Status of the control bits on a serial device : + + . EFI_SERIAL_DATA_CLEAR_TO_SEND, + EFI_SERIAL_DATA_SET_READY, + EFI_SERIAL_RING_INDICATE, + EFI_SERIAL_CARRIER_DETECT, + EFI_SERIAL_REQUEST_TO_SEND, + EFI_SERIAL_DATA_TERMINAL_READY + are all related to the DTE (Data Terminal Equipment) + and DCE (Data Communication Equipment) modes of + operation of the serial device. + . EFI_SERIAL_INPUT_BUFFER_EMPTY : equal to one if the + receive buffer is empty, 0 otherwise. + . EFI_SERIAL_OUTPUT_BUFFER_EMPTY : equal to one if the + transmit buffer is empty, 0 otherwise. + . EFI_SERIAL_HARDWARE_LOOPBACK_ENABLE : equal to one if + the hardware loopback is enabled (the ouput feeds the + receive buffer), 0 otherwise. + . EFI_SERIAL_SOFTWARE_LOOPBACK_ENABLE : equal to one if + a loopback is accomplished by software, 0 otherwise. + . EFI_SERIAL_HARDWARE_FLOW_CONTROL_ENABLE : equal to + one if the hardware flow control based on CTS (Clear + To Send) and RTS (Ready To Send) control signals is + enabled, 0 otherwise. + + @retval RETURN_SUCCESS The control bits were read from the serial device. + +**/ +RETURN_STATUS +EFIAPI +SerialPortGetControl ( + OUT UINT32 *Control + ) +{ + UINT32 MsrRegister; + UINT32 McrRegister; + UINT32 LsrRegister; + UINTN UartBase = (UINTN)PcdGet64 (PcdSerialRegisterBase); + + MsrRegister = MmioRead8 (UartBase + UMSR); + McrRegister = MmioRead8 (UartBase + UMCR); + LsrRegister = MmioRead8 (UartBase + ULSR); + + *Control = 0; + + if ((MsrRegister & DUART_MSR_CTS) == DUART_MSR_CTS) { + *Control |= EFI_SERIAL_CLEAR_TO_SEND; + } + + if ((McrRegister & DUART_MCR_RTS) == DUART_MCR_RTS) { + *Control |= EFI_SERIAL_REQUEST_TO_SEND; + } + + if ((LsrRegister & DUART_LSR_TEMT) == DUART_LSR_TEMT) { + *Control |= EFI_SERIAL_OUTPUT_BUFFER_EMPTY; + } + + if ((McrRegister & DUART_MCR_AFE) == DUART_MCR_AFE) { + *Control |= EFI_SERIAL_HARDWARE_FLOW_CONTROL_ENABLE; + } + + if ((McrRegister & DUART_MCR_LOOP) == DUART_MCR_LOOP) { + *Control |= EFI_SERIAL_HARDWARE_LOOPBACK_ENABLE; + } + + return RETURN_SUCCESS; +} + +/** + + Programmed hardware of Serial port. + + @return Always return RETURN_UNSUPPORTED. + +**/ +RETURN_STATUS +EFIAPI +SerialPortInitialize ( + VOID + ) +{ + UINT64 BaudRate; + UINT32 BaudDivisor; + UINTN UartBase = (UINTN)PcdGet64 (PcdSerialRegisterBase); + + BaudRate = (UINTN)PcdGet64 (PcdUartDefaultBaudRate); + + BaudDivisor = CalculateBaudDivisor(&BaudRate); + + while (!(MmioRead8(UartBase + ULSR) & DUART_LSR_TEMT)) + ; + + MmioWrite8(UartBase + UIER, 0x1); + MmioWrite8(UartBase + ULCR, DUART_LCR_BKSE | DUART_LCRVAL); + MmioWrite8(UartBase + UDLB, 0); + MmioWrite8(UartBase + UDMB, 0); + MmioWrite8(UartBase + ULCR, DUART_LCRVAL); + MmioWrite8(UartBase + UMCR, DUART_MCRVAL); + MmioWrite8(UartBase + UFCR, DUART_FCRVAL); + MmioWrite8(UartBase + ULCR, DUART_LCR_BKSE | DUART_LCRVAL); + MmioWrite8(UartBase + UDLB, BaudDivisor & 0xff); + MmioWrite8(UartBase + UDMB, (BaudDivisor >> 8) & 0xff); + MmioWrite8(UartBase + ULCR, DUART_LCRVAL); + return RETURN_SUCCESS; +} + +/** + Write data to serial device. + + @param Buffer Point of data buffer which need to be written. + @param NumberOfBytes Number of output bytes which are cached in Buffer. + + @retval 0 Write data failed. + @retval !0 Actual number of bytes written to serial device. + +**/ +UINTN +EFIAPI +SerialPortWrite ( + IN UINT8 *Buffer, + IN UINTN NumberOfBytes + ) +{ + UINT8* CONST Final = &Buffer[NumberOfBytes]; + UINTN UartBase = (UINTN)PcdGet64 (PcdSerialRegisterBase); + + while (Buffer < Final) { + while ((MmioRead8(UartBase + ULSR) & DUART_LSR_THRE) == 0) + ; + MmioWrite8(UartBase + UTHR, *Buffer++); + } + + return NumberOfBytes; +} + +/** + Read data from serial device and save the data in buffer. + + @param Buffer Point of data buffer which need to be written. + @param NumberOfBytes Number of output bytes which are cached in Buffer. + + @retval 0 Read data failed. + @retval !0 Actual number of bytes read from serial device. + +**/ +UINTN +EFIAPI +SerialPortRead ( + OUT UINT8 *Buffer, + IN UINTN NumberOfBytes +) +{ + UINTN Count; + UINTN UartBase = (UINTN)PcdGet64 (PcdSerialRegisterBase); + + for (Count = 0; Count < NumberOfBytes; Count++, Buffer++) { + /* + * Loop while waiting for a new char(s) to arrive in the + * RxFIFO + */ + while ((MmioRead8(UartBase + ULSR) & DUART_LSR_DR) == 0); + + *Buffer = MmioRead8(UartBase + URBR); + } + + return NumberOfBytes; +} + +/** + Check to see if any data is available to be read from the debug device. + + @retval EFI_SUCCESS At least one byte of data is available to be read + @retval EFI_NOT_READY No data is available to be read + @retval EFI_DEVICE_ERROR The serial device is not functioning properly + +**/ +BOOLEAN +EFIAPI +SerialPortPoll ( + VOID + ) +{ + UINTN UartBase = (UINTN)PcdGet64 (PcdSerialRegisterBase); + return ((MmioRead8 (UartBase + ULSR) & DUART_LSR_DR) != 0); +} + +/** + Set new attributes to LS1043a. + + @param BaudRate The baud rate of the serial device. If the baud rate is not supported, + the speed will be reduced down to the nearest supported one and the + variable's value will be updated accordingly. + @param ReceiveFifoDepth The number of characters the device will buffer on input. If the specified + value is not supported, the variable's value will be reduced down to the + nearest supported one. + @param Timeout If applicable, the number of microseconds the device will wait + before timing out a Read or a Write operation. + @param Parity If applicable, this is the EFI_PARITY_TYPE that is computed or checked + as each character is transmitted or received. If the device does not + support parity, the value is the default parity value. + @param DataBits The number of data bits in each character + @param StopBits If applicable, the EFI_STOP_BITS_TYPE number of stop bits per character. + If the device does not support stop bits, the value is the default stop + bit value. + + @retval EFI_SUCCESS All attributes were set correctly on the serial device. + @retval EFI_INVALID_PARAMETERS One or more of the attributes has an unsupported value. + +**/ +RETURN_STATUS +EFIAPI +SerialPortSetAttributes ( + IN OUT UINT64 *BaudRate, + IN OUT UINT32 *ReceiveFifoDepth, + IN OUT UINT32 *Timeout, + IN OUT EFI_PARITY_TYPE *Parity, + IN OUT UINT8 *DataBits, + IN OUT EFI_STOP_BITS_TYPE *StopBits + ) +{ + return SerialPortInitialize (); +} diff --git a/Chips/Nxp/QoriqLs/Library/DUartPortLib/DUartPortLib.inf b/Chips/Nxp/QoriqLs/Library/DUartPortLib/DUartPortLib.inf new file mode 100644 index 0000000..e19ab62 --- /dev/null +++ b/Chips/Nxp/QoriqLs/Library/DUartPortLib/DUartPortLib.inf @@ -0,0 +1,43 @@ +#/** DUartPortLib.inf +# +# Component description file for DUartPortLib module +# +# Copyright (c) 2013, Freescale Ltd. All rights reserved. +# Author: Bhupesh Sharma bhupesh.sharma@nxp.com +# +# This program and the accompanying materials +# are licensed and made available under the terms and conditions of the BSD License +# which accompanies this distribution. The full text of the license may be found at +# http://opensource.org/licenses/bsd-license.php +# +# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, +# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. +# +#**/ + +[Defines] + INF_VERSION = 0x00010005 + BASE_NAME = DUartPortLib + FILE_GUID = 8ecefc8f-a2c4-4091-b80f-20f7aeb0567f + MODULE_TYPE = BASE + VERSION_STRING = 1.0 + LIBRARY_CLASS = SerialPortLib + +[Sources.common] + DUartPortLib.c + +[LibraryClasses] + ArmLib + PcdLib + SocLib + +[Packages] + EmbeddedPkg/EmbeddedPkg.dec + MdePkg/MdePkg.dec + MdeModulePkg/MdeModulePkg.dec + ArmPlatformPkg/ArmPlatformPkg.dec + OpenPlatformPkg/Chips/Nxp/QoriqLs/NxpQoriqLs.dec + +[Pcd] + gEfiMdeModulePkgTokenSpaceGuid.PcdSerialRegisterBase + gEfiMdePkgTokenSpaceGuid.PcdUartDefaultBaudRate
On 17 October 2016 at 21:04, Bhupesh Sharma bhupesh.sharma@freescale.com wrote:
From: Sakar Arora sakar.arora@nxp.com
LS1043A SoC houses a DUART (Dual UART) IP which has two UART ports. One of these UART ports is connected to the A53 CPUs and is used for console in and out functionality.
This patch adds the support of the DUART IP as a PEI library.
Signed-off-by: Sakar Arora sakar.arora@nxp.com Signed-off-by: Bhupesh Sharma bhupesh.sharma@nxp.com
Chips/Nxp/QoriqLs/Include/Library/DUart.h | 133 +++++++++ .../QoriqLs/Library/DUartPortLib/DUartPortLib.c | 321 +++++++++++++++++++++ .../QoriqLs/Library/DUartPortLib/DUartPortLib.inf | 43 +++ 3 files changed, 497 insertions(+) create mode 100644 Chips/Nxp/QoriqLs/Include/Library/DUart.h create mode 100644 Chips/Nxp/QoriqLs/Library/DUartPortLib/DUartPortLib.c create mode 100644 Chips/Nxp/QoriqLs/Library/DUartPortLib/DUartPortLib.inf
diff --git a/Chips/Nxp/QoriqLs/Include/Library/DUart.h b/Chips/Nxp/QoriqLs/Include/Library/DUart.h
If this is an internal header, keep it with the .c file
new file mode 100644 index 0000000..479f533 --- /dev/null +++ b/Chips/Nxp/QoriqLs/Include/Library/DUart.h @@ -0,0 +1,133 @@ +/** DUart.h +* Header defining the DUART constants (Base addresses, sizes, flags) +* +* Based on Serial I/O Port library headers available in PL011Uart.h +* +* Copyright (c) 2011-2012, ARM Limited. All rights reserved. +* Copyright (c) 2016, Freescale Semiconductor, Inc. All rights reserved. +* +* This program and the accompanying materials +* are licensed and made available under the terms and conditions of the BSD License +* which accompanies this distribution. The full text of the license may be found at +* http://opensource.org/licenses/bsd-license.php +* +* THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, +* WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. +* +**/
+#ifndef __DUART_H__ +#define __DUART_H__
+#include <Uefi.h> +#include <Protocol/SerialIo.h>
+/* Register Definitions */
+// FIFO Control Register +#define DUART_FCR_FIFO_EN 0x01 /* Fifo enable */ +#define DUART_FCR_CLEAR_RCVR 0x02 /* Clear the RCVR FIFO */ +#define DUART_FCR_CLEAR_XMIT 0x04 /* Clear the XMIT FIFO */ +#define DUART_FCR_DMA_SELECT 0x08 /* For DMA applications */ +#define DUART_FCR_TRIGGER_MASK 0xC0 /* Mask for the FIFO trigger range */ +#define DUART_FCR_TRIGGER_1 0x00 /* Mask for trigger set at 1 */ +#define DUART_FCR_TRIGGER_4 0x40 /* Mask for trigger set at 4 */ +#define DUART_FCR_TRIGGER_8 0x80 /* Mask for trigger set at 8 */ +#define DUART_FCR_TRIGGER_14 0xC0 /* Mask for trigger set at 14 */
+#define DUART_FCR_RXSR 0x02 /* Receiver soft reset */ +#define DUART_FCR_TXSR 0x04 /* Transmitter soft reset */
+// Modem Control Register +#define DUART_MCR_DTR 0x01 /* Reserved */ +#define DUART_MCR_RTS 0x02 /* RTS */ +#define DUART_MCR_OUT1 0x04 /* Reserved */ +#define DUART_MCR_OUT2 0x08 /* Reserved */ +#define DUART_MCR_LOOP 0x10 /* Enable loopback test mode */ +#define DUART_MCR_AFE 0x20 /* AFE (Auto Flow Control) */
+#define DUART_MCR_DMA_EN 0x04 +#define DUART_MCR_TX_DFR 0x08
+// Line Control Register +/* +* Note: if the word length is 5 bits (DUART_LCR_WLEN5), then setting +* DUART_LCR_STOP will select 1.5 stop bits, not 2 stop bits. +*/ +#define DUART_LCR_WLS_MSK 0x03 /* character length select mask */ +#define DUART_LCR_WLS_5 0x00 /* 5 bit character length */ +#define DUART_LCR_WLS_6 0x01 /* 6 bit character length */ +#define DUART_LCR_WLS_7 0x02 /* 7 bit character length */ +#define DUART_LCR_WLS_8 0x03 /* 8 bit character length */ +#define DUART_LCR_STB 0x04 /* # stop Bits, off=1, on=1.5 or 2) */ +#define DUART_LCR_PEN 0x08 /* Parity eneble */ +#define DUART_LCR_EPS 0x10 /* Even Parity Select */ +#define DUART_LCR_STKP 0x20 /* Stick Parity */ +#define DUART_LCR_SBRK 0x40 /* Set Break */ +#define DUART_LCR_BKSE 0x80 /* Bank select enable */ +#define DUART_LCR_DLAB 0x80 /* Divisor latch access bit */
+// Line Status Register +#define DUART_LSR_DR 0x01 /* Data ready */ +#define DUART_LSR_OE 0x02 /* Overrun */ +#define DUART_LSR_PE 0x04 /* Parity error */ +#define DUART_LSR_FE 0x08 /* Framing error */ +#define DUART_LSR_BI 0x10 /* Break */ +#define DUART_LSR_THRE 0x20 /* Xmit holding register empty */ +#define DUART_LSR_TEMT 0x40 /* Xmitter empty */ +#define DUART_LSR_ERR 0x80 /* Error */
+// Modem Status Register +#define DUART_MSR_DCTS 0x01 /* Delta CTS */ +#define DUART_MSR_DDSR 0x02 /* Reserved */ +#define DUART_MSR_TERI 0x04 /* Reserved */ +#define DUART_MSR_DDCD 0x08 /* Reserved */ +#define DUART_MSR_CTS 0x10 /* Clear to Send */ +#define DUART_MSR_DSR 0x20 /* Reserved */ +#define DUART_MSR_RI 0x40 /* Reserved */ +#define DUART_MSR_DCD 0x80 /* Reserved */
+// Interrupt Identification Register +#define DUART_IIR_NO_INT 0x01 /* No interrupts pending */ +#define DUART_IIR_ID 0x06 /* Mask for the interrupt ID */
+#define DUART_IIR_MSI 0x00 /* Modem status interrupt */ +#define DUART_IIR_THRI 0x02 /* Transmitter holding register empty */ +#define DUART_IIR_RDI 0x04 /* Receiver data interrupt */ +#define DUART_IIR_RLSI 0x06 /* Receiver line status interrupt */
+// Interrupt Enable Register +#define DUART_IER_MSI 0x08 /* Enable Modem status interrupt */ +#define DUART_IER_RLSI 0x04 /* Enable receiver line status interrupt */ +#define DUART_IER_THRI 0x02 /* Enable Transmitter holding register int. */ +#define DUART_IER_RDI 0x01 /* Enable receiver data interrupt */
+// LCR defaults +#define DUART_LCR_8N1 0x03
+#define DUART_LCRVAL DUART_LCR_8N1 /* 8 data, 1 stop, no parity */ +#define DUART_MCRVAL (DUART_MCR_DTR | \
DUART_MCR_RTS) /* RTS/DTR */
+#define DUART_FCRVAL (DUART_FCR_FIFO_EN | \
DUART_FCR_RXSR | \
DUART_FCR_TXSR) /* Clear & enable FIFOs */
+#define URBR 0x0 +#define UTHR 0x0 +#define UDLB 0x0 +#define UDMB 0x1 +#define UIER 0x1 +#define UIIR 0x2 +#define UFCR 0x2 +#define UAFR 0x2 +#define ULCR 0x3 +#define UMCR 0x4 +#define ULSR 0x5 +#define UMSR 0x6 +#define USCR 0x7 +#define UDSR 0x10
+#endif /* __DUART_H__ */ diff --git a/Chips/Nxp/QoriqLs/Library/DUartPortLib/DUartPortLib.c b/Chips/Nxp/QoriqLs/Library/DUartPortLib/DUartPortLib.c new file mode 100644 index 0000000..8e999b4 --- /dev/null +++ b/Chips/Nxp/QoriqLs/Library/DUartPortLib/DUartPortLib.c @@ -0,0 +1,321 @@ +/** DuartPortLib.c
- DUART (NS16550) library functions
- Based on Serial I/O Port library functions available in PL011SerialPortLib.c
- Copyright (c) 2008 - 2010, Apple Inc. All rights reserved.<BR>
- Copyright (c) 2012 - 2013, ARM Ltd. All rights reserved.<BR>
- Copyright (c) 2016, Freescale Semiconductor, Inc. All rights reserved.
- This program and the accompanying materials
- are licensed and made available under the terms and conditions of the BSD License
- which accompanies this distribution. The full text of the license may be found at
- http://opensource.org/licenses/bsd-license.php
- THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
- WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
+**/
+#include <Base.h>
+#include <Library/IoLib.h> +#include <Library/PcdLib.h> +#include <Library/SerialPortLib.h> +#include <Library/DUart.h>
+extern UINT32 CalculateBaudDivisor(UINT64 *BaudRate);
Where is this function defined? If it is in a separate library, include the appropriate header.
+STATIC CONST UINT32 mInvalidControlBits = (EFI_SERIAL_SOFTWARE_LOOPBACK_ENABLE | \
EFI_SERIAL_DATA_TERMINAL_READY);
+/**
- Assert or deassert the control signals on a serial port.
- The following control signals are set according their bit settings :
- . Request to Send
- . Data Terminal Ready
- @param[in] Control The following bits are taken into account :
. EFI_SERIAL_REQUEST_TO_SEND : assert/deassert the
"Request To Send" control signal if this bit is
equal to one/zero.
. EFI_SERIAL_DATA_TERMINAL_READY : assert/deassert
the "Data Terminal Ready" control signal if this
bit is equal to one/zero.
. EFI_SERIAL_HARDWARE_LOOPBACK_ENABLE : enable/disable
the hardware loopback if this bit is equal to
one/zero.
. EFI_SERIAL_SOFTWARE_LOOPBACK_ENABLE : not supported.
. EFI_SERIAL_HARDWARE_FLOW_CONTROL_ENABLE : enable/
disable the hardware flow control based on CTS (Clear
To Send) and RTS (Ready To Send) control signals.
- @retval RETURN_SUCCESS The new control bits were set on the device.
- @retval RETURN_UNSUPPORTED The device does not support this operation.
+**/ +RETURN_STATUS +EFIAPI +SerialPortSetControl (
- IN UINT32 Control
- )
+{
- UINT32 McrBits;
- UINTN UartBase = (UINTN)PcdGet64 (PcdSerialRegisterBase);
- if (Control & (mInvalidControlBits)) {
- return RETURN_UNSUPPORTED;
- }
- McrBits = MmioRead8 (UartBase + UMCR);
- if (Control & EFI_SERIAL_REQUEST_TO_SEND) {
- McrBits |= DUART_MCR_RTS;
- } else {
- McrBits &= ~DUART_MCR_RTS;
- }
- if (Control & EFI_SERIAL_HARDWARE_LOOPBACK_ENABLE) {
- McrBits |= DUART_MCR_LOOP;
- } else {
- McrBits &= ~DUART_MCR_LOOP;
- }
- if (Control & EFI_SERIAL_HARDWARE_FLOW_CONTROL_ENABLE) {
- McrBits |= DUART_MCR_AFE;
- } else {
- McrBits &= ~DUART_MCR_AFE;
- }
- MmioWrite32 (UartBase + UMCR, McrBits);
- return RETURN_SUCCESS;
+}
+/**
- Retrieve the status of the control bits on a serial device.
- @param[out] Control Status of the control bits on a serial device :
. EFI_SERIAL_DATA_CLEAR_TO_SEND,
EFI_SERIAL_DATA_SET_READY,
EFI_SERIAL_RING_INDICATE,
EFI_SERIAL_CARRIER_DETECT,
EFI_SERIAL_REQUEST_TO_SEND,
EFI_SERIAL_DATA_TERMINAL_READY
are all related to the DTE (Data Terminal Equipment)
and DCE (Data Communication Equipment) modes of
operation of the serial device.
. EFI_SERIAL_INPUT_BUFFER_EMPTY : equal to one if the
receive buffer is empty, 0 otherwise.
. EFI_SERIAL_OUTPUT_BUFFER_EMPTY : equal to one if the
transmit buffer is empty, 0 otherwise.
. EFI_SERIAL_HARDWARE_LOOPBACK_ENABLE : equal to one if
the hardware loopback is enabled (the ouput feeds the
receive buffer), 0 otherwise.
. EFI_SERIAL_SOFTWARE_LOOPBACK_ENABLE : equal to one if
a loopback is accomplished by software, 0 otherwise.
. EFI_SERIAL_HARDWARE_FLOW_CONTROL_ENABLE : equal to
one if the hardware flow control based on CTS (Clear
To Send) and RTS (Ready To Send) control signals is
enabled, 0 otherwise.
- @retval RETURN_SUCCESS The control bits were read from the serial device.
+**/ +RETURN_STATUS +EFIAPI +SerialPortGetControl (
- OUT UINT32 *Control
- )
+{
- UINT32 MsrRegister;
- UINT32 McrRegister;
- UINT32 LsrRegister;
- UINTN UartBase = (UINTN)PcdGet64 (PcdSerialRegisterBase);
- MsrRegister = MmioRead8 (UartBase + UMSR);
- McrRegister = MmioRead8 (UartBase + UMCR);
- LsrRegister = MmioRead8 (UartBase + ULSR);
- *Control = 0;
- if ((MsrRegister & DUART_MSR_CTS) == DUART_MSR_CTS) {
- *Control |= EFI_SERIAL_CLEAR_TO_SEND;
- }
- if ((McrRegister & DUART_MCR_RTS) == DUART_MCR_RTS) {
- *Control |= EFI_SERIAL_REQUEST_TO_SEND;
- }
- if ((LsrRegister & DUART_LSR_TEMT) == DUART_LSR_TEMT) {
- *Control |= EFI_SERIAL_OUTPUT_BUFFER_EMPTY;
- }
- if ((McrRegister & DUART_MCR_AFE) == DUART_MCR_AFE) {
- *Control |= EFI_SERIAL_HARDWARE_FLOW_CONTROL_ENABLE;
- }
- if ((McrRegister & DUART_MCR_LOOP) == DUART_MCR_LOOP) {
- *Control |= EFI_SERIAL_HARDWARE_LOOPBACK_ENABLE;
- }
- return RETURN_SUCCESS;
+}
+/**
- Programmed hardware of Serial port.
- @return Always return RETURN_UNSUPPORTED.
+**/ +RETURN_STATUS +EFIAPI +SerialPortInitialize (
- VOID
- )
+{
- UINT64 BaudRate;
UINT32 BaudDivisor;
UINTN UartBase = (UINTN)PcdGet64 (PcdSerialRegisterBase);
- BaudRate = (UINTN)PcdGet64 (PcdUartDefaultBaudRate);
BaudDivisor = CalculateBaudDivisor(&BaudRate);
while (!(MmioRead8(UartBase + ULSR) & DUART_LSR_TEMT))
;
MmioWrite8(UartBase + UIER, 0x1);
MmioWrite8(UartBase + ULCR, DUART_LCR_BKSE | DUART_LCRVAL);
MmioWrite8(UartBase + UDLB, 0);
MmioWrite8(UartBase + UDMB, 0);
MmioWrite8(UartBase + ULCR, DUART_LCRVAL);
MmioWrite8(UartBase + UMCR, DUART_MCRVAL);
MmioWrite8(UartBase + UFCR, DUART_FCRVAL);
MmioWrite8(UartBase + ULCR, DUART_LCR_BKSE | DUART_LCRVAL);
MmioWrite8(UartBase + UDLB, BaudDivisor & 0xff);
MmioWrite8(UartBase + UDMB, (BaudDivisor >> 8) & 0xff);
MmioWrite8(UartBase + ULCR, DUART_LCRVAL);
return RETURN_SUCCESS;
+}
+/**
- Write data to serial device.
- @param Buffer Point of data buffer which need to be written.
- @param NumberOfBytes Number of output bytes which are cached in Buffer.
- @retval 0 Write data failed.
- @retval !0 Actual number of bytes written to serial device.
+**/ +UINTN +EFIAPI +SerialPortWrite (
- IN UINT8 *Buffer,
- IN UINTN NumberOfBytes
- )
+{
UINT8* CONST Final = &Buffer[NumberOfBytes];
What is the point of this const? A constant value on the stack? Or did you mean 'UINT8 CONST *Final'? In either case, you can drop the const.
UINTN UartBase = (UINTN)PcdGet64 (PcdSerialRegisterBase);
while (Buffer < Final) {
while ((MmioRead8(UartBase + ULSR) & DUART_LSR_THRE) == 0)
;
MmioWrite8(UartBase + UTHR, *Buffer++);
}
return NumberOfBytes;
+}
+/**
- Read data from serial device and save the data in buffer.
- @param Buffer Point of data buffer which need to be written.
- @param NumberOfBytes Number of output bytes which are cached in Buffer.
- @retval 0 Read data failed.
- @retval !0 Actual number of bytes read from serial device.
+**/ +UINTN +EFIAPI +SerialPortRead (
- OUT UINT8 *Buffer,
- IN UINTN NumberOfBytes
+) +{
UINTN Count;
UINTN UartBase = (UINTN)PcdGet64 (PcdSerialRegisterBase);
for (Count = 0; Count < NumberOfBytes; Count++, Buffer++) {
/*
* Loop while waiting for a new char(s) to arrive in the
* RxFIFO
*/
while ((MmioRead8(UartBase + ULSR) & DUART_LSR_DR) == 0);
*Buffer = MmioRead8(UartBase + URBR);
}
return NumberOfBytes;
+}
+/**
- Check to see if any data is available to be read from the debug device.
- @retval EFI_SUCCESS At least one byte of data is available to be read
- @retval EFI_NOT_READY No data is available to be read
- @retval EFI_DEVICE_ERROR The serial device is not functioning properly
+**/ +BOOLEAN +EFIAPI +SerialPortPoll (
- VOID
- )
+{
UINTN UartBase = (UINTN)PcdGet64 (PcdSerialRegisterBase);
return ((MmioRead8 (UartBase + ULSR) & DUART_LSR_DR) != 0);
+}
+/**
- Set new attributes to LS1043a.
- @param BaudRate The baud rate of the serial device. If the baud rate is not supported,
the speed will be reduced down to the nearest supported one and the
variable's value will be updated accordingly.
- @param ReceiveFifoDepth The number of characters the device will buffer on input. If the specified
value is not supported, the variable's value will be reduced down to the
nearest supported one.
- @param Timeout If applicable, the number of microseconds the device will wait
before timing out a Read or a Write operation.
- @param Parity If applicable, this is the EFI_PARITY_TYPE that is computed or checked
as each character is transmitted or received. If the device does not
support parity, the value is the default parity value.
- @param DataBits The number of data bits in each character
- @param StopBits If applicable, the EFI_STOP_BITS_TYPE number of stop bits per character.
If the device does not support stop bits, the value is the default stop
bit value.
- @retval EFI_SUCCESS All attributes were set correctly on the serial device.
- @retval EFI_INVALID_PARAMETERS One or more of the attributes has an unsupported value.
+**/ +RETURN_STATUS +EFIAPI +SerialPortSetAttributes (
- IN OUT UINT64 *BaudRate,
- IN OUT UINT32 *ReceiveFifoDepth,
- IN OUT UINT32 *Timeout,
- IN OUT EFI_PARITY_TYPE *Parity,
- IN OUT UINT8 *DataBits,
- IN OUT EFI_STOP_BITS_TYPE *StopBits
- )
+{
- return SerialPortInitialize ();
+}
This looks wrong. Please explain in a comment why this makes sense (if it does)
diff --git a/Chips/Nxp/QoriqLs/Library/DUartPortLib/DUartPortLib.inf b/Chips/Nxp/QoriqLs/Library/DUartPortLib/DUartPortLib.inf new file mode 100644 index 0000000..e19ab62 --- /dev/null +++ b/Chips/Nxp/QoriqLs/Library/DUartPortLib/DUartPortLib.inf @@ -0,0 +1,43 @@ +#/** DUartPortLib.inf +# +# Component description file for DUartPortLib module +# +# Copyright (c) 2013, Freescale Ltd. All rights reserved. +# Author: Bhupesh Sharma bhupesh.sharma@nxp.com +# +# This program and the accompanying materials +# are licensed and made available under the terms and conditions of the BSD License +# which accompanies this distribution. The full text of the license may be found at +# http://opensource.org/licenses/bsd-license.php +# +# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, +# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. +# +#**/
+[Defines]
- INF_VERSION = 0x00010005
- BASE_NAME = DUartPortLib
- FILE_GUID = 8ecefc8f-a2c4-4091-b80f-20f7aeb0567f
Use a fresh GUID
- MODULE_TYPE = BASE
- VERSION_STRING = 1.0
- LIBRARY_CLASS = SerialPortLib
+[Sources.common]
- DUartPortLib.c
+[LibraryClasses]
- ArmLib
- PcdLib
SocLib
Indentation
+[Packages]
- EmbeddedPkg/EmbeddedPkg.dec
- MdePkg/MdePkg.dec
- MdeModulePkg/MdeModulePkg.dec
- ArmPlatformPkg/ArmPlatformPkg.dec
- OpenPlatformPkg/Chips/Nxp/QoriqLs/NxpQoriqLs.dec
+[Pcd]
- gEfiMdeModulePkgTokenSpaceGuid.PcdSerialRegisterBase
- gEfiMdePkgTokenSpaceGuid.PcdUartDefaultBaudRate
-- 1.9.1
Hi Ard,
Thanks for the review comments.
From: Ard Biesheuvel [mailto:ard.biesheuvel@linaro.org] Sent: Tuesday, October 18, 2016 3:05 PM
On 17 October 2016 at 21:04, Bhupesh Sharma bhupesh.sharma@freescale.com wrote:
From: Sakar Arora sakar.arora@nxp.com
LS1043A SoC houses a DUART (Dual UART) IP which has two UART ports. One of these UART ports is connected to the A53 CPUs and is used for console in and out functionality.
This patch adds the support of the DUART IP as a PEI library.
Signed-off-by: Sakar Arora sakar.arora@nxp.com Signed-off-by: Bhupesh Sharma bhupesh.sharma@nxp.com
Chips/Nxp/QoriqLs/Include/Library/DUart.h | 133 +++++++++ .../QoriqLs/Library/DUartPortLib/DUartPortLib.c | 321
+++++++++++++++++++++
.../QoriqLs/Library/DUartPortLib/DUartPortLib.inf | 43 +++ 3 files changed, 497 insertions(+) create mode 100644 Chips/Nxp/QoriqLs/Include/Library/DUart.h create mode 100644 Chips/Nxp/QoriqLs/Library/DUartPortLib/DUartPortLib.c create mode 100644 Chips/Nxp/QoriqLs/Library/DUartPortLib/DUartPortLib.inf
diff --git a/Chips/Nxp/QoriqLs/Include/Library/DUart.h b/Chips/Nxp/QoriqLs/Include/Library/DUart.h
If this is an internal header, keep it with the .c file
Ok.
new file mode 100644 index 0000000..479f533 --- /dev/null +++ b/Chips/Nxp/QoriqLs/Include/Library/DUart.h @@ -0,0 +1,133 @@ +/** DUart.h +* Header defining the DUART constants (Base addresses, sizes,
flags)
+* +* Based on Serial I/O Port library headers available in PL011Uart.h +* +* Copyright (c) 2011-2012, ARM Limited. All rights reserved. +* Copyright (c) 2016, Freescale Semiconductor, Inc. All rights
reserved.
+* +* This program and the accompanying materials +* are licensed and made available under the terms and conditions of +the BSD License +* which accompanies this distribution. The full text of the
license
+may be found at +* http://opensource.org/licenses/bsd-license.php +* +* THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" +BASIS, +* WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS
OR IMPLIED.
+* +**/
+#ifndef __DUART_H__ +#define __DUART_H__
+#include <Uefi.h> +#include <Protocol/SerialIo.h>
+/* Register Definitions */
+// FIFO Control Register +#define DUART_FCR_FIFO_EN 0x01 /* Fifo enable */ +#define DUART_FCR_CLEAR_RCVR 0x02 /* Clear the RCVR FIFO */ +#define DUART_FCR_CLEAR_XMIT 0x04 /* Clear the XMIT FIFO */ +#define DUART_FCR_DMA_SELECT 0x08 /* For DMA applications */ +#define DUART_FCR_TRIGGER_MASK 0xC0 /* Mask for the FIFO trigger
range */
+#define DUART_FCR_TRIGGER_1 0x00 /* Mask for trigger set at 1 */ +#define DUART_FCR_TRIGGER_4 0x40 /* Mask for trigger set at 4 */ +#define DUART_FCR_TRIGGER_8 0x80 /* Mask for trigger set at 8 */ +#define DUART_FCR_TRIGGER_14 0xC0 /* Mask for trigger set at 14 */
+#define DUART_FCR_RXSR 0x02 /* Receiver soft reset */ +#define DUART_FCR_TXSR 0x04 /* Transmitter soft reset */
+// Modem Control Register +#define DUART_MCR_DTR 0x01 /* Reserved */ +#define DUART_MCR_RTS 0x02 /* RTS */ +#define DUART_MCR_OUT1 0x04 /* Reserved */ +#define DUART_MCR_OUT2 0x08 /* Reserved */ +#define DUART_MCR_LOOP 0x10 /* Enable loopback test mode */ +#define DUART_MCR_AFE 0x20 /* AFE (Auto Flow Control) */
+#define DUART_MCR_DMA_EN 0x04 +#define DUART_MCR_TX_DFR 0x08
+// Line Control Register +/* +* Note: if the word length is 5 bits (DUART_LCR_WLEN5), then setting +* DUART_LCR_STOP will select 1.5 stop bits, not 2 stop bits. +*/ +#define DUART_LCR_WLS_MSK 0x03 /* character length select mask
*/
+#define DUART_LCR_WLS_5 0x00 /* 5 bit character
length */
+#define DUART_LCR_WLS_6 0x01 /* 6 bit character
length */
+#define DUART_LCR_WLS_7 0x02 /* 7 bit character
length */
+#define DUART_LCR_WLS_8 0x03 /* 8 bit character
length */
+#define DUART_LCR_STB 0x04 /* # stop Bits, off=1, on=1.5 or
- */
+#define DUART_LCR_PEN 0x08 /* Parity eneble */ +#define DUART_LCR_EPS 0x10 /* Even Parity Select */ +#define DUART_LCR_STKP 0x20 /* Stick Parity */ +#define DUART_LCR_SBRK 0x40 /* Set Break */ +#define DUART_LCR_BKSE 0x80 /* Bank select enable */ +#define DUART_LCR_DLAB 0x80 /* Divisor latch access bit */
+// Line Status Register +#define DUART_LSR_DR 0x01 /* Data ready */ +#define DUART_LSR_OE 0x02 /* Overrun */ +#define DUART_LSR_PE 0x04 /* Parity error */ +#define DUART_LSR_FE 0x08 /* Framing error */ +#define DUART_LSR_BI 0x10 /* Break */ +#define DUART_LSR_THRE 0x20 /* Xmit holding register
empty */
+#define DUART_LSR_TEMT 0x40 /* Xmitter empty */ +#define DUART_LSR_ERR 0x80 /* Error */
+// Modem Status Register +#define DUART_MSR_DCTS 0x01 /* Delta CTS */ +#define DUART_MSR_DDSR 0x02 /* Reserved */ +#define DUART_MSR_TERI 0x04 /* Reserved */ +#define DUART_MSR_DDCD 0x08 /* Reserved */ +#define DUART_MSR_CTS 0x10 /* Clear to Send */ +#define DUART_MSR_DSR 0x20 /* Reserved */ +#define DUART_MSR_RI 0x40 /* Reserved */ +#define DUART_MSR_DCD 0x80 /* Reserved */
+// Interrupt Identification Register +#define DUART_IIR_NO_INT 0x01 /* No interrupts pending */ +#define DUART_IIR_ID 0x06 /* Mask for the interrupt ID */
+#define DUART_IIR_MSI 0x00 /* Modem status interrupt */ +#define DUART_IIR_THRI 0x02 /* Transmitter holding register empty
*/
+#define DUART_IIR_RDI 0x04 /* Receiver data interrupt */ +#define DUART_IIR_RLSI 0x06 /* Receiver line status interrupt */
+// Interrupt Enable Register +#define DUART_IER_MSI 0x08 /* Enable Modem status interrupt */ +#define DUART_IER_RLSI 0x04 /* Enable receiver line status
interrupt */
+#define DUART_IER_THRI 0x02 /* Enable Transmitter holding
register int. */
+#define DUART_IER_RDI 0x01 /* Enable receiver data interrupt */
+// LCR defaults +#define DUART_LCR_8N1 0x03
+#define DUART_LCRVAL DUART_LCR_8N1 /* 8 data, 1 stop,
no parity */
+#define DUART_MCRVAL (DUART_MCR_DTR | \
DUART_MCR_RTS) /* RTS/DTR */
+#define DUART_FCRVAL (DUART_FCR_FIFO_EN | \
DUART_FCR_RXSR | \
DUART_FCR_TXSR) /* Clear & enable
FIFOs */
+#define URBR 0x0 +#define UTHR 0x0 +#define UDLB 0x0 +#define UDMB 0x1 +#define UIER 0x1 +#define UIIR 0x2 +#define UFCR 0x2 +#define UAFR 0x2 +#define ULCR 0x3 +#define UMCR 0x4 +#define ULSR 0x5 +#define UMSR 0x6 +#define USCR 0x7 +#define UDSR 0x10
+#endif /* __DUART_H__ */ diff --git a/Chips/Nxp/QoriqLs/Library/DUartPortLib/DUartPortLib.c b/Chips/Nxp/QoriqLs/Library/DUartPortLib/DUartPortLib.c new file mode 100644 index 0000000..8e999b4 --- /dev/null +++ b/Chips/Nxp/QoriqLs/Library/DUartPortLib/DUartPortLib.c @@ -0,0 +1,321 @@ +/** DuartPortLib.c
- DUART (NS16550) library functions
- Based on Serial I/O Port library functions available in
- PL011SerialPortLib.c
- Copyright (c) 2008 - 2010, Apple Inc. All rights reserved.<BR>
- Copyright (c) 2012 - 2013, ARM Ltd. All rights reserved.<BR>
- Copyright (c) 2016, Freescale Semiconductor, Inc. All rights
reserved.
- This program and the accompanying materials are licensed and made
- available under the terms and conditions of the BSD License which
- accompanies this distribution. The full text of the license may be
- found at http://opensource.org/licenses/bsd-license.php
- THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS"
- BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER
EXPRESS OR IMPLIED.
+**/
+#include <Base.h>
+#include <Library/IoLib.h> +#include <Library/PcdLib.h> +#include <Library/SerialPortLib.h> +#include <Library/DUart.h>
+extern UINT32 CalculateBaudDivisor(UINT64 *BaudRate);
Where is this function defined? If it is in a separate library, include the appropriate header.
Ok, I will add the appropriate header.
+STATIC CONST UINT32 mInvalidControlBits =
(EFI_SERIAL_SOFTWARE_LOOPBACK_ENABLE | \
+EFI_SERIAL_DATA_TERMINAL_READY);
+/**
- Assert or deassert the control signals on a serial port.
- The following control signals are set according their bit settings
:
- . Request to Send
- . Data Terminal Ready
- @param[in] Control The following bits are taken into account :
. EFI_SERIAL_REQUEST_TO_SEND :
assert/deassert the
"Request To Send" control signal if this
bit is
equal to one/zero.
. EFI_SERIAL_DATA_TERMINAL_READY :
assert/deassert
the "Data Terminal Ready" control signal
if this
bit is equal to one/zero.
. EFI_SERIAL_HARDWARE_LOOPBACK_ENABLE :
enable/disable
the hardware loopback if this bit is equal
to
one/zero.
. EFI_SERIAL_SOFTWARE_LOOPBACK_ENABLE : not
supported.
. EFI_SERIAL_HARDWARE_FLOW_CONTROL_ENABLE :
enable/
disable the hardware flow control based on
CTS (Clear
To Send) and RTS (Ready To Send) control
signals.
- @retval RETURN_SUCCESS The new control bits were set on the
device.
- @retval RETURN_UNSUPPORTED The device does not support this
operation.
+**/ +RETURN_STATUS +EFIAPI +SerialPortSetControl (
- IN UINT32 Control
- )
+{
- UINT32 McrBits;
- UINTN UartBase = (UINTN)PcdGet64 (PcdSerialRegisterBase);
- if (Control & (mInvalidControlBits)) {
- return RETURN_UNSUPPORTED;
- }
- McrBits = MmioRead8 (UartBase + UMCR);
- if (Control & EFI_SERIAL_REQUEST_TO_SEND) {
- McrBits |= DUART_MCR_RTS;
- } else {
- McrBits &= ~DUART_MCR_RTS;
- }
- if (Control & EFI_SERIAL_HARDWARE_LOOPBACK_ENABLE) {
- McrBits |= DUART_MCR_LOOP;
- } else {
- McrBits &= ~DUART_MCR_LOOP;
- }
- if (Control & EFI_SERIAL_HARDWARE_FLOW_CONTROL_ENABLE) {
- McrBits |= DUART_MCR_AFE;
- } else {
- McrBits &= ~DUART_MCR_AFE;
- }
- MmioWrite32 (UartBase + UMCR, McrBits);
- return RETURN_SUCCESS;
+}
+/**
- Retrieve the status of the control bits on a serial device.
- @param[out] Control Status of the control bits on a serial
device :
. EFI_SERIAL_DATA_CLEAR_TO_SEND,
EFI_SERIAL_DATA_SET_READY,
EFI_SERIAL_RING_INDICATE,
EFI_SERIAL_CARRIER_DETECT,
EFI_SERIAL_REQUEST_TO_SEND,
EFI_SERIAL_DATA_TERMINAL_READY
are all related to the DTE (Data Terminal
Equipment)
and DCE (Data Communication Equipment)
modes of
operation of the serial device.
. EFI_SERIAL_INPUT_BUFFER_EMPTY : equal to
one if the
receive buffer is empty, 0 otherwise.
. EFI_SERIAL_OUTPUT_BUFFER_EMPTY : equal to
one if the
transmit buffer is empty, 0 otherwise.
. EFI_SERIAL_HARDWARE_LOOPBACK_ENABLE :
equal to one if
the hardware loopback is enabled (the
ouput feeds the
receive buffer), 0 otherwise.
. EFI_SERIAL_SOFTWARE_LOOPBACK_ENABLE :
equal to one if
a loopback is accomplished by software, 0
otherwise.
. EFI_SERIAL_HARDWARE_FLOW_CONTROL_ENABLE :
equal to
one if the hardware flow control based on
CTS (Clear
To Send) and RTS (Ready To Send) control
signals is
enabled, 0 otherwise.
- @retval RETURN_SUCCESS The control bits were read from the serial
device.
+**/ +RETURN_STATUS +EFIAPI +SerialPortGetControl (
- OUT UINT32 *Control
- )
+{
- UINT32 MsrRegister;
- UINT32 McrRegister;
- UINT32 LsrRegister;
- UINTN UartBase = (UINTN)PcdGet64 (PcdSerialRegisterBase);
- MsrRegister = MmioRead8 (UartBase + UMSR); McrRegister =
MmioRead8
- (UartBase + UMCR); LsrRegister = MmioRead8 (UartBase + ULSR);
- *Control = 0;
- if ((MsrRegister & DUART_MSR_CTS) == DUART_MSR_CTS) {
- *Control |= EFI_SERIAL_CLEAR_TO_SEND; }
- if ((McrRegister & DUART_MCR_RTS) == DUART_MCR_RTS) {
- *Control |= EFI_SERIAL_REQUEST_TO_SEND; }
- if ((LsrRegister & DUART_LSR_TEMT) == DUART_LSR_TEMT) {
- *Control |= EFI_SERIAL_OUTPUT_BUFFER_EMPTY; }
- if ((McrRegister & DUART_MCR_AFE) == DUART_MCR_AFE) {
- *Control |= EFI_SERIAL_HARDWARE_FLOW_CONTROL_ENABLE;
- }
- if ((McrRegister & DUART_MCR_LOOP) == DUART_MCR_LOOP) {
- *Control |= EFI_SERIAL_HARDWARE_LOOPBACK_ENABLE;
- }
- return RETURN_SUCCESS;
+}
+/**
- Programmed hardware of Serial port.
- @return Always return RETURN_UNSUPPORTED.
+**/ +RETURN_STATUS +EFIAPI +SerialPortInitialize (
- VOID
- )
+{
- UINT64 BaudRate;
UINT32 BaudDivisor;
UINTN UartBase = (UINTN)PcdGet64 (PcdSerialRegisterBase);
- BaudRate = (UINTN)PcdGet64 (PcdUartDefaultBaudRate);
BaudDivisor = CalculateBaudDivisor(&BaudRate);
while (!(MmioRead8(UartBase + ULSR) & DUART_LSR_TEMT))
;
MmioWrite8(UartBase + UIER, 0x1);
MmioWrite8(UartBase + ULCR, DUART_LCR_BKSE | DUART_LCRVAL);
MmioWrite8(UartBase + UDLB, 0);
MmioWrite8(UartBase + UDMB, 0);
MmioWrite8(UartBase + ULCR, DUART_LCRVAL);
MmioWrite8(UartBase + UMCR, DUART_MCRVAL);
MmioWrite8(UartBase + UFCR, DUART_FCRVAL);
MmioWrite8(UartBase + ULCR, DUART_LCR_BKSE | DUART_LCRVAL);
MmioWrite8(UartBase + UDLB, BaudDivisor & 0xff);
MmioWrite8(UartBase + UDMB, (BaudDivisor >> 8) & 0xff);
MmioWrite8(UartBase + ULCR, DUART_LCRVAL);
return RETURN_SUCCESS;
+}
+/**
- Write data to serial device.
- @param Buffer Point of data buffer which need to be
written.
- @param NumberOfBytes Number of output bytes which are cached
in Buffer.
- @retval 0 Write data failed.
- @retval !0 Actual number of bytes written to serial
device.
+**/ +UINTN +EFIAPI +SerialPortWrite (
- IN UINT8 *Buffer,
- IN UINTN NumberOfBytes
- )
+{
UINT8* CONST Final = &Buffer[NumberOfBytes];
What is the point of this const? A constant value on the stack? Or did you mean 'UINT8 CONST *Final'? In either case, you can drop the const.
Ok.
UINTN UartBase = (UINTN)PcdGet64 (PcdSerialRegisterBase);
while (Buffer < Final) {
while ((MmioRead8(UartBase + ULSR) & DUART_LSR_THRE)
== 0)
;
MmioWrite8(UartBase + UTHR, *Buffer++);
}
return NumberOfBytes;
+}
+/**
- Read data from serial device and save the data in buffer.
- @param Buffer Point of data buffer which need to be
written.
- @param NumberOfBytes Number of output bytes which are cached
in Buffer.
- @retval 0 Read data failed.
- @retval !0 Actual number of bytes read from serial
device.
+**/ +UINTN +EFIAPI +SerialPortRead (
- OUT UINT8 *Buffer,
- IN UINTN NumberOfBytes
+) +{
UINTN Count;
UINTN UartBase = (UINTN)PcdGet64 (PcdSerialRegisterBase);
for (Count = 0; Count < NumberOfBytes; Count++, Buffer++) {
/*
* Loop while waiting for a new char(s) to arrive in
the
* RxFIFO
*/
while ((MmioRead8(UartBase + ULSR) & DUART_LSR_DR) ==
- 0);
*Buffer = MmioRead8(UartBase + URBR);
}
return NumberOfBytes;
+}
+/**
- Check to see if any data is available to be read from the debug
device.
- @retval EFI_SUCCESS At least one byte of data is available
to be read
- @retval EFI_NOT_READY No data is available to be read
- @retval EFI_DEVICE_ERROR The serial device is not functioning
- properly
+**/ +BOOLEAN +EFIAPI +SerialPortPoll (
- VOID
- )
+{
UINTN UartBase = (UINTN)PcdGet64 (PcdSerialRegisterBase);
return ((MmioRead8 (UartBase + ULSR) & DUART_LSR_DR) != 0); }
+/**
- Set new attributes to LS1043a.
- @param BaudRate The baud rate of the serial
device. If the baud rate is not supported,
the speed will be reduced down to
the nearest supported one and the
variable's value will be updated
accordingly.
- @param ReceiveFifoDepth The number of characters the
device will buffer on input. If the specified
value is not supported, the
variable's value will be reduced down to the
nearest supported one.
- @param Timeout If applicable, the number of
microseconds the device will wait
before timing out a Read or a
Write operation.
- @param Parity If applicable, this is the
EFI_PARITY_TYPE that is computed or checked
as each character is transmitted
or received. If the device does not
support parity, the value is the
default parity value.
- @param DataBits The number of data bits in each
character
- @param StopBits If applicable, the
EFI_STOP_BITS_TYPE number of stop bits per character.
If the device does not support
stop bits, the value is the default stop
bit value.
- @retval EFI_SUCCESS All attributes were set correctly
on the serial device.
- @retval EFI_INVALID_PARAMETERS One or more of the attributes has
an unsupported value.
+**/ +RETURN_STATUS +EFIAPI +SerialPortSetAttributes (
- IN OUT UINT64 *BaudRate,
- IN OUT UINT32 *ReceiveFifoDepth,
- IN OUT UINT32 *Timeout,
- IN OUT EFI_PARITY_TYPE *Parity,
- IN OUT UINT8 *DataBits,
- IN OUT EFI_STOP_BITS_TYPE *StopBits
- )
+{
- return SerialPortInitialize ();
+}
This looks wrong. Please explain in a comment why this makes sense (if it does)
Ok, I will change this as per the latest PL011 implementation.
diff --git a/Chips/Nxp/QoriqLs/Library/DUartPortLib/DUartPortLib.inf b/Chips/Nxp/QoriqLs/Library/DUartPortLib/DUartPortLib.inf new file mode 100644 index 0000000..e19ab62 --- /dev/null +++ b/Chips/Nxp/QoriqLs/Library/DUartPortLib/DUartPortLib.inf @@ -0,0 +1,43 @@ +#/** DUartPortLib.inf +# +# Component description file for DUartPortLib module # # Copyright +(c) 2013, Freescale Ltd. All rights reserved. +# Author: Bhupesh Sharma bhupesh.sharma@nxp.com # # This program +and the accompanying materials # are licensed and made available +under the terms and conditions of the BSD License # which +accompanies this distribution. The full text of the license may be +found at # http://opensource.org/licenses/bsd-license.php +# +# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" +BASIS, # WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER
EXPRESS OR IMPLIED.
+# +#**/
+[Defines]
- INF_VERSION = 0x00010005
- BASE_NAME = DUartPortLib
- FILE_GUID = 8ecefc8f-a2c4-4091-b80f-
20f7aeb0567f
Use a fresh GUID
Ok.
- MODULE_TYPE = BASE
- VERSION_STRING = 1.0
- LIBRARY_CLASS = SerialPortLib
+[Sources.common]
- DUartPortLib.c
+[LibraryClasses]
- ArmLib
- PcdLib
SocLib
Indentation
Ok.
+[Packages]
- EmbeddedPkg/EmbeddedPkg.dec
- MdePkg/MdePkg.dec
- MdeModulePkg/MdeModulePkg.dec
- ArmPlatformPkg/ArmPlatformPkg.dec
- OpenPlatformPkg/Chips/Nxp/QoriqLs/NxpQoriqLs.dec
+[Pcd]
- gEfiMdeModulePkgTokenSpaceGuid.PcdSerialRegisterBase
- gEfiMdePkgTokenSpaceGuid.PcdUartDefaultBaudRate
-- 1.9.1
Regards, Bhupesh
On Tue, Oct 18, 2016 at 01:34:04AM +0530, Bhupesh Sharma wrote:
From: Sakar Arora sakar.arora@nxp.com
LS1043A SoC houses a DUART (Dual UART) IP which has two UART ports. One of these UART ports is connected to the A53 CPUs and is used for console in and out functionality.
This patch adds the support of the DUART IP as a PEI library.
Signed-off-by: Sakar Arora sakar.arora@nxp.com Signed-off-by: Bhupesh Sharma bhupesh.sharma@nxp.com
Chips/Nxp/QoriqLs/Include/Library/DUart.h | 133 +++++++++ .../QoriqLs/Library/DUartPortLib/DUartPortLib.c | 321 +++++++++++++++++++++ .../QoriqLs/Library/DUartPortLib/DUartPortLib.inf | 43 +++ 3 files changed, 497 insertions(+) create mode 100644 Chips/Nxp/QoriqLs/Include/Library/DUart.h create mode 100644 Chips/Nxp/QoriqLs/Library/DUartPortLib/DUartPortLib.c create mode 100644 Chips/Nxp/QoriqLs/Library/DUartPortLib/DUartPortLib.inf
diff --git a/Chips/Nxp/QoriqLs/Include/Library/DUart.h b/Chips/Nxp/QoriqLs/Include/Library/DUart.h new file mode 100644 index 0000000..479f533 --- /dev/null +++ b/Chips/Nxp/QoriqLs/Include/Library/DUart.h @@ -0,0 +1,133 @@ +/** DUart.h +* Header defining the DUART constants (Base addresses, sizes, flags) +* +* Based on Serial I/O Port library headers available in PL011Uart.h +* +* Copyright (c) 2011-2012, ARM Limited. All rights reserved. +* Copyright (c) 2016, Freescale Semiconductor, Inc. All rights reserved. +* +* This program and the accompanying materials +* are licensed and made available under the terms and conditions of the BSD License +* which accompanies this distribution. The full text of the license may be found at +* http://opensource.org/licenses/bsd-license.php +* +* THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, +* WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. +* +**/
+#ifndef __DUART_H__ +#define __DUART_H__
+#include <Uefi.h> +#include <Protocol/SerialIo.h>
+/* Register Definitions */
+// FIFO Control Register +#define DUART_FCR_FIFO_EN 0x01 /* Fifo enable */ +#define DUART_FCR_CLEAR_RCVR 0x02 /* Clear the RCVR FIFO */ +#define DUART_FCR_CLEAR_XMIT 0x04 /* Clear the XMIT FIFO */ +#define DUART_FCR_DMA_SELECT 0x08 /* For DMA applications */ +#define DUART_FCR_TRIGGER_MASK 0xC0 /* Mask for the FIFO trigger range */ +#define DUART_FCR_TRIGGER_1 0x00 /* Mask for trigger set at 1 */ +#define DUART_FCR_TRIGGER_4 0x40 /* Mask for trigger set at 4 */ +#define DUART_FCR_TRIGGER_8 0x80 /* Mask for trigger set at 8 */ +#define DUART_FCR_TRIGGER_14 0xC0 /* Mask for trigger set at 14 */
+#define DUART_FCR_RXSR 0x02 /* Receiver soft reset */ +#define DUART_FCR_TXSR 0x04 /* Transmitter soft reset */
+// Modem Control Register +#define DUART_MCR_DTR 0x01 /* Reserved */ +#define DUART_MCR_RTS 0x02 /* RTS */ +#define DUART_MCR_OUT1 0x04 /* Reserved */ +#define DUART_MCR_OUT2 0x08 /* Reserved */ +#define DUART_MCR_LOOP 0x10 /* Enable loopback test mode */ +#define DUART_MCR_AFE 0x20 /* AFE (Auto Flow Control) */
+#define DUART_MCR_DMA_EN 0x04 +#define DUART_MCR_TX_DFR 0x08
+// Line Control Register +/* +* Note: if the word length is 5 bits (DUART_LCR_WLEN5), then setting +* DUART_LCR_STOP will select 1.5 stop bits, not 2 stop bits. +*/ +#define DUART_LCR_WLS_MSK 0x03 /* character length select mask */ +#define DUART_LCR_WLS_5 0x00 /* 5 bit character length */ +#define DUART_LCR_WLS_6 0x01 /* 6 bit character length */ +#define DUART_LCR_WLS_7 0x02 /* 7 bit character length */ +#define DUART_LCR_WLS_8 0x03 /* 8 bit character length */ +#define DUART_LCR_STB 0x04 /* # stop Bits, off=1, on=1.5 or 2) */ +#define DUART_LCR_PEN 0x08 /* Parity eneble */ +#define DUART_LCR_EPS 0x10 /* Even Parity Select */ +#define DUART_LCR_STKP 0x20 /* Stick Parity */ +#define DUART_LCR_SBRK 0x40 /* Set Break */ +#define DUART_LCR_BKSE 0x80 /* Bank select enable */ +#define DUART_LCR_DLAB 0x80 /* Divisor latch access bit */
+// Line Status Register +#define DUART_LSR_DR 0x01 /* Data ready */ +#define DUART_LSR_OE 0x02 /* Overrun */ +#define DUART_LSR_PE 0x04 /* Parity error */ +#define DUART_LSR_FE 0x08 /* Framing error */ +#define DUART_LSR_BI 0x10 /* Break */ +#define DUART_LSR_THRE 0x20 /* Xmit holding register empty */ +#define DUART_LSR_TEMT 0x40 /* Xmitter empty */ +#define DUART_LSR_ERR 0x80 /* Error */
+// Modem Status Register +#define DUART_MSR_DCTS 0x01 /* Delta CTS */ +#define DUART_MSR_DDSR 0x02 /* Reserved */ +#define DUART_MSR_TERI 0x04 /* Reserved */ +#define DUART_MSR_DDCD 0x08 /* Reserved */ +#define DUART_MSR_CTS 0x10 /* Clear to Send */ +#define DUART_MSR_DSR 0x20 /* Reserved */ +#define DUART_MSR_RI 0x40 /* Reserved */ +#define DUART_MSR_DCD 0x80 /* Reserved */
+// Interrupt Identification Register +#define DUART_IIR_NO_INT 0x01 /* No interrupts pending */ +#define DUART_IIR_ID 0x06 /* Mask for the interrupt ID */
+#define DUART_IIR_MSI 0x00 /* Modem status interrupt */ +#define DUART_IIR_THRI 0x02 /* Transmitter holding register empty */ +#define DUART_IIR_RDI 0x04 /* Receiver data interrupt */ +#define DUART_IIR_RLSI 0x06 /* Receiver line status interrupt */
+// Interrupt Enable Register +#define DUART_IER_MSI 0x08 /* Enable Modem status interrupt */ +#define DUART_IER_RLSI 0x04 /* Enable receiver line status interrupt */ +#define DUART_IER_THRI 0x02 /* Enable Transmitter holding register int. */ +#define DUART_IER_RDI 0x01 /* Enable receiver data interrupt */
+// LCR defaults +#define DUART_LCR_8N1 0x03
+#define DUART_LCRVAL DUART_LCR_8N1 /* 8 data, 1 stop, no parity */ +#define DUART_MCRVAL (DUART_MCR_DTR | \
DUART_MCR_RTS) /* RTS/DTR */
+#define DUART_FCRVAL (DUART_FCR_FIFO_EN | \
DUART_FCR_RXSR | \
DUART_FCR_TXSR) /* Clear & enable FIFOs */
+#define URBR 0x0 +#define UTHR 0x0 +#define UDLB 0x0 +#define UDMB 0x1 +#define UIER 0x1 +#define UIIR 0x2 +#define UFCR 0x2 +#define UAFR 0x2 +#define ULCR 0x3 +#define UMCR 0x4 +#define ULSR 0x5 +#define UMSR 0x6 +#define USCR 0x7 +#define UDSR 0x10
+#endif /* __DUART_H__ */ diff --git a/Chips/Nxp/QoriqLs/Library/DUartPortLib/DUartPortLib.c b/Chips/Nxp/QoriqLs/Library/DUartPortLib/DUartPortLib.c new file mode 100644 index 0000000..8e999b4 --- /dev/null +++ b/Chips/Nxp/QoriqLs/Library/DUartPortLib/DUartPortLib.c @@ -0,0 +1,321 @@ +/** DuartPortLib.c
- DUART (NS16550) library functions
- Based on Serial I/O Port library functions available in PL011SerialPortLib.c
- Copyright (c) 2008 - 2010, Apple Inc. All rights reserved.<BR>
- Copyright (c) 2012 - 2013, ARM Ltd. All rights reserved.<BR>
- Copyright (c) 2016, Freescale Semiconductor, Inc. All rights reserved.
- This program and the accompanying materials
- are licensed and made available under the terms and conditions of the BSD License
- which accompanies this distribution. The full text of the license may be found at
- http://opensource.org/licenses/bsd-license.php
- THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
- WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
+**/
+#include <Base.h>
+#include <Library/IoLib.h> +#include <Library/PcdLib.h> +#include <Library/SerialPortLib.h> +#include <Library/DUart.h>
Move DUart.h first in the Library/ block?
+extern UINT32 CalculateBaudDivisor(UINT64 *BaudRate);
This should be pulled in via a header.
+STATIC CONST UINT32 mInvalidControlBits = (EFI_SERIAL_SOFTWARE_LOOPBACK_ENABLE | \
EFI_SERIAL_DATA_TERMINAL_READY);
+/**
- Assert or deassert the control signals on a serial port.
- The following control signals are set according their bit settings :
- . Request to Send
- . Data Terminal Ready
- @param[in] Control The following bits are taken into account :
. EFI_SERIAL_REQUEST_TO_SEND : assert/deassert the
"Request To Send" control signal if this bit is
equal to one/zero.
. EFI_SERIAL_DATA_TERMINAL_READY : assert/deassert
the "Data Terminal Ready" control signal if this
bit is equal to one/zero.
. EFI_SERIAL_HARDWARE_LOOPBACK_ENABLE : enable/disable
the hardware loopback if this bit is equal to
one/zero.
. EFI_SERIAL_SOFTWARE_LOOPBACK_ENABLE : not supported.
. EFI_SERIAL_HARDWARE_FLOW_CONTROL_ENABLE : enable/
disable the hardware flow control based on CTS (Clear
To Send) and RTS (Ready To Send) control signals.
- @retval RETURN_SUCCESS The new control bits were set on the device.
- @retval RETURN_UNSUPPORTED The device does not support this operation.
+**/ +RETURN_STATUS +EFIAPI +SerialPortSetControl (
- IN UINT32 Control
- )
+{
- UINT32 McrBits;
- UINTN UartBase = (UINTN)PcdGet64 (PcdSerialRegisterBase);
- if (Control & (mInvalidControlBits)) {
- return RETURN_UNSUPPORTED;
- }
- McrBits = MmioRead8 (UartBase + UMCR);
- if (Control & EFI_SERIAL_REQUEST_TO_SEND) {
- McrBits |= DUART_MCR_RTS;
- } else {
- McrBits &= ~DUART_MCR_RTS;
- }
- if (Control & EFI_SERIAL_HARDWARE_LOOPBACK_ENABLE) {
- McrBits |= DUART_MCR_LOOP;
- } else {
- McrBits &= ~DUART_MCR_LOOP;
- }
- if (Control & EFI_SERIAL_HARDWARE_FLOW_CONTROL_ENABLE) {
- McrBits |= DUART_MCR_AFE;
- } else {
- McrBits &= ~DUART_MCR_AFE;
- }
- MmioWrite32 (UartBase + UMCR, McrBits);
- return RETURN_SUCCESS;
+}
+/**
- Retrieve the status of the control bits on a serial device.
- @param[out] Control Status of the control bits on a serial device :
. EFI_SERIAL_DATA_CLEAR_TO_SEND,
EFI_SERIAL_DATA_SET_READY,
EFI_SERIAL_RING_INDICATE,
EFI_SERIAL_CARRIER_DETECT,
EFI_SERIAL_REQUEST_TO_SEND,
EFI_SERIAL_DATA_TERMINAL_READY
are all related to the DTE (Data Terminal Equipment)
and DCE (Data Communication Equipment) modes of
operation of the serial device.
. EFI_SERIAL_INPUT_BUFFER_EMPTY : equal to one if the
receive buffer is empty, 0 otherwise.
. EFI_SERIAL_OUTPUT_BUFFER_EMPTY : equal to one if the
transmit buffer is empty, 0 otherwise.
. EFI_SERIAL_HARDWARE_LOOPBACK_ENABLE : equal to one if
the hardware loopback is enabled (the ouput feeds the
receive buffer), 0 otherwise.
. EFI_SERIAL_SOFTWARE_LOOPBACK_ENABLE : equal to one if
a loopback is accomplished by software, 0 otherwise.
. EFI_SERIAL_HARDWARE_FLOW_CONTROL_ENABLE : equal to
one if the hardware flow control based on CTS (Clear
To Send) and RTS (Ready To Send) control signals is
enabled, 0 otherwise.
- @retval RETURN_SUCCESS The control bits were read from the serial device.
+**/ +RETURN_STATUS +EFIAPI +SerialPortGetControl (
- OUT UINT32 *Control
- )
+{
- UINT32 MsrRegister;
- UINT32 McrRegister;
- UINT32 LsrRegister;
- UINTN UartBase = (UINTN)PcdGet64 (PcdSerialRegisterBase);
- MsrRegister = MmioRead8 (UartBase + UMSR);
- McrRegister = MmioRead8 (UartBase + UMCR);
- LsrRegister = MmioRead8 (UartBase + ULSR);
- *Control = 0;
- if ((MsrRegister & DUART_MSR_CTS) == DUART_MSR_CTS) {
No need for the == if (MsrRegister & DUART_MSR_CTS) { is sufficient. This applies to the tests below too.
- *Control |= EFI_SERIAL_CLEAR_TO_SEND;
- }
- if ((McrRegister & DUART_MCR_RTS) == DUART_MCR_RTS) {
- *Control |= EFI_SERIAL_REQUEST_TO_SEND;
- }
- if ((LsrRegister & DUART_LSR_TEMT) == DUART_LSR_TEMT) {
- *Control |= EFI_SERIAL_OUTPUT_BUFFER_EMPTY;
- }
- if ((McrRegister & DUART_MCR_AFE) == DUART_MCR_AFE) {
- *Control |= EFI_SERIAL_HARDWARE_FLOW_CONTROL_ENABLE;
- }
- if ((McrRegister & DUART_MCR_LOOP) == DUART_MCR_LOOP) {
- *Control |= EFI_SERIAL_HARDWARE_LOOPBACK_ENABLE;
- }
- return RETURN_SUCCESS;
+}
+/**
- Programmed hardware of Serial port.
- @return Always return RETURN_UNSUPPORTED.
+**/ +RETURN_STATUS +EFIAPI +SerialPortInitialize (
- VOID
- )
+{
- UINT64 BaudRate;
- UINT32 BaudDivisor;
- UINTN UartBase = (UINTN)PcdGet64 (PcdSerialRegisterBase);
- BaudRate = (UINTN)PcdGet64 (PcdUartDefaultBaudRate);
- BaudDivisor = CalculateBaudDivisor(&BaudRate);
- while (!(MmioRead8(UartBase + ULSR) & DUART_LSR_TEMT))
- ;
Move that ; up.
- MmioWrite8(UartBase + UIER, 0x1);
A #define for that 0x1 would be nice.
- MmioWrite8(UartBase + ULCR, DUART_LCR_BKSE | DUART_LCRVAL);
- MmioWrite8(UartBase + UDLB, 0);
- MmioWrite8(UartBase + UDMB, 0);
- MmioWrite8(UartBase + ULCR, DUART_LCRVAL);
- MmioWrite8(UartBase + UMCR, DUART_MCRVAL);
- MmioWrite8(UartBase + UFCR, DUART_FCRVAL);
- MmioWrite8(UartBase + ULCR, DUART_LCR_BKSE | DUART_LCRVAL);
- MmioWrite8(UartBase + UDLB, BaudDivisor & 0xff);
- MmioWrite8(UartBase + UDMB, (BaudDivisor >> 8) & 0xff);
- MmioWrite8(UartBase + ULCR, DUART_LCRVAL);
- return RETURN_SUCCESS;
+}
+/**
- Write data to serial device.
- @param Buffer Point of data buffer which need to be written.
- @param NumberOfBytes Number of output bytes which are cached in Buffer.
- @retval 0 Write data failed.
- @retval !0 Actual number of bytes written to serial device.
+**/ +UINTN +EFIAPI +SerialPortWrite (
- IN UINT8 *Buffer,
- IN UINTN NumberOfBytes
- )
+{
- UINT8* CONST Final = &Buffer[NumberOfBytes];
- UINTN UartBase = (UINTN)PcdGet64 (PcdSerialRegisterBase);
- while (Buffer < Final) {
while ((MmioRead8(UartBase + ULSR) & DUART_LSR_THRE) == 0)
;
Move that ; up.
MmioWrite8(UartBase + UTHR, *Buffer++);
- }
- return NumberOfBytes;
+}
+/**
- Read data from serial device and save the data in buffer.
- @param Buffer Point of data buffer which need to be written.
- @param NumberOfBytes Number of output bytes which are cached in Buffer.
- @retval 0 Read data failed.
- @retval !0 Actual number of bytes read from serial device.
+**/ +UINTN +EFIAPI +SerialPortRead (
- OUT UINT8 *Buffer,
- IN UINTN NumberOfBytes
+) +{
- UINTN Count;
- UINTN UartBase = (UINTN)PcdGet64 (PcdSerialRegisterBase);
- for (Count = 0; Count < NumberOfBytes; Count++, Buffer++) {
/*
* Loop while waiting for a new char(s) to arrive in the
* RxFIFO
*/
while ((MmioRead8(UartBase + ULSR) & DUART_LSR_DR) == 0);
*Buffer = MmioRead8(UartBase + URBR);
- }
- return NumberOfBytes;
+}
+/**
- Check to see if any data is available to be read from the debug device.
- @retval EFI_SUCCESS At least one byte of data is available to be read
- @retval EFI_NOT_READY No data is available to be read
- @retval EFI_DEVICE_ERROR The serial device is not functioning properly
+**/ +BOOLEAN +EFIAPI +SerialPortPoll (
- VOID
- )
+{
- UINTN UartBase = (UINTN)PcdGet64 (PcdSerialRegisterBase);
- return ((MmioRead8 (UartBase + ULSR) & DUART_LSR_DR) != 0);
+}
+/**
- Set new attributes to LS1043a.
Refer to the DUart rather than the device it's in?
- @param BaudRate The baud rate of the serial device. If the baud rate is not supported,
the speed will be reduced down to the nearest supported one and the
variable's value will be updated accordingly.
- @param ReceiveFifoDepth The number of characters the device will buffer on input. If the specified
value is not supported, the variable's value will be reduced down to the
nearest supported one.
- @param Timeout If applicable, the number of microseconds the device will wait
before timing out a Read or a Write operation.
- @param Parity If applicable, this is the EFI_PARITY_TYPE that is computed or checked
as each character is transmitted or received. If the device does not
support parity, the value is the default parity value.
- @param DataBits The number of data bits in each character
- @param StopBits If applicable, the EFI_STOP_BITS_TYPE number of stop bits per character.
If the device does not support stop bits, the value is the default stop
bit value.
- @retval EFI_SUCCESS All attributes were set correctly on the serial device.
- @retval EFI_INVALID_PARAMETERS One or more of the attributes has an unsupported value.
+**/ +RETURN_STATUS +EFIAPI +SerialPortSetAttributes (
- IN OUT UINT64 *BaudRate,
- IN OUT UINT32 *ReceiveFifoDepth,
- IN OUT UINT32 *Timeout,
- IN OUT EFI_PARITY_TYPE *Parity,
- IN OUT UINT8 *DataBits,
- IN OUT EFI_STOP_BITS_TYPE *StopBits
- )
+{
- return SerialPortInitialize ();
+} diff --git a/Chips/Nxp/QoriqLs/Library/DUartPortLib/DUartPortLib.inf b/Chips/Nxp/QoriqLs/Library/DUartPortLib/DUartPortLib.inf new file mode 100644 index 0000000..e19ab62 --- /dev/null +++ b/Chips/Nxp/QoriqLs/Library/DUartPortLib/DUartPortLib.inf @@ -0,0 +1,43 @@ +#/** DUartPortLib.inf +# +# Component description file for DUartPortLib module +# +# Copyright (c) 2013, Freescale Ltd. All rights reserved. +# Author: Bhupesh Sharma bhupesh.sharma@nxp.com +# +# This program and the accompanying materials +# are licensed and made available under the terms and conditions of the BSD License +# which accompanies this distribution. The full text of the license may be found at +# http://opensource.org/licenses/bsd-license.php +# +# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, +# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. +# +#**/
+[Defines]
- INF_VERSION = 0x00010005
- BASE_NAME = DUartPortLib
- FILE_GUID = 8ecefc8f-a2c4-4091-b80f-20f7aeb0567f
- MODULE_TYPE = BASE
- VERSION_STRING = 1.0
- LIBRARY_CLASS = SerialPortLib
+[Sources.common]
- DUartPortLib.c
+[LibraryClasses]
- ArmLib
- PcdLib
- SocLib
+[Packages]
- EmbeddedPkg/EmbeddedPkg.dec
- MdePkg/MdePkg.dec
- MdeModulePkg/MdeModulePkg.dec
- ArmPlatformPkg/ArmPlatformPkg.dec
- OpenPlatformPkg/Chips/Nxp/QoriqLs/NxpQoriqLs.dec
Sort the Packages?
+[Pcd]
- gEfiMdeModulePkgTokenSpaceGuid.PcdSerialRegisterBase
- gEfiMdePkgTokenSpaceGuid.PcdUartDefaultBaudRate
-- 1.9.1
From: Sakar Arora Sakar.Arora@nxp.com
This patch adds the functions that initialize the following IPs on the SoC:
* Central Security Unit (CSU) - Acts as a gatekeeper for secure and non-secure accesses via SW. * TrustZone Address Space Controller (TZC-380). * Interconnect (CCI-400). * PLLs and Clocks. * ARM Generic Timer.
In addition it also provides functions that print the following useful information: * CPU Info * SoC Personality. * Board Personality. * Reset Configuration Word (RCW). * SerDes selection.
Signed-off-by: Bhupesh Sharma bhupesh.sharma@nxp.com --- .../Nxp/LS1043aRdb/Include/Library/Ls1043aSerDes.h | 89 +++ Platforms/Nxp/LS1043aRdb/Include/Library/SocLib.h | 203 ++++++- .../LS1043aRdb/Library/LS1043aRdbLib/LS1043aRdb.c | 2 + .../Library/LS1043aSocLib/LS1043aSocLib.c | 674 ++++++++++++++++++++- .../Library/LS1043aSocLib/LS1043aSocLib.inf | 13 + .../LS1043aRdb/Library/LS1043aSocLib/LsSerDes.c | 195 ++++++ 6 files changed, 1169 insertions(+), 7 deletions(-) create mode 100644 Platforms/Nxp/LS1043aRdb/Include/Library/Ls1043aSerDes.h create mode 100644 Platforms/Nxp/LS1043aRdb/Library/LS1043aSocLib/LsSerDes.c
diff --git a/Platforms/Nxp/LS1043aRdb/Include/Library/Ls1043aSerDes.h b/Platforms/Nxp/LS1043aRdb/Include/Library/Ls1043aSerDes.h new file mode 100644 index 0000000..181c268 --- /dev/null +++ b/Platforms/Nxp/LS1043aRdb/Include/Library/Ls1043aSerDes.h @@ -0,0 +1,89 @@ +/** Ls1043aSerDes.h + The Header file of SerDes Module + + Copyright (c) 2016, Freescale Semiconductor, Inc. All rights reserved. + + This program and the accompanying materials + are licensed and made available under the terms and conditions of the BSD License + which accompanies this distribution. The full text of the license may be found + http://opensource.org/licenses/bsd-license.php + + THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, + WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. + +**/ + +#ifndef __LS1043A_SERDES_H +#define __LS1043A_SERDES_H + +#define SRDS_MAX_LANES 4 + +#define LS1043_RCWSR4_SRDS1_PRTCL_MASK 0xFFFF0000 +#define LS1043_RCWSR4_SRDS1_PRTCL_SHIFT 16 + +typedef enum { + NONE = 0, + PCIE1, + PCIE2, + PCIE3, + SATA1, + XFI1, + XFI2, + SGMII1, + SGMII2, + SGMII3, + SGMII4, + SGMII5, + SGMII6, + SGMII7, + SGMII8, + SGMII9, + QSGMII1, + QSGMII2, + SERDES_PRCTL_COUNT +} SrdsPrtcl; + +enum Srds { + FSL_SRDS_1 = 0, + FSL_SRDS_2 = 1 +}; + +struct SerDesConfig { + UINT16 Protocol; + UINT8 SrdsLane[SRDS_MAX_LANES]; +}; + +struct SerDesConfig SerDes1ConfigTbl[] = { + /* SerDes 1 */ + {0x1555, {XFI1, PCIE1, PCIE2, PCIE3 } }, + {0x1560, {XFI1, PCIE1, PCIE3, PCIE3 } }, + {0x1460, {XFI1, QSGMII1, PCIE3, PCIE3 } }, + {0x1360, {XFI1, SGMII2, PCIE3, PCIE3 } }, + {0x2555, {SGMII9, PCIE1, PCIE2, PCIE3 } }, + {0x4555, {QSGMII1, PCIE1, PCIE2, PCIE3 } }, + {0x4558, {QSGMII1, PCIE1, PCIE2, SATA1 } }, + {0x1355, {XFI1, SGMII2, PCIE2, PCIE3 } }, + {0x1335, {XFI1, SGMII2, SGMII5, PCIE3 } }, + {0x1333, {XFI1, SGMII2, SGMII5, SGMII6 } }, + {0x2355, {SGMII9, SGMII2, PCIE2, PCIE3 } }, + {0x2260, {SGMII9, SGMII2, PCIE3, PCIE3 } }, + {0x2235, {SGMII9, SGMII2, SGMII5, PCIE3 } }, + {0x2233, {SGMII9, SGMII2, SGMII5, SGMII6 } }, + {0x3335, {SGMII9, SGMII2, SGMII5, PCIE3 } }, + {0x3355, {SGMII9, SGMII2, PCIE2, PCIE3 } }, + {0x3358, {SGMII9, SGMII2, PCIE2, SATA1 } }, + {0x3360, {SGMII9, SGMII2, PCIE3, PCIE3 } }, + {0x3560, {SGMII9, PCIE1, PCIE3, PCIE3 } }, + {0x3555, {SGMII9, PCIE1, PCIE2, PCIE3 } }, + {0x7000, {PCIE1, PCIE1, PCIE1, PCIE1 } }, + {0x9998, {PCIE1, PCIE2, PCIE3, SATA1 } }, + {0x6058, {PCIE1, PCIE1, PCIE2, SATA1 } }, + {0x1455, {XFI1, QSGMII1, PCIE2, PCIE3 } }, + {0x2455, {SGMII9, QSGMII1, PCIE2, PCIE3 } }, + {0x2255, {SGMII9, SGMII2, PCIE2, PCIE3 } }, + {0x3333, {SGMII9, SGMII2, SGMII5, SGMII6 } }, + {0x3338, {SGMII9, SGMII2, SGMII5, SATA1 } }, + {} +}; + +#endif /* __LS1043A_SERDES_H */ diff --git a/Platforms/Nxp/LS1043aRdb/Include/Library/SocLib.h b/Platforms/Nxp/LS1043aRdb/Include/Library/SocLib.h index d1655d5..dc798b3 100644 --- a/Platforms/Nxp/LS1043aRdb/Include/Library/SocLib.h +++ b/Platforms/Nxp/LS1043aRdb/Include/Library/SocLib.h @@ -22,14 +22,72 @@ #define HWA_CGA_M2_CLK_SEL 0x00000007 #define HWA_CGA_M2_CLK_SHIFT 0
+#define TP_ITYP_AV 0x00000001 /* Initiator available */ +#define TP_ITYP_TYPE(x) (((x) & 0x6) >> 1) /* Initiator Type */ +#define TP_ITYP_TYPE_ARM 0x0 +#define TP_ITYP_TYPE_PPC 0x1 /* PowerPC */ +#define TP_ITYP_TYPE_OTHER 0x2 /* StarCore DSP */ +#define TP_ITYP_TYPE_HA 0x3 /* HW Accelerator */ +#define TP_ITYP_THDS(x) (((x) & 0x18) >> 3) /* # threads */ +#define TP_ITYP_VER(x) (((x) & 0xe0) >> 5) /* Initiator Version */ +#define TY_ITYP_VER_A53 0x2 + +#define TP_CLUSTER_EOC_MASK 0xc0000000 /* end of clusters mask */ +#define TP_CLUSTER_INIT_MASK 0x0000003f /* initiator mask */ +#define TP_INIT_PER_CLUSTER 4 + #define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
#define LS1043A_CLK_FREQ 100000000 #define LS1043A_DDR_CLK_FREQ 100000000
#define LS1043A_MAX_CPUS 4 +#define LS1043A_FMAN_V3 #define LS1043A_NUM_FMAN 1 +#define LS1043A_NUM_FM1_DTSEC 7 +#define LS1043A_NUM_FM1_10GEC 1 + +/* + * Divide positive or negative dividend by positive divisor and round + * to closest UINTNeger. Result is undefined for negative divisors and + * for negative dividends if the divisor variable type is unsigned. + */ +#define DIV_ROUND_CLOSEST(x, divisor)( \ +{ \ + typeof(x) __x = x; \ + typeof(divisor) __d = divisor; \ + (((typeof(x))-1) > 0 || \ + ((typeof(divisor))-1) > 0 || (__x) > 0) ? \ + (((__x) + ((__d) / 2)) / (__d)) : \ + (((__x) - ((__d) / 2)) / (__d)); \ +} \ +) + +/* + * HammingWeight32: returns the hamming weight (i.e. the number + * of bits set) of a 32-bit word + */ +static inline UINTN HammingWeight32(UINTN w) +{ + UINTN Res = (w & 0x55555555) + ((w >> 1) & 0x55555555); + Res = (Res & 0x33333333) + ((Res >> 2) & 0x33333333); + Res = (Res & 0x0F0F0F0F) + ((Res >> 4) & 0x0F0F0F0F); + Res = (Res & 0x00FF00FF) + ((Res >> 8) & 0x00FF00FF); + return (Res & 0x0000FFFF) + ((Res >> 16) & 0x0000FFFF); +} + +static inline UINTN CpuMaskNext(UINTN Cpu, UINTN Mask) +{ + for (Cpu++; !((1 << Cpu) & Mask); Cpu++) + ; + + return Cpu; +}
+#define ForEachCpu(iter, cpu, num_cpus, mask) \ + for (iter = 0, cpu = CpuMaskNext(-1, mask); \ + iter < num_cpus; \ + iter++, cpu = CpuMaskNext(cpu, mask)) \
struct SysInfo { UINTN FreqProcessor[LS1043A_MAX_CPUS]; @@ -41,9 +99,122 @@ struct SysInfo { UINTN FreqQman; };
+typedef struct SocClocks { + UINTN CpuClk; /* CPU clock in Hz! */ + UINTN BusClk; + UINTN MemClk; + UINTN PciClk; + UINTN SdhcClk; +} SocClockInfo; + +enum PeriphClock { + ARM_CLK = 0, + BUS_CLK, + UART_CLK, + ESDHC_CLK, + I2C_CLK, + DSPI_CLK, +}; + +enum CsuCslxAccess { + SEC_UNIT_NS_SUP_R = 0x08, + SEC_UNIT_NS_SUP_W = 0x80, + SEC_UNIT_NS_SUP_RW = 0x88, + SEC_UNIT_NS_USER_R = 0x04, + SEC_UNIT_NS_USER_W = 0x40, + SEC_UNIT_NS_USER_RW = 0x44, + SEC_UNIT_S_SUP_R = 0x02, + SEC_UNIT_S_SUP_W = 0x20, + SEC_UNIT_S_SUP_RW = 0x22, + SEC_UNIT_S_USER_R = 0x01, + SEC_UNIT_S_USER_W = 0x10, + SEC_UNIT_S_USER_RW = 0x11, + SEC_UNIT_ALL_RW = 0xff, +}; + +enum CsuCslxInd { + SEC_UNIT_CSLX_PCIE2_IO = 0, + SEC_UNIT_CSLX_PCIE1_IO, + SEC_UNIT_CSLX_MG2TPR_IP, + SEC_UNIT_CSLX_IFC_MEM, + SEC_UNIT_CSLX_OCRAM, + SEC_UNIT_CSLX_GIC, + SEC_UNIT_CSLX_PCIE1, + SEC_UNIT_CSLX_OCRAM2, + SEC_UNIT_CSLX_QSPI_MEM, + SEC_UNIT_CSLX_PCIE2, + SEC_UNIT_CSLX_SATA, + SEC_UNIT_CSLX_USB1, + SEC_UNIT_CSLX_QM_BM_SWPORTAL, + SEC_UNIT_CSLX_PCIE3 = 16, + SEC_UNIT_CSLX_PCIE3_IO, + SEC_UNIT_CSLX_USB3 = 20, + SEC_UNIT_CSLX_USB2, + SEC_UNIT_CSLX_SERDES = 32, + SEC_UNIT_CSLX_QDMA, + SEC_UNIT_CSLX_LPUART2, + SEC_UNIT_CSLX_LPUART1, + SEC_UNIT_CSLX_LPUART4, + SEC_UNIT_CSLX_LPUART3, + SEC_UNIT_CSLX_LPUART6, + SEC_UNIT_CSLX_LPUART5, + SEC_UNIT_CSLX_DSPI1 = 41, + SEC_UNIT_CSLX_QSPI, + SEC_UNIT_CSLX_ESDHC, + SEC_UNIT_CSLX_IFC = 45, + SEC_UNIT_CSLX_I2C1, + SEC_UNIT_CSLX_I2C3 = 48, + SEC_UNIT_CSLX_I2C2, + SEC_UNIT_CSLX_DUART2 = 50, + SEC_UNIT_CSLX_DUART1, + SEC_UNIT_CSLX_WDT2, + SEC_UNIT_CSLX_WDT1, + SEC_UNIT_CSLX_EDMA, + SEC_UNIT_CSLX_SYS_CNT, + SEC_UNIT_CSLX_DMA_MUX2, + SEC_UNIT_CSLX_DMA_MUX1, + SEC_UNIT_CSLX_DDR, + SEC_UNIT_CSLX_QUICC, + SEC_UNIT_CSLX_DCFG_CCU_RCPM = 60, + SEC_UNIT_CSLX_SECURE_BOOTROM, + SEC_UNIT_CSLX_SFP, + SEC_UNIT_CSLX_TMU, + SEC_UNIT_CSLX_SECURE_MONITOR, + SEC_UNIT_CSLX_SCFG, + SEC_UNIT_CSLX_FM = 66, + SEC_UNIT_CSLX_SEC5_5, + SEC_UNIT_CSLX_BM, + SEC_UNIT_CSLX_QM, + SEC_UNIT_CSLX_GPIO2 = 70, + SEC_UNIT_CSLX_GPIO1, + SEC_UNIT_CSLX_GPIO4, + SEC_UNIT_CSLX_GPIO3, + SEC_UNIT_CSLX_PLATFORM_CONT, + SEC_UNIT_CSLX_SEC_UNIT, + SEC_UNIT_CSLX_IIC4 = 77, + SEC_UNIT_CSLX_WDT4, + SEC_UNIT_CSLX_WDT3, + SEC_UNIT_CSLX_WDT5 = 81, + SEC_UNIT_CSLX_FTM2 = 86, + SEC_UNIT_CSLX_FTM1, + SEC_UNIT_CSLX_FTM4, + SEC_UNIT_CSLX_FTM3, + SEC_UNIT_CSLX_FTM6 = 90, + SEC_UNIT_CSLX_FTM5, + SEC_UNIT_CSLX_FTM8, + SEC_UNIT_CSLX_FTM7, + SEC_UNIT_CSLX_DSCR = 120, +}; + +struct CsuNsDev { + UINTN Ind; + UINT32 Val; +}; + /* Device Configuration and Pin Control */ struct CcsrGur { UINT32 porsr1; /* POR status 1 */ +#define FSL_CHASSIS2_CCSR_PORSR1_RCW_MASK 0xFF800000 UINT32 porsr2; /* POR status 2 */ UINT8 res_008[0x20-0x8]; UINT32 gpporcr1; /* General-purpose POR configuration */ @@ -51,6 +222,18 @@ struct CcsrGur { UINT32 dcfg_fusesr; /* Fuse status register */ UINT8 res_02c[0x70-0x2c]; UINT32 devdisr; /* Device disable control */ +#define FSL_CHASSIS2_DEVDISR2_DTSEC1_1 0x80000000 +#define FSL_CHASSIS2_DEVDISR2_DTSEC1_2 0x40000000 +#define FSL_CHASSIS2_DEVDISR2_DTSEC1_3 0x20000000 +#define FSL_CHASSIS2_DEVDISR2_DTSEC1_4 0x10000000 +#define FSL_CHASSIS2_DEVDISR2_DTSEC1_5 0x08000000 +#define FSL_CHASSIS2_DEVDISR2_DTSEC1_6 0x04000000 +#define FSL_CHASSIS2_DEVDISR2_DTSEC1_9 0x00800000 +#define FSL_CHASSIS2_DEVDISR2_DTSEC1_10 0x00400000 +#define FSL_CHASSIS2_DEVDISR2_10GEC1_1 0x00800000 +#define FSL_CHASSIS2_DEVDISR2_10GEC1_2 0x00400000 +#define FSL_CHASSIS2_DEVDISR2_10GEC1_3 0x80000000 +#define FSL_CHASSIS2_DEVDISR2_10GEC1_4 0x40000000 UINT32 devdisr2; /* Device disable control 2 */ UINT32 devdisr3; /* Device disable control 3 */ UINT32 devdisr4; /* Device disable control 4 */ @@ -83,6 +266,8 @@ struct CcsrGur { #define FSL_CHASSIS2_RCWSR0_SYS_PLL_RAT_MASK 0x1f #define FSL_CHASSIS2_RCWSR0_MEM_PLL_RAT_SHIFT 16 #define FSL_CHASSIS2_RCWSR0_MEM_PLL_RAT_MASK 0x3f +#define FSL_CHASSIS2_RCWSR4_SRDS1_PRTCL_MASK 0xffff0000 +#define FSL_CHASSIS2_RCWSR4_SRDS1_PRTCL_SHIFT 16 UINT8 res_140[0x200-0x140]; UINT32 scratchrw[4]; /* Scratch Read/Write */ UINT8 res_210[0x300-0x210]; @@ -259,6 +444,12 @@ struct CcsrClk { UINT8 res_c24[0x3dc]; };
+#define CCI400_CTRLORD_TERM_BARRIER 0x00000008 +#define CCI400_CTRLORD_EN_BARRIER 0 +#define CCI400_SHAORD_NON_SHAREABLE 0x00000002 +#define CCI400_DVM_MESSAGE_REQ_EN 0x00000002 +#define CCI400_SNOOP_REQ_EN 0x00000001 + /* CCI-400 registers */ struct CcsrCci400 { UINT32 ctrl_ord; /* Control Override */ @@ -301,8 +492,18 @@ struct CcsrCci400 { UINT8 res_e004[0x10000 - 0xe004]; };
+VOID EnableDevicesNsAccess(struct CsuNsDev *NonSecureDevices, UINT32 Num); + +VOID GetSysInfo(struct SysInfo *PtrSysInfo); + +VOID SocInit(VOID); + +VOID SerDesInit(VOID); + +VOID FdtCpuSetup(VOID *Blob); + UINT32 CalculateBaudDivisor(OUT UINT64 *BaudRate); -UINT32 CalculateI2cClockRate(VOID);
+UINT32 CalculateI2cClockRate(VOID);
#endif /* __LS1043A_SOC_H__ */ diff --git a/Platforms/Nxp/LS1043aRdb/Library/LS1043aRdbLib/LS1043aRdb.c b/Platforms/Nxp/LS1043aRdb/Library/LS1043aRdbLib/LS1043aRdb.c index 4fcb8a3..7c64709 100644 --- a/Platforms/Nxp/LS1043aRdb/Library/LS1043aRdbLib/LS1043aRdb.c +++ b/Platforms/Nxp/LS1043aRdb/Library/LS1043aRdbLib/LS1043aRdb.c @@ -24,6 +24,7 @@ #include <Library/PcdLib.h> #include <Ppi/ArmMpCoreInfo.h> #include <Library/PlatformLib.h> +#include <Library/SocLib.h>
/** Return the current Boot Mode @@ -47,6 +48,7 @@ ArmPlatformInitialize ( IN UINTN MpId ) { + SocInit(); return RETURN_SUCCESS; }
diff --git a/Platforms/Nxp/LS1043aRdb/Library/LS1043aSocLib/LS1043aSocLib.c b/Platforms/Nxp/LS1043aRdb/Library/LS1043aSocLib/LS1043aSocLib.c index fdeae08..2a7cb38 100644 --- a/Platforms/Nxp/LS1043aRdb/Library/LS1043aSocLib/LS1043aSocLib.c +++ b/Platforms/Nxp/LS1043aRdb/Library/LS1043aSocLib/LS1043aSocLib.c @@ -26,20 +26,227 @@ #include <Library/DebugAgentLib.h> #include <Library/IoLib.h> #include <Library/PrintLib.h> +#include <Library/SerialPortLib.h> +#include <Library/FslIfc.h>
+#include <Drivers/ArmTrustzone.h>
#include <Library/PlatformLib.h> #include <Library/SocLib.h> #include <Library/CpldLib.h>
+#include <libfdt.h> + +/* Global Clock Information pointer */ +static SocClockInfo gClkInfo; + +static struct CsuNsDev NonSecureDevices[] = +{ + {SEC_UNIT_CSLX_PCIE2_IO, SEC_UNIT_ALL_RW}, + {SEC_UNIT_CSLX_PCIE1_IO, SEC_UNIT_ALL_RW}, + {SEC_UNIT_CSLX_MG2TPR_IP, SEC_UNIT_ALL_RW}, + {SEC_UNIT_CSLX_IFC_MEM, SEC_UNIT_ALL_RW}, + {SEC_UNIT_CSLX_OCRAM, SEC_UNIT_ALL_RW}, + {SEC_UNIT_CSLX_GIC, SEC_UNIT_ALL_RW}, + {SEC_UNIT_CSLX_PCIE1, SEC_UNIT_ALL_RW}, + {SEC_UNIT_CSLX_OCRAM2, SEC_UNIT_ALL_RW}, + {SEC_UNIT_CSLX_QSPI_MEM, SEC_UNIT_ALL_RW}, + {SEC_UNIT_CSLX_PCIE2, SEC_UNIT_ALL_RW}, + {SEC_UNIT_CSLX_SATA, SEC_UNIT_ALL_RW}, + {SEC_UNIT_CSLX_USB1, SEC_UNIT_ALL_RW}, + {SEC_UNIT_CSLX_QM_BM_SWPORTAL, SEC_UNIT_ALL_RW}, + {SEC_UNIT_CSLX_PCIE3, SEC_UNIT_ALL_RW}, + {SEC_UNIT_CSLX_PCIE3_IO, SEC_UNIT_ALL_RW}, + {SEC_UNIT_CSLX_USB3, SEC_UNIT_ALL_RW}, + {SEC_UNIT_CSLX_USB2, SEC_UNIT_ALL_RW}, + {SEC_UNIT_CSLX_SERDES, SEC_UNIT_ALL_RW}, + {SEC_UNIT_CSLX_QDMA, SEC_UNIT_ALL_RW}, + {SEC_UNIT_CSLX_LPUART2, SEC_UNIT_ALL_RW}, + {SEC_UNIT_CSLX_LPUART1, SEC_UNIT_ALL_RW}, + {SEC_UNIT_CSLX_LPUART4, SEC_UNIT_ALL_RW}, + {SEC_UNIT_CSLX_LPUART3, SEC_UNIT_ALL_RW}, + {SEC_UNIT_CSLX_LPUART6, SEC_UNIT_ALL_RW}, + {SEC_UNIT_CSLX_LPUART5, SEC_UNIT_ALL_RW}, + {SEC_UNIT_CSLX_DSPI1, SEC_UNIT_ALL_RW}, + {SEC_UNIT_CSLX_QSPI, SEC_UNIT_ALL_RW}, + {SEC_UNIT_CSLX_ESDHC, SEC_UNIT_ALL_RW}, + {SEC_UNIT_CSLX_IFC, SEC_UNIT_ALL_RW}, + {SEC_UNIT_CSLX_I2C1, SEC_UNIT_ALL_RW}, + {SEC_UNIT_CSLX_I2C3, SEC_UNIT_ALL_RW}, + {SEC_UNIT_CSLX_I2C2, SEC_UNIT_ALL_RW}, + {SEC_UNIT_CSLX_DUART2, SEC_UNIT_ALL_RW}, + {SEC_UNIT_CSLX_DUART1, SEC_UNIT_ALL_RW}, + {SEC_UNIT_CSLX_WDT2, SEC_UNIT_ALL_RW}, + {SEC_UNIT_CSLX_WDT1, SEC_UNIT_ALL_RW}, + {SEC_UNIT_CSLX_EDMA, SEC_UNIT_ALL_RW}, + {SEC_UNIT_CSLX_SYS_CNT, SEC_UNIT_ALL_RW}, + {SEC_UNIT_CSLX_DMA_MUX2, SEC_UNIT_ALL_RW}, + {SEC_UNIT_CSLX_DMA_MUX1, SEC_UNIT_ALL_RW}, + {SEC_UNIT_CSLX_DDR, SEC_UNIT_ALL_RW}, + {SEC_UNIT_CSLX_QUICC, SEC_UNIT_ALL_RW}, + {SEC_UNIT_CSLX_DCFG_CCU_RCPM, SEC_UNIT_ALL_RW}, + {SEC_UNIT_CSLX_SECURE_BOOTROM, SEC_UNIT_ALL_RW}, + {SEC_UNIT_CSLX_SFP, SEC_UNIT_ALL_RW}, + {SEC_UNIT_CSLX_TMU, SEC_UNIT_ALL_RW}, + {SEC_UNIT_CSLX_SECURE_MONITOR, SEC_UNIT_ALL_RW}, + {SEC_UNIT_CSLX_SCFG, SEC_UNIT_ALL_RW}, + {SEC_UNIT_CSLX_FM, SEC_UNIT_ALL_RW}, + {SEC_UNIT_CSLX_SEC5_5, SEC_UNIT_ALL_RW}, + {SEC_UNIT_CSLX_BM, SEC_UNIT_ALL_RW}, + {SEC_UNIT_CSLX_QM, SEC_UNIT_ALL_RW}, + {SEC_UNIT_CSLX_GPIO2, SEC_UNIT_ALL_RW}, + {SEC_UNIT_CSLX_GPIO1, SEC_UNIT_ALL_RW}, + {SEC_UNIT_CSLX_GPIO4, SEC_UNIT_ALL_RW}, + {SEC_UNIT_CSLX_GPIO3, SEC_UNIT_ALL_RW}, + {SEC_UNIT_CSLX_PLATFORM_CONT, SEC_UNIT_ALL_RW}, + {SEC_UNIT_CSLX_SEC_UNIT, SEC_UNIT_ALL_RW}, + {SEC_UNIT_CSLX_IIC4, SEC_UNIT_ALL_RW}, + {SEC_UNIT_CSLX_WDT4, SEC_UNIT_ALL_RW}, + {SEC_UNIT_CSLX_WDT3, SEC_UNIT_ALL_RW}, + {SEC_UNIT_CSLX_WDT5, SEC_UNIT_ALL_RW}, + {SEC_UNIT_CSLX_FTM2, SEC_UNIT_ALL_RW}, + {SEC_UNIT_CSLX_FTM1, SEC_UNIT_ALL_RW}, + {SEC_UNIT_CSLX_FTM4, SEC_UNIT_ALL_RW}, + {SEC_UNIT_CSLX_FTM3, SEC_UNIT_ALL_RW}, + {SEC_UNIT_CSLX_FTM6, SEC_UNIT_ALL_RW}, + {SEC_UNIT_CSLX_FTM5, SEC_UNIT_ALL_RW}, + {SEC_UNIT_CSLX_FTM8, SEC_UNIT_ALL_RW}, + {SEC_UNIT_CSLX_FTM7, SEC_UNIT_ALL_RW}, + {SEC_UNIT_CSLX_DSCR, SEC_UNIT_ALL_RW}, +}; + +char *StringToMHz ( + char *Buf, + unsigned long Hz + ) +{ + long l, m, n; + + n = DIV_ROUND_CLOSEST(Hz, 1000) / 1000L; + l = AsciiSPrint (Buf, sizeof(Buf), "%ld", n); + + Hz -= n * 1000000L; + m = DIV_ROUND_CLOSEST(Hz, 1000L); + if (m != 0) + AsciiSPrint (Buf + l, sizeof(Buf), ".%03ld", m); + return (Buf); +} + +VOID +CciConfigureSnoopDvm ( + struct CcsrCci400 *CciBase + ) +{ + // Enable snoop requests and DVM message requests for + // Slave insterface S4 (A53 core cluster) + MmioWrite32((UINTN)&CciBase->slave[4].snoop_ctrl, + CCI400_DVM_MESSAGE_REQ_EN | CCI400_SNOOP_REQ_EN); +} + +VOID IfcNorInit(VOID) { + MmioWriteBe32((UINTN) &(FSL_IFC_REGS_BASE)->cspr_cs[FSL_IFC_CS0].cspr_ext, FSL_IFC_NOR_CSPR_EXT); + + MmioWriteBe32((UINTN) &(FSL_IFC_REGS_BASE)->ftim_cs[FSL_IFC_CS0].ftim[FSL_IFC_FTIM0], FSL_IFC_NOR_FTIM0); + MmioWriteBe32((UINTN) &(FSL_IFC_REGS_BASE)->ftim_cs[FSL_IFC_CS0].ftim[FSL_IFC_FTIM1], FSL_IFC_NOR_FTIM1); + MmioWriteBe32((UINTN) &(FSL_IFC_REGS_BASE)->ftim_cs[FSL_IFC_CS0].ftim[FSL_IFC_FTIM2], FSL_IFC_NOR_FTIM2); + MmioWriteBe32((UINTN) &(FSL_IFC_REGS_BASE)->ftim_cs[FSL_IFC_CS0].ftim[FSL_IFC_FTIM3], FSL_IFC_NOR_FTIM3); + + MmioWriteBe32((UINTN) &(FSL_IFC_REGS_BASE)->cspr_cs[FSL_IFC_CS0].cspr, FSL_IFC_NOR_CSPR0); + MmioWriteBe32((UINTN) &(FSL_IFC_REGS_BASE)->amask_cs[FSL_IFC_CS0].amask, FSL_IFC_NOR_AMASK0); + MmioWriteBe32((UINTN) &(FSL_IFC_REGS_BASE)->csor_cs[FSL_IFC_CS0].csor, FSL_IFC_NOR_CSOR0); +} + +VOID +CciConfigureQos ( + struct CcsrCci400 *CciBase + ) +{ + // FIXME: Empty for now. Populate if required later. + return; +} + +VOID +Cci400Init ( + VOID + ) +{ + struct CcsrCci400 *Base = (struct CcsrCci400 *)LS1043A_CCI400_ADDR; + + /* Set CCI-400 control override register to enable barrier transaction */ + MmioWrite32((UINTN)&Base->ctrl_ord, CCI400_CTRLORD_EN_BARRIER); + + CciConfigureSnoopDvm(Base); + CciConfigureQos(Base); +} + +/** + Initialize the Secure peripherals and memory regions + + If Trustzone is supported by your platform then this function makes the required initialization + of the secure peripherals and memory regions. + +**/ +VOID +Tzc380Init ( + VOID + ) +{ + // Setup TZ Address Space Controller. + // Assumption: We have 2GB DDR mounted on the DIMMs. + // + // Since, we need ONE secure DDR region which will be used for keeping + // the PPA (EL3 platform security fw) code and the rest of the regions + // would be non-secure regions which can be accessed via NS software as + // well - so we create one TZASC region of 2GB and divided it into + // 8 equal su-regions. Now, we keep the 1st sub-regions for housing + // the PPA and use the rest of the sub-regions to allow NS accesses. + + // Note: Your OS Kernel must be aware of the secure regions before to + // enable this region + TZASCSetRegion(LS1043A_TZASC380_ADDR, 1, TZASC_REGION_ENABLED, LS1043A_DRAM1_BASE_ADDR, 0, + TZASC_REGION_SIZE_2GB, TZASC_REGION_SECURITY_SRW, 0x7F); +} + +VOID +EnableDevicesNsAccess ( + OUT struct CsuNsDev *NonSecureDevices, + IN UINT32 Num + ) +{ + UINT32 *Base = (UINT32 *)LS1043A_CSU_ADDR; + UINT32 *Reg; + UINT32 Val; + UINT32 Count; + + for (Count = 0; Count < Num; Count++) { + Reg = Base + NonSecureDevices[Count].Ind / 2; + Val = MmioReadBe32((UINTN)Reg); + if (NonSecureDevices[Count].Ind % 2 == 0) { + Val &= 0x0000ffff; + Val |= NonSecureDevices[Count].Val << 16; + } else { + Val &= 0xffff0000; + Val |= NonSecureDevices[Count].Val; + } + MmioWriteBe32((UINTN)Reg, Val); + } +} + +VOID +CsuInit ( + VOID + ) +{ + EnableDevicesNsAccess(NonSecureDevices, ARRAY_SIZE(NonSecureDevices)); +}
VOID GetSysInfo ( OUT struct SysInfo *PtrSysInfo ) { - struct CcsrGur *GurBase = (void *)(LS1043A_FSL_GUTS_ADDR); - struct CcsrClk *ClkBase = (void *)(LS1043A_FSL_CLK_ADDR); + struct CcsrGur *GurBase = (void *)(LS1043A_GUTS_ADDR); + struct CcsrClk *ClkBase = (void *)(LS1043A_CLK_ADDR); UINTN CpuIndex; UINT32 TempRcw; const UINT8 CoreCplxPll[8] = { @@ -57,8 +264,8 @@ GetSysInfo ( };
UINTN PllCount; - UINTN FreqCPll[LS1043A_FSL_NUM_CC_PLLS]; - UINTN PllRatio[LS1043A_FSL_NUM_CC_PLLS]; + UINTN FreqCPll[LS1043A_NUM_CC_PLLS]; + UINTN PllRatio[LS1043A_NUM_CC_PLLS]; UINTN SysClk = LS1043A_CLK_FREQ;
PtrSysInfo->FreqSystemBus = SysClk; @@ -71,7 +278,7 @@ GetSysInfo ( FSL_CHASSIS2_RCWSR0_MEM_PLL_RAT_SHIFT) & FSL_CHASSIS2_RCWSR0_MEM_PLL_RAT_MASK;
- for (PllCount = 0; PllCount < LS1043A_FSL_NUM_CC_PLLS; PllCount++) { + for (PllCount = 0; PllCount < LS1043A_NUM_CC_PLLS; PllCount++) { PllRatio[PllCount] = (MmioReadBe32((UINTN)&ClkBase->pllcgsr[PllCount].pllcngsr) >> 1) & 0xff; if (PllRatio[PllCount] > 4) FreqCPll[PllCount] = SysClk * PllRatio[PllCount]; @@ -112,6 +319,461 @@ GetSysInfo ( PtrSysInfo->FreqQman = PtrSysInfo->FreqSystemBus / 2; }
+VOID +ClockInit ( + VOID + ) +{ + struct SysInfo SocSysInfo; + + GetSysInfo(&SocSysInfo); + gClkInfo.CpuClk = SocSysInfo.FreqProcessor[0]; + gClkInfo.BusClk = SocSysInfo.FreqSystemBus; + gClkInfo.MemClk = SocSysInfo.FreqDdrBus; + gClkInfo.SdhcClk = SocSysInfo.FreqSdhc; +} + +INTN +TimerInit ( + VOID + ) +{ + UINT32 *TimerBase = (UINT32 *)LS1043A_TIMER_ADDR; + + if (PcdGetBool(PcdCounterFrequencyReal)) { + UINTN cntfrq = PcdGet32(PcdCounterFrequency); + + /* Update with accurate clock frequency */ + asm volatile("msr cntfrq_el0, %0" : : "r" (cntfrq) : "memory"); + } + + /* Enable clock for timer. This is a global setting. */ + MmioWrite32((UINTN)TimerBase, 0x1); + + return 0; +} + +static inline +UINT32 +InitiatorType ( + IN UINT32 Cluster, + IN UINTN InitId + ) +{ + struct CcsrGur *GurBase = (void *)(LS1043A_GUTS_ADDR); + UINT32 Idx = (Cluster >> (InitId * 8)) & TP_CLUSTER_INIT_MASK; + UINT32 Type = MmioReadBe32((UINTN)&GurBase->tp_ityp[Idx]); + + if (Type & TP_ITYP_AV) + return Type; + + return 0; +} + +UINT32 +CpuMask ( + VOID + ) +{ + struct CcsrGur *GurBase = (void *)(LS1043A_GUTS_ADDR); + UINTN ClusterIndex = 0, Count = 0; + UINT32 Cluster, Type, Mask = 0; + + do { + UINTN InitiatorIndex; + Cluster = MmioReadBe32((UINTN)&GurBase->tp_cluster[ClusterIndex].lower); + for (InitiatorIndex = 0; InitiatorIndex < TP_INIT_PER_CLUSTER; InitiatorIndex++) { + Type = InitiatorType(Cluster, InitiatorIndex); + if (Type) { + if (TP_ITYP_TYPE(Type) == TP_ITYP_TYPE_ARM) + Mask |= 1 << Count; + Count++; + } + } + ClusterIndex++; + } while ((Cluster & TP_CLUSTER_EOC_MASK) == 0x0); + + return Mask; +} + +/* + * Return the number of cores on this SOC. + */ +UINTN +CpuNumCores ( + VOID + ) +{ + return HammingWeight32(CpuMask()); +} + +UINT32 +QoriqCoreToType ( + IN UINTN Core + ) +{ + struct CcsrGur *GurBase = (VOID *)(LS1043A_GUTS_ADDR); + UINTN ClusterIndex = 0, Count = 0; + UINT32 Cluster, Type; + + do { + UINTN InitiatorIndex; + Cluster = MmioReadBe32((UINTN)&GurBase->tp_cluster[ClusterIndex].lower); + for (InitiatorIndex = 0; InitiatorIndex < TP_INIT_PER_CLUSTER; InitiatorIndex++) { + Type = InitiatorType(Cluster, InitiatorIndex); + if (Type) { + if (Count == Core) + return Type; + Count++; + } + } + ClusterIndex++; + } while ((Cluster & TP_CLUSTER_EOC_MASK) == 0x0); + + return -1; /* cannot identify the cluster */ +} + +VOID +PrintCpuInfo ( + VOID + ) +{ + struct SysInfo SysInfo; + UINTN CoreIndex, Core; + UINT32 Type; + CHAR8 Buf[32]; + CHAR8 Buffer[100]; + UINTN CharCount; + + GetSysInfo(&SysInfo); + CharCount = AsciiSPrint (Buffer, sizeof (Buffer), "Clock Configuration:"); + SerialPortWrite ((UINT8 *) Buffer, CharCount); + + ForEachCpu(CoreIndex, Core, CpuNumCores(), CpuMask()) { + if (!(CoreIndex % 3)) + DEBUG((EFI_D_INFO, "\n ")); + Type = TP_ITYP_VER(QoriqCoreToType(Core)); + CharCount = AsciiSPrint (Buffer, sizeof (Buffer), "CPU%d(%a):%-4a MHz ", Core, + Type == TY_ITYP_VER_A53 ? "A53" : "Unknown Core", + StringToMHz(Buf, SysInfo.FreqProcessor[Core])); + SerialPortWrite ((UINT8 *) Buffer, CharCount); + } + + CharCount = AsciiSPrint (Buffer, sizeof (Buffer), "\n Bus: %-4a MHz ", + StringToMHz(Buf, SysInfo.FreqSystemBus)); + SerialPortWrite ((UINT8 *) Buffer, CharCount); + CharCount = AsciiSPrint (Buffer, sizeof (Buffer), "DDR: %-4a MHz", StringToMHz(Buf, SysInfo.FreqDdrBus)); + SerialPortWrite ((UINT8 *) Buffer, CharCount); + CharCount = AsciiSPrint (Buffer, sizeof (Buffer), "\n"); + SerialPortWrite ((UINT8 *) Buffer, CharCount); +} + +VOID +PrintSocPersonality ( + VOID + ) +{ +} + +VOID +IfcInit ( + VOID + ) +{ + /* NOR Init */ + IfcNorInit(); + + /* CPLD Init */ + CpldInit(); +} + +VOID +PrintBoardPersonality ( + VOID + ) +{ + static const char *Freq[3] = {"100.00MHZ", "156.25MHZ"}; + UINT8 RcwSrc1, RcwSrc2; + UINT32 RcwSrc; + UINT32 sd1refclk_sel; + + DEBUG((EFI_D_INFO, "Board: LS1043ARDB, boot from ")); + + RcwSrc1 = CPLD_READ(RcwSource1); + RcwSrc2 = CPLD_READ(RcwSource1); + CpldRevBit(&RcwSrc1); + RcwSrc = RcwSrc1; + RcwSrc = (RcwSrc << 1) | RcwSrc2; + + if (RcwSrc == 0x25) + DEBUG((EFI_D_INFO, "vBank %d\n", CPLD_READ(Vbank))); + else if (RcwSrc == 0x106) + DEBUG((EFI_D_INFO, "NAND\n")); + else + DEBUG((EFI_D_INFO, "Invalid setting of SW4\n")); + + DEBUG((EFI_D_INFO, "CPLD: V%x.%x\nPCBA: V%x.0\n", CPLD_READ(CpldVersionMajor), + CPLD_READ(CpldVersionMinor), CPLD_READ(PcbaVersion))); + + DEBUG((EFI_D_INFO, "SERDES Reference Clocks:\n")); + sd1refclk_sel = CPLD_READ(Sd1RefClkSel); + DEBUG((EFI_D_INFO, "SD1_CLK1 = %a, SD1_CLK2 = %a\n", Freq[sd1refclk_sel], Freq[0])); +} + +VOID +PrintRCW ( + VOID + ) +{ + struct CcsrGur *Base = (void *)(LS1043A_GUTS_ADDR); + UINTN Count; + CHAR8 Buffer[100]; + UINTN CharCount; + + /* + * Display the RCW, so that no one gets confused as to what RCW + * we're actually using for this boot. + */ + + CharCount = AsciiSPrint (Buffer, sizeof (Buffer), + "Reset Configuration Word (RCW):"); + SerialPortWrite ((UINT8 *) Buffer, CharCount); + for (Count = 0; Count < ARRAY_SIZE(Base->rcwsr); Count++) { + UINT32 Rcw = MmioReadBe32((UINTN)&Base->rcwsr[Count]); + + if ((Count % 4) == 0) { + CharCount = AsciiSPrint (Buffer, sizeof (Buffer), + "\n %08x:", Count * 4); + SerialPortWrite ((UINT8 *) Buffer, CharCount); + } + + CharCount = AsciiSPrint (Buffer, sizeof (Buffer), " %08x", Rcw); + SerialPortWrite ((UINT8 *) Buffer, CharCount); + } + CharCount = AsciiSPrint (Buffer, sizeof (Buffer), "\n"); + SerialPortWrite ((UINT8 *) Buffer, CharCount); +} + +VOID +SmmuInit ( + VOID + ) +{ + UINT32 Value; + + /* set pagesize as 64K and ssmu-500 in bypass mode */ + Value = (MmioRead32((UINTN)SMMU_REG_SACR) | SACR_PAGESIZE_MASK); + MmioWrite32((UINTN)SMMU_REG_SACR, Value); + + Value = (MmioRead32((UINTN)SMMU_REG_SCR0) | SCR0_CLIENTPD_MASK) & ~(SCR0_USFCFG_MASK); + MmioWrite32((UINTN)SMMU_REG_SCR0, Value); + + Value = (MmioRead32((UINTN)SMMU_REG_NSCR0) | SCR0_CLIENTPD_MASK) & ~(SCR0_USFCFG_MASK); + MmioWrite32((UINTN)SMMU_REG_NSCR0, Value); +} + +/** + Function to initialize SoC specific constructs + // CSU + // TZC-380 + // CCI-400 + // ClockInit + // TimerInit + // CPU Info + // SoC Personality + // Board Personality + // RCW prints + // SerDes support + **/ +VOID +SocInit ( + VOID + ) +{ + + CHAR8 Buffer[100]; + UINTN CharCount; + + // LS1043A SoC has a CSU (Central Security Unit) + if (PcdGetBool(PcdCsuInitialize)) + CsuInit(); + + if (PcdGetBool(PcdTzc380Initialize)) + Tzc380Init(); + + if (PcdGetBool(PcdCci400Initialize)) + Cci400Init(); + + if (PcdGetBool(PcdClockInitialize)) + ClockInit(); + + SmmuInit(); + TimerInit(); + + // Initialize the Serial Port + SerialPortInitialize (); + CharCount = AsciiSPrint (Buffer, sizeof (Buffer), "\nUEFI firmware (version %s built at %a on %a)\n\r", + (CHAR16*)PcdGetPtr(PcdFirmwareVersionString), __TIME__, __DATE__); + SerialPortWrite ((UINT8 *) Buffer, CharCount); + + PrintCpuInfo(); + PrintRCW(); + + PrintSocPersonality(); + + IfcInit(); + + PrintBoardPersonality(); + + SerDesInit(); + return; +} + +/* fdt fixup for LS1043A */ + +VOID +FixupByCompatibleField ( + VOID *Fdt, + CONST char *Compat, + CONST char *Prop, + CONST VOID *Val, + INTN Len, + INTN Create + ) +{ + INTN Offset = -1; + Offset = fdt_node_offset_by_compatible(Fdt, -1, Compat); + while (Offset != -FDT_ERR_NOTFOUND) { + if (Create || (fdt_get_property(Fdt, Offset, Prop, NULL) != NULL)) + fdt_setprop(Fdt, Offset, Prop, Val, Len); + Offset = fdt_node_offset_by_compatible(Fdt, Offset, Compat); + } +} + +VOID +FixupByCompatibleField32 ( + VOID *Fdt, + CONST char *Compat, + CONST char *Prop, + UINT32 Val, + INTN Create + ) +{ + fdt32_t Tmp = cpu_to_fdt32(Val); + FixupByCompatibleField(Fdt, Compat, Prop, &Tmp, 4, Create); +} + +#define BMAN_IP_REV_1 0xBF8 +#define BMAN_IP_REV_2 0xBFC +VOID +FdtFixupBmanPortals ( + VOID *Blob + ) +{ + UINTN Off, Err; + UINTN Maj, Min; + UINTN IpCfg; + + UINT32 BmanRev1 = MmioReadBe32(LS1043A_BMAN_ADDR + BMAN_IP_REV_1); + UINT32 BmanRev2 = MmioReadBe32(LS1043A_BMAN_ADDR + BMAN_IP_REV_2); + char Compatible[64]; + INTN CompatibleLength; + + Maj = (BmanRev1 >> 8) & 0xff; + Min = BmanRev1 & 0xff; + + IpCfg = BmanRev2 & 0xff; + + CompatibleLength = AsciiSPrint(Compatible, sizeof(Compatible), + "fsl,bman-portal-%u.%u.%u", + Maj, Min, IpCfg) + 1; + CompatibleLength += AsciiSPrint(Compatible + CompatibleLength, + sizeof(Compatible), "fsl,bman-portal") + + 1; + + Off = fdt_node_offset_by_compatible(Blob, -1, "fsl,bman-portal"); + while (Off != -FDT_ERR_NOTFOUND) { + Err = fdt_setprop(Blob, Off, "compatible", Compatible, + CompatibleLength); + if (Err < 0) { + DEBUG((EFI_D_ERROR, "ERROR: unable to create props for %a: %s\n", + fdt_get_name(Blob, Off, NULL), fdt_strerror(Err))); + return; + } + + Off = fdt_node_offset_by_compatible(Blob, Off, "fsl,bman-portal"); + } +} + +#define QMAN_IP_REV_1 0xBF8 +#define QMAN_IP_REV_2 0xBFC +VOID +FdtFixupQmanPortals ( + VOID *Blob + ) +{ + INTN Off, Err; + UINTN Maj, Min; + UINTN IpCfg; + UINT32 QmanRev1 = MmioReadBe32(LS1043A_QMAN_ADDR + QMAN_IP_REV_1); + UINT32 QmanRev2 = MmioReadBe32(LS1043A_QMAN_ADDR + QMAN_IP_REV_2); + char Compatible[64]; + INTN CompatLength; + + Maj = (QmanRev1 >> 8) & 0xff; + Min = QmanRev1 & 0xff; + IpCfg = QmanRev2 & 0xff; + + CompatLength = AsciiSPrint(Compatible, sizeof(Compatible), + "fsl,qman-portal-%u.%u.%u", + Maj, Min, IpCfg) + 1; + CompatLength += AsciiSPrint(Compatible + CompatLength, + sizeof(Compatible), "fsl,qman-portal") + 1; + + Off = fdt_node_offset_by_compatible(Blob, -1, "fsl,qman-portal"); + while (Off != -FDT_ERR_NOTFOUND) { + Err = fdt_setprop(Blob, Off, "compatible", Compatible, + CompatLength); + if (Err < 0) { + DEBUG((EFI_D_ERROR, "ERROR: unable to create props for %a: %a\n", + fdt_get_name(Blob, Off, NULL), fdt_strerror(Err))); + return; + } + + Off = fdt_node_offset_by_compatible(Blob, Off, "fsl,qman-portal"); + } +} + +VOID +FdtFixupSdhc ( + VOID *Blob, + UINTN SdhcClk + ) +{ + const char *Compatible = "fsl,esdhc"; + + FixupByCompatibleField32(Blob, Compatible, "clock-frequency", SdhcClk, 1); + + FixupByCompatibleField(Blob, Compatible, "status", "okay", 4 + 1, 1); +} + +VOID FdtCpuSetup(VOID *blob) +{ + struct SysInfo SocSysInfo; + GetSysInfo(&SocSysInfo); + + FixupByCompatibleField32(blob, "fsl,ns16550", + "clock-frequency", SocSysInfo.FreqSystemBus, 1); + + FdtFixupSdhc(blob, SocSysInfo.FreqSdhc); + + FdtFixupBmanPortals(blob); + FdtFixupQmanPortals(blob); + + FixupByCompatibleField32(blob, "fsl,qman", + "clock-frequency", SocSysInfo.FreqQman, 1); +} +
UINT32 CalculateBaudDivisor ( @@ -135,6 +797,6 @@ CalculateI2cClockRate( struct SysInfo SocSysInfo;
GetSysInfo(&SocSysInfo); - return SocSysInfo.FreqSystemBus;
+ return SocSysInfo.FreqSystemBus; } diff --git a/Platforms/Nxp/LS1043aRdb/Library/LS1043aSocLib/LS1043aSocLib.inf b/Platforms/Nxp/LS1043aRdb/Library/LS1043aSocLib/LS1043aSocLib.inf index 322fe34..307cf21 100644 --- a/Platforms/Nxp/LS1043aRdb/Library/LS1043aSocLib/LS1043aSocLib.inf +++ b/Platforms/Nxp/LS1043aRdb/Library/LS1043aSocLib/LS1043aSocLib.inf @@ -29,12 +29,25 @@ OpenPlatformPkg/Chips/Nxp/QoriqLs/NxpQoriqLs.dec
[LibraryClasses] + ArmTrustZoneLib BaseLib CpldLib DebugLib DebugAgentLib IoLib ArmLib + MemoryAllocationLib + SerialPortLib
[Sources.common] LS1043aSocLib.c + LsSerDes.c + +[FixedPcd] + gEfiMdeModulePkgTokenSpaceGuid.PcdFirmwareVersionString + gArmPlatformTokenSpaceGuid.PcdCounterFrequencyReal + gArmPlatformTokenSpaceGuid.PcdCsuInitialize + gArmPlatformTokenSpaceGuid.PcdTzc380Initialize + gArmPlatformTokenSpaceGuid.PcdCci400Initialize + gArmPlatformTokenSpaceGuid.PcdClockInitialize + gArmPlatformTokenSpaceGuid.PcdCounterFrequency diff --git a/Platforms/Nxp/LS1043aRdb/Library/LS1043aSocLib/LsSerDes.c b/Platforms/Nxp/LS1043aRdb/Library/LS1043aSocLib/LsSerDes.c new file mode 100644 index 0000000..3312e9b --- /dev/null +++ b/Platforms/Nxp/LS1043aRdb/Library/LS1043aSocLib/LsSerDes.c @@ -0,0 +1,195 @@ +/** LsSerDes.c + Provides the basic interfaces for SerDes Module + + Copyright (c) 2016, Freescale Semiconductor, Inc. All rights reserved. + + This program and the accompanying materials + are licensed and made available under the terms and conditions of the BSD License + which accompanies this distribution. The full text of the license may be found + http://opensource.org/licenses/bsd-license.php + + THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, + WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. + +**/ + +#include <Uefi.h> +#include <Library/PlatformLib.h> +#include <Library/SocLib.h> +#include <Library/DebugLib.h> +#include <Library/DebugAgentLib.h> +#include <Library/IoLib.h> +#include <Library/Ls1043aSerDes.h> + +#ifdef LS1043A_SRDS_1 +static UINT16 SerDes1PrtclMap[SERDES_PRCTL_COUNT]; +#endif + +static struct SerDesConfig *SerDesConfigTbl[] = { + SerDes1ConfigTbl +}; + +SrdsPrtcl +GetSerDesPrtcl +( + IN INTN SerDes, + IN INTN Cfg, + IN INTN Lane +) +{ + struct SerDesConfig *Config; + + if (SerDes >= ARRAY_SIZE(SerDesConfigTbl)) + return 0; + + Config = SerDesConfigTbl[SerDes]; + while (Config->Protocol) { + if (Config->Protocol == Cfg) { + return Config->SrdsLane[Lane]; + } + Config++; + } + + return EFI_SUCCESS; +} + +EFI_STATUS +CheckSerDesPrtclValid +( + IN INTN SerDes, + IN UINT32 Prtcl +) +{ + INTN Cnt; + struct SerDesConfig *Config; + + if (SerDes >= ARRAY_SIZE(SerDesConfigTbl)) + return 0; + + Config = SerDesConfigTbl[SerDes]; + while (Config->Protocol) { + if (Config->Protocol == Prtcl) { + DEBUG((EFI_D_INFO, "Protocol: %x Matched with the one in Table\n", Prtcl)); + break; + } + Config++; + } + + if (!Config->Protocol) + return 0; + + for (Cnt = 0; Cnt < SRDS_MAX_LANES; Cnt++) { + if (Config->SrdsLane[Cnt] != NONE) + return 1; + } + + return 0; +} + + +EFI_STATUS +IsSerDesConfigured +( + IN SrdsPrtcl Device +) +{ + INTN Ret = 0; + +#ifdef LS1043A_SRDS_1 + Ret |= SerDes1PrtclMap[Device]; +#endif + + return !!Ret; +} + +INTN +GetSerDesFirstLane +( + IN UINT32 Sd, + IN SrdsPrtcl Device +) +{ + struct CcsrGur *Gur = (void *)(LS1043A_GUTS_ADDR); + UINT32 Cfg = MmioReadBe32((UINTN)&Gur->rcwsr[4]); + INTN Cnt; + + switch (Sd) { +#ifdef LS1043A_SRDS_1 + case FSL_SRDS_1: + Cfg &= LS1043_RCWSR4_SRDS1_PRTCL_MASK; + Cfg >>= LS1043_RCWSR4_SRDS1_PRTCL_SHIFT; + break; +#endif + default: + DEBUG((EFI_D_INFO, "Invalid SerDes%d, Only one SerDes is there.\n", Sd)); + break; + } + + /* Is serdes enabled at all? */ + if (Cfg == 0) + return EFI_DEVICE_ERROR; + + for (Cnt = 0; Cnt < SRDS_MAX_LANES; Cnt++) { + if (GetSerDesPrtcl(Sd, Cfg, Cnt) == Device) + return Cnt; + } + + return EFI_DEVICE_ERROR; +} + +VOID +LSSerDesInit +( + UINT32 Srds, + UINT32 SrdsAddr, + UINT32 SrdsPrtclMask, + UINT32 SrdsPrtclShift, + UINT16 SerDesPrtclMap[SERDES_PRCTL_COUNT] +) +{ + struct CcsrGur *Gur = (VOID *)(LS1043A_GUTS_ADDR); + UINT32 SrdsProt; + INTN Lane; + UINT32 Flag = 0; + + SrdsProt = MmioReadBe32((UINTN)&Gur->rcwsr[4]) & SrdsPrtclMask; + SrdsProt >>= SrdsPrtclShift; + + DEBUG((EFI_D_INFO, "Using SERDES%d Protocol: %d (0x%x)\n", Srds + 1, SrdsProt, SrdsProt)); + + if (!CheckSerDesPrtclValid(Srds, SrdsProt)) { + DEBUG((EFI_D_ERROR, "SERDES%d[PRTCL] = 0x%x is not valid\n", Srds + 1, SrdsProt)); + Flag++; + } + + for (Lane = 0; Lane < SRDS_MAX_LANES; Lane++) { + SrdsPrtcl LanePrtcl = GetSerDesPrtcl(Srds, SrdsProt, Lane); + if (LanePrtcl >= SERDES_PRCTL_COUNT) { + DEBUG((EFI_D_ERROR, "Unknown SerDes lane protocol %d\n", LanePrtcl)); + Flag++; + } else { + SerDesPrtclMap[LanePrtcl] = 1; + } + } + + if (Flag) + DEBUG((EFI_D_ERROR, "Could not configure SerDes module!!\n")); + else + DEBUG((EFI_D_INFO, "Successfully configured SerDes module!!\n")); +} + +VOID +SerDesInit +( + VOID +) +{ + DEBUG((EFI_D_INFO, "Initializing SerDes....\n")); +#ifdef LS1043A_SRDS_1 + LSSerDesInit(FSL_SRDS_1, + LS1043A_SERDES_ADDR, + LS1043_RCWSR4_SRDS1_PRTCL_MASK, + LS1043_RCWSR4_SRDS1_PRTCL_SHIFT, + SerDes1PrtclMap); +#endif +}
On 17 October 2016 at 21:04, Bhupesh Sharma bhupesh.sharma@freescale.com wrote:
From: Sakar Arora Sakar.Arora@nxp.com
This patch adds the functions that initialize the following IPs on the SoC:
- Central Security Unit (CSU) - Acts as a gatekeeper for secure and non-secure accesses via SW.
- TrustZone Address Space Controller (TZC-380).
- Interconnect (CCI-400).
- PLLs and Clocks.
- ARM Generic Timer.
In addition it also provides functions that print the following useful information:
- CPU Info
- SoC Personality.
- Board Personality.
- Reset Configuration Word (RCW).
- SerDes selection.
This looks like a mixed bag of functionality. Could you split this up please?
Also, please elaborate in the commit log how you manage to configure these secure world peripherals from EL2,
Signed-off-by: Bhupesh Sharma bhupesh.sharma@nxp.com
.../Nxp/LS1043aRdb/Include/Library/Ls1043aSerDes.h | 89 +++ Platforms/Nxp/LS1043aRdb/Include/Library/SocLib.h | 203 ++++++- .../LS1043aRdb/Library/LS1043aRdbLib/LS1043aRdb.c | 2 + .../Library/LS1043aSocLib/LS1043aSocLib.c | 674 ++++++++++++++++++++- .../Library/LS1043aSocLib/LS1043aSocLib.inf | 13 + .../LS1043aRdb/Library/LS1043aSocLib/LsSerDes.c | 195 ++++++ 6 files changed, 1169 insertions(+), 7 deletions(-) create mode 100644 Platforms/Nxp/LS1043aRdb/Include/Library/Ls1043aSerDes.h create mode 100644 Platforms/Nxp/LS1043aRdb/Library/LS1043aSocLib/LsSerDes.c
diff --git a/Platforms/Nxp/LS1043aRdb/Include/Library/Ls1043aSerDes.h b/Platforms/Nxp/LS1043aRdb/Include/Library/Ls1043aSerDes.h new file mode 100644 index 0000000..181c268 --- /dev/null +++ b/Platforms/Nxp/LS1043aRdb/Include/Library/Ls1043aSerDes.h
is this an internal header? If so, please keep it with the .c files
@@ -0,0 +1,89 @@ +/** Ls1043aSerDes.h
- The Header file of SerDes Module
- Copyright (c) 2016, Freescale Semiconductor, Inc. All rights reserved.
- This program and the accompanying materials
- are licensed and made available under the terms and conditions of the BSD License
- which accompanies this distribution. The full text of the license may be found
- http://opensource.org/licenses/bsd-license.php
- THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
- WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
+**/
+#ifndef __LS1043A_SERDES_H +#define __LS1043A_SERDES_H
+#define SRDS_MAX_LANES 4
+#define LS1043_RCWSR4_SRDS1_PRTCL_MASK 0xFFFF0000 +#define LS1043_RCWSR4_SRDS1_PRTCL_SHIFT 16
+typedef enum {
NONE = 0,
PCIE1,
PCIE2,
PCIE3,
SATA1,
XFI1,
XFI2,
SGMII1,
SGMII2,
SGMII3,
SGMII4,
SGMII5,
SGMII6,
SGMII7,
SGMII8,
SGMII9,
QSGMII1,
QSGMII2,
SERDES_PRCTL_COUNT
+} SrdsPrtcl;
+enum Srds {
FSL_SRDS_1 = 0,
FSL_SRDS_2 = 1
+};
+struct SerDesConfig {
UINT16 Protocol;
UINT8 SrdsLane[SRDS_MAX_LANES];
+};
+struct SerDesConfig SerDes1ConfigTbl[] = {
/* SerDes 1 */
{0x1555, {XFI1, PCIE1, PCIE2, PCIE3 } },
{0x1560, {XFI1, PCIE1, PCIE3, PCIE3 } },
{0x1460, {XFI1, QSGMII1, PCIE3, PCIE3 } },
{0x1360, {XFI1, SGMII2, PCIE3, PCIE3 } },
{0x2555, {SGMII9, PCIE1, PCIE2, PCIE3 } },
{0x4555, {QSGMII1, PCIE1, PCIE2, PCIE3 } },
{0x4558, {QSGMII1, PCIE1, PCIE2, SATA1 } },
{0x1355, {XFI1, SGMII2, PCIE2, PCIE3 } },
{0x1335, {XFI1, SGMII2, SGMII5, PCIE3 } },
{0x1333, {XFI1, SGMII2, SGMII5, SGMII6 } },
{0x2355, {SGMII9, SGMII2, PCIE2, PCIE3 } },
{0x2260, {SGMII9, SGMII2, PCIE3, PCIE3 } },
{0x2235, {SGMII9, SGMII2, SGMII5, PCIE3 } },
{0x2233, {SGMII9, SGMII2, SGMII5, SGMII6 } },
{0x3335, {SGMII9, SGMII2, SGMII5, PCIE3 } },
{0x3355, {SGMII9, SGMII2, PCIE2, PCIE3 } },
{0x3358, {SGMII9, SGMII2, PCIE2, SATA1 } },
{0x3360, {SGMII9, SGMII2, PCIE3, PCIE3 } },
{0x3560, {SGMII9, PCIE1, PCIE3, PCIE3 } },
{0x3555, {SGMII9, PCIE1, PCIE2, PCIE3 } },
{0x7000, {PCIE1, PCIE1, PCIE1, PCIE1 } },
{0x9998, {PCIE1, PCIE2, PCIE3, SATA1 } },
{0x6058, {PCIE1, PCIE1, PCIE2, SATA1 } },
{0x1455, {XFI1, QSGMII1, PCIE2, PCIE3 } },
{0x2455, {SGMII9, QSGMII1, PCIE2, PCIE3 } },
{0x2255, {SGMII9, SGMII2, PCIE2, PCIE3 } },
{0x3333, {SGMII9, SGMII2, SGMII5, SGMII6 } },
{0x3338, {SGMII9, SGMII2, SGMII5, SATA1 } },
{}
+};
+#endif /* __LS1043A_SERDES_H */ diff --git a/Platforms/Nxp/LS1043aRdb/Include/Library/SocLib.h b/Platforms/Nxp/LS1043aRdb/Include/Library/SocLib.h index d1655d5..dc798b3 100644 --- a/Platforms/Nxp/LS1043aRdb/Include/Library/SocLib.h +++ b/Platforms/Nxp/LS1043aRdb/Include/Library/SocLib.h @@ -22,14 +22,72 @@ #define HWA_CGA_M2_CLK_SEL 0x00000007 #define HWA_CGA_M2_CLK_SHIFT 0
+#define TP_ITYP_AV 0x00000001 /* Initiator available */ +#define TP_ITYP_TYPE(x) (((x) & 0x6) >> 1) /* Initiator Type */ +#define TP_ITYP_TYPE_ARM 0x0 +#define TP_ITYP_TYPE_PPC 0x1 /* PowerPC */ +#define TP_ITYP_TYPE_OTHER 0x2 /* StarCore DSP */ +#define TP_ITYP_TYPE_HA 0x3 /* HW Accelerator */ +#define TP_ITYP_THDS(x) (((x) & 0x18) >> 3) /* # threads */ +#define TP_ITYP_VER(x) (((x) & 0xe0) >> 5) /* Initiator Version */ +#define TY_ITYP_VER_A53 0x2
+#define TP_CLUSTER_EOC_MASK 0xc0000000 /* end of clusters mask */ +#define TP_CLUSTER_INIT_MASK 0x0000003f /* initiator mask */ +#define TP_INIT_PER_CLUSTER 4
#define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
#define LS1043A_CLK_FREQ 100000000 #define LS1043A_DDR_CLK_FREQ 100000000
#define LS1043A_MAX_CPUS 4 +#define LS1043A_FMAN_V3 #define LS1043A_NUM_FMAN 1 +#define LS1043A_NUM_FM1_DTSEC 7 +#define LS1043A_NUM_FM1_10GEC 1
+/*
- Divide positive or negative dividend by positive divisor and round
- to closest UINTNeger. Result is undefined for negative divisors and
- for negative dividends if the divisor variable type is unsigned.
- */
+#define DIV_ROUND_CLOSEST(x, divisor)( \ +{ \
typeof(x) __x = x; \
typeof(divisor) __d = divisor; \
(((typeof(x))-1) > 0 || \
((typeof(divisor))-1) > 0 || (__x) > 0) ? \
(((__x) + ((__d) / 2)) / (__d)) : \
(((__x) - ((__d) / 2)) / (__d)); \
+} \ +)
+/*
- HammingWeight32: returns the hamming weight (i.e. the number
- of bits set) of a 32-bit word
- */
+static inline UINTN HammingWeight32(UINTN w) +{
UINTN Res = (w & 0x55555555) + ((w >> 1) & 0x55555555);
Res = (Res & 0x33333333) + ((Res >> 2) & 0x33333333);
Res = (Res & 0x0F0F0F0F) + ((Res >> 4) & 0x0F0F0F0F);
Res = (Res & 0x00FF00FF) + ((Res >> 8) & 0x00FF00FF);
return (Res & 0x0000FFFF) + ((Res >> 16) & 0x0000FFFF);
+}
+static inline UINTN CpuMaskNext(UINTN Cpu, UINTN Mask) +{
for (Cpu++; !((1 << Cpu) & Mask); Cpu++)
;
return Cpu;
+}
+#define ForEachCpu(iter, cpu, num_cpus, mask) \
for (iter = 0, cpu = CpuMaskNext(-1, mask); \
iter < num_cpus; \
iter++, cpu = CpuMaskNext(cpu, mask)) \
struct SysInfo { UINTN FreqProcessor[LS1043A_MAX_CPUS]; @@ -41,9 +99,122 @@ struct SysInfo { UINTN FreqQman; };
+typedef struct SocClocks {
UINTN CpuClk; /* CPU clock in Hz! */
UINTN BusClk;
UINTN MemClk;
UINTN PciClk;
UINTN SdhcClk;
+} SocClockInfo;
+enum PeriphClock {
ARM_CLK = 0,
BUS_CLK,
UART_CLK,
ESDHC_CLK,
I2C_CLK,
DSPI_CLK,
+};
+enum CsuCslxAccess {
SEC_UNIT_NS_SUP_R = 0x08,
SEC_UNIT_NS_SUP_W = 0x80,
SEC_UNIT_NS_SUP_RW = 0x88,
SEC_UNIT_NS_USER_R = 0x04,
SEC_UNIT_NS_USER_W = 0x40,
SEC_UNIT_NS_USER_RW = 0x44,
SEC_UNIT_S_SUP_R = 0x02,
SEC_UNIT_S_SUP_W = 0x20,
SEC_UNIT_S_SUP_RW = 0x22,
SEC_UNIT_S_USER_R = 0x01,
SEC_UNIT_S_USER_W = 0x10,
SEC_UNIT_S_USER_RW = 0x11,
SEC_UNIT_ALL_RW = 0xff,
+};
+enum CsuCslxInd {
SEC_UNIT_CSLX_PCIE2_IO = 0,
SEC_UNIT_CSLX_PCIE1_IO,
SEC_UNIT_CSLX_MG2TPR_IP,
SEC_UNIT_CSLX_IFC_MEM,
SEC_UNIT_CSLX_OCRAM,
SEC_UNIT_CSLX_GIC,
SEC_UNIT_CSLX_PCIE1,
SEC_UNIT_CSLX_OCRAM2,
SEC_UNIT_CSLX_QSPI_MEM,
SEC_UNIT_CSLX_PCIE2,
SEC_UNIT_CSLX_SATA,
SEC_UNIT_CSLX_USB1,
SEC_UNIT_CSLX_QM_BM_SWPORTAL,
SEC_UNIT_CSLX_PCIE3 = 16,
SEC_UNIT_CSLX_PCIE3_IO,
SEC_UNIT_CSLX_USB3 = 20,
SEC_UNIT_CSLX_USB2,
SEC_UNIT_CSLX_SERDES = 32,
SEC_UNIT_CSLX_QDMA,
SEC_UNIT_CSLX_LPUART2,
SEC_UNIT_CSLX_LPUART1,
SEC_UNIT_CSLX_LPUART4,
SEC_UNIT_CSLX_LPUART3,
SEC_UNIT_CSLX_LPUART6,
SEC_UNIT_CSLX_LPUART5,
SEC_UNIT_CSLX_DSPI1 = 41,
SEC_UNIT_CSLX_QSPI,
SEC_UNIT_CSLX_ESDHC,
SEC_UNIT_CSLX_IFC = 45,
SEC_UNIT_CSLX_I2C1,
SEC_UNIT_CSLX_I2C3 = 48,
SEC_UNIT_CSLX_I2C2,
SEC_UNIT_CSLX_DUART2 = 50,
SEC_UNIT_CSLX_DUART1,
SEC_UNIT_CSLX_WDT2,
SEC_UNIT_CSLX_WDT1,
SEC_UNIT_CSLX_EDMA,
SEC_UNIT_CSLX_SYS_CNT,
SEC_UNIT_CSLX_DMA_MUX2,
SEC_UNIT_CSLX_DMA_MUX1,
SEC_UNIT_CSLX_DDR,
SEC_UNIT_CSLX_QUICC,
SEC_UNIT_CSLX_DCFG_CCU_RCPM = 60,
SEC_UNIT_CSLX_SECURE_BOOTROM,
SEC_UNIT_CSLX_SFP,
SEC_UNIT_CSLX_TMU,
SEC_UNIT_CSLX_SECURE_MONITOR,
SEC_UNIT_CSLX_SCFG,
SEC_UNIT_CSLX_FM = 66,
SEC_UNIT_CSLX_SEC5_5,
SEC_UNIT_CSLX_BM,
SEC_UNIT_CSLX_QM,
SEC_UNIT_CSLX_GPIO2 = 70,
SEC_UNIT_CSLX_GPIO1,
SEC_UNIT_CSLX_GPIO4,
SEC_UNIT_CSLX_GPIO3,
SEC_UNIT_CSLX_PLATFORM_CONT,
SEC_UNIT_CSLX_SEC_UNIT,
SEC_UNIT_CSLX_IIC4 = 77,
SEC_UNIT_CSLX_WDT4,
SEC_UNIT_CSLX_WDT3,
SEC_UNIT_CSLX_WDT5 = 81,
SEC_UNIT_CSLX_FTM2 = 86,
SEC_UNIT_CSLX_FTM1,
SEC_UNIT_CSLX_FTM4,
SEC_UNIT_CSLX_FTM3,
SEC_UNIT_CSLX_FTM6 = 90,
SEC_UNIT_CSLX_FTM5,
SEC_UNIT_CSLX_FTM8,
SEC_UNIT_CSLX_FTM7,
SEC_UNIT_CSLX_DSCR = 120,
+};
+struct CsuNsDev {
UINTN Ind;
UINT32 Val;
+};
/* Device Configuration and Pin Control */ struct CcsrGur { UINT32 porsr1; /* POR status 1 */ +#define FSL_CHASSIS2_CCSR_PORSR1_RCW_MASK 0xFF800000 UINT32 porsr2; /* POR status 2 */ UINT8 res_008[0x20-0x8]; UINT32 gpporcr1; /* General-purpose POR configuration */ @@ -51,6 +222,18 @@ struct CcsrGur { UINT32 dcfg_fusesr; /* Fuse status register */ UINT8 res_02c[0x70-0x2c]; UINT32 devdisr; /* Device disable control */ +#define FSL_CHASSIS2_DEVDISR2_DTSEC1_1 0x80000000 +#define FSL_CHASSIS2_DEVDISR2_DTSEC1_2 0x40000000 +#define FSL_CHASSIS2_DEVDISR2_DTSEC1_3 0x20000000 +#define FSL_CHASSIS2_DEVDISR2_DTSEC1_4 0x10000000 +#define FSL_CHASSIS2_DEVDISR2_DTSEC1_5 0x08000000 +#define FSL_CHASSIS2_DEVDISR2_DTSEC1_6 0x04000000 +#define FSL_CHASSIS2_DEVDISR2_DTSEC1_9 0x00800000 +#define FSL_CHASSIS2_DEVDISR2_DTSEC1_10 0x00400000 +#define FSL_CHASSIS2_DEVDISR2_10GEC1_1 0x00800000 +#define FSL_CHASSIS2_DEVDISR2_10GEC1_2 0x00400000 +#define FSL_CHASSIS2_DEVDISR2_10GEC1_3 0x80000000 +#define FSL_CHASSIS2_DEVDISR2_10GEC1_4 0x40000000 UINT32 devdisr2; /* Device disable control 2 */ UINT32 devdisr3; /* Device disable control 3 */ UINT32 devdisr4; /* Device disable control 4 */ @@ -83,6 +266,8 @@ struct CcsrGur { #define FSL_CHASSIS2_RCWSR0_SYS_PLL_RAT_MASK 0x1f #define FSL_CHASSIS2_RCWSR0_MEM_PLL_RAT_SHIFT 16 #define FSL_CHASSIS2_RCWSR0_MEM_PLL_RAT_MASK 0x3f +#define FSL_CHASSIS2_RCWSR4_SRDS1_PRTCL_MASK 0xffff0000 +#define FSL_CHASSIS2_RCWSR4_SRDS1_PRTCL_SHIFT 16 UINT8 res_140[0x200-0x140]; UINT32 scratchrw[4]; /* Scratch Read/Write */ UINT8 res_210[0x300-0x210]; @@ -259,6 +444,12 @@ struct CcsrClk { UINT8 res_c24[0x3dc]; };
+#define CCI400_CTRLORD_TERM_BARRIER 0x00000008 +#define CCI400_CTRLORD_EN_BARRIER 0 +#define CCI400_SHAORD_NON_SHAREABLE 0x00000002 +#define CCI400_DVM_MESSAGE_REQ_EN 0x00000002 +#define CCI400_SNOOP_REQ_EN 0x00000001
/* CCI-400 registers */ struct CcsrCci400 { UINT32 ctrl_ord; /* Control Override */ @@ -301,8 +492,18 @@ struct CcsrCci400 { UINT8 res_e004[0x10000 - 0xe004]; };
+VOID EnableDevicesNsAccess(struct CsuNsDev *NonSecureDevices, UINT32 Num);
+VOID GetSysInfo(struct SysInfo *PtrSysInfo);
+VOID SocInit(VOID);
+VOID SerDesInit(VOID);
+VOID FdtCpuSetup(VOID *Blob);
UINT32 CalculateBaudDivisor(OUT UINT64 *BaudRate); -UINT32 CalculateI2cClockRate(VOID);
+UINT32 CalculateI2cClockRate(VOID);
#endif /* __LS1043A_SOC_H__ */ diff --git a/Platforms/Nxp/LS1043aRdb/Library/LS1043aRdbLib/LS1043aRdb.c b/Platforms/Nxp/LS1043aRdb/Library/LS1043aRdbLib/LS1043aRdb.c index 4fcb8a3..7c64709 100644 --- a/Platforms/Nxp/LS1043aRdb/Library/LS1043aRdbLib/LS1043aRdb.c +++ b/Platforms/Nxp/LS1043aRdb/Library/LS1043aRdbLib/LS1043aRdb.c @@ -24,6 +24,7 @@ #include <Library/PcdLib.h> #include <Ppi/ArmMpCoreInfo.h> #include <Library/PlatformLib.h> +#include <Library/SocLib.h>
/** Return the current Boot Mode @@ -47,6 +48,7 @@ ArmPlatformInitialize ( IN UINTN MpId ) {
- SocInit(); return RETURN_SUCCESS;
}
diff --git a/Platforms/Nxp/LS1043aRdb/Library/LS1043aSocLib/LS1043aSocLib.c b/Platforms/Nxp/LS1043aRdb/Library/LS1043aSocLib/LS1043aSocLib.c index fdeae08..2a7cb38 100644 --- a/Platforms/Nxp/LS1043aRdb/Library/LS1043aSocLib/LS1043aSocLib.c +++ b/Platforms/Nxp/LS1043aRdb/Library/LS1043aSocLib/LS1043aSocLib.c @@ -26,20 +26,227 @@ #include <Library/DebugAgentLib.h> #include <Library/IoLib.h> #include <Library/PrintLib.h> +#include <Library/SerialPortLib.h> +#include <Library/FslIfc.h>
+#include <Drivers/ArmTrustzone.h>
#include <Library/PlatformLib.h> #include <Library/SocLib.h> #include <Library/CpldLib.h>
+#include <libfdt.h>
+/* Global Clock Information pointer */ +static SocClockInfo gClkInfo;
+static struct CsuNsDev NonSecureDevices[] = +{
{SEC_UNIT_CSLX_PCIE2_IO, SEC_UNIT_ALL_RW},
{SEC_UNIT_CSLX_PCIE1_IO, SEC_UNIT_ALL_RW},
{SEC_UNIT_CSLX_MG2TPR_IP, SEC_UNIT_ALL_RW},
{SEC_UNIT_CSLX_IFC_MEM, SEC_UNIT_ALL_RW},
{SEC_UNIT_CSLX_OCRAM, SEC_UNIT_ALL_RW},
{SEC_UNIT_CSLX_GIC, SEC_UNIT_ALL_RW},
{SEC_UNIT_CSLX_PCIE1, SEC_UNIT_ALL_RW},
{SEC_UNIT_CSLX_OCRAM2, SEC_UNIT_ALL_RW},
{SEC_UNIT_CSLX_QSPI_MEM, SEC_UNIT_ALL_RW},
{SEC_UNIT_CSLX_PCIE2, SEC_UNIT_ALL_RW},
{SEC_UNIT_CSLX_SATA, SEC_UNIT_ALL_RW},
{SEC_UNIT_CSLX_USB1, SEC_UNIT_ALL_RW},
{SEC_UNIT_CSLX_QM_BM_SWPORTAL, SEC_UNIT_ALL_RW},
{SEC_UNIT_CSLX_PCIE3, SEC_UNIT_ALL_RW},
{SEC_UNIT_CSLX_PCIE3_IO, SEC_UNIT_ALL_RW},
{SEC_UNIT_CSLX_USB3, SEC_UNIT_ALL_RW},
{SEC_UNIT_CSLX_USB2, SEC_UNIT_ALL_RW},
{SEC_UNIT_CSLX_SERDES, SEC_UNIT_ALL_RW},
{SEC_UNIT_CSLX_QDMA, SEC_UNIT_ALL_RW},
{SEC_UNIT_CSLX_LPUART2, SEC_UNIT_ALL_RW},
{SEC_UNIT_CSLX_LPUART1, SEC_UNIT_ALL_RW},
{SEC_UNIT_CSLX_LPUART4, SEC_UNIT_ALL_RW},
{SEC_UNIT_CSLX_LPUART3, SEC_UNIT_ALL_RW},
{SEC_UNIT_CSLX_LPUART6, SEC_UNIT_ALL_RW},
{SEC_UNIT_CSLX_LPUART5, SEC_UNIT_ALL_RW},
{SEC_UNIT_CSLX_DSPI1, SEC_UNIT_ALL_RW},
{SEC_UNIT_CSLX_QSPI, SEC_UNIT_ALL_RW},
{SEC_UNIT_CSLX_ESDHC, SEC_UNIT_ALL_RW},
{SEC_UNIT_CSLX_IFC, SEC_UNIT_ALL_RW},
{SEC_UNIT_CSLX_I2C1, SEC_UNIT_ALL_RW},
{SEC_UNIT_CSLX_I2C3, SEC_UNIT_ALL_RW},
{SEC_UNIT_CSLX_I2C2, SEC_UNIT_ALL_RW},
{SEC_UNIT_CSLX_DUART2, SEC_UNIT_ALL_RW},
{SEC_UNIT_CSLX_DUART1, SEC_UNIT_ALL_RW},
{SEC_UNIT_CSLX_WDT2, SEC_UNIT_ALL_RW},
{SEC_UNIT_CSLX_WDT1, SEC_UNIT_ALL_RW},
{SEC_UNIT_CSLX_EDMA, SEC_UNIT_ALL_RW},
{SEC_UNIT_CSLX_SYS_CNT, SEC_UNIT_ALL_RW},
{SEC_UNIT_CSLX_DMA_MUX2, SEC_UNIT_ALL_RW},
{SEC_UNIT_CSLX_DMA_MUX1, SEC_UNIT_ALL_RW},
{SEC_UNIT_CSLX_DDR, SEC_UNIT_ALL_RW},
{SEC_UNIT_CSLX_QUICC, SEC_UNIT_ALL_RW},
{SEC_UNIT_CSLX_DCFG_CCU_RCPM, SEC_UNIT_ALL_RW},
{SEC_UNIT_CSLX_SECURE_BOOTROM, SEC_UNIT_ALL_RW},
{SEC_UNIT_CSLX_SFP, SEC_UNIT_ALL_RW},
{SEC_UNIT_CSLX_TMU, SEC_UNIT_ALL_RW},
{SEC_UNIT_CSLX_SECURE_MONITOR, SEC_UNIT_ALL_RW},
{SEC_UNIT_CSLX_SCFG, SEC_UNIT_ALL_RW},
{SEC_UNIT_CSLX_FM, SEC_UNIT_ALL_RW},
{SEC_UNIT_CSLX_SEC5_5, SEC_UNIT_ALL_RW},
{SEC_UNIT_CSLX_BM, SEC_UNIT_ALL_RW},
{SEC_UNIT_CSLX_QM, SEC_UNIT_ALL_RW},
{SEC_UNIT_CSLX_GPIO2, SEC_UNIT_ALL_RW},
{SEC_UNIT_CSLX_GPIO1, SEC_UNIT_ALL_RW},
{SEC_UNIT_CSLX_GPIO4, SEC_UNIT_ALL_RW},
{SEC_UNIT_CSLX_GPIO3, SEC_UNIT_ALL_RW},
{SEC_UNIT_CSLX_PLATFORM_CONT, SEC_UNIT_ALL_RW},
{SEC_UNIT_CSLX_SEC_UNIT, SEC_UNIT_ALL_RW},
{SEC_UNIT_CSLX_IIC4, SEC_UNIT_ALL_RW},
{SEC_UNIT_CSLX_WDT4, SEC_UNIT_ALL_RW},
{SEC_UNIT_CSLX_WDT3, SEC_UNIT_ALL_RW},
{SEC_UNIT_CSLX_WDT5, SEC_UNIT_ALL_RW},
{SEC_UNIT_CSLX_FTM2, SEC_UNIT_ALL_RW},
{SEC_UNIT_CSLX_FTM1, SEC_UNIT_ALL_RW},
{SEC_UNIT_CSLX_FTM4, SEC_UNIT_ALL_RW},
{SEC_UNIT_CSLX_FTM3, SEC_UNIT_ALL_RW},
{SEC_UNIT_CSLX_FTM6, SEC_UNIT_ALL_RW},
{SEC_UNIT_CSLX_FTM5, SEC_UNIT_ALL_RW},
{SEC_UNIT_CSLX_FTM8, SEC_UNIT_ALL_RW},
{SEC_UNIT_CSLX_FTM7, SEC_UNIT_ALL_RW},
{SEC_UNIT_CSLX_DSCR, SEC_UNIT_ALL_RW},
+};
+char *StringToMHz (
- char *Buf,
- unsigned long Hz
- )
+{
long l, m, n;
n = DIV_ROUND_CLOSEST(Hz, 1000) / 1000L;
l = AsciiSPrint (Buf, sizeof(Buf), "%ld", n);
Hz -= n * 1000000L;
m = DIV_ROUND_CLOSEST(Hz, 1000L);
if (m != 0)
AsciiSPrint (Buf + l, sizeof(Buf), ".%03ld", m);
return (Buf);
+}
+VOID +CciConfigureSnoopDvm (
- struct CcsrCci400 *CciBase
- )
+{
// Enable snoop requests and DVM message requests for
// Slave insterface S4 (A53 core cluster)
MmioWrite32((UINTN)&CciBase->slave[4].snoop_ctrl,
CCI400_DVM_MESSAGE_REQ_EN | CCI400_SNOOP_REQ_EN);
+}
+VOID IfcNorInit(VOID) {
- MmioWriteBe32((UINTN) &(FSL_IFC_REGS_BASE)->cspr_cs[FSL_IFC_CS0].cspr_ext, FSL_IFC_NOR_CSPR_EXT);
- MmioWriteBe32((UINTN) &(FSL_IFC_REGS_BASE)->ftim_cs[FSL_IFC_CS0].ftim[FSL_IFC_FTIM0], FSL_IFC_NOR_FTIM0);
- MmioWriteBe32((UINTN) &(FSL_IFC_REGS_BASE)->ftim_cs[FSL_IFC_CS0].ftim[FSL_IFC_FTIM1], FSL_IFC_NOR_FTIM1);
- MmioWriteBe32((UINTN) &(FSL_IFC_REGS_BASE)->ftim_cs[FSL_IFC_CS0].ftim[FSL_IFC_FTIM2], FSL_IFC_NOR_FTIM2);
- MmioWriteBe32((UINTN) &(FSL_IFC_REGS_BASE)->ftim_cs[FSL_IFC_CS0].ftim[FSL_IFC_FTIM3], FSL_IFC_NOR_FTIM3);
- MmioWriteBe32((UINTN) &(FSL_IFC_REGS_BASE)->cspr_cs[FSL_IFC_CS0].cspr, FSL_IFC_NOR_CSPR0);
- MmioWriteBe32((UINTN) &(FSL_IFC_REGS_BASE)->amask_cs[FSL_IFC_CS0].amask, FSL_IFC_NOR_AMASK0);
- MmioWriteBe32((UINTN) &(FSL_IFC_REGS_BASE)->csor_cs[FSL_IFC_CS0].csor, FSL_IFC_NOR_CSOR0);
+}
+VOID +CciConfigureQos (
- struct CcsrCci400 *CciBase
- )
+{
// FIXME: Empty for now. Populate if required later.
return;
+}
+VOID +Cci400Init (
- VOID
- )
+{
struct CcsrCci400 *Base = (struct CcsrCci400 *)LS1043A_CCI400_ADDR;
/* Set CCI-400 control override register to enable barrier transaction */
MmioWrite32((UINTN)&Base->ctrl_ord, CCI400_CTRLORD_EN_BARRIER);
CciConfigureSnoopDvm(Base);
CciConfigureQos(Base);
+}
+/**
- Initialize the Secure peripherals and memory regions
- If Trustzone is supported by your platform then this function makes the required initialization
- of the secure peripherals and memory regions.
+**/ +VOID +Tzc380Init (
- VOID
- )
+{
- // Setup TZ Address Space Controller.
- // Assumption: We have 2GB DDR mounted on the DIMMs.
- //
- // Since, we need ONE secure DDR region which will be used for keeping
- // the PPA (EL3 platform security fw) code and the rest of the regions
- // would be non-secure regions which can be accessed via NS software as
- // well - so we create one TZASC region of 2GB and divided it into
- // 8 equal su-regions. Now, we keep the 1st sub-regions for housing
- // the PPA and use the rest of the sub-regions to allow NS accesses.
- // Note: Your OS Kernel must be aware of the secure regions before to
- // enable this region
- TZASCSetRegion(LS1043A_TZASC380_ADDR, 1, TZASC_REGION_ENABLED, LS1043A_DRAM1_BASE_ADDR, 0,
TZASC_REGION_SIZE_2GB, TZASC_REGION_SECURITY_SRW, 0x7F);
+}
+VOID +EnableDevicesNsAccess (
- OUT struct CsuNsDev *NonSecureDevices,
- IN UINT32 Num
- )
+{
UINT32 *Base = (UINT32 *)LS1043A_CSU_ADDR;
UINT32 *Reg;
UINT32 Val;
UINT32 Count;
for (Count = 0; Count < Num; Count++) {
Reg = Base + NonSecureDevices[Count].Ind / 2;
Val = MmioReadBe32((UINTN)Reg);
if (NonSecureDevices[Count].Ind % 2 == 0) {
Val &= 0x0000ffff;
Val |= NonSecureDevices[Count].Val << 16;
} else {
Val &= 0xffff0000;
Val |= NonSecureDevices[Count].Val;
}
MmioWriteBe32((UINTN)Reg, Val);
}
+}
+VOID +CsuInit (
- VOID
- )
+{
EnableDevicesNsAccess(NonSecureDevices, ARRAY_SIZE(NonSecureDevices));
+}
VOID GetSysInfo ( OUT struct SysInfo *PtrSysInfo ) {
struct CcsrGur *GurBase = (void *)(LS1043A_FSL_GUTS_ADDR);
struct CcsrClk *ClkBase = (void *)(LS1043A_FSL_CLK_ADDR);
struct CcsrGur *GurBase = (void *)(LS1043A_GUTS_ADDR);
struct CcsrClk *ClkBase = (void *)(LS1043A_CLK_ADDR); UINTN CpuIndex; UINT32 TempRcw; const UINT8 CoreCplxPll[8] = {
@@ -57,8 +264,8 @@ GetSysInfo ( };
UINTN PllCount;
UINTN FreqCPll[LS1043A_FSL_NUM_CC_PLLS];
UINTN PllRatio[LS1043A_FSL_NUM_CC_PLLS];
UINTN FreqCPll[LS1043A_NUM_CC_PLLS];
UINTN PllRatio[LS1043A_NUM_CC_PLLS]; UINTN SysClk = LS1043A_CLK_FREQ; PtrSysInfo->FreqSystemBus = SysClk;
@@ -71,7 +278,7 @@ GetSysInfo ( FSL_CHASSIS2_RCWSR0_MEM_PLL_RAT_SHIFT) & FSL_CHASSIS2_RCWSR0_MEM_PLL_RAT_MASK;
for (PllCount = 0; PllCount < LS1043A_FSL_NUM_CC_PLLS; PllCount++) {
for (PllCount = 0; PllCount < LS1043A_NUM_CC_PLLS; PllCount++) { PllRatio[PllCount] = (MmioReadBe32((UINTN)&ClkBase->pllcgsr[PllCount].pllcngsr) >> 1) & 0xff; if (PllRatio[PllCount] > 4) FreqCPll[PllCount] = SysClk * PllRatio[PllCount];
@@ -112,6 +319,461 @@ GetSysInfo ( PtrSysInfo->FreqQman = PtrSysInfo->FreqSystemBus / 2; }
+VOID +ClockInit (
- VOID
- )
+{
struct SysInfo SocSysInfo;
GetSysInfo(&SocSysInfo);
gClkInfo.CpuClk = SocSysInfo.FreqProcessor[0];
gClkInfo.BusClk = SocSysInfo.FreqSystemBus;
gClkInfo.MemClk = SocSysInfo.FreqDdrBus;
gClkInfo.SdhcClk = SocSysInfo.FreqSdhc;
+}
+INTN +TimerInit (
- VOID
- )
+{
UINT32 *TimerBase = (UINT32 *)LS1043A_TIMER_ADDR;
if (PcdGetBool(PcdCounterFrequencyReal)) {
UINTN cntfrq = PcdGet32(PcdCounterFrequency);
/* Update with accurate clock frequency */
asm volatile("msr cntfrq_el0, %0" : : "r" (cntfrq) : "memory");
}
/* Enable clock for timer. This is a global setting. */
MmioWrite32((UINTN)TimerBase, 0x1);
return 0;
+}
+static inline +UINT32 +InitiatorType (
- IN UINT32 Cluster,
- IN UINTN InitId
- )
+{
struct CcsrGur *GurBase = (void *)(LS1043A_GUTS_ADDR);
UINT32 Idx = (Cluster >> (InitId * 8)) & TP_CLUSTER_INIT_MASK;
UINT32 Type = MmioReadBe32((UINTN)&GurBase->tp_ityp[Idx]);
if (Type & TP_ITYP_AV)
return Type;
return 0;
+}
+UINT32 +CpuMask (
- VOID
- )
+{
struct CcsrGur *GurBase = (void *)(LS1043A_GUTS_ADDR);
UINTN ClusterIndex = 0, Count = 0;
UINT32 Cluster, Type, Mask = 0;
do {
UINTN InitiatorIndex;
Cluster = MmioReadBe32((UINTN)&GurBase->tp_cluster[ClusterIndex].lower);
for (InitiatorIndex = 0; InitiatorIndex < TP_INIT_PER_CLUSTER; InitiatorIndex++) {
Type = InitiatorType(Cluster, InitiatorIndex);
if (Type) {
if (TP_ITYP_TYPE(Type) == TP_ITYP_TYPE_ARM)
Mask |= 1 << Count;
Count++;
}
}
ClusterIndex++;
} while ((Cluster & TP_CLUSTER_EOC_MASK) == 0x0);
return Mask;
+}
+/*
- Return the number of cores on this SOC.
- */
+UINTN +CpuNumCores (
- VOID
- )
+{
return HammingWeight32(CpuMask());
+}
+UINT32 +QoriqCoreToType (
- IN UINTN Core
- )
+{
struct CcsrGur *GurBase = (VOID *)(LS1043A_GUTS_ADDR);
UINTN ClusterIndex = 0, Count = 0;
UINT32 Cluster, Type;
do {
UINTN InitiatorIndex;
Cluster = MmioReadBe32((UINTN)&GurBase->tp_cluster[ClusterIndex].lower);
for (InitiatorIndex = 0; InitiatorIndex < TP_INIT_PER_CLUSTER; InitiatorIndex++) {
Type = InitiatorType(Cluster, InitiatorIndex);
if (Type) {
if (Count == Core)
return Type;
Count++;
}
}
ClusterIndex++;
} while ((Cluster & TP_CLUSTER_EOC_MASK) == 0x0);
return -1; /* cannot identify the cluster */
+}
+VOID +PrintCpuInfo (
- VOID
- )
+{
struct SysInfo SysInfo;
UINTN CoreIndex, Core;
UINT32 Type;
CHAR8 Buf[32];
CHAR8 Buffer[100];
UINTN CharCount;
GetSysInfo(&SysInfo);
CharCount = AsciiSPrint (Buffer, sizeof (Buffer), "Clock Configuration:");
SerialPortWrite ((UINT8 *) Buffer, CharCount);
ForEachCpu(CoreIndex, Core, CpuNumCores(), CpuMask()) {
if (!(CoreIndex % 3))
DEBUG((EFI_D_INFO, "\n "));
Type = TP_ITYP_VER(QoriqCoreToType(Core));
CharCount = AsciiSPrint (Buffer, sizeof (Buffer), "CPU%d(%a):%-4a MHz ", Core,
Type == TY_ITYP_VER_A53 ? "A53" : "Unknown Core",
StringToMHz(Buf, SysInfo.FreqProcessor[Core]));
SerialPortWrite ((UINT8 *) Buffer, CharCount);
}
CharCount = AsciiSPrint (Buffer, sizeof (Buffer), "\n Bus: %-4a MHz ",
StringToMHz(Buf, SysInfo.FreqSystemBus));
SerialPortWrite ((UINT8 *) Buffer, CharCount);
CharCount = AsciiSPrint (Buffer, sizeof (Buffer), "DDR: %-4a MHz", StringToMHz(Buf, SysInfo.FreqDdrBus));
SerialPortWrite ((UINT8 *) Buffer, CharCount);
CharCount = AsciiSPrint (Buffer, sizeof (Buffer), "\n");
SerialPortWrite ((UINT8 *) Buffer, CharCount);
+}
+VOID +PrintSocPersonality (
- VOID
- )
+{ +}
+VOID +IfcInit (
- VOID
- )
+{
/* NOR Init */
IfcNorInit();
/* CPLD Init */
CpldInit();
+}
+VOID +PrintBoardPersonality (
- VOID
- )
+{
static const char *Freq[3] = {"100.00MHZ", "156.25MHZ"};
UINT8 RcwSrc1, RcwSrc2;
UINT32 RcwSrc;
UINT32 sd1refclk_sel;
DEBUG((EFI_D_INFO, "Board: LS1043ARDB, boot from "));
RcwSrc1 = CPLD_READ(RcwSource1);
RcwSrc2 = CPLD_READ(RcwSource1);
CpldRevBit(&RcwSrc1);
RcwSrc = RcwSrc1;
RcwSrc = (RcwSrc << 1) | RcwSrc2;
if (RcwSrc == 0x25)
DEBUG((EFI_D_INFO, "vBank %d\n", CPLD_READ(Vbank)));
else if (RcwSrc == 0x106)
DEBUG((EFI_D_INFO, "NAND\n"));
else
DEBUG((EFI_D_INFO, "Invalid setting of SW4\n"));
DEBUG((EFI_D_INFO, "CPLD: V%x.%x\nPCBA: V%x.0\n", CPLD_READ(CpldVersionMajor),
CPLD_READ(CpldVersionMinor), CPLD_READ(PcbaVersion)));
DEBUG((EFI_D_INFO, "SERDES Reference Clocks:\n"));
sd1refclk_sel = CPLD_READ(Sd1RefClkSel);
DEBUG((EFI_D_INFO, "SD1_CLK1 = %a, SD1_CLK2 = %a\n", Freq[sd1refclk_sel], Freq[0]));
+}
+VOID +PrintRCW (
- VOID
- )
+{
struct CcsrGur *Base = (void *)(LS1043A_GUTS_ADDR);
UINTN Count;
CHAR8 Buffer[100];
UINTN CharCount;
/*
* Display the RCW, so that no one gets confused as to what RCW
* we're actually using for this boot.
*/
CharCount = AsciiSPrint (Buffer, sizeof (Buffer),
"Reset Configuration Word (RCW):");
SerialPortWrite ((UINT8 *) Buffer, CharCount);
for (Count = 0; Count < ARRAY_SIZE(Base->rcwsr); Count++) {
UINT32 Rcw = MmioReadBe32((UINTN)&Base->rcwsr[Count]);
if ((Count % 4) == 0) {
CharCount = AsciiSPrint (Buffer, sizeof (Buffer),
"\n %08x:", Count * 4);
SerialPortWrite ((UINT8 *) Buffer, CharCount);
}
CharCount = AsciiSPrint (Buffer, sizeof (Buffer), " %08x", Rcw);
SerialPortWrite ((UINT8 *) Buffer, CharCount);
}
CharCount = AsciiSPrint (Buffer, sizeof (Buffer), "\n");
SerialPortWrite ((UINT8 *) Buffer, CharCount);
+}
+VOID +SmmuInit (
- VOID
- )
+{
UINT32 Value;
/* set pagesize as 64K and ssmu-500 in bypass mode */
Value = (MmioRead32((UINTN)SMMU_REG_SACR) | SACR_PAGESIZE_MASK);
MmioWrite32((UINTN)SMMU_REG_SACR, Value);
Value = (MmioRead32((UINTN)SMMU_REG_SCR0) | SCR0_CLIENTPD_MASK) & ~(SCR0_USFCFG_MASK);
MmioWrite32((UINTN)SMMU_REG_SCR0, Value);
Value = (MmioRead32((UINTN)SMMU_REG_NSCR0) | SCR0_CLIENTPD_MASK) & ~(SCR0_USFCFG_MASK);
MmioWrite32((UINTN)SMMU_REG_NSCR0, Value);
+}
+/**
- Function to initialize SoC specific constructs
- // CSU
- // TZC-380
- // CCI-400
- // ClockInit
- // TimerInit
- // CPU Info
- // SoC Personality
- // Board Personality
- // RCW prints
- // SerDes support
- **/
+VOID +SocInit (
- VOID
- )
+{
- CHAR8 Buffer[100];
- UINTN CharCount;
- // LS1043A SoC has a CSU (Central Security Unit)
- if (PcdGetBool(PcdCsuInitialize))
CsuInit();
- if (PcdGetBool(PcdTzc380Initialize))
Tzc380Init();
- if (PcdGetBool(PcdCci400Initialize))
Cci400Init();
- if (PcdGetBool(PcdClockInitialize))
ClockInit();
- SmmuInit();
- TimerInit();
- // Initialize the Serial Port
- SerialPortInitialize ();
- CharCount = AsciiSPrint (Buffer, sizeof (Buffer), "\nUEFI firmware (version %s built at %a on %a)\n\r",
- (CHAR16*)PcdGetPtr(PcdFirmwareVersionString), __TIME__, __DATE__);
- SerialPortWrite ((UINT8 *) Buffer, CharCount);
- PrintCpuInfo();
- PrintRCW();
- PrintSocPersonality();
- IfcInit();
- PrintBoardPersonality();
- SerDesInit();
- return;
+}
+/* fdt fixup for LS1043A */
+VOID +FixupByCompatibleField (
- VOID *Fdt,
- CONST char *Compat,
- CONST char *Prop,
- CONST VOID *Val,
- INTN Len,
- INTN Create
- )
+{
INTN Offset = -1;
Offset = fdt_node_offset_by_compatible(Fdt, -1, Compat);
while (Offset != -FDT_ERR_NOTFOUND) {
if (Create || (fdt_get_property(Fdt, Offset, Prop, NULL) != NULL))
fdt_setprop(Fdt, Offset, Prop, Val, Len);
Offset = fdt_node_offset_by_compatible(Fdt, Offset, Compat);
}
+}
+VOID +FixupByCompatibleField32 (
- VOID *Fdt,
- CONST char *Compat,
- CONST char *Prop,
- UINT32 Val,
- INTN Create
- )
+{
fdt32_t Tmp = cpu_to_fdt32(Val);
FixupByCompatibleField(Fdt, Compat, Prop, &Tmp, 4, Create);
+}
+#define BMAN_IP_REV_1 0xBF8 +#define BMAN_IP_REV_2 0xBFC +VOID +FdtFixupBmanPortals (
- VOID *Blob
- )
+{
UINTN Off, Err;
UINTN Maj, Min;
UINTN IpCfg;
UINT32 BmanRev1 = MmioReadBe32(LS1043A_BMAN_ADDR + BMAN_IP_REV_1);
UINT32 BmanRev2 = MmioReadBe32(LS1043A_BMAN_ADDR + BMAN_IP_REV_2);
char Compatible[64];
INTN CompatibleLength;
Maj = (BmanRev1 >> 8) & 0xff;
Min = BmanRev1 & 0xff;
IpCfg = BmanRev2 & 0xff;
CompatibleLength = AsciiSPrint(Compatible, sizeof(Compatible),
"fsl,bman-portal-%u.%u.%u",
Maj, Min, IpCfg) + 1;
CompatibleLength += AsciiSPrint(Compatible + CompatibleLength,
sizeof(Compatible), "fsl,bman-portal")
+ 1;
Off = fdt_node_offset_by_compatible(Blob, -1, "fsl,bman-portal");
while (Off != -FDT_ERR_NOTFOUND) {
Err = fdt_setprop(Blob, Off, "compatible", Compatible,
CompatibleLength);
if (Err < 0) {
DEBUG((EFI_D_ERROR, "ERROR: unable to create props for %a: %s\n",
fdt_get_name(Blob, Off, NULL), fdt_strerror(Err)));
return;
}
Off = fdt_node_offset_by_compatible(Blob, Off, "fsl,bman-portal");
}
+}
+#define QMAN_IP_REV_1 0xBF8 +#define QMAN_IP_REV_2 0xBFC +VOID +FdtFixupQmanPortals (
- VOID *Blob
- )
+{
INTN Off, Err;
UINTN Maj, Min;
UINTN IpCfg;
UINT32 QmanRev1 = MmioReadBe32(LS1043A_QMAN_ADDR + QMAN_IP_REV_1);
UINT32 QmanRev2 = MmioReadBe32(LS1043A_QMAN_ADDR + QMAN_IP_REV_2);
char Compatible[64];
INTN CompatLength;
Maj = (QmanRev1 >> 8) & 0xff;
Min = QmanRev1 & 0xff;
IpCfg = QmanRev2 & 0xff;
CompatLength = AsciiSPrint(Compatible, sizeof(Compatible),
"fsl,qman-portal-%u.%u.%u",
Maj, Min, IpCfg) + 1;
CompatLength += AsciiSPrint(Compatible + CompatLength,
sizeof(Compatible), "fsl,qman-portal") + 1;
Off = fdt_node_offset_by_compatible(Blob, -1, "fsl,qman-portal");
while (Off != -FDT_ERR_NOTFOUND) {
Err = fdt_setprop(Blob, Off, "compatible", Compatible,
CompatLength);
if (Err < 0) {
DEBUG((EFI_D_ERROR, "ERROR: unable to create props for %a: %a\n",
fdt_get_name(Blob, Off, NULL), fdt_strerror(Err)));
return;
}
Off = fdt_node_offset_by_compatible(Blob, Off, "fsl,qman-portal");
}
+}
+VOID +FdtFixupSdhc (
- VOID *Blob,
- UINTN SdhcClk
- )
+{
const char *Compatible = "fsl,esdhc";
FixupByCompatibleField32(Blob, Compatible, "clock-frequency", SdhcClk, 1);
FixupByCompatibleField(Blob, Compatible, "status", "okay", 4 + 1, 1);
+}
+VOID FdtCpuSetup(VOID *blob) +{
struct SysInfo SocSysInfo;
GetSysInfo(&SocSysInfo);
FixupByCompatibleField32(blob, "fsl,ns16550",
"clock-frequency", SocSysInfo.FreqSystemBus, 1);
FdtFixupSdhc(blob, SocSysInfo.FreqSdhc);
FdtFixupBmanPortals(blob);
FdtFixupQmanPortals(blob);
FixupByCompatibleField32(blob, "fsl,qman",
"clock-frequency", SocSysInfo.FreqQman, 1);
+}
UINT32 CalculateBaudDivisor ( @@ -135,6 +797,6 @@ CalculateI2cClockRate( struct SysInfo SocSysInfo;
GetSysInfo(&SocSysInfo);
return SocSysInfo.FreqSystemBus;
return SocSysInfo.FreqSystemBus;
} diff --git a/Platforms/Nxp/LS1043aRdb/Library/LS1043aSocLib/LS1043aSocLib.inf b/Platforms/Nxp/LS1043aRdb/Library/LS1043aSocLib/LS1043aSocLib.inf index 322fe34..307cf21 100644 --- a/Platforms/Nxp/LS1043aRdb/Library/LS1043aSocLib/LS1043aSocLib.inf +++ b/Platforms/Nxp/LS1043aRdb/Library/LS1043aSocLib/LS1043aSocLib.inf @@ -29,12 +29,25 @@ OpenPlatformPkg/Chips/Nxp/QoriqLs/NxpQoriqLs.dec
[LibraryClasses]
- ArmTrustZoneLib BaseLib CpldLib DebugLib DebugAgentLib IoLib ArmLib
- MemoryAllocationLib
- SerialPortLib
[Sources.common] LS1043aSocLib.c
- LsSerDes.c
+[FixedPcd]
- gEfiMdeModulePkgTokenSpaceGuid.PcdFirmwareVersionString
- gArmPlatformTokenSpaceGuid.PcdCounterFrequencyReal
- gArmPlatformTokenSpaceGuid.PcdCsuInitialize
- gArmPlatformTokenSpaceGuid.PcdTzc380Initialize
- gArmPlatformTokenSpaceGuid.PcdCci400Initialize
- gArmPlatformTokenSpaceGuid.PcdClockInitialize
- gArmPlatformTokenSpaceGuid.PcdCounterFrequency
diff --git a/Platforms/Nxp/LS1043aRdb/Library/LS1043aSocLib/LsSerDes.c b/Platforms/Nxp/LS1043aRdb/Library/LS1043aSocLib/LsSerDes.c new file mode 100644 index 0000000..3312e9b --- /dev/null +++ b/Platforms/Nxp/LS1043aRdb/Library/LS1043aSocLib/LsSerDes.c @@ -0,0 +1,195 @@ +/** LsSerDes.c
- Provides the basic interfaces for SerDes Module
- Copyright (c) 2016, Freescale Semiconductor, Inc. All rights reserved.
- This program and the accompanying materials
- are licensed and made available under the terms and conditions of the BSD License
- which accompanies this distribution. The full text of the license may be found
- http://opensource.org/licenses/bsd-license.php
- THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
- WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
+**/
+#include <Uefi.h> +#include <Library/PlatformLib.h> +#include <Library/SocLib.h> +#include <Library/DebugLib.h> +#include <Library/DebugAgentLib.h> +#include <Library/IoLib.h> +#include <Library/Ls1043aSerDes.h>
+#ifdef LS1043A_SRDS_1 +static UINT16 SerDes1PrtclMap[SERDES_PRCTL_COUNT]; +#endif
+static struct SerDesConfig *SerDesConfigTbl[] = {
SerDes1ConfigTbl
+};
+SrdsPrtcl +GetSerDesPrtcl +(
- IN INTN SerDes,
- IN INTN Cfg,
- IN INTN Lane
+) +{
- struct SerDesConfig *Config;
- if (SerDes >= ARRAY_SIZE(SerDesConfigTbl))
- return 0;
- Config = SerDesConfigTbl[SerDes];
- while (Config->Protocol) {
- if (Config->Protocol == Cfg) {
return Config->SrdsLane[Lane];
- }
- Config++;
- }
- return EFI_SUCCESS;
+}
+EFI_STATUS +CheckSerDesPrtclValid +(
- IN INTN SerDes,
- IN UINT32 Prtcl
+) +{
- INTN Cnt;
- struct SerDesConfig *Config;
- if (SerDes >= ARRAY_SIZE(SerDesConfigTbl))
- return 0;
- Config = SerDesConfigTbl[SerDes];
- while (Config->Protocol) {
- if (Config->Protocol == Prtcl) {
DEBUG((EFI_D_INFO, "Protocol: %x Matched with the one in Table\n", Prtcl));
break;
- }
- Config++;
- }
- if (!Config->Protocol)
- return 0;
- for (Cnt = 0; Cnt < SRDS_MAX_LANES; Cnt++) {
- if (Config->SrdsLane[Cnt] != NONE)
return 1;
- }
- return 0;
+}
+EFI_STATUS +IsSerDesConfigured +(
- IN SrdsPrtcl Device
+) +{
- INTN Ret = 0;
+#ifdef LS1043A_SRDS_1
- Ret |= SerDes1PrtclMap[Device];
+#endif
- return !!Ret;
+}
+INTN +GetSerDesFirstLane +(
- IN UINT32 Sd,
- IN SrdsPrtcl Device
+) +{
- struct CcsrGur *Gur = (void *)(LS1043A_GUTS_ADDR);
- UINT32 Cfg = MmioReadBe32((UINTN)&Gur->rcwsr[4]);
- INTN Cnt;
- switch (Sd) {
+#ifdef LS1043A_SRDS_1
- case FSL_SRDS_1:
- Cfg &= LS1043_RCWSR4_SRDS1_PRTCL_MASK;
- Cfg >>= LS1043_RCWSR4_SRDS1_PRTCL_SHIFT;
- break;
+#endif
- default:
- DEBUG((EFI_D_INFO, "Invalid SerDes%d, Only one SerDes is there.\n", Sd));
- break;
- }
- /* Is serdes enabled at all? */
- if (Cfg == 0)
- return EFI_DEVICE_ERROR;
- for (Cnt = 0; Cnt < SRDS_MAX_LANES; Cnt++) {
- if (GetSerDesPrtcl(Sd, Cfg, Cnt) == Device)
return Cnt;
- }
- return EFI_DEVICE_ERROR;
+}
+VOID +LSSerDesInit +(
- UINT32 Srds,
- UINT32 SrdsAddr,
- UINT32 SrdsPrtclMask,
- UINT32 SrdsPrtclShift,
- UINT16 SerDesPrtclMap[SERDES_PRCTL_COUNT]
+) +{
- struct CcsrGur *Gur = (VOID *)(LS1043A_GUTS_ADDR);
- UINT32 SrdsProt;
- INTN Lane;
- UINT32 Flag = 0;
- SrdsProt = MmioReadBe32((UINTN)&Gur->rcwsr[4]) & SrdsPrtclMask;
- SrdsProt >>= SrdsPrtclShift;
- DEBUG((EFI_D_INFO, "Using SERDES%d Protocol: %d (0x%x)\n", Srds + 1, SrdsProt, SrdsProt));
- if (!CheckSerDesPrtclValid(Srds, SrdsProt)) {
- DEBUG((EFI_D_ERROR, "SERDES%d[PRTCL] = 0x%x is not valid\n", Srds + 1, SrdsProt));
- Flag++;
- }
- for (Lane = 0; Lane < SRDS_MAX_LANES; Lane++) {
- SrdsPrtcl LanePrtcl = GetSerDesPrtcl(Srds, SrdsProt, Lane);
- if (LanePrtcl >= SERDES_PRCTL_COUNT) {
DEBUG((EFI_D_ERROR, "Unknown SerDes lane protocol %d\n", LanePrtcl));
Flag++;
- } else {
SerDesPrtclMap[LanePrtcl] = 1;
- }
- }
- if (Flag)
- DEBUG((EFI_D_ERROR, "Could not configure SerDes module!!\n"));
- else
- DEBUG((EFI_D_INFO, "Successfully configured SerDes module!!\n"));
+}
+VOID +SerDesInit +(
- VOID
+) +{
- DEBUG((EFI_D_INFO, "Initializing SerDes....\n"));
+#ifdef LS1043A_SRDS_1
- LSSerDesInit(FSL_SRDS_1,
LS1043A_SERDES_ADDR,
LS1043_RCWSR4_SRDS1_PRTCL_MASK,
LS1043_RCWSR4_SRDS1_PRTCL_SHIFT,
SerDes1PrtclMap);
+#endif
+}
1.9.1
Hi Ard,
Thanks for the review comments. Please see my replies inline.
From: Ard Biesheuvel [mailto:ard.biesheuvel@linaro.org] Sent: Tuesday, October 18, 2016 3:22 PM
On 17 October 2016 at 21:04, Bhupesh Sharma bhupesh.sharma@freescale.com wrote:
From: Sakar Arora Sakar.Arora@nxp.com
This patch adds the functions that initialize the following IPs on
the
SoC:
- Central Security Unit (CSU) - Acts as a gatekeeper for secure and non-secure accesses via SW.
- TrustZone Address Space Controller (TZC-380).
- Interconnect (CCI-400).
- PLLs and Clocks.
- ARM Generic Timer.
In addition it also provides functions that print the following
useful
information:
- CPU Info
- SoC Personality.
- Board Personality.
- Reset Configuration Word (RCW).
- SerDes selection.
This looks like a mixed bag of functionality. Could you split this up please?
Ok.
Also, please elaborate in the commit log how you manage to configure these secure world peripherals from EL2,
Sure, it's because of the flaky flow we have currently where we start the UEFI firmware in EL3 exception level and then execute the platform and run-time security agent (PPA).
I will add this description in the commit log in detail.
Signed-off-by: Bhupesh Sharma bhupesh.sharma@nxp.com
.../Nxp/LS1043aRdb/Include/Library/Ls1043aSerDes.h | 89 +++ Platforms/Nxp/LS1043aRdb/Include/Library/SocLib.h | 203 ++++++- .../LS1043aRdb/Library/LS1043aRdbLib/LS1043aRdb.c | 2 + .../Library/LS1043aSocLib/LS1043aSocLib.c | 674
++++++++++++++++++++-
.../Library/LS1043aSocLib/LS1043aSocLib.inf | 13 + .../LS1043aRdb/Library/LS1043aSocLib/LsSerDes.c | 195 ++++++ 6 files changed, 1169 insertions(+), 7 deletions(-) create mode 100644 Platforms/Nxp/LS1043aRdb/Include/Library/Ls1043aSerDes.h create mode 100644 Platforms/Nxp/LS1043aRdb/Library/LS1043aSocLib/LsSerDes.c
diff --git a/Platforms/Nxp/LS1043aRdb/Include/Library/Ls1043aSerDes.h b/Platforms/Nxp/LS1043aRdb/Include/Library/Ls1043aSerDes.h new file mode 100644 index 0000000..181c268 --- /dev/null +++ b/Platforms/Nxp/LS1043aRdb/Include/Library/Ls1043aSerDes.h
is this an internal header? If so, please keep it with the .c files
Yes this is an internal header. I will keep it with the .c files.
@@ -0,0 +1,89 @@ +/** Ls1043aSerDes.h
- The Header file of SerDes Module
- Copyright (c) 2016, Freescale Semiconductor, Inc. All rights
reserved.
- This program and the accompanying materials are licensed and made
- available under the terms and conditions of the BSD License which
- accompanies this distribution. The full text of the license may be
- found http://opensource.org/licenses/bsd-license.php
- THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS"
- BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER
EXPRESS OR IMPLIED.
+**/
+#ifndef __LS1043A_SERDES_H +#define __LS1043A_SERDES_H
+#define SRDS_MAX_LANES 4
+#define LS1043_RCWSR4_SRDS1_PRTCL_MASK 0xFFFF0000 #define +LS1043_RCWSR4_SRDS1_PRTCL_SHIFT 16
+typedef enum {
NONE = 0,
PCIE1,
PCIE2,
PCIE3,
SATA1,
XFI1,
XFI2,
SGMII1,
SGMII2,
SGMII3,
SGMII4,
SGMII5,
SGMII6,
SGMII7,
SGMII8,
SGMII9,
QSGMII1,
QSGMII2,
SERDES_PRCTL_COUNT
+} SrdsPrtcl;
+enum Srds {
FSL_SRDS_1 = 0,
FSL_SRDS_2 = 1
+};
+struct SerDesConfig {
UINT16 Protocol;
UINT8 SrdsLane[SRDS_MAX_LANES]; };
+struct SerDesConfig SerDes1ConfigTbl[] = {
/* SerDes 1 */
{0x1555, {XFI1, PCIE1, PCIE2, PCIE3 } },
{0x1560, {XFI1, PCIE1, PCIE3, PCIE3 } },
{0x1460, {XFI1, QSGMII1, PCIE3, PCIE3 } },
{0x1360, {XFI1, SGMII2, PCIE3, PCIE3 } },
{0x2555, {SGMII9, PCIE1, PCIE2, PCIE3 } },
{0x4555, {QSGMII1, PCIE1, PCIE2, PCIE3 } },
{0x4558, {QSGMII1, PCIE1, PCIE2, SATA1 } },
{0x1355, {XFI1, SGMII2, PCIE2, PCIE3 } },
{0x1335, {XFI1, SGMII2, SGMII5, PCIE3 } },
{0x1333, {XFI1, SGMII2, SGMII5, SGMII6 } },
{0x2355, {SGMII9, SGMII2, PCIE2, PCIE3 } },
{0x2260, {SGMII9, SGMII2, PCIE3, PCIE3 } },
{0x2235, {SGMII9, SGMII2, SGMII5, PCIE3 } },
{0x2233, {SGMII9, SGMII2, SGMII5, SGMII6 } },
{0x3335, {SGMII9, SGMII2, SGMII5, PCIE3 } },
{0x3355, {SGMII9, SGMII2, PCIE2, PCIE3 } },
{0x3358, {SGMII9, SGMII2, PCIE2, SATA1 } },
{0x3360, {SGMII9, SGMII2, PCIE3, PCIE3 } },
{0x3560, {SGMII9, PCIE1, PCIE3, PCIE3 } },
{0x3555, {SGMII9, PCIE1, PCIE2, PCIE3 } },
{0x7000, {PCIE1, PCIE1, PCIE1, PCIE1 } },
{0x9998, {PCIE1, PCIE2, PCIE3, SATA1 } },
{0x6058, {PCIE1, PCIE1, PCIE2, SATA1 } },
{0x1455, {XFI1, QSGMII1, PCIE2, PCIE3 } },
{0x2455, {SGMII9, QSGMII1, PCIE2, PCIE3 } },
{0x2255, {SGMII9, SGMII2, PCIE2, PCIE3 } },
{0x3333, {SGMII9, SGMII2, SGMII5, SGMII6 } },
{0x3338, {SGMII9, SGMII2, SGMII5, SATA1 } },
{}
+};
+#endif /* __LS1043A_SERDES_H */ diff --git a/Platforms/Nxp/LS1043aRdb/Include/Library/SocLib.h b/Platforms/Nxp/LS1043aRdb/Include/Library/SocLib.h index d1655d5..dc798b3 100644 --- a/Platforms/Nxp/LS1043aRdb/Include/Library/SocLib.h +++ b/Platforms/Nxp/LS1043aRdb/Include/Library/SocLib.h @@ -22,14 +22,72 @@ #define HWA_CGA_M2_CLK_SEL 0x00000007 #define HWA_CGA_M2_CLK_SHIFT 0
+#define TP_ITYP_AV 0x00000001 /* Initiator
available */
+#define TP_ITYP_TYPE(x) (((x) & 0x6) >> 1) /*
Initiator Type */
+#define TP_ITYP_TYPE_ARM 0x0 +#define TP_ITYP_TYPE_PPC 0x1 /* PowerPC */ +#define TP_ITYP_TYPE_OTHER 0x2 /* StarCore DSP */ +#define TP_ITYP_TYPE_HA 0x3 /* HW
Accelerator */
+#define TP_ITYP_THDS(x) (((x) & 0x18) >> 3)
/* # threads */
+#define TP_ITYP_VER(x) (((x) & 0xe0) >> 5) /*
Initiator Version */
+#define TY_ITYP_VER_A53 0x2
+#define TP_CLUSTER_EOC_MASK 0xc0000000 /* end of clusters
mask */
+#define TP_CLUSTER_INIT_MASK 0x0000003f /* initiator mask */ +#define TP_INIT_PER_CLUSTER 4
#define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
#define LS1043A_CLK_FREQ 100000000 #define LS1043A_DDR_CLK_FREQ 100000000
#define LS1043A_MAX_CPUS 4 +#define LS1043A_FMAN_V3 #define LS1043A_NUM_FMAN 1 +#define LS1043A_NUM_FM1_DTSEC 7 +#define LS1043A_NUM_FM1_10GEC 1
+/*
- Divide positive or negative dividend by positive divisor and
round
- to closest UINTNeger. Result is undefined for negative divisors
+and
- for negative dividends if the divisor variable type is unsigned.
- */
+#define DIV_ROUND_CLOSEST(x, divisor)( \ +{ \
typeof(x) __x = x; \
typeof(divisor) __d = divisor; \
(((typeof(x))-1) > 0 || \
((typeof(divisor))-1) > 0 || (__x) > 0) ? \
(((__x) + ((__d) / 2)) / (__d)) : \
(((__x) - ((__d) / 2)) / (__d)); \
+} \ +)
+/*
- HammingWeight32: returns the hamming weight (i.e. the number
- of bits set) of a 32-bit word
- */
+static inline UINTN HammingWeight32(UINTN w) {
UINTN Res = (w & 0x55555555) + ((w >> 1) & 0x55555555);
Res = (Res & 0x33333333) + ((Res >> 2) & 0x33333333);
Res = (Res & 0x0F0F0F0F) + ((Res >> 4) & 0x0F0F0F0F);
Res = (Res & 0x00FF00FF) + ((Res >> 8) & 0x00FF00FF);
return (Res & 0x0000FFFF) + ((Res >> 16) & 0x0000FFFF); }
+static inline UINTN CpuMaskNext(UINTN Cpu, UINTN Mask) {
for (Cpu++; !((1 << Cpu) & Mask); Cpu++)
;
return Cpu;
+}
+#define ForEachCpu(iter, cpu, num_cpus, mask) \
for (iter = 0, cpu = CpuMaskNext(-1, mask); \
iter < num_cpus; \
iter++, cpu = CpuMaskNext(cpu, mask)) \
struct SysInfo { UINTN FreqProcessor[LS1043A_MAX_CPUS]; @@ -41,9 +99,122 @@ struct SysInfo { UINTN FreqQman; };
+typedef struct SocClocks {
UINTN CpuClk; /* CPU clock in Hz! */
UINTN BusClk;
UINTN MemClk;
UINTN PciClk;
UINTN SdhcClk;
+} SocClockInfo;
+enum PeriphClock {
ARM_CLK = 0,
BUS_CLK,
UART_CLK,
ESDHC_CLK,
I2C_CLK,
DSPI_CLK,
+};
+enum CsuCslxAccess {
SEC_UNIT_NS_SUP_R = 0x08,
SEC_UNIT_NS_SUP_W = 0x80,
SEC_UNIT_NS_SUP_RW = 0x88,
SEC_UNIT_NS_USER_R = 0x04,
SEC_UNIT_NS_USER_W = 0x40,
SEC_UNIT_NS_USER_RW = 0x44,
SEC_UNIT_S_SUP_R = 0x02,
SEC_UNIT_S_SUP_W = 0x20,
SEC_UNIT_S_SUP_RW = 0x22,
SEC_UNIT_S_USER_R = 0x01,
SEC_UNIT_S_USER_W = 0x10,
SEC_UNIT_S_USER_RW = 0x11,
SEC_UNIT_ALL_RW = 0xff,
+};
+enum CsuCslxInd {
SEC_UNIT_CSLX_PCIE2_IO = 0,
SEC_UNIT_CSLX_PCIE1_IO,
SEC_UNIT_CSLX_MG2TPR_IP,
SEC_UNIT_CSLX_IFC_MEM,
SEC_UNIT_CSLX_OCRAM,
SEC_UNIT_CSLX_GIC,
SEC_UNIT_CSLX_PCIE1,
SEC_UNIT_CSLX_OCRAM2,
SEC_UNIT_CSLX_QSPI_MEM,
SEC_UNIT_CSLX_PCIE2,
SEC_UNIT_CSLX_SATA,
SEC_UNIT_CSLX_USB1,
SEC_UNIT_CSLX_QM_BM_SWPORTAL,
SEC_UNIT_CSLX_PCIE3 = 16,
SEC_UNIT_CSLX_PCIE3_IO,
SEC_UNIT_CSLX_USB3 = 20,
SEC_UNIT_CSLX_USB2,
SEC_UNIT_CSLX_SERDES = 32,
SEC_UNIT_CSLX_QDMA,
SEC_UNIT_CSLX_LPUART2,
SEC_UNIT_CSLX_LPUART1,
SEC_UNIT_CSLX_LPUART4,
SEC_UNIT_CSLX_LPUART3,
SEC_UNIT_CSLX_LPUART6,
SEC_UNIT_CSLX_LPUART5,
SEC_UNIT_CSLX_DSPI1 = 41,
SEC_UNIT_CSLX_QSPI,
SEC_UNIT_CSLX_ESDHC,
SEC_UNIT_CSLX_IFC = 45,
SEC_UNIT_CSLX_I2C1,
SEC_UNIT_CSLX_I2C3 = 48,
SEC_UNIT_CSLX_I2C2,
SEC_UNIT_CSLX_DUART2 = 50,
SEC_UNIT_CSLX_DUART1,
SEC_UNIT_CSLX_WDT2,
SEC_UNIT_CSLX_WDT1,
SEC_UNIT_CSLX_EDMA,
SEC_UNIT_CSLX_SYS_CNT,
SEC_UNIT_CSLX_DMA_MUX2,
SEC_UNIT_CSLX_DMA_MUX1,
SEC_UNIT_CSLX_DDR,
SEC_UNIT_CSLX_QUICC,
SEC_UNIT_CSLX_DCFG_CCU_RCPM = 60,
SEC_UNIT_CSLX_SECURE_BOOTROM,
SEC_UNIT_CSLX_SFP,
SEC_UNIT_CSLX_TMU,
SEC_UNIT_CSLX_SECURE_MONITOR,
SEC_UNIT_CSLX_SCFG,
SEC_UNIT_CSLX_FM = 66,
SEC_UNIT_CSLX_SEC5_5,
SEC_UNIT_CSLX_BM,
SEC_UNIT_CSLX_QM,
SEC_UNIT_CSLX_GPIO2 = 70,
SEC_UNIT_CSLX_GPIO1,
SEC_UNIT_CSLX_GPIO4,
SEC_UNIT_CSLX_GPIO3,
SEC_UNIT_CSLX_PLATFORM_CONT,
SEC_UNIT_CSLX_SEC_UNIT,
SEC_UNIT_CSLX_IIC4 = 77,
SEC_UNIT_CSLX_WDT4,
SEC_UNIT_CSLX_WDT3,
SEC_UNIT_CSLX_WDT5 = 81,
SEC_UNIT_CSLX_FTM2 = 86,
SEC_UNIT_CSLX_FTM1,
SEC_UNIT_CSLX_FTM4,
SEC_UNIT_CSLX_FTM3,
SEC_UNIT_CSLX_FTM6 = 90,
SEC_UNIT_CSLX_FTM5,
SEC_UNIT_CSLX_FTM8,
SEC_UNIT_CSLX_FTM7,
SEC_UNIT_CSLX_DSCR = 120,
+};
+struct CsuNsDev {
UINTN Ind;
UINT32 Val;
+};
/* Device Configuration and Pin Control */ struct CcsrGur { UINT32 porsr1; /* POR status 1 */ +#define FSL_CHASSIS2_CCSR_PORSR1_RCW_MASK 0xFF800000 UINT32 porsr2; /* POR status 2 */ UINT8 res_008[0x20-0x8]; UINT32 gpporcr1; /* General-purpose POR
configuration */
@@ -51,6 +222,18 @@ struct CcsrGur { UINT32 dcfg_fusesr; /* Fuse status register */ UINT8 res_02c[0x70-0x2c]; UINT32 devdisr; /* Device disable control */ +#define FSL_CHASSIS2_DEVDISR2_DTSEC1_1 0x80000000 #define +FSL_CHASSIS2_DEVDISR2_DTSEC1_2 0x40000000 #define +FSL_CHASSIS2_DEVDISR2_DTSEC1_3 0x20000000 #define +FSL_CHASSIS2_DEVDISR2_DTSEC1_4 0x10000000 #define +FSL_CHASSIS2_DEVDISR2_DTSEC1_5 0x08000000 #define +FSL_CHASSIS2_DEVDISR2_DTSEC1_6 0x04000000 #define +FSL_CHASSIS2_DEVDISR2_DTSEC1_9 0x00800000 +#define FSL_CHASSIS2_DEVDISR2_DTSEC1_10 0x00400000 +#define FSL_CHASSIS2_DEVDISR2_10GEC1_1 0x00800000 #define +FSL_CHASSIS2_DEVDISR2_10GEC1_2 0x00400000 #define +FSL_CHASSIS2_DEVDISR2_10GEC1_3 0x80000000 #define +FSL_CHASSIS2_DEVDISR2_10GEC1_4 0x40000000 UINT32 devdisr2; /* Device disable control 2 */ UINT32 devdisr3; /* Device disable control 3 */ UINT32 devdisr4; /* Device disable control 4 */ @@ -83,6 +266,8 @@ struct CcsrGur { #define FSL_CHASSIS2_RCWSR0_SYS_PLL_RAT_MASK 0x1f #define FSL_CHASSIS2_RCWSR0_MEM_PLL_RAT_SHIFT 16 #define FSL_CHASSIS2_RCWSR0_MEM_PLL_RAT_MASK 0x3f +#define FSL_CHASSIS2_RCWSR4_SRDS1_PRTCL_MASK 0xffff0000 +#define FSL_CHASSIS2_RCWSR4_SRDS1_PRTCL_SHIFT 16 UINT8 res_140[0x200-0x140]; UINT32 scratchrw[4]; /* Scratch Read/Write */ UINT8 res_210[0x300-0x210]; @@ -259,6 +444,12 @@ struct CcsrClk { UINT8 res_c24[0x3dc]; };
+#define CCI400_CTRLORD_TERM_BARRIER 0x00000008 +#define CCI400_CTRLORD_EN_BARRIER 0 +#define CCI400_SHAORD_NON_SHAREABLE 0x00000002 +#define CCI400_DVM_MESSAGE_REQ_EN 0x00000002 +#define CCI400_SNOOP_REQ_EN 0x00000001
/* CCI-400 registers */ struct CcsrCci400 { UINT32 ctrl_ord; /* Control Override
*/
@@ -301,8 +492,18 @@ struct CcsrCci400 { UINT8 res_e004[0x10000 - 0xe004]; };
+VOID EnableDevicesNsAccess(struct CsuNsDev *NonSecureDevices, UINT32 +Num);
+VOID GetSysInfo(struct SysInfo *PtrSysInfo);
+VOID SocInit(VOID);
+VOID SerDesInit(VOID);
+VOID FdtCpuSetup(VOID *Blob);
UINT32 CalculateBaudDivisor(OUT UINT64 *BaudRate); -UINT32 CalculateI2cClockRate(VOID);
+UINT32 CalculateI2cClockRate(VOID);
#endif /* __LS1043A_SOC_H__ */ diff --git a/Platforms/Nxp/LS1043aRdb/Library/LS1043aRdbLib/LS1043aRdb.c b/Platforms/Nxp/LS1043aRdb/Library/LS1043aRdbLib/LS1043aRdb.c index 4fcb8a3..7c64709 100644 --- a/Platforms/Nxp/LS1043aRdb/Library/LS1043aRdbLib/LS1043aRdb.c +++ b/Platforms/Nxp/LS1043aRdb/Library/LS1043aRdbLib/LS1043aRdb.c @@ -24,6 +24,7 @@ #include <Library/PcdLib.h> #include <Ppi/ArmMpCoreInfo.h> #include <Library/PlatformLib.h> +#include <Library/SocLib.h>
/** Return the current Boot Mode @@ -47,6 +48,7 @@ ArmPlatformInitialize ( IN UINTN MpId ) {
- SocInit(); return RETURN_SUCCESS;
}
diff --git a/Platforms/Nxp/LS1043aRdb/Library/LS1043aSocLib/LS1043aSocLib.c b/Platforms/Nxp/LS1043aRdb/Library/LS1043aSocLib/LS1043aSocLib.c index fdeae08..2a7cb38 100644 --- a/Platforms/Nxp/LS1043aRdb/Library/LS1043aSocLib/LS1043aSocLib.c +++ b/Platforms/Nxp/LS1043aRdb/Library/LS1043aSocLib/LS1043aSocLib.c @@ -26,20 +26,227 @@ #include <Library/DebugAgentLib.h> #include <Library/IoLib.h> #include <Library/PrintLib.h> +#include <Library/SerialPortLib.h> +#include <Library/FslIfc.h>
+#include <Drivers/ArmTrustzone.h>
#include <Library/PlatformLib.h> #include <Library/SocLib.h> #include <Library/CpldLib.h>
+#include <libfdt.h>
+/* Global Clock Information pointer */ static SocClockInfo gClkInfo;
+static struct CsuNsDev NonSecureDevices[] = {
{SEC_UNIT_CSLX_PCIE2_IO, SEC_UNIT_ALL_RW},
{SEC_UNIT_CSLX_PCIE1_IO, SEC_UNIT_ALL_RW},
{SEC_UNIT_CSLX_MG2TPR_IP, SEC_UNIT_ALL_RW},
{SEC_UNIT_CSLX_IFC_MEM, SEC_UNIT_ALL_RW},
{SEC_UNIT_CSLX_OCRAM, SEC_UNIT_ALL_RW},
{SEC_UNIT_CSLX_GIC, SEC_UNIT_ALL_RW},
{SEC_UNIT_CSLX_PCIE1, SEC_UNIT_ALL_RW},
{SEC_UNIT_CSLX_OCRAM2, SEC_UNIT_ALL_RW},
{SEC_UNIT_CSLX_QSPI_MEM, SEC_UNIT_ALL_RW},
{SEC_UNIT_CSLX_PCIE2, SEC_UNIT_ALL_RW},
{SEC_UNIT_CSLX_SATA, SEC_UNIT_ALL_RW},
{SEC_UNIT_CSLX_USB1, SEC_UNIT_ALL_RW},
{SEC_UNIT_CSLX_QM_BM_SWPORTAL, SEC_UNIT_ALL_RW},
{SEC_UNIT_CSLX_PCIE3, SEC_UNIT_ALL_RW},
{SEC_UNIT_CSLX_PCIE3_IO, SEC_UNIT_ALL_RW},
{SEC_UNIT_CSLX_USB3, SEC_UNIT_ALL_RW},
{SEC_UNIT_CSLX_USB2, SEC_UNIT_ALL_RW},
{SEC_UNIT_CSLX_SERDES, SEC_UNIT_ALL_RW},
{SEC_UNIT_CSLX_QDMA, SEC_UNIT_ALL_RW},
{SEC_UNIT_CSLX_LPUART2, SEC_UNIT_ALL_RW},
{SEC_UNIT_CSLX_LPUART1, SEC_UNIT_ALL_RW},
{SEC_UNIT_CSLX_LPUART4, SEC_UNIT_ALL_RW},
{SEC_UNIT_CSLX_LPUART3, SEC_UNIT_ALL_RW},
{SEC_UNIT_CSLX_LPUART6, SEC_UNIT_ALL_RW},
{SEC_UNIT_CSLX_LPUART5, SEC_UNIT_ALL_RW},
{SEC_UNIT_CSLX_DSPI1, SEC_UNIT_ALL_RW},
{SEC_UNIT_CSLX_QSPI, SEC_UNIT_ALL_RW},
{SEC_UNIT_CSLX_ESDHC, SEC_UNIT_ALL_RW},
{SEC_UNIT_CSLX_IFC, SEC_UNIT_ALL_RW},
{SEC_UNIT_CSLX_I2C1, SEC_UNIT_ALL_RW},
{SEC_UNIT_CSLX_I2C3, SEC_UNIT_ALL_RW},
{SEC_UNIT_CSLX_I2C2, SEC_UNIT_ALL_RW},
{SEC_UNIT_CSLX_DUART2, SEC_UNIT_ALL_RW},
{SEC_UNIT_CSLX_DUART1, SEC_UNIT_ALL_RW},
{SEC_UNIT_CSLX_WDT2, SEC_UNIT_ALL_RW},
{SEC_UNIT_CSLX_WDT1, SEC_UNIT_ALL_RW},
{SEC_UNIT_CSLX_EDMA, SEC_UNIT_ALL_RW},
{SEC_UNIT_CSLX_SYS_CNT, SEC_UNIT_ALL_RW},
{SEC_UNIT_CSLX_DMA_MUX2, SEC_UNIT_ALL_RW},
{SEC_UNIT_CSLX_DMA_MUX1, SEC_UNIT_ALL_RW},
{SEC_UNIT_CSLX_DDR, SEC_UNIT_ALL_RW},
{SEC_UNIT_CSLX_QUICC, SEC_UNIT_ALL_RW},
{SEC_UNIT_CSLX_DCFG_CCU_RCPM, SEC_UNIT_ALL_RW},
{SEC_UNIT_CSLX_SECURE_BOOTROM, SEC_UNIT_ALL_RW},
{SEC_UNIT_CSLX_SFP, SEC_UNIT_ALL_RW},
{SEC_UNIT_CSLX_TMU, SEC_UNIT_ALL_RW},
{SEC_UNIT_CSLX_SECURE_MONITOR, SEC_UNIT_ALL_RW},
{SEC_UNIT_CSLX_SCFG, SEC_UNIT_ALL_RW},
{SEC_UNIT_CSLX_FM, SEC_UNIT_ALL_RW},
{SEC_UNIT_CSLX_SEC5_5, SEC_UNIT_ALL_RW},
{SEC_UNIT_CSLX_BM, SEC_UNIT_ALL_RW},
{SEC_UNIT_CSLX_QM, SEC_UNIT_ALL_RW},
{SEC_UNIT_CSLX_GPIO2, SEC_UNIT_ALL_RW},
{SEC_UNIT_CSLX_GPIO1, SEC_UNIT_ALL_RW},
{SEC_UNIT_CSLX_GPIO4, SEC_UNIT_ALL_RW},
{SEC_UNIT_CSLX_GPIO3, SEC_UNIT_ALL_RW},
{SEC_UNIT_CSLX_PLATFORM_CONT, SEC_UNIT_ALL_RW},
{SEC_UNIT_CSLX_SEC_UNIT, SEC_UNIT_ALL_RW},
{SEC_UNIT_CSLX_IIC4, SEC_UNIT_ALL_RW},
{SEC_UNIT_CSLX_WDT4, SEC_UNIT_ALL_RW},
{SEC_UNIT_CSLX_WDT3, SEC_UNIT_ALL_RW},
{SEC_UNIT_CSLX_WDT5, SEC_UNIT_ALL_RW},
{SEC_UNIT_CSLX_FTM2, SEC_UNIT_ALL_RW},
{SEC_UNIT_CSLX_FTM1, SEC_UNIT_ALL_RW},
{SEC_UNIT_CSLX_FTM4, SEC_UNIT_ALL_RW},
{SEC_UNIT_CSLX_FTM3, SEC_UNIT_ALL_RW},
{SEC_UNIT_CSLX_FTM6, SEC_UNIT_ALL_RW},
{SEC_UNIT_CSLX_FTM5, SEC_UNIT_ALL_RW},
{SEC_UNIT_CSLX_FTM8, SEC_UNIT_ALL_RW},
{SEC_UNIT_CSLX_FTM7, SEC_UNIT_ALL_RW},
{SEC_UNIT_CSLX_DSCR, SEC_UNIT_ALL_RW}, };
+char *StringToMHz (
- char *Buf,
- unsigned long Hz
- )
+{
long l, m, n;
n = DIV_ROUND_CLOSEST(Hz, 1000) / 1000L;
l = AsciiSPrint (Buf, sizeof(Buf), "%ld", n);
Hz -= n * 1000000L;
m = DIV_ROUND_CLOSEST(Hz, 1000L);
if (m != 0)
AsciiSPrint (Buf + l, sizeof(Buf), ".%03ld", m);
return (Buf);
+}
+VOID +CciConfigureSnoopDvm (
- struct CcsrCci400 *CciBase
- )
+{
// Enable snoop requests and DVM message requests for
// Slave insterface S4 (A53 core cluster)
MmioWrite32((UINTN)&CciBase->slave[4].snoop_ctrl,
CCI400_DVM_MESSAGE_REQ_EN |
+CCI400_SNOOP_REQ_EN); }
+VOID IfcNorInit(VOID) {
- MmioWriteBe32((UINTN)
+&(FSL_IFC_REGS_BASE)->cspr_cs[FSL_IFC_CS0].cspr_ext, +FSL_IFC_NOR_CSPR_EXT);
- MmioWriteBe32((UINTN)
- &(FSL_IFC_REGS_BASE)->ftim_cs[FSL_IFC_CS0].ftim[FSL_IFC_FTIM0],
- FSL_IFC_NOR_FTIM0);
- MmioWriteBe32((UINTN)
- &(FSL_IFC_REGS_BASE)->ftim_cs[FSL_IFC_CS0].ftim[FSL_IFC_FTIM1],
- FSL_IFC_NOR_FTIM1);
- MmioWriteBe32((UINTN)
- &(FSL_IFC_REGS_BASE)->ftim_cs[FSL_IFC_CS0].ftim[FSL_IFC_FTIM2],
- FSL_IFC_NOR_FTIM2);
- MmioWriteBe32((UINTN)
- &(FSL_IFC_REGS_BASE)->ftim_cs[FSL_IFC_CS0].ftim[FSL_IFC_FTIM3],
- FSL_IFC_NOR_FTIM3);
- MmioWriteBe32((UINTN)
+&(FSL_IFC_REGS_BASE)->cspr_cs[FSL_IFC_CS0].cspr, FSL_IFC_NOR_CSPR0);
- MmioWriteBe32((UINTN)
+&(FSL_IFC_REGS_BASE)->amask_cs[FSL_IFC_CS0].amask, +FSL_IFC_NOR_AMASK0);
- MmioWriteBe32((UINTN)
+&(FSL_IFC_REGS_BASE)->csor_cs[FSL_IFC_CS0].csor, FSL_IFC_NOR_CSOR0); +}
+VOID +CciConfigureQos (
- struct CcsrCci400 *CciBase
- )
+{
// FIXME: Empty for now. Populate if required later.
return;
+}
+VOID +Cci400Init (
- VOID
- )
+{
struct CcsrCci400 *Base = (struct CcsrCci400
+*)LS1043A_CCI400_ADDR;
/* Set CCI-400 control override register to enable barrier
transaction */
MmioWrite32((UINTN)&Base->ctrl_ord,
- CCI400_CTRLORD_EN_BARRIER);
CciConfigureSnoopDvm(Base);
CciConfigureQos(Base);
+}
+/**
- Initialize the Secure peripherals and memory regions
- If Trustzone is supported by your platform then this function
makes
- the required initialization of the secure peripherals and memory
regions.
+**/ +VOID +Tzc380Init (
- VOID
- )
+{
- // Setup TZ Address Space Controller.
- // Assumption: We have 2GB DDR mounted on the DIMMs.
- //
- // Since, we need ONE secure DDR region which will be used for
+keeping
- // the PPA (EL3 platform security fw) code and the rest of the
+regions
- // would be non-secure regions which can be accessed via NS
+software as
- // well - so we create one TZASC region of 2GB and divided it into
- // 8 equal su-regions. Now, we keep the 1st sub-regions for
housing
- // the PPA and use the rest of the sub-regions to allow NS
accesses.
- // Note: Your OS Kernel must be aware of the secure regions before
+to
- // enable this region
- TZASCSetRegion(LS1043A_TZASC380_ADDR, 1, TZASC_REGION_ENABLED,
LS1043A_DRAM1_BASE_ADDR, 0,
TZASC_REGION_SIZE_2GB, TZASC_REGION_SECURITY_SRW,
+0x7F); }
+VOID +EnableDevicesNsAccess (
- OUT struct CsuNsDev *NonSecureDevices,
- IN UINT32 Num
- )
+{
UINT32 *Base = (UINT32 *)LS1043A_CSU_ADDR;
UINT32 *Reg;
UINT32 Val;
UINT32 Count;
for (Count = 0; Count < Num; Count++) {
Reg = Base + NonSecureDevices[Count].Ind / 2;
Val = MmioReadBe32((UINTN)Reg);
if (NonSecureDevices[Count].Ind % 2 == 0) {
Val &= 0x0000ffff;
Val |= NonSecureDevices[Count].Val << 16;
} else {
Val &= 0xffff0000;
Val |= NonSecureDevices[Count].Val;
}
MmioWriteBe32((UINTN)Reg, Val);
}
+}
+VOID +CsuInit (
- VOID
- )
+{
EnableDevicesNsAccess(NonSecureDevices,
+ARRAY_SIZE(NonSecureDevices)); }
VOID GetSysInfo ( OUT struct SysInfo *PtrSysInfo ) {
struct CcsrGur *GurBase = (void *)(LS1043A_FSL_GUTS_ADDR);
struct CcsrClk *ClkBase = (void *)(LS1043A_FSL_CLK_ADDR);
struct CcsrGur *GurBase = (void *)(LS1043A_GUTS_ADDR);
struct CcsrClk *ClkBase = (void *)(LS1043A_CLK_ADDR); UINTN CpuIndex; UINT32 TempRcw; const UINT8 CoreCplxPll[8] = { @@ -57,8 +264,8 @@ GetSysInfo
(
}; UINTN PllCount;
UINTN FreqCPll[LS1043A_FSL_NUM_CC_PLLS];
UINTN PllRatio[LS1043A_FSL_NUM_CC_PLLS];
UINTN FreqCPll[LS1043A_NUM_CC_PLLS];
UINTN PllRatio[LS1043A_NUM_CC_PLLS]; UINTN SysClk = LS1043A_CLK_FREQ; PtrSysInfo->FreqSystemBus = SysClk; @@ -71,7 +278,7 @@
GetSysInfo ( FSL_CHASSIS2_RCWSR0_MEM_PLL_RAT_SHIFT) & FSL_CHASSIS2_RCWSR0_MEM_PLL_RAT_MASK;
for (PllCount = 0; PllCount < LS1043A_FSL_NUM_CC_PLLS;
PllCount++) {
for (PllCount = 0; PllCount < LS1043A_NUM_CC_PLLS;
PllCount++)
- { PllRatio[PllCount] = (MmioReadBe32((UINTN)&ClkBase-
pllcgsr[PllCount].pllcngsr) >> 1) & 0xff; if (PllRatio[PllCount] > 4) FreqCPll[PllCount] = SysClk * PllRatio[PllCount]; @@ -112,6 +319,461 @@ GetSysInfo ( PtrSysInfo->FreqQman = PtrSysInfo->FreqSystemBus / 2; }
+VOID +ClockInit (
- VOID
- )
+{
struct SysInfo SocSysInfo;
GetSysInfo(&SocSysInfo);
gClkInfo.CpuClk = SocSysInfo.FreqProcessor[0];
gClkInfo.BusClk = SocSysInfo.FreqSystemBus;
gClkInfo.MemClk = SocSysInfo.FreqDdrBus;
gClkInfo.SdhcClk = SocSysInfo.FreqSdhc; }
+INTN +TimerInit (
- VOID
- )
+{
UINT32 *TimerBase = (UINT32 *)LS1043A_TIMER_ADDR;
if (PcdGetBool(PcdCounterFrequencyReal)) {
UINTN cntfrq = PcdGet32(PcdCounterFrequency);
/* Update with accurate clock frequency */
asm volatile("msr cntfrq_el0, %0" : : "r" (cntfrq) :
"memory");
}
/* Enable clock for timer. This is a global setting. */
MmioWrite32((UINTN)TimerBase, 0x1);
return 0;
+}
+static inline +UINT32 +InitiatorType (
- IN UINT32 Cluster,
- IN UINTN InitId
- )
+{
struct CcsrGur *GurBase = (void *)(LS1043A_GUTS_ADDR);
UINT32 Idx = (Cluster >> (InitId * 8)) &
TP_CLUSTER_INIT_MASK;
UINT32 Type = MmioReadBe32((UINTN)&GurBase->tp_ityp[Idx]);
if (Type & TP_ITYP_AV)
return Type;
return 0;
+}
+UINT32 +CpuMask (
- VOID
- )
+{
struct CcsrGur *GurBase = (void *)(LS1043A_GUTS_ADDR);
UINTN ClusterIndex = 0, Count = 0;
UINT32 Cluster, Type, Mask = 0;
do {
UINTN InitiatorIndex;
Cluster = MmioReadBe32((UINTN)&GurBase-
tp_cluster[ClusterIndex].lower);
for (InitiatorIndex = 0; InitiatorIndex <
TP_INIT_PER_CLUSTER; InitiatorIndex++) {
Type = InitiatorType(Cluster,
InitiatorIndex);
if (Type) {
if (TP_ITYP_TYPE(Type) ==
TP_ITYP_TYPE_ARM)
Mask |= 1 << Count;
Count++;
}
}
ClusterIndex++;
} while ((Cluster & TP_CLUSTER_EOC_MASK) == 0x0);
return Mask;
+}
+/*
- Return the number of cores on this SOC.
- */
+UINTN +CpuNumCores (
- VOID
- )
+{
return HammingWeight32(CpuMask()); }
+UINT32 +QoriqCoreToType (
- IN UINTN Core
- )
+{
struct CcsrGur *GurBase = (VOID *)(LS1043A_GUTS_ADDR);
UINTN ClusterIndex = 0, Count = 0;
UINT32 Cluster, Type;
do {
UINTN InitiatorIndex;
Cluster = MmioReadBe32((UINTN)&GurBase-
tp_cluster[ClusterIndex].lower);
for (InitiatorIndex = 0; InitiatorIndex <
TP_INIT_PER_CLUSTER; InitiatorIndex++) {
Type = InitiatorType(Cluster,
InitiatorIndex);
if (Type) {
if (Count == Core)
return Type;
Count++;
}
}
ClusterIndex++;
} while ((Cluster & TP_CLUSTER_EOC_MASK) == 0x0);
return -1; /* cannot identify the cluster */
+}
+VOID +PrintCpuInfo (
- VOID
- )
+{
struct SysInfo SysInfo;
UINTN CoreIndex, Core;
UINT32 Type;
CHAR8 Buf[32];
CHAR8 Buffer[100];
UINTN CharCount;
GetSysInfo(&SysInfo);
CharCount = AsciiSPrint (Buffer, sizeof (Buffer), "Clock
Configuration:");
SerialPortWrite ((UINT8 *) Buffer, CharCount);
ForEachCpu(CoreIndex, Core, CpuNumCores(), CpuMask()) {
if (!(CoreIndex % 3))
DEBUG((EFI_D_INFO, "\n "));
Type = TP_ITYP_VER(QoriqCoreToType(Core));
CharCount = AsciiSPrint (Buffer, sizeof (Buffer),
"CPU%d(%a):%-4a MHz ", Core,
Type == TY_ITYP_VER_A53 ? "A53" : "Unknown
Core",
StringToMHz(Buf,
SysInfo.FreqProcessor[Core]));
SerialPortWrite ((UINT8 *) Buffer, CharCount);
}
CharCount = AsciiSPrint (Buffer, sizeof (Buffer), "\n
Bus: %-4a MHz ",
StringToMHz(Buf, SysInfo.FreqSystemBus));
SerialPortWrite ((UINT8 *) Buffer, CharCount);
CharCount = AsciiSPrint (Buffer, sizeof (Buffer), "DDR:
%-4a MHz", StringToMHz(Buf, SysInfo.FreqDdrBus));
SerialPortWrite ((UINT8 *) Buffer, CharCount);
CharCount = AsciiSPrint (Buffer, sizeof (Buffer), "\n");
SerialPortWrite ((UINT8 *) Buffer, CharCount); }
+VOID +PrintSocPersonality (
- VOID
- )
+{ +}
+VOID +IfcInit (
- VOID
- )
+{
/* NOR Init */
IfcNorInit();
/* CPLD Init */
CpldInit();
+}
+VOID +PrintBoardPersonality (
- VOID
- )
+{
static const char *Freq[3] = {"100.00MHZ", "156.25MHZ"};
UINT8 RcwSrc1, RcwSrc2;
UINT32 RcwSrc;
UINT32 sd1refclk_sel;
DEBUG((EFI_D_INFO, "Board: LS1043ARDB, boot from "));
RcwSrc1 = CPLD_READ(RcwSource1);
RcwSrc2 = CPLD_READ(RcwSource1);
CpldRevBit(&RcwSrc1);
RcwSrc = RcwSrc1;
RcwSrc = (RcwSrc << 1) | RcwSrc2;
if (RcwSrc == 0x25)
DEBUG((EFI_D_INFO, "vBank %d\n", CPLD_READ(Vbank)));
else if (RcwSrc == 0x106)
DEBUG((EFI_D_INFO, "NAND\n"));
else
DEBUG((EFI_D_INFO, "Invalid setting of SW4\n"));
DEBUG((EFI_D_INFO, "CPLD: V%x.%x\nPCBA: V%x.0\n",
CPLD_READ(CpldVersionMajor),
CPLD_READ(CpldVersionMinor),
CPLD_READ(PcbaVersion)));
DEBUG((EFI_D_INFO, "SERDES Reference Clocks:\n"));
sd1refclk_sel = CPLD_READ(Sd1RefClkSel);
DEBUG((EFI_D_INFO, "SD1_CLK1 = %a, SD1_CLK2 = %a\n",
+Freq[sd1refclk_sel], Freq[0])); }
+VOID +PrintRCW (
- VOID
- )
+{
struct CcsrGur *Base = (void *)(LS1043A_GUTS_ADDR);
UINTN Count;
CHAR8 Buffer[100];
UINTN CharCount;
/*
* Display the RCW, so that no one gets confused as to what
RCW
* we're actually using for this boot.
*/
CharCount = AsciiSPrint (Buffer, sizeof (Buffer),
"Reset Configuration Word (RCW):");
SerialPortWrite ((UINT8 *) Buffer, CharCount);
for (Count = 0; Count < ARRAY_SIZE(Base->rcwsr); Count++) {
UINT32 Rcw = MmioReadBe32((UINTN)&Base-
rcwsr[Count]);
if ((Count % 4) == 0) {
CharCount = AsciiSPrint (Buffer, sizeof
(Buffer),
"\n %08x:",
Count * 4);
SerialPortWrite ((UINT8 *) Buffer,
CharCount);
}
CharCount = AsciiSPrint (Buffer, sizeof (Buffer), "
%08x", Rcw);
SerialPortWrite ((UINT8 *) Buffer, CharCount);
}
CharCount = AsciiSPrint (Buffer, sizeof (Buffer), "\n");
SerialPortWrite ((UINT8 *) Buffer, CharCount); }
+VOID +SmmuInit (
- VOID
- )
+{
UINT32 Value;
/* set pagesize as 64K and ssmu-500 in bypass mode */
Value = (MmioRead32((UINTN)SMMU_REG_SACR) |
SACR_PAGESIZE_MASK);
MmioWrite32((UINTN)SMMU_REG_SACR, Value);
Value = (MmioRead32((UINTN)SMMU_REG_SCR0) |
SCR0_CLIENTPD_MASK) & ~(SCR0_USFCFG_MASK);
MmioWrite32((UINTN)SMMU_REG_SCR0, Value);
Value = (MmioRead32((UINTN)SMMU_REG_NSCR0) |
SCR0_CLIENTPD_MASK) & ~(SCR0_USFCFG_MASK);
MmioWrite32((UINTN)SMMU_REG_NSCR0, Value); }
+/**
- Function to initialize SoC specific constructs
- // CSU
- // TZC-380
- // CCI-400
- // ClockInit
- // TimerInit
- // CPU Info
- // SoC Personality
- // Board Personality
- // RCW prints
- // SerDes support
- **/
+VOID +SocInit (
- VOID
- )
+{
- CHAR8 Buffer[100];
- UINTN CharCount;
- // LS1043A SoC has a CSU (Central Security Unit) if
- (PcdGetBool(PcdCsuInitialize))
CsuInit();
- if (PcdGetBool(PcdTzc380Initialize))
Tzc380Init();
- if (PcdGetBool(PcdCci400Initialize))
Cci400Init();
- if (PcdGetBool(PcdClockInitialize))
ClockInit();
- SmmuInit();
- TimerInit();
- // Initialize the Serial Port
- SerialPortInitialize ();
- CharCount = AsciiSPrint (Buffer, sizeof (Buffer), "\nUEFI firmware
(version %s built at %a on %a)\n\r",
- (CHAR16*)PcdGetPtr(PcdFirmwareVersionString), __TIME__,
- __DATE__); SerialPortWrite ((UINT8 *) Buffer, CharCount);
- PrintCpuInfo();
- PrintRCW();
- PrintSocPersonality();
- IfcInit();
- PrintBoardPersonality();
- SerDesInit();
- return;
+}
+/* fdt fixup for LS1043A */
+VOID +FixupByCompatibleField (
- VOID *Fdt,
- CONST char *Compat,
- CONST char *Prop,
- CONST VOID *Val,
- INTN Len,
- INTN Create
- )
+{
INTN Offset = -1;
Offset = fdt_node_offset_by_compatible(Fdt, -1, Compat);
while (Offset != -FDT_ERR_NOTFOUND) {
if (Create || (fdt_get_property(Fdt, Offset, Prop,
NULL) != NULL))
fdt_setprop(Fdt, Offset, Prop, Val, Len);
Offset = fdt_node_offset_by_compatible(Fdt, Offset,
Compat);
}
+}
+VOID +FixupByCompatibleField32 (
- VOID *Fdt,
- CONST char *Compat,
- CONST char *Prop,
- UINT32 Val,
- INTN Create
- )
+{
fdt32_t Tmp = cpu_to_fdt32(Val);
FixupByCompatibleField(Fdt, Compat, Prop, &Tmp, 4, Create); }
+#define BMAN_IP_REV_1 0xBF8 +#define BMAN_IP_REV_2 0xBFC +VOID +FdtFixupBmanPortals (
- VOID *Blob
- )
+{
UINTN Off, Err;
UINTN Maj, Min;
UINTN IpCfg;
UINT32 BmanRev1 = MmioReadBe32(LS1043A_BMAN_ADDR +
BMAN_IP_REV_1);
UINT32 BmanRev2 = MmioReadBe32(LS1043A_BMAN_ADDR +
BMAN_IP_REV_2);
char Compatible[64];
INTN CompatibleLength;
Maj = (BmanRev1 >> 8) & 0xff;
Min = BmanRev1 & 0xff;
IpCfg = BmanRev2 & 0xff;
CompatibleLength = AsciiSPrint(Compatible,
sizeof(Compatible),
"fsl,bman-portal-%u.%u.%u",
Maj, Min, IpCfg) + 1;
CompatibleLength += AsciiSPrint(Compatible +
CompatibleLength,
sizeof(Compatible),
"fsl,bman-portal")
+ 1;
Off = fdt_node_offset_by_compatible(Blob, -1, "fsl,bman-
portal");
while (Off != -FDT_ERR_NOTFOUND) {
Err = fdt_setprop(Blob, Off, "compatible",
Compatible,
CompatibleLength);
if (Err < 0) {
DEBUG((EFI_D_ERROR, "ERROR: unable to create
props for %a: %s\n",
fdt_get_name(Blob, Off, NULL),
fdt_strerror(Err)));
return;
}
Off = fdt_node_offset_by_compatible(Blob, Off,
"fsl,bman-portal");
}
+}
+#define QMAN_IP_REV_1 0xBF8 +#define QMAN_IP_REV_2 0xBFC +VOID +FdtFixupQmanPortals (
- VOID *Blob
- )
+{
INTN Off, Err;
UINTN Maj, Min;
UINTN IpCfg;
UINT32 QmanRev1 = MmioReadBe32(LS1043A_QMAN_ADDR +
QMAN_IP_REV_1);
UINT32 QmanRev2 = MmioReadBe32(LS1043A_QMAN_ADDR +
QMAN_IP_REV_2);
char Compatible[64];
INTN CompatLength;
Maj = (QmanRev1 >> 8) & 0xff;
Min = QmanRev1 & 0xff;
IpCfg = QmanRev2 & 0xff;
CompatLength = AsciiSPrint(Compatible, sizeof(Compatible),
"fsl,qman-portal-%u.%u.%u",
Maj, Min, IpCfg) + 1;
CompatLength += AsciiSPrint(Compatible + CompatLength,
sizeof(Compatible),
- "fsl,qman-portal") + 1;
Off = fdt_node_offset_by_compatible(Blob, -1, "fsl,qman-
portal");
while (Off != -FDT_ERR_NOTFOUND) {
Err = fdt_setprop(Blob, Off, "compatible",
Compatible,
CompatLength);
if (Err < 0) {
DEBUG((EFI_D_ERROR, "ERROR: unable to create
props for %a: %a\n",
fdt_get_name(Blob, Off, NULL),
fdt_strerror(Err)));
return;
}
Off = fdt_node_offset_by_compatible(Blob, Off,
"fsl,qman-portal");
}
+}
+VOID +FdtFixupSdhc (
- VOID *Blob,
- UINTN SdhcClk
- )
+{
const char *Compatible = "fsl,esdhc";
FixupByCompatibleField32(Blob, Compatible, "clock-frequency",
- SdhcClk, 1);
FixupByCompatibleField(Blob, Compatible, "status", "okay", 4
+1, 1); }
+VOID FdtCpuSetup(VOID *blob) +{
struct SysInfo SocSysInfo;
GetSysInfo(&SocSysInfo);
FixupByCompatibleField32(blob, "fsl,ns16550",
"clock-frequency",
- SocSysInfo.FreqSystemBus, 1);
FdtFixupSdhc(blob, SocSysInfo.FreqSdhc);
FdtFixupBmanPortals(blob);
FdtFixupQmanPortals(blob);
FixupByCompatibleField32(blob, "fsl,qman",
"clock-frequency", SocSysInfo.FreqQman, 1); }
UINT32 CalculateBaudDivisor ( @@ -135,6 +797,6 @@ CalculateI2cClockRate( struct SysInfo SocSysInfo;
GetSysInfo(&SocSysInfo);
return SocSysInfo.FreqSystemBus;
return SocSysInfo.FreqSystemBus;
} diff --git a/Platforms/Nxp/LS1043aRdb/Library/LS1043aSocLib/LS1043aSocLib.inf b/Platforms/Nxp/LS1043aRdb/Library/LS1043aSocLib/LS1043aSocLib.inf index 322fe34..307cf21 100644
a/Platforms/Nxp/LS1043aRdb/Library/LS1043aSocLib/LS1043aSocLib.inf
+++
b/Platforms/Nxp/LS1043aRdb/Library/LS1043aSocLib/LS1043aSocLib.inf
@@ -29,12 +29,25 @@ OpenPlatformPkg/Chips/Nxp/QoriqLs/NxpQoriqLs.dec
[LibraryClasses]
- ArmTrustZoneLib BaseLib CpldLib DebugLib DebugAgentLib IoLib ArmLib
- MemoryAllocationLib
- SerialPortLib
[Sources.common] LS1043aSocLib.c
- LsSerDes.c
+[FixedPcd]
- gEfiMdeModulePkgTokenSpaceGuid.PcdFirmwareVersionString
- gArmPlatformTokenSpaceGuid.PcdCounterFrequencyReal
- gArmPlatformTokenSpaceGuid.PcdCsuInitialize
- gArmPlatformTokenSpaceGuid.PcdTzc380Initialize
- gArmPlatformTokenSpaceGuid.PcdCci400Initialize
- gArmPlatformTokenSpaceGuid.PcdClockInitialize
- gArmPlatformTokenSpaceGuid.PcdCounterFrequency
diff --git
a/Platforms/Nxp/LS1043aRdb/Library/LS1043aSocLib/LsSerDes.c
b/Platforms/Nxp/LS1043aRdb/Library/LS1043aSocLib/LsSerDes.c new file mode 100644 index 0000000..3312e9b --- /dev/null +++ b/Platforms/Nxp/LS1043aRdb/Library/LS1043aSocLib/LsSerDes.c @@ -0,0 +1,195 @@ +/** LsSerDes.c
- Provides the basic interfaces for SerDes Module
- Copyright (c) 2016, Freescale Semiconductor, Inc. All rights
reserved.
- This program and the accompanying materials are licensed and made
- available under the terms and conditions of the BSD License which
- accompanies this distribution. The full text of the license may be
- found http://opensource.org/licenses/bsd-license.php
- THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS"
- BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER
EXPRESS OR IMPLIED.
+**/
+#include <Uefi.h> +#include <Library/PlatformLib.h> +#include <Library/SocLib.h> +#include <Library/DebugLib.h> +#include <Library/DebugAgentLib.h> +#include <Library/IoLib.h> +#include <Library/Ls1043aSerDes.h>
+#ifdef LS1043A_SRDS_1 +static UINT16 SerDes1PrtclMap[SERDES_PRCTL_COUNT]; +#endif
+static struct SerDesConfig *SerDesConfigTbl[] = {
SerDes1ConfigTbl
+};
+SrdsPrtcl +GetSerDesPrtcl +(
- IN INTN SerDes,
- IN INTN Cfg,
- IN INTN Lane
+) +{
- struct SerDesConfig *Config;
- if (SerDes >= ARRAY_SIZE(SerDesConfigTbl))
- return 0;
- Config = SerDesConfigTbl[SerDes];
- while (Config->Protocol) {
- if (Config->Protocol == Cfg) {
return Config->SrdsLane[Lane];
- }
- Config++;
- }
- return EFI_SUCCESS;
+}
+EFI_STATUS +CheckSerDesPrtclValid +(
- IN INTN SerDes,
- IN UINT32 Prtcl
+) +{
- INTN Cnt;
- struct SerDesConfig *Config;
- if (SerDes >= ARRAY_SIZE(SerDesConfigTbl))
- return 0;
- Config = SerDesConfigTbl[SerDes];
- while (Config->Protocol) {
- if (Config->Protocol == Prtcl) {
DEBUG((EFI_D_INFO, "Protocol: %x Matched with the one in
Table\n", Prtcl));
break;
- }
- Config++;
- }
- if (!Config->Protocol)
- return 0;
- for (Cnt = 0; Cnt < SRDS_MAX_LANES; Cnt++) {
- if (Config->SrdsLane[Cnt] != NONE)
return 1;
- }
- return 0;
+}
+EFI_STATUS +IsSerDesConfigured +(
- IN SrdsPrtcl Device
+) +{
- INTN Ret = 0;
+#ifdef LS1043A_SRDS_1
- Ret |= SerDes1PrtclMap[Device];
+#endif
- return !!Ret;
+}
+INTN +GetSerDesFirstLane +(
- IN UINT32 Sd,
- IN SrdsPrtcl Device
+) +{
- struct CcsrGur *Gur = (void *)(LS1043A_GUTS_ADDR);
- UINT32 Cfg = MmioReadBe32((UINTN)&Gur->rcwsr[4]);
- INTN Cnt;
- switch (Sd) {
+#ifdef LS1043A_SRDS_1
- case FSL_SRDS_1:
- Cfg &= LS1043_RCWSR4_SRDS1_PRTCL_MASK;
- Cfg >>= LS1043_RCWSR4_SRDS1_PRTCL_SHIFT;
- break;
+#endif
- default:
- DEBUG((EFI_D_INFO, "Invalid SerDes%d, Only one SerDes is
there.\n", Sd));
- break;
- }
- /* Is serdes enabled at all? */
- if (Cfg == 0)
- return EFI_DEVICE_ERROR;
- for (Cnt = 0; Cnt < SRDS_MAX_LANES; Cnt++) {
- if (GetSerDesPrtcl(Sd, Cfg, Cnt) == Device)
return Cnt;
- }
- return EFI_DEVICE_ERROR;
+}
+VOID +LSSerDesInit +(
- UINT32 Srds,
- UINT32 SrdsAddr,
- UINT32 SrdsPrtclMask,
- UINT32 SrdsPrtclShift,
- UINT16 SerDesPrtclMap[SERDES_PRCTL_COUNT]
+) +{
- struct CcsrGur *Gur = (VOID *)(LS1043A_GUTS_ADDR);
- UINT32 SrdsProt;
- INTN Lane;
- UINT32 Flag = 0;
- SrdsProt = MmioReadBe32((UINTN)&Gur->rcwsr[4]) & SrdsPrtclMask;
- SrdsProt >>= SrdsPrtclShift;
- DEBUG((EFI_D_INFO, "Using SERDES%d Protocol: %d (0x%x)\n", Srds +
- 1, SrdsProt, SrdsProt));
- if (!CheckSerDesPrtclValid(Srds, SrdsProt)) {
- DEBUG((EFI_D_ERROR, "SERDES%d[PRTCL] = 0x%x is not valid\n",
Srds + 1, SrdsProt));
- Flag++;
- }
- for (Lane = 0; Lane < SRDS_MAX_LANES; Lane++) {
- SrdsPrtcl LanePrtcl = GetSerDesPrtcl(Srds, SrdsProt, Lane);
- if (LanePrtcl >= SERDES_PRCTL_COUNT) {
DEBUG((EFI_D_ERROR, "Unknown SerDes lane protocol %d\n",
LanePrtcl));
Flag++;
- } else {
SerDesPrtclMap[LanePrtcl] = 1;
- }
- }
- if (Flag)
- DEBUG((EFI_D_ERROR, "Could not configure SerDes module!!\n"));
- else
- DEBUG((EFI_D_INFO, "Successfully configured SerDes
module!!\n"));
+}
+VOID +SerDesInit +(
- VOID
+) +{
- DEBUG((EFI_D_INFO, "Initializing SerDes....\n")); #ifdef
+LS1043A_SRDS_1
- LSSerDesInit(FSL_SRDS_1,
LS1043A_SERDES_ADDR,
LS1043_RCWSR4_SRDS1_PRTCL_MASK,
LS1043_RCWSR4_SRDS1_PRTCL_SHIFT,
SerDes1PrtclMap);
+#endif
+}
1.9.1
Regards, Bhupesh
On Tue, Oct 18, 2016 at 01:34:05AM +0530, Bhupesh Sharma wrote:
From: Sakar Arora Sakar.Arora@nxp.com
This patch adds the functions that initialize the following IPs on the SoC:
- Central Security Unit (CSU) - Acts as a gatekeeper for secure and non-secure accesses via SW.
- TrustZone Address Space Controller (TZC-380).
- Interconnect (CCI-400).
- PLLs and Clocks.
- ARM Generic Timer.
Am I correct in guessing that many or all of the above will disappear later on when your EL3 firmware architecture changes?
In addition it also provides functions that print the following useful information:
- CPU Info
- SoC Personality.
- Board Personality.
- Reset Configuration Word (RCW).
- SerDes selection.
Signed-off-by: Bhupesh Sharma bhupesh.sharma@nxp.com
.../Nxp/LS1043aRdb/Include/Library/Ls1043aSerDes.h | 89 +++ Platforms/Nxp/LS1043aRdb/Include/Library/SocLib.h | 203 ++++++- .../LS1043aRdb/Library/LS1043aRdbLib/LS1043aRdb.c | 2 + .../Library/LS1043aSocLib/LS1043aSocLib.c | 674 ++++++++++++++++++++- .../Library/LS1043aSocLib/LS1043aSocLib.inf | 13 + .../LS1043aRdb/Library/LS1043aSocLib/LsSerDes.c | 195 ++++++ 6 files changed, 1169 insertions(+), 7 deletions(-) create mode 100644 Platforms/Nxp/LS1043aRdb/Include/Library/Ls1043aSerDes.h create mode 100644 Platforms/Nxp/LS1043aRdb/Library/LS1043aSocLib/LsSerDes.c
diff --git a/Platforms/Nxp/LS1043aRdb/Include/Library/Ls1043aSerDes.h b/Platforms/Nxp/LS1043aRdb/Include/Library/Ls1043aSerDes.h new file mode 100644 index 0000000..181c268 --- /dev/null +++ b/Platforms/Nxp/LS1043aRdb/Include/Library/Ls1043aSerDes.h @@ -0,0 +1,89 @@ +/** Ls1043aSerDes.h
- The Header file of SerDes Module
- Copyright (c) 2016, Freescale Semiconductor, Inc. All rights reserved.
- This program and the accompanying materials
- are licensed and made available under the terms and conditions of the BSD License
- which accompanies this distribution. The full text of the license may be found
- http://opensource.org/licenses/bsd-license.php
- THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
- WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
+**/
+#ifndef __LS1043A_SERDES_H +#define __LS1043A_SERDES_H
+#define SRDS_MAX_LANES 4
+#define LS1043_RCWSR4_SRDS1_PRTCL_MASK 0xFFFF0000 +#define LS1043_RCWSR4_SRDS1_PRTCL_SHIFT 16
+typedef enum {
- NONE = 0,
- PCIE1,
- PCIE2,
- PCIE3,
- SATA1,
- XFI1,
- XFI2,
- SGMII1,
- SGMII2,
- SGMII3,
- SGMII4,
- SGMII5,
- SGMII6,
- SGMII7,
- SGMII8,
- SGMII9,
- QSGMII1,
- QSGMII2,
- SERDES_PRCTL_COUNT
+} SrdsPrtcl;
+enum Srds {
- FSL_SRDS_1 = 0,
- FSL_SRDS_2 = 1
+};
+struct SerDesConfig {
- UINT16 Protocol;
- UINT8 SrdsLane[SRDS_MAX_LANES];
+};
+struct SerDesConfig SerDes1ConfigTbl[] = {
- /* SerDes 1 */
- {0x1555, {XFI1, PCIE1, PCIE2, PCIE3 } },
- {0x1560, {XFI1, PCIE1, PCIE3, PCIE3 } },
- {0x1460, {XFI1, QSGMII1, PCIE3, PCIE3 } },
- {0x1360, {XFI1, SGMII2, PCIE3, PCIE3 } },
- {0x2555, {SGMII9, PCIE1, PCIE2, PCIE3 } },
- {0x4555, {QSGMII1, PCIE1, PCIE2, PCIE3 } },
- {0x4558, {QSGMII1, PCIE1, PCIE2, SATA1 } },
- {0x1355, {XFI1, SGMII2, PCIE2, PCIE3 } },
- {0x1335, {XFI1, SGMII2, SGMII5, PCIE3 } },
- {0x1333, {XFI1, SGMII2, SGMII5, SGMII6 } },
- {0x2355, {SGMII9, SGMII2, PCIE2, PCIE3 } },
- {0x2260, {SGMII9, SGMII2, PCIE3, PCIE3 } },
- {0x2235, {SGMII9, SGMII2, SGMII5, PCIE3 } },
- {0x2233, {SGMII9, SGMII2, SGMII5, SGMII6 } },
- {0x3335, {SGMII9, SGMII2, SGMII5, PCIE3 } },
- {0x3355, {SGMII9, SGMII2, PCIE2, PCIE3 } },
- {0x3358, {SGMII9, SGMII2, PCIE2, SATA1 } },
- {0x3360, {SGMII9, SGMII2, PCIE3, PCIE3 } },
- {0x3560, {SGMII9, PCIE1, PCIE3, PCIE3 } },
- {0x3555, {SGMII9, PCIE1, PCIE2, PCIE3 } },
- {0x7000, {PCIE1, PCIE1, PCIE1, PCIE1 } },
- {0x9998, {PCIE1, PCIE2, PCIE3, SATA1 } },
- {0x6058, {PCIE1, PCIE1, PCIE2, SATA1 } },
- {0x1455, {XFI1, QSGMII1, PCIE2, PCIE3 } },
- {0x2455, {SGMII9, QSGMII1, PCIE2, PCIE3 } },
- {0x2255, {SGMII9, SGMII2, PCIE2, PCIE3 } },
- {0x3333, {SGMII9, SGMII2, SGMII5, SGMII6 } },
- {0x3338, {SGMII9, SGMII2, SGMII5, SATA1 } },
- {}
+};
+#endif /* __LS1043A_SERDES_H */ diff --git a/Platforms/Nxp/LS1043aRdb/Include/Library/SocLib.h b/Platforms/Nxp/LS1043aRdb/Include/Library/SocLib.h index d1655d5..dc798b3 100644 --- a/Platforms/Nxp/LS1043aRdb/Include/Library/SocLib.h +++ b/Platforms/Nxp/LS1043aRdb/Include/Library/SocLib.h @@ -22,14 +22,72 @@ #define HWA_CGA_M2_CLK_SEL 0x00000007 #define HWA_CGA_M2_CLK_SHIFT 0 +#define TP_ITYP_AV 0x00000001 /* Initiator available */ +#define TP_ITYP_TYPE(x) (((x) & 0x6) >> 1) /* Initiator Type */ +#define TP_ITYP_TYPE_ARM 0x0 +#define TP_ITYP_TYPE_PPC 0x1 /* PowerPC */ +#define TP_ITYP_TYPE_OTHER 0x2 /* StarCore DSP */ +#define TP_ITYP_TYPE_HA 0x3 /* HW Accelerator */ +#define TP_ITYP_THDS(x) (((x) & 0x18) >> 3) /* # threads */ +#define TP_ITYP_VER(x) (((x) & 0xe0) >> 5) /* Initiator Version */ +#define TY_ITYP_VER_A53 0x2
+#define TP_CLUSTER_EOC_MASK 0xc0000000 /* end of clusters mask */ +#define TP_CLUSTER_INIT_MASK 0x0000003f /* initiator mask */ +#define TP_INIT_PER_CLUSTER 4
#define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0])) #define LS1043A_CLK_FREQ 100000000 #define LS1043A_DDR_CLK_FREQ 100000000 #define LS1043A_MAX_CPUS 4 +#define LS1043A_FMAN_V3 #define LS1043A_NUM_FMAN 1 +#define LS1043A_NUM_FM1_DTSEC 7 +#define LS1043A_NUM_FM1_10GEC 1
+/*
- Divide positive or negative dividend by positive divisor and round
- to closest UINTNeger. Result is undefined for negative divisors and
- for negative dividends if the divisor variable type is unsigned.
- */
+#define DIV_ROUND_CLOSEST(x, divisor)( \ +{ \
- typeof(x) __x = x; \
- typeof(divisor) __d = divisor; \
- (((typeof(x))-1) > 0 || \
((typeof(divisor))-1) > 0 || (__x) > 0) ? \
(((__x) + ((__d) / 2)) / (__d)) : \
(((__x) - ((__d) / 2)) / (__d)); \
+} \ +)
This too is a direct copy from include/linux/kernel.h.
+/*
- HammingWeight32: returns the hamming weight (i.e. the number
- of bits set) of a 32-bit word
- */
+static inline UINTN HammingWeight32(UINTN w) +{
- UINTN Res = (w & 0x55555555) + ((w >> 1) & 0x55555555);
- Res = (Res & 0x33333333) + ((Res >> 2) & 0x33333333);
- Res = (Res & 0x0F0F0F0F) + ((Res >> 4) & 0x0F0F0F0F);
- Res = (Res & 0x00FF00FF) + ((Res >> 8) & 0x00FF00FF);
- return (Res & 0x0000FFFF) + ((Res >> 16) & 0x0000FFFF);
+}
+static inline UINTN CpuMaskNext(UINTN Cpu, UINTN Mask) +{
- for (Cpu++; !((1 << Cpu) & Mask); Cpu++)
;
Move that ; up, please.
- return Cpu;
+} +#define ForEachCpu(iter, cpu, num_cpus, mask) \
- for (iter = 0, cpu = CpuMaskNext(-1, mask); \
iter < num_cpus; \
iter++, cpu = CpuMaskNext(cpu, mask)) \
struct SysInfo { UINTN FreqProcessor[LS1043A_MAX_CPUS]; @@ -41,9 +99,122 @@ struct SysInfo { UINTN FreqQman; }; +typedef struct SocClocks {
- UINTN CpuClk; /* CPU clock in Hz! */
- UINTN BusClk;
- UINTN MemClk;
- UINTN PciClk;
- UINTN SdhcClk;
+} SocClockInfo;
+enum PeriphClock {
- ARM_CLK = 0,
- BUS_CLK,
- UART_CLK,
- ESDHC_CLK,
- I2C_CLK,
- DSPI_CLK,
+};
+enum CsuCslxAccess {
- SEC_UNIT_NS_SUP_R = 0x08,
- SEC_UNIT_NS_SUP_W = 0x80,
- SEC_UNIT_NS_SUP_RW = 0x88,
- SEC_UNIT_NS_USER_R = 0x04,
- SEC_UNIT_NS_USER_W = 0x40,
- SEC_UNIT_NS_USER_RW = 0x44,
- SEC_UNIT_S_SUP_R = 0x02,
- SEC_UNIT_S_SUP_W = 0x20,
- SEC_UNIT_S_SUP_RW = 0x22,
- SEC_UNIT_S_USER_R = 0x01,
- SEC_UNIT_S_USER_W = 0x10,
- SEC_UNIT_S_USER_RW = 0x11,
- SEC_UNIT_ALL_RW = 0xff,
+};
+enum CsuCslxInd {
- SEC_UNIT_CSLX_PCIE2_IO = 0,
- SEC_UNIT_CSLX_PCIE1_IO,
- SEC_UNIT_CSLX_MG2TPR_IP,
- SEC_UNIT_CSLX_IFC_MEM,
- SEC_UNIT_CSLX_OCRAM,
- SEC_UNIT_CSLX_GIC,
- SEC_UNIT_CSLX_PCIE1,
- SEC_UNIT_CSLX_OCRAM2,
- SEC_UNIT_CSLX_QSPI_MEM,
- SEC_UNIT_CSLX_PCIE2,
- SEC_UNIT_CSLX_SATA,
- SEC_UNIT_CSLX_USB1,
- SEC_UNIT_CSLX_QM_BM_SWPORTAL,
- SEC_UNIT_CSLX_PCIE3 = 16,
- SEC_UNIT_CSLX_PCIE3_IO,
- SEC_UNIT_CSLX_USB3 = 20,
- SEC_UNIT_CSLX_USB2,
- SEC_UNIT_CSLX_SERDES = 32,
- SEC_UNIT_CSLX_QDMA,
- SEC_UNIT_CSLX_LPUART2,
- SEC_UNIT_CSLX_LPUART1,
- SEC_UNIT_CSLX_LPUART4,
- SEC_UNIT_CSLX_LPUART3,
- SEC_UNIT_CSLX_LPUART6,
- SEC_UNIT_CSLX_LPUART5,
- SEC_UNIT_CSLX_DSPI1 = 41,
- SEC_UNIT_CSLX_QSPI,
- SEC_UNIT_CSLX_ESDHC,
- SEC_UNIT_CSLX_IFC = 45,
- SEC_UNIT_CSLX_I2C1,
- SEC_UNIT_CSLX_I2C3 = 48,
- SEC_UNIT_CSLX_I2C2,
- SEC_UNIT_CSLX_DUART2 = 50,
- SEC_UNIT_CSLX_DUART1,
- SEC_UNIT_CSLX_WDT2,
- SEC_UNIT_CSLX_WDT1,
- SEC_UNIT_CSLX_EDMA,
- SEC_UNIT_CSLX_SYS_CNT,
- SEC_UNIT_CSLX_DMA_MUX2,
- SEC_UNIT_CSLX_DMA_MUX1,
- SEC_UNIT_CSLX_DDR,
- SEC_UNIT_CSLX_QUICC,
- SEC_UNIT_CSLX_DCFG_CCU_RCPM = 60,
- SEC_UNIT_CSLX_SECURE_BOOTROM,
- SEC_UNIT_CSLX_SFP,
- SEC_UNIT_CSLX_TMU,
- SEC_UNIT_CSLX_SECURE_MONITOR,
- SEC_UNIT_CSLX_SCFG,
- SEC_UNIT_CSLX_FM = 66,
- SEC_UNIT_CSLX_SEC5_5,
- SEC_UNIT_CSLX_BM,
- SEC_UNIT_CSLX_QM,
- SEC_UNIT_CSLX_GPIO2 = 70,
- SEC_UNIT_CSLX_GPIO1,
- SEC_UNIT_CSLX_GPIO4,
- SEC_UNIT_CSLX_GPIO3,
- SEC_UNIT_CSLX_PLATFORM_CONT,
- SEC_UNIT_CSLX_SEC_UNIT,
- SEC_UNIT_CSLX_IIC4 = 77,
- SEC_UNIT_CSLX_WDT4,
- SEC_UNIT_CSLX_WDT3,
- SEC_UNIT_CSLX_WDT5 = 81,
- SEC_UNIT_CSLX_FTM2 = 86,
- SEC_UNIT_CSLX_FTM1,
- SEC_UNIT_CSLX_FTM4,
- SEC_UNIT_CSLX_FTM3,
- SEC_UNIT_CSLX_FTM6 = 90,
- SEC_UNIT_CSLX_FTM5,
- SEC_UNIT_CSLX_FTM8,
- SEC_UNIT_CSLX_FTM7,
- SEC_UNIT_CSLX_DSCR = 120,
+};
+struct CsuNsDev {
- UINTN Ind;
- UINT32 Val;
+};
/* Device Configuration and Pin Control */ struct CcsrGur { UINT32 porsr1; /* POR status 1 */ +#define FSL_CHASSIS2_CCSR_PORSR1_RCW_MASK 0xFF800000 UINT32 porsr2; /* POR status 2 */ UINT8 res_008[0x20-0x8]; UINT32 gpporcr1; /* General-purpose POR configuration */ @@ -51,6 +222,18 @@ struct CcsrGur { UINT32 dcfg_fusesr; /* Fuse status register */ UINT8 res_02c[0x70-0x2c]; UINT32 devdisr; /* Device disable control */ +#define FSL_CHASSIS2_DEVDISR2_DTSEC1_1 0x80000000 +#define FSL_CHASSIS2_DEVDISR2_DTSEC1_2 0x40000000 +#define FSL_CHASSIS2_DEVDISR2_DTSEC1_3 0x20000000 +#define FSL_CHASSIS2_DEVDISR2_DTSEC1_4 0x10000000 +#define FSL_CHASSIS2_DEVDISR2_DTSEC1_5 0x08000000 +#define FSL_CHASSIS2_DEVDISR2_DTSEC1_6 0x04000000 +#define FSL_CHASSIS2_DEVDISR2_DTSEC1_9 0x00800000 +#define FSL_CHASSIS2_DEVDISR2_DTSEC1_10 0x00400000 +#define FSL_CHASSIS2_DEVDISR2_10GEC1_1 0x00800000 +#define FSL_CHASSIS2_DEVDISR2_10GEC1_2 0x00400000 +#define FSL_CHASSIS2_DEVDISR2_10GEC1_3 0x80000000 +#define FSL_CHASSIS2_DEVDISR2_10GEC1_4 0x40000000 UINT32 devdisr2; /* Device disable control 2 */ UINT32 devdisr3; /* Device disable control 3 */ UINT32 devdisr4; /* Device disable control 4 */ @@ -83,6 +266,8 @@ struct CcsrGur { #define FSL_CHASSIS2_RCWSR0_SYS_PLL_RAT_MASK 0x1f #define FSL_CHASSIS2_RCWSR0_MEM_PLL_RAT_SHIFT 16 #define FSL_CHASSIS2_RCWSR0_MEM_PLL_RAT_MASK 0x3f +#define FSL_CHASSIS2_RCWSR4_SRDS1_PRTCL_MASK 0xffff0000 +#define FSL_CHASSIS2_RCWSR4_SRDS1_PRTCL_SHIFT 16 UINT8 res_140[0x200-0x140]; UINT32 scratchrw[4]; /* Scratch Read/Write */ UINT8 res_210[0x300-0x210]; @@ -259,6 +444,12 @@ struct CcsrClk { UINT8 res_c24[0x3dc]; }; +#define CCI400_CTRLORD_TERM_BARRIER 0x00000008 +#define CCI400_CTRLORD_EN_BARRIER 0 +#define CCI400_SHAORD_NON_SHAREABLE 0x00000002 +#define CCI400_DVM_MESSAGE_REQ_EN 0x00000002 +#define CCI400_SNOOP_REQ_EN 0x00000001
/* CCI-400 registers */ struct CcsrCci400 { UINT32 ctrl_ord; /* Control Override */ @@ -301,8 +492,18 @@ struct CcsrCci400 { UINT8 res_e004[0x10000 - 0xe004]; }; +VOID EnableDevicesNsAccess(struct CsuNsDev *NonSecureDevices, UINT32 Num);
+VOID GetSysInfo(struct SysInfo *PtrSysInfo);
+VOID SocInit(VOID);
+VOID SerDesInit(VOID);
+VOID FdtCpuSetup(VOID *Blob);
UINT32 CalculateBaudDivisor(OUT UINT64 *BaudRate); -UINT32 CalculateI2cClockRate(VOID); +UINT32 CalculateI2cClockRate(VOID);
Unrelated whitespace change.
#endif /* __LS1043A_SOC_H__ */ diff --git a/Platforms/Nxp/LS1043aRdb/Library/LS1043aRdbLib/LS1043aRdb.c b/Platforms/Nxp/LS1043aRdb/Library/LS1043aRdbLib/LS1043aRdb.c index 4fcb8a3..7c64709 100644 --- a/Platforms/Nxp/LS1043aRdb/Library/LS1043aRdbLib/LS1043aRdb.c +++ b/Platforms/Nxp/LS1043aRdb/Library/LS1043aRdbLib/LS1043aRdb.c @@ -24,6 +24,7 @@ #include <Library/PcdLib.h> #include <Ppi/ArmMpCoreInfo.h> #include <Library/PlatformLib.h> +#include <Library/SocLib.h> /** Return the current Boot Mode @@ -47,6 +48,7 @@ ArmPlatformInitialize ( IN UINTN MpId ) {
- SocInit(); return RETURN_SUCCESS;
} diff --git a/Platforms/Nxp/LS1043aRdb/Library/LS1043aSocLib/LS1043aSocLib.c b/Platforms/Nxp/LS1043aRdb/Library/LS1043aSocLib/LS1043aSocLib.c index fdeae08..2a7cb38 100644 --- a/Platforms/Nxp/LS1043aRdb/Library/LS1043aSocLib/LS1043aSocLib.c +++ b/Platforms/Nxp/LS1043aRdb/Library/LS1043aSocLib/LS1043aSocLib.c @@ -26,20 +26,227 @@ #include <Library/DebugAgentLib.h> #include <Library/IoLib.h> #include <Library/PrintLib.h> +#include <Library/SerialPortLib.h> +#include <Library/FslIfc.h>
Indert sorted, please.
+#include <Drivers/ArmTrustzone.h> #include <Library/PlatformLib.h> #include <Library/SocLib.h> #include <Library/CpldLib.h> +#include <libfdt.h>
+/* Global Clock Information pointer */ +static SocClockInfo gClkInfo;
+static struct CsuNsDev NonSecureDevices[] = +{
{SEC_UNIT_CSLX_PCIE2_IO, SEC_UNIT_ALL_RW},
{SEC_UNIT_CSLX_PCIE1_IO, SEC_UNIT_ALL_RW},
{SEC_UNIT_CSLX_MG2TPR_IP, SEC_UNIT_ALL_RW},
{SEC_UNIT_CSLX_IFC_MEM, SEC_UNIT_ALL_RW},
{SEC_UNIT_CSLX_OCRAM, SEC_UNIT_ALL_RW},
{SEC_UNIT_CSLX_GIC, SEC_UNIT_ALL_RW},
{SEC_UNIT_CSLX_PCIE1, SEC_UNIT_ALL_RW},
{SEC_UNIT_CSLX_OCRAM2, SEC_UNIT_ALL_RW},
{SEC_UNIT_CSLX_QSPI_MEM, SEC_UNIT_ALL_RW},
{SEC_UNIT_CSLX_PCIE2, SEC_UNIT_ALL_RW},
{SEC_UNIT_CSLX_SATA, SEC_UNIT_ALL_RW},
{SEC_UNIT_CSLX_USB1, SEC_UNIT_ALL_RW},
{SEC_UNIT_CSLX_QM_BM_SWPORTAL, SEC_UNIT_ALL_RW},
{SEC_UNIT_CSLX_PCIE3, SEC_UNIT_ALL_RW},
{SEC_UNIT_CSLX_PCIE3_IO, SEC_UNIT_ALL_RW},
{SEC_UNIT_CSLX_USB3, SEC_UNIT_ALL_RW},
{SEC_UNIT_CSLX_USB2, SEC_UNIT_ALL_RW},
{SEC_UNIT_CSLX_SERDES, SEC_UNIT_ALL_RW},
{SEC_UNIT_CSLX_QDMA, SEC_UNIT_ALL_RW},
{SEC_UNIT_CSLX_LPUART2, SEC_UNIT_ALL_RW},
{SEC_UNIT_CSLX_LPUART1, SEC_UNIT_ALL_RW},
{SEC_UNIT_CSLX_LPUART4, SEC_UNIT_ALL_RW},
{SEC_UNIT_CSLX_LPUART3, SEC_UNIT_ALL_RW},
{SEC_UNIT_CSLX_LPUART6, SEC_UNIT_ALL_RW},
{SEC_UNIT_CSLX_LPUART5, SEC_UNIT_ALL_RW},
{SEC_UNIT_CSLX_DSPI1, SEC_UNIT_ALL_RW},
{SEC_UNIT_CSLX_QSPI, SEC_UNIT_ALL_RW},
{SEC_UNIT_CSLX_ESDHC, SEC_UNIT_ALL_RW},
{SEC_UNIT_CSLX_IFC, SEC_UNIT_ALL_RW},
{SEC_UNIT_CSLX_I2C1, SEC_UNIT_ALL_RW},
{SEC_UNIT_CSLX_I2C3, SEC_UNIT_ALL_RW},
{SEC_UNIT_CSLX_I2C2, SEC_UNIT_ALL_RW},
{SEC_UNIT_CSLX_DUART2, SEC_UNIT_ALL_RW},
{SEC_UNIT_CSLX_DUART1, SEC_UNIT_ALL_RW},
{SEC_UNIT_CSLX_WDT2, SEC_UNIT_ALL_RW},
{SEC_UNIT_CSLX_WDT1, SEC_UNIT_ALL_RW},
{SEC_UNIT_CSLX_EDMA, SEC_UNIT_ALL_RW},
{SEC_UNIT_CSLX_SYS_CNT, SEC_UNIT_ALL_RW},
{SEC_UNIT_CSLX_DMA_MUX2, SEC_UNIT_ALL_RW},
{SEC_UNIT_CSLX_DMA_MUX1, SEC_UNIT_ALL_RW},
{SEC_UNIT_CSLX_DDR, SEC_UNIT_ALL_RW},
{SEC_UNIT_CSLX_QUICC, SEC_UNIT_ALL_RW},
{SEC_UNIT_CSLX_DCFG_CCU_RCPM, SEC_UNIT_ALL_RW},
{SEC_UNIT_CSLX_SECURE_BOOTROM, SEC_UNIT_ALL_RW},
{SEC_UNIT_CSLX_SFP, SEC_UNIT_ALL_RW},
{SEC_UNIT_CSLX_TMU, SEC_UNIT_ALL_RW},
{SEC_UNIT_CSLX_SECURE_MONITOR, SEC_UNIT_ALL_RW},
{SEC_UNIT_CSLX_SCFG, SEC_UNIT_ALL_RW},
{SEC_UNIT_CSLX_FM, SEC_UNIT_ALL_RW},
{SEC_UNIT_CSLX_SEC5_5, SEC_UNIT_ALL_RW},
{SEC_UNIT_CSLX_BM, SEC_UNIT_ALL_RW},
{SEC_UNIT_CSLX_QM, SEC_UNIT_ALL_RW},
{SEC_UNIT_CSLX_GPIO2, SEC_UNIT_ALL_RW},
{SEC_UNIT_CSLX_GPIO1, SEC_UNIT_ALL_RW},
{SEC_UNIT_CSLX_GPIO4, SEC_UNIT_ALL_RW},
{SEC_UNIT_CSLX_GPIO3, SEC_UNIT_ALL_RW},
{SEC_UNIT_CSLX_PLATFORM_CONT, SEC_UNIT_ALL_RW},
{SEC_UNIT_CSLX_SEC_UNIT, SEC_UNIT_ALL_RW},
{SEC_UNIT_CSLX_IIC4, SEC_UNIT_ALL_RW},
{SEC_UNIT_CSLX_WDT4, SEC_UNIT_ALL_RW},
{SEC_UNIT_CSLX_WDT3, SEC_UNIT_ALL_RW},
{SEC_UNIT_CSLX_WDT5, SEC_UNIT_ALL_RW},
{SEC_UNIT_CSLX_FTM2, SEC_UNIT_ALL_RW},
{SEC_UNIT_CSLX_FTM1, SEC_UNIT_ALL_RW},
{SEC_UNIT_CSLX_FTM4, SEC_UNIT_ALL_RW},
{SEC_UNIT_CSLX_FTM3, SEC_UNIT_ALL_RW},
{SEC_UNIT_CSLX_FTM6, SEC_UNIT_ALL_RW},
{SEC_UNIT_CSLX_FTM5, SEC_UNIT_ALL_RW},
{SEC_UNIT_CSLX_FTM8, SEC_UNIT_ALL_RW},
{SEC_UNIT_CSLX_FTM7, SEC_UNIT_ALL_RW},
{SEC_UNIT_CSLX_DSCR, SEC_UNIT_ALL_RW},
+};
+char *StringToMHz (
- char *Buf,
- unsigned long Hz
- )
+{
- long l, m, n;
- n = DIV_ROUND_CLOSEST(Hz, 1000) / 1000L;
- l = AsciiSPrint (Buf, sizeof(Buf), "%ld", n);
- Hz -= n * 1000000L;
- m = DIV_ROUND_CLOSEST(Hz, 1000L);
- if (m != 0)
AsciiSPrint (Buf + l, sizeof(Buf), ".%03ld", m);
- return (Buf);
+}
+VOID +CciConfigureSnoopDvm (
- struct CcsrCci400 *CciBase
- )
+{
- // Enable snoop requests and DVM message requests for
- // Slave insterface S4 (A53 core cluster)
- MmioWrite32((UINTN)&CciBase->slave[4].snoop_ctrl,
CCI400_DVM_MESSAGE_REQ_EN | CCI400_SNOOP_REQ_EN);
+}
+VOID IfcNorInit(VOID) {
Could we have some comments on what the below does?
- MmioWriteBe32((UINTN) &(FSL_IFC_REGS_BASE)->cspr_cs[FSL_IFC_CS0].cspr_ext, FSL_IFC_NOR_CSPR_EXT);
- MmioWriteBe32((UINTN) &(FSL_IFC_REGS_BASE)->ftim_cs[FSL_IFC_CS0].ftim[FSL_IFC_FTIM0], FSL_IFC_NOR_FTIM0);
- MmioWriteBe32((UINTN) &(FSL_IFC_REGS_BASE)->ftim_cs[FSL_IFC_CS0].ftim[FSL_IFC_FTIM1], FSL_IFC_NOR_FTIM1);
- MmioWriteBe32((UINTN) &(FSL_IFC_REGS_BASE)->ftim_cs[FSL_IFC_CS0].ftim[FSL_IFC_FTIM2], FSL_IFC_NOR_FTIM2);
- MmioWriteBe32((UINTN) &(FSL_IFC_REGS_BASE)->ftim_cs[FSL_IFC_CS0].ftim[FSL_IFC_FTIM3], FSL_IFC_NOR_FTIM3);
- MmioWriteBe32((UINTN) &(FSL_IFC_REGS_BASE)->cspr_cs[FSL_IFC_CS0].cspr, FSL_IFC_NOR_CSPR0);
- MmioWriteBe32((UINTN) &(FSL_IFC_REGS_BASE)->amask_cs[FSL_IFC_CS0].amask, FSL_IFC_NOR_AMASK0);
- MmioWriteBe32((UINTN) &(FSL_IFC_REGS_BASE)->csor_cs[FSL_IFC_CS0].csor, FSL_IFC_NOR_CSOR0);
+}
+VOID +CciConfigureQos (
- struct CcsrCci400 *CciBase
- )
+{
- // FIXME: Empty for now. Populate if required later.
- return;
+}
+VOID +Cci400Init (
- VOID
- )
+{
- struct CcsrCci400 *Base = (struct CcsrCci400 *)LS1043A_CCI400_ADDR;
- /* Set CCI-400 control override register to enable barrier transaction */
- MmioWrite32((UINTN)&Base->ctrl_ord, CCI400_CTRLORD_EN_BARRIER);
- CciConfigureSnoopDvm(Base);
- CciConfigureQos(Base);
+}
+/**
- Initialize the Secure peripherals and memory regions
- If Trustzone is supported by your platform then this function makes the required initialization
- of the secure peripherals and memory regions.
+**/ +VOID +Tzc380Init (
- VOID
- )
+{
- // Setup TZ Address Space Controller.
- // Assumption: We have 2GB DDR mounted on the DIMMs.
Is there no way to determine this during runtime?
- //
- // Since, we need ONE secure DDR region which will be used for keeping
- // the PPA (EL3 platform security fw) code and the rest of the regions
- // would be non-secure regions which can be accessed via NS software as
- // well - so we create one TZASC region of 2GB and divided it into
- // 8 equal su-regions. Now, we keep the 1st sub-regions for housing
- // the PPA and use the rest of the sub-regions to allow NS accesses.
- // Note: Your OS Kernel must be aware of the secure regions before to
- // enable this region
- TZASCSetRegion(LS1043A_TZASC380_ADDR, 1, TZASC_REGION_ENABLED, LS1043A_DRAM1_BASE_ADDR, 0,
TZASC_REGION_SIZE_2GB, TZASC_REGION_SECURITY_SRW, 0x7F);
What are the 1, 0 and 0x7F?
+}
+VOID +EnableDevicesNsAccess (
- OUT struct CsuNsDev *NonSecureDevices,
- IN UINT32 Num
- )
+{
- UINT32 *Base = (UINT32 *)LS1043A_CSU_ADDR;
- UINT32 *Reg;
Why use pointers for Base and Reg?
- UINT32 Val;
- UINT32 Count;
- for (Count = 0; Count < Num; Count++) {
Reg = Base + NonSecureDevices[Count].Ind / 2;
Val = MmioReadBe32((UINTN)Reg);
if (NonSecureDevices[Count].Ind % 2 == 0) {
Val &= 0x0000ffff;
Val |= NonSecureDevices[Count].Val << 16;
} else {
Val &= 0xffff0000;
Val |= NonSecureDevices[Count].Val;
}
MmioWriteBe32((UINTN)Reg, Val);
- }
+}
+VOID +CsuInit (
- VOID
- )
+{
- EnableDevicesNsAccess(NonSecureDevices, ARRAY_SIZE(NonSecureDevices));
+} VOID GetSysInfo ( OUT struct SysInfo *PtrSysInfo ) {
- struct CcsrGur *GurBase = (void *)(LS1043A_FSL_GUTS_ADDR);
- struct CcsrClk *ClkBase = (void *)(LS1043A_FSL_CLK_ADDR);
- struct CcsrGur *GurBase = (void *)(LS1043A_GUTS_ADDR);
- struct CcsrClk *ClkBase = (void *)(LS1043A_CLK_ADDR); UINTN CpuIndex; UINT32 TempRcw; const UINT8 CoreCplxPll[8] = {
@@ -57,8 +264,8 @@ GetSysInfo ( }; UINTN PllCount;
- UINTN FreqCPll[LS1043A_FSL_NUM_CC_PLLS];
- UINTN PllRatio[LS1043A_FSL_NUM_CC_PLLS];
- UINTN FreqCPll[LS1043A_NUM_CC_PLLS];
- UINTN PllRatio[LS1043A_NUM_CC_PLLS]; UINTN SysClk = LS1043A_CLK_FREQ;
PtrSysInfo->FreqSystemBus = SysClk; @@ -71,7 +278,7 @@ GetSysInfo ( FSL_CHASSIS2_RCWSR0_MEM_PLL_RAT_SHIFT) & FSL_CHASSIS2_RCWSR0_MEM_PLL_RAT_MASK;
- for (PllCount = 0; PllCount < LS1043A_FSL_NUM_CC_PLLS; PllCount++) {
- for (PllCount = 0; PllCount < LS1043A_NUM_CC_PLLS; PllCount++) { PllRatio[PllCount] = (MmioReadBe32((UINTN)&ClkBase->pllcgsr[PllCount].pllcngsr) >> 1) & 0xff; if (PllRatio[PllCount] > 4) FreqCPll[PllCount] = SysClk * PllRatio[PllCount];
@@ -112,6 +319,461 @@ GetSysInfo ( PtrSysInfo->FreqQman = PtrSysInfo->FreqSystemBus / 2; } +VOID +ClockInit (
More very generically named functions. Like feedback on previous patch, please prepend SoCLib (or similar) to any exported functions (and make the others STATIC).
- VOID
- )
+{
- struct SysInfo SocSysInfo;
- GetSysInfo(&SocSysInfo);
- gClkInfo.CpuClk = SocSysInfo.FreqProcessor[0];
- gClkInfo.BusClk = SocSysInfo.FreqSystemBus;
- gClkInfo.MemClk = SocSysInfo.FreqDdrBus;
- gClkInfo.SdhcClk = SocSysInfo.FreqSdhc;
+}
+INTN +TimerInit (
- VOID
- )
+{
- UINT32 *TimerBase = (UINT32 *)LS1043A_TIMER_ADDR;
- if (PcdGetBool(PcdCounterFrequencyReal)) {
UINTN cntfrq = PcdGet32(PcdCounterFrequency);
/* Update with accurate clock frequency */
asm volatile("msr cntfrq_el0, %0" : : "r" (cntfrq) : "memory");
Use ArmWriteCntFrq instead.
- }
- /* Enable clock for timer. This is a global setting. */
- MmioWrite32((UINTN)TimerBase, 0x1);
- return 0;
+}
+static inline +UINT32 +InitiatorType (
- IN UINT32 Cluster,
- IN UINTN InitId
- )
+{
- struct CcsrGur *GurBase = (void *)(LS1043A_GUTS_ADDR);
VOID *
- UINT32 Idx = (Cluster >> (InitId * 8)) & TP_CLUSTER_INIT_MASK;
- UINT32 Type = MmioReadBe32((UINTN)&GurBase->tp_ityp[Idx]);
- if (Type & TP_ITYP_AV)
return Type;
- return 0;
+}
+UINT32 +CpuMask (
- VOID
- )
+{
- struct CcsrGur *GurBase = (void *)(LS1043A_GUTS_ADDR);
VOID *
- UINTN ClusterIndex = 0, Count = 0;
- UINT32 Cluster, Type, Mask = 0;
- do {
UINTN InitiatorIndex;
Cluster = MmioReadBe32((UINTN)&GurBase->tp_cluster[ClusterIndex].lower);
for (InitiatorIndex = 0; InitiatorIndex < TP_INIT_PER_CLUSTER; InitiatorIndex++) {
Type = InitiatorType(Cluster, InitiatorIndex);
if (Type) {
if (TP_ITYP_TYPE(Type) == TP_ITYP_TYPE_ARM)
Mask |= 1 << Count;
Count++;
}
}
ClusterIndex++;
- } while ((Cluster & TP_CLUSTER_EOC_MASK) == 0x0);
- return Mask;
+}
+/*
- Return the number of cores on this SOC.
- */
+UINTN +CpuNumCores (
- VOID
- )
+{
- return HammingWeight32(CpuMask());
+}
+UINT32 +QoriqCoreToType (
- IN UINTN Core
- )
+{
- struct CcsrGur *GurBase = (VOID *)(LS1043A_GUTS_ADDR);
- UINTN ClusterIndex = 0, Count = 0;
- UINT32 Cluster, Type;
- do {
UINTN InitiatorIndex;
Cluster = MmioReadBe32((UINTN)&GurBase->tp_cluster[ClusterIndex].lower);
for (InitiatorIndex = 0; InitiatorIndex < TP_INIT_PER_CLUSTER; InitiatorIndex++) {
Type = InitiatorType(Cluster, InitiatorIndex);
if (Type) {
if (Count == Core)
return Type;
Count++;
}
}
ClusterIndex++;
- } while ((Cluster & TP_CLUSTER_EOC_MASK) == 0x0);
- return -1; /* cannot identify the cluster */
+}
+VOID +PrintCpuInfo (
- VOID
- )
+{
- struct SysInfo SysInfo;
- UINTN CoreIndex, Core;
- UINT32 Type;
- CHAR8 Buf[32];
- CHAR8 Buffer[100];
- UINTN CharCount;
- GetSysInfo(&SysInfo);
- CharCount = AsciiSPrint (Buffer, sizeof (Buffer), "Clock Configuration:");
- SerialPortWrite ((UINT8 *) Buffer, CharCount);
- ForEachCpu(CoreIndex, Core, CpuNumCores(), CpuMask()) {
if (!(CoreIndex % 3))
DEBUG((EFI_D_INFO, "\n "));
Type = TP_ITYP_VER(QoriqCoreToType(Core));
CharCount = AsciiSPrint (Buffer, sizeof (Buffer), "CPU%d(%a):%-4a MHz ", Core,
Type == TY_ITYP_VER_A53 ? "A53" : "Unknown Core",
StringToMHz(Buf, SysInfo.FreqProcessor[Core]));
SerialPortWrite ((UINT8 *) Buffer, CharCount);
- }
- CharCount = AsciiSPrint (Buffer, sizeof (Buffer), "\n Bus: %-4a MHz ",
StringToMHz(Buf, SysInfo.FreqSystemBus));
- SerialPortWrite ((UINT8 *) Buffer, CharCount);
- CharCount = AsciiSPrint (Buffer, sizeof (Buffer), "DDR: %-4a MHz", StringToMHz(Buf, SysInfo.FreqDdrBus));
- SerialPortWrite ((UINT8 *) Buffer, CharCount);
- CharCount = AsciiSPrint (Buffer, sizeof (Buffer), "\n");
- SerialPortWrite ((UINT8 *) Buffer, CharCount);
+}
+VOID +PrintSocPersonality (
- VOID
- )
+{ +}
+VOID +IfcInit (
- VOID
- )
+{
- /* NOR Init */
- IfcNorInit();
- /* CPLD Init */
- CpldInit();
+}
+VOID +PrintBoardPersonality (
- VOID
- )
+{
- static const char *Freq[3] = {"100.00MHZ", "156.25MHZ"};
STATIC CONST CHAR8
- UINT8 RcwSrc1, RcwSrc2;
- UINT32 RcwSrc;
- UINT32 sd1refclk_sel;
- DEBUG((EFI_D_INFO, "Board: LS1043ARDB, boot from "));
- RcwSrc1 = CPLD_READ(RcwSource1);
- RcwSrc2 = CPLD_READ(RcwSource1);
- CpldRevBit(&RcwSrc1);
- RcwSrc = RcwSrc1;
- RcwSrc = (RcwSrc << 1) | RcwSrc2;
- if (RcwSrc == 0x25)
Always braces with if/else.
DEBUG((EFI_D_INFO, "vBank %d\n", CPLD_READ(Vbank)));
- else if (RcwSrc == 0x106)
What is 0x25 and 0x106? Can we have #defines?
DEBUG((EFI_D_INFO, "NAND\n"));
- else
DEBUG((EFI_D_INFO, "Invalid setting of SW4\n"));
- DEBUG((EFI_D_INFO, "CPLD: V%x.%x\nPCBA: V%x.0\n", CPLD_READ(CpldVersionMajor),
CPLD_READ(CpldVersionMinor), CPLD_READ(PcbaVersion)));
- DEBUG((EFI_D_INFO, "SERDES Reference Clocks:\n"));
- sd1refclk_sel = CPLD_READ(Sd1RefClkSel);
- DEBUG((EFI_D_INFO, "SD1_CLK1 = %a, SD1_CLK2 = %a\n", Freq[sd1refclk_sel], Freq[0]));
+}
+VOID +PrintRCW (
- VOID
- )
+{
- struct CcsrGur *Base = (void *)(LS1043A_GUTS_ADDR);
VOID *
- UINTN Count;
- CHAR8 Buffer[100];
- UINTN CharCount;
- /*
* Display the RCW, so that no one gets confused as to what RCW
* we're actually using for this boot.
*/
- CharCount = AsciiSPrint (Buffer, sizeof (Buffer),
"Reset Configuration Word (RCW):");
- SerialPortWrite ((UINT8 *) Buffer, CharCount);
- for (Count = 0; Count < ARRAY_SIZE(Base->rcwsr); Count++) {
UINT32 Rcw = MmioReadBe32((UINTN)&Base->rcwsr[Count]);
if ((Count % 4) == 0) {
CharCount = AsciiSPrint (Buffer, sizeof (Buffer),
"\n %08x:", Count * 4);
SerialPortWrite ((UINT8 *) Buffer, CharCount);
}
CharCount = AsciiSPrint (Buffer, sizeof (Buffer), " %08x", Rcw);
SerialPortWrite ((UINT8 *) Buffer, CharCount);
- }
- CharCount = AsciiSPrint (Buffer, sizeof (Buffer), "\n");
- SerialPortWrite ((UINT8 *) Buffer, CharCount);
+}
+VOID +SmmuInit (
- VOID
- )
+{
- UINT32 Value;
- /* set pagesize as 64K and ssmu-500 in bypass mode */
- Value = (MmioRead32((UINTN)SMMU_REG_SACR) | SACR_PAGESIZE_MASK);
- MmioWrite32((UINTN)SMMU_REG_SACR, Value);
- Value = (MmioRead32((UINTN)SMMU_REG_SCR0) | SCR0_CLIENTPD_MASK) & ~(SCR0_USFCFG_MASK);
- MmioWrite32((UINTN)SMMU_REG_SCR0, Value);
- Value = (MmioRead32((UINTN)SMMU_REG_NSCR0) | SCR0_CLIENTPD_MASK) & ~(SCR0_USFCFG_MASK);
- MmioWrite32((UINTN)SMMU_REG_NSCR0, Value);
+}
+/**
- Function to initialize SoC specific constructs
- // CSU
- // TZC-380
- // CCI-400
- // ClockInit
- // TimerInit
- // CPU Info
- // SoC Personality
- // Board Personality
- // RCW prints
- // SerDes support
- **/
+VOID +SocInit (
- VOID
- )
+{
- CHAR8 Buffer[100];
- UINTN CharCount;
- // LS1043A SoC has a CSU (Central Security Unit)
- if (PcdGetBool(PcdCsuInitialize))
CsuInit();
- if (PcdGetBool(PcdTzc380Initialize))
Tzc380Init();
- if (PcdGetBool(PcdCci400Initialize))
Cci400Init();
- if (PcdGetBool(PcdClockInitialize))
ClockInit();
- SmmuInit();
- TimerInit();
- // Initialize the Serial Port
- SerialPortInitialize ();
- CharCount = AsciiSPrint (Buffer, sizeof (Buffer), "\nUEFI firmware (version %s built at %a on %a)\n\r",
- (CHAR16*)PcdGetPtr(PcdFirmwareVersionString), __TIME__, __DATE__);
- SerialPortWrite ((UINT8 *) Buffer, CharCount);
- PrintCpuInfo();
- PrintRCW();
- PrintSocPersonality();
- IfcInit();
- PrintBoardPersonality();
- SerDesInit();
- return;
+}
+/* fdt fixup for LS1043A */
+VOID +FixupByCompatibleField (
- VOID *Fdt,
- CONST char *Compat,
- CONST char *Prop,
- CONST VOID *Val,
- INTN Len,
- INTN Create
- )
+{
- INTN Offset = -1;
- Offset = fdt_node_offset_by_compatible(Fdt, -1, Compat);
- while (Offset != -FDT_ERR_NOTFOUND) {
if (Create || (fdt_get_property(Fdt, Offset, Prop, NULL) != NULL))
fdt_setprop(Fdt, Offset, Prop, Val, Len);
Offset = fdt_node_offset_by_compatible(Fdt, Offset, Compat);
- }
+}
+VOID +FixupByCompatibleField32 (
- VOID *Fdt,
- CONST char *Compat,
- CONST char *Prop,
- UINT32 Val,
- INTN Create
- )
+{
- fdt32_t Tmp = cpu_to_fdt32(Val);
- FixupByCompatibleField(Fdt, Compat, Prop, &Tmp, 4, Create);
+}
+#define BMAN_IP_REV_1 0xBF8 +#define BMAN_IP_REV_2 0xBFC +VOID +FdtFixupBmanPortals (
- VOID *Blob
- )
+{
- UINTN Off, Err;
- UINTN Maj, Min;
- UINTN IpCfg;
- UINT32 BmanRev1 = MmioReadBe32(LS1043A_BMAN_ADDR + BMAN_IP_REV_1);
- UINT32 BmanRev2 = MmioReadBe32(LS1043A_BMAN_ADDR + BMAN_IP_REV_2);
- char Compatible[64];
CHAR8
- INTN CompatibleLength;
- Maj = (BmanRev1 >> 8) & 0xff;
- Min = BmanRev1 & 0xff;
- IpCfg = BmanRev2 & 0xff;
- CompatibleLength = AsciiSPrint(Compatible, sizeof(Compatible),
"fsl,bman-portal-%u.%u.%u",
Maj, Min, IpCfg) + 1;
- CompatibleLength += AsciiSPrint(Compatible + CompatibleLength,
sizeof(Compatible), "fsl,bman-portal")
+ 1;
- Off = fdt_node_offset_by_compatible(Blob, -1, "fsl,bman-portal");
- while (Off != -FDT_ERR_NOTFOUND) {
Err = fdt_setprop(Blob, Off, "compatible", Compatible,
CompatibleLength);
if (Err < 0) {
DEBUG((EFI_D_ERROR, "ERROR: unable to create props for %a: %s\n",
fdt_get_name(Blob, Off, NULL), fdt_strerror(Err)));
return;
}
Off = fdt_node_offset_by_compatible(Blob, Off, "fsl,bman-portal");
- }
+}
+#define QMAN_IP_REV_1 0xBF8 +#define QMAN_IP_REV_2 0xBFC +VOID +FdtFixupQmanPortals (
- VOID *Blob
- )
+{
- INTN Off, Err;
- UINTN Maj, Min;
- UINTN IpCfg;
- UINT32 QmanRev1 = MmioReadBe32(LS1043A_QMAN_ADDR + QMAN_IP_REV_1);
- UINT32 QmanRev2 = MmioReadBe32(LS1043A_QMAN_ADDR + QMAN_IP_REV_2);
- char Compatible[64];
CHAR8
- INTN CompatLength;
- Maj = (QmanRev1 >> 8) & 0xff;
- Min = QmanRev1 & 0xff;
- IpCfg = QmanRev2 & 0xff;
- CompatLength = AsciiSPrint(Compatible, sizeof(Compatible),
"fsl,qman-portal-%u.%u.%u",
Maj, Min, IpCfg) + 1;
- CompatLength += AsciiSPrint(Compatible + CompatLength,
sizeof(Compatible), "fsl,qman-portal") + 1;
- Off = fdt_node_offset_by_compatible(Blob, -1, "fsl,qman-portal");
- while (Off != -FDT_ERR_NOTFOUND) {
Err = fdt_setprop(Blob, Off, "compatible", Compatible,
CompatLength);
if (Err < 0) {
DEBUG((EFI_D_ERROR, "ERROR: unable to create props for %a: %a\n",
fdt_get_name(Blob, Off, NULL), fdt_strerror(Err)));
return;
}
Off = fdt_node_offset_by_compatible(Blob, Off, "fsl,qman-portal");
- }
+}
+VOID +FdtFixupSdhc (
- VOID *Blob,
- UINTN SdhcClk
- )
+{
- const char *Compatible = "fsl,esdhc";
- FixupByCompatibleField32(Blob, Compatible, "clock-frequency", SdhcClk, 1);
- FixupByCompatibleField(Blob, Compatible, "status", "okay", 4 + 1, 1);
+}
+VOID FdtCpuSetup(VOID *blob) +{
- struct SysInfo SocSysInfo;
- GetSysInfo(&SocSysInfo);
- FixupByCompatibleField32(blob, "fsl,ns16550",
"clock-frequency", SocSysInfo.FreqSystemBus, 1);
- FdtFixupSdhc(blob, SocSysInfo.FreqSdhc);
- FdtFixupBmanPortals(blob);
- FdtFixupQmanPortals(blob);
- FixupByCompatibleField32(blob, "fsl,qman",
"clock-frequency", SocSysInfo.FreqQman, 1);
+}
UINT32 CalculateBaudDivisor ( @@ -135,6 +797,6 @@ CalculateI2cClockRate( struct SysInfo SocSysInfo; GetSysInfo(&SocSysInfo);
- return SocSysInfo.FreqSystemBus;
- return SocSysInfo.FreqSystemBus;
Unrelated whitespace change.
} diff --git a/Platforms/Nxp/LS1043aRdb/Library/LS1043aSocLib/LS1043aSocLib.inf b/Platforms/Nxp/LS1043aRdb/Library/LS1043aSocLib/LS1043aSocLib.inf index 322fe34..307cf21 100644 --- a/Platforms/Nxp/LS1043aRdb/Library/LS1043aSocLib/LS1043aSocLib.inf +++ b/Platforms/Nxp/LS1043aRdb/Library/LS1043aSocLib/LS1043aSocLib.inf @@ -29,12 +29,25 @@ OpenPlatformPkg/Chips/Nxp/QoriqLs/NxpQoriqLs.dec [LibraryClasses]
- ArmTrustZoneLib BaseLib CpldLib DebugLib DebugAgentLib IoLib ArmLib
- MemoryAllocationLib
- SerialPortLib
[Sources.common] LS1043aSocLib.c
- LsSerDes.c
+[FixedPcd]
- gEfiMdeModulePkgTokenSpaceGuid.PcdFirmwareVersionString
- gArmPlatformTokenSpaceGuid.PcdCounterFrequencyReal
- gArmPlatformTokenSpaceGuid.PcdCsuInitialize
- gArmPlatformTokenSpaceGuid.PcdTzc380Initialize
- gArmPlatformTokenSpaceGuid.PcdCci400Initialize
- gArmPlatformTokenSpaceGuid.PcdClockInitialize
- gArmPlatformTokenSpaceGuid.PcdCounterFrequency
Please sort FixedPcd.
diff --git a/Platforms/Nxp/LS1043aRdb/Library/LS1043aSocLib/LsSerDes.c b/Platforms/Nxp/LS1043aRdb/Library/LS1043aSocLib/LsSerDes.c new file mode 100644 index 0000000..3312e9b --- /dev/null +++ b/Platforms/Nxp/LS1043aRdb/Library/LS1043aSocLib/LsSerDes.c @@ -0,0 +1,195 @@ +/** LsSerDes.c
- Provides the basic interfaces for SerDes Module
- Copyright (c) 2016, Freescale Semiconductor, Inc. All rights reserved.
- This program and the accompanying materials
- are licensed and made available under the terms and conditions of the BSD License
- which accompanies this distribution. The full text of the license may be found
- http://opensource.org/licenses/bsd-license.php
- THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
- WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
+**/
+#include <Uefi.h> +#include <Library/PlatformLib.h> +#include <Library/SocLib.h> +#include <Library/DebugLib.h> +#include <Library/DebugAgentLib.h> +#include <Library/IoLib.h> +#include <Library/Ls1043aSerDes.h>
Please sort Library/ includes alphabetically.
+#ifdef LS1043A_SRDS_1 +static UINT16 SerDes1PrtclMap[SERDES_PRCTL_COUNT]; +#endif
+static struct SerDesConfig *SerDesConfigTbl[] = {
- SerDes1ConfigTbl
+};
+SrdsPrtcl +GetSerDesPrtcl +(
- IN INTN SerDes,
- IN INTN Cfg,
- IN INTN Lane
+) +{
- struct SerDesConfig *Config;
- if (SerDes >= ARRAY_SIZE(SerDesConfigTbl))
- return 0;
- Config = SerDesConfigTbl[SerDes];
- while (Config->Protocol) {
- if (Config->Protocol == Cfg) {
return Config->SrdsLane[Lane];
- }
- Config++;
- }
- return EFI_SUCCESS;
+}
+EFI_STATUS +CheckSerDesPrtclValid +(
- IN INTN SerDes,
- IN UINT32 Prtcl
+) +{
- INTN Cnt;
- struct SerDesConfig *Config;
- if (SerDes >= ARRAY_SIZE(SerDesConfigTbl))
- return 0;
- Config = SerDesConfigTbl[SerDes];
- while (Config->Protocol) {
- if (Config->Protocol == Prtcl) {
DEBUG((EFI_D_INFO, "Protocol: %x Matched with the one in Table\n", Prtcl));
break;
- }
- Config++;
- }
- if (!Config->Protocol)
- return 0;
- for (Cnt = 0; Cnt < SRDS_MAX_LANES; Cnt++) {
- if (Config->SrdsLane[Cnt] != NONE)
return 1;
- }
- return 0;
+}
+EFI_STATUS +IsSerDesConfigured +(
- IN SrdsPrtcl Device
+) +{
- INTN Ret = 0;
+#ifdef LS1043A_SRDS_1
- Ret |= SerDes1PrtclMap[Device];
+#endif
- return !!Ret;
Eeew, please no !!.
+}
+INTN +GetSerDesFirstLane +(
- IN UINT32 Sd,
- IN SrdsPrtcl Device
+) +{
- struct CcsrGur *Gur = (void *)(LS1043A_GUTS_ADDR);
VOID *
(And that struct CcsrGur could do with a typedef.)
- UINT32 Cfg = MmioReadBe32((UINTN)&Gur->rcwsr[4]);
- INTN Cnt;
- switch (Sd) {
+#ifdef LS1043A_SRDS_1
- case FSL_SRDS_1:
- Cfg &= LS1043_RCWSR4_SRDS1_PRTCL_MASK;
- Cfg >>= LS1043_RCWSR4_SRDS1_PRTCL_SHIFT;
- break;
+#endif
- default:
- DEBUG((EFI_D_INFO, "Invalid SerDes%d, Only one SerDes is there.\n", Sd));
- break;
- }
- /* Is serdes enabled at all? */
- if (Cfg == 0)
- return EFI_DEVICE_ERROR;
- for (Cnt = 0; Cnt < SRDS_MAX_LANES; Cnt++) {
- if (GetSerDesPrtcl(Sd, Cfg, Cnt) == Device)
return Cnt;
- }
- return EFI_DEVICE_ERROR;
+}
+VOID +LSSerDesInit +(
- UINT32 Srds,
- UINT32 SrdsAddr,
- UINT32 SrdsPrtclMask,
- UINT32 SrdsPrtclShift,
- UINT16 SerDesPrtclMap[SERDES_PRCTL_COUNT]
+) +{
- struct CcsrGur *Gur = (VOID *)(LS1043A_GUTS_ADDR);
- UINT32 SrdsProt;
- INTN Lane;
- UINT32 Flag = 0;
- SrdsProt = MmioReadBe32((UINTN)&Gur->rcwsr[4]) & SrdsPrtclMask;
- SrdsProt >>= SrdsPrtclShift;
- DEBUG((EFI_D_INFO, "Using SERDES%d Protocol: %d (0x%x)\n", Srds + 1, SrdsProt, SrdsProt));
- if (!CheckSerDesPrtclValid(Srds, SrdsProt)) {
- DEBUG((EFI_D_ERROR, "SERDES%d[PRTCL] = 0x%x is not valid\n", Srds + 1, SrdsProt));
- Flag++;
- }
- for (Lane = 0; Lane < SRDS_MAX_LANES; Lane++) {
- SrdsPrtcl LanePrtcl = GetSerDesPrtcl(Srds, SrdsProt, Lane);
- if (LanePrtcl >= SERDES_PRCTL_COUNT) {
DEBUG((EFI_D_ERROR, "Unknown SerDes lane protocol %d\n", LanePrtcl));
Flag++;
- } else {
SerDesPrtclMap[LanePrtcl] = 1;
- }
- }
- if (Flag)
- DEBUG((EFI_D_ERROR, "Could not configure SerDes module!!\n"));
- else
- DEBUG((EFI_D_INFO, "Successfully configured SerDes module!!\n"));
+}
+VOID +SerDesInit +(
- VOID
+) +{
- DEBUG((EFI_D_INFO, "Initializing SerDes....\n"));
+#ifdef LS1043A_SRDS_1
- LSSerDesInit(FSL_SRDS_1,
LS1043A_SERDES_ADDR,
LS1043_RCWSR4_SRDS1_PRTCL_MASK,
LS1043_RCWSR4_SRDS1_PRTCL_SHIFT,
SerDes1PrtclMap);
+#endif
+}
1.9.1
From: Sakar Arora sakar.arora@nxp.com
This patch adds the support for system reset library which can be used to invoke a system reset via the UEFI shell on LS1043A-RDB board.
Signed-off-by: Sakar Arora sakar.arora@nxp.com Signed-off-by: Bhupesh Sharma bhupesh.sharma@nxp.com --- .../Library/ResetSystemLib/ResetSystemLib.c | 87 ++++++++++++++++++++++ .../Library/ResetSystemLib/ResetSystemLib.inf | 50 +++++++++++++ 2 files changed, 137 insertions(+) create mode 100644 Platforms/Nxp/LS1043aRdb/Library/ResetSystemLib/ResetSystemLib.c create mode 100644 Platforms/Nxp/LS1043aRdb/Library/ResetSystemLib/ResetSystemLib.inf
diff --git a/Platforms/Nxp/LS1043aRdb/Library/ResetSystemLib/ResetSystemLib.c b/Platforms/Nxp/LS1043aRdb/Library/ResetSystemLib/ResetSystemLib.c new file mode 100644 index 0000000..831dd3a --- /dev/null +++ b/Platforms/Nxp/LS1043aRdb/Library/ResetSystemLib/ResetSystemLib.c @@ -0,0 +1,87 @@ +/** ResetSystemLib.c + Do a generic Cold Reset for LS1043a + + Based on Reset system library implementation in + BeagleBoardPkg/Library/ResetSystemLib/ResetSystemLib.c + + Copyright (c) 2008 - 2010, Apple Inc. All rights reserved.<BR> + Copyright (c) 2016, Freescale Semiconductor, Inc. All rights reserved. + + This program and the accompanying materials + are licensed and made available under the terms and conditions of the BSD License + which accompanies this distribution. The full text of the license may be found at + http://opensource.org/licenses/bsd-license.php + + THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, + WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. + +**/ + +#include <Uefi.h> + +#include <Library/ArmLib.h> +#include <Library/CacheMaintenanceLib.h> +#include <Library/MemoryAllocationLib.h> +#include <Library/IoLib.h> +#include <Library/PcdLib.h> +#include <Library/TimerLib.h> +#include <Library/DebugLib.h> +#include <Library/UefiBootServicesTableLib.h> + +#include <Library/PlatformLib.h> + +#define BITMASK8 0xff +/** + Resets the entire platform. + + @param ResetType The type of reset to perform. + @param ResetStatus The status code for the reset. + @param DataSize The size, in bytes, of WatchdogData. + @param ResetData For a ResetType of EfiResetCold, EfiResetWarm, or + EfiResetShutdown the data buffer starts with a Null-terminated + Unicode string, optionally followed by additional binary data. + +**/ +EFI_STATUS +EFIAPI +LibResetSystem ( + IN EFI_RESET_TYPE ResetType, + IN EFI_STATUS ResetStatus, + IN UINTN DataSize, + IN CHAR16 *ResetData OPTIONAL + ) +{ + UINT16 Val; + + //Perform cold reset of the system. + Val = MmioReadBe16 (WDOG1_BASE_ADDR + WDOG_WCR_OFFSET); + Val &= BITMASK8; + Val |= WDOG_WCR_WDE; + MmioWriteBe16 (WDOG1_BASE_ADDR + WDOG_WCR_OFFSET, Val); + MmioWriteBe16(WDOG1_BASE_ADDR + WDOG_WSR_OFFSET, WDOG_SERVICE_SEQ1); + MmioWriteBe16(WDOG1_BASE_ADDR + WDOG_WSR_OFFSET, WDOG_SERVICE_SEQ2); + MicroSecondDelay(1000000); + + // If the reset didn't work, return an error. + ASSERT (FALSE); + return EFI_DEVICE_ERROR; +} + +/** + Initialize any infrastructure required for LibResetSystem () to function. + + @param ImageHandle The firmware allocated handle for the EFI image. + @param SystemTable A pointer to the EFI System Table. + + @retval EFI_SUCCESS The constructor always returns EFI_SUCCESS. + +**/ +EFI_STATUS +EFIAPI +LibInitializeResetSystem ( + IN EFI_HANDLE ImageHandle, + IN EFI_SYSTEM_TABLE *SystemTable + ) +{ + return EFI_SUCCESS; +} diff --git a/Platforms/Nxp/LS1043aRdb/Library/ResetSystemLib/ResetSystemLib.inf b/Platforms/Nxp/LS1043aRdb/Library/ResetSystemLib/ResetSystemLib.inf new file mode 100644 index 0000000..b568dcf --- /dev/null +++ b/Platforms/Nxp/LS1043aRdb/Library/ResetSystemLib/ResetSystemLib.inf @@ -0,0 +1,50 @@ +#/** @ResetSystemLib.inf +# Reset System lib to make it easy to port new platforms +# +# Copyright (c) 2016, Freescale Semiconductor, Inc. All rights reserved. +# +# This program and the accompanying materials +# are licensed and made available under the terms and conditions of the BSD License +# which accompanies this distribution. The full text of the license may be found at +# http://opensource.org/licenses/bsd-license.php +# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, +# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. +# +# +#**/ + +[Defines] + INF_VERSION = 0x00010005 + BASE_NAME = LS1043aRdbResetSystemLib + FILE_GUID = 781371a2-3fdd-41d4-96a1-7b34cbc9e895 + MODULE_TYPE = BASE + VERSION_STRING = 1.0 + LIBRARY_CLASS = EfiResetSystemLib + + +[Sources.common] + ResetSystemLib.c + +[Packages] + MdePkg/MdePkg.dec + ArmPkg/ArmPkg.dec + EmbeddedPkg/EmbeddedPkg.dec + OpenPlatformPkg/Platforms/Nxp/LS1043aRdb/LS1043aRdbPkg.dec + +[Pcd.common] + gArmTokenSpaceGuid.PcdCpuResetAddress + gEmbeddedTokenSpaceGuid.PcdEmbeddedFdBaseAddress + +[LibraryClasses] + DebugLib + ArmLib + IoLib + CacheMaintenanceLib + MemoryAllocationLib + UefiRuntimeServicesTableLib + TimerLib + UefiLib + UefiBootServicesTableLib + +[FixedPcd] + gArmTokenSpaceGuid.PcdFvBaseAddress
On 17 October 2016 at 21:04, Bhupesh Sharma bhupesh.sharma@freescale.com wrote:
From: Sakar Arora sakar.arora@nxp.com
This patch adds the support for system reset library which can be used to invoke a system reset via the UEFI shell on LS1043A-RDB board.
Signed-off-by: Sakar Arora sakar.arora@nxp.com Signed-off-by: Bhupesh Sharma bhupesh.sharma@nxp.com
.../Library/ResetSystemLib/ResetSystemLib.c | 87 ++++++++++++++++++++++ .../Library/ResetSystemLib/ResetSystemLib.inf | 50 +++++++++++++ 2 files changed, 137 insertions(+) create mode 100644 Platforms/Nxp/LS1043aRdb/Library/ResetSystemLib/ResetSystemLib.c create mode 100644 Platforms/Nxp/LS1043aRdb/Library/ResetSystemLib/ResetSystemLib.inf
diff --git a/Platforms/Nxp/LS1043aRdb/Library/ResetSystemLib/ResetSystemLib.c b/Platforms/Nxp/LS1043aRdb/Library/ResetSystemLib/ResetSystemLib.c new file mode 100644 index 0000000..831dd3a --- /dev/null +++ b/Platforms/Nxp/LS1043aRdb/Library/ResetSystemLib/ResetSystemLib.c @@ -0,0 +1,87 @@ +/** ResetSystemLib.c
- Do a generic Cold Reset for LS1043a
- Based on Reset system library implementation in
- BeagleBoardPkg/Library/ResetSystemLib/ResetSystemLib.c
- Copyright (c) 2008 - 2010, Apple Inc. All rights reserved.<BR>
- Copyright (c) 2016, Freescale Semiconductor, Inc. All rights reserved.
- This program and the accompanying materials
- are licensed and made available under the terms and conditions of the BSD License
- which accompanies this distribution. The full text of the license may be found at
- http://opensource.org/licenses/bsd-license.php
- THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
- WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
+**/
+#include <Uefi.h>
+#include <Library/ArmLib.h> +#include <Library/CacheMaintenanceLib.h> +#include <Library/MemoryAllocationLib.h> +#include <Library/IoLib.h> +#include <Library/PcdLib.h> +#include <Library/TimerLib.h> +#include <Library/DebugLib.h> +#include <Library/UefiBootServicesTableLib.h>
+#include <Library/PlatformLib.h>
+#define BITMASK8 0xff +/**
- Resets the entire platform.
- @param ResetType The type of reset to perform.
- @param ResetStatus The status code for the reset.
- @param DataSize The size, in bytes, of WatchdogData.
- @param ResetData For a ResetType of EfiResetCold, EfiResetWarm, or
EfiResetShutdown the data buffer starts with a Null-terminated
Unicode string, optionally followed by additional binary data.
+**/ +EFI_STATUS +EFIAPI +LibResetSystem (
- IN EFI_RESET_TYPE ResetType,
- IN EFI_STATUS ResetStatus,
- IN UINTN DataSize,
- IN CHAR16 *ResetData OPTIONAL
- )
+{
- UINT16 Val;
- //Perform cold reset of the system.
- Val = MmioReadBe16 (WDOG1_BASE_ADDR + WDOG_WCR_OFFSET);
- Val &= BITMASK8;
- Val |= WDOG_WCR_WDE;
- MmioWriteBe16 (WDOG1_BASE_ADDR + WDOG_WCR_OFFSET, Val);
- MmioWriteBe16(WDOG1_BASE_ADDR + WDOG_WSR_OFFSET, WDOG_SERVICE_SEQ1);
- MmioWriteBe16(WDOG1_BASE_ADDR + WDOG_WSR_OFFSET, WDOG_SERVICE_SEQ2);
This will explode when invoked at runtime (i.e., from the OS)
Please look at ArmPlatformPkg/Library/PL031RealTimeClockLib/PL031RealTimeClockLib.c for an example how to register the MMIO range for use by runtime services.
- MicroSecondDelay(1000000);
- // If the reset didn't work, return an error.
- ASSERT (FALSE);
- return EFI_DEVICE_ERROR;
+}
+/**
- Initialize any infrastructure required for LibResetSystem () to function.
- @param ImageHandle The firmware allocated handle for the EFI image.
- @param SystemTable A pointer to the EFI System Table.
- @retval EFI_SUCCESS The constructor always returns EFI_SUCCESS.
+**/ +EFI_STATUS +EFIAPI +LibInitializeResetSystem (
- IN EFI_HANDLE ImageHandle,
- IN EFI_SYSTEM_TABLE *SystemTable
- )
+{
- return EFI_SUCCESS;
+} diff --git a/Platforms/Nxp/LS1043aRdb/Library/ResetSystemLib/ResetSystemLib.inf b/Platforms/Nxp/LS1043aRdb/Library/ResetSystemLib/ResetSystemLib.inf new file mode 100644 index 0000000..b568dcf --- /dev/null +++ b/Platforms/Nxp/LS1043aRdb/Library/ResetSystemLib/ResetSystemLib.inf @@ -0,0 +1,50 @@ +#/** @ResetSystemLib.inf +# Reset System lib to make it easy to port new platforms +# +# Copyright (c) 2016, Freescale Semiconductor, Inc. All rights reserved. +# +# This program and the accompanying materials +# are licensed and made available under the terms and conditions of the BSD License +# which accompanies this distribution. The full text of the license may be found at +# http://opensource.org/licenses/bsd-license.php +# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, +# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. +# +# +#**/
+[Defines]
- INF_VERSION = 0x00010005
- BASE_NAME = LS1043aRdbResetSystemLib
- FILE_GUID = 781371a2-3fdd-41d4-96a1-7b34cbc9e895
Fresh GUID
- MODULE_TYPE = BASE
- VERSION_STRING = 1.0
- LIBRARY_CLASS = EfiResetSystemLib
+[Sources.common]
- ResetSystemLib.c
+[Packages]
- MdePkg/MdePkg.dec
- ArmPkg/ArmPkg.dec
- EmbeddedPkg/EmbeddedPkg.dec
- OpenPlatformPkg/Platforms/Nxp/LS1043aRdb/LS1043aRdbPkg.dec
+[Pcd.common]
- gArmTokenSpaceGuid.PcdCpuResetAddress
- gEmbeddedTokenSpaceGuid.PcdEmbeddedFdBaseAddress
+[LibraryClasses]
- DebugLib
- ArmLib
- IoLib
- CacheMaintenanceLib
- MemoryAllocationLib
- UefiRuntimeServicesTableLib
- TimerLib
- UefiLib
- UefiBootServicesTableLib
Are you using all of these? Please only include library classes that you actually depend on
+[FixedPcd]
- gArmTokenSpaceGuid.PcdFvBaseAddress
same here
-- 1.9.1
Hi Ard,
Please see my replies inline.
From: Ard Biesheuvel [mailto:ard.biesheuvel@linaro.org] Sent: Tuesday, October 18, 2016 3:07 PM
On 17 October 2016 at 21:04, Bhupesh Sharma bhupesh.sharma@freescale.com wrote:
From: Sakar Arora sakar.arora@nxp.com
This patch adds the support for system reset library which can be
used
to invoke a system reset via the UEFI shell on LS1043A-RDB board.
Signed-off-by: Sakar Arora sakar.arora@nxp.com Signed-off-by: Bhupesh Sharma bhupesh.sharma@nxp.com
.../Library/ResetSystemLib/ResetSystemLib.c | 87
++++++++++++++++++++++
.../Library/ResetSystemLib/ResetSystemLib.inf | 50
+++++++++++++
2 files changed, 137 insertions(+) create mode 100644 Platforms/Nxp/LS1043aRdb/Library/ResetSystemLib/ResetSystemLib.c create mode 100644 Platforms/Nxp/LS1043aRdb/Library/ResetSystemLib/ResetSystemLib.inf
diff --git a/Platforms/Nxp/LS1043aRdb/Library/ResetSystemLib/ResetSystemLib.c b/Platforms/Nxp/LS1043aRdb/Library/ResetSystemLib/ResetSystemLib.c new file mode 100644 index 0000000..831dd3a --- /dev/null +++
b/Platforms/Nxp/LS1043aRdb/Library/ResetSystemLib/ResetSystemLib.c
@@ -0,0 +1,87 @@ +/** ResetSystemLib.c
- Do a generic Cold Reset for LS1043a
- Based on Reset system library implementation in
- BeagleBoardPkg/Library/ResetSystemLib/ResetSystemLib.c
- Copyright (c) 2008 - 2010, Apple Inc. All rights reserved.<BR>
- Copyright (c) 2016, Freescale Semiconductor, Inc. All rights
reserved.
- This program and the accompanying materials are licensed and made
- available under the terms and conditions of the BSD License which
- accompanies this distribution. The full text of the license may be
- found at http://opensource.org/licenses/bsd-license.php
- THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS"
- BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER
EXPRESS OR IMPLIED.
+**/
+#include <Uefi.h>
+#include <Library/ArmLib.h> +#include <Library/CacheMaintenanceLib.h> #include +<Library/MemoryAllocationLib.h> #include <Library/IoLib.h> #include +<Library/PcdLib.h> #include <Library/TimerLib.h> #include +<Library/DebugLib.h> #include <Library/UefiBootServicesTableLib.h>
+#include <Library/PlatformLib.h>
+#define BITMASK8 0xff +/**
- Resets the entire platform.
- @param ResetType The type of reset to perform.
- @param ResetStatus The status code for the reset.
- @param DataSize The size, in bytes, of WatchdogData.
- @param ResetData For a ResetType of EfiResetCold,
EfiResetWarm, or
EfiResetShutdown the data buffer
starts with a Null-terminated
Unicode string, optionally followed
by additional binary data.
+**/ +EFI_STATUS +EFIAPI +LibResetSystem (
- IN EFI_RESET_TYPE ResetType,
- IN EFI_STATUS ResetStatus,
- IN UINTN DataSize,
- IN CHAR16 *ResetData OPTIONAL
- )
+{
- UINT16 Val;
- //Perform cold reset of the system.
- Val = MmioReadBe16 (WDOG1_BASE_ADDR + WDOG_WCR_OFFSET); Val &=
- BITMASK8; Val |= WDOG_WCR_WDE;
- MmioWriteBe16 (WDOG1_BASE_ADDR + WDOG_WCR_OFFSET, Val);
- MmioWriteBe16(WDOG1_BASE_ADDR + WDOG_WSR_OFFSET,
WDOG_SERVICE_SEQ1);
- MmioWriteBe16(WDOG1_BASE_ADDR + WDOG_WSR_OFFSET,
WDOG_SERVICE_SEQ2);
This will explode when invoked at runtime (i.e., from the OS)
Please look at ArmPlatformPkg/Library/PL031RealTimeClockLib/PL031RealTimeClockLib.c for an example how to register the MMIO range for use by runtime services.
Right. Like I mentioned in the comments to another review, we have added the RT support for LS1043A UEFI where we also added the correct implementation for RTC clock.
We will send this in the v2.
- MicroSecondDelay(1000000);
- // If the reset didn't work, return an error.
- ASSERT (FALSE);
- return EFI_DEVICE_ERROR;
+}
+/**
- Initialize any infrastructure required for LibResetSystem () to
function.
- @param ImageHandle The firmware allocated handle for the EFI
image.
- @param SystemTable A pointer to the EFI System Table.
- @retval EFI_SUCCESS The constructor always returns EFI_SUCCESS.
+**/ +EFI_STATUS +EFIAPI +LibInitializeResetSystem (
- IN EFI_HANDLE ImageHandle,
- IN EFI_SYSTEM_TABLE *SystemTable
- )
+{
- return EFI_SUCCESS;
+} diff --git a/Platforms/Nxp/LS1043aRdb/Library/ResetSystemLib/ResetSystemLib.inf b/Platforms/Nxp/LS1043aRdb/Library/ResetSystemLib/ResetSystemLib.inf new file mode 100644 index 0000000..b568dcf --- /dev/null +++
b/Platforms/Nxp/LS1043aRdb/Library/ResetSystemLib/ResetSystemLib.i
+++ nf @@ -0,0 +1,50 @@ +#/** @ResetSystemLib.inf +# Reset System lib to make it easy to port new platforms # # +Copyright (c) 2016, Freescale Semiconductor, Inc. All rights
reserved.
+# +# This program and the accompanying materials # are licensed and +made available under the terms and conditions of the BSD License # +which accompanies this distribution. The full text of the license
may
+be found at # http://opensource.org/licenses/bsd-license.php +# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" +BASIS, # WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER
EXPRESS OR IMPLIED.
+# +# +#**/
+[Defines]
- INF_VERSION = 0x00010005
- BASE_NAME = LS1043aRdbResetSystemLib
- FILE_GUID = 781371a2-3fdd-41d4-96a1-
7b34cbc9e895
Fresh GUID
Ok.
- MODULE_TYPE = BASE
- VERSION_STRING = 1.0
- LIBRARY_CLASS = EfiResetSystemLib
+[Sources.common]
- ResetSystemLib.c
+[Packages]
- MdePkg/MdePkg.dec
- ArmPkg/ArmPkg.dec
- EmbeddedPkg/EmbeddedPkg.dec
- OpenPlatformPkg/Platforms/Nxp/LS1043aRdb/LS1043aRdbPkg.dec
+[Pcd.common]
- gArmTokenSpaceGuid.PcdCpuResetAddress
- gEmbeddedTokenSpaceGuid.PcdEmbeddedFdBaseAddress
+[LibraryClasses]
- DebugLib
- ArmLib
- IoLib
- CacheMaintenanceLib
- MemoryAllocationLib
- UefiRuntimeServicesTableLib
- TimerLib
- UefiLib
- UefiBootServicesTableLib
Are you using all of these? Please only include library classes that you actually depend on
Sure, will fix this in v2.
+[FixedPcd]
- gArmTokenSpaceGuid.PcdFvBaseAddress
same here
Ok.
Regards, Bhupesh
On Tue, Oct 18, 2016 at 01:34:06AM +0530, Bhupesh Sharma wrote:
From: Sakar Arora sakar.arora@nxp.com
This patch adds the support for system reset library which can be used to invoke a system reset via the UEFI shell on LS1043A-RDB board.
Signed-off-by: Sakar Arora sakar.arora@nxp.com Signed-off-by: Bhupesh Sharma bhupesh.sharma@nxp.com
.../Library/ResetSystemLib/ResetSystemLib.c | 87 ++++++++++++++++++++++ .../Library/ResetSystemLib/ResetSystemLib.inf | 50 +++++++++++++ 2 files changed, 137 insertions(+) create mode 100644 Platforms/Nxp/LS1043aRdb/Library/ResetSystemLib/ResetSystemLib.c create mode 100644 Platforms/Nxp/LS1043aRdb/Library/ResetSystemLib/ResetSystemLib.inf
diff --git a/Platforms/Nxp/LS1043aRdb/Library/ResetSystemLib/ResetSystemLib.c b/Platforms/Nxp/LS1043aRdb/Library/ResetSystemLib/ResetSystemLib.c new file mode 100644 index 0000000..831dd3a --- /dev/null +++ b/Platforms/Nxp/LS1043aRdb/Library/ResetSystemLib/ResetSystemLib.c @@ -0,0 +1,87 @@ +/** ResetSystemLib.c
- Do a generic Cold Reset for LS1043a
- Based on Reset system library implementation in
- BeagleBoardPkg/Library/ResetSystemLib/ResetSystemLib.c
- Copyright (c) 2008 - 2010, Apple Inc. All rights reserved.<BR>
- Copyright (c) 2016, Freescale Semiconductor, Inc. All rights reserved.
- This program and the accompanying materials
- are licensed and made available under the terms and conditions of the BSD License
- which accompanies this distribution. The full text of the license may be found at
- http://opensource.org/licenses/bsd-license.php
- THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
- WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
+**/
+#include <Uefi.h>
+#include <Library/ArmLib.h> +#include <Library/CacheMaintenanceLib.h> +#include <Library/MemoryAllocationLib.h> +#include <Library/IoLib.h> +#include <Library/PcdLib.h> +#include <Library/TimerLib.h> +#include <Library/DebugLib.h> +#include <Library/UefiBootServicesTableLib.h>
+#include <Library/PlatformLib.h>
Sorted includes, please?
+#define BITMASK8 0xff +/**
- Resets the entire platform.
- @param ResetType The type of reset to perform.
- @param ResetStatus The status code for the reset.
- @param DataSize The size, in bytes, of WatchdogData.
- @param ResetData For a ResetType of EfiResetCold, EfiResetWarm, or
EfiResetShutdown the data buffer starts with a Null-terminated
Unicode string, optionally followed by additional binary data.
+**/ +EFI_STATUS +EFIAPI +LibResetSystem (
- IN EFI_RESET_TYPE ResetType,
- IN EFI_STATUS ResetStatus,
- IN UINTN DataSize,
- IN CHAR16 *ResetData OPTIONAL
- )
+{
- UINT16 Val;
- //Perform cold reset of the system.
- Val = MmioReadBe16 (WDOG1_BASE_ADDR + WDOG_WCR_OFFSET);
- Val &= BITMASK8;
- Val |= WDOG_WCR_WDE;
- MmioWriteBe16 (WDOG1_BASE_ADDR + WDOG_WCR_OFFSET, Val);
- MmioWriteBe16(WDOG1_BASE_ADDR + WDOG_WSR_OFFSET, WDOG_SERVICE_SEQ1);
- MmioWriteBe16(WDOG1_BASE_ADDR + WDOG_WSR_OFFSET, WDOG_SERVICE_SEQ2);
Space before those (.
Do you need a barrier in here at all?
- MicroSecondDelay(1000000);
- // If the reset didn't work, return an error.
- ASSERT (FALSE);
- return EFI_DEVICE_ERROR;
+}
+/**
- Initialize any infrastructure required for LibResetSystem () to function.
- @param ImageHandle The firmware allocated handle for the EFI image.
- @param SystemTable A pointer to the EFI System Table.
- @retval EFI_SUCCESS The constructor always returns EFI_SUCCESS.
+**/ +EFI_STATUS +EFIAPI +LibInitializeResetSystem (
- IN EFI_HANDLE ImageHandle,
- IN EFI_SYSTEM_TABLE *SystemTable
- )
+{
- return EFI_SUCCESS;
+} diff --git a/Platforms/Nxp/LS1043aRdb/Library/ResetSystemLib/ResetSystemLib.inf b/Platforms/Nxp/LS1043aRdb/Library/ResetSystemLib/ResetSystemLib.inf new file mode 100644 index 0000000..b568dcf --- /dev/null +++ b/Platforms/Nxp/LS1043aRdb/Library/ResetSystemLib/ResetSystemLib.inf @@ -0,0 +1,50 @@ +#/** @ResetSystemLib.inf +# Reset System lib to make it easy to port new platforms +# +# Copyright (c) 2016, Freescale Semiconductor, Inc. All rights reserved. +# +# This program and the accompanying materials +# are licensed and made available under the terms and conditions of the BSD License +# which accompanies this distribution. The full text of the license may be found at +# http://opensource.org/licenses/bsd-license.php +# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, +# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. +# +# +#**/
+[Defines]
- INF_VERSION = 0x00010005
- BASE_NAME = LS1043aRdbResetSystemLib
- FILE_GUID = 781371a2-3fdd-41d4-96a1-7b34cbc9e895
- MODULE_TYPE = BASE
- VERSION_STRING = 1.0
- LIBRARY_CLASS = EfiResetSystemLib
+[Sources.common]
- ResetSystemLib.c
+[Packages]
- MdePkg/MdePkg.dec
- ArmPkg/ArmPkg.dec
- EmbeddedPkg/EmbeddedPkg.dec
- OpenPlatformPkg/Platforms/Nxp/LS1043aRdb/LS1043aRdbPkg.dec
+[Pcd.common]
- gArmTokenSpaceGuid.PcdCpuResetAddress
- gEmbeddedTokenSpaceGuid.PcdEmbeddedFdBaseAddress
+[LibraryClasses]
- DebugLib
- ArmLib
- IoLib
- CacheMaintenanceLib
- MemoryAllocationLib
- UefiRuntimeServicesTableLib
- TimerLib
- UefiLib
- UefiBootServicesTableLib
Can we sort LibraryClasses and packages please?
+[FixedPcd]
- gArmTokenSpaceGuid.PcdFvBaseAddress
-- 1.9.1
Hi Leif,
From: Leif Lindholm [mailto:leif.lindholm@linaro.org] Sent: Saturday, November 05, 2016 3:15 AM
On Tue, Oct 18, 2016 at 01:34:06AM +0530, Bhupesh Sharma wrote:
From: Sakar Arora sakar.arora@nxp.com
This patch adds the support for system reset library which can be
used
to invoke a system reset via the UEFI shell on LS1043A-RDB board.
Signed-off-by: Sakar Arora sakar.arora@nxp.com Signed-off-by: Bhupesh Sharma bhupesh.sharma@nxp.com
.../Library/ResetSystemLib/ResetSystemLib.c | 87
++++++++++++++++++++++
.../Library/ResetSystemLib/ResetSystemLib.inf | 50
+++++++++++++
2 files changed, 137 insertions(+) create mode 100644 Platforms/Nxp/LS1043aRdb/Library/ResetSystemLib/ResetSystemLib.c create mode 100644 Platforms/Nxp/LS1043aRdb/Library/ResetSystemLib/ResetSystemLib.inf
diff --git a/Platforms/Nxp/LS1043aRdb/Library/ResetSystemLib/ResetSystemLib.c b/Platforms/Nxp/LS1043aRdb/Library/ResetSystemLib/ResetSystemLib.c new file mode 100644 index 0000000..831dd3a --- /dev/null +++
b/Platforms/Nxp/LS1043aRdb/Library/ResetSystemLib/ResetSystemLib.c
@@ -0,0 +1,87 @@ +/** ResetSystemLib.c
- Do a generic Cold Reset for LS1043a
- Based on Reset system library implementation in
- BeagleBoardPkg/Library/ResetSystemLib/ResetSystemLib.c
- Copyright (c) 2008 - 2010, Apple Inc. All rights reserved.<BR>
- Copyright (c) 2016, Freescale Semiconductor, Inc. All rights
reserved.
- This program and the accompanying materials are licensed and made
- available under the terms and conditions of the BSD License which
- accompanies this distribution. The full text of the license may be
- found at http://opensource.org/licenses/bsd-license.php
- THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS"
- BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER
EXPRESS OR IMPLIED.
+**/
+#include <Uefi.h>
+#include <Library/ArmLib.h> +#include <Library/CacheMaintenanceLib.h> #include +<Library/MemoryAllocationLib.h> #include <Library/IoLib.h> #include +<Library/PcdLib.h> #include <Library/TimerLib.h> #include +<Library/DebugLib.h> #include <Library/UefiBootServicesTableLib.h>
+#include <Library/PlatformLib.h>
Sorted includes, please?
Ok.
+#define BITMASK8 0xff +/**
- Resets the entire platform.
- @param ResetType The type of reset to perform.
- @param ResetStatus The status code for the reset.
- @param DataSize The size, in bytes, of WatchdogData.
- @param ResetData For a ResetType of EfiResetCold,
EfiResetWarm, or
EfiResetShutdown the data buffer
starts with a Null-terminated
Unicode string, optionally followed
by additional binary data.
+**/ +EFI_STATUS +EFIAPI +LibResetSystem (
- IN EFI_RESET_TYPE ResetType,
- IN EFI_STATUS ResetStatus,
- IN UINTN DataSize,
- IN CHAR16 *ResetData OPTIONAL
- )
+{
- UINT16 Val;
- //Perform cold reset of the system.
- Val = MmioReadBe16 (WDOG1_BASE_ADDR + WDOG_WCR_OFFSET); Val &=
- BITMASK8; Val |= WDOG_WCR_WDE;
- MmioWriteBe16 (WDOG1_BASE_ADDR + WDOG_WCR_OFFSET, Val);
- MmioWriteBe16(WDOG1_BASE_ADDR + WDOG_WSR_OFFSET,
WDOG_SERVICE_SEQ1);
- MmioWriteBe16(WDOG1_BASE_ADDR + WDOG_WSR_OFFSET,
WDOG_SERVICE_SEQ2);
Space before those (.
Ok.
Do you need a barrier in here at all?
We did not see an issue without barriers in-place. But will have a relook before sending the V2.
- MicroSecondDelay(1000000);
- // If the reset didn't work, return an error.
- ASSERT (FALSE);
- return EFI_DEVICE_ERROR;
+}
+/**
- Initialize any infrastructure required for LibResetSystem () to
function.
- @param ImageHandle The firmware allocated handle for the EFI
image.
- @param SystemTable A pointer to the EFI System Table.
- @retval EFI_SUCCESS The constructor always returns EFI_SUCCESS.
+**/ +EFI_STATUS +EFIAPI +LibInitializeResetSystem (
- IN EFI_HANDLE ImageHandle,
- IN EFI_SYSTEM_TABLE *SystemTable
- )
+{
- return EFI_SUCCESS;
+} diff --git a/Platforms/Nxp/LS1043aRdb/Library/ResetSystemLib/ResetSystemLib.inf b/Platforms/Nxp/LS1043aRdb/Library/ResetSystemLib/ResetSystemLib.inf new file mode 100644 index 0000000..b568dcf --- /dev/null +++
b/Platforms/Nxp/LS1043aRdb/Library/ResetSystemLib/ResetSystemLib.i
+++ nf @@ -0,0 +1,50 @@ +#/** @ResetSystemLib.inf +# Reset System lib to make it easy to port new platforms # # +Copyright (c) 2016, Freescale Semiconductor, Inc. All rights
reserved.
+# +# This program and the accompanying materials # are licensed and +made available under the terms and conditions of the BSD License # +which accompanies this distribution. The full text of the license
may
+be found at # http://opensource.org/licenses/bsd-license.php +# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" +BASIS, # WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER
EXPRESS OR IMPLIED.
+# +# +#**/
+[Defines]
- INF_VERSION = 0x00010005
- BASE_NAME = LS1043aRdbResetSystemLib
- FILE_GUID = 781371a2-3fdd-41d4-96a1-
7b34cbc9e895
- MODULE_TYPE = BASE
- VERSION_STRING = 1.0
- LIBRARY_CLASS = EfiResetSystemLib
+[Sources.common]
- ResetSystemLib.c
+[Packages]
- MdePkg/MdePkg.dec
- ArmPkg/ArmPkg.dec
- EmbeddedPkg/EmbeddedPkg.dec
- OpenPlatformPkg/Platforms/Nxp/LS1043aRdb/LS1043aRdbPkg.dec
+[Pcd.common]
- gArmTokenSpaceGuid.PcdCpuResetAddress
- gEmbeddedTokenSpaceGuid.PcdEmbeddedFdBaseAddress
+[LibraryClasses]
- DebugLib
- ArmLib
- IoLib
- CacheMaintenanceLib
- MemoryAllocationLib
- UefiRuntimeServicesTableLib
- TimerLib
- UefiLib
- UefiBootServicesTableLib
Can we sort LibraryClasses and packages please?
Ok.
+[FixedPcd]
- gArmTokenSpaceGuid.PcdFvBaseAddress
-- 1.9.1
From: Sakar Arora sakar.arora@nxp.com
This is the first UEFI module that executes after power on.
It runs from XIP NOR flash memory and uses on-chip OCRAM as stack.
It also iniitializes DDR controller, copies rest of UEFI firmware to DDR memory and transfers control to it.
Signed-off-by: Sakar Arora sakar.arora@nxp.com Signed-off-by: Bhupesh Sharma bhupesh.sharma@nxp.com --- .../Library/PrePiNor/AArch64/ModuleEntryPoint.S | 34 ++++++++++++++ Chips/Nxp/QoriqLs/Library/PrePiNor/PrePiNor.c | 52 ++++++++++++++++++++++ Chips/Nxp/QoriqLs/Library/PrePiNor/PrePiNor.inf | 48 ++++++++++++++++++++ 3 files changed, 134 insertions(+) create mode 100644 Chips/Nxp/QoriqLs/Library/PrePiNor/AArch64/ModuleEntryPoint.S create mode 100644 Chips/Nxp/QoriqLs/Library/PrePiNor/PrePiNor.c create mode 100644 Chips/Nxp/QoriqLs/Library/PrePiNor/PrePiNor.inf
diff --git a/Chips/Nxp/QoriqLs/Library/PrePiNor/AArch64/ModuleEntryPoint.S b/Chips/Nxp/QoriqLs/Library/PrePiNor/AArch64/ModuleEntryPoint.S new file mode 100644 index 0000000..6f3b373 --- /dev/null +++ b/Chips/Nxp/QoriqLs/Library/PrePiNor/AArch64/ModuleEntryPoint.S @@ -0,0 +1,34 @@ +// @ModuleEntryPoint.S +// +// Copyright (c) 2016, Freescale Semiconductor, Inc. All rights reserved. +// +// This program and the accompanying materials +// are licensed and made available under the terms and conditions of the BSD License +// which accompanies this distribution. The full text of the license may be found at +// http://opensource.org/licenses/bsd-license.php +// +// THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, +// WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. +// + +#include <AutoGen.h> +#include <AsmMacroIoLibV8.h> +#include <Library/PcdLib.h> + +.text +.align 3 + +GCC_ASM_EXPORT(_ModuleEntryPoint) + +StartupAddr: .8byte ASM_PFX(CEntryPoint) + +ASM_PFX(_ModuleEntryPoint): + LoadConstantToReg (FixedPcdGet32(PcdOcramStackBase), x0) + mov sp, x0 + LoadConstantToReg (FixedPcdGet64(PcdFdBaseAddress), x0) + LoadConstantToReg (FixedPcdGet32(PcdFdNorBaseAddress), x1) + LoadConstantToReg (FixedPcdGet32(PcdPiFdSize), x5) + add x1, x1, x5 + LoadConstantToReg (FixedPcdGet32(PcdFdSize), x2) + ldr x4, StartupAddr + blr x4 diff --git a/Chips/Nxp/QoriqLs/Library/PrePiNor/PrePiNor.c b/Chips/Nxp/QoriqLs/Library/PrePiNor/PrePiNor.c new file mode 100644 index 0000000..4c808db --- /dev/null +++ b/Chips/Nxp/QoriqLs/Library/PrePiNor/PrePiNor.c @@ -0,0 +1,52 @@ +/** @LS1043aPrePiNor.c +# +# Copyright (c) 2016, Freescale Semiconductor, Inc. All rights reserved. +# +# This program and the accompanying materials +# are licensed and made available under the terms and conditions of the BSD License +# which accompanies this distribution. The full text of the license may be found at +# http://opensource.org/licenses/bsd-license.php +# +# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, +# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. +# +**/ + + +#include <Library/ArmLib.h> +#include <Library/PcdLib.h> + +extern VOID DramInit(); + +UINTN mGlobalVariableBase = 0; + +VOID CopyImage(UINT8* Dest, UINT8* Src, UINTN Size) +{ + UINTN Count; + for(Count = 0; Count < Size; Count++) { + Dest[Count] = Src[Count]; + } +} + +VOID CEntryPoint( + UINTN UefiMemoryBase, + UINTN UefiNorBase, + UINTN UefiMemorySize +) +{ + VOID (*PrePiStart)(VOID); + +// Data Cache enabled on Primary core when MMU is enabled. + ArmDisableDataCache (); + // Invalidate instruction cache + ArmInvalidateInstructionCache (); + // Enable Instruction Caches on all cores. + ArmEnableInstructionCache (); + + DramInit(); + + CopyImage((VOID*)UefiMemoryBase, (VOID*)UefiNorBase, UefiMemorySize); + + PrePiStart = (VOID (*)())((UINT64)PcdGet64(PcdFvBaseAddress)); + PrePiStart(); +} diff --git a/Chips/Nxp/QoriqLs/Library/PrePiNor/PrePiNor.inf b/Chips/Nxp/QoriqLs/Library/PrePiNor/PrePiNor.inf new file mode 100644 index 0000000..1b78fa5 --- /dev/null +++ b/Chips/Nxp/QoriqLs/Library/PrePiNor/PrePiNor.inf @@ -0,0 +1,48 @@ +#/** @PrePiNor.inf +# +# Copyright (c) 2016, Freescale Semiconductor, Inc. All rights reserved. +# +# This program and the accompanying materials +# are licensed and made available under the terms and conditions of the BSD License +# which accompanies this distribution. The full text of the license may be found at +# http://opensource.org/licenses/bsd-license.php +# +# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, +# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. +# +#**/ + +[Defines] + INF_VERSION = 0x00010005 + BASE_NAME = PrePiNor + FILE_GUID = d959e387-7b91-452c-90e1-a1dbac10ddb8 + MODULE_TYPE = SEC + VERSION_STRING = 1.0 + +[Sources] + PrePiNor.c + +[Sources.AArch64] + AArch64/ModuleEntryPoint.S + +[Packages] + MdePkg/MdePkg.dec + ArmPkg/ArmPkg.dec + ArmPlatformPkg/ArmPlatformPkg.dec + OpenPlatformPkg/Chips/Nxp/QoriqLs/NxpQoriqLs.dec + +[LibraryClasses] + ArmLib + PcdLib + DdrLib + +[FixedPcd] + gNxpQoriqLsTokenSpaceGuid.PcdOcramStackBase + gNxpQoriqLsTokenSpaceGuid.PcdFdNorBaseAddress + gNxpQoriqLsTokenSpaceGuid.PcdPiFdSize + gArmTokenSpaceGuid.PcdFdBaseAddress + gArmTokenSpaceGuid.PcdFdSize + gArmTokenSpaceGuid.PcdSystemMemoryBase + gArmTokenSpaceGuid.PcdSystemMemorySize + gArmPlatformTokenSpaceGuid.PcdSystemMemoryUefiRegionSize + gArmTokenSpaceGuid.PcdFvBaseAddress
On 17 October 2016 at 21:04, Bhupesh Sharma bhupesh.sharma@freescale.com wrote:
From: Sakar Arora sakar.arora@nxp.com
This is the first UEFI module that executes after power on.
It runs from XIP NOR flash memory and uses on-chip OCRAM as stack.
It also iniitializes DDR controller, copies rest of UEFI firmware to DDR
typo ^^
memory and transfers control to it.
Signed-off-by: Sakar Arora sakar.arora@nxp.com Signed-off-by: Bhupesh Sharma bhupesh.sharma@nxp.com
.../Library/PrePiNor/AArch64/ModuleEntryPoint.S | 34 ++++++++++++++ Chips/Nxp/QoriqLs/Library/PrePiNor/PrePiNor.c | 52 ++++++++++++++++++++++ Chips/Nxp/QoriqLs/Library/PrePiNor/PrePiNor.inf | 48 ++++++++++++++++++++ 3 files changed, 134 insertions(+) create mode 100644 Chips/Nxp/QoriqLs/Library/PrePiNor/AArch64/ModuleEntryPoint.S create mode 100644 Chips/Nxp/QoriqLs/Library/PrePiNor/PrePiNor.c create mode 100644 Chips/Nxp/QoriqLs/Library/PrePiNor/PrePiNor.inf
diff --git a/Chips/Nxp/QoriqLs/Library/PrePiNor/AArch64/ModuleEntryPoint.S b/Chips/Nxp/QoriqLs/Library/PrePiNor/AArch64/ModuleEntryPoint.S new file mode 100644 index 0000000..6f3b373 --- /dev/null +++ b/Chips/Nxp/QoriqLs/Library/PrePiNor/AArch64/ModuleEntryPoint.S @@ -0,0 +1,34 @@ +// @ModuleEntryPoint.S +// +// Copyright (c) 2016, Freescale Semiconductor, Inc. All rights reserved. +// +// This program and the accompanying materials +// are licensed and made available under the terms and conditions of the BSD License +// which accompanies this distribution. The full text of the license may be found at +// http://opensource.org/licenses/bsd-license.php +// +// THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, +// WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. +//
+#include <AutoGen.h> +#include <AsmMacroIoLibV8.h> +#include <Library/PcdLib.h>
+.text +.align 3
+GCC_ASM_EXPORT(_ModuleEntryPoint)
+StartupAddr: .8byte ASM_PFX(CEntryPoint)
+ASM_PFX(_ModuleEntryPoint):
- LoadConstantToReg (FixedPcdGet32(PcdOcramStackBase), x0)
- mov sp, x0
- LoadConstantToReg (FixedPcdGet64(PcdFdBaseAddress), x0)
- LoadConstantToReg (FixedPcdGet32(PcdFdNorBaseAddress), x1)
- LoadConstantToReg (FixedPcdGet32(PcdPiFdSize), x5)
- add x1, x1, x5
- LoadConstantToReg (FixedPcdGet32(PcdFdSize), x2)
Please drop these LoadConstantToReg() invocations, and use MOV32/64 instead
- ldr x4, StartupAddr
- blr x4
diff --git a/Chips/Nxp/QoriqLs/Library/PrePiNor/PrePiNor.c b/Chips/Nxp/QoriqLs/Library/PrePiNor/PrePiNor.c new file mode 100644 index 0000000..4c808db --- /dev/null +++ b/Chips/Nxp/QoriqLs/Library/PrePiNor/PrePiNor.c @@ -0,0 +1,52 @@ +/** @LS1043aPrePiNor.c +# +# Copyright (c) 2016, Freescale Semiconductor, Inc. All rights reserved. +# +# This program and the accompanying materials +# are licensed and made available under the terms and conditions of the BSD License +# which accompanies this distribution. The full text of the license may be found at +# http://opensource.org/licenses/bsd-license.php +# +# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, +# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. +# +**/
+#include <Library/ArmLib.h> +#include <Library/PcdLib.h>
+extern VOID DramInit();
Please include the appropriate library header
+UINTN mGlobalVariableBase = 0;
What is this?
+VOID CopyImage(UINT8* Dest, UINT8* Src, UINTN Size) +{
- UINTN Count;
- for(Count = 0; Count < Size; Count++) {
- Dest[Count] = Src[Count];
- }
+}
Please use BaseMemoryLib in MdePkg. It works fine with the MMU and caches off
+VOID CEntryPoint(
- UINTN UefiMemoryBase,
- UINTN UefiNorBase,
- UINTN UefiMemorySize
+) +{
- VOID (*PrePiStart)(VOID);
+// Data Cache enabled on Primary core when MMU is enabled.
- ArmDisableDataCache ();
- // Invalidate instruction cache
- ArmInvalidateInstructionCache ();
- // Enable Instruction Caches on all cores.
- ArmEnableInstructionCache ();
- DramInit();
- CopyImage((VOID*)UefiMemoryBase, (VOID*)UefiNorBase, UefiMemorySize);
Why is this necessary? The code is already executing, so why do we need to move it?
In general, SEC and PEI can execute fine from NOR, and PEI_CORE will relocate itself to RAM as soon as it becomes available.
- PrePiStart = (VOID (*)())((UINT64)PcdGet64(PcdFvBaseAddress));
- PrePiStart();
+} diff --git a/Chips/Nxp/QoriqLs/Library/PrePiNor/PrePiNor.inf b/Chips/Nxp/QoriqLs/Library/PrePiNor/PrePiNor.inf new file mode 100644 index 0000000..1b78fa5 --- /dev/null +++ b/Chips/Nxp/QoriqLs/Library/PrePiNor/PrePiNor.inf @@ -0,0 +1,48 @@ +#/** @PrePiNor.inf +# +# Copyright (c) 2016, Freescale Semiconductor, Inc. All rights reserved. +# +# This program and the accompanying materials +# are licensed and made available under the terms and conditions of the BSD License +# which accompanies this distribution. The full text of the license may be found at +# http://opensource.org/licenses/bsd-license.php +# +# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, +# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. +# +#**/
+[Defines]
- INF_VERSION = 0x00010005
- BASE_NAME = PrePiNor
- FILE_GUID = d959e387-7b91-452c-90e1-a1dbac10ddb8
Fresh GUID
- MODULE_TYPE = SEC
- VERSION_STRING = 1.0
+[Sources]
- PrePiNor.c
+[Sources.AArch64]
- AArch64/ModuleEntryPoint.S
+[Packages]
- MdePkg/MdePkg.dec
- ArmPkg/ArmPkg.dec
- ArmPlatformPkg/ArmPlatformPkg.dec
- OpenPlatformPkg/Chips/Nxp/QoriqLs/NxpQoriqLs.dec
+[LibraryClasses]
- ArmLib
- PcdLib
- DdrLib
+[FixedPcd]
- gNxpQoriqLsTokenSpaceGuid.PcdOcramStackBase
- gNxpQoriqLsTokenSpaceGuid.PcdFdNorBaseAddress
- gNxpQoriqLsTokenSpaceGuid.PcdPiFdSize
- gArmTokenSpaceGuid.PcdFdBaseAddress
- gArmTokenSpaceGuid.PcdFdSize
- gArmTokenSpaceGuid.PcdSystemMemoryBase
- gArmTokenSpaceGuid.PcdSystemMemorySize
- gArmPlatformTokenSpaceGuid.PcdSystemMemoryUefiRegionSize
- gArmTokenSpaceGuid.PcdFvBaseAddress
-- 1.9.1
Hi Ard,
Thanks for the review comments. Please see my replies inline.
From: Ard Biesheuvel [mailto:ard.biesheuvel@linaro.org] Sent: Tuesday, October 18, 2016 3:12 PM
On 17 October 2016 at 21:04, Bhupesh Sharma bhupesh.sharma@freescale.com wrote:
From: Sakar Arora sakar.arora@nxp.com
This is the first UEFI module that executes after power on.
It runs from XIP NOR flash memory and uses on-chip OCRAM as stack.
It also iniitializes DDR controller, copies rest of UEFI firmware to DDR
typo ^^
Sorry, could not get your meaning here. Am I missing the typo (as I am not able to locate it :( )
memory and transfers control to it.
Signed-off-by: Sakar Arora sakar.arora@nxp.com Signed-off-by: Bhupesh Sharma bhupesh.sharma@nxp.com
.../Library/PrePiNor/AArch64/ModuleEntryPoint.S | 34
++++++++++++++
Chips/Nxp/QoriqLs/Library/PrePiNor/PrePiNor.c | 52
++++++++++++++++++++++
Chips/Nxp/QoriqLs/Library/PrePiNor/PrePiNor.inf | 48
++++++++++++++++++++
3 files changed, 134 insertions(+) create mode 100644 Chips/Nxp/QoriqLs/Library/PrePiNor/AArch64/ModuleEntryPoint.S create mode 100644 Chips/Nxp/QoriqLs/Library/PrePiNor/PrePiNor.c create mode 100644 Chips/Nxp/QoriqLs/Library/PrePiNor/PrePiNor.inf
diff --git a/Chips/Nxp/QoriqLs/Library/PrePiNor/AArch64/ModuleEntryPoint.S b/Chips/Nxp/QoriqLs/Library/PrePiNor/AArch64/ModuleEntryPoint.S new file mode 100644 index 0000000..6f3b373 --- /dev/null +++ b/Chips/Nxp/QoriqLs/Library/PrePiNor/AArch64/ModuleEntryPoint.S @@ -0,0 +1,34 @@ +// @ModuleEntryPoint.S +// +// Copyright (c) 2016, Freescale Semiconductor, Inc. All rights
reserved.
+// +// This program and the accompanying materials // are licensed and +made available under the terms and conditions of the BSD License // +which accompanies this distribution. The full text of the license +may be found at // http://opensource.org/licenses/bsd-license.php +// +// THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" +BASIS, // WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER
EXPRESS OR IMPLIED.
+//
+#include <AutoGen.h> +#include <AsmMacroIoLibV8.h> +#include <Library/PcdLib.h>
+.text +.align 3
+GCC_ASM_EXPORT(_ModuleEntryPoint)
+StartupAddr: .8byte ASM_PFX(CEntryPoint)
+ASM_PFX(_ModuleEntryPoint):
- LoadConstantToReg (FixedPcdGet32(PcdOcramStackBase), x0)
- mov sp, x0
- LoadConstantToReg (FixedPcdGet64(PcdFdBaseAddress), x0)
- LoadConstantToReg (FixedPcdGet32(PcdFdNorBaseAddress), x1)
- LoadConstantToReg (FixedPcdGet32(PcdPiFdSize), x5)
- add x1, x1, x5
- LoadConstantToReg (FixedPcdGet32(PcdFdSize), x2)
Please drop these LoadConstantToReg() invocations, and use MOV32/64 instead
Ok.
- ldr x4, StartupAddr
- blr x4
diff --git a/Chips/Nxp/QoriqLs/Library/PrePiNor/PrePiNor.c b/Chips/Nxp/QoriqLs/Library/PrePiNor/PrePiNor.c new file mode 100644 index 0000000..4c808db --- /dev/null +++ b/Chips/Nxp/QoriqLs/Library/PrePiNor/PrePiNor.c @@ -0,0 +1,52 @@ +/** @LS1043aPrePiNor.c +# +# Copyright (c) 2016, Freescale Semiconductor, Inc. All rights
reserved.
+# +# This program and the accompanying materials # are licensed and +made available under the terms and conditions of the BSD License # +which accompanies this distribution. The full text of the license +may be found at # http://opensource.org/licenses/bsd-license.php +# +# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" +BASIS, # WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER
EXPRESS OR IMPLIED.
+# +**/
+#include <Library/ArmLib.h> +#include <Library/PcdLib.h>
+extern VOID DramInit();
Please include the appropriate library header
Ok.
+UINTN mGlobalVariableBase = 0;
What is this?
Ok, will add appropriate comments.
+VOID CopyImage(UINT8* Dest, UINT8* Src, UINTN Size) {
- UINTN Count;
- for(Count = 0; Count < Size; Count++) {
- Dest[Count] = Src[Count];
- }
+}
Please use BaseMemoryLib in MdePkg. It works fine with the MMU and caches off
Hmmm. Ok, will try this.
+VOID CEntryPoint(
- UINTN UefiMemoryBase,
- UINTN UefiNorBase,
- UINTN UefiMemorySize
+) +{
- VOID (*PrePiStart)(VOID);
+// Data Cache enabled on Primary core when MMU is enabled.
- ArmDisableDataCache ();
- // Invalidate instruction cache
- ArmInvalidateInstructionCache ();
- // Enable Instruction Caches on all cores.
- ArmEnableInstructionCache ();
- DramInit();
- CopyImage((VOID*)UefiMemoryBase, (VOID*)UefiNorBase,
- UefiMemorySize);
Why is this necessary? The code is already executing, so why do we need to move it?
We are executing currently from NOR (XIP) which is usually slower.
In general, SEC and PEI can execute fine from NOR, and PEI_CORE will relocate itself to RAM as soon as it becomes available.
Right. But our idea is to start relocating to DDR from the PEI phase itself (BTW we don't use the SEC phase for the UEFI implementation on our SoCs), as DDR speeds are much faster than the code execution speed from the NOR flash.
We have tried setting the fastest NOR flash access timings but till these cannot be compared with the DDR execution speeds. With more and more customers demanding a very aggressive Linux boot time (from a cold reset), we put this hack in the PEI phase.
- PrePiStart = (VOID (*)())((UINT64)PcdGet64(PcdFvBaseAddress));
- PrePiStart();
+} diff --git a/Chips/Nxp/QoriqLs/Library/PrePiNor/PrePiNor.inf b/Chips/Nxp/QoriqLs/Library/PrePiNor/PrePiNor.inf new file mode 100644 index 0000000..1b78fa5 --- /dev/null +++ b/Chips/Nxp/QoriqLs/Library/PrePiNor/PrePiNor.inf @@ -0,0 +1,48 @@ +#/** @PrePiNor.inf +# +# Copyright (c) 2016, Freescale Semiconductor, Inc. All rights
reserved.
+# +# This program and the accompanying materials # are licensed and +made available under the terms and conditions of the BSD License # +which accompanies this distribution. The full text of the license +may be found at # http://opensource.org/licenses/bsd-license.php +# +# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" +BASIS, # WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER
EXPRESS OR IMPLIED.
+# +#**/
+[Defines]
- INF_VERSION = 0x00010005
- BASE_NAME = PrePiNor
- FILE_GUID = d959e387-7b91-452c-90e1-
a1dbac10ddb8
Fresh GUID
Ok.
- MODULE_TYPE = SEC
- VERSION_STRING = 1.0
+[Sources]
- PrePiNor.c
+[Sources.AArch64]
- AArch64/ModuleEntryPoint.S
+[Packages]
- MdePkg/MdePkg.dec
- ArmPkg/ArmPkg.dec
- ArmPlatformPkg/ArmPlatformPkg.dec
- OpenPlatformPkg/Chips/Nxp/QoriqLs/NxpQoriqLs.dec
+[LibraryClasses]
- ArmLib
- PcdLib
- DdrLib
+[FixedPcd]
- gNxpQoriqLsTokenSpaceGuid.PcdOcramStackBase
- gNxpQoriqLsTokenSpaceGuid.PcdFdNorBaseAddress
- gNxpQoriqLsTokenSpaceGuid.PcdPiFdSize
- gArmTokenSpaceGuid.PcdFdBaseAddress
- gArmTokenSpaceGuid.PcdFdSize
- gArmTokenSpaceGuid.PcdSystemMemoryBase
- gArmTokenSpaceGuid.PcdSystemMemorySize
- gArmPlatformTokenSpaceGuid.PcdSystemMemoryUefiRegionSize
- gArmTokenSpaceGuid.PcdFvBaseAddress
-- 1.9.1
Regards, Bhupesh
On 27 October 2016 at 08:04, Bhupesh Sharma bhupesh.sharma@nxp.com wrote:
Hi Ard,
Thanks for the review comments. Please see my replies inline.
From: Ard Biesheuvel [mailto:ard.biesheuvel@linaro.org] Sent: Tuesday, October 18, 2016 3:12 PM
On 17 October 2016 at 21:04, Bhupesh Sharma bhupesh.sharma@freescale.com wrote:
From: Sakar Arora sakar.arora@nxp.com
This is the first UEFI module that executes after power on.
It runs from XIP NOR flash memory and uses on-chip OCRAM as stack.
It also iniitializes DDR controller, copies rest of UEFI firmware to DDR
typo ^^
Sorry, could not get your meaning here. Am I missing the typo (as I am not able to locate it :( )
Please replace 'iniitializes' with 'initializes'
memory and transfers control to it.
Signed-off-by: Sakar Arora sakar.arora@nxp.com Signed-off-by: Bhupesh Sharma bhupesh.sharma@nxp.com
.../Library/PrePiNor/AArch64/ModuleEntryPoint.S | 34
++++++++++++++
Chips/Nxp/QoriqLs/Library/PrePiNor/PrePiNor.c | 52
++++++++++++++++++++++
Chips/Nxp/QoriqLs/Library/PrePiNor/PrePiNor.inf | 48
++++++++++++++++++++
3 files changed, 134 insertions(+) create mode 100644 Chips/Nxp/QoriqLs/Library/PrePiNor/AArch64/ModuleEntryPoint.S create mode 100644 Chips/Nxp/QoriqLs/Library/PrePiNor/PrePiNor.c create mode 100644 Chips/Nxp/QoriqLs/Library/PrePiNor/PrePiNor.inf
diff --git a/Chips/Nxp/QoriqLs/Library/PrePiNor/AArch64/ModuleEntryPoint.S b/Chips/Nxp/QoriqLs/Library/PrePiNor/AArch64/ModuleEntryPoint.S new file mode 100644 index 0000000..6f3b373 --- /dev/null +++ b/Chips/Nxp/QoriqLs/Library/PrePiNor/AArch64/ModuleEntryPoint.S @@ -0,0 +1,34 @@ +// @ModuleEntryPoint.S +// +// Copyright (c) 2016, Freescale Semiconductor, Inc. All rights
reserved.
+// +// This program and the accompanying materials // are licensed and +made available under the terms and conditions of the BSD License // +which accompanies this distribution. The full text of the license +may be found at // http://opensource.org/licenses/bsd-license.php +// +// THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" +BASIS, // WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER
EXPRESS OR IMPLIED.
+//
+#include <AutoGen.h> +#include <AsmMacroIoLibV8.h> +#include <Library/PcdLib.h>
+.text +.align 3
+GCC_ASM_EXPORT(_ModuleEntryPoint)
+StartupAddr: .8byte ASM_PFX(CEntryPoint)
+ASM_PFX(_ModuleEntryPoint):
- LoadConstantToReg (FixedPcdGet32(PcdOcramStackBase), x0)
- mov sp, x0
- LoadConstantToReg (FixedPcdGet64(PcdFdBaseAddress), x0)
- LoadConstantToReg (FixedPcdGet32(PcdFdNorBaseAddress), x1)
- LoadConstantToReg (FixedPcdGet32(PcdPiFdSize), x5)
- add x1, x1, x5
- LoadConstantToReg (FixedPcdGet32(PcdFdSize), x2)
Please drop these LoadConstantToReg() invocations, and use MOV32/64 instead
Ok.
- ldr x4, StartupAddr
- blr x4
diff --git a/Chips/Nxp/QoriqLs/Library/PrePiNor/PrePiNor.c b/Chips/Nxp/QoriqLs/Library/PrePiNor/PrePiNor.c new file mode 100644 index 0000000..4c808db --- /dev/null +++ b/Chips/Nxp/QoriqLs/Library/PrePiNor/PrePiNor.c @@ -0,0 +1,52 @@ +/** @LS1043aPrePiNor.c +# +# Copyright (c) 2016, Freescale Semiconductor, Inc. All rights
reserved.
+# +# This program and the accompanying materials # are licensed and +made available under the terms and conditions of the BSD License # +which accompanies this distribution. The full text of the license +may be found at # http://opensource.org/licenses/bsd-license.php +# +# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" +BASIS, # WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER
EXPRESS OR IMPLIED.
+# +**/
+#include <Library/ArmLib.h> +#include <Library/PcdLib.h>
+extern VOID DramInit();
Please include the appropriate library header
Ok.
+UINTN mGlobalVariableBase = 0;
What is this?
Ok, will add appropriate comments.
Is it actually used anywhere?
+VOID CopyImage(UINT8* Dest, UINT8* Src, UINTN Size) {
- UINTN Count;
- for(Count = 0; Count < Size; Count++) {
- Dest[Count] = Src[Count];
- }
+}
Please use BaseMemoryLib in MdePkg. It works fine with the MMU and caches off
Hmmm. Ok, will try this.
+VOID CEntryPoint(
- UINTN UefiMemoryBase,
- UINTN UefiNorBase,
- UINTN UefiMemorySize
+) +{
- VOID (*PrePiStart)(VOID);
+// Data Cache enabled on Primary core when MMU is enabled.
- ArmDisableDataCache ();
- // Invalidate instruction cache
- ArmInvalidateInstructionCache ();
- // Enable Instruction Caches on all cores.
- ArmEnableInstructionCache ();
- DramInit();
- CopyImage((VOID*)UefiMemoryBase, (VOID*)UefiNorBase,
- UefiMemorySize);
Why is this necessary? The code is already executing, so why do we need to move it?
We are executing currently from NOR (XIP) which is usually slower.
In general, SEC and PEI can execute fine from NOR, and PEI_CORE will relocate itself to RAM as soon as it becomes available.
Right. But our idea is to start relocating to DDR from the PEI phase itself (BTW we don't use the SEC phase for the UEFI implementation on our SoCs), as DDR speeds are much faster than the code execution speed from the NOR flash.
We have tried setting the fastest NOR flash access timings but till these cannot be compared with the DDR execution speeds. With more and more customers demanding a very aggressive Linux boot time (from a cold reset), we put this hack in the PEI phase.
OK. But how do you ensure that the SEC/PEI module(s) in question can execute correctly both at the NOR offset and the DDR offset? If you use the PEI facilities, the PE/COFF loader reapplies any relocation fixups that are required. If you simply copy code around like this, that is not guaranteed.
It seems to me that you are getting lucky here, simply because the AARCH64 tiny and small code models are mostly PC relative anyway, but this is really not something you can rely upon. (For instance, the GCC48 toolchain uses the large code model)
- PrePiStart = (VOID (*)())((UINT64)PcdGet64(PcdFvBaseAddress));
- PrePiStart();
+} diff --git a/Chips/Nxp/QoriqLs/Library/PrePiNor/PrePiNor.inf b/Chips/Nxp/QoriqLs/Library/PrePiNor/PrePiNor.inf new file mode 100644 index 0000000..1b78fa5 --- /dev/null +++ b/Chips/Nxp/QoriqLs/Library/PrePiNor/PrePiNor.inf @@ -0,0 +1,48 @@ +#/** @PrePiNor.inf +# +# Copyright (c) 2016, Freescale Semiconductor, Inc. All rights
reserved.
+# +# This program and the accompanying materials # are licensed and +made available under the terms and conditions of the BSD License # +which accompanies this distribution. The full text of the license +may be found at # http://opensource.org/licenses/bsd-license.php +# +# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" +BASIS, # WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER
EXPRESS OR IMPLIED.
+# +#**/
+[Defines]
- INF_VERSION = 0x00010005
- BASE_NAME = PrePiNor
- FILE_GUID = d959e387-7b91-452c-90e1-
a1dbac10ddb8
Fresh GUID
Ok.
- MODULE_TYPE = SEC
- VERSION_STRING = 1.0
+[Sources]
- PrePiNor.c
+[Sources.AArch64]
- AArch64/ModuleEntryPoint.S
+[Packages]
- MdePkg/MdePkg.dec
- ArmPkg/ArmPkg.dec
- ArmPlatformPkg/ArmPlatformPkg.dec
- OpenPlatformPkg/Chips/Nxp/QoriqLs/NxpQoriqLs.dec
+[LibraryClasses]
- ArmLib
- PcdLib
- DdrLib
+[FixedPcd]
- gNxpQoriqLsTokenSpaceGuid.PcdOcramStackBase
- gNxpQoriqLsTokenSpaceGuid.PcdFdNorBaseAddress
- gNxpQoriqLsTokenSpaceGuid.PcdPiFdSize
- gArmTokenSpaceGuid.PcdFdBaseAddress
- gArmTokenSpaceGuid.PcdFdSize
- gArmTokenSpaceGuid.PcdSystemMemoryBase
- gArmTokenSpaceGuid.PcdSystemMemorySize
- gArmPlatformTokenSpaceGuid.PcdSystemMemoryUefiRegionSize
- gArmTokenSpaceGuid.PcdFvBaseAddress
-- 1.9.1
Regards, Bhupesh
On Tue, Oct 18, 2016 at 01:34:07AM +0530, Bhupesh Sharma wrote:
From: Sakar Arora sakar.arora@nxp.com
This is the first UEFI module that executes after power on.
It runs from XIP NOR flash memory and uses on-chip OCRAM as stack.
It also iniitializes DDR controller, copies rest of UEFI firmware to DDR memory and transfers control to it.
Signed-off-by: Sakar Arora sakar.arora@nxp.com Signed-off-by: Bhupesh Sharma bhupesh.sharma@nxp.com
.../Library/PrePiNor/AArch64/ModuleEntryPoint.S | 34 ++++++++++++++ Chips/Nxp/QoriqLs/Library/PrePiNor/PrePiNor.c | 52 ++++++++++++++++++++++ Chips/Nxp/QoriqLs/Library/PrePiNor/PrePiNor.inf | 48 ++++++++++++++++++++ 3 files changed, 134 insertions(+) create mode 100644 Chips/Nxp/QoriqLs/Library/PrePiNor/AArch64/ModuleEntryPoint.S create mode 100644 Chips/Nxp/QoriqLs/Library/PrePiNor/PrePiNor.c create mode 100644 Chips/Nxp/QoriqLs/Library/PrePiNor/PrePiNor.inf
diff --git a/Chips/Nxp/QoriqLs/Library/PrePiNor/AArch64/ModuleEntryPoint.S b/Chips/Nxp/QoriqLs/Library/PrePiNor/AArch64/ModuleEntryPoint.S new file mode 100644 index 0000000..6f3b373 --- /dev/null +++ b/Chips/Nxp/QoriqLs/Library/PrePiNor/AArch64/ModuleEntryPoint.S @@ -0,0 +1,34 @@ +// @ModuleEntryPoint.S +// +// Copyright (c) 2016, Freescale Semiconductor, Inc. All rights reserved. +// +// This program and the accompanying materials +// are licensed and made available under the terms and conditions of the BSD License +// which accompanies this distribution. The full text of the license may be found at +// http://opensource.org/licenses/bsd-license.php +// +// THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, +// WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. +//
+#include <AutoGen.h> +#include <AsmMacroIoLibV8.h> +#include <Library/PcdLib.h>
+.text +.align 3
+GCC_ASM_EXPORT(_ModuleEntryPoint)
+StartupAddr: .8byte ASM_PFX(CEntryPoint)
+ASM_PFX(_ModuleEntryPoint):
- LoadConstantToReg (FixedPcdGet32(PcdOcramStackBase), x0)
- mov sp, x0
- LoadConstantToReg (FixedPcdGet64(PcdFdBaseAddress), x0)
- LoadConstantToReg (FixedPcdGet32(PcdFdNorBaseAddress), x1)
- LoadConstantToReg (FixedPcdGet32(PcdPiFdSize), x5)
- add x1, x1, x5
- LoadConstantToReg (FixedPcdGet32(PcdFdSize), x2)
- ldr x4, StartupAddr
- blr x4
diff --git a/Chips/Nxp/QoriqLs/Library/PrePiNor/PrePiNor.c b/Chips/Nxp/QoriqLs/Library/PrePiNor/PrePiNor.c new file mode 100644 index 0000000..4c808db --- /dev/null +++ b/Chips/Nxp/QoriqLs/Library/PrePiNor/PrePiNor.c @@ -0,0 +1,52 @@ +/** @LS1043aPrePiNor.c +# +# Copyright (c) 2016, Freescale Semiconductor, Inc. All rights reserved. +# +# This program and the accompanying materials +# are licensed and made available under the terms and conditions of the BSD License +# which accompanies this distribution. The full text of the license may be found at +# http://opensource.org/licenses/bsd-license.php +# +# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, +# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. +# +**/
+#include <Library/ArmLib.h> +#include <Library/PcdLib.h>
+extern VOID DramInit();
This should be defined in a header.
+UINTN mGlobalVariableBase = 0;
+VOID CopyImage(UINT8* Dest, UINT8* Src, UINTN Size)
Why this memcopy reimplementation?
+{
- UINTN Count;
- for(Count = 0; Count < Size; Count++) {
- Dest[Count] = Src[Count];
- }
+}
+VOID CEntryPoint(
- UINTN UefiMemoryBase,
- UINTN UefiNorBase,
- UINTN UefiMemorySize
+) +{
- VOID (*PrePiStart)(VOID);
+// Data Cache enabled on Primary core when MMU is enabled.
- ArmDisableDataCache ();
- // Invalidate instruction cache
- ArmInvalidateInstructionCache ();
- // Enable Instruction Caches on all cores.
- ArmEnableInstructionCache ();
- DramInit();
- CopyImage((VOID*)UefiMemoryBase, (VOID*)UefiNorBase, UefiMemorySize);
- PrePiStart = (VOID (*)())((UINT64)PcdGet64(PcdFvBaseAddress));
This code is missing barriers.
- PrePiStart();
+} diff --git a/Chips/Nxp/QoriqLs/Library/PrePiNor/PrePiNor.inf b/Chips/Nxp/QoriqLs/Library/PrePiNor/PrePiNor.inf new file mode 100644 index 0000000..1b78fa5 --- /dev/null +++ b/Chips/Nxp/QoriqLs/Library/PrePiNor/PrePiNor.inf @@ -0,0 +1,48 @@ +#/** @PrePiNor.inf +# +# Copyright (c) 2016, Freescale Semiconductor, Inc. All rights reserved. +# +# This program and the accompanying materials +# are licensed and made available under the terms and conditions of the BSD License +# which accompanies this distribution. The full text of the license may be found at +# http://opensource.org/licenses/bsd-license.php +# +# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, +# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. +# +#**/
+[Defines]
- INF_VERSION = 0x00010005
- BASE_NAME = PrePiNor
- FILE_GUID = d959e387-7b91-452c-90e1-a1dbac10ddb8
- MODULE_TYPE = SEC
- VERSION_STRING = 1.0
+[Sources]
- PrePiNor.c
+[Sources.AArch64]
- AArch64/ModuleEntryPoint.S
+[Packages]
- MdePkg/MdePkg.dec
- ArmPkg/ArmPkg.dec
- ArmPlatformPkg/ArmPlatformPkg.dec
- OpenPlatformPkg/Chips/Nxp/QoriqLs/NxpQoriqLs.dec
+[LibraryClasses]
- ArmLib
- PcdLib
- DdrLib
+[FixedPcd]
- gNxpQoriqLsTokenSpaceGuid.PcdOcramStackBase
- gNxpQoriqLsTokenSpaceGuid.PcdFdNorBaseAddress
- gNxpQoriqLsTokenSpaceGuid.PcdPiFdSize
- gArmTokenSpaceGuid.PcdFdBaseAddress
- gArmTokenSpaceGuid.PcdFdSize
- gArmTokenSpaceGuid.PcdSystemMemoryBase
- gArmTokenSpaceGuid.PcdSystemMemorySize
- gArmPlatformTokenSpaceGuid.PcdSystemMemoryUefiRegionSize
- gArmTokenSpaceGuid.PcdFvBaseAddress
Can we have some alphabetical sorting of this file please?
-- 1.9.1
Hi Leif,
From: Leif Lindholm [mailto:leif.lindholm@linaro.org] Sent: Saturday, November 05, 2016 3:38 AM
On Tue, Oct 18, 2016 at 01:34:07AM +0530, Bhupesh Sharma wrote:
From: Sakar Arora sakar.arora@nxp.com
This is the first UEFI module that executes after power on.
It runs from XIP NOR flash memory and uses on-chip OCRAM as stack.
It also iniitializes DDR controller, copies rest of UEFI firmware to DDR memory and transfers control to it.
Signed-off-by: Sakar Arora sakar.arora@nxp.com Signed-off-by: Bhupesh Sharma bhupesh.sharma@nxp.com
.../Library/PrePiNor/AArch64/ModuleEntryPoint.S | 34
++++++++++++++
Chips/Nxp/QoriqLs/Library/PrePiNor/PrePiNor.c | 52
++++++++++++++++++++++
Chips/Nxp/QoriqLs/Library/PrePiNor/PrePiNor.inf | 48
++++++++++++++++++++
3 files changed, 134 insertions(+) create mode 100644 Chips/Nxp/QoriqLs/Library/PrePiNor/AArch64/ModuleEntryPoint.S create mode 100644 Chips/Nxp/QoriqLs/Library/PrePiNor/PrePiNor.c create mode 100644 Chips/Nxp/QoriqLs/Library/PrePiNor/PrePiNor.inf
diff --git a/Chips/Nxp/QoriqLs/Library/PrePiNor/AArch64/ModuleEntryPoint.S b/Chips/Nxp/QoriqLs/Library/PrePiNor/AArch64/ModuleEntryPoint.S new file mode 100644 index 0000000..6f3b373 --- /dev/null +++ b/Chips/Nxp/QoriqLs/Library/PrePiNor/AArch64/ModuleEntryPoint.S @@ -0,0 +1,34 @@ +// @ModuleEntryPoint.S +// +// Copyright (c) 2016, Freescale Semiconductor, Inc. All rights
reserved.
+// +// This program and the accompanying materials // are licensed and +made available under the terms and conditions of the BSD License // +which accompanies this distribution. The full text of the license +may be found at // http://opensource.org/licenses/bsd-license.php +// +// THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" +BASIS, // WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER
EXPRESS OR IMPLIED.
+//
+#include <AutoGen.h> +#include <AsmMacroIoLibV8.h> +#include <Library/PcdLib.h>
+.text +.align 3
+GCC_ASM_EXPORT(_ModuleEntryPoint)
+StartupAddr: .8byte ASM_PFX(CEntryPoint)
+ASM_PFX(_ModuleEntryPoint):
- LoadConstantToReg (FixedPcdGet32(PcdOcramStackBase), x0)
- mov sp, x0
- LoadConstantToReg (FixedPcdGet64(PcdFdBaseAddress), x0)
- LoadConstantToReg (FixedPcdGet32(PcdFdNorBaseAddress), x1)
- LoadConstantToReg (FixedPcdGet32(PcdPiFdSize), x5)
- add x1, x1, x5
- LoadConstantToReg (FixedPcdGet32(PcdFdSize), x2)
- ldr x4, StartupAddr
- blr x4
diff --git a/Chips/Nxp/QoriqLs/Library/PrePiNor/PrePiNor.c b/Chips/Nxp/QoriqLs/Library/PrePiNor/PrePiNor.c new file mode 100644 index 0000000..4c808db --- /dev/null +++ b/Chips/Nxp/QoriqLs/Library/PrePiNor/PrePiNor.c @@ -0,0 +1,52 @@ +/** @LS1043aPrePiNor.c +# +# Copyright (c) 2016, Freescale Semiconductor, Inc. All rights
reserved.
+# +# This program and the accompanying materials # are licensed and +made available under the terms and conditions of the BSD License # +which accompanies this distribution. The full text of the license +may be found at # http://opensource.org/licenses/bsd-license.php +# +# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" +BASIS, # WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER
EXPRESS OR IMPLIED.
+# +**/
+#include <Library/ArmLib.h> +#include <Library/PcdLib.h>
+extern VOID DramInit();
This should be defined in a header.
Ok.
+UINTN mGlobalVariableBase = 0;
+VOID CopyImage(UINT8* Dest, UINT8* Src, UINTN Size)
Why this memcopy reimplementation?
We will try and use the standard CopyMem API before sending the V2.
+{
- UINTN Count;
- for(Count = 0; Count < Size; Count++) {
- Dest[Count] = Src[Count];
- }
+}
+VOID CEntryPoint(
- UINTN UefiMemoryBase,
- UINTN UefiNorBase,
- UINTN UefiMemorySize
+) +{
- VOID (*PrePiStart)(VOID);
+// Data Cache enabled on Primary core when MMU is enabled.
- ArmDisableDataCache ();
- // Invalidate instruction cache
- ArmInvalidateInstructionCache ();
- // Enable Instruction Caches on all cores.
- ArmEnableInstructionCache ();
- DramInit();
- CopyImage((VOID*)UefiMemoryBase, (VOID*)UefiNorBase,
- UefiMemorySize);
- PrePiStart = (VOID (*)())((UINT64)PcdGet64(PcdFvBaseAddress));
This code is missing barriers.
Ok will add them.
- PrePiStart();
+} diff --git a/Chips/Nxp/QoriqLs/Library/PrePiNor/PrePiNor.inf b/Chips/Nxp/QoriqLs/Library/PrePiNor/PrePiNor.inf new file mode 100644 index 0000000..1b78fa5 --- /dev/null +++ b/Chips/Nxp/QoriqLs/Library/PrePiNor/PrePiNor.inf @@ -0,0 +1,48 @@ +#/** @PrePiNor.inf +# +# Copyright (c) 2016, Freescale Semiconductor, Inc. All rights
reserved.
+# +# This program and the accompanying materials # are licensed and +made available under the terms and conditions of the BSD License # +which accompanies this distribution. The full text of the license +may be found at # http://opensource.org/licenses/bsd-license.php +# +# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" +BASIS, # WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER
EXPRESS OR IMPLIED.
+# +#**/
+[Defines]
- INF_VERSION = 0x00010005
- BASE_NAME = PrePiNor
- FILE_GUID = d959e387-7b91-452c-90e1-
a1dbac10ddb8
- MODULE_TYPE = SEC
- VERSION_STRING = 1.0
+[Sources]
- PrePiNor.c
+[Sources.AArch64]
- AArch64/ModuleEntryPoint.S
+[Packages]
- MdePkg/MdePkg.dec
- ArmPkg/ArmPkg.dec
- ArmPlatformPkg/ArmPlatformPkg.dec
- OpenPlatformPkg/Chips/Nxp/QoriqLs/NxpQoriqLs.dec
+[LibraryClasses]
- ArmLib
- PcdLib
- DdrLib
+[FixedPcd]
- gNxpQoriqLsTokenSpaceGuid.PcdOcramStackBase
- gNxpQoriqLsTokenSpaceGuid.PcdFdNorBaseAddress
- gNxpQoriqLsTokenSpaceGuid.PcdPiFdSize
- gArmTokenSpaceGuid.PcdFdBaseAddress
- gArmTokenSpaceGuid.PcdFdSize
- gArmTokenSpaceGuid.PcdSystemMemoryBase
- gArmTokenSpaceGuid.PcdSystemMemorySize
- gArmPlatformTokenSpaceGuid.PcdSystemMemoryUefiRegionSize
- gArmTokenSpaceGuid.PcdFvBaseAddress
Can we have some alphabetical sorting of this file please?
Ok.
-- 1.9.1
From: Sakar Arora Sakar.Arora@nxp.com
This patch adds a library which performs I2C bus initialization and provides I2C read and write APIs for the I2C controller present on the LS1043A SOC.
Signed-off-by: Meenakshi Aggarwal meenakshi.aggarwal@nxp.com Signed-off-by: Bhupesh Sharma bhupesh.sharma@nxp.com --- Chips/Nxp/QoriqLs/Include/Library/I2c.h | 199 ++++++++ Chips/Nxp/QoriqLs/Library/I2cLib/I2cLib.c | 513 +++++++++++++++++++++ Chips/Nxp/QoriqLs/Library/I2cLib/I2cLib.inf | 41 ++ .../Nxp/LS1043aRdb/Include/Library/PlatformLib.h | 1 + .../Library/LS1043aSocLib/LS1043aSocLib.c | 17 + 5 files changed, 771 insertions(+) create mode 100644 Chips/Nxp/QoriqLs/Include/Library/I2c.h create mode 100644 Chips/Nxp/QoriqLs/Library/I2cLib/I2cLib.c create mode 100644 Chips/Nxp/QoriqLs/Library/I2cLib/I2cLib.inf
diff --git a/Chips/Nxp/QoriqLs/Include/Library/I2c.h b/Chips/Nxp/QoriqLs/Include/Library/I2c.h new file mode 100644 index 0000000..e9d5d61 --- /dev/null +++ b/Chips/Nxp/QoriqLs/Include/Library/I2c.h @@ -0,0 +1,199 @@ +/** @I2c.h + Header defining the constant, base address amd function for I2C controller + + Copyright (c) 2016, Freescale Semiconductor, Inc. All rights reserved. + + This program and the accompanying materials + are licensed and made available under the terms and conditions of the BSD License + which accompanies this distribution. The full text of the license may be found at + http://opensource.org/licenses/bsd-license.php + + THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, + WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. + +**/ + +#ifndef __I2C_H___ +#define __I2C_H__ + +#include <Uefi.h> +#include <Library/TimerLib.h> + +#define I2C0 0 +#define I2C1 1 +#define I2C2 2 +#define I2C3 3 + +/// +/// Define the I2C flags +/// +/// I2C read operation when set +#define I2C_READ_FLAG 0x1 +#define I2C_WRITE_FLAG 0x2 + +#define I2C_CR_IIEN (1 << 6) +#define I2C_CR_MSTA (1 << 5) +#define I2C_CR_MTX (1 << 4) +#define I2C_CR_TX_NO_AK (1 << 3) +#define I2C_CR_RSTA (1 << 2) + +#define I2C_SR_ICF (1 << 7) +#define I2C_SR_IBB (1 << 5) +#define I2C_SR_IAL (1 << 4) +#define I2C_SR_IIF (1 << 1) +#define I2C_SR_RX_NO_AK (1 << 0) + +#define I2C_CR_IEN (0 << 7) +#define I2C_CR_IDIS (1 << 7) +#define I2C_SR_IIF_CLEAR (1 << 1) + +#define BUS_IDLE (0 | (I2C_SR_IBB << 8)) +#define BUS_BUSY (I2C_SR_IBB | (I2C_SR_IBB << 8)) +#define IIF (I2C_SR_IIF | (I2C_SR_IIF << 8)) + +#define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0])) + +/** + Record defining i2c registers +**/ + +struct I2cRegs { + UINT8 I2cAdr; + UINT8 I2cFdr; + UINT8 I2cCr; + UINT8 I2cSr; + UINT8 I2cDr; +}; + +/** + Function to initialize i2c bus + +**/ +VOID +I2cBusInit ( + VOID + ); + +/** + Function to read data usin i2c + + @param Base A pointer to the base address of I2c Controller + @param Chip Address of slave device from where data to be read + @param Offset Offset of slave memory + @param Alen Address length of slave + @param Buffer A pointer to the destination buffer for the data + @param Len Length of data to be read + + @retval EFI_NOT_READY Arbitration lost + @retval EFI_TIMEOUT Failed to initialize data transfer in predefined time + @retval EFI_NOT_FOUND ACK was not recieved + @retval EFI_SUCCESS Read was successful + +**/ +EFI_STATUS +I2cDataRead ( + IN UINT32 I2cBus, + IN UINT8 Chip, + IN UINT32 Offset, + IN UINT32 Alen, + OUT UINT8 *Buffer, + IN UINT32 Len + ); + +/** + Function to set I2c bus speed + + @param BaseAddress Base address of I2c controller + @param Speed value to be set + +**/ +EFI_STATUS +EFIAPI +I2cSetBusSpeed ( + IN UINT32 I2cBus, + IN UINT32 Speed + ); + +/** + Function to stop transaction on i2c bus + + @param I2cRegs Pointer to i2c registers + + @retval EFI_NOT_READY Arbitration was lost + @retval EFI_TIMEOUT Timeout occured + @retval EFI_SUCCESS Stop operation was successful + +**/ +EFI_STATUS +I2cStop ( + IN struct I2cRegs *I2cRegs + ); + +/** + Function to initiate data transfer on i2c bus + + @param I2cRegs Pointer to i2c base registers + @param Chip Chip Address + @param Offset Slave memory's offset + @param Alen length of chip address + + @retval EFI_NOT_READY Arbitration lost + @retval EFI_TIMEOUT Failed to initialize data transfer in predefined time + @retval EFI_NOT_FOUND ACK was not recieved + @retval EFI_SUCCESS Read was successful + +**/ +EFI_STATUS +I2cBusInitTransfer ( + IN struct I2cRegs *I2cRegs, + IN UINT8 Chip, + IN UINT32 Offset, + IN INT32 Alen + ); + + +/** + Function to write data using i2c bus + + @param Base Pointer to the base address of I2c Controller + @param Chip Address of slave device where data to be written + @param Offset Offset of slave memory + @param Alen Address length of slave + @param Buffer A pointer to the source buffer for the data + @param Len Length of data to be write + + @retval EFI_NOT_READY Arbitration lost + @retval EFI_TIMEOUT Failed to initialize data transfer in predefined time + @retval EFI_NOT_FOUND ACK was not recieved + @retval EFI_SUCCESS Read was successful + +**/ +EFI_STATUS +I2cDataWrite ( + IN UINT32 I2cBus, + IN UINT8 Chip, + IN UINT32 Offset, + IN INT32 Alen, + OUT UINT8 *Buffer, + IN INT32 Len + ); + + +/** + Function to reset I2c + +**/ + +VOID +I2cReset ( + UINT32 I2cBus + ); + +EFI_STATUS +EFIAPI +I2cProbeDevices ( + IN INT16 I2c, + IN UINT8 Chip + ); + +#endif diff --git a/Chips/Nxp/QoriqLs/Library/I2cLib/I2cLib.c b/Chips/Nxp/QoriqLs/Library/I2cLib/I2cLib.c new file mode 100644 index 0000000..0050783 --- /dev/null +++ b/Chips/Nxp/QoriqLs/Library/I2cLib/I2cLib.c @@ -0,0 +1,513 @@ +/** I2cLib.c + I2c Library containing functions for read, write, initialize, set speed etc + + Copyright (c) 2016, Freescale Semiconductor, Inc. All rights reserved. + + This program and the accompanying materials + are licensed and made available under the terms and conditions of the BSD License + which accompanies this distribution. The full text of the license may be found at + http://opensource.org/licenses/bsd-license.php + + THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, + WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. + +**/ + +#include <Base.h> +#include <Library/DebugLib.h> +#include <Library/IoLib.h> +#include <Library/BaseMemoryLib.h> +#include <Library/BaseMemoryLib/MemLibInternals.h> +#include <Library/BaseLib.h> +#include <Library/I2c.h> + +extern UINT32 I2cBusAddrArr(EFI_PHYSICAL_ADDRESS **I2cAddrArr); +extern UINT32 CalculateI2cClockRate(VOID); + +EFI_PHYSICAL_ADDRESS *I2cAddrArr; +UINT32 I2cAddrArrSize; + + +UINT16 ClkDiv[60][2] = { + { 20, 0x00 }, { 22, 0x01 }, { 24, 0x02 }, { 26, 0x03 }, + { 28, 0x04 }, { 30, 0x05 }, { 32, 0x09 }, { 34, 0x06 }, + { 36, 0x0A }, { 40, 0x07 }, { 44, 0x0C }, { 48, 0x0D }, + { 52, 0x43 }, { 56, 0x0E }, { 60, 0x45 }, { 64, 0x12 }, + { 68, 0x0F }, { 72, 0x13 }, { 80, 0x14 }, { 88, 0x15 }, + { 96, 0x19 }, { 104, 0x16 }, { 112, 0x1A }, { 128, 0x17 }, + { 136, 0x4F }, { 144, 0x1C }, { 160, 0x1D }, { 176, 0x55 }, + { 192, 0x1E }, { 208, 0x56 }, { 224, 0x22 }, { 228, 0x24 }, + { 240, 0x1F }, { 256, 0x23 }, { 288, 0x5C }, { 320, 0x25 }, + { 384, 0x26 }, { 448, 0x2A }, { 480, 0x27 }, { 512, 0x2B }, + { 576, 0x2C }, { 640, 0x2D }, { 768, 0x31 }, { 896, 0x32 }, + { 960, 0x2F }, { 1024, 0x33 }, { 1152, 0x34 },{ 1280, 0x35 }, + { 1536, 0x36 }, { 1792, 0x3A }, { 1920, 0x37 }, { 2048, 0x3B }, + { 2304, 0x3C }, { 2560, 0x3D }, { 3072, 0x3E }, { 3584, 0x7A }, + { 3840, 0x3F }, { 4096, 0x7B }, { 5120, 0x7D }, { 6144, 0x7E }, +}; + + +/** + Calculate and set proper clock divider + + @param Rate clock rate + + @retval ClkDiv Value used to get frequency divider value + +**/ +UINT8 +GetClk( + IN UINT32 Rate + ) +{ + UINTN ClkRate; + UINT32 Div; + UINT8 ClkDivx; + + ClkRate = CalculateI2cClockRate(); + + Div = (ClkRate + Rate - 1) / Rate; + if (Div < ClkDiv[0][0]) + ClkDivx = 0; + else if (Div > ClkDiv[ARRAY_SIZE(ClkDiv) - 1][0]) + ClkDivx = ARRAY_SIZE(ClkDiv) - 1; + else + for (ClkDivx = 0; ClkDiv[ClkDivx][0] < Div; ClkDivx++); + + return ClkDivx; +} + + +/** + Function to reset I2C module +**/ + +VOID +I2cReset ( + UINT32 I2cBus + ) +{ + struct I2cRegs *I2cRegs = (struct I2cRegs *)I2cAddrArr[I2cBus]; + + /** Reset module */ + MmioWrite8((UINTN)&I2cRegs->I2cCr, I2C_CR_IDIS); + MmioWrite8((UINTN)&I2cRegs->I2cSr, 0); +} + +/** + Function to set I2c bus speed + + @param BaseAddress Base address of I2c controller + @param Speed value to be set + +**/ +EFI_STATUS +EFIAPI +I2cSetBusSpeed ( + IN UINT32 I2cBus, + IN UINT32 Speed + ) +{ + struct I2cRegs *I2cRegs = (struct I2cRegs *)I2cAddrArr[I2cBus]; + ASSERT(I2cRegs); + UINT8 ClkId = GetClk(Speed); + UINT8 SpeedId = ClkDiv[ClkId][1]; + + /** Store divider value */ + MmioWrite8((UINTN)&I2cRegs->I2cFdr, SpeedId); + I2cReset(I2cBus); + + return EFI_SUCCESS; +} + + +/** + Function used to check if i2c is in mentioned state or not + + @param I2cRegs Pointer to I2C registers + @param State i2c state need to be checked + + @retval EFI_NOT_READY Arbitration was lost + @retval EFI_TIMEOUT Timeout occured + @retval CurrState Value of state register + +**/ +EFI_STATUS +WaitForI2cState ( + IN struct I2cRegs *I2cRegs, + IN UINT32 State + ) +{ + UINT8 CurrState; + UINT64 Cnt = 0; + + for (Cnt = 0; Cnt < 50; Cnt++) { + CurrState = MmioRead8((UINTN)&I2cRegs->I2cSr); + if (CurrState & I2C_SR_IAL) { + MmioWrite8((UINTN)&I2cRegs->I2cSr, CurrState | I2C_SR_IAL); + return EFI_NOT_READY; + } + if ((CurrState & (State >> 8)) == (UINT8)State) + return CurrState; + + MicroSecondDelay(300); + } + return EFI_TIMEOUT; +} + + +/** + Function to transfer byte on i2c + + @param I2cRegs Pointer to i2c registers + @param Byte Byte to be transferred on i2c bus + + @retval EFI_NOT_READY Arbitration was lost + @retval EFI_TIMEOUT Timeout occured + @retval EFI_NOT_FOUND ACK was not recieved + @retval EFI_SUCCESS Data transfer was succesful + +**/ +EFI_STATUS +TransferByte ( + IN struct I2cRegs *I2cRegs, + IN UINT8 Byte + ) +{ + EFI_STATUS Ret; + + MmioWrite8((UINTN)&I2cRegs->I2cSr, I2C_SR_IIF_CLEAR); + MmioWrite8((UINTN)&I2cRegs->I2cDr, Byte); + + Ret = WaitForI2cState(I2cRegs, IIF); + if ((Ret == EFI_TIMEOUT) || (Ret == EFI_NOT_READY)) + return Ret; + + if (Ret & I2C_SR_RX_NO_AK) { + return EFI_NOT_FOUND; + } + + return EFI_SUCCESS; +} + + +/** + Function to stop transaction on i2c bus + + @param I2cRegs Pointer to i2c registers + + @retval EFI_NOT_READY Arbitration was lost + @retval EFI_TIMEOUT Timeout occured + @retval EFI_SUCCESS Stop operation was successful + +**/ +EFI_STATUS +I2cStop ( + IN struct I2cRegs *I2cRegs + ) +{ + INT32 Ret; + UINT32 Temp = MmioRead8((UINTN)&I2cRegs->I2cCr); + + Temp &= ~(I2C_CR_MSTA | I2C_CR_MTX); + MmioWrite8((UINTN)&I2cRegs->I2cCr, Temp); + Ret = WaitForI2cState(I2cRegs, BUS_IDLE); + if (Ret < 0) + return Ret; + else + return EFI_SUCCESS; +} + + +/** + Function to send start signal, Chip Address and + memory offset + + @param I2cRegs Pointer to i2c base registers + @param Chip Chip Address + @param Offset Slave memory's offset + @param Alen length of chip address + + @retval EFI_NOT_READY Arbitration lost + @retval EFI_TIMEOUT Failed to initialize data transfer in predefined time + @retval EFI_NOT_FOUND ACK was not recieved + @retval EFI_SUCCESS Read was successful + +**/ +EFI_STATUS +InitTransfer ( + IN struct I2cRegs *I2cRegs, + IN UINT8 Chip, + IN UINT32 Offset, + IN INT32 Alen + ) +{ + UINT32 Temp; + EFI_STATUS Ret; + + /** Enable I2C controller */ + if (MmioRead8((UINTN)&I2cRegs->I2cCr) & I2C_CR_IDIS) + MmioWrite8((UINTN)&I2cRegs->I2cCr, I2C_CR_IEN); + + if (MmioRead8((UINTN)&I2cRegs->I2cAdr) == (Chip << 1)) + MmioWrite8((UINTN)&I2cRegs->I2cAdr, (Chip << 1) ^ 2); + + MmioWrite8((UINTN)&I2cRegs->I2cSr, I2C_SR_IIF_CLEAR); + Ret = WaitForI2cState(I2cRegs, BUS_IDLE); + if ((Ret == EFI_TIMEOUT) || (Ret == EFI_NOT_READY)) + return Ret; + + /** Start I2C transaction */ + Temp = MmioRead8((UINTN)&I2cRegs->I2cCr); + /** set to master mode */ + Temp |= I2C_CR_MSTA; + MmioWrite8((UINTN)&I2cRegs->I2cCr, Temp); + + Ret = WaitForI2cState(I2cRegs, BUS_BUSY); + if ((Ret == EFI_TIMEOUT) || (Ret == EFI_NOT_READY)) + return Ret; + + Temp |= I2C_CR_MTX | I2C_CR_TX_NO_AK; + MmioWrite8((UINTN)&I2cRegs->I2cCr, Temp); + + /** write slave Address */ + Ret = TransferByte(I2cRegs, Chip << 1); + if (Ret != EFI_SUCCESS) + return Ret; + + if (Alen >= 0) { + while (Alen--) { + Ret = TransferByte(I2cRegs, (Offset >> (Alen * 8)) & 0xff); + if (Ret != EFI_SUCCESS) + return Ret; + } + } + return EFI_SUCCESS; +} + + +/** + Function to check if i2c bud is idle + + @param Base Pointer to base address of I2c controller + + @retval EFI_SUCCESS + +**/ +INT32 +I2cBusIdle ( + IN VOID *Base + ) +{ + return EFI_SUCCESS; +} + + +/** + Function to initiate data transfer on i2c bus + + @param I2cRegs Pointer to i2c base registers + @param Chip Chip Address + @param Offset Slave memory's offset + @param Alen length of chip address + + @retval EFI_NOT_READY Arbitration lost + @retval EFI_TIMEOUT Failed to initialize data transfer in predefined time + @retval EFI_NOT_FOUND ACK was not recieved + @retval EFI_SUCCESS Read was successful + +**/ +EFI_STATUS +InitDataTransfer ( + IN struct I2cRegs *I2cRegs, + IN UINT8 Chip, + IN UINT32 Offset, + IN INT32 Alen + ) +{ + INT32 Retry; + EFI_STATUS Ret; + + for (Retry = 0; Retry < 3; Retry++) { + Ret = InitTransfer(I2cRegs, Chip, Offset, Alen); + if (Ret == EFI_SUCCESS) + return EFI_SUCCESS; + + I2cStop(I2cRegs); + + if (EFI_NOT_FOUND == Ret) { + return Ret; + } + + /** Disable controller */ + if (Ret != EFI_NOT_READY) + MmioWrite8((UINTN)&I2cRegs->I2cCr, I2C_CR_IDIS); + + if (I2cBusIdle(I2cRegs) < 0) + break; + } + return Ret; +} + + +/** + Function to read data using i2c bus + + @param Base A pointer to the base address of I2c Controller + @param Chip Address of slave device from where data to be read + @param Offset Offset of slave memory + @param Alen Address length of slave + @param Buffer A pointer to the destination buffer for the data + @param Len Length of data to be read + + @retval EFI_NOT_READY Arbitration lost + @retval EFI_TIMEOUT Failed to initialize data transfer in predefined time + @retval EFI_NOT_FOUND ACK was not recieved + @retval EFI_SUCCESS Read was successful + +**/ +EFI_STATUS +I2cDataRead ( + IN UINT32 I2cBus, + IN UINT8 Chip, + IN UINT32 Offset, + IN UINT32 Alen, + IN UINT8 *Buffer, + IN UINT32 Len + ) +{ + EFI_STATUS Ret; + UINT32 Temp; + INT32 i; + struct I2cRegs *I2cRegs = (struct I2cRegs *)I2cAddrArr[I2cBus]; + ASSERT(I2cRegs); + Ret = InitDataTransfer(I2cRegs, Chip, Offset, Alen); + if (Ret != EFI_SUCCESS) + return Ret; + + Temp = MmioRead8((UINTN)&I2cRegs->I2cCr); + Temp |= I2C_CR_RSTA; + MmioWrite8((UINTN)&I2cRegs->I2cCr, Temp); + + Ret = TransferByte(I2cRegs, (Chip << 1) | 1); + if (Ret != EFI_SUCCESS) { + I2cStop(I2cRegs); + return Ret; + } + /** setup bus to read data */ + Temp = MmioRead8((UINTN)&I2cRegs->I2cCr); + Temp &= ~(I2C_CR_MTX | I2C_CR_TX_NO_AK); + if (Len == 1) + Temp |= I2C_CR_TX_NO_AK; + + MmioWrite8((UINTN)&I2cRegs->I2cCr, Temp); + MmioWrite8((UINTN)&I2cRegs->I2cSr, I2C_SR_IIF_CLEAR); + + /** read data */ + /** Dummy Read to initiate recieve operation */ + MmioRead8((UINTN)&I2cRegs->I2cDr); + + for (i = 0; i < Len; i++) { + Ret = WaitForI2cState(I2cRegs, IIF); + if ((Ret == EFI_TIMEOUT) || (Ret == EFI_NOT_READY)) { + I2cStop(I2cRegs); + return Ret; + } + /** + It must generate STOP before read I2DR to prevent + controller from generating another clock cycle + **/ + if (i == (Len - 1)) { + I2cStop(I2cRegs); + } else if (i == (Len - 2)) { + Temp = MmioRead8((UINTN)&I2cRegs->I2cCr); + Temp |= I2C_CR_TX_NO_AK; + MmioWrite8((UINTN)&I2cRegs->I2cCr, Temp); + } + MmioWrite8((UINTN)&I2cRegs->I2cSr, I2C_SR_IIF_CLEAR); + Buffer[i] = MmioRead8((UINTN)&I2cRegs->I2cDr); + } + + I2cStop(I2cRegs); + return EFI_SUCCESS; +} + + +/** + Function to write data using i2c bus + + @param Base Pointer to the base address of I2c Controller + @param Chip Address of slave device where data to be written + @param Offset Offset of slave memory + @param Alen Address length of slave + @param Buffer A pointer to the source buffer for the data + @param Len Length of data to be write + + @retval EFI_NOT_READY Arbitration lost + @retval EFI_TIMEOUT Failed to initialize data transfer in predefined time + @retval EFI_NOT_FOUND ACK was not recieved + @retval EFI_SUCCESS Read was successful + +**/ +EFI_STATUS +I2cDataWrite ( + IN UINT32 I2cBus, + IN UINT8 Chip, + IN UINT32 Offset, + IN INT32 Alen, + OUT UINT8 *Buffer, + IN INT32 Len + ) +{ + EFI_STATUS Ret; + INT32 I; + struct I2cRegs *I2cRegs = (struct I2cRegs *)I2cAddrArr[I2cBus]; + ASSERT(I2cRegs); + + Ret = InitDataTransfer(I2cRegs, Chip, Offset, Alen); + if (Ret != EFI_SUCCESS) + return Ret; + + /** write data */ + /** Dummy write to initiate write operation */ + for (I = 0; I < Len; I++) { + Ret = TransferByte(I2cRegs, Buffer[I]); + if (Ret != EFI_SUCCESS) + break; + } + I2cStop(I2cRegs); + return Ret; +} + +/** + Function to Probe i2c bus + + @param I2c parameter defining I2c controller no + + @retval EFI_INVALID_PARAMETER Input parametr I2c was invalid + @retval EFI_SUCCESS I2c was initialized successfully + +**/ +EFI_STATUS +EFIAPI +I2cProbeDevices ( + IN INT16 I2c, + IN UINT8 ChipAdd + ) +{ + ASSERT(I2cAddrArr); + if(I2c >= I2cAddrArrSize || I2cAddrArr[I2c] == 0x0) + return EFI_INVALID_PARAMETER; + return I2cDataWrite(I2c, ChipAdd, 0, 0, NULL, 0); +} + +/** + Function to initialize i2c bus +**/ +VOID +I2cBusInit ( + VOID + ) +{ + I2cAddrArrSize = I2cBusAddrArr(&I2cAddrArr); +} diff --git a/Chips/Nxp/QoriqLs/Library/I2cLib/I2cLib.inf b/Chips/Nxp/QoriqLs/Library/I2cLib/I2cLib.inf new file mode 100644 index 0000000..f148c36 --- /dev/null +++ b/Chips/Nxp/QoriqLs/Library/I2cLib/I2cLib.inf @@ -0,0 +1,41 @@ +#/** I2cLib.inf +# +# Component description file for I2cLib module +# +# Copyright (c) 2016, Freescale Semiconductor, Inc. All rights reserved. +# +# This program and the accompanying materials +# are licensed and made available under the terms and conditions of the BSD License +# which accompanies this distribution. The full text of the license may be found at +# http://opensource.org/licenses/bsd-license.php +# +# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, +# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. +# +#**/ + +[Defines] + INF_VERSION = 0x00010005 + BASE_NAME = I2cLib + FILE_GUID = 8ecefc8f-a2c4-4091-b81f-20f7aeb0567f + MODULE_TYPE = BASE + VERSION_STRING = 1.0 + LIBRARY_CLASS = I2cLib + +[Sources.common] + I2cLib.c + +[LibraryClasses] + ArmLib + IoLib + BaseMemoryLib + BaseLib + SocLib + TimerLib + +[Packages] + EmbeddedPkg/EmbeddedPkg.dec + MdePkg/MdePkg.dec + MdeModulePkg/MdeModulePkg.dec + ArmPlatformPkg/ArmPlatformPkg.dec + OpenPlatformPkg/Chips/Nxp/QoriqLs/NxpQoriqLs.dec diff --git a/Platforms/Nxp/LS1043aRdb/Include/Library/PlatformLib.h b/Platforms/Nxp/LS1043aRdb/Include/Library/PlatformLib.h index 39247e8..a4d26e8 100644 --- a/Platforms/Nxp/LS1043aRdb/Include/Library/PlatformLib.h +++ b/Platforms/Nxp/LS1043aRdb/Include/Library/PlatformLib.h @@ -73,6 +73,7 @@ #define I2C2_BASE_ADDRESS 0x021A0000 #define I2C3_BASE_ADDRESS 0x02183000 #define I2C_SIZE 0x10000 + #define I2C_BUS_MAX 4 #define DSPI_MEMORY_SIZE 0x10000 #define DDRC_MEMORY_SIZE 0x10000 #define SDXC_MEMORY_SIZE 0x10000 diff --git a/Platforms/Nxp/LS1043aRdb/Library/LS1043aSocLib/LS1043aSocLib.c b/Platforms/Nxp/LS1043aRdb/Library/LS1043aSocLib/LS1043aSocLib.c index 2a7cb38..8a2a0e0 100644 --- a/Platforms/Nxp/LS1043aRdb/Library/LS1043aSocLib/LS1043aSocLib.c +++ b/Platforms/Nxp/LS1043aRdb/Library/LS1043aSocLib/LS1043aSocLib.c @@ -115,6 +115,13 @@ static struct CsuNsDev NonSecureDevices[] = {SEC_UNIT_CSLX_DSCR, SEC_UNIT_ALL_RW}, };
+EFI_PHYSICAL_ADDRESS I2cAddress[] = { + (EFI_PHYSICAL_ADDRESS)I2C0_BASE_ADDRESS, + (EFI_PHYSICAL_ADDRESS)I2C1_BASE_ADDRESS, + (EFI_PHYSICAL_ADDRESS)I2C2_BASE_ADDRESS, + (EFI_PHYSICAL_ADDRESS)I2C3_BASE_ADDRESS +}; + char *StringToMHz ( char *Buf, unsigned long Hz @@ -800,3 +807,13 @@ CalculateI2cClockRate(
return SocSysInfo.FreqSystemBus; } + + +UINT32 +I2cBusAddrArr( + EFI_PHYSICAL_ADDRESS **Arr + ) +{ + *Arr = (EFI_PHYSICAL_ADDRESS*)I2cAddress; + return I2C_BUS_MAX; +}
On Tue, Oct 18, 2016 at 01:34:08AM +0530, Bhupesh Sharma wrote:
From: Sakar Arora Sakar.Arora@nxp.com
This patch adds a library which performs I2C bus initialization and provides I2C read and write APIs for the I2C controller present on the LS1043A SOC.
Signed-off-by: Meenakshi Aggarwal meenakshi.aggarwal@nxp.com Signed-off-by: Bhupesh Sharma bhupesh.sharma@nxp.com
Chips/Nxp/QoriqLs/Include/Library/I2c.h | 199 ++++++++ Chips/Nxp/QoriqLs/Library/I2cLib/I2cLib.c | 513 +++++++++++++++++++++ Chips/Nxp/QoriqLs/Library/I2cLib/I2cLib.inf | 41 ++ .../Nxp/LS1043aRdb/Include/Library/PlatformLib.h | 1 + .../Library/LS1043aSocLib/LS1043aSocLib.c | 17 + 5 files changed, 771 insertions(+) create mode 100644 Chips/Nxp/QoriqLs/Include/Library/I2c.h create mode 100644 Chips/Nxp/QoriqLs/Library/I2cLib/I2cLib.c create mode 100644 Chips/Nxp/QoriqLs/Library/I2cLib/I2cLib.inf
diff --git a/Chips/Nxp/QoriqLs/Include/Library/I2c.h b/Chips/Nxp/QoriqLs/Include/Library/I2c.h new file mode 100644 index 0000000..e9d5d61 --- /dev/null +++ b/Chips/Nxp/QoriqLs/Include/Library/I2c.h @@ -0,0 +1,199 @@ +/** @I2c.h
- Header defining the constant, base address amd function for I2C controller
- Copyright (c) 2016, Freescale Semiconductor, Inc. All rights reserved.
- This program and the accompanying materials
- are licensed and made available under the terms and conditions of the BSD License
- which accompanies this distribution. The full text of the license may be found at
- http://opensource.org/licenses/bsd-license.php
- THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
- WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
+**/
+#ifndef __I2C_H___ +#define __I2C_H__
The two lines above don't match.
+#include <Uefi.h> +#include <Library/TimerLib.h>
+#define I2C0 0 +#define I2C1 1 +#define I2C2 2 +#define I2C3 3
+/// +/// Define the I2C flags +/// +/// I2C read operation when set +#define I2C_READ_FLAG 0x1 +#define I2C_WRITE_FLAG 0x2
+#define I2C_CR_IIEN (1 << 6) +#define I2C_CR_MSTA (1 << 5) +#define I2C_CR_MTX (1 << 4) +#define I2C_CR_TX_NO_AK (1 << 3) +#define I2C_CR_RSTA (1 << 2)
+#define I2C_SR_ICF (1 << 7) +#define I2C_SR_IBB (1 << 5) +#define I2C_SR_IAL (1 << 4) +#define I2C_SR_IIF (1 << 1) +#define I2C_SR_RX_NO_AK (1 << 0)
+#define I2C_CR_IEN (0 << 7) +#define I2C_CR_IDIS (1 << 7) +#define I2C_SR_IIF_CLEAR (1 << 1)
+#define BUS_IDLE (0 | (I2C_SR_IBB << 8)) +#define BUS_BUSY (I2C_SR_IBB | (I2C_SR_IBB << 8)) +#define IIF (I2C_SR_IIF | (I2C_SR_IIF << 8))
+#define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
Can be deleted when you update to a more recent edk2.
+/**
- Record defining i2c registers
+**/
+struct I2cRegs {
- UINT8 I2cAdr;
- UINT8 I2cFdr;
- UINT8 I2cCr;
- UINT8 I2cSr;
- UINT8 I2cDr;
+};
typedef?
+/**
- Function to initialize i2c bus
+**/ +VOID +I2cBusInit (
VOID
- );
+/**
- Function to read data usin i2c
- @param Base A pointer to the base address of I2c Controller
- @param Chip Address of slave device from where data to be read
- @param Offset Offset of slave memory
- @param Alen Address length of slave
- @param Buffer A pointer to the destination buffer for the data
- @param Len Length of data to be read
- @retval EFI_NOT_READY Arbitration lost
- @retval EFI_TIMEOUT Failed to initialize data transfer in predefined time
- @retval EFI_NOT_FOUND ACK was not recieved
- @retval EFI_SUCCESS Read was successful
+**/ +EFI_STATUS +I2cDataRead (
- IN UINT32 I2cBus,
- IN UINT8 Chip,
- IN UINT32 Offset,
- IN UINT32 Alen,
- OUT UINT8 *Buffer,
- IN UINT32 Len
- );
+/**
- Function to set I2c bus speed
- @param BaseAddress Base address of I2c controller
- @param Speed value to be set
+**/ +EFI_STATUS +EFIAPI +I2cSetBusSpeed (
- IN UINT32 I2cBus,
- IN UINT32 Speed
- );
+/**
- Function to stop transaction on i2c bus
- @param I2cRegs Pointer to i2c registers
- @retval EFI_NOT_READY Arbitration was lost
- @retval EFI_TIMEOUT Timeout occured
- @retval EFI_SUCCESS Stop operation was successful
+**/ +EFI_STATUS +I2cStop (
- IN struct I2cRegs *I2cRegs
- );
+/**
- Function to initiate data transfer on i2c bus
- @param I2cRegs Pointer to i2c base registers
- @param Chip Chip Address
- @param Offset Slave memory's offset
- @param Alen length of chip address
- @retval EFI_NOT_READY Arbitration lost
- @retval EFI_TIMEOUT Failed to initialize data transfer in predefined time
- @retval EFI_NOT_FOUND ACK was not recieved
- @retval EFI_SUCCESS Read was successful
+**/ +EFI_STATUS +I2cBusInitTransfer (
- IN struct I2cRegs *I2cRegs,
- IN UINT8 Chip,
- IN UINT32 Offset,
- IN INT32 Alen
- );
+/**
- Function to write data using i2c bus
- @param Base Pointer to the base address of I2c Controller
- @param Chip Address of slave device where data to be written
- @param Offset Offset of slave memory
- @param Alen Address length of slave
- @param Buffer A pointer to the source buffer for the data
- @param Len Length of data to be write
- @retval EFI_NOT_READY Arbitration lost
- @retval EFI_TIMEOUT Failed to initialize data transfer in predefined time
- @retval EFI_NOT_FOUND ACK was not recieved
- @retval EFI_SUCCESS Read was successful
+**/ +EFI_STATUS +I2cDataWrite (
- IN UINT32 I2cBus,
- IN UINT8 Chip,
- IN UINT32 Offset,
- IN INT32 Alen,
- OUT UINT8 *Buffer,
- IN INT32 Len
- );
+/**
- Function to reset I2c
+**/
+VOID +I2cReset (
- UINT32 I2cBus
- );
+EFI_STATUS +EFIAPI +I2cProbeDevices (
- IN INT16 I2c,
- IN UINT8 Chip
- );
+#endif diff --git a/Chips/Nxp/QoriqLs/Library/I2cLib/I2cLib.c b/Chips/Nxp/QoriqLs/Library/I2cLib/I2cLib.c new file mode 100644 index 0000000..0050783 --- /dev/null +++ b/Chips/Nxp/QoriqLs/Library/I2cLib/I2cLib.c @@ -0,0 +1,513 @@ +/** I2cLib.c
- I2c Library containing functions for read, write, initialize, set speed etc
- Copyright (c) 2016, Freescale Semiconductor, Inc. All rights reserved.
- This program and the accompanying materials
- are licensed and made available under the terms and conditions of the BSD License
- which accompanies this distribution. The full text of the license may be found at
- http://opensource.org/licenses/bsd-license.php
- THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
- WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
+**/
+#include <Base.h> +#include <Library/DebugLib.h> +#include <Library/IoLib.h> +#include <Library/BaseMemoryLib.h> +#include <Library/BaseMemoryLib/MemLibInternals.h> +#include <Library/BaseLib.h> +#include <Library/I2c.h>
Please sort the above alphabetically.
+extern UINT32 I2cBusAddrArr(EFI_PHYSICAL_ADDRESS **I2cAddrArr); +extern UINT32 CalculateI2cClockRate(VOID);
These should be pulled in from an include file.
+EFI_PHYSICAL_ADDRESS *I2cAddrArr; +UINT32 I2cAddrArrSize;
Global variables should have g or m prefix. If they're only used in this file, then m, and also make them STATIC.
+UINT16 ClkDiv[60][2] = {
- { 20, 0x00 }, { 22, 0x01 }, { 24, 0x02 }, { 26, 0x03 },
- { 28, 0x04 }, { 30, 0x05 }, { 32, 0x09 }, { 34, 0x06 },
- { 36, 0x0A }, { 40, 0x07 }, { 44, 0x0C }, { 48, 0x0D },
- { 52, 0x43 }, { 56, 0x0E }, { 60, 0x45 }, { 64, 0x12 },
- { 68, 0x0F }, { 72, 0x13 }, { 80, 0x14 }, { 88, 0x15 },
- { 96, 0x19 }, { 104, 0x16 }, { 112, 0x1A }, { 128, 0x17 },
- { 136, 0x4F }, { 144, 0x1C }, { 160, 0x1D }, { 176, 0x55 },
- { 192, 0x1E }, { 208, 0x56 }, { 224, 0x22 }, { 228, 0x24 },
- { 240, 0x1F }, { 256, 0x23 }, { 288, 0x5C }, { 320, 0x25 },
- { 384, 0x26 }, { 448, 0x2A }, { 480, 0x27 }, { 512, 0x2B },
- { 576, 0x2C }, { 640, 0x2D }, { 768, 0x31 }, { 896, 0x32 },
- { 960, 0x2F }, { 1024, 0x33 }, { 1152, 0x34 },{ 1280, 0x35 },
- { 1536, 0x36 }, { 1792, 0x3A }, { 1920, 0x37 }, { 2048, 0x3B },
- { 2304, 0x3C }, { 2560, 0x3D }, { 3072, 0x3E }, { 3584, 0x7A },
- { 3840, 0x3F }, { 4096, 0x7B }, { 5120, 0x7D }, { 6144, 0x7E },
+};
+/**
- Calculate and set proper clock divider
- @param Rate clock rate
- @retval ClkDiv Value used to get frequency divider value
+**/
STATIC?
+UINT8 +GetClk(
- IN UINT32 Rate
- )
+{
- UINTN ClkRate;
- UINT32 Div;
- UINT8 ClkDivx;
- ClkRate = CalculateI2cClockRate();
- Div = (ClkRate + Rate - 1) / Rate;
- if (Div < ClkDiv[0][0])
- ClkDivx = 0;
- else if (Div > ClkDiv[ARRAY_SIZE(ClkDiv) - 1][0])
- ClkDivx = ARRAY_SIZE(ClkDiv) - 1;
- else
- for (ClkDivx = 0; ClkDiv[ClkDivx][0] < Div; ClkDivx++);
- return ClkDivx;
+}
+/**
- Function to reset I2C module
+**/
+VOID +I2cReset (
- UINT32 I2cBus
- )
+{
- struct I2cRegs *I2cRegs = (struct I2cRegs *)I2cAddrArr[I2cBus];
- /** Reset module */
- MmioWrite8((UINTN)&I2cRegs->I2cCr, I2C_CR_IDIS);
- MmioWrite8((UINTN)&I2cRegs->I2cSr, 0);
+}
+/**
- Function to set I2c bus speed
- @param BaseAddress Base address of I2c controller
- @param Speed value to be set
+**/ +EFI_STATUS +EFIAPI +I2cSetBusSpeed (
- IN UINT32 I2cBus,
- IN UINT32 Speed
- )
+{
- struct I2cRegs *I2cRegs = (struct I2cRegs *)I2cAddrArr[I2cBus];
- ASSERT(I2cRegs);
- UINT8 ClkId = GetClk(Speed);
- UINT8 SpeedId = ClkDiv[ClkId][1];
- /** Store divider value */
- MmioWrite8((UINTN)&I2cRegs->I2cFdr, SpeedId);
- I2cReset(I2cBus);
- return EFI_SUCCESS;
+}
+/**
- Function used to check if i2c is in mentioned state or not
- @param I2cRegs Pointer to I2C registers
- @param State i2c state need to be checked
- @retval EFI_NOT_READY Arbitration was lost
- @retval EFI_TIMEOUT Timeout occured
- @retval CurrState Value of state register
+**/ +EFI_STATUS +WaitForI2cState (
- IN struct I2cRegs *I2cRegs,
- IN UINT32 State
- )
+{
- UINT8 CurrState;
- UINT64 Cnt = 0;
- for (Cnt = 0; Cnt < 50; Cnt++) {
- CurrState = MmioRead8((UINTN)&I2cRegs->I2cSr);
- if (CurrState & I2C_SR_IAL) {
MmioWrite8((UINTN)&I2cRegs->I2cSr, CurrState | I2C_SR_IAL);
return EFI_NOT_READY;
- }
- if ((CurrState & (State >> 8)) == (UINT8)State)
return CurrState;
- MicroSecondDelay(300);
Why 300?
- }
- return EFI_TIMEOUT;
+}
+/**
- Function to transfer byte on i2c
- @param I2cRegs Pointer to i2c registers
- @param Byte Byte to be transferred on i2c bus
- @retval EFI_NOT_READY Arbitration was lost
- @retval EFI_TIMEOUT Timeout occured
- @retval EFI_NOT_FOUND ACK was not recieved
- @retval EFI_SUCCESS Data transfer was succesful
+**/
STATIC?
+EFI_STATUS +TransferByte (
- IN struct I2cRegs *I2cRegs,
- IN UINT8 Byte
- )
+{
- EFI_STATUS Ret;
- MmioWrite8((UINTN)&I2cRegs->I2cSr, I2C_SR_IIF_CLEAR);
- MmioWrite8((UINTN)&I2cRegs->I2cDr, Byte);
- Ret = WaitForI2cState(I2cRegs, IIF);
- if ((Ret == EFI_TIMEOUT) || (Ret == EFI_NOT_READY))
- return Ret;
- if (Ret & I2C_SR_RX_NO_AK) {
- return EFI_NOT_FOUND;
- }
- return EFI_SUCCESS;
+}
+/**
- Function to stop transaction on i2c bus
- @param I2cRegs Pointer to i2c registers
- @retval EFI_NOT_READY Arbitration was lost
- @retval EFI_TIMEOUT Timeout occured
- @retval EFI_SUCCESS Stop operation was successful
+**/ +EFI_STATUS +I2cStop (
- IN struct I2cRegs *I2cRegs
- )
+{
- INT32 Ret;
- UINT32 Temp = MmioRead8((UINTN)&I2cRegs->I2cCr);
- Temp &= ~(I2C_CR_MSTA | I2C_CR_MTX);
- MmioWrite8((UINTN)&I2cRegs->I2cCr, Temp);
- Ret = WaitForI2cState(I2cRegs, BUS_IDLE);
- if (Ret < 0)
Always braces with if/else.
- return Ret;
- else
- return EFI_SUCCESS;
+}
+/**
- Function to send start signal, Chip Address and
- memory offset
- @param I2cRegs Pointer to i2c base registers
- @param Chip Chip Address
- @param Offset Slave memory's offset
- @param Alen length of chip address
- @retval EFI_NOT_READY Arbitration lost
- @retval EFI_TIMEOUT Failed to initialize data transfer in predefined time
- @retval EFI_NOT_FOUND ACK was not recieved
- @retval EFI_SUCCESS Read was successful
+**/ +EFI_STATUS +InitTransfer (
- IN struct I2cRegs *I2cRegs,
- IN UINT8 Chip,
- IN UINT32 Offset,
- IN INT32 Alen
- )
+{
- UINT32 Temp;
- EFI_STATUS Ret;
- /** Enable I2C controller */
- if (MmioRead8((UINTN)&I2cRegs->I2cCr) & I2C_CR_IDIS)
Always braces with if/else. (please address globally)
- MmioWrite8((UINTN)&I2cRegs->I2cCr, I2C_CR_IEN);
- if (MmioRead8((UINTN)&I2cRegs->I2cAdr) == (Chip << 1))
- MmioWrite8((UINTN)&I2cRegs->I2cAdr, (Chip << 1) ^ 2);
- MmioWrite8((UINTN)&I2cRegs->I2cSr, I2C_SR_IIF_CLEAR);
- Ret = WaitForI2cState(I2cRegs, BUS_IDLE);
- if ((Ret == EFI_TIMEOUT) || (Ret == EFI_NOT_READY))
- return Ret;
- /** Start I2C transaction */
- Temp = MmioRead8((UINTN)&I2cRegs->I2cCr);
- /** set to master mode */
- Temp |= I2C_CR_MSTA;
- MmioWrite8((UINTN)&I2cRegs->I2cCr, Temp);
- Ret = WaitForI2cState(I2cRegs, BUS_BUSY);
- if ((Ret == EFI_TIMEOUT) || (Ret == EFI_NOT_READY))
- return Ret;
- Temp |= I2C_CR_MTX | I2C_CR_TX_NO_AK;
- MmioWrite8((UINTN)&I2cRegs->I2cCr, Temp);
- /** write slave Address */
- Ret = TransferByte(I2cRegs, Chip << 1);
Can we have a macro instead of that inline <<?
- if (Ret != EFI_SUCCESS)
- return Ret;
- if (Alen >= 0) {
- while (Alen--) {
Ret = TransferByte(I2cRegs, (Offset >> (Alen * 8)) & 0xff);
Can we have a macro instead of that inline Offset/Alen manipulation?
if (Ret != EFI_SUCCESS)
return Ret;
- }
- }
- return EFI_SUCCESS;
+}
+/**
- Function to check if i2c bud is idle
- @param Base Pointer to base address of I2c controller
- @retval EFI_SUCCESS
+**/ +INT32 +I2cBusIdle (
- IN VOID *Base
- )
+{
- return EFI_SUCCESS;
+}
+/**
- Function to initiate data transfer on i2c bus
- @param I2cRegs Pointer to i2c base registers
- @param Chip Chip Address
- @param Offset Slave memory's offset
- @param Alen length of chip address
- @retval EFI_NOT_READY Arbitration lost
- @retval EFI_TIMEOUT Failed to initialize data transfer in predefined time
- @retval EFI_NOT_FOUND ACK was not recieved
- @retval EFI_SUCCESS Read was successful
+**/ +EFI_STATUS +InitDataTransfer (
- IN struct I2cRegs *I2cRegs,
- IN UINT8 Chip,
- IN UINT32 Offset,
- IN INT32 Alen
- )
+{
- INT32 Retry;
- EFI_STATUS Ret;
- for (Retry = 0; Retry < 3; Retry++) {
- Ret = InitTransfer(I2cRegs, Chip, Offset, Alen);
- if (Ret == EFI_SUCCESS)
return EFI_SUCCESS;
- I2cStop(I2cRegs);
- if (EFI_NOT_FOUND == Ret) {
return Ret;
- }
- /** Disable controller */
- if (Ret != EFI_NOT_READY)
MmioWrite8((UINTN)&I2cRegs->I2cCr, I2C_CR_IDIS);
- if (I2cBusIdle(I2cRegs) < 0)
break;
- }
- return Ret;
+}
+/**
- Function to read data using i2c bus
- @param Base A pointer to the base address of I2c Controller
- @param Chip Address of slave device from where data to be read
- @param Offset Offset of slave memory
- @param Alen Address length of slave
- @param Buffer A pointer to the destination buffer for the data
- @param Len Length of data to be read
- @retval EFI_NOT_READY Arbitration lost
- @retval EFI_TIMEOUT Failed to initialize data transfer in predefined time
- @retval EFI_NOT_FOUND ACK was not recieved
- @retval EFI_SUCCESS Read was successful
+**/ +EFI_STATUS +I2cDataRead (
- IN UINT32 I2cBus,
- IN UINT8 Chip,
- IN UINT32 Offset,
- IN UINT32 Alen,
- IN UINT8 *Buffer,
- IN UINT32 Len
- )
+{
- EFI_STATUS Ret;
- UINT32 Temp;
- INT32 i;
- struct I2cRegs *I2cRegs = (struct I2cRegs *)I2cAddrArr[I2cBus];
- ASSERT(I2cRegs);
- Ret = InitDataTransfer(I2cRegs, Chip, Offset, Alen);
- if (Ret != EFI_SUCCESS)
- return Ret;
- Temp = MmioRead8((UINTN)&I2cRegs->I2cCr);
- Temp |= I2C_CR_RSTA;
- MmioWrite8((UINTN)&I2cRegs->I2cCr, Temp);
- Ret = TransferByte(I2cRegs, (Chip << 1) | 1);
Can we have a macro instead of that inline manipulation of Chip? Or can the prototype of TransferByte be extended to make the code more obvious?
- if (Ret != EFI_SUCCESS) {
- I2cStop(I2cRegs);
- return Ret;
- }
- /** setup bus to read data */
- Temp = MmioRead8((UINTN)&I2cRegs->I2cCr);
- Temp &= ~(I2C_CR_MTX | I2C_CR_TX_NO_AK);
- if (Len == 1)
- Temp |= I2C_CR_TX_NO_AK;
- MmioWrite8((UINTN)&I2cRegs->I2cCr, Temp);
- MmioWrite8((UINTN)&I2cRegs->I2cSr, I2C_SR_IIF_CLEAR);
- /** read data */
- /** Dummy Read to initiate recieve operation */
- MmioRead8((UINTN)&I2cRegs->I2cDr);
- for (i = 0; i < Len; i++) {
- Ret = WaitForI2cState(I2cRegs, IIF);
- if ((Ret == EFI_TIMEOUT) || (Ret == EFI_NOT_READY)) {
I2cStop(I2cRegs);
return Ret;
- }
- /**
It must generate STOP before read I2DR to prevent
controller from generating another clock cycle
- **/
- if (i == (Len - 1)) {
I2cStop(I2cRegs);
- } else if (i == (Len - 2)) {
Temp = MmioRead8((UINTN)&I2cRegs->I2cCr);
Temp |= I2C_CR_TX_NO_AK;
MmioWrite8((UINTN)&I2cRegs->I2cCr, Temp);
- }
- MmioWrite8((UINTN)&I2cRegs->I2cSr, I2C_SR_IIF_CLEAR);
- Buffer[i] = MmioRead8((UINTN)&I2cRegs->I2cDr);
- }
- I2cStop(I2cRegs);
- return EFI_SUCCESS;
+}
+/**
- Function to write data using i2c bus
- @param Base Pointer to the base address of I2c Controller
- @param Chip Address of slave device where data to be written
- @param Offset Offset of slave memory
- @param Alen Address length of slave
- @param Buffer A pointer to the source buffer for the data
- @param Len Length of data to be write
- @retval EFI_NOT_READY Arbitration lost
- @retval EFI_TIMEOUT Failed to initialize data transfer in predefined time
- @retval EFI_NOT_FOUND ACK was not recieved
- @retval EFI_SUCCESS Read was successful
+**/ +EFI_STATUS +I2cDataWrite (
- IN UINT32 I2cBus,
- IN UINT8 Chip,
- IN UINT32 Offset,
- IN INT32 Alen,
- OUT UINT8 *Buffer,
- IN INT32 Len
- )
+{
- EFI_STATUS Ret;
- INT32 I;
- struct I2cRegs *I2cRegs = (struct I2cRegs *)I2cAddrArr[I2cBus];
- ASSERT(I2cRegs);
- Ret = InitDataTransfer(I2cRegs, Chip, Offset, Alen);
- if (Ret != EFI_SUCCESS)
- return Ret;
- /** write data */
- /** Dummy write to initiate write operation */
- for (I = 0; I < Len; I++) {
- Ret = TransferByte(I2cRegs, Buffer[I]);
- if (Ret != EFI_SUCCESS)
break;
- }
- I2cStop(I2cRegs);
- return Ret;
+}
+/**
- Function to Probe i2c bus
- @param I2c parameter defining I2c controller no
- @retval EFI_INVALID_PARAMETER Input parametr I2c was invalid
- @retval EFI_SUCCESS I2c was initialized successfully
+**/ +EFI_STATUS +EFIAPI +I2cProbeDevices (
- IN INT16 I2c,
- IN UINT8 ChipAdd
- )
+{
- ASSERT(I2cAddrArr);
- if(I2c >= I2cAddrArrSize || I2cAddrArr[I2c] == 0x0)
Parenthesis around each comparison statement, please.
- return EFI_INVALID_PARAMETER;
- return I2cDataWrite(I2c, ChipAdd, 0, 0, NULL, 0);
+}
+/**
- Function to initialize i2c bus
+**/ +VOID +I2cBusInit (
VOID
- )
+{
- I2cAddrArrSize = I2cBusAddrArr(&I2cAddrArr);
+} diff --git a/Chips/Nxp/QoriqLs/Library/I2cLib/I2cLib.inf b/Chips/Nxp/QoriqLs/Library/I2cLib/I2cLib.inf new file mode 100644 index 0000000..f148c36 --- /dev/null +++ b/Chips/Nxp/QoriqLs/Library/I2cLib/I2cLib.inf @@ -0,0 +1,41 @@ +#/** I2cLib.inf +# +# Component description file for I2cLib module +# +# Copyright (c) 2016, Freescale Semiconductor, Inc. All rights reserved. +# +# This program and the accompanying materials +# are licensed and made available under the terms and conditions of the BSD License +# which accompanies this distribution. The full text of the license may be found at +# http://opensource.org/licenses/bsd-license.php +# +# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, +# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. +# +#**/
+[Defines]
- INF_VERSION = 0x00010005
- BASE_NAME = I2cLib
- FILE_GUID = 8ecefc8f-a2c4-4091-b81f-20f7aeb0567f
- MODULE_TYPE = BASE
- VERSION_STRING = 1.0
- LIBRARY_CLASS = I2cLib
+[Sources.common]
- I2cLib.c
+[LibraryClasses]
- ArmLib
- IoLib
- BaseMemoryLib
- BaseLib
- SocLib
- TimerLib
+[Packages]
- EmbeddedPkg/EmbeddedPkg.dec
- MdePkg/MdePkg.dec
- MdeModulePkg/MdeModulePkg.dec
- ArmPlatformPkg/ArmPlatformPkg.dec
- OpenPlatformPkg/Chips/Nxp/QoriqLs/NxpQoriqLs.dec
Please sort file names and LibraryClasses in this file.
diff --git a/Platforms/Nxp/LS1043aRdb/Include/Library/PlatformLib.h b/Platforms/Nxp/LS1043aRdb/Include/Library/PlatformLib.h index 39247e8..a4d26e8 100644 --- a/Platforms/Nxp/LS1043aRdb/Include/Library/PlatformLib.h +++ b/Platforms/Nxp/LS1043aRdb/Include/Library/PlatformLib.h @@ -73,6 +73,7 @@ #define I2C2_BASE_ADDRESS 0x021A0000 #define I2C3_BASE_ADDRESS 0x02183000 #define I2C_SIZE 0x10000
- #define I2C_BUS_MAX 4 #define DSPI_MEMORY_SIZE 0x10000 #define DDRC_MEMORY_SIZE 0x10000 #define SDXC_MEMORY_SIZE 0x10000
diff --git a/Platforms/Nxp/LS1043aRdb/Library/LS1043aSocLib/LS1043aSocLib.c b/Platforms/Nxp/LS1043aRdb/Library/LS1043aSocLib/LS1043aSocLib.c index 2a7cb38..8a2a0e0 100644 --- a/Platforms/Nxp/LS1043aRdb/Library/LS1043aSocLib/LS1043aSocLib.c +++ b/Platforms/Nxp/LS1043aRdb/Library/LS1043aSocLib/LS1043aSocLib.c @@ -115,6 +115,13 @@ static struct CsuNsDev NonSecureDevices[] = {SEC_UNIT_CSLX_DSCR, SEC_UNIT_ALL_RW}, }; +EFI_PHYSICAL_ADDRESS I2cAddress[] = {
(EFI_PHYSICAL_ADDRESS)I2C0_BASE_ADDRESS,
(EFI_PHYSICAL_ADDRESS)I2C1_BASE_ADDRESS,
(EFI_PHYSICAL_ADDRESS)I2C2_BASE_ADDRESS,
(EFI_PHYSICAL_ADDRESS)I2C3_BASE_ADDRESS
+};
char *StringToMHz ( char *Buf, unsigned long Hz @@ -800,3 +807,13 @@ CalculateI2cClockRate( return SocSysInfo.FreqSystemBus; }
+UINT32 +I2cBusAddrArr(
EFI_PHYSICAL_ADDRESS **Arr
)
+{
- *Arr = (EFI_PHYSICAL_ADDRESS*)I2cAddress;
- return I2C_BUS_MAX;
+}
1.9.1
Hi Leif,
From: Leif Lindholm [mailto:leif.lindholm@linaro.org] Sent: Saturday, November 05, 2016 4:04 AM
On Tue, Oct 18, 2016 at 01:34:08AM +0530, Bhupesh Sharma wrote:
From: Sakar Arora Sakar.Arora@nxp.com
This patch adds a library which performs I2C bus initialization and provides I2C read and write APIs for the I2C controller present on
the
LS1043A SOC.
Signed-off-by: Meenakshi Aggarwal meenakshi.aggarwal@nxp.com Signed-off-by: Bhupesh Sharma bhupesh.sharma@nxp.com
Chips/Nxp/QoriqLs/Include/Library/I2c.h | 199 ++++++++ Chips/Nxp/QoriqLs/Library/I2cLib/I2cLib.c | 513
+++++++++++++++++++++
Chips/Nxp/QoriqLs/Library/I2cLib/I2cLib.inf | 41 ++ .../Nxp/LS1043aRdb/Include/Library/PlatformLib.h | 1 + .../Library/LS1043aSocLib/LS1043aSocLib.c | 17 + 5 files changed, 771 insertions(+) create mode 100644 Chips/Nxp/QoriqLs/Include/Library/I2c.h create mode 100644 Chips/Nxp/QoriqLs/Library/I2cLib/I2cLib.c create mode 100644 Chips/Nxp/QoriqLs/Library/I2cLib/I2cLib.inf
diff --git a/Chips/Nxp/QoriqLs/Include/Library/I2c.h b/Chips/Nxp/QoriqLs/Include/Library/I2c.h new file mode 100644 index 0000000..e9d5d61 --- /dev/null +++ b/Chips/Nxp/QoriqLs/Include/Library/I2c.h @@ -0,0 +1,199 @@ +/** @I2c.h
- Header defining the constant, base address amd function for I2C
+controller
- Copyright (c) 2016, Freescale Semiconductor, Inc. All rights
reserved.
- This program and the accompanying materials are licensed and made
- available under the terms and conditions of the BSD License which
- accompanies this distribution. The full text of the license may be
- found at http://opensource.org/licenses/bsd-license.php
- THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS"
- BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER
EXPRESS OR IMPLIED.
+**/
+#ifndef __I2C_H___ +#define __I2C_H__
The two lines above don't match.
Oops. Will fix in v2.
+#include <Uefi.h> +#include <Library/TimerLib.h>
+#define I2C0 0 +#define I2C1 1 +#define I2C2 2 +#define I2C3 3
+/// +/// Define the I2C flags +/// +/// I2C read operation when set +#define I2C_READ_FLAG 0x1 +#define I2C_WRITE_FLAG 0x2
+#define I2C_CR_IIEN (1 << 6) +#define I2C_CR_MSTA (1 << 5) +#define I2C_CR_MTX (1 << 4) +#define I2C_CR_TX_NO_AK (1 << 3) +#define I2C_CR_RSTA (1 << 2)
+#define I2C_SR_ICF (1 << 7) +#define I2C_SR_IBB (1 << 5) +#define I2C_SR_IAL (1 << 4) +#define I2C_SR_IIF (1 << 1) +#define I2C_SR_RX_NO_AK (1 << 0)
+#define I2C_CR_IEN (0 << 7) +#define I2C_CR_IDIS (1 << 7) +#define I2C_SR_IIF_CLEAR (1 << 1)
+#define BUS_IDLE (0 | (I2C_SR_IBB << 8)) #define BUS_BUSY
(I2C_SR_IBB
+| (I2C_SR_IBB << 8)) #define IIF (I2C_SR_IIF | (I2C_SR_IIF << 8))
+#define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
Can be deleted when you update to a more recent edk2.
Sure.
+/**
- Record defining i2c registers
+**/
+struct I2cRegs {
- UINT8 I2cAdr;
- UINT8 I2cFdr;
- UINT8 I2cCr;
- UINT8 I2cSr;
- UINT8 I2cDr;
+};
typedef?
Will make this a typedef in V2.
+/**
- Function to initialize i2c bus
+**/ +VOID +I2cBusInit (
VOID
- );
+/**
- Function to read data usin i2c
- @param Base A pointer to the base address of
I2c Controller
- @param Chip Address of slave device from where
data to be read
- @param Offset Offset of slave memory
- @param Alen Address length of slave
- @param Buffer A pointer to the destination buffer
for the data
- @param Len Length of data to be read
- @retval EFI_NOT_READY Arbitration lost
- @retval EFI_TIMEOUT Failed to initialize data transfer
in predefined time
- @retval EFI_NOT_FOUND ACK was not recieved
- @retval EFI_SUCCESS Read was successful
+**/ +EFI_STATUS +I2cDataRead (
- IN UINT32 I2cBus,
- IN UINT8 Chip,
- IN UINT32 Offset,
- IN UINT32 Alen,
- OUT UINT8 *Buffer,
- IN UINT32 Len
- );
+/**
- Function to set I2c bus speed
- @param BaseAddress Base address of I2c controller
- @param Speed value to be set
+**/ +EFI_STATUS +EFIAPI +I2cSetBusSpeed (
- IN UINT32 I2cBus,
- IN UINT32 Speed
- );
+/**
- Function to stop transaction on i2c bus
- @param I2cRegs Pointer to i2c registers
- @retval EFI_NOT_READY Arbitration was lost
- @retval EFI_TIMEOUT Timeout occured
- @retval EFI_SUCCESS Stop operation was successful
+**/ +EFI_STATUS +I2cStop (
- IN struct I2cRegs *I2cRegs
- );
+/**
- Function to initiate data transfer on i2c bus
- @param I2cRegs Pointer to i2c base registers
- @param Chip Chip Address
- @param Offset Slave memory's offset
- @param Alen length of chip address
- @retval EFI_NOT_READY Arbitration lost
- @retval EFI_TIMEOUT Failed to initialize data
transfer in predefined time
- @retval EFI_NOT_FOUND ACK was not recieved
- @retval EFI_SUCCESS Read was successful
+**/ +EFI_STATUS +I2cBusInitTransfer (
- IN struct I2cRegs *I2cRegs,
- IN UINT8 Chip,
- IN UINT32 Offset,
- IN INT32 Alen
- );
+/**
- Function to write data using i2c bus
- @param Base Pointer to the base address of
I2c Controller
- @param Chip Address of slave device where
data to be written
- @param Offset Offset of slave memory
- @param Alen Address length of slave
- @param Buffer A pointer to the source buffer
for the data
- @param Len Length of data to be write
- @retval EFI_NOT_READY Arbitration lost
- @retval EFI_TIMEOUT Failed to initialize data
transfer in predefined time
- @retval EFI_NOT_FOUND ACK was not recieved
- @retval EFI_SUCCESS Read was successful
+**/ +EFI_STATUS +I2cDataWrite (
- IN UINT32 I2cBus,
- IN UINT8 Chip,
- IN UINT32 Offset,
- IN INT32 Alen,
- OUT UINT8 *Buffer,
- IN INT32 Len
- );
+/**
- Function to reset I2c
+**/
+VOID +I2cReset (
- UINT32 I2cBus
- );
+EFI_STATUS +EFIAPI +I2cProbeDevices (
- IN INT16 I2c,
- IN UINT8 Chip
- );
+#endif diff --git a/Chips/Nxp/QoriqLs/Library/I2cLib/I2cLib.c b/Chips/Nxp/QoriqLs/Library/I2cLib/I2cLib.c new file mode 100644 index 0000000..0050783 --- /dev/null +++ b/Chips/Nxp/QoriqLs/Library/I2cLib/I2cLib.c @@ -0,0 +1,513 @@ +/** I2cLib.c
- I2c Library containing functions for read, write, initialize, set
+speed etc
- Copyright (c) 2016, Freescale Semiconductor, Inc. All rights
reserved.
- This program and the accompanying materials are licensed and made
- available under the terms and conditions of the BSD License which
- accompanies this distribution. The full text of the license may be
- found at http://opensource.org/licenses/bsd-license.php
- THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS"
- BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER
EXPRESS OR IMPLIED.
+**/
+#include <Base.h> +#include <Library/DebugLib.h> +#include <Library/IoLib.h> +#include <Library/BaseMemoryLib.h> +#include <Library/BaseMemoryLib/MemLibInternals.h> +#include <Library/BaseLib.h> +#include <Library/I2c.h>
Please sort the above alphabetically.
Ok.
+extern UINT32 I2cBusAddrArr(EFI_PHYSICAL_ADDRESS **I2cAddrArr); +extern UINT32 CalculateI2cClockRate(VOID);
These should be pulled in from an include file.
Sure.
+EFI_PHYSICAL_ADDRESS *I2cAddrArr; +UINT32 I2cAddrArrSize;
Global variables should have g or m prefix. If they're only used in this file, then m, and also make them STATIC.
Ok, thanks for the pointers :)
+UINT16 ClkDiv[60][2] = {
- { 20, 0x00 }, { 22, 0x01 }, { 24, 0x02 }, { 26, 0x03 },
- { 28, 0x04 }, { 30, 0x05 }, { 32, 0x09 }, { 34, 0x06 },
- { 36, 0x0A }, { 40, 0x07 }, { 44, 0x0C }, { 48, 0x0D },
- { 52, 0x43 }, { 56, 0x0E }, { 60, 0x45 }, { 64, 0x12 },
- { 68, 0x0F }, { 72, 0x13 }, { 80, 0x14 }, { 88, 0x15 },
- { 96, 0x19 }, { 104, 0x16 }, { 112, 0x1A }, { 128, 0x17 },
- { 136, 0x4F }, { 144, 0x1C }, { 160, 0x1D }, { 176, 0x55 },
- { 192, 0x1E }, { 208, 0x56 }, { 224, 0x22 }, { 228, 0x24 },
- { 240, 0x1F }, { 256, 0x23 }, { 288, 0x5C }, { 320, 0x25 },
- { 384, 0x26 }, { 448, 0x2A }, { 480, 0x27 }, { 512, 0x2B },
- { 576, 0x2C }, { 640, 0x2D }, { 768, 0x31 }, { 896, 0x32 },
- { 960, 0x2F }, { 1024, 0x33 }, { 1152, 0x34 },{ 1280, 0x35 },
- { 1536, 0x36 }, { 1792, 0x3A }, { 1920, 0x37 }, { 2048, 0x3B },
- { 2304, 0x3C }, { 2560, 0x3D }, { 3072, 0x3E }, { 3584, 0x7A },
- { 3840, 0x3F }, { 4096, 0x7B }, { 5120, 0x7D }, { 6144, 0x7E }, };
+/**
- Calculate and set proper clock divider
- @param Rate clock rate
- @retval ClkDiv Value used to get frequency divider value
+**/
STATIC?
Ok.
+UINT8 +GetClk(
- IN UINT32 Rate
- )
+{
- UINTN ClkRate;
- UINT32 Div;
- UINT8 ClkDivx;
- ClkRate = CalculateI2cClockRate();
- Div = (ClkRate + Rate - 1) / Rate;
- if (Div < ClkDiv[0][0])
- ClkDivx = 0;
- else if (Div > ClkDiv[ARRAY_SIZE(ClkDiv) - 1][0])
- ClkDivx = ARRAY_SIZE(ClkDiv) - 1; else
- for (ClkDivx = 0; ClkDiv[ClkDivx][0] < Div; ClkDivx++);
- return ClkDivx;
+}
+/**
- Function to reset I2C module
+**/
+VOID +I2cReset (
- UINT32 I2cBus
- )
+{
- struct I2cRegs *I2cRegs = (struct I2cRegs *)I2cAddrArr[I2cBus];
- /** Reset module */
- MmioWrite8((UINTN)&I2cRegs->I2cCr, I2C_CR_IDIS);
- MmioWrite8((UINTN)&I2cRegs->I2cSr, 0); }
+/**
- Function to set I2c bus speed
- @param BaseAddress Base address of I2c controller
- @param Speed value to be set
+**/ +EFI_STATUS +EFIAPI +I2cSetBusSpeed (
- IN UINT32 I2cBus,
- IN UINT32 Speed
- )
+{
- struct I2cRegs *I2cRegs = (struct I2cRegs *)I2cAddrArr[I2cBus];
- ASSERT(I2cRegs);
- UINT8 ClkId = GetClk(Speed);
- UINT8 SpeedId = ClkDiv[ClkId][1];
- /** Store divider value */
- MmioWrite8((UINTN)&I2cRegs->I2cFdr, SpeedId); I2cReset(I2cBus);
- return EFI_SUCCESS;
+}
+/**
- Function used to check if i2c is in mentioned state or not
- @param I2cRegs Pointer to I2C registers
- @param State i2c state need to be checked
- @retval EFI_NOT_READY Arbitration was lost
- @retval EFI_TIMEOUT Timeout occured
- @retval CurrState Value of state register
+**/ +EFI_STATUS +WaitForI2cState (
- IN struct I2cRegs *I2cRegs,
- IN UINT32 State
- )
+{
- UINT8 CurrState;
- UINT64 Cnt = 0;
- for (Cnt = 0; Cnt < 50; Cnt++) {
- CurrState = MmioRead8((UINTN)&I2cRegs->I2cSr);
- if (CurrState & I2C_SR_IAL) {
MmioWrite8((UINTN)&I2cRegs->I2cSr, CurrState | I2C_SR_IAL);
return EFI_NOT_READY;
- }
- if ((CurrState & (State >> 8)) == (UINT8)State)
return CurrState;
- MicroSecondDelay(300);
Why 300?
Ok, will add appropriate comment here.
- }
- return EFI_TIMEOUT;
+}
+/**
- Function to transfer byte on i2c
- @param I2cRegs Pointer to i2c registers
- @param Byte Byte to be transferred on i2c bus
- @retval EFI_NOT_READY Arbitration was lost
- @retval EFI_TIMEOUT Timeout occured
- @retval EFI_NOT_FOUND ACK was not recieved
- @retval EFI_SUCCESS Data transfer was succesful
+**/
STATIC?
Ok.
+EFI_STATUS +TransferByte (
- IN struct I2cRegs *I2cRegs,
- IN UINT8 Byte
- )
+{
- EFI_STATUS Ret;
- MmioWrite8((UINTN)&I2cRegs->I2cSr, I2C_SR_IIF_CLEAR);
- MmioWrite8((UINTN)&I2cRegs->I2cDr, Byte);
- Ret = WaitForI2cState(I2cRegs, IIF); if ((Ret == EFI_TIMEOUT) ||
- (Ret == EFI_NOT_READY))
- return Ret;
- if (Ret & I2C_SR_RX_NO_AK) {
- return EFI_NOT_FOUND;
- }
- return EFI_SUCCESS;
+}
+/**
- Function to stop transaction on i2c bus
- @param I2cRegs Pointer to i2c registers
- @retval EFI_NOT_READY Arbitration was lost
- @retval EFI_TIMEOUT Timeout occured
- @retval EFI_SUCCESS Stop operation was successful
+**/ +EFI_STATUS +I2cStop (
- IN struct I2cRegs *I2cRegs
- )
+{
- INT32 Ret;
- UINT32 Temp = MmioRead8((UINTN)&I2cRegs->I2cCr);
- Temp &= ~(I2C_CR_MSTA | I2C_CR_MTX);
- MmioWrite8((UINTN)&I2cRegs->I2cCr, Temp); Ret =
- WaitForI2cState(I2cRegs, BUS_IDLE); if (Ret < 0)
Always braces with if/else.
Sure.
- return Ret;
- else
- return EFI_SUCCESS;
+}
+/**
- Function to send start signal, Chip Address and
- memory offset
- @param I2cRegs Pointer to i2c base registers
- @param Chip Chip Address
- @param Offset Slave memory's offset
- @param Alen length of chip address
- @retval EFI_NOT_READY Arbitration lost
- @retval EFI_TIMEOUT Failed to initialize data
transfer in predefined time
- @retval EFI_NOT_FOUND ACK was not recieved
- @retval EFI_SUCCESS Read was successful
+**/ +EFI_STATUS +InitTransfer (
- IN struct I2cRegs *I2cRegs,
- IN UINT8 Chip,
- IN UINT32 Offset,
- IN INT32 Alen
- )
+{
- UINT32 Temp;
- EFI_STATUS Ret;
- /** Enable I2C controller */
- if (MmioRead8((UINTN)&I2cRegs->I2cCr) & I2C_CR_IDIS)
Always braces with if/else. (please address globally)
Ok.
- MmioWrite8((UINTN)&I2cRegs->I2cCr, I2C_CR_IEN);
- if (MmioRead8((UINTN)&I2cRegs->I2cAdr) == (Chip << 1))
- MmioWrite8((UINTN)&I2cRegs->I2cAdr, (Chip << 1) ^ 2);
- MmioWrite8((UINTN)&I2cRegs->I2cSr, I2C_SR_IIF_CLEAR); Ret =
- WaitForI2cState(I2cRegs, BUS_IDLE); if ((Ret == EFI_TIMEOUT) ||
- (Ret == EFI_NOT_READY))
- return Ret;
- /** Start I2C transaction */
- Temp = MmioRead8((UINTN)&I2cRegs->I2cCr);
- /** set to master mode */
- Temp |= I2C_CR_MSTA;
- MmioWrite8((UINTN)&I2cRegs->I2cCr, Temp);
- Ret = WaitForI2cState(I2cRegs, BUS_BUSY); if ((Ret ==
EFI_TIMEOUT)
- || (Ret == EFI_NOT_READY))
- return Ret;
- Temp |= I2C_CR_MTX | I2C_CR_TX_NO_AK;
- MmioWrite8((UINTN)&I2cRegs->I2cCr, Temp);
- /** write slave Address */
- Ret = TransferByte(I2cRegs, Chip << 1);
Can we have a macro instead of that inline <<?
Yes, will change in V2.
- if (Ret != EFI_SUCCESS)
- return Ret;
- if (Alen >= 0) {
- while (Alen--) {
Ret = TransferByte(I2cRegs, (Offset >> (Alen * 8)) & 0xff);
Can we have a macro instead of that inline Offset/Alen manipulation?
Yes, will change in V2.
if (Ret != EFI_SUCCESS)
return Ret;
- }
- }
- return EFI_SUCCESS;
+}
+/**
- Function to check if i2c bud is idle
- @param Base Pointer to base address of I2c controller
- @retval EFI_SUCCESS
+**/ +INT32 +I2cBusIdle (
- IN VOID *Base
- )
+{
- return EFI_SUCCESS;
+}
+/**
- Function to initiate data transfer on i2c bus
- @param I2cRegs Pointer to i2c base registers
- @param Chip Chip Address
- @param Offset Slave memory's offset
- @param Alen length of chip address
- @retval EFI_NOT_READY Arbitration lost
- @retval EFI_TIMEOUT Failed to initialize data
transfer in predefined time
- @retval EFI_NOT_FOUND ACK was not recieved
- @retval EFI_SUCCESS Read was successful
+**/ +EFI_STATUS +InitDataTransfer (
- IN struct I2cRegs *I2cRegs,
- IN UINT8 Chip,
- IN UINT32 Offset,
- IN INT32 Alen
- )
+{
- INT32 Retry;
- EFI_STATUS Ret;
- for (Retry = 0; Retry < 3; Retry++) {
- Ret = InitTransfer(I2cRegs, Chip, Offset, Alen);
- if (Ret == EFI_SUCCESS)
return EFI_SUCCESS;
- I2cStop(I2cRegs);
- if (EFI_NOT_FOUND == Ret) {
return Ret;
- }
- /** Disable controller */
- if (Ret != EFI_NOT_READY)
MmioWrite8((UINTN)&I2cRegs->I2cCr, I2C_CR_IDIS);
- if (I2cBusIdle(I2cRegs) < 0)
break;
- }
- return Ret;
+}
+/**
- Function to read data using i2c bus
- @param Base A pointer to the base address of
I2c Controller
- @param Chip Address of slave device from
where data to be read
- @param Offset Offset of slave memory
- @param Alen Address length of slave
- @param Buffer A pointer to the destination
buffer for the data
- @param Len Length of data to be read
- @retval EFI_NOT_READY Arbitration lost
- @retval EFI_TIMEOUT Failed to initialize data
transfer in predefined time
- @retval EFI_NOT_FOUND ACK was not recieved
- @retval EFI_SUCCESS Read was successful
+**/ +EFI_STATUS +I2cDataRead (
- IN UINT32 I2cBus,
- IN UINT8 Chip,
- IN UINT32 Offset,
- IN UINT32 Alen,
- IN UINT8 *Buffer,
- IN UINT32 Len
- )
+{
- EFI_STATUS Ret;
- UINT32 Temp;
- INT32 i;
- struct I2cRegs *I2cRegs = (struct I2cRegs *)I2cAddrArr[I2cBus];
- ASSERT(I2cRegs);
- Ret = InitDataTransfer(I2cRegs, Chip, Offset, Alen);
- if (Ret != EFI_SUCCESS)
- return Ret;
- Temp = MmioRead8((UINTN)&I2cRegs->I2cCr);
- Temp |= I2C_CR_RSTA;
- MmioWrite8((UINTN)&I2cRegs->I2cCr, Temp);
- Ret = TransferByte(I2cRegs, (Chip << 1) | 1);
Can we have a macro instead of that inline manipulation of Chip? Or can the prototype of TransferByte be extended to make the code more obvious?
Yes, will change in V2.
- if (Ret != EFI_SUCCESS) {
- I2cStop(I2cRegs);
- return Ret;
- }
- /** setup bus to read data */
- Temp = MmioRead8((UINTN)&I2cRegs->I2cCr);
- Temp &= ~(I2C_CR_MTX | I2C_CR_TX_NO_AK); if (Len == 1)
- Temp |= I2C_CR_TX_NO_AK;
- MmioWrite8((UINTN)&I2cRegs->I2cCr, Temp);
- MmioWrite8((UINTN)&I2cRegs->I2cSr, I2C_SR_IIF_CLEAR);
- /** read data */
- /** Dummy Read to initiate recieve operation */
- MmioRead8((UINTN)&I2cRegs->I2cDr);
- for (i = 0; i < Len; i++) {
- Ret = WaitForI2cState(I2cRegs, IIF);
- if ((Ret == EFI_TIMEOUT) || (Ret == EFI_NOT_READY)) {
I2cStop(I2cRegs);
return Ret;
- }
- /**
It must generate STOP before read I2DR to prevent
controller from generating another clock cycle
- **/
- if (i == (Len - 1)) {
I2cStop(I2cRegs);
- } else if (i == (Len - 2)) {
Temp = MmioRead8((UINTN)&I2cRegs->I2cCr);
Temp |= I2C_CR_TX_NO_AK;
MmioWrite8((UINTN)&I2cRegs->I2cCr, Temp);
- }
- MmioWrite8((UINTN)&I2cRegs->I2cSr, I2C_SR_IIF_CLEAR);
- Buffer[i] = MmioRead8((UINTN)&I2cRegs->I2cDr);
- }
- I2cStop(I2cRegs);
- return EFI_SUCCESS;
+}
+/**
- Function to write data using i2c bus
- @param Base Pointer to the base address of
I2c Controller
- @param Chip Address of slave device where
data to be written
- @param Offset Offset of slave memory
- @param Alen Address length of slave
- @param Buffer A pointer to the source buffer
for the data
- @param Len Length of data to be write
- @retval EFI_NOT_READY Arbitration lost
- @retval EFI_TIMEOUT Failed to initialize data
transfer in predefined time
- @retval EFI_NOT_FOUND ACK was not recieved
- @retval EFI_SUCCESS Read was successful
+**/ +EFI_STATUS +I2cDataWrite (
- IN UINT32 I2cBus,
- IN UINT8 Chip,
- IN UINT32 Offset,
- IN INT32 Alen,
- OUT UINT8 *Buffer,
- IN INT32 Len
- )
+{
- EFI_STATUS Ret;
- INT32 I;
- struct I2cRegs *I2cRegs = (struct I2cRegs *)I2cAddrArr[I2cBus];
- ASSERT(I2cRegs);
- Ret = InitDataTransfer(I2cRegs, Chip, Offset, Alen); if (Ret !=
- EFI_SUCCESS)
- return Ret;
- /** write data */
- /** Dummy write to initiate write operation */
- for (I = 0; I < Len; I++) {
- Ret = TransferByte(I2cRegs, Buffer[I]);
- if (Ret != EFI_SUCCESS)
break;
- }
- I2cStop(I2cRegs);
- return Ret;
+}
+/**
- Function to Probe i2c bus
- @param I2c parameter defining I2c controller
no
- @retval EFI_INVALID_PARAMETER Input parametr I2c was invalid
- @retval EFI_SUCCESS I2c was initialized successfully
+**/ +EFI_STATUS +EFIAPI +I2cProbeDevices (
- IN INT16 I2c,
- IN UINT8 ChipAdd
- )
+{
- ASSERT(I2cAddrArr);
- if(I2c >= I2cAddrArrSize || I2cAddrArr[I2c] == 0x0)
Parenthesis around each comparison statement, please.
Ok.
- return EFI_INVALID_PARAMETER;
- return I2cDataWrite(I2c, ChipAdd, 0, 0, NULL, 0); }
+/**
- Function to initialize i2c bus
+**/ +VOID +I2cBusInit (
VOID
- )
+{
- I2cAddrArrSize = I2cBusAddrArr(&I2cAddrArr); }
diff --git a/Chips/Nxp/QoriqLs/Library/I2cLib/I2cLib.inf b/Chips/Nxp/QoriqLs/Library/I2cLib/I2cLib.inf new file mode 100644 index 0000000..f148c36 --- /dev/null +++ b/Chips/Nxp/QoriqLs/Library/I2cLib/I2cLib.inf @@ -0,0 +1,41 @@ +#/** I2cLib.inf +# +# Component description file for I2cLib module # # Copyright (c) +2016, Freescale Semiconductor, Inc. All rights reserved. +# +# This program and the accompanying materials # are licensed and +made available under the terms and conditions of the BSD License # +which accompanies this distribution. The full text of the license
may
+be found at # http://opensource.org/licenses/bsd-license.php +# +# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" +BASIS, # WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER
EXPRESS OR IMPLIED.
+# +#**/
+[Defines]
- INF_VERSION = 0x00010005
- BASE_NAME = I2cLib
- FILE_GUID = 8ecefc8f-a2c4-4091-b81f-
20f7aeb0567f
- MODULE_TYPE = BASE
- VERSION_STRING = 1.0
- LIBRARY_CLASS = I2cLib
+[Sources.common]
- I2cLib.c
+[LibraryClasses]
- ArmLib
- IoLib
- BaseMemoryLib
- BaseLib
- SocLib
- TimerLib
+[Packages]
- EmbeddedPkg/EmbeddedPkg.dec
- MdePkg/MdePkg.dec
- MdeModulePkg/MdeModulePkg.dec
- ArmPlatformPkg/ArmPlatformPkg.dec
- OpenPlatformPkg/Chips/Nxp/QoriqLs/NxpQoriqLs.dec
Please sort file names and LibraryClasses in this file.
Ok.
diff --git a/Platforms/Nxp/LS1043aRdb/Include/Library/PlatformLib.h b/Platforms/Nxp/LS1043aRdb/Include/Library/PlatformLib.h index 39247e8..a4d26e8 100644 --- a/Platforms/Nxp/LS1043aRdb/Include/Library/PlatformLib.h +++ b/Platforms/Nxp/LS1043aRdb/Include/Library/PlatformLib.h @@ -73,6 +73,7 @@ #define I2C2_BASE_ADDRESS 0x021A0000 #define I2C3_BASE_ADDRESS 0x02183000 #define I2C_SIZE 0x10000
- #define I2C_BUS_MAX 4 #define DSPI_MEMORY_SIZE 0x10000 #define DDRC_MEMORY_SIZE 0x10000 #define SDXC_MEMORY_SIZE 0x10000
diff --git a/Platforms/Nxp/LS1043aRdb/Library/LS1043aSocLib/LS1043aSocLib.c b/Platforms/Nxp/LS1043aRdb/Library/LS1043aSocLib/LS1043aSocLib.c index 2a7cb38..8a2a0e0 100644 --- a/Platforms/Nxp/LS1043aRdb/Library/LS1043aSocLib/LS1043aSocLib.c +++ b/Platforms/Nxp/LS1043aRdb/Library/LS1043aSocLib/LS1043aSocLib.c @@ -115,6 +115,13 @@ static struct CsuNsDev NonSecureDevices[] = {SEC_UNIT_CSLX_DSCR, SEC_UNIT_ALL_RW}, };
+EFI_PHYSICAL_ADDRESS I2cAddress[] = {
(EFI_PHYSICAL_ADDRESS)I2C0_BASE_ADDRESS,
(EFI_PHYSICAL_ADDRESS)I2C1_BASE_ADDRESS,
(EFI_PHYSICAL_ADDRESS)I2C2_BASE_ADDRESS,
(EFI_PHYSICAL_ADDRESS)I2C3_BASE_ADDRESS
+};
char *StringToMHz ( char *Buf, unsigned long Hz @@ -800,3 +807,13 @@ CalculateI2cClockRate(
return SocSysInfo.FreqSystemBus; }
+UINT32 +I2cBusAddrArr(
EFI_PHYSICAL_ADDRESS **Arr
)
+{
- *Arr = (EFI_PHYSICAL_ADDRESS*)I2cAddress;
- return I2C_BUS_MAX;
+}
1.9.1
From: Sakar Arora sakar.arora@nxp.com
This patch adds a DXE driver for the I2C controller present on LS1043A SoC.
This DXE driver uses the I2C library to implement various functionalities required by the I2C master protocol.
Signed-off-by: Meenakshi Aggarwal meenakshi.aggarwal@nxp.com Signed-off-by: Bhupesh Sharma bhupesh.sharma@nxp.com --- Chips/Nxp/QoriqLs/I2c/I2cDxe.c | 156 +++++++++++++++++++++++++++++++++++++++ Chips/Nxp/QoriqLs/I2c/I2cDxe.inf | 52 +++++++++++++ 2 files changed, 208 insertions(+) create mode 100644 Chips/Nxp/QoriqLs/I2c/I2cDxe.c create mode 100644 Chips/Nxp/QoriqLs/I2c/I2cDxe.inf
diff --git a/Chips/Nxp/QoriqLs/I2c/I2cDxe.c b/Chips/Nxp/QoriqLs/I2c/I2cDxe.c new file mode 100644 index 0000000..982c43d --- /dev/null +++ b/Chips/Nxp/QoriqLs/I2c/I2cDxe.c @@ -0,0 +1,156 @@ +/** I2c.c + I2c driver APIs for read, write, initialize, set speed and reset + + Copyright (c) 2016, Freescale Semiconductor, Inc. All rights reserved. + + This program and the accompanying materials + are licensed and made available under the terms and conditions of the BSD License + which accompanies this distribution. The full text of the license may be found at + http://opensource.org/licenses/bsd-license.php + + THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, + WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. + +**/ +#include <Library/UefiBootServicesTableLib.h> +#include <Library/DebugLib.h> +#include <Library/IoLib.h> +#include <Library/I2c.h> +#include <Protocol/I2cMaster.h> + + +EFI_STATUS +EFIAPI +SetBusFrequency ( + IN CONST EFI_I2C_MASTER_PROTOCOL *This, + IN OUT UINTN *BusClockHertz + ) +{ + + return (I2cSetBusSpeed(PcdGet32(PcdI2cBus), *BusClockHertz)); +} + +EFI_STATUS +EFIAPI +Reset ( + IN CONST EFI_I2C_MASTER_PROTOCOL *This + ) +{ + I2cReset(PcdGet32(PcdI2cBus)); + return EFI_SUCCESS; +} + +EFI_STATUS +EFIAPI StartRequest ( + IN CONST EFI_I2C_MASTER_PROTOCOL *This, + IN UINTN SlaveAddress, + IN EFI_I2C_REQUEST_PACKET *RequestPacket, + IN EFI_EVENT Event OPTIONAL, + OUT EFI_STATUS *I2cStatus OPTIONAL + ) +{ + UINT32 Count; + INT32 Ret; + UINT32 Length; + UINT8 *Buffer = NULL; + UINT32 Flag; + + if (RequestPacket->OperationCount <= 0) { + DEBUG((EFI_D_ERROR," Operation count is not valid %d\n", + RequestPacket->OperationCount)); + return EFI_INVALID_PARAMETER; + } + + if (RequestPacket->Operation == NULL) { + DEBUG((EFI_D_ERROR," Operation array is NULL\n")); + return EFI_INVALID_PARAMETER; + } + + for (Count = 0; Count < RequestPacket->OperationCount; Count++) { + Flag = RequestPacket->Operation[Count].Flags; + Length = RequestPacket->Operation[Count].LengthInBytes; + Buffer = RequestPacket->Operation[Count].Buffer; + + if (Length <= 0) { + DEBUG((EFI_D_ERROR," Invalid length of buffer %d\n", Length)); + return EFI_INVALID_PARAMETER; + } + + if (Flag == I2C_READ_FLAG) { + Ret = I2cDataRead (PcdGet32(PcdI2cBus), SlaveAddress, + 0x00, sizeof(SlaveAddress)/8, Buffer, Length); + if (Ret != EFI_SUCCESS) { + DEBUG((EFI_D_ERROR," I2c read operation failed (error %d)\n", Ret)); + return Ret; + } + } else if (Flag == I2C_WRITE_FLAG) { + Ret = I2cDataWrite (PcdGet32(PcdI2cBus), SlaveAddress, + 0x00, sizeof(SlaveAddress)/8, Buffer, Length); + if (Ret != EFI_SUCCESS) { + DEBUG((EFI_D_ERROR," I2c write operation failed (error %d)\n", Ret)); + return Ret; + } + } else { + DEBUG((EFI_D_ERROR," Invalid Flag %d\n",Flag)); + return EFI_INVALID_PARAMETER; + } + } + + return EFI_SUCCESS; +} + +CONST EFI_I2C_CONTROLLER_CAPABILITIES I2cControllerCapabilities = { + 0, + 0, + 0, + 0 +}; + +EFI_I2C_MASTER_PROTOCOL I2c = { + /// + /// Set the clock frequency for the I2C bus. + /// + SetBusFrequency, + /// + /// Reset the I2C host controller. + /// + Reset, + /// + /// Start an I2C transaction in master mode on the host controller. + /// + StartRequest, + /// + /// Pointer to an EFI_I2C_CONTROLLER_CAPABILITIES data structure containing + /// the capabilities of the I2C host controller. + /// + &I2cControllerCapabilities +}; + +/** + The user Entry Point for I2C module. The user code starts with this function. + + @param[in] ImageHandle The firmware allocated handle for the EFI image. + @param[in] SystemTable A pointer to the EFI System Table. + + @retval EFI_SUCCESS The entry point is executed successfully. + @retval other Some error occurs when executing this entry point. + +**/ +EFI_STATUS +EFIAPI +InitializeI2c( + IN EFI_HANDLE ImageHandle, + IN EFI_SYSTEM_TABLE *SystemTable + ) +{ + EFI_STATUS Status = 0; + + I2cBusInit(); + + Status = gBS->InstallMultipleProtocolInterfaces ( + &ImageHandle, + &gEfiI2cMasterProtocolGuid, (VOID**)&I2c, + NULL + ); + return Status; +} diff --git a/Chips/Nxp/QoriqLs/I2c/I2cDxe.inf b/Chips/Nxp/QoriqLs/I2c/I2cDxe.inf new file mode 100644 index 0000000..0b37c38 --- /dev/null +++ b/Chips/Nxp/QoriqLs/I2c/I2cDxe.inf @@ -0,0 +1,52 @@ +/* I2cDxe.inf +# +# Component description file for I2c driver +# +# Copyright (c) 2016, Freescale Semiconductor, Inc. All rights reserved. +# +# This program and the accompanying materials +# are licensed and made available under the terms and conditions of the BSD License +# which accompanies this distribution. The full text of the license may be found at +# http://opensource.org/licenses/bsd-license.php +# +# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, +# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. +# +# +*/ + +[Defines] + INF_VERSION = 0x00010005 + BASE_NAME = I2c + FILE_GUID = 4ec8b120-8307-11e0-bd91-0002a5d5c51b + MODULE_TYPE = DXE_DRIVER + VERSION_STRING = 1.0 + ENTRY_POINT = InitializeI2c + +[Sources.common] + I2cDxe.c + +[LibraryClasses] + I2cLib + ArmLib + PcdLib + UefiLib + UefiDriverEntryPoint + MemoryAllocationLib + IoLib + PcdLib + +[Packages] + MdePkg/MdePkg.dec + OpenPlatformPkg/Platforms/Nxp/LS1043aRdb/LS1043aRdbPkg.dec + OpenPlatformPkg/Chips/Nxp/QoriqLs/NxpQoriqLs.dec + +[Protocols] + gEfiI2cMasterProtocolGuid + +[Pcd] + gNxpQoriqLsTokenSpaceGuid.PcdI2cBus + gNxpQoriqLsTokenSpaceGuid.PcdI2cSpeed + +[Depex] + TRUE
On 17 October 2016 at 21:04, Bhupesh Sharma bhupesh.sharma@freescale.com wrote:
From: Sakar Arora sakar.arora@nxp.com
This patch adds a DXE driver for the I2C controller present on LS1043A SoC.
This DXE driver uses the I2C library to implement various functionalities required by the I2C master protocol.
Signed-off-by: Meenakshi Aggarwal meenakshi.aggarwal@nxp.com Signed-off-by: Bhupesh Sharma bhupesh.sharma@nxp.com
Chips/Nxp/QoriqLs/I2c/I2cDxe.c | 156 +++++++++++++++++++++++++++++++++++++++ Chips/Nxp/QoriqLs/I2c/I2cDxe.inf | 52 +++++++++++++ 2 files changed, 208 insertions(+) create mode 100644 Chips/Nxp/QoriqLs/I2c/I2cDxe.c create mode 100644 Chips/Nxp/QoriqLs/I2c/I2cDxe.inf
diff --git a/Chips/Nxp/QoriqLs/I2c/I2cDxe.c b/Chips/Nxp/QoriqLs/I2c/I2cDxe.c new file mode 100644 index 0000000..982c43d --- /dev/null +++ b/Chips/Nxp/QoriqLs/I2c/I2cDxe.c @@ -0,0 +1,156 @@ +/** I2c.c
- I2c driver APIs for read, write, initialize, set speed and reset
- Copyright (c) 2016, Freescale Semiconductor, Inc. All rights reserved.
- This program and the accompanying materials
- are licensed and made available under the terms and conditions of the BSD License
- which accompanies this distribution. The full text of the license may be found at
- http://opensource.org/licenses/bsd-license.php
- THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
- WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
+**/ +#include <Library/UefiBootServicesTableLib.h> +#include <Library/DebugLib.h> +#include <Library/IoLib.h> +#include <Library/I2c.h> +#include <Protocol/I2cMaster.h>
+EFI_STATUS +EFIAPI +SetBusFrequency (
- IN CONST EFI_I2C_MASTER_PROTOCOL *This,
- IN OUT UINTN *BusClockHertz
- )
+{
- return (I2cSetBusSpeed(PcdGet32(PcdI2cBus), *BusClockHertz));
+}
+EFI_STATUS +EFIAPI +Reset (
- IN CONST EFI_I2C_MASTER_PROTOCOL *This
- )
+{
- I2cReset(PcdGet32(PcdI2cBus));
- return EFI_SUCCESS;
+}
+EFI_STATUS +EFIAPI StartRequest (
- IN CONST EFI_I2C_MASTER_PROTOCOL *This,
- IN UINTN SlaveAddress,
- IN EFI_I2C_REQUEST_PACKET *RequestPacket,
- IN EFI_EVENT Event OPTIONAL,
- OUT EFI_STATUS *I2cStatus OPTIONAL
- )
+{
- UINT32 Count;
- INT32 Ret;
- UINT32 Length;
- UINT8 *Buffer = NULL;
- UINT32 Flag;
- if (RequestPacket->OperationCount <= 0) {
- DEBUG((EFI_D_ERROR," Operation count is not valid %d\n",
RequestPacket->OperationCount));
- return EFI_INVALID_PARAMETER;
- }
- if (RequestPacket->Operation == NULL) {
- DEBUG((EFI_D_ERROR," Operation array is NULL\n"));
- return EFI_INVALID_PARAMETER;
- }
- for (Count = 0; Count < RequestPacket->OperationCount; Count++) {
- Flag = RequestPacket->Operation[Count].Flags;
- Length = RequestPacket->Operation[Count].LengthInBytes;
- Buffer = RequestPacket->Operation[Count].Buffer;
- if (Length <= 0) {
DEBUG((EFI_D_ERROR," Invalid length of buffer %d\n", Length));
return EFI_INVALID_PARAMETER;
- }
- if (Flag == I2C_READ_FLAG) {
Ret = I2cDataRead (PcdGet32(PcdI2cBus), SlaveAddress,
0x00, sizeof(SlaveAddress)/8, Buffer, Length);
if (Ret != EFI_SUCCESS) {
DEBUG((EFI_D_ERROR," I2c read operation failed (error %d)\n", Ret));
return Ret;
}
- } else if (Flag == I2C_WRITE_FLAG) {
Ret = I2cDataWrite (PcdGet32(PcdI2cBus), SlaveAddress,
0x00, sizeof(SlaveAddress)/8, Buffer, Length);
if (Ret != EFI_SUCCESS) {
DEBUG((EFI_D_ERROR," I2c write operation failed (error %d)\n", Ret));
return Ret;
}
- } else {
DEBUG((EFI_D_ERROR," Invalid Flag %d\n",Flag));
return EFI_INVALID_PARAMETER;
- }
- }
- return EFI_SUCCESS;
+}
+CONST EFI_I2C_CONTROLLER_CAPABILITIES I2cControllerCapabilities = {
STATIC
- 0,
- 0,
- 0,
- 0
+};
+EFI_I2C_MASTER_PROTOCOL I2c = {
STATIC
- ///
- /// Set the clock frequency for the I2C bus.
- ///
- SetBusFrequency,
- ///
- /// Reset the I2C host controller.
- ///
- Reset,
- ///
- /// Start an I2C transaction in master mode on the host controller.
- ///
- StartRequest,
- ///
- /// Pointer to an EFI_I2C_CONTROLLER_CAPABILITIES data structure containing
- /// the capabilities of the I2C host controller.
- ///
- &I2cControllerCapabilities
+};
+/**
- The user Entry Point for I2C module. The user code starts with this function.
- @param[in] ImageHandle The firmware allocated handle for the EFI image.
- @param[in] SystemTable A pointer to the EFI System Table.
- @retval EFI_SUCCESS The entry point is executed successfully.
- @retval other Some error occurs when executing this entry point.
+**/ +EFI_STATUS +EFIAPI +InitializeI2c(
- IN EFI_HANDLE ImageHandle,
- IN EFI_SYSTEM_TABLE *SystemTable
- )
+{
- EFI_STATUS Status = 0;
- I2cBusInit();
- Status = gBS->InstallMultipleProtocolInterfaces (
&ImageHandle,
&gEfiI2cMasterProtocolGuid, (VOID**)&I2c,
NULL
);
- return Status;
+} diff --git a/Chips/Nxp/QoriqLs/I2c/I2cDxe.inf b/Chips/Nxp/QoriqLs/I2c/I2cDxe.inf new file mode 100644 index 0000000..0b37c38 --- /dev/null +++ b/Chips/Nxp/QoriqLs/I2c/I2cDxe.inf @@ -0,0 +1,52 @@ +/* I2cDxe.inf +# +# Component description file for I2c driver +# +# Copyright (c) 2016, Freescale Semiconductor, Inc. All rights reserved. +# +# This program and the accompanying materials +# are licensed and made available under the terms and conditions of the BSD License +# which accompanies this distribution. The full text of the license may be found at +# http://opensource.org/licenses/bsd-license.php +# +# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, +# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. +# +# +*/
+[Defines]
- INF_VERSION = 0x00010005
- BASE_NAME = I2c
- FILE_GUID = 4ec8b120-8307-11e0-bd91-0002a5d5c51b
Fresh GUID
- MODULE_TYPE = DXE_DRIVER
- VERSION_STRING = 1.0
- ENTRY_POINT = InitializeI2c
+[Sources.common]
- I2cDxe.c
+[LibraryClasses]
- I2cLib
- ArmLib
- PcdLib
- UefiLib
- UefiDriverEntryPoint
- MemoryAllocationLib
- IoLib
- PcdLib
+[Packages]
- MdePkg/MdePkg.dec
- OpenPlatformPkg/Platforms/Nxp/LS1043aRdb/LS1043aRdbPkg.dec
- OpenPlatformPkg/Chips/Nxp/QoriqLs/NxpQoriqLs.dec
+[Protocols]
- gEfiI2cMasterProtocolGuid
+[Pcd]
- gNxpQoriqLsTokenSpaceGuid.PcdI2cBus
- gNxpQoriqLsTokenSpaceGuid.PcdI2cSpeed
+[Depex]
- TRUE
-- 1.9.1
Hi Ard,
Thanks for the review comments. Please see my replies inline.
From: Ard Biesheuvel [mailto:ard.biesheuvel@linaro.org] Sent: Tuesday, October 18, 2016 3:14 PM
On 17 October 2016 at 21:04, Bhupesh Sharma bhupesh.sharma@freescale.com wrote:
From: Sakar Arora sakar.arora@nxp.com
This patch adds a DXE driver for the I2C controller present on
LS1043A
SoC.
This DXE driver uses the I2C library to implement various functionalities required by the I2C master protocol.
Signed-off-by: Meenakshi Aggarwal meenakshi.aggarwal@nxp.com Signed-off-by: Bhupesh Sharma bhupesh.sharma@nxp.com
Chips/Nxp/QoriqLs/I2c/I2cDxe.c | 156
+++++++++++++++++++++++++++++++++++++++
Chips/Nxp/QoriqLs/I2c/I2cDxe.inf | 52 +++++++++++++ 2 files changed, 208 insertions(+) create mode 100644 Chips/Nxp/QoriqLs/I2c/I2cDxe.c create mode
100644
Chips/Nxp/QoriqLs/I2c/I2cDxe.inf
diff --git a/Chips/Nxp/QoriqLs/I2c/I2cDxe.c b/Chips/Nxp/QoriqLs/I2c/I2cDxe.c new file mode 100644 index 0000000..982c43d --- /dev/null +++ b/Chips/Nxp/QoriqLs/I2c/I2cDxe.c @@ -0,0 +1,156 @@ +/** I2c.c
- I2c driver APIs for read, write, initialize, set speed and reset
- Copyright (c) 2016, Freescale Semiconductor, Inc. All rights
reserved.
- This program and the accompanying materials are licensed and made
- available under the terms and conditions of the BSD License which
- accompanies this distribution. The full text of the license may be
- found at http://opensource.org/licenses/bsd-license.php
- THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS"
- BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER
EXPRESS OR IMPLIED.
+**/ +#include <Library/UefiBootServicesTableLib.h> +#include <Library/DebugLib.h> +#include <Library/IoLib.h> +#include <Library/I2c.h> +#include <Protocol/I2cMaster.h>
+EFI_STATUS +EFIAPI +SetBusFrequency (
- IN CONST EFI_I2C_MASTER_PROTOCOL *This,
- IN OUT UINTN *BusClockHertz
- )
+{
- return (I2cSetBusSpeed(PcdGet32(PcdI2cBus), *BusClockHertz)); }
+EFI_STATUS +EFIAPI +Reset (
- IN CONST EFI_I2C_MASTER_PROTOCOL *This
- )
+{
- I2cReset(PcdGet32(PcdI2cBus));
- return EFI_SUCCESS;
+}
+EFI_STATUS +EFIAPI StartRequest (
- IN CONST EFI_I2C_MASTER_PROTOCOL *This,
- IN UINTN SlaveAddress,
- IN EFI_I2C_REQUEST_PACKET *RequestPacket,
- IN EFI_EVENT Event OPTIONAL,
- OUT EFI_STATUS *I2cStatus OPTIONAL
- )
+{
- UINT32 Count;
- INT32 Ret;
- UINT32 Length;
- UINT8 *Buffer = NULL;
- UINT32 Flag;
- if (RequestPacket->OperationCount <= 0) {
- DEBUG((EFI_D_ERROR," Operation count is not valid %d\n",
RequestPacket->OperationCount));
- return EFI_INVALID_PARAMETER;
- }
- if (RequestPacket->Operation == NULL) {
- DEBUG((EFI_D_ERROR," Operation array is NULL\n"));
- return EFI_INVALID_PARAMETER;
- }
- for (Count = 0; Count < RequestPacket->OperationCount; Count++) {
- Flag = RequestPacket->Operation[Count].Flags;
- Length = RequestPacket->Operation[Count].LengthInBytes;
- Buffer = RequestPacket->Operation[Count].Buffer;
- if (Length <= 0) {
DEBUG((EFI_D_ERROR," Invalid length of buffer %d\n", Length));
return EFI_INVALID_PARAMETER;
- }
- if (Flag == I2C_READ_FLAG) {
Ret = I2cDataRead (PcdGet32(PcdI2cBus), SlaveAddress,
0x00, sizeof(SlaveAddress)/8, Buffer, Length);
if (Ret != EFI_SUCCESS) {
DEBUG((EFI_D_ERROR," I2c read operation failed (error
%d)\n", Ret));
return Ret;
}
- } else if (Flag == I2C_WRITE_FLAG) {
Ret = I2cDataWrite (PcdGet32(PcdI2cBus), SlaveAddress,
0x00, sizeof(SlaveAddress)/8, Buffer, Length);
if (Ret != EFI_SUCCESS) {
DEBUG((EFI_D_ERROR," I2c write operation failed (error
%d)\n", Ret));
return Ret;
}
- } else {
DEBUG((EFI_D_ERROR," Invalid Flag %d\n",Flag));
return EFI_INVALID_PARAMETER;
- }
- }
- return EFI_SUCCESS;
+}
+CONST EFI_I2C_CONTROLLER_CAPABILITIES I2cControllerCapabilities = {
STATIC
Ok.
- 0,
- 0,
- 0,
- 0
+};
+EFI_I2C_MASTER_PROTOCOL I2c = {
STATIC
Ok.
- ///
- /// Set the clock frequency for the I2C bus.
- ///
- SetBusFrequency,
- ///
- /// Reset the I2C host controller.
- ///
- Reset,
- ///
- /// Start an I2C transaction in master mode on the host
controller.
- ///
- StartRequest,
- ///
- /// Pointer to an EFI_I2C_CONTROLLER_CAPABILITIES data structure
+containing
- /// the capabilities of the I2C host controller.
- ///
- &I2cControllerCapabilities
+};
+/**
- The user Entry Point for I2C module. The user code starts with
this function.
- @param[in] ImageHandle The firmware allocated handle for the
EFI image.
- @param[in] SystemTable A pointer to the EFI System Table.
- @retval EFI_SUCCESS The entry point is executed
successfully.
- @retval other Some error occurs when executing this
entry point.
+**/ +EFI_STATUS +EFIAPI +InitializeI2c(
- IN EFI_HANDLE ImageHandle,
- IN EFI_SYSTEM_TABLE *SystemTable
- )
+{
- EFI_STATUS Status = 0;
- I2cBusInit();
- Status = gBS->InstallMultipleProtocolInterfaces (
&ImageHandle,
&gEfiI2cMasterProtocolGuid, (VOID**)&I2c,
NULL
);
- return Status;
+} diff --git a/Chips/Nxp/QoriqLs/I2c/I2cDxe.inf b/Chips/Nxp/QoriqLs/I2c/I2cDxe.inf new file mode 100644 index 0000000..0b37c38 --- /dev/null +++ b/Chips/Nxp/QoriqLs/I2c/I2cDxe.inf @@ -0,0 +1,52 @@ +/* I2cDxe.inf +# +# Component description file for I2c driver # # Copyright (c)
2016,
+Freescale Semiconductor, Inc. All rights reserved. +# +# This program and the accompanying materials # are licensed and +made available under the terms and conditions of the BSD License # +which accompanies this distribution. The full text of the license
may
+be found at # http://opensource.org/licenses/bsd-license.php +# +# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" +BASIS, # WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER
EXPRESS OR IMPLIED.
+# +# +*/
+[Defines]
- INF_VERSION = 0x00010005
- BASE_NAME = I2c
- FILE_GUID = 4ec8b120-8307-11e0-bd91-
0002a5d5c51b
Fresh GUID
Ok, will change this in V2.
- MODULE_TYPE = DXE_DRIVER
- VERSION_STRING = 1.0
- ENTRY_POINT = InitializeI2c
+[Sources.common]
- I2cDxe.c
+[LibraryClasses]
- I2cLib
- ArmLib
- PcdLib
- UefiLib
- UefiDriverEntryPoint
- MemoryAllocationLib
- IoLib
- PcdLib
+[Packages]
- MdePkg/MdePkg.dec
- OpenPlatformPkg/Platforms/Nxp/LS1043aRdb/LS1043aRdbPkg.dec
- OpenPlatformPkg/Chips/Nxp/QoriqLs/NxpQoriqLs.dec
+[Protocols]
- gEfiI2cMasterProtocolGuid
+[Pcd]
- gNxpQoriqLsTokenSpaceGuid.PcdI2cBus
- gNxpQoriqLsTokenSpaceGuid.PcdI2cSpeed
+[Depex]
- TRUE
-- 1.9.1
Regards, Bhupesh
On Tue, Oct 18, 2016 at 01:34:09AM +0530, Bhupesh Sharma wrote:
From: Sakar Arora sakar.arora@nxp.com
This patch adds a DXE driver for the I2C controller present on LS1043A SoC.
This DXE driver uses the I2C library to implement various functionalities required by the I2C master protocol.
Signed-off-by: Meenakshi Aggarwal meenakshi.aggarwal@nxp.com Signed-off-by: Bhupesh Sharma bhupesh.sharma@nxp.com
Chips/Nxp/QoriqLs/I2c/I2cDxe.c | 156 +++++++++++++++++++++++++++++++++++++++ Chips/Nxp/QoriqLs/I2c/I2cDxe.inf | 52 +++++++++++++ 2 files changed, 208 insertions(+) create mode 100644 Chips/Nxp/QoriqLs/I2c/I2cDxe.c create mode 100644 Chips/Nxp/QoriqLs/I2c/I2cDxe.inf
diff --git a/Chips/Nxp/QoriqLs/I2c/I2cDxe.c b/Chips/Nxp/QoriqLs/I2c/I2cDxe.c new file mode 100644 index 0000000..982c43d --- /dev/null +++ b/Chips/Nxp/QoriqLs/I2c/I2cDxe.c @@ -0,0 +1,156 @@ +/** I2c.c
- I2c driver APIs for read, write, initialize, set speed and reset
- Copyright (c) 2016, Freescale Semiconductor, Inc. All rights reserved.
- This program and the accompanying materials
- are licensed and made available under the terms and conditions of the BSD License
- which accompanies this distribution. The full text of the license may be found at
- http://opensource.org/licenses/bsd-license.php
- THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
- WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
+**/ +#include <Library/UefiBootServicesTableLib.h> +#include <Library/DebugLib.h> +#include <Library/IoLib.h> +#include <Library/I2c.h> +#include <Protocol/I2cMaster.h>
Please sort the above alphabetically.
+EFI_STATUS +EFIAPI +SetBusFrequency (
- IN CONST EFI_I2C_MASTER_PROTOCOL *This,
- IN OUT UINTN *BusClockHertz
- )
+{
- return (I2cSetBusSpeed(PcdGet32(PcdI2cBus), *BusClockHertz));
+}
+EFI_STATUS +EFIAPI +Reset (
- IN CONST EFI_I2C_MASTER_PROTOCOL *This
- )
+{
- I2cReset(PcdGet32(PcdI2cBus));
- return EFI_SUCCESS;
+}
+EFI_STATUS +EFIAPI StartRequest (
- IN CONST EFI_I2C_MASTER_PROTOCOL *This,
- IN UINTN SlaveAddress,
- IN EFI_I2C_REQUEST_PACKET *RequestPacket,
- IN EFI_EVENT Event OPTIONAL,
- OUT EFI_STATUS *I2cStatus OPTIONAL
- )
+{
- UINT32 Count;
- INT32 Ret;
- UINT32 Length;
- UINT8 *Buffer = NULL;
- UINT32 Flag;
- if (RequestPacket->OperationCount <= 0) {
- DEBUG((EFI_D_ERROR," Operation count is not valid %d\n",
RequestPacket->OperationCount));
- return EFI_INVALID_PARAMETER;
- }
- if (RequestPacket->Operation == NULL) {
- DEBUG((EFI_D_ERROR," Operation array is NULL\n"));
- return EFI_INVALID_PARAMETER;
- }
- for (Count = 0; Count < RequestPacket->OperationCount; Count++) {
- Flag = RequestPacket->Operation[Count].Flags;
- Length = RequestPacket->Operation[Count].LengthInBytes;
- Buffer = RequestPacket->Operation[Count].Buffer;
- if (Length <= 0) {
DEBUG((EFI_D_ERROR," Invalid length of buffer %d\n", Length));
return EFI_INVALID_PARAMETER;
- }
- if (Flag == I2C_READ_FLAG) {
Ret = I2cDataRead (PcdGet32(PcdI2cBus), SlaveAddress,
0x00, sizeof(SlaveAddress)/8, Buffer, Length);
What's 0x00?
Why sizeof(SlaveAddress)/8? Since it's used twice in this function, could put it in a temporary variable with a descriptive name and maybe a comment if needed.
if (Ret != EFI_SUCCESS) {
DEBUG((EFI_D_ERROR," I2c read operation failed (error %d)\n", Ret));
return Ret;
}
- } else if (Flag == I2C_WRITE_FLAG) {
Ret = I2cDataWrite (PcdGet32(PcdI2cBus), SlaveAddress,
0x00, sizeof(SlaveAddress)/8, Buffer, Length);
if (Ret != EFI_SUCCESS) {
DEBUG((EFI_D_ERROR," I2c write operation failed (error %d)\n", Ret));
return Ret;
}
- } else {
DEBUG((EFI_D_ERROR," Invalid Flag %d\n",Flag));
return EFI_INVALID_PARAMETER;
- }
- }
- return EFI_SUCCESS;
+}
+CONST EFI_I2C_CONTROLLER_CAPABILITIES I2cControllerCapabilities = {
- 0,
- 0,
- 0,
- 0
+};
+EFI_I2C_MASTER_PROTOCOL I2c = {
- ///
- /// Set the clock frequency for the I2C bus.
- ///
- SetBusFrequency,
- ///
- /// Reset the I2C host controller.
- ///
- Reset,
- ///
- /// Start an I2C transaction in master mode on the host controller.
- ///
- StartRequest,
- ///
- /// Pointer to an EFI_I2C_CONTROLLER_CAPABILITIES data structure containing
- /// the capabilities of the I2C host controller.
- ///
- &I2cControllerCapabilities
+};
+/**
- The user Entry Point for I2C module. The user code starts with this function.
- @param[in] ImageHandle The firmware allocated handle for the EFI image.
- @param[in] SystemTable A pointer to the EFI System Table.
- @retval EFI_SUCCESS The entry point is executed successfully.
- @retval other Some error occurs when executing this entry point.
+**/ +EFI_STATUS +EFIAPI +InitializeI2c(
- IN EFI_HANDLE ImageHandle,
- IN EFI_SYSTEM_TABLE *SystemTable
- )
+{
- EFI_STATUS Status = 0;
- I2cBusInit();
- Status = gBS->InstallMultipleProtocolInterfaces (
&ImageHandle,
&gEfiI2cMasterProtocolGuid, (VOID**)&I2c,
NULL
);
- return Status;
+} diff --git a/Chips/Nxp/QoriqLs/I2c/I2cDxe.inf b/Chips/Nxp/QoriqLs/I2c/I2cDxe.inf new file mode 100644 index 0000000..0b37c38 --- /dev/null +++ b/Chips/Nxp/QoriqLs/I2c/I2cDxe.inf @@ -0,0 +1,52 @@ +/* I2cDxe.inf +# +# Component description file for I2c driver +# +# Copyright (c) 2016, Freescale Semiconductor, Inc. All rights reserved. +# +# This program and the accompanying materials +# are licensed and made available under the terms and conditions of the BSD License +# which accompanies this distribution. The full text of the license may be found at +# http://opensource.org/licenses/bsd-license.php +# +# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, +# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. +# +# +*/
+[Defines]
- INF_VERSION = 0x00010005
- BASE_NAME = I2c
- FILE_GUID = 4ec8b120-8307-11e0-bd91-0002a5d5c51b
- MODULE_TYPE = DXE_DRIVER
- VERSION_STRING = 1.0
- ENTRY_POINT = InitializeI2c
+[Sources.common]
- I2cDxe.c
+[LibraryClasses]
- I2cLib
- ArmLib
- PcdLib
- UefiLib
- UefiDriverEntryPoint
- MemoryAllocationLib
- IoLib
- PcdLib
+[Packages]
- MdePkg/MdePkg.dec
- OpenPlatformPkg/Platforms/Nxp/LS1043aRdb/LS1043aRdbPkg.dec
- OpenPlatformPkg/Chips/Nxp/QoriqLs/NxpQoriqLs.dec
Please sort Packages and LibraryClasses alphabetically.
+[Protocols]
- gEfiI2cMasterProtocolGuid
+[Pcd]
- gNxpQoriqLsTokenSpaceGuid.PcdI2cBus
- gNxpQoriqLsTokenSpaceGuid.PcdI2cSpeed
+[Depex]
- TRUE
-- 1.9.1
Hi Leif,
From: Leif Lindholm [mailto:leif.lindholm@linaro.org] Sent: Saturday, November 05, 2016 4:27 AM
On Tue, Oct 18, 2016 at 01:34:09AM +0530, Bhupesh Sharma wrote:
From: Sakar Arora sakar.arora@nxp.com
This patch adds a DXE driver for the I2C controller present on
LS1043A
SoC.
This DXE driver uses the I2C library to implement various functionalities required by the I2C master protocol.
Signed-off-by: Meenakshi Aggarwal meenakshi.aggarwal@nxp.com Signed-off-by: Bhupesh Sharma bhupesh.sharma@nxp.com
Chips/Nxp/QoriqLs/I2c/I2cDxe.c | 156
+++++++++++++++++++++++++++++++++++++++
Chips/Nxp/QoriqLs/I2c/I2cDxe.inf | 52 +++++++++++++ 2 files changed, 208 insertions(+) create mode 100644 Chips/Nxp/QoriqLs/I2c/I2cDxe.c create mode
100644
Chips/Nxp/QoriqLs/I2c/I2cDxe.inf
diff --git a/Chips/Nxp/QoriqLs/I2c/I2cDxe.c b/Chips/Nxp/QoriqLs/I2c/I2cDxe.c new file mode 100644 index 0000000..982c43d --- /dev/null +++ b/Chips/Nxp/QoriqLs/I2c/I2cDxe.c @@ -0,0 +1,156 @@ +/** I2c.c
- I2c driver APIs for read, write, initialize, set speed and reset
- Copyright (c) 2016, Freescale Semiconductor, Inc. All rights
reserved.
- This program and the accompanying materials are licensed and made
- available under the terms and conditions of the BSD License which
- accompanies this distribution. The full text of the license may be
- found at http://opensource.org/licenses/bsd-license.php
- THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS"
- BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER
EXPRESS OR IMPLIED.
+**/ +#include <Library/UefiBootServicesTableLib.h> +#include <Library/DebugLib.h> +#include <Library/IoLib.h> +#include <Library/I2c.h> +#include <Protocol/I2cMaster.h>
Please sort the above alphabetically.
Ok.
+EFI_STATUS +EFIAPI +SetBusFrequency (
- IN CONST EFI_I2C_MASTER_PROTOCOL *This,
- IN OUT UINTN *BusClockHertz
- )
+{
- return (I2cSetBusSpeed(PcdGet32(PcdI2cBus), *BusClockHertz)); }
+EFI_STATUS +EFIAPI +Reset (
- IN CONST EFI_I2C_MASTER_PROTOCOL *This
- )
+{
- I2cReset(PcdGet32(PcdI2cBus));
- return EFI_SUCCESS;
+}
+EFI_STATUS +EFIAPI StartRequest (
- IN CONST EFI_I2C_MASTER_PROTOCOL *This,
- IN UINTN SlaveAddress,
- IN EFI_I2C_REQUEST_PACKET *RequestPacket,
- IN EFI_EVENT Event OPTIONAL,
- OUT EFI_STATUS *I2cStatus OPTIONAL
- )
+{
- UINT32 Count;
- INT32 Ret;
- UINT32 Length;
- UINT8 *Buffer = NULL;
- UINT32 Flag;
- if (RequestPacket->OperationCount <= 0) {
- DEBUG((EFI_D_ERROR," Operation count is not valid %d\n",
RequestPacket->OperationCount));
- return EFI_INVALID_PARAMETER;
- }
- if (RequestPacket->Operation == NULL) {
- DEBUG((EFI_D_ERROR," Operation array is NULL\n"));
- return EFI_INVALID_PARAMETER;
- }
- for (Count = 0; Count < RequestPacket->OperationCount; Count++) {
- Flag = RequestPacket->Operation[Count].Flags;
- Length = RequestPacket->Operation[Count].LengthInBytes;
- Buffer = RequestPacket->Operation[Count].Buffer;
- if (Length <= 0) {
DEBUG((EFI_D_ERROR," Invalid length of buffer %d\n", Length));
return EFI_INVALID_PARAMETER;
- }
- if (Flag == I2C_READ_FLAG) {
Ret = I2cDataRead (PcdGet32(PcdI2cBus), SlaveAddress,
0x00, sizeof(SlaveAddress)/8, Buffer, Length);
What's 0x00?
Why sizeof(SlaveAddress)/8? Since it's used twice in this function, could put it in a temporary variable with a descriptive name and maybe a comment if needed.
Sure, will add comments or use marcos/variables for clarity.
if (Ret != EFI_SUCCESS) {
DEBUG((EFI_D_ERROR," I2c read operation failed (error
%d)\n", Ret));
return Ret;
}
- } else if (Flag == I2C_WRITE_FLAG) {
Ret = I2cDataWrite (PcdGet32(PcdI2cBus), SlaveAddress,
0x00, sizeof(SlaveAddress)/8, Buffer, Length);
if (Ret != EFI_SUCCESS) {
DEBUG((EFI_D_ERROR," I2c write operation failed (error
%d)\n", Ret));
return Ret;
}
- } else {
DEBUG((EFI_D_ERROR," Invalid Flag %d\n",Flag));
return EFI_INVALID_PARAMETER;
- }
- }
- return EFI_SUCCESS;
+}
+CONST EFI_I2C_CONTROLLER_CAPABILITIES I2cControllerCapabilities = {
- 0,
- 0,
- 0,
- 0
+};
+EFI_I2C_MASTER_PROTOCOL I2c = {
- ///
- /// Set the clock frequency for the I2C bus.
- ///
- SetBusFrequency,
- ///
- /// Reset the I2C host controller.
- ///
- Reset,
- ///
- /// Start an I2C transaction in master mode on the host
controller.
- ///
- StartRequest,
- ///
- /// Pointer to an EFI_I2C_CONTROLLER_CAPABILITIES data structure
+containing
- /// the capabilities of the I2C host controller.
- ///
- &I2cControllerCapabilities
+};
+/**
- The user Entry Point for I2C module. The user code starts with
this function.
- @param[in] ImageHandle The firmware allocated handle for the
EFI image.
- @param[in] SystemTable A pointer to the EFI System Table.
- @retval EFI_SUCCESS The entry point is executed
successfully.
- @retval other Some error occurs when executing this
entry point.
+**/ +EFI_STATUS +EFIAPI +InitializeI2c(
- IN EFI_HANDLE ImageHandle,
- IN EFI_SYSTEM_TABLE *SystemTable
- )
+{
- EFI_STATUS Status = 0;
- I2cBusInit();
- Status = gBS->InstallMultipleProtocolInterfaces (
&ImageHandle,
&gEfiI2cMasterProtocolGuid, (VOID**)&I2c,
NULL
);
- return Status;
+} diff --git a/Chips/Nxp/QoriqLs/I2c/I2cDxe.inf b/Chips/Nxp/QoriqLs/I2c/I2cDxe.inf new file mode 100644 index 0000000..0b37c38 --- /dev/null +++ b/Chips/Nxp/QoriqLs/I2c/I2cDxe.inf @@ -0,0 +1,52 @@ +/* I2cDxe.inf +# +# Component description file for I2c driver # # Copyright (c)
2016,
+Freescale Semiconductor, Inc. All rights reserved. +# +# This program and the accompanying materials # are licensed and +made available under the terms and conditions of the BSD License # +which accompanies this distribution. The full text of the license
may
+be found at # http://opensource.org/licenses/bsd-license.php +# +# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" +BASIS, # WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER
EXPRESS OR IMPLIED.
+# +# +*/
+[Defines]
- INF_VERSION = 0x00010005
- BASE_NAME = I2c
- FILE_GUID = 4ec8b120-8307-11e0-bd91-
0002a5d5c51b
- MODULE_TYPE = DXE_DRIVER
- VERSION_STRING = 1.0
- ENTRY_POINT = InitializeI2c
+[Sources.common]
- I2cDxe.c
+[LibraryClasses]
- I2cLib
- ArmLib
- PcdLib
- UefiLib
- UefiDriverEntryPoint
- MemoryAllocationLib
- IoLib
- PcdLib
+[Packages]
- MdePkg/MdePkg.dec
- OpenPlatformPkg/Platforms/Nxp/LS1043aRdb/LS1043aRdbPkg.dec
- OpenPlatformPkg/Chips/Nxp/QoriqLs/NxpQoriqLs.dec
Please sort Packages and LibraryClasses alphabetically.
Ok.
+[Protocols]
- gEfiI2cMasterProtocolGuid
+[Pcd]
- gNxpQoriqLsTokenSpaceGuid.PcdI2cBus
- gNxpQoriqLsTokenSpaceGuid.PcdI2cSpeed
+[Depex]
- TRUE
-- 1.9.1
From: Sakar Arora sakar.arora@nxp.com
NXP/FSL ARMv8 SoCs currently use a EL3 platform and run-time security firmware which is called PPA (Primary Protected Application).
This firmware is placed on the flash device and is loaded into DDR and executed via a UEFI DXE driver. PPA does the initial platform EL3 settings and then returns the control back to UEFI in EL2 exception level.
Later implementations of PPA will allow it to start by itself in the EL3 level and start UEFI in EL2 exception level.
This patch adds the PPA load and execution handlers.
Signed-off-by: Sakar Arora sakar.arora@nxp.com Signed-off-by: Bhupesh Sharma bhupesh.sharma@nxp.com --- Chips/Nxp/QoriqLs/PpaInitDxe/PpaInit.c | 117 ++++++++++++++++++++++ Chips/Nxp/QoriqLs/PpaInitDxe/PpaInitDxe.inf | 63 ++++++++++++ Chips/Nxp/QoriqLs/PpaInitDxe/PpaInitHelper.S | 79 +++++++++++++++ Chips/Nxp/QoriqLs/PpaInitDxe/PpaItbParse.c | 144 +++++++++++++++++++++++++++ Chips/Nxp/QoriqLs/PpaInitDxe/PpaItbParse.h | 52 ++++++++++ 5 files changed, 455 insertions(+) create mode 100644 Chips/Nxp/QoriqLs/PpaInitDxe/PpaInit.c create mode 100644 Chips/Nxp/QoriqLs/PpaInitDxe/PpaInitDxe.inf create mode 100644 Chips/Nxp/QoriqLs/PpaInitDxe/PpaInitHelper.S create mode 100755 Chips/Nxp/QoriqLs/PpaInitDxe/PpaItbParse.c create mode 100755 Chips/Nxp/QoriqLs/PpaInitDxe/PpaItbParse.h
diff --git a/Chips/Nxp/QoriqLs/PpaInitDxe/PpaInit.c b/Chips/Nxp/QoriqLs/PpaInitDxe/PpaInit.c new file mode 100644 index 0000000..4e4cedb --- /dev/null +++ b/Chips/Nxp/QoriqLs/PpaInitDxe/PpaInit.c @@ -0,0 +1,117 @@ +/** @file +# +# DXE driver for loading Primary Protected Application +# +# Copyright (c) 2016, Freescale Semiconductor, Inc. All rights reserved. +# +# This program and the accompanying materials +# are licensed and made available under the terms and conditions of the BSD License +# which accompanies this distribution. The full text of the license may be found at +# http://opensource.org/licenses/bsd-license.php +# +# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, +# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. +# +**/ + +#include <Chipset/AArch64.h> +#include <Library/ArmPlatformLib.h> +#include <Library/PcdLib.h> +#include <Library/DebugLib.h> +#include <Library/IoLib.h> +#include <Library/PrintLib.h> +#include <Library/MemoryAllocationLib.h> +#include <Library/BaseMemoryLib/MemLibInternals.h> +#include "PpaItbParse.h" + +extern EFI_STATUS PpaInit(UINT64); +extern VOID InitMmu(ARM_MEMORY_REGION_DESCRIPTOR*); + +/** + * Copying PPA firmware to DDR + */ +VOID +CopyPpaImage ( + const char *title, + UINTN image_addr, + UINTN image_size, + UINTN PpaRamAddr) +{ + DEBUG((EFI_D_INFO, "%a copied to address 0x%x\n", title, PpaRamAddr)); + InternalMemCopyMem((void *)PpaRamAddr, (void *)image_addr, image_size); +} + +UINTN +GetPpaImagefromFlash ( + VOID + ) +{ + EFI_STATUS Status; + EFI_PHYSICAL_ADDRESS FitImage; + EFI_PHYSICAL_ADDRESS PpaImage; + INT32 CfgNodeOffset; + INT32 NodeOffset; + INT32 PpaImageSize; + UINTN PpaRamAddr; + + // Assuming that the PPA FW is present on NOR flash + // FIXME: Add support for other flash devices. + FitImage = PcdGet64 (PcdPpaNorBaseAddr); + + // PPA will be placed on DDR at this address: + // Top of DDR - PcdPpaDdrOffsetAddr + PpaRamAddr = PcdGet64 (PcdSystemMemoryBase) + PcdGet64 (PcdSystemMemorySize) + - PcdGet64 (PcdPpaDdrOffsetAddr); + + Status = FitCheckHeader(FitImage); + if (EFI_ERROR (Status)) { + DEBUG((EFI_D_ERROR, "Bad FIT image header (0x%x).\n", Status)); + goto EXIT_FREE_FIT; + } + + Status = FitGetConfNode(FitImage, (void *)(PcdGetPtr(PcdPpaFitConfiguration)), &CfgNodeOffset); + if (EFI_ERROR (Status)) { + DEBUG((EFI_D_ERROR, "Did not find configuration node in FIT header (0x%x).\n", Status)); + goto EXIT_FREE_FIT; + } + + Status = FitGetNodeFromConf(FitImage, CfgNodeOffset, FIT_FIRMWARE_IMAGE, &NodeOffset); + if (EFI_ERROR (Status)) { + DEBUG((EFI_D_ERROR, "Did not find PPA node in FIT header (0x%x).\n", Status)); + goto EXIT_FREE_FIT; + } + + Status = FitGetNodeData(FitImage, NodeOffset, (VOID*)&PpaImage, &PpaImageSize); + if (EFI_ERROR (Status)) { + DEBUG((EFI_D_ERROR, "Did not find PPA f/w in FIT image (0x%x).\n", Status)); + goto EXIT_FREE_FIT; + } + + CopyPpaImage ("PPA Firmware", PpaImage, PpaImageSize, PpaRamAddr); + + return PpaRamAddr; + +EXIT_FREE_FIT: + // Flow should never reach here + ASSERT (Status == EFI_SUCCESS); + + return 0; +} + +EFI_STATUS +PpaInitialize ( + IN EFI_HANDLE ImageHandle, + IN EFI_SYSTEM_TABLE *SystemTable + ) +{ + EFI_STATUS Status; + UINTN PpaRamAddr; + ARM_MEMORY_REGION_DESCRIPTOR *MemoryTable; + + PpaRamAddr = GetPpaImagefromFlash(); + + Status = PpaInit(PpaRamAddr); + ArmPlatformGetVirtualMemoryMap (&MemoryTable); + InitMmu(MemoryTable); + return Status; +} diff --git a/Chips/Nxp/QoriqLs/PpaInitDxe/PpaInitDxe.inf b/Chips/Nxp/QoriqLs/PpaInitDxe/PpaInitDxe.inf new file mode 100644 index 0000000..80f9cb0 --- /dev/null +++ b/Chips/Nxp/QoriqLs/PpaInitDxe/PpaInitDxe.inf @@ -0,0 +1,63 @@ +#/** PpaInitDxe.inf +# +# Component description file for Ppa Initialization driver +# +# Copyright (c) 2016, Freescale Semiconductor, Inc. All rights reserved. +# +# This program and the accompanying materials +# are licensed and made available under the terms and conditions of the BSD License +# which accompanies this distribution. The full text of the license may be found at +# http://opensource.org/licenses/bsd-license.php +# +# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, +# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. +# +# +#**/ + +[Defines] + INF_VERSION = 0x00010005 + BASE_NAME = PpaInit + FILE_GUID = 4d00ef14-c4e0-426b-81b7-30a00a14abb6 + MODULE_TYPE = DXE_DRIVER + VERSION_STRING = 1.0 + + ENTRY_POINT = PpaInitialize + +[Sources.common] + PpaInit.c + PpaInitHelper.S + PpaItbParse.c + +[Packages] + MdePkg/MdePkg.dec + ArmPkg/ArmPkg.dec + ArmPlatformPkg/ArmPlatformPkg.dec + EmbeddedPkg/EmbeddedPkg.dec + OpenPlatformPkg/Chips/Nxp/QoriqLs/NxpQoriqLs.dec + +[LibraryClasses] + BaseLib + UefiLib + UefiDriverEntryPoint + MemoryInitPeiLib + ArmLib + BdsLib + FdtLib + +[Guids] + +[Protocols] + +[Pcd] + gArmTokenSpaceGuid.PcdSystemMemoryBase + gArmTokenSpaceGuid.PcdSystemMemorySize + gNxpQoriqLsTokenSpaceGuid.PcdPpaNorBaseAddr + gNxpQoriqLsTokenSpaceGuid.PcdPpaDdrOffsetAddr + gNxpQoriqLsTokenSpaceGuid.PcdPpaFitConfiguration + +[FixedPcd] + + +[depex] + TRUE diff --git a/Chips/Nxp/QoriqLs/PpaInitDxe/PpaInitHelper.S b/Chips/Nxp/QoriqLs/PpaInitDxe/PpaInitHelper.S new file mode 100644 index 0000000..237015c --- /dev/null +++ b/Chips/Nxp/QoriqLs/PpaInitDxe/PpaInitHelper.S @@ -0,0 +1,79 @@ +# @PpaInitHelper.S +# +# Copyright (c) 2016, Freescale Semiconductor, Inc. All rights +# reserved. +# +# This program and the accompanying materials +# are licensed and made available under the terms and conditions of the BSD License +# which accompanies this distribution. The full text of the license may be found at +# http://opensource.org/licenses/bsd-license.php +# +# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, +# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. +# +# +#include <AutoGen.h> + +.text +.align 2 + +GCC_ASM_EXPORT(PpaInit) +GCC_ASM_EXPORT(El2SwitchSetup) + +ASM_PFX(PpaInit): +//Push return address to the stack +//sub sp, sp, #16 +//stur x30, [sp, #0] + +//Save stack pointer for EL2 + mov x1, sp + msr sp_el2, x1 + +//Set boot loc pointer + adr x4, 1f + adr x1, ADDR_BASE_SCFG + ldr w2, [x1] + mov x1, x4 + rev w3, w1 + str w3, [x2, #0x604] + lsr x1, x4, #32 + rev w3, w1 + str w3, [x2, #0x600] + +//Call PPA monitor + br x0 + +1: +//Pop out return address from stack +//ldur x30, [sp, #0] +//add sp, sp, #16 + + // Enable GICv2 interrupts in EL2 mode + mrs x0, hcr_el2 + orr x0, x0, #0x18 + msr hcr_el2, x0 + +//return 0 + mov x0, #0 + ret + + +ASM_PFX(El2SwitchSetup): + mov x0, #0x5b1 // non-secure el0/el1 | hvc | 64bit el2 + msr scr_el3, x0 + msr cptr_el3, xzr // disable coprocessor traps to el3 + mov x0, #0x33ff + msr cptr_el2, x0 // disable coprocessor traps to el2 + // initialize sctlr_el2 + msr sctlr_el2, xzr + mov x0, #0x3c9 + msr spsr_el3, x0 // el2_sp2 | d | a | i | f + ret + +ADDR_BASE_SCFG: + .long 0x01570000 + +ADDR_BASE_DCFG: + .long 0x01EE0000 + +ASM_FUNCTION_REMOVE_IF_UNREFERENCED diff --git a/Chips/Nxp/QoriqLs/PpaInitDxe/PpaItbParse.c b/Chips/Nxp/QoriqLs/PpaInitDxe/PpaItbParse.c new file mode 100755 index 0000000..9e6a477 --- /dev/null +++ b/Chips/Nxp/QoriqLs/PpaInitDxe/PpaItbParse.c @@ -0,0 +1,144 @@ +#include <libfdt.h> +#include <Library/DebugLib.h> + +#include "PpaItbParse.h" + +EFI_STATUS +FitCheckHeader( + EFI_PHYSICAL_ADDRESS FitImage +) +{ + if(fdt_check_header((VOID*) FitImage)) { + DEBUG((EFI_D_ERROR, "bad FIT header\n")); + return EFI_UNSUPPORTED; + } + + /* mandatory / node 'description' property */ + if (fdt_getprop((VOID*)FitImage, 0, FIT_DESC_PROP, NULL) == NULL) { + DEBUG((EFI_D_ERROR, "Wrong FIT format: no description\n")); + return EFI_UNSUPPORTED; + } + + /* mandatory subimages parent '/images' node */ + if (fdt_path_offset((VOID*)FitImage, FIT_IMAGES_PATH) < 0) { + DEBUG((EFI_D_ERROR, "Wrong FIT format: no images parent node\n")); + return EFI_UNSUPPORTED; + } + return EFI_SUCCESS; +} + +EFI_STATUS +FitGetConfNode ( + EFI_PHYSICAL_ADDRESS FitImage, + VOID* ConfigPtr, + INT32* NodeOffset +) +{ + INT32 noffset, confs_noffset; + INT32 len; + char* ConfigName; + + confs_noffset = fdt_path_offset((VOID*)FitImage, FIT_CONFS_PATH); + if (confs_noffset < 0) { + DEBUG((EFI_D_ERROR, "Can't find configurations parent node '%s' (%s)\n", + FIT_CONFS_PATH, fdt_strerror(confs_noffset))); + return EFI_UNSUPPORTED; + } + + ConfigName = (char*)ConfigPtr; + + if(ConfigName && *ConfigName == '\0') + ConfigName = NULL; + if (ConfigName == NULL) { + /* get configuration unit name from the default property + * */ + DEBUG((EFI_D_ERROR, "No configuration specified, trying default...\n")); + ConfigName = (CHAR8 *)fdt_getprop((VOID*)FitImage, confs_noffset, + FIT_DEFAULT_PROP, &len); + } + noffset = fdt_subnode_offset((VOID*)FitImage, confs_noffset, ConfigName); + if (noffset < 0) { + DEBUG((EFI_D_ERROR, + "Can't get node offset for configuration unit name: '%s' (%s)\n", + ConfigName, fdt_strerror(noffset))); + return EFI_UNSUPPORTED; + } + + *NodeOffset = noffset; + return EFI_SUCCESS; +} + +EFI_STATUS +FitGetNodeFromConf ( + EFI_PHYSICAL_ADDRESS FitImage, + INT32 CfgNodeOffset, + CHAR8* ConfPropName, + INT32* NodeOffset +) +{ + INT32 noffset, len, img_noffset; + CHAR8* PropName; + + PropName = (char *)fdt_getprop((VOID*)FitImage, CfgNodeOffset, + ConfPropName, &len); + + if (PropName == NULL) { + return EFI_UNSUPPORTED; + } + + img_noffset = fdt_path_offset((VOID*)FitImage, FIT_IMAGES_PATH); + if (img_noffset < 0) { + return EFI_UNSUPPORTED; + } + noffset = fdt_subnode_offset((VOID*)FitImage, img_noffset, PropName); + if (noffset < 0) { + return EFI_UNSUPPORTED; + } + + *NodeOffset = noffset; + return EFI_SUCCESS; +} + +EFI_STATUS +FitGetNodeData ( + EFI_PHYSICAL_ADDRESS FitImage, + INT32 NodeOffset, + EFI_PHYSICAL_ADDRESS* Addr, + INT32* Size +) +{ + VOID *Data; + + Data = (VOID*)fdt_getprop((VOID*)FitImage, NodeOffset, FIT_IMAGE_DATA, Size); + if(Data == NULL) { + return EFI_UNSUPPORTED; + } + *Addr = (EFI_PHYSICAL_ADDRESS)Data; + return EFI_SUCCESS; +} + +EFI_STATUS +FitGetNodeLoad ( + EFI_PHYSICAL_ADDRESS FitImage, + INT32 NodeOffset, + EFI_PHYSICAL_ADDRESS* Addr +) +{ + INT32 Size; + VOID* Load; + + Load = (VOID*)fdt_getprop((VOID*)FitImage, NodeOffset, FIT_IMAGE_LOAD, &Size); + if(Load == NULL) { + return EFI_UNSUPPORTED; + } + + if(Size == 4) + *Addr = MmioReadBe32((UINTN) Load); + else if(Size == 8) + *Addr = MmioReadBe64((UINTN) Load); + else { + return EFI_UNSUPPORTED; + } + + return EFI_SUCCESS; +} diff --git a/Chips/Nxp/QoriqLs/PpaInitDxe/PpaItbParse.h b/Chips/Nxp/QoriqLs/PpaInitDxe/PpaItbParse.h new file mode 100755 index 0000000..a6f78c0 --- /dev/null +++ b/Chips/Nxp/QoriqLs/PpaInitDxe/PpaItbParse.h @@ -0,0 +1,52 @@ +#ifndef __PPA_ITB_PARSE__ +#define __PPA_ITB_PARSE__ + +#include <Library/IoLib.h> + +#define FIT_DESC_PROP "description" +#define FIT_IMAGES_PATH "/images" +#define FIT_KERNEL_IMAGE "kernel" +#define FIT_INITRD_IMAGE "ramdisk" +#define FIT_FIRMWARE_IMAGE "firmware" +#define FIT_FDT_IMAGE "fdt" +#define FIT_CONFS_PATH "/configurations" +#define FIT_DEFAULT_PROP "default" +#define FIT_IMAGE_DATA "data" +#define FIT_IMAGE_LOAD "load" + +EFI_STATUS +FitCheckHeader( + EFI_PHYSICAL_ADDRESS FitImage +); + +EFI_STATUS +FitGetConfNode ( + EFI_PHYSICAL_ADDRESS FitImage, + VOID* ConfigPtr, + INT32* NodeOffset +); + +EFI_STATUS +FitGetNodeFromConf ( + EFI_PHYSICAL_ADDRESS FitImage, + INT32 CfgNodeOffset, + CHAR8* ConfPropName, + INT32* NodeOffset +); + +EFI_STATUS +FitGetNodeData ( + EFI_PHYSICAL_ADDRESS FitImage, + INT32 NodeOffset, + EFI_PHYSICAL_ADDRESS* Addr, + INT32* Size +); + +EFI_STATUS +FitGetNodeLoad ( + EFI_PHYSICAL_ADDRESS FitImage, + INT32 NodeOffset, + EFI_PHYSICAL_ADDRESS* Addr +); + +#endif
On Tue, Oct 18, 2016 at 01:34:10AM +0530, Bhupesh Sharma wrote:
From: Sakar Arora sakar.arora@nxp.com
NXP/FSL ARMv8 SoCs currently use a EL3 platform and run-time security firmware which is called PPA (Primary Protected Application).
This firmware is placed on the flash device and is loaded into DDR and executed via a UEFI DXE driver. PPA does the initial platform EL3 settings and then returns the control back to UEFI in EL2 exception level.
Later implementations of PPA will allow it to start by itself in the EL3 level and start UEFI in EL2 exception level.
This patch adds the PPA load and execution handlers.
Again, excellent commit message.
Signed-off-by: Sakar Arora sakar.arora@nxp.com Signed-off-by: Bhupesh Sharma bhupesh.sharma@nxp.com
Chips/Nxp/QoriqLs/PpaInitDxe/PpaInit.c | 117 ++++++++++++++++++++++ Chips/Nxp/QoriqLs/PpaInitDxe/PpaInitDxe.inf | 63 ++++++++++++ Chips/Nxp/QoriqLs/PpaInitDxe/PpaInitHelper.S | 79 +++++++++++++++ Chips/Nxp/QoriqLs/PpaInitDxe/PpaItbParse.c | 144 +++++++++++++++++++++++++++ Chips/Nxp/QoriqLs/PpaInitDxe/PpaItbParse.h | 52 ++++++++++ 5 files changed, 455 insertions(+) create mode 100644 Chips/Nxp/QoriqLs/PpaInitDxe/PpaInit.c create mode 100644 Chips/Nxp/QoriqLs/PpaInitDxe/PpaInitDxe.inf create mode 100644 Chips/Nxp/QoriqLs/PpaInitDxe/PpaInitHelper.S create mode 100755 Chips/Nxp/QoriqLs/PpaInitDxe/PpaItbParse.c create mode 100755 Chips/Nxp/QoriqLs/PpaInitDxe/PpaItbParse.h
diff --git a/Chips/Nxp/QoriqLs/PpaInitDxe/PpaInit.c b/Chips/Nxp/QoriqLs/PpaInitDxe/PpaInit.c new file mode 100644 index 0000000..4e4cedb --- /dev/null +++ b/Chips/Nxp/QoriqLs/PpaInitDxe/PpaInit.c @@ -0,0 +1,117 @@ +/** @file +# +# DXE driver for loading Primary Protected Application +# +# Copyright (c) 2016, Freescale Semiconductor, Inc. All rights reserved. +# +# This program and the accompanying materials +# are licensed and made available under the terms and conditions of the BSD License +# which accompanies this distribution. The full text of the license may be found at +# http://opensource.org/licenses/bsd-license.php +# +# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, +# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. +# +**/
+#include <Chipset/AArch64.h> +#include <Library/ArmPlatformLib.h> +#include <Library/PcdLib.h> +#include <Library/DebugLib.h> +#include <Library/IoLib.h> +#include <Library/PrintLib.h> +#include <Library/MemoryAllocationLib.h> +#include <Library/BaseMemoryLib/MemLibInternals.h> +#include "PpaItbParse.h"
Please sort alphabetically.
+extern EFI_STATUS PpaInit(UINT64); +extern VOID InitMmu(ARM_MEMORY_REGION_DESCRIPTOR*);
These should be pulled in from an include file.
+/**
- Copying PPA firmware to DDR
- */
+VOID +CopyPpaImage (
- const char *title,
- UINTN image_addr,
- UINTN image_size,
- UINTN PpaRamAddr)
+{
- DEBUG((EFI_D_INFO, "%a copied to address 0x%x\n", title, PpaRamAddr));
- InternalMemCopyMem((void *)PpaRamAddr, (void *)image_addr, image_size);
+}
+UINTN +GetPpaImagefromFlash (
- VOID
- )
+{
- EFI_STATUS Status;
- EFI_PHYSICAL_ADDRESS FitImage;
- EFI_PHYSICAL_ADDRESS PpaImage;
- INT32 CfgNodeOffset;
- INT32 NodeOffset;
- INT32 PpaImageSize;
- UINTN PpaRamAddr;
- // Assuming that the PPA FW is present on NOR flash
- // FIXME: Add support for other flash devices.
No FIXME please.
- FitImage = PcdGet64 (PcdPpaNorBaseAddr);
- // PPA will be placed on DDR at this address:
- // Top of DDR - PcdPpaDdrOffsetAddr
- PpaRamAddr = PcdGet64 (PcdSystemMemoryBase) + PcdGet64 (PcdSystemMemorySize)
- PcdGet64 (PcdPpaDdrOffsetAddr);
- Status = FitCheckHeader(FitImage);
- if (EFI_ERROR (Status)) {
DEBUG((EFI_D_ERROR, "Bad FIT image header (0x%x).\n", Status));
goto EXIT_FREE_FIT;
- }
- Status = FitGetConfNode(FitImage, (void *)(PcdGetPtr(PcdPpaFitConfiguration)), &CfgNodeOffset);
- if (EFI_ERROR (Status)) {
DEBUG((EFI_D_ERROR, "Did not find configuration node in FIT header (0x%x).\n", Status));
goto EXIT_FREE_FIT;
- }
- Status = FitGetNodeFromConf(FitImage, CfgNodeOffset, FIT_FIRMWARE_IMAGE, &NodeOffset);
- if (EFI_ERROR (Status)) {
DEBUG((EFI_D_ERROR, "Did not find PPA node in FIT header (0x%x).\n", Status));
goto EXIT_FREE_FIT;
- }
- Status = FitGetNodeData(FitImage, NodeOffset, (VOID*)&PpaImage, &PpaImageSize);
- if (EFI_ERROR (Status)) {
DEBUG((EFI_D_ERROR, "Did not find PPA f/w in FIT image (0x%x).\n", Status));
goto EXIT_FREE_FIT;
- }
- CopyPpaImage ("PPA Firmware", PpaImage, PpaImageSize, PpaRamAddr);
- return PpaRamAddr;
+EXIT_FREE_FIT:
- // Flow should never reach here
- ASSERT (Status == EFI_SUCCESS);
- return 0;
+}
+EFI_STATUS +PpaInitialize (
- IN EFI_HANDLE ImageHandle,
- IN EFI_SYSTEM_TABLE *SystemTable
- )
+{
- EFI_STATUS Status;
- UINTN PpaRamAddr;
- ARM_MEMORY_REGION_DESCRIPTOR *MemoryTable;
- PpaRamAddr = GetPpaImagefromFlash();
- Status = PpaInit(PpaRamAddr);
- ArmPlatformGetVirtualMemoryMap (&MemoryTable);
- InitMmu(MemoryTable);
I won't comment on every missing space before function name and opening (, but please add here to keep it consistent.
- return Status;
+} diff --git a/Chips/Nxp/QoriqLs/PpaInitDxe/PpaInitDxe.inf b/Chips/Nxp/QoriqLs/PpaInitDxe/PpaInitDxe.inf new file mode 100644 index 0000000..80f9cb0 --- /dev/null +++ b/Chips/Nxp/QoriqLs/PpaInitDxe/PpaInitDxe.inf @@ -0,0 +1,63 @@ +#/** PpaInitDxe.inf +# +# Component description file for Ppa Initialization driver +# +# Copyright (c) 2016, Freescale Semiconductor, Inc. All rights reserved. +# +# This program and the accompanying materials +# are licensed and made available under the terms and conditions of the BSD License +# which accompanies this distribution. The full text of the license may be found at +# http://opensource.org/licenses/bsd-license.php +# +# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, +# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. +# +# +#**/
+[Defines]
- INF_VERSION = 0x00010005
- BASE_NAME = PpaInit
- FILE_GUID = 4d00ef14-c4e0-426b-81b7-30a00a14abb6
- MODULE_TYPE = DXE_DRIVER
- VERSION_STRING = 1.0
- ENTRY_POINT = PpaInitialize
+[Sources.common]
- PpaInit.c
- PpaInitHelper.S
- PpaItbParse.c
+[Packages]
- MdePkg/MdePkg.dec
- ArmPkg/ArmPkg.dec
- ArmPlatformPkg/ArmPlatformPkg.dec
- EmbeddedPkg/EmbeddedPkg.dec
- OpenPlatformPkg/Chips/Nxp/QoriqLs/NxpQoriqLs.dec
+[LibraryClasses]
- BaseLib
- UefiLib
- UefiDriverEntryPoint
- MemoryInitPeiLib
- ArmLib
- BdsLib
- FdtLib
+[Guids]
+[Protocols]
+[Pcd]
- gArmTokenSpaceGuid.PcdSystemMemoryBase
- gArmTokenSpaceGuid.PcdSystemMemorySize
- gNxpQoriqLsTokenSpaceGuid.PcdPpaNorBaseAddr
- gNxpQoriqLsTokenSpaceGuid.PcdPpaDdrOffsetAddr
- gNxpQoriqLsTokenSpaceGuid.PcdPpaFitConfiguration
Please sort alpabetically above.
+[FixedPcd]
+[depex]
- TRUE
diff --git a/Chips/Nxp/QoriqLs/PpaInitDxe/PpaInitHelper.S b/Chips/Nxp/QoriqLs/PpaInitDxe/PpaInitHelper.S new file mode 100644 index 0000000..237015c --- /dev/null +++ b/Chips/Nxp/QoriqLs/PpaInitDxe/PpaInitHelper.S @@ -0,0 +1,79 @@ +# @PpaInitHelper.S +# +# Copyright (c) 2016, Freescale Semiconductor, Inc. All rights +# reserved. +# +# This program and the accompanying materials +# are licensed and made available under the terms and conditions of the BSD License +# which accompanies this distribution. The full text of the license may be found at +# http://opensource.org/licenses/bsd-license.php +# +# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, +# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. +# +# +#include <AutoGen.h>
Huh? Why include this file?
+.text +.align 2
+GCC_ASM_EXPORT(PpaInit) +GCC_ASM_EXPORT(El2SwitchSetup)
+ASM_PFX(PpaInit): +//Push return address to the stack +//sub sp, sp, #16 +//stur x30, [sp, #0]
Please no commented out code. Delete it if not used.
+//Save stack pointer for EL2
- mov x1, sp
- msr sp_el2, x1
+//Set boot loc pointer
- adr x4, 1f
- adr x1, ADDR_BASE_SCFG
- ldr w2, [x1]
- mov x1, x4
- rev w3, w1
- str w3, [x2, #0x604]
- lsr x1, x4, #32
- rev w3, w1
- str w3, [x2, #0x600]
+//Call PPA monitor
- br x0
+1: +//Pop out return address from stack +//ldur x30, [sp, #0] +//add sp, sp, #16
Delete.
- // Enable GICv2 interrupts in EL2 mode
- mrs x0, hcr_el2
- orr x0, x0, #0x18
- msr hcr_el2, x0
+//return 0
- mov x0, #0
- ret
+ASM_PFX(El2SwitchSetup):
- mov x0, #0x5b1 // non-secure el0/el1 | hvc | 64bit el2
- msr scr_el3, x0
- msr cptr_el3, xzr // disable coprocessor traps to el3
- mov x0, #0x33ff
- msr cptr_el2, x0 // disable coprocessor traps to el2
- // initialize sctlr_el2
- msr sctlr_el2, xzr
- mov x0, #0x3c9
- msr spsr_el3, x0 // el2_sp2 | d | a | i | f
- ret
+ADDR_BASE_SCFG:
- .long 0x01570000
+ADDR_BASE_DCFG:
- .long 0x01EE0000
+ASM_FUNCTION_REMOVE_IF_UNREFERENCED diff --git a/Chips/Nxp/QoriqLs/PpaInitDxe/PpaItbParse.c b/Chips/Nxp/QoriqLs/PpaInitDxe/PpaItbParse.c new file mode 100755 index 0000000..9e6a477 --- /dev/null +++ b/Chips/Nxp/QoriqLs/PpaInitDxe/PpaItbParse.c @@ -0,0 +1,144 @@ +#include <libfdt.h> +#include <Library/DebugLib.h>
+#include "PpaItbParse.h"
+EFI_STATUS +FitCheckHeader(
- EFI_PHYSICAL_ADDRESS FitImage
+) +{
- if(fdt_check_header((VOID*) FitImage)) {
DEBUG((EFI_D_ERROR, "bad FIT header\n"));
return EFI_UNSUPPORTED;
- }
- /* mandatory / node 'description' property */
- if (fdt_getprop((VOID*)FitImage, 0, FIT_DESC_PROP, NULL) == NULL) {
DEBUG((EFI_D_ERROR, "Wrong FIT format: no description\n"));
return EFI_UNSUPPORTED;
- }
- /* mandatory subimages parent '/images' node */
- if (fdt_path_offset((VOID*)FitImage, FIT_IMAGES_PATH) < 0) {
DEBUG((EFI_D_ERROR, "Wrong FIT format: no images parent node\n"));
return EFI_UNSUPPORTED;
- }
- return EFI_SUCCESS;
+}
+EFI_STATUS +FitGetConfNode (
- EFI_PHYSICAL_ADDRESS FitImage,
- VOID* ConfigPtr,
- INT32* NodeOffset
+) +{
- INT32 noffset, confs_noffset;
- INT32 len;
- char* ConfigName;
CHAR8
- confs_noffset = fdt_path_offset((VOID*)FitImage, FIT_CONFS_PATH);
- if (confs_noffset < 0) {
- DEBUG((EFI_D_ERROR, "Can't find configurations parent node '%s' (%s)\n",
FIT_CONFS_PATH, fdt_strerror(confs_noffset)));
- return EFI_UNSUPPORTED;
- }
- ConfigName = (char*)ConfigPtr;
CHAR8
- if(ConfigName && *ConfigName == '\0')
- ConfigName = NULL;
- if (ConfigName == NULL) {
/* get configuration unit name from the default property
* */
- DEBUG((EFI_D_ERROR, "No configuration specified, trying default...\n"));
- ConfigName = (CHAR8 *)fdt_getprop((VOID*)FitImage, confs_noffset,
FIT_DEFAULT_PROP, &len);
- }
- noffset = fdt_subnode_offset((VOID*)FitImage, confs_noffset, ConfigName);
- if (noffset < 0) {
DEBUG((EFI_D_ERROR,
"Can't get node offset for configuration unit name: '%s' (%s)\n",
ConfigName, fdt_strerror(noffset)));
return EFI_UNSUPPORTED;
- }
- *NodeOffset = noffset;
- return EFI_SUCCESS;
+}
+EFI_STATUS +FitGetNodeFromConf (
- EFI_PHYSICAL_ADDRESS FitImage,
- INT32 CfgNodeOffset,
- CHAR8* ConfPropName,
- INT32* NodeOffset
+) +{
- INT32 noffset, len, img_noffset;
- CHAR8* PropName;
- PropName = (char *)fdt_getprop((VOID*)FitImage, CfgNodeOffset,
CHAR8
ConfPropName, &len);
- if (PropName == NULL) {
return EFI_UNSUPPORTED;
- }
- img_noffset = fdt_path_offset((VOID*)FitImage, FIT_IMAGES_PATH);
- if (img_noffset < 0) {
return EFI_UNSUPPORTED;
- }
- noffset = fdt_subnode_offset((VOID*)FitImage, img_noffset, PropName);
- if (noffset < 0) {
return EFI_UNSUPPORTED;
- }
- *NodeOffset = noffset;
- return EFI_SUCCESS;
+}
+EFI_STATUS +FitGetNodeData (
- EFI_PHYSICAL_ADDRESS FitImage,
- INT32 NodeOffset,
These parameter names need aligning (and it's not just the tabs here).
- EFI_PHYSICAL_ADDRESS* Addr,
- INT32* Size
+) +{
- VOID *Data;
- Data = (VOID*)fdt_getprop((VOID*)FitImage, NodeOffset, FIT_IMAGE_DATA, Size);
- if(Data == NULL) {
Space after if (please address globally).
return EFI_UNSUPPORTED;
- }
- *Addr = (EFI_PHYSICAL_ADDRESS)Data;
- return EFI_SUCCESS;
+}
+EFI_STATUS +FitGetNodeLoad (
- EFI_PHYSICAL_ADDRESS FitImage,
- INT32 NodeOffset,
- EFI_PHYSICAL_ADDRESS* Addr
+) +{
- INT32 Size;
- VOID* Load;
- Load = (VOID*)fdt_getprop((VOID*)FitImage, NodeOffset, FIT_IMAGE_LOAD, &Size);
- if(Load == NULL) {
return EFI_UNSUPPORTED;
- }
- if(Size == 4)
And braces on all if/else please (globally).
*Addr = MmioReadBe32((UINTN) Load);
- else if(Size == 8)
*Addr = MmioReadBe64((UINTN) Load);
- else {
return EFI_UNSUPPORTED;
- }
- return EFI_SUCCESS;
+} diff --git a/Chips/Nxp/QoriqLs/PpaInitDxe/PpaItbParse.h b/Chips/Nxp/QoriqLs/PpaInitDxe/PpaItbParse.h new file mode 100755 index 0000000..a6f78c0 --- /dev/null +++ b/Chips/Nxp/QoriqLs/PpaInitDxe/PpaItbParse.h @@ -0,0 +1,52 @@ +#ifndef __PPA_ITB_PARSE__ +#define __PPA_ITB_PARSE__
+#include <Library/IoLib.h>
+#define FIT_DESC_PROP "description" +#define FIT_IMAGES_PATH "/images" +#define FIT_KERNEL_IMAGE "kernel" +#define FIT_INITRD_IMAGE "ramdisk" +#define FIT_FIRMWARE_IMAGE "firmware" +#define FIT_FDT_IMAGE "fdt" +#define FIT_CONFS_PATH "/configurations" +#define FIT_DEFAULT_PROP "default" +#define FIT_IMAGE_DATA "data" +#define FIT_IMAGE_LOAD "load"
Is there any logical ordering of the above that makes more sense than alphabetical? If not, can these be sorted please?
+EFI_STATUS +FitCheckHeader(
- EFI_PHYSICAL_ADDRESS FitImage
+);
+EFI_STATUS +FitGetConfNode (
- EFI_PHYSICAL_ADDRESS FitImage,
- VOID* ConfigPtr,
- INT32* NodeOffset
+);
+EFI_STATUS +FitGetNodeFromConf (
- EFI_PHYSICAL_ADDRESS FitImage,
- INT32 CfgNodeOffset,
- CHAR8* ConfPropName,
- INT32* NodeOffset
+);
+EFI_STATUS +FitGetNodeData (
- EFI_PHYSICAL_ADDRESS FitImage,
- INT32 NodeOffset,
- EFI_PHYSICAL_ADDRESS* Addr,
- INT32* Size
+);
+EFI_STATUS +FitGetNodeLoad (
- EFI_PHYSICAL_ADDRESS FitImage,
- INT32 NodeOffset,
- EFI_PHYSICAL_ADDRESS* Addr
+);
+#endif
1.9.1
Hi Leif,
From: Leif Lindholm [mailto:leif.lindholm@linaro.org] Sent: Saturday, November 05, 2016 4:52 AM
On Tue, Oct 18, 2016 at 01:34:10AM +0530, Bhupesh Sharma wrote:
From: Sakar Arora sakar.arora@nxp.com
NXP/FSL ARMv8 SoCs currently use a EL3 platform and run-time security firmware which is called PPA (Primary Protected Application).
This firmware is placed on the flash device and is loaded into DDR
and
executed via a UEFI DXE driver. PPA does the initial platform EL3 settings and then returns the control back to UEFI in EL2 exception level.
Later implementations of PPA will allow it to start by itself in the EL3 level and start UEFI in EL2 exception level.
This patch adds the PPA load and execution handlers.
Again, excellent commit message.
Signed-off-by: Sakar Arora sakar.arora@nxp.com Signed-off-by: Bhupesh Sharma bhupesh.sharma@nxp.com
Chips/Nxp/QoriqLs/PpaInitDxe/PpaInit.c | 117
++++++++++++++++++++++
Chips/Nxp/QoriqLs/PpaInitDxe/PpaInitDxe.inf | 63 ++++++++++++ Chips/Nxp/QoriqLs/PpaInitDxe/PpaInitHelper.S | 79 +++++++++++++++ Chips/Nxp/QoriqLs/PpaInitDxe/PpaItbParse.c | 144
+++++++++++++++++++++++++++
Chips/Nxp/QoriqLs/PpaInitDxe/PpaItbParse.h | 52 ++++++++++ 5 files changed, 455 insertions(+) create mode 100644 Chips/Nxp/QoriqLs/PpaInitDxe/PpaInit.c create mode 100644 Chips/Nxp/QoriqLs/PpaInitDxe/PpaInitDxe.inf create mode 100644 Chips/Nxp/QoriqLs/PpaInitDxe/PpaInitHelper.S create mode 100755 Chips/Nxp/QoriqLs/PpaInitDxe/PpaItbParse.c create mode 100755 Chips/Nxp/QoriqLs/PpaInitDxe/PpaItbParse.h
diff --git a/Chips/Nxp/QoriqLs/PpaInitDxe/PpaInit.c b/Chips/Nxp/QoriqLs/PpaInitDxe/PpaInit.c new file mode 100644 index 0000000..4e4cedb --- /dev/null +++ b/Chips/Nxp/QoriqLs/PpaInitDxe/PpaInit.c @@ -0,0 +1,117 @@ +/** @file +# +# DXE driver for loading Primary Protected Application # # +Copyright (c) 2016, Freescale Semiconductor, Inc. All rights
reserved.
+# +# This program and the accompanying materials # are licensed and +made available under the terms and conditions of the BSD License # +which accompanies this distribution. The full text of the license +may be found at # http://opensource.org/licenses/bsd-license.php +# +# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" +BASIS, # WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER
EXPRESS OR IMPLIED.
+# +**/
+#include <Chipset/AArch64.h> +#include <Library/ArmPlatformLib.h> +#include <Library/PcdLib.h> +#include <Library/DebugLib.h> +#include <Library/IoLib.h> +#include <Library/PrintLib.h> +#include <Library/MemoryAllocationLib.h> #include +<Library/BaseMemoryLib/MemLibInternals.h> +#include "PpaItbParse.h"
Please sort alphabetically.
Sure.
+extern EFI_STATUS PpaInit(UINT64); +extern VOID InitMmu(ARM_MEMORY_REGION_DESCRIPTOR*);
These should be pulled in from an include file.
Ok.
+/**
- Copying PPA firmware to DDR
- */
+VOID +CopyPpaImage (
- const char *title,
- UINTN image_addr,
- UINTN image_size,
- UINTN PpaRamAddr)
+{
- DEBUG((EFI_D_INFO, "%a copied to address 0x%x\n", title,
+PpaRamAddr));
- InternalMemCopyMem((void *)PpaRamAddr, (void *)image_addr,
+image_size); }
+UINTN +GetPpaImagefromFlash (
- VOID
- )
+{
- EFI_STATUS Status;
- EFI_PHYSICAL_ADDRESS FitImage;
- EFI_PHYSICAL_ADDRESS PpaImage;
- INT32 CfgNodeOffset;
- INT32 NodeOffset;
- INT32 PpaImageSize;
- UINTN PpaRamAddr;
- // Assuming that the PPA FW is present on NOR flash
- // FIXME: Add support for other flash devices.
No FIXME please.
Ok :)
- FitImage = PcdGet64 (PcdPpaNorBaseAddr);
- // PPA will be placed on DDR at this address:
- // Top of DDR - PcdPpaDdrOffsetAddr
- PpaRamAddr = PcdGet64 (PcdSystemMemoryBase) + PcdGet64
(PcdSystemMemorySize)
- PcdGet64 (PcdPpaDdrOffsetAddr);
- Status = FitCheckHeader(FitImage);
- if (EFI_ERROR (Status)) {
DEBUG((EFI_D_ERROR, "Bad FIT image header (0x%x).\n",
Status));
goto EXIT_FREE_FIT;
- }
- Status = FitGetConfNode(FitImage, (void
*)(PcdGetPtr(PcdPpaFitConfiguration)), &CfgNodeOffset);
- if (EFI_ERROR (Status)) {
DEBUG((EFI_D_ERROR, "Did not find configuration node in FIT
header (0x%x).\n", Status));
goto EXIT_FREE_FIT;
- }
- Status = FitGetNodeFromConf(FitImage, CfgNodeOffset,
FIT_FIRMWARE_IMAGE, &NodeOffset);
- if (EFI_ERROR (Status)) {
DEBUG((EFI_D_ERROR, "Did not find PPA node in FIT header
(0x%x).\n", Status));
goto EXIT_FREE_FIT;
- }
- Status = FitGetNodeData(FitImage, NodeOffset, (VOID*)&PpaImage,
&PpaImageSize);
- if (EFI_ERROR (Status)) {
DEBUG((EFI_D_ERROR, "Did not find PPA f/w in FIT image
(0x%x).\n", Status));
goto EXIT_FREE_FIT;
- }
- CopyPpaImage ("PPA Firmware", PpaImage, PpaImageSize,
PpaRamAddr);
- return PpaRamAddr;
+EXIT_FREE_FIT:
- // Flow should never reach here
- ASSERT (Status == EFI_SUCCESS);
- return 0;
+}
+EFI_STATUS +PpaInitialize (
- IN EFI_HANDLE ImageHandle,
- IN EFI_SYSTEM_TABLE *SystemTable
- )
+{
- EFI_STATUS Status;
- UINTN PpaRamAddr;
- ARM_MEMORY_REGION_DESCRIPTOR *MemoryTable;
- PpaRamAddr = GetPpaImagefromFlash();
- Status = PpaInit(PpaRamAddr);
- ArmPlatformGetVirtualMemoryMap (&MemoryTable);
- InitMmu(MemoryTable);
I won't comment on every missing space before function name and opening (, but please add here to keep it consistent.
Sure.
- return Status;
+} diff --git a/Chips/Nxp/QoriqLs/PpaInitDxe/PpaInitDxe.inf b/Chips/Nxp/QoriqLs/PpaInitDxe/PpaInitDxe.inf new file mode 100644 index 0000000..80f9cb0 --- /dev/null +++ b/Chips/Nxp/QoriqLs/PpaInitDxe/PpaInitDxe.inf @@ -0,0 +1,63 @@ +#/** PpaInitDxe.inf +# +# Component description file for Ppa Initialization driver # # +Copyright (c) 2016, Freescale Semiconductor, Inc. All rights
reserved.
+# +# This program and the accompanying materials # are licensed and +made available under the terms and conditions of the BSD License # +which accompanies this distribution. The full text of the license +may be found at # http://opensource.org/licenses/bsd-license.php +# +# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" +BASIS, # WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER
EXPRESS OR IMPLIED.
+# +# +#**/
+[Defines]
- INF_VERSION = 0x00010005
- BASE_NAME = PpaInit
- FILE_GUID = 4d00ef14-c4e0-426b-81b7-
30a00a14abb6
- MODULE_TYPE = DXE_DRIVER
- VERSION_STRING = 1.0
- ENTRY_POINT = PpaInitialize
+[Sources.common]
- PpaInit.c
- PpaInitHelper.S
- PpaItbParse.c
+[Packages]
- MdePkg/MdePkg.dec
- ArmPkg/ArmPkg.dec
- ArmPlatformPkg/ArmPlatformPkg.dec
- EmbeddedPkg/EmbeddedPkg.dec
- OpenPlatformPkg/Chips/Nxp/QoriqLs/NxpQoriqLs.dec
+[LibraryClasses]
- BaseLib
- UefiLib
- UefiDriverEntryPoint
- MemoryInitPeiLib
- ArmLib
- BdsLib
- FdtLib
+[Guids]
+[Protocols]
+[Pcd]
- gArmTokenSpaceGuid.PcdSystemMemoryBase
- gArmTokenSpaceGuid.PcdSystemMemorySize
- gNxpQoriqLsTokenSpaceGuid.PcdPpaNorBaseAddr
- gNxpQoriqLsTokenSpaceGuid.PcdPpaDdrOffsetAddr
- gNxpQoriqLsTokenSpaceGuid.PcdPpaFitConfiguration
Please sort alpabetically above.
Ok.
+[FixedPcd]
+[depex]
- TRUE
diff --git a/Chips/Nxp/QoriqLs/PpaInitDxe/PpaInitHelper.S b/Chips/Nxp/QoriqLs/PpaInitDxe/PpaInitHelper.S new file mode 100644 index 0000000..237015c --- /dev/null +++ b/Chips/Nxp/QoriqLs/PpaInitDxe/PpaInitHelper.S @@ -0,0 +1,79 @@ +# @PpaInitHelper.S +# +# Copyright (c) 2016, Freescale Semiconductor, Inc. All rights # +reserved. +# +# This program and the accompanying materials # are licensed and +made available under the terms and conditions of the BSD License # +which accompanies this distribution. The full text of the license +may be found at # http://opensource.org/licenses/bsd-license.php +# +# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" +BASIS, # WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER
EXPRESS OR IMPLIED.
+# +# +#include <AutoGen.h>
Huh? Why include this file?
Ok, will remove this.
+.text +.align 2
+GCC_ASM_EXPORT(PpaInit) +GCC_ASM_EXPORT(El2SwitchSetup)
+ASM_PFX(PpaInit): +//Push return address to the stack +//sub sp, sp, #16 +//stur x30, [sp, #0]
Please no commented out code. Delete it if not used.
Will fix in V2.
+//Save stack pointer for EL2
- mov x1, sp
- msr sp_el2, x1
+//Set boot loc pointer
- adr x4, 1f
- adr x1, ADDR_BASE_SCFG
- ldr w2, [x1]
- mov x1, x4
- rev w3, w1
- str w3, [x2, #0x604]
- lsr x1, x4, #32
- rev w3, w1
- str w3, [x2, #0x600]
+//Call PPA monitor
- br x0
+1: +//Pop out return address from stack +//ldur x30, [sp, #0] +//add sp, sp, #16
Delete.
Ok.
- // Enable GICv2 interrupts in EL2 mode
- mrs x0, hcr_el2
- orr x0, x0, #0x18
- msr hcr_el2, x0
+//return 0
- mov x0, #0
- ret
+ASM_PFX(El2SwitchSetup):
- mov x0, #0x5b1 // non-secure el0/el1 | hvc | 64bit el2
- msr scr_el3, x0
- msr cptr_el3, xzr // disable coprocessor traps to el3
- mov x0, #0x33ff
- msr cptr_el2, x0 // disable coprocessor traps to el2
- // initialize sctlr_el2
- msr sctlr_el2, xzr
- mov x0, #0x3c9
- msr spsr_el3, x0 // el2_sp2 | d | a | i | f
- ret
+ADDR_BASE_SCFG:
- .long 0x01570000
+ADDR_BASE_DCFG:
- .long 0x01EE0000
+ASM_FUNCTION_REMOVE_IF_UNREFERENCED diff --git a/Chips/Nxp/QoriqLs/PpaInitDxe/PpaItbParse.c b/Chips/Nxp/QoriqLs/PpaInitDxe/PpaItbParse.c new file mode 100755 index 0000000..9e6a477 --- /dev/null +++ b/Chips/Nxp/QoriqLs/PpaInitDxe/PpaItbParse.c @@ -0,0 +1,144 @@ +#include <libfdt.h> +#include <Library/DebugLib.h>
+#include "PpaItbParse.h"
+EFI_STATUS +FitCheckHeader(
- EFI_PHYSICAL_ADDRESS FitImage
+) +{
- if(fdt_check_header((VOID*) FitImage)) {
DEBUG((EFI_D_ERROR, "bad FIT header\n"));
return EFI_UNSUPPORTED;
- }
- /* mandatory / node 'description' property */
- if (fdt_getprop((VOID*)FitImage, 0, FIT_DESC_PROP, NULL) == NULL)
{
DEBUG((EFI_D_ERROR, "Wrong FIT format: no description\n"));
return EFI_UNSUPPORTED;
- }
- /* mandatory subimages parent '/images' node */
- if (fdt_path_offset((VOID*)FitImage, FIT_IMAGES_PATH) < 0) {
DEBUG((EFI_D_ERROR, "Wrong FIT format: no images parent
node\n"));
return EFI_UNSUPPORTED;
- }
- return EFI_SUCCESS;
+}
+EFI_STATUS +FitGetConfNode (
- EFI_PHYSICAL_ADDRESS FitImage,
- VOID* ConfigPtr,
- INT32* NodeOffset
+) +{
- INT32 noffset, confs_noffset;
- INT32 len;
- char* ConfigName;
CHAR8
- confs_noffset = fdt_path_offset((VOID*)FitImage, FIT_CONFS_PATH);
- if (confs_noffset < 0) {
- DEBUG((EFI_D_ERROR, "Can't find configurations parent node '%s'
(%s)\n",
FIT_CONFS_PATH, fdt_strerror(confs_noffset)));
- return EFI_UNSUPPORTED;
- }
- ConfigName = (char*)ConfigPtr;
CHAR8
Ok.
- if(ConfigName && *ConfigName == '\0')
- ConfigName = NULL;
- if (ConfigName == NULL) {
/* get configuration unit name from the default property
* */
- DEBUG((EFI_D_ERROR, "No configuration specified, trying
default...\n"));
- ConfigName = (CHAR8 *)fdt_getprop((VOID*)FitImage,
confs_noffset,
FIT_DEFAULT_PROP, &len);
- }
- noffset = fdt_subnode_offset((VOID*)FitImage, confs_noffset,
ConfigName);
- if (noffset < 0) {
DEBUG((EFI_D_ERROR,
"Can't get node offset for configuration unit name: '%s'
(%s)\n",
ConfigName, fdt_strerror(noffset)));
return EFI_UNSUPPORTED;
- }
- *NodeOffset = noffset;
- return EFI_SUCCESS;
+}
+EFI_STATUS +FitGetNodeFromConf (
- EFI_PHYSICAL_ADDRESS FitImage,
- INT32 CfgNodeOffset,
- CHAR8* ConfPropName,
- INT32* NodeOffset
+) +{
- INT32 noffset, len, img_noffset;
- CHAR8* PropName;
- PropName = (char *)fdt_getprop((VOID*)FitImage, CfgNodeOffset,
CHAR8
ConfPropName, &len);
- if (PropName == NULL) {
return EFI_UNSUPPORTED;
- }
- img_noffset = fdt_path_offset((VOID*)FitImage, FIT_IMAGES_PATH);
- if (img_noffset < 0) {
return EFI_UNSUPPORTED;
- }
- noffset = fdt_subnode_offset((VOID*)FitImage, img_noffset,
PropName);
- if (noffset < 0) {
return EFI_UNSUPPORTED;
- }
- *NodeOffset = noffset;
- return EFI_SUCCESS;
+}
+EFI_STATUS +FitGetNodeData (
- EFI_PHYSICAL_ADDRESS FitImage,
- INT32 NodeOffset,
These parameter names need aligning (and it's not just the tabs here).
Ok.
- EFI_PHYSICAL_ADDRESS* Addr,
- INT32* Size
+) +{
- VOID *Data;
- Data = (VOID*)fdt_getprop((VOID*)FitImage, NodeOffset,
FIT_IMAGE_DATA, Size);
- if(Data == NULL) {
Space after if (please address globally).
Ok.
return EFI_UNSUPPORTED;
- }
- *Addr = (EFI_PHYSICAL_ADDRESS)Data;
- return EFI_SUCCESS;
+}
+EFI_STATUS +FitGetNodeLoad (
- EFI_PHYSICAL_ADDRESS FitImage,
- INT32 NodeOffset,
- EFI_PHYSICAL_ADDRESS* Addr
+) +{
- INT32 Size;
- VOID* Load;
- Load = (VOID*)fdt_getprop((VOID*)FitImage, NodeOffset,
FIT_IMAGE_LOAD, &Size);
- if(Load == NULL) {
return EFI_UNSUPPORTED;
- }
- if(Size == 4)
And braces on all if/else please (globally).
Ok. Was following the conventional Linux style of not having braces for single line of execution, but we can change that in V2.
*Addr = MmioReadBe32((UINTN) Load);
- else if(Size == 8)
*Addr = MmioReadBe64((UINTN) Load);
- else {
return EFI_UNSUPPORTED;
- }
- return EFI_SUCCESS;
+} diff --git a/Chips/Nxp/QoriqLs/PpaInitDxe/PpaItbParse.h b/Chips/Nxp/QoriqLs/PpaInitDxe/PpaItbParse.h new file mode 100755 index 0000000..a6f78c0 --- /dev/null +++ b/Chips/Nxp/QoriqLs/PpaInitDxe/PpaItbParse.h @@ -0,0 +1,52 @@ +#ifndef __PPA_ITB_PARSE__ +#define __PPA_ITB_PARSE__
+#include <Library/IoLib.h>
+#define FIT_DESC_PROP "description" +#define FIT_IMAGES_PATH "/images" +#define FIT_KERNEL_IMAGE "kernel" +#define FIT_INITRD_IMAGE "ramdisk" +#define FIT_FIRMWARE_IMAGE "firmware" +#define FIT_FDT_IMAGE "fdt" +#define FIT_CONFS_PATH "/configurations" +#define FIT_DEFAULT_PROP "default" +#define FIT_IMAGE_DATA "data" +#define FIT_IMAGE_LOAD "load"
Is there any logical ordering of the above that makes more sense than alphabetical? If not, can these be sorted please?
Sure.
+EFI_STATUS +FitCheckHeader(
- EFI_PHYSICAL_ADDRESS FitImage
+);
+EFI_STATUS +FitGetConfNode (
- EFI_PHYSICAL_ADDRESS FitImage,
- VOID* ConfigPtr,
- INT32* NodeOffset
+);
+EFI_STATUS +FitGetNodeFromConf (
- EFI_PHYSICAL_ADDRESS FitImage,
- INT32
CfgNodeOffset,
- CHAR8*
ConfPropName,
- INT32* NodeOffset
+);
+EFI_STATUS +FitGetNodeData (
- EFI_PHYSICAL_ADDRESS FitImage,
- INT32 NodeOffset,
- EFI_PHYSICAL_ADDRESS* Addr,
- INT32* Size
+);
+EFI_STATUS +FitGetNodeLoad (
- EFI_PHYSICAL_ADDRESS FitImage,
- INT32 NodeOffset,
- EFI_PHYSICAL_ADDRESS* Addr
+);
+#endif
1.9.1
From: Sakar Arora sakar.arora@nxp.com
NXP/FSL LS1043A-RDB board has a on-board RTC clock chip (DS1407), which sits over the I2C bus.
This patch adds the support for this on-board RTC chip via a library which provides real time clock APIs on top of I2C APIs
Signed-off-by: Sakar Arora sakar.arora@nxp.com Signed-off-by: Bhupesh Sharma bhupesh.sharma@nxp.com --- .../QoriqLs/Library/Ds1307RtcLib/Ds1307RtcLib.c | 250 +++++++++++++++++++++ .../QoriqLs/Library/Ds1307RtcLib/Ds1307RtcLib.inf | 44 ++++ 2 files changed, 294 insertions(+) create mode 100644 Chips/Nxp/QoriqLs/Library/Ds1307RtcLib/Ds1307RtcLib.c create mode 100644 Chips/Nxp/QoriqLs/Library/Ds1307RtcLib/Ds1307RtcLib.inf
diff --git a/Chips/Nxp/QoriqLs/Library/Ds1307RtcLib/Ds1307RtcLib.c b/Chips/Nxp/QoriqLs/Library/Ds1307RtcLib/Ds1307RtcLib.c new file mode 100644 index 0000000..85fe564 --- /dev/null +++ b/Chips/Nxp/QoriqLs/Library/Ds1307RtcLib/Ds1307RtcLib.c @@ -0,0 +1,250 @@ +/** @Ds1307RtcLib.c + Implement EFI RealTimeClock with runtime services via RTC Lib for DS1307 RTC. + + Based on RTC implementation available in + EmbeddedPkg/Library/TemplateRealTimeClockLib/RealTimeClockLib.c + + Copyright (c) 2008 - 2009, Apple Inc. All rights reserved.<BR> + Copyright (c) 2016, Freescale Semiconductor, Inc. All rights reserved. + + This program and the accompanying materials + are licensed and made available under the terms and conditions of the BSD License + which accompanies this distribution. The full text of the license may be found at + http://opensource.org/licenses/bsd-license.php + + THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, + WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. + +**/ + +#include <PiDxe.h> +#include <Library/BaseLib.h> +#include <Library/DebugLib.h> +#include <Library/IoLib.h> +#include <Library/RealTimeClockLib.h> +#include <Library/I2c.h> + + +#define Bin(Bcd) ((Bcd) & 0x0f) + ((Bcd) >> 4) * 10 +#define Bcd(Bin) (((Bin / 10) << 4) | (Bin % 10)) + + +/* + * RTC register addresses + */ +#define DS1307_SEC_REG_ADDR 0x00 +#define DS1307_MIN_REG_ADDR 0x01 +#define DS1307_HR_REG_ADDR 0x02 +#define DS1307_DAY_REG_ADDR 0x03 +#define DS1307_DATE_REG_ADDR 0x04 +#define DS1307_MON_REG_ADDR 0x05 +#define DS1307_YR_REG_ADDR 0x06 +#define DS1307_CTL_REG_ADDR 0x07 + +#define DS1307_SEC_BIT_CH 0x80 /* Clock Halt (in Register 0) */ + +#define DS1307_CTL_BIT_RS0 0x01 /* Rate select 0 */ +#define DS1307_CTL_BIT_RS1 0x02 /* Rate select 1 */ +#define DS1307_CTL_BIT_SQWE 0x10 /* Square Wave Enable */ +#define DS1307_CTL_BIT_OUT 0x80 /* Output Control */ + +UINT8 RtcRead( + UINT8 RtcRegAddr +) +{ + INT32 Status; + UINT8 Val = 0; + Status = I2cDataRead(PcdGet32(PcdRtcI2cBus), PcdGet32(PcdDs1307I2cAddress), RtcRegAddr, 0x1, &Val, sizeof(Val)); + if(EFI_ERROR(Status)) + DEBUG((EFI_D_ERROR, "RTC read error at Addr:0x%x\n", RtcRegAddr)); + return Val; +} + +VOID RtcWrite( + UINT8 RtcRegAddr, + UINT8 Val) +{ + INT32 Status; + Status = I2cDataWrite(PcdGet32(PcdRtcI2cBus), PcdGet32(PcdDs1307I2cAddress), RtcRegAddr, 0x1, &Val, sizeof(Val)); + if(EFI_ERROR(Status)) + DEBUG((EFI_D_ERROR, "RTC write error at Addr:0x%x\n", RtcRegAddr)); + +} + +/** + Returns the current time and date information, and the time-keeping capabilities + of the hardware platform. + + @param Time A pointer to storage to receive a snapshot of the current time. + @param Capabilities An optional pointer to a buffer to receive the real time clock + device's capabilities. + + @retval EFI_SUCCESS The operation completed successfully. + @retval EFI_INVALID_PARAMETER Time is NULL. + @retval EFI_DEVICE_ERROR The time could not be retrieved due to hardware error. + +**/ + +EFI_STATUS +EFIAPI +LibGetTime ( + OUT EFI_TIME *Time, + OUT EFI_TIME_CAPABILITIES *Capabilities + ) +{ + EFI_STATUS Status = EFI_SUCCESS; + CHAR16 Second, Minute, Hour, Day, Month, Year; + + Second = RtcRead (DS1307_SEC_REG_ADDR); + Minute = RtcRead (DS1307_MIN_REG_ADDR); + Hour = RtcRead (DS1307_HR_REG_ADDR); + Day = RtcRead (DS1307_DATE_REG_ADDR); + Month = RtcRead (DS1307_MON_REG_ADDR); + Year = RtcRead (DS1307_YR_REG_ADDR); + + if (Second & DS1307_SEC_BIT_CH) { + DEBUG((EFI_D_ERROR, "### Warning: RTC oscillator has stopped\n")); + /* clear the CH flag */ + RtcWrite (DS1307_SEC_REG_ADDR, + RtcRead (DS1307_SEC_REG_ADDR) & ~DS1307_SEC_BIT_CH); + Status = EFI_DEVICE_ERROR; + } + + Time->Second = Bin (Second & 0x7F); + Time->Minute = Bin (Minute & 0x7F); + Time->Hour = Bin (Hour & 0x3F); + Time->Day = Bin (Day & 0x3F); + Time->Month = Bin (Month & 0x1F); + Time->Year = Bin (Year) + ( Bin (Year) >= 70 ? 1900 : 2000); + + return Status; +} + + +/** + Sets the current local time and date information. + + @param Time A pointer to the current time. + + @retval EFI_SUCCESS The operation completed successfully. + @retval EFI_INVALID_PARAMETER A time field is out of range. + @retval EFI_DEVICE_ERROR The time could not be set due due to hardware error. + +**/ +EFI_STATUS +EFIAPI +LibSetTime ( + IN EFI_TIME *Time + ) +{ + if (Time->Year < 1970 || Time->Year > 2069) + DEBUG((EFI_D_ERROR, "WARNING: Year should be between 1970 and 2069!\n")); + + RtcWrite (DS1307_YR_REG_ADDR, Bcd (Time->Year % 100)); + RtcWrite (DS1307_MON_REG_ADDR, Bcd (Time->Month)); + RtcWrite (DS1307_DATE_REG_ADDR, Bcd (Time->Day)); + RtcWrite (DS1307_HR_REG_ADDR, Bcd (Time->Hour)); + RtcWrite (DS1307_MIN_REG_ADDR, Bcd (Time->Minute)); + RtcWrite (DS1307_SEC_REG_ADDR, Bcd (Time->Second)); + + return EFI_SUCCESS; +} + + +/** + Returns the current wakeup alarm clock setting. + + @param Enabled Indicates if the alarm is currently enabled or disabled. + @param Pending Indicates if the alarm signal is pending and requires acknowledgement. + @param Time The current alarm setting. + + @retval EFI_SUCCESS The alarm settings were returned. + @retval EFI_INVALID_PARAMETER Any parameter is NULL. + @retval EFI_DEVICE_ERROR The wakeup time could not be retrieved due to a hardware error. + +**/ +EFI_STATUS +EFIAPI +LibGetWakeupTime ( + OUT BOOLEAN *Enabled, + OUT BOOLEAN *Pending, + OUT EFI_TIME *Time + ) +{ + // Not a required feature + return EFI_UNSUPPORTED; +} + + +/** + Sets the system wakeup alarm clock time. + + @param Enabled Enable or disable the wakeup alarm. + @param Time If Enable is TRUE, the time to set the wakeup alarm for. + + @retval EFI_SUCCESS If Enable is TRUE, then the wakeup alarm was enabled. If + Enable is FALSE, then the wakeup alarm was disabled. + @retval EFI_INVALID_PARAMETER A time field is out of range. + @retval EFI_DEVICE_ERROR The wakeup time could not be set due to a hardware error. + @retval EFI_UNSUPPORTED A wakeup timer is not supported on this platform. + +**/ +EFI_STATUS +EFIAPI +LibSetWakeupTime ( + IN BOOLEAN Enabled, + OUT EFI_TIME *Time + ) +{ + // Not a required feature + return EFI_UNSUPPORTED; +} + + + +/** + This is the declaration of an EFI image entry point. This can be the entry point to an application + written to this specification, an EFI boot service driver, or an EFI runtime driver. + + @param ImageHandle Handle that identifies the loaded image. + @param SystemTable System Table for this image. + + @retval EFI_SUCCESS The operation completed successfully. + +**/ +EFI_STATUS +EFIAPI +LibRtcInitialize ( + IN EFI_HANDLE ImageHandle, + IN EFI_SYSTEM_TABLE *SystemTable + ) +{ + I2cBusInit(); + I2cSetBusSpeed(PcdGet32(PcdRtcI2cBus), PcdGet32(PcdI2cSpeed)); + return EFI_SUCCESS; +} + + +/** + Fixup internal data so that EFI can be call in virtual mode. + Call the passed in Child Notify event and convert any pointers in + lib to virtual mode. + + @param[in] Event The Event that is being processed + @param[in] Context Event Context +**/ +VOID +EFIAPI +LibRtcVirtualNotifyEvent ( + IN EFI_EVENT Event, + IN VOID *Context + ) +{ + // + // Only needed if you are going to support the OS calling RTC functions in virtual mode. + // You will need to call EfiConvertPointer (). To convert any stored physical addresses + // to virtual address. After the OS transistions to calling in virtual mode, all future + // runtime calls will be made in virtual mode. + // + return; +} diff --git a/Chips/Nxp/QoriqLs/Library/Ds1307RtcLib/Ds1307RtcLib.inf b/Chips/Nxp/QoriqLs/Library/Ds1307RtcLib/Ds1307RtcLib.inf new file mode 100644 index 0000000..0eada07 --- /dev/null +++ b/Chips/Nxp/QoriqLs/Library/Ds1307RtcLib/Ds1307RtcLib.inf @@ -0,0 +1,44 @@ +#/** @Ds1307RtcLib.inf +# +# Lib to provide support for DS1307 Real Time Clock +# +# Copyright (c) 2016, Freescale Semiconductor, Inc. All rights reserved. +# +# This program and the accompanying materials +# are licensed and made available under the terms and conditions of the BSD License +# which accompanies this distribution. The full text of the license may be found at +# http://opensource.org/licenses/bsd-license.php +# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, +# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. +# +# +#**/ + +[Defines] + INF_VERSION = 0x00010005 + BASE_NAME = Ds1307RtcLib + FILE_GUID = B661E02D-A90B-42AB-A5F9-CF841AAA43D9 + MODULE_TYPE = BASE + VERSION_STRING = 1.0 + LIBRARY_CLASS = RealTimeClockLib + + +[Sources.common] + Ds1307RtcLib.c + + +[Packages] + MdePkg/MdePkg.dec + EmbeddedPkg/EmbeddedPkg.dec + OpenPlatformPkg/Platforms/Nxp/LS1043aRdb/LS1043aRdbPkg.dec + OpenPlatformPkg/Chips/Nxp/QoriqLs/NxpQoriqLs.dec + +[LibraryClasses] + IoLib + DebugLib + I2cLib + +[Pcd] + gNxpQoriqLsTokenSpaceGuid.PcdRtcI2cBus + gNxpQoriqLsTokenSpaceGuid.PcdI2cSpeed + gNxpQoriqLsTokenSpaceGuid.PcdDs1307I2cAddress
On 17 October 2016 at 21:04, Bhupesh Sharma bhupesh.sharma@freescale.com wrote:
From: Sakar Arora sakar.arora@nxp.com
NXP/FSL LS1043A-RDB board has a on-board RTC clock chip (DS1407), which sits over the I2C bus.
This patch adds the support for this on-board RTC chip via a library which provides real time clock APIs on top of I2C APIs
Signed-off-by: Sakar Arora sakar.arora@nxp.com Signed-off-by: Bhupesh Sharma bhupesh.sharma@nxp.com
.../QoriqLs/Library/Ds1307RtcLib/Ds1307RtcLib.c | 250 +++++++++++++++++++++ .../QoriqLs/Library/Ds1307RtcLib/Ds1307RtcLib.inf | 44 ++++ 2 files changed, 294 insertions(+) create mode 100644 Chips/Nxp/QoriqLs/Library/Ds1307RtcLib/Ds1307RtcLib.c create mode 100644 Chips/Nxp/QoriqLs/Library/Ds1307RtcLib/Ds1307RtcLib.inf
diff --git a/Chips/Nxp/QoriqLs/Library/Ds1307RtcLib/Ds1307RtcLib.c b/Chips/Nxp/QoriqLs/Library/Ds1307RtcLib/Ds1307RtcLib.c new file mode 100644 index 0000000..85fe564 --- /dev/null +++ b/Chips/Nxp/QoriqLs/Library/Ds1307RtcLib/Ds1307RtcLib.c @@ -0,0 +1,250 @@ +/** @Ds1307RtcLib.c
- Implement EFI RealTimeClock with runtime services via RTC Lib for DS1307 RTC.
- Based on RTC implementation available in
- EmbeddedPkg/Library/TemplateRealTimeClockLib/RealTimeClockLib.c
- Copyright (c) 2008 - 2009, Apple Inc. All rights reserved.<BR>
- Copyright (c) 2016, Freescale Semiconductor, Inc. All rights reserved.
- This program and the accompanying materials
- are licensed and made available under the terms and conditions of the BSD License
- which accompanies this distribution. The full text of the license may be found at
- http://opensource.org/licenses/bsd-license.php
- THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
- WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
+**/
+#include <PiDxe.h> +#include <Library/BaseLib.h> +#include <Library/DebugLib.h> +#include <Library/IoLib.h> +#include <Library/RealTimeClockLib.h> +#include <Library/I2c.h>
+#define Bin(Bcd) ((Bcd) & 0x0f) + ((Bcd) >> 4) * 10 +#define Bcd(Bin) (((Bin / 10) << 4) | (Bin % 10))
+/*
- RTC register addresses
- */
+#define DS1307_SEC_REG_ADDR 0x00 +#define DS1307_MIN_REG_ADDR 0x01 +#define DS1307_HR_REG_ADDR 0x02 +#define DS1307_DAY_REG_ADDR 0x03 +#define DS1307_DATE_REG_ADDR 0x04 +#define DS1307_MON_REG_ADDR 0x05 +#define DS1307_YR_REG_ADDR 0x06 +#define DS1307_CTL_REG_ADDR 0x07
+#define DS1307_SEC_BIT_CH 0x80 /* Clock Halt (in Register 0) */
+#define DS1307_CTL_BIT_RS0 0x01 /* Rate select 0 */ +#define DS1307_CTL_BIT_RS1 0x02 /* Rate select 1 */ +#define DS1307_CTL_BIT_SQWE 0x10 /* Square Wave Enable */ +#define DS1307_CTL_BIT_OUT 0x80 /* Output Control */
+UINT8 RtcRead(
UINT8 RtcRegAddr
+) +{
INT32 Status;
UINT8 Val = 0;
Status = I2cDataRead(PcdGet32(PcdRtcI2cBus), PcdGet32(PcdDs1307I2cAddress), RtcRegAddr, 0x1, &Val, sizeof(Val));
if(EFI_ERROR(Status))
DEBUG((EFI_D_ERROR, "RTC read error at Addr:0x%x\n", RtcRegAddr));
return Val;
+}
+VOID RtcWrite(
UINT8 RtcRegAddr,
UINT8 Val)
+{
INT32 Status;
Status = I2cDataWrite(PcdGet32(PcdRtcI2cBus), PcdGet32(PcdDs1307I2cAddress), RtcRegAddr, 0x1, &Val, sizeof(Val));
if(EFI_ERROR(Status))
DEBUG((EFI_D_ERROR, "RTC write error at Addr:0x%x\n", RtcRegAddr));
+}
The RTC driver is a DXE_RUNTIME_DRIVER, which means that, like the reset driver, these functions need to be able to cope with being called at runtime. This means no DEBUG() statements, but more importantly, that the protocols it depends on are also implemented by DXE_RUNTIME_DRIVER modules, which implies [presumably] that this I2C controller cannot be used by the OS at the same time.
+/**
- Returns the current time and date information, and the time-keeping capabilities
- of the hardware platform.
- @param Time A pointer to storage to receive a snapshot of the current time.
- @param Capabilities An optional pointer to a buffer to receive the real time clock
device's capabilities.
- @retval EFI_SUCCESS The operation completed successfully.
- @retval EFI_INVALID_PARAMETER Time is NULL.
- @retval EFI_DEVICE_ERROR The time could not be retrieved due to hardware error.
+**/
+EFI_STATUS +EFIAPI +LibGetTime (
- OUT EFI_TIME *Time,
- OUT EFI_TIME_CAPABILITIES *Capabilities
- )
+{
EFI_STATUS Status = EFI_SUCCESS;
CHAR16 Second, Minute, Hour, Day, Month, Year;
Second = RtcRead (DS1307_SEC_REG_ADDR);
Minute = RtcRead (DS1307_MIN_REG_ADDR);
Hour = RtcRead (DS1307_HR_REG_ADDR);
Day = RtcRead (DS1307_DATE_REG_ADDR);
Month = RtcRead (DS1307_MON_REG_ADDR);
Year = RtcRead (DS1307_YR_REG_ADDR);
if (Second & DS1307_SEC_BIT_CH) {
DEBUG((EFI_D_ERROR, "### Warning: RTC oscillator has stopped\n"));
/* clear the CH flag */
RtcWrite (DS1307_SEC_REG_ADDR,
RtcRead (DS1307_SEC_REG_ADDR) & ~DS1307_SEC_BIT_CH);
Status = EFI_DEVICE_ERROR;
}
Time->Second = Bin (Second & 0x7F);
Time->Minute = Bin (Minute & 0x7F);
Time->Hour = Bin (Hour & 0x3F);
Time->Day = Bin (Day & 0x3F);
Time->Month = Bin (Month & 0x1F);
Time->Year = Bin (Year) + ( Bin (Year) >= 70 ? 1900 : 2000);
- return Status;
+}
+/**
- Sets the current local time and date information.
- @param Time A pointer to the current time.
- @retval EFI_SUCCESS The operation completed successfully.
- @retval EFI_INVALID_PARAMETER A time field is out of range.
- @retval EFI_DEVICE_ERROR The time could not be set due due to hardware error.
+**/ +EFI_STATUS +EFIAPI +LibSetTime (
- IN EFI_TIME *Time
- )
+{
if (Time->Year < 1970 || Time->Year > 2069)
DEBUG((EFI_D_ERROR, "WARNING: Year should be between 1970 and 2069!\n"));
RtcWrite (DS1307_YR_REG_ADDR, Bcd (Time->Year % 100));
RtcWrite (DS1307_MON_REG_ADDR, Bcd (Time->Month));
RtcWrite (DS1307_DATE_REG_ADDR, Bcd (Time->Day));
RtcWrite (DS1307_HR_REG_ADDR, Bcd (Time->Hour));
RtcWrite (DS1307_MIN_REG_ADDR, Bcd (Time->Minute));
RtcWrite (DS1307_SEC_REG_ADDR, Bcd (Time->Second));
- return EFI_SUCCESS;
+}
+/**
- Returns the current wakeup alarm clock setting.
- @param Enabled Indicates if the alarm is currently enabled or disabled.
- @param Pending Indicates if the alarm signal is pending and requires acknowledgement.
- @param Time The current alarm setting.
- @retval EFI_SUCCESS The alarm settings were returned.
- @retval EFI_INVALID_PARAMETER Any parameter is NULL.
- @retval EFI_DEVICE_ERROR The wakeup time could not be retrieved due to a hardware error.
+**/ +EFI_STATUS +EFIAPI +LibGetWakeupTime (
- OUT BOOLEAN *Enabled,
- OUT BOOLEAN *Pending,
- OUT EFI_TIME *Time
- )
+{
- // Not a required feature
- return EFI_UNSUPPORTED;
+}
+/**
- Sets the system wakeup alarm clock time.
- @param Enabled Enable or disable the wakeup alarm.
- @param Time If Enable is TRUE, the time to set the wakeup alarm for.
- @retval EFI_SUCCESS If Enable is TRUE, then the wakeup alarm was enabled. If
Enable is FALSE, then the wakeup alarm was disabled.
- @retval EFI_INVALID_PARAMETER A time field is out of range.
- @retval EFI_DEVICE_ERROR The wakeup time could not be set due to a hardware error.
- @retval EFI_UNSUPPORTED A wakeup timer is not supported on this platform.
+**/ +EFI_STATUS +EFIAPI +LibSetWakeupTime (
- IN BOOLEAN Enabled,
- OUT EFI_TIME *Time
- )
+{
- // Not a required feature
- return EFI_UNSUPPORTED;
+}
+/**
- This is the declaration of an EFI image entry point. This can be the entry point to an application
- written to this specification, an EFI boot service driver, or an EFI runtime driver.
- @param ImageHandle Handle that identifies the loaded image.
- @param SystemTable System Table for this image.
- @retval EFI_SUCCESS The operation completed successfully.
+**/ +EFI_STATUS +EFIAPI +LibRtcInitialize (
- IN EFI_HANDLE ImageHandle,
- IN EFI_SYSTEM_TABLE *SystemTable
- )
+{
I2cBusInit();
I2cSetBusSpeed(PcdGet32(PcdRtcI2cBus), PcdGet32(PcdI2cSpeed));
- return EFI_SUCCESS;
+}
+/**
- Fixup internal data so that EFI can be call in virtual mode.
- Call the passed in Child Notify event and convert any pointers in
- lib to virtual mode.
- @param[in] Event The Event that is being processed
- @param[in] Context Event Context
+**/ +VOID +EFIAPI +LibRtcVirtualNotifyEvent (
- IN EFI_EVENT Event,
- IN VOID *Context
- )
+{
- //
- // Only needed if you are going to support the OS calling RTC functions in virtual mode.
- // You will need to call EfiConvertPointer (). To convert any stored physical addresses
- // to virtual address. After the OS transistions to calling in virtual mode, all future
- // runtime calls will be made in virtual mode.
- //
- return;
+} diff --git a/Chips/Nxp/QoriqLs/Library/Ds1307RtcLib/Ds1307RtcLib.inf b/Chips/Nxp/QoriqLs/Library/Ds1307RtcLib/Ds1307RtcLib.inf new file mode 100644 index 0000000..0eada07 --- /dev/null +++ b/Chips/Nxp/QoriqLs/Library/Ds1307RtcLib/Ds1307RtcLib.inf @@ -0,0 +1,44 @@ +#/** @Ds1307RtcLib.inf +# +# Lib to provide support for DS1307 Real Time Clock +# +# Copyright (c) 2016, Freescale Semiconductor, Inc. All rights reserved. +# +# This program and the accompanying materials +# are licensed and made available under the terms and conditions of the BSD License +# which accompanies this distribution. The full text of the license may be found at +# http://opensource.org/licenses/bsd-license.php +# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, +# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. +# +# +#**/
+[Defines]
- INF_VERSION = 0x00010005
- BASE_NAME = Ds1307RtcLib
- FILE_GUID = B661E02D-A90B-42AB-A5F9-CF841AAA43D9
fresh GUID
- MODULE_TYPE = BASE
- VERSION_STRING = 1.0
- LIBRARY_CLASS = RealTimeClockLib
+[Sources.common]
- Ds1307RtcLib.c
+[Packages]
- MdePkg/MdePkg.dec
- EmbeddedPkg/EmbeddedPkg.dec
- OpenPlatformPkg/Platforms/Nxp/LS1043aRdb/LS1043aRdbPkg.dec
- OpenPlatformPkg/Chips/Nxp/QoriqLs/NxpQoriqLs.dec
+[LibraryClasses]
- IoLib
- DebugLib
- I2cLib
+[Pcd]
- gNxpQoriqLsTokenSpaceGuid.PcdRtcI2cBus
- gNxpQoriqLsTokenSpaceGuid.PcdI2cSpeed
- gNxpQoriqLsTokenSpaceGuid.PcdDs1307I2cAddress
-- 1.9.1
Hi Ard,
Thanks for the review comments. Please see my replies inline.
From: Ard Biesheuvel [mailto:ard.biesheuvel@linaro.org] Sent: Tuesday, October 18, 2016 3:28 PM
On 17 October 2016 at 21:04, Bhupesh Sharma bhupesh.sharma@freescale.com wrote:
From: Sakar Arora sakar.arora@nxp.com
NXP/FSL LS1043A-RDB board has a on-board RTC clock chip (DS1407), which sits over the I2C bus.
This patch adds the support for this on-board RTC chip via a library which provides real time clock APIs on top of I2C APIs
Signed-off-by: Sakar Arora sakar.arora@nxp.com Signed-off-by: Bhupesh Sharma bhupesh.sharma@nxp.com
.../QoriqLs/Library/Ds1307RtcLib/Ds1307RtcLib.c | 250
+++++++++++++++++++++
.../QoriqLs/Library/Ds1307RtcLib/Ds1307RtcLib.inf | 44 ++++ 2 files changed, 294 insertions(+) create mode 100644 Chips/Nxp/QoriqLs/Library/Ds1307RtcLib/Ds1307RtcLib.c create mode 100644 Chips/Nxp/QoriqLs/Library/Ds1307RtcLib/Ds1307RtcLib.inf
diff --git a/Chips/Nxp/QoriqLs/Library/Ds1307RtcLib/Ds1307RtcLib.c b/Chips/Nxp/QoriqLs/Library/Ds1307RtcLib/Ds1307RtcLib.c new file mode 100644 index 0000000..85fe564 --- /dev/null +++ b/Chips/Nxp/QoriqLs/Library/Ds1307RtcLib/Ds1307RtcLib.c @@ -0,0 +1,250 @@ +/** @Ds1307RtcLib.c
- Implement EFI RealTimeClock with runtime services via RTC Lib for
DS1307 RTC.
- Based on RTC implementation available in
- EmbeddedPkg/Library/TemplateRealTimeClockLib/RealTimeClockLib.c
- Copyright (c) 2008 - 2009, Apple Inc. All rights reserved.<BR>
- Copyright (c) 2016, Freescale Semiconductor, Inc. All rights
reserved.
- This program and the accompanying materials are licensed and made
- available under the terms and conditions of the BSD License which
- accompanies this distribution. The full text of the license may be
- found at http://opensource.org/licenses/bsd-license.php
- THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS"
- BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER
EXPRESS OR IMPLIED.
+**/
+#include <PiDxe.h> +#include <Library/BaseLib.h> +#include <Library/DebugLib.h> +#include <Library/IoLib.h> +#include <Library/RealTimeClockLib.h> #include <Library/I2c.h>
+#define Bin(Bcd) ((Bcd) & 0x0f) + ((Bcd) >> 4) * 10 #define Bcd(Bin) +(((Bin / 10) << 4) | (Bin % 10))
+/*
- RTC register addresses
- */
+#define DS1307_SEC_REG_ADDR 0x00 +#define DS1307_MIN_REG_ADDR 0x01 +#define DS1307_HR_REG_ADDR 0x02 +#define DS1307_DAY_REG_ADDR 0x03 +#define DS1307_DATE_REG_ADDR 0x04 +#define DS1307_MON_REG_ADDR 0x05 +#define DS1307_YR_REG_ADDR 0x06 +#define DS1307_CTL_REG_ADDR 0x07
+#define DS1307_SEC_BIT_CH 0x80 /* Clock Halt (in Register 0)
*/
+#define DS1307_CTL_BIT_RS0 0x01 /* Rate select 0
*/
+#define DS1307_CTL_BIT_RS1 0x02 /* Rate select 1
*/
+#define DS1307_CTL_BIT_SQWE 0x10 /* Square Wave Enable
*/
+#define DS1307_CTL_BIT_OUT 0x80 /* Output Control
*/
+UINT8 RtcRead(
UINT8 RtcRegAddr
+) +{
INT32 Status;
UINT8 Val = 0;
Status = I2cDataRead(PcdGet32(PcdRtcI2cBus),
PcdGet32(PcdDs1307I2cAddress), RtcRegAddr, 0x1, &Val, sizeof(Val));
if(EFI_ERROR(Status))
DEBUG((EFI_D_ERROR, "RTC read error at Addr:0x%x\n",
RtcRegAddr));
return Val;
+}
+VOID RtcWrite(
UINT8 RtcRegAddr,
UINT8 Val)
+{
INT32 Status;
Status = I2cDataWrite(PcdGet32(PcdRtcI2cBus),
PcdGet32(PcdDs1307I2cAddress), RtcRegAddr, 0x1, &Val, sizeof(Val));
if(EFI_ERROR(Status))
DEBUG((EFI_D_ERROR, "RTC write error at Addr:0x%x\n",
+RtcRegAddr));
+}
The RTC driver is a DXE_RUNTIME_DRIVER, which means that, like the reset driver, these functions need to be able to cope with being called at runtime. This means no DEBUG() statements, but more importantly, that the protocols it depends on are also implemented by DXE_RUNTIME_DRIVER modules, which implies [presumably] that this I2C controller cannot be used by the OS at the same time.
Right, we just finished adding the RT support for LS1043A UEFI code. V2 will contain the support for RT which will include:
- storing variables persistently on NOR flash. - Removing DEBUG statements inside RT function which can cause a crash when called from the OS. - Adding support for RT in the I2C + RTC driver. - Adding support for RT in the ResetLib.
+/**
- Returns the current time and date information, and the time-
keeping
+capabilities
- of the hardware platform.
- @param Time A pointer to storage to receive a
snapshot of the current time.
- @param Capabilities An optional pointer to a buffer to
receive the real time clock
device's capabilities.
- @retval EFI_SUCCESS The operation completed
successfully.
- @retval EFI_INVALID_PARAMETER Time is NULL.
- @retval EFI_DEVICE_ERROR The time could not be retrieved due
to hardware error.
+**/
+EFI_STATUS +EFIAPI +LibGetTime (
- OUT EFI_TIME *Time,
- OUT EFI_TIME_CAPABILITIES *Capabilities
- )
+{
EFI_STATUS Status = EFI_SUCCESS;
CHAR16 Second, Minute, Hour, Day, Month, Year;
Second = RtcRead (DS1307_SEC_REG_ADDR);
Minute = RtcRead (DS1307_MIN_REG_ADDR);
Hour = RtcRead (DS1307_HR_REG_ADDR);
Day = RtcRead (DS1307_DATE_REG_ADDR);
Month = RtcRead (DS1307_MON_REG_ADDR);
Year = RtcRead (DS1307_YR_REG_ADDR);
if (Second & DS1307_SEC_BIT_CH) {
DEBUG((EFI_D_ERROR, "### Warning: RTC oscillator has
stopped\n"));
/* clear the CH flag */
RtcWrite (DS1307_SEC_REG_ADDR,
RtcRead (DS1307_SEC_REG_ADDR) &
~DS1307_SEC_BIT_CH);
Status = EFI_DEVICE_ERROR;
}
Time->Second = Bin (Second & 0x7F);
Time->Minute = Bin (Minute & 0x7F);
Time->Hour = Bin (Hour & 0x3F);
Time->Day = Bin (Day & 0x3F);
Time->Month = Bin (Month & 0x1F);
Time->Year = Bin (Year) + ( Bin (Year) >= 70 ? 1900 : 2000);
- return Status;
+}
+/**
- Sets the current local time and date information.
- @param Time A pointer to the current time.
- @retval EFI_SUCCESS The operation completed
successfully.
- @retval EFI_INVALID_PARAMETER A time field is out of range.
- @retval EFI_DEVICE_ERROR The time could not be set due due to
hardware error.
+**/ +EFI_STATUS +EFIAPI +LibSetTime (
- IN EFI_TIME *Time
- )
+{
if (Time->Year < 1970 || Time->Year > 2069)
DEBUG((EFI_D_ERROR, "WARNING: Year should be between
+1970 and 2069!\n"));
RtcWrite (DS1307_YR_REG_ADDR, Bcd (Time->Year % 100));
RtcWrite (DS1307_MON_REG_ADDR, Bcd (Time->Month));
RtcWrite (DS1307_DATE_REG_ADDR, Bcd (Time->Day));
RtcWrite (DS1307_HR_REG_ADDR, Bcd (Time->Hour));
RtcWrite (DS1307_MIN_REG_ADDR, Bcd (Time->Minute));
RtcWrite (DS1307_SEC_REG_ADDR, Bcd (Time->Second));
- return EFI_SUCCESS;
+}
+/**
- Returns the current wakeup alarm clock setting.
- @param Enabled Indicates if the alarm is currently
enabled or disabled.
- @param Pending Indicates if the alarm signal is
pending and requires acknowledgement.
- @param Time The current alarm setting.
- @retval EFI_SUCCESS The alarm settings were returned.
- @retval EFI_INVALID_PARAMETER Any parameter is NULL.
- @retval EFI_DEVICE_ERROR The wakeup time could not be
retrieved due to a hardware error.
+**/ +EFI_STATUS +EFIAPI +LibGetWakeupTime (
- OUT BOOLEAN *Enabled,
- OUT BOOLEAN *Pending,
- OUT EFI_TIME *Time
- )
+{
- // Not a required feature
- return EFI_UNSUPPORTED;
+}
+/**
- Sets the system wakeup alarm clock time.
- @param Enabled Enable or disable the wakeup alarm.
- @param Time If Enable is TRUE, the time to set
the wakeup alarm for.
- @retval EFI_SUCCESS If Enable is TRUE, then the wakeup
alarm was enabled. If
Enable is FALSE, then the wakeup
alarm was disabled.
- @retval EFI_INVALID_PARAMETER A time field is out of range.
- @retval EFI_DEVICE_ERROR The wakeup time could not be set due
to a hardware error.
- @retval EFI_UNSUPPORTED A wakeup timer is not supported on
this platform.
+**/ +EFI_STATUS +EFIAPI +LibSetWakeupTime (
- IN BOOLEAN Enabled,
- OUT EFI_TIME *Time
- )
+{
- // Not a required feature
- return EFI_UNSUPPORTED;
+}
+/**
- This is the declaration of an EFI image entry point. This can be
+the entry point to an application
- written to this specification, an EFI boot service driver, or an
EFI runtime driver.
- @param ImageHandle Handle that identifies the loaded
image.
- @param SystemTable System Table for this image.
- @retval EFI_SUCCESS The operation completed
successfully.
+**/ +EFI_STATUS +EFIAPI +LibRtcInitialize (
- IN EFI_HANDLE ImageHandle,
- IN EFI_SYSTEM_TABLE *SystemTable
- )
+{
I2cBusInit();
I2cSetBusSpeed(PcdGet32(PcdRtcI2cBus),
PcdGet32(PcdI2cSpeed));
- return EFI_SUCCESS;
+}
+/**
- Fixup internal data so that EFI can be call in virtual mode.
- Call the passed in Child Notify event and convert any pointers in
- lib to virtual mode.
- @param[in] Event The Event that is being processed
- @param[in] Context Event Context
+**/ +VOID +EFIAPI +LibRtcVirtualNotifyEvent (
- IN EFI_EVENT Event,
- IN VOID *Context
- )
+{
- //
- // Only needed if you are going to support the OS calling RTC
functions in virtual mode.
- // You will need to call EfiConvertPointer (). To convert any
+stored physical addresses
- // to virtual address. After the OS transistions to calling in
+virtual mode, all future
- // runtime calls will be made in virtual mode.
- //
- return;
+} diff --git a/Chips/Nxp/QoriqLs/Library/Ds1307RtcLib/Ds1307RtcLib.inf b/Chips/Nxp/QoriqLs/Library/Ds1307RtcLib/Ds1307RtcLib.inf new file mode 100644 index 0000000..0eada07 --- /dev/null +++ b/Chips/Nxp/QoriqLs/Library/Ds1307RtcLib/Ds1307RtcLib.inf @@ -0,0 +1,44 @@ +#/** @Ds1307RtcLib.inf +# +# Lib to provide support for DS1307 Real Time Clock # # Copyright +(c) 2016, Freescale Semiconductor, Inc. All rights reserved. +# +# This program and the accompanying materials # are licensed and +made available under the terms and conditions of the BSD License # +which accompanies this distribution. The full text of the license
may
+be found at # http://opensource.org/licenses/bsd-license.php +# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" +BASIS, # WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER
EXPRESS OR IMPLIED.
+# +# +#**/
+[Defines]
- INF_VERSION = 0x00010005
- BASE_NAME = Ds1307RtcLib
- FILE_GUID = B661E02D-A90B-42AB-A5F9-
CF841AAA43D9
fresh GUID
Ok.
- MODULE_TYPE = BASE
- VERSION_STRING = 1.0
- LIBRARY_CLASS = RealTimeClockLib
+[Sources.common]
- Ds1307RtcLib.c
+[Packages]
- MdePkg/MdePkg.dec
- EmbeddedPkg/EmbeddedPkg.dec
- OpenPlatformPkg/Platforms/Nxp/LS1043aRdb/LS1043aRdbPkg.dec
- OpenPlatformPkg/Chips/Nxp/QoriqLs/NxpQoriqLs.dec
+[LibraryClasses]
- IoLib
- DebugLib
- I2cLib
+[Pcd]
- gNxpQoriqLsTokenSpaceGuid.PcdRtcI2cBus
- gNxpQoriqLsTokenSpaceGuid.PcdI2cSpeed
- gNxpQoriqLsTokenSpaceGuid.PcdDs1307I2cAddress
-- 1.9.1
Regards, Bhupesh
On Tue, Oct 18, 2016 at 01:34:11AM +0530, Bhupesh Sharma wrote:
From: Sakar Arora sakar.arora@nxp.com
NXP/FSL LS1043A-RDB board has a on-board RTC clock chip (DS1407), which sits over the I2C bus.
This patch adds the support for this on-board RTC chip via a library which provides real time clock APIs on top of I2C APIs
Signed-off-by: Sakar Arora sakar.arora@nxp.com Signed-off-by: Bhupesh Sharma bhupesh.sharma@nxp.com
.../QoriqLs/Library/Ds1307RtcLib/Ds1307RtcLib.c | 250 +++++++++++++++++++++ .../QoriqLs/Library/Ds1307RtcLib/Ds1307RtcLib.inf | 44 ++++ 2 files changed, 294 insertions(+) create mode 100644 Chips/Nxp/QoriqLs/Library/Ds1307RtcLib/Ds1307RtcLib.c create mode 100644 Chips/Nxp/QoriqLs/Library/Ds1307RtcLib/Ds1307RtcLib.inf
diff --git a/Chips/Nxp/QoriqLs/Library/Ds1307RtcLib/Ds1307RtcLib.c b/Chips/Nxp/QoriqLs/Library/Ds1307RtcLib/Ds1307RtcLib.c new file mode 100644 index 0000000..85fe564 --- /dev/null +++ b/Chips/Nxp/QoriqLs/Library/Ds1307RtcLib/Ds1307RtcLib.c @@ -0,0 +1,250 @@ +/** @Ds1307RtcLib.c
- Implement EFI RealTimeClock with runtime services via RTC Lib for DS1307 RTC.
- Based on RTC implementation available in
- EmbeddedPkg/Library/TemplateRealTimeClockLib/RealTimeClockLib.c
- Copyright (c) 2008 - 2009, Apple Inc. All rights reserved.<BR>
- Copyright (c) 2016, Freescale Semiconductor, Inc. All rights reserved.
- This program and the accompanying materials
- are licensed and made available under the terms and conditions of the BSD License
- which accompanies this distribution. The full text of the license may be found at
- http://opensource.org/licenses/bsd-license.php
- THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
- WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
+**/
+#include <PiDxe.h> +#include <Library/BaseLib.h> +#include <Library/DebugLib.h> +#include <Library/IoLib.h> +#include <Library/RealTimeClockLib.h> +#include <Library/I2c.h>
Sorted please.
+#define Bin(Bcd) ((Bcd) & 0x0f) + ((Bcd) >> 4) * 10 +#define Bcd(Bin) (((Bin / 10) << 4) | (Bin % 10))
+/*
- RTC register addresses
- */
+#define DS1307_SEC_REG_ADDR 0x00 +#define DS1307_MIN_REG_ADDR 0x01 +#define DS1307_HR_REG_ADDR 0x02 +#define DS1307_DAY_REG_ADDR 0x03 +#define DS1307_DATE_REG_ADDR 0x04 +#define DS1307_MON_REG_ADDR 0x05 +#define DS1307_YR_REG_ADDR 0x06 +#define DS1307_CTL_REG_ADDR 0x07
+#define DS1307_SEC_BIT_CH 0x80 /* Clock Halt (in Register 0) */
+#define DS1307_CTL_BIT_RS0 0x01 /* Rate select 0 */ +#define DS1307_CTL_BIT_RS1 0x02 /* Rate select 1 */ +#define DS1307_CTL_BIT_SQWE 0x10 /* Square Wave Enable */ +#define DS1307_CTL_BIT_OUT 0x80 /* Output Control */
+UINT8 RtcRead(
UINT8 RtcRegAddr
+) +{
- INT32 Status;
- UINT8 Val = 0;
- Status = I2cDataRead(PcdGet32(PcdRtcI2cBus), PcdGet32(PcdDs1307I2cAddress), RtcRegAddr, 0x1, &Val, sizeof(Val));
- if(EFI_ERROR(Status))
DEBUG((EFI_D_ERROR, "RTC read error at Addr:0x%x\n", RtcRegAddr));
- return Val;
+}
+VOID RtcWrite(
UINT8 RtcRegAddr,
UINT8 Val)
+{
- INT32 Status;
- Status = I2cDataWrite(PcdGet32(PcdRtcI2cBus), PcdGet32(PcdDs1307I2cAddress), RtcRegAddr, 0x1, &Val, sizeof(Val));
- if(EFI_ERROR(Status))
DEBUG((EFI_D_ERROR, "RTC write error at Addr:0x%x\n", RtcRegAddr));
+}
+/**
- Returns the current time and date information, and the time-keeping capabilities
- of the hardware platform.
- @param Time A pointer to storage to receive a snapshot of the current time.
- @param Capabilities An optional pointer to a buffer to receive the real time clock
device's capabilities.
- @retval EFI_SUCCESS The operation completed successfully.
- @retval EFI_INVALID_PARAMETER Time is NULL.
- @retval EFI_DEVICE_ERROR The time could not be retrieved due to hardware error.
+**/
+EFI_STATUS +EFIAPI +LibGetTime (
- OUT EFI_TIME *Time,
- OUT EFI_TIME_CAPABILITIES *Capabilities
- )
+{
- EFI_STATUS Status = EFI_SUCCESS;
- CHAR16 Second, Minute, Hour, Day, Month, Year;
- Second = RtcRead (DS1307_SEC_REG_ADDR);
- Minute = RtcRead (DS1307_MIN_REG_ADDR);
- Hour = RtcRead (DS1307_HR_REG_ADDR);
- Day = RtcRead (DS1307_DATE_REG_ADDR);
- Month = RtcRead (DS1307_MON_REG_ADDR);
- Year = RtcRead (DS1307_YR_REG_ADDR);
- if (Second & DS1307_SEC_BIT_CH) {
DEBUG((EFI_D_ERROR, "### Warning: RTC oscillator has stopped\n"));
/* clear the CH flag */
RtcWrite (DS1307_SEC_REG_ADDR,
RtcRead (DS1307_SEC_REG_ADDR) & ~DS1307_SEC_BIT_CH);
Status = EFI_DEVICE_ERROR;
- }
- Time->Second = Bin (Second & 0x7F);
- Time->Minute = Bin (Minute & 0x7F);
- Time->Hour = Bin (Hour & 0x3F);
- Time->Day = Bin (Day & 0x3F);
- Time->Month = Bin (Month & 0x1F);
- Time->Year = Bin (Year) + ( Bin (Year) >= 70 ? 1900 : 2000);
Can we have a comment on the hardware behaviour this is translating?
- return Status;
+}
+/**
- Sets the current local time and date information.
- @param Time A pointer to the current time.
- @retval EFI_SUCCESS The operation completed successfully.
- @retval EFI_INVALID_PARAMETER A time field is out of range.
- @retval EFI_DEVICE_ERROR The time could not be set due due to hardware error.
+**/ +EFI_STATUS +EFIAPI +LibSetTime (
- IN EFI_TIME *Time
- )
+{
- if (Time->Year < 1970 || Time->Year > 2069)
DEBUG((EFI_D_ERROR, "WARNING: Year should be between 1970 and 2069!\n"));
I don't think the universe cares about this software constraint. So please instead refer to the hardware limitation this is trying to work around.
- RtcWrite (DS1307_YR_REG_ADDR, Bcd (Time->Year % 100));
- RtcWrite (DS1307_MON_REG_ADDR, Bcd (Time->Month));
- RtcWrite (DS1307_DATE_REG_ADDR, Bcd (Time->Day));
- RtcWrite (DS1307_HR_REG_ADDR, Bcd (Time->Hour));
- RtcWrite (DS1307_MIN_REG_ADDR, Bcd (Time->Minute));
- RtcWrite (DS1307_SEC_REG_ADDR, Bcd (Time->Second));
- return EFI_SUCCESS;
+}
+/**
- Returns the current wakeup alarm clock setting.
- @param Enabled Indicates if the alarm is currently enabled or disabled.
- @param Pending Indicates if the alarm signal is pending and requires acknowledgement.
- @param Time The current alarm setting.
- @retval EFI_SUCCESS The alarm settings were returned.
- @retval EFI_INVALID_PARAMETER Any parameter is NULL.
- @retval EFI_DEVICE_ERROR The wakeup time could not be retrieved due to a hardware error.
+**/ +EFI_STATUS +EFIAPI +LibGetWakeupTime (
- OUT BOOLEAN *Enabled,
- OUT BOOLEAN *Pending,
- OUT EFI_TIME *Time
- )
+{
- // Not a required feature
- return EFI_UNSUPPORTED;
+}
+/**
- Sets the system wakeup alarm clock time.
- @param Enabled Enable or disable the wakeup alarm.
- @param Time If Enable is TRUE, the time to set the wakeup alarm for.
- @retval EFI_SUCCESS If Enable is TRUE, then the wakeup alarm was enabled. If
Enable is FALSE, then the wakeup alarm was disabled.
- @retval EFI_INVALID_PARAMETER A time field is out of range.
- @retval EFI_DEVICE_ERROR The wakeup time could not be set due to a hardware error.
- @retval EFI_UNSUPPORTED A wakeup timer is not supported on this platform.
+**/ +EFI_STATUS +EFIAPI +LibSetWakeupTime (
- IN BOOLEAN Enabled,
- OUT EFI_TIME *Time
- )
+{
- // Not a required feature
- return EFI_UNSUPPORTED;
+}
+/**
- This is the declaration of an EFI image entry point. This can be the entry point to an application
- written to this specification, an EFI boot service driver, or an EFI runtime driver.
- @param ImageHandle Handle that identifies the loaded image.
- @param SystemTable System Table for this image.
- @retval EFI_SUCCESS The operation completed successfully.
+**/ +EFI_STATUS +EFIAPI +LibRtcInitialize (
- IN EFI_HANDLE ImageHandle,
- IN EFI_SYSTEM_TABLE *SystemTable
- )
+{
- I2cBusInit();
- I2cSetBusSpeed(PcdGet32(PcdRtcI2cBus), PcdGet32(PcdI2cSpeed));
- return EFI_SUCCESS;
+}
+/**
- Fixup internal data so that EFI can be call in virtual mode.
- Call the passed in Child Notify event and convert any pointers in
- lib to virtual mode.
- @param[in] Event The Event that is being processed
- @param[in] Context Event Context
+**/ +VOID +EFIAPI +LibRtcVirtualNotifyEvent (
- IN EFI_EVENT Event,
- IN VOID *Context
- )
+{
- //
- // Only needed if you are going to support the OS calling RTC functions in virtual mode.
- // You will need to call EfiConvertPointer (). To convert any stored physical addresses
- // to virtual address. After the OS transistions to calling in virtual mode, all future
- // runtime calls will be made in virtual mode.
- //
- return;
+} diff --git a/Chips/Nxp/QoriqLs/Library/Ds1307RtcLib/Ds1307RtcLib.inf b/Chips/Nxp/QoriqLs/Library/Ds1307RtcLib/Ds1307RtcLib.inf new file mode 100644 index 0000000..0eada07 --- /dev/null +++ b/Chips/Nxp/QoriqLs/Library/Ds1307RtcLib/Ds1307RtcLib.inf @@ -0,0 +1,44 @@ +#/** @Ds1307RtcLib.inf +# +# Lib to provide support for DS1307 Real Time Clock +# +# Copyright (c) 2016, Freescale Semiconductor, Inc. All rights reserved. +# +# This program and the accompanying materials +# are licensed and made available under the terms and conditions of the BSD License +# which accompanies this distribution. The full text of the license may be found at +# http://opensource.org/licenses/bsd-license.php +# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, +# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. +# +# +#**/
+[Defines]
- INF_VERSION = 0x00010005
- BASE_NAME = Ds1307RtcLib
- FILE_GUID = B661E02D-A90B-42AB-A5F9-CF841AAA43D9
- MODULE_TYPE = BASE
- VERSION_STRING = 1.0
- LIBRARY_CLASS = RealTimeClockLib
+[Sources.common]
- Ds1307RtcLib.c
+[Packages]
- MdePkg/MdePkg.dec
- EmbeddedPkg/EmbeddedPkg.dec
- OpenPlatformPkg/Platforms/Nxp/LS1043aRdb/LS1043aRdbPkg.dec
- OpenPlatformPkg/Chips/Nxp/QoriqLs/NxpQoriqLs.dec
+[LibraryClasses]
- IoLib
- DebugLib
- I2cLib
+[Pcd]
- gNxpQoriqLsTokenSpaceGuid.PcdRtcI2cBus
- gNxpQoriqLsTokenSpaceGuid.PcdI2cSpeed
- gNxpQoriqLsTokenSpaceGuid.PcdDs1307I2cAddress
Can we have some alphabetic sorting here, please?
-- 1.9.1
Hi Leif,
From: Leif Lindholm [mailto:leif.lindholm@linaro.org] Sent: Saturday, November 05, 2016 5:02 AM
On Tue, Oct 18, 2016 at 01:34:11AM +0530, Bhupesh Sharma wrote:
From: Sakar Arora sakar.arora@nxp.com
NXP/FSL LS1043A-RDB board has a on-board RTC clock chip (DS1407), which sits over the I2C bus.
This patch adds the support for this on-board RTC chip via a library which provides real time clock APIs on top of I2C APIs
Signed-off-by: Sakar Arora sakar.arora@nxp.com Signed-off-by: Bhupesh Sharma bhupesh.sharma@nxp.com
.../QoriqLs/Library/Ds1307RtcLib/Ds1307RtcLib.c | 250
+++++++++++++++++++++
.../QoriqLs/Library/Ds1307RtcLib/Ds1307RtcLib.inf | 44 ++++ 2 files changed, 294 insertions(+) create mode 100644 Chips/Nxp/QoriqLs/Library/Ds1307RtcLib/Ds1307RtcLib.c create mode 100644 Chips/Nxp/QoriqLs/Library/Ds1307RtcLib/Ds1307RtcLib.inf
diff --git a/Chips/Nxp/QoriqLs/Library/Ds1307RtcLib/Ds1307RtcLib.c b/Chips/Nxp/QoriqLs/Library/Ds1307RtcLib/Ds1307RtcLib.c new file mode 100644 index 0000000..85fe564 --- /dev/null +++ b/Chips/Nxp/QoriqLs/Library/Ds1307RtcLib/Ds1307RtcLib.c @@ -0,0 +1,250 @@ +/** @Ds1307RtcLib.c
- Implement EFI RealTimeClock with runtime services via RTC Lib for
DS1307 RTC.
- Based on RTC implementation available in
- EmbeddedPkg/Library/TemplateRealTimeClockLib/RealTimeClockLib.c
- Copyright (c) 2008 - 2009, Apple Inc. All rights reserved.<BR>
- Copyright (c) 2016, Freescale Semiconductor, Inc. All rights
reserved.
- This program and the accompanying materials are licensed and made
- available under the terms and conditions of the BSD License which
- accompanies this distribution. The full text of the license may be
- found at http://opensource.org/licenses/bsd-license.php
- THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS"
- BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER
EXPRESS OR IMPLIED.
+**/
+#include <PiDxe.h> +#include <Library/BaseLib.h> +#include <Library/DebugLib.h> +#include <Library/IoLib.h> +#include <Library/RealTimeClockLib.h> #include <Library/I2c.h>
Sorted please.
Ok.
+#define Bin(Bcd) ((Bcd) & 0x0f) + ((Bcd) >> 4) * 10 #define Bcd(Bin) +(((Bin / 10) << 4) | (Bin % 10))
+/*
- RTC register addresses
- */
+#define DS1307_SEC_REG_ADDR 0x00 +#define DS1307_MIN_REG_ADDR 0x01 +#define DS1307_HR_REG_ADDR 0x02 +#define DS1307_DAY_REG_ADDR 0x03 +#define DS1307_DATE_REG_ADDR 0x04 +#define DS1307_MON_REG_ADDR 0x05 +#define DS1307_YR_REG_ADDR 0x06 +#define DS1307_CTL_REG_ADDR 0x07
+#define DS1307_SEC_BIT_CH 0x80 /* Clock Halt (in Register 0) */
+#define DS1307_CTL_BIT_RS0 0x01 /* Rate select 0 */ +#define DS1307_CTL_BIT_RS1 0x02 /* Rate select 1 */ +#define DS1307_CTL_BIT_SQWE 0x10 /* Square Wave Enable
*/
+#define DS1307_CTL_BIT_OUT 0x80 /* Output Control */
+UINT8 RtcRead(
UINT8 RtcRegAddr
+) +{
- INT32 Status;
- UINT8 Val = 0;
- Status = I2cDataRead(PcdGet32(PcdRtcI2cBus),
PcdGet32(PcdDs1307I2cAddress), RtcRegAddr, 0x1, &Val, sizeof(Val));
- if(EFI_ERROR(Status))
DEBUG((EFI_D_ERROR, "RTC read error at Addr:0x%x\n",
RtcRegAddr));
- return Val;
+}
+VOID RtcWrite(
UINT8 RtcRegAddr,
UINT8 Val)
+{
- INT32 Status;
- Status = I2cDataWrite(PcdGet32(PcdRtcI2cBus),
PcdGet32(PcdDs1307I2cAddress), RtcRegAddr, 0x1, &Val, sizeof(Val));
- if(EFI_ERROR(Status))
DEBUG((EFI_D_ERROR, "RTC write error at Addr:0x%x\n",
RtcRegAddr));
+}
+/**
- Returns the current time and date information, and the time-
keeping
+capabilities
- of the hardware platform.
- @param Time A pointer to storage to receive a
snapshot of the current time.
- @param Capabilities An optional pointer to a buffer to
receive the real time clock
device's capabilities.
- @retval EFI_SUCCESS The operation completed
successfully.
- @retval EFI_INVALID_PARAMETER Time is NULL.
- @retval EFI_DEVICE_ERROR The time could not be retrieved due
to hardware error.
+**/
+EFI_STATUS +EFIAPI +LibGetTime (
- OUT EFI_TIME *Time,
- OUT EFI_TIME_CAPABILITIES *Capabilities
- )
+{
- EFI_STATUS Status = EFI_SUCCESS;
- CHAR16 Second, Minute, Hour, Day, Month, Year;
- Second = RtcRead (DS1307_SEC_REG_ADDR);
- Minute = RtcRead (DS1307_MIN_REG_ADDR);
- Hour = RtcRead (DS1307_HR_REG_ADDR);
- Day = RtcRead (DS1307_DATE_REG_ADDR);
- Month = RtcRead (DS1307_MON_REG_ADDR);
- Year = RtcRead (DS1307_YR_REG_ADDR);
- if (Second & DS1307_SEC_BIT_CH) {
DEBUG((EFI_D_ERROR, "### Warning: RTC oscillator has
stopped\n"));
/* clear the CH flag */
RtcWrite (DS1307_SEC_REG_ADDR,
RtcRead (DS1307_SEC_REG_ADDR) &
~DS1307_SEC_BIT_CH);
Status = EFI_DEVICE_ERROR;
- }
- Time->Second = Bin (Second & 0x7F);
- Time->Minute = Bin (Minute & 0x7F);
- Time->Hour = Bin (Hour & 0x3F);
- Time->Day = Bin (Day & 0x3F);
- Time->Month = Bin (Month & 0x1F);
- Time->Year = Bin (Year) + ( Bin (Year) >= 70 ? 1900 : 2000);
Can we have a comment on the hardware behaviour this is translating?
Sure.
- return Status;
+}
+/**
- Sets the current local time and date information.
- @param Time A pointer to the current time.
- @retval EFI_SUCCESS The operation completed
successfully.
- @retval EFI_INVALID_PARAMETER A time field is out of range.
- @retval EFI_DEVICE_ERROR The time could not be set due due to
hardware error.
+**/ +EFI_STATUS +EFIAPI +LibSetTime (
- IN EFI_TIME *Time
- )
+{
- if (Time->Year < 1970 || Time->Year > 2069)
DEBUG((EFI_D_ERROR, "WARNING: Year should be between 1970
and
+2069!\n"));
I don't think the universe cares about this software constraint. So please instead refer to the hardware limitation this is trying to work around.
OK :)
- RtcWrite (DS1307_YR_REG_ADDR, Bcd (Time->Year % 100));
- RtcWrite (DS1307_MON_REG_ADDR, Bcd (Time->Month));
- RtcWrite (DS1307_DATE_REG_ADDR, Bcd (Time->Day));
- RtcWrite (DS1307_HR_REG_ADDR, Bcd (Time->Hour));
- RtcWrite (DS1307_MIN_REG_ADDR, Bcd (Time->Minute));
- RtcWrite (DS1307_SEC_REG_ADDR, Bcd (Time->Second));
- return EFI_SUCCESS;
+}
+/**
- Returns the current wakeup alarm clock setting.
- @param Enabled Indicates if the alarm is currently
enabled or disabled.
- @param Pending Indicates if the alarm signal is
pending and requires acknowledgement.
- @param Time The current alarm setting.
- @retval EFI_SUCCESS The alarm settings were returned.
- @retval EFI_INVALID_PARAMETER Any parameter is NULL.
- @retval EFI_DEVICE_ERROR The wakeup time could not be
retrieved due to a hardware error.
+**/ +EFI_STATUS +EFIAPI +LibGetWakeupTime (
- OUT BOOLEAN *Enabled,
- OUT BOOLEAN *Pending,
- OUT EFI_TIME *Time
- )
+{
- // Not a required feature
- return EFI_UNSUPPORTED;
+}
+/**
- Sets the system wakeup alarm clock time.
- @param Enabled Enable or disable the wakeup alarm.
- @param Time If Enable is TRUE, the time to set
the wakeup alarm for.
- @retval EFI_SUCCESS If Enable is TRUE, then the wakeup
alarm was enabled. If
Enable is FALSE, then the wakeup
alarm was disabled.
- @retval EFI_INVALID_PARAMETER A time field is out of range.
- @retval EFI_DEVICE_ERROR The wakeup time could not be set due
to a hardware error.
- @retval EFI_UNSUPPORTED A wakeup timer is not supported on
this platform.
+**/ +EFI_STATUS +EFIAPI +LibSetWakeupTime (
- IN BOOLEAN Enabled,
- OUT EFI_TIME *Time
- )
+{
- // Not a required feature
- return EFI_UNSUPPORTED;
+}
+/**
- This is the declaration of an EFI image entry point. This can be
+the entry point to an application
- written to this specification, an EFI boot service driver, or an
EFI runtime driver.
- @param ImageHandle Handle that identifies the loaded
image.
- @param SystemTable System Table for this image.
- @retval EFI_SUCCESS The operation completed
successfully.
+**/ +EFI_STATUS +EFIAPI +LibRtcInitialize (
- IN EFI_HANDLE ImageHandle,
- IN EFI_SYSTEM_TABLE *SystemTable
- )
+{
- I2cBusInit();
- I2cSetBusSpeed(PcdGet32(PcdRtcI2cBus), PcdGet32(PcdI2cSpeed));
- return EFI_SUCCESS;
+}
+/**
- Fixup internal data so that EFI can be call in virtual mode.
- Call the passed in Child Notify event and convert any pointers in
- lib to virtual mode.
- @param[in] Event The Event that is being processed
- @param[in] Context Event Context
+**/ +VOID +EFIAPI +LibRtcVirtualNotifyEvent (
- IN EFI_EVENT Event,
- IN VOID *Context
- )
+{
- //
- // Only needed if you are going to support the OS calling RTC
functions in virtual mode.
- // You will need to call EfiConvertPointer (). To convert any
+stored physical addresses
- // to virtual address. After the OS transistions to calling in
+virtual mode, all future
- // runtime calls will be made in virtual mode.
- //
- return;
+} diff --git a/Chips/Nxp/QoriqLs/Library/Ds1307RtcLib/Ds1307RtcLib.inf b/Chips/Nxp/QoriqLs/Library/Ds1307RtcLib/Ds1307RtcLib.inf new file mode 100644 index 0000000..0eada07 --- /dev/null +++ b/Chips/Nxp/QoriqLs/Library/Ds1307RtcLib/Ds1307RtcLib.inf @@ -0,0 +1,44 @@ +#/** @Ds1307RtcLib.inf +# +# Lib to provide support for DS1307 Real Time Clock # # Copyright +(c) 2016, Freescale Semiconductor, Inc. All rights reserved. +# +# This program and the accompanying materials # are licensed and +made available under the terms and conditions of the BSD License # +which accompanies this distribution. The full text of the license
may
+be found at # http://opensource.org/licenses/bsd-license.php +# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" +BASIS, # WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER
EXPRESS OR IMPLIED.
+# +# +#**/
+[Defines]
- INF_VERSION = 0x00010005
- BASE_NAME = Ds1307RtcLib
- FILE_GUID = B661E02D-A90B-42AB-A5F9-
CF841AAA43D9
- MODULE_TYPE = BASE
- VERSION_STRING = 1.0
- LIBRARY_CLASS = RealTimeClockLib
+[Sources.common]
- Ds1307RtcLib.c
+[Packages]
- MdePkg/MdePkg.dec
- EmbeddedPkg/EmbeddedPkg.dec
- OpenPlatformPkg/Platforms/Nxp/LS1043aRdb/LS1043aRdbPkg.dec
- OpenPlatformPkg/Chips/Nxp/QoriqLs/NxpQoriqLs.dec
+[LibraryClasses]
- IoLib
- DebugLib
- I2cLib
+[Pcd]
- gNxpQoriqLsTokenSpaceGuid.PcdRtcI2cBus
- gNxpQoriqLsTokenSpaceGuid.PcdI2cSpeed
- gNxpQoriqLsTokenSpaceGuid.PcdDs1307I2cAddress
Can we have some alphabetic sorting here, please?
Sure.
-- 1.9.1
From: Sakar Arora sakar.arora@nxp.com
This patch adds support for the Watchdog timer present on the LS1043A SoC.
The patch installs Watchdog timer arch protocol and implements APIs necessary for the same.
Signed-off-by: Sakar Arora sakar.arora@nxp.com --- .../LS1043aRdb/LS1043aWatchDog/LS1043aWatchDog.c | 355 +++++++++++++++++++++ .../LS1043aWatchDog/LS1043aWatchDogDxe.inf | 54 ++++ 2 files changed, 409 insertions(+) create mode 100644 Platforms/Nxp/LS1043aRdb/LS1043aWatchDog/LS1043aWatchDog.c create mode 100644 Platforms/Nxp/LS1043aRdb/LS1043aWatchDog/LS1043aWatchDogDxe.inf
diff --git a/Platforms/Nxp/LS1043aRdb/LS1043aWatchDog/LS1043aWatchDog.c b/Platforms/Nxp/LS1043aRdb/LS1043aWatchDog/LS1043aWatchDog.c new file mode 100644 index 0000000..ea298f9 --- /dev/null +++ b/Platforms/Nxp/LS1043aRdb/LS1043aWatchDog/LS1043aWatchDog.c @@ -0,0 +1,355 @@ +/** LS1043aWatchDog.c +* +* Based on Watchdog driver implemenation available in +* ArmPlatformPkg/Drivers/SP805WatchdogDxe/SP805Watchdog.c +* +* Copyright (c) 2011-2013, ARM Limited. All rights reserved. +* Copyright (c) 2016, Freescale Semiconductor, Inc. All rights reserved. +* +* This program and the accompanying materials +* are licensed and made available under the terms and conditions of the BSD License +* which accompanies this distribution. The full text of the license may be found at +* http://opensource.org/licenses/bsd-license.php +* +* THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, +* WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. +* +**/ + + +#include <PiDxe.h> + +#include <Library/BaseLib.h> +#include <Library/BaseMemoryLib.h> +#include <Library/DebugLib.h> +#include <Library/IoLib.h> +#include <Library/PcdLib.h> +#include <Library/UefiBootServicesTableLib.h> +#include <Library/UefiRuntimeServicesTableLib.h> +#include <Library/UefiLib.h> + +#include <Protocol/WatchdogTimer.h> +#include <Library/PlatformLib.h> + +#define LS1043A_WT_MAX_TIME 128 +#define LS1043A_WD_COUNT(sec) (((sec) * 2 - 1) << 8) +#define LS1043A_WD_SEC(cnt) (((cnt) + 1) / 2) + +EFI_EVENT EfiExitBootServicesEvent = (EFI_EVENT)NULL; + +inline +VOID +LS1043aWdogPing ( + VOID + ) +{ + MmioWriteBe16(WDOG1_BASE_ADDR + WDOG_WSR_OFFSET, WDOG_SERVICE_SEQ1); + MmioWriteBe16(WDOG1_BASE_ADDR + WDOG_WSR_OFFSET, WDOG_SERVICE_SEQ2); +} + +/** + Stop the LS1043aWdog watchdog timer from counting down by disabling interrupts. +**/ +inline +VOID +LS1043aWdogStop ( + VOID + ) +{ + // LS1043a Watchdog cannot be disabled by software once started. + // At best, we can keep pinging the watchdog + LS1043aWdogPing(); +} + +/** + Starts the LS1043aWdog counting down by enabling interrupts. + The count down will start from the value stored in the Load register, + not from the value where it was previously stopped. +**/ +inline +VOID +LS1043aWdogStart ( + VOID + ) +{ + /* Watchdog is enabled already in LS1043aWdogInitialize - time to reload the timeout value */ + LS1043aWdogPing(); +} + +/** + On exiting boot services we must make sure the LS1043aWdog Watchdog Timer + is stopped. +**/ +VOID +EFIAPI +ExitBootServicesEvent ( + IN EFI_EVENT Event, + IN VOID *Context + ) +{ + LS1043aWdogStop(); +} + +/** + This function registers the handler NotifyFunction so it is called every time + the watchdog timer expires. It also passes the amount of time since the last + handler call to the NotifyFunction. + If NotifyFunction is not NULL and a handler is not already registered, + then the new handler is registered and EFI_SUCCESS is returned. + If NotifyFunction is NULL, and a handler is already registered, + then that handler is unregistered. + If an attempt is made to register a handler when a handler is already registered, + then EFI_ALREADY_STARTED is returned. + If an attempt is made to unregister a handler when a handler is not registered, + then EFI_INVALID_PARAMETER is returned. + + @param This The EFI_TIMER_ARCH_PROTOCOL instance. + @param NotifyFunction The function to call when a timer interrupt fires. This + function executes at TPL_HIGH_LEVEL. The DXE Core will + register a handler for the timer interrupt, so it can know + how much time has passed. This information is used to + signal timer based events. NULL will unregister the handler. + + @retval EFI_SUCCESS The watchdog timer handler was registered. + @retval EFI_ALREADY_STARTED NotifyFunction is not NULL, and a handler is already + registered. + @retval EFI_INVALID_PARAMETER NotifyFunction is NULL, and a handler was not + previously registered. + +**/ +EFI_STATUS +EFIAPI +LS1043aWdogRegisterHandler ( + IN CONST EFI_WATCHDOG_TIMER_ARCH_PROTOCOL *This, + IN EFI_WATCHDOG_TIMER_NOTIFY NotifyFunction + ) +{ + // ERROR: This function is not supported. + // The hardware watchdog will reset the board + return EFI_INVALID_PARAMETER; +} + +/** + + This function adjusts the period of timer interrupts to the value specified + by TimerPeriod. If the timer period is updated, then the selected timer + period is stored in EFI_TIMER.TimerPeriod, and EFI_SUCCESS is returned. If + the timer hardware is not programmable, then EFI_UNSUPPORTED is returned. + If an error occurs while attempting to update the timer period, then the + timer hardware will be put back in its state prior to this call, and + EFI_DEVICE_ERROR is returned. If TimerPeriod is 0, then the timer interrupt + is disabled. This is not the same as disabling the CPU's interrupts. + Instead, it must either turn off the timer hardware, or it must adjust the + interrupt controller so that a CPU interrupt is not generated when the timer + interrupt fires. + + @param This The EFI_TIMER_ARCH_PROTOCOL instance. + @param TimerPeriod The rate to program the timer interrupt in 100 nS units. If + the timer hardware is not programmable, then EFI_UNSUPPORTED is + returned. If the timer is programmable, then the timer period + will be rounded up to the nearest timer period that is supported + by the timer hardware. If TimerPeriod is set to 0, then the + timer interrupts will be disabled. + + + @retval EFI_SUCCESS The timer period was changed. + @retval EFI_UNSUPPORTED The platform cannot change the period of the timer interrupt. + @retval EFI_DEVICE_ERROR The timer period could not be changed due to a device error. + +**/ +EFI_STATUS +EFIAPI +LS1043aWdogSetTimerPeriod ( + IN CONST EFI_WATCHDOG_TIMER_ARCH_PROTOCOL *This, + IN UINT64 TimerPeriod // In 100ns units + ) +{ + EFI_STATUS Status = EFI_SUCCESS; + UINT64 TimerPeriodInSec; + UINT16 Val; + + if( TimerPeriod == 0 ) { + // This is a watchdog stop request + LS1043aWdogStop(); + goto EXIT; + } else { + // Convert the TimerPeriod (in 100 ns unit) to an equivalent second value + + TimerPeriodInSec = DivU64x32(TimerPeriod, 10000000); + + // The registers in the LS1043aWdog are only 32 bits + if(TimerPeriodInSec > LS1043A_WT_MAX_TIME) { + // We could load the watchdog with the maximum supported value but + // if a smaller value was requested, this could have the watchdog + // triggering before it was intended. + // Better generate an error to let the caller know. + Status = EFI_DEVICE_ERROR; + goto EXIT; + } + + // set the new timeout value in the WCR + Val = MmioReadBe16(WDOG1_BASE_ADDR + WDOG_WCR_OFFSET); + Val &= ~WDOG_WCR_WT; + // Convert the timeout value from Seconds to timer count + Val |= ((LS1043A_WD_COUNT(TimerPeriodInSec) & 0xff00) << 8); + MmioWriteBe16(WDOG1_BASE_ADDR + WDOG_WCR_OFFSET, Val); + + // Start the watchdog + LS1043aWdogStart(); + } + + EXIT: + return Status; +} + +/** + This function retrieves the period of timer interrupts in 100 ns units, + returns that value in TimerPeriod, and returns EFI_SUCCESS. If TimerPeriod + is NULL, then EFI_INVALID_PARAMETER is returned. If a TimerPeriod of 0 is + returned, then the timer is currently disabled. + + @param This The EFI_TIMER_ARCH_PROTOCOL instance. + @param TimerPeriod A pointer to the timer period to retrieve in 100 ns units. If + 0 is returned, then the timer is currently disabled. + + + @retval EFI_SUCCESS The timer period was returned in TimerPeriod. + @retval EFI_INVALID_PARAMETER TimerPeriod is NULL. + +**/ +EFI_STATUS +EFIAPI +LS1043aWdogGetTimerPeriod ( + IN CONST EFI_WATCHDOG_TIMER_ARCH_PROTOCOL *This, + OUT UINT64 *TimerPeriod + ) +{ + EFI_STATUS Status = EFI_SUCCESS; + UINT64 ReturnValue; + UINT16 Val; + + if (TimerPeriod == NULL) { + return EFI_INVALID_PARAMETER; + } + + // Check if the watchdog is stopped + if ( (MmioReadBe16(WDOG1_BASE_ADDR + WDOG_WCR_OFFSET) & WDOG_WCR_WDE) == 0 ) { + // It is stopped, so return zero. + ReturnValue = 0; + } else { + // Convert the Watchdog ticks into equivalent TimerPeriod second + // value. + Val = (MmioReadBe16(WDOG1_BASE_ADDR + WDOG_WCR_OFFSET) & WDOG_WCR_WT ) >> 8; + ReturnValue = LS1043A_WD_SEC(Val); + } + + *TimerPeriod = ReturnValue; + return Status; +} + +/** + Interface structure for the Watchdog Architectural Protocol. + + @par Protocol Description: + This protocol provides a service to set the amount of time to wait + before firing the watchdog timer, and it also provides a service to + register a handler that is invoked when the watchdog timer fires. + + @par When the watchdog timer fires, control will be passed to a handler + if one has been registered. If no handler has been registered, + or the registered handler returns, then the system will be + reset by calling the Runtime Service ResetSystem(). + + @param RegisterHandler + Registers a handler that will be called each time the + watchdogtimer interrupt fires. TimerPeriod defines the minimum + time between timer interrupts, so TimerPeriod will also + be the minimum time between calls to the registered + handler. + NOTE: If the watchdog resets the system in hardware, then + this function will not have any chance of executing. + + @param SetTimerPeriod + Sets the period of the timer interrupt in 100 nS units. + This function is optional, and may return EFI_UNSUPPORTED. + If this function is supported, then the timer period will + be rounded up to the nearest supported timer period. + + @param GetTimerPeriod + Retrieves the period of the timer interrupt in 100 nS units. + +**/ +EFI_WATCHDOG_TIMER_ARCH_PROTOCOL gWatchdogTimer = { + (EFI_WATCHDOG_TIMER_REGISTER_HANDLER) LS1043aWdogRegisterHandler, + (EFI_WATCHDOG_TIMER_SET_TIMER_PERIOD) LS1043aWdogSetTimerPeriod, + (EFI_WATCHDOG_TIMER_GET_TIMER_PERIOD) LS1043aWdogGetTimerPeriod +}; + +/** + Initialize the state information for the Watchdog Timer Architectural Protocol. + + @param ImageHandle of the loaded driver + @param SystemTable Pointer to the System Table + + @retval EFI_SUCCESS Protocol registered + @retval EFI_OUT_OF_RESOURCES Cannot allocate protocol data structure + @retval EFI_DEVICE_ERROR Hardware problems + +**/ +EFI_STATUS +EFIAPI +LS1043aWdogInitialize ( + IN EFI_HANDLE ImageHandle, + IN EFI_SYSTEM_TABLE *SystemTable + ) +{ + EFI_STATUS Status; + EFI_HANDLE Handle; + UINT16 Val; + + + Val = MmioReadBe16(WDOG1_BASE_ADDR + WDOG_WCR_OFFSET); + + Val &= ~WDOG_WCR_WT; + + Val &= ~WDOG_WCR_WDE; + + Val |= LS1043A_WD_COUNT(LS1043A_WT_MAX_TIME) & 0xff00; + + MmioWriteBe16(WDOG1_BASE_ADDR + WDOG_WCR_OFFSET, Val); + + Val |= WDOG_WCR_WDE; + + // + // Make sure the Watchdog Timer Architectural Protocol has not been installed in the system yet. + // This will avoid conflicts with the universal watchdog + // + ASSERT_PROTOCOL_ALREADY_INSTALLED (NULL, &gEfiWatchdogTimerArchProtocolGuid); + + // Register for an ExitBootServicesEvent + Status = gBS->CreateEvent (EVT_SIGNAL_EXIT_BOOT_SERVICES, TPL_NOTIFY, ExitBootServicesEvent, NULL, &EfiExitBootServicesEvent); + if (EFI_ERROR(Status)) { + Status = EFI_OUT_OF_RESOURCES; + goto EXIT; + } + + // Install the Timer Architectural Protocol onto a new handle + Handle = NULL; + Status = gBS->InstallMultipleProtocolInterfaces( + &Handle, + &gEfiWatchdogTimerArchProtocolGuid, &gWatchdogTimer, + NULL + ); + if (EFI_ERROR(Status)) { + Status = EFI_OUT_OF_RESOURCES; + goto EXIT; + } + +EXIT: + if(EFI_ERROR(Status)) { + // The watchdog failed to initialize + ASSERT(FALSE); + } + LS1043aWdogPing(); + return Status; +} diff --git a/Platforms/Nxp/LS1043aRdb/LS1043aWatchDog/LS1043aWatchDogDxe.inf b/Platforms/Nxp/LS1043aRdb/LS1043aWatchDog/LS1043aWatchDogDxe.inf new file mode 100644 index 0000000..e1dbbcf --- /dev/null +++ b/Platforms/Nxp/LS1043aRdb/LS1043aWatchDog/LS1043aWatchDogDxe.inf @@ -0,0 +1,54 @@ +#/** LS1043aWatchDog.inf +# +# Component description file for LS1043a WatchDog module +# +# Copyright (c) 2016, Freescale Semiconductor, Inc. All rights reserved. +# +# This program and the accompanying materials +# are licensed and made available under the terms and conditions of the BSD License +# which accompanies this distribution. The full text of the license may be found at +# http://opensource.org/licenses/bsd-license.php +# +# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, +# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. +# +#**/ + +[Defines] + INF_VERSION = 0x00010005 + BASE_NAME = LS1043aWatchDogDxe + FILE_GUID = ebd705fb-fa92-46a7-b32b-7f566d944614 + MODULE_TYPE = DXE_DRIVER + VERSION_STRING = 1.0 + + ENTRY_POINT = LS1043aWdogInitialize + +[Sources.common] + LS1043aWatchDog.c + +[Packages] + MdePkg/MdePkg.dec + EmbeddedPkg/EmbeddedPkg.dec + ArmPkg/ArmPkg.dec + ArmPlatformPkg/ArmPlatformPkg.dec + OpenPlatformPkg/Platforms/Nxp/LS1043aRdb/LS1043aRdbPkg.dec + +[LibraryClasses] + BaseLib + BaseMemoryLib + DebugLib + IoLib + PcdLib + UefiLib + UefiBootServicesTableLib + UefiDriverEntryPoint + UefiRuntimeServicesTableLib + +[Pcd] + gArmPlatformTokenSpaceGuid.PcdLS1043aWatchDogBase + +[Protocols] + gEfiWatchdogTimerArchProtocolGuid + +[Depex] + TRUE
On 17 October 2016 at 21:04, Bhupesh Sharma bhupesh.sharma@freescale.com wrote:
From: Sakar Arora sakar.arora@nxp.com
This patch adds support for the Watchdog timer present on the LS1043A SoC.
The patch installs Watchdog timer arch protocol and implements APIs necessary for the same.
Signed-off-by: Sakar Arora sakar.arora@nxp.com
.../LS1043aRdb/LS1043aWatchDog/LS1043aWatchDog.c | 355 +++++++++++++++++++++ .../LS1043aWatchDog/LS1043aWatchDogDxe.inf | 54 ++++ 2 files changed, 409 insertions(+) create mode 100644 Platforms/Nxp/LS1043aRdb/LS1043aWatchDog/LS1043aWatchDog.c create mode 100644 Platforms/Nxp/LS1043aRdb/LS1043aWatchDog/LS1043aWatchDogDxe.inf
diff --git a/Platforms/Nxp/LS1043aRdb/LS1043aWatchDog/LS1043aWatchDog.c b/Platforms/Nxp/LS1043aRdb/LS1043aWatchDog/LS1043aWatchDog.c new file mode 100644 index 0000000..ea298f9 --- /dev/null +++ b/Platforms/Nxp/LS1043aRdb/LS1043aWatchDog/LS1043aWatchDog.c @@ -0,0 +1,355 @@ +/** LS1043aWatchDog.c +* +* Based on Watchdog driver implemenation available in +* ArmPlatformPkg/Drivers/SP805WatchdogDxe/SP805Watchdog.c +* +* Copyright (c) 2011-2013, ARM Limited. All rights reserved. +* Copyright (c) 2016, Freescale Semiconductor, Inc. All rights reserved. +* +* This program and the accompanying materials +* are licensed and made available under the terms and conditions of the BSD License +* which accompanies this distribution. The full text of the license may be found at +* http://opensource.org/licenses/bsd-license.php +* +* THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, +* WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. +* +**/
+#include <PiDxe.h>
+#include <Library/BaseLib.h> +#include <Library/BaseMemoryLib.h> +#include <Library/DebugLib.h> +#include <Library/IoLib.h> +#include <Library/PcdLib.h> +#include <Library/UefiBootServicesTableLib.h> +#include <Library/UefiRuntimeServicesTableLib.h> +#include <Library/UefiLib.h>
+#include <Protocol/WatchdogTimer.h> +#include <Library/PlatformLib.h>
+#define LS1043A_WT_MAX_TIME 128 +#define LS1043A_WD_COUNT(sec) (((sec) * 2 - 1) << 8) +#define LS1043A_WD_SEC(cnt) (((cnt) + 1) / 2)
+EFI_EVENT EfiExitBootServicesEvent = (EFI_EVENT)NULL;
+inline +VOID +LS1043aWdogPing (
- VOID
- )
+{
- MmioWriteBe16(WDOG1_BASE_ADDR + WDOG_WSR_OFFSET, WDOG_SERVICE_SEQ1);
- MmioWriteBe16(WDOG1_BASE_ADDR + WDOG_WSR_OFFSET, WDOG_SERVICE_SEQ2);
+}
+/**
- Stop the LS1043aWdog watchdog timer from counting down by disabling interrupts.
+**/ +inline +VOID +LS1043aWdogStop (
- VOID
- )
+{
- // LS1043a Watchdog cannot be disabled by software once started.
- // At best, we can keep pinging the watchdog
- LS1043aWdogPing();
+}
+/**
- Starts the LS1043aWdog counting down by enabling interrupts.
- The count down will start from the value stored in the Load register,
- not from the value where it was previously stopped.
+**/ +inline +VOID +LS1043aWdogStart (
- VOID
- )
+{
- /* Watchdog is enabled already in LS1043aWdogInitialize - time to reload the timeout value */
- LS1043aWdogPing();
+}
+/**
- On exiting boot services we must make sure the LS1043aWdog Watchdog Timer
- is stopped.
+**/ +VOID +EFIAPI +ExitBootServicesEvent (
- IN EFI_EVENT Event,
- IN VOID *Context
- )
+{
- LS1043aWdogStop();
+}
+/**
- This function registers the handler NotifyFunction so it is called every time
- the watchdog timer expires. It also passes the amount of time since the last
- handler call to the NotifyFunction.
- If NotifyFunction is not NULL and a handler is not already registered,
- then the new handler is registered and EFI_SUCCESS is returned.
- If NotifyFunction is NULL, and a handler is already registered,
- then that handler is unregistered.
- If an attempt is made to register a handler when a handler is already registered,
- then EFI_ALREADY_STARTED is returned.
- If an attempt is made to unregister a handler when a handler is not registered,
- then EFI_INVALID_PARAMETER is returned.
- @param This The EFI_TIMER_ARCH_PROTOCOL instance.
- @param NotifyFunction The function to call when a timer interrupt fires. This
function executes at TPL_HIGH_LEVEL. The DXE Core will
register a handler for the timer interrupt, so it can know
how much time has passed. This information is used to
signal timer based events. NULL will unregister the handler.
- @retval EFI_SUCCESS The watchdog timer handler was registered.
- @retval EFI_ALREADY_STARTED NotifyFunction is not NULL, and a handler is already
registered.
- @retval EFI_INVALID_PARAMETER NotifyFunction is NULL, and a handler was not
previously registered.
+**/ +EFI_STATUS +EFIAPI +LS1043aWdogRegisterHandler (
- IN CONST EFI_WATCHDOG_TIMER_ARCH_PROTOCOL *This,
- IN EFI_WATCHDOG_TIMER_NOTIFY NotifyFunction
- )
+{
- // ERROR: This function is not supported.
- // The hardware watchdog will reset the board
- return EFI_INVALID_PARAMETER;
+}
+/**
- This function adjusts the period of timer interrupts to the value specified
- by TimerPeriod. If the timer period is updated, then the selected timer
- period is stored in EFI_TIMER.TimerPeriod, and EFI_SUCCESS is returned. If
- the timer hardware is not programmable, then EFI_UNSUPPORTED is returned.
- If an error occurs while attempting to update the timer period, then the
- timer hardware will be put back in its state prior to this call, and
- EFI_DEVICE_ERROR is returned. If TimerPeriod is 0, then the timer interrupt
- is disabled. This is not the same as disabling the CPU's interrupts.
- Instead, it must either turn off the timer hardware, or it must adjust the
- interrupt controller so that a CPU interrupt is not generated when the timer
- interrupt fires.
- @param This The EFI_TIMER_ARCH_PROTOCOL instance.
- @param TimerPeriod The rate to program the timer interrupt in 100 nS units. If
the timer hardware is not programmable, then EFI_UNSUPPORTED is
returned. If the timer is programmable, then the timer period
will be rounded up to the nearest timer period that is supported
by the timer hardware. If TimerPeriod is set to 0, then the
timer interrupts will be disabled.
- @retval EFI_SUCCESS The timer period was changed.
- @retval EFI_UNSUPPORTED The platform cannot change the period of the timer interrupt.
- @retval EFI_DEVICE_ERROR The timer period could not be changed due to a device error.
+**/ +EFI_STATUS +EFIAPI +LS1043aWdogSetTimerPeriod (
- IN CONST EFI_WATCHDOG_TIMER_ARCH_PROTOCOL *This,
- IN UINT64 TimerPeriod // In 100ns units
- )
+{
- EFI_STATUS Status = EFI_SUCCESS;
- UINT64 TimerPeriodInSec;
- UINT16 Val;
- if( TimerPeriod == 0 ) {
- // This is a watchdog stop request
- LS1043aWdogStop();
- goto EXIT;
- } else {
- // Convert the TimerPeriod (in 100 ns unit) to an equivalent second value
- TimerPeriodInSec = DivU64x32(TimerPeriod, 10000000);
- // The registers in the LS1043aWdog are only 32 bits
- if(TimerPeriodInSec > LS1043A_WT_MAX_TIME) {
// We could load the watchdog with the maximum supported value but
// if a smaller value was requested, this could have the watchdog
// triggering before it was intended.
// Better generate an error to let the caller know.
Status = EFI_DEVICE_ERROR;
goto EXIT;
- }
- // set the new timeout value in the WCR
- Val = MmioReadBe16(WDOG1_BASE_ADDR + WDOG_WCR_OFFSET);
- Val &= ~WDOG_WCR_WT;
- // Convert the timeout value from Seconds to timer count
- Val |= ((LS1043A_WD_COUNT(TimerPeriodInSec) & 0xff00) << 8);
- MmioWriteBe16(WDOG1_BASE_ADDR + WDOG_WCR_OFFSET, Val);
- // Start the watchdog
- LS1043aWdogStart();
- }
- EXIT:
- return Status;
+}
+/**
- This function retrieves the period of timer interrupts in 100 ns units,
- returns that value in TimerPeriod, and returns EFI_SUCCESS. If TimerPeriod
- is NULL, then EFI_INVALID_PARAMETER is returned. If a TimerPeriod of 0 is
- returned, then the timer is currently disabled.
- @param This The EFI_TIMER_ARCH_PROTOCOL instance.
- @param TimerPeriod A pointer to the timer period to retrieve in 100 ns units. If
0 is returned, then the timer is currently disabled.
- @retval EFI_SUCCESS The timer period was returned in TimerPeriod.
- @retval EFI_INVALID_PARAMETER TimerPeriod is NULL.
+**/ +EFI_STATUS +EFIAPI +LS1043aWdogGetTimerPeriod (
- IN CONST EFI_WATCHDOG_TIMER_ARCH_PROTOCOL *This,
- OUT UINT64 *TimerPeriod
- )
+{
- EFI_STATUS Status = EFI_SUCCESS;
- UINT64 ReturnValue;
- UINT16 Val;
- if (TimerPeriod == NULL) {
- return EFI_INVALID_PARAMETER;
- }
- // Check if the watchdog is stopped
- if ( (MmioReadBe16(WDOG1_BASE_ADDR + WDOG_WCR_OFFSET) & WDOG_WCR_WDE) == 0 ) {
- // It is stopped, so return zero.
- ReturnValue = 0;
- } else {
- // Convert the Watchdog ticks into equivalent TimerPeriod second
- // value.
- Val = (MmioReadBe16(WDOG1_BASE_ADDR + WDOG_WCR_OFFSET) & WDOG_WCR_WT ) >> 8;
- ReturnValue = LS1043A_WD_SEC(Val);
- }
- *TimerPeriod = ReturnValue;
- return Status;
+}
+/**
- Interface structure for the Watchdog Architectural Protocol.
- @par Protocol Description:
- This protocol provides a service to set the amount of time to wait
- before firing the watchdog timer, and it also provides a service to
- register a handler that is invoked when the watchdog timer fires.
- @par When the watchdog timer fires, control will be passed to a handler
- if one has been registered. If no handler has been registered,
- or the registered handler returns, then the system will be
- reset by calling the Runtime Service ResetSystem().
- @param RegisterHandler
- Registers a handler that will be called each time the
- watchdogtimer interrupt fires. TimerPeriod defines the minimum
- time between timer interrupts, so TimerPeriod will also
- be the minimum time between calls to the registered
- handler.
- NOTE: If the watchdog resets the system in hardware, then
this function will not have any chance of executing.
- @param SetTimerPeriod
- Sets the period of the timer interrupt in 100 nS units.
- This function is optional, and may return EFI_UNSUPPORTED.
- If this function is supported, then the timer period will
- be rounded up to the nearest supported timer period.
- @param GetTimerPeriod
- Retrieves the period of the timer interrupt in 100 nS units.
+**/ +EFI_WATCHDOG_TIMER_ARCH_PROTOCOL gWatchdogTimer = {
- (EFI_WATCHDOG_TIMER_REGISTER_HANDLER) LS1043aWdogRegisterHandler,
- (EFI_WATCHDOG_TIMER_SET_TIMER_PERIOD) LS1043aWdogSetTimerPeriod,
- (EFI_WATCHDOG_TIMER_GET_TIMER_PERIOD) LS1043aWdogGetTimerPeriod
+};
+/**
- Initialize the state information for the Watchdog Timer Architectural Protocol.
- @param ImageHandle of the loaded driver
- @param SystemTable Pointer to the System Table
- @retval EFI_SUCCESS Protocol registered
- @retval EFI_OUT_OF_RESOURCES Cannot allocate protocol data structure
- @retval EFI_DEVICE_ERROR Hardware problems
+**/ +EFI_STATUS +EFIAPI +LS1043aWdogInitialize (
- IN EFI_HANDLE ImageHandle,
- IN EFI_SYSTEM_TABLE *SystemTable
- )
+{
- EFI_STATUS Status;
- EFI_HANDLE Handle;
- UINT16 Val;
- Val = MmioReadBe16(WDOG1_BASE_ADDR + WDOG_WCR_OFFSET);
- Val &= ~WDOG_WCR_WT;
- Val &= ~WDOG_WCR_WDE;
- Val |= LS1043A_WD_COUNT(LS1043A_WT_MAX_TIME) & 0xff00;
- MmioWriteBe16(WDOG1_BASE_ADDR + WDOG_WCR_OFFSET, Val);
- Val |= WDOG_WCR_WDE;
- //
- // Make sure the Watchdog Timer Architectural Protocol has not been installed in the system yet.
- // This will avoid conflicts with the universal watchdog
- //
- ASSERT_PROTOCOL_ALREADY_INSTALLED (NULL, &gEfiWatchdogTimerArchProtocolGuid);
- // Register for an ExitBootServicesEvent
- Status = gBS->CreateEvent (EVT_SIGNAL_EXIT_BOOT_SERVICES, TPL_NOTIFY, ExitBootServicesEvent, NULL, &EfiExitBootServicesEvent);
- if (EFI_ERROR(Status)) {
- Status = EFI_OUT_OF_RESOURCES;
- goto EXIT;
- }
- // Install the Timer Architectural Protocol onto a new handle
- Handle = NULL;
- Status = gBS->InstallMultipleProtocolInterfaces(
&Handle,
&gEfiWatchdogTimerArchProtocolGuid, &gWatchdogTimer,
NULL
);
- if (EFI_ERROR(Status)) {
- Status = EFI_OUT_OF_RESOURCES;
- goto EXIT;
- }
+EXIT:
- if(EFI_ERROR(Status)) {
- // The watchdog failed to initialize
- ASSERT(FALSE);
- }
LS1043aWdogPing();
- return Status;
+} diff --git a/Platforms/Nxp/LS1043aRdb/LS1043aWatchDog/LS1043aWatchDogDxe.inf b/Platforms/Nxp/LS1043aRdb/LS1043aWatchDog/LS1043aWatchDogDxe.inf new file mode 100644 index 0000000..e1dbbcf --- /dev/null +++ b/Platforms/Nxp/LS1043aRdb/LS1043aWatchDog/LS1043aWatchDogDxe.inf @@ -0,0 +1,54 @@ +#/** LS1043aWatchDog.inf +# +# Component description file for LS1043a WatchDog module +# +# Copyright (c) 2016, Freescale Semiconductor, Inc. All rights reserved. +# +# This program and the accompanying materials +# are licensed and made available under the terms and conditions of the BSD License +# which accompanies this distribution. The full text of the license may be found at +# http://opensource.org/licenses/bsd-license.php +# +# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, +# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. +# +#**/
+[Defines]
- INF_VERSION = 0x00010005
- BASE_NAME = LS1043aWatchDogDxe
- FILE_GUID = ebd705fb-fa92-46a7-b32b-7f566d944614
fresh GUID please
- MODULE_TYPE = DXE_DRIVER
- VERSION_STRING = 1.0
- ENTRY_POINT = LS1043aWdogInitialize
+[Sources.common]
- LS1043aWatchDog.c
+[Packages]
- MdePkg/MdePkg.dec
- EmbeddedPkg/EmbeddedPkg.dec
- ArmPkg/ArmPkg.dec
- ArmPlatformPkg/ArmPlatformPkg.dec
- OpenPlatformPkg/Platforms/Nxp/LS1043aRdb/LS1043aRdbPkg.dec
+[LibraryClasses]
- BaseLib
- BaseMemoryLib
- DebugLib
- IoLib
- PcdLib
- UefiLib
- UefiBootServicesTableLib
- UefiDriverEntryPoint
- UefiRuntimeServicesTableLib
Are you using all of these?
+[Pcd]
- gArmPlatformTokenSpaceGuid.PcdLS1043aWatchDogBase
+[Protocols]
- gEfiWatchdogTimerArchProtocolGuid
+[Depex]
- TRUE
-- 1.9.1
Hi Ard,
Thanks for the review comments. Please see my replies inline.
From: Ard Biesheuvel [mailto:ard.biesheuvel@linaro.org] Sent: Tuesday, October 18, 2016 3:29 PM
On 17 October 2016 at 21:04, Bhupesh Sharma bhupesh.sharma@freescale.com wrote:
From: Sakar Arora sakar.arora@nxp.com
This patch adds support for the Watchdog timer present on the LS1043A SoC.
The patch installs Watchdog timer arch protocol and implements APIs necessary for the same.
Signed-off-by: Sakar Arora sakar.arora@nxp.com
.../LS1043aRdb/LS1043aWatchDog/LS1043aWatchDog.c | 355
+++++++++++++++++++++
.../LS1043aWatchDog/LS1043aWatchDogDxe.inf | 54 ++++ 2 files changed, 409 insertions(+) create mode 100644 Platforms/Nxp/LS1043aRdb/LS1043aWatchDog/LS1043aWatchDog.c create mode 100644 Platforms/Nxp/LS1043aRdb/LS1043aWatchDog/LS1043aWatchDogDxe.inf
diff --git a/Platforms/Nxp/LS1043aRdb/LS1043aWatchDog/LS1043aWatchDog.c b/Platforms/Nxp/LS1043aRdb/LS1043aWatchDog/LS1043aWatchDog.c new file mode 100644 index 0000000..ea298f9 --- /dev/null +++ b/Platforms/Nxp/LS1043aRdb/LS1043aWatchDog/LS1043aWatchDog.c @@ -0,0 +1,355 @@ +/** LS1043aWatchDog.c +* +* Based on Watchdog driver implemenation available in +* ArmPlatformPkg/Drivers/SP805WatchdogDxe/SP805Watchdog.c +* +* Copyright (c) 2011-2013, ARM Limited. All rights reserved. +* Copyright (c) 2016, Freescale Semiconductor, Inc. All rights
reserved.
+* +* This program and the accompanying materials +* are licensed and made available under the terms and conditions of +the BSD License +* which accompanies this distribution. The full text of the
license
+may be found at +* http://opensource.org/licenses/bsd-license.php +* +* THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" +BASIS, +* WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS
OR IMPLIED.
+* +**/
+#include <PiDxe.h>
+#include <Library/BaseLib.h> +#include <Library/BaseMemoryLib.h> +#include <Library/DebugLib.h> +#include <Library/IoLib.h> +#include <Library/PcdLib.h> +#include <Library/UefiBootServicesTableLib.h> +#include <Library/UefiRuntimeServicesTableLib.h> +#include <Library/UefiLib.h>
+#include <Protocol/WatchdogTimer.h> +#include <Library/PlatformLib.h>
+#define LS1043A_WT_MAX_TIME 128 +#define LS1043A_WD_COUNT(sec) (((sec) * 2 - 1) << 8) +#define LS1043A_WD_SEC(cnt) (((cnt) + 1) / 2)
+EFI_EVENT EfiExitBootServicesEvent =
(EFI_EVENT)NULL;
+inline +VOID +LS1043aWdogPing (
- VOID
- )
+{
- MmioWriteBe16(WDOG1_BASE_ADDR + WDOG_WSR_OFFSET,
+WDOG_SERVICE_SEQ1);
- MmioWriteBe16(WDOG1_BASE_ADDR + WDOG_WSR_OFFSET,
+WDOG_SERVICE_SEQ2); }
+/**
- Stop the LS1043aWdog watchdog timer from counting down by
disabling interrupts.
+**/ +inline +VOID +LS1043aWdogStop (
- VOID
- )
+{
- // LS1043a Watchdog cannot be disabled by software once started.
- // At best, we can keep pinging the watchdog
- LS1043aWdogPing();
+}
+/**
- Starts the LS1043aWdog counting down by enabling interrupts.
- The count down will start from the value stored in the Load
+register,
- not from the value where it was previously stopped.
+**/ +inline +VOID +LS1043aWdogStart (
- VOID
- )
+{
- /* Watchdog is enabled already in LS1043aWdogInitialize - time to
+reload the timeout value */
- LS1043aWdogPing();
+}
+/**
- On exiting boot services we must make sure the LS1043aWdog
Watchdog Timer
- is stopped.
+**/ +VOID +EFIAPI +ExitBootServicesEvent (
- IN EFI_EVENT Event,
- IN VOID *Context
- )
+{
- LS1043aWdogStop();
+}
+/**
- This function registers the handler NotifyFunction so it is called
+every time
- the watchdog timer expires. It also passes the amount of time
+since the last
- handler call to the NotifyFunction.
- If NotifyFunction is not NULL and a handler is not already
+registered,
- then the new handler is registered and EFI_SUCCESS is returned.
- If NotifyFunction is NULL, and a handler is already registered,
- then that handler is unregistered.
- If an attempt is made to register a handler when a handler is
+already registered,
- then EFI_ALREADY_STARTED is returned.
- If an attempt is made to unregister a handler when a handler is
not
+registered,
- then EFI_INVALID_PARAMETER is returned.
- @param This The EFI_TIMER_ARCH_PROTOCOL instance.
- @param NotifyFunction The function to call when a timer
interrupt fires. This
function executes at TPL_HIGH_LEVEL. The
DXE Core will
register a handler for the timer
interrupt, so it can know
how much time has passed. This
information is used to
signal timer based events. NULL will
unregister the handler.
- @retval EFI_SUCCESS The watchdog timer handler was
registered.
- @retval EFI_ALREADY_STARTED NotifyFunction is not NULL, and a
handler is already
registered.
- @retval EFI_INVALID_PARAMETER NotifyFunction is NULL, and a
handler was not
previously registered.
+**/ +EFI_STATUS +EFIAPI +LS1043aWdogRegisterHandler (
- IN CONST EFI_WATCHDOG_TIMER_ARCH_PROTOCOL *This,
- IN EFI_WATCHDOG_TIMER_NOTIFY NotifyFunction
- )
+{
- // ERROR: This function is not supported.
- // The hardware watchdog will reset the board
- return EFI_INVALID_PARAMETER;
+}
+/**
- This function adjusts the period of timer interrupts to the value
- specified by TimerPeriod. If the timer period is updated, then
the
- selected timer period is stored in EFI_TIMER.TimerPeriod, and
- EFI_SUCCESS is returned. If the timer hardware is not
programmable, then EFI_UNSUPPORTED is returned.
- If an error occurs while attempting to update the timer period,
- then the timer hardware will be put back in its state prior to
this
- call, and EFI_DEVICE_ERROR is returned. If TimerPeriod is 0, then
- the timer interrupt is disabled. This is not the same as
disabling the CPU's interrupts.
- Instead, it must either turn off the timer hardware, or it must
- adjust the interrupt controller so that a CPU interrupt is not
- generated when the timer interrupt fires.
- @param This The EFI_TIMER_ARCH_PROTOCOL instance.
- @param TimerPeriod The rate to program the timer interrupt
in 100 nS units. If
the timer hardware is not programmable,
then EFI_UNSUPPORTED is
returned. If the timer is programmable,
then the timer period
will be rounded up to the nearest timer
period that is supported
by the timer hardware. If TimerPeriod is
set to 0, then the
timer interrupts will be disabled.
- @retval EFI_SUCCESS The timer period was changed.
- @retval EFI_UNSUPPORTED The platform cannot change the
period of the timer interrupt.
- @retval EFI_DEVICE_ERROR The timer period could not be
changed due to a device error.
+**/ +EFI_STATUS +EFIAPI +LS1043aWdogSetTimerPeriod (
- IN CONST EFI_WATCHDOG_TIMER_ARCH_PROTOCOL *This,
- IN UINT64 TimerPeriod // In
100ns units
- )
+{
- EFI_STATUS Status = EFI_SUCCESS;
- UINT64 TimerPeriodInSec;
- UINT16 Val;
- if( TimerPeriod == 0 ) {
- // This is a watchdog stop request
- LS1043aWdogStop();
- goto EXIT;
- } else {
- // Convert the TimerPeriod (in 100 ns unit) to an equivalent
- second value
- TimerPeriodInSec = DivU64x32(TimerPeriod, 10000000);
- // The registers in the LS1043aWdog are only 32 bits
- if(TimerPeriodInSec > LS1043A_WT_MAX_TIME) {
// We could load the watchdog with the maximum supported value
but
// if a smaller value was requested, this could have the
watchdog
// triggering before it was intended.
// Better generate an error to let the caller know.
Status = EFI_DEVICE_ERROR;
goto EXIT;
- }
- // set the new timeout value in the WCR
- Val = MmioReadBe16(WDOG1_BASE_ADDR + WDOG_WCR_OFFSET);
- Val &= ~WDOG_WCR_WT;
- // Convert the timeout value from Seconds to timer count
- Val |= ((LS1043A_WD_COUNT(TimerPeriodInSec) & 0xff00) << 8);
- MmioWriteBe16(WDOG1_BASE_ADDR + WDOG_WCR_OFFSET, Val);
- // Start the watchdog
- LS1043aWdogStart();
- }
- EXIT:
- return Status;
+}
+/**
- This function retrieves the period of timer interrupts in 100 ns
+units,
- returns that value in TimerPeriod, and returns EFI_SUCCESS. If
+TimerPeriod
- is NULL, then EFI_INVALID_PARAMETER is returned. If a TimerPeriod
+of 0 is
- returned, then the timer is currently disabled.
- @param This The EFI_TIMER_ARCH_PROTOCOL instance.
- @param TimerPeriod A pointer to the timer period to retrieve
in 100 ns units. If
0 is returned, then the timer is
currently disabled.
- @retval EFI_SUCCESS The timer period was returned in
TimerPeriod.
- @retval EFI_INVALID_PARAMETER TimerPeriod is NULL.
+**/ +EFI_STATUS +EFIAPI +LS1043aWdogGetTimerPeriod (
- IN CONST EFI_WATCHDOG_TIMER_ARCH_PROTOCOL *This,
- OUT UINT64 *TimerPeriod
- )
+{
- EFI_STATUS Status = EFI_SUCCESS;
- UINT64 ReturnValue;
- UINT16 Val;
- if (TimerPeriod == NULL) {
- return EFI_INVALID_PARAMETER;
- }
- // Check if the watchdog is stopped if (
- (MmioReadBe16(WDOG1_BASE_ADDR + WDOG_WCR_OFFSET) & WDOG_WCR_WDE) ==
0 ) {
- // It is stopped, so return zero.
- ReturnValue = 0;
- } else {
- // Convert the Watchdog ticks into equivalent TimerPeriod second
- // value.
- Val = (MmioReadBe16(WDOG1_BASE_ADDR + WDOG_WCR_OFFSET) &
WDOG_WCR_WT ) >> 8;
- ReturnValue = LS1043A_WD_SEC(Val); }
- *TimerPeriod = ReturnValue;
- return Status;
+}
+/**
- Interface structure for the Watchdog Architectural Protocol.
- @par Protocol Description:
- This protocol provides a service to set the amount of time to wait
- before firing the watchdog timer, and it also provides a service to
- register a handler that is invoked when the watchdog timer fires.
- @par When the watchdog timer fires, control will be passed to a
- handler if one has been registered. If no handler has been
- registered, or the registered handler returns, then the system
will
- be reset by calling the Runtime Service ResetSystem().
- @param RegisterHandler
- Registers a handler that will be called each time the
- watchdogtimer interrupt fires. TimerPeriod defines the minimum
- time between timer interrupts, so TimerPeriod will also be the
- minimum time between calls to the registered handler.
- NOTE: If the watchdog resets the system in hardware, then
this function will not have any chance of executing.
- @param SetTimerPeriod
- Sets the period of the timer interrupt in 100 nS units.
- This function is optional, and may return EFI_UNSUPPORTED.
- If this function is supported, then the timer period will be
- rounded up to the nearest supported timer period.
- @param GetTimerPeriod
- Retrieves the period of the timer interrupt in 100 nS units.
+**/ +EFI_WATCHDOG_TIMER_ARCH_PROTOCOL gWatchdogTimer = {
- (EFI_WATCHDOG_TIMER_REGISTER_HANDLER) LS1043aWdogRegisterHandler,
- (EFI_WATCHDOG_TIMER_SET_TIMER_PERIOD) LS1043aWdogSetTimerPeriod,
- (EFI_WATCHDOG_TIMER_GET_TIMER_PERIOD) LS1043aWdogGetTimerPeriod };
+/**
- Initialize the state information for the Watchdog Timer
Architectural Protocol.
- @param ImageHandle of the loaded driver
- @param SystemTable Pointer to the System Table
- @retval EFI_SUCCESS Protocol registered
- @retval EFI_OUT_OF_RESOURCES Cannot allocate protocol data
structure
- @retval EFI_DEVICE_ERROR Hardware problems
+**/ +EFI_STATUS +EFIAPI +LS1043aWdogInitialize (
- IN EFI_HANDLE ImageHandle,
- IN EFI_SYSTEM_TABLE *SystemTable
- )
+{
- EFI_STATUS Status;
- EFI_HANDLE Handle;
- UINT16 Val;
- Val = MmioReadBe16(WDOG1_BASE_ADDR + WDOG_WCR_OFFSET);
- Val &= ~WDOG_WCR_WT;
- Val &= ~WDOG_WCR_WDE;
- Val |= LS1043A_WD_COUNT(LS1043A_WT_MAX_TIME) & 0xff00;
- MmioWriteBe16(WDOG1_BASE_ADDR + WDOG_WCR_OFFSET, Val);
- Val |= WDOG_WCR_WDE;
- //
- // Make sure the Watchdog Timer Architectural Protocol has not
been installed in the system yet.
- // This will avoid conflicts with the universal watchdog //
- ASSERT_PROTOCOL_ALREADY_INSTALLED (NULL,
- &gEfiWatchdogTimerArchProtocolGuid);
- // Register for an ExitBootServicesEvent Status = gBS-
CreateEvent
- (EVT_SIGNAL_EXIT_BOOT_SERVICES, TPL_NOTIFY, ExitBootServicesEvent,
- NULL, &EfiExitBootServicesEvent); if (EFI_ERROR(Status)) {
- Status = EFI_OUT_OF_RESOURCES;
- goto EXIT;
- }
- // Install the Timer Architectural Protocol onto a new handle
- Handle = NULL; Status = gBS->InstallMultipleProtocolInterfaces(
&Handle,
&gEfiWatchdogTimerArchProtocolGuid,
&gWatchdogTimer,
NULL
);
- if (EFI_ERROR(Status)) {
- Status = EFI_OUT_OF_RESOURCES;
- goto EXIT;
- }
+EXIT:
- if(EFI_ERROR(Status)) {
- // The watchdog failed to initialize
- ASSERT(FALSE);
- }
LS1043aWdogPing();
- return Status;
+} diff --git a/Platforms/Nxp/LS1043aRdb/LS1043aWatchDog/LS1043aWatchDogDxe.inf b/Platforms/Nxp/LS1043aRdb/LS1043aWatchDog/LS1043aWatchDogDxe.inf new file mode 100644 index 0000000..e1dbbcf --- /dev/null +++ b/Platforms/Nxp/LS1043aRdb/LS1043aWatchDog/LS1043aWatchDogDxe.inf @@ -0,0 +1,54 @@ +#/** LS1043aWatchDog.inf +# +# Component description file for LS1043a WatchDog module # # +Copyright (c) 2016, Freescale Semiconductor, Inc. All rights
reserved.
+# +# This program and the accompanying materials # are licensed and +made available under the terms and conditions of the BSD License # +which accompanies this distribution. The full text of the license +may be found at # http://opensource.org/licenses/bsd-license.php +# +# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" +BASIS, # WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER
EXPRESS OR IMPLIED.
+# +#**/
+[Defines]
- INF_VERSION = 0x00010005
- BASE_NAME = LS1043aWatchDogDxe
- FILE_GUID = ebd705fb-fa92-46a7-b32b-
7f566d944614
fresh GUID please
Ok.
- MODULE_TYPE = DXE_DRIVER
- VERSION_STRING = 1.0
- ENTRY_POINT = LS1043aWdogInitialize
+[Sources.common]
- LS1043aWatchDog.c
+[Packages]
- MdePkg/MdePkg.dec
- EmbeddedPkg/EmbeddedPkg.dec
- ArmPkg/ArmPkg.dec
- ArmPlatformPkg/ArmPlatformPkg.dec
- OpenPlatformPkg/Platforms/Nxp/LS1043aRdb/LS1043aRdbPkg.dec
+[LibraryClasses]
- BaseLib
- BaseMemoryLib
- DebugLib
- IoLib
- PcdLib
- UefiLib
- UefiBootServicesTableLib
- UefiDriverEntryPoint
- UefiRuntimeServicesTableLib
Are you using all of these?
Understood. Will remove the extra ones in V2.
+[Pcd]
- gArmPlatformTokenSpaceGuid.PcdLS1043aWatchDogBase
+[Protocols]
- gEfiWatchdogTimerArchProtocolGuid
+[Depex]
- TRUE
-- 1.9.1
Regards, Bhupesh
On Tue, Oct 18, 2016 at 01:34:12AM +0530, Bhupesh Sharma wrote:
From: Sakar Arora sakar.arora@nxp.com
This patch adds support for the Watchdog timer present on the LS1043A SoC.
The patch installs Watchdog timer arch protocol and implements APIs necessary for the same.
Signed-off-by: Sakar Arora sakar.arora@nxp.com
.../LS1043aRdb/LS1043aWatchDog/LS1043aWatchDog.c | 355 +++++++++++++++++++++ .../LS1043aWatchDog/LS1043aWatchDogDxe.inf | 54 ++++ 2 files changed, 409 insertions(+) create mode 100644 Platforms/Nxp/LS1043aRdb/LS1043aWatchDog/LS1043aWatchDog.c create mode 100644 Platforms/Nxp/LS1043aRdb/LS1043aWatchDog/LS1043aWatchDogDxe.inf
diff --git a/Platforms/Nxp/LS1043aRdb/LS1043aWatchDog/LS1043aWatchDog.c b/Platforms/Nxp/LS1043aRdb/LS1043aWatchDog/LS1043aWatchDog.c new file mode 100644 index 0000000..ea298f9 --- /dev/null +++ b/Platforms/Nxp/LS1043aRdb/LS1043aWatchDog/LS1043aWatchDog.c @@ -0,0 +1,355 @@ +/** LS1043aWatchDog.c +* +* Based on Watchdog driver implemenation available in +* ArmPlatformPkg/Drivers/SP805WatchdogDxe/SP805Watchdog.c +* +* Copyright (c) 2011-2013, ARM Limited. All rights reserved. +* Copyright (c) 2016, Freescale Semiconductor, Inc. All rights reserved. +* +* This program and the accompanying materials +* are licensed and made available under the terms and conditions of the BSD License +* which accompanies this distribution. The full text of the license may be found at +* http://opensource.org/licenses/bsd-license.php +* +* THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, +* WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. +* +**/
+#include <PiDxe.h>
+#include <Library/BaseLib.h> +#include <Library/BaseMemoryLib.h> +#include <Library/DebugLib.h> +#include <Library/IoLib.h> +#include <Library/PcdLib.h> +#include <Library/UefiBootServicesTableLib.h> +#include <Library/UefiRuntimeServicesTableLib.h> +#include <Library/UefiLib.h>
+#include <Protocol/WatchdogTimer.h> +#include <Library/PlatformLib.h>
Sort, please.
+#define LS1043A_WT_MAX_TIME 128 +#define LS1043A_WD_COUNT(sec) (((sec) * 2 - 1) << 8) +#define LS1043A_WD_SEC(cnt) (((cnt) + 1) / 2)
+EFI_EVENT EfiExitBootServicesEvent = (EFI_EVENT)NULL;
STATIC and prefix m?
+inline
No inline please. I would expect the compiler to inline these anyway if they're marked STATIC (as they should be if not used externally). Please apply throughout.
+VOID +LS1043aWdogPing (
- VOID
- )
+{
- MmioWriteBe16(WDOG1_BASE_ADDR + WDOG_WSR_OFFSET, WDOG_SERVICE_SEQ1);
- MmioWriteBe16(WDOG1_BASE_ADDR + WDOG_WSR_OFFSET, WDOG_SERVICE_SEQ2);
+}
+/**
- Stop the LS1043aWdog watchdog timer from counting down by disabling interrupts.
+**/ +inline +VOID +LS1043aWdogStop (
- VOID
- )
+{
- // LS1043a Watchdog cannot be disabled by software once started.
- // At best, we can keep pinging the watchdog
- LS1043aWdogPing();
+}
+/**
- Starts the LS1043aWdog counting down by enabling interrupts.
- The count down will start from the value stored in the Load register,
- not from the value where it was previously stopped.
+**/ +inline +VOID +LS1043aWdogStart (
- VOID
- )
+{
- /* Watchdog is enabled already in LS1043aWdogInitialize - time to reload the timeout value */
- LS1043aWdogPing();
+}
+/**
- On exiting boot services we must make sure the LS1043aWdog Watchdog Timer
- is stopped.
+**/ +VOID +EFIAPI +ExitBootServicesEvent (
- IN EFI_EVENT Event,
- IN VOID *Context
- )
+{
- LS1043aWdogStop();
+}
+/**
- This function registers the handler NotifyFunction so it is called every time
- the watchdog timer expires. It also passes the amount of time since the last
- handler call to the NotifyFunction.
- If NotifyFunction is not NULL and a handler is not already registered,
- then the new handler is registered and EFI_SUCCESS is returned.
- If NotifyFunction is NULL, and a handler is already registered,
- then that handler is unregistered.
- If an attempt is made to register a handler when a handler is already registered,
- then EFI_ALREADY_STARTED is returned.
- If an attempt is made to unregister a handler when a handler is not registered,
- then EFI_INVALID_PARAMETER is returned.
- @param This The EFI_TIMER_ARCH_PROTOCOL instance.
- @param NotifyFunction The function to call when a timer interrupt fires. This
function executes at TPL_HIGH_LEVEL. The DXE Core will
register a handler for the timer interrupt, so it can know
how much time has passed. This information is used to
signal timer based events. NULL will unregister the handler.
- @retval EFI_SUCCESS The watchdog timer handler was registered.
- @retval EFI_ALREADY_STARTED NotifyFunction is not NULL, and a handler is already
registered.
- @retval EFI_INVALID_PARAMETER NotifyFunction is NULL, and a handler was not
previously registered.
+**/ +EFI_STATUS +EFIAPI +LS1043aWdogRegisterHandler (
- IN CONST EFI_WATCHDOG_TIMER_ARCH_PROTOCOL *This,
- IN EFI_WATCHDOG_TIMER_NOTIFY NotifyFunction
- )
+{
- // ERROR: This function is not supported.
- // The hardware watchdog will reset the board
- return EFI_INVALID_PARAMETER;
+}
+/**
- This function adjusts the period of timer interrupts to the value specified
- by TimerPeriod. If the timer period is updated, then the selected timer
- period is stored in EFI_TIMER.TimerPeriod, and EFI_SUCCESS is returned. If
- the timer hardware is not programmable, then EFI_UNSUPPORTED is returned.
- If an error occurs while attempting to update the timer period, then the
- timer hardware will be put back in its state prior to this call, and
- EFI_DEVICE_ERROR is returned. If TimerPeriod is 0, then the timer interrupt
- is disabled. This is not the same as disabling the CPU's interrupts.
- Instead, it must either turn off the timer hardware, or it must adjust the
- interrupt controller so that a CPU interrupt is not generated when the timer
- interrupt fires.
- @param This The EFI_TIMER_ARCH_PROTOCOL instance.
- @param TimerPeriod The rate to program the timer interrupt in 100 nS units. If
the timer hardware is not programmable, then EFI_UNSUPPORTED is
returned. If the timer is programmable, then the timer period
will be rounded up to the nearest timer period that is supported
by the timer hardware. If TimerPeriod is set to 0, then the
timer interrupts will be disabled.
- @retval EFI_SUCCESS The timer period was changed.
- @retval EFI_UNSUPPORTED The platform cannot change the period of the timer interrupt.
- @retval EFI_DEVICE_ERROR The timer period could not be changed due to a device error.
+**/ +EFI_STATUS +EFIAPI +LS1043aWdogSetTimerPeriod (
- IN CONST EFI_WATCHDOG_TIMER_ARCH_PROTOCOL *This,
- IN UINT64 TimerPeriod // In 100ns units
- )
+{
- EFI_STATUS Status = EFI_SUCCESS;
- UINT64 TimerPeriodInSec;
- UINT16 Val;
- if( TimerPeriod == 0 ) {
- // This is a watchdog stop request
- LS1043aWdogStop();
- goto EXIT;
There is no cleanup to be done, so no need for the goto. Drop this goto.
- } else {
- // Convert the TimerPeriod (in 100 ns unit) to an equivalent second value
- TimerPeriodInSec = DivU64x32(TimerPeriod, 10000000);
- // The registers in the LS1043aWdog are only 32 bits
- if(TimerPeriodInSec > LS1043A_WT_MAX_TIME) {
// We could load the watchdog with the maximum supported value but
// if a smaller value was requested, this could have the watchdog
// triggering before it was intended.
// Better generate an error to let the caller know.
Status = EFI_DEVICE_ERROR;
goto EXIT;
Replace above two lines with return EFI_DEVICE_ERROR;
- }
- // set the new timeout value in the WCR
- Val = MmioReadBe16(WDOG1_BASE_ADDR + WDOG_WCR_OFFSET);
- Val &= ~WDOG_WCR_WT;
- // Convert the timeout value from Seconds to timer count
- Val |= ((LS1043A_WD_COUNT(TimerPeriodInSec) & 0xff00) << 8);
- MmioWriteBe16(WDOG1_BASE_ADDR + WDOG_WCR_OFFSET, Val);
- // Start the watchdog
- LS1043aWdogStart();
- }
- EXIT:
- return Status;
And these two with return EFI_SUCCESS;
+}
+/**
- This function retrieves the period of timer interrupts in 100 ns units,
- returns that value in TimerPeriod, and returns EFI_SUCCESS. If TimerPeriod
- is NULL, then EFI_INVALID_PARAMETER is returned. If a TimerPeriod of 0 is
- returned, then the timer is currently disabled.
- @param This The EFI_TIMER_ARCH_PROTOCOL instance.
- @param TimerPeriod A pointer to the timer period to retrieve in 100 ns units. If
0 is returned, then the timer is currently disabled.
- @retval EFI_SUCCESS The timer period was returned in TimerPeriod.
- @retval EFI_INVALID_PARAMETER TimerPeriod is NULL.
+**/ +EFI_STATUS +EFIAPI +LS1043aWdogGetTimerPeriod (
- IN CONST EFI_WATCHDOG_TIMER_ARCH_PROTOCOL *This,
- OUT UINT64 *TimerPeriod
- )
+{
- EFI_STATUS Status = EFI_SUCCESS;
- UINT64 ReturnValue;
- UINT16 Val;
- if (TimerPeriod == NULL) {
- return EFI_INVALID_PARAMETER;
- }
- // Check if the watchdog is stopped
- if ( (MmioReadBe16(WDOG1_BASE_ADDR + WDOG_WCR_OFFSET) & WDOG_WCR_WDE) == 0 ) {
No space padding at start/end.
- // It is stopped, so return zero.
- ReturnValue = 0;
- } else {
- // Convert the Watchdog ticks into equivalent TimerPeriod second
- // value.
- Val = (MmioReadBe16(WDOG1_BASE_ADDR + WDOG_WCR_OFFSET) & WDOG_WCR_WT ) >> 8;
Drop space before ).
- ReturnValue = LS1043A_WD_SEC(Val);
- }
- *TimerPeriod = ReturnValue;
- return Status;
+}
+/**
- Interface structure for the Watchdog Architectural Protocol.
- @par Protocol Description:
- This protocol provides a service to set the amount of time to wait
- before firing the watchdog timer, and it also provides a service to
- register a handler that is invoked when the watchdog timer fires.
- @par When the watchdog timer fires, control will be passed to a handler
- if one has been registered. If no handler has been registered,
- or the registered handler returns, then the system will be
- reset by calling the Runtime Service ResetSystem().
- @param RegisterHandler
- Registers a handler that will be called each time the
- watchdogtimer interrupt fires. TimerPeriod defines the minimum
- time between timer interrupts, so TimerPeriod will also
- be the minimum time between calls to the registered
- handler.
- NOTE: If the watchdog resets the system in hardware, then
this function will not have any chance of executing.
- @param SetTimerPeriod
- Sets the period of the timer interrupt in 100 nS units.
- This function is optional, and may return EFI_UNSUPPORTED.
- If this function is supported, then the timer period will
- be rounded up to the nearest supported timer period.
- @param GetTimerPeriod
- Retrieves the period of the timer interrupt in 100 nS units.
+**/ +EFI_WATCHDOG_TIMER_ARCH_PROTOCOL gWatchdogTimer = {
- (EFI_WATCHDOG_TIMER_REGISTER_HANDLER) LS1043aWdogRegisterHandler,
- (EFI_WATCHDOG_TIMER_SET_TIMER_PERIOD) LS1043aWdogSetTimerPeriod,
- (EFI_WATCHDOG_TIMER_GET_TIMER_PERIOD) LS1043aWdogGetTimerPeriod
+};
+/**
- Initialize the state information for the Watchdog Timer Architectural Protocol.
- @param ImageHandle of the loaded driver
- @param SystemTable Pointer to the System Table
- @retval EFI_SUCCESS Protocol registered
- @retval EFI_OUT_OF_RESOURCES Cannot allocate protocol data structure
- @retval EFI_DEVICE_ERROR Hardware problems
+**/ +EFI_STATUS +EFIAPI +LS1043aWdogInitialize (
- IN EFI_HANDLE ImageHandle,
- IN EFI_SYSTEM_TABLE *SystemTable
- )
+{
- EFI_STATUS Status;
- EFI_HANDLE Handle;
- UINT16 Val;
- Val = MmioReadBe16(WDOG1_BASE_ADDR + WDOG_WCR_OFFSET);
- Val &= ~WDOG_WCR_WT;
- Val &= ~WDOG_WCR_WDE;
- Val |= LS1043A_WD_COUNT(LS1043A_WT_MAX_TIME) & 0xff00;
- MmioWriteBe16(WDOG1_BASE_ADDR + WDOG_WCR_OFFSET, Val);
- Val |= WDOG_WCR_WDE;
- //
- // Make sure the Watchdog Timer Architectural Protocol has not been installed in the system yet.
- // This will avoid conflicts with the universal watchdog
- //
- ASSERT_PROTOCOL_ALREADY_INSTALLED (NULL, &gEfiWatchdogTimerArchProtocolGuid);
- // Register for an ExitBootServicesEvent
- Status = gBS->CreateEvent (EVT_SIGNAL_EXIT_BOOT_SERVICES, TPL_NOTIFY, ExitBootServicesEvent, NULL, &EfiExitBootServicesEvent);
- if (EFI_ERROR(Status)) {
- Status = EFI_OUT_OF_RESOURCES;
- goto EXIT;
- }
- // Install the Timer Architectural Protocol onto a new handle
- Handle = NULL;
- Status = gBS->InstallMultipleProtocolInterfaces(
&Handle,
&gEfiWatchdogTimerArchProtocolGuid, &gWatchdogTimer,
NULL
);
- if (EFI_ERROR(Status)) {
- Status = EFI_OUT_OF_RESOURCES;
- goto EXIT;
- }
+EXIT:
- if(EFI_ERROR(Status)) {
- // The watchdog failed to initialize
- ASSERT(FALSE);
- }
- LS1043aWdogPing();
- return Status;
+} diff --git a/Platforms/Nxp/LS1043aRdb/LS1043aWatchDog/LS1043aWatchDogDxe.inf b/Platforms/Nxp/LS1043aRdb/LS1043aWatchDog/LS1043aWatchDogDxe.inf new file mode 100644 index 0000000..e1dbbcf --- /dev/null +++ b/Platforms/Nxp/LS1043aRdb/LS1043aWatchDog/LS1043aWatchDogDxe.inf @@ -0,0 +1,54 @@ +#/** LS1043aWatchDog.inf +# +# Component description file for LS1043a WatchDog module +# +# Copyright (c) 2016, Freescale Semiconductor, Inc. All rights reserved. +# +# This program and the accompanying materials +# are licensed and made available under the terms and conditions of the BSD License +# which accompanies this distribution. The full text of the license may be found at +# http://opensource.org/licenses/bsd-license.php +# +# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, +# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. +# +#**/
+[Defines]
- INF_VERSION = 0x00010005
- BASE_NAME = LS1043aWatchDogDxe
- FILE_GUID = ebd705fb-fa92-46a7-b32b-7f566d944614
- MODULE_TYPE = DXE_DRIVER
- VERSION_STRING = 1.0
- ENTRY_POINT = LS1043aWdogInitialize
+[Sources.common]
- LS1043aWatchDog.c
+[Packages]
- MdePkg/MdePkg.dec
- EmbeddedPkg/EmbeddedPkg.dec
- ArmPkg/ArmPkg.dec
- ArmPlatformPkg/ArmPlatformPkg.dec
- OpenPlatformPkg/Platforms/Nxp/LS1043aRdb/LS1043aRdbPkg.dec
+[LibraryClasses]
- BaseLib
- BaseMemoryLib
- DebugLib
- IoLib
- PcdLib
- UefiLib
- UefiBootServicesTableLib
- UefiDriverEntryPoint
- UefiRuntimeServicesTableLib
Please sort above.
+[Pcd]
- gArmPlatformTokenSpaceGuid.PcdLS1043aWatchDogBase
+[Protocols]
- gEfiWatchdogTimerArchProtocolGuid
+[Depex]
- TRUE
-- 1.9.1
Hi Leif,
From: Leif Lindholm [mailto:leif.lindholm@linaro.org] Sent: Saturday, November 05, 2016 5:14 AM
On Tue, Oct 18, 2016 at 01:34:12AM +0530, Bhupesh Sharma wrote:
From: Sakar Arora sakar.arora@nxp.com
This patch adds support for the Watchdog timer present on the LS1043A SoC.
The patch installs Watchdog timer arch protocol and implements APIs necessary for the same.
Signed-off-by: Sakar Arora sakar.arora@nxp.com
.../LS1043aRdb/LS1043aWatchDog/LS1043aWatchDog.c | 355
+++++++++++++++++++++
.../LS1043aWatchDog/LS1043aWatchDogDxe.inf | 54 ++++ 2 files changed, 409 insertions(+) create mode 100644 Platforms/Nxp/LS1043aRdb/LS1043aWatchDog/LS1043aWatchDog.c create mode 100644 Platforms/Nxp/LS1043aRdb/LS1043aWatchDog/LS1043aWatchDogDxe.inf
diff --git a/Platforms/Nxp/LS1043aRdb/LS1043aWatchDog/LS1043aWatchDog.c b/Platforms/Nxp/LS1043aRdb/LS1043aWatchDog/LS1043aWatchDog.c new file mode 100644 index 0000000..ea298f9 --- /dev/null +++ b/Platforms/Nxp/LS1043aRdb/LS1043aWatchDog/LS1043aWatchDog.c @@ -0,0 +1,355 @@ +/** LS1043aWatchDog.c +* +* Based on Watchdog driver implemenation available in +* ArmPlatformPkg/Drivers/SP805WatchdogDxe/SP805Watchdog.c +* +* Copyright (c) 2011-2013, ARM Limited. All rights reserved. +* Copyright (c) 2016, Freescale Semiconductor, Inc. All rights
reserved.
+* +* This program and the accompanying materials +* are licensed and made available under the terms and conditions of +the BSD License +* which accompanies this distribution. The full text of the
license
+may be found at +* http://opensource.org/licenses/bsd-license.php +* +* THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" +BASIS, +* WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS
OR IMPLIED.
+* +**/
+#include <PiDxe.h>
+#include <Library/BaseLib.h> +#include <Library/BaseMemoryLib.h> +#include <Library/DebugLib.h> +#include <Library/IoLib.h> +#include <Library/PcdLib.h> +#include <Library/UefiBootServicesTableLib.h> +#include <Library/UefiRuntimeServicesTableLib.h> +#include <Library/UefiLib.h>
+#include <Protocol/WatchdogTimer.h> +#include <Library/PlatformLib.h>
Sort, please.
Ok.
+#define LS1043A_WT_MAX_TIME 128 +#define LS1043A_WD_COUNT(sec) (((sec) * 2 - 1) << 8) +#define LS1043A_WD_SEC(cnt) (((cnt) + 1) / 2)
+EFI_EVENT EfiExitBootServicesEvent =
(EFI_EVENT)NULL;
STATIC and prefix m?
Ok.
+inline
No inline please. I would expect the compiler to inline these anyway if they're marked STATIC (as they should be if not used externally). Please apply throughout.
Ok.
+VOID +LS1043aWdogPing (
- VOID
- )
+{
- MmioWriteBe16(WDOG1_BASE_ADDR + WDOG_WSR_OFFSET,
+WDOG_SERVICE_SEQ1);
- MmioWriteBe16(WDOG1_BASE_ADDR + WDOG_WSR_OFFSET,
+WDOG_SERVICE_SEQ2); }
+/**
- Stop the LS1043aWdog watchdog timer from counting down by
disabling interrupts.
+**/ +inline +VOID +LS1043aWdogStop (
- VOID
- )
+{
- // LS1043a Watchdog cannot be disabled by software once started.
- // At best, we can keep pinging the watchdog
- LS1043aWdogPing();
+}
+/**
- Starts the LS1043aWdog counting down by enabling interrupts.
- The count down will start from the value stored in the Load
+register,
- not from the value where it was previously stopped.
+**/ +inline +VOID +LS1043aWdogStart (
- VOID
- )
+{
- /* Watchdog is enabled already in LS1043aWdogInitialize - time to
+reload the timeout value */
- LS1043aWdogPing();
+}
+/**
- On exiting boot services we must make sure the LS1043aWdog
Watchdog Timer
- is stopped.
+**/ +VOID +EFIAPI +ExitBootServicesEvent (
- IN EFI_EVENT Event,
- IN VOID *Context
- )
+{
- LS1043aWdogStop();
+}
+/**
- This function registers the handler NotifyFunction so it is called
+every time
- the watchdog timer expires. It also passes the amount of time
+since the last
- handler call to the NotifyFunction.
- If NotifyFunction is not NULL and a handler is not already
+registered,
- then the new handler is registered and EFI_SUCCESS is returned.
- If NotifyFunction is NULL, and a handler is already registered,
- then that handler is unregistered.
- If an attempt is made to register a handler when a handler is
+already registered,
- then EFI_ALREADY_STARTED is returned.
- If an attempt is made to unregister a handler when a handler is
not
+registered,
- then EFI_INVALID_PARAMETER is returned.
- @param This The EFI_TIMER_ARCH_PROTOCOL instance.
- @param NotifyFunction The function to call when a timer
interrupt fires. This
function executes at TPL_HIGH_LEVEL. The
DXE Core will
register a handler for the timer
interrupt, so it can know
how much time has passed. This
information is used to
signal timer based events. NULL will
unregister the handler.
- @retval EFI_SUCCESS The watchdog timer handler was
registered.
- @retval EFI_ALREADY_STARTED NotifyFunction is not NULL, and a
handler is already
registered.
- @retval EFI_INVALID_PARAMETER NotifyFunction is NULL, and a
handler was not
previously registered.
+**/ +EFI_STATUS +EFIAPI +LS1043aWdogRegisterHandler (
- IN CONST EFI_WATCHDOG_TIMER_ARCH_PROTOCOL *This,
- IN EFI_WATCHDOG_TIMER_NOTIFY NotifyFunction
- )
+{
- // ERROR: This function is not supported.
- // The hardware watchdog will reset the board
- return EFI_INVALID_PARAMETER;
+}
+/**
- This function adjusts the period of timer interrupts to the value
- specified by TimerPeriod. If the timer period is updated, then
the
- selected timer period is stored in EFI_TIMER.TimerPeriod, and
- EFI_SUCCESS is returned. If the timer hardware is not
programmable, then EFI_UNSUPPORTED is returned.
- If an error occurs while attempting to update the timer period,
- then the timer hardware will be put back in its state prior to
this
- call, and EFI_DEVICE_ERROR is returned. If TimerPeriod is 0, then
- the timer interrupt is disabled. This is not the same as
disabling the CPU's interrupts.
- Instead, it must either turn off the timer hardware, or it must
- adjust the interrupt controller so that a CPU interrupt is not
- generated when the timer interrupt fires.
- @param This The EFI_TIMER_ARCH_PROTOCOL instance.
- @param TimerPeriod The rate to program the timer interrupt
in 100 nS units. If
the timer hardware is not programmable,
then EFI_UNSUPPORTED is
returned. If the timer is programmable,
then the timer period
will be rounded up to the nearest timer
period that is supported
by the timer hardware. If TimerPeriod is
set to 0, then the
timer interrupts will be disabled.
- @retval EFI_SUCCESS The timer period was changed.
- @retval EFI_UNSUPPORTED The platform cannot change the
period of the timer interrupt.
- @retval EFI_DEVICE_ERROR The timer period could not be
changed due to a device error.
+**/ +EFI_STATUS +EFIAPI +LS1043aWdogSetTimerPeriod (
- IN CONST EFI_WATCHDOG_TIMER_ARCH_PROTOCOL *This,
- IN UINT64 TimerPeriod // In
100ns units
- )
+{
- EFI_STATUS Status = EFI_SUCCESS;
- UINT64 TimerPeriodInSec;
- UINT16 Val;
- if( TimerPeriod == 0 ) {
- // This is a watchdog stop request
- LS1043aWdogStop();
- goto EXIT;
There is no cleanup to be done, so no need for the goto. Drop this goto.
Ok.
- } else {
- // Convert the TimerPeriod (in 100 ns unit) to an equivalent
- second value
- TimerPeriodInSec = DivU64x32(TimerPeriod, 10000000);
- // The registers in the LS1043aWdog are only 32 bits
- if(TimerPeriodInSec > LS1043A_WT_MAX_TIME) {
// We could load the watchdog with the maximum supported value
but
// if a smaller value was requested, this could have the
watchdog
// triggering before it was intended.
// Better generate an error to let the caller know.
Status = EFI_DEVICE_ERROR;
goto EXIT;
Replace above two lines with return EFI_DEVICE_ERROR;
Sure.
- }
- // set the new timeout value in the WCR
- Val = MmioReadBe16(WDOG1_BASE_ADDR + WDOG_WCR_OFFSET);
- Val &= ~WDOG_WCR_WT;
- // Convert the timeout value from Seconds to timer count
- Val |= ((LS1043A_WD_COUNT(TimerPeriodInSec) & 0xff00) << 8);
- MmioWriteBe16(WDOG1_BASE_ADDR + WDOG_WCR_OFFSET, Val);
- // Start the watchdog
- LS1043aWdogStart();
- }
- EXIT:
- return Status;
And these two with return EFI_SUCCESS;
Ok.
+}
+/**
- This function retrieves the period of timer interrupts in 100 ns
+units,
- returns that value in TimerPeriod, and returns EFI_SUCCESS. If
+TimerPeriod
- is NULL, then EFI_INVALID_PARAMETER is returned. If a TimerPeriod
+of 0 is
- returned, then the timer is currently disabled.
- @param This The EFI_TIMER_ARCH_PROTOCOL instance.
- @param TimerPeriod A pointer to the timer period to retrieve
in 100 ns units. If
0 is returned, then the timer is
currently disabled.
- @retval EFI_SUCCESS The timer period was returned in
TimerPeriod.
- @retval EFI_INVALID_PARAMETER TimerPeriod is NULL.
+**/ +EFI_STATUS +EFIAPI +LS1043aWdogGetTimerPeriod (
- IN CONST EFI_WATCHDOG_TIMER_ARCH_PROTOCOL *This,
- OUT UINT64 *TimerPeriod
- )
+{
- EFI_STATUS Status = EFI_SUCCESS;
- UINT64 ReturnValue;
- UINT16 Val;
- if (TimerPeriod == NULL) {
- return EFI_INVALID_PARAMETER;
- }
- // Check if the watchdog is stopped if (
- (MmioReadBe16(WDOG1_BASE_ADDR + WDOG_WCR_OFFSET) & WDOG_WCR_WDE) ==
- 0 ) {
No space padding at start/end.
Ok.
- // It is stopped, so return zero.
- ReturnValue = 0;
- } else {
- // Convert the Watchdog ticks into equivalent TimerPeriod second
- // value.
- Val = (MmioReadBe16(WDOG1_BASE_ADDR + WDOG_WCR_OFFSET) &
- WDOG_WCR_WT ) >> 8;
Drop space before ).
Ok.
- ReturnValue = LS1043A_WD_SEC(Val); }
- *TimerPeriod = ReturnValue;
- return Status;
+}
+/**
- Interface structure for the Watchdog Architectural Protocol.
- @par Protocol Description:
- This protocol provides a service to set the amount of time to wait
- before firing the watchdog timer, and it also provides a service to
- register a handler that is invoked when the watchdog timer fires.
- @par When the watchdog timer fires, control will be passed to a
- handler if one has been registered. If no handler has been
- registered, or the registered handler returns, then the system
will
- be reset by calling the Runtime Service ResetSystem().
- @param RegisterHandler
- Registers a handler that will be called each time the
- watchdogtimer interrupt fires. TimerPeriod defines the minimum
- time between timer interrupts, so TimerPeriod will also be the
- minimum time between calls to the registered handler.
- NOTE: If the watchdog resets the system in hardware, then
this function will not have any chance of executing.
- @param SetTimerPeriod
- Sets the period of the timer interrupt in 100 nS units.
- This function is optional, and may return EFI_UNSUPPORTED.
- If this function is supported, then the timer period will be
- rounded up to the nearest supported timer period.
- @param GetTimerPeriod
- Retrieves the period of the timer interrupt in 100 nS units.
+**/ +EFI_WATCHDOG_TIMER_ARCH_PROTOCOL gWatchdogTimer = {
- (EFI_WATCHDOG_TIMER_REGISTER_HANDLER) LS1043aWdogRegisterHandler,
- (EFI_WATCHDOG_TIMER_SET_TIMER_PERIOD) LS1043aWdogSetTimerPeriod,
- (EFI_WATCHDOG_TIMER_GET_TIMER_PERIOD) LS1043aWdogGetTimerPeriod };
+/**
- Initialize the state information for the Watchdog Timer
Architectural Protocol.
- @param ImageHandle of the loaded driver
- @param SystemTable Pointer to the System Table
- @retval EFI_SUCCESS Protocol registered
- @retval EFI_OUT_OF_RESOURCES Cannot allocate protocol data
structure
- @retval EFI_DEVICE_ERROR Hardware problems
+**/ +EFI_STATUS +EFIAPI +LS1043aWdogInitialize (
- IN EFI_HANDLE ImageHandle,
- IN EFI_SYSTEM_TABLE *SystemTable
- )
+{
- EFI_STATUS Status;
- EFI_HANDLE Handle;
- UINT16 Val;
- Val = MmioReadBe16(WDOG1_BASE_ADDR + WDOG_WCR_OFFSET);
- Val &= ~WDOG_WCR_WT;
- Val &= ~WDOG_WCR_WDE;
- Val |= LS1043A_WD_COUNT(LS1043A_WT_MAX_TIME) & 0xff00;
- MmioWriteBe16(WDOG1_BASE_ADDR + WDOG_WCR_OFFSET, Val);
- Val |= WDOG_WCR_WDE;
- //
- // Make sure the Watchdog Timer Architectural Protocol has not
been installed in the system yet.
- // This will avoid conflicts with the universal watchdog //
- ASSERT_PROTOCOL_ALREADY_INSTALLED (NULL,
- &gEfiWatchdogTimerArchProtocolGuid);
- // Register for an ExitBootServicesEvent Status = gBS-
CreateEvent
- (EVT_SIGNAL_EXIT_BOOT_SERVICES, TPL_NOTIFY, ExitBootServicesEvent,
- NULL, &EfiExitBootServicesEvent); if (EFI_ERROR(Status)) {
- Status = EFI_OUT_OF_RESOURCES;
- goto EXIT;
- }
- // Install the Timer Architectural Protocol onto a new handle
- Handle = NULL; Status = gBS->InstallMultipleProtocolInterfaces(
&Handle,
&gEfiWatchdogTimerArchProtocolGuid,
&gWatchdogTimer,
NULL
);
- if (EFI_ERROR(Status)) {
- Status = EFI_OUT_OF_RESOURCES;
- goto EXIT;
- }
+EXIT:
- if(EFI_ERROR(Status)) {
- // The watchdog failed to initialize
- ASSERT(FALSE);
- }
- LS1043aWdogPing();
- return Status;
+} diff --git a/Platforms/Nxp/LS1043aRdb/LS1043aWatchDog/LS1043aWatchDogDxe.inf b/Platforms/Nxp/LS1043aRdb/LS1043aWatchDog/LS1043aWatchDogDxe.inf new file mode 100644 index 0000000..e1dbbcf --- /dev/null +++ b/Platforms/Nxp/LS1043aRdb/LS1043aWatchDog/LS1043aWatchDogDxe.inf @@ -0,0 +1,54 @@ +#/** LS1043aWatchDog.inf +# +# Component description file for LS1043a WatchDog module # # +Copyright (c) 2016, Freescale Semiconductor, Inc. All rights
reserved.
+# +# This program and the accompanying materials # are licensed and +made available under the terms and conditions of the BSD License # +which accompanies this distribution. The full text of the license +may be found at # http://opensource.org/licenses/bsd-license.php +# +# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" +BASIS, # WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER
EXPRESS OR IMPLIED.
+# +#**/
+[Defines]
- INF_VERSION = 0x00010005
- BASE_NAME = LS1043aWatchDogDxe
- FILE_GUID = ebd705fb-fa92-46a7-b32b-
7f566d944614
- MODULE_TYPE = DXE_DRIVER
- VERSION_STRING = 1.0
- ENTRY_POINT = LS1043aWdogInitialize
+[Sources.common]
- LS1043aWatchDog.c
+[Packages]
- MdePkg/MdePkg.dec
- EmbeddedPkg/EmbeddedPkg.dec
- ArmPkg/ArmPkg.dec
- ArmPlatformPkg/ArmPlatformPkg.dec
- OpenPlatformPkg/Platforms/Nxp/LS1043aRdb/LS1043aRdbPkg.dec
+[LibraryClasses]
- BaseLib
- BaseMemoryLib
- DebugLib
- IoLib
- PcdLib
- UefiLib
- UefiBootServicesTableLib
- UefiDriverEntryPoint
- UefiRuntimeServicesTableLib
Please sort above.
Sure.
+[Pcd]
- gArmPlatformTokenSpaceGuid.PcdLS1043aWatchDogBase
+[Protocols]
- gEfiWatchdogTimerArchProtocolGuid
+[Depex]
- TRUE
-- 1.9.1
From: Sakar Arora sakar.arora@nxp.com
The patch adds the device description, flash description and declaration files for the LS1043aRdbPkg.
In addition this patch also adds the build scripts required to build this package.
Signed-off-by: Sakar Arora sakar.arora@nxp.com Signed-off-by: Bhupesh Sharma bhupesh.sharma@nxp.com --- Chips/Nxp/QoriqLs/NxpQoriqLs.dec | 50 +++ Platforms/Nxp/LS1043aRdb/LS1043aRdbPkg.dec | 166 ++++++++ Platforms/Nxp/LS1043aRdb/LS1043aRdbPkg.dsc | 602 +++++++++++++++++++++++++++++ Platforms/Nxp/LS1043aRdb/LS1043aRdbPkg.fdf | 311 +++++++++++++++ Platforms/Nxp/LS1043aRdb/build.sh | 72 ++++ Platforms/Nxp/LS1043aRdb/ls1043a_env.cshrc | 2 + 6 files changed, 1203 insertions(+) create mode 100644 Chips/Nxp/QoriqLs/NxpQoriqLs.dec create mode 100644 Platforms/Nxp/LS1043aRdb/LS1043aRdbPkg.dec create mode 100644 Platforms/Nxp/LS1043aRdb/LS1043aRdbPkg.dsc create mode 100644 Platforms/Nxp/LS1043aRdb/LS1043aRdbPkg.fdf create mode 100755 Platforms/Nxp/LS1043aRdb/build.sh create mode 100644 Platforms/Nxp/LS1043aRdb/ls1043a_env.cshrc
diff --git a/Chips/Nxp/QoriqLs/NxpQoriqLs.dec b/Chips/Nxp/QoriqLs/NxpQoriqLs.dec new file mode 100644 index 0000000..6b04836 --- /dev/null +++ b/Chips/Nxp/QoriqLs/NxpQoriqLs.dec @@ -0,0 +1,50 @@ +#/** LS1043a board package. +# +# Copyright (c) 2016, Freescale Semiconductor, Inc. All rights reserved. +# +# This program and the accompanying materials are licensed and made available under +# the terms and conditions of the BSD License which accompanies this distribution. +# The full text of the license may be found at +# http://opensource.org/licenses/bsd-license.php +# +# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, +# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. +# +#**/ + +[Defines] + DEC_SPECIFICATION = 0x00010005 + PACKAGE_NAME = NxpQoriqLs + PACKAGE_GUID = 6eba6648-d853-4eb3-9761-528b82d5ab14 + PACKAGE_VERSION = 0.1 + +################################################################################ +# +# Include Section - list of Include Paths that are provided by this package. +# Comments are used for Keywords and Module Types. +# +# Supported Module Types: +# BASE SEC PEI_CORE PEIM DXE_CORE DXE_DRIVER DXE_RUNTIME_DRIVER DXE_SMM_DRIVER DXE_SAL_DRIVER UEFI_DRIVER UEFI_APPLICATION +# +################################################################################ +[Includes.common] + Include # Root include for the package + +[Guids.common] + gNxpQoriqLsTokenSpaceGuid = { 0x6834fe45, 0x4aee, 0x4fc6, { 0xbc, 0xb5, 0xff, 0x45, 0xb7, 0xa8, 0x71, 0xf2 } } + +[PcdsFixedAtBuild.common] + + gNxpQoriqLsTokenSpaceGuid.PcdOcramStackBase|0x0|UINT32|0x00000001 + gNxpQoriqLsTokenSpaceGuid.PcdFdNorBaseAddress|0x0|UINT64|0x00000002 + gNxpQoriqLsTokenSpaceGuid.PcdPiFdBaseAddress|0x0|UINT64|0x00000003 + gNxpQoriqLsTokenSpaceGuid.PcdPiFdSize|0x0|UINT32|0x00000004 + gNxpQoriqLsTokenSpaceGuid.PcdFvNorBaseAddress|0x0|UINT64|0x00000005 + gNxpQoriqLsTokenSpaceGuid.PcdFvNorSize|0x0|UINT32|0x00000006 + gNxpQoriqLsTokenSpaceGuid.PcdI2cBus|0|UINT32|0x0000007 + gNxpQoriqLsTokenSpaceGuid.PcdRtcI2cBus|0|UINT32|0x0000008 + gNxpQoriqLsTokenSpaceGuid.PcdDs1307I2cAddress|0|UINT32|0x0000009 + gNxpQoriqLsTokenSpaceGuid.PcdPpaFitConfiguration|""|VOID*|0x000000A + gNxpQoriqLsTokenSpaceGuid.PcdPpaNorBaseAddr|0x0|UINT64|0x000000B + gNxpQoriqLsTokenSpaceGuid.PcdPpaDdrOffsetAddr|0x0|UINT64|0x000000C + gNxpQoriqLsTokenSpaceGuid.PcdI2cSpeed|0|UINT32|0x000000D diff --git a/Platforms/Nxp/LS1043aRdb/LS1043aRdbPkg.dec b/Platforms/Nxp/LS1043aRdb/LS1043aRdbPkg.dec new file mode 100644 index 0000000..9df3eb7 --- /dev/null +++ b/Platforms/Nxp/LS1043aRdb/LS1043aRdbPkg.dec @@ -0,0 +1,166 @@ +#/** LS1043a board package. +# +# Copyright (c) 2016, Freescale Semiconductor, Inc. All rights reserved. +# +# This program and the accompanying materials are licensed and made available under +# the terms and conditions of the BSD License which accompanies this distribution. +# The full text of the license may be found at +# http://opensource.org/licenses/bsd-license.php +# +# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, +# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. +# +#**/ + +[Defines] + DEC_SPECIFICATION = 0x00010005 + PACKAGE_NAME = LS1043aRdbPkg + PACKAGE_GUID = 6eba6648-d853-4eb3-9761-528b82d5ab04 + PACKAGE_VERSION = 0.1 + +################################################################################ +# +# Include Section - list of Include Paths that are provided by this package. +# Comments are used for Keywords and Module Types. +# +# Supported Module Types: +# BASE SEC PEI_CORE PEIM DXE_CORE DXE_DRIVER DXE_RUNTIME_DRIVER DXE_SMM_DRIVER DXE_SAL_DRIVER UEFI_DRIVER UEFI_APPLICATION +# +################################################################################ +[Includes.common] + Include # Root include for the package + +[Guids.common] + gLS1043aRdbTokenSpaceGuid = { 0x6834fe45, 0x4aee, 0x4fc6, { 0xbc, 0xb5, 0xff, 0x45, 0xb7, 0xa8, 0x71, 0xe2 } } + gEfiMmcHostProtocolGuid = { 0x3e591c00, 0x9e4a, 0x11df, {0x92, 0x44, 0x00, 0x02, 0xA5, 0xD5, 0xC5, 0x1B }} + gShellDebug1HiiGuid = {0x25f200aa, 0xd3cb, 0x470a, {0xbf, 0x51, 0xe7, 0xd1, 0x62, 0xd2, 0x2e, 0x6f}} + gShellNetwork1HiiGuid = {0xf3d301bb, 0xf4a5, 0x45a8, {0xb0, 0xb7, 0xfa, 0x99, 0x9c, 0x62, 0x37, 0xae}} + gEfiDpcProtocolGuid = {0x480f8ae9, 0xc46, 0x4aa9, { 0xbc, 0x89, 0xdb, 0x9f, 0xba, 0x61, 0x98, 0x6 }} + gShellTftpHiiGuid = {0x738a9314, 0x82c1, 0x4592, {0x8f, 0xf7, 0xc1, 0xbd, 0xf1, 0xb2, 0x0e, 0xd4}} + + + ## Include/Protocol/SimpleNetwork.h + gEfiSimpleNetworkProtocolGuid = { 0xA19832B9, 0xAC25, 0x11D3, { 0x9A, 0x2D, 0x00, 0x90, 0x27, 0x3F, 0xC1, 0x4D }} + + ## Include/Protocol/ManagedNetwork.h + gEfiManagedNetworkServiceBindingProtocolGuid = { 0xF36FF770, 0xA7E1, 0x42CF, { 0x9E, 0xD2, 0x56, 0xF0, 0xF2, 0x71, 0xF4, 0x4C }} + + ## Include/Protocol/ManagedNetwork.h + gEfiManagedNetworkProtocolGuid = { 0x7ab33a91, 0xace5, 0x4326, { 0xb5, 0x72, 0xe7, 0xee, 0x33, 0xd3, 0x9f, 0x16 }} + + ## Include/Protocol/HiiConfigRouting.h + gEfiHiiConfigRoutingProtocolGuid = {0x587e72d7, 0xcc50, 0x4f79, {0x82, 0x09, 0xca, 0x29, 0x1f, 0xc1, 0xa1, 0x0f}} + + ## Include/Protocol/Arp.h + gEfiArpServiceBindingProtocolGuid = { 0xF44C00EE, 0x1F2C, 0x4A00, { 0xAA, 0x09, 0x1C, 0x9F, 0x3E, 0x08, 0x00, 0xA3 }} + + ## Include/Protocol/Arp.h + gEfiArpProtocolGuid = { 0xF4B427BB, 0xBA21, 0x4F16, { 0xBC, 0x4E, 0x43, 0xE4, 0x16, 0xAB, 0x61, 0x9C }} + + ## Include/Protocol/Dhcp4.h + gEfiDhcp4ServiceBindingProtocolGuid = { 0x9D9A39D8, 0xBD42, 0x4A73, { 0xA4, 0xD5, 0x8E, 0xE9, 0x4B, 0xE1, 0x13, 0x80 }} + + ## Include/Protocol/Dhcp4.h + gEfiDhcp4ProtocolGuid = { 0x8A219718, 0x4EF5, 0x4761, { 0x91, 0xC8, 0xC0, 0xF0, 0x4B, 0xDA, 0x9E, 0x56 }} + + ## Include/Protocol/Tcp4.h + gEfiTcp4ServiceBindingProtocolGuid = { 0x00720665, 0x67EB, 0x4A99, { 0xBA, 0xF7, 0xD3, 0xC3, 0x3A, 0x1C, 0x7C, 0xC9 }} + + ## Include/Protocol/Tcp4.h + gEfiTcp4ProtocolGuid = { 0x65530BC7, 0xA359, 0x410F, { 0xB0, 0x10, 0x5A, 0xAD, 0xC7, 0xEC, 0x2B, 0x62 }} + + ## Include/Protocol/Ip4.h + gEfiIp4ServiceBindingProtocolGuid = { 0xC51711E7, 0xB4BF, 0x404A, { 0xBF, 0xB8, 0x0A, 0x04, 0x8E, 0xF1, 0xFF, 0xE4 }} + + ## Include/Protocol/Ip4.h + gEfiIp4ProtocolGuid = { 0x41D94CD2, 0x35B6, 0x455A, { 0x82, 0x58, 0xD4, 0xE5, 0x13, 0x34, 0xAA, 0xDD }} + + ## Include/Protocol/Ip4Config.h + gEfiIp4ConfigProtocolGuid = { 0x3B95AA31, 0x3793, 0x434B, { 0x86, 0x67, 0xC8, 0x07, 0x08, 0x92, 0xE0, 0x5E }} + + ## Include/Protocol/Udp4.h + gEfiUdp4ServiceBindingProtocolGuid = { 0x83F01464, 0x99BD, 0x45E5, { 0xB3, 0x83, 0xAF, 0x63, 0x05, 0xD8, 0xE9, 0xE6 }} + + ## Include/Protocol/Udp4.h + gEfiUdp4ProtocolGuid = { 0x3AD9DF29, 0x4501, 0x478D, { 0xB1, 0xF8, 0x7F, 0x7F, 0xE7, 0x0E, 0x50, 0xF3 }} + + ## Include/Protocol/Mtftp4.h + gEfiMtftp4ServiceBindingProtocolGuid = { 0x2FE800BE, 0x8F01, 0x4AA6, { 0x94, 0x6B, 0xD7, 0x13, 0x88, 0xE1, 0x83, 0x3F }} + + ## Include/Protocol/Mtftp4.h + gEfiMtftp4ProtocolGuid = { 0x78247C57, 0x63DB, 0x4708, { 0x99, 0xC2, 0xA8, 0xB4, 0xA9, 0xA6, 0x1F, 0x6B }} + +[PcdsFixedAtBuild.common] + # Size to reserve in the primary core stack for PEI Global Variables + # = sizeof(UINTN) /* PcdPeiServicePtr or HobListPtr */ + gArmPlatformTokenSpaceGuid.PcdPeiGlobalVariableSize|0x4|UINT32|0x00000016 + gArmPlatformTokenSpaceGuid.PcdCounterFrequency|12000000|UINT32|0x00000017 + + ## LS1043a UART + gArmPlatformTokenSpaceGuid.LS1043aUartClkInHz|61440000|UINT32|0x00000018 + gArmPlatformTokenSpaceGuid.LS1043aUartInteger|0|UINT32|0x00000019 + gArmPlatformTokenSpaceGuid.LS1043aUartFractional|0|UINT32|0x0000001A + + ## Timer + gArmTokenSpaceGuid.PcdArmArchTimerFreqInHz|0|UINT32|0x0000001B + gEmbeddedTokenSpaceGuid.PcdTimerPeriod|10000|UINT32|0x0000001D + gArmPlatformTokenSpaceGuid.PcdArmArchTimerVirtIntrNum|0|UINT32|0x0000001E + gArmPlatformTokenSpaceGuid.PcdArmArchTimerHypIntrNum|0|UINT32|0x0000001F + gArmPlatformTokenSpaceGuid.PcdArmArchTimerSecIntrNum|0|UINT32|0x00000020 + gArmPlatformTokenSpaceGuid.PcdArmArchTimerIntrNum|0|UINT32|0x00000021 + gEmbeddedTokenSpaceGuid.PcdMetronomeTickPeriod|0|UINT32|0x00000022 + + gArmPlatformTokenSpaceGuid.PcdLS1043aWatchDogBase|0x0|UINT32|0x00000023 + gArmPlatformTokenSpaceGuid.DUartClkInHz|0x0|UINT32|0x00000024 + gArmPlatformTokenSpaceGuid.DUartInteger|0x0|UINT32|0x00000025 + + ## Ddr + gArmTokenSpaceGuid.PcdDdrInitialize|FALSE|BOOLEAN|0x00000026 + + # + # LS1043a Soc Specific PCDs + # + gArmPlatformTokenSpaceGuid.PcdCounterFrequencyReal|FALSE|BOOLEAN|0x00000027 + gArmPlatformTokenSpaceGuid.PcdCsuInitialize|FALSE|BOOLEAN|0x00000028 + gArmPlatformTokenSpaceGuid.PcdTzc380Initialize|FALSE|BOOLEAN|0x00000029 + gArmPlatformTokenSpaceGuid.PcdCci400Initialize|FALSE|BOOLEAN|0x0000002A + gArmPlatformTokenSpaceGuid.PcdClockInitialize|FALSE|BOOLEAN|0x0000002B + + gLS1043aRdbTokenSpaceGuid.PcdFdNandLba|0x0|UINT32|0x00000031 + + #gEfiShellPkgTokenSpaceGuid.PcdShellLibAutoInitialize|FALSE|BOOLEAN|0x00000039 + # + # PPA specific PCDs + # + gArmPlatformTokenSpaceGuid.PcdPpaNorBaseAddr|0x0|UINT64|0x00000032 + gArmPlatformTokenSpaceGuid.PcdPpaDdrOffsetAddr|0x0|UINT64|0x00000033 # calculated from top of DDR + gLS1043aRdbTokenSpaceGuid.PcdPpaFitConfiguration|""|VOID*|0x00000034 + + ## PCI + # This value is used to set the base address of PCI express hierarchy. + # @Prompt PCI Express Base Address. + # + gArmPlatformTokenSpaceGuid.PcdPciMaxPayloadFixup|FALSE|BOOLEAN|0x00000040 + gArmPlatformTokenSpaceGuid.PcdPciBusHotPlugDeviceSupport|TRUE|BOOLEAN|0x00000041 + gArmPlatformTokenSpaceGuid.PcdKludgeMapPciMmioAsCached|FALSE|BOOLEAN|0x00000006 + gArmPlatformTokenSpaceGuid.PcdPciBusMin|0|UINT64|0x00000042 + gArmPlatformTokenSpaceGuid.PcdPciBusMax|255|UINT64|0x00000043 + gArmPlatformTokenSpaceGuid.PcdPciIoBase|0x00010000|UINT64|0x00000044 + gArmPlatformTokenSpaceGuid.PcdPciIoSize|0x00010000|UINT64|0x00000045 + gArmPlatformTokenSpaceGuid.PcdPciMmio32Base|0x40000000|UINT32|0x00000046 + gArmPlatformTokenSpaceGuid.PcdPciMmio32Size|0x40000000|UINT32|0x00000047 + gArmPlatformTokenSpaceGuid.PcdPciMemTranslation|0x5000000000|UINT64|0x00000055 + gArmPlatformTokenSpaceGuid.PcdPciMmio64Base|0x5040000000|UINT64|0x00000048 + gArmPlatformTokenSpaceGuid.PcdPciMmio64Size|0x0040000000|UINT64|0x00000049 + gArmPlatformTokenSpaceGuid.PcdPciIoTranslation|0x00010000|UINT64|0x00000050 + gEfiMdePkgTokenSpaceGuid.PcdPci1ExpressBaseAddress|0x5000000000|UINT64|0x00000051 + gEfiMdePkgTokenSpaceGuid.PcdPci2ExpressBaseAddress|0x4800000000|UINT64|0x00000052 + gEfiMdePkgTokenSpaceGuid.PcdPci3ExpressBaseAddress|0x5000000000|UINT64|0x00000058 + gEfiMdePkgTokenSpaceGuid.PcdPciExpressBaseAddress|0x03600000|UINT64|0x0000004D + + gLS1043aRdbTokenSpaceGuid.PcdBootMode|0x0|UINT32|0x00000038 + gLS1043aRdbTokenSpaceGuid.PcdPpaNandLba|0x10|UINT32|0x00000039 + + gLS1043aRdbTokenSpaceGuid.PcdPpaImageSize|0x100000|UINT32|0x00000040 + gLS1043aRdbTokenSpaceGuid.PcdPpaSdxcLba|0x10|UINT32|0x00000041 + gLS1043aRdbTokenSpaceGuid.PcdFdSdxcLba|0x0|UINT32|0x00000042 diff --git a/Platforms/Nxp/LS1043aRdb/LS1043aRdbPkg.dsc b/Platforms/Nxp/LS1043aRdb/LS1043aRdbPkg.dsc new file mode 100644 index 0000000..1e3c2db --- /dev/null +++ b/Platforms/Nxp/LS1043aRdb/LS1043aRdbPkg.dsc @@ -0,0 +1,602 @@ +#/** LS1043A board package. +# +# Copyright (c) 2016, Freescale Semiconductor, Inc. All rights reserved. +# +# This program and the accompanying materials +# are licensed and made available under the terms and conditions of the BSD License +# which accompanies this distribution. The full text of the license may be found at +# http://opensource.org/licenses/bsd-license.php +# +# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, +# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. +# +#**/ + +################################################################################ +# +# Defines Section - statements that will be processed to create a Makefile. +# +################################################################################ +[Defines] + # + # Defines for default states. These can be changed on the command line. + # -D FLAG=VALUE + # + PLATFORM_NAME = LS1043aRdbPkg + PLATFORM_GUID = 60169ec4-d2b4-44f8-825e-f8684fd42e4f + PLATFORM_VERSION = 0.1 + DSC_SPECIFICATION = 0x00010005 + OUTPUT_DIRECTORY = Build/LS1043aRdb + SUPPORTED_ARCHITECTURES = AARCH64 + BUILD_TARGETS = DEBUG|RELEASE + SKUID_IDENTIFIER = DEFAULT + FLASH_DEFINITION = OpenPlatformPkg/Platforms/Nxp/LS1043aRdb/LS1043aRdbPkg.fdf + +[LibraryClasses.common] + ArmLib|ArmPkg/Library/ArmLib/ArmBaseLib.inf + ArmCpuLib|ArmPkg/Drivers/ArmCpuLib/ArmCortexAEMv8Lib/ArmCortexAEMv8Lib.inf + ArmSmcLib|ArmPkg/Library/ArmSmcLib/ArmSmcLib.inf + ArmMmuLib|ArmPkg/Library/ArmMmuLib/ArmMmuBaseLib.inf + + ArmGenericTimerCounterLib|ArmPkg/Library/ArmGenericTimerPhyCounterLib/ArmGenericTimerPhyCounterLib.inf + TimerLib|ArmPkg/Library/ArmArchTimerLib/ArmArchTimerLib.inf + + SocLib|OpenPlatformPkg/Platforms/Nxp/LS1043aRdb/Library/LS1043aSocLib/LS1043aSocLib.inf + ArmTrustZoneLib|ArmPlatformPkg/Drivers/ArmTrustZone/ArmTrustZone.inf + CpldLib|OpenPlatformPkg/Platforms/Nxp/LS1043aRdb/Library/CpldLib/CpldLib.inf + ArmPlatformLib|OpenPlatformPkg/Platforms/Nxp/LS1043aRdb/Library/LS1043aRdbLib/LS1043aRdbLib.inf + ArmPlatformStackLib|ArmPlatformPkg/Library/ArmPlatformStackLib/ArmPlatformStackLib.inf + + HiiLib|MdeModulePkg/Library/UefiHiiLib/UefiHiiLib.inf + UefiHiiServicesLib|MdeModulePkg/Library/UefiHiiServicesLib/UefiHiiServicesLib.inf + + FileExplorerLib|MdeModulePkg/Library/FileExplorerLib/FileExplorerLib.inf + #ImageDecoderLib|MdeModulePkg/Library/ImageDecoderLib/ImageDecoderLib.inf + + BootLogoLib|MdeModulePkg/Library/BootLogoLib/BootLogoLib.inf + PlatformBootManagerLib|ArmPkg/Library/PlatformBootManagerLib/PlatformBootManagerLib.inf + + DxeServicesLib|MdePkg/Library/DxeServicesLib/DxeServicesLib.inf + UefiBootManagerLib|MdeModulePkg/Library/UefiBootManagerLib/UefiBootManagerLib.inf + CustomizedDisplayLib|MdeModulePkg/Library/CustomizedDisplayLib/CustomizedDisplayLib.inf + +# Networking Requirements + NetLib|MdeModulePkg/Library/DxeNetLib/DxeNetLib.inf + DpcLib|MdeModulePkg/Library/DxeDpcLib/DxeDpcLib.inf + UdpIoLib|MdeModulePkg/Library/DxeUdpIoLib/DxeUdpIoLib.inf + IpIoLib|MdeModulePkg/Library/DxeIpIoLib/DxeIpIoLib.inf + + # ARM GIC400 General Interrupt Driver + ArmGicLib|ArmPkg/Drivers/ArmGic/ArmGicLib.inf + ArmGicArchLib|ArmPkg/Library/ArmGicArchLib/ArmGicArchLib.inf + +!if $(TARGET) == RELEASE + DebugLib|MdePkg/Library/BaseDebugLibSerialPort/BaseDebugLibSerialPort.inf + UncachedMemoryAllocationLib|ArmPkg/Library/UncachedMemoryAllocationLib/UncachedMemoryAllocationLib.inf +!else + DebugLib|MdePkg/Library/BaseDebugLibSerialPort/BaseDebugLibSerialPort.inf + UncachedMemoryAllocationLib|ArmPkg/Library/UncachedMemoryAllocationLib/UncachedMemoryAllocationLib.inf +!endif + + DebugPrintErrorLevelLib|MdePkg/Library/BaseDebugPrintErrorLevelLib/BaseDebugPrintErrorLevelLib.inf + + # I2c Library + I2cLib|OpenPlatformPkg/Chips/Nxp/QoriqLs/Library/I2cLib/I2cLib.inf + + # Ddr Library + DdrLib|OpenPlatformPkg/Platforms/Nxp/LS1043aRdb/Library/DdrLib/DdrLib.inf + + MemoryAllocationLib|MdePkg/Library/UefiMemoryAllocationLib/UefiMemoryAllocationLib.inf + + BaseLib|MdePkg/Library/BaseLib/BaseLib.inf + SynchronizationLib|MdePkg/Library/BaseSynchronizationLib/BaseSynchronizationLib.inf + BaseMemoryLib|ArmPkg/Library/BaseMemoryLibStm/BaseMemoryLibStm.inf + + EfiResetSystemLib|OpenPlatformPkg/Platforms/Nxp/LS1043aRdb/Library/ResetSystemLib/ResetSystemLib.inf + + PerformanceLib|MdePkg/Library/BasePerformanceLibNull/BasePerformanceLibNull.inf + PrintLib|MdePkg/Library/BasePrintLib/BasePrintLib.inf + + EfiFileLib|EmbeddedPkg/Library/EfiFileLib/EfiFileLib.inf + + PeCoffLib|MdePkg/Library/BasePeCoffLib/BasePeCoffLib.inf + + PeCoffGetEntryPointLib|MdePkg/Library/BasePeCoffGetEntryPointLib/BasePeCoffGetEntryPointLib.inf + + PeCoffExtraActionLib|ArmPkg/Library/DebugPeCoffExtraActionLib/DebugPeCoffExtraActionLib.inf + + CacheMaintenanceLib|ArmPkg/Library/ArmCacheMaintenanceLib/ArmCacheMaintenanceLib.inf + DefaultExceptionHandlerLib|ArmPkg/Library/DefaultExceptionHandlerLib/DefaultExceptionHandlerLib.inf + CpuExceptionHandlerLib|ArmPkg/Library/ArmExceptionLib/ArmExceptionLib.inf + PrePiLib|EmbeddedPkg/Library/PrePiLib/PrePiLib.inf + RealTimeClockLib|OpenPlatformPkg/Chips/Nxp/QoriqLs/Library/Ds1307RtcLib/Ds1307RtcLib.inf + SemihostLib|ArmPkg/Library/SemihostLib/SemihostLib.inf + + # UART Driver + SerialPortLib|OpenPlatformPkg/Chips/Nxp/QoriqLs/Library/DUartPortLib/DUartPortLib.inf + + IoLib|MdePkg/Library/BaseIoLibIntrinsic/BaseIoLibIntrinsic.inf + + MemoryAllocationLib|MdePkg/Library/UefiMemoryAllocationLib/UefiMemoryAllocationLib.inf + UefiLib|MdePkg/Library/UefiLib/UefiLib.inf + HobLib|MdePkg/Library/DxeHobLib/DxeHobLib.inf + UefiRuntimeServicesTableLib|MdePkg/Library/UefiRuntimeServicesTableLib/UefiRuntimeServicesTableLib.inf + DevicePathLib|MdePkg/Library/UefiDevicePathLib/UefiDevicePathLib.inf + UefiBootServicesTableLib|MdePkg/Library/UefiBootServicesTableLib/UefiBootServicesTableLib.inf + + DxeServicesTableLib|MdePkg/Library/DxeServicesTableLib/DxeServicesTableLib.inf + UefiDriverEntryPoint|MdePkg/Library/UefiDriverEntryPoint/UefiDriverEntryPoint.inf + UefiApplicationEntryPoint|MdePkg/Library/UefiApplicationEntryPoint/UefiApplicationEntryPoint.inf + +# +# Assume everything is fixed at build +# + PcdLib|MdePkg/Library/BasePcdLibNull/BasePcdLibNull.inf + + UefiRuntimeLib|MdePkg/Library/UefiRuntimeLib/UefiRuntimeLib.inf + + UefiUsbLib|MdePkg/Library/UefiUsbLib/UefiUsbLib.inf + + CpuLib|MdePkg/Library/BaseCpuLib/BaseCpuLib.inf + + ArmDisassemblerLib|ArmPkg/Library/ArmDisassemblerLib/ArmDisassemblerLib.inf + DebugAgentLib|MdeModulePkg/Library/DebugAgentLibNull/DebugAgentLibNull.inf + DmaLib|ArmPkg/Library/ArmDmaLib/ArmDmaLib.inf + + BdsLib|ArmPkg/Library/BdsLib/BdsLib.inf + FdtLib|EmbeddedPkg/Library/FdtLib/FdtLib.inf + + ShellLib|ShellPkg/Library/UefiShellLib/UefiShellLib.inf + ShellCommandLib|ShellPkg/Library/UefiShellCommandLib/UefiShellCommandLib.inf + FileHandleLib|MdePkg/Library/UefiFileHandleLib/UefiFileHandleLib.inf + ShellCEntryLib|ShellPkg/Library/UefiShellCEntryLib/UefiShellCEntryLib.inf + SortLib|MdeModulePkg/Library/UefiSortLib/UefiSortLib.inf + + NetLib|MdeModulePkg/Library/DxeNetLib/DxeNetLib.inf + HandleParsingLib|ShellPkg/Library/UefiHandleParsingLib/UefiHandleParsingLib.inf + + BcfgCommandLib|ShellPkg/Library/UefiShellBcfgCommandLib/UefiShellBcfgCommandLib.inf + + TpmMeasurementLib|MdeModulePkg/Library/TpmMeasurementLibNull/TpmMeasurementLibNull.inf + AuthVariableLib|MdeModulePkg/Library/AuthVariableLibNull/AuthVariableLibNull.inf + VarCheckLib|MdeModulePkg/Library/VarCheckLib/VarCheckLib.inf + +[LibraryClasses.common.SEC] + + PcdLib|MdePkg/Library/BasePcdLibNull/BasePcdLibNull.inf + ReportStatusCodeLib|IntelFrameworkModulePkg/Library/PeiDxeDebugLibReportStatusCode/PeiDxeDebugLibReportStatusCode.inf + UefiDecompressLib|MdePkg/Library/BaseUefiDecompressLib/BaseUefiDecompressLib.inf + ExtractGuidedSectionLib|EmbeddedPkg/Library/PrePiExtractGuidedSectionLib/PrePiExtractGuidedSectionLib.inf + LzmaDecompressLib|IntelFrameworkModulePkg/Library/LzmaCustomDecompressLib/LzmaCustomDecompressLib.inf + + PeCoffLib|MdePkg/Library/BasePeCoffLib/BasePeCoffLib.inf + + HobLib|EmbeddedPkg/Library/PrePiHobLib/PrePiHobLib.inf + PrePiHobListPointerLib|ArmPlatformPkg/Library/PrePiHobListPointerLib/PrePiHobListPointerLib.inf + MemoryAllocationLib|EmbeddedPkg/Library/PrePiMemoryAllocationLib/PrePiMemoryAllocationLib.inf + PerformanceLib|MdeModulePkg/Library/PeiPerformanceLib/PeiPerformanceLib.inf + PlatformPeiLib|ArmPlatformPkg/PlatformPei/PlatformPeiLib.inf + MemoryInitPeiLib|ArmPlatformPkg/MemoryInitPei/MemoryInitPeiLib.inf + + # 1/123 faster than Stm or Vstm version + BaseMemoryLib|MdePkg/Library/BaseMemoryLib/BaseMemoryLib.inf + + # Uncomment to turn on GDB stub in SEC. + #DebugAgentLib|EmbeddedPkg/Library/GdbDebugAgent/GdbDebugAgent.inf + +[LibraryClasses.common.PEI_CORE] + PcdLib|MdePkg/Library/BasePcdLibNull/BasePcdLibNull.inf + ReportStatusCodeLib|IntelFrameworkModulePkg/Library/PeiDxeDebugLibReportStatusCode/PeiDxeDebugLibReportStatusCode.inf + +[LibraryClasses.common.DXE_CORE] + HobLib|MdePkg/Library/DxeCoreHobLib/DxeCoreHobLib.inf + MemoryAllocationLib|MdeModulePkg/Library/DxeCoreMemoryAllocationLib/DxeCoreMemoryAllocationLib.inf + DxeCoreEntryPoint|MdePkg/Library/DxeCoreEntryPoint/DxeCoreEntryPoint.inf + ReportStatusCodeLib|IntelFrameworkModulePkg/Library/DxeReportStatusCodeLibFramework/DxeReportStatusCodeLib.inf + ExtractGuidedSectionLib|MdePkg/Library/DxeExtractGuidedSectionLib/DxeExtractGuidedSectionLib.inf + UefiDecompressLib|MdePkg/Library/BaseUefiDecompressLib/BaseUefiDecompressLib.inf + DxeServicesLib|MdePkg/Library/DxeServicesLib/DxeServicesLib.inf + PeCoffLib|EmbeddedPkg/Library/DxeHobPeCoffLib/DxeHobPeCoffLib.inf + + PerformanceLib|MdeModulePkg/Library/DxeCorePerformanceLib/DxeCorePerformanceLib.inf + +[LibraryClasses.common.DXE_DRIVER] + ReportStatusCodeLib|IntelFrameworkModulePkg/Library/DxeReportStatusCodeLibFramework/DxeReportStatusCodeLib.inf + DxeServicesLib|MdePkg/Library/DxeServicesLib/DxeServicesLib.inf + SecurityManagementLib|MdeModulePkg/Library/DxeSecurityManagementLib/DxeSecurityManagementLib.inf + PerformanceLib|MdeModulePkg/Library/DxePerformanceLib/DxePerformanceLib.inf + MemoryInitPeiLib|ArmPlatformPkg/MemoryInitPei/MemoryInitPeiLib.inf + +[LibraryClasses.common.UEFI_APPLICATION] + PcdLib|MdePkg/Library/DxePcdLib/DxePcdLib.inf + HobLib|MdePkg/Library/DxeHobLib/DxeHobLib.inf + ReportStatusCodeLib|IntelFrameworkModulePkg/Library/DxeReportStatusCodeLibFramework/DxeReportStatusCodeLib.inf + UefiDecompressLib|IntelFrameworkModulePkg/Library/BaseUefiTianoCustomDecompressLib/BaseUefiTianoCustomDecompressLib.inf + PerformanceLib|MdeModulePkg/Library/DxePerformanceLib/DxePerformanceLib.inf + +[LibraryClasses.common.UEFI_DRIVER] + ReportStatusCodeLib|IntelFrameworkModulePkg/Library/DxeReportStatusCodeLibFramework/DxeReportStatusCodeLib.inf + UefiDecompressLib|IntelFrameworkModulePkg/Library/BaseUefiTianoCustomDecompressLib/BaseUefiTianoCustomDecompressLib.inf + ExtractGuidedSectionLib|MdePkg/Library/DxeExtractGuidedSectionLib/DxeExtractGuidedSectionLib.inf + PerformanceLib|MdeModulePkg/Library/DxePerformanceLib/DxePerformanceLib.inf + DxeServicesLib|MdePkg/Library/DxeServicesLib/DxeServicesLib.inf + +[LibraryClasses.common.DXE_RUNTIME_DRIVER] + HobLib|MdePkg/Library/DxeHobLib/DxeHobLib.inf + MemoryAllocationLib|MdePkg/Library/UefiMemoryAllocationLib/UefiMemoryAllocationLib.inf + ReportStatusCodeLib|IntelFrameworkModulePkg/Library/DxeReportStatusCodeLibFramework/DxeReportStatusCodeLib.inf + CapsuleLib|MdeModulePkg/Library/DxeCapsuleLibNull/DxeCapsuleLibNull.inf + PeCoffLib|EmbeddedPkg/Library/DxeHobPeCoffLib/DxeHobPeCoffLib.inf + +[LibraryClasses.AARCH64] + # + # It is not possible to prevent the ARM compiler for generic intrinsic functions. + # This library provides the instrinsic functions generate by a given compiler. + # [LibraryClasses.ARM] and NULL mean link this library into all ARM images. + # + NULL|ArmPkg/Library/CompilerIntrinsicsLib/CompilerIntrinsicsLib.inf + +################################################################################ +# +# Pcd Section - list of all EDK II PCD Entries defined by this Platform +# +################################################################################ + +[PcdsFeatureFlag.common] + ## If TRUE, Graphics Output Protocol will be installed on virtual handle created by ConsplitterDxe. + # It could be set FALSE to save size. + gEfiMdeModulePkgTokenSpaceGuid.PcdConOutGopSupport|TRUE + gEfiMdeModulePkgTokenSpaceGuid.PcdConOutUgaSupport|FALSE + + gEfiMdePkgTokenSpaceGuid.PcdComponentNameDisable|TRUE + gEfiMdePkgTokenSpaceGuid.PcdDriverDiagnosticsDisable|TRUE + gEfiMdePkgTokenSpaceGuid.PcdComponentName2Disable|TRUE + gEfiMdePkgTokenSpaceGuid.PcdDriverDiagnostics2Disable|TRUE + + # + # Control what commands are supported from the UI + # Turn these on and off to add features or save size + # + gEmbeddedTokenSpaceGuid.PcdEmbeddedMacBoot|TRUE + gEmbeddedTokenSpaceGuid.PcdEmbeddedDirCmd|TRUE + gEmbeddedTokenSpaceGuid.PcdEmbeddedHobCmd|TRUE + gEmbeddedTokenSpaceGuid.PcdEmbeddedHwDebugCmd|TRUE + gEmbeddedTokenSpaceGuid.PcdEmbeddedPciDebugCmd|TRUE + gEmbeddedTokenSpaceGuid.PcdEmbeddedIoEnable|FALSE + gEmbeddedTokenSpaceGuid.PcdEmbeddedScriptCmd|FALSE + + gEmbeddedTokenSpaceGuid.PcdCacheEnable|TRUE + + # Use the Vector Table location in CpuDxe. We will not copy the Vector Table at PcdCpuVectorBaseAddress + gArmTokenSpaceGuid.PcdRelocateVectorTable|FALSE + + gEmbeddedTokenSpaceGuid.PcdPrePiProduceMemoryTypeInformationHob|TRUE + gArmTokenSpaceGuid.PcdCpuDxeProduceDebugSupport|FALSE + + gEfiMdeModulePkgTokenSpaceGuid.PcdTurnOffUsbLegacySupport|TRUE + +[PcdsDynamicDefault.common] + # + # Set video resolution for boot options and for text setup. + # PlatformDxe can set the former at runtime. + # + gEfiMdeModulePkgTokenSpaceGuid.PcdVideoHorizontalResolution|800 + gEfiMdeModulePkgTokenSpaceGuid.PcdVideoVerticalResolution|600 + gEfiMdeModulePkgTokenSpaceGuid.PcdSetupVideoHorizontalResolution|640 + gEfiMdeModulePkgTokenSpaceGuid.PcdSetupVideoVerticalResolution|480 + +[PcdsFixedAtBuild.common] + gEfiMdeModulePkgTokenSpaceGuid.PcdMaxVariableSize|0x2000 + gEfiMdeModulePkgTokenSpaceGuid.PcdMaxAuthVariableSize|0x2800 + + gEfiMdeModulePkgTokenSpaceGuid.PcdResetOnMemoryTypeInformationChange|FALSE + gEfiMdeModulePkgTokenSpaceGuid.PcdBootManagerMenuFile|{ 0x21, 0xaa, 0x2c, 0x46, 0x14, 0x76, 0x03, 0x45, 0x83, 0x6e, 0x8a, 0xb6, 0xf4, 0x66, 0x23, 0x31 } + gEfiIntelFrameworkModulePkgTokenSpaceGuid.PcdShellFile|{ 0x83, 0xA5, 0x04, 0x7C, 0x3E, 0x9E, 0x1C, 0x4F, 0xAD, 0x65, 0xE0, 0x52, 0x68, 0xD0, 0xB4, 0xD1 } + gEfiMdePkgTokenSpaceGuid.PcdPlatformBootTimeOut|20 + + gArmPlatformTokenSpaceGuid.PcdFirmwareVendor|"LS1043a RDB board" + gEmbeddedTokenSpaceGuid.PcdEmbeddedPrompt|"LS1043a" + + gArmPlatformTokenSpaceGuid.PcdCoreCount|1 # Only one core + gArmPlatformTokenSpaceGuid.PcdCounterFrequency|12000000 #12Mhz + + gEfiMdePkgTokenSpaceGuid.PcdMaximumUnicodeStringLength|1000000 + gEfiMdePkgTokenSpaceGuid.PcdMaximumAsciiStringLength|2000000 + gEfiMdePkgTokenSpaceGuid.PcdMaximumLinkedListLength|1000000 + gEfiMdePkgTokenSpaceGuid.PcdSpinLockTimeout|10000000 + gEfiMdePkgTokenSpaceGuid.PcdDebugClearMemoryValue|0xAF + gEfiMdePkgTokenSpaceGuid.PcdPerformanceLibraryPropertyMask|1 + #gEfiMdePkgTokenSpaceGuid.PcdPerformanceLibraryPropertyMask|0 # turn off for now + gEfiMdePkgTokenSpaceGuid.PcdPostCodePropertyMask|0 + gEfiMdePkgTokenSpaceGuid.PcdUefiLibMaxPrintBufferSize|320 + +# DEBUG_ASSERT_ENABLED 0x01 +# DEBUG_PRINT_ENABLED 0x02 +# DEBUG_CODE_ENABLED 0x04 +# CLEAR_MEMORY_ENABLED 0x08 +# ASSERT_BREAKPOINT_ENABLED 0x10 +# ASSERT_DEADLOOP_ENABLED 0x20 +!if $(TARGET) == RELEASE + gEfiMdePkgTokenSpaceGuid.PcdDebugPropertyMask|0x27 + gEfiMdePkgTokenSpaceGuid.PcdDebugPrintErrorLevel|0x81000000 #0x8000000F #Print almost everything +!else + gEfiMdePkgTokenSpaceGuid.PcdDebugPropertyMask|0x2F + gEfiMdePkgTokenSpaceGuid.PcdDebugPrintErrorLevel|0x81000044 #0x8000000F #Print almost everything +!endif + +# DEBUG_INIT 0x00000001 // Initialization +# DEBUG_WARN 0x00000002 // Warnings +# DEBUG_LOAD 0x00000004 // Load events +# DEBUG_FS 0x00000008 // EFI File system +# DEBUG_POOL 0x00000010 // Alloc & Free's +# DEBUG_PAGE 0x00000020 // Alloc & Free's +# DEBUG_INFO 0x00000040 // Verbose +# DEBUG_DISPATCH 0x00000080 // PEI/DXE Dispatchers +# DEBUG_VARIABLE 0x00000100 // Variable +# DEBUG_BM 0x00000400 // Boot Manager +# DEBUG_BLKIO 0x00001000 // BlkIo Driver +# DEBUG_NET 0x00004000 // SNI Driver +# DEBUG_UNDI 0x00010000 // UNDI Driver +# DEBUG_LOADFILE 0x00020000 // UNDI Driver +# DEBUG_EVENT 0x00080000 // Event messages +# DEBUG_ERROR 0x80000000 // Error + + gEfiMdePkgTokenSpaceGuid.PcdReportStatusCodePropertyMask|0x07 + + gEmbeddedTokenSpaceGuid.PcdEmbeddedAutomaticBootCommand|"" + gEmbeddedTokenSpaceGuid.PcdEmbeddedDefaultTextColor|0x07 + gEmbeddedTokenSpaceGuid.PcdEmbeddedMemVariableStoreSize|0x10000 + +# +# Optional feature to help prevent EFI memory map fragments +# Turned on and off via: PcdPrePiProduceMemoryTypeInformationHob +# Values are in EFI Pages (4K). DXE Core will make sure that +# at least this much of each type of memory can be allocated +# from a single memory range. This way you only end up with +# maximum of two fragements for each type in the memory map +# (the memory used, and the free memory that was prereserved +# but not used). +# + gEmbeddedTokenSpaceGuid.PcdMemoryTypeEfiACPIReclaimMemory|0 + gEmbeddedTokenSpaceGuid.PcdMemoryTypeEfiACPIMemoryNVS|0 + gEmbeddedTokenSpaceGuid.PcdMemoryTypeEfiReservedMemoryType|0 + gEmbeddedTokenSpaceGuid.PcdMemoryTypeEfiRuntimeServicesData|80 + gEmbeddedTokenSpaceGuid.PcdMemoryTypeEfiRuntimeServicesCode|40 + gEmbeddedTokenSpaceGuid.PcdMemoryTypeEfiBootServicesCode|400 + gEmbeddedTokenSpaceGuid.PcdMemoryTypeEfiBootServicesData|3000 + gEmbeddedTokenSpaceGuid.PcdMemoryTypeEfiLoaderCode|10 + gEmbeddedTokenSpaceGuid.PcdMemoryTypeEfiLoaderData|0 + + # PCI PCDs + # + gArmPlatformTokenSpaceGuid.PcdKludgeMapPciMmioAsCached|FALSE + gArmPlatformTokenSpaceGuid.PcdPciBusMin|0 + gArmPlatformTokenSpaceGuid.PcdPciBusMax|255 + gArmPlatformTokenSpaceGuid.PcdPciIoBase|0x00010000 + gArmPlatformTokenSpaceGuid.PcdPciIoSize|0x00010000 # 64k + gArmPlatformTokenSpaceGuid.PcdPciIoTranslation|0x00010000 + gArmPlatformTokenSpaceGuid.PcdPciMmio32Base|0x40000000 + gArmPlatformTokenSpaceGuid.PcdPciMmio32Size|0x40000000 # 128M + gArmPlatformTokenSpaceGuid.PcdPciMemTranslation|0x5000000000 + gArmPlatformTokenSpaceGuid.PcdPciMmio64Base|0x5040000000 + gArmPlatformTokenSpaceGuid.PcdPciMmio64Size|0x40000000 + gEfiMdePkgTokenSpaceGuid.PcdPci1ExpressBaseAddress|0x5000000000 + gEfiMdePkgTokenSpaceGuid.PcdPci2ExpressBaseAddress|0x4800000000 + gEfiMdePkgTokenSpaceGuid.PcdPci3ExpressBaseAddress|0x5000000000 + + ## Serial Terminal + gEfiMdeModulePkgTokenSpaceGuid.PcdSerialRegisterBase|0x21c0500 + gEfiMdePkgTokenSpaceGuid.PcdUartDefaultBaudRate|115200 + + gEfiMdePkgTokenSpaceGuid.PcdDefaultTerminalType|4 + + # + # ARM General Interrupt Controller + gArmTokenSpaceGuid.PcdGicDistributorBase|0x1401000 + gArmTokenSpaceGuid.PcdGicInterruptInterfaceBase|0x1402000 + + # + # LS1043a board Specific PCDs + # XX (DRAM - Region 1 2GB) + # (NOR - IFC Region 1 512MB) + gArmTokenSpaceGuid.PcdSystemMemoryBase|0x80000000 + gArmTokenSpaceGuid.PcdSystemMemorySize|0x80000000 + + # + # LS1043a Soc Specific PCDs + # + gArmPlatformTokenSpaceGuid.PcdCounterFrequencyReal|TRUE + gArmPlatformTokenSpaceGuid.PcdCsuInitialize|TRUE + gArmPlatformTokenSpaceGuid.PcdTzc380Initialize|TRUE + gArmPlatformTokenSpaceGuid.PcdCci400Initialize|TRUE + gArmPlatformTokenSpaceGuid.PcdClockInitialize|TRUE + + # + # PPA specific PCDs + # + gNxpQoriqLsTokenSpaceGuid.PcdPpaNorBaseAddr|0x60500000 + gNxpQoriqLsTokenSpaceGuid.PcdPpaDdrOffsetAddr|0x8000000 # (128MB) calculated from top of DDR + + # Size of the region used by UEFI in permanent memory (Reserved 16MB) + gArmPlatformTokenSpaceGuid.PcdSystemMemoryUefiRegionSize|0x01000000 + + # Size of the region reserved for fixed address allocations (Reserved 32MB) + gArmTokenSpaceGuid.PcdArmLinuxKernelMaxOffset|0x08000000 + gArmTokenSpaceGuid.PcdArmLinuxFdtMaxOffset|0x08000000 + gArmTokenSpaceGuid.PcdArmLinuxFdtAlignment|0x0 + + gArmTokenSpaceGuid.PcdCpuVectorBaseAddress|0x94A00000 + gArmTokenSpaceGuid.PcdCpuResetAddress|0x94A00000 + + # Timer + gArmTokenSpaceGuid.PcdArmArchTimerFreqInHz|0 + gEmbeddedTokenSpaceGuid.PcdTimerPeriod|10000 # expressed in 100ns units, 100,000 x 100 ns = 10,000,000 ns = 10 ms + gArmPlatformTokenSpaceGuid.PcdArmArchTimerVirtIntrNum|11 # Virtual PPI + gArmPlatformTokenSpaceGuid.PcdArmArchTimerHypIntrNum|10 # Hypervisor PPI + gArmPlatformTokenSpaceGuid.PcdArmArchTimerSecIntrNum|13 # Physical Secure PPI + gArmPlatformTokenSpaceGuid.PcdArmArchTimerIntrNum|14 # Physical Non-Secure PPI + gEmbeddedTokenSpaceGuid.PcdMetronomeTickPeriod|1000 + #gEmbeddedTokenSpaceGuid.PcdEmbeddedPerformanceCounterPeriodInNanoseconds|77 + #gEmbeddedTokenSpaceGuid.PcdEmbeddedPerformanceCounterFrequencyInHz|13000000 + + # We want to use the Shell Libraries but don't want it to initialise + # automatically. We initialise the libraries when the command is called by the + # Shell. + gEfiShellPkgTokenSpaceGuid.PcdShellLibAutoInitialize|FALSE + + # + # ARM Pcds + # + gArmTokenSpaceGuid.PcdArmUncachedMemoryMask|0x0000000040000000 + + gArmPlatformTokenSpaceGuid.PcdDefaultBootDescription|L"EFI Linux from NOR flash" + gArmPlatformTokenSpaceGuid.PcdDefaultBootDevicePath|L"MemoryMapped(0x0,0x61100000,0x6111FFFF)" + gEmbeddedTokenSpaceGuid.PcdFdtDevicePaths|L"MemoryMapped(0x0,0x61B00000,0x61BFFFFF)/fsl-ls1043a-uefi-rdb.dtb" + + gArmPlatformTokenSpaceGuid.PcdDefaultBootArgument|L"MemoryMapped(0x0,0x61120000,0x61AFFFFF) -d "MemoryMapped(0x0,0x61B00000,0x61BFFFFF)" -f "MemoryMapped(0x0,0x61C00000,0x638FFFFF)" -c "console=ttyS0,115200 root=/dev/ram0 earlycon=uart8250,0x21c0500,115200"" + + # PPA + gLS1043aRdbTokenSpaceGuid.PcdPpaFitConfiguration|"config@1" + + # Use the serial console for both ConIn & ConOut + gArmPlatformTokenSpaceGuid.PcdDefaultConOutPaths|L"VenHw(D3987D4B-971A-435F-8CAF-4967EB627241)/Uart(115200,8,N,1)/VenPcAnsi();" + gArmPlatformTokenSpaceGuid.PcdDefaultConInPaths|L"VenHw(D3987D4B-971A-435F-8CAF-4967EB627241)/Uart(115200,8,N,1)/VenPcAnsi()" + + gEfiShellPkgTokenSpaceGuid.PcdShellLibAutoInitialize|FALSE + gEfiMdePkgTokenSpaceGuid.PcdUefiLibMaxPrintBufferSize|16000 +!ifdef $(NO_SHELL_PROFILES) + gEfiShellPkgTokenSpaceGuid.PcdShellProfileMask|0x00 +!endif #$(NO_SHELL_PROFILES) + + gNxpQoriqLsTokenSpaceGuid.PcdFdNorBaseAddress|0x60400000 + gNxpQoriqLsTokenSpaceGuid.PcdOcramStackBase|0x10010000 + gNxpQoriqLsTokenSpaceGuid.PcdI2cBus|0 + gNxpQoriqLsTokenSpaceGuid.PcdI2cSpeed|10000 + gNxpQoriqLsTokenSpaceGuid.PcdRtcI2cBus|0 + gNxpQoriqLsTokenSpaceGuid.PcdDs1307I2cAddress|0x68 + +################################################################################ +# +# Components Section - list of all EDK II Modules needed by this Platform +# +################################################################################ +[Components.common] + # + # SEC + # + OpenPlatformPkg/Chips/Nxp/QoriqLs/Library/PrePiNor/PrePiNor.inf + ArmPlatformPkg/PrePi/PeiUniCore.inf + + # + # DXE + # + MdeModulePkg/Core/Dxe/DxeMain.inf { + <LibraryClasses> + PcdLib|MdePkg/Library/BasePcdLibNull/BasePcdLibNull.inf + NULL|MdeModulePkg/Library/DxeCrc32GuidedSectionExtractLib/DxeCrc32GuidedSectionExtractLib.inf + NULL|EmbeddedPkg/Library/LzmaHobCustomDecompressLib/LzmaHobCustomDecompressLib.inf + } + MdeModulePkg/Universal/PCD/Dxe/Pcd.inf { + <LibraryClasses> + PcdLib|MdePkg/Library/BasePcdLibNull/BasePcdLibNull.inf + } + + # + # Architectural Protocols + # + ArmPkg/Drivers/CpuDxe/CpuDxe.inf + MdeModulePkg/Core/RuntimeDxe/RuntimeDxe.inf + MdeModulePkg/Universal/SecurityStubDxe/SecurityStubDxe.inf + MdeModulePkg/Universal/CapsuleRuntimeDxe/CapsuleRuntimeDxe.inf + MdeModulePkg/Universal/Variable/EmuRuntimeDxe/EmuVariableRuntimeDxe.inf + EmbeddedPkg/EmbeddedMonotonicCounter/EmbeddedMonotonicCounter.inf + + # FDT installation + EmbeddedPkg/Drivers/FdtPlatformDxe/FdtPlatformDxe.inf + + MdeModulePkg/Universal/Console/ConPlatformDxe/ConPlatformDxe.inf + MdeModulePkg/Universal/Console/ConSplitterDxe/ConSplitterDxe.inf + MdeModulePkg/Universal/Console/GraphicsConsoleDxe/GraphicsConsoleDxe.inf + MdeModulePkg/Universal/Console/TerminalDxe/TerminalDxe.inf + MdeModulePkg/Universal/SerialDxe/SerialDxe.inf + + MdeModulePkg/Universal/Acpi/AcpiTableDxe/AcpiTableDxe.inf + + EmbeddedPkg/ResetRuntimeDxe/ResetRuntimeDxe.inf + EmbeddedPkg/RealTimeClockRuntimeDxe/RealTimeClockRuntimeDxe.inf + EmbeddedPkg/MetronomeDxe/MetronomeDxe.inf + ArmPkg/Drivers/TimerDxe/TimerDxe.inf + OpenPlatformPkg/Platforms/Nxp/LS1043aRdb/LS1043aWatchDog/LS1043aWatchDogDxe.inf + ArmPkg/Drivers/ArmGic/ArmGicDxe.inf + + EmbeddedPkg/SimpleTextInOutSerial/SimpleTextInOutSerial.inf + + # + # PPA + # + OpenPlatformPkg/Chips/Nxp/QoriqLs/PpaInitDxe/PpaInitDxe.inf + + # + # FAT filesystem + GPT/MBR partitioning + # + MdeModulePkg/Universal/Disk/UnicodeCollation/EnglishDxe/EnglishDxe.inf + + # + # I2C + # + OpenPlatformPkg/Chips/Nxp/QoriqLs/I2c/I2cDxe.inf + + # + # Bds + # + MdeModulePkg/Universal/DevicePathDxe/DevicePathDxe.inf + MdeModulePkg/Universal/DisplayEngineDxe/DisplayEngineDxe.inf + MdeModulePkg/Universal/SetupBrowserDxe/SetupBrowserDxe.inf + MdeModulePkg/Universal/BdsDxe/BdsDxe.inf + MdeModulePkg/Application/UiApp/UiApp.inf { + <LibraryClasses> + NULL|MdeModulePkg/Library/DeviceManagerUiLib/DeviceManagerUiLib.inf + NULL|MdeModulePkg/Library/BootManagerUiLib/BootManagerUiLib.inf + NULL|MdeModulePkg/Library/BootMaintenanceManagerUiLib/BootMaintenanceManagerUiLib.inf + } + + MdeModulePkg/Universal/HiiDatabaseDxe/HiiDatabaseDxe.inf + + # + # Example Application + # + MdeModulePkg/Application/HelloWorld/HelloWorld.inf + + ShellPkg/Library/UefiShellLib/UefiShellLib.inf + ShellPkg/Library/UefiShellCommandLib/UefiShellCommandLib.inf + ShellPkg/Library/UefiShellLevel2CommandsLib/UefiShellLevel2CommandsLib.inf + ShellPkg/Library/UefiHandleParsingLib/UefiHandleParsingLib.inf + + ShellPkg/Library/UefiDpLib/UefiDpLib.inf { + <LibraryClasses> + TimerLib|MdePkg/Library/BaseTimerLibNullTemplate/BaseTimerLibNullTemplate.inf + PerformanceLib|MdePkg/Library/BasePerformanceLibNull/BasePerformanceLibNull.inf + DxeServicesLib|MdePkg/Library/DxeServicesLib/DxeServicesLib.inf + } + +ShellPkg/Application/Shell/Shell.inf { + <LibraryClasses> + NULL|ShellPkg/Library/UefiShellLevel2CommandsLib/UefiShellLevel2CommandsLib.inf + NULL|ShellPkg/Library/UefiShellLevel1CommandsLib/UefiShellLevel1CommandsLib.inf + NULL|ShellPkg/Library/UefiShellLevel3CommandsLib/UefiShellLevel3CommandsLib.inf +!ifndef $(NO_SHELL_PROFILES) + NULL|ShellPkg/Library/UefiShellDriver1CommandsLib/UefiShellDriver1CommandsLib.inf + NULL|ShellPkg/Library/UefiShellInstall1CommandsLib/UefiShellInstall1CommandsLib.inf + NULL|ShellPkg/Library/UefiShellDebug1CommandsLib/UefiShellDebug1CommandsLib.inf + NULL|ShellPkg/Library/UefiShellNetwork1CommandsLib/UefiShellNetwork1CommandsLib.inf + NULL|ShellPkg/Library/UefiShellTftpCommandLib/UefiShellTftpCommandLib.inf +!ifdef $(INCLUDE_DP) + NULL|ShellPkg/Library/UefiDpLib/UefiDpLib.inf +!endif #$(INCLUDE_DP) +!ifdef $(INCLUDE_TFTP_COMMAND) + NULL|ShellPkg/Library/UefiShellTftpCommandLib/UefiShellTftpCommandLib.inf +!endif #$(INCLUDE_TFTP_COMMAND) +!endif #$(NO_SHELL_PROFILES) + } + + ## diff --git a/Platforms/Nxp/LS1043aRdb/LS1043aRdbPkg.fdf b/Platforms/Nxp/LS1043aRdb/LS1043aRdbPkg.fdf new file mode 100644 index 0000000..1633630 --- /dev/null +++ b/Platforms/Nxp/LS1043aRdb/LS1043aRdbPkg.fdf @@ -0,0 +1,311 @@ +# FLASH layout file for LS1043a board. +# +# Copyright (c) 2016, Freescale Ltd. All rights reserved. +# +# This program and the accompanying materials +# are licensed and made available under the terms and conditions of the BSD License +# which accompanies this distribution. The full text of the license may be found at +# http://opensource.org/licenses/bsd-license.php +# +# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, +# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. +# + +################################################################################ +# +# FD Section +# The [FD] Section is made up of the definition statements and a +# description of what goes into the Flash Device Image. Each FD section +# defines one flash "device" image. A flash device image may be one of +# the following: Removable media bootable image (like a boot floppy +# image,) an Option ROM image (that would be "flashed" into an add-in +# card,) a System "Flash" image (that would be burned into a system's +# flash) or an Update ("Capsule") image that will be used to update and +# existing system flash. +# +################################################################################ + +[FD.LS1043aRdb_EFI] +BaseAddress = 0xE0000000|gArmTokenSpaceGuid.PcdFdBaseAddress #The base address of the FLASH Device. +Size = 0x000C8000|gArmTokenSpaceGuid.PcdFdSize #The size in bytes of the FLASH Device +ErasePolarity = 1 +BlockSize = 0x1 +NumBlocks = 0xC8000 + +################################################################################ +# +# Following are lists of FD Region layout which correspond to the locations of different +# images within the flash device. +# +# Regions must be defined in ascending order and may not overlap. +# +# A Layout Region start with a eight digit hex offset (leading "0x" required) followed by +# the pipe "|" character, followed by the size of the region, also in hex with the leading +# "0x" characters. Like: +# Offset|Size +# PcdOffsetCName|PcdSizeCName +# RegionType <FV, DATA, or FILE> +# +################################################################################ +0x00000000|0x000C8000 +gArmTokenSpaceGuid.PcdFvBaseAddress|gArmTokenSpaceGuid.PcdFvSize +FV = FVMAIN_COMPACT + +[FD.LS1043aRdbPi_EFI] +BaseAddress = 0x60400000|gNxpQoriqLsTokenSpaceGuid.PcdPiFdBaseAddress #The base address of the FLASH Device. +Size = 0x00008000|gNxpQoriqLsTokenSpaceGuid.PcdPiFdSize #The size in bytes of the FLASH Device +ErasePolarity = 1 +BlockSize = 0x1 +NumBlocks = 0x8000 + +0x00000000|0x00008000 +gNxpQoriqLsTokenSpaceGuid.PcdFvNorBaseAddress|gNxpQoriqLsTokenSpaceGuid.PcdFvNorSize +FV = FVNOR_COMPACT + + +################################################################################ +# +# FV Section +# +# [FV] section is used to define what components or modules are placed within a flash +# device file. This section also defines order the components and modules are positioned +# within the image. The [FV] section consists of define statements, set statements and +# module statements. +# +################################################################################ + +[FV.FvMain] +BlockSize = 0x1 +NumBlocks = 0 # This FV gets compressed so make it just big enough +FvAlignment = 8 # FV alignment and FV attributes setting. +ERASE_POLARITY = 1 +MEMORY_MAPPED = TRUE +STICKY_WRITE = TRUE +LOCK_CAP = TRUE +LOCK_STATUS = TRUE +WRITE_DISABLED_CAP = TRUE +WRITE_ENABLED_CAP = TRUE +WRITE_STATUS = TRUE +WRITE_LOCK_CAP = TRUE +WRITE_LOCK_STATUS = TRUE +READ_DISABLED_CAP = TRUE +READ_ENABLED_CAP = TRUE +READ_STATUS = TRUE +READ_LOCK_CAP = TRUE +READ_LOCK_STATUS = TRUE + + INF MdeModulePkg/Core/Dxe/DxeMain.inf + INF MdeModulePkg/Universal/PCD/Dxe/Pcd.inf + + INF OpenPlatformPkg/Chips/Nxp/QoriqLs/PpaInitDxe/PpaInitDxe.inf + + # + # PI DXE Drivers producing Architectural Protocols (EFI Services) + # + INF ArmPkg/Drivers/CpuDxe/CpuDxe.inf + + INF MdeModulePkg/Core/RuntimeDxe/RuntimeDxe.inf + INF ArmPkg/Drivers/ArmGic/ArmGicDxe.inf + INF ArmPkg/Drivers/TimerDxe/TimerDxe.inf + INF OpenPlatformPkg/Platforms/Nxp/LS1043aRdb/LS1043aWatchDog/LS1043aWatchDogDxe.inf + INF MdeModulePkg/Universal/SecurityStubDxe/SecurityStubDxe.inf + INF MdeModulePkg/Universal/CapsuleRuntimeDxe/CapsuleRuntimeDxe.inf + INF MdeModulePkg/Universal/HiiDatabaseDxe/HiiDatabaseDxe.inf + INF EmbeddedPkg/EmbeddedMonotonicCounter/EmbeddedMonotonicCounter.inf + INF MdeModulePkg/Universal/Variable/EmuRuntimeDxe/EmuVariableRuntimeDxe.inf + # + # Multiple Console IO support + # + INF MdeModulePkg/Universal/Console/ConPlatformDxe/ConPlatformDxe.inf + INF MdeModulePkg/Universal/Console/ConSplitterDxe/ConSplitterDxe.inf + INF MdeModulePkg/Universal/Console/GraphicsConsoleDxe/GraphicsConsoleDxe.inf + INF MdeModulePkg/Universal/SerialDxe/SerialDxe.inf + INF MdeModulePkg/Universal/Console/TerminalDxe/TerminalDxe.inf + + INF EmbeddedPkg/ResetRuntimeDxe/ResetRuntimeDxe.inf + INF EmbeddedPkg/RealTimeClockRuntimeDxe/RealTimeClockRuntimeDxe.inf + INF EmbeddedPkg/MetronomeDxe/MetronomeDxe.inf + INF EmbeddedPkg/SimpleTextInOutSerial/SimpleTextInOutSerial.inf + + # + # I2C + # + INF OpenPlatformPkg/Chips/Nxp/QoriqLs/I2c/I2cDxe.inf + + # + # FAT filesystem + GPT/MBR partitioning + # + INF MdeModulePkg/Universal/Disk/UnicodeCollation/EnglishDxe/EnglishDxe.inf + + # + # UEFI application (Shell Embedded Boot Loader) + # + INF ShellPkg/Application/Shell/Shell.inf + #INF ShellBinPkg/UefiShell/UefiShell.inf + + # + # Bds + # + INF MdeModulePkg/Universal/DevicePathDxe/DevicePathDxe.inf + INF MdeModulePkg/Universal/DisplayEngineDxe/DisplayEngineDxe.inf + INF MdeModulePkg/Universal/SetupBrowserDxe/SetupBrowserDxe.inf + INF MdeModulePkg/Universal/BdsDxe/BdsDxe.inf + INF MdeModulePkg/Application/UiApp/UiApp.inf + + # + # FDT installation + # + # The UEFI driver is at the end of the list of the driver to be dispatched + # after the device drivers (eg: Ethernet) to ensure we have support for them. + + +[FV.FVNOR_COMPACT] +FvAlignment = 8 +ERASE_POLARITY = 1 +MEMORY_MAPPED = TRUE +STICKY_WRITE = TRUE +LOCK_CAP = TRUE +LOCK_STATUS = TRUE +WRITE_DISABLED_CAP = TRUE +WRITE_ENABLED_CAP = TRUE +WRITE_STATUS = TRUE +WRITE_LOCK_CAP = TRUE +WRITE_LOCK_STATUS = TRUE +READ_DISABLED_CAP = TRUE +READ_ENABLED_CAP = TRUE +READ_STATUS = TRUE +READ_LOCK_CAP = TRUE +READ_LOCK_STATUS = TRUE + + INF OpenPlatformPkg/Chips/Nxp/QoriqLs/Library/PrePiNor/PrePiNor.inf + + +[FV.FVMAIN_COMPACT] +FvAlignment = 8 +ERASE_POLARITY = 1 +MEMORY_MAPPED = TRUE +STICKY_WRITE = TRUE +LOCK_CAP = TRUE +LOCK_STATUS = TRUE +WRITE_DISABLED_CAP = TRUE +WRITE_ENABLED_CAP = TRUE +WRITE_STATUS = TRUE +WRITE_LOCK_CAP = TRUE +WRITE_LOCK_STATUS = TRUE +READ_DISABLED_CAP = TRUE +READ_ENABLED_CAP = TRUE +READ_STATUS = TRUE +READ_LOCK_CAP = TRUE +READ_LOCK_STATUS = TRUE + + INF ArmPlatformPkg/PrePi/PeiUniCore.inf + + FILE FV_IMAGE = 9E21FD93-9C72-4c15-8C4B-E77F1DB2D792 { + SECTION GUIDED EE4E5898-3914-4259-9D6E-DC7BD79403CF PROCESSING_REQUIRED = TRUE { + SECTION FV_IMAGE = FVMAIN + } + } + +################################################################################ +# +# Rules are use with the [FV] section's module INF type to define +# how an FFS file is created for a given INF file. The following Rule are the default +# rules for the different module type. User can add the customized rules to define the +# content of the FFS file. +# +################################################################################ + + +############################################################################ +# Example of a DXE_DRIVER FFS file with a Checksum encapsulation section # +############################################################################ +# +#[Rule.Common.DXE_DRIVER] +# FILE DRIVER = $(NAMED_GUID) { +# DXE_DEPEX DXE_DEPEX Optional $(INF_OUTPUT)/$(MODULE_NAME).depex +# COMPRESS PI_STD { +# GUIDED { +# PE32 PE32 $(INF_OUTPUT)/$(MODULE_NAME).efi +# UI STRING="$(MODULE_NAME)" Optional +# VERSION STRING="$(INF_VERSION)" Optional BUILD_NUM=$(BUILD_NUMBER) +# } +# } +# } +# +############################################################################ + +[Rule.Common.SEC] + FILE SEC = $(NAMED_GUID) RELOCS_STRIPPED { + TE TE Align = 32 $(INF_OUTPUT)/$(MODULE_NAME).efi + } + +[Rule.Common.PEI_CORE] + FILE PEI_CORE = $(NAMED_GUID) { + TE TE $(INF_OUTPUT)/$(MODULE_NAME).efi + UI STRING ="$(MODULE_NAME)" Optional + } + +[Rule.Common.PEIM] + FILE PEIM = $(NAMED_GUID) { + PEI_DEPEX PEI_DEPEX Optional $(INF_OUTPUT)/$(MODULE_NAME).depex + PE32 PE32 $(INF_OUTPUT)/$(MODULE_NAME).efi + UI STRING="$(MODULE_NAME)" Optional + } + +[Rule.Common.PEIM.TIANOCOMPRESSED] + FILE PEIM = $(NAMED_GUID) DEBUG_MYTOOLS_IA32 { + PEI_DEPEX PEI_DEPEX Optional $(INF_OUTPUT)/$(MODULE_NAME).depex + GUIDED A31280AD-481E-41B6-95E8-127F4C984779 PROCESSING_REQUIRED = TRUE { + PE32 PE32 $(INF_OUTPUT)/$(MODULE_NAME).efi + UI STRING="$(MODULE_NAME)" Optional + } + } + +[Rule.Common.DXE_CORE] + FILE DXE_CORE = $(NAMED_GUID) { + PE32 PE32 $(INF_OUTPUT)/$(MODULE_NAME).efi + UI STRING="$(MODULE_NAME)" Optional + } + + +[Rule.Common.UEFI_DRIVER] + FILE DRIVER = $(NAMED_GUID) { + DXE_DEPEX DXE_DEPEX Optional $(INF_OUTPUT)/$(MODULE_NAME).depex + PE32 PE32 $(INF_OUTPUT)/$(MODULE_NAME).efi + UI STRING="$(MODULE_NAME)" Optional + } + +[Rule.Common.DXE_DRIVER] + FILE DRIVER = $(NAMED_GUID) { + DXE_DEPEX DXE_DEPEX Optional $(INF_OUTPUT)/$(MODULE_NAME).depex + PE32 PE32 $(INF_OUTPUT)/$(MODULE_NAME).efi + UI STRING="$(MODULE_NAME)" Optional + } + +[Rule.Common.DXE_RUNTIME_DRIVER] + FILE DRIVER = $(NAMED_GUID) { + DXE_DEPEX DXE_DEPEX Optional $(INF_OUTPUT)/$(MODULE_NAME).depex + PE32 PE32 $(INF_OUTPUT)/$(MODULE_NAME).efi + UI STRING="$(MODULE_NAME)" Optional + } + +[Rule.Common.UEFI_APPLICATION] + FILE APPLICATION = $(NAMED_GUID) { + UI STRING ="$(MODULE_NAME)" Optional + PE32 PE32 $(INF_OUTPUT)/$(MODULE_NAME).efi + } + +[Rule.Common.UEFI_DRIVER.BINARY] + FILE DRIVER = $(NAMED_GUID) { + DXE_DEPEX DXE_DEPEX Optional |.depex + PE32 PE32 |.efi + UI STRING="$(MODULE_NAME)" Optional + VERSION STRING="$(INF_VERSION)" Optional BUILD_NUM=$(BUILD_NUMBER) + } + +[Rule.Common.UEFI_APPLICATION.BINARY] + FILE APPLICATION = $(NAMED_GUID) { + PE32 PE32 |.efi + UI STRING="$(MODULE_NAME)" Optional + VERSION STRING="$(INF_VERSION)" Optional BUILD_NUM=$(BUILD_NUMBER) + } diff --git a/Platforms/Nxp/LS1043aRdb/build.sh b/Platforms/Nxp/LS1043aRdb/build.sh new file mode 100755 index 0000000..4012a78 --- /dev/null +++ b/Platforms/Nxp/LS1043aRdb/build.sh @@ -0,0 +1,72 @@ +#!/bin/bash + +# UEFI build script for LS1043A SoC from Freescale +# +# Copyright (c) 2016, Freescale Semiconductor, Inc. All rights reserved. +# +# This program and the accompanying materials +# are licensed and made available under the terms and conditions of the BSD License +# which accompanies this distribution. The full text of the license may be found at +# http://opensource.org/licenses/bsd-license.php +# +# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, +# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. +# + +print_usage_banner() +{ + echo "This shell script expects:" + echo " Arg 1 (mandatory): Build candidate (can be RELEASE or DEBUG). By + default we build the RELEASE candidate." + echo " Arg 2 (optional): clean - To do a 'make clean' operation." +} + +# Actual stuff starts from here +echo ".........................................." +echo "Welcome to LS1043A UEFI Build environment" +echo ".........................................." + +# Check for input arguments +if [[ $1 == "" ]]; then + echo "Error ! No build target specified." + print_usage_banner + exit +fi + +# Check for input arguments +if [[ $1 != "RELEASE" ]]; then + if [[ $1 != "DEBUG" ]]; then + echo "Error ! Incorrect build target specified." + print_usage_banner + exit + fi +fi + +if [[ $2 == "clean" ]]; then + echo "Cleaning up the build directory '../../../../Build/LS1043aRdb/'.." + rm -rf ../../../../Build/LS1043aRdb/* + exit +fi + +# Clean-up +set -e +shopt -s nocasematch + +# +# Setup workspace now +# +echo Initializing workspace +cd ../../../../ + +# Use the BaseTools in edk2 +export EDK_TOOLS_PATH=`pwd`/BaseTools +source edksetup.sh BaseTools + +# Global Defaults +ARCH=AARCH64 +TARGET_TOOLS=GCC49 + +build -p "$WORKSPACE/OpenPlatformPkg/Platforms/Nxp/LS1043aRdb/LS1043aRdbPkg.dsc" -a $ARCH -t $TARGET_TOOLS -b $1 + +cat $WORKSPACE/Build/LS1043aRdb/$1_GCC49/FV/LS1043ARDB_EFI.fd >> $WORKSPACE/Build/LS1043aRdb/$1_GCC49/FV/LS1043ARDBPI_EFI.fd +mv $WORKSPACE/Build/LS1043aRdb/$1_GCC49/FV/LS1043ARDBPI_EFI.fd $WORKSPACE/Build/LS1043aRdb/$1_GCC49/FV/LS1043ARDB_EFI.fd diff --git a/Platforms/Nxp/LS1043aRdb/ls1043a_env.cshrc b/Platforms/Nxp/LS1043aRdb/ls1043a_env.cshrc new file mode 100644 index 0000000..63d702e --- /dev/null +++ b/Platforms/Nxp/LS1043aRdb/ls1043a_env.cshrc @@ -0,0 +1,2 @@ +export GCC49_AARCH64_PREFIX='aarch64-linux-gnu-' +unset ARCH
On Tue, Oct 18, 2016 at 01:34:13AM +0530, Bhupesh Sharma wrote:
From: Sakar Arora sakar.arora@nxp.com
The patch adds the device description, flash description and declaration files for the LS1043aRdbPkg.
In addition this patch also adds the build scripts required to build this package.
Signed-off-by: Sakar Arora sakar.arora@nxp.com Signed-off-by: Bhupesh Sharma bhupesh.sharma@nxp.com
Chips/Nxp/QoriqLs/NxpQoriqLs.dec | 50 +++ Platforms/Nxp/LS1043aRdb/LS1043aRdbPkg.dec | 166 ++++++++ Platforms/Nxp/LS1043aRdb/LS1043aRdbPkg.dsc | 602 +++++++++++++++++++++++++++++ Platforms/Nxp/LS1043aRdb/LS1043aRdbPkg.fdf | 311 +++++++++++++++ Platforms/Nxp/LS1043aRdb/build.sh | 72 ++++ Platforms/Nxp/LS1043aRdb/ls1043a_env.cshrc | 2 + 6 files changed, 1203 insertions(+) create mode 100644 Chips/Nxp/QoriqLs/NxpQoriqLs.dec create mode 100644 Platforms/Nxp/LS1043aRdb/LS1043aRdbPkg.dec create mode 100644 Platforms/Nxp/LS1043aRdb/LS1043aRdbPkg.dsc create mode 100644 Platforms/Nxp/LS1043aRdb/LS1043aRdbPkg.fdf create mode 100755 Platforms/Nxp/LS1043aRdb/build.sh create mode 100644 Platforms/Nxp/LS1043aRdb/ls1043a_env.cshrc
diff --git a/Chips/Nxp/QoriqLs/NxpQoriqLs.dec b/Chips/Nxp/QoriqLs/NxpQoriqLs.dec new file mode 100644 index 0000000..6b04836 --- /dev/null +++ b/Chips/Nxp/QoriqLs/NxpQoriqLs.dec
OK, this is a problem. This file is referenced by previous commits, which breaks bisect.
@@ -0,0 +1,50 @@ +#/** LS1043a board package. +# +# Copyright (c) 2016, Freescale Semiconductor, Inc. All rights reserved. +# +# This program and the accompanying materials are licensed and made available under +# the terms and conditions of the BSD License which accompanies this distribution. +# The full text of the license may be found at +# http://opensource.org/licenses/bsd-license.php +# +# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, +# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. +# +#**/
+[Defines]
- DEC_SPECIFICATION = 0x00010005
- PACKAGE_NAME = NxpQoriqLs
- PACKAGE_GUID = 6eba6648-d853-4eb3-9761-528b82d5ab14
- PACKAGE_VERSION = 0.1
+################################################################################ +# +# Include Section - list of Include Paths that are provided by this package. +# Comments are used for Keywords and Module Types. +# +# Supported Module Types: +# BASE SEC PEI_CORE PEIM DXE_CORE DXE_DRIVER DXE_RUNTIME_DRIVER DXE_SMM_DRIVER DXE_SAL_DRIVER UEFI_DRIVER UEFI_APPLICATION +# +################################################################################ +[Includes.common]
- Include # Root include for the package
+[Guids.common]
- gNxpQoriqLsTokenSpaceGuid = { 0x6834fe45, 0x4aee, 0x4fc6, { 0xbc, 0xb5, 0xff, 0x45, 0xb7, 0xa8, 0x71, 0xf2 } }
+[PcdsFixedAtBuild.common]
- gNxpQoriqLsTokenSpaceGuid.PcdOcramStackBase|0x0|UINT32|0x00000001
- gNxpQoriqLsTokenSpaceGuid.PcdFdNorBaseAddress|0x0|UINT64|0x00000002
- gNxpQoriqLsTokenSpaceGuid.PcdPiFdBaseAddress|0x0|UINT64|0x00000003
- gNxpQoriqLsTokenSpaceGuid.PcdPiFdSize|0x0|UINT32|0x00000004
- gNxpQoriqLsTokenSpaceGuid.PcdFvNorBaseAddress|0x0|UINT64|0x00000005
- gNxpQoriqLsTokenSpaceGuid.PcdFvNorSize|0x0|UINT32|0x00000006
- gNxpQoriqLsTokenSpaceGuid.PcdI2cBus|0|UINT32|0x0000007
- gNxpQoriqLsTokenSpaceGuid.PcdRtcI2cBus|0|UINT32|0x0000008
- gNxpQoriqLsTokenSpaceGuid.PcdDs1307I2cAddress|0|UINT32|0x0000009
- gNxpQoriqLsTokenSpaceGuid.PcdPpaFitConfiguration|""|VOID*|0x000000A
- gNxpQoriqLsTokenSpaceGuid.PcdPpaNorBaseAddr|0x0|UINT64|0x000000B
- gNxpQoriqLsTokenSpaceGuid.PcdPpaDdrOffsetAddr|0x0|UINT64|0x000000C
- gNxpQoriqLsTokenSpaceGuid.PcdI2cSpeed|0|UINT32|0x000000D
Sort these, please.
diff --git a/Platforms/Nxp/LS1043aRdb/LS1043aRdbPkg.dec b/Platforms/Nxp/LS1043aRdb/LS1043aRdbPkg.dec new file mode 100644 index 0000000..9df3eb7 --- /dev/null +++ b/Platforms/Nxp/LS1043aRdb/LS1043aRdbPkg.dec
Another bisect breakage. These need to go in before the components that reference them.
@@ -0,0 +1,166 @@ +#/** LS1043a board package. +# +# Copyright (c) 2016, Freescale Semiconductor, Inc. All rights reserved. +# +# This program and the accompanying materials are licensed and made available under +# the terms and conditions of the BSD License which accompanies this distribution. +# The full text of the license may be found at +# http://opensource.org/licenses/bsd-license.php +# +# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, +# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. +# +#**/
+[Defines]
- DEC_SPECIFICATION = 0x00010005
- PACKAGE_NAME = LS1043aRdbPkg
- PACKAGE_GUID = 6eba6648-d853-4eb3-9761-528b82d5ab04
- PACKAGE_VERSION = 0.1
+################################################################################ +# +# Include Section - list of Include Paths that are provided by this package. +# Comments are used for Keywords and Module Types. +# +# Supported Module Types: +# BASE SEC PEI_CORE PEIM DXE_CORE DXE_DRIVER DXE_RUNTIME_DRIVER DXE_SMM_DRIVER DXE_SAL_DRIVER UEFI_DRIVER UEFI_APPLICATION +# +################################################################################ +[Includes.common]
- Include # Root include for the package
+[Guids.common]
- gLS1043aRdbTokenSpaceGuid = { 0x6834fe45, 0x4aee, 0x4fc6, { 0xbc, 0xb5, 0xff, 0x45, 0xb7, 0xa8, 0x71, 0xe2 } }
- gEfiMmcHostProtocolGuid = { 0x3e591c00, 0x9e4a, 0x11df, {0x92, 0x44, 0x00, 0x02, 0xA5, 0xD5, 0xC5, 0x1B }}
- gShellDebug1HiiGuid = {0x25f200aa, 0xd3cb, 0x470a, {0xbf, 0x51, 0xe7, 0xd1, 0x62, 0xd2, 0x2e, 0x6f}}
- gShellNetwork1HiiGuid = {0xf3d301bb, 0xf4a5, 0x45a8, {0xb0, 0xb7, 0xfa, 0x99, 0x9c, 0x62, 0x37, 0xae}}
- gEfiDpcProtocolGuid = {0x480f8ae9, 0xc46, 0x4aa9, { 0xbc, 0x89, 0xdb, 0x9f, 0xba, 0x61, 0x98, 0x6 }}
- gShellTftpHiiGuid = {0x738a9314, 0x82c1, 0x4592, {0x8f, 0xf7, 0xc1, 0xbd, 0xf1, 0xb2, 0x0e, 0xd4}}
Sort these, please.
- ## Include/Protocol/SimpleNetwork.h
- gEfiSimpleNetworkProtocolGuid = { 0xA19832B9, 0xAC25, 0x11D3, { 0x9A, 0x2D, 0x00, 0x90, 0x27, 0x3F, 0xC1, 0x4D }}
- ## Include/Protocol/ManagedNetwork.h
- gEfiManagedNetworkServiceBindingProtocolGuid = { 0xF36FF770, 0xA7E1, 0x42CF, { 0x9E, 0xD2, 0x56, 0xF0, 0xF2, 0x71, 0xF4, 0x4C }}
- ## Include/Protocol/ManagedNetwork.h
- gEfiManagedNetworkProtocolGuid = { 0x7ab33a91, 0xace5, 0x4326, { 0xb5, 0x72, 0xe7, 0xee, 0x33, 0xd3, 0x9f, 0x16 }}
- ## Include/Protocol/HiiConfigRouting.h
- gEfiHiiConfigRoutingProtocolGuid = {0x587e72d7, 0xcc50, 0x4f79, {0x82, 0x09, 0xca, 0x29, 0x1f, 0xc1, 0xa1, 0x0f}}
- ## Include/Protocol/Arp.h
- gEfiArpServiceBindingProtocolGuid = { 0xF44C00EE, 0x1F2C, 0x4A00, { 0xAA, 0x09, 0x1C, 0x9F, 0x3E, 0x08, 0x00, 0xA3 }}
- ## Include/Protocol/Arp.h
- gEfiArpProtocolGuid = { 0xF4B427BB, 0xBA21, 0x4F16, { 0xBC, 0x4E, 0x43, 0xE4, 0x16, 0xAB, 0x61, 0x9C }}
- ## Include/Protocol/Dhcp4.h
- gEfiDhcp4ServiceBindingProtocolGuid = { 0x9D9A39D8, 0xBD42, 0x4A73, { 0xA4, 0xD5, 0x8E, 0xE9, 0x4B, 0xE1, 0x13, 0x80 }}
Why are you redefining all of these that already exist in MdePkg.dec? Please delete all of these (including the below ones).
- ## Include/Protocol/Dhcp4.h
- gEfiDhcp4ProtocolGuid = { 0x8A219718, 0x4EF5, 0x4761, { 0x91, 0xC8, 0xC0, 0xF0, 0x4B, 0xDA, 0x9E, 0x56 }}
- ## Include/Protocol/Tcp4.h
- gEfiTcp4ServiceBindingProtocolGuid = { 0x00720665, 0x67EB, 0x4A99, { 0xBA, 0xF7, 0xD3, 0xC3, 0x3A, 0x1C, 0x7C, 0xC9 }}
- ## Include/Protocol/Tcp4.h
- gEfiTcp4ProtocolGuid = { 0x65530BC7, 0xA359, 0x410F, { 0xB0, 0x10, 0x5A, 0xAD, 0xC7, 0xEC, 0x2B, 0x62 }}
- ## Include/Protocol/Ip4.h
- gEfiIp4ServiceBindingProtocolGuid = { 0xC51711E7, 0xB4BF, 0x404A, { 0xBF, 0xB8, 0x0A, 0x04, 0x8E, 0xF1, 0xFF, 0xE4 }}
- ## Include/Protocol/Ip4.h
- gEfiIp4ProtocolGuid = { 0x41D94CD2, 0x35B6, 0x455A, { 0x82, 0x58, 0xD4, 0xE5, 0x13, 0x34, 0xAA, 0xDD }}
- ## Include/Protocol/Ip4Config.h
- gEfiIp4ConfigProtocolGuid = { 0x3B95AA31, 0x3793, 0x434B, { 0x86, 0x67, 0xC8, 0x07, 0x08, 0x92, 0xE0, 0x5E }}
- ## Include/Protocol/Udp4.h
- gEfiUdp4ServiceBindingProtocolGuid = { 0x83F01464, 0x99BD, 0x45E5, { 0xB3, 0x83, 0xAF, 0x63, 0x05, 0xD8, 0xE9, 0xE6 }}
- ## Include/Protocol/Udp4.h
- gEfiUdp4ProtocolGuid = { 0x3AD9DF29, 0x4501, 0x478D, { 0xB1, 0xF8, 0x7F, 0x7F, 0xE7, 0x0E, 0x50, 0xF3 }}
- ## Include/Protocol/Mtftp4.h
- gEfiMtftp4ServiceBindingProtocolGuid = { 0x2FE800BE, 0x8F01, 0x4AA6, { 0x94, 0x6B, 0xD7, 0x13, 0x88, 0xE1, 0x83, 0x3F }}
- ## Include/Protocol/Mtftp4.h
- gEfiMtftp4ProtocolGuid = { 0x78247C57, 0x63DB, 0x4708, { 0x99, 0xC2, 0xA8, 0xB4, 0xA9, 0xA6, 0x1F, 0x6B }}
+[PcdsFixedAtBuild.common]
- # Size to reserve in the primary core stack for PEI Global Variables
- # = sizeof(UINTN) /* PcdPeiServicePtr or HobListPtr */
- gArmPlatformTokenSpaceGuid.PcdPeiGlobalVariableSize|0x4|UINT32|0x00000016
- gArmPlatformTokenSpaceGuid.PcdCounterFrequency|12000000|UINT32|0x00000017
New Pcds you are defining in this file should be in your own token space. In this case, gLS1043aRdbTokenSpaceGuid. Like it's done in NxpQoriqLs.dec.
- ## LS1043a UART
- gArmPlatformTokenSpaceGuid.LS1043aUartClkInHz|61440000|UINT32|0x00000018
- gArmPlatformTokenSpaceGuid.LS1043aUartInteger|0|UINT32|0x00000019
- gArmPlatformTokenSpaceGuid.LS1043aUartFractional|0|UINT32|0x0000001A
- ## Timer
- gArmTokenSpaceGuid.PcdArmArchTimerFreqInHz|0|UINT32|0x0000001B
- gEmbeddedTokenSpaceGuid.PcdTimerPeriod|10000|UINT32|0x0000001D
- gArmPlatformTokenSpaceGuid.PcdArmArchTimerVirtIntrNum|0|UINT32|0x0000001E
- gArmPlatformTokenSpaceGuid.PcdArmArchTimerHypIntrNum|0|UINT32|0x0000001F
- gArmPlatformTokenSpaceGuid.PcdArmArchTimerSecIntrNum|0|UINT32|0x00000020
- gArmPlatformTokenSpaceGuid.PcdArmArchTimerIntrNum|0|UINT32|0x00000021
- gEmbeddedTokenSpaceGuid.PcdMetronomeTickPeriod|0|UINT32|0x00000022
- gArmPlatformTokenSpaceGuid.PcdLS1043aWatchDogBase|0x0|UINT32|0x00000023
- gArmPlatformTokenSpaceGuid.DUartClkInHz|0x0|UINT32|0x00000024
- gArmPlatformTokenSpaceGuid.DUartInteger|0x0|UINT32|0x00000025
- ## Ddr
- gArmTokenSpaceGuid.PcdDdrInitialize|FALSE|BOOLEAN|0x00000026
- #
- # LS1043a Soc Specific PCDs
- #
- gArmPlatformTokenSpaceGuid.PcdCounterFrequencyReal|FALSE|BOOLEAN|0x00000027
- gArmPlatformTokenSpaceGuid.PcdCsuInitialize|FALSE|BOOLEAN|0x00000028
- gArmPlatformTokenSpaceGuid.PcdTzc380Initialize|FALSE|BOOLEAN|0x00000029
- gArmPlatformTokenSpaceGuid.PcdCci400Initialize|FALSE|BOOLEAN|0x0000002A
- gArmPlatformTokenSpaceGuid.PcdClockInitialize|FALSE|BOOLEAN|0x0000002B
- gLS1043aRdbTokenSpaceGuid.PcdFdNandLba|0x0|UINT32|0x00000031
- #gEfiShellPkgTokenSpaceGuid.PcdShellLibAutoInitialize|FALSE|BOOLEAN|0x00000039
- #
- # PPA specific PCDs
- #
- gArmPlatformTokenSpaceGuid.PcdPpaNorBaseAddr|0x0|UINT64|0x00000032
- gArmPlatformTokenSpaceGuid.PcdPpaDdrOffsetAddr|0x0|UINT64|0x00000033 # calculated from top of DDR
- gLS1043aRdbTokenSpaceGuid.PcdPpaFitConfiguration|""|VOID*|0x00000034
- ## PCI
- # This value is used to set the base address of PCI express hierarchy.
- # @Prompt PCI Express Base Address.
- #
- gArmPlatformTokenSpaceGuid.PcdPciMaxPayloadFixup|FALSE|BOOLEAN|0x00000040
- gArmPlatformTokenSpaceGuid.PcdPciBusHotPlugDeviceSupport|TRUE|BOOLEAN|0x00000041
- gArmPlatformTokenSpaceGuid.PcdKludgeMapPciMmioAsCached|FALSE|BOOLEAN|0x00000006
- gArmPlatformTokenSpaceGuid.PcdPciBusMin|0|UINT64|0x00000042
- gArmPlatformTokenSpaceGuid.PcdPciBusMax|255|UINT64|0x00000043
- gArmPlatformTokenSpaceGuid.PcdPciIoBase|0x00010000|UINT64|0x00000044
- gArmPlatformTokenSpaceGuid.PcdPciIoSize|0x00010000|UINT64|0x00000045
- gArmPlatformTokenSpaceGuid.PcdPciMmio32Base|0x40000000|UINT32|0x00000046
- gArmPlatformTokenSpaceGuid.PcdPciMmio32Size|0x40000000|UINT32|0x00000047
- gArmPlatformTokenSpaceGuid.PcdPciMemTranslation|0x5000000000|UINT64|0x00000055
- gArmPlatformTokenSpaceGuid.PcdPciMmio64Base|0x5040000000|UINT64|0x00000048
- gArmPlatformTokenSpaceGuid.PcdPciMmio64Size|0x0040000000|UINT64|0x00000049
- gArmPlatformTokenSpaceGuid.PcdPciIoTranslation|0x00010000|UINT64|0x00000050
- gEfiMdePkgTokenSpaceGuid.PcdPci1ExpressBaseAddress|0x5000000000|UINT64|0x00000051
- gEfiMdePkgTokenSpaceGuid.PcdPci2ExpressBaseAddress|0x4800000000|UINT64|0x00000052
- gEfiMdePkgTokenSpaceGuid.PcdPci3ExpressBaseAddress|0x5000000000|UINT64|0x00000058
- gEfiMdePkgTokenSpaceGuid.PcdPciExpressBaseAddress|0x03600000|UINT64|0x0000004D
- gLS1043aRdbTokenSpaceGuid.PcdBootMode|0x0|UINT32|0x00000038
- gLS1043aRdbTokenSpaceGuid.PcdPpaNandLba|0x10|UINT32|0x00000039
- gLS1043aRdbTokenSpaceGuid.PcdPpaImageSize|0x100000|UINT32|0x00000040
- gLS1043aRdbTokenSpaceGuid.PcdPpaSdxcLba|0x10|UINT32|0x00000041
- gLS1043aRdbTokenSpaceGuid.PcdFdSdxcLba|0x0|UINT32|0x00000042
diff --git a/Platforms/Nxp/LS1043aRdb/LS1043aRdbPkg.dsc b/Platforms/Nxp/LS1043aRdb/LS1043aRdbPkg.dsc new file mode 100644 index 0000000..1e3c2db --- /dev/null +++ b/Platforms/Nxp/LS1043aRdb/LS1043aRdbPkg.dsc @@ -0,0 +1,602 @@ +#/** LS1043A board package. +# +# Copyright (c) 2016, Freescale Semiconductor, Inc. All rights reserved. +# +# This program and the accompanying materials +# are licensed and made available under the terms and conditions of the BSD License +# which accompanies this distribution. The full text of the license may be found at +# http://opensource.org/licenses/bsd-license.php +# +# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, +# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. +# +#**/
+################################################################################ +# +# Defines Section - statements that will be processed to create a Makefile. +# +################################################################################ +[Defines]
- #
- # Defines for default states. These can be changed on the command line.
- # -D FLAG=VALUE
- #
- PLATFORM_NAME = LS1043aRdbPkg
- PLATFORM_GUID = 60169ec4-d2b4-44f8-825e-f8684fd42e4f
- PLATFORM_VERSION = 0.1
- DSC_SPECIFICATION = 0x00010005
- OUTPUT_DIRECTORY = Build/LS1043aRdb
- SUPPORTED_ARCHITECTURES = AARCH64
- BUILD_TARGETS = DEBUG|RELEASE
- SKUID_IDENTIFIER = DEFAULT
- FLASH_DEFINITION = OpenPlatformPkg/Platforms/Nxp/LS1043aRdb/LS1043aRdbPkg.fdf
+[LibraryClasses.common]
- ArmLib|ArmPkg/Library/ArmLib/ArmBaseLib.inf
- ArmCpuLib|ArmPkg/Drivers/ArmCpuLib/ArmCortexAEMv8Lib/ArmCortexAEMv8Lib.inf
- ArmSmcLib|ArmPkg/Library/ArmSmcLib/ArmSmcLib.inf
- ArmMmuLib|ArmPkg/Library/ArmMmuLib/ArmMmuBaseLib.inf
- ArmGenericTimerCounterLib|ArmPkg/Library/ArmGenericTimerPhyCounterLib/ArmGenericTimerPhyCounterLib.inf
- TimerLib|ArmPkg/Library/ArmArchTimerLib/ArmArchTimerLib.inf
- SocLib|OpenPlatformPkg/Platforms/Nxp/LS1043aRdb/Library/LS1043aSocLib/LS1043aSocLib.inf
- ArmTrustZoneLib|ArmPlatformPkg/Drivers/ArmTrustZone/ArmTrustZone.inf
- CpldLib|OpenPlatformPkg/Platforms/Nxp/LS1043aRdb/Library/CpldLib/CpldLib.inf
- ArmPlatformLib|OpenPlatformPkg/Platforms/Nxp/LS1043aRdb/Library/LS1043aRdbLib/LS1043aRdbLib.inf
- ArmPlatformStackLib|ArmPlatformPkg/Library/ArmPlatformStackLib/ArmPlatformStackLib.inf
- HiiLib|MdeModulePkg/Library/UefiHiiLib/UefiHiiLib.inf
- UefiHiiServicesLib|MdeModulePkg/Library/UefiHiiServicesLib/UefiHiiServicesLib.inf
- FileExplorerLib|MdeModulePkg/Library/FileExplorerLib/FileExplorerLib.inf
- #ImageDecoderLib|MdeModulePkg/Library/ImageDecoderLib/ImageDecoderLib.inf
- BootLogoLib|MdeModulePkg/Library/BootLogoLib/BootLogoLib.inf
- PlatformBootManagerLib|ArmPkg/Library/PlatformBootManagerLib/PlatformBootManagerLib.inf
- DxeServicesLib|MdePkg/Library/DxeServicesLib/DxeServicesLib.inf
- UefiBootManagerLib|MdeModulePkg/Library/UefiBootManagerLib/UefiBootManagerLib.inf
- CustomizedDisplayLib|MdeModulePkg/Library/CustomizedDisplayLib/CustomizedDisplayLib.inf
+# Networking Requirements
- NetLib|MdeModulePkg/Library/DxeNetLib/DxeNetLib.inf
- DpcLib|MdeModulePkg/Library/DxeDpcLib/DxeDpcLib.inf
- UdpIoLib|MdeModulePkg/Library/DxeUdpIoLib/DxeUdpIoLib.inf
- IpIoLib|MdeModulePkg/Library/DxeIpIoLib/DxeIpIoLib.inf
- # ARM GIC400 General Interrupt Driver
- ArmGicLib|ArmPkg/Drivers/ArmGic/ArmGicLib.inf
- ArmGicArchLib|ArmPkg/Library/ArmGicArchLib/ArmGicArchLib.inf
+!if $(TARGET) == RELEASE
- DebugLib|MdePkg/Library/BaseDebugLibSerialPort/BaseDebugLibSerialPort.inf
- UncachedMemoryAllocationLib|ArmPkg/Library/UncachedMemoryAllocationLib/UncachedMemoryAllocationLib.inf
+!else
- DebugLib|MdePkg/Library/BaseDebugLibSerialPort/BaseDebugLibSerialPort.inf
- UncachedMemoryAllocationLib|ArmPkg/Library/UncachedMemoryAllocationLib/UncachedMemoryAllocationLib.inf
+!endif
Both conditions invoke the same libraries.
- DebugPrintErrorLevelLib|MdePkg/Library/BaseDebugPrintErrorLevelLib/BaseDebugPrintErrorLevelLib.inf
- # I2c Library
- I2cLib|OpenPlatformPkg/Chips/Nxp/QoriqLs/Library/I2cLib/I2cLib.inf
- # Ddr Library
- DdrLib|OpenPlatformPkg/Platforms/Nxp/LS1043aRdb/Library/DdrLib/DdrLib.inf
- MemoryAllocationLib|MdePkg/Library/UefiMemoryAllocationLib/UefiMemoryAllocationLib.inf
- BaseLib|MdePkg/Library/BaseLib/BaseLib.inf
- SynchronizationLib|MdePkg/Library/BaseSynchronizationLib/BaseSynchronizationLib.inf
- BaseMemoryLib|ArmPkg/Library/BaseMemoryLibStm/BaseMemoryLibStm.inf
- EfiResetSystemLib|OpenPlatformPkg/Platforms/Nxp/LS1043aRdb/Library/ResetSystemLib/ResetSystemLib.inf
- PerformanceLib|MdePkg/Library/BasePerformanceLibNull/BasePerformanceLibNull.inf
- PrintLib|MdePkg/Library/BasePrintLib/BasePrintLib.inf
- EfiFileLib|EmbeddedPkg/Library/EfiFileLib/EfiFileLib.inf
- PeCoffLib|MdePkg/Library/BasePeCoffLib/BasePeCoffLib.inf
- PeCoffGetEntryPointLib|MdePkg/Library/BasePeCoffGetEntryPointLib/BasePeCoffGetEntryPointLib.inf
- PeCoffExtraActionLib|ArmPkg/Library/DebugPeCoffExtraActionLib/DebugPeCoffExtraActionLib.inf
- CacheMaintenanceLib|ArmPkg/Library/ArmCacheMaintenanceLib/ArmCacheMaintenanceLib.inf
- DefaultExceptionHandlerLib|ArmPkg/Library/DefaultExceptionHandlerLib/DefaultExceptionHandlerLib.inf
- CpuExceptionHandlerLib|ArmPkg/Library/ArmExceptionLib/ArmExceptionLib.inf
- PrePiLib|EmbeddedPkg/Library/PrePiLib/PrePiLib.inf
- RealTimeClockLib|OpenPlatformPkg/Chips/Nxp/QoriqLs/Library/Ds1307RtcLib/Ds1307RtcLib.inf
- SemihostLib|ArmPkg/Library/SemihostLib/SemihostLib.inf
- # UART Driver
- SerialPortLib|OpenPlatformPkg/Chips/Nxp/QoriqLs/Library/DUartPortLib/DUartPortLib.inf
- IoLib|MdePkg/Library/BaseIoLibIntrinsic/BaseIoLibIntrinsic.inf
- MemoryAllocationLib|MdePkg/Library/UefiMemoryAllocationLib/UefiMemoryAllocationLib.inf
- UefiLib|MdePkg/Library/UefiLib/UefiLib.inf
- HobLib|MdePkg/Library/DxeHobLib/DxeHobLib.inf
- UefiRuntimeServicesTableLib|MdePkg/Library/UefiRuntimeServicesTableLib/UefiRuntimeServicesTableLib.inf
- DevicePathLib|MdePkg/Library/UefiDevicePathLib/UefiDevicePathLib.inf
- UefiBootServicesTableLib|MdePkg/Library/UefiBootServicesTableLib/UefiBootServicesTableLib.inf
- DxeServicesTableLib|MdePkg/Library/DxeServicesTableLib/DxeServicesTableLib.inf
- UefiDriverEntryPoint|MdePkg/Library/UefiDriverEntryPoint/UefiDriverEntryPoint.inf
- UefiApplicationEntryPoint|MdePkg/Library/UefiApplicationEntryPoint/UefiApplicationEntryPoint.inf
+# +# Assume everything is fixed at build +#
- PcdLib|MdePkg/Library/BasePcdLibNull/BasePcdLibNull.inf
- UefiRuntimeLib|MdePkg/Library/UefiRuntimeLib/UefiRuntimeLib.inf
- UefiUsbLib|MdePkg/Library/UefiUsbLib/UefiUsbLib.inf
- CpuLib|MdePkg/Library/BaseCpuLib/BaseCpuLib.inf
- ArmDisassemblerLib|ArmPkg/Library/ArmDisassemblerLib/ArmDisassemblerLib.inf
- DebugAgentLib|MdeModulePkg/Library/DebugAgentLibNull/DebugAgentLibNull.inf
- DmaLib|ArmPkg/Library/ArmDmaLib/ArmDmaLib.inf
- BdsLib|ArmPkg/Library/BdsLib/BdsLib.inf
- FdtLib|EmbeddedPkg/Library/FdtLib/FdtLib.inf
- ShellLib|ShellPkg/Library/UefiShellLib/UefiShellLib.inf
- ShellCommandLib|ShellPkg/Library/UefiShellCommandLib/UefiShellCommandLib.inf
- FileHandleLib|MdePkg/Library/UefiFileHandleLib/UefiFileHandleLib.inf
- ShellCEntryLib|ShellPkg/Library/UefiShellCEntryLib/UefiShellCEntryLib.inf
- SortLib|MdeModulePkg/Library/UefiSortLib/UefiSortLib.inf
- NetLib|MdeModulePkg/Library/DxeNetLib/DxeNetLib.inf
- HandleParsingLib|ShellPkg/Library/UefiHandleParsingLib/UefiHandleParsingLib.inf
- BcfgCommandLib|ShellPkg/Library/UefiShellBcfgCommandLib/UefiShellBcfgCommandLib.inf
- TpmMeasurementLib|MdeModulePkg/Library/TpmMeasurementLibNull/TpmMeasurementLibNull.inf
- AuthVariableLib|MdeModulePkg/Library/AuthVariableLibNull/AuthVariableLibNull.inf
- VarCheckLib|MdeModulePkg/Library/VarCheckLib/VarCheckLib.inf
+[LibraryClasses.common.SEC]
- PcdLib|MdePkg/Library/BasePcdLibNull/BasePcdLibNull.inf
- ReportStatusCodeLib|IntelFrameworkModulePkg/Library/PeiDxeDebugLibReportStatusCode/PeiDxeDebugLibReportStatusCode.inf
- UefiDecompressLib|MdePkg/Library/BaseUefiDecompressLib/BaseUefiDecompressLib.inf
- ExtractGuidedSectionLib|EmbeddedPkg/Library/PrePiExtractGuidedSectionLib/PrePiExtractGuidedSectionLib.inf
- LzmaDecompressLib|IntelFrameworkModulePkg/Library/LzmaCustomDecompressLib/LzmaCustomDecompressLib.inf
- PeCoffLib|MdePkg/Library/BasePeCoffLib/BasePeCoffLib.inf
- HobLib|EmbeddedPkg/Library/PrePiHobLib/PrePiHobLib.inf
- PrePiHobListPointerLib|ArmPlatformPkg/Library/PrePiHobListPointerLib/PrePiHobListPointerLib.inf
- MemoryAllocationLib|EmbeddedPkg/Library/PrePiMemoryAllocationLib/PrePiMemoryAllocationLib.inf
- PerformanceLib|MdeModulePkg/Library/PeiPerformanceLib/PeiPerformanceLib.inf
- PlatformPeiLib|ArmPlatformPkg/PlatformPei/PlatformPeiLib.inf
- MemoryInitPeiLib|ArmPlatformPkg/MemoryInitPei/MemoryInitPeiLib.inf
- # 1/123 faster than Stm or Vstm version
- BaseMemoryLib|MdePkg/Library/BaseMemoryLib/BaseMemoryLib.inf
- # Uncomment to turn on GDB stub in SEC.
- #DebugAgentLib|EmbeddedPkg/Library/GdbDebugAgent/GdbDebugAgent.inf
+[LibraryClasses.common.PEI_CORE]
- PcdLib|MdePkg/Library/BasePcdLibNull/BasePcdLibNull.inf
- ReportStatusCodeLib|IntelFrameworkModulePkg/Library/PeiDxeDebugLibReportStatusCode/PeiDxeDebugLibReportStatusCode.inf
+[LibraryClasses.common.DXE_CORE]
- HobLib|MdePkg/Library/DxeCoreHobLib/DxeCoreHobLib.inf
- MemoryAllocationLib|MdeModulePkg/Library/DxeCoreMemoryAllocationLib/DxeCoreMemoryAllocationLib.inf
- DxeCoreEntryPoint|MdePkg/Library/DxeCoreEntryPoint/DxeCoreEntryPoint.inf
- ReportStatusCodeLib|IntelFrameworkModulePkg/Library/DxeReportStatusCodeLibFramework/DxeReportStatusCodeLib.inf
- ExtractGuidedSectionLib|MdePkg/Library/DxeExtractGuidedSectionLib/DxeExtractGuidedSectionLib.inf
- UefiDecompressLib|MdePkg/Library/BaseUefiDecompressLib/BaseUefiDecompressLib.inf
- DxeServicesLib|MdePkg/Library/DxeServicesLib/DxeServicesLib.inf
- PeCoffLib|EmbeddedPkg/Library/DxeHobPeCoffLib/DxeHobPeCoffLib.inf
- PerformanceLib|MdeModulePkg/Library/DxeCorePerformanceLib/DxeCorePerformanceLib.inf
+[LibraryClasses.common.DXE_DRIVER]
- ReportStatusCodeLib|IntelFrameworkModulePkg/Library/DxeReportStatusCodeLibFramework/DxeReportStatusCodeLib.inf
- DxeServicesLib|MdePkg/Library/DxeServicesLib/DxeServicesLib.inf
- SecurityManagementLib|MdeModulePkg/Library/DxeSecurityManagementLib/DxeSecurityManagementLib.inf
- PerformanceLib|MdeModulePkg/Library/DxePerformanceLib/DxePerformanceLib.inf
- MemoryInitPeiLib|ArmPlatformPkg/MemoryInitPei/MemoryInitPeiLib.inf
+[LibraryClasses.common.UEFI_APPLICATION]
- PcdLib|MdePkg/Library/DxePcdLib/DxePcdLib.inf
- HobLib|MdePkg/Library/DxeHobLib/DxeHobLib.inf
- ReportStatusCodeLib|IntelFrameworkModulePkg/Library/DxeReportStatusCodeLibFramework/DxeReportStatusCodeLib.inf
- UefiDecompressLib|IntelFrameworkModulePkg/Library/BaseUefiTianoCustomDecompressLib/BaseUefiTianoCustomDecompressLib.inf
- PerformanceLib|MdeModulePkg/Library/DxePerformanceLib/DxePerformanceLib.inf
+[LibraryClasses.common.UEFI_DRIVER]
- ReportStatusCodeLib|IntelFrameworkModulePkg/Library/DxeReportStatusCodeLibFramework/DxeReportStatusCodeLib.inf
- UefiDecompressLib|IntelFrameworkModulePkg/Library/BaseUefiTianoCustomDecompressLib/BaseUefiTianoCustomDecompressLib.inf
- ExtractGuidedSectionLib|MdePkg/Library/DxeExtractGuidedSectionLib/DxeExtractGuidedSectionLib.inf
- PerformanceLib|MdeModulePkg/Library/DxePerformanceLib/DxePerformanceLib.inf
- DxeServicesLib|MdePkg/Library/DxeServicesLib/DxeServicesLib.inf
+[LibraryClasses.common.DXE_RUNTIME_DRIVER]
- HobLib|MdePkg/Library/DxeHobLib/DxeHobLib.inf
- MemoryAllocationLib|MdePkg/Library/UefiMemoryAllocationLib/UefiMemoryAllocationLib.inf
- ReportStatusCodeLib|IntelFrameworkModulePkg/Library/DxeReportStatusCodeLibFramework/DxeReportStatusCodeLib.inf
- CapsuleLib|MdeModulePkg/Library/DxeCapsuleLibNull/DxeCapsuleLibNull.inf
- PeCoffLib|EmbeddedPkg/Library/DxeHobPeCoffLib/DxeHobPeCoffLib.inf
+[LibraryClasses.AARCH64]
- #
- # It is not possible to prevent the ARM compiler for generic intrinsic functions.
- # This library provides the instrinsic functions generate by a given compiler.
- # [LibraryClasses.ARM] and NULL mean link this library into all ARM images.
- #
- NULL|ArmPkg/Library/CompilerIntrinsicsLib/CompilerIntrinsicsLib.inf
+################################################################################ +# +# Pcd Section - list of all EDK II PCD Entries defined by this Platform +# +################################################################################
+[PcdsFeatureFlag.common]
- ## If TRUE, Graphics Output Protocol will be installed on virtual handle created by ConsplitterDxe.
- # It could be set FALSE to save size.
- gEfiMdeModulePkgTokenSpaceGuid.PcdConOutGopSupport|TRUE
- gEfiMdeModulePkgTokenSpaceGuid.PcdConOutUgaSupport|FALSE
- gEfiMdePkgTokenSpaceGuid.PcdComponentNameDisable|TRUE
- gEfiMdePkgTokenSpaceGuid.PcdDriverDiagnosticsDisable|TRUE
- gEfiMdePkgTokenSpaceGuid.PcdComponentName2Disable|TRUE
- gEfiMdePkgTokenSpaceGuid.PcdDriverDiagnostics2Disable|TRUE
- #
- # Control what commands are supported from the UI
- # Turn these on and off to add features or save size
- #
- gEmbeddedTokenSpaceGuid.PcdEmbeddedMacBoot|TRUE
- gEmbeddedTokenSpaceGuid.PcdEmbeddedDirCmd|TRUE
- gEmbeddedTokenSpaceGuid.PcdEmbeddedHobCmd|TRUE
- gEmbeddedTokenSpaceGuid.PcdEmbeddedHwDebugCmd|TRUE
- gEmbeddedTokenSpaceGuid.PcdEmbeddedPciDebugCmd|TRUE
- gEmbeddedTokenSpaceGuid.PcdEmbeddedIoEnable|FALSE
- gEmbeddedTokenSpaceGuid.PcdEmbeddedScriptCmd|FALSE
- gEmbeddedTokenSpaceGuid.PcdCacheEnable|TRUE
- # Use the Vector Table location in CpuDxe. We will not copy the Vector Table at PcdCpuVectorBaseAddress
- gArmTokenSpaceGuid.PcdRelocateVectorTable|FALSE
- gEmbeddedTokenSpaceGuid.PcdPrePiProduceMemoryTypeInformationHob|TRUE
- gArmTokenSpaceGuid.PcdCpuDxeProduceDebugSupport|FALSE
- gEfiMdeModulePkgTokenSpaceGuid.PcdTurnOffUsbLegacySupport|TRUE
+[PcdsDynamicDefault.common]
- #
- # Set video resolution for boot options and for text setup.
- # PlatformDxe can set the former at runtime.
- #
- gEfiMdeModulePkgTokenSpaceGuid.PcdVideoHorizontalResolution|800
- gEfiMdeModulePkgTokenSpaceGuid.PcdVideoVerticalResolution|600
- gEfiMdeModulePkgTokenSpaceGuid.PcdSetupVideoHorizontalResolution|640
- gEfiMdeModulePkgTokenSpaceGuid.PcdSetupVideoVerticalResolution|480
+[PcdsFixedAtBuild.common]
- gEfiMdeModulePkgTokenSpaceGuid.PcdMaxVariableSize|0x2000
- gEfiMdeModulePkgTokenSpaceGuid.PcdMaxAuthVariableSize|0x2800
- gEfiMdeModulePkgTokenSpaceGuid.PcdResetOnMemoryTypeInformationChange|FALSE
- gEfiMdeModulePkgTokenSpaceGuid.PcdBootManagerMenuFile|{ 0x21, 0xaa, 0x2c, 0x46, 0x14, 0x76, 0x03, 0x45, 0x83, 0x6e, 0x8a, 0xb6, 0xf4, 0x66, 0x23, 0x31 }
- gEfiIntelFrameworkModulePkgTokenSpaceGuid.PcdShellFile|{ 0x83, 0xA5, 0x04, 0x7C, 0x3E, 0x9E, 0x1C, 0x4F, 0xAD, 0x65, 0xE0, 0x52, 0x68, 0xD0, 0xB4, 0xD1 }
- gEfiMdePkgTokenSpaceGuid.PcdPlatformBootTimeOut|20
- gArmPlatformTokenSpaceGuid.PcdFirmwareVendor|"LS1043a RDB board"
- gEmbeddedTokenSpaceGuid.PcdEmbeddedPrompt|"LS1043a"
- gArmPlatformTokenSpaceGuid.PcdCoreCount|1 # Only one core
- gArmPlatformTokenSpaceGuid.PcdCounterFrequency|12000000 #12Mhz
- gEfiMdePkgTokenSpaceGuid.PcdMaximumUnicodeStringLength|1000000
- gEfiMdePkgTokenSpaceGuid.PcdMaximumAsciiStringLength|2000000
- gEfiMdePkgTokenSpaceGuid.PcdMaximumLinkedListLength|1000000
- gEfiMdePkgTokenSpaceGuid.PcdSpinLockTimeout|10000000
- gEfiMdePkgTokenSpaceGuid.PcdDebugClearMemoryValue|0xAF
- gEfiMdePkgTokenSpaceGuid.PcdPerformanceLibraryPropertyMask|1
- #gEfiMdePkgTokenSpaceGuid.PcdPerformanceLibraryPropertyMask|0 # turn off for now
- gEfiMdePkgTokenSpaceGuid.PcdPostCodePropertyMask|0
- gEfiMdePkgTokenSpaceGuid.PcdUefiLibMaxPrintBufferSize|320
+# DEBUG_ASSERT_ENABLED 0x01 +# DEBUG_PRINT_ENABLED 0x02 +# DEBUG_CODE_ENABLED 0x04 +# CLEAR_MEMORY_ENABLED 0x08 +# ASSERT_BREAKPOINT_ENABLED 0x10 +# ASSERT_DEADLOOP_ENABLED 0x20 +!if $(TARGET) == RELEASE
- gEfiMdePkgTokenSpaceGuid.PcdDebugPropertyMask|0x27
- gEfiMdePkgTokenSpaceGuid.PcdDebugPrintErrorLevel|0x81000000 #0x8000000F #Print almost everything
+!else
- gEfiMdePkgTokenSpaceGuid.PcdDebugPropertyMask|0x2F
- gEfiMdePkgTokenSpaceGuid.PcdDebugPrintErrorLevel|0x81000044 #0x8000000F #Print almost everything
+!endif
+# DEBUG_INIT 0x00000001 // Initialization +# DEBUG_WARN 0x00000002 // Warnings +# DEBUG_LOAD 0x00000004 // Load events +# DEBUG_FS 0x00000008 // EFI File system +# DEBUG_POOL 0x00000010 // Alloc & Free's +# DEBUG_PAGE 0x00000020 // Alloc & Free's +# DEBUG_INFO 0x00000040 // Verbose +# DEBUG_DISPATCH 0x00000080 // PEI/DXE Dispatchers +# DEBUG_VARIABLE 0x00000100 // Variable +# DEBUG_BM 0x00000400 // Boot Manager +# DEBUG_BLKIO 0x00001000 // BlkIo Driver +# DEBUG_NET 0x00004000 // SNI Driver +# DEBUG_UNDI 0x00010000 // UNDI Driver +# DEBUG_LOADFILE 0x00020000 // UNDI Driver +# DEBUG_EVENT 0x00080000 // Event messages +# DEBUG_ERROR 0x80000000 // Error
- gEfiMdePkgTokenSpaceGuid.PcdReportStatusCodePropertyMask|0x07
- gEmbeddedTokenSpaceGuid.PcdEmbeddedAutomaticBootCommand|""
- gEmbeddedTokenSpaceGuid.PcdEmbeddedDefaultTextColor|0x07
- gEmbeddedTokenSpaceGuid.PcdEmbeddedMemVariableStoreSize|0x10000
+# +# Optional feature to help prevent EFI memory map fragments +# Turned on and off via: PcdPrePiProduceMemoryTypeInformationHob +# Values are in EFI Pages (4K). DXE Core will make sure that +# at least this much of each type of memory can be allocated +# from a single memory range. This way you only end up with +# maximum of two fragements for each type in the memory map +# (the memory used, and the free memory that was prereserved +# but not used). +#
- gEmbeddedTokenSpaceGuid.PcdMemoryTypeEfiACPIReclaimMemory|0
- gEmbeddedTokenSpaceGuid.PcdMemoryTypeEfiACPIMemoryNVS|0
- gEmbeddedTokenSpaceGuid.PcdMemoryTypeEfiReservedMemoryType|0
- gEmbeddedTokenSpaceGuid.PcdMemoryTypeEfiRuntimeServicesData|80
- gEmbeddedTokenSpaceGuid.PcdMemoryTypeEfiRuntimeServicesCode|40
- gEmbeddedTokenSpaceGuid.PcdMemoryTypeEfiBootServicesCode|400
- gEmbeddedTokenSpaceGuid.PcdMemoryTypeEfiBootServicesData|3000
- gEmbeddedTokenSpaceGuid.PcdMemoryTypeEfiLoaderCode|10
- gEmbeddedTokenSpaceGuid.PcdMemoryTypeEfiLoaderData|0
- # PCI PCDs
- #
- gArmPlatformTokenSpaceGuid.PcdKludgeMapPciMmioAsCached|FALSE
- gArmPlatformTokenSpaceGuid.PcdPciBusMin|0
- gArmPlatformTokenSpaceGuid.PcdPciBusMax|255
- gArmPlatformTokenSpaceGuid.PcdPciIoBase|0x00010000
- gArmPlatformTokenSpaceGuid.PcdPciIoSize|0x00010000 # 64k
- gArmPlatformTokenSpaceGuid.PcdPciIoTranslation|0x00010000
- gArmPlatformTokenSpaceGuid.PcdPciMmio32Base|0x40000000
- gArmPlatformTokenSpaceGuid.PcdPciMmio32Size|0x40000000 # 128M
- gArmPlatformTokenSpaceGuid.PcdPciMemTranslation|0x5000000000
- gArmPlatformTokenSpaceGuid.PcdPciMmio64Base|0x5040000000
- gArmPlatformTokenSpaceGuid.PcdPciMmio64Size|0x40000000
- gEfiMdePkgTokenSpaceGuid.PcdPci1ExpressBaseAddress|0x5000000000
- gEfiMdePkgTokenSpaceGuid.PcdPci2ExpressBaseAddress|0x4800000000
- gEfiMdePkgTokenSpaceGuid.PcdPci3ExpressBaseAddress|0x5000000000
- ## Serial Terminal
- gEfiMdeModulePkgTokenSpaceGuid.PcdSerialRegisterBase|0x21c0500
- gEfiMdePkgTokenSpaceGuid.PcdUartDefaultBaudRate|115200
- gEfiMdePkgTokenSpaceGuid.PcdDefaultTerminalType|4
- #
- # ARM General Interrupt Controller
- gArmTokenSpaceGuid.PcdGicDistributorBase|0x1401000
- gArmTokenSpaceGuid.PcdGicInterruptInterfaceBase|0x1402000
- #
- # LS1043a board Specific PCDs
- # XX (DRAM - Region 1 2GB)
- # (NOR - IFC Region 1 512MB)
- gArmTokenSpaceGuid.PcdSystemMemoryBase|0x80000000
- gArmTokenSpaceGuid.PcdSystemMemorySize|0x80000000
- #
- # LS1043a Soc Specific PCDs
- #
- gArmPlatformTokenSpaceGuid.PcdCounterFrequencyReal|TRUE
- gArmPlatformTokenSpaceGuid.PcdCsuInitialize|TRUE
- gArmPlatformTokenSpaceGuid.PcdTzc380Initialize|TRUE
- gArmPlatformTokenSpaceGuid.PcdCci400Initialize|TRUE
- gArmPlatformTokenSpaceGuid.PcdClockInitialize|TRUE
- #
- # PPA specific PCDs
- #
- gNxpQoriqLsTokenSpaceGuid.PcdPpaNorBaseAddr|0x60500000
- gNxpQoriqLsTokenSpaceGuid.PcdPpaDdrOffsetAddr|0x8000000 # (128MB) calculated from top of DDR
- # Size of the region used by UEFI in permanent memory (Reserved 16MB)
- gArmPlatformTokenSpaceGuid.PcdSystemMemoryUefiRegionSize|0x01000000
- # Size of the region reserved for fixed address allocations (Reserved 32MB)
- gArmTokenSpaceGuid.PcdArmLinuxKernelMaxOffset|0x08000000
- gArmTokenSpaceGuid.PcdArmLinuxFdtMaxOffset|0x08000000
- gArmTokenSpaceGuid.PcdArmLinuxFdtAlignment|0x0
- gArmTokenSpaceGuid.PcdCpuVectorBaseAddress|0x94A00000
- gArmTokenSpaceGuid.PcdCpuResetAddress|0x94A00000
- # Timer
- gArmTokenSpaceGuid.PcdArmArchTimerFreqInHz|0
- gEmbeddedTokenSpaceGuid.PcdTimerPeriod|10000 # expressed in 100ns units, 100,000 x 100 ns = 10,000,000 ns = 10 ms
- gArmPlatformTokenSpaceGuid.PcdArmArchTimerVirtIntrNum|11 # Virtual PPI
- gArmPlatformTokenSpaceGuid.PcdArmArchTimerHypIntrNum|10 # Hypervisor PPI
- gArmPlatformTokenSpaceGuid.PcdArmArchTimerSecIntrNum|13 # Physical Secure PPI
- gArmPlatformTokenSpaceGuid.PcdArmArchTimerIntrNum|14 # Physical Non-Secure PPI
- gEmbeddedTokenSpaceGuid.PcdMetronomeTickPeriod|1000
- #gEmbeddedTokenSpaceGuid.PcdEmbeddedPerformanceCounterPeriodInNanoseconds|77
- #gEmbeddedTokenSpaceGuid.PcdEmbeddedPerformanceCounterFrequencyInHz|13000000
- # We want to use the Shell Libraries but don't want it to initialise
- # automatically. We initialise the libraries when the command is called by the
- # Shell.
- gEfiShellPkgTokenSpaceGuid.PcdShellLibAutoInitialize|FALSE
- #
- # ARM Pcds
- #
- gArmTokenSpaceGuid.PcdArmUncachedMemoryMask|0x0000000040000000
- gArmPlatformTokenSpaceGuid.PcdDefaultBootDescription|L"EFI Linux from NOR flash"
- gArmPlatformTokenSpaceGuid.PcdDefaultBootDevicePath|L"MemoryMapped(0x0,0x61100000,0x6111FFFF)"
- gEmbeddedTokenSpaceGuid.PcdFdtDevicePaths|L"MemoryMapped(0x0,0x61B00000,0x61BFFFFF)/fsl-ls1043a-uefi-rdb.dtb"
- gArmPlatformTokenSpaceGuid.PcdDefaultBootArgument|L"MemoryMapped(0x0,0x61120000,0x61AFFFFF) -d "MemoryMapped(0x0,0x61B00000,0x61BFFFFF)" -f "MemoryMapped(0x0,0x61C00000,0x638FFFFF)" -c "console=ttyS0,115200 root=/dev/ram0 earlycon=uart8250,0x21c0500,115200""
- # PPA
- gLS1043aRdbTokenSpaceGuid.PcdPpaFitConfiguration|"config@1"
- # Use the serial console for both ConIn & ConOut
- gArmPlatformTokenSpaceGuid.PcdDefaultConOutPaths|L"VenHw(D3987D4B-971A-435F-8CAF-4967EB627241)/Uart(115200,8,N,1)/VenPcAnsi();"
- gArmPlatformTokenSpaceGuid.PcdDefaultConInPaths|L"VenHw(D3987D4B-971A-435F-8CAF-4967EB627241)/Uart(115200,8,N,1)/VenPcAnsi()"
- gEfiShellPkgTokenSpaceGuid.PcdShellLibAutoInitialize|FALSE
- gEfiMdePkgTokenSpaceGuid.PcdUefiLibMaxPrintBufferSize|16000
+!ifdef $(NO_SHELL_PROFILES)
- gEfiShellPkgTokenSpaceGuid.PcdShellProfileMask|0x00
+!endif #$(NO_SHELL_PROFILES)
- gNxpQoriqLsTokenSpaceGuid.PcdFdNorBaseAddress|0x60400000
- gNxpQoriqLsTokenSpaceGuid.PcdOcramStackBase|0x10010000
- gNxpQoriqLsTokenSpaceGuid.PcdI2cBus|0
- gNxpQoriqLsTokenSpaceGuid.PcdI2cSpeed|10000
- gNxpQoriqLsTokenSpaceGuid.PcdRtcI2cBus|0
- gNxpQoriqLsTokenSpaceGuid.PcdDs1307I2cAddress|0x68
+################################################################################ +# +# Components Section - list of all EDK II Modules needed by this Platform +# +################################################################################ +[Components.common]
- #
- # SEC
- #
- OpenPlatformPkg/Chips/Nxp/QoriqLs/Library/PrePiNor/PrePiNor.inf
- ArmPlatformPkg/PrePi/PeiUniCore.inf
- #
- # DXE
- #
- MdeModulePkg/Core/Dxe/DxeMain.inf {
<LibraryClasses>
PcdLib|MdePkg/Library/BasePcdLibNull/BasePcdLibNull.inf
NULL|MdeModulePkg/Library/DxeCrc32GuidedSectionExtractLib/DxeCrc32GuidedSectionExtractLib.inf
NULL|EmbeddedPkg/Library/LzmaHobCustomDecompressLib/LzmaHobCustomDecompressLib.inf
- }
- MdeModulePkg/Universal/PCD/Dxe/Pcd.inf {
<LibraryClasses>
PcdLib|MdePkg/Library/BasePcdLibNull/BasePcdLibNull.inf
- }
- #
- # Architectural Protocols
- #
- ArmPkg/Drivers/CpuDxe/CpuDxe.inf
- MdeModulePkg/Core/RuntimeDxe/RuntimeDxe.inf
- MdeModulePkg/Universal/SecurityStubDxe/SecurityStubDxe.inf
- MdeModulePkg/Universal/CapsuleRuntimeDxe/CapsuleRuntimeDxe.inf
- MdeModulePkg/Universal/Variable/EmuRuntimeDxe/EmuVariableRuntimeDxe.inf
- EmbeddedPkg/EmbeddedMonotonicCounter/EmbeddedMonotonicCounter.inf
- # FDT installation
- EmbeddedPkg/Drivers/FdtPlatformDxe/FdtPlatformDxe.inf
- MdeModulePkg/Universal/Console/ConPlatformDxe/ConPlatformDxe.inf
- MdeModulePkg/Universal/Console/ConSplitterDxe/ConSplitterDxe.inf
- MdeModulePkg/Universal/Console/GraphicsConsoleDxe/GraphicsConsoleDxe.inf
- MdeModulePkg/Universal/Console/TerminalDxe/TerminalDxe.inf
- MdeModulePkg/Universal/SerialDxe/SerialDxe.inf
- MdeModulePkg/Universal/Acpi/AcpiTableDxe/AcpiTableDxe.inf
- EmbeddedPkg/ResetRuntimeDxe/ResetRuntimeDxe.inf
- EmbeddedPkg/RealTimeClockRuntimeDxe/RealTimeClockRuntimeDxe.inf
- EmbeddedPkg/MetronomeDxe/MetronomeDxe.inf
- ArmPkg/Drivers/TimerDxe/TimerDxe.inf
- OpenPlatformPkg/Platforms/Nxp/LS1043aRdb/LS1043aWatchDog/LS1043aWatchDogDxe.inf
- ArmPkg/Drivers/ArmGic/ArmGicDxe.inf
- EmbeddedPkg/SimpleTextInOutSerial/SimpleTextInOutSerial.inf
- #
- # PPA
- #
- OpenPlatformPkg/Chips/Nxp/QoriqLs/PpaInitDxe/PpaInitDxe.inf
- #
- # FAT filesystem + GPT/MBR partitioning
- #
- MdeModulePkg/Universal/Disk/UnicodeCollation/EnglishDxe/EnglishDxe.inf
- #
- # I2C
- #
- OpenPlatformPkg/Chips/Nxp/QoriqLs/I2c/I2cDxe.inf
- #
- # Bds
- #
- MdeModulePkg/Universal/DevicePathDxe/DevicePathDxe.inf
- MdeModulePkg/Universal/DisplayEngineDxe/DisplayEngineDxe.inf
- MdeModulePkg/Universal/SetupBrowserDxe/SetupBrowserDxe.inf
- MdeModulePkg/Universal/BdsDxe/BdsDxe.inf
- MdeModulePkg/Application/UiApp/UiApp.inf {
<LibraryClasses>
NULL|MdeModulePkg/Library/DeviceManagerUiLib/DeviceManagerUiLib.inf
NULL|MdeModulePkg/Library/BootManagerUiLib/BootManagerUiLib.inf
NULL|MdeModulePkg/Library/BootMaintenanceManagerUiLib/BootMaintenanceManagerUiLib.inf
- }
- MdeModulePkg/Universal/HiiDatabaseDxe/HiiDatabaseDxe.inf
- #
- # Example Application
- #
- MdeModulePkg/Application/HelloWorld/HelloWorld.inf
- ShellPkg/Library/UefiShellLib/UefiShellLib.inf
- ShellPkg/Library/UefiShellCommandLib/UefiShellCommandLib.inf
- ShellPkg/Library/UefiShellLevel2CommandsLib/UefiShellLevel2CommandsLib.inf
- ShellPkg/Library/UefiHandleParsingLib/UefiHandleParsingLib.inf
- ShellPkg/Library/UefiDpLib/UefiDpLib.inf {
<LibraryClasses>
TimerLib|MdePkg/Library/BaseTimerLibNullTemplate/BaseTimerLibNullTemplate.inf
PerformanceLib|MdePkg/Library/BasePerformanceLibNull/BasePerformanceLibNull.inf
DxeServicesLib|MdePkg/Library/DxeServicesLib/DxeServicesLib.inf
- }
+ShellPkg/Application/Shell/Shell.inf {
<LibraryClasses>
NULL|ShellPkg/Library/UefiShellLevel2CommandsLib/UefiShellLevel2CommandsLib.inf
NULL|ShellPkg/Library/UefiShellLevel1CommandsLib/UefiShellLevel1CommandsLib.inf
NULL|ShellPkg/Library/UefiShellLevel3CommandsLib/UefiShellLevel3CommandsLib.inf
+!ifndef $(NO_SHELL_PROFILES)
NULL|ShellPkg/Library/UefiShellDriver1CommandsLib/UefiShellDriver1CommandsLib.inf
NULL|ShellPkg/Library/UefiShellInstall1CommandsLib/UefiShellInstall1CommandsLib.inf
NULL|ShellPkg/Library/UefiShellDebug1CommandsLib/UefiShellDebug1CommandsLib.inf
NULL|ShellPkg/Library/UefiShellNetwork1CommandsLib/UefiShellNetwork1CommandsLib.inf
NULL|ShellPkg/Library/UefiShellTftpCommandLib/UefiShellTftpCommandLib.inf
+!ifdef $(INCLUDE_DP)
NULL|ShellPkg/Library/UefiDpLib/UefiDpLib.inf
+!endif #$(INCLUDE_DP) +!ifdef $(INCLUDE_TFTP_COMMAND)
NULL|ShellPkg/Library/UefiShellTftpCommandLib/UefiShellTftpCommandLib.inf
+!endif #$(INCLUDE_TFTP_COMMAND) +!endif #$(NO_SHELL_PROFILES)
}
- ##
diff --git a/Platforms/Nxp/LS1043aRdb/LS1043aRdbPkg.fdf b/Platforms/Nxp/LS1043aRdb/LS1043aRdbPkg.fdf new file mode 100644 index 0000000..1633630 --- /dev/null +++ b/Platforms/Nxp/LS1043aRdb/LS1043aRdbPkg.fdf @@ -0,0 +1,311 @@ +# FLASH layout file for LS1043a board. +# +# Copyright (c) 2016, Freescale Ltd. All rights reserved. +# +# This program and the accompanying materials +# are licensed and made available under the terms and conditions of the BSD License +# which accompanies this distribution. The full text of the license may be found at +# http://opensource.org/licenses/bsd-license.php +# +# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, +# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. +#
+################################################################################ +# +# FD Section +# The [FD] Section is made up of the definition statements and a +# description of what goes into the Flash Device Image. Each FD section +# defines one flash "device" image. A flash device image may be one of +# the following: Removable media bootable image (like a boot floppy +# image,) an Option ROM image (that would be "flashed" into an add-in +# card,) a System "Flash" image (that would be burned into a system's +# flash) or an Update ("Capsule") image that will be used to update and +# existing system flash. +# +################################################################################
+[FD.LS1043aRdb_EFI] +BaseAddress = 0xE0000000|gArmTokenSpaceGuid.PcdFdBaseAddress #The base address of the FLASH Device. +Size = 0x000C8000|gArmTokenSpaceGuid.PcdFdSize #The size in bytes of the FLASH Device +ErasePolarity = 1 +BlockSize = 0x1 +NumBlocks = 0xC8000
+################################################################################ +# +# Following are lists of FD Region layout which correspond to the locations of different +# images within the flash device. +# +# Regions must be defined in ascending order and may not overlap. +# +# A Layout Region start with a eight digit hex offset (leading "0x" required) followed by +# the pipe "|" character, followed by the size of the region, also in hex with the leading +# "0x" characters. Like: +# Offset|Size +# PcdOffsetCName|PcdSizeCName +# RegionType <FV, DATA, or FILE> +# +################################################################################ +0x00000000|0x000C8000 +gArmTokenSpaceGuid.PcdFvBaseAddress|gArmTokenSpaceGuid.PcdFvSize +FV = FVMAIN_COMPACT
+[FD.LS1043aRdbPi_EFI] +BaseAddress = 0x60400000|gNxpQoriqLsTokenSpaceGuid.PcdPiFdBaseAddress #The base address of the FLASH Device. +Size = 0x00008000|gNxpQoriqLsTokenSpaceGuid.PcdPiFdSize #The size in bytes of the FLASH Device +ErasePolarity = 1 +BlockSize = 0x1 +NumBlocks = 0x8000
+0x00000000|0x00008000 +gNxpQoriqLsTokenSpaceGuid.PcdFvNorBaseAddress|gNxpQoriqLsTokenSpaceGuid.PcdFvNorSize +FV = FVNOR_COMPACT
+################################################################################ +# +# FV Section +# +# [FV] section is used to define what components or modules are placed within a flash +# device file. This section also defines order the components and modules are positioned +# within the image. The [FV] section consists of define statements, set statements and +# module statements. +# +################################################################################
+[FV.FvMain] +BlockSize = 0x1 +NumBlocks = 0 # This FV gets compressed so make it just big enough +FvAlignment = 8 # FV alignment and FV attributes setting. +ERASE_POLARITY = 1 +MEMORY_MAPPED = TRUE +STICKY_WRITE = TRUE +LOCK_CAP = TRUE +LOCK_STATUS = TRUE +WRITE_DISABLED_CAP = TRUE +WRITE_ENABLED_CAP = TRUE +WRITE_STATUS = TRUE +WRITE_LOCK_CAP = TRUE +WRITE_LOCK_STATUS = TRUE +READ_DISABLED_CAP = TRUE +READ_ENABLED_CAP = TRUE +READ_STATUS = TRUE +READ_LOCK_CAP = TRUE +READ_LOCK_STATUS = TRUE
- INF MdeModulePkg/Core/Dxe/DxeMain.inf
- INF MdeModulePkg/Universal/PCD/Dxe/Pcd.inf
- INF OpenPlatformPkg/Chips/Nxp/QoriqLs/PpaInitDxe/PpaInitDxe.inf
- #
- # PI DXE Drivers producing Architectural Protocols (EFI Services)
- #
- INF ArmPkg/Drivers/CpuDxe/CpuDxe.inf
- INF MdeModulePkg/Core/RuntimeDxe/RuntimeDxe.inf
- INF ArmPkg/Drivers/ArmGic/ArmGicDxe.inf
- INF ArmPkg/Drivers/TimerDxe/TimerDxe.inf
- INF OpenPlatformPkg/Platforms/Nxp/LS1043aRdb/LS1043aWatchDog/LS1043aWatchDogDxe.inf
- INF MdeModulePkg/Universal/SecurityStubDxe/SecurityStubDxe.inf
- INF MdeModulePkg/Universal/CapsuleRuntimeDxe/CapsuleRuntimeDxe.inf
- INF MdeModulePkg/Universal/HiiDatabaseDxe/HiiDatabaseDxe.inf
- INF EmbeddedPkg/EmbeddedMonotonicCounter/EmbeddedMonotonicCounter.inf
- INF MdeModulePkg/Universal/Variable/EmuRuntimeDxe/EmuVariableRuntimeDxe.inf
- #
- # Multiple Console IO support
- #
- INF MdeModulePkg/Universal/Console/ConPlatformDxe/ConPlatformDxe.inf
- INF MdeModulePkg/Universal/Console/ConSplitterDxe/ConSplitterDxe.inf
- INF MdeModulePkg/Universal/Console/GraphicsConsoleDxe/GraphicsConsoleDxe.inf
- INF MdeModulePkg/Universal/SerialDxe/SerialDxe.inf
- INF MdeModulePkg/Universal/Console/TerminalDxe/TerminalDxe.inf
- INF EmbeddedPkg/ResetRuntimeDxe/ResetRuntimeDxe.inf
- INF EmbeddedPkg/RealTimeClockRuntimeDxe/RealTimeClockRuntimeDxe.inf
- INF EmbeddedPkg/MetronomeDxe/MetronomeDxe.inf
- INF EmbeddedPkg/SimpleTextInOutSerial/SimpleTextInOutSerial.inf
- #
- # I2C
- #
- INF OpenPlatformPkg/Chips/Nxp/QoriqLs/I2c/I2cDxe.inf
- #
- # FAT filesystem + GPT/MBR partitioning
- #
- INF MdeModulePkg/Universal/Disk/UnicodeCollation/EnglishDxe/EnglishDxe.inf
- #
- # UEFI application (Shell Embedded Boot Loader)
- #
- INF ShellPkg/Application/Shell/Shell.inf
- #INF ShellBinPkg/UefiShell/UefiShell.inf
- #
- # Bds
- #
- INF MdeModulePkg/Universal/DevicePathDxe/DevicePathDxe.inf
- INF MdeModulePkg/Universal/DisplayEngineDxe/DisplayEngineDxe.inf
- INF MdeModulePkg/Universal/SetupBrowserDxe/SetupBrowserDxe.inf
- INF MdeModulePkg/Universal/BdsDxe/BdsDxe.inf
- INF MdeModulePkg/Application/UiApp/UiApp.inf
- #
- # FDT installation
- #
- # The UEFI driver is at the end of the list of the driver to be dispatched
- # after the device drivers (eg: Ethernet) to ensure we have support for them.
+[FV.FVNOR_COMPACT] +FvAlignment = 8 +ERASE_POLARITY = 1 +MEMORY_MAPPED = TRUE +STICKY_WRITE = TRUE +LOCK_CAP = TRUE +LOCK_STATUS = TRUE +WRITE_DISABLED_CAP = TRUE +WRITE_ENABLED_CAP = TRUE +WRITE_STATUS = TRUE +WRITE_LOCK_CAP = TRUE +WRITE_LOCK_STATUS = TRUE +READ_DISABLED_CAP = TRUE +READ_ENABLED_CAP = TRUE +READ_STATUS = TRUE +READ_LOCK_CAP = TRUE +READ_LOCK_STATUS = TRUE
- INF OpenPlatformPkg/Chips/Nxp/QoriqLs/Library/PrePiNor/PrePiNor.inf
+[FV.FVMAIN_COMPACT] +FvAlignment = 8 +ERASE_POLARITY = 1 +MEMORY_MAPPED = TRUE +STICKY_WRITE = TRUE +LOCK_CAP = TRUE +LOCK_STATUS = TRUE +WRITE_DISABLED_CAP = TRUE +WRITE_ENABLED_CAP = TRUE +WRITE_STATUS = TRUE +WRITE_LOCK_CAP = TRUE +WRITE_LOCK_STATUS = TRUE +READ_DISABLED_CAP = TRUE +READ_ENABLED_CAP = TRUE +READ_STATUS = TRUE +READ_LOCK_CAP = TRUE +READ_LOCK_STATUS = TRUE
- INF ArmPlatformPkg/PrePi/PeiUniCore.inf
- FILE FV_IMAGE = 9E21FD93-9C72-4c15-8C4B-E77F1DB2D792 {
- SECTION GUIDED EE4E5898-3914-4259-9D6E-DC7BD79403CF PROCESSING_REQUIRED = TRUE {
SECTION FV_IMAGE = FVMAIN
- }
- }
+################################################################################ +# +# Rules are use with the [FV] section's module INF type to define +# how an FFS file is created for a given INF file. The following Rule are the default +# rules for the different module type. User can add the customized rules to define the +# content of the FFS file. +# +################################################################################
+############################################################################ +# Example of a DXE_DRIVER FFS file with a Checksum encapsulation section # +############################################################################ +# +#[Rule.Common.DXE_DRIVER] +# FILE DRIVER = $(NAMED_GUID) { +# DXE_DEPEX DXE_DEPEX Optional $(INF_OUTPUT)/$(MODULE_NAME).depex +# COMPRESS PI_STD { +# GUIDED { +# PE32 PE32 $(INF_OUTPUT)/$(MODULE_NAME).efi +# UI STRING="$(MODULE_NAME)" Optional +# VERSION STRING="$(INF_VERSION)" Optional BUILD_NUM=$(BUILD_NUMBER) +# } +# } +# } +# +############################################################################
+[Rule.Common.SEC]
- FILE SEC = $(NAMED_GUID) RELOCS_STRIPPED {
- TE TE Align = 32 $(INF_OUTPUT)/$(MODULE_NAME).efi
- }
+[Rule.Common.PEI_CORE]
- FILE PEI_CORE = $(NAMED_GUID) {
- TE TE $(INF_OUTPUT)/$(MODULE_NAME).efi
- UI STRING ="$(MODULE_NAME)" Optional
- }
+[Rule.Common.PEIM]
- FILE PEIM = $(NAMED_GUID) {
PEI_DEPEX PEI_DEPEX Optional $(INF_OUTPUT)/$(MODULE_NAME).depex
PE32 PE32 $(INF_OUTPUT)/$(MODULE_NAME).efi
UI STRING="$(MODULE_NAME)" Optional
- }
+[Rule.Common.PEIM.TIANOCOMPRESSED]
- FILE PEIM = $(NAMED_GUID) DEBUG_MYTOOLS_IA32 {
- PEI_DEPEX PEI_DEPEX Optional $(INF_OUTPUT)/$(MODULE_NAME).depex
- GUIDED A31280AD-481E-41B6-95E8-127F4C984779 PROCESSING_REQUIRED = TRUE {
PE32 PE32 $(INF_OUTPUT)/$(MODULE_NAME).efi
UI STRING="$(MODULE_NAME)" Optional
- }
- }
+[Rule.Common.DXE_CORE]
- FILE DXE_CORE = $(NAMED_GUID) {
- PE32 PE32 $(INF_OUTPUT)/$(MODULE_NAME).efi
- UI STRING="$(MODULE_NAME)" Optional
- }
+[Rule.Common.UEFI_DRIVER]
- FILE DRIVER = $(NAMED_GUID) {
- DXE_DEPEX DXE_DEPEX Optional $(INF_OUTPUT)/$(MODULE_NAME).depex
- PE32 PE32 $(INF_OUTPUT)/$(MODULE_NAME).efi
- UI STRING="$(MODULE_NAME)" Optional
- }
+[Rule.Common.DXE_DRIVER]
- FILE DRIVER = $(NAMED_GUID) {
- DXE_DEPEX DXE_DEPEX Optional $(INF_OUTPUT)/$(MODULE_NAME).depex
- PE32 PE32 $(INF_OUTPUT)/$(MODULE_NAME).efi
- UI STRING="$(MODULE_NAME)" Optional
- }
+[Rule.Common.DXE_RUNTIME_DRIVER]
- FILE DRIVER = $(NAMED_GUID) {
- DXE_DEPEX DXE_DEPEX Optional $(INF_OUTPUT)/$(MODULE_NAME).depex
- PE32 PE32 $(INF_OUTPUT)/$(MODULE_NAME).efi
- UI STRING="$(MODULE_NAME)" Optional
- }
+[Rule.Common.UEFI_APPLICATION]
- FILE APPLICATION = $(NAMED_GUID) {
- UI STRING ="$(MODULE_NAME)" Optional
- PE32 PE32 $(INF_OUTPUT)/$(MODULE_NAME).efi
- }
+[Rule.Common.UEFI_DRIVER.BINARY]
- FILE DRIVER = $(NAMED_GUID) {
- DXE_DEPEX DXE_DEPEX Optional |.depex
- PE32 PE32 |.efi
- UI STRING="$(MODULE_NAME)" Optional
- VERSION STRING="$(INF_VERSION)" Optional BUILD_NUM=$(BUILD_NUMBER)
- }
+[Rule.Common.UEFI_APPLICATION.BINARY]
- FILE APPLICATION = $(NAMED_GUID) {
- PE32 PE32 |.efi
- UI STRING="$(MODULE_NAME)" Optional
- VERSION STRING="$(INF_VERSION)" Optional BUILD_NUM=$(BUILD_NUMBER)
- }
diff --git a/Platforms/Nxp/LS1043aRdb/build.sh b/Platforms/Nxp/LS1043aRdb/build.sh new file mode 100755 index 0000000..4012a78 --- /dev/null +++ b/Platforms/Nxp/LS1043aRdb/build.sh
I would very much prefer not to merge these last two files. But I would be happy to add an entry for LS1043A to the default config in my uefi-tools set of helper scripts.
/ Leif
@@ -0,0 +1,72 @@ +#!/bin/bash
+# UEFI build script for LS1043A SoC from Freescale +# +# Copyright (c) 2016, Freescale Semiconductor, Inc. All rights reserved. +# +# This program and the accompanying materials +# are licensed and made available under the terms and conditions of the BSD License +# which accompanies this distribution. The full text of the license may be found at +# http://opensource.org/licenses/bsd-license.php +# +# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, +# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. +#
+print_usage_banner() +{
- echo "This shell script expects:"
- echo " Arg 1 (mandatory): Build candidate (can be RELEASE or DEBUG). By
default we build the RELEASE candidate."
- echo " Arg 2 (optional): clean - To do a 'make clean' operation."
+}
+# Actual stuff starts from here +echo ".........................................." +echo "Welcome to LS1043A UEFI Build environment" +echo ".........................................."
+# Check for input arguments +if [[ $1 == "" ]]; then
- echo "Error ! No build target specified."
- print_usage_banner
- exit
+fi
+# Check for input arguments +if [[ $1 != "RELEASE" ]]; then
- if [[ $1 != "DEBUG" ]]; then
echo "Error ! Incorrect build target specified."
print_usage_banner
exit
- fi
+fi
+if [[ $2 == "clean" ]]; then
- echo "Cleaning up the build directory '../../../../Build/LS1043aRdb/'.."
- rm -rf ../../../../Build/LS1043aRdb/*
- exit
+fi
+# Clean-up +set -e +shopt -s nocasematch
+# +# Setup workspace now +# +echo Initializing workspace +cd ../../../../
+# Use the BaseTools in edk2 +export EDK_TOOLS_PATH=`pwd`/BaseTools +source edksetup.sh BaseTools
+# Global Defaults +ARCH=AARCH64 +TARGET_TOOLS=GCC49
+build -p "$WORKSPACE/OpenPlatformPkg/Platforms/Nxp/LS1043aRdb/LS1043aRdbPkg.dsc" -a $ARCH -t $TARGET_TOOLS -b $1
+cat $WORKSPACE/Build/LS1043aRdb/$1_GCC49/FV/LS1043ARDB_EFI.fd >> $WORKSPACE/Build/LS1043aRdb/$1_GCC49/FV/LS1043ARDBPI_EFI.fd +mv $WORKSPACE/Build/LS1043aRdb/$1_GCC49/FV/LS1043ARDBPI_EFI.fd $WORKSPACE/Build/LS1043aRdb/$1_GCC49/FV/LS1043ARDB_EFI.fd diff --git a/Platforms/Nxp/LS1043aRdb/ls1043a_env.cshrc b/Platforms/Nxp/LS1043aRdb/ls1043a_env.cshrc new file mode 100644 index 0000000..63d702e --- /dev/null +++ b/Platforms/Nxp/LS1043aRdb/ls1043a_env.cshrc @@ -0,0 +1,2 @@ +export GCC49_AARCH64_PREFIX='aarch64-linux-gnu-'
+unset ARCH
1.9.1
Hi Leif,
From: Leif Lindholm [mailto:leif.lindholm@linaro.org] Sent: Saturday, November 05, 2016 5:54 AM
On Tue, Oct 18, 2016 at 01:34:13AM +0530, Bhupesh Sharma wrote:
From: Sakar Arora sakar.arora@nxp.com
The patch adds the device description, flash description and
declaration
files for the LS1043aRdbPkg.
In addition this patch also adds the build scripts required to build this package.
Signed-off-by: Sakar Arora sakar.arora@nxp.com Signed-off-by: Bhupesh Sharma bhupesh.sharma@nxp.com
Chips/Nxp/QoriqLs/NxpQoriqLs.dec | 50 +++ Platforms/Nxp/LS1043aRdb/LS1043aRdbPkg.dec | 166 ++++++++ Platforms/Nxp/LS1043aRdb/LS1043aRdbPkg.dsc | 602
+++++++++++++++++++++++++++++
Platforms/Nxp/LS1043aRdb/LS1043aRdbPkg.fdf | 311 +++++++++++++++ Platforms/Nxp/LS1043aRdb/build.sh | 72 ++++ Platforms/Nxp/LS1043aRdb/ls1043a_env.cshrc | 2 + 6 files changed, 1203 insertions(+) create mode 100644 Chips/Nxp/QoriqLs/NxpQoriqLs.dec create mode 100644 Platforms/Nxp/LS1043aRdb/LS1043aRdbPkg.dec create mode 100644 Platforms/Nxp/LS1043aRdb/LS1043aRdbPkg.dsc create mode 100644 Platforms/Nxp/LS1043aRdb/LS1043aRdbPkg.fdf create mode 100755 Platforms/Nxp/LS1043aRdb/build.sh create mode 100644 Platforms/Nxp/LS1043aRdb/ls1043a_env.cshrc
diff --git a/Chips/Nxp/QoriqLs/NxpQoriqLs.dec
b/Chips/Nxp/QoriqLs/NxpQoriqLs.dec
new file mode 100644 index 0000000..6b04836 --- /dev/null +++ b/Chips/Nxp/QoriqLs/NxpQoriqLs.dec
OK, this is a problem. This file is referenced by previous commits, which breaks bisect.
Ok, will fix this in v2.
@@ -0,0 +1,50 @@ +#/** LS1043a board package. +# +# Copyright (c) 2016, Freescale Semiconductor, Inc. All rights
reserved.
+# +# This program and the accompanying materials are licensed and
made available under
+# the terms and conditions of the BSD License which accompanies
this distribution.
+# The full text of the license may be found at +# http://opensource.org/licenses/bsd-license.php +# +# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS"
BASIS,
+# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER
EXPRESS OR IMPLIED.
+# +#**/
+[Defines]
- DEC_SPECIFICATION = 0x00010005
- PACKAGE_NAME = NxpQoriqLs
- PACKAGE_GUID = 6eba6648-d853-4eb3-9761-
528b82d5ab14
- PACKAGE_VERSION = 0.1
+###################################################################### ##########
+# +# Include Section - list of Include Paths that are provided by this
package.
+# Comments are used for Keywords and Module Types. +# +# Supported Module Types: +# BASE SEC PEI_CORE PEIM DXE_CORE DXE_DRIVER DXE_RUNTIME_DRIVER
DXE_SMM_DRIVER DXE_SAL_DRIVER UEFI_DRIVER UEFI_APPLICATION
+#
+###################################################################### ##########
+[Includes.common]
- Include # Root include for the package
+[Guids.common]
- gNxpQoriqLsTokenSpaceGuid = { 0x6834fe45, 0x4aee, 0x4fc6, {
0xbc, 0xb5, 0xff, 0x45, 0xb7, 0xa8, 0x71, 0xf2 } }
+[PcdsFixedAtBuild.common]
- gNxpQoriqLsTokenSpaceGuid.PcdOcramStackBase|0x0|UINT32|0x00000001
gNxpQoriqLsTokenSpaceGuid.PcdFdNorBaseAddress|0x0|UINT64|0x00000002
- gNxpQoriqLsTokenSpaceGuid.PcdPiFdBaseAddress|0x0|UINT64|0x00000003
- gNxpQoriqLsTokenSpaceGuid.PcdPiFdSize|0x0|UINT32|0x00000004
gNxpQoriqLsTokenSpaceGuid.PcdFvNorBaseAddress|0x0|UINT64|0x00000005
- gNxpQoriqLsTokenSpaceGuid.PcdFvNorSize|0x0|UINT32|0x00000006
- gNxpQoriqLsTokenSpaceGuid.PcdI2cBus|0|UINT32|0x0000007
- gNxpQoriqLsTokenSpaceGuid.PcdRtcI2cBus|0|UINT32|0x0000008
- gNxpQoriqLsTokenSpaceGuid.PcdDs1307I2cAddress|0|UINT32|0x0000009
gNxpQoriqLsTokenSpaceGuid.PcdPpaFitConfiguration|""|VOID*|0x000000A
- gNxpQoriqLsTokenSpaceGuid.PcdPpaNorBaseAddr|0x0|UINT64|0x000000B
- gNxpQoriqLsTokenSpaceGuid.PcdPpaDdrOffsetAddr|0x0|UINT64|0x000000C
- gNxpQoriqLsTokenSpaceGuid.PcdI2cSpeed|0|UINT32|0x000000D
Sort these, please.
Sure.
diff --git a/Platforms/Nxp/LS1043aRdb/LS1043aRdbPkg.dec
b/Platforms/Nxp/LS1043aRdb/LS1043aRdbPkg.dec
new file mode 100644 index 0000000..9df3eb7 --- /dev/null +++ b/Platforms/Nxp/LS1043aRdb/LS1043aRdbPkg.dec
Another bisect breakage. These need to go in before the components that reference them.
Ok.
@@ -0,0 +1,166 @@ +#/** LS1043a board package. +# +# Copyright (c) 2016, Freescale Semiconductor, Inc. All rights
reserved.
+# +# This program and the accompanying materials are licensed and
made available under
+# the terms and conditions of the BSD License which accompanies
this distribution.
+# The full text of the license may be found at +# http://opensource.org/licenses/bsd-license.php +# +# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS"
BASIS,
+# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER
EXPRESS OR IMPLIED.
+# +#**/
+[Defines]
- DEC_SPECIFICATION = 0x00010005
- PACKAGE_NAME = LS1043aRdbPkg
- PACKAGE_GUID = 6eba6648-d853-4eb3-9761-
528b82d5ab04
- PACKAGE_VERSION = 0.1
+###################################################################### ##########
+# +# Include Section - list of Include Paths that are provided by this
package.
+# Comments are used for Keywords and Module Types. +# +# Supported Module Types: +# BASE SEC PEI_CORE PEIM DXE_CORE DXE_DRIVER DXE_RUNTIME_DRIVER
DXE_SMM_DRIVER DXE_SAL_DRIVER UEFI_DRIVER UEFI_APPLICATION
+#
+###################################################################### ##########
+[Includes.common]
- Include # Root include for the package
+[Guids.common]
- gLS1043aRdbTokenSpaceGuid = { 0x6834fe45, 0x4aee, 0x4fc6, {
0xbc, 0xb5, 0xff, 0x45, 0xb7, 0xa8, 0x71, 0xe2 } }
- gEfiMmcHostProtocolGuid = { 0x3e591c00, 0x9e4a, 0x11df,
{0x92, 0x44, 0x00, 0x02, 0xA5, 0xD5, 0xC5, 0x1B }}
- gShellDebug1HiiGuid = {0x25f200aa, 0xd3cb, 0x470a,
{0xbf, 0x51, 0xe7, 0xd1, 0x62, 0xd2, 0x2e, 0x6f}}
- gShellNetwork1HiiGuid = {0xf3d301bb, 0xf4a5, 0x45a8,
{0xb0, 0xb7, 0xfa, 0x99, 0x9c, 0x62, 0x37, 0xae}}
- gEfiDpcProtocolGuid = {0x480f8ae9, 0xc46, 0x4aa9, {
0xbc, 0x89, 0xdb, 0x9f, 0xba, 0x61, 0x98, 0x6 }}
- gShellTftpHiiGuid = {0x738a9314, 0x82c1, 0x4592,
{0x8f, 0xf7, 0xc1, 0xbd, 0xf1, 0xb2, 0x0e, 0xd4}}
Sort these, please.
Ok.
- ## Include/Protocol/SimpleNetwork.h
- gEfiSimpleNetworkProtocolGuid = { 0xA19832B9, 0xAC25, 0x11D3, {
0x9A, 0x2D, 0x00, 0x90, 0x27, 0x3F, 0xC1, 0x4D }}
- ## Include/Protocol/ManagedNetwork.h
- gEfiManagedNetworkServiceBindingProtocolGuid = { 0xF36FF770,
0xA7E1, 0x42CF, { 0x9E, 0xD2, 0x56, 0xF0, 0xF2, 0x71, 0xF4, 0x4C }}
- ## Include/Protocol/ManagedNetwork.h
- gEfiManagedNetworkProtocolGuid = { 0x7ab33a91, 0xace5, 0x4326, {
0xb5, 0x72, 0xe7, 0xee, 0x33, 0xd3, 0x9f, 0x16 }}
- ## Include/Protocol/HiiConfigRouting.h
- gEfiHiiConfigRoutingProtocolGuid = {0x587e72d7, 0xcc50, 0x4f79,
{0x82, 0x09, 0xca, 0x29, 0x1f, 0xc1, 0xa1, 0x0f}}
- ## Include/Protocol/Arp.h
- gEfiArpServiceBindingProtocolGuid = { 0xF44C00EE, 0x1F2C, 0x4A00,
{ 0xAA, 0x09, 0x1C, 0x9F, 0x3E, 0x08, 0x00, 0xA3 }}
- ## Include/Protocol/Arp.h
- gEfiArpProtocolGuid = { 0xF4B427BB, 0xBA21, 0x4F16, {
0xBC, 0x4E, 0x43, 0xE4, 0x16, 0xAB, 0x61, 0x9C }}
- ## Include/Protocol/Dhcp4.h
- gEfiDhcp4ServiceBindingProtocolGuid = { 0x9D9A39D8, 0xBD42,
0x4A73, { 0xA4, 0xD5, 0x8E, 0xE9, 0x4B, 0xE1, 0x13, 0x80 }}
Why are you redefining all of these that already exist in MdePkg.dec? Please delete all of these (including the below ones).
Ok.
- ## Include/Protocol/Dhcp4.h
- gEfiDhcp4ProtocolGuid = { 0x8A219718, 0x4EF5, 0x4761, {
0x91, 0xC8, 0xC0, 0xF0, 0x4B, 0xDA, 0x9E, 0x56 }}
- ## Include/Protocol/Tcp4.h
- gEfiTcp4ServiceBindingProtocolGuid = { 0x00720665, 0x67EB, 0x4A99,
{ 0xBA, 0xF7, 0xD3, 0xC3, 0x3A, 0x1C, 0x7C, 0xC9 }}
- ## Include/Protocol/Tcp4.h
- gEfiTcp4ProtocolGuid = { 0x65530BC7, 0xA359, 0x410F, {
0xB0, 0x10, 0x5A, 0xAD, 0xC7, 0xEC, 0x2B, 0x62 }}
- ## Include/Protocol/Ip4.h
- gEfiIp4ServiceBindingProtocolGuid = { 0xC51711E7, 0xB4BF, 0x404A,
{ 0xBF, 0xB8, 0x0A, 0x04, 0x8E, 0xF1, 0xFF, 0xE4 }}
- ## Include/Protocol/Ip4.h
- gEfiIp4ProtocolGuid = { 0x41D94CD2, 0x35B6, 0x455A, {
0x82, 0x58, 0xD4, 0xE5, 0x13, 0x34, 0xAA, 0xDD }}
- ## Include/Protocol/Ip4Config.h
- gEfiIp4ConfigProtocolGuid = { 0x3B95AA31, 0x3793, 0x434B, {
0x86, 0x67, 0xC8, 0x07, 0x08, 0x92, 0xE0, 0x5E }}
- ## Include/Protocol/Udp4.h
- gEfiUdp4ServiceBindingProtocolGuid = { 0x83F01464, 0x99BD, 0x45E5,
{ 0xB3, 0x83, 0xAF, 0x63, 0x05, 0xD8, 0xE9, 0xE6 }}
- ## Include/Protocol/Udp4.h
- gEfiUdp4ProtocolGuid = { 0x3AD9DF29, 0x4501, 0x478D, {
0xB1, 0xF8, 0x7F, 0x7F, 0xE7, 0x0E, 0x50, 0xF3 }}
- ## Include/Protocol/Mtftp4.h
- gEfiMtftp4ServiceBindingProtocolGuid = { 0x2FE800BE, 0x8F01,
0x4AA6, { 0x94, 0x6B, 0xD7, 0x13, 0x88, 0xE1, 0x83, 0x3F }}
- ## Include/Protocol/Mtftp4.h
- gEfiMtftp4ProtocolGuid = { 0x78247C57, 0x63DB, 0x4708, {
0x99, 0xC2, 0xA8, 0xB4, 0xA9, 0xA6, 0x1F, 0x6B }}
+[PcdsFixedAtBuild.common]
- # Size to reserve in the primary core stack for PEI Global
Variables
- # = sizeof(UINTN) /* PcdPeiServicePtr or HobListPtr */
gArmPlatformTokenSpaceGuid.PcdPeiGlobalVariableSize|0x4|UINT32|0x000000 16
gArmPlatformTokenSpaceGuid.PcdCounterFrequency|12000000|UINT32|0x000000 17
New Pcds you are defining in this file should be in your own token space. In this case, gLS1043aRdbTokenSpaceGuid. Like it's done in NxpQoriqLs.dec.
Ok.
- ## LS1043a UART
gArmPlatformTokenSpaceGuid.LS1043aUartClkInHz|61440000|UINT32|0x0000001 8
- gArmPlatformTokenSpaceGuid.LS1043aUartInteger|0|UINT32|0x00000019
gArmPlatformTokenSpaceGuid.LS1043aUartFractional|0|UINT32|0x0000001A
- ## Timer
- gArmTokenSpaceGuid.PcdArmArchTimerFreqInHz|0|UINT32|0x0000001B
- gEmbeddedTokenSpaceGuid.PcdTimerPeriod|10000|UINT32|0x0000001D
gArmPlatformTokenSpaceGuid.PcdArmArchTimerVirtIntrNum|0|UINT32|0x000000 1E
gArmPlatformTokenSpaceGuid.PcdArmArchTimerHypIntrNum|0|UINT32|0x0000001 F
gArmPlatformTokenSpaceGuid.PcdArmArchTimerSecIntrNum|0|UINT32|0x0000002 0
gArmPlatformTokenSpaceGuid.PcdArmArchTimerIntrNum|0|UINT32|0x00000021
- gEmbeddedTokenSpaceGuid.PcdMetronomeTickPeriod|0|UINT32|0x00000022
gArmPlatformTokenSpaceGuid.PcdLS1043aWatchDogBase|0x0|UINT32|0x00000023
- gArmPlatformTokenSpaceGuid.DUartClkInHz|0x0|UINT32|0x00000024
- gArmPlatformTokenSpaceGuid.DUartInteger|0x0|UINT32|0x00000025
- ## Ddr
- gArmTokenSpaceGuid.PcdDdrInitialize|FALSE|BOOLEAN|0x00000026
- #
- # LS1043a Soc Specific PCDs
- #
gArmPlatformTokenSpaceGuid.PcdCounterFrequencyReal|FALSE|BOOLEAN|0x0000 0027
gArmPlatformTokenSpaceGuid.PcdCsuInitialize|FALSE|BOOLEAN|0x00000028
gArmPlatformTokenSpaceGuid.PcdTzc380Initialize|FALSE|BOOLEAN|0x00000029
gArmPlatformTokenSpaceGuid.PcdCci400Initialize|FALSE|BOOLEAN|0x0000002A
gArmPlatformTokenSpaceGuid.PcdClockInitialize|FALSE|BOOLEAN|0x0000002B
- gLS1043aRdbTokenSpaceGuid.PcdFdNandLba|0x0|UINT32|0x00000031
#gEfiShellPkgTokenSpaceGuid.PcdShellLibAutoInitialize|FALSE|BOOLEAN|0x0 0000039
- #
- # PPA specific PCDs
- #
- gArmPlatformTokenSpaceGuid.PcdPpaNorBaseAddr|0x0|UINT64|0x00000032
gArmPlatformTokenSpaceGuid.PcdPpaDdrOffsetAddr|0x0|UINT64|0x00000033 # calculated from top of DDR
gLS1043aRdbTokenSpaceGuid.PcdPpaFitConfiguration|""|VOID*|0x00000034
- ## PCI
- # This value is used to set the base address of PCI express
hierarchy.
- # @Prompt PCI Express Base Address.
- #
gArmPlatformTokenSpaceGuid.PcdPciMaxPayloadFixup|FALSE|BOOLEAN|0x000000 40
gArmPlatformTokenSpaceGuid.PcdPciBusHotPlugDeviceSupport|TRUE|BOOLEAN|0 x00000041
gArmPlatformTokenSpaceGuid.PcdKludgeMapPciMmioAsCached|FALSE|BOOLEAN|0x 00000006
- gArmPlatformTokenSpaceGuid.PcdPciBusMin|0|UINT64|0x00000042
- gArmPlatformTokenSpaceGuid.PcdPciBusMax|255|UINT64|0x00000043
gArmPlatformTokenSpaceGuid.PcdPciIoBase|0x00010000|UINT64|0x00000044
gArmPlatformTokenSpaceGuid.PcdPciIoSize|0x00010000|UINT64|0x00000045
gArmPlatformTokenSpaceGuid.PcdPciMmio32Base|0x40000000|UINT32|0x0000004 6
gArmPlatformTokenSpaceGuid.PcdPciMmio32Size|0x40000000|UINT32|0x0000004 7
gArmPlatformTokenSpaceGuid.PcdPciMemTranslation|0x5000000000|UINT64|0x0 0000055
gArmPlatformTokenSpaceGuid.PcdPciMmio64Base|0x5040000000|UINT64|0x00000 048
gArmPlatformTokenSpaceGuid.PcdPciMmio64Size|0x0040000000|UINT64|0x00000 049
gArmPlatformTokenSpaceGuid.PcdPciIoTranslation|0x00010000|UINT64|0x0000 0050
gEfiMdePkgTokenSpaceGuid.PcdPci1ExpressBaseAddress|0x5000000000|UINT64| 0x00000051
gEfiMdePkgTokenSpaceGuid.PcdPci2ExpressBaseAddress|0x4800000000|UINT64| 0x00000052
gEfiMdePkgTokenSpaceGuid.PcdPci3ExpressBaseAddress|0x5000000000|UINT64| 0x00000058
gEfiMdePkgTokenSpaceGuid.PcdPciExpressBaseAddress|0x03600000|UINT64|0x0 000004D
- gLS1043aRdbTokenSpaceGuid.PcdBootMode|0x0|UINT32|0x00000038
- gLS1043aRdbTokenSpaceGuid.PcdPpaNandLba|0x10|UINT32|0x00000039
gLS1043aRdbTokenSpaceGuid.PcdPpaImageSize|0x100000|UINT32|0x00000040
- gLS1043aRdbTokenSpaceGuid.PcdPpaSdxcLba|0x10|UINT32|0x00000041
- gLS1043aRdbTokenSpaceGuid.PcdFdSdxcLba|0x0|UINT32|0x00000042
diff --git a/Platforms/Nxp/LS1043aRdb/LS1043aRdbPkg.dsc
b/Platforms/Nxp/LS1043aRdb/LS1043aRdbPkg.dsc
new file mode 100644 index 0000000..1e3c2db --- /dev/null +++ b/Platforms/Nxp/LS1043aRdb/LS1043aRdbPkg.dsc @@ -0,0 +1,602 @@ +#/** LS1043A board package. +# +# Copyright (c) 2016, Freescale Semiconductor, Inc. All rights
reserved.
+# +# This program and the accompanying materials +# are licensed and made available under the terms and conditions
of the BSD License
+# which accompanies this distribution. The full text of the
license may be found at
+# http://opensource.org/licenses/bsd-license.php +# +# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS"
BASIS,
+# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER
EXPRESS OR IMPLIED.
+# +#**/
+###################################################################### ##########
+# +# Defines Section - statements that will be processed to create a
Makefile.
+#
+###################################################################### ##########
+[Defines]
- #
- # Defines for default states. These can be changed on the command
line.
- # -D FLAG=VALUE
- #
- PLATFORM_NAME = LS1043aRdbPkg
- PLATFORM_GUID = 60169ec4-d2b4-44f8-825e-
f8684fd42e4f
- PLATFORM_VERSION = 0.1
- DSC_SPECIFICATION = 0x00010005
- OUTPUT_DIRECTORY = Build/LS1043aRdb
- SUPPORTED_ARCHITECTURES = AARCH64
- BUILD_TARGETS = DEBUG|RELEASE
- SKUID_IDENTIFIER = DEFAULT
- FLASH_DEFINITION =
OpenPlatformPkg/Platforms/Nxp/LS1043aRdb/LS1043aRdbPkg.fdf
+[LibraryClasses.common]
- ArmLib|ArmPkg/Library/ArmLib/ArmBaseLib.inf
ArmCpuLib|ArmPkg/Drivers/ArmCpuLib/ArmCortexAEMv8Lib/ArmCortexAEMv8Lib. inf
- ArmSmcLib|ArmPkg/Library/ArmSmcLib/ArmSmcLib.inf
- ArmMmuLib|ArmPkg/Library/ArmMmuLib/ArmMmuBaseLib.inf
ArmGenericTimerCounterLib|ArmPkg/Library/ArmGenericTimerPhyCounterLib/A rmGenericTimerPhyCounterLib.inf
- TimerLib|ArmPkg/Library/ArmArchTimerLib/ArmArchTimerLib.inf
SocLib|OpenPlatformPkg/Platforms/Nxp/LS1043aRdb/Library/LS1043aSocLib/L S1043aSocLib.inf
ArmTrustZoneLib|ArmPlatformPkg/Drivers/ArmTrustZone/ArmTrustZone.inf
CpldLib|OpenPlatformPkg/Platforms/Nxp/LS1043aRdb/Library/CpldLib/CpldLi b.inf
ArmPlatformLib|OpenPlatformPkg/Platforms/Nxp/LS1043aRdb/Library/LS1043a RdbLib/LS1043aRdbLib.inf
ArmPlatformStackLib|ArmPlatformPkg/Library/ArmPlatformStackLib/ArmPlatf ormStackLib.inf
- HiiLib|MdeModulePkg/Library/UefiHiiLib/UefiHiiLib.inf
UefiHiiServicesLib|MdeModulePkg/Library/UefiHiiServicesLib/UefiHiiServi cesLib.inf
FileExplorerLib|MdeModulePkg/Library/FileExplorerLib/FileExplorerLib.in f
#ImageDecoderLib|MdeModulePkg/Library/ImageDecoderLib/ImageDecoderLib.i nf
- BootLogoLib|MdeModulePkg/Library/BootLogoLib/BootLogoLib.inf
PlatformBootManagerLib|ArmPkg/Library/PlatformBootManagerLib/PlatformBo otManagerLib.inf
- DxeServicesLib|MdePkg/Library/DxeServicesLib/DxeServicesLib.inf
UefiBootManagerLib|MdeModulePkg/Library/UefiBootManagerLib/UefiBootMana gerLib.inf
CustomizedDisplayLib|MdeModulePkg/Library/CustomizedDisplayLib/Customiz edDisplayLib.inf
+# Networking Requirements
- NetLib|MdeModulePkg/Library/DxeNetLib/DxeNetLib.inf
- DpcLib|MdeModulePkg/Library/DxeDpcLib/DxeDpcLib.inf
- UdpIoLib|MdeModulePkg/Library/DxeUdpIoLib/DxeUdpIoLib.inf
- IpIoLib|MdeModulePkg/Library/DxeIpIoLib/DxeIpIoLib.inf
- # ARM GIC400 General Interrupt Driver
- ArmGicLib|ArmPkg/Drivers/ArmGic/ArmGicLib.inf
- ArmGicArchLib|ArmPkg/Library/ArmGicArchLib/ArmGicArchLib.inf
+!if $(TARGET) == RELEASE
DebugLib|MdePkg/Library/BaseDebugLibSerialPort/BaseDebugLibSerialPort.i nf
UncachedMemoryAllocationLib|ArmPkg/Library/UncachedMemoryAllocationLib/ UncachedMemoryAllocationLib.inf
+!else
DebugLib|MdePkg/Library/BaseDebugLibSerialPort/BaseDebugLibSerialPort.i nf
UncachedMemoryAllocationLib|ArmPkg/Library/UncachedMemoryAllocationLib/ UncachedMemoryAllocationLib.inf
+!endif
Both conditions invoke the same libraries.
Ok, will fix this.
DebugPrintErrorLevelLib|MdePkg/Library/BaseDebugPrintErrorLevelLib/Base DebugPrintErrorLevelLib.inf
- # I2c Library
- I2cLib|OpenPlatformPkg/Chips/Nxp/QoriqLs/Library/I2cLib/I2cLib.inf
- # Ddr Library
DdrLib|OpenPlatformPkg/Platforms/Nxp/LS1043aRdb/Library/DdrLib/DdrLib.i nf
MemoryAllocationLib|MdePkg/Library/UefiMemoryAllocationLib/UefiMemoryAl locationLib.inf
- BaseLib|MdePkg/Library/BaseLib/BaseLib.inf
SynchronizationLib|MdePkg/Library/BaseSynchronizationLib/BaseSynchroniz ationLib.inf
- BaseMemoryLib|ArmPkg/Library/BaseMemoryLibStm/BaseMemoryLibStm.inf
EfiResetSystemLib|OpenPlatformPkg/Platforms/Nxp/LS1043aRdb/Library/Rese tSystemLib/ResetSystemLib.inf
PerformanceLib|MdePkg/Library/BasePerformanceLibNull/BasePerformanceLib Null.inf
- PrintLib|MdePkg/Library/BasePrintLib/BasePrintLib.inf
- EfiFileLib|EmbeddedPkg/Library/EfiFileLib/EfiFileLib.inf
- PeCoffLib|MdePkg/Library/BasePeCoffLib/BasePeCoffLib.inf
PeCoffGetEntryPointLib|MdePkg/Library/BasePeCoffGetEntryPointLib/BasePe CoffGetEntryPointLib.inf
PeCoffExtraActionLib|ArmPkg/Library/DebugPeCoffExtraActionLib/DebugPeCo ffExtraActionLib.inf
CacheMaintenanceLib|ArmPkg/Library/ArmCacheMaintenanceLib/ArmCacheMaint enanceLib.inf
DefaultExceptionHandlerLib|ArmPkg/Library/DefaultExceptionHandlerLib/De faultExceptionHandlerLib.inf
CpuExceptionHandlerLib|ArmPkg/Library/ArmExceptionLib/ArmExceptionLib.i nf
- PrePiLib|EmbeddedPkg/Library/PrePiLib/PrePiLib.inf
RealTimeClockLib|OpenPlatformPkg/Chips/Nxp/QoriqLs/Library/Ds1307RtcLib /Ds1307RtcLib.inf
- SemihostLib|ArmPkg/Library/SemihostLib/SemihostLib.inf
- # UART Driver
SerialPortLib|OpenPlatformPkg/Chips/Nxp/QoriqLs/Library/DUartPortLib/DU artPortLib.inf
- IoLib|MdePkg/Library/BaseIoLibIntrinsic/BaseIoLibIntrinsic.inf
MemoryAllocationLib|MdePkg/Library/UefiMemoryAllocationLib/UefiMemoryAl locationLib.inf
- UefiLib|MdePkg/Library/UefiLib/UefiLib.inf
- HobLib|MdePkg/Library/DxeHobLib/DxeHobLib.inf
UefiRuntimeServicesTableLib|MdePkg/Library/UefiRuntimeServicesTableLib/ UefiRuntimeServicesTableLib.inf
DevicePathLib|MdePkg/Library/UefiDevicePathLib/UefiDevicePathLib.inf
UefiBootServicesTableLib|MdePkg/Library/UefiBootServicesTableLib/UefiBo otServicesTableLib.inf
DxeServicesTableLib|MdePkg/Library/DxeServicesTableLib/DxeServicesTable Lib.inf
UefiDriverEntryPoint|MdePkg/Library/UefiDriverEntryPoint/UefiDriverEntr yPoint.inf
UefiApplicationEntryPoint|MdePkg/Library/UefiApplicationEntryPoint/Uefi ApplicationEntryPoint.inf
+# +# Assume everything is fixed at build +#
- PcdLib|MdePkg/Library/BasePcdLibNull/BasePcdLibNull.inf
- UefiRuntimeLib|MdePkg/Library/UefiRuntimeLib/UefiRuntimeLib.inf
- UefiUsbLib|MdePkg/Library/UefiUsbLib/UefiUsbLib.inf
- CpuLib|MdePkg/Library/BaseCpuLib/BaseCpuLib.inf
ArmDisassemblerLib|ArmPkg/Library/ArmDisassemblerLib/ArmDisassemblerLib .inf
DebugAgentLib|MdeModulePkg/Library/DebugAgentLibNull/DebugAgentLibNull. inf
- DmaLib|ArmPkg/Library/ArmDmaLib/ArmDmaLib.inf
- BdsLib|ArmPkg/Library/BdsLib/BdsLib.inf
- FdtLib|EmbeddedPkg/Library/FdtLib/FdtLib.inf
- ShellLib|ShellPkg/Library/UefiShellLib/UefiShellLib.inf
ShellCommandLib|ShellPkg/Library/UefiShellCommandLib/UefiShellCommandLi b.inf
FileHandleLib|MdePkg/Library/UefiFileHandleLib/UefiFileHandleLib.inf
ShellCEntryLib|ShellPkg/Library/UefiShellCEntryLib/UefiShellCEntryLib.i nf
- SortLib|MdeModulePkg/Library/UefiSortLib/UefiSortLib.inf
- NetLib|MdeModulePkg/Library/DxeNetLib/DxeNetLib.inf
HandleParsingLib|ShellPkg/Library/UefiHandleParsingLib/UefiHandleParsin gLib.inf
BcfgCommandLib|ShellPkg/Library/UefiShellBcfgCommandLib/UefiShellBcfgCo mmandLib.inf
TpmMeasurementLib|MdeModulePkg/Library/TpmMeasurementLibNull/TpmMeasure mentLibNull.inf
AuthVariableLib|MdeModulePkg/Library/AuthVariableLibNull/AuthVariableLi bNull.inf
- VarCheckLib|MdeModulePkg/Library/VarCheckLib/VarCheckLib.inf
+[LibraryClasses.common.SEC]
- PcdLib|MdePkg/Library/BasePcdLibNull/BasePcdLibNull.inf
ReportStatusCodeLib|IntelFrameworkModulePkg/Library/PeiDxeDebugLibRepor tStatusCode/PeiDxeDebugLibReportStatusCode.inf
UefiDecompressLib|MdePkg/Library/BaseUefiDecompressLib/BaseUefiDecompre ssLib.inf
ExtractGuidedSectionLib|EmbeddedPkg/Library/PrePiExtractGuidedSectionLi b/PrePiExtractGuidedSectionLib.inf
LzmaDecompressLib|IntelFrameworkModulePkg/Library/LzmaCustomDecompressL ib/LzmaCustomDecompressLib.inf
- PeCoffLib|MdePkg/Library/BasePeCoffLib/BasePeCoffLib.inf
- HobLib|EmbeddedPkg/Library/PrePiHobLib/PrePiHobLib.inf
PrePiHobListPointerLib|ArmPlatformPkg/Library/PrePiHobListPointerLib/Pr ePiHobListPointerLib.inf
MemoryAllocationLib|EmbeddedPkg/Library/PrePiMemoryAllocationLib/PrePiM emoryAllocationLib.inf
PerformanceLib|MdeModulePkg/Library/PeiPerformanceLib/PeiPerformanceLib .inf
- PlatformPeiLib|ArmPlatformPkg/PlatformPei/PlatformPeiLib.inf
- MemoryInitPeiLib|ArmPlatformPkg/MemoryInitPei/MemoryInitPeiLib.inf
- # 1/123 faster than Stm or Vstm version
- BaseMemoryLib|MdePkg/Library/BaseMemoryLib/BaseMemoryLib.inf
- # Uncomment to turn on GDB stub in SEC.
- #DebugAgentLib|EmbeddedPkg/Library/GdbDebugAgent/GdbDebugAgent.inf
+[LibraryClasses.common.PEI_CORE]
- PcdLib|MdePkg/Library/BasePcdLibNull/BasePcdLibNull.inf
ReportStatusCodeLib|IntelFrameworkModulePkg/Library/PeiDxeDebugLibRepor tStatusCode/PeiDxeDebugLibReportStatusCode.inf
+[LibraryClasses.common.DXE_CORE]
- HobLib|MdePkg/Library/DxeCoreHobLib/DxeCoreHobLib.inf
MemoryAllocationLib|MdeModulePkg/Library/DxeCoreMemoryAllocationLib/Dxe CoreMemoryAllocationLib.inf
DxeCoreEntryPoint|MdePkg/Library/DxeCoreEntryPoint/DxeCoreEntryPoint.in f
ReportStatusCodeLib|IntelFrameworkModulePkg/Library/DxeReportStatusCode LibFramework/DxeReportStatusCodeLib.inf
ExtractGuidedSectionLib|MdePkg/Library/DxeExtractGuidedSectionLib/DxeEx tractGuidedSectionLib.inf
UefiDecompressLib|MdePkg/Library/BaseUefiDecompressLib/BaseUefiDecompre ssLib.inf
- DxeServicesLib|MdePkg/Library/DxeServicesLib/DxeServicesLib.inf
- PeCoffLib|EmbeddedPkg/Library/DxeHobPeCoffLib/DxeHobPeCoffLib.inf
PerformanceLib|MdeModulePkg/Library/DxeCorePerformanceLib/DxeCorePerfor manceLib.inf
+[LibraryClasses.common.DXE_DRIVER]
ReportStatusCodeLib|IntelFrameworkModulePkg/Library/DxeReportStatusCode LibFramework/DxeReportStatusCodeLib.inf
- DxeServicesLib|MdePkg/Library/DxeServicesLib/DxeServicesLib.inf
SecurityManagementLib|MdeModulePkg/Library/DxeSecurityManagementLib/Dxe SecurityManagementLib.inf
PerformanceLib|MdeModulePkg/Library/DxePerformanceLib/DxePerformanceLib .inf
- MemoryInitPeiLib|ArmPlatformPkg/MemoryInitPei/MemoryInitPeiLib.inf
+[LibraryClasses.common.UEFI_APPLICATION]
- PcdLib|MdePkg/Library/DxePcdLib/DxePcdLib.inf
- HobLib|MdePkg/Library/DxeHobLib/DxeHobLib.inf
ReportStatusCodeLib|IntelFrameworkModulePkg/Library/DxeReportStatusCode LibFramework/DxeReportStatusCodeLib.inf
UefiDecompressLib|IntelFrameworkModulePkg/Library/BaseUefiTianoCustomDe compressLib/BaseUefiTianoCustomDecompressLib.inf
PerformanceLib|MdeModulePkg/Library/DxePerformanceLib/DxePerformanceLib .inf
+[LibraryClasses.common.UEFI_DRIVER]
ReportStatusCodeLib|IntelFrameworkModulePkg/Library/DxeReportStatusCode LibFramework/DxeReportStatusCodeLib.inf
UefiDecompressLib|IntelFrameworkModulePkg/Library/BaseUefiTianoCustomDe compressLib/BaseUefiTianoCustomDecompressLib.inf
ExtractGuidedSectionLib|MdePkg/Library/DxeExtractGuidedSectionLib/DxeEx tractGuidedSectionLib.inf
PerformanceLib|MdeModulePkg/Library/DxePerformanceLib/DxePerformanceLib .inf
- DxeServicesLib|MdePkg/Library/DxeServicesLib/DxeServicesLib.inf
+[LibraryClasses.common.DXE_RUNTIME_DRIVER]
- HobLib|MdePkg/Library/DxeHobLib/DxeHobLib.inf
MemoryAllocationLib|MdePkg/Library/UefiMemoryAllocationLib/UefiMemoryAl locationLib.inf
ReportStatusCodeLib|IntelFrameworkModulePkg/Library/DxeReportStatusCode LibFramework/DxeReportStatusCodeLib.inf
CapsuleLib|MdeModulePkg/Library/DxeCapsuleLibNull/DxeCapsuleLibNull.inf
- PeCoffLib|EmbeddedPkg/Library/DxeHobPeCoffLib/DxeHobPeCoffLib.inf
+[LibraryClasses.AARCH64]
- #
- # It is not possible to prevent the ARM compiler for generic
intrinsic functions.
- # This library provides the instrinsic functions generate by a
given compiler.
- # [LibraryClasses.ARM] and NULL mean link this library into all
ARM images.
- #
NULL|ArmPkg/Library/CompilerIntrinsicsLib/CompilerIntrinsicsLib.inf
+###################################################################### ##########
+# +# Pcd Section - list of all EDK II PCD Entries defined by this
Platform
+#
+###################################################################### ##########
+[PcdsFeatureFlag.common]
- ## If TRUE, Graphics Output Protocol will be installed on virtual
handle created by ConsplitterDxe.
- # It could be set FALSE to save size.
- gEfiMdeModulePkgTokenSpaceGuid.PcdConOutGopSupport|TRUE
- gEfiMdeModulePkgTokenSpaceGuid.PcdConOutUgaSupport|FALSE
- gEfiMdePkgTokenSpaceGuid.PcdComponentNameDisable|TRUE
- gEfiMdePkgTokenSpaceGuid.PcdDriverDiagnosticsDisable|TRUE
- gEfiMdePkgTokenSpaceGuid.PcdComponentName2Disable|TRUE
- gEfiMdePkgTokenSpaceGuid.PcdDriverDiagnostics2Disable|TRUE
- #
- # Control what commands are supported from the UI
- # Turn these on and off to add features or save size
- #
- gEmbeddedTokenSpaceGuid.PcdEmbeddedMacBoot|TRUE
- gEmbeddedTokenSpaceGuid.PcdEmbeddedDirCmd|TRUE
- gEmbeddedTokenSpaceGuid.PcdEmbeddedHobCmd|TRUE
- gEmbeddedTokenSpaceGuid.PcdEmbeddedHwDebugCmd|TRUE
- gEmbeddedTokenSpaceGuid.PcdEmbeddedPciDebugCmd|TRUE
- gEmbeddedTokenSpaceGuid.PcdEmbeddedIoEnable|FALSE
- gEmbeddedTokenSpaceGuid.PcdEmbeddedScriptCmd|FALSE
- gEmbeddedTokenSpaceGuid.PcdCacheEnable|TRUE
- # Use the Vector Table location in CpuDxe. We will not copy the
Vector Table at PcdCpuVectorBaseAddress
- gArmTokenSpaceGuid.PcdRelocateVectorTable|FALSE
gEmbeddedTokenSpaceGuid.PcdPrePiProduceMemoryTypeInformationHob|TRUE
- gArmTokenSpaceGuid.PcdCpuDxeProduceDebugSupport|FALSE
- gEfiMdeModulePkgTokenSpaceGuid.PcdTurnOffUsbLegacySupport|TRUE
+[PcdsDynamicDefault.common]
- #
- # Set video resolution for boot options and for text setup.
- # PlatformDxe can set the former at runtime.
- #
- gEfiMdeModulePkgTokenSpaceGuid.PcdVideoHorizontalResolution|800
- gEfiMdeModulePkgTokenSpaceGuid.PcdVideoVerticalResolution|600
gEfiMdeModulePkgTokenSpaceGuid.PcdSetupVideoHorizontalResolution|640
- gEfiMdeModulePkgTokenSpaceGuid.PcdSetupVideoVerticalResolution|480
+[PcdsFixedAtBuild.common]
- gEfiMdeModulePkgTokenSpaceGuid.PcdMaxVariableSize|0x2000
- gEfiMdeModulePkgTokenSpaceGuid.PcdMaxAuthVariableSize|0x2800
gEfiMdeModulePkgTokenSpaceGuid.PcdResetOnMemoryTypeInformationChange|FA LSE
- gEfiMdeModulePkgTokenSpaceGuid.PcdBootManagerMenuFile|{ 0x21,
0xaa, 0x2c, 0x46, 0x14, 0x76, 0x03, 0x45, 0x83, 0x6e, 0x8a, 0xb6, 0xf4, 0x66, 0x23, 0x31 }
- gEfiIntelFrameworkModulePkgTokenSpaceGuid.PcdShellFile|{ 0x83,
0xA5, 0x04, 0x7C, 0x3E, 0x9E, 0x1C, 0x4F, 0xAD, 0x65, 0xE0, 0x52, 0x68, 0xD0, 0xB4, 0xD1 }
- gEfiMdePkgTokenSpaceGuid.PcdPlatformBootTimeOut|20
- gArmPlatformTokenSpaceGuid.PcdFirmwareVendor|"LS1043a RDB board"
- gEmbeddedTokenSpaceGuid.PcdEmbeddedPrompt|"LS1043a"
- gArmPlatformTokenSpaceGuid.PcdCoreCount|1 # Only one core
- gArmPlatformTokenSpaceGuid.PcdCounterFrequency|12000000 #12Mhz
- gEfiMdePkgTokenSpaceGuid.PcdMaximumUnicodeStringLength|1000000
- gEfiMdePkgTokenSpaceGuid.PcdMaximumAsciiStringLength|2000000
- gEfiMdePkgTokenSpaceGuid.PcdMaximumLinkedListLength|1000000
- gEfiMdePkgTokenSpaceGuid.PcdSpinLockTimeout|10000000
- gEfiMdePkgTokenSpaceGuid.PcdDebugClearMemoryValue|0xAF
- gEfiMdePkgTokenSpaceGuid.PcdPerformanceLibraryPropertyMask|1
- #gEfiMdePkgTokenSpaceGuid.PcdPerformanceLibraryPropertyMask|0 #
turn off for now
- gEfiMdePkgTokenSpaceGuid.PcdPostCodePropertyMask|0
- gEfiMdePkgTokenSpaceGuid.PcdUefiLibMaxPrintBufferSize|320
+# DEBUG_ASSERT_ENABLED 0x01 +# DEBUG_PRINT_ENABLED 0x02 +# DEBUG_CODE_ENABLED 0x04 +# CLEAR_MEMORY_ENABLED 0x08 +# ASSERT_BREAKPOINT_ENABLED 0x10 +# ASSERT_DEADLOOP_ENABLED 0x20 +!if $(TARGET) == RELEASE
- gEfiMdePkgTokenSpaceGuid.PcdDebugPropertyMask|0x27
- gEfiMdePkgTokenSpaceGuid.PcdDebugPrintErrorLevel|0x81000000
#0x8000000F #Print almost everything
+!else
- gEfiMdePkgTokenSpaceGuid.PcdDebugPropertyMask|0x2F
- gEfiMdePkgTokenSpaceGuid.PcdDebugPrintErrorLevel|0x81000044
#0x8000000F #Print almost everything
+!endif
+# DEBUG_INIT 0x00000001 // Initialization +# DEBUG_WARN 0x00000002 // Warnings +# DEBUG_LOAD 0x00000004 // Load events +# DEBUG_FS 0x00000008 // EFI File system +# DEBUG_POOL 0x00000010 // Alloc & Free's +# DEBUG_PAGE 0x00000020 // Alloc & Free's +# DEBUG_INFO 0x00000040 // Verbose +# DEBUG_DISPATCH 0x00000080 // PEI/DXE Dispatchers +# DEBUG_VARIABLE 0x00000100 // Variable +# DEBUG_BM 0x00000400 // Boot Manager +# DEBUG_BLKIO 0x00001000 // BlkIo Driver +# DEBUG_NET 0x00004000 // SNI Driver +# DEBUG_UNDI 0x00010000 // UNDI Driver +# DEBUG_LOADFILE 0x00020000 // UNDI Driver +# DEBUG_EVENT 0x00080000 // Event messages +# DEBUG_ERROR 0x80000000 // Error
- gEfiMdePkgTokenSpaceGuid.PcdReportStatusCodePropertyMask|0x07
- gEmbeddedTokenSpaceGuid.PcdEmbeddedAutomaticBootCommand|""
- gEmbeddedTokenSpaceGuid.PcdEmbeddedDefaultTextColor|0x07
- gEmbeddedTokenSpaceGuid.PcdEmbeddedMemVariableStoreSize|0x10000
+# +# Optional feature to help prevent EFI memory map fragments +# Turned on and off via: PcdPrePiProduceMemoryTypeInformationHob +# Values are in EFI Pages (4K). DXE Core will make sure that +# at least this much of each type of memory can be allocated +# from a single memory range. This way you only end up with +# maximum of two fragements for each type in the memory map +# (the memory used, and the free memory that was prereserved +# but not used). +#
- gEmbeddedTokenSpaceGuid.PcdMemoryTypeEfiACPIReclaimMemory|0
- gEmbeddedTokenSpaceGuid.PcdMemoryTypeEfiACPIMemoryNVS|0
- gEmbeddedTokenSpaceGuid.PcdMemoryTypeEfiReservedMemoryType|0
- gEmbeddedTokenSpaceGuid.PcdMemoryTypeEfiRuntimeServicesData|80
- gEmbeddedTokenSpaceGuid.PcdMemoryTypeEfiRuntimeServicesCode|40
- gEmbeddedTokenSpaceGuid.PcdMemoryTypeEfiBootServicesCode|400
- gEmbeddedTokenSpaceGuid.PcdMemoryTypeEfiBootServicesData|3000
- gEmbeddedTokenSpaceGuid.PcdMemoryTypeEfiLoaderCode|10
- gEmbeddedTokenSpaceGuid.PcdMemoryTypeEfiLoaderData|0
- # PCI PCDs
- #
- gArmPlatformTokenSpaceGuid.PcdKludgeMapPciMmioAsCached|FALSE
- gArmPlatformTokenSpaceGuid.PcdPciBusMin|0
- gArmPlatformTokenSpaceGuid.PcdPciBusMax|255
- gArmPlatformTokenSpaceGuid.PcdPciIoBase|0x00010000
- gArmPlatformTokenSpaceGuid.PcdPciIoSize|0x00010000 # 64k
- gArmPlatformTokenSpaceGuid.PcdPciIoTranslation|0x00010000
- gArmPlatformTokenSpaceGuid.PcdPciMmio32Base|0x40000000
- gArmPlatformTokenSpaceGuid.PcdPciMmio32Size|0x40000000 # 128M
- gArmPlatformTokenSpaceGuid.PcdPciMemTranslation|0x5000000000
- gArmPlatformTokenSpaceGuid.PcdPciMmio64Base|0x5040000000
- gArmPlatformTokenSpaceGuid.PcdPciMmio64Size|0x40000000
- gEfiMdePkgTokenSpaceGuid.PcdPci1ExpressBaseAddress|0x5000000000
- gEfiMdePkgTokenSpaceGuid.PcdPci2ExpressBaseAddress|0x4800000000
- gEfiMdePkgTokenSpaceGuid.PcdPci3ExpressBaseAddress|0x5000000000
- ## Serial Terminal
- gEfiMdeModulePkgTokenSpaceGuid.PcdSerialRegisterBase|0x21c0500
- gEfiMdePkgTokenSpaceGuid.PcdUartDefaultBaudRate|115200
- gEfiMdePkgTokenSpaceGuid.PcdDefaultTerminalType|4
- #
- # ARM General Interrupt Controller
- gArmTokenSpaceGuid.PcdGicDistributorBase|0x1401000
- gArmTokenSpaceGuid.PcdGicInterruptInterfaceBase|0x1402000
- #
- # LS1043a board Specific PCDs
- # XX (DRAM - Region 1 2GB)
- # (NOR - IFC Region 1 512MB)
- gArmTokenSpaceGuid.PcdSystemMemoryBase|0x80000000
- gArmTokenSpaceGuid.PcdSystemMemorySize|0x80000000
- #
- # LS1043a Soc Specific PCDs
- #
- gArmPlatformTokenSpaceGuid.PcdCounterFrequencyReal|TRUE
- gArmPlatformTokenSpaceGuid.PcdCsuInitialize|TRUE
- gArmPlatformTokenSpaceGuid.PcdTzc380Initialize|TRUE
- gArmPlatformTokenSpaceGuid.PcdCci400Initialize|TRUE
- gArmPlatformTokenSpaceGuid.PcdClockInitialize|TRUE
- #
- # PPA specific PCDs
- #
- gNxpQoriqLsTokenSpaceGuid.PcdPpaNorBaseAddr|0x60500000
- gNxpQoriqLsTokenSpaceGuid.PcdPpaDdrOffsetAddr|0x8000000 # (128MB)
calculated from top of DDR
- # Size of the region used by UEFI in permanent memory (Reserved
16MB)
gArmPlatformTokenSpaceGuid.PcdSystemMemoryUefiRegionSize|0x01000000
- # Size of the region reserved for fixed address allocations
(Reserved 32MB)
- gArmTokenSpaceGuid.PcdArmLinuxKernelMaxOffset|0x08000000
- gArmTokenSpaceGuid.PcdArmLinuxFdtMaxOffset|0x08000000
- gArmTokenSpaceGuid.PcdArmLinuxFdtAlignment|0x0
- gArmTokenSpaceGuid.PcdCpuVectorBaseAddress|0x94A00000
- gArmTokenSpaceGuid.PcdCpuResetAddress|0x94A00000
- # Timer
- gArmTokenSpaceGuid.PcdArmArchTimerFreqInHz|0
- gEmbeddedTokenSpaceGuid.PcdTimerPeriod|10000 # expressed in 100ns
units, 100,000 x 100 ns = 10,000,000 ns = 10 ms
- gArmPlatformTokenSpaceGuid.PcdArmArchTimerVirtIntrNum|11 # Virtual
PPI
- gArmPlatformTokenSpaceGuid.PcdArmArchTimerHypIntrNum|10 #
Hypervisor PPI
- gArmPlatformTokenSpaceGuid.PcdArmArchTimerSecIntrNum|13 # Physical
Secure PPI
- gArmPlatformTokenSpaceGuid.PcdArmArchTimerIntrNum|14 # Physical
Non-Secure PPI
- gEmbeddedTokenSpaceGuid.PcdMetronomeTickPeriod|1000
#gEmbeddedTokenSpaceGuid.PcdEmbeddedPerformanceCounterPeriodInNanosecon ds|77
#gEmbeddedTokenSpaceGuid.PcdEmbeddedPerformanceCounterFrequencyInHz|130 00000
- # We want to use the Shell Libraries but don't want it to
initialise
- # automatically. We initialise the libraries when the command is
called by the
- # Shell.
- gEfiShellPkgTokenSpaceGuid.PcdShellLibAutoInitialize|FALSE
- #
- # ARM Pcds
- #
- gArmTokenSpaceGuid.PcdArmUncachedMemoryMask|0x0000000040000000
- gArmPlatformTokenSpaceGuid.PcdDefaultBootDescription|L"EFI Linux
from NOR flash"
gArmPlatformTokenSpaceGuid.PcdDefaultBootDevicePath|L"MemoryMapped(0x0, 0x61100000,0x6111FFFF)"
gEmbeddedTokenSpaceGuid.PcdFdtDevicePaths|L"MemoryMapped(0x0,0x61B00000 ,0x61BFFFFF)/fsl-ls1043a-uefi-rdb.dtb"
gArmPlatformTokenSpaceGuid.PcdDefaultBootArgument|L"MemoryMapped(0x0,0x 61120000,0x61AFFFFF) -d "MemoryMapped(0x0,0x61B00000,0x61BFFFFF)" -f "MemoryMapped(0x0,0x61C00000,0x638FFFFF)" -c "console=ttyS0,115200 root=/dev/ram0 earlycon=uart8250,0x21c0500,115200""
- # PPA
- gLS1043aRdbTokenSpaceGuid.PcdPpaFitConfiguration|"config@1"
- # Use the serial console for both ConIn & ConOut
- gArmPlatformTokenSpaceGuid.PcdDefaultConOutPaths|L"VenHw(D3987D4B-
971A-435F-8CAF-4967EB627241)/Uart(115200,8,N,1)/VenPcAnsi();"
- gArmPlatformTokenSpaceGuid.PcdDefaultConInPaths|L"VenHw(D3987D4B-
971A-435F-8CAF-4967EB627241)/Uart(115200,8,N,1)/VenPcAnsi()"
- gEfiShellPkgTokenSpaceGuid.PcdShellLibAutoInitialize|FALSE
- gEfiMdePkgTokenSpaceGuid.PcdUefiLibMaxPrintBufferSize|16000
+!ifdef $(NO_SHELL_PROFILES)
- gEfiShellPkgTokenSpaceGuid.PcdShellProfileMask|0x00
+!endif #$(NO_SHELL_PROFILES)
- gNxpQoriqLsTokenSpaceGuid.PcdFdNorBaseAddress|0x60400000
- gNxpQoriqLsTokenSpaceGuid.PcdOcramStackBase|0x10010000
- gNxpQoriqLsTokenSpaceGuid.PcdI2cBus|0
- gNxpQoriqLsTokenSpaceGuid.PcdI2cSpeed|10000
- gNxpQoriqLsTokenSpaceGuid.PcdRtcI2cBus|0
- gNxpQoriqLsTokenSpaceGuid.PcdDs1307I2cAddress|0x68
+###################################################################### ##########
+# +# Components Section - list of all EDK II Modules needed by this
Platform
+#
+###################################################################### ##########
+[Components.common]
- #
- # SEC
- #
- OpenPlatformPkg/Chips/Nxp/QoriqLs/Library/PrePiNor/PrePiNor.inf
- ArmPlatformPkg/PrePi/PeiUniCore.inf
- #
- # DXE
- #
- MdeModulePkg/Core/Dxe/DxeMain.inf {
<LibraryClasses>
PcdLib|MdePkg/Library/BasePcdLibNull/BasePcdLibNull.inf
NULL|MdeModulePkg/Library/DxeCrc32GuidedSectionExtractLib/DxeCrc32Guide dSectionExtractLib.inf
NULL|EmbeddedPkg/Library/LzmaHobCustomDecompressLib/LzmaHobCustomDecomp ressLib.inf
- }
- MdeModulePkg/Universal/PCD/Dxe/Pcd.inf {
<LibraryClasses>
PcdLib|MdePkg/Library/BasePcdLibNull/BasePcdLibNull.inf
- }
- #
- # Architectural Protocols
- #
- ArmPkg/Drivers/CpuDxe/CpuDxe.inf
- MdeModulePkg/Core/RuntimeDxe/RuntimeDxe.inf
- MdeModulePkg/Universal/SecurityStubDxe/SecurityStubDxe.inf
- MdeModulePkg/Universal/CapsuleRuntimeDxe/CapsuleRuntimeDxe.inf
MdeModulePkg/Universal/Variable/EmuRuntimeDxe/EmuVariableRuntimeDxe.inf
- EmbeddedPkg/EmbeddedMonotonicCounter/EmbeddedMonotonicCounter.inf
- # FDT installation
- EmbeddedPkg/Drivers/FdtPlatformDxe/FdtPlatformDxe.inf
- MdeModulePkg/Universal/Console/ConPlatformDxe/ConPlatformDxe.inf
- MdeModulePkg/Universal/Console/ConSplitterDxe/ConSplitterDxe.inf
MdeModulePkg/Universal/Console/GraphicsConsoleDxe/GraphicsConsoleDxe.in f
- MdeModulePkg/Universal/Console/TerminalDxe/TerminalDxe.inf
- MdeModulePkg/Universal/SerialDxe/SerialDxe.inf
- MdeModulePkg/Universal/Acpi/AcpiTableDxe/AcpiTableDxe.inf
- EmbeddedPkg/ResetRuntimeDxe/ResetRuntimeDxe.inf
- EmbeddedPkg/RealTimeClockRuntimeDxe/RealTimeClockRuntimeDxe.inf
- EmbeddedPkg/MetronomeDxe/MetronomeDxe.inf
- ArmPkg/Drivers/TimerDxe/TimerDxe.inf
OpenPlatformPkg/Platforms/Nxp/LS1043aRdb/LS1043aWatchDog/LS1043aWatchDo gDxe.inf
- ArmPkg/Drivers/ArmGic/ArmGicDxe.inf
- EmbeddedPkg/SimpleTextInOutSerial/SimpleTextInOutSerial.inf
- #
- # PPA
- #
- OpenPlatformPkg/Chips/Nxp/QoriqLs/PpaInitDxe/PpaInitDxe.inf
- #
- # FAT filesystem + GPT/MBR partitioning
- #
MdeModulePkg/Universal/Disk/UnicodeCollation/EnglishDxe/EnglishDxe.inf
- #
- # I2C
- #
- OpenPlatformPkg/Chips/Nxp/QoriqLs/I2c/I2cDxe.inf
- #
- # Bds
- #
- MdeModulePkg/Universal/DevicePathDxe/DevicePathDxe.inf
- MdeModulePkg/Universal/DisplayEngineDxe/DisplayEngineDxe.inf
- MdeModulePkg/Universal/SetupBrowserDxe/SetupBrowserDxe.inf
- MdeModulePkg/Universal/BdsDxe/BdsDxe.inf
- MdeModulePkg/Application/UiApp/UiApp.inf {
<LibraryClasses>
NULL|MdeModulePkg/Library/DeviceManagerUiLib/DeviceManagerUiLib.inf
NULL|MdeModulePkg/Library/BootManagerUiLib/BootManagerUiLib.inf
NULL|MdeModulePkg/Library/BootMaintenanceManagerUiLib/BootMaintenanceMa nagerUiLib.inf
- }
- MdeModulePkg/Universal/HiiDatabaseDxe/HiiDatabaseDxe.inf
- #
- # Example Application
- #
- MdeModulePkg/Application/HelloWorld/HelloWorld.inf
- ShellPkg/Library/UefiShellLib/UefiShellLib.inf
- ShellPkg/Library/UefiShellCommandLib/UefiShellCommandLib.inf
ShellPkg/Library/UefiShellLevel2CommandsLib/UefiShellLevel2CommandsLib. inf
- ShellPkg/Library/UefiHandleParsingLib/UefiHandleParsingLib.inf
- ShellPkg/Library/UefiDpLib/UefiDpLib.inf {
<LibraryClasses>
TimerLib|MdePkg/Library/BaseTimerLibNullTemplate/BaseTimerLibNullTempla te.inf
PerformanceLib|MdePkg/Library/BasePerformanceLibNull/BasePerformanceLib Null.inf
DxeServicesLib|MdePkg/Library/DxeServicesLib/DxeServicesLib.inf
- }
+ShellPkg/Application/Shell/Shell.inf {
<LibraryClasses>
NULL|ShellPkg/Library/UefiShellLevel2CommandsLib/UefiShellLevel2Command sLib.inf
NULL|ShellPkg/Library/UefiShellLevel1CommandsLib/UefiShellLevel1Command sLib.inf
NULL|ShellPkg/Library/UefiShellLevel3CommandsLib/UefiShellLevel3Command sLib.inf
+!ifndef $(NO_SHELL_PROFILES)
NULL|ShellPkg/Library/UefiShellDriver1CommandsLib/UefiShellDriver1Comma ndsLib.inf
NULL|ShellPkg/Library/UefiShellInstall1CommandsLib/UefiShellInstall1Com mandsLib.inf
NULL|ShellPkg/Library/UefiShellDebug1CommandsLib/UefiShellDebug1Command sLib.inf
NULL|ShellPkg/Library/UefiShellNetwork1CommandsLib/UefiShellNetwork1Com mandsLib.inf
NULL|ShellPkg/Library/UefiShellTftpCommandLib/UefiShellTftpCommandLib.i nf
+!ifdef $(INCLUDE_DP)
NULL|ShellPkg/Library/UefiDpLib/UefiDpLib.inf
+!endif #$(INCLUDE_DP) +!ifdef $(INCLUDE_TFTP_COMMAND)
NULL|ShellPkg/Library/UefiShellTftpCommandLib/UefiShellTftpCommandLib.i nf
+!endif #$(INCLUDE_TFTP_COMMAND) +!endif #$(NO_SHELL_PROFILES)
}
- ##
diff --git a/Platforms/Nxp/LS1043aRdb/LS1043aRdbPkg.fdf
b/Platforms/Nxp/LS1043aRdb/LS1043aRdbPkg.fdf
new file mode 100644 index 0000000..1633630 --- /dev/null +++ b/Platforms/Nxp/LS1043aRdb/LS1043aRdbPkg.fdf @@ -0,0 +1,311 @@ +# FLASH layout file for LS1043a board. +# +# Copyright (c) 2016, Freescale Ltd. All rights reserved. +# +# This program and the accompanying materials +# are licensed and made available under the terms and conditions
of the BSD License
+# which accompanies this distribution. The full text of the
license may be found at
+# http://opensource.org/licenses/bsd-license.php +# +# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS"
BASIS,
+# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER
EXPRESS OR IMPLIED.
+#
+###################################################################### ##########
+# +# FD Section +# The [FD] Section is made up of the definition statements and a +# description of what goes into the Flash Device Image. Each FD
section
+# defines one flash "device" image. A flash device image may be one
of
+# the following: Removable media bootable image (like a boot floppy +# image,) an Option ROM image (that would be "flashed" into an add-
in
+# card,) a System "Flash" image (that would be burned into a
system's
+# flash) or an Update ("Capsule") image that will be used to update
and
+# existing system flash. +#
+###################################################################### ##########
+[FD.LS1043aRdb_EFI] +BaseAddress = 0xE0000000|gArmTokenSpaceGuid.PcdFdBaseAddress #The
base address of the FLASH Device.
+Size = 0x000C8000|gArmTokenSpaceGuid.PcdFdSize #The
size in bytes of the FLASH Device
+ErasePolarity = 1 +BlockSize = 0x1 +NumBlocks = 0xC8000
+###################################################################### ##########
+# +# Following are lists of FD Region layout which correspond to the
locations of different
+# images within the flash device. +# +# Regions must be defined in ascending order and may not overlap. +# +# A Layout Region start with a eight digit hex offset (leading "0x"
required) followed by
+# the pipe "|" character, followed by the size of the region, also
in hex with the leading
+# "0x" characters. Like: +# Offset|Size +# PcdOffsetCName|PcdSizeCName +# RegionType <FV, DATA, or FILE> +#
+###################################################################### ##########
+0x00000000|0x000C8000 +gArmTokenSpaceGuid.PcdFvBaseAddress|gArmTokenSpaceGuid.PcdFvSize +FV = FVMAIN_COMPACT
+[FD.LS1043aRdbPi_EFI] +BaseAddress =
0x60400000|gNxpQoriqLsTokenSpaceGuid.PcdPiFdBaseAddress #The base address of the FLASH Device.
+Size = 0x00008000|gNxpQoriqLsTokenSpaceGuid.PcdPiFdSize
#The size in bytes of the FLASH Device
+ErasePolarity = 1 +BlockSize = 0x1 +NumBlocks = 0x8000
+0x00000000|0x00008000
+gNxpQoriqLsTokenSpaceGuid.PcdFvNorBaseAddress|gNxpQoriqLsTokenSpaceGui d.PcdFvNorSize
+FV = FVNOR_COMPACT
+###################################################################### ##########
+# +# FV Section +# +# [FV] section is used to define what components or modules are
placed within a flash
+# device file. This section also defines order the components and
modules are positioned
+# within the image. The [FV] section consists of define statements,
set statements and
+# module statements. +#
+###################################################################### ##########
+[FV.FvMain] +BlockSize = 0x1 +NumBlocks = 0 # This FV gets compressed so make it
just big enough
+FvAlignment = 8 # FV alignment and FV attributes
setting.
+ERASE_POLARITY = 1 +MEMORY_MAPPED = TRUE +STICKY_WRITE = TRUE +LOCK_CAP = TRUE +LOCK_STATUS = TRUE +WRITE_DISABLED_CAP = TRUE +WRITE_ENABLED_CAP = TRUE +WRITE_STATUS = TRUE +WRITE_LOCK_CAP = TRUE +WRITE_LOCK_STATUS = TRUE +READ_DISABLED_CAP = TRUE +READ_ENABLED_CAP = TRUE +READ_STATUS = TRUE +READ_LOCK_CAP = TRUE +READ_LOCK_STATUS = TRUE
- INF MdeModulePkg/Core/Dxe/DxeMain.inf
- INF MdeModulePkg/Universal/PCD/Dxe/Pcd.inf
- INF OpenPlatformPkg/Chips/Nxp/QoriqLs/PpaInitDxe/PpaInitDxe.inf
- #
- # PI DXE Drivers producing Architectural Protocols (EFI Services)
- #
- INF ArmPkg/Drivers/CpuDxe/CpuDxe.inf
- INF MdeModulePkg/Core/RuntimeDxe/RuntimeDxe.inf
- INF ArmPkg/Drivers/ArmGic/ArmGicDxe.inf
- INF ArmPkg/Drivers/TimerDxe/TimerDxe.inf
- INF
OpenPlatformPkg/Platforms/Nxp/LS1043aRdb/LS1043aWatchDog/LS1043aWatchDo gDxe.inf
- INF MdeModulePkg/Universal/SecurityStubDxe/SecurityStubDxe.inf
- INF MdeModulePkg/Universal/CapsuleRuntimeDxe/CapsuleRuntimeDxe.inf
- INF MdeModulePkg/Universal/HiiDatabaseDxe/HiiDatabaseDxe.inf
- INF
EmbeddedPkg/EmbeddedMonotonicCounter/EmbeddedMonotonicCounter.inf
- INF
MdeModulePkg/Universal/Variable/EmuRuntimeDxe/EmuVariableRuntimeDxe.inf
- #
- # Multiple Console IO support
- #
- INF
MdeModulePkg/Universal/Console/ConPlatformDxe/ConPlatformDxe.inf
- INF
MdeModulePkg/Universal/Console/ConSplitterDxe/ConSplitterDxe.inf
- INF
MdeModulePkg/Universal/Console/GraphicsConsoleDxe/GraphicsConsoleDxe.in f
- INF MdeModulePkg/Universal/SerialDxe/SerialDxe.inf
- INF MdeModulePkg/Universal/Console/TerminalDxe/TerminalDxe.inf
- INF EmbeddedPkg/ResetRuntimeDxe/ResetRuntimeDxe.inf
- INF
EmbeddedPkg/RealTimeClockRuntimeDxe/RealTimeClockRuntimeDxe.inf
- INF EmbeddedPkg/MetronomeDxe/MetronomeDxe.inf
- INF EmbeddedPkg/SimpleTextInOutSerial/SimpleTextInOutSerial.inf
- #
- # I2C
- #
- INF OpenPlatformPkg/Chips/Nxp/QoriqLs/I2c/I2cDxe.inf
- #
- # FAT filesystem + GPT/MBR partitioning
- #
- INF
MdeModulePkg/Universal/Disk/UnicodeCollation/EnglishDxe/EnglishDxe.inf
- #
- # UEFI application (Shell Embedded Boot Loader)
- #
- INF ShellPkg/Application/Shell/Shell.inf
- #INF ShellBinPkg/UefiShell/UefiShell.inf
- #
- # Bds
- #
- INF MdeModulePkg/Universal/DevicePathDxe/DevicePathDxe.inf
- INF MdeModulePkg/Universal/DisplayEngineDxe/DisplayEngineDxe.inf
- INF MdeModulePkg/Universal/SetupBrowserDxe/SetupBrowserDxe.inf
- INF MdeModulePkg/Universal/BdsDxe/BdsDxe.inf
- INF MdeModulePkg/Application/UiApp/UiApp.inf
- #
- # FDT installation
- #
- # The UEFI driver is at the end of the list of the driver to be
dispatched
- # after the device drivers (eg: Ethernet) to ensure we have
support for them.
+[FV.FVNOR_COMPACT] +FvAlignment = 8 +ERASE_POLARITY = 1 +MEMORY_MAPPED = TRUE +STICKY_WRITE = TRUE +LOCK_CAP = TRUE +LOCK_STATUS = TRUE +WRITE_DISABLED_CAP = TRUE +WRITE_ENABLED_CAP = TRUE +WRITE_STATUS = TRUE +WRITE_LOCK_CAP = TRUE +WRITE_LOCK_STATUS = TRUE +READ_DISABLED_CAP = TRUE +READ_ENABLED_CAP = TRUE +READ_STATUS = TRUE +READ_LOCK_CAP = TRUE +READ_LOCK_STATUS = TRUE
- INF
OpenPlatformPkg/Chips/Nxp/QoriqLs/Library/PrePiNor/PrePiNor.inf
+[FV.FVMAIN_COMPACT] +FvAlignment = 8 +ERASE_POLARITY = 1 +MEMORY_MAPPED = TRUE +STICKY_WRITE = TRUE +LOCK_CAP = TRUE +LOCK_STATUS = TRUE +WRITE_DISABLED_CAP = TRUE +WRITE_ENABLED_CAP = TRUE +WRITE_STATUS = TRUE +WRITE_LOCK_CAP = TRUE +WRITE_LOCK_STATUS = TRUE +READ_DISABLED_CAP = TRUE +READ_ENABLED_CAP = TRUE +READ_STATUS = TRUE +READ_LOCK_CAP = TRUE +READ_LOCK_STATUS = TRUE
- INF ArmPlatformPkg/PrePi/PeiUniCore.inf
- FILE FV_IMAGE = 9E21FD93-9C72-4c15-8C4B-E77F1DB2D792 {
- SECTION GUIDED EE4E5898-3914-4259-9D6E-DC7BD79403CF
PROCESSING_REQUIRED = TRUE {
SECTION FV_IMAGE = FVMAIN
- }
- }
+###################################################################### ##########
+# +# Rules are use with the [FV] section's module INF type to define +# how an FFS file is created for a given INF file. The following
Rule are the default
+# rules for the different module type. User can add the customized
rules to define the
+# content of the FFS file. +#
+###################################################################### ##########
+###################################################################### ######
+# Example of a DXE_DRIVER FFS file with a Checksum encapsulation
section #
+###################################################################### ######
+# +#[Rule.Common.DXE_DRIVER] +# FILE DRIVER = $(NAMED_GUID) { +# DXE_DEPEX DXE_DEPEX Optional
$(INF_OUTPUT)/$(MODULE_NAME).depex
+# COMPRESS PI_STD { +# GUIDED { +# PE32 PE32
$(INF_OUTPUT)/$(MODULE_NAME).efi
+# UI STRING="$(MODULE_NAME)" Optional +# VERSION STRING="$(INF_VERSION)" Optional
BUILD_NUM=$(BUILD_NUMBER)
+# } +# } +# } +#
+###################################################################### ######
+[Rule.Common.SEC]
- FILE SEC = $(NAMED_GUID) RELOCS_STRIPPED {
- TE TE Align = 32
$(INF_OUTPUT)/$(MODULE_NAME).efi
- }
+[Rule.Common.PEI_CORE]
- FILE PEI_CORE = $(NAMED_GUID) {
- TE TE
$(INF_OUTPUT)/$(MODULE_NAME).efi
- UI STRING ="$(MODULE_NAME)" Optional
- }
+[Rule.Common.PEIM]
- FILE PEIM = $(NAMED_GUID) {
PEI_DEPEX PEI_DEPEX Optional
$(INF_OUTPUT)/$(MODULE_NAME).depex
PE32 PE32
$(INF_OUTPUT)/$(MODULE_NAME).efi
UI STRING="$(MODULE_NAME)" Optional
- }
+[Rule.Common.PEIM.TIANOCOMPRESSED]
- FILE PEIM = $(NAMED_GUID) DEBUG_MYTOOLS_IA32 {
- PEI_DEPEX PEI_DEPEX Optional
$(INF_OUTPUT)/$(MODULE_NAME).depex
- GUIDED A31280AD-481E-41B6-95E8-127F4C984779 PROCESSING_REQUIRED
= TRUE {
PE32 PE32
$(INF_OUTPUT)/$(MODULE_NAME).efi
UI STRING="$(MODULE_NAME)" Optional
- }
- }
+[Rule.Common.DXE_CORE]
- FILE DXE_CORE = $(NAMED_GUID) {
- PE32 PE32
$(INF_OUTPUT)/$(MODULE_NAME).efi
- UI STRING="$(MODULE_NAME)" Optional
- }
+[Rule.Common.UEFI_DRIVER]
- FILE DRIVER = $(NAMED_GUID) {
- DXE_DEPEX DXE_DEPEX Optional
$(INF_OUTPUT)/$(MODULE_NAME).depex
- PE32 PE32
$(INF_OUTPUT)/$(MODULE_NAME).efi
- UI STRING="$(MODULE_NAME)" Optional
- }
+[Rule.Common.DXE_DRIVER]
- FILE DRIVER = $(NAMED_GUID) {
- DXE_DEPEX DXE_DEPEX Optional
$(INF_OUTPUT)/$(MODULE_NAME).depex
- PE32 PE32
$(INF_OUTPUT)/$(MODULE_NAME).efi
- UI STRING="$(MODULE_NAME)" Optional
- }
+[Rule.Common.DXE_RUNTIME_DRIVER]
- FILE DRIVER = $(NAMED_GUID) {
- DXE_DEPEX DXE_DEPEX Optional
$(INF_OUTPUT)/$(MODULE_NAME).depex
- PE32 PE32
$(INF_OUTPUT)/$(MODULE_NAME).efi
- UI STRING="$(MODULE_NAME)" Optional
- }
+[Rule.Common.UEFI_APPLICATION]
- FILE APPLICATION = $(NAMED_GUID) {
- UI STRING ="$(MODULE_NAME)" Optional
- PE32 PE32
$(INF_OUTPUT)/$(MODULE_NAME).efi
- }
+[Rule.Common.UEFI_DRIVER.BINARY]
- FILE DRIVER = $(NAMED_GUID) {
- DXE_DEPEX DXE_DEPEX Optional |.depex
- PE32 PE32 |.efi
- UI STRING="$(MODULE_NAME)" Optional
- VERSION STRING="$(INF_VERSION)" Optional
BUILD_NUM=$(BUILD_NUMBER)
- }
+[Rule.Common.UEFI_APPLICATION.BINARY]
- FILE APPLICATION = $(NAMED_GUID) {
- PE32 PE32 |.efi
- UI STRING="$(MODULE_NAME)" Optional
- VERSION STRING="$(INF_VERSION)" Optional
BUILD_NUM=$(BUILD_NUMBER)
- }
diff --git a/Platforms/Nxp/LS1043aRdb/build.sh
b/Platforms/Nxp/LS1043aRdb/build.sh
new file mode 100755 index 0000000..4012a78 --- /dev/null +++ b/Platforms/Nxp/LS1043aRdb/build.sh
I would very much prefer not to merge these last two files. But I would be happy to add an entry for LS1043A to the default config in my uefi-tools set of helper scripts.
Ok, so I will send a patch to update the default config in uefi-tools.
Regards, Bhupesh
/ Leif
@@ -0,0 +1,72 @@ +#!/bin/bash
+# UEFI build script for LS1043A SoC from Freescale +# +# Copyright (c) 2016, Freescale Semiconductor, Inc. All rights
reserved.
+# +# This program and the accompanying materials +# are licensed and made available under the terms and conditions of
the BSD License
+# which accompanies this distribution. The full text of the license
may be found at
+# http://opensource.org/licenses/bsd-license.php +# +# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS"
BASIS,
+# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS
OR IMPLIED.
+#
+print_usage_banner() +{
- echo "This shell script expects:"
- echo " Arg 1 (mandatory): Build candidate (can be RELEASE or
DEBUG). By
default we build the RELEASE candidate."
- echo " Arg 2 (optional): clean - To do a 'make clean'
operation."
+}
+# Actual stuff starts from here +echo ".........................................." +echo "Welcome to LS1043A UEFI Build environment" +echo ".........................................."
+# Check for input arguments +if [[ $1 == "" ]]; then
- echo "Error ! No build target specified."
- print_usage_banner
- exit
+fi
+# Check for input arguments +if [[ $1 != "RELEASE" ]]; then
- if [[ $1 != "DEBUG" ]]; then
echo "Error ! Incorrect build target specified."
print_usage_banner
exit
- fi
+fi
+if [[ $2 == "clean" ]]; then
- echo "Cleaning up the build directory
'../../../../Build/LS1043aRdb/'.."
- rm -rf ../../../../Build/LS1043aRdb/*
- exit
+fi
+# Clean-up +set -e +shopt -s nocasematch
+# +# Setup workspace now +# +echo Initializing workspace +cd ../../../../
+# Use the BaseTools in edk2 +export EDK_TOOLS_PATH=`pwd`/BaseTools +source edksetup.sh BaseTools
+# Global Defaults +ARCH=AARCH64 +TARGET_TOOLS=GCC49
+build -p
"$WORKSPACE/OpenPlatformPkg/Platforms/Nxp/LS1043aRdb/LS1043aRdbPkg.dsc" -a $ARCH -t $TARGET_TOOLS -b $1
+cat $WORKSPACE/Build/LS1043aRdb/$1_GCC49/FV/LS1043ARDB_EFI.fd >>
$WORKSPACE/Build/LS1043aRdb/$1_GCC49/FV/LS1043ARDBPI_EFI.fd
+mv $WORKSPACE/Build/LS1043aRdb/$1_GCC49/FV/LS1043ARDBPI_EFI.fd
$WORKSPACE/Build/LS1043aRdb/$1_GCC49/FV/LS1043ARDB_EFI.fd
diff --git a/Platforms/Nxp/LS1043aRdb/ls1043a_env.cshrc
b/Platforms/Nxp/LS1043aRdb/ls1043a_env.cshrc
new file mode 100644 index 0000000..63d702e --- /dev/null +++ b/Platforms/Nxp/LS1043aRdb/ls1043a_env.cshrc @@ -0,0 +1,2 @@ +export GCC49_AARCH64_PREFIX='aarch64-linux-gnu-'
+unset ARCH
1.9.1
Hi Bhupesh,
Many thanks for this contribution. Couple of overall questions (before I start digging into the code):
On Tue, Oct 18, 2016 at 01:33:59AM +0530, Bhupesh Sharma wrote:
From: Bhupesh Sharma bhupesh.sharma@nxp.com
This patchset adds the support for NXP/FSL's LS1043A RDB platform.
The LS1043A RDB platform houses the 4-A53 core LS1043A SoC from NXP/FSL. Details about the LS1043A SoC and RDB board can be seen here:
SoC:
http://www.nxp.com/products/microcontrollers-and-processors/arm-processors/ qoriq-arm-processors/qoriq-ls1043a-and-ls1023a-multicore-communications-processors:LS1043A?lang_cd=en
RDB board:
http://www.nxp.com/products/microcontrollers-and-processors/arm-processors/ qoriq-arm-processors/qoriq-ls1043a-reference-design-board:LS1043A-RDB#pspFeatures
UEFI firmware boot-flow on the NXP/FSL ARMv8 SoCs is different from the usual ATF (which runs in EL3) and UEFI (which runs entirely in EL2 mode) flow:
NXP/FSL ARMv8 SoCs currently use a EL3 platform and run-time security firmware which is called PPA (Primary Protected Application).
This firmware is placed on the flash device and is loaded into DDR and executed via a UEFI DXE driver. PPA does the initial platform EL3 settings and then returns the control back to UEFI in EL2 exception level.
OK, this sounds a bit funky, but I'll get to that when I look at the code. If there's enough TODO/FIXME in there, I probably won't mind :)
Is it still implementing PSCI?
Later implementations of PPA will allow it to start by itself in the EL3 level and start UEFI in EL2 exception level.
Yes, that sounds ideal.
This patchset is rebased against the OpenPlatformPkg git tree (master branch).
Sakar Arora (14): Platforms/NXP: Add intial support for LS1043A RDB Board Platforms/NXP: Add support for DDR Controller initialization Platforms/NXP: Add support for CPLD controller access Platforms/NXP: Add initial support for LS1043a SOC Library Chips/NXP: Add support for DUART library
Wow, I think I'm nearing the 20 year anniversary of my first DUART code. :)
Thanks!
/ Leif
Platforms/NXP: Add support for initialization of peripherals on LS1043A Platforms/NXP: Add support for system reset library Chips/NXP: Add PrePi initialization module that runs from XIP source Chips/NXP: Add I2C operations library Chips/NXP: Add I2C master driver based on I2C library Chips/NXP: Add support for execution of PPA for EL3 initialization Chips/NXP: Add support for DS1307 RTC library Platforms/NXP: Add support for Watchdog driver (LS1043A) Platforms/NXP: Add the fdf, dsc and dec files for LS1043aRdbPkg build
Chips/Nxp/QoriqLs/I2c/I2cDxe.c | 156 ++++ Chips/Nxp/QoriqLs/I2c/I2cDxe.inf | 52 ++ Chips/Nxp/QoriqLs/Include/Library/DUart.h | 133 ++++ Chips/Nxp/QoriqLs/Include/Library/I2c.h | 199 +++++ .../QoriqLs/Library/DUartPortLib/DUartPortLib.c | 321 ++++++++ .../QoriqLs/Library/DUartPortLib/DUartPortLib.inf | 43 ++ .../QoriqLs/Library/Ds1307RtcLib/Ds1307RtcLib.c | 250 +++++++ .../QoriqLs/Library/Ds1307RtcLib/Ds1307RtcLib.inf | 44 ++ Chips/Nxp/QoriqLs/Library/I2cLib/I2cLib.c | 513 +++++++++++++ Chips/Nxp/QoriqLs/Library/I2cLib/I2cLib.inf | 41 ++ .../Library/PrePiNor/AArch64/ModuleEntryPoint.S | 34 + Chips/Nxp/QoriqLs/Library/PrePiNor/PrePiNor.c | 52 ++ Chips/Nxp/QoriqLs/Library/PrePiNor/PrePiNor.inf | 48 ++ Chips/Nxp/QoriqLs/NxpQoriqLs.dec | 50 ++ Chips/Nxp/QoriqLs/PpaInitDxe/PpaInit.c | 117 +++ Chips/Nxp/QoriqLs/PpaInitDxe/PpaInitDxe.inf | 63 ++ Chips/Nxp/QoriqLs/PpaInitDxe/PpaInitHelper.S | 79 ++ Chips/Nxp/QoriqLs/PpaInitDxe/PpaItbParse.c | 144 ++++ Chips/Nxp/QoriqLs/PpaInitDxe/PpaItbParse.h | 52 ++ Platforms/Nxp/LS1043aRdb/Include/Library/Common.h | 68 ++ Platforms/Nxp/LS1043aRdb/Include/Library/CpldLib.h | 75 ++ Platforms/Nxp/LS1043aRdb/Include/Library/Ddr.h | 190 +++++ Platforms/Nxp/LS1043aRdb/Include/Library/FslIfc.h | 721 ++++++++++++++++++ .../Nxp/LS1043aRdb/Include/Library/Ls1043aSerDes.h | 89 +++ .../Nxp/LS1043aRdb/Include/Library/PlatformLib.h | 179 +++++ Platforms/Nxp/LS1043aRdb/Include/Library/SocLib.h | 509 +++++++++++++ Platforms/Nxp/LS1043aRdb/LS1043aRdbPkg.dec | 166 +++++ Platforms/Nxp/LS1043aRdb/LS1043aRdbPkg.dsc | 602 +++++++++++++++ Platforms/Nxp/LS1043aRdb/LS1043aRdbPkg.fdf | 311 ++++++++ .../LS1043aRdb/LS1043aWatchDog/LS1043aWatchDog.c | 355 +++++++++ .../LS1043aWatchDog/LS1043aWatchDogDxe.inf | 54 ++ Platforms/Nxp/LS1043aRdb/Library/CpldLib/CpldLib.c | 157 ++++ .../Nxp/LS1043aRdb/Library/CpldLib/CpldLib.inf | 33 + Platforms/Nxp/LS1043aRdb/Library/DdrLib/DdrLib.c | 188 +++++ Platforms/Nxp/LS1043aRdb/Library/DdrLib/DdrLib.inf | 41 ++ .../Nxp/LS1043aRdb/Library/LS1043aRdbLib/Common.c | 103 +++ .../LS1043aRdb/Library/LS1043aRdbLib/LS1043aRdb.c | 109 +++ .../Library/LS1043aRdbLib/LS1043aRdbHelper.S | 61 ++ .../Library/LS1043aRdbLib/LS1043aRdbLib.inf | 56 ++ .../Library/LS1043aRdbLib/LS1043aRdbMem.c | 149 ++++ .../Library/LS1043aSocLib/LS1043aSocLib.c | 819 +++++++++++++++++++++ .../Library/LS1043aSocLib/LS1043aSocLib.inf | 53 ++ .../LS1043aRdb/Library/LS1043aSocLib/LsSerDes.c | 195 +++++ .../Library/ResetSystemLib/ResetSystemLib.c | 87 +++ .../Library/ResetSystemLib/ResetSystemLib.inf | 50 ++ Platforms/Nxp/LS1043aRdb/build.sh | 72 ++ Platforms/Nxp/LS1043aRdb/ls1043a_env.cshrc | 2 + 47 files changed, 7885 insertions(+) create mode 100644 Chips/Nxp/QoriqLs/I2c/I2cDxe.c create mode 100644 Chips/Nxp/QoriqLs/I2c/I2cDxe.inf create mode 100644 Chips/Nxp/QoriqLs/Include/Library/DUart.h create mode 100644 Chips/Nxp/QoriqLs/Include/Library/I2c.h create mode 100644 Chips/Nxp/QoriqLs/Library/DUartPortLib/DUartPortLib.c create mode 100644 Chips/Nxp/QoriqLs/Library/DUartPortLib/DUartPortLib.inf create mode 100644 Chips/Nxp/QoriqLs/Library/Ds1307RtcLib/Ds1307RtcLib.c create mode 100644 Chips/Nxp/QoriqLs/Library/Ds1307RtcLib/Ds1307RtcLib.inf create mode 100644 Chips/Nxp/QoriqLs/Library/I2cLib/I2cLib.c create mode 100644 Chips/Nxp/QoriqLs/Library/I2cLib/I2cLib.inf create mode 100644 Chips/Nxp/QoriqLs/Library/PrePiNor/AArch64/ModuleEntryPoint.S create mode 100644 Chips/Nxp/QoriqLs/Library/PrePiNor/PrePiNor.c create mode 100644 Chips/Nxp/QoriqLs/Library/PrePiNor/PrePiNor.inf create mode 100644 Chips/Nxp/QoriqLs/NxpQoriqLs.dec create mode 100644 Chips/Nxp/QoriqLs/PpaInitDxe/PpaInit.c create mode 100644 Chips/Nxp/QoriqLs/PpaInitDxe/PpaInitDxe.inf create mode 100644 Chips/Nxp/QoriqLs/PpaInitDxe/PpaInitHelper.S create mode 100755 Chips/Nxp/QoriqLs/PpaInitDxe/PpaItbParse.c create mode 100755 Chips/Nxp/QoriqLs/PpaInitDxe/PpaItbParse.h create mode 100644 Platforms/Nxp/LS1043aRdb/Include/Library/Common.h create mode 100644 Platforms/Nxp/LS1043aRdb/Include/Library/CpldLib.h create mode 100644 Platforms/Nxp/LS1043aRdb/Include/Library/Ddr.h create mode 100644 Platforms/Nxp/LS1043aRdb/Include/Library/FslIfc.h create mode 100644 Platforms/Nxp/LS1043aRdb/Include/Library/Ls1043aSerDes.h create mode 100644 Platforms/Nxp/LS1043aRdb/Include/Library/PlatformLib.h create mode 100644 Platforms/Nxp/LS1043aRdb/Include/Library/SocLib.h create mode 100644 Platforms/Nxp/LS1043aRdb/LS1043aRdbPkg.dec create mode 100644 Platforms/Nxp/LS1043aRdb/LS1043aRdbPkg.dsc create mode 100644 Platforms/Nxp/LS1043aRdb/LS1043aRdbPkg.fdf create mode 100644 Platforms/Nxp/LS1043aRdb/LS1043aWatchDog/LS1043aWatchDog.c create mode 100644 Platforms/Nxp/LS1043aRdb/LS1043aWatchDog/LS1043aWatchDogDxe.inf create mode 100644 Platforms/Nxp/LS1043aRdb/Library/CpldLib/CpldLib.c create mode 100644 Platforms/Nxp/LS1043aRdb/Library/CpldLib/CpldLib.inf create mode 100644 Platforms/Nxp/LS1043aRdb/Library/DdrLib/DdrLib.c create mode 100644 Platforms/Nxp/LS1043aRdb/Library/DdrLib/DdrLib.inf create mode 100644 Platforms/Nxp/LS1043aRdb/Library/LS1043aRdbLib/Common.c create mode 100644 Platforms/Nxp/LS1043aRdb/Library/LS1043aRdbLib/LS1043aRdb.c create mode 100644 Platforms/Nxp/LS1043aRdb/Library/LS1043aRdbLib/LS1043aRdbHelper.S create mode 100644 Platforms/Nxp/LS1043aRdb/Library/LS1043aRdbLib/LS1043aRdbLib.inf create mode 100644 Platforms/Nxp/LS1043aRdb/Library/LS1043aRdbLib/LS1043aRdbMem.c create mode 100644 Platforms/Nxp/LS1043aRdb/Library/LS1043aSocLib/LS1043aSocLib.c create mode 100644 Platforms/Nxp/LS1043aRdb/Library/LS1043aSocLib/LS1043aSocLib.inf create mode 100644 Platforms/Nxp/LS1043aRdb/Library/LS1043aSocLib/LsSerDes.c create mode 100644 Platforms/Nxp/LS1043aRdb/Library/ResetSystemLib/ResetSystemLib.c create mode 100644 Platforms/Nxp/LS1043aRdb/Library/ResetSystemLib/ResetSystemLib.inf create mode 100755 Platforms/Nxp/LS1043aRdb/build.sh create mode 100644 Platforms/Nxp/LS1043aRdb/ls1043a_env.cshrc
-- 1.9.1
Hi Leif,
From: Leif Lindholm [mailto:leif.lindholm@linaro.org] Sent: Tuesday, October 18, 2016 9:13 PM
Hi Bhupesh,
Many thanks for this contribution. Couple of overall questions (before I start digging into the code):
Many thanks for looking into this. Please see my replies inline.
On Tue, Oct 18, 2016 at 01:33:59AM +0530, Bhupesh Sharma wrote:
From: Bhupesh Sharma bhupesh.sharma@nxp.com
This patchset adds the support for NXP/FSL's LS1043A RDB platform.
The LS1043A RDB platform houses the 4-A53 core LS1043A SoC from
NXP/FSL.
Details about the LS1043A SoC and RDB board can be seen here:
SoC:
http://www.nxp.com/products/microcontrollers-and-processors/arm-
proces
sors/ qoriq-arm-processors/qoriq-ls1043a-and-ls1023a-multicore-
communication
s-processors:LS1043A?lang_cd=en
RDB board:
http://www.nxp.com/products/microcontrollers-and-processors/arm-
proces
sors/ qoriq-arm-processors/qoriq-ls1043a-reference-design-board:LS1043A-
RDB#
pspFeatures
UEFI firmware boot-flow on the NXP/FSL ARMv8 SoCs is different from the usual ATF (which runs in EL3) and UEFI (which runs entirely in
EL2
mode) flow:
NXP/FSL ARMv8 SoCs currently use a EL3 platform and run-time security firmware which is called PPA (Primary Protected
Application).
This firmware is placed on the flash device and is loaded into DDR and executed via a UEFI DXE driver. PPA does the initial platform EL3 settings and then returns the control back to UEFI in EL2 exception level.
OK, this sounds a bit funky, but I'll get to that when I look at the code. If there's enough TODO/FIXME in there, I probably won't mind :)
It is flunky :(, but we are working on changing this flow in near future.
Is it still implementing PSCI?
Yes, it is implementing PSCI v0.2 currently and there are plans to implement PSCI v1.0 soon.
Later implementations of PPA will allow it to start by itself in the EL3 level and start UEFI in EL2 exception level.
Yes, that sounds ideal.
:)
This patchset is rebased against the OpenPlatformPkg git tree (master branch).
Sakar Arora (14): Platforms/NXP: Add intial support for LS1043A RDB Board Platforms/NXP: Add support for DDR Controller initialization Platforms/NXP: Add support for CPLD controller access Platforms/NXP: Add initial support for LS1043a SOC Library Chips/NXP: Add support for DUART library
Wow, I think I'm nearing the 20 year anniversary of my first DUART code. :)
Thanks!
/ Leif
Platforms/NXP: Add support for initialization of peripherals on LS1043A Platforms/NXP: Add support for system reset library Chips/NXP: Add PrePi initialization module that runs from XIP
source
Chips/NXP: Add I2C operations library Chips/NXP: Add I2C master driver based on I2C library Chips/NXP: Add support for execution of PPA for EL3 initialization Chips/NXP: Add support for DS1307 RTC library Platforms/NXP: Add support for Watchdog driver (LS1043A) Platforms/NXP: Add the fdf, dsc and dec files for LS1043aRdbPkg build
Chips/Nxp/QoriqLs/I2c/I2cDxe.c | 156 ++++ Chips/Nxp/QoriqLs/I2c/I2cDxe.inf | 52 ++ Chips/Nxp/QoriqLs/Include/Library/DUart.h | 133 ++++ Chips/Nxp/QoriqLs/Include/Library/I2c.h | 199 +++++ .../QoriqLs/Library/DUartPortLib/DUartPortLib.c | 321 ++++++++ .../QoriqLs/Library/DUartPortLib/DUartPortLib.inf | 43 ++ .../QoriqLs/Library/Ds1307RtcLib/Ds1307RtcLib.c | 250 +++++++ .../QoriqLs/Library/Ds1307RtcLib/Ds1307RtcLib.inf | 44 ++ Chips/Nxp/QoriqLs/Library/I2cLib/I2cLib.c | 513
+++++++++++++
Chips/Nxp/QoriqLs/Library/I2cLib/I2cLib.inf | 41 ++ .../Library/PrePiNor/AArch64/ModuleEntryPoint.S | 34 + Chips/Nxp/QoriqLs/Library/PrePiNor/PrePiNor.c | 52 ++ Chips/Nxp/QoriqLs/Library/PrePiNor/PrePiNor.inf | 48 ++ Chips/Nxp/QoriqLs/NxpQoriqLs.dec | 50 ++ Chips/Nxp/QoriqLs/PpaInitDxe/PpaInit.c | 117 +++ Chips/Nxp/QoriqLs/PpaInitDxe/PpaInitDxe.inf | 63 ++ Chips/Nxp/QoriqLs/PpaInitDxe/PpaInitHelper.S | 79 ++ Chips/Nxp/QoriqLs/PpaInitDxe/PpaItbParse.c | 144 ++++ Chips/Nxp/QoriqLs/PpaInitDxe/PpaItbParse.h | 52 ++ Platforms/Nxp/LS1043aRdb/Include/Library/Common.h | 68 ++ Platforms/Nxp/LS1043aRdb/Include/Library/CpldLib.h | 75 ++ Platforms/Nxp/LS1043aRdb/Include/Library/Ddr.h | 190 +++++ Platforms/Nxp/LS1043aRdb/Include/Library/FslIfc.h | 721 ++++++++++++++++++
.../Nxp/LS1043aRdb/Include/Library/Ls1043aSerDes.h | 89 +++
.../Nxp/LS1043aRdb/Include/Library/PlatformLib.h | 179 +++++ Platforms/Nxp/LS1043aRdb/Include/Library/SocLib.h | 509
+++++++++++++
Platforms/Nxp/LS1043aRdb/LS1043aRdbPkg.dec | 166 +++++ Platforms/Nxp/LS1043aRdb/LS1043aRdbPkg.dsc | 602
+++++++++++++++
Platforms/Nxp/LS1043aRdb/LS1043aRdbPkg.fdf | 311 ++++++++ .../LS1043aRdb/LS1043aWatchDog/LS1043aWatchDog.c | 355 +++++++++ .../LS1043aWatchDog/LS1043aWatchDogDxe.inf | 54 ++ Platforms/Nxp/LS1043aRdb/Library/CpldLib/CpldLib.c | 157 ++++ .../Nxp/LS1043aRdb/Library/CpldLib/CpldLib.inf | 33 + Platforms/Nxp/LS1043aRdb/Library/DdrLib/DdrLib.c | 188 +++++ Platforms/Nxp/LS1043aRdb/Library/DdrLib/DdrLib.inf | 41 ++ .../Nxp/LS1043aRdb/Library/LS1043aRdbLib/Common.c | 103 +++ .../LS1043aRdb/Library/LS1043aRdbLib/LS1043aRdb.c | 109 +++ .../Library/LS1043aRdbLib/LS1043aRdbHelper.S | 61 ++ .../Library/LS1043aRdbLib/LS1043aRdbLib.inf | 56 ++ .../Library/LS1043aRdbLib/LS1043aRdbMem.c | 149 ++++ .../Library/LS1043aSocLib/LS1043aSocLib.c | 819
+++++++++++++++++++++
.../Library/LS1043aSocLib/LS1043aSocLib.inf | 53 ++ .../LS1043aRdb/Library/LS1043aSocLib/LsSerDes.c | 195 +++++ .../Library/ResetSystemLib/ResetSystemLib.c | 87 +++ .../Library/ResetSystemLib/ResetSystemLib.inf | 50 ++ Platforms/Nxp/LS1043aRdb/build.sh | 72 ++ Platforms/Nxp/LS1043aRdb/ls1043a_env.cshrc | 2 + 47 files changed, 7885 insertions(+) create mode 100644 Chips/Nxp/QoriqLs/I2c/I2cDxe.c create mode
100644
Chips/Nxp/QoriqLs/I2c/I2cDxe.inf create mode 100644 Chips/Nxp/QoriqLs/Include/Library/DUart.h create mode 100644 Chips/Nxp/QoriqLs/Include/Library/I2c.h create mode 100644 Chips/Nxp/QoriqLs/Library/DUartPortLib/DUartPortLib.c create mode 100644 Chips/Nxp/QoriqLs/Library/DUartPortLib/DUartPortLib.inf create mode 100644 Chips/Nxp/QoriqLs/Library/Ds1307RtcLib/Ds1307RtcLib.c create mode 100644 Chips/Nxp/QoriqLs/Library/Ds1307RtcLib/Ds1307RtcLib.inf create mode 100644 Chips/Nxp/QoriqLs/Library/I2cLib/I2cLib.c create mode 100644 Chips/Nxp/QoriqLs/Library/I2cLib/I2cLib.inf create mode 100644 Chips/Nxp/QoriqLs/Library/PrePiNor/AArch64/ModuleEntryPoint.S create mode 100644 Chips/Nxp/QoriqLs/Library/PrePiNor/PrePiNor.c create mode 100644 Chips/Nxp/QoriqLs/Library/PrePiNor/PrePiNor.inf create mode 100644 Chips/Nxp/QoriqLs/NxpQoriqLs.dec create mode 100644 Chips/Nxp/QoriqLs/PpaInitDxe/PpaInit.c create mode 100644 Chips/Nxp/QoriqLs/PpaInitDxe/PpaInitDxe.inf create mode 100644 Chips/Nxp/QoriqLs/PpaInitDxe/PpaInitHelper.S create mode 100755 Chips/Nxp/QoriqLs/PpaInitDxe/PpaItbParse.c create mode 100755 Chips/Nxp/QoriqLs/PpaInitDxe/PpaItbParse.h create mode 100644 Platforms/Nxp/LS1043aRdb/Include/Library/Common.h create mode 100644
Platforms/Nxp/LS1043aRdb/Include/Library/CpldLib.h
create mode 100644 Platforms/Nxp/LS1043aRdb/Include/Library/Ddr.h create mode 100644 Platforms/Nxp/LS1043aRdb/Include/Library/FslIfc.h create mode 100644 Platforms/Nxp/LS1043aRdb/Include/Library/Ls1043aSerDes.h create mode 100644 Platforms/Nxp/LS1043aRdb/Include/Library/PlatformLib.h create mode 100644 Platforms/Nxp/LS1043aRdb/Include/Library/SocLib.h create mode 100644 Platforms/Nxp/LS1043aRdb/LS1043aRdbPkg.dec create mode 100644 Platforms/Nxp/LS1043aRdb/LS1043aRdbPkg.dsc create mode 100644 Platforms/Nxp/LS1043aRdb/LS1043aRdbPkg.fdf create mode 100644 Platforms/Nxp/LS1043aRdb/LS1043aWatchDog/LS1043aWatchDog.c create mode 100644 Platforms/Nxp/LS1043aRdb/LS1043aWatchDog/LS1043aWatchDogDxe.inf create mode 100644
Platforms/Nxp/LS1043aRdb/Library/CpldLib/CpldLib.c
create mode 100644 Platforms/Nxp/LS1043aRdb/Library/CpldLib/CpldLib.inf create mode 100644 Platforms/Nxp/LS1043aRdb/Library/DdrLib/DdrLib.c create mode 100644
Platforms/Nxp/LS1043aRdb/Library/DdrLib/DdrLib.inf
create mode 100644 Platforms/Nxp/LS1043aRdb/Library/LS1043aRdbLib/Common.c create mode 100644 Platforms/Nxp/LS1043aRdb/Library/LS1043aRdbLib/LS1043aRdb.c create mode 100644 Platforms/Nxp/LS1043aRdb/Library/LS1043aRdbLib/LS1043aRdbHelper.S create mode 100644 Platforms/Nxp/LS1043aRdb/Library/LS1043aRdbLib/LS1043aRdbLib.inf create mode 100644 Platforms/Nxp/LS1043aRdb/Library/LS1043aRdbLib/LS1043aRdbMem.c create mode 100644 Platforms/Nxp/LS1043aRdb/Library/LS1043aSocLib/LS1043aSocLib.c create mode 100644 Platforms/Nxp/LS1043aRdb/Library/LS1043aSocLib/LS1043aSocLib.inf create mode 100644 Platforms/Nxp/LS1043aRdb/Library/LS1043aSocLib/LsSerDes.c create mode 100644 Platforms/Nxp/LS1043aRdb/Library/ResetSystemLib/ResetSystemLib.c create mode 100644 Platforms/Nxp/LS1043aRdb/Library/ResetSystemLib/ResetSystemLib.inf create mode 100755 Platforms/Nxp/LS1043aRdb/build.sh create mode 100644 Platforms/Nxp/LS1043aRdb/ls1043a_env.cshrc
-- 1.9.1
Regards, Bhupesh