1 /* SPDX-License-Identifier: Apache-2.0 */
2 /*
3 * Copyright (c) 2023 EPAM Systems
4 */
5
6 #include <zephyr/arch/arm64/hypercall.h>
7 #include <zephyr/xen/generic.h>
8 #include <zephyr/xen/public/memory.h>
9 #include <zephyr/xen/public/xen.h>
10
11 #include <zephyr/kernel.h>
12
xendom_add_to_physmap(int domid,unsigned long idx,unsigned int space,xen_pfn_t gpfn)13 int xendom_add_to_physmap(int domid, unsigned long idx,
14 unsigned int space, xen_pfn_t gpfn)
15 {
16 struct xen_add_to_physmap xatp = {
17 .domid = domid,
18 .idx = idx,
19 .space = space,
20 .gpfn = gpfn,
21 };
22
23 return HYPERVISOR_memory_op(XENMEM_add_to_physmap, &xatp);
24 }
25
xendom_add_to_physmap_batch(int domid,int foreign_domid,unsigned int space,unsigned int size,xen_ulong_t * idxs,xen_pfn_t * gpfns,int * errs)26 int xendom_add_to_physmap_batch(int domid, int foreign_domid,
27 unsigned int space, unsigned int size,
28 xen_ulong_t *idxs, xen_pfn_t *gpfns, int *errs)
29 {
30 struct xen_add_to_physmap_batch xatpb = {
31 .domid = domid,
32 .u.foreign_domid = foreign_domid,
33 .space = space,
34 .size = size,
35 };
36
37 set_xen_guest_handle(xatpb.gpfns, gpfns);
38 set_xen_guest_handle(xatpb.idxs, idxs);
39 set_xen_guest_handle(xatpb.errs, errs);
40
41 return HYPERVISOR_memory_op(XENMEM_add_to_physmap_batch, &xatpb);
42 }
43
xendom_remove_from_physmap(int domid,xen_pfn_t gpfn)44 int xendom_remove_from_physmap(int domid, xen_pfn_t gpfn)
45 {
46 struct xen_remove_from_physmap xrfp = {
47 .domid = domid,
48 .gpfn = gpfn,
49 };
50
51 return HYPERVISOR_memory_op(XENMEM_remove_from_physmap, &xrfp);
52 }
53
xendom_populate_physmap(int domid,unsigned int extent_order,unsigned int nr_extents,unsigned int mem_flags,xen_pfn_t * extent_start)54 int xendom_populate_physmap(int domid, unsigned int extent_order,
55 unsigned int nr_extents, unsigned int mem_flags,
56 xen_pfn_t *extent_start)
57 {
58 struct xen_memory_reservation reservation = {
59 .domid = domid,
60 .extent_order = extent_order,
61 .nr_extents = nr_extents,
62 .mem_flags = mem_flags,
63 };
64
65 set_xen_guest_handle(reservation.extent_start, extent_start);
66
67 return HYPERVISOR_memory_op(XENMEM_populate_physmap, &reservation);
68 }
69