14b87d7a4SMichal Simek /* 21f84e1eaSMichal Simek * VM ops 31f84e1eaSMichal Simek * 41f84e1eaSMichal Simek * Copyright (C) 2008-2009 Michal Simek <monstr@monstr.eu> 51f84e1eaSMichal Simek * Copyright (C) 2008-2009 PetaLogix 64b87d7a4SMichal Simek * Copyright (C) 2006 Atmark Techno, Inc. 74b87d7a4SMichal Simek * Changes for MMU support: 84b87d7a4SMichal Simek * Copyright (C) 2007 Xilinx, Inc. All rights reserved. 94b87d7a4SMichal Simek * 104b87d7a4SMichal Simek * This file is subject to the terms and conditions of the GNU General Public 114b87d7a4SMichal Simek * License. See the file "COPYING" in the main directory of this archive 124b87d7a4SMichal Simek * for more details. 134b87d7a4SMichal Simek */ 144b87d7a4SMichal Simek 154b87d7a4SMichal Simek #ifndef _ASM_MICROBLAZE_PAGE_H 164b87d7a4SMichal Simek #define _ASM_MICROBLAZE_PAGE_H 174b87d7a4SMichal Simek 184b87d7a4SMichal Simek #include <linux/pfn.h> 194b87d7a4SMichal Simek #include <asm/setup.h> 20a1253977SJohn Williams #include <asm/asm-compat.h> 211f84e1eaSMichal Simek #include <linux/const.h> 221f84e1eaSMichal Simek 231f84e1eaSMichal Simek #ifdef __KERNEL__ 244b87d7a4SMichal Simek 254b87d7a4SMichal Simek /* PAGE_SHIFT determines the page size */ 264b87d7a4SMichal Simek #define PAGE_SHIFT (12) 271f84e1eaSMichal Simek #define PAGE_SIZE (_AC(1, UL) << PAGE_SHIFT) 284b87d7a4SMichal Simek #define PAGE_MASK (~(PAGE_SIZE-1)) 294b87d7a4SMichal Simek 30a1253977SJohn Williams #define LOAD_OFFSET ASM_CONST((CONFIG_KERNEL_START-CONFIG_KERNEL_BASE_ADDR)) 31a1253977SJohn Williams 324b87d7a4SMichal Simek #ifndef __ASSEMBLY__ 334b87d7a4SMichal Simek 34de925d9dSMichal Simek /* MS be sure that SLAB allocates aligned objects */ 35de925d9dSMichal Simek #define ARCH_KMALLOC_MINALIGN L1_CACHE_BYTES 36de925d9dSMichal Simek 37ffe57d02SMichal Simek #define ARCH_SLAB_MINALIGN L1_CACHE_BYTES 38ffe57d02SMichal Simek 394b87d7a4SMichal Simek #define PAGE_UP(addr) (((addr)+((PAGE_SIZE)-1))&(~((PAGE_SIZE)-1))) 404b87d7a4SMichal Simek #define PAGE_DOWN(addr) ((addr)&(~((PAGE_SIZE)-1))) 414b87d7a4SMichal Simek 424b87d7a4SMichal Simek /* align addr on a size boundary - adjust address up/down if needed */ 434b87d7a4SMichal Simek #define _ALIGN_UP(addr, size) (((addr)+((size)-1))&(~((size)-1))) 444b87d7a4SMichal Simek #define _ALIGN_DOWN(addr, size) ((addr)&(~((size)-1))) 454b87d7a4SMichal Simek 464b87d7a4SMichal Simek /* align addr on a size boundary - adjust address up if needed */ 474b87d7a4SMichal Simek #define _ALIGN(addr, size) _ALIGN_UP(addr, size) 484b87d7a4SMichal Simek 491f84e1eaSMichal Simek #ifndef CONFIG_MMU 504b87d7a4SMichal Simek /* 514b87d7a4SMichal Simek * PAGE_OFFSET -- the first address of the first page of memory. When not 524b87d7a4SMichal Simek * using MMU this corresponds to the first free page in physical memory (aligned 534b87d7a4SMichal Simek * on a page boundary). 544b87d7a4SMichal Simek */ 554b87d7a4SMichal Simek extern unsigned int __page_offset; 564b87d7a4SMichal Simek #define PAGE_OFFSET __page_offset 574b87d7a4SMichal Simek 581f84e1eaSMichal Simek #else /* CONFIG_MMU */ 591f84e1eaSMichal Simek 601f84e1eaSMichal Simek /* 611f84e1eaSMichal Simek * PAGE_OFFSET -- the first address of the first page of memory. With MMU 621f84e1eaSMichal Simek * it is set to the kernel start address (aligned on a page boundary). 631f84e1eaSMichal Simek * 641f84e1eaSMichal Simek * CONFIG_KERNEL_START is defined in arch/microblaze/config.in and used 651f84e1eaSMichal Simek * in arch/microblaze/Makefile. 661f84e1eaSMichal Simek */ 671f84e1eaSMichal Simek #define PAGE_OFFSET CONFIG_KERNEL_START 681f84e1eaSMichal Simek 691f84e1eaSMichal Simek /* 701f84e1eaSMichal Simek * The basic type of a PTE - 32 bit physical addressing. 711f84e1eaSMichal Simek */ 721f84e1eaSMichal Simek typedef unsigned long pte_basic_t; 731f84e1eaSMichal Simek #define PTE_SHIFT (PAGE_SHIFT - 2) /* 1024 ptes per page */ 741f84e1eaSMichal Simek #define PTE_FMT "%.8lx" 751f84e1eaSMichal Simek 761f84e1eaSMichal Simek #endif /* CONFIG_MMU */ 771f84e1eaSMichal Simek 7843f2a6e8SMichal Simek # define copy_page(to, from) memcpy((to), (from), PAGE_SIZE) 794b87d7a4SMichal Simek # define clear_page(pgaddr) memset((pgaddr), 0, PAGE_SIZE) 804b87d7a4SMichal Simek 814b87d7a4SMichal Simek # define clear_user_page(pgaddr, vaddr, page) memset((pgaddr), 0, PAGE_SIZE) 824b87d7a4SMichal Simek # define copy_user_page(vto, vfrom, vaddr, topg) \ 834b87d7a4SMichal Simek memcpy((vto), (vfrom), PAGE_SIZE) 844b87d7a4SMichal Simek 854b87d7a4SMichal Simek /* 864b87d7a4SMichal Simek * These are used to make use of C type-checking.. 874b87d7a4SMichal Simek */ 884b87d7a4SMichal Simek typedef struct page *pgtable_t; 894b87d7a4SMichal Simek typedef struct { unsigned long pte; } pte_t; 904b87d7a4SMichal Simek typedef struct { unsigned long pgprot; } pgprot_t; 911f84e1eaSMichal Simek /* FIXME this can depend on linux kernel version */ 921f84e1eaSMichal Simek # ifdef CONFIG_MMU 931f84e1eaSMichal Simek typedef struct { unsigned long pmd; } pmd_t; 941f84e1eaSMichal Simek typedef struct { unsigned long pgd; } pgd_t; 951f84e1eaSMichal Simek # else /* CONFIG_MMU */ 964b87d7a4SMichal Simek typedef struct { unsigned long ste[64]; } pmd_t; 974b87d7a4SMichal Simek typedef struct { pmd_t pue[1]; } pud_t; 984b87d7a4SMichal Simek typedef struct { pud_t pge[1]; } pgd_t; 991f84e1eaSMichal Simek # endif /* CONFIG_MMU */ 1004b87d7a4SMichal Simek 1014b87d7a4SMichal Simek # define pte_val(x) ((x).pte) 1024b87d7a4SMichal Simek # define pgprot_val(x) ((x).pgprot) 1031f84e1eaSMichal Simek 1041f84e1eaSMichal Simek # ifdef CONFIG_MMU 1051f84e1eaSMichal Simek # define pmd_val(x) ((x).pmd) 1061f84e1eaSMichal Simek # define pgd_val(x) ((x).pgd) 1071f84e1eaSMichal Simek # else /* CONFIG_MMU */ 1084b87d7a4SMichal Simek # define pmd_val(x) ((x).ste[0]) 1094b87d7a4SMichal Simek # define pud_val(x) ((x).pue[0]) 1104b87d7a4SMichal Simek # define pgd_val(x) ((x).pge[0]) 1111f84e1eaSMichal Simek # endif /* CONFIG_MMU */ 1124b87d7a4SMichal Simek 1134b87d7a4SMichal Simek # define __pte(x) ((pte_t) { (x) }) 1144b87d7a4SMichal Simek # define __pmd(x) ((pmd_t) { (x) }) 1154b87d7a4SMichal Simek # define __pgd(x) ((pgd_t) { (x) }) 1164b87d7a4SMichal Simek # define __pgprot(x) ((pgprot_t) { (x) }) 1174b87d7a4SMichal Simek 1184b87d7a4SMichal Simek /** 1194b87d7a4SMichal Simek * Conversions for virtual address, physical address, pfn, and struct 1204b87d7a4SMichal Simek * page are defined in the following files. 1214b87d7a4SMichal Simek * 1224b87d7a4SMichal Simek * virt -+ 1234b87d7a4SMichal Simek * | asm-microblaze/page.h 1244b87d7a4SMichal Simek * phys -+ 1254b87d7a4SMichal Simek * | linux/pfn.h 1264b87d7a4SMichal Simek * pfn -+ 1274b87d7a4SMichal Simek * | asm-generic/memory_model.h 1284b87d7a4SMichal Simek * page -+ 1294b87d7a4SMichal Simek * 1304b87d7a4SMichal Simek */ 1314b87d7a4SMichal Simek 1324b87d7a4SMichal Simek extern unsigned long max_low_pfn; 1334b87d7a4SMichal Simek extern unsigned long min_low_pfn; 1344b87d7a4SMichal Simek extern unsigned long max_pfn; 1354b87d7a4SMichal Simek 1361f84e1eaSMichal Simek extern unsigned long memory_start; 1371f84e1eaSMichal Simek extern unsigned long memory_end; 1381f84e1eaSMichal Simek extern unsigned long memory_size; 1391f84e1eaSMichal Simek 1401f84e1eaSMichal Simek extern int page_is_ram(unsigned long pfn); 1414b87d7a4SMichal Simek 1424b87d7a4SMichal Simek # define phys_to_pfn(phys) (PFN_DOWN(phys)) 1434b87d7a4SMichal Simek # define pfn_to_phys(pfn) (PFN_PHYS(pfn)) 1444b87d7a4SMichal Simek 1454b87d7a4SMichal Simek # define virt_to_pfn(vaddr) (phys_to_pfn((__pa(vaddr)))) 1464b87d7a4SMichal Simek # define pfn_to_virt(pfn) __va(pfn_to_phys((pfn))) 1474b87d7a4SMichal Simek 1481f84e1eaSMichal Simek # ifdef CONFIG_MMU 149d79f3b06SMichal Simek 150d79f3b06SMichal Simek # define virt_to_page(kaddr) (pfn_to_page(__pa(kaddr) >> PAGE_SHIFT)) 151d79f3b06SMichal Simek # define page_to_virt(page) __va(page_to_pfn(page) << PAGE_SHIFT) 152d79f3b06SMichal Simek # define page_to_phys(page) (page_to_pfn(page) << PAGE_SHIFT) 153d79f3b06SMichal Simek 1541f84e1eaSMichal Simek # else /* CONFIG_MMU */ 1554b87d7a4SMichal Simek # define virt_to_page(vaddr) (pfn_to_page(virt_to_pfn(vaddr))) 1564b87d7a4SMichal Simek # define page_to_virt(page) (pfn_to_virt(page_to_pfn(page))) 1574b87d7a4SMichal Simek # define page_to_phys(page) (pfn_to_phys(page_to_pfn(page))) 1584b87d7a4SMichal Simek # define page_to_bus(page) (page_to_phys(page)) 1594b87d7a4SMichal Simek # define phys_to_page(paddr) (pfn_to_page(phys_to_pfn(paddr))) 1601f84e1eaSMichal Simek # endif /* CONFIG_MMU */ 1614b87d7a4SMichal Simek 1621f84e1eaSMichal Simek # ifndef CONFIG_MMU 1635dd48a23Ssteve@digidescorp.com # define pfn_valid(pfn) (((pfn) >= min_low_pfn) && \ 1645dd48a23Ssteve@digidescorp.com ((pfn) <= (min_low_pfn + max_mapnr))) 1654b87d7a4SMichal Simek # define ARCH_PFN_OFFSET (PAGE_OFFSET >> PAGE_SHIFT) 1661f84e1eaSMichal Simek # else /* CONFIG_MMU */ 1671f84e1eaSMichal Simek # define ARCH_PFN_OFFSET (memory_start >> PAGE_SHIFT) 1681f84e1eaSMichal Simek # define pfn_valid(pfn) ((pfn) < (max_mapnr + ARCH_PFN_OFFSET)) 1691f84e1eaSMichal Simek # define VALID_PAGE(page) ((page - mem_map) < max_mapnr) 1701f84e1eaSMichal Simek # endif /* CONFIG_MMU */ 1714b87d7a4SMichal Simek 1724b87d7a4SMichal Simek # endif /* __ASSEMBLY__ */ 1734b87d7a4SMichal Simek 1744b87d7a4SMichal Simek #define virt_addr_valid(vaddr) (pfn_valid(virt_to_pfn(vaddr))) 1754b87d7a4SMichal Simek 1761f84e1eaSMichal Simek 1771f84e1eaSMichal Simek # ifndef CONFIG_MMU 1781f84e1eaSMichal Simek # define __pa(vaddr) ((unsigned long) (vaddr)) 1791f84e1eaSMichal Simek # define __va(paddr) ((void *) (paddr)) 1801f84e1eaSMichal Simek # else /* CONFIG_MMU */ 1811f84e1eaSMichal Simek # define __pa(x) __virt_to_phys((unsigned long)(x)) 1821f84e1eaSMichal Simek # define __va(x) ((void *)__phys_to_virt((unsigned long)(x))) 1831f84e1eaSMichal Simek # endif /* CONFIG_MMU */ 1841f84e1eaSMichal Simek 1851f84e1eaSMichal Simek 1864b87d7a4SMichal Simek /* Convert between virtual and physical address for MMU. */ 1874b87d7a4SMichal Simek /* Handle MicroBlaze processor with virtual memory. */ 1881f84e1eaSMichal Simek #ifndef CONFIG_MMU 1894b87d7a4SMichal Simek #define __virt_to_phys(addr) addr 1904b87d7a4SMichal Simek #define __phys_to_virt(addr) addr 1911f84e1eaSMichal Simek #define tophys(rd, rs) addik rd, rs, 0 1921f84e1eaSMichal Simek #define tovirt(rd, rs) addik rd, rs, 0 1931f84e1eaSMichal Simek #else 1941f84e1eaSMichal Simek #define __virt_to_phys(addr) \ 1951f84e1eaSMichal Simek ((addr) + CONFIG_KERNEL_BASE_ADDR - CONFIG_KERNEL_START) 1961f84e1eaSMichal Simek #define __phys_to_virt(addr) \ 1971f84e1eaSMichal Simek ((addr) + CONFIG_KERNEL_START - CONFIG_KERNEL_BASE_ADDR) 1981f84e1eaSMichal Simek #define tophys(rd, rs) \ 1991f84e1eaSMichal Simek addik rd, rs, (CONFIG_KERNEL_BASE_ADDR - CONFIG_KERNEL_START) 2001f84e1eaSMichal Simek #define tovirt(rd, rs) \ 2011f84e1eaSMichal Simek addik rd, rs, (CONFIG_KERNEL_START - CONFIG_KERNEL_BASE_ADDR) 2021f84e1eaSMichal Simek #endif /* CONFIG_MMU */ 2034b87d7a4SMichal Simek 2044b87d7a4SMichal Simek #define TOPHYS(addr) __virt_to_phys(addr) 2054b87d7a4SMichal Simek 2061f84e1eaSMichal Simek #ifdef CONFIG_MMU 2071f84e1eaSMichal Simek #ifdef CONFIG_CONTIGUOUS_PAGE_ALLOC 2081f84e1eaSMichal Simek #define WANT_PAGE_VIRTUAL 1 /* page alloc 2 relies on this */ 2091f84e1eaSMichal Simek #endif 2101f84e1eaSMichal Simek 2111f84e1eaSMichal Simek #define VM_DATA_DEFAULT_FLAGS (VM_READ | VM_WRITE | VM_EXEC | \ 2121f84e1eaSMichal Simek VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC) 2131f84e1eaSMichal Simek #endif /* CONFIG_MMU */ 2141f84e1eaSMichal Simek 2154b87d7a4SMichal Simek #endif /* __KERNEL__ */ 2164b87d7a4SMichal Simek 2174b87d7a4SMichal Simek #include <asm-generic/memory_model.h> 2185b17e1cdSArnd Bergmann #include <asm-generic/getorder.h> 2194b87d7a4SMichal Simek 2204b87d7a4SMichal Simek #endif /* _ASM_MICROBLAZE_PAGE_H */ 221