xref: /netbsd-src/sys/arch/xen/include/xenio.h (revision 0e8ff7c9626428b51a287575da03b757c0a16a24)
1*0e8ff7c9Sbouyer /*	$NetBSD: xenio.h,v 1.12 2020/05/26 10:11:56 bouyer Exp $	*/
2977bfc35Scl 
3e9666f30Sbouyer /******************************************************************************
4e9666f30Sbouyer  * privcmd.h
5977bfc35Scl  *
6e9666f30Sbouyer  * Copyright (c) 2003-2004, K A Fraser
7e9666f30Sbouyer  *
8e9666f30Sbouyer  * This file may be distributed separately from the Linux kernel, or
9e9666f30Sbouyer  * incorporated into other software packages, subject to the following license:
10977bfc35Scl  *
11977bfc35Scl  * Permission is hereby granted, free of charge, to any person obtaining a copy
12e9666f30Sbouyer  * of this source file (the "Software"), to deal in the Software without
13e9666f30Sbouyer  * restriction, including without limitation the rights to use, copy, modify,
14e9666f30Sbouyer  * merge, publish, distribute, sublicense, and/or sell copies of the Software,
15e9666f30Sbouyer  * and to permit persons to whom the Software is furnished to do so, subject to
16e9666f30Sbouyer  * the following conditions:
17977bfc35Scl  *
18977bfc35Scl  * The above copyright notice and this permission notice shall be included in
19977bfc35Scl  * all copies or substantial portions of the Software.
20977bfc35Scl  *
21977bfc35Scl  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
22977bfc35Scl  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
23977bfc35Scl  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
24977bfc35Scl  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
25977bfc35Scl  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
26e9666f30Sbouyer  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
27e9666f30Sbouyer  * IN THE SOFTWARE.
28977bfc35Scl  */
29977bfc35Scl 
3064db2748Scegger #ifndef __XEN_XENIO_H__
3164db2748Scegger #define __XEN_XENIO_H__
32977bfc35Scl 
33e9666f30Sbouyer /* Interface to /proc/xen/privcmd */
34977bfc35Scl 
3525d3b9e7Sdholland #include <sys/ioccom.h>
3625d3b9e7Sdholland 
3725d3b9e7Sdholland 
38e9666f30Sbouyer typedef struct privcmd_hypercall
39e9666f30Sbouyer {
40977bfc35Scl     unsigned long op;
41977bfc35Scl     unsigned long arg[5];
42895da00eSbouyer     long retval;
43977bfc35Scl } privcmd_hypercall_t;
44977bfc35Scl 
45e9666f30Sbouyer typedef struct privcmd_mmap_entry {
46e9666f30Sbouyer     unsigned long va;
47e9666f30Sbouyer     unsigned long mfn;
48e9666f30Sbouyer     unsigned long npages;
49e9666f30Sbouyer } privcmd_mmap_entry_t;
50e9666f30Sbouyer 
51e9666f30Sbouyer typedef struct privcmd_mmap {
52e9666f30Sbouyer     int num;
53e9666f30Sbouyer     domid_t dom; /* target domain */
54e9666f30Sbouyer     privcmd_mmap_entry_t *entry;
55e9666f30Sbouyer } privcmd_mmap_t;
56e9666f30Sbouyer 
57e9666f30Sbouyer typedef struct privcmd_mmapbatch {
58e9666f30Sbouyer     int num;     /* number of pages to populate */
59e9666f30Sbouyer     domid_t dom; /* target domain */
60e9666f30Sbouyer     unsigned long addr;  /* virtual address */
61e9666f30Sbouyer     unsigned long *arr; /* array of mfns - top nibble set on err */
62e9666f30Sbouyer } privcmd_mmapbatch_t;
63e9666f30Sbouyer 
645932e641Scegger typedef struct privcmd_mmapbatch_v2 {
655932e641Scegger     int num;     /* number of pages to populate */
665932e641Scegger     domid_t dom; /* target domain */
675932e641Scegger     uint64_t addr;  /* virtual address */
685932e641Scegger     const xen_pfn_t *arr; /* array of mfns */
695932e641Scegger     int *err; /* array of error codes */
705932e641Scegger } privcmd_mmapbatch_v2_t;
715932e641Scegger 
72e9666f30Sbouyer typedef struct privcmd_blkmsg
73e9666f30Sbouyer {
74977bfc35Scl     unsigned long op;
75977bfc35Scl     void         *buf;
76977bfc35Scl     int           buf_size;
77977bfc35Scl } privcmd_blkmsg_t;
78977bfc35Scl 
79e9666f30Sbouyer /*
80e9666f30Sbouyer  * @cmd: IOCTL_PRIVCMD_HYPERCALL
81e9666f30Sbouyer  * @arg: &privcmd_hypercall_t
82e9666f30Sbouyer  * Return: Value returned from execution of the specified hypercall.
83e9666f30Sbouyer  */
84977bfc35Scl #define IOCTL_PRIVCMD_HYPERCALL         \
85e9666f30Sbouyer     _IOWR('P', 0, privcmd_hypercall_t)
86977bfc35Scl 
87b0bd23ffSyamt #if defined(_KERNEL)
88b0bd23ffSyamt /* compat */
89b0bd23ffSyamt #define IOCTL_PRIVCMD_INITDOMAIN_EVTCHN_OLD \
90e9666f30Sbouyer     _IO('P', 1)
91895da00eSbouyer 
92895da00eSbouyer typedef struct oprivcmd_hypercall
93895da00eSbouyer {
94895da00eSbouyer     unsigned long op;
95895da00eSbouyer     unsigned long arg[5];
96895da00eSbouyer } oprivcmd_hypercall_t;
97895da00eSbouyer 
98895da00eSbouyer #define IOCTL_PRIVCMD_HYPERCALL_OLD       \
99895da00eSbouyer     _IOWR('P', 0, oprivcmd_hypercall_t)
100b0bd23ffSyamt #endif /* defined(_KERNEL) */
101e9666f30Sbouyer 
102e9666f30Sbouyer #define IOCTL_PRIVCMD_MMAP             \
103e9666f30Sbouyer     _IOW('P', 2, privcmd_mmap_t)
104e9666f30Sbouyer #define IOCTL_PRIVCMD_MMAPBATCH        \
105e9666f30Sbouyer     _IOW('P', 3, privcmd_mmapbatch_t)
106e9666f30Sbouyer #define IOCTL_PRIVCMD_GET_MACH2PHYS_START_MFN \
1077558bd0aSbouyer     _IOR('P', 4, unsigned long)
108e9666f30Sbouyer 
109b0bd23ffSyamt /*
110b0bd23ffSyamt  * @cmd: IOCTL_PRIVCMD_INITDOMAIN_EVTCHN
111b0bd23ffSyamt  * @arg: n/a
112b0bd23ffSyamt  * Return: Port associated with domain-controller end of control event channel
113b0bd23ffSyamt  *         for the initial domain.
114b0bd23ffSyamt  */
115b0bd23ffSyamt #define IOCTL_PRIVCMD_INITDOMAIN_EVTCHN \
116b0bd23ffSyamt     _IOR('P', 5, int)
117*0e8ff7c9Sbouyer 
1185932e641Scegger #define IOCTL_PRIVCMD_MMAPBATCH_V2      \
119e1f9b2b0Scegger     _IOW('P', 6, privcmd_mmapbatch_v2_t)
120b0bd23ffSyamt 
121*0e8ff7c9Sbouyer /*
122*0e8ff7c9Sbouyer  * @cmd: IOCTL_PRIVCMD_MMAP_RESOURCE
123*0e8ff7c9Sbouyer  * @arg &privcmd_mmap_resource_t
124*0e8ff7c9Sbouyer  * Return:
125*0e8ff7c9Sbouyer  * map the specified resource at the provided virtual address
126*0e8ff7c9Sbouyer  */
127*0e8ff7c9Sbouyer 
128*0e8ff7c9Sbouyer typedef struct privcmd_mmap_resource {
129*0e8ff7c9Sbouyer         domid_t dom;
130*0e8ff7c9Sbouyer 	uint32_t type;
131*0e8ff7c9Sbouyer 	uint32_t id;
132*0e8ff7c9Sbouyer 	uint32_t idx;
133*0e8ff7c9Sbouyer 	uint64_t num;
134*0e8ff7c9Sbouyer 	uint64_t addr;
135*0e8ff7c9Sbouyer } privcmd_mmap_resource_t;
136*0e8ff7c9Sbouyer 
137*0e8ff7c9Sbouyer #define IOCTL_PRIVCMD_MMAP_RESOURCE      \
138*0e8ff7c9Sbouyer     _IOW('P', 7, privcmd_mmap_resource_t)
139*0e8ff7c9Sbouyer 
140*0e8ff7c9Sbouyer /*
141*0e8ff7c9Sbouyer  * @cmd: IOCTL_GNTDEV_MMAP_GRANT_REF
142*0e8ff7c9Sbouyer  * @arg &ioctl_gntdev_mmap_grant_ref
143*0e8ff7c9Sbouyer  * Return:
144*0e8ff7c9Sbouyer  * map the grant references at the virtual address provided by caller
145*0e8ff7c9Sbouyer  * The grant ref already exists (e.g. comes from a remote domain)
146*0e8ff7c9Sbouyer  */
147*0e8ff7c9Sbouyer struct ioctl_gntdev_grant_ref {
148*0e8ff7c9Sbouyer 	/* The domain ID of the grant to be mapped. */
149*0e8ff7c9Sbouyer 	uint32_t domid;
150*0e8ff7c9Sbouyer 	/* The grant reference of the grant to be mapped. */
151*0e8ff7c9Sbouyer 	uint32_t ref;
152*0e8ff7c9Sbouyer };
153*0e8ff7c9Sbouyer 
154*0e8ff7c9Sbouyer struct ioctl_gntdev_grant_notify {
155*0e8ff7c9Sbouyer 	ssize_t offset;
156*0e8ff7c9Sbouyer 	uint32_t action;
157*0e8ff7c9Sbouyer 	uint32_t event_channel_port;
158*0e8ff7c9Sbouyer };
159*0e8ff7c9Sbouyer #define UNMAP_NOTIFY_CLEAR_BYTE 0x1
160*0e8ff7c9Sbouyer #define UNMAP_NOTIFY_SEND_EVENT 0x2
161*0e8ff7c9Sbouyer 
162*0e8ff7c9Sbouyer struct ioctl_gntdev_mmap_grant_ref {
163*0e8ff7c9Sbouyer 	/* The number of grants to be mapped. */
164*0e8ff7c9Sbouyer 	uint32_t count;
165*0e8ff7c9Sbouyer 	uint32_t pad;
166*0e8ff7c9Sbouyer 	/* The virtual address where they should be mapped */
167*0e8ff7c9Sbouyer 	void *va;
168*0e8ff7c9Sbouyer 	/* notify action */
169*0e8ff7c9Sbouyer 	struct ioctl_gntdev_grant_notify notify;
170*0e8ff7c9Sbouyer 	/* Array of grant references, of size @count. */
171*0e8ff7c9Sbouyer 	struct ioctl_gntdev_grant_ref *refs;
172*0e8ff7c9Sbouyer };
173*0e8ff7c9Sbouyer 
174*0e8ff7c9Sbouyer #define IOCTL_GNTDEV_MMAP_GRANT_REF \
175*0e8ff7c9Sbouyer     _IOW('P', 8, struct ioctl_gntdev_mmap_grant_ref)
176*0e8ff7c9Sbouyer 
177*0e8ff7c9Sbouyer /*
178*0e8ff7c9Sbouyer  * @cmd: IOCTL_GNTDEV_ALLOC_GRANT_REF
179*0e8ff7c9Sbouyer  * @arg &ioctl_gntdev_alloc_grant_ref
180*0e8ff7c9Sbouyer  * Return:
181*0e8ff7c9Sbouyer  * Allocate local memory and grant it to a remote domain.
182*0e8ff7c9Sbouyer  * local memory is mmaped at the virtual address provided by caller
183*0e8ff7c9Sbouyer  */
184*0e8ff7c9Sbouyer 
185*0e8ff7c9Sbouyer struct ioctl_gntdev_alloc_grant_ref {
186*0e8ff7c9Sbouyer 	/* IN parameters */
187*0e8ff7c9Sbouyer 	uint16_t domid;
188*0e8ff7c9Sbouyer 	uint16_t flags;
189*0e8ff7c9Sbouyer 	uint32_t count;
190*0e8ff7c9Sbouyer 	void *va;
191*0e8ff7c9Sbouyer 	/* notify action */
192*0e8ff7c9Sbouyer 	struct ioctl_gntdev_grant_notify notify;
193*0e8ff7c9Sbouyer 	/* Variable OUT parameter */
194*0e8ff7c9Sbouyer 	uint32_t *gref_ids;
195*0e8ff7c9Sbouyer };
196*0e8ff7c9Sbouyer 
197*0e8ff7c9Sbouyer #define IOCTL_GNTDEV_ALLOC_GRANT_REF \
198*0e8ff7c9Sbouyer     _IOW('P', 9, struct ioctl_gntdev_alloc_grant_ref)
199*0e8ff7c9Sbouyer 
200*0e8ff7c9Sbouyer #define GNTDEV_ALLOC_FLAG_WRITABLE 0x01
201*0e8ff7c9Sbouyer 
202*0e8ff7c9Sbouyer 
203e9666f30Sbouyer /* Interface to /dev/xenevt */
204e9666f30Sbouyer /* EVTCHN_RESET: Clear and reinit the event buffer. Clear error condition. */
205e9666f30Sbouyer #define EVTCHN_RESET  _IO('E', 1)
206e9666f30Sbouyer /* EVTCHN_BIND: Bind to the specified event-channel port. */
207e9666f30Sbouyer #define EVTCHN_BIND   _IOW('E', 2, unsigned long)
208e9666f30Sbouyer /* EVTCHN_UNBIND: Unbind from the specified event-channel port. */
209e9666f30Sbouyer #define EVTCHN_UNBIND _IOW('E', 3, unsigned long)
210e9666f30Sbouyer 
21164db2748Scegger #endif /* __XEN_XENIO_H__ */
212