162306a36Sopenharmony_ci/* 262306a36Sopenharmony_ci * Copyright(c) 2011-2016 Intel Corporation. All rights reserved. 362306a36Sopenharmony_ci * 462306a36Sopenharmony_ci * Permission is hereby granted, free of charge, to any person obtaining a 562306a36Sopenharmony_ci * copy of this software and associated documentation files (the "Software"), 662306a36Sopenharmony_ci * to deal in the Software without restriction, including without limitation 762306a36Sopenharmony_ci * the rights to use, copy, modify, merge, publish, distribute, sublicense, 862306a36Sopenharmony_ci * and/or sell copies of the Software, and to permit persons to whom the 962306a36Sopenharmony_ci * Software is furnished to do so, subject to the following conditions: 1062306a36Sopenharmony_ci * 1162306a36Sopenharmony_ci * The above copyright notice and this permission notice (including the next 1262306a36Sopenharmony_ci * paragraph) shall be included in all copies or substantial portions of the 1362306a36Sopenharmony_ci * Software. 1462306a36Sopenharmony_ci * 1562306a36Sopenharmony_ci * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 1662306a36Sopenharmony_ci * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 1762306a36Sopenharmony_ci * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 1862306a36Sopenharmony_ci * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 1962306a36Sopenharmony_ci * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 2062306a36Sopenharmony_ci * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 2162306a36Sopenharmony_ci * SOFTWARE. 2262306a36Sopenharmony_ci * 2362306a36Sopenharmony_ci * Authors: 2462306a36Sopenharmony_ci * Ke Yu 2562306a36Sopenharmony_ci * Zhiyuan Lv <zhiyuan.lv@intel.com> 2662306a36Sopenharmony_ci * 2762306a36Sopenharmony_ci * Contributors: 2862306a36Sopenharmony_ci * Terrence Xu <terrence.xu@intel.com> 2962306a36Sopenharmony_ci * Changbin Du <changbin.du@intel.com> 3062306a36Sopenharmony_ci * Bing Niu <bing.niu@intel.com> 3162306a36Sopenharmony_ci * Zhi Wang <zhi.a.wang@intel.com> 3262306a36Sopenharmony_ci * 3362306a36Sopenharmony_ci */ 3462306a36Sopenharmony_ci 3562306a36Sopenharmony_ci#ifndef _GVT_DISPLAY_H_ 3662306a36Sopenharmony_ci#define _GVT_DISPLAY_H_ 3762306a36Sopenharmony_ci 3862306a36Sopenharmony_ci#include <linux/types.h> 3962306a36Sopenharmony_ci#include <linux/hrtimer.h> 4062306a36Sopenharmony_ci 4162306a36Sopenharmony_cistruct intel_gvt; 4262306a36Sopenharmony_cistruct intel_vgpu; 4362306a36Sopenharmony_ci 4462306a36Sopenharmony_ci#define SBI_REG_MAX 20 4562306a36Sopenharmony_ci#define DPCD_SIZE 0x700 4662306a36Sopenharmony_ci 4762306a36Sopenharmony_ci#define intel_vgpu_port(vgpu, port) \ 4862306a36Sopenharmony_ci (&(vgpu->display.ports[port])) 4962306a36Sopenharmony_ci 5062306a36Sopenharmony_ci#define intel_vgpu_has_monitor_on_port(vgpu, port) \ 5162306a36Sopenharmony_ci (intel_vgpu_port(vgpu, port)->edid && \ 5262306a36Sopenharmony_ci intel_vgpu_port(vgpu, port)->edid->data_valid) 5362306a36Sopenharmony_ci 5462306a36Sopenharmony_ci#define intel_vgpu_port_is_dp(vgpu, port) \ 5562306a36Sopenharmony_ci ((intel_vgpu_port(vgpu, port)->type == GVT_DP_A) || \ 5662306a36Sopenharmony_ci (intel_vgpu_port(vgpu, port)->type == GVT_DP_B) || \ 5762306a36Sopenharmony_ci (intel_vgpu_port(vgpu, port)->type == GVT_DP_C) || \ 5862306a36Sopenharmony_ci (intel_vgpu_port(vgpu, port)->type == GVT_DP_D)) 5962306a36Sopenharmony_ci 6062306a36Sopenharmony_ci#define INTEL_GVT_MAX_UEVENT_VARS 3 6162306a36Sopenharmony_ci 6262306a36Sopenharmony_ci/* DPCD start */ 6362306a36Sopenharmony_ci#define DPCD_SIZE 0x700 6462306a36Sopenharmony_ci 6562306a36Sopenharmony_ci/* DPCD */ 6662306a36Sopenharmony_ci#define DP_SET_POWER 0x600 6762306a36Sopenharmony_ci#define DP_SET_POWER_D0 0x1 6862306a36Sopenharmony_ci#define AUX_NATIVE_WRITE 0x8 6962306a36Sopenharmony_ci#define AUX_NATIVE_READ 0x9 7062306a36Sopenharmony_ci 7162306a36Sopenharmony_ci#define AUX_NATIVE_REPLY_MASK (0x3 << 4) 7262306a36Sopenharmony_ci#define AUX_NATIVE_REPLY_ACK (0x0 << 4) 7362306a36Sopenharmony_ci#define AUX_NATIVE_REPLY_NAK (0x1 << 4) 7462306a36Sopenharmony_ci#define AUX_NATIVE_REPLY_DEFER (0x2 << 4) 7562306a36Sopenharmony_ci 7662306a36Sopenharmony_ci#define AUX_BURST_SIZE 20 7762306a36Sopenharmony_ci 7862306a36Sopenharmony_ci/* DPCD addresses */ 7962306a36Sopenharmony_ci#define DPCD_REV 0x000 8062306a36Sopenharmony_ci#define DPCD_MAX_LINK_RATE 0x001 8162306a36Sopenharmony_ci#define DPCD_MAX_LANE_COUNT 0x002 8262306a36Sopenharmony_ci 8362306a36Sopenharmony_ci#define DPCD_TRAINING_PATTERN_SET 0x102 8462306a36Sopenharmony_ci#define DPCD_SINK_COUNT 0x200 8562306a36Sopenharmony_ci#define DPCD_LANE0_1_STATUS 0x202 8662306a36Sopenharmony_ci#define DPCD_LANE2_3_STATUS 0x203 8762306a36Sopenharmony_ci#define DPCD_LANE_ALIGN_STATUS_UPDATED 0x204 8862306a36Sopenharmony_ci#define DPCD_SINK_STATUS 0x205 8962306a36Sopenharmony_ci 9062306a36Sopenharmony_ci/* link training */ 9162306a36Sopenharmony_ci#define DPCD_TRAINING_PATTERN_SET_MASK 0x03 9262306a36Sopenharmony_ci#define DPCD_LINK_TRAINING_DISABLED 0x00 9362306a36Sopenharmony_ci#define DPCD_TRAINING_PATTERN_1 0x01 9462306a36Sopenharmony_ci#define DPCD_TRAINING_PATTERN_2 0x02 9562306a36Sopenharmony_ci 9662306a36Sopenharmony_ci#define DPCD_CP_READY_MASK (1 << 6) 9762306a36Sopenharmony_ci 9862306a36Sopenharmony_ci/* lane status */ 9962306a36Sopenharmony_ci#define DPCD_LANES_CR_DONE 0x11 10062306a36Sopenharmony_ci#define DPCD_LANES_EQ_DONE 0x22 10162306a36Sopenharmony_ci#define DPCD_SYMBOL_LOCKED 0x44 10262306a36Sopenharmony_ci 10362306a36Sopenharmony_ci#define DPCD_INTERLANE_ALIGN_DONE 0x01 10462306a36Sopenharmony_ci 10562306a36Sopenharmony_ci#define DPCD_SINK_IN_SYNC 0x03 10662306a36Sopenharmony_ci/* DPCD end */ 10762306a36Sopenharmony_ci 10862306a36Sopenharmony_ci#define SBI_RESPONSE_MASK 0x3 10962306a36Sopenharmony_ci#define SBI_RESPONSE_SHIFT 0x1 11062306a36Sopenharmony_ci#define SBI_STAT_MASK 0x1 11162306a36Sopenharmony_ci#define SBI_STAT_SHIFT 0x0 11262306a36Sopenharmony_ci#define SBI_OPCODE_SHIFT 8 11362306a36Sopenharmony_ci#define SBI_OPCODE_MASK (0xff << SBI_OPCODE_SHIFT) 11462306a36Sopenharmony_ci#define SBI_CMD_IORD 2 11562306a36Sopenharmony_ci#define SBI_CMD_IOWR 3 11662306a36Sopenharmony_ci#define SBI_CMD_CRRD 6 11762306a36Sopenharmony_ci#define SBI_CMD_CRWR 7 11862306a36Sopenharmony_ci#define SBI_ADDR_OFFSET_SHIFT 16 11962306a36Sopenharmony_ci#define SBI_ADDR_OFFSET_MASK (0xffff << SBI_ADDR_OFFSET_SHIFT) 12062306a36Sopenharmony_ci 12162306a36Sopenharmony_cistruct intel_vgpu_sbi_register { 12262306a36Sopenharmony_ci unsigned int offset; 12362306a36Sopenharmony_ci u32 value; 12462306a36Sopenharmony_ci}; 12562306a36Sopenharmony_ci 12662306a36Sopenharmony_cistruct intel_vgpu_sbi { 12762306a36Sopenharmony_ci int number; 12862306a36Sopenharmony_ci struct intel_vgpu_sbi_register registers[SBI_REG_MAX]; 12962306a36Sopenharmony_ci}; 13062306a36Sopenharmony_ci 13162306a36Sopenharmony_cienum intel_gvt_plane_type { 13262306a36Sopenharmony_ci PRIMARY_PLANE = 0, 13362306a36Sopenharmony_ci CURSOR_PLANE, 13462306a36Sopenharmony_ci SPRITE_PLANE, 13562306a36Sopenharmony_ci MAX_PLANE 13662306a36Sopenharmony_ci}; 13762306a36Sopenharmony_ci 13862306a36Sopenharmony_cistruct intel_vgpu_dpcd_data { 13962306a36Sopenharmony_ci bool data_valid; 14062306a36Sopenharmony_ci u8 data[DPCD_SIZE]; 14162306a36Sopenharmony_ci}; 14262306a36Sopenharmony_ci 14362306a36Sopenharmony_cienum intel_vgpu_port_type { 14462306a36Sopenharmony_ci GVT_CRT = 0, 14562306a36Sopenharmony_ci GVT_DP_A, 14662306a36Sopenharmony_ci GVT_DP_B, 14762306a36Sopenharmony_ci GVT_DP_C, 14862306a36Sopenharmony_ci GVT_DP_D, 14962306a36Sopenharmony_ci GVT_HDMI_B, 15062306a36Sopenharmony_ci GVT_HDMI_C, 15162306a36Sopenharmony_ci GVT_HDMI_D, 15262306a36Sopenharmony_ci GVT_PORT_MAX 15362306a36Sopenharmony_ci}; 15462306a36Sopenharmony_ci 15562306a36Sopenharmony_cienum intel_vgpu_edid { 15662306a36Sopenharmony_ci GVT_EDID_1024_768, 15762306a36Sopenharmony_ci GVT_EDID_1920_1200, 15862306a36Sopenharmony_ci GVT_EDID_NUM, 15962306a36Sopenharmony_ci}; 16062306a36Sopenharmony_ci 16162306a36Sopenharmony_ci#define GVT_DEFAULT_REFRESH_RATE 60 16262306a36Sopenharmony_cistruct intel_vgpu_port { 16362306a36Sopenharmony_ci /* per display EDID information */ 16462306a36Sopenharmony_ci struct intel_vgpu_edid_data *edid; 16562306a36Sopenharmony_ci /* per display DPCD information */ 16662306a36Sopenharmony_ci struct intel_vgpu_dpcd_data *dpcd; 16762306a36Sopenharmony_ci int type; 16862306a36Sopenharmony_ci enum intel_vgpu_edid id; 16962306a36Sopenharmony_ci /* x1000 to get accurate 59.94, 24.976, 29.94, etc. in timing std. */ 17062306a36Sopenharmony_ci u32 vrefresh_k; 17162306a36Sopenharmony_ci}; 17262306a36Sopenharmony_ci 17362306a36Sopenharmony_cistruct intel_vgpu_vblank_timer { 17462306a36Sopenharmony_ci struct hrtimer timer; 17562306a36Sopenharmony_ci u32 vrefresh_k; 17662306a36Sopenharmony_ci u64 period; 17762306a36Sopenharmony_ci}; 17862306a36Sopenharmony_ci 17962306a36Sopenharmony_cistatic inline char *vgpu_edid_str(enum intel_vgpu_edid id) 18062306a36Sopenharmony_ci{ 18162306a36Sopenharmony_ci switch (id) { 18262306a36Sopenharmony_ci case GVT_EDID_1024_768: 18362306a36Sopenharmony_ci return "1024x768"; 18462306a36Sopenharmony_ci case GVT_EDID_1920_1200: 18562306a36Sopenharmony_ci return "1920x1200"; 18662306a36Sopenharmony_ci default: 18762306a36Sopenharmony_ci return ""; 18862306a36Sopenharmony_ci } 18962306a36Sopenharmony_ci} 19062306a36Sopenharmony_ci 19162306a36Sopenharmony_cistatic inline unsigned int vgpu_edid_xres(enum intel_vgpu_edid id) 19262306a36Sopenharmony_ci{ 19362306a36Sopenharmony_ci switch (id) { 19462306a36Sopenharmony_ci case GVT_EDID_1024_768: 19562306a36Sopenharmony_ci return 1024; 19662306a36Sopenharmony_ci case GVT_EDID_1920_1200: 19762306a36Sopenharmony_ci return 1920; 19862306a36Sopenharmony_ci default: 19962306a36Sopenharmony_ci return 0; 20062306a36Sopenharmony_ci } 20162306a36Sopenharmony_ci} 20262306a36Sopenharmony_ci 20362306a36Sopenharmony_cistatic inline unsigned int vgpu_edid_yres(enum intel_vgpu_edid id) 20462306a36Sopenharmony_ci{ 20562306a36Sopenharmony_ci switch (id) { 20662306a36Sopenharmony_ci case GVT_EDID_1024_768: 20762306a36Sopenharmony_ci return 768; 20862306a36Sopenharmony_ci case GVT_EDID_1920_1200: 20962306a36Sopenharmony_ci return 1200; 21062306a36Sopenharmony_ci default: 21162306a36Sopenharmony_ci return 0; 21262306a36Sopenharmony_ci } 21362306a36Sopenharmony_ci} 21462306a36Sopenharmony_ci 21562306a36Sopenharmony_civoid intel_vgpu_emulate_vblank(struct intel_vgpu *vgpu); 21662306a36Sopenharmony_civoid vgpu_update_vblank_emulation(struct intel_vgpu *vgpu, bool turnon); 21762306a36Sopenharmony_ci 21862306a36Sopenharmony_ciint intel_vgpu_init_display(struct intel_vgpu *vgpu, u64 resolution); 21962306a36Sopenharmony_civoid intel_vgpu_reset_display(struct intel_vgpu *vgpu); 22062306a36Sopenharmony_civoid intel_vgpu_clean_display(struct intel_vgpu *vgpu); 22162306a36Sopenharmony_ci 22262306a36Sopenharmony_ciint pipe_is_enabled(struct intel_vgpu *vgpu, int pipe); 22362306a36Sopenharmony_ci 22462306a36Sopenharmony_ci#endif 225