• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /* SPDX-License-Identifier: GPL-2.0-only */
2 #ifndef __KVM_HYP_MEMORY_H
3 #define __KVM_HYP_MEMORY_H
4 
5 #include <asm/page.h>
6 
7 #include <linux/types.h>
8 
9 struct hyp_pool;
10 struct hyp_page {
11 	unsigned int refcount;
12 	unsigned int order;
13 	struct hyp_pool *pool;
14 	struct list_head node;
15 };
16 
17 extern s64 hyp_physvirt_offset;
18 extern u64 __hyp_vmemmap;
19 #define hyp_vmemmap ((struct hyp_page *)__hyp_vmemmap)
20 
21 #define __hyp_pa(virt)	((phys_addr_t)(virt) + hyp_physvirt_offset)
22 #define __hyp_va(phys)	((void *)((phys_addr_t)(phys) - hyp_physvirt_offset))
23 
hyp_phys_to_virt(phys_addr_t phys)24 static inline void *hyp_phys_to_virt(phys_addr_t phys)
25 {
26 	return __hyp_va(phys);
27 }
28 
hyp_virt_to_phys(void * addr)29 static inline phys_addr_t hyp_virt_to_phys(void *addr)
30 {
31 	return __hyp_pa(addr);
32 }
33 
34 #define hyp_phys_to_pfn(phys)	((phys) >> PAGE_SHIFT)
35 #define hyp_pfn_to_phys(pfn)	((phys_addr_t)((pfn) << PAGE_SHIFT))
36 #define hyp_phys_to_page(phys)	(&hyp_vmemmap[hyp_phys_to_pfn(phys)])
37 #define hyp_virt_to_page(virt)	hyp_phys_to_page(__hyp_pa(virt))
38 #define hyp_virt_to_pfn(virt)	hyp_phys_to_pfn(__hyp_pa(virt))
39 
40 #define hyp_page_to_pfn(page)	((struct hyp_page *)(page) - hyp_vmemmap)
41 #define hyp_page_to_phys(page)  hyp_pfn_to_phys((hyp_page_to_pfn(page)))
42 #define hyp_page_to_virt(page)	__hyp_va(hyp_page_to_phys(page))
43 #define hyp_page_to_pool(page)	(((struct hyp_page *)page)->pool)
44 
hyp_page_count(void * addr)45 static inline int hyp_page_count(void *addr)
46 {
47 	struct hyp_page *p = hyp_virt_to_page(addr);
48 
49 	return p->refcount;
50 }
51 
52 #endif /* __KVM_HYP_MEMORY_H */
53