[PATCH] remove non-DISCONTIG use of pgdat->node_mem_map
[linux-2.6.git] / include / asm-parisc / mmzone.h
1 #ifndef _PARISC_MMZONE_H
2 #define _PARISC_MMZONE_H
3
4 #ifdef CONFIG_DISCONTIGMEM
5
6 #define MAX_PHYSMEM_RANGES 8 /* Fix the size for now (current known max is 3) */
7 extern int npmem_ranges;
8
9 struct node_map_data {
10     pg_data_t pg_data;
11 };
12
13 extern struct node_map_data node_data[];
14
15 #define NODE_DATA(nid)          (&node_data[nid].pg_data)
16
17 /*
18  * Given a kernel address, find the home node of the underlying memory.
19  */
20 #define kvaddr_to_nid(kaddr)    pfn_to_nid(__pa(kaddr) >> PAGE_SHIFT)
21
22 #define node_start_pfn(nid)     (NODE_DATA(nid)->node_start_pfn)
23 #define node_end_pfn(nid)                                               \
24 ({                                                                      \
25         pg_data_t *__pgdat = NODE_DATA(nid);                            \
26         __pgdat->node_start_pfn + __pgdat->node_spanned_pages;          \
27 })
28 #define node_localnr(pfn, nid)          ((pfn) - node_start_pfn(nid))
29
30 #define local_mapnr(kvaddr)                                             \
31 ({                                                                      \
32         unsigned long __pfn = __pa(kvaddr) >> PAGE_SHIFT;               \
33         (__pfn - node_start_pfn(pfn_to_nid(__pfn)));                    \
34 })
35
36 #define pfn_to_page(pfn)                                                \
37 ({                                                                      \
38         unsigned long __pfn = (pfn);                                    \
39         int __node  = pfn_to_nid(__pfn);                                \
40         &NODE_DATA(__node)->node_mem_map[node_localnr(__pfn,__node)];   \
41 })
42
43 #define page_to_pfn(pg)                                                 \
44 ({                                                                      \
45         struct page *__page = pg;                                       \
46         struct zone *__zone = page_zone(__page);                        \
47         BUG_ON(__zone == NULL);                                         \
48         (unsigned long)(__page - __zone->zone_mem_map)                  \
49                 + __zone->zone_start_pfn;                               \
50 })
51
52 /* We have these possible memory map layouts:
53  * Astro: 0-3.75, 67.75-68, 4-64
54  * zx1: 0-1, 257-260, 4-256
55  * Stretch (N-class): 0-2, 4-32, 34-xxx
56  */
57
58 /* Since each 1GB can only belong to one region (node), we can create
59  * an index table for pfn to nid lookup; each entry in pfnnid_map 
60  * represents 1GB, and contains the node that the memory belongs to. */
61
62 #define PFNNID_SHIFT (30 - PAGE_SHIFT)
63 #define PFNNID_MAP_MAX  512     /* support 512GB */
64 extern unsigned char pfnnid_map[PFNNID_MAP_MAX];
65
66 #ifndef __LP64__
67 #define pfn_is_io(pfn) ((pfn & (0xf0000000UL >> PAGE_SHIFT)) == (0xf0000000UL >> PAGE_SHIFT))
68 #else
69 /* io can be 0xf0f0f0f0f0xxxxxx or 0xfffffffff0000000 */
70 #define pfn_is_io(pfn) ((pfn & (0xf000000000000000UL >> PAGE_SHIFT)) == (0xf000000000000000UL >> PAGE_SHIFT))
71 #endif
72
73 static inline int pfn_to_nid(unsigned long pfn)
74 {
75         unsigned int i;
76         unsigned char r;
77
78         if (unlikely(pfn_is_io(pfn)))
79                 return 0;
80
81         i = pfn >> PFNNID_SHIFT;
82         BUG_ON(i >= sizeof(pfnnid_map) / sizeof(pfnnid_map[0]));
83         r = pfnnid_map[i];
84         BUG_ON(r == 0xff);
85
86         return (int)r;
87 }
88
89 static inline int pfn_valid(int pfn)
90 {
91         int nid = pfn_to_nid(pfn);
92
93         if (nid >= 0)
94                 return (pfn < node_end_pfn(nid));
95         return 0;
96 }
97
98 #else /* !CONFIG_DISCONTIGMEM */
99 #define MAX_PHYSMEM_RANGES      1 
100 #endif
101 #endif /* _PARISC_MMZONE_H */