Skip to content

Commit c082afa

Browse files
committed
drm/i915: Move aliasing_ppgtt underneath its i915_ggtt
The aliasing_ppgtt provides a PIN_USER alias for the global gtt, so move it under the i915_ggtt to simplify later transformations to enable intel_context.vm. Signed-off-by: Chris Wilson <[email protected]> Reviewed-by: Tvrtko Ursulin <[email protected]> Link: https://patchwork.freedesktop.org/patch/msgid/[email protected]
1 parent a562772 commit c082afa

File tree

7 files changed

+71
-51
lines changed

7 files changed

+71
-51
lines changed

drivers/gpu/drm/i915/gem/i915_gem_context.c

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -459,8 +459,7 @@ __create_context(struct drm_i915_private *i915)
459459
i915_gem_context_set_recoverable(ctx);
460460

461461
ctx->ring_size = 4 * PAGE_SIZE;
462-
ctx->desc_template =
463-
default_desc_template(i915, &i915->mm.aliasing_ppgtt->vm);
462+
ctx->desc_template = default_desc_template(i915, NULL);
464463

465464
for (i = 0; i < ARRAY_SIZE(ctx->hang_timestamp); i++)
466465
ctx->hang_timestamp[i] = jiffies - CONTEXT_FAST_HANG_JIFFIES;
@@ -2258,8 +2257,8 @@ int i915_gem_context_getparam_ioctl(struct drm_device *dev, void *data,
22582257
args->size = 0;
22592258
if (ctx->vm)
22602259
args->value = ctx->vm->total;
2261-
else if (to_i915(dev)->mm.aliasing_ppgtt)
2262-
args->value = to_i915(dev)->mm.aliasing_ppgtt->vm.total;
2260+
else if (to_i915(dev)->ggtt.alias)
2261+
args->value = to_i915(dev)->ggtt.alias->vm.total;
22632262
else
22642263
args->value = to_i915(dev)->ggtt.vm.total;
22652264
break;

drivers/gpu/drm/i915/gem/selftests/i915_gem_context.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1190,7 +1190,7 @@ static int igt_ctx_readonly(void *arg)
11901190
goto out_unlock;
11911191
}
11921192

1193-
vm = ctx->vm ?: &i915->mm.aliasing_ppgtt->vm;
1193+
vm = ctx->vm ?: &i915->ggtt.alias->vm;
11941194
if (!vm || !vm->has_read_only) {
11951195
err = 0;
11961196
goto out_unlock;

drivers/gpu/drm/i915/gt/intel_ringbuffer.c

Lines changed: 45 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1376,30 +1376,41 @@ static void ring_context_destroy(struct kref *ref)
13761376
intel_context_free(ce);
13771377
}
13781378

1379-
static int __context_pin_ppgtt(struct i915_gem_context *ctx)
1379+
static struct i915_address_space *vm_alias(struct intel_context *ce)
1380+
{
1381+
struct i915_address_space *vm;
1382+
1383+
vm = ce->gem_context->vm;
1384+
if (!vm)
1385+
vm = &ce->engine->gt->ggtt->alias->vm;
1386+
1387+
return vm;
1388+
}
1389+
1390+
static int __context_pin_ppgtt(struct intel_context *ce)
13801391
{
13811392
struct i915_address_space *vm;
13821393
int err = 0;
13831394

1384-
vm = ctx->vm ?: &ctx->i915->mm.aliasing_ppgtt->vm;
1395+
vm = vm_alias(ce);
13851396
if (vm)
13861397
err = gen6_ppgtt_pin(i915_vm_to_ppgtt((vm)));
13871398

13881399
return err;
13891400
}
13901401

1391-
static void __context_unpin_ppgtt(struct i915_gem_context *ctx)
1402+
static void __context_unpin_ppgtt(struct intel_context *ce)
13921403
{
13931404
struct i915_address_space *vm;
13941405

1395-
vm = ctx->vm ?: &ctx->i915->mm.aliasing_ppgtt->vm;
1406+
vm = vm_alias(ce);
13961407
if (vm)
13971408
gen6_ppgtt_unpin(i915_vm_to_ppgtt(vm));
13981409
}
13991410

14001411
static void ring_context_unpin(struct intel_context *ce)
14011412
{
1402-
__context_unpin_ppgtt(ce->gem_context);
1413+
__context_unpin_ppgtt(ce);
14031414
}
14041415

14051416
static struct i915_vma *
@@ -1493,7 +1504,7 @@ static int ring_context_pin(struct intel_context *ce)
14931504
if (err)
14941505
return err;
14951506

1496-
err = __context_pin_ppgtt(ce->gem_context);
1507+
err = __context_pin_ppgtt(ce);
14971508
if (err)
14981509
goto err_active;
14991510

@@ -1685,7 +1696,7 @@ static inline int mi_set_context(struct i915_request *rq, u32 flags)
16851696
return 0;
16861697
}
16871698

1688-
static int remap_l3(struct i915_request *rq, int slice)
1699+
static int remap_l3_slice(struct i915_request *rq, int slice)
16891700
{
16901701
u32 *cs, *remap_info = rq->i915->l3_parity.remap_info[slice];
16911702
int i;
@@ -1713,15 +1724,34 @@ static int remap_l3(struct i915_request *rq, int slice)
17131724
return 0;
17141725
}
17151726

1727+
static int remap_l3(struct i915_request *rq)
1728+
{
1729+
struct i915_gem_context *ctx = rq->gem_context;
1730+
int i, err;
1731+
1732+
if (!ctx->remap_slice)
1733+
return 0;
1734+
1735+
for (i = 0; i < MAX_L3_SLICES; i++) {
1736+
if (!(ctx->remap_slice & BIT(i)))
1737+
continue;
1738+
1739+
err = remap_l3_slice(rq, i);
1740+
if (err)
1741+
return err;
1742+
}
1743+
1744+
ctx->remap_slice = 0;
1745+
return 0;
1746+
}
1747+
17161748
static int switch_context(struct i915_request *rq)
17171749
{
17181750
struct intel_engine_cs *engine = rq->engine;
1719-
struct i915_gem_context *ctx = rq->gem_context;
1720-
struct i915_address_space *vm =
1721-
ctx->vm ?: &rq->i915->mm.aliasing_ppgtt->vm;
1751+
struct i915_address_space *vm = vm_alias(rq->hw_context);
17221752
unsigned int unwind_mm = 0;
17231753
u32 hw_flags = 0;
1724-
int ret, i;
1754+
int ret;
17251755

17261756
GEM_BUG_ON(HAS_EXECLISTS(rq->i915));
17271757

@@ -1765,7 +1795,7 @@ static int switch_context(struct i915_request *rq)
17651795
* as nothing actually executes using the kernel context; it
17661796
* is purely used for flushing user contexts.
17671797
*/
1768-
if (i915_gem_context_is_kernel(ctx))
1798+
if (i915_gem_context_is_kernel(rq->gem_context))
17691799
hw_flags = MI_RESTORE_INHIBIT;
17701800

17711801
ret = mi_set_context(rq, hw_flags);
@@ -1799,18 +1829,9 @@ static int switch_context(struct i915_request *rq)
17991829
goto err_mm;
18001830
}
18011831

1802-
if (ctx->remap_slice) {
1803-
for (i = 0; i < MAX_L3_SLICES; i++) {
1804-
if (!(ctx->remap_slice & BIT(i)))
1805-
continue;
1806-
1807-
ret = remap_l3(rq, i);
1808-
if (ret)
1809-
goto err_mm;
1810-
}
1811-
1812-
ctx->remap_slice = 0;
1813-
}
1832+
ret = remap_l3(rq);
1833+
if (ret)
1834+
goto err_mm;
18141835

18151836
return 0;
18161837

drivers/gpu/drm/i915/i915_drv.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -784,9 +784,6 @@ struct i915_gem_mm {
784784
*/
785785
struct vfsmount *gemfs;
786786

787-
/** PPGTT used for aliasing the PPGTT with the GTT */
788-
struct i915_ppgtt *aliasing_ppgtt;
789-
790787
struct notifier_block oom_notifier;
791788
struct notifier_block vmap_notifier;
792789
struct shrinker shrinker;

drivers/gpu/drm/i915/i915_gem_gtt.c

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -2446,18 +2446,18 @@ static int aliasing_gtt_bind_vma(struct i915_vma *vma,
24462446
pte_flags |= PTE_READ_ONLY;
24472447

24482448
if (flags & I915_VMA_LOCAL_BIND) {
2449-
struct i915_ppgtt *appgtt = i915->mm.aliasing_ppgtt;
2449+
struct i915_ppgtt *alias = i915_vm_to_ggtt(vma->vm)->alias;
24502450

24512451
if (!(vma->flags & I915_VMA_LOCAL_BIND)) {
2452-
ret = appgtt->vm.allocate_va_range(&appgtt->vm,
2453-
vma->node.start,
2454-
vma->size);
2452+
ret = alias->vm.allocate_va_range(&alias->vm,
2453+
vma->node.start,
2454+
vma->size);
24552455
if (ret)
24562456
return ret;
24572457
}
24582458

2459-
appgtt->vm.insert_entries(&appgtt->vm, vma, cache_level,
2460-
pte_flags);
2459+
alias->vm.insert_entries(&alias->vm, vma,
2460+
cache_level, pte_flags);
24612461
}
24622462

24632463
if (flags & I915_VMA_GLOBAL_BIND) {
@@ -2485,7 +2485,8 @@ static void aliasing_gtt_unbind_vma(struct i915_vma *vma)
24852485
}
24862486

24872487
if (vma->flags & I915_VMA_LOCAL_BIND) {
2488-
struct i915_address_space *vm = &i915->mm.aliasing_ppgtt->vm;
2488+
struct i915_address_space *vm =
2489+
&i915_vm_to_ggtt(vma->vm)->alias->vm;
24892490

24902491
vm->clear_range(vm, vma->node.start, vma->size);
24912492
}
@@ -2542,13 +2543,12 @@ static void i915_gtt_color_adjust(const struct drm_mm_node *node,
25422543
*end -= I915_GTT_PAGE_SIZE;
25432544
}
25442545

2545-
static int init_aliasing_ppgtt(struct drm_i915_private *i915)
2546+
static int init_aliasing_ppgtt(struct i915_ggtt *ggtt)
25462547
{
2547-
struct i915_ggtt *ggtt = &i915->ggtt;
25482548
struct i915_ppgtt *ppgtt;
25492549
int err;
25502550

2551-
ppgtt = i915_ppgtt_create(i915);
2551+
ppgtt = i915_ppgtt_create(ggtt->vm.i915);
25522552
if (IS_ERR(ppgtt))
25532553
return PTR_ERR(ppgtt);
25542554

@@ -2567,7 +2567,7 @@ static int init_aliasing_ppgtt(struct drm_i915_private *i915)
25672567
if (err)
25682568
goto err_ppgtt;
25692569

2570-
i915->mm.aliasing_ppgtt = ppgtt;
2570+
ggtt->alias = ppgtt;
25712571

25722572
GEM_BUG_ON(ggtt->vm.vma_ops.bind_vma != ggtt_bind_vma);
25732573
ggtt->vm.vma_ops.bind_vma = aliasing_gtt_bind_vma;
@@ -2582,14 +2582,14 @@ static int init_aliasing_ppgtt(struct drm_i915_private *i915)
25822582
return err;
25832583
}
25842584

2585-
static void fini_aliasing_ppgtt(struct drm_i915_private *i915)
2585+
static void fini_aliasing_ppgtt(struct i915_ggtt *ggtt)
25862586
{
2587-
struct i915_ggtt *ggtt = &i915->ggtt;
2587+
struct drm_i915_private *i915 = ggtt->vm.i915;
25882588
struct i915_ppgtt *ppgtt;
25892589

25902590
mutex_lock(&i915->drm.struct_mutex);
25912591

2592-
ppgtt = fetch_and_zero(&i915->mm.aliasing_ppgtt);
2592+
ppgtt = fetch_and_zero(&ggtt->alias);
25932593
if (!ppgtt)
25942594
goto out;
25952595

@@ -2706,7 +2706,7 @@ int i915_init_ggtt(struct drm_i915_private *i915)
27062706
return ret;
27072707

27082708
if (INTEL_PPGTT(i915) == INTEL_PPGTT_ALIASING) {
2709-
ret = init_aliasing_ppgtt(i915);
2709+
ret = init_aliasing_ppgtt(&i915->ggtt);
27102710
if (ret)
27112711
cleanup_init_ggtt(&i915->ggtt);
27122712
}
@@ -2755,7 +2755,7 @@ void i915_ggtt_driver_release(struct drm_i915_private *i915)
27552755
{
27562756
struct pagevec *pvec;
27572757

2758-
fini_aliasing_ppgtt(i915);
2758+
fini_aliasing_ppgtt(&i915->ggtt);
27592759

27602760
ggtt_cleanup_hw(&i915->ggtt);
27612761

@@ -3588,7 +3588,7 @@ int i915_gem_gtt_reserve(struct i915_address_space *vm,
35883588
GEM_BUG_ON(!IS_ALIGNED(size, I915_GTT_PAGE_SIZE));
35893589
GEM_BUG_ON(!IS_ALIGNED(offset, I915_GTT_MIN_ALIGNMENT));
35903590
GEM_BUG_ON(range_overflows(offset, size, vm->total));
3591-
GEM_BUG_ON(vm == &vm->i915->mm.aliasing_ppgtt->vm);
3591+
GEM_BUG_ON(vm == &vm->i915->ggtt.alias->vm);
35923592
GEM_BUG_ON(drm_mm_node_allocated(node));
35933593

35943594
node->size = size;
@@ -3685,7 +3685,7 @@ int i915_gem_gtt_insert(struct i915_address_space *vm,
36853685
GEM_BUG_ON(start >= end);
36863686
GEM_BUG_ON(start > 0 && !IS_ALIGNED(start, I915_GTT_PAGE_SIZE));
36873687
GEM_BUG_ON(end < U64_MAX && !IS_ALIGNED(end, I915_GTT_PAGE_SIZE));
3688-
GEM_BUG_ON(vm == &vm->i915->mm.aliasing_ppgtt->vm);
3688+
GEM_BUG_ON(vm == &vm->i915->ggtt.alias->vm);
36893689
GEM_BUG_ON(drm_mm_node_allocated(node));
36903690

36913691
if (unlikely(range_overflows(start, size, end)))

drivers/gpu/drm/i915/i915_gem_gtt.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -394,6 +394,9 @@ struct i915_ggtt {
394394
void __iomem *gsm;
395395
void (*invalidate)(struct i915_ggtt *ggtt);
396396

397+
/** PPGTT used for aliasing the PPGTT with the GTT */
398+
struct i915_ppgtt *alias;
399+
397400
bool do_idle_maps;
398401

399402
int mtrr;

drivers/gpu/drm/i915/i915_vma.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ vma_create(struct drm_i915_gem_object *obj,
104104
struct rb_node *rb, **p;
105105

106106
/* The aliasing_ppgtt should never be used directly! */
107-
GEM_BUG_ON(vm == &vm->i915->mm.aliasing_ppgtt->vm);
107+
GEM_BUG_ON(vm == &vm->i915->ggtt.alias->vm);
108108

109109
vma = i915_vma_alloc();
110110
if (vma == NULL)

0 commit comments

Comments
 (0)