63
63
64
64
#define MBOX_IRQ_NAME "pcc-mbox"
65
65
66
- static struct mbox_chan * pcc_mbox_channels ;
67
-
68
66
/**
69
67
* struct pcc_chan_reg - PCC register bundle
70
68
*
@@ -106,7 +104,7 @@ struct pcc_chan_info {
106
104
107
105
#define to_pcc_chan_info (c ) container_of(c, struct pcc_chan_info, chan)
108
106
static struct pcc_chan_info * chan_info ;
109
- static struct mbox_controller pcc_mbox_ctrl = {} ;
107
+ static int pcc_chan_count ;
110
108
111
109
/*
112
110
* PCC can be used with perf critical drivers such as CPPC
@@ -281,11 +279,11 @@ struct pcc_mbox_chan *
281
279
pcc_mbox_request_channel (struct mbox_client * cl , int subspace_id )
282
280
{
283
281
struct pcc_chan_info * pchan ;
284
- struct device * dev = pcc_mbox_ctrl .dev ;
285
282
struct mbox_chan * chan ;
283
+ struct device * dev ;
286
284
unsigned long flags ;
287
285
288
- if (subspace_id < 0 || subspace_id >= pcc_mbox_ctrl . num_chans )
286
+ if (subspace_id < 0 || subspace_id >= pcc_chan_count )
289
287
return ERR_PTR (- ENOENT );
290
288
291
289
pchan = chan_info + subspace_id ;
@@ -294,6 +292,7 @@ pcc_mbox_request_channel(struct mbox_client *cl, int subspace_id)
294
292
dev_err (dev , "Channel not found for idx: %d\n" , subspace_id );
295
293
return ERR_PTR (- EBUSY );
296
294
}
295
+ dev = chan -> mbox -> dev ;
297
296
298
297
spin_lock_irqsave (& chan -> lock , flags );
299
298
chan -> msg_free = 0 ;
@@ -576,16 +575,12 @@ static void pcc_parse_subspace_shmem(struct pcc_chan_info *pchan,
576
575
*/
577
576
static int __init acpi_pcc_probe (void )
578
577
{
578
+ int count , i , rc = 0 ;
579
+ acpi_status status ;
579
580
struct acpi_table_header * pcct_tbl ;
580
- struct acpi_subtable_header * pcct_entry ;
581
- struct acpi_table_pcct * acpi_pcct_tbl ;
582
581
struct acpi_subtable_proc proc [ACPI_PCCT_TYPE_RESERVED ];
583
- int count , i , rc ;
584
- acpi_status status = AE_OK ;
585
582
586
- /* Search for PCCT */
587
583
status = acpi_get_table (ACPI_SIG_PCCT , 0 , & pcct_tbl );
588
-
589
584
if (ACPI_FAILURE (status ) || !pcct_tbl )
590
585
return - ENODEV ;
591
586
@@ -607,21 +602,60 @@ static int __init acpi_pcc_probe(void)
607
602
pr_warn ("Invalid PCCT: %d PCC subspaces\n" , count );
608
603
609
604
rc = - EINVAL ;
610
- goto err_put_pcct ;
605
+ } else {
606
+ pcc_chan_count = count ;
611
607
}
612
608
613
- pcc_mbox_channels = kcalloc (count , sizeof (struct mbox_chan ),
614
- GFP_KERNEL );
609
+ acpi_put_table (pcct_tbl );
610
+
611
+ return rc ;
612
+ }
613
+
614
+ /**
615
+ * pcc_mbox_probe - Called when we find a match for the
616
+ * PCCT platform device. This is purely used to represent
617
+ * the PCCT as a virtual device for registering with the
618
+ * generic Mailbox framework.
619
+ *
620
+ * @pdev: Pointer to platform device returned when a match
621
+ * is found.
622
+ *
623
+ * Return: 0 for Success, else errno.
624
+ */
625
+ static int pcc_mbox_probe (struct platform_device * pdev )
626
+ {
627
+ struct device * dev = & pdev -> dev ;
628
+ struct mbox_controller * pcc_mbox_ctrl ;
629
+ struct mbox_chan * pcc_mbox_channels ;
630
+ struct acpi_table_header * pcct_tbl ;
631
+ struct acpi_subtable_header * pcct_entry ;
632
+ struct acpi_table_pcct * acpi_pcct_tbl ;
633
+ acpi_status status = AE_OK ;
634
+ int i , rc , count = pcc_chan_count ;
635
+
636
+ /* Search for PCCT */
637
+ status = acpi_get_table (ACPI_SIG_PCCT , 0 , & pcct_tbl );
638
+
639
+ if (ACPI_FAILURE (status ) || !pcct_tbl )
640
+ return - ENODEV ;
641
+
642
+ pcc_mbox_channels = devm_kcalloc (dev , count , sizeof (* pcc_mbox_channels ),
643
+ GFP_KERNEL );
615
644
if (!pcc_mbox_channels ) {
616
- pr_err ("Could not allocate space for PCC mbox channels\n" );
617
645
rc = - ENOMEM ;
618
- goto err_put_pcct ;
646
+ goto err ;
619
647
}
620
648
621
- chan_info = kcalloc ( count , sizeof (* chan_info ), GFP_KERNEL );
649
+ chan_info = devm_kcalloc ( dev , count , sizeof (* chan_info ), GFP_KERNEL );
622
650
if (!chan_info ) {
623
651
rc = - ENOMEM ;
624
- goto err_free_mbox ;
652
+ goto err ;
653
+ }
654
+
655
+ pcc_mbox_ctrl = devm_kmalloc (dev , sizeof (* pcc_mbox_ctrl ), GFP_KERNEL );
656
+ if (!pcc_mbox_ctrl ) {
657
+ rc = - ENOMEM ;
658
+ goto err ;
625
659
}
626
660
627
661
/* Point to the first PCC subspace entry */
@@ -630,7 +664,7 @@ static int __init acpi_pcc_probe(void)
630
664
631
665
acpi_pcct_tbl = (struct acpi_table_pcct * ) pcct_tbl ;
632
666
if (acpi_pcct_tbl -> flags & ACPI_PCCT_DOORBELL )
633
- pcc_mbox_ctrl . txdone_irq = true;
667
+ pcc_mbox_ctrl -> txdone_irq = true;
634
668
635
669
for (i = 0 ; i < count ; i ++ ) {
636
670
struct pcc_chan_info * pchan = chan_info + i ;
@@ -639,13 +673,13 @@ static int __init acpi_pcc_probe(void)
639
673
pchan -> chan .mchan = & pcc_mbox_channels [i ];
640
674
641
675
if (pcct_entry -> type == ACPI_PCCT_TYPE_EXT_PCC_SLAVE_SUBSPACE &&
642
- !pcc_mbox_ctrl . txdone_irq ) {
676
+ !pcc_mbox_ctrl -> txdone_irq ) {
643
677
pr_err ("Plaform Interrupt flag must be set to 1" );
644
678
rc = - EINVAL ;
645
679
goto err ;
646
680
}
647
681
648
- if (pcc_mbox_ctrl . txdone_irq ) {
682
+ if (pcc_mbox_ctrl -> txdone_irq ) {
649
683
rc = pcc_parse_subspace_irq (pchan , pcct_entry );
650
684
if (rc < 0 )
651
685
goto err ;
@@ -660,51 +694,25 @@ static int __init acpi_pcc_probe(void)
660
694
((unsigned long ) pcct_entry + pcct_entry -> length );
661
695
}
662
696
663
- pcc_mbox_ctrl . num_chans = count ;
697
+ pcc_mbox_ctrl -> num_chans = count ;
664
698
665
- pr_info ("Detected %d PCC Subspaces\n" , pcc_mbox_ctrl . num_chans );
699
+ pr_info ("Detected %d PCC Subspaces\n" , pcc_mbox_ctrl -> num_chans );
666
700
667
- return 0 ;
701
+ pcc_mbox_ctrl -> chans = pcc_mbox_channels ;
702
+ pcc_mbox_ctrl -> ops = & pcc_chan_ops ;
703
+ pcc_mbox_ctrl -> dev = dev ;
668
704
705
+ pr_info ("Registering PCC driver as Mailbox controller\n" );
706
+ rc = mbox_controller_register (pcc_mbox_ctrl );
707
+ if (rc )
708
+ pr_err ("Err registering PCC as Mailbox controller: %d\n" , rc );
709
+ else
710
+ return 0 ;
669
711
err :
670
- kfree (chan_info );
671
- err_free_mbox :
672
- kfree (pcc_mbox_channels );
673
- err_put_pcct :
674
712
acpi_put_table (pcct_tbl );
675
713
return rc ;
676
714
}
677
715
678
- /**
679
- * pcc_mbox_probe - Called when we find a match for the
680
- * PCCT platform device. This is purely used to represent
681
- * the PCCT as a virtual device for registering with the
682
- * generic Mailbox framework.
683
- *
684
- * @pdev: Pointer to platform device returned when a match
685
- * is found.
686
- *
687
- * Return: 0 for Success, else errno.
688
- */
689
- static int pcc_mbox_probe (struct platform_device * pdev )
690
- {
691
- int ret = 0 ;
692
-
693
- pcc_mbox_ctrl .chans = pcc_mbox_channels ;
694
- pcc_mbox_ctrl .ops = & pcc_chan_ops ;
695
- pcc_mbox_ctrl .dev = & pdev -> dev ;
696
-
697
- pr_info ("Registering PCC driver as Mailbox controller\n" );
698
- ret = mbox_controller_register (& pcc_mbox_ctrl );
699
-
700
- if (ret ) {
701
- pr_err ("Err registering PCC as Mailbox controller: %d\n" , ret );
702
- ret = - ENODEV ;
703
- }
704
-
705
- return ret ;
706
- }
707
-
708
716
static struct platform_driver pcc_mbox_driver = {
709
717
.probe = pcc_mbox_probe ,
710
718
.driver = {
0 commit comments