| // SPDX-License-Identifier: GPL-2.0-only |
| /* |
| * Copyright (C) 2020 Google, inc |
| * Author: Quentin Perret <qperret@google.com> |
| */ |
| |
| #include <asm/kvm_pgtable.h> |
| |
| #include <nvhe/memory.h> |
| |
| s64 hyp_physvirt_offset; |
| struct kvm_pgtable_mm_ops hyp_early_alloc_mm_ops; |
| |
| static unsigned long base; |
| static unsigned long end; |
| static unsigned long cur; |
| |
| unsigned long hyp_early_alloc_nr_pages(void) |
| { |
| return (cur - base) >> PAGE_SHIFT; |
| } |
| |
| extern void clear_page(void *to); |
| void * hyp_early_alloc_page(void *arg) |
| { |
| unsigned long ret = cur; |
| |
| cur += PAGE_SIZE; |
| if (cur > end) { |
| cur = ret; |
| return NULL; |
| } |
| clear_page((void*)ret); |
| |
| return (void *)ret; |
| } |
| |
| void hyp_early_alloc_init(unsigned long virt, unsigned long size) |
| { |
| base = virt; |
| end = virt + size; |
| cur = virt; |
| |
| 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; |
| } |