2 * Copyright(c) 2011-2016 Intel Corporation. All rights reserved.
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
11 * The above copyright notice and this permission notice (including the next
12 * paragraph) shall be included in all copies or substantial portions of the
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
36 #include <uapi/linux/pci_regs.h>
37 #include <linux/kvm_host.h>
38 #include <linux/vfio.h>
39 #include <linux/mdev.h>
42 #include "intel_gvt.h"
47 #include "interrupt.h"
52 #include "scheduler.h"
53 #include "sched_policy.h"
54 #include "mmio_context.h"
55 #include "cmd_parser.h"
56 #include "fb_decoder.h"
58 #include "page_track.h"
60 #define GVT_MAX_VGPU 8
62 /* Describe per-platform limitations. */
63 struct intel_gvt_device_info {
64 u32 max_support_vgpus;
68 unsigned long msi_cap_offset;
71 u32 gtt_entry_size_shift;
72 int gmadr_bytes_in_cmd;
76 /* GM resources owned by a vGPU */
77 struct intel_vgpu_gm {
80 struct drm_mm_node low_gm_node;
81 struct drm_mm_node high_gm_node;
84 #define INTEL_GVT_MAX_NUM_FENCES 32
86 /* Fences owned by a vGPU */
87 struct intel_vgpu_fence {
88 struct i915_fence_reg *regs[INTEL_GVT_MAX_NUM_FENCES];
93 struct intel_vgpu_mmio {
97 #define INTEL_GVT_MAX_BAR_NUM 4
99 struct intel_vgpu_pci_bar {
104 struct intel_vgpu_cfg_space {
105 unsigned char virtual_cfg_space[PCI_CFG_SPACE_EXP_SIZE];
106 struct intel_vgpu_pci_bar bar[INTEL_GVT_MAX_BAR_NUM];
110 #define vgpu_cfg_space(vgpu) ((vgpu)->cfg_space.virtual_cfg_space)
112 struct intel_vgpu_irq {
113 bool irq_warn_once[INTEL_GVT_EVENT_MAX];
114 DECLARE_BITMAP(flip_done_event[I915_MAX_PIPES],
115 INTEL_GVT_EVENT_MAX);
118 struct intel_vgpu_opregion {
121 u32 gfn[INTEL_GVT_OPREGION_PAGES];
124 #define vgpu_opregion(vgpu) (&(vgpu->opregion))
126 struct intel_vgpu_display {
127 struct intel_vgpu_i2c_edid i2c_edid;
128 struct intel_vgpu_port ports[I915_MAX_PORTS];
129 struct intel_vgpu_sbi sbi;
133 struct vgpu_sched_ctl {
138 INTEL_VGPU_EXECLIST_SUBMISSION = 1,
139 INTEL_VGPU_GUC_SUBMISSION,
142 struct intel_vgpu_submission_ops {
144 int (*init)(struct intel_vgpu *vgpu, intel_engine_mask_t engine_mask);
145 void (*clean)(struct intel_vgpu *vgpu, intel_engine_mask_t engine_mask);
146 void (*reset)(struct intel_vgpu *vgpu, intel_engine_mask_t engine_mask);
149 struct intel_vgpu_submission {
150 struct intel_vgpu_execlist execlist[I915_NUM_ENGINES];
151 struct list_head workload_q_head[I915_NUM_ENGINES];
152 struct intel_context *shadow[I915_NUM_ENGINES];
153 struct kmem_cache *workloads;
154 atomic_t running_workload_num;
156 u64 i915_context_pml4;
157 u64 i915_context_pdps[GEN8_3LVL_PDPES];
159 DECLARE_BITMAP(shadow_ctx_desc_updated, I915_NUM_ENGINES);
160 DECLARE_BITMAP(tlb_handle_pending, I915_NUM_ENGINES);
161 void *ring_scan_buffer[I915_NUM_ENGINES];
162 int ring_scan_buffer_size[I915_NUM_ENGINES];
163 const struct intel_vgpu_submission_ops *ops;
164 int virtual_submission_interface;
169 u64 ring_context_gpa;
170 } last_ctx[I915_NUM_ENGINES];
173 #define KVMGT_DEBUGFS_FILENAME "kvmgt_nr_cache_entries"
176 INTEL_VGPU_STATUS_ATTACHED = 0,
177 INTEL_VGPU_STATUS_ACTIVE,
178 INTEL_VGPU_STATUS_NR_BITS,
182 struct vfio_device vfio_device;
183 struct intel_gvt *gvt;
184 struct mutex vgpu_lock;
186 DECLARE_BITMAP(status, INTEL_VGPU_STATUS_NR_BITS);
189 unsigned int resetting_eng;
191 /* Both sched_data and sched_ctl can be seen a part of the global gvt
192 * scheduler structure. So below 2 vgpu data are protected
193 * by sched_lock, not vgpu_lock.
196 struct vgpu_sched_ctl sched_ctl;
198 struct intel_vgpu_fence fence;
199 struct intel_vgpu_gm gm;
200 struct intel_vgpu_cfg_space cfg_space;
201 struct intel_vgpu_mmio mmio;
202 struct intel_vgpu_irq irq;
203 struct intel_vgpu_gtt gtt;
204 struct intel_vgpu_opregion opregion;
205 struct intel_vgpu_display display;
206 struct intel_vgpu_submission submission;
207 struct radix_tree_root page_track_tree;
208 u32 hws_pga[I915_NUM_ENGINES];
209 /* Set on PCI_D3, reset on DMLR, not reflecting the actual PM state */
212 struct dentry *debugfs;
214 struct list_head dmabuf_obj_list_head;
215 struct mutex dmabuf_lock;
216 struct idr object_idr;
217 struct intel_vgpu_vblank_timer vblank_timer;
221 struct vfio_region *region;
223 struct eventfd_ctx *intx_trigger;
224 struct eventfd_ctx *msi_trigger;
227 * Two caches are used to avoid mapping duplicated pages (eg.
228 * scratch pages). This help to reduce dma setup overhead.
230 struct rb_root gfn_cache;
231 struct rb_root dma_addr_cache;
232 unsigned long nr_cache_entries;
233 struct mutex cache_lock;
235 struct kvm_page_track_notifier_node track_node;
236 #define NR_BKT (1 << 18)
237 struct hlist_head ptable[NR_BKT];
241 /* validating GM healthy status*/
242 #define vgpu_is_vm_unhealthy(ret_val) \
243 (((ret_val) == -EBADRQC) || ((ret_val) == -EFAULT))
245 struct intel_gvt_gm {
246 unsigned long vgpu_allocated_low_gm_size;
247 unsigned long vgpu_allocated_high_gm_size;
250 struct intel_gvt_fence {
251 unsigned long vgpu_allocated_fence_num;
254 /* Special MMIO blocks. */
255 struct gvt_mmio_block {
263 #define INTEL_GVT_MMIO_HASH_BITS 11
265 struct intel_gvt_mmio {
267 /* Register contains RO bits */
268 #define F_RO (1 << 0)
269 /* Register contains graphics address */
270 #define F_GMADR (1 << 1)
271 /* Mode mask registers with high 16 bits as the mask bits */
272 #define F_MODE_MASK (1 << 2)
273 /* This reg can be accessed by GPU commands */
274 #define F_CMD_ACCESS (1 << 3)
275 /* This reg has been accessed by a VM */
276 #define F_ACCESSED (1 << 4)
277 /* This reg requires save & restore during host PM suspend/resume */
278 #define F_PM_SAVE (1 << 5)
279 /* This reg could be accessed by unaligned address */
280 #define F_UNALIGN (1 << 6)
281 /* This reg is in GVT's mmio save-restor list and in hardware
282 * logical context image
284 #define F_SR_IN_CTX (1 << 7)
285 /* Value of command write of this reg needs to be patched */
286 #define F_CMD_WRITE_PATCH (1 << 8)
288 struct gvt_mmio_block *mmio_block;
289 unsigned int num_mmio_block;
291 DECLARE_HASHTABLE(mmio_info_table, INTEL_GVT_MMIO_HASH_BITS);
292 unsigned long num_tracked_mmio;
295 struct intel_gvt_firmware {
298 bool firmware_loaded;
301 struct intel_vgpu_config {
303 unsigned int high_mm;
307 * A vGPU with a weight of 8 will get twice as much GPU as a vGPU with
308 * a weight of 4 on a contended host, different vGPU type has different
309 * weight set. Legal weights range from 1 to 16.
312 enum intel_vgpu_edid edid;
316 struct intel_vgpu_type {
317 struct mdev_type type;
319 const struct intel_vgpu_config *conf;
323 /* GVT scope lock, protect GVT itself, and all resource currently
324 * not yet protected by special locks(vgpu and scheduler lock).
327 /* scheduler scope lock, protect gvt and vgpu schedule related data */
328 struct mutex sched_lock;
331 struct idr vgpu_idr; /* vGPU IDR pool */
333 struct intel_gvt_device_info device_info;
334 struct intel_gvt_gm gm;
335 struct intel_gvt_fence fence;
336 struct intel_gvt_mmio mmio;
337 struct intel_gvt_firmware firmware;
338 struct intel_gvt_irq irq;
339 struct intel_gvt_gtt gtt;
340 struct intel_gvt_workload_scheduler scheduler;
341 struct notifier_block shadow_ctx_notifier_block[I915_NUM_ENGINES];
342 DECLARE_HASHTABLE(cmd_table, GVT_CMD_HASH_BITS);
343 struct mdev_parent parent;
344 struct mdev_type **mdev_types;
345 struct intel_vgpu_type *types;
346 unsigned int num_types;
347 struct intel_vgpu *idle_vgpu;
349 struct task_struct *service_thread;
350 wait_queue_head_t service_thread_wq;
352 /* service_request is always used in bit operation, we should always
353 * use it with atomic bit ops so that no need to use gvt big lock.
355 unsigned long service_request;
358 struct engine_mmio *mmio;
359 int ctx_mmio_count[I915_NUM_ENGINES];
360 u32 *tlb_mmio_offset_list;
361 u32 tlb_mmio_offset_list_cnt;
362 u32 *mocs_mmio_offset_list;
363 u32 mocs_mmio_offset_list_cnt;
365 bool is_reg_whitelist_updated;
367 struct dentry *debugfs_root;
370 static inline struct intel_gvt *to_gvt(struct drm_i915_private *i915)
376 /* Scheduling trigger by timer */
377 INTEL_GVT_REQUEST_SCHED = 0,
379 /* Scheduling trigger by event */
380 INTEL_GVT_REQUEST_EVENT_SCHED = 1,
382 /* per-vGPU vblank emulation request */
383 INTEL_GVT_REQUEST_EMULATE_VBLANK = 2,
384 INTEL_GVT_REQUEST_EMULATE_VBLANK_MAX = INTEL_GVT_REQUEST_EMULATE_VBLANK
388 static inline void intel_gvt_request_service(struct intel_gvt *gvt,
391 set_bit(service, (void *)&gvt->service_request);
392 wake_up(&gvt->service_thread_wq);
395 void intel_gvt_free_firmware(struct intel_gvt *gvt);
396 int intel_gvt_load_firmware(struct intel_gvt *gvt);
398 /* Aperture/GM space definitions for GVT device */
399 #define MB_TO_BYTES(mb) ((mb) << 20ULL)
400 #define BYTES_TO_MB(b) ((b) >> 20ULL)
402 #define HOST_LOW_GM_SIZE MB_TO_BYTES(128)
403 #define HOST_HIGH_GM_SIZE MB_TO_BYTES(384)
406 #define gvt_to_ggtt(gvt) ((gvt)->gt->ggtt)
408 /* Aperture/GM space definitions for GVT device */
409 #define gvt_aperture_sz(gvt) gvt_to_ggtt(gvt)->mappable_end
410 #define gvt_aperture_pa_base(gvt) gvt_to_ggtt(gvt)->gmadr.start
412 #define gvt_ggtt_gm_sz(gvt) gvt_to_ggtt(gvt)->vm.total
413 #define gvt_ggtt_sz(gvt) (gvt_to_ggtt(gvt)->vm.total >> PAGE_SHIFT << 3)
414 #define gvt_hidden_sz(gvt) (gvt_ggtt_gm_sz(gvt) - gvt_aperture_sz(gvt))
416 #define gvt_aperture_gmadr_base(gvt) (0)
417 #define gvt_aperture_gmadr_end(gvt) (gvt_aperture_gmadr_base(gvt) \
418 + gvt_aperture_sz(gvt) - 1)
420 #define gvt_hidden_gmadr_base(gvt) (gvt_aperture_gmadr_base(gvt) \
421 + gvt_aperture_sz(gvt))
422 #define gvt_hidden_gmadr_end(gvt) (gvt_hidden_gmadr_base(gvt) \
423 + gvt_hidden_sz(gvt) - 1)
425 #define gvt_fence_sz(gvt) (gvt_to_ggtt(gvt)->num_fences)
427 /* Aperture/GM space definitions for vGPU */
428 #define vgpu_aperture_offset(vgpu) ((vgpu)->gm.low_gm_node.start)
429 #define vgpu_hidden_offset(vgpu) ((vgpu)->gm.high_gm_node.start)
430 #define vgpu_aperture_sz(vgpu) ((vgpu)->gm.aperture_sz)
431 #define vgpu_hidden_sz(vgpu) ((vgpu)->gm.hidden_sz)
433 #define vgpu_aperture_pa_base(vgpu) \
434 (gvt_aperture_pa_base(vgpu->gvt) + vgpu_aperture_offset(vgpu))
436 #define vgpu_ggtt_gm_sz(vgpu) ((vgpu)->gm.aperture_sz + (vgpu)->gm.hidden_sz)
438 #define vgpu_aperture_pa_end(vgpu) \
439 (vgpu_aperture_pa_base(vgpu) + vgpu_aperture_sz(vgpu) - 1)
441 #define vgpu_aperture_gmadr_base(vgpu) (vgpu_aperture_offset(vgpu))
442 #define vgpu_aperture_gmadr_end(vgpu) \
443 (vgpu_aperture_gmadr_base(vgpu) + vgpu_aperture_sz(vgpu) - 1)
445 #define vgpu_hidden_gmadr_base(vgpu) (vgpu_hidden_offset(vgpu))
446 #define vgpu_hidden_gmadr_end(vgpu) \
447 (vgpu_hidden_gmadr_base(vgpu) + vgpu_hidden_sz(vgpu) - 1)
449 #define vgpu_fence_base(vgpu) (vgpu->fence.base)
450 #define vgpu_fence_sz(vgpu) (vgpu->fence.size)
452 /* ring context size i.e. the first 0x50 dwords*/
453 #define RING_CTX_SIZE 320
455 int intel_vgpu_alloc_resource(struct intel_vgpu *vgpu,
456 const struct intel_vgpu_config *conf);
457 void intel_vgpu_reset_resource(struct intel_vgpu *vgpu);
458 void intel_vgpu_free_resource(struct intel_vgpu *vgpu);
459 void intel_vgpu_write_fence(struct intel_vgpu *vgpu,
460 u32 fence, u64 value);
462 /* Macros for easily accessing vGPU virtual/shadow register.
463 Explicitly seperate use for typed MMIO reg or real offset.*/
464 #define vgpu_vreg_t(vgpu, reg) \
465 (*(u32 *)(vgpu->mmio.vreg + i915_mmio_reg_offset(reg)))
466 #define vgpu_vreg(vgpu, offset) \
467 (*(u32 *)(vgpu->mmio.vreg + (offset)))
468 #define vgpu_vreg64_t(vgpu, reg) \
469 (*(u64 *)(vgpu->mmio.vreg + i915_mmio_reg_offset(reg)))
470 #define vgpu_vreg64(vgpu, offset) \
471 (*(u64 *)(vgpu->mmio.vreg + (offset)))
473 #define for_each_active_vgpu(gvt, vgpu, id) \
474 idr_for_each_entry((&(gvt)->vgpu_idr), (vgpu), (id)) \
475 for_each_if(test_bit(INTEL_VGPU_STATUS_ACTIVE, vgpu->status))
477 static inline void intel_vgpu_write_pci_bar(struct intel_vgpu *vgpu,
478 u32 offset, u32 val, bool low)
482 /* BAR offset should be 32 bits algiend */
483 offset = rounddown(offset, 4);
484 pval = (u32 *)(vgpu_cfg_space(vgpu) + offset);
488 * only update bit 31 - bit 4,
489 * leave the bit 3 - bit 0 unchanged.
491 *pval = (val & GENMASK(31, 4)) | (*pval & GENMASK(3, 0));
497 int intel_gvt_init_vgpu_types(struct intel_gvt *gvt);
498 void intel_gvt_clean_vgpu_types(struct intel_gvt *gvt);
500 struct intel_vgpu *intel_gvt_create_idle_vgpu(struct intel_gvt *gvt);
501 void intel_gvt_destroy_idle_vgpu(struct intel_vgpu *vgpu);
502 int intel_gvt_create_vgpu(struct intel_vgpu *vgpu,
503 const struct intel_vgpu_config *conf);
504 void intel_gvt_destroy_vgpu(struct intel_vgpu *vgpu);
505 void intel_gvt_release_vgpu(struct intel_vgpu *vgpu);
506 void intel_gvt_reset_vgpu_locked(struct intel_vgpu *vgpu, bool dmlr,
507 intel_engine_mask_t engine_mask);
508 void intel_gvt_reset_vgpu(struct intel_vgpu *vgpu);
509 void intel_gvt_activate_vgpu(struct intel_vgpu *vgpu);
510 void intel_gvt_deactivate_vgpu(struct intel_vgpu *vgpu);
512 int intel_gvt_set_opregion(struct intel_vgpu *vgpu);
513 int intel_gvt_set_edid(struct intel_vgpu *vgpu, int port_num);
515 /* validating GM functions */
516 #define vgpu_gmadr_is_aperture(vgpu, gmadr) \
517 ((gmadr >= vgpu_aperture_gmadr_base(vgpu)) && \
518 (gmadr <= vgpu_aperture_gmadr_end(vgpu)))
520 #define vgpu_gmadr_is_hidden(vgpu, gmadr) \
521 ((gmadr >= vgpu_hidden_gmadr_base(vgpu)) && \
522 (gmadr <= vgpu_hidden_gmadr_end(vgpu)))
524 #define vgpu_gmadr_is_valid(vgpu, gmadr) \
525 ((vgpu_gmadr_is_aperture(vgpu, gmadr) || \
526 (vgpu_gmadr_is_hidden(vgpu, gmadr))))
528 #define gvt_gmadr_is_aperture(gvt, gmadr) \
529 ((gmadr >= gvt_aperture_gmadr_base(gvt)) && \
530 (gmadr <= gvt_aperture_gmadr_end(gvt)))
532 #define gvt_gmadr_is_hidden(gvt, gmadr) \
533 ((gmadr >= gvt_hidden_gmadr_base(gvt)) && \
534 (gmadr <= gvt_hidden_gmadr_end(gvt)))
536 #define gvt_gmadr_is_valid(gvt, gmadr) \
537 (gvt_gmadr_is_aperture(gvt, gmadr) || \
538 gvt_gmadr_is_hidden(gvt, gmadr))
540 bool intel_gvt_ggtt_validate_range(struct intel_vgpu *vgpu, u64 addr, u32 size);
541 int intel_gvt_ggtt_gmadr_g2h(struct intel_vgpu *vgpu, u64 g_addr, u64 *h_addr);
542 int intel_gvt_ggtt_gmadr_h2g(struct intel_vgpu *vgpu, u64 h_addr, u64 *g_addr);
543 int intel_gvt_ggtt_index_g2h(struct intel_vgpu *vgpu, unsigned long g_index,
544 unsigned long *h_index);
545 int intel_gvt_ggtt_h2g_index(struct intel_vgpu *vgpu, unsigned long h_index,
546 unsigned long *g_index);
548 void intel_vgpu_init_cfg_space(struct intel_vgpu *vgpu,
550 void intel_vgpu_reset_cfg_space(struct intel_vgpu *vgpu);
552 int intel_vgpu_emulate_cfg_read(struct intel_vgpu *vgpu, unsigned int offset,
553 void *p_data, unsigned int bytes);
555 int intel_vgpu_emulate_cfg_write(struct intel_vgpu *vgpu, unsigned int offset,
556 void *p_data, unsigned int bytes);
558 void intel_vgpu_emulate_hotplug(struct intel_vgpu *vgpu, bool connected);
560 static inline u64 intel_vgpu_get_bar_gpa(struct intel_vgpu *vgpu, int bar)
562 /* We are 64bit bar. */
563 return (*(u64 *)(vgpu->cfg_space.virtual_cfg_space + bar)) &
564 PCI_BASE_ADDRESS_MEM_MASK;
567 void intel_vgpu_clean_opregion(struct intel_vgpu *vgpu);
568 int intel_vgpu_init_opregion(struct intel_vgpu *vgpu);
569 int intel_vgpu_opregion_base_write_handler(struct intel_vgpu *vgpu, u32 gpa);
571 int intel_vgpu_emulate_opregion_request(struct intel_vgpu *vgpu, u32 swsci);
572 void populate_pvinfo_page(struct intel_vgpu *vgpu);
574 int intel_gvt_scan_and_shadow_workload(struct intel_vgpu_workload *workload);
575 void enter_failsafe_mode(struct intel_vgpu *vgpu, int reason);
576 void intel_vgpu_detach_regions(struct intel_vgpu *vgpu);
579 GVT_FAILSAFE_UNSUPPORTED_GUEST,
580 GVT_FAILSAFE_INSUFFICIENT_RESOURCE,
581 GVT_FAILSAFE_GUEST_ERR,
584 static inline void mmio_hw_access_pre(struct intel_gt *gt)
586 intel_runtime_pm_get(gt->uncore->rpm);
589 static inline void mmio_hw_access_post(struct intel_gt *gt)
591 intel_runtime_pm_put_unchecked(gt->uncore->rpm);
595 * intel_gvt_mmio_set_accessed - mark a MMIO has been accessed
597 * @offset: register offset
600 static inline void intel_gvt_mmio_set_accessed(
601 struct intel_gvt *gvt, unsigned int offset)
603 gvt->mmio.mmio_attribute[offset >> 2] |= F_ACCESSED;
607 * intel_gvt_mmio_is_cmd_accessible - if a MMIO could be accessed by command
609 * @offset: register offset
612 * True if an MMIO is able to be accessed by GPU commands
614 static inline bool intel_gvt_mmio_is_cmd_accessible(
615 struct intel_gvt *gvt, unsigned int offset)
617 return gvt->mmio.mmio_attribute[offset >> 2] & F_CMD_ACCESS;
621 * intel_gvt_mmio_set_cmd_accessible -
622 * mark a MMIO could be accessible by command
624 * @offset: register offset
627 static inline void intel_gvt_mmio_set_cmd_accessible(
628 struct intel_gvt *gvt, unsigned int offset)
630 gvt->mmio.mmio_attribute[offset >> 2] |= F_CMD_ACCESS;
634 * intel_gvt_mmio_is_unalign - mark a MMIO could be accessed unaligned
636 * @offset: register offset
639 static inline bool intel_gvt_mmio_is_unalign(
640 struct intel_gvt *gvt, unsigned int offset)
642 return gvt->mmio.mmio_attribute[offset >> 2] & F_UNALIGN;
646 * intel_gvt_mmio_has_mode_mask - if a MMIO has a mode mask
648 * @offset: register offset
651 * True if a MMIO has a mode mask in its higher 16 bits, false if it isn't.
654 static inline bool intel_gvt_mmio_has_mode_mask(
655 struct intel_gvt *gvt, unsigned int offset)
657 return gvt->mmio.mmio_attribute[offset >> 2] & F_MODE_MASK;
661 * intel_gvt_mmio_is_sr_in_ctx -
662 * check if an MMIO has F_SR_IN_CTX mask
664 * @offset: register offset
667 * True if an MMIO has an F_SR_IN_CTX mask, false if it isn't.
670 static inline bool intel_gvt_mmio_is_sr_in_ctx(
671 struct intel_gvt *gvt, unsigned int offset)
673 return gvt->mmio.mmio_attribute[offset >> 2] & F_SR_IN_CTX;
677 * intel_gvt_mmio_set_sr_in_ctx -
678 * mask an MMIO in GVT's mmio save-restore list and also
679 * in hardware logical context image
681 * @offset: register offset
684 static inline void intel_gvt_mmio_set_sr_in_ctx(
685 struct intel_gvt *gvt, unsigned int offset)
687 gvt->mmio.mmio_attribute[offset >> 2] |= F_SR_IN_CTX;
690 void intel_gvt_debugfs_add_vgpu(struct intel_vgpu *vgpu);
692 * intel_gvt_mmio_set_cmd_write_patch -
693 * mark an MMIO if its cmd write needs to be
696 * @offset: register offset
699 static inline void intel_gvt_mmio_set_cmd_write_patch(
700 struct intel_gvt *gvt, unsigned int offset)
702 gvt->mmio.mmio_attribute[offset >> 2] |= F_CMD_WRITE_PATCH;
706 * intel_gvt_mmio_is_cmd_write_patch - check if an mmio's cmd access needs to
709 * @offset: register offset
712 * True if GPU commmand write to an MMIO should be patched
714 static inline bool intel_gvt_mmio_is_cmd_write_patch(
715 struct intel_gvt *gvt, unsigned int offset)
717 return gvt->mmio.mmio_attribute[offset >> 2] & F_CMD_WRITE_PATCH;
721 * intel_gvt_read_gpa - copy data from GPA to host data buffer
723 * @gpa: guest physical address
724 * @buf: host data buffer
728 * Zero on success, negative error code if failed.
730 static inline int intel_gvt_read_gpa(struct intel_vgpu *vgpu, unsigned long gpa,
731 void *buf, unsigned long len)
733 if (!test_bit(INTEL_VGPU_STATUS_ATTACHED, vgpu->status))
735 return vfio_dma_rw(&vgpu->vfio_device, gpa, buf, len, false);
739 * intel_gvt_write_gpa - copy data from host data buffer to GPA
741 * @gpa: guest physical address
742 * @buf: host data buffer
746 * Zero on success, negative error code if failed.
748 static inline int intel_gvt_write_gpa(struct intel_vgpu *vgpu,
749 unsigned long gpa, void *buf, unsigned long len)
751 if (!test_bit(INTEL_VGPU_STATUS_ATTACHED, vgpu->status))
753 return vfio_dma_rw(&vgpu->vfio_device, gpa, buf, len, true);
756 void intel_gvt_debugfs_remove_vgpu(struct intel_vgpu *vgpu);
757 void intel_gvt_debugfs_init(struct intel_gvt *gvt);
758 void intel_gvt_debugfs_clean(struct intel_gvt *gvt);
760 int intel_gvt_page_track_add(struct intel_vgpu *info, u64 gfn);
761 int intel_gvt_page_track_remove(struct intel_vgpu *info, u64 gfn);
762 int intel_gvt_dma_pin_guest_page(struct intel_vgpu *vgpu, dma_addr_t dma_addr);
763 int intel_gvt_dma_map_guest_page(struct intel_vgpu *vgpu, unsigned long gfn,
764 unsigned long size, dma_addr_t *dma_addr);
765 void intel_gvt_dma_unmap_guest_page(struct intel_vgpu *vgpu,
766 dma_addr_t dma_addr);