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#ifndef _GVT_DISPLAY_H_ 368c2ecf20Sopenharmony_ci#define _GVT_DISPLAY_H_ 378c2ecf20Sopenharmony_ci 388c2ecf20Sopenharmony_ci#include <linux/types.h> 398c2ecf20Sopenharmony_ci 408c2ecf20Sopenharmony_cistruct intel_gvt; 418c2ecf20Sopenharmony_cistruct intel_vgpu; 428c2ecf20Sopenharmony_ci 438c2ecf20Sopenharmony_ci#define SBI_REG_MAX 20 448c2ecf20Sopenharmony_ci#define DPCD_SIZE 0x700 458c2ecf20Sopenharmony_ci 468c2ecf20Sopenharmony_ci#define intel_vgpu_port(vgpu, port) \ 478c2ecf20Sopenharmony_ci (&(vgpu->display.ports[port])) 488c2ecf20Sopenharmony_ci 498c2ecf20Sopenharmony_ci#define intel_vgpu_has_monitor_on_port(vgpu, port) \ 508c2ecf20Sopenharmony_ci (intel_vgpu_port(vgpu, port)->edid && \ 518c2ecf20Sopenharmony_ci intel_vgpu_port(vgpu, port)->edid->data_valid) 528c2ecf20Sopenharmony_ci 538c2ecf20Sopenharmony_ci#define intel_vgpu_port_is_dp(vgpu, port) \ 548c2ecf20Sopenharmony_ci ((intel_vgpu_port(vgpu, port)->type == GVT_DP_A) || \ 558c2ecf20Sopenharmony_ci (intel_vgpu_port(vgpu, port)->type == GVT_DP_B) || \ 568c2ecf20Sopenharmony_ci (intel_vgpu_port(vgpu, port)->type == GVT_DP_C) || \ 578c2ecf20Sopenharmony_ci (intel_vgpu_port(vgpu, port)->type == GVT_DP_D)) 588c2ecf20Sopenharmony_ci 598c2ecf20Sopenharmony_ci#define INTEL_GVT_MAX_UEVENT_VARS 3 608c2ecf20Sopenharmony_ci 618c2ecf20Sopenharmony_ci/* DPCD start */ 628c2ecf20Sopenharmony_ci#define DPCD_SIZE 0x700 638c2ecf20Sopenharmony_ci 648c2ecf20Sopenharmony_ci/* DPCD */ 658c2ecf20Sopenharmony_ci#define DP_SET_POWER 0x600 668c2ecf20Sopenharmony_ci#define DP_SET_POWER_D0 0x1 678c2ecf20Sopenharmony_ci#define AUX_NATIVE_WRITE 0x8 688c2ecf20Sopenharmony_ci#define AUX_NATIVE_READ 0x9 698c2ecf20Sopenharmony_ci 708c2ecf20Sopenharmony_ci#define AUX_NATIVE_REPLY_MASK (0x3 << 4) 718c2ecf20Sopenharmony_ci#define AUX_NATIVE_REPLY_ACK (0x0 << 4) 728c2ecf20Sopenharmony_ci#define AUX_NATIVE_REPLY_NAK (0x1 << 4) 738c2ecf20Sopenharmony_ci#define AUX_NATIVE_REPLY_DEFER (0x2 << 4) 748c2ecf20Sopenharmony_ci 758c2ecf20Sopenharmony_ci#define AUX_BURST_SIZE 20 768c2ecf20Sopenharmony_ci 778c2ecf20Sopenharmony_ci/* DPCD addresses */ 788c2ecf20Sopenharmony_ci#define DPCD_REV 0x000 798c2ecf20Sopenharmony_ci#define DPCD_MAX_LINK_RATE 0x001 808c2ecf20Sopenharmony_ci#define DPCD_MAX_LANE_COUNT 0x002 818c2ecf20Sopenharmony_ci 828c2ecf20Sopenharmony_ci#define DPCD_TRAINING_PATTERN_SET 0x102 838c2ecf20Sopenharmony_ci#define DPCD_SINK_COUNT 0x200 848c2ecf20Sopenharmony_ci#define DPCD_LANE0_1_STATUS 0x202 858c2ecf20Sopenharmony_ci#define DPCD_LANE2_3_STATUS 0x203 868c2ecf20Sopenharmony_ci#define DPCD_LANE_ALIGN_STATUS_UPDATED 0x204 878c2ecf20Sopenharmony_ci#define DPCD_SINK_STATUS 0x205 888c2ecf20Sopenharmony_ci 898c2ecf20Sopenharmony_ci/* link training */ 908c2ecf20Sopenharmony_ci#define DPCD_TRAINING_PATTERN_SET_MASK 0x03 918c2ecf20Sopenharmony_ci#define DPCD_LINK_TRAINING_DISABLED 0x00 928c2ecf20Sopenharmony_ci#define DPCD_TRAINING_PATTERN_1 0x01 938c2ecf20Sopenharmony_ci#define DPCD_TRAINING_PATTERN_2 0x02 948c2ecf20Sopenharmony_ci 958c2ecf20Sopenharmony_ci#define DPCD_CP_READY_MASK (1 << 6) 968c2ecf20Sopenharmony_ci 978c2ecf20Sopenharmony_ci/* lane status */ 988c2ecf20Sopenharmony_ci#define DPCD_LANES_CR_DONE 0x11 998c2ecf20Sopenharmony_ci#define DPCD_LANES_EQ_DONE 0x22 1008c2ecf20Sopenharmony_ci#define DPCD_SYMBOL_LOCKED 0x44 1018c2ecf20Sopenharmony_ci 1028c2ecf20Sopenharmony_ci#define DPCD_INTERLANE_ALIGN_DONE 0x01 1038c2ecf20Sopenharmony_ci 1048c2ecf20Sopenharmony_ci#define DPCD_SINK_IN_SYNC 0x03 1058c2ecf20Sopenharmony_ci/* DPCD end */ 1068c2ecf20Sopenharmony_ci 1078c2ecf20Sopenharmony_ci#define SBI_RESPONSE_MASK 0x3 1088c2ecf20Sopenharmony_ci#define SBI_RESPONSE_SHIFT 0x1 1098c2ecf20Sopenharmony_ci#define SBI_STAT_MASK 0x1 1108c2ecf20Sopenharmony_ci#define SBI_STAT_SHIFT 0x0 1118c2ecf20Sopenharmony_ci#define SBI_OPCODE_SHIFT 8 1128c2ecf20Sopenharmony_ci#define SBI_OPCODE_MASK (0xff << SBI_OPCODE_SHIFT) 1138c2ecf20Sopenharmony_ci#define SBI_CMD_IORD 2 1148c2ecf20Sopenharmony_ci#define SBI_CMD_IOWR 3 1158c2ecf20Sopenharmony_ci#define SBI_CMD_CRRD 6 1168c2ecf20Sopenharmony_ci#define SBI_CMD_CRWR 7 1178c2ecf20Sopenharmony_ci#define SBI_ADDR_OFFSET_SHIFT 16 1188c2ecf20Sopenharmony_ci#define SBI_ADDR_OFFSET_MASK (0xffff << SBI_ADDR_OFFSET_SHIFT) 1198c2ecf20Sopenharmony_ci 1208c2ecf20Sopenharmony_cistruct intel_vgpu_sbi_register { 1218c2ecf20Sopenharmony_ci unsigned int offset; 1228c2ecf20Sopenharmony_ci u32 value; 1238c2ecf20Sopenharmony_ci}; 1248c2ecf20Sopenharmony_ci 1258c2ecf20Sopenharmony_cistruct intel_vgpu_sbi { 1268c2ecf20Sopenharmony_ci int number; 1278c2ecf20Sopenharmony_ci struct intel_vgpu_sbi_register registers[SBI_REG_MAX]; 1288c2ecf20Sopenharmony_ci}; 1298c2ecf20Sopenharmony_ci 1308c2ecf20Sopenharmony_cienum intel_gvt_plane_type { 1318c2ecf20Sopenharmony_ci PRIMARY_PLANE = 0, 1328c2ecf20Sopenharmony_ci CURSOR_PLANE, 1338c2ecf20Sopenharmony_ci SPRITE_PLANE, 1348c2ecf20Sopenharmony_ci MAX_PLANE 1358c2ecf20Sopenharmony_ci}; 1368c2ecf20Sopenharmony_ci 1378c2ecf20Sopenharmony_cistruct intel_vgpu_dpcd_data { 1388c2ecf20Sopenharmony_ci bool data_valid; 1398c2ecf20Sopenharmony_ci u8 data[DPCD_SIZE]; 1408c2ecf20Sopenharmony_ci}; 1418c2ecf20Sopenharmony_ci 1428c2ecf20Sopenharmony_cienum intel_vgpu_port_type { 1438c2ecf20Sopenharmony_ci GVT_CRT = 0, 1448c2ecf20Sopenharmony_ci GVT_DP_A, 1458c2ecf20Sopenharmony_ci GVT_DP_B, 1468c2ecf20Sopenharmony_ci GVT_DP_C, 1478c2ecf20Sopenharmony_ci GVT_DP_D, 1488c2ecf20Sopenharmony_ci GVT_HDMI_B, 1498c2ecf20Sopenharmony_ci GVT_HDMI_C, 1508c2ecf20Sopenharmony_ci GVT_HDMI_D, 1518c2ecf20Sopenharmony_ci GVT_PORT_MAX 1528c2ecf20Sopenharmony_ci}; 1538c2ecf20Sopenharmony_ci 1548c2ecf20Sopenharmony_cienum intel_vgpu_edid { 1558c2ecf20Sopenharmony_ci GVT_EDID_1024_768, 1568c2ecf20Sopenharmony_ci GVT_EDID_1920_1200, 1578c2ecf20Sopenharmony_ci GVT_EDID_NUM, 1588c2ecf20Sopenharmony_ci}; 1598c2ecf20Sopenharmony_ci 1608c2ecf20Sopenharmony_cistruct intel_vgpu_port { 1618c2ecf20Sopenharmony_ci /* per display EDID information */ 1628c2ecf20Sopenharmony_ci struct intel_vgpu_edid_data *edid; 1638c2ecf20Sopenharmony_ci /* per display DPCD information */ 1648c2ecf20Sopenharmony_ci struct intel_vgpu_dpcd_data *dpcd; 1658c2ecf20Sopenharmony_ci int type; 1668c2ecf20Sopenharmony_ci enum intel_vgpu_edid id; 1678c2ecf20Sopenharmony_ci}; 1688c2ecf20Sopenharmony_ci 1698c2ecf20Sopenharmony_cistatic inline char *vgpu_edid_str(enum intel_vgpu_edid id) 1708c2ecf20Sopenharmony_ci{ 1718c2ecf20Sopenharmony_ci switch (id) { 1728c2ecf20Sopenharmony_ci case GVT_EDID_1024_768: 1738c2ecf20Sopenharmony_ci return "1024x768"; 1748c2ecf20Sopenharmony_ci case GVT_EDID_1920_1200: 1758c2ecf20Sopenharmony_ci return "1920x1200"; 1768c2ecf20Sopenharmony_ci default: 1778c2ecf20Sopenharmony_ci return ""; 1788c2ecf20Sopenharmony_ci } 1798c2ecf20Sopenharmony_ci} 1808c2ecf20Sopenharmony_ci 1818c2ecf20Sopenharmony_cistatic inline unsigned int vgpu_edid_xres(enum intel_vgpu_edid id) 1828c2ecf20Sopenharmony_ci{ 1838c2ecf20Sopenharmony_ci switch (id) { 1848c2ecf20Sopenharmony_ci case GVT_EDID_1024_768: 1858c2ecf20Sopenharmony_ci return 1024; 1868c2ecf20Sopenharmony_ci case GVT_EDID_1920_1200: 1878c2ecf20Sopenharmony_ci return 1920; 1888c2ecf20Sopenharmony_ci default: 1898c2ecf20Sopenharmony_ci return 0; 1908c2ecf20Sopenharmony_ci } 1918c2ecf20Sopenharmony_ci} 1928c2ecf20Sopenharmony_ci 1938c2ecf20Sopenharmony_cistatic inline unsigned int vgpu_edid_yres(enum intel_vgpu_edid id) 1948c2ecf20Sopenharmony_ci{ 1958c2ecf20Sopenharmony_ci switch (id) { 1968c2ecf20Sopenharmony_ci case GVT_EDID_1024_768: 1978c2ecf20Sopenharmony_ci return 768; 1988c2ecf20Sopenharmony_ci case GVT_EDID_1920_1200: 1998c2ecf20Sopenharmony_ci return 1200; 2008c2ecf20Sopenharmony_ci default: 2018c2ecf20Sopenharmony_ci return 0; 2028c2ecf20Sopenharmony_ci } 2038c2ecf20Sopenharmony_ci} 2048c2ecf20Sopenharmony_ci 2058c2ecf20Sopenharmony_civoid intel_gvt_emulate_vblank(struct intel_gvt *gvt); 2068c2ecf20Sopenharmony_civoid intel_gvt_check_vblank_emulation(struct intel_gvt *gvt); 2078c2ecf20Sopenharmony_ci 2088c2ecf20Sopenharmony_ciint intel_vgpu_init_display(struct intel_vgpu *vgpu, u64 resolution); 2098c2ecf20Sopenharmony_civoid intel_vgpu_reset_display(struct intel_vgpu *vgpu); 2108c2ecf20Sopenharmony_civoid intel_vgpu_clean_display(struct intel_vgpu *vgpu); 2118c2ecf20Sopenharmony_ci 2128c2ecf20Sopenharmony_ciint pipe_is_enabled(struct intel_vgpu *vgpu, int pipe); 2138c2ecf20Sopenharmony_ci 2148c2ecf20Sopenharmony_ci#endif 215