Zhi Wang | 0ad35fe | 2016-06-16 08:07:00 -0400 | [diff] [blame] | 1 | /* |
| 2 | * Copyright(c) 2011-2016 Intel Corporation. All rights reserved. |
| 3 | * |
| 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: |
| 10 | * |
| 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 |
| 13 | * Software. |
| 14 | * |
| 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 |
| 21 | * SOFTWARE. |
Zhi Wang | 82d375d | 2016-07-05 12:40:49 -0400 | [diff] [blame] | 22 | * |
| 23 | * Authors: |
| 24 | * Eddie Dong <eddie.dong@intel.com> |
| 25 | * Dexuan Cui |
| 26 | * Jike Song <jike.song@intel.com> |
| 27 | * |
| 28 | * Contributors: |
| 29 | * Zhi Wang <zhi.a.wang@intel.com> |
| 30 | * |
Zhi Wang | 0ad35fe | 2016-06-16 08:07:00 -0400 | [diff] [blame] | 31 | */ |
| 32 | |
| 33 | #ifndef _GVT_MPT_H_ |
| 34 | #define _GVT_MPT_H_ |
| 35 | |
| 36 | /** |
| 37 | * DOC: Hypervisor Service APIs for GVT-g Core Logic |
| 38 | * |
| 39 | * This is the glue layer between specific hypervisor MPT modules and GVT-g core |
| 40 | * logic. Each kind of hypervisor MPT module provides a collection of function |
| 41 | * callbacks and will be attached to GVT host when the driver is loading. |
| 42 | * GVT-g core logic will call these APIs to request specific services from |
| 43 | * hypervisor. |
| 44 | */ |
| 45 | |
| 46 | /** |
| 47 | * intel_gvt_hypervisor_detect_host - check if GVT-g is running within |
| 48 | * hypervisor host/privilged domain |
| 49 | * |
| 50 | * Returns: |
| 51 | * Zero on success, -ENODEV if current kernel is running inside a VM |
| 52 | */ |
| 53 | static inline int intel_gvt_hypervisor_detect_host(void) |
| 54 | { |
| 55 | return intel_gvt_host.mpt->detect_host(); |
| 56 | } |
| 57 | |
Zhi Wang | 82d375d | 2016-07-05 12:40:49 -0400 | [diff] [blame] | 58 | /** |
| 59 | * intel_gvt_hypervisor_attach_vgpu - call hypervisor to initialize vGPU |
| 60 | * related stuffs inside hypervisor. |
| 61 | * |
| 62 | * Returns: |
| 63 | * Zero on success, negative error code if failed. |
| 64 | */ |
| 65 | static inline int intel_gvt_hypervisor_attach_vgpu(struct intel_vgpu *vgpu) |
| 66 | { |
| 67 | return intel_gvt_host.mpt->attach_vgpu(vgpu, &vgpu->handle); |
| 68 | } |
| 69 | |
| 70 | /** |
| 71 | * intel_gvt_hypervisor_detach_vgpu - call hypervisor to release vGPU |
| 72 | * related stuffs inside hypervisor. |
| 73 | * |
| 74 | * Returns: |
| 75 | * Zero on success, negative error code if failed. |
| 76 | */ |
| 77 | static inline void intel_gvt_hypervisor_detach_vgpu(struct intel_vgpu *vgpu) |
| 78 | { |
| 79 | intel_gvt_host.mpt->detach_vgpu(vgpu->handle); |
| 80 | } |
| 81 | |
Zhi Wang | c8fe6a68 | 2015-09-17 09:22:08 +0800 | [diff] [blame^] | 82 | #define MSI_CAP_CONTROL(offset) (offset + 2) |
| 83 | #define MSI_CAP_ADDRESS(offset) (offset + 4) |
| 84 | #define MSI_CAP_DATA(offset) (offset + 8) |
| 85 | #define MSI_CAP_EN 0x1 |
| 86 | |
| 87 | /** |
| 88 | * intel_gvt_hypervisor_inject_msi - inject a MSI interrupt into vGPU |
| 89 | * |
| 90 | * Returns: |
| 91 | * Zero on success, negative error code if failed. |
| 92 | */ |
| 93 | static inline int intel_gvt_hypervisor_inject_msi(struct intel_vgpu *vgpu) |
| 94 | { |
| 95 | unsigned long offset = vgpu->gvt->device_info.msi_cap_offset; |
| 96 | u16 control, data; |
| 97 | u32 addr; |
| 98 | int ret; |
| 99 | |
| 100 | control = *(u16 *)(vgpu_cfg_space(vgpu) + MSI_CAP_CONTROL(offset)); |
| 101 | addr = *(u32 *)(vgpu_cfg_space(vgpu) + MSI_CAP_ADDRESS(offset)); |
| 102 | data = *(u16 *)(vgpu_cfg_space(vgpu) + MSI_CAP_DATA(offset)); |
| 103 | |
| 104 | /* Do not generate MSI if MSIEN is disable */ |
| 105 | if (!(control & MSI_CAP_EN)) |
| 106 | return 0; |
| 107 | |
| 108 | if (WARN(control & GENMASK(15, 1), "only support one MSI format\n")) |
| 109 | return -EINVAL; |
| 110 | |
| 111 | gvt_dbg_irq("vgpu%d: inject msi address %x data%x\n", vgpu->id, addr, |
| 112 | data); |
| 113 | |
| 114 | ret = intel_gvt_host.mpt->inject_msi(vgpu->handle, addr, data); |
| 115 | if (ret) |
| 116 | return ret; |
| 117 | return 0; |
| 118 | } |
| 119 | |
Zhi Wang | 0ad35fe | 2016-06-16 08:07:00 -0400 | [diff] [blame] | 120 | #endif /* _GVT_MPT_H_ */ |