Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions drivers/xen/memory.c
Original file line number Diff line number Diff line change
Expand Up @@ -66,3 +66,25 @@ int xendom_populate_physmap(int domid, unsigned int extent_order,

return HYPERVISOR_memory_op(XENMEM_populate_physmap, &reservation);
}

int xendom_acquire_resource(domid_t domid, uint16_t type, uint32_t id, uint64_t frame,
uint32_t *nr_frames, xen_pfn_t *frame_list)
{
struct xen_mem_acquire_resource acquire_res = {
.domid = domid,
.type = type,
.id = id,
.pad = 0,
.frame = frame,
.nr_frames = *nr_frames,
};
int ret;

set_xen_guest_handle(acquire_res.frame_list, frame_list);

ret = HYPERVISOR_memory_op(XENMEM_acquire_resource, &acquire_res);

*nr_frames = acquire_res.nr_frames;

return ret;
}
25 changes: 25 additions & 0 deletions include/zephyr/xen/memory.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
* Copyright (c) 2023 EPAM Systems
*/

#ifndef ZEPHYR_XEN_MEMORY_H_
#define ZEPHYR_XEN_MEMORY_H_

#include <zephyr/kernel.h>
#include <zephyr/xen/public/memory.h>
#include <zephyr/xen/public/xen.h>
Expand Down Expand Up @@ -64,3 +67,25 @@ int xendom_remove_from_physmap(int domid, xen_pfn_t gpfn);
int xendom_populate_physmap(int domid, unsigned int extent_order,
unsigned int nr_extents, unsigned int mem_flags,
xen_pfn_t *extent_start);

/**
* @brief Acquire a resource mapping for the Xen domain.
*
* Issues the XENMEM_acquire_resource hypercall to map a resource buffer
* (e.g., I/O request server, grant table, VM trace buffer) into the
* specified domain's physmap, or query its total size.
*
* @param domid Target domain identifier. Use DOMID_SELF for the calling domain.
* @param type Resource type identifier (e.g., XENMEM_resource_ioreq_server).
* @param id Resource-specific identifier (e.g., server ID or table ID).
* @param frame Starting frame number for mapping, or ignored if *nr_frames == 0.
* @param nr_frames [in,out] On input, number of frames to map; on return,
* number of frames actually mapped (or total frames if queried).
* @param frame_list Guest frame list buffer: input GFNs for HVM guests,
* output MFNs for PV guests.
* @return Zero on success, or a negative errno code on failure.
*/
int xendom_acquire_resource(domid_t domid, uint16_t type, uint32_t id, uint64_t frame,
uint32_t *nr_frames, xen_pfn_t *frame_list);

#endif /* ZEPHYR_XEN_MEMORY_H_ */
78 changes: 78 additions & 0 deletions include/zephyr/xen/public/memory.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* SPDX-License-Identifier: MIT */

Check warning on line 1 in include/zephyr/xen/public/memory.h

View workflow job for this annotation

GitHub Actions / Run compliance checks on patch series (PR)

License may not be allowed

include/zephyr/xen/public/memory.h:1 License file for 'MIT' not found in /LICENSES. Please check https://docs.zephyrproject.org/latest/contribute/guidelines.html#components-using-other-licenses.

/******************************************************************************
* memory.h
Expand Down Expand Up @@ -161,4 +161,82 @@
typedef struct xen_remove_from_physmap xen_remove_from_physmap_t;
DEFINE_XEN_GUEST_HANDLE(xen_remove_from_physmap_t);

/*
* Get the pages for a particular guest resource, so that they can be
* mapped directly by a tools domain.
*/
#define XENMEM_acquire_resource 28
struct xen_mem_acquire_resource {
/* IN - The domain whose resource is to be mapped */
domid_t domid;
/* IN - the type of resource */
uint16_t type;

#define XENMEM_resource_ioreq_server 0
#define XENMEM_resource_grant_table 1
#define XENMEM_resource_vmtrace_buf 2

/*
* IN - a type-specific resource identifier, which must be zero
* unless stated otherwise.
*
* type == XENMEM_resource_ioreq_server -> id == ioreq server id
* type == XENMEM_resource_grant_table -> id defined below
*/
uint32_t id;

#define XENMEM_resource_grant_table_id_shared 0
#define XENMEM_resource_grant_table_id_status 1

/*
* IN/OUT
*
* As an IN parameter number of frames of the resource to be mapped.
* This value may be updated over the course of the operation.
*
* When frame_list is NULL and nr_frames is 0, this is interpreted as a
* request for the size of the resource, which shall be returned in the
* nr_frames field.
*
* The size of a resource will never be zero, but a nonzero result doesn't
* guarantee that a subsequent mapping request will be successful. There
* are further type/id specific constraints which may change between the
* two calls.
*/
uint32_t nr_frames;
/*
* Padding field, must be zero on input.
* In a previous version this was an output field with the lowest bit
* named XENMEM_rsrc_acq_caller_owned. Future versions of this interface
* will not reuse this bit as an output with the field being zero on
* input.
*/
uint32_t pad;
/*
* IN - the index of the initial frame to be mapped. This parameter
* is ignored if nr_frames is 0. This value may be updated
* over the course of the operation.
*/
uint64_t frame;

#define XENMEM_resource_ioreq_server_frame_bufioreq 0
#define XENMEM_resource_ioreq_server_frame_ioreq(n) (1 + (n))

/*
* IN/OUT - If the tools domain is PV then, upon return, frame_list
* will be populated with the MFNs of the resource.
* If the tools domain is HVM then it is expected that, on
* entry, frame_list will be populated with a list of GFNs
* that will be mapped to the MFNs of the resource.
* If -EIO is returned then the frame_list has only been
* partially mapped and it is up to the caller to unmap all
* the GFNs.
* This parameter may be NULL if nr_frames is 0. This
* value may be updated over the course of the operation.
*/
XEN_GUEST_HANDLE(xen_pfn_t) frame_list;
};
typedef struct xen_mem_acquire_resource xen_mem_acquire_resource_t;
DEFINE_XEN_GUEST_HANDLE(xen_mem_acquire_resource_t);

#endif /* __XEN_PUBLIC_MEMORY_H__ */
Loading