Linux-libre 5.4.48-gnu
[librecmc/linux-libre.git] / include / uapi / linux / io_uring.h
1 /* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
2 /*
3  * Header file for the io_uring interface.
4  *
5  * Copyright (C) 2019 Jens Axboe
6  * Copyright (C) 2019 Christoph Hellwig
7  */
8 #ifndef LINUX_IO_URING_H
9 #define LINUX_IO_URING_H
10
11 #include <linux/fs.h>
12 #include <linux/types.h>
13
14 /*
15  * IO submission data structure (Submission Queue Entry)
16  */
17 struct io_uring_sqe {
18         __u8    opcode;         /* type of operation for this sqe */
19         __u8    flags;          /* IOSQE_ flags */
20         __u16   ioprio;         /* ioprio for the request */
21         __s32   fd;             /* file descriptor to do IO on */
22         __u64   off;            /* offset into file */
23         __u64   addr;           /* pointer to buffer or iovecs */
24         __u32   len;            /* buffer size or number of iovecs */
25         union {
26                 __kernel_rwf_t  rw_flags;
27                 __u32           fsync_flags;
28                 __u16           poll_events;
29                 __u32           sync_range_flags;
30                 __u32           msg_flags;
31                 __u32           timeout_flags;
32         };
33         __u64   user_data;      /* data to be passed back at completion time */
34         union {
35                 __u16   buf_index;      /* index into fixed buffers, if used */
36                 __u64   __pad2[3];
37         };
38 };
39
40 /*
41  * sqe->flags
42  */
43 #define IOSQE_FIXED_FILE        (1U << 0)       /* use fixed fileset */
44 #define IOSQE_IO_DRAIN          (1U << 1)       /* issue after inflight IO */
45 #define IOSQE_IO_LINK           (1U << 2)       /* links next sqe */
46
47 /*
48  * io_uring_setup() flags
49  */
50 #define IORING_SETUP_IOPOLL     (1U << 0)       /* io_context is polled */
51 #define IORING_SETUP_SQPOLL     (1U << 1)       /* SQ poll thread */
52 #define IORING_SETUP_SQ_AFF     (1U << 2)       /* sq_thread_cpu is valid */
53
54 #define IORING_OP_NOP           0
55 #define IORING_OP_READV         1
56 #define IORING_OP_WRITEV        2
57 #define IORING_OP_FSYNC         3
58 #define IORING_OP_READ_FIXED    4
59 #define IORING_OP_WRITE_FIXED   5
60 #define IORING_OP_POLL_ADD      6
61 #define IORING_OP_POLL_REMOVE   7
62 #define IORING_OP_SYNC_FILE_RANGE       8
63 #define IORING_OP_SENDMSG       9
64 #define IORING_OP_RECVMSG       10
65 #define IORING_OP_TIMEOUT       11
66
67 /*
68  * sqe->fsync_flags
69  */
70 #define IORING_FSYNC_DATASYNC   (1U << 0)
71
72 /*
73  * IO completion data structure (Completion Queue Entry)
74  */
75 struct io_uring_cqe {
76         __u64   user_data;      /* sqe->data submission passed back */
77         __s32   res;            /* result code for this event */
78         __u32   flags;
79 };
80
81 /*
82  * Magic offsets for the application to mmap the data it needs
83  */
84 #define IORING_OFF_SQ_RING              0ULL
85 #define IORING_OFF_CQ_RING              0x8000000ULL
86 #define IORING_OFF_SQES                 0x10000000ULL
87
88 /*
89  * Filled with the offset for mmap(2)
90  */
91 struct io_sqring_offsets {
92         __u32 head;
93         __u32 tail;
94         __u32 ring_mask;
95         __u32 ring_entries;
96         __u32 flags;
97         __u32 dropped;
98         __u32 array;
99         __u32 resv1;
100         __u64 resv2;
101 };
102
103 /*
104  * sq_ring->flags
105  */
106 #define IORING_SQ_NEED_WAKEUP   (1U << 0) /* needs io_uring_enter wakeup */
107
108 struct io_cqring_offsets {
109         __u32 head;
110         __u32 tail;
111         __u32 ring_mask;
112         __u32 ring_entries;
113         __u32 overflow;
114         __u32 cqes;
115         __u64 resv[2];
116 };
117
118 /*
119  * io_uring_enter(2) flags
120  */
121 #define IORING_ENTER_GETEVENTS  (1U << 0)
122 #define IORING_ENTER_SQ_WAKEUP  (1U << 1)
123
124 /*
125  * Passed in for io_uring_setup(2). Copied back with updated info on success
126  */
127 struct io_uring_params {
128         __u32 sq_entries;
129         __u32 cq_entries;
130         __u32 flags;
131         __u32 sq_thread_cpu;
132         __u32 sq_thread_idle;
133         __u32 features;
134         __u32 resv[4];
135         struct io_sqring_offsets sq_off;
136         struct io_cqring_offsets cq_off;
137 };
138
139 /*
140  * io_uring_params->features flags
141  */
142 #define IORING_FEAT_SINGLE_MMAP         (1U << 0)
143
144 /*
145  * io_uring_register(2) opcodes and arguments
146  */
147 #define IORING_REGISTER_BUFFERS         0
148 #define IORING_UNREGISTER_BUFFERS       1
149 #define IORING_REGISTER_FILES           2
150 #define IORING_UNREGISTER_FILES         3
151 #define IORING_REGISTER_EVENTFD         4
152 #define IORING_UNREGISTER_EVENTFD       5
153
154 #endif