Skip to content

Commit 6c55404

Browse files
author
Thomas Hellström
committed
drm/xe: Introduce CONFIG_DRM_XE_GPUSVM
Don't rely on CONFIG_DRM_GPUSVM because other drivers may enable it causing us to compile in SVM support unintentionally. Also take the opportunity to leave more code out of compilation if !CONFIG_DRM_XE_GPUSVM and !CONFIG_DRM_XE_DEVMEM_MIRROR v3: - Fixes for compilation errors on 32-bit. This changes the Kconfig logic a bit. Signed-off-by: Thomas Hellström <[email protected]> Reviewed-by: Matthew Brost <[email protected]> Link: https://lore.kernel.org/r/[email protected]
1 parent cca9734 commit 6c55404

File tree

9 files changed

+98
-27
lines changed

9 files changed

+98
-27
lines changed

drivers/gpu/drm/xe/Kconfig

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@ config DRM_XE
3939
select DRM_TTM_HELPER
4040
select DRM_EXEC
4141
select DRM_GPUVM
42-
select DRM_GPUSVM if !UML && DEVICE_PRIVATE
4342
select DRM_SCHED
4443
select MMU_NOTIFIER
4544
select WANT_DEV_COREDUMP
@@ -74,9 +73,22 @@ config DRM_XE_DP_TUNNEL
7473

7574
If in doubt say "Y".
7675

76+
config DRM_XE_GPUSVM
77+
bool "Enable CPU to GPU address mirroring"
78+
depends on DRM_XE
79+
depends on !UML
80+
depends on DEVICE_PRIVATE
81+
default y
82+
select DRM_GPUSVM
83+
help
84+
Enable this option if you want support for CPU to GPU address
85+
mirroring.
86+
87+
If in doubut say "Y".
88+
7789
config DRM_XE_DEVMEM_MIRROR
7890
bool "Enable device memory mirror"
79-
depends on DRM_XE
91+
depends on DRM_XE_GPUSVM
8092
select GET_FREE_REGION
8193
default y
8294
help

drivers/gpu/drm/xe/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ xe-y += xe_bb.o \
125125
xe_wopcm.o
126126

127127
xe-$(CONFIG_HMM_MIRROR) += xe_hmm.o
128-
xe-$(CONFIG_DRM_GPUSVM) += xe_svm.o
128+
xe-$(CONFIG_DRM_XE_GPUSVM) += xe_svm.o
129129

130130
# graphics hardware monitoring (HWMON) support
131131
xe-$(CONFIG_HWMON) += xe_hwmon.o

drivers/gpu/drm/xe/xe_device_types.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,9 @@ struct xe_vram_region {
107107
resource_size_t actual_physical_size;
108108
/** @mapping: pointer to VRAM mappable space */
109109
void __iomem *mapping;
110+
/** @ttm: VRAM TTM manager */
111+
struct xe_ttm_vram_mgr ttm;
112+
#if IS_ENABLED(CONFIG_DRM_XE_DEVMEM_MIRROR)
110113
/** @pagemap: Used to remap device memory as ZONE_DEVICE */
111114
struct dev_pagemap pagemap;
112115
/**
@@ -120,8 +123,7 @@ struct xe_vram_region {
120123
* This is generated when remap device memory as ZONE_DEVICE
121124
*/
122125
resource_size_t hpa_base;
123-
/** @ttm: VRAM TTM manager */
124-
struct xe_ttm_vram_mgr ttm;
126+
#endif
125127
};
126128

127129
/**

drivers/gpu/drm/xe/xe_migrate.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1544,6 +1544,7 @@ void xe_migrate_wait(struct xe_migrate *m)
15441544
dma_fence_wait(m->fence, false);
15451545
}
15461546

1547+
#if IS_ENABLED(CONFIG_DRM_XE_DEVMEM_MIRROR)
15471548
static u32 pte_update_cmd_size(u64 size)
15481549
{
15491550
u32 num_dword;
@@ -1719,6 +1720,8 @@ struct dma_fence *xe_migrate_from_vram(struct xe_migrate *m,
17191720
XE_MIGRATE_COPY_TO_SRAM);
17201721
}
17211722

1723+
#endif
1724+
17221725
#if IS_ENABLED(CONFIG_DRM_XE_KUNIT_TEST)
17231726
#include "tests/xe_migrate.c"
17241727
#endif

drivers/gpu/drm/xe/xe_pt.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1420,6 +1420,7 @@ static int xe_pt_userptr_pre_commit(struct xe_migrate_pt_update *pt_update)
14201420
return err;
14211421
}
14221422

1423+
#if IS_ENABLED(CONFIG_DRM_XE_GPUSVM)
14231424
static int xe_pt_svm_pre_commit(struct xe_migrate_pt_update *pt_update)
14241425
{
14251426
struct xe_vm *vm = pt_update->vops->vm;
@@ -1453,6 +1454,7 @@ static int xe_pt_svm_pre_commit(struct xe_migrate_pt_update *pt_update)
14531454

14541455
return 0;
14551456
}
1457+
#endif
14561458

14571459
struct invalidation_fence {
14581460
struct xe_gt_tlb_invalidation_fence base;
@@ -2257,11 +2259,15 @@ static const struct xe_migrate_pt_update_ops userptr_migrate_ops = {
22572259
.pre_commit = xe_pt_userptr_pre_commit,
22582260
};
22592261

2262+
#if IS_ENABLED(CONFIG_DRM_XE_GPUSVM)
22602263
static const struct xe_migrate_pt_update_ops svm_migrate_ops = {
22612264
.populate = xe_vm_populate_pgtable,
22622265
.clear = xe_migrate_clear_pgtable_callback,
22632266
.pre_commit = xe_pt_svm_pre_commit,
22642267
};
2268+
#else
2269+
static const struct xe_migrate_pt_update_ops svm_migrate_ops;
2270+
#endif
22652271

22662272
/**
22672273
* xe_pt_update_ops_run() - Run PT update operations

drivers/gpu/drm/xe/xe_query.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -340,7 +340,7 @@ static int query_config(struct xe_device *xe, struct drm_xe_device_query *query)
340340
if (xe_device_get_root_tile(xe)->mem.vram.usable_size)
341341
config->info[DRM_XE_QUERY_CONFIG_FLAGS] |=
342342
DRM_XE_QUERY_CONFIG_FLAG_HAS_VRAM;
343-
if (xe->info.has_usm && IS_ENABLED(CONFIG_DRM_GPUSVM))
343+
if (xe->info.has_usm && IS_ENABLED(CONFIG_DRM_XE_GPUSVM))
344344
config->info[DRM_XE_QUERY_CONFIG_FLAGS] |=
345345
DRM_XE_QUERY_CONFIG_FLAG_HAS_CPU_ADDR_MIRROR;
346346
config->info[DRM_XE_QUERY_CONFIG_FLAGS] |=

drivers/gpu/drm/xe/xe_svm.c

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -340,6 +340,8 @@ static void xe_svm_garbage_collector_work_func(struct work_struct *w)
340340
up_write(&vm->lock);
341341
}
342342

343+
#if IS_ENABLED(CONFIG_DRM_XE_DEVMEM_MIRROR)
344+
343345
static struct xe_vram_region *page_to_vr(struct page *page)
344346
{
345347
return container_of(page->pgmap, struct xe_vram_region, pagemap);
@@ -578,6 +580,8 @@ static const struct drm_gpusvm_devmem_ops gpusvm_devmem_ops = {
578580
.copy_to_ram = xe_svm_copy_to_ram,
579581
};
580582

583+
#endif
584+
581585
static const struct drm_gpusvm_ops gpusvm_ops = {
582586
.range_alloc = xe_svm_range_alloc,
583587
.range_free = xe_svm_range_free,
@@ -651,6 +655,7 @@ static bool xe_svm_range_is_valid(struct xe_svm_range *range,
651655
return (range->tile_present & ~range->tile_invalidated) & BIT(tile->id);
652656
}
653657

658+
#if IS_ENABLED(CONFIG_DRM_XE_DEVMEM_MIRROR)
654659
static struct xe_vram_region *tile_to_vr(struct xe_tile *tile)
655660
{
656661
return &tile->mem.vram;
@@ -709,6 +714,15 @@ static int xe_svm_alloc_vram(struct xe_vm *vm, struct xe_tile *tile,
709714

710715
return err;
711716
}
717+
#else
718+
static int xe_svm_alloc_vram(struct xe_vm *vm, struct xe_tile *tile,
719+
struct xe_svm_range *range,
720+
const struct drm_gpusvm_ctx *ctx)
721+
{
722+
return -EOPNOTSUPP;
723+
}
724+
#endif
725+
712726

713727
/**
714728
* xe_svm_handle_pagefault() - SVM handle page fault
@@ -867,6 +881,7 @@ int xe_svm_bo_evict(struct xe_bo *bo)
867881
}
868882

869883
#if IS_ENABLED(CONFIG_DRM_XE_DEVMEM_MIRROR)
884+
870885
static struct drm_pagemap_device_addr
871886
xe_drm_pagemap_device_map(struct drm_pagemap *dpagemap,
872887
struct device *dev,

drivers/gpu/drm/xe/xe_svm.h

Lines changed: 53 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
#ifndef _XE_SVM_H_
77
#define _XE_SVM_H_
88

9+
#if IS_ENABLED(CONFIG_DRM_XE_GPUSVM)
10+
911
#include <drm/drm_pagemap.h>
1012
#include <drm/drm_gpusvm.h>
1113

@@ -44,7 +46,6 @@ struct xe_svm_range {
4446
u8 skip_migrate :1;
4547
};
4648

47-
#if IS_ENABLED(CONFIG_DRM_GPUSVM)
4849
/**
4950
* xe_svm_range_pages_valid() - SVM range pages valid
5051
* @range: SVM range
@@ -73,7 +74,50 @@ bool xe_svm_has_mapping(struct xe_vm *vm, u64 start, u64 end);
7374
int xe_svm_bo_evict(struct xe_bo *bo);
7475

7576
void xe_svm_range_debug(struct xe_svm_range *range, const char *operation);
77+
78+
/**
79+
* xe_svm_range_has_dma_mapping() - SVM range has DMA mapping
80+
* @range: SVM range
81+
*
82+
* Return: True if SVM range has a DMA mapping, False otherwise
83+
*/
84+
static inline bool xe_svm_range_has_dma_mapping(struct xe_svm_range *range)
85+
{
86+
lockdep_assert_held(&range->base.gpusvm->notifier_lock);
87+
return range->base.flags.has_dma_mapping;
88+
}
89+
90+
#define xe_svm_assert_in_notifier(vm__) \
91+
lockdep_assert_held_write(&(vm__)->svm.gpusvm.notifier_lock)
92+
93+
#define xe_svm_notifier_lock(vm__) \
94+
drm_gpusvm_notifier_lock(&(vm__)->svm.gpusvm)
95+
96+
#define xe_svm_notifier_unlock(vm__) \
97+
drm_gpusvm_notifier_unlock(&(vm__)->svm.gpusvm)
98+
7699
#else
100+
#include <linux/interval_tree.h>
101+
102+
struct drm_pagemap_device_addr;
103+
struct xe_bo;
104+
struct xe_gt;
105+
struct xe_vm;
106+
struct xe_vma;
107+
struct xe_tile;
108+
struct xe_vram_region;
109+
110+
#define XE_INTERCONNECT_VRAM 1
111+
112+
struct xe_svm_range {
113+
struct {
114+
struct interval_tree_node itree;
115+
const struct drm_pagemap_device_addr *dma_addr;
116+
} base;
117+
u32 tile_present;
118+
u32 tile_invalidated;
119+
};
120+
77121
static inline bool xe_svm_range_pages_valid(struct xe_svm_range *range)
78122
{
79123
return false;
@@ -125,27 +169,16 @@ static inline
125169
void xe_svm_range_debug(struct xe_svm_range *range, const char *operation)
126170
{
127171
}
128-
#endif
129172

130-
/**
131-
* xe_svm_range_has_dma_mapping() - SVM range has DMA mapping
132-
* @range: SVM range
133-
*
134-
* Return: True if SVM range has a DMA mapping, False otherwise
135-
*/
136-
static inline bool xe_svm_range_has_dma_mapping(struct xe_svm_range *range)
173+
#define xe_svm_assert_in_notifier(...) do {} while (0)
174+
#define xe_svm_range_has_dma_mapping(...) false
175+
176+
static inline void xe_svm_notifier_lock(struct xe_vm *vm)
137177
{
138-
lockdep_assert_held(&range->base.gpusvm->notifier_lock);
139-
return range->base.flags.has_dma_mapping;
140178
}
141179

142-
#define xe_svm_assert_in_notifier(vm__) \
143-
lockdep_assert_held_write(&(vm__)->svm.gpusvm.notifier_lock)
144-
145-
#define xe_svm_notifier_lock(vm__) \
146-
drm_gpusvm_notifier_lock(&(vm__)->svm.gpusvm)
147-
148-
#define xe_svm_notifier_unlock(vm__) \
149-
drm_gpusvm_notifier_unlock(&(vm__)->svm.gpusvm)
150-
180+
static inline void xe_svm_notifier_unlock(struct xe_vm *vm)
181+
{
182+
}
183+
#endif
151184
#endif

drivers/gpu/drm/xe/xe_vm.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3109,7 +3109,7 @@ static int vm_bind_ioctl_check_args(struct xe_device *xe, struct xe_vm *vm,
31093109

31103110
if (XE_IOCTL_DBG(xe, is_cpu_addr_mirror &&
31113111
(!xe_vm_in_fault_mode(vm) ||
3112-
!IS_ENABLED(CONFIG_DRM_GPUSVM)))) {
3112+
!IS_ENABLED(CONFIG_DRM_XE_GPUSVM)))) {
31133113
err = -EINVAL;
31143114
goto free_bind_ops;
31153115
}

0 commit comments

Comments
 (0)