summaryrefslogtreecommitdiff
path: root/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_helpers.c
diff options
context:
space:
mode:
authorZhan Liu <zhan.liu@amd.com>2021-03-08 20:20:44 -0500
committerAlex Deucher <alexander.deucher@amd.com>2021-03-23 23:10:49 -0400
commit0dd795323405680f68cc16a471d19bc3369cc519 (patch)
tree3ccce3d9dae826fe413e51b5430b714ea171458d /drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_helpers.c
parent89551f2387f5bc3c7b8ea0696b467529f6c86f53 (diff)
drm/amdgpu/display: Implement functions to let DC allocate GPU memory
[Why] DC needs to communicate with PM FW through GPU memory. In order to do so we need to be able to allocate memory from within DC. [How] Call amdgpu_bo_create_kernel to allocate GPU memory and use a list in amdgpu_display_manager to track our allocations so we can clean them up later. Signed-off-by: Harry Wentland <harry.wentland@amd.com> Signed-off-by: Zhan Liu <zhan.liu@amd.com> Reviewed-by: Charlene Liu <charlene.liu@amd.com> Acked-by: Zhan Liu <zhan.liu@amd.com> Signed-off-by: Alex Deucher <alexander.deucher@amd.com>
Diffstat (limited to 'drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_helpers.c')
-rw-r--r--drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_helpers.c40
1 files changed, 37 insertions, 3 deletions
diff --git a/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_helpers.c b/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_helpers.c
index b459f4d36405..b0e49d01c206 100644
--- a/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_helpers.c
+++ b/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_helpers.c
@@ -652,8 +652,31 @@ void *dm_helpers_allocate_gpu_mem(
size_t size,
long long *addr)
{
- // TODO
- return NULL;
+ struct amdgpu_device *adev = ctx->driver_context;
+ struct dal_allocation *da;
+ u32 domain = (type == DC_MEM_ALLOC_TYPE_GART) ?
+ AMDGPU_GEM_DOMAIN_GTT : AMDGPU_GEM_DOMAIN_VRAM;
+ int ret;
+
+ da = kzalloc(sizeof(struct dal_allocation), GFP_KERNEL);
+ if (!da)
+ return NULL;
+
+ ret = amdgpu_bo_create_kernel(adev, size, PAGE_SIZE,
+ domain, &da->bo,
+ &da->gpu_addr, &da->cpu_ptr);
+
+ *addr = da->gpu_addr;
+
+ if (ret) {
+ kfree(da);
+ return NULL;
+ }
+
+ /* add da to list in dm */
+ list_add(&da->list, &adev->dm.da_list);
+
+ return da->cpu_ptr;
}
void dm_helpers_free_gpu_mem(
@@ -661,7 +684,18 @@ void dm_helpers_free_gpu_mem(
enum dc_gpu_mem_alloc_type type,
void *pvMem)
{
- // TODO
+ struct amdgpu_device *adev = ctx->driver_context;
+ struct dal_allocation *da;
+
+ /* walk the da list in DM */
+ list_for_each_entry(da, &adev->dm.da_list, list) {
+ if (pvMem == da->cpu_ptr) {
+ amdgpu_bo_free_kernel(&da->bo, &da->gpu_addr, &da->cpu_ptr);
+ list_del(&da->list);
+ kfree(da);
+ break;
+ }
+ }
}
bool dm_helpes_dmub_outbox0_interrupt_control(struct dc_context *ctx, bool enable)