All of lore.kernel.org
 help / color / mirror / Atom feed
From: Sudeep Holla <sudeep.holla@arm.com>
To: linux-acpi@vger.kernel.org, linux-kernel@vger.kernel.org
Cc: Sudeep Holla <sudeep.holla@arm.com>,
	Cristian Marussi <cristian.marussi@arm.com>,
	"Rafael J . Wysocki" <rjw@rjwysocki.net>,
	Jassi Brar <jassisinghbrar@gmail.com>
Subject: [PATCH v2 13/14] mailbox: pcc: Move bulk of PCCT parsing into pcc_mbox_probe
Date: Fri, 17 Sep 2021 14:33:56 +0100	[thread overview]
Message-ID: <20210917133357.1911092-14-sudeep.holla@arm.com> (raw)
In-Reply-To: <20210917133357.1911092-1-sudeep.holla@arm.com>

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 <sudeep.holla@arm.com>
---
 drivers/mailbox/pcc.c | 124 ++++++++++++++++++++++--------------------
 1 file changed, 66 insertions(+), 58 deletions(-)

diff --git a/drivers/mailbox/pcc.c b/drivers/mailbox/pcc.c
index eb90c9eaaf9c..887a3704c12e 100644
--- a/drivers/mailbox/pcc.c
+++ b/drivers/mailbox/pcc.c
@@ -63,8 +63,6 @@
 
 #define MBOX_IRQ_NAME		"pcc-mbox"
 
-static struct mbox_chan *pcc_mbox_channels;
-
 /**
  * struct pcc_chan_reg - PCC register bundle
  *
@@ -106,7 +104,7 @@ struct pcc_chan_info {
 
 #define to_pcc_chan_info(c) container_of(c, struct pcc_chan_info, chan)
 static struct pcc_chan_info *chan_info;
-static struct mbox_controller pcc_mbox_ctrl = {};
+static int pcc_chan_count;
 
 /*
  * PCC can be used with perf critical drivers such as CPPC
@@ -281,11 +279,11 @@ struct pcc_mbox_chan *
 pcc_mbox_request_channel(struct mbox_client *cl, int subspace_id)
 {
 	struct pcc_chan_info *pchan;
-	struct device *dev = pcc_mbox_ctrl.dev;
 	struct mbox_chan *chan;
+	struct device *dev;
 	unsigned long flags;
 
-	if (subspace_id < 0 || subspace_id >= pcc_mbox_ctrl.num_chans)
+	if (subspace_id < 0 || subspace_id >= pcc_chan_count)
 		return ERR_PTR(-ENOENT);
 
 	pchan = chan_info + subspace_id;
@@ -294,6 +292,7 @@ pcc_mbox_request_channel(struct mbox_client *cl, int subspace_id)
 		dev_err(dev, "Channel not found for idx: %d\n", subspace_id);
 		return ERR_PTR(-EBUSY);
 	}
+	dev = chan->mbox->dev;
 
 	spin_lock_irqsave(&chan->lock, flags);
 	chan->msg_free = 0;
@@ -576,16 +575,12 @@ static void pcc_parse_subspace_shmem(struct pcc_chan_info *pchan,
  */
 static int __init acpi_pcc_probe(void)
 {
+	int count, i, rc = 0;
+	acpi_status status;
 	struct acpi_table_header *pcct_tbl;
-	struct acpi_subtable_header *pcct_entry;
-	struct acpi_table_pcct *acpi_pcct_tbl;
 	struct acpi_subtable_proc proc[ACPI_PCCT_TYPE_RESERVED];
-	int count, i, rc;
-	acpi_status status = AE_OK;
 
-	/* Search for PCCT */
 	status = acpi_get_table(ACPI_SIG_PCCT, 0, &pcct_tbl);
-
 	if (ACPI_FAILURE(status) || !pcct_tbl)
 		return -ENODEV;
 
@@ -607,21 +602,60 @@ static int __init acpi_pcc_probe(void)
 			pr_warn("Invalid PCCT: %d PCC subspaces\n", count);
 
 		rc = -EINVAL;
-		goto err_put_pcct;
+	} else {
+		pcc_chan_count = count;
 	}
 
-	pcc_mbox_channels = kcalloc(count, sizeof(struct mbox_chan),
-				    GFP_KERNEL);
+	acpi_put_table(pcct_tbl);
+
+	return rc;
+}
+
+/**
+ * pcc_mbox_probe - Called when we find a match for the
+ *	PCCT platform device. This is purely used to represent
+ *	the PCCT as a virtual device for registering with the
+ *	generic Mailbox framework.
+ *
+ * @pdev: Pointer to platform device returned when a match
+ *	is found.
+ *
+ *	Return: 0 for Success, else errno.
+ */
+static int pcc_mbox_probe(struct platform_device *pdev)
+{
+	struct device *dev = &pdev->dev;
+	struct mbox_controller *pcc_mbox_ctrl;
+	struct mbox_chan *pcc_mbox_channels;
+	struct acpi_table_header *pcct_tbl;
+	struct acpi_subtable_header *pcct_entry;
+	struct acpi_table_pcct *acpi_pcct_tbl;
+	acpi_status status = AE_OK;
+	int i, rc, count = pcc_chan_count;
+
+	/* Search for PCCT */
+	status = acpi_get_table(ACPI_SIG_PCCT, 0, &pcct_tbl);
+
+	if (ACPI_FAILURE(status) || !pcct_tbl)
+		return -ENODEV;
+
+	pcc_mbox_channels = devm_kcalloc(dev, count, sizeof(*pcc_mbox_channels),
+					 GFP_KERNEL);
 	if (!pcc_mbox_channels) {
-		pr_err("Could not allocate space for PCC mbox channels\n");
 		rc = -ENOMEM;
-		goto err_put_pcct;
+		goto err;
 	}
 
-	chan_info = kcalloc(count, sizeof(*chan_info), GFP_KERNEL);
+	chan_info = devm_kcalloc(dev, count, sizeof(*chan_info), GFP_KERNEL);
 	if (!chan_info) {
 		rc = -ENOMEM;
-		goto err_free_mbox;
+		goto err;
+	}
+
+	pcc_mbox_ctrl = devm_kmalloc(dev, sizeof(*pcc_mbox_ctrl), GFP_KERNEL);
+	if (!pcc_mbox_ctrl) {
+		rc = -ENOMEM;
+		goto err;
 	}
 
 	/* Point to the first PCC subspace entry */
@@ -630,7 +664,7 @@ static int __init acpi_pcc_probe(void)
 
 	acpi_pcct_tbl = (struct acpi_table_pcct *) pcct_tbl;
 	if (acpi_pcct_tbl->flags & ACPI_PCCT_DOORBELL)
-		pcc_mbox_ctrl.txdone_irq = true;
+		pcc_mbox_ctrl->txdone_irq = true;
 
 	for (i = 0; i < count; i++) {
 		struct pcc_chan_info *pchan = chan_info + i;
@@ -639,13 +673,13 @@ static int __init acpi_pcc_probe(void)
 		pchan->chan.mchan = &pcc_mbox_channels[i];
 
 		if (pcct_entry->type == ACPI_PCCT_TYPE_EXT_PCC_SLAVE_SUBSPACE &&
-		    !pcc_mbox_ctrl.txdone_irq) {
+		    !pcc_mbox_ctrl->txdone_irq) {
 			pr_err("Plaform Interrupt flag must be set to 1");
 			rc = -EINVAL;
 			goto err;
 		}
 
-		if (pcc_mbox_ctrl.txdone_irq) {
+		if (pcc_mbox_ctrl->txdone_irq) {
 			rc = pcc_parse_subspace_irq(pchan, pcct_entry);
 			if (rc < 0)
 				goto err;
@@ -660,51 +694,25 @@ static int __init acpi_pcc_probe(void)
 			((unsigned long) pcct_entry + pcct_entry->length);
 	}
 
-	pcc_mbox_ctrl.num_chans = count;
+	pcc_mbox_ctrl->num_chans = count;
 
-	pr_info("Detected %d PCC Subspaces\n", pcc_mbox_ctrl.num_chans);
+	pr_info("Detected %d PCC Subspaces\n", pcc_mbox_ctrl->num_chans);
 
-	return 0;
+	pcc_mbox_ctrl->chans = pcc_mbox_channels;
+	pcc_mbox_ctrl->ops = &pcc_chan_ops;
+	pcc_mbox_ctrl->dev = dev;
 
+	pr_info("Registering PCC driver as Mailbox controller\n");
+	rc = mbox_controller_register(pcc_mbox_ctrl);
+	if (rc)
+		pr_err("Err registering PCC as Mailbox controller: %d\n", rc);
+	else
+		return 0;
 err:
-	kfree(chan_info);
-err_free_mbox:
-	kfree(pcc_mbox_channels);
-err_put_pcct:
 	acpi_put_table(pcct_tbl);
 	return rc;
 }
 
-/**
- * pcc_mbox_probe - Called when we find a match for the
- *	PCCT platform device. This is purely used to represent
- *	the PCCT as a virtual device for registering with the
- *	generic Mailbox framework.
- *
- * @pdev: Pointer to platform device returned when a match
- *	is found.
- *
- *	Return: 0 for Success, else errno.
- */
-static int pcc_mbox_probe(struct platform_device *pdev)
-{
-	int ret = 0;
-
-	pcc_mbox_ctrl.chans = pcc_mbox_channels;
-	pcc_mbox_ctrl.ops = &pcc_chan_ops;
-	pcc_mbox_ctrl.dev = &pdev->dev;
-
-	pr_info("Registering PCC driver as Mailbox controller\n");
-	ret = mbox_controller_register(&pcc_mbox_ctrl);
-
-	if (ret) {
-		pr_err("Err registering PCC as Mailbox controller: %d\n", ret);
-		ret = -ENODEV;
-	}
-
-	return ret;
-}
-
 static struct platform_driver pcc_mbox_driver = {
 	.probe = pcc_mbox_probe,
 	.driver = {
-- 
2.25.1


  parent reply	other threads:[~2021-09-17 13:34 UTC|newest]

Thread overview: 23+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-09-17 13:33 [PATCH v2 00/14] mailbox: pcc: Add support for PCCT extended PCC subspaces Sudeep Holla
2021-09-17 13:33 ` [PATCH v2 01/14] mailbox: pcc: Fix kernel doc warnings Sudeep Holla
2021-09-17 13:33 ` [PATCH v2 02/14] ACPI: CPPC: " Sudeep Holla
2021-09-17 13:33 ` [PATCH v2 03/14] mailbox: pcc: Refactor all PCC channel information into a structure Sudeep Holla
2021-09-17 13:33 ` [PATCH v2 04/14] mailbox: pcc: Consolidate subspace interrupt information parsing Sudeep Holla
2021-09-17 13:33 ` [PATCH v2 05/14] mailbox: pcc: Consolidate subspace doorbell register parsing Sudeep Holla
2021-09-17 13:33 ` [PATCH v2 06/14] mailbox: pcc: Add pcc_mbox_chan structure to hold shared memory region info Sudeep Holla
2021-09-17 13:33 ` [PATCH v2 07/14] mailbox: pcc: Use PCC mailbox channel pointer instead of standard Sudeep Holla
2021-10-04 20:05   ` Wolfram Sang
2021-10-11 10:07   ` Sudeep Holla
2021-10-11 14:08   ` Guenter Roeck
2021-09-17 13:33 ` [PATCH v2 08/14] mailbox: pcc: Rename doorbell ack to platform interrupt ack register Sudeep Holla
2021-09-17 13:33 ` [PATCH v2 09/14] mailbox: pcc: Add PCC register bundle and associated accessor functions Sudeep Holla
2021-09-17 13:33 ` [PATCH v2 10/14] mailbox: pcc: Avoid accessing PCCT table in pcc_send_data and pcc_mbox_irq Sudeep Holla
2021-09-17 13:33 ` [PATCH v2 11/14] mailbox: pcc: Drop handling invalid bit-width in {read,write}_register Sudeep Holla
2021-09-17 13:33 ` [PATCH v2 12/14] mailbox: pcc: Add support for PCCT extended PCC subspaces(type 3/4) Sudeep Holla
2021-09-17 13:33 ` Sudeep Holla [this message]
2021-09-17 13:33 ` [PATCH v2 14/14] ACPI/PCC: Add myself as maintainer for PCC mailbox driver Sudeep Holla
2021-09-17 15:10   ` Rafael J. Wysocki
2021-10-11 10:09 ` [PATCH v2 00/14] mailbox: pcc: Add support for PCCT extended PCC subspaces Sudeep Holla
2021-10-21 16:54   ` Sudeep Holla
2021-10-22 15:05     ` Jassi Brar
2021-10-22 17:09       ` Sudeep Holla

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20210917133357.1911092-14-sudeep.holla@arm.com \
    --to=sudeep.holla@arm.com \
    --cc=cristian.marussi@arm.com \
    --cc=jassisinghbrar@gmail.com \
    --cc=linux-acpi@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=rjw@rjwysocki.net \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.