[PATCH 13/13] drm/amdgpu: introduce doorbell bo in kernel
Shashank Sharma
shashank.sharma at amd.com
Fri Feb 3 19:08:35 UTC 2023
From: Alex Deucher <alexander.deucher at amd.com>
This patch does the following:
- Removes doorbell ptr from adev.
- Moves doorbell.num_doorbells into mman.num_doorbells.
- Introduces a kernel bo for doorbell management in form of mman.doorbell_kernel_bo.
This bo holds the doorbell space now.
- Introduces mman.doorbell_bo_size: to save total doorbell memory size.
- Also introduces mman.doorbell_va to save CPU address of doorbell BO
mapping. This ptr will be used now for doorbell read/write from doorbell BAR.
Signed-off-by: Alex Deucher <alexander.deucher at amd.com>
Signed-off-by: Shashank Sharma <shashank.sharma at amd.com>
---
drivers/gpu/drm/amd/amdgpu/amdgpu.h | 1 -
drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.c | 5 ++--
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c | 28 ++++++++++----------
drivers/gpu/drm/amd/amdgpu/amdgpu_doorbell.h | 4 ---
drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c | 14 ++++++++++
drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.h | 6 +++++
6 files changed, 36 insertions(+), 22 deletions(-)
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu.h b/drivers/gpu/drm/amd/amdgpu/amdgpu.h
index e1c1a360614e..dd3875ae1ad3 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu.h
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu.h
@@ -834,7 +834,6 @@ struct amdgpu_device {
spinlock_t audio_endpt_idx_lock;
amdgpu_block_rreg_t audio_endpt_rreg;
amdgpu_block_wreg_t audio_endpt_wreg;
- struct amdgpu_doorbell doorbell;
/* clock/pll info */
struct amdgpu_clock clock;
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.c
index 28076da2258f..aea943e337df 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.c
@@ -109,11 +109,10 @@ static void amdgpu_doorbell_get_kfd_info(struct amdgpu_device *adev,
*aperture_base = adev->gmc.doorbell_aper_base;
*aperture_size = 0;
*start_offset = 0;
- } else if (adev->gmc.doorbell_aper_size > adev->doorbell.num_doorbells *
- sizeof(u32)) {
+ } else if (adev->gmc.doorbell_aper_size > adev->mman.doorbell_kernel_bo_size) {
*aperture_base = adev->gmc.doorbell_aper_base;
*aperture_size = adev->gmc.doorbell_aper_size;
- *start_offset = adev->doorbell.num_doorbells * sizeof(u32);
+ *start_offset = adev->mman.doorbell_kernel_bo_size;
} else {
*aperture_base = 0;
*aperture_size = 0;
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c
index cda5387aae50..85c353e4707a 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c
@@ -596,8 +596,8 @@ u32 amdgpu_mm_rdoorbell(struct amdgpu_device *adev, u32 index)
if (amdgpu_device_skip_hw_access(adev))
return 0;
- if (index < adev->doorbell.num_doorbells) {
- return readl(adev->mman.doorbell_aper_base_kaddr + index);
+ if (index < adev->mman.num_doorbells) {
+ return readl(adev->mman.doorbell_va + index);
} else {
DRM_ERROR("reading beyond doorbell aperture: 0x%08x!\n", index);
return 0;
@@ -619,8 +619,8 @@ void amdgpu_mm_wdoorbell(struct amdgpu_device *adev, u32 index, u32 v)
if (amdgpu_device_skip_hw_access(adev))
return;
- if (index < adev->doorbell.num_doorbells) {
- writel(v, adev->mman.doorbell_aper_base_kaddr + index);
+ if (index < adev->mman.num_doorbells) {
+ writel(v, adev->mman.doorbell_va + index);
} else {
DRM_ERROR("writing beyond doorbell aperture: 0x%08x!\n", index);
}
@@ -640,8 +640,8 @@ u64 amdgpu_mm_rdoorbell64(struct amdgpu_device *adev, u32 index)
if (amdgpu_device_skip_hw_access(adev))
return 0;
- if (index < adev->doorbell.num_doorbells) {
- return atomic64_read((atomic64_t *)(adev->mman.doorbell_aper_base_kaddr + index));
+ if (index < adev->mman.num_doorbells) {
+ return atomic64_read((atomic64_t *)(adev->mman.doorbell_va + index));
} else {
DRM_ERROR("reading beyond doorbell aperture: 0x%08x!\n", index);
return 0;
@@ -663,8 +663,8 @@ void amdgpu_mm_wdoorbell64(struct amdgpu_device *adev, u32 index, u64 v)
if (amdgpu_device_skip_hw_access(adev))
return;
- if (index < adev->doorbell.num_doorbells) {
- atomic64_set((atomic64_t *)(adev->mman.doorbell_aper_base_kaddr + index), v);
+ if (index < adev->mman.num_doorbells) {
+ atomic64_set((atomic64_t *)(adev->mman.doorbell_va + index), v);
} else {
DRM_ERROR("writing beyond doorbell aperture: 0x%08x!\n", index);
}
@@ -1037,7 +1037,7 @@ static int amdgpu_device_doorbell_init(struct amdgpu_device *adev)
if (adev->asic_type < CHIP_BONAIRE) {
adev->gmc.doorbell_aper_base = 0;
adev->gmc.doorbell_aper_size = 0;
- adev->doorbell.num_doorbells = 0;
+ adev->mman.num_doorbells = 0;
adev->mman.doorbell_aper_base_kaddr = NULL;
return 0;
}
@@ -1052,13 +1052,13 @@ static int amdgpu_device_doorbell_init(struct amdgpu_device *adev)
adev->gmc.doorbell_aper_size = pci_resource_len(adev->pdev, 2);
if (adev->enable_mes) {
- adev->doorbell.num_doorbells =
+ adev->mman.num_doorbells =
adev->gmc.doorbell_aper_size / sizeof(u32);
} else {
- adev->doorbell.num_doorbells =
+ adev->mman.num_doorbells =
min_t(u32, adev->gmc.doorbell_aper_size / sizeof(u32),
adev->doorbell_index.max_assignment+1);
- if (adev->doorbell.num_doorbells == 0)
+ if (adev->mman.num_doorbells == 0)
return -EINVAL;
/* For Vega, reserve and map two pages on doorbell BAR since SDMA
@@ -1068,11 +1068,11 @@ static int amdgpu_device_doorbell_init(struct amdgpu_device *adev)
* the max num_doorbells should + 1 page (0x400 in dword)
*/
if (adev->asic_type >= CHIP_VEGA10)
- adev->doorbell.num_doorbells += 0x400;
+ adev->mman.num_doorbells += 0x400;
}
adev->mman.doorbell_aper_base_kaddr = ioremap(adev->gmc.doorbell_aper_base,
- adev->doorbell.num_doorbells *
+ adev->mman.num_doorbells *
sizeof(u32));
if (adev->mman.doorbell_aper_base_kaddr == NULL)
return -ENOMEM;
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_doorbell.h b/drivers/gpu/drm/amd/amdgpu/amdgpu_doorbell.h
index 464be28da4fb..97298a98561f 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_doorbell.h
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_doorbell.h
@@ -24,10 +24,6 @@
/*
* GPU doorbell structures, functions & helpers
*/
-struct amdgpu_doorbell {
- u32 num_doorbells; /* Number of doorbells actually reserved for amdgpu. */
-};
-
/* Reserved doorbells for amdgpu (including multimedia).
* KFD can use all the rest in the 2M doorbell bar.
* For asic before vega10, doorbell is 32-bit, so the
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c
index 4cec90debe46..5f16023a5991 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c
@@ -1840,6 +1840,18 @@ int amdgpu_ttm_init(struct amdgpu_device *adev)
if (r)
return r;
+ adev->mman.doorbell_kernel_bo_size = adev->mman.num_doorbells * sizeof(u32);
+ r = amdgpu_bo_create_kernel_at(adev,
+ 0,
+ adev->mman.doorbell_kernel_bo_size,
+ AMDGPU_GEM_DOMAIN_DOORBELL,
+ &adev->mman.doorbell_kernel_bo,
+ (void **)&adev->mman.doorbell_va);
+ if (r) {
+ DRM_ERROR("Failed to create doorbell BO\n");
+ return r;
+ }
+
DRM_INFO("amdgpu: %uM of VRAM memory ready\n",
(unsigned) (adev->gmc.real_vram_size / (1024 * 1024)));
@@ -1931,6 +1943,8 @@ void amdgpu_ttm_fini(struct amdgpu_device *adev)
NULL, NULL);
amdgpu_bo_free_kernel(&adev->mman.sdma_access_bo, NULL,
&adev->mman.sdma_access_ptr);
+ amdgpu_bo_free_kernel(&adev->mman.doorbell_kernel_bo,
+ NULL, (void **)&adev->mman.doorbell_va);
amdgpu_ttm_fw_reserve_vram_fini(adev);
amdgpu_ttm_drv_reserve_vram_fini(adev);
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.h b/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.h
index 9971665d7d99..3cada4b49ca2 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.h
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.h
@@ -98,6 +98,12 @@ struct amdgpu_mman {
/* PAGE_SIZE'd BO for process memory r/w over SDMA. */
struct amdgpu_bo *sdma_access_bo;
void *sdma_access_ptr;
+
+ /* doorbells reserved for the kernel driver */
+ u32 num_doorbells; /* Number of doorbells actually reserved for amdgpu. */
+ uint64_t doorbell_kernel_bo_size;
+ struct amdgpu_bo *doorbell_kernel_bo;
+ u32 *doorbell_va;
};
struct amdgpu_copy_mem {
--
2.34.1
More information about the amd-gfx
mailing list