| 1 | /* |
| 2 | * FreeBSD ioccom definitions for ioctl(2) emulation |
| 3 | * |
| 4 | * Copyright (c) 2013 Stacey D. Son |
| 5 | * |
| 6 | * SPDX-License-Identifier: GPL-2.0-or-later |
| 7 | */ |
| 8 | #ifndef BSD_USER_FREEBSD_OS_IOCTL_IOCCOM_H |
| 9 | #define BSD_USER_FREEBSD_OS_IOCTL_IOCCOM_H |
| 10 | |
| 11 | /* |
| 12 | * Ioctl's have the command encoded in the lower word, and the size of |
| 13 | * any in or out parameters in the upper word. The high 3 bits of the |
| 14 | * upper word are used to encode the in/out status of the parameter. |
| 15 | */ |
| 16 | /* number of bits for ioctl size */ |
| 17 | #define TARGET_IOCPARM_SHIFT 13 |
| 18 | |
| 19 | /* parameter length mask */ |
| 20 | #define TARGET_IOCPARM_MASK ((1 << TARGET_IOCPARM_SHIFT) - 1) |
| 21 | |
| 22 | #define TARGET_IOCPARM_LEN(x) (((x) >> 16) & TARGET_IOCPARM_MASK) |
| 23 | #define TARGET_IOCBASECMD(x) ((x) & ~(TARGET_IOCPARM_MASK << 16)) |
| 24 | #define TARGET_IOCGROUP(x) (((x) >> 8) & 0xff) |
| 25 | |
| 26 | #define TARGET_IOCPARM_MAX (1 << TARGET_IOCPARM_SHIFT) /* max size of ioctl */ |
| 27 | #define TARGET_IOC_VOID 0x20000000 /* no parameters */ |
| 28 | #define TARGET_IOC_OUT 0x40000000 /* copy out parameters */ |
| 29 | #define TARGET_IOC_IN 0x80000000 /* copy in parameters */ |
| 30 | #define TARGET_IOC_INOUT (TARGET_IOC_IN | TARGET_IOC_OUT) |
| 31 | #define TARGET_IOC_DIRMASK (TARGET_IOC_VOID | TARGET_IOC_OUT | TARGET_IOC_IN) |
| 32 | |
| 33 | #define TARGET_IOC(inout, group, num, len) ((abi_ulong) \ |
| 34 | ((inout) | (((len) & TARGET_IOCPARM_MASK) << 16) | ((group) << 8) \ |
| 35 | | (num))) |
| 36 | #define TARGET_IO(g, n) TARGET_IOC(TARGET_IOC_VOID, (g), (n), 0) |
| 37 | #define TARGET_IOWINT(g, n) TARGET_IOC(TARGET_IOC_VOID, (g), (n), sizeof(int)) |
| 38 | #define TARGET_IOR(g, n, t) TARGET_IOC(TARGET_IOC_OUT, (g), (n), sizeof(t)) |
| 39 | #define TARGET_IOW(g, n, t) TARGET_IOC(TARGET_IOC_IN, (g), (n), sizeof(t)) |
| 40 | /* this should be _IORW, but stdio got there first */ |
| 41 | #define TARGET_IOWR(g, n, t) TARGET_IOC(TARGET_IOC_INOUT, (g), (n), sizeof(t)) |
| 42 | |
| 43 | #endif /* BSD_USER_FREEBSD_OS_IOCTL_IOCCOM_H */ |