Merge tag 'rproc-v6.16' of git://git.kernel.org/pub/scm/linux/kernel/git/remoteproc/linux

Pull remoteproc updates from Bjorn Andersson:

 - Fix resource cleanup in the remoteproc attach error handling code
   paths

 - Refactor the various TI K3 drivers to extract and reuse common code
   between them

 - Add support in the i.MX remoteproc driver for determining from the
   firmware if Linux should wait on a "firmware ready" signal at startup

 - Improve the Xilinx R5F power down mechanism to handle use cases where
   this is shared with other entities in the system

* tag 'rproc-v6.16' of git://git.kernel.org/pub/scm/linux/kernel/git/remoteproc/linux: (46 commits)
  remoteproc: k3: Refactor release_tsp() functions into common driver
  remoteproc: k3: Refactor reserved_mem_init() functions into common driver
  remoteproc: k3: Refactor mem_release() functions into common driver
  remoteproc: k3: Refactor of_get_memories() functions into common driver
  remoteproc: k3: Refactor .da_to_va rproc ops into common driver
  remoteproc: k3: Refactor .get_loaded_rsc_table ops into common driver
  remoteproc: k3: Refactor .detach rproc ops into common driver
  remoteproc: k3: Refactor .attach rproc ops into common driver
  remoteproc: k3: Refactor .stop rproc ops into common driver
  remoteproc: k3: Refactor .start rproc ops into common driver
  remoteproc: k3: Refactor .unprepare rproc ops into common driver
  remoteproc: k3: Refactor .prepare rproc ops into common driver
  remoteproc: k3-dsp: Assert local reset during .prepare callback
  remoteproc: k3-dsp: Don't override rproc ops in IPC-only mode
  remoteproc: k3: Refactor rproc_request_mbox() implementations into common driver
  remoteproc: k3-m4: Ping the mbox while acquiring the channel
  remoteproc: k3: Refactor rproc_release() implementation into common driver
  remoteproc: k3-m4: Introduce central function to release rproc from reset
  remoteproc: k3-dsp: Correct Reset deassert logic for devices w/o lresets
  remoteproc: k3: Refactor rproc_reset() implementation into common driver
  ...
This commit is contained in:
Linus Torvalds
2025-06-02 11:04:29 -07:00
14 changed files with 1304 additions and 1874 deletions
@@ -16,6 +16,9 @@ description:
properties:
compatible:
enum:
- qcom,sc8180x-adsp-pas
- qcom,sc8180x-cdsp-pas
- qcom,sc8180x-slpi-pas
- qcom,sm8150-adsp-pas
- qcom,sm8150-cdsp-pas
- qcom,sm8150-mpss-pas
@@ -15,16 +15,20 @@ description:
properties:
compatible:
enum:
- qcom,sar2130p-adsp-pas
- qcom,sm8350-adsp-pas
- qcom,sm8350-cdsp-pas
- qcom,sm8350-slpi-pas
- qcom,sm8350-mpss-pas
- qcom,sm8450-adsp-pas
- qcom,sm8450-cdsp-pas
- qcom,sm8450-mpss-pas
- qcom,sm8450-slpi-pas
oneOf:
- enum:
- qcom,sar2130p-adsp-pas
- qcom,sm8350-adsp-pas
- qcom,sm8350-cdsp-pas
- qcom,sm8350-slpi-pas
- qcom,sm8350-mpss-pas
- qcom,sm8450-adsp-pas
- qcom,sm8450-cdsp-pas
- qcom,sm8450-mpss-pas
- qcom,sm8450-slpi-pas
- items:
- const: qcom,sc8280xp-slpi-pas
- const: qcom,sm8350-slpi-pas
reg:
maxItems: 1
@@ -61,14 +65,15 @@ allOf:
- if:
properties:
compatible:
enum:
- qcom,sar2130p-adsp-pas
- qcom,sm8350-adsp-pas
- qcom,sm8350-cdsp-pas
- qcom,sm8350-slpi-pas
- qcom,sm8450-adsp-pas
- qcom,sm8450-cdsp-pas
- qcom,sm8450-slpi-pas
contains:
enum:
- qcom,sar2130p-adsp-pas
- qcom,sm8350-adsp-pas
- qcom,sm8350-cdsp-pas
- qcom,sm8350-slpi-pas
- qcom,sm8450-adsp-pas
- qcom,sm8450-cdsp-pas
- qcom,sm8450-slpi-pas
then:
properties:
interrupts:
@@ -102,12 +107,13 @@ allOf:
- if:
properties:
compatible:
enum:
- qcom,sar2130p-adsp-pas
- qcom,sm8350-adsp-pas
- qcom,sm8350-slpi-pas
- qcom,sm8450-adsp-pas
- qcom,sm8450-slpi-pas
contains:
enum:
- qcom,sar2130p-adsp-pas
- qcom,sm8350-adsp-pas
- qcom,sm8350-slpi-pas
- qcom,sm8450-adsp-pas
- qcom,sm8450-slpi-pas
then:
properties:
power-domains:
@@ -139,6 +139,10 @@ properties:
If defined, when remoteproc is probed, it loads the default firmware and
starts the remote processor.
firmware-name:
maxItems: 1
description: Default name of the remote processor firmware.
required:
- compatible
- reg
+3 -3
View File
@@ -36,7 +36,7 @@ obj-$(CONFIG_RCAR_REMOTEPROC) += rcar_rproc.o
obj-$(CONFIG_ST_REMOTEPROC) += st_remoteproc.o
obj-$(CONFIG_ST_SLIM_REMOTEPROC) += st_slim_rproc.o
obj-$(CONFIG_STM32_RPROC) += stm32_rproc.o
obj-$(CONFIG_TI_K3_DSP_REMOTEPROC) += ti_k3_dsp_remoteproc.o
obj-$(CONFIG_TI_K3_M4_REMOTEPROC) += ti_k3_m4_remoteproc.o
obj-$(CONFIG_TI_K3_R5_REMOTEPROC) += ti_k3_r5_remoteproc.o
obj-$(CONFIG_TI_K3_DSP_REMOTEPROC) += ti_k3_dsp_remoteproc.o ti_k3_common.o
obj-$(CONFIG_TI_K3_M4_REMOTEPROC) += ti_k3_m4_remoteproc.o ti_k3_common.o
obj-$(CONFIG_TI_K3_R5_REMOTEPROC) += ti_k3_r5_remoteproc.o ti_k3_common.o
obj-$(CONFIG_XLNX_R5_REMOTEPROC) += xlnx_r5_remoteproc.o
+96 -2
View File
@@ -36,9 +36,18 @@ module_param_named(no_mailboxes, no_mailboxes, int, 0644);
MODULE_PARM_DESC(no_mailboxes,
"There is no mailbox between cores, so ignore remote proc reply after start, default is 0 (off).");
/* Flag indicating that the remote is up and running */
#define REMOTE_IS_READY BIT(0)
/* Flag indicating that the host should wait for a firmware-ready response */
#define WAIT_FW_READY BIT(1)
#define REMOTE_READY_WAIT_MAX_RETRIES 500
/*
* This flag is set in the DSP resource table's features field to indicate
* that the firmware requires the host NOT to wait for a FW_READY response.
*/
#define FEATURE_DONT_WAIT_FW_READY BIT(0)
/* att flags */
/* DSP own area */
#define ATT_OWN BIT(31)
@@ -73,6 +82,10 @@ MODULE_PARM_DESC(no_mailboxes,
#define IMX8ULP_SIP_HIFI_XRDC 0xc200000e
#define FW_RSC_NXP_S_MAGIC ((uint32_t)'n' << 24 | \
(uint32_t)'x' << 16 | \
(uint32_t)'p' << 8 | \
(uint32_t)'s')
/*
* enum - Predefined Mailbox Messages
*
@@ -139,6 +152,24 @@ struct imx_dsp_rproc_dcfg {
int (*reset)(struct imx_dsp_rproc *priv);
};
/**
* struct fw_rsc_imx_dsp - i.MX DSP specific info
*
* @len: length of the resource entry
* @magic_num: 32-bit magic number
* @version: version of data structure
* @features: feature flags supported by the i.MX DSP firmware
*
* This represents a DSP-specific resource in the firmware's
* resource table, providing information on supported features.
*/
struct fw_rsc_imx_dsp {
uint32_t len;
uint32_t magic_num;
uint32_t version;
uint32_t features;
} __packed;
static const struct imx_rproc_att imx_dsp_rproc_att_imx8qm[] = {
/* dev addr , sys addr , size , flags */
{ 0x596e8000, 0x556e8000, 0x00008000, ATT_OWN },
@@ -297,6 +328,66 @@ static int imx_dsp_rproc_ready(struct rproc *rproc)
return -ETIMEDOUT;
}
/**
* imx_dsp_rproc_handle_rsc() - Handle DSP-specific resource table entries
* @rproc: remote processor instance
* @rsc_type: resource type identifier
* @rsc: pointer to the resource entry
* @offset: offset of the resource entry
* @avail: available space in the resource table
*
* Parse the DSP-specific resource entry and update flags accordingly.
* If the WAIT_FW_READY feature is set, the host must wait for the firmware
* to signal readiness before proceeding with execution.
*
* Return: RSC_HANDLED if processed successfully, RSC_IGNORED otherwise.
*/
static int imx_dsp_rproc_handle_rsc(struct rproc *rproc, u32 rsc_type,
void *rsc, int offset, int avail)
{
struct imx_dsp_rproc *priv = rproc->priv;
struct fw_rsc_imx_dsp *imx_dsp_rsc = rsc;
struct device *dev = rproc->dev.parent;
if (!imx_dsp_rsc) {
dev_dbg(dev, "Invalid fw_rsc_imx_dsp.\n");
return RSC_IGNORED;
}
/* Make sure resource isn't truncated */
if (sizeof(struct fw_rsc_imx_dsp) > avail ||
sizeof(struct fw_rsc_imx_dsp) != imx_dsp_rsc->len) {
dev_dbg(dev, "Resource fw_rsc_imx_dsp is truncated.\n");
return RSC_IGNORED;
}
/*
* If FW_RSC_NXP_S_MAGIC number is not found then
* wait for fw_ready reply (default work flow)
*/
if (imx_dsp_rsc->magic_num != FW_RSC_NXP_S_MAGIC) {
dev_dbg(dev, "Invalid resource table magic number.\n");
return RSC_IGNORED;
}
/*
* For now, in struct fw_rsc_imx_dsp, version 0,
* only FEATURE_DONT_WAIT_FW_READY is valid.
*
* When adding new features, please upgrade version.
*/
if (imx_dsp_rsc->version > 0) {
dev_warn(dev, "Unexpected fw_rsc_imx_dsp version %d.\n",
imx_dsp_rsc->version);
return RSC_IGNORED;
}
if (imx_dsp_rsc->features & FEATURE_DONT_WAIT_FW_READY)
priv->flags &= ~WAIT_FW_READY;
return RSC_HANDLED;
}
/*
* Start function for rproc_ops
*
@@ -335,8 +426,8 @@ static int imx_dsp_rproc_start(struct rproc *rproc)
if (ret)
dev_err(dev, "Failed to enable remote core!\n");
else
ret = imx_dsp_rproc_ready(rproc);
else if (priv->flags & WAIT_FW_READY)
return imx_dsp_rproc_ready(rproc);
return ret;
}
@@ -939,6 +1030,7 @@ static const struct rproc_ops imx_dsp_rproc_ops = {
.kick = imx_dsp_rproc_kick,
.load = imx_dsp_rproc_elf_load_segments,
.parse_fw = imx_dsp_rproc_parse_fw,
.handle_rsc = imx_dsp_rproc_handle_rsc,
.find_loaded_rsc_table = rproc_elf_find_loaded_rsc_table,
.sanity_check = rproc_elf_sanity_check,
.get_boot_addr = rproc_elf_get_boot_addr,
@@ -1058,6 +1150,8 @@ static int imx_dsp_rproc_probe(struct platform_device *pdev)
priv = rproc->priv;
priv->rproc = rproc;
priv->dsp_dcfg = dsp_dcfg;
/* By default, host waits for fw_ready reply */
priv->flags |= WAIT_FW_READY;
if (no_mailboxes)
imx_dsp_rproc_mbox_init = imx_dsp_rproc_mbox_no_alloc;
+2
View File
@@ -196,6 +196,7 @@ struct qcom_iris *qcom_iris_probe(struct device *parent, bool *use_48mhz_xo)
err_device_del:
device_del(&iris->dev);
put_device(&iris->dev);
return ERR_PTR(ret);
}
@@ -203,4 +204,5 @@ err_device_del:
void qcom_iris_remove(struct qcom_iris *iris)
{
device_del(&iris->dev);
put_device(&iris->dev);
}
+3 -4
View File
@@ -1617,7 +1617,7 @@ static int rproc_attach(struct rproc *rproc)
ret = rproc_set_rsc_table(rproc);
if (ret) {
dev_err(dev, "can't load resource table: %d\n", ret);
goto unprepare_device;
goto clean_up_resources;
}
/* reset max_notifyid */
@@ -1634,7 +1634,7 @@ static int rproc_attach(struct rproc *rproc)
ret = rproc_handle_resources(rproc, rproc_loading_handlers);
if (ret) {
dev_err(dev, "Failed to process resources: %d\n", ret);
goto unprepare_device;
goto clean_up_resources;
}
/* Allocate carveout resources associated to rproc */
@@ -1653,9 +1653,9 @@ static int rproc_attach(struct rproc *rproc)
clean_up_resources:
rproc_resource_cleanup(rproc);
unprepare_device:
/* release HW resources if needed */
rproc_unprepare_device(rproc);
kfree(rproc->clean_table);
disable_iommu:
rproc_disable_iommu(rproc);
return ret;
@@ -2025,7 +2025,6 @@ int rproc_shutdown(struct rproc *rproc)
kfree(rproc->cached_table);
rproc->cached_table = NULL;
rproc->table_ptr = NULL;
rproc->table_sz = 0;
out:
mutex_unlock(&rproc->lock);
return ret;
+7 -1
View File
@@ -835,6 +835,7 @@ static int stm32_rproc_probe(struct platform_device *pdev)
struct device *dev = &pdev->dev;
struct stm32_rproc *ddata;
struct device_node *np = dev->of_node;
const char *fw_name;
struct rproc *rproc;
unsigned int state;
int ret;
@@ -843,7 +844,12 @@ static int stm32_rproc_probe(struct platform_device *pdev)
if (ret)
return ret;
rproc = devm_rproc_alloc(dev, np->name, &st_rproc_ops, NULL, sizeof(*ddata));
/* Look for an optional firmware name */
ret = rproc_of_parse_firmware(dev, 0, &fw_name);
if (ret < 0 && ret != -EINVAL)
return ret;
rproc = devm_rproc_alloc(dev, np->name, &st_rproc_ops, fw_name, sizeof(*ddata));
if (!rproc)
return -ENOMEM;
+551
View File
@@ -0,0 +1,551 @@
// SPDX-License-Identifier: GPL-2.0-only
/*
* TI K3 Remote Processor(s) driver common code
*
* Refactored out of ti_k3_r5_remoteproc.c, ti_k3_dsp_remoteproc.c and
* ti_k3_m4_remoteproc.c.
*
* ti_k3_r5_remoteproc.c:
* Copyright (C) 2017-2022 Texas Instruments Incorporated - https://www.ti.com/
* Suman Anna <s-anna@ti.com>
*
* ti_k3_dsp_remoteproc.c:
* Copyright (C) 2018-2022 Texas Instruments Incorporated - https://www.ti.com/
* Suman Anna <s-anna@ti.com>
*
* ti_k3_m4_remoteproc.c:
* Copyright (C) 2021-2024 Texas Instruments Incorporated - https://www.ti.com/
* Hari Nagalla <hnagalla@ti.com>
*/
#include <linux/io.h>
#include <linux/mailbox_client.h>
#include <linux/module.h>
#include <linux/of_address.h>
#include <linux/of_device.h>
#include <linux/of_reserved_mem.h>
#include <linux/omap-mailbox.h>
#include <linux/platform_device.h>
#include <linux/remoteproc.h>
#include <linux/reset.h>
#include <linux/slab.h>
#include "omap_remoteproc.h"
#include "remoteproc_internal.h"
#include "ti_sci_proc.h"
#include "ti_k3_common.h"
/**
* k3_rproc_mbox_callback() - inbound mailbox message handler
* @client: mailbox client pointer used for requesting the mailbox channel
* @data: mailbox payload
*
* This handler is invoked by the K3 mailbox driver whenever a mailbox
* message is received. Usually, the mailbox payload simply contains
* the index of the virtqueue that is kicked by the remote processor,
* and we let remoteproc core handle it.
*
* In addition to virtqueue indices, we also have some out-of-band values
* that indicate different events. Those values are deliberately very
* large so they don't coincide with virtqueue indices.
*/
void k3_rproc_mbox_callback(struct mbox_client *client, void *data)
{
struct k3_rproc *kproc = container_of(client, struct k3_rproc, client);
struct device *dev = kproc->rproc->dev.parent;
struct rproc *rproc = kproc->rproc;
u32 msg = (u32)(uintptr_t)(data);
dev_dbg(dev, "mbox msg: 0x%x\n", msg);
switch (msg) {
case RP_MBOX_CRASH:
/*
* remoteproc detected an exception, but error recovery is not
* supported. So, just log this for now
*/
dev_err(dev, "K3 rproc %s crashed\n", rproc->name);
break;
case RP_MBOX_ECHO_REPLY:
dev_info(dev, "received echo reply from %s\n", rproc->name);
break;
default:
/* silently handle all other valid messages */
if (msg >= RP_MBOX_READY && msg < RP_MBOX_END_MSG)
return;
if (msg > rproc->max_notifyid) {
dev_dbg(dev, "dropping unknown message 0x%x", msg);
return;
}
/* msg contains the index of the triggered vring */
if (rproc_vq_interrupt(rproc, msg) == IRQ_NONE)
dev_dbg(dev, "no message was found in vqid %d\n", msg);
}
}
EXPORT_SYMBOL_GPL(k3_rproc_mbox_callback);
/*
* Kick the remote processor to notify about pending unprocessed messages.
* The vqid usage is not used and is inconsequential, as the kick is performed
* through a simulated GPIO (a bit in an IPC interrupt-triggering register),
* the remote processor is expected to process both its Tx and Rx virtqueues.
*/
void k3_rproc_kick(struct rproc *rproc, int vqid)
{
struct k3_rproc *kproc = rproc->priv;
struct device *dev = kproc->dev;
u32 msg = (u32)vqid;
int ret;
/*
* Send the index of the triggered virtqueue in the mailbox payload.
* NOTE: msg is cast to uintptr_t to prevent compiler warnings when
* void* is 64bit. It is safely cast back to u32 in the mailbox driver.
*/
ret = mbox_send_message(kproc->mbox, (void *)(uintptr_t)msg);
if (ret < 0)
dev_err(dev, "failed to send mailbox message, status = %d\n",
ret);
}
EXPORT_SYMBOL_GPL(k3_rproc_kick);
/* Put the remote processor into reset */
int k3_rproc_reset(struct k3_rproc *kproc)
{
struct device *dev = kproc->dev;
int ret;
if (kproc->data->uses_lreset) {
ret = reset_control_assert(kproc->reset);
if (ret)
dev_err(dev, "local-reset assert failed (%pe)\n", ERR_PTR(ret));
} else {
ret = kproc->ti_sci->ops.dev_ops.put_device(kproc->ti_sci,
kproc->ti_sci_id);
if (ret)
dev_err(dev, "module-reset assert failed (%pe)\n", ERR_PTR(ret));
}
return ret;
}
EXPORT_SYMBOL_GPL(k3_rproc_reset);
/* Release the remote processor from reset */
int k3_rproc_release(struct k3_rproc *kproc)
{
struct device *dev = kproc->dev;
int ret;
if (kproc->data->uses_lreset) {
ret = reset_control_deassert(kproc->reset);
if (ret) {
dev_err(dev, "local-reset deassert failed, (%pe)\n", ERR_PTR(ret));
if (kproc->ti_sci->ops.dev_ops.put_device(kproc->ti_sci,
kproc->ti_sci_id))
dev_warn(dev, "module-reset assert back failed\n");
}
} else {
ret = kproc->ti_sci->ops.dev_ops.get_device(kproc->ti_sci,
kproc->ti_sci_id);
if (ret)
dev_err(dev, "module-reset deassert failed (%pe)\n", ERR_PTR(ret));
}
return ret;
}
EXPORT_SYMBOL_GPL(k3_rproc_release);
int k3_rproc_request_mbox(struct rproc *rproc)
{
struct k3_rproc *kproc = rproc->priv;
struct mbox_client *client = &kproc->client;
struct device *dev = kproc->dev;
int ret;
client->dev = dev;
client->tx_done = NULL;
client->rx_callback = k3_rproc_mbox_callback;
client->tx_block = false;
client->knows_txdone = false;
kproc->mbox = mbox_request_channel(client, 0);
if (IS_ERR(kproc->mbox))
return dev_err_probe(dev, PTR_ERR(kproc->mbox),
"mbox_request_channel failed\n");
/*
* Ping the remote processor, this is only for sanity-sake for now;
* there is no functional effect whatsoever.
*
* Note that the reply will _not_ arrive immediately: this message
* will wait in the mailbox fifo until the remote processor is booted.
*/
ret = mbox_send_message(kproc->mbox, (void *)RP_MBOX_ECHO_REQUEST);
if (ret < 0) {
dev_err(dev, "mbox_send_message failed (%pe)\n", ERR_PTR(ret));
mbox_free_channel(kproc->mbox);
return ret;
}
return 0;
}
EXPORT_SYMBOL_GPL(k3_rproc_request_mbox);
/*
* The K3 DSP and M4 cores have a local reset that affects only the CPU, and a
* generic module reset that powers on the device and allows the internal
* memories to be accessed while the local reset is asserted. This function is
* used to release the global reset on remote cores to allow loading into the
* internal RAMs. The .prepare() ops is invoked by remoteproc core before any
* firmware loading, and is followed by the .start() ops after loading to
* actually let the remote cores to run.
*/
int k3_rproc_prepare(struct rproc *rproc)
{
struct k3_rproc *kproc = rproc->priv;
struct device *dev = kproc->dev;
int ret;
/* If the core is running already no need to deassert the module reset */
if (rproc->state == RPROC_DETACHED)
return 0;
/*
* Ensure the local reset is asserted so the core doesn't
* execute bogus code when the module reset is released.
*/
if (kproc->data->uses_lreset) {
ret = k3_rproc_reset(kproc);
if (ret)
return ret;
ret = reset_control_status(kproc->reset);
if (ret <= 0) {
dev_err(dev, "local reset still not asserted\n");
return ret;
}
}
ret = kproc->ti_sci->ops.dev_ops.get_device(kproc->ti_sci,
kproc->ti_sci_id);
if (ret) {
dev_err(dev, "could not deassert module-reset for internal RAM loading\n");
return ret;
}
return 0;
}
EXPORT_SYMBOL_GPL(k3_rproc_prepare);
/*
* This function implements the .unprepare() ops and performs the complimentary
* operations to that of the .prepare() ops. The function is used to assert the
* global reset on applicable K3 DSP and M4 cores. This completes the second
* portion of powering down the remote core. The cores themselves are only
* halted in the .stop() callback through the local reset, and the .unprepare()
* ops is invoked by the remoteproc core after the remoteproc is stopped to
* balance the global reset.
*/
int k3_rproc_unprepare(struct rproc *rproc)
{
struct k3_rproc *kproc = rproc->priv;
struct device *dev = kproc->dev;
int ret;
/* If the core is going to be detached do not assert the module reset */
if (rproc->state == RPROC_DETACHED)
return 0;
ret = kproc->ti_sci->ops.dev_ops.put_device(kproc->ti_sci,
kproc->ti_sci_id);
if (ret) {
dev_err(dev, "module-reset assert failed\n");
return ret;
}
return 0;
}
EXPORT_SYMBOL_GPL(k3_rproc_unprepare);
/*
* Power up the remote processor.
*
* This function will be invoked only after the firmware for this rproc
* was loaded, parsed successfully, and all of its resource requirements
* were met. This callback is invoked only in remoteproc mode.
*/
int k3_rproc_start(struct rproc *rproc)
{
struct k3_rproc *kproc = rproc->priv;
return k3_rproc_release(kproc);
}
EXPORT_SYMBOL_GPL(k3_rproc_start);
/*
* Stop the remote processor.
*
* This function puts the remote processor into reset, and finishes processing
* of any pending messages. This callback is invoked only in remoteproc mode.
*/
int k3_rproc_stop(struct rproc *rproc)
{
struct k3_rproc *kproc = rproc->priv;
return k3_rproc_reset(kproc);
}
EXPORT_SYMBOL_GPL(k3_rproc_stop);
/*
* Attach to a running remote processor (IPC-only mode)
*
* The rproc attach callback is a NOP. The remote processor is already booted,
* and all required resources have been acquired during probe routine, so there
* is no need to issue any TI-SCI commands to boot the remote cores in IPC-only
* mode. This callback is invoked only in IPC-only mode and exists because
* rproc_validate() checks for its existence.
*/
int k3_rproc_attach(struct rproc *rproc) { return 0; }
EXPORT_SYMBOL_GPL(k3_rproc_attach);
/*
* Detach from a running remote processor (IPC-only mode)
*
* The rproc detach callback is a NOP. The remote processor is not stopped and
* will be left in booted state in IPC-only mode. This callback is invoked only
* in IPC-only mode and exists for sanity sake
*/
int k3_rproc_detach(struct rproc *rproc) { return 0; }
EXPORT_SYMBOL_GPL(k3_rproc_detach);
/*
* This function implements the .get_loaded_rsc_table() callback and is used
* to provide the resource table for a booted remote processor in IPC-only
* mode. The remote processor firmwares follow a design-by-contract approach
* and are expected to have the resource table at the base of the DDR region
* reserved for firmware usage. This provides flexibility for the remote
* processor to be booted by different bootloaders that may or may not have the
* ability to publish the resource table address and size through a DT
* property.
*/
struct resource_table *k3_get_loaded_rsc_table(struct rproc *rproc,
size_t *rsc_table_sz)
{
struct k3_rproc *kproc = rproc->priv;
struct device *dev = kproc->dev;
if (!kproc->rmem[0].cpu_addr) {
dev_err(dev, "memory-region #1 does not exist, loaded rsc table can't be found");
return ERR_PTR(-ENOMEM);
}
/*
* NOTE: The resource table size is currently hard-coded to a maximum
* of 256 bytes. The most common resource table usage for K3 firmwares
* is to only have the vdev resource entry and an optional trace entry.
* The exact size could be computed based on resource table address, but
* the hard-coded value suffices to support the IPC-only mode.
*/
*rsc_table_sz = 256;
return (__force struct resource_table *)kproc->rmem[0].cpu_addr;
}
EXPORT_SYMBOL_GPL(k3_get_loaded_rsc_table);
/*
* Custom function to translate a remote processor device address (internal
* RAMs only) to a kernel virtual address. The remote processors can access
* their RAMs at either an internal address visible only from a remote
* processor, or at the SoC-level bus address. Both these addresses need to be
* looked through for translation. The translated addresses can be used either
* by the remoteproc core for loading (when using kernel remoteproc loader), or
* by any rpmsg bus drivers.
*/
void *k3_rproc_da_to_va(struct rproc *rproc, u64 da, size_t len, bool *is_iomem)
{
struct k3_rproc *kproc = rproc->priv;
void __iomem *va = NULL;
phys_addr_t bus_addr;
u32 dev_addr, offset;
size_t size;
int i;
if (len == 0)
return NULL;
for (i = 0; i < kproc->num_mems; i++) {
bus_addr = kproc->mem[i].bus_addr;
dev_addr = kproc->mem[i].dev_addr;
size = kproc->mem[i].size;
/* handle rproc-view addresses */
if (da >= dev_addr && ((da + len) <= (dev_addr + size))) {
offset = da - dev_addr;
va = kproc->mem[i].cpu_addr + offset;
return (__force void *)va;
}
/* handle SoC-view addresses */
if (da >= bus_addr && (da + len) <= (bus_addr + size)) {
offset = da - bus_addr;
va = kproc->mem[i].cpu_addr + offset;
return (__force void *)va;
}
}
/* handle static DDR reserved memory regions */
for (i = 0; i < kproc->num_rmems; i++) {
dev_addr = kproc->rmem[i].dev_addr;
size = kproc->rmem[i].size;
if (da >= dev_addr && ((da + len) <= (dev_addr + size))) {
offset = da - dev_addr;
va = kproc->rmem[i].cpu_addr + offset;
return (__force void *)va;
}
}
return NULL;
}
EXPORT_SYMBOL_GPL(k3_rproc_da_to_va);
int k3_rproc_of_get_memories(struct platform_device *pdev,
struct k3_rproc *kproc)
{
const struct k3_rproc_dev_data *data = kproc->data;
struct device *dev = &pdev->dev;
struct resource *res;
int num_mems = 0;
int i;
num_mems = data->num_mems;
kproc->mem = devm_kcalloc(kproc->dev, num_mems,
sizeof(*kproc->mem), GFP_KERNEL);
if (!kproc->mem)
return -ENOMEM;
for (i = 0; i < num_mems; i++) {
res = platform_get_resource_byname(pdev, IORESOURCE_MEM,
data->mems[i].name);
if (!res) {
dev_err(dev, "found no memory resource for %s\n",
data->mems[i].name);
return -EINVAL;
}
if (!devm_request_mem_region(dev, res->start,
resource_size(res),
dev_name(dev))) {
dev_err(dev, "could not request %s region for resource\n",
data->mems[i].name);
return -EBUSY;
}
kproc->mem[i].cpu_addr = devm_ioremap_wc(dev, res->start,
resource_size(res));
if (!kproc->mem[i].cpu_addr) {
dev_err(dev, "failed to map %s memory\n",
data->mems[i].name);
return -ENOMEM;
}
kproc->mem[i].bus_addr = res->start;
kproc->mem[i].dev_addr = data->mems[i].dev_addr;
kproc->mem[i].size = resource_size(res);
dev_dbg(dev, "memory %8s: bus addr %pa size 0x%zx va %pK da 0x%x\n",
data->mems[i].name, &kproc->mem[i].bus_addr,
kproc->mem[i].size, kproc->mem[i].cpu_addr,
kproc->mem[i].dev_addr);
}
kproc->num_mems = num_mems;
return 0;
}
EXPORT_SYMBOL_GPL(k3_rproc_of_get_memories);
void k3_mem_release(void *data)
{
struct device *dev = data;
of_reserved_mem_device_release(dev);
}
EXPORT_SYMBOL_GPL(k3_mem_release);
int k3_reserved_mem_init(struct k3_rproc *kproc)
{
struct device *dev = kproc->dev;
struct device_node *np = dev->of_node;
struct device_node *rmem_np;
struct reserved_mem *rmem;
int num_rmems;
int ret, i;
num_rmems = of_property_count_elems_of_size(np, "memory-region",
sizeof(phandle));
if (num_rmems < 0) {
dev_err(dev, "device does not reserved memory regions (%d)\n",
num_rmems);
return -EINVAL;
}
if (num_rmems < 2) {
dev_err(dev, "device needs at least two memory regions to be defined, num = %d\n",
num_rmems);
return -EINVAL;
}
/* use reserved memory region 0 for vring DMA allocations */
ret = of_reserved_mem_device_init_by_idx(dev, np, 0);
if (ret) {
dev_err(dev, "device cannot initialize DMA pool (%d)\n", ret);
return ret;
}
ret = devm_add_action_or_reset(dev, k3_mem_release, dev);
if (ret)
return ret;
num_rmems--;
kproc->rmem = devm_kcalloc(dev, num_rmems, sizeof(*kproc->rmem), GFP_KERNEL);
if (!kproc->rmem)
return -ENOMEM;
/* use remaining reserved memory regions for static carveouts */
for (i = 0; i < num_rmems; i++) {
rmem_np = of_parse_phandle(np, "memory-region", i + 1);
if (!rmem_np)
return -EINVAL;
rmem = of_reserved_mem_lookup(rmem_np);
of_node_put(rmem_np);
if (!rmem)
return -EINVAL;
kproc->rmem[i].bus_addr = rmem->base;
/* 64-bit address regions currently not supported */
kproc->rmem[i].dev_addr = (u32)rmem->base;
kproc->rmem[i].size = rmem->size;
kproc->rmem[i].cpu_addr = devm_ioremap_wc(dev, rmem->base, rmem->size);
if (!kproc->rmem[i].cpu_addr) {
dev_err(dev, "failed to map reserved memory#%d at %pa of size %pa\n",
i + 1, &rmem->base, &rmem->size);
return -ENOMEM;
}
dev_dbg(dev, "reserved memory%d: bus addr %pa size 0x%zx va %pK da 0x%x\n",
i + 1, &kproc->rmem[i].bus_addr,
kproc->rmem[i].size, kproc->rmem[i].cpu_addr,
kproc->rmem[i].dev_addr);
}
kproc->num_rmems = num_rmems;
return 0;
}
EXPORT_SYMBOL_GPL(k3_reserved_mem_init);
void k3_release_tsp(void *data)
{
struct ti_sci_proc *tsp = data;
ti_sci_proc_release(tsp);
}
EXPORT_SYMBOL_GPL(k3_release_tsp);
MODULE_LICENSE("GPL");
MODULE_DESCRIPTION("TI K3 common Remoteproc code");
+118
View File
@@ -0,0 +1,118 @@
/* SPDX-License-Identifier: GPL-2.0-only */
/*
* TI K3 Remote Processor(s) driver common code
*
* Refactored out of ti_k3_r5_remoteproc.c, ti_k3_dsp_remoteproc.c and
* ti_k3_m4_remoteproc.c.
*
* ti_k3_r5_remoteproc.c:
* Copyright (C) 2017-2022 Texas Instruments Incorporated - https://www.ti.com/
* Suman Anna <s-anna@ti.com>
*
* ti_k3_dsp_remoteproc.c:
* Copyright (C) 2018-2022 Texas Instruments Incorporated - https://www.ti.com/
* Suman Anna <s-anna@ti.com>
*
* ti_k3_m4_remoteproc.c:
* Copyright (C) 2021-2024 Texas Instruments Incorporated - https://www.ti.com/
* Hari Nagalla <hnagalla@ti.com>
*/
#ifndef REMOTEPROC_TI_K3_COMMON_H
#define REMOTEPROC_TI_K3_COMMON_H
#define KEYSTONE_RPROC_LOCAL_ADDRESS_MASK (SZ_16M - 1)
/**
* struct k3_rproc_mem - internal memory structure
* @cpu_addr: MPU virtual address of the memory region
* @bus_addr: Bus address used to access the memory region
* @dev_addr: Device address of the memory region from remote processor view
* @size: Size of the memory region
*/
struct k3_rproc_mem {
void __iomem *cpu_addr;
phys_addr_t bus_addr;
u32 dev_addr;
size_t size;
};
/**
* struct k3_rproc_mem_data - memory definitions for a remote processor
* @name: name for this memory entry
* @dev_addr: device address for the memory entry
*/
struct k3_rproc_mem_data {
const char *name;
const u32 dev_addr;
};
/**
* struct k3_rproc_dev_data - device data structure for a remote processor
* @mems: pointer to memory definitions for a remote processor
* @num_mems: number of memory regions in @mems
* @boot_align_addr: boot vector address alignment granularity
* @uses_lreset: flag to denote the need for local reset management
*/
struct k3_rproc_dev_data {
const struct k3_rproc_mem_data *mems;
u32 num_mems;
u32 boot_align_addr;
bool uses_lreset;
};
/**
* struct k3_rproc - k3 remote processor driver structure
* @dev: cached device pointer
* @rproc: remoteproc device handle
* @mem: internal memory regions data
* @num_mems: number of internal memory regions
* @rmem: reserved memory regions data
* @num_rmems: number of reserved memory regions
* @reset: reset control handle
* @data: pointer to DSP-specific device data
* @tsp: TI-SCI processor control handle
* @ti_sci: TI-SCI handle
* @ti_sci_id: TI-SCI device identifier
* @mbox: mailbox channel handle
* @client: mailbox client to request the mailbox channel
* @priv: void pointer to carry any private data
*/
struct k3_rproc {
struct device *dev;
struct rproc *rproc;
struct k3_rproc_mem *mem;
int num_mems;
struct k3_rproc_mem *rmem;
int num_rmems;
struct reset_control *reset;
const struct k3_rproc_dev_data *data;
struct ti_sci_proc *tsp;
const struct ti_sci_handle *ti_sci;
u32 ti_sci_id;
struct mbox_chan *mbox;
struct mbox_client client;
void *priv;
};
void k3_rproc_mbox_callback(struct mbox_client *client, void *data);
void k3_rproc_kick(struct rproc *rproc, int vqid);
int k3_rproc_reset(struct k3_rproc *kproc);
int k3_rproc_release(struct k3_rproc *kproc);
int k3_rproc_request_mbox(struct rproc *rproc);
int k3_rproc_prepare(struct rproc *rproc);
int k3_rproc_unprepare(struct rproc *rproc);
int k3_rproc_start(struct rproc *rproc);
int k3_rproc_stop(struct rproc *rproc);
int k3_rproc_attach(struct rproc *rproc);
int k3_rproc_detach(struct rproc *rproc);
struct resource_table *k3_get_loaded_rsc_table(struct rproc *rproc,
size_t *rsc_table_sz);
void *k3_rproc_da_to_va(struct rproc *rproc, u64 da, size_t len,
bool *is_iomem);
int k3_rproc_of_get_memories(struct platform_device *pdev,
struct k3_rproc *kproc);
void k3_mem_release(void *data);
int k3_reserved_mem_init(struct k3_rproc *kproc);
void k3_release_tsp(void *data);
#endif /* REMOTEPROC_TI_K3_COMMON_H */
+26 -590
View File
@@ -20,291 +20,7 @@
#include "omap_remoteproc.h"
#include "remoteproc_internal.h"
#include "ti_sci_proc.h"
#define KEYSTONE_RPROC_LOCAL_ADDRESS_MASK (SZ_16M - 1)
/**
* struct k3_dsp_mem - internal memory structure
* @cpu_addr: MPU virtual address of the memory region
* @bus_addr: Bus address used to access the memory region
* @dev_addr: Device address of the memory region from DSP view
* @size: Size of the memory region
*/
struct k3_dsp_mem {
void __iomem *cpu_addr;
phys_addr_t bus_addr;
u32 dev_addr;
size_t size;
};
/**
* struct k3_dsp_mem_data - memory definitions for a DSP
* @name: name for this memory entry
* @dev_addr: device address for the memory entry
*/
struct k3_dsp_mem_data {
const char *name;
const u32 dev_addr;
};
/**
* struct k3_dsp_dev_data - device data structure for a DSP
* @mems: pointer to memory definitions for a DSP
* @num_mems: number of memory regions in @mems
* @boot_align_addr: boot vector address alignment granularity
* @uses_lreset: flag to denote the need for local reset management
*/
struct k3_dsp_dev_data {
const struct k3_dsp_mem_data *mems;
u32 num_mems;
u32 boot_align_addr;
bool uses_lreset;
};
/**
* struct k3_dsp_rproc - k3 DSP remote processor driver structure
* @dev: cached device pointer
* @rproc: remoteproc device handle
* @mem: internal memory regions data
* @num_mems: number of internal memory regions
* @rmem: reserved memory regions data
* @num_rmems: number of reserved memory regions
* @reset: reset control handle
* @data: pointer to DSP-specific device data
* @tsp: TI-SCI processor control handle
* @ti_sci: TI-SCI handle
* @ti_sci_id: TI-SCI device identifier
* @mbox: mailbox channel handle
* @client: mailbox client to request the mailbox channel
*/
struct k3_dsp_rproc {
struct device *dev;
struct rproc *rproc;
struct k3_dsp_mem *mem;
int num_mems;
struct k3_dsp_mem *rmem;
int num_rmems;
struct reset_control *reset;
const struct k3_dsp_dev_data *data;
struct ti_sci_proc *tsp;
const struct ti_sci_handle *ti_sci;
u32 ti_sci_id;
struct mbox_chan *mbox;
struct mbox_client client;
};
/**
* k3_dsp_rproc_mbox_callback() - inbound mailbox message handler
* @client: mailbox client pointer used for requesting the mailbox channel
* @data: mailbox payload
*
* This handler is invoked by the OMAP mailbox driver whenever a mailbox
* message is received. Usually, the mailbox payload simply contains
* the index of the virtqueue that is kicked by the remote processor,
* and we let remoteproc core handle it.
*
* In addition to virtqueue indices, we also have some out-of-band values
* that indicate different events. Those values are deliberately very
* large so they don't coincide with virtqueue indices.
*/
static void k3_dsp_rproc_mbox_callback(struct mbox_client *client, void *data)
{
struct k3_dsp_rproc *kproc = container_of(client, struct k3_dsp_rproc,
client);
struct device *dev = kproc->rproc->dev.parent;
const char *name = kproc->rproc->name;
u32 msg = omap_mbox_message(data);
/* Do not forward messages from a detached core */
if (kproc->rproc->state == RPROC_DETACHED)
return;
dev_dbg(dev, "mbox msg: 0x%x\n", msg);
switch (msg) {
case RP_MBOX_CRASH:
/*
* remoteproc detected an exception, but error recovery is not
* supported. So, just log this for now
*/
dev_err(dev, "K3 DSP rproc %s crashed\n", name);
break;
case RP_MBOX_ECHO_REPLY:
dev_info(dev, "received echo reply from %s\n", name);
break;
default:
/* silently handle all other valid messages */
if (msg >= RP_MBOX_READY && msg < RP_MBOX_END_MSG)
return;
if (msg > kproc->rproc->max_notifyid) {
dev_dbg(dev, "dropping unknown message 0x%x", msg);
return;
}
/* msg contains the index of the triggered vring */
if (rproc_vq_interrupt(kproc->rproc, msg) == IRQ_NONE)
dev_dbg(dev, "no message was found in vqid %d\n", msg);
}
}
/*
* Kick the remote processor to notify about pending unprocessed messages.
* The vqid usage is not used and is inconsequential, as the kick is performed
* through a simulated GPIO (a bit in an IPC interrupt-triggering register),
* the remote processor is expected to process both its Tx and Rx virtqueues.
*/
static void k3_dsp_rproc_kick(struct rproc *rproc, int vqid)
{
struct k3_dsp_rproc *kproc = rproc->priv;
struct device *dev = rproc->dev.parent;
mbox_msg_t msg = (mbox_msg_t)vqid;
int ret;
/* Do not forward messages to a detached core */
if (kproc->rproc->state == RPROC_DETACHED)
return;
/* send the index of the triggered virtqueue in the mailbox payload */
ret = mbox_send_message(kproc->mbox, (void *)msg);
if (ret < 0)
dev_err(dev, "failed to send mailbox message (%pe)\n",
ERR_PTR(ret));
}
/* Put the DSP processor into reset */
static int k3_dsp_rproc_reset(struct k3_dsp_rproc *kproc)
{
struct device *dev = kproc->dev;
int ret;
ret = reset_control_assert(kproc->reset);
if (ret) {
dev_err(dev, "local-reset assert failed (%pe)\n", ERR_PTR(ret));
return ret;
}
if (kproc->data->uses_lreset)
return ret;
ret = kproc->ti_sci->ops.dev_ops.put_device(kproc->ti_sci,
kproc->ti_sci_id);
if (ret) {
dev_err(dev, "module-reset assert failed (%pe)\n", ERR_PTR(ret));
if (reset_control_deassert(kproc->reset))
dev_warn(dev, "local-reset deassert back failed\n");
}
return ret;
}
/* Release the DSP processor from reset */
static int k3_dsp_rproc_release(struct k3_dsp_rproc *kproc)
{
struct device *dev = kproc->dev;
int ret;
if (kproc->data->uses_lreset)
goto lreset;
ret = kproc->ti_sci->ops.dev_ops.get_device(kproc->ti_sci,
kproc->ti_sci_id);
if (ret) {
dev_err(dev, "module-reset deassert failed (%pe)\n", ERR_PTR(ret));
return ret;
}
lreset:
ret = reset_control_deassert(kproc->reset);
if (ret) {
dev_err(dev, "local-reset deassert failed, (%pe)\n", ERR_PTR(ret));
if (kproc->ti_sci->ops.dev_ops.put_device(kproc->ti_sci,
kproc->ti_sci_id))
dev_warn(dev, "module-reset assert back failed\n");
}
return ret;
}
static int k3_dsp_rproc_request_mbox(struct rproc *rproc)
{
struct k3_dsp_rproc *kproc = rproc->priv;
struct mbox_client *client = &kproc->client;
struct device *dev = kproc->dev;
int ret;
client->dev = dev;
client->tx_done = NULL;
client->rx_callback = k3_dsp_rproc_mbox_callback;
client->tx_block = false;
client->knows_txdone = false;
kproc->mbox = mbox_request_channel(client, 0);
if (IS_ERR(kproc->mbox))
return dev_err_probe(dev, PTR_ERR(kproc->mbox),
"mbox_request_channel failed\n");
/*
* Ping the remote processor, this is only for sanity-sake for now;
* there is no functional effect whatsoever.
*
* Note that the reply will _not_ arrive immediately: this message
* will wait in the mailbox fifo until the remote processor is booted.
*/
ret = mbox_send_message(kproc->mbox, (void *)RP_MBOX_ECHO_REQUEST);
if (ret < 0) {
dev_err(dev, "mbox_send_message failed (%pe)\n", ERR_PTR(ret));
mbox_free_channel(kproc->mbox);
return ret;
}
return 0;
}
/*
* The C66x DSP cores have a local reset that affects only the CPU, and a
* generic module reset that powers on the device and allows the DSP internal
* memories to be accessed while the local reset is asserted. This function is
* used to release the global reset on C66x DSPs to allow loading into the DSP
* internal RAMs. The .prepare() ops is invoked by remoteproc core before any
* firmware loading, and is followed by the .start() ops after loading to
* actually let the C66x DSP cores run. This callback is invoked only in
* remoteproc mode.
*/
static int k3_dsp_rproc_prepare(struct rproc *rproc)
{
struct k3_dsp_rproc *kproc = rproc->priv;
struct device *dev = kproc->dev;
int ret;
ret = kproc->ti_sci->ops.dev_ops.get_device(kproc->ti_sci,
kproc->ti_sci_id);
if (ret)
dev_err(dev, "module-reset deassert failed, cannot enable internal RAM loading (%pe)\n",
ERR_PTR(ret));
return ret;
}
/*
* This function implements the .unprepare() ops and performs the complimentary
* operations to that of the .prepare() ops. The function is used to assert the
* global reset on applicable C66x cores. This completes the second portion of
* powering down the C66x DSP cores. The cores themselves are only halted in the
* .stop() callback through the local reset, and the .unprepare() ops is invoked
* by the remoteproc core after the remoteproc is stopped to balance the global
* reset. This callback is invoked only in remoteproc mode.
*/
static int k3_dsp_rproc_unprepare(struct rproc *rproc)
{
struct k3_dsp_rproc *kproc = rproc->priv;
struct device *dev = kproc->dev;
int ret;
ret = kproc->ti_sci->ops.dev_ops.put_device(kproc->ti_sci,
kproc->ti_sci_id);
if (ret)
dev_err(dev, "module-reset assert failed (%pe)\n", ERR_PTR(ret));
return ret;
}
#include "ti_k3_common.h"
/*
* Power up the DSP remote processor.
@@ -315,7 +31,7 @@ static int k3_dsp_rproc_unprepare(struct rproc *rproc)
*/
static int k3_dsp_rproc_start(struct rproc *rproc)
{
struct k3_dsp_rproc *kproc = rproc->priv;
struct k3_rproc *kproc = rproc->priv;
struct device *dev = kproc->dev;
u32 boot_addr;
int ret;
@@ -332,288 +48,30 @@ static int k3_dsp_rproc_start(struct rproc *rproc)
if (ret)
return ret;
ret = k3_dsp_rproc_release(kproc);
/* Call the K3 common start function after doing DSP specific stuff */
ret = k3_rproc_start(rproc);
if (ret)
return ret;
return 0;
}
/*
* Stop the DSP remote processor.
*
* This function puts the DSP processor into reset, and finishes processing
* of any pending messages. This callback is invoked only in remoteproc mode.
*/
static int k3_dsp_rproc_stop(struct rproc *rproc)
{
struct k3_dsp_rproc *kproc = rproc->priv;
k3_dsp_rproc_reset(kproc);
return 0;
}
/*
* Attach to a running DSP remote processor (IPC-only mode)
*
* This rproc attach callback is a NOP. The remote processor is already booted,
* and all required resources have been acquired during probe routine, so there
* is no need to issue any TI-SCI commands to boot the DSP core. This callback
* is invoked only in IPC-only mode and exists because rproc_validate() checks
* for its existence.
*/
static int k3_dsp_rproc_attach(struct rproc *rproc) { return 0; }
/*
* Detach from a running DSP remote processor (IPC-only mode)
*
* This rproc detach callback is a NOP. The DSP core is not stopped and will be
* left to continue to run its booted firmware. This callback is invoked only in
* IPC-only mode and exists for sanity sake.
*/
static int k3_dsp_rproc_detach(struct rproc *rproc) { return 0; }
/*
* This function implements the .get_loaded_rsc_table() callback and is used
* to provide the resource table for a booted DSP in IPC-only mode. The K3 DSP
* firmwares follow a design-by-contract approach and are expected to have the
* resource table at the base of the DDR region reserved for firmware usage.
* This provides flexibility for the remote processor to be booted by different
* bootloaders that may or may not have the ability to publish the resource table
* address and size through a DT property. This callback is invoked only in
* IPC-only mode.
*/
static struct resource_table *k3_dsp_get_loaded_rsc_table(struct rproc *rproc,
size_t *rsc_table_sz)
{
struct k3_dsp_rproc *kproc = rproc->priv;
struct device *dev = kproc->dev;
if (!kproc->rmem[0].cpu_addr) {
dev_err(dev, "memory-region #1 does not exist, loaded rsc table can't be found");
return ERR_PTR(-ENOMEM);
}
/*
* NOTE: The resource table size is currently hard-coded to a maximum
* of 256 bytes. The most common resource table usage for K3 firmwares
* is to only have the vdev resource entry and an optional trace entry.
* The exact size could be computed based on resource table address, but
* the hard-coded value suffices to support the IPC-only mode.
*/
*rsc_table_sz = 256;
return (__force struct resource_table *)kproc->rmem[0].cpu_addr;
}
/*
* Custom function to translate a DSP device address (internal RAMs only) to a
* kernel virtual address. The DSPs can access their RAMs at either an internal
* address visible only from a DSP, or at the SoC-level bus address. Both these
* addresses need to be looked through for translation. The translated addresses
* can be used either by the remoteproc core for loading (when using kernel
* remoteproc loader), or by any rpmsg bus drivers.
*/
static void *k3_dsp_rproc_da_to_va(struct rproc *rproc, u64 da, size_t len, bool *is_iomem)
{
struct k3_dsp_rproc *kproc = rproc->priv;
void __iomem *va = NULL;
phys_addr_t bus_addr;
u32 dev_addr, offset;
size_t size;
int i;
if (len == 0)
return NULL;
for (i = 0; i < kproc->num_mems; i++) {
bus_addr = kproc->mem[i].bus_addr;
dev_addr = kproc->mem[i].dev_addr;
size = kproc->mem[i].size;
if (da < KEYSTONE_RPROC_LOCAL_ADDRESS_MASK) {
/* handle DSP-view addresses */
if (da >= dev_addr &&
((da + len) <= (dev_addr + size))) {
offset = da - dev_addr;
va = kproc->mem[i].cpu_addr + offset;
return (__force void *)va;
}
} else {
/* handle SoC-view addresses */
if (da >= bus_addr &&
(da + len) <= (bus_addr + size)) {
offset = da - bus_addr;
va = kproc->mem[i].cpu_addr + offset;
return (__force void *)va;
}
}
}
/* handle static DDR reserved memory regions */
for (i = 0; i < kproc->num_rmems; i++) {
dev_addr = kproc->rmem[i].dev_addr;
size = kproc->rmem[i].size;
if (da >= dev_addr && ((da + len) <= (dev_addr + size))) {
offset = da - dev_addr;
va = kproc->rmem[i].cpu_addr + offset;
return (__force void *)va;
}
}
return NULL;
}
static const struct rproc_ops k3_dsp_rproc_ops = {
.start = k3_dsp_rproc_start,
.stop = k3_dsp_rproc_stop,
.kick = k3_dsp_rproc_kick,
.da_to_va = k3_dsp_rproc_da_to_va,
.start = k3_dsp_rproc_start,
.stop = k3_rproc_stop,
.attach = k3_rproc_attach,
.detach = k3_rproc_detach,
.kick = k3_rproc_kick,
.da_to_va = k3_rproc_da_to_va,
.get_loaded_rsc_table = k3_get_loaded_rsc_table,
};
static int k3_dsp_rproc_of_get_memories(struct platform_device *pdev,
struct k3_dsp_rproc *kproc)
{
const struct k3_dsp_dev_data *data = kproc->data;
struct device *dev = &pdev->dev;
struct resource *res;
int num_mems = 0;
int i;
num_mems = kproc->data->num_mems;
kproc->mem = devm_kcalloc(kproc->dev, num_mems,
sizeof(*kproc->mem), GFP_KERNEL);
if (!kproc->mem)
return -ENOMEM;
for (i = 0; i < num_mems; i++) {
res = platform_get_resource_byname(pdev, IORESOURCE_MEM,
data->mems[i].name);
if (!res) {
dev_err(dev, "found no memory resource for %s\n",
data->mems[i].name);
return -EINVAL;
}
if (!devm_request_mem_region(dev, res->start,
resource_size(res),
dev_name(dev))) {
dev_err(dev, "could not request %s region for resource\n",
data->mems[i].name);
return -EBUSY;
}
kproc->mem[i].cpu_addr = devm_ioremap_wc(dev, res->start,
resource_size(res));
if (!kproc->mem[i].cpu_addr) {
dev_err(dev, "failed to map %s memory\n",
data->mems[i].name);
return -ENOMEM;
}
kproc->mem[i].bus_addr = res->start;
kproc->mem[i].dev_addr = data->mems[i].dev_addr;
kproc->mem[i].size = resource_size(res);
dev_dbg(dev, "memory %8s: bus addr %pa size 0x%zx va %pK da 0x%x\n",
data->mems[i].name, &kproc->mem[i].bus_addr,
kproc->mem[i].size, kproc->mem[i].cpu_addr,
kproc->mem[i].dev_addr);
}
kproc->num_mems = num_mems;
return 0;
}
static void k3_dsp_mem_release(void *data)
{
struct device *dev = data;
of_reserved_mem_device_release(dev);
}
static int k3_dsp_reserved_mem_init(struct k3_dsp_rproc *kproc)
{
struct device *dev = kproc->dev;
struct device_node *np = dev->of_node;
struct device_node *rmem_np;
struct reserved_mem *rmem;
int num_rmems;
int ret, i;
num_rmems = of_property_count_elems_of_size(np, "memory-region",
sizeof(phandle));
if (num_rmems < 0) {
dev_err(dev, "device does not reserved memory regions (%pe)\n",
ERR_PTR(num_rmems));
return -EINVAL;
}
if (num_rmems < 2) {
dev_err(dev, "device needs at least two memory regions to be defined, num = %d\n",
num_rmems);
return -EINVAL;
}
/* use reserved memory region 0 for vring DMA allocations */
ret = of_reserved_mem_device_init_by_idx(dev, np, 0);
if (ret) {
dev_err(dev, "device cannot initialize DMA pool (%pe)\n",
ERR_PTR(ret));
return ret;
}
ret = devm_add_action_or_reset(dev, k3_dsp_mem_release, dev);
if (ret)
return ret;
num_rmems--;
kproc->rmem = devm_kcalloc(dev, num_rmems, sizeof(*kproc->rmem), GFP_KERNEL);
if (!kproc->rmem)
return -ENOMEM;
/* use remaining reserved memory regions for static carveouts */
for (i = 0; i < num_rmems; i++) {
rmem_np = of_parse_phandle(np, "memory-region", i + 1);
if (!rmem_np)
return -EINVAL;
rmem = of_reserved_mem_lookup(rmem_np);
of_node_put(rmem_np);
if (!rmem)
return -EINVAL;
kproc->rmem[i].bus_addr = rmem->base;
/* 64-bit address regions currently not supported */
kproc->rmem[i].dev_addr = (u32)rmem->base;
kproc->rmem[i].size = rmem->size;
kproc->rmem[i].cpu_addr = devm_ioremap_wc(dev, rmem->base, rmem->size);
if (!kproc->rmem[i].cpu_addr) {
dev_err(dev, "failed to map reserved memory#%d at %pa of size %pa\n",
i + 1, &rmem->base, &rmem->size);
return -ENOMEM;
}
dev_dbg(dev, "reserved memory%d: bus addr %pa size 0x%zx va %pK da 0x%x\n",
i + 1, &kproc->rmem[i].bus_addr,
kproc->rmem[i].size, kproc->rmem[i].cpu_addr,
kproc->rmem[i].dev_addr);
}
kproc->num_rmems = num_rmems;
return 0;
}
static void k3_dsp_release_tsp(void *data)
{
struct ti_sci_proc *tsp = data;
ti_sci_proc_release(tsp);
}
static int k3_dsp_rproc_probe(struct platform_device *pdev)
{
struct device *dev = &pdev->dev;
struct device_node *np = dev->of_node;
const struct k3_dsp_dev_data *data;
struct k3_dsp_rproc *kproc;
const struct k3_rproc_dev_data *data;
struct k3_rproc *kproc;
struct rproc *rproc;
const char *fw_name;
bool p_state = false;
@@ -635,15 +93,15 @@ static int k3_dsp_rproc_probe(struct platform_device *pdev)
rproc->has_iommu = false;
rproc->recovery_disabled = true;
if (data->uses_lreset) {
rproc->ops->prepare = k3_dsp_rproc_prepare;
rproc->ops->unprepare = k3_dsp_rproc_unprepare;
rproc->ops->prepare = k3_rproc_prepare;
rproc->ops->unprepare = k3_rproc_unprepare;
}
kproc = rproc->priv;
kproc->rproc = rproc;
kproc->dev = dev;
kproc->data = data;
ret = k3_dsp_rproc_request_mbox(rproc);
ret = k3_rproc_request_mbox(rproc);
if (ret)
return ret;
@@ -671,15 +129,15 @@ static int k3_dsp_rproc_probe(struct platform_device *pdev)
dev_err_probe(dev, ret, "ti_sci_proc_request failed\n");
return ret;
}
ret = devm_add_action_or_reset(dev, k3_dsp_release_tsp, kproc->tsp);
ret = devm_add_action_or_reset(dev, k3_release_tsp, kproc->tsp);
if (ret)
return ret;
ret = k3_dsp_rproc_of_get_memories(pdev, kproc);
ret = k3_rproc_of_get_memories(pdev, kproc);
if (ret)
return ret;
ret = k3_dsp_reserved_mem_init(kproc);
ret = k3_reserved_mem_init(kproc);
if (ret)
return dev_err_probe(dev, ret, "reserved memory init failed\n");
@@ -692,30 +150,8 @@ static int k3_dsp_rproc_probe(struct platform_device *pdev)
if (p_state) {
dev_info(dev, "configured DSP for IPC-only mode\n");
rproc->state = RPROC_DETACHED;
/* override rproc ops with only required IPC-only mode ops */
rproc->ops->prepare = NULL;
rproc->ops->unprepare = NULL;
rproc->ops->start = NULL;
rproc->ops->stop = NULL;
rproc->ops->attach = k3_dsp_rproc_attach;
rproc->ops->detach = k3_dsp_rproc_detach;
rproc->ops->get_loaded_rsc_table = k3_dsp_get_loaded_rsc_table;
} else {
dev_info(dev, "configured DSP for remoteproc mode\n");
/*
* ensure the DSP local reset is asserted to ensure the DSP
* doesn't execute bogus code in .prepare() when the module
* reset is released.
*/
if (data->uses_lreset) {
ret = reset_control_status(kproc->reset);
if (ret < 0) {
return dev_err_probe(dev, ret, "failed to get reset status\n");
} else if (ret == 0) {
dev_warn(dev, "local reset is deasserted for device\n");
k3_dsp_rproc_reset(kproc);
}
}
}
ret = devm_rproc_add(dev, rproc);
@@ -729,7 +165,7 @@ static int k3_dsp_rproc_probe(struct platform_device *pdev)
static void k3_dsp_rproc_remove(struct platform_device *pdev)
{
struct k3_dsp_rproc *kproc = platform_get_drvdata(pdev);
struct k3_rproc *kproc = platform_get_drvdata(pdev);
struct rproc *rproc = kproc->rproc;
struct device *dev = &pdev->dev;
int ret;
@@ -743,37 +179,37 @@ static void k3_dsp_rproc_remove(struct platform_device *pdev)
mbox_free_channel(kproc->mbox);
}
static const struct k3_dsp_mem_data c66_mems[] = {
static const struct k3_rproc_mem_data c66_mems[] = {
{ .name = "l2sram", .dev_addr = 0x800000 },
{ .name = "l1pram", .dev_addr = 0xe00000 },
{ .name = "l1dram", .dev_addr = 0xf00000 },
};
/* C71x cores only have a L1P Cache, there are no L1P SRAMs */
static const struct k3_dsp_mem_data c71_mems[] = {
static const struct k3_rproc_mem_data c71_mems[] = {
{ .name = "l2sram", .dev_addr = 0x800000 },
{ .name = "l1dram", .dev_addr = 0xe00000 },
};
static const struct k3_dsp_mem_data c7xv_mems[] = {
static const struct k3_rproc_mem_data c7xv_mems[] = {
{ .name = "l2sram", .dev_addr = 0x800000 },
};
static const struct k3_dsp_dev_data c66_data = {
static const struct k3_rproc_dev_data c66_data = {
.mems = c66_mems,
.num_mems = ARRAY_SIZE(c66_mems),
.boot_align_addr = SZ_1K,
.uses_lreset = true,
};
static const struct k3_dsp_dev_data c71_data = {
static const struct k3_rproc_dev_data c71_data = {
.mems = c71_mems,
.num_mems = ARRAY_SIZE(c71_mems),
.boot_align_addr = SZ_2M,
.uses_lreset = false,
};
static const struct k3_dsp_dev_data c7xv_data = {
static const struct k3_rproc_dev_data c7xv_data = {
.mems = c7xv_mems,
.num_mems = ARRAY_SIZE(c7xv_mems),
.boot_align_addr = SZ_2M,
+37 -546
View File
@@ -19,552 +19,35 @@
#include "omap_remoteproc.h"
#include "remoteproc_internal.h"
#include "ti_sci_proc.h"
#define K3_M4_IRAM_DEV_ADDR 0x00000
#define K3_M4_DRAM_DEV_ADDR 0x30000
/**
* struct k3_m4_rproc_mem - internal memory structure
* @cpu_addr: MPU virtual address of the memory region
* @bus_addr: Bus address used to access the memory region
* @dev_addr: Device address of the memory region from remote processor view
* @size: Size of the memory region
*/
struct k3_m4_rproc_mem {
void __iomem *cpu_addr;
phys_addr_t bus_addr;
u32 dev_addr;
size_t size;
};
/**
* struct k3_m4_rproc_mem_data - memory definitions for a remote processor
* @name: name for this memory entry
* @dev_addr: device address for the memory entry
*/
struct k3_m4_rproc_mem_data {
const char *name;
const u32 dev_addr;
};
/**
* struct k3_m4_rproc - k3 remote processor driver structure
* @dev: cached device pointer
* @mem: internal memory regions data
* @num_mems: number of internal memory regions
* @rmem: reserved memory regions data
* @num_rmems: number of reserved memory regions
* @reset: reset control handle
* @tsp: TI-SCI processor control handle
* @ti_sci: TI-SCI handle
* @ti_sci_id: TI-SCI device identifier
* @mbox: mailbox channel handle
* @client: mailbox client to request the mailbox channel
*/
struct k3_m4_rproc {
struct device *dev;
struct k3_m4_rproc_mem *mem;
int num_mems;
struct k3_m4_rproc_mem *rmem;
int num_rmems;
struct reset_control *reset;
struct ti_sci_proc *tsp;
const struct ti_sci_handle *ti_sci;
u32 ti_sci_id;
struct mbox_chan *mbox;
struct mbox_client client;
};
/**
* k3_m4_rproc_mbox_callback() - inbound mailbox message handler
* @client: mailbox client pointer used for requesting the mailbox channel
* @data: mailbox payload
*
* This handler is invoked by the K3 mailbox driver whenever a mailbox
* message is received. Usually, the mailbox payload simply contains
* the index of the virtqueue that is kicked by the remote processor,
* and we let remoteproc core handle it.
*
* In addition to virtqueue indices, we also have some out-of-band values
* that indicate different events. Those values are deliberately very
* large so they don't coincide with virtqueue indices.
*/
static void k3_m4_rproc_mbox_callback(struct mbox_client *client, void *data)
{
struct device *dev = client->dev;
struct rproc *rproc = dev_get_drvdata(dev);
u32 msg = (u32)(uintptr_t)(data);
dev_dbg(dev, "mbox msg: 0x%x\n", msg);
switch (msg) {
case RP_MBOX_CRASH:
/*
* remoteproc detected an exception, but error recovery is not
* supported. So, just log this for now
*/
dev_err(dev, "K3 rproc %s crashed\n", rproc->name);
break;
case RP_MBOX_ECHO_REPLY:
dev_info(dev, "received echo reply from %s\n", rproc->name);
break;
default:
/* silently handle all other valid messages */
if (msg >= RP_MBOX_READY && msg < RP_MBOX_END_MSG)
return;
if (msg > rproc->max_notifyid) {
dev_dbg(dev, "dropping unknown message 0x%x", msg);
return;
}
/* msg contains the index of the triggered vring */
if (rproc_vq_interrupt(rproc, msg) == IRQ_NONE)
dev_dbg(dev, "no message was found in vqid %d\n", msg);
}
}
/*
* Kick the remote processor to notify about pending unprocessed messages.
* The vqid usage is not used and is inconsequential, as the kick is performed
* through a simulated GPIO (a bit in an IPC interrupt-triggering register),
* the remote processor is expected to process both its Tx and Rx virtqueues.
*/
static void k3_m4_rproc_kick(struct rproc *rproc, int vqid)
{
struct k3_m4_rproc *kproc = rproc->priv;
struct device *dev = kproc->dev;
u32 msg = (u32)vqid;
int ret;
/*
* Send the index of the triggered virtqueue in the mailbox payload.
* NOTE: msg is cast to uintptr_t to prevent compiler warnings when
* void* is 64bit. It is safely cast back to u32 in the mailbox driver.
*/
ret = mbox_send_message(kproc->mbox, (void *)(uintptr_t)msg);
if (ret < 0)
dev_err(dev, "failed to send mailbox message, status = %d\n",
ret);
}
static int k3_m4_rproc_ping_mbox(struct k3_m4_rproc *kproc)
{
struct device *dev = kproc->dev;
int ret;
/*
* Ping the remote processor, this is only for sanity-sake for now;
* there is no functional effect whatsoever.
*
* Note that the reply will _not_ arrive immediately: this message
* will wait in the mailbox fifo until the remote processor is booted.
*/
ret = mbox_send_message(kproc->mbox, (void *)RP_MBOX_ECHO_REQUEST);
if (ret < 0) {
dev_err(dev, "mbox_send_message failed: %d\n", ret);
return ret;
}
return 0;
}
/*
* The M4 cores have a local reset that affects only the CPU, and a
* generic module reset that powers on the device and allows the internal
* memories to be accessed while the local reset is asserted. This function is
* used to release the global reset on remote cores to allow loading into the
* internal RAMs. The .prepare() ops is invoked by remoteproc core before any
* firmware loading, and is followed by the .start() ops after loading to
* actually let the remote cores to run.
*/
static int k3_m4_rproc_prepare(struct rproc *rproc)
{
struct k3_m4_rproc *kproc = rproc->priv;
struct device *dev = kproc->dev;
int ret;
/* If the core is running already no need to deassert the module reset */
if (rproc->state == RPROC_DETACHED)
return 0;
/*
* Ensure the local reset is asserted so the core doesn't
* execute bogus code when the module reset is released.
*/
ret = reset_control_assert(kproc->reset);
if (ret) {
dev_err(dev, "could not assert local reset\n");
return ret;
}
ret = reset_control_status(kproc->reset);
if (ret <= 0) {
dev_err(dev, "local reset still not asserted\n");
return ret;
}
ret = kproc->ti_sci->ops.dev_ops.get_device(kproc->ti_sci,
kproc->ti_sci_id);
if (ret) {
dev_err(dev, "could not deassert module-reset for internal RAM loading\n");
return ret;
}
return 0;
}
/*
* This function implements the .unprepare() ops and performs the complimentary
* operations to that of the .prepare() ops. The function is used to assert the
* global reset on applicable cores. This completes the second portion of
* powering down the remote core. The cores themselves are only halted in the
* .stop() callback through the local reset, and the .unprepare() ops is invoked
* by the remoteproc core after the remoteproc is stopped to balance the global
* reset.
*/
static int k3_m4_rproc_unprepare(struct rproc *rproc)
{
struct k3_m4_rproc *kproc = rproc->priv;
struct device *dev = kproc->dev;
int ret;
/* If the core is going to be detached do not assert the module reset */
if (rproc->state == RPROC_ATTACHED)
return 0;
ret = kproc->ti_sci->ops.dev_ops.put_device(kproc->ti_sci,
kproc->ti_sci_id);
if (ret) {
dev_err(dev, "module-reset assert failed\n");
return ret;
}
return 0;
}
/*
* This function implements the .get_loaded_rsc_table() callback and is used
* to provide the resource table for a booted remote processor in IPC-only
* mode. The remote processor firmwares follow a design-by-contract approach
* and are expected to have the resource table at the base of the DDR region
* reserved for firmware usage. This provides flexibility for the remote
* processor to be booted by different bootloaders that may or may not have the
* ability to publish the resource table address and size through a DT
* property.
*/
static struct resource_table *k3_m4_get_loaded_rsc_table(struct rproc *rproc,
size_t *rsc_table_sz)
{
struct k3_m4_rproc *kproc = rproc->priv;
struct device *dev = kproc->dev;
if (!kproc->rmem[0].cpu_addr) {
dev_err(dev, "memory-region #1 does not exist, loaded rsc table can't be found");
return ERR_PTR(-ENOMEM);
}
/*
* NOTE: The resource table size is currently hard-coded to a maximum
* of 256 bytes. The most common resource table usage for K3 firmwares
* is to only have the vdev resource entry and an optional trace entry.
* The exact size could be computed based on resource table address, but
* the hard-coded value suffices to support the IPC-only mode.
*/
*rsc_table_sz = 256;
return (__force struct resource_table *)kproc->rmem[0].cpu_addr;
}
/*
* Custom function to translate a remote processor device address (internal
* RAMs only) to a kernel virtual address. The remote processors can access
* their RAMs at either an internal address visible only from a remote
* processor, or at the SoC-level bus address. Both these addresses need to be
* looked through for translation. The translated addresses can be used either
* by the remoteproc core for loading (when using kernel remoteproc loader), or
* by any rpmsg bus drivers.
*/
static void *k3_m4_rproc_da_to_va(struct rproc *rproc, u64 da, size_t len, bool *is_iomem)
{
struct k3_m4_rproc *kproc = rproc->priv;
void __iomem *va = NULL;
phys_addr_t bus_addr;
u32 dev_addr, offset;
size_t size;
int i;
if (len == 0)
return NULL;
for (i = 0; i < kproc->num_mems; i++) {
bus_addr = kproc->mem[i].bus_addr;
dev_addr = kproc->mem[i].dev_addr;
size = kproc->mem[i].size;
/* handle M4-view addresses */
if (da >= dev_addr && ((da + len) <= (dev_addr + size))) {
offset = da - dev_addr;
va = kproc->mem[i].cpu_addr + offset;
return (__force void *)va;
}
/* handle SoC-view addresses */
if (da >= bus_addr && ((da + len) <= (bus_addr + size))) {
offset = da - bus_addr;
va = kproc->mem[i].cpu_addr + offset;
return (__force void *)va;
}
}
/* handle static DDR reserved memory regions */
for (i = 0; i < kproc->num_rmems; i++) {
dev_addr = kproc->rmem[i].dev_addr;
size = kproc->rmem[i].size;
if (da >= dev_addr && ((da + len) <= (dev_addr + size))) {
offset = da - dev_addr;
va = kproc->rmem[i].cpu_addr + offset;
return (__force void *)va;
}
}
return NULL;
}
static int k3_m4_rproc_of_get_memories(struct platform_device *pdev,
struct k3_m4_rproc *kproc)
{
static const char * const mem_names[] = { "iram", "dram" };
static const u32 mem_addrs[] = { K3_M4_IRAM_DEV_ADDR, K3_M4_DRAM_DEV_ADDR };
struct device *dev = &pdev->dev;
struct resource *res;
int num_mems;
int i;
num_mems = ARRAY_SIZE(mem_names);
kproc->mem = devm_kcalloc(kproc->dev, num_mems,
sizeof(*kproc->mem), GFP_KERNEL);
if (!kproc->mem)
return -ENOMEM;
for (i = 0; i < num_mems; i++) {
res = platform_get_resource_byname(pdev, IORESOURCE_MEM,
mem_names[i]);
if (!res) {
dev_err(dev, "found no memory resource for %s\n",
mem_names[i]);
return -EINVAL;
}
if (!devm_request_mem_region(dev, res->start,
resource_size(res),
dev_name(dev))) {
dev_err(dev, "could not request %s region for resource\n",
mem_names[i]);
return -EBUSY;
}
kproc->mem[i].cpu_addr = devm_ioremap_wc(dev, res->start,
resource_size(res));
if (!kproc->mem[i].cpu_addr) {
dev_err(dev, "failed to map %s memory\n",
mem_names[i]);
return -ENOMEM;
}
kproc->mem[i].bus_addr = res->start;
kproc->mem[i].dev_addr = mem_addrs[i];
kproc->mem[i].size = resource_size(res);
dev_dbg(dev, "memory %8s: bus addr %pa size 0x%zx va %pK da 0x%x\n",
mem_names[i], &kproc->mem[i].bus_addr,
kproc->mem[i].size, kproc->mem[i].cpu_addr,
kproc->mem[i].dev_addr);
}
kproc->num_mems = num_mems;
return 0;
}
static void k3_m4_rproc_dev_mem_release(void *data)
{
struct device *dev = data;
of_reserved_mem_device_release(dev);
}
static int k3_m4_reserved_mem_init(struct k3_m4_rproc *kproc)
{
struct device *dev = kproc->dev;
struct device_node *np = dev->of_node;
struct device_node *rmem_np;
struct reserved_mem *rmem;
int num_rmems;
int ret, i;
num_rmems = of_property_count_elems_of_size(np, "memory-region",
sizeof(phandle));
if (num_rmems < 0) {
dev_err(dev, "device does not reserved memory regions (%d)\n",
num_rmems);
return -EINVAL;
}
if (num_rmems < 2) {
dev_err(dev, "device needs at least two memory regions to be defined, num = %d\n",
num_rmems);
return -EINVAL;
}
/* use reserved memory region 0 for vring DMA allocations */
ret = of_reserved_mem_device_init_by_idx(dev, np, 0);
if (ret) {
dev_err(dev, "device cannot initialize DMA pool (%d)\n", ret);
return ret;
}
ret = devm_add_action_or_reset(dev, k3_m4_rproc_dev_mem_release, dev);
if (ret)
return ret;
num_rmems--;
kproc->rmem = devm_kcalloc(dev, num_rmems, sizeof(*kproc->rmem), GFP_KERNEL);
if (!kproc->rmem)
return -ENOMEM;
/* use remaining reserved memory regions for static carveouts */
for (i = 0; i < num_rmems; i++) {
rmem_np = of_parse_phandle(np, "memory-region", i + 1);
if (!rmem_np)
return -EINVAL;
rmem = of_reserved_mem_lookup(rmem_np);
of_node_put(rmem_np);
if (!rmem)
return -EINVAL;
kproc->rmem[i].bus_addr = rmem->base;
/* 64-bit address regions currently not supported */
kproc->rmem[i].dev_addr = (u32)rmem->base;
kproc->rmem[i].size = rmem->size;
kproc->rmem[i].cpu_addr = devm_ioremap_wc(dev, rmem->base, rmem->size);
if (!kproc->rmem[i].cpu_addr) {
dev_err(dev, "failed to map reserved memory#%d at %pa of size %pa\n",
i + 1, &rmem->base, &rmem->size);
return -ENOMEM;
}
dev_dbg(dev, "reserved memory%d: bus addr %pa size 0x%zx va %pK da 0x%x\n",
i + 1, &kproc->rmem[i].bus_addr,
kproc->rmem[i].size, kproc->rmem[i].cpu_addr,
kproc->rmem[i].dev_addr);
}
kproc->num_rmems = num_rmems;
return 0;
}
static void k3_m4_release_tsp(void *data)
{
struct ti_sci_proc *tsp = data;
ti_sci_proc_release(tsp);
}
/*
* Power up the M4 remote processor.
*
* This function will be invoked only after the firmware for this rproc
* was loaded, parsed successfully, and all of its resource requirements
* were met. This callback is invoked only in remoteproc mode.
*/
static int k3_m4_rproc_start(struct rproc *rproc)
{
struct k3_m4_rproc *kproc = rproc->priv;
struct device *dev = kproc->dev;
int ret;
ret = k3_m4_rproc_ping_mbox(kproc);
if (ret)
return ret;
ret = reset_control_deassert(kproc->reset);
if (ret) {
dev_err(dev, "local-reset deassert failed, ret = %d\n", ret);
return ret;
}
return 0;
}
/*
* Stop the M4 remote processor.
*
* This function puts the M4 processor into reset, and finishes processing
* of any pending messages. This callback is invoked only in remoteproc mode.
*/
static int k3_m4_rproc_stop(struct rproc *rproc)
{
struct k3_m4_rproc *kproc = rproc->priv;
struct device *dev = kproc->dev;
int ret;
ret = reset_control_assert(kproc->reset);
if (ret) {
dev_err(dev, "local-reset assert failed, ret = %d\n", ret);
return ret;
}
return 0;
}
/*
* Attach to a running M4 remote processor (IPC-only mode)
*
* The remote processor is already booted, so there is no need to issue any
* TI-SCI commands to boot the M4 core. This callback is used only in IPC-only
* mode.
*/
static int k3_m4_rproc_attach(struct rproc *rproc)
{
struct k3_m4_rproc *kproc = rproc->priv;
int ret;
ret = k3_m4_rproc_ping_mbox(kproc);
if (ret)
return ret;
return 0;
}
/*
* Detach from a running M4 remote processor (IPC-only mode)
*
* This rproc detach callback performs the opposite operation to attach
* callback, the M4 core is not stopped and will be left to continue to
* run its booted firmware. This callback is invoked only in IPC-only mode.
*/
static int k3_m4_rproc_detach(struct rproc *rproc)
{
return 0;
}
#include "ti_k3_common.h"
static const struct rproc_ops k3_m4_rproc_ops = {
.prepare = k3_m4_rproc_prepare,
.unprepare = k3_m4_rproc_unprepare,
.start = k3_m4_rproc_start,
.stop = k3_m4_rproc_stop,
.attach = k3_m4_rproc_attach,
.detach = k3_m4_rproc_detach,
.kick = k3_m4_rproc_kick,
.da_to_va = k3_m4_rproc_da_to_va,
.get_loaded_rsc_table = k3_m4_get_loaded_rsc_table,
.prepare = k3_rproc_prepare,
.unprepare = k3_rproc_unprepare,
.start = k3_rproc_start,
.stop = k3_rproc_stop,
.attach = k3_rproc_attach,
.detach = k3_rproc_detach,
.kick = k3_rproc_kick,
.da_to_va = k3_rproc_da_to_va,
.get_loaded_rsc_table = k3_get_loaded_rsc_table,
};
static int k3_m4_rproc_probe(struct platform_device *pdev)
{
const struct k3_rproc_dev_data *data;
struct device *dev = &pdev->dev;
struct k3_m4_rproc *kproc;
struct k3_rproc *kproc;
struct rproc *rproc;
const char *fw_name;
bool r_state = false;
bool p_state = false;
int ret;
data = of_device_get_match_data(dev);
if (!data)
return -ENODEV;
ret = rproc_of_parse_firmware(dev, 0, &fw_name);
if (ret)
return dev_err_probe(dev, ret, "failed to parse firmware-name property\n");
@@ -578,6 +61,8 @@ static int k3_m4_rproc_probe(struct platform_device *pdev)
rproc->recovery_disabled = true;
kproc = rproc->priv;
kproc->dev = dev;
kproc->rproc = rproc;
kproc->data = data;
platform_set_drvdata(pdev, rproc);
kproc->ti_sci = devm_ti_sci_get_by_phandle(dev, "ti,sci");
@@ -601,15 +86,15 @@ static int k3_m4_rproc_probe(struct platform_device *pdev)
ret = ti_sci_proc_request(kproc->tsp);
if (ret < 0)
return dev_err_probe(dev, ret, "ti_sci_proc_request failed\n");
ret = devm_add_action_or_reset(dev, k3_m4_release_tsp, kproc->tsp);
ret = devm_add_action_or_reset(dev, k3_release_tsp, kproc->tsp);
if (ret)
return ret;
ret = k3_m4_rproc_of_get_memories(pdev, kproc);
ret = k3_rproc_of_get_memories(pdev, kproc);
if (ret)
return ret;
ret = k3_m4_reserved_mem_init(kproc);
ret = k3_reserved_mem_init(kproc);
if (ret)
return dev_err_probe(dev, ret, "reserved memory init failed\n");
@@ -627,15 +112,9 @@ static int k3_m4_rproc_probe(struct platform_device *pdev)
dev_info(dev, "configured M4F for remoteproc mode\n");
}
kproc->client.dev = dev;
kproc->client.tx_done = NULL;
kproc->client.rx_callback = k3_m4_rproc_mbox_callback;
kproc->client.tx_block = false;
kproc->client.knows_txdone = false;
kproc->mbox = mbox_request_channel(&kproc->client, 0);
if (IS_ERR(kproc->mbox))
return dev_err_probe(dev, PTR_ERR(kproc->mbox),
"mbox_request_channel failed\n");
ret = k3_rproc_request_mbox(rproc);
if (ret)
return ret;
ret = devm_rproc_add(dev, rproc);
if (ret)
@@ -645,8 +124,20 @@ static int k3_m4_rproc_probe(struct platform_device *pdev)
return 0;
}
static const struct k3_rproc_mem_data am64_m4_mems[] = {
{ .name = "iram", .dev_addr = 0x0 },
{ .name = "dram", .dev_addr = 0x30000 },
};
static const struct k3_rproc_dev_data am64_m4_data = {
.mems = am64_m4_mems,
.num_mems = ARRAY_SIZE(am64_m4_mems),
.boot_align_addr = SZ_1K,
.uses_lreset = true,
};
static const struct of_device_id k3_m4_of_match[] = {
{ .compatible = "ti,am64-m4fss", },
{ .compatible = "ti,am64-m4fss", .data = &am64_m4_data, },
{ /* sentinel */ },
};
MODULE_DEVICE_TABLE(of, k3_m4_of_match);
File diff suppressed because it is too large Load Diff
+33 -1
View File
@@ -380,6 +380,18 @@ static int zynqmp_r5_rproc_start(struct rproc *rproc)
dev_dbg(r5_core->dev, "RPU boot addr 0x%llx from %s.", rproc->bootaddr,
bootmem == PM_RPU_BOOTMEM_HIVEC ? "OCM" : "TCM");
/* Request node before starting RPU core if new version of API is supported */
if (zynqmp_pm_feature(PM_REQUEST_NODE) > 1) {
ret = zynqmp_pm_request_node(r5_core->pm_domain_id,
ZYNQMP_PM_CAPABILITY_ACCESS, 0,
ZYNQMP_PM_REQUEST_ACK_BLOCKING);
if (ret < 0) {
dev_err(r5_core->dev, "failed to request 0x%x",
r5_core->pm_domain_id);
return ret;
}
}
ret = zynqmp_pm_request_wake(r5_core->pm_domain_id, 1,
bootmem, ZYNQMP_PM_REQUEST_ACK_NO);
if (ret)
@@ -401,10 +413,30 @@ static int zynqmp_r5_rproc_stop(struct rproc *rproc)
struct zynqmp_r5_core *r5_core = rproc->priv;
int ret;
/* Use release node API to stop core if new version of API is supported */
if (zynqmp_pm_feature(PM_RELEASE_NODE) > 1) {
ret = zynqmp_pm_release_node(r5_core->pm_domain_id);
if (ret)
dev_err(r5_core->dev, "failed to stop remoteproc RPU %d\n", ret);
return ret;
}
/*
* Check expected version of EEMI call before calling it. This avoids
* any error or warning prints from firmware as it is expected that fw
* doesn't support it.
*/
if (zynqmp_pm_feature(PM_FORCE_POWERDOWN) != 1) {
dev_dbg(r5_core->dev, "EEMI interface %d ver 1 not supported\n",
PM_FORCE_POWERDOWN);
return -EOPNOTSUPP;
}
/* maintain force pwr down for backward compatibility */
ret = zynqmp_pm_force_pwrdwn(r5_core->pm_domain_id,
ZYNQMP_PM_REQUEST_ACK_BLOCKING);
if (ret)
dev_err(r5_core->dev, "failed to stop remoteproc RPU %d\n", ret);
dev_err(r5_core->dev, "core force power down failed\n");
return ret;
}