104d348aeSZhi Wang /*
204d348aeSZhi Wang * Copyright(c) 2011-2016 Intel Corporation. All rights reserved.
304d348aeSZhi Wang *
404d348aeSZhi Wang * Permission is hereby granted, free of charge, to any person obtaining a
504d348aeSZhi Wang * copy of this software and associated documentation files (the "Software"),
604d348aeSZhi Wang * to deal in the Software without restriction, including without limitation
704d348aeSZhi Wang * the rights to use, copy, modify, merge, publish, distribute, sublicense,
804d348aeSZhi Wang * and/or sell copies of the Software, and to permit persons to whom the
904d348aeSZhi Wang * Software is furnished to do so, subject to the following conditions:
1004d348aeSZhi Wang *
1104d348aeSZhi Wang * The above copyright notice and this permission notice (including the next
1204d348aeSZhi Wang * paragraph) shall be included in all copies or substantial portions of the
1304d348aeSZhi Wang * Software.
1404d348aeSZhi Wang *
1504d348aeSZhi Wang * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
1604d348aeSZhi Wang * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
1704d348aeSZhi Wang * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
1804d348aeSZhi Wang * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
1904d348aeSZhi Wang * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
2004d348aeSZhi Wang * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
2104d348aeSZhi Wang * SOFTWARE.
2204d348aeSZhi Wang *
2304d348aeSZhi Wang * Authors:
2404d348aeSZhi Wang * Ke Yu
2504d348aeSZhi Wang * Zhiyuan Lv <zhiyuan.lv@intel.com>
2604d348aeSZhi Wang *
2704d348aeSZhi Wang * Contributors:
2804d348aeSZhi Wang * Terrence Xu <terrence.xu@intel.com>
2904d348aeSZhi Wang * Changbin Du <changbin.du@intel.com>
3004d348aeSZhi Wang * Bing Niu <bing.niu@intel.com>
3104d348aeSZhi Wang * Zhi Wang <zhi.a.wang@intel.com>
3204d348aeSZhi Wang *
3304d348aeSZhi Wang */
3404d348aeSZhi Wang
3504d348aeSZhi Wang #include "i915_drv.h"
36ce2fce25SMatt Roper #include "i915_reg.h"
37feddf6e8SZhenyu Wang #include "gvt.h"
3804d348aeSZhi Wang
395e258fa5SVille Syrjälä #include "display/bxt_dpio_phy_regs.h"
40514ca6dfSVille Syrjälä #include "display/i9xx_plane_regs.h"
418cecf4aeSVille Syrjälä #include "display/intel_cursor_regs.h"
42acc855d3SJani Nikula #include "display/intel_display.h"
4399417adbSJani Nikula #include "display/intel_dpio_phy.h"
4441b088a2SJani Nikula #include "display/intel_sprite_regs.h"
4599417adbSJani Nikula
get_edp_pipe(struct intel_vgpu * vgpu)4604d348aeSZhi Wang static int get_edp_pipe(struct intel_vgpu *vgpu)
4704d348aeSZhi Wang {
4804d348aeSZhi Wang u32 data = vgpu_vreg(vgpu, _TRANS_DDI_FUNC_CTL_EDP);
4904d348aeSZhi Wang int pipe = -1;
5004d348aeSZhi Wang
5104d348aeSZhi Wang switch (data & TRANS_DDI_EDP_INPUT_MASK) {
5204d348aeSZhi Wang case TRANS_DDI_EDP_INPUT_A_ON:
5304d348aeSZhi Wang case TRANS_DDI_EDP_INPUT_A_ONOFF:
5404d348aeSZhi Wang pipe = PIPE_A;
5504d348aeSZhi Wang break;
5604d348aeSZhi Wang case TRANS_DDI_EDP_INPUT_B_ONOFF:
5704d348aeSZhi Wang pipe = PIPE_B;
5804d348aeSZhi Wang break;
5904d348aeSZhi Wang case TRANS_DDI_EDP_INPUT_C_ONOFF:
6004d348aeSZhi Wang pipe = PIPE_C;
6104d348aeSZhi Wang break;
6204d348aeSZhi Wang }
6304d348aeSZhi Wang return pipe;
6404d348aeSZhi Wang }
6504d348aeSZhi Wang
edp_pipe_is_enabled(struct intel_vgpu * vgpu)6604d348aeSZhi Wang static int edp_pipe_is_enabled(struct intel_vgpu *vgpu)
6704d348aeSZhi Wang {
68a61ac1e7SChris Wilson struct drm_i915_private *dev_priv = vgpu->gvt->gt->i915;
6904d348aeSZhi Wang
70984b61c3SJani Nikula if (!(vgpu_vreg_t(vgpu, TRANSCONF(dev_priv, TRANSCODER_EDP)) & TRANSCONF_ENABLE))
7104d348aeSZhi Wang return 0;
7204d348aeSZhi Wang
7304d348aeSZhi Wang if (!(vgpu_vreg(vgpu, _TRANS_DDI_FUNC_CTL_EDP) & TRANS_DDI_FUNC_ENABLE))
7404d348aeSZhi Wang return 0;
7504d348aeSZhi Wang return 1;
7604d348aeSZhi Wang }
7704d348aeSZhi Wang
pipe_is_enabled(struct intel_vgpu * vgpu,int pipe)789f31d106STina Zhang int pipe_is_enabled(struct intel_vgpu *vgpu, int pipe)
7904d348aeSZhi Wang {
80a61ac1e7SChris Wilson struct drm_i915_private *dev_priv = vgpu->gvt->gt->i915;
8104d348aeSZhi Wang
82db19c724SPankaj Bharadiya if (drm_WARN_ON(&dev_priv->drm,
83db19c724SPankaj Bharadiya pipe < PIPE_A || pipe >= I915_MAX_PIPES))
8404d348aeSZhi Wang return -EINVAL;
8504d348aeSZhi Wang
86984b61c3SJani Nikula if (vgpu_vreg_t(vgpu, TRANSCONF(dev_priv, pipe)) & TRANSCONF_ENABLE)
8704d348aeSZhi Wang return 1;
8804d348aeSZhi Wang
8904d348aeSZhi Wang if (edp_pipe_is_enabled(vgpu) &&
9004d348aeSZhi Wang get_edp_pipe(vgpu) == pipe)
9104d348aeSZhi Wang return 1;
9204d348aeSZhi Wang return 0;
9304d348aeSZhi Wang }
9404d348aeSZhi Wang
95bca5609fSZhenyu Wang static unsigned char virtual_dp_monitor_edid[GVT_EDID_NUM][EDID_SIZE] = {
96bca5609fSZhenyu Wang {
97bca5609fSZhenyu Wang /* EDID with 1024x768 as its resolution */
98bca5609fSZhenyu Wang /*Header*/
99bca5609fSZhenyu Wang 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00,
100bca5609fSZhenyu Wang /* Vendor & Product Identification */
101bca5609fSZhenyu Wang 0x22, 0xf0, 0x54, 0x29, 0x00, 0x00, 0x00, 0x00, 0x04, 0x17,
102bca5609fSZhenyu Wang /* Version & Revision */
103bca5609fSZhenyu Wang 0x01, 0x04,
104bca5609fSZhenyu Wang /* Basic Display Parameters & Features */
105bca5609fSZhenyu Wang 0xa5, 0x34, 0x20, 0x78, 0x23,
106bca5609fSZhenyu Wang /* Color Characteristics */
107bca5609fSZhenyu Wang 0xfc, 0x81, 0xa4, 0x55, 0x4d, 0x9d, 0x25, 0x12, 0x50, 0x54,
108bca5609fSZhenyu Wang /* Established Timings: maximum resolution is 1024x768 */
109bca5609fSZhenyu Wang 0x21, 0x08, 0x00,
110bca5609fSZhenyu Wang /* Standard Timings. All invalid */
111bca5609fSZhenyu Wang 0x00, 0xc0, 0x00, 0xc0, 0x00, 0x40, 0x00, 0x80, 0x00, 0x00,
112bca5609fSZhenyu Wang 0x00, 0x40, 0x00, 0x00, 0x00, 0x01,
113bca5609fSZhenyu Wang /* 18 Byte Data Blocks 1: invalid */
114bca5609fSZhenyu Wang 0x00, 0x00, 0x80, 0xa0, 0x70, 0xb0,
115bca5609fSZhenyu Wang 0x23, 0x40, 0x30, 0x20, 0x36, 0x00, 0x06, 0x44, 0x21, 0x00, 0x00, 0x1a,
116bca5609fSZhenyu Wang /* 18 Byte Data Blocks 2: invalid */
117bca5609fSZhenyu Wang 0x00, 0x00, 0x00, 0xfd, 0x00, 0x18, 0x3c, 0x18, 0x50, 0x11, 0x00, 0x0a,
118bca5609fSZhenyu Wang 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
119bca5609fSZhenyu Wang /* 18 Byte Data Blocks 3: invalid */
120bca5609fSZhenyu Wang 0x00, 0x00, 0x00, 0xfc, 0x00, 0x48,
121bca5609fSZhenyu Wang 0x50, 0x20, 0x5a, 0x52, 0x32, 0x34, 0x34, 0x30, 0x77, 0x0a, 0x20, 0x20,
122bca5609fSZhenyu Wang /* 18 Byte Data Blocks 4: invalid */
123bca5609fSZhenyu Wang 0x00, 0x00, 0x00, 0xff, 0x00, 0x43, 0x4e, 0x34, 0x33, 0x30, 0x34, 0x30,
124bca5609fSZhenyu Wang 0x44, 0x58, 0x51, 0x0a, 0x20, 0x20,
125bca5609fSZhenyu Wang /* Extension Block Count */
126bca5609fSZhenyu Wang 0x00,
127bca5609fSZhenyu Wang /* Checksum */
128bca5609fSZhenyu Wang 0xef,
129bca5609fSZhenyu Wang },
130bca5609fSZhenyu Wang {
1312c883136SChuanxiao Dong /* EDID with 1920x1200 as its resolution */
13204d348aeSZhi Wang /*Header*/
13304d348aeSZhi Wang 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00,
13404d348aeSZhi Wang /* Vendor & Product Identification */
13504d348aeSZhi Wang 0x22, 0xf0, 0x54, 0x29, 0x00, 0x00, 0x00, 0x00, 0x04, 0x17,
13604d348aeSZhi Wang /* Version & Revision */
13704d348aeSZhi Wang 0x01, 0x04,
13804d348aeSZhi Wang /* Basic Display Parameters & Features */
13904d348aeSZhi Wang 0xa5, 0x34, 0x20, 0x78, 0x23,
14004d348aeSZhi Wang /* Color Characteristics */
14104d348aeSZhi Wang 0xfc, 0x81, 0xa4, 0x55, 0x4d, 0x9d, 0x25, 0x12, 0x50, 0x54,
14204d348aeSZhi Wang /* Established Timings: maximum resolution is 1024x768 */
14304d348aeSZhi Wang 0x21, 0x08, 0x00,
1442c883136SChuanxiao Dong /*
1452c883136SChuanxiao Dong * Standard Timings.
1462c883136SChuanxiao Dong * below new resolutions can be supported:
1472c883136SChuanxiao Dong * 1920x1080, 1280x720, 1280x960, 1280x1024,
1482c883136SChuanxiao Dong * 1440x900, 1600x1200, 1680x1050
1492c883136SChuanxiao Dong */
1502c883136SChuanxiao Dong 0xd1, 0xc0, 0x81, 0xc0, 0x81, 0x40, 0x81, 0x80, 0x95, 0x00,
1512c883136SChuanxiao Dong 0xa9, 0x40, 0xb3, 0x00, 0x01, 0x01,
1522c883136SChuanxiao Dong /* 18 Byte Data Blocks 1: max resolution is 1920x1200 */
1532c883136SChuanxiao Dong 0x28, 0x3c, 0x80, 0xa0, 0x70, 0xb0,
15404d348aeSZhi Wang 0x23, 0x40, 0x30, 0x20, 0x36, 0x00, 0x06, 0x44, 0x21, 0x00, 0x00, 0x1a,
15504d348aeSZhi Wang /* 18 Byte Data Blocks 2: invalid */
15604d348aeSZhi Wang 0x00, 0x00, 0x00, 0xfd, 0x00, 0x18, 0x3c, 0x18, 0x50, 0x11, 0x00, 0x0a,
15704d348aeSZhi Wang 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
15804d348aeSZhi Wang /* 18 Byte Data Blocks 3: invalid */
15904d348aeSZhi Wang 0x00, 0x00, 0x00, 0xfc, 0x00, 0x48,
16004d348aeSZhi Wang 0x50, 0x20, 0x5a, 0x52, 0x32, 0x34, 0x34, 0x30, 0x77, 0x0a, 0x20, 0x20,
16104d348aeSZhi Wang /* 18 Byte Data Blocks 4: invalid */
16204d348aeSZhi Wang 0x00, 0x00, 0x00, 0xff, 0x00, 0x43, 0x4e, 0x34, 0x33, 0x30, 0x34, 0x30,
16304d348aeSZhi Wang 0x44, 0x58, 0x51, 0x0a, 0x20, 0x20,
16404d348aeSZhi Wang /* Extension Block Count */
16504d348aeSZhi Wang 0x00,
16604d348aeSZhi Wang /* Checksum */
1672c883136SChuanxiao Dong 0x45,
168bca5609fSZhenyu Wang },
16904d348aeSZhi Wang };
17004d348aeSZhi Wang
17104d348aeSZhi Wang #define DPCD_HEADER_SIZE 0xb
17204d348aeSZhi Wang
173e2e02cbbSPei Zhang /* let the virtual display supports DP1.2 */
174999ccb40SDu, Changbin static u8 dpcd_fix_data[DPCD_HEADER_SIZE] = {
175edb8d77aSTina Zhang 0x12, 0x014, 0x84, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
17604d348aeSZhi Wang };
17704d348aeSZhi Wang
emulate_monitor_status_change(struct intel_vgpu * vgpu)17804d348aeSZhi Wang static void emulate_monitor_status_change(struct intel_vgpu *vgpu)
17904d348aeSZhi Wang {
180a61ac1e7SChris Wilson struct drm_i915_private *dev_priv = vgpu->gvt->gt->i915;
18165eff272SXiong Zhang int pipe;
18265eff272SXiong Zhang
18372bad997SColin Xu if (IS_BROXTON(dev_priv)) {
184a5a8ef93SColin Xu enum transcoder trans;
185a5a8ef93SColin Xu enum port port;
18672bad997SColin Xu
187a5a8ef93SColin Xu /* Clear PIPE, DDI, PHY, HPD before setting new */
1888625b221SVille Syrjälä vgpu_vreg_t(vgpu, GEN8_DE_PORT_ISR) &=
189e5abaab3SVille Syrjälä ~(GEN8_DE_PORT_HOTPLUG(HPD_PORT_A) |
190e5abaab3SVille Syrjälä GEN8_DE_PORT_HOTPLUG(HPD_PORT_B) |
191e5abaab3SVille Syrjälä GEN8_DE_PORT_HOTPLUG(HPD_PORT_C));
19272bad997SColin Xu
193a5a8ef93SColin Xu for_each_pipe(dev_priv, pipe) {
194984b61c3SJani Nikula vgpu_vreg_t(vgpu, TRANSCONF(dev_priv, pipe)) &=
1953eb08ea5SVille Syrjälä ~(TRANSCONF_ENABLE | TRANSCONF_STATE_ENABLE);
196be30c827SJani Nikula vgpu_vreg_t(vgpu, DSPCNTR(dev_priv, pipe)) &= ~DISP_ENABLE;
197a5a8ef93SColin Xu vgpu_vreg_t(vgpu, SPRCTL(pipe)) &= ~SPRITE_ENABLE;
19893160b2dSJani Nikula vgpu_vreg_t(vgpu, CURCNTR(dev_priv, pipe)) &= ~MCURSOR_MODE_MASK;
19993160b2dSJani Nikula vgpu_vreg_t(vgpu, CURCNTR(dev_priv, pipe)) |= MCURSOR_MODE_DISABLE;
200a5a8ef93SColin Xu }
201a5a8ef93SColin Xu
202a5a8ef93SColin Xu for (trans = TRANSCODER_A; trans <= TRANSCODER_EDP; trans++) {
203*b092d6adSJani Nikula vgpu_vreg_t(vgpu, TRANS_DDI_FUNC_CTL(dev_priv, trans)) &=
204a5a8ef93SColin Xu ~(TRANS_DDI_BPC_MASK | TRANS_DDI_MODE_SELECT_MASK |
205a5a8ef93SColin Xu TRANS_DDI_PORT_MASK | TRANS_DDI_FUNC_ENABLE);
206a5a8ef93SColin Xu }
207*b092d6adSJani Nikula vgpu_vreg_t(vgpu, TRANS_DDI_FUNC_CTL(dev_priv, TRANSCODER_A)) &=
208a5a8ef93SColin Xu ~(TRANS_DDI_BPC_MASK | TRANS_DDI_MODE_SELECT_MASK |
209a5a8ef93SColin Xu TRANS_DDI_PORT_MASK);
210a5a8ef93SColin Xu
211a5a8ef93SColin Xu for (port = PORT_A; port <= PORT_C; port++) {
212a5a8ef93SColin Xu vgpu_vreg_t(vgpu, BXT_PHY_CTL(port)) &=
213a5a8ef93SColin Xu ~BXT_PHY_LANE_ENABLED;
214a5a8ef93SColin Xu vgpu_vreg_t(vgpu, BXT_PHY_CTL(port)) |=
215a5a8ef93SColin Xu (BXT_PHY_CMNLANE_POWERDOWN_ACK |
216a5a8ef93SColin Xu BXT_PHY_LANE_POWERDOWN_ACK);
217a5a8ef93SColin Xu
218a5a8ef93SColin Xu vgpu_vreg_t(vgpu, BXT_PORT_PLL_ENABLE(port)) &=
219a5a8ef93SColin Xu ~(PORT_PLL_POWER_STATE | PORT_PLL_POWER_ENABLE |
220a5a8ef93SColin Xu PORT_PLL_REF_SEL | PORT_PLL_LOCK |
221a5a8ef93SColin Xu PORT_PLL_ENABLE);
222a5a8ef93SColin Xu
223a5a8ef93SColin Xu vgpu_vreg_t(vgpu, DDI_BUF_CTL(port)) &=
224a5a8ef93SColin Xu ~(DDI_INIT_DISPLAY_DETECTED |
225a5a8ef93SColin Xu DDI_BUF_CTL_ENABLE);
226a5a8ef93SColin Xu vgpu_vreg_t(vgpu, DDI_BUF_CTL(port)) |= DDI_BUF_IS_IDLE;
227a5a8ef93SColin Xu }
2284ceb06e7SColin Xu vgpu_vreg_t(vgpu, PCH_PORT_HOTPLUG) &=
2294ceb06e7SColin Xu ~(PORTA_HOTPLUG_ENABLE | PORTA_HOTPLUG_STATUS_MASK);
2304ceb06e7SColin Xu vgpu_vreg_t(vgpu, PCH_PORT_HOTPLUG) &=
2314ceb06e7SColin Xu ~(PORTB_HOTPLUG_ENABLE | PORTB_HOTPLUG_STATUS_MASK);
2324ceb06e7SColin Xu vgpu_vreg_t(vgpu, PCH_PORT_HOTPLUG) &=
2334ceb06e7SColin Xu ~(PORTC_HOTPLUG_ENABLE | PORTC_HOTPLUG_STATUS_MASK);
2344ceb06e7SColin Xu /* No hpd_invert set in vgpu vbt, need to clear invert mask */
2354ceb06e7SColin Xu vgpu_vreg_t(vgpu, PCH_PORT_HOTPLUG) &= ~BXT_DDI_HPD_INVERT_MASK;
2364ceb06e7SColin Xu vgpu_vreg_t(vgpu, GEN8_DE_PORT_ISR) &= ~BXT_DE_PORT_HOTPLUG_MASK;
237a5a8ef93SColin Xu
238a5a8ef93SColin Xu vgpu_vreg_t(vgpu, BXT_P_CR_GT_DISP_PWRON) &= ~(BIT(0) | BIT(1));
239a5a8ef93SColin Xu vgpu_vreg_t(vgpu, BXT_PORT_CL1CM_DW0(DPIO_PHY0)) &=
240a5a8ef93SColin Xu ~PHY_POWER_GOOD;
241a5a8ef93SColin Xu vgpu_vreg_t(vgpu, BXT_PORT_CL1CM_DW0(DPIO_PHY1)) &=
242a5a8ef93SColin Xu ~PHY_POWER_GOOD;
243a5a8ef93SColin Xu vgpu_vreg_t(vgpu, BXT_PHY_CTL_FAMILY(DPIO_PHY0)) &= ~BIT(30);
244a5a8ef93SColin Xu vgpu_vreg_t(vgpu, BXT_PHY_CTL_FAMILY(DPIO_PHY1)) &= ~BIT(30);
245a5a8ef93SColin Xu
246a5a8ef93SColin Xu vgpu_vreg_t(vgpu, SFUSE_STRAP) &= ~SFUSE_STRAP_DDIB_DETECTED;
247a5a8ef93SColin Xu vgpu_vreg_t(vgpu, SFUSE_STRAP) &= ~SFUSE_STRAP_DDIC_DETECTED;
248a5a8ef93SColin Xu
249a5a8ef93SColin Xu /*
250a5a8ef93SColin Xu * Only 1 PIPE enabled in current vGPU display and PIPE_A is
251a5a8ef93SColin Xu * tied to TRANSCODER_A in HW, so it's safe to assume PIPE_A,
252a5a8ef93SColin Xu * TRANSCODER_A can be enabled. PORT_x depends on the input of
253a5a8ef93SColin Xu * setup_virtual_dp_monitor.
254a5a8ef93SColin Xu */
255984b61c3SJani Nikula vgpu_vreg_t(vgpu, TRANSCONF(dev_priv, TRANSCODER_A)) |= TRANSCONF_ENABLE;
256984b61c3SJani Nikula vgpu_vreg_t(vgpu, TRANSCONF(dev_priv, TRANSCODER_A)) |= TRANSCONF_STATE_ENABLE;
257a5a8ef93SColin Xu
258a5a8ef93SColin Xu /*
259a5a8ef93SColin Xu * Golden M/N are calculated based on:
260a5a8ef93SColin Xu * 24 bpp, 4 lanes, 154000 pixel clk (from virtual EDID),
261a5a8ef93SColin Xu * DP link clk 1620 MHz and non-constant_n.
262a5a8ef93SColin Xu * TODO: calculate DP link symbol clk and stream clk m/n.
263a5a8ef93SColin Xu */
2645702d5d4SJani Nikula vgpu_vreg_t(vgpu, PIPE_DATA_M1(dev_priv, TRANSCODER_A)) = TU_SIZE(64);
2655702d5d4SJani Nikula vgpu_vreg_t(vgpu, PIPE_DATA_M1(dev_priv, TRANSCODER_A)) |= 0x5b425e;
26612967c4fSJani Nikula vgpu_vreg_t(vgpu, PIPE_DATA_N1(dev_priv, TRANSCODER_A)) = 0x800000;
2673c461986SJani Nikula vgpu_vreg_t(vgpu, PIPE_LINK_M1(dev_priv, TRANSCODER_A)) = 0x3cd6e;
2680b406cc9SJani Nikula vgpu_vreg_t(vgpu, PIPE_LINK_N1(dev_priv, TRANSCODER_A)) = 0x80000;
269a5a8ef93SColin Xu
270a5a8ef93SColin Xu /* Enable per-DDI/PORT vreg */
27172bad997SColin Xu if (intel_vgpu_has_monitor_on_port(vgpu, PORT_A)) {
272a5a8ef93SColin Xu vgpu_vreg_t(vgpu, BXT_P_CR_GT_DISP_PWRON) |= BIT(1);
273a5a8ef93SColin Xu vgpu_vreg_t(vgpu, BXT_PORT_CL1CM_DW0(DPIO_PHY1)) |=
274a5a8ef93SColin Xu PHY_POWER_GOOD;
275a5a8ef93SColin Xu vgpu_vreg_t(vgpu, BXT_PHY_CTL_FAMILY(DPIO_PHY1)) |=
276a5a8ef93SColin Xu BIT(30);
277a5a8ef93SColin Xu vgpu_vreg_t(vgpu, BXT_PHY_CTL(PORT_A)) |=
278a5a8ef93SColin Xu BXT_PHY_LANE_ENABLED;
279a5a8ef93SColin Xu vgpu_vreg_t(vgpu, BXT_PHY_CTL(PORT_A)) &=
280a5a8ef93SColin Xu ~(BXT_PHY_CMNLANE_POWERDOWN_ACK |
281a5a8ef93SColin Xu BXT_PHY_LANE_POWERDOWN_ACK);
282a5a8ef93SColin Xu vgpu_vreg_t(vgpu, BXT_PORT_PLL_ENABLE(PORT_A)) |=
283a5a8ef93SColin Xu (PORT_PLL_POWER_STATE | PORT_PLL_POWER_ENABLE |
284a5a8ef93SColin Xu PORT_PLL_REF_SEL | PORT_PLL_LOCK |
285a5a8ef93SColin Xu PORT_PLL_ENABLE);
286a5a8ef93SColin Xu vgpu_vreg_t(vgpu, DDI_BUF_CTL(PORT_A)) |=
287a5a8ef93SColin Xu (DDI_BUF_CTL_ENABLE | DDI_INIT_DISPLAY_DETECTED);
288a5a8ef93SColin Xu vgpu_vreg_t(vgpu, DDI_BUF_CTL(PORT_A)) &=
289a5a8ef93SColin Xu ~DDI_BUF_IS_IDLE;
290*b092d6adSJani Nikula vgpu_vreg_t(vgpu,
291*b092d6adSJani Nikula TRANS_DDI_FUNC_CTL(dev_priv, TRANSCODER_EDP)) |=
292a5a8ef93SColin Xu (TRANS_DDI_BPC_8 | TRANS_DDI_MODE_SELECT_DP_SST |
293a5a8ef93SColin Xu TRANS_DDI_FUNC_ENABLE);
2944ceb06e7SColin Xu vgpu_vreg_t(vgpu, PCH_PORT_HOTPLUG) |=
2954ceb06e7SColin Xu PORTA_HOTPLUG_ENABLE;
29672bad997SColin Xu vgpu_vreg_t(vgpu, GEN8_DE_PORT_ISR) |=
297e5abaab3SVille Syrjälä GEN8_DE_PORT_HOTPLUG(HPD_PORT_A);
29872bad997SColin Xu }
29972bad997SColin Xu
30072bad997SColin Xu if (intel_vgpu_has_monitor_on_port(vgpu, PORT_B)) {
301a5a8ef93SColin Xu vgpu_vreg_t(vgpu, SFUSE_STRAP) |= SFUSE_STRAP_DDIB_DETECTED;
302a5a8ef93SColin Xu vgpu_vreg_t(vgpu, BXT_P_CR_GT_DISP_PWRON) |= BIT(0);
303a5a8ef93SColin Xu vgpu_vreg_t(vgpu, BXT_PORT_CL1CM_DW0(DPIO_PHY0)) |=
304a5a8ef93SColin Xu PHY_POWER_GOOD;
305a5a8ef93SColin Xu vgpu_vreg_t(vgpu, BXT_PHY_CTL_FAMILY(DPIO_PHY0)) |=
306a5a8ef93SColin Xu BIT(30);
307a5a8ef93SColin Xu vgpu_vreg_t(vgpu, BXT_PHY_CTL(PORT_B)) |=
308a5a8ef93SColin Xu BXT_PHY_LANE_ENABLED;
309a5a8ef93SColin Xu vgpu_vreg_t(vgpu, BXT_PHY_CTL(PORT_B)) &=
310a5a8ef93SColin Xu ~(BXT_PHY_CMNLANE_POWERDOWN_ACK |
311a5a8ef93SColin Xu BXT_PHY_LANE_POWERDOWN_ACK);
312a5a8ef93SColin Xu vgpu_vreg_t(vgpu, BXT_PORT_PLL_ENABLE(PORT_B)) |=
313a5a8ef93SColin Xu (PORT_PLL_POWER_STATE | PORT_PLL_POWER_ENABLE |
314a5a8ef93SColin Xu PORT_PLL_REF_SEL | PORT_PLL_LOCK |
315a5a8ef93SColin Xu PORT_PLL_ENABLE);
316a5a8ef93SColin Xu vgpu_vreg_t(vgpu, DDI_BUF_CTL(PORT_B)) |=
317a5a8ef93SColin Xu DDI_BUF_CTL_ENABLE;
318a5a8ef93SColin Xu vgpu_vreg_t(vgpu, DDI_BUF_CTL(PORT_B)) &=
319a5a8ef93SColin Xu ~DDI_BUF_IS_IDLE;
320*b092d6adSJani Nikula vgpu_vreg_t(vgpu,
321*b092d6adSJani Nikula TRANS_DDI_FUNC_CTL(dev_priv, TRANSCODER_A)) |=
322a5a8ef93SColin Xu (TRANS_DDI_BPC_8 | TRANS_DDI_MODE_SELECT_DP_SST |
323a5a8ef93SColin Xu (PORT_B << TRANS_DDI_PORT_SHIFT) |
324a5a8ef93SColin Xu TRANS_DDI_FUNC_ENABLE);
3254ceb06e7SColin Xu vgpu_vreg_t(vgpu, PCH_PORT_HOTPLUG) |=
3264ceb06e7SColin Xu PORTB_HOTPLUG_ENABLE;
32772bad997SColin Xu vgpu_vreg_t(vgpu, GEN8_DE_PORT_ISR) |=
328e5abaab3SVille Syrjälä GEN8_DE_PORT_HOTPLUG(HPD_PORT_B);
32972bad997SColin Xu }
33072bad997SColin Xu
33172bad997SColin Xu if (intel_vgpu_has_monitor_on_port(vgpu, PORT_C)) {
332a5a8ef93SColin Xu vgpu_vreg_t(vgpu, SFUSE_STRAP) |= SFUSE_STRAP_DDIC_DETECTED;
333a5a8ef93SColin Xu vgpu_vreg_t(vgpu, BXT_P_CR_GT_DISP_PWRON) |= BIT(0);
334a5a8ef93SColin Xu vgpu_vreg_t(vgpu, BXT_PORT_CL1CM_DW0(DPIO_PHY0)) |=
335a5a8ef93SColin Xu PHY_POWER_GOOD;
336a5a8ef93SColin Xu vgpu_vreg_t(vgpu, BXT_PHY_CTL_FAMILY(DPIO_PHY0)) |=
337a5a8ef93SColin Xu BIT(30);
338a5a8ef93SColin Xu vgpu_vreg_t(vgpu, BXT_PHY_CTL(PORT_C)) |=
339a5a8ef93SColin Xu BXT_PHY_LANE_ENABLED;
340a5a8ef93SColin Xu vgpu_vreg_t(vgpu, BXT_PHY_CTL(PORT_C)) &=
341a5a8ef93SColin Xu ~(BXT_PHY_CMNLANE_POWERDOWN_ACK |
342a5a8ef93SColin Xu BXT_PHY_LANE_POWERDOWN_ACK);
343a5a8ef93SColin Xu vgpu_vreg_t(vgpu, BXT_PORT_PLL_ENABLE(PORT_C)) |=
344a5a8ef93SColin Xu (PORT_PLL_POWER_STATE | PORT_PLL_POWER_ENABLE |
345a5a8ef93SColin Xu PORT_PLL_REF_SEL | PORT_PLL_LOCK |
346a5a8ef93SColin Xu PORT_PLL_ENABLE);
347a5a8ef93SColin Xu vgpu_vreg_t(vgpu, DDI_BUF_CTL(PORT_C)) |=
348a5a8ef93SColin Xu DDI_BUF_CTL_ENABLE;
349a5a8ef93SColin Xu vgpu_vreg_t(vgpu, DDI_BUF_CTL(PORT_C)) &=
350a5a8ef93SColin Xu ~DDI_BUF_IS_IDLE;
351*b092d6adSJani Nikula vgpu_vreg_t(vgpu,
352*b092d6adSJani Nikula TRANS_DDI_FUNC_CTL(dev_priv, TRANSCODER_A)) |=
353a5a8ef93SColin Xu (TRANS_DDI_BPC_8 | TRANS_DDI_MODE_SELECT_DP_SST |
354a5a8ef93SColin Xu (PORT_B << TRANS_DDI_PORT_SHIFT) |
355a5a8ef93SColin Xu TRANS_DDI_FUNC_ENABLE);
3564ceb06e7SColin Xu vgpu_vreg_t(vgpu, PCH_PORT_HOTPLUG) |=
3574ceb06e7SColin Xu PORTC_HOTPLUG_ENABLE;
35872bad997SColin Xu vgpu_vreg_t(vgpu, GEN8_DE_PORT_ISR) |=
359e5abaab3SVille Syrjälä GEN8_DE_PORT_HOTPLUG(HPD_PORT_C);
36072bad997SColin Xu }
36172bad997SColin Xu
36272bad997SColin Xu return;
36372bad997SColin Xu }
36472bad997SColin Xu
36590551a12SZhenyu Wang vgpu_vreg_t(vgpu, SDEISR) &= ~(SDE_PORTB_HOTPLUG_CPT |
36604d348aeSZhi Wang SDE_PORTC_HOTPLUG_CPT |
36704d348aeSZhi Wang SDE_PORTD_HOTPLUG_CPT);
36804d348aeSZhi Wang
3695f4ae270SChris Wilson if (IS_SKYLAKE(dev_priv) ||
3705f4ae270SChris Wilson IS_KABYLAKE(dev_priv) ||
3715f4ae270SChris Wilson IS_COFFEELAKE(dev_priv) ||
3725f4ae270SChris Wilson IS_COMETLAKE(dev_priv)) {
37390551a12SZhenyu Wang vgpu_vreg_t(vgpu, SDEISR) &= ~(SDE_PORTA_HOTPLUG_SPT |
37404d348aeSZhi Wang SDE_PORTE_HOTPLUG_SPT);
37590551a12SZhenyu Wang vgpu_vreg_t(vgpu, SKL_FUSE_STATUS) |=
37688a16b64SWeinan Li SKL_FUSE_DOWNLOAD_STATUS |
377b2891eb2SImre Deak SKL_FUSE_PG_DIST_STATUS(SKL_PG0) |
378b2891eb2SImre Deak SKL_FUSE_PG_DIST_STATUS(SKL_PG1) |
379b2891eb2SImre Deak SKL_FUSE_PG_DIST_STATUS(SKL_PG2);
380f965b681SColin Xu /*
381f965b681SColin Xu * Only 1 PIPE enabled in current vGPU display and PIPE_A is
382f965b681SColin Xu * tied to TRANSCODER_A in HW, so it's safe to assume PIPE_A,
383f965b681SColin Xu * TRANSCODER_A can be enabled. PORT_x depends on the input of
384f965b681SColin Xu * setup_virtual_dp_monitor, we can bind DPLL0 to any PORT_x
385f965b681SColin Xu * so we fixed to DPLL0 here.
386f965b681SColin Xu * Setup DPLL0: DP link clk 1620 MHz, non SSC, DP Mode
387f965b681SColin Xu */
388f965b681SColin Xu vgpu_vreg_t(vgpu, DPLL_CTRL1) =
389f965b681SColin Xu DPLL_CTRL1_OVERRIDE(DPLL_ID_SKL_DPLL0);
390f965b681SColin Xu vgpu_vreg_t(vgpu, DPLL_CTRL1) |=
391f965b681SColin Xu DPLL_CTRL1_LINK_RATE(DPLL_CTRL1_LINK_RATE_1620, DPLL_ID_SKL_DPLL0);
392f965b681SColin Xu vgpu_vreg_t(vgpu, LCPLL1_CTL) =
393f965b681SColin Xu LCPLL_PLL_ENABLE | LCPLL_PLL_LOCK;
394f965b681SColin Xu vgpu_vreg_t(vgpu, DPLL_STATUS) = DPLL_LOCK(DPLL_ID_SKL_DPLL0);
395f965b681SColin Xu /*
396f965b681SColin Xu * Golden M/N are calculated based on:
397f965b681SColin Xu * 24 bpp, 4 lanes, 154000 pixel clk (from virtual EDID),
398f965b681SColin Xu * DP link clk 1620 MHz and non-constant_n.
399f965b681SColin Xu * TODO: calculate DP link symbol clk and stream clk m/n.
400f965b681SColin Xu */
4015702d5d4SJani Nikula vgpu_vreg_t(vgpu, PIPE_DATA_M1(dev_priv, TRANSCODER_A)) = TU_SIZE(64);
4025702d5d4SJani Nikula vgpu_vreg_t(vgpu, PIPE_DATA_M1(dev_priv, TRANSCODER_A)) |= 0x5b425e;
40312967c4fSJani Nikula vgpu_vreg_t(vgpu, PIPE_DATA_N1(dev_priv, TRANSCODER_A)) = 0x800000;
4043c461986SJani Nikula vgpu_vreg_t(vgpu, PIPE_LINK_M1(dev_priv, TRANSCODER_A)) = 0x3cd6e;
4050b406cc9SJani Nikula vgpu_vreg_t(vgpu, PIPE_LINK_N1(dev_priv, TRANSCODER_A)) = 0x80000;
40688a16b64SWeinan Li }
40704d348aeSZhi Wang
408858b0f57SBing Niu if (intel_vgpu_has_monitor_on_port(vgpu, PORT_B)) {
409f965b681SColin Xu vgpu_vreg_t(vgpu, DPLL_CTRL2) &=
410f965b681SColin Xu ~DPLL_CTRL2_DDI_CLK_OFF(PORT_B);
411f965b681SColin Xu vgpu_vreg_t(vgpu, DPLL_CTRL2) |=
412f965b681SColin Xu DPLL_CTRL2_DDI_CLK_SEL(DPLL_ID_SKL_DPLL0, PORT_B);
413f965b681SColin Xu vgpu_vreg_t(vgpu, DPLL_CTRL2) |=
414f965b681SColin Xu DPLL_CTRL2_DDI_SEL_OVERRIDE(PORT_B);
41590551a12SZhenyu Wang vgpu_vreg_t(vgpu, SFUSE_STRAP) |= SFUSE_STRAP_DDIB_DETECTED;
416*b092d6adSJani Nikula vgpu_vreg_t(vgpu, TRANS_DDI_FUNC_CTL(dev_priv, TRANSCODER_A)) &=
417efa69d73SPei Zhang ~(TRANS_DDI_BPC_MASK | TRANS_DDI_MODE_SELECT_MASK |
418efa69d73SPei Zhang TRANS_DDI_PORT_MASK);
419*b092d6adSJani Nikula vgpu_vreg_t(vgpu, TRANS_DDI_FUNC_CTL(dev_priv, TRANSCODER_A)) |=
42075db1a5bSTina Zhang (TRANS_DDI_BPC_8 | TRANS_DDI_MODE_SELECT_DP_SST |
421efa69d73SPei Zhang (PORT_B << TRANS_DDI_PORT_SHIFT) |
422efa69d73SPei Zhang TRANS_DDI_FUNC_ENABLE);
423295a0d0bSXiong Zhang if (IS_BROADWELL(dev_priv)) {
42490551a12SZhenyu Wang vgpu_vreg_t(vgpu, PORT_CLK_SEL(PORT_B)) &=
425295a0d0bSXiong Zhang ~PORT_CLK_SEL_MASK;
42690551a12SZhenyu Wang vgpu_vreg_t(vgpu, PORT_CLK_SEL(PORT_B)) |=
427295a0d0bSXiong Zhang PORT_CLK_SEL_LCPLL_810;
428295a0d0bSXiong Zhang }
42990551a12SZhenyu Wang vgpu_vreg_t(vgpu, DDI_BUF_CTL(PORT_B)) |= DDI_BUF_CTL_ENABLE;
43090551a12SZhenyu Wang vgpu_vreg_t(vgpu, DDI_BUF_CTL(PORT_B)) &= ~DDI_BUF_IS_IDLE;
43190551a12SZhenyu Wang vgpu_vreg_t(vgpu, SDEISR) |= SDE_PORTB_HOTPLUG_CPT;
432858b0f57SBing Niu }
43304d348aeSZhi Wang
434858b0f57SBing Niu if (intel_vgpu_has_monitor_on_port(vgpu, PORT_C)) {
435f965b681SColin Xu vgpu_vreg_t(vgpu, DPLL_CTRL2) &=
436f965b681SColin Xu ~DPLL_CTRL2_DDI_CLK_OFF(PORT_C);
437f965b681SColin Xu vgpu_vreg_t(vgpu, DPLL_CTRL2) |=
438f965b681SColin Xu DPLL_CTRL2_DDI_CLK_SEL(DPLL_ID_SKL_DPLL0, PORT_C);
439f965b681SColin Xu vgpu_vreg_t(vgpu, DPLL_CTRL2) |=
440f965b681SColin Xu DPLL_CTRL2_DDI_SEL_OVERRIDE(PORT_C);
44190551a12SZhenyu Wang vgpu_vreg_t(vgpu, SDEISR) |= SDE_PORTC_HOTPLUG_CPT;
442*b092d6adSJani Nikula vgpu_vreg_t(vgpu, TRANS_DDI_FUNC_CTL(dev_priv, TRANSCODER_A)) &=
443efa69d73SPei Zhang ~(TRANS_DDI_BPC_MASK | TRANS_DDI_MODE_SELECT_MASK |
444efa69d73SPei Zhang TRANS_DDI_PORT_MASK);
445*b092d6adSJani Nikula vgpu_vreg_t(vgpu, TRANS_DDI_FUNC_CTL(dev_priv, TRANSCODER_A)) |=
44675db1a5bSTina Zhang (TRANS_DDI_BPC_8 | TRANS_DDI_MODE_SELECT_DP_SST |
447efa69d73SPei Zhang (PORT_C << TRANS_DDI_PORT_SHIFT) |
448efa69d73SPei Zhang TRANS_DDI_FUNC_ENABLE);
449295a0d0bSXiong Zhang if (IS_BROADWELL(dev_priv)) {
45090551a12SZhenyu Wang vgpu_vreg_t(vgpu, PORT_CLK_SEL(PORT_C)) &=
451295a0d0bSXiong Zhang ~PORT_CLK_SEL_MASK;
45290551a12SZhenyu Wang vgpu_vreg_t(vgpu, PORT_CLK_SEL(PORT_C)) |=
453295a0d0bSXiong Zhang PORT_CLK_SEL_LCPLL_810;
454295a0d0bSXiong Zhang }
45590551a12SZhenyu Wang vgpu_vreg_t(vgpu, DDI_BUF_CTL(PORT_C)) |= DDI_BUF_CTL_ENABLE;
45690551a12SZhenyu Wang vgpu_vreg_t(vgpu, DDI_BUF_CTL(PORT_C)) &= ~DDI_BUF_IS_IDLE;
45790551a12SZhenyu Wang vgpu_vreg_t(vgpu, SFUSE_STRAP) |= SFUSE_STRAP_DDIC_DETECTED;
458858b0f57SBing Niu }
45904d348aeSZhi Wang
460858b0f57SBing Niu if (intel_vgpu_has_monitor_on_port(vgpu, PORT_D)) {
461f965b681SColin Xu vgpu_vreg_t(vgpu, DPLL_CTRL2) &=
462f965b681SColin Xu ~DPLL_CTRL2_DDI_CLK_OFF(PORT_D);
463f965b681SColin Xu vgpu_vreg_t(vgpu, DPLL_CTRL2) |=
464f965b681SColin Xu DPLL_CTRL2_DDI_CLK_SEL(DPLL_ID_SKL_DPLL0, PORT_D);
465f965b681SColin Xu vgpu_vreg_t(vgpu, DPLL_CTRL2) |=
466f965b681SColin Xu DPLL_CTRL2_DDI_SEL_OVERRIDE(PORT_D);
46790551a12SZhenyu Wang vgpu_vreg_t(vgpu, SDEISR) |= SDE_PORTD_HOTPLUG_CPT;
468*b092d6adSJani Nikula vgpu_vreg_t(vgpu, TRANS_DDI_FUNC_CTL(dev_priv, TRANSCODER_A)) &=
469efa69d73SPei Zhang ~(TRANS_DDI_BPC_MASK | TRANS_DDI_MODE_SELECT_MASK |
470efa69d73SPei Zhang TRANS_DDI_PORT_MASK);
471*b092d6adSJani Nikula vgpu_vreg_t(vgpu, TRANS_DDI_FUNC_CTL(dev_priv, TRANSCODER_A)) |=
47275db1a5bSTina Zhang (TRANS_DDI_BPC_8 | TRANS_DDI_MODE_SELECT_DP_SST |
473efa69d73SPei Zhang (PORT_D << TRANS_DDI_PORT_SHIFT) |
474efa69d73SPei Zhang TRANS_DDI_FUNC_ENABLE);
475295a0d0bSXiong Zhang if (IS_BROADWELL(dev_priv)) {
47690551a12SZhenyu Wang vgpu_vreg_t(vgpu, PORT_CLK_SEL(PORT_D)) &=
477295a0d0bSXiong Zhang ~PORT_CLK_SEL_MASK;
47890551a12SZhenyu Wang vgpu_vreg_t(vgpu, PORT_CLK_SEL(PORT_D)) |=
479295a0d0bSXiong Zhang PORT_CLK_SEL_LCPLL_810;
480295a0d0bSXiong Zhang }
48190551a12SZhenyu Wang vgpu_vreg_t(vgpu, DDI_BUF_CTL(PORT_D)) |= DDI_BUF_CTL_ENABLE;
48290551a12SZhenyu Wang vgpu_vreg_t(vgpu, DDI_BUF_CTL(PORT_D)) &= ~DDI_BUF_IS_IDLE;
48390551a12SZhenyu Wang vgpu_vreg_t(vgpu, SFUSE_STRAP) |= SFUSE_STRAP_DDID_DETECTED;
484858b0f57SBing Niu }
48504d348aeSZhi Wang
4865f4ae270SChris Wilson if ((IS_SKYLAKE(dev_priv) ||
4875f4ae270SChris Wilson IS_KABYLAKE(dev_priv) ||
4885f4ae270SChris Wilson IS_COFFEELAKE(dev_priv) ||
4895f4ae270SChris Wilson IS_COMETLAKE(dev_priv)) &&
49004d348aeSZhi Wang intel_vgpu_has_monitor_on_port(vgpu, PORT_E)) {
49190551a12SZhenyu Wang vgpu_vreg_t(vgpu, SDEISR) |= SDE_PORTE_HOTPLUG_SPT;
49204d348aeSZhi Wang }
49304d348aeSZhi Wang
49404d348aeSZhi Wang if (intel_vgpu_has_monitor_on_port(vgpu, PORT_A)) {
49504d348aeSZhi Wang if (IS_BROADWELL(dev_priv))
49690551a12SZhenyu Wang vgpu_vreg_t(vgpu, GEN8_DE_PORT_ISR) |=
497e5abaab3SVille Syrjälä GEN8_DE_PORT_HOTPLUG(HPD_PORT_A);
49804d348aeSZhi Wang else
49990551a12SZhenyu Wang vgpu_vreg_t(vgpu, SDEISR) |= SDE_PORTA_HOTPLUG_SPT;
500858b0f57SBing Niu
50190551a12SZhenyu Wang vgpu_vreg_t(vgpu, DDI_BUF_CTL(PORT_A)) |= DDI_INIT_DISPLAY_DETECTED;
50204d348aeSZhi Wang }
50375e64ff2SXiong Zhang
50475e64ff2SXiong Zhang /* Clear host CRT status, so guest couldn't detect this host CRT. */
50575e64ff2SXiong Zhang if (IS_BROADWELL(dev_priv))
50690551a12SZhenyu Wang vgpu_vreg_t(vgpu, PCH_ADPA) &= ~ADPA_CRT_HOTPLUG_MONITOR_MASK;
5074e889d62SXiaolin Zhang
50865eff272SXiong Zhang /* Disable Primary/Sprite/Cursor plane */
50965eff272SXiong Zhang for_each_pipe(dev_priv, pipe) {
510be30c827SJani Nikula vgpu_vreg_t(vgpu, DSPCNTR(dev_priv, pipe)) &= ~DISP_ENABLE;
51165eff272SXiong Zhang vgpu_vreg_t(vgpu, SPRCTL(pipe)) &= ~SPRITE_ENABLE;
51293160b2dSJani Nikula vgpu_vreg_t(vgpu, CURCNTR(dev_priv, pipe)) &= ~MCURSOR_MODE_MASK;
51393160b2dSJani Nikula vgpu_vreg_t(vgpu, CURCNTR(dev_priv, pipe)) |= MCURSOR_MODE_DISABLE;
51465eff272SXiong Zhang }
51565eff272SXiong Zhang
516984b61c3SJani Nikula vgpu_vreg_t(vgpu, TRANSCONF(dev_priv, TRANSCODER_A)) |= TRANSCONF_ENABLE;
51704d348aeSZhi Wang }
51804d348aeSZhi Wang
clean_virtual_dp_monitor(struct intel_vgpu * vgpu,int port_num)51904d348aeSZhi Wang static void clean_virtual_dp_monitor(struct intel_vgpu *vgpu, int port_num)
52004d348aeSZhi Wang {
52104d348aeSZhi Wang struct intel_vgpu_port *port = intel_vgpu_port(vgpu, port_num);
52204d348aeSZhi Wang
52304d348aeSZhi Wang kfree(port->edid);
52404d348aeSZhi Wang port->edid = NULL;
52504d348aeSZhi Wang
52604d348aeSZhi Wang kfree(port->dpcd);
52704d348aeSZhi Wang port->dpcd = NULL;
52804d348aeSZhi Wang }
52904d348aeSZhi Wang
vblank_timer_fn(struct hrtimer * data)530b01739fbSColin Xu static enum hrtimer_restart vblank_timer_fn(struct hrtimer *data)
531b01739fbSColin Xu {
532b01739fbSColin Xu struct intel_vgpu_vblank_timer *vblank_timer;
533b01739fbSColin Xu struct intel_vgpu *vgpu;
534b01739fbSColin Xu
535b01739fbSColin Xu vblank_timer = container_of(data, struct intel_vgpu_vblank_timer, timer);
536b01739fbSColin Xu vgpu = container_of(vblank_timer, struct intel_vgpu, vblank_timer);
537b01739fbSColin Xu
538b01739fbSColin Xu /* Set vblank emulation request per-vGPU bit */
539b01739fbSColin Xu intel_gvt_request_service(vgpu->gvt,
540b01739fbSColin Xu INTEL_GVT_REQUEST_EMULATE_VBLANK + vgpu->id);
541b01739fbSColin Xu hrtimer_add_expires_ns(&vblank_timer->timer, vblank_timer->period);
542b01739fbSColin Xu return HRTIMER_RESTART;
543b01739fbSColin Xu }
544b01739fbSColin Xu
setup_virtual_dp_monitor(struct intel_vgpu * vgpu,int port_num,int type,unsigned int resolution)54504d348aeSZhi Wang static int setup_virtual_dp_monitor(struct intel_vgpu *vgpu, int port_num,
546d1a513beSZhenyu Wang int type, unsigned int resolution)
54704d348aeSZhi Wang {
548a61ac1e7SChris Wilson struct drm_i915_private *i915 = vgpu->gvt->gt->i915;
54904d348aeSZhi Wang struct intel_vgpu_port *port = intel_vgpu_port(vgpu, port_num);
550b01739fbSColin Xu struct intel_vgpu_vblank_timer *vblank_timer = &vgpu->vblank_timer;
55104d348aeSZhi Wang
55212d58619SPankaj Bharadiya if (drm_WARN_ON(&i915->drm, resolution >= GVT_EDID_NUM))
553d1a513beSZhenyu Wang return -EINVAL;
554d1a513beSZhenyu Wang
55504d348aeSZhi Wang port->edid = kzalloc(sizeof(*(port->edid)), GFP_KERNEL);
55604d348aeSZhi Wang if (!port->edid)
55704d348aeSZhi Wang return -ENOMEM;
55804d348aeSZhi Wang
55904d348aeSZhi Wang port->dpcd = kzalloc(sizeof(*(port->dpcd)), GFP_KERNEL);
56004d348aeSZhi Wang if (!port->dpcd) {
56104d348aeSZhi Wang kfree(port->edid);
56204d348aeSZhi Wang return -ENOMEM;
56304d348aeSZhi Wang }
56404d348aeSZhi Wang
565d1a513beSZhenyu Wang memcpy(port->edid->edid_block, virtual_dp_monitor_edid[resolution],
56604d348aeSZhi Wang EDID_SIZE);
56704d348aeSZhi Wang port->edid->data_valid = true;
56804d348aeSZhi Wang
56904d348aeSZhi Wang memcpy(port->dpcd->data, dpcd_fix_data, DPCD_HEADER_SIZE);
57004d348aeSZhi Wang port->dpcd->data_valid = true;
57104d348aeSZhi Wang port->dpcd->data[DPCD_SINK_COUNT] = 0x1;
57204d348aeSZhi Wang port->type = type;
57349220789SHang Yuan port->id = resolution;
5746a4500c7SColin Xu port->vrefresh_k = GVT_DEFAULT_REFRESH_RATE * MSEC_PER_SEC;
5756a4500c7SColin Xu vgpu->display.port_num = port_num;
57604d348aeSZhi Wang
577b01739fbSColin Xu /* Init hrtimer based on default refresh rate */
578b01739fbSColin Xu hrtimer_init(&vblank_timer->timer, CLOCK_MONOTONIC, HRTIMER_MODE_ABS);
579b01739fbSColin Xu vblank_timer->timer.function = vblank_timer_fn;
580b01739fbSColin Xu vblank_timer->vrefresh_k = port->vrefresh_k;
581b01739fbSColin Xu vblank_timer->period = DIV64_U64_ROUND_CLOSEST(NSEC_PER_SEC * MSEC_PER_SEC, vblank_timer->vrefresh_k);
58204d348aeSZhi Wang
58304d348aeSZhi Wang emulate_monitor_status_change(vgpu);
5844e889d62SXiaolin Zhang
58504d348aeSZhi Wang return 0;
58604d348aeSZhi Wang }
58704d348aeSZhi Wang
58804d348aeSZhi Wang /**
589b01739fbSColin Xu * vgpu_update_vblank_emulation - Update per-vGPU vblank_timer
590b01739fbSColin Xu * @vgpu: vGPU operated
591b01739fbSColin Xu * @turnon: Turn ON/OFF vblank_timer
59204d348aeSZhi Wang *
593b01739fbSColin Xu * This function is used to turn on/off or update the per-vGPU vblank_timer
5943eb08ea5SVille Syrjälä * when TRANSCONF is enabled or disabled. vblank_timer period is also updated
595b01739fbSColin Xu * if guest changed the refresh rate.
59604d348aeSZhi Wang *
59704d348aeSZhi Wang */
vgpu_update_vblank_emulation(struct intel_vgpu * vgpu,bool turnon)598b01739fbSColin Xu void vgpu_update_vblank_emulation(struct intel_vgpu *vgpu, bool turnon)
59904d348aeSZhi Wang {
600b01739fbSColin Xu struct intel_vgpu_vblank_timer *vblank_timer = &vgpu->vblank_timer;
601b01739fbSColin Xu struct intel_vgpu_port *port =
602b01739fbSColin Xu intel_vgpu_port(vgpu, vgpu->display.port_num);
60304d348aeSZhi Wang
604b01739fbSColin Xu if (turnon) {
605b01739fbSColin Xu /*
606b01739fbSColin Xu * Skip the re-enable if already active and vrefresh unchanged.
607b01739fbSColin Xu * Otherwise, stop timer if already active and restart with new
608b01739fbSColin Xu * period.
609b01739fbSColin Xu */
610b01739fbSColin Xu if (vblank_timer->vrefresh_k != port->vrefresh_k ||
611b01739fbSColin Xu !hrtimer_active(&vblank_timer->timer)) {
612b01739fbSColin Xu /* Stop timer before start with new period if active */
613b01739fbSColin Xu if (hrtimer_active(&vblank_timer->timer))
614b01739fbSColin Xu hrtimer_cancel(&vblank_timer->timer);
61504d348aeSZhi Wang
616b01739fbSColin Xu /* Make sure new refresh rate updated to timer period */
617b01739fbSColin Xu vblank_timer->vrefresh_k = port->vrefresh_k;
618b01739fbSColin Xu vblank_timer->period = DIV64_U64_ROUND_CLOSEST(NSEC_PER_SEC * MSEC_PER_SEC, vblank_timer->vrefresh_k);
619b01739fbSColin Xu hrtimer_start(&vblank_timer->timer,
620b01739fbSColin Xu ktime_add_ns(ktime_get(), vblank_timer->period),
62104d348aeSZhi Wang HRTIMER_MODE_ABS);
622b01739fbSColin Xu }
623b01739fbSColin Xu } else {
624b01739fbSColin Xu /* Caller request to stop vblank */
625b01739fbSColin Xu hrtimer_cancel(&vblank_timer->timer);
626b01739fbSColin Xu }
62704d348aeSZhi Wang }
62804d348aeSZhi Wang
emulate_vblank_on_pipe(struct intel_vgpu * vgpu,int pipe)62904d348aeSZhi Wang static void emulate_vblank_on_pipe(struct intel_vgpu *vgpu, int pipe)
63004d348aeSZhi Wang {
631a61ac1e7SChris Wilson struct drm_i915_private *dev_priv = vgpu->gvt->gt->i915;
63204d348aeSZhi Wang struct intel_vgpu_irq *irq = &vgpu->irq;
63304d348aeSZhi Wang int vblank_event[] = {
63404d348aeSZhi Wang [PIPE_A] = PIPE_A_VBLANK,
63504d348aeSZhi Wang [PIPE_B] = PIPE_B_VBLANK,
63604d348aeSZhi Wang [PIPE_C] = PIPE_C_VBLANK,
63704d348aeSZhi Wang };
63804d348aeSZhi Wang int event;
63904d348aeSZhi Wang
64004d348aeSZhi Wang if (pipe < PIPE_A || pipe > PIPE_C)
64104d348aeSZhi Wang return;
64204d348aeSZhi Wang
64304d348aeSZhi Wang for_each_set_bit(event, irq->flip_done_event[pipe],
64404d348aeSZhi Wang INTEL_GVT_EVENT_MAX) {
64504d348aeSZhi Wang clear_bit(event, irq->flip_done_event[pipe]);
64604d348aeSZhi Wang if (!pipe_is_enabled(vgpu, pipe))
64704d348aeSZhi Wang continue;
64804d348aeSZhi Wang
64904d348aeSZhi Wang intel_vgpu_trigger_virtual_event(vgpu, event);
65004d348aeSZhi Wang }
65104d348aeSZhi Wang
65204d348aeSZhi Wang if (pipe_is_enabled(vgpu, pipe)) {
6538edbb0eeSJani Nikula vgpu_vreg_t(vgpu, PIPE_FRMCOUNT_G4X(dev_priv, pipe))++;
65404d348aeSZhi Wang intel_vgpu_trigger_virtual_event(vgpu, vblank_event[pipe]);
65504d348aeSZhi Wang }
65604d348aeSZhi Wang }
65704d348aeSZhi Wang
intel_vgpu_emulate_vblank(struct intel_vgpu * vgpu)658b01739fbSColin Xu void intel_vgpu_emulate_vblank(struct intel_vgpu *vgpu)
65904d348aeSZhi Wang {
66004d348aeSZhi Wang int pipe;
66104d348aeSZhi Wang
662f25a49abSColin Xu mutex_lock(&vgpu->vgpu_lock);
663a61ac1e7SChris Wilson for_each_pipe(vgpu->gvt->gt->i915, pipe)
66404d348aeSZhi Wang emulate_vblank_on_pipe(vgpu, pipe);
665f25a49abSColin Xu mutex_unlock(&vgpu->vgpu_lock);
66604d348aeSZhi Wang }
66704d348aeSZhi Wang
66804d348aeSZhi Wang /**
6691ca20f33SHang Yuan * intel_vgpu_emulate_hotplug - trigger hotplug event for vGPU
6701ca20f33SHang Yuan * @vgpu: a vGPU
671cf9ed666SChris Wilson * @connected: link state
6721ca20f33SHang Yuan *
6731ca20f33SHang Yuan * This function is used to trigger hotplug interrupt for vGPU
6741ca20f33SHang Yuan *
6751ca20f33SHang Yuan */
intel_vgpu_emulate_hotplug(struct intel_vgpu * vgpu,bool connected)6761ca20f33SHang Yuan void intel_vgpu_emulate_hotplug(struct intel_vgpu *vgpu, bool connected)
6771ca20f33SHang Yuan {
678a61ac1e7SChris Wilson struct drm_i915_private *i915 = vgpu->gvt->gt->i915;
6791ca20f33SHang Yuan
6801ca20f33SHang Yuan /* TODO: add more platforms support */
6815f4ae270SChris Wilson if (IS_SKYLAKE(i915) ||
6825f4ae270SChris Wilson IS_KABYLAKE(i915) ||
6835f4ae270SChris Wilson IS_COFFEELAKE(i915) ||
6845f4ae270SChris Wilson IS_COMETLAKE(i915)) {
6851ca20f33SHang Yuan if (connected) {
6861ca20f33SHang Yuan vgpu_vreg_t(vgpu, SFUSE_STRAP) |=
6871ca20f33SHang Yuan SFUSE_STRAP_DDID_DETECTED;
6881ca20f33SHang Yuan vgpu_vreg_t(vgpu, SDEISR) |= SDE_PORTD_HOTPLUG_CPT;
6891ca20f33SHang Yuan } else {
6901ca20f33SHang Yuan vgpu_vreg_t(vgpu, SFUSE_STRAP) &=
6911ca20f33SHang Yuan ~SFUSE_STRAP_DDID_DETECTED;
6921ca20f33SHang Yuan vgpu_vreg_t(vgpu, SDEISR) &= ~SDE_PORTD_HOTPLUG_CPT;
6931ca20f33SHang Yuan }
6941ca20f33SHang Yuan vgpu_vreg_t(vgpu, SDEIIR) |= SDE_PORTD_HOTPLUG_CPT;
6951ca20f33SHang Yuan vgpu_vreg_t(vgpu, PCH_PORT_HOTPLUG) |=
6961ca20f33SHang Yuan PORTD_HOTPLUG_STATUS_MASK;
6971ca20f33SHang Yuan intel_vgpu_trigger_virtual_event(vgpu, DP_D_HOTPLUG);
698a5a8ef93SColin Xu } else if (IS_BROXTON(i915)) {
699a5a8ef93SColin Xu if (intel_vgpu_has_monitor_on_port(vgpu, PORT_A)) {
7004ceb06e7SColin Xu if (connected) {
701a5a8ef93SColin Xu vgpu_vreg_t(vgpu, GEN8_DE_PORT_ISR) |=
702a5a8ef93SColin Xu GEN8_DE_PORT_HOTPLUG(HPD_PORT_A);
703a5a8ef93SColin Xu } else {
704a5a8ef93SColin Xu vgpu_vreg_t(vgpu, GEN8_DE_PORT_ISR) &=
705a5a8ef93SColin Xu ~GEN8_DE_PORT_HOTPLUG(HPD_PORT_A);
706a5a8ef93SColin Xu }
7074ceb06e7SColin Xu vgpu_vreg_t(vgpu, GEN8_DE_PORT_IIR) |=
7084ceb06e7SColin Xu GEN8_DE_PORT_HOTPLUG(HPD_PORT_A);
7094ceb06e7SColin Xu vgpu_vreg_t(vgpu, PCH_PORT_HOTPLUG) &=
7104ceb06e7SColin Xu ~PORTA_HOTPLUG_STATUS_MASK;
7114ceb06e7SColin Xu vgpu_vreg_t(vgpu, PCH_PORT_HOTPLUG) |=
7124ceb06e7SColin Xu PORTA_HOTPLUG_LONG_DETECT;
7134ceb06e7SColin Xu intel_vgpu_trigger_virtual_event(vgpu, DP_A_HOTPLUG);
7144ceb06e7SColin Xu }
715a5a8ef93SColin Xu if (intel_vgpu_has_monitor_on_port(vgpu, PORT_B)) {
7164ceb06e7SColin Xu if (connected) {
7174ceb06e7SColin Xu vgpu_vreg_t(vgpu, GEN8_DE_PORT_ISR) |=
7184ceb06e7SColin Xu GEN8_DE_PORT_HOTPLUG(HPD_PORT_B);
7194ceb06e7SColin Xu vgpu_vreg_t(vgpu, SFUSE_STRAP) |=
7204ceb06e7SColin Xu SFUSE_STRAP_DDIB_DETECTED;
7214ceb06e7SColin Xu } else {
722a5a8ef93SColin Xu vgpu_vreg_t(vgpu, GEN8_DE_PORT_ISR) &=
723a5a8ef93SColin Xu ~GEN8_DE_PORT_HOTPLUG(HPD_PORT_B);
7244ceb06e7SColin Xu vgpu_vreg_t(vgpu, SFUSE_STRAP) &=
7254ceb06e7SColin Xu ~SFUSE_STRAP_DDIB_DETECTED;
7264ceb06e7SColin Xu }
7274ceb06e7SColin Xu vgpu_vreg_t(vgpu, GEN8_DE_PORT_IIR) |=
7284ceb06e7SColin Xu GEN8_DE_PORT_HOTPLUG(HPD_PORT_B);
7294ceb06e7SColin Xu vgpu_vreg_t(vgpu, PCH_PORT_HOTPLUG) &=
7304ceb06e7SColin Xu ~PORTB_HOTPLUG_STATUS_MASK;
7314ceb06e7SColin Xu vgpu_vreg_t(vgpu, PCH_PORT_HOTPLUG) |=
7324ceb06e7SColin Xu PORTB_HOTPLUG_LONG_DETECT;
7334ceb06e7SColin Xu intel_vgpu_trigger_virtual_event(vgpu, DP_B_HOTPLUG);
734a5a8ef93SColin Xu }
735a5a8ef93SColin Xu if (intel_vgpu_has_monitor_on_port(vgpu, PORT_C)) {
7364ceb06e7SColin Xu if (connected) {
7374ceb06e7SColin Xu vgpu_vreg_t(vgpu, GEN8_DE_PORT_ISR) |=
7384ceb06e7SColin Xu GEN8_DE_PORT_HOTPLUG(HPD_PORT_C);
7394ceb06e7SColin Xu vgpu_vreg_t(vgpu, SFUSE_STRAP) |=
7404ceb06e7SColin Xu SFUSE_STRAP_DDIC_DETECTED;
7414ceb06e7SColin Xu } else {
742a5a8ef93SColin Xu vgpu_vreg_t(vgpu, GEN8_DE_PORT_ISR) &=
743a5a8ef93SColin Xu ~GEN8_DE_PORT_HOTPLUG(HPD_PORT_C);
7444ceb06e7SColin Xu vgpu_vreg_t(vgpu, SFUSE_STRAP) &=
7454ceb06e7SColin Xu ~SFUSE_STRAP_DDIC_DETECTED;
746a5a8ef93SColin Xu }
7474ceb06e7SColin Xu vgpu_vreg_t(vgpu, GEN8_DE_PORT_IIR) |=
7484ceb06e7SColin Xu GEN8_DE_PORT_HOTPLUG(HPD_PORT_C);
7494ceb06e7SColin Xu vgpu_vreg_t(vgpu, PCH_PORT_HOTPLUG) &=
7504ceb06e7SColin Xu ~PORTC_HOTPLUG_STATUS_MASK;
751a5a8ef93SColin Xu vgpu_vreg_t(vgpu, PCH_PORT_HOTPLUG) |=
7524ceb06e7SColin Xu PORTC_HOTPLUG_LONG_DETECT;
7534ceb06e7SColin Xu intel_vgpu_trigger_virtual_event(vgpu, DP_C_HOTPLUG);
7544ceb06e7SColin Xu }
7551ca20f33SHang Yuan }
7561ca20f33SHang Yuan }
7571ca20f33SHang Yuan
7581ca20f33SHang Yuan /**
75904d348aeSZhi Wang * intel_vgpu_clean_display - clean vGPU virtual display emulation
76004d348aeSZhi Wang * @vgpu: a vGPU
76104d348aeSZhi Wang *
76204d348aeSZhi Wang * This function is used to clean vGPU virtual display emulation stuffs
76304d348aeSZhi Wang *
76404d348aeSZhi Wang */
intel_vgpu_clean_display(struct intel_vgpu * vgpu)76504d348aeSZhi Wang void intel_vgpu_clean_display(struct intel_vgpu *vgpu)
76604d348aeSZhi Wang {
767a61ac1e7SChris Wilson struct drm_i915_private *dev_priv = vgpu->gvt->gt->i915;
76804d348aeSZhi Wang
7695f4ae270SChris Wilson if (IS_SKYLAKE(dev_priv) ||
7705f4ae270SChris Wilson IS_KABYLAKE(dev_priv) ||
7715f4ae270SChris Wilson IS_COFFEELAKE(dev_priv) ||
7725f4ae270SChris Wilson IS_COMETLAKE(dev_priv))
77304d348aeSZhi Wang clean_virtual_dp_monitor(vgpu, PORT_D);
77404d348aeSZhi Wang else
77504d348aeSZhi Wang clean_virtual_dp_monitor(vgpu, PORT_B);
776b01739fbSColin Xu
777b01739fbSColin Xu vgpu_update_vblank_emulation(vgpu, false);
77804d348aeSZhi Wang }
77904d348aeSZhi Wang
78004d348aeSZhi Wang /**
78104d348aeSZhi Wang * intel_vgpu_init_display- initialize vGPU virtual display emulation
78204d348aeSZhi Wang * @vgpu: a vGPU
783a752b070SZhenyu Wang * @resolution: resolution index for intel_vgpu_edid
78404d348aeSZhi Wang *
78504d348aeSZhi Wang * This function is used to initialize vGPU virtual display emulation stuffs
78604d348aeSZhi Wang *
78704d348aeSZhi Wang * Returns:
78804d348aeSZhi Wang * Zero on success, negative error code if failed.
78904d348aeSZhi Wang *
79004d348aeSZhi Wang */
intel_vgpu_init_display(struct intel_vgpu * vgpu,u64 resolution)791d1a513beSZhenyu Wang int intel_vgpu_init_display(struct intel_vgpu *vgpu, u64 resolution)
79204d348aeSZhi Wang {
793a61ac1e7SChris Wilson struct drm_i915_private *dev_priv = vgpu->gvt->gt->i915;
79404d348aeSZhi Wang
79504d348aeSZhi Wang intel_vgpu_init_i2c_edid(vgpu);
79604d348aeSZhi Wang
7975f4ae270SChris Wilson if (IS_SKYLAKE(dev_priv) ||
7985f4ae270SChris Wilson IS_KABYLAKE(dev_priv) ||
7995f4ae270SChris Wilson IS_COFFEELAKE(dev_priv) ||
8005f4ae270SChris Wilson IS_COMETLAKE(dev_priv))
801d1a513beSZhenyu Wang return setup_virtual_dp_monitor(vgpu, PORT_D, GVT_DP_D,
802d1a513beSZhenyu Wang resolution);
80304d348aeSZhi Wang else
804d1a513beSZhenyu Wang return setup_virtual_dp_monitor(vgpu, PORT_B, GVT_DP_B,
805d1a513beSZhenyu Wang resolution);
80604d348aeSZhi Wang }
8076294b61bSChangbin Du
8086294b61bSChangbin Du /**
8096294b61bSChangbin Du * intel_vgpu_reset_display- reset vGPU virtual display emulation
8106294b61bSChangbin Du * @vgpu: a vGPU
8116294b61bSChangbin Du *
8126294b61bSChangbin Du * This function is used to reset vGPU virtual display emulation stuffs
8136294b61bSChangbin Du *
8146294b61bSChangbin Du */
intel_vgpu_reset_display(struct intel_vgpu * vgpu)8156294b61bSChangbin Du void intel_vgpu_reset_display(struct intel_vgpu *vgpu)
8166294b61bSChangbin Du {
8176294b61bSChangbin Du emulate_monitor_status_change(vgpu);
8186294b61bSChangbin Du }
819