Commit 13076a29 authored by Peter Zijlstra's avatar Peter Zijlstra Committed by Geert Uytterhoeven

m68k: mm: Unify Motorola MMU page setup

Seeing how there are 5 copies of this magic code, one of which is
unexplainably different, unify and document things.
Suggested-by: default avatarWill Deacon <will@kernel.org>
Signed-off-by: default avatarPeter Zijlstra (Intel) <peterz@infradead.org>
Acked-by: default avatarWill Deacon <will@kernel.org>
Acked-by: default avatarGreg Ungerer <gerg@linux-m68k.org>
Tested-by: default avatarMichael Schmitz <schmitzmic@gmail.com>
Tested-by: default avatarGreg Ungerer <gerg@linux-m68k.org>
Link: https://lore.kernel.org/r/20200131125403.597688427@infradead.orgSigned-off-by: default avatarGeert Uytterhoeven <geert@linux-m68k.org>
parent fd1aa630
...@@ -5,6 +5,9 @@ ...@@ -5,6 +5,9 @@
#include <asm/tlb.h> #include <asm/tlb.h>
#include <asm/tlbflush.h> #include <asm/tlbflush.h>
extern void mmu_page_ctor(void *page);
extern void mmu_page_dtor(void *page);
extern pmd_t *get_pointer_table(void); extern pmd_t *get_pointer_table(void);
extern int free_pointer_table(pmd_t *); extern int free_pointer_table(pmd_t *);
...@@ -13,25 +16,21 @@ static inline pte_t *pte_alloc_one_kernel(struct mm_struct *mm) ...@@ -13,25 +16,21 @@ static inline pte_t *pte_alloc_one_kernel(struct mm_struct *mm)
pte_t *pte; pte_t *pte;
pte = (pte_t *)__get_free_page(GFP_KERNEL|__GFP_ZERO); pte = (pte_t *)__get_free_page(GFP_KERNEL|__GFP_ZERO);
if (pte) { if (pte)
__flush_page_to_ram(pte); mmu_page_ctor(pte);
flush_tlb_kernel_page(pte);
nocache_page(pte);
}
return pte; return pte;
} }
static inline void pte_free_kernel(struct mm_struct *mm, pte_t *pte) static inline void pte_free_kernel(struct mm_struct *mm, pte_t *pte)
{ {
cache_page(pte); mmu_page_dtor(pte);
free_page((unsigned long) pte); free_page((unsigned long) pte);
} }
static inline pgtable_t pte_alloc_one(struct mm_struct *mm) static inline pgtable_t pte_alloc_one(struct mm_struct *mm)
{ {
struct page *page; struct page *page;
pte_t *pte;
page = alloc_pages(GFP_KERNEL|__GFP_ZERO, 0); page = alloc_pages(GFP_KERNEL|__GFP_ZERO, 0);
if(!page) if(!page)
...@@ -41,18 +40,16 @@ static inline pgtable_t pte_alloc_one(struct mm_struct *mm) ...@@ -41,18 +40,16 @@ static inline pgtable_t pte_alloc_one(struct mm_struct *mm)
return NULL; return NULL;
} }
pte = kmap(page); mmu_page_ctor(kmap(page));
__flush_page_to_ram(pte);
flush_tlb_kernel_page(pte);
nocache_page(pte);
kunmap(page); kunmap(page);
return page; return page;
} }
static inline void pte_free(struct mm_struct *mm, pgtable_t page) static inline void pte_free(struct mm_struct *mm, pgtable_t page)
{ {
pgtable_pte_page_dtor(page); pgtable_pte_page_dtor(page);
cache_page(kmap(page)); mmu_page_dtor(kmap(page));
kunmap(page); kunmap(page);
__free_page(page); __free_page(page);
} }
...@@ -61,7 +58,7 @@ static inline void __pte_free_tlb(struct mmu_gather *tlb, pgtable_t page, ...@@ -61,7 +58,7 @@ static inline void __pte_free_tlb(struct mmu_gather *tlb, pgtable_t page,
unsigned long address) unsigned long address)
{ {
pgtable_pte_page_dtor(page); pgtable_pte_page_dtor(page);
cache_page(kmap(page)); mmu_page_dtor(kmap(page));
kunmap(page); kunmap(page);
__free_page(page); __free_page(page);
} }
......
...@@ -77,8 +77,7 @@ pmd_t *get_pointer_table (void) ...@@ -77,8 +77,7 @@ pmd_t *get_pointer_table (void)
if (!(page = (void *)get_zeroed_page(GFP_KERNEL))) if (!(page = (void *)get_zeroed_page(GFP_KERNEL)))
return NULL; return NULL;
flush_tlb_kernel_page(page); mmu_page_ctor(page);
nocache_page(page);
new = PD_PTABLE(page); new = PD_PTABLE(page);
PD_MARKBITS(new) = 0xfe; PD_MARKBITS(new) = 0xfe;
...@@ -112,7 +111,7 @@ int free_pointer_table (pmd_t *ptable) ...@@ -112,7 +111,7 @@ int free_pointer_table (pmd_t *ptable)
if (PD_MARKBITS(dp) == 0xff) { if (PD_MARKBITS(dp) == 0xff) {
/* all tables in page are free, free page */ /* all tables in page are free, free page */
list_del(dp); list_del(dp);
cache_page((void *)page); mmu_page_dtor((void *)page);
free_page (page); free_page (page);
return 1; return 1;
} else if (ptable_list.next != dp) { } else if (ptable_list.next != dp) {
......
...@@ -45,6 +45,28 @@ unsigned long mm_cachebits; ...@@ -45,6 +45,28 @@ unsigned long mm_cachebits;
EXPORT_SYMBOL(mm_cachebits); EXPORT_SYMBOL(mm_cachebits);
#endif #endif
/*
* Motorola 680x0 user's manual recommends using uncached memory for address
* translation tables.
*
* Seeing how the MMU can be external on (some of) these chips, that seems like
* a very important recommendation to follow. Provide some helpers to combat
* 'variation' amongst the users of this.
*/
void mmu_page_ctor(void *page)
{
__flush_page_to_ram(page);
flush_tlb_kernel_page(page);
nocache_page(page);
}
void mmu_page_dtor(void *page)
{
cache_page(page);
}
/* size of memory already mapped in head.S */ /* size of memory already mapped in head.S */
extern __initdata unsigned long m68k_init_mapped_size; extern __initdata unsigned long m68k_init_mapped_size;
...@@ -60,9 +82,7 @@ static pte_t * __init kernel_page_table(void) ...@@ -60,9 +82,7 @@ static pte_t * __init kernel_page_table(void)
__func__, PAGE_SIZE, PAGE_SIZE); __func__, PAGE_SIZE, PAGE_SIZE);
clear_page(ptablep); clear_page(ptablep);
__flush_page_to_ram(ptablep); mmu_page_ctor(ptablep);
flush_tlb_kernel_page(ptablep);
nocache_page(ptablep);
return ptablep; return ptablep;
} }
...@@ -106,9 +126,7 @@ static pmd_t * __init kernel_ptr_table(void) ...@@ -106,9 +126,7 @@ static pmd_t * __init kernel_ptr_table(void)
__func__, PAGE_SIZE, PAGE_SIZE); __func__, PAGE_SIZE, PAGE_SIZE);
clear_page(last_pgtable); clear_page(last_pgtable);
__flush_page_to_ram(last_pgtable); mmu_page_ctor(last_pgtable);
flush_tlb_kernel_page(last_pgtable);
nocache_page(last_pgtable);
} }
return last_pgtable; return last_pgtable;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment