Skip to contentSkip to conversation

40x large page PTEs - Mark III

PATCH David Gibson 1 participant 1 message Jun 13, 2002

lore
Share & tools
lore
#0 lore raw

Here's the third cut at large page support for the 40x. This patch I actually consider a candidate for committing to 2_4_devel. iopa() is much cleaner, and pgtable.h is set up so that it should be pretty easy to accommodate other large-page implementations for other processors when/if they happen.

It seems to work well on the EP405PC board here, but it needs more testing on non-4xx machines to make sure I didn't break something.

arch/ppc/config.in renamed from home/dgibson/kernel/linuxppc_2_4_devel/arch/ppc/config.in +0 -3
diff -urN /home/dgibson/kernel/linuxppc_2_4_devel/arch/ppc/config.in linux-grinch-largepage/arch/ppc/config.in
@@ -357,9 +357,6 @@
   if [ "$CONFIG_8xx" = "y" ]; then
     bool "Pinned Kernel TLBs (860 ONLY)" CONFIG_PIN_TLB
   fi
-  if [ "$CONFIG_40x" = "y" ]; then
-    bool "Pinned Kernel TLBs" CONFIG_PIN_TLB
-  fi
 fi
 
 if [ "$CONFIG_ALL_PPC" = "y" ]; then
arch/ppc/kernel/head_4xx.S renamed from home/dgibson/kernel/linuxppc_2_4_devel/arch/ppc/kernel/head_4xx.S +50 -42

160 lines not on this page · raw message

arch/ppc/kernel/misc.S renamed from home/dgibson/kernel/linuxppc_2_4_devel/arch/ppc/kernel/misc.S +4 -14
diff -urN /home/dgibson/kernel/linuxppc_2_4_devel/arch/ppc/kernel/misc.S linux-grinch-largepage/arch/ppc/kernel/misc.S
@@ -354,18 +354,8 @@
  * Flush MMU TLB
  */
 _GLOBAL(_tlbia)
-#if defined(CONFIG_40x) && defined(CONFIG_PIN_TLB)
-	/* This needs to be coordinated with other pinning functions since
-	 * we don't keep a memory location of number of entries to reduce
-	 * cache pollution during these operations.
-	 */
-	lis	r3, 0
-	sync
-1:
-	tlbwe	r3, r3, TLB_TAG		/* just ensure V is clear */
-	addi	r3, r3, 1		/*   so r3 works fine for that */
-	cmpwi	0, r3, 61		/* reserve last two entries */
-	ble	1b
+#if defined(CONFIG_40x)
+	tlbia
 	isync
 #elif defined(CONFIG_440)
 	lis	r3,0
@@ -376,7 +366,7 @@
 	cmpwi	0,r3,61
 	ble	1b
 	isync
-#else
+#else /* !defined(CONFIG_40x) && !defined(CONFIG_440) */
 #if defined(CONFIG_SMP)
 	mfmsr	r10
 	SYNC
@@ -410,7 +400,7 @@
 #else /* CONFIG_SMP */
 	sync
 #endif /* CONFIG_SMP */
-#endif /* defined(CONFIG_40x) && defined(CONFIG_PIN_TLB) */
+#endif /* ! defined(CONFIG_40x) && ! defined(CONFIG_440) */
 	blr
 
 /*
arch/ppc/mm/4xx_mmu.c renamed from home/dgibson/kernel/linuxppc_2_4_devel/arch/ppc/mm/4xx_mmu.c +47 -0

57 lines not on this page · raw message

arch/ppc/mm/pgtable.c renamed from home/dgibson/kernel/linuxppc_2_4_devel/arch/ppc/mm/pgtable.c +27 -6
diff -urN /home/dgibson/kernel/linuxppc_2_4_devel/arch/ppc/mm/pgtable.c linux-grinch-largepage/arch/ppc/mm/pgtable.c
@@ -75,6 +75,12 @@
 #define p_mapped_by_bats(x)	(0UL)
 #endif /* HAVE_BATS */
 
+#if (_PMD_SIZE == 0) /* No large page PMD support */
+#define 	largepte_mapin_ram()	0UL
+#else
+extern unsigned long largepte_mapin_ram(void);
+#endif
+
 #ifndef CONFIG_PPC_ISERIES
 #ifndef CONFIG_440
 void *
@@ -346,9 +352,12 @@
 		bat_mapin_ram(__bat2, __bat3);
 #endif /* HAVE_BATS */
 
-	v = KERNELBASE;
-	p = PPC_MEMSTART;
-	for (s = 0; s < total_lowmem; s += PAGE_SIZE) {
+	s = largepte_mapin_ram();
+
+	v = KERNELBASE + s;
+	p = PPC_MEMSTART + s;
+
+	for (; s < total_lowmem; s += PAGE_SIZE) {
 		/* On the MPC8xx, we want the page shared so we
 		 * don't get ASID compares on kernel space.
 		 */
@@ -451,6 +460,8 @@
 	 * tables.......I am actively working on resolving this, but
 	 * can't hold up other stuff.  -- Dan
 	 */
+	pgd_t	*pgd;
+	pmd_t	*pmd;
 	pte_t *pte;
 	struct mm_struct *mm;
 
@@ -468,10 +479,20 @@
 		mm = &init_mm;
 
 	pa = 0;
-	if (get_pteptr(mm, addr, &pte))
-		pa = (pte_val(*pte) & PAGE_MASK) | (addr & ~PAGE_MASK);
+	pgd = pgd_offset(mm, addr);
+	if (pgd) {
+		pmd = pmd_offset(pgd, addr);
+		if (pmd_present(*pmd)) {
+			pte = pte_offset(pmd, addr);
+			pa = (pte_val(*pte) & PAGE_MASK) | (addr & ~PAGE_MASK);
+		} else if (pmd_largepage(*pmd)) {
+			unsigned long mask = pmd_largepagemask(*pmd);
+
+			pa = (pmd_val(*pmd) & mask) | (addr & ~mask);
+		}
+	}
 
-	return(pa);
+	return pa;
 }
 
 /* This is will find the virtual address for a physical one....
include/asm-ppc/pgtable.h renamed from home/dgibson/kernel/linuxppc_2_4_devel/include/asm-ppc/pgtable.h +16 -10
diff -urN /home/dgibson/kernel/linuxppc_2_4_devel/include/asm-ppc/pgtable.h linux-grinch-largepage/include/asm-ppc/pgtable.h
@@ -18,15 +18,7 @@
 extern void _tlbia(void);
 
 #ifdef CONFIG_4xx
-#ifdef CONFIG_PIN_TLB
-/* When pinning entries on the 4xx, we have to use a software function
- * to ensure we don't remove them since there isn't any hardware support
- * for this.
- */
-#define __tlbia()	_tlbia()
-#else
 #define __tlbia()	asm volatile ("tlbia; sync" : : : "memory")
-#endif
 
 static inline void local_flush_tlb_all(void)
 	{ __tlbia(); }
@@ -296,7 +288,12 @@
 #define _PAGE_HWWRITE	0x100	/* hardware: Dirty & RW, set in exception */
 #define _PAGE_HWEXEC	0x200	/* hardware: EX permission */
 #define _PAGE_ACCESSED	0x400	/* software: R: page referenced */
-#define _PMD_PRESENT	PAGE_MASK
+
+#define _PMD_PRESENT	0x400	/* PMD points to page of PTEs */
+#define _PMD_SIZE	0x0e0	/* size field, != 0 for large-page PMD entry */
+#define _PMD_SIZE_4M	0x0c0
+#define _PMD_SIZE_16M	0x0e0
+#define PMD_PAGE_SIZE(pmd)	(1024 << ((pmd_val(pmd) & _PMD_SIZE) >> 4))
 
 #elif defined(CONFIG_440)
 
@@ -398,6 +395,12 @@
 #ifndef _PAGE_EXEC
 #define _PAGE_EXEC	0
 #endif
+#ifndef _PMD_SIZE
+#define _PMD_SIZE	0
+/* Make sure we get a link error if PMD_PAGE_SIZE is ever called on a
+ * kernel without large page PMD support */
+extern unsigned long PMD_PAGE_SIZE(pmd_t);
+#endif
 
 #define _PAGE_CHG_MASK	(PAGE_MASK | _PAGE_ACCESSED | _PAGE_DIRTY)
 
@@ -469,9 +472,12 @@
 #define pte_clear(ptep)		do { set_pte((ptep), __pte(0)); } while (0)
 
 #define pmd_none(pmd)		(!pmd_val(pmd))
-#define	pmd_bad(pmd)		((pmd_val(pmd) & _PMD_PRESENT) == 0)
+#define	pmd_bad(pmd)		( ((pmd_val(pmd) & _PMD_PRESENT) == 0) && \
+				  ((pmd_val(pmd) & _PMD_SIZE) == 0) )
 #define	pmd_present(pmd)	((pmd_val(pmd) & _PMD_PRESENT) != 0)
 #define	pmd_clear(pmdp)		do { pmd_val(*(pmdp)) = 0; } while (0)
+#define pmd_largepage(pmd)	((pmd_val(pmd) & _PMD_SIZE) != 0)
+#define pmd_largepagemask(pmd)	(~(PMD_PAGE_SIZE(pmd) - 1))
 
 #define pte_page(x)		(mem_map+(unsigned long)((pte_val(x)-PPC_MEMSTART) >> PAGE_SHIFT))
 

--
David Gibson | For every complex problem there is a
[email protected] | solution which is simple, neat and
| wrong. -- H.L. Mencken
http://www.ozlabs.org/people/dgibson

** Sent via the linuxppc-embedded mail list. See http://lists.linuxppc.org/