-
-
Save mthierry/2e2f64afa7c4380a9c898ed0a6f37d03 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
commit 8cc7a88e3430e3dbc0a5c873c467ee9fed729cfd | |
Author: Akash Goel <[email protected]> | |
Date: Mon Dec 28 13:56:18 2015 +0530 | |
drm/i915: Support to enable TRTT on GEN9 | |
Gen9 has an additional address translation hardware support in form of | |
Tiled Resource Translation Table (TR-TT) which provides an extra level | |
of abstraction over PPGTT. | |
This is useful for mapping Sparse/Tiled texture resources. | |
Sparse resources are created as virtual-only allocations. Regions of the | |
resource that the application intends to use is bound to the physical memory | |
on the fly and can be re-bound to different memory allocations over the | |
lifetime of the resource. | |
TR-TT is tightly coupled with PPGTT, a new instance of TR-TT will be required | |
for a new PPGTT instance, but TR-TT may not enabled for every context. | |
1/16th of the 48bit PPGTT space is earmarked for the translation by TR-TT, | |
which such chunk to use is conveyed to HW through a register. | |
Any GFX address, which lies in that reserved 44 bit range will be translated | |
through TR-TT first and then through PPGTT to get the actual physical address, | |
so the output of translation from TR-TT will be a PPGTT offset. | |
TRTT is constructed as a 3 level tile Table. Each tile is 64KB is size which | |
leaves behind 44-16=28 address bits. 28bits are partitioned as 9+9+10, and | |
each level is contained within a 4KB page hence L3 and L2 is composed of | |
512 64b entries and L1 is composed of 1024 32b entries. | |
There is a provision to keep TR-TT Tables in virtual space, where the pages of | |
TRTT tables will be mapped to PPGTT. | |
Currently this is the supported mode, in this mode UMD will have a full control | |
on TR-TT management, with bare minimum support from KMD. | |
So the entries of L3 table will contain the PPGTT offset of L2 Table pages, | |
similarly entries of L2 table will contain the PPGTT offset of L1 Table pages. | |
The entries of L1 table will contain the PPGTT offset of BOs actually backing | |
the Sparse resources. | |
UMD will have to allocate the L3/L2/L1 table pages as a regular BO only & | |
assign them a PPGTT address through the Soft Pin API (for example, use soft pin | |
to assign l3_table_address to the L3 table BO, when used). | |
UMD will also program the entries in the TR-TT page tables using regular batch | |
commands (MI_STORE_DATA_IMM), or via mmapping of the page table BOs. | |
UMD may do the complete PPGTT address space management, on the pretext that it | |
could help minimize the conflicts. | |
Any space in TR-TT segment not bound to any Sparse texture, will be handled | |
through Invalid tile, User is expected to initialize the entries of a new | |
L3/L2/L1 table page with the Invalid tile pattern. The entries corresponding to | |
the holes in the Sparse texture resource will be set with the Null tile pattern | |
The improper programming of TRTT should only lead to a recoverable GPU hang, | |
eventually leading to banning of the culprit context without victimizing others. | |
The association of any Sparse resource with the BOs will be known only to UMD, | |
and only the Sparse resources shall be assigned an offset from the TR-TT segment | |
by UMD. The use of TR-TT segment or mapping of Sparse resources will be | |
transparent to the KMD, UMD will do the address assignment from TR-TT segment | |
autonomously and KMD will be oblivious of it. | |
Any object must not be assigned an address from TR-TT segment, they will be | |
mapped to PPGTT in a regular way by KMD. | |
This patch provides an interface through which UMD can convey KMD to enable | |
TR-TT for a given context. A new I915_CONTEXT_PARAM_TRTT param has been | |
added to I915_GEM_CONTEXT_SETPARAM ioctl for that purpose. | |
UMD will have to pass the GFX address of L3 table page, start location of TR-TT | |
segment alongwith the pattern value for the Null & invalid Tile registers. | |
v2: | |
- Support context_getparam for TRTT also and dispense with a separate | |
GETPARAM case for TRTT (Chris). | |
- Use i915_dbg to log errors for the invalid TRTT ABI parameters passed | |
from user space (Chris). | |
- Move all the argument checking for TRTT in context_setparam to the | |
set_trtt function (Chris). | |
- Change the type of 'flags' field inside 'intel_context' to unsigned (Chris) | |
- Rename certain functions to rightly reflect their purpose, rename | |
the new param for TRTT in gem_context_param to I915_CONTEXT_PARAM_TRTT, | |
rephrase few lines in the commit message body, add more comments (Chris). | |
- Extend ABI to allow User specify TRTT segment location also. | |
- Fix for selective enabling of TRTT on per context basis, explicitly | |
disable TR-TT at the start of a new context. | |
v3: | |
- Check the return value of gen9_emit_trtt_regs (Chris) | |
- Update the kernel doc for intel_context structure. | |
- Rebased. | |
v4: | |
- Fix the warnings reported by 'checkpatch.pl --strict' (Michel) | |
- Fix the context_getparam implementation avoiding the reset of size field, | |
affecting the TRTT case. | |
v5: | |
- Update the TR-TT params right away in context_setparam, by constructing | |
& submitting a request emitting LRIs, instead of deferring it and | |
conflating with the next batch submission (Chris) | |
- Follow the struct_mutex handling related prescribed rules, while accessing | |
User space buffer, both in context_setparam & getparam functions (Chris). | |
v6: | |
- Fix the warning caused due to removal of un-allocated trtt vma node. | |
v7: | |
- Move context ref/unref to context_setparam_ioctl from set_trtt() & remove | |
that from get_trtt() as not really needed there (Chris). | |
- Add a check for improper values for Null & Invalid Tiles. | |
- Remove superfluous DRM_ERROR from trtt_context_allocate_vma (Chris). | |
- Rebased. | |
v8: | |
- Add context ref/unref to context_getparam_ioctl also so as to be consistent | |
and ease the extension of ioctl in future (Chris) | |
v9: | |
- Fix the handling of return value from trtt_context_allocate_vma() function, | |
causing kernel panic at the time of destroying context, in case of | |
unsuccessful allocation of trtt vma. | |
- Rebased. | |
v10: | |
- Rebased. | |
v11: | |
- Rebased (intel_ring_emit gone). | |
v12: | |
- Rebased (i915_add_request_no_flush gone). | |
Testcase: igt/gem_trtt | |
Cc: Chris Wilson <[email protected]> | |
Cc: Michel Thierry <[email protected]> | |
Signed-off-by: Akash Goel <[email protected]> | |
Reviewed-by: Chris Wilson <[email protected]> | |
Signed-off-by: Michel Thierry <[email protected]> | |
diff --git a/drivers/gpu/drm/i915/i915_drv.h b/drivers/gpu/drm/i915/i915_drv.h | |
index 37c3522e9389..b15e5d9ad243 100644 | |
--- a/drivers/gpu/drm/i915/i915_drv.h | |
+++ b/drivers/gpu/drm/i915/i915_drv.h | |
@@ -775,6 +775,7 @@ struct intel_csr { | |
func(has_resource_streamer); \ | |
func(has_runtime_pm); \ | |
func(has_snoop); \ | |
+ func(has_trtt); \ | |
func(unfenced_needs_alignment); \ | |
func(cursor_needs_physical); \ | |
func(hws_needs_physical); \ | |
@@ -2986,6 +2987,8 @@ intel_info(const struct drm_i915_private *dev_priv) | |
#define HAS_POOLED_EU(dev_priv) ((dev_priv)->info.has_pooled_eu) | |
+#define HAS_TRTT(dev) (INTEL_INFO(dev)->has_trtt) | |
+ | |
#define INTEL_PCH_DEVICE_ID_MASK 0xff00 | |
#define INTEL_PCH_DEVICE_ID_MASK_EXT 0xff80 | |
#define INTEL_PCH_IBX_DEVICE_ID_TYPE 0x3b00 | |
diff --git a/drivers/gpu/drm/i915/i915_gem_context.c b/drivers/gpu/drm/i915/i915_gem_context.c | |
index a56e79430082..3afaeaf19b95 100644 | |
--- a/drivers/gpu/drm/i915/i915_gem_context.c | |
+++ b/drivers/gpu/drm/i915/i915_gem_context.c | |
@@ -92,6 +92,14 @@ | |
#define ALL_L3_SLICES(dev) (1 << NUM_L3_SLICES(dev)) - 1 | |
+static void intel_context_free_trtt(struct i915_gem_context *ctx) | |
+{ | |
+ if (!ctx->trtt_info.vma) | |
+ return; | |
+ | |
+ intel_trtt_context_destroy_vma(ctx->trtt_info.vma); | |
+} | |
+ | |
void i915_gem_context_free(struct kref *ctx_ref) | |
{ | |
struct i915_gem_context *ctx = container_of(ctx_ref, typeof(*ctx), ref); | |
@@ -101,6 +109,7 @@ void i915_gem_context_free(struct kref *ctx_ref) | |
trace_i915_context_free(ctx); | |
GEM_BUG_ON(!i915_gem_context_is_closed(ctx)); | |
+ intel_context_free_trtt(ctx); | |
i915_ppgtt_put(ctx->ppgtt); | |
for (i = 0; i < I915_NUM_ENGINES; i++) { | |
@@ -564,6 +573,129 @@ void i915_gem_context_close(struct drm_device *dev, struct drm_file *file) | |
idr_destroy(&file_priv->context_idr); | |
} | |
+static int | |
+intel_context_get_trtt(struct i915_gem_context *ctx, | |
+ struct drm_i915_gem_context_param *args) | |
+{ | |
+ struct drm_i915_gem_context_trtt_param trtt_params; | |
+ struct drm_i915_private *dev_priv = ctx->i915; | |
+ | |
+ if (!HAS_TRTT(dev_priv) || !USES_FULL_48BIT_PPGTT(dev_priv)) { | |
+ return -ENODEV; | |
+ } else if (args->size < sizeof(trtt_params)) { | |
+ args->size = sizeof(trtt_params); | |
+ } else { | |
+ trtt_params.segment_base_addr = | |
+ ctx->trtt_info.segment_base_addr; | |
+ trtt_params.l3_table_address = | |
+ ctx->trtt_info.l3_table_address; | |
+ trtt_params.null_tile_val = | |
+ ctx->trtt_info.null_tile_val; | |
+ trtt_params.invd_tile_val = | |
+ ctx->trtt_info.invd_tile_val; | |
+ | |
+ mutex_unlock(&dev_priv->drm.struct_mutex); | |
+ | |
+ if (__copy_to_user(u64_to_user_ptr(args->value), | |
+ &trtt_params, | |
+ sizeof(trtt_params))) { | |
+ mutex_lock(&dev_priv->drm.struct_mutex); | |
+ return -EFAULT; | |
+ } | |
+ | |
+ args->size = sizeof(trtt_params); | |
+ mutex_lock(&dev_priv->drm.struct_mutex); | |
+ } | |
+ | |
+ return 0; | |
+} | |
+ | |
+static int | |
+intel_context_set_trtt(struct i915_gem_context *ctx, | |
+ struct drm_i915_gem_context_param *args) | |
+{ | |
+ struct drm_i915_gem_context_trtt_param trtt_params; | |
+ struct i915_vma *vma; | |
+ struct drm_i915_private *dev_priv = ctx->i915; | |
+ int ret; | |
+ | |
+ if (!HAS_TRTT(dev_priv) || !USES_FULL_48BIT_PPGTT(dev_priv)) | |
+ return -ENODEV; | |
+ else if (i915_gem_context_use_trtt(ctx)) | |
+ return -EEXIST; | |
+ else if (args->size < sizeof(trtt_params)) | |
+ return -EINVAL; | |
+ | |
+ mutex_unlock(&dev_priv->drm.struct_mutex); | |
+ | |
+ if (copy_from_user(&trtt_params, | |
+ u64_to_user_ptr(args->value), | |
+ sizeof(trtt_params))) { | |
+ mutex_lock(&dev_priv->drm.struct_mutex); | |
+ ret = -EFAULT; | |
+ goto exit; | |
+ } | |
+ | |
+ mutex_lock(&dev_priv->drm.struct_mutex); | |
+ | |
+ /* Check if the setup happened from another path */ | |
+ if (i915_gem_context_use_trtt(ctx)) { | |
+ ret = -EEXIST; | |
+ goto exit; | |
+ } | |
+ | |
+ /* basic sanity checks for the segment location & l3 table pointer */ | |
+ if (trtt_params.segment_base_addr & (GEN9_TRTT_SEGMENT_SIZE - 1)) { | |
+ DRM_DEBUG_DRIVER("segment base address not correctly aligned\n"); | |
+ ret = -EINVAL; | |
+ goto exit; | |
+ } | |
+ | |
+ if (((trtt_params.l3_table_address + PAGE_SIZE) >= | |
+ trtt_params.segment_base_addr) && | |
+ (trtt_params.l3_table_address < | |
+ (trtt_params.segment_base_addr + GEN9_TRTT_SEGMENT_SIZE))) { | |
+ DRM_DEBUG_DRIVER("l3 table address conflicts with trtt segment\n"); | |
+ ret = -EINVAL; | |
+ goto exit; | |
+ } | |
+ | |
+ if (trtt_params.l3_table_address & ~GEN9_TRTT_L3_GFXADDR_MASK) { | |
+ DRM_DEBUG_DRIVER("invalid l3 table address\n"); | |
+ ret = -EINVAL; | |
+ goto exit; | |
+ } | |
+ | |
+ if (trtt_params.null_tile_val == trtt_params.invd_tile_val) { | |
+ DRM_DEBUG_DRIVER("incorrect values for null & invalid tiles\n"); | |
+ return -EINVAL; | |
+ } | |
+ | |
+ vma = intel_trtt_context_allocate_vma(&ctx->ppgtt->base, | |
+ trtt_params.segment_base_addr); | |
+ if (IS_ERR(vma)) { | |
+ ret = PTR_ERR(vma); | |
+ goto exit; | |
+ } | |
+ | |
+ ctx->trtt_info.vma = vma; | |
+ ctx->trtt_info.null_tile_val = trtt_params.null_tile_val; | |
+ ctx->trtt_info.invd_tile_val = trtt_params.invd_tile_val; | |
+ ctx->trtt_info.l3_table_address = trtt_params.l3_table_address; | |
+ ctx->trtt_info.segment_base_addr = trtt_params.segment_base_addr; | |
+ | |
+ ret = intel_lr_rcs_context_setup_trtt(ctx); | |
+ if (ret) { | |
+ intel_trtt_context_destroy_vma(ctx->trtt_info.vma); | |
+ goto exit; | |
+ } | |
+ | |
+ i915_gem_context_set_trtt(ctx); | |
+ | |
+exit: | |
+ return ret; | |
+} | |
+ | |
static inline int | |
mi_set_context(struct drm_i915_gem_request *req, u32 flags) | |
{ | |
@@ -1024,7 +1156,14 @@ int i915_gem_context_getparam_ioctl(struct drm_device *dev, void *data, | |
return PTR_ERR(ctx); | |
} | |
- args->size = 0; | |
+ /* | |
+ * Take a reference also, as in certain cases we have to release & | |
+ * reacquire the struct_mutex and we don't want the context to | |
+ * go away. | |
+ */ | |
+ i915_gem_context_get(ctx); | |
+ | |
+ args->size = (args->param != I915_CONTEXT_PARAM_TRTT) ? 0 : args->size; | |
switch (args->param) { | |
case I915_CONTEXT_PARAM_BAN_PERIOD: | |
ret = -EINVAL; | |
@@ -1049,10 +1188,14 @@ int i915_gem_context_getparam_ioctl(struct drm_device *dev, void *data, | |
case I915_CONTEXT_PARAM_WATCHDOG: | |
ret = i915_gem_context_get_watchdog(ctx, args); | |
break; | |
+ case I915_CONTEXT_PARAM_TRTT: | |
+ ret = intel_context_get_trtt(ctx, args); | |
+ break; | |
default: | |
ret = -EINVAL; | |
break; | |
} | |
+ i915_gem_context_put(ctx); | |
mutex_unlock(&dev->struct_mutex); | |
return ret; | |
@@ -1076,6 +1219,13 @@ int i915_gem_context_setparam_ioctl(struct drm_device *dev, void *data, | |
return PTR_ERR(ctx); | |
} | |
+ /* | |
+ * Take a reference also, as in certain cases we have to release & | |
+ * reacquire the struct_mutex and we don't want the context to | |
+ * go away. | |
+ */ | |
+ i915_gem_context_get(ctx); | |
+ | |
switch (args->param) { | |
case I915_CONTEXT_PARAM_BAN_PERIOD: | |
ret = -EINVAL; | |
@@ -1109,10 +1259,14 @@ int i915_gem_context_setparam_ioctl(struct drm_device *dev, void *data, | |
case I915_CONTEXT_PARAM_WATCHDOG: | |
ret = i915_gem_context_set_watchdog(ctx, args); | |
break; | |
+ case I915_CONTEXT_PARAM_TRTT: | |
+ ret = intel_context_set_trtt(ctx, args); | |
+ break; | |
default: | |
ret = -EINVAL; | |
break; | |
} | |
+ i915_gem_context_put(ctx); | |
mutex_unlock(&dev->struct_mutex); | |
return ret; | |
diff --git a/drivers/gpu/drm/i915/i915_gem_context.h b/drivers/gpu/drm/i915/i915_gem_context.h | |
index 88700bdbb4e1..737660efce5c 100644 | |
--- a/drivers/gpu/drm/i915/i915_gem_context.h | |
+++ b/drivers/gpu/drm/i915/i915_gem_context.h | |
@@ -108,6 +108,7 @@ struct i915_gem_context { | |
#define CONTEXT_BANNABLE 3 | |
#define CONTEXT_BANNED 4 | |
#define CONTEXT_FORCE_SINGLE_SUBMISSION 5 | |
+#define CONTEXT_USE_TRTT 6 | |
/** | |
* @hw_id: - unique identifier for the context | |
@@ -157,6 +158,18 @@ struct i915_gem_context { | |
bool initialised; | |
} engine[I915_NUM_ENGINES]; | |
+ /** | |
+ * @trtt_info: Programming parameters for tr-tt (redirection tables | |
+ * for userspace, for sparse resource management). | |
+ */ | |
+ struct intel_context_trtt { | |
+ u32 invd_tile_val; | |
+ u32 null_tile_val; | |
+ u64 l3_table_address; | |
+ u64 segment_base_addr; | |
+ struct i915_vma *vma; | |
+ } trtt_info; | |
+ | |
/** ring_size: size for allocating the per-engine ring buffer */ | |
u32 ring_size; | |
/** desc_template: invariant fields for the HW context descriptor */ | |
@@ -240,6 +253,16 @@ static inline void i915_gem_context_set_force_single_submission(struct i915_gem_ | |
__set_bit(CONTEXT_FORCE_SINGLE_SUBMISSION, &ctx->flags); | |
} | |
+static inline bool i915_gem_context_use_trtt(const struct i915_gem_context *ctx) | |
+{ | |
+ return test_bit(CONTEXT_USE_TRTT, &ctx->flags); | |
+} | |
+ | |
+static inline void i915_gem_context_set_trtt(struct i915_gem_context *ctx) | |
+{ | |
+ __set_bit(CONTEXT_USE_TRTT, &ctx->flags); | |
+} | |
+ | |
static inline bool i915_gem_context_is_default(const struct i915_gem_context *c) | |
{ | |
return c->user_handle == DEFAULT_CONTEXT_HANDLE; | |
diff --git a/drivers/gpu/drm/i915/i915_gem_gtt.c b/drivers/gpu/drm/i915/i915_gem_gtt.c | |
index 4ff854e6413c..cfbc1c47aab8 100644 | |
--- a/drivers/gpu/drm/i915/i915_gem_gtt.c | |
+++ b/drivers/gpu/drm/i915/i915_gem_gtt.c | |
@@ -1899,6 +1899,16 @@ int i915_ppgtt_init_hw(struct drm_i915_private *dev_priv) | |
{ | |
gtt_write_workarounds(dev_priv); | |
+ if (HAS_TRTT(dev_priv) && USES_FULL_48BIT_PPGTT(dev_priv)) { | |
+ /* | |
+ * Globally enable TR-TT support in Hw. | |
+ * Still TR-TT enabling on per context basis is required. | |
+ * Non-trtt contexts are not affected by this setting. | |
+ */ | |
+ I915_WRITE(GEN9_TR_CHICKEN_BIT_VECTOR, | |
+ GEN9_TRTT_BYPASS_DISABLE); | |
+ } | |
+ | |
/* In the case of execlists, PPGTT is enabled by the context descriptor | |
* and the PDPs are contained within the context itself. We don't | |
* need to do anything here. */ | |
@@ -3171,6 +3181,56 @@ void i915_gem_restore_gtt_mappings(struct drm_i915_private *dev_priv) | |
i915_ggtt_invalidate(dev_priv); | |
} | |
+void intel_trtt_context_destroy_vma(struct i915_vma *vma) | |
+{ | |
+ WARN_ON(!list_empty(&vma->obj_link)); | |
+ WARN_ON(!list_empty(&vma->vm_link)); | |
+ WARN_ON(!list_empty(&vma->exec_list)); | |
+ | |
+ WARN_ON(!i915_vma_is_pinned(vma)); | |
+ | |
+ if (drm_mm_node_allocated(&vma->node)) | |
+ drm_mm_remove_node(&vma->node); | |
+ | |
+ i915_ppgtt_put(i915_vm_to_ppgtt(vma->vm)); | |
+ kmem_cache_free(vma->vm->i915->vmas, vma); | |
+} | |
+ | |
+struct i915_vma * | |
+intel_trtt_context_allocate_vma(struct i915_address_space *vm, | |
+ uint64_t segment_base_addr) | |
+{ | |
+ struct i915_vma *vma; | |
+ int ret; | |
+ | |
+ GEM_BUG_ON(vm->closed); | |
+ | |
+ vma = kmem_cache_zalloc(vm->i915->vmas, GFP_KERNEL); | |
+ if (!vma) | |
+ return ERR_PTR(-ENOMEM); | |
+ | |
+ INIT_LIST_HEAD(&vma->obj_link); | |
+ INIT_LIST_HEAD(&vma->vm_link); | |
+ INIT_LIST_HEAD(&vma->exec_list); | |
+ vma->vm = vm; | |
+ i915_ppgtt_get(i915_vm_to_ppgtt(vm)); | |
+ | |
+ /* Mark the vma as permanently pinned */ | |
+ __i915_vma_pin(vma); | |
+ | |
+ /* Reserve from the 48 bit PPGTT space */ | |
+ vma->size = GEN9_TRTT_SEGMENT_SIZE; | |
+ ret = i915_gem_gtt_reserve(vma->vm, &vma->node, | |
+ GEN9_TRTT_SEGMENT_SIZE, segment_base_addr, | |
+ vma->node.color, 0); | |
+ if (ret) { | |
+ intel_trtt_context_destroy_vma(vma); | |
+ return ERR_PTR(ret); | |
+ } | |
+ | |
+ return vma; | |
+} | |
+ | |
static struct scatterlist * | |
rotate_pages(const dma_addr_t *in, unsigned int offset, | |
unsigned int width, unsigned int height, | |
diff --git a/drivers/gpu/drm/i915/i915_gem_gtt.h b/drivers/gpu/drm/i915/i915_gem_gtt.h | |
index da9aa9f706e7..08b1875e6376 100644 | |
--- a/drivers/gpu/drm/i915/i915_gem_gtt.h | |
+++ b/drivers/gpu/drm/i915/i915_gem_gtt.h | |
@@ -143,6 +143,10 @@ typedef u64 gen8_ppgtt_pml4e_t; | |
#define GEN8_PPAT_ELLC_OVERRIDE (0<<2) | |
#define GEN8_PPAT(i, x) ((u64)(x) << ((i) * 8)) | |
+/* Fixed size segment */ | |
+#define GEN9_TRTT_SEG_SIZE_SHIFT 44 | |
+#define GEN9_TRTT_SEGMENT_SIZE (1ULL << GEN9_TRTT_SEG_SIZE_SHIFT) | |
+ | |
struct sg_table; | |
struct intel_rotation_info { | |
@@ -600,4 +604,8 @@ int i915_gem_gtt_insert(struct i915_address_space *vm, | |
#define PIN_OFFSET_FIXED BIT(11) | |
#define PIN_OFFSET_MASK (-I915_GTT_PAGE_SIZE) | |
+struct i915_vma * | |
+intel_trtt_context_allocate_vma(struct i915_address_space *vm, | |
+ uint64_t segment_base_addr); | |
+void intel_trtt_context_destroy_vma(struct i915_vma *vma); | |
#endif | |
diff --git a/drivers/gpu/drm/i915/i915_pci.c b/drivers/gpu/drm/i915/i915_pci.c | |
index 537c1d56ecef..d51867c22b7a 100644 | |
--- a/drivers/gpu/drm/i915/i915_pci.c | |
+++ b/drivers/gpu/drm/i915/i915_pci.c | |
@@ -355,6 +355,7 @@ static const struct intel_device_info intel_skylake_info = { | |
.gen = 9, | |
.has_csr = 1, | |
.has_guc = 1, | |
+ .has_trtt = 1, | |
.ddb_size = 896, | |
}; | |
@@ -364,6 +365,7 @@ static const struct intel_device_info intel_skylake_gt3_info = { | |
.gen = 9, | |
.has_csr = 1, | |
.has_guc = 1, | |
+ .has_trtt = 1, | |
.ddb_size = 896, | |
.ring_mask = RENDER_RING | BSD_RING | BLT_RING | VEBOX_RING | BSD2_RING, | |
}; | |
@@ -399,6 +401,7 @@ static const struct intel_device_info intel_broxton_info = { | |
GEN9_LP_FEATURES, | |
.platform = INTEL_BROXTON, | |
.ddb_size = 512, | |
+ .has_trtt = 1, | |
}; | |
static const struct intel_device_info intel_geminilake_info = { | |
diff --git a/drivers/gpu/drm/i915/i915_reg.h b/drivers/gpu/drm/i915/i915_reg.h | |
index 1d35be1382b6..1085294f447f 100644 | |
--- a/drivers/gpu/drm/i915/i915_reg.h | |
+++ b/drivers/gpu/drm/i915/i915_reg.h | |
@@ -226,6 +226,25 @@ static inline bool i915_mmio_reg_valid(i915_reg_t reg) | |
#define GEN8_RPCS_EU_MIN_SHIFT 0 | |
#define GEN8_RPCS_EU_MIN_MASK (0xf << GEN8_RPCS_EU_MIN_SHIFT) | |
+#define GEN9_TR_CHICKEN_BIT_VECTOR _MMIO(0x4DFC) | |
+#define GEN9_TRTT_BYPASS_DISABLE (1 << 0) | |
+ | |
+/* TRTT registers in the H/W Context */ | |
+#define GEN9_TRTT_L3_POINTER_DW0 _MMIO(0x4DE0) | |
+#define GEN9_TRTT_L3_POINTER_DW1 _MMIO(0x4DE4) | |
+#define GEN9_TRTT_L3_GFXADDR_MASK 0xFFFFFFFF0000 | |
+ | |
+#define GEN9_TRTT_NULL_TILE_REG _MMIO(0x4DE8) | |
+#define GEN9_TRTT_INVD_TILE_REG _MMIO(0x4DEC) | |
+ | |
+#define GEN9_TRTT_VA_MASKDATA _MMIO(0x4DF0) | |
+#define GEN9_TRVA_MASK_VALUE 0xF0 | |
+#define GEN9_TRVA_DATA_MASK 0xF | |
+ | |
+#define GEN9_TRTT_TABLE_CONTROL _MMIO(0x4DF4) | |
+#define GEN9_TRTT_IN_GFX_VA_SPACE (1 << 1) | |
+#define GEN9_TRTT_ENABLE (1 << 0) | |
+ | |
#define GAM_ECOCHK _MMIO(0x4090) | |
#define BDW_DISABLE_HDC_INVALIDATION (1<<25) | |
#define ECOCHK_SNB_BIT (1<<10) | |
diff --git a/drivers/gpu/drm/i915/intel_lrc.c b/drivers/gpu/drm/i915/intel_lrc.c | |
index 5765b6d7da26..cd5d6b7fd285 100644 | |
--- a/drivers/gpu/drm/i915/intel_lrc.c | |
+++ b/drivers/gpu/drm/i915/intel_lrc.c | |
@@ -1733,6 +1733,91 @@ static int gen8_init_rcs_context(struct drm_i915_gem_request *req) | |
return i915_gem_render_state_emit(req); | |
} | |
+static int gen9_init_rcs_context_trtt(struct drm_i915_gem_request *req) | |
+{ | |
+ u32 *cs; | |
+ | |
+ cs = intel_ring_begin(req, 2 + 2); | |
+ if (IS_ERR(cs)) | |
+ return PTR_ERR(cs); | |
+ | |
+ *cs++ = MI_LOAD_REGISTER_IMM(1); | |
+ | |
+ *cs++ = i915_mmio_reg_offset(GEN9_TRTT_TABLE_CONTROL); | |
+ *cs++ = 0; | |
+ | |
+ *cs++ = MI_NOOP; | |
+ intel_ring_advance(req, cs); | |
+ | |
+ return 0; | |
+} | |
+ | |
+static int gen9_init_rcs_context(struct drm_i915_gem_request *req) | |
+{ | |
+ int ret; | |
+ | |
+ /* | |
+ * Explictily disable TR-TT at the start of a new context. | |
+ * Otherwise on switching from a TR-TT context to a new Non TR-TT | |
+ * context the TR-TT settings of the outgoing context could get | |
+ * spilled on to the new incoming context as only the Ring Context | |
+ * part is loaded on the first submission of a new context, due to | |
+ * the setting of ENGINE_CTX_RESTORE_INHIBIT bit. | |
+ */ | |
+ ret = gen9_init_rcs_context_trtt(req); | |
+ if (ret) | |
+ return ret; | |
+ | |
+ return gen8_init_rcs_context(req); | |
+} | |
+ | |
+static int gen9_emit_trtt_regs(struct drm_i915_gem_request *req) | |
+{ | |
+ struct i915_gem_context *ctx = req->ctx; | |
+ u64 masked_l3_gfx_address = | |
+ ctx->trtt_info.l3_table_address & GEN9_TRTT_L3_GFXADDR_MASK; | |
+ u32 trva_data_value = | |
+ (ctx->trtt_info.segment_base_addr >> GEN9_TRTT_SEG_SIZE_SHIFT) & | |
+ GEN9_TRVA_DATA_MASK; | |
+ const int num_lri_cmds = 6; | |
+ u32 *cs; | |
+ | |
+ /* | |
+ * Emitting LRIs to update the TRTT registers is most reliable, instead | |
+ * of directly updating the context image, as this will ensure that | |
+ * update happens in a serialized manner for the context and also | |
+ * lite-restore scenario will get handled. | |
+ */ | |
+ cs = intel_ring_begin(req, num_lri_cmds * 2 + 2); | |
+ if (IS_ERR(cs)) | |
+ return PTR_ERR(cs); | |
+ | |
+ *cs++ = MI_LOAD_REGISTER_IMM(num_lri_cmds); | |
+ | |
+ *cs++ = i915_mmio_reg_offset(GEN9_TRTT_L3_POINTER_DW0); | |
+ *cs++ = lower_32_bits(masked_l3_gfx_address); | |
+ | |
+ *cs++ = i915_mmio_reg_offset(GEN9_TRTT_L3_POINTER_DW1); | |
+ *cs++ = upper_32_bits(masked_l3_gfx_address); | |
+ | |
+ *cs++ = i915_mmio_reg_offset(GEN9_TRTT_NULL_TILE_REG); | |
+ *cs++ = ctx->trtt_info.null_tile_val; | |
+ | |
+ *cs++ = i915_mmio_reg_offset(GEN9_TRTT_INVD_TILE_REG); | |
+ *cs++ = ctx->trtt_info.invd_tile_val; | |
+ | |
+ *cs++ = i915_mmio_reg_offset(GEN9_TRTT_VA_MASKDATA); | |
+ *cs++ = GEN9_TRVA_MASK_VALUE | trva_data_value; | |
+ | |
+ *cs++ = i915_mmio_reg_offset(GEN9_TRTT_TABLE_CONTROL); | |
+ *cs++ = GEN9_TRTT_IN_GFX_VA_SPACE | GEN9_TRTT_ENABLE; | |
+ | |
+ *cs++ = MI_NOOP; | |
+ intel_ring_advance(req, cs); | |
+ | |
+ return 0; | |
+} | |
+ | |
/** | |
* intel_logical_ring_cleanup() - deallocate the Engine Command Streamer | |
* @engine: Engine Command Streamer. | |
@@ -1915,11 +2000,14 @@ int logical_render_ring_init(struct intel_engine_cs *engine) | |
engine->irq_keep_mask |= GT_RENDER_L3_PARITY_ERROR_INTERRUPT; | |
/* Override some for render ring. */ | |
- if (INTEL_GEN(dev_priv) >= 9) | |
+ if (INTEL_GEN(dev_priv) >= 9) { | |
engine->init_hw = gen9_init_render_ring; | |
- else | |
+ engine->init_context = gen9_init_rcs_context; | |
+ } else { | |
engine->init_hw = gen8_init_render_ring; | |
- engine->init_context = gen8_init_rcs_context; | |
+ engine->init_context = gen8_init_rcs_context; | |
+ } | |
+ | |
engine->emit_flush = gen8_emit_flush_render; | |
engine->emit_breadcrumb = gen8_emit_breadcrumb_render; | |
engine->emit_breadcrumb_sz = gen8_emit_breadcrumb_render_sz; | |
@@ -2235,3 +2323,19 @@ void intel_lr_context_resume(struct drm_i915_private *dev_priv) | |
} | |
} | |
} | |
+ | |
+int intel_lr_rcs_context_setup_trtt(struct i915_gem_context *ctx) | |
+{ | |
+ struct intel_engine_cs *engine = ctx->i915->engine[RCS]; | |
+ struct drm_i915_gem_request *req; | |
+ int ret; | |
+ | |
+ req = i915_gem_request_alloc(engine, ctx); | |
+ if (IS_ERR(req)) | |
+ return PTR_ERR(req); | |
+ | |
+ ret = gen9_emit_trtt_regs(req); | |
+ | |
+ i915_add_request(req); | |
+ return ret; | |
+} | |
diff --git a/drivers/gpu/drm/i915/intel_lrc.h b/drivers/gpu/drm/i915/intel_lrc.h | |
index 52b3a1fd4059..2399320d7f14 100644 | |
--- a/drivers/gpu/drm/i915/intel_lrc.h | |
+++ b/drivers/gpu/drm/i915/intel_lrc.h | |
@@ -81,6 +81,7 @@ struct i915_gem_context; | |
void intel_lr_context_resume(struct drm_i915_private *dev_priv); | |
uint64_t intel_lr_context_descriptor(struct i915_gem_context *ctx, | |
struct intel_engine_cs *engine); | |
+int intel_lr_rcs_context_setup_trtt(struct i915_gem_context *ctx); | |
/* Execlists */ | |
int intel_sanitize_enable_execlists(struct drm_i915_private *dev_priv, | |
diff --git a/include/uapi/drm/i915_drm.h b/include/uapi/drm/i915_drm.h | |
index 18bc0ec618dd..926f9142c96e 100644 | |
--- a/include/uapi/drm/i915_drm.h | |
+++ b/include/uapi/drm/i915_drm.h | |
@@ -1309,9 +1309,17 @@ struct drm_i915_gem_context_param { | |
#define I915_CONTEXT_PARAM_NO_ERROR_CAPTURE 0x4 | |
#define I915_CONTEXT_PARAM_BANNABLE 0x5 | |
#define I915_CONTEXT_PARAM_WATCHDOG 0x6 | |
+#define I915_CONTEXT_PARAM_TRTT 0x7 | |
__u64 value; | |
}; | |
+struct drm_i915_gem_context_trtt_param { | |
+ __u64 segment_base_addr; | |
+ __u64 l3_table_address; | |
+ __u32 invd_tile_val; | |
+ __u32 null_tile_val; | |
+}; | |
+ | |
enum drm_i915_oa_format { | |
I915_OA_FORMAT_A13 = 1, | |
I915_OA_FORMAT_A29, |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment