Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

drm/xe: Allow bo mapping on multiple ggtts

Make bo->ggtt an array to support bo mapping on multiple ggtts.
Add XE_BO_FLAG_GGTTx flags to map the bo on ggtt of tile 'x'.

Signed-off-by: Niranjana Vishwanathapura <niranjana.vishwanathapura@intel.com>
Reviewed-by: Matthew Brost <matthew.brost@intel.com>
Signed-off-by: John Harrison <John.C.Harrison@Intel.com>
Link: https://patchwork.freedesktop.org/patch/msgid/20241120000222.204095-2-John.C.Harrison@Intel.com

authored by

Niranjana Vishwanathapura and committed by
John Harrison
5a3b0df2 ae78ec0a

+101 -46
+7 -5
drivers/gpu/drm/xe/display/xe_fb_pin.c
··· 161 161 } 162 162 163 163 vma->dpt = dpt; 164 - vma->node = dpt->ggtt_node; 164 + vma->node = dpt->ggtt_node[tile0->id]; 165 165 return 0; 166 166 } 167 167 ··· 213 213 if (xe_bo_is_vram(bo) && ggtt->flags & XE_GGTT_FLAGS_64K) 214 214 align = max_t(u32, align, SZ_64K); 215 215 216 - if (bo->ggtt_node && view->type == I915_GTT_VIEW_NORMAL) { 217 - vma->node = bo->ggtt_node; 216 + if (bo->ggtt_node[ggtt->tile->id] && view->type == I915_GTT_VIEW_NORMAL) { 217 + vma->node = bo->ggtt_node[ggtt->tile->id]; 218 218 } else if (view->type == I915_GTT_VIEW_NORMAL) { 219 219 u32 x, size = bo->ttm.base.size; 220 220 ··· 345 345 346 346 static void __xe_unpin_fb_vma(struct i915_vma *vma) 347 347 { 348 + u8 tile_id = vma->node->ggtt->tile->id; 349 + 348 350 if (vma->dpt) 349 351 xe_bo_unpin_map_no_vm(vma->dpt); 350 - else if (!xe_ggtt_node_allocated(vma->bo->ggtt_node) || 351 - vma->bo->ggtt_node->base.start != vma->node->base.start) 352 + else if (!xe_ggtt_node_allocated(vma->bo->ggtt_node[tile_id]) || 353 + vma->bo->ggtt_node[tile_id]->base.start != vma->node->base.start) 352 354 xe_ggtt_node_remove(vma->node, false); 353 355 354 356 ttm_bo_reserve(&vma->bo->ttm, false, false, NULL);
+35 -14
drivers/gpu/drm/xe/xe_bo.c
··· 1140 1140 { 1141 1141 struct xe_bo *bo = ttm_to_xe_bo(ttm_bo); 1142 1142 struct xe_device *xe = ttm_to_xe_device(ttm_bo->bdev); 1143 + struct xe_tile *tile; 1144 + u8 id; 1143 1145 1144 1146 if (bo->ttm.base.import_attach) 1145 1147 drm_prime_gem_destroy(&bo->ttm.base, NULL); ··· 1149 1147 1150 1148 xe_assert(xe, list_empty(&ttm_bo->base.gpuva.list)); 1151 1149 1152 - if (bo->ggtt_node && bo->ggtt_node->base.size) 1153 - xe_ggtt_remove_bo(bo->tile->mem.ggtt, bo); 1150 + for_each_tile(tile, xe, id) 1151 + if (bo->ggtt_node[id] && bo->ggtt_node[id]->base.size) 1152 + xe_ggtt_remove_bo(tile->mem.ggtt, bo); 1154 1153 1155 1154 #ifdef CONFIG_PROC_FS 1156 1155 if (bo->client) ··· 1321 1318 xe_bo_free(bo); 1322 1319 return ERR_PTR(-EINVAL); 1323 1320 } 1321 + 1322 + /* XE_BO_FLAG_GGTTx requires XE_BO_FLAG_GGTT also be set */ 1323 + if ((flags & XE_BO_FLAG_GGTT_ALL) && !(flags & XE_BO_FLAG_GGTT)) 1324 + return ERR_PTR(-EINVAL); 1324 1325 1325 1326 if (flags & (XE_BO_FLAG_VRAM_MASK | XE_BO_FLAG_STOLEN) && 1326 1327 !(flags & XE_BO_FLAG_IGNORE_MIN_PAGE_SIZE) && ··· 1516 1509 bo->vm = vm; 1517 1510 1518 1511 if (bo->flags & XE_BO_FLAG_GGTT) { 1519 - if (!tile && flags & XE_BO_FLAG_STOLEN) 1520 - tile = xe_device_get_root_tile(xe); 1512 + struct xe_tile *t; 1513 + u8 id; 1521 1514 1522 - xe_assert(xe, tile); 1515 + if (!(bo->flags & XE_BO_FLAG_GGTT_ALL)) { 1516 + if (!tile && flags & XE_BO_FLAG_STOLEN) 1517 + tile = xe_device_get_root_tile(xe); 1523 1518 1524 - if (flags & XE_BO_FLAG_FIXED_PLACEMENT) { 1525 - err = xe_ggtt_insert_bo_at(tile->mem.ggtt, bo, 1526 - start + bo->size, U64_MAX); 1527 - } else { 1528 - err = xe_ggtt_insert_bo(tile->mem.ggtt, bo); 1519 + xe_assert(xe, tile); 1529 1520 } 1530 - if (err) 1531 - goto err_unlock_put_bo; 1521 + 1522 + for_each_tile(t, xe, id) { 1523 + if (t != tile && !(bo->flags & XE_BO_FLAG_GGTTx(t))) 1524 + continue; 1525 + 1526 + if (flags & XE_BO_FLAG_FIXED_PLACEMENT) { 1527 + err = xe_ggtt_insert_bo_at(t->mem.ggtt, bo, 1528 + start + bo->size, U64_MAX); 1529 + } else { 1530 + err = xe_ggtt_insert_bo(t->mem.ggtt, bo); 1531 + } 1532 + if (err) 1533 + goto err_unlock_put_bo; 1534 + } 1532 1535 } 1533 1536 1534 1537 return bo; ··· 2396 2379 2397 2380 void xe_bo_put(struct xe_bo *bo) 2398 2381 { 2382 + struct xe_tile *tile; 2383 + u8 id; 2384 + 2399 2385 might_sleep(); 2400 2386 if (bo) { 2401 2387 #ifdef CONFIG_PROC_FS 2402 2388 if (bo->client) 2403 2389 might_lock(&bo->client->bos_lock); 2404 2390 #endif 2405 - if (bo->ggtt_node && bo->ggtt_node->ggtt) 2406 - might_lock(&bo->ggtt_node->ggtt->lock); 2391 + for_each_tile(tile, xe_bo_device(bo), id) 2392 + if (bo->ggtt_node[id] && bo->ggtt_node[id]->ggtt) 2393 + might_lock(&bo->ggtt_node[id]->ggtt->lock); 2407 2394 drm_gem_object_put(&bo->ttm.base); 2408 2395 } 2409 2396 }
+27 -5
drivers/gpu/drm/xe/xe_bo.h
··· 39 39 #define XE_BO_FLAG_NEEDS_64K BIT(15) 40 40 #define XE_BO_FLAG_NEEDS_2M BIT(16) 41 41 #define XE_BO_FLAG_GGTT_INVALIDATE BIT(17) 42 + #define XE_BO_FLAG_GGTT0 BIT(18) 43 + #define XE_BO_FLAG_GGTT1 BIT(19) 44 + #define XE_BO_FLAG_GGTT2 BIT(20) 45 + #define XE_BO_FLAG_GGTT3 BIT(21) 46 + #define XE_BO_FLAG_GGTT_ALL (XE_BO_FLAG_GGTT0 | \ 47 + XE_BO_FLAG_GGTT1 | \ 48 + XE_BO_FLAG_GGTT2 | \ 49 + XE_BO_FLAG_GGTT3) 50 + 42 51 /* this one is trigger internally only */ 43 52 #define XE_BO_FLAG_INTERNAL_TEST BIT(30) 44 53 #define XE_BO_FLAG_INTERNAL_64K BIT(31) 54 + 55 + #define XE_BO_FLAG_GGTTx(tile) \ 56 + (XE_BO_FLAG_GGTT0 << (tile)->id) 45 57 46 58 #define XE_PTE_SHIFT 12 47 59 #define XE_PAGE_SIZE (1 << XE_PTE_SHIFT) ··· 206 194 } 207 195 208 196 static inline u32 209 - xe_bo_ggtt_addr(struct xe_bo *bo) 197 + __xe_bo_ggtt_addr(struct xe_bo *bo, u8 tile_id) 210 198 { 211 - if (XE_WARN_ON(!bo->ggtt_node)) 199 + struct xe_ggtt_node *ggtt_node = bo->ggtt_node[tile_id]; 200 + 201 + if (XE_WARN_ON(!ggtt_node)) 212 202 return 0; 213 203 214 - XE_WARN_ON(bo->ggtt_node->base.size > bo->size); 215 - XE_WARN_ON(bo->ggtt_node->base.start + bo->ggtt_node->base.size > (1ull << 32)); 216 - return bo->ggtt_node->base.start; 204 + XE_WARN_ON(ggtt_node->base.size > bo->size); 205 + XE_WARN_ON(ggtt_node->base.start + ggtt_node->base.size > (1ull << 32)); 206 + return ggtt_node->base.start; 207 + } 208 + 209 + static inline u32 210 + xe_bo_ggtt_addr(struct xe_bo *bo) 211 + { 212 + xe_assert(xe_bo_device(bo), bo->tile); 213 + 214 + return __xe_bo_ggtt_addr(bo, bo->tile->id); 217 215 } 218 216 219 217 int xe_bo_vmap(struct xe_bo *bo);
+10 -4
drivers/gpu/drm/xe/xe_bo_evict.c
··· 152 152 } 153 153 154 154 if (bo->flags & XE_BO_FLAG_GGTT) { 155 - struct xe_tile *tile = bo->tile; 155 + struct xe_tile *tile; 156 + u8 id; 156 157 157 - mutex_lock(&tile->mem.ggtt->lock); 158 - xe_ggtt_map_bo(tile->mem.ggtt, bo); 159 - mutex_unlock(&tile->mem.ggtt->lock); 158 + for_each_tile(tile, xe, id) { 159 + if (tile != bo->tile && !(bo->flags & XE_BO_FLAG_GGTTx(tile))) 160 + continue; 161 + 162 + mutex_lock(&tile->mem.ggtt->lock); 163 + xe_ggtt_map_bo(tile->mem.ggtt, bo); 164 + mutex_unlock(&tile->mem.ggtt->lock); 165 + } 160 166 } 161 167 162 168 /*
+3 -2
drivers/gpu/drm/xe/xe_bo_types.h
··· 13 13 #include <drm/ttm/ttm_execbuf_util.h> 14 14 #include <drm/ttm/ttm_placement.h> 15 15 16 + #include "xe_device_types.h" 16 17 #include "xe_ggtt_types.h" 17 18 18 19 struct xe_device; ··· 40 39 struct ttm_place placements[XE_BO_MAX_PLACEMENTS]; 41 40 /** @placement: current placement for this BO */ 42 41 struct ttm_placement placement; 43 - /** @ggtt_node: GGTT node if this BO is mapped in the GGTT */ 44 - struct xe_ggtt_node *ggtt_node; 42 + /** @ggtt_node: Array of GGTT nodes if this BO is mapped in the GGTTs */ 43 + struct xe_ggtt_node *ggtt_node[XE_MAX_TILES_PER_DEVICE]; 45 44 /** @vmap: iosys map of this buffer */ 46 45 struct iosys_map vmap; 47 46 /** @ttm_kmap: TTM bo kmap object for internal use only. Keep off. */
+19 -16
drivers/gpu/drm/xe/xe_ggtt.c
··· 598 598 u64 start; 599 599 u64 offset, pte; 600 600 601 - if (XE_WARN_ON(!bo->ggtt_node)) 601 + if (XE_WARN_ON(!bo->ggtt_node[ggtt->tile->id])) 602 602 return; 603 603 604 - start = bo->ggtt_node->base.start; 604 + start = bo->ggtt_node[ggtt->tile->id]->base.start; 605 605 606 606 for (offset = 0; offset < bo->size; offset += XE_PAGE_SIZE) { 607 607 pte = ggtt->pt_ops->pte_encode_bo(bo, offset, pat_index); ··· 612 612 static int __xe_ggtt_insert_bo_at(struct xe_ggtt *ggtt, struct xe_bo *bo, 613 613 u64 start, u64 end) 614 614 { 615 - int err; 616 615 u64 alignment = bo->min_align > 0 ? bo->min_align : XE_PAGE_SIZE; 616 + u8 tile_id = ggtt->tile->id; 617 + int err; 617 618 618 619 if (xe_bo_is_vram(bo) && ggtt->flags & XE_GGTT_FLAGS_64K) 619 620 alignment = SZ_64K; 620 621 621 - if (XE_WARN_ON(bo->ggtt_node)) { 622 + if (XE_WARN_ON(bo->ggtt_node[tile_id])) { 622 623 /* Someone's already inserted this BO in the GGTT */ 623 - xe_tile_assert(ggtt->tile, bo->ggtt_node->base.size == bo->size); 624 + xe_tile_assert(ggtt->tile, bo->ggtt_node[tile_id]->base.size == bo->size); 624 625 return 0; 625 626 } 626 627 ··· 631 630 632 631 xe_pm_runtime_get_noresume(tile_to_xe(ggtt->tile)); 633 632 634 - bo->ggtt_node = xe_ggtt_node_init(ggtt); 635 - if (IS_ERR(bo->ggtt_node)) { 636 - err = PTR_ERR(bo->ggtt_node); 637 - bo->ggtt_node = NULL; 633 + bo->ggtt_node[tile_id] = xe_ggtt_node_init(ggtt); 634 + if (IS_ERR(bo->ggtt_node[tile_id])) { 635 + err = PTR_ERR(bo->ggtt_node[tile_id]); 636 + bo->ggtt_node[tile_id] = NULL; 638 637 goto out; 639 638 } 640 639 641 640 mutex_lock(&ggtt->lock); 642 - err = drm_mm_insert_node_in_range(&ggtt->mm, &bo->ggtt_node->base, bo->size, 643 - alignment, 0, start, end, 0); 641 + err = drm_mm_insert_node_in_range(&ggtt->mm, &bo->ggtt_node[tile_id]->base, 642 + bo->size, alignment, 0, start, end, 0); 644 643 if (err) { 645 - xe_ggtt_node_fini(bo->ggtt_node); 646 - bo->ggtt_node = NULL; 644 + xe_ggtt_node_fini(bo->ggtt_node[tile_id]); 645 + bo->ggtt_node[tile_id] = NULL; 647 646 } else { 648 647 xe_ggtt_map_bo(ggtt, bo); 649 648 } ··· 692 691 */ 693 692 void xe_ggtt_remove_bo(struct xe_ggtt *ggtt, struct xe_bo *bo) 694 693 { 695 - if (XE_WARN_ON(!bo->ggtt_node)) 694 + u8 tile_id = ggtt->tile->id; 695 + 696 + if (XE_WARN_ON(!bo->ggtt_node[tile_id])) 696 697 return; 697 698 698 699 /* This BO is not currently in the GGTT */ 699 - xe_tile_assert(ggtt->tile, bo->ggtt_node->base.size == bo->size); 700 + xe_tile_assert(ggtt->tile, bo->ggtt_node[tile_id]->base.size == bo->size); 700 701 701 - xe_ggtt_node_remove(bo->ggtt_node, 702 + xe_ggtt_node_remove(bo->ggtt_node[tile_id], 702 703 bo->flags & XE_BO_FLAG_GGTT_INVALIDATE); 703 704 } 704 705