diff --git a/bsps/aarch64/rk3399/console/console.c b/bsps/aarch64/rk3399/console/console.c new file mode 100644 index 0000000000..e584fd3d58 --- /dev/null +++ b/bsps/aarch64/rk3399/console/console.c @@ -0,0 +1,139 @@ +/* SPDX-License-Identifier: BSD-2-Clause */ + +/** + * @file + * + * @ingroup RTEMSBSPsAArch64RK3399 + * + * @brief Console Configuration + */ + +/* + * Copyright (C) 2026 Ning Yang + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#include +#include +#include + +#include +#include + +#include + +uint32_t rk3399_uart_reg_shift = 2; + +static uint8_t get_register(uintptr_t addr, uint8_t i) +{ + volatile uint8_t *reg = (uint8_t *) addr; + + i <<= rk3399_uart_reg_shift; + return reg [i]; +} + +static void set_register(uintptr_t addr, uint8_t i, uint8_t val) +{ + volatile uint8_t *reg = (uint8_t *) addr; + i <<= rk3399_uart_reg_shift; + reg [i] = val; +} + +static ns16550_context rk3399_uart_instances[5] = { + { + .base = RTEMS_TERMIOS_DEVICE_CONTEXT_INITIALIZER("RK3399 UART 0"), + .get_reg = get_register, + .set_reg = set_register, + .initial_baud = RK3399_UART_DEFAULT_BAUD, + .port = RK3399_UART0_BASE + }, { + .base = RTEMS_TERMIOS_DEVICE_CONTEXT_INITIALIZER("RK3399 UART 1"), + .get_reg = get_register, + .set_reg = set_register, + .initial_baud = RK3399_UART_DEFAULT_BAUD, + .port = RK3399_UART1_BASE + }, { + .base = RTEMS_TERMIOS_DEVICE_CONTEXT_INITIALIZER("RK3399 UART 2"), + .get_reg = get_register, + .set_reg = set_register, + .initial_baud = RK3399_UART_DEFAULT_BAUD, + .port = RK3399_UART2_BASE + }, { + .base = RTEMS_TERMIOS_DEVICE_CONTEXT_INITIALIZER("RK3399 UART 3"), + .get_reg = get_register, + .set_reg = set_register, + .initial_baud = RK3399_UART_DEFAULT_BAUD, + .port = RK3399_UART3_BASE + }, { + .base = RTEMS_TERMIOS_DEVICE_CONTEXT_INITIALIZER("RK3399 UART 4"), + .get_reg = get_register, + .set_reg = set_register, + .initial_baud = RK3399_UART_DEFAULT_BAUD, + .port = RK3399_UART4_BASE + } +}; + +rtems_status_code console_initialize( + rtems_device_major_number major, + rtems_device_minor_number minor, + void *arg +) +{ + (void) major; + (void) minor; + (void) arg; + + size_t i; + + rtems_termios_initialize(); + + for (i = 0; i < RTEMS_ARRAY_SIZE(rk3399_uart_instances); ++i) { + ns16550_context *ctx = &rk3399_uart_instances[i]; + char uart[] = "/dev/ttySX"; + + uart[sizeof(uart) - 2] = (char) ('0' + i); + + rtems_termios_device_install( + &uart[0], + &ns16550_handler_polled, + NULL, + &ctx->base + ); + + if (i == BSP_CONSOLE_MINOR) { + link(&uart[0], CONSOLE_DEVICE_NAME); + } + } + + return RTEMS_SUCCESSFUL; +} + +static void output_char(char c) +{ + rtems_termios_device_context *ctx = &rk3399_uart_instances[BSP_CONSOLE_MINOR].base; + ns16550_polled_putchar(ctx, c); +} + +BSP_output_char_function_type BSP_output_char = output_char; + +BSP_polling_getchar_function_type BSP_poll_char = NULL; diff --git a/bsps/aarch64/rk3399/include/bsp.h b/bsps/aarch64/rk3399/include/bsp.h new file mode 100644 index 0000000000..18e4b26912 --- /dev/null +++ b/bsps/aarch64/rk3399/include/bsp.h @@ -0,0 +1,72 @@ +/* SPDX-License-Identifier: BSD-2-Clause */ + +/** + * @file + * + * @ingroup RTEMSBSPsAArch64RK3399 + * + * @brief Core BSP definitions + */ + +/* + * Copyright (C) 2026 Ning Yang + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef LIBBSP_AARCH64_RK3399_BSP_H +#define LIBBSP_AARCH64_RK3399_BSP_H + +/** + * @addtogroup RTEMSBSPsAArch64 + * + * @{ + */ + +#include + +#ifndef ASM + +#include +#include + +#include + +#ifdef __cplusplus +extern "C" { +#endif /* __cplusplus */ + +#define BSP_ARM_GIC_CPUIF_BASE 0xfff00000 +#define BSP_ARM_GIC_DIST_BASE 0xfee00000 +#define BSP_ARM_GIC_REDIST_BASE 0xfef00000 + +BSP_START_TEXT_SECTION void rk3399_setup_mmu_and_cache( void ); + +#ifdef __cplusplus +} +#endif /* __cplusplus */ + +#endif /* ASM */ + +/** @} */ + +#endif /* LIBBSP_AARCH64_RK3399_BSP_H */ diff --git a/bsps/aarch64/rk3399/include/bsp/irq.h b/bsps/aarch64/rk3399/include/bsp/irq.h new file mode 100644 index 0000000000..bd6eaa4ea7 --- /dev/null +++ b/bsps/aarch64/rk3399/include/bsp/irq.h @@ -0,0 +1,64 @@ +/* SPDX-License-Identifier: BSD-2-Clause */ + +/** + * @file + * + * @ingroup RTEMSBSPsAArch64RK3399 + * + * @brief BSP IRQ definitions + */ + +/* + * Copyright (C) 2026 Ning Yang + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef LIBBSP_AARCH64_RK3399_IRQ_H +#define LIBBSP_AARCH64_RK3399_IRQ_H + +#ifndef ASM + +#include +#include + +#include + +#ifdef __cplusplus +extern "C" { +#endif /* __cplusplus */ + +#define BSP_INTERRUPT_VECTOR_COUNT 1020 + +/* Interrupts vectors */ +#define BSP_TIMER_VIRT_PPI 27 +#define BSP_TIMER_PHYS_NS_PPI 30 + +/** @} */ + +#ifdef __cplusplus +} +#endif /* __cplusplus */ + +#endif /* ASM */ + +#endif /* LIBBSP_AARCH64_RK3399_IRQ_H */ diff --git a/bsps/aarch64/rk3399/include/bsp/rk3399.h b/bsps/aarch64/rk3399/include/bsp/rk3399.h new file mode 100644 index 0000000000..ab0093df13 --- /dev/null +++ b/bsps/aarch64/rk3399/include/bsp/rk3399.h @@ -0,0 +1,74 @@ +/* SPDX-License-Identifier: BSD-2-Clause */ + +/** + * @file + * + * @ingroup RTEMSBSPsAArch64RK3399 + * + * @brief Register definitions. + */ + +/* + * Copyright (C) 2026 Ning Yang + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef LIBBSP_AARCH64_RK3399_RK3399_H +#define LIBBSP_AARCH64_RK3399_RK3399_H + +#include +#include +#include + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * @name RK3399 UARTs + * + * @{ + */ +#define RK3399_UART_BASE 0xff180000 +#define RK3399_UART_DEVICE_SIZE 0x10000 + +#define RK3399_UART0_BASE (RK3399_UART_BASE + 0x00000) +#define RK3399_UART0_SIZE RK3399_UART_DEVICE_SIZE +#define RK3399_UART1_BASE (RK3399_UART_BASE + 0x10000) +#define RK3399_UART1_SIZE RK3399_UART_DEVICE_SIZE +#define RK3399_UART2_BASE (RK3399_UART_BASE + 0x20000) +#define RK3399_UART2_SIZE RK3399_UART_DEVICE_SIZE +#define RK3399_UART3_BASE (RK3399_UART_BASE + 0x30000) +#define RK3399_UART3_SIZE RK3399_UART_DEVICE_SIZE + +#define RK3399_UART4_BASE 0xff370000 +#define RK3399_UART4_SIZE RK3399_UART_DEVICE_SIZE + +#define RK3399_UART_DEFAULT_BAUD 1500000 +/** @} */ + +#ifdef __cplusplus +} +#endif /* __cplusplus */ + +#endif /* LIBBSP_AARCH64_RK3399_RK3399_H */ \ No newline at end of file diff --git a/bsps/aarch64/rk3399/include/tm27.h b/bsps/aarch64/rk3399/include/tm27.h new file mode 100644 index 0000000000..90b37760c3 --- /dev/null +++ b/bsps/aarch64/rk3399/include/tm27.h @@ -0,0 +1,45 @@ +/* SPDX-License-Identifier: BSD-2-Clause */ + +/** + * @file + * + * @ingroup RTEMSBSPsAArch64RK3399 + * + * @brief BSP tm27 header + */ + +/* + * Copyright (C) 2026 Ning Yang + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _RTEMS_TMTEST27 +#error "This is an RTEMS internal file you must not include directly." +#endif + +#ifndef __tm27_h +#define __tm27_h + +#include + +#endif /* __tm27_h */ diff --git a/bsps/aarch64/rk3399/start/bspstart.c b/bsps/aarch64/rk3399/start/bspstart.c new file mode 100644 index 0000000000..ac31a3bb93 --- /dev/null +++ b/bsps/aarch64/rk3399/start/bspstart.c @@ -0,0 +1,48 @@ +/* SPDX-License-Identifier: BSD-2-Clause */ + +/** + * @file + * + * @ingroup RTEMSBSPsAArch64RK3399 + * + * @brief This source file contains the implementation of bsp_start(). + */ + +/* + * Copyright (C) 2026 Ning Yang + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#include +#include +#include +#include + +void bsp_start( void ) +{ + bsp_interrupt_initialize(); + rtems_cache_coherent_add_area( + bsp_section_nocacheheap_begin, + (uintptr_t) bsp_section_nocacheheap_size + ); +} diff --git a/bsps/aarch64/rk3399/start/bspstarthooks.c b/bsps/aarch64/rk3399/start/bspstarthooks.c new file mode 100644 index 0000000000..d7fff787b4 --- /dev/null +++ b/bsps/aarch64/rk3399/start/bspstarthooks.c @@ -0,0 +1,58 @@ +/* SPDX-License-Identifier: BSD-2-Clause */ + +/** + * @file + * + * @ingroup RTEMSBSPsAArch64RK3399 + * + * @brief BSP Startup Hooks + */ + +/* + * Copyright (C) 2026 Ning Yang + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#include +#include + +BSP_START_TEXT_SECTION void rk3399_setup_mmu_and_cache(void); + +#ifdef BSP_START_ENABLE_EL3_START_SUPPORT +BSP_START_TEXT_SECTION void bsp_start_hook_0(void) +{ + /* Do nothing */ +} +#endif + +BSP_START_TEXT_SECTION void bsp_start_hook_1(void) +{ + _AARCH64_Data_synchronization_barrier(); + _AARCH64_Instruction_synchronization_barrier(); + + AArch64_start_set_vector_base(); + bsp_start_copy_sections(); + + rk3399_setup_mmu_and_cache(); + bsp_start_clear_bss(); +} diff --git a/bsps/aarch64/rk3399/start/bspstartmmu.c b/bsps/aarch64/rk3399/start/bspstartmmu.c new file mode 100644 index 0000000000..4ad9d02d9b --- /dev/null +++ b/bsps/aarch64/rk3399/start/bspstartmmu.c @@ -0,0 +1,53 @@ +/* SPDX-License-Identifier: BSD-2-Clause */ + +/** + * @file + * + * @ingroup RTEMSBSPsAArch64RK3399 + * + * @brief This source file contains the default MMU tables and setup. + */ + +/* + * Copyright (C) 2026 Ning Yang + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#include +#include +#include + +BSP_START_TEXT_SECTION void rk3399_setup_mmu_and_cache( void ) +{ + aarch64_mmu_control *control = &aarch64_mmu_instance; + + aarch64_mmu_setup(); + + aarch64_mmu_setup_translation_table( + control, + &aarch64_mmu_config_table[ 0 ], + aarch64_mmu_config_table_size + ); + + aarch64_mmu_enable( control ); +} \ No newline at end of file diff --git a/bsps/aarch64/rk3399/start/mmu-config.c b/bsps/aarch64/rk3399/start/mmu-config.c new file mode 100644 index 0000000000..9dd4b30908 --- /dev/null +++ b/bsps/aarch64/rk3399/start/mmu-config.c @@ -0,0 +1,64 @@ +/* SPDX-License-Identifier: BSD-2-Clause */ + +/** + * @file + * + * @ingroup RTEMSBSPsAArch64RK3399 + * + * @brief This source file contains the definition of ::aarch64_mmu_config_table + * and ::aarch64_mmu_config_table_size. + */ + +/* + * Copyright (C) 2026 Ning Yang + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#include +#include +#include +#include +#include + +BSP_START_DATA_SECTION const aarch64_mmu_config_entry +aarch64_mmu_config_table[] = { + AARCH64_MMU_DEFAULT_SECTIONS, + { /* GIC500 */ + .begin = 0xFEE00000ULL, + .end = 0xFF000000ULL, + .flags = AARCH64_MMU_DEVICE + }, + { /* NS16550 UART0-UART3 */ + .begin = RK3399_UART_BASE, + .end = RK3399_UART_BASE + RK3399_UART_DEVICE_SIZE * 4, + .flags = AARCH64_MMU_DEVICE + }, + { /* NS16550 UART4 */ + .begin = RK3399_UART4_BASE, + .end = RK3399_UART4_BASE + RK3399_UART_DEVICE_SIZE, + .flags = AARCH64_MMU_DEVICE + } +}; + +BSP_START_DATA_SECTION const size_t aarch64_mmu_config_table_size = + RTEMS_ARRAY_SIZE(aarch64_mmu_config_table); diff --git a/spec/build/bsps/aarch64/rk3399/abi.yml b/spec/build/bsps/aarch64/rk3399/abi.yml new file mode 100644 index 0000000000..e83af6eb8b --- /dev/null +++ b/spec/build/bsps/aarch64/rk3399/abi.yml @@ -0,0 +1,18 @@ +SPDX-License-Identifier: CC-BY-SA-4.0 OR BSD-2-Clause +actions: +- get-string: null +- split: null +- env-append: null +build-type: option +copyrights: +- Copyright (C) 2026 Ning Yang +default: +- enabled-by: true + value: + - -mcpu=cortex-a72 +description: | + ABI flags +enabled-by: true +links: [] +name: ABI_FLAGS +type: build diff --git a/spec/build/bsps/aarch64/rk3399/bsprockpro64.yml b/spec/build/bsps/aarch64/rk3399/bsprockpro64.yml new file mode 100644 index 0000000000..8f9bf5379e --- /dev/null +++ b/spec/build/bsps/aarch64/rk3399/bsprockpro64.yml @@ -0,0 +1,19 @@ +SPDX-License-Identifier: CC-BY-SA-4.0 OR BSD-2-Clause +arch: aarch64 +bsp: rk3399_rockpro64 +build-type: bsp +cflags: [] +copyrights: +- Copyright (C) 2026 Ning Yang +cppflags: [] +enabled-by: true +family: rk3399 +includes: [] +install: [] +links: +- role: build-dependency + uid: grp +- role: build-dependency + uid: linkcmds +source: [] +type: build diff --git a/spec/build/bsps/aarch64/rk3399/grp.yml b/spec/build/bsps/aarch64/rk3399/grp.yml new file mode 100644 index 0000000000..a704916e9e --- /dev/null +++ b/spec/build/bsps/aarch64/rk3399/grp.yml @@ -0,0 +1,51 @@ +SPDX-License-Identifier: CC-BY-SA-4.0 OR BSD-2-Clause +build-type: group +cflags: [] +copyrights: +- Copyright (C) 2026 Ning Yang +cppflags: [] +cxxflags: [] +enabled-by: true +includes: [] +install: [] +ldflags: [] +links: +- role: build-dependency + uid: ../grp +- role: build-dependency + uid: ../start +- role: build-dependency + uid: abi +- role: build-dependency + uid: obj +- role: build-dependency + uid: optconminor +- role: build-dependency + uid: optloadoff +- role: build-dependency + uid: optnocachelen +- role: build-dependency + uid: optramlen +- role: build-dependency + uid: optramori +- role: build-dependency + uid: ../objclockarmgenerictimer +- role: build-dependency + uid: ../../obj +- role: build-dependency + uid: ../../objirq +- role: build-dependency + uid: ../../dev/irq/objarmgicv3 +- role: build-dependency + uid: ../../objmem +- role: build-dependency + uid: ../../optcachedata +- role: build-dependency + uid: ../../optcacheinst +- role: build-dependency + uid: ../../opto2 +- role: build-dependency + uid: ../../bspopts +type: build +use-after: [] +use-before: [] diff --git a/spec/build/bsps/aarch64/rk3399/linkcmds.yml b/spec/build/bsps/aarch64/rk3399/linkcmds.yml new file mode 100644 index 0000000000..2d3cfe587b --- /dev/null +++ b/spec/build/bsps/aarch64/rk3399/linkcmds.yml @@ -0,0 +1,73 @@ +SPDX-License-Identifier: CC-BY-SA-4.0 OR BSD-2-Clause +build-type: config-file +content: | + /* SPDX-License-Identifier: BSD-2-Clause */ + + /* + * Copyright (C) 2026 Ning Yang + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + + MEMORY { + RAM : ORIGIN = ${BSP_RK3399_RAM_BASE} + ${BSP_RK3399_LOAD_OFFSET}, LENGTH = ${BSP_RK3399_RAM_LENGTH} - ${BSP_RK3399_LOAD_OFFSET} - ${BSP_RK3399_NOCACHE_LENGTH} - 0x1000 * ${AARCH64_MMU_TRANSLATION_TABLE_PAGES} + RAM_MMU : ORIGIN = ${BSP_RK3399_RAM_BASE} + ${BSP_RK3399_RAM_LENGTH} - (0x1000 * ${AARCH64_MMU_TRANSLATION_TABLE_PAGES}) - ${BSP_RK3399_NOCACHE_LENGTH}, LENGTH = 0x1000 * ${AARCH64_MMU_TRANSLATION_TABLE_PAGES} + NOCACHE : ORIGIN = ${BSP_RK3399_RAM_BASE} + ${BSP_RK3399_RAM_LENGTH} - ${BSP_RK3399_NOCACHE_LENGTH}, LENGTH = ${BSP_RK3399_NOCACHE_LENGTH} + } + + REGION_ALIAS ("REGION_START", RAM); + REGION_ALIAS ("REGION_VECTOR", RAM); + REGION_ALIAS ("REGION_TEXT", RAM); + REGION_ALIAS ("REGION_TEXT_LOAD", RAM); + REGION_ALIAS ("REGION_RODATA", RAM); + REGION_ALIAS ("REGION_RODATA_LOAD", RAM); + REGION_ALIAS ("REGION_DATA", RAM); + REGION_ALIAS ("REGION_DATA_LOAD", RAM); + REGION_ALIAS ("REGION_FAST_TEXT", RAM); + REGION_ALIAS ("REGION_FAST_TEXT_LOAD", RAM); + REGION_ALIAS ("REGION_FAST_DATA", RAM); + REGION_ALIAS ("REGION_FAST_DATA_LOAD", RAM); + REGION_ALIAS ("REGION_BSS", RAM); + REGION_ALIAS ("REGION_WORK", RAM); + REGION_ALIAS ("REGION_STACK", RAM); + REGION_ALIAS ("REGION_NOCACHE", NOCACHE); + REGION_ALIAS ("REGION_NOCACHE_LOAD", NOCACHE); + + bsp_stack_exception_size = DEFINED (bsp_stack_exception_size) ? bsp_stack_exception_size : 1024; + + bsp_section_rwbarrier_align = DEFINED (bsp_section_rwbarrier_align) ? bsp_section_rwbarrier_align : 1M; + + bsp_vector_table_in_start_section = 1; + bsp_translation_table_base = ORIGIN (RAM_MMU); + bsp_translation_table_end = ORIGIN (RAM_MMU) + LENGTH (RAM_MMU); + + OUTPUT_FORMAT ("elf64-littleaarch64") + OUTPUT_ARCH (aarch64) + + INCLUDE linkcmds.base +copyrights: +- Copyright (C) 2026 Ning Yang +enabled-by: true +install-path: ${BSP_LIBDIR} +links: [] +target: linkcmds +type: build diff --git a/spec/build/bsps/aarch64/rk3399/obj.yml b/spec/build/bsps/aarch64/rk3399/obj.yml new file mode 100644 index 0000000000..f7e374870d --- /dev/null +++ b/spec/build/bsps/aarch64/rk3399/obj.yml @@ -0,0 +1,38 @@ +SPDX-License-Identifier: CC-BY-SA-4.0 OR BSD-2-Clause +build-type: objects +cflags: [] +copyrights: +- Copyright (C) 2026 Ning Yang +cppflags: [] +cxxflags: [] +enabled-by: true +includes: [] +install: +- destination: ${BSP_INCLUDEDIR} + source: + - bsps/aarch64/rk3399/include/bsp.h +- destination: ${BSP_INCLUDEDIR}/bsp + source: + - bsps/aarch64/rk3399/include/bsp/irq.h +links: +- role: build-dependency + uid: ../optmmupages +source: +- bsps/aarch64/rk3399/console/console.c +- bsps/aarch64/rk3399/start/bspstart.c +- bsps/aarch64/rk3399/start/bspstarthooks.c +- bsps/aarch64/rk3399/start/bspstartmmu.c +- bsps/aarch64/rk3399/start/mmu-config.c +- bsps/aarch64/shared/cache/cache.c +- bsps/aarch64/shared/mmu/mmu-setup.c +- bsps/aarch64/shared/mmu/vmsav8-64.c +- bsps/aarch64/shared/start/start-cpu-mpidr.S +- bsps/shared/dev/btimer/btimer-cpucounter.c +- bsps/shared/dev/getentropy/getentropy-cpucounter.c +- bsps/shared/dev/serial/console-termios-init.c +- bsps/shared/dev/serial/console-termios.c +- bsps/shared/irq/irq-default-handler.c +- bsps/shared/start/bspreset-arm-psci.S +- bsps/shared/start/gettargethash-default.c +- bsps/shared/start/sbrk.c +type: build diff --git a/spec/build/bsps/aarch64/rk3399/optconminor.yml b/spec/build/bsps/aarch64/rk3399/optconminor.yml new file mode 100644 index 0000000000..a75242e95a --- /dev/null +++ b/spec/build/bsps/aarch64/rk3399/optconminor.yml @@ -0,0 +1,17 @@ +SPDX-License-Identifier: CC-BY-SA-4.0 OR BSD-2-Clause +actions: +- get-integer: null +- define: null +build-type: option +copyrights: +- Copyright (C) 2026 Ning Yang +default: +- enabled-by: true + value: 2 +description: | + minor number of console device +enabled-by: true +format: '{}' +links: [] +name: BSP_CONSOLE_MINOR +type: build diff --git a/spec/build/bsps/aarch64/rk3399/optloadoff.yml b/spec/build/bsps/aarch64/rk3399/optloadoff.yml new file mode 100644 index 0000000000..ca4ffb40cb --- /dev/null +++ b/spec/build/bsps/aarch64/rk3399/optloadoff.yml @@ -0,0 +1,19 @@ +SPDX-License-Identifier: CC-BY-SA-4.0 OR BSD-2-Clause +actions: +- get-integer: null +- assert-uint32: null +- env-assign: null +- format-and-define: null +build-type: option +copyrights: +- Copyright (C) 2026 Ning Yang +default: +- enabled-by: true + value: 0x00200000 +description: | + offset of RAM region from memory area base +enabled-by: true +format: '{:#010x}' +links: [] +name: BSP_RK3399_LOAD_OFFSET +type: build diff --git a/spec/build/bsps/aarch64/rk3399/optnocachelen.yml b/spec/build/bsps/aarch64/rk3399/optnocachelen.yml new file mode 100644 index 0000000000..0d2d196fad --- /dev/null +++ b/spec/build/bsps/aarch64/rk3399/optnocachelen.yml @@ -0,0 +1,19 @@ +SPDX-License-Identifier: CC-BY-SA-4.0 OR BSD-2-Clause +actions: +- get-integer: null +- assert-uint32: null +- env-assign: null +- format-and-define: null +build-type: option +copyrights: +- Copyright (C) 2026 Ning Yang +default: +- enabled-by: true + value: 0x00100000 +description: | + length of nocache RAM region +enabled-by: true +format: '{:#010x}' +links: [] +name: BSP_RK3399_NOCACHE_LENGTH +type: build diff --git a/spec/build/bsps/aarch64/rk3399/optramlen.yml b/spec/build/bsps/aarch64/rk3399/optramlen.yml new file mode 100644 index 0000000000..6cd23f6c7c --- /dev/null +++ b/spec/build/bsps/aarch64/rk3399/optramlen.yml @@ -0,0 +1,19 @@ +SPDX-License-Identifier: CC-BY-SA-4.0 OR BSD-2-Clause +actions: +- get-integer: null +- assert-uint32: null +- env-assign: null +- format-and-define: null +build-type: option +copyrights: +- Copyright (C) 2026 Ning Yang +default: +- enabled-by: true + value: 0xf0efe000 +description: | + length of memory area available to the BSP +enabled-by: true +format: '{:#010x}' +links: [] +name: BSP_RK3399_RAM_LENGTH +type: build diff --git a/spec/build/bsps/aarch64/rk3399/optramori.yml b/spec/build/bsps/aarch64/rk3399/optramori.yml new file mode 100644 index 0000000000..eda8af3b16 --- /dev/null +++ b/spec/build/bsps/aarch64/rk3399/optramori.yml @@ -0,0 +1,19 @@ +SPDX-License-Identifier: CC-BY-SA-4.0 OR BSD-2-Clause +actions: +- get-integer: null +- assert-uint32: null +- env-assign: null +- format-and-define: null +build-type: option +copyrights: +- Copyright (C) 2026 Ning Yang +default: +- enabled-by: true + value: 0 +description: | + base address of memory area available to the BSP +enabled-by: true +format: '{:#010x}' +links: [] +name: BSP_RK3399_RAM_BASE +type: build diff --git a/spec/build/bsps/dev/irq/optarmgic-icc-bpr0.yml b/spec/build/bsps/dev/irq/optarmgic-icc-bpr0.yml index cb5fae34eb..289b946716 100644 --- a/spec/build/bsps/dev/irq/optarmgic-icc-bpr0.yml +++ b/spec/build/bsps/dev/irq/optarmgic-icc-bpr0.yml @@ -12,6 +12,7 @@ default: - aarch64/a72_ilp32_qemu - aarch64/a72_lp64_qemu - aarch64/raspberrypi4b + - aarch64/rk3399_rockpro64 - aarch64/versal_aiedge - aarch64/versal_qemu - aarch64/versal_vck190 diff --git a/spec/build/bsps/dev/irq/optarmgic-icc-igrpen0.yml b/spec/build/bsps/dev/irq/optarmgic-icc-igrpen0.yml index c9e8b576fa..88581fa8db 100644 --- a/spec/build/bsps/dev/irq/optarmgic-icc-igrpen0.yml +++ b/spec/build/bsps/dev/irq/optarmgic-icc-igrpen0.yml @@ -12,6 +12,7 @@ default: - aarch64/a72_ilp32_qemu - aarch64/a72_lp64_qemu - aarch64/raspberrypi4b + - aarch64/rk3399_rockpro64 - aarch64/versal_aiedge - aarch64/versal_qemu - aarch64/versal_vck190