Skip to content

Commit d223f98

Browse files
committed
drm/v3d: Add support for compute shader dispatch.
The compute shader dispatch interface is pretty simple -- just pass in the regs that userspace has passed us, with no CLs to run. However, with no CL to run it means that we need to do manual cache flushing of the L2 after the HW execution completes (for SSBO, atomic, and image_load_store writes that are the output of compute shaders). This doesn't yet expose the L2 cache's ability to have a region of the address space not write back to memory (which could be used for shared_var storage). So far, the Mesa side has been tested on V3D v4.2 simpenrose (passing the ES31 tests), and on the kernel side on 7278 (failing atomic compswap tests in a way that doesn't reproduce on simpenrose). v2: Fix excessive allocation for the clean_job (reported by Dan Carpenter). Keep refs on jobs until clean_job is finished, to avoid spurious MMU errors if the output BOs are freed by userspace before L2 cleaning is finished. Signed-off-by: Eric Anholt <eric@anholt.net> Link: https://patchwork.freedesktop.org/patch/msgid/20190416225856.20264-4-eric@anholt.net Acked-by: Rob Clark <robdclark@gmail.com>
1 parent a783a09 commit d223f98

10 files changed

Lines changed: 531 additions & 19 deletions

File tree

‎drivers/gpu/drm/v3d/v3d_debugfs.c‎

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,17 @@ static const struct v3d_reg_def v3d_core_reg_defs[] = {
5858
REGDEF(V3D_GMP_VIO_ADDR),
5959
};
6060

61+
static const struct v3d_reg_def v3d_csd_reg_defs[] = {
62+
REGDEF(V3D_CSD_STATUS),
63+
REGDEF(V3D_CSD_CURRENT_CFG0),
64+
REGDEF(V3D_CSD_CURRENT_CFG1),
65+
REGDEF(V3D_CSD_CURRENT_CFG2),
66+
REGDEF(V3D_CSD_CURRENT_CFG3),
67+
REGDEF(V3D_CSD_CURRENT_CFG4),
68+
REGDEF(V3D_CSD_CURRENT_CFG5),
69+
REGDEF(V3D_CSD_CURRENT_CFG6),
70+
};
71+
6172
static int v3d_v3d_debugfs_regs(struct seq_file *m, void *unused)
6273
{
6374
struct drm_info_node *node = (struct drm_info_node *)m->private;
@@ -89,6 +100,17 @@ static int v3d_v3d_debugfs_regs(struct seq_file *m, void *unused)
89100
V3D_CORE_READ(core,
90101
v3d_core_reg_defs[i].reg));
91102
}
103+
104+
if (v3d_has_csd(v3d)) {
105+
for (i = 0; i < ARRAY_SIZE(v3d_csd_reg_defs); i++) {
106+
seq_printf(m, "core %d %s (0x%04x): 0x%08x\n",
107+
core,
108+
v3d_csd_reg_defs[i].name,
109+
v3d_csd_reg_defs[i].reg,
110+
V3D_CORE_READ(core,
111+
v3d_csd_reg_defs[i].reg));
112+
}
113+
}
92114
}
93115

94116
return 0;

‎drivers/gpu/drm/v3d/v3d_drv.c‎

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@
77
* This driver supports the Broadcom V3D 3.3 and 4.1 OpenGL ES GPUs.
88
* For V3D 2.x support, see the VC4 driver.
99
*
10-
* Currently only single-core rendering using the binner and renderer,
11-
* along with TFU (texture formatting unit) rendering is supported.
12-
* V3D 4.x's CSD (compute shader dispatch) is not yet supported.
10+
* The V3D GPU includes a tiled render (composed of a bin and render
11+
* pipelines), the TFU (texture formatting unit), and the CSD (compute
12+
* shader dispatch).
1313
*/
1414

1515
#include <linux/clk.h>
@@ -120,6 +120,9 @@ static int v3d_get_param_ioctl(struct drm_device *dev, void *data,
120120
case DRM_V3D_PARAM_SUPPORTS_TFU:
121121
args->value = 1;
122122
return 0;
123+
case DRM_V3D_PARAM_SUPPORTS_CSD:
124+
args->value = v3d_has_csd(v3d);
125+
return 0;
123126
default:
124127
DRM_DEBUG("Unknown parameter %d\n", args->param);
125128
return -EINVAL;
@@ -179,6 +182,7 @@ static const struct drm_ioctl_desc v3d_drm_ioctls[] = {
179182
DRM_IOCTL_DEF_DRV(V3D_GET_PARAM, v3d_get_param_ioctl, DRM_RENDER_ALLOW),
180183
DRM_IOCTL_DEF_DRV(V3D_GET_BO_OFFSET, v3d_get_bo_offset_ioctl, DRM_RENDER_ALLOW),
181184
DRM_IOCTL_DEF_DRV(V3D_SUBMIT_TFU, v3d_submit_tfu_ioctl, DRM_RENDER_ALLOW | DRM_AUTH),
185+
DRM_IOCTL_DEF_DRV(V3D_SUBMIT_CSD, v3d_submit_csd_ioctl, DRM_RENDER_ALLOW | DRM_AUTH),
182186
};
183187

184188
static struct drm_driver v3d_drm_driver = {

‎drivers/gpu/drm/v3d/v3d_drv.h‎

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,11 @@ enum v3d_queue {
1616
V3D_BIN,
1717
V3D_RENDER,
1818
V3D_TFU,
19+
V3D_CSD,
20+
V3D_CACHE_CLEAN,
1921
};
2022

21-
#define V3D_MAX_QUEUES (V3D_TFU + 1)
23+
#define V3D_MAX_QUEUES (V3D_CACHE_CLEAN + 1)
2224

2325
struct v3d_queue_state {
2426
struct drm_gpu_scheduler sched;
@@ -70,6 +72,7 @@ struct v3d_dev {
7072
struct v3d_bin_job *bin_job;
7173
struct v3d_render_job *render_job;
7274
struct v3d_tfu_job *tfu_job;
75+
struct v3d_csd_job *csd_job;
7376

7477
struct v3d_queue_state queue[V3D_MAX_QUEUES];
7578

@@ -92,6 +95,12 @@ struct v3d_dev {
9295
*/
9396
struct mutex sched_lock;
9497

98+
/* Lock taken during a cache clean and when initiating an L2
99+
* flush, to keep L2 flushes from interfering with the
100+
* synchronous L2 cleans.
101+
*/
102+
struct mutex cache_clean_lock;
103+
95104
struct {
96105
u32 num_allocated;
97106
u32 pages_allocated;
@@ -104,6 +113,12 @@ to_v3d_dev(struct drm_device *dev)
104113
return (struct v3d_dev *)dev->dev_private;
105114
}
106115

116+
static inline bool
117+
v3d_has_csd(struct v3d_dev *v3d)
118+
{
119+
return v3d->ver >= 41;
120+
}
121+
107122
/* The per-fd struct, which tracks the MMU mappings. */
108123
struct v3d_file_priv {
109124
struct v3d_dev *v3d;
@@ -222,6 +237,14 @@ struct v3d_tfu_job {
222237
struct drm_v3d_submit_tfu args;
223238
};
224239

240+
struct v3d_csd_job {
241+
struct v3d_job base;
242+
243+
u32 timedout_batches;
244+
245+
struct drm_v3d_submit_csd args;
246+
};
247+
225248
/**
226249
* _wait_for - magic (register) wait macro
227250
*
@@ -283,11 +306,14 @@ int v3d_submit_cl_ioctl(struct drm_device *dev, void *data,
283306
struct drm_file *file_priv);
284307
int v3d_submit_tfu_ioctl(struct drm_device *dev, void *data,
285308
struct drm_file *file_priv);
309+
int v3d_submit_csd_ioctl(struct drm_device *dev, void *data,
310+
struct drm_file *file_priv);
286311
int v3d_wait_bo_ioctl(struct drm_device *dev, void *data,
287312
struct drm_file *file_priv);
288313
void v3d_job_put(struct v3d_job *job);
289314
void v3d_reset(struct v3d_dev *v3d);
290315
void v3d_invalidate_caches(struct v3d_dev *v3d);
316+
void v3d_clean_caches(struct v3d_dev *v3d);
291317

292318
/* v3d_irq.c */
293319
int v3d_irq_init(struct v3d_dev *v3d);

‎drivers/gpu/drm/v3d/v3d_fence.c‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@ static const char *v3d_fence_get_timeline_name(struct dma_fence *fence)
3636
return "v3d-render";
3737
case V3D_TFU:
3838
return "v3d-tfu";
39+
case V3D_CSD:
40+
return "v3d-csd";
3941
default:
4042
return NULL;
4143
}

‎drivers/gpu/drm/v3d/v3d_gem.c‎

Lines changed: 151 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -162,10 +162,52 @@ v3d_flush_l2t(struct v3d_dev *v3d, int core)
162162
/* While there is a busy bit (V3D_L2TCACTL_L2TFLS), we don't
163163
* need to wait for completion before dispatching the job --
164164
* L2T accesses will be stalled until the flush has completed.
165+
* However, we do need to make sure we don't try to trigger a
166+
* new flush while the L2_CLEAN queue is trying to
167+
* synchronously clean after a job.
165168
*/
169+
mutex_lock(&v3d->cache_clean_lock);
166170
V3D_CORE_WRITE(core, V3D_CTL_L2TCACTL,
167171
V3D_L2TCACTL_L2TFLS |
168172
V3D_SET_FIELD(V3D_L2TCACTL_FLM_FLUSH, V3D_L2TCACTL_FLM));
173+
mutex_unlock(&v3d->cache_clean_lock);
174+
}
175+
176+
/* Cleans texture L1 and L2 cachelines (writing back dirty data).
177+
*
178+
* For cleaning, which happens from the CACHE_CLEAN queue after CSD has
179+
* executed, we need to make sure that the clean is done before
180+
* signaling job completion. So, we synchronously wait before
181+
* returning, and we make sure that L2 invalidates don't happen in the
182+
* meantime to confuse our are-we-done checks.
183+
*/
184+
void
185+
v3d_clean_caches(struct v3d_dev *v3d)
186+
{
187+
struct drm_device *dev = &v3d->drm;
188+
int core = 0;
189+
190+
trace_v3d_cache_clean_begin(dev);
191+
192+
V3D_CORE_WRITE(core, V3D_CTL_L2TCACTL, V3D_L2TCACTL_TMUWCF);
193+
if (wait_for(!(V3D_CORE_READ(core, V3D_CTL_L2TCACTL) &
194+
V3D_L2TCACTL_L2TFLS), 100)) {
195+
DRM_ERROR("Timeout waiting for L1T write combiner flush\n");
196+
}
197+
198+
mutex_lock(&v3d->cache_clean_lock);
199+
V3D_CORE_WRITE(core, V3D_CTL_L2TCACTL,
200+
V3D_L2TCACTL_L2TFLS |
201+
V3D_SET_FIELD(V3D_L2TCACTL_FLM_CLEAN, V3D_L2TCACTL_FLM));
202+
203+
if (wait_for(!(V3D_CORE_READ(core, V3D_CTL_L2TCACTL) &
204+
V3D_L2TCACTL_L2TFLS), 100)) {
205+
DRM_ERROR("Timeout waiting for L2T clean\n");
206+
}
207+
208+
mutex_unlock(&v3d->cache_clean_lock);
209+
210+
trace_v3d_cache_clean_end(dev);
169211
}
170212

171213
/* Invalidates the slice caches. These are read-only caches. */
@@ -429,7 +471,8 @@ static void
429471
v3d_attach_fences_and_unlock_reservation(struct drm_file *file_priv,
430472
struct v3d_job *job,
431473
struct ww_acquire_ctx *acquire_ctx,
432-
u32 out_sync)
474+
u32 out_sync,
475+
struct dma_fence *done_fence)
433476
{
434477
struct drm_syncobj *sync_out;
435478
int i;
@@ -445,7 +488,7 @@ v3d_attach_fences_and_unlock_reservation(struct drm_file *file_priv,
445488
/* Update the return sync object for the job */
446489
sync_out = drm_syncobj_find(file_priv, out_sync);
447490
if (sync_out) {
448-
drm_syncobj_replace_fence(sync_out, job->done_fence);
491+
drm_syncobj_replace_fence(sync_out, done_fence);
449492
drm_syncobj_put(sync_out);
450493
}
451494
}
@@ -541,8 +584,10 @@ v3d_submit_cl_ioctl(struct drm_device *dev, void *data,
541584
mutex_unlock(&v3d->sched_lock);
542585

543586
v3d_attach_fences_and_unlock_reservation(file_priv,
544-
&render->base, &acquire_ctx,
545-
args->out_sync);
587+
&render->base,
588+
&acquire_ctx,
589+
args->out_sync,
590+
render->base.done_fence);
546591

547592
if (bin)
548593
v3d_job_put(&bin->base);
@@ -641,7 +686,8 @@ v3d_submit_tfu_ioctl(struct drm_device *dev, void *data,
641686

642687
v3d_attach_fences_and_unlock_reservation(file_priv,
643688
&job->base, &acquire_ctx,
644-
args->out_sync);
689+
args->out_sync,
690+
job->base.done_fence);
645691

646692
v3d_job_put(&job->base);
647693

@@ -657,6 +703,105 @@ v3d_submit_tfu_ioctl(struct drm_device *dev, void *data,
657703
return ret;
658704
}
659705

706+
/**
707+
* v3d_submit_csd_ioctl() - Submits a CSD (texture formatting) job to the V3D.
708+
* @dev: DRM device
709+
* @data: ioctl argument
710+
* @file_priv: DRM file for this fd
711+
*
712+
* Userspace provides the register setup for the CSD, which we don't
713+
* need to validate since the CSD is behind the MMU.
714+
*/
715+
int
716+
v3d_submit_csd_ioctl(struct drm_device *dev, void *data,
717+
struct drm_file *file_priv)
718+
{
719+
struct v3d_dev *v3d = to_v3d_dev(dev);
720+
struct v3d_file_priv *v3d_priv = file_priv->driver_priv;
721+
struct drm_v3d_submit_csd *args = data;
722+
struct v3d_csd_job *job;
723+
struct v3d_job *clean_job;
724+
struct ww_acquire_ctx acquire_ctx;
725+
int ret;
726+
727+
trace_v3d_submit_csd_ioctl(&v3d->drm, args->cfg[5], args->cfg[6]);
728+
729+
if (!v3d_has_csd(v3d)) {
730+
DRM_DEBUG("Attempting CSD submit on non-CSD hardware\n");
731+
return -EINVAL;
732+
}
733+
734+
job = kcalloc(1, sizeof(*job), GFP_KERNEL);
735+
if (!job)
736+
return -ENOMEM;
737+
738+
ret = v3d_job_init(v3d, file_priv, &job->base,
739+
v3d_job_free, args->in_sync);
740+
if (ret) {
741+
kfree(job);
742+
return ret;
743+
}
744+
745+
clean_job = kcalloc(1, sizeof(*clean_job), GFP_KERNEL);
746+
if (!clean_job) {
747+
v3d_job_put(&job->base);
748+
kfree(job);
749+
return -ENOMEM;
750+
}
751+
752+
ret = v3d_job_init(v3d, file_priv, clean_job, v3d_job_free, 0);
753+
if (ret) {
754+
v3d_job_put(&job->base);
755+
kfree(clean_job);
756+
return ret;
757+
}
758+
759+
job->args = *args;
760+
761+
ret = v3d_lookup_bos(dev, file_priv, clean_job,
762+
args->bo_handles, args->bo_handle_count);
763+
if (ret)
764+
goto fail;
765+
766+
ret = v3d_lock_bo_reservations(clean_job->base.bo,
767+
clean_job->base.bo_count,
768+
&acquire_ctx);
769+
if (ret)
770+
goto fail;
771+
772+
mutex_lock(&v3d->sched_lock);
773+
ret = v3d_push_job(v3d_priv, &job->base, V3D_CSD);
774+
if (ret)
775+
goto fail_unreserve;
776+
777+
clean_job->in_fence = dma_fence_get(job->base.done_fence);
778+
ret = v3d_push_job(v3d_priv, clean_job, V3D_CACHE_CLEAN);
779+
if (ret)
780+
goto fail_unreserve;
781+
mutex_unlock(&v3d->sched_lock);
782+
783+
v3d_attach_fences_and_unlock_reservation(file_priv,
784+
clean_job,
785+
&acquire_ctx,
786+
args->out_sync,
787+
clean_job->done_fence);
788+
789+
v3d_job_put(&job->base);
790+
v3d_job_put(clean_job);
791+
792+
return 0;
793+
794+
fail_unreserve:
795+
mutex_unlock(&v3d->sched_lock);
796+
drm_gem_unlock_reservations(clean_job->bo, clean_job->bo_count,
797+
&acquire_ctx);
798+
fail:
799+
v3d_job_put(&job->base);
800+
v3d_job_put(clean_job);
801+
802+
return ret;
803+
}
804+
660805
int
661806
v3d_gem_init(struct drm_device *dev)
662807
{
@@ -672,6 +817,7 @@ v3d_gem_init(struct drm_device *dev)
672817
mutex_init(&v3d->bo_lock);
673818
mutex_init(&v3d->reset_lock);
674819
mutex_init(&v3d->sched_lock);
820+
mutex_init(&v3d->cache_clean_lock);
675821

676822
/* Note: We don't allocate address 0. Various bits of HW
677823
* treat 0 as special, such as the occlusion query counters

‎drivers/gpu/drm/v3d/v3d_irq.c‎

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@
44
/**
55
* DOC: Interrupt management for the V3D engine
66
*
7-
* When we take a bin, render, or TFU done interrupt, we need to
8-
* signal the fence for that job so that the scheduler can queue up
9-
* the next one and unblock any waiters.
7+
* When we take a bin, render, TFU done, or CSD done interrupt, we
8+
* need to signal the fence for that job so that the scheduler can
9+
* queue up the next one and unblock any waiters.
1010
*
1111
* When we take the binner out of memory interrupt, we need to
1212
* allocate some new memory and pass it to the binner so that the
@@ -20,6 +20,7 @@
2020
#define V3D_CORE_IRQS ((u32)(V3D_INT_OUTOMEM | \
2121
V3D_INT_FLDONE | \
2222
V3D_INT_FRDONE | \
23+
V3D_INT_CSDDONE | \
2324
V3D_INT_GMPV))
2425

2526
#define V3D_HUB_IRQS ((u32)(V3D_HUB_INT_MMU_WRV | \
@@ -112,6 +113,15 @@ v3d_irq(int irq, void *arg)
112113
status = IRQ_HANDLED;
113114
}
114115

116+
if (intsts & V3D_INT_CSDDONE) {
117+
struct v3d_fence *fence =
118+
to_v3d_fence(v3d->csd_job->base.irq_fence);
119+
120+
trace_v3d_csd_irq(&v3d->drm, fence->seqno);
121+
dma_fence_signal(&fence->base);
122+
status = IRQ_HANDLED;
123+
}
124+
115125
/* We shouldn't be triggering these if we have GMP in
116126
* always-allowed mode.
117127
*/

0 commit comments

Comments
 (0)