Skip to content

Commit 4a5ad08

Browse files
arunpravin24alexdeucher
authored andcommitted
drm/amdgpu: Add address alignment support to DCC buffers
Add address alignment support to the DCC VRAM buffers. v2: - adjust size based on the max_texture_channel_caches values only for GFX12 DCC buffers. - used AMDGPU_GEM_CREATE_GFX12_DCC flag to apply change only for DCC buffers. - roundup non power of two DCC buffer adjusted size to nearest power of two number as the buddy allocator does not support non power of two alignments. This applies only to the contiguous DCC buffers. v3:(Alex) - rewrite the max texture channel caches comparison code in an algorithmic way to determine the alignment size. v4:(Alex) - Move the logic from amdgpu_vram_mgr_dcc_alignment() to gmc_v12_0.c and add a new gmc func callback for dcc alignment. If the callback is non-NULL, call it to get the alignment, otherwise, use the default. v5:(Alex) - Set the Alignment to a default value if the callback doesn't exist. - Add the callback to amdgpu_gmc_funcs. v6: - Fix checkpatch warning reported by Intel CI. v7:(Christian) - remove the AMDGPU_GEM_CREATE_GFX12_DCC flag and keep a flag that checks the BO pinning and for a specific hw generation. v8:(Christian) - move this check into gmc_v12_0_get_dcc_alignment. v9: - Fix 32bit build errors Signed-off-by: Arunpravin Paneer Selvam <[email protected]> Acked-by: Alex Deucher <[email protected]> Acked-by: Christian König <[email protected]> Reviewed-by: Frank Min <[email protected]> Signed-off-by: Alex Deucher <[email protected]> (cherry picked from commit aa94b62)
1 parent 50e376f commit 4a5ad08

File tree

3 files changed

+57
-2
lines changed

3 files changed

+57
-2
lines changed

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,8 @@ struct amdgpu_gmc_funcs {
156156
uint64_t addr, uint64_t *flags);
157157
/* get the amount of memory used by the vbios for pre-OS console */
158158
unsigned int (*get_vbios_fb_size)(struct amdgpu_device *adev);
159+
/* get the DCC buffer alignment */
160+
unsigned int (*get_dcc_alignment)(struct amdgpu_device *adev);
159161

160162
enum amdgpu_memory_partition (*query_mem_partition_mode)(
161163
struct amdgpu_device *adev);
@@ -363,6 +365,10 @@ struct amdgpu_gmc {
363365
(adev)->gmc.gmc_funcs->override_vm_pte_flags \
364366
((adev), (vm), (addr), (pte_flags))
365367
#define amdgpu_gmc_get_vbios_fb_size(adev) (adev)->gmc.gmc_funcs->get_vbios_fb_size((adev))
368+
#define amdgpu_gmc_get_dcc_alignment(adev) ({ \
369+
typeof(adev) _adev = (adev); \
370+
_adev->gmc.gmc_funcs->get_dcc_alignment(_adev); \
371+
})
366372

367373
/**
368374
* amdgpu_gmc_vram_full_visible - Check if full VRAM is visible through the BAR

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

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -456,6 +456,7 @@ static int amdgpu_vram_mgr_new(struct ttm_resource_manager *man,
456456
u64 vis_usage = 0, max_bytes, min_block_size;
457457
struct amdgpu_vram_mgr_resource *vres;
458458
u64 size, remaining_size, lpfn, fpfn;
459+
unsigned int adjust_dcc_size = 0;
459460
struct drm_buddy *mm = &mgr->mm;
460461
struct drm_buddy_block *block;
461462
unsigned long pages_per_block;
@@ -511,7 +512,18 @@ static int amdgpu_vram_mgr_new(struct ttm_resource_manager *man,
511512
/* Allocate blocks in desired range */
512513
vres->flags |= DRM_BUDDY_RANGE_ALLOCATION;
513514

515+
if (adev->gmc.gmc_funcs->get_dcc_alignment)
516+
adjust_dcc_size = amdgpu_gmc_get_dcc_alignment(adev);
517+
514518
remaining_size = (u64)vres->base.size;
519+
if (bo->flags & AMDGPU_GEM_CREATE_VRAM_CONTIGUOUS && adjust_dcc_size) {
520+
unsigned int dcc_size;
521+
522+
dcc_size = roundup_pow_of_two(vres->base.size + adjust_dcc_size);
523+
remaining_size = (u64)dcc_size;
524+
525+
vres->flags |= DRM_BUDDY_TRIM_DISABLE;
526+
}
515527

516528
mutex_lock(&mgr->lock);
517529
while (remaining_size) {
@@ -521,8 +533,11 @@ static int amdgpu_vram_mgr_new(struct ttm_resource_manager *man,
521533
min_block_size = mgr->default_page_size;
522534

523535
size = remaining_size;
524-
if ((size >= (u64)pages_per_block << PAGE_SHIFT) &&
525-
!(size & (((u64)pages_per_block << PAGE_SHIFT) - 1)))
536+
537+
if (bo->flags & AMDGPU_GEM_CREATE_VRAM_CONTIGUOUS && adjust_dcc_size)
538+
min_block_size = size;
539+
else if ((size >= (u64)pages_per_block << PAGE_SHIFT) &&
540+
!(size & (((u64)pages_per_block << PAGE_SHIFT) - 1)))
526541
min_block_size = (u64)pages_per_block << PAGE_SHIFT;
527542

528543
BUG_ON(min_block_size < mm->chunk_size);
@@ -553,6 +568,22 @@ static int amdgpu_vram_mgr_new(struct ttm_resource_manager *man,
553568
}
554569
mutex_unlock(&mgr->lock);
555570

571+
if (bo->flags & AMDGPU_GEM_CREATE_VRAM_CONTIGUOUS && adjust_dcc_size) {
572+
struct drm_buddy_block *dcc_block;
573+
unsigned long dcc_start;
574+
u64 trim_start;
575+
576+
dcc_block = amdgpu_vram_mgr_first_block(&vres->blocks);
577+
/* Adjust the start address for DCC buffers only */
578+
dcc_start =
579+
roundup((unsigned long)amdgpu_vram_mgr_block_start(dcc_block),
580+
adjust_dcc_size);
581+
trim_start = (u64)dcc_start;
582+
drm_buddy_block_trim(mm, &trim_start,
583+
(u64)vres->base.size,
584+
&vres->blocks);
585+
}
586+
556587
vres->base.start = 0;
557588
size = max_t(u64, amdgpu_vram_mgr_blocks_size(&vres->blocks),
558589
vres->base.size);

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

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -542,6 +542,23 @@ static unsigned gmc_v12_0_get_vbios_fb_size(struct amdgpu_device *adev)
542542
return 0;
543543
}
544544

545+
static unsigned int gmc_v12_0_get_dcc_alignment(struct amdgpu_device *adev)
546+
{
547+
unsigned int max_tex_channel_caches, alignment;
548+
549+
if (amdgpu_ip_version(adev, GC_HWIP, 0) != IP_VERSION(12, 0, 0) &&
550+
amdgpu_ip_version(adev, GC_HWIP, 0) != IP_VERSION(12, 0, 1))
551+
return 0;
552+
553+
max_tex_channel_caches = adev->gfx.config.max_texture_channel_caches;
554+
if (is_power_of_2(max_tex_channel_caches))
555+
alignment = (unsigned int)(max_tex_channel_caches / SZ_4);
556+
else
557+
alignment = roundup_pow_of_two(max_tex_channel_caches);
558+
559+
return (unsigned int)(alignment * max_tex_channel_caches * SZ_1K);
560+
}
561+
545562
static const struct amdgpu_gmc_funcs gmc_v12_0_gmc_funcs = {
546563
.flush_gpu_tlb = gmc_v12_0_flush_gpu_tlb,
547564
.flush_gpu_tlb_pasid = gmc_v12_0_flush_gpu_tlb_pasid,
@@ -551,6 +568,7 @@ static const struct amdgpu_gmc_funcs gmc_v12_0_gmc_funcs = {
551568
.get_vm_pde = gmc_v12_0_get_vm_pde,
552569
.get_vm_pte = gmc_v12_0_get_vm_pte,
553570
.get_vbios_fb_size = gmc_v12_0_get_vbios_fb_size,
571+
.get_dcc_alignment = gmc_v12_0_get_dcc_alignment,
554572
};
555573

556574
static void gmc_v12_0_set_gmc_funcs(struct amdgpu_device *adev)

0 commit comments

Comments
 (0)