Skip to content

Commit ce02870

Browse files
sudeep-hollaJassiBrar
authored andcommitted
mailbox: pcc: Move bulk of PCCT parsing into pcc_mbox_probe
Move the PCCT subspace parsing and allocation into pcc_mbox_probe so that we can get rid of global PCC channel and mailbox controller data. It also helps to make use of devm_* APIs for all the allocations. Signed-off-by: Sudeep Holla <[email protected]> Signed-off-by: Jassi Brar <[email protected]>
1 parent c45ded7 commit ce02870

File tree

1 file changed

+66
-58
lines changed

1 file changed

+66
-58
lines changed

drivers/mailbox/pcc.c

Lines changed: 66 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,6 @@
6363

6464
#define MBOX_IRQ_NAME "pcc-mbox"
6565

66-
static struct mbox_chan *pcc_mbox_channels;
67-
6866
/**
6967
* struct pcc_chan_reg - PCC register bundle
7068
*
@@ -106,7 +104,7 @@ struct pcc_chan_info {
106104

107105
#define to_pcc_chan_info(c) container_of(c, struct pcc_chan_info, chan)
108106
static struct pcc_chan_info *chan_info;
109-
static struct mbox_controller pcc_mbox_ctrl = {};
107+
static int pcc_chan_count;
110108

111109
/*
112110
* PCC can be used with perf critical drivers such as CPPC
@@ -281,11 +279,11 @@ struct pcc_mbox_chan *
281279
pcc_mbox_request_channel(struct mbox_client *cl, int subspace_id)
282280
{
283281
struct pcc_chan_info *pchan;
284-
struct device *dev = pcc_mbox_ctrl.dev;
285282
struct mbox_chan *chan;
283+
struct device *dev;
286284
unsigned long flags;
287285

288-
if (subspace_id < 0 || subspace_id >= pcc_mbox_ctrl.num_chans)
286+
if (subspace_id < 0 || subspace_id >= pcc_chan_count)
289287
return ERR_PTR(-ENOENT);
290288

291289
pchan = chan_info + subspace_id;
@@ -294,6 +292,7 @@ pcc_mbox_request_channel(struct mbox_client *cl, int subspace_id)
294292
dev_err(dev, "Channel not found for idx: %d\n", subspace_id);
295293
return ERR_PTR(-EBUSY);
296294
}
295+
dev = chan->mbox->dev;
297296

298297
spin_lock_irqsave(&chan->lock, flags);
299298
chan->msg_free = 0;
@@ -576,16 +575,12 @@ static void pcc_parse_subspace_shmem(struct pcc_chan_info *pchan,
576575
*/
577576
static int __init acpi_pcc_probe(void)
578577
{
578+
int count, i, rc = 0;
579+
acpi_status status;
579580
struct acpi_table_header *pcct_tbl;
580-
struct acpi_subtable_header *pcct_entry;
581-
struct acpi_table_pcct *acpi_pcct_tbl;
582581
struct acpi_subtable_proc proc[ACPI_PCCT_TYPE_RESERVED];
583-
int count, i, rc;
584-
acpi_status status = AE_OK;
585582

586-
/* Search for PCCT */
587583
status = acpi_get_table(ACPI_SIG_PCCT, 0, &pcct_tbl);
588-
589584
if (ACPI_FAILURE(status) || !pcct_tbl)
590585
return -ENODEV;
591586

@@ -607,21 +602,60 @@ static int __init acpi_pcc_probe(void)
607602
pr_warn("Invalid PCCT: %d PCC subspaces\n", count);
608603

609604
rc = -EINVAL;
610-
goto err_put_pcct;
605+
} else {
606+
pcc_chan_count = count;
611607
}
612608

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);
615644
if (!pcc_mbox_channels) {
616-
pr_err("Could not allocate space for PCC mbox channels\n");
617645
rc = -ENOMEM;
618-
goto err_put_pcct;
646+
goto err;
619647
}
620648

621-
chan_info = kcalloc(count, sizeof(*chan_info), GFP_KERNEL);
649+
chan_info = devm_kcalloc(dev, count, sizeof(*chan_info), GFP_KERNEL);
622650
if (!chan_info) {
623651
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;
625659
}
626660

627661
/* Point to the first PCC subspace entry */
@@ -630,7 +664,7 @@ static int __init acpi_pcc_probe(void)
630664

631665
acpi_pcct_tbl = (struct acpi_table_pcct *) pcct_tbl;
632666
if (acpi_pcct_tbl->flags & ACPI_PCCT_DOORBELL)
633-
pcc_mbox_ctrl.txdone_irq = true;
667+
pcc_mbox_ctrl->txdone_irq = true;
634668

635669
for (i = 0; i < count; i++) {
636670
struct pcc_chan_info *pchan = chan_info + i;
@@ -639,13 +673,13 @@ static int __init acpi_pcc_probe(void)
639673
pchan->chan.mchan = &pcc_mbox_channels[i];
640674

641675
if (pcct_entry->type == ACPI_PCCT_TYPE_EXT_PCC_SLAVE_SUBSPACE &&
642-
!pcc_mbox_ctrl.txdone_irq) {
676+
!pcc_mbox_ctrl->txdone_irq) {
643677
pr_err("Plaform Interrupt flag must be set to 1");
644678
rc = -EINVAL;
645679
goto err;
646680
}
647681

648-
if (pcc_mbox_ctrl.txdone_irq) {
682+
if (pcc_mbox_ctrl->txdone_irq) {
649683
rc = pcc_parse_subspace_irq(pchan, pcct_entry);
650684
if (rc < 0)
651685
goto err;
@@ -660,51 +694,25 @@ static int __init acpi_pcc_probe(void)
660694
((unsigned long) pcct_entry + pcct_entry->length);
661695
}
662696

663-
pcc_mbox_ctrl.num_chans = count;
697+
pcc_mbox_ctrl->num_chans = count;
664698

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);
666700

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;
668704

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;
669711
err:
670-
kfree(chan_info);
671-
err_free_mbox:
672-
kfree(pcc_mbox_channels);
673-
err_put_pcct:
674712
acpi_put_table(pcct_tbl);
675713
return rc;
676714
}
677715

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-
708716
static struct platform_driver pcc_mbox_driver = {
709717
.probe = pcc_mbox_probe,
710718
.driver = {

0 commit comments

Comments
 (0)