Skip to content

Commit 535881a

Browse files
committed
drm/xe/uapi: Document the memory_region bitmask
The uAPI should stay generic in regarding to the bitmask. It is the userspace responsibility to check for the type/class of the memory, without any assumption. Also add comments inside the code to explain how it is actually constructed so we don't accidentally change the assignment of the instance and the masks. No functional change in this patch. It only explains and document the memory_region masks. A further follow-up work with the organization of all memory regions around struct xe_mem_regions is desired, but not part of this patch. Signed-off-by: Rodrigo Vivi <[email protected]> Reviewed-by: Lucas De Marchi <[email protected]> Acked-by: José Roberto de Souza <[email protected]> Acked-by: Mateusz Naklicki <[email protected]> Signed-off-by: Francois Dugast <[email protected]>
1 parent 4b43789 commit 535881a

File tree

2 files changed

+37
-5
lines changed

2 files changed

+37
-5
lines changed

drivers/gpu/drm/xe/xe_query.c

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -266,6 +266,11 @@ static int query_mem_regions(struct xe_device *xe,
266266

267267
man = ttm_manager_type(&xe->ttm, XE_PL_TT);
268268
mem_regions->mem_regions[0].mem_class = DRM_XE_MEM_REGION_CLASS_SYSMEM;
269+
/*
270+
* The instance needs to be a unique number that represents the index
271+
* in the placement mask used at xe_gem_create_ioctl() for the
272+
* xe_bo_create() placement.
273+
*/
269274
mem_regions->mem_regions[0].instance = 0;
270275
mem_regions->mem_regions[0].min_page_size = PAGE_SIZE;
271276
mem_regions->mem_regions[0].total_size = man->size << PAGE_SHIFT;
@@ -381,6 +386,20 @@ static int query_gt_list(struct xe_device *xe, struct drm_xe_device_query *query
381386
gt_list->gt_list[id].tile_id = gt_to_tile(gt)->id;
382387
gt_list->gt_list[id].gt_id = gt->info.id;
383388
gt_list->gt_list[id].reference_clock = gt->info.reference_clock;
389+
/*
390+
* The mem_regions indexes in the mask below need to
391+
* directly identify the struct
392+
* drm_xe_query_mem_regions' instance constructed at
393+
* query_mem_regions()
394+
*
395+
* For our current platforms:
396+
* Bit 0 -> System Memory
397+
* Bit 1 -> VRAM0 on Tile0
398+
* Bit 2 -> VRAM1 on Tile1
399+
* However the uAPI is generic and it's userspace's
400+
* responsibility to check the mem_class, without any
401+
* assumption.
402+
*/
384403
if (!IS_DGFX(xe))
385404
gt_list->gt_list[id].near_mem_regions = 0x1;
386405
else

include/uapi/drm/xe_drm.h

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -256,10 +256,9 @@ struct drm_xe_mem_region {
256256
*/
257257
__u16 mem_class;
258258
/**
259-
* @instance: The instance for this region.
260-
*
261-
* The @mem_class and @instance taken together will always give
262-
* a unique pair.
259+
* @instance: The unique ID for this region, which serves as the
260+
* index in the placement bitmask used as argument for
261+
* &DRM_IOCTL_XE_GEM_CREATE
263262
*/
264263
__u16 instance;
265264
/**
@@ -404,6 +403,10 @@ struct drm_xe_gt {
404403
* @near_mem_regions: Bit mask of instances from
405404
* drm_xe_query_mem_regions that are nearest to the current engines
406405
* of this GT.
406+
* Each index in this mask refers directly to the struct
407+
* drm_xe_query_mem_regions' instance, no assumptions should
408+
* be made about order. The type of each region is described
409+
* by struct drm_xe_query_mem_regions' mem_class.
407410
*/
408411
__u64 near_mem_regions;
409412
/**
@@ -412,6 +415,10 @@ struct drm_xe_gt {
412415
* In general, they have extra indirections when compared to the
413416
* @near_mem_regions. For a discrete device this could mean system
414417
* memory and memory living in a different tile.
418+
* Each index in this mask refers directly to the struct
419+
* drm_xe_query_mem_regions' instance, no assumptions should
420+
* be made about order. The type of each region is described
421+
* by struct drm_xe_query_mem_regions' mem_class.
415422
*/
416423
__u64 far_mem_regions;
417424
/** @reserved: Reserved */
@@ -652,7 +659,13 @@ struct drm_xe_gem_create {
652659
*/
653660
__u64 size;
654661

655-
/** @placement: A mask of memory instances of where BO can be placed. */
662+
/**
663+
* @placement: A mask of memory instances of where BO can be placed.
664+
* Each index in this mask refers directly to the struct
665+
* drm_xe_query_mem_regions' instance, no assumptions should
666+
* be made about order. The type of each region is described
667+
* by struct drm_xe_query_mem_regions' mem_class.
668+
*/
656669
__u32 placement;
657670

658671
#define DRM_XE_GEM_CREATE_FLAG_DEFER_BACKING (1 << 0)

0 commit comments

Comments
 (0)