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