1 /* $FreeBSD$ */ 2 /*- 3 * Copyright (c) 2014 Hans Petter Selasky. All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright 9 * notice, this list of conditions and the following disclaimer. 10 * 2. Redistributions in binary form must reproduce the above copyright 11 * notice, this list of conditions and the following disclaimer in the 12 * documentation and/or other materials provided with the distribution. 13 * 14 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 15 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 16 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 17 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 18 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 19 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 20 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 24 * SUCH DAMAGE. 25 */ 26 27 #ifndef _CUSE_IOCTL_H_ 28 #define _CUSE_IOCTL_H_ 29 30 #include <sys/ioccom.h> 31 #include <sys/types.h> 32 33 #define CUSE_BUFFER_MAX PAGE_SIZE 34 #define CUSE_DEVICES_MAX 64 /* units */ 35 #define CUSE_BUF_MIN_PTR 0x10000UL 36 #define CUSE_BUF_MAX_PTR 0x20000UL 37 #define CUSE_ALLOC_UNIT_MAX 128 /* units */ 38 /* All memory allocations must be less than the following limit */ 39 #define CUSE_ALLOC_PAGES_MAX (((16UL * 1024UL * 1024UL) + PAGE_SIZE - 1) / PAGE_SIZE) 40 41 struct cuse_dev; 42 43 struct cuse_data_chunk { 44 uintptr_t local_ptr; 45 uintptr_t peer_ptr; 46 unsigned long length; 47 }; 48 49 struct cuse_alloc_info { 50 unsigned long page_count; 51 unsigned long alloc_nr; 52 }; 53 54 struct cuse_command { 55 struct cuse_dev *dev; 56 unsigned long fflags; 57 uintptr_t per_file_handle; 58 uintptr_t data_pointer; 59 unsigned long argument; 60 unsigned long command; /* see CUSE_CMD_XXX */ 61 }; 62 63 struct cuse_create_dev { 64 struct cuse_dev *dev; 65 uid_t user_id; 66 gid_t group_id; 67 int permissions; 68 char devname[80]; /* /dev/xxxxx */ 69 }; 70 71 /* Definition of internal IOCTLs for /dev/cuse */ 72 73 #define CUSE_IOCTL_GET_COMMAND _IOR('C', 0, struct cuse_command) 74 #define CUSE_IOCTL_WRITE_DATA _IOW('C', 1, struct cuse_data_chunk) 75 #define CUSE_IOCTL_READ_DATA _IOW('C', 2, struct cuse_data_chunk) 76 #define CUSE_IOCTL_SYNC_COMMAND _IOW('C', 3, int) 77 #define CUSE_IOCTL_GET_SIG _IOR('C', 4, int) 78 #define CUSE_IOCTL_ALLOC_MEMORY _IOW('C', 5, struct cuse_alloc_info) 79 #define CUSE_IOCTL_FREE_MEMORY _IOW('C', 6, struct cuse_alloc_info) 80 #define CUSE_IOCTL_SET_PFH _IOW('C', 7, uintptr_t) 81 #define CUSE_IOCTL_CREATE_DEV _IOW('C', 8, struct cuse_create_dev) 82 #define CUSE_IOCTL_DESTROY_DEV _IOW('C', 9, struct cuse_dev *) 83 #define CUSE_IOCTL_ALLOC_UNIT _IOR('C',10, int) 84 #define CUSE_IOCTL_FREE_UNIT _IOW('C',11, int) 85 #define CUSE_IOCTL_SELWAKEUP _IOW('C',12, int) 86 #define CUSE_IOCTL_ALLOC_UNIT_BY_ID _IOWR('C',13, int) 87 #define CUSE_IOCTL_FREE_UNIT_BY_ID _IOWR('C',14, int) 88 89 #endif /* _CUSE_IOCTL_H_ */ 90