All of lore.kernel.org
 help / color / mirror / Atom feed
From: Balaji Selvanathan via U-Boot <u-boot@lists.u-boot-project.org>
To: u-boot@lists.u-boot-project.org,
	Sumit Garg <sumit.garg@kernel.org>,
	u-boot-qcom@groups.io
Cc: Rayagonda Kokatanur <rayagonda.kokatanur@broadcom.com>,
	Tom Rini <trini@konsulko.com>,
	Ilias Apalodimas <ilias.apalodimas@linaro.org>,
	Casey Connolly <casey.connolly@linaro.org>,
	Neil Armstrong <neil.armstrong@linaro.org>,
	Johan Jonker <jbx6244@gmail.com>,
	Tien Fong Chee <tien.fong.chee@altera.com>,
	Michael Srba <Michael.Srba@seznam.cz>,
	Sumit Garg <sumit.garg@oss.qualcomm.com>,
	Aswin Murugan <aswin.murugan@oss.qualcomm.com>,
	Balaji Selvanathan <balaji.selvanathan@oss.qualcomm.com>
Subject: [PATCH v6 3/8] arm: snapdragon: Disable MMU early before U-Boot reset vector
Date: Mon, 03 Aug 2026 21:28:48 +0530	[thread overview]
Message-ID: <20260803-snagboot-v6-3-e8bf7a6fc0a4@oss.qualcomm.com> (raw)
In-Reply-To: <20260803-snagboot-v6-0-e8bf7a6fc0a4@oss.qualcomm.com>

When U-Boot is loaded by XBL in Snagboot mode, XBL leaves the MMU
enabled with its own page tables. This causes stale TLB entries and
incorrect memory mappings when U-Boot initializes its own MMU.

Disable the MMU and invalidate TLBs before branching to the
reset vector. This ensures a clean MMU state for U-Boot initialization
in Snagboot mode.

Signed-off-by: Balaji Selvanathan <balaji.selvanathan@oss.qualcomm.com>
---
Changes iv v5:
- Clear C bit (Dcache enable) also during MMU disable

Changes iv v4:
- Remove handling for EL1 or EL2 entry as for Snagboot we would
  only enter U-Boot in EL3 from previous bootloader

Changes in v3:
- Brought the MMU disable logic under CONFIG_QCOM_SNAGBOOT_SUPPORT
  ifdef condition
- Moved the MMU disable codes to a new seperate file

Changes in v2:
- Newly introduced in v2
---
 arch/arm/mach-snapdragon/include/mach/boot0.h      |  2 ++
 .../mach-snapdragon/include/mach/snagboot_boot0.h  | 27 ++++++++++++++++++++++
 2 files changed, 29 insertions(+)

diff --git a/arch/arm/mach-snapdragon/include/mach/boot0.h b/arch/arm/mach-snapdragon/include/mach/boot0.h
index b3c76d6d97d..a4eb5723d2e 100644
--- a/arch/arm/mach-snapdragon/include/mach/boot0.h
+++ b/arch/arm/mach-snapdragon/include/mach/boot0.h
@@ -4,6 +4,8 @@
 #else
 #if defined(CONFIG_BOOT0_MSM8916_PSCI_WORKAROUND)
 #include "msm8916_boot0.h"
+#elif defined(CONFIG_QCOM_BOOT0_SNAGBOOT_MODE)
+#include "snagboot_boot0.h"
 #else
 	b	reset
 #endif
diff --git a/arch/arm/mach-snapdragon/include/mach/snagboot_boot0.h b/arch/arm/mach-snapdragon/include/mach/snagboot_boot0.h
new file mode 100644
index 00000000000..f82ee87c9b9
--- /dev/null
+++ b/arch/arm/mach-snapdragon/include/mach/snagboot_boot0.h
@@ -0,0 +1,27 @@
+/* SPDX-License-Identifier: GPL-2.0+ */
+/*
+ * Early MMU Disable for Snagboot Mode
+ *
+ * Disable MMU at the earliest possible point for EL3 entry.
+ * Snagboot mode always enters U-Boot at EL3.
+ *
+ * After disabling MMU, invalidate TLB to clear any stale entries that might
+ * cause issues when MMU is re-enabled later.
+ */
+
+	mrs	x0, CurrentEL
+	cmp	x0, #(3 << 2)	/* Verify EL3 entry */
+	b.ne	reset		/* Unexpected: not at EL3 */
+
+	/* Disable MMU at EL3 */
+	mrs	x0, sctlr_el3
+	bic	x0, x0, #1	/* Clear M bit (MMU enable) */
+	bic	x0, x0, #(1 << 2)   /* Clear C bit (Dcache enable) */
+	bic	x0, x0, #(1 << 19)  /* Clear WXN bit (Write XOR Execute) */
+	msr	sctlr_el3, x0
+	isb
+	/* Invalidate entire TLB for all ELs */
+	tlbi	alle3
+	dsb	sy
+	isb
+	b	reset
\ No newline at end of file

-- 
2.34.1


  parent reply	other threads:[~2026-08-03 15:59 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-08-03 15:58 [PATCH v6 0/8] arm: snapdragon: Add snagboot support for Lemans-EVK Balaji Selvanathan via U-Boot
2026-08-03 15:58 ` [PATCH v6 1/8] arm: snapdragon: Make SYSRESET_PSCI optional Balaji Selvanathan via U-Boot
2026-08-03 15:58 ` [PATCH v6 2/8] arm: snapdragon: Guard PSCI functions with CONFIG_ARM_SMCCC Balaji Selvanathan via U-Boot
2026-08-03 15:58 ` Balaji Selvanathan via U-Boot [this message]
2026-08-03 15:58 ` [PATCH v6 4/8] arm: snapdragon: Add CONFIG_QCOM_SNAGBOOT_MODE option Balaji Selvanathan via U-Boot
2026-08-03 15:58 ` [PATCH v6 5/8] soc: qcom: cmd-db: Allow boot without CMD DB data Balaji Selvanathan via U-Boot
2026-08-03 15:58 ` [PATCH v6 6/8] arch: arm: dts: remove Lemans EVK override DTS Balaji Selvanathan via U-Boot
2026-08-03 15:58 ` [PATCH v6 7/8] configs: add qcom_lemans_snagboot_defconfig for Lemans-EVK Balaji Selvanathan via U-Boot
2026-08-03 15:58 ` [PATCH v6 8/8] doc: qualcomm: Add snagboot mode documentation Balaji Selvanathan via U-Boot

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=20260803-snagboot-v6-3-e8bf7a6fc0a4@oss.qualcomm.com \
    --to=u-boot@lists.u-boot-project.org \
    --cc=Michael.Srba@seznam.cz \
    --cc=aswin.murugan@oss.qualcomm.com \
    --cc=balaji.selvanathan@oss.qualcomm.com \
    --cc=casey.connolly@linaro.org \
    --cc=ilias.apalodimas@linaro.org \
    --cc=jbx6244@gmail.com \
    --cc=neil.armstrong@linaro.org \
    --cc=rayagonda.kokatanur@broadcom.com \
    --cc=sumit.garg@kernel.org \
    --cc=sumit.garg@oss.qualcomm.com \
    --cc=tien.fong.chee@altera.com \
    --cc=trini@konsulko.com \
    --cc=u-boot-qcom@groups.io \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.