Zhi Wang | 1786571 | 2016-05-01 19:02:37 -0400 | [diff] [blame] | 1 | /* |
| 2 | * Copyright(c) 2011-2016 Intel Corporation. All rights reserved. |
| 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 FROM, |
| 20 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE |
| 21 | * SOFTWARE. |
| 22 | * |
| 23 | * Authors: |
| 24 | * Eddie Dong <eddie.dong@intel.com> |
| 25 | * Kevin Tian <kevin.tian@intel.com> |
| 26 | * |
| 27 | * Contributors: |
| 28 | * Zhi Wang <zhi.a.wang@intel.com> |
| 29 | * Changbin Du <changbin.du@intel.com> |
| 30 | * Zhenyu Wang <zhenyuw@linux.intel.com> |
| 31 | * Tina Zhang <tina.zhang@intel.com> |
| 32 | * Bing Niu <bing.niu@intel.com> |
| 33 | * |
| 34 | */ |
| 35 | |
| 36 | #include "i915_drv.h" |
Zhenyu Wang | feddf6e | 2016-10-20 17:15:03 +0800 | [diff] [blame] | 37 | #include "gvt.h" |
Xiong Zhang | 7fb6a7d | 2017-05-23 05:38:08 +0800 | [diff] [blame] | 38 | #include "trace.h" |
Zhi Wang | 1786571 | 2016-05-01 19:02:37 -0400 | [diff] [blame] | 39 | |
Changbin Du | 4447f42 | 2017-12-08 14:56:20 +0800 | [diff] [blame] | 40 | /** |
| 41 | * Defined in Intel Open Source PRM. |
| 42 | * Ref: https://01.org/linuxgraphics/documentation/hardware-specification-prms |
| 43 | */ |
| 44 | #define TRVATTL3PTRDW(i) _MMIO(0x4de0 + (i)*4) |
| 45 | #define TRNULLDETCT _MMIO(0x4de8) |
| 46 | #define TRINVTILEDETCT _MMIO(0x4dec) |
| 47 | #define TRVADR _MMIO(0x4df0) |
| 48 | #define TRTTE _MMIO(0x4df4) |
| 49 | #define RING_EXCC(base) _MMIO((base) + 0x28) |
| 50 | #define RING_GFX_MODE(base) _MMIO((base) + 0x29c) |
| 51 | #define VF_GUARDBAND _MMIO(0x83a4) |
Zhi Wang | 1786571 | 2016-05-01 19:02:37 -0400 | [diff] [blame] | 52 | |
Changbin Du | 4447f42 | 2017-12-08 14:56:20 +0800 | [diff] [blame] | 53 | /* Raw offset is appened to each line for convenience. */ |
Changbin Du | 8316488 | 2017-12-08 14:56:21 +0800 | [diff] [blame] | 54 | static struct engine_mmio gen8_engine_mmio_list[] __cacheline_aligned = { |
Changbin Du | 4447f42 | 2017-12-08 14:56:20 +0800 | [diff] [blame] | 55 | {RCS, GFX_MODE_GEN7, 0xffff, false}, /* 0x229c */ |
| 56 | {RCS, GEN9_CTX_PREEMPT_REG, 0x0, false}, /* 0x2248 */ |
| 57 | {RCS, HWSTAM, 0x0, false}, /* 0x2098 */ |
| 58 | {RCS, INSTPM, 0xffff, true}, /* 0x20c0 */ |
| 59 | {RCS, RING_FORCE_TO_NONPRIV(RENDER_RING_BASE, 0), 0, false}, /* 0x24d0 */ |
| 60 | {RCS, RING_FORCE_TO_NONPRIV(RENDER_RING_BASE, 1), 0, false}, /* 0x24d4 */ |
| 61 | {RCS, RING_FORCE_TO_NONPRIV(RENDER_RING_BASE, 2), 0, false}, /* 0x24d8 */ |
| 62 | {RCS, RING_FORCE_TO_NONPRIV(RENDER_RING_BASE, 3), 0, false}, /* 0x24dc */ |
| 63 | {RCS, RING_FORCE_TO_NONPRIV(RENDER_RING_BASE, 4), 0, false}, /* 0x24e0 */ |
| 64 | {RCS, RING_FORCE_TO_NONPRIV(RENDER_RING_BASE, 5), 0, false}, /* 0x24e4 */ |
| 65 | {RCS, RING_FORCE_TO_NONPRIV(RENDER_RING_BASE, 6), 0, false}, /* 0x24e8 */ |
| 66 | {RCS, RING_FORCE_TO_NONPRIV(RENDER_RING_BASE, 7), 0, false}, /* 0x24ec */ |
| 67 | {RCS, RING_FORCE_TO_NONPRIV(RENDER_RING_BASE, 8), 0, false}, /* 0x24f0 */ |
| 68 | {RCS, RING_FORCE_TO_NONPRIV(RENDER_RING_BASE, 9), 0, false}, /* 0x24f4 */ |
| 69 | {RCS, RING_FORCE_TO_NONPRIV(RENDER_RING_BASE, 10), 0, false}, /* 0x24f8 */ |
| 70 | {RCS, RING_FORCE_TO_NONPRIV(RENDER_RING_BASE, 11), 0, false}, /* 0x24fc */ |
| 71 | {RCS, CACHE_MODE_1, 0xffff, true}, /* 0x7004 */ |
| 72 | {RCS, GEN7_GT_MODE, 0xffff, true}, /* 0x7008 */ |
| 73 | {RCS, CACHE_MODE_0_GEN7, 0xffff, true}, /* 0x7000 */ |
| 74 | {RCS, GEN7_COMMON_SLICE_CHICKEN1, 0xffff, true}, /* 0x7010 */ |
| 75 | {RCS, HDC_CHICKEN0, 0xffff, true}, /* 0x7300 */ |
| 76 | {RCS, VF_GUARDBAND, 0xffff, true}, /* 0x83a4 */ |
| 77 | |
| 78 | {BCS, RING_GFX_MODE(BLT_RING_BASE), 0xffff, false}, /* 0x2229c */ |
| 79 | {BCS, RING_MI_MODE(BLT_RING_BASE), 0xffff, false}, /* 0x2209c */ |
| 80 | {BCS, RING_INSTPM(BLT_RING_BASE), 0xffff, false}, /* 0x220c0 */ |
| 81 | {BCS, RING_HWSTAM(BLT_RING_BASE), 0x0, false}, /* 0x22098 */ |
| 82 | {BCS, RING_EXCC(BLT_RING_BASE), 0x0, false}, /* 0x22028 */ |
Changbin Du | 8316488 | 2017-12-08 14:56:21 +0800 | [diff] [blame] | 83 | { /* Terminated */ } |
Zhi Wang | 1786571 | 2016-05-01 19:02:37 -0400 | [diff] [blame] | 84 | }; |
| 85 | |
Changbin Du | 8316488 | 2017-12-08 14:56:21 +0800 | [diff] [blame] | 86 | static struct engine_mmio gen9_engine_mmio_list[] __cacheline_aligned = { |
Changbin Du | 4447f42 | 2017-12-08 14:56:20 +0800 | [diff] [blame] | 87 | {RCS, GFX_MODE_GEN7, 0xffff, false}, /* 0x229c */ |
| 88 | {RCS, GEN9_CTX_PREEMPT_REG, 0x0, false}, /* 0x2248 */ |
| 89 | {RCS, HWSTAM, 0x0, false}, /* 0x2098 */ |
| 90 | {RCS, INSTPM, 0xffff, true}, /* 0x20c0 */ |
| 91 | {RCS, RING_FORCE_TO_NONPRIV(RENDER_RING_BASE, 0), 0, false}, /* 0x24d0 */ |
| 92 | {RCS, RING_FORCE_TO_NONPRIV(RENDER_RING_BASE, 1), 0, false}, /* 0x24d4 */ |
| 93 | {RCS, RING_FORCE_TO_NONPRIV(RENDER_RING_BASE, 2), 0, false}, /* 0x24d8 */ |
| 94 | {RCS, RING_FORCE_TO_NONPRIV(RENDER_RING_BASE, 3), 0, false}, /* 0x24dc */ |
| 95 | {RCS, RING_FORCE_TO_NONPRIV(RENDER_RING_BASE, 4), 0, false}, /* 0x24e0 */ |
| 96 | {RCS, RING_FORCE_TO_NONPRIV(RENDER_RING_BASE, 5), 0, false}, /* 0x24e4 */ |
| 97 | {RCS, RING_FORCE_TO_NONPRIV(RENDER_RING_BASE, 6), 0, false}, /* 0x24e8 */ |
| 98 | {RCS, RING_FORCE_TO_NONPRIV(RENDER_RING_BASE, 7), 0, false}, /* 0x24ec */ |
| 99 | {RCS, RING_FORCE_TO_NONPRIV(RENDER_RING_BASE, 8), 0, false}, /* 0x24f0 */ |
| 100 | {RCS, RING_FORCE_TO_NONPRIV(RENDER_RING_BASE, 9), 0, false}, /* 0x24f4 */ |
| 101 | {RCS, RING_FORCE_TO_NONPRIV(RENDER_RING_BASE, 10), 0, false}, /* 0x24f8 */ |
| 102 | {RCS, RING_FORCE_TO_NONPRIV(RENDER_RING_BASE, 11), 0, false}, /* 0x24fc */ |
| 103 | {RCS, CACHE_MODE_1, 0xffff, true}, /* 0x7004 */ |
| 104 | {RCS, GEN7_GT_MODE, 0xffff, true}, /* 0x7008 */ |
| 105 | {RCS, CACHE_MODE_0_GEN7, 0xffff, true}, /* 0x7000 */ |
| 106 | {RCS, GEN7_COMMON_SLICE_CHICKEN1, 0xffff, true}, /* 0x7010 */ |
| 107 | {RCS, HDC_CHICKEN0, 0xffff, true}, /* 0x7300 */ |
| 108 | {RCS, VF_GUARDBAND, 0xffff, true}, /* 0x83a4 */ |
Zhi Wang | 1786571 | 2016-05-01 19:02:37 -0400 | [diff] [blame] | 109 | |
Changbin Du | 4447f42 | 2017-12-08 14:56:20 +0800 | [diff] [blame] | 110 | {RCS, GEN8_PRIVATE_PAT_LO, 0, false}, /* 0x40e0 */ |
| 111 | {RCS, GEN8_PRIVATE_PAT_HI, 0, false}, /* 0x40e4 */ |
| 112 | {RCS, GEN8_CS_CHICKEN1, 0xffff, true}, /* 0x2580 */ |
| 113 | {RCS, COMMON_SLICE_CHICKEN2, 0xffff, true}, /* 0x7014 */ |
| 114 | {RCS, GEN9_CS_DEBUG_MODE1, 0xffff, false}, /* 0x20ec */ |
| 115 | {RCS, GEN8_L3SQCREG4, 0, false}, /* 0xb118 */ |
| 116 | {RCS, GEN7_HALF_SLICE_CHICKEN1, 0xffff, true}, /* 0xe100 */ |
| 117 | {RCS, HALF_SLICE_CHICKEN2, 0xffff, true}, /* 0xe180 */ |
| 118 | {RCS, HALF_SLICE_CHICKEN3, 0xffff, true}, /* 0xe184 */ |
| 119 | {RCS, GEN9_HALF_SLICE_CHICKEN5, 0xffff, true}, /* 0xe188 */ |
| 120 | {RCS, GEN9_HALF_SLICE_CHICKEN7, 0xffff, true}, /* 0xe194 */ |
| 121 | {RCS, TRVATTL3PTRDW(0), 0, false}, /* 0x4de0 */ |
| 122 | {RCS, TRVATTL3PTRDW(1), 0, false}, /* 0x4de4 */ |
| 123 | {RCS, TRNULLDETCT, 0, false}, /* 0x4de8 */ |
| 124 | {RCS, TRINVTILEDETCT, 0, false}, /* 0x4dec */ |
| 125 | {RCS, TRVADR, 0, false}, /* 0x4df0 */ |
| 126 | {RCS, TRTTE, 0, false}, /* 0x4df4 */ |
Zhi Wang | 1786571 | 2016-05-01 19:02:37 -0400 | [diff] [blame] | 127 | |
Changbin Du | 4447f42 | 2017-12-08 14:56:20 +0800 | [diff] [blame] | 128 | {BCS, RING_GFX_MODE(BLT_RING_BASE), 0xffff, false}, /* 0x2229c */ |
| 129 | {BCS, RING_MI_MODE(BLT_RING_BASE), 0xffff, false}, /* 0x2209c */ |
| 130 | {BCS, RING_INSTPM(BLT_RING_BASE), 0xffff, false}, /* 0x220c0 */ |
| 131 | {BCS, RING_HWSTAM(BLT_RING_BASE), 0x0, false}, /* 0x22098 */ |
| 132 | {BCS, RING_EXCC(BLT_RING_BASE), 0x0, false}, /* 0x22028 */ |
Zhi Wang | 1786571 | 2016-05-01 19:02:37 -0400 | [diff] [blame] | 133 | |
Changbin Du | 4447f42 | 2017-12-08 14:56:20 +0800 | [diff] [blame] | 134 | {VCS2, RING_EXCC(GEN8_BSD2_RING_BASE), 0xffff, false}, /* 0x1c028 */ |
Zhi Wang | 1786571 | 2016-05-01 19:02:37 -0400 | [diff] [blame] | 135 | |
Changbin Du | 4447f42 | 2017-12-08 14:56:20 +0800 | [diff] [blame] | 136 | {VECS, RING_EXCC(VEBOX_RING_BASE), 0xffff, false}, /* 0x1a028 */ |
Xu Han | 6f696d1 | 2017-03-29 10:13:58 +0800 | [diff] [blame] | 137 | |
Changbin Du | 4447f42 | 2017-12-08 14:56:20 +0800 | [diff] [blame] | 138 | {RCS, GEN8_HDC_CHICKEN1, 0xffff, true}, /* 0x7304 */ |
| 139 | {RCS, GEN9_CTX_PREEMPT_REG, 0x0, false}, /* 0x2248 */ |
| 140 | {RCS, GEN7_UCGCTL4, 0x0, false}, /* 0x940c */ |
| 141 | {RCS, GAMT_CHKN_BIT_REG, 0x0, false}, /* 0x4ab8 */ |
Xu Han | 6f696d1 | 2017-03-29 10:13:58 +0800 | [diff] [blame] | 142 | |
Changbin Du | 4447f42 | 2017-12-08 14:56:20 +0800 | [diff] [blame] | 143 | {RCS, GEN9_GAMT_ECO_REG_RW_IA, 0x0, false}, /* 0x4ab0 */ |
| 144 | {RCS, GEN9_CSFE_CHICKEN1_RCS, 0x0, false}, /* 0x20d4 */ |
Xu Han | 6f696d1 | 2017-03-29 10:13:58 +0800 | [diff] [blame] | 145 | |
Changbin Du | 4447f42 | 2017-12-08 14:56:20 +0800 | [diff] [blame] | 146 | {RCS, GEN8_GARBCNTL, 0x0, false}, /* 0xb004 */ |
| 147 | {RCS, GEN7_FF_THREAD_MODE, 0x0, false}, /* 0x20a0 */ |
| 148 | {RCS, FF_SLICE_CS_CHICKEN2, 0xffff, false}, /* 0x20e4 */ |
Changbin Du | 8316488 | 2017-12-08 14:56:21 +0800 | [diff] [blame] | 149 | { /* Terminated */ } |
Zhi Wang | 1786571 | 2016-05-01 19:02:37 -0400 | [diff] [blame] | 150 | }; |
| 151 | |
| 152 | static u32 gen9_render_mocs[I915_NUM_ENGINES][64]; |
| 153 | static u32 gen9_render_mocs_L3[32]; |
| 154 | |
| 155 | static void handle_tlb_pending_event(struct intel_vgpu *vgpu, int ring_id) |
| 156 | { |
| 157 | struct drm_i915_private *dev_priv = vgpu->gvt->dev_priv; |
Zhi Wang | 91d5d85 | 2017-09-10 21:33:20 +0800 | [diff] [blame] | 158 | struct intel_vgpu_submission *s = &vgpu->submission; |
Arkadiusz Hiler | 1c860a3 | 2016-10-21 13:11:50 +0200 | [diff] [blame] | 159 | enum forcewake_domains fw; |
Zhi Wang | 1786571 | 2016-05-01 19:02:37 -0400 | [diff] [blame] | 160 | i915_reg_t reg; |
| 161 | u32 regs[] = { |
| 162 | [RCS] = 0x4260, |
| 163 | [VCS] = 0x4264, |
| 164 | [VCS2] = 0x4268, |
| 165 | [BCS] = 0x426c, |
| 166 | [VECS] = 0x4270, |
| 167 | }; |
| 168 | |
| 169 | if (WARN_ON(ring_id >= ARRAY_SIZE(regs))) |
| 170 | return; |
| 171 | |
Zhi Wang | 91d5d85 | 2017-09-10 21:33:20 +0800 | [diff] [blame] | 172 | if (!test_and_clear_bit(ring_id, (void *)s->tlb_handle_pending)) |
Zhi Wang | 1786571 | 2016-05-01 19:02:37 -0400 | [diff] [blame] | 173 | return; |
| 174 | |
| 175 | reg = _MMIO(regs[ring_id]); |
| 176 | |
Arkadiusz Hiler | 1c860a3 | 2016-10-21 13:11:50 +0200 | [diff] [blame] | 177 | /* WaForceWakeRenderDuringMmioTLBInvalidate:skl |
| 178 | * we need to put a forcewake when invalidating RCS TLB caches, |
| 179 | * otherwise device can go to RC6 state and interrupt invalidation |
| 180 | * process |
| 181 | */ |
| 182 | fw = intel_uncore_forcewake_for_reg(dev_priv, reg, |
| 183 | FW_REG_READ | FW_REG_WRITE); |
Xu Han | e3476c0 | 2017-03-29 10:13:59 +0800 | [diff] [blame] | 184 | if (ring_id == RCS && (IS_SKYLAKE(dev_priv) || IS_KABYLAKE(dev_priv))) |
Arkadiusz Hiler | 1c860a3 | 2016-10-21 13:11:50 +0200 | [diff] [blame] | 185 | fw |= FORCEWAKE_RENDER; |
Zhi Wang | 1786571 | 2016-05-01 19:02:37 -0400 | [diff] [blame] | 186 | |
Arkadiusz Hiler | 1c860a3 | 2016-10-21 13:11:50 +0200 | [diff] [blame] | 187 | intel_uncore_forcewake_get(dev_priv, fw); |
| 188 | |
| 189 | I915_WRITE_FW(reg, 0x1); |
| 190 | |
| 191 | if (wait_for_atomic((I915_READ_FW(reg) == 0), 50)) |
Tina Zhang | 695fbc0 | 2017-03-10 04:26:53 -0500 | [diff] [blame] | 192 | gvt_vgpu_err("timeout in invalidate ring (%d) tlb\n", ring_id); |
Ping Gao | f24940e | 2016-10-27 14:37:41 +0800 | [diff] [blame] | 193 | else |
| 194 | vgpu_vreg(vgpu, regs[ring_id]) = 0; |
Zhi Wang | 1786571 | 2016-05-01 19:02:37 -0400 | [diff] [blame] | 195 | |
Arkadiusz Hiler | 1c860a3 | 2016-10-21 13:11:50 +0200 | [diff] [blame] | 196 | intel_uncore_forcewake_put(dev_priv, fw); |
| 197 | |
Zhi Wang | 1786571 | 2016-05-01 19:02:37 -0400 | [diff] [blame] | 198 | gvt_dbg_core("invalidate TLB for ring %d\n", ring_id); |
| 199 | } |
| 200 | |
Weinan Li | e47107a | 2017-12-13 10:47:00 +0800 | [diff] [blame^] | 201 | static void switch_mocs(struct intel_vgpu *pre, struct intel_vgpu *next, |
| 202 | int ring_id) |
Zhi Wang | 1786571 | 2016-05-01 19:02:37 -0400 | [diff] [blame] | 203 | { |
Weinan Li | e47107a | 2017-12-13 10:47:00 +0800 | [diff] [blame^] | 204 | struct drm_i915_private *dev_priv; |
Zhi Wang | 1786571 | 2016-05-01 19:02:37 -0400 | [diff] [blame] | 205 | i915_reg_t offset, l3_offset; |
| 206 | u32 regs[] = { |
| 207 | [RCS] = 0xc800, |
| 208 | [VCS] = 0xc900, |
| 209 | [VCS2] = 0xca00, |
| 210 | [BCS] = 0xcc00, |
| 211 | [VECS] = 0xcb00, |
| 212 | }; |
| 213 | int i; |
| 214 | |
Weinan Li | e47107a | 2017-12-13 10:47:00 +0800 | [diff] [blame^] | 215 | dev_priv = pre ? pre->gvt->dev_priv : next->gvt->dev_priv; |
Zhi Wang | 1786571 | 2016-05-01 19:02:37 -0400 | [diff] [blame] | 216 | if (WARN_ON(ring_id >= ARRAY_SIZE(regs))) |
| 217 | return; |
| 218 | |
Zhenyu Wang | 946260e | 2016-10-22 13:21:45 +0800 | [diff] [blame] | 219 | offset.reg = regs[ring_id]; |
Weinan Li | e47107a | 2017-12-13 10:47:00 +0800 | [diff] [blame^] | 220 | |
Zhi Wang | 1786571 | 2016-05-01 19:02:37 -0400 | [diff] [blame] | 221 | for (i = 0; i < 64; i++) { |
Weinan Li | e47107a | 2017-12-13 10:47:00 +0800 | [diff] [blame^] | 222 | if (pre) |
| 223 | vgpu_vreg(pre, offset) = |
| 224 | I915_READ_FW(offset); |
| 225 | else |
| 226 | gen9_render_mocs[ring_id][i] = |
| 227 | I915_READ_FW(offset); |
| 228 | |
| 229 | if (next) |
| 230 | I915_WRITE_FW(offset, vgpu_vreg(next, offset)); |
| 231 | else |
| 232 | I915_WRITE_FW(offset, gen9_render_mocs[ring_id][i]); |
| 233 | |
Zhi Wang | 1786571 | 2016-05-01 19:02:37 -0400 | [diff] [blame] | 234 | offset.reg += 4; |
| 235 | } |
| 236 | |
| 237 | if (ring_id == RCS) { |
| 238 | l3_offset.reg = 0xb020; |
| 239 | for (i = 0; i < 32; i++) { |
Weinan Li | e47107a | 2017-12-13 10:47:00 +0800 | [diff] [blame^] | 240 | if (pre) |
| 241 | vgpu_vreg(pre, l3_offset) = |
| 242 | I915_READ_FW(l3_offset); |
| 243 | else |
| 244 | gen9_render_mocs_L3[i] = |
| 245 | I915_READ_FW(l3_offset); |
| 246 | if (next) |
| 247 | I915_WRITE_FW(l3_offset, |
| 248 | vgpu_vreg(next, l3_offset)); |
| 249 | else |
| 250 | I915_WRITE_FW(l3_offset, |
| 251 | gen9_render_mocs_L3[i]); |
Zhi Wang | 1786571 | 2016-05-01 19:02:37 -0400 | [diff] [blame] | 252 | |
Zhi Wang | 1786571 | 2016-05-01 19:02:37 -0400 | [diff] [blame] | 253 | l3_offset.reg += 4; |
| 254 | } |
| 255 | } |
| 256 | } |
| 257 | |
Chuanxiao Dong | bc6a1c8 | 2017-02-14 15:14:05 +0800 | [diff] [blame] | 258 | #define CTX_CONTEXT_CONTROL_VAL 0x03 |
| 259 | |
Weinan Li | e47107a | 2017-12-13 10:47:00 +0800 | [diff] [blame^] | 260 | /* Switch ring mmio values (context). */ |
| 261 | static void switch_mmio(struct intel_vgpu *pre, |
| 262 | struct intel_vgpu *next, |
| 263 | int ring_id) |
Zhi Wang | 1786571 | 2016-05-01 19:02:37 -0400 | [diff] [blame] | 264 | { |
Weinan Li | e47107a | 2017-12-13 10:47:00 +0800 | [diff] [blame^] | 265 | struct drm_i915_private *dev_priv; |
| 266 | struct intel_vgpu_submission *s; |
| 267 | u32 *reg_state, ctx_ctrl; |
Chuanxiao Dong | bc6a1c8 | 2017-02-14 15:14:05 +0800 | [diff] [blame] | 268 | u32 inhibit_mask = |
| 269 | _MASKED_BIT_ENABLE(CTX_CTRL_ENGINE_CTX_RESTORE_INHIBIT); |
Changbin Du | 8316488 | 2017-12-08 14:56:21 +0800 | [diff] [blame] | 270 | struct engine_mmio *mmio; |
Weinan Li | e47107a | 2017-12-13 10:47:00 +0800 | [diff] [blame^] | 271 | u32 old_v, new_v; |
Zhi Wang | 1786571 | 2016-05-01 19:02:37 -0400 | [diff] [blame] | 272 | |
Weinan Li | e47107a | 2017-12-13 10:47:00 +0800 | [diff] [blame^] | 273 | dev_priv = pre ? pre->gvt->dev_priv : next->gvt->dev_priv; |
Changbin Du | 8316488 | 2017-12-08 14:56:21 +0800 | [diff] [blame] | 274 | if (IS_SKYLAKE(dev_priv) || IS_KABYLAKE(dev_priv)) |
Weinan Li | e47107a | 2017-12-13 10:47:00 +0800 | [diff] [blame^] | 275 | switch_mocs(pre, next, ring_id); |
Zhi Wang | 1786571 | 2016-05-01 19:02:37 -0400 | [diff] [blame] | 276 | |
Weinan Li | e47107a | 2017-12-13 10:47:00 +0800 | [diff] [blame^] | 277 | mmio = dev_priv->gvt->engine_mmio_list; |
Changbin Du | 8316488 | 2017-12-08 14:56:21 +0800 | [diff] [blame] | 278 | while (i915_mmio_reg_offset((mmio++)->reg)) { |
Zhi Wang | 1786571 | 2016-05-01 19:02:37 -0400 | [diff] [blame] | 279 | if (mmio->ring_id != ring_id) |
| 280 | continue; |
Weinan Li | e47107a | 2017-12-13 10:47:00 +0800 | [diff] [blame^] | 281 | // save |
| 282 | if (pre) { |
| 283 | vgpu_vreg(pre, mmio->reg) = I915_READ_FW(mmio->reg); |
| 284 | if (mmio->mask) |
| 285 | vgpu_vreg(pre, mmio->reg) &= |
| 286 | ~(mmio->mask << 16); |
| 287 | old_v = vgpu_vreg(pre, mmio->reg); |
Zhi Wang | 1786571 | 2016-05-01 19:02:37 -0400 | [diff] [blame] | 288 | } else |
Weinan Li | e47107a | 2017-12-13 10:47:00 +0800 | [diff] [blame^] | 289 | old_v = mmio->value = I915_READ_FW(mmio->reg); |
Zhi Wang | 1786571 | 2016-05-01 19:02:37 -0400 | [diff] [blame] | 290 | |
Weinan Li | e47107a | 2017-12-13 10:47:00 +0800 | [diff] [blame^] | 291 | // restore |
| 292 | if (next) { |
| 293 | s = &next->submission; |
| 294 | reg_state = |
| 295 | s->shadow_ctx->engine[ring_id].lrc_reg_state; |
| 296 | ctx_ctrl = reg_state[CTX_CONTEXT_CONTROL_VAL]; |
| 297 | /* |
| 298 | * if it is an inhibit context, load in_context mmio |
| 299 | * into HW by mmio write. If it is not, skip this mmio |
| 300 | * write. |
| 301 | */ |
| 302 | if (mmio->in_context && |
| 303 | (ctx_ctrl & inhibit_mask) != inhibit_mask) |
| 304 | continue; |
Chuanxiao Dong | 2345ab1 | 2017-05-08 09:27:39 +0800 | [diff] [blame] | 305 | |
Weinan Li | e47107a | 2017-12-13 10:47:00 +0800 | [diff] [blame^] | 306 | if (mmio->mask) |
| 307 | new_v = vgpu_vreg(next, mmio->reg) | |
| 308 | (mmio->mask << 16); |
| 309 | else |
| 310 | new_v = vgpu_vreg(next, mmio->reg); |
| 311 | } else { |
| 312 | if (mmio->in_context) |
| 313 | continue; |
| 314 | if (mmio->mask) |
| 315 | new_v = mmio->value | (mmio->mask << 16); |
| 316 | else |
| 317 | new_v = mmio->value; |
| 318 | } |
Zhi Wang | 1786571 | 2016-05-01 19:02:37 -0400 | [diff] [blame] | 319 | |
Weinan Li | e47107a | 2017-12-13 10:47:00 +0800 | [diff] [blame^] | 320 | I915_WRITE_FW(mmio->reg, new_v); |
| 321 | |
| 322 | trace_render_mmio(pre ? pre->id : 0, |
| 323 | next ? next->id : 0, |
| 324 | "switch", |
Xiong Zhang | 7fb6a7d | 2017-05-23 05:38:08 +0800 | [diff] [blame] | 325 | i915_mmio_reg_offset(mmio->reg), |
Weinan Li | e47107a | 2017-12-13 10:47:00 +0800 | [diff] [blame^] | 326 | old_v, new_v); |
Zhi Wang | 1786571 | 2016-05-01 19:02:37 -0400 | [diff] [blame] | 327 | } |
Weinan Li | e47107a | 2017-12-13 10:47:00 +0800 | [diff] [blame^] | 328 | |
| 329 | if (next) |
| 330 | handle_tlb_pending_event(next, ring_id); |
Zhi Wang | 1786571 | 2016-05-01 19:02:37 -0400 | [diff] [blame] | 331 | } |
Changbin Du | 0e86cc9 | 2017-05-04 10:52:38 +0800 | [diff] [blame] | 332 | |
| 333 | /** |
| 334 | * intel_gvt_switch_render_mmio - switch mmio context of specific engine |
| 335 | * @pre: the last vGPU that own the engine |
| 336 | * @next: the vGPU to switch to |
| 337 | * @ring_id: specify the engine |
| 338 | * |
| 339 | * If pre is null indicates that host own the engine. If next is null |
| 340 | * indicates that we are switching to host workload. |
| 341 | */ |
| 342 | void intel_gvt_switch_mmio(struct intel_vgpu *pre, |
| 343 | struct intel_vgpu *next, int ring_id) |
| 344 | { |
Changbin Du | 4671ea2 | 2017-06-23 15:45:32 +0800 | [diff] [blame] | 345 | struct drm_i915_private *dev_priv; |
| 346 | |
Changbin Du | 0e86cc9 | 2017-05-04 10:52:38 +0800 | [diff] [blame] | 347 | if (WARN_ON(!pre && !next)) |
| 348 | return; |
| 349 | |
| 350 | gvt_dbg_render("switch ring %d from %s to %s\n", ring_id, |
| 351 | pre ? "vGPU" : "host", next ? "vGPU" : "HOST"); |
| 352 | |
Changbin Du | 4671ea2 | 2017-06-23 15:45:32 +0800 | [diff] [blame] | 353 | dev_priv = pre ? pre->gvt->dev_priv : next->gvt->dev_priv; |
| 354 | |
| 355 | /** |
| 356 | * We are using raw mmio access wrapper to improve the |
| 357 | * performace for batch mmio read/write, so we need |
| 358 | * handle forcewake mannually. |
| 359 | */ |
| 360 | intel_uncore_forcewake_get(dev_priv, FORCEWAKE_ALL); |
Weinan Li | e47107a | 2017-12-13 10:47:00 +0800 | [diff] [blame^] | 361 | switch_mmio(pre, next, ring_id); |
Changbin Du | 4671ea2 | 2017-06-23 15:45:32 +0800 | [diff] [blame] | 362 | intel_uncore_forcewake_put(dev_priv, FORCEWAKE_ALL); |
Changbin Du | 0e86cc9 | 2017-05-04 10:52:38 +0800 | [diff] [blame] | 363 | } |
Changbin Du | 8316488 | 2017-12-08 14:56:21 +0800 | [diff] [blame] | 364 | |
| 365 | /** |
| 366 | * intel_gvt_init_engine_mmio_context - Initiate the engine mmio list |
| 367 | * @gvt: GVT device |
| 368 | * |
| 369 | */ |
| 370 | void intel_gvt_init_engine_mmio_context(struct intel_gvt *gvt) |
| 371 | { |
| 372 | if (IS_SKYLAKE(gvt->dev_priv) || IS_KABYLAKE(gvt->dev_priv)) |
| 373 | gvt->engine_mmio_list = gen9_engine_mmio_list; |
| 374 | else |
| 375 | gvt->engine_mmio_list = gen8_engine_mmio_list; |
| 376 | } |