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