162306a36Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0 */ 262306a36Sopenharmony_ci/* 362306a36Sopenharmony_ci * Copyright (C) 2008-2009 Michal Simek <monstr@monstr.eu> 462306a36Sopenharmony_ci * Copyright (C) 2008-2009 PetaLogix 562306a36Sopenharmony_ci * Copyright (C) 2006 Atmark Techno, Inc. 662306a36Sopenharmony_ci */ 762306a36Sopenharmony_ci 862306a36Sopenharmony_ci#ifndef _ASM_MICROBLAZE_PGTABLE_H 962306a36Sopenharmony_ci#define _ASM_MICROBLAZE_PGTABLE_H 1062306a36Sopenharmony_ci 1162306a36Sopenharmony_ci#include <asm/setup.h> 1262306a36Sopenharmony_ci 1362306a36Sopenharmony_ci#ifndef __ASSEMBLY__ 1462306a36Sopenharmony_ciextern int mem_init_done; 1562306a36Sopenharmony_ci#endif 1662306a36Sopenharmony_ci 1762306a36Sopenharmony_ci#include <asm-generic/pgtable-nopmd.h> 1862306a36Sopenharmony_ci 1962306a36Sopenharmony_ci#ifdef __KERNEL__ 2062306a36Sopenharmony_ci#ifndef __ASSEMBLY__ 2162306a36Sopenharmony_ci 2262306a36Sopenharmony_ci#include <linux/sched.h> 2362306a36Sopenharmony_ci#include <linux/threads.h> 2462306a36Sopenharmony_ci#include <asm/processor.h> /* For TASK_SIZE */ 2562306a36Sopenharmony_ci#include <asm/mmu.h> 2662306a36Sopenharmony_ci#include <asm/page.h> 2762306a36Sopenharmony_ci 2862306a36Sopenharmony_ciextern unsigned long va_to_phys(unsigned long address); 2962306a36Sopenharmony_ciextern pte_t *va_to_pte(unsigned long address); 3062306a36Sopenharmony_ci 3162306a36Sopenharmony_ci/* 3262306a36Sopenharmony_ci * The following only work if pte_present() is true. 3362306a36Sopenharmony_ci * Undefined behaviour if not.. 3462306a36Sopenharmony_ci */ 3562306a36Sopenharmony_ci 3662306a36Sopenharmony_ci/* Start and end of the vmalloc area. */ 3762306a36Sopenharmony_ci/* Make sure to map the vmalloc area above the pinned kernel memory area 3862306a36Sopenharmony_ci of 32Mb. */ 3962306a36Sopenharmony_ci#define VMALLOC_START (CONFIG_KERNEL_START + CONFIG_LOWMEM_SIZE) 4062306a36Sopenharmony_ci#define VMALLOC_END ioremap_bot 4162306a36Sopenharmony_ci 4262306a36Sopenharmony_ci#endif /* __ASSEMBLY__ */ 4362306a36Sopenharmony_ci 4462306a36Sopenharmony_ci/* 4562306a36Sopenharmony_ci * Macro to mark a page protection value as "uncacheable". 4662306a36Sopenharmony_ci */ 4762306a36Sopenharmony_ci 4862306a36Sopenharmony_ci#define _PAGE_CACHE_CTL (_PAGE_GUARDED | _PAGE_NO_CACHE | \ 4962306a36Sopenharmony_ci _PAGE_WRITETHRU) 5062306a36Sopenharmony_ci 5162306a36Sopenharmony_ci#define pgprot_noncached(prot) \ 5262306a36Sopenharmony_ci (__pgprot((pgprot_val(prot) & ~_PAGE_CACHE_CTL) | \ 5362306a36Sopenharmony_ci _PAGE_NO_CACHE | _PAGE_GUARDED)) 5462306a36Sopenharmony_ci 5562306a36Sopenharmony_ci#define pgprot_noncached_wc(prot) \ 5662306a36Sopenharmony_ci (__pgprot((pgprot_val(prot) & ~_PAGE_CACHE_CTL) | \ 5762306a36Sopenharmony_ci _PAGE_NO_CACHE)) 5862306a36Sopenharmony_ci 5962306a36Sopenharmony_ci/* 6062306a36Sopenharmony_ci * The MicroBlaze MMU is identical to the PPC-40x MMU, and uses a hash 6162306a36Sopenharmony_ci * table containing PTEs, together with a set of 16 segment registers, to 6262306a36Sopenharmony_ci * define the virtual to physical address mapping. 6362306a36Sopenharmony_ci * 6462306a36Sopenharmony_ci * We use the hash table as an extended TLB, i.e. a cache of currently 6562306a36Sopenharmony_ci * active mappings. We maintain a two-level page table tree, much 6662306a36Sopenharmony_ci * like that used by the i386, for the sake of the Linux memory 6762306a36Sopenharmony_ci * management code. Low-level assembler code in hashtable.S 6862306a36Sopenharmony_ci * (procedure hash_page) is responsible for extracting ptes from the 6962306a36Sopenharmony_ci * tree and putting them into the hash table when necessary, and 7062306a36Sopenharmony_ci * updating the accessed and modified bits in the page table tree. 7162306a36Sopenharmony_ci */ 7262306a36Sopenharmony_ci 7362306a36Sopenharmony_ci/* 7462306a36Sopenharmony_ci * The MicroBlaze processor has a TLB architecture identical to PPC-40x. The 7562306a36Sopenharmony_ci * instruction and data sides share a unified, 64-entry, semi-associative 7662306a36Sopenharmony_ci * TLB which is maintained totally under software control. In addition, the 7762306a36Sopenharmony_ci * instruction side has a hardware-managed, 2,4, or 8-entry, fully-associative 7862306a36Sopenharmony_ci * TLB which serves as a first level to the shared TLB. These two TLBs are 7962306a36Sopenharmony_ci * known as the UTLB and ITLB, respectively (see "mmu.h" for definitions). 8062306a36Sopenharmony_ci */ 8162306a36Sopenharmony_ci 8262306a36Sopenharmony_ci/* 8362306a36Sopenharmony_ci * The normal case is that PTEs are 32-bits and we have a 1-page 8462306a36Sopenharmony_ci * 1024-entry pgdir pointing to 1-page 1024-entry PTE pages. -- paulus 8562306a36Sopenharmony_ci * 8662306a36Sopenharmony_ci */ 8762306a36Sopenharmony_ci 8862306a36Sopenharmony_ci/* PGDIR_SHIFT determines what a top-level page table entry can map */ 8962306a36Sopenharmony_ci#define PGDIR_SHIFT (PAGE_SHIFT + PTE_SHIFT) 9062306a36Sopenharmony_ci#define PGDIR_SIZE (1UL << PGDIR_SHIFT) 9162306a36Sopenharmony_ci#define PGDIR_MASK (~(PGDIR_SIZE-1)) 9262306a36Sopenharmony_ci 9362306a36Sopenharmony_ci/* 9462306a36Sopenharmony_ci * entries per page directory level: our page-table tree is two-level, so 9562306a36Sopenharmony_ci * we don't really have any PMD directory. 9662306a36Sopenharmony_ci */ 9762306a36Sopenharmony_ci#define PTRS_PER_PTE (1 << PTE_SHIFT) 9862306a36Sopenharmony_ci#define PTRS_PER_PMD 1 9962306a36Sopenharmony_ci#define PTRS_PER_PGD (1 << (32 - PGDIR_SHIFT)) 10062306a36Sopenharmony_ci 10162306a36Sopenharmony_ci#define USER_PTRS_PER_PGD (TASK_SIZE / PGDIR_SIZE) 10262306a36Sopenharmony_ci#define FIRST_USER_PGD_NR 0 10362306a36Sopenharmony_ci 10462306a36Sopenharmony_ci#define USER_PGD_PTRS (PAGE_OFFSET >> PGDIR_SHIFT) 10562306a36Sopenharmony_ci#define KERNEL_PGD_PTRS (PTRS_PER_PGD-USER_PGD_PTRS) 10662306a36Sopenharmony_ci 10762306a36Sopenharmony_ci#define pte_ERROR(e) \ 10862306a36Sopenharmony_ci printk(KERN_ERR "%s:%d: bad pte "PTE_FMT".\n", \ 10962306a36Sopenharmony_ci __FILE__, __LINE__, pte_val(e)) 11062306a36Sopenharmony_ci#define pgd_ERROR(e) \ 11162306a36Sopenharmony_ci printk(KERN_ERR "%s:%d: bad pgd %08lx.\n", \ 11262306a36Sopenharmony_ci __FILE__, __LINE__, pgd_val(e)) 11362306a36Sopenharmony_ci 11462306a36Sopenharmony_ci/* 11562306a36Sopenharmony_ci * Bits in a linux-style PTE. These match the bits in the 11662306a36Sopenharmony_ci * (hardware-defined) PTE as closely as possible. 11762306a36Sopenharmony_ci */ 11862306a36Sopenharmony_ci 11962306a36Sopenharmony_ci/* There are several potential gotchas here. The hardware TLBLO 12062306a36Sopenharmony_ci * field looks like this: 12162306a36Sopenharmony_ci * 12262306a36Sopenharmony_ci * 0 1 2 3 4 ... 18 19 20 21 22 23 24 25 26 27 28 29 30 31 12362306a36Sopenharmony_ci * RPN..................... 0 0 EX WR ZSEL....... W I M G 12462306a36Sopenharmony_ci * 12562306a36Sopenharmony_ci * Where possible we make the Linux PTE bits match up with this 12662306a36Sopenharmony_ci * 12762306a36Sopenharmony_ci * - bits 20 and 21 must be cleared, because we use 4k pages (4xx can 12862306a36Sopenharmony_ci * support down to 1k pages), this is done in the TLBMiss exception 12962306a36Sopenharmony_ci * handler. 13062306a36Sopenharmony_ci * - We use only zones 0 (for kernel pages) and 1 (for user pages) 13162306a36Sopenharmony_ci * of the 16 available. Bit 24-26 of the TLB are cleared in the TLB 13262306a36Sopenharmony_ci * miss handler. Bit 27 is PAGE_USER, thus selecting the correct 13362306a36Sopenharmony_ci * zone. 13462306a36Sopenharmony_ci * - PRESENT *must* be in the bottom two bits because swap PTEs use the top 13562306a36Sopenharmony_ci * 30 bits. Because 4xx doesn't support SMP anyway, M is irrelevant so we 13662306a36Sopenharmony_ci * borrow it for PAGE_PRESENT. Bit 30 is cleared in the TLB miss handler 13762306a36Sopenharmony_ci * before the TLB entry is loaded. 13862306a36Sopenharmony_ci * - All other bits of the PTE are loaded into TLBLO without 13962306a36Sopenharmony_ci * * modification, leaving us only the bits 20, 21, 24, 25, 26, 30 for 14062306a36Sopenharmony_ci * software PTE bits. We actually use bits 21, 24, 25, and 14162306a36Sopenharmony_ci * 30 respectively for the software bits: ACCESSED, DIRTY, RW, and 14262306a36Sopenharmony_ci * PRESENT. 14362306a36Sopenharmony_ci */ 14462306a36Sopenharmony_ci 14562306a36Sopenharmony_ci/* Definitions for MicroBlaze. */ 14662306a36Sopenharmony_ci#define _PAGE_GUARDED 0x001 /* G: page is guarded from prefetch */ 14762306a36Sopenharmony_ci#define _PAGE_PRESENT 0x002 /* software: PTE contains a translation */ 14862306a36Sopenharmony_ci#define _PAGE_NO_CACHE 0x004 /* I: caching is inhibited */ 14962306a36Sopenharmony_ci#define _PAGE_WRITETHRU 0x008 /* W: caching is write-through */ 15062306a36Sopenharmony_ci#define _PAGE_USER 0x010 /* matches one of the zone permission bits */ 15162306a36Sopenharmony_ci#define _PAGE_RW 0x040 /* software: Writes permitted */ 15262306a36Sopenharmony_ci#define _PAGE_DIRTY 0x080 /* software: dirty page */ 15362306a36Sopenharmony_ci#define _PAGE_HWWRITE 0x100 /* hardware: Dirty & RW, set in exception */ 15462306a36Sopenharmony_ci#define _PAGE_HWEXEC 0x200 /* hardware: EX permission */ 15562306a36Sopenharmony_ci#define _PAGE_ACCESSED 0x400 /* software: R: page referenced */ 15662306a36Sopenharmony_ci#define _PMD_PRESENT PAGE_MASK 15762306a36Sopenharmony_ci 15862306a36Sopenharmony_ci/* We borrow bit 24 to store the exclusive marker in swap PTEs. */ 15962306a36Sopenharmony_ci#define _PAGE_SWP_EXCLUSIVE _PAGE_DIRTY 16062306a36Sopenharmony_ci 16162306a36Sopenharmony_ci/* 16262306a36Sopenharmony_ci * Some bits are unused... 16362306a36Sopenharmony_ci */ 16462306a36Sopenharmony_ci#ifndef _PAGE_HASHPTE 16562306a36Sopenharmony_ci#define _PAGE_HASHPTE 0 16662306a36Sopenharmony_ci#endif 16762306a36Sopenharmony_ci#ifndef _PTE_NONE_MASK 16862306a36Sopenharmony_ci#define _PTE_NONE_MASK 0 16962306a36Sopenharmony_ci#endif 17062306a36Sopenharmony_ci#ifndef _PAGE_SHARED 17162306a36Sopenharmony_ci#define _PAGE_SHARED 0 17262306a36Sopenharmony_ci#endif 17362306a36Sopenharmony_ci#ifndef _PAGE_EXEC 17462306a36Sopenharmony_ci#define _PAGE_EXEC 0 17562306a36Sopenharmony_ci#endif 17662306a36Sopenharmony_ci 17762306a36Sopenharmony_ci#define _PAGE_CHG_MASK (PAGE_MASK | _PAGE_ACCESSED | _PAGE_DIRTY) 17862306a36Sopenharmony_ci 17962306a36Sopenharmony_ci/* 18062306a36Sopenharmony_ci * Note: the _PAGE_COHERENT bit automatically gets set in the hardware 18162306a36Sopenharmony_ci * PTE if CONFIG_SMP is defined (hash_page does this); there is no need 18262306a36Sopenharmony_ci * to have it in the Linux PTE, and in fact the bit could be reused for 18362306a36Sopenharmony_ci * another purpose. -- paulus. 18462306a36Sopenharmony_ci */ 18562306a36Sopenharmony_ci#define _PAGE_BASE (_PAGE_PRESENT | _PAGE_ACCESSED) 18662306a36Sopenharmony_ci#define _PAGE_WRENABLE (_PAGE_RW | _PAGE_DIRTY | _PAGE_HWWRITE) 18762306a36Sopenharmony_ci 18862306a36Sopenharmony_ci#define _PAGE_KERNEL \ 18962306a36Sopenharmony_ci (_PAGE_BASE | _PAGE_WRENABLE | _PAGE_SHARED | _PAGE_HWEXEC) 19062306a36Sopenharmony_ci 19162306a36Sopenharmony_ci#define _PAGE_IO (_PAGE_KERNEL | _PAGE_NO_CACHE | _PAGE_GUARDED) 19262306a36Sopenharmony_ci 19362306a36Sopenharmony_ci#define PAGE_NONE __pgprot(_PAGE_BASE) 19462306a36Sopenharmony_ci#define PAGE_READONLY __pgprot(_PAGE_BASE | _PAGE_USER) 19562306a36Sopenharmony_ci#define PAGE_READONLY_X __pgprot(_PAGE_BASE | _PAGE_USER | _PAGE_EXEC) 19662306a36Sopenharmony_ci#define PAGE_SHARED __pgprot(_PAGE_BASE | _PAGE_USER | _PAGE_RW) 19762306a36Sopenharmony_ci#define PAGE_SHARED_X \ 19862306a36Sopenharmony_ci __pgprot(_PAGE_BASE | _PAGE_USER | _PAGE_RW | _PAGE_EXEC) 19962306a36Sopenharmony_ci#define PAGE_COPY __pgprot(_PAGE_BASE | _PAGE_USER) 20062306a36Sopenharmony_ci#define PAGE_COPY_X __pgprot(_PAGE_BASE | _PAGE_USER | _PAGE_EXEC) 20162306a36Sopenharmony_ci 20262306a36Sopenharmony_ci#define PAGE_KERNEL __pgprot(_PAGE_KERNEL) 20362306a36Sopenharmony_ci#define PAGE_KERNEL_RO __pgprot(_PAGE_BASE | _PAGE_SHARED) 20462306a36Sopenharmony_ci#define PAGE_KERNEL_CI __pgprot(_PAGE_IO) 20562306a36Sopenharmony_ci 20662306a36Sopenharmony_ci/* 20762306a36Sopenharmony_ci * We consider execute permission the same as read. 20862306a36Sopenharmony_ci * Also, write permissions imply read permissions. 20962306a36Sopenharmony_ci */ 21062306a36Sopenharmony_ci 21162306a36Sopenharmony_ci#ifndef __ASSEMBLY__ 21262306a36Sopenharmony_ci/* 21362306a36Sopenharmony_ci * ZERO_PAGE is a global shared page that is always zero: used 21462306a36Sopenharmony_ci * for zero-mapped memory areas etc.. 21562306a36Sopenharmony_ci */ 21662306a36Sopenharmony_ciextern unsigned long empty_zero_page[1024]; 21762306a36Sopenharmony_ci#define ZERO_PAGE(vaddr) (virt_to_page(empty_zero_page)) 21862306a36Sopenharmony_ci 21962306a36Sopenharmony_ci#endif /* __ASSEMBLY__ */ 22062306a36Sopenharmony_ci 22162306a36Sopenharmony_ci#define pte_none(pte) ((pte_val(pte) & ~_PTE_NONE_MASK) == 0) 22262306a36Sopenharmony_ci#define pte_present(pte) (pte_val(pte) & _PAGE_PRESENT) 22362306a36Sopenharmony_ci#define pte_clear(mm, addr, ptep) \ 22462306a36Sopenharmony_ci do { set_pte_at((mm), (addr), (ptep), __pte(0)); } while (0) 22562306a36Sopenharmony_ci 22662306a36Sopenharmony_ci#define pmd_none(pmd) (!pmd_val(pmd)) 22762306a36Sopenharmony_ci#define pmd_bad(pmd) ((pmd_val(pmd) & _PMD_PRESENT) == 0) 22862306a36Sopenharmony_ci#define pmd_present(pmd) ((pmd_val(pmd) & _PMD_PRESENT) != 0) 22962306a36Sopenharmony_ci#define pmd_clear(pmdp) do { pmd_val(*(pmdp)) = 0; } while (0) 23062306a36Sopenharmony_ci 23162306a36Sopenharmony_ci#define pte_page(x) (mem_map + (unsigned long) \ 23262306a36Sopenharmony_ci ((pte_val(x) - memory_start) >> PAGE_SHIFT)) 23362306a36Sopenharmony_ci#define PFN_PTE_SHIFT PAGE_SHIFT 23462306a36Sopenharmony_ci 23562306a36Sopenharmony_ci#define pte_pfn(x) (pte_val(x) >> PFN_PTE_SHIFT) 23662306a36Sopenharmony_ci 23762306a36Sopenharmony_ci#define pfn_pte(pfn, prot) \ 23862306a36Sopenharmony_ci __pte(((pte_basic_t)(pfn) << PFN_PTE_SHIFT) | pgprot_val(prot)) 23962306a36Sopenharmony_ci 24062306a36Sopenharmony_ci#ifndef __ASSEMBLY__ 24162306a36Sopenharmony_ci/* 24262306a36Sopenharmony_ci * The following only work if pte_present() is true. 24362306a36Sopenharmony_ci * Undefined behaviour if not.. 24462306a36Sopenharmony_ci */ 24562306a36Sopenharmony_cistatic inline int pte_read(pte_t pte) { return pte_val(pte) & _PAGE_USER; } 24662306a36Sopenharmony_cistatic inline int pte_write(pte_t pte) { return pte_val(pte) & _PAGE_RW; } 24762306a36Sopenharmony_cistatic inline int pte_exec(pte_t pte) { return pte_val(pte) & _PAGE_EXEC; } 24862306a36Sopenharmony_cistatic inline int pte_dirty(pte_t pte) { return pte_val(pte) & _PAGE_DIRTY; } 24962306a36Sopenharmony_cistatic inline int pte_young(pte_t pte) { return pte_val(pte) & _PAGE_ACCESSED; } 25062306a36Sopenharmony_ci 25162306a36Sopenharmony_cistatic inline void pte_uncache(pte_t pte) { pte_val(pte) |= _PAGE_NO_CACHE; } 25262306a36Sopenharmony_cistatic inline void pte_cache(pte_t pte) { pte_val(pte) &= ~_PAGE_NO_CACHE; } 25362306a36Sopenharmony_ci 25462306a36Sopenharmony_cistatic inline pte_t pte_rdprotect(pte_t pte) \ 25562306a36Sopenharmony_ci { pte_val(pte) &= ~_PAGE_USER; return pte; } 25662306a36Sopenharmony_cistatic inline pte_t pte_wrprotect(pte_t pte) \ 25762306a36Sopenharmony_ci { pte_val(pte) &= ~(_PAGE_RW | _PAGE_HWWRITE); return pte; } 25862306a36Sopenharmony_cistatic inline pte_t pte_exprotect(pte_t pte) \ 25962306a36Sopenharmony_ci { pte_val(pte) &= ~_PAGE_EXEC; return pte; } 26062306a36Sopenharmony_cistatic inline pte_t pte_mkclean(pte_t pte) \ 26162306a36Sopenharmony_ci { pte_val(pte) &= ~(_PAGE_DIRTY | _PAGE_HWWRITE); return pte; } 26262306a36Sopenharmony_cistatic inline pte_t pte_mkold(pte_t pte) \ 26362306a36Sopenharmony_ci { pte_val(pte) &= ~_PAGE_ACCESSED; return pte; } 26462306a36Sopenharmony_ci 26562306a36Sopenharmony_cistatic inline pte_t pte_mkread(pte_t pte) \ 26662306a36Sopenharmony_ci { pte_val(pte) |= _PAGE_USER; return pte; } 26762306a36Sopenharmony_cistatic inline pte_t pte_mkexec(pte_t pte) \ 26862306a36Sopenharmony_ci { pte_val(pte) |= _PAGE_USER | _PAGE_EXEC; return pte; } 26962306a36Sopenharmony_cistatic inline pte_t pte_mkwrite_novma(pte_t pte) \ 27062306a36Sopenharmony_ci { pte_val(pte) |= _PAGE_RW; return pte; } 27162306a36Sopenharmony_cistatic inline pte_t pte_mkdirty(pte_t pte) \ 27262306a36Sopenharmony_ci { pte_val(pte) |= _PAGE_DIRTY; return pte; } 27362306a36Sopenharmony_cistatic inline pte_t pte_mkyoung(pte_t pte) \ 27462306a36Sopenharmony_ci { pte_val(pte) |= _PAGE_ACCESSED; return pte; } 27562306a36Sopenharmony_ci 27662306a36Sopenharmony_ci/* 27762306a36Sopenharmony_ci * Conversion functions: convert a page and protection to a page entry, 27862306a36Sopenharmony_ci * and a page entry and page directory to the page they refer to. 27962306a36Sopenharmony_ci */ 28062306a36Sopenharmony_ci 28162306a36Sopenharmony_cistatic inline pte_t mk_pte_phys(phys_addr_t physpage, pgprot_t pgprot) 28262306a36Sopenharmony_ci{ 28362306a36Sopenharmony_ci pte_t pte; 28462306a36Sopenharmony_ci pte_val(pte) = physpage | pgprot_val(pgprot); 28562306a36Sopenharmony_ci return pte; 28662306a36Sopenharmony_ci} 28762306a36Sopenharmony_ci 28862306a36Sopenharmony_ci#define mk_pte(page, pgprot) \ 28962306a36Sopenharmony_ci({ \ 29062306a36Sopenharmony_ci pte_t pte; \ 29162306a36Sopenharmony_ci pte_val(pte) = (((page - mem_map) << PAGE_SHIFT) + memory_start) | \ 29262306a36Sopenharmony_ci pgprot_val(pgprot); \ 29362306a36Sopenharmony_ci pte; \ 29462306a36Sopenharmony_ci}) 29562306a36Sopenharmony_ci 29662306a36Sopenharmony_cistatic inline pte_t pte_modify(pte_t pte, pgprot_t newprot) 29762306a36Sopenharmony_ci{ 29862306a36Sopenharmony_ci pte_val(pte) = (pte_val(pte) & _PAGE_CHG_MASK) | pgprot_val(newprot); 29962306a36Sopenharmony_ci return pte; 30062306a36Sopenharmony_ci} 30162306a36Sopenharmony_ci 30262306a36Sopenharmony_ci/* 30362306a36Sopenharmony_ci * Atomic PTE updates. 30462306a36Sopenharmony_ci * 30562306a36Sopenharmony_ci * pte_update clears and sets bit atomically, and returns 30662306a36Sopenharmony_ci * the old pte value. 30762306a36Sopenharmony_ci * The ((unsigned long)(p+1) - 4) hack is to get to the least-significant 30862306a36Sopenharmony_ci * 32 bits of the PTE regardless of whether PTEs are 32 or 64 bits. 30962306a36Sopenharmony_ci */ 31062306a36Sopenharmony_cistatic inline unsigned long pte_update(pte_t *p, unsigned long clr, 31162306a36Sopenharmony_ci unsigned long set) 31262306a36Sopenharmony_ci{ 31362306a36Sopenharmony_ci unsigned long flags, old, tmp; 31462306a36Sopenharmony_ci 31562306a36Sopenharmony_ci raw_local_irq_save(flags); 31662306a36Sopenharmony_ci 31762306a36Sopenharmony_ci __asm__ __volatile__( "lw %0, %2, r0 \n" 31862306a36Sopenharmony_ci "andn %1, %0, %3 \n" 31962306a36Sopenharmony_ci "or %1, %1, %4 \n" 32062306a36Sopenharmony_ci "sw %1, %2, r0 \n" 32162306a36Sopenharmony_ci : "=&r" (old), "=&r" (tmp) 32262306a36Sopenharmony_ci : "r" ((unsigned long)(p + 1) - 4), "r" (clr), "r" (set) 32362306a36Sopenharmony_ci : "cc"); 32462306a36Sopenharmony_ci 32562306a36Sopenharmony_ci raw_local_irq_restore(flags); 32662306a36Sopenharmony_ci 32762306a36Sopenharmony_ci return old; 32862306a36Sopenharmony_ci} 32962306a36Sopenharmony_ci 33062306a36Sopenharmony_ci/* 33162306a36Sopenharmony_ci * set_pte stores a linux PTE into the linux page table. 33262306a36Sopenharmony_ci */ 33362306a36Sopenharmony_cistatic inline void set_pte(pte_t *ptep, pte_t pte) 33462306a36Sopenharmony_ci{ 33562306a36Sopenharmony_ci *ptep = pte; 33662306a36Sopenharmony_ci} 33762306a36Sopenharmony_ci 33862306a36Sopenharmony_ci#define __HAVE_ARCH_PTEP_TEST_AND_CLEAR_YOUNG 33962306a36Sopenharmony_cistatic inline int ptep_test_and_clear_young(struct vm_area_struct *vma, 34062306a36Sopenharmony_ci unsigned long address, pte_t *ptep) 34162306a36Sopenharmony_ci{ 34262306a36Sopenharmony_ci return (pte_update(ptep, _PAGE_ACCESSED, 0) & _PAGE_ACCESSED) != 0; 34362306a36Sopenharmony_ci} 34462306a36Sopenharmony_ci 34562306a36Sopenharmony_cistatic inline int ptep_test_and_clear_dirty(struct mm_struct *mm, 34662306a36Sopenharmony_ci unsigned long addr, pte_t *ptep) 34762306a36Sopenharmony_ci{ 34862306a36Sopenharmony_ci return (pte_update(ptep, \ 34962306a36Sopenharmony_ci (_PAGE_DIRTY | _PAGE_HWWRITE), 0) & _PAGE_DIRTY) != 0; 35062306a36Sopenharmony_ci} 35162306a36Sopenharmony_ci 35262306a36Sopenharmony_ci#define __HAVE_ARCH_PTEP_GET_AND_CLEAR 35362306a36Sopenharmony_cistatic inline pte_t ptep_get_and_clear(struct mm_struct *mm, 35462306a36Sopenharmony_ci unsigned long addr, pte_t *ptep) 35562306a36Sopenharmony_ci{ 35662306a36Sopenharmony_ci return __pte(pte_update(ptep, ~_PAGE_HASHPTE, 0)); 35762306a36Sopenharmony_ci} 35862306a36Sopenharmony_ci 35962306a36Sopenharmony_ci/*static inline void ptep_set_wrprotect(struct mm_struct *mm, 36062306a36Sopenharmony_ci unsigned long addr, pte_t *ptep) 36162306a36Sopenharmony_ci{ 36262306a36Sopenharmony_ci pte_update(ptep, (_PAGE_RW | _PAGE_HWWRITE), 0); 36362306a36Sopenharmony_ci}*/ 36462306a36Sopenharmony_ci 36562306a36Sopenharmony_cistatic inline void ptep_mkdirty(struct mm_struct *mm, 36662306a36Sopenharmony_ci unsigned long addr, pte_t *ptep) 36762306a36Sopenharmony_ci{ 36862306a36Sopenharmony_ci pte_update(ptep, 0, _PAGE_DIRTY); 36962306a36Sopenharmony_ci} 37062306a36Sopenharmony_ci 37162306a36Sopenharmony_ci/*#define pte_same(A,B) (((pte_val(A) ^ pte_val(B)) & ~_PAGE_HASHPTE) == 0)*/ 37262306a36Sopenharmony_ci 37362306a36Sopenharmony_ci/* Convert pmd entry to page */ 37462306a36Sopenharmony_ci/* our pmd entry is an effective address of pte table*/ 37562306a36Sopenharmony_ci/* returns effective address of the pmd entry*/ 37662306a36Sopenharmony_cistatic inline unsigned long pmd_page_vaddr(pmd_t pmd) 37762306a36Sopenharmony_ci{ 37862306a36Sopenharmony_ci return ((unsigned long) (pmd_val(pmd) & PAGE_MASK)); 37962306a36Sopenharmony_ci} 38062306a36Sopenharmony_ci 38162306a36Sopenharmony_ci/* returns pfn of the pmd entry*/ 38262306a36Sopenharmony_ci#define pmd_pfn(pmd) (__pa(pmd_val(pmd)) >> PAGE_SHIFT) 38362306a36Sopenharmony_ci 38462306a36Sopenharmony_ci/* returns struct *page of the pmd entry*/ 38562306a36Sopenharmony_ci#define pmd_page(pmd) (pfn_to_page(__pa(pmd_val(pmd)) >> PAGE_SHIFT)) 38662306a36Sopenharmony_ci 38762306a36Sopenharmony_ci/* Find an entry in the third-level page table.. */ 38862306a36Sopenharmony_ci 38962306a36Sopenharmony_ciextern pgd_t swapper_pg_dir[PTRS_PER_PGD]; 39062306a36Sopenharmony_ci 39162306a36Sopenharmony_ci/* 39262306a36Sopenharmony_ci * Encode/decode swap entries and swap PTEs. Swap PTEs are all PTEs that 39362306a36Sopenharmony_ci * are !pte_none() && !pte_present(). 39462306a36Sopenharmony_ci * 39562306a36Sopenharmony_ci * 1 1 1 1 1 1 1 1 1 2 2 2 2 2 2 2 2 2 2 3 3 39662306a36Sopenharmony_ci * 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 39762306a36Sopenharmony_ci * <------------------ offset -------------------> E < type -> 0 0 39862306a36Sopenharmony_ci * 39962306a36Sopenharmony_ci * E is the exclusive marker that is not stored in swap entries. 40062306a36Sopenharmony_ci */ 40162306a36Sopenharmony_ci#define __swp_type(entry) ((entry).val & 0x1f) 40262306a36Sopenharmony_ci#define __swp_offset(entry) ((entry).val >> 6) 40362306a36Sopenharmony_ci#define __swp_entry(type, offset) \ 40462306a36Sopenharmony_ci ((swp_entry_t) { ((type) & 0x1f) | ((offset) << 6) }) 40562306a36Sopenharmony_ci#define __pte_to_swp_entry(pte) ((swp_entry_t) { pte_val(pte) >> 2 }) 40662306a36Sopenharmony_ci#define __swp_entry_to_pte(x) ((pte_t) { (x).val << 2 }) 40762306a36Sopenharmony_ci 40862306a36Sopenharmony_cistatic inline int pte_swp_exclusive(pte_t pte) 40962306a36Sopenharmony_ci{ 41062306a36Sopenharmony_ci return pte_val(pte) & _PAGE_SWP_EXCLUSIVE; 41162306a36Sopenharmony_ci} 41262306a36Sopenharmony_ci 41362306a36Sopenharmony_cistatic inline pte_t pte_swp_mkexclusive(pte_t pte) 41462306a36Sopenharmony_ci{ 41562306a36Sopenharmony_ci pte_val(pte) |= _PAGE_SWP_EXCLUSIVE; 41662306a36Sopenharmony_ci return pte; 41762306a36Sopenharmony_ci} 41862306a36Sopenharmony_ci 41962306a36Sopenharmony_cistatic inline pte_t pte_swp_clear_exclusive(pte_t pte) 42062306a36Sopenharmony_ci{ 42162306a36Sopenharmony_ci pte_val(pte) &= ~_PAGE_SWP_EXCLUSIVE; 42262306a36Sopenharmony_ci return pte; 42362306a36Sopenharmony_ci} 42462306a36Sopenharmony_ci 42562306a36Sopenharmony_ciextern unsigned long iopa(unsigned long addr); 42662306a36Sopenharmony_ci 42762306a36Sopenharmony_ci/* Values for nocacheflag and cmode */ 42862306a36Sopenharmony_ci/* These are not used by the APUS kernel_map, but prevents 42962306a36Sopenharmony_ci * compilation errors. 43062306a36Sopenharmony_ci */ 43162306a36Sopenharmony_ci#define IOMAP_FULL_CACHING 0 43262306a36Sopenharmony_ci#define IOMAP_NOCACHE_SER 1 43362306a36Sopenharmony_ci#define IOMAP_NOCACHE_NONSER 2 43462306a36Sopenharmony_ci#define IOMAP_NO_COPYBACK 3 43562306a36Sopenharmony_ci 43662306a36Sopenharmony_civoid do_page_fault(struct pt_regs *regs, unsigned long address, 43762306a36Sopenharmony_ci unsigned long error_code); 43862306a36Sopenharmony_ci 43962306a36Sopenharmony_civoid mapin_ram(void); 44062306a36Sopenharmony_ciint map_page(unsigned long va, phys_addr_t pa, int flags); 44162306a36Sopenharmony_ci 44262306a36Sopenharmony_ciextern int mem_init_done; 44362306a36Sopenharmony_ci 44462306a36Sopenharmony_ciasmlinkage void __init mmu_init(void); 44562306a36Sopenharmony_ci 44662306a36Sopenharmony_ci#endif /* __ASSEMBLY__ */ 44762306a36Sopenharmony_ci#endif /* __KERNEL__ */ 44862306a36Sopenharmony_ci 44962306a36Sopenharmony_ci#ifndef __ASSEMBLY__ 45062306a36Sopenharmony_ciextern unsigned long ioremap_bot, ioremap_base; 45162306a36Sopenharmony_ci 45262306a36Sopenharmony_civoid setup_memory(void); 45362306a36Sopenharmony_ci#endif /* __ASSEMBLY__ */ 45462306a36Sopenharmony_ci 45562306a36Sopenharmony_ci#endif /* _ASM_MICROBLAZE_PGTABLE_H */ 456