Skip to content

Commit ecacec0

Browse files
committed
drm/xe: Add Xe SVM populate_devmem_pfn GPU SVM vfunc
Get device pfns from BO's buddy blocks. Used in migrate_* core MM functions called in GPU SVM to migrate between device and system memory. v2: - Use new drm_gpusvm_devmem_ops v3: - Better commit message (Thomas) v5: - s/xe_mem_region/xe_vram_region (Rebase) Signed-off-by: Niranjana Vishwanathapura <[email protected]> Signed-off-by: Oak Zeng <[email protected]> Signed-off-by: Matthew Brost <[email protected]> Reviewed-by: Thomas Hellström <[email protected]> Link: https://patchwork.freedesktop.org/patch/msgid/[email protected]
1 parent c5b3eb5 commit ecacec0

File tree

1 file changed

+40
-0
lines changed

1 file changed

+40
-0
lines changed

drivers/gpu/drm/xe/xe_svm.c

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
#include "xe_migrate.h"
88
#include "xe_pt.h"
99
#include "xe_svm.h"
10+
#include "xe_ttm_vram_mgr.h"
1011
#include "xe_vm.h"
1112
#include "xe_vm_types.h"
1213

@@ -461,8 +462,47 @@ static int xe_svm_copy_to_ram(struct page **pages, dma_addr_t *dma_addr,
461462
return xe_svm_copy(pages, dma_addr, npages, XE_SVM_COPY_TO_SRAM);
462463
}
463464

465+
static struct xe_bo *to_xe_bo(struct drm_gpusvm_devmem *devmem_allocation)
466+
{
467+
return container_of(devmem_allocation, struct xe_bo, devmem_allocation);
468+
}
469+
470+
static u64 block_offset_to_pfn(struct xe_vram_region *vr, u64 offset)
471+
{
472+
return PHYS_PFN(offset + vr->hpa_base);
473+
}
474+
475+
static struct drm_buddy *tile_to_buddy(struct xe_tile *tile)
476+
{
477+
return &tile->mem.vram.ttm.mm;
478+
}
479+
480+
static int xe_svm_populate_devmem_pfn(struct drm_gpusvm_devmem *devmem_allocation,
481+
unsigned long npages, unsigned long *pfn)
482+
{
483+
struct xe_bo *bo = to_xe_bo(devmem_allocation);
484+
struct ttm_resource *res = bo->ttm.resource;
485+
struct list_head *blocks = &to_xe_ttm_vram_mgr_resource(res)->blocks;
486+
struct drm_buddy_block *block;
487+
int j = 0;
488+
489+
list_for_each_entry(block, blocks, link) {
490+
struct xe_vram_region *vr = block->private;
491+
struct xe_tile *tile = vr_to_tile(vr);
492+
struct drm_buddy *buddy = tile_to_buddy(tile);
493+
u64 block_pfn = block_offset_to_pfn(vr, drm_buddy_block_offset(block));
494+
int i;
495+
496+
for (i = 0; i < drm_buddy_block_size(buddy, block) >> PAGE_SHIFT; ++i)
497+
pfn[j++] = block_pfn + i;
498+
}
499+
500+
return 0;
501+
}
502+
464503
__maybe_unused
465504
static const struct drm_gpusvm_devmem_ops gpusvm_devmem_ops = {
505+
.populate_devmem_pfn = xe_svm_populate_devmem_pfn,
466506
.copy_to_devmem = xe_svm_copy_to_devmem,
467507
.copy_to_ram = xe_svm_copy_to_ram,
468508
};

0 commit comments

Comments
 (0)