11da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds/* 226ff6c11ef38e08990c1e417c299246e6ab18ff7Paul Mundt * This file contains the functions and defines necessary to modify and 326ff6c11ef38e08990c1e417c299246e6ab18ff7Paul Mundt * use the SuperH page table tree. 426ff6c11ef38e08990c1e417c299246e6ab18ff7Paul Mundt * 51da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * Copyright (C) 1999 Niibe Yutaka 6249cfea914002baac0af4b080306e6b820cd86b2Paul Mundt * Copyright (C) 2002 - 2007 Paul Mundt 726ff6c11ef38e08990c1e417c299246e6ab18ff7Paul Mundt * 826ff6c11ef38e08990c1e417c299246e6ab18ff7Paul Mundt * This file is subject to the terms and conditions of the GNU General 926ff6c11ef38e08990c1e417c299246e6ab18ff7Paul Mundt * Public License. See the file "COPYING" in the main directory of this 1026ff6c11ef38e08990c1e417c299246e6ab18ff7Paul Mundt * archive for more details. 111da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds */ 1226ff6c11ef38e08990c1e417c299246e6ab18ff7Paul Mundt#ifndef __ASM_SH_PGTABLE_H 1326ff6c11ef38e08990c1e417c299246e6ab18ff7Paul Mundt#define __ASM_SH_PGTABLE_H 141da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 15782bb5a532f883540bf403afb19f735a4eefd95bPaul Mundt#ifdef CONFIG_X2TLB 16e44d6c4010a4c84369013932eea4721d16cbc08dPaul Mundt#include <asm/pgtable-3level.h> 175d9b4b19f118abfb75e352841f7bf74580d7e427Matt Fleming#else 18e44d6c4010a4c84369013932eea4721d16cbc08dPaul Mundt#include <asm/pgtable-2level.h> 195d9b4b19f118abfb75e352841f7bf74580d7e427Matt Fleming#endif 2026ff6c11ef38e08990c1e417c299246e6ab18ff7Paul Mundt#include <asm/page.h> 2165d517eb7224d24ee4206416161390f30d69e622Paul Mundt#include <asm/mmu.h> 2226ff6c11ef38e08990c1e417c299246e6ab18ff7Paul Mundt 231da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#ifndef __ASSEMBLY__ 241da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#include <asm/addrspace.h> 251da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#include <asm/fixmap.h> 261da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 271da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds/* 281da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * ZERO_PAGE is a global shared page that is always zero: used 291da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds * for zero-mapped memory areas etc.. 301da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds */ 3126ff6c11ef38e08990c1e417c299246e6ab18ff7Paul Mundtextern unsigned long empty_zero_page[PAGE_SIZE / sizeof(unsigned long)]; 321da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#define ZERO_PAGE(vaddr) (virt_to_page(empty_zero_page)) 331da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 341da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#endif /* !__ASSEMBLY__ */ 351da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 3621440cf04a64cd1b1209c12a6e1a3afba2a28709Paul Mundt/* 3736bcd39dbca824daffe16d607ae574b6edc7d31aPaul Mundt * Effective and physical address definitions, to aid with sign 3836bcd39dbca824daffe16d607ae574b6edc7d31aPaul Mundt * extension. 3936bcd39dbca824daffe16d607ae574b6edc7d31aPaul Mundt */ 4036bcd39dbca824daffe16d607ae574b6edc7d31aPaul Mundt#define NEFF 32 4136bcd39dbca824daffe16d607ae574b6edc7d31aPaul Mundt#define NEFF_SIGN (1LL << (NEFF - 1)) 4236bcd39dbca824daffe16d607ae574b6edc7d31aPaul Mundt#define NEFF_MASK (-1LL << NEFF) 4336bcd39dbca824daffe16d607ae574b6edc7d31aPaul Mundt 44c7914834ef3b8a396b7e82ea34ac07cdcfe6f868Paul Mundtstatic inline unsigned long long neff_sign_extend(unsigned long val) 45c7914834ef3b8a396b7e82ea34ac07cdcfe6f868Paul Mundt{ 46c7914834ef3b8a396b7e82ea34ac07cdcfe6f868Paul Mundt unsigned long long extended = val; 47c7914834ef3b8a396b7e82ea34ac07cdcfe6f868Paul Mundt return (extended & NEFF_SIGN) ? (extended | NEFF_MASK) : extended; 48c7914834ef3b8a396b7e82ea34ac07cdcfe6f868Paul Mundt} 49c7914834ef3b8a396b7e82ea34ac07cdcfe6f868Paul Mundt 5036bcd39dbca824daffe16d607ae574b6edc7d31aPaul Mundt#ifdef CONFIG_29BIT 5136bcd39dbca824daffe16d607ae574b6edc7d31aPaul Mundt#define NPHYS 29 5236bcd39dbca824daffe16d607ae574b6edc7d31aPaul Mundt#else 5336bcd39dbca824daffe16d607ae574b6edc7d31aPaul Mundt#define NPHYS 32 5436bcd39dbca824daffe16d607ae574b6edc7d31aPaul Mundt#endif 5536bcd39dbca824daffe16d607ae574b6edc7d31aPaul Mundt 5636bcd39dbca824daffe16d607ae574b6edc7d31aPaul Mundt#define NPHYS_SIGN (1LL << (NPHYS - 1)) 5736bcd39dbca824daffe16d607ae574b6edc7d31aPaul Mundt#define NPHYS_MASK (-1LL << NPHYS) 5836bcd39dbca824daffe16d607ae574b6edc7d31aPaul Mundt 59db2e1fa3f0eefbbe04e90d6e4d290ee176b28248Paul Mundt#define PGDIR_SIZE (1UL << PGDIR_SHIFT) 601da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#define PGDIR_MASK (~(PGDIR_SIZE-1)) 611da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 6221440cf04a64cd1b1209c12a6e1a3afba2a28709Paul Mundt/* Entries per level */ 637a847f819063b80cc5b38d39e8aad4d60f6ca2fdPaul Mundt#define PTRS_PER_PTE (PAGE_SIZE / (1 << PTE_MAGNITUDE)) 6421440cf04a64cd1b1209c12a6e1a3afba2a28709Paul Mundt 65d455a3696c72283923e6870e9e4fe1daa861d7cdHugh Dickins#define FIRST_USER_ADDRESS 0 661da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 671f69b6af9171f50135cce8023c84d82fbf42a8f5Matt Fleming#define PHYS_ADDR_MASK29 0x1fffffff 681f69b6af9171f50135cce8023c84d82fbf42a8f5Matt Fleming#define PHYS_ADDR_MASK32 0xffffffff 691f69b6af9171f50135cce8023c84d82fbf42a8f5Matt Fleming 701f69b6af9171f50135cce8023c84d82fbf42a8f5Matt Flemingstatic inline unsigned long phys_addr_mask(void) 711f69b6af9171f50135cce8023c84d82fbf42a8f5Matt Fleming{ 721f69b6af9171f50135cce8023c84d82fbf42a8f5Matt Fleming /* Is the MMU in 29bit mode? */ 731f69b6af9171f50135cce8023c84d82fbf42a8f5Matt Fleming if (__in_29bit_mode()) 741f69b6af9171f50135cce8023c84d82fbf42a8f5Matt Fleming return PHYS_ADDR_MASK29; 751f69b6af9171f50135cce8023c84d82fbf42a8f5Matt Fleming 761f69b6af9171f50135cce8023c84d82fbf42a8f5Matt Fleming return PHYS_ADDR_MASK32; 771f69b6af9171f50135cce8023c84d82fbf42a8f5Matt Fleming} 78d02b08f6e8b184ffef349e395210a5e82ff4f4bcStuart Menefy 791f69b6af9171f50135cce8023c84d82fbf42a8f5Matt Fleming#define PTE_PHYS_MASK (phys_addr_mask() & PAGE_MASK) 80cb700aa4f13d38726defab3060d3ebeaf67dc189Paul Mundt#define PTE_FLAGS_MASK (~(PTE_PHYS_MASK) << PAGE_SHIFT) 811da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 820468b4bb125542e75e39f08ebaa74a7daf845631Paul Mundt#ifdef CONFIG_SUPERH32 83f0b859e3d63a07995f0db294864c2f3c9228f1e4Paul Mundt#define VMALLOC_START (P3SEG) 840468b4bb125542e75e39f08ebaa74a7daf845631Paul Mundt#else 850468b4bb125542e75e39f08ebaa74a7daf845631Paul Mundt#define VMALLOC_START (0xf0000000) 860468b4bb125542e75e39f08ebaa74a7daf845631Paul Mundt#endif 871da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#define VMALLOC_END (FIXADDR_START-2*PAGE_SIZE) 881da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 89249cfea914002baac0af4b080306e6b820cd86b2Paul Mundt#if defined(CONFIG_SUPERH32) 90249cfea914002baac0af4b080306e6b820cd86b2Paul Mundt#include <asm/pgtable_32.h> 9121440cf04a64cd1b1209c12a6e1a3afba2a28709Paul Mundt#else 92249cfea914002baac0af4b080306e6b820cd86b2Paul Mundt#include <asm/pgtable_64.h> 931da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#endif 941da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 951da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds/* 9621440cf04a64cd1b1209c12a6e1a3afba2a28709Paul Mundt * SH-X and lower (legacy) SuperH parts (SH-3, SH-4, some SH-4A) can't do page 9721440cf04a64cd1b1209c12a6e1a3afba2a28709Paul Mundt * protection for execute, and considers it the same as a read. Also, write 9821440cf04a64cd1b1209c12a6e1a3afba2a28709Paul Mundt * permission implies read permission. This is the closest we can get.. 9921440cf04a64cd1b1209c12a6e1a3afba2a28709Paul Mundt * 10021440cf04a64cd1b1209c12a6e1a3afba2a28709Paul Mundt * SH-X2 (SH7785) and later parts take this to the opposite end of the extreme, 10121440cf04a64cd1b1209c12a6e1a3afba2a28709Paul Mundt * not only supporting separate execute, read, and write bits, but having 10221440cf04a64cd1b1209c12a6e1a3afba2a28709Paul Mundt * completely separate permission bits for user and kernel space. 1031da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds */ 10421440cf04a64cd1b1209c12a6e1a3afba2a28709Paul Mundt /*xwr*/ 1051da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#define __P000 PAGE_NONE 1061da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#define __P001 PAGE_READONLY 1071da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#define __P010 PAGE_COPY 1081da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#define __P011 PAGE_COPY 10921440cf04a64cd1b1209c12a6e1a3afba2a28709Paul Mundt#define __P100 PAGE_EXECREAD 11021440cf04a64cd1b1209c12a6e1a3afba2a28709Paul Mundt#define __P101 PAGE_EXECREAD 1111da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#define __P110 PAGE_COPY 1121da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#define __P111 PAGE_COPY 1131da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 1141da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#define __S000 PAGE_NONE 1151da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#define __S001 PAGE_READONLY 11621440cf04a64cd1b1209c12a6e1a3afba2a28709Paul Mundt#define __S010 PAGE_WRITEONLY 1171da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#define __S011 PAGE_SHARED 11821440cf04a64cd1b1209c12a6e1a3afba2a28709Paul Mundt#define __S100 PAGE_EXECREAD 11921440cf04a64cd1b1209c12a6e1a3afba2a28709Paul Mundt#define __S101 PAGE_EXECREAD 12021440cf04a64cd1b1209c12a6e1a3afba2a28709Paul Mundt#define __S110 PAGE_RWX 12121440cf04a64cd1b1209c12a6e1a3afba2a28709Paul Mundt#define __S111 PAGE_RWX 1221da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 1231da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvaldstypedef pte_t *pte_addr_t; 1241da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 1251da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#define kern_addr_valid(addr) (1) 1261da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 127249cfea914002baac0af4b080306e6b820cd86b2Paul Mundt#define pte_pfn(x) ((unsigned long)(((x).pte_low >> PAGE_SHIFT))) 1288c65b4a60450590e79a28e9717ceffa9e4debb3fTim Schmielau 1291da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds/* 1302a5eacca85d39d8b6dffae821d7d260f05584dc7Matt Fleming * Initialise the page table caches 1311da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds */ 1322a5eacca85d39d8b6dffae821d7d260f05584dc7Matt Flemingextern void pgtable_cache_init(void); 1331da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 134249cfea914002baac0af4b080306e6b820cd86b2Paul Mundtstruct vm_area_struct; 1358f82f0c7029d39b499389c8e225cf147fb83abe2Paul Mundtstruct mm_struct; 1369cef7492696a416663b4edb953a4eade8517ebebPaul Mundt 1379cef7492696a416663b4edb953a4eade8517ebebPaul Mundtextern void __update_cache(struct vm_area_struct *vma, 1389cef7492696a416663b4edb953a4eade8517ebebPaul Mundt unsigned long address, pte_t pte); 1399cef7492696a416663b4edb953a4eade8517ebebPaul Mundtextern void __update_tlb(struct vm_area_struct *vma, 1409cef7492696a416663b4edb953a4eade8517ebebPaul Mundt unsigned long address, pte_t pte); 1419cef7492696a416663b4edb953a4eade8517ebebPaul Mundt 1429cef7492696a416663b4edb953a4eade8517ebebPaul Mundtstatic inline void 1434b3073e1c53a256275f1079c0fbfbe85883d9275Russell Kingupdate_mmu_cache(struct vm_area_struct *vma, unsigned long address, pte_t *ptep) 1449cef7492696a416663b4edb953a4eade8517ebebPaul Mundt{ 1454b3073e1c53a256275f1079c0fbfbe85883d9275Russell King pte_t pte = *ptep; 1469cef7492696a416663b4edb953a4eade8517ebebPaul Mundt __update_cache(vma, address, pte); 1479cef7492696a416663b4edb953a4eade8517ebebPaul Mundt __update_tlb(vma, address, pte); 1489cef7492696a416663b4edb953a4eade8517ebebPaul Mundt} 1499cef7492696a416663b4edb953a4eade8517ebebPaul Mundt 15021440cf04a64cd1b1209c12a6e1a3afba2a28709Paul Mundtextern pgd_t swapper_pg_dir[PTRS_PER_PGD]; 15121440cf04a64cd1b1209c12a6e1a3afba2a28709Paul Mundtextern void paging_init(void); 1529acb98fb7ce948063a2269b4f8db83d6bef7e2b0Paul Mundtextern void page_table_range_init(unsigned long start, unsigned long end, 1539acb98fb7ce948063a2269b4f8db83d6bef7e2b0Paul Mundt pgd_t *pgd); 15421440cf04a64cd1b1209c12a6e1a3afba2a28709Paul Mundt 155ee1acbfabd5270b40ce2cfdc202070b7ca91cdffPaul Mundt/* arch/sh/mm/mmap.c */ 156ee1acbfabd5270b40ce2cfdc202070b7ca91cdffPaul Mundt#define HAVE_ARCH_UNMAPPED_AREA 157ee1acbfabd5270b40ce2cfdc202070b7ca91cdffPaul Mundt#define HAVE_ARCH_UNMAPPED_AREA_TOPDOWN 158ee1acbfabd5270b40ce2cfdc202070b7ca91cdffPaul Mundt 159a16382ce1cbcc3ab12274e20f92c09c439629162Paul Mundt#define __HAVE_ARCH_PTE_SPECIAL 160a16382ce1cbcc3ab12274e20f92c09c439629162Paul Mundt 1611da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds#include <asm-generic/pgtable.h> 1621da177e4c3f41524e886b7f1b8a0c1fc7321cacLinus Torvalds 163249cfea914002baac0af4b080306e6b820cd86b2Paul Mundt#endif /* __ASM_SH_PGTABLE_H */ 164