xref: /openbmc/linux/arch/arm64/kvm/hyp/include/nvhe/gfp.h (revision ded1ffea)
18e17c662SQuentin Perret /* SPDX-License-Identifier: GPL-2.0-only */
28e17c662SQuentin Perret #ifndef __KVM_HYP_GFP_H
38e17c662SQuentin Perret #define __KVM_HYP_GFP_H
48e17c662SQuentin Perret 
58e17c662SQuentin Perret #include <linux/list.h>
68e17c662SQuentin Perret 
78e17c662SQuentin Perret #include <nvhe/memory.h>
88e17c662SQuentin Perret #include <nvhe/spinlock.h>
98e17c662SQuentin Perret 
1087ec0606SQuentin Perret #define HYP_NO_ORDER	USHRT_MAX
118e17c662SQuentin Perret 
128e17c662SQuentin Perret struct hyp_pool {
138e17c662SQuentin Perret 	/*
148e17c662SQuentin Perret 	 * Spinlock protecting concurrent changes to the memory pool as well as
158e17c662SQuentin Perret 	 * the struct hyp_page of the pool's pages until we have a proper atomic
168e17c662SQuentin Perret 	 * API at EL2.
178e17c662SQuentin Perret 	 */
188e17c662SQuentin Perret 	hyp_spinlock_t lock;
19ded1ffeaSKirill A. Shutemov 	struct list_head free_area[NR_PAGE_ORDERS];
208e17c662SQuentin Perret 	phys_addr_t range_start;
218e17c662SQuentin Perret 	phys_addr_t range_end;
2287ec0606SQuentin Perret 	unsigned short max_order;
238e17c662SQuentin Perret };
248e17c662SQuentin Perret 
258e17c662SQuentin Perret /* Allocation */
2687ec0606SQuentin Perret void *hyp_alloc_pages(struct hyp_pool *pool, unsigned short order);
271d58a17eSQuentin Perret void hyp_split_page(struct hyp_page *page);
28d978b9cfSQuentin Perret void hyp_get_page(struct hyp_pool *pool, void *addr);
29d978b9cfSQuentin Perret void hyp_put_page(struct hyp_pool *pool, void *addr);
308e17c662SQuentin Perret 
318e17c662SQuentin Perret /* Used pages cannot be freed */
328e17c662SQuentin Perret int hyp_pool_init(struct hyp_pool *pool, u64 pfn, unsigned int nr_pages,
338e17c662SQuentin Perret 		  unsigned int reserved_pages);
348e17c662SQuentin Perret #endif /* __KVM_HYP_GFP_H */
35