xref: /linux/arch/riscv/mm/physaddr.c (revision 1ac731c529cd4d6adbce134754b51ff7d822b145)
16435f773SZong Li // SPDX-License-Identifier: GPL-2.0
26435f773SZong Li 
36435f773SZong Li #include <linux/types.h>
46435f773SZong Li #include <linux/mmdebug.h>
56435f773SZong Li #include <linux/mm.h>
66435f773SZong Li #include <asm/page.h>
76435f773SZong Li #include <asm/sections.h>
86435f773SZong Li 
__virt_to_phys(unsigned long x)96435f773SZong Li phys_addr_t __virt_to_phys(unsigned long x)
106435f773SZong Li {
116435f773SZong Li 	/*
126435f773SZong Li 	 * Boundary checking aginst the kernel linear mapping space.
136435f773SZong Li 	 */
145f763b3bSAlexandre Ghiti 	WARN(!is_linear_mapping(x) && !is_kernel_mapping(x),
156435f773SZong Li 	     "virt_to_phys used for non-linear address: %pK (%pS)\n",
166435f773SZong Li 	     (void *)x, (void *)x);
176435f773SZong Li 
186435f773SZong Li 	return __va_to_pa_nodebug(x);
196435f773SZong Li }
206435f773SZong Li EXPORT_SYMBOL(__virt_to_phys);
216435f773SZong Li 
__phys_addr_symbol(unsigned long x)226435f773SZong Li phys_addr_t __phys_addr_symbol(unsigned long x)
236435f773SZong Li {
24658e2c51SAlexandre Ghiti 	unsigned long kernel_start = kernel_map.virt_addr;
250c496881SSamuel Holland 	unsigned long kernel_end = kernel_start + kernel_map.size;
266435f773SZong Li 
276435f773SZong Li 	/*
286435f773SZong Li 	 * Boundary checking aginst the kernel image mapping.
296435f773SZong Li 	 * __pa_symbol should only be used on kernel symbol addresses.
306435f773SZong Li 	 */
316435f773SZong Li 	VIRTUAL_BUG_ON(x < kernel_start || x > kernel_end);
326435f773SZong Li 
336435f773SZong Li 	return __va_to_pa_nodebug(x);
346435f773SZong Li }
356435f773SZong Li EXPORT_SYMBOL(__phys_addr_symbol);
36*3335068fSAlexandre Ghiti 
linear_mapping_va_to_pa(unsigned long x)37*3335068fSAlexandre Ghiti phys_addr_t linear_mapping_va_to_pa(unsigned long x)
38*3335068fSAlexandre Ghiti {
39*3335068fSAlexandre Ghiti 	BUG_ON(!kernel_map.va_pa_offset);
40*3335068fSAlexandre Ghiti 
41*3335068fSAlexandre Ghiti 	return ((unsigned long)(x) - kernel_map.va_pa_offset);
42*3335068fSAlexandre Ghiti }
43*3335068fSAlexandre Ghiti EXPORT_SYMBOL(linear_mapping_va_to_pa);
44*3335068fSAlexandre Ghiti 
linear_mapping_pa_to_va(unsigned long x)45*3335068fSAlexandre Ghiti void *linear_mapping_pa_to_va(unsigned long x)
46*3335068fSAlexandre Ghiti {
47*3335068fSAlexandre Ghiti 	BUG_ON(!kernel_map.va_pa_offset);
48*3335068fSAlexandre Ghiti 
49*3335068fSAlexandre Ghiti 	return ((void *)((unsigned long)(x) + kernel_map.va_pa_offset));
50*3335068fSAlexandre Ghiti }
51*3335068fSAlexandre Ghiti EXPORT_SYMBOL(linear_mapping_pa_to_va);
52