From: Zhenyu Wang Subject: Re: [PATCH v3 2/8] drm/i915: get ready of memory for pvmmio Date: Wed, 14 Nov 2018 10:43:51 +0800 Message-ID: <20181114024351.GQ7021@zhen-hp.sh.intel.com> References: <1542098120-29684-1-git-send-email-xiaolin.zhang@intel.com> <1542098120-29684-3-git-send-email-xiaolin.zhang@intel.com> Reply-To: Zhenyu Wang Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="===============0387825453==" Return-path: In-Reply-To: <1542098120-29684-3-git-send-email-xiaolin.zhang@intel.com> List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: intel-gfx-bounces@lists.freedesktop.org Sender: "Intel-gfx" To: Xiaolin Zhang Cc: intel-gfx@lists.freedesktop.org, Zhiyuan Lv , Yuan Hang , intel-gvt-dev@lists.freedesktop.org, Jiang Fei List-Id: intel-gfx@lists.freedesktop.org --===============0387825453== Content-Type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="JvUS8mwutKMHKosv" Content-Disposition: inline --JvUS8mwutKMHKosv Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On 2018.11.13 16:35:14 +0800, Xiaolin Zhang wrote: > To enable pvmmio feature, we need to prepare one 4K shared page > which will be accessed by both guest and backend i915 driver used for > data exchagne. >=20 > the layout of shared_page also defined as well in this patch. >=20 > guest i915 will allocate one page memory and then pass this page's physic= al > address to backend i915 driver through PVINFO register so that backend i9= 15 > driver can access this shared page without hypeviser trap cost > for shared data exchagne via hyperviser read_gpa functionality. >=20 > v0: RFC > v1: addressed RFC comment to move both shared_page_lock and shared_page > to i915_virtual_gpu structure > v2: packed i915_virtual_gpu structure > v3: added SHARED_PAGE_SETUP g2v notification for pv shared_page setup >=20 > Cc: Zhenyu Wang > Cc: Zhi Wang > Cc: Chris Wilson > Cc: Joonas Lahtinen > Cc: He Min > Cc: Jiang Fei > Cc: Gong Zhipeng > Cc: Yuan Hang > Cc: Zhiyuan Lv > Signed-off-by: Xiaolin Zhang > --- > drivers/gpu/drm/i915/i915_drv.c | 2 ++ > drivers/gpu/drm/i915/i915_drv.h | 4 +++- > drivers/gpu/drm/i915/i915_pvinfo.h | 29 ++++++++++++++++++++++++++++- > drivers/gpu/drm/i915/i915_vgpu.c | 23 +++++++++++++++++++++++ > 4 files changed, 56 insertions(+), 2 deletions(-) >=20 > diff --git a/drivers/gpu/drm/i915/i915_drv.c b/drivers/gpu/drm/i915/i915_= drv.c > index baac35f..557ab67 100644 > --- a/drivers/gpu/drm/i915/i915_drv.c > +++ b/drivers/gpu/drm/i915/i915_drv.c > @@ -987,6 +987,8 @@ static void i915_mmio_cleanup(struct drm_i915_private= *dev_priv) > =20 > intel_teardown_mchbar(dev_priv); > pci_iounmap(pdev, dev_priv->regs); > + if (intel_vgpu_active(dev_priv) && dev_priv->vgpu.shared_page) > + free_page((unsigned long)dev_priv->vgpu.shared_page); > } > =20 > /** > diff --git a/drivers/gpu/drm/i915/i915_drv.h b/drivers/gpu/drm/i915/i915_= drv.h > index 7b2d7cb..d7a972f 100644 > --- a/drivers/gpu/drm/i915/i915_drv.h > +++ b/drivers/gpu/drm/i915/i915_drv.h > @@ -1345,7 +1345,9 @@ struct i915_virtual_gpu { > bool active; > u32 caps; > u32 pv_caps; > -}; > + spinlock_t shared_page_lock; > + struct gvt_shared_page *shared_page; > +} __packed; > =20 > /* used in computing the new watermarks state */ > struct intel_wm_config { > diff --git a/drivers/gpu/drm/i915/i915_pvinfo.h b/drivers/gpu/drm/i915/i9= 15_pvinfo.h > index 78a4b9c..aa5eebc 100644 > --- a/drivers/gpu/drm/i915/i915_pvinfo.h > +++ b/drivers/gpu/drm/i915/i915_pvinfo.h > @@ -24,6 +24,8 @@ > #ifndef _I915_PVINFO_H_ > #define _I915_PVINFO_H_ > =20 > +#include "i915_gem.h" > + > /* The MMIO offset of the shared info between guest and host emulator */ > #define VGT_PVINFO_PAGE 0x78000 > #define VGT_PVINFO_SIZE 0x1000 > @@ -46,9 +48,29 @@ enum vgt_g2v_type { > VGT_G2V_PPGTT_L4_PAGE_TABLE_DESTROY, > VGT_G2V_EXECLIST_CONTEXT_CREATE, > VGT_G2V_EXECLIST_CONTEXT_DESTROY, > + VGT_G2V_SHARED_PAGE_SETUP, > VGT_G2V_MAX, > }; > =20 > +struct pv_ppgtt_update { > + u64 pdp; > + u64 start; > + u64 length; > + u32 cache_level; > +}; > + > +/* > + * shared page(4KB) between gvt and VM, could be allocated by guest driv= er > + * or a fixed location in PCI bar 0 region > + */ > +struct gvt_shared_page { > + u32 reg_addr; > + u32 elsp_data[I915_NUM_ENGINES * 4]; You can't rely on I915_NUM_ENGINES, which may be changed so that would cause incompatibility in shared page definition. > + u32 ring_id; > + u32 disable_irq; > + struct pv_ppgtt_update pv_ppgtt; > +}; > + > /* > * VGT capabilities type > */ > @@ -121,7 +143,12 @@ struct vgt_if { > =20 > u32 pvmmio_caps; > =20 > - u32 rsv7[0x200 - 25]; /* pad to one page */ > + struct { > + u32 lo; > + u32 hi; > + } shared_page_gpa; > + > + u32 rsv7[0x200 - 27]; /* pad to one page */ > } __packed; > =20 > #define vgtif_reg(x) \ > diff --git a/drivers/gpu/drm/i915/i915_vgpu.c b/drivers/gpu/drm/i915/i915= _vgpu.c > index 219c7c0..63f70bf 100644 > --- a/drivers/gpu/drm/i915/i915_vgpu.c > +++ b/drivers/gpu/drm/i915/i915_vgpu.c > @@ -63,6 +63,7 @@ void i915_check_vgpu(struct drm_i915_private *dev_priv) > u64 magic; > u16 version_major; > u32 gvt_caps; > + u64 gpa; > =20 > BUILD_BUG_ON(sizeof(struct vgt_if) !=3D VGT_PVINFO_SIZE); > =20 > @@ -95,6 +96,28 @@ void i915_check_vgpu(struct drm_i915_private *dev_priv) > if (!dev_priv->vgpu.pv_caps) > return; > =20 > + dev_priv->vgpu.shared_page =3D (struct gvt_shared_page *) > + get_zeroed_page(GFP_KERNEL); > + if (!dev_priv->vgpu.shared_page) { > + DRM_ERROR("out of memory for shared page memory\n"); > + return; > + } > + gpa =3D __pa(dev_priv->vgpu.shared_page); > + __raw_i915_write32(dev_priv, vgtif_reg(shared_page_gpa.lo), > + lower_32_bits(gpa)); > + __raw_i915_write32(dev_priv, vgtif_reg(shared_page_gpa.hi), > + upper_32_bits(gpa)); > + if (gpa !=3D __raw_i915_read64(dev_priv, > + vgtif_reg(shared_page_gpa))) { > + DRM_ERROR("vgpu: passed shared_page_gpa failed\n"); > + free_page((unsigned long)dev_priv->vgpu.shared_page); > + dev_priv->vgpu.pv_caps =3D 0; > + __raw_i915_write32(dev_priv, vgtif_reg(pvmmio_caps), 0); > + return; > + } > + __raw_i915_write32(dev_priv, vgtif_reg(g2v_notify), > + VGT_G2V_SHARED_PAGE_SETUP); > + spin_lock_init(&dev_priv->vgpu.shared_page_lock); > =20 > DRM_INFO("Virtual GPU for Intel GVT-g detected with pvmmio 0x%x\n", > dev_priv->vgpu.pv_caps); > --=20 > 2.7.4 >=20 > _______________________________________________ > intel-gvt-dev mailing list > intel-gvt-dev@lists.freedesktop.org > https://lists.freedesktop.org/mailman/listinfo/intel-gvt-dev --=20 Open Source Technology Center, Intel ltd. $gpg --keyserver wwwkeys.pgp.net --recv-keys 4D781827 --JvUS8mwutKMHKosv Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iF0EARECAB0WIQTXuabgHDW6LPt9CICxBBozTXgYJwUCW+uL5gAKCRCxBBozTXgY J+DXAJ9SiwKaT1KBql82+Z+yF7qoEj7augCcDOwMVhnRQW97SEh6rfwsHSyjpkc= =m6KE -----END PGP SIGNATURE----- --JvUS8mwutKMHKosv-- --===============0387825453== Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: base64 Content-Disposition: inline X19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX18KSW50ZWwtZ2Z4 IG1haWxpbmcgbGlzdApJbnRlbC1nZnhAbGlzdHMuZnJlZWRlc2t0b3Aub3JnCmh0dHBzOi8vbGlz dHMuZnJlZWRlc2t0b3Aub3JnL21haWxtYW4vbGlzdGluZm8vaW50ZWwtZ2Z4Cg== --===============0387825453==--