Merge tag 'drm-intel-next-2019-04-04' into gvt-next
[linux-2.6-microblaze.git] / drivers / gpu / drm / i915 / i915_gem_context.h
1 /*
2  * Copyright © 2016 Intel Corporation
3  *
4  * Permission is hereby granted, free of charge, to any person obtaining a
5  * copy of this software and associated documentation files (the "Software"),
6  * to deal in the Software without restriction, including without limitation
7  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8  * and/or sell copies of the Software, and to permit persons to whom the
9  * Software is furnished to do so, subject to the following conditions:
10  *
11  * The above copyright notice and this permission notice (including the next
12  * paragraph) shall be included in all copies or substantial portions of the
13  * Software.
14  *
15  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
18  * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
21  * IN THE SOFTWARE.
22  *
23  */
24
25 #ifndef __I915_GEM_CONTEXT_H__
26 #define __I915_GEM_CONTEXT_H__
27
28 #include "i915_gem_context_types.h"
29
30 #include "i915_gem.h"
31 #include "i915_scheduler.h"
32 #include "intel_context.h"
33 #include "intel_device_info.h"
34
35 struct drm_device;
36 struct drm_file;
37
38 static inline bool i915_gem_context_is_closed(const struct i915_gem_context *ctx)
39 {
40         return test_bit(CONTEXT_CLOSED, &ctx->flags);
41 }
42
43 static inline void i915_gem_context_set_closed(struct i915_gem_context *ctx)
44 {
45         GEM_BUG_ON(i915_gem_context_is_closed(ctx));
46         set_bit(CONTEXT_CLOSED, &ctx->flags);
47 }
48
49 static inline bool i915_gem_context_no_error_capture(const struct i915_gem_context *ctx)
50 {
51         return test_bit(UCONTEXT_NO_ERROR_CAPTURE, &ctx->user_flags);
52 }
53
54 static inline void i915_gem_context_set_no_error_capture(struct i915_gem_context *ctx)
55 {
56         set_bit(UCONTEXT_NO_ERROR_CAPTURE, &ctx->user_flags);
57 }
58
59 static inline void i915_gem_context_clear_no_error_capture(struct i915_gem_context *ctx)
60 {
61         clear_bit(UCONTEXT_NO_ERROR_CAPTURE, &ctx->user_flags);
62 }
63
64 static inline bool i915_gem_context_is_bannable(const struct i915_gem_context *ctx)
65 {
66         return test_bit(UCONTEXT_BANNABLE, &ctx->user_flags);
67 }
68
69 static inline void i915_gem_context_set_bannable(struct i915_gem_context *ctx)
70 {
71         set_bit(UCONTEXT_BANNABLE, &ctx->user_flags);
72 }
73
74 static inline void i915_gem_context_clear_bannable(struct i915_gem_context *ctx)
75 {
76         clear_bit(UCONTEXT_BANNABLE, &ctx->user_flags);
77 }
78
79 static inline bool i915_gem_context_is_recoverable(const struct i915_gem_context *ctx)
80 {
81         return test_bit(UCONTEXT_RECOVERABLE, &ctx->user_flags);
82 }
83
84 static inline void i915_gem_context_set_recoverable(struct i915_gem_context *ctx)
85 {
86         set_bit(UCONTEXT_RECOVERABLE, &ctx->user_flags);
87 }
88
89 static inline void i915_gem_context_clear_recoverable(struct i915_gem_context *ctx)
90 {
91         clear_bit(UCONTEXT_RECOVERABLE, &ctx->user_flags);
92 }
93
94 static inline bool i915_gem_context_is_banned(const struct i915_gem_context *ctx)
95 {
96         return test_bit(CONTEXT_BANNED, &ctx->flags);
97 }
98
99 static inline void i915_gem_context_set_banned(struct i915_gem_context *ctx)
100 {
101         set_bit(CONTEXT_BANNED, &ctx->flags);
102 }
103
104 static inline bool i915_gem_context_force_single_submission(const struct i915_gem_context *ctx)
105 {
106         return test_bit(CONTEXT_FORCE_SINGLE_SUBMISSION, &ctx->flags);
107 }
108
109 static inline void i915_gem_context_set_force_single_submission(struct i915_gem_context *ctx)
110 {
111         __set_bit(CONTEXT_FORCE_SINGLE_SUBMISSION, &ctx->flags);
112 }
113
114 int __i915_gem_context_pin_hw_id(struct i915_gem_context *ctx);
115 static inline int i915_gem_context_pin_hw_id(struct i915_gem_context *ctx)
116 {
117         if (atomic_inc_not_zero(&ctx->hw_id_pin_count))
118                 return 0;
119
120         return __i915_gem_context_pin_hw_id(ctx);
121 }
122
123 static inline void i915_gem_context_unpin_hw_id(struct i915_gem_context *ctx)
124 {
125         GEM_BUG_ON(atomic_read(&ctx->hw_id_pin_count) == 0u);
126         atomic_dec(&ctx->hw_id_pin_count);
127 }
128
129 static inline bool i915_gem_context_is_kernel(struct i915_gem_context *ctx)
130 {
131         return !ctx->file_priv;
132 }
133
134 /* i915_gem_context.c */
135 int __must_check i915_gem_contexts_init(struct drm_i915_private *dev_priv);
136 void i915_gem_contexts_lost(struct drm_i915_private *dev_priv);
137 void i915_gem_contexts_fini(struct drm_i915_private *dev_priv);
138
139 int i915_gem_context_open(struct drm_i915_private *i915,
140                           struct drm_file *file);
141 void i915_gem_context_close(struct drm_file *file);
142
143 int i915_switch_context(struct i915_request *rq);
144 int i915_gem_switch_to_kernel_context(struct drm_i915_private *i915,
145                                       intel_engine_mask_t engine_mask);
146
147 void i915_gem_context_release(struct kref *ctx_ref);
148 struct i915_gem_context *
149 i915_gem_context_create_gvt(struct drm_device *dev);
150
151 int i915_gem_vm_create_ioctl(struct drm_device *dev, void *data,
152                              struct drm_file *file);
153 int i915_gem_vm_destroy_ioctl(struct drm_device *dev, void *data,
154                               struct drm_file *file);
155
156 int i915_gem_context_create_ioctl(struct drm_device *dev, void *data,
157                                   struct drm_file *file);
158 int i915_gem_context_destroy_ioctl(struct drm_device *dev, void *data,
159                                    struct drm_file *file);
160 int i915_gem_context_getparam_ioctl(struct drm_device *dev, void *data,
161                                     struct drm_file *file_priv);
162 int i915_gem_context_setparam_ioctl(struct drm_device *dev, void *data,
163                                     struct drm_file *file_priv);
164 int i915_gem_context_reset_stats_ioctl(struct drm_device *dev, void *data,
165                                        struct drm_file *file);
166
167 struct i915_gem_context *
168 i915_gem_context_create_kernel(struct drm_i915_private *i915, int prio);
169
170 static inline struct i915_gem_context *
171 i915_gem_context_get(struct i915_gem_context *ctx)
172 {
173         kref_get(&ctx->ref);
174         return ctx;
175 }
176
177 static inline void i915_gem_context_put(struct i915_gem_context *ctx)
178 {
179         kref_put(&ctx->ref, i915_gem_context_release);
180 }
181
182 struct i915_lut_handle *i915_lut_handle_alloc(void);
183 void i915_lut_handle_free(struct i915_lut_handle *lut);
184
185 #endif /* !__I915_GEM_CONTEXT_H__ */