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> 198d5796d2SLennert Buytenhek #include <asm/sizes.h> 208d5796d2SLennert Buytenhek 210cdc8b92SNicolas Pitre #ifdef CONFIG_NEED_MACH_MEMORY_H 221b9f95f8SNicolas Pitre #include <mach/memory.h> 231b9f95f8SNicolas Pitre #endif 241b9f95f8SNicolas Pitre 254baa9922SRussell King /* 264baa9922SRussell King * Allow for constants defined here to be used from assembly code 274baa9922SRussell King * by prepending the UL suffix only with actual C code compilation. 284baa9922SRussell King */ 298d5796d2SLennert Buytenhek #define UL(x) _AC(x, UL) 304baa9922SRussell King 314baa9922SRussell King #ifdef CONFIG_MMU 324baa9922SRussell King 334baa9922SRussell King /* 348d5796d2SLennert Buytenhek * PAGE_OFFSET - the virtual address of the start of the kernel image 354baa9922SRussell King * TASK_SIZE - the maximum size of a user space task. 364baa9922SRussell King * TASK_UNMAPPED_BASE - the lower boundary of the mmap VM area 374baa9922SRussell King */ 388d5796d2SLennert Buytenhek #define PAGE_OFFSET UL(CONFIG_PAGE_OFFSET) 398d5796d2SLennert Buytenhek #define TASK_SIZE (UL(CONFIG_PAGE_OFFSET) - UL(0x01000000)) 408d5796d2SLennert Buytenhek #define TASK_UNMAPPED_BASE (UL(CONFIG_PAGE_OFFSET) / 3) 414baa9922SRussell King 424baa9922SRussell King /* 434baa9922SRussell King * The maximum size of a 26-bit user space task. 444baa9922SRussell King */ 454baa9922SRussell King #define TASK_SIZE_26 UL(0x04000000) 464baa9922SRussell King 474baa9922SRussell King /* 484baa9922SRussell King * The module space lives between the addresses given by TASK_SIZE 494baa9922SRussell King * and PAGE_OFFSET - it must be within 32MB of the kernel text. 504baa9922SRussell King */ 51adca6dc2SCatalin Marinas #ifndef CONFIG_THUMB2_KERNEL 52d73cd428SNicolas Pitre #define MODULES_VADDR (PAGE_OFFSET - 16*1024*1024) 53adca6dc2SCatalin Marinas #else 54adca6dc2SCatalin Marinas /* smaller range for Thumb-2 symbols relocation (2^24)*/ 55adca6dc2SCatalin Marinas #define MODULES_VADDR (PAGE_OFFSET - 8*1024*1024) 56adca6dc2SCatalin Marinas #endif 57adca6dc2SCatalin Marinas 58ab4f2ee1SRussell King #if TASK_SIZE > MODULES_VADDR 594baa9922SRussell King #error Top of user space clashes with start of module space 604baa9922SRussell King #endif 614baa9922SRussell King 624baa9922SRussell King /* 63d73cd428SNicolas Pitre * The highmem pkmap virtual space shares the end of the module area. 64d73cd428SNicolas Pitre */ 65d73cd428SNicolas Pitre #ifdef CONFIG_HIGHMEM 66d73cd428SNicolas Pitre #define MODULES_END (PAGE_OFFSET - PMD_SIZE) 67d73cd428SNicolas Pitre #else 68d73cd428SNicolas Pitre #define MODULES_END (PAGE_OFFSET) 69d73cd428SNicolas Pitre #endif 70d73cd428SNicolas Pitre 71d73cd428SNicolas Pitre /* 724baa9922SRussell King * The XIP kernel gets mapped at the bottom of the module vm area. 734baa9922SRussell King * Since we use sections to map it, this macro replaces the physical address 744baa9922SRussell King * with its virtual address while keeping offset from the base section. 754baa9922SRussell King */ 76ab4f2ee1SRussell King #define XIP_VIRT_ADDR(physaddr) (MODULES_VADDR + ((physaddr) & 0x000fffff)) 774baa9922SRussell King 784baa9922SRussell King /* 794baa9922SRussell King * Allow 16MB-aligned ioremap pages 804baa9922SRussell King */ 814baa9922SRussell King #define IOREMAP_MAX_ORDER 24 824baa9922SRussell King 83a7bd08c8SFenkart/Bostandzhyan #define CONSISTENT_END (0xffe00000UL) 84a7bd08c8SFenkart/Bostandzhyan 854baa9922SRussell King #else /* CONFIG_MMU */ 864baa9922SRussell King 874baa9922SRussell King /* 884baa9922SRussell King * The limitation of user task size can grow up to the end of free ram region. 894baa9922SRussell King * It is difficult to define and perhaps will never meet the original meaning 904baa9922SRussell King * of this define that was meant to. 914baa9922SRussell King * Fortunately, there is no reference for this in noMMU mode, for now. 924baa9922SRussell King */ 934baa9922SRussell King #ifndef TASK_SIZE 944baa9922SRussell King #define TASK_SIZE (CONFIG_DRAM_SIZE) 954baa9922SRussell King #endif 964baa9922SRussell King 974baa9922SRussell King #ifndef TASK_UNMAPPED_BASE 984baa9922SRussell King #define TASK_UNMAPPED_BASE UL(0x00000000) 994baa9922SRussell King #endif 1004baa9922SRussell King 1014baa9922SRussell King #ifndef PHYS_OFFSET 102c931b4f6SFenkart/Bostandzhyan #define PHYS_OFFSET UL(CONFIG_DRAM_BASE) 1034baa9922SRussell King #endif 1044baa9922SRussell King 1054baa9922SRussell King #ifndef END_MEM 106c931b4f6SFenkart/Bostandzhyan #define END_MEM (UL(CONFIG_DRAM_BASE) + CONFIG_DRAM_SIZE) 1074baa9922SRussell King #endif 1084baa9922SRussell King 1094baa9922SRussell King #ifndef PAGE_OFFSET 1104baa9922SRussell King #define PAGE_OFFSET (PHYS_OFFSET) 1114baa9922SRussell King #endif 1124baa9922SRussell King 1134baa9922SRussell King /* 1144baa9922SRussell King * The module can be at any place in ram in nommu mode. 1154baa9922SRussell King */ 116ab4f2ee1SRussell King #define MODULES_END (END_MEM) 117ab4f2ee1SRussell King #define MODULES_VADDR (PHYS_OFFSET) 1184baa9922SRussell King 11938b4205aSUwe Kleine-König #define XIP_VIRT_ADDR(physaddr) (physaddr) 12038b4205aSUwe Kleine-König 1214baa9922SRussell King #endif /* !CONFIG_MMU */ 1224baa9922SRussell King 1234baa9922SRussell King /* 1241dbd30e9SLinus Walleij * We fix the TCM memories max 32 KiB ITCM resp DTCM at these 1251dbd30e9SLinus Walleij * locations 1261dbd30e9SLinus Walleij */ 1271dbd30e9SLinus Walleij #ifdef CONFIG_HAVE_TCM 1281dbd30e9SLinus Walleij #define ITCM_OFFSET UL(0xfffe0000) 1291dbd30e9SLinus Walleij #define DTCM_OFFSET UL(0xfffe8000) 1301dbd30e9SLinus Walleij #endif 1311dbd30e9SLinus Walleij 1321dbd30e9SLinus Walleij /* 1334baa9922SRussell King * Convert a physical address to a Page Frame Number and back 1344baa9922SRussell King */ 1353a6b1676SWill Deacon #define __phys_to_pfn(paddr) ((unsigned long)((paddr) >> PAGE_SHIFT)) 1363a6b1676SWill Deacon #define __pfn_to_phys(pfn) ((phys_addr_t)(pfn) << PAGE_SHIFT) 1374baa9922SRussell King 138719301ffSRussell King /* 139719301ffSRussell King * Convert a page to/from a physical address 140719301ffSRussell King */ 141719301ffSRussell King #define page_to_phys(page) (__pfn_to_phys(page_to_pfn(page))) 142719301ffSRussell King #define phys_to_page(phys) (pfn_to_page(__phys_to_pfn(phys))) 143719301ffSRussell King 1444baa9922SRussell King #ifndef __ASSEMBLY__ 1454baa9922SRussell King 1464baa9922SRussell King /* 147dc21af99SRussell King * Physical vs virtual RAM address space conversion. These are 148dc21af99SRussell King * private definitions which should NOT be used outside memory.h 149dc21af99SRussell King * files. Use virt_to_phys/phys_to_virt/__pa/__va instead. 150dc21af99SRussell King */ 151dc21af99SRussell King #ifndef __virt_to_phys 152dc21af99SRussell King #ifdef CONFIG_ARM_PATCH_PHYS_VIRT 153dc21af99SRussell King 154cada3c08SRussell King /* 155cada3c08SRussell King * Constants used to force the right instruction encodings and shifts 156cada3c08SRussell King * so that all we need to do is modify the 8-bit constant field. 157cada3c08SRussell King */ 158cada3c08SRussell King #define __PV_BITS_31_24 0x81000000 159cada3c08SRussell King 160dc21af99SRussell King extern unsigned long __pv_phys_offset; 161dc21af99SRussell King #define PHYS_OFFSET __pv_phys_offset 162dc21af99SRussell King 163cada3c08SRussell King #define __pv_stub(from,to,instr,type) \ 164dc21af99SRussell King __asm__("@ __pv_stub\n" \ 165dc21af99SRussell King "1: " instr " %0, %1, %2\n" \ 166dc21af99SRussell King " .pushsection .pv_table,\"a\"\n" \ 167dc21af99SRussell King " .long 1b\n" \ 168dc21af99SRussell King " .popsection\n" \ 169dc21af99SRussell King : "=r" (to) \ 170cada3c08SRussell King : "r" (from), "I" (type)) 171dc21af99SRussell King 172dc21af99SRussell King static inline unsigned long __virt_to_phys(unsigned long x) 173dc21af99SRussell King { 174dc21af99SRussell King unsigned long t; 175cada3c08SRussell King __pv_stub(x, t, "add", __PV_BITS_31_24); 176dc21af99SRussell King return t; 177dc21af99SRussell King } 178dc21af99SRussell King 179dc21af99SRussell King static inline unsigned long __phys_to_virt(unsigned long x) 180dc21af99SRussell King { 181dc21af99SRussell King unsigned long t; 182cada3c08SRussell King __pv_stub(x, t, "sub", __PV_BITS_31_24); 183dc21af99SRussell King return t; 184dc21af99SRussell King } 185dc21af99SRussell King #else 186dc21af99SRussell King #define __virt_to_phys(x) ((x) - PAGE_OFFSET + PHYS_OFFSET) 187dc21af99SRussell King #define __phys_to_virt(x) ((x) - PHYS_OFFSET + PAGE_OFFSET) 188dc21af99SRussell King #endif 189dc21af99SRussell King #endif 190dc21af99SRussell King 191dc21af99SRussell King #ifndef PHYS_OFFSET 1921b9f95f8SNicolas Pitre #ifdef PLAT_PHYS_OFFSET 193dc21af99SRussell King #define PHYS_OFFSET PLAT_PHYS_OFFSET 1941b9f95f8SNicolas Pitre #else 1951b9f95f8SNicolas Pitre #define PHYS_OFFSET UL(CONFIG_PHYS_OFFSET) 1961b9f95f8SNicolas Pitre #endif 197dc21af99SRussell King #endif 198dc21af99SRussell King 199dc21af99SRussell King /* 2004baa9922SRussell King * PFNs are used to describe any physical page; this means 2014baa9922SRussell King * PFN 0 == physical address 0. 2024baa9922SRussell King * 2034baa9922SRussell King * This is the PFN of the first RAM page in the kernel 2044baa9922SRussell King * direct-mapped view. We assume this is the first page 2054baa9922SRussell King * of RAM in the mem_map as well. 2064baa9922SRussell King */ 2074baa9922SRussell King #define PHYS_PFN_OFFSET (PHYS_OFFSET >> PAGE_SHIFT) 2084baa9922SRussell King 2094baa9922SRussell King /* 2104baa9922SRussell King * These are *only* valid on the kernel direct mapped RAM memory. 2114baa9922SRussell King * Note: Drivers should NOT use these. They are the wrong 2124baa9922SRussell King * translation for translating DMA addresses. Use the driver 2134baa9922SRussell King * DMA support - see dma-mapping.h. 2144baa9922SRussell King */ 2153a6b1676SWill Deacon static inline phys_addr_t virt_to_phys(const volatile void *x) 2164baa9922SRussell King { 2174baa9922SRussell King return __virt_to_phys((unsigned long)(x)); 2184baa9922SRussell King } 2194baa9922SRussell King 2203a6b1676SWill Deacon static inline void *phys_to_virt(phys_addr_t x) 2214baa9922SRussell King { 2224baa9922SRussell King return (void *)(__phys_to_virt((unsigned long)(x))); 2234baa9922SRussell King } 2244baa9922SRussell King 2254baa9922SRussell King /* 2264baa9922SRussell King * Drivers should NOT use these either. 2274baa9922SRussell King */ 2284baa9922SRussell King #define __pa(x) __virt_to_phys((unsigned long)(x)) 2294baa9922SRussell King #define __va(x) ((void *)__phys_to_virt((unsigned long)(x))) 2304baa9922SRussell King #define pfn_to_kaddr(pfn) __va((pfn) << PAGE_SHIFT) 2314baa9922SRussell King 2324baa9922SRussell King /* 2334baa9922SRussell King * Virtual <-> DMA view memory address translations 2344baa9922SRussell King * Again, these are *only* valid on the kernel direct mapped RAM 2354baa9922SRussell King * memory. Use of these is *deprecated* (and that doesn't mean 2364baa9922SRussell King * use the __ prefixed forms instead.) See dma-mapping.h. 2374baa9922SRussell King */ 238b5ee9002SNicolas Pitre #ifndef __virt_to_bus 239b5ee9002SNicolas Pitre #define __virt_to_bus __virt_to_phys 240b5ee9002SNicolas Pitre #define __bus_to_virt __phys_to_virt 2411c4a4f48SRussell King #define __pfn_to_bus(x) __pfn_to_phys(x) 2421c4a4f48SRussell King #define __bus_to_pfn(x) __phys_to_pfn(x) 243b5ee9002SNicolas Pitre #endif 244b5ee9002SNicolas Pitre 2454baa9922SRussell King static inline __deprecated unsigned long virt_to_bus(void *x) 2464baa9922SRussell King { 2474baa9922SRussell King return __virt_to_bus((unsigned long)x); 2484baa9922SRussell King } 2494baa9922SRussell King 2504baa9922SRussell King static inline __deprecated void *bus_to_virt(unsigned long x) 2514baa9922SRussell King { 2524baa9922SRussell King return (void *)__bus_to_virt(x); 2534baa9922SRussell King } 2544baa9922SRussell King 2554baa9922SRussell King /* 2564baa9922SRussell King * Conversion between a struct page and a physical address. 2574baa9922SRussell King * 2584baa9922SRussell King * Note: when converting an unknown physical address to a 2594baa9922SRussell King * struct page, the resulting pointer must be validated 2604baa9922SRussell King * using VALID_PAGE(). It must return an invalid struct page 2614baa9922SRussell King * for any physical address not corresponding to a system 2624baa9922SRussell King * RAM address. 2634baa9922SRussell King * 2644baa9922SRussell King * page_to_pfn(page) convert a struct page * to a PFN number 2654baa9922SRussell King * pfn_to_page(pfn) convert a _valid_ PFN number to struct page * 2664baa9922SRussell King * 2674baa9922SRussell King * virt_to_page(k) convert a _valid_ virtual address to struct page * 2684baa9922SRussell King * virt_addr_valid(k) indicates whether a virtual address is valid 2694baa9922SRussell King */ 2704baa9922SRussell King #define ARCH_PFN_OFFSET PHYS_PFN_OFFSET 2714baa9922SRussell King 2724baa9922SRussell King #define virt_to_page(kaddr) pfn_to_page(__pa(kaddr) >> PAGE_SHIFT) 2734baa9922SRussell King #define virt_addr_valid(kaddr) ((unsigned long)(kaddr) >= PAGE_OFFSET && (unsigned long)(kaddr) < (unsigned long)high_memory) 2744baa9922SRussell King 2754baa9922SRussell King /* 2764baa9922SRussell King * Optional coherency support. Currently used only by selected 2774baa9922SRussell King * Intel XSC3-based systems. 2784baa9922SRussell King */ 2794baa9922SRussell King #ifndef arch_is_coherent 2804baa9922SRussell King #define arch_is_coherent() 0 2814baa9922SRussell King #endif 2824baa9922SRussell King 2834baa9922SRussell King #endif 2844baa9922SRussell King 2854baa9922SRussell King #include <asm-generic/memory_model.h> 2864baa9922SRussell King 2874baa9922SRussell King #endif 288