[07/11] drm/amdgpu/virt: add two functions for MM table

Submitted by Yu, Xiangliang on April 24, 2017, 6:58 a.m.

Details

Message ID 1493017089-23101-8-git-send-email-Xiangliang.Yu@amd.com
State New
Headers show
Series "Enable UVD and PSP loading for SRIOV" ( rev: 1 ) in AMD X.Org drivers

Not browsing as part of any series.

Commit Message

Yu, Xiangliang April 24, 2017, 6:58 a.m.
Add two functions to allocate & free MM table memory.

Signed-off-by: Xiangliang Yu <Xiangliang.Yu@amd.com>
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_virt.c | 46 ++++++++++++++++++++++++++++++++
 drivers/gpu/drm/amd/amdgpu/amdgpu_virt.h |  2 ++
 2 files changed, 48 insertions(+)

Patch hide | download patch | download mbox

diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_virt.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_virt.c
index 7fce7b5..1363239 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_virt.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_virt.c
@@ -227,3 +227,49 @@  int amdgpu_virt_reset_gpu(struct amdgpu_device *adev)
 
 	return 0;
 }
+
+/**
+ * amdgpu_virt_alloc_mm_table() - alloc memory for mm table
+ * @amdgpu:	amdgpu device.
+ * MM table is used by UVD and VCE for its initialization
+ * Return: Zero if allocate success.
+ */
+int amdgpu_virt_alloc_mm_table(struct amdgpu_device *adev)
+{
+	int r;
+
+	if (!amdgpu_sriov_vf(adev) || adev->virt.mm_table.gpu_addr)
+		return 0;
+
+	r = amdgpu_bo_create_kernel(adev, PAGE_SIZE, PAGE_SIZE,
+				    AMDGPU_GEM_DOMAIN_VRAM,
+				    &adev->virt.mm_table.bo,
+				    &adev->virt.mm_table.gpu_addr,
+				    (void *)&adev->virt.mm_table.cpu_addr);
+	if (r) {
+		DRM_ERROR("failed to alloc mm table and error = %d.\n", r);
+		return r;
+	}
+
+	memset((void *)adev->virt.mm_table.cpu_addr, 0, PAGE_SIZE);
+	DRM_INFO("MM table gpu addr = 0x%llx, cpu addr = %p.\n",
+		 adev->virt.mm_table.gpu_addr,
+		 adev->virt.mm_table.cpu_addr);
+	return 0;
+}
+
+/**
+ * amdgpu_virt_free_mm_table() - free mm table memory
+ * @amdgpu:	amdgpu device.
+ * Free MM table memory
+ */
+void amdgpu_virt_free_mm_table(struct amdgpu_device *adev)
+{
+	if (!amdgpu_sriov_vf(adev) || !adev->virt.mm_table.gpu_addr)
+		return;
+
+	amdgpu_bo_free_kernel(&adev->virt.mm_table.bo,
+			      &adev->virt.mm_table.gpu_addr,
+			      (void *)&adev->virt.mm_table.cpu_addr);
+	adev->virt.mm_table.gpu_addr = 0;
+}
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_virt.h b/drivers/gpu/drm/amd/amdgpu/amdgpu_virt.h
index 1ee0a19..a8ed162 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_virt.h
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_virt.h
@@ -98,5 +98,7 @@  int amdgpu_virt_request_full_gpu(struct amdgpu_device *adev, bool init);
 int amdgpu_virt_release_full_gpu(struct amdgpu_device *adev, bool init);
 int amdgpu_virt_reset_gpu(struct amdgpu_device *adev);
 int amdgpu_sriov_gpu_reset(struct amdgpu_device *adev, bool voluntary);
+int amdgpu_virt_alloc_mm_table(struct amdgpu_device *adev);
+void amdgpu_virt_free_mm_table(struct amdgpu_device *adev);
 
 #endif

Comments

> -----Original Message-----

> From: amd-gfx [mailto:amd-gfx-bounces@lists.freedesktop.org] On Behalf

> Of Xiangliang Yu

> Sent: Monday, April 24, 2017 2:58 AM

> To: amd-gfx@lists.freedesktop.org

> Cc: Yu, Xiangliang

> Subject: [PATCH 07/11] drm/amdgpu/virt: add two functions for MM table

> 

> Add two functions to allocate & free MM table memory.

> 

> Signed-off-by: Xiangliang Yu <Xiangliang.Yu@amd.com>


Reviewed-by: Alex Deucher <alexander.deucher@amd.com>


> ---

>  drivers/gpu/drm/amd/amdgpu/amdgpu_virt.c | 46

> ++++++++++++++++++++++++++++++++

>  drivers/gpu/drm/amd/amdgpu/amdgpu_virt.h |  2 ++

>  2 files changed, 48 insertions(+)

> 

> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_virt.c

> b/drivers/gpu/drm/amd/amdgpu/amdgpu_virt.c

> index 7fce7b5..1363239 100644

> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_virt.c

> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_virt.c

> @@ -227,3 +227,49 @@ int amdgpu_virt_reset_gpu(struct amdgpu_device

> *adev)

> 

>  	return 0;

>  }

> +

> +/**

> + * amdgpu_virt_alloc_mm_table() - alloc memory for mm table

> + * @amdgpu:	amdgpu device.

> + * MM table is used by UVD and VCE for its initialization

> + * Return: Zero if allocate success.

> + */

> +int amdgpu_virt_alloc_mm_table(struct amdgpu_device *adev)

> +{

> +	int r;

> +

> +	if (!amdgpu_sriov_vf(adev) || adev->virt.mm_table.gpu_addr)

> +		return 0;

> +

> +	r = amdgpu_bo_create_kernel(adev, PAGE_SIZE, PAGE_SIZE,

> +				    AMDGPU_GEM_DOMAIN_VRAM,

> +				    &adev->virt.mm_table.bo,

> +				    &adev->virt.mm_table.gpu_addr,

> +				    (void *)&adev->virt.mm_table.cpu_addr);

> +	if (r) {

> +		DRM_ERROR("failed to alloc mm table and error = %d.\n", r);

> +		return r;

> +	}

> +

> +	memset((void *)adev->virt.mm_table.cpu_addr, 0, PAGE_SIZE);

> +	DRM_INFO("MM table gpu addr = 0x%llx, cpu addr = %p.\n",

> +		 adev->virt.mm_table.gpu_addr,

> +		 adev->virt.mm_table.cpu_addr);

> +	return 0;

> +}

> +

> +/**

> + * amdgpu_virt_free_mm_table() - free mm table memory

> + * @amdgpu:	amdgpu device.

> + * Free MM table memory

> + */

> +void amdgpu_virt_free_mm_table(struct amdgpu_device *adev)

> +{

> +	if (!amdgpu_sriov_vf(adev) || !adev->virt.mm_table.gpu_addr)

> +		return;

> +

> +	amdgpu_bo_free_kernel(&adev->virt.mm_table.bo,

> +			      &adev->virt.mm_table.gpu_addr,

> +			      (void *)&adev->virt.mm_table.cpu_addr);

> +	adev->virt.mm_table.gpu_addr = 0;

> +}

> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_virt.h

> b/drivers/gpu/drm/amd/amdgpu/amdgpu_virt.h

> index 1ee0a19..a8ed162 100644

> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_virt.h

> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_virt.h

> @@ -98,5 +98,7 @@ int amdgpu_virt_request_full_gpu(struct

> amdgpu_device *adev, bool init);

>  int amdgpu_virt_release_full_gpu(struct amdgpu_device *adev, bool init);

>  int amdgpu_virt_reset_gpu(struct amdgpu_device *adev);

>  int amdgpu_sriov_gpu_reset(struct amdgpu_device *adev, bool voluntary);

> +int amdgpu_virt_alloc_mm_table(struct amdgpu_device *adev);

> +void amdgpu_virt_free_mm_table(struct amdgpu_device *adev);

> 

>  #endif

> --

> 2.7.4

> 

> _______________________________________________

> amd-gfx mailing list

> amd-gfx@lists.freedesktop.org

> https://lists.freedesktop.org/mailman/listinfo/amd-gfx