Blame view
include/asm-generic/memory_model.h
2.12 KB
a117e66ed
|
1 2 |
#ifndef __ASM_MEMORY_MODEL_H #define __ASM_MEMORY_MODEL_H |
8f235d1a3
|
3 |
#include <linux/pfn.h> |
a117e66ed
|
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
#ifndef __ASSEMBLY__ #if defined(CONFIG_FLATMEM) #ifndef ARCH_PFN_OFFSET #define ARCH_PFN_OFFSET (0UL) #endif #elif defined(CONFIG_DISCONTIGMEM) #ifndef arch_pfn_to_nid #define arch_pfn_to_nid(pfn) pfn_to_nid(pfn) #endif #ifndef arch_local_page_offset #define arch_local_page_offset(pfn, nid) \ ((pfn) - NODE_DATA(nid)->node_start_pfn) #endif #endif /* CONFIG_DISCONTIGMEM */ |
a117e66ed
|
24 25 26 27 |
/* * supports 3 memory models. */ #if defined(CONFIG_FLATMEM) |
67de64821
|
28 29 |
#define __pfn_to_page(pfn) (mem_map + ((pfn) - ARCH_PFN_OFFSET)) #define __page_to_pfn(page) ((unsigned long)((page) - mem_map) + \ |
a117e66ed
|
30 31 |
ARCH_PFN_OFFSET) #elif defined(CONFIG_DISCONTIGMEM) |
67de64821
|
32 |
#define __pfn_to_page(pfn) \ |
a117e66ed
|
33 |
({ unsigned long __pfn = (pfn); \ |
c5d712433
|
34 |
unsigned long __nid = arch_pfn_to_nid(__pfn); \ |
a117e66ed
|
35 36 |
NODE_DATA(__nid)->node_mem_map + arch_local_page_offset(__pfn, __nid);\ }) |
67de64821
|
37 |
#define __page_to_pfn(pg) \ |
aa462abe8
|
38 |
({ const struct page *__pg = (pg); \ |
a0140c1d8
|
39 40 41 |
struct pglist_data *__pgdat = NODE_DATA(page_to_nid(__pg)); \ (unsigned long)(__pg - __pgdat->node_mem_map) + \ __pgdat->node_start_pfn; \ |
a117e66ed
|
42 |
}) |
8f6aac419
|
43 |
#elif defined(CONFIG_SPARSEMEM_VMEMMAP) |
af901ca18
|
44 |
/* memmap is virtually contiguous. */ |
8f6aac419
|
45 |
#define __pfn_to_page(pfn) (vmemmap + (pfn)) |
32272a269
|
46 |
#define __page_to_pfn(page) (unsigned long)((page) - vmemmap) |
8f6aac419
|
47 |
|
a117e66ed
|
48 49 |
#elif defined(CONFIG_SPARSEMEM) /* |
1a49123b3
|
50 |
* Note: section's mem_map is encoded to reflect its start_pfn. |
a117e66ed
|
51 52 |
* section[i].section_mem_map == mem_map's address - start_pfn; */ |
67de64821
|
53 |
#define __page_to_pfn(pg) \ |
aa462abe8
|
54 |
({ const struct page *__pg = (pg); \ |
a117e66ed
|
55 |
int __sec = page_to_section(__pg); \ |
f05b6284e
|
56 |
(unsigned long)(__pg - __section_mem_map_addr(__nr_to_section(__sec))); \ |
a117e66ed
|
57 |
}) |
67de64821
|
58 |
#define __pfn_to_page(pfn) \ |
a117e66ed
|
59 60 61 62 63 |
({ unsigned long __pfn = (pfn); \ struct mem_section *__sec = __pfn_to_section(__pfn); \ __section_mem_map_addr(__sec) + __pfn; \ }) #endif /* CONFIG_FLATMEM/DISCONTIGMEM/SPARSEMEM */ |
67de64821
|
64 |
|
012dcef3f
|
65 66 67 |
/* * Convert a physical address to a Page Frame Number and back */ |
8f235d1a3
|
68 |
#define __phys_to_pfn(paddr) PHYS_PFN(paddr) |
ae4f97696
|
69 |
#define __pfn_to_phys(pfn) PFN_PHYS(pfn) |
012dcef3f
|
70 |
|
67de64821
|
71 72 |
#define page_to_pfn __page_to_pfn #define pfn_to_page __pfn_to_page |
a117e66ed
|
73 74 |
#endif /* __ASSEMBLY__ */ |
a117e66ed
|
75 76 |
#endif |