Merge tag 'pull-fixes' of git://git.kernel.org/pub/scm/linux/kernel/git/viro/vfs
[linux-2.6-block.git] / include / asm-generic / memory_model.h
CommitLineData
b2441318 1/* SPDX-License-Identifier: GPL-2.0 */
a117e66e
KH
2#ifndef __ASM_MEMORY_MODEL_H
3#define __ASM_MEMORY_MODEL_H
4
8f235d1a
CG
5#include <linux/pfn.h>
6
a117e66e
KH
7#ifndef __ASSEMBLY__
8
bb1c50d3
MR
9/*
10 * supports 3 memory models.
11 */
a117e66e
KH
12#if defined(CONFIG_FLATMEM)
13
14#ifndef ARCH_PFN_OFFSET
15#define ARCH_PFN_OFFSET (0UL)
16#endif
17
67de6482
AW
18#define __pfn_to_page(pfn) (mem_map + ((pfn) - ARCH_PFN_OFFSET))
19#define __page_to_pfn(page) ((unsigned long)((page) - mem_map) + \
a117e66e 20 ARCH_PFN_OFFSET)
a117e66e 21
8f6aac41
CL
22#elif defined(CONFIG_SPARSEMEM_VMEMMAP)
23
af901ca1 24/* memmap is virtually contiguous. */
8f6aac41 25#define __pfn_to_page(pfn) (vmemmap + (pfn))
32272a26 26#define __page_to_pfn(page) (unsigned long)((page) - vmemmap)
8f6aac41 27
a117e66e
KH
28#elif defined(CONFIG_SPARSEMEM)
29/*
1a49123b 30 * Note: section's mem_map is encoded to reflect its start_pfn.
a117e66e
KH
31 * section[i].section_mem_map == mem_map's address - start_pfn;
32 */
67de6482 33#define __page_to_pfn(pg) \
aa462abe 34({ const struct page *__pg = (pg); \
a117e66e 35 int __sec = page_to_section(__pg); \
f05b6284 36 (unsigned long)(__pg - __section_mem_map_addr(__nr_to_section(__sec))); \
a117e66e
KH
37})
38
67de6482 39#define __pfn_to_page(pfn) \
a117e66e
KH
40({ unsigned long __pfn = (pfn); \
41 struct mem_section *__sec = __pfn_to_section(__pfn); \
42 __section_mem_map_addr(__sec) + __pfn; \
43})
bb1c50d3 44#endif /* CONFIG_FLATMEM/SPARSEMEM */
67de6482 45
012dcef3
CH
46/*
47 * Convert a physical address to a Page Frame Number and back
48 */
8f235d1a 49#define __phys_to_pfn(paddr) PHYS_PFN(paddr)
ae4f9769 50#define __pfn_to_phys(pfn) PFN_PHYS(pfn)
012dcef3 51
67de6482
AW
52#define page_to_pfn __page_to_pfn
53#define pfn_to_page __pfn_to_page
a117e66e
KH
54
55#endif /* __ASSEMBLY__ */
a117e66e
KH
56
57#endif