forked from Qortal/Brooklyn
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
54 lines
1.1 KiB
54 lines
1.1 KiB
// SPDX-License-Identifier: GPL-2.0-only |
|
/* |
|
* Copyright (C) 2020 Google LLC |
|
* Author: Quentin Perret <[email protected]> |
|
*/ |
|
|
|
#include <asm/kvm_pgtable.h> |
|
|
|
#include <nvhe/early_alloc.h> |
|
#include <nvhe/memory.h> |
|
|
|
struct kvm_pgtable_mm_ops hyp_early_alloc_mm_ops; |
|
s64 __ro_after_init hyp_physvirt_offset; |
|
|
|
static unsigned long base; |
|
static unsigned long end; |
|
static unsigned long cur; |
|
|
|
unsigned long hyp_early_alloc_nr_used_pages(void) |
|
{ |
|
return (cur - base) >> PAGE_SHIFT; |
|
} |
|
|
|
void *hyp_early_alloc_contig(unsigned int nr_pages) |
|
{ |
|
unsigned long size = (nr_pages << PAGE_SHIFT); |
|
void *ret = (void *)cur; |
|
|
|
if (!nr_pages) |
|
return NULL; |
|
|
|
if (end - cur < size) |
|
return NULL; |
|
|
|
cur += size; |
|
memset(ret, 0, size); |
|
|
|
return ret; |
|
} |
|
|
|
void *hyp_early_alloc_page(void *arg) |
|
{ |
|
return hyp_early_alloc_contig(1); |
|
} |
|
|
|
void hyp_early_alloc_init(void *virt, unsigned long size) |
|
{ |
|
base = cur = (unsigned long)virt; |
|
end = base + size; |
|
|
|
hyp_early_alloc_mm_ops.zalloc_page = hyp_early_alloc_page; |
|
hyp_early_alloc_mm_ops.phys_to_virt = hyp_phys_to_virt; |
|
hyp_early_alloc_mm_ops.virt_to_phys = hyp_virt_to_phys; |
|
}
|
|
|