All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Yu, Xiangliang" <Xiangliang.Yu-5C7GfCeVMHo@public.gmane.org>
To: "Christian König"
	<deathsimple-ANTagKRnAhcb1SvskN2V4Q@public.gmane.org>,
	"amd-gfx-PD4FTy7X32lNgt0PjOBp9y5qC8QIuHrW@public.gmane.org"
	<amd-gfx-PD4FTy7X32lNgt0PjOBp9y5qC8QIuHrW@public.gmane.org>
Subject: RE: [V2 04/11] drm/amdgpu/virt: use kiq to access registers
Date: Tue, 10 Jan 2017 14:01:34 +0000	[thread overview]
Message-ID: <CY4PR12MB1701B676A67A72E8B59F545FEB670@CY4PR12MB1701.namprd12.prod.outlook.com> (raw)
In-Reply-To: <35600919-5cd3-4920-f2dd-db0e0620e3fa-ANTagKRnAhcb1SvskN2V4Q@public.gmane.org>

> -----Original Message-----
> From: Christian König [mailto:deathsimple@vodafone.de]
> Sent: Tuesday, January 10, 2017 9:09 PM
> To: Yu, Xiangliang <Xiangliang.Yu@amd.com>; amd-
> gfx@lists.freedesktop.org
> Subject: Re: [V2 04/11] drm/amdgpu/virt: use kiq to access registers
> 
> Am 10.01.2017 um 11:00 schrieb Xiangliang Yu:
> > For virtualization, it is must for driver to use KIQ to access
> > registers when it is out of GPU full access mode.
> >
> > Signed-off-by: Xiangliang Yu <Xiangliang.Yu@amd.com>
> > ---
> >   drivers/gpu/drm/amd/amdgpu/Makefile        |  2 +-
> >   drivers/gpu/drm/amd/amdgpu/amdgpu_device.c |  6 +++
> >   drivers/gpu/drm/amd/amdgpu/amdgpu_virt.c   | 86
> ++++++++++++++++++++++++++++++
> >   drivers/gpu/drm/amd/amdgpu/amdgpu_virt.h   |  5 ++
> >   drivers/gpu/drm/amd/amdgpu/vi.c            |  3 ++
> >   5 files changed, 101 insertions(+), 1 deletion(-)
> >   create mode 100644 drivers/gpu/drm/amd/amdgpu/amdgpu_virt.c
> >
> > diff --git a/drivers/gpu/drm/amd/amdgpu/Makefile
> > b/drivers/gpu/drm/amd/amdgpu/Makefile
> > index 4185b03..0b8e470 100644
> > --- a/drivers/gpu/drm/amd/amdgpu/Makefile
> > +++ b/drivers/gpu/drm/amd/amdgpu/Makefile
> > @@ -30,7 +30,7 @@ amdgpu-y += amdgpu_device.o amdgpu_kms.o \
> >   	atombios_encoders.o amdgpu_sa.o atombios_i2c.o \
> >   	amdgpu_prime.o amdgpu_vm.o amdgpu_ib.o amdgpu_pll.o \
> >   	amdgpu_ucode.o amdgpu_bo_list.o amdgpu_ctx.o amdgpu_sync.o \
> > -	amdgpu_gtt_mgr.o amdgpu_vram_mgr.o
> > +	amdgpu_gtt_mgr.o amdgpu_vram_mgr.o amdgpu_virt.o
> >
> >   # add asic specific block
> >   amdgpu-$(CONFIG_DRM_AMDGPU_CIK)+= cik.o cik_ih.o kv_smc.o
> kv_dpm.o \
> > diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c
> > b/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c
> > index f82919d..9a2fd3e 100644
> > --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c
> > +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c
> > @@ -95,6 +95,9 @@ uint32_t amdgpu_mm_rreg(struct amdgpu_device
> *adev, uint32_t reg,
> >   {
> >   	uint32_t ret;
> >
> > +	if (amdgpu_sriov_runtime(adev) && !in_interrupt())
> > +		return amdgpu_virt_kiq_rreg(adev, reg);
> > +
> >   	if ((reg * 4) < adev->rmmio_size && !always_indirect)
> >   		ret = readl(((void __iomem *)adev->rmmio) + (reg * 4));
> >   	else {
> > @@ -114,6 +117,9 @@ void amdgpu_mm_wreg(struct amdgpu_device
> *adev, uint32_t reg, uint32_t v,
> >   {
> >   	trace_amdgpu_mm_wreg(adev->pdev->device, reg, v);
> >
> > +	if (amdgpu_sriov_runtime(adev))
> > +		return amdgpu_virt_kiq_wreg(adev, reg, v);
> > +
> >   	if ((reg * 4) < adev->rmmio_size && !always_indirect)
> >   		writel(v, ((void __iomem *)adev->rmmio) + (reg * 4));
> >   	else {
> > diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_virt.c
> > b/drivers/gpu/drm/amd/amdgpu/amdgpu_virt.c
> > new file mode 100644
> > index 0000000..6520a4e
> > --- /dev/null
> > +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_virt.c
> > @@ -0,0 +1,86 @@
> > +/*
> > + * Copyright 2017 Advanced Micro Devices, Inc.
> > + *
> > + * Permission is hereby granted, free of charge, to any person
> > +obtaining a
> > + * copy of this software and associated documentation files (the
> > +"Software"),
> > + * to deal in the Software without restriction, including without
> > +limitation
> > + * the rights to use, copy, modify, merge, publish, distribute,
> > +sublicense,
> > + * and/or sell copies of the Software, and to permit persons to whom
> > +the
> > + * Software is furnished to do so, subject to the following conditions:
> > + *
> > + * The above copyright notice and this permission notice shall be
> > +included in
> > + * all copies or substantial portions of the Software.
> > + *
> > + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY
> KIND,
> > +EXPRESS OR
> > + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
> > +MERCHANTABILITY,
> > + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN
> NO EVENT
> > +SHALL
> > + * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM,
> > +DAMAGES OR
> > + * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
> > +OTHERWISE,
> > + * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR
> THE USE
> > +OR
> > + * OTHER DEALINGS IN THE SOFTWARE.
> > + */
> > +
> > +#include "amdgpu.h"
> > +#include "amdgpu_virt.h"
> > +
> > +void amdgpu_virt_init_setting(struct amdgpu_device *adev) {
> > +	mutex_init(&adev->virt.lock);
> > +}
> > +
> > +uint32_t amdgpu_virt_kiq_rreg(struct amdgpu_device *adev, uint32_t
> > +reg) {
> > +	signed long r;
> > +	uint32_t val;
> > +	struct fence *f;
> > +	struct amdgpu_kiq *kiq = &adev->gfx.kiq;
> > +	struct amdgpu_ring *ring = &kiq->ring;
> > +
> > +	BUG_ON(!ring->funcs->emit_rreg);
> > +
> > +	mutex_lock(&adev->virt.lock);
> > +	amdgpu_ring_alloc(ring, 32);
> > +	amdgpu_ring_emit_hdp_flush(ring);
> > +	amdgpu_ring_emit_rreg(ring, reg);
> > +	amdgpu_ring_emit_hdp_invalidate(ring);
> > +	amdgpu_fence_emit(ring, &f);
> > +	fence_get(f);
> > +	amdgpu_ring_commit(ring);
> > +	mutex_unlock(&adev->virt.lock);
> > +
> > +	r = fence_wait(f, false);
> > +	fence_put(f);
> 
> Why do you grab and release an extra fence reference here?

KIQ ring has no scheduler, I think we need to take care fence.

> 
> > +	if (r)
> > +		DRM_ERROR("wait for kiq fence error: %ld.\n", r);
> > +	fence_put(f);
> > +
> > +	val = adev->wb.wb[adev->virt.val_offs];
> > +
> > +	return val;
> > +}
> > +
> > +void amdgpu_virt_kiq_wreg(struct amdgpu_device *adev, uint32_t reg,
> > +uint32_t v) {
> > +	signed long r;
> > +	struct fence *f;
> > +	struct amdgpu_kiq *kiq = &adev->gfx.kiq;
> > +	struct amdgpu_ring *ring = &kiq->ring;
> > +
> > +	BUG_ON(!ring->funcs->emit_wreg);
> > +
> > +	mutex_lock(&adev->virt.lock);
> > +	amdgpu_ring_alloc(ring, 32);
> > +	amdgpu_ring_emit_hdp_flush(ring);
> > +	amdgpu_ring_emit_wreg(ring, reg, v);
> > +	amdgpu_ring_emit_hdp_invalidate(ring);
> > +	amdgpu_fence_emit(ring, &f);
> > +	fence_get(f);
> > +	amdgpu_ring_commit(ring);
> > +	mutex_unlock(&adev->virt.lock);
> > +
> > +	r = fence_wait(f, false);
> > +	fence_put(f);
> > +	if (r)
> > +		DRM_ERROR("wait for kiq fence error: %ld.\n", r);
> > +	fence_put(f);
> > +}
> > diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_virt.h
> > b/drivers/gpu/drm/amd/amdgpu/amdgpu_virt.h
> > index 79619b6..24f0590 100644
> > --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_virt.h
> > +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_virt.h
> > @@ -33,6 +33,7 @@
> >   struct amdgpu_virt {
> >   	uint32_t		caps;
> >   	uint32_t		val_offs;
> > +	struct mutex		lock;
> >   };
> >
> >   #define amdgpu_sriov_enabled(adev) \ @@ -59,4 +60,8 @@ static inline
> > bool is_virtual_machine(void)
> >   #endif
> >   }
> >
> > +void amdgpu_virt_init_setting(struct amdgpu_device *adev); uint32_t
> > +amdgpu_virt_kiq_rreg(struct amdgpu_device *adev, uint32_t reg); void
> > +amdgpu_virt_kiq_wreg(struct amdgpu_device *adev, uint32_t reg,
> > +uint32_t v);
> > +
> >   #endif
> > diff --git a/drivers/gpu/drm/amd/amdgpu/vi.c
> > b/drivers/gpu/drm/amd/amdgpu/vi.c index 7350a8f..dc0d4fa 100644
> > --- a/drivers/gpu/drm/amd/amdgpu/vi.c
> > +++ b/drivers/gpu/drm/amd/amdgpu/vi.c
> > @@ -892,6 +892,9 @@ static int vi_common_early_init(void *handle)
> >   		(amdgpu_ip_block_mask & (1 <<
> AMD_IP_BLOCK_TYPE_SMC)))
> >   		smc_enabled = true;
> >
> > +	if (amdgpu_sriov_vf(adev))
> > +		amdgpu_virt_init_setting(adev);
> > +
> >   	adev->rev_id = vi_get_rev_id(adev);
> >   	adev->external_rev_id = 0xFF;
> >   	switch (adev->asic_type) {
> 

_______________________________________________
amd-gfx mailing list
amd-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

  parent reply	other threads:[~2017-01-10 14:01 UTC|newest]

Thread overview: 44+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-01-10 10:00 [V2 00/11] Add support AMD GPU virtualization soultion Xiangliang Yu
     [not found] ` <1484042450-22987-1-git-send-email-Xiangliang.Yu-5C7GfCeVMHo@public.gmane.org>
2017-01-10 10:00   ` [V2 01/11] drm/amdgpu/ring: add two interfaces to support r/w registers with kiq Xiangliang Yu
     [not found]     ` <1484042450-22987-2-git-send-email-Xiangliang.Yu-5C7GfCeVMHo@public.gmane.org>
2017-01-10 15:31       ` Deucher, Alexander
2017-01-10 10:00   ` [V2 02/11] drm/amdgpu/gfx8: implement emit_rreg/wreg function Xiangliang Yu
     [not found]     ` <1484042450-22987-3-git-send-email-Xiangliang.Yu-5C7GfCeVMHo@public.gmane.org>
2017-01-10 15:34       ` Deucher, Alexander
     [not found]         ` <BN6PR12MB165294D179EF65B87ECFCA6DF7670-/b2+HYfkarQqUD6E6FAiowdYzm3356FpvxpqHgZTriW3zl9H0oFU5g@public.gmane.org>
2017-01-10 15:46           ` Yu, Xiangliang
2017-01-10 10:00   ` [V2 03/11] drm/amdgpu/virt: add runtime flag Xiangliang Yu
     [not found]     ` <1484042450-22987-4-git-send-email-Xiangliang.Yu-5C7GfCeVMHo@public.gmane.org>
2017-01-10 15:35       ` Deucher, Alexander
2017-01-10 10:00   ` [V2 04/11] drm/amdgpu/virt: use kiq to access registers Xiangliang Yu
     [not found]     ` <1484042450-22987-5-git-send-email-Xiangliang.Yu-5C7GfCeVMHo@public.gmane.org>
2017-01-10 13:09       ` Christian König
     [not found]         ` <35600919-5cd3-4920-f2dd-db0e0620e3fa-ANTagKRnAhcb1SvskN2V4Q@public.gmane.org>
2017-01-10 14:01           ` Yu, Xiangliang [this message]
     [not found]             ` <CY4PR12MB1701B676A67A72E8B59F545FEB670-rpdhrqHFk05QaJCA3gGb3wdYzm3356FpvxpqHgZTriW3zl9H0oFU5g@public.gmane.org>
2017-01-10 14:07               ` Christian König
     [not found]                 ` <623ec744-5911-9777-9271-9a221fac8821-ANTagKRnAhcb1SvskN2V4Q@public.gmane.org>
2017-01-10 14:14                   ` Yu, Xiangliang
2017-01-11  2:44           ` 答复: " Liu, Monk
2017-01-11  3:06           ` Liu, Monk
     [not found]             ` <BY2PR1201MB111068093D612E37CCD64DF284660-O28G1zQ8oGliQkyLPkmea2rFom/aUZj6nBOFsp37pqbUKgpGm//BTAC/G2K4zDHf@public.gmane.org>
2017-01-11  8:30               ` Liu, Monk
     [not found]                 ` <BY2PR1201MB11107ADADF57EBE79AB97D7F84660-O28G1zQ8oGliQkyLPkmea2rFom/aUZj6nBOFsp37pqbUKgpGm//BTAC/G2K4zDHf@public.gmane.org>
2017-01-11 11:48                   ` Christian König
2017-01-10 10:00   ` [V2 05/11] drm/amdgpu/virt: add high level interfaces for virt Xiangliang Yu
     [not found]     ` <1484042450-22987-6-git-send-email-Xiangliang.Yu-5C7GfCeVMHo@public.gmane.org>
2017-01-10 13:12       ` Christian König
     [not found]         ` <486049d3-8d0f-59fd-87d7-71111f168560-ANTagKRnAhcb1SvskN2V4Q@public.gmane.org>
2017-01-10 13:33           ` Yu, Xiangliang
     [not found]             ` <CY4PR12MB1701636B667485FAF5260876EB670-rpdhrqHFk05QaJCA3gGb3wdYzm3356FpvxpqHgZTriW3zl9H0oFU5g@public.gmane.org>
2017-01-10 13:59               ` Christian König
     [not found]                 ` <9350e215-4325-8c5e-db84-c5318aa480a2-ANTagKRnAhcb1SvskN2V4Q@public.gmane.org>
2017-01-10 14:26                   ` Yu, Xiangliang
2017-01-10 15:35       ` Deucher, Alexander
2017-01-10 10:00   ` [V2 06/11] drm/amdgpu/virt: implement VI virt operation interfaces Xiangliang Yu
     [not found]     ` <1484042450-22987-7-git-send-email-Xiangliang.Yu-5C7GfCeVMHo@public.gmane.org>
2017-01-10 13:15       ` Christian König
     [not found]         ` <c2f40171-37f4-4617-b4d3-62f40d907ebc-ANTagKRnAhcb1SvskN2V4Q@public.gmane.org>
2017-01-10 13:20           ` Yu, Xiangliang
     [not found]             ` <CY4PR12MB1701449882D58F66699786E4EB670-rpdhrqHFk05QaJCA3gGb3wdYzm3356FpvxpqHgZTriW3zl9H0oFU5g@public.gmane.org>
2017-01-10 13:29               ` Christian König
     [not found]                 ` <33a2d958-38cd-09aa-2bc2-4b3795cba4d4-ANTagKRnAhcb1SvskN2V4Q@public.gmane.org>
2017-01-10 13:43                   ` Yu, Xiangliang
     [not found]                     ` <CY4PR12MB170198A2080865A1E95FAF3BEB670-rpdhrqHFk05QaJCA3gGb3wdYzm3356FpvxpqHgZTriW3zl9H0oFU5g@public.gmane.org>
2017-01-10 14:05                       ` Christian König
     [not found]                         ` <91042d0c-f0ad-4969-04c8-b4926a6b5d2f-ANTagKRnAhcb1SvskN2V4Q@public.gmane.org>
2017-01-10 14:17                           ` Yu, Xiangliang
2017-01-10 15:36       ` Deucher, Alexander
2017-01-10 10:00   ` [V2 07/11] drm/amdgpu: request/release full gpu access if device is vf Xiangliang Yu
     [not found]     ` <1484042450-22987-8-git-send-email-Xiangliang.Yu-5C7GfCeVMHo@public.gmane.org>
2017-01-10 15:37       ` Deucher, Alexander
2017-01-10 10:00   ` [V2 08/11] drm/amdgpu/vi: add support virtualization Xiangliang Yu
     [not found]     ` <1484042450-22987-9-git-send-email-Xiangliang.Yu-5C7GfCeVMHo@public.gmane.org>
2017-01-10 15:37       ` Deucher, Alexander
2017-01-10 10:00   ` [V2 09/11] drm/amdgpu/virt: enable virtual display Xiangliang Yu
     [not found]     ` <1484042450-22987-10-git-send-email-Xiangliang.Yu-5C7GfCeVMHo@public.gmane.org>
2017-01-10 15:44       ` Deucher, Alexander
2017-01-10 10:00   ` [V2 10/11] drm/amdgpu/virt: disable dc Xiangliang Yu
     [not found]     ` <1484042450-22987-11-git-send-email-Xiangliang.Yu-5C7GfCeVMHo@public.gmane.org>
2017-01-10 15:44       ` Deucher, Alexander
2017-01-10 10:00   ` [V2 11/11] drm/amdgpu: do not reset gpu for virtualization Xiangliang Yu
     [not found]     ` <1484042450-22987-12-git-send-email-Xiangliang.Yu-5C7GfCeVMHo@public.gmane.org>
2017-01-10 10:05       ` 答复: " Liu, Monk
2017-01-10 13:18       ` Christian König
     [not found]         ` <7106150a-e0e1-f904-6b00-33ee8fe5bd01-ANTagKRnAhcb1SvskN2V4Q@public.gmane.org>
2017-01-10 13:36           ` Yu, Xiangliang
     [not found]             ` <CY4PR12MB17016411760E74CE227A7B78EB670-rpdhrqHFk05QaJCA3gGb3wdYzm3356FpvxpqHgZTriW3zl9H0oFU5g@public.gmane.org>
2017-01-10 15:28               ` Deucher, Alexander

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=CY4PR12MB1701B676A67A72E8B59F545FEB670@CY4PR12MB1701.namprd12.prod.outlook.com \
    --to=xiangliang.yu-5c7gfcevmho@public.gmane.org \
    --cc=amd-gfx-PD4FTy7X32lNgt0PjOBp9y5qC8QIuHrW@public.gmane.org \
    --cc=deathsimple-ANTagKRnAhcb1SvskN2V4Q@public.gmane.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.