Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 54c30d2

Browse files
contactshashanksharmaalexdeucher
authored andcommitted
drm/amdgpu: create kernel doorbell pages
This patch: - creates a doorbell page for graphics driver usages. - adds a few new varlables in adev->doorbell structure to keep track of kernel's doorbell-bo. - removes the adev->doorbell.ptr variable, replaces it with kernel-doorbell-bo's cpu address. V2: - Create doorbell BO directly, no wrappe functions (Alex) - no additional doorbell structure (Alex, Christian) - Use doorbell_cpu_ptr, remove ioremap (Christian, Alex) - Allocate one extra page of doorbells for MES (Alex) V4: Move MES doorbell base init into MES related patch (Christian) Cc: Alex Deucher <[email protected]> Cc: Christian Koenig <[email protected]> Reviewed-by: Christian König <[email protected]> Signed-off-by: Shashank Sharma <[email protected]> Signed-off-by: Alex Deucher <[email protected]>
1 parent 36f3f37 commit 54c30d2

File tree

3 files changed

+53
-14
lines changed

3 files changed

+53
-14
lines changed

drivers/gpu/drm/amd/amdgpu/amdgpu_doorbell.h

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,15 @@ struct amdgpu_doorbell {
3131
/* doorbell mmio */
3232
resource_size_t base;
3333
resource_size_t size;
34-
u32 __iomem *ptr;
3534

3635
/* Number of doorbells reserved for amdgpu kernel driver */
3736
u32 num_kernel_doorbells;
37+
38+
/* Kernel doorbells */
39+
struct amdgpu_bo *kernel_doorbells;
40+
41+
/* For CPU access of doorbells */
42+
uint32_t *cpu_addr;
3843
};
3944

4045
/* Reserved doorbells for amdgpu (including multimedia).
@@ -350,6 +355,7 @@ void amdgpu_mm_wdoorbell64(struct amdgpu_device *adev, u32 index, u64 v);
350355
*/
351356
int amdgpu_doorbell_init(struct amdgpu_device *adev);
352357
void amdgpu_doorbell_fini(struct amdgpu_device *adev);
358+
int amdgpu_doorbell_create_kernel_doorbells(struct amdgpu_device *adev);
353359

354360
#define RDOORBELL32(index) amdgpu_mm_rdoorbell(adev, (index))
355361
#define WDOORBELL32(index, v) amdgpu_mm_wdoorbell(adev, (index), (v))

drivers/gpu/drm/amd/amdgpu/amdgpu_doorbell_mgr.c

Lines changed: 39 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ u32 amdgpu_mm_rdoorbell(struct amdgpu_device *adev, u32 index)
3939
return 0;
4040

4141
if (index < adev->doorbell.num_kernel_doorbells)
42-
return readl(adev->doorbell.ptr + index);
42+
return readl(adev->doorbell.cpu_addr + index);
4343

4444
DRM_ERROR("reading beyond doorbell aperture: 0x%08x!\n", index);
4545
return 0;
@@ -61,7 +61,7 @@ void amdgpu_mm_wdoorbell(struct amdgpu_device *adev, u32 index, u32 v)
6161
return;
6262

6363
if (index < adev->doorbell.num_kernel_doorbells)
64-
writel(v, adev->doorbell.ptr + index);
64+
writel(v, adev->doorbell.cpu_addr + index);
6565
else
6666
DRM_ERROR("writing beyond doorbell aperture: 0x%08x!\n", index);
6767
}
@@ -81,7 +81,7 @@ u64 amdgpu_mm_rdoorbell64(struct amdgpu_device *adev, u32 index)
8181
return 0;
8282

8383
if (index < adev->doorbell.num_kernel_doorbells)
84-
return atomic64_read((atomic64_t *)(adev->doorbell.ptr + index));
84+
return atomic64_read((atomic64_t *)(adev->doorbell.cpu_addr + index));
8585

8686
DRM_ERROR("reading beyond doorbell aperture: 0x%08x!\n", index);
8787
return 0;
@@ -103,11 +103,43 @@ void amdgpu_mm_wdoorbell64(struct amdgpu_device *adev, u32 index, u64 v)
103103
return;
104104

105105
if (index < adev->doorbell.num_kernel_doorbells)
106-
atomic64_set((atomic64_t *)(adev->doorbell.ptr + index), v);
106+
atomic64_set((atomic64_t *)(adev->doorbell.cpu_addr + index), v);
107107
else
108108
DRM_ERROR("writing beyond doorbell aperture: 0x%08x!\n", index);
109109
}
110110

111+
/**
112+
* amdgpu_doorbell_create_kernel_doorbells - Create kernel doorbells for graphics
113+
*
114+
* @adev: amdgpu_device pointer
115+
*
116+
* Creates doorbells for graphics driver usages.
117+
* returns 0 on success, error otherwise.
118+
*/
119+
int amdgpu_doorbell_create_kernel_doorbells(struct amdgpu_device *adev)
120+
{
121+
int r;
122+
int size;
123+
124+
/* Reserve first num_kernel_doorbells (page-aligned) for kernel ops */
125+
size = ALIGN(adev->doorbell.num_kernel_doorbells * sizeof(u32), PAGE_SIZE);
126+
127+
r = amdgpu_bo_create_kernel(adev,
128+
size,
129+
PAGE_SIZE,
130+
AMDGPU_GEM_DOMAIN_DOORBELL,
131+
&adev->doorbell.kernel_doorbells,
132+
NULL,
133+
(void **)&adev->doorbell.cpu_addr);
134+
if (r) {
135+
DRM_ERROR("Failed to allocate kernel doorbells, err=%d\n", r);
136+
return r;
137+
}
138+
139+
adev->doorbell.num_kernel_doorbells = size / sizeof(u32);
140+
return 0;
141+
}
142+
111143
/*
112144
* GPU doorbell aperture helpers function.
113145
*/
@@ -127,7 +159,6 @@ int amdgpu_doorbell_init(struct amdgpu_device *adev)
127159
adev->doorbell.base = 0;
128160
adev->doorbell.size = 0;
129161
adev->doorbell.num_kernel_doorbells = 0;
130-
adev->doorbell.ptr = NULL;
131162
return 0;
132163
}
133164

@@ -156,12 +187,6 @@ int amdgpu_doorbell_init(struct amdgpu_device *adev)
156187
if (adev->asic_type >= CHIP_VEGA10)
157188
adev->doorbell.num_kernel_doorbells += 0x400;
158189

159-
adev->doorbell.ptr = ioremap(adev->doorbell.base,
160-
adev->doorbell.num_kernel_doorbells *
161-
sizeof(u32));
162-
if (adev->doorbell.ptr == NULL)
163-
return -ENOMEM;
164-
165190
return 0;
166191
}
167192

@@ -174,6 +199,7 @@ int amdgpu_doorbell_init(struct amdgpu_device *adev)
174199
*/
175200
void amdgpu_doorbell_fini(struct amdgpu_device *adev)
176201
{
177-
iounmap(adev->doorbell.ptr);
178-
adev->doorbell.ptr = NULL;
202+
amdgpu_bo_free_kernel(&adev->doorbell.kernel_doorbells,
203+
NULL,
204+
(void **)&adev->doorbell.cpu_addr);
179205
}

drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1945,6 +1945,13 @@ int amdgpu_ttm_init(struct amdgpu_device *adev)
19451945
return r;
19461946
}
19471947

1948+
/* Create a boorbell page for kernel usages */
1949+
r = amdgpu_doorbell_create_kernel_doorbells(adev);
1950+
if (r) {
1951+
DRM_ERROR("Failed to initialize kernel doorbells.\n");
1952+
return r;
1953+
}
1954+
19481955
/* Initialize preemptible memory pool */
19491956
r = amdgpu_preempt_mgr_init(adev);
19501957
if (r) {

0 commit comments

Comments
 (0)