Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

[ARM] Clean up discontigmem support

Most architectures have fairly simple discontiguous memory - a
simple set of successive regions each containing some memory.
These can be described simply as a log2 of their maximum size,
along with the base address of the first region and the number
of regions.

The base address is already described by PHYS_PFN_OFFSET, and
the number of regions via the MAX_NUMNODES and the number of
online nodes.

If we then supply the log2 of their maximum size, all the other
discontigmem macros can move into generic code.

There is one exception: lh7a40x seems to have a more complicated
setup; this is left alone.

Signed-off-by: Russell King <rmk+kernel@arm.linux.org.uk>

authored by

Russell King and committed by
Russell King
b7dc96d7 0215ffb0

+54 -160
+1 -39
include/asm-arm/arch-aaec2000/memory.h
··· 17 17 #define __virt_to_bus(x) __virt_to_phys(x) 18 18 #define __bus_to_virt(x) __phys_to_virt(x) 19 19 20 - #ifdef CONFIG_DISCONTIGMEM 21 - 22 20 /* 23 21 * The nodes are the followings: 24 22 * ··· 25 27 * node 2: 0xf800.0000 - 0xfbff.ffff 26 28 * node 3: 0xfc00.0000 - 0xffff.ffff 27 29 */ 28 - 29 - /* 30 - * Given a kernel address, find the home node of the underlying memory. 31 - */ 32 - #define KVADDR_TO_NID(addr) \ 33 - (((unsigned long)(addr) - PAGE_OFFSET) >> NODE_MAX_MEM_SHIFT) 34 - 35 - /* 36 - * Given a page frame number, convert it to a node id. 37 - */ 38 - #define PFN_TO_NID(pfn) \ 39 - (((pfn) - PHYS_PFN_OFFSET) >> (NODE_MAX_MEM_SHIFT - PAGE_SHIFT)) 40 - 41 - /* 42 - * Given a kaddr, ADDR_TO_MAPBASE finds the owning node of the memory 43 - * and return the mem_map of that node. 44 - */ 45 - #define ADDR_TO_MAPBASE(kaddr) NODE_MEM_MAP(KVADDR_TO_NID(kaddr)) 46 - 47 - /* 48 - * Given a page frame number, find the owning node of the memory 49 - * and return the mem_map of that node. 50 - */ 51 - #define PFN_TO_MAPBASE(pfn) NODE_MEM_MAP(PFN_TO_NID(pfn)) 52 - 53 - /* 54 - * Given a kaddr, LOCAL_MEM_MAP finds the owning node of the memory 55 - * and returns the index corresponding to the appropriate page in the 56 - * node's mem_map. 57 - */ 58 - #define LOCAL_MAP_NR(addr) \ 59 - (((unsigned long)(addr) & (NODE_MAX_MEM_SIZE - 1)) >> PAGE_SHIFT) 60 - 61 - #define NODE_MAX_MEM_SHIFT 26 62 - #define NODE_MAX_MEM_SIZE (1 << NODE_MAX_MEM_SHIFT) 63 - 64 - #endif /* CONFIG_DISCONTIGMEM */ 30 + #define NODE_MEM_SIZE_BITS 26 65 31 66 32 #endif /* __ASM_ARCH_MEMORY_H */
+10 -43
include/asm-arm/arch-clps711x/memory.h
··· 62 62 * memory bank. For those systems, simply undefine CONFIG_DISCONTIGMEM. 63 63 */ 64 64 65 - #ifdef CONFIG_DISCONTIGMEM 65 + /* 66 + * The PS7211 allows up to 256MB max per DRAM bank, but the EDB7211 67 + * uses only one of the two banks (bank #1). However, even within 68 + * bank #1, memory is discontiguous. 69 + * 70 + * The EDB7211 has two 8MB DRAM areas with 8MB of empty space between 71 + * them, so we use 24 for the node max shift to get 16MB node sizes. 72 + */ 73 + 66 74 /* 67 75 * Because of the wide memory address space between physical RAM banks on the 68 76 * SA1100, it's much more convenient to use Linux's NUMA support to implement ··· 88 80 * node 2: 0xd0000000 - 0xd7ffffff 89 81 * node 3: 0xd8000000 - 0xdfffffff 90 82 */ 91 - 92 - /* 93 - * Given a kernel address, find the home node of the underlying memory. 94 - */ 95 - #define KVADDR_TO_NID(addr) \ 96 - (((unsigned long)(addr) - PAGE_OFFSET) >> NODE_MAX_MEM_SHIFT) 97 - 98 - /* 99 - * Given a page frame number, convert it to a node id. 100 - */ 101 - #define PFN_TO_NID(pfn) \ 102 - (((pfn) - PHYS_PFN_OFFSET) >> (NODE_MAX_MEM_SHIFT - PAGE_SHIFT)) 103 - 104 - /* 105 - * Given a kaddr, ADDR_TO_MAPBASE finds the owning node of the memory 106 - * and returns the mem_map of that node. 107 - */ 108 - #define ADDR_TO_MAPBASE(kaddr) \ 109 - NODE_MEM_MAP(KVADDR_TO_NID((unsigned long)(kaddr))) 110 - 111 - #define PFN_TO_MAPBASE(pfn) NODE_MEM_MAP(PFN_TO_NID(pfn)) 112 - 113 - /* 114 - * Given a kaddr, LOCAL_MAR_NR finds the owning node of the memory 115 - * and returns the index corresponding to the appropriate page in the 116 - * node's mem_map. 117 - */ 118 - #define LOCAL_MAP_NR(addr) \ 119 - (((unsigned long)(addr) & (NODE_MAX_MEM_SIZE - 1)) >> PAGE_SHIFT) 120 - 121 - /* 122 - * The PS7211 allows up to 256MB max per DRAM bank, but the EDB7211 123 - * uses only one of the two banks (bank #1). However, even within 124 - * bank #1, memory is discontiguous. 125 - * 126 - * The EDB7211 has two 8MB DRAM areas with 8MB of empty space between 127 - * them, so we use 24 for the node max shift to get 16MB node sizes. 128 - */ 129 - #define NODE_MAX_MEM_SHIFT 24 130 - #define NODE_MAX_MEM_SIZE (1<<NODE_MAX_MEM_SHIFT) 131 - 132 - #endif /* CONFIG_DISCONTIGMEM */ 83 + #define NODE_MEM_SIZE_BITS 24 133 84 134 85 #endif 135 86
-12
include/asm-arm/arch-lh7a40x/memory.h
··· 58 58 #endif 59 59 60 60 /* 61 - * Given a kaddr, ADDR_TO_MAPBASE finds the owning node of the memory 62 - * and return the mem_map of that node. 63 - */ 64 - # define ADDR_TO_MAPBASE(kaddr) NODE_MEM_MAP(KVADDR_TO_NID(kaddr)) 65 - 66 - /* 67 - * Given a page frame number, find the owning node of the memory 68 - * and return the mem_map of that node. 69 - */ 70 - # define PFN_TO_MAPBASE(pfn) NODE_MEM_MAP(PFN_TO_NID(pfn)) 71 - 72 - /* 73 61 * Given a kaddr, LOCAL_MEM_MAP finds the owning node of the memory 74 62 * and returns the index corresponding to the appropriate page in the 75 63 * node's mem_map.
+3 -33
include/asm-arm/arch-pxa/memory.h
··· 27 27 #define __virt_to_bus(x) __virt_to_phys(x) 28 28 #define __bus_to_virt(x) __phys_to_virt(x) 29 29 30 - #ifdef CONFIG_DISCONTIGMEM 31 30 /* 32 31 * The nodes are matched with the physical SDRAM banks as follows: 33 32 * ··· 34 35 * node 1: 0xa4000000-0xa7ffffff --> 0xc4000000-0xc7ffffff 35 36 * node 2: 0xa8000000-0xabffffff --> 0xc8000000-0xcbffffff 36 37 * node 3: 0xac000000-0xafffffff --> 0xcc000000-0xcfffffff 38 + * 39 + * This needs a node mem size of 26 bits. 37 40 */ 38 - 39 - /* 40 - * Given a kernel address, find the home node of the underlying memory. 41 - */ 42 - #define KVADDR_TO_NID(addr) (((unsigned long)(addr) - PAGE_OFFSET) >> 26) 43 - 44 - /* 45 - * Given a page frame number, convert it to a node id. 46 - */ 47 - #define PFN_TO_NID(pfn) (((pfn) - PHYS_PFN_OFFSET) >> (26 - PAGE_SHIFT)) 48 - 49 - /* 50 - * Given a kaddr, ADDR_TO_MAPBASE finds the owning node of the memory 51 - * and returns the mem_map of that node. 52 - */ 53 - #define ADDR_TO_MAPBASE(kaddr) NODE_MEM_MAP(KVADDR_TO_NID(kaddr)) 54 - 55 - /* 56 - * Given a page frame number, find the owning node of the memory 57 - * and returns the mem_map of that node. 58 - */ 59 - #define PFN_TO_MAPBASE(pfn) NODE_MEM_MAP(PFN_TO_NID(pfn)) 60 - 61 - /* 62 - * Given a kaddr, LOCAL_MEM_MAP finds the owning node of the memory 63 - * and returns the index corresponding to the appropriate page in the 64 - * node's mem_map. 65 - */ 66 - #define LOCAL_MAP_NR(addr) \ 67 - (((unsigned long)(addr) & 0x03ffffff) >> PAGE_SHIFT) 68 - 69 - #endif 41 + #define NODE_MEM_SIZE_BITS 26 70 42 71 43 #endif
+1 -33
include/asm-arm/arch-sa1100/memory.h
··· 39 39 #define __virt_to_bus(x) __virt_to_phys(x) 40 40 #define __bus_to_virt(x) __phys_to_virt(x) 41 41 42 - #ifdef CONFIG_DISCONTIGMEM 43 42 /* 44 43 * Because of the wide memory address space between physical RAM banks on the 45 44 * SA1100, it's much convenient to use Linux's NUMA support to implement our ··· 56 57 * node 2: 0xd0000000 - 0xd7ffffff 57 58 * node 3: 0xd8000000 - 0xdfffffff 58 59 */ 59 - 60 - /* 61 - * Given a kernel address, find the home node of the underlying memory. 62 - */ 63 - #define KVADDR_TO_NID(addr) (((unsigned long)(addr) - PAGE_OFFSET) >> 27) 64 - 65 - /* 66 - * Given a page frame number, convert it to a node id. 67 - */ 68 - #define PFN_TO_NID(pfn) (((pfn) - PHYS_PFN_OFFSET) >> (27 - PAGE_SHIFT)) 69 - 70 - /* 71 - * Given a kaddr, ADDR_TO_MAPBASE finds the owning node of the memory 72 - * and return the mem_map of that node. 73 - */ 74 - #define ADDR_TO_MAPBASE(kaddr) NODE_MEM_MAP(KVADDR_TO_NID(kaddr)) 75 - 76 - /* 77 - * Given a page frame number, find the owning node of the memory 78 - * and return the mem_map of that node. 79 - */ 80 - #define PFN_TO_MAPBASE(pfn) NODE_MEM_MAP(PFN_TO_NID(pfn)) 81 - 82 - /* 83 - * Given a kaddr, LOCAL_MEM_MAP finds the owning node of the memory 84 - * and returns the index corresponding to the appropriate page in the 85 - * node's mem_map. 86 - */ 87 - #define LOCAL_MAP_NR(addr) \ 88 - (((unsigned long)(addr) & 0x07ffffff) >> PAGE_SHIFT) 89 - 90 - #endif 60 + #define NODE_MEM_SIZE_BITS 27 91 61 92 62 /* 93 63 * Cache flushing area - SA1100 zero bank
+39
include/asm-arm/memory.h
··· 215 215 * virt_addr_valid(k) indicates whether a virtual address is valid 216 216 */ 217 217 #ifndef CONFIG_DISCONTIGMEM 218 + 218 219 #define ARCH_PFN_OFFSET PHYS_PFN_OFFSET 219 220 #define pfn_valid(pfn) ((pfn) >= PHYS_PFN_OFFSET && (pfn) < (PHYS_PFN_OFFSET + max_mapnr)) 220 221 ··· 231 230 * around in memory. 232 231 */ 233 232 #include <linux/numa.h> 233 + 234 234 #define arch_pfn_to_nid(pfn) PFN_TO_NID(pfn) 235 235 #define arch_local_page_offset(pfn, nid) LOCAL_MAP_NR((pfn) << PAGE_SHIFT) 236 236 ··· 257 255 * PHYS_TO_NID is used by the ARM kernel/setup.c 258 256 */ 259 257 #define PHYS_TO_NID(addr) PFN_TO_NID((addr) >> PAGE_SHIFT) 258 + 259 + /* 260 + * Given a kaddr, ADDR_TO_MAPBASE finds the owning node of the memory 261 + * and returns the mem_map of that node. 262 + */ 263 + #define ADDR_TO_MAPBASE(kaddr) NODE_MEM_MAP(KVADDR_TO_NID(kaddr)) 264 + 265 + /* 266 + * Given a page frame number, find the owning node of the memory 267 + * and returns the mem_map of that node. 268 + */ 269 + #define PFN_TO_MAPBASE(pfn) NODE_MEM_MAP(PFN_TO_NID(pfn)) 270 + 271 + #ifdef NODE_MEM_SIZE_BITS 272 + #define NODE_MEM_SIZE_MASK ((1 << NODE_MEM_SIZE_BITS) - 1) 273 + 274 + /* 275 + * Given a kernel address, find the home node of the underlying memory. 276 + */ 277 + #define KVADDR_TO_NID(addr) \ 278 + (((unsigned long)(addr) - PAGE_OFFSET) >> NODE_MEM_SIZE_BITS) 279 + 280 + /* 281 + * Given a page frame number, convert it to a node id. 282 + */ 283 + #define PFN_TO_NID(pfn) \ 284 + (((pfn) - PHYS_PFN_OFFSET) >> (NODE_MEM_SIZE_BITS - PAGE_SHIFT)) 285 + 286 + /* 287 + * Given a kaddr, LOCAL_MEM_MAP finds the owning node of the memory 288 + * and returns the index corresponding to the appropriate page in the 289 + * node's mem_map. 290 + */ 291 + #define LOCAL_MAP_NR(addr) \ 292 + (((unsigned long)(addr) & NODE_MEM_SIZE_MASK) >> PAGE_SHIFT) 293 + 294 + #endif /* NODE_MEM_SIZE_BITS */ 260 295 261 296 #endif /* !CONFIG_DISCONTIGMEM */ 262 297