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 * Eddie Dong <eddie.dong@intel.com> 268c2ecf20Sopenharmony_ci * 278c2ecf20Sopenharmony_ci * Contributors: 288c2ecf20Sopenharmony_ci * Niu Bing <bing.niu@intel.com> 298c2ecf20Sopenharmony_ci * Zhi Wang <zhi.a.wang@intel.com> 308c2ecf20Sopenharmony_ci * 318c2ecf20Sopenharmony_ci */ 328c2ecf20Sopenharmony_ci 338c2ecf20Sopenharmony_ci#ifndef _GVT_H_ 348c2ecf20Sopenharmony_ci#define _GVT_H_ 358c2ecf20Sopenharmony_ci 368c2ecf20Sopenharmony_ci#include "debug.h" 378c2ecf20Sopenharmony_ci#include "hypercall.h" 388c2ecf20Sopenharmony_ci#include "mmio.h" 398c2ecf20Sopenharmony_ci#include "reg.h" 408c2ecf20Sopenharmony_ci#include "interrupt.h" 418c2ecf20Sopenharmony_ci#include "gtt.h" 428c2ecf20Sopenharmony_ci#include "display.h" 438c2ecf20Sopenharmony_ci#include "edid.h" 448c2ecf20Sopenharmony_ci#include "execlist.h" 458c2ecf20Sopenharmony_ci#include "scheduler.h" 468c2ecf20Sopenharmony_ci#include "sched_policy.h" 478c2ecf20Sopenharmony_ci#include "mmio_context.h" 488c2ecf20Sopenharmony_ci#include "cmd_parser.h" 498c2ecf20Sopenharmony_ci#include "fb_decoder.h" 508c2ecf20Sopenharmony_ci#include "dmabuf.h" 518c2ecf20Sopenharmony_ci#include "page_track.h" 528c2ecf20Sopenharmony_ci 538c2ecf20Sopenharmony_ci#define GVT_MAX_VGPU 8 548c2ecf20Sopenharmony_ci 558c2ecf20Sopenharmony_cistruct intel_gvt_host { 568c2ecf20Sopenharmony_ci struct device *dev; 578c2ecf20Sopenharmony_ci bool initialized; 588c2ecf20Sopenharmony_ci int hypervisor_type; 598c2ecf20Sopenharmony_ci struct intel_gvt_mpt *mpt; 608c2ecf20Sopenharmony_ci}; 618c2ecf20Sopenharmony_ci 628c2ecf20Sopenharmony_ciextern struct intel_gvt_host intel_gvt_host; 638c2ecf20Sopenharmony_ci 648c2ecf20Sopenharmony_ci/* Describe per-platform limitations. */ 658c2ecf20Sopenharmony_cistruct intel_gvt_device_info { 668c2ecf20Sopenharmony_ci u32 max_support_vgpus; 678c2ecf20Sopenharmony_ci u32 cfg_space_size; 688c2ecf20Sopenharmony_ci u32 mmio_size; 698c2ecf20Sopenharmony_ci u32 mmio_bar; 708c2ecf20Sopenharmony_ci unsigned long msi_cap_offset; 718c2ecf20Sopenharmony_ci u32 gtt_start_offset; 728c2ecf20Sopenharmony_ci u32 gtt_entry_size; 738c2ecf20Sopenharmony_ci u32 gtt_entry_size_shift; 748c2ecf20Sopenharmony_ci int gmadr_bytes_in_cmd; 758c2ecf20Sopenharmony_ci u32 max_surface_size; 768c2ecf20Sopenharmony_ci}; 778c2ecf20Sopenharmony_ci 788c2ecf20Sopenharmony_ci/* GM resources owned by a vGPU */ 798c2ecf20Sopenharmony_cistruct intel_vgpu_gm { 808c2ecf20Sopenharmony_ci u64 aperture_sz; 818c2ecf20Sopenharmony_ci u64 hidden_sz; 828c2ecf20Sopenharmony_ci struct drm_mm_node low_gm_node; 838c2ecf20Sopenharmony_ci struct drm_mm_node high_gm_node; 848c2ecf20Sopenharmony_ci}; 858c2ecf20Sopenharmony_ci 868c2ecf20Sopenharmony_ci#define INTEL_GVT_MAX_NUM_FENCES 32 878c2ecf20Sopenharmony_ci 888c2ecf20Sopenharmony_ci/* Fences owned by a vGPU */ 898c2ecf20Sopenharmony_cistruct intel_vgpu_fence { 908c2ecf20Sopenharmony_ci struct i915_fence_reg *regs[INTEL_GVT_MAX_NUM_FENCES]; 918c2ecf20Sopenharmony_ci u32 base; 928c2ecf20Sopenharmony_ci u32 size; 938c2ecf20Sopenharmony_ci}; 948c2ecf20Sopenharmony_ci 958c2ecf20Sopenharmony_cistruct intel_vgpu_mmio { 968c2ecf20Sopenharmony_ci void *vreg; 978c2ecf20Sopenharmony_ci}; 988c2ecf20Sopenharmony_ci 998c2ecf20Sopenharmony_ci#define INTEL_GVT_MAX_BAR_NUM 4 1008c2ecf20Sopenharmony_ci 1018c2ecf20Sopenharmony_cistruct intel_vgpu_pci_bar { 1028c2ecf20Sopenharmony_ci u64 size; 1038c2ecf20Sopenharmony_ci bool tracked; 1048c2ecf20Sopenharmony_ci}; 1058c2ecf20Sopenharmony_ci 1068c2ecf20Sopenharmony_cistruct intel_vgpu_cfg_space { 1078c2ecf20Sopenharmony_ci unsigned char virtual_cfg_space[PCI_CFG_SPACE_EXP_SIZE]; 1088c2ecf20Sopenharmony_ci struct intel_vgpu_pci_bar bar[INTEL_GVT_MAX_BAR_NUM]; 1098c2ecf20Sopenharmony_ci u32 pmcsr_off; 1108c2ecf20Sopenharmony_ci}; 1118c2ecf20Sopenharmony_ci 1128c2ecf20Sopenharmony_ci#define vgpu_cfg_space(vgpu) ((vgpu)->cfg_space.virtual_cfg_space) 1138c2ecf20Sopenharmony_ci 1148c2ecf20Sopenharmony_cistruct intel_vgpu_irq { 1158c2ecf20Sopenharmony_ci bool irq_warn_once[INTEL_GVT_EVENT_MAX]; 1168c2ecf20Sopenharmony_ci DECLARE_BITMAP(flip_done_event[I915_MAX_PIPES], 1178c2ecf20Sopenharmony_ci INTEL_GVT_EVENT_MAX); 1188c2ecf20Sopenharmony_ci}; 1198c2ecf20Sopenharmony_ci 1208c2ecf20Sopenharmony_cistruct intel_vgpu_opregion { 1218c2ecf20Sopenharmony_ci bool mapped; 1228c2ecf20Sopenharmony_ci void *va; 1238c2ecf20Sopenharmony_ci u32 gfn[INTEL_GVT_OPREGION_PAGES]; 1248c2ecf20Sopenharmony_ci}; 1258c2ecf20Sopenharmony_ci 1268c2ecf20Sopenharmony_ci#define vgpu_opregion(vgpu) (&(vgpu->opregion)) 1278c2ecf20Sopenharmony_ci 1288c2ecf20Sopenharmony_cistruct intel_vgpu_display { 1298c2ecf20Sopenharmony_ci struct intel_vgpu_i2c_edid i2c_edid; 1308c2ecf20Sopenharmony_ci struct intel_vgpu_port ports[I915_MAX_PORTS]; 1318c2ecf20Sopenharmony_ci struct intel_vgpu_sbi sbi; 1328c2ecf20Sopenharmony_ci}; 1338c2ecf20Sopenharmony_ci 1348c2ecf20Sopenharmony_cistruct vgpu_sched_ctl { 1358c2ecf20Sopenharmony_ci int weight; 1368c2ecf20Sopenharmony_ci}; 1378c2ecf20Sopenharmony_ci 1388c2ecf20Sopenharmony_cienum { 1398c2ecf20Sopenharmony_ci INTEL_VGPU_EXECLIST_SUBMISSION = 1, 1408c2ecf20Sopenharmony_ci INTEL_VGPU_GUC_SUBMISSION, 1418c2ecf20Sopenharmony_ci}; 1428c2ecf20Sopenharmony_ci 1438c2ecf20Sopenharmony_cistruct intel_vgpu_submission_ops { 1448c2ecf20Sopenharmony_ci const char *name; 1458c2ecf20Sopenharmony_ci int (*init)(struct intel_vgpu *vgpu, intel_engine_mask_t engine_mask); 1468c2ecf20Sopenharmony_ci void (*clean)(struct intel_vgpu *vgpu, intel_engine_mask_t engine_mask); 1478c2ecf20Sopenharmony_ci void (*reset)(struct intel_vgpu *vgpu, intel_engine_mask_t engine_mask); 1488c2ecf20Sopenharmony_ci}; 1498c2ecf20Sopenharmony_ci 1508c2ecf20Sopenharmony_cistruct intel_vgpu_submission { 1518c2ecf20Sopenharmony_ci struct intel_vgpu_execlist execlist[I915_NUM_ENGINES]; 1528c2ecf20Sopenharmony_ci struct list_head workload_q_head[I915_NUM_ENGINES]; 1538c2ecf20Sopenharmony_ci struct intel_context *shadow[I915_NUM_ENGINES]; 1548c2ecf20Sopenharmony_ci struct kmem_cache *workloads; 1558c2ecf20Sopenharmony_ci atomic_t running_workload_num; 1568c2ecf20Sopenharmony_ci union { 1578c2ecf20Sopenharmony_ci u64 i915_context_pml4; 1588c2ecf20Sopenharmony_ci u64 i915_context_pdps[GEN8_3LVL_PDPES]; 1598c2ecf20Sopenharmony_ci }; 1608c2ecf20Sopenharmony_ci DECLARE_BITMAP(shadow_ctx_desc_updated, I915_NUM_ENGINES); 1618c2ecf20Sopenharmony_ci DECLARE_BITMAP(tlb_handle_pending, I915_NUM_ENGINES); 1628c2ecf20Sopenharmony_ci void *ring_scan_buffer[I915_NUM_ENGINES]; 1638c2ecf20Sopenharmony_ci int ring_scan_buffer_size[I915_NUM_ENGINES]; 1648c2ecf20Sopenharmony_ci const struct intel_vgpu_submission_ops *ops; 1658c2ecf20Sopenharmony_ci int virtual_submission_interface; 1668c2ecf20Sopenharmony_ci bool active; 1678c2ecf20Sopenharmony_ci struct { 1688c2ecf20Sopenharmony_ci u32 lrca; 1698c2ecf20Sopenharmony_ci bool valid; 1708c2ecf20Sopenharmony_ci u64 ring_context_gpa; 1718c2ecf20Sopenharmony_ci } last_ctx[I915_NUM_ENGINES]; 1728c2ecf20Sopenharmony_ci}; 1738c2ecf20Sopenharmony_ci 1748c2ecf20Sopenharmony_cistruct intel_vgpu { 1758c2ecf20Sopenharmony_ci struct intel_gvt *gvt; 1768c2ecf20Sopenharmony_ci struct mutex vgpu_lock; 1778c2ecf20Sopenharmony_ci int id; 1788c2ecf20Sopenharmony_ci unsigned long handle; /* vGPU handle used by hypervisor MPT modules */ 1798c2ecf20Sopenharmony_ci bool active; 1808c2ecf20Sopenharmony_ci bool pv_notified; 1818c2ecf20Sopenharmony_ci bool failsafe; 1828c2ecf20Sopenharmony_ci unsigned int resetting_eng; 1838c2ecf20Sopenharmony_ci 1848c2ecf20Sopenharmony_ci /* Both sched_data and sched_ctl can be seen a part of the global gvt 1858c2ecf20Sopenharmony_ci * scheduler structure. So below 2 vgpu data are protected 1868c2ecf20Sopenharmony_ci * by sched_lock, not vgpu_lock. 1878c2ecf20Sopenharmony_ci */ 1888c2ecf20Sopenharmony_ci void *sched_data; 1898c2ecf20Sopenharmony_ci struct vgpu_sched_ctl sched_ctl; 1908c2ecf20Sopenharmony_ci 1918c2ecf20Sopenharmony_ci struct intel_vgpu_fence fence; 1928c2ecf20Sopenharmony_ci struct intel_vgpu_gm gm; 1938c2ecf20Sopenharmony_ci struct intel_vgpu_cfg_space cfg_space; 1948c2ecf20Sopenharmony_ci struct intel_vgpu_mmio mmio; 1958c2ecf20Sopenharmony_ci struct intel_vgpu_irq irq; 1968c2ecf20Sopenharmony_ci struct intel_vgpu_gtt gtt; 1978c2ecf20Sopenharmony_ci struct intel_vgpu_opregion opregion; 1988c2ecf20Sopenharmony_ci struct intel_vgpu_display display; 1998c2ecf20Sopenharmony_ci struct intel_vgpu_submission submission; 2008c2ecf20Sopenharmony_ci struct radix_tree_root page_track_tree; 2018c2ecf20Sopenharmony_ci u32 hws_pga[I915_NUM_ENGINES]; 2028c2ecf20Sopenharmony_ci /* Set on PCI_D3, reset on DMLR, not reflecting the actual PM state */ 2038c2ecf20Sopenharmony_ci bool d3_entered; 2048c2ecf20Sopenharmony_ci 2058c2ecf20Sopenharmony_ci struct dentry *debugfs; 2068c2ecf20Sopenharmony_ci 2078c2ecf20Sopenharmony_ci /* Hypervisor-specific device state. */ 2088c2ecf20Sopenharmony_ci void *vdev; 2098c2ecf20Sopenharmony_ci 2108c2ecf20Sopenharmony_ci struct list_head dmabuf_obj_list_head; 2118c2ecf20Sopenharmony_ci struct mutex dmabuf_lock; 2128c2ecf20Sopenharmony_ci struct idr object_idr; 2138c2ecf20Sopenharmony_ci 2148c2ecf20Sopenharmony_ci u32 scan_nonprivbb; 2158c2ecf20Sopenharmony_ci}; 2168c2ecf20Sopenharmony_ci 2178c2ecf20Sopenharmony_cistatic inline void *intel_vgpu_vdev(struct intel_vgpu *vgpu) 2188c2ecf20Sopenharmony_ci{ 2198c2ecf20Sopenharmony_ci return vgpu->vdev; 2208c2ecf20Sopenharmony_ci} 2218c2ecf20Sopenharmony_ci 2228c2ecf20Sopenharmony_ci/* validating GM healthy status*/ 2238c2ecf20Sopenharmony_ci#define vgpu_is_vm_unhealthy(ret_val) \ 2248c2ecf20Sopenharmony_ci (((ret_val) == -EBADRQC) || ((ret_val) == -EFAULT)) 2258c2ecf20Sopenharmony_ci 2268c2ecf20Sopenharmony_cistruct intel_gvt_gm { 2278c2ecf20Sopenharmony_ci unsigned long vgpu_allocated_low_gm_size; 2288c2ecf20Sopenharmony_ci unsigned long vgpu_allocated_high_gm_size; 2298c2ecf20Sopenharmony_ci}; 2308c2ecf20Sopenharmony_ci 2318c2ecf20Sopenharmony_cistruct intel_gvt_fence { 2328c2ecf20Sopenharmony_ci unsigned long vgpu_allocated_fence_num; 2338c2ecf20Sopenharmony_ci}; 2348c2ecf20Sopenharmony_ci 2358c2ecf20Sopenharmony_ci/* Special MMIO blocks. */ 2368c2ecf20Sopenharmony_cistruct gvt_mmio_block { 2378c2ecf20Sopenharmony_ci unsigned int device; 2388c2ecf20Sopenharmony_ci i915_reg_t offset; 2398c2ecf20Sopenharmony_ci unsigned int size; 2408c2ecf20Sopenharmony_ci gvt_mmio_func read; 2418c2ecf20Sopenharmony_ci gvt_mmio_func write; 2428c2ecf20Sopenharmony_ci}; 2438c2ecf20Sopenharmony_ci 2448c2ecf20Sopenharmony_ci#define INTEL_GVT_MMIO_HASH_BITS 11 2458c2ecf20Sopenharmony_ci 2468c2ecf20Sopenharmony_cistruct intel_gvt_mmio { 2478c2ecf20Sopenharmony_ci u8 *mmio_attribute; 2488c2ecf20Sopenharmony_ci/* Register contains RO bits */ 2498c2ecf20Sopenharmony_ci#define F_RO (1 << 0) 2508c2ecf20Sopenharmony_ci/* Register contains graphics address */ 2518c2ecf20Sopenharmony_ci#define F_GMADR (1 << 1) 2528c2ecf20Sopenharmony_ci/* Mode mask registers with high 16 bits as the mask bits */ 2538c2ecf20Sopenharmony_ci#define F_MODE_MASK (1 << 2) 2548c2ecf20Sopenharmony_ci/* This reg can be accessed by GPU commands */ 2558c2ecf20Sopenharmony_ci#define F_CMD_ACCESS (1 << 3) 2568c2ecf20Sopenharmony_ci/* This reg has been accessed by a VM */ 2578c2ecf20Sopenharmony_ci#define F_ACCESSED (1 << 4) 2588c2ecf20Sopenharmony_ci/* This reg requires save & restore during host PM suspend/resume */ 2598c2ecf20Sopenharmony_ci#define F_PM_SAVE (1 << 5) 2608c2ecf20Sopenharmony_ci/* This reg could be accessed by unaligned address */ 2618c2ecf20Sopenharmony_ci#define F_UNALIGN (1 << 6) 2628c2ecf20Sopenharmony_ci/* This reg is in GVT's mmio save-restor list and in hardware 2638c2ecf20Sopenharmony_ci * logical context image 2648c2ecf20Sopenharmony_ci */ 2658c2ecf20Sopenharmony_ci#define F_SR_IN_CTX (1 << 7) 2668c2ecf20Sopenharmony_ci 2678c2ecf20Sopenharmony_ci struct gvt_mmio_block *mmio_block; 2688c2ecf20Sopenharmony_ci unsigned int num_mmio_block; 2698c2ecf20Sopenharmony_ci 2708c2ecf20Sopenharmony_ci DECLARE_HASHTABLE(mmio_info_table, INTEL_GVT_MMIO_HASH_BITS); 2718c2ecf20Sopenharmony_ci unsigned long num_tracked_mmio; 2728c2ecf20Sopenharmony_ci}; 2738c2ecf20Sopenharmony_ci 2748c2ecf20Sopenharmony_cistruct intel_gvt_firmware { 2758c2ecf20Sopenharmony_ci void *cfg_space; 2768c2ecf20Sopenharmony_ci void *mmio; 2778c2ecf20Sopenharmony_ci bool firmware_loaded; 2788c2ecf20Sopenharmony_ci}; 2798c2ecf20Sopenharmony_ci 2808c2ecf20Sopenharmony_ci#define NR_MAX_INTEL_VGPU_TYPES 20 2818c2ecf20Sopenharmony_cistruct intel_vgpu_type { 2828c2ecf20Sopenharmony_ci char name[16]; 2838c2ecf20Sopenharmony_ci unsigned int avail_instance; 2848c2ecf20Sopenharmony_ci unsigned int low_gm_size; 2858c2ecf20Sopenharmony_ci unsigned int high_gm_size; 2868c2ecf20Sopenharmony_ci unsigned int fence; 2878c2ecf20Sopenharmony_ci unsigned int weight; 2888c2ecf20Sopenharmony_ci enum intel_vgpu_edid resolution; 2898c2ecf20Sopenharmony_ci}; 2908c2ecf20Sopenharmony_ci 2918c2ecf20Sopenharmony_cistruct intel_gvt { 2928c2ecf20Sopenharmony_ci /* GVT scope lock, protect GVT itself, and all resource currently 2938c2ecf20Sopenharmony_ci * not yet protected by special locks(vgpu and scheduler lock). 2948c2ecf20Sopenharmony_ci */ 2958c2ecf20Sopenharmony_ci struct mutex lock; 2968c2ecf20Sopenharmony_ci /* scheduler scope lock, protect gvt and vgpu schedule related data */ 2978c2ecf20Sopenharmony_ci struct mutex sched_lock; 2988c2ecf20Sopenharmony_ci 2998c2ecf20Sopenharmony_ci struct intel_gt *gt; 3008c2ecf20Sopenharmony_ci struct idr vgpu_idr; /* vGPU IDR pool */ 3018c2ecf20Sopenharmony_ci 3028c2ecf20Sopenharmony_ci struct intel_gvt_device_info device_info; 3038c2ecf20Sopenharmony_ci struct intel_gvt_gm gm; 3048c2ecf20Sopenharmony_ci struct intel_gvt_fence fence; 3058c2ecf20Sopenharmony_ci struct intel_gvt_mmio mmio; 3068c2ecf20Sopenharmony_ci struct intel_gvt_firmware firmware; 3078c2ecf20Sopenharmony_ci struct intel_gvt_irq irq; 3088c2ecf20Sopenharmony_ci struct intel_gvt_gtt gtt; 3098c2ecf20Sopenharmony_ci struct intel_gvt_workload_scheduler scheduler; 3108c2ecf20Sopenharmony_ci struct notifier_block shadow_ctx_notifier_block[I915_NUM_ENGINES]; 3118c2ecf20Sopenharmony_ci DECLARE_HASHTABLE(cmd_table, GVT_CMD_HASH_BITS); 3128c2ecf20Sopenharmony_ci struct intel_vgpu_type *types; 3138c2ecf20Sopenharmony_ci unsigned int num_types; 3148c2ecf20Sopenharmony_ci struct intel_vgpu *idle_vgpu; 3158c2ecf20Sopenharmony_ci 3168c2ecf20Sopenharmony_ci struct task_struct *service_thread; 3178c2ecf20Sopenharmony_ci wait_queue_head_t service_thread_wq; 3188c2ecf20Sopenharmony_ci 3198c2ecf20Sopenharmony_ci /* service_request is always used in bit operation, we should always 3208c2ecf20Sopenharmony_ci * use it with atomic bit ops so that no need to use gvt big lock. 3218c2ecf20Sopenharmony_ci */ 3228c2ecf20Sopenharmony_ci unsigned long service_request; 3238c2ecf20Sopenharmony_ci 3248c2ecf20Sopenharmony_ci struct { 3258c2ecf20Sopenharmony_ci struct engine_mmio *mmio; 3268c2ecf20Sopenharmony_ci int ctx_mmio_count[I915_NUM_ENGINES]; 3278c2ecf20Sopenharmony_ci u32 *tlb_mmio_offset_list; 3288c2ecf20Sopenharmony_ci u32 tlb_mmio_offset_list_cnt; 3298c2ecf20Sopenharmony_ci u32 *mocs_mmio_offset_list; 3308c2ecf20Sopenharmony_ci u32 mocs_mmio_offset_list_cnt; 3318c2ecf20Sopenharmony_ci } engine_mmio_list; 3328c2ecf20Sopenharmony_ci 3338c2ecf20Sopenharmony_ci struct dentry *debugfs_root; 3348c2ecf20Sopenharmony_ci}; 3358c2ecf20Sopenharmony_ci 3368c2ecf20Sopenharmony_cistatic inline struct intel_gvt *to_gvt(struct drm_i915_private *i915) 3378c2ecf20Sopenharmony_ci{ 3388c2ecf20Sopenharmony_ci return i915->gvt; 3398c2ecf20Sopenharmony_ci} 3408c2ecf20Sopenharmony_ci 3418c2ecf20Sopenharmony_cienum { 3428c2ecf20Sopenharmony_ci INTEL_GVT_REQUEST_EMULATE_VBLANK = 0, 3438c2ecf20Sopenharmony_ci 3448c2ecf20Sopenharmony_ci /* Scheduling trigger by timer */ 3458c2ecf20Sopenharmony_ci INTEL_GVT_REQUEST_SCHED = 1, 3468c2ecf20Sopenharmony_ci 3478c2ecf20Sopenharmony_ci /* Scheduling trigger by event */ 3488c2ecf20Sopenharmony_ci INTEL_GVT_REQUEST_EVENT_SCHED = 2, 3498c2ecf20Sopenharmony_ci}; 3508c2ecf20Sopenharmony_ci 3518c2ecf20Sopenharmony_cistatic inline void intel_gvt_request_service(struct intel_gvt *gvt, 3528c2ecf20Sopenharmony_ci int service) 3538c2ecf20Sopenharmony_ci{ 3548c2ecf20Sopenharmony_ci set_bit(service, (void *)&gvt->service_request); 3558c2ecf20Sopenharmony_ci wake_up(&gvt->service_thread_wq); 3568c2ecf20Sopenharmony_ci} 3578c2ecf20Sopenharmony_ci 3588c2ecf20Sopenharmony_civoid intel_gvt_free_firmware(struct intel_gvt *gvt); 3598c2ecf20Sopenharmony_ciint intel_gvt_load_firmware(struct intel_gvt *gvt); 3608c2ecf20Sopenharmony_ci 3618c2ecf20Sopenharmony_ci/* Aperture/GM space definitions for GVT device */ 3628c2ecf20Sopenharmony_ci#define MB_TO_BYTES(mb) ((mb) << 20ULL) 3638c2ecf20Sopenharmony_ci#define BYTES_TO_MB(b) ((b) >> 20ULL) 3648c2ecf20Sopenharmony_ci 3658c2ecf20Sopenharmony_ci#define HOST_LOW_GM_SIZE MB_TO_BYTES(128) 3668c2ecf20Sopenharmony_ci#define HOST_HIGH_GM_SIZE MB_TO_BYTES(384) 3678c2ecf20Sopenharmony_ci#define HOST_FENCE 4 3688c2ecf20Sopenharmony_ci 3698c2ecf20Sopenharmony_ci#define gvt_to_ggtt(gvt) ((gvt)->gt->ggtt) 3708c2ecf20Sopenharmony_ci 3718c2ecf20Sopenharmony_ci/* Aperture/GM space definitions for GVT device */ 3728c2ecf20Sopenharmony_ci#define gvt_aperture_sz(gvt) gvt_to_ggtt(gvt)->mappable_end 3738c2ecf20Sopenharmony_ci#define gvt_aperture_pa_base(gvt) gvt_to_ggtt(gvt)->gmadr.start 3748c2ecf20Sopenharmony_ci 3758c2ecf20Sopenharmony_ci#define gvt_ggtt_gm_sz(gvt) gvt_to_ggtt(gvt)->vm.total 3768c2ecf20Sopenharmony_ci#define gvt_ggtt_sz(gvt) (gvt_to_ggtt(gvt)->vm.total >> PAGE_SHIFT << 3) 3778c2ecf20Sopenharmony_ci#define gvt_hidden_sz(gvt) (gvt_ggtt_gm_sz(gvt) - gvt_aperture_sz(gvt)) 3788c2ecf20Sopenharmony_ci 3798c2ecf20Sopenharmony_ci#define gvt_aperture_gmadr_base(gvt) (0) 3808c2ecf20Sopenharmony_ci#define gvt_aperture_gmadr_end(gvt) (gvt_aperture_gmadr_base(gvt) \ 3818c2ecf20Sopenharmony_ci + gvt_aperture_sz(gvt) - 1) 3828c2ecf20Sopenharmony_ci 3838c2ecf20Sopenharmony_ci#define gvt_hidden_gmadr_base(gvt) (gvt_aperture_gmadr_base(gvt) \ 3848c2ecf20Sopenharmony_ci + gvt_aperture_sz(gvt)) 3858c2ecf20Sopenharmony_ci#define gvt_hidden_gmadr_end(gvt) (gvt_hidden_gmadr_base(gvt) \ 3868c2ecf20Sopenharmony_ci + gvt_hidden_sz(gvt) - 1) 3878c2ecf20Sopenharmony_ci 3888c2ecf20Sopenharmony_ci#define gvt_fence_sz(gvt) (gvt_to_ggtt(gvt)->num_fences) 3898c2ecf20Sopenharmony_ci 3908c2ecf20Sopenharmony_ci/* Aperture/GM space definitions for vGPU */ 3918c2ecf20Sopenharmony_ci#define vgpu_aperture_offset(vgpu) ((vgpu)->gm.low_gm_node.start) 3928c2ecf20Sopenharmony_ci#define vgpu_hidden_offset(vgpu) ((vgpu)->gm.high_gm_node.start) 3938c2ecf20Sopenharmony_ci#define vgpu_aperture_sz(vgpu) ((vgpu)->gm.aperture_sz) 3948c2ecf20Sopenharmony_ci#define vgpu_hidden_sz(vgpu) ((vgpu)->gm.hidden_sz) 3958c2ecf20Sopenharmony_ci 3968c2ecf20Sopenharmony_ci#define vgpu_aperture_pa_base(vgpu) \ 3978c2ecf20Sopenharmony_ci (gvt_aperture_pa_base(vgpu->gvt) + vgpu_aperture_offset(vgpu)) 3988c2ecf20Sopenharmony_ci 3998c2ecf20Sopenharmony_ci#define vgpu_ggtt_gm_sz(vgpu) ((vgpu)->gm.aperture_sz + (vgpu)->gm.hidden_sz) 4008c2ecf20Sopenharmony_ci 4018c2ecf20Sopenharmony_ci#define vgpu_aperture_pa_end(vgpu) \ 4028c2ecf20Sopenharmony_ci (vgpu_aperture_pa_base(vgpu) + vgpu_aperture_sz(vgpu) - 1) 4038c2ecf20Sopenharmony_ci 4048c2ecf20Sopenharmony_ci#define vgpu_aperture_gmadr_base(vgpu) (vgpu_aperture_offset(vgpu)) 4058c2ecf20Sopenharmony_ci#define vgpu_aperture_gmadr_end(vgpu) \ 4068c2ecf20Sopenharmony_ci (vgpu_aperture_gmadr_base(vgpu) + vgpu_aperture_sz(vgpu) - 1) 4078c2ecf20Sopenharmony_ci 4088c2ecf20Sopenharmony_ci#define vgpu_hidden_gmadr_base(vgpu) (vgpu_hidden_offset(vgpu)) 4098c2ecf20Sopenharmony_ci#define vgpu_hidden_gmadr_end(vgpu) \ 4108c2ecf20Sopenharmony_ci (vgpu_hidden_gmadr_base(vgpu) + vgpu_hidden_sz(vgpu) - 1) 4118c2ecf20Sopenharmony_ci 4128c2ecf20Sopenharmony_ci#define vgpu_fence_base(vgpu) (vgpu->fence.base) 4138c2ecf20Sopenharmony_ci#define vgpu_fence_sz(vgpu) (vgpu->fence.size) 4148c2ecf20Sopenharmony_ci 4158c2ecf20Sopenharmony_cistruct intel_vgpu_creation_params { 4168c2ecf20Sopenharmony_ci __u64 handle; 4178c2ecf20Sopenharmony_ci __u64 low_gm_sz; /* in MB */ 4188c2ecf20Sopenharmony_ci __u64 high_gm_sz; /* in MB */ 4198c2ecf20Sopenharmony_ci __u64 fence_sz; 4208c2ecf20Sopenharmony_ci __u64 resolution; 4218c2ecf20Sopenharmony_ci __s32 primary; 4228c2ecf20Sopenharmony_ci __u64 vgpu_id; 4238c2ecf20Sopenharmony_ci 4248c2ecf20Sopenharmony_ci __u32 weight; 4258c2ecf20Sopenharmony_ci}; 4268c2ecf20Sopenharmony_ci 4278c2ecf20Sopenharmony_ciint intel_vgpu_alloc_resource(struct intel_vgpu *vgpu, 4288c2ecf20Sopenharmony_ci struct intel_vgpu_creation_params *param); 4298c2ecf20Sopenharmony_civoid intel_vgpu_reset_resource(struct intel_vgpu *vgpu); 4308c2ecf20Sopenharmony_civoid intel_vgpu_free_resource(struct intel_vgpu *vgpu); 4318c2ecf20Sopenharmony_civoid intel_vgpu_write_fence(struct intel_vgpu *vgpu, 4328c2ecf20Sopenharmony_ci u32 fence, u64 value); 4338c2ecf20Sopenharmony_ci 4348c2ecf20Sopenharmony_ci/* Macros for easily accessing vGPU virtual/shadow register. 4358c2ecf20Sopenharmony_ci Explicitly seperate use for typed MMIO reg or real offset.*/ 4368c2ecf20Sopenharmony_ci#define vgpu_vreg_t(vgpu, reg) \ 4378c2ecf20Sopenharmony_ci (*(u32 *)(vgpu->mmio.vreg + i915_mmio_reg_offset(reg))) 4388c2ecf20Sopenharmony_ci#define vgpu_vreg(vgpu, offset) \ 4398c2ecf20Sopenharmony_ci (*(u32 *)(vgpu->mmio.vreg + (offset))) 4408c2ecf20Sopenharmony_ci#define vgpu_vreg64_t(vgpu, reg) \ 4418c2ecf20Sopenharmony_ci (*(u64 *)(vgpu->mmio.vreg + i915_mmio_reg_offset(reg))) 4428c2ecf20Sopenharmony_ci#define vgpu_vreg64(vgpu, offset) \ 4438c2ecf20Sopenharmony_ci (*(u64 *)(vgpu->mmio.vreg + (offset))) 4448c2ecf20Sopenharmony_ci 4458c2ecf20Sopenharmony_ci#define for_each_active_vgpu(gvt, vgpu, id) \ 4468c2ecf20Sopenharmony_ci idr_for_each_entry((&(gvt)->vgpu_idr), (vgpu), (id)) \ 4478c2ecf20Sopenharmony_ci for_each_if(vgpu->active) 4488c2ecf20Sopenharmony_ci 4498c2ecf20Sopenharmony_cistatic inline void intel_vgpu_write_pci_bar(struct intel_vgpu *vgpu, 4508c2ecf20Sopenharmony_ci u32 offset, u32 val, bool low) 4518c2ecf20Sopenharmony_ci{ 4528c2ecf20Sopenharmony_ci u32 *pval; 4538c2ecf20Sopenharmony_ci 4548c2ecf20Sopenharmony_ci /* BAR offset should be 32 bits algiend */ 4558c2ecf20Sopenharmony_ci offset = rounddown(offset, 4); 4568c2ecf20Sopenharmony_ci pval = (u32 *)(vgpu_cfg_space(vgpu) + offset); 4578c2ecf20Sopenharmony_ci 4588c2ecf20Sopenharmony_ci if (low) { 4598c2ecf20Sopenharmony_ci /* 4608c2ecf20Sopenharmony_ci * only update bit 31 - bit 4, 4618c2ecf20Sopenharmony_ci * leave the bit 3 - bit 0 unchanged. 4628c2ecf20Sopenharmony_ci */ 4638c2ecf20Sopenharmony_ci *pval = (val & GENMASK(31, 4)) | (*pval & GENMASK(3, 0)); 4648c2ecf20Sopenharmony_ci } else { 4658c2ecf20Sopenharmony_ci *pval = val; 4668c2ecf20Sopenharmony_ci } 4678c2ecf20Sopenharmony_ci} 4688c2ecf20Sopenharmony_ci 4698c2ecf20Sopenharmony_ciint intel_gvt_init_vgpu_types(struct intel_gvt *gvt); 4708c2ecf20Sopenharmony_civoid intel_gvt_clean_vgpu_types(struct intel_gvt *gvt); 4718c2ecf20Sopenharmony_ci 4728c2ecf20Sopenharmony_cistruct intel_vgpu *intel_gvt_create_idle_vgpu(struct intel_gvt *gvt); 4738c2ecf20Sopenharmony_civoid intel_gvt_destroy_idle_vgpu(struct intel_vgpu *vgpu); 4748c2ecf20Sopenharmony_cistruct intel_vgpu *intel_gvt_create_vgpu(struct intel_gvt *gvt, 4758c2ecf20Sopenharmony_ci struct intel_vgpu_type *type); 4768c2ecf20Sopenharmony_civoid intel_gvt_destroy_vgpu(struct intel_vgpu *vgpu); 4778c2ecf20Sopenharmony_civoid intel_gvt_release_vgpu(struct intel_vgpu *vgpu); 4788c2ecf20Sopenharmony_civoid intel_gvt_reset_vgpu_locked(struct intel_vgpu *vgpu, bool dmlr, 4798c2ecf20Sopenharmony_ci intel_engine_mask_t engine_mask); 4808c2ecf20Sopenharmony_civoid intel_gvt_reset_vgpu(struct intel_vgpu *vgpu); 4818c2ecf20Sopenharmony_civoid intel_gvt_activate_vgpu(struct intel_vgpu *vgpu); 4828c2ecf20Sopenharmony_civoid intel_gvt_deactivate_vgpu(struct intel_vgpu *vgpu); 4838c2ecf20Sopenharmony_ci 4848c2ecf20Sopenharmony_ci/* validating GM functions */ 4858c2ecf20Sopenharmony_ci#define vgpu_gmadr_is_aperture(vgpu, gmadr) \ 4868c2ecf20Sopenharmony_ci ((gmadr >= vgpu_aperture_gmadr_base(vgpu)) && \ 4878c2ecf20Sopenharmony_ci (gmadr <= vgpu_aperture_gmadr_end(vgpu))) 4888c2ecf20Sopenharmony_ci 4898c2ecf20Sopenharmony_ci#define vgpu_gmadr_is_hidden(vgpu, gmadr) \ 4908c2ecf20Sopenharmony_ci ((gmadr >= vgpu_hidden_gmadr_base(vgpu)) && \ 4918c2ecf20Sopenharmony_ci (gmadr <= vgpu_hidden_gmadr_end(vgpu))) 4928c2ecf20Sopenharmony_ci 4938c2ecf20Sopenharmony_ci#define vgpu_gmadr_is_valid(vgpu, gmadr) \ 4948c2ecf20Sopenharmony_ci ((vgpu_gmadr_is_aperture(vgpu, gmadr) || \ 4958c2ecf20Sopenharmony_ci (vgpu_gmadr_is_hidden(vgpu, gmadr)))) 4968c2ecf20Sopenharmony_ci 4978c2ecf20Sopenharmony_ci#define gvt_gmadr_is_aperture(gvt, gmadr) \ 4988c2ecf20Sopenharmony_ci ((gmadr >= gvt_aperture_gmadr_base(gvt)) && \ 4998c2ecf20Sopenharmony_ci (gmadr <= gvt_aperture_gmadr_end(gvt))) 5008c2ecf20Sopenharmony_ci 5018c2ecf20Sopenharmony_ci#define gvt_gmadr_is_hidden(gvt, gmadr) \ 5028c2ecf20Sopenharmony_ci ((gmadr >= gvt_hidden_gmadr_base(gvt)) && \ 5038c2ecf20Sopenharmony_ci (gmadr <= gvt_hidden_gmadr_end(gvt))) 5048c2ecf20Sopenharmony_ci 5058c2ecf20Sopenharmony_ci#define gvt_gmadr_is_valid(gvt, gmadr) \ 5068c2ecf20Sopenharmony_ci (gvt_gmadr_is_aperture(gvt, gmadr) || \ 5078c2ecf20Sopenharmony_ci gvt_gmadr_is_hidden(gvt, gmadr)) 5088c2ecf20Sopenharmony_ci 5098c2ecf20Sopenharmony_cibool intel_gvt_ggtt_validate_range(struct intel_vgpu *vgpu, u64 addr, u32 size); 5108c2ecf20Sopenharmony_ciint intel_gvt_ggtt_gmadr_g2h(struct intel_vgpu *vgpu, u64 g_addr, u64 *h_addr); 5118c2ecf20Sopenharmony_ciint intel_gvt_ggtt_gmadr_h2g(struct intel_vgpu *vgpu, u64 h_addr, u64 *g_addr); 5128c2ecf20Sopenharmony_ciint intel_gvt_ggtt_index_g2h(struct intel_vgpu *vgpu, unsigned long g_index, 5138c2ecf20Sopenharmony_ci unsigned long *h_index); 5148c2ecf20Sopenharmony_ciint intel_gvt_ggtt_h2g_index(struct intel_vgpu *vgpu, unsigned long h_index, 5158c2ecf20Sopenharmony_ci unsigned long *g_index); 5168c2ecf20Sopenharmony_ci 5178c2ecf20Sopenharmony_civoid intel_vgpu_init_cfg_space(struct intel_vgpu *vgpu, 5188c2ecf20Sopenharmony_ci bool primary); 5198c2ecf20Sopenharmony_civoid intel_vgpu_reset_cfg_space(struct intel_vgpu *vgpu); 5208c2ecf20Sopenharmony_ci 5218c2ecf20Sopenharmony_ciint intel_vgpu_emulate_cfg_read(struct intel_vgpu *vgpu, unsigned int offset, 5228c2ecf20Sopenharmony_ci void *p_data, unsigned int bytes); 5238c2ecf20Sopenharmony_ci 5248c2ecf20Sopenharmony_ciint intel_vgpu_emulate_cfg_write(struct intel_vgpu *vgpu, unsigned int offset, 5258c2ecf20Sopenharmony_ci void *p_data, unsigned int bytes); 5268c2ecf20Sopenharmony_ci 5278c2ecf20Sopenharmony_civoid intel_vgpu_emulate_hotplug(struct intel_vgpu *vgpu, bool connected); 5288c2ecf20Sopenharmony_ci 5298c2ecf20Sopenharmony_cistatic inline u64 intel_vgpu_get_bar_gpa(struct intel_vgpu *vgpu, int bar) 5308c2ecf20Sopenharmony_ci{ 5318c2ecf20Sopenharmony_ci /* We are 64bit bar. */ 5328c2ecf20Sopenharmony_ci return (*(u64 *)(vgpu->cfg_space.virtual_cfg_space + bar)) & 5338c2ecf20Sopenharmony_ci PCI_BASE_ADDRESS_MEM_MASK; 5348c2ecf20Sopenharmony_ci} 5358c2ecf20Sopenharmony_ci 5368c2ecf20Sopenharmony_civoid intel_vgpu_clean_opregion(struct intel_vgpu *vgpu); 5378c2ecf20Sopenharmony_ciint intel_vgpu_init_opregion(struct intel_vgpu *vgpu); 5388c2ecf20Sopenharmony_ciint intel_vgpu_opregion_base_write_handler(struct intel_vgpu *vgpu, u32 gpa); 5398c2ecf20Sopenharmony_ci 5408c2ecf20Sopenharmony_ciint intel_vgpu_emulate_opregion_request(struct intel_vgpu *vgpu, u32 swsci); 5418c2ecf20Sopenharmony_civoid populate_pvinfo_page(struct intel_vgpu *vgpu); 5428c2ecf20Sopenharmony_ci 5438c2ecf20Sopenharmony_ciint intel_gvt_scan_and_shadow_workload(struct intel_vgpu_workload *workload); 5448c2ecf20Sopenharmony_civoid enter_failsafe_mode(struct intel_vgpu *vgpu, int reason); 5458c2ecf20Sopenharmony_ci 5468c2ecf20Sopenharmony_cistruct intel_gvt_ops { 5478c2ecf20Sopenharmony_ci int (*emulate_cfg_read)(struct intel_vgpu *, unsigned int, void *, 5488c2ecf20Sopenharmony_ci unsigned int); 5498c2ecf20Sopenharmony_ci int (*emulate_cfg_write)(struct intel_vgpu *, unsigned int, void *, 5508c2ecf20Sopenharmony_ci unsigned int); 5518c2ecf20Sopenharmony_ci int (*emulate_mmio_read)(struct intel_vgpu *, u64, void *, 5528c2ecf20Sopenharmony_ci unsigned int); 5538c2ecf20Sopenharmony_ci int (*emulate_mmio_write)(struct intel_vgpu *, u64, void *, 5548c2ecf20Sopenharmony_ci unsigned int); 5558c2ecf20Sopenharmony_ci struct intel_vgpu *(*vgpu_create)(struct intel_gvt *, 5568c2ecf20Sopenharmony_ci struct intel_vgpu_type *); 5578c2ecf20Sopenharmony_ci void (*vgpu_destroy)(struct intel_vgpu *vgpu); 5588c2ecf20Sopenharmony_ci void (*vgpu_release)(struct intel_vgpu *vgpu); 5598c2ecf20Sopenharmony_ci void (*vgpu_reset)(struct intel_vgpu *); 5608c2ecf20Sopenharmony_ci void (*vgpu_activate)(struct intel_vgpu *); 5618c2ecf20Sopenharmony_ci void (*vgpu_deactivate)(struct intel_vgpu *); 5628c2ecf20Sopenharmony_ci struct intel_vgpu_type *(*gvt_find_vgpu_type)(struct intel_gvt *gvt, 5638c2ecf20Sopenharmony_ci const char *name); 5648c2ecf20Sopenharmony_ci bool (*get_gvt_attrs)(struct attribute_group ***intel_vgpu_type_groups); 5658c2ecf20Sopenharmony_ci int (*vgpu_query_plane)(struct intel_vgpu *vgpu, void *); 5668c2ecf20Sopenharmony_ci int (*vgpu_get_dmabuf)(struct intel_vgpu *vgpu, unsigned int); 5678c2ecf20Sopenharmony_ci int (*write_protect_handler)(struct intel_vgpu *, u64, void *, 5688c2ecf20Sopenharmony_ci unsigned int); 5698c2ecf20Sopenharmony_ci void (*emulate_hotplug)(struct intel_vgpu *vgpu, bool connected); 5708c2ecf20Sopenharmony_ci}; 5718c2ecf20Sopenharmony_ci 5728c2ecf20Sopenharmony_ci 5738c2ecf20Sopenharmony_cienum { 5748c2ecf20Sopenharmony_ci GVT_FAILSAFE_UNSUPPORTED_GUEST, 5758c2ecf20Sopenharmony_ci GVT_FAILSAFE_INSUFFICIENT_RESOURCE, 5768c2ecf20Sopenharmony_ci GVT_FAILSAFE_GUEST_ERR, 5778c2ecf20Sopenharmony_ci}; 5788c2ecf20Sopenharmony_ci 5798c2ecf20Sopenharmony_cistatic inline void mmio_hw_access_pre(struct intel_gt *gt) 5808c2ecf20Sopenharmony_ci{ 5818c2ecf20Sopenharmony_ci intel_runtime_pm_get(gt->uncore->rpm); 5828c2ecf20Sopenharmony_ci} 5838c2ecf20Sopenharmony_ci 5848c2ecf20Sopenharmony_cistatic inline void mmio_hw_access_post(struct intel_gt *gt) 5858c2ecf20Sopenharmony_ci{ 5868c2ecf20Sopenharmony_ci intel_runtime_pm_put_unchecked(gt->uncore->rpm); 5878c2ecf20Sopenharmony_ci} 5888c2ecf20Sopenharmony_ci 5898c2ecf20Sopenharmony_ci/** 5908c2ecf20Sopenharmony_ci * intel_gvt_mmio_set_accessed - mark a MMIO has been accessed 5918c2ecf20Sopenharmony_ci * @gvt: a GVT device 5928c2ecf20Sopenharmony_ci * @offset: register offset 5938c2ecf20Sopenharmony_ci * 5948c2ecf20Sopenharmony_ci */ 5958c2ecf20Sopenharmony_cistatic inline void intel_gvt_mmio_set_accessed( 5968c2ecf20Sopenharmony_ci struct intel_gvt *gvt, unsigned int offset) 5978c2ecf20Sopenharmony_ci{ 5988c2ecf20Sopenharmony_ci gvt->mmio.mmio_attribute[offset >> 2] |= F_ACCESSED; 5998c2ecf20Sopenharmony_ci} 6008c2ecf20Sopenharmony_ci 6018c2ecf20Sopenharmony_ci/** 6028c2ecf20Sopenharmony_ci * intel_gvt_mmio_is_cmd_accessible - if a MMIO could be accessed by command 6038c2ecf20Sopenharmony_ci * @gvt: a GVT device 6048c2ecf20Sopenharmony_ci * @offset: register offset 6058c2ecf20Sopenharmony_ci * 6068c2ecf20Sopenharmony_ci * Returns: 6078c2ecf20Sopenharmony_ci * True if an MMIO is able to be accessed by GPU commands 6088c2ecf20Sopenharmony_ci */ 6098c2ecf20Sopenharmony_cistatic inline bool intel_gvt_mmio_is_cmd_accessible( 6108c2ecf20Sopenharmony_ci struct intel_gvt *gvt, unsigned int offset) 6118c2ecf20Sopenharmony_ci{ 6128c2ecf20Sopenharmony_ci return gvt->mmio.mmio_attribute[offset >> 2] & F_CMD_ACCESS; 6138c2ecf20Sopenharmony_ci} 6148c2ecf20Sopenharmony_ci 6158c2ecf20Sopenharmony_ci/** 6168c2ecf20Sopenharmony_ci * intel_gvt_mmio_set_cmd_accessible - 6178c2ecf20Sopenharmony_ci * mark a MMIO could be accessible by command 6188c2ecf20Sopenharmony_ci * @gvt: a GVT device 6198c2ecf20Sopenharmony_ci * @offset: register offset 6208c2ecf20Sopenharmony_ci * 6218c2ecf20Sopenharmony_ci */ 6228c2ecf20Sopenharmony_cistatic inline void intel_gvt_mmio_set_cmd_accessible( 6238c2ecf20Sopenharmony_ci struct intel_gvt *gvt, unsigned int offset) 6248c2ecf20Sopenharmony_ci{ 6258c2ecf20Sopenharmony_ci gvt->mmio.mmio_attribute[offset >> 2] |= F_CMD_ACCESS; 6268c2ecf20Sopenharmony_ci} 6278c2ecf20Sopenharmony_ci 6288c2ecf20Sopenharmony_ci/** 6298c2ecf20Sopenharmony_ci * intel_gvt_mmio_is_unalign - mark a MMIO could be accessed unaligned 6308c2ecf20Sopenharmony_ci * @gvt: a GVT device 6318c2ecf20Sopenharmony_ci * @offset: register offset 6328c2ecf20Sopenharmony_ci * 6338c2ecf20Sopenharmony_ci */ 6348c2ecf20Sopenharmony_cistatic inline bool intel_gvt_mmio_is_unalign( 6358c2ecf20Sopenharmony_ci struct intel_gvt *gvt, unsigned int offset) 6368c2ecf20Sopenharmony_ci{ 6378c2ecf20Sopenharmony_ci return gvt->mmio.mmio_attribute[offset >> 2] & F_UNALIGN; 6388c2ecf20Sopenharmony_ci} 6398c2ecf20Sopenharmony_ci 6408c2ecf20Sopenharmony_ci/** 6418c2ecf20Sopenharmony_ci * intel_gvt_mmio_has_mode_mask - if a MMIO has a mode mask 6428c2ecf20Sopenharmony_ci * @gvt: a GVT device 6438c2ecf20Sopenharmony_ci * @offset: register offset 6448c2ecf20Sopenharmony_ci * 6458c2ecf20Sopenharmony_ci * Returns: 6468c2ecf20Sopenharmony_ci * True if a MMIO has a mode mask in its higher 16 bits, false if it isn't. 6478c2ecf20Sopenharmony_ci * 6488c2ecf20Sopenharmony_ci */ 6498c2ecf20Sopenharmony_cistatic inline bool intel_gvt_mmio_has_mode_mask( 6508c2ecf20Sopenharmony_ci struct intel_gvt *gvt, unsigned int offset) 6518c2ecf20Sopenharmony_ci{ 6528c2ecf20Sopenharmony_ci return gvt->mmio.mmio_attribute[offset >> 2] & F_MODE_MASK; 6538c2ecf20Sopenharmony_ci} 6548c2ecf20Sopenharmony_ci 6558c2ecf20Sopenharmony_ci/** 6568c2ecf20Sopenharmony_ci * intel_gvt_mmio_is_sr_in_ctx - 6578c2ecf20Sopenharmony_ci * check if an MMIO has F_SR_IN_CTX mask 6588c2ecf20Sopenharmony_ci * @gvt: a GVT device 6598c2ecf20Sopenharmony_ci * @offset: register offset 6608c2ecf20Sopenharmony_ci * 6618c2ecf20Sopenharmony_ci * Returns: 6628c2ecf20Sopenharmony_ci * True if an MMIO has an F_SR_IN_CTX mask, false if it isn't. 6638c2ecf20Sopenharmony_ci * 6648c2ecf20Sopenharmony_ci */ 6658c2ecf20Sopenharmony_cistatic inline bool intel_gvt_mmio_is_sr_in_ctx( 6668c2ecf20Sopenharmony_ci struct intel_gvt *gvt, unsigned int offset) 6678c2ecf20Sopenharmony_ci{ 6688c2ecf20Sopenharmony_ci return gvt->mmio.mmio_attribute[offset >> 2] & F_SR_IN_CTX; 6698c2ecf20Sopenharmony_ci} 6708c2ecf20Sopenharmony_ci 6718c2ecf20Sopenharmony_ci/** 6728c2ecf20Sopenharmony_ci * intel_gvt_mmio_set_sr_in_ctx - 6738c2ecf20Sopenharmony_ci * mask an MMIO in GVT's mmio save-restore list and also 6748c2ecf20Sopenharmony_ci * in hardware logical context image 6758c2ecf20Sopenharmony_ci * @gvt: a GVT device 6768c2ecf20Sopenharmony_ci * @offset: register offset 6778c2ecf20Sopenharmony_ci * 6788c2ecf20Sopenharmony_ci */ 6798c2ecf20Sopenharmony_cistatic inline void intel_gvt_mmio_set_sr_in_ctx( 6808c2ecf20Sopenharmony_ci struct intel_gvt *gvt, unsigned int offset) 6818c2ecf20Sopenharmony_ci{ 6828c2ecf20Sopenharmony_ci gvt->mmio.mmio_attribute[offset >> 2] |= F_SR_IN_CTX; 6838c2ecf20Sopenharmony_ci} 6848c2ecf20Sopenharmony_ci 6858c2ecf20Sopenharmony_civoid intel_gvt_debugfs_add_vgpu(struct intel_vgpu *vgpu); 6868c2ecf20Sopenharmony_civoid intel_gvt_debugfs_remove_vgpu(struct intel_vgpu *vgpu); 6878c2ecf20Sopenharmony_civoid intel_gvt_debugfs_init(struct intel_gvt *gvt); 6888c2ecf20Sopenharmony_civoid intel_gvt_debugfs_clean(struct intel_gvt *gvt); 6898c2ecf20Sopenharmony_ci 6908c2ecf20Sopenharmony_ciint intel_gvt_pm_resume(struct intel_gvt *gvt); 6918c2ecf20Sopenharmony_ci 6928c2ecf20Sopenharmony_ci#include "trace.h" 6938c2ecf20Sopenharmony_ci#include "mpt.h" 6948c2ecf20Sopenharmony_ci 6958c2ecf20Sopenharmony_ci#endif 696