linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Sudeep Holla <sudeep.holla@arm.com>
To: ALKML <linux-arm-kernel@lists.infradead.org>,
	LKML <linux-kernel@vger.kernel.org>,
	DTML <devicetree@vger.kernel.org>
Cc: Sudeep Holla <sudeep.holla@arm.com>,
	Roy Franz <roy.franz@cavium.com>,
	Harb Abdulhamid <harba@codeaurora.org>,
	Nishanth Menon <nm@ti.com>, Arnd Bergmann <arnd@arndb.de>,
	Loc Ho <lho@apm.com>, Ryan Harkin <Ryan.Harkin@arm.com>,
	Jassi Brar <jassisinghbrar@gmail.com>
Subject: [PATCH v4 14/20] firmware: arm_scmi: add per-protocol channels support using idr objects
Date: Fri,  3 Nov 2017 14:47:51 +0000	[thread overview]
Message-ID: <1509720477-18936-15-git-send-email-sudeep.holla@arm.com> (raw)
In-Reply-To: <1509720477-18936-1-git-send-email-sudeep.holla@arm.com>

In order to maintain the channel information per protocol, we need
some sort of list or hashtable to hold all this information. IDR
provides sparse array mapping of small integer ID numbers onto arbitrary
pointers. In this case the arbitrary pointers can be pointers to the
channel information.

This patch adds support for per-protocol channels using those idr
objects.

Cc: Arnd Bergmann <arnd@arndb.de>
Signed-off-by: Sudeep Holla <sudeep.holla@arm.com>
---
 drivers/firmware/arm_scmi/driver.c | 54 +++++++++++++++++++++++++++++---------
 1 file changed, 42 insertions(+), 12 deletions(-)

diff --git a/drivers/firmware/arm_scmi/driver.c b/drivers/firmware/arm_scmi/driver.c
index 24acb421208c..6734a035bcc6 100644
--- a/drivers/firmware/arm_scmi/driver.c
+++ b/drivers/firmware/arm_scmi/driver.c
@@ -118,6 +118,7 @@ struct scmi_chan_info {
 	struct mbox_chan *chan;
 	void __iomem *payload;
 	struct device *dev;
+	struct scmi_handle *handle;
 };
 
 /**
@@ -129,7 +130,7 @@ struct scmi_chan_info {
  * @version: SCMI revision information containing protocol version,
  *	implementation version and (sub-)vendor identification.
  * @minfo: Message info
- * @tx_cinfo: Reference to SCMI channel information
+ * @tx_idr: IDR object to map protocol id to channel info pointer
  * @protocols_imp: list of protocols implemented, currently maximum of
  *	MAX_PROTOCOLS_IMP elements allocated by the base protocol
  * @node: list head
@@ -141,7 +142,7 @@ struct scmi_info {
 	struct scmi_revision_info version;
 	struct scmi_handle handle;
 	struct scmi_xfers_info minfo;
-	struct scmi_chan_info *tx_cinfo;
+	struct idr tx_idr;
 	u8 *protocols_imp;
 	struct list_head node;
 	int users;
@@ -232,7 +233,7 @@ static void scmi_rx_callback(struct mbox_client *cl, void *m)
 	struct scmi_xfer *xfer;
 	struct scmi_chan_info *cinfo = client_to_scmi_chan_info(cl);
 	struct device *dev = cinfo->dev;
-	struct scmi_info *info = dev_get_drvdata(dev);
+	struct scmi_info *info = handle_to_scmi_info(cinfo->handle);
 	struct scmi_xfers_info *minfo = &info->minfo;
 	struct scmi_shared_mem __iomem *mem = cinfo->payload;
 
@@ -409,7 +410,11 @@ int scmi_do_xfer(const struct scmi_handle *handle, struct scmi_xfer *xfer)
 	int timeout;
 	struct scmi_info *info = handle_to_scmi_info(handle);
 	struct device *dev = info->dev;
-	struct scmi_chan_info *cinfo = info->tx_cinfo;
+	struct scmi_chan_info *cinfo;
+
+	cinfo = idr_find(&info->tx_idr, xfer->hdr.protocol_id);
+	if (unlikely(!cinfo))
+		return -EINVAL;
 
 	ret = mbox_send_message(cinfo->chan, xfer);
 	if (ret < 0) {
@@ -681,13 +686,18 @@ static int scmi_mailbox_check(struct device_node *np)
 	return of_parse_phandle_with_args(np, "mboxes", "#mbox-cells", 0, &arg);
 }
 
-static int scmi_mbox_free_channel(struct scmi_chan_info *cinfo)
+static int scmi_mbox_free_channel(int id, void *p, void *data)
 {
+	struct scmi_chan_info *cinfo = p;
+	struct idr *idr = data;
+
 	if (!IS_ERR_OR_NULL(cinfo->chan)) {
 		mbox_free_channel(cinfo->chan);
 		cinfo->chan = NULL;
 	}
 
+	idr_remove(idr, id);
+
 	return 0;
 }
 
@@ -695,6 +705,7 @@ static int scmi_remove(struct platform_device *pdev)
 {
 	int ret = 0;
 	struct scmi_info *info = platform_get_drvdata(pdev);
+	struct idr *idr = &info->tx_idr;
 
 	mutex_lock(&scmi_list_mutex);
 	if (info->users)
@@ -703,28 +714,34 @@ static int scmi_remove(struct platform_device *pdev)
 		list_del(&info->node);
 	mutex_unlock(&scmi_list_mutex);
 
-	if (!ret)
+	if (!ret) {
 		/* Safe to free channels since no more users */
-		return scmi_mbox_free_channel(info->tx_cinfo);
+		ret = idr_for_each(idr, scmi_mbox_free_channel, idr);
+		idr_destroy(&info->tx_idr);
+	}
 
 	return ret;
 }
 
-static inline int scmi_mbox_chan_setup(struct scmi_info *info)
+static inline int
+scmi_mbox_chan_setup(struct scmi_info *info, struct device *dev, int prot_id)
 {
 	int ret;
 	struct resource res;
 	resource_size_t size;
-	struct device *dev = info->dev;
 	struct device_node *shmem, *np = dev->of_node;
 	struct scmi_chan_info *cinfo;
 	struct mbox_client *cl;
 
+	if (scmi_mailbox_check(np)) {
+		cinfo = idr_find(&info->tx_idr, SCMI_PROTOCOL_BASE);
+		goto idr_alloc;
+	}
+
 	cinfo = devm_kzalloc(info->dev, sizeof(*cinfo), GFP_KERNEL);
 	if (!cinfo)
 		return -ENOMEM;
 
-	info->tx_cinfo = cinfo;
 	cinfo->dev = dev;
 
 	cl = &cinfo->cl;
@@ -758,6 +775,14 @@ static inline int scmi_mbox_chan_setup(struct scmi_info *info)
 		return ret;
 	}
 
+idr_alloc:
+	ret = idr_alloc(&info->tx_idr, cinfo, prot_id, prot_id + 1, GFP_KERNEL);
+	if (ret != prot_id) {
+		dev_err(dev, "unable to allocate SCMI idr slot err %d\n", ret);
+		return ret;
+	}
+
+	cinfo->handle = &info->handle;
 	return 0;
 }
 
@@ -774,6 +799,11 @@ scmi_create_protocol_device(struct device_node *np, struct scmi_info *info,
 		return;
 	}
 
+	if (scmi_mbox_chan_setup(info, &sdev->dev, prot_id)) {
+		dev_err(&sdev->dev, "failed to setup transport\n");
+		scmi_device_destroy(sdev);
+	}
+
 	/* setup handle now as the transport is ready */
 	scmi_set_handle(sdev);
 }
@@ -808,19 +838,19 @@ static int scmi_probe(struct platform_device *pdev)
 		return ret;
 
 	platform_set_drvdata(pdev, info);
+	idr_init(&info->tx_idr);
 
 	handle = &info->handle;
 	handle->dev = info->dev;
 	handle->version = &info->version;
 
-	ret = scmi_mbox_chan_setup(info);
+	ret = scmi_mbox_chan_setup(info, dev, SCMI_PROTOCOL_BASE);
 	if (ret)
 		return ret;
 
 	ret = scmi_base_protocol_init(handle);
 	if (ret) {
 		dev_err(dev, "unable to communicate with SCMI(%d)\n", ret);
-		scmi_mbox_free_channel(info->tx_cinfo);
 		return ret;
 	}
 
-- 
2.7.4

  parent reply	other threads:[~2017-11-03 14:49 UTC|newest]

Thread overview: 34+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-11-03 14:47 [PATCH v4 00/20] firmware: ARM System Control and Management Interface(SCMI) support Sudeep Holla
2017-11-03 14:47 ` [PATCH v4 01/20] dt-bindings: mailbox: add support for mailbox client shared memory Sudeep Holla
2017-11-03 14:47 ` [PATCH v4 02/20] dt-bindings: arm: add support for ARM System Control and Management Interface(SCMI) protocol Sudeep Holla
2017-11-06 22:18   ` Rob Herring
2017-11-03 14:47 ` [PATCH v4 03/20] firmware: arm_scmi: add basic driver infrastructure for SCMI Sudeep Holla
2017-11-04 11:51   ` Jassi Brar
2017-11-08 16:33     ` Sudeep Holla
2017-11-03 14:47 ` [PATCH v4 04/20] firmware: arm_scmi: add common infrastructure and support for base protocol Sudeep Holla
2017-11-03 14:47 ` [PATCH v4 05/20] firmware: arm_scmi: add scmi protocol bus to enumerate protocol devices Sudeep Holla
2017-11-21 18:04   ` Sudeep Holla
2017-11-03 14:47 ` [PATCH v4 06/20] firmware: arm_scmi: add initial support for performance protocol Sudeep Holla
2017-11-03 14:47 ` [PATCH v4 07/20] firmware: arm_scmi: add initial support for clock protocol Sudeep Holla
2017-11-03 14:47 ` [PATCH v4 08/20] firmware: arm_scmi: add initial support for power protocol Sudeep Holla
2017-11-03 14:47 ` [PATCH v4 09/20] firmware: arm_scmi: add initial support for sensor protocol Sudeep Holla
2017-11-03 14:47 ` [PATCH v4 10/20] firmware: arm_scmi: probe and initialise all the supported protocols Sudeep Holla
2017-11-03 14:47 ` [PATCH v4 11/20] firmware: arm_scmi: add support for polling based SCMI transfers Sudeep Holla
2017-11-03 14:47 ` [PATCH v4 12/20] firmware: arm_scmi: add option for polling based performance domain operations Sudeep Holla
2017-11-03 14:47 ` [PATCH v4 13/20] firmware: arm_scmi: refactor in preparation to support per-protocol channels Sudeep Holla
2017-11-03 14:47 ` Sudeep Holla [this message]
2017-11-03 14:47 ` [PATCH v4 15/20] firmware: arm_scmi: add device power domain support using genpd Sudeep Holla
2017-11-03 14:56   ` Sudeep Holla
2017-11-03 14:47 ` [PATCH v4 16/20] clk: add support for clocks provided by SCMI Sudeep Holla
2017-11-03 14:47 ` [PATCH v4 17/20] hwmon: (core) Add hwmon_max to hwmon_sensor_types enumeration Sudeep Holla
2017-11-03 14:47 ` [PATCH v4 18/20] hwmon: add support for sensors exported via ARM SCMI Sudeep Holla
2017-11-03 14:47 ` [PATCH v4 19/20] cpufreq: add support for CPU DVFS based on SCMI message protocol Sudeep Holla
2017-11-07  6:15   ` Viresh Kumar
2017-11-03 14:47 ` [PATCH v4 20/20] cpufreq: scmi: add support for fast frequency switching Sudeep Holla
2017-11-07  6:19   ` Viresh Kumar
2017-11-07 10:57     ` Sudeep Holla
2017-11-08  0:24   ` Rafael J. Wysocki
2017-11-08 10:42     ` Sudeep Holla
2017-11-08 11:05       ` Arnd Bergmann
2017-11-08 15:42         ` Sudeep Holla
2017-11-08 11:21       ` Rafael J. Wysocki

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=1509720477-18936-15-git-send-email-sudeep.holla@arm.com \
    --to=sudeep.holla@arm.com \
    --cc=Ryan.Harkin@arm.com \
    --cc=arnd@arndb.de \
    --cc=devicetree@vger.kernel.org \
    --cc=harba@codeaurora.org \
    --cc=jassisinghbrar@gmail.com \
    --cc=lho@apm.com \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=nm@ti.com \
    --cc=roy.franz@cavium.com \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).