Skip to content

Commit 9bdad1f

Browse files
soburikartben
authored andcommitted
drivers: xen: memory: add acquire_resource wrapper
Add XENMEM_acquire_resource wrapper to map device model related buffers. This is required for communication with the ioreq server. - memory - xendom_acquire_resource: HYPERVISOR_memory_op(XENMEM_acquire_resource) Signed-off-by: TOKITA Hiroshi <[email protected]>
1 parent 14ac666 commit 9bdad1f

File tree

3 files changed

+125
-0
lines changed

3 files changed

+125
-0
lines changed

drivers/xen/memory.c

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,3 +66,25 @@ int xendom_populate_physmap(int domid, unsigned int extent_order,
6666

6767
return HYPERVISOR_memory_op(XENMEM_populate_physmap, &reservation);
6868
}
69+
70+
int xendom_acquire_resource(domid_t domid, uint16_t type, uint32_t id, uint64_t frame,
71+
uint32_t *nr_frames, xen_pfn_t *frame_list)
72+
{
73+
struct xen_mem_acquire_resource acquire_res = {
74+
.domid = domid,
75+
.type = type,
76+
.id = id,
77+
.pad = 0,
78+
.frame = frame,
79+
.nr_frames = *nr_frames,
80+
};
81+
int ret;
82+
83+
set_xen_guest_handle(acquire_res.frame_list, frame_list);
84+
85+
ret = HYPERVISOR_memory_op(XENMEM_acquire_resource, &acquire_res);
86+
87+
*nr_frames = acquire_res.nr_frames;
88+
89+
return ret;
90+
}

include/zephyr/xen/memory.h

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@
33
* Copyright (c) 2023 EPAM Systems
44
*/
55

6+
#ifndef ZEPHYR_XEN_MEMORY_H_
7+
#define ZEPHYR_XEN_MEMORY_H_
8+
69
#include <zephyr/kernel.h>
710
#include <zephyr/xen/public/memory.h>
811
#include <zephyr/xen/public/xen.h>
@@ -64,3 +67,25 @@ int xendom_remove_from_physmap(int domid, xen_pfn_t gpfn);
6467
int xendom_populate_physmap(int domid, unsigned int extent_order,
6568
unsigned int nr_extents, unsigned int mem_flags,
6669
xen_pfn_t *extent_start);
70+
71+
/**
72+
* @brief Acquire a resource mapping for the Xen domain.
73+
*
74+
* Issues the XENMEM_acquire_resource hypercall to map a resource buffer
75+
* (e.g., I/O request server, grant table, VM trace buffer) into the
76+
* specified domain's physmap, or query its total size.
77+
*
78+
* @param domid Target domain identifier. Use DOMID_SELF for the calling domain.
79+
* @param type Resource type identifier (e.g., XENMEM_resource_ioreq_server).
80+
* @param id Resource-specific identifier (e.g., server ID or table ID).
81+
* @param frame Starting frame number for mapping, or ignored if *nr_frames == 0.
82+
* @param nr_frames [in,out] On input, number of frames to map; on return,
83+
* number of frames actually mapped (or total frames if queried).
84+
* @param frame_list Guest frame list buffer: input GFNs for HVM guests,
85+
* output MFNs for PV guests.
86+
* @return Zero on success, or a negative errno code on failure.
87+
*/
88+
int xendom_acquire_resource(domid_t domid, uint16_t type, uint32_t id, uint64_t frame,
89+
uint32_t *nr_frames, xen_pfn_t *frame_list);
90+
91+
#endif /* ZEPHYR_XEN_MEMORY_H_ */

include/zephyr/xen/public/memory.h

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,4 +161,82 @@ struct xen_remove_from_physmap {
161161
typedef struct xen_remove_from_physmap xen_remove_from_physmap_t;
162162
DEFINE_XEN_GUEST_HANDLE(xen_remove_from_physmap_t);
163163

164+
/*
165+
* Get the pages for a particular guest resource, so that they can be
166+
* mapped directly by a tools domain.
167+
*/
168+
#define XENMEM_acquire_resource 28
169+
struct xen_mem_acquire_resource {
170+
/* IN - The domain whose resource is to be mapped */
171+
domid_t domid;
172+
/* IN - the type of resource */
173+
uint16_t type;
174+
175+
#define XENMEM_resource_ioreq_server 0
176+
#define XENMEM_resource_grant_table 1
177+
#define XENMEM_resource_vmtrace_buf 2
178+
179+
/*
180+
* IN - a type-specific resource identifier, which must be zero
181+
* unless stated otherwise.
182+
*
183+
* type == XENMEM_resource_ioreq_server -> id == ioreq server id
184+
* type == XENMEM_resource_grant_table -> id defined below
185+
*/
186+
uint32_t id;
187+
188+
#define XENMEM_resource_grant_table_id_shared 0
189+
#define XENMEM_resource_grant_table_id_status 1
190+
191+
/*
192+
* IN/OUT
193+
*
194+
* As an IN parameter number of frames of the resource to be mapped.
195+
* This value may be updated over the course of the operation.
196+
*
197+
* When frame_list is NULL and nr_frames is 0, this is interpreted as a
198+
* request for the size of the resource, which shall be returned in the
199+
* nr_frames field.
200+
*
201+
* The size of a resource will never be zero, but a nonzero result doesn't
202+
* guarantee that a subsequent mapping request will be successful. There
203+
* are further type/id specific constraints which may change between the
204+
* two calls.
205+
*/
206+
uint32_t nr_frames;
207+
/*
208+
* Padding field, must be zero on input.
209+
* In a previous version this was an output field with the lowest bit
210+
* named XENMEM_rsrc_acq_caller_owned. Future versions of this interface
211+
* will not reuse this bit as an output with the field being zero on
212+
* input.
213+
*/
214+
uint32_t pad;
215+
/*
216+
* IN - the index of the initial frame to be mapped. This parameter
217+
* is ignored if nr_frames is 0. This value may be updated
218+
* over the course of the operation.
219+
*/
220+
uint64_t frame;
221+
222+
#define XENMEM_resource_ioreq_server_frame_bufioreq 0
223+
#define XENMEM_resource_ioreq_server_frame_ioreq(n) (1 + (n))
224+
225+
/*
226+
* IN/OUT - If the tools domain is PV then, upon return, frame_list
227+
* will be populated with the MFNs of the resource.
228+
* If the tools domain is HVM then it is expected that, on
229+
* entry, frame_list will be populated with a list of GFNs
230+
* that will be mapped to the MFNs of the resource.
231+
* If -EIO is returned then the frame_list has only been
232+
* partially mapped and it is up to the caller to unmap all
233+
* the GFNs.
234+
* This parameter may be NULL if nr_frames is 0. This
235+
* value may be updated over the course of the operation.
236+
*/
237+
XEN_GUEST_HANDLE(xen_pfn_t) frame_list;
238+
};
239+
typedef struct xen_mem_acquire_resource xen_mem_acquire_resource_t;
240+
DEFINE_XEN_GUEST_HANDLE(xen_mem_acquire_resource_t);
241+
164242
#endif /* __XEN_PUBLIC_MEMORY_H__ */

0 commit comments

Comments
 (0)