Skip to content

Commit 3ad86ae

Browse files
juhapekkamkahola
authored andcommitted
drm/xe: add interface to request physical alignment for buffer objects
Add xe_bo_create_pin_map_at_aligned() which augment xe_bo_create_pin_map_at() with alignment parameter allowing to pass required alignemnt if it differ from default. Signed-off-by: Juha-Pekka Heikkila <[email protected]> Reviewed-by: Jonathan Cavitt <[email protected]> Signed-off-by: Mika Kahola <[email protected]> Link: https://patchwork.freedesktop.org/patch/msgid/[email protected]
1 parent 26f69e8 commit 3ad86ae

File tree

5 files changed

+37
-9
lines changed

5 files changed

+37
-9
lines changed

drivers/gpu/drm/xe/compat-i915-headers/gem/i915_gem_stolen.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ static inline int i915_gem_stolen_insert_node_in_range(struct xe_device *xe,
2929

3030
bo = xe_bo_create_locked_range(xe, xe_device_get_root_tile(xe),
3131
NULL, size, start, end,
32-
ttm_bo_type_kernel, flags);
32+
ttm_bo_type_kernel, flags, 0);
3333
if (IS_ERR(bo)) {
3434
err = PTR_ERR(bo);
3535
bo = NULL;

drivers/gpu/drm/xe/xe_bo.c

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1454,7 +1454,8 @@ static struct xe_bo *
14541454
__xe_bo_create_locked(struct xe_device *xe,
14551455
struct xe_tile *tile, struct xe_vm *vm,
14561456
size_t size, u64 start, u64 end,
1457-
u16 cpu_caching, enum ttm_bo_type type, u32 flags)
1457+
u16 cpu_caching, enum ttm_bo_type type, u32 flags,
1458+
u64 alignment)
14581459
{
14591460
struct xe_bo *bo = NULL;
14601461
int err;
@@ -1483,6 +1484,8 @@ __xe_bo_create_locked(struct xe_device *xe,
14831484
if (IS_ERR(bo))
14841485
return bo;
14851486

1487+
bo->min_align = alignment;
1488+
14861489
/*
14871490
* Note that instead of taking a reference no the drm_gpuvm_resv_bo(),
14881491
* to ensure the shared resv doesn't disappear under the bo, the bo
@@ -1523,16 +1526,18 @@ struct xe_bo *
15231526
xe_bo_create_locked_range(struct xe_device *xe,
15241527
struct xe_tile *tile, struct xe_vm *vm,
15251528
size_t size, u64 start, u64 end,
1526-
enum ttm_bo_type type, u32 flags)
1529+
enum ttm_bo_type type, u32 flags, u64 alignment)
15271530
{
1528-
return __xe_bo_create_locked(xe, tile, vm, size, start, end, 0, type, flags);
1531+
return __xe_bo_create_locked(xe, tile, vm, size, start, end, 0, type,
1532+
flags, alignment);
15291533
}
15301534

15311535
struct xe_bo *xe_bo_create_locked(struct xe_device *xe, struct xe_tile *tile,
15321536
struct xe_vm *vm, size_t size,
15331537
enum ttm_bo_type type, u32 flags)
15341538
{
1535-
return __xe_bo_create_locked(xe, tile, vm, size, 0, ~0ULL, 0, type, flags);
1539+
return __xe_bo_create_locked(xe, tile, vm, size, 0, ~0ULL, 0, type,
1540+
flags, 0);
15361541
}
15371542

15381543
struct xe_bo *xe_bo_create_user(struct xe_device *xe, struct xe_tile *tile,
@@ -1542,7 +1547,7 @@ struct xe_bo *xe_bo_create_user(struct xe_device *xe, struct xe_tile *tile,
15421547
{
15431548
struct xe_bo *bo = __xe_bo_create_locked(xe, tile, vm, size, 0, ~0ULL,
15441549
cpu_caching, ttm_bo_type_device,
1545-
flags | XE_BO_FLAG_USER);
1550+
flags | XE_BO_FLAG_USER, 0);
15461551
if (!IS_ERR(bo))
15471552
xe_bo_unlock_vm_held(bo);
15481553

@@ -1565,6 +1570,17 @@ struct xe_bo *xe_bo_create_pin_map_at(struct xe_device *xe, struct xe_tile *tile
15651570
struct xe_vm *vm,
15661571
size_t size, u64 offset,
15671572
enum ttm_bo_type type, u32 flags)
1573+
{
1574+
return xe_bo_create_pin_map_at_aligned(xe, tile, vm, size, offset,
1575+
type, flags, 0);
1576+
}
1577+
1578+
struct xe_bo *xe_bo_create_pin_map_at_aligned(struct xe_device *xe,
1579+
struct xe_tile *tile,
1580+
struct xe_vm *vm,
1581+
size_t size, u64 offset,
1582+
enum ttm_bo_type type, u32 flags,
1583+
u64 alignment)
15681584
{
15691585
struct xe_bo *bo;
15701586
int err;
@@ -1576,7 +1592,8 @@ struct xe_bo *xe_bo_create_pin_map_at(struct xe_device *xe, struct xe_tile *tile
15761592
flags |= XE_BO_FLAG_GGTT;
15771593

15781594
bo = xe_bo_create_locked_range(xe, tile, vm, size, start, end, type,
1579-
flags | XE_BO_FLAG_NEEDS_CPU_ACCESS);
1595+
flags | XE_BO_FLAG_NEEDS_CPU_ACCESS,
1596+
alignment);
15801597
if (IS_ERR(bo))
15811598
return bo;
15821599

drivers/gpu/drm/xe/xe_bo.h

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ struct xe_bo *
7777
xe_bo_create_locked_range(struct xe_device *xe,
7878
struct xe_tile *tile, struct xe_vm *vm,
7979
size_t size, u64 start, u64 end,
80-
enum ttm_bo_type type, u32 flags);
80+
enum ttm_bo_type type, u32 flags, u64 alignment);
8181
struct xe_bo *xe_bo_create_locked(struct xe_device *xe, struct xe_tile *tile,
8282
struct xe_vm *vm, size_t size,
8383
enum ttm_bo_type type, u32 flags);
@@ -94,6 +94,12 @@ struct xe_bo *xe_bo_create_pin_map(struct xe_device *xe, struct xe_tile *tile,
9494
struct xe_bo *xe_bo_create_pin_map_at(struct xe_device *xe, struct xe_tile *tile,
9595
struct xe_vm *vm, size_t size, u64 offset,
9696
enum ttm_bo_type type, u32 flags);
97+
struct xe_bo *xe_bo_create_pin_map_at_aligned(struct xe_device *xe,
98+
struct xe_tile *tile,
99+
struct xe_vm *vm,
100+
size_t size, u64 offset,
101+
enum ttm_bo_type type, u32 flags,
102+
u64 alignment);
97103
struct xe_bo *xe_bo_create_from_data(struct xe_device *xe, struct xe_tile *tile,
98104
const void *data, size_t size,
99105
enum ttm_bo_type type, u32 flags);

drivers/gpu/drm/xe/xe_bo_types.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,11 @@ struct xe_bo {
7676

7777
/** @vram_userfault_link: Link into @mem_access.vram_userfault.list */
7878
struct list_head vram_userfault_link;
79+
80+
/** @min_align: minimum alignment needed for this BO if different
81+
* from default
82+
*/
83+
u64 min_align;
7984
};
8085

8186
#define intel_bo_to_drm_bo(bo) (&(bo)->ttm.base)

drivers/gpu/drm/xe/xe_ggtt.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -603,7 +603,7 @@ static int __xe_ggtt_insert_bo_at(struct xe_ggtt *ggtt, struct xe_bo *bo,
603603
u64 start, u64 end)
604604
{
605605
int err;
606-
u64 alignment = XE_PAGE_SIZE;
606+
u64 alignment = bo->min_align > 0 ? bo->min_align : XE_PAGE_SIZE;
607607

608608
if (xe_bo_is_vram(bo) && ggtt->flags & XE_GGTT_FLAGS_64K)
609609
alignment = SZ_64K;

0 commit comments

Comments
 (0)