2018-06-05 04:30:36 +08:00
|
|
|
// SPDX-License-Identifier: GPL-2.0
|
|
|
|
/*
|
|
|
|
* Qualcomm Peripheral Image Loader for Q6V5
|
|
|
|
*
|
|
|
|
* Copyright (C) 2016-2018 Linaro Ltd.
|
|
|
|
* Copyright (C) 2014 Sony Mobile Communications AB
|
|
|
|
* Copyright (c) 2012-2013, The Linux Foundation. All rights reserved.
|
|
|
|
*/
|
|
|
|
#include <linux/kernel.h>
|
|
|
|
#include <linux/platform_device.h>
|
2022-02-25 11:32:24 +08:00
|
|
|
#include <linux/interconnect.h>
|
2018-06-05 04:30:36 +08:00
|
|
|
#include <linux/interrupt.h>
|
2018-07-06 20:57:53 +08:00
|
|
|
#include <linux/module.h>
|
2022-01-15 09:13:38 +08:00
|
|
|
#include <linux/soc/qcom/qcom_aoss.h>
|
2018-06-05 04:30:36 +08:00
|
|
|
#include <linux/soc/qcom/smem.h>
|
|
|
|
#include <linux/soc/qcom/smem_state.h>
|
|
|
|
#include <linux/remoteproc.h>
|
2020-11-22 13:41:34 +08:00
|
|
|
#include "qcom_common.h"
|
2018-06-05 04:30:36 +08:00
|
|
|
#include "qcom_q6v5.h"
|
|
|
|
|
2021-09-16 21:59:21 +08:00
|
|
|
#define Q6V5_LOAD_STATE_MSG_LEN 64
|
2020-03-24 13:29:03 +08:00
|
|
|
#define Q6V5_PANIC_DELAY_MS 200
|
|
|
|
|
2021-09-16 21:59:21 +08:00
|
|
|
static int q6v5_load_state_toggle(struct qcom_q6v5 *q6v5, bool enable)
|
|
|
|
{
|
|
|
|
char buf[Q6V5_LOAD_STATE_MSG_LEN];
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
if (!q6v5->qmp)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
ret = snprintf(buf, sizeof(buf),
|
|
|
|
"{class: image, res: load_state, name: %s, val: %s}",
|
|
|
|
q6v5->load_state, enable ? "on" : "off");
|
|
|
|
|
|
|
|
WARN_ON(ret >= Q6V5_LOAD_STATE_MSG_LEN);
|
|
|
|
|
|
|
|
ret = qmp_send(q6v5->qmp, buf, sizeof(buf));
|
|
|
|
if (ret)
|
|
|
|
dev_err(q6v5->dev, "failed to toggle load state\n");
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2018-06-05 04:30:36 +08:00
|
|
|
/**
|
|
|
|
* qcom_q6v5_prepare() - reinitialize the qcom_q6v5 context before start
|
|
|
|
* @q6v5: reference to qcom_q6v5 context to be reinitialized
|
|
|
|
*
|
|
|
|
* Return: 0 on success, negative errno on failure
|
|
|
|
*/
|
|
|
|
int qcom_q6v5_prepare(struct qcom_q6v5 *q6v5)
|
|
|
|
{
|
2021-09-16 21:59:21 +08:00
|
|
|
int ret;
|
|
|
|
|
2022-02-25 11:32:24 +08:00
|
|
|
ret = icc_set_bw(q6v5->path, 0, UINT_MAX);
|
|
|
|
if (ret < 0) {
|
|
|
|
dev_err(q6v5->dev, "failed to set bandwidth request\n");
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2021-09-16 21:59:21 +08:00
|
|
|
ret = q6v5_load_state_toggle(q6v5, true);
|
2022-02-25 11:32:24 +08:00
|
|
|
if (ret) {
|
|
|
|
icc_set_bw(q6v5->path, 0, 0);
|
2021-09-16 21:59:21 +08:00
|
|
|
return ret;
|
2022-02-25 11:32:24 +08:00
|
|
|
}
|
2021-09-16 21:59:21 +08:00
|
|
|
|
2018-06-05 04:30:36 +08:00
|
|
|
reinit_completion(&q6v5->start_done);
|
|
|
|
reinit_completion(&q6v5->stop_done);
|
|
|
|
|
|
|
|
q6v5->running = true;
|
|
|
|
q6v5->handover_issued = false;
|
|
|
|
|
|
|
|
enable_irq(q6v5->handover_irq);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
2018-07-06 20:57:53 +08:00
|
|
|
EXPORT_SYMBOL_GPL(qcom_q6v5_prepare);
|
2018-06-05 04:30:36 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* qcom_q6v5_unprepare() - unprepare the qcom_q6v5 context after stop
|
|
|
|
* @q6v5: reference to qcom_q6v5 context to be unprepared
|
|
|
|
*
|
|
|
|
* Return: 0 on success, 1 if handover hasn't yet been called
|
|
|
|
*/
|
|
|
|
int qcom_q6v5_unprepare(struct qcom_q6v5 *q6v5)
|
|
|
|
{
|
|
|
|
disable_irq(q6v5->handover_irq);
|
2021-09-16 21:59:21 +08:00
|
|
|
q6v5_load_state_toggle(q6v5, false);
|
2018-06-05 04:30:36 +08:00
|
|
|
|
2022-02-25 11:32:24 +08:00
|
|
|
/* Disable interconnect vote, in case handover never happened */
|
|
|
|
icc_set_bw(q6v5->path, 0, 0);
|
|
|
|
|
2018-06-05 04:30:36 +08:00
|
|
|
return !q6v5->handover_issued;
|
|
|
|
}
|
2018-07-06 20:57:53 +08:00
|
|
|
EXPORT_SYMBOL_GPL(qcom_q6v5_unprepare);
|
2018-06-05 04:30:36 +08:00
|
|
|
|
|
|
|
static irqreturn_t q6v5_wdog_interrupt(int irq, void *data)
|
|
|
|
{
|
|
|
|
struct qcom_q6v5 *q6v5 = data;
|
|
|
|
size_t len;
|
|
|
|
char *msg;
|
|
|
|
|
|
|
|
/* Sometimes the stop triggers a watchdog rather than a stop-ack */
|
|
|
|
if (!q6v5->running) {
|
|
|
|
complete(&q6v5->stop_done);
|
|
|
|
return IRQ_HANDLED;
|
|
|
|
}
|
|
|
|
|
|
|
|
msg = qcom_smem_get(QCOM_SMEM_HOST_ANY, q6v5->crash_reason, &len);
|
|
|
|
if (!IS_ERR(msg) && len > 0 && msg[0])
|
|
|
|
dev_err(q6v5->dev, "watchdog received: %s\n", msg);
|
|
|
|
else
|
|
|
|
dev_err(q6v5->dev, "watchdog without message\n");
|
|
|
|
|
2022-07-05 20:08:18 +08:00
|
|
|
q6v5->running = false;
|
2018-06-05 04:30:36 +08:00
|
|
|
rproc_report_crash(q6v5->rproc, RPROC_WATCHDOG);
|
|
|
|
|
|
|
|
return IRQ_HANDLED;
|
|
|
|
}
|
|
|
|
|
|
|
|
static irqreturn_t q6v5_fatal_interrupt(int irq, void *data)
|
|
|
|
{
|
|
|
|
struct qcom_q6v5 *q6v5 = data;
|
|
|
|
size_t len;
|
|
|
|
char *msg;
|
|
|
|
|
2022-07-05 20:08:18 +08:00
|
|
|
if (!q6v5->running)
|
|
|
|
return IRQ_HANDLED;
|
|
|
|
|
2018-06-05 04:30:36 +08:00
|
|
|
msg = qcom_smem_get(QCOM_SMEM_HOST_ANY, q6v5->crash_reason, &len);
|
|
|
|
if (!IS_ERR(msg) && len > 0 && msg[0])
|
|
|
|
dev_err(q6v5->dev, "fatal error received: %s\n", msg);
|
|
|
|
else
|
|
|
|
dev_err(q6v5->dev, "fatal error without message\n");
|
|
|
|
|
2018-10-01 22:25:00 +08:00
|
|
|
q6v5->running = false;
|
2018-06-05 04:30:36 +08:00
|
|
|
rproc_report_crash(q6v5->rproc, RPROC_FATAL_ERROR);
|
|
|
|
|
|
|
|
return IRQ_HANDLED;
|
|
|
|
}
|
|
|
|
|
|
|
|
static irqreturn_t q6v5_ready_interrupt(int irq, void *data)
|
|
|
|
{
|
|
|
|
struct qcom_q6v5 *q6v5 = data;
|
|
|
|
|
|
|
|
complete(&q6v5->start_done);
|
|
|
|
|
|
|
|
return IRQ_HANDLED;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* qcom_q6v5_wait_for_start() - wait for remote processor start signal
|
|
|
|
* @q6v5: reference to qcom_q6v5 context
|
|
|
|
* @timeout: timeout to wait for the event, in jiffies
|
|
|
|
*
|
|
|
|
* qcom_q6v5_unprepare() should not be called when this function fails.
|
|
|
|
*
|
|
|
|
* Return: 0 on success, -ETIMEDOUT on timeout
|
|
|
|
*/
|
|
|
|
int qcom_q6v5_wait_for_start(struct qcom_q6v5 *q6v5, int timeout)
|
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
ret = wait_for_completion_timeout(&q6v5->start_done, timeout);
|
|
|
|
if (!ret)
|
|
|
|
disable_irq(q6v5->handover_irq);
|
|
|
|
|
|
|
|
return !ret ? -ETIMEDOUT : 0;
|
|
|
|
}
|
2018-07-06 20:57:53 +08:00
|
|
|
EXPORT_SYMBOL_GPL(qcom_q6v5_wait_for_start);
|
2018-06-05 04:30:36 +08:00
|
|
|
|
|
|
|
static irqreturn_t q6v5_handover_interrupt(int irq, void *data)
|
|
|
|
{
|
|
|
|
struct qcom_q6v5 *q6v5 = data;
|
|
|
|
|
|
|
|
if (q6v5->handover)
|
|
|
|
q6v5->handover(q6v5);
|
|
|
|
|
2022-02-25 11:32:24 +08:00
|
|
|
icc_set_bw(q6v5->path, 0, 0);
|
|
|
|
|
2018-06-05 04:30:36 +08:00
|
|
|
q6v5->handover_issued = true;
|
|
|
|
|
|
|
|
return IRQ_HANDLED;
|
|
|
|
}
|
|
|
|
|
|
|
|
static irqreturn_t q6v5_stop_interrupt(int irq, void *data)
|
|
|
|
{
|
|
|
|
struct qcom_q6v5 *q6v5 = data;
|
|
|
|
|
|
|
|
complete(&q6v5->stop_done);
|
|
|
|
|
|
|
|
return IRQ_HANDLED;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* qcom_q6v5_request_stop() - request the remote processor to stop
|
|
|
|
* @q6v5: reference to qcom_q6v5 context
|
2020-11-22 13:41:34 +08:00
|
|
|
* @sysmon: reference to the remote's sysmon instance, or NULL
|
2018-06-05 04:30:36 +08:00
|
|
|
*
|
|
|
|
* Return: 0 on success, negative errno on failure
|
|
|
|
*/
|
2020-11-22 13:41:34 +08:00
|
|
|
int qcom_q6v5_request_stop(struct qcom_q6v5 *q6v5, struct qcom_sysmon *sysmon)
|
2018-06-05 04:30:36 +08:00
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
|
2020-06-03 00:32:56 +08:00
|
|
|
q6v5->running = false;
|
|
|
|
|
2020-11-22 13:41:34 +08:00
|
|
|
/* Don't perform SMP2P dance if sysmon already shut down the remote */
|
|
|
|
if (qcom_sysmon_shutdown_acked(sysmon))
|
|
|
|
return 0;
|
|
|
|
|
2018-06-05 04:30:36 +08:00
|
|
|
qcom_smem_state_update_bits(q6v5->state,
|
|
|
|
BIT(q6v5->stop_bit), BIT(q6v5->stop_bit));
|
|
|
|
|
|
|
|
ret = wait_for_completion_timeout(&q6v5->stop_done, 5 * HZ);
|
|
|
|
|
|
|
|
qcom_smem_state_update_bits(q6v5->state, BIT(q6v5->stop_bit), 0);
|
|
|
|
|
|
|
|
return ret == 0 ? -ETIMEDOUT : 0;
|
|
|
|
}
|
2018-07-06 20:57:53 +08:00
|
|
|
EXPORT_SYMBOL_GPL(qcom_q6v5_request_stop);
|
2018-06-05 04:30:36 +08:00
|
|
|
|
2020-03-24 13:29:03 +08:00
|
|
|
/**
|
|
|
|
* qcom_q6v5_panic() - panic handler to invoke a stop on the remote
|
|
|
|
* @q6v5: reference to qcom_q6v5 context
|
|
|
|
*
|
|
|
|
* Set the stop bit and sleep in order to allow the remote processor to flush
|
|
|
|
* its caches etc for post mortem debugging.
|
|
|
|
*
|
|
|
|
* Return: 200ms
|
|
|
|
*/
|
|
|
|
unsigned long qcom_q6v5_panic(struct qcom_q6v5 *q6v5)
|
|
|
|
{
|
|
|
|
qcom_smem_state_update_bits(q6v5->state,
|
|
|
|
BIT(q6v5->stop_bit), BIT(q6v5->stop_bit));
|
|
|
|
|
|
|
|
return Q6V5_PANIC_DELAY_MS;
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL_GPL(qcom_q6v5_panic);
|
|
|
|
|
2018-06-05 04:30:36 +08:00
|
|
|
/**
|
|
|
|
* qcom_q6v5_init() - initializer of the q6v5 common struct
|
|
|
|
* @q6v5: handle to be initialized
|
|
|
|
* @pdev: platform_device reference for acquiring resources
|
|
|
|
* @rproc: associated remoteproc instance
|
|
|
|
* @crash_reason: SMEM id for crash reason string, or 0 if none
|
2021-09-16 21:59:21 +08:00
|
|
|
* @load_state: load state resource string
|
2018-06-05 04:30:36 +08:00
|
|
|
* @handover: function to be called when proxy resources should be released
|
|
|
|
*
|
|
|
|
* Return: 0 on success, negative errno on failure
|
|
|
|
*/
|
|
|
|
int qcom_q6v5_init(struct qcom_q6v5 *q6v5, struct platform_device *pdev,
|
2021-09-16 21:59:21 +08:00
|
|
|
struct rproc *rproc, int crash_reason, const char *load_state,
|
2018-06-05 04:30:36 +08:00
|
|
|
void (*handover)(struct qcom_q6v5 *q6v5))
|
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
q6v5->rproc = rproc;
|
|
|
|
q6v5->dev = &pdev->dev;
|
|
|
|
q6v5->crash_reason = crash_reason;
|
|
|
|
q6v5->handover = handover;
|
|
|
|
|
|
|
|
init_completion(&q6v5->start_done);
|
|
|
|
init_completion(&q6v5->stop_done);
|
|
|
|
|
|
|
|
q6v5->wdog_irq = platform_get_irq_byname(pdev, "wdog");
|
2019-07-31 02:15:38 +08:00
|
|
|
if (q6v5->wdog_irq < 0)
|
2018-10-10 06:25:27 +08:00
|
|
|
return q6v5->wdog_irq;
|
|
|
|
|
2018-06-05 04:30:36 +08:00
|
|
|
ret = devm_request_threaded_irq(&pdev->dev, q6v5->wdog_irq,
|
|
|
|
NULL, q6v5_wdog_interrupt,
|
|
|
|
IRQF_TRIGGER_RISING | IRQF_ONESHOT,
|
|
|
|
"q6v5 wdog", q6v5);
|
|
|
|
if (ret) {
|
|
|
|
dev_err(&pdev->dev, "failed to acquire wdog IRQ\n");
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
q6v5->fatal_irq = platform_get_irq_byname(pdev, "fatal");
|
2019-07-31 02:15:38 +08:00
|
|
|
if (q6v5->fatal_irq < 0)
|
2018-10-10 06:25:27 +08:00
|
|
|
return q6v5->fatal_irq;
|
2018-09-20 09:51:51 +08:00
|
|
|
|
2018-06-05 04:30:36 +08:00
|
|
|
ret = devm_request_threaded_irq(&pdev->dev, q6v5->fatal_irq,
|
|
|
|
NULL, q6v5_fatal_interrupt,
|
|
|
|
IRQF_TRIGGER_RISING | IRQF_ONESHOT,
|
|
|
|
"q6v5 fatal", q6v5);
|
|
|
|
if (ret) {
|
|
|
|
dev_err(&pdev->dev, "failed to acquire fatal IRQ\n");
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
q6v5->ready_irq = platform_get_irq_byname(pdev, "ready");
|
2019-07-31 02:15:38 +08:00
|
|
|
if (q6v5->ready_irq < 0)
|
2018-10-10 06:25:27 +08:00
|
|
|
return q6v5->ready_irq;
|
2018-09-20 09:51:51 +08:00
|
|
|
|
2018-06-05 04:30:36 +08:00
|
|
|
ret = devm_request_threaded_irq(&pdev->dev, q6v5->ready_irq,
|
|
|
|
NULL, q6v5_ready_interrupt,
|
|
|
|
IRQF_TRIGGER_RISING | IRQF_ONESHOT,
|
|
|
|
"q6v5 ready", q6v5);
|
|
|
|
if (ret) {
|
|
|
|
dev_err(&pdev->dev, "failed to acquire ready IRQ\n");
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
q6v5->handover_irq = platform_get_irq_byname(pdev, "handover");
|
2019-07-31 02:15:38 +08:00
|
|
|
if (q6v5->handover_irq < 0)
|
2018-10-10 06:25:27 +08:00
|
|
|
return q6v5->handover_irq;
|
2018-09-20 09:51:51 +08:00
|
|
|
|
2018-06-05 04:30:36 +08:00
|
|
|
ret = devm_request_threaded_irq(&pdev->dev, q6v5->handover_irq,
|
|
|
|
NULL, q6v5_handover_interrupt,
|
|
|
|
IRQF_TRIGGER_RISING | IRQF_ONESHOT,
|
|
|
|
"q6v5 handover", q6v5);
|
|
|
|
if (ret) {
|
|
|
|
dev_err(&pdev->dev, "failed to acquire handover IRQ\n");
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
disable_irq(q6v5->handover_irq);
|
|
|
|
|
|
|
|
q6v5->stop_irq = platform_get_irq_byname(pdev, "stop-ack");
|
2019-07-31 02:15:38 +08:00
|
|
|
if (q6v5->stop_irq < 0)
|
2018-10-10 06:25:27 +08:00
|
|
|
return q6v5->stop_irq;
|
2018-09-20 09:51:51 +08:00
|
|
|
|
2018-06-05 04:30:36 +08:00
|
|
|
ret = devm_request_threaded_irq(&pdev->dev, q6v5->stop_irq,
|
|
|
|
NULL, q6v5_stop_interrupt,
|
|
|
|
IRQF_TRIGGER_RISING | IRQF_ONESHOT,
|
|
|
|
"q6v5 stop", q6v5);
|
|
|
|
if (ret) {
|
|
|
|
dev_err(&pdev->dev, "failed to acquire stop-ack IRQ\n");
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2021-06-18 19:15:55 +08:00
|
|
|
q6v5->state = devm_qcom_smem_state_get(&pdev->dev, "stop", &q6v5->stop_bit);
|
2018-06-05 04:30:36 +08:00
|
|
|
if (IS_ERR(q6v5->state)) {
|
|
|
|
dev_err(&pdev->dev, "failed to acquire stop state\n");
|
|
|
|
return PTR_ERR(q6v5->state);
|
|
|
|
}
|
|
|
|
|
2021-09-16 21:59:21 +08:00
|
|
|
q6v5->load_state = devm_kstrdup_const(&pdev->dev, load_state, GFP_KERNEL);
|
|
|
|
q6v5->qmp = qmp_get(&pdev->dev);
|
|
|
|
if (IS_ERR(q6v5->qmp)) {
|
|
|
|
if (PTR_ERR(q6v5->qmp) != -ENODEV)
|
|
|
|
return dev_err_probe(&pdev->dev, PTR_ERR(q6v5->qmp),
|
|
|
|
"failed to acquire load state\n");
|
|
|
|
q6v5->qmp = NULL;
|
|
|
|
} else if (!q6v5->load_state) {
|
|
|
|
if (!load_state)
|
|
|
|
dev_err(&pdev->dev, "load state resource string empty\n");
|
|
|
|
|
|
|
|
qmp_put(q6v5->qmp);
|
|
|
|
return load_state ? -ENOMEM : -EINVAL;
|
|
|
|
}
|
|
|
|
|
2022-02-25 11:32:24 +08:00
|
|
|
q6v5->path = devm_of_icc_get(&pdev->dev, NULL);
|
|
|
|
if (IS_ERR(q6v5->path))
|
|
|
|
return dev_err_probe(&pdev->dev, PTR_ERR(q6v5->path),
|
|
|
|
"failed to acquire interconnect path\n");
|
|
|
|
|
2018-06-05 04:30:36 +08:00
|
|
|
return 0;
|
|
|
|
}
|
2018-07-06 20:57:53 +08:00
|
|
|
EXPORT_SYMBOL_GPL(qcom_q6v5_init);
|
|
|
|
|
2021-09-16 21:59:21 +08:00
|
|
|
/**
|
|
|
|
* qcom_q6v5_deinit() - deinitialize the q6v5 common struct
|
|
|
|
* @q6v5: reference to qcom_q6v5 context to be deinitialized
|
|
|
|
*/
|
|
|
|
void qcom_q6v5_deinit(struct qcom_q6v5 *q6v5)
|
|
|
|
{
|
|
|
|
qmp_put(q6v5->qmp);
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL_GPL(qcom_q6v5_deinit);
|
|
|
|
|
2018-07-06 20:57:53 +08:00
|
|
|
MODULE_LICENSE("GPL v2");
|
|
|
|
MODULE_DESCRIPTION("Qualcomm Peripheral Image Loader for Q6V5");
|