KVM
Classes | Macros | Functions
gfp.h File Reference
#include <linux/list.h>
#include <nvhe/memory.h>
#include <nvhe/spinlock.h>
Include dependency graph for gfp.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  hyp_pool
 

Macros

#define HYP_NO_ORDER   USHRT_MAX
 

Functions

void * hyp_alloc_pages (struct hyp_pool *pool, unsigned short order)
 
void hyp_split_page (struct hyp_page *page)
 
void hyp_get_page (struct hyp_pool *pool, void *addr)
 
void hyp_put_page (struct hyp_pool *pool, void *addr)
 
int hyp_pool_init (struct hyp_pool *pool, u64 pfn, unsigned int nr_pages, unsigned int reserved_pages)
 

Macro Definition Documentation

◆ HYP_NO_ORDER

#define HYP_NO_ORDER   USHRT_MAX

Definition at line 10 of file gfp.h.

Function Documentation

◆ hyp_alloc_pages()

void* hyp_alloc_pages ( struct hyp_pool pool,
unsigned short  order 
)

Definition at line 198 of file page_alloc.c.

199 {
200  unsigned short i = order;
201  struct hyp_page *p;
202 
203  hyp_spin_lock(&pool->lock);
204 
205  /* Look for a high-enough-order page */
206  while (i <= pool->max_order && list_empty(&pool->free_area[i]))
207  i++;
208  if (i > pool->max_order) {
209  hyp_spin_unlock(&pool->lock);
210  return NULL;
211  }
212 
213  /* Extract it from the tree at the right order */
214  p = node_to_page(pool->free_area[i].next);
215  p = __hyp_extract_page(pool, p, order);
216 
218  hyp_spin_unlock(&pool->lock);
219 
220  return hyp_page_to_virt(p);
221 }
#define hyp_page_to_virt(page)
Definition: memory.h:38
static void hyp_set_page_refcounted(struct hyp_page *p)
Definition: memory.h:70
static struct hyp_page * __hyp_extract_page(struct hyp_pool *pool, struct hyp_page *p, unsigned short order)
Definition: page_alloc.c:130
static struct hyp_page * node_to_page(struct list_head *node)
Definition: page_alloc.c:88
static void hyp_spin_unlock(hyp_spinlock_t *lock)
Definition: spinlock.h:82
static void hyp_spin_lock(hyp_spinlock_t *lock)
Definition: spinlock.h:44
unsigned short order
Definition: memory.h:12
hyp_spinlock_t lock
Definition: gfp.h:18
unsigned short max_order
Definition: gfp.h:22
struct list_head free_area[NR_PAGE_ORDERS]
Definition: gfp.h:19
Here is the call graph for this function:
Here is the caller graph for this function:

◆ hyp_get_page()

void hyp_get_page ( struct hyp_pool pool,
void *  addr 
)

Definition at line 175 of file page_alloc.c.

176 {
177  struct hyp_page *p = hyp_virt_to_page(addr);
178 
179  hyp_spin_lock(&pool->lock);
180  hyp_page_ref_inc(p);
181  hyp_spin_unlock(&pool->lock);
182 }
#define hyp_virt_to_page(virt)
Definition: memory.h:33
static void hyp_page_ref_inc(struct hyp_page *p)
Definition: memory.h:52
Here is the call graph for this function:
Here is the caller graph for this function:

◆ hyp_pool_init()

int hyp_pool_init ( struct hyp_pool pool,
u64  pfn,
unsigned int  nr_pages,
unsigned int  reserved_pages 
)

Definition at line 223 of file page_alloc.c.

225 {
226  phys_addr_t phys = hyp_pfn_to_phys(pfn);
227  struct hyp_page *p;
228  int i;
229 
230  hyp_spin_lock_init(&pool->lock);
231  pool->max_order = min(MAX_PAGE_ORDER,
232  get_order(nr_pages << PAGE_SHIFT));
233  for (i = 0; i <= pool->max_order; i++)
234  INIT_LIST_HEAD(&pool->free_area[i]);
235  pool->range_start = phys;
236  pool->range_end = phys + (nr_pages << PAGE_SHIFT);
237 
238  /* Init the vmemmap portion */
239  p = hyp_phys_to_page(phys);
240  for (i = 0; i < nr_pages; i++)
242 
243  /* Attach the unused pages to the buddy tree */
244  for (i = reserved_pages; i < nr_pages; i++)
245  __hyp_put_page(pool, &p[i]);
246 
247  return 0;
248 }
#define hyp_phys_to_page(phys)
Definition: memory.h:32
#define hyp_pfn_to_phys(pfn)
Definition: memory.h:31
static void __hyp_put_page(struct hyp_pool *pool, struct hyp_page *p)
Definition: page_alloc.c:153
#define hyp_spin_lock_init(l)
Definition: spinlock.h:39
phys_addr_t range_end
Definition: gfp.h:21
phys_addr_t range_start
Definition: gfp.h:20
Here is the call graph for this function:
Here is the caller graph for this function:

◆ hyp_put_page()

void hyp_put_page ( struct hyp_pool pool,
void *  addr 
)

Definition at line 166 of file page_alloc.c.

167 {
168  struct hyp_page *p = hyp_virt_to_page(addr);
169 
170  hyp_spin_lock(&pool->lock);
171  __hyp_put_page(pool, p);
172  hyp_spin_unlock(&pool->lock);
173 }
Here is the call graph for this function:
Here is the caller graph for this function:

◆ hyp_split_page()

void hyp_split_page ( struct hyp_page page)

Definition at line 184 of file page_alloc.c.

185 {
186  unsigned short order = p->order;
187  unsigned int i;
188 
189  p->order = 0;
190  for (i = 1; i < (1 << order); i++) {
191  struct hyp_page *tail = p + i;
192 
193  tail->order = 0;
195  }
196 }
Here is the call graph for this function:
Here is the caller graph for this function: