mirror of
https://github.com/torvalds/linux.git
synced 2025-04-09 14:45:27 +00:00

max_mapnr is essentially the size of the memory map for systems that use FLATMEM. There is no reason to calculate it in each and every architecture when it's anyway calculated in alloc_node_mem_map(). Drop setting of max_mapnr from architecture code and set it once in alloc_node_mem_map(). While on it, move definition of mem_map and max_mapnr to mm/mm_init.c so there won't be two copies for MMU and !MMU variants. Link: https://lkml.kernel.org/r/20250313135003.836600-10-rppt@kernel.org Signed-off-by: Mike Rapoport (Microsoft) <rppt@kernel.org> Acked-by: Dave Hansen <dave.hansen@linux.intel.com> [x86] Tested-by: Mark Brown <broonie@kernel.org> Cc: Alexander Gordeev <agordeev@linux.ibm.com> Cc: Andreas Larsson <andreas@gaisler.com> Cc: Andy Lutomirski <luto@kernel.org> Cc: Ard Biesheuvel <ardb@kernel.org> Cc: Arnd Bergmann <arnd@arndb.de> Cc: Borislav Betkov <bp@alien8.de> Cc: Catalin Marinas <catalin.marinas@arm.com> Cc: David S. Miller <davem@davemloft.net> Cc: Dinh Nguyen <dinguyen@kernel.org> Cc: Geert Uytterhoeven <geert@linux-m68k.org> Cc: Gerald Schaefer <gerald.schaefer@linux.ibm.com> Cc: Guo Ren (csky) <guoren@kernel.org> Cc: Heiko Carstens <hca@linux.ibm.com> Cc: Helge Deller <deller@gmx.de> Cc: Huacai Chen <chenhuacai@kernel.org> Cc: Ingo Molnar <mingo@redhat.com> Cc: Jiaxun Yang <jiaxun.yang@flygoat.com> Cc: Johannes Berg <johannes@sipsolutions.net> Cc: John Paul Adrian Glaubitz <glaubitz@physik.fu-berlin.de> Cc: Madhavan Srinivasan <maddy@linux.ibm.com> Cc: Matt Turner <mattst88@gmail.com> Cc: Max Filippov <jcmvbkbc@gmail.com> Cc: Michael Ellerman <mpe@ellerman.id.au> Cc: Michal Simek <monstr@monstr.eu> Cc: Palmer Dabbelt <palmer@dabbelt.com> Cc: Richard Weinberger <richard@nod.at> Cc: Russel King <linux@armlinux.org.uk> Cc: Stafford Horne <shorne@gmail.com> Cc: Thomas Bogendoerfer <tsbogend@alpha.franken.de> Cc: Thomas Gleinxer <tglx@linutronix.de> Cc: Vasily Gorbik <gor@linux.ibm.com> Cc: Vineet Gupta <vgupta@kernel.org> Cc: Will Deacon <will@kernel.org> Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
84 lines
2.0 KiB
C
84 lines
2.0 KiB
C
/* SPDX-License-Identifier: GPL-2.0 */
|
|
#ifndef __ASM_MEMORY_MODEL_H
|
|
#define __ASM_MEMORY_MODEL_H
|
|
|
|
#include <linux/pfn.h>
|
|
|
|
#ifndef __ASSEMBLY__
|
|
|
|
/*
|
|
* supports 3 memory models.
|
|
*/
|
|
#if defined(CONFIG_FLATMEM)
|
|
|
|
#ifndef ARCH_PFN_OFFSET
|
|
#define ARCH_PFN_OFFSET (0UL)
|
|
#endif
|
|
|
|
#define __pfn_to_page(pfn) (mem_map + ((pfn) - ARCH_PFN_OFFSET))
|
|
#define __page_to_pfn(page) ((unsigned long)((page) - mem_map) + \
|
|
ARCH_PFN_OFFSET)
|
|
|
|
/* avoid <linux/mm.h> include hell */
|
|
extern unsigned long max_mapnr;
|
|
|
|
#ifndef pfn_valid
|
|
static inline int pfn_valid(unsigned long pfn)
|
|
{
|
|
unsigned long pfn_offset = ARCH_PFN_OFFSET;
|
|
|
|
return pfn >= pfn_offset && (pfn - pfn_offset) < max_mapnr;
|
|
}
|
|
#define pfn_valid pfn_valid
|
|
#endif
|
|
|
|
#elif defined(CONFIG_SPARSEMEM_VMEMMAP)
|
|
|
|
/* memmap is virtually contiguous. */
|
|
#define __pfn_to_page(pfn) (vmemmap + (pfn))
|
|
#define __page_to_pfn(page) (unsigned long)((page) - vmemmap)
|
|
|
|
#elif defined(CONFIG_SPARSEMEM)
|
|
/*
|
|
* Note: section's mem_map is encoded to reflect its start_pfn.
|
|
* section[i].section_mem_map == mem_map's address - start_pfn;
|
|
*/
|
|
#define __page_to_pfn(pg) \
|
|
({ const struct page *__pg = (pg); \
|
|
int __sec = page_to_section(__pg); \
|
|
(unsigned long)(__pg - __section_mem_map_addr(__nr_to_section(__sec))); \
|
|
})
|
|
|
|
#define __pfn_to_page(pfn) \
|
|
({ unsigned long __pfn = (pfn); \
|
|
struct mem_section *__sec = __pfn_to_section(__pfn); \
|
|
__section_mem_map_addr(__sec) + __pfn; \
|
|
})
|
|
#endif /* CONFIG_FLATMEM/SPARSEMEM */
|
|
|
|
/*
|
|
* Convert a physical address to a Page Frame Number and back
|
|
*/
|
|
#define __phys_to_pfn(paddr) PHYS_PFN(paddr)
|
|
#define __pfn_to_phys(pfn) PFN_PHYS(pfn)
|
|
|
|
#define page_to_pfn __page_to_pfn
|
|
#define pfn_to_page __pfn_to_page
|
|
|
|
#ifdef CONFIG_DEBUG_VIRTUAL
|
|
#define page_to_phys(page) \
|
|
({ \
|
|
unsigned long __pfn = page_to_pfn(page); \
|
|
\
|
|
WARN_ON_ONCE(!pfn_valid(__pfn)); \
|
|
PFN_PHYS(__pfn); \
|
|
})
|
|
#else
|
|
#define page_to_phys(page) PFN_PHYS(page_to_pfn(page))
|
|
#endif /* CONFIG_DEBUG_VIRTUAL */
|
|
#define phys_to_page(phys) pfn_to_page(PHYS_PFN(phys))
|
|
|
|
#endif /* __ASSEMBLY__ */
|
|
|
|
#endif
|