Cleaning up code related to VRAM regions and its initialization - part 2
Subsystems (3)
v7 cover Cleaning up code related to VRAM regions and its initialization - part 2
From: Piotr Piórkowski <[email protected]>
As a follow-up to the earlier VRAM region cleanups, this patch series focuses on further improving the flexibility and clarity of the Xe driver's VRAM management.
This series focuses on preparing the VRAM region handling code for future platforms, where a more dynamic representation of device and tile VRAM regions will be required. Static allocation of these structures is replaced with dynamic allocation to increase flexibility and improve maintainability. Additionally, the initialization logic for device-wide and tile-local VRAM regions is unified, replacing the previously separate code paths. This simplification improves code clarity and facilitates future extensions involving additional VRAM region types.
v2:
- fix doc comments in struct xe_vram_region
- remove unnecessary includes (Jani)
v3:
- move code from xe_vram_init_regions_managers to xe_tile_init_noalloc (Matthew)
- replace ioremap_wc to devm_ioremap_wc for mapping VRAM BAR (Matthew)
- Replace the tile id parameter with vram region in the xe_pf_begin function.
v4:
- add new patch "Use devm_ioremap_wc for VRAM mapping and drop manual unmap" (Matthew)
- add new patch "Move struct xe_vram_region to a dedicated header" (Jani)
- fix null pointer dereference in xe_assert when VRAM region for tile hasn't been initialized (Michal)
v5:
- Fix build if CONFIG_DRM_XE_DEVMEM_MIRROR is enabled
v6:
- Fix build if CONFIG_DRM_XE_DISPLAY is enabled
v7:
- rebase after new changes related to SVM
Piotr Piórkowski (4):
drm/xe: Use devm_ioremap_wc for VRAM mapping and drop manual unmap drm/xe: Use dynamic allocation for tile and device VRAM region
structures
drm/xe: Move struct xe_vram_region to a dedicated header drm/xe: Unify the initialization of VRAM regions
drivers/gpu/drm/xe/display/xe_fb_pin.c | 3 +- drivers/gpu/drm/xe/display/xe_plane_initial.c | 3 +- drivers/gpu/drm/xe/xe_assert.h | 4 +- drivers/gpu/drm/xe/xe_bo.c | 1 + drivers/gpu/drm/xe/xe_bo_types.h | 1 + drivers/gpu/drm/xe/xe_device.c | 20 +++ drivers/gpu/drm/xe/xe_device_types.h | 62 +------ drivers/gpu/drm/xe/xe_gt_pagefault.c | 13 +- drivers/gpu/drm/xe/xe_gt_sriov_pf_config.c | 3 +- drivers/gpu/drm/xe/xe_migrate.c | 19 +- drivers/gpu/drm/xe/xe_pci.c | 6 + drivers/gpu/drm/xe/xe_query.c | 5 +- drivers/gpu/drm/xe/xe_svm.c | 27 +-- drivers/gpu/drm/xe/xe_tile.c | 58 ++++--- drivers/gpu/drm/xe/xe_tile.h | 13 +- drivers/gpu/drm/xe/xe_ttm_stolen_mgr.c | 7 +- drivers/gpu/drm/xe/xe_ttm_vram_mgr.c | 19 +- drivers/gpu/drm/xe/xe_ttm_vram_mgr.h | 3 +- drivers/gpu/drm/xe/xe_vram.c | 163 +++++++++++------- drivers/gpu/drm/xe/xe_vram.h | 5 + drivers/gpu/drm/xe/xe_vram_types.h | 82 +++++++++ 21 files changed, 318 insertions(+), 199 deletions(-) create mode 100644 drivers/gpu/drm/xe/xe_vram_types.h
Signature · 1 line
2.34.1
PATCH v7 1/4 drm/xe: Use devm_ioremap_wc for VRAM mapping and drop manual unmap
From: Piotr Piórkowski <[email protected]>
Let's replace the manual call to ioremap_wc function with devm_ioremap_wc function, ensuring that VRAM mappings are automatically released when the driver is detached.
Since devm_ioremap_wc registers the mapping with the device's managed resources, the explicit iounmap call in vram_fini is no longer needed, so let's remove it.
--- drivers/gpu/drm/xe/xe_vram.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-)
drivers/gpu/drm/xe/xe_vram.c +2 -4
@@ -156,7 +156,8 @@ static int determine_lmem_bar_size(struct xe_device *xe) xe->mem.vram.dpa_base =0 ;/* set up a map to the total memory area. */ - xe->mem.vram.mapping =ioremap_wc (xe->mem.vram.io_start, xe->mem.vram.io_size); + xe->mem.vram.mapping =devm_ioremap_wc (&pdev->dev, xe->mem.vram.io_start, + xe->mem.vram.io_size);return 0 ; }
@@ -278,9 +279,6 @@ static void vram_fini(void *arg)struct xe_tile *tile;int id; -if (xe->mem.vram.mapping) -iounmap (xe->mem.vram.mapping); - xe->mem.vram.mapping =NULL ;for_each_tile (tile, xe, id)
Signature · 1 line
2.34.1
PATCH v7 2/4 drm/xe: Use dynamic allocation for tile and device VRAM region structures
In reply to Piórkowski, PiotrFrom: Piotr Piórkowski <[email protected]>
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.
--- drivers/gpu/drm/xe/display/xe_fb_pin.c | 2 +- drivers/gpu/drm/xe/display/xe_plane_initial.c | 2 +- drivers/gpu/drm/xe/xe_assert.h | 4 +- drivers/gpu/drm/xe/xe_device.c | 19 ++++++ drivers/gpu/drm/xe/xe_device_types.h | 6 +- drivers/gpu/drm/xe/xe_gt_sriov_pf_config.c | 2 +- drivers/gpu/drm/xe/xe_migrate.c | 18 +++--- drivers/gpu/drm/xe/xe_pci.c | 6 ++ drivers/gpu/drm/xe/xe_query.c | 2 +- drivers/gpu/drm/xe/xe_svm.c | 24 ++----- drivers/gpu/drm/xe/xe_tile.c | 33 +++++++++- drivers/gpu/drm/xe/xe_tile.h | 4 +- drivers/gpu/drm/xe/xe_ttm_stolen_mgr.c | 6 +- drivers/gpu/drm/xe/xe_ttm_vram_mgr.c | 4 +- drivers/gpu/drm/xe/xe_vram.c | 64 ++++++++++--------- 15 files changed, 124 insertions(+), 72 deletions(-)
drivers/gpu/drm/xe/display/xe_fb_pin.c +1 -1
@@ -297,7 +297,7 @@ static struct i915_vma *__xe_pin_fb_vma(const struct intel_framebuffer *fb,* accessible. This is important on small-bar systems where * only some subset of VRAM is CPU accessible. */ -if (tile->mem.vram.io_size < tile->mem.vram.usable_size) { +if (tile->mem.vram->io_size < tile->mem.vram->usable_size) { ret = -EINVAL ; goto err; }
drivers/gpu/drm/xe/display/xe_plane_initial.c +1 -1
@@ -103,7 +103,7 @@ initial_plane_bo(struct xe_device *xe,* We don't currently expect this to ever be placed in the * stolen portion. */ -if (phys_base >= tile0->mem.vram.usable_size) { +if (phys_base >= tile0->mem.vram->usable_size) {drm_err (&xe->drm,"Initial plane programming using invalid range, phys_base=%pa\n" , &phys_base);
drivers/gpu/drm/xe/xe_assert.h +3 -1
@@ -145,7 +145,9 @@const struct xe_tile *__tile = (tile); \ char __buf[10] __maybe_unused; \xe_assert_msg (tile_to_xe (__tile), condition,"tile: %u VRAM %s\n" msg, \ - __tile->id, ({string_get_size (__tile->mem.vram.actual_physical_size,1 , \ + __tile->id, ({string_get_size (__tile->mem.vram ? \ + __tile->mem.vram->actual_physical_size : \ +0 ,1 , \ STRING_UNITS_2, __buf, sizeof(__buf)); __buf; }), ## arg); \ })
drivers/gpu/drm/xe/xe_device.c +19 -0
@@ -685,6 +685,21 @@ static void sriov_update_device_info(struct xe_device *xe) } } +static int xe_device_vram_alloc (struct xe_device *xe) +{ +struct xe_vram_region *vram; + +if (!IS_DGFX (xe)) +return 0 ; + + vram =drmm_kzalloc (&xe->drm,sizeof (*vram),GFP_KERNEL ); +if (!vram) +return -ENOMEM ; + + xe->mem.vram = vram; +return 0 ; +} +/** * xe_device_probe_early: Device early probe * @xe: xe device instance
@@ -729,6 +744,10 @@ int xe_device_probe_early(struct xe_device *xe) xe->wedged.mode = xe_modparam.wedged_mode; + err =xe_device_vram_alloc (xe); +if (err) +return err; +return 0 ; }ALLOW_ERROR_INJECTION (xe_device_probe_early,ERRNO );/* See xe_pci_probe() */
drivers/gpu/drm/xe/xe_device_types.h +4 -2
@@ -74,6 +74,8 @@ struct xe_pxp;* device, such as HBM memory or CXL extension memory. */ struct xe_vram_region { +/** @tile: Backpointer to tile */ +struct xe_tile *tile;/** @io_start: IO start address of this VRAM instance */ resource_size_t io_start;/**
@@ -213,7 +215,7 @@ struct xe_tile {* Although VRAM is associated with a specific tile, it can * still be accessed by all tiles' GTs. */ -struct xe_vram_region vram; +struct xe_vram_region *vram;/** @mem.ggtt: Global graphics translation table */ struct xe_ggtt *ggtt;
@@ -394,7 +396,7 @@ struct xe_device {/** @mem: memory info for device */ struct {/** @mem.vram: VRAM info for device */ -struct xe_vram_region vram; +struct xe_vram_region *vram;/** @mem.sys_mgr: system TTM manager */ struct ttm_resource_manager sys_mgr;/** @mem.sys_mgr: system memory shrinker. */
drivers/gpu/drm/xe/xe_gt_sriov_pf_config.c +1 -1
@@ -1574,7 +1574,7 @@ static u64 pf_query_free_lmem(struct xe_gt *gt) {struct xe_tile *tile = gt->tile; -return xe_ttm_vram_get_avail (&tile->mem.vram.ttm.manager); +return xe_ttm_vram_get_avail (&tile->mem.vram->ttm.manager); }static u64 pf_query_max_lmem (struct xe_gt *gt)
drivers/gpu/drm/xe/xe_migrate.c +9 -9
@@ -130,9 +130,9 @@ static u64 xe_migrate_vram_ofs(struct xe_device *xe, u64 addr, bool is_comp_pte)u64 identity_offset =IDENTITY_OFFSET ;if (GRAPHICS_VER (xe) >=20 && is_comp_pte) - identity_offset +=DIV_ROUND_UP_ULL (xe->mem.vram.actual_physical_size,SZ_1G ); + identity_offset +=DIV_ROUND_UP_ULL (xe->mem.vram->actual_physical_size,SZ_1G ); - addr -= xe->mem.vram.dpa_base; + addr -= xe->mem.vram->dpa_base;return addr + (identity_offset <<xe_pt_shift (2 )); }
@@ -142,22 +142,22 @@ static void xe_migrate_program_identity(struct xe_device *xe, struct xe_vm *vm,u64 pos, ofs, flags;u64 entry;/* XXX: Unclear if this should be usable_size? */ -u64 vram_limit = xe->mem.vram.actual_physical_size + - xe->mem.vram.dpa_base; +u64 vram_limit = xe->mem.vram->actual_physical_size + + xe->mem.vram->dpa_base;u32 level =2 ; ofs = map_ofs +XE_PAGE_SIZE * level + vram_offset *8 ; flags = vm->pt_ops->pte_encode_addr (xe,0 , pat_index, level, true,0 ); -xe_assert (xe,IS_ALIGNED (xe->mem.vram.usable_size,SZ_2M )); +xe_assert (xe,IS_ALIGNED (xe->mem.vram->usable_size,SZ_2M ));/* * Use 1GB pages when possible, last chunk always use 2M * pages as mixing reserved memory (stolen, WOCPM) with a single * mapping is not allowed on certain platforms. */ -for (pos = xe->mem.vram.dpa_base; pos < vram_limit; +for (pos = xe->mem.vram->dpa_base; pos < vram_limit; pos +=SZ_1G , ofs +=8 ) {if (pos +SZ_1G >= vram_limit) { entry = vm->pt_ops->pde_encode_bo(bo, pt_2m_ofs,
@@ -310,7 +310,7 @@ static int xe_migrate_prepare_vm(struct xe_tile *tile, struct xe_migrate *m,xe_migrate_program_identity (xe, vm, bo, map_ofs,IDENTITY_OFFSET , pat_index, pt30_ofs); -xe_assert (xe, xe->mem.vram.actual_physical_size <= +xe_assert (xe, xe->mem.vram->actual_physical_size <= (MAX_NUM_PTE -IDENTITY_OFFSET ) *SZ_1G );/*
@@ -320,10 +320,10 @@ static int xe_migrate_prepare_vm(struct xe_tile *tile, struct xe_migrate *m,if (GRAPHICS_VER (xe) >=20 &&xe_device_has_flat_ccs (xe)) {u16 comp_pat_index = xe->pat.idx[XE_CACHE_NONE_COMPRESSION ];u64 vram_offset =IDENTITY_OFFSET + -DIV_ROUND_UP_ULL (xe->mem.vram.actual_physical_size,SZ_1G ); +DIV_ROUND_UP_ULL (xe->mem.vram->actual_physical_size,SZ_1G );u64 pt31_ofs = bo->size -XE_PAGE_SIZE ; -xe_assert (xe, xe->mem.vram.actual_physical_size <= (MAX_NUM_PTE - +xe_assert (xe, xe->mem.vram->actual_physical_size <= (MAX_NUM_PTE -IDENTITY_OFFSET -IDENTITY_OFFSET /2 ) *SZ_1G );xe_migrate_program_identity (xe, vm, bo, map_ofs, vram_offset, comp_pat_index, pt31_ofs);
drivers/gpu/drm/xe/xe_pci.c +6 -0
@@ -714,12 +714,18 @@ static int xe_info_init(struct xe_device *xe,* All of these together determine the overall GT count. */ for_each_tile (tile, xe, id) { +int err; + gt = tile->primary_gt; gt->info.id = xe->info.gt_count++; gt->info.type =XE_GT_TYPE_MAIN ; gt->info.has_indirect_ring_state = graphics_desc->has_indirect_ring_state; gt->info.engine_mask = graphics_desc->hw_engine_mask; + err =xe_tile_alloc_vram (tile); +if (err) +return err; +if (MEDIA_VER (xe) <13 && media_desc) gt->info.engine_mask |= media_desc->hw_engine_mask;
drivers/gpu/drm/xe/xe_query.c +1 -1
@@ -337,7 +337,7 @@ static int query_config(struct xe_device *xe, struct drm_xe_device_query *query) config->num_params = num_params; config->info[DRM_XE_QUERY_CONFIG_REV_AND_DEVICE_ID ] = xe->info.devid | (xe->info.revid <<16 ); -if (xe_device_get_root_tile (xe)->mem.vram.usable_size) +if (xe->mem.vram) config->info[DRM_XE_QUERY_CONFIG_FLAGS ] |=DRM_XE_QUERY_CONFIG_FLAG_HAS_VRAM ;if (xe->info.has_usm &&IS_ENABLED (CONFIG_DRM_XE_GPUSVM ))
drivers/gpu/drm/xe/xe_svm.c +7 -17
@@ -306,16 +306,11 @@ static struct xe_vram_region *page_to_vr(struct page *page) return container_of(page_pgmap(page), struct xe_vram_region, pagemap); } -static struct xe_tile *vr_to_tile (struct xe_vram_region *vr) -{ - return container_of(vr, struct xe_tile, mem.vram); -} -static u64 xe_vram_region_page_to_dpa (struct xe_vram_region *vr,struct page *page) {u64 dpa; -struct xe_tile *tile =vr_to_tile (vr); +struct xe_tile *tile = vr->tile;u64 pfn =page_to_pfn (page);u64 offset;
@@ -370,7 +365,7 @@ static int xe_svm_copy(struct page **pages, dma_addr_t *dma_addr,if (!vr && spage) { vr =page_to_vr (spage); - tile =vr_to_tile (vr); + tile = vr->tile; }XE_WARN_ON (spage &&page_to_vr (spage) != vr);
@@ -508,7 +503,7 @@ static u64 block_offset_to_pfn(struct xe_vram_region *vr, u64 offset)static struct drm_buddy *tile_to_buddy (struct xe_tile *tile) { -return &tile->mem.vram.ttm.mm; +return &tile->mem.vram->ttm.mm; } 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_allocatilist_for_each_entry (block, blocks, link) {struct xe_vram_region *vr = block->private; -struct xe_tile *tile =vr_to_tile (vr); +struct xe_tile *tile = vr->tile;struct drm_buddy *buddy =tile_to_buddy (tile);u64 block_pfn =block_offset_to_pfn (vr,drm_buddy_block_offset (block));int i;
@@ -683,20 +678,15 @@ u64 xe_svm_find_vma_start(struct xe_vm *vm, u64 start, u64 end, struct xe_vma *v }#if IS_ENABLED (CONFIG_DRM_XE_PAGEMAP ) -static struct xe_vram_region *tile_to_vr (struct xe_tile *tile) -{ -return &tile->mem.vram; -} -static int xe_drm_pagemap_populate_mm (struct drm_pagemap *dpagemap,unsigned long start,unsigned long end,struct mm_struct *mm,unsigned long timeslice_ms) { -struct xe_tile *tile =container_of (dpagemap,typeof (*tile), mem.vram.dpagemap); +struct xe_vram_region *vr =container_of (dpagemap,typeof (*vr), dpagemap); +struct xe_tile *tile = vr->tile;struct xe_device *xe =tile_to_xe (tile);struct device *dev = xe->drm.dev; -struct xe_vram_region *vr =tile_to_vr (tile);struct drm_buddy_block *block;struct list_head *blocks;struct xe_bo *bo;
@@ -722,7 +712,7 @@ static int xe_drm_pagemap_populate_mm(struct drm_pagemap *dpagemap,drm_pagemap_devmem_init (&bo->devmem_allocation, dev, mm, &dpagemap_devmem_ops, - &tile->mem.vram.dpagemap, + &tile->mem.vram->dpagemap, end - start); blocks = &to_xe_ttm_vram_mgr_resource (bo->ttm.resource)->blocks;
drivers/gpu/drm/xe/xe_tile.c +30 -3
@@ -95,6 +95,33 @@ static int xe_tile_alloc(struct xe_tile *tile)return 0 ; } +/** +* xe_tile_alloc_vram - Perform per-tile VRAM structs allocation +* @tile: Tile to perform allocations for +* +* Allocates VRAM per-tile data structures using DRM-managed allocations. +* Does not touch the hardware. +* +* Returns -ENOMEM if allocations fail, otherwise 0. +*/ +int xe_tile_alloc_vram (struct xe_tile *tile) +{ +struct xe_device *xe =tile_to_xe (tile); +struct xe_vram_region *vram; + +if (!IS_DGFX (xe)) +return 0 ; + + vram =drmm_kzalloc (&xe->drm,sizeof (*vram),GFP_KERNEL ); +if (!vram) +return -ENOMEM ; + + vram->tile = tile; + tile->mem.vram = vram; + +return 0 ; +} +/** * xe_tile_init_early - Initialize the tile and primary GT * @tile: Tile to initialize
@@ -132,8 +159,8 @@ static int tile_ttm_mgr_init(struct xe_tile *tile)struct xe_device *xe =tile_to_xe (tile);int err; -if (tile->mem.vram.usable_size) { - err =xe_ttm_vram_mgr_init (tile, &tile->mem.vram.ttm); +if (tile->mem.vram->usable_size) { + err =xe_ttm_vram_mgr_init (tile, &tile->mem.vram->ttm);if (err)return err; xe->info.mem_region_mask |=BIT (tile->id) <<1 ;
@@ -168,7 +195,7 @@ int xe_tile_init_noalloc(struct xe_tile *tile)xe_wa_apply_tile_workarounds (tile);if (xe->info.has_usm &&IS_DGFX (xe)) -xe_devm_add (tile, &tile->mem.vram); +xe_devm_add (tile, tile->mem.vram);return xe_tile_sysfs_init (tile); }
drivers/gpu/drm/xe/xe_tile.h +3 -1
@@ -14,12 +14,14 @@ int xe_tile_init_early(struct xe_tile *tile, struct xe_device *xe, u8 id);int xe_tile_init_noalloc (struct xe_tile *tile);int xe_tile_init (struct xe_tile *tile); +int xe_tile_alloc_vram (struct xe_tile *tile); +void xe_tile_migrate_wait (struct xe_tile *tile);#if IS_ENABLED (CONFIG_DRM_XE_PAGEMAP )static inline struct drm_pagemap *xe_tile_local_pagemap (struct xe_tile *tile) { -return &tile->mem.vram.dpagemap; +return &tile->mem.vram->dpagemap; }#else static inline struct drm_pagemap *xe_tile_local_pagemap (struct xe_tile *tile)
drivers/gpu/drm/xe/xe_ttm_stolen_mgr.c +3 -3
@@ -89,8 +89,8 @@ static s64 detect_bar2_dgfx(struct xe_device *xe, struct xe_ttm_stolen_mgr *mgr)u64 tile_offset;u64 tile_size; - tile_offset = tile->mem.vram.io_start - xe->mem.vram.io_start; - tile_size = tile->mem.vram.actual_physical_size; + tile_offset = tile->mem.vram->io_start - xe->mem.vram->io_start; + tile_size = tile->mem.vram->actual_physical_size;/* Use DSM base address instead for stolen memory */ mgr->stolen_base = (xe_mmio_read64_2x32 (mmio,DSMBASE ) &BDSM_MASK ) - tile_offset;
@@ -107,7 +107,7 @@ static s64 detect_bar2_dgfx(struct xe_device *xe, struct xe_ttm_stolen_mgr *mgr)/* Verify usage fits in the actual resource available */ if (mgr->stolen_base + stolen_size <=pci_resource_len (pdev,LMEM_BAR )) - mgr->io_base = tile->mem.vram.io_start + mgr->stolen_base; + mgr->io_base = tile->mem.vram->io_start + mgr->stolen_base;/* * There may be few KB of platform dependent reserved memory at the end
drivers/gpu/drm/xe/xe_ttm_vram_mgr.c +2 -2
@@ -340,7 +340,7 @@ int __xe_ttm_vram_mgr_init(struct xe_device *xe, struct xe_ttm_vram_mgr *mgr,int xe_ttm_vram_mgr_init (struct xe_tile *tile,struct xe_ttm_vram_mgr *mgr) {struct xe_device *xe =tile_to_xe (tile); -struct xe_vram_region *vram = &tile->mem.vram; +struct xe_vram_region *vram = tile->mem.vram; return __xe_ttm_vram_mgr_init(xe, mgr, XE_PL_VRAM0 + tile->id, vram->usable_size, vram->io_size,
@@ -392,7 +392,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 + tile->mem.vram.io_start; +phys_addr_t phys = cursor.start + tile->mem.vram->io_start;size_t size =min_t (u64, cursor.size,SZ_2G );dma_addr_t addr;
drivers/gpu/drm/xe/xe_vram.c +34 -30
115 lines not on this page · raw message
Signature · 1 line
2.34.1
PATCH v7 3/4 drm/xe: Move struct xe_vram_region to a dedicated header
In reply to Piórkowski, PiotrFrom: Piotr Piórkowski <[email protected]>
Let's move the xe_vram_region structure to a new header dedicated to VRAM to improve modularity and avoid unnecessary dependencies when only VRAM-related structures are needed.
v2: Fix build if CONFIG_DRM_XE_DEVMEM_MIRROR is enabled
v3: Fix build if CONFIG_DRM_XE_DISPLAY is enabled
--- drivers/gpu/drm/xe/display/xe_fb_pin.c | 1 + drivers/gpu/drm/xe/display/xe_plane_initial.c | 1 + drivers/gpu/drm/xe/xe_assert.h | 6 +- drivers/gpu/drm/xe/xe_bo.c | 1 + drivers/gpu/drm/xe/xe_bo_types.h | 1 + drivers/gpu/drm/xe/xe_device.c | 1 + drivers/gpu/drm/xe/xe_device_types.h | 60 +-------------- drivers/gpu/drm/xe/xe_gt_sriov_pf_config.c | 1 + drivers/gpu/drm/xe/xe_migrate.c | 1 + drivers/gpu/drm/xe/xe_svm.c | 3 +- drivers/gpu/drm/xe/xe_tile.c | 1 + drivers/gpu/drm/xe/xe_tile.h | 11 --- drivers/gpu/drm/xe/xe_ttm_stolen_mgr.c | 1 + drivers/gpu/drm/xe/xe_ttm_vram_mgr.c | 1 + drivers/gpu/drm/xe/xe_vram.c | 12 +++ drivers/gpu/drm/xe/xe_vram.h | 4 + drivers/gpu/drm/xe/xe_vram_types.h | 74 +++++++++++++++++++ 17 files changed, 106 insertions(+), 74 deletions(-) create mode 100644 drivers/gpu/drm/xe/xe_vram_types.h
drivers/gpu/drm/xe/display/xe_fb_pin.c +1 -0
@@ -16,6 +16,7 @@#include "xe_device.h" #include "xe_ggtt.h" #include "xe_pm.h" +#include "xe_vram_types.h" static void write_dpt_rotated(struct xe_bo *bo, struct iosys_map *map, u32 *dpt_ofs, u32 bo_ofs,
drivers/gpu/drm/xe/display/xe_plane_initial.c +1 -0
@@ -22,6 +22,7 @@#include "intel_plane_initial.h" #include "xe_bo.h" #include "xe_wa.h" +#include "xe_vram_types.h" #include <generated/xe_wa_oob.h>
drivers/gpu/drm/xe/xe_assert.h +3 -3
@@ -12,6 +12,7 @@#include "xe_gt_types.h" #include "xe_step.h" +#include "xe_vram.h" /** * DOC: Xe Asserts
@@ -145,9 +146,8 @@const struct xe_tile *__tile = (tile); \ char __buf[10] __maybe_unused; \xe_assert_msg (tile_to_xe (__tile), condition,"tile: %u VRAM %s\n" msg, \ - __tile->id, ({string_get_size (__tile->mem.vram ? \ - __tile->mem.vram->actual_physical_size : \ -0 ,1 , \ + __tile->id, ({string_get_size ( \ +xe_vram_region_actual_physical_size (__tile->mem.vram),1 , \ STRING_UNITS_2, __buf, sizeof(__buf)); __buf; }), ## arg); \ })
drivers/gpu/drm/xe/xe_bo.c +1 -0
@@ -34,6 +34,7 @@#include "xe_trace_bo.h" #include "xe_ttm_stolen_mgr.h" #include "xe_vm.h" +#include "xe_vram_types.h" const char *const xe_mem_type_to_name[TTM_NUM_MEM_TYPES ] = { [XE_PL_SYSTEM ] ="system" ,
drivers/gpu/drm/xe/xe_bo_types.h +1 -0
@@ -9,6 +9,7 @@#include <linux/iosys-map.h> #include <drm/drm_gpusvm.h> +#include <drm/drm_pagemap.h> #include <drm/ttm/ttm_bo.h> #include <drm/ttm/ttm_device.h> #include <drm/ttm/ttm_placement.h>
drivers/gpu/drm/xe/xe_device.c +1 -0
@@ -63,6 +63,7 @@#include "xe_ttm_sys_mgr.h" #include "xe_vm.h" #include "xe_vram.h" +#include "xe_vram_types.h" #include "xe_vsec.h" #include "xe_wait_user_fence.h" #include "xe_wa.h"
drivers/gpu/drm/xe/xe_device_types.h +1 -59
84 lines not on this page · raw message
drivers/gpu/drm/xe/xe_gt_sriov_pf_config.c +1 -0
@@ -33,6 +33,7 @@#include "xe_migrate.h" #include "xe_sriov.h" #include "xe_ttm_vram_mgr.h" +#include "xe_vram_types.h" #include "xe_wopcm.h" #define make_u64_from_u32 (hi, lo) ((u64)((u64)(u32)(hi) << 32 | (u32)(lo)))
drivers/gpu/drm/xe/xe_migrate.c +1 -0
@@ -34,6 +34,7 @@#include "xe_sync.h" #include "xe_trace_bo.h" #include "xe_vm.h" +#include "xe_vram_types.h" /** * struct xe_migrate - migrate context.
drivers/gpu/drm/xe/xe_svm.c +2 -1
@@ -17,6 +17,7 @@#include "xe_ttm_vram_mgr.h" #include "xe_vm.h" #include "xe_vm_types.h" +#include "xe_vram_types.h" static bool xe_svm_range_in_vram (struct xe_svm_range *range) {
@@ -1006,7 +1007,7 @@ int xe_svm_alloc_vram(struct xe_tile *tile, struct xe_svm_range *range,xe_assert (tile_to_xe (tile), range->base.flags.migrate_devmem);range_debug (range,"ALLOCATE VRAM" ); - dpagemap =xe_tile_local_pagemap (tile); + dpagemap = &tile->mem.vram->dpagemap; return drm_pagemap_populate_mm(dpagemap, xe_svm_range_start(range), xe_svm_range_end(range), range->base.gpusvm->mm,
drivers/gpu/drm/xe/xe_tile.c +1 -0
@@ -18,6 +18,7 @@#include "xe_tile.h" #include "xe_tile_sysfs.h" #include "xe_ttm_vram_mgr.h" +#include "xe_vram_types.h" #include "xe_wa.h" /**
drivers/gpu/drm/xe/xe_tile.h +0 -11
@@ -18,15 +18,4 @@ int xe_tile_alloc_vram(struct xe_tile *tile);void xe_tile_migrate_wait (struct xe_tile *tile); -#if IS_ENABLED (CONFIG_DRM_XE_PAGEMAP ) -static inline struct drm_pagemap *xe_tile_local_pagemap (struct xe_tile *tile) -{ -return &tile->mem.vram->dpagemap; -} -#else -static inline struct drm_pagemap *xe_tile_local_pagemap (struct xe_tile *tile) -{ -return NULL ; -} -#endif #endif
drivers/gpu/drm/xe/xe_ttm_stolen_mgr.c +1 -0
@@ -24,6 +24,7 @@#include "xe_sriov.h" #include "xe_ttm_stolen_mgr.h" #include "xe_ttm_vram_mgr.h" +#include "xe_vram_types.h" #include "xe_wa.h" struct xe_ttm_stolen_mgr {
drivers/gpu/drm/xe/xe_ttm_vram_mgr.c +1 -0
@@ -15,6 +15,7 @@#include "xe_gt.h" #include "xe_res_cursor.h" #include "xe_ttm_vram_mgr.h" +#include "xe_vram_types.h" static inline struct drm_buddy_block *xe_ttm_vram_mgr_first_block (struct list_head *list)
drivers/gpu/drm/xe/xe_vram.c +12 -0
@@ -20,6 +20,7 @@#include "xe_module.h" #include "xe_sriov.h" #include "xe_vram.h" +#include "xe_vram_types.h" #define BAR_SIZE_SHIFT 20
@@ -375,3 +376,14 @@ int xe_vram_probe(struct xe_device *xe)return devm_add_action_or_reset (xe->drm.dev, vram_fini, xe); } + +/** +* xe_vram_region_actual_physical_size() - Get the actual physical size of a VRAM region +* @vram: the xe_vram_region struct +* +* Return: the actual physical size of the VRAM region, or 0 if @vram is NULL +*/ +resource_size_t xe_vram_region_actual_physical_size (struct xe_vram_region *vram) +{ +return vram ? vram->actual_physical_size :0 ; +}
drivers/gpu/drm/xe/xe_vram.h +4 -0
@@ -6,8 +6,12 @@#ifndef _XE_VRAM_H_#define _XE_VRAM_H_ +#include <linux/types.h> +struct xe_device ; +struct xe_vram_region ;int xe_vram_probe (struct xe_device *xe); +resource_size_t xe_vram_region_actual_physical_size (struct xe_vram_region *vram);#endif
drivers/gpu/drm/xe/xe_vram_types.h new file +74 -0
74 lines not on this page · raw message
Signature · 1 line
2.34.1
PATCH v7 4/4 drm/xe: Unify the initialization of VRAM regions
In reply to Piórkowski, PiotrFrom: Piotr Piórkowski <[email protected]>
Currently in the drivers we have defined VRAM regions per device and per tile. Initialization of these regions is done in two completely different ways. To simplify the logic of the code and make it easier to add new regions in the future, let's unify the way we initialize VRAM regions.
v2:
- fix doc comments in struct xe_vram_region
- remove unnecessary includes (Jani)
v3:
- move code from xe_vram_init_regions_managers to xe_tile_init_noalloc (Matthew)
- replace ioremap_wc to devm_ioremap_wc for mapping VRAM BAR (Matthew)
- Replace the tile id parameter with vram region in the xe_pf_begin function.
--- drivers/gpu/drm/xe/xe_gt_pagefault.c | 13 ++- drivers/gpu/drm/xe/xe_query.c | 3 +- drivers/gpu/drm/xe/xe_tile.c | 38 +++---- drivers/gpu/drm/xe/xe_ttm_vram_mgr.c | 16 ++- drivers/gpu/drm/xe/xe_ttm_vram_mgr.h | 3 +- drivers/gpu/drm/xe/xe_vram.c | 149 ++++++++++++++++----------- drivers/gpu/drm/xe/xe_vram.h | 1 + drivers/gpu/drm/xe/xe_vram_types.h | 8 ++ 8 files changed, 134 insertions(+), 97 deletions(-)
drivers/gpu/drm/xe/xe_gt_pagefault.c +8 -5
@@ -23,6 +23,7 @@#include "xe_svm.h" #include "xe_trace_bo.h" #include "xe_vm.h" +#include "xe_vram_types.h" struct pagefault {u64 page_addr;
@@ -74,7 +75,7 @@ static bool vma_is_valid(struct xe_tile *tile, struct xe_vma *vma) }static int xe_pf_begin (struct drm_exec *exec,struct xe_vma *vma, -bool atomic,unsigned int id) +bool atomic,struct xe_vram_region *vram) {struct xe_bo *bo =xe_vma_bo (vma);struct xe_vm *vm =xe_vma_vm (vma);
@@ -84,14 +85,16 @@ static int xe_pf_begin(struct drm_exec *exec, struct xe_vma *vma,if (err)return err; -if (atomic &&IS_DGFX (vm->xe)) { +if (atomic && vram) { +xe_assert (vm->xe,IS_DGFX (vm->xe)); +if (xe_vma_is_userptr (vma)) { err = -EACCES ;return err; }/* Migrate to VRAM, move should invalidate the VMA first */ - err =xe_bo_migrate (bo,XE_PL_VRAM0 + id); + err =xe_bo_migrate (bo, vram->placement);if (err)return err; }else if (bo) {
@@ -138,7 +141,7 @@ static int handle_vma_pagefault(struct xe_gt *gt, struct xe_vma *vma,/* Lock VM and BOs dma-resv */ drm_exec_init (&exec,0 ,0 ); drm_exec_until_all_locked(&exec) { - err =xe_pf_begin (&exec, vma, atomic, tile->id); + err =xe_pf_begin (&exec, vma, atomic, tile->mem.vram);drm_exec_retry_on_contention (&exec);if (xe_vm_validate_should_retry (&exec, err, &end)) err = -EAGAIN ;
@@ -572,7 +575,7 @@ static int handle_acc(struct xe_gt *gt, struct acc *acc)/* Lock VM and BOs dma-resv */ drm_exec_init (&exec,0 ,0 ); drm_exec_until_all_locked(&exec) { - ret =xe_pf_begin (&exec, vma, true, tile->id); + ret =xe_pf_begin (&exec, vma, true, tile->mem.vram);drm_exec_retry_on_contention (&exec);if (ret)break ;
drivers/gpu/drm/xe/xe_query.c +2 -1
@@ -27,6 +27,7 @@#include "xe_oa.h" #include "xe_pxp.h" #include "xe_ttm_vram_mgr.h" +#include "xe_vram_types.h" #include "xe_wa.h" static const u16 xe_to_user_engine_class[] = {
@@ -409,7 +410,7 @@ static int query_gt_list(struct xe_device *xe, struct drm_xe_device_query *query gt_list->gt_list[id].near_mem_regions =0x1 ; else gt_list->gt_list[id].near_mem_regions = -BIT (gt_to_tile (gt)->id) <<1 ; +BIT (gt_to_tile (gt)->mem.vram->id) <<1 ; gt_list->gt_list[id].far_mem_regions = xe->info.mem_region_mask ^ gt_list->gt_list[id].near_mem_regions;
drivers/gpu/drm/xe/xe_tile.c +13 -25
@@ -7,6 +7,7 @@#include <drm/drm_managed.h> +#include "xe_bo.h" #include "xe_device.h" #include "xe_ggtt.h" #include "xe_gt.h"
@@ -20,6 +21,7 @@#include "xe_ttm_vram_mgr.h" #include "xe_vram_types.h" #include "xe_wa.h" +#include "xe_vram.h" /** * DOC: Multi-tile Design
@@ -113,11 +115,9 @@ int xe_tile_alloc_vram(struct xe_tile *tile)if (!IS_DGFX (xe))return 0 ; - vram =drmm_kzalloc (&xe->drm,sizeof (*vram),GFP_KERNEL ); -if (!vram) -return -ENOMEM ; - - vram->tile = tile; + vram =xe_vram_region_alloc (xe, tile->id,XE_PL_VRAM0 + tile->id); +if (IS_ERR (vram)) +return PTR_ERR (vram); tile->mem.vram = vram;return 0 ;
@@ -155,21 +155,6 @@ int xe_tile_init_early(struct xe_tile *tile, struct xe_device *xe, u8 id) }ALLOW_ERROR_INJECTION (xe_tile_init_early,ERRNO );/* See xe_pci_probe() */ -static int tile_ttm_mgr_init (struct xe_tile *tile) -{ -struct xe_device *xe =tile_to_xe (tile); -int err; - -if (tile->mem.vram->usable_size) { - err =xe_ttm_vram_mgr_init (tile, &tile->mem.vram->ttm); -if (err) -return err; - xe->info.mem_region_mask |=BIT (tile->id) <<1 ; - } - -return 0 ; -} -/** * xe_tile_init_noalloc - Init tile up to the point where allocations can happen. * @tile: The tile to initialize.
@@ -187,17 +172,20 @@ static int tile_ttm_mgr_init(struct xe_tile *tile)int xe_tile_init_noalloc (struct xe_tile *tile) {struct xe_device *xe =tile_to_xe (tile); -int err; - - err =tile_ttm_mgr_init (tile); -if (err) -return err;xe_wa_apply_tile_workarounds (tile);if (xe->info.has_usm &&IS_DGFX (xe))xe_devm_add (tile, tile->mem.vram); +if (IS_DGFX (xe) && !ttm_resource_manager_used (&tile->mem.vram->ttm.manager)) { +int err =xe_ttm_vram_mgr_init (xe, tile->mem.vram); + +if (err) +return err; + xe->info.mem_region_mask |=BIT (tile->mem.vram->id) <<1 ; + } +return xe_tile_sysfs_init (tile); }
drivers/gpu/drm/xe/xe_ttm_vram_mgr.c +11 -5
@@ -338,12 +338,18 @@ int __xe_ttm_vram_mgr_init(struct xe_device *xe, struct xe_ttm_vram_mgr *mgr,return drmm_add_action_or_reset (&xe->drm, ttm_vram_mgr_fini, mgr); } -int xe_ttm_vram_mgr_init (struct xe_tile *tile,struct xe_ttm_vram_mgr *mgr) +/** +* xe_ttm_vram_mgr_init - initialize TTM VRAM region +* @xe: pointer to Xe device +* @vram: pointer to xe_vram_region that contains the memory region attributes +* +* Initialize the Xe TTM for given @vram region using the given parameters. +* +* Returns 0 for success, negative error code otherwise. +*/ +int xe_ttm_vram_mgr_init (struct xe_device *xe,struct xe_vram_region *vram) { -struct xe_device *xe =tile_to_xe (tile); -struct xe_vram_region *vram = tile->mem.vram; - -return __xe_ttm_vram_mgr_init (xe, mgr,XE_PL_VRAM0 + tile->id, +return __xe_ttm_vram_mgr_init (xe, &vram->ttm, vram->placement, vram->usable_size, vram->io_size,PAGE_SIZE ); }
drivers/gpu/drm/xe/xe_ttm_vram_mgr.h +2 -1
@@ -11,11 +11,12 @@enum dma_data_direction ;struct xe_device ;struct xe_tile ; +struct xe_vram_region ;int __xe_ttm_vram_mgr_init (struct xe_device *xe,struct xe_ttm_vram_mgr *mgr,u32 mem_type,u64 size,u64 io_size,u64 default_page_size); -int xe_ttm_vram_mgr_init (struct xe_tile *tile,struct xe_ttm_vram_mgr *mgr); +int xe_ttm_vram_mgr_init (struct xe_device *xe,struct xe_vram_region *vram); int xe_ttm_vram_mgr_alloc_sgt(struct xe_device *xe, struct ttm_resource *res, u64 offset, u64 length,
drivers/gpu/drm/xe/xe_vram.c +89 -60
207 lines not on this page · raw message
drivers/gpu/drm/xe/xe_vram.h +1 -0
@@ -13,5 +13,6 @@ struct xe_vram_region;int xe_vram_probe (struct xe_device *xe);resource_size_t xe_vram_region_actual_physical_size (struct xe_vram_region *vram); +struct xe_vram_region *xe_vram_region_alloc (struct xe_device *xe,u8 id,u32 placement);#endif
drivers/gpu/drm/xe/xe_vram_types.h +8 -0
@@ -22,6 +22,12 @@ struct xe_tile;struct xe_vram_region {/** @tile: Backpointer to tile */ struct xe_tile *tile; +/** +* @id: VRAM region instance id +* +* The value should be unique for VRAM region. +*/ +u8 id;/** @io_start: IO start address of this VRAM instance */ resource_size_t io_start;/**
@@ -54,6 +60,8 @@ struct xe_vram_region {void __iomem *mapping;/** @ttm: VRAM TTM manager */ struct xe_ttm_vram_mgr ttm; +/** @placement: TTM placement dedicated for this region */ +u32 placement;#if IS_ENABLED (CONFIG_DRM_XE_PAGEMAP )/** @pagemap: Used to remap device memory as ZONE_DEVICE */ struct dev_pagemap pagemap;
Signature · 1 line
2.34.1