18c2ecf20Sopenharmony_ci/* SPDX-License-Identifier: ((GPL-2.0 WITH Linux-syscall-note) OR MIT) */
28c2ecf20Sopenharmony_ci/******************************************************************************
38c2ecf20Sopenharmony_ci * privcmd.h
48c2ecf20Sopenharmony_ci *
58c2ecf20Sopenharmony_ci * Interface to /proc/xen/privcmd.
68c2ecf20Sopenharmony_ci *
78c2ecf20Sopenharmony_ci * Copyright (c) 2003-2005, K A Fraser
88c2ecf20Sopenharmony_ci *
98c2ecf20Sopenharmony_ci * This program is free software; you can redistribute it and/or
108c2ecf20Sopenharmony_ci * modify it under the terms of the GNU General Public License version 2
118c2ecf20Sopenharmony_ci * as published by the Free Software Foundation; or, when distributed
128c2ecf20Sopenharmony_ci * separately from the Linux kernel or incorporated into other
138c2ecf20Sopenharmony_ci * software packages, subject to the following license:
148c2ecf20Sopenharmony_ci *
158c2ecf20Sopenharmony_ci * Permission is hereby granted, free of charge, to any person obtaining a copy
168c2ecf20Sopenharmony_ci * of this source file (the "Software"), to deal in the Software without
178c2ecf20Sopenharmony_ci * restriction, including without limitation the rights to use, copy, modify,
188c2ecf20Sopenharmony_ci * merge, publish, distribute, sublicense, and/or sell copies of the Software,
198c2ecf20Sopenharmony_ci * and to permit persons to whom the Software is furnished to do so, subject to
208c2ecf20Sopenharmony_ci * the following conditions:
218c2ecf20Sopenharmony_ci *
228c2ecf20Sopenharmony_ci * The above copyright notice and this permission notice shall be included in
238c2ecf20Sopenharmony_ci * all copies or substantial portions of the Software.
248c2ecf20Sopenharmony_ci *
258c2ecf20Sopenharmony_ci * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
268c2ecf20Sopenharmony_ci * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
278c2ecf20Sopenharmony_ci * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
288c2ecf20Sopenharmony_ci * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
298c2ecf20Sopenharmony_ci * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
308c2ecf20Sopenharmony_ci * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
318c2ecf20Sopenharmony_ci * IN THE SOFTWARE.
328c2ecf20Sopenharmony_ci */
338c2ecf20Sopenharmony_ci
348c2ecf20Sopenharmony_ci#ifndef __LINUX_PUBLIC_PRIVCMD_H__
358c2ecf20Sopenharmony_ci#define __LINUX_PUBLIC_PRIVCMD_H__
368c2ecf20Sopenharmony_ci
378c2ecf20Sopenharmony_ci#include <linux/types.h>
388c2ecf20Sopenharmony_ci#include <linux/compiler.h>
398c2ecf20Sopenharmony_ci#include <xen/interface/xen.h>
408c2ecf20Sopenharmony_ci
418c2ecf20Sopenharmony_cistruct privcmd_hypercall {
428c2ecf20Sopenharmony_ci	__u64 op;
438c2ecf20Sopenharmony_ci	__u64 arg[5];
448c2ecf20Sopenharmony_ci};
458c2ecf20Sopenharmony_ci
468c2ecf20Sopenharmony_cistruct privcmd_mmap_entry {
478c2ecf20Sopenharmony_ci	__u64 va;
488c2ecf20Sopenharmony_ci	/*
498c2ecf20Sopenharmony_ci	 * This should be a GFN. It's not possible to change the name because
508c2ecf20Sopenharmony_ci	 * it's exposed to the user-space.
518c2ecf20Sopenharmony_ci	 */
528c2ecf20Sopenharmony_ci	__u64 mfn;
538c2ecf20Sopenharmony_ci	__u64 npages;
548c2ecf20Sopenharmony_ci};
558c2ecf20Sopenharmony_ci
568c2ecf20Sopenharmony_cistruct privcmd_mmap {
578c2ecf20Sopenharmony_ci	int num;
588c2ecf20Sopenharmony_ci	domid_t dom; /* target domain */
598c2ecf20Sopenharmony_ci	struct privcmd_mmap_entry __user *entry;
608c2ecf20Sopenharmony_ci};
618c2ecf20Sopenharmony_ci
628c2ecf20Sopenharmony_cistruct privcmd_mmapbatch {
638c2ecf20Sopenharmony_ci	int num;     /* number of pages to populate */
648c2ecf20Sopenharmony_ci	domid_t dom; /* target domain */
658c2ecf20Sopenharmony_ci	__u64 addr;  /* virtual address */
668c2ecf20Sopenharmony_ci	xen_pfn_t __user *arr; /* array of mfns - or'd with
678c2ecf20Sopenharmony_ci				  PRIVCMD_MMAPBATCH_*_ERROR on err */
688c2ecf20Sopenharmony_ci};
698c2ecf20Sopenharmony_ci
708c2ecf20Sopenharmony_ci#define PRIVCMD_MMAPBATCH_MFN_ERROR     0xf0000000U
718c2ecf20Sopenharmony_ci#define PRIVCMD_MMAPBATCH_PAGED_ERROR   0x80000000U
728c2ecf20Sopenharmony_ci
738c2ecf20Sopenharmony_cistruct privcmd_mmapbatch_v2 {
748c2ecf20Sopenharmony_ci	unsigned int num; /* number of pages to populate */
758c2ecf20Sopenharmony_ci	domid_t dom;      /* target domain */
768c2ecf20Sopenharmony_ci	__u64 addr;       /* virtual address */
778c2ecf20Sopenharmony_ci	const xen_pfn_t __user *arr; /* array of mfns */
788c2ecf20Sopenharmony_ci	int __user *err;  /* array of error codes */
798c2ecf20Sopenharmony_ci};
808c2ecf20Sopenharmony_ci
818c2ecf20Sopenharmony_cistruct privcmd_dm_op_buf {
828c2ecf20Sopenharmony_ci	void __user *uptr;
838c2ecf20Sopenharmony_ci	size_t size;
848c2ecf20Sopenharmony_ci};
858c2ecf20Sopenharmony_ci
868c2ecf20Sopenharmony_cistruct privcmd_dm_op {
878c2ecf20Sopenharmony_ci	domid_t dom;
888c2ecf20Sopenharmony_ci	__u16 num;
898c2ecf20Sopenharmony_ci	const struct privcmd_dm_op_buf __user *ubufs;
908c2ecf20Sopenharmony_ci};
918c2ecf20Sopenharmony_ci
928c2ecf20Sopenharmony_cistruct privcmd_mmap_resource {
938c2ecf20Sopenharmony_ci	domid_t dom;
948c2ecf20Sopenharmony_ci	__u32 type;
958c2ecf20Sopenharmony_ci	__u32 id;
968c2ecf20Sopenharmony_ci	__u32 idx;
978c2ecf20Sopenharmony_ci	__u64 num;
988c2ecf20Sopenharmony_ci	__u64 addr;
998c2ecf20Sopenharmony_ci};
1008c2ecf20Sopenharmony_ci
1018c2ecf20Sopenharmony_ci/*
1028c2ecf20Sopenharmony_ci * @cmd: IOCTL_PRIVCMD_HYPERCALL
1038c2ecf20Sopenharmony_ci * @arg: &privcmd_hypercall_t
1048c2ecf20Sopenharmony_ci * Return: Value returned from execution of the specified hypercall.
1058c2ecf20Sopenharmony_ci *
1068c2ecf20Sopenharmony_ci * @cmd: IOCTL_PRIVCMD_MMAPBATCH_V2
1078c2ecf20Sopenharmony_ci * @arg: &struct privcmd_mmapbatch_v2
1088c2ecf20Sopenharmony_ci * Return: 0 on success (i.e., arg->err contains valid error codes for
1098c2ecf20Sopenharmony_ci * each frame).  On an error other than a failed frame remap, -1 is
1108c2ecf20Sopenharmony_ci * returned and errno is set to EINVAL, EFAULT etc.  As an exception,
1118c2ecf20Sopenharmony_ci * if the operation was otherwise successful but any frame failed with
1128c2ecf20Sopenharmony_ci * -ENOENT, then -1 is returned and errno is set to ENOENT.
1138c2ecf20Sopenharmony_ci */
1148c2ecf20Sopenharmony_ci#define IOCTL_PRIVCMD_HYPERCALL					\
1158c2ecf20Sopenharmony_ci	_IOC(_IOC_NONE, 'P', 0, sizeof(struct privcmd_hypercall))
1168c2ecf20Sopenharmony_ci#define IOCTL_PRIVCMD_MMAP					\
1178c2ecf20Sopenharmony_ci	_IOC(_IOC_NONE, 'P', 2, sizeof(struct privcmd_mmap))
1188c2ecf20Sopenharmony_ci#define IOCTL_PRIVCMD_MMAPBATCH					\
1198c2ecf20Sopenharmony_ci	_IOC(_IOC_NONE, 'P', 3, sizeof(struct privcmd_mmapbatch))
1208c2ecf20Sopenharmony_ci#define IOCTL_PRIVCMD_MMAPBATCH_V2				\
1218c2ecf20Sopenharmony_ci	_IOC(_IOC_NONE, 'P', 4, sizeof(struct privcmd_mmapbatch_v2))
1228c2ecf20Sopenharmony_ci#define IOCTL_PRIVCMD_DM_OP					\
1238c2ecf20Sopenharmony_ci	_IOC(_IOC_NONE, 'P', 5, sizeof(struct privcmd_dm_op))
1248c2ecf20Sopenharmony_ci#define IOCTL_PRIVCMD_RESTRICT					\
1258c2ecf20Sopenharmony_ci	_IOC(_IOC_NONE, 'P', 6, sizeof(domid_t))
1268c2ecf20Sopenharmony_ci#define IOCTL_PRIVCMD_MMAP_RESOURCE				\
1278c2ecf20Sopenharmony_ci	_IOC(_IOC_NONE, 'P', 7, sizeof(struct privcmd_mmap_resource))
1288c2ecf20Sopenharmony_ci
1298c2ecf20Sopenharmony_ci#endif /* __LINUX_PUBLIC_PRIVCMD_H__ */
130