Mika Kuoppala | 9d0a6fa | 2014-05-14 17:02:16 +0300 | [diff] [blame] | 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 | |
Chris Wilson | e40f9ee | 2016-08-02 22:50:36 +0100 | [diff] [blame] | 31 | struct render_state { |
| 32 | const struct intel_renderstate_rodata *rodata; |
Chris Wilson | a5e85c8 | 2016-08-15 10:49:03 +0100 | [diff] [blame] | 33 | struct i915_vma *vma; |
Chris Wilson | e40f9ee | 2016-08-02 22:50:36 +0100 | [diff] [blame] | 34 | u32 aux_batch_size; |
| 35 | u32 aux_batch_offset; |
| 36 | }; |
| 37 | |
Mika Kuoppala | 9d0a6fa | 2014-05-14 17:02:16 +0300 | [diff] [blame] | 38 | static const struct intel_renderstate_rodata * |
Chris Wilson | 15d21db | 2016-08-02 22:50:37 +0100 | [diff] [blame] | 39 | render_state_get_rodata(const struct drm_i915_gem_request *req) |
Mika Kuoppala | 9d0a6fa | 2014-05-14 17:02:16 +0300 | [diff] [blame] | 40 | { |
Chris Wilson | 15d21db | 2016-08-02 22:50:37 +0100 | [diff] [blame] | 41 | switch (INTEL_GEN(req->i915)) { |
Mika Kuoppala | 9d0a6fa | 2014-05-14 17:02:16 +0300 | [diff] [blame] | 42 | case 6: |
| 43 | return &gen6_null_state; |
| 44 | case 7: |
| 45 | return &gen7_null_state; |
| 46 | case 8: |
| 47 | return &gen8_null_state; |
Armin Reese | ff7a60f | 2014-10-23 08:34:28 -0700 | [diff] [blame] | 48 | case 9: |
| 49 | return &gen9_null_state; |
Mika Kuoppala | 9d0a6fa | 2014-05-14 17:02:16 +0300 | [diff] [blame] | 50 | } |
| 51 | |
| 52 | return NULL; |
| 53 | } |
| 54 | |
Arun Siluvery | 84e8102 | 2015-07-20 10:46:10 +0100 | [diff] [blame] | 55 | /* |
| 56 | * Macro to add commands to auxiliary batch. |
| 57 | * This macro only checks for page overflow before inserting the commands, |
| 58 | * this is sufficient as the null state generator makes the final batch |
| 59 | * with two passes to build command and state separately. At this point |
| 60 | * the size of both are known and it compacts them by relocating the state |
| 61 | * right after the commands taking care of aligment so we should sufficient |
| 62 | * space below them for adding new commands. |
| 63 | */ |
| 64 | #define OUT_BATCH(batch, i, val) \ |
| 65 | do { \ |
| 66 | if (WARN_ON((i) >= PAGE_SIZE / sizeof(u32))) { \ |
| 67 | ret = -ENOSPC; \ |
| 68 | goto err_out; \ |
| 69 | } \ |
| 70 | (batch)[(i)++] = (val); \ |
| 71 | } while(0) |
| 72 | |
Chris Wilson | 1ce826d | 2014-06-10 11:23:33 +0100 | [diff] [blame] | 73 | static int render_state_setup(struct render_state *so) |
| 74 | { |
Chris Wilson | a5e85c8 | 2016-08-15 10:49:03 +0100 | [diff] [blame] | 75 | struct drm_device *dev = so->vma->vm->dev; |
Chris Wilson | 1ce826d | 2014-06-10 11:23:33 +0100 | [diff] [blame] | 76 | const struct intel_renderstate_rodata *rodata = so->rodata; |
Chris Wilson | 15d21db | 2016-08-02 22:50:37 +0100 | [diff] [blame] | 77 | const bool has_64bit_reloc = INTEL_GEN(dev) >= 8; |
Chris Wilson | 1ce826d | 2014-06-10 11:23:33 +0100 | [diff] [blame] | 78 | unsigned int i = 0, reloc_index = 0; |
| 79 | struct page *page; |
| 80 | u32 *d; |
| 81 | int ret; |
| 82 | |
Chris Wilson | a5e85c8 | 2016-08-15 10:49:03 +0100 | [diff] [blame] | 83 | ret = i915_gem_object_set_to_cpu_domain(so->vma->obj, true); |
Mika Kuoppala | 9d0a6fa | 2014-05-14 17:02:16 +0300 | [diff] [blame] | 84 | if (ret) |
| 85 | return ret; |
| 86 | |
Chris Wilson | a5e85c8 | 2016-08-15 10:49:03 +0100 | [diff] [blame] | 87 | page = i915_gem_object_get_dirty_page(so->vma->obj, 0); |
Chris Wilson | 1ce826d | 2014-06-10 11:23:33 +0100 | [diff] [blame] | 88 | d = kmap(page); |
| 89 | |
Mika Kuoppala | 9d0a6fa | 2014-05-14 17:02:16 +0300 | [diff] [blame] | 90 | while (i < rodata->batch_items) { |
| 91 | u32 s = rodata->batch[i]; |
| 92 | |
Chris Wilson | 1ce826d | 2014-06-10 11:23:33 +0100 | [diff] [blame] | 93 | if (i * 4 == rodata->reloc[reloc_index]) { |
Chris Wilson | a5e85c8 | 2016-08-15 10:49:03 +0100 | [diff] [blame] | 94 | u64 r = s + so->vma->node.start; |
Chris Wilson | 1ce826d | 2014-06-10 11:23:33 +0100 | [diff] [blame] | 95 | s = lower_32_bits(r); |
Chris Wilson | 15d21db | 2016-08-02 22:50:37 +0100 | [diff] [blame] | 96 | if (has_64bit_reloc) { |
Mika Kuoppala | 9d0a6fa | 2014-05-14 17:02:16 +0300 | [diff] [blame] | 97 | if (i + 1 >= rodata->batch_items || |
Mika Kuoppala | dd72bde | 2015-07-17 17:08:51 +0100 | [diff] [blame] | 98 | rodata->batch[i + 1] != 0) { |
| 99 | ret = -EINVAL; |
| 100 | goto err_out; |
| 101 | } |
Mika Kuoppala | 9d0a6fa | 2014-05-14 17:02:16 +0300 | [diff] [blame] | 102 | |
Chris Wilson | 1ce826d | 2014-06-10 11:23:33 +0100 | [diff] [blame] | 103 | d[i++] = s; |
| 104 | s = upper_32_bits(r); |
Mika Kuoppala | 9d0a6fa | 2014-05-14 17:02:16 +0300 | [diff] [blame] | 105 | } |
| 106 | |
| 107 | reloc_index++; |
| 108 | } |
| 109 | |
Chris Wilson | 1ce826d | 2014-06-10 11:23:33 +0100 | [diff] [blame] | 110 | d[i++] = s; |
Mika Kuoppala | 9d0a6fa | 2014-05-14 17:02:16 +0300 | [diff] [blame] | 111 | } |
Arun Siluvery | 84e8102 | 2015-07-20 10:46:10 +0100 | [diff] [blame] | 112 | |
| 113 | while (i % CACHELINE_DWORDS) |
| 114 | OUT_BATCH(d, i, MI_NOOP); |
| 115 | |
| 116 | so->aux_batch_offset = i * sizeof(u32); |
| 117 | |
arun.siluvery@linux.intel.com | 33e141e | 2016-06-03 06:34:33 +0100 | [diff] [blame] | 118 | if (HAS_POOLED_EU(dev)) { |
| 119 | /* |
| 120 | * We always program 3x6 pool config but depending upon which |
| 121 | * subslice is disabled HW drops down to appropriate config |
| 122 | * shown below. |
| 123 | * |
| 124 | * In the below table 2x6 config always refers to |
| 125 | * fused-down version, native 2x6 is not available and can |
| 126 | * be ignored |
| 127 | * |
| 128 | * SNo subslices config eu pool configuration |
| 129 | * ----------------------------------------------------------- |
| 130 | * 1 3 subslices enabled (3x6) - 0x00777000 (9+9) |
| 131 | * 2 ss0 disabled (2x6) - 0x00777000 (3+9) |
| 132 | * 3 ss1 disabled (2x6) - 0x00770000 (6+6) |
| 133 | * 4 ss2 disabled (2x6) - 0x00007000 (9+3) |
| 134 | */ |
| 135 | u32 eu_pool_config = 0x00777000; |
| 136 | |
| 137 | OUT_BATCH(d, i, GEN9_MEDIA_POOL_STATE); |
| 138 | OUT_BATCH(d, i, GEN9_MEDIA_POOL_ENABLE); |
| 139 | OUT_BATCH(d, i, eu_pool_config); |
| 140 | OUT_BATCH(d, i, 0); |
| 141 | OUT_BATCH(d, i, 0); |
| 142 | OUT_BATCH(d, i, 0); |
| 143 | } |
| 144 | |
Arun Siluvery | 84e8102 | 2015-07-20 10:46:10 +0100 | [diff] [blame] | 145 | OUT_BATCH(d, i, MI_BATCH_BUFFER_END); |
| 146 | so->aux_batch_size = (i * sizeof(u32)) - so->aux_batch_offset; |
| 147 | |
| 148 | /* |
| 149 | * Since we are sending length, we need to strictly conform to |
| 150 | * all requirements. For Gen2 this must be a multiple of 8. |
| 151 | */ |
| 152 | so->aux_batch_size = ALIGN(so->aux_batch_size, 8); |
| 153 | |
Chris Wilson | 1ce826d | 2014-06-10 11:23:33 +0100 | [diff] [blame] | 154 | kunmap(page); |
Mika Kuoppala | 9d0a6fa | 2014-05-14 17:02:16 +0300 | [diff] [blame] | 155 | |
Chris Wilson | a5e85c8 | 2016-08-15 10:49:03 +0100 | [diff] [blame] | 156 | ret = i915_gem_object_set_to_gtt_domain(so->vma->obj, false); |
Mika Kuoppala | 9d0a6fa | 2014-05-14 17:02:16 +0300 | [diff] [blame] | 157 | if (ret) |
| 158 | return ret; |
| 159 | |
Chris Wilson | 1ce826d | 2014-06-10 11:23:33 +0100 | [diff] [blame] | 160 | if (rodata->reloc[reloc_index] != -1) { |
| 161 | DRM_ERROR("only %d relocs resolved\n", reloc_index); |
Mika Kuoppala | 9d0a6fa | 2014-05-14 17:02:16 +0300 | [diff] [blame] | 162 | return -EINVAL; |
| 163 | } |
| 164 | |
Mika Kuoppala | 9d0a6fa | 2014-05-14 17:02:16 +0300 | [diff] [blame] | 165 | return 0; |
Mika Kuoppala | dd72bde | 2015-07-17 17:08:51 +0100 | [diff] [blame] | 166 | |
| 167 | err_out: |
| 168 | kunmap(page); |
| 169 | return ret; |
Mika Kuoppala | 9d0a6fa | 2014-05-14 17:02:16 +0300 | [diff] [blame] | 170 | } |
| 171 | |
Arun Siluvery | 84e8102 | 2015-07-20 10:46:10 +0100 | [diff] [blame] | 172 | #undef OUT_BATCH |
| 173 | |
John Harrison | be01363 | 2015-05-29 17:43:45 +0100 | [diff] [blame] | 174 | int i915_gem_render_state_init(struct drm_i915_gem_request *req) |
Mika Kuoppala | 9d0a6fa | 2014-05-14 17:02:16 +0300 | [diff] [blame] | 175 | { |
Chris Wilson | 1ce826d | 2014-06-10 11:23:33 +0100 | [diff] [blame] | 176 | struct render_state so; |
Chris Wilson | a5e85c8 | 2016-08-15 10:49:03 +0100 | [diff] [blame] | 177 | struct drm_i915_gem_object *obj; |
Mika Kuoppala | 9d0a6fa | 2014-05-14 17:02:16 +0300 | [diff] [blame] | 178 | int ret; |
| 179 | |
Chris Wilson | 15d21db | 2016-08-02 22:50:37 +0100 | [diff] [blame] | 180 | if (WARN_ON(req->engine->id != RCS)) |
| 181 | return -ENOENT; |
Chris Wilson | 1ce826d | 2014-06-10 11:23:33 +0100 | [diff] [blame] | 182 | |
Chris Wilson | 15d21db | 2016-08-02 22:50:37 +0100 | [diff] [blame] | 183 | so.rodata = render_state_get_rodata(req); |
| 184 | if (!so.rodata) |
Mika Kuoppala | 9d0a6fa | 2014-05-14 17:02:16 +0300 | [diff] [blame] | 185 | return 0; |
| 186 | |
Chris Wilson | 15d21db | 2016-08-02 22:50:37 +0100 | [diff] [blame] | 187 | if (so.rodata->batch_items * 4 > 4096) |
| 188 | return -EINVAL; |
| 189 | |
Chris Wilson | a5e85c8 | 2016-08-15 10:49:03 +0100 | [diff] [blame] | 190 | obj = i915_gem_object_create(&req->i915->drm, 4096); |
| 191 | if (IS_ERR(obj)) |
| 192 | return PTR_ERR(obj); |
Chris Wilson | 15d21db | 2016-08-02 22:50:37 +0100 | [diff] [blame] | 193 | |
Chris Wilson | a5e85c8 | 2016-08-15 10:49:03 +0100 | [diff] [blame] | 194 | so.vma = i915_vma_create(obj, &req->i915->ggtt.base, NULL); |
| 195 | if (IS_ERR(so.vma)) { |
| 196 | ret = PTR_ERR(so.vma); |
| 197 | goto err_obj; |
| 198 | } |
| 199 | |
| 200 | ret = i915_vma_pin(so.vma, 0, 0, PIN_GLOBAL); |
Chris Wilson | 15d21db | 2016-08-02 22:50:37 +0100 | [diff] [blame] | 201 | if (ret) |
| 202 | goto err_obj; |
| 203 | |
Chris Wilson | 15d21db | 2016-08-02 22:50:37 +0100 | [diff] [blame] | 204 | ret = render_state_setup(&so); |
| 205 | if (ret) |
| 206 | goto err_unpin; |
| 207 | |
Chris Wilson | a5e85c8 | 2016-08-15 10:49:03 +0100 | [diff] [blame] | 208 | ret = req->engine->emit_bb_start(req, so.vma->node.start, |
Chris Wilson | 803688b | 2016-08-02 22:50:27 +0100 | [diff] [blame] | 209 | so.rodata->batch_items * 4, |
| 210 | I915_DISPATCH_SECURE); |
Mika Kuoppala | 9d0a6fa | 2014-05-14 17:02:16 +0300 | [diff] [blame] | 211 | if (ret) |
Chris Wilson | 15d21db | 2016-08-02 22:50:37 +0100 | [diff] [blame] | 212 | goto err_unpin; |
Mika Kuoppala | 9d0a6fa | 2014-05-14 17:02:16 +0300 | [diff] [blame] | 213 | |
Arun Siluvery | 84e8102 | 2015-07-20 10:46:10 +0100 | [diff] [blame] | 214 | if (so.aux_batch_size > 8) { |
Chris Wilson | 803688b | 2016-08-02 22:50:27 +0100 | [diff] [blame] | 215 | ret = req->engine->emit_bb_start(req, |
Chris Wilson | a5e85c8 | 2016-08-15 10:49:03 +0100 | [diff] [blame] | 216 | (so.vma->node.start + |
Chris Wilson | 803688b | 2016-08-02 22:50:27 +0100 | [diff] [blame] | 217 | so.aux_batch_offset), |
| 218 | so.aux_batch_size, |
| 219 | I915_DISPATCH_SECURE); |
Arun Siluvery | 84e8102 | 2015-07-20 10:46:10 +0100 | [diff] [blame] | 220 | if (ret) |
Chris Wilson | 15d21db | 2016-08-02 22:50:37 +0100 | [diff] [blame] | 221 | goto err_unpin; |
Arun Siluvery | 84e8102 | 2015-07-20 10:46:10 +0100 | [diff] [blame] | 222 | } |
| 223 | |
Chris Wilson | a5e85c8 | 2016-08-15 10:49:03 +0100 | [diff] [blame] | 224 | i915_vma_move_to_active(so.vma, req, 0); |
Chris Wilson | 15d21db | 2016-08-02 22:50:37 +0100 | [diff] [blame] | 225 | err_unpin: |
Chris Wilson | a5e85c8 | 2016-08-15 10:49:03 +0100 | [diff] [blame] | 226 | i915_vma_unpin(so.vma); |
Chris Wilson | 15d21db | 2016-08-02 22:50:37 +0100 | [diff] [blame] | 227 | err_obj: |
Chris Wilson | a5e85c8 | 2016-08-15 10:49:03 +0100 | [diff] [blame] | 228 | i915_gem_object_put(obj); |
Mika Kuoppala | 9d0a6fa | 2014-05-14 17:02:16 +0300 | [diff] [blame] | 229 | return ret; |
| 230 | } |