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 164baa9922SRussell King /* 174baa9922SRussell King * Allow for constants defined here to be used from assembly code 184baa9922SRussell King * by prepending the UL suffix only with actual C code compilation. 194baa9922SRussell King */ 204baa9922SRussell King #ifndef __ASSEMBLY__ 214baa9922SRussell King #define UL(x) (x##UL) 224baa9922SRussell King #else 234baa9922SRussell King #define UL(x) (x) 244baa9922SRussell King #endif 254baa9922SRussell King 264baa9922SRussell King #include <linux/compiler.h> 27a09e64fbSRussell King #include <mach/memory.h> 284baa9922SRussell King #include <asm/sizes.h> 294baa9922SRussell King 304baa9922SRussell King #ifdef CONFIG_MMU 314baa9922SRussell King 324baa9922SRussell King #ifndef TASK_SIZE 334baa9922SRussell King /* 344baa9922SRussell King * TASK_SIZE - the maximum size of a user space task. 354baa9922SRussell King * TASK_UNMAPPED_BASE - the lower boundary of the mmap VM area 364baa9922SRussell King */ 374baa9922SRussell King #define TASK_SIZE UL(0xbf000000) 384baa9922SRussell King #define TASK_UNMAPPED_BASE UL(0x40000000) 394baa9922SRussell King #endif 404baa9922SRussell King 414baa9922SRussell King /* 424baa9922SRussell King * The maximum size of a 26-bit user space task. 434baa9922SRussell King */ 444baa9922SRussell King #define TASK_SIZE_26 UL(0x04000000) 454baa9922SRussell King 464baa9922SRussell King /* 474baa9922SRussell King * Page offset: 3GB 484baa9922SRussell King */ 494baa9922SRussell King #ifndef PAGE_OFFSET 504baa9922SRussell King #define PAGE_OFFSET UL(0xc0000000) 514baa9922SRussell King #endif 524baa9922SRussell King 534baa9922SRussell King /* 544baa9922SRussell King * The module space lives between the addresses given by TASK_SIZE 554baa9922SRussell King * and PAGE_OFFSET - it must be within 32MB of the kernel text. 564baa9922SRussell King */ 574baa9922SRussell King #define MODULE_END (PAGE_OFFSET) 584baa9922SRussell King #define MODULE_START (MODULE_END - 16*1048576) 594baa9922SRussell King 604baa9922SRussell King #if TASK_SIZE > MODULE_START 614baa9922SRussell King #error Top of user space clashes with start of module space 624baa9922SRussell King #endif 634baa9922SRussell King 644baa9922SRussell King /* 654baa9922SRussell King * The XIP kernel gets mapped at the bottom of the module vm area. 664baa9922SRussell King * Since we use sections to map it, this macro replaces the physical address 674baa9922SRussell King * with its virtual address while keeping offset from the base section. 684baa9922SRussell King */ 694baa9922SRussell King #define XIP_VIRT_ADDR(physaddr) (MODULE_START + ((physaddr) & 0x000fffff)) 704baa9922SRussell King 714baa9922SRussell King /* 724baa9922SRussell King * Allow 16MB-aligned ioremap pages 734baa9922SRussell King */ 744baa9922SRussell King #define IOREMAP_MAX_ORDER 24 754baa9922SRussell King 764baa9922SRussell King #else /* CONFIG_MMU */ 774baa9922SRussell King 784baa9922SRussell King /* 794baa9922SRussell King * The limitation of user task size can grow up to the end of free ram region. 804baa9922SRussell King * It is difficult to define and perhaps will never meet the original meaning 814baa9922SRussell King * of this define that was meant to. 824baa9922SRussell King * Fortunately, there is no reference for this in noMMU mode, for now. 834baa9922SRussell King */ 844baa9922SRussell King #ifndef TASK_SIZE 854baa9922SRussell King #define TASK_SIZE (CONFIG_DRAM_SIZE) 864baa9922SRussell King #endif 874baa9922SRussell King 884baa9922SRussell King #ifndef TASK_UNMAPPED_BASE 894baa9922SRussell King #define TASK_UNMAPPED_BASE UL(0x00000000) 904baa9922SRussell King #endif 914baa9922SRussell King 924baa9922SRussell King #ifndef PHYS_OFFSET 934baa9922SRussell King #define PHYS_OFFSET (CONFIG_DRAM_BASE) 944baa9922SRussell King #endif 954baa9922SRussell King 964baa9922SRussell King #ifndef END_MEM 974baa9922SRussell King #define END_MEM (CONFIG_DRAM_BASE + CONFIG_DRAM_SIZE) 984baa9922SRussell King #endif 994baa9922SRussell King 1004baa9922SRussell King #ifndef PAGE_OFFSET 1014baa9922SRussell King #define PAGE_OFFSET (PHYS_OFFSET) 1024baa9922SRussell King #endif 1034baa9922SRussell King 1044baa9922SRussell King /* 1054baa9922SRussell King * The module can be at any place in ram in nommu mode. 1064baa9922SRussell King */ 1074baa9922SRussell King #define MODULE_END (END_MEM) 1084baa9922SRussell King #define MODULE_START (PHYS_OFFSET) 1094baa9922SRussell King 1104baa9922SRussell King #endif /* !CONFIG_MMU */ 1114baa9922SRussell King 1124baa9922SRussell King /* 1134baa9922SRussell King * Size of DMA-consistent memory region. Must be multiple of 2M, 1144baa9922SRussell King * between 2MB and 14MB inclusive. 1154baa9922SRussell King */ 1164baa9922SRussell King #ifndef CONSISTENT_DMA_SIZE 1174baa9922SRussell King #define CONSISTENT_DMA_SIZE SZ_2M 1184baa9922SRussell King #endif 1194baa9922SRussell King 1204baa9922SRussell King /* 1214baa9922SRussell King * Physical vs virtual RAM address space conversion. These are 1224baa9922SRussell King * private definitions which should NOT be used outside memory.h 1234baa9922SRussell King * files. Use virt_to_phys/phys_to_virt/__pa/__va instead. 1244baa9922SRussell King */ 1254baa9922SRussell King #ifndef __virt_to_phys 1264baa9922SRussell King #define __virt_to_phys(x) ((x) - PAGE_OFFSET + PHYS_OFFSET) 1274baa9922SRussell King #define __phys_to_virt(x) ((x) - PHYS_OFFSET + PAGE_OFFSET) 1284baa9922SRussell King #endif 1294baa9922SRussell King 1304baa9922SRussell King /* 1314baa9922SRussell King * Convert a physical address to a Page Frame Number and back 1324baa9922SRussell King */ 1334baa9922SRussell King #define __phys_to_pfn(paddr) ((paddr) >> PAGE_SHIFT) 1344baa9922SRussell King #define __pfn_to_phys(pfn) ((pfn) << PAGE_SHIFT) 1354baa9922SRussell King 1364baa9922SRussell King #ifndef __ASSEMBLY__ 1374baa9922SRussell King 1384baa9922SRussell King /* 1394baa9922SRussell King * The DMA mask corresponding to the maximum bus address allocatable 1404baa9922SRussell King * using GFP_DMA. The default here places no restriction on DMA 1414baa9922SRussell King * allocations. This must be the smallest DMA mask in the system, 1424baa9922SRussell King * so a successful GFP_DMA allocation will always satisfy this. 1434baa9922SRussell King */ 1444baa9922SRussell King #ifndef ISA_DMA_THRESHOLD 1454baa9922SRussell King #define ISA_DMA_THRESHOLD (0xffffffffULL) 1464baa9922SRussell King #endif 1474baa9922SRussell King 1484baa9922SRussell King #ifndef arch_adjust_zones 1494baa9922SRussell King #define arch_adjust_zones(node,size,holes) do { } while (0) 1504baa9922SRussell King #endif 1514baa9922SRussell King 1524baa9922SRussell King /* 15360296c71SLennert Buytenhek * Amount of memory reserved for the vmalloc() area, and minimum 15460296c71SLennert Buytenhek * address for vmalloc mappings. 15560296c71SLennert Buytenhek */ 15660296c71SLennert Buytenhek extern unsigned long vmalloc_reserve; 15760296c71SLennert Buytenhek 15860296c71SLennert Buytenhek #define VMALLOC_MIN (void *)(VMALLOC_END - vmalloc_reserve) 15960296c71SLennert Buytenhek 16060296c71SLennert Buytenhek /* 1614baa9922SRussell King * PFNs are used to describe any physical page; this means 1624baa9922SRussell King * PFN 0 == physical address 0. 1634baa9922SRussell King * 1644baa9922SRussell King * This is the PFN of the first RAM page in the kernel 1654baa9922SRussell King * direct-mapped view. We assume this is the first page 1664baa9922SRussell King * of RAM in the mem_map as well. 1674baa9922SRussell King */ 1684baa9922SRussell King #define PHYS_PFN_OFFSET (PHYS_OFFSET >> PAGE_SHIFT) 1694baa9922SRussell King 1704baa9922SRussell King /* 1714baa9922SRussell King * These are *only* valid on the kernel direct mapped RAM memory. 1724baa9922SRussell King * Note: Drivers should NOT use these. They are the wrong 1734baa9922SRussell King * translation for translating DMA addresses. Use the driver 1744baa9922SRussell King * DMA support - see dma-mapping.h. 1754baa9922SRussell King */ 1764baa9922SRussell King static inline unsigned long virt_to_phys(void *x) 1774baa9922SRussell King { 1784baa9922SRussell King return __virt_to_phys((unsigned long)(x)); 1794baa9922SRussell King } 1804baa9922SRussell King 1814baa9922SRussell King static inline void *phys_to_virt(unsigned long x) 1824baa9922SRussell King { 1834baa9922SRussell King return (void *)(__phys_to_virt((unsigned long)(x))); 1844baa9922SRussell King } 1854baa9922SRussell King 1864baa9922SRussell King /* 1874baa9922SRussell King * Drivers should NOT use these either. 1884baa9922SRussell King */ 1894baa9922SRussell King #define __pa(x) __virt_to_phys((unsigned long)(x)) 1904baa9922SRussell King #define __va(x) ((void *)__phys_to_virt((unsigned long)(x))) 1914baa9922SRussell King #define pfn_to_kaddr(pfn) __va((pfn) << PAGE_SHIFT) 1924baa9922SRussell King 1934baa9922SRussell King /* 1944baa9922SRussell King * Virtual <-> DMA view memory address translations 1954baa9922SRussell King * Again, these are *only* valid on the kernel direct mapped RAM 1964baa9922SRussell King * memory. Use of these is *deprecated* (and that doesn't mean 1974baa9922SRussell King * use the __ prefixed forms instead.) See dma-mapping.h. 1984baa9922SRussell King */ 1994baa9922SRussell King static inline __deprecated unsigned long virt_to_bus(void *x) 2004baa9922SRussell King { 2014baa9922SRussell King return __virt_to_bus((unsigned long)x); 2024baa9922SRussell King } 2034baa9922SRussell King 2044baa9922SRussell King static inline __deprecated void *bus_to_virt(unsigned long x) 2054baa9922SRussell King { 2064baa9922SRussell King return (void *)__bus_to_virt(x); 2074baa9922SRussell King } 2084baa9922SRussell King 2094baa9922SRussell King /* 2104baa9922SRussell King * Conversion between a struct page and a physical address. 2114baa9922SRussell King * 2124baa9922SRussell King * Note: when converting an unknown physical address to a 2134baa9922SRussell King * struct page, the resulting pointer must be validated 2144baa9922SRussell King * using VALID_PAGE(). It must return an invalid struct page 2154baa9922SRussell King * for any physical address not corresponding to a system 2164baa9922SRussell King * RAM address. 2174baa9922SRussell King * 2184baa9922SRussell King * page_to_pfn(page) convert a struct page * to a PFN number 2194baa9922SRussell King * pfn_to_page(pfn) convert a _valid_ PFN number to struct page * 2204baa9922SRussell King * pfn_valid(pfn) indicates whether a PFN number is valid 2214baa9922SRussell King * 2224baa9922SRussell King * virt_to_page(k) convert a _valid_ virtual address to struct page * 2234baa9922SRussell King * virt_addr_valid(k) indicates whether a virtual address is valid 2244baa9922SRussell King */ 2254baa9922SRussell King #ifndef CONFIG_DISCONTIGMEM 2264baa9922SRussell King 2274baa9922SRussell King #define ARCH_PFN_OFFSET PHYS_PFN_OFFSET 2284baa9922SRussell King 2294baa9922SRussell King #ifndef CONFIG_SPARSEMEM 2304baa9922SRussell King #define pfn_valid(pfn) ((pfn) >= PHYS_PFN_OFFSET && (pfn) < (PHYS_PFN_OFFSET + max_mapnr)) 2314baa9922SRussell King #endif 2324baa9922SRussell King 2334baa9922SRussell King #define virt_to_page(kaddr) pfn_to_page(__pa(kaddr) >> PAGE_SHIFT) 2344baa9922SRussell King #define virt_addr_valid(kaddr) ((unsigned long)(kaddr) >= PAGE_OFFSET && (unsigned long)(kaddr) < (unsigned long)high_memory) 2354baa9922SRussell King 2364baa9922SRussell King #define PHYS_TO_NID(addr) (0) 2374baa9922SRussell King 2384baa9922SRussell King #else /* CONFIG_DISCONTIGMEM */ 2394baa9922SRussell King 2404baa9922SRussell King /* 2414baa9922SRussell King * This is more complex. We have a set of mem_map arrays spread 2424baa9922SRussell King * around in memory. 2434baa9922SRussell King */ 2444baa9922SRussell King #include <linux/numa.h> 2454baa9922SRussell King 2464baa9922SRussell King #define arch_pfn_to_nid(pfn) PFN_TO_NID(pfn) 2474baa9922SRussell King #define arch_local_page_offset(pfn, nid) LOCAL_MAP_NR((pfn) << PAGE_SHIFT) 2484baa9922SRussell King 2494baa9922SRussell King #define pfn_valid(pfn) \ 2504baa9922SRussell King ({ \ 2514baa9922SRussell King unsigned int nid = PFN_TO_NID(pfn); \ 2524baa9922SRussell King int valid = nid < MAX_NUMNODES; \ 2534baa9922SRussell King if (valid) { \ 2544baa9922SRussell King pg_data_t *node = NODE_DATA(nid); \ 2554baa9922SRussell King valid = (pfn - node->node_start_pfn) < \ 2564baa9922SRussell King node->node_spanned_pages; \ 2574baa9922SRussell King } \ 2584baa9922SRussell King valid; \ 2594baa9922SRussell King }) 2604baa9922SRussell King 2614baa9922SRussell King #define virt_to_page(kaddr) \ 2624baa9922SRussell King (ADDR_TO_MAPBASE(kaddr) + LOCAL_MAP_NR(kaddr)) 2634baa9922SRussell King 2644baa9922SRussell King #define virt_addr_valid(kaddr) (KVADDR_TO_NID(kaddr) < MAX_NUMNODES) 2654baa9922SRussell King 2664baa9922SRussell King /* 2674baa9922SRussell King * Common discontigmem stuff. 2684baa9922SRussell King * PHYS_TO_NID is used by the ARM kernel/setup.c 2694baa9922SRussell King */ 2704baa9922SRussell King #define PHYS_TO_NID(addr) PFN_TO_NID((addr) >> PAGE_SHIFT) 2714baa9922SRussell King 2724baa9922SRussell King /* 2734baa9922SRussell King * Given a kaddr, ADDR_TO_MAPBASE finds the owning node of the memory 2744baa9922SRussell King * and returns the mem_map of that node. 2754baa9922SRussell King */ 2764baa9922SRussell King #define ADDR_TO_MAPBASE(kaddr) NODE_MEM_MAP(KVADDR_TO_NID(kaddr)) 2774baa9922SRussell King 2784baa9922SRussell King /* 2794baa9922SRussell King * Given a page frame number, find the owning node of the memory 2804baa9922SRussell King * and returns the mem_map of that node. 2814baa9922SRussell King */ 2824baa9922SRussell King #define PFN_TO_MAPBASE(pfn) NODE_MEM_MAP(PFN_TO_NID(pfn)) 2834baa9922SRussell King 2844baa9922SRussell King #ifdef NODE_MEM_SIZE_BITS 2854baa9922SRussell King #define NODE_MEM_SIZE_MASK ((1 << NODE_MEM_SIZE_BITS) - 1) 2864baa9922SRussell King 2874baa9922SRussell King /* 2884baa9922SRussell King * Given a kernel address, find the home node of the underlying memory. 2894baa9922SRussell King */ 2904baa9922SRussell King #define KVADDR_TO_NID(addr) \ 2914baa9922SRussell King (((unsigned long)(addr) - PAGE_OFFSET) >> NODE_MEM_SIZE_BITS) 2924baa9922SRussell King 2934baa9922SRussell King /* 2944baa9922SRussell King * Given a page frame number, convert it to a node id. 2954baa9922SRussell King */ 2964baa9922SRussell King #define PFN_TO_NID(pfn) \ 2974baa9922SRussell King (((pfn) - PHYS_PFN_OFFSET) >> (NODE_MEM_SIZE_BITS - PAGE_SHIFT)) 2984baa9922SRussell King 2994baa9922SRussell King /* 3004baa9922SRussell King * Given a kaddr, LOCAL_MEM_MAP finds the owning node of the memory 3014baa9922SRussell King * and returns the index corresponding to the appropriate page in the 3024baa9922SRussell King * node's mem_map. 3034baa9922SRussell King */ 3044baa9922SRussell King #define LOCAL_MAP_NR(addr) \ 3054baa9922SRussell King (((unsigned long)(addr) & NODE_MEM_SIZE_MASK) >> PAGE_SHIFT) 3064baa9922SRussell King 3074baa9922SRussell King #endif /* NODE_MEM_SIZE_BITS */ 3084baa9922SRussell King 3094baa9922SRussell King #endif /* !CONFIG_DISCONTIGMEM */ 3104baa9922SRussell King 3114baa9922SRussell King /* 3124baa9922SRussell King * For BIO. "will die". Kill me when bio_to_phys() and bvec_to_phys() die. 3134baa9922SRussell King */ 3144baa9922SRussell King #define page_to_phys(page) (page_to_pfn(page) << PAGE_SHIFT) 3154baa9922SRussell King 3164baa9922SRussell King /* 3174baa9922SRussell King * Optional device DMA address remapping. Do _not_ use directly! 3184baa9922SRussell King * We should really eliminate virt_to_bus() here - it's deprecated. 3194baa9922SRussell King */ 3204baa9922SRussell King #ifndef __arch_page_to_dma 3214baa9922SRussell King #define page_to_dma(dev, page) ((dma_addr_t)__virt_to_bus((unsigned long)page_address(page))) 3224baa9922SRussell King #define dma_to_virt(dev, addr) ((void *)__bus_to_virt(addr)) 3234baa9922SRussell King #define virt_to_dma(dev, addr) ((dma_addr_t)__virt_to_bus((unsigned long)(addr))) 3244baa9922SRussell King #else 3254baa9922SRussell King #define page_to_dma(dev, page) (__arch_page_to_dma(dev, page)) 3264baa9922SRussell King #define dma_to_virt(dev, addr) (__arch_dma_to_virt(dev, addr)) 3274baa9922SRussell King #define virt_to_dma(dev, addr) (__arch_virt_to_dma(dev, addr)) 3284baa9922SRussell King #endif 3294baa9922SRussell King 3304baa9922SRussell King /* 3314baa9922SRussell King * Optional coherency support. Currently used only by selected 3324baa9922SRussell King * Intel XSC3-based systems. 3334baa9922SRussell King */ 3344baa9922SRussell King #ifndef arch_is_coherent 3354baa9922SRussell King #define arch_is_coherent() 0 3364baa9922SRussell King #endif 3374baa9922SRussell King 3384baa9922SRussell King #endif 3394baa9922SRussell King 3404baa9922SRussell King #include <asm-generic/memory_model.h> 3414baa9922SRussell King 3424baa9922SRussell King #endif 343