xref: /openbmc/u-boot/arch/arm/include/asm/memory.h (revision 23ff8633)
1 /*
2  *  linux/include/asm-arm/memory.h
3  *
4  *  Copyright (C) 2000-2002 Russell King
5  *
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.
9  *
10  *  Note: this file should not be included by non-asm/.h files
11  */
12 #ifndef __ASM_ARM_MEMORY_H
13 #define __ASM_ARM_MEMORY_H
14 
15 #if 0	/* XXX###XXX */
16 
17 #include <asm/arch/memory.h>
18 
19 /*
20  * PFNs are used to describe any physical page; this means
21  * PFN 0 == physical address 0.
22  *
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.
26  */
27 #define PHYS_PFN_OFFSET	(PHYS_OFFSET >> PAGE_SHIFT)
28 
29 /*
30  * These are *only* valid on the kernel direct mapped RAM memory.
31  */
32 static inline unsigned long virt_to_phys(void *x)
33 {
34 	return __virt_to_phys((unsigned long)(x));
35 }
36 
37 static inline void *phys_to_virt(unsigned long x)
38 {
39 	return (void *)(__phys_to_virt((unsigned long)(x)));
40 }
41 
42 #define __pa(x)			__virt_to_phys((unsigned long)(x))
43 #define __va(x)			((void *)__phys_to_virt((unsigned long)(x)))
44 
45 /*
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 *depreciated*.
49  */
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))))
52 
53 /*
54  * Conversion between a struct page and a physical address.
55  *
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
60  * RAM address.
61  *
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
65  *
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
68  */
69 #ifndef CONFIG_DISCONTIGMEM
70 
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))
74 
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)
77 
78 #define PHYS_TO_NID(addr)	(0)
79 
80 #define VALID_PAGE(page)	((page - mem_map) < max_mapnr)
81 
82 #else
83 
84 /*
85  * This is more complex.  We have a set of mem_map arrays spread
86  * around in memory.
87  */
88 #define page_to_pfn(page)					\
89 	(((page) - page_zone(page)->zone_mem_map)		\
90 	  + (page_zone(page)->zone_start_paddr >> PAGE_SHIFT))
91 
92 #define pfn_to_page(pfn)					\
93 	(PFN_TO_MAPBASE(pfn) + LOCAL_MAP_NR((pfn) << PAGE_SHIFT))
94 
95 #define pfn_valid(pfn)						\
96   ({								\
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));\
101    })
102 
103 #define virt_to_page(kaddr)					\
104 	(ADDR_TO_MAPBASE(kaddr) + LOCAL_MAP_NR(kaddr))
105 
106 #define virt_addr_valid(kaddr)	(KVADDR_TO_NID(kaddr) < NR_NODES)
107 
108 /*
109  * Common discontigmem stuff.
110  *  PHYS_TO_NID is used by the ARM kernel/setup.c
111  */
112 #define PHYS_TO_NID(addr)	PFN_TO_NID((addr) >> PAGE_SHIFT)
113 
114 /*
115  * 2.4 compatibility
116  *
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.
120  */
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)); \
125 })
126 
127 #endif
128 
129 /*
130  * We should really eliminate virt_to_bus() here - it's depreciated.
131  */
132 #define page_to_bus(page)	(virt_to_bus(page_address(page)))
133 
134 #endif	/* XXX###XXX */
135 
136 #endif	/* __ASM_ARM_MEMORY_H */
137