[PATCH v2 2/4] drm/xe/ttm: Add PF-mem VRAM placement types for TTM
Piórkowski, Piotr <[email protected]>
| Newsgroups | org.freedesktop.lists.intel-xe |
|---|---|
| Message-ID | <[email protected]> |
From: Piotr Piórkowski <[email protected]> PF-mem regions are dedicated to kernel-only pinned BOs. They are not exposed to userspace and cannot be exported through dma-buf. Add dedicated TTM placement types for PF-mem VRAM regions and update the BO, resource iterator, power-management, and PCI removal paths to recognize them. Since PF-mem cannot contain user memory, its placement types are intentionally excluded from user BO eviction. v2: - Modify commit message. - Add comments explaining why PF-mem is excluded from user BO eviction (Sashiko). - Resolve xe_ttm_vram_mgr_alloc_sgt() physical address via xe_map_resource_to_region() instead of the tile's VRAM region (Sashiko). Assisted-by: Claude:claude-5-sonnet Signed-off-by: Piotr Piórkowski <[email protected]> --- drivers/gpu/drm/xe/xe_bo.c | 16 ++++++++++++---- drivers/gpu/drm/xe/xe_bo.h | 17 +++++++++++++++++ drivers/gpu/drm/xe/xe_bo_evict.c | 7 +++++-- drivers/gpu/drm/xe/xe_pm.c | 4 ++-- drivers/gpu/drm/xe/xe_res_cursor.h | 9 ++++++++- drivers/gpu/drm/xe/xe_ttm_vram_mgr.c | 9 ++++----- 6 files changed, 48 insertions(+), 14 deletions(-) diff --git a/drivers/gpu/drm/xe/xe_bo.c b/drivers/gpu/drm/xe/xe_bo.c index dde309821237..7b1a82e18faa 100644 --- a/drivers/gpu/drm/xe/xe_bo.c +++ b/drivers/gpu/drm/xe/xe_bo.c @@ -46,6 +46,8 @@ const char *const xe_mem_type_to_name[TTM_NUM_MEM_TYPES] = { [XE_PL_TT] = "gtt", [XE_PL_VRAM0] = "vram0", [XE_PL_VRAM1] = "vram1", + [XE_PL_VRAM0_PFMEM] = "vram0_pfmem", + [XE_PL_VRAM1_PFMEM] = "vram1_pfmem", [XE_PL_STOLEN] = "stolen" }; @@ -166,11 +168,12 @@ static bool xe_bo_is_user(struct xe_bo *bo) static struct xe_migrate * mem_type_to_migrate(struct xe_device *xe, u32 mem_type) { - struct xe_tile *tile; + u8 tile_id; xe_assert(xe, mem_type == XE_PL_STOLEN || mem_type_is_vram(mem_type)); - tile = &xe->tiles[mem_type == XE_PL_STOLEN ? 0 : (mem_type - XE_PL_VRAM0)]; - return tile->migrate; + tile_id = mem_type == XE_PL_STOLEN ? 0 : xe_vram_pl_to_tile_id(xe, mem_type); + + return xe->tiles[tile_id].migrate; } static void try_add_system(struct xe_device *xe, struct xe_bo *bo, @@ -360,6 +363,8 @@ static void xe_evict_flags(struct ttm_buffer_object *tbo, switch (tbo->resource->mem_type) { case XE_PL_VRAM0: case XE_PL_VRAM1: + case XE_PL_VRAM0_PFMEM: + case XE_PL_VRAM1_PFMEM: case XE_PL_STOLEN: *placement = tt_placement; break; @@ -639,7 +644,10 @@ static int xe_ttm_io_mem_reserve(struct ttm_device *bdev, case XE_PL_TT: return 0; case XE_PL_VRAM0: - case XE_PL_VRAM1: { + case XE_PL_VRAM1: + case XE_PL_VRAM0_PFMEM: + case XE_PL_VRAM1_PFMEM: + { struct xe_vram_region *vram = xe_map_resource_to_region(mem); if (!xe_ttm_resource_visible(xe, mem)) diff --git a/drivers/gpu/drm/xe/xe_bo.h b/drivers/gpu/drm/xe/xe_bo.h index e8081af5bfc1..c698f70a3b0c 100644 --- a/drivers/gpu/drm/xe/xe_bo.h +++ b/drivers/gpu/drm/xe/xe_bo.h @@ -83,8 +83,13 @@ #define XE_PL_TT TTM_PL_TT #define XE_PL_VRAM0 TTM_PL_VRAM #define XE_PL_VRAM1 (XE_PL_VRAM0 + 1) +#define XE_PL_VRAM0_PFMEM (XE_PL_VRAM1 + 1) +#define XE_PL_VRAM1_PFMEM (XE_PL_VRAM0_PFMEM + 1) #define XE_PL_STOLEN (TTM_NUM_MEM_TYPES - 1) +#define xe_for_each_vram_pl(i) \ + for (i = XE_PL_VRAM0; i <= XE_PL_VRAM1_PFMEM; i++) + #define XE_BO_PROPS_INVALID (-1) #define XE_PCI_BARRIER_MMAP_OFFSET (0x50 << XE_PTE_SHIFT) @@ -614,4 +619,16 @@ static inline bool xe_bo_is_mem_type(struct xe_bo *bo, u32 mem_type) xe_bo_assert_held(bo); return bo->ttm.resource->mem_type == mem_type; } + +static inline u8 xe_vram_pl_to_tile_id(struct xe_device *xe, u32 mem_type) +{ + xe_assert(xe, mem_type_is_vram(mem_type)); + + if (mem_type >= XE_PL_VRAM0 && mem_type <= XE_PL_VRAM1) + return mem_type - XE_PL_VRAM0; + + xe_assert(xe, mem_type >= XE_PL_VRAM0_PFMEM && mem_type <= XE_PL_VRAM1_PFMEM); + return mem_type - XE_PL_VRAM0_PFMEM; +} + #endif diff --git a/drivers/gpu/drm/xe/xe_bo_evict.c b/drivers/gpu/drm/xe/xe_bo_evict.c index 7661fca7f278..a25ec6c750da 100644 --- a/drivers/gpu/drm/xe/xe_bo_evict.c +++ b/drivers/gpu/drm/xe/xe_bo_evict.c @@ -118,7 +118,10 @@ int xe_bo_evict_all_user(struct xe_device *xe) u32 mem_type; int ret; - /* User memory */ + /* + * Iterate over placements that can contain user memory. PF-mem placements + * are excluded since they are reserved for pinned kernel BOs. + */ for (mem_type = XE_PL_TT; mem_type <= XE_PL_VRAM1; ++mem_type) { struct ttm_resource_manager *man = ttm_manager_type(bdev, mem_type); @@ -303,7 +306,7 @@ void xe_bo_pci_dev_remove_all(struct xe_device *xe) * Move pagemap bos and exported dma-buf to system, and * purge everything else. */ - for (mem_type = XE_PL_VRAM1; mem_type >= XE_PL_TT; --mem_type) { + for (mem_type = XE_PL_VRAM1_PFMEM; mem_type >= XE_PL_TT; --mem_type) { struct ttm_resource_manager *man = ttm_manager_type(&xe->ttm, mem_type); diff --git a/drivers/gpu/drm/xe/xe_pm.c b/drivers/gpu/drm/xe/xe_pm.c index f517bf453b54..a4fe6a89d9dd 100644 --- a/drivers/gpu/drm/xe/xe_pm.c +++ b/drivers/gpu/drm/xe/xe_pm.c @@ -975,7 +975,7 @@ int xe_pm_set_vram_threshold(struct xe_device *xe, u32 threshold) u32 vram_total_mb = 0; int i; - for (i = XE_PL_VRAM0; i <= XE_PL_VRAM1; ++i) { + xe_for_each_vram_pl(i) { man = ttm_manager_type(&xe->ttm, i); if (man) vram_total_mb += DIV_ROUND_UP_ULL(man->size, 1024 * 1024); @@ -1012,7 +1012,7 @@ void xe_pm_d3cold_allowed_toggle(struct xe_device *xe) return; } - for (i = XE_PL_VRAM0; i <= XE_PL_VRAM1; ++i) { + xe_for_each_vram_pl(i) { man = ttm_manager_type(&xe->ttm, i); if (man) { vram_used = ttm_resource_manager_usage(man); diff --git a/drivers/gpu/drm/xe/xe_res_cursor.h b/drivers/gpu/drm/xe/xe_res_cursor.h index 0522caafd89d..4603a3356e53 100644 --- a/drivers/gpu/drm/xe/xe_res_cursor.h +++ b/drivers/gpu/drm/xe/xe_res_cursor.h @@ -111,7 +111,9 @@ static inline void xe_res_first(struct ttm_resource *res, break; } case XE_PL_VRAM0: - case XE_PL_VRAM1: { + case XE_PL_VRAM1: + case XE_PL_VRAM0_PFMEM: + case XE_PL_VRAM1_PFMEM: { struct gpu_buddy_block *block; struct list_head *head, *next; struct gpu_buddy *mm = xe_res_get_buddy(res); @@ -303,6 +305,8 @@ static inline void xe_res_next(struct xe_res_cursor *cur, u64 size) break; case XE_PL_VRAM0: case XE_PL_VRAM1: + case XE_PL_VRAM0_PFMEM: + case XE_PL_VRAM1_PFMEM: { start = size - cur->size; block = cur->node; @@ -322,6 +326,7 @@ static inline void xe_res_next(struct xe_res_cursor *cur, u64 size) cur->remaining); cur->node = block; break; + } default: return; } @@ -358,6 +363,8 @@ static inline bool xe_res_is_vram(const struct xe_res_cursor *cur) case XE_PL_STOLEN: case XE_PL_VRAM0: case XE_PL_VRAM1: + case XE_PL_VRAM0_PFMEM: + case XE_PL_VRAM1_PFMEM: return true; default: break; diff --git a/drivers/gpu/drm/xe/xe_ttm_vram_mgr.c b/drivers/gpu/drm/xe/xe_ttm_vram_mgr.c index 05911904c1f9..bb28b493fd93 100644 --- a/drivers/gpu/drm/xe/xe_ttm_vram_mgr.c +++ b/drivers/gpu/drm/xe/xe_ttm_vram_mgr.c @@ -18,6 +18,7 @@ #include "xe_pm.h" #include "xe_res_cursor.h" #include "xe_ttm_vram_mgr.h" +#include "xe_vram.h" #include "xe_vram_types.h" static inline struct gpu_buddy_block * @@ -336,7 +337,6 @@ int __xe_ttm_vram_mgr_init(struct xe_device *xe, struct xe_ttm_vram_mgr *mgr, { struct ttm_resource_manager *man = &mgr->manager; struct dmem_cgroup_region *cg; - const char *name; int err; man->func = &xe_ttm_vram_mgr_func; @@ -365,8 +365,7 @@ int __xe_ttm_vram_mgr_init(struct xe_device *xe, struct xe_ttm_vram_mgr *mgr, if (err) return err; - name = mem_type == XE_PL_VRAM0 ? "vram0" : "vram1"; - cg = drmm_cgroup_register_region(&xe->drm, name, + cg = drmm_cgroup_register_region(&xe->drm, xe_mem_type_to_name[mem_type], &(struct dmem_cgroup_init){ .size = size, .ops = &xe_ttm_vram_mgr_dmem_ops, @@ -405,7 +404,7 @@ int xe_ttm_vram_mgr_alloc_sgt(struct xe_device *xe, enum dma_data_direction dir, struct sg_table **sgt) { - struct xe_tile *tile = &xe->tiles[res->mem_type - XE_PL_VRAM0]; + struct xe_vram_region *vram = xe_map_resource_to_region(res); struct xe_ttm_vram_mgr_resource *vres = to_xe_ttm_vram_mgr_resource(res); struct xe_res_cursor cursor; struct scatterlist *sg; @@ -443,7 +442,7 @@ int xe_ttm_vram_mgr_alloc_sgt(struct xe_device *xe, */ xe_res_first(res, offset, length, &cursor); for_each_sgtable_sg((*sgt), sg, i) { - phys_addr_t phys = cursor.start + xe_vram_region_io_start(tile->mem.vram); + phys_addr_t phys = cursor.start + xe_vram_region_io_start(vram); size_t size = min_t(u64, cursor.size, SZ_2G); dma_addr_t addr; -- 2.34.1