[PATCH 16/23] drm/amdgpu: add flag to indicate VF runtime state

Xiangliang Yu Xiangliang.Yu at amd.com
Sat Dec 17 16:16:38 UTC 2016


Guest driver will select using KIQ to access gpu registers if
runtime flas is set, or will use MMIO method to r/w registers
directly.

When VF's initialization is done, VF should use set runtime flag
and use KIQ method. And clear runtime flag when starting to unload
driver.

Signed-off-by: Monk Liu <Monk.Liu at amd.com>
Signed-off-by: Xiangliang Yu <Xiangliang.Yu at amd.com>
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_device.c | 6 ++++++
 drivers/gpu/drm/amd/amdgpu/amdgpu_virt.h   | 5 +++++
 drivers/gpu/drm/amd/mxgpu/mxgpu_mb.c       | 3 +++
 3 files changed, 14 insertions(+)

diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c
index ab8c8bb5..b3c1820 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c
@@ -94,6 +94,9 @@ uint32_t amdgpu_mm_rreg(struct amdgpu_device *adev, uint32_t reg,
 {
 	uint32_t ret;
 
+	if (amdgpu_sriov_runtime(adev))
+		return amdgpu_kiq_rreg(adev, reg);
+
 	if ((reg * 4) < adev->rmmio_size && !always_indirect)
 		ret = readl(((void __iomem *)adev->rmmio) + (reg * 4));
 	else {
@@ -113,6 +116,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_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.h b/drivers/gpu/drm/amd/amdgpu/amdgpu_virt.h
index c78435d..eb2905e 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_virt.h
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_virt.h
@@ -30,6 +30,8 @@ struct amdgpu_vm;
 #define AMDGPU_SRIOV_CAPS_ENABLE_IOV   (1 << 1) /* sr-iov is enabled on this GPU */
 #define AMDGPU_SRIOV_CAPS_IS_VF        (1 << 2) /* this GPU is a virtual function */
 #define AMDGPU_PASSTHROUGH_MODE        (1 << 3) /* thw whole GPU is pass through for VM */
+/* now GPU is not in init/fini stage */
+#define AMDGPU_SRIOV_CAPS_IS_RUNTIME	(1 << 4)
 /* GPU virtualization */
 struct amdgpu_virtualization {
 	uint32_t virtual_caps;
@@ -55,6 +57,9 @@ struct amdgpu_csa {
 #define amdgpu_passthrough(adev) \
 ((adev)->virtualization.virtual_caps & AMDGPU_PASSTHROUGH_MODE)
 
+#define amdgpu_sriov_runtime(adev) \
+((adev)->virtualization.virtual_caps & AMDGPU_SRIOV_CAPS_IS_RUNTIME)
+
 static inline bool is_virtual_machine(void)
 {
 #ifdef CONFIG_X86
diff --git a/drivers/gpu/drm/amd/mxgpu/mxgpu_mb.c b/drivers/gpu/drm/amd/mxgpu/mxgpu_mb.c
index 387246c..f0c7e97 100644
--- a/drivers/gpu/drm/amd/mxgpu/mxgpu_mb.c
+++ b/drivers/gpu/drm/amd/mxgpu/mxgpu_mb.c
@@ -134,6 +134,7 @@ int amdgpu_get_gpu(struct amdgpu_device *adev)
 	if (!adev->priv_data)
 		return 0;
 
+	adev->virtualization.virtual_caps &= ~AMDGPU_SRIOV_CAPS_IS_RUNTIME;
 	r = xgpu_request_full_gpu_access(adev, false);
 	if (r)
 		return r;
@@ -152,5 +153,7 @@ int amdgpu_put_gpu(struct amdgpu_device *adev)
 	if (r)
 		return r;
 
+	adev->virtualization.virtual_caps |= AMDGPU_SRIOV_CAPS_IS_RUNTIME;
+
 	return 0;
 }
-- 
2.7.4



More information about the amd-gfx mailing list