drm/modes: Fix drm_mode_vrefres() docs
[drm/drm-misc.git] / io_uring / rsrc.h
blob7a4668deaa1a9efb3728eaae53bcb8b84792898f
1 // SPDX-License-Identifier: GPL-2.0
2 #ifndef IOU_RSRC_H
3 #define IOU_RSRC_H
5 #define IO_NODE_ALLOC_CACHE_MAX 32
7 #define IO_RSRC_TAG_TABLE_SHIFT (PAGE_SHIFT - 3)
8 #define IO_RSRC_TAG_TABLE_MAX (1U << IO_RSRC_TAG_TABLE_SHIFT)
9 #define IO_RSRC_TAG_TABLE_MASK (IO_RSRC_TAG_TABLE_MAX - 1)
11 enum {
12 IORING_RSRC_FILE = 0,
13 IORING_RSRC_BUFFER = 1,
16 struct io_rsrc_node {
17 unsigned char type;
18 int refs;
20 u64 tag;
21 union {
22 unsigned long file_ptr;
23 struct io_mapped_ubuf *buf;
27 struct io_mapped_ubuf {
28 u64 ubuf;
29 unsigned int len;
30 unsigned int nr_bvecs;
31 unsigned int folio_shift;
32 refcount_t refs;
33 unsigned long acct_pages;
34 struct bio_vec bvec[] __counted_by(nr_bvecs);
37 struct io_imu_folio_data {
38 /* Head folio can be partially included in the fixed buf */
39 unsigned int nr_pages_head;
40 /* For non-head/tail folios, has to be fully included */
41 unsigned int nr_pages_mid;
42 unsigned int folio_shift;
45 struct io_rsrc_node *io_rsrc_node_alloc(struct io_ring_ctx *ctx, int type);
46 void io_free_rsrc_node(struct io_ring_ctx *ctx, struct io_rsrc_node *node);
47 void io_rsrc_data_free(struct io_ring_ctx *ctx, struct io_rsrc_data *data);
48 int io_rsrc_data_alloc(struct io_rsrc_data *data, unsigned nr);
50 int io_import_fixed(int ddir, struct iov_iter *iter,
51 struct io_mapped_ubuf *imu,
52 u64 buf_addr, size_t len);
54 int io_register_clone_buffers(struct io_ring_ctx *ctx, void __user *arg);
55 int io_sqe_buffers_unregister(struct io_ring_ctx *ctx);
56 int io_sqe_buffers_register(struct io_ring_ctx *ctx, void __user *arg,
57 unsigned int nr_args, u64 __user *tags);
58 int io_sqe_files_unregister(struct io_ring_ctx *ctx);
59 int io_sqe_files_register(struct io_ring_ctx *ctx, void __user *arg,
60 unsigned nr_args, u64 __user *tags);
62 int io_register_files_update(struct io_ring_ctx *ctx, void __user *arg,
63 unsigned nr_args);
64 int io_register_rsrc_update(struct io_ring_ctx *ctx, void __user *arg,
65 unsigned size, unsigned type);
66 int io_register_rsrc(struct io_ring_ctx *ctx, void __user *arg,
67 unsigned int size, unsigned int type);
69 static inline struct io_rsrc_node *io_rsrc_node_lookup(struct io_rsrc_data *data,
70 int index)
72 if (index < data->nr)
73 return data->nodes[array_index_nospec(index, data->nr)];
74 return NULL;
77 static inline void io_put_rsrc_node(struct io_ring_ctx *ctx, struct io_rsrc_node *node)
79 if (node && !--node->refs)
80 io_free_rsrc_node(ctx, node);
83 static inline bool io_reset_rsrc_node(struct io_ring_ctx *ctx,
84 struct io_rsrc_data *data, int index)
86 struct io_rsrc_node *node = data->nodes[index];
88 if (!node)
89 return false;
90 io_put_rsrc_node(ctx, node);
91 data->nodes[index] = NULL;
92 return true;
95 static inline void io_req_put_rsrc_nodes(struct io_kiocb *req)
97 if (req->file_node) {
98 io_put_rsrc_node(req->ctx, req->file_node);
99 req->file_node = NULL;
101 if (req->flags & REQ_F_BUF_NODE) {
102 io_put_rsrc_node(req->ctx, req->buf_node);
103 req->buf_node = NULL;
107 static inline void io_req_assign_rsrc_node(struct io_rsrc_node **dst_node,
108 struct io_rsrc_node *node)
110 node->refs++;
111 *dst_node = node;
114 static inline void io_req_assign_buf_node(struct io_kiocb *req,
115 struct io_rsrc_node *node)
117 io_req_assign_rsrc_node(&req->buf_node, node);
118 req->flags |= REQ_F_BUF_NODE;
121 int io_files_update(struct io_kiocb *req, unsigned int issue_flags);
122 int io_files_update_prep(struct io_kiocb *req, const struct io_uring_sqe *sqe);
124 int __io_account_mem(struct user_struct *user, unsigned long nr_pages);
126 static inline void __io_unaccount_mem(struct user_struct *user,
127 unsigned long nr_pages)
129 atomic_long_sub(nr_pages, &user->locked_vm);
132 #endif