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

drm/xe: Split xe_migrate allocation from initialization

Currently, xe_migrate_init handled both allocation and initialization,
Lets moves allocation to xe_tile_alloc via a new xe_migrate_alloc
function, and keep initialization in xe_migrate_init.
This will allow the migration pointers to be passed to other structures
before full initialization.
Also replaces devm_kzalloc with drmm_kzalloc for better
DRM-managed memory.

Signed-off-by: Piotr Piórkowski <piotr.piorkowski@intel.com>
Reviewed-by: Matthew Brost <matthew.brost@intel.com>
Link: https://lore.kernel.org/r/20250714184818.89201-5-piotr.piorkowski@intel.com
Signed-off-by: Lucas De Marchi <lucas.demarchi@intel.com>

authored by

Piotr Piórkowski and committed by
Lucas De Marchi
d65ff1ec 7a20b4f5

+23 -7
+18 -7
drivers/gpu/drm/xe/xe_migrate.c
··· 390 390 } 391 391 392 392 /** 393 + * xe_migrate_alloc - Allocate a migrate struct for a given &xe_tile 394 + * @tile: &xe_tile 395 + * 396 + * Allocates a &xe_migrate for a given tile. 397 + * 398 + * Return: &xe_migrate on success, or NULL when out of memory. 399 + */ 400 + struct xe_migrate *xe_migrate_alloc(struct xe_tile *tile) 401 + { 402 + struct xe_migrate *m = drmm_kzalloc(&tile_to_xe(tile)->drm, sizeof(*m), GFP_KERNEL); 403 + 404 + if (m) 405 + m->tile = tile; 406 + return m; 407 + } 408 + 409 + /** 393 410 * xe_migrate_init() - Initialize a migrate context 394 411 * @tile: Back-pointer to the tile we're initializing for. 395 412 * ··· 416 399 { 417 400 struct xe_device *xe = tile_to_xe(tile); 418 401 struct xe_gt *primary_gt = tile->primary_gt; 419 - struct xe_migrate *m; 402 + struct xe_migrate *m = tile->migrate; 420 403 struct xe_vm *vm; 421 404 int err; 422 - 423 - m = devm_kzalloc(xe->drm.dev, sizeof(*m), GFP_KERNEL); 424 - if (!m) 425 - return ERR_PTR(-ENOMEM); 426 - 427 - m->tile = tile; 428 405 429 406 /* Special layout, prepared below.. */ 430 407 vm = xe_vm_create(xe, XE_VM_FLAG_MIGRATION |
+1
drivers/gpu/drm/xe/xe_migrate.h
··· 93 93 u8 tile_id; 94 94 }; 95 95 96 + struct xe_migrate *xe_migrate_alloc(struct xe_tile *tile); 96 97 struct xe_migrate *xe_migrate_init(struct xe_tile *tile); 97 98 98 99 struct dma_fence *xe_migrate_to_vram(struct xe_migrate *m,
+4
drivers/gpu/drm/xe/xe_tile.c
··· 94 94 if (!tile->mem.ggtt) 95 95 return -ENOMEM; 96 96 97 + tile->migrate = xe_migrate_alloc(tile); 98 + if (!tile->migrate) 99 + return -ENOMEM; 100 + 97 101 return 0; 98 102 } 99 103