From a889df9ca82d3a3f4c45302d8cb9ab475a2db409 Mon Sep 17 00:00:00 2001 From: Ben Levinsky Date: Wed, 9 Aug 2023 16:49:46 -0700 Subject: [PATCH] lib: freertos: consolidate common Xilinx code Move common code in Xilinx area to consolidated location to remove redundant code. Enable A72 and A78 build in BSP for FreeRTOS OS. Signed-off-by: Ben Levinsky --- lib/system/freertos/CMakeLists.txt | 8 ++ lib/system/freertos/sys.h | 2 - .../freertos/xlnx_common/CMakeLists.txt | 1 + lib/system/freertos/xlnx_common/irq.c | 5 +- .../freertos/{zynqmp_r5 => xlnx_common}/sys.c | 27 +++-- lib/system/freertos/xlnx_common/sys.h | 25 +++++ lib/system/freertos/zynq7/CMakeLists.txt | 6 - lib/system/freertos/zynq7/sys.c | 99 ----------------- lib/system/freertos/zynq7/sys.h | 46 -------- lib/system/freertos/zynqmp_a53/CMakeLists.txt | 6 - lib/system/freertos/zynqmp_a53/sys.c | 103 ------------------ lib/system/freertos/zynqmp_a53/sys.h | 46 -------- lib/system/freertos/zynqmp_r5/CMakeLists.txt | 6 - lib/system/freertos/zynqmp_r5/sys.h | 46 -------- .../generic/xlnx_common/zynqmp_aarch64/sys.c | 1 + 15 files changed, 57 insertions(+), 370 deletions(-) rename lib/system/freertos/{zynqmp_r5 => xlnx_common}/sys.c (75%) delete mode 100644 lib/system/freertos/zynq7/CMakeLists.txt delete mode 100644 lib/system/freertos/zynq7/sys.c delete mode 100644 lib/system/freertos/zynq7/sys.h delete mode 100644 lib/system/freertos/zynqmp_a53/CMakeLists.txt delete mode 100644 lib/system/freertos/zynqmp_a53/sys.c delete mode 100644 lib/system/freertos/zynqmp_a53/sys.h delete mode 100644 lib/system/freertos/zynqmp_r5/CMakeLists.txt delete mode 100644 lib/system/freertos/zynqmp_r5/sys.h diff --git a/lib/system/freertos/CMakeLists.txt b/lib/system/freertos/CMakeLists.txt index 98ca318c..def65f13 100644 --- a/lib/system/freertos/CMakeLists.txt +++ b/lib/system/freertos/CMakeLists.txt @@ -21,4 +21,12 @@ if (EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/${PROJECT_MACHINE}) add_subdirectory(${PROJECT_MACHINE}) endif (EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/${PROJECT_MACHINE}) +if ("${PROJECT_MACHINE}" STREQUAL "zynqmp_a53" OR + "${PROJECT_MACHINE}" STREQUAL "zynqmp_a72" OR + "${PROJECT_MACHINE}" STREQUAL "zynqmp_a78" OR + "${PROJECT_MACHINE}" STREQUAL "zynqmp_r5" OR + "${PROJECT_MACHINE}" STREQUAL "zynq7") +add_subdirectory(xlnx_common) +endif() + # vim: expandtab:ts=2:sw=2:smartindent diff --git a/lib/system/freertos/sys.h b/lib/system/freertos/sys.h index 680e858c..11d5e7a5 100644 --- a/lib/system/freertos/sys.h +++ b/lib/system/freertos/sys.h @@ -19,8 +19,6 @@ #include -#include "./@PROJECT_MACHINE@/sys.h" - #ifdef __cplusplus extern "C" { #endif diff --git a/lib/system/freertos/xlnx_common/CMakeLists.txt b/lib/system/freertos/xlnx_common/CMakeLists.txt index c443fb20..0bd99290 100644 --- a/lib/system/freertos/xlnx_common/CMakeLists.txt +++ b/lib/system/freertos/xlnx_common/CMakeLists.txt @@ -1,5 +1,6 @@ collect (PROJECT_LIB_HEADERS sys.h) collect (PROJECT_LIB_SOURCES irq.c) +collect (PROJECT_LIB_SOURCES sys.c) # vim: expandtab:ts=2:sw=2:smartindent diff --git a/lib/system/freertos/xlnx_common/irq.c b/lib/system/freertos/xlnx_common/irq.c index 9f318614..ecd3acad 100644 --- a/lib/system/freertos/xlnx_common/irq.c +++ b/lib/system/freertos/xlnx_common/irq.c @@ -5,8 +5,8 @@ */ /* - * @file generic/xlnx_common/irq.c - * @brief generic libmetal Xilinx irq controller definitions. + * @file freertos/xlnx_common/irq.c + * @brief freertos libmetal Xilinx irq controller definitions. */ #include @@ -17,6 +17,7 @@ #include #include #include +#include #define MAX_IRQS XLNX_MAXIRQS diff --git a/lib/system/freertos/zynqmp_r5/sys.c b/lib/system/freertos/xlnx_common/sys.c similarity index 75% rename from lib/system/freertos/zynqmp_r5/sys.c rename to lib/system/freertos/xlnx_common/sys.c index 67405bb7..2d903c80 100644 --- a/lib/system/freertos/zynqmp_r5/sys.c +++ b/lib/system/freertos/xlnx_common/sys.c @@ -1,25 +1,40 @@ /* - * Copyright (c) 2016, Xilinx Inc. and Contributors. All rights reserved. - * Copyright (C) 2022, Advanced Micro Devices, Inc. + * Copyright (C) 2023, Advanced Micro Devices, Inc. * * SPDX-License-Identifier: BSD-3-Clause */ /* - * @file freertos/zynqmp_r5/sys.c + * @file freertos/xlnx_common/sys.c * @brief machine specific system primitives implementation. */ #include #include #include +#include #include #include "xil_cache.h" #include "xil_exception.h" +#include "xscugic.h" #include "xil_mmu.h" + +#if (defined(__aarch64__) || defined(ARMA53_32)) && !defined(SDT) + +#ifdef VERSAL_NET +#include "xcpu_cortexa78.h" +#elif defined(versal) +#include "xcpu_cortexa72.h" +#else +#include "xreg_cortexa53.h" +#endif /* defined(versal) */ + +#elif defined(ARMR5) + #include "xil_mpu.h" #include "xreg_cortexr5.h" -#include "xscugic.h" + +#endif /* (defined(__aarch64__) || defined(ARMA53_32)) && !defined(SDT) */ void sys_irq_restore_enable(unsigned int flags) { @@ -60,10 +75,6 @@ void metal_weak metal_generic_default_poll(void) metal_asm volatile("wfi"); } -/** - * The code moved to cortexr5/xil_mpu.c:Xil_MemMap() - * NULL in pa masks possible Xil_MemMap() errors. - */ void *metal_machine_io_mem_map(void *va, metal_phys_addr_t pa, size_t size, unsigned int flags) { diff --git a/lib/system/freertos/xlnx_common/sys.h b/lib/system/freertos/xlnx_common/sys.h index 21f09550..c7b0786f 100644 --- a/lib/system/freertos/xlnx_common/sys.h +++ b/lib/system/freertos/xlnx_common/sys.h @@ -1,5 +1,6 @@ /* * Copyright (c) 2015, Xilinx Inc. and Contributors. All rights reserved. + * Copyright (c) 2023 Advanced Micro Devices, Inc. All rights reserved. * * SPDX-License-Identifier: BSD-3-Clause */ @@ -16,10 +17,16 @@ #ifndef __METAL_FREERTOS_XLNX_COMMON_SYS__H__ #define __METAL_FREERTOS_XLNX_COMMON_SYS__H__ +#include "xscugic.h" + #ifdef __cplusplus extern "C" { #endif +#ifndef XLNX_MAXIRQS +#define XLNX_MAXIRQS XSCUGIC_MAX_NUM_INTR_INPUTS +#endif + /** * @brief metal_xlnx_irq_isr * @@ -40,6 +47,24 @@ void metal_xlnx_irq_isr(void *arg); */ int metal_xlnx_irq_init(void); +static inline void sys_irq_enable(unsigned int vector) +{ +#ifdef PLATFORM_ZYNQ + XScuGic_EnableIntr(XPAR_SCUGIC_0_DIST_BASEADDR, vector); +#else + vPortEnableInterrupt(vector); +#endif +} + +static inline void sys_irq_disable(unsigned int vector) +{ +#ifdef PLATFORM_ZYNQ + XScuGic_DisableIntr(XPAR_SCUGIC_0_DIST_BASEADDR, vector); +#else + vPortDisableInterrupt(vector); +#endif +} + #ifdef __cplusplus } #endif diff --git a/lib/system/freertos/zynq7/CMakeLists.txt b/lib/system/freertos/zynq7/CMakeLists.txt deleted file mode 100644 index cf12dfe0..00000000 --- a/lib/system/freertos/zynq7/CMakeLists.txt +++ /dev/null @@ -1,6 +0,0 @@ -collect (PROJECT_LIB_HEADERS sys.h) - -collect (PROJECT_LIB_SOURCES sys.c) - -add_subdirectory(../xlnx_common ${CMAKE_CURRENT_BINARY_DIR}/../xlnx_common) -# vim: expandtab:ts=2:sw=2:smartindent diff --git a/lib/system/freertos/zynq7/sys.c b/lib/system/freertos/zynq7/sys.c deleted file mode 100644 index 3cff41c4..00000000 --- a/lib/system/freertos/zynq7/sys.c +++ /dev/null @@ -1,99 +0,0 @@ -/* - * Copyright (c) 2014, Mentor Graphics Corporation - * Copyright (c) 2016, Xilinx Inc. and Contributors. All rights reserved. - * - * SPDX-License-Identifier: BSD-3-Clause - */ - -/* - * @file freertos/zynq7/sys.c - * @brief machine specific system primitives implementation. - */ - -#include -#include -#include -#include -#include "xil_cache.h" -#include "xil_exception.h" -#include "xil_mmu.h" -#include "xscugic.h" - -/* Translation table is 16K in size */ -#define ARM_AR_MEM_TTB_SIZE (16*1024) - -/* Each TTB descriptor covers a 1MB region */ -#define ARM_AR_MEM_TTB_SECT_SIZE (1024*1024) - -/* Mask off lower bits of addr */ -#define ARM_AR_MEM_TTB_SECT_SIZE_MASK (~(ARM_AR_MEM_TTB_SECT_SIZE-1UL)) - -void sys_irq_restore_enable(unsigned int flags) -{ - Xil_ExceptionEnableMask(~flags); -} - -unsigned int sys_irq_save_disable(void) -{ - unsigned int state = mfcpsr() & XIL_EXCEPTION_ALL; - - if (state != XIL_EXCEPTION_ALL) { - Xil_ExceptionDisableMask(XIL_EXCEPTION_ALL); - } - return state; -} - -void metal_machine_cache_flush(void *addr, unsigned int len) -{ - if (!addr && !len) - Xil_DCacheFlush(); - else - Xil_DCacheFlushRange((intptr_t)addr, len); -} - -void metal_machine_cache_invalidate(void *addr, unsigned int len) -{ - if (!addr && !len) - Xil_DCacheInvalidate(); - else - Xil_DCacheInvalidateRange((intptr_t)addr, len); -} - -/** - * @brief poll function until some event happens - */ -void metal_weak metal_generic_default_poll(void) -{ - metal_asm volatile("wfi"); -} - -void *metal_machine_io_mem_map(void *va, metal_phys_addr_t pa, - size_t size, unsigned int flags) -{ - unsigned int section_offset; - unsigned int ttb_addr; - - if (!flags) - return va; - /* - * Ensure the virtual and physical addresses are aligned on a - * section boundary - */ - pa &= ARM_AR_MEM_TTB_SECT_SIZE_MASK; - - /* - * Loop through entire region of memory (one MMU section at a time). - * Each section requires a TTB entry. - */ - for (section_offset = 0; section_offset < size; - section_offset += ARM_AR_MEM_TTB_SECT_SIZE) { - - /* Calculate translation table entry for this memory section */ - ttb_addr = (pa + section_offset); - - /* Write translation table entry value to entry address */ - Xil_SetTlbAttributes(ttb_addr, flags); - } - - return va; -} diff --git a/lib/system/freertos/zynq7/sys.h b/lib/system/freertos/zynq7/sys.h deleted file mode 100644 index 51b08ed9..00000000 --- a/lib/system/freertos/zynq7/sys.h +++ /dev/null @@ -1,46 +0,0 @@ -/* - * Copyright (c) 2016, Xilinx Inc. and Contributors. All rights reserved. - * - * SPDX-License-Identifier: BSD-3-Clause - */ - -/* - * @file freertos/zynq7/sys.h - * @brief freertos zynq7 system primitives for libmetal. - */ - -#ifndef __METAL_FREERTOS_SYS__H__ -#error "Include metal/sys.h instead of metal/freertos/@PROJECT_MACHINE@/sys.h" -#endif - -#include -#include "xscugic.h" - -#ifndef __METAL_FREERTOS_ZYNQ7_SYS__H__ -#define __METAL_FREERTOS_ZYNQ7_SYS__H__ - -#ifdef __cplusplus -extern "C" { -#endif - -#ifdef METAL_INTERNAL - -#define XLNX_MAXIRQS XSCUGIC_MAX_NUM_INTR_INPUTS - -static inline void sys_irq_enable(unsigned int vector) -{ - XScuGic_EnableIntr(XPAR_SCUGIC_0_DIST_BASEADDR, vector); -} - -static inline void sys_irq_disable(unsigned int vector) -{ - XScuGic_DisableIntr(XPAR_SCUGIC_0_DIST_BASEADDR, vector); -} - -#endif /* METAL_INTERNAL */ - -#ifdef __cplusplus -} -#endif - -#endif /* __METAL_FREERTOS_ZYNQ7_SYS__H__ */ diff --git a/lib/system/freertos/zynqmp_a53/CMakeLists.txt b/lib/system/freertos/zynqmp_a53/CMakeLists.txt deleted file mode 100644 index cf12dfe0..00000000 --- a/lib/system/freertos/zynqmp_a53/CMakeLists.txt +++ /dev/null @@ -1,6 +0,0 @@ -collect (PROJECT_LIB_HEADERS sys.h) - -collect (PROJECT_LIB_SOURCES sys.c) - -add_subdirectory(../xlnx_common ${CMAKE_CURRENT_BINARY_DIR}/../xlnx_common) -# vim: expandtab:ts=2:sw=2:smartindent diff --git a/lib/system/freertos/zynqmp_a53/sys.c b/lib/system/freertos/zynqmp_a53/sys.c deleted file mode 100644 index 411776e1..00000000 --- a/lib/system/freertos/zynqmp_a53/sys.c +++ /dev/null @@ -1,103 +0,0 @@ -/* - * Copyright (c) 2017, Xilinx Inc. and Contributors. All rights reserved. - * - * SPDX-License-Identifier: BSD-3-Clause - */ - -/* - * @file freertos/zynqmp_a53/sys.c - * @brief machine specific system primitives implementation. - */ - -#include -#include -#include -#include -#include -#include "xil_cache.h" -#include "xil_exception.h" -#include "xil_mmu.h" -#include "xreg_cortexa53.h" -#include "xscugic.h" - -void sys_irq_restore_enable(unsigned int flags) -{ - Xil_ExceptionEnableMask(~flags); -} - -unsigned int sys_irq_save_disable(void) -{ - unsigned int state = mfcpsr() & XIL_EXCEPTION_ALL; - - if (state != XIL_EXCEPTION_ALL) { - Xil_ExceptionDisableMask(XIL_EXCEPTION_ALL); - } - return state; -} - -void metal_machine_cache_flush(void *addr, unsigned int len) -{ - if (!addr && !len) - Xil_DCacheFlush(); - else - Xil_DCacheFlushRange((intptr_t)addr, len); -} - -void metal_machine_cache_invalidate(void *addr, unsigned int len) -{ - if (!addr && !len) - Xil_DCacheInvalidate(); - else - Xil_DCacheInvalidateRange((intptr_t)addr, len); -} - -/** - * @brief poll function until some event happens - */ -void metal_weak metal_generic_default_poll(void) -{ - metal_asm volatile("wfi"); -} - -void *metal_machine_io_mem_map(void *va, metal_phys_addr_t pa, - size_t size, unsigned int flags) -{ - unsigned long section_offset; - unsigned long ttb_addr; -#if defined(__aarch64__) - unsigned long ttb_size = (pa < 4*GB) ? 2*MB : 1*GB; -#else - unsigned long ttb_size = 1*MB; -#endif - - if (!flags) - return va; - - /* Ensure alignment on a section boundary */ - pa &= ~(ttb_size-1UL); - - /* - * Loop through entire region of memory (one MMU section at a time). - * Each section requires a TTB entry. - */ - for (section_offset = 0; section_offset < size; ) { - /* Calculate translation table entry for this memory section */ - ttb_addr = (pa + section_offset); - - /* Write translation table entry value to entry address */ - Xil_SetTlbAttributes(ttb_addr, flags); - -#if defined(__aarch64__) - /* - * recalculate if we started below 4GB and going above in - * 64bit mode - */ - if (ttb_addr >= 4*GB) { - ttb_size = 1*GB; - } -#endif - section_offset += ttb_size; - } - - return va; -} diff --git a/lib/system/freertos/zynqmp_a53/sys.h b/lib/system/freertos/zynqmp_a53/sys.h deleted file mode 100644 index f2291d28..00000000 --- a/lib/system/freertos/zynqmp_a53/sys.h +++ /dev/null @@ -1,46 +0,0 @@ -/* - * Copyright (c) 2017, Xilinx Inc. and Contributors. All rights reserved. - * - * SPDX-License-Identifier: BSD-3-Clause - */ - -/* - * @file freertos/zynqmp_a53/sys.h - * @brief freertos zynqmp_a53 system primitives for libmetal. - */ - -#ifndef __METAL_FREERTOS_SYS__H__ -#error "Include metal/sys.h instead of metal/freertos/@PROJECT_MACHINE@/sys.h" -#endif - -#include -#include "xscugic.h" - -#ifndef __METAL_FREERTOS_ZYNQMP_A53_SYS__H__ -#define __METAL_FREERTOS_ZYNQMP_A53_SYS__H__ - -#ifdef __cplusplus -extern "C" { -#endif - -#ifdef METAL_INTERNAL - -#define XLNX_MAXIRQS XSCUGIC_MAX_NUM_INTR_INPUTS - -static inline void sys_irq_enable(unsigned int vector) -{ - XScuGic_EnableIntr(XPAR_SCUGIC_0_DIST_BASEADDR, vector); -} - -static inline void sys_irq_disable(unsigned int vector) -{ - XScuGic_DisableIntr(XPAR_SCUGIC_0_DIST_BASEADDR, vector); -} - -#endif /* METAL_INTERNAL */ - -#ifdef __cplusplus -} -#endif - -#endif /* __METAL_FREERTOS_ZYNQMP_A53_SYS__H__ */ diff --git a/lib/system/freertos/zynqmp_r5/CMakeLists.txt b/lib/system/freertos/zynqmp_r5/CMakeLists.txt deleted file mode 100644 index cf12dfe0..00000000 --- a/lib/system/freertos/zynqmp_r5/CMakeLists.txt +++ /dev/null @@ -1,6 +0,0 @@ -collect (PROJECT_LIB_HEADERS sys.h) - -collect (PROJECT_LIB_SOURCES sys.c) - -add_subdirectory(../xlnx_common ${CMAKE_CURRENT_BINARY_DIR}/../xlnx_common) -# vim: expandtab:ts=2:sw=2:smartindent diff --git a/lib/system/freertos/zynqmp_r5/sys.h b/lib/system/freertos/zynqmp_r5/sys.h deleted file mode 100644 index 1fca6e16..00000000 --- a/lib/system/freertos/zynqmp_r5/sys.h +++ /dev/null @@ -1,46 +0,0 @@ -/* - * Copyright (c) 2016, Xilinx Inc. and Contributors. All rights reserved. - * - * SPDX-License-Identifier: BSD-3-Clause - */ - -/* - * @file freertos/zynqmp_r5/sys.h - * @brief freertos zynqmp_r5 system primitives for libmetal. - */ - -#ifndef __METAL_FREERTOS_SYS__H__ -#error "Include metal/sys.h instead of metal/freertos/@PROJECT_MACHINE@/sys.h" -#endif - -#include -#include "xscugic.h" - -#ifndef __METAL_FREERTOS_ZYNQMP_R5_SYS__H__ -#define __METAL_FREERTOS_ZYNQMP_R5_SYS__H__ - -#ifdef __cplusplus -extern "C" { -#endif - -#ifdef METAL_INTERNAL - -#define XLNX_MAXIRQS XSCUGIC_MAX_NUM_INTR_INPUTS - -static inline void sys_irq_enable(unsigned int vector) -{ - XScuGic_EnableIntr(XPAR_SCUGIC_0_DIST_BASEADDR, vector); -} - -static inline void sys_irq_disable(unsigned int vector) -{ - XScuGic_DisableIntr(XPAR_SCUGIC_0_DIST_BASEADDR, vector); -} - -#endif /* METAL_INTERNAL */ - -#ifdef __cplusplus -} -#endif - -#endif /* __METAL_FREERTOS_ZYNQMP_R5_SYS__H__ */ diff --git a/lib/system/generic/xlnx_common/zynqmp_aarch64/sys.c b/lib/system/generic/xlnx_common/zynqmp_aarch64/sys.c index e3bf1bed..453b4e63 100644 --- a/lib/system/generic/xlnx_common/zynqmp_aarch64/sys.c +++ b/lib/system/generic/xlnx_common/zynqmp_aarch64/sys.c @@ -13,6 +13,7 @@ #include #include #include +#include #include #include "xil_cache.h" #include "xil_exception.h"