Linux-EFI Archive mirror
 help / color / mirror / Atom feed
From: wangyao@lemote.com
To: ardb@kernel.org, chenhuacai@kernel.org, wangrui@loongson.cn
Cc: linux-efi@vger.kernel.org, ainux.wang@gmail.com,
	Wang Yao <wangyao@lemote.com>
Subject: [PATCH] efi/loongarch: Change MMU translation mode
Date: Wed, 22 Nov 2023 16:49:06 +0800	[thread overview]
Message-ID: <20231122084906.12476-1-wangyao@lemote.com> (raw)

From: Wang Yao <wangyao@lemote.com>

Refer ot UEFI spec v2.10 section 2.3.8 LoongArch Platforms:

The processor is in the following execution mode during boot service:
    ...
    The memory is in physical addressing mode. LoongArch architecture
    defines two memory access mode, namely direct address translation
    mode and mapped address translation mode.

So need to change MMU translation mode before config direct mapping.

Signed-off-by: Wang Yao <wangyao@lemote.com>
---
 drivers/firmware/efi/libstub/loongarch.c | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/drivers/firmware/efi/libstub/loongarch.c b/drivers/firmware/efi/libstub/loongarch.c
index 807cba2693fc..4c0a84c58f5b 100644
--- a/drivers/firmware/efi/libstub/loongarch.c
+++ b/drivers/firmware/efi/libstub/loongarch.c
@@ -49,7 +49,7 @@ efi_status_t efi_boot_kernel(void *handle, efi_loaded_image_t *image,
 	struct exit_boot_struct priv;
 	unsigned long desc_size;
 	efi_status_t status;
-	u32 desc_ver;
+	u32 desc_ver, val;
 
 	status = efi_alloc_virtmap(&priv.runtime_map, &desc_size, &desc_ver);
 	if (status != EFI_SUCCESS) {
@@ -69,6 +69,12 @@ efi_status_t efi_boot_kernel(void *handle, efi_loaded_image_t *image,
 		    priv.runtime_entry_count * desc_size, desc_size,
 		    desc_ver, priv.runtime_map);
 
+	/* Change address translation mode */
+	val = csr_read32(LOONGARCH_CSR_CRMD);
+	val &= ~CSR_CRMD_DA;
+	val |= CSR_CRMD_PG;
+	csr_write32(val, LOONGARCH_CSR_CRMD);
+
 	/* Config Direct Mapping */
 	csr_write64(CSR_DMW0_INIT, LOONGARCH_CSR_DMWIN0);
 	csr_write64(CSR_DMW1_INIT, LOONGARCH_CSR_DMWIN1);
-- 
2.27.0


             reply	other threads:[~2023-11-22  8:50 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-11-22  8:49 wangyao [this message]
2023-11-22 14:22 ` [PATCH] efi/loongarch: Change MMU translation mode Huacai Chen
2023-11-23  0:22   ` Ainux Wang
2023-11-23  4:05     ` Huacai Chen
2023-11-23  7:05       ` Ainux Wang
2023-11-23  7:49         ` Huacai Chen

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=20231122084906.12476-1-wangyao@lemote.com \
    --to=wangyao@lemote.com \
    --cc=ainux.wang@gmail.com \
    --cc=ardb@kernel.org \
    --cc=chenhuacai@kernel.org \
    --cc=linux-efi@vger.kernel.org \
    --cc=wangrui@loongson.cn \
    /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;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).