Home | History | Annotate | Line # | Download | only in include
      1 /*	$NetBSD: xenio.h,v 1.12 2020/05/26 10:11:56 bouyer Exp $	*/
      2 
      3 /******************************************************************************
      4  * privcmd.h
      5  *
      6  * Copyright (c) 2003-2004, K A Fraser
      7  *
      8  * This file may be distributed separately from the Linux kernel, or
      9  * incorporated into other software packages, subject to the following license:
     10  *
     11  * Permission is hereby granted, free of charge, to any person obtaining a copy
     12  * of this source file (the "Software"), to deal in the Software without
     13  * restriction, including without limitation the rights to use, copy, modify,
     14  * merge, publish, distribute, sublicense, and/or sell copies of the Software,
     15  * and to permit persons to whom the Software is furnished to do so, subject to
     16  * the following conditions:
     17  *
     18  * The above copyright notice and this permission notice shall be included in
     19  * all copies or substantial portions of the Software.
     20  *
     21  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
     22  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
     23  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
     24  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
     25  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
     26  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
     27  * IN THE SOFTWARE.
     28  */
     29 
     30 #ifndef __XEN_XENIO_H__
     31 #define __XEN_XENIO_H__
     32 
     33 /* Interface to /proc/xen/privcmd */
     34 
     35 #include <sys/ioccom.h>
     36 
     37 
     38 typedef struct privcmd_hypercall
     39 {
     40     unsigned long op;
     41     unsigned long arg[5];
     42     long retval;
     43 } privcmd_hypercall_t;
     44 
     45 typedef struct privcmd_mmap_entry {
     46     unsigned long va;
     47     unsigned long mfn;
     48     unsigned long npages;
     49 } privcmd_mmap_entry_t;
     50 
     51 typedef struct privcmd_mmap {
     52     int num;
     53     domid_t dom; /* target domain */
     54     privcmd_mmap_entry_t *entry;
     55 } privcmd_mmap_t;
     56 
     57 typedef struct privcmd_mmapbatch {
     58     int num;     /* number of pages to populate */
     59     domid_t dom; /* target domain */
     60     unsigned long addr;  /* virtual address */
     61     unsigned long *arr; /* array of mfns - top nibble set on err */
     62 } privcmd_mmapbatch_t;
     63 
     64 typedef struct privcmd_mmapbatch_v2 {
     65     int num;     /* number of pages to populate */
     66     domid_t dom; /* target domain */
     67     uint64_t addr;  /* virtual address */
     68     const xen_pfn_t *arr; /* array of mfns */
     69     int *err; /* array of error codes */
     70 } privcmd_mmapbatch_v2_t;
     71 
     72 typedef struct privcmd_blkmsg
     73 {
     74     unsigned long op;
     75     void         *buf;
     76     int           buf_size;
     77 } privcmd_blkmsg_t;
     78 
     79 /*
     80  * @cmd: IOCTL_PRIVCMD_HYPERCALL
     81  * @arg: &privcmd_hypercall_t
     82  * Return: Value returned from execution of the specified hypercall.
     83  */
     84 #define IOCTL_PRIVCMD_HYPERCALL         \
     85     _IOWR('P', 0, privcmd_hypercall_t)
     86 
     87 #if defined(_KERNEL)
     88 /* compat */
     89 #define IOCTL_PRIVCMD_INITDOMAIN_EVTCHN_OLD \
     90     _IO('P', 1)
     91 
     92 typedef struct oprivcmd_hypercall
     93 {
     94     unsigned long op;
     95     unsigned long arg[5];
     96 } oprivcmd_hypercall_t;
     97 
     98 #define IOCTL_PRIVCMD_HYPERCALL_OLD       \
     99     _IOWR('P', 0, oprivcmd_hypercall_t)
    100 #endif /* defined(_KERNEL) */
    101 
    102 #define IOCTL_PRIVCMD_MMAP             \
    103     _IOW('P', 2, privcmd_mmap_t)
    104 #define IOCTL_PRIVCMD_MMAPBATCH        \
    105     _IOW('P', 3, privcmd_mmapbatch_t)
    106 #define IOCTL_PRIVCMD_GET_MACH2PHYS_START_MFN \
    107     _IOR('P', 4, unsigned long)
    108 
    109 /*
    110  * @cmd: IOCTL_PRIVCMD_INITDOMAIN_EVTCHN
    111  * @arg: n/a
    112  * Return: Port associated with domain-controller end of control event channel
    113  *         for the initial domain.
    114  */
    115 #define IOCTL_PRIVCMD_INITDOMAIN_EVTCHN \
    116     _IOR('P', 5, int)
    117 
    118 #define IOCTL_PRIVCMD_MMAPBATCH_V2      \
    119     _IOW('P', 6, privcmd_mmapbatch_v2_t)
    120 
    121 /*
    122  * @cmd: IOCTL_PRIVCMD_MMAP_RESOURCE
    123  * @arg &privcmd_mmap_resource_t
    124  * Return:
    125  * map the specified resource at the provided virtual address
    126  */
    127 
    128 typedef struct privcmd_mmap_resource {
    129         domid_t dom;
    130 	uint32_t type;
    131 	uint32_t id;
    132 	uint32_t idx;
    133 	uint64_t num;
    134 	uint64_t addr;
    135 } privcmd_mmap_resource_t;
    136 
    137 #define IOCTL_PRIVCMD_MMAP_RESOURCE      \
    138     _IOW('P', 7, privcmd_mmap_resource_t)
    139 
    140 /*
    141  * @cmd: IOCTL_GNTDEV_MMAP_GRANT_REF
    142  * @arg &ioctl_gntdev_mmap_grant_ref
    143  * Return:
    144  * map the grant references at the virtual address provided by caller
    145  * The grant ref already exists (e.g. comes from a remote domain)
    146  */
    147 struct ioctl_gntdev_grant_ref {
    148 	/* The domain ID of the grant to be mapped. */
    149 	uint32_t domid;
    150 	/* The grant reference of the grant to be mapped. */
    151 	uint32_t ref;
    152 };
    153 
    154 struct ioctl_gntdev_grant_notify {
    155 	ssize_t offset;
    156 	uint32_t action;
    157 	uint32_t event_channel_port;
    158 };
    159 #define UNMAP_NOTIFY_CLEAR_BYTE 0x1
    160 #define UNMAP_NOTIFY_SEND_EVENT 0x2
    161 
    162 struct ioctl_gntdev_mmap_grant_ref {
    163 	/* The number of grants to be mapped. */
    164 	uint32_t count;
    165 	uint32_t pad;
    166 	/* The virtual address where they should be mapped */
    167 	void *va;
    168 	/* notify action */
    169 	struct ioctl_gntdev_grant_notify notify;
    170 	/* Array of grant references, of size @count. */
    171 	struct ioctl_gntdev_grant_ref *refs;
    172 };
    173 
    174 #define IOCTL_GNTDEV_MMAP_GRANT_REF \
    175     _IOW('P', 8, struct ioctl_gntdev_mmap_grant_ref)
    176 
    177 /*
    178  * @cmd: IOCTL_GNTDEV_ALLOC_GRANT_REF
    179  * @arg &ioctl_gntdev_alloc_grant_ref
    180  * Return:
    181  * Allocate local memory and grant it to a remote domain.
    182  * local memory is mmaped at the virtual address provided by caller
    183  */
    184 
    185 struct ioctl_gntdev_alloc_grant_ref {
    186 	/* IN parameters */
    187 	uint16_t domid;
    188 	uint16_t flags;
    189 	uint32_t count;
    190 	void *va;
    191 	/* notify action */
    192 	struct ioctl_gntdev_grant_notify notify;
    193 	/* Variable OUT parameter */
    194 	uint32_t *gref_ids;
    195 };
    196 
    197 #define IOCTL_GNTDEV_ALLOC_GRANT_REF \
    198     _IOW('P', 9, struct ioctl_gntdev_alloc_grant_ref)
    199 
    200 #define GNTDEV_ALLOC_FLAG_WRITABLE 0x01
    201 
    202 
    203 /* Interface to /dev/xenevt */
    204 /* EVTCHN_RESET: Clear and reinit the event buffer. Clear error condition. */
    205 #define EVTCHN_RESET  _IO('E', 1)
    206 /* EVTCHN_BIND: Bind to the specified event-channel port. */
    207 #define EVTCHN_BIND   _IOW('E', 2, unsigned long)
    208 /* EVTCHN_UNBIND: Unbind from the specified event-channel port. */
    209 #define EVTCHN_UNBIND _IOW('E', 3, unsigned long)
    210 
    211 #endif /* __XEN_XENIO_H__ */
    212