Path: blob/master/arch/arm64/kvm/hyp/nvhe/early_alloc.c
26516 views
// SPDX-License-Identifier: GPL-2.0-only1/*2* Copyright (C) 2020 Google LLC3* Author: Quentin Perret <[email protected]>4*/56#include <asm/kvm_pgtable.h>78#include <nvhe/early_alloc.h>9#include <nvhe/memory.h>1011struct kvm_pgtable_mm_ops hyp_early_alloc_mm_ops;12s64 __ro_after_init hyp_physvirt_offset;1314static unsigned long base;15static unsigned long end;16static unsigned long cur;1718unsigned long hyp_early_alloc_nr_used_pages(void)19{20return (cur - base) >> PAGE_SHIFT;21}2223void *hyp_early_alloc_contig(unsigned int nr_pages)24{25unsigned long size = (nr_pages << PAGE_SHIFT);26void *ret = (void *)cur;2728if (!nr_pages)29return NULL;3031if (end - cur < size)32return NULL;3334cur += size;35memset(ret, 0, size);3637return ret;38}3940void *hyp_early_alloc_page(void *arg)41{42return hyp_early_alloc_contig(1);43}4445static void hyp_early_alloc_get_page(void *addr) { }46static void hyp_early_alloc_put_page(void *addr) { }4748void hyp_early_alloc_init(void *virt, unsigned long size)49{50base = cur = (unsigned long)virt;51end = base + size;5253hyp_early_alloc_mm_ops.zalloc_page = hyp_early_alloc_page;54hyp_early_alloc_mm_ops.phys_to_virt = hyp_phys_to_virt;55hyp_early_alloc_mm_ops.virt_to_phys = hyp_virt_to_phys;56hyp_early_alloc_mm_ops.get_page = hyp_early_alloc_get_page;57hyp_early_alloc_mm_ops.put_page = hyp_early_alloc_put_page;58}596061