Greg Kroah-Hartman | b244131 | 2017-11-01 15:07:57 +0100 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0 */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9 | #include <asm/smp.h> |
| 10 | |
| 11 | struct bootmem_data_t; /* stupid forward decl. */ |
| 12 | |
| 13 | /* |
| 14 | * Following are macros that are specific to this numa platform. |
| 15 | */ |
| 16 | |
| 17 | extern pg_data_t node_data[]; |
| 18 | |
| 19 | #define alpha_pa_to_nid(pa) \ |
| 20 | (alpha_mv.pa_to_nid \ |
| 21 | ? alpha_mv.pa_to_nid(pa) \ |
| 22 | : (0)) |
| 23 | #define node_mem_start(nid) \ |
| 24 | (alpha_mv.node_mem_start \ |
| 25 | ? alpha_mv.node_mem_start(nid) \ |
| 26 | : (0UL)) |
| 27 | #define node_mem_size(nid) \ |
| 28 | (alpha_mv.node_mem_size \ |
| 29 | ? alpha_mv.node_mem_size(nid) \ |
| 30 | : ((nid) ? (0UL) : (~0UL))) |
| 31 | |
| 32 | #define pa_to_nid(pa) alpha_pa_to_nid(pa) |
| 33 | #define NODE_DATA(nid) (&node_data[(nid)]) |
| 34 | |
| 35 | #define node_localnr(pfn, nid) ((pfn) - NODE_DATA(nid)->node_start_pfn) |
| 36 | |
| 37 | #if 1 |
| 38 | #define PLAT_NODE_DATA_LOCALNR(p, n) \ |
| 39 | (((p) >> PAGE_SHIFT) - PLAT_NODE_DATA(n)->gendata.node_start_pfn) |
| 40 | #else |
| 41 | static inline unsigned long |
| 42 | PLAT_NODE_DATA_LOCALNR(unsigned long p, int n) |
| 43 | { |
| 44 | unsigned long temp; |
| 45 | temp = p >> PAGE_SHIFT; |
| 46 | return temp - PLAT_NODE_DATA(n)->gendata.node_start_pfn; |
| 47 | } |
| 48 | #endif |
| 49 | |
| 50 | #ifdef CONFIG_DISCONTIGMEM |
| 51 | |
| 52 | /* |
| 53 | * Following are macros that each numa implementation must define. |
| 54 | */ |
| 55 | |
| 56 | /* |
| 57 | * Given a kernel address, find the home node of the underlying memory. |
| 58 | */ |
| 59 | #define kvaddr_to_nid(kaddr) pa_to_nid(__pa(kaddr)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 60 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 61 | /* |
| 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 | |
Nadia Yvette Chambers | 6d49e35 | 2012-12-06 10:39:54 +0100 | [diff] [blame] | 70 | /* XXX: FIXME -- nyc */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 71 | #define kern_addr_valid(kaddr) (0) |
| 72 | |
| 73 | #define virt_to_page(kaddr) pfn_to_page(__pa(kaddr) >> PAGE_SHIFT) |
| 74 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 75 | #define pmd_page(pmd) (pfn_to_page(pmd_val(pmd) >> 32)) |
Dave McCracken | 46a82b2 | 2006-09-25 23:31:48 -0700 | [diff] [blame] | 76 | #define pgd_page(pgd) (pfn_to_page(pgd_val(pgd) >> 32)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 77 | #define pte_pfn(pte) (pte_val(pte) >> 32) |
| 78 | |
| 79 | #define mk_pte(page, pgprot) \ |
| 80 | ({ \ |
| 81 | pte_t pte; \ |
| 82 | unsigned long pfn; \ |
| 83 | \ |
KAMEZAWA Hiroyuki | a0140c1 | 2006-03-27 01:15:55 -0800 | [diff] [blame] | 84 | pfn = page_to_pfn(page) << 32; \ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 85 | pte_val(pte) = pfn | pgprot_val(pgprot); \ |
| 86 | \ |
| 87 | pte; \ |
| 88 | }) |
| 89 | |
| 90 | #define pte_page(x) \ |
| 91 | ({ \ |
| 92 | unsigned long kvirt; \ |
| 93 | struct page * __xx; \ |
| 94 | \ |
| 95 | kvirt = (unsigned long)__va(pte_val(x) >> (32-PAGE_SHIFT)); \ |
| 96 | __xx = virt_to_page(kvirt); \ |
| 97 | \ |
| 98 | __xx; \ |
| 99 | }) |
| 100 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 101 | #define page_to_pa(page) \ |
KAMEZAWA Hiroyuki | 1c05dda | 2006-03-27 01:15:36 -0800 | [diff] [blame] | 102 | (page_to_pfn(page) << PAGE_SHIFT) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 103 | |
| 104 | #define pfn_to_nid(pfn) pa_to_nid(((u64)(pfn) << PAGE_SHIFT)) |
| 105 | #define pfn_valid(pfn) \ |
| 106 | (((pfn) - node_start_pfn(pfn_to_nid(pfn))) < \ |
| 107 | node_spanned_pages(pfn_to_nid(pfn))) \ |
| 108 | |
| 109 | #define virt_addr_valid(kaddr) pfn_valid((__pa(kaddr) >> PAGE_SHIFT)) |
| 110 | |
| 111 | #endif /* CONFIG_DISCONTIGMEM */ |
| 112 | |
| 113 | #endif /* _ASM_MMZONE_H_ */ |