@@ -70,57 +70,20 @@ void tegra_bpmp_put(struct tegra_bpmp *bpmp)
7070}
7171EXPORT_SYMBOL_GPL (tegra_bpmp_put );
7272
73- static int tegra_bpmp_channel_get_index (struct tegra_bpmp_channel * channel )
74- {
75- return channel - channel -> bpmp -> channels ;
76- }
77-
7873static int
7974tegra_bpmp_channel_get_thread_index (struct tegra_bpmp_channel * channel )
8075{
8176 struct tegra_bpmp * bpmp = channel -> bpmp ;
82- unsigned int offset , count ;
77+ unsigned int count ;
8378 int index ;
8479
85- offset = bpmp -> soc -> channels .thread .offset ;
8680 count = bpmp -> soc -> channels .thread .count ;
8781
88- index = tegra_bpmp_channel_get_index (channel );
89- if (index < 0 )
90- return index ;
91-
92- if (index < offset || index >= offset + count )
82+ index = channel - channel -> bpmp -> threaded_channels ;
83+ if (index < 0 || index >= count )
9384 return - EINVAL ;
9485
95- return index - offset ;
96- }
97-
98- static struct tegra_bpmp_channel *
99- tegra_bpmp_channel_get_thread (struct tegra_bpmp * bpmp , unsigned int index )
100- {
101- unsigned int offset = bpmp -> soc -> channels .thread .offset ;
102- unsigned int count = bpmp -> soc -> channels .thread .count ;
103-
104- if (index >= count )
105- return NULL ;
106-
107- return & bpmp -> channels [offset + index ];
108- }
109-
110- static struct tegra_bpmp_channel *
111- tegra_bpmp_channel_get_tx (struct tegra_bpmp * bpmp )
112- {
113- unsigned int offset = bpmp -> soc -> channels .cpu_tx .offset ;
114-
115- return & bpmp -> channels [offset + smp_processor_id ()];
116- }
117-
118- static struct tegra_bpmp_channel *
119- tegra_bpmp_channel_get_rx (struct tegra_bpmp * bpmp )
120- {
121- unsigned int offset = bpmp -> soc -> channels .cpu_rx .offset ;
122-
123- return & bpmp -> channels [offset ];
86+ return index ;
12487}
12588
12689static bool tegra_bpmp_message_valid (const struct tegra_bpmp_message * msg )
@@ -271,11 +234,7 @@ tegra_bpmp_write_threaded(struct tegra_bpmp *bpmp, unsigned int mrq,
271234 goto unlock ;
272235 }
273236
274- channel = tegra_bpmp_channel_get_thread (bpmp , index );
275- if (!channel ) {
276- err = - EINVAL ;
277- goto unlock ;
278- }
237+ channel = & bpmp -> threaded_channels [index ];
279238
280239 if (!tegra_bpmp_master_free (channel )) {
281240 err = - EBUSY ;
@@ -328,12 +287,18 @@ int tegra_bpmp_transfer_atomic(struct tegra_bpmp *bpmp,
328287 if (!tegra_bpmp_message_valid (msg ))
329288 return - EINVAL ;
330289
331- channel = tegra_bpmp_channel_get_tx (bpmp );
290+ channel = bpmp -> tx_channel ;
291+
292+ spin_lock (& bpmp -> atomic_tx_lock );
332293
333294 err = tegra_bpmp_channel_write (channel , msg -> mrq , MSG_ACK ,
334295 msg -> tx .data , msg -> tx .size );
335- if (err < 0 )
296+ if (err < 0 ) {
297+ spin_unlock (& bpmp -> atomic_tx_lock );
336298 return err ;
299+ }
300+
301+ spin_unlock (& bpmp -> atomic_tx_lock );
337302
338303 err = mbox_send_message (bpmp -> mbox .channel , NULL );
339304 if (err < 0 )
@@ -607,7 +572,7 @@ static void tegra_bpmp_handle_rx(struct mbox_client *client, void *data)
607572 unsigned int i , count ;
608573 unsigned long * busy ;
609574
610- channel = tegra_bpmp_channel_get_rx ( bpmp ) ;
575+ channel = bpmp -> rx_channel ;
611576 count = bpmp -> soc -> channels .thread .count ;
612577 busy = bpmp -> threaded .busy ;
613578
@@ -619,9 +584,7 @@ static void tegra_bpmp_handle_rx(struct mbox_client *client, void *data)
619584 for_each_set_bit (i , busy , count ) {
620585 struct tegra_bpmp_channel * channel ;
621586
622- channel = tegra_bpmp_channel_get_thread (bpmp , i );
623- if (!channel )
624- continue ;
587+ channel = & bpmp -> threaded_channels [i ];
625588
626589 if (tegra_bpmp_master_acked (channel )) {
627590 tegra_bpmp_channel_signal (channel );
@@ -698,7 +661,6 @@ static void tegra_bpmp_channel_cleanup(struct tegra_bpmp_channel *channel)
698661
699662static int tegra_bpmp_probe (struct platform_device * pdev )
700663{
701- struct tegra_bpmp_channel * channel ;
702664 struct tegra_bpmp * bpmp ;
703665 unsigned int i ;
704666 char tag [32 ];
@@ -732,7 +694,7 @@ static int tegra_bpmp_probe(struct platform_device *pdev)
732694 }
733695
734696 bpmp -> rx .virt = gen_pool_dma_alloc (bpmp -> rx .pool , 4096 , & bpmp -> rx .phys );
735- if (!bpmp -> rx .pool ) {
697+ if (!bpmp -> rx .virt ) {
736698 dev_err (& pdev -> dev , "failed to allocate from RX pool\n" );
737699 err = - ENOMEM ;
738700 goto free_tx ;
@@ -758,24 +720,45 @@ static int tegra_bpmp_probe(struct platform_device *pdev)
758720 goto free_rx ;
759721 }
760722
761- bpmp -> num_channels = bpmp -> soc -> channels .cpu_tx .count +
762- bpmp -> soc -> channels .thread .count +
763- bpmp -> soc -> channels .cpu_rx .count ;
723+ spin_lock_init (& bpmp -> atomic_tx_lock );
724+ bpmp -> tx_channel = devm_kzalloc (& pdev -> dev , sizeof (* bpmp -> tx_channel ),
725+ GFP_KERNEL );
726+ if (!bpmp -> tx_channel ) {
727+ err = - ENOMEM ;
728+ goto free_rx ;
729+ }
764730
765- bpmp -> channels = devm_kcalloc (& pdev -> dev , bpmp -> num_channels ,
766- sizeof ( * channel ), GFP_KERNEL );
767- if (!bpmp -> channels ) {
731+ bpmp -> rx_channel = devm_kzalloc (& pdev -> dev , sizeof ( * bpmp -> rx_channel ) ,
732+ GFP_KERNEL );
733+ if (!bpmp -> rx_channel ) {
768734 err = - ENOMEM ;
769735 goto free_rx ;
770736 }
771737
772- /* message channel initialization */
773- for (i = 0 ; i < bpmp -> num_channels ; i ++ ) {
774- struct tegra_bpmp_channel * channel = & bpmp -> channels [i ];
738+ bpmp -> threaded_channels = devm_kcalloc (& pdev -> dev , bpmp -> threaded .count ,
739+ sizeof (* bpmp -> threaded_channels ),
740+ GFP_KERNEL );
741+ if (!bpmp -> threaded_channels ) {
742+ err = - ENOMEM ;
743+ goto free_rx ;
744+ }
775745
776- err = tegra_bpmp_channel_init (channel , bpmp , i );
746+ err = tegra_bpmp_channel_init (bpmp -> tx_channel , bpmp ,
747+ bpmp -> soc -> channels .cpu_tx .offset );
748+ if (err < 0 )
749+ goto free_rx ;
750+
751+ err = tegra_bpmp_channel_init (bpmp -> rx_channel , bpmp ,
752+ bpmp -> soc -> channels .cpu_rx .offset );
753+ if (err < 0 )
754+ goto cleanup_tx_channel ;
755+
756+ for (i = 0 ; i < bpmp -> threaded .count ; i ++ ) {
757+ err = tegra_bpmp_channel_init (
758+ & bpmp -> threaded_channels [i ], bpmp ,
759+ bpmp -> soc -> channels .thread .offset + i );
777760 if (err < 0 )
778- goto cleanup_channels ;
761+ goto cleanup_threaded_channels ;
779762 }
780763
781764 /* mbox registration */
@@ -788,15 +771,14 @@ static int tegra_bpmp_probe(struct platform_device *pdev)
788771 if (IS_ERR (bpmp -> mbox .channel )) {
789772 err = PTR_ERR (bpmp -> mbox .channel );
790773 dev_err (& pdev -> dev , "failed to get HSP mailbox: %d\n" , err );
791- goto cleanup_channels ;
774+ goto cleanup_threaded_channels ;
792775 }
793776
794777 /* reset message channels */
795- for (i = 0 ; i < bpmp -> num_channels ; i ++ ) {
796- struct tegra_bpmp_channel * channel = & bpmp -> channels [i ];
797-
798- tegra_bpmp_channel_reset (channel );
799- }
778+ tegra_bpmp_channel_reset (bpmp -> tx_channel );
779+ tegra_bpmp_channel_reset (bpmp -> rx_channel );
780+ for (i = 0 ; i < bpmp -> threaded .count ; i ++ )
781+ tegra_bpmp_channel_reset (& bpmp -> threaded_channels [i ]);
800782
801783 err = tegra_bpmp_request_mrq (bpmp , MRQ_PING ,
802784 tegra_bpmp_mrq_handle_ping , bpmp );
@@ -845,9 +827,15 @@ static int tegra_bpmp_probe(struct platform_device *pdev)
845827 tegra_bpmp_free_mrq (bpmp , MRQ_PING , bpmp );
846828free_mbox :
847829 mbox_free_channel (bpmp -> mbox .channel );
848- cleanup_channels :
849- while (i -- )
850- tegra_bpmp_channel_cleanup (& bpmp -> channels [i ]);
830+ cleanup_threaded_channels :
831+ for (i = 0 ; i < bpmp -> threaded .count ; i ++ ) {
832+ if (bpmp -> threaded_channels [i ].bpmp )
833+ tegra_bpmp_channel_cleanup (& bpmp -> threaded_channels [i ]);
834+ }
835+
836+ tegra_bpmp_channel_cleanup (bpmp -> rx_channel );
837+ cleanup_tx_channel :
838+ tegra_bpmp_channel_cleanup (bpmp -> tx_channel );
851839free_rx :
852840 gen_pool_free (bpmp -> rx .pool , (unsigned long )bpmp -> rx .virt , 4096 );
853841free_tx :
@@ -858,18 +846,16 @@ static int tegra_bpmp_probe(struct platform_device *pdev)
858846static const struct tegra_bpmp_soc tegra186_soc = {
859847 .channels = {
860848 .cpu_tx = {
861- .offset = 0 ,
862- .count = 6 ,
849+ .offset = 3 ,
863850 .timeout = 60 * USEC_PER_SEC ,
864851 },
865852 .thread = {
866- .offset = 6 ,
867- .count = 7 ,
853+ .offset = 0 ,
854+ .count = 3 ,
868855 .timeout = 600 * USEC_PER_SEC ,
869856 },
870857 .cpu_rx = {
871858 .offset = 13 ,
872- .count = 1 ,
873859 .timeout = 0 ,
874860 },
875861 },
0 commit comments