From 5e536a0dc7ae40954b69b3c35305b4cb7b64491d Mon Sep 17 00:00:00 2001 From: Ben Levinsky Date: Wed, 9 Aug 2023 16:49:46 -0700 Subject: [PATCH] lib: freertos: Add support for A72 and A78 Enable A72 and A78 build in BSP for FreeRTOS OS. Signed-off-by: Ben Levinsky --- .../freertos/xlnx_common/CMakeLists.txt | 4 + .../xlnx_common/zynqmp_aarch64/CMakeLists.txt | 3 + .../freertos/xlnx_common/zynqmp_aarch64/sys.c | 115 ++++++++++++++++++ .../freertos/xlnx_common/zynqmp_aarch64/sys.h | 46 +++++++ lib/system/freertos/zynqmp_a72/CMakeLists.txt | 4 + lib/system/freertos/zynqmp_a72/sys.h | 16 +++ lib/system/freertos/zynqmp_a78/CMakeLists.txt | 3 + lib/system/freertos/zynqmp_a78/sys.h | 16 +++ .../generic/xlnx_common/zynqmp_aarch64/sys.c | 1 + 9 files changed, 208 insertions(+) create mode 100644 lib/system/freertos/xlnx_common/zynqmp_aarch64/CMakeLists.txt create mode 100644 lib/system/freertos/xlnx_common/zynqmp_aarch64/sys.c create mode 100644 lib/system/freertos/xlnx_common/zynqmp_aarch64/sys.h create mode 100644 lib/system/freertos/zynqmp_a72/CMakeLists.txt create mode 100644 lib/system/freertos/zynqmp_a72/sys.h create mode 100644 lib/system/freertos/zynqmp_a78/CMakeLists.txt create mode 100644 lib/system/freertos/zynqmp_a78/sys.h diff --git a/lib/system/freertos/xlnx_common/CMakeLists.txt b/lib/system/freertos/xlnx_common/CMakeLists.txt index c443fb20..d831349a 100644 --- a/lib/system/freertos/xlnx_common/CMakeLists.txt +++ b/lib/system/freertos/xlnx_common/CMakeLists.txt @@ -2,4 +2,8 @@ collect (PROJECT_LIB_HEADERS sys.h) collect (PROJECT_LIB_SOURCES irq.c) +if ("${PROJECT_MACHINE}" STREQUAL "zynqmp_a53" OR "${PROJECT_MACHINE}" STREQUAL "zynqmp_a72" OR "${PROJECT_MACHINE}" STREQUAL "zynqmp_a78") + add_subdirectory(zynqmp_aarch64) +endif ("${PROJECT_MACHINE}" STREQUAL "zynqmp_a53" OR "${PROJECT_MACHINE}" STREQUAL "zynqmp_a72" OR "${PROJECT_MACHINE}" STREQUAL "zynqmp_a78") + # vim: expandtab:ts=2:sw=2:smartindent diff --git a/lib/system/freertos/xlnx_common/zynqmp_aarch64/CMakeLists.txt b/lib/system/freertos/xlnx_common/zynqmp_aarch64/CMakeLists.txt new file mode 100644 index 00000000..87d3c35e --- /dev/null +++ b/lib/system/freertos/xlnx_common/zynqmp_aarch64/CMakeLists.txt @@ -0,0 +1,3 @@ +collect (PROJECT_LIB_HEADERS sys.h) +collect (PROJECT_LIB_SOURCES sys.c) +# vim: expandtab:ts=2:sw=2:smartindent diff --git a/lib/system/freertos/xlnx_common/zynqmp_aarch64/sys.c b/lib/system/freertos/xlnx_common/zynqmp_aarch64/sys.c new file mode 100644 index 00000000..be947aa6 --- /dev/null +++ b/lib/system/freertos/xlnx_common/zynqmp_aarch64/sys.c @@ -0,0 +1,115 @@ +/* + * Copyright (c) 2023 Advanced Micro Devices, Inc. All Rights Reserved. + * + * SPDX-License-Identifier: BSD-3-Clause + */ + +/* + * @file freertos/xlnx_common/zynqmp_aarch64/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 "xscugic.h" + +/* System Device Tree (SDT) flow does not have the files generated. */ +#ifndef SDT + +#ifdef VERSAL_NET +#include "xcpu_cortexa78.h" +#elif defined(versal) +#include "xcpu_cortexa72.h" +#else +#include "xreg_cortexa53.h" +#endif /* defined(versal) */ + +#endif /* !SDT */ + +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 + */ +inline void metal_weak metal_freertos_default_poll(void) +{ + metal_asm volatile("wfi"); +} + +/* TODO: document functionality of this function. */ +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 /* defined(__aarch64__) */ + + 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/xlnx_common/zynqmp_aarch64/sys.h b/lib/system/freertos/xlnx_common/zynqmp_aarch64/sys.h new file mode 100644 index 00000000..cf1cbac5 --- /dev/null +++ b/lib/system/freertos/xlnx_common/zynqmp_aarch64/sys.h @@ -0,0 +1,46 @@ +/* + * Copyright (c) 2023, Xilinx Inc. and Contributors. All rights reserved. + * + * SPDX-License-Identifier: BSD-3-Clause + */ + +/* + * @file freertps/xlnx_common/zynqmp_aarch64/sys.h + * @brief freertos zynqmp_aarch64 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_XLNX_COMMON_AARCH64_SYS__H__ +#define __METAL_FREERTOS_ZYNQMP_XLNX_COMMON_AARCH64_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_XLNX_COMMON_AARCH64_SYS__H__ */ diff --git a/lib/system/freertos/zynqmp_a72/CMakeLists.txt b/lib/system/freertos/zynqmp_a72/CMakeLists.txt new file mode 100644 index 00000000..20f4c7be --- /dev/null +++ b/lib/system/freertos/zynqmp_a72/CMakeLists.txt @@ -0,0 +1,4 @@ +collect (PROJECT_LIB_HEADERS sys.h) + +add_subdirectory(../xlnx_common ${CMAKE_CURRENT_BINARY_DIR}/../xlnx_common) +# vim: expandtab:ts=2:sw=2:smartindent diff --git a/lib/system/freertos/zynqmp_a72/sys.h b/lib/system/freertos/zynqmp_a72/sys.h new file mode 100644 index 00000000..d1308d1d --- /dev/null +++ b/lib/system/freertos/zynqmp_a72/sys.h @@ -0,0 +1,16 @@ +/* + * Copyright (c) 2023, Xilinx Inc. and Contributors. All rights reserved. + * + * SPDX-License-Identifier: BSD-3-Clause + */ + +/* + * @file freertos/zynqmp_a72/sys.h + * @brief freertos zynqmp_a72 system primitives for libmetal. + */ + +/* + * The header file is still required as freertos/sys.h expects + * "./@PROJECT_MACHINE@/sys.h" to still exist. + */ +#include diff --git a/lib/system/freertos/zynqmp_a78/CMakeLists.txt b/lib/system/freertos/zynqmp_a78/CMakeLists.txt new file mode 100644 index 00000000..a9e14b61 --- /dev/null +++ b/lib/system/freertos/zynqmp_a78/CMakeLists.txt @@ -0,0 +1,3 @@ +collect (PROJECT_LIB_HEADERS sys.h) + +add_subdirectory(../xlnx_common ${CMAKE_CURRENT_BINARY_DIR}/../xlnx_common) diff --git a/lib/system/freertos/zynqmp_a78/sys.h b/lib/system/freertos/zynqmp_a78/sys.h new file mode 100644 index 00000000..31bd21ae --- /dev/null +++ b/lib/system/freertos/zynqmp_a78/sys.h @@ -0,0 +1,16 @@ +/* + * Copyright (c) 2023 Advanced Micro Devices, Inc. All Rights Reserved. + * + * SPDX-License-Identifier: BSD-3-Clause + */ + +/* + * @file freertos/zynqmp_a78/sys.h + * @brief freertos zynqmp_a78 system primitives for libmetal. + */ + +/* + * The header file is still required as freertos/sys.h expects + * "./@PROJECT_MACHINE@/sys.h" to still exist. + */ +#include 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"