xref: /openbmc/linux/arch/arm64/kvm/hyp/include/nvhe/gfp.h (revision d978b9cf)
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 
108e17c662SQuentin Perret #define HYP_NO_ORDER	UINT_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;
198e17c662SQuentin Perret 	struct list_head free_area[MAX_ORDER];
208e17c662SQuentin Perret 	phys_addr_t range_start;
218e17c662SQuentin Perret 	phys_addr_t range_end;
228e17c662SQuentin Perret 	unsigned int max_order;
238e17c662SQuentin Perret };
248e17c662SQuentin Perret 
258e17c662SQuentin Perret /* Allocation */
268e17c662SQuentin Perret void *hyp_alloc_pages(struct hyp_pool *pool, unsigned int order);
27*d978b9cfSQuentin Perret void hyp_get_page(struct hyp_pool *pool, void *addr);
28*d978b9cfSQuentin Perret void hyp_put_page(struct hyp_pool *pool, void *addr);
298e17c662SQuentin Perret 
308e17c662SQuentin Perret /* Used pages cannot be freed */
318e17c662SQuentin Perret int hyp_pool_init(struct hyp_pool *pool, u64 pfn, unsigned int nr_pages,
328e17c662SQuentin Perret 		  unsigned int reserved_pages);
338e17c662SQuentin Perret #endif /* __KVM_HYP_GFP_H */
34