14baa9922SRussell King /* 24baa9922SRussell King * arch/arm/include/asm/memory.h 34baa9922SRussell King * 44baa9922SRussell King * Copyright (C) 2000-2002 Russell King 54baa9922SRussell King * modification for nommu, Hyok S. Choi, 2004 64baa9922SRussell King * 74baa9922SRussell King * This program is free software; you can redistribute it and/or modify 84baa9922SRussell King * it under the terms of the GNU General Public License version 2 as 94baa9922SRussell King * published by the Free Software Foundation. 104baa9922SRussell King * 114baa9922SRussell King * Note: this file should not be included by non-asm/.h files 124baa9922SRussell King */ 134baa9922SRussell King #ifndef __ASM_ARM_MEMORY_H 144baa9922SRussell King #define __ASM_ARM_MEMORY_H 154baa9922SRussell King 168d5796d2SLennert Buytenhek #include <linux/compiler.h> 178d5796d2SLennert Buytenhek #include <linux/const.h> 183a6b1676SWill Deacon #include <linux/types.h> 19158e8bfeSAlessandro Rubini #include <linux/sizes.h> 208d5796d2SLennert Buytenhek 214756dcbfSCyril Chemparathy #include <asm/cache.h> 224756dcbfSCyril Chemparathy 230cdc8b92SNicolas Pitre #ifdef CONFIG_NEED_MACH_MEMORY_H 241b9f95f8SNicolas Pitre #include <mach/memory.h> 251b9f95f8SNicolas Pitre #endif 261b9f95f8SNicolas Pitre 274baa9922SRussell King /* 284baa9922SRussell King * Allow for constants defined here to be used from assembly code 294baa9922SRussell King * by prepending the UL suffix only with actual C code compilation. 304baa9922SRussell King */ 318d5796d2SLennert Buytenhek #define UL(x) _AC(x, UL) 324baa9922SRussell King 334baa9922SRussell King #ifdef CONFIG_MMU 344baa9922SRussell King 354baa9922SRussell King /* 368d5796d2SLennert Buytenhek * PAGE_OFFSET - the virtual address of the start of the kernel image 374baa9922SRussell King * TASK_SIZE - the maximum size of a user space task. 384baa9922SRussell King * TASK_UNMAPPED_BASE - the lower boundary of the mmap VM area 394baa9922SRussell King */ 408d5796d2SLennert Buytenhek #define PAGE_OFFSET UL(CONFIG_PAGE_OFFSET) 415d1c20bcSWill Deacon #define TASK_SIZE (UL(CONFIG_PAGE_OFFSET) - UL(SZ_16M)) 4279d1f5c9SWill Deacon #define TASK_UNMAPPED_BASE ALIGN(TASK_SIZE / 3, SZ_16M) 434baa9922SRussell King 444baa9922SRussell King /* 454baa9922SRussell King * The maximum size of a 26-bit user space task. 464baa9922SRussell King */ 475d1c20bcSWill Deacon #define TASK_SIZE_26 (UL(1) << 26) 484baa9922SRussell King 494baa9922SRussell King /* 504baa9922SRussell King * The module space lives between the addresses given by TASK_SIZE 514baa9922SRussell King * and PAGE_OFFSET - it must be within 32MB of the kernel text. 524baa9922SRussell King */ 53adca6dc2SCatalin Marinas #ifndef CONFIG_THUMB2_KERNEL 545d1c20bcSWill Deacon #define MODULES_VADDR (PAGE_OFFSET - SZ_16M) 55adca6dc2SCatalin Marinas #else 56adca6dc2SCatalin Marinas /* smaller range for Thumb-2 symbols relocation (2^24)*/ 575d1c20bcSWill Deacon #define MODULES_VADDR (PAGE_OFFSET - SZ_8M) 58adca6dc2SCatalin Marinas #endif 59adca6dc2SCatalin Marinas 60ab4f2ee1SRussell King #if TASK_SIZE > MODULES_VADDR 614baa9922SRussell King #error Top of user space clashes with start of module space 624baa9922SRussell King #endif 634baa9922SRussell King 644baa9922SRussell King /* 65d73cd428SNicolas Pitre * The highmem pkmap virtual space shares the end of the module area. 66d73cd428SNicolas Pitre */ 67d73cd428SNicolas Pitre #ifdef CONFIG_HIGHMEM 68d73cd428SNicolas Pitre #define MODULES_END (PAGE_OFFSET - PMD_SIZE) 69d73cd428SNicolas Pitre #else 70d73cd428SNicolas Pitre #define MODULES_END (PAGE_OFFSET) 71d73cd428SNicolas Pitre #endif 72d73cd428SNicolas Pitre 73d73cd428SNicolas Pitre /* 744baa9922SRussell King * The XIP kernel gets mapped at the bottom of the module vm area. 754baa9922SRussell King * Since we use sections to map it, this macro replaces the physical address 764baa9922SRussell King * with its virtual address while keeping offset from the base section. 774baa9922SRussell King */ 78ab4f2ee1SRussell King #define XIP_VIRT_ADDR(physaddr) (MODULES_VADDR + ((physaddr) & 0x000fffff)) 794baa9922SRussell King 804baa9922SRussell King /* 814baa9922SRussell King * Allow 16MB-aligned ioremap pages 824baa9922SRussell King */ 834baa9922SRussell King #define IOREMAP_MAX_ORDER 24 844baa9922SRussell King 85a7bd08c8SFenkart/Bostandzhyan #define CONSISTENT_END (0xffe00000UL) 86a7bd08c8SFenkart/Bostandzhyan 874baa9922SRussell King #else /* CONFIG_MMU */ 884baa9922SRussell King 894baa9922SRussell King /* 904baa9922SRussell King * The limitation of user task size can grow up to the end of free ram region. 914baa9922SRussell King * It is difficult to define and perhaps will never meet the original meaning 924baa9922SRussell King * of this define that was meant to. 934baa9922SRussell King * Fortunately, there is no reference for this in noMMU mode, for now. 944baa9922SRussell King */ 954baa9922SRussell King #ifndef TASK_SIZE 964baa9922SRussell King #define TASK_SIZE (CONFIG_DRAM_SIZE) 974baa9922SRussell King #endif 984baa9922SRussell King 994baa9922SRussell King #ifndef TASK_UNMAPPED_BASE 1004baa9922SRussell King #define TASK_UNMAPPED_BASE UL(0x00000000) 1014baa9922SRussell King #endif 1024baa9922SRussell King 1034baa9922SRussell King #ifndef END_MEM 104c931b4f6SFenkart/Bostandzhyan #define END_MEM (UL(CONFIG_DRAM_BASE) + CONFIG_DRAM_SIZE) 1054baa9922SRussell King #endif 1064baa9922SRussell King 1074baa9922SRussell King #ifndef PAGE_OFFSET 108b713aa0bSRussell King #define PAGE_OFFSET PLAT_PHYS_OFFSET 1094baa9922SRussell King #endif 1104baa9922SRussell King 1114baa9922SRussell King /* 1124baa9922SRussell King * The module can be at any place in ram in nommu mode. 1134baa9922SRussell King */ 114ab4f2ee1SRussell King #define MODULES_END (END_MEM) 115b713aa0bSRussell King #define MODULES_VADDR PAGE_OFFSET 1164baa9922SRussell King 11738b4205aSUwe Kleine-König #define XIP_VIRT_ADDR(physaddr) (physaddr) 11838b4205aSUwe Kleine-König 1194baa9922SRussell King #endif /* !CONFIG_MMU */ 1204baa9922SRussell King 1214baa9922SRussell King /* 1221dbd30e9SLinus Walleij * We fix the TCM memories max 32 KiB ITCM resp DTCM at these 1231dbd30e9SLinus Walleij * locations 1241dbd30e9SLinus Walleij */ 1251dbd30e9SLinus Walleij #ifdef CONFIG_HAVE_TCM 1261dbd30e9SLinus Walleij #define ITCM_OFFSET UL(0xfffe0000) 1271dbd30e9SLinus Walleij #define DTCM_OFFSET UL(0xfffe8000) 1281dbd30e9SLinus Walleij #endif 1291dbd30e9SLinus Walleij 1301dbd30e9SLinus Walleij /* 1314baa9922SRussell King * Convert a physical address to a Page Frame Number and back 1324baa9922SRussell King */ 1333a6b1676SWill Deacon #define __phys_to_pfn(paddr) ((unsigned long)((paddr) >> PAGE_SHIFT)) 1343a6b1676SWill Deacon #define __pfn_to_phys(pfn) ((phys_addr_t)(pfn) << PAGE_SHIFT) 1354baa9922SRussell King 136719301ffSRussell King /* 137719301ffSRussell King * Convert a page to/from a physical address 138719301ffSRussell King */ 139719301ffSRussell King #define page_to_phys(page) (__pfn_to_phys(page_to_pfn(page))) 140719301ffSRussell King #define phys_to_page(phys) (pfn_to_page(__phys_to_pfn(phys))) 141719301ffSRussell King 1424756dcbfSCyril Chemparathy /* 1434756dcbfSCyril Chemparathy * Minimum guaranted alignment in pgd_alloc(). The page table pointers passed 1444756dcbfSCyril Chemparathy * around in head.S and proc-*.S are shifted by this amount, in order to 1454756dcbfSCyril Chemparathy * leave spare high bits for systems with physical address extension. This 1464756dcbfSCyril Chemparathy * does not fully accomodate the 40-bit addressing capability of ARM LPAE, but 1474756dcbfSCyril Chemparathy * gives us about 38-bits or so. 1484756dcbfSCyril Chemparathy */ 1494756dcbfSCyril Chemparathy #ifdef CONFIG_ARM_LPAE 1504756dcbfSCyril Chemparathy #define ARCH_PGD_SHIFT L1_CACHE_SHIFT 1514756dcbfSCyril Chemparathy #else 1524756dcbfSCyril Chemparathy #define ARCH_PGD_SHIFT 0 1534756dcbfSCyril Chemparathy #endif 1544756dcbfSCyril Chemparathy #define ARCH_PGD_MASK ((1 << ARCH_PGD_SHIFT) - 1) 1554756dcbfSCyril Chemparathy 156b713aa0bSRussell King /* 157b713aa0bSRussell King * PLAT_PHYS_OFFSET is the offset (from zero) of the start of physical 158b713aa0bSRussell King * memory. This is used for XIP and NoMMU kernels, or by kernels which 159b713aa0bSRussell King * have their own mach/memory.h. Assembly code must always use 160b713aa0bSRussell King * PLAT_PHYS_OFFSET and not PHYS_OFFSET. 161b713aa0bSRussell King */ 162b713aa0bSRussell King #ifndef PLAT_PHYS_OFFSET 163b713aa0bSRussell King #define PLAT_PHYS_OFFSET UL(CONFIG_PHYS_OFFSET) 164b713aa0bSRussell King #endif 165b713aa0bSRussell King 1664baa9922SRussell King #ifndef __ASSEMBLY__ 1674baa9922SRussell King 1684baa9922SRussell King /* 169dc21af99SRussell King * Physical vs virtual RAM address space conversion. These are 170dc21af99SRussell King * private definitions which should NOT be used outside memory.h 171dc21af99SRussell King * files. Use virt_to_phys/phys_to_virt/__pa/__va instead. 172dc21af99SRussell King */ 173dc21af99SRussell King #ifndef __virt_to_phys 174dc21af99SRussell King #ifdef CONFIG_ARM_PATCH_PHYS_VIRT 175dc21af99SRussell King 176cada3c08SRussell King /* 177cada3c08SRussell King * Constants used to force the right instruction encodings and shifts 178cada3c08SRussell King * so that all we need to do is modify the 8-bit constant field. 179cada3c08SRussell King */ 180cada3c08SRussell King #define __PV_BITS_31_24 0x81000000 181f52bb722SSricharan R #define __PV_BITS_7_0 0x81 182cada3c08SRussell King 183f52bb722SSricharan R extern u64 __pv_phys_offset; 184f52bb722SSricharan R extern u64 __pv_offset; 185f52bb722SSricharan R extern void fixup_pv_table(const void *, unsigned long); 186f52bb722SSricharan R extern const void *__pv_table_begin, *__pv_table_end; 187f52bb722SSricharan R 188dc21af99SRussell King #define PHYS_OFFSET __pv_phys_offset 189dc21af99SRussell King 190cada3c08SRussell King #define __pv_stub(from,to,instr,type) \ 191dc21af99SRussell King __asm__("@ __pv_stub\n" \ 192dc21af99SRussell King "1: " instr " %0, %1, %2\n" \ 193dc21af99SRussell King " .pushsection .pv_table,\"a\"\n" \ 194dc21af99SRussell King " .long 1b\n" \ 195dc21af99SRussell King " .popsection\n" \ 196dc21af99SRussell King : "=r" (to) \ 197cada3c08SRussell King : "r" (from), "I" (type)) 198dc21af99SRussell King 199f52bb722SSricharan R #define __pv_stub_mov_hi(t) \ 200f52bb722SSricharan R __asm__ volatile("@ __pv_stub_mov\n" \ 201f52bb722SSricharan R "1: mov %R0, %1\n" \ 202f52bb722SSricharan R " .pushsection .pv_table,\"a\"\n" \ 203f52bb722SSricharan R " .long 1b\n" \ 204f52bb722SSricharan R " .popsection\n" \ 205f52bb722SSricharan R : "=r" (t) \ 206f52bb722SSricharan R : "I" (__PV_BITS_7_0)) 207f52bb722SSricharan R 208f52bb722SSricharan R #define __pv_add_carry_stub(x, y) \ 209f52bb722SSricharan R __asm__ volatile("@ __pv_add_carry_stub\n" \ 210f52bb722SSricharan R "1: adds %Q0, %1, %2\n" \ 211f52bb722SSricharan R " adc %R0, %R0, #0\n" \ 212f52bb722SSricharan R " .pushsection .pv_table,\"a\"\n" \ 213f52bb722SSricharan R " .long 1b\n" \ 214f52bb722SSricharan R " .popsection\n" \ 215f52bb722SSricharan R : "+r" (y) \ 216f52bb722SSricharan R : "r" (x), "I" (__PV_BITS_31_24) \ 217f52bb722SSricharan R : "cc") 218f52bb722SSricharan R 219ca5a45c0SSantosh Shilimkar static inline phys_addr_t __virt_to_phys(unsigned long x) 220dc21af99SRussell King { 221f52bb722SSricharan R phys_addr_t t; 222f52bb722SSricharan R 223f52bb722SSricharan R if (sizeof(phys_addr_t) == 4) { 224cada3c08SRussell King __pv_stub(x, t, "add", __PV_BITS_31_24); 225f52bb722SSricharan R } else { 226f52bb722SSricharan R __pv_stub_mov_hi(t); 227f52bb722SSricharan R __pv_add_carry_stub(x, t); 228f52bb722SSricharan R } 229dc21af99SRussell King return t; 230dc21af99SRussell King } 231dc21af99SRussell King 232ca5a45c0SSantosh Shilimkar static inline unsigned long __phys_to_virt(phys_addr_t x) 233dc21af99SRussell King { 234dc21af99SRussell King unsigned long t; 235139cc2baSVictor Kamensky 236139cc2baSVictor Kamensky /* 237139cc2baSVictor Kamensky * 'unsigned long' cast discard upper word when 238139cc2baSVictor Kamensky * phys_addr_t is 64 bit, and makes sure that inline 239139cc2baSVictor Kamensky * assembler expression receives 32 bit argument 240139cc2baSVictor Kamensky * in place where 'r' 32 bit operand is expected. 241139cc2baSVictor Kamensky */ 242139cc2baSVictor Kamensky __pv_stub((unsigned long) x, t, "sub", __PV_BITS_31_24); 243dc21af99SRussell King return t; 244dc21af99SRussell King } 245ca5a45c0SSantosh Shilimkar 246dc21af99SRussell King #else 247ca5a45c0SSantosh Shilimkar 248b713aa0bSRussell King #define PHYS_OFFSET PLAT_PHYS_OFFSET 249b713aa0bSRussell King 250ca5a45c0SSantosh Shilimkar static inline phys_addr_t __virt_to_phys(unsigned long x) 251ca5a45c0SSantosh Shilimkar { 252ca5a45c0SSantosh Shilimkar return (phys_addr_t)x - PAGE_OFFSET + PHYS_OFFSET; 253ca5a45c0SSantosh Shilimkar } 254ca5a45c0SSantosh Shilimkar 255ca5a45c0SSantosh Shilimkar static inline unsigned long __phys_to_virt(phys_addr_t x) 256ca5a45c0SSantosh Shilimkar { 257ca5a45c0SSantosh Shilimkar return x - PHYS_OFFSET + PAGE_OFFSET; 258ca5a45c0SSantosh Shilimkar } 259ca5a45c0SSantosh Shilimkar 260dc21af99SRussell King #endif 261dc21af99SRussell King #endif 262b4ad5155SStephen Boyd 263dc21af99SRussell King /* 2644baa9922SRussell King * PFNs are used to describe any physical page; this means 2654baa9922SRussell King * PFN 0 == physical address 0. 2664baa9922SRussell King * 2674baa9922SRussell King * This is the PFN of the first RAM page in the kernel 2684baa9922SRussell King * direct-mapped view. We assume this is the first page 2694baa9922SRussell King * of RAM in the mem_map as well. 2704baa9922SRussell King */ 2715b20c5b2SCyril Chemparathy #define PHYS_PFN_OFFSET ((unsigned long)(PHYS_OFFSET >> PAGE_SHIFT)) 2724baa9922SRussell King 2734baa9922SRussell King /* 2744baa9922SRussell King * These are *only* valid on the kernel direct mapped RAM memory. 2754baa9922SRussell King * Note: Drivers should NOT use these. They are the wrong 2764baa9922SRussell King * translation for translating DMA addresses. Use the driver 2774baa9922SRussell King * DMA support - see dma-mapping.h. 2784baa9922SRussell King */ 2793a6b1676SWill Deacon static inline phys_addr_t virt_to_phys(const volatile void *x) 2804baa9922SRussell King { 2814baa9922SRussell King return __virt_to_phys((unsigned long)(x)); 2824baa9922SRussell King } 2834baa9922SRussell King 2843a6b1676SWill Deacon static inline void *phys_to_virt(phys_addr_t x) 2854baa9922SRussell King { 286ca5a45c0SSantosh Shilimkar return (void *)__phys_to_virt(x); 2874baa9922SRussell King } 2884baa9922SRussell King 2894baa9922SRussell King /* 2904baa9922SRussell King * Drivers should NOT use these either. 2914baa9922SRussell King */ 2924baa9922SRussell King #define __pa(x) __virt_to_phys((unsigned long)(x)) 293ca5a45c0SSantosh Shilimkar #define __va(x) ((void *)__phys_to_virt((phys_addr_t)(x))) 2944baa9922SRussell King #define pfn_to_kaddr(pfn) __va((pfn) << PAGE_SHIFT) 2954baa9922SRussell King 2965e4432d3SRussell King extern phys_addr_t (*arch_virt_to_idmap)(unsigned long x); 2975e4432d3SRussell King 2984baa9922SRussell King /* 2994dc9a817SSantosh Shilimkar * These are for systems that have a hardware interconnect supported alias of 3004dc9a817SSantosh Shilimkar * physical memory for idmap purposes. Most cases should leave these 3014dc9a817SSantosh Shilimkar * untouched. 3024dc9a817SSantosh Shilimkar */ 3034dc9a817SSantosh Shilimkar static inline phys_addr_t __virt_to_idmap(unsigned long x) 3044dc9a817SSantosh Shilimkar { 3054dc9a817SSantosh Shilimkar if (arch_virt_to_idmap) 3064dc9a817SSantosh Shilimkar return arch_virt_to_idmap(x); 3074dc9a817SSantosh Shilimkar else 3084dc9a817SSantosh Shilimkar return __virt_to_phys(x); 3094dc9a817SSantosh Shilimkar } 3104dc9a817SSantosh Shilimkar 3114dc9a817SSantosh Shilimkar #define virt_to_idmap(x) __virt_to_idmap((unsigned long)(x)) 3124dc9a817SSantosh Shilimkar 3134dc9a817SSantosh Shilimkar /* 3144baa9922SRussell King * Virtual <-> DMA view memory address translations 3154baa9922SRussell King * Again, these are *only* valid on the kernel direct mapped RAM 3164baa9922SRussell King * memory. Use of these is *deprecated* (and that doesn't mean 3174baa9922SRussell King * use the __ prefixed forms instead.) See dma-mapping.h. 3184baa9922SRussell King */ 319b5ee9002SNicolas Pitre #ifndef __virt_to_bus 320b5ee9002SNicolas Pitre #define __virt_to_bus __virt_to_phys 321b5ee9002SNicolas Pitre #define __bus_to_virt __phys_to_virt 3221c4a4f48SRussell King #define __pfn_to_bus(x) __pfn_to_phys(x) 3231c4a4f48SRussell King #define __bus_to_pfn(x) __phys_to_pfn(x) 324b5ee9002SNicolas Pitre #endif 325b5ee9002SNicolas Pitre 326a5d533eeSArnd Bergmann #ifdef CONFIG_VIRT_TO_BUS 3274baa9922SRussell King static inline __deprecated unsigned long virt_to_bus(void *x) 3284baa9922SRussell King { 3294baa9922SRussell King return __virt_to_bus((unsigned long)x); 3304baa9922SRussell King } 3314baa9922SRussell King 3324baa9922SRussell King static inline __deprecated void *bus_to_virt(unsigned long x) 3334baa9922SRussell King { 3344baa9922SRussell King return (void *)__bus_to_virt(x); 3354baa9922SRussell King } 336a5d533eeSArnd Bergmann #endif 3374baa9922SRussell King 3384baa9922SRussell King /* 3394baa9922SRussell King * Conversion between a struct page and a physical address. 3404baa9922SRussell King * 3414baa9922SRussell King * page_to_pfn(page) convert a struct page * to a PFN number 3424baa9922SRussell King * pfn_to_page(pfn) convert a _valid_ PFN number to struct page * 3434baa9922SRussell King * 3444baa9922SRussell King * virt_to_page(k) convert a _valid_ virtual address to struct page * 3454baa9922SRussell King * virt_addr_valid(k) indicates whether a virtual address is valid 3464baa9922SRussell King */ 3474baa9922SRussell King #define ARCH_PFN_OFFSET PHYS_PFN_OFFSET 3484baa9922SRussell King 3494baa9922SRussell King #define virt_to_page(kaddr) pfn_to_page(__pa(kaddr) >> PAGE_SHIFT) 350efea3403SLaura Abbott #define virt_addr_valid(kaddr) (((unsigned long)(kaddr) >= PAGE_OFFSET && (unsigned long)(kaddr) < (unsigned long)high_memory) \ 351efea3403SLaura Abbott && pfn_valid(__pa(kaddr) >> PAGE_SHIFT) ) 3524baa9922SRussell King 3534baa9922SRussell King #endif 3544baa9922SRussell King 3554baa9922SRussell King #include <asm-generic/memory_model.h> 3564baa9922SRussell King 3574baa9922SRussell King #endif 358