Skip to content

Commit d5b1a78

Browse files
committed
drm/vc4: Add support for drawing 3D frames.
The user submission is basically a pointer to a command list and a pointer to uniforms. We copy those in to the kernel, validate and relocate them, and store the result in a GPU BO which we queue for execution. v2: Drop support for NV shader recs (not necessary for GL), simplify vc4_use_bo(), improve bin flush/semaphore checks, use __u32 style types. Signed-off-by: Eric Anholt <[email protected]>
1 parent d3f5168 commit d5b1a78

File tree

12 files changed

+3243
-1
lines changed

12 files changed

+3243
-1
lines changed

drivers/gpu/drm/vc4/Makefile

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,19 @@ vc4-y := \
88
vc4_crtc.o \
99
vc4_drv.o \
1010
vc4_kms.o \
11+
vc4_gem.o \
1112
vc4_hdmi.o \
1213
vc4_hvs.o \
14+
vc4_irq.o \
1315
vc4_plane.o \
16+
vc4_render_cl.o \
17+
vc4_trace_points.o \
1418
vc4_v3d.o \
19+
vc4_validate.o \
1520
vc4_validate_shaders.o
1621

1722
vc4-$(CONFIG_DEBUG_FS) += vc4_debugfs.o
1823

1924
obj-$(CONFIG_DRM_VC4) += vc4.o
25+
26+
CFLAGS_vc4_trace_points.o := -I$(src)

drivers/gpu/drm/vc4/vc4_drv.c

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,9 @@ static const struct file_operations vc4_drm_fops = {
7474
};
7575

7676
static const struct drm_ioctl_desc vc4_drm_ioctls[] = {
77+
DRM_IOCTL_DEF_DRV(VC4_SUBMIT_CL, vc4_submit_cl_ioctl, 0),
78+
DRM_IOCTL_DEF_DRV(VC4_WAIT_SEQNO, vc4_wait_seqno_ioctl, 0),
79+
DRM_IOCTL_DEF_DRV(VC4_WAIT_BO, vc4_wait_bo_ioctl, 0),
7780
DRM_IOCTL_DEF_DRV(VC4_CREATE_BO, vc4_create_bo_ioctl, 0),
7881
DRM_IOCTL_DEF_DRV(VC4_MMAP_BO, vc4_mmap_bo_ioctl, 0),
7982
DRM_IOCTL_DEF_DRV(VC4_CREATE_SHADER_BO, vc4_create_shader_bo_ioctl, 0),
@@ -83,10 +86,16 @@ static struct drm_driver vc4_drm_driver = {
8386
.driver_features = (DRIVER_MODESET |
8487
DRIVER_ATOMIC |
8588
DRIVER_GEM |
89+
DRIVER_HAVE_IRQ |
8690
DRIVER_PRIME),
8791
.lastclose = vc4_lastclose,
8892
.preclose = vc4_drm_preclose,
8993

94+
.irq_handler = vc4_irq,
95+
.irq_preinstall = vc4_irq_preinstall,
96+
.irq_postinstall = vc4_irq_postinstall,
97+
.irq_uninstall = vc4_irq_uninstall,
98+
9099
.enable_vblank = vc4_enable_vblank,
91100
.disable_vblank = vc4_disable_vblank,
92101
.get_vblank_counter = drm_vblank_count,
@@ -181,9 +190,11 @@ static int vc4_drm_bind(struct device *dev)
181190
if (ret)
182191
goto unref;
183192

193+
vc4_gem_init(drm);
194+
184195
ret = component_bind_all(dev, drm);
185196
if (ret)
186-
goto unref;
197+
goto gem_destroy;
187198

188199
ret = drm_dev_register(drm, 0);
189200
if (ret < 0)
@@ -207,6 +218,8 @@ static int vc4_drm_bind(struct device *dev)
207218
drm_dev_unregister(drm);
208219
unbind_all:
209220
component_unbind_all(dev, drm);
221+
gem_destroy:
222+
vc4_gem_destroy(drm);
210223
unref:
211224
drm_dev_unref(drm);
212225
vc4_bo_cache_destroy(drm);

drivers/gpu/drm/vc4/vc4_drv.h

Lines changed: 182 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,48 @@ struct vc4_dev {
4949

5050
/* Protects bo_cache and the BO stats. */
5151
struct mutex bo_lock;
52+
53+
/* Sequence number for the last job queued in job_list.
54+
* Starts at 0 (no jobs emitted).
55+
*/
56+
uint64_t emit_seqno;
57+
58+
/* Sequence number for the last completed job on the GPU.
59+
* Starts at 0 (no jobs completed).
60+
*/
61+
uint64_t finished_seqno;
62+
63+
/* List of all struct vc4_exec_info for jobs to be executed.
64+
* The first job in the list is the one currently programmed
65+
* into ct0ca/ct1ca for execution.
66+
*/
67+
struct list_head job_list;
68+
/* List of the finished vc4_exec_infos waiting to be freed by
69+
* job_done_work.
70+
*/
71+
struct list_head job_done_list;
72+
/* Spinlock used to synchronize the job_list and seqno
73+
* accesses between the IRQ handler and GEM ioctls.
74+
*/
75+
spinlock_t job_lock;
76+
wait_queue_head_t job_wait_queue;
77+
struct work_struct job_done_work;
78+
79+
/* The binner overflow memory that's currently set up in
80+
* BPOA/BPOS registers. When overflow occurs and a new one is
81+
* allocated, the previous one will be moved to
82+
* vc4->current_exec's free list.
83+
*/
84+
struct vc4_bo *overflow_mem;
85+
struct work_struct overflow_mem_work;
86+
87+
struct {
88+
uint32_t last_ct0ca, last_ct1ca;
89+
struct timer_list timer;
90+
struct work_struct reset_work;
91+
} hangcheck;
92+
93+
struct semaphore async_modeset;
5294
};
5395

5496
static inline struct vc4_dev *
@@ -60,6 +102,9 @@ to_vc4_dev(struct drm_device *dev)
60102
struct vc4_bo {
61103
struct drm_gem_cma_object base;
62104

105+
/* seqno of the last job to render to this BO. */
106+
uint64_t seqno;
107+
63108
/* List entry for the BO's position in either
64109
* vc4_exec_info->unref_list or vc4_dev->bo_cache.time_list
65110
*/
@@ -130,6 +175,101 @@ to_vc4_encoder(struct drm_encoder *encoder)
130175
#define HVS_READ(offset) readl(vc4->hvs->regs + offset)
131176
#define HVS_WRITE(offset, val) writel(val, vc4->hvs->regs + offset)
132177

178+
struct vc4_exec_info {
179+
/* Sequence number for this bin/render job. */
180+
uint64_t seqno;
181+
182+
/* Kernel-space copy of the ioctl arguments */
183+
struct drm_vc4_submit_cl *args;
184+
185+
/* This is the array of BOs that were looked up at the start of exec.
186+
* Command validation will use indices into this array.
187+
*/
188+
struct drm_gem_cma_object **bo;
189+
uint32_t bo_count;
190+
191+
/* Pointers for our position in vc4->job_list */
192+
struct list_head head;
193+
194+
/* List of other BOs used in the job that need to be released
195+
* once the job is complete.
196+
*/
197+
struct list_head unref_list;
198+
199+
/* Current unvalidated indices into @bo loaded by the non-hardware
200+
* VC4_PACKET_GEM_HANDLES.
201+
*/
202+
uint32_t bo_index[2];
203+
204+
/* This is the BO where we store the validated command lists, shader
205+
* records, and uniforms.
206+
*/
207+
struct drm_gem_cma_object *exec_bo;
208+
209+
/**
210+
* This tracks the per-shader-record state (packet 64) that
211+
* determines the length of the shader record and the offset
212+
* it's expected to be found at. It gets read in from the
213+
* command lists.
214+
*/
215+
struct vc4_shader_state {
216+
uint32_t addr;
217+
/* Maximum vertex index referenced by any primitive using this
218+
* shader state.
219+
*/
220+
uint32_t max_index;
221+
} *shader_state;
222+
223+
/** How many shader states the user declared they were using. */
224+
uint32_t shader_state_size;
225+
/** How many shader state records the validator has seen. */
226+
uint32_t shader_state_count;
227+
228+
bool found_tile_binning_mode_config_packet;
229+
bool found_start_tile_binning_packet;
230+
bool found_increment_semaphore_packet;
231+
bool found_flush;
232+
uint8_t bin_tiles_x, bin_tiles_y;
233+
struct drm_gem_cma_object *tile_bo;
234+
uint32_t tile_alloc_offset;
235+
236+
/**
237+
* Computed addresses pointing into exec_bo where we start the
238+
* bin thread (ct0) and render thread (ct1).
239+
*/
240+
uint32_t ct0ca, ct0ea;
241+
uint32_t ct1ca, ct1ea;
242+
243+
/* Pointer to the unvalidated bin CL (if present). */
244+
void *bin_u;
245+
246+
/* Pointers to the shader recs. These paddr gets incremented as CL
247+
* packets are relocated in validate_gl_shader_state, and the vaddrs
248+
* (u and v) get incremented and size decremented as the shader recs
249+
* themselves are validated.
250+
*/
251+
void *shader_rec_u;
252+
void *shader_rec_v;
253+
uint32_t shader_rec_p;
254+
uint32_t shader_rec_size;
255+
256+
/* Pointers to the uniform data. These pointers are incremented, and
257+
* size decremented, as each batch of uniforms is uploaded.
258+
*/
259+
void *uniforms_u;
260+
void *uniforms_v;
261+
uint32_t uniforms_p;
262+
uint32_t uniforms_size;
263+
};
264+
265+
static inline struct vc4_exec_info *
266+
vc4_first_job(struct vc4_dev *vc4)
267+
{
268+
if (list_empty(&vc4->job_list))
269+
return NULL;
270+
return list_first_entry(&vc4->job_list, struct vc4_exec_info, head);
271+
}
272+
133273
/**
134274
* struct vc4_texture_sample_info - saves the offsets into the UBO for texture
135275
* setup parameters.
@@ -231,10 +371,31 @@ void vc4_debugfs_cleanup(struct drm_minor *minor);
231371
/* vc4_drv.c */
232372
void __iomem *vc4_ioremap_regs(struct platform_device *dev, int index);
233373

374+
/* vc4_gem.c */
375+
void vc4_gem_init(struct drm_device *dev);
376+
void vc4_gem_destroy(struct drm_device *dev);
377+
int vc4_submit_cl_ioctl(struct drm_device *dev, void *data,
378+
struct drm_file *file_priv);
379+
int vc4_wait_seqno_ioctl(struct drm_device *dev, void *data,
380+
struct drm_file *file_priv);
381+
int vc4_wait_bo_ioctl(struct drm_device *dev, void *data,
382+
struct drm_file *file_priv);
383+
void vc4_submit_next_job(struct drm_device *dev);
384+
int vc4_wait_for_seqno(struct drm_device *dev, uint64_t seqno,
385+
uint64_t timeout_ns, bool interruptible);
386+
void vc4_job_handle_completed(struct vc4_dev *vc4);
387+
234388
/* vc4_hdmi.c */
235389
extern struct platform_driver vc4_hdmi_driver;
236390
int vc4_hdmi_debugfs_regs(struct seq_file *m, void *unused);
237391

392+
/* vc4_irq.c */
393+
irqreturn_t vc4_irq(int irq, void *arg);
394+
void vc4_irq_preinstall(struct drm_device *dev);
395+
int vc4_irq_postinstall(struct drm_device *dev);
396+
void vc4_irq_uninstall(struct drm_device *dev);
397+
void vc4_irq_reset(struct drm_device *dev);
398+
238399
/* vc4_hvs.c */
239400
extern struct platform_driver vc4_hvs_driver;
240401
void vc4_hvs_dump_state(struct drm_device *dev);
@@ -253,6 +414,27 @@ u32 vc4_plane_dlist_size(struct drm_plane_state *state);
253414
extern struct platform_driver vc4_v3d_driver;
254415
int vc4_v3d_debugfs_ident(struct seq_file *m, void *unused);
255416
int vc4_v3d_debugfs_regs(struct seq_file *m, void *unused);
417+
int vc4_v3d_set_power(struct vc4_dev *vc4, bool on);
418+
419+
/* vc4_validate.c */
420+
int
421+
vc4_validate_bin_cl(struct drm_device *dev,
422+
void *validated,
423+
void *unvalidated,
424+
struct vc4_exec_info *exec);
425+
426+
int
427+
vc4_validate_shader_recs(struct drm_device *dev, struct vc4_exec_info *exec);
428+
429+
struct drm_gem_cma_object *vc4_use_bo(struct vc4_exec_info *exec,
430+
uint32_t hindex);
431+
432+
int vc4_get_rcl(struct drm_device *dev, struct vc4_exec_info *exec);
433+
434+
bool vc4_check_tex_size(struct vc4_exec_info *exec,
435+
struct drm_gem_cma_object *fbo,
436+
uint32_t offset, uint8_t tiling_format,
437+
uint32_t width, uint32_t height, uint8_t cpp);
256438

257439
/* vc4_validate_shader.c */
258440
struct vc4_validated_shader_info *

0 commit comments

Comments
 (0)