2 * Copyright © 2014 Intel Corporation
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:
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
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
24 * Mika Kuoppala <mika.kuoppala@intel.com>
29 #include "intel_renderstate.h"
30 #include "intel_ring.h"
32 static const struct intel_renderstate_rodata *
33 render_state_get_rodata(const struct intel_engine_cs *engine)
35 if (engine->class != RENDER_CLASS)
38 switch (INTEL_GEN(engine->i915)) {
40 return &gen6_null_state;
42 return &gen7_null_state;
44 return &gen8_null_state;
46 return &gen9_null_state;
53 * Macro to add commands to auxiliary batch.
54 * This macro only checks for page overflow before inserting the commands,
55 * this is sufficient as the null state generator makes the final batch
56 * with two passes to build command and state separately. At this point
57 * the size of both are known and it compacts them by relocating the state
58 * right after the commands taking care of alignment so we should sufficient
59 * space below them for adding new commands.
61 #define OUT_BATCH(batch, i, val) \
63 if ((i) >= PAGE_SIZE / sizeof(u32)) \
65 (batch)[(i)++] = (val); \
68 static int render_state_setup(struct intel_renderstate *so,
69 struct drm_i915_private *i915)
71 const struct intel_renderstate_rodata *rodata = so->rodata;
72 unsigned int i = 0, reloc_index = 0;
76 d = i915_gem_object_pin_map(so->vma->obj, I915_MAP_WB);
80 while (i < rodata->batch_items) {
81 u32 s = rodata->batch[i];
83 if (i * 4 == rodata->reloc[reloc_index]) {
84 u64 r = s + so->vma->node.start;
86 if (HAS_64BIT_RELOC(i915)) {
87 if (i + 1 >= rodata->batch_items ||
88 rodata->batch[i + 1] != 0)
101 if (rodata->reloc[reloc_index] != -1) {
102 drm_err(&i915->drm, "only %d relocs resolved\n", reloc_index);
106 so->batch_offset = i915_ggtt_offset(so->vma);
107 so->batch_size = rodata->batch_items * sizeof(u32);
109 while (i % CACHELINE_DWORDS)
110 OUT_BATCH(d, i, MI_NOOP);
112 so->aux_offset = i * sizeof(u32);
114 if (HAS_POOLED_EU(i915)) {
116 * We always program 3x6 pool config but depending upon which
117 * subslice is disabled HW drops down to appropriate config
120 * In the below table 2x6 config always refers to
121 * fused-down version, native 2x6 is not available and can
124 * SNo subslices config eu pool configuration
125 * -----------------------------------------------------------
126 * 1 3 subslices enabled (3x6) - 0x00777000 (9+9)
127 * 2 ss0 disabled (2x6) - 0x00777000 (3+9)
128 * 3 ss1 disabled (2x6) - 0x00770000 (6+6)
129 * 4 ss2 disabled (2x6) - 0x00007000 (9+3)
131 u32 eu_pool_config = 0x00777000;
133 OUT_BATCH(d, i, GEN9_MEDIA_POOL_STATE);
134 OUT_BATCH(d, i, GEN9_MEDIA_POOL_ENABLE);
135 OUT_BATCH(d, i, eu_pool_config);
141 OUT_BATCH(d, i, MI_BATCH_BUFFER_END);
142 so->aux_size = i * sizeof(u32) - so->aux_offset;
143 so->aux_offset += so->batch_offset;
145 * Since we are sending length, we need to strictly conform to
146 * all requirements. For Gen2 this must be a multiple of 8.
148 so->aux_size = ALIGN(so->aux_size, 8);
152 __i915_gem_object_flush_map(so->vma->obj, 0, i * sizeof(u32));
153 __i915_gem_object_release_map(so->vma->obj);
159 int intel_renderstate_init(struct intel_renderstate *so,
160 struct intel_engine_cs *engine)
162 struct drm_i915_gem_object *obj;
165 memset(so, 0, sizeof(*so));
167 so->rodata = render_state_get_rodata(engine);
171 if (so->rodata->batch_items * 4 > PAGE_SIZE)
174 obj = i915_gem_object_create_internal(engine->i915, PAGE_SIZE);
178 so->vma = i915_vma_instance(obj, &engine->gt->ggtt->vm, NULL);
179 if (IS_ERR(so->vma)) {
180 err = PTR_ERR(so->vma);
184 err = i915_vma_pin(so->vma, 0, 0, PIN_GLOBAL | PIN_HIGH);
188 err = render_state_setup(so, engine->i915);
195 i915_vma_unpin(so->vma);
197 i915_gem_object_put(obj);
202 int intel_renderstate_emit(struct intel_renderstate *so,
203 struct i915_request *rq)
205 struct intel_engine_cs *engine = rq->engine;
211 i915_vma_lock(so->vma);
212 err = i915_request_await_object(rq, so->vma->obj, false);
214 err = i915_vma_move_to_active(so->vma, rq, 0);
215 i915_vma_unlock(so->vma);
219 err = engine->emit_bb_start(rq,
220 so->batch_offset, so->batch_size,
221 I915_DISPATCH_SECURE);
225 if (so->aux_size > 8) {
226 err = engine->emit_bb_start(rq,
227 so->aux_offset, so->aux_size,
228 I915_DISPATCH_SECURE);
236 void intel_renderstate_fini(struct intel_renderstate *so)
238 i915_vma_unpin_and_release(&so->vma, 0);