public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Jonathan Cameron <Jonathan.Cameron@huawei.com>
To: Sudeep Holla <sudeep.holla@arm.com>
Cc: ALKML <linux-arm-kernel@lists.infradead.org>,
	LKML <linux-kernel@vger.kernel.org>,
	DTML <devicetree@vger.kernel.org>,
	"Alexey Klimov" <klimov.linux@gmail.com>,
	Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	Arnd Bergmann <arnd@arndb.de>
Subject: Re: [PATCH v6 03/20] firmware: arm_scmi: add basic driver infrastructure for SCMI
Date: Mon, 5 Mar 2018 14:47:42 +0000	[thread overview]
Message-ID: <20180305154742.000029c0@huawei.com> (raw)
In-Reply-To: <9d6e431e-fa07-63b6-81fc-6b00c7e8267e@arm.com>



> >> +/**
> >> + * scmi_one_xfer_get() - Allocate one message
> >> + *
> >> + * @handle: SCMI entity handle
> >> + *
> >> + * Helper function which is used by various command functions that are
> >> + * exposed to clients of this driver for allocating a message traffic event.
> >> + *
> >> + * This function can sleep depending on pending requests already in the system
> >> + * for the SCMI entity. Further, this also holds a spinlock to maintain
> >> + * integrity of internal data structures.
> >> + *
> >> + * Return: 0 if all went fine, else corresponding error.
> >> + */
> >> +static struct scmi_xfer *scmi_one_xfer_get(const struct scmi_handle *handle)  
> > Maybe it's just me, but I think this would be more clearly named as
> > scmi_xfer_alloc.
> >   
> 
> Agreed to some extent. The reason I didn't have it as alloc as they are
> preallocated and this just returns a reference to free slot in that
> preallocated array.
> 
> > I'd assume we were dealing with one anyway as it's not called scmi_xfers_get
> > and the get to my mind implies a reference counter rather than allocating
> > an xfer for use...
> >   
> 
> Ah OK, I get your concerne with _get/_put but _alloc/_free is equally
> bad then in the contect of preallocated buffers.
Sure, this is always a fun question.  Lots of other options
_assign _deassign works but never feels nice.

> 
...
> 
> >> +	.max_msg = 20,		/* Limited by MBOX_TX_QUEUE_LEN */
> >> +	.max_msg_size = 128,
> >> +};
> >> +
> >> +/* Each compatible listed below must have descriptor associated with it */
> >> +static const struct of_device_id scmi_of_match[] = {
> >> +	{ .compatible = "arm,scmi", .data = &scmi_generic_desc },
> >> +	{ /* Sentinel */ },
> >> +};
> >> +
> >> +MODULE_DEVICE_TABLE(of, scmi_of_match);
> >> +
> >> +static int scmi_xfer_info_init(struct scmi_info *sinfo)
> >> +{
> >> +	int i;
> >> +	struct scmi_xfer *xfer;
> >> +	struct device *dev = sinfo->dev;
> >> +	const struct scmi_desc *desc = sinfo->desc;
> >> +	struct scmi_xfers_info *info = &sinfo->minfo;
> >> +
> >> +	/* Pre-allocated messages, no more than what hdr.seq can support */
> >> +	if (WARN_ON(desc->max_msg >= (MSG_TOKEN_ID_MASK + 1))) {
> >> +		dev_err(dev, "Maximum message of %d exceeds supported %d\n",
> >> +			desc->max_msg, MSG_TOKEN_ID_MASK + 1);
> >> +		return -EINVAL;
> >> +	}
> >> +
> >> +	info->xfer_block = devm_kcalloc(dev, desc->max_msg,
> >> +					sizeof(*info->xfer_block), GFP_KERNEL);
> >> +	if (!info->xfer_block)
> >> +		return -ENOMEM;
> >> +
> >> +	info->xfer_alloc_table = devm_kcalloc(dev, BITS_TO_LONGS(desc->max_msg),
> >> +					      sizeof(long), GFP_KERNEL);
> >> +	if (!info->xfer_alloc_table)
> >> +		return -ENOMEM;  
> > Hmm. I wonder if it is worth adding a devm_bitmap_alloc?
> >   
> 
> OK
> 
> >> +
> >> +	bitmap_zero(info->xfer_alloc_table, desc->max_msg);  
> > kcalloc zeros the memory.
> >   
> >> +
> >> +	/* Pre-initialize the buffer pointer to pre-allocated buffers */
> >> +	for (i = 0, xfer = info->xfer_block; i < desc->max_msg; i++, xfer++) {
> >> +		xfer->rx.buf = devm_kcalloc(dev, sizeof(u8), desc->max_msg_size,
> >> +					    GFP_KERNEL);
> >> +		if (!xfer->rx.buf)
> >> +			return -ENOMEM;
> >> +
> >> +		xfer->tx.buf = xfer->rx.buf;
> >> +		init_completion(&xfer->done);
> >> +	}
> >> +
> >> +	spin_lock_init(&info->xfer_lock);
> >> +
> >> +	return 0;
> >> +}
> >> +
> >> +static int scmi_mailbox_check(struct device_node *np)
> >> +{
> >> +	struct of_phandle_args arg;
> >> +
> >> +	return of_parse_phandle_with_args(np, "mboxes", "#mbox-cells", 0, &arg);
> >> +}
> >> +
> >> +static int scmi_mbox_free_channel(struct scmi_info *info)  
> > Some of the naming in here could do with being adjusted to be obviously
> > 'balanced'.  The moment I see a free I expect a matched alloc but in this
> > case the alloc is done in scmi_mbox_chan_setup which at very least
> > should be scmi_mbox_setup_channel and should really imply that it is
> > doing allocation as well.
> >   
> 
> That's inline with mailbox APIs.

oh goody.  Fair enough if ugly
> 
...
> OK

  reply	other threads:[~2018-03-05 14:47 UTC|newest]

Thread overview: 37+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-02-23 16:23 [PATCH v6 00/20] firmware: ARM System Control and Management Interface(SCMI) support Sudeep Holla
2018-02-23 16:23 ` [PATCH v6 01/20] dt-bindings: mailbox: add support for mailbox client shared memory Sudeep Holla
2018-02-23 16:23 ` [PATCH v6 02/20] dt-bindings: arm: add support for ARM System Control and Management Interface(SCMI) protocol Sudeep Holla
2018-02-23 16:23 ` [PATCH v6 03/20] firmware: arm_scmi: add basic driver infrastructure for SCMI Sudeep Holla
2018-02-26 15:57   ` Philippe Ombredanne
2018-02-26 17:10     ` Sudeep Holla
2018-03-05 13:52   ` Jonathan Cameron
2018-03-05 14:30     ` Sudeep Holla
2018-03-05 14:47       ` Jonathan Cameron [this message]
2018-02-23 16:23 ` [PATCH v6 04/20] firmware: arm_scmi: add common infrastructure and support for base protocol Sudeep Holla
2018-03-05 14:11   ` Jonathan Cameron
2018-02-23 16:23 ` [PATCH v6 05/20] firmware: arm_scmi: add scmi protocol bus to enumerate protocol devices Sudeep Holla
2018-03-05 14:23   ` Jonathan Cameron
2018-02-23 16:23 ` [PATCH v6 06/20] firmware: arm_scmi: add initial support for performance protocol Sudeep Holla
2018-03-05 14:29   ` Jonathan Cameron
2018-02-23 16:23 ` [PATCH v6 07/20] firmware: arm_scmi: add initial support for clock protocol Sudeep Holla
2018-02-23 16:23 ` [PATCH v6 08/20] firmware: arm_scmi: add initial support for power protocol Sudeep Holla
2018-02-23 16:23 ` [PATCH v6 09/20] firmware: arm_scmi: add initial support for sensor protocol Sudeep Holla
2018-02-23 16:23 ` [PATCH v6 10/20] firmware: arm_scmi: probe and initialise all the supported protocols Sudeep Holla
2018-02-23 16:23 ` [PATCH v6 11/20] firmware: arm_scmi: add support for polling based SCMI transfers Sudeep Holla
2018-02-23 16:23 ` [PATCH v6 12/20] firmware: arm_scmi: add option for polling based performance domain operations Sudeep Holla
2018-02-23 16:23 ` [PATCH v6 13/20] firmware: arm_scmi: refactor in preparation to support per-protocol channels Sudeep Holla
2018-03-05 14:35   ` Jonathan Cameron
2018-03-05 14:43     ` Sudeep Holla
2018-02-23 16:23 ` [PATCH v6 14/20] firmware: arm_scmi: add per-protocol channels support using idr objects Sudeep Holla
2018-02-23 16:23 ` [PATCH v6 15/20] firmware: arm_scmi: add device power domain support using genpd Sudeep Holla
2018-02-23 16:23 ` [PATCH v6 16/20] clk: add support for clocks provided by SCMI Sudeep Holla
2018-03-16 23:02   ` Stephen Boyd
2018-03-20 12:08     ` Sudeep Holla
2018-03-20 16:22       ` Stephen Boyd
2018-03-20 12:11   ` [PATCH] clk: scmi: use devm_of_clk_add_hw_provider() API and drop scmi_clocks_remove Sudeep Holla
2018-03-20 14:42     ` Sudeep Holla
2018-03-20 16:22     ` Stephen Boyd
2018-02-23 16:23 ` [PATCH v6 17/20] hwmon: (core) Add hwmon_max to hwmon_sensor_types enumeration Sudeep Holla
2018-02-23 16:23 ` [PATCH v6 18/20] hwmon: add support for sensors exported via ARM SCMI Sudeep Holla
2018-02-23 16:23 ` [PATCH v6 19/20] cpufreq: add support for CPU DVFS based on SCMI message protocol Sudeep Holla
2018-02-23 16:23 ` [PATCH v6 20/20] cpufreq: scmi: add support for fast frequency switching 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=20180305154742.000029c0@huawei.com \
    --to=jonathan.cameron@huawei.com \
    --cc=arnd@arndb.de \
    --cc=devicetree@vger.kernel.org \
    --cc=gregkh@linuxfoundation.org \
    --cc=klimov.linux@gmail.com \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=sudeep.holla@arm.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