18c2ecf20Sopenharmony_ci/*
28c2ecf20Sopenharmony_ci * Copyright(c) 2011-2016 Intel Corporation. All rights reserved.
38c2ecf20Sopenharmony_ci *
48c2ecf20Sopenharmony_ci * Permission is hereby granted, free of charge, to any person obtaining a
58c2ecf20Sopenharmony_ci * copy of this software and associated documentation files (the "Software"),
68c2ecf20Sopenharmony_ci * to deal in the Software without restriction, including without limitation
78c2ecf20Sopenharmony_ci * the rights to use, copy, modify, merge, publish, distribute, sublicense,
88c2ecf20Sopenharmony_ci * and/or sell copies of the Software, and to permit persons to whom the
98c2ecf20Sopenharmony_ci * Software is furnished to do so, subject to the following conditions:
108c2ecf20Sopenharmony_ci *
118c2ecf20Sopenharmony_ci * The above copyright notice and this permission notice (including the next
128c2ecf20Sopenharmony_ci * paragraph) shall be included in all copies or substantial portions of the
138c2ecf20Sopenharmony_ci * Software.
148c2ecf20Sopenharmony_ci *
158c2ecf20Sopenharmony_ci * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
168c2ecf20Sopenharmony_ci * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
178c2ecf20Sopenharmony_ci * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
188c2ecf20Sopenharmony_ci * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
198c2ecf20Sopenharmony_ci * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
208c2ecf20Sopenharmony_ci * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
218c2ecf20Sopenharmony_ci * SOFTWARE.
228c2ecf20Sopenharmony_ci *
238c2ecf20Sopenharmony_ci * Authors:
248c2ecf20Sopenharmony_ci *    Ke Yu
258c2ecf20Sopenharmony_ci *    Zhiyuan Lv <zhiyuan.lv@intel.com>
268c2ecf20Sopenharmony_ci *
278c2ecf20Sopenharmony_ci * Contributors:
288c2ecf20Sopenharmony_ci *    Terrence Xu <terrence.xu@intel.com>
298c2ecf20Sopenharmony_ci *    Changbin Du <changbin.du@intel.com>
308c2ecf20Sopenharmony_ci *    Bing Niu <bing.niu@intel.com>
318c2ecf20Sopenharmony_ci *    Zhi Wang <zhi.a.wang@intel.com>
328c2ecf20Sopenharmony_ci *
338c2ecf20Sopenharmony_ci */
348c2ecf20Sopenharmony_ci
358c2ecf20Sopenharmony_ci#include "i915_drv.h"
368c2ecf20Sopenharmony_ci#include "gvt.h"
378c2ecf20Sopenharmony_ci
388c2ecf20Sopenharmony_cistatic int get_edp_pipe(struct intel_vgpu *vgpu)
398c2ecf20Sopenharmony_ci{
408c2ecf20Sopenharmony_ci	u32 data = vgpu_vreg(vgpu, _TRANS_DDI_FUNC_CTL_EDP);
418c2ecf20Sopenharmony_ci	int pipe = -1;
428c2ecf20Sopenharmony_ci
438c2ecf20Sopenharmony_ci	switch (data & TRANS_DDI_EDP_INPUT_MASK) {
448c2ecf20Sopenharmony_ci	case TRANS_DDI_EDP_INPUT_A_ON:
458c2ecf20Sopenharmony_ci	case TRANS_DDI_EDP_INPUT_A_ONOFF:
468c2ecf20Sopenharmony_ci		pipe = PIPE_A;
478c2ecf20Sopenharmony_ci		break;
488c2ecf20Sopenharmony_ci	case TRANS_DDI_EDP_INPUT_B_ONOFF:
498c2ecf20Sopenharmony_ci		pipe = PIPE_B;
508c2ecf20Sopenharmony_ci		break;
518c2ecf20Sopenharmony_ci	case TRANS_DDI_EDP_INPUT_C_ONOFF:
528c2ecf20Sopenharmony_ci		pipe = PIPE_C;
538c2ecf20Sopenharmony_ci		break;
548c2ecf20Sopenharmony_ci	}
558c2ecf20Sopenharmony_ci	return pipe;
568c2ecf20Sopenharmony_ci}
578c2ecf20Sopenharmony_ci
588c2ecf20Sopenharmony_cistatic int edp_pipe_is_enabled(struct intel_vgpu *vgpu)
598c2ecf20Sopenharmony_ci{
608c2ecf20Sopenharmony_ci	struct drm_i915_private *dev_priv = vgpu->gvt->gt->i915;
618c2ecf20Sopenharmony_ci
628c2ecf20Sopenharmony_ci	if (!(vgpu_vreg_t(vgpu, PIPECONF(_PIPE_EDP)) & PIPECONF_ENABLE))
638c2ecf20Sopenharmony_ci		return 0;
648c2ecf20Sopenharmony_ci
658c2ecf20Sopenharmony_ci	if (!(vgpu_vreg(vgpu, _TRANS_DDI_FUNC_CTL_EDP) & TRANS_DDI_FUNC_ENABLE))
668c2ecf20Sopenharmony_ci		return 0;
678c2ecf20Sopenharmony_ci	return 1;
688c2ecf20Sopenharmony_ci}
698c2ecf20Sopenharmony_ci
708c2ecf20Sopenharmony_ciint pipe_is_enabled(struct intel_vgpu *vgpu, int pipe)
718c2ecf20Sopenharmony_ci{
728c2ecf20Sopenharmony_ci	struct drm_i915_private *dev_priv = vgpu->gvt->gt->i915;
738c2ecf20Sopenharmony_ci
748c2ecf20Sopenharmony_ci	if (drm_WARN_ON(&dev_priv->drm,
758c2ecf20Sopenharmony_ci			pipe < PIPE_A || pipe >= I915_MAX_PIPES))
768c2ecf20Sopenharmony_ci		return -EINVAL;
778c2ecf20Sopenharmony_ci
788c2ecf20Sopenharmony_ci	if (vgpu_vreg_t(vgpu, PIPECONF(pipe)) & PIPECONF_ENABLE)
798c2ecf20Sopenharmony_ci		return 1;
808c2ecf20Sopenharmony_ci
818c2ecf20Sopenharmony_ci	if (edp_pipe_is_enabled(vgpu) &&
828c2ecf20Sopenharmony_ci			get_edp_pipe(vgpu) == pipe)
838c2ecf20Sopenharmony_ci		return 1;
848c2ecf20Sopenharmony_ci	return 0;
858c2ecf20Sopenharmony_ci}
868c2ecf20Sopenharmony_ci
878c2ecf20Sopenharmony_cistatic unsigned char virtual_dp_monitor_edid[GVT_EDID_NUM][EDID_SIZE] = {
888c2ecf20Sopenharmony_ci	{
898c2ecf20Sopenharmony_ci/* EDID with 1024x768 as its resolution */
908c2ecf20Sopenharmony_ci		/*Header*/
918c2ecf20Sopenharmony_ci		0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00,
928c2ecf20Sopenharmony_ci		/* Vendor & Product Identification */
938c2ecf20Sopenharmony_ci		0x22, 0xf0, 0x54, 0x29, 0x00, 0x00, 0x00, 0x00, 0x04, 0x17,
948c2ecf20Sopenharmony_ci		/* Version & Revision */
958c2ecf20Sopenharmony_ci		0x01, 0x04,
968c2ecf20Sopenharmony_ci		/* Basic Display Parameters & Features */
978c2ecf20Sopenharmony_ci		0xa5, 0x34, 0x20, 0x78, 0x23,
988c2ecf20Sopenharmony_ci		/* Color Characteristics */
998c2ecf20Sopenharmony_ci		0xfc, 0x81, 0xa4, 0x55, 0x4d, 0x9d, 0x25, 0x12, 0x50, 0x54,
1008c2ecf20Sopenharmony_ci		/* Established Timings: maximum resolution is 1024x768 */
1018c2ecf20Sopenharmony_ci		0x21, 0x08, 0x00,
1028c2ecf20Sopenharmony_ci		/* Standard Timings. All invalid */
1038c2ecf20Sopenharmony_ci		0x00, 0xc0, 0x00, 0xc0, 0x00, 0x40, 0x00, 0x80, 0x00, 0x00,
1048c2ecf20Sopenharmony_ci		0x00, 0x40, 0x00, 0x00, 0x00, 0x01,
1058c2ecf20Sopenharmony_ci		/* 18 Byte Data Blocks 1: invalid */
1068c2ecf20Sopenharmony_ci		0x00, 0x00, 0x80, 0xa0, 0x70, 0xb0,
1078c2ecf20Sopenharmony_ci		0x23, 0x40, 0x30, 0x20, 0x36, 0x00, 0x06, 0x44, 0x21, 0x00, 0x00, 0x1a,
1088c2ecf20Sopenharmony_ci		/* 18 Byte Data Blocks 2: invalid */
1098c2ecf20Sopenharmony_ci		0x00, 0x00, 0x00, 0xfd, 0x00, 0x18, 0x3c, 0x18, 0x50, 0x11, 0x00, 0x0a,
1108c2ecf20Sopenharmony_ci		0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
1118c2ecf20Sopenharmony_ci		/* 18 Byte Data Blocks 3: invalid */
1128c2ecf20Sopenharmony_ci		0x00, 0x00, 0x00, 0xfc, 0x00, 0x48,
1138c2ecf20Sopenharmony_ci		0x50, 0x20, 0x5a, 0x52, 0x32, 0x34, 0x34, 0x30, 0x77, 0x0a, 0x20, 0x20,
1148c2ecf20Sopenharmony_ci		/* 18 Byte Data Blocks 4: invalid */
1158c2ecf20Sopenharmony_ci		0x00, 0x00, 0x00, 0xff, 0x00, 0x43, 0x4e, 0x34, 0x33, 0x30, 0x34, 0x30,
1168c2ecf20Sopenharmony_ci		0x44, 0x58, 0x51, 0x0a, 0x20, 0x20,
1178c2ecf20Sopenharmony_ci		/* Extension Block Count */
1188c2ecf20Sopenharmony_ci		0x00,
1198c2ecf20Sopenharmony_ci		/* Checksum */
1208c2ecf20Sopenharmony_ci		0xef,
1218c2ecf20Sopenharmony_ci	},
1228c2ecf20Sopenharmony_ci	{
1238c2ecf20Sopenharmony_ci/* EDID with 1920x1200 as its resolution */
1248c2ecf20Sopenharmony_ci		/*Header*/
1258c2ecf20Sopenharmony_ci		0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00,
1268c2ecf20Sopenharmony_ci		/* Vendor & Product Identification */
1278c2ecf20Sopenharmony_ci		0x22, 0xf0, 0x54, 0x29, 0x00, 0x00, 0x00, 0x00, 0x04, 0x17,
1288c2ecf20Sopenharmony_ci		/* Version & Revision */
1298c2ecf20Sopenharmony_ci		0x01, 0x04,
1308c2ecf20Sopenharmony_ci		/* Basic Display Parameters & Features */
1318c2ecf20Sopenharmony_ci		0xa5, 0x34, 0x20, 0x78, 0x23,
1328c2ecf20Sopenharmony_ci		/* Color Characteristics */
1338c2ecf20Sopenharmony_ci		0xfc, 0x81, 0xa4, 0x55, 0x4d, 0x9d, 0x25, 0x12, 0x50, 0x54,
1348c2ecf20Sopenharmony_ci		/* Established Timings: maximum resolution is 1024x768 */
1358c2ecf20Sopenharmony_ci		0x21, 0x08, 0x00,
1368c2ecf20Sopenharmony_ci		/*
1378c2ecf20Sopenharmony_ci		 * Standard Timings.
1388c2ecf20Sopenharmony_ci		 * below new resolutions can be supported:
1398c2ecf20Sopenharmony_ci		 * 1920x1080, 1280x720, 1280x960, 1280x1024,
1408c2ecf20Sopenharmony_ci		 * 1440x900, 1600x1200, 1680x1050
1418c2ecf20Sopenharmony_ci		 */
1428c2ecf20Sopenharmony_ci		0xd1, 0xc0, 0x81, 0xc0, 0x81, 0x40, 0x81, 0x80, 0x95, 0x00,
1438c2ecf20Sopenharmony_ci		0xa9, 0x40, 0xb3, 0x00, 0x01, 0x01,
1448c2ecf20Sopenharmony_ci		/* 18 Byte Data Blocks 1: max resolution is 1920x1200 */
1458c2ecf20Sopenharmony_ci		0x28, 0x3c, 0x80, 0xa0, 0x70, 0xb0,
1468c2ecf20Sopenharmony_ci		0x23, 0x40, 0x30, 0x20, 0x36, 0x00, 0x06, 0x44, 0x21, 0x00, 0x00, 0x1a,
1478c2ecf20Sopenharmony_ci		/* 18 Byte Data Blocks 2: invalid */
1488c2ecf20Sopenharmony_ci		0x00, 0x00, 0x00, 0xfd, 0x00, 0x18, 0x3c, 0x18, 0x50, 0x11, 0x00, 0x0a,
1498c2ecf20Sopenharmony_ci		0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
1508c2ecf20Sopenharmony_ci		/* 18 Byte Data Blocks 3: invalid */
1518c2ecf20Sopenharmony_ci		0x00, 0x00, 0x00, 0xfc, 0x00, 0x48,
1528c2ecf20Sopenharmony_ci		0x50, 0x20, 0x5a, 0x52, 0x32, 0x34, 0x34, 0x30, 0x77, 0x0a, 0x20, 0x20,
1538c2ecf20Sopenharmony_ci		/* 18 Byte Data Blocks 4: invalid */
1548c2ecf20Sopenharmony_ci		0x00, 0x00, 0x00, 0xff, 0x00, 0x43, 0x4e, 0x34, 0x33, 0x30, 0x34, 0x30,
1558c2ecf20Sopenharmony_ci		0x44, 0x58, 0x51, 0x0a, 0x20, 0x20,
1568c2ecf20Sopenharmony_ci		/* Extension Block Count */
1578c2ecf20Sopenharmony_ci		0x00,
1588c2ecf20Sopenharmony_ci		/* Checksum */
1598c2ecf20Sopenharmony_ci		0x45,
1608c2ecf20Sopenharmony_ci	},
1618c2ecf20Sopenharmony_ci};
1628c2ecf20Sopenharmony_ci
1638c2ecf20Sopenharmony_ci#define DPCD_HEADER_SIZE        0xb
1648c2ecf20Sopenharmony_ci
1658c2ecf20Sopenharmony_ci/* let the virtual display supports DP1.2 */
1668c2ecf20Sopenharmony_cistatic u8 dpcd_fix_data[DPCD_HEADER_SIZE] = {
1678c2ecf20Sopenharmony_ci	0x12, 0x014, 0x84, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
1688c2ecf20Sopenharmony_ci};
1698c2ecf20Sopenharmony_ci
1708c2ecf20Sopenharmony_cistatic void emulate_monitor_status_change(struct intel_vgpu *vgpu)
1718c2ecf20Sopenharmony_ci{
1728c2ecf20Sopenharmony_ci	struct drm_i915_private *dev_priv = vgpu->gvt->gt->i915;
1738c2ecf20Sopenharmony_ci	int pipe;
1748c2ecf20Sopenharmony_ci
1758c2ecf20Sopenharmony_ci	if (IS_BROXTON(dev_priv)) {
1768c2ecf20Sopenharmony_ci		enum transcoder trans;
1778c2ecf20Sopenharmony_ci		enum port port;
1788c2ecf20Sopenharmony_ci
1798c2ecf20Sopenharmony_ci		/* Clear PIPE, DDI, PHY, HPD before setting new */
1808c2ecf20Sopenharmony_ci		vgpu_vreg_t(vgpu, GEN8_DE_PORT_ISR) &= ~(BXT_DE_PORT_HP_DDIA |
1818c2ecf20Sopenharmony_ci			BXT_DE_PORT_HP_DDIB |
1828c2ecf20Sopenharmony_ci			BXT_DE_PORT_HP_DDIC);
1838c2ecf20Sopenharmony_ci
1848c2ecf20Sopenharmony_ci		for_each_pipe(dev_priv, pipe) {
1858c2ecf20Sopenharmony_ci			vgpu_vreg_t(vgpu, PIPECONF(pipe)) &=
1868c2ecf20Sopenharmony_ci				~(PIPECONF_ENABLE | I965_PIPECONF_ACTIVE);
1878c2ecf20Sopenharmony_ci			vgpu_vreg_t(vgpu, DSPCNTR(pipe)) &= ~DISPLAY_PLANE_ENABLE;
1888c2ecf20Sopenharmony_ci			vgpu_vreg_t(vgpu, SPRCTL(pipe)) &= ~SPRITE_ENABLE;
1898c2ecf20Sopenharmony_ci			vgpu_vreg_t(vgpu, CURCNTR(pipe)) &= ~MCURSOR_MODE;
1908c2ecf20Sopenharmony_ci			vgpu_vreg_t(vgpu, CURCNTR(pipe)) |= MCURSOR_MODE_DISABLE;
1918c2ecf20Sopenharmony_ci		}
1928c2ecf20Sopenharmony_ci
1938c2ecf20Sopenharmony_ci		for (trans = TRANSCODER_A; trans <= TRANSCODER_EDP; trans++) {
1948c2ecf20Sopenharmony_ci			vgpu_vreg_t(vgpu, TRANS_DDI_FUNC_CTL(trans)) &=
1958c2ecf20Sopenharmony_ci				~(TRANS_DDI_BPC_MASK | TRANS_DDI_MODE_SELECT_MASK |
1968c2ecf20Sopenharmony_ci				  TRANS_DDI_PORT_MASK | TRANS_DDI_FUNC_ENABLE);
1978c2ecf20Sopenharmony_ci		}
1988c2ecf20Sopenharmony_ci		vgpu_vreg_t(vgpu, TRANS_DDI_FUNC_CTL(TRANSCODER_A)) &=
1998c2ecf20Sopenharmony_ci			~(TRANS_DDI_BPC_MASK | TRANS_DDI_MODE_SELECT_MASK |
2008c2ecf20Sopenharmony_ci			  TRANS_DDI_PORT_MASK);
2018c2ecf20Sopenharmony_ci
2028c2ecf20Sopenharmony_ci		for (port = PORT_A; port <= PORT_C; port++) {
2038c2ecf20Sopenharmony_ci			vgpu_vreg_t(vgpu, BXT_PHY_CTL(port)) &=
2048c2ecf20Sopenharmony_ci				~BXT_PHY_LANE_ENABLED;
2058c2ecf20Sopenharmony_ci			vgpu_vreg_t(vgpu, BXT_PHY_CTL(port)) |=
2068c2ecf20Sopenharmony_ci				(BXT_PHY_CMNLANE_POWERDOWN_ACK |
2078c2ecf20Sopenharmony_ci				 BXT_PHY_LANE_POWERDOWN_ACK);
2088c2ecf20Sopenharmony_ci
2098c2ecf20Sopenharmony_ci			vgpu_vreg_t(vgpu, BXT_PORT_PLL_ENABLE(port)) &=
2108c2ecf20Sopenharmony_ci				~(PORT_PLL_POWER_STATE | PORT_PLL_POWER_ENABLE |
2118c2ecf20Sopenharmony_ci				  PORT_PLL_REF_SEL | PORT_PLL_LOCK |
2128c2ecf20Sopenharmony_ci				  PORT_PLL_ENABLE);
2138c2ecf20Sopenharmony_ci
2148c2ecf20Sopenharmony_ci			vgpu_vreg_t(vgpu, DDI_BUF_CTL(port)) &=
2158c2ecf20Sopenharmony_ci				~(DDI_INIT_DISPLAY_DETECTED |
2168c2ecf20Sopenharmony_ci				  DDI_BUF_CTL_ENABLE);
2178c2ecf20Sopenharmony_ci			vgpu_vreg_t(vgpu, DDI_BUF_CTL(port)) |= DDI_BUF_IS_IDLE;
2188c2ecf20Sopenharmony_ci		}
2198c2ecf20Sopenharmony_ci		vgpu_vreg_t(vgpu, PCH_PORT_HOTPLUG) &=
2208c2ecf20Sopenharmony_ci			~(PORTA_HOTPLUG_ENABLE | PORTA_HOTPLUG_STATUS_MASK);
2218c2ecf20Sopenharmony_ci		vgpu_vreg_t(vgpu, PCH_PORT_HOTPLUG) &=
2228c2ecf20Sopenharmony_ci			~(PORTB_HOTPLUG_ENABLE | PORTB_HOTPLUG_STATUS_MASK);
2238c2ecf20Sopenharmony_ci		vgpu_vreg_t(vgpu, PCH_PORT_HOTPLUG) &=
2248c2ecf20Sopenharmony_ci			~(PORTC_HOTPLUG_ENABLE | PORTC_HOTPLUG_STATUS_MASK);
2258c2ecf20Sopenharmony_ci		/* No hpd_invert set in vgpu vbt, need to clear invert mask */
2268c2ecf20Sopenharmony_ci		vgpu_vreg_t(vgpu, PCH_PORT_HOTPLUG) &= ~BXT_DDI_HPD_INVERT_MASK;
2278c2ecf20Sopenharmony_ci		vgpu_vreg_t(vgpu, GEN8_DE_PORT_ISR) &= ~BXT_DE_PORT_HOTPLUG_MASK;
2288c2ecf20Sopenharmony_ci
2298c2ecf20Sopenharmony_ci		vgpu_vreg_t(vgpu, BXT_P_CR_GT_DISP_PWRON) &= ~(BIT(0) | BIT(1));
2308c2ecf20Sopenharmony_ci		vgpu_vreg_t(vgpu, BXT_PORT_CL1CM_DW0(DPIO_PHY0)) &=
2318c2ecf20Sopenharmony_ci			~PHY_POWER_GOOD;
2328c2ecf20Sopenharmony_ci		vgpu_vreg_t(vgpu, BXT_PORT_CL1CM_DW0(DPIO_PHY1)) &=
2338c2ecf20Sopenharmony_ci			~PHY_POWER_GOOD;
2348c2ecf20Sopenharmony_ci		vgpu_vreg_t(vgpu, BXT_PHY_CTL_FAMILY(DPIO_PHY0)) &= ~BIT(30);
2358c2ecf20Sopenharmony_ci		vgpu_vreg_t(vgpu, BXT_PHY_CTL_FAMILY(DPIO_PHY1)) &= ~BIT(30);
2368c2ecf20Sopenharmony_ci
2378c2ecf20Sopenharmony_ci		vgpu_vreg_t(vgpu, SFUSE_STRAP) &= ~SFUSE_STRAP_DDIB_DETECTED;
2388c2ecf20Sopenharmony_ci		vgpu_vreg_t(vgpu, SFUSE_STRAP) &= ~SFUSE_STRAP_DDIC_DETECTED;
2398c2ecf20Sopenharmony_ci
2408c2ecf20Sopenharmony_ci		/*
2418c2ecf20Sopenharmony_ci		 * Only 1 PIPE enabled in current vGPU display and PIPE_A is
2428c2ecf20Sopenharmony_ci		 *  tied to TRANSCODER_A in HW, so it's safe to assume PIPE_A,
2438c2ecf20Sopenharmony_ci		 *   TRANSCODER_A can be enabled. PORT_x depends on the input of
2448c2ecf20Sopenharmony_ci		 *   setup_virtual_dp_monitor.
2458c2ecf20Sopenharmony_ci		 */
2468c2ecf20Sopenharmony_ci		vgpu_vreg_t(vgpu, PIPECONF(PIPE_A)) |= PIPECONF_ENABLE;
2478c2ecf20Sopenharmony_ci		vgpu_vreg_t(vgpu, PIPECONF(PIPE_A)) |= I965_PIPECONF_ACTIVE;
2488c2ecf20Sopenharmony_ci
2498c2ecf20Sopenharmony_ci		/*
2508c2ecf20Sopenharmony_ci		 * Golden M/N are calculated based on:
2518c2ecf20Sopenharmony_ci		 *   24 bpp, 4 lanes, 154000 pixel clk (from virtual EDID),
2528c2ecf20Sopenharmony_ci		 *   DP link clk 1620 MHz and non-constant_n.
2538c2ecf20Sopenharmony_ci		 * TODO: calculate DP link symbol clk and stream clk m/n.
2548c2ecf20Sopenharmony_ci		 */
2558c2ecf20Sopenharmony_ci		vgpu_vreg_t(vgpu, PIPE_DATA_M1(TRANSCODER_A)) = 63 << TU_SIZE_SHIFT;
2568c2ecf20Sopenharmony_ci		vgpu_vreg_t(vgpu, PIPE_DATA_M1(TRANSCODER_A)) |= 0x5b425e;
2578c2ecf20Sopenharmony_ci		vgpu_vreg_t(vgpu, PIPE_DATA_N1(TRANSCODER_A)) = 0x800000;
2588c2ecf20Sopenharmony_ci		vgpu_vreg_t(vgpu, PIPE_LINK_M1(TRANSCODER_A)) = 0x3cd6e;
2598c2ecf20Sopenharmony_ci		vgpu_vreg_t(vgpu, PIPE_LINK_N1(TRANSCODER_A)) = 0x80000;
2608c2ecf20Sopenharmony_ci
2618c2ecf20Sopenharmony_ci		/* Enable per-DDI/PORT vreg */
2628c2ecf20Sopenharmony_ci		if (intel_vgpu_has_monitor_on_port(vgpu, PORT_A)) {
2638c2ecf20Sopenharmony_ci			vgpu_vreg_t(vgpu, BXT_P_CR_GT_DISP_PWRON) |= BIT(1);
2648c2ecf20Sopenharmony_ci			vgpu_vreg_t(vgpu, BXT_PORT_CL1CM_DW0(DPIO_PHY1)) |=
2658c2ecf20Sopenharmony_ci				PHY_POWER_GOOD;
2668c2ecf20Sopenharmony_ci			vgpu_vreg_t(vgpu, BXT_PHY_CTL_FAMILY(DPIO_PHY1)) |=
2678c2ecf20Sopenharmony_ci				BIT(30);
2688c2ecf20Sopenharmony_ci			vgpu_vreg_t(vgpu, BXT_PHY_CTL(PORT_A)) |=
2698c2ecf20Sopenharmony_ci				BXT_PHY_LANE_ENABLED;
2708c2ecf20Sopenharmony_ci			vgpu_vreg_t(vgpu, BXT_PHY_CTL(PORT_A)) &=
2718c2ecf20Sopenharmony_ci				~(BXT_PHY_CMNLANE_POWERDOWN_ACK |
2728c2ecf20Sopenharmony_ci				  BXT_PHY_LANE_POWERDOWN_ACK);
2738c2ecf20Sopenharmony_ci			vgpu_vreg_t(vgpu, BXT_PORT_PLL_ENABLE(PORT_A)) |=
2748c2ecf20Sopenharmony_ci				(PORT_PLL_POWER_STATE | PORT_PLL_POWER_ENABLE |
2758c2ecf20Sopenharmony_ci				 PORT_PLL_REF_SEL | PORT_PLL_LOCK |
2768c2ecf20Sopenharmony_ci				 PORT_PLL_ENABLE);
2778c2ecf20Sopenharmony_ci			vgpu_vreg_t(vgpu, DDI_BUF_CTL(PORT_A)) |=
2788c2ecf20Sopenharmony_ci				(DDI_BUF_CTL_ENABLE | DDI_INIT_DISPLAY_DETECTED);
2798c2ecf20Sopenharmony_ci			vgpu_vreg_t(vgpu, DDI_BUF_CTL(PORT_A)) &=
2808c2ecf20Sopenharmony_ci				~DDI_BUF_IS_IDLE;
2818c2ecf20Sopenharmony_ci			vgpu_vreg_t(vgpu, TRANS_DDI_FUNC_CTL(TRANSCODER_EDP)) |=
2828c2ecf20Sopenharmony_ci				(TRANS_DDI_BPC_8 | TRANS_DDI_MODE_SELECT_DP_SST |
2838c2ecf20Sopenharmony_ci				 TRANS_DDI_FUNC_ENABLE);
2848c2ecf20Sopenharmony_ci			vgpu_vreg_t(vgpu, PCH_PORT_HOTPLUG) |=
2858c2ecf20Sopenharmony_ci				PORTA_HOTPLUG_ENABLE;
2868c2ecf20Sopenharmony_ci			vgpu_vreg_t(vgpu, GEN8_DE_PORT_ISR) |=
2878c2ecf20Sopenharmony_ci				BXT_DE_PORT_HP_DDIA;
2888c2ecf20Sopenharmony_ci		}
2898c2ecf20Sopenharmony_ci
2908c2ecf20Sopenharmony_ci		if (intel_vgpu_has_monitor_on_port(vgpu, PORT_B)) {
2918c2ecf20Sopenharmony_ci			vgpu_vreg_t(vgpu, SFUSE_STRAP) |= SFUSE_STRAP_DDIB_DETECTED;
2928c2ecf20Sopenharmony_ci			vgpu_vreg_t(vgpu, BXT_P_CR_GT_DISP_PWRON) |= BIT(0);
2938c2ecf20Sopenharmony_ci			vgpu_vreg_t(vgpu, BXT_PORT_CL1CM_DW0(DPIO_PHY0)) |=
2948c2ecf20Sopenharmony_ci				PHY_POWER_GOOD;
2958c2ecf20Sopenharmony_ci			vgpu_vreg_t(vgpu, BXT_PHY_CTL_FAMILY(DPIO_PHY0)) |=
2968c2ecf20Sopenharmony_ci				BIT(30);
2978c2ecf20Sopenharmony_ci			vgpu_vreg_t(vgpu, BXT_PHY_CTL(PORT_B)) |=
2988c2ecf20Sopenharmony_ci				BXT_PHY_LANE_ENABLED;
2998c2ecf20Sopenharmony_ci			vgpu_vreg_t(vgpu, BXT_PHY_CTL(PORT_B)) &=
3008c2ecf20Sopenharmony_ci				~(BXT_PHY_CMNLANE_POWERDOWN_ACK |
3018c2ecf20Sopenharmony_ci				  BXT_PHY_LANE_POWERDOWN_ACK);
3028c2ecf20Sopenharmony_ci			vgpu_vreg_t(vgpu, BXT_PORT_PLL_ENABLE(PORT_B)) |=
3038c2ecf20Sopenharmony_ci				(PORT_PLL_POWER_STATE | PORT_PLL_POWER_ENABLE |
3048c2ecf20Sopenharmony_ci				 PORT_PLL_REF_SEL | PORT_PLL_LOCK |
3058c2ecf20Sopenharmony_ci				 PORT_PLL_ENABLE);
3068c2ecf20Sopenharmony_ci			vgpu_vreg_t(vgpu, DDI_BUF_CTL(PORT_B)) |=
3078c2ecf20Sopenharmony_ci				DDI_BUF_CTL_ENABLE;
3088c2ecf20Sopenharmony_ci			vgpu_vreg_t(vgpu, DDI_BUF_CTL(PORT_B)) &=
3098c2ecf20Sopenharmony_ci				~DDI_BUF_IS_IDLE;
3108c2ecf20Sopenharmony_ci			vgpu_vreg_t(vgpu, TRANS_DDI_FUNC_CTL(TRANSCODER_A)) |=
3118c2ecf20Sopenharmony_ci				(TRANS_DDI_BPC_8 | TRANS_DDI_MODE_SELECT_DP_SST |
3128c2ecf20Sopenharmony_ci				 (PORT_B << TRANS_DDI_PORT_SHIFT) |
3138c2ecf20Sopenharmony_ci				 TRANS_DDI_FUNC_ENABLE);
3148c2ecf20Sopenharmony_ci			vgpu_vreg_t(vgpu, PCH_PORT_HOTPLUG) |=
3158c2ecf20Sopenharmony_ci				PORTB_HOTPLUG_ENABLE;
3168c2ecf20Sopenharmony_ci			vgpu_vreg_t(vgpu, GEN8_DE_PORT_ISR) |=
3178c2ecf20Sopenharmony_ci				BXT_DE_PORT_HP_DDIB;
3188c2ecf20Sopenharmony_ci		}
3198c2ecf20Sopenharmony_ci
3208c2ecf20Sopenharmony_ci		if (intel_vgpu_has_monitor_on_port(vgpu, PORT_C)) {
3218c2ecf20Sopenharmony_ci			vgpu_vreg_t(vgpu, SFUSE_STRAP) |= SFUSE_STRAP_DDIC_DETECTED;
3228c2ecf20Sopenharmony_ci			vgpu_vreg_t(vgpu, BXT_P_CR_GT_DISP_PWRON) |= BIT(0);
3238c2ecf20Sopenharmony_ci			vgpu_vreg_t(vgpu, BXT_PORT_CL1CM_DW0(DPIO_PHY0)) |=
3248c2ecf20Sopenharmony_ci				PHY_POWER_GOOD;
3258c2ecf20Sopenharmony_ci			vgpu_vreg_t(vgpu, BXT_PHY_CTL_FAMILY(DPIO_PHY0)) |=
3268c2ecf20Sopenharmony_ci				BIT(30);
3278c2ecf20Sopenharmony_ci			vgpu_vreg_t(vgpu, BXT_PHY_CTL(PORT_C)) |=
3288c2ecf20Sopenharmony_ci				BXT_PHY_LANE_ENABLED;
3298c2ecf20Sopenharmony_ci			vgpu_vreg_t(vgpu, BXT_PHY_CTL(PORT_C)) &=
3308c2ecf20Sopenharmony_ci				~(BXT_PHY_CMNLANE_POWERDOWN_ACK |
3318c2ecf20Sopenharmony_ci				  BXT_PHY_LANE_POWERDOWN_ACK);
3328c2ecf20Sopenharmony_ci			vgpu_vreg_t(vgpu, BXT_PORT_PLL_ENABLE(PORT_C)) |=
3338c2ecf20Sopenharmony_ci				(PORT_PLL_POWER_STATE | PORT_PLL_POWER_ENABLE |
3348c2ecf20Sopenharmony_ci				 PORT_PLL_REF_SEL | PORT_PLL_LOCK |
3358c2ecf20Sopenharmony_ci				 PORT_PLL_ENABLE);
3368c2ecf20Sopenharmony_ci			vgpu_vreg_t(vgpu, DDI_BUF_CTL(PORT_C)) |=
3378c2ecf20Sopenharmony_ci				DDI_BUF_CTL_ENABLE;
3388c2ecf20Sopenharmony_ci			vgpu_vreg_t(vgpu, DDI_BUF_CTL(PORT_C)) &=
3398c2ecf20Sopenharmony_ci				~DDI_BUF_IS_IDLE;
3408c2ecf20Sopenharmony_ci			vgpu_vreg_t(vgpu, TRANS_DDI_FUNC_CTL(TRANSCODER_A)) |=
3418c2ecf20Sopenharmony_ci				(TRANS_DDI_BPC_8 | TRANS_DDI_MODE_SELECT_DP_SST |
3428c2ecf20Sopenharmony_ci				 (PORT_B << TRANS_DDI_PORT_SHIFT) |
3438c2ecf20Sopenharmony_ci				 TRANS_DDI_FUNC_ENABLE);
3448c2ecf20Sopenharmony_ci			vgpu_vreg_t(vgpu, PCH_PORT_HOTPLUG) |=
3458c2ecf20Sopenharmony_ci				PORTC_HOTPLUG_ENABLE;
3468c2ecf20Sopenharmony_ci			vgpu_vreg_t(vgpu, GEN8_DE_PORT_ISR) |=
3478c2ecf20Sopenharmony_ci				BXT_DE_PORT_HP_DDIC;
3488c2ecf20Sopenharmony_ci		}
3498c2ecf20Sopenharmony_ci
3508c2ecf20Sopenharmony_ci		return;
3518c2ecf20Sopenharmony_ci	}
3528c2ecf20Sopenharmony_ci
3538c2ecf20Sopenharmony_ci	vgpu_vreg_t(vgpu, SDEISR) &= ~(SDE_PORTB_HOTPLUG_CPT |
3548c2ecf20Sopenharmony_ci			SDE_PORTC_HOTPLUG_CPT |
3558c2ecf20Sopenharmony_ci			SDE_PORTD_HOTPLUG_CPT);
3568c2ecf20Sopenharmony_ci
3578c2ecf20Sopenharmony_ci	if (IS_SKYLAKE(dev_priv) ||
3588c2ecf20Sopenharmony_ci	    IS_KABYLAKE(dev_priv) ||
3598c2ecf20Sopenharmony_ci	    IS_COFFEELAKE(dev_priv) ||
3608c2ecf20Sopenharmony_ci	    IS_COMETLAKE(dev_priv)) {
3618c2ecf20Sopenharmony_ci		vgpu_vreg_t(vgpu, SDEISR) &= ~(SDE_PORTA_HOTPLUG_SPT |
3628c2ecf20Sopenharmony_ci				SDE_PORTE_HOTPLUG_SPT);
3638c2ecf20Sopenharmony_ci		vgpu_vreg_t(vgpu, SKL_FUSE_STATUS) |=
3648c2ecf20Sopenharmony_ci				SKL_FUSE_DOWNLOAD_STATUS |
3658c2ecf20Sopenharmony_ci				SKL_FUSE_PG_DIST_STATUS(SKL_PG0) |
3668c2ecf20Sopenharmony_ci				SKL_FUSE_PG_DIST_STATUS(SKL_PG1) |
3678c2ecf20Sopenharmony_ci				SKL_FUSE_PG_DIST_STATUS(SKL_PG2);
3688c2ecf20Sopenharmony_ci		/*
3698c2ecf20Sopenharmony_ci		 * Only 1 PIPE enabled in current vGPU display and PIPE_A is
3708c2ecf20Sopenharmony_ci		 *  tied to TRANSCODER_A in HW, so it's safe to assume PIPE_A,
3718c2ecf20Sopenharmony_ci		 *   TRANSCODER_A can be enabled. PORT_x depends on the input of
3728c2ecf20Sopenharmony_ci		 *   setup_virtual_dp_monitor, we can bind DPLL0 to any PORT_x
3738c2ecf20Sopenharmony_ci		 *   so we fixed to DPLL0 here.
3748c2ecf20Sopenharmony_ci		 * Setup DPLL0: DP link clk 1620 MHz, non SSC, DP Mode
3758c2ecf20Sopenharmony_ci		 */
3768c2ecf20Sopenharmony_ci		vgpu_vreg_t(vgpu, DPLL_CTRL1) =
3778c2ecf20Sopenharmony_ci			DPLL_CTRL1_OVERRIDE(DPLL_ID_SKL_DPLL0);
3788c2ecf20Sopenharmony_ci		vgpu_vreg_t(vgpu, DPLL_CTRL1) |=
3798c2ecf20Sopenharmony_ci			DPLL_CTRL1_LINK_RATE(DPLL_CTRL1_LINK_RATE_1620, DPLL_ID_SKL_DPLL0);
3808c2ecf20Sopenharmony_ci		vgpu_vreg_t(vgpu, LCPLL1_CTL) =
3818c2ecf20Sopenharmony_ci			LCPLL_PLL_ENABLE | LCPLL_PLL_LOCK;
3828c2ecf20Sopenharmony_ci		vgpu_vreg_t(vgpu, DPLL_STATUS) = DPLL_LOCK(DPLL_ID_SKL_DPLL0);
3838c2ecf20Sopenharmony_ci		/*
3848c2ecf20Sopenharmony_ci		 * Golden M/N are calculated based on:
3858c2ecf20Sopenharmony_ci		 *   24 bpp, 4 lanes, 154000 pixel clk (from virtual EDID),
3868c2ecf20Sopenharmony_ci		 *   DP link clk 1620 MHz and non-constant_n.
3878c2ecf20Sopenharmony_ci		 * TODO: calculate DP link symbol clk and stream clk m/n.
3888c2ecf20Sopenharmony_ci		 */
3898c2ecf20Sopenharmony_ci		vgpu_vreg_t(vgpu, PIPE_DATA_M1(TRANSCODER_A)) = 63 << TU_SIZE_SHIFT;
3908c2ecf20Sopenharmony_ci		vgpu_vreg_t(vgpu, PIPE_DATA_M1(TRANSCODER_A)) |= 0x5b425e;
3918c2ecf20Sopenharmony_ci		vgpu_vreg_t(vgpu, PIPE_DATA_N1(TRANSCODER_A)) = 0x800000;
3928c2ecf20Sopenharmony_ci		vgpu_vreg_t(vgpu, PIPE_LINK_M1(TRANSCODER_A)) = 0x3cd6e;
3938c2ecf20Sopenharmony_ci		vgpu_vreg_t(vgpu, PIPE_LINK_N1(TRANSCODER_A)) = 0x80000;
3948c2ecf20Sopenharmony_ci	}
3958c2ecf20Sopenharmony_ci
3968c2ecf20Sopenharmony_ci	if (intel_vgpu_has_monitor_on_port(vgpu, PORT_B)) {
3978c2ecf20Sopenharmony_ci		vgpu_vreg_t(vgpu, DPLL_CTRL2) &=
3988c2ecf20Sopenharmony_ci			~DPLL_CTRL2_DDI_CLK_OFF(PORT_B);
3998c2ecf20Sopenharmony_ci		vgpu_vreg_t(vgpu, DPLL_CTRL2) |=
4008c2ecf20Sopenharmony_ci			DPLL_CTRL2_DDI_CLK_SEL(DPLL_ID_SKL_DPLL0, PORT_B);
4018c2ecf20Sopenharmony_ci		vgpu_vreg_t(vgpu, DPLL_CTRL2) |=
4028c2ecf20Sopenharmony_ci			DPLL_CTRL2_DDI_SEL_OVERRIDE(PORT_B);
4038c2ecf20Sopenharmony_ci		vgpu_vreg_t(vgpu, SFUSE_STRAP) |= SFUSE_STRAP_DDIB_DETECTED;
4048c2ecf20Sopenharmony_ci		vgpu_vreg_t(vgpu, TRANS_DDI_FUNC_CTL(TRANSCODER_A)) &=
4058c2ecf20Sopenharmony_ci			~(TRANS_DDI_BPC_MASK | TRANS_DDI_MODE_SELECT_MASK |
4068c2ecf20Sopenharmony_ci			TRANS_DDI_PORT_MASK);
4078c2ecf20Sopenharmony_ci		vgpu_vreg_t(vgpu, TRANS_DDI_FUNC_CTL(TRANSCODER_A)) |=
4088c2ecf20Sopenharmony_ci			(TRANS_DDI_BPC_8 | TRANS_DDI_MODE_SELECT_DP_SST |
4098c2ecf20Sopenharmony_ci			(PORT_B << TRANS_DDI_PORT_SHIFT) |
4108c2ecf20Sopenharmony_ci			TRANS_DDI_FUNC_ENABLE);
4118c2ecf20Sopenharmony_ci		if (IS_BROADWELL(dev_priv)) {
4128c2ecf20Sopenharmony_ci			vgpu_vreg_t(vgpu, PORT_CLK_SEL(PORT_B)) &=
4138c2ecf20Sopenharmony_ci				~PORT_CLK_SEL_MASK;
4148c2ecf20Sopenharmony_ci			vgpu_vreg_t(vgpu, PORT_CLK_SEL(PORT_B)) |=
4158c2ecf20Sopenharmony_ci				PORT_CLK_SEL_LCPLL_810;
4168c2ecf20Sopenharmony_ci		}
4178c2ecf20Sopenharmony_ci		vgpu_vreg_t(vgpu, DDI_BUF_CTL(PORT_B)) |= DDI_BUF_CTL_ENABLE;
4188c2ecf20Sopenharmony_ci		vgpu_vreg_t(vgpu, DDI_BUF_CTL(PORT_B)) &= ~DDI_BUF_IS_IDLE;
4198c2ecf20Sopenharmony_ci		vgpu_vreg_t(vgpu, SDEISR) |= SDE_PORTB_HOTPLUG_CPT;
4208c2ecf20Sopenharmony_ci	}
4218c2ecf20Sopenharmony_ci
4228c2ecf20Sopenharmony_ci	if (intel_vgpu_has_monitor_on_port(vgpu, PORT_C)) {
4238c2ecf20Sopenharmony_ci		vgpu_vreg_t(vgpu, DPLL_CTRL2) &=
4248c2ecf20Sopenharmony_ci			~DPLL_CTRL2_DDI_CLK_OFF(PORT_C);
4258c2ecf20Sopenharmony_ci		vgpu_vreg_t(vgpu, DPLL_CTRL2) |=
4268c2ecf20Sopenharmony_ci			DPLL_CTRL2_DDI_CLK_SEL(DPLL_ID_SKL_DPLL0, PORT_C);
4278c2ecf20Sopenharmony_ci		vgpu_vreg_t(vgpu, DPLL_CTRL2) |=
4288c2ecf20Sopenharmony_ci			DPLL_CTRL2_DDI_SEL_OVERRIDE(PORT_C);
4298c2ecf20Sopenharmony_ci		vgpu_vreg_t(vgpu, SDEISR) |= SDE_PORTC_HOTPLUG_CPT;
4308c2ecf20Sopenharmony_ci		vgpu_vreg_t(vgpu, TRANS_DDI_FUNC_CTL(TRANSCODER_A)) &=
4318c2ecf20Sopenharmony_ci			~(TRANS_DDI_BPC_MASK | TRANS_DDI_MODE_SELECT_MASK |
4328c2ecf20Sopenharmony_ci			TRANS_DDI_PORT_MASK);
4338c2ecf20Sopenharmony_ci		vgpu_vreg_t(vgpu, TRANS_DDI_FUNC_CTL(TRANSCODER_A)) |=
4348c2ecf20Sopenharmony_ci			(TRANS_DDI_BPC_8 | TRANS_DDI_MODE_SELECT_DP_SST |
4358c2ecf20Sopenharmony_ci			(PORT_C << TRANS_DDI_PORT_SHIFT) |
4368c2ecf20Sopenharmony_ci			TRANS_DDI_FUNC_ENABLE);
4378c2ecf20Sopenharmony_ci		if (IS_BROADWELL(dev_priv)) {
4388c2ecf20Sopenharmony_ci			vgpu_vreg_t(vgpu, PORT_CLK_SEL(PORT_C)) &=
4398c2ecf20Sopenharmony_ci				~PORT_CLK_SEL_MASK;
4408c2ecf20Sopenharmony_ci			vgpu_vreg_t(vgpu, PORT_CLK_SEL(PORT_C)) |=
4418c2ecf20Sopenharmony_ci				PORT_CLK_SEL_LCPLL_810;
4428c2ecf20Sopenharmony_ci		}
4438c2ecf20Sopenharmony_ci		vgpu_vreg_t(vgpu, DDI_BUF_CTL(PORT_C)) |= DDI_BUF_CTL_ENABLE;
4448c2ecf20Sopenharmony_ci		vgpu_vreg_t(vgpu, DDI_BUF_CTL(PORT_C)) &= ~DDI_BUF_IS_IDLE;
4458c2ecf20Sopenharmony_ci		vgpu_vreg_t(vgpu, SFUSE_STRAP) |= SFUSE_STRAP_DDIC_DETECTED;
4468c2ecf20Sopenharmony_ci	}
4478c2ecf20Sopenharmony_ci
4488c2ecf20Sopenharmony_ci	if (intel_vgpu_has_monitor_on_port(vgpu, PORT_D)) {
4498c2ecf20Sopenharmony_ci		vgpu_vreg_t(vgpu, DPLL_CTRL2) &=
4508c2ecf20Sopenharmony_ci			~DPLL_CTRL2_DDI_CLK_OFF(PORT_D);
4518c2ecf20Sopenharmony_ci		vgpu_vreg_t(vgpu, DPLL_CTRL2) |=
4528c2ecf20Sopenharmony_ci			DPLL_CTRL2_DDI_CLK_SEL(DPLL_ID_SKL_DPLL0, PORT_D);
4538c2ecf20Sopenharmony_ci		vgpu_vreg_t(vgpu, DPLL_CTRL2) |=
4548c2ecf20Sopenharmony_ci			DPLL_CTRL2_DDI_SEL_OVERRIDE(PORT_D);
4558c2ecf20Sopenharmony_ci		vgpu_vreg_t(vgpu, SDEISR) |= SDE_PORTD_HOTPLUG_CPT;
4568c2ecf20Sopenharmony_ci		vgpu_vreg_t(vgpu, TRANS_DDI_FUNC_CTL(TRANSCODER_A)) &=
4578c2ecf20Sopenharmony_ci			~(TRANS_DDI_BPC_MASK | TRANS_DDI_MODE_SELECT_MASK |
4588c2ecf20Sopenharmony_ci			TRANS_DDI_PORT_MASK);
4598c2ecf20Sopenharmony_ci		vgpu_vreg_t(vgpu, TRANS_DDI_FUNC_CTL(TRANSCODER_A)) |=
4608c2ecf20Sopenharmony_ci			(TRANS_DDI_BPC_8 | TRANS_DDI_MODE_SELECT_DP_SST |
4618c2ecf20Sopenharmony_ci			(PORT_D << TRANS_DDI_PORT_SHIFT) |
4628c2ecf20Sopenharmony_ci			TRANS_DDI_FUNC_ENABLE);
4638c2ecf20Sopenharmony_ci		if (IS_BROADWELL(dev_priv)) {
4648c2ecf20Sopenharmony_ci			vgpu_vreg_t(vgpu, PORT_CLK_SEL(PORT_D)) &=
4658c2ecf20Sopenharmony_ci				~PORT_CLK_SEL_MASK;
4668c2ecf20Sopenharmony_ci			vgpu_vreg_t(vgpu, PORT_CLK_SEL(PORT_D)) |=
4678c2ecf20Sopenharmony_ci				PORT_CLK_SEL_LCPLL_810;
4688c2ecf20Sopenharmony_ci		}
4698c2ecf20Sopenharmony_ci		vgpu_vreg_t(vgpu, DDI_BUF_CTL(PORT_D)) |= DDI_BUF_CTL_ENABLE;
4708c2ecf20Sopenharmony_ci		vgpu_vreg_t(vgpu, DDI_BUF_CTL(PORT_D)) &= ~DDI_BUF_IS_IDLE;
4718c2ecf20Sopenharmony_ci		vgpu_vreg_t(vgpu, SFUSE_STRAP) |= SFUSE_STRAP_DDID_DETECTED;
4728c2ecf20Sopenharmony_ci	}
4738c2ecf20Sopenharmony_ci
4748c2ecf20Sopenharmony_ci	if ((IS_SKYLAKE(dev_priv) ||
4758c2ecf20Sopenharmony_ci	     IS_KABYLAKE(dev_priv) ||
4768c2ecf20Sopenharmony_ci	     IS_COFFEELAKE(dev_priv) ||
4778c2ecf20Sopenharmony_ci	     IS_COMETLAKE(dev_priv)) &&
4788c2ecf20Sopenharmony_ci			intel_vgpu_has_monitor_on_port(vgpu, PORT_E)) {
4798c2ecf20Sopenharmony_ci		vgpu_vreg_t(vgpu, SDEISR) |= SDE_PORTE_HOTPLUG_SPT;
4808c2ecf20Sopenharmony_ci	}
4818c2ecf20Sopenharmony_ci
4828c2ecf20Sopenharmony_ci	if (intel_vgpu_has_monitor_on_port(vgpu, PORT_A)) {
4838c2ecf20Sopenharmony_ci		if (IS_BROADWELL(dev_priv))
4848c2ecf20Sopenharmony_ci			vgpu_vreg_t(vgpu, GEN8_DE_PORT_ISR) |=
4858c2ecf20Sopenharmony_ci				GEN8_PORT_DP_A_HOTPLUG;
4868c2ecf20Sopenharmony_ci		else
4878c2ecf20Sopenharmony_ci			vgpu_vreg_t(vgpu, SDEISR) |= SDE_PORTA_HOTPLUG_SPT;
4888c2ecf20Sopenharmony_ci
4898c2ecf20Sopenharmony_ci		vgpu_vreg_t(vgpu, DDI_BUF_CTL(PORT_A)) |= DDI_INIT_DISPLAY_DETECTED;
4908c2ecf20Sopenharmony_ci	}
4918c2ecf20Sopenharmony_ci
4928c2ecf20Sopenharmony_ci	/* Clear host CRT status, so guest couldn't detect this host CRT. */
4938c2ecf20Sopenharmony_ci	if (IS_BROADWELL(dev_priv))
4948c2ecf20Sopenharmony_ci		vgpu_vreg_t(vgpu, PCH_ADPA) &= ~ADPA_CRT_HOTPLUG_MONITOR_MASK;
4958c2ecf20Sopenharmony_ci
4968c2ecf20Sopenharmony_ci	/* Disable Primary/Sprite/Cursor plane */
4978c2ecf20Sopenharmony_ci	for_each_pipe(dev_priv, pipe) {
4988c2ecf20Sopenharmony_ci		vgpu_vreg_t(vgpu, DSPCNTR(pipe)) &= ~DISPLAY_PLANE_ENABLE;
4998c2ecf20Sopenharmony_ci		vgpu_vreg_t(vgpu, SPRCTL(pipe)) &= ~SPRITE_ENABLE;
5008c2ecf20Sopenharmony_ci		vgpu_vreg_t(vgpu, CURCNTR(pipe)) &= ~MCURSOR_MODE;
5018c2ecf20Sopenharmony_ci		vgpu_vreg_t(vgpu, CURCNTR(pipe)) |= MCURSOR_MODE_DISABLE;
5028c2ecf20Sopenharmony_ci	}
5038c2ecf20Sopenharmony_ci
5048c2ecf20Sopenharmony_ci	vgpu_vreg_t(vgpu, PIPECONF(PIPE_A)) |= PIPECONF_ENABLE;
5058c2ecf20Sopenharmony_ci}
5068c2ecf20Sopenharmony_ci
5078c2ecf20Sopenharmony_cistatic void clean_virtual_dp_monitor(struct intel_vgpu *vgpu, int port_num)
5088c2ecf20Sopenharmony_ci{
5098c2ecf20Sopenharmony_ci	struct intel_vgpu_port *port = intel_vgpu_port(vgpu, port_num);
5108c2ecf20Sopenharmony_ci
5118c2ecf20Sopenharmony_ci	kfree(port->edid);
5128c2ecf20Sopenharmony_ci	port->edid = NULL;
5138c2ecf20Sopenharmony_ci
5148c2ecf20Sopenharmony_ci	kfree(port->dpcd);
5158c2ecf20Sopenharmony_ci	port->dpcd = NULL;
5168c2ecf20Sopenharmony_ci}
5178c2ecf20Sopenharmony_ci
5188c2ecf20Sopenharmony_cistatic int setup_virtual_dp_monitor(struct intel_vgpu *vgpu, int port_num,
5198c2ecf20Sopenharmony_ci				    int type, unsigned int resolution)
5208c2ecf20Sopenharmony_ci{
5218c2ecf20Sopenharmony_ci	struct drm_i915_private *i915 = vgpu->gvt->gt->i915;
5228c2ecf20Sopenharmony_ci	struct intel_vgpu_port *port = intel_vgpu_port(vgpu, port_num);
5238c2ecf20Sopenharmony_ci
5248c2ecf20Sopenharmony_ci	if (drm_WARN_ON(&i915->drm, resolution >= GVT_EDID_NUM))
5258c2ecf20Sopenharmony_ci		return -EINVAL;
5268c2ecf20Sopenharmony_ci
5278c2ecf20Sopenharmony_ci	port->edid = kzalloc(sizeof(*(port->edid)), GFP_KERNEL);
5288c2ecf20Sopenharmony_ci	if (!port->edid)
5298c2ecf20Sopenharmony_ci		return -ENOMEM;
5308c2ecf20Sopenharmony_ci
5318c2ecf20Sopenharmony_ci	port->dpcd = kzalloc(sizeof(*(port->dpcd)), GFP_KERNEL);
5328c2ecf20Sopenharmony_ci	if (!port->dpcd) {
5338c2ecf20Sopenharmony_ci		kfree(port->edid);
5348c2ecf20Sopenharmony_ci		return -ENOMEM;
5358c2ecf20Sopenharmony_ci	}
5368c2ecf20Sopenharmony_ci
5378c2ecf20Sopenharmony_ci	memcpy(port->edid->edid_block, virtual_dp_monitor_edid[resolution],
5388c2ecf20Sopenharmony_ci			EDID_SIZE);
5398c2ecf20Sopenharmony_ci	port->edid->data_valid = true;
5408c2ecf20Sopenharmony_ci
5418c2ecf20Sopenharmony_ci	memcpy(port->dpcd->data, dpcd_fix_data, DPCD_HEADER_SIZE);
5428c2ecf20Sopenharmony_ci	port->dpcd->data_valid = true;
5438c2ecf20Sopenharmony_ci	port->dpcd->data[DPCD_SINK_COUNT] = 0x1;
5448c2ecf20Sopenharmony_ci	port->type = type;
5458c2ecf20Sopenharmony_ci	port->id = resolution;
5468c2ecf20Sopenharmony_ci
5478c2ecf20Sopenharmony_ci	emulate_monitor_status_change(vgpu);
5488c2ecf20Sopenharmony_ci
5498c2ecf20Sopenharmony_ci	return 0;
5508c2ecf20Sopenharmony_ci}
5518c2ecf20Sopenharmony_ci
5528c2ecf20Sopenharmony_ci/**
5538c2ecf20Sopenharmony_ci * intel_gvt_check_vblank_emulation - check if vblank emulation timer should
5548c2ecf20Sopenharmony_ci * be turned on/off when a virtual pipe is enabled/disabled.
5558c2ecf20Sopenharmony_ci * @gvt: a GVT device
5568c2ecf20Sopenharmony_ci *
5578c2ecf20Sopenharmony_ci * This function is used to turn on/off vblank timer according to currently
5588c2ecf20Sopenharmony_ci * enabled/disabled virtual pipes.
5598c2ecf20Sopenharmony_ci *
5608c2ecf20Sopenharmony_ci */
5618c2ecf20Sopenharmony_civoid intel_gvt_check_vblank_emulation(struct intel_gvt *gvt)
5628c2ecf20Sopenharmony_ci{
5638c2ecf20Sopenharmony_ci	struct intel_gvt_irq *irq = &gvt->irq;
5648c2ecf20Sopenharmony_ci	struct intel_vgpu *vgpu;
5658c2ecf20Sopenharmony_ci	int pipe, id;
5668c2ecf20Sopenharmony_ci	int found = false;
5678c2ecf20Sopenharmony_ci
5688c2ecf20Sopenharmony_ci	mutex_lock(&gvt->lock);
5698c2ecf20Sopenharmony_ci	for_each_active_vgpu(gvt, vgpu, id) {
5708c2ecf20Sopenharmony_ci		for (pipe = 0; pipe < I915_MAX_PIPES; pipe++) {
5718c2ecf20Sopenharmony_ci			if (pipe_is_enabled(vgpu, pipe)) {
5728c2ecf20Sopenharmony_ci				found = true;
5738c2ecf20Sopenharmony_ci				break;
5748c2ecf20Sopenharmony_ci			}
5758c2ecf20Sopenharmony_ci		}
5768c2ecf20Sopenharmony_ci		if (found)
5778c2ecf20Sopenharmony_ci			break;
5788c2ecf20Sopenharmony_ci	}
5798c2ecf20Sopenharmony_ci
5808c2ecf20Sopenharmony_ci	/* all the pipes are disabled */
5818c2ecf20Sopenharmony_ci	if (!found)
5828c2ecf20Sopenharmony_ci		hrtimer_cancel(&irq->vblank_timer.timer);
5838c2ecf20Sopenharmony_ci	else
5848c2ecf20Sopenharmony_ci		hrtimer_start(&irq->vblank_timer.timer,
5858c2ecf20Sopenharmony_ci			ktime_add_ns(ktime_get(), irq->vblank_timer.period),
5868c2ecf20Sopenharmony_ci			HRTIMER_MODE_ABS);
5878c2ecf20Sopenharmony_ci	mutex_unlock(&gvt->lock);
5888c2ecf20Sopenharmony_ci}
5898c2ecf20Sopenharmony_ci
5908c2ecf20Sopenharmony_cistatic void emulate_vblank_on_pipe(struct intel_vgpu *vgpu, int pipe)
5918c2ecf20Sopenharmony_ci{
5928c2ecf20Sopenharmony_ci	struct drm_i915_private *dev_priv = vgpu->gvt->gt->i915;
5938c2ecf20Sopenharmony_ci	struct intel_vgpu_irq *irq = &vgpu->irq;
5948c2ecf20Sopenharmony_ci	int vblank_event[] = {
5958c2ecf20Sopenharmony_ci		[PIPE_A] = PIPE_A_VBLANK,
5968c2ecf20Sopenharmony_ci		[PIPE_B] = PIPE_B_VBLANK,
5978c2ecf20Sopenharmony_ci		[PIPE_C] = PIPE_C_VBLANK,
5988c2ecf20Sopenharmony_ci	};
5998c2ecf20Sopenharmony_ci	int event;
6008c2ecf20Sopenharmony_ci
6018c2ecf20Sopenharmony_ci	if (pipe < PIPE_A || pipe > PIPE_C)
6028c2ecf20Sopenharmony_ci		return;
6038c2ecf20Sopenharmony_ci
6048c2ecf20Sopenharmony_ci	for_each_set_bit(event, irq->flip_done_event[pipe],
6058c2ecf20Sopenharmony_ci			INTEL_GVT_EVENT_MAX) {
6068c2ecf20Sopenharmony_ci		clear_bit(event, irq->flip_done_event[pipe]);
6078c2ecf20Sopenharmony_ci		if (!pipe_is_enabled(vgpu, pipe))
6088c2ecf20Sopenharmony_ci			continue;
6098c2ecf20Sopenharmony_ci
6108c2ecf20Sopenharmony_ci		intel_vgpu_trigger_virtual_event(vgpu, event);
6118c2ecf20Sopenharmony_ci	}
6128c2ecf20Sopenharmony_ci
6138c2ecf20Sopenharmony_ci	if (pipe_is_enabled(vgpu, pipe)) {
6148c2ecf20Sopenharmony_ci		vgpu_vreg_t(vgpu, PIPE_FRMCOUNT_G4X(pipe))++;
6158c2ecf20Sopenharmony_ci		intel_vgpu_trigger_virtual_event(vgpu, vblank_event[pipe]);
6168c2ecf20Sopenharmony_ci	}
6178c2ecf20Sopenharmony_ci}
6188c2ecf20Sopenharmony_ci
6198c2ecf20Sopenharmony_cistatic void emulate_vblank(struct intel_vgpu *vgpu)
6208c2ecf20Sopenharmony_ci{
6218c2ecf20Sopenharmony_ci	int pipe;
6228c2ecf20Sopenharmony_ci
6238c2ecf20Sopenharmony_ci	mutex_lock(&vgpu->vgpu_lock);
6248c2ecf20Sopenharmony_ci	for_each_pipe(vgpu->gvt->gt->i915, pipe)
6258c2ecf20Sopenharmony_ci		emulate_vblank_on_pipe(vgpu, pipe);
6268c2ecf20Sopenharmony_ci	mutex_unlock(&vgpu->vgpu_lock);
6278c2ecf20Sopenharmony_ci}
6288c2ecf20Sopenharmony_ci
6298c2ecf20Sopenharmony_ci/**
6308c2ecf20Sopenharmony_ci * intel_gvt_emulate_vblank - trigger vblank events for vGPUs on GVT device
6318c2ecf20Sopenharmony_ci * @gvt: a GVT device
6328c2ecf20Sopenharmony_ci *
6338c2ecf20Sopenharmony_ci * This function is used to trigger vblank interrupts for vGPUs on GVT device
6348c2ecf20Sopenharmony_ci *
6358c2ecf20Sopenharmony_ci */
6368c2ecf20Sopenharmony_civoid intel_gvt_emulate_vblank(struct intel_gvt *gvt)
6378c2ecf20Sopenharmony_ci{
6388c2ecf20Sopenharmony_ci	struct intel_vgpu *vgpu;
6398c2ecf20Sopenharmony_ci	int id;
6408c2ecf20Sopenharmony_ci
6418c2ecf20Sopenharmony_ci	mutex_lock(&gvt->lock);
6428c2ecf20Sopenharmony_ci	for_each_active_vgpu(gvt, vgpu, id)
6438c2ecf20Sopenharmony_ci		emulate_vblank(vgpu);
6448c2ecf20Sopenharmony_ci	mutex_unlock(&gvt->lock);
6458c2ecf20Sopenharmony_ci}
6468c2ecf20Sopenharmony_ci
6478c2ecf20Sopenharmony_ci/**
6488c2ecf20Sopenharmony_ci * intel_vgpu_emulate_hotplug - trigger hotplug event for vGPU
6498c2ecf20Sopenharmony_ci * @vgpu: a vGPU
6508c2ecf20Sopenharmony_ci * @connected: link state
6518c2ecf20Sopenharmony_ci *
6528c2ecf20Sopenharmony_ci * This function is used to trigger hotplug interrupt for vGPU
6538c2ecf20Sopenharmony_ci *
6548c2ecf20Sopenharmony_ci */
6558c2ecf20Sopenharmony_civoid intel_vgpu_emulate_hotplug(struct intel_vgpu *vgpu, bool connected)
6568c2ecf20Sopenharmony_ci{
6578c2ecf20Sopenharmony_ci	struct drm_i915_private *i915 = vgpu->gvt->gt->i915;
6588c2ecf20Sopenharmony_ci
6598c2ecf20Sopenharmony_ci	/* TODO: add more platforms support */
6608c2ecf20Sopenharmony_ci	if (IS_SKYLAKE(i915) ||
6618c2ecf20Sopenharmony_ci	    IS_KABYLAKE(i915) ||
6628c2ecf20Sopenharmony_ci	    IS_COFFEELAKE(i915) ||
6638c2ecf20Sopenharmony_ci	    IS_COMETLAKE(i915)) {
6648c2ecf20Sopenharmony_ci		if (connected) {
6658c2ecf20Sopenharmony_ci			vgpu_vreg_t(vgpu, SFUSE_STRAP) |=
6668c2ecf20Sopenharmony_ci				SFUSE_STRAP_DDID_DETECTED;
6678c2ecf20Sopenharmony_ci			vgpu_vreg_t(vgpu, SDEISR) |= SDE_PORTD_HOTPLUG_CPT;
6688c2ecf20Sopenharmony_ci		} else {
6698c2ecf20Sopenharmony_ci			vgpu_vreg_t(vgpu, SFUSE_STRAP) &=
6708c2ecf20Sopenharmony_ci				~SFUSE_STRAP_DDID_DETECTED;
6718c2ecf20Sopenharmony_ci			vgpu_vreg_t(vgpu, SDEISR) &= ~SDE_PORTD_HOTPLUG_CPT;
6728c2ecf20Sopenharmony_ci		}
6738c2ecf20Sopenharmony_ci		vgpu_vreg_t(vgpu, SDEIIR) |= SDE_PORTD_HOTPLUG_CPT;
6748c2ecf20Sopenharmony_ci		vgpu_vreg_t(vgpu, PCH_PORT_HOTPLUG) |=
6758c2ecf20Sopenharmony_ci				PORTD_HOTPLUG_STATUS_MASK;
6768c2ecf20Sopenharmony_ci		intel_vgpu_trigger_virtual_event(vgpu, DP_D_HOTPLUG);
6778c2ecf20Sopenharmony_ci	} else if (IS_BROXTON(i915)) {
6788c2ecf20Sopenharmony_ci		if (intel_vgpu_has_monitor_on_port(vgpu, PORT_A)) {
6798c2ecf20Sopenharmony_ci			if (connected) {
6808c2ecf20Sopenharmony_ci				vgpu_vreg_t(vgpu, GEN8_DE_PORT_ISR) |=
6818c2ecf20Sopenharmony_ci					BXT_DE_PORT_HP_DDIA;
6828c2ecf20Sopenharmony_ci			} else {
6838c2ecf20Sopenharmony_ci				vgpu_vreg_t(vgpu, GEN8_DE_PORT_ISR) &=
6848c2ecf20Sopenharmony_ci					~BXT_DE_PORT_HP_DDIA;
6858c2ecf20Sopenharmony_ci			}
6868c2ecf20Sopenharmony_ci			vgpu_vreg_t(vgpu, GEN8_DE_PORT_IIR) |=
6878c2ecf20Sopenharmony_ci				BXT_DE_PORT_HP_DDIA;
6888c2ecf20Sopenharmony_ci			vgpu_vreg_t(vgpu, PCH_PORT_HOTPLUG) &=
6898c2ecf20Sopenharmony_ci				~PORTA_HOTPLUG_STATUS_MASK;
6908c2ecf20Sopenharmony_ci			vgpu_vreg_t(vgpu, PCH_PORT_HOTPLUG) |=
6918c2ecf20Sopenharmony_ci				PORTA_HOTPLUG_LONG_DETECT;
6928c2ecf20Sopenharmony_ci			intel_vgpu_trigger_virtual_event(vgpu, DP_A_HOTPLUG);
6938c2ecf20Sopenharmony_ci		}
6948c2ecf20Sopenharmony_ci		if (intel_vgpu_has_monitor_on_port(vgpu, PORT_B)) {
6958c2ecf20Sopenharmony_ci			if (connected) {
6968c2ecf20Sopenharmony_ci				vgpu_vreg_t(vgpu, GEN8_DE_PORT_ISR) |=
6978c2ecf20Sopenharmony_ci					BXT_DE_PORT_HP_DDIB;
6988c2ecf20Sopenharmony_ci				vgpu_vreg_t(vgpu, SFUSE_STRAP) |=
6998c2ecf20Sopenharmony_ci					SFUSE_STRAP_DDIB_DETECTED;
7008c2ecf20Sopenharmony_ci			} else {
7018c2ecf20Sopenharmony_ci				vgpu_vreg_t(vgpu, GEN8_DE_PORT_ISR) &=
7028c2ecf20Sopenharmony_ci					~BXT_DE_PORT_HP_DDIB;
7038c2ecf20Sopenharmony_ci				vgpu_vreg_t(vgpu, SFUSE_STRAP) &=
7048c2ecf20Sopenharmony_ci					~SFUSE_STRAP_DDIB_DETECTED;
7058c2ecf20Sopenharmony_ci			}
7068c2ecf20Sopenharmony_ci			vgpu_vreg_t(vgpu, GEN8_DE_PORT_IIR) |=
7078c2ecf20Sopenharmony_ci				BXT_DE_PORT_HP_DDIB;
7088c2ecf20Sopenharmony_ci			vgpu_vreg_t(vgpu, PCH_PORT_HOTPLUG) &=
7098c2ecf20Sopenharmony_ci				~PORTB_HOTPLUG_STATUS_MASK;
7108c2ecf20Sopenharmony_ci			vgpu_vreg_t(vgpu, PCH_PORT_HOTPLUG) |=
7118c2ecf20Sopenharmony_ci				PORTB_HOTPLUG_LONG_DETECT;
7128c2ecf20Sopenharmony_ci			intel_vgpu_trigger_virtual_event(vgpu, DP_B_HOTPLUG);
7138c2ecf20Sopenharmony_ci		}
7148c2ecf20Sopenharmony_ci		if (intel_vgpu_has_monitor_on_port(vgpu, PORT_C)) {
7158c2ecf20Sopenharmony_ci			if (connected) {
7168c2ecf20Sopenharmony_ci				vgpu_vreg_t(vgpu, GEN8_DE_PORT_ISR) |=
7178c2ecf20Sopenharmony_ci					BXT_DE_PORT_HP_DDIC;
7188c2ecf20Sopenharmony_ci				vgpu_vreg_t(vgpu, SFUSE_STRAP) |=
7198c2ecf20Sopenharmony_ci					SFUSE_STRAP_DDIC_DETECTED;
7208c2ecf20Sopenharmony_ci			} else {
7218c2ecf20Sopenharmony_ci				vgpu_vreg_t(vgpu, GEN8_DE_PORT_ISR) &=
7228c2ecf20Sopenharmony_ci					~BXT_DE_PORT_HP_DDIC;
7238c2ecf20Sopenharmony_ci				vgpu_vreg_t(vgpu, SFUSE_STRAP) &=
7248c2ecf20Sopenharmony_ci					~SFUSE_STRAP_DDIC_DETECTED;
7258c2ecf20Sopenharmony_ci			}
7268c2ecf20Sopenharmony_ci			vgpu_vreg_t(vgpu, GEN8_DE_PORT_IIR) |=
7278c2ecf20Sopenharmony_ci				BXT_DE_PORT_HP_DDIC;
7288c2ecf20Sopenharmony_ci			vgpu_vreg_t(vgpu, PCH_PORT_HOTPLUG) &=
7298c2ecf20Sopenharmony_ci				~PORTC_HOTPLUG_STATUS_MASK;
7308c2ecf20Sopenharmony_ci			vgpu_vreg_t(vgpu, PCH_PORT_HOTPLUG) |=
7318c2ecf20Sopenharmony_ci				PORTC_HOTPLUG_LONG_DETECT;
7328c2ecf20Sopenharmony_ci			intel_vgpu_trigger_virtual_event(vgpu, DP_C_HOTPLUG);
7338c2ecf20Sopenharmony_ci		}
7348c2ecf20Sopenharmony_ci	}
7358c2ecf20Sopenharmony_ci}
7368c2ecf20Sopenharmony_ci
7378c2ecf20Sopenharmony_ci/**
7388c2ecf20Sopenharmony_ci * intel_vgpu_clean_display - clean vGPU virtual display emulation
7398c2ecf20Sopenharmony_ci * @vgpu: a vGPU
7408c2ecf20Sopenharmony_ci *
7418c2ecf20Sopenharmony_ci * This function is used to clean vGPU virtual display emulation stuffs
7428c2ecf20Sopenharmony_ci *
7438c2ecf20Sopenharmony_ci */
7448c2ecf20Sopenharmony_civoid intel_vgpu_clean_display(struct intel_vgpu *vgpu)
7458c2ecf20Sopenharmony_ci{
7468c2ecf20Sopenharmony_ci	struct drm_i915_private *dev_priv = vgpu->gvt->gt->i915;
7478c2ecf20Sopenharmony_ci
7488c2ecf20Sopenharmony_ci	if (IS_SKYLAKE(dev_priv) ||
7498c2ecf20Sopenharmony_ci	    IS_KABYLAKE(dev_priv) ||
7508c2ecf20Sopenharmony_ci	    IS_COFFEELAKE(dev_priv) ||
7518c2ecf20Sopenharmony_ci	    IS_COMETLAKE(dev_priv))
7528c2ecf20Sopenharmony_ci		clean_virtual_dp_monitor(vgpu, PORT_D);
7538c2ecf20Sopenharmony_ci	else
7548c2ecf20Sopenharmony_ci		clean_virtual_dp_monitor(vgpu, PORT_B);
7558c2ecf20Sopenharmony_ci}
7568c2ecf20Sopenharmony_ci
7578c2ecf20Sopenharmony_ci/**
7588c2ecf20Sopenharmony_ci * intel_vgpu_init_display- initialize vGPU virtual display emulation
7598c2ecf20Sopenharmony_ci * @vgpu: a vGPU
7608c2ecf20Sopenharmony_ci * @resolution: resolution index for intel_vgpu_edid
7618c2ecf20Sopenharmony_ci *
7628c2ecf20Sopenharmony_ci * This function is used to initialize vGPU virtual display emulation stuffs
7638c2ecf20Sopenharmony_ci *
7648c2ecf20Sopenharmony_ci * Returns:
7658c2ecf20Sopenharmony_ci * Zero on success, negative error code if failed.
7668c2ecf20Sopenharmony_ci *
7678c2ecf20Sopenharmony_ci */
7688c2ecf20Sopenharmony_ciint intel_vgpu_init_display(struct intel_vgpu *vgpu, u64 resolution)
7698c2ecf20Sopenharmony_ci{
7708c2ecf20Sopenharmony_ci	struct drm_i915_private *dev_priv = vgpu->gvt->gt->i915;
7718c2ecf20Sopenharmony_ci
7728c2ecf20Sopenharmony_ci	intel_vgpu_init_i2c_edid(vgpu);
7738c2ecf20Sopenharmony_ci
7748c2ecf20Sopenharmony_ci	if (IS_SKYLAKE(dev_priv) ||
7758c2ecf20Sopenharmony_ci	    IS_KABYLAKE(dev_priv) ||
7768c2ecf20Sopenharmony_ci	    IS_COFFEELAKE(dev_priv) ||
7778c2ecf20Sopenharmony_ci	    IS_COMETLAKE(dev_priv))
7788c2ecf20Sopenharmony_ci		return setup_virtual_dp_monitor(vgpu, PORT_D, GVT_DP_D,
7798c2ecf20Sopenharmony_ci						resolution);
7808c2ecf20Sopenharmony_ci	else
7818c2ecf20Sopenharmony_ci		return setup_virtual_dp_monitor(vgpu, PORT_B, GVT_DP_B,
7828c2ecf20Sopenharmony_ci						resolution);
7838c2ecf20Sopenharmony_ci}
7848c2ecf20Sopenharmony_ci
7858c2ecf20Sopenharmony_ci/**
7868c2ecf20Sopenharmony_ci * intel_vgpu_reset_display- reset vGPU virtual display emulation
7878c2ecf20Sopenharmony_ci * @vgpu: a vGPU
7888c2ecf20Sopenharmony_ci *
7898c2ecf20Sopenharmony_ci * This function is used to reset vGPU virtual display emulation stuffs
7908c2ecf20Sopenharmony_ci *
7918c2ecf20Sopenharmony_ci */
7928c2ecf20Sopenharmony_civoid intel_vgpu_reset_display(struct intel_vgpu *vgpu)
7938c2ecf20Sopenharmony_ci{
7948c2ecf20Sopenharmony_ci	emulate_monitor_status_change(vgpu);
7958c2ecf20Sopenharmony_ci}
796