XenevaOS
Loading...
Searching...
No Matches
ioctl.h
Go to the documentation of this file.
1#ifndef __LINUX_IOCTL_H__
2#define __LINUX_IOCTL_H__
3
4/*
5 * DCL <linux/ioctl.h> -- the _IOC encoding, from uapi/asm-generic/ioctl.h.
6 *
7 * WHY THIS EXISTS ALONGSIDE BaseHdr/Fs/tty.h
8 * ------------------------------------------
9 * Xeneva's own devfs already has an ioctl vocabulary (Fs/tty.h: TIOCGWINSZ
10 * 0x5401 and friends), written as bare numbers because that is what Xeneva's
11 * dispatch compares against. The mainline tty stack does not work that way:
12 * several of its request numbers are *computed* from a direction/size/type
13 * tuple, and serial_core.c compares against two of them --
14 *
15 * case TIOCSISO7816: case TIOCGISO7816: (serial_core.c:1601,1605)
16 *
17 * -- which are _IOWR('T', 0x43, struct serial_iso7816) and
18 * _IOR('T', 0x42, struct serial_iso7816), i.e. they cannot be written as
19 * plain integers without baking in sizeof(struct serial_iso7816).
20 *
21 * So there are two encodings in the tree for now. That is a real
22 * inconsistency, not an oversight, and it is recorded as an open question in
23 * DCL_TODO.md for the stage that brings tty_io.c's dispatch over: whoever
24 * wires request routing has to decide which encoding userspace speaks. Until
25 * then this header is mainline's, unmodified in layout, so nothing that
26 * depends on the encoding is quietly wrong.
27 *
28 * upstream include/uapi/asm-generic/ioctl.h (mainline v7.2)
29 */
30
31#define _IOC_NRBITS 8
32#define _IOC_TYPEBITS 8
33#define _IOC_SIZEBITS 14
34#define _IOC_DIRBITS 2
35
36#define _IOC_NRSHIFT 0
37#define _IOC_TYPESHIFT (_IOC_NRSHIFT + _IOC_NRBITS)
38#define _IOC_SIZESHIFT (_IOC_TYPESHIFT + _IOC_TYPEBITS)
39#define _IOC_DIRSHIFT (_IOC_SIZESHIFT + _IOC_SIZEBITS)
40
41#define _IOC_NONE 0U
42#define _IOC_WRITE 1U
43#define _IOC_READ 2U
44
45#define _IOC(dir, type, nr, size) \
46 (((dir) << _IOC_DIRSHIFT) | \
47 ((type) << _IOC_TYPESHIFT) | \
48 ((nr) << _IOC_NRSHIFT) | \
49 ((size) << _IOC_SIZESHIFT))
50
51#define _IO(type, nr) _IOC(_IOC_NONE, (type), (nr), 0)
52#define _IOR(type, nr, size) _IOC(_IOC_READ, (type), (nr), sizeof(size))
53#define _IOW(type, nr, size) _IOC(_IOC_WRITE, (type), (nr), sizeof(size))
54#define _IOWR(type, nr, size) _IOC(_IOC_READ | _IOC_WRITE, (type), (nr), sizeof(size))
55
56#define _IOC_DIR(nr) (((nr) >> _IOC_DIRSHIFT) & ((1 << _IOC_DIRBITS) - 1))
57#define _IOC_TYPE(nr) (((nr) >> _IOC_TYPESHIFT) & ((1 << _IOC_TYPEBITS) - 1))
58#define _IOC_NR(nr) (((nr) >> _IOC_NRSHIFT) & ((1 << _IOC_NRBITS) - 1))
59#define _IOC_SIZE(nr) (((nr) >> _IOC_SIZESHIFT) & ((1 << _IOC_SIZEBITS) - 1))
60
61#endif /* __LINUX_IOCTL_H__ */