Devicetree
 help / color / mirror / Atom feed
From: "Vítor Hugo Silva" <vitorhg20080@gmail.com>
To: linux-riscv@lists.infradead.org
Cc: devicetree@vger.kernel.org, linux-kernel@vger.kernel.org,
	Rob Herring <robh@kernel.org>,
	Krzysztof Kozlowski <krzk+dt@kernel.org>,
	Conor Dooley <conor+dt@kernel.org>,
	Paul Walmsley <pjw@kernel.org>,
	Palmer Dabbelt <palmer@dabbelt.com>,
	Albert Ou <aou@eecs.berkeley.edu>,
	Alexandre Ghiti <alex@ghiti.fr>
Subject: [PATCH RFC 01/19] riscv: Prepare ESP32-P4 early CLIC trap vectors
Date: Wed, 25 Nov 2026 23:30:02 +0000	[thread overview]
Message-ID: <20261125233020.1380594-2-vitorhg20080@gmail.com> (raw)
In-Reply-To: <20261125233020.1380594-1-vitorhg20080@gmail.com>

The ESP32-P4 HP cores run with mtvec.MODE fixed to CLIC. The legacy
mie and mip CSRs cannot mask CLIC interrupts, and mtvec.BASE requires
64-byte alignment.

Add an opt-in configuration for RV32, single-hart M-mode. Mask local
interrupts through mstatus.MIE at kernel entry. Align the early park,
PMP probe and normal exception vectors to 64 bytes.

AI assisted with the trap entry changes and elaborate the help
description.

Link: https://documentation.espressif.com/esp32-p4_technical_reference_manual_en.pdf
Signed-off-by: Vítor Hugo Silva <vitorhg20080@gmail.com>
---
 arch/riscv/Kconfig.socs   |  9 +++++++++
 arch/riscv/kernel/entry.S |  6 ++++++
 arch/riscv/kernel/head.S  | 13 +++++++++++++
 3 files changed, 28 insertions(+)

diff --git a/arch/riscv/Kconfig.socs b/arch/riscv/Kconfig.socs
index cecbce0c4983..0272923c7d88 100644
--- a/arch/riscv/Kconfig.socs
+++ b/arch/riscv/Kconfig.socs
@@ -12,6 +12,15 @@ config ARCH_ANLOGIC
 	help
 	  This enables support for Anlogic SoC platform hardware.
 
+config RISCV_ESP32P4_CLIC
+	bool "Espressif ESP32-P4 early CLIC setup"
+	depends on ARCH_RV32I && RISCV_M_MODE && !SMP
+	help
+	  Enable early machine-mode trap setup for a single ESP32-P4 hart.
+	  This aligns the trap vectors to 64 bytes as required by the CLIC.
+	  During kernel entry, it clears mstatus.MIE to mask interrupts,
+	  since the legacy mie and mip CSRs do not control the CLIC.
+
 config ARCH_ESWIN
 	bool "ESWIN SoCs"
 	help
diff --git a/arch/riscv/kernel/entry.S b/arch/riscv/kernel/entry.S
index 61b7a7716697..f659bf62bb39 100644
--- a/arch/riscv/kernel/entry.S
+++ b/arch/riscv/kernel/entry.S
@@ -125,7 +125,13 @@
 		CONFIG_RISCV_USER_CFI)
 .endm
 
+#ifdef CONFIG_RISCV_ESP32P4_CLIC
+	/* mtvec.BASE starts at bit 6 in CLIC mode. */
+	.balign 64
+SYM_CODE_START_NOALIGN(handle_exception)
+#else
 SYM_CODE_START(handle_exception)
+#endif
 	/*
 	 * If coming from userspace, preserve the user thread pointer and load
 	 * the kernel thread pointer.  If we came from the kernel, the scratch
diff --git a/arch/riscv/kernel/head.S b/arch/riscv/kernel/head.S
index 1631fd6bc786..f266c4238b2f 100644
--- a/arch/riscv/kernel/head.S
+++ b/arch/riscv/kernel/head.S
@@ -183,7 +183,11 @@ secondary_start_sbi:
 	call smp_callin
 #endif /* CONFIG_SMP */
 
+#ifdef CONFIG_RISCV_ESP32P4_CLIC
+.balign 64
+#else
 .align 2
+#endif
 .Lsecondary_park:
 	/*
 	 * Park this hart if we:
@@ -210,9 +214,14 @@ secondary_start_sbi:
 SYM_CODE_END(_start)
 
 SYM_CODE_START(_start_kernel)
+#ifdef CONFIG_RISCV_ESP32P4_CLIC
+	/* The CLIC uses mstatus.MIE to mask interrupts globally. */
+	csrci CSR_STATUS, SR_IE
+#else
 	/* Mask all interrupts */
 	csrw CSR_IE, zero
 	csrw CSR_IP, zero
+#endif
 
 #ifdef CONFIG_RISCV_M_MODE
 	/* flush the instruction cache */
@@ -233,7 +242,11 @@ SYM_CODE_START(_start_kernel)
 	csrw CSR_PMPADDR0, a0
 	li a0, (PMP_A_NAPOT | PMP_R | PMP_W | PMP_X)
 	csrw CSR_PMPCFG0, a0
+#ifdef CONFIG_RISCV_ESP32P4_CLIC
+.balign 64
+#else
 .align 2
+#endif
 .Lpmp_done:
 
 	/*
-- 
2.56.1


  reply	other threads:[~2026-11-25 23:30 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-25 23:30 [PATCH RFC 00/19] riscv: Add initial support for Espressif ESP32-P4 Vítor Hugo Silva
2026-11-25 23:30 ` Vítor Hugo Silva [this message]
2026-11-25 23:30 ` [PATCH RFC 02/19] riscv: Handle ESP32-P4 CLIC trap context Vítor Hugo Silva
2026-11-25 23:30 ` [PATCH RFC 03/19] dt-bindings: interrupt-controller: Add Espressif ESP32-P4 CLIC Vítor Hugo Silva
2026-11-25 23:30 ` [PATCH RFC 04/19] irqchip: Add Espressif ESP32-P4 CLIC support Vítor Hugo Silva
2026-11-25 23:30 ` [PATCH RFC 05/19] dt-bindings: interrupt-controller: Add Espressif ESP32-P4 interrupt matrix Vítor Hugo Silva
2026-11-25 23:30 ` [PATCH RFC 06/19] irqchip: Add Espressif ESP32-P4 interrupt matrix support Vítor Hugo Silva
2026-11-25 23:30 ` [PATCH RFC 07/19] dt-bindings: timer: Add Espressif ESP32-P4 CLINT Vítor Hugo Silva
2026-11-25 23:30 ` [PATCH RFC 08/19] clocksource/drivers/timer-clint: Add Espressif ESP32-P4 support Vítor Hugo Silva
2026-11-25 23:30 ` [PATCH RFC 09/19] dt-bindings: serial: Add Espressif ESP32-P4 UART Vítor Hugo Silva
2026-11-25 23:30 ` [PATCH RFC 10/19] serial: esp32: Restore the ESP32 UART driver Vítor Hugo Silva
2026-11-25 23:30 ` [PATCH RFC 11/19] serial: esp32: Add support for the ESP32-P4 UART Vítor Hugo Silva
2026-11-25 23:30 ` [PATCH RFC 12/19] serial: esp32: Rearm TX interrupts when the FIFO is full Vítor Hugo Silva
2026-11-25 23:30 ` [PATCH RFC 13/19] serial: esp32: Add early console support for ESP32-P4 Vítor Hugo Silva
2026-11-25 23:30 ` [PATCH RFC 14/19] riscv: Synchronize instructions written to ESP32-P4 PSRAM Vítor Hugo Silva
2026-11-25 23:30 ` [PATCH RFC 15/19] riscv: Align init data to the ESP32-P4 PMP granularity Vítor Hugo Silva
2026-11-25 23:30 ` [PATCH RFC 16/19] dt-bindings: riscv: Add Waveshare ESP32-P4-Module-DEV-KIT Vítor Hugo Silva
2026-11-25 23:30 ` [PATCH RFC 17/19] dt-bindings: riscv: cpus: Document Espressif ESP32-P4 HP harts Vítor Hugo Silva
2026-11-25 23:30 ` [PATCH RFC 18/19] riscv: dts: Add Waveshare ESP32-P4-Module-DEV-KIT Vítor Hugo Silva
2026-11-25 23:30 ` [PATCH RFC 19/19] MAINTAINERS: Add the Espressif ESP32-P4 platform Vítor Hugo Silva

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20261125233020.1380594-2-vitorhg20080@gmail.com \
    --to=vitorhg20080@gmail.com \
    --cc=alex@ghiti.fr \
    --cc=aou@eecs.berkeley.edu \
    --cc=conor+dt@kernel.org \
    --cc=devicetree@vger.kernel.org \
    --cc=krzk+dt@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-riscv@lists.infradead.org \
    --cc=palmer@dabbelt.com \
    --cc=pjw@kernel.org \
    --cc=robh@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox