Skip to content

Commit 31afb33

Browse files
piorkovgregkh
authored andcommitted
drm/xe: Use dynamic allocation for tile and device VRAM region structures
[ Upstream commit f92cfd72d9a650f90260c54accd840c6500c4c3a ] In future platforms, we will need to represent the device and tile VRAM regions in a more dynamic way, so let's abandon the static allocation of these structures and start use a dynamic allocation. v2: - Add a helpers for accessing fields of the xe_vram_region structure v3: - Add missing EXPORT_SYMBOL_IF_KUNIT for xe_vram_region_actual_physical_size Signed-off-by: Piotr Piórkowski <[email protected]> Cc: Stuart Summers <[email protected]> Cc: Matthew Auld <[email protected]> Cc: Satyanarayana K V P <[email protected]> Reviewed-by: Satyanarayana K V P <[email protected]> Acked-by: Matthew Brost <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Lucas De Marchi <[email protected]> Stable-dep-of: d30203739be7 ("drm/xe: Move rebar to be done earlier") Signed-off-by: Sasha Levin <[email protected]> Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent 898acad commit 31afb33

16 files changed

Lines changed: 202 additions & 77 deletions

drivers/gpu/drm/xe/display/xe_fb_pin.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -289,15 +289,15 @@ static struct i915_vma *__xe_pin_fb_vma(const struct intel_framebuffer *fb,
289289
if (IS_DGFX(to_xe_device(bo->ttm.base.dev)) &&
290290
intel_fb_rc_ccs_cc_plane(&fb->base) >= 0 &&
291291
!(bo->flags & XE_BO_FLAG_NEEDS_CPU_ACCESS)) {
292-
struct xe_tile *tile = xe_device_get_root_tile(xe);
292+
struct xe_vram_region *vram = xe_device_get_root_tile(xe)->mem.vram;
293293

294294
/*
295295
* If we need to able to access the clear-color value stored in
296296
* the buffer, then we require that such buffers are also CPU
297297
* accessible. This is important on small-bar systems where
298298
* only some subset of VRAM is CPU accessible.
299299
*/
300-
if (tile->mem.vram.io_size < tile->mem.vram.usable_size) {
300+
if (xe_vram_region_io_size(vram) < xe_vram_region_usable_size(vram)) {
301301
ret = -EINVAL;
302302
goto err;
303303
}

drivers/gpu/drm/xe/display/xe_plane_initial.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ initial_plane_bo(struct xe_device *xe,
103103
* We don't currently expect this to ever be placed in the
104104
* stolen portion.
105105
*/
106-
if (phys_base >= tile0->mem.vram.usable_size) {
106+
if (phys_base >= xe_vram_region_usable_size(tile0->mem.vram)) {
107107
drm_err(&xe->drm,
108108
"Initial plane programming using invalid range, phys_base=%pa\n",
109109
&phys_base);

drivers/gpu/drm/xe/xe_assert.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212

1313
#include "xe_gt_types.h"
1414
#include "xe_step.h"
15+
#include "xe_vram.h"
1516

1617
/**
1718
* DOC: Xe Asserts
@@ -145,7 +146,8 @@
145146
const struct xe_tile *__tile = (tile); \
146147
char __buf[10] __maybe_unused; \
147148
xe_assert_msg(tile_to_xe(__tile), condition, "tile: %u VRAM %s\n" msg, \
148-
__tile->id, ({ string_get_size(__tile->mem.vram.actual_physical_size, 1, \
149+
__tile->id, ({ string_get_size( \
150+
xe_vram_region_actual_physical_size(__tile->mem.vram), 1, \
149151
STRING_UNITS_2, __buf, sizeof(__buf)); __buf; }), ## arg); \
150152
})
151153

drivers/gpu/drm/xe/xe_device.c

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -688,6 +688,21 @@ static void sriov_update_device_info(struct xe_device *xe)
688688
}
689689
}
690690

691+
static int xe_device_vram_alloc(struct xe_device *xe)
692+
{
693+
struct xe_vram_region *vram;
694+
695+
if (!IS_DGFX(xe))
696+
return 0;
697+
698+
vram = drmm_kzalloc(&xe->drm, sizeof(*vram), GFP_KERNEL);
699+
if (!vram)
700+
return -ENOMEM;
701+
702+
xe->mem.vram = vram;
703+
return 0;
704+
}
705+
691706
/**
692707
* xe_device_probe_early: Device early probe
693708
* @xe: xe device instance
@@ -735,6 +750,10 @@ int xe_device_probe_early(struct xe_device *xe)
735750

736751
xe->wedged.mode = xe_modparam.wedged_mode;
737752

753+
err = xe_device_vram_alloc(xe);
754+
if (err)
755+
return err;
756+
738757
return 0;
739758
}
740759
ALLOW_ERROR_INJECTION(xe_device_probe_early, ERRNO); /* See xe_pci_probe() */

drivers/gpu/drm/xe/xe_device_types.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,8 @@ struct xe_pxp;
7777
* device, such as HBM memory or CXL extension memory.
7878
*/
7979
struct xe_vram_region {
80+
/** @tile: Back pointer to tile */
81+
struct xe_tile *tile;
8082
/** @io_start: IO start address of this VRAM instance */
8183
resource_size_t io_start;
8284
/**
@@ -216,7 +218,7 @@ struct xe_tile {
216218
* Although VRAM is associated with a specific tile, it can
217219
* still be accessed by all tiles' GTs.
218220
*/
219-
struct xe_vram_region vram;
221+
struct xe_vram_region *vram;
220222

221223
/** @mem.ggtt: Global graphics translation table */
222224
struct xe_ggtt *ggtt;
@@ -412,7 +414,7 @@ struct xe_device {
412414
/** @mem: memory info for device */
413415
struct {
414416
/** @mem.vram: VRAM info for device */
415-
struct xe_vram_region vram;
417+
struct xe_vram_region *vram;
416418
/** @mem.sys_mgr: system TTM manager */
417419
struct ttm_resource_manager sys_mgr;
418420
/** @mem.sys_mgr: system memory shrinker. */

drivers/gpu/drm/xe/xe_gt_sriov_pf_config.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1604,7 +1604,7 @@ static u64 pf_query_free_lmem(struct xe_gt *gt)
16041604
{
16051605
struct xe_tile *tile = gt->tile;
16061606

1607-
return xe_ttm_vram_get_avail(&tile->mem.vram.ttm.manager);
1607+
return xe_ttm_vram_get_avail(&tile->mem.vram->ttm.manager);
16081608
}
16091609

16101610
static u64 pf_query_max_lmem(struct xe_gt *gt)

drivers/gpu/drm/xe/xe_migrate.c

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
#include "xe_sync.h"
3535
#include "xe_trace_bo.h"
3636
#include "xe_vm.h"
37+
#include "xe_vram.h"
3738

3839
/**
3940
* struct xe_migrate - migrate context.
@@ -130,34 +131,36 @@ static u64 xe_migrate_vram_ofs(struct xe_device *xe, u64 addr, bool is_comp_pte)
130131
u64 identity_offset = IDENTITY_OFFSET;
131132

132133
if (GRAPHICS_VER(xe) >= 20 && is_comp_pte)
133-
identity_offset += DIV_ROUND_UP_ULL(xe->mem.vram.actual_physical_size, SZ_1G);
134+
identity_offset += DIV_ROUND_UP_ULL(xe_vram_region_actual_physical_size
135+
(xe->mem.vram), SZ_1G);
134136

135-
addr -= xe->mem.vram.dpa_base;
137+
addr -= xe_vram_region_dpa_base(xe->mem.vram);
136138
return addr + (identity_offset << xe_pt_shift(2));
137139
}
138140

139141
static void xe_migrate_program_identity(struct xe_device *xe, struct xe_vm *vm, struct xe_bo *bo,
140142
u64 map_ofs, u64 vram_offset, u16 pat_index, u64 pt_2m_ofs)
141143
{
144+
struct xe_vram_region *vram = xe->mem.vram;
145+
resource_size_t dpa_base = xe_vram_region_dpa_base(vram);
142146
u64 pos, ofs, flags;
143147
u64 entry;
144148
/* XXX: Unclear if this should be usable_size? */
145-
u64 vram_limit = xe->mem.vram.actual_physical_size +
146-
xe->mem.vram.dpa_base;
149+
u64 vram_limit = xe_vram_region_actual_physical_size(vram) + dpa_base;
147150
u32 level = 2;
148151

149152
ofs = map_ofs + XE_PAGE_SIZE * level + vram_offset * 8;
150153
flags = vm->pt_ops->pte_encode_addr(xe, 0, pat_index, level,
151154
true, 0);
152155

153-
xe_assert(xe, IS_ALIGNED(xe->mem.vram.usable_size, SZ_2M));
156+
xe_assert(xe, IS_ALIGNED(xe_vram_region_usable_size(vram), SZ_2M));
154157

155158
/*
156159
* Use 1GB pages when possible, last chunk always use 2M
157160
* pages as mixing reserved memory (stolen, WOCPM) with a single
158161
* mapping is not allowed on certain platforms.
159162
*/
160-
for (pos = xe->mem.vram.dpa_base; pos < vram_limit;
163+
for (pos = dpa_base; pos < vram_limit;
161164
pos += SZ_1G, ofs += 8) {
162165
if (pos + SZ_1G >= vram_limit) {
163166
entry = vm->pt_ops->pde_encode_bo(bo, pt_2m_ofs,
@@ -307,11 +310,11 @@ static int xe_migrate_prepare_vm(struct xe_tile *tile, struct xe_migrate *m,
307310
/* Identity map the entire vram at 256GiB offset */
308311
if (IS_DGFX(xe)) {
309312
u64 pt30_ofs = xe_bo_size(bo) - 2 * XE_PAGE_SIZE;
313+
resource_size_t actual_phy_size = xe_vram_region_actual_physical_size(xe->mem.vram);
310314

311315
xe_migrate_program_identity(xe, vm, bo, map_ofs, IDENTITY_OFFSET,
312316
pat_index, pt30_ofs);
313-
xe_assert(xe, xe->mem.vram.actual_physical_size <=
314-
(MAX_NUM_PTE - IDENTITY_OFFSET) * SZ_1G);
317+
xe_assert(xe, actual_phy_size <= (MAX_NUM_PTE - IDENTITY_OFFSET) * SZ_1G);
315318

316319
/*
317320
* Identity map the entire vram for compressed pat_index for xe2+
@@ -320,11 +323,11 @@ static int xe_migrate_prepare_vm(struct xe_tile *tile, struct xe_migrate *m,
320323
if (GRAPHICS_VER(xe) >= 20 && xe_device_has_flat_ccs(xe)) {
321324
u16 comp_pat_index = xe->pat.idx[XE_CACHE_NONE_COMPRESSION];
322325
u64 vram_offset = IDENTITY_OFFSET +
323-
DIV_ROUND_UP_ULL(xe->mem.vram.actual_physical_size, SZ_1G);
326+
DIV_ROUND_UP_ULL(actual_phy_size, SZ_1G);
324327
u64 pt31_ofs = xe_bo_size(bo) - XE_PAGE_SIZE;
325328

326-
xe_assert(xe, xe->mem.vram.actual_physical_size <= (MAX_NUM_PTE -
327-
IDENTITY_OFFSET - IDENTITY_OFFSET / 2) * SZ_1G);
329+
xe_assert(xe, actual_phy_size <= (MAX_NUM_PTE - IDENTITY_OFFSET -
330+
IDENTITY_OFFSET / 2) * SZ_1G);
328331
xe_migrate_program_identity(xe, vm, bo, map_ofs, vram_offset,
329332
comp_pat_index, pt31_ofs);
330333
}

drivers/gpu/drm/xe/xe_pci.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -687,13 +687,19 @@ static int xe_info_init(struct xe_device *xe,
687687
* All of these together determine the overall GT count.
688688
*/
689689
for_each_tile(tile, xe, id) {
690+
int err;
691+
690692
gt = tile->primary_gt;
691693
gt->info.type = XE_GT_TYPE_MAIN;
692694
gt->info.id = tile->id * xe->info.max_gt_per_tile;
693695
gt->info.has_indirect_ring_state = graphics_desc->has_indirect_ring_state;
694696
gt->info.engine_mask = graphics_desc->hw_engine_mask;
695697
xe->info.gt_count++;
696698

699+
err = xe_tile_alloc_vram(tile);
700+
if (err)
701+
return err;
702+
697703
if (MEDIA_VER(xe) < 13 && media_desc)
698704
gt->info.engine_mask |= media_desc->hw_engine_mask;
699705

drivers/gpu/drm/xe/xe_query.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -334,7 +334,7 @@ static int query_config(struct xe_device *xe, struct drm_xe_device_query *query)
334334
config->num_params = num_params;
335335
config->info[DRM_XE_QUERY_CONFIG_REV_AND_DEVICE_ID] =
336336
xe->info.devid | (xe->info.revid << 16);
337-
if (xe_device_get_root_tile(xe)->mem.vram.usable_size)
337+
if (xe->mem.vram)
338338
config->info[DRM_XE_QUERY_CONFIG_FLAGS] |=
339339
DRM_XE_QUERY_CONFIG_FLAG_HAS_VRAM;
340340
if (xe->info.has_usm && IS_ENABLED(CONFIG_DRM_XE_GPUSVM))

drivers/gpu/drm/xe/xe_svm.c

Lines changed: 7 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -306,16 +306,11 @@ static struct xe_vram_region *page_to_vr(struct page *page)
306306
return container_of(page_pgmap(page), struct xe_vram_region, pagemap);
307307
}
308308

309-
static struct xe_tile *vr_to_tile(struct xe_vram_region *vr)
310-
{
311-
return container_of(vr, struct xe_tile, mem.vram);
312-
}
313-
314309
static u64 xe_vram_region_page_to_dpa(struct xe_vram_region *vr,
315310
struct page *page)
316311
{
317312
u64 dpa;
318-
struct xe_tile *tile = vr_to_tile(vr);
313+
struct xe_tile *tile = vr->tile;
319314
u64 pfn = page_to_pfn(page);
320315
u64 offset;
321316

@@ -370,7 +365,7 @@ static int xe_svm_copy(struct page **pages, dma_addr_t *dma_addr,
370365

371366
if (!vr && spage) {
372367
vr = page_to_vr(spage);
373-
tile = vr_to_tile(vr);
368+
tile = vr->tile;
374369
}
375370
XE_WARN_ON(spage && page_to_vr(spage) != vr);
376371

@@ -508,7 +503,7 @@ static u64 block_offset_to_pfn(struct xe_vram_region *vr, u64 offset)
508503

509504
static struct drm_buddy *tile_to_buddy(struct xe_tile *tile)
510505
{
511-
return &tile->mem.vram.ttm.mm;
506+
return &tile->mem.vram->ttm.mm;
512507
}
513508

514509
static int xe_svm_populate_devmem_pfn(struct drm_pagemap_devmem *devmem_allocation,
@@ -522,7 +517,7 @@ static int xe_svm_populate_devmem_pfn(struct drm_pagemap_devmem *devmem_allocati
522517

523518
list_for_each_entry(block, blocks, link) {
524519
struct xe_vram_region *vr = block->private;
525-
struct xe_tile *tile = vr_to_tile(vr);
520+
struct xe_tile *tile = vr->tile;
526521
struct drm_buddy *buddy = tile_to_buddy(tile);
527522
u64 block_pfn = block_offset_to_pfn(vr, drm_buddy_block_offset(block));
528523
int i;
@@ -683,20 +678,15 @@ u64 xe_svm_find_vma_start(struct xe_vm *vm, u64 start, u64 end, struct xe_vma *v
683678
}
684679

685680
#if IS_ENABLED(CONFIG_DRM_XE_PAGEMAP)
686-
static struct xe_vram_region *tile_to_vr(struct xe_tile *tile)
687-
{
688-
return &tile->mem.vram;
689-
}
690-
691681
static int xe_drm_pagemap_populate_mm(struct drm_pagemap *dpagemap,
692682
unsigned long start, unsigned long end,
693683
struct mm_struct *mm,
694684
unsigned long timeslice_ms)
695685
{
696-
struct xe_tile *tile = container_of(dpagemap, typeof(*tile), mem.vram.dpagemap);
686+
struct xe_vram_region *vr = container_of(dpagemap, typeof(*vr), dpagemap);
687+
struct xe_tile *tile = vr->tile;
697688
struct xe_device *xe = tile_to_xe(tile);
698689
struct device *dev = xe->drm.dev;
699-
struct xe_vram_region *vr = tile_to_vr(tile);
700690
struct drm_buddy_block *block;
701691
struct list_head *blocks;
702692
struct xe_bo *bo;
@@ -722,7 +712,7 @@ static int xe_drm_pagemap_populate_mm(struct drm_pagemap *dpagemap,
722712

723713
drm_pagemap_devmem_init(&bo->devmem_allocation, dev, mm,
724714
&dpagemap_devmem_ops,
725-
&tile->mem.vram.dpagemap,
715+
&tile->mem.vram->dpagemap,
726716
end - start);
727717

728718
blocks = &to_xe_ttm_vram_mgr_resource(bo->ttm.resource)->blocks;

0 commit comments

Comments
 (0)