b.liu | e958203 | 2025-04-17 19:18:16 +0800 | [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 | * Ke Yu |
| 25 | * Zhiyuan Lv <zhiyuan.lv@intel.com> |
| 26 | * |
| 27 | * Contributors: |
| 28 | * Terrence Xu <terrence.xu@intel.com> |
| 29 | * Changbin Du <changbin.du@intel.com> |
| 30 | * Bing Niu <bing.niu@intel.com> |
| 31 | * Zhi Wang <zhi.a.wang@intel.com> |
| 32 | * |
| 33 | */ |
| 34 | |
| 35 | #include "i915_drv.h" |
| 36 | #include "gvt.h" |
| 37 | |
| 38 | static int get_edp_pipe(struct intel_vgpu *vgpu) |
| 39 | { |
| 40 | u32 data = vgpu_vreg(vgpu, _TRANS_DDI_FUNC_CTL_EDP); |
| 41 | int pipe = -1; |
| 42 | |
| 43 | switch (data & TRANS_DDI_EDP_INPUT_MASK) { |
| 44 | case TRANS_DDI_EDP_INPUT_A_ON: |
| 45 | case TRANS_DDI_EDP_INPUT_A_ONOFF: |
| 46 | pipe = PIPE_A; |
| 47 | break; |
| 48 | case TRANS_DDI_EDP_INPUT_B_ONOFF: |
| 49 | pipe = PIPE_B; |
| 50 | break; |
| 51 | case TRANS_DDI_EDP_INPUT_C_ONOFF: |
| 52 | pipe = PIPE_C; |
| 53 | break; |
| 54 | } |
| 55 | return pipe; |
| 56 | } |
| 57 | |
| 58 | static int edp_pipe_is_enabled(struct intel_vgpu *vgpu) |
| 59 | { |
| 60 | struct drm_i915_private *dev_priv = vgpu->gvt->dev_priv; |
| 61 | |
| 62 | if (!(vgpu_vreg_t(vgpu, PIPECONF(_PIPE_EDP)) & PIPECONF_ENABLE)) |
| 63 | return 0; |
| 64 | |
| 65 | if (!(vgpu_vreg(vgpu, _TRANS_DDI_FUNC_CTL_EDP) & TRANS_DDI_FUNC_ENABLE)) |
| 66 | return 0; |
| 67 | return 1; |
| 68 | } |
| 69 | |
| 70 | int pipe_is_enabled(struct intel_vgpu *vgpu, int pipe) |
| 71 | { |
| 72 | struct drm_i915_private *dev_priv = vgpu->gvt->dev_priv; |
| 73 | |
| 74 | if (WARN_ON(pipe < PIPE_A || pipe >= I915_MAX_PIPES)) |
| 75 | return -EINVAL; |
| 76 | |
| 77 | if (vgpu_vreg_t(vgpu, PIPECONF(pipe)) & PIPECONF_ENABLE) |
| 78 | return 1; |
| 79 | |
| 80 | if (edp_pipe_is_enabled(vgpu) && |
| 81 | get_edp_pipe(vgpu) == pipe) |
| 82 | return 1; |
| 83 | return 0; |
| 84 | } |
| 85 | |
| 86 | static unsigned char virtual_dp_monitor_edid[GVT_EDID_NUM][EDID_SIZE] = { |
| 87 | { |
| 88 | /* EDID with 1024x768 as its resolution */ |
| 89 | /*Header*/ |
| 90 | 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, |
| 91 | /* Vendor & Product Identification */ |
| 92 | 0x22, 0xf0, 0x54, 0x29, 0x00, 0x00, 0x00, 0x00, 0x04, 0x17, |
| 93 | /* Version & Revision */ |
| 94 | 0x01, 0x04, |
| 95 | /* Basic Display Parameters & Features */ |
| 96 | 0xa5, 0x34, 0x20, 0x78, 0x23, |
| 97 | /* Color Characteristics */ |
| 98 | 0xfc, 0x81, 0xa4, 0x55, 0x4d, 0x9d, 0x25, 0x12, 0x50, 0x54, |
| 99 | /* Established Timings: maximum resolution is 1024x768 */ |
| 100 | 0x21, 0x08, 0x00, |
| 101 | /* Standard Timings. All invalid */ |
| 102 | 0x00, 0xc0, 0x00, 0xc0, 0x00, 0x40, 0x00, 0x80, 0x00, 0x00, |
| 103 | 0x00, 0x40, 0x00, 0x00, 0x00, 0x01, |
| 104 | /* 18 Byte Data Blocks 1: invalid */ |
| 105 | 0x00, 0x00, 0x80, 0xa0, 0x70, 0xb0, |
| 106 | 0x23, 0x40, 0x30, 0x20, 0x36, 0x00, 0x06, 0x44, 0x21, 0x00, 0x00, 0x1a, |
| 107 | /* 18 Byte Data Blocks 2: invalid */ |
| 108 | 0x00, 0x00, 0x00, 0xfd, 0x00, 0x18, 0x3c, 0x18, 0x50, 0x11, 0x00, 0x0a, |
| 109 | 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, |
| 110 | /* 18 Byte Data Blocks 3: invalid */ |
| 111 | 0x00, 0x00, 0x00, 0xfc, 0x00, 0x48, |
| 112 | 0x50, 0x20, 0x5a, 0x52, 0x32, 0x34, 0x34, 0x30, 0x77, 0x0a, 0x20, 0x20, |
| 113 | /* 18 Byte Data Blocks 4: invalid */ |
| 114 | 0x00, 0x00, 0x00, 0xff, 0x00, 0x43, 0x4e, 0x34, 0x33, 0x30, 0x34, 0x30, |
| 115 | 0x44, 0x58, 0x51, 0x0a, 0x20, 0x20, |
| 116 | /* Extension Block Count */ |
| 117 | 0x00, |
| 118 | /* Checksum */ |
| 119 | 0xef, |
| 120 | }, |
| 121 | { |
| 122 | /* EDID with 1920x1200 as its resolution */ |
| 123 | /*Header*/ |
| 124 | 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, |
| 125 | /* Vendor & Product Identification */ |
| 126 | 0x22, 0xf0, 0x54, 0x29, 0x00, 0x00, 0x00, 0x00, 0x04, 0x17, |
| 127 | /* Version & Revision */ |
| 128 | 0x01, 0x04, |
| 129 | /* Basic Display Parameters & Features */ |
| 130 | 0xa5, 0x34, 0x20, 0x78, 0x23, |
| 131 | /* Color Characteristics */ |
| 132 | 0xfc, 0x81, 0xa4, 0x55, 0x4d, 0x9d, 0x25, 0x12, 0x50, 0x54, |
| 133 | /* Established Timings: maximum resolution is 1024x768 */ |
| 134 | 0x21, 0x08, 0x00, |
| 135 | /* |
| 136 | * Standard Timings. |
| 137 | * below new resolutions can be supported: |
| 138 | * 1920x1080, 1280x720, 1280x960, 1280x1024, |
| 139 | * 1440x900, 1600x1200, 1680x1050 |
| 140 | */ |
| 141 | 0xd1, 0xc0, 0x81, 0xc0, 0x81, 0x40, 0x81, 0x80, 0x95, 0x00, |
| 142 | 0xa9, 0x40, 0xb3, 0x00, 0x01, 0x01, |
| 143 | /* 18 Byte Data Blocks 1: max resolution is 1920x1200 */ |
| 144 | 0x28, 0x3c, 0x80, 0xa0, 0x70, 0xb0, |
| 145 | 0x23, 0x40, 0x30, 0x20, 0x36, 0x00, 0x06, 0x44, 0x21, 0x00, 0x00, 0x1a, |
| 146 | /* 18 Byte Data Blocks 2: invalid */ |
| 147 | 0x00, 0x00, 0x00, 0xfd, 0x00, 0x18, 0x3c, 0x18, 0x50, 0x11, 0x00, 0x0a, |
| 148 | 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, |
| 149 | /* 18 Byte Data Blocks 3: invalid */ |
| 150 | 0x00, 0x00, 0x00, 0xfc, 0x00, 0x48, |
| 151 | 0x50, 0x20, 0x5a, 0x52, 0x32, 0x34, 0x34, 0x30, 0x77, 0x0a, 0x20, 0x20, |
| 152 | /* 18 Byte Data Blocks 4: invalid */ |
| 153 | 0x00, 0x00, 0x00, 0xff, 0x00, 0x43, 0x4e, 0x34, 0x33, 0x30, 0x34, 0x30, |
| 154 | 0x44, 0x58, 0x51, 0x0a, 0x20, 0x20, |
| 155 | /* Extension Block Count */ |
| 156 | 0x00, |
| 157 | /* Checksum */ |
| 158 | 0x45, |
| 159 | }, |
| 160 | }; |
| 161 | |
| 162 | #define DPCD_HEADER_SIZE 0xb |
| 163 | |
| 164 | /* let the virtual display supports DP1.2 */ |
| 165 | static u8 dpcd_fix_data[DPCD_HEADER_SIZE] = { |
| 166 | 0x12, 0x014, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 |
| 167 | }; |
| 168 | |
| 169 | static void emulate_monitor_status_change(struct intel_vgpu *vgpu) |
| 170 | { |
| 171 | struct drm_i915_private *dev_priv = vgpu->gvt->dev_priv; |
| 172 | int pipe; |
| 173 | |
| 174 | if (IS_BROXTON(dev_priv)) { |
| 175 | enum transcoder trans; |
| 176 | enum port port; |
| 177 | |
| 178 | /* Clear PIPE, DDI, PHY, HPD before setting new */ |
| 179 | vgpu_vreg_t(vgpu, GEN8_DE_PORT_ISR) &= ~(BXT_DE_PORT_HP_DDIA | |
| 180 | BXT_DE_PORT_HP_DDIB | |
| 181 | BXT_DE_PORT_HP_DDIC); |
| 182 | |
| 183 | for_each_pipe(dev_priv, pipe) { |
| 184 | vgpu_vreg_t(vgpu, PIPECONF(pipe)) &= |
| 185 | ~(PIPECONF_ENABLE | I965_PIPECONF_ACTIVE); |
| 186 | vgpu_vreg_t(vgpu, DSPCNTR(pipe)) &= ~DISPLAY_PLANE_ENABLE; |
| 187 | vgpu_vreg_t(vgpu, SPRCTL(pipe)) &= ~SPRITE_ENABLE; |
| 188 | vgpu_vreg_t(vgpu, CURCNTR(pipe)) &= ~MCURSOR_MODE; |
| 189 | vgpu_vreg_t(vgpu, CURCNTR(pipe)) |= MCURSOR_MODE_DISABLE; |
| 190 | } |
| 191 | |
| 192 | for (trans = TRANSCODER_A; trans <= TRANSCODER_EDP; trans++) { |
| 193 | vgpu_vreg_t(vgpu, TRANS_DDI_FUNC_CTL(trans)) &= |
| 194 | ~(TRANS_DDI_BPC_MASK | TRANS_DDI_MODE_SELECT_MASK | |
| 195 | TRANS_DDI_PORT_MASK | TRANS_DDI_FUNC_ENABLE); |
| 196 | } |
| 197 | vgpu_vreg_t(vgpu, TRANS_DDI_FUNC_CTL(TRANSCODER_A)) &= |
| 198 | ~(TRANS_DDI_BPC_MASK | TRANS_DDI_MODE_SELECT_MASK | |
| 199 | TRANS_DDI_PORT_MASK); |
| 200 | |
| 201 | for (port = PORT_A; port <= PORT_C; port++) { |
| 202 | vgpu_vreg_t(vgpu, BXT_PHY_CTL(port)) &= |
| 203 | ~BXT_PHY_LANE_ENABLED; |
| 204 | vgpu_vreg_t(vgpu, BXT_PHY_CTL(port)) |= |
| 205 | (BXT_PHY_CMNLANE_POWERDOWN_ACK | |
| 206 | BXT_PHY_LANE_POWERDOWN_ACK); |
| 207 | |
| 208 | vgpu_vreg_t(vgpu, BXT_PORT_PLL_ENABLE(port)) &= |
| 209 | ~(PORT_PLL_POWER_STATE | PORT_PLL_POWER_ENABLE | |
| 210 | PORT_PLL_REF_SEL | PORT_PLL_LOCK | |
| 211 | PORT_PLL_ENABLE); |
| 212 | |
| 213 | vgpu_vreg_t(vgpu, DDI_BUF_CTL(port)) &= |
| 214 | ~(DDI_INIT_DISPLAY_DETECTED | |
| 215 | DDI_BUF_CTL_ENABLE); |
| 216 | vgpu_vreg_t(vgpu, DDI_BUF_CTL(port)) |= DDI_BUF_IS_IDLE; |
| 217 | } |
| 218 | vgpu_vreg_t(vgpu, PCH_PORT_HOTPLUG) &= |
| 219 | ~(PORTA_HOTPLUG_ENABLE | PORTA_HOTPLUG_STATUS_MASK); |
| 220 | vgpu_vreg_t(vgpu, PCH_PORT_HOTPLUG) &= |
| 221 | ~(PORTB_HOTPLUG_ENABLE | PORTB_HOTPLUG_STATUS_MASK); |
| 222 | vgpu_vreg_t(vgpu, PCH_PORT_HOTPLUG) &= |
| 223 | ~(PORTC_HOTPLUG_ENABLE | PORTC_HOTPLUG_STATUS_MASK); |
| 224 | /* No hpd_invert set in vgpu vbt, need to clear invert mask */ |
| 225 | vgpu_vreg_t(vgpu, PCH_PORT_HOTPLUG) &= ~BXT_DDI_HPD_INVERT_MASK; |
| 226 | vgpu_vreg_t(vgpu, GEN8_DE_PORT_ISR) &= ~BXT_DE_PORT_HOTPLUG_MASK; |
| 227 | |
| 228 | vgpu_vreg_t(vgpu, BXT_P_CR_GT_DISP_PWRON) &= ~(BIT(0) | BIT(1)); |
| 229 | vgpu_vreg_t(vgpu, BXT_PORT_CL1CM_DW0(DPIO_PHY0)) &= |
| 230 | ~PHY_POWER_GOOD; |
| 231 | vgpu_vreg_t(vgpu, BXT_PORT_CL1CM_DW0(DPIO_PHY1)) &= |
| 232 | ~PHY_POWER_GOOD; |
| 233 | vgpu_vreg_t(vgpu, BXT_PHY_CTL_FAMILY(DPIO_PHY0)) &= ~BIT(30); |
| 234 | vgpu_vreg_t(vgpu, BXT_PHY_CTL_FAMILY(DPIO_PHY1)) &= ~BIT(30); |
| 235 | |
| 236 | vgpu_vreg_t(vgpu, SFUSE_STRAP) &= ~SFUSE_STRAP_DDIB_DETECTED; |
| 237 | vgpu_vreg_t(vgpu, SFUSE_STRAP) &= ~SFUSE_STRAP_DDIC_DETECTED; |
| 238 | |
| 239 | /* |
| 240 | * Only 1 PIPE enabled in current vGPU display and PIPE_A is |
| 241 | * tied to TRANSCODER_A in HW, so it's safe to assume PIPE_A, |
| 242 | * TRANSCODER_A can be enabled. PORT_x depends on the input of |
| 243 | * setup_virtual_dp_monitor. |
| 244 | */ |
| 245 | vgpu_vreg_t(vgpu, PIPECONF(PIPE_A)) |= PIPECONF_ENABLE; |
| 246 | vgpu_vreg_t(vgpu, PIPECONF(PIPE_A)) |= I965_PIPECONF_ACTIVE; |
| 247 | |
| 248 | /* |
| 249 | * Golden M/N are calculated based on: |
| 250 | * 24 bpp, 4 lanes, 154000 pixel clk (from virtual EDID), |
| 251 | * DP link clk 1620 MHz and non-constant_n. |
| 252 | * TODO: calculate DP link symbol clk and stream clk m/n. |
| 253 | */ |
| 254 | vgpu_vreg_t(vgpu, PIPE_DATA_M1(TRANSCODER_A)) = 63 << TU_SIZE_SHIFT; |
| 255 | vgpu_vreg_t(vgpu, PIPE_DATA_M1(TRANSCODER_A)) |= 0x5b425e; |
| 256 | vgpu_vreg_t(vgpu, PIPE_DATA_N1(TRANSCODER_A)) = 0x800000; |
| 257 | vgpu_vreg_t(vgpu, PIPE_LINK_M1(TRANSCODER_A)) = 0x3cd6e; |
| 258 | vgpu_vreg_t(vgpu, PIPE_LINK_N1(TRANSCODER_A)) = 0x80000; |
| 259 | |
| 260 | /* Enable per-DDI/PORT vreg */ |
| 261 | if (intel_vgpu_has_monitor_on_port(vgpu, PORT_A)) { |
| 262 | vgpu_vreg_t(vgpu, BXT_P_CR_GT_DISP_PWRON) |= BIT(1); |
| 263 | vgpu_vreg_t(vgpu, BXT_PORT_CL1CM_DW0(DPIO_PHY1)) |= |
| 264 | PHY_POWER_GOOD; |
| 265 | vgpu_vreg_t(vgpu, BXT_PHY_CTL_FAMILY(DPIO_PHY1)) |= |
| 266 | BIT(30); |
| 267 | vgpu_vreg_t(vgpu, BXT_PHY_CTL(PORT_A)) |= |
| 268 | BXT_PHY_LANE_ENABLED; |
| 269 | vgpu_vreg_t(vgpu, BXT_PHY_CTL(PORT_A)) &= |
| 270 | ~(BXT_PHY_CMNLANE_POWERDOWN_ACK | |
| 271 | BXT_PHY_LANE_POWERDOWN_ACK); |
| 272 | vgpu_vreg_t(vgpu, BXT_PORT_PLL_ENABLE(PORT_A)) |= |
| 273 | (PORT_PLL_POWER_STATE | PORT_PLL_POWER_ENABLE | |
| 274 | PORT_PLL_REF_SEL | PORT_PLL_LOCK | |
| 275 | PORT_PLL_ENABLE); |
| 276 | vgpu_vreg_t(vgpu, DDI_BUF_CTL(PORT_A)) |= |
| 277 | (DDI_BUF_CTL_ENABLE | DDI_INIT_DISPLAY_DETECTED); |
| 278 | vgpu_vreg_t(vgpu, DDI_BUF_CTL(PORT_A)) &= |
| 279 | ~DDI_BUF_IS_IDLE; |
| 280 | vgpu_vreg_t(vgpu, TRANS_DDI_FUNC_CTL(TRANSCODER_EDP)) |= |
| 281 | (TRANS_DDI_BPC_8 | TRANS_DDI_MODE_SELECT_DP_SST | |
| 282 | TRANS_DDI_FUNC_ENABLE); |
| 283 | vgpu_vreg_t(vgpu, PCH_PORT_HOTPLUG) |= |
| 284 | PORTA_HOTPLUG_ENABLE; |
| 285 | vgpu_vreg_t(vgpu, GEN8_DE_PORT_ISR) |= |
| 286 | BXT_DE_PORT_HP_DDIA; |
| 287 | } |
| 288 | |
| 289 | if (intel_vgpu_has_monitor_on_port(vgpu, PORT_B)) { |
| 290 | vgpu_vreg_t(vgpu, SFUSE_STRAP) |= SFUSE_STRAP_DDIB_DETECTED; |
| 291 | vgpu_vreg_t(vgpu, BXT_P_CR_GT_DISP_PWRON) |= BIT(0); |
| 292 | vgpu_vreg_t(vgpu, BXT_PORT_CL1CM_DW0(DPIO_PHY0)) |= |
| 293 | PHY_POWER_GOOD; |
| 294 | vgpu_vreg_t(vgpu, BXT_PHY_CTL_FAMILY(DPIO_PHY0)) |= |
| 295 | BIT(30); |
| 296 | vgpu_vreg_t(vgpu, BXT_PHY_CTL(PORT_B)) |= |
| 297 | BXT_PHY_LANE_ENABLED; |
| 298 | vgpu_vreg_t(vgpu, BXT_PHY_CTL(PORT_B)) &= |
| 299 | ~(BXT_PHY_CMNLANE_POWERDOWN_ACK | |
| 300 | BXT_PHY_LANE_POWERDOWN_ACK); |
| 301 | vgpu_vreg_t(vgpu, BXT_PORT_PLL_ENABLE(PORT_B)) |= |
| 302 | (PORT_PLL_POWER_STATE | PORT_PLL_POWER_ENABLE | |
| 303 | PORT_PLL_REF_SEL | PORT_PLL_LOCK | |
| 304 | PORT_PLL_ENABLE); |
| 305 | vgpu_vreg_t(vgpu, DDI_BUF_CTL(PORT_B)) |= |
| 306 | DDI_BUF_CTL_ENABLE; |
| 307 | vgpu_vreg_t(vgpu, DDI_BUF_CTL(PORT_B)) &= |
| 308 | ~DDI_BUF_IS_IDLE; |
| 309 | vgpu_vreg_t(vgpu, TRANS_DDI_FUNC_CTL(TRANSCODER_A)) |= |
| 310 | (TRANS_DDI_BPC_8 | TRANS_DDI_MODE_SELECT_DP_SST | |
| 311 | (PORT_B << TRANS_DDI_PORT_SHIFT) | |
| 312 | TRANS_DDI_FUNC_ENABLE); |
| 313 | vgpu_vreg_t(vgpu, PCH_PORT_HOTPLUG) |= |
| 314 | PORTB_HOTPLUG_ENABLE; |
| 315 | vgpu_vreg_t(vgpu, GEN8_DE_PORT_ISR) |= |
| 316 | BXT_DE_PORT_HP_DDIB; |
| 317 | } |
| 318 | |
| 319 | if (intel_vgpu_has_monitor_on_port(vgpu, PORT_C)) { |
| 320 | vgpu_vreg_t(vgpu, SFUSE_STRAP) |= SFUSE_STRAP_DDIC_DETECTED; |
| 321 | vgpu_vreg_t(vgpu, BXT_P_CR_GT_DISP_PWRON) |= BIT(0); |
| 322 | vgpu_vreg_t(vgpu, BXT_PORT_CL1CM_DW0(DPIO_PHY0)) |= |
| 323 | PHY_POWER_GOOD; |
| 324 | vgpu_vreg_t(vgpu, BXT_PHY_CTL_FAMILY(DPIO_PHY0)) |= |
| 325 | BIT(30); |
| 326 | vgpu_vreg_t(vgpu, BXT_PHY_CTL(PORT_C)) |= |
| 327 | BXT_PHY_LANE_ENABLED; |
| 328 | vgpu_vreg_t(vgpu, BXT_PHY_CTL(PORT_C)) &= |
| 329 | ~(BXT_PHY_CMNLANE_POWERDOWN_ACK | |
| 330 | BXT_PHY_LANE_POWERDOWN_ACK); |
| 331 | vgpu_vreg_t(vgpu, BXT_PORT_PLL_ENABLE(PORT_C)) |= |
| 332 | (PORT_PLL_POWER_STATE | PORT_PLL_POWER_ENABLE | |
| 333 | PORT_PLL_REF_SEL | PORT_PLL_LOCK | |
| 334 | PORT_PLL_ENABLE); |
| 335 | vgpu_vreg_t(vgpu, DDI_BUF_CTL(PORT_C)) |= |
| 336 | DDI_BUF_CTL_ENABLE; |
| 337 | vgpu_vreg_t(vgpu, DDI_BUF_CTL(PORT_C)) &= |
| 338 | ~DDI_BUF_IS_IDLE; |
| 339 | vgpu_vreg_t(vgpu, TRANS_DDI_FUNC_CTL(TRANSCODER_A)) |= |
| 340 | (TRANS_DDI_BPC_8 | TRANS_DDI_MODE_SELECT_DP_SST | |
| 341 | (PORT_B << TRANS_DDI_PORT_SHIFT) | |
| 342 | TRANS_DDI_FUNC_ENABLE); |
| 343 | vgpu_vreg_t(vgpu, PCH_PORT_HOTPLUG) |= |
| 344 | PORTC_HOTPLUG_ENABLE; |
| 345 | vgpu_vreg_t(vgpu, GEN8_DE_PORT_ISR) |= |
| 346 | BXT_DE_PORT_HP_DDIC; |
| 347 | } |
| 348 | |
| 349 | return; |
| 350 | } |
| 351 | |
| 352 | vgpu_vreg_t(vgpu, SDEISR) &= ~(SDE_PORTB_HOTPLUG_CPT | |
| 353 | SDE_PORTC_HOTPLUG_CPT | |
| 354 | SDE_PORTD_HOTPLUG_CPT); |
| 355 | |
| 356 | if (IS_SKYLAKE(dev_priv) || IS_KABYLAKE(dev_priv) || |
| 357 | IS_COFFEELAKE(dev_priv)) { |
| 358 | vgpu_vreg_t(vgpu, SDEISR) &= ~(SDE_PORTA_HOTPLUG_SPT | |
| 359 | SDE_PORTE_HOTPLUG_SPT); |
| 360 | vgpu_vreg_t(vgpu, SKL_FUSE_STATUS) |= |
| 361 | SKL_FUSE_DOWNLOAD_STATUS | |
| 362 | SKL_FUSE_PG_DIST_STATUS(SKL_PG0) | |
| 363 | SKL_FUSE_PG_DIST_STATUS(SKL_PG1) | |
| 364 | SKL_FUSE_PG_DIST_STATUS(SKL_PG2); |
| 365 | /* |
| 366 | * Only 1 PIPE enabled in current vGPU display and PIPE_A is |
| 367 | * tied to TRANSCODER_A in HW, so it's safe to assume PIPE_A, |
| 368 | * TRANSCODER_A can be enabled. PORT_x depends on the input of |
| 369 | * setup_virtual_dp_monitor, we can bind DPLL0 to any PORT_x |
| 370 | * so we fixed to DPLL0 here. |
| 371 | * Setup DPLL0: DP link clk 1620 MHz, non SSC, DP Mode |
| 372 | */ |
| 373 | vgpu_vreg_t(vgpu, DPLL_CTRL1) = |
| 374 | DPLL_CTRL1_OVERRIDE(DPLL_ID_SKL_DPLL0); |
| 375 | vgpu_vreg_t(vgpu, DPLL_CTRL1) |= |
| 376 | DPLL_CTRL1_LINK_RATE(DPLL_CTRL1_LINK_RATE_1620, DPLL_ID_SKL_DPLL0); |
| 377 | vgpu_vreg_t(vgpu, LCPLL1_CTL) = |
| 378 | LCPLL_PLL_ENABLE | LCPLL_PLL_LOCK; |
| 379 | vgpu_vreg_t(vgpu, DPLL_STATUS) = DPLL_LOCK(DPLL_ID_SKL_DPLL0); |
| 380 | /* |
| 381 | * Golden M/N are calculated based on: |
| 382 | * 24 bpp, 4 lanes, 154000 pixel clk (from virtual EDID), |
| 383 | * DP link clk 1620 MHz and non-constant_n. |
| 384 | * TODO: calculate DP link symbol clk and stream clk m/n. |
| 385 | */ |
| 386 | vgpu_vreg_t(vgpu, PIPE_DATA_M1(TRANSCODER_A)) = 63 << TU_SIZE_SHIFT; |
| 387 | vgpu_vreg_t(vgpu, PIPE_DATA_M1(TRANSCODER_A)) |= 0x5b425e; |
| 388 | vgpu_vreg_t(vgpu, PIPE_DATA_N1(TRANSCODER_A)) = 0x800000; |
| 389 | vgpu_vreg_t(vgpu, PIPE_LINK_M1(TRANSCODER_A)) = 0x3cd6e; |
| 390 | vgpu_vreg_t(vgpu, PIPE_LINK_N1(TRANSCODER_A)) = 0x80000; |
| 391 | } |
| 392 | |
| 393 | if (intel_vgpu_has_monitor_on_port(vgpu, PORT_B)) { |
| 394 | vgpu_vreg_t(vgpu, DPLL_CTRL2) &= |
| 395 | ~DPLL_CTRL2_DDI_CLK_OFF(PORT_B); |
| 396 | vgpu_vreg_t(vgpu, DPLL_CTRL2) |= |
| 397 | DPLL_CTRL2_DDI_CLK_SEL(DPLL_ID_SKL_DPLL0, PORT_B); |
| 398 | vgpu_vreg_t(vgpu, DPLL_CTRL2) |= |
| 399 | DPLL_CTRL2_DDI_SEL_OVERRIDE(PORT_B); |
| 400 | vgpu_vreg_t(vgpu, SFUSE_STRAP) |= SFUSE_STRAP_DDIB_DETECTED; |
| 401 | vgpu_vreg_t(vgpu, TRANS_DDI_FUNC_CTL(TRANSCODER_A)) &= |
| 402 | ~(TRANS_DDI_BPC_MASK | TRANS_DDI_MODE_SELECT_MASK | |
| 403 | TRANS_DDI_PORT_MASK); |
| 404 | vgpu_vreg_t(vgpu, TRANS_DDI_FUNC_CTL(TRANSCODER_A)) |= |
| 405 | (TRANS_DDI_BPC_8 | TRANS_DDI_MODE_SELECT_DVI | |
| 406 | (PORT_B << TRANS_DDI_PORT_SHIFT) | |
| 407 | TRANS_DDI_FUNC_ENABLE); |
| 408 | if (IS_BROADWELL(dev_priv)) { |
| 409 | vgpu_vreg_t(vgpu, PORT_CLK_SEL(PORT_B)) &= |
| 410 | ~PORT_CLK_SEL_MASK; |
| 411 | vgpu_vreg_t(vgpu, PORT_CLK_SEL(PORT_B)) |= |
| 412 | PORT_CLK_SEL_LCPLL_810; |
| 413 | } |
| 414 | vgpu_vreg_t(vgpu, DDI_BUF_CTL(PORT_B)) |= DDI_BUF_CTL_ENABLE; |
| 415 | vgpu_vreg_t(vgpu, DDI_BUF_CTL(PORT_B)) &= ~DDI_BUF_IS_IDLE; |
| 416 | vgpu_vreg_t(vgpu, SDEISR) |= SDE_PORTB_HOTPLUG_CPT; |
| 417 | } |
| 418 | |
| 419 | if (intel_vgpu_has_monitor_on_port(vgpu, PORT_C)) { |
| 420 | vgpu_vreg_t(vgpu, DPLL_CTRL2) &= |
| 421 | ~DPLL_CTRL2_DDI_CLK_OFF(PORT_C); |
| 422 | vgpu_vreg_t(vgpu, DPLL_CTRL2) |= |
| 423 | DPLL_CTRL2_DDI_CLK_SEL(DPLL_ID_SKL_DPLL0, PORT_C); |
| 424 | vgpu_vreg_t(vgpu, DPLL_CTRL2) |= |
| 425 | DPLL_CTRL2_DDI_SEL_OVERRIDE(PORT_C); |
| 426 | vgpu_vreg_t(vgpu, SDEISR) |= SDE_PORTC_HOTPLUG_CPT; |
| 427 | vgpu_vreg_t(vgpu, TRANS_DDI_FUNC_CTL(TRANSCODER_A)) &= |
| 428 | ~(TRANS_DDI_BPC_MASK | TRANS_DDI_MODE_SELECT_MASK | |
| 429 | TRANS_DDI_PORT_MASK); |
| 430 | vgpu_vreg_t(vgpu, TRANS_DDI_FUNC_CTL(TRANSCODER_A)) |= |
| 431 | (TRANS_DDI_BPC_8 | TRANS_DDI_MODE_SELECT_DVI | |
| 432 | (PORT_C << TRANS_DDI_PORT_SHIFT) | |
| 433 | TRANS_DDI_FUNC_ENABLE); |
| 434 | if (IS_BROADWELL(dev_priv)) { |
| 435 | vgpu_vreg_t(vgpu, PORT_CLK_SEL(PORT_C)) &= |
| 436 | ~PORT_CLK_SEL_MASK; |
| 437 | vgpu_vreg_t(vgpu, PORT_CLK_SEL(PORT_C)) |= |
| 438 | PORT_CLK_SEL_LCPLL_810; |
| 439 | } |
| 440 | vgpu_vreg_t(vgpu, DDI_BUF_CTL(PORT_C)) |= DDI_BUF_CTL_ENABLE; |
| 441 | vgpu_vreg_t(vgpu, DDI_BUF_CTL(PORT_C)) &= ~DDI_BUF_IS_IDLE; |
| 442 | vgpu_vreg_t(vgpu, SFUSE_STRAP) |= SFUSE_STRAP_DDIC_DETECTED; |
| 443 | } |
| 444 | |
| 445 | if (intel_vgpu_has_monitor_on_port(vgpu, PORT_D)) { |
| 446 | vgpu_vreg_t(vgpu, DPLL_CTRL2) &= |
| 447 | ~DPLL_CTRL2_DDI_CLK_OFF(PORT_D); |
| 448 | vgpu_vreg_t(vgpu, DPLL_CTRL2) |= |
| 449 | DPLL_CTRL2_DDI_CLK_SEL(DPLL_ID_SKL_DPLL0, PORT_D); |
| 450 | vgpu_vreg_t(vgpu, DPLL_CTRL2) |= |
| 451 | DPLL_CTRL2_DDI_SEL_OVERRIDE(PORT_D); |
| 452 | vgpu_vreg_t(vgpu, SDEISR) |= SDE_PORTD_HOTPLUG_CPT; |
| 453 | vgpu_vreg_t(vgpu, TRANS_DDI_FUNC_CTL(TRANSCODER_A)) &= |
| 454 | ~(TRANS_DDI_BPC_MASK | TRANS_DDI_MODE_SELECT_MASK | |
| 455 | TRANS_DDI_PORT_MASK); |
| 456 | vgpu_vreg_t(vgpu, TRANS_DDI_FUNC_CTL(TRANSCODER_A)) |= |
| 457 | (TRANS_DDI_BPC_8 | TRANS_DDI_MODE_SELECT_DVI | |
| 458 | (PORT_D << TRANS_DDI_PORT_SHIFT) | |
| 459 | TRANS_DDI_FUNC_ENABLE); |
| 460 | if (IS_BROADWELL(dev_priv)) { |
| 461 | vgpu_vreg_t(vgpu, PORT_CLK_SEL(PORT_D)) &= |
| 462 | ~PORT_CLK_SEL_MASK; |
| 463 | vgpu_vreg_t(vgpu, PORT_CLK_SEL(PORT_D)) |= |
| 464 | PORT_CLK_SEL_LCPLL_810; |
| 465 | } |
| 466 | vgpu_vreg_t(vgpu, DDI_BUF_CTL(PORT_D)) |= DDI_BUF_CTL_ENABLE; |
| 467 | vgpu_vreg_t(vgpu, DDI_BUF_CTL(PORT_D)) &= ~DDI_BUF_IS_IDLE; |
| 468 | vgpu_vreg_t(vgpu, SFUSE_STRAP) |= SFUSE_STRAP_DDID_DETECTED; |
| 469 | } |
| 470 | |
| 471 | if ((IS_SKYLAKE(dev_priv) || IS_KABYLAKE(dev_priv) || |
| 472 | IS_COFFEELAKE(dev_priv)) && |
| 473 | intel_vgpu_has_monitor_on_port(vgpu, PORT_E)) { |
| 474 | vgpu_vreg_t(vgpu, SDEISR) |= SDE_PORTE_HOTPLUG_SPT; |
| 475 | } |
| 476 | |
| 477 | if (intel_vgpu_has_monitor_on_port(vgpu, PORT_A)) { |
| 478 | if (IS_BROADWELL(dev_priv)) |
| 479 | vgpu_vreg_t(vgpu, GEN8_DE_PORT_ISR) |= |
| 480 | GEN8_PORT_DP_A_HOTPLUG; |
| 481 | else |
| 482 | vgpu_vreg_t(vgpu, SDEISR) |= SDE_PORTA_HOTPLUG_SPT; |
| 483 | |
| 484 | vgpu_vreg_t(vgpu, DDI_BUF_CTL(PORT_A)) |= DDI_INIT_DISPLAY_DETECTED; |
| 485 | } |
| 486 | |
| 487 | /* Clear host CRT status, so guest couldn't detect this host CRT. */ |
| 488 | if (IS_BROADWELL(dev_priv)) |
| 489 | vgpu_vreg_t(vgpu, PCH_ADPA) &= ~ADPA_CRT_HOTPLUG_MONITOR_MASK; |
| 490 | |
| 491 | /* Disable Primary/Sprite/Cursor plane */ |
| 492 | for_each_pipe(dev_priv, pipe) { |
| 493 | vgpu_vreg_t(vgpu, DSPCNTR(pipe)) &= ~DISPLAY_PLANE_ENABLE; |
| 494 | vgpu_vreg_t(vgpu, SPRCTL(pipe)) &= ~SPRITE_ENABLE; |
| 495 | vgpu_vreg_t(vgpu, CURCNTR(pipe)) &= ~MCURSOR_MODE; |
| 496 | vgpu_vreg_t(vgpu, CURCNTR(pipe)) |= MCURSOR_MODE_DISABLE; |
| 497 | } |
| 498 | |
| 499 | vgpu_vreg_t(vgpu, PIPECONF(PIPE_A)) |= PIPECONF_ENABLE; |
| 500 | } |
| 501 | |
| 502 | static void clean_virtual_dp_monitor(struct intel_vgpu *vgpu, int port_num) |
| 503 | { |
| 504 | struct intel_vgpu_port *port = intel_vgpu_port(vgpu, port_num); |
| 505 | |
| 506 | kfree(port->edid); |
| 507 | port->edid = NULL; |
| 508 | |
| 509 | kfree(port->dpcd); |
| 510 | port->dpcd = NULL; |
| 511 | } |
| 512 | |
| 513 | static int setup_virtual_dp_monitor(struct intel_vgpu *vgpu, int port_num, |
| 514 | int type, unsigned int resolution) |
| 515 | { |
| 516 | struct intel_vgpu_port *port = intel_vgpu_port(vgpu, port_num); |
| 517 | |
| 518 | if (WARN_ON(resolution >= GVT_EDID_NUM)) |
| 519 | return -EINVAL; |
| 520 | |
| 521 | port->edid = kzalloc(sizeof(*(port->edid)), GFP_KERNEL); |
| 522 | if (!port->edid) |
| 523 | return -ENOMEM; |
| 524 | |
| 525 | port->dpcd = kzalloc(sizeof(*(port->dpcd)), GFP_KERNEL); |
| 526 | if (!port->dpcd) { |
| 527 | kfree(port->edid); |
| 528 | return -ENOMEM; |
| 529 | } |
| 530 | |
| 531 | memcpy(port->edid->edid_block, virtual_dp_monitor_edid[resolution], |
| 532 | EDID_SIZE); |
| 533 | port->edid->data_valid = true; |
| 534 | |
| 535 | memcpy(port->dpcd->data, dpcd_fix_data, DPCD_HEADER_SIZE); |
| 536 | port->dpcd->data_valid = true; |
| 537 | port->dpcd->data[DPCD_SINK_COUNT] = 0x1; |
| 538 | port->type = type; |
| 539 | port->id = resolution; |
| 540 | |
| 541 | emulate_monitor_status_change(vgpu); |
| 542 | |
| 543 | return 0; |
| 544 | } |
| 545 | |
| 546 | /** |
| 547 | * intel_gvt_check_vblank_emulation - check if vblank emulation timer should |
| 548 | * be turned on/off when a virtual pipe is enabled/disabled. |
| 549 | * @gvt: a GVT device |
| 550 | * |
| 551 | * This function is used to turn on/off vblank timer according to currently |
| 552 | * enabled/disabled virtual pipes. |
| 553 | * |
| 554 | */ |
| 555 | void intel_gvt_check_vblank_emulation(struct intel_gvt *gvt) |
| 556 | { |
| 557 | struct intel_gvt_irq *irq = &gvt->irq; |
| 558 | struct intel_vgpu *vgpu; |
| 559 | int pipe, id; |
| 560 | int found = false; |
| 561 | |
| 562 | mutex_lock(&gvt->lock); |
| 563 | for_each_active_vgpu(gvt, vgpu, id) { |
| 564 | for (pipe = 0; pipe < I915_MAX_PIPES; pipe++) { |
| 565 | if (pipe_is_enabled(vgpu, pipe)) { |
| 566 | found = true; |
| 567 | break; |
| 568 | } |
| 569 | } |
| 570 | if (found) |
| 571 | break; |
| 572 | } |
| 573 | |
| 574 | /* all the pipes are disabled */ |
| 575 | if (!found) |
| 576 | hrtimer_cancel(&irq->vblank_timer.timer); |
| 577 | else |
| 578 | hrtimer_start(&irq->vblank_timer.timer, |
| 579 | ktime_add_ns(ktime_get(), irq->vblank_timer.period), |
| 580 | HRTIMER_MODE_ABS); |
| 581 | mutex_unlock(&gvt->lock); |
| 582 | } |
| 583 | |
| 584 | static void emulate_vblank_on_pipe(struct intel_vgpu *vgpu, int pipe) |
| 585 | { |
| 586 | struct drm_i915_private *dev_priv = vgpu->gvt->dev_priv; |
| 587 | struct intel_vgpu_irq *irq = &vgpu->irq; |
| 588 | int vblank_event[] = { |
| 589 | [PIPE_A] = PIPE_A_VBLANK, |
| 590 | [PIPE_B] = PIPE_B_VBLANK, |
| 591 | [PIPE_C] = PIPE_C_VBLANK, |
| 592 | }; |
| 593 | int event; |
| 594 | |
| 595 | if (pipe < PIPE_A || pipe > PIPE_C) |
| 596 | return; |
| 597 | |
| 598 | for_each_set_bit(event, irq->flip_done_event[pipe], |
| 599 | INTEL_GVT_EVENT_MAX) { |
| 600 | clear_bit(event, irq->flip_done_event[pipe]); |
| 601 | if (!pipe_is_enabled(vgpu, pipe)) |
| 602 | continue; |
| 603 | |
| 604 | intel_vgpu_trigger_virtual_event(vgpu, event); |
| 605 | } |
| 606 | |
| 607 | if (pipe_is_enabled(vgpu, pipe)) { |
| 608 | vgpu_vreg_t(vgpu, PIPE_FRMCOUNT_G4X(pipe))++; |
| 609 | intel_vgpu_trigger_virtual_event(vgpu, vblank_event[pipe]); |
| 610 | } |
| 611 | } |
| 612 | |
| 613 | static void emulate_vblank(struct intel_vgpu *vgpu) |
| 614 | { |
| 615 | int pipe; |
| 616 | |
| 617 | mutex_lock(&vgpu->vgpu_lock); |
| 618 | for_each_pipe(vgpu->gvt->dev_priv, pipe) |
| 619 | emulate_vblank_on_pipe(vgpu, pipe); |
| 620 | mutex_unlock(&vgpu->vgpu_lock); |
| 621 | } |
| 622 | |
| 623 | /** |
| 624 | * intel_gvt_emulate_vblank - trigger vblank events for vGPUs on GVT device |
| 625 | * @gvt: a GVT device |
| 626 | * |
| 627 | * This function is used to trigger vblank interrupts for vGPUs on GVT device |
| 628 | * |
| 629 | */ |
| 630 | void intel_gvt_emulate_vblank(struct intel_gvt *gvt) |
| 631 | { |
| 632 | struct intel_vgpu *vgpu; |
| 633 | int id; |
| 634 | |
| 635 | mutex_lock(&gvt->lock); |
| 636 | for_each_active_vgpu(gvt, vgpu, id) |
| 637 | emulate_vblank(vgpu); |
| 638 | mutex_unlock(&gvt->lock); |
| 639 | } |
| 640 | |
| 641 | /** |
| 642 | * intel_vgpu_emulate_hotplug - trigger hotplug event for vGPU |
| 643 | * @vgpu: a vGPU |
| 644 | * @connected: link state |
| 645 | * |
| 646 | * This function is used to trigger hotplug interrupt for vGPU |
| 647 | * |
| 648 | */ |
| 649 | void intel_vgpu_emulate_hotplug(struct intel_vgpu *vgpu, bool connected) |
| 650 | { |
| 651 | struct drm_i915_private *dev_priv = vgpu->gvt->dev_priv; |
| 652 | |
| 653 | /* TODO: add more platforms support */ |
| 654 | if (IS_SKYLAKE(dev_priv) || IS_KABYLAKE(dev_priv) || |
| 655 | IS_COFFEELAKE(dev_priv)) { |
| 656 | if (connected) { |
| 657 | vgpu_vreg_t(vgpu, SFUSE_STRAP) |= |
| 658 | SFUSE_STRAP_DDID_DETECTED; |
| 659 | vgpu_vreg_t(vgpu, SDEISR) |= SDE_PORTD_HOTPLUG_CPT; |
| 660 | } else { |
| 661 | vgpu_vreg_t(vgpu, SFUSE_STRAP) &= |
| 662 | ~SFUSE_STRAP_DDID_DETECTED; |
| 663 | vgpu_vreg_t(vgpu, SDEISR) &= ~SDE_PORTD_HOTPLUG_CPT; |
| 664 | } |
| 665 | vgpu_vreg_t(vgpu, SDEIIR) |= SDE_PORTD_HOTPLUG_CPT; |
| 666 | vgpu_vreg_t(vgpu, PCH_PORT_HOTPLUG) |= |
| 667 | PORTD_HOTPLUG_STATUS_MASK; |
| 668 | intel_vgpu_trigger_virtual_event(vgpu, DP_D_HOTPLUG); |
| 669 | } else if (IS_BROXTON(dev_priv)) { |
| 670 | if (intel_vgpu_has_monitor_on_port(vgpu, PORT_A)) { |
| 671 | if (connected) { |
| 672 | vgpu_vreg_t(vgpu, GEN8_DE_PORT_ISR) |= |
| 673 | BXT_DE_PORT_HP_DDIA; |
| 674 | } else { |
| 675 | vgpu_vreg_t(vgpu, GEN8_DE_PORT_ISR) &= |
| 676 | ~BXT_DE_PORT_HP_DDIA; |
| 677 | } |
| 678 | vgpu_vreg_t(vgpu, GEN8_DE_PORT_IIR) |= |
| 679 | BXT_DE_PORT_HP_DDIA; |
| 680 | vgpu_vreg_t(vgpu, PCH_PORT_HOTPLUG) &= |
| 681 | ~PORTA_HOTPLUG_STATUS_MASK; |
| 682 | vgpu_vreg_t(vgpu, PCH_PORT_HOTPLUG) |= |
| 683 | PORTA_HOTPLUG_LONG_DETECT; |
| 684 | intel_vgpu_trigger_virtual_event(vgpu, DP_A_HOTPLUG); |
| 685 | } |
| 686 | if (intel_vgpu_has_monitor_on_port(vgpu, PORT_B)) { |
| 687 | if (connected) { |
| 688 | vgpu_vreg_t(vgpu, GEN8_DE_PORT_ISR) |= |
| 689 | BXT_DE_PORT_HP_DDIB; |
| 690 | vgpu_vreg_t(vgpu, SFUSE_STRAP) |= |
| 691 | SFUSE_STRAP_DDIB_DETECTED; |
| 692 | } else { |
| 693 | vgpu_vreg_t(vgpu, GEN8_DE_PORT_ISR) &= |
| 694 | ~BXT_DE_PORT_HP_DDIB; |
| 695 | vgpu_vreg_t(vgpu, SFUSE_STRAP) &= |
| 696 | ~SFUSE_STRAP_DDIB_DETECTED; |
| 697 | } |
| 698 | vgpu_vreg_t(vgpu, GEN8_DE_PORT_IIR) |= |
| 699 | BXT_DE_PORT_HP_DDIB; |
| 700 | vgpu_vreg_t(vgpu, PCH_PORT_HOTPLUG) &= |
| 701 | ~PORTB_HOTPLUG_STATUS_MASK; |
| 702 | vgpu_vreg_t(vgpu, PCH_PORT_HOTPLUG) |= |
| 703 | PORTB_HOTPLUG_LONG_DETECT; |
| 704 | intel_vgpu_trigger_virtual_event(vgpu, DP_B_HOTPLUG); |
| 705 | } |
| 706 | if (intel_vgpu_has_monitor_on_port(vgpu, PORT_C)) { |
| 707 | if (connected) { |
| 708 | vgpu_vreg_t(vgpu, GEN8_DE_PORT_ISR) |= |
| 709 | BXT_DE_PORT_HP_DDIC; |
| 710 | vgpu_vreg_t(vgpu, SFUSE_STRAP) |= |
| 711 | SFUSE_STRAP_DDIC_DETECTED; |
| 712 | } else { |
| 713 | vgpu_vreg_t(vgpu, GEN8_DE_PORT_ISR) &= |
| 714 | ~BXT_DE_PORT_HP_DDIC; |
| 715 | vgpu_vreg_t(vgpu, SFUSE_STRAP) &= |
| 716 | ~SFUSE_STRAP_DDIC_DETECTED; |
| 717 | } |
| 718 | vgpu_vreg_t(vgpu, GEN8_DE_PORT_IIR) |= |
| 719 | BXT_DE_PORT_HP_DDIC; |
| 720 | vgpu_vreg_t(vgpu, PCH_PORT_HOTPLUG) &= |
| 721 | ~PORTC_HOTPLUG_STATUS_MASK; |
| 722 | vgpu_vreg_t(vgpu, PCH_PORT_HOTPLUG) |= |
| 723 | PORTC_HOTPLUG_LONG_DETECT; |
| 724 | intel_vgpu_trigger_virtual_event(vgpu, DP_C_HOTPLUG); |
| 725 | } |
| 726 | } |
| 727 | } |
| 728 | |
| 729 | /** |
| 730 | * intel_vgpu_clean_display - clean vGPU virtual display emulation |
| 731 | * @vgpu: a vGPU |
| 732 | * |
| 733 | * This function is used to clean vGPU virtual display emulation stuffs |
| 734 | * |
| 735 | */ |
| 736 | void intel_vgpu_clean_display(struct intel_vgpu *vgpu) |
| 737 | { |
| 738 | struct drm_i915_private *dev_priv = vgpu->gvt->dev_priv; |
| 739 | |
| 740 | if (IS_SKYLAKE(dev_priv) || IS_KABYLAKE(dev_priv) || |
| 741 | IS_COFFEELAKE(dev_priv)) |
| 742 | clean_virtual_dp_monitor(vgpu, PORT_D); |
| 743 | else |
| 744 | clean_virtual_dp_monitor(vgpu, PORT_B); |
| 745 | } |
| 746 | |
| 747 | /** |
| 748 | * intel_vgpu_init_display- initialize vGPU virtual display emulation |
| 749 | * @vgpu: a vGPU |
| 750 | * @resolution: resolution index for intel_vgpu_edid |
| 751 | * |
| 752 | * This function is used to initialize vGPU virtual display emulation stuffs |
| 753 | * |
| 754 | * Returns: |
| 755 | * Zero on success, negative error code if failed. |
| 756 | * |
| 757 | */ |
| 758 | int intel_vgpu_init_display(struct intel_vgpu *vgpu, u64 resolution) |
| 759 | { |
| 760 | struct drm_i915_private *dev_priv = vgpu->gvt->dev_priv; |
| 761 | |
| 762 | intel_vgpu_init_i2c_edid(vgpu); |
| 763 | |
| 764 | if (IS_SKYLAKE(dev_priv) || IS_KABYLAKE(dev_priv) || |
| 765 | IS_COFFEELAKE(dev_priv)) |
| 766 | return setup_virtual_dp_monitor(vgpu, PORT_D, GVT_DP_D, |
| 767 | resolution); |
| 768 | else |
| 769 | return setup_virtual_dp_monitor(vgpu, PORT_B, GVT_DP_B, |
| 770 | resolution); |
| 771 | } |
| 772 | |
| 773 | /** |
| 774 | * intel_vgpu_reset_display- reset vGPU virtual display emulation |
| 775 | * @vgpu: a vGPU |
| 776 | * |
| 777 | * This function is used to reset vGPU virtual display emulation stuffs |
| 778 | * |
| 779 | */ |
| 780 | void intel_vgpu_reset_display(struct intel_vgpu *vgpu) |
| 781 | { |
| 782 | emulate_monitor_status_change(vgpu); |
| 783 | } |