blob: 9210e93a92c337f18c94fd962bbeb5e23cfbb739 [file] [log] [blame]
Paul Mundt26ff6c12006-09-27 15:13:36 +09001/*
2 * This file contains the functions and defines necessary to modify and
3 * use the SuperH page table tree.
4 *
5 * Copyright (C) 1999 Niibe Yutaka
Paul Mundt249cfea2007-11-19 18:26:19 +09006 * Copyright (C) 2002 - 2007 Paul Mundt
Paul Mundt26ff6c12006-09-27 15:13:36 +09007 *
8 * This file is subject to the terms and conditions of the GNU General
9 * Public License. See the file "COPYING" in the main directory of this
10 * archive for more details.
11 */
Linus Torvalds1da177e2005-04-16 15:20:36 -070012#ifndef __ASM_SH_PGTABLE_H
13#define __ASM_SH_PGTABLE_H
14
Paul Mundt782bb5a2010-01-13 19:11:14 +090015#ifdef CONFIG_X2TLB
Paul Mundte44d6c42010-01-13 19:18:39 +090016#include <asm/pgtable-3level.h>
Matt Fleming5d9b4b12009-12-13 14:38:50 +000017#else
Paul Mundte44d6c42010-01-13 19:18:39 +090018#include <asm/pgtable-2level.h>
Matt Fleming5d9b4b12009-12-13 14:38:50 +000019#endif
Paul Mundt26ff6c12006-09-27 15:13:36 +090020#include <asm/page.h>
Paul Mundt65d517e2011-05-31 14:37:44 +090021#include <asm/mmu.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070022
Linus Torvalds1da177e2005-04-16 15:20:36 -070023#ifndef __ASSEMBLY__
Linus Torvalds1da177e2005-04-16 15:20:36 -070024#include <asm/addrspace.h>
25#include <asm/fixmap.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070026
Linus Torvalds1da177e2005-04-16 15:20:36 -070027/*
Linus Torvalds1da177e2005-04-16 15:20:36 -070028 * ZERO_PAGE is a global shared page that is always zero: used
29 * for zero-mapped memory areas etc..
30 */
Paul Mundt26ff6c12006-09-27 15:13:36 +090031extern unsigned long empty_zero_page[PAGE_SIZE / sizeof(unsigned long)];
Linus Torvalds1da177e2005-04-16 15:20:36 -070032#define ZERO_PAGE(vaddr) (virt_to_page(empty_zero_page))
33
34#endif /* !__ASSEMBLY__ */
35
Paul Mundt21440cf2006-11-20 14:30:26 +090036/*
Paul Mundt36bcd392007-11-10 19:16:55 +090037 * Effective and physical address definitions, to aid with sign
38 * extension.
39 */
40#define NEFF 32
41#define NEFF_SIGN (1LL << (NEFF - 1))
42#define NEFF_MASK (-1LL << NEFF)
43
Paul Mundtc7914832009-08-04 17:14:39 +090044static inline unsigned long long neff_sign_extend(unsigned long val)
45{
46 unsigned long long extended = val;
47 return (extended & NEFF_SIGN) ? (extended | NEFF_MASK) : extended;
48}
49
Paul Mundt36bcd392007-11-10 19:16:55 +090050#ifdef CONFIG_29BIT
51#define NPHYS 29
52#else
53#define NPHYS 32
54#endif
55
56#define NPHYS_SIGN (1LL << (NPHYS - 1))
57#define NPHYS_MASK (-1LL << NPHYS)
58
Paul Mundtdb2e1fa2007-02-14 14:13:10 +090059#define PGDIR_SIZE (1UL << PGDIR_SHIFT)
Linus Torvalds1da177e2005-04-16 15:20:36 -070060#define PGDIR_MASK (~(PGDIR_SIZE-1))
61
Paul Mundt21440cf2006-11-20 14:30:26 +090062/* Entries per level */
Paul Mundt7a847f82006-12-26 15:29:19 +090063#define PTRS_PER_PTE (PAGE_SIZE / (1 << PTE_MAGNITUDE))
Paul Mundt21440cf2006-11-20 14:30:26 +090064
Hugh Dickinsd455a362005-04-19 13:29:23 -070065#define FIRST_USER_ADDRESS 0
Linus Torvalds1da177e2005-04-16 15:20:36 -070066
Matt Fleming1f69b6a2009-10-06 21:22:25 +000067#define PHYS_ADDR_MASK29 0x1fffffff
68#define PHYS_ADDR_MASK32 0xffffffff
69
Matt Fleming1f69b6a2009-10-06 21:22:25 +000070static inline unsigned long phys_addr_mask(void)
71{
72 /* Is the MMU in 29bit mode? */
73 if (__in_29bit_mode())
74 return PHYS_ADDR_MASK29;
75
76 return PHYS_ADDR_MASK32;
77}
Stuart Menefyd02b08f2007-11-30 17:52:53 +090078
Matt Fleming1f69b6a2009-10-06 21:22:25 +000079#define PTE_PHYS_MASK (phys_addr_mask() & PAGE_MASK)
Paul Mundtcb700aa2008-09-12 20:41:05 +090080#define PTE_FLAGS_MASK (~(PTE_PHYS_MASK) << PAGE_SHIFT)
Linus Torvalds1da177e2005-04-16 15:20:36 -070081
Paul Mundt0468b4b2007-11-10 20:39:06 +090082#ifdef CONFIG_SUPERH32
Paul Mundtf0b859e2007-07-25 10:43:47 +090083#define VMALLOC_START (P3SEG)
Paul Mundt0468b4b2007-11-10 20:39:06 +090084#else
85#define VMALLOC_START (0xf0000000)
86#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -070087#define VMALLOC_END (FIXADDR_START-2*PAGE_SIZE)
88
Paul Mundt249cfea2007-11-19 18:26:19 +090089#if defined(CONFIG_SUPERH32)
90#include <asm/pgtable_32.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070091#else
Paul Mundt249cfea2007-11-19 18:26:19 +090092#include <asm/pgtable_64.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070093#endif
94
Linus Torvalds1da177e2005-04-16 15:20:36 -070095/*
Paul Mundt21440cf2006-11-20 14:30:26 +090096 * SH-X and lower (legacy) SuperH parts (SH-3, SH-4, some SH-4A) can't do page
97 * protection for execute, and considers it the same as a read. Also, write
98 * permission implies read permission. This is the closest we can get..
99 *
100 * SH-X2 (SH7785) and later parts take this to the opposite end of the extreme,
101 * not only supporting separate execute, read, and write bits, but having
102 * completely separate permission bits for user and kernel space.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700103 */
Paul Mundt21440cf2006-11-20 14:30:26 +0900104 /*xwr*/
Linus Torvalds1da177e2005-04-16 15:20:36 -0700105#define __P000 PAGE_NONE
106#define __P001 PAGE_READONLY
107#define __P010 PAGE_COPY
108#define __P011 PAGE_COPY
Paul Mundt21440cf2006-11-20 14:30:26 +0900109#define __P100 PAGE_EXECREAD
110#define __P101 PAGE_EXECREAD
Linus Torvalds1da177e2005-04-16 15:20:36 -0700111#define __P110 PAGE_COPY
112#define __P111 PAGE_COPY
113
114#define __S000 PAGE_NONE
115#define __S001 PAGE_READONLY
Paul Mundt21440cf2006-11-20 14:30:26 +0900116#define __S010 PAGE_WRITEONLY
Linus Torvalds1da177e2005-04-16 15:20:36 -0700117#define __S011 PAGE_SHARED
Paul Mundt21440cf2006-11-20 14:30:26 +0900118#define __S100 PAGE_EXECREAD
119#define __S101 PAGE_EXECREAD
120#define __S110 PAGE_RWX
121#define __S111 PAGE_RWX
Linus Torvalds1da177e2005-04-16 15:20:36 -0700122
Linus Torvalds1da177e2005-04-16 15:20:36 -0700123typedef pte_t *pte_addr_t;
124
Linus Torvalds1da177e2005-04-16 15:20:36 -0700125#define kern_addr_valid(addr) (1)
126
Linus Torvalds1da177e2005-04-16 15:20:36 -0700127#define io_remap_pfn_range(vma, vaddr, pfn, size, prot) \
128 remap_pfn_range(vma, vaddr, pfn, size, prot)
129
Paul Mundt249cfea2007-11-19 18:26:19 +0900130#define pte_pfn(x) ((unsigned long)(((x).pte_low >> PAGE_SHIFT)))
Tim Schmielau8c65b4a2005-11-07 00:59:43 -0800131
Linus Torvalds1da177e2005-04-16 15:20:36 -0700132/*
Matt Fleming2a5eacc2009-12-31 12:19:24 +0000133 * Initialise the page table caches
Linus Torvalds1da177e2005-04-16 15:20:36 -0700134 */
Matt Fleming2a5eacc2009-12-31 12:19:24 +0000135extern void pgtable_cache_init(void);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700136
Paul Mundt249cfea2007-11-19 18:26:19 +0900137struct vm_area_struct;
Paul Mundt8f82f0c2011-01-14 15:46:50 +0900138struct mm_struct;
Paul Mundt9cef7492009-07-29 00:12:17 +0900139
140extern void __update_cache(struct vm_area_struct *vma,
141 unsigned long address, pte_t pte);
142extern void __update_tlb(struct vm_area_struct *vma,
143 unsigned long address, pte_t pte);
144
145static inline void
Russell King4b3073e2009-12-18 16:40:18 +0000146update_mmu_cache(struct vm_area_struct *vma, unsigned long address, pte_t *ptep)
Paul Mundt9cef7492009-07-29 00:12:17 +0900147{
Russell King4b3073e2009-12-18 16:40:18 +0000148 pte_t pte = *ptep;
Paul Mundt9cef7492009-07-29 00:12:17 +0900149 __update_cache(vma, address, pte);
150 __update_tlb(vma, address, pte);
151}
152
Paul Mundt21440cf2006-11-20 14:30:26 +0900153extern pgd_t swapper_pg_dir[PTRS_PER_PGD];
154extern void paging_init(void);
Paul Mundt9acb98f2007-12-17 10:52:11 +0900155extern void page_table_range_init(unsigned long start, unsigned long end,
156 pgd_t *pgd);
Paul Mundt21440cf2006-11-20 14:30:26 +0900157
Paul Mundtee1acbf2009-05-07 16:38:16 +0900158/* arch/sh/mm/mmap.c */
159#define HAVE_ARCH_UNMAPPED_AREA
160#define HAVE_ARCH_UNMAPPED_AREA_TOPDOWN
161
Paul Mundta16382c2010-10-27 16:40:19 +0900162#define __HAVE_ARCH_PTE_SPECIAL
163
Linus Torvalds1da177e2005-04-16 15:20:36 -0700164#include <asm-generic/pgtable.h>
165
Paul Mundt249cfea2007-11-19 18:26:19 +0900166#endif /* __ASM_SH_PGTABLE_H */