Skip to content

Commit 38c927f

Browse files
committed
firmware: arm_scmi: Separate out tx buffer handling and prepare to add rx
Currently we pre-allocate transmit buffers only and use the first free slot in that pre-allocated buffer for transmitting any new message that are generally originated from OS to the platform firmware. Notifications or the delayed responses on the other hand are originated from the platform firmware and consumes by the OS. It's better to have separate and dedicated pre-allocated buffers to handle the notifications. We can still use the transmit buffers for the delayed responses. In addition, let's prepare existing scmi_xfer_{get,put} for acquiring and releasing a slot to identify the right(tx/rx) buffers. Signed-off-by: Sudeep Holla <[email protected]>
1 parent 46cc7c2 commit 38c927f

File tree

1 file changed

+27
-13
lines changed

1 file changed

+27
-13
lines changed

drivers/firmware/arm_scmi/driver.c

Lines changed: 27 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ struct scmi_chan_info {
111111
* @handle: Instance of SCMI handle to send to clients
112112
* @version: SCMI revision information containing protocol version,
113113
* implementation version and (sub-)vendor identification.
114-
* @minfo: Message info
114+
* @tx_minfo: Universal Transmit Message management info
115115
* @tx_idr: IDR object to map protocol id to Tx channel info pointer
116116
* @rx_idr: IDR object to map protocol id to Rx channel info pointer
117117
* @protocols_imp: List of protocols implemented, currently maximum of
@@ -124,7 +124,7 @@ struct scmi_info {
124124
const struct scmi_desc *desc;
125125
struct scmi_revision_info version;
126126
struct scmi_handle handle;
127-
struct scmi_xfers_info minfo;
127+
struct scmi_xfers_info tx_minfo;
128128
struct idr tx_idr;
129129
struct idr rx_idr;
130130
u8 *protocols_imp;
@@ -251,6 +251,7 @@ static void scmi_tx_prepare(struct mbox_client *cl, void *m)
251251
* scmi_xfer_get() - Allocate one message
252252
*
253253
* @handle: Pointer to SCMI entity handle
254+
* @minfo: Pointer to Tx/Rx Message management info based on channel type
254255
*
255256
* Helper function which is used by various message functions that are
256257
* exposed to clients of this driver for allocating a message traffic event.
@@ -261,13 +262,13 @@ static void scmi_tx_prepare(struct mbox_client *cl, void *m)
261262
*
262263
* Return: 0 if all went fine, else corresponding error.
263264
*/
264-
static struct scmi_xfer *scmi_xfer_get(const struct scmi_handle *handle)
265+
static struct scmi_xfer *scmi_xfer_get(const struct scmi_handle *handle,
266+
struct scmi_xfers_info *minfo)
265267
{
266268
u16 xfer_id;
267269
struct scmi_xfer *xfer;
268270
unsigned long flags, bit_pos;
269271
struct scmi_info *info = handle_to_scmi_info(handle);
270-
struct scmi_xfers_info *minfo = &info->minfo;
271272

272273
/* Keep the locked section as small as possible */
273274
spin_lock_irqsave(&minfo->xfer_lock, flags);
@@ -290,18 +291,17 @@ static struct scmi_xfer *scmi_xfer_get(const struct scmi_handle *handle)
290291
}
291292

292293
/**
293-
* scmi_xfer_put() - Release a message
294+
* __scmi_xfer_put() - Release a message
294295
*
295-
* @handle: Pointer to SCMI entity handle
296+
* @minfo: Pointer to Tx/Rx Message management info based on channel type
296297
* @xfer: message that was reserved by scmi_xfer_get
297298
*
298299
* This holds a spinlock to maintain integrity of internal data structures.
299300
*/
300-
void scmi_xfer_put(const struct scmi_handle *handle, struct scmi_xfer *xfer)
301+
static void
302+
__scmi_xfer_put(struct scmi_xfers_info *minfo, struct scmi_xfer *xfer)
301303
{
302304
unsigned long flags;
303-
struct scmi_info *info = handle_to_scmi_info(handle);
304-
struct scmi_xfers_info *minfo = &info->minfo;
305305

306306
/*
307307
* Keep the locked section as small as possible
@@ -332,7 +332,7 @@ static void scmi_rx_callback(struct mbox_client *cl, void *m)
332332
struct scmi_chan_info *cinfo = client_to_scmi_chan_info(cl);
333333
struct device *dev = cinfo->dev;
334334
struct scmi_info *info = handle_to_scmi_info(cinfo->handle);
335-
struct scmi_xfers_info *minfo = &info->minfo;
335+
struct scmi_xfers_info *minfo = &info->tx_minfo;
336336
struct scmi_shared_mem __iomem *mem = cinfo->payload;
337337

338338
xfer_id = MSG_XTRACT_TOKEN(ioread32(&mem->msg_header));
@@ -351,6 +351,19 @@ static void scmi_rx_callback(struct mbox_client *cl, void *m)
351351
complete(&xfer->done);
352352
}
353353

354+
/**
355+
* scmi_xfer_put() - Release a transmit message
356+
*
357+
* @handle: Pointer to SCMI entity handle
358+
* @xfer: message that was reserved by scmi_xfer_get
359+
*/
360+
void scmi_xfer_put(const struct scmi_handle *handle, struct scmi_xfer *xfer)
361+
{
362+
struct scmi_info *info = handle_to_scmi_info(handle);
363+
364+
__scmi_xfer_put(&info->tx_minfo, xfer);
365+
}
366+
354367
static bool
355368
scmi_xfer_poll_done(const struct scmi_chan_info *cinfo, struct scmi_xfer *xfer)
356369
{
@@ -440,7 +453,7 @@ int scmi_do_xfer(const struct scmi_handle *handle, struct scmi_xfer *xfer)
440453
}
441454

442455
/**
443-
* scmi_xfer_get_init() - Allocate and initialise one message
456+
* scmi_xfer_get_init() - Allocate and initialise one message for transmit
444457
*
445458
* @handle: Pointer to SCMI entity handle
446459
* @msg_id: Message identifier
@@ -461,14 +474,15 @@ int scmi_xfer_get_init(const struct scmi_handle *handle, u8 msg_id, u8 prot_id,
461474
int ret;
462475
struct scmi_xfer *xfer;
463476
struct scmi_info *info = handle_to_scmi_info(handle);
477+
struct scmi_xfers_info *minfo = &info->tx_minfo;
464478
struct device *dev = info->dev;
465479

466480
/* Ensure we have sane transfer sizes */
467481
if (rx_size > info->desc->max_msg_size ||
468482
tx_size > info->desc->max_msg_size)
469483
return -ERANGE;
470484

471-
xfer = scmi_xfer_get(handle);
485+
xfer = scmi_xfer_get(handle, minfo);
472486
if (IS_ERR(xfer)) {
473487
ret = PTR_ERR(xfer);
474488
dev_err(dev, "failed to get free message slot(%d)\n", ret);
@@ -607,7 +621,7 @@ static int scmi_xfer_info_init(struct scmi_info *sinfo)
607621
struct scmi_xfer *xfer;
608622
struct device *dev = sinfo->dev;
609623
const struct scmi_desc *desc = sinfo->desc;
610-
struct scmi_xfers_info *info = &sinfo->minfo;
624+
struct scmi_xfers_info *info = &sinfo->tx_minfo;
611625

612626
/* Pre-allocated messages, no more than what hdr.seq can support */
613627
if (WARN_ON(desc->max_msg >= MSG_TOKEN_MAX)) {

0 commit comments

Comments
 (0)