Skip to content

Commit 564b5e2

Browse files
Lina IyerAndy Gross
authored andcommitted
drivers: qcom: rpmh: allow requests to be sent asynchronously
Platform drivers that want to send a request but do not want to block until the RPMH request completes have now a new API - rpmh_write_async(). The API allocates memory and send the requests and returns the control back to the platform driver. The tx_done callback from the controller is handled in the context of the controller's thread and frees the allocated memory. This API allows RPMH requests from atomic contexts as well. Signed-off-by: Lina Iyer <ilina@codeaurora.org> Signed-off-by: Raju P.L.S.S.S.N <rplsssn@codeaurora.org> Signed-off-by: Andy Gross <andy.gross@linaro.org>
1 parent 600513d commit 564b5e2

File tree

3 files changed

+60
-0
lines changed

3 files changed

+60
-0
lines changed

drivers/soc/qcom/rpmh-internal.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,13 +54,15 @@ struct tcs_group {
5454
* @completion: triggered when request is done
5555
* @dev: the device making the request
5656
* @err: err return from the controller
57+
* @needs_free: check to free dynamically allocated request object
5758
*/
5859
struct rpmh_request {
5960
struct tcs_request msg;
6061
struct tcs_cmd cmd[MAX_RPMH_PAYLOAD];
6162
struct completion *completion;
6263
const struct device *dev;
6364
int err;
65+
bool needs_free;
6466
};
6567

6668
/**

drivers/soc/qcom/rpmh.c

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
.cmd = { { 0 } }, \
3535
.completion = q, \
3636
.dev = dev, \
37+
.needs_free = false, \
3738
}
3839

3940
#define ctrlr_to_drv(ctrlr) container_of(ctrlr, struct rsc_drv, client)
@@ -75,6 +76,9 @@ void rpmh_tx_done(const struct tcs_request *msg, int r)
7576
/* Signal the blocking thread we are done */
7677
if (compl)
7778
complete(compl);
79+
80+
if (rpm_msg->needs_free)
81+
kfree(rpm_msg);
7882
}
7983

8084
static struct cache_req *__find_req(struct rpmh_ctrlr *ctrlr, u32 addr)
@@ -180,6 +184,53 @@ static int __rpmh_write(const struct device *dev, enum rpmh_state state,
180184
return ret;
181185
}
182186

187+
static int __fill_rpmh_msg(struct rpmh_request *req, enum rpmh_state state,
188+
const struct tcs_cmd *cmd, u32 n)
189+
{
190+
if (!cmd || !n || n > MAX_RPMH_PAYLOAD)
191+
return -EINVAL;
192+
193+
memcpy(req->cmd, cmd, n * sizeof(*cmd));
194+
195+
req->msg.state = state;
196+
req->msg.cmds = req->cmd;
197+
req->msg.num_cmds = n;
198+
199+
return 0;
200+
}
201+
202+
/**
203+
* rpmh_write_async: Write a set of RPMH commands
204+
*
205+
* @dev: The device making the request
206+
* @state: Active/sleep set
207+
* @cmd: The payload data
208+
* @n: The number of elements in payload
209+
*
210+
* Write a set of RPMH commands, the order of commands is maintained
211+
* and will be sent as a single shot.
212+
*/
213+
int rpmh_write_async(const struct device *dev, enum rpmh_state state,
214+
const struct tcs_cmd *cmd, u32 n)
215+
{
216+
struct rpmh_request *rpm_msg;
217+
int ret;
218+
219+
rpm_msg = kzalloc(sizeof(*rpm_msg), GFP_ATOMIC);
220+
if (!rpm_msg)
221+
return -ENOMEM;
222+
rpm_msg->needs_free = true;
223+
224+
ret = __fill_rpmh_msg(rpm_msg, state, cmd, n);
225+
if (ret) {
226+
kfree(rpm_msg);
227+
return ret;
228+
}
229+
230+
return __rpmh_write(dev, state, rpm_msg);
231+
}
232+
EXPORT_SYMBOL(rpmh_write_async);
233+
183234
/**
184235
* rpmh_write: Write a set of RPMH commands and block until response
185236
*

include/soc/qcom/rpmh.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@
1414
int rpmh_write(const struct device *dev, enum rpmh_state state,
1515
const struct tcs_cmd *cmd, u32 n);
1616

17+
int rpmh_write_async(const struct device *dev, enum rpmh_state state,
18+
const struct tcs_cmd *cmd, u32 n);
19+
1720
int rpmh_flush(const struct device *dev);
1821

1922
int rpmh_invalidate(const struct device *dev);
@@ -24,6 +27,10 @@ static inline int rpmh_write(const struct device *dev, enum rpmh_state state,
2427
const struct tcs_cmd *cmd, u32 n)
2528
{ return -ENODEV; }
2629

30+
static inline int rpmh_write_async(const struct device *dev,
31+
enum rpmh_state state,
32+
const struct tcs_cmd *cmd, u32 n)
33+
{ return -ENODEV; }
2734

2835
static inline int rpmh_flush(const struct device *dev)
2936
{ return -ENODEV; }

0 commit comments

Comments
 (0)