Skip to content

Commit 0d2b494

Browse files
linuswmichalsimek
authored andcommitted
microblaze: Make virt_to_pfn() a static inline
Making virt_to_pfn() a static inline taking a strongly typed (const void *) makes the contract of a passing a pointer of that type to the function explicit and exposes any misuse of the macro virt_to_pfn() acting polymorphic and accepting many types such as (void *), (unitptr_t) or (unsigned long) as arguments without warnings. Move the function down in the file so __pa() exists in our scope, and it compiles. This in turn requires moving __pa() as it depends on __virt_to_phys() that was below. (Lazy macro evaluation conflicts with strict function ordering.) Make a symmetric change to pfn_to_virt() so we have type checking both ways. Due to this the <asm/page.h> file being included into some assembly files, some further inclusion guards are needed to make sure assembly keeps compiling. Signed-off-by: Linus Walleij <linus.walleij@linaro.org> Link: https://lore.kernel.org/r/20230808-virt-to-phys-microblaze-v1-1-e6df710fe0a1@linaro.org Signed-off-by: Michal Simek <michal.simek@amd.com>
1 parent b48edb8 commit 0d2b494

File tree

1 file changed

+19
-8
lines changed
  • arch/microblaze/include/asm

1 file changed

+19
-8
lines changed

arch/microblaze/include/asm/page.h

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -99,21 +99,13 @@ extern int page_is_ram(unsigned long pfn);
9999
# define phys_to_pfn(phys) (PFN_DOWN(phys))
100100
# define pfn_to_phys(pfn) (PFN_PHYS(pfn))
101101

102-
# define virt_to_pfn(vaddr) (phys_to_pfn((__pa(vaddr))))
103-
# define pfn_to_virt(pfn) __va(pfn_to_phys((pfn)))
104-
105102
# define virt_to_page(kaddr) (pfn_to_page(__pa(kaddr) >> PAGE_SHIFT))
106103
# define page_to_virt(page) __va(page_to_pfn(page) << PAGE_SHIFT)
107104
# define page_to_phys(page) (page_to_pfn(page) << PAGE_SHIFT)
108105

109106
# define ARCH_PFN_OFFSET (memory_start >> PAGE_SHIFT)
110107
# endif /* __ASSEMBLY__ */
111108

112-
#define virt_addr_valid(vaddr) (pfn_valid(virt_to_pfn(vaddr)))
113-
114-
# define __pa(x) __virt_to_phys((unsigned long)(x))
115-
# define __va(x) ((void *)__phys_to_virt((unsigned long)(x)))
116-
117109
/* Convert between virtual and physical address for MMU. */
118110
/* Handle MicroBlaze processor with virtual memory. */
119111
#define __virt_to_phys(addr) \
@@ -125,6 +117,25 @@ extern int page_is_ram(unsigned long pfn);
125117
#define tovirt(rd, rs) \
126118
addik rd, rs, (CONFIG_KERNEL_START - CONFIG_KERNEL_BASE_ADDR)
127119

120+
#ifndef __ASSEMBLY__
121+
122+
# define __pa(x) __virt_to_phys((unsigned long)(x))
123+
# define __va(x) ((void *)__phys_to_virt((unsigned long)(x)))
124+
125+
static inline unsigned long virt_to_pfn(const void *vaddr)
126+
{
127+
return phys_to_pfn(__pa(vaddr));
128+
}
129+
130+
static inline const void *pfn_to_virt(unsigned long pfn)
131+
{
132+
return __va(pfn_to_phys((pfn)));
133+
}
134+
135+
#define virt_addr_valid(vaddr) (pfn_valid(virt_to_pfn(vaddr)))
136+
137+
#endif /* __ASSEMBLY__ */
138+
128139
#define TOPHYS(addr) __virt_to_phys(addr)
129140

130141
#endif /* __KERNEL__ */

0 commit comments

Comments
 (0)