ftp://ftp.kernel.org/pub/linux/kernel/v2.6/linux-2.6.6.tar.bz2
[linux-2.6.git] / include / asm-i386 / mmzone.h
1 /*
2  * Written by Pat Gaughen (gone@us.ibm.com) Mar 2002
3  *
4  */
5
6 #ifndef _ASM_MMZONE_H_
7 #define _ASM_MMZONE_H_
8
9 #include <asm/smp.h>
10
11 #ifdef CONFIG_DISCONTIGMEM
12
13 #ifdef CONFIG_NUMA
14         #ifdef CONFIG_X86_NUMAQ
15                 #include <asm/numaq.h>
16         #else   /* summit or generic arch */
17                 #include <asm/srat.h>
18         #endif
19 #else /* !CONFIG_NUMA */
20         #define get_memcfg_numa get_memcfg_numa_flat
21         #define get_zholes_size(n) (0)
22 #endif /* CONFIG_NUMA */
23
24 extern struct pglist_data *node_data[];
25 #define NODE_DATA(nid)          (node_data[nid])
26
27 /*
28  * generic node memory support, the following assumptions apply:
29  *
30  * 1) memory comes in 256Mb contigious chunks which are either present or not
31  * 2) we will not have more than 64Gb in total
32  *
33  * for now assume that 64Gb is max amount of RAM for whole system
34  *    64Gb / 4096bytes/page = 16777216 pages
35  */
36 #define MAX_NR_PAGES 16777216
37 #define MAX_ELEMENTS 256
38 #define PAGES_PER_ELEMENT (MAX_NR_PAGES/MAX_ELEMENTS)
39
40 extern u8 physnode_map[];
41
42 static inline int pfn_to_nid(unsigned long pfn)
43 {
44 #ifdef CONFIG_NUMA
45         return(physnode_map[(pfn) / PAGES_PER_ELEMENT]);
46 #else
47         return 0;
48 #endif
49 }
50
51 static inline struct pglist_data *pfn_to_pgdat(unsigned long pfn)
52 {
53         return(NODE_DATA(pfn_to_nid(pfn)));
54 }
55
56
57 /*
58  * Following are macros that are specific to this numa platform.
59  */
60 #define reserve_bootmem(addr, size) \
61         reserve_bootmem_node(NODE_DATA(0), (addr), (size))
62 #define alloc_bootmem(x) \
63         __alloc_bootmem_node(NODE_DATA(0), (x), SMP_CACHE_BYTES, __pa(MAX_DMA_ADDRESS))
64 #define alloc_bootmem_low(x) \
65         __alloc_bootmem_node(NODE_DATA(0), (x), SMP_CACHE_BYTES, 0)
66 #define alloc_bootmem_pages(x) \
67         __alloc_bootmem_node(NODE_DATA(0), (x), PAGE_SIZE, __pa(MAX_DMA_ADDRESS))
68 #define alloc_bootmem_low_pages(x) \
69         __alloc_bootmem_node(NODE_DATA(0), (x), PAGE_SIZE, 0)
70 #define alloc_bootmem_node(ignore, x) \
71         __alloc_bootmem_node(NODE_DATA(0), (x), SMP_CACHE_BYTES, __pa(MAX_DMA_ADDRESS))
72 #define alloc_bootmem_pages_node(ignore, x) \
73         __alloc_bootmem_node(NODE_DATA(0), (x), PAGE_SIZE, __pa(MAX_DMA_ADDRESS))
74 #define alloc_bootmem_low_pages_node(ignore, x) \
75         __alloc_bootmem_node(NODE_DATA(0), (x), PAGE_SIZE, 0)
76
77 #define node_localnr(pfn, nid)          ((pfn) - node_data[nid]->node_start_pfn)
78
79 /*
80  * Following are macros that each numa implmentation must define.
81  */
82
83 /*
84  * Given a kernel address, find the home node of the underlying memory.
85  */
86 #define kvaddr_to_nid(kaddr)    pfn_to_nid(__pa(kaddr) >> PAGE_SHIFT)
87
88 #define node_mem_map(nid)       (NODE_DATA(nid)->node_mem_map)
89 #define node_start_pfn(nid)     (NODE_DATA(nid)->node_start_pfn)
90 #define node_end_pfn(nid)                                               \
91 ({                                                                      \
92         pg_data_t *__pgdat = NODE_DATA(nid);                            \
93         __pgdat->node_start_pfn + __pgdat->node_spanned_pages;          \
94 })
95
96 #define local_mapnr(kvaddr)                                             \
97 ({                                                                      \
98         unsigned long __pfn = __pa(kvaddr) >> PAGE_SHIFT;               \
99         (__pfn - node_start_pfn(pfn_to_nid(__pfn)));                    \
100 })
101
102 /* XXX: FIXME -- wli */
103 #define kern_addr_valid(kaddr)  (0)
104
105 #define pfn_to_page(pfn)                                                \
106 ({                                                                      \
107         unsigned long __pfn = pfn;                                      \
108         int __node  = pfn_to_nid(__pfn);                                \
109         &node_mem_map(__node)[node_localnr(__pfn,__node)];              \
110 })
111
112 #define page_to_pfn(pg)                                                 \
113 ({                                                                      \
114         struct page *__page = pg;                                       \
115         struct zone *__zone = page_zone(__page);                        \
116         (unsigned long)(__page - __zone->zone_mem_map)                  \
117                 + __zone->zone_start_pfn;                               \
118 })
119 #define pmd_page(pmd)           (pfn_to_page(pmd_val(pmd) >> PAGE_SHIFT))
120
121 #ifdef CONFIG_X86_NUMAQ            /* we have contiguous memory on NUMA-Q */
122 #define pfn_valid(pfn)          ((pfn) < num_physpages)
123 #else
124 static inline int pfn_valid(int pfn)
125 {
126         int nid = pfn_to_nid(pfn);
127
128         if (nid >= 0)
129                 return (pfn < node_end_pfn(nid));
130         return 0;
131 }
132 #endif
133
134 extern int get_memcfg_numa_flat(void );
135 /*
136  * This allows any one NUMA architecture to be compiled
137  * for, and still fall back to the flat function if it
138  * fails.
139  */
140 static inline void get_memcfg_numa(void)
141 {
142 #ifdef CONFIG_X86_NUMAQ
143         if (get_memcfg_numaq())
144                 return;
145 #elif CONFIG_ACPI_SRAT
146         if (get_memcfg_from_srat())
147                 return;
148 #endif
149
150         get_memcfg_numa_flat();
151 }
152
153 #endif /* CONFIG_DISCONTIGMEM */
154 #endif /* _ASM_MMZONE_H_ */