@@ -172,8 +172,6 @@ struct pispbe_node {
172
172
struct mutex node_lock ;
173
173
/* vb2_queue lock */
174
174
struct mutex queue_lock ;
175
- /* Protect pispbe_node->ready_queue and pispbe_buffer->ready_list */
176
- spinlock_t ready_lock ;
177
175
struct list_head ready_queue ;
178
176
struct vb2_queue queue ;
179
177
struct v4l2_format format ;
@@ -219,6 +217,9 @@ struct pispbe_hw_enables {
219
217
220
218
/* Records a job configuration and memory addresses. */
221
219
struct pispbe_job_descriptor {
220
+ struct list_head queue ;
221
+ struct pispbe_buffer * buffers [PISPBE_NUM_NODES ];
222
+ struct pispbe_node_group * node_group ;
222
223
dma_addr_t hw_dma_addrs [N_HW_ADDRESSES ];
223
224
struct pisp_be_tiles_config * config ;
224
225
struct pispbe_hw_enables hw_enables ;
@@ -235,8 +236,10 @@ struct pispbe_dev {
235
236
struct clk * clk ;
236
237
struct pispbe_node_group node_group [PISPBE_NUM_NODE_GROUPS ];
237
238
struct pispbe_job queued_job , running_job ;
238
- spinlock_t hw_lock ; /* protects "hw_busy" flag and streaming_map */
239
+ /* protects "hw_busy" flag, streaming_map and job_queue */
240
+ spinlock_t hw_lock ;
239
241
bool hw_busy ; /* non-zero if a job is queued or is being started */
242
+ struct list_head job_queue ;
240
243
int irq ;
241
244
u32 hw_version ;
242
245
u8 done , started ;
@@ -460,42 +463,48 @@ static void pispbe_xlate_addrs(struct pispbe_job_descriptor *job,
460
463
* For Output0, Output1, Tdn and Stitch, a buffer only needs to be
461
464
* available if the blocks are enabled in the config.
462
465
*
463
- * Needs to be called with hw_lock held.
466
+ * If all the buffers required to form a job are available, append the
467
+ * job descriptor to the job queue to be later queued to the HW.
464
468
*
465
469
* Returns 0 if a job has been successfully prepared, < 0 otherwise.
466
470
*/
467
- static int pispbe_prepare_job (struct pispbe_node_group * node_group ,
468
- struct pispbe_job_descriptor * job )
471
+ static int pispbe_prepare_job (struct pispbe_node_group * node_group )
469
472
{
470
473
struct pispbe_buffer * buf [PISPBE_NUM_NODES ] = {};
471
474
struct pispbe_dev * pispbe = node_group -> pispbe ;
475
+ struct pispbe_job_descriptor * job ;
476
+ unsigned int streaming_map ;
472
477
unsigned int config_index ;
473
478
struct pispbe_node * node ;
474
- unsigned long flags ;
475
479
476
- lockdep_assert_held (& pispbe -> hw_lock );
480
+ scoped_guard (spinlock_irq , & pispbe -> hw_lock ) {
481
+ static const u32 mask = BIT (CONFIG_NODE ) | BIT (MAIN_INPUT_NODE );
477
482
478
- memset (job , 0 , sizeof (struct pispbe_job_descriptor ));
483
+ if ((node_group -> streaming_map & mask ) != mask )
484
+ return - ENODEV ;
479
485
480
- if (((BIT (CONFIG_NODE ) | BIT (MAIN_INPUT_NODE )) &
481
- node_group -> streaming_map ) !=
482
- (BIT (CONFIG_NODE ) | BIT (MAIN_INPUT_NODE )))
483
- return - ENODEV ;
486
+ /*
487
+ * Take a copy of streaming_map: nodes activated after this
488
+ * point are ignored when preparing this job.
489
+ */
490
+ streaming_map = node_group -> streaming_map ;
491
+ }
492
+
493
+ job = kzalloc (sizeof (* job ), GFP_KERNEL );
494
+ if (!job )
495
+ return - ENOMEM ;
484
496
485
497
node = & node_group -> node [CONFIG_NODE ];
486
- spin_lock_irqsave (& node -> ready_lock , flags );
487
498
buf [CONFIG_NODE ] = list_first_entry_or_null (& node -> ready_queue ,
488
499
struct pispbe_buffer ,
489
500
ready_list );
490
- if (buf [CONFIG_NODE ]) {
491
- list_del ( & buf [ CONFIG_NODE ] -> ready_list );
492
- pispbe -> queued_job . buf [ CONFIG_NODE ] = buf [ CONFIG_NODE ] ;
501
+ if (! buf [CONFIG_NODE ]) {
502
+ kfree ( job );
503
+ return - ENODEV ;
493
504
}
494
- spin_unlock_irqrestore (& node -> ready_lock , flags );
495
505
496
- /* Exit early if no config buffer has been queued. */
497
- if (!buf [CONFIG_NODE ])
498
- return - ENODEV ;
506
+ list_del (& buf [CONFIG_NODE ]-> ready_list );
507
+ job -> buffers [CONFIG_NODE ] = buf [CONFIG_NODE ];
499
508
500
509
config_index = buf [CONFIG_NODE ]-> vb .vb2_buf .index ;
501
510
job -> config = & node_group -> config [config_index ];
@@ -516,7 +525,7 @@ static int pispbe_prepare_job(struct pispbe_node_group *node_group,
516
525
continue ;
517
526
518
527
buf [i ] = NULL ;
519
- if (!(node_group -> streaming_map & BIT (i )))
528
+ if (!(streaming_map & BIT (i )))
520
529
continue ;
521
530
522
531
if ((!(rgb_en & PISP_BE_RGB_ENABLE_OUTPUT0 ) &&
@@ -543,25 +552,27 @@ static int pispbe_prepare_job(struct pispbe_node_group *node_group,
543
552
node = & node_group -> node [i ];
544
553
545
554
/* Pull a buffer from each V4L2 queue to form the queued job */
546
- spin_lock_irqsave (& node -> ready_lock , flags );
547
555
buf [i ] = list_first_entry_or_null (& node -> ready_queue ,
548
556
struct pispbe_buffer ,
549
557
ready_list );
550
558
if (buf [i ]) {
551
559
list_del (& buf [i ]-> ready_list );
552
- pispbe -> queued_job . buf [i ] = buf [i ];
560
+ job -> buffers [i ] = buf [i ];
553
561
}
554
- spin_unlock_irqrestore (& node -> ready_lock , flags );
555
562
556
563
if (!buf [i ] && !ignore_buffers )
557
564
goto err_return_buffers ;
558
565
}
559
566
560
- pispbe -> queued_job . node_group = node_group ;
567
+ job -> node_group = node_group ;
561
568
562
569
/* Convert buffers to DMA addresses for the hardware */
563
570
pispbe_xlate_addrs (job , buf , node_group );
564
571
572
+ spin_lock (& pispbe -> hw_lock );
573
+ list_add_tail (& job -> queue , & pispbe -> job_queue );
574
+ spin_unlock (& pispbe -> hw_lock );
575
+
565
576
return 0 ;
566
577
567
578
err_return_buffers :
@@ -572,12 +583,10 @@ static int pispbe_prepare_job(struct pispbe_node_group *node_group,
572
583
continue ;
573
584
574
585
/* Return the buffer to the ready_list queue */
575
- spin_lock_irqsave (& n -> ready_lock , flags );
576
586
list_add (& buf [i ]-> ready_list , & n -> ready_queue );
577
- spin_unlock_irqrestore (& n -> ready_lock , flags );
578
587
}
579
588
580
- memset ( & pispbe -> queued_job , 0 , sizeof ( pispbe -> queued_job ) );
589
+ kfree ( job );
581
590
582
591
return - ENODEV ;
583
592
}
@@ -586,49 +595,41 @@ static void pispbe_schedule(struct pispbe_dev *pispbe,
586
595
struct pispbe_node_group * node_group ,
587
596
bool clear_hw_busy )
588
597
{
589
- struct pispbe_job_descriptor job ;
590
- unsigned long flags ;
591
-
592
- spin_lock_irqsave (& pispbe -> hw_lock , flags );
593
-
594
- if (clear_hw_busy )
595
- pispbe -> hw_busy = false;
598
+ struct pispbe_job_descriptor * job ;
596
599
597
- if (pispbe -> hw_busy )
598
- goto unlock_and_return ;
600
+ scoped_guard (spinlock_irqsave , & pispbe -> hw_lock ) {
601
+ if (clear_hw_busy )
602
+ pispbe -> hw_busy = false;
599
603
600
- for ( unsigned int i = 0 ; i < PISPBE_NUM_NODE_GROUPS ; i ++ ) {
601
- int ret ;
604
+ if ( pispbe -> hw_busy )
605
+ return ;
602
606
603
- /* Schedule jobs only for a specific group. */
604
- if (node_group && & pispbe -> node_group [i ] != node_group )
605
- continue ;
607
+ job = list_first_entry_or_null (& pispbe -> job_queue ,
608
+ struct pispbe_job_descriptor ,
609
+ queue );
610
+ if (!job )
611
+ return ;
606
612
607
- /*
608
- * Prepare a job for this group, if the group is not ready
609
- * continue and try with the next one.
610
- */
611
- ret = pispbe_prepare_job (& pispbe -> node_group [i ], & job );
612
- if (ret )
613
+ if (node_group && job -> node_group != node_group )
613
614
continue ;
614
615
615
- /*
616
- * We can kick the job off without the hw_lock, as this can
617
- * never run again until hw_busy is cleared, which will happen
618
- * only when the following job has been queued and an interrupt
619
- * is rised.
620
- */
621
- pispbe -> hw_busy = true;
622
- spin_unlock_irqrestore (& pispbe -> hw_lock , flags );
616
+ list_del (& job -> queue );
623
617
624
- pispbe_queue_job (pispbe , & job );
618
+ for (unsigned int i = 0 ; i < PISPBE_NUM_NODES ; i ++ )
619
+ pispbe -> queued_job .buf [i ] = job -> buffers [i ];
620
+ pispbe -> queued_job .node_group = job -> node_group ;
625
621
626
- return ;
622
+ pispbe -> hw_busy = true ;
627
623
}
628
624
629
- unlock_and_return :
630
- /* No job has been queued, just release the lock and return. */
631
- spin_unlock_irqrestore (& pispbe -> hw_lock , flags );
625
+ /*
626
+ * We can kick the job off without the hw_lock, as this can
627
+ * never run again until hw_busy is cleared, which will happen
628
+ * only when the following job has been queued and an interrupt
629
+ * is rised.
630
+ */
631
+ pispbe_queue_job (pispbe , job );
632
+ kfree (job );
632
633
}
633
634
634
635
static void pispbe_isr_jobdone (struct pispbe_dev * pispbe ,
@@ -881,18 +882,16 @@ static void pispbe_node_buffer_queue(struct vb2_buffer *buf)
881
882
struct pispbe_node * node = vb2_get_drv_priv (buf -> vb2_queue );
882
883
struct pispbe_node_group * node_group = node -> node_group ;
883
884
struct pispbe_dev * pispbe = node -> node_group -> pispbe ;
884
- unsigned long flags ;
885
885
886
886
dev_dbg (pispbe -> dev , "%s: for node %s\n" , __func__ , NODE_NAME (node ));
887
- spin_lock_irqsave (& node -> ready_lock , flags );
888
887
list_add_tail (& buffer -> ready_list , & node -> ready_queue );
889
- spin_unlock_irqrestore (& node -> ready_lock , flags );
890
888
891
889
/*
892
890
* Every time we add a buffer, check if there's now some work for the hw
893
891
* to do, but only for this client.
894
892
*/
895
- pispbe_schedule (node_group -> pispbe , node_group , false);
893
+ if (!pispbe_prepare_job (node_group ))
894
+ pispbe_schedule (pispbe , node_group , false);
896
895
}
897
896
898
897
static int pispbe_node_start_streaming (struct vb2_queue * q , unsigned int count )
@@ -901,35 +900,33 @@ static int pispbe_node_start_streaming(struct vb2_queue *q, unsigned int count)
901
900
struct pispbe_node_group * node_group = node -> node_group ;
902
901
struct pispbe_dev * pispbe = node_group -> pispbe ;
903
902
struct pispbe_buffer * buf , * tmp ;
904
- unsigned long flags ;
905
903
int ret ;
906
904
907
905
ret = pm_runtime_resume_and_get (pispbe -> dev );
908
906
if (ret < 0 )
909
907
goto err_return_buffers ;
910
908
911
- spin_lock_irqsave (& pispbe -> hw_lock , flags );
909
+ spin_lock_irq (& pispbe -> hw_lock );
912
910
node -> node_group -> streaming_map |= BIT (node -> id );
913
911
node -> node_group -> sequence = 0 ;
914
- spin_unlock_irqrestore (& pispbe -> hw_lock , flags );
912
+ spin_unlock_irq (& pispbe -> hw_lock );
915
913
916
914
dev_dbg (pispbe -> dev , "%s: for node %s (count %u)\n" ,
917
915
__func__ , NODE_NAME (node ), count );
918
916
dev_dbg (pispbe -> dev , "Nodes streaming for this group now 0x%x\n" ,
919
917
node -> node_group -> streaming_map );
920
918
921
919
/* Maybe we're ready to run. */
922
- pispbe_schedule (node_group -> pispbe , node_group , false);
920
+ if (!pispbe_prepare_job (node_group ))
921
+ pispbe_schedule (pispbe , node_group , false);
923
922
924
923
return 0 ;
925
924
926
925
err_return_buffers :
927
- spin_lock_irqsave (& pispbe -> hw_lock , flags );
928
926
list_for_each_entry_safe (buf , tmp , & node -> ready_queue , ready_list ) {
929
927
list_del (& buf -> ready_list );
930
928
vb2_buffer_done (& buf -> vb .vb2_buf , VB2_BUF_STATE_QUEUED );
931
929
}
932
- spin_unlock_irqrestore (& pispbe -> hw_lock , flags );
933
930
934
931
return ret ;
935
932
}
@@ -940,7 +937,6 @@ static void pispbe_node_stop_streaming(struct vb2_queue *q)
940
937
struct pispbe_node_group * node_group = node -> node_group ;
941
938
struct pispbe_dev * pispbe = node_group -> pispbe ;
942
939
struct pispbe_buffer * buf ;
943
- unsigned long flags ;
944
940
945
941
/*
946
942
* Now this is a bit awkward. In a simple M2M device we could just wait
@@ -952,27 +948,34 @@ static void pispbe_node_stop_streaming(struct vb2_queue *q)
952
948
* This may return buffers out of order.
953
949
*/
954
950
dev_dbg (pispbe -> dev , "%s: for node %s\n" , __func__ , NODE_NAME (node ));
955
- spin_lock_irqsave (& pispbe -> hw_lock , flags );
956
951
do {
957
- unsigned long flags1 ;
958
-
959
- spin_lock_irqsave (& node -> ready_lock , flags1 );
960
952
buf = list_first_entry_or_null (& node -> ready_queue ,
961
953
struct pispbe_buffer ,
962
954
ready_list );
963
955
if (buf ) {
964
956
list_del (& buf -> ready_list );
965
957
vb2_buffer_done (& buf -> vb .vb2_buf , VB2_BUF_STATE_ERROR );
966
958
}
967
- spin_unlock_irqrestore (& node -> ready_lock , flags1 );
968
959
} while (buf );
969
- spin_unlock_irqrestore (& pispbe -> hw_lock , flags );
970
960
971
961
vb2_wait_for_all_buffers (& node -> queue );
972
962
973
- spin_lock_irqsave (& pispbe -> hw_lock , flags );
963
+ spin_lock_irq (& pispbe -> hw_lock );
974
964
node_group -> streaming_map &= ~BIT (node -> id );
975
- spin_unlock_irqrestore (& pispbe -> hw_lock , flags );
965
+
966
+ /* Release all jobs in the group once all nodes have stopped streaming. */
967
+ if (node_group -> streaming_map == 0 ) {
968
+ struct pispbe_job_descriptor * job , * temp ;
969
+
970
+ list_for_each_entry_safe (job , temp , & pispbe -> job_queue , queue ) {
971
+ if (job -> node_group != node_group )
972
+ continue ;
973
+
974
+ list_del (& job -> queue );
975
+ kfree (job );
976
+ }
977
+ }
978
+ spin_unlock_irq (& pispbe -> hw_lock );
976
979
977
980
pm_runtime_mark_last_busy (pispbe -> dev );
978
981
pm_runtime_put_autosuspend (pispbe -> dev );
@@ -1432,7 +1435,6 @@ static int pispbe_init_node(struct pispbe_node_group *node_group,
1432
1435
mutex_init (& node -> node_lock );
1433
1436
mutex_init (& node -> queue_lock );
1434
1437
INIT_LIST_HEAD (& node -> ready_queue );
1435
- spin_lock_init (& node -> ready_lock );
1436
1438
1437
1439
node -> format .type = node -> buf_type ;
1438
1440
pispbe_node_def_fmt (node );
@@ -1731,6 +1733,8 @@ static int pispbe_probe(struct platform_device *pdev)
1731
1733
if (!pispbe )
1732
1734
return - ENOMEM ;
1733
1735
1736
+ INIT_LIST_HEAD (& pispbe -> job_queue );
1737
+
1734
1738
dev_set_drvdata (& pdev -> dev , pispbe );
1735
1739
pispbe -> dev = & pdev -> dev ;
1736
1740
platform_set_drvdata (pdev , pispbe );
0 commit comments