mirror of
https://github.com/AuxXxilium/linux_dsm_epyc7002.git
synced 2024-12-26 00:15:51 +07:00
57c8a661d9
Move remaining definitions and declarations from include/linux/bootmem.h into include/linux/memblock.h and remove the redundant header. The includes were replaced with the semantic patch below and then semi-automated removal of duplicated '#include <linux/memblock.h> @@ @@ - #include <linux/bootmem.h> + #include <linux/memblock.h> [sfr@canb.auug.org.au: dma-direct: fix up for the removal of linux/bootmem.h] Link: http://lkml.kernel.org/r/20181002185342.133d1680@canb.auug.org.au [sfr@canb.auug.org.au: powerpc: fix up for removal of linux/bootmem.h] Link: http://lkml.kernel.org/r/20181005161406.73ef8727@canb.auug.org.au [sfr@canb.auug.org.au: x86/kaslr, ACPI/NUMA: fix for linux/bootmem.h removal] Link: http://lkml.kernel.org/r/20181008190341.5e396491@canb.auug.org.au Link: http://lkml.kernel.org/r/1536927045-23536-30-git-send-email-rppt@linux.vnet.ibm.com Signed-off-by: Mike Rapoport <rppt@linux.vnet.ibm.com> Signed-off-by: Stephen Rothwell <sfr@canb.auug.org.au> Acked-by: Michal Hocko <mhocko@suse.com> Cc: Catalin Marinas <catalin.marinas@arm.com> Cc: Chris Zankel <chris@zankel.net> Cc: "David S. Miller" <davem@davemloft.net> Cc: Geert Uytterhoeven <geert@linux-m68k.org> Cc: Greentime Hu <green.hu@gmail.com> Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org> Cc: Guan Xuetao <gxt@pku.edu.cn> Cc: Ingo Molnar <mingo@redhat.com> Cc: "James E.J. Bottomley" <jejb@parisc-linux.org> Cc: Jonas Bonn <jonas@southpole.se> Cc: Jonathan Corbet <corbet@lwn.net> Cc: Ley Foon Tan <lftan@altera.com> Cc: Mark Salter <msalter@redhat.com> Cc: Martin Schwidefsky <schwidefsky@de.ibm.com> Cc: Matt Turner <mattst88@gmail.com> Cc: Michael Ellerman <mpe@ellerman.id.au> Cc: Michal Simek <monstr@monstr.eu> Cc: Palmer Dabbelt <palmer@sifive.com> Cc: Paul Burton <paul.burton@mips.com> Cc: Richard Kuo <rkuo@codeaurora.org> Cc: Richard Weinberger <richard@nod.at> Cc: Rich Felker <dalias@libc.org> Cc: Russell King <linux@armlinux.org.uk> Cc: Serge Semin <fancer.lancer@gmail.com> Cc: Thomas Gleixner <tglx@linutronix.de> Cc: Tony Luck <tony.luck@intel.com> Cc: Vineet Gupta <vgupta@synopsys.com> Cc: Yoshinori Sato <ysato@users.sourceforge.jp> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
226 lines
5.8 KiB
C
226 lines
5.8 KiB
C
// SPDX-License-Identifier: GPL-2.0
|
|
/*
|
|
* Based upon linux/arch/m68k/mm/sun3mmu.c
|
|
* Based upon linux/arch/ppc/mm/mmu_context.c
|
|
*
|
|
* Implementations of mm routines specific to the Coldfire MMU.
|
|
*
|
|
* Copyright (c) 2008 Freescale Semiconductor, Inc.
|
|
*/
|
|
|
|
#include <linux/kernel.h>
|
|
#include <linux/types.h>
|
|
#include <linux/mm.h>
|
|
#include <linux/init.h>
|
|
#include <linux/string.h>
|
|
#include <linux/memblock.h>
|
|
|
|
#include <asm/setup.h>
|
|
#include <asm/page.h>
|
|
#include <asm/pgtable.h>
|
|
#include <asm/mmu_context.h>
|
|
#include <asm/mcf_pgalloc.h>
|
|
#include <asm/tlbflush.h>
|
|
|
|
#define KMAPAREA(x) ((x >= VMALLOC_START) && (x < KMAP_END))
|
|
|
|
mm_context_t next_mmu_context;
|
|
unsigned long context_map[LAST_CONTEXT / BITS_PER_LONG + 1];
|
|
atomic_t nr_free_contexts;
|
|
struct mm_struct *context_mm[LAST_CONTEXT+1];
|
|
unsigned long num_pages;
|
|
|
|
/*
|
|
* ColdFire paging_init derived from sun3.
|
|
*/
|
|
void __init paging_init(void)
|
|
{
|
|
pgd_t *pg_dir;
|
|
pte_t *pg_table;
|
|
unsigned long address, size;
|
|
unsigned long next_pgtable, bootmem_end;
|
|
unsigned long zones_size[MAX_NR_ZONES];
|
|
enum zone_type zone;
|
|
int i;
|
|
|
|
empty_zero_page = (void *) memblock_alloc(PAGE_SIZE, PAGE_SIZE);
|
|
memset((void *) empty_zero_page, 0, PAGE_SIZE);
|
|
|
|
pg_dir = swapper_pg_dir;
|
|
memset(swapper_pg_dir, 0, sizeof(swapper_pg_dir));
|
|
|
|
size = num_pages * sizeof(pte_t);
|
|
size = (size + PAGE_SIZE) & ~(PAGE_SIZE-1);
|
|
next_pgtable = (unsigned long) memblock_alloc(size, PAGE_SIZE);
|
|
|
|
bootmem_end = (next_pgtable + size + PAGE_SIZE) & PAGE_MASK;
|
|
pg_dir += PAGE_OFFSET >> PGDIR_SHIFT;
|
|
|
|
address = PAGE_OFFSET;
|
|
while (address < (unsigned long)high_memory) {
|
|
pg_table = (pte_t *) next_pgtable;
|
|
next_pgtable += PTRS_PER_PTE * sizeof(pte_t);
|
|
pgd_val(*pg_dir) = (unsigned long) pg_table;
|
|
pg_dir++;
|
|
|
|
/* now change pg_table to kernel virtual addresses */
|
|
for (i = 0; i < PTRS_PER_PTE; ++i, ++pg_table) {
|
|
pte_t pte = pfn_pte(virt_to_pfn(address), PAGE_INIT);
|
|
if (address >= (unsigned long) high_memory)
|
|
pte_val(pte) = 0;
|
|
|
|
set_pte(pg_table, pte);
|
|
address += PAGE_SIZE;
|
|
}
|
|
}
|
|
|
|
current->mm = NULL;
|
|
|
|
for (zone = 0; zone < MAX_NR_ZONES; zone++)
|
|
zones_size[zone] = 0x0;
|
|
zones_size[ZONE_DMA] = num_pages;
|
|
free_area_init(zones_size);
|
|
}
|
|
|
|
int cf_tlb_miss(struct pt_regs *regs, int write, int dtlb, int extension_word)
|
|
{
|
|
unsigned long flags, mmuar, mmutr;
|
|
struct mm_struct *mm;
|
|
pgd_t *pgd;
|
|
pmd_t *pmd;
|
|
pte_t *pte;
|
|
int asid;
|
|
|
|
local_irq_save(flags);
|
|
|
|
mmuar = (dtlb) ? mmu_read(MMUAR) :
|
|
regs->pc + (extension_word * sizeof(long));
|
|
|
|
mm = (!user_mode(regs) && KMAPAREA(mmuar)) ? &init_mm : current->mm;
|
|
if (!mm) {
|
|
local_irq_restore(flags);
|
|
return -1;
|
|
}
|
|
|
|
pgd = pgd_offset(mm, mmuar);
|
|
if (pgd_none(*pgd)) {
|
|
local_irq_restore(flags);
|
|
return -1;
|
|
}
|
|
|
|
pmd = pmd_offset(pgd, mmuar);
|
|
if (pmd_none(*pmd)) {
|
|
local_irq_restore(flags);
|
|
return -1;
|
|
}
|
|
|
|
pte = (KMAPAREA(mmuar)) ? pte_offset_kernel(pmd, mmuar)
|
|
: pte_offset_map(pmd, mmuar);
|
|
if (pte_none(*pte) || !pte_present(*pte)) {
|
|
local_irq_restore(flags);
|
|
return -1;
|
|
}
|
|
|
|
if (write) {
|
|
if (!pte_write(*pte)) {
|
|
local_irq_restore(flags);
|
|
return -1;
|
|
}
|
|
set_pte(pte, pte_mkdirty(*pte));
|
|
}
|
|
|
|
set_pte(pte, pte_mkyoung(*pte));
|
|
asid = mm->context & 0xff;
|
|
if (!pte_dirty(*pte) && !KMAPAREA(mmuar))
|
|
set_pte(pte, pte_wrprotect(*pte));
|
|
|
|
mmutr = (mmuar & PAGE_MASK) | (asid << MMUTR_IDN) | MMUTR_V;
|
|
if ((mmuar < TASK_UNMAPPED_BASE) || (mmuar >= TASK_SIZE))
|
|
mmutr |= (pte->pte & CF_PAGE_MMUTR_MASK) >> CF_PAGE_MMUTR_SHIFT;
|
|
mmu_write(MMUTR, mmutr);
|
|
|
|
mmu_write(MMUDR, (pte_val(*pte) & PAGE_MASK) |
|
|
((pte->pte) & CF_PAGE_MMUDR_MASK) | MMUDR_SZ_8KB | MMUDR_X);
|
|
|
|
if (dtlb)
|
|
mmu_write(MMUOR, MMUOR_ACC | MMUOR_UAA);
|
|
else
|
|
mmu_write(MMUOR, MMUOR_ITLB | MMUOR_ACC | MMUOR_UAA);
|
|
|
|
local_irq_restore(flags);
|
|
return 0;
|
|
}
|
|
|
|
void __init cf_bootmem_alloc(void)
|
|
{
|
|
unsigned long memstart;
|
|
|
|
/* _rambase and _ramend will be naturally page aligned */
|
|
m68k_memory[0].addr = _rambase;
|
|
m68k_memory[0].size = _ramend - _rambase;
|
|
|
|
memblock_add(m68k_memory[0].addr, m68k_memory[0].size);
|
|
|
|
/* compute total pages in system */
|
|
num_pages = PFN_DOWN(_ramend - _rambase);
|
|
|
|
/* page numbers */
|
|
memstart = PAGE_ALIGN(_ramstart);
|
|
min_low_pfn = PFN_DOWN(_rambase);
|
|
max_pfn = max_low_pfn = PFN_DOWN(_ramend);
|
|
high_memory = (void *)_ramend;
|
|
|
|
/* Reserve kernel text/data/bss */
|
|
memblock_reserve(_rambase, memstart - _rambase);
|
|
|
|
m68k_virt_to_node_shift = fls(_ramend - 1) - 6;
|
|
module_fixup(NULL, __start_fixup, __stop_fixup);
|
|
|
|
/* setup node data */
|
|
m68k_setup_node(0);
|
|
}
|
|
|
|
/*
|
|
* Initialize the context management stuff.
|
|
* The following was taken from arch/ppc/mmu_context.c
|
|
*/
|
|
void __init cf_mmu_context_init(void)
|
|
{
|
|
/*
|
|
* Some processors have too few contexts to reserve one for
|
|
* init_mm, and require using context 0 for a normal task.
|
|
* Other processors reserve the use of context zero for the kernel.
|
|
* This code assumes FIRST_CONTEXT < 32.
|
|
*/
|
|
context_map[0] = (1 << FIRST_CONTEXT) - 1;
|
|
next_mmu_context = FIRST_CONTEXT;
|
|
atomic_set(&nr_free_contexts, LAST_CONTEXT - FIRST_CONTEXT + 1);
|
|
}
|
|
|
|
/*
|
|
* Steal a context from a task that has one at the moment.
|
|
* This is only used on 8xx and 4xx and we presently assume that
|
|
* they don't do SMP. If they do then thicfpgalloc.hs will have to check
|
|
* whether the MM we steal is in use.
|
|
* We also assume that this is only used on systems that don't
|
|
* use an MMU hash table - this is true for 8xx and 4xx.
|
|
* This isn't an LRU system, it just frees up each context in
|
|
* turn (sort-of pseudo-random replacement :). This would be the
|
|
* place to implement an LRU scheme if anyone was motivated to do it.
|
|
* -- paulus
|
|
*/
|
|
void steal_context(void)
|
|
{
|
|
struct mm_struct *mm;
|
|
/*
|
|
* free up context `next_mmu_context'
|
|
* if we shouldn't free context 0, don't...
|
|
*/
|
|
if (next_mmu_context < FIRST_CONTEXT)
|
|
next_mmu_context = FIRST_CONTEXT;
|
|
mm = context_mm[next_mmu_context];
|
|
flush_tlb_mm(mm);
|
|
destroy_context(mm);
|
|
}
|
|
|