linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Christophe Leroy <christophe.leroy@c-s.fr>
To: Benjamin Herrenschmidt <benh@kernel.crashing.org>,
	Paul Mackerras <paulus@samba.org>,
	Michael Ellerman <mpe@ellerman.id.au>
Cc: linux-kernel@vger.kernel.org, linuxppc-dev@lists.ozlabs.org
Subject: [PATCH v1 32/46] powerpc/8xx: Don't set IMMR map anymore at boot
Date: Mon, 16 Mar 2020 12:36:18 +0000 (UTC)	[thread overview]
Message-ID: <4f5a73b921b164be820b24ecaa74622cc2e6e9b8.1584360344.git.christophe.leroy@c-s.fr> (raw)
In-Reply-To: <cover.1584360343.git.christophe.leroy@c-s.fr>

Only early debug requires IMMR to be mapped early.

No need to set it up and pin it in assembly. Map it
through page tables at udbg init when necessary.

If CONFIG_PIN_TLB_IMMR is selected, pin it once we
don't need the 32 Mb pinned RAM anymore.

Signed-off-by: Christophe Leroy <christophe.leroy@c-s.fr>
---
 arch/powerpc/kernel/head_8xx.S     | 36 ++++++++++++------------------
 arch/powerpc/mm/mmu_decl.h         |  4 ++++
 arch/powerpc/mm/nohash/8xx.c       | 15 +++++++++----
 arch/powerpc/platforms/8xx/Kconfig |  2 +-
 arch/powerpc/sysdev/cpm_common.c   |  2 ++
 5 files changed, 32 insertions(+), 27 deletions(-)

diff --git a/arch/powerpc/kernel/head_8xx.S b/arch/powerpc/kernel/head_8xx.S
index 84b3c7692b37..6a1a74e9b011 100644
--- a/arch/powerpc/kernel/head_8xx.S
+++ b/arch/powerpc/kernel/head_8xx.S
@@ -748,6 +748,20 @@ start_here:
 	rfi
 /* Load up the kernel context */
 2:
+#ifdef CONFIG_PIN_TLB_IMMR
+	mfspr	r0, SPRN_MD_CTR
+	ori	r0, r0, 0x1f00
+	mtspr	SPRN_MD_CTR, r0
+	LOAD_REG_IMMEDIATE(r0, VIRT_IMMR_BASE | MD_EVALID)
+	mtspr	SPRN_MD_EPN, r0
+	LOAD_REG_IMMEDIATE(r0, MD_SVALID | MD_PS512K | MD_GUARDED)
+	mtspr	SPRN_MD_TWC, r0
+	mfspr   r0, SPRN_IMMR
+	rlwinm	r0, r0, 0, 0xfff80000
+	ori	r0, r0, 0xf0 | _PAGE_DIRTY | _PAGE_SPS | _PAGE_SH | \
+			_PAGE_NO_CACHE | _PAGE_PRESENT
+	mtspr	SPRN_MD_RPN, r0
+#endif
 	tlbia			/* Clear all TLB entries */
 	sync			/* wait for tlbia/tlbie to finish */
 
@@ -796,28 +810,6 @@ initial_mmu:
 	ori	r8, r8, MD_APG_INIT@l
 	mtspr	SPRN_MD_AP, r8
 
-	/* Map a 512k page for the IMMR to get the processor
-	 * internal registers (among other things).
-	 */
-#ifdef CONFIG_PIN_TLB_IMMR
-	oris	r10, r10, MD_RSV4I@h
-	ori	r10, r10, 0x1c00
-	mtspr	SPRN_MD_CTR, r10
-
-	mfspr	r9, 638			/* Get current IMMR */
-	andis.	r9, r9, 0xfff8		/* Get 512 kbytes boundary */
-
-	lis	r8, VIRT_IMMR_BASE@h	/* Create vaddr for TLB */
-	ori	r8, r8, MD_EVALID	/* Mark it valid */
-	mtspr	SPRN_MD_EPN, r8
-	li	r8, MD_PS512K | MD_GUARDED	/* Set 512k byte page */
-	ori	r8, r8, MD_SVALID	/* Make it valid */
-	mtspr	SPRN_MD_TWC, r8
-	mr	r8, r9			/* Create paddr for TLB */
-	ori	r8, r8, MI_BOOTINIT|0x2 /* Inhibit cache -- Cort */
-	mtspr	SPRN_MD_RPN, r8
-#endif
-
 	/* Now map the lower RAM (up to 32 Mbytes) into the ITLB. */
 #ifdef CONFIG_PIN_TLB_TEXT
 	lis	r8, MI_RSV4I@h
diff --git a/arch/powerpc/mm/mmu_decl.h b/arch/powerpc/mm/mmu_decl.h
index 7097e07a209a..1b6d39e9baed 100644
--- a/arch/powerpc/mm/mmu_decl.h
+++ b/arch/powerpc/mm/mmu_decl.h
@@ -182,6 +182,10 @@ static inline void mmu_mark_initmem_nx(void) { }
 static inline void mmu_mark_rodata_ro(void) { }
 #endif
 
+#ifdef CONFIG_PPC_8xx
+void __init mmu_mapin_immr(void);
+#endif
+
 #ifdef CONFIG_PPC_DEBUG_WX
 void ptdump_check_wx(void);
 #else
diff --git a/arch/powerpc/mm/nohash/8xx.c b/arch/powerpc/mm/nohash/8xx.c
index 3189308dece4..2a55904986c6 100644
--- a/arch/powerpc/mm/nohash/8xx.c
+++ b/arch/powerpc/mm/nohash/8xx.c
@@ -65,7 +65,7 @@ void __init MMU_init_hw(void)
 	if (IS_ENABLED(CONFIG_PIN_TLB_DATA)) {
 		unsigned long ctr = mfspr(SPRN_MD_CTR) & 0xfe000000;
 		unsigned long flags = 0xf0 | MD_SPS16K | _PAGE_SH | _PAGE_DIRTY;
-		int i = IS_ENABLED(CONFIG_PIN_TLB_IMMR) ? 29 : 28;
+		int i = 28;
 		unsigned long addr = 0;
 		unsigned long mem = total_lowmem;
 
@@ -80,12 +80,19 @@ void __init MMU_init_hw(void)
 	}
 }
 
-static void __init mmu_mapin_immr(void)
+static bool immr_is_mapped __initdata;
+
+void __init mmu_mapin_immr(void)
 {
 	unsigned long p = PHYS_IMMR_BASE;
 	unsigned long v = VIRT_IMMR_BASE;
 	int offset;
 
+	if (immr_is_mapped)
+		return;
+
+	immr_is_mapped = true;
+
 	for (offset = 0; offset < IMMR_SIZE; offset += PAGE_SIZE)
 		map_kernel_page(v + offset, p + offset, PAGE_KERNEL_NCG);
 }
@@ -121,9 +128,10 @@ unsigned long __init mmu_mapin_ram(unsigned long base, unsigned long top)
 {
 	unsigned long mapped;
 
+	mmu_mapin_immr();
+
 	if (__map_without_ltlbs) {
 		mapped = 0;
-		mmu_mapin_immr();
 		if (!IS_ENABLED(CONFIG_PIN_TLB_IMMR))
 			patch_instruction_site(&patch__dtlbmiss_immr_jmp, PPC_INST_NOP);
 		if (!IS_ENABLED(CONFIG_PIN_TLB_TEXT))
@@ -142,7 +150,6 @@ unsigned long __init mmu_mapin_ram(unsigned long base, unsigned long top)
 		 */
 		mmu_mapin_ram_chunk(0, einittext8, PAGE_KERNEL_X);
 		mmu_mapin_ram_chunk(einittext8, mapped, PAGE_KERNEL);
-		mmu_mapin_immr();
 	}
 
 	mmu_patch_cmp_limit(&patch__dtlbmiss_linmem_top, mapped);
diff --git a/arch/powerpc/platforms/8xx/Kconfig b/arch/powerpc/platforms/8xx/Kconfig
index 0d036cd868ef..04ea1a8a0bdc 100644
--- a/arch/powerpc/platforms/8xx/Kconfig
+++ b/arch/powerpc/platforms/8xx/Kconfig
@@ -187,7 +187,7 @@ config PIN_TLB_DATA
 
 config PIN_TLB_IMMR
 	bool "Pinned TLB for IMMR"
-	depends on PIN_TLB || PPC_EARLY_DEBUG_CPM
+	depends on PIN_TLB
 	default y
 	help
 	  This pins the IMMR area with a 512kbytes page. In case
diff --git a/arch/powerpc/sysdev/cpm_common.c b/arch/powerpc/sysdev/cpm_common.c
index 71660bacb264..7dc1960f8bdb 100644
--- a/arch/powerpc/sysdev/cpm_common.c
+++ b/arch/powerpc/sysdev/cpm_common.c
@@ -68,6 +68,8 @@ static void udbg_putc_cpm(char c)
 void __init udbg_init_cpm(void)
 {
 #ifdef CONFIG_PPC_8xx
+	mmu_mapin_immr();
+
 	cpm_udbg_txdesc = (u32 __iomem __force *)
 			  (CONFIG_PPC_EARLY_DEBUG_CPM_ADDR - PHYS_IMMR_BASE +
 			   VIRT_IMMR_BASE);
-- 
2.25.0


  parent reply	other threads:[~2020-03-16 12:37 UTC|newest]

Thread overview: 55+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-03-16 12:35 [PATCH v1 00/46] Use hugepages to map kernel mem on 8xx Christophe Leroy
2020-03-16 12:35 ` [PATCH v1 01/46] powerpc/kasan: Fix shadow memory protection with CONFIG_KASAN_VMALLOC Christophe Leroy
2020-03-16 12:35 ` [PATCH v1 02/46] powerpc/kasan: Fix error detection on memory allocation Christophe Leroy
2020-03-16 12:35 ` [PATCH v1 03/46] powerpc/kasan: Fix issues by lowering KASAN_SHADOW_END Christophe Leroy
2020-03-16 12:35 ` [PATCH v1 04/46] powerpc/kasan: Fix shadow pages allocation failure Christophe Leroy
2020-03-16 12:35 ` [PATCH v1 05/46] powerpc/kasan: Remove unnecessary page table locking Christophe Leroy
2020-03-16 12:35 ` [PATCH v1 06/46] powerpc/kasan: Refactor update of early shadow mappings Christophe Leroy
2020-04-02 10:19   ` Christophe Leroy
2020-03-16 12:35 ` [PATCH v1 07/46] powerpc/kasan: Declare kasan_init_region() weak Christophe Leroy
2020-03-16 12:35 ` [PATCH v1 08/46] powerpc/ptdump: Limit size of flags text to 1/2 chars on PPC32 Christophe Leroy
2020-03-16 12:35 ` [PATCH v1 09/46] powerpc/ptdump: Reorder flags Christophe Leroy
2020-03-16 12:35 ` [PATCH v1 10/46] powerpc/ptdump: Add _PAGE_COHERENT flag Christophe Leroy
2020-03-16 12:35 ` [PATCH v1 11/46] powerpc/ptdump: Display size of BATs Christophe Leroy
2020-03-17  3:25   ` kbuild test robot
2020-03-16 12:35 ` [PATCH v1 12/46] powerpc/ptdump: Standardise display of BAT flags Christophe Leroy
2020-03-16 12:35 ` [PATCH v1 13/46] powerpc/ptdump: Properly handle non standard page size Christophe Leroy
2020-03-16 12:35 ` [PATCH v1 14/46] powerpc/ptdump: Handle hugepd at PGD level Christophe Leroy
2020-03-16 12:36 ` [PATCH v1 15/46] powerpc/32s: Don't warn when mapping RO data ROX Christophe Leroy
2020-03-16 12:36 ` [PATCH v1 16/46] powerpc/mm: Allocate static page tables for fixmap Christophe Leroy
2020-03-17 14:38   ` Christophe Leroy
2020-03-17 16:00     ` Luc Van Oostenryck
2020-03-16 12:36 ` [PATCH v1 17/46] powerpc/mm: Fix conditions to perform MMU specific management by blocks on PPC32 Christophe Leroy
2020-03-16 12:36 ` [PATCH v1 18/46] powerpc/mm: PTE_ATOMIC_UPDATES is only for 40x Christophe Leroy
2020-03-16 12:36 ` [PATCH v1 19/46] powerpc/mm: Refactor pte_update() on nohash/32 Christophe Leroy
2020-03-16 12:36 ` [PATCH v1 20/46] powerpc/mm: Refactor pte_update() on book3s/32 Christophe Leroy
2020-03-16 12:36 ` [PATCH v1 21/46] powerpc/mm: Standardise __ptep_test_and_clear_young() params between PPC32 and PPC64 Christophe Leroy
2020-03-16 12:36 ` [PATCH v1 22/46] powerpc/mm: Standardise pte_update() prototype " Christophe Leroy
2020-03-16 12:36 ` [PATCH v1 23/46] powerpc/mm: Create a dedicated pte_update() for 8xx Christophe Leroy
2020-03-16 12:36 ` [PATCH v1 24/46] powerpc/mm: Reduce hugepd size for 8M hugepages on 8xx Christophe Leroy
2020-03-16 12:36 ` [PATCH v1 25/46] powerpc/8xx: Drop CONFIG_8xx_COPYBACK option Christophe Leroy
2020-03-16 12:36 ` [PATCH v1 26/46] powerpc/8xx: Prepare handlers for _PAGE_HUGE for 512k pages Christophe Leroy
2020-03-16 12:36 ` [PATCH v1 27/46] powerpc/8xx: Manage 512k huge pages as standard pages Christophe Leroy
2020-03-16 12:36 ` [PATCH v1 28/46] powerpc/8xx: Only 8M pages are hugepte pages now Christophe Leroy
2020-03-16 12:36 ` [PATCH v1 29/46] powerpc/8xx: MM_SLICE is not needed anymore Christophe Leroy
2020-03-16 12:36 ` [PATCH v1 30/46] powerpc/8xx: Move PPC_PIN_TLB options into 8xx Kconfig Christophe Leroy
2020-03-16 12:36 ` [PATCH v1 31/46] powerpc/8xx: Add function to update pinned TLBs Christophe Leroy
2020-03-16 12:36 ` Christophe Leroy [this message]
2020-03-16 12:36 ` [PATCH v1 33/46] powerpc/8xx: Always pin TLBs at startup Christophe Leroy
2020-03-16 12:36 ` [PATCH v1 34/46] powerpc/8xx: Drop special handling of Linear and IMMR mappings in I/D TLB handlers Christophe Leroy
2020-03-16 12:36 ` [PATCH v1 35/46] powerpc/8xx: Remove now unused TLB miss functions Christophe Leroy
2020-03-16 12:36 ` [PATCH v1 36/46] powerpc/8xx: Move DTLB perf handling closer Christophe Leroy
2020-03-16 12:36 ` [PATCH v1 37/46] powerpc/mm: Don't be too strict with _etext alignment on PPC32 Christophe Leroy
2020-03-16 12:36 ` [PATCH v1 38/46] powerpc/8xx: Refactor kernel address boundary comparison Christophe Leroy
2020-03-16 12:36 ` [PATCH v1 39/46] powerpc/8xx: Add a function to early map kernel via huge pages Christophe Leroy
2020-03-17  1:39   ` kbuild test robot
2020-03-17 14:43     ` Christophe Leroy
2020-04-02 10:13       ` Christophe Leroy
2020-03-16 12:36 ` [PATCH v1 40/46] powerpc/8xx: Map IMMR with a huge page Christophe Leroy
2020-03-16 12:36 ` [PATCH v1 41/46] powerpc/8xx: Map linear memory with huge pages Christophe Leroy
2020-03-16 12:36 ` [PATCH v1 42/46] powerpc/8xx: Allow STRICT_KERNEL_RwX with pinned TLB Christophe Leroy
2020-03-16 12:36 ` [PATCH v1 43/46] powerpc/8xx: Allow large TLBs with DEBUG_PAGEALLOC Christophe Leroy
2020-03-16 12:36 ` [PATCH v1 44/46] powerpc/8xx: Implement dedicated kasan_init_region() Christophe Leroy
2020-03-16 12:36 ` [PATCH v1 45/46] powerpc/32s: Allow mapping with BATs with DEBUG_PAGEALLOC Christophe Leroy
2020-03-16 12:36 ` [PATCH v1 46/46] powerpc/32s: Implement dedicated kasan_init_region() Christophe Leroy
2020-03-17 14:32   ` Christophe Leroy

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=4f5a73b921b164be820b24ecaa74622cc2e6e9b8.1584360344.git.christophe.leroy@c-s.fr \
    --to=christophe.leroy@c-s.fr \
    --cc=benh@kernel.crashing.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linuxppc-dev@lists.ozlabs.org \
    --cc=mpe@ellerman.id.au \
    --cc=paulus@samba.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;
as well as URLs for NNTP newsgroup(s).