xref: /openbmc/linux/include/uapi/xen/privcmd.h (revision b97d6790d03b763eca08847a9a5869a4291b9f9a)
1e2be04c7SGreg Kroah-Hartman /* SPDX-License-Identifier: ((GPL-2.0 WITH Linux-syscall-note) OR MIT) */
272503791SDavid Howells /******************************************************************************
372503791SDavid Howells  * privcmd.h
472503791SDavid Howells  *
572503791SDavid Howells  * Interface to /proc/xen/privcmd.
672503791SDavid Howells  *
772503791SDavid Howells  * Copyright (c) 2003-2005, K A Fraser
872503791SDavid Howells  *
972503791SDavid Howells  * This program is free software; you can redistribute it and/or
1072503791SDavid Howells  * modify it under the terms of the GNU General Public License version 2
1172503791SDavid Howells  * as published by the Free Software Foundation; or, when distributed
1272503791SDavid Howells  * separately from the Linux kernel or incorporated into other
1372503791SDavid Howells  * software packages, subject to the following license:
1472503791SDavid Howells  *
1572503791SDavid Howells  * Permission is hereby granted, free of charge, to any person obtaining a copy
1672503791SDavid Howells  * of this source file (the "Software"), to deal in the Software without
1772503791SDavid Howells  * restriction, including without limitation the rights to use, copy, modify,
1872503791SDavid Howells  * merge, publish, distribute, sublicense, and/or sell copies of the Software,
1972503791SDavid Howells  * and to permit persons to whom the Software is furnished to do so, subject to
2072503791SDavid Howells  * the following conditions:
2172503791SDavid Howells  *
2272503791SDavid Howells  * The above copyright notice and this permission notice shall be included in
2372503791SDavid Howells  * all copies or substantial portions of the Software.
2472503791SDavid Howells  *
2572503791SDavid Howells  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
2672503791SDavid Howells  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
2772503791SDavid Howells  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
2872503791SDavid Howells  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
2972503791SDavid Howells  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
3072503791SDavid Howells  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
3172503791SDavid Howells  * IN THE SOFTWARE.
3272503791SDavid Howells  */
3372503791SDavid Howells 
3472503791SDavid Howells #ifndef __LINUX_PUBLIC_PRIVCMD_H__
3572503791SDavid Howells #define __LINUX_PUBLIC_PRIVCMD_H__
3672503791SDavid Howells 
3772503791SDavid Howells #include <linux/types.h>
3872503791SDavid Howells #include <linux/compiler.h>
3972503791SDavid Howells #include <xen/interface/xen.h>
4072503791SDavid Howells 
4172503791SDavid Howells struct privcmd_hypercall {
4272503791SDavid Howells 	__u64 op;
4372503791SDavid Howells 	__u64 arg[5];
4472503791SDavid Howells };
4572503791SDavid Howells 
4672503791SDavid Howells struct privcmd_mmap_entry {
4772503791SDavid Howells 	__u64 va;
48a13d7201SJulien Grall 	/*
49a13d7201SJulien Grall 	 * This should be a GFN. It's not possible to change the name because
50a13d7201SJulien Grall 	 * it's exposed to the user-space.
51a13d7201SJulien Grall 	 */
5272503791SDavid Howells 	__u64 mfn;
5372503791SDavid Howells 	__u64 npages;
5472503791SDavid Howells };
5572503791SDavid Howells 
5672503791SDavid Howells struct privcmd_mmap {
5772503791SDavid Howells 	int num;
5872503791SDavid Howells 	domid_t dom; /* target domain */
5972503791SDavid Howells 	struct privcmd_mmap_entry __user *entry;
6072503791SDavid Howells };
6172503791SDavid Howells 
6272503791SDavid Howells struct privcmd_mmapbatch {
6372503791SDavid Howells 	int num;     /* number of pages to populate */
6472503791SDavid Howells 	domid_t dom; /* target domain */
6572503791SDavid Howells 	__u64 addr;  /* virtual address */
6672503791SDavid Howells 	xen_pfn_t __user *arr; /* array of mfns - or'd with
6772503791SDavid Howells 				  PRIVCMD_MMAPBATCH_*_ERROR on err */
6872503791SDavid Howells };
6972503791SDavid Howells 
7072503791SDavid Howells #define PRIVCMD_MMAPBATCH_MFN_ERROR     0xf0000000U
7172503791SDavid Howells #define PRIVCMD_MMAPBATCH_PAGED_ERROR   0x80000000U
7272503791SDavid Howells 
7372503791SDavid Howells struct privcmd_mmapbatch_v2 {
7472503791SDavid Howells 	unsigned int num; /* number of pages to populate */
7572503791SDavid Howells 	domid_t dom;      /* target domain */
7672503791SDavid Howells 	__u64 addr;       /* virtual address */
7772503791SDavid Howells 	const xen_pfn_t __user *arr; /* array of mfns */
7872503791SDavid Howells 	int __user *err;  /* array of error codes */
7972503791SDavid Howells };
8072503791SDavid Howells 
81ab520be8SPaul Durrant struct privcmd_dm_op_buf {
82ab520be8SPaul Durrant 	void __user *uptr;
83ab520be8SPaul Durrant 	size_t size;
84ab520be8SPaul Durrant };
85ab520be8SPaul Durrant 
86ab520be8SPaul Durrant struct privcmd_dm_op {
87ab520be8SPaul Durrant 	domid_t dom;
88ab520be8SPaul Durrant 	__u16 num;
89ab520be8SPaul Durrant 	const struct privcmd_dm_op_buf __user *ubufs;
90ab520be8SPaul Durrant };
91ab520be8SPaul Durrant 
923ad08765SPaul Durrant struct privcmd_mmap_resource {
933ad08765SPaul Durrant 	domid_t dom;
943ad08765SPaul Durrant 	__u32 type;
953ad08765SPaul Durrant 	__u32 id;
963ad08765SPaul Durrant 	__u32 idx;
973ad08765SPaul Durrant 	__u64 num;
983ad08765SPaul Durrant 	__u64 addr;
993ad08765SPaul Durrant };
1003ad08765SPaul Durrant 
101f8941e6cSViresh Kumar /* For privcmd_irqfd::flags */
102f8941e6cSViresh Kumar #define PRIVCMD_IRQFD_FLAG_DEASSIGN (1 << 0)
103f8941e6cSViresh Kumar 
104f8941e6cSViresh Kumar struct privcmd_irqfd {
1050d99e8c8SViresh Kumar 	__u64 dm_op;
106f8941e6cSViresh Kumar 	__u32 size; /* Size of structure pointed by dm_op */
107f8941e6cSViresh Kumar 	__u32 fd;
108f8941e6cSViresh Kumar 	__u32 flags;
109f8941e6cSViresh Kumar 	domid_t dom;
110f8941e6cSViresh Kumar 	__u8 pad[2];
111f8941e6cSViresh Kumar };
112f8941e6cSViresh Kumar 
11372503791SDavid Howells /*
11472503791SDavid Howells  * @cmd: IOCTL_PRIVCMD_HYPERCALL
11572503791SDavid Howells  * @arg: &privcmd_hypercall_t
11672503791SDavid Howells  * Return: Value returned from execution of the specified hypercall.
11772503791SDavid Howells  *
11872503791SDavid Howells  * @cmd: IOCTL_PRIVCMD_MMAPBATCH_V2
11972503791SDavid Howells  * @arg: &struct privcmd_mmapbatch_v2
12072503791SDavid Howells  * Return: 0 on success (i.e., arg->err contains valid error codes for
12172503791SDavid Howells  * each frame).  On an error other than a failed frame remap, -1 is
12272503791SDavid Howells  * returned and errno is set to EINVAL, EFAULT etc.  As an exception,
12372503791SDavid Howells  * if the operation was otherwise successful but any frame failed with
12472503791SDavid Howells  * -ENOENT, then -1 is returned and errno is set to ENOENT.
12572503791SDavid Howells  */
12672503791SDavid Howells #define IOCTL_PRIVCMD_HYPERCALL					\
12772503791SDavid Howells 	_IOC(_IOC_NONE, 'P', 0, sizeof(struct privcmd_hypercall))
12872503791SDavid Howells #define IOCTL_PRIVCMD_MMAP					\
12972503791SDavid Howells 	_IOC(_IOC_NONE, 'P', 2, sizeof(struct privcmd_mmap))
13072503791SDavid Howells #define IOCTL_PRIVCMD_MMAPBATCH					\
13172503791SDavid Howells 	_IOC(_IOC_NONE, 'P', 3, sizeof(struct privcmd_mmapbatch))
13272503791SDavid Howells #define IOCTL_PRIVCMD_MMAPBATCH_V2				\
13372503791SDavid Howells 	_IOC(_IOC_NONE, 'P', 4, sizeof(struct privcmd_mmapbatch_v2))
134ab520be8SPaul Durrant #define IOCTL_PRIVCMD_DM_OP					\
135ab520be8SPaul Durrant 	_IOC(_IOC_NONE, 'P', 5, sizeof(struct privcmd_dm_op))
1364610d240SPaul Durrant #define IOCTL_PRIVCMD_RESTRICT					\
1374610d240SPaul Durrant 	_IOC(_IOC_NONE, 'P', 6, sizeof(domid_t))
1383ad08765SPaul Durrant #define IOCTL_PRIVCMD_MMAP_RESOURCE				\
1393ad08765SPaul Durrant 	_IOC(_IOC_NONE, 'P', 7, sizeof(struct privcmd_mmap_resource))
140f8941e6cSViresh Kumar #define IOCTL_PRIVCMD_IRQFD					\
141*ca8ab593SViresh Kumar 	_IOW('P', 8, struct privcmd_irqfd)
14272503791SDavid Howells 
14372503791SDavid Howells #endif /* __LINUX_PUBLIC_PRIVCMD_H__ */
144