Skip to content

Commit 59e0910

Browse files
quic-bjorandeandersson
authored andcommitted
soc: qcom: aoss: Move length requirements from caller
The existing implementation of qmp_send() requires the caller to provide a buffer which is of word-aligned. The underlying reason for this is that message ram only supports word accesses, but pushing this requirement onto the clients results in the same boiler plate code sprinkled in every call site. By using a temporary buffer in qmp_send() we can hide the underlying hardware limitations from the clients and allow them to pass their NUL-terminates C string directly. Signed-off-by: Bjorn Andersson <quic_bjorande@quicinc.com> Reviewed-by: Konrad Dybcio <konrad.dybcio@linaro.org> Link: https://lore.kernel.org/r/20230811205839.727373-2-quic_bjorande@quicinc.com Signed-off-by: Bjorn Andersson <andersson@kernel.org>
1 parent f9eac7e commit 59e0910

File tree

4 files changed

+16
-17
lines changed

4 files changed

+16
-17
lines changed

drivers/net/ipa/ipa_power.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -332,7 +332,7 @@ void ipa_power_retention(struct ipa *ipa, bool enable)
332332

333333
(void)snprintf(buf, sizeof(buf), fmt, enable ? '1' : '0');
334334

335-
ret = qmp_send(power->qmp, buf, sizeof(buf));
335+
ret = qmp_send(power->qmp, buf);
336336
if (ret)
337337
dev_err(power->dev, "error %d sending QMP %sable request\n",
338338
ret, enable ? "en" : "dis");

drivers/remoteproc/qcom_q6v5.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ static int q6v5_load_state_toggle(struct qcom_q6v5 *q6v5, bool enable)
3535

3636
WARN_ON(ret >= Q6V5_LOAD_STATE_MSG_LEN);
3737

38-
ret = qmp_send(q6v5->qmp, buf, sizeof(buf));
38+
ret = qmp_send(q6v5->qmp, buf);
3939
if (ret)
4040
dev_err(q6v5->dev, "failed to toggle load state\n");
4141

drivers/soc/qcom/qcom_aoss.c

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -206,36 +206,35 @@ static bool qmp_message_empty(struct qmp *qmp)
206206
* qmp_send() - send a message to the AOSS
207207
* @qmp: qmp context
208208
* @data: message to be sent
209-
* @len: length of the message
210209
*
211210
* Transmit @data to AOSS and wait for the AOSS to acknowledge the message.
212-
* @len must be a multiple of 4 and not longer than the mailbox size. Access is
213-
* synchronized by this implementation.
211+
* data must not be longer than the mailbox size. Access is synchronized by
212+
* this implementation.
214213
*
215214
* Return: 0 on success, negative errno on failure
216215
*/
217-
int qmp_send(struct qmp *qmp, const void *data, size_t len)
216+
int qmp_send(struct qmp *qmp, const void *data)
218217
{
218+
char buf[QMP_MSG_LEN];
219219
long time_left;
220220
int ret;
221221

222222
if (WARN_ON(IS_ERR_OR_NULL(qmp) || !data))
223223
return -EINVAL;
224224

225-
if (WARN_ON(len + sizeof(u32) > qmp->size))
225+
if (WARN_ON(strlen(data) >= sizeof(buf)))
226226
return -EINVAL;
227227

228-
if (WARN_ON(len % sizeof(u32)))
229-
return -EINVAL;
228+
strscpy_pad(buf, data, sizeof(buf));
230229

231230
mutex_lock(&qmp->tx_lock);
232231

233232
/* The message RAM only implements 32-bit accesses */
234233
__iowrite32_copy(qmp->msgram + qmp->offset + sizeof(u32),
235-
data, len / sizeof(u32));
236-
writel(len, qmp->msgram + qmp->offset);
234+
buf, sizeof(buf) / sizeof(u32));
235+
writel(sizeof(buf), qmp->msgram + qmp->offset);
237236

238-
/* Read back len to confirm data written in message RAM */
237+
/* Read back length to confirm data written in message RAM */
239238
readl(qmp->msgram + qmp->offset);
240239
qmp_kick(qmp);
241240

@@ -262,15 +261,15 @@ static int qmp_qdss_clk_prepare(struct clk_hw *hw)
262261
static const char buf[QMP_MSG_LEN] = "{class: clock, res: qdss, val: 1}";
263262
struct qmp *qmp = container_of(hw, struct qmp, qdss_clk);
264263

265-
return qmp_send(qmp, buf, sizeof(buf));
264+
return qmp_send(qmp, buf);
266265
}
267266

268267
static void qmp_qdss_clk_unprepare(struct clk_hw *hw)
269268
{
270269
static const char buf[QMP_MSG_LEN] = "{class: clock, res: qdss, val: 0}";
271270
struct qmp *qmp = container_of(hw, struct qmp, qdss_clk);
272271

273-
qmp_send(qmp, buf, sizeof(buf));
272+
qmp_send(qmp, buf);
274273
}
275274

276275
static const struct clk_ops qmp_qdss_clk_ops = {
@@ -344,7 +343,7 @@ static int qmp_cdev_set_cur_state(struct thermal_cooling_device *cdev,
344343
qmp_cdev->name,
345344
cdev_state ? "on" : "off");
346345

347-
ret = qmp_send(qmp_cdev->qmp, buf, sizeof(buf));
346+
ret = qmp_send(qmp_cdev->qmp, buf);
348347

349348
if (!ret)
350349
qmp_cdev->state = cdev_state;

include/linux/soc/qcom/qcom_aoss.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,13 @@ struct qmp;
1313

1414
#if IS_ENABLED(CONFIG_QCOM_AOSS_QMP)
1515

16-
int qmp_send(struct qmp *qmp, const void *data, size_t len);
16+
int qmp_send(struct qmp *qmp, const void *data);
1717
struct qmp *qmp_get(struct device *dev);
1818
void qmp_put(struct qmp *qmp);
1919

2020
#else
2121

22-
static inline int qmp_send(struct qmp *qmp, const void *data, size_t len)
22+
static inline int qmp_send(struct qmp *qmp, const void *data)
2323
{
2424
return -ENODEV;
2525
}

0 commit comments

Comments
 (0)