xref: /linux-6.15/include/uapi/xen/gntalloc.h (revision bf580223)
1564eb714SDavid Vrabel /******************************************************************************
2564eb714SDavid Vrabel  * gntalloc.h
3564eb714SDavid Vrabel  *
4564eb714SDavid Vrabel  * Interface to /dev/xen/gntalloc.
5564eb714SDavid Vrabel  *
6564eb714SDavid Vrabel  * Author: Daniel De Graaf <[email protected]>
7564eb714SDavid Vrabel  *
8564eb714SDavid Vrabel  * This file is in the public domain.
9564eb714SDavid Vrabel  */
10564eb714SDavid Vrabel 
11564eb714SDavid Vrabel #ifndef __LINUX_PUBLIC_GNTALLOC_H__
12564eb714SDavid Vrabel #define __LINUX_PUBLIC_GNTALLOC_H__
13564eb714SDavid Vrabel 
1491afb7c3SMikko Rapeli #include <linux/types.h>
1591afb7c3SMikko Rapeli 
16564eb714SDavid Vrabel /*
17564eb714SDavid Vrabel  * Allocates a new page and creates a new grant reference.
18564eb714SDavid Vrabel  */
19564eb714SDavid Vrabel #define IOCTL_GNTALLOC_ALLOC_GREF \
20564eb714SDavid Vrabel _IOC(_IOC_NONE, 'G', 5, sizeof(struct ioctl_gntalloc_alloc_gref))
21564eb714SDavid Vrabel struct ioctl_gntalloc_alloc_gref {
22564eb714SDavid Vrabel 	/* IN parameters */
23564eb714SDavid Vrabel 	/* The ID of the domain to be given access to the grants. */
2491afb7c3SMikko Rapeli 	__u16 domid;
25564eb714SDavid Vrabel 	/* Flags for this mapping */
2691afb7c3SMikko Rapeli 	__u16 flags;
27564eb714SDavid Vrabel 	/* Number of pages to map */
2891afb7c3SMikko Rapeli 	__u32 count;
29564eb714SDavid Vrabel 	/* OUT parameters */
30564eb714SDavid Vrabel 	/* The offset to be used on a subsequent call to mmap(). */
3191afb7c3SMikko Rapeli 	__u64 index;
32564eb714SDavid Vrabel 	/* The grant references of the newly created grant, one per page */
33564eb714SDavid Vrabel 	/* Variable size, depending on count */
34*bf580223SKees Cook 	union {
3591afb7c3SMikko Rapeli 		__u32 gref_ids[1];
36*bf580223SKees Cook 		__DECLARE_FLEX_ARRAY(__u32, gref_ids_flex);
37*bf580223SKees Cook 	};
38564eb714SDavid Vrabel };
39564eb714SDavid Vrabel 
40564eb714SDavid Vrabel #define GNTALLOC_FLAG_WRITABLE 1
41564eb714SDavid Vrabel 
42564eb714SDavid Vrabel /*
43564eb714SDavid Vrabel  * Deallocates the grant reference, allowing the associated page to be freed if
44564eb714SDavid Vrabel  * no other domains are using it.
45564eb714SDavid Vrabel  */
46564eb714SDavid Vrabel #define IOCTL_GNTALLOC_DEALLOC_GREF \
47564eb714SDavid Vrabel _IOC(_IOC_NONE, 'G', 6, sizeof(struct ioctl_gntalloc_dealloc_gref))
48564eb714SDavid Vrabel struct ioctl_gntalloc_dealloc_gref {
49564eb714SDavid Vrabel 	/* IN parameters */
50564eb714SDavid Vrabel 	/* The offset returned in the map operation */
5191afb7c3SMikko Rapeli 	__u64 index;
52564eb714SDavid Vrabel 	/* Number of references to unmap */
5391afb7c3SMikko Rapeli 	__u32 count;
54564eb714SDavid Vrabel };
55564eb714SDavid Vrabel 
56564eb714SDavid Vrabel /*
57564eb714SDavid Vrabel  * Sets up an unmap notification within the page, so that the other side can do
58564eb714SDavid Vrabel  * cleanup if this side crashes. Required to implement cross-domain robust
59564eb714SDavid Vrabel  * mutexes or close notification on communication channels.
60564eb714SDavid Vrabel  *
61564eb714SDavid Vrabel  * Each mapped page only supports one notification; multiple calls referring to
62564eb714SDavid Vrabel  * the same page overwrite the previous notification. You must clear the
63564eb714SDavid Vrabel  * notification prior to the IOCTL_GNTALLOC_DEALLOC_GREF if you do not want it
64564eb714SDavid Vrabel  * to occur.
65564eb714SDavid Vrabel  */
66564eb714SDavid Vrabel #define IOCTL_GNTALLOC_SET_UNMAP_NOTIFY \
67564eb714SDavid Vrabel _IOC(_IOC_NONE, 'G', 7, sizeof(struct ioctl_gntalloc_unmap_notify))
68564eb714SDavid Vrabel struct ioctl_gntalloc_unmap_notify {
69564eb714SDavid Vrabel 	/* IN parameters */
70564eb714SDavid Vrabel 	/* Offset in the file descriptor for a byte within the page (same as
71564eb714SDavid Vrabel 	 * used in mmap). If using UNMAP_NOTIFY_CLEAR_BYTE, this is the byte to
72564eb714SDavid Vrabel 	 * be cleared. Otherwise, it can be any byte in the page whose
73564eb714SDavid Vrabel 	 * notification we are adjusting.
74564eb714SDavid Vrabel 	 */
7591afb7c3SMikko Rapeli 	__u64 index;
76564eb714SDavid Vrabel 	/* Action(s) to take on unmap */
7791afb7c3SMikko Rapeli 	__u32 action;
78564eb714SDavid Vrabel 	/* Event channel to notify */
7991afb7c3SMikko Rapeli 	__u32 event_channel_port;
80564eb714SDavid Vrabel };
81564eb714SDavid Vrabel 
82564eb714SDavid Vrabel /* Clear (set to zero) the byte specified by index */
83564eb714SDavid Vrabel #define UNMAP_NOTIFY_CLEAR_BYTE 0x1
84564eb714SDavid Vrabel /* Send an interrupt on the indicated event channel */
85564eb714SDavid Vrabel #define UNMAP_NOTIFY_SEND_EVENT 0x2
86564eb714SDavid Vrabel 
87564eb714SDavid Vrabel #endif /* __LINUX_PUBLIC_GNTALLOC_H__ */
88