ANDROID: virt: gunyah: Add a gunyah hcall for ioremap

Add a gunyah hook for ioremap to let the hypervisor know what
iomem regions are being used by the guest.

Bug: 424772814
Change-Id: I46b25f704fcd2c35d16558718e36eef560f56bb9
Signed-off-by: Prakruthi Deepak Heragu <quic_pheragu@quicinc.com>
This commit is contained in:
Prakruthi Deepak Heragu
2025-06-10 12:25:03 -07:00
committed by Treehugger Robot
parent a7c066a30e
commit 52cc64794a
3 changed files with 58 additions and 3 deletions

View File

@@ -44,6 +44,7 @@ EXPORT_SYMBOL_GPL(arch_is_gunyah_guest);
#define GUNYAH_HYPERCALL_MSGQ_RECV GUNYAH_HYPERCALL(0x801C)
#define GUNYAH_HYPERCALL_ADDRSPACE_MAP GUNYAH_HYPERCALL(0x802B)
#define GUNYAH_HYPERCALL_ADDRSPACE_UNMAP GUNYAH_HYPERCALL(0x802C)
#define GUNYAH_HYPERCALL_ADDRSPACE_CONFIG_VMMIO_RANGE GUNYAH_HYPERCALL(0x8060)
#define GUNYAH_HYPERCALL_MEMEXTENT_DONATE GUNYAH_HYPERCALL(0x8061)
#define GUNYAH_HYPERCALL_VCPU_RUN GUNYAH_HYPERCALL(0x8065)
#define GUNYAH_HYPERCALL_ADDRSPC_MODIFY_PAGES GUNYAH_HYPERCALL(0x8069)
@@ -81,6 +82,34 @@ enum gunyah_error gunyah_hypercall_addrspc_modify_pages(u64 capid, u64 addr,
}
EXPORT_SYMBOL_GPL(gunyah_hypercall_addrspc_modify_pages);
/**
* gunyah_hypercall_addrspc_configure_vmmio_range() - Configure virtual MMIO device regions for
* the address space.
* @capid: Address space capability ID
* @base: Base guest address of MMIO region
* @size: Size of the MMIO region
* @op: Map or Unmap
*/
enum gunyah_error gunyah_hypercall_addrspc_configure_vmmio_range(u64 capid, u64 base,
u64 size, u64 op)
{
struct arm_smccc_1_2_regs args = {
.a0 = GUNYAH_HYPERCALL_ADDRSPACE_CONFIG_VMMIO_RANGE,
.a1 = capid,
.a2 = base,
.a3 = size,
.a4 = op,
/* Reserved. Must be 0 */
.a5 = 0,
};
struct arm_smccc_1_2_regs res;
arm_smccc_1_2_hvc(&args, &res);
return res.a0;
}
EXPORT_SYMBOL_GPL(gunyah_hypercall_addrspc_configure_vmmio_range);
/**
* gunyah_hypercall_bell_send() - Assert a gunyah doorbell
* @capid: capability ID of the doorbell

View File

@@ -1,8 +1,10 @@
// SPDX-License-Identifier: GPL-2.0
/* Copyright (c) 2025 Qualcomm Innovation Center, Inc. All rights reserved. */
/* Copyright (c) Qualcomm Technologies, Inc. and/or its subsidiaries. */
#include <linux/gunyah.h>
#include <linux/init.h>
#include <linux/io.h>
#include <linux/pgtable.h>
#include <linux/virtio_balloon.h>
#include <asm/hypervisor.h>
@@ -16,6 +18,28 @@ struct addrspace_info_area_rootvm_addrspace_cap {
static u64 our_addrspace_capid;
static int gunyah_mmio_guard_ioremap_hook(phys_addr_t phys, size_t size, pgprot_t *prot)
{
pteval_t protval = pgprot_val(*prot);
int ret;
/*
* We only expect MMIO emulation for regions mapped with device
* attributes.
*/
if (protval != PROT_DEVICE_nGnRE && protval != PROT_DEVICE_nGnRnE)
return 0;
ret = gunyah_hypercall_addrspc_configure_vmmio_range(our_addrspace_capid,
phys, size, GUNYAH_ADDRSPACE_VMMIO_CONFIGURE_OP_ADD_RANGE);
if (ret == GUNYAH_ERROR_UNIMPLEMENTED || ret == GUNYAH_ERROR_BUSY)
/* Gunyah would have configured VMMIO via DT */
ret = GUNYAH_ERROR_OK;
return gunyah_error_remap(ret);
}
#ifdef CONFIG_VIRTIO_BALLOON_HYP_OPS
static void gunyah_page_relinquish(struct page *page, unsigned int nr)
{
@@ -71,6 +95,7 @@ static int __init gunyah_guest_init(void)
our_addrspace_capid = info->addrspace_cap;
arm64_ioremap_prot_hook_register(&gunyah_mmio_guard_ioremap_hook);
#ifdef CONFIG_VIRTIO_BALLOON_HYP_OPS
virtio_balloon_hyp_ops = &gunyah_virtio_balloon_hyp_ops;
#endif

View File

@@ -600,8 +600,9 @@ gunyah_hypercall_vcpu_run(u64 capid, unsigned long *resume_data,
#define GUNYAH_ADDRSPC_MODIFY_FLAG_SANITIZE_BIT 1
enum gunyah_error
gunyah_hypercall_addrspc_modify_pages(u64 capid, u64 addr, u64 size, u64 flags);
enum gunyah_error
gunyah_hypercall_addrspace_find_info_area(unsigned long *ipa, unsigned long *size);
enum gunyah_error
#define GUNYAH_ADDRSPACE_VMMIO_CONFIGURE_OP_ADD_RANGE 0
gunyah_hypercall_addrspc_configure_vmmio_range(u64 capid, u64 base, u64 size, u64 op);
#endif