2 * linux/include/asm-arm/memory.h
4 * Copyright (C) 2000-2002 Russell King
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2 as
8 * published by the Free Software Foundation.
10 * Note: this file should not be included by non-asm/.h files
12 #ifndef __ASM_ARM_MEMORY_H
13 #define __ASM_ARM_MEMORY_H
17 #include <asm/arch/memory.h>
20 * PFNs are used to describe any physical page; this means
21 * PFN 0 == physical address 0.
23 * This is the PFN of the first RAM page in the kernel
24 * direct-mapped view. We assume this is the first page
25 * of RAM in the mem_map as well.
27 #define PHYS_PFN_OFFSET (PHYS_OFFSET >> PAGE_SHIFT)
30 * These are *only* valid on the kernel direct mapped RAM memory.
32 static inline unsigned long virt_to_phys(void *x)
34 return __virt_to_phys((unsigned long)(x));
37 static inline void *phys_to_virt(unsigned long x)
39 return (void *)(__phys_to_virt((unsigned long)(x)));
42 #define __pa(x) __virt_to_phys((unsigned long)(x))
43 #define __va(x) ((void *)__phys_to_virt((unsigned long)(x)))
46 * Virtual <-> DMA view memory address translations
47 * Again, these are *only* valid on the kernel direct mapped RAM
48 * memory. Use of these is *deprecated*.
50 #define virt_to_bus(x) (__virt_to_bus((unsigned long)(x)))
51 #define bus_to_virt(x) ((void *)(__bus_to_virt((unsigned long)(x))))
54 * Conversion between a struct page and a physical address.
56 * Note: when converting an unknown physical address to a
57 * struct page, the resulting pointer must be validated
58 * using VALID_PAGE(). It must return an invalid struct page
59 * for any physical address not corresponding to a system
62 * page_to_pfn(page) convert a struct page * to a PFN number
63 * pfn_to_page(pfn) convert a _valid_ PFN number to struct page *
64 * pfn_valid(pfn) indicates whether a PFN number is valid
66 * virt_to_page(k) convert a _valid_ virtual address to struct page *
67 * virt_addr_valid(k) indicates whether a virtual address is valid
69 #ifndef CONFIG_DISCONTIGMEM
71 #define page_to_pfn(page) (((page) - mem_map) + PHYS_PFN_OFFSET)
72 #define pfn_to_page(pfn) ((mem_map + (pfn)) - PHYS_PFN_OFFSET)
73 #define pfn_valid(pfn) ((pfn) >= PHYS_PFN_OFFSET && (pfn) < (PHYS_PFN_OFFSET + max_mapnr))
75 #define virt_to_page(kaddr) (pfn_to_page(__pa(kaddr) >> PAGE_SHIFT))
76 #define virt_addr_valid(kaddr) ((kaddr) >= PAGE_OFFSET && (kaddr) < (unsigned long)high_memory)
78 #define PHYS_TO_NID(addr) (0)
80 #define VALID_PAGE(page) ((page - mem_map) < max_mapnr)
85 * This is more complex. We have a set of mem_map arrays spread
88 #define page_to_pfn(page) \
89 (((page) - page_zone(page)->zone_mem_map) \
90 + (page_zone(page)->zone_start_paddr >> PAGE_SHIFT))
92 #define pfn_to_page(pfn) \
93 (PFN_TO_MAPBASE(pfn) + LOCAL_MAP_NR((pfn) << PAGE_SHIFT))
95 #define pfn_valid(pfn) \
97 unsigned int node = PFN_TO_NID(pfn); \
98 struct pglist_data *nd = NODE_DATA(node); \
99 ((node < NR_NODES) && \
100 ((pfn - (nd->node_start_paddr >> PAGE_SHIFT)) < nd->node_size));\
103 #define virt_to_page(kaddr) \
104 (ADDR_TO_MAPBASE(kaddr) + LOCAL_MAP_NR(kaddr))
106 #define virt_addr_valid(kaddr) (KVADDR_TO_NID(kaddr) < NR_NODES)
109 * Common discontigmem stuff.
110 * PHYS_TO_NID is used by the ARM kernel/setup.c
112 #define PHYS_TO_NID(addr) PFN_TO_NID((addr) >> PAGE_SHIFT)
117 * VALID_PAGE returns a non-zero value if given page pointer is valid.
118 * This assumes all node's mem_maps are stored within the node they
119 * refer to. This is actually inherently buggy.
121 #define VALID_PAGE(page) \
122 ({ unsigned int node = KVADDR_TO_NID(page); \
123 ((node < NR_NODES) && \
124 ((unsigned)((page) - NODE_MEM_MAP(node)) < NODE_DATA(node)->node_size)); \
130 * We should really eliminate virt_to_bus() here - it's deprecated.
132 #define page_to_bus(page) (virt_to_bus(page_address(page)))
134 #endif /* XXX###XXX */
136 #endif /* __ASM_ARM_MEMORY_H */