blob: ae039f4fd71121d1d1710d5cfeda926e8f4a6d82 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001#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) */
7extern int npmem_ranges;
8
9struct node_map_data {
10 pg_data_t pg_data;
11};
12
13extern 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
Linus Torvalds1da177e2005-04-16 15:20:36 -070022#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
Linus Torvalds1da177e2005-04-16 15:20:36 -070030#define pfn_to_page(pfn) \
31({ \
32 unsigned long __pfn = (pfn); \
33 int __node = pfn_to_nid(__pfn); \
Dave Hansen408fde82005-06-23 00:07:37 -070034 &NODE_DATA(__node)->node_mem_map[node_localnr(__pfn,__node)]; \
Linus Torvalds1da177e2005-04-16 15:20:36 -070035})
36
37#define page_to_pfn(pg) \
38({ \
39 struct page *__page = pg; \
40 struct zone *__zone = page_zone(__page); \
41 BUG_ON(__zone == NULL); \
42 (unsigned long)(__page - __zone->zone_mem_map) \
43 + __zone->zone_start_pfn; \
44})
45
46/* We have these possible memory map layouts:
47 * Astro: 0-3.75, 67.75-68, 4-64
48 * zx1: 0-1, 257-260, 4-256
49 * Stretch (N-class): 0-2, 4-32, 34-xxx
50 */
51
52/* Since each 1GB can only belong to one region (node), we can create
53 * an index table for pfn to nid lookup; each entry in pfnnid_map
54 * represents 1GB, and contains the node that the memory belongs to. */
55
56#define PFNNID_SHIFT (30 - PAGE_SHIFT)
57#define PFNNID_MAP_MAX 512 /* support 512GB */
58extern unsigned char pfnnid_map[PFNNID_MAP_MAX];
59
60#ifndef __LP64__
61#define pfn_is_io(pfn) ((pfn & (0xf0000000UL >> PAGE_SHIFT)) == (0xf0000000UL >> PAGE_SHIFT))
62#else
63/* io can be 0xf0f0f0f0f0xxxxxx or 0xfffffffff0000000 */
64#define pfn_is_io(pfn) ((pfn & (0xf000000000000000UL >> PAGE_SHIFT)) == (0xf000000000000000UL >> PAGE_SHIFT))
65#endif
66
67static inline int pfn_to_nid(unsigned long pfn)
68{
69 unsigned int i;
70 unsigned char r;
71
72 if (unlikely(pfn_is_io(pfn)))
73 return 0;
74
75 i = pfn >> PFNNID_SHIFT;
76 BUG_ON(i >= sizeof(pfnnid_map) / sizeof(pfnnid_map[0]));
77 r = pfnnid_map[i];
78 BUG_ON(r == 0xff);
79
80 return (int)r;
81}
82
83static inline int pfn_valid(int pfn)
84{
85 int nid = pfn_to_nid(pfn);
86
87 if (nid >= 0)
88 return (pfn < node_end_pfn(nid));
89 return 0;
90}
91
92#else /* !CONFIG_DISCONTIGMEM */
93#define MAX_PHYSMEM_RANGES 1
94#endif
95#endif /* _PARISC_MMZONE_H */