|
7 | 7 | #include "xe_migrate.h"
|
8 | 8 | #include "xe_pt.h"
|
9 | 9 | #include "xe_svm.h"
|
| 10 | +#include "xe_ttm_vram_mgr.h" |
10 | 11 | #include "xe_vm.h"
|
11 | 12 | #include "xe_vm_types.h"
|
12 | 13 |
|
@@ -461,8 +462,47 @@ static int xe_svm_copy_to_ram(struct page **pages, dma_addr_t *dma_addr,
|
461 | 462 | return xe_svm_copy(pages, dma_addr, npages, XE_SVM_COPY_TO_SRAM);
|
462 | 463 | }
|
463 | 464 |
|
| 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 | + |
464 | 503 | __maybe_unused
|
465 | 504 | static const struct drm_gpusvm_devmem_ops gpusvm_devmem_ops = {
|
| 505 | + .populate_devmem_pfn = xe_svm_populate_devmem_pfn, |
466 | 506 | .copy_to_devmem = xe_svm_copy_to_devmem,
|
467 | 507 | .copy_to_ram = xe_svm_copy_to_ram,
|
468 | 508 | };
|
|
0 commit comments