Merge tag 'sound-5.8-rc3' of git://git.kernel.org/pub/scm/linux/kernel/git/tiwai...
[linux-2.6-microblaze.git] / include / uapi / linux / io_uring.h
1 /* SPDX-License-Identifier: (GPL-2.0 WITH Linux-syscall-note) OR MIT */
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         union {
23                 __u64   off;    /* offset into file */
24                 __u64   addr2;
25         };
26         union {
27                 __u64   addr;   /* pointer to buffer or iovecs */
28                 __u64   splice_off_in;
29         };
30         __u32   len;            /* buffer size or number of iovecs */
31         union {
32                 __kernel_rwf_t  rw_flags;
33                 __u32           fsync_flags;
34                 __u16           poll_events;
35                 __u32           sync_range_flags;
36                 __u32           msg_flags;
37                 __u32           timeout_flags;
38                 __u32           accept_flags;
39                 __u32           cancel_flags;
40                 __u32           open_flags;
41                 __u32           statx_flags;
42                 __u32           fadvise_advice;
43                 __u32           splice_flags;
44         };
45         __u64   user_data;      /* data to be passed back at completion time */
46         union {
47                 struct {
48                         /* pack this to avoid bogus arm OABI complaints */
49                         union {
50                                 /* index into fixed buffers, if used */
51                                 __u16   buf_index;
52                                 /* for grouped buffer selection */
53                                 __u16   buf_group;
54                         } __attribute__((packed));
55                         /* personality to use, if used */
56                         __u16   personality;
57                         __s32   splice_fd_in;
58                 };
59                 __u64   __pad2[3];
60         };
61 };
62
63 enum {
64         IOSQE_FIXED_FILE_BIT,
65         IOSQE_IO_DRAIN_BIT,
66         IOSQE_IO_LINK_BIT,
67         IOSQE_IO_HARDLINK_BIT,
68         IOSQE_ASYNC_BIT,
69         IOSQE_BUFFER_SELECT_BIT,
70 };
71
72 /*
73  * sqe->flags
74  */
75 /* use fixed fileset */
76 #define IOSQE_FIXED_FILE        (1U << IOSQE_FIXED_FILE_BIT)
77 /* issue after inflight IO */
78 #define IOSQE_IO_DRAIN          (1U << IOSQE_IO_DRAIN_BIT)
79 /* links next sqe */
80 #define IOSQE_IO_LINK           (1U << IOSQE_IO_LINK_BIT)
81 /* like LINK, but stronger */
82 #define IOSQE_IO_HARDLINK       (1U << IOSQE_IO_HARDLINK_BIT)
83 /* always go async */
84 #define IOSQE_ASYNC             (1U << IOSQE_ASYNC_BIT)
85 /* select buffer from sqe->buf_group */
86 #define IOSQE_BUFFER_SELECT     (1U << IOSQE_BUFFER_SELECT_BIT)
87
88 /*
89  * io_uring_setup() flags
90  */
91 #define IORING_SETUP_IOPOLL     (1U << 0)       /* io_context is polled */
92 #define IORING_SETUP_SQPOLL     (1U << 1)       /* SQ poll thread */
93 #define IORING_SETUP_SQ_AFF     (1U << 2)       /* sq_thread_cpu is valid */
94 #define IORING_SETUP_CQSIZE     (1U << 3)       /* app defines CQ size */
95 #define IORING_SETUP_CLAMP      (1U << 4)       /* clamp SQ/CQ ring sizes */
96 #define IORING_SETUP_ATTACH_WQ  (1U << 5)       /* attach to existing wq */
97
98 enum {
99         IORING_OP_NOP,
100         IORING_OP_READV,
101         IORING_OP_WRITEV,
102         IORING_OP_FSYNC,
103         IORING_OP_READ_FIXED,
104         IORING_OP_WRITE_FIXED,
105         IORING_OP_POLL_ADD,
106         IORING_OP_POLL_REMOVE,
107         IORING_OP_SYNC_FILE_RANGE,
108         IORING_OP_SENDMSG,
109         IORING_OP_RECVMSG,
110         IORING_OP_TIMEOUT,
111         IORING_OP_TIMEOUT_REMOVE,
112         IORING_OP_ACCEPT,
113         IORING_OP_ASYNC_CANCEL,
114         IORING_OP_LINK_TIMEOUT,
115         IORING_OP_CONNECT,
116         IORING_OP_FALLOCATE,
117         IORING_OP_OPENAT,
118         IORING_OP_CLOSE,
119         IORING_OP_FILES_UPDATE,
120         IORING_OP_STATX,
121         IORING_OP_READ,
122         IORING_OP_WRITE,
123         IORING_OP_FADVISE,
124         IORING_OP_MADVISE,
125         IORING_OP_SEND,
126         IORING_OP_RECV,
127         IORING_OP_OPENAT2,
128         IORING_OP_EPOLL_CTL,
129         IORING_OP_SPLICE,
130         IORING_OP_PROVIDE_BUFFERS,
131         IORING_OP_REMOVE_BUFFERS,
132         IORING_OP_TEE,
133
134         /* this goes last, obviously */
135         IORING_OP_LAST,
136 };
137
138 /*
139  * sqe->fsync_flags
140  */
141 #define IORING_FSYNC_DATASYNC   (1U << 0)
142
143 /*
144  * sqe->timeout_flags
145  */
146 #define IORING_TIMEOUT_ABS      (1U << 0)
147
148 /*
149  * sqe->splice_flags
150  * extends splice(2) flags
151  */
152 #define SPLICE_F_FD_IN_FIXED    (1U << 31) /* the last bit of __u32 */
153
154 /*
155  * IO completion data structure (Completion Queue Entry)
156  */
157 struct io_uring_cqe {
158         __u64   user_data;      /* sqe->data submission passed back */
159         __s32   res;            /* result code for this event */
160         __u32   flags;
161 };
162
163 /*
164  * cqe->flags
165  *
166  * IORING_CQE_F_BUFFER  If set, the upper 16 bits are the buffer ID
167  */
168 #define IORING_CQE_F_BUFFER             (1U << 0)
169
170 enum {
171         IORING_CQE_BUFFER_SHIFT         = 16,
172 };
173
174 /*
175  * Magic offsets for the application to mmap the data it needs
176  */
177 #define IORING_OFF_SQ_RING              0ULL
178 #define IORING_OFF_CQ_RING              0x8000000ULL
179 #define IORING_OFF_SQES                 0x10000000ULL
180
181 /*
182  * Filled with the offset for mmap(2)
183  */
184 struct io_sqring_offsets {
185         __u32 head;
186         __u32 tail;
187         __u32 ring_mask;
188         __u32 ring_entries;
189         __u32 flags;
190         __u32 dropped;
191         __u32 array;
192         __u32 resv1;
193         __u64 resv2;
194 };
195
196 /*
197  * sq_ring->flags
198  */
199 #define IORING_SQ_NEED_WAKEUP   (1U << 0) /* needs io_uring_enter wakeup */
200
201 struct io_cqring_offsets {
202         __u32 head;
203         __u32 tail;
204         __u32 ring_mask;
205         __u32 ring_entries;
206         __u32 overflow;
207         __u32 cqes;
208         __u32 flags;
209         __u32 resv1;
210         __u64 resv2;
211 };
212
213 /*
214  * cq_ring->flags
215  */
216
217 /* disable eventfd notifications */
218 #define IORING_CQ_EVENTFD_DISABLED      (1U << 0)
219
220 /*
221  * io_uring_enter(2) flags
222  */
223 #define IORING_ENTER_GETEVENTS  (1U << 0)
224 #define IORING_ENTER_SQ_WAKEUP  (1U << 1)
225
226 /*
227  * Passed in for io_uring_setup(2). Copied back with updated info on success
228  */
229 struct io_uring_params {
230         __u32 sq_entries;
231         __u32 cq_entries;
232         __u32 flags;
233         __u32 sq_thread_cpu;
234         __u32 sq_thread_idle;
235         __u32 features;
236         __u32 wq_fd;
237         __u32 resv[3];
238         struct io_sqring_offsets sq_off;
239         struct io_cqring_offsets cq_off;
240 };
241
242 /*
243  * io_uring_params->features flags
244  */
245 #define IORING_FEAT_SINGLE_MMAP         (1U << 0)
246 #define IORING_FEAT_NODROP              (1U << 1)
247 #define IORING_FEAT_SUBMIT_STABLE       (1U << 2)
248 #define IORING_FEAT_RW_CUR_POS          (1U << 3)
249 #define IORING_FEAT_CUR_PERSONALITY     (1U << 4)
250 #define IORING_FEAT_FAST_POLL           (1U << 5)
251
252 /*
253  * io_uring_register(2) opcodes and arguments
254  */
255 #define IORING_REGISTER_BUFFERS         0
256 #define IORING_UNREGISTER_BUFFERS       1
257 #define IORING_REGISTER_FILES           2
258 #define IORING_UNREGISTER_FILES         3
259 #define IORING_REGISTER_EVENTFD         4
260 #define IORING_UNREGISTER_EVENTFD       5
261 #define IORING_REGISTER_FILES_UPDATE    6
262 #define IORING_REGISTER_EVENTFD_ASYNC   7
263 #define IORING_REGISTER_PROBE           8
264 #define IORING_REGISTER_PERSONALITY     9
265 #define IORING_UNREGISTER_PERSONALITY   10
266
267 struct io_uring_files_update {
268         __u32 offset;
269         __u32 resv;
270         __aligned_u64 /* __s32 * */ fds;
271 };
272
273 #define IO_URING_OP_SUPPORTED   (1U << 0)
274
275 struct io_uring_probe_op {
276         __u8 op;
277         __u8 resv;
278         __u16 flags;    /* IO_URING_OP_* flags */
279         __u32 resv2;
280 };
281
282 struct io_uring_probe {
283         __u8 last_op;   /* last opcode supported */
284         __u8 ops_len;   /* length of ops[] array below */
285         __u16 resv;
286         __u32 resv2[3];
287         struct io_uring_probe_op ops[0];
288 };
289
290 #endif