Skip to content

Commit b7589a9

Browse files
anholtpopcornmix
authored andcommitted
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 0fb7cb1 commit b7589a9

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
@@ -57,6 +57,17 @@ static const struct v3d_reg_def v3d_core_reg_defs[] = {
5757
REGDEF(V3D_GMP_VIO_ADDR),
5858
};
5959

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

93115
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>
@@ -114,6 +114,9 @@ static int v3d_get_param_ioctl(struct drm_device *dev, void *data,
114114
case DRM_V3D_PARAM_SUPPORTS_TFU:
115115
args->value = 1;
116116
return 0;
117+
case DRM_V3D_PARAM_SUPPORTS_CSD:
118+
args->value = v3d_has_csd(v3d);
119+
return 0;
117120
default:
118121
DRM_DEBUG("Unknown parameter %d\n", args->param);
119122
return -EINVAL;
@@ -183,6 +186,7 @@ static const struct drm_ioctl_desc v3d_drm_ioctls[] = {
183186
DRM_IOCTL_DEF_DRV(V3D_GET_PARAM, v3d_get_param_ioctl, DRM_RENDER_ALLOW),
184187
DRM_IOCTL_DEF_DRV(V3D_GET_BO_OFFSET, v3d_get_bo_offset_ioctl, DRM_RENDER_ALLOW),
185188
DRM_IOCTL_DEF_DRV(V3D_SUBMIT_TFU, v3d_submit_tfu_ioctl, DRM_RENDER_ALLOW | DRM_AUTH),
189+
DRM_IOCTL_DEF_DRV(V3D_SUBMIT_CSD, v3d_submit_csd_ioctl, DRM_RENDER_ALLOW | DRM_AUTH),
186190
};
187191

188192
static const struct vm_operations_struct v3d_vm_ops = {

‎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;
@@ -237,6 +252,14 @@ struct v3d_tfu_job {
237252
struct drm_v3d_submit_tfu args;
238253
};
239254

255+
struct v3d_csd_job {
256+
struct v3d_job base;
257+
258+
u32 timedout_batches;
259+
260+
struct drm_v3d_submit_csd args;
261+
};
262+
240263
/**
241264
* _wait_for - magic (register) wait macro
242265
*
@@ -302,11 +325,14 @@ int v3d_submit_cl_ioctl(struct drm_device *dev, void *data,
302325
struct drm_file *file_priv);
303326
int v3d_submit_tfu_ioctl(struct drm_device *dev, void *data,
304327
struct drm_file *file_priv);
328+
int v3d_submit_csd_ioctl(struct drm_device *dev, void *data,
329+
struct drm_file *file_priv);
305330
int v3d_wait_bo_ioctl(struct drm_device *dev, void *data,
306331
struct drm_file *file_priv);
307332
void v3d_job_put(struct v3d_job *job);
308333
void v3d_reset(struct v3d_dev *v3d);
309334
void v3d_invalidate_caches(struct v3d_dev *v3d);
335+
void v3d_clean_caches(struct v3d_dev *v3d);
310336

311337
/* v3d_irq.c */
312338
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. */
@@ -584,7 +626,8 @@ static void
584626
v3d_attach_fences_and_unlock_reservation(struct drm_file *file_priv,
585627
struct v3d_job *job,
586628
struct ww_acquire_ctx *acquire_ctx,
587-
u32 out_sync)
629+
u32 out_sync,
630+
struct dma_fence *done_fence)
588631
{
589632
struct drm_syncobj *sync_out;
590633

@@ -594,7 +637,7 @@ v3d_attach_fences_and_unlock_reservation(struct drm_file *file_priv,
594637
/* Update the return sync object for the job */
595638
sync_out = drm_syncobj_find(file_priv, out_sync);
596639
if (sync_out) {
597-
drm_syncobj_replace_fence(sync_out, job->done_fence);
640+
drm_syncobj_replace_fence(sync_out, done_fence);
598641
drm_syncobj_put(sync_out);
599642
}
600643
}
@@ -691,8 +734,10 @@ v3d_submit_cl_ioctl(struct drm_device *dev, void *data,
691734
mutex_unlock(&v3d->sched_lock);
692735

693736
v3d_attach_fences_and_unlock_reservation(file_priv,
694-
&render->base, &acquire_ctx,
695-
args->out_sync);
737+
&render->base,
738+
&acquire_ctx,
739+
args->out_sync,
740+
render->base.done_fence);
696741

697742
if (bin)
698743
v3d_job_put(&bin->base);
@@ -785,7 +830,8 @@ v3d_submit_tfu_ioctl(struct drm_device *dev, void *data,
785830

786831
v3d_attach_fences_and_unlock_reservation(file_priv,
787832
&job->base, &acquire_ctx,
788-
args->out_sync);
833+
args->out_sync,
834+
job->base.done_fence);
789835

790836
v3d_job_put(&job->base);
791837

@@ -801,6 +847,105 @@ v3d_submit_tfu_ioctl(struct drm_device *dev, void *data,
801847
return ret;
802848
}
803849

850+
/**
851+
* v3d_submit_csd_ioctl() - Submits a CSD (texture formatting) job to the V3D.
852+
* @dev: DRM device
853+
* @data: ioctl argument
854+
* @file_priv: DRM file for this fd
855+
*
856+
* Userspace provides the register setup for the CSD, which we don't
857+
* need to validate since the CSD is behind the MMU.
858+
*/
859+
int
860+
v3d_submit_csd_ioctl(struct drm_device *dev, void *data,
861+
struct drm_file *file_priv)
862+
{
863+
struct v3d_dev *v3d = to_v3d_dev(dev);
864+
struct v3d_file_priv *v3d_priv = file_priv->driver_priv;
865+
struct drm_v3d_submit_csd *args = data;
866+
struct v3d_csd_job *job;
867+
struct v3d_job *clean_job;
868+
struct ww_acquire_ctx acquire_ctx;
869+
int ret;
870+
871+
trace_v3d_submit_csd_ioctl(&v3d->drm, args->cfg[5], args->cfg[6]);
872+
873+
if (!v3d_has_csd(v3d)) {
874+
DRM_DEBUG("Attempting CSD submit on non-CSD hardware\n");
875+
return -EINVAL;
876+
}
877+
878+
job = kcalloc(1, sizeof(*job), GFP_KERNEL);
879+
if (!job)
880+
return -ENOMEM;
881+
882+
ret = v3d_job_init(v3d, file_priv, &job->base,
883+
v3d_job_free, args->in_sync);
884+
if (ret) {
885+
kfree(job);
886+
return ret;
887+
}
888+
889+
clean_job = kcalloc(1, sizeof(*clean_job), GFP_KERNEL);
890+
if (!clean_job) {
891+
v3d_job_put(&job->base);
892+
kfree(job);
893+
return -ENOMEM;
894+
}
895+
896+
ret = v3d_job_init(v3d, file_priv, clean_job, v3d_job_free, 0);
897+
if (ret) {
898+
v3d_job_put(&job->base);
899+
kfree(clean_job);
900+
return ret;
901+
}
902+
903+
job->args = *args;
904+
905+
ret = v3d_lookup_bos(dev, file_priv, clean_job,
906+
args->bo_handles, args->bo_handle_count);
907+
if (ret)
908+
goto fail;
909+
910+
ret = v3d_lock_bo_reservations(clean_job, &acquire_ctx);
911+
if (ret)
912+
goto fail;
913+
914+
mutex_lock(&v3d->sched_lock);
915+
ret = v3d_push_job(v3d_priv, &job->base, V3D_CSD);
916+
if (ret)
917+
goto fail_unreserve;
918+
919+
ret = v3d_add_dep(clean_job, dma_fence_get(job->base.done_fence));
920+
if (ret)
921+
goto fail_unreserve;
922+
ret = v3d_push_job(v3d_priv, clean_job, V3D_CACHE_CLEAN);
923+
if (ret)
924+
goto fail_unreserve;
925+
mutex_unlock(&v3d->sched_lock);
926+
927+
v3d_attach_fences_and_unlock_reservation(file_priv,
928+
clean_job,
929+
&acquire_ctx,
930+
args->out_sync,
931+
clean_job->done_fence);
932+
933+
v3d_job_put(&job->base);
934+
v3d_job_put(clean_job);
935+
936+
return 0;
937+
938+
fail_unreserve:
939+
mutex_unlock(&v3d->sched_lock);
940+
v3d_unlock_bo_reservations(clean_job->bo, clean_job->bo_count,
941+
&acquire_ctx);
942+
fail:
943+
v3d_job_put(&job->base);
944+
v3d_job_put(clean_job);
945+
946+
return ret;
947+
}
948+
804949
int
805950
v3d_gem_init(struct drm_device *dev)
806951
{
@@ -816,6 +961,7 @@ v3d_gem_init(struct drm_device *dev)
816961
mutex_init(&v3d->bo_lock);
817962
mutex_init(&v3d->reset_lock);
818963
mutex_init(&v3d->sched_lock);
964+
mutex_init(&v3d->cache_clean_lock);
819965

820966
/* Note: We don't allocate address 0. Various bits of HW
821967
* 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 | \
@@ -109,6 +110,15 @@ v3d_irq(int irq, void *arg)
109110
status = IRQ_HANDLED;
110111
}
111112

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

0 commit comments

Comments
 (0)