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
29 #include "intel_renderstate.h"
31 static const struct intel_renderstate_rodata *
32 render_state_get_rodata(struct drm_device *dev, const int gen)
36 return &gen6_null_state;
38 return &gen7_null_state;
40 return &gen8_null_state;
42 return &gen9_null_state;
48 static int render_state_init(struct render_state *so, struct drm_device *dev)
52 so->gen = INTEL_INFO(dev)->gen;
53 so->rodata = render_state_get_rodata(dev, so->gen);
54 if (so->rodata == NULL)
57 if (so->rodata->batch_items * 4 > 4096)
60 so->obj = i915_gem_alloc_object(dev, 4096);
64 ret = i915_gem_obj_ggtt_pin(so->obj, 4096, 0);
68 so->ggtt_offset = i915_gem_obj_ggtt_offset(so->obj);
72 drm_gem_object_unreference(&so->obj->base);
76 static int render_state_setup(struct render_state *so)
78 const struct intel_renderstate_rodata *rodata = so->rodata;
79 unsigned int i = 0, reloc_index = 0;
84 ret = i915_gem_object_set_to_cpu_domain(so->obj, true);
88 page = sg_page(so->obj->pages->sgl);
91 while (i < rodata->batch_items) {
92 u32 s = rodata->batch[i];
94 if (i * 4 == rodata->reloc[reloc_index]) {
95 u64 r = s + so->ggtt_offset;
98 if (i + 1 >= rodata->batch_items ||
99 rodata->batch[i + 1] != 0)
103 s = upper_32_bits(r);
113 ret = i915_gem_object_set_to_gtt_domain(so->obj, false);
117 if (rodata->reloc[reloc_index] != -1) {
118 DRM_ERROR("only %d relocs resolved\n", reloc_index);
125 void i915_gem_render_state_fini(struct render_state *so)
127 i915_gem_object_ggtt_unpin(so->obj);
128 drm_gem_object_unreference(&so->obj->base);
131 int i915_gem_render_state_prepare(struct intel_engine_cs *ring,
132 struct render_state *so)
136 if (WARN_ON(ring->id != RCS))
139 ret = render_state_init(so, ring->dev);
143 if (so->rodata == NULL)
146 ret = render_state_setup(so);
148 i915_gem_render_state_fini(so);
155 int i915_gem_render_state_init(struct intel_engine_cs *ring)
157 struct render_state so;
160 ret = i915_gem_render_state_prepare(ring, &so);
164 if (so.rodata == NULL)
167 ret = ring->dispatch_execbuffer(ring,
169 so.rodata->batch_items * 4,
170 I915_DISPATCH_SECURE);
174 i915_vma_move_to_active(i915_gem_obj_to_ggtt(so.obj), ring);
176 ret = __i915_add_request(ring, NULL, so.obj);
177 /* __i915_add_request moves object to inactive if it fails */
179 i915_gem_render_state_fini(&so);