Skip to content

Commit

Permalink
drm/i915/gvt: clean up intel_gvt.h as interface for i915 core
Browse files Browse the repository at this point in the history
i915 core should only call functions and structures exposed through
intel_gvt.h. Remove internal gvt.h and i915_pvinfo.h.

Change for internal intel_gvt structure as private handler which
not requires to expose gvt internal structure for i915 core.

v2: Fix per Chris's comment
- carefully handle dev_priv->gvt assignment
- add necessary bracket for macro helper
- forward declartion struct intel_gvt
- keep free operation within same file handling alloc

v3: fix use after free and remove intel_gvt.initialized

v4: change to_gvt() to an inline

Reviewed-by: Chris Wilson <chris@chris-wilson.co.uk>
Signed-off-by: Zhenyu Wang <zhenyuw@linux.intel.com>
  • Loading branch information
Zhenyu Wang committed Oct 20, 2016
1 parent 1140f9e commit feddf6e
Show file tree
Hide file tree
Showing 20 changed files with 44 additions and 14 deletions.
1 change: 1 addition & 0 deletions drivers/gpu/drm/i915/gvt/aperture_gm.c
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
*/

#include "i915_drv.h"
#include "gvt.h"

#define MB_TO_BYTES(mb) ((mb) << 20ULL)
#define BYTES_TO_MB(b) ((b) >> 20ULL)
Expand Down
1 change: 1 addition & 0 deletions drivers/gpu/drm/i915/gvt/cfg_space.c
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
*/

#include "i915_drv.h"
#include "gvt.h"

enum {
INTEL_GVT_PCI_BAR_GTTMMIO = 0,
Expand Down
2 changes: 2 additions & 0 deletions drivers/gpu/drm/i915/gvt/cmd_parser.c
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@

#include <linux/slab.h>
#include "i915_drv.h"
#include "gvt.h"
#include "i915_pvinfo.h"
#include "trace.h"

#define INVALID_OP (~0U)
Expand Down
1 change: 1 addition & 0 deletions drivers/gpu/drm/i915/gvt/display.c
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
*/

#include "i915_drv.h"
#include "gvt.h"

static int get_edp_pipe(struct intel_vgpu *vgpu)
{
Expand Down
1 change: 1 addition & 0 deletions drivers/gpu/drm/i915/gvt/edid.c
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
*/

#include "i915_drv.h"
#include "gvt.h"

#define GMBUS1_TOTAL_BYTES_SHIFT 16
#define GMBUS1_TOTAL_BYTES_MASK 0x1ff
Expand Down
1 change: 1 addition & 0 deletions drivers/gpu/drm/i915/gvt/execlist.c
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
*/

#include "i915_drv.h"
#include "gvt.h"

#define _EL_OFFSET_STATUS 0x234
#define _EL_OFFSET_STATUS_BUF 0x370
Expand Down
2 changes: 2 additions & 0 deletions drivers/gpu/drm/i915/gvt/firmware.c
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@
#include <linux/crc32.h>

#include "i915_drv.h"
#include "gvt.h"
#include "i915_pvinfo.h"

#define FIRMWARE_VERSION (0x0)

Expand Down
2 changes: 2 additions & 0 deletions drivers/gpu/drm/i915/gvt/gtt.c
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@
*/

#include "i915_drv.h"
#include "gvt.h"
#include "i915_pvinfo.h"
#include "trace.h"

static bool enable_out_of_sync = false;
Expand Down
19 changes: 13 additions & 6 deletions drivers/gpu/drm/i915/gvt/gvt.c
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
#include <linux/kthread.h>

#include "i915_drv.h"
#include "gvt.h"

struct intel_gvt_host intel_gvt_host;

Expand Down Expand Up @@ -173,9 +174,9 @@ static int init_service_thread(struct intel_gvt *gvt)
*/
void intel_gvt_clean_device(struct drm_i915_private *dev_priv)
{
struct intel_gvt *gvt = &dev_priv->gvt;
struct intel_gvt *gvt = to_gvt(dev_priv);

if (WARN_ON(!gvt->initialized))
if (WARN_ON(!gvt))
return;

clean_service_thread(gvt);
Expand All @@ -188,7 +189,8 @@ void intel_gvt_clean_device(struct drm_i915_private *dev_priv)
intel_gvt_clean_mmio_info(gvt);
intel_gvt_free_firmware(gvt);

gvt->initialized = false;
kfree(dev_priv->gvt);
dev_priv->gvt = NULL;
}

/**
Expand All @@ -204,7 +206,7 @@ void intel_gvt_clean_device(struct drm_i915_private *dev_priv)
*/
int intel_gvt_init_device(struct drm_i915_private *dev_priv)
{
struct intel_gvt *gvt = &dev_priv->gvt;
struct intel_gvt *gvt;
int ret;

/*
Expand All @@ -214,9 +216,13 @@ int intel_gvt_init_device(struct drm_i915_private *dev_priv)
if (WARN_ON(!intel_gvt_host.initialized))
return -EINVAL;

if (WARN_ON(gvt->initialized))
if (WARN_ON(dev_priv->gvt))
return -EEXIST;

gvt = kzalloc(sizeof(struct intel_gvt), GFP_KERNEL);
if (!gvt)
return -ENOMEM;

gvt_dbg_core("init gvt device\n");

mutex_init(&gvt->lock);
Expand Down Expand Up @@ -261,7 +267,7 @@ int intel_gvt_init_device(struct drm_i915_private *dev_priv)
goto out_clean_cmd_parser;

gvt_dbg_core("gvt device creation is done\n");
gvt->initialized = true;
dev_priv->gvt = gvt;
return 0;

out_clean_cmd_parser:
Expand All @@ -280,5 +286,6 @@ int intel_gvt_init_device(struct drm_i915_private *dev_priv)
intel_gvt_free_firmware(gvt);
out_clean_mmio_info:
intel_gvt_clean_mmio_info(gvt);
kfree(gvt);
return ret;
}
7 changes: 5 additions & 2 deletions drivers/gpu/drm/i915/gvt/gvt.h
Original file line number Diff line number Diff line change
Expand Up @@ -192,8 +192,6 @@ struct intel_gvt_opregion {

struct intel_gvt {
struct mutex lock;
bool initialized;

struct drm_i915_private *dev_priv;
struct idr vgpu_idr; /* vGPU IDR pool */

Expand All @@ -213,6 +211,11 @@ struct intel_gvt {
unsigned long service_request;
};

static inline struct intel_gvt *to_gvt(struct drm_i915_private *i915)
{
return i915->gvt;
}

enum {
INTEL_GVT_REQUEST_EMULATE_VBLANK = 0,
};
Expand Down
2 changes: 2 additions & 0 deletions drivers/gpu/drm/i915/gvt/handlers.c
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@
*/

#include "i915_drv.h"
#include "gvt.h"
#include "i915_pvinfo.h"

/* XXX FIXME i915 has changed PP_XXX definition */
#define PCH_PP_STATUS _MMIO(0xc7200)
Expand Down
1 change: 1 addition & 0 deletions drivers/gpu/drm/i915/gvt/interrupt.c
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
*/

#include "i915_drv.h"
#include "gvt.h"

/* common offset among interrupt control registers */
#define regbase_to_isr(base) (base)
Expand Down
1 change: 1 addition & 0 deletions drivers/gpu/drm/i915/gvt/mmio.c
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
*/

#include "i915_drv.h"
#include "gvt.h"

/**
* intel_vgpu_gpa_to_mmio_offset - translate a GPA to MMIO offset
Expand Down
1 change: 1 addition & 0 deletions drivers/gpu/drm/i915/gvt/opregion.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@

#include <linux/acpi.h>
#include "i915_drv.h"
#include "gvt.h"

static int init_vgpu_opregion(struct intel_vgpu *vgpu, u32 gpa)
{
Expand Down
1 change: 1 addition & 0 deletions drivers/gpu/drm/i915/gvt/render.c
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
*/

#include "i915_drv.h"
#include "gvt.h"

struct render_mmio {
int ring_id;
Expand Down
1 change: 1 addition & 0 deletions drivers/gpu/drm/i915/gvt/sched_policy.c
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
*/

#include "i915_drv.h"
#include "gvt.h"

static bool vgpu_has_pending_workload(struct intel_vgpu *vgpu)
{
Expand Down
5 changes: 3 additions & 2 deletions drivers/gpu/drm/i915/gvt/scheduler.c
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,11 @@
*
*/

#include "i915_drv.h"

#include <linux/kthread.h>

#include "i915_drv.h"
#include "gvt.h"

#define RING_CTX_OFF(x) \
offsetof(struct execlist_ring_context, x)

Expand Down
2 changes: 2 additions & 0 deletions drivers/gpu/drm/i915/gvt/vgpu.c
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@
*/

#include "i915_drv.h"
#include "gvt.h"
#include "i915_pvinfo.h"

static void clean_vgpu_mmio(struct intel_vgpu *vgpu)
{
Expand Down
4 changes: 2 additions & 2 deletions drivers/gpu/drm/i915/i915_drv.h
Original file line number Diff line number Diff line change
Expand Up @@ -1778,7 +1778,7 @@ struct drm_i915_private {

struct i915_virtual_gpu vgpu;

struct intel_gvt gvt;
struct intel_gvt *gvt;

struct intel_guc guc;

Expand Down Expand Up @@ -2992,7 +2992,7 @@ int intel_wait_for_register_fw(struct drm_i915_private *dev_priv,

static inline bool intel_gvt_active(struct drm_i915_private *dev_priv)
{
return dev_priv->gvt.initialized;
return dev_priv->gvt;
}

static inline bool intel_vgpu_active(struct drm_i915_private *dev_priv)
Expand Down
3 changes: 1 addition & 2 deletions drivers/gpu/drm/i915/intel_gvt.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,7 @@
#ifndef _INTEL_GVT_H_
#define _INTEL_GVT_H_

#include "i915_pvinfo.h"
#include "gvt/gvt.h"
struct intel_gvt;

#ifdef CONFIG_DRM_I915_GVT
int intel_gvt_init(struct drm_i915_private *dev_priv);
Expand Down

0 comments on commit feddf6e

Please sign in to comment.