xref: /openbmc/linux/arch/arm/include/asm/memory.h (revision 1dbd30e9)
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>
188d5796d2SLennert Buytenhek #include <mach/memory.h>
198d5796d2SLennert Buytenhek #include <asm/sizes.h>
208d5796d2SLennert Buytenhek 
214baa9922SRussell King /*
224baa9922SRussell King  * Allow for constants defined here to be used from assembly code
234baa9922SRussell King  * by prepending the UL suffix only with actual C code compilation.
244baa9922SRussell King  */
258d5796d2SLennert Buytenhek #define UL(x) _AC(x, UL)
264baa9922SRussell King 
274baa9922SRussell King #ifdef CONFIG_MMU
284baa9922SRussell King 
294baa9922SRussell King /*
308d5796d2SLennert Buytenhek  * PAGE_OFFSET - the virtual address of the start of the kernel image
314baa9922SRussell King  * TASK_SIZE - the maximum size of a user space task.
324baa9922SRussell King  * TASK_UNMAPPED_BASE - the lower boundary of the mmap VM area
334baa9922SRussell King  */
348d5796d2SLennert Buytenhek #define PAGE_OFFSET		UL(CONFIG_PAGE_OFFSET)
358d5796d2SLennert Buytenhek #define TASK_SIZE		(UL(CONFIG_PAGE_OFFSET) - UL(0x01000000))
368d5796d2SLennert Buytenhek #define TASK_UNMAPPED_BASE	(UL(CONFIG_PAGE_OFFSET) / 3)
374baa9922SRussell King 
384baa9922SRussell King /*
394baa9922SRussell King  * The maximum size of a 26-bit user space task.
404baa9922SRussell King  */
414baa9922SRussell King #define TASK_SIZE_26		UL(0x04000000)
424baa9922SRussell King 
434baa9922SRussell King /*
444baa9922SRussell King  * The module space lives between the addresses given by TASK_SIZE
454baa9922SRussell King  * and PAGE_OFFSET - it must be within 32MB of the kernel text.
464baa9922SRussell King  */
47adca6dc2SCatalin Marinas #ifndef CONFIG_THUMB2_KERNEL
48d73cd428SNicolas Pitre #define MODULES_VADDR		(PAGE_OFFSET - 16*1024*1024)
49adca6dc2SCatalin Marinas #else
50adca6dc2SCatalin Marinas /* smaller range for Thumb-2 symbols relocation (2^24)*/
51adca6dc2SCatalin Marinas #define MODULES_VADDR		(PAGE_OFFSET - 8*1024*1024)
52adca6dc2SCatalin Marinas #endif
53adca6dc2SCatalin Marinas 
54ab4f2ee1SRussell King #if TASK_SIZE > MODULES_VADDR
554baa9922SRussell King #error Top of user space clashes with start of module space
564baa9922SRussell King #endif
574baa9922SRussell King 
584baa9922SRussell King /*
59d73cd428SNicolas Pitre  * The highmem pkmap virtual space shares the end of the module area.
60d73cd428SNicolas Pitre  */
61d73cd428SNicolas Pitre #ifdef CONFIG_HIGHMEM
62d73cd428SNicolas Pitre #define MODULES_END		(PAGE_OFFSET - PMD_SIZE)
63d73cd428SNicolas Pitre #else
64d73cd428SNicolas Pitre #define MODULES_END		(PAGE_OFFSET)
65d73cd428SNicolas Pitre #endif
66d73cd428SNicolas Pitre 
67d73cd428SNicolas Pitre /*
684baa9922SRussell King  * The XIP kernel gets mapped at the bottom of the module vm area.
694baa9922SRussell King  * Since we use sections to map it, this macro replaces the physical address
704baa9922SRussell King  * with its virtual address while keeping offset from the base section.
714baa9922SRussell King  */
72ab4f2ee1SRussell King #define XIP_VIRT_ADDR(physaddr)  (MODULES_VADDR + ((physaddr) & 0x000fffff))
734baa9922SRussell King 
744baa9922SRussell King /*
754baa9922SRussell King  * Allow 16MB-aligned ioremap pages
764baa9922SRussell King  */
774baa9922SRussell King #define IOREMAP_MAX_ORDER	24
784baa9922SRussell King 
79a7bd08c8SFenkart/Bostandzhyan /*
80a7bd08c8SFenkart/Bostandzhyan  * Size of DMA-consistent memory region.  Must be multiple of 2M,
81a7bd08c8SFenkart/Bostandzhyan  * between 2MB and 14MB inclusive.
82a7bd08c8SFenkart/Bostandzhyan  */
83a7bd08c8SFenkart/Bostandzhyan #ifndef CONSISTENT_DMA_SIZE
84a7bd08c8SFenkart/Bostandzhyan #define CONSISTENT_DMA_SIZE 	SZ_2M
85a7bd08c8SFenkart/Bostandzhyan #endif
86a7bd08c8SFenkart/Bostandzhyan 
87a7bd08c8SFenkart/Bostandzhyan #define CONSISTENT_END		(0xffe00000UL)
88a7bd08c8SFenkart/Bostandzhyan #define CONSISTENT_BASE		(CONSISTENT_END - CONSISTENT_DMA_SIZE)
89a7bd08c8SFenkart/Bostandzhyan 
904baa9922SRussell King #else /* CONFIG_MMU */
914baa9922SRussell King 
924baa9922SRussell King /*
934baa9922SRussell King  * The limitation of user task size can grow up to the end of free ram region.
944baa9922SRussell King  * It is difficult to define and perhaps will never meet the original meaning
954baa9922SRussell King  * of this define that was meant to.
964baa9922SRussell King  * Fortunately, there is no reference for this in noMMU mode, for now.
974baa9922SRussell King  */
984baa9922SRussell King #ifndef TASK_SIZE
994baa9922SRussell King #define TASK_SIZE		(CONFIG_DRAM_SIZE)
1004baa9922SRussell King #endif
1014baa9922SRussell King 
1024baa9922SRussell King #ifndef TASK_UNMAPPED_BASE
1034baa9922SRussell King #define TASK_UNMAPPED_BASE	UL(0x00000000)
1044baa9922SRussell King #endif
1054baa9922SRussell King 
1064baa9922SRussell King #ifndef PHYS_OFFSET
107c931b4f6SFenkart/Bostandzhyan #define PHYS_OFFSET 		UL(CONFIG_DRAM_BASE)
1084baa9922SRussell King #endif
1094baa9922SRussell King 
1104baa9922SRussell King #ifndef END_MEM
111c931b4f6SFenkart/Bostandzhyan #define END_MEM     		(UL(CONFIG_DRAM_BASE) + CONFIG_DRAM_SIZE)
1124baa9922SRussell King #endif
1134baa9922SRussell King 
1144baa9922SRussell King #ifndef PAGE_OFFSET
1154baa9922SRussell King #define PAGE_OFFSET		(PHYS_OFFSET)
1164baa9922SRussell King #endif
1174baa9922SRussell King 
1184baa9922SRussell King /*
1194baa9922SRussell King  * The module can be at any place in ram in nommu mode.
1204baa9922SRussell King  */
121ab4f2ee1SRussell King #define MODULES_END		(END_MEM)
122ab4f2ee1SRussell King #define MODULES_VADDR		(PHYS_OFFSET)
1234baa9922SRussell King 
1244baa9922SRussell King #endif /* !CONFIG_MMU */
1254baa9922SRussell King 
1264baa9922SRussell King /*
1271dbd30e9SLinus Walleij  * We fix the TCM memories max 32 KiB ITCM resp DTCM at these
1281dbd30e9SLinus Walleij  * locations
1291dbd30e9SLinus Walleij  */
1301dbd30e9SLinus Walleij #ifdef CONFIG_HAVE_TCM
1311dbd30e9SLinus Walleij #define ITCM_OFFSET	UL(0xfffe0000)
1321dbd30e9SLinus Walleij #define DTCM_OFFSET	UL(0xfffe8000)
1331dbd30e9SLinus Walleij #endif
1341dbd30e9SLinus Walleij 
1351dbd30e9SLinus Walleij /*
1364baa9922SRussell King  * Physical vs virtual RAM address space conversion.  These are
1374baa9922SRussell King  * private definitions which should NOT be used outside memory.h
1384baa9922SRussell King  * files.  Use virt_to_phys/phys_to_virt/__pa/__va instead.
1394baa9922SRussell King  */
140a8cf81ffSRussell King #ifndef __virt_to_phys
1414baa9922SRussell King #define __virt_to_phys(x)	((x) - PAGE_OFFSET + PHYS_OFFSET)
1424baa9922SRussell King #define __phys_to_virt(x)	((x) - PHYS_OFFSET + PAGE_OFFSET)
143a8cf81ffSRussell King #endif
1444baa9922SRussell King 
1454baa9922SRussell King /*
1464baa9922SRussell King  * Convert a physical address to a Page Frame Number and back
1474baa9922SRussell King  */
1484baa9922SRussell King #define	__phys_to_pfn(paddr)	((paddr) >> PAGE_SHIFT)
1494baa9922SRussell King #define	__pfn_to_phys(pfn)	((pfn) << PAGE_SHIFT)
1504baa9922SRussell King 
151719301ffSRussell King /*
152719301ffSRussell King  * Convert a page to/from a physical address
153719301ffSRussell King  */
154719301ffSRussell King #define page_to_phys(page)	(__pfn_to_phys(page_to_pfn(page)))
155719301ffSRussell King #define phys_to_page(phys)	(pfn_to_page(__phys_to_pfn(phys)))
156719301ffSRussell King 
1574baa9922SRussell King #ifndef __ASSEMBLY__
1584baa9922SRussell King 
1594baa9922SRussell King /*
1604baa9922SRussell King  * The DMA mask corresponding to the maximum bus address allocatable
1614baa9922SRussell King  * using GFP_DMA.  The default here places no restriction on DMA
1624baa9922SRussell King  * allocations.  This must be the smallest DMA mask in the system,
1634baa9922SRussell King  * so a successful GFP_DMA allocation will always satisfy this.
1644baa9922SRussell King  */
1654baa9922SRussell King #ifndef ISA_DMA_THRESHOLD
1664baa9922SRussell King #define ISA_DMA_THRESHOLD	(0xffffffffULL)
1674baa9922SRussell King #endif
1684baa9922SRussell King 
1694baa9922SRussell King #ifndef arch_adjust_zones
1704baa9922SRussell King #define arch_adjust_zones(node,size,holes) do { } while (0)
1713bca103aSNicolas Pitre #elif !defined(CONFIG_ZONE_DMA)
1723bca103aSNicolas Pitre #error "custom arch_adjust_zones() requires CONFIG_ZONE_DMA"
1734baa9922SRussell King #endif
1744baa9922SRussell King 
1754baa9922SRussell King /*
1764baa9922SRussell King  * PFNs are used to describe any physical page; this means
1774baa9922SRussell King  * PFN 0 == physical address 0.
1784baa9922SRussell King  *
1794baa9922SRussell King  * This is the PFN of the first RAM page in the kernel
1804baa9922SRussell King  * direct-mapped view.  We assume this is the first page
1814baa9922SRussell King  * of RAM in the mem_map as well.
1824baa9922SRussell King  */
1834baa9922SRussell King #define PHYS_PFN_OFFSET	(PHYS_OFFSET >> PAGE_SHIFT)
1844baa9922SRussell King 
1854baa9922SRussell King /*
1864baa9922SRussell King  * These are *only* valid on the kernel direct mapped RAM memory.
1874baa9922SRussell King  * Note: Drivers should NOT use these.  They are the wrong
1884baa9922SRussell King  * translation for translating DMA addresses.  Use the driver
1894baa9922SRussell King  * DMA support - see dma-mapping.h.
1904baa9922SRussell King  */
1914baa9922SRussell King static inline unsigned long virt_to_phys(void *x)
1924baa9922SRussell King {
1934baa9922SRussell King 	return __virt_to_phys((unsigned long)(x));
1944baa9922SRussell King }
1954baa9922SRussell King 
1964baa9922SRussell King static inline void *phys_to_virt(unsigned long x)
1974baa9922SRussell King {
1984baa9922SRussell King 	return (void *)(__phys_to_virt((unsigned long)(x)));
1994baa9922SRussell King }
2004baa9922SRussell King 
2014baa9922SRussell King /*
2024baa9922SRussell King  * Drivers should NOT use these either.
2034baa9922SRussell King  */
2044baa9922SRussell King #define __pa(x)			__virt_to_phys((unsigned long)(x))
2054baa9922SRussell King #define __va(x)			((void *)__phys_to_virt((unsigned long)(x)))
2064baa9922SRussell King #define pfn_to_kaddr(pfn)	__va((pfn) << PAGE_SHIFT)
2074baa9922SRussell King 
2084baa9922SRussell King /*
2094baa9922SRussell King  * Virtual <-> DMA view memory address translations
2104baa9922SRussell King  * Again, these are *only* valid on the kernel direct mapped RAM
2114baa9922SRussell King  * memory.  Use of these is *deprecated* (and that doesn't mean
2124baa9922SRussell King  * use the __ prefixed forms instead.)  See dma-mapping.h.
2134baa9922SRussell King  */
214b5ee9002SNicolas Pitre #ifndef __virt_to_bus
215b5ee9002SNicolas Pitre #define __virt_to_bus	__virt_to_phys
216b5ee9002SNicolas Pitre #define __bus_to_virt	__phys_to_virt
2171c4a4f48SRussell King #define __pfn_to_bus(x)	__pfn_to_phys(x)
2181c4a4f48SRussell King #define __bus_to_pfn(x)	__phys_to_pfn(x)
219b5ee9002SNicolas Pitre #endif
220b5ee9002SNicolas Pitre 
2214baa9922SRussell King static inline __deprecated unsigned long virt_to_bus(void *x)
2224baa9922SRussell King {
2234baa9922SRussell King 	return __virt_to_bus((unsigned long)x);
2244baa9922SRussell King }
2254baa9922SRussell King 
2264baa9922SRussell King static inline __deprecated void *bus_to_virt(unsigned long x)
2274baa9922SRussell King {
2284baa9922SRussell King 	return (void *)__bus_to_virt(x);
2294baa9922SRussell King }
2304baa9922SRussell King 
2314baa9922SRussell King /*
2324baa9922SRussell King  * Conversion between a struct page and a physical address.
2334baa9922SRussell King  *
2344baa9922SRussell King  * Note: when converting an unknown physical address to a
2354baa9922SRussell King  * struct page, the resulting pointer must be validated
2364baa9922SRussell King  * using VALID_PAGE().  It must return an invalid struct page
2374baa9922SRussell King  * for any physical address not corresponding to a system
2384baa9922SRussell King  * RAM address.
2394baa9922SRussell King  *
2404baa9922SRussell King  *  page_to_pfn(page)	convert a struct page * to a PFN number
2414baa9922SRussell King  *  pfn_to_page(pfn)	convert a _valid_ PFN number to struct page *
2424baa9922SRussell King  *
2434baa9922SRussell King  *  virt_to_page(k)	convert a _valid_ virtual address to struct page *
2444baa9922SRussell King  *  virt_addr_valid(k)	indicates whether a virtual address is valid
2454baa9922SRussell King  */
2464baa9922SRussell King #ifndef CONFIG_DISCONTIGMEM
2474baa9922SRussell King 
2484baa9922SRussell King #define ARCH_PFN_OFFSET		PHYS_PFN_OFFSET
2494baa9922SRussell King 
2504baa9922SRussell King #define virt_to_page(kaddr)	pfn_to_page(__pa(kaddr) >> PAGE_SHIFT)
2514baa9922SRussell King #define virt_addr_valid(kaddr)	((unsigned long)(kaddr) >= PAGE_OFFSET && (unsigned long)(kaddr) < (unsigned long)high_memory)
2524baa9922SRussell King 
2534baa9922SRussell King #define PHYS_TO_NID(addr)	(0)
2544baa9922SRussell King 
2554baa9922SRussell King #else /* CONFIG_DISCONTIGMEM */
2564baa9922SRussell King 
2574baa9922SRussell King /*
2584baa9922SRussell King  * This is more complex.  We have a set of mem_map arrays spread
2594baa9922SRussell King  * around in memory.
2604baa9922SRussell King  */
2614baa9922SRussell King #include <linux/numa.h>
2624baa9922SRussell King 
2634baa9922SRussell King #define arch_pfn_to_nid(pfn)	PFN_TO_NID(pfn)
2644baa9922SRussell King #define arch_local_page_offset(pfn, nid) LOCAL_MAP_NR((pfn) << PAGE_SHIFT)
2654baa9922SRussell King 
2664baa9922SRussell King #define virt_to_page(kaddr)					\
2674baa9922SRussell King 	(ADDR_TO_MAPBASE(kaddr) + LOCAL_MAP_NR(kaddr))
2684baa9922SRussell King 
2694baa9922SRussell King #define virt_addr_valid(kaddr)	(KVADDR_TO_NID(kaddr) < MAX_NUMNODES)
2704baa9922SRussell King 
2714baa9922SRussell King /*
2724baa9922SRussell King  * Common discontigmem stuff.
2734baa9922SRussell King  *  PHYS_TO_NID is used by the ARM kernel/setup.c
2744baa9922SRussell King  */
2754baa9922SRussell King #define PHYS_TO_NID(addr)	PFN_TO_NID((addr) >> PAGE_SHIFT)
2764baa9922SRussell King 
2774baa9922SRussell King /*
2784baa9922SRussell King  * Given a kaddr, ADDR_TO_MAPBASE finds the owning node of the memory
2794baa9922SRussell King  * and returns the mem_map of that node.
2804baa9922SRussell King  */
2814baa9922SRussell King #define ADDR_TO_MAPBASE(kaddr)	NODE_MEM_MAP(KVADDR_TO_NID(kaddr))
2824baa9922SRussell King 
2834baa9922SRussell King /*
2844baa9922SRussell King  * Given a page frame number, find the owning node of the memory
2854baa9922SRussell King  * and returns the mem_map of that node.
2864baa9922SRussell King  */
2874baa9922SRussell King #define PFN_TO_MAPBASE(pfn)	NODE_MEM_MAP(PFN_TO_NID(pfn))
2884baa9922SRussell King 
2894baa9922SRussell King #ifdef NODE_MEM_SIZE_BITS
2904baa9922SRussell King #define NODE_MEM_SIZE_MASK	((1 << NODE_MEM_SIZE_BITS) - 1)
2914baa9922SRussell King 
2924baa9922SRussell King /*
2934baa9922SRussell King  * Given a kernel address, find the home node of the underlying memory.
2944baa9922SRussell King  */
2954baa9922SRussell King #define KVADDR_TO_NID(addr) \
2964baa9922SRussell King 	(((unsigned long)(addr) - PAGE_OFFSET) >> NODE_MEM_SIZE_BITS)
2974baa9922SRussell King 
2984baa9922SRussell King /*
2994baa9922SRussell King  * Given a page frame number, convert it to a node id.
3004baa9922SRussell King  */
3014baa9922SRussell King #define PFN_TO_NID(pfn) \
3024baa9922SRussell King 	(((pfn) - PHYS_PFN_OFFSET) >> (NODE_MEM_SIZE_BITS - PAGE_SHIFT))
3034baa9922SRussell King 
3044baa9922SRussell King /*
3054baa9922SRussell King  * Given a kaddr, LOCAL_MEM_MAP finds the owning node of the memory
3064baa9922SRussell King  * and returns the index corresponding to the appropriate page in the
3074baa9922SRussell King  * node's mem_map.
3084baa9922SRussell King  */
3094baa9922SRussell King #define LOCAL_MAP_NR(addr) \
3104baa9922SRussell King 	(((unsigned long)(addr) & NODE_MEM_SIZE_MASK) >> PAGE_SHIFT)
3114baa9922SRussell King 
3124baa9922SRussell King #endif /* NODE_MEM_SIZE_BITS */
3134baa9922SRussell King 
3144baa9922SRussell King #endif /* !CONFIG_DISCONTIGMEM */
3154baa9922SRussell King 
3164baa9922SRussell King /*
3174baa9922SRussell King  * Optional coherency support.  Currently used only by selected
3184baa9922SRussell King  * Intel XSC3-based systems.
3194baa9922SRussell King  */
3204baa9922SRussell King #ifndef arch_is_coherent
3214baa9922SRussell King #define arch_is_coherent()		0
3224baa9922SRussell King #endif
3234baa9922SRussell King 
3244baa9922SRussell King #endif
3254baa9922SRussell King 
3264baa9922SRussell King #include <asm-generic/memory_model.h>
3274baa9922SRussell King 
3284baa9922SRussell King #endif
329