Rev 6937 | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 6937 | Rev 7144 | ||
---|---|---|---|
1 | /* |
1 | /* |
2 | * Copyright © 2008,2010 Intel Corporation |
2 | * Copyright © 2008,2010 Intel Corporation |
3 | * |
3 | * |
4 | * Permission is hereby granted, free of charge, to any person obtaining a |
4 | * Permission is hereby granted, free of charge, to any person obtaining a |
5 | * copy of this software and associated documentation files (the "Software"), |
5 | * copy of this software and associated documentation files (the "Software"), |
6 | * to deal in the Software without restriction, including without limitation |
6 | * to deal in the Software without restriction, including without limitation |
7 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, |
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 |
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: |
9 | * Software is furnished to do so, subject to the following conditions: |
10 | * |
10 | * |
11 | * The above copyright notice and this permission notice (including the next |
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 |
12 | * paragraph) shall be included in all copies or substantial portions of the |
13 | * Software. |
13 | * Software. |
14 | * |
14 | * |
15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
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, |
16 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
17 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL |
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 |
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 |
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 |
20 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS |
21 | * IN THE SOFTWARE. |
21 | * IN THE SOFTWARE. |
22 | * |
22 | * |
23 | * Authors: |
23 | * Authors: |
24 | * Eric Anholt |
24 | * Eric Anholt |
25 | * Chris Wilson |
25 | * Chris Wilson |
26 | * |
26 | * |
27 | */ |
27 | */ |
28 | 28 | ||
29 | #include |
29 | #include |
30 | #include |
30 | #include |
31 | #include "i915_drv.h" |
31 | #include "i915_drv.h" |
32 | #include "i915_trace.h" |
32 | #include "i915_trace.h" |
33 | #include "intel_drv.h" |
33 | #include "intel_drv.h" |
34 | #include |
34 | #include |
35 | #include |
35 | #include |
36 | 36 | ||
37 | #define __EXEC_OBJECT_HAS_PIN (1<<31) |
37 | #define __EXEC_OBJECT_HAS_PIN (1<<31) |
38 | #define __EXEC_OBJECT_HAS_FENCE (1<<30) |
38 | #define __EXEC_OBJECT_HAS_FENCE (1<<30) |
39 | #define __EXEC_OBJECT_NEEDS_MAP (1<<29) |
39 | #define __EXEC_OBJECT_NEEDS_MAP (1<<29) |
40 | #define __EXEC_OBJECT_NEEDS_BIAS (1<<28) |
40 | #define __EXEC_OBJECT_NEEDS_BIAS (1<<28) |
41 | 41 | ||
42 | #define BATCH_OFFSET_BIAS (256*1024) |
42 | #define BATCH_OFFSET_BIAS (256*1024) |
43 | 43 | ||
44 | struct eb_vmas { |
44 | struct eb_vmas { |
45 | struct list_head vmas; |
45 | struct list_head vmas; |
46 | int and; |
46 | int and; |
47 | union { |
47 | union { |
48 | struct i915_vma *lut[0]; |
48 | struct i915_vma *lut[0]; |
49 | struct hlist_head buckets[0]; |
49 | struct hlist_head buckets[0]; |
50 | }; |
50 | }; |
51 | }; |
51 | }; |
52 | 52 | ||
53 | static struct eb_vmas * |
53 | static struct eb_vmas * |
54 | eb_create(struct drm_i915_gem_execbuffer2 *args) |
54 | eb_create(struct drm_i915_gem_execbuffer2 *args) |
55 | { |
55 | { |
56 | struct eb_vmas *eb = NULL; |
56 | struct eb_vmas *eb = NULL; |
57 | 57 | ||
58 | if (args->flags & I915_EXEC_HANDLE_LUT) { |
58 | if (args->flags & I915_EXEC_HANDLE_LUT) { |
59 | unsigned size = args->buffer_count; |
59 | unsigned size = args->buffer_count; |
60 | size *= sizeof(struct i915_vma *); |
60 | size *= sizeof(struct i915_vma *); |
61 | size += sizeof(struct eb_vmas); |
61 | size += sizeof(struct eb_vmas); |
62 | eb = kmalloc(size, GFP_TEMPORARY | __GFP_NOWARN | __GFP_NORETRY); |
62 | eb = kmalloc(size, GFP_TEMPORARY | __GFP_NOWARN | __GFP_NORETRY); |
63 | } |
63 | } |
64 | 64 | ||
65 | if (eb == NULL) { |
65 | if (eb == NULL) { |
66 | unsigned size = args->buffer_count; |
66 | unsigned size = args->buffer_count; |
67 | unsigned count = PAGE_SIZE / sizeof(struct hlist_head) / 2; |
67 | unsigned count = PAGE_SIZE / sizeof(struct hlist_head) / 2; |
68 | BUILD_BUG_ON_NOT_POWER_OF_2(PAGE_SIZE / sizeof(struct hlist_head)); |
68 | BUILD_BUG_ON_NOT_POWER_OF_2(PAGE_SIZE / sizeof(struct hlist_head)); |
69 | while (count > 2*size) |
69 | while (count > 2*size) |
70 | count >>= 1; |
70 | count >>= 1; |
71 | eb = kzalloc(count*sizeof(struct hlist_head) + |
71 | eb = kzalloc(count*sizeof(struct hlist_head) + |
72 | sizeof(struct eb_vmas), |
72 | sizeof(struct eb_vmas), |
73 | GFP_TEMPORARY); |
73 | GFP_TEMPORARY); |
74 | if (eb == NULL) |
74 | if (eb == NULL) |
75 | return eb; |
75 | return eb; |
76 | 76 | ||
77 | eb->and = count - 1; |
77 | eb->and = count - 1; |
78 | } else |
78 | } else |
79 | eb->and = -args->buffer_count; |
79 | eb->and = -args->buffer_count; |
80 | 80 | ||
81 | INIT_LIST_HEAD(&eb->vmas); |
81 | INIT_LIST_HEAD(&eb->vmas); |
82 | return eb; |
82 | return eb; |
83 | } |
83 | } |
84 | 84 | ||
85 | static void |
85 | static void |
86 | eb_reset(struct eb_vmas *eb) |
86 | eb_reset(struct eb_vmas *eb) |
87 | { |
87 | { |
88 | if (eb->and >= 0) |
88 | if (eb->and >= 0) |
89 | memset(eb->buckets, 0, (eb->and+1)*sizeof(struct hlist_head)); |
89 | memset(eb->buckets, 0, (eb->and+1)*sizeof(struct hlist_head)); |
90 | } |
90 | } |
91 | 91 | ||
92 | static int |
92 | static int |
93 | eb_lookup_vmas(struct eb_vmas *eb, |
93 | eb_lookup_vmas(struct eb_vmas *eb, |
94 | struct drm_i915_gem_exec_object2 *exec, |
94 | struct drm_i915_gem_exec_object2 *exec, |
95 | const struct drm_i915_gem_execbuffer2 *args, |
95 | const struct drm_i915_gem_execbuffer2 *args, |
96 | struct i915_address_space *vm, |
96 | struct i915_address_space *vm, |
97 | struct drm_file *file) |
97 | struct drm_file *file) |
98 | { |
98 | { |
99 | struct drm_i915_gem_object *obj; |
99 | struct drm_i915_gem_object *obj; |
100 | struct list_head objects; |
100 | struct list_head objects; |
101 | int i, ret; |
101 | int i, ret; |
102 | 102 | ||
103 | INIT_LIST_HEAD(&objects); |
103 | INIT_LIST_HEAD(&objects); |
104 | spin_lock(&file->table_lock); |
104 | spin_lock(&file->table_lock); |
105 | /* Grab a reference to the object and release the lock so we can lookup |
105 | /* Grab a reference to the object and release the lock so we can lookup |
106 | * or create the VMA without using GFP_ATOMIC */ |
106 | * or create the VMA without using GFP_ATOMIC */ |
107 | for (i = 0; i < args->buffer_count; i++) { |
107 | for (i = 0; i < args->buffer_count; i++) { |
108 | obj = to_intel_bo(idr_find(&file->object_idr, exec[i].handle)); |
108 | obj = to_intel_bo(idr_find(&file->object_idr, exec[i].handle)); |
109 | if (obj == NULL) { |
109 | if (obj == NULL) { |
110 | spin_unlock(&file->table_lock); |
110 | spin_unlock(&file->table_lock); |
111 | DRM_DEBUG("Invalid object handle %d at index %d\n", |
111 | DRM_DEBUG("Invalid object handle %d at index %d\n", |
112 | exec[i].handle, i); |
112 | exec[i].handle, i); |
113 | ret = -ENOENT; |
113 | ret = -ENOENT; |
114 | goto err; |
114 | goto err; |
115 | } |
115 | } |
116 | 116 | ||
117 | if (!list_empty(&obj->obj_exec_link)) { |
117 | if (!list_empty(&obj->obj_exec_link)) { |
118 | spin_unlock(&file->table_lock); |
118 | spin_unlock(&file->table_lock); |
119 | DRM_DEBUG("Object %p [handle %d, index %d] appears more than once in object list\n", |
119 | DRM_DEBUG("Object %p [handle %d, index %d] appears more than once in object list\n", |
120 | obj, exec[i].handle, i); |
120 | obj, exec[i].handle, i); |
121 | ret = -EINVAL; |
121 | ret = -EINVAL; |
122 | goto err; |
122 | goto err; |
123 | } |
123 | } |
124 | 124 | ||
125 | drm_gem_object_reference(&obj->base); |
125 | drm_gem_object_reference(&obj->base); |
126 | list_add_tail(&obj->obj_exec_link, &objects); |
126 | list_add_tail(&obj->obj_exec_link, &objects); |
127 | } |
127 | } |
128 | spin_unlock(&file->table_lock); |
128 | spin_unlock(&file->table_lock); |
129 | 129 | ||
130 | i = 0; |
130 | i = 0; |
131 | while (!list_empty(&objects)) { |
131 | while (!list_empty(&objects)) { |
132 | struct i915_vma *vma; |
132 | struct i915_vma *vma; |
133 | 133 | ||
134 | obj = list_first_entry(&objects, |
134 | obj = list_first_entry(&objects, |
135 | struct drm_i915_gem_object, |
135 | struct drm_i915_gem_object, |
136 | obj_exec_link); |
136 | obj_exec_link); |
137 | 137 | ||
138 | /* |
138 | /* |
139 | * NOTE: We can leak any vmas created here when something fails |
139 | * NOTE: We can leak any vmas created here when something fails |
140 | * later on. But that's no issue since vma_unbind can deal with |
140 | * later on. But that's no issue since vma_unbind can deal with |
141 | * vmas which are not actually bound. And since only |
141 | * vmas which are not actually bound. And since only |
142 | * lookup_or_create exists as an interface to get at the vma |
142 | * lookup_or_create exists as an interface to get at the vma |
143 | * from the (obj, vm) we don't run the risk of creating |
143 | * from the (obj, vm) we don't run the risk of creating |
144 | * duplicated vmas for the same vm. |
144 | * duplicated vmas for the same vm. |
145 | */ |
145 | */ |
146 | vma = i915_gem_obj_lookup_or_create_vma(obj, vm); |
146 | vma = i915_gem_obj_lookup_or_create_vma(obj, vm); |
147 | if (IS_ERR(vma)) { |
147 | if (IS_ERR(vma)) { |
148 | DRM_DEBUG("Failed to lookup VMA\n"); |
148 | DRM_DEBUG("Failed to lookup VMA\n"); |
149 | ret = PTR_ERR(vma); |
149 | ret = PTR_ERR(vma); |
150 | goto err; |
150 | goto err; |
151 | } |
151 | } |
152 | 152 | ||
153 | /* Transfer ownership from the objects list to the vmas list. */ |
153 | /* Transfer ownership from the objects list to the vmas list. */ |
154 | list_add_tail(&vma->exec_list, &eb->vmas); |
154 | list_add_tail(&vma->exec_list, &eb->vmas); |
155 | list_del_init(&obj->obj_exec_link); |
155 | list_del_init(&obj->obj_exec_link); |
156 | 156 | ||
157 | vma->exec_entry = &exec[i]; |
157 | vma->exec_entry = &exec[i]; |
158 | if (eb->and < 0) { |
158 | if (eb->and < 0) { |
159 | eb->lut[i] = vma; |
159 | eb->lut[i] = vma; |
160 | } else { |
160 | } else { |
161 | uint32_t handle = args->flags & I915_EXEC_HANDLE_LUT ? i : exec[i].handle; |
161 | uint32_t handle = args->flags & I915_EXEC_HANDLE_LUT ? i : exec[i].handle; |
162 | vma->exec_handle = handle; |
162 | vma->exec_handle = handle; |
163 | hlist_add_head(&vma->exec_node, |
163 | hlist_add_head(&vma->exec_node, |
164 | &eb->buckets[handle & eb->and]); |
164 | &eb->buckets[handle & eb->and]); |
165 | } |
165 | } |
166 | ++i; |
166 | ++i; |
167 | } |
167 | } |
168 | 168 | ||
169 | return 0; |
169 | return 0; |
170 | 170 | ||
171 | 171 | ||
172 | err: |
172 | err: |
173 | while (!list_empty(&objects)) { |
173 | while (!list_empty(&objects)) { |
174 | obj = list_first_entry(&objects, |
174 | obj = list_first_entry(&objects, |
175 | struct drm_i915_gem_object, |
175 | struct drm_i915_gem_object, |
176 | obj_exec_link); |
176 | obj_exec_link); |
177 | list_del_init(&obj->obj_exec_link); |
177 | list_del_init(&obj->obj_exec_link); |
178 | drm_gem_object_unreference(&obj->base); |
178 | drm_gem_object_unreference(&obj->base); |
179 | } |
179 | } |
180 | /* |
180 | /* |
181 | * Objects already transfered to the vmas list will be unreferenced by |
181 | * Objects already transfered to the vmas list will be unreferenced by |
182 | * eb_destroy. |
182 | * eb_destroy. |
183 | */ |
183 | */ |
184 | 184 | ||
185 | return ret; |
185 | return ret; |
186 | } |
186 | } |
187 | 187 | ||
188 | static struct i915_vma *eb_get_vma(struct eb_vmas *eb, unsigned long handle) |
188 | static struct i915_vma *eb_get_vma(struct eb_vmas *eb, unsigned long handle) |
189 | { |
189 | { |
190 | if (eb->and < 0) { |
190 | if (eb->and < 0) { |
191 | if (handle >= -eb->and) |
191 | if (handle >= -eb->and) |
192 | return NULL; |
192 | return NULL; |
193 | return eb->lut[handle]; |
193 | return eb->lut[handle]; |
194 | } else { |
194 | } else { |
195 | struct hlist_head *head; |
195 | struct hlist_head *head; |
196 | struct hlist_node *node; |
- | |
197 | - | ||
198 | head = &eb->buckets[handle & eb->and]; |
- | |
199 | hlist_for_each(node, head) { |
- | |
200 | struct i915_vma *vma; |
196 | struct i915_vma *vma; |
- | 197 | ||
201 | 198 | head = &eb->buckets[handle & eb->and]; |
|
202 | vma = hlist_entry(node, struct i915_vma, exec_node); |
199 | hlist_for_each_entry(vma, head, exec_node) { |
203 | if (vma->exec_handle == handle) |
200 | if (vma->exec_handle == handle) |
204 | return vma; |
201 | return vma; |
205 | } |
202 | } |
206 | return NULL; |
203 | return NULL; |
207 | } |
204 | } |
208 | } |
205 | } |
209 | 206 | ||
210 | static void |
207 | static void |
211 | i915_gem_execbuffer_unreserve_vma(struct i915_vma *vma) |
208 | i915_gem_execbuffer_unreserve_vma(struct i915_vma *vma) |
212 | { |
209 | { |
213 | struct drm_i915_gem_exec_object2 *entry; |
210 | struct drm_i915_gem_exec_object2 *entry; |
214 | struct drm_i915_gem_object *obj = vma->obj; |
211 | struct drm_i915_gem_object *obj = vma->obj; |
215 | 212 | ||
216 | if (!drm_mm_node_allocated(&vma->node)) |
213 | if (!drm_mm_node_allocated(&vma->node)) |
217 | return; |
214 | return; |
218 | 215 | ||
219 | entry = vma->exec_entry; |
216 | entry = vma->exec_entry; |
220 | 217 | ||
221 | if (entry->flags & __EXEC_OBJECT_HAS_FENCE) |
218 | if (entry->flags & __EXEC_OBJECT_HAS_FENCE) |
222 | i915_gem_object_unpin_fence(obj); |
219 | i915_gem_object_unpin_fence(obj); |
223 | 220 | ||
224 | if (entry->flags & __EXEC_OBJECT_HAS_PIN) |
221 | if (entry->flags & __EXEC_OBJECT_HAS_PIN) |
225 | vma->pin_count--; |
222 | vma->pin_count--; |
226 | 223 | ||
227 | entry->flags &= ~(__EXEC_OBJECT_HAS_FENCE | __EXEC_OBJECT_HAS_PIN); |
224 | entry->flags &= ~(__EXEC_OBJECT_HAS_FENCE | __EXEC_OBJECT_HAS_PIN); |
228 | } |
225 | } |
229 | 226 | ||
230 | static void eb_destroy(struct eb_vmas *eb) |
227 | static void eb_destroy(struct eb_vmas *eb) |
231 | { |
228 | { |
232 | while (!list_empty(&eb->vmas)) { |
229 | while (!list_empty(&eb->vmas)) { |
233 | struct i915_vma *vma; |
230 | struct i915_vma *vma; |
234 | 231 | ||
235 | vma = list_first_entry(&eb->vmas, |
232 | vma = list_first_entry(&eb->vmas, |
236 | struct i915_vma, |
233 | struct i915_vma, |
237 | exec_list); |
234 | exec_list); |
238 | list_del_init(&vma->exec_list); |
235 | list_del_init(&vma->exec_list); |
239 | i915_gem_execbuffer_unreserve_vma(vma); |
236 | i915_gem_execbuffer_unreserve_vma(vma); |
240 | drm_gem_object_unreference(&vma->obj->base); |
237 | drm_gem_object_unreference(&vma->obj->base); |
241 | } |
238 | } |
242 | kfree(eb); |
239 | kfree(eb); |
243 | } |
240 | } |
244 | 241 | ||
245 | static inline int use_cpu_reloc(struct drm_i915_gem_object *obj) |
242 | static inline int use_cpu_reloc(struct drm_i915_gem_object *obj) |
246 | { |
243 | { |
247 | return (HAS_LLC(obj->base.dev) || |
244 | return (HAS_LLC(obj->base.dev) || |
248 | obj->base.write_domain == I915_GEM_DOMAIN_CPU || |
245 | obj->base.write_domain == I915_GEM_DOMAIN_CPU || |
249 | obj->cache_level != I915_CACHE_NONE); |
246 | obj->cache_level != I915_CACHE_NONE); |
250 | } |
247 | } |
251 | 248 | ||
252 | /* Used to convert any address to canonical form. |
249 | /* Used to convert any address to canonical form. |
253 | * Starting from gen8, some commands (e.g. STATE_BASE_ADDRESS, |
250 | * Starting from gen8, some commands (e.g. STATE_BASE_ADDRESS, |
254 | * MI_LOAD_REGISTER_MEM and others, see Broadwell PRM Vol2a) require the |
251 | * MI_LOAD_REGISTER_MEM and others, see Broadwell PRM Vol2a) require the |
255 | * addresses to be in a canonical form: |
252 | * addresses to be in a canonical form: |
256 | * "GraphicsAddress[63:48] are ignored by the HW and assumed to be in correct |
253 | * "GraphicsAddress[63:48] are ignored by the HW and assumed to be in correct |
257 | * canonical form [63:48] == [47]." |
254 | * canonical form [63:48] == [47]." |
258 | */ |
255 | */ |
259 | #define GEN8_HIGH_ADDRESS_BIT 47 |
256 | #define GEN8_HIGH_ADDRESS_BIT 47 |
260 | static inline uint64_t gen8_canonical_addr(uint64_t address) |
257 | static inline uint64_t gen8_canonical_addr(uint64_t address) |
261 | { |
258 | { |
262 | return sign_extend64(address, GEN8_HIGH_ADDRESS_BIT); |
259 | return sign_extend64(address, GEN8_HIGH_ADDRESS_BIT); |
263 | } |
260 | } |
264 | 261 | ||
265 | static inline uint64_t gen8_noncanonical_addr(uint64_t address) |
262 | static inline uint64_t gen8_noncanonical_addr(uint64_t address) |
266 | { |
263 | { |
267 | return address & ((1ULL << (GEN8_HIGH_ADDRESS_BIT + 1)) - 1); |
264 | return address & ((1ULL << (GEN8_HIGH_ADDRESS_BIT + 1)) - 1); |
268 | } |
265 | } |
269 | 266 | ||
270 | static inline uint64_t |
267 | static inline uint64_t |
271 | relocation_target(struct drm_i915_gem_relocation_entry *reloc, |
268 | relocation_target(struct drm_i915_gem_relocation_entry *reloc, |
272 | uint64_t target_offset) |
269 | uint64_t target_offset) |
273 | { |
270 | { |
274 | return gen8_canonical_addr((int)reloc->delta + target_offset); |
271 | return gen8_canonical_addr((int)reloc->delta + target_offset); |
275 | } |
272 | } |
276 | 273 | ||
277 | static int |
274 | static int |
278 | relocate_entry_cpu(struct drm_i915_gem_object *obj, |
275 | relocate_entry_cpu(struct drm_i915_gem_object *obj, |
279 | struct drm_i915_gem_relocation_entry *reloc, |
276 | struct drm_i915_gem_relocation_entry *reloc, |
280 | uint64_t target_offset) |
277 | uint64_t target_offset) |
281 | { |
278 | { |
282 | struct drm_device *dev = obj->base.dev; |
279 | struct drm_device *dev = obj->base.dev; |
283 | uint32_t page_offset = offset_in_page(reloc->offset); |
280 | uint32_t page_offset = offset_in_page(reloc->offset); |
284 | uint64_t delta = relocation_target(reloc, target_offset); |
281 | uint64_t delta = relocation_target(reloc, target_offset); |
285 | char *vaddr; |
282 | char *vaddr; |
286 | int ret; |
283 | int ret; |
287 | 284 | ||
288 | ret = i915_gem_object_set_to_cpu_domain(obj, true); |
285 | ret = i915_gem_object_set_to_cpu_domain(obj, true); |
289 | if (ret) |
286 | if (ret) |
290 | return ret; |
287 | return ret; |
291 | 288 | ||
292 | vaddr = kmap_atomic(i915_gem_object_get_dirty_page(obj, |
289 | vaddr = kmap_atomic(i915_gem_object_get_dirty_page(obj, |
293 | reloc->offset >> PAGE_SHIFT)); |
290 | reloc->offset >> PAGE_SHIFT)); |
294 | *(uint32_t *)(vaddr + page_offset) = lower_32_bits(delta); |
291 | *(uint32_t *)(vaddr + page_offset) = lower_32_bits(delta); |
295 | 292 | ||
296 | if (INTEL_INFO(dev)->gen >= 8) { |
293 | if (INTEL_INFO(dev)->gen >= 8) { |
297 | page_offset = offset_in_page(page_offset + sizeof(uint32_t)); |
294 | page_offset = offset_in_page(page_offset + sizeof(uint32_t)); |
298 | 295 | ||
299 | if (page_offset == 0) { |
296 | if (page_offset == 0) { |
300 | kunmap_atomic(vaddr); |
297 | kunmap_atomic(vaddr); |
301 | vaddr = kmap_atomic(i915_gem_object_get_dirty_page(obj, |
298 | vaddr = kmap_atomic(i915_gem_object_get_dirty_page(obj, |
302 | (reloc->offset + sizeof(uint32_t)) >> PAGE_SHIFT)); |
299 | (reloc->offset + sizeof(uint32_t)) >> PAGE_SHIFT)); |
303 | } |
300 | } |
304 | 301 | ||
305 | *(uint32_t *)(vaddr + page_offset) = upper_32_bits(delta); |
302 | *(uint32_t *)(vaddr + page_offset) = upper_32_bits(delta); |
306 | } |
303 | } |
307 | 304 | ||
308 | kunmap_atomic(vaddr); |
305 | kunmap_atomic(vaddr); |
309 | 306 | ||
310 | return 0; |
307 | return 0; |
311 | } |
308 | } |
312 | 309 | ||
313 | static int |
310 | static int |
314 | relocate_entry_gtt(struct drm_i915_gem_object *obj, |
311 | relocate_entry_gtt(struct drm_i915_gem_object *obj, |
315 | struct drm_i915_gem_relocation_entry *reloc, |
312 | struct drm_i915_gem_relocation_entry *reloc, |
316 | uint64_t target_offset) |
313 | uint64_t target_offset) |
317 | { |
314 | { |
318 | struct drm_device *dev = obj->base.dev; |
315 | struct drm_device *dev = obj->base.dev; |
319 | struct drm_i915_private *dev_priv = dev->dev_private; |
316 | struct drm_i915_private *dev_priv = dev->dev_private; |
320 | uint64_t delta = relocation_target(reloc, target_offset); |
317 | uint64_t delta = relocation_target(reloc, target_offset); |
321 | uint64_t offset; |
318 | uint64_t offset; |
322 | void __iomem *reloc_page; |
319 | void __iomem *reloc_page; |
323 | int ret; |
320 | int ret; |
324 | 321 | ||
325 | ret = i915_gem_object_set_to_gtt_domain(obj, true); |
322 | ret = i915_gem_object_set_to_gtt_domain(obj, true); |
326 | if (ret) |
323 | if (ret) |
327 | return ret; |
324 | return ret; |
328 | 325 | ||
329 | ret = i915_gem_object_put_fence(obj); |
326 | ret = i915_gem_object_put_fence(obj); |
330 | if (ret) |
327 | if (ret) |
331 | return ret; |
328 | return ret; |
332 | 329 | ||
333 | /* Map the page containing the relocation we're going to perform. */ |
330 | /* Map the page containing the relocation we're going to perform. */ |
334 | offset = i915_gem_obj_ggtt_offset(obj); |
331 | offset = i915_gem_obj_ggtt_offset(obj); |
335 | offset += reloc->offset; |
332 | offset += reloc->offset; |
336 | MapPage(dev_priv->gtt.mappable,dev_priv->gtt.mappable_base + |
333 | reloc_page = io_mapping_map_atomic_wc(dev_priv->gtt.mappable, |
337 | (offset & PAGE_MASK), PG_SW); |
334 | offset & PAGE_MASK); |
338 | reloc_page = dev_priv->gtt.mappable; |
- | |
339 | iowrite32(lower_32_bits(delta), reloc_page + offset_in_page(offset)); |
335 | iowrite32(lower_32_bits(delta), reloc_page + offset_in_page(offset)); |
- | 336 | ||
- | 337 | if (INTEL_INFO(dev)->gen >= 8) { |
|
- | 338 | offset += sizeof(uint32_t); |
|
- | 339 | ||
340 | 340 | if (offset_in_page(offset) == 0) { |
|
- | 341 | io_mapping_unmap_atomic(reloc_page); |
|
- | 342 | reloc_page = |
|
- | 343 | io_mapping_map_atomic_wc(dev_priv->gtt.mappable, |
|
- | 344 | offset); |
|
- | 345 | } |
|
- | 346 | ||
- | 347 | iowrite32(upper_32_bits(delta), |
|
- | 348 | reloc_page + offset_in_page(offset)); |
|
- | 349 | } |
|
- | 350 | ||
341 | // io_mapping_unmap_atomic(reloc_page); |
351 | io_mapping_unmap_atomic(reloc_page); |
342 | 352 | ||
343 | return 0; |
353 | return 0; |
344 | } |
354 | } |
345 | 355 | ||
346 | static void |
356 | static void |
347 | clflush_write32(void *addr, uint32_t value) |
357 | clflush_write32(void *addr, uint32_t value) |
348 | { |
358 | { |
349 | /* This is not a fast path, so KISS. */ |
359 | /* This is not a fast path, so KISS. */ |
350 | drm_clflush_virt_range(addr, sizeof(uint32_t)); |
360 | drm_clflush_virt_range(addr, sizeof(uint32_t)); |
351 | *(uint32_t *)addr = value; |
361 | *(uint32_t *)addr = value; |
352 | drm_clflush_virt_range(addr, sizeof(uint32_t)); |
362 | drm_clflush_virt_range(addr, sizeof(uint32_t)); |
353 | } |
363 | } |
354 | 364 | ||
355 | static int |
365 | static int |
356 | relocate_entry_clflush(struct drm_i915_gem_object *obj, |
366 | relocate_entry_clflush(struct drm_i915_gem_object *obj, |
357 | struct drm_i915_gem_relocation_entry *reloc, |
367 | struct drm_i915_gem_relocation_entry *reloc, |
358 | uint64_t target_offset) |
368 | uint64_t target_offset) |
359 | { |
369 | { |
360 | struct drm_device *dev = obj->base.dev; |
370 | struct drm_device *dev = obj->base.dev; |
361 | uint32_t page_offset = offset_in_page(reloc->offset); |
371 | uint32_t page_offset = offset_in_page(reloc->offset); |
362 | uint64_t delta = relocation_target(reloc, target_offset); |
372 | uint64_t delta = relocation_target(reloc, target_offset); |
363 | char *vaddr; |
373 | char *vaddr; |
364 | int ret; |
374 | int ret; |
365 | 375 | ||
366 | ret = i915_gem_object_set_to_gtt_domain(obj, true); |
376 | ret = i915_gem_object_set_to_gtt_domain(obj, true); |
367 | if (ret) |
377 | if (ret) |
368 | return ret; |
378 | return ret; |
369 | 379 | ||
370 | vaddr = kmap_atomic(i915_gem_object_get_dirty_page(obj, |
380 | vaddr = kmap_atomic(i915_gem_object_get_dirty_page(obj, |
371 | reloc->offset >> PAGE_SHIFT)); |
381 | reloc->offset >> PAGE_SHIFT)); |
372 | clflush_write32(vaddr + page_offset, lower_32_bits(delta)); |
382 | clflush_write32(vaddr + page_offset, lower_32_bits(delta)); |
373 | 383 | ||
374 | if (INTEL_INFO(dev)->gen >= 8) { |
384 | if (INTEL_INFO(dev)->gen >= 8) { |
375 | page_offset = offset_in_page(page_offset + sizeof(uint32_t)); |
385 | page_offset = offset_in_page(page_offset + sizeof(uint32_t)); |
376 | 386 | ||
377 | if (page_offset == 0) { |
387 | if (page_offset == 0) { |
378 | kunmap_atomic(vaddr); |
388 | kunmap_atomic(vaddr); |
379 | vaddr = kmap_atomic(i915_gem_object_get_dirty_page(obj, |
389 | vaddr = kmap_atomic(i915_gem_object_get_dirty_page(obj, |
380 | (reloc->offset + sizeof(uint32_t)) >> PAGE_SHIFT)); |
390 | (reloc->offset + sizeof(uint32_t)) >> PAGE_SHIFT)); |
381 | } |
391 | } |
382 | 392 | ||
383 | clflush_write32(vaddr + page_offset, upper_32_bits(delta)); |
393 | clflush_write32(vaddr + page_offset, upper_32_bits(delta)); |
384 | } |
394 | } |
385 | 395 | ||
386 | kunmap_atomic(vaddr); |
396 | kunmap_atomic(vaddr); |
387 | 397 | ||
388 | return 0; |
398 | return 0; |
389 | } |
399 | } |
390 | 400 | ||
391 | static int |
401 | static int |
392 | i915_gem_execbuffer_relocate_entry(struct drm_i915_gem_object *obj, |
402 | i915_gem_execbuffer_relocate_entry(struct drm_i915_gem_object *obj, |
393 | struct eb_vmas *eb, |
403 | struct eb_vmas *eb, |
394 | struct drm_i915_gem_relocation_entry *reloc) |
404 | struct drm_i915_gem_relocation_entry *reloc) |
395 | { |
405 | { |
396 | struct drm_device *dev = obj->base.dev; |
406 | struct drm_device *dev = obj->base.dev; |
397 | struct drm_gem_object *target_obj; |
407 | struct drm_gem_object *target_obj; |
398 | struct drm_i915_gem_object *target_i915_obj; |
408 | struct drm_i915_gem_object *target_i915_obj; |
399 | struct i915_vma *target_vma; |
409 | struct i915_vma *target_vma; |
400 | uint64_t target_offset; |
410 | uint64_t target_offset; |
401 | int ret; |
411 | int ret; |
402 | 412 | ||
403 | /* we've already hold a reference to all valid objects */ |
413 | /* we've already hold a reference to all valid objects */ |
404 | target_vma = eb_get_vma(eb, reloc->target_handle); |
414 | target_vma = eb_get_vma(eb, reloc->target_handle); |
405 | if (unlikely(target_vma == NULL)) |
415 | if (unlikely(target_vma == NULL)) |
406 | return -ENOENT; |
416 | return -ENOENT; |
407 | target_i915_obj = target_vma->obj; |
417 | target_i915_obj = target_vma->obj; |
408 | target_obj = &target_vma->obj->base; |
418 | target_obj = &target_vma->obj->base; |
409 | 419 | ||
410 | target_offset = gen8_canonical_addr(target_vma->node.start); |
420 | target_offset = gen8_canonical_addr(target_vma->node.start); |
411 | 421 | ||
412 | /* Sandybridge PPGTT errata: We need a global gtt mapping for MI and |
422 | /* Sandybridge PPGTT errata: We need a global gtt mapping for MI and |
413 | * pipe_control writes because the gpu doesn't properly redirect them |
423 | * pipe_control writes because the gpu doesn't properly redirect them |
414 | * through the ppgtt for non_secure batchbuffers. */ |
424 | * through the ppgtt for non_secure batchbuffers. */ |
415 | if (unlikely(IS_GEN6(dev) && |
425 | if (unlikely(IS_GEN6(dev) && |
416 | reloc->write_domain == I915_GEM_DOMAIN_INSTRUCTION)) { |
426 | reloc->write_domain == I915_GEM_DOMAIN_INSTRUCTION)) { |
417 | ret = i915_vma_bind(target_vma, target_i915_obj->cache_level, |
427 | ret = i915_vma_bind(target_vma, target_i915_obj->cache_level, |
418 | PIN_GLOBAL); |
428 | PIN_GLOBAL); |
419 | if (WARN_ONCE(ret, "Unexpected failure to bind target VMA!")) |
429 | if (WARN_ONCE(ret, "Unexpected failure to bind target VMA!")) |
420 | return ret; |
430 | return ret; |
421 | } |
431 | } |
422 | 432 | ||
423 | /* Validate that the target is in a valid r/w GPU domain */ |
433 | /* Validate that the target is in a valid r/w GPU domain */ |
424 | if (unlikely(reloc->write_domain & (reloc->write_domain - 1))) { |
434 | if (unlikely(reloc->write_domain & (reloc->write_domain - 1))) { |
425 | DRM_DEBUG("reloc with multiple write domains: " |
435 | DRM_DEBUG("reloc with multiple write domains: " |
426 | "obj %p target %d offset %d " |
436 | "obj %p target %d offset %d " |
427 | "read %08x write %08x", |
437 | "read %08x write %08x", |
428 | obj, reloc->target_handle, |
438 | obj, reloc->target_handle, |
429 | (int) reloc->offset, |
439 | (int) reloc->offset, |
430 | reloc->read_domains, |
440 | reloc->read_domains, |
431 | reloc->write_domain); |
441 | reloc->write_domain); |
432 | return -EINVAL; |
442 | return -EINVAL; |
433 | } |
443 | } |
434 | if (unlikely((reloc->write_domain | reloc->read_domains) |
444 | if (unlikely((reloc->write_domain | reloc->read_domains) |
435 | & ~I915_GEM_GPU_DOMAINS)) { |
445 | & ~I915_GEM_GPU_DOMAINS)) { |
436 | DRM_DEBUG("reloc with read/write non-GPU domains: " |
446 | DRM_DEBUG("reloc with read/write non-GPU domains: " |
437 | "obj %p target %d offset %d " |
447 | "obj %p target %d offset %d " |
438 | "read %08x write %08x", |
448 | "read %08x write %08x", |
439 | obj, reloc->target_handle, |
449 | obj, reloc->target_handle, |
440 | (int) reloc->offset, |
450 | (int) reloc->offset, |
441 | reloc->read_domains, |
451 | reloc->read_domains, |
442 | reloc->write_domain); |
452 | reloc->write_domain); |
443 | return -EINVAL; |
453 | return -EINVAL; |
444 | } |
454 | } |
445 | 455 | ||
446 | target_obj->pending_read_domains |= reloc->read_domains; |
456 | target_obj->pending_read_domains |= reloc->read_domains; |
447 | target_obj->pending_write_domain |= reloc->write_domain; |
457 | target_obj->pending_write_domain |= reloc->write_domain; |
448 | 458 | ||
449 | /* If the relocation already has the right value in it, no |
459 | /* If the relocation already has the right value in it, no |
450 | * more work needs to be done. |
460 | * more work needs to be done. |
451 | */ |
461 | */ |
452 | if (target_offset == reloc->presumed_offset) |
462 | if (target_offset == reloc->presumed_offset) |
453 | return 0; |
463 | return 0; |
454 | 464 | ||
455 | /* Check that the relocation address is valid... */ |
465 | /* Check that the relocation address is valid... */ |
456 | if (unlikely(reloc->offset > |
466 | if (unlikely(reloc->offset > |
457 | obj->base.size - (INTEL_INFO(dev)->gen >= 8 ? 8 : 4))) { |
467 | obj->base.size - (INTEL_INFO(dev)->gen >= 8 ? 8 : 4))) { |
458 | DRM_DEBUG("Relocation beyond object bounds: " |
468 | DRM_DEBUG("Relocation beyond object bounds: " |
459 | "obj %p target %d offset %d size %d.\n", |
469 | "obj %p target %d offset %d size %d.\n", |
460 | obj, reloc->target_handle, |
470 | obj, reloc->target_handle, |
461 | (int) reloc->offset, |
471 | (int) reloc->offset, |
462 | (int) obj->base.size); |
472 | (int) obj->base.size); |
463 | return -EINVAL; |
473 | return -EINVAL; |
464 | } |
474 | } |
465 | if (unlikely(reloc->offset & 3)) { |
475 | if (unlikely(reloc->offset & 3)) { |
466 | DRM_DEBUG("Relocation not 4-byte aligned: " |
476 | DRM_DEBUG("Relocation not 4-byte aligned: " |
467 | "obj %p target %d offset %d.\n", |
477 | "obj %p target %d offset %d.\n", |
468 | obj, reloc->target_handle, |
478 | obj, reloc->target_handle, |
469 | (int) reloc->offset); |
479 | (int) reloc->offset); |
470 | return -EINVAL; |
480 | return -EINVAL; |
471 | } |
481 | } |
472 | 482 | ||
473 | /* We can't wait for rendering with pagefaults disabled */ |
483 | /* We can't wait for rendering with pagefaults disabled */ |
474 | 484 | ||
475 | if (use_cpu_reloc(obj)) |
485 | if (use_cpu_reloc(obj)) |
476 | ret = relocate_entry_cpu(obj, reloc, target_offset); |
486 | ret = relocate_entry_cpu(obj, reloc, target_offset); |
477 | else if (obj->map_and_fenceable) |
487 | else if (obj->map_and_fenceable) |
478 | ret = relocate_entry_gtt(obj, reloc, target_offset); |
488 | ret = relocate_entry_gtt(obj, reloc, target_offset); |
479 | else if (1) |
489 | else if (1) |
480 | ret = relocate_entry_clflush(obj, reloc, target_offset); |
490 | ret = relocate_entry_clflush(obj, reloc, target_offset); |
481 | else { |
491 | else { |
482 | WARN_ONCE(1, "Impossible case in relocation handling\n"); |
492 | WARN_ONCE(1, "Impossible case in relocation handling\n"); |
483 | ret = -ENODEV; |
493 | ret = -ENODEV; |
484 | } |
494 | } |
485 | 495 | ||
486 | if (ret) |
496 | if (ret) |
487 | return ret; |
497 | return ret; |
488 | 498 | ||
489 | /* and update the user's relocation entry */ |
499 | /* and update the user's relocation entry */ |
490 | reloc->presumed_offset = target_offset; |
500 | reloc->presumed_offset = target_offset; |
491 | 501 | ||
492 | return 0; |
502 | return 0; |
493 | } |
503 | } |
494 | 504 | ||
495 | static int |
505 | static int |
496 | i915_gem_execbuffer_relocate_vma(struct i915_vma *vma, |
506 | i915_gem_execbuffer_relocate_vma(struct i915_vma *vma, |
497 | struct eb_vmas *eb) |
507 | struct eb_vmas *eb) |
498 | { |
508 | { |
499 | #define N_RELOC(x) ((x) / sizeof(struct drm_i915_gem_relocation_entry)) |
509 | #define N_RELOC(x) ((x) / sizeof(struct drm_i915_gem_relocation_entry)) |
500 | struct drm_i915_gem_relocation_entry stack_reloc[N_RELOC(64)]; |
510 | struct drm_i915_gem_relocation_entry stack_reloc[N_RELOC(64)]; |
501 | struct drm_i915_gem_relocation_entry __user *user_relocs; |
511 | struct drm_i915_gem_relocation_entry __user *user_relocs; |
502 | struct drm_i915_gem_exec_object2 *entry = vma->exec_entry; |
512 | struct drm_i915_gem_exec_object2 *entry = vma->exec_entry; |
503 | int remain, ret; |
513 | int remain, ret; |
504 | 514 | ||
505 | user_relocs = to_user_ptr(entry->relocs_ptr); |
515 | user_relocs = to_user_ptr(entry->relocs_ptr); |
506 | 516 | ||
507 | remain = entry->relocation_count; |
517 | remain = entry->relocation_count; |
508 | while (remain) { |
518 | while (remain) { |
509 | struct drm_i915_gem_relocation_entry *r = stack_reloc; |
519 | struct drm_i915_gem_relocation_entry *r = stack_reloc; |
510 | int count = remain; |
520 | int count = remain; |
511 | if (count > ARRAY_SIZE(stack_reloc)) |
521 | if (count > ARRAY_SIZE(stack_reloc)) |
512 | count = ARRAY_SIZE(stack_reloc); |
522 | count = ARRAY_SIZE(stack_reloc); |
513 | remain -= count; |
523 | remain -= count; |
514 | 524 | ||
- | 525 | if (__copy_from_user_inatomic(r, user_relocs, count*sizeof(r[0]))) |
|
515 | memcpy(r, user_relocs, count*sizeof(r[0])); |
526 | return -EFAULT; |
516 | 527 | ||
517 | do { |
528 | do { |
518 | u64 offset = r->presumed_offset; |
529 | u64 offset = r->presumed_offset; |
519 | 530 | ||
520 | ret = i915_gem_execbuffer_relocate_entry(vma->obj, eb, r); |
531 | ret = i915_gem_execbuffer_relocate_entry(vma->obj, eb, r); |
521 | if (ret) |
532 | if (ret) |
522 | return ret; |
533 | return ret; |
523 | 534 | ||
524 | if (r->presumed_offset != offset) |
- | |
525 | { |
535 | if (r->presumed_offset != offset && |
526 | memcpy(&user_relocs->presumed_offset, |
536 | __copy_to_user_inatomic(&user_relocs->presumed_offset, |
527 | &r->presumed_offset, |
537 | &r->presumed_offset, |
- | 538 | sizeof(r->presumed_offset))) { |
|
528 | sizeof(r->presumed_offset)); |
539 | return -EFAULT; |
529 | } |
540 | } |
530 | 541 | ||
531 | user_relocs++; |
542 | user_relocs++; |
532 | r++; |
543 | r++; |
533 | } while (--count); |
544 | } while (--count); |
534 | } |
545 | } |
535 | 546 | ||
536 | return 0; |
547 | return 0; |
537 | #undef N_RELOC |
548 | #undef N_RELOC |
538 | } |
549 | } |
539 | 550 | ||
540 | static int |
551 | static int |
541 | i915_gem_execbuffer_relocate_vma_slow(struct i915_vma *vma, |
552 | i915_gem_execbuffer_relocate_vma_slow(struct i915_vma *vma, |
542 | struct eb_vmas *eb, |
553 | struct eb_vmas *eb, |
543 | struct drm_i915_gem_relocation_entry *relocs) |
554 | struct drm_i915_gem_relocation_entry *relocs) |
544 | { |
555 | { |
545 | const struct drm_i915_gem_exec_object2 *entry = vma->exec_entry; |
556 | const struct drm_i915_gem_exec_object2 *entry = vma->exec_entry; |
546 | int i, ret; |
557 | int i, ret; |
547 | 558 | ||
548 | for (i = 0; i < entry->relocation_count; i++) { |
559 | for (i = 0; i < entry->relocation_count; i++) { |
549 | ret = i915_gem_execbuffer_relocate_entry(vma->obj, eb, &relocs[i]); |
560 | ret = i915_gem_execbuffer_relocate_entry(vma->obj, eb, &relocs[i]); |
550 | if (ret) |
561 | if (ret) |
551 | return ret; |
562 | return ret; |
552 | } |
563 | } |
553 | 564 | ||
554 | return 0; |
565 | return 0; |
555 | } |
566 | } |
556 | 567 | ||
557 | static int |
568 | static int |
558 | i915_gem_execbuffer_relocate(struct eb_vmas *eb) |
569 | i915_gem_execbuffer_relocate(struct eb_vmas *eb) |
559 | { |
570 | { |
560 | struct i915_vma *vma; |
571 | struct i915_vma *vma; |
561 | int ret = 0; |
572 | int ret = 0; |
562 | 573 | ||
563 | /* This is the fast path and we cannot handle a pagefault whilst |
574 | /* This is the fast path and we cannot handle a pagefault whilst |
564 | * holding the struct mutex lest the user pass in the relocations |
575 | * holding the struct mutex lest the user pass in the relocations |
565 | * contained within a mmaped bo. For in such a case we, the page |
576 | * contained within a mmaped bo. For in such a case we, the page |
566 | * fault handler would call i915_gem_fault() and we would try to |
577 | * fault handler would call i915_gem_fault() and we would try to |
567 | * acquire the struct mutex again. Obviously this is bad and so |
578 | * acquire the struct mutex again. Obviously this is bad and so |
568 | * lockdep complains vehemently. |
579 | * lockdep complains vehemently. |
569 | */ |
580 | */ |
570 | pagefault_disable(); |
581 | pagefault_disable(); |
571 | list_for_each_entry(vma, &eb->vmas, exec_list) { |
582 | list_for_each_entry(vma, &eb->vmas, exec_list) { |
572 | ret = i915_gem_execbuffer_relocate_vma(vma, eb); |
583 | ret = i915_gem_execbuffer_relocate_vma(vma, eb); |
573 | if (ret) |
584 | if (ret) |
574 | break; |
585 | break; |
575 | } |
586 | } |
576 | pagefault_enable(); |
587 | pagefault_enable(); |
577 | 588 | ||
578 | return ret; |
589 | return ret; |
579 | } |
590 | } |
580 | 591 | ||
581 | static bool only_mappable_for_reloc(unsigned int flags) |
592 | static bool only_mappable_for_reloc(unsigned int flags) |
582 | { |
593 | { |
583 | return (flags & (EXEC_OBJECT_NEEDS_FENCE | __EXEC_OBJECT_NEEDS_MAP)) == |
594 | return (flags & (EXEC_OBJECT_NEEDS_FENCE | __EXEC_OBJECT_NEEDS_MAP)) == |
584 | __EXEC_OBJECT_NEEDS_MAP; |
595 | __EXEC_OBJECT_NEEDS_MAP; |
585 | } |
596 | } |
586 | 597 | ||
587 | static int |
598 | static int |
588 | i915_gem_execbuffer_reserve_vma(struct i915_vma *vma, |
599 | i915_gem_execbuffer_reserve_vma(struct i915_vma *vma, |
589 | struct intel_engine_cs *ring, |
600 | struct intel_engine_cs *ring, |
590 | bool *need_reloc) |
601 | bool *need_reloc) |
591 | { |
602 | { |
592 | struct drm_i915_gem_object *obj = vma->obj; |
603 | struct drm_i915_gem_object *obj = vma->obj; |
593 | struct drm_i915_gem_exec_object2 *entry = vma->exec_entry; |
604 | struct drm_i915_gem_exec_object2 *entry = vma->exec_entry; |
594 | uint64_t flags; |
605 | uint64_t flags; |
595 | int ret; |
606 | int ret; |
596 | 607 | ||
597 | flags = PIN_USER; |
608 | flags = PIN_USER; |
598 | if (entry->flags & EXEC_OBJECT_NEEDS_GTT) |
609 | if (entry->flags & EXEC_OBJECT_NEEDS_GTT) |
599 | flags |= PIN_GLOBAL; |
610 | flags |= PIN_GLOBAL; |
600 | 611 | ||
601 | if (!drm_mm_node_allocated(&vma->node)) { |
612 | if (!drm_mm_node_allocated(&vma->node)) { |
602 | /* Wa32bitGeneralStateOffset & Wa32bitInstructionBaseOffset, |
613 | /* Wa32bitGeneralStateOffset & Wa32bitInstructionBaseOffset, |
603 | * limit address to the first 4GBs for unflagged objects. |
614 | * limit address to the first 4GBs for unflagged objects. |
604 | */ |
615 | */ |
605 | if ((entry->flags & EXEC_OBJECT_SUPPORTS_48B_ADDRESS) == 0) |
616 | if ((entry->flags & EXEC_OBJECT_SUPPORTS_48B_ADDRESS) == 0) |
606 | flags |= PIN_ZONE_4G; |
617 | flags |= PIN_ZONE_4G; |
607 | if (entry->flags & __EXEC_OBJECT_NEEDS_MAP) |
618 | if (entry->flags & __EXEC_OBJECT_NEEDS_MAP) |
608 | flags |= PIN_GLOBAL | PIN_MAPPABLE; |
619 | flags |= PIN_GLOBAL | PIN_MAPPABLE; |
609 | if (entry->flags & __EXEC_OBJECT_NEEDS_BIAS) |
620 | if (entry->flags & __EXEC_OBJECT_NEEDS_BIAS) |
610 | flags |= BATCH_OFFSET_BIAS | PIN_OFFSET_BIAS; |
621 | flags |= BATCH_OFFSET_BIAS | PIN_OFFSET_BIAS; |
611 | if (entry->flags & EXEC_OBJECT_PINNED) |
622 | if (entry->flags & EXEC_OBJECT_PINNED) |
612 | flags |= entry->offset | PIN_OFFSET_FIXED; |
623 | flags |= entry->offset | PIN_OFFSET_FIXED; |
613 | if ((flags & PIN_MAPPABLE) == 0) |
624 | if ((flags & PIN_MAPPABLE) == 0) |
614 | flags |= PIN_HIGH; |
625 | flags |= PIN_HIGH; |
615 | } |
626 | } |
616 | 627 | ||
617 | ret = i915_gem_object_pin(obj, vma->vm, entry->alignment, flags); |
628 | ret = i915_gem_object_pin(obj, vma->vm, entry->alignment, flags); |
618 | if ((ret == -ENOSPC || ret == -E2BIG) && |
629 | if ((ret == -ENOSPC || ret == -E2BIG) && |
619 | only_mappable_for_reloc(entry->flags)) |
630 | only_mappable_for_reloc(entry->flags)) |
620 | ret = i915_gem_object_pin(obj, vma->vm, |
631 | ret = i915_gem_object_pin(obj, vma->vm, |
621 | entry->alignment, |
632 | entry->alignment, |
622 | flags & ~PIN_MAPPABLE); |
633 | flags & ~PIN_MAPPABLE); |
623 | if (ret) |
634 | if (ret) |
624 | return ret; |
635 | return ret; |
625 | 636 | ||
626 | entry->flags |= __EXEC_OBJECT_HAS_PIN; |
637 | entry->flags |= __EXEC_OBJECT_HAS_PIN; |
627 | 638 | ||
628 | if (entry->flags & EXEC_OBJECT_NEEDS_FENCE) { |
639 | if (entry->flags & EXEC_OBJECT_NEEDS_FENCE) { |
629 | ret = i915_gem_object_get_fence(obj); |
640 | ret = i915_gem_object_get_fence(obj); |
630 | if (ret) |
641 | if (ret) |
631 | return ret; |
642 | return ret; |
632 | 643 | ||
633 | if (i915_gem_object_pin_fence(obj)) |
644 | if (i915_gem_object_pin_fence(obj)) |
634 | entry->flags |= __EXEC_OBJECT_HAS_FENCE; |
645 | entry->flags |= __EXEC_OBJECT_HAS_FENCE; |
635 | } |
646 | } |
636 | 647 | ||
637 | if (entry->offset != vma->node.start) { |
648 | if (entry->offset != vma->node.start) { |
638 | entry->offset = vma->node.start; |
649 | entry->offset = vma->node.start; |
639 | *need_reloc = true; |
650 | *need_reloc = true; |
640 | } |
651 | } |
641 | 652 | ||
642 | if (entry->flags & EXEC_OBJECT_WRITE) { |
653 | if (entry->flags & EXEC_OBJECT_WRITE) { |
643 | obj->base.pending_read_domains = I915_GEM_DOMAIN_RENDER; |
654 | obj->base.pending_read_domains = I915_GEM_DOMAIN_RENDER; |
644 | obj->base.pending_write_domain = I915_GEM_DOMAIN_RENDER; |
655 | obj->base.pending_write_domain = I915_GEM_DOMAIN_RENDER; |
645 | } |
656 | } |
646 | 657 | ||
647 | return 0; |
658 | return 0; |
648 | } |
659 | } |
649 | 660 | ||
650 | static bool |
661 | static bool |
651 | need_reloc_mappable(struct i915_vma *vma) |
662 | need_reloc_mappable(struct i915_vma *vma) |
652 | { |
663 | { |
653 | struct drm_i915_gem_exec_object2 *entry = vma->exec_entry; |
664 | struct drm_i915_gem_exec_object2 *entry = vma->exec_entry; |
654 | 665 | ||
655 | if (entry->relocation_count == 0) |
666 | if (entry->relocation_count == 0) |
656 | return false; |
667 | return false; |
657 | 668 | ||
658 | if (!i915_is_ggtt(vma->vm)) |
669 | if (!vma->is_ggtt) |
659 | return false; |
670 | return false; |
660 | 671 | ||
661 | /* See also use_cpu_reloc() */ |
672 | /* See also use_cpu_reloc() */ |
662 | if (HAS_LLC(vma->obj->base.dev)) |
673 | if (HAS_LLC(vma->obj->base.dev)) |
663 | return false; |
674 | return false; |
664 | 675 | ||
665 | if (vma->obj->base.write_domain == I915_GEM_DOMAIN_CPU) |
676 | if (vma->obj->base.write_domain == I915_GEM_DOMAIN_CPU) |
666 | return false; |
677 | return false; |
667 | 678 | ||
668 | return true; |
679 | return true; |
669 | } |
680 | } |
670 | 681 | ||
671 | static bool |
682 | static bool |
672 | eb_vma_misplaced(struct i915_vma *vma) |
683 | eb_vma_misplaced(struct i915_vma *vma) |
673 | { |
684 | { |
674 | struct drm_i915_gem_exec_object2 *entry = vma->exec_entry; |
685 | struct drm_i915_gem_exec_object2 *entry = vma->exec_entry; |
675 | struct drm_i915_gem_object *obj = vma->obj; |
686 | struct drm_i915_gem_object *obj = vma->obj; |
676 | 687 | ||
677 | WARN_ON(entry->flags & __EXEC_OBJECT_NEEDS_MAP && |
- | |
678 | !i915_is_ggtt(vma->vm)); |
688 | WARN_ON(entry->flags & __EXEC_OBJECT_NEEDS_MAP && !vma->is_ggtt); |
679 | 689 | ||
680 | if (entry->alignment && |
690 | if (entry->alignment && |
681 | vma->node.start & (entry->alignment - 1)) |
691 | vma->node.start & (entry->alignment - 1)) |
682 | return true; |
692 | return true; |
683 | 693 | ||
684 | if (entry->flags & EXEC_OBJECT_PINNED && |
694 | if (entry->flags & EXEC_OBJECT_PINNED && |
685 | vma->node.start != entry->offset) |
695 | vma->node.start != entry->offset) |
686 | return true; |
696 | return true; |
687 | 697 | ||
688 | if (entry->flags & __EXEC_OBJECT_NEEDS_BIAS && |
698 | if (entry->flags & __EXEC_OBJECT_NEEDS_BIAS && |
689 | vma->node.start < BATCH_OFFSET_BIAS) |
699 | vma->node.start < BATCH_OFFSET_BIAS) |
690 | return true; |
700 | return true; |
691 | 701 | ||
692 | /* avoid costly ping-pong once a batch bo ended up non-mappable */ |
702 | /* avoid costly ping-pong once a batch bo ended up non-mappable */ |
693 | if (entry->flags & __EXEC_OBJECT_NEEDS_MAP && !obj->map_and_fenceable) |
703 | if (entry->flags & __EXEC_OBJECT_NEEDS_MAP && !obj->map_and_fenceable) |
694 | return !only_mappable_for_reloc(entry->flags); |
704 | return !only_mappable_for_reloc(entry->flags); |
695 | 705 | ||
696 | if ((entry->flags & EXEC_OBJECT_SUPPORTS_48B_ADDRESS) == 0 && |
706 | if ((entry->flags & EXEC_OBJECT_SUPPORTS_48B_ADDRESS) == 0 && |
697 | (vma->node.start + vma->node.size - 1) >> 32) |
707 | (vma->node.start + vma->node.size - 1) >> 32) |
698 | return true; |
708 | return true; |
699 | 709 | ||
700 | return false; |
710 | return false; |
701 | } |
711 | } |
702 | 712 | ||
703 | static int |
713 | static int |
704 | i915_gem_execbuffer_reserve(struct intel_engine_cs *ring, |
714 | i915_gem_execbuffer_reserve(struct intel_engine_cs *ring, |
705 | struct list_head *vmas, |
715 | struct list_head *vmas, |
706 | struct intel_context *ctx, |
716 | struct intel_context *ctx, |
707 | bool *need_relocs) |
717 | bool *need_relocs) |
708 | { |
718 | { |
709 | struct drm_i915_gem_object *obj; |
719 | struct drm_i915_gem_object *obj; |
710 | struct i915_vma *vma; |
720 | struct i915_vma *vma; |
711 | struct i915_address_space *vm; |
721 | struct i915_address_space *vm; |
712 | struct list_head ordered_vmas; |
722 | struct list_head ordered_vmas; |
713 | struct list_head pinned_vmas; |
723 | struct list_head pinned_vmas; |
714 | bool has_fenced_gpu_access = INTEL_INFO(ring->dev)->gen < 4; |
724 | bool has_fenced_gpu_access = INTEL_INFO(ring->dev)->gen < 4; |
715 | int retry; |
725 | int retry; |
716 | 726 | ||
717 | i915_gem_retire_requests_ring(ring); |
727 | i915_gem_retire_requests_ring(ring); |
718 | 728 | ||
719 | vm = list_first_entry(vmas, struct i915_vma, exec_list)->vm; |
729 | vm = list_first_entry(vmas, struct i915_vma, exec_list)->vm; |
720 | 730 | ||
721 | INIT_LIST_HEAD(&ordered_vmas); |
731 | INIT_LIST_HEAD(&ordered_vmas); |
722 | INIT_LIST_HEAD(&pinned_vmas); |
732 | INIT_LIST_HEAD(&pinned_vmas); |
723 | while (!list_empty(vmas)) { |
733 | while (!list_empty(vmas)) { |
724 | struct drm_i915_gem_exec_object2 *entry; |
734 | struct drm_i915_gem_exec_object2 *entry; |
725 | bool need_fence, need_mappable; |
735 | bool need_fence, need_mappable; |
726 | 736 | ||
727 | vma = list_first_entry(vmas, struct i915_vma, exec_list); |
737 | vma = list_first_entry(vmas, struct i915_vma, exec_list); |
728 | obj = vma->obj; |
738 | obj = vma->obj; |
729 | entry = vma->exec_entry; |
739 | entry = vma->exec_entry; |
730 | 740 | ||
731 | if (ctx->flags & CONTEXT_NO_ZEROMAP) |
741 | if (ctx->flags & CONTEXT_NO_ZEROMAP) |
732 | entry->flags |= __EXEC_OBJECT_NEEDS_BIAS; |
742 | entry->flags |= __EXEC_OBJECT_NEEDS_BIAS; |
733 | 743 | ||
734 | if (!has_fenced_gpu_access) |
744 | if (!has_fenced_gpu_access) |
735 | entry->flags &= ~EXEC_OBJECT_NEEDS_FENCE; |
745 | entry->flags &= ~EXEC_OBJECT_NEEDS_FENCE; |
736 | need_fence = |
746 | need_fence = |
737 | entry->flags & EXEC_OBJECT_NEEDS_FENCE && |
747 | entry->flags & EXEC_OBJECT_NEEDS_FENCE && |
738 | obj->tiling_mode != I915_TILING_NONE; |
748 | obj->tiling_mode != I915_TILING_NONE; |
739 | need_mappable = need_fence || need_reloc_mappable(vma); |
749 | need_mappable = need_fence || need_reloc_mappable(vma); |
740 | 750 | ||
741 | if (entry->flags & EXEC_OBJECT_PINNED) |
751 | if (entry->flags & EXEC_OBJECT_PINNED) |
742 | list_move_tail(&vma->exec_list, &pinned_vmas); |
752 | list_move_tail(&vma->exec_list, &pinned_vmas); |
743 | else if (need_mappable) { |
753 | else if (need_mappable) { |
744 | entry->flags |= __EXEC_OBJECT_NEEDS_MAP; |
754 | entry->flags |= __EXEC_OBJECT_NEEDS_MAP; |
745 | list_move(&vma->exec_list, &ordered_vmas); |
755 | list_move(&vma->exec_list, &ordered_vmas); |
746 | } else |
756 | } else |
747 | list_move_tail(&vma->exec_list, &ordered_vmas); |
757 | list_move_tail(&vma->exec_list, &ordered_vmas); |
748 | 758 | ||
749 | obj->base.pending_read_domains = I915_GEM_GPU_DOMAINS & ~I915_GEM_DOMAIN_COMMAND; |
759 | obj->base.pending_read_domains = I915_GEM_GPU_DOMAINS & ~I915_GEM_DOMAIN_COMMAND; |
750 | obj->base.pending_write_domain = 0; |
760 | obj->base.pending_write_domain = 0; |
751 | } |
761 | } |
752 | list_splice(&ordered_vmas, vmas); |
762 | list_splice(&ordered_vmas, vmas); |
753 | list_splice(&pinned_vmas, vmas); |
763 | list_splice(&pinned_vmas, vmas); |
754 | 764 | ||
755 | /* Attempt to pin all of the buffers into the GTT. |
765 | /* Attempt to pin all of the buffers into the GTT. |
756 | * This is done in 3 phases: |
766 | * This is done in 3 phases: |
757 | * |
767 | * |
758 | * 1a. Unbind all objects that do not match the GTT constraints for |
768 | * 1a. Unbind all objects that do not match the GTT constraints for |
759 | * the execbuffer (fenceable, mappable, alignment etc). |
769 | * the execbuffer (fenceable, mappable, alignment etc). |
760 | * 1b. Increment pin count for already bound objects. |
770 | * 1b. Increment pin count for already bound objects. |
761 | * 2. Bind new objects. |
771 | * 2. Bind new objects. |
762 | * 3. Decrement pin count. |
772 | * 3. Decrement pin count. |
763 | * |
773 | * |
764 | * This avoid unnecessary unbinding of later objects in order to make |
774 | * This avoid unnecessary unbinding of later objects in order to make |
765 | * room for the earlier objects *unless* we need to defragment. |
775 | * room for the earlier objects *unless* we need to defragment. |
766 | */ |
776 | */ |
767 | retry = 0; |
777 | retry = 0; |
768 | do { |
778 | do { |
769 | int ret = 0; |
779 | int ret = 0; |
770 | 780 | ||
771 | /* Unbind any ill-fitting objects or pin. */ |
781 | /* Unbind any ill-fitting objects or pin. */ |
772 | list_for_each_entry(vma, vmas, exec_list) { |
782 | list_for_each_entry(vma, vmas, exec_list) { |
773 | if (!drm_mm_node_allocated(&vma->node)) |
783 | if (!drm_mm_node_allocated(&vma->node)) |
774 | continue; |
784 | continue; |
775 | 785 | ||
776 | if (eb_vma_misplaced(vma)) |
786 | if (eb_vma_misplaced(vma)) |
777 | ret = i915_vma_unbind(vma); |
787 | ret = i915_vma_unbind(vma); |
778 | else |
788 | else |
779 | ret = i915_gem_execbuffer_reserve_vma(vma, ring, need_relocs); |
789 | ret = i915_gem_execbuffer_reserve_vma(vma, ring, need_relocs); |
780 | if (ret) |
790 | if (ret) |
781 | goto err; |
791 | goto err; |
782 | } |
792 | } |
783 | 793 | ||
784 | /* Bind fresh objects */ |
794 | /* Bind fresh objects */ |
785 | list_for_each_entry(vma, vmas, exec_list) { |
795 | list_for_each_entry(vma, vmas, exec_list) { |
786 | if (drm_mm_node_allocated(&vma->node)) |
796 | if (drm_mm_node_allocated(&vma->node)) |
787 | continue; |
797 | continue; |
788 | 798 | ||
789 | ret = i915_gem_execbuffer_reserve_vma(vma, ring, need_relocs); |
799 | ret = i915_gem_execbuffer_reserve_vma(vma, ring, need_relocs); |
790 | if (ret) |
800 | if (ret) |
791 | goto err; |
801 | goto err; |
792 | } |
802 | } |
793 | 803 | ||
794 | err: |
804 | err: |
795 | if (ret != -ENOSPC || retry++) |
805 | if (ret != -ENOSPC || retry++) |
796 | return ret; |
806 | return ret; |
797 | 807 | ||
798 | /* Decrement pin count for bound objects */ |
808 | /* Decrement pin count for bound objects */ |
799 | list_for_each_entry(vma, vmas, exec_list) |
809 | list_for_each_entry(vma, vmas, exec_list) |
800 | i915_gem_execbuffer_unreserve_vma(vma); |
810 | i915_gem_execbuffer_unreserve_vma(vma); |
801 | 811 | ||
802 | ret = i915_gem_evict_vm(vm, true); |
812 | ret = i915_gem_evict_vm(vm, true); |
803 | if (ret) |
813 | if (ret) |
804 | return ret; |
814 | return ret; |
805 | } while (1); |
815 | } while (1); |
806 | } |
816 | } |
807 | 817 | ||
808 | static int |
818 | static int |
809 | i915_gem_execbuffer_relocate_slow(struct drm_device *dev, |
819 | i915_gem_execbuffer_relocate_slow(struct drm_device *dev, |
810 | struct drm_i915_gem_execbuffer2 *args, |
820 | struct drm_i915_gem_execbuffer2 *args, |
811 | struct drm_file *file, |
821 | struct drm_file *file, |
812 | struct intel_engine_cs *ring, |
822 | struct intel_engine_cs *ring, |
813 | struct eb_vmas *eb, |
823 | struct eb_vmas *eb, |
814 | struct drm_i915_gem_exec_object2 *exec, |
824 | struct drm_i915_gem_exec_object2 *exec, |
815 | struct intel_context *ctx) |
825 | struct intel_context *ctx) |
816 | { |
826 | { |
817 | struct drm_i915_gem_relocation_entry *reloc; |
827 | struct drm_i915_gem_relocation_entry *reloc; |
818 | struct i915_address_space *vm; |
828 | struct i915_address_space *vm; |
819 | struct i915_vma *vma; |
829 | struct i915_vma *vma; |
820 | bool need_relocs; |
830 | bool need_relocs; |
821 | int *reloc_offset; |
831 | int *reloc_offset; |
822 | int i, total, ret; |
832 | int i, total, ret; |
823 | unsigned count = args->buffer_count; |
833 | unsigned count = args->buffer_count; |
824 | 834 | ||
825 | vm = list_first_entry(&eb->vmas, struct i915_vma, exec_list)->vm; |
835 | vm = list_first_entry(&eb->vmas, struct i915_vma, exec_list)->vm; |
826 | 836 | ||
827 | /* We may process another execbuffer during the unlock... */ |
837 | /* We may process another execbuffer during the unlock... */ |
828 | while (!list_empty(&eb->vmas)) { |
838 | while (!list_empty(&eb->vmas)) { |
829 | vma = list_first_entry(&eb->vmas, struct i915_vma, exec_list); |
839 | vma = list_first_entry(&eb->vmas, struct i915_vma, exec_list); |
830 | list_del_init(&vma->exec_list); |
840 | list_del_init(&vma->exec_list); |
831 | i915_gem_execbuffer_unreserve_vma(vma); |
841 | i915_gem_execbuffer_unreserve_vma(vma); |
832 | drm_gem_object_unreference(&vma->obj->base); |
842 | drm_gem_object_unreference(&vma->obj->base); |
833 | } |
843 | } |
834 | 844 | ||
835 | mutex_unlock(&dev->struct_mutex); |
845 | mutex_unlock(&dev->struct_mutex); |
836 | 846 | ||
837 | total = 0; |
847 | total = 0; |
838 | for (i = 0; i < count; i++) |
848 | for (i = 0; i < count; i++) |
839 | total += exec[i].relocation_count; |
849 | total += exec[i].relocation_count; |
840 | 850 | ||
841 | reloc_offset = __builtin_malloc(count * sizeof(*reloc_offset)); |
851 | reloc_offset = __builtin_malloc(count * sizeof(*reloc_offset)); |
842 | reloc = __builtin_malloc(total * sizeof(*reloc)); |
852 | reloc = __builtin_malloc(total * sizeof(*reloc)); |
843 | if (reloc == NULL || reloc_offset == NULL) { |
853 | if (reloc == NULL || reloc_offset == NULL) { |
844 | kfree(reloc); |
854 | kfree(reloc); |
845 | kfree(reloc_offset); |
855 | kfree(reloc_offset); |
846 | mutex_lock(&dev->struct_mutex); |
856 | mutex_lock(&dev->struct_mutex); |
847 | return -ENOMEM; |
857 | return -ENOMEM; |
848 | } |
858 | } |
849 | 859 | ||
850 | total = 0; |
860 | total = 0; |
851 | for (i = 0; i < count; i++) { |
861 | for (i = 0; i < count; i++) { |
852 | struct drm_i915_gem_relocation_entry __user *user_relocs; |
862 | struct drm_i915_gem_relocation_entry __user *user_relocs; |
853 | u64 invalid_offset = (u64)-1; |
863 | u64 invalid_offset = (u64)-1; |
854 | int j; |
864 | int j; |
855 | 865 | ||
856 | user_relocs = to_user_ptr(exec[i].relocs_ptr); |
866 | user_relocs = to_user_ptr(exec[i].relocs_ptr); |
857 | 867 | ||
858 | if (copy_from_user(reloc+total, user_relocs, |
868 | if (copy_from_user(reloc+total, user_relocs, |
859 | exec[i].relocation_count * sizeof(*reloc))) { |
869 | exec[i].relocation_count * sizeof(*reloc))) { |
860 | ret = -EFAULT; |
870 | ret = -EFAULT; |
861 | mutex_lock(&dev->struct_mutex); |
871 | mutex_lock(&dev->struct_mutex); |
862 | goto err; |
872 | goto err; |
863 | } |
873 | } |
864 | 874 | ||
865 | /* As we do not update the known relocation offsets after |
875 | /* As we do not update the known relocation offsets after |
866 | * relocating (due to the complexities in lock handling), |
876 | * relocating (due to the complexities in lock handling), |
867 | * we need to mark them as invalid now so that we force the |
877 | * we need to mark them as invalid now so that we force the |
868 | * relocation processing next time. Just in case the target |
878 | * relocation processing next time. Just in case the target |
869 | * object is evicted and then rebound into its old |
879 | * object is evicted and then rebound into its old |
870 | * presumed_offset before the next execbuffer - if that |
880 | * presumed_offset before the next execbuffer - if that |
871 | * happened we would make the mistake of assuming that the |
881 | * happened we would make the mistake of assuming that the |
872 | * relocations were valid. |
882 | * relocations were valid. |
873 | */ |
883 | */ |
874 | for (j = 0; j < exec[i].relocation_count; j++) { |
884 | for (j = 0; j < exec[i].relocation_count; j++) { |
875 | if (__copy_to_user(&user_relocs[j].presumed_offset, |
885 | if (__copy_to_user(&user_relocs[j].presumed_offset, |
876 | &invalid_offset, |
886 | &invalid_offset, |
877 | sizeof(invalid_offset))) { |
887 | sizeof(invalid_offset))) { |
878 | ret = -EFAULT; |
888 | ret = -EFAULT; |
879 | mutex_lock(&dev->struct_mutex); |
889 | mutex_lock(&dev->struct_mutex); |
880 | goto err; |
890 | goto err; |
881 | } |
891 | } |
882 | } |
892 | } |
883 | 893 | ||
884 | reloc_offset[i] = total; |
894 | reloc_offset[i] = total; |
885 | total += exec[i].relocation_count; |
895 | total += exec[i].relocation_count; |
886 | } |
896 | } |
887 | 897 | ||
888 | ret = i915_mutex_lock_interruptible(dev); |
898 | ret = i915_mutex_lock_interruptible(dev); |
889 | if (ret) { |
899 | if (ret) { |
890 | mutex_lock(&dev->struct_mutex); |
900 | mutex_lock(&dev->struct_mutex); |
891 | goto err; |
901 | goto err; |
892 | } |
902 | } |
893 | 903 | ||
894 | /* reacquire the objects */ |
904 | /* reacquire the objects */ |
895 | eb_reset(eb); |
905 | eb_reset(eb); |
896 | ret = eb_lookup_vmas(eb, exec, args, vm, file); |
906 | ret = eb_lookup_vmas(eb, exec, args, vm, file); |
897 | if (ret) |
907 | if (ret) |
898 | goto err; |
908 | goto err; |
899 | 909 | ||
900 | need_relocs = (args->flags & I915_EXEC_NO_RELOC) == 0; |
910 | need_relocs = (args->flags & I915_EXEC_NO_RELOC) == 0; |
901 | ret = i915_gem_execbuffer_reserve(ring, &eb->vmas, ctx, &need_relocs); |
911 | ret = i915_gem_execbuffer_reserve(ring, &eb->vmas, ctx, &need_relocs); |
902 | if (ret) |
912 | if (ret) |
903 | goto err; |
913 | goto err; |
904 | 914 | ||
905 | list_for_each_entry(vma, &eb->vmas, exec_list) { |
915 | list_for_each_entry(vma, &eb->vmas, exec_list) { |
906 | int offset = vma->exec_entry - exec; |
916 | int offset = vma->exec_entry - exec; |
907 | ret = i915_gem_execbuffer_relocate_vma_slow(vma, eb, |
917 | ret = i915_gem_execbuffer_relocate_vma_slow(vma, eb, |
908 | reloc + reloc_offset[offset]); |
918 | reloc + reloc_offset[offset]); |
909 | if (ret) |
919 | if (ret) |
910 | goto err; |
920 | goto err; |
911 | } |
921 | } |
912 | 922 | ||
913 | /* Leave the user relocations as are, this is the painfully slow path, |
923 | /* Leave the user relocations as are, this is the painfully slow path, |
914 | * and we want to avoid the complication of dropping the lock whilst |
924 | * and we want to avoid the complication of dropping the lock whilst |
915 | * having buffers reserved in the aperture and so causing spurious |
925 | * having buffers reserved in the aperture and so causing spurious |
916 | * ENOSPC for random operations. |
926 | * ENOSPC for random operations. |
917 | */ |
927 | */ |
918 | 928 | ||
919 | err: |
929 | err: |
920 | kfree(reloc); |
930 | kfree(reloc); |
921 | kfree(reloc_offset); |
931 | kfree(reloc_offset); |
922 | return ret; |
932 | return ret; |
923 | } |
933 | } |
924 | 934 | ||
925 | static int |
935 | static int |
926 | i915_gem_execbuffer_move_to_gpu(struct drm_i915_gem_request *req, |
936 | i915_gem_execbuffer_move_to_gpu(struct drm_i915_gem_request *req, |
927 | struct list_head *vmas) |
937 | struct list_head *vmas) |
928 | { |
938 | { |
929 | const unsigned other_rings = ~intel_ring_flag(req->ring); |
939 | const unsigned other_rings = ~intel_ring_flag(req->ring); |
930 | struct i915_vma *vma; |
940 | struct i915_vma *vma; |
931 | uint32_t flush_domains = 0; |
941 | uint32_t flush_domains = 0; |
932 | bool flush_chipset = false; |
942 | bool flush_chipset = false; |
933 | int ret; |
943 | int ret; |
934 | 944 | ||
935 | list_for_each_entry(vma, vmas, exec_list) { |
945 | list_for_each_entry(vma, vmas, exec_list) { |
936 | struct drm_i915_gem_object *obj = vma->obj; |
946 | struct drm_i915_gem_object *obj = vma->obj; |
937 | 947 | ||
938 | if (obj->active & other_rings) { |
948 | if (obj->active & other_rings) { |
939 | ret = i915_gem_object_sync(obj, req->ring, &req); |
949 | ret = i915_gem_object_sync(obj, req->ring, &req); |
940 | if (ret) |
950 | if (ret) |
941 | return ret; |
951 | return ret; |
942 | } |
952 | } |
943 | 953 | ||
944 | if (obj->base.write_domain & I915_GEM_DOMAIN_CPU) |
954 | if (obj->base.write_domain & I915_GEM_DOMAIN_CPU) |
945 | flush_chipset |= i915_gem_clflush_object(obj, false); |
955 | flush_chipset |= i915_gem_clflush_object(obj, false); |
946 | 956 | ||
947 | flush_domains |= obj->base.write_domain; |
957 | flush_domains |= obj->base.write_domain; |
948 | } |
958 | } |
949 | 959 | ||
950 | if (flush_chipset) |
960 | if (flush_chipset) |
951 | i915_gem_chipset_flush(req->ring->dev); |
961 | i915_gem_chipset_flush(req->ring->dev); |
952 | 962 | ||
953 | if (flush_domains & I915_GEM_DOMAIN_GTT) |
963 | if (flush_domains & I915_GEM_DOMAIN_GTT) |
954 | wmb(); |
964 | wmb(); |
955 | 965 | ||
956 | /* Unconditionally invalidate gpu caches and ensure that we do flush |
966 | /* Unconditionally invalidate gpu caches and ensure that we do flush |
957 | * any residual writes from the previous batch. |
967 | * any residual writes from the previous batch. |
958 | */ |
968 | */ |
959 | return intel_ring_invalidate_all_caches(req); |
969 | return intel_ring_invalidate_all_caches(req); |
960 | } |
970 | } |
961 | 971 | ||
962 | static bool |
972 | static bool |
963 | i915_gem_check_execbuffer(struct drm_i915_gem_execbuffer2 *exec) |
973 | i915_gem_check_execbuffer(struct drm_i915_gem_execbuffer2 *exec) |
964 | { |
974 | { |
965 | if (exec->flags & __I915_EXEC_UNKNOWN_FLAGS) |
975 | if (exec->flags & __I915_EXEC_UNKNOWN_FLAGS) |
966 | return false; |
976 | return false; |
967 | 977 | ||
968 | /* Kernel clipping was a DRI1 misfeature */ |
978 | /* Kernel clipping was a DRI1 misfeature */ |
969 | if (exec->num_cliprects || exec->cliprects_ptr) |
979 | if (exec->num_cliprects || exec->cliprects_ptr) |
970 | return false; |
980 | return false; |
971 | 981 | ||
972 | if (exec->DR4 == 0xffffffff) { |
982 | if (exec->DR4 == 0xffffffff) { |
973 | DRM_DEBUG("UXA submitting garbage DR4, fixing up\n"); |
983 | DRM_DEBUG("UXA submitting garbage DR4, fixing up\n"); |
974 | exec->DR4 = 0; |
984 | exec->DR4 = 0; |
975 | } |
985 | } |
976 | if (exec->DR1 || exec->DR4) |
986 | if (exec->DR1 || exec->DR4) |
977 | return false; |
987 | return false; |
978 | 988 | ||
979 | if ((exec->batch_start_offset | exec->batch_len) & 0x7) |
989 | if ((exec->batch_start_offset | exec->batch_len) & 0x7) |
980 | return false; |
990 | return false; |
981 | 991 | ||
982 | return true; |
992 | return true; |
983 | } |
993 | } |
984 | 994 | ||
985 | static int |
995 | static int |
986 | validate_exec_list(struct drm_device *dev, |
996 | validate_exec_list(struct drm_device *dev, |
987 | struct drm_i915_gem_exec_object2 *exec, |
997 | struct drm_i915_gem_exec_object2 *exec, |
988 | int count) |
998 | int count) |
989 | { |
999 | { |
990 | unsigned relocs_total = 0; |
1000 | unsigned relocs_total = 0; |
991 | unsigned relocs_max = UINT_MAX / sizeof(struct drm_i915_gem_relocation_entry); |
1001 | unsigned relocs_max = UINT_MAX / sizeof(struct drm_i915_gem_relocation_entry); |
992 | unsigned invalid_flags; |
1002 | unsigned invalid_flags; |
993 | int i; |
1003 | int i; |
994 | 1004 | ||
995 | invalid_flags = __EXEC_OBJECT_UNKNOWN_FLAGS; |
1005 | invalid_flags = __EXEC_OBJECT_UNKNOWN_FLAGS; |
996 | if (USES_FULL_PPGTT(dev)) |
1006 | if (USES_FULL_PPGTT(dev)) |
997 | invalid_flags |= EXEC_OBJECT_NEEDS_GTT; |
1007 | invalid_flags |= EXEC_OBJECT_NEEDS_GTT; |
998 | 1008 | ||
999 | for (i = 0; i < count; i++) { |
1009 | for (i = 0; i < count; i++) { |
1000 | char __user *ptr = to_user_ptr(exec[i].relocs_ptr); |
1010 | char __user *ptr = to_user_ptr(exec[i].relocs_ptr); |
1001 | int length; /* limited by fault_in_pages_readable() */ |
1011 | int length; /* limited by fault_in_pages_readable() */ |
1002 | 1012 | ||
1003 | if (exec[i].flags & invalid_flags) |
1013 | if (exec[i].flags & invalid_flags) |
1004 | return -EINVAL; |
1014 | return -EINVAL; |
1005 | 1015 | ||
1006 | /* Offset can be used as input (EXEC_OBJECT_PINNED), reject |
1016 | /* Offset can be used as input (EXEC_OBJECT_PINNED), reject |
1007 | * any non-page-aligned or non-canonical addresses. |
1017 | * any non-page-aligned or non-canonical addresses. |
1008 | */ |
1018 | */ |
1009 | if (exec[i].flags & EXEC_OBJECT_PINNED) { |
1019 | if (exec[i].flags & EXEC_OBJECT_PINNED) { |
1010 | if (exec[i].offset != |
1020 | if (exec[i].offset != |
1011 | gen8_canonical_addr(exec[i].offset & PAGE_MASK)) |
1021 | gen8_canonical_addr(exec[i].offset & PAGE_MASK)) |
1012 | return -EINVAL; |
1022 | return -EINVAL; |
1013 | 1023 | ||
1014 | /* From drm_mm perspective address space is continuous, |
1024 | /* From drm_mm perspective address space is continuous, |
1015 | * so from this point we're always using non-canonical |
1025 | * so from this point we're always using non-canonical |
1016 | * form internally. |
1026 | * form internally. |
1017 | */ |
1027 | */ |
1018 | exec[i].offset = gen8_noncanonical_addr(exec[i].offset); |
1028 | exec[i].offset = gen8_noncanonical_addr(exec[i].offset); |
1019 | } |
1029 | } |
1020 | 1030 | ||
1021 | if (exec[i].alignment && !is_power_of_2(exec[i].alignment)) |
1031 | if (exec[i].alignment && !is_power_of_2(exec[i].alignment)) |
1022 | return -EINVAL; |
1032 | return -EINVAL; |
1023 | 1033 | ||
1024 | /* First check for malicious input causing overflow in |
1034 | /* First check for malicious input causing overflow in |
1025 | * the worst case where we need to allocate the entire |
1035 | * the worst case where we need to allocate the entire |
1026 | * relocation tree as a single array. |
1036 | * relocation tree as a single array. |
1027 | */ |
1037 | */ |
1028 | if (exec[i].relocation_count > relocs_max - relocs_total) |
1038 | if (exec[i].relocation_count > relocs_max - relocs_total) |
1029 | return -EINVAL; |
1039 | return -EINVAL; |
1030 | relocs_total += exec[i].relocation_count; |
1040 | relocs_total += exec[i].relocation_count; |
1031 | 1041 | ||
1032 | length = exec[i].relocation_count * |
1042 | length = exec[i].relocation_count * |
1033 | sizeof(struct drm_i915_gem_relocation_entry); |
1043 | sizeof(struct drm_i915_gem_relocation_entry); |
1034 | /* |
1044 | /* |
1035 | * We must check that the entire relocation array is safe |
1045 | * We must check that the entire relocation array is safe |
1036 | * to read, but since we may need to update the presumed |
1046 | * to read, but since we may need to update the presumed |
1037 | * offsets during execution, check for full write access. |
1047 | * offsets during execution, check for full write access. |
1038 | */ |
1048 | */ |
1039 | } |
1049 | } |
1040 | 1050 | ||
1041 | return 0; |
1051 | return 0; |
1042 | } |
1052 | } |
1043 | 1053 | ||
1044 | static struct intel_context * |
1054 | static struct intel_context * |
1045 | i915_gem_validate_context(struct drm_device *dev, struct drm_file *file, |
1055 | i915_gem_validate_context(struct drm_device *dev, struct drm_file *file, |
1046 | struct intel_engine_cs *ring, const u32 ctx_id) |
1056 | struct intel_engine_cs *ring, const u32 ctx_id) |
1047 | { |
1057 | { |
1048 | struct intel_context *ctx = NULL; |
1058 | struct intel_context *ctx = NULL; |
1049 | struct i915_ctx_hang_stats *hs; |
1059 | struct i915_ctx_hang_stats *hs; |
1050 | 1060 | ||
1051 | if (ring->id != RCS && ctx_id != DEFAULT_CONTEXT_HANDLE) |
1061 | if (ring->id != RCS && ctx_id != DEFAULT_CONTEXT_HANDLE) |
1052 | return ERR_PTR(-EINVAL); |
1062 | return ERR_PTR(-EINVAL); |
1053 | 1063 | ||
1054 | ctx = i915_gem_context_get(file->driver_priv, ctx_id); |
1064 | ctx = i915_gem_context_get(file->driver_priv, ctx_id); |
1055 | if (IS_ERR(ctx)) |
1065 | if (IS_ERR(ctx)) |
1056 | return ctx; |
1066 | return ctx; |
1057 | 1067 | ||
1058 | hs = &ctx->hang_stats; |
1068 | hs = &ctx->hang_stats; |
1059 | if (hs->banned) { |
1069 | if (hs->banned) { |
1060 | DRM_DEBUG("Context %u tried to submit while banned\n", ctx_id); |
1070 | DRM_DEBUG("Context %u tried to submit while banned\n", ctx_id); |
1061 | return ERR_PTR(-EIO); |
1071 | return ERR_PTR(-EIO); |
1062 | } |
1072 | } |
1063 | 1073 | ||
1064 | if (i915.enable_execlists && !ctx->engine[ring->id].state) { |
1074 | if (i915.enable_execlists && !ctx->engine[ring->id].state) { |
1065 | int ret = intel_lr_context_deferred_alloc(ctx, ring); |
1075 | int ret = intel_lr_context_deferred_alloc(ctx, ring); |
1066 | if (ret) { |
1076 | if (ret) { |
1067 | DRM_DEBUG("Could not create LRC %u: %d\n", ctx_id, ret); |
1077 | DRM_DEBUG("Could not create LRC %u: %d\n", ctx_id, ret); |
1068 | return ERR_PTR(ret); |
1078 | return ERR_PTR(ret); |
1069 | } |
1079 | } |
1070 | } |
1080 | } |
1071 | 1081 | ||
1072 | return ctx; |
1082 | return ctx; |
1073 | } |
1083 | } |
1074 | 1084 | ||
1075 | void |
1085 | void |
1076 | i915_gem_execbuffer_move_to_active(struct list_head *vmas, |
1086 | i915_gem_execbuffer_move_to_active(struct list_head *vmas, |
1077 | struct drm_i915_gem_request *req) |
1087 | struct drm_i915_gem_request *req) |
1078 | { |
1088 | { |
1079 | struct intel_engine_cs *ring = i915_gem_request_get_ring(req); |
1089 | struct intel_engine_cs *ring = i915_gem_request_get_ring(req); |
1080 | struct i915_vma *vma; |
1090 | struct i915_vma *vma; |
1081 | 1091 | ||
1082 | list_for_each_entry(vma, vmas, exec_list) { |
1092 | list_for_each_entry(vma, vmas, exec_list) { |
1083 | struct drm_i915_gem_exec_object2 *entry = vma->exec_entry; |
1093 | struct drm_i915_gem_exec_object2 *entry = vma->exec_entry; |
1084 | struct drm_i915_gem_object *obj = vma->obj; |
1094 | struct drm_i915_gem_object *obj = vma->obj; |
1085 | u32 old_read = obj->base.read_domains; |
1095 | u32 old_read = obj->base.read_domains; |
1086 | u32 old_write = obj->base.write_domain; |
1096 | u32 old_write = obj->base.write_domain; |
1087 | 1097 | ||
1088 | obj->dirty = 1; /* be paranoid */ |
1098 | obj->dirty = 1; /* be paranoid */ |
1089 | obj->base.write_domain = obj->base.pending_write_domain; |
1099 | obj->base.write_domain = obj->base.pending_write_domain; |
1090 | if (obj->base.write_domain == 0) |
1100 | if (obj->base.write_domain == 0) |
1091 | obj->base.pending_read_domains |= obj->base.read_domains; |
1101 | obj->base.pending_read_domains |= obj->base.read_domains; |
1092 | obj->base.read_domains = obj->base.pending_read_domains; |
1102 | obj->base.read_domains = obj->base.pending_read_domains; |
1093 | 1103 | ||
1094 | i915_vma_move_to_active(vma, req); |
1104 | i915_vma_move_to_active(vma, req); |
1095 | if (obj->base.write_domain) { |
1105 | if (obj->base.write_domain) { |
1096 | i915_gem_request_assign(&obj->last_write_req, req); |
1106 | i915_gem_request_assign(&obj->last_write_req, req); |
1097 | 1107 | ||
1098 | intel_fb_obj_invalidate(obj, ORIGIN_CS); |
1108 | intel_fb_obj_invalidate(obj, ORIGIN_CS); |
1099 | 1109 | ||
1100 | /* update for the implicit flush after a batch */ |
1110 | /* update for the implicit flush after a batch */ |
1101 | obj->base.write_domain &= ~I915_GEM_GPU_DOMAINS; |
1111 | obj->base.write_domain &= ~I915_GEM_GPU_DOMAINS; |
1102 | } |
1112 | } |
1103 | if (entry->flags & EXEC_OBJECT_NEEDS_FENCE) { |
1113 | if (entry->flags & EXEC_OBJECT_NEEDS_FENCE) { |
1104 | i915_gem_request_assign(&obj->last_fenced_req, req); |
1114 | i915_gem_request_assign(&obj->last_fenced_req, req); |
1105 | if (entry->flags & __EXEC_OBJECT_HAS_FENCE) { |
1115 | if (entry->flags & __EXEC_OBJECT_HAS_FENCE) { |
1106 | struct drm_i915_private *dev_priv = to_i915(ring->dev); |
1116 | struct drm_i915_private *dev_priv = to_i915(ring->dev); |
1107 | list_move_tail(&dev_priv->fence_regs[obj->fence_reg].lru_list, |
1117 | list_move_tail(&dev_priv->fence_regs[obj->fence_reg].lru_list, |
1108 | &dev_priv->mm.fence_list); |
1118 | &dev_priv->mm.fence_list); |
1109 | } |
1119 | } |
1110 | } |
1120 | } |
1111 | 1121 | ||
1112 | trace_i915_gem_object_change_domain(obj, old_read, old_write); |
1122 | trace_i915_gem_object_change_domain(obj, old_read, old_write); |
1113 | } |
1123 | } |
1114 | } |
1124 | } |
1115 | 1125 | ||
1116 | void |
1126 | void |
1117 | i915_gem_execbuffer_retire_commands(struct i915_execbuffer_params *params) |
1127 | i915_gem_execbuffer_retire_commands(struct i915_execbuffer_params *params) |
1118 | { |
1128 | { |
1119 | /* Unconditionally force add_request to emit a full flush. */ |
1129 | /* Unconditionally force add_request to emit a full flush. */ |
1120 | params->ring->gpu_caches_dirty = true; |
1130 | params->ring->gpu_caches_dirty = true; |
1121 | 1131 | ||
1122 | /* Add a breadcrumb for the completion of the batch buffer */ |
1132 | /* Add a breadcrumb for the completion of the batch buffer */ |
1123 | __i915_add_request(params->request, params->batch_obj, true); |
1133 | __i915_add_request(params->request, params->batch_obj, true); |
1124 | } |
1134 | } |
1125 | 1135 | ||
1126 | static int |
1136 | static int |
1127 | i915_reset_gen7_sol_offsets(struct drm_device *dev, |
1137 | i915_reset_gen7_sol_offsets(struct drm_device *dev, |
1128 | struct drm_i915_gem_request *req) |
1138 | struct drm_i915_gem_request *req) |
1129 | { |
1139 | { |
1130 | struct intel_engine_cs *ring = req->ring; |
1140 | struct intel_engine_cs *ring = req->ring; |
1131 | struct drm_i915_private *dev_priv = dev->dev_private; |
1141 | struct drm_i915_private *dev_priv = dev->dev_private; |
1132 | int ret, i; |
1142 | int ret, i; |
1133 | 1143 | ||
1134 | if (!IS_GEN7(dev) || ring != &dev_priv->ring[RCS]) { |
1144 | if (!IS_GEN7(dev) || ring != &dev_priv->ring[RCS]) { |
1135 | DRM_DEBUG("sol reset is gen7/rcs only\n"); |
1145 | DRM_DEBUG("sol reset is gen7/rcs only\n"); |
1136 | return -EINVAL; |
1146 | return -EINVAL; |
1137 | } |
1147 | } |
1138 | 1148 | ||
1139 | ret = intel_ring_begin(req, 4 * 3); |
1149 | ret = intel_ring_begin(req, 4 * 3); |
1140 | if (ret) |
1150 | if (ret) |
1141 | return ret; |
1151 | return ret; |
1142 | 1152 | ||
1143 | for (i = 0; i < 4; i++) { |
1153 | for (i = 0; i < 4; i++) { |
1144 | intel_ring_emit(ring, MI_LOAD_REGISTER_IMM(1)); |
1154 | intel_ring_emit(ring, MI_LOAD_REGISTER_IMM(1)); |
1145 | intel_ring_emit_reg(ring, GEN7_SO_WRITE_OFFSET(i)); |
1155 | intel_ring_emit_reg(ring, GEN7_SO_WRITE_OFFSET(i)); |
1146 | intel_ring_emit(ring, 0); |
1156 | intel_ring_emit(ring, 0); |
1147 | } |
1157 | } |
1148 | 1158 | ||
1149 | intel_ring_advance(ring); |
1159 | intel_ring_advance(ring); |
1150 | 1160 | ||
1151 | return 0; |
1161 | return 0; |
1152 | } |
1162 | } |
1153 | 1163 | ||
1154 | static struct drm_i915_gem_object* |
1164 | static struct drm_i915_gem_object* |
1155 | i915_gem_execbuffer_parse(struct intel_engine_cs *ring, |
1165 | i915_gem_execbuffer_parse(struct intel_engine_cs *ring, |
1156 | struct drm_i915_gem_exec_object2 *shadow_exec_entry, |
1166 | struct drm_i915_gem_exec_object2 *shadow_exec_entry, |
1157 | struct eb_vmas *eb, |
1167 | struct eb_vmas *eb, |
1158 | struct drm_i915_gem_object *batch_obj, |
1168 | struct drm_i915_gem_object *batch_obj, |
1159 | u32 batch_start_offset, |
1169 | u32 batch_start_offset, |
1160 | u32 batch_len, |
1170 | u32 batch_len, |
1161 | bool is_master) |
1171 | bool is_master) |
1162 | { |
1172 | { |
1163 | struct drm_i915_gem_object *shadow_batch_obj; |
1173 | struct drm_i915_gem_object *shadow_batch_obj; |
1164 | struct i915_vma *vma; |
1174 | struct i915_vma *vma; |
1165 | int ret; |
1175 | int ret; |
1166 | 1176 | ||
1167 | shadow_batch_obj = i915_gem_batch_pool_get(&ring->batch_pool, |
1177 | shadow_batch_obj = i915_gem_batch_pool_get(&ring->batch_pool, |
1168 | PAGE_ALIGN(batch_len)); |
1178 | PAGE_ALIGN(batch_len)); |
1169 | if (IS_ERR(shadow_batch_obj)) |
1179 | if (IS_ERR(shadow_batch_obj)) |
1170 | return shadow_batch_obj; |
1180 | return shadow_batch_obj; |
1171 | 1181 | ||
1172 | ret = i915_parse_cmds(ring, |
1182 | ret = i915_parse_cmds(ring, |
1173 | batch_obj, |
1183 | batch_obj, |
1174 | shadow_batch_obj, |
1184 | shadow_batch_obj, |
1175 | batch_start_offset, |
1185 | batch_start_offset, |
1176 | batch_len, |
1186 | batch_len, |
1177 | is_master); |
1187 | is_master); |
1178 | if (ret) |
1188 | if (ret) |
1179 | goto err; |
1189 | goto err; |
1180 | 1190 | ||
1181 | ret = i915_gem_obj_ggtt_pin(shadow_batch_obj, 0, 0); |
1191 | ret = i915_gem_obj_ggtt_pin(shadow_batch_obj, 0, 0); |
1182 | if (ret) |
1192 | if (ret) |
1183 | goto err; |
1193 | goto err; |
1184 | 1194 | ||
1185 | i915_gem_object_unpin_pages(shadow_batch_obj); |
1195 | i915_gem_object_unpin_pages(shadow_batch_obj); |
1186 | 1196 | ||
1187 | memset(shadow_exec_entry, 0, sizeof(*shadow_exec_entry)); |
1197 | memset(shadow_exec_entry, 0, sizeof(*shadow_exec_entry)); |
1188 | 1198 | ||
1189 | vma = i915_gem_obj_to_ggtt(shadow_batch_obj); |
1199 | vma = i915_gem_obj_to_ggtt(shadow_batch_obj); |
1190 | vma->exec_entry = shadow_exec_entry; |
1200 | vma->exec_entry = shadow_exec_entry; |
1191 | vma->exec_entry->flags = __EXEC_OBJECT_HAS_PIN; |
1201 | vma->exec_entry->flags = __EXEC_OBJECT_HAS_PIN; |
1192 | drm_gem_object_reference(&shadow_batch_obj->base); |
1202 | drm_gem_object_reference(&shadow_batch_obj->base); |
1193 | list_add_tail(&vma->exec_list, &eb->vmas); |
1203 | list_add_tail(&vma->exec_list, &eb->vmas); |
1194 | 1204 | ||
1195 | shadow_batch_obj->base.pending_read_domains = I915_GEM_DOMAIN_COMMAND; |
1205 | shadow_batch_obj->base.pending_read_domains = I915_GEM_DOMAIN_COMMAND; |
1196 | 1206 | ||
1197 | return shadow_batch_obj; |
1207 | return shadow_batch_obj; |
1198 | 1208 | ||
1199 | err: |
1209 | err: |
1200 | i915_gem_object_unpin_pages(shadow_batch_obj); |
1210 | i915_gem_object_unpin_pages(shadow_batch_obj); |
1201 | if (ret == -EACCES) /* unhandled chained batch */ |
1211 | if (ret == -EACCES) /* unhandled chained batch */ |
1202 | return batch_obj; |
1212 | return batch_obj; |
1203 | else |
1213 | else |
1204 | return ERR_PTR(ret); |
1214 | return ERR_PTR(ret); |
1205 | } |
1215 | } |
1206 | 1216 | ||
1207 | int |
1217 | int |
1208 | i915_gem_ringbuffer_submission(struct i915_execbuffer_params *params, |
1218 | i915_gem_ringbuffer_submission(struct i915_execbuffer_params *params, |
1209 | struct drm_i915_gem_execbuffer2 *args, |
1219 | struct drm_i915_gem_execbuffer2 *args, |
1210 | struct list_head *vmas) |
1220 | struct list_head *vmas) |
1211 | { |
1221 | { |
1212 | struct drm_device *dev = params->dev; |
1222 | struct drm_device *dev = params->dev; |
1213 | struct intel_engine_cs *ring = params->ring; |
1223 | struct intel_engine_cs *ring = params->ring; |
1214 | struct drm_i915_private *dev_priv = dev->dev_private; |
1224 | struct drm_i915_private *dev_priv = dev->dev_private; |
1215 | u64 exec_start, exec_len; |
1225 | u64 exec_start, exec_len; |
1216 | int instp_mode; |
1226 | int instp_mode; |
1217 | u32 instp_mask; |
1227 | u32 instp_mask; |
1218 | int ret; |
1228 | int ret; |
1219 | 1229 | ||
1220 | ret = i915_gem_execbuffer_move_to_gpu(params->request, vmas); |
1230 | ret = i915_gem_execbuffer_move_to_gpu(params->request, vmas); |
1221 | if (ret) |
1231 | if (ret) |
1222 | return ret; |
1232 | return ret; |
1223 | 1233 | ||
1224 | ret = i915_switch_context(params->request); |
1234 | ret = i915_switch_context(params->request); |
1225 | if (ret) |
1235 | if (ret) |
1226 | return ret; |
1236 | return ret; |
1227 | 1237 | ||
1228 | WARN(params->ctx->ppgtt && params->ctx->ppgtt->pd_dirty_rings & (1< |
1238 | WARN(params->ctx->ppgtt && params->ctx->ppgtt->pd_dirty_rings & (1< |
1229 | "%s didn't clear reload\n", ring->name); |
1239 | "%s didn't clear reload\n", ring->name); |
1230 | 1240 | ||
1231 | instp_mode = args->flags & I915_EXEC_CONSTANTS_MASK; |
1241 | instp_mode = args->flags & I915_EXEC_CONSTANTS_MASK; |
1232 | instp_mask = I915_EXEC_CONSTANTS_MASK; |
1242 | instp_mask = I915_EXEC_CONSTANTS_MASK; |
1233 | switch (instp_mode) { |
1243 | switch (instp_mode) { |
1234 | case I915_EXEC_CONSTANTS_REL_GENERAL: |
1244 | case I915_EXEC_CONSTANTS_REL_GENERAL: |
1235 | case I915_EXEC_CONSTANTS_ABSOLUTE: |
1245 | case I915_EXEC_CONSTANTS_ABSOLUTE: |
1236 | case I915_EXEC_CONSTANTS_REL_SURFACE: |
1246 | case I915_EXEC_CONSTANTS_REL_SURFACE: |
1237 | if (instp_mode != 0 && ring != &dev_priv->ring[RCS]) { |
1247 | if (instp_mode != 0 && ring != &dev_priv->ring[RCS]) { |
1238 | DRM_DEBUG("non-0 rel constants mode on non-RCS\n"); |
1248 | DRM_DEBUG("non-0 rel constants mode on non-RCS\n"); |
1239 | return -EINVAL; |
1249 | return -EINVAL; |
1240 | } |
1250 | } |
1241 | 1251 | ||
1242 | if (instp_mode != dev_priv->relative_constants_mode) { |
1252 | if (instp_mode != dev_priv->relative_constants_mode) { |
1243 | if (INTEL_INFO(dev)->gen < 4) { |
1253 | if (INTEL_INFO(dev)->gen < 4) { |
1244 | DRM_DEBUG("no rel constants on pre-gen4\n"); |
1254 | DRM_DEBUG("no rel constants on pre-gen4\n"); |
1245 | return -EINVAL; |
1255 | return -EINVAL; |
1246 | } |
1256 | } |
1247 | 1257 | ||
1248 | if (INTEL_INFO(dev)->gen > 5 && |
1258 | if (INTEL_INFO(dev)->gen > 5 && |
1249 | instp_mode == I915_EXEC_CONSTANTS_REL_SURFACE) { |
1259 | instp_mode == I915_EXEC_CONSTANTS_REL_SURFACE) { |
1250 | DRM_DEBUG("rel surface constants mode invalid on gen5+\n"); |
1260 | DRM_DEBUG("rel surface constants mode invalid on gen5+\n"); |
1251 | return -EINVAL; |
1261 | return -EINVAL; |
1252 | } |
1262 | } |
1253 | 1263 | ||
1254 | /* The HW changed the meaning on this bit on gen6 */ |
1264 | /* The HW changed the meaning on this bit on gen6 */ |
1255 | if (INTEL_INFO(dev)->gen >= 6) |
1265 | if (INTEL_INFO(dev)->gen >= 6) |
1256 | instp_mask &= ~I915_EXEC_CONSTANTS_REL_SURFACE; |
1266 | instp_mask &= ~I915_EXEC_CONSTANTS_REL_SURFACE; |
1257 | } |
1267 | } |
1258 | break; |
1268 | break; |
1259 | default: |
1269 | default: |
1260 | DRM_DEBUG("execbuf with unknown constants: %d\n", instp_mode); |
1270 | DRM_DEBUG("execbuf with unknown constants: %d\n", instp_mode); |
1261 | return -EINVAL; |
1271 | return -EINVAL; |
1262 | } |
1272 | } |
1263 | 1273 | ||
1264 | if (ring == &dev_priv->ring[RCS] && |
1274 | if (ring == &dev_priv->ring[RCS] && |
1265 | instp_mode != dev_priv->relative_constants_mode) { |
1275 | instp_mode != dev_priv->relative_constants_mode) { |
1266 | ret = intel_ring_begin(params->request, 4); |
1276 | ret = intel_ring_begin(params->request, 4); |
1267 | if (ret) |
1277 | if (ret) |
1268 | return ret; |
1278 | return ret; |
1269 | 1279 | ||
1270 | intel_ring_emit(ring, MI_NOOP); |
1280 | intel_ring_emit(ring, MI_NOOP); |
1271 | intel_ring_emit(ring, MI_LOAD_REGISTER_IMM(1)); |
1281 | intel_ring_emit(ring, MI_LOAD_REGISTER_IMM(1)); |
1272 | intel_ring_emit_reg(ring, INSTPM); |
1282 | intel_ring_emit_reg(ring, INSTPM); |
1273 | intel_ring_emit(ring, instp_mask << 16 | instp_mode); |
1283 | intel_ring_emit(ring, instp_mask << 16 | instp_mode); |
1274 | intel_ring_advance(ring); |
1284 | intel_ring_advance(ring); |
1275 | 1285 | ||
1276 | dev_priv->relative_constants_mode = instp_mode; |
1286 | dev_priv->relative_constants_mode = instp_mode; |
1277 | } |
1287 | } |
1278 | 1288 | ||
1279 | if (args->flags & I915_EXEC_GEN7_SOL_RESET) { |
1289 | if (args->flags & I915_EXEC_GEN7_SOL_RESET) { |
1280 | ret = i915_reset_gen7_sol_offsets(dev, params->request); |
1290 | ret = i915_reset_gen7_sol_offsets(dev, params->request); |
1281 | if (ret) |
1291 | if (ret) |
1282 | return ret; |
1292 | return ret; |
1283 | } |
1293 | } |
1284 | 1294 | ||
1285 | exec_len = args->batch_len; |
1295 | exec_len = args->batch_len; |
1286 | exec_start = params->batch_obj_vm_offset + |
1296 | exec_start = params->batch_obj_vm_offset + |
1287 | params->args_batch_start_offset; |
1297 | params->args_batch_start_offset; |
- | 1298 | ||
- | 1299 | if (exec_len == 0) |
|
- | 1300 | exec_len = params->batch_obj->base.size; |
|
1288 | 1301 | ||
1289 | ret = ring->dispatch_execbuffer(params->request, |
1302 | ret = ring->dispatch_execbuffer(params->request, |
1290 | exec_start, exec_len, |
1303 | exec_start, exec_len, |
1291 | params->dispatch_flags); |
1304 | params->dispatch_flags); |
1292 | if (ret) |
1305 | if (ret) |
1293 | return ret; |
1306 | return ret; |
1294 | 1307 | ||
1295 | trace_i915_gem_ring_dispatch(params->request, params->dispatch_flags); |
1308 | trace_i915_gem_ring_dispatch(params->request, params->dispatch_flags); |
1296 | 1309 | ||
1297 | i915_gem_execbuffer_move_to_active(vmas, params->request); |
1310 | i915_gem_execbuffer_move_to_active(vmas, params->request); |
1298 | i915_gem_execbuffer_retire_commands(params); |
1311 | i915_gem_execbuffer_retire_commands(params); |
1299 | 1312 | ||
1300 | return 0; |
1313 | return 0; |
1301 | } |
1314 | } |
1302 | 1315 | ||
1303 | /** |
1316 | /** |
1304 | * Find one BSD ring to dispatch the corresponding BSD command. |
1317 | * Find one BSD ring to dispatch the corresponding BSD command. |
1305 | * The Ring ID is returned. |
1318 | * The ring index is returned. |
1306 | */ |
1319 | */ |
1307 | static int gen8_dispatch_bsd_ring(struct drm_device *dev, |
1320 | static unsigned int |
1308 | struct drm_file *file) |
1321 | gen8_dispatch_bsd_ring(struct drm_i915_private *dev_priv, struct drm_file *file) |
1309 | { |
1322 | { |
1310 | struct drm_i915_private *dev_priv = dev->dev_private; |
- | |
1311 | struct drm_i915_file_private *file_priv = file->driver_priv; |
1323 | struct drm_i915_file_private *file_priv = file->driver_priv; |
1312 | 1324 | ||
1313 | /* Check whether the file_priv is using one ring */ |
1325 | /* Check whether the file_priv has already selected one ring. */ |
1314 | if (file_priv->bsd_ring) |
- | |
1315 | return file_priv->bsd_ring->id; |
- | |
1316 | else { |
1326 | if ((int)file_priv->bsd_ring < 0) { |
1317 | /* If no, use the ping-pong mechanism to select one ring */ |
- | |
1318 | int ring_id; |
- | |
1319 | 1327 | /* If not, use the ping-pong mechanism to select one. */ |
|
1320 | mutex_lock(&dev->struct_mutex); |
1328 | mutex_lock(&dev_priv->dev->struct_mutex); |
1321 | if (dev_priv->mm.bsd_ring_dispatch_index == 0) { |
- | |
1322 | ring_id = VCS; |
1329 | file_priv->bsd_ring = dev_priv->mm.bsd_ring_dispatch_index; |
1323 | dev_priv->mm.bsd_ring_dispatch_index = 1; |
- | |
1324 | } else { |
- | |
1325 | ring_id = VCS2; |
- | |
1326 | dev_priv->mm.bsd_ring_dispatch_index = 0; |
- | |
1327 | } |
- | |
1328 | file_priv->bsd_ring = &dev_priv->ring[ring_id]; |
1330 | dev_priv->mm.bsd_ring_dispatch_index ^= 1; |
1329 | mutex_unlock(&dev->struct_mutex); |
- | |
1330 | return ring_id; |
1331 | mutex_unlock(&dev_priv->dev->struct_mutex); |
- | 1332 | } |
|
- | 1333 | ||
1331 | } |
1334 | return file_priv->bsd_ring; |
1332 | } |
1335 | } |
1333 | 1336 | ||
1334 | static struct drm_i915_gem_object * |
1337 | static struct drm_i915_gem_object * |
1335 | eb_get_batch(struct eb_vmas *eb) |
1338 | eb_get_batch(struct eb_vmas *eb) |
1336 | { |
1339 | { |
1337 | struct i915_vma *vma = list_entry(eb->vmas.prev, typeof(*vma), exec_list); |
1340 | struct i915_vma *vma = list_entry(eb->vmas.prev, typeof(*vma), exec_list); |
1338 | 1341 | ||
1339 | /* |
1342 | /* |
1340 | * SNA is doing fancy tricks with compressing batch buffers, which leads |
1343 | * SNA is doing fancy tricks with compressing batch buffers, which leads |
1341 | * to negative relocation deltas. Usually that works out ok since the |
1344 | * to negative relocation deltas. Usually that works out ok since the |
1342 | * relocate address is still positive, except when the batch is placed |
1345 | * relocate address is still positive, except when the batch is placed |
1343 | * very low in the GTT. Ensure this doesn't happen. |
1346 | * very low in the GTT. Ensure this doesn't happen. |
1344 | * |
1347 | * |
1345 | * Note that actual hangs have only been observed on gen7, but for |
1348 | * Note that actual hangs have only been observed on gen7, but for |
1346 | * paranoia do it everywhere. |
1349 | * paranoia do it everywhere. |
1347 | */ |
1350 | */ |
1348 | if ((vma->exec_entry->flags & EXEC_OBJECT_PINNED) == 0) |
1351 | if ((vma->exec_entry->flags & EXEC_OBJECT_PINNED) == 0) |
1349 | vma->exec_entry->flags |= __EXEC_OBJECT_NEEDS_BIAS; |
1352 | vma->exec_entry->flags |= __EXEC_OBJECT_NEEDS_BIAS; |
1350 | 1353 | ||
1351 | return vma->obj; |
1354 | return vma->obj; |
1352 | } |
1355 | } |
- | 1356 | ||
- | 1357 | #define I915_USER_RINGS (4) |
|
- | 1358 | ||
- | 1359 | static const enum intel_ring_id user_ring_map[I915_USER_RINGS + 1] = { |
|
- | 1360 | [I915_EXEC_DEFAULT] = RCS, |
|
- | 1361 | [I915_EXEC_RENDER] = RCS, |
|
- | 1362 | [I915_EXEC_BLT] = BCS, |
|
- | 1363 | [I915_EXEC_BSD] = VCS, |
|
- | 1364 | [I915_EXEC_VEBOX] = VECS |
|
- | 1365 | }; |
|
- | 1366 | ||
- | 1367 | static int |
|
- | 1368 | eb_select_ring(struct drm_i915_private *dev_priv, |
|
- | 1369 | struct drm_file *file, |
|
- | 1370 | struct drm_i915_gem_execbuffer2 *args, |
|
- | 1371 | struct intel_engine_cs **ring) |
|
- | 1372 | { |
|
- | 1373 | unsigned int user_ring_id = args->flags & I915_EXEC_RING_MASK; |
|
- | 1374 | ||
- | 1375 | if (user_ring_id > I915_USER_RINGS) { |
|
- | 1376 | DRM_DEBUG("execbuf with unknown ring: %u\n", user_ring_id); |
|
- | 1377 | return -EINVAL; |
|
- | 1378 | } |
|
- | 1379 | ||
- | 1380 | if ((user_ring_id != I915_EXEC_BSD) && |
|
- | 1381 | ((args->flags & I915_EXEC_BSD_MASK) != 0)) { |
|
- | 1382 | DRM_DEBUG("execbuf with non bsd ring but with invalid " |
|
- | 1383 | "bsd dispatch flags: %d\n", (int)(args->flags)); |
|
- | 1384 | return -EINVAL; |
|
- | 1385 | } |
|
- | 1386 | ||
- | 1387 | if (user_ring_id == I915_EXEC_BSD && HAS_BSD2(dev_priv)) { |
|
- | 1388 | unsigned int bsd_idx = args->flags & I915_EXEC_BSD_MASK; |
|
- | 1389 | ||
- | 1390 | if (bsd_idx == I915_EXEC_BSD_DEFAULT) { |
|
- | 1391 | bsd_idx = gen8_dispatch_bsd_ring(dev_priv, file); |
|
- | 1392 | } else if (bsd_idx >= I915_EXEC_BSD_RING1 && |
|
- | 1393 | bsd_idx <= I915_EXEC_BSD_RING2) { |
|
- | 1394 | bsd_idx >>= I915_EXEC_BSD_SHIFT; |
|
- | 1395 | bsd_idx--; |
|
- | 1396 | } else { |
|
- | 1397 | DRM_DEBUG("execbuf with unknown bsd ring: %u\n", |
|
- | 1398 | bsd_idx); |
|
- | 1399 | return -EINVAL; |
|
- | 1400 | } |
|
- | 1401 | ||
- | 1402 | *ring = &dev_priv->ring[_VCS(bsd_idx)]; |
|
- | 1403 | } else { |
|
- | 1404 | *ring = &dev_priv->ring[user_ring_map[user_ring_id]]; |
|
- | 1405 | } |
|
- | 1406 | ||
- | 1407 | if (!intel_ring_initialized(*ring)) { |
|
- | 1408 | DRM_DEBUG("execbuf with invalid ring: %u\n", user_ring_id); |
|
- | 1409 | return -EINVAL; |
|
- | 1410 | } |
|
- | 1411 | ||
- | 1412 | return 0; |
|
- | 1413 | } |
|
1353 | 1414 | ||
1354 | static int |
1415 | static int |
1355 | i915_gem_do_execbuffer(struct drm_device *dev, void *data, |
1416 | i915_gem_do_execbuffer(struct drm_device *dev, void *data, |
1356 | struct drm_file *file, |
1417 | struct drm_file *file, |
1357 | struct drm_i915_gem_execbuffer2 *args, |
1418 | struct drm_i915_gem_execbuffer2 *args, |
1358 | struct drm_i915_gem_exec_object2 *exec) |
1419 | struct drm_i915_gem_exec_object2 *exec) |
1359 | { |
1420 | { |
1360 | struct drm_i915_private *dev_priv = dev->dev_private; |
1421 | struct drm_i915_private *dev_priv = dev->dev_private; |
- | 1422 | struct drm_i915_gem_request *req = NULL; |
|
1361 | struct eb_vmas *eb; |
1423 | struct eb_vmas *eb; |
1362 | struct drm_i915_gem_object *batch_obj; |
1424 | struct drm_i915_gem_object *batch_obj; |
1363 | struct drm_i915_gem_exec_object2 shadow_exec_entry; |
1425 | struct drm_i915_gem_exec_object2 shadow_exec_entry; |
1364 | struct intel_engine_cs *ring; |
1426 | struct intel_engine_cs *ring; |
1365 | struct intel_context *ctx; |
1427 | struct intel_context *ctx; |
1366 | struct i915_address_space *vm; |
1428 | struct i915_address_space *vm; |
1367 | struct i915_execbuffer_params params_master; /* XXX: will be removed later */ |
1429 | struct i915_execbuffer_params params_master; /* XXX: will be removed later */ |
1368 | struct i915_execbuffer_params *params = ¶ms_master; |
1430 | struct i915_execbuffer_params *params = ¶ms_master; |
1369 | const u32 ctx_id = i915_execbuffer2_get_context_id(*args); |
1431 | const u32 ctx_id = i915_execbuffer2_get_context_id(*args); |
1370 | u32 dispatch_flags; |
1432 | u32 dispatch_flags; |
1371 | int ret; |
1433 | int ret; |
1372 | bool need_relocs; |
1434 | bool need_relocs; |
1373 | 1435 | ||
1374 | if (!i915_gem_check_execbuffer(args)) |
1436 | if (!i915_gem_check_execbuffer(args)) |
1375 | return -EINVAL; |
1437 | return -EINVAL; |
1376 | 1438 | ||
1377 | ret = validate_exec_list(dev, exec, args->buffer_count); |
1439 | ret = validate_exec_list(dev, exec, args->buffer_count); |
1378 | if (ret) |
1440 | if (ret) |
1379 | return ret; |
1441 | return ret; |
1380 | 1442 | ||
1381 | dispatch_flags = 0; |
1443 | dispatch_flags = 0; |
1382 | if (args->flags & I915_EXEC_SECURE) { |
1444 | if (args->flags & I915_EXEC_SECURE) { |
1383 | 1445 | ||
1384 | dispatch_flags |= I915_DISPATCH_SECURE; |
1446 | dispatch_flags |= I915_DISPATCH_SECURE; |
1385 | } |
1447 | } |
1386 | if (args->flags & I915_EXEC_IS_PINNED) |
1448 | if (args->flags & I915_EXEC_IS_PINNED) |
1387 | dispatch_flags |= I915_DISPATCH_PINNED; |
1449 | dispatch_flags |= I915_DISPATCH_PINNED; |
1388 | - | ||
1389 | if ((args->flags & I915_EXEC_RING_MASK) > LAST_USER_RING) { |
- | |
1390 | DRM_DEBUG("execbuf with unknown ring: %d\n", |
- | |
1391 | (int)(args->flags & I915_EXEC_RING_MASK)); |
- | |
1392 | return -EINVAL; |
- | |
1393 | } |
- | |
1394 | - | ||
1395 | if (((args->flags & I915_EXEC_RING_MASK) != I915_EXEC_BSD) && |
- | |
1396 | ((args->flags & I915_EXEC_BSD_MASK) != 0)) { |
- | |
1397 | DRM_DEBUG("execbuf with non bsd ring but with invalid " |
1450 | |
1398 | "bsd dispatch flags: %d\n", (int)(args->flags)); |
- | |
1399 | return -EINVAL; |
- | |
1400 | } |
- | |
1401 | - | ||
1402 | if ((args->flags & I915_EXEC_RING_MASK) == I915_EXEC_DEFAULT) |
- | |
1403 | ring = &dev_priv->ring[RCS]; |
- | |
1404 | else if ((args->flags & I915_EXEC_RING_MASK) == I915_EXEC_BSD) { |
- | |
1405 | if (HAS_BSD2(dev)) { |
- | |
1406 | int ring_id; |
- | |
1407 | - | ||
1408 | switch (args->flags & I915_EXEC_BSD_MASK) { |
- | |
1409 | case I915_EXEC_BSD_DEFAULT: |
- | |
1410 | ring_id = gen8_dispatch_bsd_ring(dev, file); |
- | |
1411 | ring = &dev_priv->ring[ring_id]; |
- | |
1412 | break; |
- | |
1413 | case I915_EXEC_BSD_RING1: |
- | |
1414 | ring = &dev_priv->ring[VCS]; |
- | |
1415 | break; |
- | |
1416 | case I915_EXEC_BSD_RING2: |
- | |
1417 | ring = &dev_priv->ring[VCS2]; |
1451 | ret = eb_select_ring(dev_priv, file, args, &ring); |
1418 | break; |
- | |
1419 | default: |
- | |
1420 | DRM_DEBUG("execbuf with unknown bsd ring: %d\n", |
- | |
1421 | (int)(args->flags & I915_EXEC_BSD_MASK)); |
- | |
1422 | return -EINVAL; |
- | |
1423 | } |
- | |
1424 | } else |
- | |
1425 | ring = &dev_priv->ring[VCS]; |
- | |
1426 | } else |
- | |
1427 | ring = &dev_priv->ring[(args->flags & I915_EXEC_RING_MASK) - 1]; |
- | |
1428 | - | ||
1429 | if (!intel_ring_initialized(ring)) { |
- | |
1430 | DRM_DEBUG("execbuf with invalid ring: %d\n", |
- | |
1431 | (int)(args->flags & I915_EXEC_RING_MASK)); |
1452 | if (ret) |
1432 | return -EINVAL; |
- | |
1433 | } |
1453 | return ret; |
1434 | 1454 | ||
1435 | if (args->buffer_count < 1) { |
1455 | if (args->buffer_count < 1) { |
1436 | DRM_DEBUG("execbuf with %d buffers\n", args->buffer_count); |
1456 | DRM_DEBUG("execbuf with %d buffers\n", args->buffer_count); |
1437 | return -EINVAL; |
1457 | return -EINVAL; |
1438 | } |
1458 | } |
1439 | 1459 | ||
1440 | if (args->flags & I915_EXEC_RESOURCE_STREAMER) { |
1460 | if (args->flags & I915_EXEC_RESOURCE_STREAMER) { |
1441 | if (!HAS_RESOURCE_STREAMER(dev)) { |
1461 | if (!HAS_RESOURCE_STREAMER(dev)) { |
1442 | DRM_DEBUG("RS is only allowed for Haswell, Gen8 and above\n"); |
1462 | DRM_DEBUG("RS is only allowed for Haswell, Gen8 and above\n"); |
1443 | return -EINVAL; |
1463 | return -EINVAL; |
1444 | } |
1464 | } |
1445 | if (ring->id != RCS) { |
1465 | if (ring->id != RCS) { |
1446 | DRM_DEBUG("RS is not available on %s\n", |
1466 | DRM_DEBUG("RS is not available on %s\n", |
1447 | ring->name); |
1467 | ring->name); |
1448 | return -EINVAL; |
1468 | return -EINVAL; |
1449 | } |
1469 | } |
1450 | 1470 | ||
1451 | dispatch_flags |= I915_DISPATCH_RS; |
1471 | dispatch_flags |= I915_DISPATCH_RS; |
1452 | } |
1472 | } |
1453 | 1473 | ||
1454 | intel_runtime_pm_get(dev_priv); |
1474 | intel_runtime_pm_get(dev_priv); |
1455 | 1475 | ||
1456 | ret = i915_mutex_lock_interruptible(dev); |
1476 | ret = i915_mutex_lock_interruptible(dev); |
1457 | if (ret) |
1477 | if (ret) |
1458 | goto pre_mutex_err; |
1478 | goto pre_mutex_err; |
1459 | 1479 | ||
1460 | ctx = i915_gem_validate_context(dev, file, ring, ctx_id); |
1480 | ctx = i915_gem_validate_context(dev, file, ring, ctx_id); |
1461 | if (IS_ERR(ctx)) { |
1481 | if (IS_ERR(ctx)) { |
1462 | mutex_unlock(&dev->struct_mutex); |
1482 | mutex_unlock(&dev->struct_mutex); |
1463 | ret = PTR_ERR(ctx); |
1483 | ret = PTR_ERR(ctx); |
1464 | goto pre_mutex_err; |
1484 | goto pre_mutex_err; |
1465 | } |
1485 | } |
1466 | 1486 | ||
1467 | i915_gem_context_reference(ctx); |
1487 | i915_gem_context_reference(ctx); |
1468 | 1488 | ||
1469 | if (ctx->ppgtt) |
1489 | if (ctx->ppgtt) |
1470 | vm = &ctx->ppgtt->base; |
1490 | vm = &ctx->ppgtt->base; |
1471 | else |
1491 | else |
1472 | vm = &dev_priv->gtt.base; |
1492 | vm = &dev_priv->gtt.base; |
1473 | 1493 | ||
1474 | memset(¶ms_master, 0x00, sizeof(params_master)); |
1494 | memset(¶ms_master, 0x00, sizeof(params_master)); |
1475 | 1495 | ||
1476 | eb = eb_create(args); |
1496 | eb = eb_create(args); |
1477 | if (eb == NULL) { |
1497 | if (eb == NULL) { |
1478 | i915_gem_context_unreference(ctx); |
1498 | i915_gem_context_unreference(ctx); |
1479 | mutex_unlock(&dev->struct_mutex); |
1499 | mutex_unlock(&dev->struct_mutex); |
1480 | ret = -ENOMEM; |
1500 | ret = -ENOMEM; |
1481 | goto pre_mutex_err; |
1501 | goto pre_mutex_err; |
1482 | } |
1502 | } |
1483 | 1503 | ||
1484 | /* Look up object handles */ |
1504 | /* Look up object handles */ |
1485 | ret = eb_lookup_vmas(eb, exec, args, vm, file); |
1505 | ret = eb_lookup_vmas(eb, exec, args, vm, file); |
1486 | if (ret) |
1506 | if (ret) |
1487 | goto err; |
1507 | goto err; |
1488 | 1508 | ||
1489 | /* take note of the batch buffer before we might reorder the lists */ |
1509 | /* take note of the batch buffer before we might reorder the lists */ |
1490 | batch_obj = eb_get_batch(eb); |
1510 | batch_obj = eb_get_batch(eb); |
1491 | 1511 | ||
1492 | /* Move the objects en-masse into the GTT, evicting if necessary. */ |
1512 | /* Move the objects en-masse into the GTT, evicting if necessary. */ |
1493 | need_relocs = (args->flags & I915_EXEC_NO_RELOC) == 0; |
1513 | need_relocs = (args->flags & I915_EXEC_NO_RELOC) == 0; |
1494 | ret = i915_gem_execbuffer_reserve(ring, &eb->vmas, ctx, &need_relocs); |
1514 | ret = i915_gem_execbuffer_reserve(ring, &eb->vmas, ctx, &need_relocs); |
1495 | if (ret) |
1515 | if (ret) |
1496 | goto err; |
1516 | goto err; |
1497 | 1517 | ||
1498 | /* The objects are in their final locations, apply the relocations. */ |
1518 | /* The objects are in their final locations, apply the relocations. */ |
1499 | if (need_relocs) |
1519 | if (need_relocs) |
1500 | ret = i915_gem_execbuffer_relocate(eb); |
1520 | ret = i915_gem_execbuffer_relocate(eb); |
1501 | if (ret) { |
1521 | if (ret) { |
1502 | if (ret == -EFAULT) { |
1522 | if (ret == -EFAULT) { |
1503 | ret = i915_gem_execbuffer_relocate_slow(dev, args, file, ring, |
1523 | ret = i915_gem_execbuffer_relocate_slow(dev, args, file, ring, |
1504 | eb, exec, ctx); |
1524 | eb, exec, ctx); |
1505 | BUG_ON(!mutex_is_locked(&dev->struct_mutex)); |
1525 | BUG_ON(!mutex_is_locked(&dev->struct_mutex)); |
1506 | } |
1526 | } |
1507 | if (ret) |
1527 | if (ret) |
1508 | goto err; |
1528 | goto err; |
1509 | } |
1529 | } |
1510 | 1530 | ||
1511 | /* Set the pending read domains for the batch buffer to COMMAND */ |
1531 | /* Set the pending read domains for the batch buffer to COMMAND */ |
1512 | if (batch_obj->base.pending_write_domain) { |
1532 | if (batch_obj->base.pending_write_domain) { |
1513 | DRM_DEBUG("Attempting to use self-modifying batch buffer\n"); |
1533 | DRM_DEBUG("Attempting to use self-modifying batch buffer\n"); |
1514 | ret = -EINVAL; |
1534 | ret = -EINVAL; |
1515 | goto err; |
1535 | goto err; |
1516 | } |
1536 | } |
1517 | 1537 | ||
1518 | params->args_batch_start_offset = args->batch_start_offset; |
1538 | params->args_batch_start_offset = args->batch_start_offset; |
1519 | 1539 | ||
1520 | #if 0 |
1540 | #if 0 |
1521 | if (i915_needs_cmd_parser(ring) && args->batch_len) { |
1541 | if (i915_needs_cmd_parser(ring) && args->batch_len) { |
1522 | struct drm_i915_gem_object *parsed_batch_obj; |
1542 | struct drm_i915_gem_object *parsed_batch_obj; |
1523 | 1543 | ||
1524 | parsed_batch_obj = i915_gem_execbuffer_parse(ring, |
1544 | parsed_batch_obj = i915_gem_execbuffer_parse(ring, |
1525 | &shadow_exec_entry, |
1545 | &shadow_exec_entry, |
1526 | eb, |
1546 | eb, |
1527 | batch_obj, |
1547 | batch_obj, |
1528 | args->batch_start_offset, |
1548 | args->batch_start_offset, |
1529 | args->batch_len, |
1549 | args->batch_len, |
1530 | file->is_master); |
1550 | file->is_master); |
1531 | if (IS_ERR(parsed_batch_obj)) { |
1551 | if (IS_ERR(parsed_batch_obj)) { |
1532 | ret = PTR_ERR(parsed_batch_obj); |
1552 | ret = PTR_ERR(parsed_batch_obj); |
1533 | goto err; |
1553 | goto err; |
1534 | } |
1554 | } |
1535 | 1555 | ||
1536 | /* |
1556 | /* |
1537 | * parsed_batch_obj == batch_obj means batch not fully parsed: |
1557 | * parsed_batch_obj == batch_obj means batch not fully parsed: |
1538 | * Accept, but don't promote to secure. |
1558 | * Accept, but don't promote to secure. |
1539 | */ |
1559 | */ |
1540 | 1560 | ||
1541 | if (parsed_batch_obj != batch_obj) { |
1561 | if (parsed_batch_obj != batch_obj) { |
1542 | /* |
1562 | /* |
1543 | * Batch parsed and accepted: |
1563 | * Batch parsed and accepted: |
1544 | * |
1564 | * |
1545 | * Set the DISPATCH_SECURE bit to remove the NON_SECURE |
1565 | * Set the DISPATCH_SECURE bit to remove the NON_SECURE |
1546 | * bit from MI_BATCH_BUFFER_START commands issued in |
1566 | * bit from MI_BATCH_BUFFER_START commands issued in |
1547 | * the dispatch_execbuffer implementations. We |
1567 | * the dispatch_execbuffer implementations. We |
1548 | * specifically don't want that set on batches the |
1568 | * specifically don't want that set on batches the |
1549 | * command parser has accepted. |
1569 | * command parser has accepted. |
1550 | */ |
1570 | */ |
1551 | dispatch_flags |= I915_DISPATCH_SECURE; |
1571 | dispatch_flags |= I915_DISPATCH_SECURE; |
1552 | params->args_batch_start_offset = 0; |
1572 | params->args_batch_start_offset = 0; |
1553 | batch_obj = parsed_batch_obj; |
1573 | batch_obj = parsed_batch_obj; |
1554 | } |
1574 | } |
1555 | } |
1575 | } |
1556 | #endif |
1576 | #endif |
1557 | 1577 | ||
1558 | batch_obj->base.pending_read_domains |= I915_GEM_DOMAIN_COMMAND; |
1578 | batch_obj->base.pending_read_domains |= I915_GEM_DOMAIN_COMMAND; |
1559 | 1579 | ||
1560 | /* snb/ivb/vlv conflate the "batch in ppgtt" bit with the "non-secure |
1580 | /* snb/ivb/vlv conflate the "batch in ppgtt" bit with the "non-secure |
1561 | * batch" bit. Hence we need to pin secure batches into the global gtt. |
1581 | * batch" bit. Hence we need to pin secure batches into the global gtt. |
1562 | * hsw should have this fixed, but bdw mucks it up again. */ |
1582 | * hsw should have this fixed, but bdw mucks it up again. */ |
1563 | if (dispatch_flags & I915_DISPATCH_SECURE) { |
1583 | if (dispatch_flags & I915_DISPATCH_SECURE) { |
1564 | /* |
1584 | /* |
1565 | * So on first glance it looks freaky that we pin the batch here |
1585 | * So on first glance it looks freaky that we pin the batch here |
1566 | * outside of the reservation loop. But: |
1586 | * outside of the reservation loop. But: |
1567 | * - The batch is already pinned into the relevant ppgtt, so we |
1587 | * - The batch is already pinned into the relevant ppgtt, so we |
1568 | * already have the backing storage fully allocated. |
1588 | * already have the backing storage fully allocated. |
1569 | * - No other BO uses the global gtt (well contexts, but meh), |
1589 | * - No other BO uses the global gtt (well contexts, but meh), |
1570 | * so we don't really have issues with multiple objects not |
1590 | * so we don't really have issues with multiple objects not |
1571 | * fitting due to fragmentation. |
1591 | * fitting due to fragmentation. |
1572 | * So this is actually safe. |
1592 | * So this is actually safe. |
1573 | */ |
1593 | */ |
1574 | ret = i915_gem_obj_ggtt_pin(batch_obj, 0, 0); |
1594 | ret = i915_gem_obj_ggtt_pin(batch_obj, 0, 0); |
1575 | if (ret) |
1595 | if (ret) |
1576 | goto err; |
1596 | goto err; |
1577 | 1597 | ||
1578 | params->batch_obj_vm_offset = i915_gem_obj_ggtt_offset(batch_obj); |
1598 | params->batch_obj_vm_offset = i915_gem_obj_ggtt_offset(batch_obj); |
1579 | } else |
1599 | } else |
1580 | params->batch_obj_vm_offset = i915_gem_obj_offset(batch_obj, vm); |
1600 | params->batch_obj_vm_offset = i915_gem_obj_offset(batch_obj, vm); |
1581 | 1601 | ||
1582 | /* Allocate a request for this batch buffer nice and early. */ |
1602 | /* Allocate a request for this batch buffer nice and early. */ |
1583 | ret = i915_gem_request_alloc(ring, ctx, ¶ms->request); |
1603 | req = i915_gem_request_alloc(ring, ctx); |
1584 | if (ret) |
1604 | if (IS_ERR(req)) { |
- | 1605 | ret = PTR_ERR(req); |
|
1585 | goto err_batch_unpin; |
1606 | goto err_batch_unpin; |
- | 1607 | } |
|
1586 | 1608 | ||
1587 | ret = i915_gem_request_add_to_client(params->request, file); |
1609 | ret = i915_gem_request_add_to_client(req, file); |
1588 | if (ret) |
1610 | if (ret) |
1589 | goto err_batch_unpin; |
1611 | goto err_batch_unpin; |
1590 | 1612 | ||
1591 | /* |
1613 | /* |
1592 | * Save assorted stuff away to pass through to *_submission(). |
1614 | * Save assorted stuff away to pass through to *_submission(). |
1593 | * NB: This data should be 'persistent' and not local as it will |
1615 | * NB: This data should be 'persistent' and not local as it will |
1594 | * kept around beyond the duration of the IOCTL once the GPU |
1616 | * kept around beyond the duration of the IOCTL once the GPU |
1595 | * scheduler arrives. |
1617 | * scheduler arrives. |
1596 | */ |
1618 | */ |
1597 | params->dev = dev; |
1619 | params->dev = dev; |
1598 | params->file = file; |
1620 | params->file = file; |
1599 | params->ring = ring; |
1621 | params->ring = ring; |
1600 | params->dispatch_flags = dispatch_flags; |
1622 | params->dispatch_flags = dispatch_flags; |
1601 | params->batch_obj = batch_obj; |
1623 | params->batch_obj = batch_obj; |
1602 | params->ctx = ctx; |
1624 | params->ctx = ctx; |
- | 1625 | params->request = req; |
|
1603 | 1626 | ||
1604 | ret = dev_priv->gt.execbuf_submit(params, args, &eb->vmas); |
1627 | ret = dev_priv->gt.execbuf_submit(params, args, &eb->vmas); |
1605 | 1628 | ||
1606 | err_batch_unpin: |
1629 | err_batch_unpin: |
1607 | /* |
1630 | /* |
1608 | * FIXME: We crucially rely upon the active tracking for the (ppgtt) |
1631 | * FIXME: We crucially rely upon the active tracking for the (ppgtt) |
1609 | * batch vma for correctness. For less ugly and less fragility this |
1632 | * batch vma for correctness. For less ugly and less fragility this |
1610 | * needs to be adjusted to also track the ggtt batch vma properly as |
1633 | * needs to be adjusted to also track the ggtt batch vma properly as |
1611 | * active. |
1634 | * active. |
1612 | */ |
1635 | */ |
1613 | if (dispatch_flags & I915_DISPATCH_SECURE) |
1636 | if (dispatch_flags & I915_DISPATCH_SECURE) |
1614 | i915_gem_object_ggtt_unpin(batch_obj); |
1637 | i915_gem_object_ggtt_unpin(batch_obj); |
1615 | 1638 | ||
1616 | err: |
1639 | err: |
1617 | /* the request owns the ref now */ |
1640 | /* the request owns the ref now */ |
1618 | i915_gem_context_unreference(ctx); |
1641 | i915_gem_context_unreference(ctx); |
1619 | eb_destroy(eb); |
1642 | eb_destroy(eb); |
1620 | 1643 | ||
1621 | /* |
1644 | /* |
1622 | * If the request was created but not successfully submitted then it |
1645 | * If the request was created but not successfully submitted then it |
1623 | * must be freed again. If it was submitted then it is being tracked |
1646 | * must be freed again. If it was submitted then it is being tracked |
1624 | * on the active request list and no clean up is required here. |
1647 | * on the active request list and no clean up is required here. |
1625 | */ |
1648 | */ |
1626 | if (ret && params->request) |
1649 | if (ret && !IS_ERR_OR_NULL(req)) |
1627 | i915_gem_request_cancel(params->request); |
1650 | i915_gem_request_cancel(req); |
1628 | 1651 | ||
1629 | mutex_unlock(&dev->struct_mutex); |
1652 | mutex_unlock(&dev->struct_mutex); |
1630 | 1653 | ||
1631 | pre_mutex_err: |
1654 | pre_mutex_err: |
1632 | /* intel_gpu_busy should also get a ref, so it will free when the device |
1655 | /* intel_gpu_busy should also get a ref, so it will free when the device |
1633 | * is really idle. */ |
1656 | * is really idle. */ |
1634 | intel_runtime_pm_put(dev_priv); |
1657 | intel_runtime_pm_put(dev_priv); |
1635 | return ret; |
1658 | return ret; |
1636 | } |
1659 | } |
1637 | 1660 | ||
1638 | #if 0 |
1661 | #if 0 |
1639 | /* |
1662 | /* |
1640 | * Legacy execbuffer just creates an exec2 list from the original exec object |
1663 | * Legacy execbuffer just creates an exec2 list from the original exec object |
1641 | * list array and passes it to the real function. |
1664 | * list array and passes it to the real function. |
1642 | */ |
1665 | */ |
1643 | int |
1666 | int |
1644 | i915_gem_execbuffer(struct drm_device *dev, void *data, |
1667 | i915_gem_execbuffer(struct drm_device *dev, void *data, |
1645 | struct drm_file *file) |
1668 | struct drm_file *file) |
1646 | { |
1669 | { |
1647 | struct drm_i915_gem_execbuffer *args = data; |
1670 | struct drm_i915_gem_execbuffer *args = data; |
1648 | struct drm_i915_gem_execbuffer2 exec2; |
1671 | struct drm_i915_gem_execbuffer2 exec2; |
1649 | struct drm_i915_gem_exec_object *exec_list = NULL; |
1672 | struct drm_i915_gem_exec_object *exec_list = NULL; |
1650 | struct drm_i915_gem_exec_object2 *exec2_list = NULL; |
1673 | struct drm_i915_gem_exec_object2 *exec2_list = NULL; |
1651 | int ret, i; |
1674 | int ret, i; |
1652 | 1675 | ||
1653 | if (args->buffer_count < 1) { |
1676 | if (args->buffer_count < 1) { |
1654 | DRM_DEBUG("execbuf with %d buffers\n", args->buffer_count); |
1677 | DRM_DEBUG("execbuf with %d buffers\n", args->buffer_count); |
1655 | return -EINVAL; |
1678 | return -EINVAL; |
1656 | } |
1679 | } |
1657 | 1680 | ||
1658 | /* Copy in the exec list from userland */ |
1681 | /* Copy in the exec list from userland */ |
1659 | exec_list = drm_malloc_ab(sizeof(*exec_list), args->buffer_count); |
1682 | exec_list = drm_malloc_ab(sizeof(*exec_list), args->buffer_count); |
1660 | exec2_list = drm_malloc_ab(sizeof(*exec2_list), args->buffer_count); |
1683 | exec2_list = drm_malloc_ab(sizeof(*exec2_list), args->buffer_count); |
1661 | if (exec_list == NULL || exec2_list == NULL) { |
1684 | if (exec_list == NULL || exec2_list == NULL) { |
1662 | DRM_DEBUG("Failed to allocate exec list for %d buffers\n", |
1685 | DRM_DEBUG("Failed to allocate exec list for %d buffers\n", |
1663 | args->buffer_count); |
1686 | args->buffer_count); |
1664 | drm_free_large(exec_list); |
1687 | drm_free_large(exec_list); |
1665 | drm_free_large(exec2_list); |
1688 | drm_free_large(exec2_list); |
1666 | return -ENOMEM; |
1689 | return -ENOMEM; |
1667 | } |
1690 | } |
1668 | ret = copy_from_user(exec_list, |
1691 | ret = copy_from_user(exec_list, |
1669 | to_user_ptr(args->buffers_ptr), |
1692 | to_user_ptr(args->buffers_ptr), |
1670 | sizeof(*exec_list) * args->buffer_count); |
1693 | sizeof(*exec_list) * args->buffer_count); |
1671 | if (ret != 0) { |
1694 | if (ret != 0) { |
1672 | DRM_DEBUG("copy %d exec entries failed %d\n", |
1695 | DRM_DEBUG("copy %d exec entries failed %d\n", |
1673 | args->buffer_count, ret); |
1696 | args->buffer_count, ret); |
1674 | drm_free_large(exec_list); |
1697 | drm_free_large(exec_list); |
1675 | drm_free_large(exec2_list); |
1698 | drm_free_large(exec2_list); |
1676 | return -EFAULT; |
1699 | return -EFAULT; |
1677 | } |
1700 | } |
1678 | 1701 | ||
1679 | for (i = 0; i < args->buffer_count; i++) { |
1702 | for (i = 0; i < args->buffer_count; i++) { |
1680 | exec2_list[i].handle = exec_list[i].handle; |
1703 | exec2_list[i].handle = exec_list[i].handle; |
1681 | exec2_list[i].relocation_count = exec_list[i].relocation_count; |
1704 | exec2_list[i].relocation_count = exec_list[i].relocation_count; |
1682 | exec2_list[i].relocs_ptr = exec_list[i].relocs_ptr; |
1705 | exec2_list[i].relocs_ptr = exec_list[i].relocs_ptr; |
1683 | exec2_list[i].alignment = exec_list[i].alignment; |
1706 | exec2_list[i].alignment = exec_list[i].alignment; |
1684 | exec2_list[i].offset = exec_list[i].offset; |
1707 | exec2_list[i].offset = exec_list[i].offset; |
1685 | if (INTEL_INFO(dev)->gen < 4) |
1708 | if (INTEL_INFO(dev)->gen < 4) |
1686 | exec2_list[i].flags = EXEC_OBJECT_NEEDS_FENCE; |
1709 | exec2_list[i].flags = EXEC_OBJECT_NEEDS_FENCE; |
1687 | else |
1710 | else |
1688 | exec2_list[i].flags = 0; |
1711 | exec2_list[i].flags = 0; |
1689 | } |
1712 | } |
1690 | 1713 | ||
1691 | exec2.buffers_ptr = args->buffers_ptr; |
1714 | exec2.buffers_ptr = args->buffers_ptr; |
1692 | exec2.buffer_count = args->buffer_count; |
1715 | exec2.buffer_count = args->buffer_count; |
1693 | exec2.batch_start_offset = args->batch_start_offset; |
1716 | exec2.batch_start_offset = args->batch_start_offset; |
1694 | exec2.batch_len = args->batch_len; |
1717 | exec2.batch_len = args->batch_len; |
1695 | exec2.DR1 = args->DR1; |
1718 | exec2.DR1 = args->DR1; |
1696 | exec2.DR4 = args->DR4; |
1719 | exec2.DR4 = args->DR4; |
1697 | exec2.num_cliprects = args->num_cliprects; |
1720 | exec2.num_cliprects = args->num_cliprects; |
1698 | exec2.cliprects_ptr = args->cliprects_ptr; |
1721 | exec2.cliprects_ptr = args->cliprects_ptr; |
1699 | exec2.flags = I915_EXEC_RENDER; |
1722 | exec2.flags = I915_EXEC_RENDER; |
1700 | i915_execbuffer2_set_context_id(exec2, 0); |
1723 | i915_execbuffer2_set_context_id(exec2, 0); |
1701 | 1724 | ||
1702 | ret = i915_gem_do_execbuffer(dev, data, file, &exec2, exec2_list); |
1725 | ret = i915_gem_do_execbuffer(dev, data, file, &exec2, exec2_list); |
1703 | if (!ret) { |
1726 | if (!ret) { |
1704 | struct drm_i915_gem_exec_object __user *user_exec_list = |
1727 | struct drm_i915_gem_exec_object __user *user_exec_list = |
1705 | to_user_ptr(args->buffers_ptr); |
1728 | to_user_ptr(args->buffers_ptr); |
1706 | 1729 | ||
1707 | /* Copy the new buffer offsets back to the user's exec list. */ |
1730 | /* Copy the new buffer offsets back to the user's exec list. */ |
1708 | for (i = 0; i < args->buffer_count; i++) { |
1731 | for (i = 0; i < args->buffer_count; i++) { |
1709 | exec2_list[i].offset = |
1732 | exec2_list[i].offset = |
1710 | gen8_canonical_addr(exec2_list[i].offset); |
1733 | gen8_canonical_addr(exec2_list[i].offset); |
1711 | ret = __copy_to_user(&user_exec_list[i].offset, |
1734 | ret = __copy_to_user(&user_exec_list[i].offset, |
1712 | &exec2_list[i].offset, |
1735 | &exec2_list[i].offset, |
1713 | sizeof(user_exec_list[i].offset)); |
1736 | sizeof(user_exec_list[i].offset)); |
1714 | if (ret) { |
1737 | if (ret) { |
1715 | ret = -EFAULT; |
1738 | ret = -EFAULT; |
1716 | DRM_DEBUG("failed to copy %d exec entries " |
1739 | DRM_DEBUG("failed to copy %d exec entries " |
1717 | "back to user (%d)\n", |
1740 | "back to user (%d)\n", |
1718 | args->buffer_count, ret); |
1741 | args->buffer_count, ret); |
1719 | break; |
1742 | break; |
1720 | } |
1743 | } |
1721 | } |
1744 | } |
1722 | } |
1745 | } |
1723 | 1746 | ||
1724 | drm_free_large(exec_list); |
1747 | drm_free_large(exec_list); |
1725 | drm_free_large(exec2_list); |
1748 | drm_free_large(exec2_list); |
1726 | return ret; |
1749 | return ret; |
1727 | } |
1750 | } |
1728 | #endif |
1751 | #endif |
1729 | 1752 | ||
1730 | int |
1753 | int |
1731 | i915_gem_execbuffer2(struct drm_device *dev, void *data, |
1754 | i915_gem_execbuffer2(struct drm_device *dev, void *data, |
1732 | struct drm_file *file) |
1755 | struct drm_file *file) |
1733 | { |
1756 | { |
1734 | struct drm_i915_gem_execbuffer2 *args = data; |
1757 | struct drm_i915_gem_execbuffer2 *args = data; |
1735 | struct drm_i915_gem_exec_object2 *exec2_list = NULL; |
1758 | struct drm_i915_gem_exec_object2 *exec2_list = NULL; |
1736 | int ret; |
1759 | int ret; |
1737 | 1760 | ||
1738 | if (args->buffer_count < 1 || |
1761 | if (args->buffer_count < 1 || |
1739 | args->buffer_count > UINT_MAX / sizeof(*exec2_list)) { |
1762 | args->buffer_count > UINT_MAX / sizeof(*exec2_list)) { |
1740 | DRM_DEBUG("execbuf2 with %d buffers\n", args->buffer_count); |
1763 | DRM_DEBUG("execbuf2 with %d buffers\n", args->buffer_count); |
1741 | return -EINVAL; |
1764 | return -EINVAL; |
1742 | } |
1765 | } |
1743 | 1766 | ||
1744 | if (args->rsvd2 != 0) { |
1767 | if (args->rsvd2 != 0) { |
1745 | DRM_DEBUG("dirty rvsd2 field\n"); |
1768 | DRM_DEBUG("dirty rvsd2 field\n"); |
1746 | return -EINVAL; |
1769 | return -EINVAL; |
1747 | } |
1770 | } |
1748 | 1771 | ||
1749 | exec2_list = kmalloc(sizeof(*exec2_list)*args->buffer_count, |
1772 | exec2_list = kmalloc(sizeof(*exec2_list)*args->buffer_count, |
1750 | GFP_TEMPORARY | __GFP_NOWARN | __GFP_NORETRY); |
1773 | GFP_TEMPORARY | __GFP_NOWARN | __GFP_NORETRY); |
1751 | if (exec2_list == NULL) { |
1774 | if (exec2_list == NULL) { |
1752 | DRM_DEBUG("Failed to allocate exec list for %d buffers\n", |
1775 | DRM_DEBUG("Failed to allocate exec list for %d buffers\n", |
1753 | args->buffer_count); |
1776 | args->buffer_count); |
1754 | return -ENOMEM; |
1777 | return -ENOMEM; |
1755 | } |
1778 | } |
1756 | ret = copy_from_user(exec2_list, |
1779 | ret = copy_from_user(exec2_list, |
1757 | to_user_ptr(args->buffers_ptr), |
1780 | to_user_ptr(args->buffers_ptr), |
1758 | sizeof(*exec2_list) * args->buffer_count); |
1781 | sizeof(*exec2_list) * args->buffer_count); |
1759 | if (ret != 0) { |
1782 | if (ret != 0) { |
1760 | DRM_DEBUG("copy %d exec entries failed %d\n", |
1783 | DRM_DEBUG("copy %d exec entries failed %d\n", |
1761 | args->buffer_count, ret); |
1784 | args->buffer_count, ret); |
1762 | kfree(exec2_list); |
1785 | kfree(exec2_list); |
1763 | FAIL(); |
1786 | FAIL(); |
1764 | return -EFAULT; |
1787 | return -EFAULT; |
1765 | } |
1788 | } |
1766 | 1789 | ||
1767 | ret = i915_gem_do_execbuffer(dev, data, file, args, exec2_list); |
1790 | ret = i915_gem_do_execbuffer(dev, data, file, args, exec2_list); |
1768 | if (!ret) { |
1791 | if (!ret) { |
1769 | /* Copy the new buffer offsets back to the user's exec list. */ |
1792 | /* Copy the new buffer offsets back to the user's exec list. */ |
1770 | struct drm_i915_gem_exec_object2 __user *user_exec_list = |
1793 | struct drm_i915_gem_exec_object2 __user *user_exec_list = |
1771 | to_user_ptr(args->buffers_ptr); |
1794 | to_user_ptr(args->buffers_ptr); |
1772 | int i; |
1795 | int i; |
1773 | 1796 | ||
1774 | for (i = 0; i < args->buffer_count; i++) { |
1797 | for (i = 0; i < args->buffer_count; i++) { |
1775 | exec2_list[i].offset = |
1798 | exec2_list[i].offset = |
1776 | gen8_canonical_addr(exec2_list[i].offset); |
1799 | gen8_canonical_addr(exec2_list[i].offset); |
1777 | ret = __copy_to_user(&user_exec_list[i].offset, |
1800 | ret = __copy_to_user(&user_exec_list[i].offset, |
1778 | &exec2_list[i].offset, |
1801 | &exec2_list[i].offset, |
1779 | sizeof(user_exec_list[i].offset)); |
1802 | sizeof(user_exec_list[i].offset)); |
1780 | if (ret) { |
1803 | if (ret) { |
1781 | ret = -EFAULT; |
1804 | ret = -EFAULT; |
1782 | DRM_DEBUG("failed to copy %d exec entries " |
1805 | DRM_DEBUG("failed to copy %d exec entries " |
1783 | "back to user\n", |
1806 | "back to user\n", |
1784 | args->buffer_count); |
1807 | args->buffer_count); |
1785 | break; |
1808 | break; |
1786 | } |
1809 | } |
1787 | } |
1810 | } |
1788 | } |
1811 | } |
1789 | 1812 | ||
1790 | kfree(exec2_list); |
1813 | kfree(exec2_list); |
1791 | return ret; |
1814 | return ret; |
1792 | }>>>>>>>><>> |
1815 | }>>>>>>>=>>><>> |
1793 | 1816 | ||
1794 | #define><28) |
1817 | #define><28) |
1795 | 1818 | ||
1796 | #define>29) |
1819 | #define>29) |
1797 | #define><29) |
1820 | #define><29) |
1798 | #define>30) |
1821 | #define>30) |
1799 | #define><30) |
1822 | #define><30) |
1800 | #define>31) |
1823 | #define>31) |
1801 | #define><31) |
1824 | #define><31) |
1802 | #define> |
1825 | #define> |