Commit cfdd30b4 authored by Rodrigo Vivi's avatar Rodrigo Vivi

Merge tag 'gvt-next-2020-02-26' of https://github.com/intel/gvt-linux into drm-intel-next-queued

gvt-next-2020-02-26

- Enable VFIO edid for all platform (Zhenyu)
- Code cleanup for attr group and unused vblank complete (Zhenyu, Julian)
- Make gvt oblivious of kvmgt data structures (Julian)
- Make WARN* drm specific (Pankaj)
Signed-off-by: default avatarRodrigo Vivi <rodrigo.vivi@intel.com>
From: Zhenyu Wang <zhenyuw@linux.intel.com>
Link: https://patchwork.freedesktop.org/patch/msgid/20200226103840.GD10413@zhen-hp.sh.intel.com
parents 7a0a6ee7 a8bb49b6
...@@ -134,11 +134,11 @@ void intel_vgpu_write_fence(struct intel_vgpu *vgpu, ...@@ -134,11 +134,11 @@ void intel_vgpu_write_fence(struct intel_vgpu *vgpu,
assert_rpm_wakelock_held(&dev_priv->runtime_pm); assert_rpm_wakelock_held(&dev_priv->runtime_pm);
if (WARN_ON(fence >= vgpu_fence_sz(vgpu))) if (drm_WARN_ON(&dev_priv->drm, fence >= vgpu_fence_sz(vgpu)))
return; return;
reg = vgpu->fence.regs[fence]; reg = vgpu->fence.regs[fence];
if (WARN_ON(!reg)) if (drm_WARN_ON(&dev_priv->drm, !reg))
return; return;
fence_reg_lo = FENCE_REG_GEN6_LO(reg->id); fence_reg_lo = FENCE_REG_GEN6_LO(reg->id);
...@@ -167,7 +167,7 @@ static void free_vgpu_fence(struct intel_vgpu *vgpu) ...@@ -167,7 +167,7 @@ static void free_vgpu_fence(struct intel_vgpu *vgpu)
struct i915_fence_reg *reg; struct i915_fence_reg *reg;
u32 i; u32 i;
if (WARN_ON(!vgpu_fence_sz(vgpu))) if (drm_WARN_ON(&dev_priv->drm, !vgpu_fence_sz(vgpu)))
return; return;
intel_runtime_pm_get(&dev_priv->runtime_pm); intel_runtime_pm_get(&dev_priv->runtime_pm);
......
...@@ -106,10 +106,13 @@ static void vgpu_pci_cfg_mem_write(struct intel_vgpu *vgpu, unsigned int off, ...@@ -106,10 +106,13 @@ static void vgpu_pci_cfg_mem_write(struct intel_vgpu *vgpu, unsigned int off,
int intel_vgpu_emulate_cfg_read(struct intel_vgpu *vgpu, unsigned int offset, int intel_vgpu_emulate_cfg_read(struct intel_vgpu *vgpu, unsigned int offset,
void *p_data, unsigned int bytes) void *p_data, unsigned int bytes)
{ {
if (WARN_ON(bytes > 4)) struct drm_i915_private *i915 = vgpu->gvt->dev_priv;
if (drm_WARN_ON(&i915->drm, bytes > 4))
return -EINVAL; return -EINVAL;
if (WARN_ON(offset + bytes > vgpu->gvt->device_info.cfg_space_size)) if (drm_WARN_ON(&i915->drm,
offset + bytes > vgpu->gvt->device_info.cfg_space_size))
return -EINVAL; return -EINVAL;
memcpy(p_data, vgpu_cfg_space(vgpu) + offset, bytes); memcpy(p_data, vgpu_cfg_space(vgpu) + offset, bytes);
...@@ -297,34 +300,36 @@ static int emulate_pci_bar_write(struct intel_vgpu *vgpu, unsigned int offset, ...@@ -297,34 +300,36 @@ static int emulate_pci_bar_write(struct intel_vgpu *vgpu, unsigned int offset,
int intel_vgpu_emulate_cfg_write(struct intel_vgpu *vgpu, unsigned int offset, int intel_vgpu_emulate_cfg_write(struct intel_vgpu *vgpu, unsigned int offset,
void *p_data, unsigned int bytes) void *p_data, unsigned int bytes)
{ {
struct drm_i915_private *i915 = vgpu->gvt->dev_priv;
int ret; int ret;
if (WARN_ON(bytes > 4)) if (drm_WARN_ON(&i915->drm, bytes > 4))
return -EINVAL; return -EINVAL;
if (WARN_ON(offset + bytes > vgpu->gvt->device_info.cfg_space_size)) if (drm_WARN_ON(&i915->drm,
offset + bytes > vgpu->gvt->device_info.cfg_space_size))
return -EINVAL; return -EINVAL;
/* First check if it's PCI_COMMAND */ /* First check if it's PCI_COMMAND */
if (IS_ALIGNED(offset, 2) && offset == PCI_COMMAND) { if (IS_ALIGNED(offset, 2) && offset == PCI_COMMAND) {
if (WARN_ON(bytes > 2)) if (drm_WARN_ON(&i915->drm, bytes > 2))
return -EINVAL; return -EINVAL;
return emulate_pci_command_write(vgpu, offset, p_data, bytes); return emulate_pci_command_write(vgpu, offset, p_data, bytes);
} }
switch (rounddown(offset, 4)) { switch (rounddown(offset, 4)) {
case PCI_ROM_ADDRESS: case PCI_ROM_ADDRESS:
if (WARN_ON(!IS_ALIGNED(offset, 4))) if (drm_WARN_ON(&i915->drm, !IS_ALIGNED(offset, 4)))
return -EINVAL; return -EINVAL;
return emulate_pci_rom_bar_write(vgpu, offset, p_data, bytes); return emulate_pci_rom_bar_write(vgpu, offset, p_data, bytes);
case PCI_BASE_ADDRESS_0 ... PCI_BASE_ADDRESS_5: case PCI_BASE_ADDRESS_0 ... PCI_BASE_ADDRESS_5:
if (WARN_ON(!IS_ALIGNED(offset, 4))) if (drm_WARN_ON(&i915->drm, !IS_ALIGNED(offset, 4)))
return -EINVAL; return -EINVAL;
return emulate_pci_bar_write(vgpu, offset, p_data, bytes); return emulate_pci_bar_write(vgpu, offset, p_data, bytes);
case INTEL_GVT_PCI_SWSCI: case INTEL_GVT_PCI_SWSCI:
if (WARN_ON(!IS_ALIGNED(offset, 4))) if (drm_WARN_ON(&i915->drm, !IS_ALIGNED(offset, 4)))
return -EINVAL; return -EINVAL;
ret = intel_vgpu_emulate_opregion_request(vgpu, *(u32 *)p_data); ret = intel_vgpu_emulate_opregion_request(vgpu, *(u32 *)p_data);
if (ret) if (ret)
...@@ -332,7 +337,7 @@ int intel_vgpu_emulate_cfg_write(struct intel_vgpu *vgpu, unsigned int offset, ...@@ -332,7 +337,7 @@ int intel_vgpu_emulate_cfg_write(struct intel_vgpu *vgpu, unsigned int offset,
break; break;
case INTEL_GVT_PCI_OPREGION: case INTEL_GVT_PCI_OPREGION:
if (WARN_ON(!IS_ALIGNED(offset, 4))) if (drm_WARN_ON(&i915->drm, !IS_ALIGNED(offset, 4)))
return -EINVAL; return -EINVAL;
ret = intel_vgpu_opregion_base_write_handler(vgpu, ret = intel_vgpu_opregion_base_write_handler(vgpu,
*(u32 *)p_data); *(u32 *)p_data);
......
...@@ -1230,7 +1230,7 @@ static int gen8_decode_mi_display_flip(struct parser_exec_state *s, ...@@ -1230,7 +1230,7 @@ static int gen8_decode_mi_display_flip(struct parser_exec_state *s,
dword2 = cmd_val(s, 2); dword2 = cmd_val(s, 2);
v = (dword0 & GENMASK(21, 19)) >> 19; v = (dword0 & GENMASK(21, 19)) >> 19;
if (WARN_ON(v >= ARRAY_SIZE(gen8_plane_code))) if (drm_WARN_ON(&dev_priv->drm, v >= ARRAY_SIZE(gen8_plane_code)))
return -EBADRQC; return -EBADRQC;
info->pipe = gen8_plane_code[v].pipe; info->pipe = gen8_plane_code[v].pipe;
...@@ -1250,7 +1250,7 @@ static int gen8_decode_mi_display_flip(struct parser_exec_state *s, ...@@ -1250,7 +1250,7 @@ static int gen8_decode_mi_display_flip(struct parser_exec_state *s,
info->stride_reg = SPRSTRIDE(info->pipe); info->stride_reg = SPRSTRIDE(info->pipe);
info->surf_reg = SPRSURF(info->pipe); info->surf_reg = SPRSURF(info->pipe);
} else { } else {
WARN_ON(1); drm_WARN_ON(&dev_priv->drm, 1);
return -EBADRQC; return -EBADRQC;
} }
return 0; return 0;
......
...@@ -71,7 +71,8 @@ int pipe_is_enabled(struct intel_vgpu *vgpu, int pipe) ...@@ -71,7 +71,8 @@ int pipe_is_enabled(struct intel_vgpu *vgpu, int pipe)
{ {
struct drm_i915_private *dev_priv = vgpu->gvt->dev_priv; struct drm_i915_private *dev_priv = vgpu->gvt->dev_priv;
if (WARN_ON(pipe < PIPE_A || pipe >= I915_MAX_PIPES)) if (drm_WARN_ON(&dev_priv->drm,
pipe < PIPE_A || pipe >= I915_MAX_PIPES))
return -EINVAL; return -EINVAL;
if (vgpu_vreg_t(vgpu, PIPECONF(pipe)) & PIPECONF_ENABLE) if (vgpu_vreg_t(vgpu, PIPECONF(pipe)) & PIPECONF_ENABLE)
...@@ -319,9 +320,10 @@ static void clean_virtual_dp_monitor(struct intel_vgpu *vgpu, int port_num) ...@@ -319,9 +320,10 @@ static void clean_virtual_dp_monitor(struct intel_vgpu *vgpu, int port_num)
static int setup_virtual_dp_monitor(struct intel_vgpu *vgpu, int port_num, static int setup_virtual_dp_monitor(struct intel_vgpu *vgpu, int port_num,
int type, unsigned int resolution) int type, unsigned int resolution)
{ {
struct drm_i915_private *i915 = vgpu->gvt->dev_priv;
struct intel_vgpu_port *port = intel_vgpu_port(vgpu, port_num); struct intel_vgpu_port *port = intel_vgpu_port(vgpu, port_num);
if (WARN_ON(resolution >= GVT_EDID_NUM)) if (drm_WARN_ON(&i915->drm, resolution >= GVT_EDID_NUM))
return -EINVAL; return -EINVAL;
port->edid = kzalloc(sizeof(*(port->edid)), GFP_KERNEL); port->edid = kzalloc(sizeof(*(port->edid)), GFP_KERNEL);
......
...@@ -67,11 +67,11 @@ static int vgpu_gem_get_pages( ...@@ -67,11 +67,11 @@ static int vgpu_gem_get_pages(
u32 page_num; u32 page_num;
fb_info = (struct intel_vgpu_fb_info *)obj->gvt_info; fb_info = (struct intel_vgpu_fb_info *)obj->gvt_info;
if (WARN_ON(!fb_info)) if (drm_WARN_ON(&dev_priv->drm, !fb_info))
return -ENODEV; return -ENODEV;
vgpu = fb_info->obj->vgpu; vgpu = fb_info->obj->vgpu;
if (WARN_ON(!vgpu)) if (drm_WARN_ON(&dev_priv->drm, !vgpu))
return -ENODEV; return -ENODEV;
st = kmalloc(sizeof(*st), GFP_KERNEL); st = kmalloc(sizeof(*st), GFP_KERNEL);
......
...@@ -153,7 +153,7 @@ static int gmbus0_mmio_write(struct intel_vgpu *vgpu, ...@@ -153,7 +153,7 @@ static int gmbus0_mmio_write(struct intel_vgpu *vgpu,
port = cnp_get_port_from_gmbus0(pin_select); port = cnp_get_port_from_gmbus0(pin_select);
else else
port = get_port_from_gmbus0(pin_select); port = get_port_from_gmbus0(pin_select);
if (WARN_ON(port < 0)) if (drm_WARN_ON(&dev_priv->drm, port < 0))
return 0; return 0;
vgpu->display.i2c_edid.state = I2C_GMBUS; vgpu->display.i2c_edid.state = I2C_GMBUS;
...@@ -276,7 +276,9 @@ static int gmbus1_mmio_write(struct intel_vgpu *vgpu, unsigned int offset, ...@@ -276,7 +276,9 @@ static int gmbus1_mmio_write(struct intel_vgpu *vgpu, unsigned int offset,
static int gmbus3_mmio_write(struct intel_vgpu *vgpu, unsigned int offset, static int gmbus3_mmio_write(struct intel_vgpu *vgpu, unsigned int offset,
void *p_data, unsigned int bytes) void *p_data, unsigned int bytes)
{ {
WARN_ON(1); struct drm_i915_private *i915 = vgpu->gvt->dev_priv;
drm_WARN_ON(&i915->drm, 1);
return 0; return 0;
} }
...@@ -371,7 +373,9 @@ static int gmbus2_mmio_write(struct intel_vgpu *vgpu, unsigned int offset, ...@@ -371,7 +373,9 @@ static int gmbus2_mmio_write(struct intel_vgpu *vgpu, unsigned int offset,
int intel_gvt_i2c_handle_gmbus_read(struct intel_vgpu *vgpu, int intel_gvt_i2c_handle_gmbus_read(struct intel_vgpu *vgpu,
unsigned int offset, void *p_data, unsigned int bytes) unsigned int offset, void *p_data, unsigned int bytes)
{ {
if (WARN_ON(bytes > 8 && (offset & (bytes - 1)))) struct drm_i915_private *i915 = vgpu->gvt->dev_priv;
if (drm_WARN_ON(&i915->drm, bytes > 8 && (offset & (bytes - 1))))
return -EINVAL; return -EINVAL;
if (offset == i915_mmio_reg_offset(PCH_GMBUS2)) if (offset == i915_mmio_reg_offset(PCH_GMBUS2))
...@@ -399,7 +403,9 @@ int intel_gvt_i2c_handle_gmbus_read(struct intel_vgpu *vgpu, ...@@ -399,7 +403,9 @@ int intel_gvt_i2c_handle_gmbus_read(struct intel_vgpu *vgpu,
int intel_gvt_i2c_handle_gmbus_write(struct intel_vgpu *vgpu, int intel_gvt_i2c_handle_gmbus_write(struct intel_vgpu *vgpu,
unsigned int offset, void *p_data, unsigned int bytes) unsigned int offset, void *p_data, unsigned int bytes)
{ {
if (WARN_ON(bytes > 8 && (offset & (bytes - 1)))) struct drm_i915_private *i915 = vgpu->gvt->dev_priv;
if (drm_WARN_ON(&i915->drm, bytes > 8 && (offset & (bytes - 1))))
return -EINVAL; return -EINVAL;
if (offset == i915_mmio_reg_offset(PCH_GMBUS0)) if (offset == i915_mmio_reg_offset(PCH_GMBUS0))
...@@ -473,6 +479,7 @@ void intel_gvt_i2c_handle_aux_ch_write(struct intel_vgpu *vgpu, ...@@ -473,6 +479,7 @@ void intel_gvt_i2c_handle_aux_ch_write(struct intel_vgpu *vgpu,
unsigned int offset, unsigned int offset,
void *p_data) void *p_data)
{ {
struct drm_i915_private *i915 = vgpu->gvt->dev_priv;
struct intel_vgpu_i2c_edid *i2c_edid = &vgpu->display.i2c_edid; struct intel_vgpu_i2c_edid *i2c_edid = &vgpu->display.i2c_edid;
int msg_length, ret_msg_size; int msg_length, ret_msg_size;
int msg, addr, ctrl, op; int msg, addr, ctrl, op;
...@@ -532,9 +539,9 @@ void intel_gvt_i2c_handle_aux_ch_write(struct intel_vgpu *vgpu, ...@@ -532,9 +539,9 @@ void intel_gvt_i2c_handle_aux_ch_write(struct intel_vgpu *vgpu,
* support the gfx driver to do EDID access. * support the gfx driver to do EDID access.
*/ */
} else { } else {
if (WARN_ON((op & 0x1) != GVT_AUX_I2C_READ)) if (drm_WARN_ON(&i915->drm, (op & 0x1) != GVT_AUX_I2C_READ))
return; return;
if (WARN_ON(msg_length != 4)) if (drm_WARN_ON(&i915->drm, msg_length != 4))
return; return;
if (i2c_edid->edid_available && i2c_edid->slave_selected) { if (i2c_edid->edid_available && i2c_edid->slave_selected) {
unsigned char val = edid_get_byte(vgpu); unsigned char val = edid_get_byte(vgpu);
......
...@@ -71,8 +71,10 @@ bool intel_gvt_ggtt_validate_range(struct intel_vgpu *vgpu, u64 addr, u32 size) ...@@ -71,8 +71,10 @@ bool intel_gvt_ggtt_validate_range(struct intel_vgpu *vgpu, u64 addr, u32 size)
/* translate a guest gmadr to host gmadr */ /* translate a guest gmadr to host gmadr */
int intel_gvt_ggtt_gmadr_g2h(struct intel_vgpu *vgpu, u64 g_addr, u64 *h_addr) int intel_gvt_ggtt_gmadr_g2h(struct intel_vgpu *vgpu, u64 g_addr, u64 *h_addr)
{ {
if (WARN(!vgpu_gmadr_is_valid(vgpu, g_addr), struct drm_i915_private *i915 = vgpu->gvt->dev_priv;
"invalid guest gmadr %llx\n", g_addr))
if (drm_WARN(&i915->drm, !vgpu_gmadr_is_valid(vgpu, g_addr),
"invalid guest gmadr %llx\n", g_addr))
return -EACCES; return -EACCES;
if (vgpu_gmadr_is_aperture(vgpu, g_addr)) if (vgpu_gmadr_is_aperture(vgpu, g_addr))
...@@ -87,8 +89,10 @@ int intel_gvt_ggtt_gmadr_g2h(struct intel_vgpu *vgpu, u64 g_addr, u64 *h_addr) ...@@ -87,8 +89,10 @@ int intel_gvt_ggtt_gmadr_g2h(struct intel_vgpu *vgpu, u64 g_addr, u64 *h_addr)
/* translate a host gmadr to guest gmadr */ /* translate a host gmadr to guest gmadr */
int intel_gvt_ggtt_gmadr_h2g(struct intel_vgpu *vgpu, u64 h_addr, u64 *g_addr) int intel_gvt_ggtt_gmadr_h2g(struct intel_vgpu *vgpu, u64 h_addr, u64 *g_addr)
{ {
if (WARN(!gvt_gmadr_is_valid(vgpu->gvt, h_addr), struct drm_i915_private *i915 = vgpu->gvt->dev_priv;
"invalid host gmadr %llx\n", h_addr))
if (drm_WARN(&i915->drm, !gvt_gmadr_is_valid(vgpu->gvt, h_addr),
"invalid host gmadr %llx\n", h_addr))
return -EACCES; return -EACCES;
if (gvt_gmadr_is_aperture(vgpu->gvt, h_addr)) if (gvt_gmadr_is_aperture(vgpu->gvt, h_addr))
...@@ -940,6 +944,7 @@ static int ppgtt_invalidate_spt(struct intel_vgpu_ppgtt_spt *spt); ...@@ -940,6 +944,7 @@ static int ppgtt_invalidate_spt(struct intel_vgpu_ppgtt_spt *spt);
static int ppgtt_invalidate_spt_by_shadow_entry(struct intel_vgpu *vgpu, static int ppgtt_invalidate_spt_by_shadow_entry(struct intel_vgpu *vgpu,
struct intel_gvt_gtt_entry *e) struct intel_gvt_gtt_entry *e)
{ {
struct drm_i915_private *i915 = vgpu->gvt->dev_priv;
struct intel_gvt_gtt_pte_ops *ops = vgpu->gvt->gtt.pte_ops; struct intel_gvt_gtt_pte_ops *ops = vgpu->gvt->gtt.pte_ops;
struct intel_vgpu_ppgtt_spt *s; struct intel_vgpu_ppgtt_spt *s;
enum intel_gvt_gtt_type cur_pt_type; enum intel_gvt_gtt_type cur_pt_type;
...@@ -952,7 +957,9 @@ static int ppgtt_invalidate_spt_by_shadow_entry(struct intel_vgpu *vgpu, ...@@ -952,7 +957,9 @@ static int ppgtt_invalidate_spt_by_shadow_entry(struct intel_vgpu *vgpu,
if (!gtt_type_is_pt(cur_pt_type) || if (!gtt_type_is_pt(cur_pt_type) ||
!gtt_type_is_pt(cur_pt_type + 1)) { !gtt_type_is_pt(cur_pt_type + 1)) {
WARN(1, "Invalid page table type, cur_pt_type is: %d\n", cur_pt_type); drm_WARN(&i915->drm, 1,
"Invalid page table type, cur_pt_type is: %d\n",
cur_pt_type);
return -EINVAL; return -EINVAL;
} }
...@@ -2347,6 +2354,7 @@ int intel_vgpu_emulate_ggtt_mmio_write(struct intel_vgpu *vgpu, ...@@ -2347,6 +2354,7 @@ int intel_vgpu_emulate_ggtt_mmio_write(struct intel_vgpu *vgpu,
static int alloc_scratch_pages(struct intel_vgpu *vgpu, static int alloc_scratch_pages(struct intel_vgpu *vgpu,
enum intel_gvt_gtt_type type) enum intel_gvt_gtt_type type)
{ {
struct drm_i915_private *i915 = vgpu->gvt->dev_priv;
struct intel_vgpu_gtt *gtt = &vgpu->gtt; struct intel_vgpu_gtt *gtt = &vgpu->gtt;
struct intel_gvt_gtt_pte_ops *ops = vgpu->gvt->gtt.pte_ops; struct intel_gvt_gtt_pte_ops *ops = vgpu->gvt->gtt.pte_ops;
int page_entry_num = I915_GTT_PAGE_SIZE >> int page_entry_num = I915_GTT_PAGE_SIZE >>
...@@ -2356,7 +2364,8 @@ static int alloc_scratch_pages(struct intel_vgpu *vgpu, ...@@ -2356,7 +2364,8 @@ static int alloc_scratch_pages(struct intel_vgpu *vgpu,
struct device *dev = &vgpu->gvt->dev_priv->drm.pdev->dev; struct device *dev = &vgpu->gvt->dev_priv->drm.pdev->dev;
dma_addr_t daddr; dma_addr_t daddr;
if (WARN_ON(type < GTT_TYPE_PPGTT_PTE_PT || type >= GTT_TYPE_MAX)) if (drm_WARN_ON(&i915->drm,
type < GTT_TYPE_PPGTT_PTE_PT || type >= GTT_TYPE_MAX))
return -EINVAL; return -EINVAL;
scratch_pt = (void *)get_zeroed_page(GFP_KERNEL); scratch_pt = (void *)get_zeroed_page(GFP_KERNEL);
......
...@@ -120,10 +120,8 @@ static struct attribute_group *gvt_vgpu_type_groups[] = { ...@@ -120,10 +120,8 @@ static struct attribute_group *gvt_vgpu_type_groups[] = {
[0 ... NR_MAX_INTEL_VGPU_TYPES - 1] = NULL, [0 ... NR_MAX_INTEL_VGPU_TYPES - 1] = NULL,
}; };
static bool intel_get_gvt_attrs(struct attribute ***type_attrs, static bool intel_get_gvt_attrs(struct attribute_group ***intel_vgpu_type_groups)
struct attribute_group ***intel_vgpu_type_groups)
{ {
*type_attrs = gvt_type_attrs;
*intel_vgpu_type_groups = gvt_vgpu_type_groups; *intel_vgpu_type_groups = gvt_vgpu_type_groups;
return true; return true;
} }
...@@ -267,7 +265,7 @@ void intel_gvt_clean_device(struct drm_i915_private *dev_priv) ...@@ -267,7 +265,7 @@ void intel_gvt_clean_device(struct drm_i915_private *dev_priv)
{ {
struct intel_gvt *gvt = to_gvt(dev_priv); struct intel_gvt *gvt = to_gvt(dev_priv);
if (WARN_ON(!gvt)) if (drm_WARN_ON(&dev_priv->drm, !gvt))
return; return;
intel_gvt_destroy_idle_vgpu(gvt->idle_vgpu); intel_gvt_destroy_idle_vgpu(gvt->idle_vgpu);
...@@ -306,7 +304,7 @@ int intel_gvt_init_device(struct drm_i915_private *dev_priv) ...@@ -306,7 +304,7 @@ int intel_gvt_init_device(struct drm_i915_private *dev_priv)
struct intel_vgpu *vgpu; struct intel_vgpu *vgpu;
int ret; int ret;
if (WARN_ON(dev_priv->gvt)) if (drm_WARN_ON(&dev_priv->drm, dev_priv->gvt))
return -EEXIST; return -EEXIST;
gvt = kzalloc(sizeof(struct intel_gvt), GFP_KERNEL); gvt = kzalloc(sizeof(struct intel_gvt), GFP_KERNEL);
......
...@@ -196,41 +196,21 @@ struct intel_vgpu { ...@@ -196,41 +196,21 @@ struct intel_vgpu {
struct dentry *debugfs; struct dentry *debugfs;
#if IS_ENABLED(CONFIG_DRM_I915_GVT_KVMGT) /* Hypervisor-specific device state. */
struct { void *vdev;
struct mdev_device *mdev;
struct vfio_region *region;
int num_regions;
struct eventfd_ctx *intx_trigger;
struct eventfd_ctx *msi_trigger;
/*
* Two caches are used to avoid mapping duplicated pages (eg.
* scratch pages). This help to reduce dma setup overhead.
*/
struct rb_root gfn_cache;
struct rb_root dma_addr_cache;
unsigned long nr_cache_entries;
struct mutex cache_lock;
struct notifier_block iommu_notifier;
struct notifier_block group_notifier;
struct kvm *kvm;
struct work_struct release_work;
atomic_t released;
struct vfio_device *vfio_device;
} vdev;
#endif
struct list_head dmabuf_obj_list_head; struct list_head dmabuf_obj_list_head;
struct mutex dmabuf_lock; struct mutex dmabuf_lock;
struct idr object_idr; struct idr object_idr;
struct completion vblank_done;
u32 scan_nonprivbb; u32 scan_nonprivbb;
}; };
static inline void *intel_vgpu_vdev(struct intel_vgpu *vgpu)
{
return vgpu->vdev;
}
/* validating GM healthy status*/ /* validating GM healthy status*/
#define vgpu_is_vm_unhealthy(ret_val) \ #define vgpu_is_vm_unhealthy(ret_val) \
(((ret_val) == -EBADRQC) || ((ret_val) == -EFAULT)) (((ret_val) == -EBADRQC) || ((ret_val) == -EFAULT))
...@@ -570,8 +550,7 @@ struct intel_gvt_ops { ...@@ -570,8 +550,7 @@ struct intel_gvt_ops {
void (*vgpu_deactivate)(struct intel_vgpu *); void (*vgpu_deactivate)(struct intel_vgpu *);
struct intel_vgpu_type *(*gvt_find_vgpu_type)(struct intel_gvt *gvt, struct intel_vgpu_type *(*gvt_find_vgpu_type)(struct intel_gvt *gvt,
const char *name); const char *name);
bool (*get_gvt_attrs)(struct attribute ***type_attrs, bool (*get_gvt_attrs)(struct attribute_group ***intel_vgpu_type_groups);
struct attribute_group ***intel_vgpu_type_groups);
int (*vgpu_query_plane)(struct intel_vgpu *vgpu, void *); int (*vgpu_query_plane)(struct intel_vgpu *vgpu, void *);
int (*vgpu_get_dmabuf)(struct intel_vgpu *vgpu, unsigned int); int (*vgpu_get_dmabuf)(struct intel_vgpu *vgpu, unsigned int);
int (*write_protect_handler)(struct intel_vgpu *, u64, void *, int (*write_protect_handler)(struct intel_vgpu *, u64, void *,
......
...@@ -836,7 +836,7 @@ static int trigger_aux_channel_interrupt(struct intel_vgpu *vgpu, ...@@ -836,7 +836,7 @@ static int trigger_aux_channel_interrupt(struct intel_vgpu *vgpu,
reg == i915_mmio_reg_offset(DP_AUX_CH_CTL(AUX_CH_D))) reg == i915_mmio_reg_offset(DP_AUX_CH_CTL(AUX_CH_D)))
event = AUX_CHANNEL_D; event = AUX_CHANNEL_D;
else { else {
WARN_ON(true); drm_WARN_ON(&dev_priv->drm, true);
return -EINVAL; return -EINVAL;
} }
...@@ -1306,13 +1306,15 @@ static int pvinfo_mmio_write(struct intel_vgpu *vgpu, unsigned int offset, ...@@ -1306,13 +1306,15 @@ static int pvinfo_mmio_write(struct intel_vgpu *vgpu, unsigned int offset,
static int pf_write(struct intel_vgpu *vgpu, static int pf_write(struct intel_vgpu *vgpu,
unsigned int offset, void *p_data, unsigned int bytes) unsigned int offset, void *p_data, unsigned int bytes)
{ {
struct drm_i915_private *i915 = vgpu->gvt->dev_priv;
u32 val = *(u32 *)p_data; u32 val = *(u32 *)p_data;
if ((offset == _PS_1A_CTRL || offset == _PS_2A_CTRL || if ((offset == _PS_1A_CTRL || offset == _PS_2A_CTRL ||
offset == _PS_1B_CTRL || offset == _PS_2B_CTRL || offset == _PS_1B_CTRL || offset == _PS_2B_CTRL ||
offset == _PS_1C_CTRL) && (val & PS_PLANE_SEL_MASK) != 0) { offset == _PS_1C_CTRL) && (val & PS_PLANE_SEL_MASK) != 0) {
WARN_ONCE(true, "VM(%d): guest is trying to scaling a plane\n", drm_WARN_ONCE(&i915->drm, true,
vgpu->id); "VM(%d): guest is trying to scaling a plane\n",
vgpu->id);
return 0; return 0;
} }
...@@ -1360,13 +1362,15 @@ static int fpga_dbg_mmio_write(struct intel_vgpu *vgpu, ...@@ -1360,13 +1362,15 @@ static int fpga_dbg_mmio_write(struct intel_vgpu *vgpu,
static int dma_ctrl_write(struct intel_vgpu *vgpu, unsigned int offset, static int dma_ctrl_write(struct intel_vgpu *vgpu, unsigned int offset,
void *p_data, unsigned int bytes) void *p_data, unsigned int bytes)
{ {
struct drm_i915_private *i915 = vgpu->gvt->dev_priv;
u32 mode; u32 mode;
write_vreg(vgpu, offset, p_data, bytes); write_vreg(vgpu, offset, p_data, bytes);
mode = vgpu_vreg(vgpu, offset); mode = vgpu_vreg(vgpu, offset);
if (GFX_MODE_BIT_SET_IN_MASK(mode, START_DMA)) { if (GFX_MODE_BIT_SET_IN_MASK(mode, START_DMA)) {
WARN_ONCE(1, "VM(%d): iGVT-g doesn't support GuC\n", drm_WARN_ONCE(&i915->drm, 1,
"VM(%d): iGVT-g doesn't support GuC\n",
vgpu->id); vgpu->id);
return 0; return 0;
} }
...@@ -1377,10 +1381,12 @@ static int dma_ctrl_write(struct intel_vgpu *vgpu, unsigned int offset, ...@@ -1377,10 +1381,12 @@ static int dma_ctrl_write(struct intel_vgpu *vgpu, unsigned int offset,
static int gen9_trtte_write(struct intel_vgpu *vgpu, unsigned int offset, static int gen9_trtte_write(struct intel_vgpu *vgpu, unsigned int offset,
void *p_data, unsigned int bytes) void *p_data, unsigned int bytes)
{ {
struct drm_i915_private *i915 = vgpu->gvt->dev_priv;
u32 trtte = *(u32 *)p_data; u32 trtte = *(u32 *)p_data;
if ((trtte & 1) && (trtte & (1 << 1)) == 0) { if ((trtte & 1) && (trtte & (1 << 1)) == 0) {
WARN(1, "VM(%d): Use physical address for TRTT!\n", drm_WARN(&i915->drm, 1,
"VM(%d): Use physical address for TRTT!\n",
vgpu->id); vgpu->id);
return -EINVAL; return -EINVAL;
} }
...@@ -1682,12 +1688,13 @@ static int mmio_read_from_hw(struct intel_vgpu *vgpu, ...@@ -1682,12 +1688,13 @@ static int mmio_read_from_hw(struct intel_vgpu *vgpu,
static int elsp_mmio_write(struct intel_vgpu *vgpu, unsigned int offset, static int elsp_mmio_write(struct intel_vgpu *vgpu, unsigned int offset,
void *p_data, unsigned int bytes) void *p_data, unsigned int bytes)
{ {
struct drm_i915_private *i915 = vgpu->gvt->dev_priv;
int ring_id = intel_gvt_render_mmio_to_ring_id(vgpu->gvt, offset); int ring_id = intel_gvt_render_mmio_to_ring_id(vgpu->gvt, offset);
struct intel_vgpu_execlist *execlist; struct intel_vgpu_execlist *execlist;
u32 data = *(u32 *)p_data; u32 data = *(u32 *)p_data;
int ret = 0; int ret = 0;
if (WARN_ON(ring_id < 0 || ring_id >= I915_NUM_ENGINES)) if (drm_WARN_ON(&i915->drm, ring_id < 0 || ring_id >= I915_NUM_ENGINES))
return -EINVAL; return -EINVAL;
execlist = &vgpu->submission.execlist[ring_id]; execlist = &vgpu->submission.execlist[ring_id];
...@@ -3541,13 +3548,14 @@ bool intel_gvt_in_force_nonpriv_whitelist(struct intel_gvt *gvt, ...@@ -3541,13 +3548,14 @@ bool intel_gvt_in_force_nonpriv_whitelist(struct intel_gvt *gvt,
int intel_vgpu_mmio_reg_rw(struct intel_vgpu *vgpu, unsigned int offset, int intel_vgpu_mmio_reg_rw(struct intel_vgpu *vgpu, unsigned int offset,
void *pdata, unsigned int bytes, bool is_read) void *pdata, unsigned int bytes, bool is_read)
{ {
struct drm_i915_private *i915 = vgpu->gvt->dev_priv;
struct intel_gvt *gvt = vgpu->gvt; struct intel_gvt *gvt = vgpu->gvt;
struct intel_gvt_mmio_info *mmio_info; struct intel_gvt_mmio_info *mmio_info;
struct gvt_mmio_block *mmio_block; struct gvt_mmio_block *mmio_block;
gvt_mmio_func func; gvt_mmio_func func;
int ret; int ret;
if (WARN_ON(bytes > 8)) if (drm_WARN_ON(&i915->drm, bytes > 8))
return -EINVAL; return -EINVAL;
/* /*
......
...@@ -244,6 +244,7 @@ int intel_vgpu_reg_master_irq_handler(struct intel_vgpu *vgpu, ...@@ -244,6 +244,7 @@ int intel_vgpu_reg_master_irq_handler(struct intel_vgpu *vgpu,
int intel_vgpu_reg_ier_handler(struct intel_vgpu *vgpu, int intel_vgpu_reg_ier_handler(struct intel_vgpu *vgpu,
unsigned int reg, void *p_data, unsigned int bytes) unsigned int reg, void *p_data, unsigned int bytes)
{ {
struct drm_i915_private *i915 = vgpu->gvt->dev_priv;
struct intel_gvt *gvt = vgpu->gvt; struct intel_gvt *gvt = vgpu->gvt;
struct intel_gvt_irq_ops *ops = gvt->irq.ops; struct intel_gvt_irq_ops *ops = gvt->irq.ops;
struct intel_gvt_irq_info *info; struct intel_gvt_irq_info *info;
...@@ -255,7 +256,7 @@ int intel_vgpu_reg_ier_handler(struct intel_vgpu *vgpu, ...@@ -255,7 +256,7 @@ int intel_vgpu_reg_ier_handler(struct intel_vgpu *vgpu,
vgpu_vreg(vgpu, reg) = ier; vgpu_vreg(vgpu, reg) = ier;
info = regbase_to_irq_info(gvt, ier_to_regbase(reg)); info = regbase_to_irq_info(gvt, ier_to_regbase(reg));
if (WARN_ON(!info)) if (drm_WARN_ON(&i915->drm, !info))
return -EINVAL; return -EINVAL;
if (info->has_upstream_irq) if (info->has_upstream_irq)
...@@ -282,6 +283,7 @@ int intel_vgpu_reg_ier_handler(struct intel_vgpu *vgpu, ...@@ -282,6 +283,7 @@ int intel_vgpu_reg_ier_handler(struct intel_vgpu *vgpu,
int intel_vgpu_reg_iir_handler(struct intel_vgpu *vgpu, unsigned int reg, int intel_vgpu_reg_iir_handler(struct intel_vgpu *vgpu, unsigned int reg,
void *p_data, unsigned int bytes) void *p_data, unsigned int bytes)
{ {
struct drm_i915_private *i915 = vgpu->gvt->dev_priv;
struct intel_gvt_irq_info *info = regbase_to_irq_info(vgpu->gvt, struct intel_gvt_irq_info *info = regbase_to_irq_info(vgpu->gvt,
iir_to_regbase(reg)); iir_to_regbase(reg));
u32 iir = *(u32 *)p_data; u32 iir = *(u32 *)p_data;
...@@ -289,7 +291,7 @@ int intel_vgpu_reg_iir_handler(struct intel_vgpu *vgpu, unsigned int reg, ...@@ -289,7 +291,7 @@ int intel_vgpu_reg_iir_handler(struct intel_vgpu *vgpu, unsigned int reg,
trace_write_ir(vgpu->id, "IIR", reg, iir, vgpu_vreg(vgpu, reg), trace_write_ir(vgpu->id, "IIR", reg, iir, vgpu_vreg(vgpu, reg),
(vgpu_vreg(vgpu, reg) ^ iir)); (vgpu_vreg(vgpu, reg) ^ iir));
if (WARN_ON(!info)) if (drm_WARN_ON(&i915->drm, !info))
return -EINVAL; return -EINVAL;
vgpu_vreg(vgpu, reg) &= ~iir; vgpu_vreg(vgpu, reg) &= ~iir;
...@@ -319,6 +321,7 @@ static struct intel_gvt_irq_map gen8_irq_map[] = { ...@@ -319,6 +321,7 @@ static struct intel_gvt_irq_map gen8_irq_map[] = {
static void update_upstream_irq(struct intel_vgpu *vgpu, static void update_upstream_irq(struct intel_vgpu *vgpu,
struct intel_gvt_irq_info *info) struct intel_gvt_irq_info *info)
{ {
struct drm_i915_private *i915 = vgpu->gvt->dev_priv;
struct intel_gvt_irq *irq = &vgpu->gvt->irq; struct intel_gvt_irq *irq = &vgpu->gvt->irq;
struct intel_gvt_irq_map *map = irq->irq_map; struct intel_gvt_irq_map *map = irq->irq_map;
struct intel_gvt_irq_info *up_irq_info = NULL; struct intel_gvt_irq_info *up_irq_info = NULL;
...@@ -340,7 +343,8 @@ static void update_upstream_irq(struct intel_vgpu *vgpu, ...@@ -340,7 +343,8 @@ static void update_upstream_irq(struct intel_vgpu *vgpu,
if (!up_irq_info) if (!up_irq_info)
up_irq_info = irq->info[map->up_irq_group]; up_irq_info = irq->info[map->up_irq_group];
else else
WARN_ON(up_irq_info != irq->info[map->up_irq_group]); drm_WARN_ON(&i915->drm, up_irq_info !=
irq->info[map->up_irq_group]);
bit = map->up_irq_bit; bit = map->up_irq_bit;
...@@ -350,7 +354,7 @@ static void update_upstream_irq(struct intel_vgpu *vgpu, ...@@ -350,7 +354,7 @@ static void update_upstream_irq(struct intel_vgpu *vgpu,
clear_bits |= (1 << bit); clear_bits |= (1 << bit);
} }
if (WARN_ON(!up_irq_info)) if (drm_WARN_ON(&i915->drm, !up_irq_info))
return; return;
if (up_irq_info->group == INTEL_GVT_IRQ_INFO_MASTER) { if (up_irq_info->group == INTEL_GVT_IRQ_INFO_MASTER) {
...@@ -618,13 +622,14 @@ static struct intel_gvt_irq_ops gen8_irq_ops = { ...@@ -618,13 +622,14 @@ static struct intel_gvt_irq_ops gen8_irq_ops = {
void intel_vgpu_trigger_virtual_event(struct intel_vgpu *vgpu, void intel_vgpu_trigger_virtual_event(struct intel_vgpu *vgpu,
enum intel_gvt_event_type event) enum intel_gvt_event_type event)
{ {
struct drm_i915_private *i915 = vgpu->gvt->dev_priv;
struct intel_gvt *gvt = vgpu->gvt; struct intel_gvt *gvt = vgpu->gvt;
struct intel_gvt_irq *irq = &gvt->irq; struct intel_gvt_irq *irq = &gvt->irq;
gvt_event_virt_handler_t handler; gvt_event_virt_handler_t handler;
struct intel_gvt_irq_ops *ops = gvt->irq.ops; struct intel_gvt_irq_ops *ops = gvt->irq.ops;
handler = get_event_virt_handler(irq, event); handler = get_event_virt_handler(irq, event);
WARN_ON(!handler); drm_WARN_ON(&i915->drm, !handler);
handler(irq, event, vgpu); handler(irq, event, vgpu);
......
...@@ -108,6 +108,36 @@ struct gvt_dma { ...@@ -108,6 +108,36 @@ struct gvt_dma {
struct kref ref; struct kref ref;
}; };
struct kvmgt_vdev {
struct intel_vgpu *vgpu;
struct mdev_device *mdev;
struct vfio_region *region;
int num_regions;
struct eventfd_ctx *intx_trigger;
struct eventfd_ctx *msi_trigger;
/*
* Two caches are used to avoid mapping duplicated pages (eg.
* scratch pages). This help to reduce dma setup overhead.
*/
struct rb_root gfn_cache;
struct rb_root dma_addr_cache;
unsigned long nr_cache_entries;
struct mutex cache_lock;
struct notifier_block iommu_notifier;
struct notifier_block group_notifier;
struct kvm *kvm;
struct work_struct release_work;
atomic_t released;
struct vfio_device *vfio_device;
};
static inline struct kvmgt_vdev *kvmgt_vdev(struct intel_vgpu *vgpu)
{
return intel_vgpu_vdev(vgpu);
}
static inline bool handle_valid(unsigned long handle) static inline bool handle_valid(unsigned long handle)
{ {
return !!(handle & ~0xff); return !!(handle & ~0xff);
...@@ -120,6 +150,7 @@ static bool kvmgt_guest_exit(struct kvmgt_guest_info *info); ...@@ -120,6 +150,7 @@ static bool kvmgt_guest_exit(struct kvmgt_guest_info *info);
static void gvt_unpin_guest_page(struct intel_vgpu *vgpu, unsigned long gfn, static void gvt_unpin_guest_page(struct intel_vgpu *vgpu, unsigned long gfn,
unsigned long size) unsigned long size)
{ {
struct drm_i915_private *i915 = vgpu->gvt->dev_priv;
int total_pages; int total_pages;
int npage; int npage;
int ret; int ret;
...@@ -129,8 +160,8 @@ static void gvt_unpin_guest_page(struct intel_vgpu *vgpu, unsigned long gfn, ...@@ -129,8 +160,8 @@ static void gvt_unpin_guest_page(struct intel_vgpu *vgpu, unsigned long gfn,
for (npage = 0; npage < total_pages; npage++) { for (npage = 0; npage < total_pages; npage++) {
unsigned long cur_gfn = gfn + npage; unsigned long cur_gfn = gfn + npage;
ret = vfio_unpin_pages(mdev_dev(vgpu->vdev.mdev), &cur_gfn, 1); ret = vfio_unpin_pages(mdev_dev(kvmgt_vdev(vgpu)->mdev), &cur_gfn, 1);
WARN_ON(ret != 1); drm_WARN_ON(&i915->drm, ret != 1);
} }
} }
...@@ -152,7 +183,7 @@ static int gvt_pin_guest_page(struct intel_vgpu *vgpu, unsigned long gfn, ...@@ -152,7 +183,7 @@ static int gvt_pin_guest_page(struct intel_vgpu *vgpu, unsigned long gfn,
unsigned long cur_gfn = gfn + npage; unsigned long cur_gfn = gfn + npage;
unsigned long pfn; unsigned long pfn;
ret = vfio_pin_pages(mdev_dev(vgpu->vdev.mdev), &cur_gfn, 1, ret = vfio_pin_pages(mdev_dev(kvmgt_vdev(vgpu)->mdev), &cur_gfn, 1,
IOMMU_READ | IOMMU_WRITE, &pfn); IOMMU_READ | IOMMU_WRITE, &pfn);
if (ret != 1) { if (ret != 1) {
gvt_vgpu_err("vfio_pin_pages failed for gfn 0x%lx, ret %d\n", gvt_vgpu_err("vfio_pin_pages failed for gfn 0x%lx, ret %d\n",
...@@ -219,7 +250,7 @@ static void gvt_dma_unmap_page(struct intel_vgpu *vgpu, unsigned long gfn, ...@@ -219,7 +250,7 @@ static void gvt_dma_unmap_page(struct intel_vgpu *vgpu, unsigned long gfn,
static struct gvt_dma *__gvt_cache_find_dma_addr(struct intel_vgpu *vgpu, static struct gvt_dma *__gvt_cache_find_dma_addr(struct intel_vgpu *vgpu,
dma_addr_t dma_addr) dma_addr_t dma_addr)
{ {
struct rb_node *node = vgpu->vdev.dma_addr_cache.rb_node; struct rb_node *node = kvmgt_vdev(vgpu)->dma_addr_cache.rb_node;
struct gvt_dma *itr; struct gvt_dma *itr;
while (node) { while (node) {
...@@ -237,7 +268,7 @@ static struct gvt_dma *__gvt_cache_find_dma_addr(struct intel_vgpu *vgpu, ...@@ -237,7 +268,7 @@ static struct gvt_dma *__gvt_cache_find_dma_addr(struct intel_vgpu *vgpu,
static struct gvt_dma *__gvt_cache_find_gfn(struct intel_vgpu *vgpu, gfn_t gfn) static struct gvt_dma *__gvt_cache_find_gfn(struct intel_vgpu *vgpu, gfn_t gfn)
{ {
struct rb_node *node = vgpu->vdev.gfn_cache.rb_node; struct rb_node *node = kvmgt_vdev(vgpu)->gfn_cache.rb_node;
struct gvt_dma *itr; struct gvt_dma *itr;
while (node) { while (node) {
...@@ -258,6 +289,7 @@ static int __gvt_cache_add(struct intel_vgpu *vgpu, gfn_t gfn, ...@@ -258,6 +289,7 @@ static int __gvt_cache_add(struct intel_vgpu *vgpu, gfn_t gfn,
{ {
struct gvt_dma *new, *itr; struct gvt_dma *new, *itr;
struct rb_node **link, *parent = NULL; struct rb_node **link, *parent = NULL;
struct kvmgt_vdev *vdev = kvmgt_vdev(vgpu);
new = kzalloc(sizeof(struct gvt_dma), GFP_KERNEL); new = kzalloc(sizeof(struct gvt_dma), GFP_KERNEL);
if (!new) if (!new)
...@@ -270,7 +302,7 @@ static int __gvt_cache_add(struct intel_vgpu *vgpu, gfn_t gfn, ...@@ -270,7 +302,7 @@ static int __gvt_cache_add(struct intel_vgpu *vgpu, gfn_t gfn,
kref_init(&new->ref); kref_init(&new->ref);
/* gfn_cache maps gfn to struct gvt_dma. */ /* gfn_cache maps gfn to struct gvt_dma. */
link = &vgpu->vdev.gfn_cache.rb_node; link = &vdev->gfn_cache.rb_node;
while (*link) { while (*link) {
parent = *link; parent = *link;
itr = rb_entry(parent, struct gvt_dma, gfn_node); itr = rb_entry(parent, struct gvt_dma, gfn_node);
...@@ -281,11 +313,11 @@ static int __gvt_cache_add(struct intel_vgpu *vgpu, gfn_t gfn, ...@@ -281,11 +313,11 @@ static int __gvt_cache_add(struct intel_vgpu *vgpu, gfn_t gfn,
link = &parent->rb_right; link = &parent->rb_right;
} }
rb_link_node(&new->gfn_node, parent, link); rb_link_node(&new->gfn_node, parent, link);
rb_insert_color(&new->gfn_node, &vgpu->vdev.gfn_cache); rb_insert_color(&new->gfn_node, &vdev->gfn_cache);
/* dma_addr_cache maps dma addr to struct gvt_dma. */ /* dma_addr_cache maps dma addr to struct gvt_dma. */
parent = NULL; parent = NULL;
link = &vgpu->vdev.dma_addr_cache.rb_node; link = &vdev->dma_addr_cache.rb_node;
while (*link) { while (*link) {
parent = *link; parent = *link;
itr = rb_entry(parent, struct gvt_dma, dma_addr_node); itr = rb_entry(parent, struct gvt_dma, dma_addr_node);
...@@ -296,46 +328,51 @@ static int __gvt_cache_add(struct intel_vgpu *vgpu, gfn_t gfn, ...@@ -296,46 +328,51 @@ static int __gvt_cache_add(struct intel_vgpu *vgpu, gfn_t gfn,
link = &parent->rb_right; link = &parent->rb_right;
} }
rb_link_node(&new->dma_addr_node, parent, link); rb_link_node(&new->dma_addr_node, parent, link);
rb_insert_color(&new->dma_addr_node, &vgpu->vdev.dma_addr_cache); rb_insert_color(&new->dma_addr_node, &vdev->dma_addr_cache);
vgpu->vdev.nr_cache_entries++; vdev->nr_cache_entries++;
return 0; return 0;
} }
static void __gvt_cache_remove_entry(struct intel_vgpu *vgpu, static void __gvt_cache_remove_entry(struct intel_vgpu *vgpu,
struct gvt_dma *entry) struct gvt_dma *entry)
{ {
rb_erase(&entry->gfn_node, &vgpu->vdev.gfn_cache); struct kvmgt_vdev *vdev = kvmgt_vdev(vgpu);
rb_erase(&entry->dma_addr_node, &vgpu->vdev.dma_addr_cache);
rb_erase(&entry->gfn_node, &vdev->gfn_cache);
rb_erase(&entry->dma_addr_node, &vdev->dma_addr_cache);
kfree(entry); kfree(entry);
vgpu->vdev.nr_cache_entries--; vdev->nr_cache_entries--;
} }
static void gvt_cache_destroy(struct intel_vgpu *vgpu) static void gvt_cache_destroy(struct intel_vgpu *vgpu)
{ {
struct gvt_dma *dma; struct gvt_dma *dma;
struct rb_node *node = NULL; struct rb_node *node = NULL;
struct kvmgt_vdev *vdev = kvmgt_vdev(vgpu);
for (;;) { for (;;) {
mutex_lock(&vgpu->vdev.cache_lock); mutex_lock(&vdev->cache_lock);
node = rb_first(&vgpu->vdev.gfn_cache); node = rb_first(&vdev->gfn_cache);
if (!node) { if (!node) {
mutex_unlock(&vgpu->vdev.cache_lock); mutex_unlock(&vdev->cache_lock);
break; break;
} }
dma = rb_entry(node, struct gvt_dma, gfn_node); dma = rb_entry(node, struct gvt_dma, gfn_node);
gvt_dma_unmap_page(vgpu, dma->gfn, dma->dma_addr, dma->size); gvt_dma_unmap_page(vgpu, dma->gfn, dma->dma_addr, dma->size);
__gvt_cache_remove_entry(vgpu, dma); __gvt_cache_remove_entry(vgpu, dma);
mutex_unlock(&vgpu->vdev.cache_lock); mutex_unlock(&vdev->cache_lock);
} }
} }
static void gvt_cache_init(struct intel_vgpu *vgpu) static void gvt_cache_init(struct intel_vgpu *vgpu)
{ {
vgpu->vdev.gfn_cache = RB_ROOT; struct kvmgt_vdev *vdev = kvmgt_vdev(vgpu);
vgpu->vdev.dma_addr_cache = RB_ROOT;
vgpu->vdev.nr_cache_entries = 0; vdev->gfn_cache = RB_ROOT;
mutex_init(&vgpu->vdev.cache_lock); vdev->dma_addr_cache = RB_ROOT;
vdev->nr_cache_entries = 0;
mutex_init(&vdev->cache_lock);
} }
static void kvmgt_protect_table_init(struct kvmgt_guest_info *info) static void kvmgt_protect_table_init(struct kvmgt_guest_info *info)
...@@ -409,16 +446,18 @@ static void kvmgt_protect_table_del(struct kvmgt_guest_info *info, ...@@ -409,16 +446,18 @@ static void kvmgt_protect_table_del(struct kvmgt_guest_info *info,
static size_t intel_vgpu_reg_rw_opregion(struct intel_vgpu *vgpu, char *buf, static size_t intel_vgpu_reg_rw_opregion(struct intel_vgpu *vgpu, char *buf,
size_t count, loff_t *ppos, bool iswrite) size_t count, loff_t *ppos, bool iswrite)
{ {
struct kvmgt_vdev *vdev = kvmgt_vdev(vgpu);
unsigned int i = VFIO_PCI_OFFSET_TO_INDEX(*ppos) - unsigned int i = VFIO_PCI_OFFSET_TO_INDEX(*ppos) -
VFIO_PCI_NUM_REGIONS; VFIO_PCI_NUM_REGIONS;
void *base = vgpu->vdev.region[i].data; void *base = vdev->region[i].data;
loff_t pos = *ppos & VFIO_PCI_OFFSET_MASK; loff_t pos = *ppos & VFIO_PCI_OFFSET_MASK;
if (pos >= vgpu->vdev.region[i].size || iswrite) {
if (pos >= vdev->region[i].size || iswrite) {
gvt_vgpu_err("invalid op or offset for Intel vgpu OpRegion\n"); gvt_vgpu_err("invalid op or offset for Intel vgpu OpRegion\n");
return -EINVAL; return -EINVAL;
} }
count = min(count, (size_t)(vgpu->vdev.region[i].size - pos)); count = min(count, (size_t)(vdev->region[i].size - pos));
memcpy(buf, base + pos, count); memcpy(buf, base + pos, count);
return count; return count;
...@@ -512,7 +551,7 @@ static size_t intel_vgpu_reg_rw_edid(struct intel_vgpu *vgpu, char *buf, ...@@ -512,7 +551,7 @@ static size_t intel_vgpu_reg_rw_edid(struct intel_vgpu *vgpu, char *buf,
unsigned int i = VFIO_PCI_OFFSET_TO_INDEX(*ppos) - unsigned int i = VFIO_PCI_OFFSET_TO_INDEX(*ppos) -
VFIO_PCI_NUM_REGIONS; VFIO_PCI_NUM_REGIONS;
struct vfio_edid_region *region = struct vfio_edid_region *region =
(struct vfio_edid_region *)vgpu->vdev.region[i].data; (struct vfio_edid_region *)kvmgt_vdev(vgpu)->region[i].data;
loff_t pos = *ppos & VFIO_PCI_OFFSET_MASK; loff_t pos = *ppos & VFIO_PCI_OFFSET_MASK;
if (pos < region->vfio_edid_regs.edid_offset) { if (pos < region->vfio_edid_regs.edid_offset) {
...@@ -544,32 +583,34 @@ static int intel_vgpu_register_reg(struct intel_vgpu *vgpu, ...@@ -544,32 +583,34 @@ static int intel_vgpu_register_reg(struct intel_vgpu *vgpu,
const struct intel_vgpu_regops *ops, const struct intel_vgpu_regops *ops,
size_t size, u32 flags, void *data) size_t size, u32 flags, void *data)
{ {
struct kvmgt_vdev *vdev = kvmgt_vdev(vgpu);
struct vfio_region *region; struct vfio_region *region;
region = krealloc(vgpu->vdev.region, region = krealloc(vdev->region,
(vgpu->vdev.num_regions + 1) * sizeof(*region), (vdev->num_regions + 1) * sizeof(*region),
GFP_KERNEL); GFP_KERNEL);
if (!region) if (!region)
return -ENOMEM; return -ENOMEM;
vgpu->vdev.region = region; vdev->region = region;
vgpu->vdev.region[vgpu->vdev.num_regions].type = type; vdev->region[vdev->num_regions].type = type;
vgpu->vdev.region[vgpu->vdev.num_regions].subtype = subtype; vdev->region[vdev->num_regions].subtype = subtype;
vgpu->vdev.region[vgpu->vdev.num_regions].ops = ops; vdev->region[vdev->num_regions].ops = ops;
vgpu->vdev.region[vgpu->vdev.num_regions].size = size; vdev->region[vdev->num_regions].size = size;
vgpu->vdev.region[vgpu->vdev.num_regions].flags = flags; vdev->region[vdev->num_regions].flags = flags;
vgpu->vdev.region[vgpu->vdev.num_regions].data = data; vdev->region[vdev->num_regions].data = data;
vgpu->vdev.num_regions++; vdev->num_regions++;
return 0; return 0;
} }
static int kvmgt_get_vfio_device(void *p_vgpu) static int kvmgt_get_vfio_device(void *p_vgpu)
{ {
struct intel_vgpu *vgpu = (struct intel_vgpu *)p_vgpu; struct intel_vgpu *vgpu = (struct intel_vgpu *)p_vgpu;
struct kvmgt_vdev *vdev = kvmgt_vdev(vgpu);
vgpu->vdev.vfio_device = vfio_device_get_from_dev( vdev->vfio_device = vfio_device_get_from_dev(
mdev_dev(vgpu->vdev.mdev)); mdev_dev(vdev->mdev));
if (!vgpu->vdev.vfio_device) { if (!vdev->vfio_device) {
gvt_vgpu_err("failed to get vfio device\n"); gvt_vgpu_err("failed to get vfio device\n");
return -ENODEV; return -ENODEV;
} }
...@@ -637,10 +678,12 @@ static int kvmgt_set_edid(void *p_vgpu, int port_num) ...@@ -637,10 +678,12 @@ static int kvmgt_set_edid(void *p_vgpu, int port_num)
static void kvmgt_put_vfio_device(void *vgpu) static void kvmgt_put_vfio_device(void *vgpu)
{ {
if (WARN_ON(!((struct intel_vgpu *)vgpu)->vdev.vfio_device)) struct kvmgt_vdev *vdev = kvmgt_vdev((struct intel_vgpu *)vgpu);
if (WARN_ON(!vdev->vfio_device))
return; return;
vfio_device_put(((struct intel_vgpu *)vgpu)->vdev.vfio_device); vfio_device_put(vdev->vfio_device);
} }
static int intel_vgpu_create(struct kobject *kobj, struct mdev_device *mdev) static int intel_vgpu_create(struct kobject *kobj, struct mdev_device *mdev)
...@@ -669,9 +712,9 @@ static int intel_vgpu_create(struct kobject *kobj, struct mdev_device *mdev) ...@@ -669,9 +712,9 @@ static int intel_vgpu_create(struct kobject *kobj, struct mdev_device *mdev)
goto out; goto out;
} }
INIT_WORK(&vgpu->vdev.release_work, intel_vgpu_release_work); INIT_WORK(&kvmgt_vdev(vgpu)->release_work, intel_vgpu_release_work);
vgpu->vdev.mdev = mdev; kvmgt_vdev(vgpu)->mdev = mdev;
mdev_set_drvdata(mdev, vgpu); mdev_set_drvdata(mdev, vgpu);
gvt_dbg_core("intel_vgpu_create succeeded for mdev: %s\n", gvt_dbg_core("intel_vgpu_create succeeded for mdev: %s\n",
...@@ -696,9 +739,10 @@ static int intel_vgpu_remove(struct mdev_device *mdev) ...@@ -696,9 +739,10 @@ static int intel_vgpu_remove(struct mdev_device *mdev)
static int intel_vgpu_iommu_notifier(struct notifier_block *nb, static int intel_vgpu_iommu_notifier(struct notifier_block *nb,
unsigned long action, void *data) unsigned long action, void *data)
{ {
struct intel_vgpu *vgpu = container_of(nb, struct kvmgt_vdev *vdev = container_of(nb,
struct intel_vgpu, struct kvmgt_vdev,
vdev.iommu_notifier); iommu_notifier);
struct intel_vgpu *vgpu = vdev->vgpu;
if (action == VFIO_IOMMU_NOTIFY_DMA_UNMAP) { if (action == VFIO_IOMMU_NOTIFY_DMA_UNMAP) {
struct vfio_iommu_type1_dma_unmap *unmap = data; struct vfio_iommu_type1_dma_unmap *unmap = data;
...@@ -708,7 +752,7 @@ static int intel_vgpu_iommu_notifier(struct notifier_block *nb, ...@@ -708,7 +752,7 @@ static int intel_vgpu_iommu_notifier(struct notifier_block *nb,
iov_pfn = unmap->iova >> PAGE_SHIFT; iov_pfn = unmap->iova >> PAGE_SHIFT;
end_iov_pfn = iov_pfn + unmap->size / PAGE_SIZE; end_iov_pfn = iov_pfn + unmap->size / PAGE_SIZE;
mutex_lock(&vgpu->vdev.cache_lock); mutex_lock(&vdev->cache_lock);
for (; iov_pfn < end_iov_pfn; iov_pfn++) { for (; iov_pfn < end_iov_pfn; iov_pfn++) {
entry = __gvt_cache_find_gfn(vgpu, iov_pfn); entry = __gvt_cache_find_gfn(vgpu, iov_pfn);
if (!entry) if (!entry)
...@@ -718,7 +762,7 @@ static int intel_vgpu_iommu_notifier(struct notifier_block *nb, ...@@ -718,7 +762,7 @@ static int intel_vgpu_iommu_notifier(struct notifier_block *nb,
entry->size); entry->size);
__gvt_cache_remove_entry(vgpu, entry); __gvt_cache_remove_entry(vgpu, entry);
} }
mutex_unlock(&vgpu->vdev.cache_lock); mutex_unlock(&vdev->cache_lock);
} }
return NOTIFY_OK; return NOTIFY_OK;
...@@ -727,16 +771,16 @@ static int intel_vgpu_iommu_notifier(struct notifier_block *nb, ...@@ -727,16 +771,16 @@ static int intel_vgpu_iommu_notifier(struct notifier_block *nb,
static int intel_vgpu_group_notifier(struct notifier_block *nb, static int intel_vgpu_group_notifier(struct notifier_block *nb,
unsigned long action, void *data) unsigned long action, void *data)
{ {
struct intel_vgpu *vgpu = container_of(nb, struct kvmgt_vdev *vdev = container_of(nb,
struct intel_vgpu, struct kvmgt_vdev,
vdev.group_notifier); group_notifier);
/* the only action we care about */ /* the only action we care about */
if (action == VFIO_GROUP_NOTIFY_SET_KVM) { if (action == VFIO_GROUP_NOTIFY_SET_KVM) {
vgpu->vdev.kvm = data; vdev->kvm = data;
if (!data) if (!data)
schedule_work(&vgpu->vdev.release_work); schedule_work(&vdev->release_work);
} }
return NOTIFY_OK; return NOTIFY_OK;
...@@ -745,15 +789,16 @@ static int intel_vgpu_group_notifier(struct notifier_block *nb, ...@@ -745,15 +789,16 @@ static int intel_vgpu_group_notifier(struct notifier_block *nb,
static int intel_vgpu_open(struct mdev_device *mdev) static int intel_vgpu_open(struct mdev_device *mdev)
{ {
struct intel_vgpu *vgpu = mdev_get_drvdata(mdev); struct intel_vgpu *vgpu = mdev_get_drvdata(mdev);
struct kvmgt_vdev *vdev = kvmgt_vdev(vgpu);
unsigned long events; unsigned long events;
int ret; int ret;
vgpu->vdev.iommu_notifier.notifier_call = intel_vgpu_iommu_notifier; vdev->iommu_notifier.notifier_call = intel_vgpu_iommu_notifier;
vgpu->vdev.group_notifier.notifier_call = intel_vgpu_group_notifier; vdev->group_notifier.notifier_call = intel_vgpu_group_notifier;
events = VFIO_IOMMU_NOTIFY_DMA_UNMAP; events = VFIO_IOMMU_NOTIFY_DMA_UNMAP;
ret = vfio_register_notifier(mdev_dev(mdev), VFIO_IOMMU_NOTIFY, &events, ret = vfio_register_notifier(mdev_dev(mdev), VFIO_IOMMU_NOTIFY, &events,
&vgpu->vdev.iommu_notifier); &vdev->iommu_notifier);
if (ret != 0) { if (ret != 0) {
gvt_vgpu_err("vfio_register_notifier for iommu failed: %d\n", gvt_vgpu_err("vfio_register_notifier for iommu failed: %d\n",
ret); ret);
...@@ -762,7 +807,7 @@ static int intel_vgpu_open(struct mdev_device *mdev) ...@@ -762,7 +807,7 @@ static int intel_vgpu_open(struct mdev_device *mdev)
events = VFIO_GROUP_NOTIFY_SET_KVM; events = VFIO_GROUP_NOTIFY_SET_KVM;
ret = vfio_register_notifier(mdev_dev(mdev), VFIO_GROUP_NOTIFY, &events, ret = vfio_register_notifier(mdev_dev(mdev), VFIO_GROUP_NOTIFY, &events,
&vgpu->vdev.group_notifier); &vdev->group_notifier);
if (ret != 0) { if (ret != 0) {
gvt_vgpu_err("vfio_register_notifier for group failed: %d\n", gvt_vgpu_err("vfio_register_notifier for group failed: %d\n",
ret); ret);
...@@ -781,51 +826,56 @@ static int intel_vgpu_open(struct mdev_device *mdev) ...@@ -781,51 +826,56 @@ static int intel_vgpu_open(struct mdev_device *mdev)
intel_gvt_ops->vgpu_activate(vgpu); intel_gvt_ops->vgpu_activate(vgpu);
atomic_set(&vgpu->vdev.released, 0); atomic_set(&vdev->released, 0);
return ret; return ret;
undo_group: undo_group:
vfio_unregister_notifier(mdev_dev(mdev), VFIO_GROUP_NOTIFY, vfio_unregister_notifier(mdev_dev(mdev), VFIO_GROUP_NOTIFY,
&vgpu->vdev.group_notifier); &vdev->group_notifier);
undo_iommu: undo_iommu:
vfio_unregister_notifier(mdev_dev(mdev), VFIO_IOMMU_NOTIFY, vfio_unregister_notifier(mdev_dev(mdev), VFIO_IOMMU_NOTIFY,
&vgpu->vdev.iommu_notifier); &vdev->iommu_notifier);
out: out:
return ret; return ret;
} }
static void intel_vgpu_release_msi_eventfd_ctx(struct intel_vgpu *vgpu) static void intel_vgpu_release_msi_eventfd_ctx(struct intel_vgpu *vgpu)
{ {
struct kvmgt_vdev *vdev = kvmgt_vdev(vgpu);
struct eventfd_ctx *trigger; struct eventfd_ctx *trigger;
trigger = vgpu->vdev.msi_trigger; trigger = vdev->msi_trigger;
if (trigger) { if (trigger) {
eventfd_ctx_put(trigger); eventfd_ctx_put(trigger);
vgpu->vdev.msi_trigger = NULL; vdev->msi_trigger = NULL;
} }
} }
static void __intel_vgpu_release(struct intel_vgpu *vgpu) static void __intel_vgpu_release(struct intel_vgpu *vgpu)
{ {
struct kvmgt_vdev *vdev = kvmgt_vdev(vgpu);
struct drm_i915_private *i915 = vgpu->gvt->dev_priv;
struct kvmgt_guest_info *info; struct kvmgt_guest_info *info;
int ret; int ret;
if (!handle_valid(vgpu->handle)) if (!handle_valid(vgpu->handle))
return; return;
if (atomic_cmpxchg(&vgpu->vdev.released, 0, 1)) if (atomic_cmpxchg(&vdev->released, 0, 1))
return; return;
intel_gvt_ops->vgpu_release(vgpu); intel_gvt_ops->vgpu_release(vgpu);
ret = vfio_unregister_notifier(mdev_dev(vgpu->vdev.mdev), VFIO_IOMMU_NOTIFY, ret = vfio_unregister_notifier(mdev_dev(vdev->mdev), VFIO_IOMMU_NOTIFY,
&vgpu->vdev.iommu_notifier); &vdev->iommu_notifier);
WARN(ret, "vfio_unregister_notifier for iommu failed: %d\n", ret); drm_WARN(&i915->drm, ret,
"vfio_unregister_notifier for iommu failed: %d\n", ret);
ret = vfio_unregister_notifier(mdev_dev(vgpu->vdev.mdev), VFIO_GROUP_NOTIFY, ret = vfio_unregister_notifier(mdev_dev(vdev->mdev), VFIO_GROUP_NOTIFY,
&vgpu->vdev.group_notifier); &vdev->group_notifier);
WARN(ret, "vfio_unregister_notifier for group failed: %d\n", ret); drm_WARN(&i915->drm, ret,
"vfio_unregister_notifier for group failed: %d\n", ret);
/* dereference module reference taken at open */ /* dereference module reference taken at open */
module_put(THIS_MODULE); module_put(THIS_MODULE);
...@@ -835,7 +885,7 @@ static void __intel_vgpu_release(struct intel_vgpu *vgpu) ...@@ -835,7 +885,7 @@ static void __intel_vgpu_release(struct intel_vgpu *vgpu)
intel_vgpu_release_msi_eventfd_ctx(vgpu); intel_vgpu_release_msi_eventfd_ctx(vgpu);
vgpu->vdev.kvm = NULL; vdev->kvm = NULL;
vgpu->handle = 0; vgpu->handle = 0;
} }
...@@ -848,10 +898,10 @@ static void intel_vgpu_release(struct mdev_device *mdev) ...@@ -848,10 +898,10 @@ static void intel_vgpu_release(struct mdev_device *mdev)
static void intel_vgpu_release_work(struct work_struct *work) static void intel_vgpu_release_work(struct work_struct *work)
{ {
struct intel_vgpu *vgpu = container_of(work, struct intel_vgpu, struct kvmgt_vdev *vdev = container_of(work, struct kvmgt_vdev,
vdev.release_work); release_work);
__intel_vgpu_release(vgpu); __intel_vgpu_release(vdev->vgpu);
} }
static u64 intel_vgpu_get_bar_addr(struct intel_vgpu *vgpu, int bar) static u64 intel_vgpu_get_bar_addr(struct intel_vgpu *vgpu, int bar)
...@@ -933,12 +983,13 @@ static ssize_t intel_vgpu_rw(struct mdev_device *mdev, char *buf, ...@@ -933,12 +983,13 @@ static ssize_t intel_vgpu_rw(struct mdev_device *mdev, char *buf,
size_t count, loff_t *ppos, bool is_write) size_t count, loff_t *ppos, bool is_write)
{ {
struct intel_vgpu *vgpu = mdev_get_drvdata(mdev); struct intel_vgpu *vgpu = mdev_get_drvdata(mdev);
struct kvmgt_vdev *vdev = kvmgt_vdev(vgpu);
unsigned int index = VFIO_PCI_OFFSET_TO_INDEX(*ppos); unsigned int index = VFIO_PCI_OFFSET_TO_INDEX(*ppos);
u64 pos = *ppos & VFIO_PCI_OFFSET_MASK; u64 pos = *ppos & VFIO_PCI_OFFSET_MASK;
int ret = -EINVAL; int ret = -EINVAL;
if (index >= VFIO_PCI_NUM_REGIONS + vgpu->vdev.num_regions) { if (index >= VFIO_PCI_NUM_REGIONS + vdev->num_regions) {
gvt_vgpu_err("invalid index: %u\n", index); gvt_vgpu_err("invalid index: %u\n", index);
return -EINVAL; return -EINVAL;
} }
...@@ -967,11 +1018,11 @@ static ssize_t intel_vgpu_rw(struct mdev_device *mdev, char *buf, ...@@ -967,11 +1018,11 @@ static ssize_t intel_vgpu_rw(struct mdev_device *mdev, char *buf,
case VFIO_PCI_ROM_REGION_INDEX: case VFIO_PCI_ROM_REGION_INDEX:
break; break;
default: default:
if (index >= VFIO_PCI_NUM_REGIONS + vgpu->vdev.num_regions) if (index >= VFIO_PCI_NUM_REGIONS + vdev->num_regions)
return -EINVAL; return -EINVAL;
index -= VFIO_PCI_NUM_REGIONS; index -= VFIO_PCI_NUM_REGIONS;
return vgpu->vdev.region[index].ops->rw(vgpu, buf, count, return vdev->region[index].ops->rw(vgpu, buf, count,
ppos, is_write); ppos, is_write);
} }
...@@ -1224,7 +1275,7 @@ static int intel_vgpu_set_msi_trigger(struct intel_vgpu *vgpu, ...@@ -1224,7 +1275,7 @@ static int intel_vgpu_set_msi_trigger(struct intel_vgpu *vgpu,
gvt_vgpu_err("eventfd_ctx_fdget failed\n"); gvt_vgpu_err("eventfd_ctx_fdget failed\n");
return PTR_ERR(trigger); return PTR_ERR(trigger);
} }
vgpu->vdev.msi_trigger = trigger; kvmgt_vdev(vgpu)->msi_trigger = trigger;
} else if ((flags & VFIO_IRQ_SET_DATA_NONE) && !count) } else if ((flags & VFIO_IRQ_SET_DATA_NONE) && !count)
intel_vgpu_release_msi_eventfd_ctx(vgpu); intel_vgpu_release_msi_eventfd_ctx(vgpu);
...@@ -1276,6 +1327,7 @@ static long intel_vgpu_ioctl(struct mdev_device *mdev, unsigned int cmd, ...@@ -1276,6 +1327,7 @@ static long intel_vgpu_ioctl(struct mdev_device *mdev, unsigned int cmd,
unsigned long arg) unsigned long arg)
{ {
struct intel_vgpu *vgpu = mdev_get_drvdata(mdev); struct intel_vgpu *vgpu = mdev_get_drvdata(mdev);
struct kvmgt_vdev *vdev = kvmgt_vdev(vgpu);
unsigned long minsz; unsigned long minsz;
gvt_dbg_core("vgpu%d ioctl, cmd: %d\n", vgpu->id, cmd); gvt_dbg_core("vgpu%d ioctl, cmd: %d\n", vgpu->id, cmd);
...@@ -1294,7 +1346,7 @@ static long intel_vgpu_ioctl(struct mdev_device *mdev, unsigned int cmd, ...@@ -1294,7 +1346,7 @@ static long intel_vgpu_ioctl(struct mdev_device *mdev, unsigned int cmd,
info.flags = VFIO_DEVICE_FLAGS_PCI; info.flags = VFIO_DEVICE_FLAGS_PCI;
info.flags |= VFIO_DEVICE_FLAGS_RESET; info.flags |= VFIO_DEVICE_FLAGS_RESET;
info.num_regions = VFIO_PCI_NUM_REGIONS + info.num_regions = VFIO_PCI_NUM_REGIONS +
vgpu->vdev.num_regions; vdev->num_regions;
info.num_irqs = VFIO_PCI_NUM_IRQS; info.num_irqs = VFIO_PCI_NUM_IRQS;
return copy_to_user((void __user *)arg, &info, minsz) ? return copy_to_user((void __user *)arg, &info, minsz) ?
...@@ -1385,22 +1437,22 @@ static long intel_vgpu_ioctl(struct mdev_device *mdev, unsigned int cmd, ...@@ -1385,22 +1437,22 @@ static long intel_vgpu_ioctl(struct mdev_device *mdev, unsigned int cmd,
.header.version = 1 }; .header.version = 1 };
if (info.index >= VFIO_PCI_NUM_REGIONS + if (info.index >= VFIO_PCI_NUM_REGIONS +
vgpu->vdev.num_regions) vdev->num_regions)
return -EINVAL; return -EINVAL;
info.index = info.index =
array_index_nospec(info.index, array_index_nospec(info.index,
VFIO_PCI_NUM_REGIONS + VFIO_PCI_NUM_REGIONS +
vgpu->vdev.num_regions); vdev->num_regions);
i = info.index - VFIO_PCI_NUM_REGIONS; i = info.index - VFIO_PCI_NUM_REGIONS;
info.offset = info.offset =
VFIO_PCI_INDEX_TO_OFFSET(info.index); VFIO_PCI_INDEX_TO_OFFSET(info.index);
info.size = vgpu->vdev.region[i].size; info.size = vdev->region[i].size;
info.flags = vgpu->vdev.region[i].flags; info.flags = vdev->region[i].flags;
cap_type.type = vgpu->vdev.region[i].type; cap_type.type = vdev->region[i].type;
cap_type.subtype = vgpu->vdev.region[i].subtype; cap_type.subtype = vdev->region[i].subtype;
ret = vfio_info_add_capability(&caps, ret = vfio_info_add_capability(&caps,
&cap_type.header, &cap_type.header,
...@@ -1597,12 +1649,10 @@ static struct mdev_parent_ops intel_vgpu_ops = { ...@@ -1597,12 +1649,10 @@ static struct mdev_parent_ops intel_vgpu_ops = {
static int kvmgt_host_init(struct device *dev, void *gvt, const void *ops) static int kvmgt_host_init(struct device *dev, void *gvt, const void *ops)
{ {
struct attribute **kvm_type_attrs;
struct attribute_group **kvm_vgpu_type_groups; struct attribute_group **kvm_vgpu_type_groups;
intel_gvt_ops = ops; intel_gvt_ops = ops;
if (!intel_gvt_ops->get_gvt_attrs(&kvm_type_attrs, if (!intel_gvt_ops->get_gvt_attrs(&kvm_vgpu_type_groups))
&kvm_vgpu_type_groups))
return -EFAULT; return -EFAULT;
intel_vgpu_ops.supported_type_groups = kvm_vgpu_type_groups; intel_vgpu_ops.supported_type_groups = kvm_vgpu_type_groups;
...@@ -1742,13 +1792,15 @@ static int kvmgt_guest_init(struct mdev_device *mdev) ...@@ -1742,13 +1792,15 @@ static int kvmgt_guest_init(struct mdev_device *mdev)
{ {
struct kvmgt_guest_info *info; struct kvmgt_guest_info *info;
struct intel_vgpu *vgpu; struct intel_vgpu *vgpu;
struct kvmgt_vdev *vdev;
struct kvm *kvm; struct kvm *kvm;
vgpu = mdev_get_drvdata(mdev); vgpu = mdev_get_drvdata(mdev);
if (handle_valid(vgpu->handle)) if (handle_valid(vgpu->handle))
return -EEXIST; return -EEXIST;
kvm = vgpu->vdev.kvm; vdev = kvmgt_vdev(vgpu);
kvm = vdev->kvm;
if (!kvm || kvm->mm != current->mm) { if (!kvm || kvm->mm != current->mm) {
gvt_vgpu_err("KVM is required to use Intel vGPU\n"); gvt_vgpu_err("KVM is required to use Intel vGPU\n");
return -ESRCH; return -ESRCH;
...@@ -1769,8 +1821,6 @@ static int kvmgt_guest_init(struct mdev_device *mdev) ...@@ -1769,8 +1821,6 @@ static int kvmgt_guest_init(struct mdev_device *mdev)
kvmgt_protect_table_init(info); kvmgt_protect_table_init(info);
gvt_cache_init(vgpu); gvt_cache_init(vgpu);
init_completion(&vgpu->vblank_done);
info->track_node.track_write = kvmgt_page_track_write; info->track_node.track_write = kvmgt_page_track_write;
info->track_node.track_flush_slot = kvmgt_page_track_flush_slot; info->track_node.track_flush_slot = kvmgt_page_track_flush_slot;
kvm_page_track_register_notifier(kvm, &info->track_node); kvm_page_track_register_notifier(kvm, &info->track_node);
...@@ -1778,7 +1828,7 @@ static int kvmgt_guest_init(struct mdev_device *mdev) ...@@ -1778,7 +1828,7 @@ static int kvmgt_guest_init(struct mdev_device *mdev)
info->debugfs_cache_entries = debugfs_create_ulong( info->debugfs_cache_entries = debugfs_create_ulong(
"kvmgt_nr_cache_entries", "kvmgt_nr_cache_entries",
0444, vgpu->debugfs, 0444, vgpu->debugfs,
&vgpu->vdev.nr_cache_entries); &vdev->nr_cache_entries);
return 0; return 0;
} }
...@@ -1795,9 +1845,17 @@ static bool kvmgt_guest_exit(struct kvmgt_guest_info *info) ...@@ -1795,9 +1845,17 @@ static bool kvmgt_guest_exit(struct kvmgt_guest_info *info)
return true; return true;
} }
static int kvmgt_attach_vgpu(void *vgpu, unsigned long *handle) static int kvmgt_attach_vgpu(void *p_vgpu, unsigned long *handle)
{ {
/* nothing to do here */ struct intel_vgpu *vgpu = (struct intel_vgpu *)p_vgpu;
vgpu->vdev = kzalloc(sizeof(struct kvmgt_vdev), GFP_KERNEL);
if (!vgpu->vdev)
return -ENOMEM;
kvmgt_vdev(vgpu)->vgpu = vgpu;
return 0; return 0;
} }
...@@ -1805,29 +1863,34 @@ static void kvmgt_detach_vgpu(void *p_vgpu) ...@@ -1805,29 +1863,34 @@ static void kvmgt_detach_vgpu(void *p_vgpu)
{ {
int i; int i;
struct intel_vgpu *vgpu = (struct intel_vgpu *)p_vgpu; struct intel_vgpu *vgpu = (struct intel_vgpu *)p_vgpu;
struct kvmgt_vdev *vdev = kvmgt_vdev(vgpu);
if (!vgpu->vdev.region) if (!vdev->region)
return; return;
for (i = 0; i < vgpu->vdev.num_regions; i++) for (i = 0; i < vdev->num_regions; i++)
if (vgpu->vdev.region[i].ops->release) if (vdev->region[i].ops->release)
vgpu->vdev.region[i].ops->release(vgpu, vdev->region[i].ops->release(vgpu,
&vgpu->vdev.region[i]); &vdev->region[i]);
vgpu->vdev.num_regions = 0; vdev->num_regions = 0;
kfree(vgpu->vdev.region); kfree(vdev->region);
vgpu->vdev.region = NULL; vdev->region = NULL;
kfree(vdev);
} }
static int kvmgt_inject_msi(unsigned long handle, u32 addr, u16 data) static int kvmgt_inject_msi(unsigned long handle, u32 addr, u16 data)
{ {
struct kvmgt_guest_info *info; struct kvmgt_guest_info *info;
struct intel_vgpu *vgpu; struct intel_vgpu *vgpu;
struct kvmgt_vdev *vdev;
if (!handle_valid(handle)) if (!handle_valid(handle))
return -ESRCH; return -ESRCH;
info = (struct kvmgt_guest_info *)handle; info = (struct kvmgt_guest_info *)handle;
vgpu = info->vgpu; vgpu = info->vgpu;
vdev = kvmgt_vdev(vgpu);
/* /*
* When guest is poweroff, msi_trigger is set to NULL, but vgpu's * When guest is poweroff, msi_trigger is set to NULL, but vgpu's
...@@ -1838,10 +1901,10 @@ static int kvmgt_inject_msi(unsigned long handle, u32 addr, u16 data) ...@@ -1838,10 +1901,10 @@ static int kvmgt_inject_msi(unsigned long handle, u32 addr, u16 data)
* enabled by guest. so if msi_trigger is null, success is still * enabled by guest. so if msi_trigger is null, success is still
* returned and don't inject interrupt into guest. * returned and don't inject interrupt into guest.
*/ */
if (vgpu->vdev.msi_trigger == NULL) if (vdev->msi_trigger == NULL)
return 0; return 0;
if (eventfd_signal(vgpu->vdev.msi_trigger, 1) == 1) if (eventfd_signal(vdev->msi_trigger, 1) == 1)
return 0; return 0;
return -EFAULT; return -EFAULT;
...@@ -1867,26 +1930,26 @@ static unsigned long kvmgt_gfn_to_pfn(unsigned long handle, unsigned long gfn) ...@@ -1867,26 +1930,26 @@ static unsigned long kvmgt_gfn_to_pfn(unsigned long handle, unsigned long gfn)
static int kvmgt_dma_map_guest_page(unsigned long handle, unsigned long gfn, static int kvmgt_dma_map_guest_page(unsigned long handle, unsigned long gfn,
unsigned long size, dma_addr_t *dma_addr) unsigned long size, dma_addr_t *dma_addr)
{ {
struct kvmgt_guest_info *info;
struct intel_vgpu *vgpu; struct intel_vgpu *vgpu;
struct kvmgt_vdev *vdev;
struct gvt_dma *entry; struct gvt_dma *entry;
int ret; int ret;
if (!handle_valid(handle)) if (!handle_valid(handle))
return -EINVAL; return -EINVAL;
info = (struct kvmgt_guest_info *)handle; vgpu = ((struct kvmgt_guest_info *)handle)->vgpu;
vgpu = info->vgpu; vdev = kvmgt_vdev(vgpu);
mutex_lock(&info->vgpu->vdev.cache_lock); mutex_lock(&vdev->cache_lock);
entry = __gvt_cache_find_gfn(info->vgpu, gfn); entry = __gvt_cache_find_gfn(vgpu, gfn);
if (!entry) { if (!entry) {
ret = gvt_dma_map_page(vgpu, gfn, dma_addr, size); ret = gvt_dma_map_page(vgpu, gfn, dma_addr, size);
if (ret) if (ret)
goto err_unlock; goto err_unlock;
ret = __gvt_cache_add(info->vgpu, gfn, *dma_addr, size); ret = __gvt_cache_add(vgpu, gfn, *dma_addr, size);
if (ret) if (ret)
goto err_unmap; goto err_unmap;
} else if (entry->size != size) { } else if (entry->size != size) {
...@@ -1898,7 +1961,7 @@ static int kvmgt_dma_map_guest_page(unsigned long handle, unsigned long gfn, ...@@ -1898,7 +1961,7 @@ static int kvmgt_dma_map_guest_page(unsigned long handle, unsigned long gfn,
if (ret) if (ret)
goto err_unlock; goto err_unlock;
ret = __gvt_cache_add(info->vgpu, gfn, *dma_addr, size); ret = __gvt_cache_add(vgpu, gfn, *dma_addr, size);
if (ret) if (ret)
goto err_unmap; goto err_unmap;
} else { } else {
...@@ -1906,19 +1969,20 @@ static int kvmgt_dma_map_guest_page(unsigned long handle, unsigned long gfn, ...@@ -1906,19 +1969,20 @@ static int kvmgt_dma_map_guest_page(unsigned long handle, unsigned long gfn,
*dma_addr = entry->dma_addr; *dma_addr = entry->dma_addr;
} }
mutex_unlock(&info->vgpu->vdev.cache_lock); mutex_unlock(&vdev->cache_lock);
return 0; return 0;
err_unmap: err_unmap:
gvt_dma_unmap_page(vgpu, gfn, *dma_addr, size); gvt_dma_unmap_page(vgpu, gfn, *dma_addr, size);
err_unlock: err_unlock:
mutex_unlock(&info->vgpu->vdev.cache_lock); mutex_unlock(&vdev->cache_lock);
return ret; return ret;
} }
static int kvmgt_dma_pin_guest_page(unsigned long handle, dma_addr_t dma_addr) static int kvmgt_dma_pin_guest_page(unsigned long handle, dma_addr_t dma_addr)
{ {
struct kvmgt_guest_info *info; struct kvmgt_guest_info *info;
struct kvmgt_vdev *vdev;
struct gvt_dma *entry; struct gvt_dma *entry;
int ret = 0; int ret = 0;
...@@ -1926,14 +1990,15 @@ static int kvmgt_dma_pin_guest_page(unsigned long handle, dma_addr_t dma_addr) ...@@ -1926,14 +1990,15 @@ static int kvmgt_dma_pin_guest_page(unsigned long handle, dma_addr_t dma_addr)
return -ENODEV; return -ENODEV;
info = (struct kvmgt_guest_info *)handle; info = (struct kvmgt_guest_info *)handle;
vdev = kvmgt_vdev(info->vgpu);
mutex_lock(&info->vgpu->vdev.cache_lock); mutex_lock(&vdev->cache_lock);
entry = __gvt_cache_find_dma_addr(info->vgpu, dma_addr); entry = __gvt_cache_find_dma_addr(info->vgpu, dma_addr);
if (entry) if (entry)
kref_get(&entry->ref); kref_get(&entry->ref);
else else
ret = -ENOMEM; ret = -ENOMEM;
mutex_unlock(&info->vgpu->vdev.cache_lock); mutex_unlock(&vdev->cache_lock);
return ret; return ret;
} }
...@@ -1949,19 +2014,21 @@ static void __gvt_dma_release(struct kref *ref) ...@@ -1949,19 +2014,21 @@ static void __gvt_dma_release(struct kref *ref)
static void kvmgt_dma_unmap_guest_page(unsigned long handle, dma_addr_t dma_addr) static void kvmgt_dma_unmap_guest_page(unsigned long handle, dma_addr_t dma_addr)
{ {
struct kvmgt_guest_info *info; struct intel_vgpu *vgpu;
struct kvmgt_vdev *vdev;
struct gvt_dma *entry; struct gvt_dma *entry;
if (!handle_valid(handle)) if (!handle_valid(handle))
return; return;
info = (struct kvmgt_guest_info *)handle; vgpu = ((struct kvmgt_guest_info *)handle)->vgpu;
vdev = kvmgt_vdev(vgpu);
mutex_lock(&info->vgpu->vdev.cache_lock); mutex_lock(&vdev->cache_lock);
entry = __gvt_cache_find_dma_addr(info->vgpu, dma_addr); entry = __gvt_cache_find_dma_addr(vgpu, dma_addr);
if (entry) if (entry)
kref_put(&entry->ref, __gvt_dma_release); kref_put(&entry->ref, __gvt_dma_release);
mutex_unlock(&info->vgpu->vdev.cache_lock); mutex_unlock(&vdev->cache_lock);
} }
static int kvmgt_rw_gpa(unsigned long handle, unsigned long gpa, static int kvmgt_rw_gpa(unsigned long handle, unsigned long gpa,
......
...@@ -102,6 +102,7 @@ static void failsafe_emulate_mmio_rw(struct intel_vgpu *vgpu, u64 pa, ...@@ -102,6 +102,7 @@ static void failsafe_emulate_mmio_rw(struct intel_vgpu *vgpu, u64 pa,
int intel_vgpu_emulate_mmio_read(struct intel_vgpu *vgpu, u64 pa, int intel_vgpu_emulate_mmio_read(struct intel_vgpu *vgpu, u64 pa,
void *p_data, unsigned int bytes) void *p_data, unsigned int bytes)
{ {
struct drm_i915_private *i915 = vgpu->gvt->dev_priv;
struct intel_gvt *gvt = vgpu->gvt; struct intel_gvt *gvt = vgpu->gvt;
unsigned int offset = 0; unsigned int offset = 0;
int ret = -EINVAL; int ret = -EINVAL;
...@@ -114,15 +115,17 @@ int intel_vgpu_emulate_mmio_read(struct intel_vgpu *vgpu, u64 pa, ...@@ -114,15 +115,17 @@ int intel_vgpu_emulate_mmio_read(struct intel_vgpu *vgpu, u64 pa,
offset = intel_vgpu_gpa_to_mmio_offset(vgpu, pa); offset = intel_vgpu_gpa_to_mmio_offset(vgpu, pa);
if (WARN_ON(bytes > 8)) if (drm_WARN_ON(&i915->drm, bytes > 8))
goto err; goto err;
if (reg_is_gtt(gvt, offset)) { if (reg_is_gtt(gvt, offset)) {
if (WARN_ON(!IS_ALIGNED(offset, 4) && !IS_ALIGNED(offset, 8))) if (drm_WARN_ON(&i915->drm, !IS_ALIGNED(offset, 4) &&
!IS_ALIGNED(offset, 8)))
goto err; goto err;
if (WARN_ON(bytes != 4 && bytes != 8)) if (drm_WARN_ON(&i915->drm, bytes != 4 && bytes != 8))
goto err; goto err;
if (WARN_ON(!reg_is_gtt(gvt, offset + bytes - 1))) if (drm_WARN_ON(&i915->drm,
!reg_is_gtt(gvt, offset + bytes - 1)))
goto err; goto err;
ret = intel_vgpu_emulate_ggtt_mmio_read(vgpu, offset, ret = intel_vgpu_emulate_ggtt_mmio_read(vgpu, offset,
...@@ -132,16 +135,16 @@ int intel_vgpu_emulate_mmio_read(struct intel_vgpu *vgpu, u64 pa, ...@@ -132,16 +135,16 @@ int intel_vgpu_emulate_mmio_read(struct intel_vgpu *vgpu, u64 pa,
goto out; goto out;
} }
if (WARN_ON_ONCE(!reg_is_mmio(gvt, offset))) { if (drm_WARN_ON_ONCE(&i915->drm, !reg_is_mmio(gvt, offset))) {
ret = intel_gvt_hypervisor_read_gpa(vgpu, pa, p_data, bytes); ret = intel_gvt_hypervisor_read_gpa(vgpu, pa, p_data, bytes);
goto out; goto out;
} }
if (WARN_ON(!reg_is_mmio(gvt, offset + bytes - 1))) if (drm_WARN_ON(&i915->drm, !reg_is_mmio(gvt, offset + bytes - 1)))
goto err; goto err;
if (!intel_gvt_mmio_is_unalign(gvt, offset)) { if (!intel_gvt_mmio_is_unalign(gvt, offset)) {
if (WARN_ON(!IS_ALIGNED(offset, bytes))) if (drm_WARN_ON(&i915->drm, !IS_ALIGNED(offset, bytes)))
goto err; goto err;
} }
...@@ -174,6 +177,7 @@ int intel_vgpu_emulate_mmio_read(struct intel_vgpu *vgpu, u64 pa, ...@@ -174,6 +177,7 @@ int intel_vgpu_emulate_mmio_read(struct intel_vgpu *vgpu, u64 pa,
int intel_vgpu_emulate_mmio_write(struct intel_vgpu *vgpu, u64 pa, int intel_vgpu_emulate_mmio_write(struct intel_vgpu *vgpu, u64 pa,
void *p_data, unsigned int bytes) void *p_data, unsigned int bytes)
{ {
struct drm_i915_private *i915 = vgpu->gvt->dev_priv;
struct intel_gvt *gvt = vgpu->gvt; struct intel_gvt *gvt = vgpu->gvt;
unsigned int offset = 0; unsigned int offset = 0;
int ret = -EINVAL; int ret = -EINVAL;
...@@ -187,15 +191,17 @@ int intel_vgpu_emulate_mmio_write(struct intel_vgpu *vgpu, u64 pa, ...@@ -187,15 +191,17 @@ int intel_vgpu_emulate_mmio_write(struct intel_vgpu *vgpu, u64 pa,
offset = intel_vgpu_gpa_to_mmio_offset(vgpu, pa); offset = intel_vgpu_gpa_to_mmio_offset(vgpu, pa);
if (WARN_ON(bytes > 8)) if (drm_WARN_ON(&i915->drm, bytes > 8))
goto err; goto err;
if (reg_is_gtt(gvt, offset)) { if (reg_is_gtt(gvt, offset)) {
if (WARN_ON(!IS_ALIGNED(offset, 4) && !IS_ALIGNED(offset, 8))) if (drm_WARN_ON(&i915->drm, !IS_ALIGNED(offset, 4) &&
!IS_ALIGNED(offset, 8)))
goto err; goto err;
if (WARN_ON(bytes != 4 && bytes != 8)) if (drm_WARN_ON(&i915->drm, bytes != 4 && bytes != 8))
goto err; goto err;
if (WARN_ON(!reg_is_gtt(gvt, offset + bytes - 1))) if (drm_WARN_ON(&i915->drm,
!reg_is_gtt(gvt, offset + bytes - 1)))
goto err; goto err;
ret = intel_vgpu_emulate_ggtt_mmio_write(vgpu, offset, ret = intel_vgpu_emulate_ggtt_mmio_write(vgpu, offset,
...@@ -205,7 +211,7 @@ int intel_vgpu_emulate_mmio_write(struct intel_vgpu *vgpu, u64 pa, ...@@ -205,7 +211,7 @@ int intel_vgpu_emulate_mmio_write(struct intel_vgpu *vgpu, u64 pa,
goto out; goto out;
} }
if (WARN_ON_ONCE(!reg_is_mmio(gvt, offset))) { if (drm_WARN_ON_ONCE(&i915->drm, !reg_is_mmio(gvt, offset))) {
ret = intel_gvt_hypervisor_write_gpa(vgpu, pa, p_data, bytes); ret = intel_gvt_hypervisor_write_gpa(vgpu, pa, p_data, bytes);
goto out; goto out;
} }
......
...@@ -357,7 +357,7 @@ static void handle_tlb_pending_event(struct intel_vgpu *vgpu, int ring_id) ...@@ -357,7 +357,7 @@ static void handle_tlb_pending_event(struct intel_vgpu *vgpu, int ring_id)
if (!regs) if (!regs)
return; return;
if (WARN_ON(ring_id >= cnt)) if (drm_WARN_ON(&dev_priv->drm, ring_id >= cnt))
return; return;
if (!test_and_clear_bit(ring_id, (void *)s->tlb_handle_pending)) if (!test_and_clear_bit(ring_id, (void *)s->tlb_handle_pending))
...@@ -406,7 +406,7 @@ static void switch_mocs(struct intel_vgpu *pre, struct intel_vgpu *next, ...@@ -406,7 +406,7 @@ static void switch_mocs(struct intel_vgpu *pre, struct intel_vgpu *next,
int i; int i;
dev_priv = pre ? pre->gvt->dev_priv : next->gvt->dev_priv; dev_priv = pre ? pre->gvt->dev_priv : next->gvt->dev_priv;
if (WARN_ON(ring_id >= ARRAY_SIZE(regs))) if (drm_WARN_ON(&dev_priv->drm, ring_id >= ARRAY_SIZE(regs)))
return; return;
if (ring_id == RCS0 && IS_GEN(dev_priv, 9)) if (ring_id == RCS0 && IS_GEN(dev_priv, 9))
...@@ -553,7 +553,7 @@ void intel_gvt_switch_mmio(struct intel_vgpu *pre, ...@@ -553,7 +553,7 @@ void intel_gvt_switch_mmio(struct intel_vgpu *pre,
{ {
struct drm_i915_private *dev_priv; struct drm_i915_private *dev_priv;
if (WARN_ON(!pre && !next)) if (WARN(!pre && !next, "switch ring %d from host to HOST\n", ring_id))
return; return;
gvt_dbg_render("switch ring %d from %s to %s\n", ring_id, gvt_dbg_render("switch ring %d from %s to %s\n", ring_id,
......
...@@ -1310,6 +1310,7 @@ int intel_vgpu_select_submission_ops(struct intel_vgpu *vgpu, ...@@ -1310,6 +1310,7 @@ int intel_vgpu_select_submission_ops(struct intel_vgpu *vgpu,
intel_engine_mask_t engine_mask, intel_engine_mask_t engine_mask,
unsigned int interface) unsigned int interface)
{ {
struct drm_i915_private *i915 = vgpu->gvt->dev_priv;
struct intel_vgpu_submission *s = &vgpu->submission; struct intel_vgpu_submission *s = &vgpu->submission;
const struct intel_vgpu_submission_ops *ops[] = { const struct intel_vgpu_submission_ops *ops[] = {
[INTEL_VGPU_EXECLIST_SUBMISSION] = [INTEL_VGPU_EXECLIST_SUBMISSION] =
...@@ -1317,10 +1318,11 @@ int intel_vgpu_select_submission_ops(struct intel_vgpu *vgpu, ...@@ -1317,10 +1318,11 @@ int intel_vgpu_select_submission_ops(struct intel_vgpu *vgpu,
}; };
int ret; int ret;
if (WARN_ON(interface >= ARRAY_SIZE(ops))) if (drm_WARN_ON(&i915->drm, interface >= ARRAY_SIZE(ops)))
return -EINVAL; return -EINVAL;
if (WARN_ON(interface == 0 && engine_mask != ALL_ENGINES)) if (drm_WARN_ON(&i915->drm,
interface == 0 && engine_mask != ALL_ENGINES))
return -EINVAL; return -EINVAL;
if (s->active) if (s->active)
......
...@@ -37,6 +37,7 @@ ...@@ -37,6 +37,7 @@
void populate_pvinfo_page(struct intel_vgpu *vgpu) void populate_pvinfo_page(struct intel_vgpu *vgpu)
{ {
struct drm_i915_private *i915 = vgpu->gvt->dev_priv;
/* setup the ballooning information */ /* setup the ballooning information */
vgpu_vreg64_t(vgpu, vgtif_reg(magic)) = VGT_MAGIC; vgpu_vreg64_t(vgpu, vgtif_reg(magic)) = VGT_MAGIC;
vgpu_vreg_t(vgpu, vgtif_reg(version_major)) = 1; vgpu_vreg_t(vgpu, vgtif_reg(version_major)) = 1;
...@@ -69,7 +70,7 @@ void populate_pvinfo_page(struct intel_vgpu *vgpu) ...@@ -69,7 +70,7 @@ void populate_pvinfo_page(struct intel_vgpu *vgpu)
vgpu_hidden_gmadr_base(vgpu), vgpu_hidden_sz(vgpu)); vgpu_hidden_gmadr_base(vgpu), vgpu_hidden_sz(vgpu));
gvt_dbg_core("fence size %d\n", vgpu_fence_sz(vgpu)); gvt_dbg_core("fence size %d\n", vgpu_fence_sz(vgpu));
WARN_ON(sizeof(struct vgt_if) != VGT_PVINFO_SIZE); drm_WARN_ON(&i915->drm, sizeof(struct vgt_if) != VGT_PVINFO_SIZE);
} }
#define VGPU_MAX_WEIGHT 16 #define VGPU_MAX_WEIGHT 16
...@@ -270,11 +271,12 @@ void intel_gvt_release_vgpu(struct intel_vgpu *vgpu) ...@@ -270,11 +271,12 @@ void intel_gvt_release_vgpu(struct intel_vgpu *vgpu)
*/ */
void intel_gvt_destroy_vgpu(struct intel_vgpu *vgpu) void intel_gvt_destroy_vgpu(struct intel_vgpu *vgpu)
{ {
struct drm_i915_private *i915 = vgpu->gvt->dev_priv;
struct intel_gvt *gvt = vgpu->gvt; struct intel_gvt *gvt = vgpu->gvt;
mutex_lock(&vgpu->vgpu_lock); mutex_lock(&vgpu->vgpu_lock);
WARN(vgpu->active, "vGPU is still active!\n"); drm_WARN(&i915->drm, vgpu->active, "vGPU is still active!\n");
intel_gvt_debugfs_remove_vgpu(vgpu); intel_gvt_debugfs_remove_vgpu(vgpu);
intel_vgpu_clean_sched_policy(vgpu); intel_vgpu_clean_sched_policy(vgpu);
...@@ -426,9 +428,7 @@ static struct intel_vgpu *__intel_gvt_create_vgpu(struct intel_gvt *gvt, ...@@ -426,9 +428,7 @@ static struct intel_vgpu *__intel_gvt_create_vgpu(struct intel_gvt *gvt,
if (ret) if (ret)
goto out_clean_sched_policy; goto out_clean_sched_policy;
/*TODO: add more platforms support */ ret = intel_gvt_hypervisor_set_edid(vgpu, PORT_D);
if (IS_SKYLAKE(gvt->dev_priv) || IS_KABYLAKE(gvt->dev_priv))
ret = intel_gvt_hypervisor_set_edid(vgpu, PORT_D);
if (ret) if (ret)
goto out_clean_sched_policy; goto out_clean_sched_policy;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment