blob: 64d0ab98fcd8da6e7bd1765c8572512fb02e9e7d [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * Written by Kanoj Sarcar (kanoj@sgi.com) Aug 99
3 * Adapted for the alpha wildfire architecture Jan 2001.
4 */
5#ifndef _ASM_MMZONE_H_
6#define _ASM_MMZONE_H_
7
Linus Torvalds1da177e2005-04-16 15:20:36 -07008#include <asm/smp.h>
9
10struct bootmem_data_t; /* stupid forward decl. */
11
12/*
13 * Following are macros that are specific to this numa platform.
14 */
15
16extern pg_data_t node_data[];
17
18#define alpha_pa_to_nid(pa) \
19 (alpha_mv.pa_to_nid \
20 ? alpha_mv.pa_to_nid(pa) \
21 : (0))
22#define node_mem_start(nid) \
23 (alpha_mv.node_mem_start \
24 ? alpha_mv.node_mem_start(nid) \
25 : (0UL))
26#define node_mem_size(nid) \
27 (alpha_mv.node_mem_size \
28 ? alpha_mv.node_mem_size(nid) \
29 : ((nid) ? (0UL) : (~0UL)))
30
31#define pa_to_nid(pa) alpha_pa_to_nid(pa)
32#define NODE_DATA(nid) (&node_data[(nid)])
33
34#define node_localnr(pfn, nid) ((pfn) - NODE_DATA(nid)->node_start_pfn)
35
36#if 1
37#define PLAT_NODE_DATA_LOCALNR(p, n) \
38 (((p) >> PAGE_SHIFT) - PLAT_NODE_DATA(n)->gendata.node_start_pfn)
39#else
40static inline unsigned long
41PLAT_NODE_DATA_LOCALNR(unsigned long p, int n)
42{
43 unsigned long temp;
44 temp = p >> PAGE_SHIFT;
45 return temp - PLAT_NODE_DATA(n)->gendata.node_start_pfn;
46}
47#endif
48
49#ifdef CONFIG_DISCONTIGMEM
50
51/*
52 * Following are macros that each numa implementation must define.
53 */
54
55/*
56 * Given a kernel address, find the home node of the underlying memory.
57 */
58#define kvaddr_to_nid(kaddr) pa_to_nid(__pa(kaddr))
Linus Torvalds1da177e2005-04-16 15:20:36 -070059#define node_start_pfn(nid) (NODE_DATA(nid)->node_start_pfn)
60
Linus Torvalds1da177e2005-04-16 15:20:36 -070061/*
62 * Given a kaddr, LOCAL_BASE_ADDR finds the owning node of the memory
63 * and returns the kaddr corresponding to first physical page in the
64 * node's mem_map.
65 */
66#define LOCAL_BASE_ADDR(kaddr) \
67 ((unsigned long)__va(NODE_DATA(kvaddr_to_nid(kaddr))->node_start_pfn \
68 << PAGE_SHIFT))
69
70/* XXX: FIXME -- wli */
71#define kern_addr_valid(kaddr) (0)
72
73#define virt_to_page(kaddr) pfn_to_page(__pa(kaddr) >> PAGE_SHIFT)
74
75#define VALID_PAGE(page) (((page) - mem_map) < max_mapnr)
76
77#define pmd_page(pmd) (pfn_to_page(pmd_val(pmd) >> 32))
78#define pte_pfn(pte) (pte_val(pte) >> 32)
79
80#define mk_pte(page, pgprot) \
81({ \
82 pte_t pte; \
83 unsigned long pfn; \
84 \
KAMEZAWA Hiroyukia0140c12006-03-27 01:15:55 -080085 pfn = page_to_pfn(page) << 32; \
Linus Torvalds1da177e2005-04-16 15:20:36 -070086 pte_val(pte) = pfn | pgprot_val(pgprot); \
87 \
88 pte; \
89})
90
91#define pte_page(x) \
92({ \
93 unsigned long kvirt; \
94 struct page * __xx; \
95 \
96 kvirt = (unsigned long)__va(pte_val(x) >> (32-PAGE_SHIFT)); \
97 __xx = virt_to_page(kvirt); \
98 \
99 __xx; \
100})
101
Linus Torvalds1da177e2005-04-16 15:20:36 -0700102#define page_to_pa(page) \
KAMEZAWA Hiroyuki1c05dda2006-03-27 01:15:36 -0800103 (page_to_pfn(page) << PAGE_SHIFT)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700104
105#define pfn_to_nid(pfn) pa_to_nid(((u64)(pfn) << PAGE_SHIFT))
106#define pfn_valid(pfn) \
107 (((pfn) - node_start_pfn(pfn_to_nid(pfn))) < \
108 node_spanned_pages(pfn_to_nid(pfn))) \
109
110#define virt_addr_valid(kaddr) pfn_valid((__pa(kaddr) >> PAGE_SHIFT))
111
112#endif /* CONFIG_DISCONTIGMEM */
113
114#endif /* _ASM_MMZONE_H_ */