diff --git a/arch/arm64/Kconfig b/arch/arm64/Kconfig index 2f0251ec546..84b3c1dfe03 100644 --- a/arch/arm64/Kconfig +++ b/arch/arm64/Kconfig @@ -66,6 +66,22 @@ config ARCH_CHIP_RK3399 ---help--- Rockchip RK3399 SoC +config ARCH_CHIP_RK3588 + bool "Rockchip RK3588 / RK3588S" + select ARCH_CORTEX_A55 + select ARCH_HAVE_ADDRENV + select ARCH_HAVE_IRQPRIO + select ARCH_HAVE_IRQTRIGGER + select ARCH_HAVE_LOWPUTC + select ARCH_HAVE_RESET + select ARCH_NEED_ADDRENV_MAPPING + select ARCH_USE_MMU + select ARM64_HAVE_PSCI + select ARMV8A_HAVE_GICv3 + ---help--- + Rockchip RK3588 and RK3588S SoCs with GICv3, PSCI and early + UART support. + config ARCH_CHIP_QEMU bool "QEMU virt platform (ARMv8a)" select ARCH_HAVE_ADDRENV @@ -383,6 +399,7 @@ config ARCH_CHIP default "a64" if ARCH_CHIP_A64 default "a527" if ARCH_CHIP_SUNXI_A527 default "rk3399" if ARCH_CHIP_RK3399 + default "rk3588" if ARCH_CHIP_RK3588 default "zynq-mpsoc" if ARCH_CHIP_ZYNQ_MPSOC default "qemu" if ARCH_CHIP_QEMU default "goldfish" if ARCH_CHIP_GOLDFISH @@ -536,6 +553,10 @@ if ARCH_CHIP_RK3399 source "arch/arm64/src/rk3399/Kconfig" endif +if ARCH_CHIP_RK3588 +source "arch/arm64/src/rk3588/Kconfig" +endif + if ARCH_CHIP_QEMU source "arch/arm64/src/qemu/Kconfig" endif diff --git a/arch/arm64/include/rk3588/chip.h b/arch/arm64/include/rk3588/chip.h new file mode 100644 index 00000000000..7d02f33e651 --- /dev/null +++ b/arch/arm64/include/rk3588/chip.h @@ -0,0 +1,79 @@ +/**************************************************************************** + * arch/arm64/include/rk3588/chip.h + * + * SPDX-License-Identifier: Apache-2.0 + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. The + * ASF licenses this file to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance with the + * License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations + * under the License. + * + ****************************************************************************/ + +#ifndef __ARCH_ARM64_INCLUDE_RK3588_CHIP_H +#define __ARCH_ARM64_INCLUDE_RK3588_CHIP_H + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include + +/**************************************************************************** + * Pre-processor Definitions + ****************************************************************************/ + +/* Rockchip RK3588 / RK3588S GICv3 base addresses. The upstream device tree + * places the distributor at 0xfe600000 and the redistributor window at + * 0xfe680000. + */ + +#define CONFIG_GICD_BASE 0xfe600000 +#define CONFIG_GICD_SIZE 0x00010000 +#define CONFIG_GICR_BASE 0xfe680000 +#define CONFIG_GICR_SIZE 0x00100000 +#define CONFIG_GICR_OFFSET 0x20000 + +/* U-Boot relocates the ARM64 Image from kernel_addr_r to 0x02080000. The + * initial port uses the 512 MiB window validated on the 4 GiB board. + */ + +#define CONFIG_RAMBANK1_ADDR CONFIG_RAM_START +#define CONFIG_RAMBANK1_SIZE CONFIG_RAM_SIZE + +/* The UART register window is 0x100 bytes in the upstream device tree. The + * MMU maps it as one 4 KiB page, its minimum mapping granularity. + */ + +#define RK3588_UART_MMU_SIZE 0x1000 + +/* Address at which U-Boot enters NuttX after Image relocation. */ + +#define CONFIG_LOAD_BASE CONFIG_RAM_START + +#define MPID_TO_CLUSTER_ID(mpid) ((mpid) & ~0xff) + +/**************************************************************************** + * Assembly Macros + ****************************************************************************/ + +#ifdef __ASSEMBLY__ + +.macro get_cpu_id xreg0 + mrs \xreg0, mpidr_el1 + ubfx \xreg0, \xreg0, #0, #8 +.endm + +#endif /* __ASSEMBLY__ */ + +#endif /* __ARCH_ARM64_INCLUDE_RK3588_CHIP_H */ diff --git a/arch/arm64/include/rk3588/irq.h b/arch/arm64/include/rk3588/irq.h new file mode 100644 index 00000000000..901e8958232 --- /dev/null +++ b/arch/arm64/include/rk3588/irq.h @@ -0,0 +1,44 @@ +/**************************************************************************** + * arch/arm64/include/rk3588/irq.h + * + * SPDX-License-Identifier: Apache-2.0 + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. The + * ASF licenses this file to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance with the + * License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations + * under the License. + * + ****************************************************************************/ + +/* This file should never be included directly but, rather, only indirectly + * through nuttx/irq.h + */ + +#ifndef __ARCH_ARM64_INCLUDE_RK3588_IRQ_H +#define __ARCH_ARM64_INCLUDE_RK3588_IRQ_H + +/**************************************************************************** + * Pre-processor Definitions + ****************************************************************************/ + +/* Size the IRQ table to cover the highest SPI currently described by the + * upstream RK3588 device tree. SPI 400 has GIC interrupt ID 432. + */ + +#define NR_IRQS 512 + +/* GIC interrupt IDs are the device-tree SPI number plus 32. */ + +#define RK3588_IRQ_UART2 365 /* GIC_SPI 333 */ + +#endif /* __ARCH_ARM64_INCLUDE_RK3588_IRQ_H */ diff --git a/arch/arm64/src/rk3588/CMakeLists.txt b/arch/arm64/src/rk3588/CMakeLists.txt new file mode 100644 index 00000000000..1456a160804 --- /dev/null +++ b/arch/arm64/src/rk3588/CMakeLists.txt @@ -0,0 +1,29 @@ +# ############################################################################## +# arch/arm64/src/rk3588/CMakeLists.txt +# +# SPDX-License-Identifier: Apache-2.0 +# +# Licensed to the Apache Software Foundation (ASF) under one or more contributor +# license agreements. See the NOTICE file distributed with this work for +# additional information regarding copyright ownership. The ASF licenses this +# file to you under the Apache License, Version 2.0 (the "License"); you may not +# use this file except in compliance with the License. You may obtain a copy of +# the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations under +# the License. +# +# ############################################################################## + +set(SRCS rk3588_boot.c rk3588_serial.c) + +if(CONFIG_ARCH_EARLY_PRINT) + list(APPEND SRCS rk3588_lowputc.S) +endif() + +target_sources(arch PRIVATE ${SRCS}) diff --git a/arch/arm64/src/rk3588/Kconfig b/arch/arm64/src/rk3588/Kconfig new file mode 100644 index 00000000000..a75262c35ba --- /dev/null +++ b/arch/arm64/src/rk3588/Kconfig @@ -0,0 +1,7 @@ +# +# For a description of the syntax of this configuration file, +# see the file kconfig-language.txt in the NuttX tools repository. +# + +if ARCH_CHIP_RK3588 +endif # ARCH_CHIP_RK3588 diff --git a/arch/arm64/src/rk3588/Make.defs b/arch/arm64/src/rk3588/Make.defs new file mode 100644 index 00000000000..942f6508273 --- /dev/null +++ b/arch/arm64/src/rk3588/Make.defs @@ -0,0 +1,31 @@ +############################################################################ +# arch/arm64/src/rk3588/Make.defs +# +# SPDX-License-Identifier: Apache-2.0 +# +# Licensed to the Apache Software Foundation (ASF) under one or more +# contributor license agreements. See the NOTICE file distributed with +# this work for additional information regarding copyright ownership. The +# ASF licenses this file to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance with the +# License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations +# under the License. +# +############################################################################ + +include common/Make.defs + +# C Source Files specific to SoC + +CHIP_CSRCS = rk3588_boot.c rk3588_serial.c + +ifeq ($(CONFIG_ARCH_EARLY_PRINT),y) +CHIP_ASRCS = rk3588_lowputc.S +endif diff --git a/arch/arm64/src/rk3588/chip.h b/arch/arm64/src/rk3588/chip.h new file mode 100644 index 00000000000..428d5ec5a73 --- /dev/null +++ b/arch/arm64/src/rk3588/chip.h @@ -0,0 +1,36 @@ +/**************************************************************************** + * arch/arm64/src/rk3588/chip.h + * + * SPDX-License-Identifier: Apache-2.0 + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. The + * ASF licenses this file to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance with the + * License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations + * under the License. + * + * Thin source-side wrapper that pulls in the RK3588 chip definitions from + * the arch include tree. Common arm64 sources in this directory include + * "chip.h" directly. + * + ****************************************************************************/ + +#ifndef __ARCH_ARM64_SRC_RK3588_CHIP_H +#define __ARCH_ARM64_SRC_RK3588_CHIP_H + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include + +#endif /* __ARCH_ARM64_SRC_RK3588_CHIP_H */ diff --git a/arch/arm64/src/rk3588/rk3588_boot.c b/arch/arm64/src/rk3588/rk3588_boot.c new file mode 100644 index 00000000000..aed9f15903d --- /dev/null +++ b/arch/arm64/src/rk3588/rk3588_boot.c @@ -0,0 +1,102 @@ +/**************************************************************************** + * arch/arm64/src/rk3588/rk3588_boot.c + * + * SPDX-License-Identifier: Apache-2.0 + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. The + * ASF licenses this file to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance with the + * License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations + * under the License. + * + ****************************************************************************/ + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include + +#include + +#ifdef CONFIG_SMP +# include "arm64_smp.h" +#endif + +#include "arm64_arch.h" +#include "arm64_internal.h" +#include "arm64_mmu.h" +#include "rk3588_boot.h" + +/**************************************************************************** + * Private Data + ****************************************************************************/ + +static const struct arm_mmu_region g_mmu_regions[] = +{ + MMU_REGION_FLAT_ENTRY("UART2", + CONFIG_16550_UART0_BASE, RK3588_UART_MMU_SIZE, + MT_DEVICE_NGNRNE | MT_RW | MT_SECURE), + + MMU_REGION_FLAT_ENTRY("GICD", + CONFIG_GICD_BASE, CONFIG_GICD_SIZE, + MT_DEVICE_NGNRNE | MT_RW | MT_SECURE), + + MMU_REGION_FLAT_ENTRY("GICR", + CONFIG_GICR_BASE, CONFIG_GICR_SIZE, + MT_DEVICE_NGNRNE | MT_RW | MT_SECURE), + + MMU_REGION_FLAT_ENTRY("DRAM0_S0", + CONFIG_RAMBANK1_ADDR, CONFIG_RAMBANK1_SIZE, + MT_NORMAL | MT_RW | MT_SECURE), +}; + +const struct arm_mmu_config g_mmu_config = +{ + .num_regions = nitems(g_mmu_regions), + .mmu_regions = g_mmu_regions, +}; + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +void arm64_el_init(void) +{ + /* The supported firmware handoff needs no platform-specific setup here. */ +} + +void arm64_chip_boot(void) +{ + rk3588_memory_initialize(); + + /* Map I/O and DRAM, then enable the MMU. */ + + arm64_mmu_init(true); + +#if defined(CONFIG_ARM64_PSCI) + arm64_psci_init("smc"); +#endif + + rk3588_board_initialize(); + +#ifdef USE_EARLYSERIALINIT + arm64_earlyserialinit(); +#endif +} + +#if defined(CONFIG_NET) && !defined(CONFIG_NETDEV_LATEINIT) +void arm64_netinitialize(void) +{ + /* Network initialization is not implemented. */ +} +#endif diff --git a/arch/arm64/src/rk3588/rk3588_boot.h b/arch/arm64/src/rk3588/rk3588_boot.h new file mode 100644 index 00000000000..0ac4a1a66fe --- /dev/null +++ b/arch/arm64/src/rk3588/rk3588_boot.h @@ -0,0 +1,56 @@ +/**************************************************************************** + * arch/arm64/src/rk3588/rk3588_boot.h + * + * SPDX-License-Identifier: Apache-2.0 + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. The + * ASF licenses this file to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance with the + * License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations + * under the License. + * + ****************************************************************************/ + +#ifndef __ARCH_ARM64_SRC_RK3588_RK3588_BOOT_H +#define __ARCH_ARM64_SRC_RK3588_RK3588_BOOT_H + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include + +/**************************************************************************** + * Public Function Prototypes + ****************************************************************************/ + +#ifndef __ASSEMBLY__ + +#undef EXTERN +#if defined(__cplusplus) +# define EXTERN extern "C" +extern "C" +{ +#else +# define EXTERN extern +#endif + +void rk3588_memory_initialize(void); +void rk3588_board_initialize(void); + +#undef EXTERN +#if defined(__cplusplus) +} +#endif + +#endif /* __ASSEMBLY__ */ +#endif /* __ARCH_ARM64_SRC_RK3588_RK3588_BOOT_H */ diff --git a/arch/arm64/src/rk3588/rk3588_lowputc.S b/arch/arm64/src/rk3588/rk3588_lowputc.S new file mode 100644 index 00000000000..9efc13169b7 --- /dev/null +++ b/arch/arm64/src/rk3588/rk3588_lowputc.S @@ -0,0 +1,63 @@ +/**************************************************************************** + * arch/arm64/src/rk3588/rk3588_lowputc.S + * + * SPDX-License-Identifier: Apache-2.0 + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. The + * ASF licenses this file to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance with the + * License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations + * under the License. + * + **************************************************************************** + * + * DESCRIPTION + * Early UART output for RK3588 / RK3588S. + * + * The Orange Pi 5 Pro debug UART is UART2, a 16550-compatible block + * with 4-byte register spacing. Boot firmware already leaves it in a + * usable state, so early printk only needs to poll THRE and write bytes. + * + ****************************************************************************/ + +#include + +#include "arm64_macro.inc" + + .file "rk3588_lowputc.S" + +#define CONSOLE_UART_BASE CONFIG_16550_UART0_BASE +#define UART_THR_OFF 0x00 +#define UART_LSR_OFF 0x14 +#define UART_LSR_THRE (1 << 5) + +.macro early_uart_ready xb, wt +1: + ldr \wt, [\xb, #UART_LSR_OFF] + tst \wt, #UART_LSR_THRE + b.eq 1b +.endm + +.macro early_uart_transmit xb, wt + str \wt, [\xb, #UART_THR_OFF] +.endm + +GTEXT(arm64_earlyprintinit) +SECTION_FUNC(text, arm64_earlyprintinit) + ret + +GTEXT(arm64_lowputc) +SECTION_FUNC(text, arm64_lowputc) + ldr x15, =CONSOLE_UART_BASE + early_uart_ready x15, w2 + early_uart_transmit x15, w0 + ret diff --git a/arch/arm64/src/rk3588/rk3588_serial.c b/arch/arm64/src/rk3588/rk3588_serial.c new file mode 100644 index 00000000000..b424b77c386 --- /dev/null +++ b/arch/arm64/src/rk3588/rk3588_serial.c @@ -0,0 +1,54 @@ +/**************************************************************************** + * arch/arm64/src/rk3588/rk3588_serial.c + * + * SPDX-License-Identifier: Apache-2.0 + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. The + * ASF licenses this file to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance with the + * License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations + * under the License. + * + ****************************************************************************/ + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include + +#ifdef CONFIG_16550_UART + +#include + +#include "arm64_internal.h" + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +void arm64_earlyserialinit(void) +{ + /* The Orange Pi boot chain already programs the console UART. Preserve + * that state and let the generic 16550 driver take over without forcing + * a baud-rate reprogramming step. + */ + + u16550_earlyserialinit(); +} + +void arm64_serialinit(void) +{ + u16550_serialinit(); +} + +#endif /* CONFIG_16550_UART */