xref: /OK3568_Linux_fs/kernel/include/uapi/xen/privcmd.h (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1*4882a593Smuzhiyun /* SPDX-License-Identifier: ((GPL-2.0 WITH Linux-syscall-note) OR MIT) */
2*4882a593Smuzhiyun /******************************************************************************
3*4882a593Smuzhiyun  * privcmd.h
4*4882a593Smuzhiyun  *
5*4882a593Smuzhiyun  * Interface to /proc/xen/privcmd.
6*4882a593Smuzhiyun  *
7*4882a593Smuzhiyun  * Copyright (c) 2003-2005, K A Fraser
8*4882a593Smuzhiyun  *
9*4882a593Smuzhiyun  * This program is free software; you can redistribute it and/or
10*4882a593Smuzhiyun  * modify it under the terms of the GNU General Public License version 2
11*4882a593Smuzhiyun  * as published by the Free Software Foundation; or, when distributed
12*4882a593Smuzhiyun  * separately from the Linux kernel or incorporated into other
13*4882a593Smuzhiyun  * software packages, subject to the following license:
14*4882a593Smuzhiyun  *
15*4882a593Smuzhiyun  * Permission is hereby granted, free of charge, to any person obtaining a copy
16*4882a593Smuzhiyun  * of this source file (the "Software"), to deal in the Software without
17*4882a593Smuzhiyun  * restriction, including without limitation the rights to use, copy, modify,
18*4882a593Smuzhiyun  * merge, publish, distribute, sublicense, and/or sell copies of the Software,
19*4882a593Smuzhiyun  * and to permit persons to whom the Software is furnished to do so, subject to
20*4882a593Smuzhiyun  * the following conditions:
21*4882a593Smuzhiyun  *
22*4882a593Smuzhiyun  * The above copyright notice and this permission notice shall be included in
23*4882a593Smuzhiyun  * all copies or substantial portions of the Software.
24*4882a593Smuzhiyun  *
25*4882a593Smuzhiyun  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
26*4882a593Smuzhiyun  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
27*4882a593Smuzhiyun  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
28*4882a593Smuzhiyun  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
29*4882a593Smuzhiyun  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
30*4882a593Smuzhiyun  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
31*4882a593Smuzhiyun  * IN THE SOFTWARE.
32*4882a593Smuzhiyun  */
33*4882a593Smuzhiyun 
34*4882a593Smuzhiyun #ifndef __LINUX_PUBLIC_PRIVCMD_H__
35*4882a593Smuzhiyun #define __LINUX_PUBLIC_PRIVCMD_H__
36*4882a593Smuzhiyun 
37*4882a593Smuzhiyun #include <linux/types.h>
38*4882a593Smuzhiyun #include <linux/compiler.h>
39*4882a593Smuzhiyun #include <xen/interface/xen.h>
40*4882a593Smuzhiyun 
41*4882a593Smuzhiyun struct privcmd_hypercall {
42*4882a593Smuzhiyun 	__u64 op;
43*4882a593Smuzhiyun 	__u64 arg[5];
44*4882a593Smuzhiyun };
45*4882a593Smuzhiyun 
46*4882a593Smuzhiyun struct privcmd_mmap_entry {
47*4882a593Smuzhiyun 	__u64 va;
48*4882a593Smuzhiyun 	/*
49*4882a593Smuzhiyun 	 * This should be a GFN. It's not possible to change the name because
50*4882a593Smuzhiyun 	 * it's exposed to the user-space.
51*4882a593Smuzhiyun 	 */
52*4882a593Smuzhiyun 	__u64 mfn;
53*4882a593Smuzhiyun 	__u64 npages;
54*4882a593Smuzhiyun };
55*4882a593Smuzhiyun 
56*4882a593Smuzhiyun struct privcmd_mmap {
57*4882a593Smuzhiyun 	int num;
58*4882a593Smuzhiyun 	domid_t dom; /* target domain */
59*4882a593Smuzhiyun 	struct privcmd_mmap_entry __user *entry;
60*4882a593Smuzhiyun };
61*4882a593Smuzhiyun 
62*4882a593Smuzhiyun struct privcmd_mmapbatch {
63*4882a593Smuzhiyun 	int num;     /* number of pages to populate */
64*4882a593Smuzhiyun 	domid_t dom; /* target domain */
65*4882a593Smuzhiyun 	__u64 addr;  /* virtual address */
66*4882a593Smuzhiyun 	xen_pfn_t __user *arr; /* array of mfns - or'd with
67*4882a593Smuzhiyun 				  PRIVCMD_MMAPBATCH_*_ERROR on err */
68*4882a593Smuzhiyun };
69*4882a593Smuzhiyun 
70*4882a593Smuzhiyun #define PRIVCMD_MMAPBATCH_MFN_ERROR     0xf0000000U
71*4882a593Smuzhiyun #define PRIVCMD_MMAPBATCH_PAGED_ERROR   0x80000000U
72*4882a593Smuzhiyun 
73*4882a593Smuzhiyun struct privcmd_mmapbatch_v2 {
74*4882a593Smuzhiyun 	unsigned int num; /* number of pages to populate */
75*4882a593Smuzhiyun 	domid_t dom;      /* target domain */
76*4882a593Smuzhiyun 	__u64 addr;       /* virtual address */
77*4882a593Smuzhiyun 	const xen_pfn_t __user *arr; /* array of mfns */
78*4882a593Smuzhiyun 	int __user *err;  /* array of error codes */
79*4882a593Smuzhiyun };
80*4882a593Smuzhiyun 
81*4882a593Smuzhiyun struct privcmd_dm_op_buf {
82*4882a593Smuzhiyun 	void __user *uptr;
83*4882a593Smuzhiyun 	size_t size;
84*4882a593Smuzhiyun };
85*4882a593Smuzhiyun 
86*4882a593Smuzhiyun struct privcmd_dm_op {
87*4882a593Smuzhiyun 	domid_t dom;
88*4882a593Smuzhiyun 	__u16 num;
89*4882a593Smuzhiyun 	const struct privcmd_dm_op_buf __user *ubufs;
90*4882a593Smuzhiyun };
91*4882a593Smuzhiyun 
92*4882a593Smuzhiyun struct privcmd_mmap_resource {
93*4882a593Smuzhiyun 	domid_t dom;
94*4882a593Smuzhiyun 	__u32 type;
95*4882a593Smuzhiyun 	__u32 id;
96*4882a593Smuzhiyun 	__u32 idx;
97*4882a593Smuzhiyun 	__u64 num;
98*4882a593Smuzhiyun 	__u64 addr;
99*4882a593Smuzhiyun };
100*4882a593Smuzhiyun 
101*4882a593Smuzhiyun /*
102*4882a593Smuzhiyun  * @cmd: IOCTL_PRIVCMD_HYPERCALL
103*4882a593Smuzhiyun  * @arg: &privcmd_hypercall_t
104*4882a593Smuzhiyun  * Return: Value returned from execution of the specified hypercall.
105*4882a593Smuzhiyun  *
106*4882a593Smuzhiyun  * @cmd: IOCTL_PRIVCMD_MMAPBATCH_V2
107*4882a593Smuzhiyun  * @arg: &struct privcmd_mmapbatch_v2
108*4882a593Smuzhiyun  * Return: 0 on success (i.e., arg->err contains valid error codes for
109*4882a593Smuzhiyun  * each frame).  On an error other than a failed frame remap, -1 is
110*4882a593Smuzhiyun  * returned and errno is set to EINVAL, EFAULT etc.  As an exception,
111*4882a593Smuzhiyun  * if the operation was otherwise successful but any frame failed with
112*4882a593Smuzhiyun  * -ENOENT, then -1 is returned and errno is set to ENOENT.
113*4882a593Smuzhiyun  */
114*4882a593Smuzhiyun #define IOCTL_PRIVCMD_HYPERCALL					\
115*4882a593Smuzhiyun 	_IOC(_IOC_NONE, 'P', 0, sizeof(struct privcmd_hypercall))
116*4882a593Smuzhiyun #define IOCTL_PRIVCMD_MMAP					\
117*4882a593Smuzhiyun 	_IOC(_IOC_NONE, 'P', 2, sizeof(struct privcmd_mmap))
118*4882a593Smuzhiyun #define IOCTL_PRIVCMD_MMAPBATCH					\
119*4882a593Smuzhiyun 	_IOC(_IOC_NONE, 'P', 3, sizeof(struct privcmd_mmapbatch))
120*4882a593Smuzhiyun #define IOCTL_PRIVCMD_MMAPBATCH_V2				\
121*4882a593Smuzhiyun 	_IOC(_IOC_NONE, 'P', 4, sizeof(struct privcmd_mmapbatch_v2))
122*4882a593Smuzhiyun #define IOCTL_PRIVCMD_DM_OP					\
123*4882a593Smuzhiyun 	_IOC(_IOC_NONE, 'P', 5, sizeof(struct privcmd_dm_op))
124*4882a593Smuzhiyun #define IOCTL_PRIVCMD_RESTRICT					\
125*4882a593Smuzhiyun 	_IOC(_IOC_NONE, 'P', 6, sizeof(domid_t))
126*4882a593Smuzhiyun #define IOCTL_PRIVCMD_MMAP_RESOURCE				\
127*4882a593Smuzhiyun 	_IOC(_IOC_NONE, 'P', 7, sizeof(struct privcmd_mmap_resource))
128*4882a593Smuzhiyun 
129*4882a593Smuzhiyun #endif /* __LINUX_PUBLIC_PRIVCMD_H__ */
130