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