drm/i915: Remove duplicate golden render state init from execlists
[linux-block.git] / drivers / gpu / drm / i915 / i915_gem_render_state.c
CommitLineData
9d0a6fa6
MK
1/*
2 * Copyright © 2014 Intel Corporation
3 *
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
10 *
11 * The above copyright notice and this permission notice (including the next
12 * paragraph) shall be included in all copies or substantial portions of the
13 * Software.
14 *
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
21 * IN THE SOFTWARE.
22 *
23 * Authors:
24 * Mika Kuoppala <mika.kuoppala@intel.com>
25 *
26 */
27
28#include "i915_drv.h"
29#include "intel_renderstate.h"
30
e40f9ee6
CW
31struct render_state {
32 const struct intel_renderstate_rodata *rodata;
33 struct drm_i915_gem_object *obj;
34 u64 ggtt_offset;
35 int gen;
36 u32 aux_batch_size;
37 u32 aux_batch_offset;
38};
39
9d0a6fa6 40static const struct intel_renderstate_rodata *
c033666a 41render_state_get_rodata(const int gen)
9d0a6fa6
MK
42{
43 switch (gen) {
44 case 6:
45 return &gen6_null_state;
46 case 7:
47 return &gen7_null_state;
48 case 8:
49 return &gen8_null_state;
ff7a60f2
AR
50 case 9:
51 return &gen9_null_state;
9d0a6fa6
MK
52 }
53
54 return NULL;
55}
56
c033666a
CW
57static int render_state_init(struct render_state *so,
58 struct drm_i915_private *dev_priv)
9d0a6fa6 59{
9d0a6fa6
MK
60 int ret;
61
c033666a 62 so->gen = INTEL_GEN(dev_priv);
e40f9ee6 63 so->ggtt_offset = 0; /* keep gcc quiet */
c033666a 64 so->rodata = render_state_get_rodata(so->gen);
1ce826d4
CW
65 if (so->rodata == NULL)
66 return 0;
67
68 if (so->rodata->batch_items * 4 > 4096)
9d0a6fa6
MK
69 return -EINVAL;
70
91c8a326 71 so->obj = i915_gem_object_create(&dev_priv->drm, 4096);
fe3db79b
CW
72 if (IS_ERR(so->obj))
73 return PTR_ERR(so->obj);
1ce826d4
CW
74
75 ret = i915_gem_obj_ggtt_pin(so->obj, 4096, 0);
76 if (ret)
77 goto free_gem;
78
79 so->ggtt_offset = i915_gem_obj_ggtt_offset(so->obj);
80 return 0;
81
82free_gem:
f8c417cd 83 i915_gem_object_put(so->obj);
1ce826d4
CW
84 return ret;
85}
86
84e81020
AS
87/*
88 * Macro to add commands to auxiliary batch.
89 * This macro only checks for page overflow before inserting the commands,
90 * this is sufficient as the null state generator makes the final batch
91 * with two passes to build command and state separately. At this point
92 * the size of both are known and it compacts them by relocating the state
93 * right after the commands taking care of aligment so we should sufficient
94 * space below them for adding new commands.
95 */
96#define OUT_BATCH(batch, i, val) \
97 do { \
98 if (WARN_ON((i) >= PAGE_SIZE / sizeof(u32))) { \
99 ret = -ENOSPC; \
100 goto err_out; \
101 } \
102 (batch)[(i)++] = (val); \
103 } while(0)
104
1ce826d4
CW
105static int render_state_setup(struct render_state *so)
106{
33e141ed 107 struct drm_device *dev = so->obj->base.dev;
1ce826d4
CW
108 const struct intel_renderstate_rodata *rodata = so->rodata;
109 unsigned int i = 0, reloc_index = 0;
110 struct page *page;
111 u32 *d;
112 int ret;
113
9d0a6fa6
MK
114 ret = i915_gem_object_set_to_cpu_domain(so->obj, true);
115 if (ret)
116 return ret;
117
033908ae 118 page = i915_gem_object_get_dirty_page(so->obj, 0);
1ce826d4
CW
119 d = kmap(page);
120
9d0a6fa6
MK
121 while (i < rodata->batch_items) {
122 u32 s = rodata->batch[i];
123
1ce826d4
CW
124 if (i * 4 == rodata->reloc[reloc_index]) {
125 u64 r = s + so->ggtt_offset;
126 s = lower_32_bits(r);
127 if (so->gen >= 8) {
9d0a6fa6 128 if (i + 1 >= rodata->batch_items ||
dd72bde0
MK
129 rodata->batch[i + 1] != 0) {
130 ret = -EINVAL;
131 goto err_out;
132 }
9d0a6fa6 133
1ce826d4
CW
134 d[i++] = s;
135 s = upper_32_bits(r);
9d0a6fa6
MK
136 }
137
138 reloc_index++;
139 }
140
1ce826d4 141 d[i++] = s;
9d0a6fa6 142 }
84e81020
AS
143
144 while (i % CACHELINE_DWORDS)
145 OUT_BATCH(d, i, MI_NOOP);
146
147 so->aux_batch_offset = i * sizeof(u32);
148
33e141ed 149 if (HAS_POOLED_EU(dev)) {
150 /*
151 * We always program 3x6 pool config but depending upon which
152 * subslice is disabled HW drops down to appropriate config
153 * shown below.
154 *
155 * In the below table 2x6 config always refers to
156 * fused-down version, native 2x6 is not available and can
157 * be ignored
158 *
159 * SNo subslices config eu pool configuration
160 * -----------------------------------------------------------
161 * 1 3 subslices enabled (3x6) - 0x00777000 (9+9)
162 * 2 ss0 disabled (2x6) - 0x00777000 (3+9)
163 * 3 ss1 disabled (2x6) - 0x00770000 (6+6)
164 * 4 ss2 disabled (2x6) - 0x00007000 (9+3)
165 */
166 u32 eu_pool_config = 0x00777000;
167
168 OUT_BATCH(d, i, GEN9_MEDIA_POOL_STATE);
169 OUT_BATCH(d, i, GEN9_MEDIA_POOL_ENABLE);
170 OUT_BATCH(d, i, eu_pool_config);
171 OUT_BATCH(d, i, 0);
172 OUT_BATCH(d, i, 0);
173 OUT_BATCH(d, i, 0);
174 }
175
84e81020
AS
176 OUT_BATCH(d, i, MI_BATCH_BUFFER_END);
177 so->aux_batch_size = (i * sizeof(u32)) - so->aux_batch_offset;
178
179 /*
180 * Since we are sending length, we need to strictly conform to
181 * all requirements. For Gen2 this must be a multiple of 8.
182 */
183 so->aux_batch_size = ALIGN(so->aux_batch_size, 8);
184
1ce826d4 185 kunmap(page);
9d0a6fa6
MK
186
187 ret = i915_gem_object_set_to_gtt_domain(so->obj, false);
188 if (ret)
189 return ret;
190
1ce826d4
CW
191 if (rodata->reloc[reloc_index] != -1) {
192 DRM_ERROR("only %d relocs resolved\n", reloc_index);
9d0a6fa6
MK
193 return -EINVAL;
194 }
195
9d0a6fa6 196 return 0;
dd72bde0
MK
197
198err_out:
199 kunmap(page);
200 return ret;
9d0a6fa6
MK
201}
202
84e81020
AS
203#undef OUT_BATCH
204
e40f9ee6 205static void render_state_fini(struct render_state *so)
1ce826d4
CW
206{
207 i915_gem_object_ggtt_unpin(so->obj);
f8c417cd 208 i915_gem_object_put(so->obj);
1ce826d4
CW
209}
210
e40f9ee6
CW
211static int render_state_prepare(struct intel_engine_cs *engine,
212 struct render_state *so)
9d0a6fa6 213{
9d0a6fa6
MK
214 int ret;
215
0bc40be8 216 if (WARN_ON(engine->id != RCS))
46470fc9
MK
217 return -ENOENT;
218
c033666a 219 ret = render_state_init(so, engine->i915);
1ce826d4
CW
220 if (ret)
221 return ret;
9d0a6fa6 222
564ddb2f 223 if (so->rodata == NULL)
1ce826d4 224 return 0;
9d0a6fa6 225
564ddb2f
OM
226 ret = render_state_setup(so);
227 if (ret) {
e40f9ee6 228 render_state_fini(so);
564ddb2f
OM
229 return ret;
230 }
231
232 return 0;
233}
234
be01363f 235int i915_gem_render_state_init(struct drm_i915_gem_request *req)
564ddb2f
OM
236{
237 struct render_state so;
238 int ret;
239
e40f9ee6 240 ret = render_state_prepare(req->engine, &so);
9d0a6fa6 241 if (ret)
564ddb2f
OM
242 return ret;
243
244 if (so.rodata == NULL)
245 return 0;
9d0a6fa6 246
803688ba
CW
247 ret = req->engine->emit_bb_start(req, so.ggtt_offset,
248 so.rodata->batch_items * 4,
249 I915_DISPATCH_SECURE);
9d0a6fa6
MK
250 if (ret)
251 goto out;
252
84e81020 253 if (so.aux_batch_size > 8) {
803688ba
CW
254 ret = req->engine->emit_bb_start(req,
255 (so.ggtt_offset +
256 so.aux_batch_offset),
257 so.aux_batch_size,
258 I915_DISPATCH_SECURE);
84e81020
AS
259 if (ret)
260 goto out;
261 }
262
b2af0376 263 i915_vma_move_to_active(i915_gem_obj_to_ggtt(so.obj), req);
9d0a6fa6 264out:
e40f9ee6 265 render_state_fini(&so);
9d0a6fa6
MK
266 return ret;
267}