Skip to content

Commit 30f8c74

Browse files
committed
drm/vc4: Warn if some v3d code is run on BCM2711
The BCM2711 has a separate driver for the v3d, and thus we can't call into any of the driver entrypoints that rely on the v3d being there. Let's add a bunch of checks and complain loudly if that ever happen. Reviewed-by: Melissa Wen <[email protected]> Signed-off-by: Maxime Ripard <[email protected]> Link: https://lore.kernel.org/r/[email protected]
1 parent d19e00e commit 30f8c74

File tree

11 files changed

+211
-1
lines changed

11 files changed

+211
-1
lines changed

drivers/gpu/drm/vc4/vc4_bo.c

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -248,6 +248,9 @@ void vc4_bo_add_to_purgeable_pool(struct vc4_bo *bo)
248248
{
249249
struct vc4_dev *vc4 = to_vc4_dev(bo->base.base.dev);
250250

251+
if (WARN_ON_ONCE(vc4->is_vc5))
252+
return;
253+
251254
mutex_lock(&vc4->purgeable.lock);
252255
list_add_tail(&bo->size_head, &vc4->purgeable.list);
253256
vc4->purgeable.num++;
@@ -259,6 +262,9 @@ static void vc4_bo_remove_from_purgeable_pool_locked(struct vc4_bo *bo)
259262
{
260263
struct vc4_dev *vc4 = to_vc4_dev(bo->base.base.dev);
261264

265+
if (WARN_ON_ONCE(vc4->is_vc5))
266+
return;
267+
262268
/* list_del_init() is used here because the caller might release
263269
* the purgeable lock in order to acquire the madv one and update the
264270
* madv status.
@@ -387,6 +393,9 @@ struct drm_gem_object *vc4_create_object(struct drm_device *dev, size_t size)
387393
struct vc4_dev *vc4 = to_vc4_dev(dev);
388394
struct vc4_bo *bo;
389395

396+
if (WARN_ON_ONCE(vc4->is_vc5))
397+
return ERR_PTR(-ENODEV);
398+
390399
bo = kzalloc(sizeof(*bo), GFP_KERNEL);
391400
if (!bo)
392401
return ERR_PTR(-ENOMEM);
@@ -413,6 +422,9 @@ struct vc4_bo *vc4_bo_create(struct drm_device *dev, size_t unaligned_size,
413422
struct drm_gem_cma_object *cma_obj;
414423
struct vc4_bo *bo;
415424

425+
if (WARN_ON_ONCE(vc4->is_vc5))
426+
return ERR_PTR(-ENODEV);
427+
416428
if (size == 0)
417429
return ERR_PTR(-EINVAL);
418430

@@ -475,9 +487,13 @@ int vc4_bo_dumb_create(struct drm_file *file_priv,
475487
struct drm_device *dev,
476488
struct drm_mode_create_dumb *args)
477489
{
490+
struct vc4_dev *vc4 = to_vc4_dev(dev);
478491
struct vc4_bo *bo = NULL;
479492
int ret;
480493

494+
if (WARN_ON_ONCE(vc4->is_vc5))
495+
return -ENODEV;
496+
481497
ret = vc4_dumb_fixup_args(args);
482498
if (ret)
483499
return ret;
@@ -598,8 +614,12 @@ static void vc4_bo_cache_time_work(struct work_struct *work)
598614

599615
int vc4_bo_inc_usecnt(struct vc4_bo *bo)
600616
{
617+
struct vc4_dev *vc4 = to_vc4_dev(bo->base.base.dev);
601618
int ret;
602619

620+
if (WARN_ON_ONCE(vc4->is_vc5))
621+
return -ENODEV;
622+
603623
/* Fast path: if the BO is already retained by someone, no need to
604624
* check the madv status.
605625
*/
@@ -634,6 +654,11 @@ int vc4_bo_inc_usecnt(struct vc4_bo *bo)
634654

635655
void vc4_bo_dec_usecnt(struct vc4_bo *bo)
636656
{
657+
struct vc4_dev *vc4 = to_vc4_dev(bo->base.base.dev);
658+
659+
if (WARN_ON_ONCE(vc4->is_vc5))
660+
return;
661+
637662
/* Fast path: if the BO is still retained by someone, no need to test
638663
* the madv value.
639664
*/
@@ -753,6 +778,9 @@ int vc4_create_bo_ioctl(struct drm_device *dev, void *data,
753778
struct vc4_bo *bo = NULL;
754779
int ret;
755780

781+
if (WARN_ON_ONCE(vc4->is_vc5))
782+
return -ENODEV;
783+
756784
ret = vc4_grab_bin_bo(vc4, vc4file);
757785
if (ret)
758786
return ret;
@@ -776,9 +804,13 @@ int vc4_create_bo_ioctl(struct drm_device *dev, void *data,
776804
int vc4_mmap_bo_ioctl(struct drm_device *dev, void *data,
777805
struct drm_file *file_priv)
778806
{
807+
struct vc4_dev *vc4 = to_vc4_dev(dev);
779808
struct drm_vc4_mmap_bo *args = data;
780809
struct drm_gem_object *gem_obj;
781810

811+
if (WARN_ON_ONCE(vc4->is_vc5))
812+
return -ENODEV;
813+
782814
gem_obj = drm_gem_object_lookup(file_priv, args->handle);
783815
if (!gem_obj) {
784816
DRM_DEBUG("Failed to look up GEM BO %d\n", args->handle);
@@ -802,6 +834,9 @@ vc4_create_shader_bo_ioctl(struct drm_device *dev, void *data,
802834
struct vc4_bo *bo = NULL;
803835
int ret;
804836

837+
if (WARN_ON_ONCE(vc4->is_vc5))
838+
return -ENODEV;
839+
805840
if (args->size == 0)
806841
return -EINVAL;
807842

@@ -872,11 +907,15 @@ vc4_create_shader_bo_ioctl(struct drm_device *dev, void *data,
872907
int vc4_set_tiling_ioctl(struct drm_device *dev, void *data,
873908
struct drm_file *file_priv)
874909
{
910+
struct vc4_dev *vc4 = to_vc4_dev(dev);
875911
struct drm_vc4_set_tiling *args = data;
876912
struct drm_gem_object *gem_obj;
877913
struct vc4_bo *bo;
878914
bool t_format;
879915

916+
if (WARN_ON_ONCE(vc4->is_vc5))
917+
return -ENODEV;
918+
880919
if (args->flags != 0)
881920
return -EINVAL;
882921

@@ -915,10 +954,14 @@ int vc4_set_tiling_ioctl(struct drm_device *dev, void *data,
915954
int vc4_get_tiling_ioctl(struct drm_device *dev, void *data,
916955
struct drm_file *file_priv)
917956
{
957+
struct vc4_dev *vc4 = to_vc4_dev(dev);
918958
struct drm_vc4_get_tiling *args = data;
919959
struct drm_gem_object *gem_obj;
920960
struct vc4_bo *bo;
921961

962+
if (WARN_ON_ONCE(vc4->is_vc5))
963+
return -ENODEV;
964+
922965
if (args->flags != 0 || args->modifier != 0)
923966
return -EINVAL;
924967

@@ -945,6 +988,9 @@ int vc4_bo_cache_init(struct drm_device *dev)
945988
struct vc4_dev *vc4 = to_vc4_dev(dev);
946989
int i;
947990

991+
if (WARN_ON_ONCE(vc4->is_vc5))
992+
return -ENODEV;
993+
948994
/* Create the initial set of BO labels that the kernel will
949995
* use. This lets us avoid a bunch of string reallocation in
950996
* the kernel's draw and BO allocation paths.
@@ -1004,6 +1050,9 @@ int vc4_label_bo_ioctl(struct drm_device *dev, void *data,
10041050
struct drm_gem_object *gem_obj;
10051051
int ret = 0, label;
10061052

1053+
if (WARN_ON_ONCE(vc4->is_vc5))
1054+
return -ENODEV;
1055+
10071056
if (!args->len)
10081057
return -EINVAL;
10091058

drivers/gpu/drm/vc4/vc4_drv.c

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,9 @@ static int vc4_get_param_ioctl(struct drm_device *dev, void *data,
9999
if (args->pad != 0)
100100
return -EINVAL;
101101

102+
if (WARN_ON_ONCE(vc4->is_vc5))
103+
return -ENODEV;
104+
102105
if (!vc4->v3d)
103106
return -ENODEV;
104107

@@ -142,11 +145,16 @@ static int vc4_get_param_ioctl(struct drm_device *dev, void *data,
142145

143146
static int vc4_open(struct drm_device *dev, struct drm_file *file)
144147
{
148+
struct vc4_dev *vc4 = to_vc4_dev(dev);
145149
struct vc4_file *vc4file;
146150

151+
if (WARN_ON_ONCE(vc4->is_vc5))
152+
return -ENODEV;
153+
147154
vc4file = kzalloc(sizeof(*vc4file), GFP_KERNEL);
148155
if (!vc4file)
149156
return -ENOMEM;
157+
vc4file->dev = vc4;
150158

151159
vc4_perfmon_open_file(vc4file);
152160
file->driver_priv = vc4file;
@@ -158,6 +166,9 @@ static void vc4_close(struct drm_device *dev, struct drm_file *file)
158166
struct vc4_dev *vc4 = to_vc4_dev(dev);
159167
struct vc4_file *vc4file = file->driver_priv;
160168

169+
if (WARN_ON_ONCE(vc4->is_vc5))
170+
return;
171+
161172
if (vc4file->bin_bo_used)
162173
vc4_v3d_bin_bo_put(vc4);
163174

drivers/gpu/drm/vc4/vc4_drv.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,8 @@ enum vc4_kernel_bo_type {
4848
* done. This way, only events related to a specific job will be counted.
4949
*/
5050
struct vc4_perfmon {
51+
struct vc4_dev *dev;
52+
5153
/* Tracks the number of users of the perfmon, when this counter reaches
5254
* zero the perfmon is destroyed.
5355
*/
@@ -580,6 +582,8 @@ to_vc4_crtc_state(struct drm_crtc_state *crtc_state)
580582
#define VC4_REG32(reg) { .name = #reg, .offset = reg }
581583

582584
struct vc4_exec_info {
585+
struct vc4_dev *dev;
586+
583587
/* Sequence number for this bin/render job. */
584588
uint64_t seqno;
585589

@@ -701,6 +705,8 @@ struct vc4_exec_info {
701705
* released when the DRM file is closed should be placed here.
702706
*/
703707
struct vc4_file {
708+
struct vc4_dev *dev;
709+
704710
struct {
705711
struct idr idr;
706712
struct mutex lock;

drivers/gpu/drm/vc4/vc4_gem.c

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,9 @@ vc4_get_hang_state_ioctl(struct drm_device *dev, void *data,
7676
u32 i;
7777
int ret = 0;
7878

79+
if (WARN_ON_ONCE(vc4->is_vc5))
80+
return -ENODEV;
81+
7982
if (!vc4->v3d) {
8083
DRM_DEBUG("VC4_GET_HANG_STATE with no VC4 V3D probed\n");
8184
return -ENODEV;
@@ -386,6 +389,9 @@ vc4_wait_for_seqno(struct drm_device *dev, uint64_t seqno, uint64_t timeout_ns,
386389
unsigned long timeout_expire;
387390
DEFINE_WAIT(wait);
388391

392+
if (WARN_ON_ONCE(vc4->is_vc5))
393+
return -ENODEV;
394+
389395
if (vc4->finished_seqno >= seqno)
390396
return 0;
391397

@@ -468,6 +474,9 @@ vc4_submit_next_bin_job(struct drm_device *dev)
468474
struct vc4_dev *vc4 = to_vc4_dev(dev);
469475
struct vc4_exec_info *exec;
470476

477+
if (WARN_ON_ONCE(vc4->is_vc5))
478+
return;
479+
471480
again:
472481
exec = vc4_first_bin_job(vc4);
473482
if (!exec)
@@ -513,6 +522,9 @@ vc4_submit_next_render_job(struct drm_device *dev)
513522
if (!exec)
514523
return;
515524

525+
if (WARN_ON_ONCE(vc4->is_vc5))
526+
return;
527+
516528
/* A previous RCL may have written to one of our textures, and
517529
* our full cache flush at bin time may have occurred before
518530
* that RCL completed. Flush the texture cache now, but not
@@ -531,6 +543,9 @@ vc4_move_job_to_render(struct drm_device *dev, struct vc4_exec_info *exec)
531543
struct vc4_dev *vc4 = to_vc4_dev(dev);
532544
bool was_empty = list_empty(&vc4->render_job_list);
533545

546+
if (WARN_ON_ONCE(vc4->is_vc5))
547+
return;
548+
534549
list_move_tail(&exec->head, &vc4->render_job_list);
535550
if (was_empty)
536551
vc4_submit_next_render_job(dev);
@@ -997,6 +1012,9 @@ vc4_job_handle_completed(struct vc4_dev *vc4)
9971012
unsigned long irqflags;
9981013
struct vc4_seqno_cb *cb, *cb_temp;
9991014

1015+
if (WARN_ON_ONCE(vc4->is_vc5))
1016+
return;
1017+
10001018
spin_lock_irqsave(&vc4->job_lock, irqflags);
10011019
while (!list_empty(&vc4->job_done_list)) {
10021020
struct vc4_exec_info *exec =
@@ -1033,6 +1051,9 @@ int vc4_queue_seqno_cb(struct drm_device *dev,
10331051
struct vc4_dev *vc4 = to_vc4_dev(dev);
10341052
unsigned long irqflags;
10351053

1054+
if (WARN_ON_ONCE(vc4->is_vc5))
1055+
return -ENODEV;
1056+
10361057
cb->func = func;
10371058
INIT_WORK(&cb->work, vc4_seqno_cb_work);
10381059

@@ -1083,8 +1104,12 @@ int
10831104
vc4_wait_seqno_ioctl(struct drm_device *dev, void *data,
10841105
struct drm_file *file_priv)
10851106
{
1107+
struct vc4_dev *vc4 = to_vc4_dev(dev);
10861108
struct drm_vc4_wait_seqno *args = data;
10871109

1110+
if (WARN_ON_ONCE(vc4->is_vc5))
1111+
return -ENODEV;
1112+
10881113
return vc4_wait_for_seqno_ioctl_helper(dev, args->seqno,
10891114
&args->timeout_ns);
10901115
}
@@ -1093,11 +1118,15 @@ int
10931118
vc4_wait_bo_ioctl(struct drm_device *dev, void *data,
10941119
struct drm_file *file_priv)
10951120
{
1121+
struct vc4_dev *vc4 = to_vc4_dev(dev);
10961122
int ret;
10971123
struct drm_vc4_wait_bo *args = data;
10981124
struct drm_gem_object *gem_obj;
10991125
struct vc4_bo *bo;
11001126

1127+
if (WARN_ON_ONCE(vc4->is_vc5))
1128+
return -ENODEV;
1129+
11011130
if (args->pad != 0)
11021131
return -EINVAL;
11031132

@@ -1144,6 +1173,9 @@ vc4_submit_cl_ioctl(struct drm_device *dev, void *data,
11441173
args->shader_rec_size,
11451174
args->bo_handle_count);
11461175

1176+
if (WARN_ON_ONCE(vc4->is_vc5))
1177+
return -ENODEV;
1178+
11471179
if (!vc4->v3d) {
11481180
DRM_DEBUG("VC4_SUBMIT_CL with no VC4 V3D probed\n");
11491181
return -ENODEV;
@@ -1167,6 +1199,7 @@ vc4_submit_cl_ioctl(struct drm_device *dev, void *data,
11671199
DRM_ERROR("malloc failure on exec struct\n");
11681200
return -ENOMEM;
11691201
}
1202+
exec->dev = vc4;
11701203

11711204
ret = vc4_v3d_pm_get(vc4);
11721205
if (ret) {
@@ -1276,6 +1309,9 @@ int vc4_gem_init(struct drm_device *dev)
12761309
{
12771310
struct vc4_dev *vc4 = to_vc4_dev(dev);
12781311

1312+
if (WARN_ON_ONCE(vc4->is_vc5))
1313+
return -ENODEV;
1314+
12791315
vc4->dma_fence_context = dma_fence_context_alloc(1);
12801316

12811317
INIT_LIST_HEAD(&vc4->bin_job_list);
@@ -1321,11 +1357,15 @@ static void vc4_gem_destroy(struct drm_device *dev, void *unused)
13211357
int vc4_gem_madvise_ioctl(struct drm_device *dev, void *data,
13221358
struct drm_file *file_priv)
13231359
{
1360+
struct vc4_dev *vc4 = to_vc4_dev(dev);
13241361
struct drm_vc4_gem_madvise *args = data;
13251362
struct drm_gem_object *gem_obj;
13261363
struct vc4_bo *bo;
13271364
int ret;
13281365

1366+
if (WARN_ON_ONCE(vc4->is_vc5))
1367+
return -ENODEV;
1368+
13291369
switch (args->madv) {
13301370
case VC4_MADV_DONTNEED:
13311371
case VC4_MADV_WILLNEED:

0 commit comments

Comments
 (0)