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 *    Kevin Tian <kevin.tian@intel.com>
258c2ecf20Sopenharmony_ci *    Zhi Wang <zhi.a.wang@intel.com>
268c2ecf20Sopenharmony_ci *
278c2ecf20Sopenharmony_ci * Contributors:
288c2ecf20Sopenharmony_ci *    Min he <min.he@intel.com>
298c2ecf20Sopenharmony_ci *
308c2ecf20Sopenharmony_ci */
318c2ecf20Sopenharmony_ci
328c2ecf20Sopenharmony_ci#ifndef _GVT_INTERRUPT_H_
338c2ecf20Sopenharmony_ci#define _GVT_INTERRUPT_H_
348c2ecf20Sopenharmony_ci
358c2ecf20Sopenharmony_ci#include <linux/types.h>
368c2ecf20Sopenharmony_ci
378c2ecf20Sopenharmony_cienum intel_gvt_event_type {
388c2ecf20Sopenharmony_ci	RCS_MI_USER_INTERRUPT = 0,
398c2ecf20Sopenharmony_ci	RCS_DEBUG,
408c2ecf20Sopenharmony_ci	RCS_MMIO_SYNC_FLUSH,
418c2ecf20Sopenharmony_ci	RCS_CMD_STREAMER_ERR,
428c2ecf20Sopenharmony_ci	RCS_PIPE_CONTROL,
438c2ecf20Sopenharmony_ci	RCS_L3_PARITY_ERR,
448c2ecf20Sopenharmony_ci	RCS_WATCHDOG_EXCEEDED,
458c2ecf20Sopenharmony_ci	RCS_PAGE_DIRECTORY_FAULT,
468c2ecf20Sopenharmony_ci	RCS_AS_CONTEXT_SWITCH,
478c2ecf20Sopenharmony_ci	RCS_MONITOR_BUFF_HALF_FULL,
488c2ecf20Sopenharmony_ci
498c2ecf20Sopenharmony_ci	VCS_MI_USER_INTERRUPT,
508c2ecf20Sopenharmony_ci	VCS_MMIO_SYNC_FLUSH,
518c2ecf20Sopenharmony_ci	VCS_CMD_STREAMER_ERR,
528c2ecf20Sopenharmony_ci	VCS_MI_FLUSH_DW,
538c2ecf20Sopenharmony_ci	VCS_WATCHDOG_EXCEEDED,
548c2ecf20Sopenharmony_ci	VCS_PAGE_DIRECTORY_FAULT,
558c2ecf20Sopenharmony_ci	VCS_AS_CONTEXT_SWITCH,
568c2ecf20Sopenharmony_ci
578c2ecf20Sopenharmony_ci	VCS2_MI_USER_INTERRUPT,
588c2ecf20Sopenharmony_ci	VCS2_MI_FLUSH_DW,
598c2ecf20Sopenharmony_ci	VCS2_AS_CONTEXT_SWITCH,
608c2ecf20Sopenharmony_ci
618c2ecf20Sopenharmony_ci	BCS_MI_USER_INTERRUPT,
628c2ecf20Sopenharmony_ci	BCS_MMIO_SYNC_FLUSH,
638c2ecf20Sopenharmony_ci	BCS_CMD_STREAMER_ERR,
648c2ecf20Sopenharmony_ci	BCS_MI_FLUSH_DW,
658c2ecf20Sopenharmony_ci	BCS_PAGE_DIRECTORY_FAULT,
668c2ecf20Sopenharmony_ci	BCS_AS_CONTEXT_SWITCH,
678c2ecf20Sopenharmony_ci
688c2ecf20Sopenharmony_ci	VECS_MI_USER_INTERRUPT,
698c2ecf20Sopenharmony_ci	VECS_MI_FLUSH_DW,
708c2ecf20Sopenharmony_ci	VECS_AS_CONTEXT_SWITCH,
718c2ecf20Sopenharmony_ci
728c2ecf20Sopenharmony_ci	PIPE_A_FIFO_UNDERRUN,
738c2ecf20Sopenharmony_ci	PIPE_B_FIFO_UNDERRUN,
748c2ecf20Sopenharmony_ci	PIPE_A_CRC_ERR,
758c2ecf20Sopenharmony_ci	PIPE_B_CRC_ERR,
768c2ecf20Sopenharmony_ci	PIPE_A_CRC_DONE,
778c2ecf20Sopenharmony_ci	PIPE_B_CRC_DONE,
788c2ecf20Sopenharmony_ci	PIPE_A_ODD_FIELD,
798c2ecf20Sopenharmony_ci	PIPE_B_ODD_FIELD,
808c2ecf20Sopenharmony_ci	PIPE_A_EVEN_FIELD,
818c2ecf20Sopenharmony_ci	PIPE_B_EVEN_FIELD,
828c2ecf20Sopenharmony_ci	PIPE_A_LINE_COMPARE,
838c2ecf20Sopenharmony_ci	PIPE_B_LINE_COMPARE,
848c2ecf20Sopenharmony_ci	PIPE_C_LINE_COMPARE,
858c2ecf20Sopenharmony_ci	PIPE_A_VBLANK,
868c2ecf20Sopenharmony_ci	PIPE_B_VBLANK,
878c2ecf20Sopenharmony_ci	PIPE_C_VBLANK,
888c2ecf20Sopenharmony_ci	PIPE_A_VSYNC,
898c2ecf20Sopenharmony_ci	PIPE_B_VSYNC,
908c2ecf20Sopenharmony_ci	PIPE_C_VSYNC,
918c2ecf20Sopenharmony_ci	PRIMARY_A_FLIP_DONE,
928c2ecf20Sopenharmony_ci	PRIMARY_B_FLIP_DONE,
938c2ecf20Sopenharmony_ci	PRIMARY_C_FLIP_DONE,
948c2ecf20Sopenharmony_ci	SPRITE_A_FLIP_DONE,
958c2ecf20Sopenharmony_ci	SPRITE_B_FLIP_DONE,
968c2ecf20Sopenharmony_ci	SPRITE_C_FLIP_DONE,
978c2ecf20Sopenharmony_ci
988c2ecf20Sopenharmony_ci	PCU_THERMAL,
998c2ecf20Sopenharmony_ci	PCU_PCODE2DRIVER_MAILBOX,
1008c2ecf20Sopenharmony_ci
1018c2ecf20Sopenharmony_ci	DPST_PHASE_IN,
1028c2ecf20Sopenharmony_ci	DPST_HISTOGRAM,
1038c2ecf20Sopenharmony_ci	GSE,
1048c2ecf20Sopenharmony_ci	DP_A_HOTPLUG,
1058c2ecf20Sopenharmony_ci	AUX_CHANNEL_A,
1068c2ecf20Sopenharmony_ci	PERF_COUNTER,
1078c2ecf20Sopenharmony_ci	POISON,
1088c2ecf20Sopenharmony_ci	GTT_FAULT,
1098c2ecf20Sopenharmony_ci	ERROR_INTERRUPT_COMBINED,
1108c2ecf20Sopenharmony_ci
1118c2ecf20Sopenharmony_ci	FDI_RX_INTERRUPTS_TRANSCODER_A,
1128c2ecf20Sopenharmony_ci	AUDIO_CP_CHANGE_TRANSCODER_A,
1138c2ecf20Sopenharmony_ci	AUDIO_CP_REQUEST_TRANSCODER_A,
1148c2ecf20Sopenharmony_ci	FDI_RX_INTERRUPTS_TRANSCODER_B,
1158c2ecf20Sopenharmony_ci	AUDIO_CP_CHANGE_TRANSCODER_B,
1168c2ecf20Sopenharmony_ci	AUDIO_CP_REQUEST_TRANSCODER_B,
1178c2ecf20Sopenharmony_ci	FDI_RX_INTERRUPTS_TRANSCODER_C,
1188c2ecf20Sopenharmony_ci	AUDIO_CP_CHANGE_TRANSCODER_C,
1198c2ecf20Sopenharmony_ci	AUDIO_CP_REQUEST_TRANSCODER_C,
1208c2ecf20Sopenharmony_ci	ERR_AND_DBG,
1218c2ecf20Sopenharmony_ci	GMBUS,
1228c2ecf20Sopenharmony_ci	SDVO_B_HOTPLUG,
1238c2ecf20Sopenharmony_ci	CRT_HOTPLUG,
1248c2ecf20Sopenharmony_ci	DP_B_HOTPLUG,
1258c2ecf20Sopenharmony_ci	DP_C_HOTPLUG,
1268c2ecf20Sopenharmony_ci	DP_D_HOTPLUG,
1278c2ecf20Sopenharmony_ci	AUX_CHANNEL_B,
1288c2ecf20Sopenharmony_ci	AUX_CHANNEL_C,
1298c2ecf20Sopenharmony_ci	AUX_CHANNEL_D,
1308c2ecf20Sopenharmony_ci	AUDIO_POWER_STATE_CHANGE_B,
1318c2ecf20Sopenharmony_ci	AUDIO_POWER_STATE_CHANGE_C,
1328c2ecf20Sopenharmony_ci	AUDIO_POWER_STATE_CHANGE_D,
1338c2ecf20Sopenharmony_ci
1348c2ecf20Sopenharmony_ci	INTEL_GVT_EVENT_RESERVED,
1358c2ecf20Sopenharmony_ci	INTEL_GVT_EVENT_MAX,
1368c2ecf20Sopenharmony_ci};
1378c2ecf20Sopenharmony_ci
1388c2ecf20Sopenharmony_cistruct intel_gvt_irq;
1398c2ecf20Sopenharmony_cistruct intel_gvt;
1408c2ecf20Sopenharmony_cistruct intel_vgpu;
1418c2ecf20Sopenharmony_ci
1428c2ecf20Sopenharmony_citypedef void (*gvt_event_virt_handler_t)(struct intel_gvt_irq *irq,
1438c2ecf20Sopenharmony_ci	enum intel_gvt_event_type event, struct intel_vgpu *vgpu);
1448c2ecf20Sopenharmony_ci
1458c2ecf20Sopenharmony_cistruct intel_gvt_irq_ops {
1468c2ecf20Sopenharmony_ci	void (*init_irq)(struct intel_gvt_irq *irq);
1478c2ecf20Sopenharmony_ci	void (*check_pending_irq)(struct intel_vgpu *vgpu);
1488c2ecf20Sopenharmony_ci};
1498c2ecf20Sopenharmony_ci
1508c2ecf20Sopenharmony_ci/* the list of physical interrupt control register groups */
1518c2ecf20Sopenharmony_cienum intel_gvt_irq_type {
1528c2ecf20Sopenharmony_ci	INTEL_GVT_IRQ_INFO_GT,
1538c2ecf20Sopenharmony_ci	INTEL_GVT_IRQ_INFO_DPY,
1548c2ecf20Sopenharmony_ci	INTEL_GVT_IRQ_INFO_PCH,
1558c2ecf20Sopenharmony_ci	INTEL_GVT_IRQ_INFO_PM,
1568c2ecf20Sopenharmony_ci
1578c2ecf20Sopenharmony_ci	INTEL_GVT_IRQ_INFO_MASTER,
1588c2ecf20Sopenharmony_ci	INTEL_GVT_IRQ_INFO_GT0,
1598c2ecf20Sopenharmony_ci	INTEL_GVT_IRQ_INFO_GT1,
1608c2ecf20Sopenharmony_ci	INTEL_GVT_IRQ_INFO_GT2,
1618c2ecf20Sopenharmony_ci	INTEL_GVT_IRQ_INFO_GT3,
1628c2ecf20Sopenharmony_ci	INTEL_GVT_IRQ_INFO_DE_PIPE_A,
1638c2ecf20Sopenharmony_ci	INTEL_GVT_IRQ_INFO_DE_PIPE_B,
1648c2ecf20Sopenharmony_ci	INTEL_GVT_IRQ_INFO_DE_PIPE_C,
1658c2ecf20Sopenharmony_ci	INTEL_GVT_IRQ_INFO_DE_PORT,
1668c2ecf20Sopenharmony_ci	INTEL_GVT_IRQ_INFO_DE_MISC,
1678c2ecf20Sopenharmony_ci	INTEL_GVT_IRQ_INFO_AUD,
1688c2ecf20Sopenharmony_ci	INTEL_GVT_IRQ_INFO_PCU,
1698c2ecf20Sopenharmony_ci
1708c2ecf20Sopenharmony_ci	INTEL_GVT_IRQ_INFO_MAX,
1718c2ecf20Sopenharmony_ci};
1728c2ecf20Sopenharmony_ci
1738c2ecf20Sopenharmony_ci#define INTEL_GVT_IRQ_BITWIDTH	32
1748c2ecf20Sopenharmony_ci
1758c2ecf20Sopenharmony_ci/* device specific interrupt bit definitions */
1768c2ecf20Sopenharmony_cistruct intel_gvt_irq_info {
1778c2ecf20Sopenharmony_ci	char *name;
1788c2ecf20Sopenharmony_ci	i915_reg_t reg_base;
1798c2ecf20Sopenharmony_ci	enum intel_gvt_event_type bit_to_event[INTEL_GVT_IRQ_BITWIDTH];
1808c2ecf20Sopenharmony_ci	unsigned long warned;
1818c2ecf20Sopenharmony_ci	int group;
1828c2ecf20Sopenharmony_ci	DECLARE_BITMAP(downstream_irq_bitmap, INTEL_GVT_IRQ_BITWIDTH);
1838c2ecf20Sopenharmony_ci	bool has_upstream_irq;
1848c2ecf20Sopenharmony_ci};
1858c2ecf20Sopenharmony_ci
1868c2ecf20Sopenharmony_ci/* per-event information */
1878c2ecf20Sopenharmony_cistruct intel_gvt_event_info {
1888c2ecf20Sopenharmony_ci	int bit;				/* map to register bit */
1898c2ecf20Sopenharmony_ci	int policy;				/* forwarding policy */
1908c2ecf20Sopenharmony_ci	struct intel_gvt_irq_info *info;	/* register info */
1918c2ecf20Sopenharmony_ci	gvt_event_virt_handler_t v_handler;	/* for v_event */
1928c2ecf20Sopenharmony_ci};
1938c2ecf20Sopenharmony_ci
1948c2ecf20Sopenharmony_cistruct intel_gvt_irq_map {
1958c2ecf20Sopenharmony_ci	int up_irq_group;
1968c2ecf20Sopenharmony_ci	int up_irq_bit;
1978c2ecf20Sopenharmony_ci	int down_irq_group;
1988c2ecf20Sopenharmony_ci	u32 down_irq_bitmask;
1998c2ecf20Sopenharmony_ci};
2008c2ecf20Sopenharmony_ci
2018c2ecf20Sopenharmony_cistruct intel_gvt_vblank_timer {
2028c2ecf20Sopenharmony_ci	struct hrtimer timer;
2038c2ecf20Sopenharmony_ci	u64 period;
2048c2ecf20Sopenharmony_ci};
2058c2ecf20Sopenharmony_ci
2068c2ecf20Sopenharmony_ci/* structure containing device specific IRQ state */
2078c2ecf20Sopenharmony_cistruct intel_gvt_irq {
2088c2ecf20Sopenharmony_ci	struct intel_gvt_irq_ops *ops;
2098c2ecf20Sopenharmony_ci	struct intel_gvt_irq_info *info[INTEL_GVT_IRQ_INFO_MAX];
2108c2ecf20Sopenharmony_ci	DECLARE_BITMAP(irq_info_bitmap, INTEL_GVT_IRQ_INFO_MAX);
2118c2ecf20Sopenharmony_ci	struct intel_gvt_event_info events[INTEL_GVT_EVENT_MAX];
2128c2ecf20Sopenharmony_ci	DECLARE_BITMAP(pending_events, INTEL_GVT_EVENT_MAX);
2138c2ecf20Sopenharmony_ci	struct intel_gvt_irq_map *irq_map;
2148c2ecf20Sopenharmony_ci	struct intel_gvt_vblank_timer vblank_timer;
2158c2ecf20Sopenharmony_ci};
2168c2ecf20Sopenharmony_ci
2178c2ecf20Sopenharmony_ciint intel_gvt_init_irq(struct intel_gvt *gvt);
2188c2ecf20Sopenharmony_civoid intel_gvt_clean_irq(struct intel_gvt *gvt);
2198c2ecf20Sopenharmony_ci
2208c2ecf20Sopenharmony_civoid intel_vgpu_trigger_virtual_event(struct intel_vgpu *vgpu,
2218c2ecf20Sopenharmony_ci	enum intel_gvt_event_type event);
2228c2ecf20Sopenharmony_ci
2238c2ecf20Sopenharmony_ciint intel_vgpu_reg_iir_handler(struct intel_vgpu *vgpu, unsigned int reg,
2248c2ecf20Sopenharmony_ci	void *p_data, unsigned int bytes);
2258c2ecf20Sopenharmony_ciint intel_vgpu_reg_ier_handler(struct intel_vgpu *vgpu,
2268c2ecf20Sopenharmony_ci	unsigned int reg, void *p_data, unsigned int bytes);
2278c2ecf20Sopenharmony_ciint intel_vgpu_reg_master_irq_handler(struct intel_vgpu *vgpu,
2288c2ecf20Sopenharmony_ci	unsigned int reg, void *p_data, unsigned int bytes);
2298c2ecf20Sopenharmony_ciint intel_vgpu_reg_imr_handler(struct intel_vgpu *vgpu,
2308c2ecf20Sopenharmony_ci	unsigned int reg, void *p_data, unsigned int bytes);
2318c2ecf20Sopenharmony_ci
2328c2ecf20Sopenharmony_ciint gvt_ring_id_to_pipe_control_notify_event(int ring_id);
2338c2ecf20Sopenharmony_ciint gvt_ring_id_to_mi_flush_dw_event(int ring_id);
2348c2ecf20Sopenharmony_ciint gvt_ring_id_to_mi_user_interrupt_event(int ring_id);
2358c2ecf20Sopenharmony_ci
2368c2ecf20Sopenharmony_ci#endif /* _GVT_INTERRUPT_H_ */
237