drm/msm: Add support for the WHERE_AM_I opcode
Subsystems (4)
PATCH 3/3 drm/msm: Get rid of the REG_ADRENO offsets
In reply to Jordan CrouseAs newer GPU families are added it makes less sense to maintain a "generic" version functions for older families. Move adreno_submit() and get_rptr() into the target specific code for a2xx, a3xx and a4xx. Add a parameter to adreno_flush to pass the target specific WPTR register instead of relying on the generic register.
All of this gets rid of the last of the REG_ADRENO offsets so remove all all the register definitions and infrastructure.
---
drivers/gpu/drm/msm/adreno/a2xx_gpu.c | 65 +++++++++++++++----- drivers/gpu/drm/msm/adreno/a3xx_gpu.c | 77 ++++++++++++++++++----- drivers/gpu/drm/msm/adreno/a4xx_gpu.c | 82 ++++++++++++++++++------- drivers/gpu/drm/msm/adreno/a5xx_gpu.c | 12 ---- drivers/gpu/drm/msm/adreno/a6xx_gpu.c | 13 ---- drivers/gpu/drm/msm/adreno/adreno_gpu.c | 82 +------------------------ drivers/gpu/drm/msm/adreno/adreno_gpu.h | 81 +----------------------- 7 files changed, 178 insertions(+), 234 deletions(-)
drivers/gpu/drm/msm/adreno/a2xx_gpu.c +50 -15
@@ -10,6 +10,48 @@ extern bool hang_debug;static void a2xx_dump (struct msm_gpu *gpu);static bool a2xx_idle (struct msm_gpu *gpu); +static void a2xx_submit (struct msm_gpu *gpu,struct msm_gem_submit *submit) +{ +struct msm_drm_private *priv = gpu->dev->dev_private; +struct msm_ringbuffer *ring = submit->ring; +unsigned int i; + +for (i =0 ; i < submit->nr_cmds; i++) { +switch (submit->cmd[i].type) { +case MSM_SUBMIT_CMD_IB_TARGET_BUF : +/* ignore IB-targets */ +break ; +case MSM_SUBMIT_CMD_CTX_RESTORE_BUF : +/* ignore if there has not been a ctx switch: */ +if (priv->lastctx == submit->queue->ctx) +break ; + fallthrough; +case MSM_SUBMIT_CMD_BUF : +OUT_PKT3 (ring,CP_INDIRECT_BUFFER_PFD ,2 ); +OUT_RING (ring,lower_32_bits (submit->cmd[i].iova)); +OUT_RING (ring, submit->cmd[i].size); +OUT_PKT2 (ring); +break ; + } + } + +OUT_PKT0 (ring,REG_AXXX_CP_SCRATCH_REG2 ,1 ); +OUT_RING (ring, submit->seqno); + +/* wait for idle before cache flush/interrupt */ +OUT_PKT3 (ring,CP_WAIT_FOR_IDLE ,1 ); +OUT_RING (ring,0x00000000 ); + +OUT_PKT3 (ring,CP_EVENT_WRITE ,3 ); +OUT_RING (ring,CACHE_FLUSH_TS ); +OUT_RING (ring,rbmemptr (ring, fence)); +OUT_RING (ring, submit->seqno); +OUT_PKT3 (ring,CP_INTERRUPT ,1 ); +OUT_RING (ring,0x80000000 ); + +adreno_flush (gpu, ring,REG_AXXX_CP_RB_WPTR ); +} +static bool a2xx_me_init (struct msm_gpu *gpu) {struct msm_ringbuffer *ring = gpu->rb[0 ];
@@ -53,7 +95,7 @@ static bool a2xx_me_init(struct msm_gpu *gpu)OUT_PKT3 (ring,CP_SET_PROTECTED_MODE ,1 );OUT_RING (ring,1 ); - gpu->funcs->flush (gpu, ring); +adreno_flush (gpu, ring,REG_AXXX_CP_RB_WPTR );return a2xx_idle (gpu); }
@@ -421,16 +463,11 @@ a2xx_create_address_space(struct msm_gpu *gpu, struct platform_device *pdev)return aspace; } -/* Register offset defines for A2XX - copy of A3XX */ -static const unsigned int a2xx_register_offsets[REG_ADRENO_REGISTER_MAX ] = { -REG_ADRENO_DEFINE (REG_ADRENO_CP_RB_BASE ,REG_AXXX_CP_RB_BASE ), -REG_ADRENO_SKIP (REG_ADRENO_CP_RB_BASE_HI ), -REG_ADRENO_DEFINE (REG_ADRENO_CP_RB_RPTR_ADDR ,REG_AXXX_CP_RB_RPTR_ADDR ), -REG_ADRENO_SKIP (REG_ADRENO_CP_RB_RPTR_ADDR_HI ), -REG_ADRENO_DEFINE (REG_ADRENO_CP_RB_RPTR ,REG_AXXX_CP_RB_RPTR ), -REG_ADRENO_DEFINE (REG_ADRENO_CP_RB_WPTR ,REG_AXXX_CP_RB_WPTR ), -REG_ADRENO_DEFINE (REG_ADRENO_CP_RB_CNTL ,REG_AXXX_CP_RB_CNTL ), -}; +static u32 a2xx_get_rptr (struct msm_gpu *gpu,struct msm_ringbuffer *ring) +{ + ring->memptrs->rptr =gpu_read (gpu,REG_AXXX_CP_RB_RPTR ); +return ring->memptrs->rptr; +}static const struct adreno_gpu_funcs funcs = { .base = {
@@ -439,8 +476,7 @@ static const struct adreno_gpu_funcs funcs = { .pm_suspend = msm_gpu_pm_suspend, .pm_resume = msm_gpu_pm_resume, .recover = a2xx_recover, - .submit = adreno_submit, - .flush = adreno_flush, + .submit = a2xx_submit, .active_ring = adreno_active_ring, .irq = a2xx_irq, .destroy = a2xx_destroy,
@@ -450,6 +486,7 @@ static const struct adreno_gpu_funcs funcs = { .gpu_state_get = a2xx_gpu_state_get, .gpu_state_put = adreno_gpu_state_put, .create_address_space = a2xx_create_address_space, + .get_rptr = a2xx_get_rptr, }, };
@@ -491,8 +528,6 @@ struct msm_gpu *a2xx_gpu_init(struct drm_device *dev)else adreno_gpu->registers = a220_registers; - adreno_gpu->reg_offsets = a2xx_register_offsets; - ret =adreno_gpu_init (dev, pdev, adreno_gpu, &funcs,1 );if (ret) goto fail;
drivers/gpu/drm/msm/adreno/a3xx_gpu.c +63 -14
113 lines not on this page · raw message
drivers/gpu/drm/msm/adreno/a4xx_gpu.c +61 -21
126 lines not on this page · raw message
drivers/gpu/drm/msm/adreno/a5xx_gpu.c +0 -12
@@ -1121,17 +1121,6 @@ static irqreturn_t a5xx_irq(struct msm_gpu *gpu)return IRQ_HANDLED ; } -static const u32 a5xx_register_offsets[REG_ADRENO_REGISTER_MAX ] = { -REG_ADRENO_DEFINE (REG_ADRENO_CP_RB_BASE ,REG_A5XX_CP_RB_BASE ), -REG_ADRENO_DEFINE (REG_ADRENO_CP_RB_BASE_HI ,REG_A5XX_CP_RB_BASE_HI ), -REG_ADRENO_DEFINE (REG_ADRENO_CP_RB_RPTR_ADDR ,REG_A5XX_CP_RB_RPTR_ADDR ), -REG_ADRENO_DEFINE (REG_ADRENO_CP_RB_RPTR_ADDR_HI , -REG_A5XX_CP_RB_RPTR_ADDR_HI ), -REG_ADRENO_DEFINE (REG_ADRENO_CP_RB_RPTR ,REG_A5XX_CP_RB_RPTR ), -REG_ADRENO_DEFINE (REG_ADRENO_CP_RB_WPTR ,REG_A5XX_CP_RB_WPTR ), -REG_ADRENO_DEFINE (REG_ADRENO_CP_RB_CNTL ,REG_A5XX_CP_RB_CNTL ), -}; -static const u32 a5xx_registers[] = {0x0000 ,0x0002 ,0x0004 ,0x0020 ,0x0022 ,0x0026 ,0x0029 ,0x002B ,0x002E ,0x0035 ,0x0038 ,0x0042 ,0x0044 ,0x0044 ,0x0047 ,0x0095 ,
@@ -1587,7 +1576,6 @@ struct msm_gpu *a5xx_gpu_init(struct drm_device *dev) gpu = &adreno_gpu->base; adreno_gpu->registers = a5xx_registers; - adreno_gpu->reg_offsets = a5xx_register_offsets; a5xx_gpu->lm_leakage =0x4E001A ;
drivers/gpu/drm/msm/adreno/a6xx_gpu.c +0 -13
@@ -1022,18 +1022,6 @@ static irqreturn_t a6xx_irq(struct msm_gpu *gpu)return IRQ_HANDLED ; } -static const u32 a6xx_register_offsets[REG_ADRENO_REGISTER_MAX ] = { -REG_ADRENO_DEFINE (REG_ADRENO_CP_RB_BASE ,REG_A6XX_CP_RB_BASE ), -REG_ADRENO_DEFINE (REG_ADRENO_CP_RB_BASE_HI ,REG_A6XX_CP_RB_BASE_HI ), -REG_ADRENO_DEFINE (REG_ADRENO_CP_RB_RPTR_ADDR , -REG_A6XX_CP_RB_RPTR_ADDR_LO ), -REG_ADRENO_DEFINE (REG_ADRENO_CP_RB_RPTR_ADDR_HI , -REG_A6XX_CP_RB_RPTR_ADDR_HI ), -REG_ADRENO_DEFINE (REG_ADRENO_CP_RB_RPTR ,REG_A6XX_CP_RB_RPTR ), -REG_ADRENO_DEFINE (REG_ADRENO_CP_RB_WPTR ,REG_A6XX_CP_RB_WPTR ), -REG_ADRENO_DEFINE (REG_ADRENO_CP_RB_CNTL ,REG_A6XX_CP_RB_CNTL ), -}; -static int a6xx_pm_resume (struct msm_gpu *gpu) {struct adreno_gpu *adreno_gpu =to_adreno_gpu (gpu);
@@ -1208,7 +1196,6 @@ struct msm_gpu *a6xx_gpu_init(struct drm_device *dev) gpu = &adreno_gpu->base; adreno_gpu->registers =NULL ; - adreno_gpu->reg_offsets = a6xx_register_offsets;if (adreno_is_a650 (adreno_gpu)) adreno_gpu->base.hw_apriv = true;
drivers/gpu/drm/msm/adreno/adreno_gpu.c +3 -79
101 lines not on this page · raw message
drivers/gpu/drm/msm/adreno/adreno_gpu.h +1 -80
119 lines not on this page · raw message
Signature · 6 lines
2.25.1 _______________________________________________ dri-devel mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/dri-devel
PATCH 2/3 drm/msm: a6xx: Use WHERE_AM_I for eligible targets
In reply to Jordan CrouseSupport the WHERE_AM_I opcode for the A618, A630 and A640 GPUs if the microcode supports it. The WHERE_AM_I opcode allows the RPTR shadow to be updated in priviliged memory which protects the shadow from being read or written from user submissions.
A650 already supports extended APRIV have built in hardware support for to access privilged memory from the CP and can go back to using the hardware RPTR shadow feature.
---
drivers/gpu/drm/msm/adreno/a6xx_gpu.c | 87 ++++++++++++++++++++++++++- drivers/gpu/drm/msm/adreno/a6xx_gpu.h | 9 +++ 2 files changed, 93 insertions(+), 3 deletions(-)
drivers/gpu/drm/msm/adreno/a6xx_gpu.c +84 -3
@@ -51,9 +51,20 @@ bool a6xx_idle(struct msm_gpu *gpu, struct msm_ringbuffer *ring)static void a6xx_flush (struct msm_gpu *gpu,struct msm_ringbuffer *ring) { +struct adreno_gpu *adreno_gpu =to_adreno_gpu (gpu); +struct a6xx_gpu *a6xx_gpu =to_a6xx_gpu (adreno_gpu);uint32_t wptr;unsigned long flags; +/* Expanded APRIV doesn't need to issue the WHERE_AM_I opcode */ +if (a6xx_gpu->has_whereami && !adreno_gpu->base.hw_apriv) { +struct a6xx_gpu *a6xx_gpu =to_a6xx_gpu (adreno_gpu); + +OUT_PKT7 (ring,CP_WHERE_AM_I ,2 ); +OUT_RING (ring,lower_32_bits (shadowptr (a6xx_gpu, ring))); +OUT_RING (ring,upper_32_bits (shadowptr (a6xx_gpu, ring))); + } +spin_lock_irqsave (&ring->lock, flags);/* Copy the shadow to the actual register */
@@ -508,6 +519,30 @@ static int a6xx_cp_init(struct msm_gpu *gpu)return a6xx_idle (gpu, ring) ?0 : -EINVAL ; } +static void a6xx_ucode_check_version (struct a6xx_gpu *a6xx_gpu, +struct drm_gem_object *obj) +{ +u32 *buf =msm_gem_get_vaddr_active (obj); + +if (IS_ERR (buf)) +return ; + +/* +* If the lowest nibble is 0xa that is an indication that this microcode +* has been patched. The actual version is in dword [3] but we only care +* about the patchlevel which is the lowest nibble of dword [3] +* +* Otherwise check that the firmware is greater than or equal to 1.90 +* which was the first version that had this fix built in +*/ +if (((buf[0 ] &0xf ) ==0xa ) && (buf[2 ] &0xf ) >=1 ) + a6xx_gpu->has_whereami = true; +else if ((buf[0 ] &0xfff ) >0x190 ) + a6xx_gpu->has_whereami = true; + +msm_gem_put_vaddr (obj); +} +static int a6xx_ucode_init (struct msm_gpu *gpu) {struct adreno_gpu *adreno_gpu =to_adreno_gpu (gpu);
@@ -528,6 +563,7 @@ static int a6xx_ucode_init(struct msm_gpu *gpu) }msm_gem_object_set_name (a6xx_gpu->sqe_bo,"sqefw" ); +a6xx_ucode_check_version (a6xx_gpu, a6xx_gpu->sqe_bo); } gpu_write64(gpu, REG_A6XX_CP_SQE_INSTR_BASE_LO,
@@ -743,8 +779,37 @@ static int a6xx_hw_init(struct msm_gpu *gpu)gpu_write64 (gpu,REG_A6XX_CP_RB_BASE ,REG_A6XX_CP_RB_BASE_HI , gpu->rb[0 ]->iova); -gpu_write (gpu,REG_A6XX_CP_RB_CNTL , -MSM_GPU_RB_CNTL_DEFAULT |AXXX_CP_RB_CNTL_NO_UPDATE ); +/* Targets that support extended APRIV can use the RPTR shadow from +* hardware but all the other ones need to disable the feature. Targets +* that support the WHERE_AM_I opcode can use that instead +*/ +if (adreno_gpu->base.hw_apriv) +gpu_write (gpu,REG_A6XX_CP_RB_CNTL ,MSM_GPU_RB_CNTL_DEFAULT ); +else +gpu_write (gpu,REG_A6XX_CP_RB_CNTL , +MSM_GPU_RB_CNTL_DEFAULT |AXXX_CP_RB_CNTL_NO_UPDATE ); + +/* +* Expanded APRIV and targets that support WHERE_AM_I both need a +* privileged buffer to store the RPTR shadow +*/ + +if (adreno_gpu->base.hw_apriv || a6xx_gpu->has_whereami) { +if (!a6xx_gpu->shadow_bo) { + a6xx_gpu->shadow =msm_gem_kernel_new_locked (gpu->dev, +sizeof (u32) * gpu->nr_rings, +MSM_BO_UNCACHED |MSM_BO_MAP_PRIV , + gpu->aspace, &a6xx_gpu->shadow_bo, + &a6xx_gpu->shadow_iova); + +if (IS_ERR (a6xx_gpu->shadow)) +return PTR_ERR (a6xx_gpu->shadow); + } + +gpu_write64 (gpu,REG_A6XX_CP_RB_RPTR_ADDR_LO , +REG_A6XX_CP_RB_RPTR_ADDR_HI , +shadowptr (a6xx_gpu, gpu->rb[0 ])); + }/* Always come up on rb 0 */ a6xx_gpu->cur_ring = gpu->rb[0 ];
@@ -1033,6 +1098,11 @@ static void a6xx_destroy(struct msm_gpu *gpu)drm_gem_object_put (a6xx_gpu->sqe_bo); } +if (a6xx_gpu->shadow_bo) { +msm_gem_unpin_iova (a6xx_gpu->shadow_bo, gpu->aspace); +drm_gem_object_put (a6xx_gpu->shadow_bo); + } +a6xx_gmu_remove (a6xx_gpu);adreno_gpu_cleanup (adreno_gpu);
@@ -1081,6 +1151,17 @@ a6xx_create_private_address_space(struct msm_gpu *gpu) "gpu", 0x100000000ULL, 0x1ffffffffULL); } +static uint32_t a6xx_get_rptr (struct msm_gpu *gpu,struct msm_ringbuffer *ring) +{ +struct adreno_gpu *adreno_gpu =to_adreno_gpu (gpu); +struct a6xx_gpu *a6xx_gpu =to_a6xx_gpu (adreno_gpu); + +if (adreno_gpu->base.hw_apriv || a6xx_gpu->has_whereami) +return a6xx_gpu->shadow[ring->id]; + +return ring->memptrs->rptr =gpu_read (gpu,REG_A6XX_CP_RB_RPTR ); +} +static const struct adreno_gpu_funcs funcs = { .base = { .get_param = adreno_get_param,
@@ -1089,7 +1170,6 @@ static const struct adreno_gpu_funcs funcs = { .pm_resume = a6xx_pm_resume, .recover = a6xx_recover, .submit = a6xx_submit, - .flush = a6xx_flush, .active_ring = a6xx_active_ring, .irq = a6xx_irq, .destroy = a6xx_destroy,
@@ -1105,6 +1185,7 @@ static const struct adreno_gpu_funcs funcs = {#endif .create_address_space = adreno_iommu_create_address_space, .create_private_address_space = a6xx_create_private_address_space, + .get_rptr = a6xx_get_rptr, }, .get_timestamp = a6xx_get_timestamp, };
drivers/gpu/drm/msm/adreno/a6xx_gpu.h +9 -0
@@ -22,6 +22,12 @@ struct a6xx_gpu {struct msm_file_private *cur_ctx;struct a6xx_gmu gmu; + +struct drm_gem_object *shadow_bo; +uint64_t shadow_iova; +uint32_t *shadow; + +bool has_whereami; };#define to_a6xx_gpu (x) container_of(x, struct a6xx_gpu, base)
@@ -51,6 +57,9 @@ static inline bool a6xx_has_gbif(struct adreno_gpu *gpu)return true; } +#define shadowptr (_a6xx_gpu, _ring) ((_a6xx_gpu)->shadow_iova + \ + ((_ring)->id * sizeof(uint32_t))) +int a6xx_gmu_resume (struct a6xx_gpu *gpu);int a6xx_gmu_stop (struct a6xx_gpu *gpu);
Signature · 6 lines
2.25.1 _______________________________________________ dri-devel mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/dri-devel
cover drm/msm: Add support for the WHERE_AM_I opcode
The microcode in linux-firmware has been updated to 1.87.01 for a5xx 1.77.01 for a6xx [1]. These microcode versions support a new opcode called WHERE_AM_I that takes the place of the hardware RPTR shadow and enables the microcode to update the RPTR shadow in privileged memory so it is protected against the user.
This patch series re-enables the RPTR shadow and preemption for a5xx and older versions of a6xx if the WHERE_AM_I opcode is available. Newer a6xx targets (starting with a650) have automatic privileged protection so the hardware RPTR shadow can be renabled for those targets too. If any of the needed dependencies aren't met then the RPTR shadow will remain disabled (along with preemption on 5xx).
This stack is bsed on https://gitlab.freedesktop.org/drm/msm.git msm-next-pgtables as there are some minor dependencies on the reorganized code in the pgtable stack.
Jordan
Jordan Crouse (3):
drm/msm: Allow a5xx to mark the RPTR shadow as privileged drm/msm: a6xx: Use WHERE_AM_I for eligible targets drm/msm: Get rid of the REG_ADRENO offsets
drivers/gpu/drm/msm/adreno/a2xx_gpu.c | 65 +++++++++--- drivers/gpu/drm/msm/adreno/a3xx_gpu.c | 77 +++++++++++--- drivers/gpu/drm/msm/adreno/a4xx_gpu.c | 82 +++++++++++---- drivers/gpu/drm/msm/adreno/a5xx_gpu.c | 108 ++++++++++++++++---- drivers/gpu/drm/msm/adreno/a5xx_gpu.h | 12 +++ drivers/gpu/drm/msm/adreno/a5xx_power.c | 2 +- drivers/gpu/drm/msm/adreno/a5xx_preempt.c | 5 +- drivers/gpu/drm/msm/adreno/a6xx_gpu.c | 100 +++++++++++++++--- drivers/gpu/drm/msm/adreno/a6xx_gpu.h | 9 ++ drivers/gpu/drm/msm/adreno/adreno_gpu.c | 81 +-------------- drivers/gpu/drm/msm/adreno/adreno_gpu.h | 81 +-------------- drivers/gpu/drm/msm/adreno/adreno_pm4.xml.h | 1 + drivers/gpu/drm/msm/msm_gpu.h | 1 + 13 files changed, 377 insertions(+), 247 deletions(-)
Signature · 6 lines
2.25.1 _______________________________________________ dri-devel mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/dri-devel
PATCH 1/3 drm/msm: Allow a5xx to mark the RPTR shadow as privileged
Newer microcode versions have support for the CP_WHERE_AM_I opcode which allows the RPTR shadow memory to be marked as privileged to protect it from corruption. Move the RPTR shadow into its own buffer and protect it it if the current microcode version supports the new feature.
We can also re-enable preemption for those targets that support CP_WHERE_AM_I. Start out by preemptively assuming that we can enable preemption and disable it in a5xx_hw_init if the microcode version comes back as too old.
---
drivers/gpu/drm/msm/adreno/a5xx_gpu.c | 96 ++++++++++++++++++--- drivers/gpu/drm/msm/adreno/a5xx_gpu.h | 12 +++ drivers/gpu/drm/msm/adreno/a5xx_power.c | 2 +- drivers/gpu/drm/msm/adreno/a5xx_preempt.c | 5 +- drivers/gpu/drm/msm/adreno/adreno_gpu.c | 5 ++ drivers/gpu/drm/msm/adreno/adreno_pm4.xml.h | 1 + drivers/gpu/drm/msm/msm_gpu.h | 1 + 7 files changed, 109 insertions(+), 13 deletions(-)
drivers/gpu/drm/msm/adreno/a5xx_gpu.c +86 -10
@@ -18,13 +18,24 @@ static void a5xx_dump(struct msm_gpu *gpu);#define GPU_PAS_ID 13 -static void a5xx_flush (struct msm_gpu *gpu,struct msm_ringbuffer *ring) +void a5xx_flush (struct msm_gpu *gpu,struct msm_ringbuffer *ring, +bool sync) {struct adreno_gpu *adreno_gpu =to_adreno_gpu (gpu);struct a5xx_gpu *a5xx_gpu =to_a5xx_gpu (adreno_gpu);uint32_t wptr;unsigned long flags; +/* +* Most flush operations need to issue a WHERE_AM_I opcode to sync up +* the rptr shadow +*/ +if (a5xx_gpu->has_whereami && sync) { +OUT_PKT7 (ring,CP_WHERE_AM_I ,2 ); +OUT_RING (ring,lower_32_bits (shadowptr (a5xx_gpu, ring))); +OUT_RING (ring,upper_32_bits (shadowptr (a5xx_gpu, ring))); + } +spin_lock_irqsave (&ring->lock, flags);/* Copy the shadow to the actual register */
@@ -90,7 +101,7 @@ static void a5xx_submit_in_rb(struct msm_gpu *gpu, struct msm_gem_submit *submit } } -a5xx_flush (gpu, ring); +a5xx_flush (gpu, ring, true);a5xx_preempt_trigger (gpu);/* we might not necessarily have a cmd from userspace to
@@ -204,7 +215,8 @@ static void a5xx_submit(struct msm_gpu *gpu, struct msm_gem_submit *submit)/* Set bit 0 to trigger an interrupt on preempt complete */ OUT_RING (ring,0x01 ); -a5xx_flush (gpu, ring); +/* A WHERE_AM_I packet is not needed after a YIELD */ +a5xx_flush (gpu, ring, false);/* Check to see if we need to start preemption */ a5xx_preempt_trigger (gpu);
@@ -363,7 +375,7 @@ static int a5xx_me_init(struct msm_gpu *gpu)OUT_RING (ring,0x00000000 );OUT_RING (ring,0x00000000 ); - gpu->funcs->flush (gpu, ring); +a5xx_flush (gpu, ring, true);return a5xx_idle (gpu, ring) ?0 : -EINVAL ; }
@@ -405,11 +417,31 @@ static int a5xx_preempt_start(struct msm_gpu *gpu)OUT_RING (ring,0x01 );OUT_RING (ring,0x01 ); - gpu->funcs->flush (gpu, ring); +/* The WHERE_AMI_I packet is not needed after a YIELD is issued */ +a5xx_flush (gpu, ring, false);return a5xx_idle (gpu, ring) ?0 : -EINVAL ; } +static void a5xx_ucode_check_version (struct a5xx_gpu *a5xx_gpu, +struct drm_gem_object *obj) +{ +u32 *buf =msm_gem_get_vaddr_active (obj); + +if (IS_ERR (buf)) +return ; + +/* +* If the lowest nibble is 0xa that is an indication that this microcode +* has been patched. The actual version is in dword [3] but we only care +* about the patchlevel which is the lowest nibble of dword [3] +*/ +if (((buf[0 ] &0xf ) ==0xa ) && (buf[2 ] &0xf ) >=1 ) + a5xx_gpu->has_whereami = true; + +msm_gem_put_vaddr (obj); +} +static int a5xx_ucode_init (struct msm_gpu *gpu) {struct adreno_gpu *adreno_gpu =to_adreno_gpu (gpu);
@@ -445,6 +477,7 @@ static int a5xx_ucode_init(struct msm_gpu *gpu) }msm_gem_object_set_name (a5xx_gpu->pfp_bo,"pfpfw" ); +a5xx_ucode_check_version (a5xx_gpu, a5xx_gpu->pfp_bo); } gpu_write64(gpu, REG_A5XX_CP_ME_INSTR_BASE_LO,
@@ -504,6 +537,7 @@ static int a5xx_zap_shader_init(struct msm_gpu *gpu)static int a5xx_hw_init (struct msm_gpu *gpu) {struct adreno_gpu *adreno_gpu =to_adreno_gpu (gpu); +struct a5xx_gpu *a5xx_gpu =to_a5xx_gpu (adreno_gpu);int ret;gpu_write (gpu,REG_A5XX_VBIF_ROUND_ROBIN_QOS_ARB ,0x00000003 );
@@ -712,9 +746,36 @@ static int a5xx_hw_init(struct msm_gpu *gpu)gpu_write64 (gpu,REG_A5XX_CP_RB_BASE ,REG_A5XX_CP_RB_BASE_HI , gpu->rb[0 ]->iova); +/* +* If the microcode supports the WHERE_AM_I opcode then we can use that +* in lieu of the RPTR shadow and enable preemption. Otherwise, we +* can't safely use the RPTR shadow or preemption. In either case, the +* RPTR shadow should be disabled in hardware. +*/ gpu_write (gpu,REG_A5XX_CP_RB_CNTL ,MSM_GPU_RB_CNTL_DEFAULT |AXXX_CP_RB_CNTL_NO_UPDATE ); +/* Disable preemption if WHERE_AM_I isn't available */ +if (!a5xx_gpu->has_whereami && gpu->nr_rings >1 ) { +a5xx_preempt_fini (gpu); + gpu->nr_rings =1 ; + }else { +/* Create a privileged buffer for the RPTR shadow */ +if (!a5xx_gpu->shadow_bo) { + a5xx_gpu->shadow =msm_gem_kernel_new (gpu->dev, +sizeof (u32) * gpu->nr_rings, +MSM_BO_UNCACHED |MSM_BO_MAP_PRIV , + gpu->aspace, &a5xx_gpu->shadow_bo, + &a5xx_gpu->shadow_iova); + +if (IS_ERR (a5xx_gpu->shadow)) +return PTR_ERR (a5xx_gpu->shadow); + } + +gpu_write64 (gpu,REG_A5XX_CP_RB_RPTR_ADDR , +REG_A5XX_CP_RB_RPTR_ADDR_HI ,shadowptr (a5xx_gpu, gpu->rb[0 ])); + } +a5xx_preempt_hw_init (gpu);/* Disable the interrupts through the initial bringup stage */
@@ -738,7 +799,7 @@ static int a5xx_hw_init(struct msm_gpu *gpu)OUT_PKT7 (gpu->rb[0 ],CP_EVENT_WRITE ,1 );OUT_RING (gpu->rb[0 ],CP_EVENT_WRITE_0_EVENT (STAT_EVENT )); - gpu->funcs->flush (gpu, gpu->rb[0 ]); +a5xx_flush (gpu, gpu->rb[0 ], true);if (!a5xx_idle (gpu, gpu->rb[0 ]))return -EINVAL ; }
@@ -756,7 +817,7 @@ static int a5xx_hw_init(struct msm_gpu *gpu)OUT_PKT7 (gpu->rb[0 ],CP_SET_SECURE_MODE ,1 );OUT_RING (gpu->rb[0 ],0x00000000 ); - gpu->funcs->flush (gpu, gpu->rb[0 ]); +a5xx_flush (gpu, gpu->rb[0 ], true);if (!a5xx_idle (gpu, gpu->rb[0 ]))return -EINVAL ; }else if (ret == -ENODEV ) {
@@ -823,6 +884,11 @@ static void a5xx_destroy(struct msm_gpu *gpu)drm_gem_object_put (a5xx_gpu->gpmu_bo); } +if (a5xx_gpu->shadow_bo) { +msm_gem_unpin_iova (a5xx_gpu->shadow_bo, gpu->aspace); +drm_gem_object_put (a5xx_gpu->shadow_bo); + } +adreno_gpu_cleanup (adreno_gpu);kfree (a5xx_gpu); }
@@ -1430,6 +1496,17 @@ static unsigned long a5xx_gpu_busy(struct msm_gpu *gpu)return (unsigned long )busy_time; } +static uint32_t a5xx_get_rptr (struct msm_gpu *gpu,struct msm_ringbuffer *ring) +{ +struct adreno_gpu *adreno_gpu =to_adreno_gpu (gpu); +struct a5xx_gpu *a5xx_gpu =to_a5xx_gpu (adreno_gpu); + +if (a5xx_gpu->has_whereami) +return a5xx_gpu->shadow[ring->id]; + +return ring->memptrs->rptr =gpu_read (gpu,REG_A5XX_CP_RB_RPTR ); +} +static const struct adreno_gpu_funcs funcs = { .base = { .get_param = adreno_get_param,
@@ -1438,7 +1515,6 @@ static const struct adreno_gpu_funcs funcs = { .pm_resume = a5xx_pm_resume, .recover = a5xx_recover, .submit = a5xx_submit, - .flush = a5xx_flush, .active_ring = a5xx_active_ring, .irq = a5xx_irq, .destroy = a5xx_destroy,
@@ -1452,6 +1528,7 @@ static const struct adreno_gpu_funcs funcs = { .gpu_state_get = a5xx_gpu_state_get, .gpu_state_put = a5xx_gpu_state_put, .create_address_space = adreno_iommu_create_address_space, + .get_rptr = a5xx_get_rptr, }, .get_timestamp = a5xx_get_timestamp, };
@@ -1516,8 +1593,7 @@ struct msm_gpu *a5xx_gpu_init(struct drm_device *dev)check_speed_bin (&pdev->dev); -/* Restricting nr_rings to 1 to temporarily disable preemption */ - ret =adreno_gpu_init (dev, pdev, adreno_gpu, &funcs,1 ); + ret =adreno_gpu_init (dev, pdev, adreno_gpu, &funcs,4 );if (ret) {a5xx_destroy (&(a5xx_gpu->base.base));return ERR_PTR (ret);
drivers/gpu/drm/msm/adreno/a5xx_gpu.h +12 -0
@@ -37,6 +37,13 @@ struct a5xx_gpu {atomic_t preempt_state;struct timer_list preempt_timer; + +struct drm_gem_object *shadow_bo; +uint64_t shadow_iova; +uint32_t *shadow; + +/* True if the microcode supports the WHERE_AM_I opcode */ +bool has_whereami; };#define to_a5xx_gpu (x) container_of(x, struct a5xx_gpu, base)
@@ -141,6 +148,9 @@ static inline int spin_usecs(struct msm_gpu *gpu, uint32_t usecs,return -ETIMEDOUT ; } +#define shadowptr (a5xx_gpu, ring) ((a5xx_gpu)->shadow_iova + \ + ((ring)->id * sizeof(uint32_t))) +bool a5xx_idle (struct msm_gpu *gpu,struct msm_ringbuffer *ring);void a5xx_set_hwcg (struct msm_gpu *gpu,bool state);
@@ -150,6 +160,8 @@ void a5xx_preempt_trigger(struct msm_gpu *gpu);void a5xx_preempt_irq (struct msm_gpu *gpu);void a5xx_preempt_fini (struct msm_gpu *gpu); +void a5xx_flush (struct msm_gpu *gpu,struct msm_ringbuffer *ring,bool sync); +/* Return true if we are in a preempt state */ static inline bool a5xx_in_preempt (struct a5xx_gpu *a5xx_gpu) {
drivers/gpu/drm/msm/adreno/a5xx_power.c +1 -1
@@ -240,7 +240,7 @@ static int a5xx_gpmu_init(struct msm_gpu *gpu)OUT_PKT7 (ring,CP_SET_PROTECTED_MODE ,1 );OUT_RING (ring,1 ); - gpu->funcs->flush (gpu, ring); +a5xx_flush (gpu, ring, true);if (!a5xx_idle (gpu, ring)) { DRM_ERROR("%s: Unable to load GPMU firmware. GPMU will not be active\n",
drivers/gpu/drm/msm/adreno/a5xx_preempt.c +3 -2
@@ -259,8 +259,9 @@ static int preempt_init_ring(struct a5xx_gpu *a5xx_gpu, ptr->magic =A5XX_PREEMPT_RECORD_MAGIC ; ptr->info =0 ; ptr->data =0 ; - ptr->cntl =MSM_GPU_RB_CNTL_DEFAULT ; - ptr->rptr_addr =rbmemptr (ring, rptr); + ptr->cntl =MSM_GPU_RB_CNTL_DEFAULT |AXXX_CP_RB_CNTL_NO_UPDATE ; + + ptr->rptr_addr =shadowptr (a5xx_gpu, ring); ptr->counter = counters_iova;return 0 ;
drivers/gpu/drm/msm/adreno/adreno_gpu.c +5 -0
@@ -422,6 +422,11 @@ int adreno_hw_init(struct msm_gpu *gpu)static uint32_t get_rptr (struct adreno_gpu *adreno_gpu,struct msm_ringbuffer *ring) { +struct msm_gpu *gpu = &adreno_gpu->base; + +if (gpu->funcs->get_rptr) +return gpu->funcs->get_rptr (gpu, ring); +return ring->memptrs->rptr =adreno_gpu_read ( adreno_gpu,REG_ADRENO_CP_RB_RPTR ); }
drivers/gpu/drm/msm/adreno/adreno_pm4.xml.h +1 -0
@@ -298,6 +298,7 @@ enum adreno_pm4_type3_packets {CP_SET_BIN_DATA5_OFFSET =46 ,CP_SET_CTXSWITCH_IB =85 ,CP_REG_WRITE =109 , + CP_WHERE_AM_I = 98, }; enum adreno_state_block {
drivers/gpu/drm/msm/msm_gpu.h +1 -0
@@ -68,6 +68,7 @@ struct msm_gpu_funcs { (struct msm_gpu *gpu, struct platform_device *pdev);struct msm_gem_address_space *(*create_private_address_space) (struct msm_gpu *gpu); +uint32_t (*get_rptr)(struct msm_gpu *gpu,struct msm_ringbuffer *ring); };struct msm_gpu {
Signature · 1 line
2.25.1