/*1* This file contains the routines for initializing the MMU2* on the 4xx series of chips.3* -- paulus4*5* Derived from arch/ppc/mm/init.c:6* Copyright (C) 1995-1996 Gary Thomas ([email protected])7*8* Modifications by Paul Mackerras (PowerMac) ([email protected])9* and Cort Dougan (PReP) ([email protected])10* Copyright (C) 1996 Paul Mackerras11*12* Derived from "arch/i386/mm/init.c"13* Copyright (C) 1991, 1992, 1993, 1994 Linus Torvalds14*15* This program is free software; you can redistribute it and/or16* modify it under the terms of the GNU General Public License17* as published by the Free Software Foundation; either version18* 2 of the License, or (at your option) any later version.19*20*/2122#include <linux/signal.h>23#include <linux/sched.h>24#include <linux/kernel.h>25#include <linux/errno.h>26#include <linux/string.h>27#include <linux/types.h>28#include <linux/ptrace.h>29#include <linux/mman.h>30#include <linux/mm.h>31#include <linux/swap.h>32#include <linux/stddef.h>33#include <linux/vmalloc.h>34#include <linux/init.h>35#include <linux/delay.h>36#include <linux/highmem.h>37#include <linux/memblock.h>3839#include <asm/pgalloc.h>40#include <asm/prom.h>41#include <asm/io.h>42#include <asm/mmu_context.h>43#include <asm/pgtable.h>44#include <asm/mmu.h>45#include <asm/uaccess.h>46#include <asm/smp.h>47#include <asm/bootx.h>48#include <asm/machdep.h>49#include <asm/setup.h>5051#include "mmu_decl.h"5253extern int __map_without_ltlbs;54/*55* MMU_init_hw does the chip-specific initialization of the MMU hardware.56*/57void __init MMU_init_hw(void)58{59/*60* The Zone Protection Register (ZPR) defines how protection will61* be applied to every page which is a member of a given zone. At62* present, we utilize only two of the 4xx's zones.63* The zone index bits (of ZSEL) in the PTE are used for software64* indicators, except the LSB. For user access, zone 1 is used,65* for kernel access, zone 0 is used. We set all but zone 166* to zero, allowing only kernel access as indicated in the PTE.67* For zone 1, we set a 01 binary (a value of 10 will not work)68* to allow user access as indicated in the PTE. This also allows69* kernel access as indicated in the PTE.70*/7172mtspr(SPRN_ZPR, 0x10000000);7374flush_instruction_cache();7576/*77* Set up the real-mode cache parameters for the exception vector78* handlers (which are run in real-mode).79*/8081mtspr(SPRN_DCWR, 0x00000000); /* All caching is write-back */8283/*84* Cache instruction and data space where the exception85* vectors and the kernel live in real-mode.86*/8788mtspr(SPRN_DCCR, 0xFFFF0000); /* 2GByte of data space at 0x0. */89mtspr(SPRN_ICCR, 0xFFFF0000); /* 2GByte of instr. space at 0x0. */90}9192#define LARGE_PAGE_SIZE_16M (1<<24)93#define LARGE_PAGE_SIZE_4M (1<<22)9495unsigned long __init mmu_mapin_ram(unsigned long top)96{97unsigned long v, s, mapped;98phys_addr_t p;99100v = KERNELBASE;101p = 0;102s = total_lowmem;103104if (__map_without_ltlbs)105return 0;106107while (s >= LARGE_PAGE_SIZE_16M) {108pmd_t *pmdp;109unsigned long val = p | _PMD_SIZE_16M | _PAGE_EXEC | _PAGE_HWWRITE;110111pmdp = pmd_offset(pud_offset(pgd_offset_k(v), v), v);112pmd_val(*pmdp++) = val;113pmd_val(*pmdp++) = val;114pmd_val(*pmdp++) = val;115pmd_val(*pmdp++) = val;116117v += LARGE_PAGE_SIZE_16M;118p += LARGE_PAGE_SIZE_16M;119s -= LARGE_PAGE_SIZE_16M;120}121122while (s >= LARGE_PAGE_SIZE_4M) {123pmd_t *pmdp;124unsigned long val = p | _PMD_SIZE_4M | _PAGE_EXEC | _PAGE_HWWRITE;125126pmdp = pmd_offset(pud_offset(pgd_offset_k(v), v), v);127pmd_val(*pmdp) = val;128129v += LARGE_PAGE_SIZE_4M;130p += LARGE_PAGE_SIZE_4M;131s -= LARGE_PAGE_SIZE_4M;132}133134mapped = total_lowmem - s;135136/* If the size of RAM is not an exact power of two, we may not137* have covered RAM in its entirety with 16 and 4 MiB138* pages. Consequently, restrict the top end of RAM currently139* allocable so that calls to the MEMBLOCK to allocate PTEs for "tail"140* coverage with normal-sized pages (or other reasons) do not141* attempt to allocate outside the allowed range.142*/143memblock_set_current_limit(mapped);144145return mapped;146}147148void setup_initial_memory_limit(phys_addr_t first_memblock_base,149phys_addr_t first_memblock_size)150{151/* We don't currently support the first MEMBLOCK not mapping 0152* physical on those processors153*/154BUG_ON(first_memblock_base != 0);155156/* 40x can only access 16MB at the moment (see head_40x.S) */157memblock_set_current_limit(min_t(u64, first_memblock_size, 0x00800000));158}159160161