From patchwork Tue Sep 30 10:05:33 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jike Song X-Patchwork-Id: 5001821 Return-Path: X-Original-To: patchwork-intel-gfx@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork2.web.kernel.org (Postfix) with ESMTP id BD5AFBEEA6 for ; Tue, 30 Sep 2014 10:11:41 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id DE8C22018E for ; Tue, 30 Sep 2014 10:11:40 +0000 (UTC) Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) by mail.kernel.org (Postfix) with ESMTP id E3D032016C for ; Tue, 30 Sep 2014 10:11:39 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 48BB86EAE0; Tue, 30 Sep 2014 03:11:39 -0700 (PDT) X-Original-To: intel-gfx@lists.freedesktop.org Delivered-To: intel-gfx@lists.freedesktop.org Received: from mga14.intel.com (mga14.intel.com [192.55.52.115]) by gabe.freedesktop.org (Postfix) with ESMTP id 3AB386E6C5 for ; Tue, 30 Sep 2014 03:11:36 -0700 (PDT) Received: from azsmga001.ch.intel.com ([10.2.17.19]) by fmsmga103.fm.intel.com with ESMTP; 30 Sep 2014 03:02:12 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.04,625,1406617200"; d="scan'208";a="480959882" Received: from kvmgt.bj.intel.com ([10.238.154.64]) by azsmga001.ch.intel.com with ESMTP; 30 Sep 2014 03:11:34 -0700 From: Jike Song To: daniel.vetter@ffwll.ch, intel-gfx@lists.freedesktop.org Date: Tue, 30 Sep 2014 18:05:33 +0800 Message-Id: <1412071538-19059-4-git-send-email-jike.song@intel.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1412071538-19059-1-git-send-email-jike.song@intel.com> References: <1412071538-19059-1-git-send-email-jike.song@intel.com> Subject: [Intel-gfx] [RFC PATCH 3/8] drm/i915: add the vgt implementation of MMIO/GTT mediations X-BeenThere: intel-gfx@lists.freedesktop.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: Intel graphics driver community testing & development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: intel-gfx-bounces@lists.freedesktop.org Sender: "Intel-gfx" X-Spam-Status: No, score=-4.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_MED, RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP vgt mediates GPU operations from host i915, in the same way as mediating GPU operations from normal VMs. This way vgt can have centralized management about sharing among host and other VMs. To achieve that, we add a hook in critical wrapper interfaces (MMIO/GTT). This patch only adds the MMIO/GTT accessing functions, without changing the existing i915 MMIO/GTT access behaviors. Signed-off-by: Jike Song --- drivers/gpu/drm/i915/i915_vgt.h | 21 ++++++++ drivers/gpu/drm/i915/vgt/vgt.c | 105 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 126 insertions(+) diff --git a/drivers/gpu/drm/i915/i915_vgt.h b/drivers/gpu/drm/i915/i915_vgt.h index c6a4144..03e7f00 100644 --- a/drivers/gpu/drm/i915/i915_vgt.h +++ b/drivers/gpu/drm/i915/i915_vgt.h @@ -1,9 +1,14 @@ #ifndef _I915_VGT_H_ #define _I915_VGT_H_ +struct drm_i915_private; + #ifdef CONFIG_I915_IGVT bool i915_start_vgt(struct pci_dev *); +void i915_vgt_record_priv(struct drm_i915_private *); +bool vgt_emulate_host_read(u32, void *, int, bool, bool); +bool vgt_emulate_host_write(u32, void *, int, bool, bool); #else /* !CONFIG_I915_IGVT */ @@ -12,6 +17,22 @@ static inline bool i915_start_vgt(struct pci_dev *pdev) return false; } +static inline void i915_vgt_record_priv(struct drm_i915_private *priv) +{ +} + +static inline bool vgt_emulate_host_read(u32 reg, void *val, int len, + bool is_gtt, bool trace) +{ + return false; +} + +static inline bool vgt_emulate_host_write(u32 reg, void *val, int len, + bool is_gtt, bool trace) +{ + return false; +} + #endif /* CONFIG_I915_IGVT */ #endif diff --git a/drivers/gpu/drm/i915/vgt/vgt.c b/drivers/gpu/drm/i915/vgt/vgt.c index 07ccee6..f33baf3 100644 --- a/drivers/gpu/drm/i915/vgt/vgt.c +++ b/drivers/gpu/drm/i915/vgt/vgt.c @@ -2,8 +2,12 @@ #include #include +#include "../i915_drv.h" #include "vgt.h" +const static bool vgt_integration_done = false; +static struct drm_i915_private *dev_priv = NULL; + /** * Initialize Intel GVT-g @@ -16,3 +20,104 @@ bool i915_start_vgt(struct pci_dev *pdev) /* vgt is not yet integrated, this only means testing */ return false; } + +static bool vgt_mmio_read(off_t reg, void *val, int len, bool trace) +{ + switch (len) { + case 1: + *(u8 *)val = dev_priv->uncore.funcs.mmio_readb(dev_priv, + reg, trace); + break; + case 2: + *(u16 *)val = dev_priv->uncore.funcs.mmio_readw(dev_priv, + reg, trace); + break; + case 4: + *(u32 *)val = dev_priv->uncore.funcs.mmio_readl(dev_priv, + reg, trace); + break; + case 8: + *(u64 *)val = dev_priv->uncore.funcs.mmio_readq(dev_priv, + reg, trace); + break; + default: + return false; + } + return true; +} + +static bool vgt_mmio_write(off_t reg, void *val, int len, bool trace) +{ + switch (len) { + case 1: + dev_priv->uncore.funcs.mmio_writeb(dev_priv, + reg, *(u8 *)val, trace); + break; + case 2: + dev_priv->uncore.funcs.mmio_writew(dev_priv, + reg, *(u16 *)val, trace); + break; + case 4: + dev_priv->uncore.funcs.mmio_writel(dev_priv, + reg, *(u32 *)val, trace); + break; + case 8: + dev_priv->uncore.funcs.mmio_writeq(dev_priv, + reg, *(u64 *)val, trace); + break; + default: + return false; + } + return true; +} + +static bool vgt_gtt_read(off_t reg, void *val, int len) +{ + switch (len) { + case 4: + *(u32 *)val = readl(reg + dev_priv->gtt.gsm); + break; + case 8: + *(u64 *)val = readq(reg + dev_priv->gtt.gsm); + break; + default: + return false; + } + return true; +} + +static bool vgt_gtt_write(off_t reg, void *val, int len) +{ + switch (len) { + case 4: + writel(*(u32 *)val, reg + dev_priv->gtt.gsm); + break; + case 8: + writeq(*(u64 *)val, reg + dev_priv->gtt.gsm); + break; + default: + return false; + } + return true; +} + +bool vgt_emulate_host_read(u32 reg, void *val, int len, bool is_gtt, + bool trace) +{ + if (!vgt_integration_done) + return is_gtt ? vgt_gtt_read(reg, val, len) : + vgt_mmio_read(reg, val, len, trace); +} + +bool vgt_emulate_host_write(u32 reg, void *val, int len, bool is_gtt, + bool trace) +{ + if (!vgt_integration_done) + return is_gtt ? vgt_gtt_write(reg, val, len) : + vgt_mmio_write(reg, val, len, trace); +} + +void i915_vgt_record_priv(struct drm_i915_private *priv) +{ + dev_priv = priv; +}