aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--arch/xtensa/kernel/entry.S42
-rw-r--r--include/asm-xtensa/pgtable.h213
2 files changed, 129 insertions, 126 deletions
diff --git a/arch/xtensa/kernel/entry.S b/arch/xtensa/kernel/entry.S
index 8dc7a2c26ff9..65741e3368e7 100644
--- a/arch/xtensa/kernel/entry.S
+++ b/arch/xtensa/kernel/entry.S
@@ -1572,10 +1572,12 @@ ENTRY(fast_second_level_miss)
1572 l32i a0, a1, TASK_MM # tsk->mm 1572 l32i a0, a1, TASK_MM # tsk->mm
1573 beqz a0, 9f 1573 beqz a0, 9f
1574 1574
15758: rsr a1, EXCVADDR # fault address 1575
1576 _PGD_OFFSET(a0, a1, a1) 1576 /* We deliberately destroy a3 that holds the exception table. */
1577
15788: rsr a3, EXCVADDR # fault address
1579 _PGD_OFFSET(a0, a3, a1)
1577 l32i a0, a0, 0 # read pmdval 1580 l32i a0, a0, 0 # read pmdval
1578 //beqi a0, _PAGE_USER, 2f
1579 beqz a0, 2f 1581 beqz a0, 2f
1580 1582
1581 /* Read ptevaddr and convert to top of page-table page. 1583 /* Read ptevaddr and convert to top of page-table page.
@@ -1596,20 +1598,34 @@ ENTRY(fast_second_level_miss)
1596 extui a1, a0, 0, PAGE_SHIFT # ... & PAGE_MASK 1598 extui a1, a0, 0, PAGE_SHIFT # ... & PAGE_MASK
1597 xor a0, a0, a1 1599 xor a0, a0, a1
1598 1600
1599 1601 movi a1, _PAGE_DIRECTORY
1600 movi a1, PAGE_DIRECTORY
1601 or a0, a0, a1 # ... | PAGE_DIRECTORY 1602 or a0, a0, a1 # ... | PAGE_DIRECTORY
1602 1603
1604 /*
1605 * We utilize all three wired-ways (7-9( to hold pmd translations.
1606 * Memory regions are mapped to the DTLBs according to bits 28 and 29.
1607 * This allows to map the three most common regions to three different
1608 * DTLBs:
1609 * 0,1 -> way 7 program (0040.0000) and virtual (c000.0000)
1610 * 2 -> way 8 shared libaries (2000.0000)
1611 * 3 -> way 0 stack (3000.0000)
1612 */
1613
1614 extui a3, a3, 28, 2 # addr. bit 28 and 29 0,1,2,3
1603 rsr a1, PTEVADDR 1615 rsr a1, PTEVADDR
1616 addx2 a3, a3, a3 # -> 0,3,6,9
1604 srli a1, a1, PAGE_SHIFT 1617 srli a1, a1, PAGE_SHIFT
1618 extui a3, a3, 2, 2 # -> 0,0,1,2
1605 slli a1, a1, PAGE_SHIFT # ptevaddr & PAGE_MASK 1619 slli a1, a1, PAGE_SHIFT # ptevaddr & PAGE_MASK
1606 addi a1, a1, DTLB_WAY_PGD # ... + way_number 1620 addi a3, a3, DTLB_WAY_PGD
1621 add a1, a1, a3 # ... + way_number
1607 1622
1608 wdtlb a0, a1 16233: wdtlb a0, a1
1609 dsync 1624 dsync
1610 1625
1611 /* Exit critical section. */ 1626 /* Exit critical section. */
1612 1627
16284: movi a3, exc_table # restore a3
1613 movi a0, 0 1629 movi a0, 0
1614 s32i a0, a3, EXC_TABLE_FIXUP 1630 s32i a0, a3, EXC_TABLE_FIXUP
1615 1631
@@ -1638,6 +1654,7 @@ ENTRY(fast_second_level_miss)
1638 1654
16392: /* Invalid PGD, default exception handling */ 16552: /* Invalid PGD, default exception handling */
1640 1656
1657 movi a3, exc_table
1641 rsr a1, DEPC 1658 rsr a1, DEPC
1642 xsr a3, EXCSAVE_1 1659 xsr a3, EXCSAVE_1
1643 s32i a1, a2, PT_AREG2 1660 s32i a1, a2, PT_AREG2
@@ -1682,15 +1699,15 @@ ENTRY(fast_store_prohibited)
16828: rsr a1, EXCVADDR # fault address 16998: rsr a1, EXCVADDR # fault address
1683 _PGD_OFFSET(a0, a1, a4) 1700 _PGD_OFFSET(a0, a1, a4)
1684 l32i a0, a0, 0 1701 l32i a0, a0, 0
1685 //beqi a0, _PAGE_USER, 2f # FIXME use _PAGE_INVALID
1686 beqz a0, 2f 1702 beqz a0, 2f
1687 1703
1704 /* Note that we assume _PAGE_WRITABLE_BIT is only set if pte is valid.*/
1705
1688 _PTE_OFFSET(a0, a1, a4) 1706 _PTE_OFFSET(a0, a1, a4)
1689 l32i a4, a0, 0 # read pteval 1707 l32i a4, a0, 0 # read pteval
1690 movi a1, _PAGE_VALID | _PAGE_RW 1708 bbci.l a4, _PAGE_WRITABLE_BIT, 2f
1691 bnall a4, a1, 2f
1692 1709
1693 movi a1, _PAGE_ACCESSED | _PAGE_DIRTY | _PAGE_WRENABLE 1710 movi a1, _PAGE_ACCESSED | _PAGE_DIRTY | _PAGE_HW_WRITE
1694 or a4, a4, a1 1711 or a4, a4, a1
1695 rsr a1, EXCVADDR 1712 rsr a1, EXCVADDR
1696 s32i a4, a0, 0 1713 s32i a4, a0, 0
@@ -1700,10 +1717,7 @@ ENTRY(fast_store_prohibited)
1700 dhwb a0, 0 1717 dhwb a0, 0
1701#endif 1718#endif
1702 pdtlb a0, a1 1719 pdtlb a0, a1
1703 beqz a0, 1f
1704 idtlb a0 // FIXME do we need this?
1705 wdtlb a4, a0 1720 wdtlb a4, a0
17061:
1707 1721
1708 /* Exit critical section. */ 1722 /* Exit critical section. */
1709 1723
diff --git a/include/asm-xtensa/pgtable.h b/include/asm-xtensa/pgtable.h
index 06850f3b26a7..667a6c46b5a1 100644
--- a/include/asm-xtensa/pgtable.h
+++ b/include/asm-xtensa/pgtable.h
@@ -2,10 +2,10 @@
2 * linux/include/asm-xtensa/pgtable.h 2 * linux/include/asm-xtensa/pgtable.h
3 * 3 *
4 * This program is free software; you can redistribute it and/or modify 4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version2 as 5 * it under the terms of the GNU General Public License version 2 as
6 * published by the Free Software Foundation. 6 * published by the Free Software Foundation.
7 * 7 *
8 * Copyright (C) 2001 - 2005 Tensilica Inc. 8 * Copyright (C) 2001 - 2007 Tensilica Inc.
9 */ 9 */
10 10
11#ifndef _XTENSA_PGTABLE_H 11#ifndef _XTENSA_PGTABLE_H
@@ -23,7 +23,7 @@
23 23
24/* 24/*
25 * The Xtensa architecture port of Linux has a two-level page table system, 25 * The Xtensa architecture port of Linux has a two-level page table system,
26 * i.e. the logical three-level Linux page table layout are folded. 26 * i.e. the logical three-level Linux page table layout is folded.
27 * Each task has the following memory page tables: 27 * Each task has the following memory page tables:
28 * 28 *
29 * PGD table (page directory), ie. 3rd-level page table: 29 * PGD table (page directory), ie. 3rd-level page table:
@@ -43,6 +43,7 @@
43 * 43 *
44 * The individual pages are 4 kB big with special pages for the empty_zero_page. 44 * The individual pages are 4 kB big with special pages for the empty_zero_page.
45 */ 45 */
46
46#define PGDIR_SHIFT 22 47#define PGDIR_SHIFT 22
47#define PGDIR_SIZE (1UL << PGDIR_SHIFT) 48#define PGDIR_SIZE (1UL << PGDIR_SHIFT)
48#define PGDIR_MASK (~(PGDIR_SIZE-1)) 49#define PGDIR_MASK (~(PGDIR_SIZE-1))
@@ -53,12 +54,10 @@
53 */ 54 */
54#define PTRS_PER_PTE 1024 55#define PTRS_PER_PTE 1024
55#define PTRS_PER_PTE_SHIFT 10 56#define PTRS_PER_PTE_SHIFT 10
56#define PTRS_PER_PMD 1
57#define PTRS_PER_PGD 1024 57#define PTRS_PER_PGD 1024
58#define PGD_ORDER 0 58#define PGD_ORDER 0
59#define PMD_ORDER 0
60#define USER_PTRS_PER_PGD (TASK_SIZE/PGDIR_SIZE) 59#define USER_PTRS_PER_PGD (TASK_SIZE/PGDIR_SIZE)
61#define FIRST_USER_ADDRESS 0 60#define FIRST_USER_ADDRESS 0
62#define FIRST_USER_PGD_NR (FIRST_USER_ADDRESS >> PGDIR_SHIFT) 61#define FIRST_USER_PGD_NR (FIRST_USER_ADDRESS >> PGDIR_SHIFT)
63 62
64/* virtual memory area. We keep a distance to other memory regions to be 63/* virtual memory area. We keep a distance to other memory regions to be
@@ -86,47 +85,54 @@
86 * See further below for PTE layout for swapped-out pages. 85 * See further below for PTE layout for swapped-out pages.
87 */ 86 */
88 87
89#define _PAGE_VALID (1<<0) /* hardware: page is accessible */ 88#define _PAGE_HW_EXEC (1<<0) /* hardware: page is executable */
90#define _PAGE_WRENABLE (1<<1) /* hardware: page is writable */ 89#define _PAGE_HW_WRITE (1<<1) /* hardware: page is writable */
90
91#define _PAGE_FILE (1<<1) /* non-linear mapping, if !present */
92#define _PAGE_PROTNONE (3<<0) /* special case for VM_PROT_NONE */
91 93
92/* None of these cache modes include MP coherency: */ 94/* None of these cache modes include MP coherency: */
93#define _PAGE_NO_CACHE (0<<2) /* bypass, non-speculative */ 95#define _PAGE_CA_BYPASS (0<<2) /* bypass, non-speculative */
94#if XCHAL_DCACHE_IS_WRITEBACK 96#define _PAGE_CA_WB (1<<2) /* write-back */
95# define _PAGE_WRITEBACK (1<<2) /* write back */ 97#define _PAGE_CA_WT (2<<2) /* write-through */
96# define _PAGE_WRITETHRU (2<<2) /* write through */ 98#define _PAGE_CA_MASK (3<<2)
97#else 99#define _PAGE_INVALID (3<<2)
98# define _PAGE_WRITEBACK (1<<2) /* assume write through */
99# define _PAGE_WRITETHRU (1<<2)
100#endif
101#define _PAGE_NOALLOC (3<<2) /* don't allocate cache,if not cached */
102#define _CACHE_MASK (3<<2)
103 100
104#define _PAGE_USER (1<<4) /* user access (ring=1) */ 101#define _PAGE_USER (1<<4) /* user access (ring=1) */
105#define _PAGE_KERNEL (0<<4) /* kernel access (ring=0) */
106 102
107/* Software */ 103/* Software */
108#define _PAGE_RW (1<<6) /* software: page writable */ 104#define _PAGE_WRITABLE_BIT 6
105#define _PAGE_WRITABLE (1<<6) /* software: page writable */
109#define _PAGE_DIRTY (1<<7) /* software: page dirty */ 106#define _PAGE_DIRTY (1<<7) /* software: page dirty */
110#define _PAGE_ACCESSED (1<<8) /* software: page accessed (read) */ 107#define _PAGE_ACCESSED (1<<8) /* software: page accessed (read) */
111#define _PAGE_FILE (1<<9) /* nonlinear file mapping*/
112 108
113#define _PAGE_CHG_MASK (PAGE_MASK | _PAGE_ACCESSED | _CACHE_MASK | _PAGE_DIRTY) 109/* On older HW revisions, we always have to set bit 0 */
114#define _PAGE_PRESENT ( _PAGE_VALID | _PAGE_WRITEBACK | _PAGE_ACCESSED) 110#if XCHAL_HW_VERSION_MAJOR < 2000
111# define _PAGE_VALID (1<<0)
112#else
113# define _PAGE_VALID 0
114#endif
115
116#define _PAGE_CHG_MASK (PAGE_MASK | _PAGE_ACCESSED | _PAGE_DIRTY)
117#define _PAGE_PRESENT (_PAGE_VALID | _PAGE_CA_WB | _PAGE_ACCESSED)
115 118
116#ifdef CONFIG_MMU 119#ifdef CONFIG_MMU
117 120
118# define PAGE_NONE __pgprot(_PAGE_PRESENT) 121#define PAGE_NONE __pgprot(_PAGE_INVALID | _PAGE_USER | _PAGE_PROTNONE)
119# define PAGE_SHARED __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_RW) 122#define PAGE_COPY __pgprot(_PAGE_PRESENT | _PAGE_USER)
120# define PAGE_COPY __pgprot(_PAGE_PRESENT | _PAGE_USER) 123#define PAGE_COPY_EXEC __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_HW_EXEC)
121# define PAGE_READONLY __pgprot(_PAGE_PRESENT | _PAGE_USER) 124#define PAGE_READONLY __pgprot(_PAGE_PRESENT | _PAGE_USER)
122# define PAGE_KERNEL __pgprot(_PAGE_PRESENT | _PAGE_KERNEL | _PAGE_WRENABLE) 125#define PAGE_READONLY_EXEC __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_HW_EXEC)
123# define PAGE_INVALID __pgprot(_PAGE_USER) 126#define PAGE_SHARED __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_WRITABLE)
124 127#define PAGE_SHARED_EXEC \
125# if (DCACHE_WAY_SIZE > PAGE_SIZE) 128 __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_WRITABLE | _PAGE_HW_EXEC)
126# define PAGE_DIRECTORY __pgprot(_PAGE_VALID | _PAGE_ACCESSED | _PAGE_KERNEL) 129#define PAGE_KERNEL __pgprot(_PAGE_PRESENT)
127# else 130
128# define PAGE_DIRECTORY __pgprot(_PAGE_PRESENT | _PAGE_KERNEL) 131#if (DCACHE_WAY_SIZE > PAGE_SIZE)
129# endif 132# define _PAGE_DIRECTORY (_PAGE_VALID | _PAGE_ACCESSED | _PAGE_HW_WRITE)
133#else
134# define _PAGE_DIRECTORY (_PAGE_VALID|_PAGE_ACCESSED|_PAGE_HW_WRITE|_PAGE_CA_WB)
135#endif
130 136
131#else /* no mmu */ 137#else /* no mmu */
132 138
@@ -145,23 +151,23 @@
145 * What follows is the closest we can get by reasonable means.. 151 * What follows is the closest we can get by reasonable means..
146 * See linux/mm/mmap.c for protection_map[] array that uses these definitions. 152 * See linux/mm/mmap.c for protection_map[] array that uses these definitions.
147 */ 153 */
148#define __P000 PAGE_NONE /* private --- */ 154#define __P000 PAGE_NONE /* private --- */
149#define __P001 PAGE_READONLY /* private --r */ 155#define __P001 PAGE_READONLY /* private --r */
150#define __P010 PAGE_COPY /* private -w- */ 156#define __P010 PAGE_COPY /* private -w- */
151#define __P011 PAGE_COPY /* private -wr */ 157#define __P011 PAGE_COPY /* private -wr */
152#define __P100 PAGE_READONLY /* private x-- */ 158#define __P100 PAGE_READONLY_EXEC /* private x-- */
153#define __P101 PAGE_READONLY /* private x-r */ 159#define __P101 PAGE_READONLY_EXEC /* private x-r */
154#define __P110 PAGE_COPY /* private xw- */ 160#define __P110 PAGE_COPY_EXEC /* private xw- */
155#define __P111 PAGE_COPY /* private xwr */ 161#define __P111 PAGE_COPY_EXEC /* private xwr */
156 162
157#define __S000 PAGE_NONE /* shared --- */ 163#define __S000 PAGE_NONE /* shared --- */
158#define __S001 PAGE_READONLY /* shared --r */ 164#define __S001 PAGE_READONLY /* shared --r */
159#define __S010 PAGE_SHARED /* shared -w- */ 165#define __S010 PAGE_SHARED /* shared -w- */
160#define __S011 PAGE_SHARED /* shared -wr */ 166#define __S011 PAGE_SHARED /* shared -wr */
161#define __S100 PAGE_READONLY /* shared x-- */ 167#define __S100 PAGE_READONLY_EXEC /* shared x-- */
162#define __S101 PAGE_READONLY /* shared x-r */ 168#define __S101 PAGE_READONLY_EXEC /* shared x-r */
163#define __S110 PAGE_SHARED /* shared xw- */ 169#define __S110 PAGE_SHARED_EXEC /* shared xw- */
164#define __S111 PAGE_SHARED /* shared xwr */ 170#define __S111 PAGE_SHARED_EXEC /* shared xwr */
165 171
166#ifndef __ASSEMBLY__ 172#ifndef __ASSEMBLY__
167 173
@@ -183,35 +189,42 @@ extern pgd_t swapper_pg_dir[PAGE_SIZE/sizeof(pgd_t)];
183#define pmd_page(pmd) virt_to_page(pmd_val(pmd)) 189#define pmd_page(pmd) virt_to_page(pmd_val(pmd))
184 190
185/* 191/*
186 * The following only work if pte_present() is true. 192 * pte status.
187 */ 193 */
188#define pte_none(pte) (!(pte_val(pte) ^ _PAGE_USER)) 194#define pte_none(pte) (pte_val(pte) == _PAGE_INVALID)
189#define pte_present(pte) (pte_val(pte) & _PAGE_VALID) 195#define pte_present(pte) \
196 (((pte_val(pte) & _PAGE_CA_MASK) != _PAGE_INVALID) \
197 || ((pte_val(pte) & _PAGE_PROTNONE) == _PAGE_PROTNONE))
190#define pte_clear(mm,addr,ptep) \ 198#define pte_clear(mm,addr,ptep) \
191 do { update_pte(ptep, __pte(_PAGE_USER)); } while(0) 199 do { update_pte(ptep, __pte(_PAGE_INVALID)); } while(0)
192 200
193#define pmd_none(pmd) (!pmd_val(pmd)) 201#define pmd_none(pmd) (!pmd_val(pmd))
194#define pmd_present(pmd) (pmd_val(pmd) & PAGE_MASK) 202#define pmd_present(pmd) (pmd_val(pmd) & PAGE_MASK)
195#define pmd_clear(pmdp) do { set_pmd(pmdp, __pmd(0)); } while (0)
196#define pmd_bad(pmd) (pmd_val(pmd) & ~PAGE_MASK) 203#define pmd_bad(pmd) (pmd_val(pmd) & ~PAGE_MASK)
204#define pmd_clear(pmdp) do { set_pmd(pmdp, __pmd(0)); } while (0)
197 205
198/* Note: We use the _PAGE_USER bit to indicate write-protect kernel memory */ 206static inline int pte_write(pte_t pte) { return pte_val(pte) & _PAGE_WRITABLE; }
199
200static inline int pte_write(pte_t pte) { return pte_val(pte) & _PAGE_RW; }
201static inline int pte_dirty(pte_t pte) { return pte_val(pte) & _PAGE_DIRTY; } 207static inline int pte_dirty(pte_t pte) { return pte_val(pte) & _PAGE_DIRTY; }
202static inline int pte_young(pte_t pte) { return pte_val(pte) & _PAGE_ACCESSED; } 208static inline int pte_young(pte_t pte) { return pte_val(pte) & _PAGE_ACCESSED; }
203static inline int pte_file(pte_t pte) { return pte_val(pte) & _PAGE_FILE; } 209static inline int pte_file(pte_t pte) { return pte_val(pte) & _PAGE_FILE; }
204static inline pte_t pte_wrprotect(pte_t pte) { pte_val(pte) &= ~(_PAGE_RW | _PAGE_WRENABLE); return pte; } 210static inline pte_t pte_wrprotect(pte_t pte)
205static inline pte_t pte_mkclean(pte_t pte) { pte_val(pte) &= ~_PAGE_DIRTY; return pte; } 211 { pte_val(pte) &= ~(_PAGE_WRITABLE | _PAGE_HW_WRITE); return pte; }
206static inline pte_t pte_mkold(pte_t pte) { pte_val(pte) &= ~_PAGE_ACCESSED; return pte; } 212static inline pte_t pte_mkclean(pte_t pte)
207static inline pte_t pte_mkdirty(pte_t pte) { pte_val(pte) |= _PAGE_DIRTY; return pte; } 213 { pte_val(pte) &= ~(_PAGE_DIRTY | _PAGE_HW_WRITE); return pte; }
208static inline pte_t pte_mkyoung(pte_t pte) { pte_val(pte) |= _PAGE_ACCESSED; return pte; } 214static inline pte_t pte_mkold(pte_t pte)
209static inline pte_t pte_mkwrite(pte_t pte) { pte_val(pte) |= _PAGE_RW; return pte; } 215 { pte_val(pte) &= ~_PAGE_ACCESSED; return pte; }
216static inline pte_t pte_mkdirty(pte_t pte)
217 { pte_val(pte) |= _PAGE_DIRTY; return pte; }
218static inline pte_t pte_mkyoung(pte_t pte)
219 { pte_val(pte) |= _PAGE_ACCESSED; return pte; }
220static inline pte_t pte_mkwrite(pte_t pte)
221 { pte_val(pte) |= _PAGE_WRITABLE; return pte; }
210 222
211/* 223/*
212 * Conversion functions: convert a page and protection to a page entry, 224 * Conversion functions: convert a page and protection to a page entry,
213 * and a page entry and page directory to the page they refer to. 225 * and a page entry and page directory to the page they refer to.
214 */ 226 */
227
215#define pte_pfn(pte) (pte_val(pte) >> PAGE_SHIFT) 228#define pte_pfn(pte) (pte_val(pte) >> PAGE_SHIFT)
216#define pte_same(a,b) (pte_val(a) == pte_val(b)) 229#define pte_same(a,b) (pte_val(a) == pte_val(b))
217#define pte_page(x) pfn_to_page(pte_pfn(x)) 230#define pte_page(x) pfn_to_page(pte_pfn(x))
@@ -231,9 +244,6 @@ static inline pte_t pte_modify(pte_t pte, pgprot_t newprot)
231static inline void update_pte(pte_t *ptep, pte_t pteval) 244static inline void update_pte(pte_t *ptep, pte_t pteval)
232{ 245{
233 *ptep = pteval; 246 *ptep = pteval;
234#if (DCACHE_WAY_SIZE > PAGE_SIZE) && XCHAL_DCACHE_IS_WRITEBACK
235 __asm__ __volatile__ ("memw; dhwb %0, 0; dsync" :: "a" (ptep));
236#endif
237} 247}
238 248
239struct mm_struct; 249struct mm_struct;
@@ -249,9 +259,6 @@ static inline void
249set_pmd(pmd_t *pmdp, pmd_t pmdval) 259set_pmd(pmd_t *pmdp, pmd_t pmdval)
250{ 260{
251 *pmdp = pmdval; 261 *pmdp = pmdval;
252#if (DCACHE_WAY_SIZE > PAGE_SIZE) && XCHAL_DCACHE_IS_WRITEBACK
253 __asm__ __volatile__ ("memw; dhwb %0, 0; dsync" :: "a" (pmdp));
254#endif
255} 262}
256 263
257struct vm_area_struct; 264struct vm_area_struct;
@@ -306,52 +313,34 @@ ptep_set_wrprotect(struct mm_struct *mm, unsigned long addr, pte_t *ptep)
306 313
307/* 314/*
308 * Encode and decode a swap entry. 315 * Encode and decode a swap entry.
309 * Each PTE in a process VM's page table is either:
310 * "present" -- valid and not swapped out, protection bits are meaningful;
311 * "not present" -- which further subdivides in these two cases:
312 * "none" -- no mapping at all; identified by pte_none(), set by pte_clear(
313 * "swapped out" -- the page is swapped out, and the SWP macros below
314 * are used to store swap file info in the PTE itself.
315 *
316 * In the Xtensa processor MMU, any PTE entries in user space (or anywhere
317 * in virtual memory that can map differently across address spaces)
318 * must have a correct ring value that represents the RASID field that
319 * is changed when switching address spaces. Eg. such PTE entries cannot
320 * be set to ring zero, because that can cause a (global) kernel ASID
321 * entry to be created in the TLBs (even with invalid cache attribute),
322 * potentially causing a multihit exception when going back to another
323 * address space that mapped the same virtual address at another ring.
324 *
325 * SO: we avoid using ring bits (_PAGE_RING_MASK) in "not present" PTEs.
326 * We also avoid using the _PAGE_VALID bit which must be zero for non-present
327 * pages.
328 * 316 *
329 * We end up with the following available bits: 1..3 and 7..31. 317 * Format of swap pte:
330 * We don't bother with 1..3 for now (we can use them later if needed), 318 * bit 0 MBZ
331 * and chose to allocate 6 bits for SWP_TYPE and the remaining 19 bits 319 * bit 1 page-file (must be zero)
332 * for SWP_OFFSET. At least 5 bits are needed for SWP_TYPE, because it 320 * bits 2 - 3 page hw access mode (must be 11: _PAGE_INVALID)
333 * is currently implemented as an index into swap_info[MAX_SWAPFILES] 321 * bits 4 - 5 ring protection (must be 01: _PAGE_USER)
334 * and MAX_SWAPFILES is currently defined as 32 in <linux/swap.h>. 322 * bits 6 - 10 swap type (5 bits -> 32 types)
335 * However, for some reason all other architectures in the 2.4 kernel 323 * bits 11 - 31 swap offset / PAGE_SIZE (21 bits -> 8GB)
336 * reserve either 6, 7, or 8 bits so I'll not detract from that for now. :) 324
337 * SWP_OFFSET is an offset into the swap file in page-size units, so 325 * Format of file pte:
338 * with 4 kB pages, 19 bits supports a maximum swap file size of 2 GB. 326 * bit 0 MBZ
339 * 327 * bit 1 page-file (must be one: _PAGE_FILE)
340 * FIXME: 2 GB isn't very big. Other bits can be used to allow 328 * bits 2 - 3 page hw access mode (must be 11: _PAGE_INVALID)
341 * larger swap sizes. In the meantime, it appears relatively easy to get 329 * bits 4 - 5 ring protection (must be 01: _PAGE_USER)
342 * around the 2 GB limitation by simply using multiple swap files. 330 * bits 6 - 31 file offset / PAGE_SIZE
343 */ 331 */
344 332
345#define __swp_type(entry) (((entry).val >> 7) & 0x3f) 333#define __swp_type(entry) (((entry).val >> 6) & 0x1f)
346#define __swp_offset(entry) ((entry).val >> 13) 334#define __swp_offset(entry) ((entry).val >> 11)
347#define __swp_entry(type,offs) ((swp_entry_t) {((type) << 7) | ((offs) << 13)}) 335#define __swp_entry(type,offs) \
336 ((swp_entry_t) {((type) << 6) | ((offs) << 11) | _PAGE_INVALID})
348#define __pte_to_swp_entry(pte) ((swp_entry_t) { pte_val(pte) }) 337#define __pte_to_swp_entry(pte) ((swp_entry_t) { pte_val(pte) })
349#define __swp_entry_to_pte(x) ((pte_t) { (x).val }) 338#define __swp_entry_to_pte(x) ((pte_t) { (x).val })
350 339
351#define PTE_FILE_MAX_BITS 29 340#define PTE_FILE_MAX_BITS 28
352#define pte_to_pgoff(pte) (pte_val(pte) >> 3) 341#define pte_to_pgoff(pte) (pte_val(pte) >> 4)
353#define pgoff_to_pte(off) ((pte_t) { ((off) << 3) | _PAGE_FILE }) 342#define pgoff_to_pte(off) \
354 343 ((pte_t) { ((off) << 4) | _PAGE_INVALID | _PAGE_FILE })
355 344
356#endif /* !defined (__ASSEMBLY__) */ 345#endif /* !defined (__ASSEMBLY__) */
357 346