16a3cece5e5e7e7c0fde769d7cf065fb8aef6e54eMichal Simek/* 215902bf63c8332946e5a1f48a72e3ae22874b11bMichal Simek * Copyright (C) 2008-2009 Michal Simek <monstr@monstr.eu> 315902bf63c8332946e5a1f48a72e3ae22874b11bMichal Simek * Copyright (C) 2008-2009 PetaLogix 46a3cece5e5e7e7c0fde769d7cf065fb8aef6e54eMichal Simek * Copyright (C) 2006 Atmark Techno, Inc. 56a3cece5e5e7e7c0fde769d7cf065fb8aef6e54eMichal Simek * 66a3cece5e5e7e7c0fde769d7cf065fb8aef6e54eMichal Simek * This file is subject to the terms and conditions of the GNU General Public 76a3cece5e5e7e7c0fde769d7cf065fb8aef6e54eMichal Simek * License. See the file "COPYING" in the main directory of this archive 86a3cece5e5e7e7c0fde769d7cf065fb8aef6e54eMichal Simek * for more details. 96a3cece5e5e7e7c0fde769d7cf065fb8aef6e54eMichal Simek */ 106a3cece5e5e7e7c0fde769d7cf065fb8aef6e54eMichal Simek 116a3cece5e5e7e7c0fde769d7cf065fb8aef6e54eMichal Simek#ifndef _ASM_MICROBLAZE_PGTABLE_H 126a3cece5e5e7e7c0fde769d7cf065fb8aef6e54eMichal Simek#define _ASM_MICROBLAZE_PGTABLE_H 136a3cece5e5e7e7c0fde769d7cf065fb8aef6e54eMichal Simek 146a3cece5e5e7e7c0fde769d7cf065fb8aef6e54eMichal Simek#include <asm/setup.h> 156a3cece5e5e7e7c0fde769d7cf065fb8aef6e54eMichal Simek 1679bf3a137617e6deeac411c39f1660b7e91d6348Michal Simek#ifndef __ASSEMBLY__ 1779bf3a137617e6deeac411c39f1660b7e91d6348Michal Simekextern int mem_init_done; 1879bf3a137617e6deeac411c39f1660b7e91d6348Michal Simek#endif 1979bf3a137617e6deeac411c39f1660b7e91d6348Michal Simek 2015902bf63c8332946e5a1f48a72e3ae22874b11bMichal Simek#ifndef CONFIG_MMU 2115902bf63c8332946e5a1f48a72e3ae22874b11bMichal Simek 226a3cece5e5e7e7c0fde769d7cf065fb8aef6e54eMichal Simek#define pgd_present(pgd) (1) /* pages are always present on non MMU */ 236a3cece5e5e7e7c0fde769d7cf065fb8aef6e54eMichal Simek#define pgd_none(pgd) (0) 246a3cece5e5e7e7c0fde769d7cf065fb8aef6e54eMichal Simek#define pgd_bad(pgd) (0) 256a3cece5e5e7e7c0fde769d7cf065fb8aef6e54eMichal Simek#define pgd_clear(pgdp) 266a3cece5e5e7e7c0fde769d7cf065fb8aef6e54eMichal Simek#define kern_addr_valid(addr) (1) 276a3cece5e5e7e7c0fde769d7cf065fb8aef6e54eMichal Simek#define pmd_offset(a, b) ((void *) 0) 286a3cece5e5e7e7c0fde769d7cf065fb8aef6e54eMichal Simek 296a3cece5e5e7e7c0fde769d7cf065fb8aef6e54eMichal Simek#define PAGE_NONE __pgprot(0) /* these mean nothing to non MMU */ 306a3cece5e5e7e7c0fde769d7cf065fb8aef6e54eMichal Simek#define PAGE_SHARED __pgprot(0) /* these mean nothing to non MMU */ 316a3cece5e5e7e7c0fde769d7cf065fb8aef6e54eMichal Simek#define PAGE_COPY __pgprot(0) /* these mean nothing to non MMU */ 326a3cece5e5e7e7c0fde769d7cf065fb8aef6e54eMichal Simek#define PAGE_READONLY __pgprot(0) /* these mean nothing to non MMU */ 336a3cece5e5e7e7c0fde769d7cf065fb8aef6e54eMichal Simek#define PAGE_KERNEL __pgprot(0) /* these mean nothing to non MMU */ 346a3cece5e5e7e7c0fde769d7cf065fb8aef6e54eMichal Simek 350c60155e14eb00fa13836a710a2d2efb63d8861cArnd Bergmann#define pgprot_noncached(x) (x) 360c60155e14eb00fa13836a710a2d2efb63d8861cArnd Bergmann 376a3cece5e5e7e7c0fde769d7cf065fb8aef6e54eMichal Simek#define __swp_type(x) (0) 386a3cece5e5e7e7c0fde769d7cf065fb8aef6e54eMichal Simek#define __swp_offset(x) (0) 396a3cece5e5e7e7c0fde769d7cf065fb8aef6e54eMichal Simek#define __swp_entry(typ, off) ((swp_entry_t) { ((typ) | ((off) << 7)) }) 406a3cece5e5e7e7c0fde769d7cf065fb8aef6e54eMichal Simek#define __pte_to_swp_entry(pte) ((swp_entry_t) { pte_val(pte) }) 416a3cece5e5e7e7c0fde769d7cf065fb8aef6e54eMichal Simek#define __swp_entry_to_pte(x) ((pte_t) { (x).val }) 426a3cece5e5e7e7c0fde769d7cf065fb8aef6e54eMichal Simek 436a3cece5e5e7e7c0fde769d7cf065fb8aef6e54eMichal Simek#ifndef __ASSEMBLY__ 446a3cece5e5e7e7c0fde769d7cf065fb8aef6e54eMichal Simekstatic inline int pte_file(pte_t pte) { return 0; } 456a3cece5e5e7e7c0fde769d7cf065fb8aef6e54eMichal Simek#endif /* __ASSEMBLY__ */ 466a3cece5e5e7e7c0fde769d7cf065fb8aef6e54eMichal Simek 476a3cece5e5e7e7c0fde769d7cf065fb8aef6e54eMichal Simek#define ZERO_PAGE(vaddr) ({ BUG(); NULL; }) 486a3cece5e5e7e7c0fde769d7cf065fb8aef6e54eMichal Simek 496a3cece5e5e7e7c0fde769d7cf065fb8aef6e54eMichal Simek#define swapper_pg_dir ((pgd_t *) NULL) 506a3cece5e5e7e7c0fde769d7cf065fb8aef6e54eMichal Simek 516a3cece5e5e7e7c0fde769d7cf065fb8aef6e54eMichal Simek#define pgtable_cache_init() do {} while (0) 526a3cece5e5e7e7c0fde769d7cf065fb8aef6e54eMichal Simek 536a3cece5e5e7e7c0fde769d7cf065fb8aef6e54eMichal Simek#define arch_enter_lazy_cpu_mode() do {} while (0) 546a3cece5e5e7e7c0fde769d7cf065fb8aef6e54eMichal Simek 5579bf3a137617e6deeac411c39f1660b7e91d6348Michal Simek#define pgprot_noncached_wc(prot) prot 5679bf3a137617e6deeac411c39f1660b7e91d6348Michal Simek 57099a2f4284eba5da2708d0e8fe0797dc095d47caMichal Simek/* 58099a2f4284eba5da2708d0e8fe0797dc095d47caMichal Simek * All 32bit addresses are effectively valid for vmalloc... 59099a2f4284eba5da2708d0e8fe0797dc095d47caMichal Simek * Sort of meaningless for non-VM targets. 60099a2f4284eba5da2708d0e8fe0797dc095d47caMichal Simek */ 61099a2f4284eba5da2708d0e8fe0797dc095d47caMichal Simek#define VMALLOC_START 0 62099a2f4284eba5da2708d0e8fe0797dc095d47caMichal Simek#define VMALLOC_END 0xffffffff 63099a2f4284eba5da2708d0e8fe0797dc095d47caMichal Simek 6415902bf63c8332946e5a1f48a72e3ae22874b11bMichal Simek#else /* CONFIG_MMU */ 6515902bf63c8332946e5a1f48a72e3ae22874b11bMichal Simek 6615902bf63c8332946e5a1f48a72e3ae22874b11bMichal Simek#include <asm-generic/4level-fixup.h> 6715902bf63c8332946e5a1f48a72e3ae22874b11bMichal Simek 6815902bf63c8332946e5a1f48a72e3ae22874b11bMichal Simek#ifdef __KERNEL__ 6915902bf63c8332946e5a1f48a72e3ae22874b11bMichal Simek#ifndef __ASSEMBLY__ 7015902bf63c8332946e5a1f48a72e3ae22874b11bMichal Simek 7115902bf63c8332946e5a1f48a72e3ae22874b11bMichal Simek#include <linux/sched.h> 7215902bf63c8332946e5a1f48a72e3ae22874b11bMichal Simek#include <linux/threads.h> 7315902bf63c8332946e5a1f48a72e3ae22874b11bMichal Simek#include <asm/processor.h> /* For TASK_SIZE */ 7415902bf63c8332946e5a1f48a72e3ae22874b11bMichal Simek#include <asm/mmu.h> 7515902bf63c8332946e5a1f48a72e3ae22874b11bMichal Simek#include <asm/page.h> 7615902bf63c8332946e5a1f48a72e3ae22874b11bMichal Simek 7715902bf63c8332946e5a1f48a72e3ae22874b11bMichal Simek#define FIRST_USER_ADDRESS 0 7815902bf63c8332946e5a1f48a72e3ae22874b11bMichal Simek 7915902bf63c8332946e5a1f48a72e3ae22874b11bMichal Simekextern unsigned long va_to_phys(unsigned long address); 8015902bf63c8332946e5a1f48a72e3ae22874b11bMichal Simekextern pte_t *va_to_pte(unsigned long address); 8115902bf63c8332946e5a1f48a72e3ae22874b11bMichal Simek 8215902bf63c8332946e5a1f48a72e3ae22874b11bMichal Simek/* 8315902bf63c8332946e5a1f48a72e3ae22874b11bMichal Simek * The following only work if pte_present() is true. 8415902bf63c8332946e5a1f48a72e3ae22874b11bMichal Simek * Undefined behaviour if not.. 8515902bf63c8332946e5a1f48a72e3ae22874b11bMichal Simek */ 8615902bf63c8332946e5a1f48a72e3ae22874b11bMichal Simek 8715902bf63c8332946e5a1f48a72e3ae22874b11bMichal Simekstatic inline int pte_special(pte_t pte) { return 0; } 8815902bf63c8332946e5a1f48a72e3ae22874b11bMichal Simek 8915902bf63c8332946e5a1f48a72e3ae22874b11bMichal Simekstatic inline pte_t pte_mkspecial(pte_t pte) { return pte; } 9015902bf63c8332946e5a1f48a72e3ae22874b11bMichal Simek 9115902bf63c8332946e5a1f48a72e3ae22874b11bMichal Simek/* Start and end of the vmalloc area. */ 9215902bf63c8332946e5a1f48a72e3ae22874b11bMichal Simek/* Make sure to map the vmalloc area above the pinned kernel memory area 9315902bf63c8332946e5a1f48a72e3ae22874b11bMichal Simek of 32Mb. */ 9483a92529c1789f86481190743a6bb09f31ec39a8Michal Simek#define VMALLOC_START (CONFIG_KERNEL_START + CONFIG_LOWMEM_SIZE) 9515902bf63c8332946e5a1f48a72e3ae22874b11bMichal Simek#define VMALLOC_END ioremap_bot 9615902bf63c8332946e5a1f48a72e3ae22874b11bMichal Simek 9715902bf63c8332946e5a1f48a72e3ae22874b11bMichal Simek#endif /* __ASSEMBLY__ */ 9815902bf63c8332946e5a1f48a72e3ae22874b11bMichal Simek 9915902bf63c8332946e5a1f48a72e3ae22874b11bMichal Simek/* 100a6475c132278c1be158a13872c233aeab8a00176Michal Simek * Macro to mark a page protection value as "uncacheable". 101a6475c132278c1be158a13872c233aeab8a00176Michal Simek */ 102a6475c132278c1be158a13872c233aeab8a00176Michal Simek 103a6475c132278c1be158a13872c233aeab8a00176Michal Simek#define _PAGE_CACHE_CTL (_PAGE_GUARDED | _PAGE_NO_CACHE | \ 104a6475c132278c1be158a13872c233aeab8a00176Michal Simek _PAGE_WRITETHRU) 105a6475c132278c1be158a13872c233aeab8a00176Michal Simek 106a6475c132278c1be158a13872c233aeab8a00176Michal Simek#define pgprot_noncached(prot) \ 107a6475c132278c1be158a13872c233aeab8a00176Michal Simek (__pgprot((pgprot_val(prot) & ~_PAGE_CACHE_CTL) | \ 108a6475c132278c1be158a13872c233aeab8a00176Michal Simek _PAGE_NO_CACHE | _PAGE_GUARDED)) 109a6475c132278c1be158a13872c233aeab8a00176Michal Simek 110a6475c132278c1be158a13872c233aeab8a00176Michal Simek#define pgprot_noncached_wc(prot) \ 111a6475c132278c1be158a13872c233aeab8a00176Michal Simek (__pgprot((pgprot_val(prot) & ~_PAGE_CACHE_CTL) | \ 112a6475c132278c1be158a13872c233aeab8a00176Michal Simek _PAGE_NO_CACHE)) 113a6475c132278c1be158a13872c233aeab8a00176Michal Simek 114a6475c132278c1be158a13872c233aeab8a00176Michal Simek/* 11515902bf63c8332946e5a1f48a72e3ae22874b11bMichal Simek * The MicroBlaze MMU is identical to the PPC-40x MMU, and uses a hash 11615902bf63c8332946e5a1f48a72e3ae22874b11bMichal Simek * table containing PTEs, together with a set of 16 segment registers, to 11715902bf63c8332946e5a1f48a72e3ae22874b11bMichal Simek * define the virtual to physical address mapping. 11815902bf63c8332946e5a1f48a72e3ae22874b11bMichal Simek * 11915902bf63c8332946e5a1f48a72e3ae22874b11bMichal Simek * We use the hash table as an extended TLB, i.e. a cache of currently 12015902bf63c8332946e5a1f48a72e3ae22874b11bMichal Simek * active mappings. We maintain a two-level page table tree, much 12115902bf63c8332946e5a1f48a72e3ae22874b11bMichal Simek * like that used by the i386, for the sake of the Linux memory 12215902bf63c8332946e5a1f48a72e3ae22874b11bMichal Simek * management code. Low-level assembler code in hashtable.S 12315902bf63c8332946e5a1f48a72e3ae22874b11bMichal Simek * (procedure hash_page) is responsible for extracting ptes from the 12415902bf63c8332946e5a1f48a72e3ae22874b11bMichal Simek * tree and putting them into the hash table when necessary, and 12515902bf63c8332946e5a1f48a72e3ae22874b11bMichal Simek * updating the accessed and modified bits in the page table tree. 12615902bf63c8332946e5a1f48a72e3ae22874b11bMichal Simek */ 12715902bf63c8332946e5a1f48a72e3ae22874b11bMichal Simek 12815902bf63c8332946e5a1f48a72e3ae22874b11bMichal Simek/* 12915902bf63c8332946e5a1f48a72e3ae22874b11bMichal Simek * The MicroBlaze processor has a TLB architecture identical to PPC-40x. The 13015902bf63c8332946e5a1f48a72e3ae22874b11bMichal Simek * instruction and data sides share a unified, 64-entry, semi-associative 13115902bf63c8332946e5a1f48a72e3ae22874b11bMichal Simek * TLB which is maintained totally under software control. In addition, the 13215902bf63c8332946e5a1f48a72e3ae22874b11bMichal Simek * instruction side has a hardware-managed, 2,4, or 8-entry, fully-associative 13315902bf63c8332946e5a1f48a72e3ae22874b11bMichal Simek * TLB which serves as a first level to the shared TLB. These two TLBs are 13415902bf63c8332946e5a1f48a72e3ae22874b11bMichal Simek * known as the UTLB and ITLB, respectively (see "mmu.h" for definitions). 13515902bf63c8332946e5a1f48a72e3ae22874b11bMichal Simek */ 13615902bf63c8332946e5a1f48a72e3ae22874b11bMichal Simek 13715902bf63c8332946e5a1f48a72e3ae22874b11bMichal Simek/* 13815902bf63c8332946e5a1f48a72e3ae22874b11bMichal Simek * The normal case is that PTEs are 32-bits and we have a 1-page 13915902bf63c8332946e5a1f48a72e3ae22874b11bMichal Simek * 1024-entry pgdir pointing to 1-page 1024-entry PTE pages. -- paulus 14015902bf63c8332946e5a1f48a72e3ae22874b11bMichal Simek * 14115902bf63c8332946e5a1f48a72e3ae22874b11bMichal Simek */ 14215902bf63c8332946e5a1f48a72e3ae22874b11bMichal Simek 14315902bf63c8332946e5a1f48a72e3ae22874b11bMichal Simek/* PMD_SHIFT determines the size of the area mapped by the PTE pages */ 14415902bf63c8332946e5a1f48a72e3ae22874b11bMichal Simek#define PMD_SHIFT (PAGE_SHIFT + PTE_SHIFT) 14515902bf63c8332946e5a1f48a72e3ae22874b11bMichal Simek#define PMD_SIZE (1UL << PMD_SHIFT) 14615902bf63c8332946e5a1f48a72e3ae22874b11bMichal Simek#define PMD_MASK (~(PMD_SIZE-1)) 14715902bf63c8332946e5a1f48a72e3ae22874b11bMichal Simek 14815902bf63c8332946e5a1f48a72e3ae22874b11bMichal Simek/* PGDIR_SHIFT determines what a top-level page table entry can map */ 14915902bf63c8332946e5a1f48a72e3ae22874b11bMichal Simek#define PGDIR_SHIFT PMD_SHIFT 15015902bf63c8332946e5a1f48a72e3ae22874b11bMichal Simek#define PGDIR_SIZE (1UL << PGDIR_SHIFT) 15115902bf63c8332946e5a1f48a72e3ae22874b11bMichal Simek#define PGDIR_MASK (~(PGDIR_SIZE-1)) 15215902bf63c8332946e5a1f48a72e3ae22874b11bMichal Simek 15315902bf63c8332946e5a1f48a72e3ae22874b11bMichal Simek/* 15415902bf63c8332946e5a1f48a72e3ae22874b11bMichal Simek * entries per page directory level: our page-table tree is two-level, so 15515902bf63c8332946e5a1f48a72e3ae22874b11bMichal Simek * we don't really have any PMD directory. 15615902bf63c8332946e5a1f48a72e3ae22874b11bMichal Simek */ 15715902bf63c8332946e5a1f48a72e3ae22874b11bMichal Simek#define PTRS_PER_PTE (1 << PTE_SHIFT) 15815902bf63c8332946e5a1f48a72e3ae22874b11bMichal Simek#define PTRS_PER_PMD 1 15915902bf63c8332946e5a1f48a72e3ae22874b11bMichal Simek#define PTRS_PER_PGD (1 << (32 - PGDIR_SHIFT)) 16015902bf63c8332946e5a1f48a72e3ae22874b11bMichal Simek 16115902bf63c8332946e5a1f48a72e3ae22874b11bMichal Simek#define USER_PTRS_PER_PGD (TASK_SIZE / PGDIR_SIZE) 16215902bf63c8332946e5a1f48a72e3ae22874b11bMichal Simek#define FIRST_USER_PGD_NR 0 16315902bf63c8332946e5a1f48a72e3ae22874b11bMichal Simek 16415902bf63c8332946e5a1f48a72e3ae22874b11bMichal Simek#define USER_PGD_PTRS (PAGE_OFFSET >> PGDIR_SHIFT) 16515902bf63c8332946e5a1f48a72e3ae22874b11bMichal Simek#define KERNEL_PGD_PTRS (PTRS_PER_PGD-USER_PGD_PTRS) 16615902bf63c8332946e5a1f48a72e3ae22874b11bMichal Simek 16715902bf63c8332946e5a1f48a72e3ae22874b11bMichal Simek#define pte_ERROR(e) \ 16815902bf63c8332946e5a1f48a72e3ae22874b11bMichal Simek printk(KERN_ERR "%s:%d: bad pte "PTE_FMT".\n", \ 16915902bf63c8332946e5a1f48a72e3ae22874b11bMichal Simek __FILE__, __LINE__, pte_val(e)) 17015902bf63c8332946e5a1f48a72e3ae22874b11bMichal Simek#define pmd_ERROR(e) \ 17115902bf63c8332946e5a1f48a72e3ae22874b11bMichal Simek printk(KERN_ERR "%s:%d: bad pmd %08lx.\n", \ 17215902bf63c8332946e5a1f48a72e3ae22874b11bMichal Simek __FILE__, __LINE__, pmd_val(e)) 17315902bf63c8332946e5a1f48a72e3ae22874b11bMichal Simek#define pgd_ERROR(e) \ 17415902bf63c8332946e5a1f48a72e3ae22874b11bMichal Simek printk(KERN_ERR "%s:%d: bad pgd %08lx.\n", \ 17515902bf63c8332946e5a1f48a72e3ae22874b11bMichal Simek __FILE__, __LINE__, pgd_val(e)) 17615902bf63c8332946e5a1f48a72e3ae22874b11bMichal Simek 17715902bf63c8332946e5a1f48a72e3ae22874b11bMichal Simek/* 17815902bf63c8332946e5a1f48a72e3ae22874b11bMichal Simek * Bits in a linux-style PTE. These match the bits in the 17915902bf63c8332946e5a1f48a72e3ae22874b11bMichal Simek * (hardware-defined) PTE as closely as possible. 18015902bf63c8332946e5a1f48a72e3ae22874b11bMichal Simek */ 18115902bf63c8332946e5a1f48a72e3ae22874b11bMichal Simek 18215902bf63c8332946e5a1f48a72e3ae22874b11bMichal Simek/* There are several potential gotchas here. The hardware TLBLO 18315902bf63c8332946e5a1f48a72e3ae22874b11bMichal Simek * field looks like this: 18415902bf63c8332946e5a1f48a72e3ae22874b11bMichal Simek * 18515902bf63c8332946e5a1f48a72e3ae22874b11bMichal Simek * 0 1 2 3 4 ... 18 19 20 21 22 23 24 25 26 27 28 29 30 31 18615902bf63c8332946e5a1f48a72e3ae22874b11bMichal Simek * RPN..................... 0 0 EX WR ZSEL....... W I M G 18715902bf63c8332946e5a1f48a72e3ae22874b11bMichal Simek * 18815902bf63c8332946e5a1f48a72e3ae22874b11bMichal Simek * Where possible we make the Linux PTE bits match up with this 18915902bf63c8332946e5a1f48a72e3ae22874b11bMichal Simek * 19015902bf63c8332946e5a1f48a72e3ae22874b11bMichal Simek * - bits 20 and 21 must be cleared, because we use 4k pages (4xx can 19115902bf63c8332946e5a1f48a72e3ae22874b11bMichal Simek * support down to 1k pages), this is done in the TLBMiss exception 19215902bf63c8332946e5a1f48a72e3ae22874b11bMichal Simek * handler. 19315902bf63c8332946e5a1f48a72e3ae22874b11bMichal Simek * - We use only zones 0 (for kernel pages) and 1 (for user pages) 19415902bf63c8332946e5a1f48a72e3ae22874b11bMichal Simek * of the 16 available. Bit 24-26 of the TLB are cleared in the TLB 19515902bf63c8332946e5a1f48a72e3ae22874b11bMichal Simek * miss handler. Bit 27 is PAGE_USER, thus selecting the correct 19615902bf63c8332946e5a1f48a72e3ae22874b11bMichal Simek * zone. 19715902bf63c8332946e5a1f48a72e3ae22874b11bMichal Simek * - PRESENT *must* be in the bottom two bits because swap cache 19815902bf63c8332946e5a1f48a72e3ae22874b11bMichal Simek * entries use the top 30 bits. Because 4xx doesn't support SMP 19915902bf63c8332946e5a1f48a72e3ae22874b11bMichal Simek * anyway, M is irrelevant so we borrow it for PAGE_PRESENT. Bit 30 20015902bf63c8332946e5a1f48a72e3ae22874b11bMichal Simek * is cleared in the TLB miss handler before the TLB entry is loaded. 20115902bf63c8332946e5a1f48a72e3ae22874b11bMichal Simek * - All other bits of the PTE are loaded into TLBLO without 20215902bf63c8332946e5a1f48a72e3ae22874b11bMichal Simek * * modification, leaving us only the bits 20, 21, 24, 25, 26, 30 for 20315902bf63c8332946e5a1f48a72e3ae22874b11bMichal Simek * software PTE bits. We actually use use bits 21, 24, 25, and 20415902bf63c8332946e5a1f48a72e3ae22874b11bMichal Simek * 30 respectively for the software bits: ACCESSED, DIRTY, RW, and 20515902bf63c8332946e5a1f48a72e3ae22874b11bMichal Simek * PRESENT. 20615902bf63c8332946e5a1f48a72e3ae22874b11bMichal Simek */ 20715902bf63c8332946e5a1f48a72e3ae22874b11bMichal Simek 20815902bf63c8332946e5a1f48a72e3ae22874b11bMichal Simek/* Definitions for MicroBlaze. */ 20915902bf63c8332946e5a1f48a72e3ae22874b11bMichal Simek#define _PAGE_GUARDED 0x001 /* G: page is guarded from prefetch */ 210f14d6f7c31c73a902a6b567dc719128e74603902Michal Simek#define _PAGE_FILE 0x001 /* when !present: nonlinear file mapping */ 21115902bf63c8332946e5a1f48a72e3ae22874b11bMichal Simek#define _PAGE_PRESENT 0x002 /* software: PTE contains a translation */ 21215902bf63c8332946e5a1f48a72e3ae22874b11bMichal Simek#define _PAGE_NO_CACHE 0x004 /* I: caching is inhibited */ 21315902bf63c8332946e5a1f48a72e3ae22874b11bMichal Simek#define _PAGE_WRITETHRU 0x008 /* W: caching is write-through */ 21415902bf63c8332946e5a1f48a72e3ae22874b11bMichal Simek#define _PAGE_USER 0x010 /* matches one of the zone permission bits */ 21515902bf63c8332946e5a1f48a72e3ae22874b11bMichal Simek#define _PAGE_RW 0x040 /* software: Writes permitted */ 21615902bf63c8332946e5a1f48a72e3ae22874b11bMichal Simek#define _PAGE_DIRTY 0x080 /* software: dirty page */ 21715902bf63c8332946e5a1f48a72e3ae22874b11bMichal Simek#define _PAGE_HWWRITE 0x100 /* hardware: Dirty & RW, set in exception */ 21815902bf63c8332946e5a1f48a72e3ae22874b11bMichal Simek#define _PAGE_HWEXEC 0x200 /* hardware: EX permission */ 21915902bf63c8332946e5a1f48a72e3ae22874b11bMichal Simek#define _PAGE_ACCESSED 0x400 /* software: R: page referenced */ 22015902bf63c8332946e5a1f48a72e3ae22874b11bMichal Simek#define _PMD_PRESENT PAGE_MASK 22115902bf63c8332946e5a1f48a72e3ae22874b11bMichal Simek 22215902bf63c8332946e5a1f48a72e3ae22874b11bMichal Simek/* 22315902bf63c8332946e5a1f48a72e3ae22874b11bMichal Simek * Some bits are unused... 22415902bf63c8332946e5a1f48a72e3ae22874b11bMichal Simek */ 22515902bf63c8332946e5a1f48a72e3ae22874b11bMichal Simek#ifndef _PAGE_HASHPTE 22615902bf63c8332946e5a1f48a72e3ae22874b11bMichal Simek#define _PAGE_HASHPTE 0 22715902bf63c8332946e5a1f48a72e3ae22874b11bMichal Simek#endif 22815902bf63c8332946e5a1f48a72e3ae22874b11bMichal Simek#ifndef _PTE_NONE_MASK 22915902bf63c8332946e5a1f48a72e3ae22874b11bMichal Simek#define _PTE_NONE_MASK 0 23015902bf63c8332946e5a1f48a72e3ae22874b11bMichal Simek#endif 23115902bf63c8332946e5a1f48a72e3ae22874b11bMichal Simek#ifndef _PAGE_SHARED 23215902bf63c8332946e5a1f48a72e3ae22874b11bMichal Simek#define _PAGE_SHARED 0 23315902bf63c8332946e5a1f48a72e3ae22874b11bMichal Simek#endif 23415902bf63c8332946e5a1f48a72e3ae22874b11bMichal Simek#ifndef _PAGE_EXEC 23515902bf63c8332946e5a1f48a72e3ae22874b11bMichal Simek#define _PAGE_EXEC 0 23615902bf63c8332946e5a1f48a72e3ae22874b11bMichal Simek#endif 23715902bf63c8332946e5a1f48a72e3ae22874b11bMichal Simek 23815902bf63c8332946e5a1f48a72e3ae22874b11bMichal Simek#define _PAGE_CHG_MASK (PAGE_MASK | _PAGE_ACCESSED | _PAGE_DIRTY) 23915902bf63c8332946e5a1f48a72e3ae22874b11bMichal Simek 24015902bf63c8332946e5a1f48a72e3ae22874b11bMichal Simek/* 24115902bf63c8332946e5a1f48a72e3ae22874b11bMichal Simek * Note: the _PAGE_COHERENT bit automatically gets set in the hardware 24215902bf63c8332946e5a1f48a72e3ae22874b11bMichal Simek * PTE if CONFIG_SMP is defined (hash_page does this); there is no need 24315902bf63c8332946e5a1f48a72e3ae22874b11bMichal Simek * to have it in the Linux PTE, and in fact the bit could be reused for 24415902bf63c8332946e5a1f48a72e3ae22874b11bMichal Simek * another purpose. -- paulus. 24515902bf63c8332946e5a1f48a72e3ae22874b11bMichal Simek */ 24615902bf63c8332946e5a1f48a72e3ae22874b11bMichal Simek#define _PAGE_BASE (_PAGE_PRESENT | _PAGE_ACCESSED) 24715902bf63c8332946e5a1f48a72e3ae22874b11bMichal Simek#define _PAGE_WRENABLE (_PAGE_RW | _PAGE_DIRTY | _PAGE_HWWRITE) 24815902bf63c8332946e5a1f48a72e3ae22874b11bMichal Simek 24915902bf63c8332946e5a1f48a72e3ae22874b11bMichal Simek#define _PAGE_KERNEL \ 25015902bf63c8332946e5a1f48a72e3ae22874b11bMichal Simek (_PAGE_BASE | _PAGE_WRENABLE | _PAGE_SHARED | _PAGE_HWEXEC) 25115902bf63c8332946e5a1f48a72e3ae22874b11bMichal Simek 25215902bf63c8332946e5a1f48a72e3ae22874b11bMichal Simek#define _PAGE_IO (_PAGE_KERNEL | _PAGE_NO_CACHE | _PAGE_GUARDED) 25315902bf63c8332946e5a1f48a72e3ae22874b11bMichal Simek 25415902bf63c8332946e5a1f48a72e3ae22874b11bMichal Simek#define PAGE_NONE __pgprot(_PAGE_BASE) 25515902bf63c8332946e5a1f48a72e3ae22874b11bMichal Simek#define PAGE_READONLY __pgprot(_PAGE_BASE | _PAGE_USER) 25615902bf63c8332946e5a1f48a72e3ae22874b11bMichal Simek#define PAGE_READONLY_X __pgprot(_PAGE_BASE | _PAGE_USER | _PAGE_EXEC) 25715902bf63c8332946e5a1f48a72e3ae22874b11bMichal Simek#define PAGE_SHARED __pgprot(_PAGE_BASE | _PAGE_USER | _PAGE_RW) 25815902bf63c8332946e5a1f48a72e3ae22874b11bMichal Simek#define PAGE_SHARED_X \ 25915902bf63c8332946e5a1f48a72e3ae22874b11bMichal Simek __pgprot(_PAGE_BASE | _PAGE_USER | _PAGE_RW | _PAGE_EXEC) 26015902bf63c8332946e5a1f48a72e3ae22874b11bMichal Simek#define PAGE_COPY __pgprot(_PAGE_BASE | _PAGE_USER) 26115902bf63c8332946e5a1f48a72e3ae22874b11bMichal Simek#define PAGE_COPY_X __pgprot(_PAGE_BASE | _PAGE_USER | _PAGE_EXEC) 26215902bf63c8332946e5a1f48a72e3ae22874b11bMichal Simek 26315902bf63c8332946e5a1f48a72e3ae22874b11bMichal Simek#define PAGE_KERNEL __pgprot(_PAGE_KERNEL) 26415902bf63c8332946e5a1f48a72e3ae22874b11bMichal Simek#define PAGE_KERNEL_RO __pgprot(_PAGE_BASE | _PAGE_SHARED) 26515902bf63c8332946e5a1f48a72e3ae22874b11bMichal Simek#define PAGE_KERNEL_CI __pgprot(_PAGE_IO) 26615902bf63c8332946e5a1f48a72e3ae22874b11bMichal Simek 26715902bf63c8332946e5a1f48a72e3ae22874b11bMichal Simek/* 26815902bf63c8332946e5a1f48a72e3ae22874b11bMichal Simek * We consider execute permission the same as read. 26915902bf63c8332946e5a1f48a72e3ae22874b11bMichal Simek * Also, write permissions imply read permissions. 27015902bf63c8332946e5a1f48a72e3ae22874b11bMichal Simek */ 27115902bf63c8332946e5a1f48a72e3ae22874b11bMichal Simek#define __P000 PAGE_NONE 27215902bf63c8332946e5a1f48a72e3ae22874b11bMichal Simek#define __P001 PAGE_READONLY_X 27315902bf63c8332946e5a1f48a72e3ae22874b11bMichal Simek#define __P010 PAGE_COPY 27415902bf63c8332946e5a1f48a72e3ae22874b11bMichal Simek#define __P011 PAGE_COPY_X 27515902bf63c8332946e5a1f48a72e3ae22874b11bMichal Simek#define __P100 PAGE_READONLY 27615902bf63c8332946e5a1f48a72e3ae22874b11bMichal Simek#define __P101 PAGE_READONLY_X 27715902bf63c8332946e5a1f48a72e3ae22874b11bMichal Simek#define __P110 PAGE_COPY 27815902bf63c8332946e5a1f48a72e3ae22874b11bMichal Simek#define __P111 PAGE_COPY_X 27915902bf63c8332946e5a1f48a72e3ae22874b11bMichal Simek 28015902bf63c8332946e5a1f48a72e3ae22874b11bMichal Simek#define __S000 PAGE_NONE 28115902bf63c8332946e5a1f48a72e3ae22874b11bMichal Simek#define __S001 PAGE_READONLY_X 28215902bf63c8332946e5a1f48a72e3ae22874b11bMichal Simek#define __S010 PAGE_SHARED 28315902bf63c8332946e5a1f48a72e3ae22874b11bMichal Simek#define __S011 PAGE_SHARED_X 28415902bf63c8332946e5a1f48a72e3ae22874b11bMichal Simek#define __S100 PAGE_READONLY 28515902bf63c8332946e5a1f48a72e3ae22874b11bMichal Simek#define __S101 PAGE_READONLY_X 28615902bf63c8332946e5a1f48a72e3ae22874b11bMichal Simek#define __S110 PAGE_SHARED 28715902bf63c8332946e5a1f48a72e3ae22874b11bMichal Simek#define __S111 PAGE_SHARED_X 28815902bf63c8332946e5a1f48a72e3ae22874b11bMichal Simek 28915902bf63c8332946e5a1f48a72e3ae22874b11bMichal Simek#ifndef __ASSEMBLY__ 29015902bf63c8332946e5a1f48a72e3ae22874b11bMichal Simek/* 29115902bf63c8332946e5a1f48a72e3ae22874b11bMichal Simek * ZERO_PAGE is a global shared page that is always zero: used 29215902bf63c8332946e5a1f48a72e3ae22874b11bMichal Simek * for zero-mapped memory areas etc.. 29315902bf63c8332946e5a1f48a72e3ae22874b11bMichal Simek */ 29415902bf63c8332946e5a1f48a72e3ae22874b11bMichal Simekextern unsigned long empty_zero_page[1024]; 29515902bf63c8332946e5a1f48a72e3ae22874b11bMichal Simek#define ZERO_PAGE(vaddr) (virt_to_page(empty_zero_page)) 29615902bf63c8332946e5a1f48a72e3ae22874b11bMichal Simek 29715902bf63c8332946e5a1f48a72e3ae22874b11bMichal Simek#endif /* __ASSEMBLY__ */ 29815902bf63c8332946e5a1f48a72e3ae22874b11bMichal Simek 29915902bf63c8332946e5a1f48a72e3ae22874b11bMichal Simek#define pte_none(pte) ((pte_val(pte) & ~_PTE_NONE_MASK) == 0) 30015902bf63c8332946e5a1f48a72e3ae22874b11bMichal Simek#define pte_present(pte) (pte_val(pte) & _PAGE_PRESENT) 30115902bf63c8332946e5a1f48a72e3ae22874b11bMichal Simek#define pte_clear(mm, addr, ptep) \ 30215902bf63c8332946e5a1f48a72e3ae22874b11bMichal Simek do { set_pte_at((mm), (addr), (ptep), __pte(0)); } while (0) 30315902bf63c8332946e5a1f48a72e3ae22874b11bMichal Simek 30415902bf63c8332946e5a1f48a72e3ae22874b11bMichal Simek#define pmd_none(pmd) (!pmd_val(pmd)) 30515902bf63c8332946e5a1f48a72e3ae22874b11bMichal Simek#define pmd_bad(pmd) ((pmd_val(pmd) & _PMD_PRESENT) == 0) 30615902bf63c8332946e5a1f48a72e3ae22874b11bMichal Simek#define pmd_present(pmd) ((pmd_val(pmd) & _PMD_PRESENT) != 0) 30715902bf63c8332946e5a1f48a72e3ae22874b11bMichal Simek#define pmd_clear(pmdp) do { pmd_val(*(pmdp)) = 0; } while (0) 30815902bf63c8332946e5a1f48a72e3ae22874b11bMichal Simek 30915902bf63c8332946e5a1f48a72e3ae22874b11bMichal Simek#define pte_page(x) (mem_map + (unsigned long) \ 31015902bf63c8332946e5a1f48a72e3ae22874b11bMichal Simek ((pte_val(x) - memory_start) >> PAGE_SHIFT)) 31115902bf63c8332946e5a1f48a72e3ae22874b11bMichal Simek#define PFN_SHIFT_OFFSET (PAGE_SHIFT) 31215902bf63c8332946e5a1f48a72e3ae22874b11bMichal Simek 31315902bf63c8332946e5a1f48a72e3ae22874b11bMichal Simek#define pte_pfn(x) (pte_val(x) >> PFN_SHIFT_OFFSET) 31415902bf63c8332946e5a1f48a72e3ae22874b11bMichal Simek 31515902bf63c8332946e5a1f48a72e3ae22874b11bMichal Simek#define pfn_pte(pfn, prot) \ 31615902bf63c8332946e5a1f48a72e3ae22874b11bMichal Simek __pte(((pte_basic_t)(pfn) << PFN_SHIFT_OFFSET) | pgprot_val(prot)) 31715902bf63c8332946e5a1f48a72e3ae22874b11bMichal Simek 31815902bf63c8332946e5a1f48a72e3ae22874b11bMichal Simek#ifndef __ASSEMBLY__ 31915902bf63c8332946e5a1f48a72e3ae22874b11bMichal Simek/* 32015902bf63c8332946e5a1f48a72e3ae22874b11bMichal Simek * The "pgd_xxx()" functions here are trivial for a folded two-level 32115902bf63c8332946e5a1f48a72e3ae22874b11bMichal Simek * setup: the pgd is never bad, and a pmd always exists (as it's folded 32215902bf63c8332946e5a1f48a72e3ae22874b11bMichal Simek * into the pgd entry) 32315902bf63c8332946e5a1f48a72e3ae22874b11bMichal Simek */ 32415902bf63c8332946e5a1f48a72e3ae22874b11bMichal Simekstatic inline int pgd_none(pgd_t pgd) { return 0; } 32515902bf63c8332946e5a1f48a72e3ae22874b11bMichal Simekstatic inline int pgd_bad(pgd_t pgd) { return 0; } 32615902bf63c8332946e5a1f48a72e3ae22874b11bMichal Simekstatic inline int pgd_present(pgd_t pgd) { return 1; } 32715902bf63c8332946e5a1f48a72e3ae22874b11bMichal Simek#define pgd_clear(xp) do { } while (0) 32815902bf63c8332946e5a1f48a72e3ae22874b11bMichal Simek#define pgd_page(pgd) \ 32915902bf63c8332946e5a1f48a72e3ae22874b11bMichal Simek ((unsigned long) __va(pgd_val(pgd) & PAGE_MASK)) 33015902bf63c8332946e5a1f48a72e3ae22874b11bMichal Simek 33115902bf63c8332946e5a1f48a72e3ae22874b11bMichal Simek/* 33215902bf63c8332946e5a1f48a72e3ae22874b11bMichal Simek * The following only work if pte_present() is true. 33315902bf63c8332946e5a1f48a72e3ae22874b11bMichal Simek * Undefined behaviour if not.. 33415902bf63c8332946e5a1f48a72e3ae22874b11bMichal Simek */ 33515902bf63c8332946e5a1f48a72e3ae22874b11bMichal Simekstatic inline int pte_read(pte_t pte) { return pte_val(pte) & _PAGE_USER; } 33615902bf63c8332946e5a1f48a72e3ae22874b11bMichal Simekstatic inline int pte_write(pte_t pte) { return pte_val(pte) & _PAGE_RW; } 33715902bf63c8332946e5a1f48a72e3ae22874b11bMichal Simekstatic inline int pte_exec(pte_t pte) { return pte_val(pte) & _PAGE_EXEC; } 33815902bf63c8332946e5a1f48a72e3ae22874b11bMichal Simekstatic inline int pte_dirty(pte_t pte) { return pte_val(pte) & _PAGE_DIRTY; } 33915902bf63c8332946e5a1f48a72e3ae22874b11bMichal Simekstatic inline int pte_young(pte_t pte) { return pte_val(pte) & _PAGE_ACCESSED; } 340f14d6f7c31c73a902a6b567dc719128e74603902Michal Simekstatic inline int pte_file(pte_t pte) { return pte_val(pte) & _PAGE_FILE; } 34115902bf63c8332946e5a1f48a72e3ae22874b11bMichal Simek 34215902bf63c8332946e5a1f48a72e3ae22874b11bMichal Simekstatic inline void pte_uncache(pte_t pte) { pte_val(pte) |= _PAGE_NO_CACHE; } 34315902bf63c8332946e5a1f48a72e3ae22874b11bMichal Simekstatic inline void pte_cache(pte_t pte) { pte_val(pte) &= ~_PAGE_NO_CACHE; } 34415902bf63c8332946e5a1f48a72e3ae22874b11bMichal Simek 34515902bf63c8332946e5a1f48a72e3ae22874b11bMichal Simekstatic inline pte_t pte_rdprotect(pte_t pte) \ 34615902bf63c8332946e5a1f48a72e3ae22874b11bMichal Simek { pte_val(pte) &= ~_PAGE_USER; return pte; } 34715902bf63c8332946e5a1f48a72e3ae22874b11bMichal Simekstatic inline pte_t pte_wrprotect(pte_t pte) \ 34815902bf63c8332946e5a1f48a72e3ae22874b11bMichal Simek { pte_val(pte) &= ~(_PAGE_RW | _PAGE_HWWRITE); return pte; } 34915902bf63c8332946e5a1f48a72e3ae22874b11bMichal Simekstatic inline pte_t pte_exprotect(pte_t pte) \ 35015902bf63c8332946e5a1f48a72e3ae22874b11bMichal Simek { pte_val(pte) &= ~_PAGE_EXEC; return pte; } 35115902bf63c8332946e5a1f48a72e3ae22874b11bMichal Simekstatic inline pte_t pte_mkclean(pte_t pte) \ 35215902bf63c8332946e5a1f48a72e3ae22874b11bMichal Simek { pte_val(pte) &= ~(_PAGE_DIRTY | _PAGE_HWWRITE); return pte; } 35315902bf63c8332946e5a1f48a72e3ae22874b11bMichal Simekstatic inline pte_t pte_mkold(pte_t pte) \ 35415902bf63c8332946e5a1f48a72e3ae22874b11bMichal Simek { pte_val(pte) &= ~_PAGE_ACCESSED; return pte; } 35515902bf63c8332946e5a1f48a72e3ae22874b11bMichal Simek 35615902bf63c8332946e5a1f48a72e3ae22874b11bMichal Simekstatic inline pte_t pte_mkread(pte_t pte) \ 35715902bf63c8332946e5a1f48a72e3ae22874b11bMichal Simek { pte_val(pte) |= _PAGE_USER; return pte; } 35815902bf63c8332946e5a1f48a72e3ae22874b11bMichal Simekstatic inline pte_t pte_mkexec(pte_t pte) \ 35915902bf63c8332946e5a1f48a72e3ae22874b11bMichal Simek { pte_val(pte) |= _PAGE_USER | _PAGE_EXEC; return pte; } 36015902bf63c8332946e5a1f48a72e3ae22874b11bMichal Simekstatic inline pte_t pte_mkwrite(pte_t pte) \ 36115902bf63c8332946e5a1f48a72e3ae22874b11bMichal Simek { pte_val(pte) |= _PAGE_RW; return pte; } 36215902bf63c8332946e5a1f48a72e3ae22874b11bMichal Simekstatic inline pte_t pte_mkdirty(pte_t pte) \ 36315902bf63c8332946e5a1f48a72e3ae22874b11bMichal Simek { pte_val(pte) |= _PAGE_DIRTY; return pte; } 36415902bf63c8332946e5a1f48a72e3ae22874b11bMichal Simekstatic inline pte_t pte_mkyoung(pte_t pte) \ 36515902bf63c8332946e5a1f48a72e3ae22874b11bMichal Simek { pte_val(pte) |= _PAGE_ACCESSED; return pte; } 36615902bf63c8332946e5a1f48a72e3ae22874b11bMichal Simek 36715902bf63c8332946e5a1f48a72e3ae22874b11bMichal Simek/* 36815902bf63c8332946e5a1f48a72e3ae22874b11bMichal Simek * Conversion functions: convert a page and protection to a page entry, 36915902bf63c8332946e5a1f48a72e3ae22874b11bMichal Simek * and a page entry and page directory to the page they refer to. 37015902bf63c8332946e5a1f48a72e3ae22874b11bMichal Simek */ 37115902bf63c8332946e5a1f48a72e3ae22874b11bMichal Simek 37215902bf63c8332946e5a1f48a72e3ae22874b11bMichal Simekstatic inline pte_t mk_pte_phys(phys_addr_t physpage, pgprot_t pgprot) 37315902bf63c8332946e5a1f48a72e3ae22874b11bMichal Simek{ 37415902bf63c8332946e5a1f48a72e3ae22874b11bMichal Simek pte_t pte; 37515902bf63c8332946e5a1f48a72e3ae22874b11bMichal Simek pte_val(pte) = physpage | pgprot_val(pgprot); 37615902bf63c8332946e5a1f48a72e3ae22874b11bMichal Simek return pte; 37715902bf63c8332946e5a1f48a72e3ae22874b11bMichal Simek} 37815902bf63c8332946e5a1f48a72e3ae22874b11bMichal Simek 37915902bf63c8332946e5a1f48a72e3ae22874b11bMichal Simek#define mk_pte(page, pgprot) \ 38015902bf63c8332946e5a1f48a72e3ae22874b11bMichal Simek({ \ 38115902bf63c8332946e5a1f48a72e3ae22874b11bMichal Simek pte_t pte; \ 38215902bf63c8332946e5a1f48a72e3ae22874b11bMichal Simek pte_val(pte) = (((page - mem_map) << PAGE_SHIFT) + memory_start) | \ 38315902bf63c8332946e5a1f48a72e3ae22874b11bMichal Simek pgprot_val(pgprot); \ 38415902bf63c8332946e5a1f48a72e3ae22874b11bMichal Simek pte; \ 38515902bf63c8332946e5a1f48a72e3ae22874b11bMichal Simek}) 38615902bf63c8332946e5a1f48a72e3ae22874b11bMichal Simek 38715902bf63c8332946e5a1f48a72e3ae22874b11bMichal Simekstatic inline pte_t pte_modify(pte_t pte, pgprot_t newprot) 38815902bf63c8332946e5a1f48a72e3ae22874b11bMichal Simek{ 38915902bf63c8332946e5a1f48a72e3ae22874b11bMichal Simek pte_val(pte) = (pte_val(pte) & _PAGE_CHG_MASK) | pgprot_val(newprot); 39015902bf63c8332946e5a1f48a72e3ae22874b11bMichal Simek return pte; 39115902bf63c8332946e5a1f48a72e3ae22874b11bMichal Simek} 39215902bf63c8332946e5a1f48a72e3ae22874b11bMichal Simek 39315902bf63c8332946e5a1f48a72e3ae22874b11bMichal Simek/* 39415902bf63c8332946e5a1f48a72e3ae22874b11bMichal Simek * Atomic PTE updates. 39515902bf63c8332946e5a1f48a72e3ae22874b11bMichal Simek * 39615902bf63c8332946e5a1f48a72e3ae22874b11bMichal Simek * pte_update clears and sets bit atomically, and returns 39715902bf63c8332946e5a1f48a72e3ae22874b11bMichal Simek * the old pte value. 39815902bf63c8332946e5a1f48a72e3ae22874b11bMichal Simek * The ((unsigned long)(p+1) - 4) hack is to get to the least-significant 39915902bf63c8332946e5a1f48a72e3ae22874b11bMichal Simek * 32 bits of the PTE regardless of whether PTEs are 32 or 64 bits. 40015902bf63c8332946e5a1f48a72e3ae22874b11bMichal Simek */ 40115902bf63c8332946e5a1f48a72e3ae22874b11bMichal Simekstatic inline unsigned long pte_update(pte_t *p, unsigned long clr, 40215902bf63c8332946e5a1f48a72e3ae22874b11bMichal Simek unsigned long set) 40315902bf63c8332946e5a1f48a72e3ae22874b11bMichal Simek{ 4041f80a67da2da4180355bc36b2691f16684b194fdMichal Simek unsigned long flags, old, tmp; 4051f80a67da2da4180355bc36b2691f16684b194fdMichal Simek 4061f80a67da2da4180355bc36b2691f16684b194fdMichal Simek raw_local_irq_save(flags); 4071f80a67da2da4180355bc36b2691f16684b194fdMichal Simek 4081f80a67da2da4180355bc36b2691f16684b194fdMichal Simek __asm__ __volatile__( "lw %0, %2, r0 \n" 4091f80a67da2da4180355bc36b2691f16684b194fdMichal Simek "andn %1, %0, %3 \n" 4101f80a67da2da4180355bc36b2691f16684b194fdMichal Simek "or %1, %1, %4 \n" 4111f80a67da2da4180355bc36b2691f16684b194fdMichal Simek "sw %1, %2, r0 \n" 4121f80a67da2da4180355bc36b2691f16684b194fdMichal Simek : "=&r" (old), "=&r" (tmp) 4131f80a67da2da4180355bc36b2691f16684b194fdMichal Simek : "r" ((unsigned long)(p + 1) - 4), "r" (clr), "r" (set) 4141f80a67da2da4180355bc36b2691f16684b194fdMichal Simek : "cc"); 4151f80a67da2da4180355bc36b2691f16684b194fdMichal Simek 4161f80a67da2da4180355bc36b2691f16684b194fdMichal Simek raw_local_irq_restore(flags); 41715902bf63c8332946e5a1f48a72e3ae22874b11bMichal Simek 41815902bf63c8332946e5a1f48a72e3ae22874b11bMichal Simek return old; 41915902bf63c8332946e5a1f48a72e3ae22874b11bMichal Simek} 42015902bf63c8332946e5a1f48a72e3ae22874b11bMichal Simek 42115902bf63c8332946e5a1f48a72e3ae22874b11bMichal Simek/* 42215902bf63c8332946e5a1f48a72e3ae22874b11bMichal Simek * set_pte stores a linux PTE into the linux page table. 42315902bf63c8332946e5a1f48a72e3ae22874b11bMichal Simek */ 42415902bf63c8332946e5a1f48a72e3ae22874b11bMichal Simekstatic inline void set_pte(struct mm_struct *mm, unsigned long addr, 42515902bf63c8332946e5a1f48a72e3ae22874b11bMichal Simek pte_t *ptep, pte_t pte) 42615902bf63c8332946e5a1f48a72e3ae22874b11bMichal Simek{ 42715902bf63c8332946e5a1f48a72e3ae22874b11bMichal Simek *ptep = pte; 42815902bf63c8332946e5a1f48a72e3ae22874b11bMichal Simek} 42915902bf63c8332946e5a1f48a72e3ae22874b11bMichal Simek 43015902bf63c8332946e5a1f48a72e3ae22874b11bMichal Simekstatic inline void set_pte_at(struct mm_struct *mm, unsigned long addr, 43115902bf63c8332946e5a1f48a72e3ae22874b11bMichal Simek pte_t *ptep, pte_t pte) 43215902bf63c8332946e5a1f48a72e3ae22874b11bMichal Simek{ 43315902bf63c8332946e5a1f48a72e3ae22874b11bMichal Simek *ptep = pte; 43415902bf63c8332946e5a1f48a72e3ae22874b11bMichal Simek} 43515902bf63c8332946e5a1f48a72e3ae22874b11bMichal Simek 436658b368da198a1436c7d6a0f1f4029d3c6e30b20Michal Simek#define __HAVE_ARCH_PTEP_TEST_AND_CLEAR_YOUNG 437658b368da198a1436c7d6a0f1f4029d3c6e30b20Michal Simekstatic inline int ptep_test_and_clear_young(struct vm_area_struct *vma, 438658b368da198a1436c7d6a0f1f4029d3c6e30b20Michal Simek unsigned long address, pte_t *ptep) 43915902bf63c8332946e5a1f48a72e3ae22874b11bMichal Simek{ 44015902bf63c8332946e5a1f48a72e3ae22874b11bMichal Simek return (pte_update(ptep, _PAGE_ACCESSED, 0) & _PAGE_ACCESSED) != 0; 44115902bf63c8332946e5a1f48a72e3ae22874b11bMichal Simek} 44215902bf63c8332946e5a1f48a72e3ae22874b11bMichal Simek 44315902bf63c8332946e5a1f48a72e3ae22874b11bMichal Simekstatic inline int ptep_test_and_clear_dirty(struct mm_struct *mm, 44415902bf63c8332946e5a1f48a72e3ae22874b11bMichal Simek unsigned long addr, pte_t *ptep) 44515902bf63c8332946e5a1f48a72e3ae22874b11bMichal Simek{ 44615902bf63c8332946e5a1f48a72e3ae22874b11bMichal Simek return (pte_update(ptep, \ 44715902bf63c8332946e5a1f48a72e3ae22874b11bMichal Simek (_PAGE_DIRTY | _PAGE_HWWRITE), 0) & _PAGE_DIRTY) != 0; 44815902bf63c8332946e5a1f48a72e3ae22874b11bMichal Simek} 44915902bf63c8332946e5a1f48a72e3ae22874b11bMichal Simek 450658b368da198a1436c7d6a0f1f4029d3c6e30b20Michal Simek#define __HAVE_ARCH_PTEP_GET_AND_CLEAR 45115902bf63c8332946e5a1f48a72e3ae22874b11bMichal Simekstatic inline pte_t ptep_get_and_clear(struct mm_struct *mm, 45215902bf63c8332946e5a1f48a72e3ae22874b11bMichal Simek unsigned long addr, pte_t *ptep) 45315902bf63c8332946e5a1f48a72e3ae22874b11bMichal Simek{ 45415902bf63c8332946e5a1f48a72e3ae22874b11bMichal Simek return __pte(pte_update(ptep, ~_PAGE_HASHPTE, 0)); 45515902bf63c8332946e5a1f48a72e3ae22874b11bMichal Simek} 45615902bf63c8332946e5a1f48a72e3ae22874b11bMichal Simek 45715902bf63c8332946e5a1f48a72e3ae22874b11bMichal Simek/*static inline void ptep_set_wrprotect(struct mm_struct *mm, 45815902bf63c8332946e5a1f48a72e3ae22874b11bMichal Simek unsigned long addr, pte_t *ptep) 45915902bf63c8332946e5a1f48a72e3ae22874b11bMichal Simek{ 46015902bf63c8332946e5a1f48a72e3ae22874b11bMichal Simek pte_update(ptep, (_PAGE_RW | _PAGE_HWWRITE), 0); 46115902bf63c8332946e5a1f48a72e3ae22874b11bMichal Simek}*/ 46215902bf63c8332946e5a1f48a72e3ae22874b11bMichal Simek 46315902bf63c8332946e5a1f48a72e3ae22874b11bMichal Simekstatic inline void ptep_mkdirty(struct mm_struct *mm, 46415902bf63c8332946e5a1f48a72e3ae22874b11bMichal Simek unsigned long addr, pte_t *ptep) 46515902bf63c8332946e5a1f48a72e3ae22874b11bMichal Simek{ 46615902bf63c8332946e5a1f48a72e3ae22874b11bMichal Simek pte_update(ptep, 0, _PAGE_DIRTY); 46715902bf63c8332946e5a1f48a72e3ae22874b11bMichal Simek} 46815902bf63c8332946e5a1f48a72e3ae22874b11bMichal Simek 46915902bf63c8332946e5a1f48a72e3ae22874b11bMichal Simek/*#define pte_same(A,B) (((pte_val(A) ^ pte_val(B)) & ~_PAGE_HASHPTE) == 0)*/ 47015902bf63c8332946e5a1f48a72e3ae22874b11bMichal Simek 47115902bf63c8332946e5a1f48a72e3ae22874b11bMichal Simek/* Convert pmd entry to page */ 47215902bf63c8332946e5a1f48a72e3ae22874b11bMichal Simek/* our pmd entry is an effective address of pte table*/ 47315902bf63c8332946e5a1f48a72e3ae22874b11bMichal Simek/* returns effective address of the pmd entry*/ 47415902bf63c8332946e5a1f48a72e3ae22874b11bMichal Simek#define pmd_page_kernel(pmd) ((unsigned long) (pmd_val(pmd) & PAGE_MASK)) 47515902bf63c8332946e5a1f48a72e3ae22874b11bMichal Simek 47615902bf63c8332946e5a1f48a72e3ae22874b11bMichal Simek/* returns struct *page of the pmd entry*/ 47715902bf63c8332946e5a1f48a72e3ae22874b11bMichal Simek#define pmd_page(pmd) (pfn_to_page(__pa(pmd_val(pmd)) >> PAGE_SHIFT)) 47815902bf63c8332946e5a1f48a72e3ae22874b11bMichal Simek 47915902bf63c8332946e5a1f48a72e3ae22874b11bMichal Simek/* to find an entry in a kernel page-table-directory */ 48015902bf63c8332946e5a1f48a72e3ae22874b11bMichal Simek#define pgd_offset_k(address) pgd_offset(&init_mm, address) 48115902bf63c8332946e5a1f48a72e3ae22874b11bMichal Simek 48215902bf63c8332946e5a1f48a72e3ae22874b11bMichal Simek/* to find an entry in a page-table-directory */ 48315902bf63c8332946e5a1f48a72e3ae22874b11bMichal Simek#define pgd_index(address) ((address) >> PGDIR_SHIFT) 48415902bf63c8332946e5a1f48a72e3ae22874b11bMichal Simek#define pgd_offset(mm, address) ((mm)->pgd + pgd_index(address)) 48515902bf63c8332946e5a1f48a72e3ae22874b11bMichal Simek 48615902bf63c8332946e5a1f48a72e3ae22874b11bMichal Simek/* Find an entry in the second-level page table.. */ 48715902bf63c8332946e5a1f48a72e3ae22874b11bMichal Simekstatic inline pmd_t *pmd_offset(pgd_t *dir, unsigned long address) 48815902bf63c8332946e5a1f48a72e3ae22874b11bMichal Simek{ 48915902bf63c8332946e5a1f48a72e3ae22874b11bMichal Simek return (pmd_t *) dir; 49015902bf63c8332946e5a1f48a72e3ae22874b11bMichal Simek} 49115902bf63c8332946e5a1f48a72e3ae22874b11bMichal Simek 49215902bf63c8332946e5a1f48a72e3ae22874b11bMichal Simek/* Find an entry in the third-level page table.. */ 49315902bf63c8332946e5a1f48a72e3ae22874b11bMichal Simek#define pte_index(address) \ 49415902bf63c8332946e5a1f48a72e3ae22874b11bMichal Simek (((address) >> PAGE_SHIFT) & (PTRS_PER_PTE - 1)) 49515902bf63c8332946e5a1f48a72e3ae22874b11bMichal Simek#define pte_offset_kernel(dir, addr) \ 49615902bf63c8332946e5a1f48a72e3ae22874b11bMichal Simek ((pte_t *) pmd_page_kernel(*(dir)) + pte_index(addr)) 49715902bf63c8332946e5a1f48a72e3ae22874b11bMichal Simek#define pte_offset_map(dir, addr) \ 498ece0e2b6406a995c371e0311190631ea34ad851aPeter Zijlstra ((pte_t *) kmap_atomic(pmd_page(*(dir))) + pte_index(addr)) 49915902bf63c8332946e5a1f48a72e3ae22874b11bMichal Simek 500ece0e2b6406a995c371e0311190631ea34ad851aPeter Zijlstra#define pte_unmap(pte) kunmap_atomic(pte) 50115902bf63c8332946e5a1f48a72e3ae22874b11bMichal Simek 50215902bf63c8332946e5a1f48a72e3ae22874b11bMichal Simek/* Encode and decode a nonlinear file mapping entry */ 50315902bf63c8332946e5a1f48a72e3ae22874b11bMichal Simek#define PTE_FILE_MAX_BITS 29 50415902bf63c8332946e5a1f48a72e3ae22874b11bMichal Simek#define pte_to_pgoff(pte) (pte_val(pte) >> 3) 505f14d6f7c31c73a902a6b567dc719128e74603902Michal Simek#define pgoff_to_pte(off) ((pte_t) { ((off) << 3) | _PAGE_FILE }) 50615902bf63c8332946e5a1f48a72e3ae22874b11bMichal Simek 50715902bf63c8332946e5a1f48a72e3ae22874b11bMichal Simekextern pgd_t swapper_pg_dir[PTRS_PER_PGD]; 50815902bf63c8332946e5a1f48a72e3ae22874b11bMichal Simek 50915902bf63c8332946e5a1f48a72e3ae22874b11bMichal Simek/* 51015902bf63c8332946e5a1f48a72e3ae22874b11bMichal Simek * Encode and decode a swap entry. 51115902bf63c8332946e5a1f48a72e3ae22874b11bMichal Simek * Note that the bits we use in a PTE for representing a swap entry 51215902bf63c8332946e5a1f48a72e3ae22874b11bMichal Simek * must not include the _PAGE_PRESENT bit, or the _PAGE_HASHPTE bit 51315902bf63c8332946e5a1f48a72e3ae22874b11bMichal Simek * (if used). -- paulus 51415902bf63c8332946e5a1f48a72e3ae22874b11bMichal Simek */ 51515902bf63c8332946e5a1f48a72e3ae22874b11bMichal Simek#define __swp_type(entry) ((entry).val & 0x3f) 51615902bf63c8332946e5a1f48a72e3ae22874b11bMichal Simek#define __swp_offset(entry) ((entry).val >> 6) 51715902bf63c8332946e5a1f48a72e3ae22874b11bMichal Simek#define __swp_entry(type, offset) \ 51815902bf63c8332946e5a1f48a72e3ae22874b11bMichal Simek ((swp_entry_t) { (type) | ((offset) << 6) }) 51915902bf63c8332946e5a1f48a72e3ae22874b11bMichal Simek#define __pte_to_swp_entry(pte) ((swp_entry_t) { pte_val(pte) >> 2 }) 52015902bf63c8332946e5a1f48a72e3ae22874b11bMichal Simek#define __swp_entry_to_pte(x) ((pte_t) { (x).val << 2 }) 52115902bf63c8332946e5a1f48a72e3ae22874b11bMichal Simek 52215902bf63c8332946e5a1f48a72e3ae22874b11bMichal Simekextern unsigned long iopa(unsigned long addr); 52315902bf63c8332946e5a1f48a72e3ae22874b11bMichal Simek 52415902bf63c8332946e5a1f48a72e3ae22874b11bMichal Simek/* Values for nocacheflag and cmode */ 52515902bf63c8332946e5a1f48a72e3ae22874b11bMichal Simek/* These are not used by the APUS kernel_map, but prevents 52615902bf63c8332946e5a1f48a72e3ae22874b11bMichal Simek * compilation errors. 52715902bf63c8332946e5a1f48a72e3ae22874b11bMichal Simek */ 52815902bf63c8332946e5a1f48a72e3ae22874b11bMichal Simek#define IOMAP_FULL_CACHING 0 52915902bf63c8332946e5a1f48a72e3ae22874b11bMichal Simek#define IOMAP_NOCACHE_SER 1 53015902bf63c8332946e5a1f48a72e3ae22874b11bMichal Simek#define IOMAP_NOCACHE_NONSER 2 53115902bf63c8332946e5a1f48a72e3ae22874b11bMichal Simek#define IOMAP_NO_COPYBACK 3 53215902bf63c8332946e5a1f48a72e3ae22874b11bMichal Simek 53315902bf63c8332946e5a1f48a72e3ae22874b11bMichal Simek/* Needs to be defined here and not in linux/mm.h, as it is arch dependent */ 53415902bf63c8332946e5a1f48a72e3ae22874b11bMichal Simek#define kern_addr_valid(addr) (1) 53515902bf63c8332946e5a1f48a72e3ae22874b11bMichal Simek 53615902bf63c8332946e5a1f48a72e3ae22874b11bMichal Simek/* 53715902bf63c8332946e5a1f48a72e3ae22874b11bMichal Simek * No page table caches to initialise 53815902bf63c8332946e5a1f48a72e3ae22874b11bMichal Simek */ 53915902bf63c8332946e5a1f48a72e3ae22874b11bMichal Simek#define pgtable_cache_init() do { } while (0) 54015902bf63c8332946e5a1f48a72e3ae22874b11bMichal Simek 54115902bf63c8332946e5a1f48a72e3ae22874b11bMichal Simekvoid do_page_fault(struct pt_regs *regs, unsigned long address, 54215902bf63c8332946e5a1f48a72e3ae22874b11bMichal Simek unsigned long error_code); 54315902bf63c8332946e5a1f48a72e3ae22874b11bMichal Simek 54415902bf63c8332946e5a1f48a72e3ae22874b11bMichal Simekvoid mapin_ram(void); 54515902bf63c8332946e5a1f48a72e3ae22874b11bMichal Simekint map_page(unsigned long va, phys_addr_t pa, int flags); 54615902bf63c8332946e5a1f48a72e3ae22874b11bMichal Simek 54715902bf63c8332946e5a1f48a72e3ae22874b11bMichal Simekextern int mem_init_done; 54815902bf63c8332946e5a1f48a72e3ae22874b11bMichal Simek 54915902bf63c8332946e5a1f48a72e3ae22874b11bMichal Simekasmlinkage void __init mmu_init(void); 55015902bf63c8332946e5a1f48a72e3ae22874b11bMichal Simek 55115902bf63c8332946e5a1f48a72e3ae22874b11bMichal Simekvoid __init *early_get_page(void); 55215902bf63c8332946e5a1f48a72e3ae22874b11bMichal Simek 55315902bf63c8332946e5a1f48a72e3ae22874b11bMichal Simek#endif /* __ASSEMBLY__ */ 55415902bf63c8332946e5a1f48a72e3ae22874b11bMichal Simek#endif /* __KERNEL__ */ 55515902bf63c8332946e5a1f48a72e3ae22874b11bMichal Simek 55615902bf63c8332946e5a1f48a72e3ae22874b11bMichal Simek#endif /* CONFIG_MMU */ 55715902bf63c8332946e5a1f48a72e3ae22874b11bMichal Simek 5586a3cece5e5e7e7c0fde769d7cf065fb8aef6e54eMichal Simek#ifndef __ASSEMBLY__ 5596a3cece5e5e7e7c0fde769d7cf065fb8aef6e54eMichal Simek#include <asm-generic/pgtable.h> 5606a3cece5e5e7e7c0fde769d7cf065fb8aef6e54eMichal Simek 561ae8ee1505162f47f8b8cf7a44c26ea6b172e1445Michal Simekextern unsigned long ioremap_bot, ioremap_base; 562ae8ee1505162f47f8b8cf7a44c26ea6b172e1445Michal Simek 563cd44da154241170be3f1fadb1f2ca689f6802628Michal Simekvoid *consistent_alloc(gfp_t gfp, size_t size, dma_addr_t *dma_handle); 564f1525765fb9c432f5dc5d0d18102fbe9980a14aeMichal Simekvoid consistent_free(size_t size, void *vaddr); 565ae8ee1505162f47f8b8cf7a44c26ea6b172e1445Michal Simekvoid consistent_sync(void *vaddr, size_t size, int direction); 566ae8ee1505162f47f8b8cf7a44c26ea6b172e1445Michal Simekvoid consistent_sync_page(struct page *page, unsigned long offset, 567ae8ee1505162f47f8b8cf7a44c26ea6b172e1445Michal Simek size_t size, int direction); 568ae8ee1505162f47f8b8cf7a44c26ea6b172e1445Michal Simek 5696a3cece5e5e7e7c0fde769d7cf065fb8aef6e54eMichal Simekvoid setup_memory(void); 5706a3cece5e5e7e7c0fde769d7cf065fb8aef6e54eMichal Simek#endif /* __ASSEMBLY__ */ 5716a3cece5e5e7e7c0fde769d7cf065fb8aef6e54eMichal Simek 5726a3cece5e5e7e7c0fde769d7cf065fb8aef6e54eMichal Simek#endif /* _ASM_MICROBLAZE_PGTABLE_H */ 573