blob: 5dff5787dfebb041cfd817cc4b4c50886d788f25 [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 Mundt26ff6c12006-09-27 15:13:36 +090015#include <asm-generic/pgtable-nopmd.h>
16#include <asm/page.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070017
Linus Torvalds1da177e2005-04-16 15:20:36 -070018#ifndef __ASSEMBLY__
Linus Torvalds1da177e2005-04-16 15:20:36 -070019#include <asm/addrspace.h>
20#include <asm/fixmap.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070021
Linus Torvalds1da177e2005-04-16 15:20:36 -070022/*
Linus Torvalds1da177e2005-04-16 15:20:36 -070023 * ZERO_PAGE is a global shared page that is always zero: used
24 * for zero-mapped memory areas etc..
25 */
Paul Mundt26ff6c12006-09-27 15:13:36 +090026extern unsigned long empty_zero_page[PAGE_SIZE / sizeof(unsigned long)];
Linus Torvalds1da177e2005-04-16 15:20:36 -070027#define ZERO_PAGE(vaddr) (virt_to_page(empty_zero_page))
28
29#endif /* !__ASSEMBLY__ */
30
Paul Mundt21440cf2006-11-20 14:30:26 +090031/*
Paul Mundt36bcd392007-11-10 19:16:55 +090032 * Effective and physical address definitions, to aid with sign
33 * extension.
34 */
35#define NEFF 32
36#define NEFF_SIGN (1LL << (NEFF - 1))
37#define NEFF_MASK (-1LL << NEFF)
38
Paul Mundtc7914832009-08-04 17:14:39 +090039static inline unsigned long long neff_sign_extend(unsigned long val)
40{
41 unsigned long long extended = val;
42 return (extended & NEFF_SIGN) ? (extended | NEFF_MASK) : extended;
43}
44
Paul Mundt36bcd392007-11-10 19:16:55 +090045#ifdef CONFIG_29BIT
46#define NPHYS 29
47#else
48#define NPHYS 32
49#endif
50
51#define NPHYS_SIGN (1LL << (NPHYS - 1))
52#define NPHYS_MASK (-1LL << NPHYS)
53
54/*
Paul Mundt21440cf2006-11-20 14:30:26 +090055 * traditional two-level paging structure
56 */
57/* PTE bits */
Paul Mundt55183e92007-11-21 16:19:12 +090058#if defined(CONFIG_X2TLB) || defined(CONFIG_SUPERH64)
Paul Mundt21440cf2006-11-20 14:30:26 +090059# define PTE_MAGNITUDE 3 /* 64-bit PTEs on extended mode SH-X2 TLB */
60#else
61# define PTE_MAGNITUDE 2 /* 32-bit PTEs */
62#endif
63#define PTE_SHIFT PAGE_SHIFT
64#define PTE_BITS (PTE_SHIFT - PTE_MAGNITUDE)
65
66/* PGD bits */
67#define PGDIR_SHIFT (PTE_SHIFT + PTE_BITS)
Paul Mundtdb2e1fa2007-02-14 14:13:10 +090068#define PGDIR_SIZE (1UL << PGDIR_SHIFT)
Linus Torvalds1da177e2005-04-16 15:20:36 -070069#define PGDIR_MASK (~(PGDIR_SIZE-1))
70
Paul Mundt21440cf2006-11-20 14:30:26 +090071/* Entries per level */
Paul Mundt7a847f82006-12-26 15:29:19 +090072#define PTRS_PER_PTE (PAGE_SIZE / (1 << PTE_MAGNITUDE))
Paul Mundtd04a0f72007-09-21 11:55:03 +090073#define PTRS_PER_PGD (PAGE_SIZE / sizeof(pgd_t))
Paul Mundt21440cf2006-11-20 14:30:26 +090074
Linus Torvalds1da177e2005-04-16 15:20:36 -070075#define USER_PTRS_PER_PGD (TASK_SIZE/PGDIR_SIZE)
Hugh Dickinsd455a362005-04-19 13:29:23 -070076#define FIRST_USER_ADDRESS 0
Linus Torvalds1da177e2005-04-16 15:20:36 -070077
Matt Fleming1f69b6a2009-10-06 21:22:25 +000078#define PHYS_ADDR_MASK29 0x1fffffff
79#define PHYS_ADDR_MASK32 0xffffffff
80
81#ifdef CONFIG_PMB
82static inline unsigned long phys_addr_mask(void)
83{
84 /* Is the MMU in 29bit mode? */
85 if (__in_29bit_mode())
86 return PHYS_ADDR_MASK29;
87
88 return PHYS_ADDR_MASK32;
89}
90#elif CONFIG_32BIT
91static inline unsigned long phys_addr_mask(void)
92{
93 return PHYS_ADDR_MASK32;
94}
Stuart Menefyd02b08f2007-11-30 17:52:53 +090095#else
Matt Fleming1f69b6a2009-10-06 21:22:25 +000096static inline unsigned long phys_addr_mask(void)
97{
98 return PHYS_ADDR_MASK29;
99}
Stuart Menefyd02b08f2007-11-30 17:52:53 +0900100#endif
101
Matt Fleming1f69b6a2009-10-06 21:22:25 +0000102#define PTE_PHYS_MASK (phys_addr_mask() & PAGE_MASK)
Paul Mundtcb700aa2008-09-12 20:41:05 +0900103#define PTE_FLAGS_MASK (~(PTE_PHYS_MASK) << PAGE_SHIFT)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700104
Paul Mundt0468b4b2007-11-10 20:39:06 +0900105#ifdef CONFIG_SUPERH32
Paul Mundtf0b859e2007-07-25 10:43:47 +0900106#define VMALLOC_START (P3SEG)
Paul Mundt0468b4b2007-11-10 20:39:06 +0900107#else
108#define VMALLOC_START (0xf0000000)
109#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700110#define VMALLOC_END (FIXADDR_START-2*PAGE_SIZE)
111
Paul Mundt249cfea2007-11-19 18:26:19 +0900112#if defined(CONFIG_SUPERH32)
113#include <asm/pgtable_32.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -0700114#else
Paul Mundt249cfea2007-11-19 18:26:19 +0900115#include <asm/pgtable_64.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -0700116#endif
117
Linus Torvalds1da177e2005-04-16 15:20:36 -0700118/*
Paul Mundt21440cf2006-11-20 14:30:26 +0900119 * SH-X and lower (legacy) SuperH parts (SH-3, SH-4, some SH-4A) can't do page
120 * protection for execute, and considers it the same as a read. Also, write
121 * permission implies read permission. This is the closest we can get..
122 *
123 * SH-X2 (SH7785) and later parts take this to the opposite end of the extreme,
124 * not only supporting separate execute, read, and write bits, but having
125 * completely separate permission bits for user and kernel space.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700126 */
Paul Mundt21440cf2006-11-20 14:30:26 +0900127 /*xwr*/
Linus Torvalds1da177e2005-04-16 15:20:36 -0700128#define __P000 PAGE_NONE
129#define __P001 PAGE_READONLY
130#define __P010 PAGE_COPY
131#define __P011 PAGE_COPY
Paul Mundt21440cf2006-11-20 14:30:26 +0900132#define __P100 PAGE_EXECREAD
133#define __P101 PAGE_EXECREAD
Linus Torvalds1da177e2005-04-16 15:20:36 -0700134#define __P110 PAGE_COPY
135#define __P111 PAGE_COPY
136
137#define __S000 PAGE_NONE
138#define __S001 PAGE_READONLY
Paul Mundt21440cf2006-11-20 14:30:26 +0900139#define __S010 PAGE_WRITEONLY
Linus Torvalds1da177e2005-04-16 15:20:36 -0700140#define __S011 PAGE_SHARED
Paul Mundt21440cf2006-11-20 14:30:26 +0900141#define __S100 PAGE_EXECREAD
142#define __S101 PAGE_EXECREAD
143#define __S110 PAGE_RWX
144#define __S111 PAGE_RWX
Linus Torvalds1da177e2005-04-16 15:20:36 -0700145
Linus Torvalds1da177e2005-04-16 15:20:36 -0700146typedef pte_t *pte_addr_t;
147
Linus Torvalds1da177e2005-04-16 15:20:36 -0700148#define kern_addr_valid(addr) (1)
149
Linus Torvalds1da177e2005-04-16 15:20:36 -0700150#define io_remap_pfn_range(vma, vaddr, pfn, size, prot) \
151 remap_pfn_range(vma, vaddr, pfn, size, prot)
152
Paul Mundt249cfea2007-11-19 18:26:19 +0900153#define pte_pfn(x) ((unsigned long)(((x).pte_low >> PAGE_SHIFT)))
Tim Schmielau8c65b4a2005-11-07 00:59:43 -0800154
Linus Torvalds1da177e2005-04-16 15:20:36 -0700155/*
156 * No page table caches to initialise
157 */
158#define pgtable_cache_init() do { } while (0)
159
Paul Mundt249cfea2007-11-19 18:26:19 +0900160struct vm_area_struct;
Paul Mundt9cef7492009-07-29 00:12:17 +0900161
162extern void __update_cache(struct vm_area_struct *vma,
163 unsigned long address, pte_t pte);
164extern void __update_tlb(struct vm_area_struct *vma,
165 unsigned long address, pte_t pte);
166
167static inline void
168update_mmu_cache(struct vm_area_struct *vma, unsigned long address, pte_t pte)
169{
170 __update_cache(vma, address, pte);
171 __update_tlb(vma, address, pte);
172}
173
Paul Mundt21440cf2006-11-20 14:30:26 +0900174extern pgd_t swapper_pg_dir[PTRS_PER_PGD];
175extern void paging_init(void);
Paul Mundt9acb98f2007-12-17 10:52:11 +0900176extern void page_table_range_init(unsigned long start, unsigned long end,
177 pgd_t *pgd);
Paul Mundt21440cf2006-11-20 14:30:26 +0900178
Paul Mundtee1acbf2009-05-07 16:38:16 +0900179/* arch/sh/mm/mmap.c */
180#define HAVE_ARCH_UNMAPPED_AREA
181#define HAVE_ARCH_UNMAPPED_AREA_TOPDOWN
182
Linus Torvalds1da177e2005-04-16 15:20:36 -0700183#include <asm-generic/pgtable.h>
184
Paul Mundt249cfea2007-11-19 18:26:19 +0900185#endif /* __ASM_SH_PGTABLE_H */