Back to home page

OSCL-LXR

 
 

    


0001 // SPDX-License-Identifier: GPL-2.0-only
0002 /*
0003  * TI K3 R5F (MCU) Remote Processor driver
0004  *
0005  * Copyright (C) 2017-2022 Texas Instruments Incorporated - https://www.ti.com/
0006  *  Suman Anna <s-anna@ti.com>
0007  */
0008 
0009 #include <linux/dma-mapping.h>
0010 #include <linux/err.h>
0011 #include <linux/interrupt.h>
0012 #include <linux/kernel.h>
0013 #include <linux/mailbox_client.h>
0014 #include <linux/module.h>
0015 #include <linux/of_address.h>
0016 #include <linux/of_device.h>
0017 #include <linux/of_reserved_mem.h>
0018 #include <linux/omap-mailbox.h>
0019 #include <linux/platform_device.h>
0020 #include <linux/pm_runtime.h>
0021 #include <linux/remoteproc.h>
0022 #include <linux/reset.h>
0023 #include <linux/slab.h>
0024 
0025 #include "omap_remoteproc.h"
0026 #include "remoteproc_internal.h"
0027 #include "ti_sci_proc.h"
0028 
0029 /* This address can either be for ATCM or BTCM with the other at address 0x0 */
0030 #define K3_R5_TCM_DEV_ADDR  0x41010000
0031 
0032 /* R5 TI-SCI Processor Configuration Flags */
0033 #define PROC_BOOT_CFG_FLAG_R5_DBG_EN            0x00000001
0034 #define PROC_BOOT_CFG_FLAG_R5_DBG_NIDEN         0x00000002
0035 #define PROC_BOOT_CFG_FLAG_R5_LOCKSTEP          0x00000100
0036 #define PROC_BOOT_CFG_FLAG_R5_TEINIT            0x00000200
0037 #define PROC_BOOT_CFG_FLAG_R5_NMFI_EN           0x00000400
0038 #define PROC_BOOT_CFG_FLAG_R5_TCM_RSTBASE       0x00000800
0039 #define PROC_BOOT_CFG_FLAG_R5_BTCM_EN           0x00001000
0040 #define PROC_BOOT_CFG_FLAG_R5_ATCM_EN           0x00002000
0041 /* Available from J7200 SoCs onwards */
0042 #define PROC_BOOT_CFG_FLAG_R5_MEM_INIT_DIS      0x00004000
0043 /* Applicable to only AM64x SoCs */
0044 #define PROC_BOOT_CFG_FLAG_R5_SINGLE_CORE       0x00008000
0045 
0046 /* R5 TI-SCI Processor Control Flags */
0047 #define PROC_BOOT_CTRL_FLAG_R5_CORE_HALT        0x00000001
0048 
0049 /* R5 TI-SCI Processor Status Flags */
0050 #define PROC_BOOT_STATUS_FLAG_R5_WFE            0x00000001
0051 #define PROC_BOOT_STATUS_FLAG_R5_WFI            0x00000002
0052 #define PROC_BOOT_STATUS_FLAG_R5_CLK_GATED      0x00000004
0053 #define PROC_BOOT_STATUS_FLAG_R5_LOCKSTEP_PERMITTED 0x00000100
0054 /* Applicable to only AM64x SoCs */
0055 #define PROC_BOOT_STATUS_FLAG_R5_SINGLECORE_ONLY    0x00000200
0056 
0057 /**
0058  * struct k3_r5_mem - internal memory structure
0059  * @cpu_addr: MPU virtual address of the memory region
0060  * @bus_addr: Bus address used to access the memory region
0061  * @dev_addr: Device address from remoteproc view
0062  * @size: Size of the memory region
0063  */
0064 struct k3_r5_mem {
0065     void __iomem *cpu_addr;
0066     phys_addr_t bus_addr;
0067     u32 dev_addr;
0068     size_t size;
0069 };
0070 
0071 /*
0072  * All cluster mode values are not applicable on all SoCs. The following
0073  * are the modes supported on various SoCs:
0074  *   Split mode      : AM65x, J721E, J7200 and AM64x SoCs
0075  *   LockStep mode   : AM65x, J721E and J7200 SoCs
0076  *   Single-CPU mode : AM64x SoCs only
0077  */
0078 enum cluster_mode {
0079     CLUSTER_MODE_SPLIT = 0,
0080     CLUSTER_MODE_LOCKSTEP,
0081     CLUSTER_MODE_SINGLECPU,
0082 };
0083 
0084 /**
0085  * struct k3_r5_soc_data - match data to handle SoC variations
0086  * @tcm_is_double: flag to denote the larger unified TCMs in certain modes
0087  * @tcm_ecc_autoinit: flag to denote the auto-initialization of TCMs for ECC
0088  * @single_cpu_mode: flag to denote if SoC/IP supports Single-CPU mode
0089  */
0090 struct k3_r5_soc_data {
0091     bool tcm_is_double;
0092     bool tcm_ecc_autoinit;
0093     bool single_cpu_mode;
0094 };
0095 
0096 /**
0097  * struct k3_r5_cluster - K3 R5F Cluster structure
0098  * @dev: cached device pointer
0099  * @mode: Mode to configure the Cluster - Split or LockStep
0100  * @cores: list of R5 cores within the cluster
0101  * @soc_data: SoC-specific feature data for a R5FSS
0102  */
0103 struct k3_r5_cluster {
0104     struct device *dev;
0105     enum cluster_mode mode;
0106     struct list_head cores;
0107     const struct k3_r5_soc_data *soc_data;
0108 };
0109 
0110 /**
0111  * struct k3_r5_core - K3 R5 core structure
0112  * @elem: linked list item
0113  * @dev: cached device pointer
0114  * @rproc: rproc handle representing this core
0115  * @mem: internal memory regions data
0116  * @sram: on-chip SRAM memory regions data
0117  * @num_mems: number of internal memory regions
0118  * @num_sram: number of on-chip SRAM memory regions
0119  * @reset: reset control handle
0120  * @tsp: TI-SCI processor control handle
0121  * @ti_sci: TI-SCI handle
0122  * @ti_sci_id: TI-SCI device identifier
0123  * @atcm_enable: flag to control ATCM enablement
0124  * @btcm_enable: flag to control BTCM enablement
0125  * @loczrama: flag to dictate which TCM is at device address 0x0
0126  */
0127 struct k3_r5_core {
0128     struct list_head elem;
0129     struct device *dev;
0130     struct rproc *rproc;
0131     struct k3_r5_mem *mem;
0132     struct k3_r5_mem *sram;
0133     int num_mems;
0134     int num_sram;
0135     struct reset_control *reset;
0136     struct ti_sci_proc *tsp;
0137     const struct ti_sci_handle *ti_sci;
0138     u32 ti_sci_id;
0139     u32 atcm_enable;
0140     u32 btcm_enable;
0141     u32 loczrama;
0142 };
0143 
0144 /**
0145  * struct k3_r5_rproc - K3 remote processor state
0146  * @dev: cached device pointer
0147  * @cluster: cached pointer to parent cluster structure
0148  * @mbox: mailbox channel handle
0149  * @client: mailbox client to request the mailbox channel
0150  * @rproc: rproc handle
0151  * @core: cached pointer to r5 core structure being used
0152  * @rmem: reserved memory regions data
0153  * @num_rmems: number of reserved memory regions
0154  */
0155 struct k3_r5_rproc {
0156     struct device *dev;
0157     struct k3_r5_cluster *cluster;
0158     struct mbox_chan *mbox;
0159     struct mbox_client client;
0160     struct rproc *rproc;
0161     struct k3_r5_core *core;
0162     struct k3_r5_mem *rmem;
0163     int num_rmems;
0164 };
0165 
0166 /**
0167  * k3_r5_rproc_mbox_callback() - inbound mailbox message handler
0168  * @client: mailbox client pointer used for requesting the mailbox channel
0169  * @data: mailbox payload
0170  *
0171  * This handler is invoked by the OMAP mailbox driver whenever a mailbox
0172  * message is received. Usually, the mailbox payload simply contains
0173  * the index of the virtqueue that is kicked by the remote processor,
0174  * and we let remoteproc core handle it.
0175  *
0176  * In addition to virtqueue indices, we also have some out-of-band values
0177  * that indicate different events. Those values are deliberately very
0178  * large so they don't coincide with virtqueue indices.
0179  */
0180 static void k3_r5_rproc_mbox_callback(struct mbox_client *client, void *data)
0181 {
0182     struct k3_r5_rproc *kproc = container_of(client, struct k3_r5_rproc,
0183                         client);
0184     struct device *dev = kproc->rproc->dev.parent;
0185     const char *name = kproc->rproc->name;
0186     u32 msg = omap_mbox_message(data);
0187 
0188     dev_dbg(dev, "mbox msg: 0x%x\n", msg);
0189 
0190     switch (msg) {
0191     case RP_MBOX_CRASH:
0192         /*
0193          * remoteproc detected an exception, but error recovery is not
0194          * supported. So, just log this for now
0195          */
0196         dev_err(dev, "K3 R5F rproc %s crashed\n", name);
0197         break;
0198     case RP_MBOX_ECHO_REPLY:
0199         dev_info(dev, "received echo reply from %s\n", name);
0200         break;
0201     default:
0202         /* silently handle all other valid messages */
0203         if (msg >= RP_MBOX_READY && msg < RP_MBOX_END_MSG)
0204             return;
0205         if (msg > kproc->rproc->max_notifyid) {
0206             dev_dbg(dev, "dropping unknown message 0x%x", msg);
0207             return;
0208         }
0209         /* msg contains the index of the triggered vring */
0210         if (rproc_vq_interrupt(kproc->rproc, msg) == IRQ_NONE)
0211             dev_dbg(dev, "no message was found in vqid %d\n", msg);
0212     }
0213 }
0214 
0215 /* kick a virtqueue */
0216 static void k3_r5_rproc_kick(struct rproc *rproc, int vqid)
0217 {
0218     struct k3_r5_rproc *kproc = rproc->priv;
0219     struct device *dev = rproc->dev.parent;
0220     mbox_msg_t msg = (mbox_msg_t)vqid;
0221     int ret;
0222 
0223     /* send the index of the triggered virtqueue in the mailbox payload */
0224     ret = mbox_send_message(kproc->mbox, (void *)msg);
0225     if (ret < 0)
0226         dev_err(dev, "failed to send mailbox message, status = %d\n",
0227             ret);
0228 }
0229 
0230 static int k3_r5_split_reset(struct k3_r5_core *core)
0231 {
0232     int ret;
0233 
0234     ret = reset_control_assert(core->reset);
0235     if (ret) {
0236         dev_err(core->dev, "local-reset assert failed, ret = %d\n",
0237             ret);
0238         return ret;
0239     }
0240 
0241     ret = core->ti_sci->ops.dev_ops.put_device(core->ti_sci,
0242                            core->ti_sci_id);
0243     if (ret) {
0244         dev_err(core->dev, "module-reset assert failed, ret = %d\n",
0245             ret);
0246         if (reset_control_deassert(core->reset))
0247             dev_warn(core->dev, "local-reset deassert back failed\n");
0248     }
0249 
0250     return ret;
0251 }
0252 
0253 static int k3_r5_split_release(struct k3_r5_core *core)
0254 {
0255     int ret;
0256 
0257     ret = core->ti_sci->ops.dev_ops.get_device(core->ti_sci,
0258                            core->ti_sci_id);
0259     if (ret) {
0260         dev_err(core->dev, "module-reset deassert failed, ret = %d\n",
0261             ret);
0262         return ret;
0263     }
0264 
0265     ret = reset_control_deassert(core->reset);
0266     if (ret) {
0267         dev_err(core->dev, "local-reset deassert failed, ret = %d\n",
0268             ret);
0269         if (core->ti_sci->ops.dev_ops.put_device(core->ti_sci,
0270                              core->ti_sci_id))
0271             dev_warn(core->dev, "module-reset assert back failed\n");
0272     }
0273 
0274     return ret;
0275 }
0276 
0277 static int k3_r5_lockstep_reset(struct k3_r5_cluster *cluster)
0278 {
0279     struct k3_r5_core *core;
0280     int ret;
0281 
0282     /* assert local reset on all applicable cores */
0283     list_for_each_entry(core, &cluster->cores, elem) {
0284         ret = reset_control_assert(core->reset);
0285         if (ret) {
0286             dev_err(core->dev, "local-reset assert failed, ret = %d\n",
0287                 ret);
0288             core = list_prev_entry(core, elem);
0289             goto unroll_local_reset;
0290         }
0291     }
0292 
0293     /* disable PSC modules on all applicable cores */
0294     list_for_each_entry(core, &cluster->cores, elem) {
0295         ret = core->ti_sci->ops.dev_ops.put_device(core->ti_sci,
0296                                core->ti_sci_id);
0297         if (ret) {
0298             dev_err(core->dev, "module-reset assert failed, ret = %d\n",
0299                 ret);
0300             goto unroll_module_reset;
0301         }
0302     }
0303 
0304     return 0;
0305 
0306 unroll_module_reset:
0307     list_for_each_entry_continue_reverse(core, &cluster->cores, elem) {
0308         if (core->ti_sci->ops.dev_ops.put_device(core->ti_sci,
0309                              core->ti_sci_id))
0310             dev_warn(core->dev, "module-reset assert back failed\n");
0311     }
0312     core = list_last_entry(&cluster->cores, struct k3_r5_core, elem);
0313 unroll_local_reset:
0314     list_for_each_entry_from_reverse(core, &cluster->cores, elem) {
0315         if (reset_control_deassert(core->reset))
0316             dev_warn(core->dev, "local-reset deassert back failed\n");
0317     }
0318 
0319     return ret;
0320 }
0321 
0322 static int k3_r5_lockstep_release(struct k3_r5_cluster *cluster)
0323 {
0324     struct k3_r5_core *core;
0325     int ret;
0326 
0327     /* enable PSC modules on all applicable cores */
0328     list_for_each_entry_reverse(core, &cluster->cores, elem) {
0329         ret = core->ti_sci->ops.dev_ops.get_device(core->ti_sci,
0330                                core->ti_sci_id);
0331         if (ret) {
0332             dev_err(core->dev, "module-reset deassert failed, ret = %d\n",
0333                 ret);
0334             core = list_next_entry(core, elem);
0335             goto unroll_module_reset;
0336         }
0337     }
0338 
0339     /* deassert local reset on all applicable cores */
0340     list_for_each_entry_reverse(core, &cluster->cores, elem) {
0341         ret = reset_control_deassert(core->reset);
0342         if (ret) {
0343             dev_err(core->dev, "module-reset deassert failed, ret = %d\n",
0344                 ret);
0345             goto unroll_local_reset;
0346         }
0347     }
0348 
0349     return 0;
0350 
0351 unroll_local_reset:
0352     list_for_each_entry_continue(core, &cluster->cores, elem) {
0353         if (reset_control_assert(core->reset))
0354             dev_warn(core->dev, "local-reset assert back failed\n");
0355     }
0356     core = list_first_entry(&cluster->cores, struct k3_r5_core, elem);
0357 unroll_module_reset:
0358     list_for_each_entry_from(core, &cluster->cores, elem) {
0359         if (core->ti_sci->ops.dev_ops.put_device(core->ti_sci,
0360                              core->ti_sci_id))
0361             dev_warn(core->dev, "module-reset assert back failed\n");
0362     }
0363 
0364     return ret;
0365 }
0366 
0367 static inline int k3_r5_core_halt(struct k3_r5_core *core)
0368 {
0369     return ti_sci_proc_set_control(core->tsp,
0370                        PROC_BOOT_CTRL_FLAG_R5_CORE_HALT, 0);
0371 }
0372 
0373 static inline int k3_r5_core_run(struct k3_r5_core *core)
0374 {
0375     return ti_sci_proc_set_control(core->tsp,
0376                        0, PROC_BOOT_CTRL_FLAG_R5_CORE_HALT);
0377 }
0378 
0379 static int k3_r5_rproc_request_mbox(struct rproc *rproc)
0380 {
0381     struct k3_r5_rproc *kproc = rproc->priv;
0382     struct mbox_client *client = &kproc->client;
0383     struct device *dev = kproc->dev;
0384     int ret;
0385 
0386     client->dev = dev;
0387     client->tx_done = NULL;
0388     client->rx_callback = k3_r5_rproc_mbox_callback;
0389     client->tx_block = false;
0390     client->knows_txdone = false;
0391 
0392     kproc->mbox = mbox_request_channel(client, 0);
0393     if (IS_ERR(kproc->mbox)) {
0394         ret = -EBUSY;
0395         dev_err(dev, "mbox_request_channel failed: %ld\n",
0396             PTR_ERR(kproc->mbox));
0397         return ret;
0398     }
0399 
0400     /*
0401      * Ping the remote processor, this is only for sanity-sake for now;
0402      * there is no functional effect whatsoever.
0403      *
0404      * Note that the reply will _not_ arrive immediately: this message
0405      * will wait in the mailbox fifo until the remote processor is booted.
0406      */
0407     ret = mbox_send_message(kproc->mbox, (void *)RP_MBOX_ECHO_REQUEST);
0408     if (ret < 0) {
0409         dev_err(dev, "mbox_send_message failed: %d\n", ret);
0410         mbox_free_channel(kproc->mbox);
0411         return ret;
0412     }
0413 
0414     return 0;
0415 }
0416 
0417 /*
0418  * The R5F cores have controls for both a reset and a halt/run. The code
0419  * execution from DDR requires the initial boot-strapping code to be run
0420  * from the internal TCMs. This function is used to release the resets on
0421  * applicable cores to allow loading into the TCMs. The .prepare() ops is
0422  * invoked by remoteproc core before any firmware loading, and is followed
0423  * by the .start() ops after loading to actually let the R5 cores run.
0424  *
0425  * The Single-CPU mode on applicable SoCs (eg: AM64x) only uses Core0 to
0426  * execute code, but combines the TCMs from both cores. The resets for both
0427  * cores need to be released to make this possible, as the TCMs are in general
0428  * private to each core. Only Core0 needs to be unhalted for running the
0429  * cluster in this mode. The function uses the same reset logic as LockStep
0430  * mode for this (though the behavior is agnostic of the reset release order).
0431  * This callback is invoked only in remoteproc mode.
0432  */
0433 static int k3_r5_rproc_prepare(struct rproc *rproc)
0434 {
0435     struct k3_r5_rproc *kproc = rproc->priv;
0436     struct k3_r5_cluster *cluster = kproc->cluster;
0437     struct k3_r5_core *core = kproc->core;
0438     struct device *dev = kproc->dev;
0439     u32 ctrl = 0, cfg = 0, stat = 0;
0440     u64 boot_vec = 0;
0441     bool mem_init_dis;
0442     int ret;
0443 
0444     ret = ti_sci_proc_get_status(core->tsp, &boot_vec, &cfg, &ctrl, &stat);
0445     if (ret < 0)
0446         return ret;
0447     mem_init_dis = !!(cfg & PROC_BOOT_CFG_FLAG_R5_MEM_INIT_DIS);
0448 
0449     /* Re-use LockStep-mode reset logic for Single-CPU mode */
0450     ret = (cluster->mode == CLUSTER_MODE_LOCKSTEP ||
0451            cluster->mode == CLUSTER_MODE_SINGLECPU) ?
0452         k3_r5_lockstep_release(cluster) : k3_r5_split_release(core);
0453     if (ret) {
0454         dev_err(dev, "unable to enable cores for TCM loading, ret = %d\n",
0455             ret);
0456         return ret;
0457     }
0458 
0459     /*
0460      * Newer IP revisions like on J7200 SoCs support h/w auto-initialization
0461      * of TCMs, so there is no need to perform the s/w memzero. This bit is
0462      * configurable through System Firmware, the default value does perform
0463      * auto-init, but account for it in case it is disabled
0464      */
0465     if (cluster->soc_data->tcm_ecc_autoinit && !mem_init_dis) {
0466         dev_dbg(dev, "leveraging h/w init for TCM memories\n");
0467         return 0;
0468     }
0469 
0470     /*
0471      * Zero out both TCMs unconditionally (access from v8 Arm core is not
0472      * affected by ATCM & BTCM enable configuration values) so that ECC
0473      * can be effective on all TCM addresses.
0474      */
0475     dev_dbg(dev, "zeroing out ATCM memory\n");
0476     memset(core->mem[0].cpu_addr, 0x00, core->mem[0].size);
0477 
0478     dev_dbg(dev, "zeroing out BTCM memory\n");
0479     memset(core->mem[1].cpu_addr, 0x00, core->mem[1].size);
0480 
0481     return 0;
0482 }
0483 
0484 /*
0485  * This function implements the .unprepare() ops and performs the complimentary
0486  * operations to that of the .prepare() ops. The function is used to assert the
0487  * resets on all applicable cores for the rproc device (depending on LockStep
0488  * or Split mode). This completes the second portion of powering down the R5F
0489  * cores. The cores themselves are only halted in the .stop() ops, and the
0490  * .unprepare() ops is invoked by the remoteproc core after the remoteproc is
0491  * stopped.
0492  *
0493  * The Single-CPU mode on applicable SoCs (eg: AM64x) combines the TCMs from
0494  * both cores. The access is made possible only with releasing the resets for
0495  * both cores, but with only Core0 unhalted. This function re-uses the same
0496  * reset assert logic as LockStep mode for this mode (though the behavior is
0497  * agnostic of the reset assert order). This callback is invoked only in
0498  * remoteproc mode.
0499  */
0500 static int k3_r5_rproc_unprepare(struct rproc *rproc)
0501 {
0502     struct k3_r5_rproc *kproc = rproc->priv;
0503     struct k3_r5_cluster *cluster = kproc->cluster;
0504     struct k3_r5_core *core = kproc->core;
0505     struct device *dev = kproc->dev;
0506     int ret;
0507 
0508     /* Re-use LockStep-mode reset logic for Single-CPU mode */
0509     ret = (cluster->mode == CLUSTER_MODE_LOCKSTEP ||
0510            cluster->mode == CLUSTER_MODE_SINGLECPU) ?
0511         k3_r5_lockstep_reset(cluster) : k3_r5_split_reset(core);
0512     if (ret)
0513         dev_err(dev, "unable to disable cores, ret = %d\n", ret);
0514 
0515     return ret;
0516 }
0517 
0518 /*
0519  * The R5F start sequence includes two different operations
0520  * 1. Configure the boot vector for R5F core(s)
0521  * 2. Unhalt/Run the R5F core(s)
0522  *
0523  * The sequence is different between LockStep and Split modes. The LockStep
0524  * mode requires the boot vector to be configured only for Core0, and then
0525  * unhalt both the cores to start the execution - Core1 needs to be unhalted
0526  * first followed by Core0. The Split-mode requires that Core0 to be maintained
0527  * always in a higher power state that Core1 (implying Core1 needs to be started
0528  * always only after Core0 is started).
0529  *
0530  * The Single-CPU mode on applicable SoCs (eg: AM64x) only uses Core0 to execute
0531  * code, so only Core0 needs to be unhalted. The function uses the same logic
0532  * flow as Split-mode for this. This callback is invoked only in remoteproc
0533  * mode.
0534  */
0535 static int k3_r5_rproc_start(struct rproc *rproc)
0536 {
0537     struct k3_r5_rproc *kproc = rproc->priv;
0538     struct k3_r5_cluster *cluster = kproc->cluster;
0539     struct device *dev = kproc->dev;
0540     struct k3_r5_core *core;
0541     u32 boot_addr;
0542     int ret;
0543 
0544     ret = k3_r5_rproc_request_mbox(rproc);
0545     if (ret)
0546         return ret;
0547 
0548     boot_addr = rproc->bootaddr;
0549     /* TODO: add boot_addr sanity checking */
0550     dev_dbg(dev, "booting R5F core using boot addr = 0x%x\n", boot_addr);
0551 
0552     /* boot vector need not be programmed for Core1 in LockStep mode */
0553     core = kproc->core;
0554     ret = ti_sci_proc_set_config(core->tsp, boot_addr, 0, 0);
0555     if (ret)
0556         goto put_mbox;
0557 
0558     /* unhalt/run all applicable cores */
0559     if (cluster->mode == CLUSTER_MODE_LOCKSTEP) {
0560         list_for_each_entry_reverse(core, &cluster->cores, elem) {
0561             ret = k3_r5_core_run(core);
0562             if (ret)
0563                 goto unroll_core_run;
0564         }
0565     } else {
0566         ret = k3_r5_core_run(core);
0567         if (ret)
0568             goto put_mbox;
0569     }
0570 
0571     return 0;
0572 
0573 unroll_core_run:
0574     list_for_each_entry_continue(core, &cluster->cores, elem) {
0575         if (k3_r5_core_halt(core))
0576             dev_warn(core->dev, "core halt back failed\n");
0577     }
0578 put_mbox:
0579     mbox_free_channel(kproc->mbox);
0580     return ret;
0581 }
0582 
0583 /*
0584  * The R5F stop function includes the following operations
0585  * 1. Halt R5F core(s)
0586  *
0587  * The sequence is different between LockStep and Split modes, and the order
0588  * of cores the operations are performed are also in general reverse to that
0589  * of the start function. The LockStep mode requires each operation to be
0590  * performed first on Core0 followed by Core1. The Split-mode requires that
0591  * Core0 to be maintained always in a higher power state that Core1 (implying
0592  * Core1 needs to be stopped first before Core0).
0593  *
0594  * The Single-CPU mode on applicable SoCs (eg: AM64x) only uses Core0 to execute
0595  * code, so only Core0 needs to be halted. The function uses the same logic
0596  * flow as Split-mode for this.
0597  *
0598  * Note that the R5F halt operation in general is not effective when the R5F
0599  * core is running, but is needed to make sure the core won't run after
0600  * deasserting the reset the subsequent time. The asserting of reset can
0601  * be done here, but is preferred to be done in the .unprepare() ops - this
0602  * maintains the symmetric behavior between the .start(), .stop(), .prepare()
0603  * and .unprepare() ops, and also balances them well between sysfs 'state'
0604  * flow and device bind/unbind or module removal. This callback is invoked
0605  * only in remoteproc mode.
0606  */
0607 static int k3_r5_rproc_stop(struct rproc *rproc)
0608 {
0609     struct k3_r5_rproc *kproc = rproc->priv;
0610     struct k3_r5_cluster *cluster = kproc->cluster;
0611     struct k3_r5_core *core = kproc->core;
0612     int ret;
0613 
0614     /* halt all applicable cores */
0615     if (cluster->mode == CLUSTER_MODE_LOCKSTEP) {
0616         list_for_each_entry(core, &cluster->cores, elem) {
0617             ret = k3_r5_core_halt(core);
0618             if (ret) {
0619                 core = list_prev_entry(core, elem);
0620                 goto unroll_core_halt;
0621             }
0622         }
0623     } else {
0624         ret = k3_r5_core_halt(core);
0625         if (ret)
0626             goto out;
0627     }
0628 
0629     mbox_free_channel(kproc->mbox);
0630 
0631     return 0;
0632 
0633 unroll_core_halt:
0634     list_for_each_entry_from_reverse(core, &cluster->cores, elem) {
0635         if (k3_r5_core_run(core))
0636             dev_warn(core->dev, "core run back failed\n");
0637     }
0638 out:
0639     return ret;
0640 }
0641 
0642 /*
0643  * Attach to a running R5F remote processor (IPC-only mode)
0644  *
0645  * The R5F attach callback only needs to request the mailbox, the remote
0646  * processor is already booted, so there is no need to issue any TI-SCI
0647  * commands to boot the R5F cores in IPC-only mode. This callback is invoked
0648  * only in IPC-only mode.
0649  */
0650 static int k3_r5_rproc_attach(struct rproc *rproc)
0651 {
0652     struct k3_r5_rproc *kproc = rproc->priv;
0653     struct device *dev = kproc->dev;
0654     int ret;
0655 
0656     ret = k3_r5_rproc_request_mbox(rproc);
0657     if (ret)
0658         return ret;
0659 
0660     dev_info(dev, "R5F core initialized in IPC-only mode\n");
0661     return 0;
0662 }
0663 
0664 /*
0665  * Detach from a running R5F remote processor (IPC-only mode)
0666  *
0667  * The R5F detach callback performs the opposite operation to attach callback
0668  * and only needs to release the mailbox, the R5F cores are not stopped and
0669  * will be left in booted state in IPC-only mode. This callback is invoked
0670  * only in IPC-only mode.
0671  */
0672 static int k3_r5_rproc_detach(struct rproc *rproc)
0673 {
0674     struct k3_r5_rproc *kproc = rproc->priv;
0675     struct device *dev = kproc->dev;
0676 
0677     mbox_free_channel(kproc->mbox);
0678     dev_info(dev, "R5F core deinitialized in IPC-only mode\n");
0679     return 0;
0680 }
0681 
0682 /*
0683  * This function implements the .get_loaded_rsc_table() callback and is used
0684  * to provide the resource table for the booted R5F in IPC-only mode. The K3 R5F
0685  * firmwares follow a design-by-contract approach and are expected to have the
0686  * resource table at the base of the DDR region reserved for firmware usage.
0687  * This provides flexibility for the remote processor to be booted by different
0688  * bootloaders that may or may not have the ability to publish the resource table
0689  * address and size through a DT property. This callback is invoked only in
0690  * IPC-only mode.
0691  */
0692 static struct resource_table *k3_r5_get_loaded_rsc_table(struct rproc *rproc,
0693                              size_t *rsc_table_sz)
0694 {
0695     struct k3_r5_rproc *kproc = rproc->priv;
0696     struct device *dev = kproc->dev;
0697 
0698     if (!kproc->rmem[0].cpu_addr) {
0699         dev_err(dev, "memory-region #1 does not exist, loaded rsc table can't be found");
0700         return ERR_PTR(-ENOMEM);
0701     }
0702 
0703     /*
0704      * NOTE: The resource table size is currently hard-coded to a maximum
0705      * of 256 bytes. The most common resource table usage for K3 firmwares
0706      * is to only have the vdev resource entry and an optional trace entry.
0707      * The exact size could be computed based on resource table address, but
0708      * the hard-coded value suffices to support the IPC-only mode.
0709      */
0710     *rsc_table_sz = 256;
0711     return (struct resource_table *)kproc->rmem[0].cpu_addr;
0712 }
0713 
0714 /*
0715  * Internal Memory translation helper
0716  *
0717  * Custom function implementing the rproc .da_to_va ops to provide address
0718  * translation (device address to kernel virtual address) for internal RAMs
0719  * present in a DSP or IPU device). The translated addresses can be used
0720  * either by the remoteproc core for loading, or by any rpmsg bus drivers.
0721  */
0722 static void *k3_r5_rproc_da_to_va(struct rproc *rproc, u64 da, size_t len, bool *is_iomem)
0723 {
0724     struct k3_r5_rproc *kproc = rproc->priv;
0725     struct k3_r5_core *core = kproc->core;
0726     void __iomem *va = NULL;
0727     phys_addr_t bus_addr;
0728     u32 dev_addr, offset;
0729     size_t size;
0730     int i;
0731 
0732     if (len == 0)
0733         return NULL;
0734 
0735     /* handle both R5 and SoC views of ATCM and BTCM */
0736     for (i = 0; i < core->num_mems; i++) {
0737         bus_addr = core->mem[i].bus_addr;
0738         dev_addr = core->mem[i].dev_addr;
0739         size = core->mem[i].size;
0740 
0741         /* handle R5-view addresses of TCMs */
0742         if (da >= dev_addr && ((da + len) <= (dev_addr + size))) {
0743             offset = da - dev_addr;
0744             va = core->mem[i].cpu_addr + offset;
0745             return (__force void *)va;
0746         }
0747 
0748         /* handle SoC-view addresses of TCMs */
0749         if (da >= bus_addr && ((da + len) <= (bus_addr + size))) {
0750             offset = da - bus_addr;
0751             va = core->mem[i].cpu_addr + offset;
0752             return (__force void *)va;
0753         }
0754     }
0755 
0756     /* handle any SRAM regions using SoC-view addresses */
0757     for (i = 0; i < core->num_sram; i++) {
0758         dev_addr = core->sram[i].dev_addr;
0759         size = core->sram[i].size;
0760 
0761         if (da >= dev_addr && ((da + len) <= (dev_addr + size))) {
0762             offset = da - dev_addr;
0763             va = core->sram[i].cpu_addr + offset;
0764             return (__force void *)va;
0765         }
0766     }
0767 
0768     /* handle static DDR reserved memory regions */
0769     for (i = 0; i < kproc->num_rmems; i++) {
0770         dev_addr = kproc->rmem[i].dev_addr;
0771         size = kproc->rmem[i].size;
0772 
0773         if (da >= dev_addr && ((da + len) <= (dev_addr + size))) {
0774             offset = da - dev_addr;
0775             va = kproc->rmem[i].cpu_addr + offset;
0776             return (__force void *)va;
0777         }
0778     }
0779 
0780     return NULL;
0781 }
0782 
0783 static const struct rproc_ops k3_r5_rproc_ops = {
0784     .prepare    = k3_r5_rproc_prepare,
0785     .unprepare  = k3_r5_rproc_unprepare,
0786     .start      = k3_r5_rproc_start,
0787     .stop       = k3_r5_rproc_stop,
0788     .kick       = k3_r5_rproc_kick,
0789     .da_to_va   = k3_r5_rproc_da_to_va,
0790 };
0791 
0792 /*
0793  * Internal R5F Core configuration
0794  *
0795  * Each R5FSS has a cluster-level setting for configuring the processor
0796  * subsystem either in a safety/fault-tolerant LockStep mode or a performance
0797  * oriented Split mode on most SoCs. A fewer SoCs support a non-safety mode
0798  * as an alternate for LockStep mode that exercises only a single R5F core
0799  * called Single-CPU mode. Each R5F core has a number of settings to either
0800  * enable/disable each of the TCMs, control which TCM appears at the R5F core's
0801  * address 0x0. These settings need to be configured before the resets for the
0802  * corresponding core are released. These settings are all protected and managed
0803  * by the System Processor.
0804  *
0805  * This function is used to pre-configure these settings for each R5F core, and
0806  * the configuration is all done through various ti_sci_proc functions that
0807  * communicate with the System Processor. The function also ensures that both
0808  * the cores are halted before the .prepare() step.
0809  *
0810  * The function is called from k3_r5_cluster_rproc_init() and is invoked either
0811  * once (in LockStep mode or Single-CPU modes) or twice (in Split mode). Support
0812  * for LockStep-mode is dictated by an eFUSE register bit, and the config
0813  * settings retrieved from DT are adjusted accordingly as per the permitted
0814  * cluster mode. Another eFUSE register bit dictates if the R5F cluster only
0815  * supports a Single-CPU mode. All cluster level settings like Cluster mode and
0816  * TEINIT (exception handling state dictating ARM or Thumb mode) can only be set
0817  * and retrieved using Core0.
0818  *
0819  * The function behavior is different based on the cluster mode. The R5F cores
0820  * are configured independently as per their individual settings in Split mode.
0821  * They are identically configured in LockStep mode using the primary Core0
0822  * settings. However, some individual settings cannot be set in LockStep mode.
0823  * This is overcome by switching to Split-mode initially and then programming
0824  * both the cores with the same settings, before reconfiguing again for
0825  * LockStep mode.
0826  */
0827 static int k3_r5_rproc_configure(struct k3_r5_rproc *kproc)
0828 {
0829     struct k3_r5_cluster *cluster = kproc->cluster;
0830     struct device *dev = kproc->dev;
0831     struct k3_r5_core *core0, *core, *temp;
0832     u32 ctrl = 0, cfg = 0, stat = 0;
0833     u32 set_cfg = 0, clr_cfg = 0;
0834     u64 boot_vec = 0;
0835     bool lockstep_en;
0836     bool single_cpu;
0837     int ret;
0838 
0839     core0 = list_first_entry(&cluster->cores, struct k3_r5_core, elem);
0840     if (cluster->mode == CLUSTER_MODE_LOCKSTEP ||
0841         cluster->mode == CLUSTER_MODE_SINGLECPU) {
0842         core = core0;
0843     } else {
0844         core = kproc->core;
0845     }
0846 
0847     ret = ti_sci_proc_get_status(core->tsp, &boot_vec, &cfg, &ctrl,
0848                      &stat);
0849     if (ret < 0)
0850         return ret;
0851 
0852     dev_dbg(dev, "boot_vector = 0x%llx, cfg = 0x%x ctrl = 0x%x stat = 0x%x\n",
0853         boot_vec, cfg, ctrl, stat);
0854 
0855     /* check if only Single-CPU mode is supported on applicable SoCs */
0856     if (cluster->soc_data->single_cpu_mode) {
0857         single_cpu =
0858             !!(stat & PROC_BOOT_STATUS_FLAG_R5_SINGLECORE_ONLY);
0859         if (single_cpu && cluster->mode == CLUSTER_MODE_SPLIT) {
0860             dev_err(cluster->dev, "split-mode not permitted, force configuring for single-cpu mode\n");
0861             cluster->mode = CLUSTER_MODE_SINGLECPU;
0862         }
0863         goto config;
0864     }
0865 
0866     /* check conventional LockStep vs Split mode configuration */
0867     lockstep_en = !!(stat & PROC_BOOT_STATUS_FLAG_R5_LOCKSTEP_PERMITTED);
0868     if (!lockstep_en && cluster->mode == CLUSTER_MODE_LOCKSTEP) {
0869         dev_err(cluster->dev, "lockstep mode not permitted, force configuring for split-mode\n");
0870         cluster->mode = CLUSTER_MODE_SPLIT;
0871     }
0872 
0873 config:
0874     /* always enable ARM mode and set boot vector to 0 */
0875     boot_vec = 0x0;
0876     if (core == core0) {
0877         clr_cfg = PROC_BOOT_CFG_FLAG_R5_TEINIT;
0878         if (cluster->soc_data->single_cpu_mode) {
0879             /*
0880              * Single-CPU configuration bit can only be configured
0881              * on Core0 and system firmware will NACK any requests
0882              * with the bit configured, so program it only on
0883              * permitted cores
0884              */
0885             if (cluster->mode == CLUSTER_MODE_SINGLECPU)
0886                 set_cfg = PROC_BOOT_CFG_FLAG_R5_SINGLE_CORE;
0887         } else {
0888             /*
0889              * LockStep configuration bit is Read-only on Split-mode
0890              * _only_ devices and system firmware will NACK any
0891              * requests with the bit configured, so program it only
0892              * on permitted devices
0893              */
0894             if (lockstep_en)
0895                 clr_cfg |= PROC_BOOT_CFG_FLAG_R5_LOCKSTEP;
0896         }
0897     }
0898 
0899     if (core->atcm_enable)
0900         set_cfg |= PROC_BOOT_CFG_FLAG_R5_ATCM_EN;
0901     else
0902         clr_cfg |= PROC_BOOT_CFG_FLAG_R5_ATCM_EN;
0903 
0904     if (core->btcm_enable)
0905         set_cfg |= PROC_BOOT_CFG_FLAG_R5_BTCM_EN;
0906     else
0907         clr_cfg |= PROC_BOOT_CFG_FLAG_R5_BTCM_EN;
0908 
0909     if (core->loczrama)
0910         set_cfg |= PROC_BOOT_CFG_FLAG_R5_TCM_RSTBASE;
0911     else
0912         clr_cfg |= PROC_BOOT_CFG_FLAG_R5_TCM_RSTBASE;
0913 
0914     if (cluster->mode == CLUSTER_MODE_LOCKSTEP) {
0915         /*
0916          * work around system firmware limitations to make sure both
0917          * cores are programmed symmetrically in LockStep. LockStep
0918          * and TEINIT config is only allowed with Core0.
0919          */
0920         list_for_each_entry(temp, &cluster->cores, elem) {
0921             ret = k3_r5_core_halt(temp);
0922             if (ret)
0923                 goto out;
0924 
0925             if (temp != core) {
0926                 clr_cfg &= ~PROC_BOOT_CFG_FLAG_R5_LOCKSTEP;
0927                 clr_cfg &= ~PROC_BOOT_CFG_FLAG_R5_TEINIT;
0928             }
0929             ret = ti_sci_proc_set_config(temp->tsp, boot_vec,
0930                              set_cfg, clr_cfg);
0931             if (ret)
0932                 goto out;
0933         }
0934 
0935         set_cfg = PROC_BOOT_CFG_FLAG_R5_LOCKSTEP;
0936         clr_cfg = 0;
0937         ret = ti_sci_proc_set_config(core->tsp, boot_vec,
0938                          set_cfg, clr_cfg);
0939     } else {
0940         ret = k3_r5_core_halt(core);
0941         if (ret)
0942             goto out;
0943 
0944         ret = ti_sci_proc_set_config(core->tsp, boot_vec,
0945                          set_cfg, clr_cfg);
0946     }
0947 
0948 out:
0949     return ret;
0950 }
0951 
0952 static int k3_r5_reserved_mem_init(struct k3_r5_rproc *kproc)
0953 {
0954     struct device *dev = kproc->dev;
0955     struct device_node *np = dev_of_node(dev);
0956     struct device_node *rmem_np;
0957     struct reserved_mem *rmem;
0958     int num_rmems;
0959     int ret, i;
0960 
0961     num_rmems = of_property_count_elems_of_size(np, "memory-region",
0962                             sizeof(phandle));
0963     if (num_rmems <= 0) {
0964         dev_err(dev, "device does not have reserved memory regions, ret = %d\n",
0965             num_rmems);
0966         return -EINVAL;
0967     }
0968     if (num_rmems < 2) {
0969         dev_err(dev, "device needs at least two memory regions to be defined, num = %d\n",
0970             num_rmems);
0971         return -EINVAL;
0972     }
0973 
0974     /* use reserved memory region 0 for vring DMA allocations */
0975     ret = of_reserved_mem_device_init_by_idx(dev, np, 0);
0976     if (ret) {
0977         dev_err(dev, "device cannot initialize DMA pool, ret = %d\n",
0978             ret);
0979         return ret;
0980     }
0981 
0982     num_rmems--;
0983     kproc->rmem = kcalloc(num_rmems, sizeof(*kproc->rmem), GFP_KERNEL);
0984     if (!kproc->rmem) {
0985         ret = -ENOMEM;
0986         goto release_rmem;
0987     }
0988 
0989     /* use remaining reserved memory regions for static carveouts */
0990     for (i = 0; i < num_rmems; i++) {
0991         rmem_np = of_parse_phandle(np, "memory-region", i + 1);
0992         if (!rmem_np) {
0993             ret = -EINVAL;
0994             goto unmap_rmem;
0995         }
0996 
0997         rmem = of_reserved_mem_lookup(rmem_np);
0998         if (!rmem) {
0999             of_node_put(rmem_np);
1000             ret = -EINVAL;
1001             goto unmap_rmem;
1002         }
1003         of_node_put(rmem_np);
1004 
1005         kproc->rmem[i].bus_addr = rmem->base;
1006         /*
1007          * R5Fs do not have an MMU, but have a Region Address Translator
1008          * (RAT) module that provides a fixed entry translation between
1009          * the 32-bit processor addresses to 64-bit bus addresses. The
1010          * RAT is programmable only by the R5F cores. Support for RAT
1011          * is currently not supported, so 64-bit address regions are not
1012          * supported. The absence of MMUs implies that the R5F device
1013          * addresses/supported memory regions are restricted to 32-bit
1014          * bus addresses, and are identical
1015          */
1016         kproc->rmem[i].dev_addr = (u32)rmem->base;
1017         kproc->rmem[i].size = rmem->size;
1018         kproc->rmem[i].cpu_addr = ioremap_wc(rmem->base, rmem->size);
1019         if (!kproc->rmem[i].cpu_addr) {
1020             dev_err(dev, "failed to map reserved memory#%d at %pa of size %pa\n",
1021                 i + 1, &rmem->base, &rmem->size);
1022             ret = -ENOMEM;
1023             goto unmap_rmem;
1024         }
1025 
1026         dev_dbg(dev, "reserved memory%d: bus addr %pa size 0x%zx va %pK da 0x%x\n",
1027             i + 1, &kproc->rmem[i].bus_addr,
1028             kproc->rmem[i].size, kproc->rmem[i].cpu_addr,
1029             kproc->rmem[i].dev_addr);
1030     }
1031     kproc->num_rmems = num_rmems;
1032 
1033     return 0;
1034 
1035 unmap_rmem:
1036     for (i--; i >= 0; i--)
1037         iounmap(kproc->rmem[i].cpu_addr);
1038     kfree(kproc->rmem);
1039 release_rmem:
1040     of_reserved_mem_device_release(dev);
1041     return ret;
1042 }
1043 
1044 static void k3_r5_reserved_mem_exit(struct k3_r5_rproc *kproc)
1045 {
1046     int i;
1047 
1048     for (i = 0; i < kproc->num_rmems; i++)
1049         iounmap(kproc->rmem[i].cpu_addr);
1050     kfree(kproc->rmem);
1051 
1052     of_reserved_mem_device_release(kproc->dev);
1053 }
1054 
1055 /*
1056  * Each R5F core within a typical R5FSS instance has a total of 64 KB of TCMs,
1057  * split equally into two 32 KB banks between ATCM and BTCM. The TCMs from both
1058  * cores are usable in Split-mode, but only the Core0 TCMs can be used in
1059  * LockStep-mode. The newer revisions of the R5FSS IP maximizes these TCMs by
1060  * leveraging the Core1 TCMs as well in certain modes where they would have
1061  * otherwise been unusable (Eg: LockStep-mode on J7200 SoCs, Single-CPU mode on
1062  * AM64x SoCs). This is done by making a Core1 TCM visible immediately after the
1063  * corresponding Core0 TCM. The SoC memory map uses the larger 64 KB sizes for
1064  * the Core0 TCMs, and the dts representation reflects this increased size on
1065  * supported SoCs. The Core0 TCM sizes therefore have to be adjusted to only
1066  * half the original size in Split mode.
1067  */
1068 static void k3_r5_adjust_tcm_sizes(struct k3_r5_rproc *kproc)
1069 {
1070     struct k3_r5_cluster *cluster = kproc->cluster;
1071     struct k3_r5_core *core = kproc->core;
1072     struct device *cdev = core->dev;
1073     struct k3_r5_core *core0;
1074 
1075     if (cluster->mode == CLUSTER_MODE_LOCKSTEP ||
1076         cluster->mode == CLUSTER_MODE_SINGLECPU ||
1077         !cluster->soc_data->tcm_is_double)
1078         return;
1079 
1080     core0 = list_first_entry(&cluster->cores, struct k3_r5_core, elem);
1081     if (core == core0) {
1082         WARN_ON(core->mem[0].size != SZ_64K);
1083         WARN_ON(core->mem[1].size != SZ_64K);
1084 
1085         core->mem[0].size /= 2;
1086         core->mem[1].size /= 2;
1087 
1088         dev_dbg(cdev, "adjusted TCM sizes, ATCM = 0x%zx BTCM = 0x%zx\n",
1089             core->mem[0].size, core->mem[1].size);
1090     }
1091 }
1092 
1093 /*
1094  * This function checks and configures a R5F core for IPC-only or remoteproc
1095  * mode. The driver is configured to be in IPC-only mode for a R5F core when
1096  * the core has been loaded and started by a bootloader. The IPC-only mode is
1097  * detected by querying the System Firmware for reset, power on and halt status
1098  * and ensuring that the core is running. Any incomplete steps at bootloader
1099  * are validated and errored out.
1100  *
1101  * In IPC-only mode, the driver state flags for ATCM, BTCM and LOCZRAMA settings
1102  * and cluster mode parsed originally from kernel DT are updated to reflect the
1103  * actual values configured by bootloader. The driver internal device memory
1104  * addresses for TCMs are also updated.
1105  */
1106 static int k3_r5_rproc_configure_mode(struct k3_r5_rproc *kproc)
1107 {
1108     struct k3_r5_cluster *cluster = kproc->cluster;
1109     struct k3_r5_core *core = kproc->core;
1110     struct device *cdev = core->dev;
1111     bool r_state = false, c_state = false;
1112     u32 ctrl = 0, cfg = 0, stat = 0, halted = 0;
1113     u64 boot_vec = 0;
1114     u32 atcm_enable, btcm_enable, loczrama;
1115     struct k3_r5_core *core0;
1116     enum cluster_mode mode;
1117     int ret;
1118 
1119     core0 = list_first_entry(&cluster->cores, struct k3_r5_core, elem);
1120 
1121     ret = core->ti_sci->ops.dev_ops.is_on(core->ti_sci, core->ti_sci_id,
1122                           &r_state, &c_state);
1123     if (ret) {
1124         dev_err(cdev, "failed to get initial state, mode cannot be determined, ret = %d\n",
1125             ret);
1126         return ret;
1127     }
1128     if (r_state != c_state) {
1129         dev_warn(cdev, "R5F core may have been powered on by a different host, programmed state (%d) != actual state (%d)\n",
1130              r_state, c_state);
1131     }
1132 
1133     ret = reset_control_status(core->reset);
1134     if (ret < 0) {
1135         dev_err(cdev, "failed to get initial local reset status, ret = %d\n",
1136             ret);
1137         return ret;
1138     }
1139 
1140     ret = ti_sci_proc_get_status(core->tsp, &boot_vec, &cfg, &ctrl,
1141                      &stat);
1142     if (ret < 0) {
1143         dev_err(cdev, "failed to get initial processor status, ret = %d\n",
1144             ret);
1145         return ret;
1146     }
1147     atcm_enable = cfg & PROC_BOOT_CFG_FLAG_R5_ATCM_EN ?  1 : 0;
1148     btcm_enable = cfg & PROC_BOOT_CFG_FLAG_R5_BTCM_EN ?  1 : 0;
1149     loczrama = cfg & PROC_BOOT_CFG_FLAG_R5_TCM_RSTBASE ?  1 : 0;
1150     if (cluster->soc_data->single_cpu_mode) {
1151         mode = cfg & PROC_BOOT_CFG_FLAG_R5_SINGLE_CORE ?
1152                 CLUSTER_MODE_SINGLECPU : CLUSTER_MODE_SPLIT;
1153     } else {
1154         mode = cfg & PROC_BOOT_CFG_FLAG_R5_LOCKSTEP ?
1155                 CLUSTER_MODE_LOCKSTEP : CLUSTER_MODE_SPLIT;
1156     }
1157     halted = ctrl & PROC_BOOT_CTRL_FLAG_R5_CORE_HALT;
1158 
1159     /*
1160      * IPC-only mode detection requires both local and module resets to
1161      * be deasserted and R5F core to be unhalted. Local reset status is
1162      * irrelevant if module reset is asserted (POR value has local reset
1163      * deasserted), and is deemed as remoteproc mode
1164      */
1165     if (c_state && !ret && !halted) {
1166         dev_info(cdev, "configured R5F for IPC-only mode\n");
1167         kproc->rproc->state = RPROC_DETACHED;
1168         ret = 1;
1169         /* override rproc ops with only required IPC-only mode ops */
1170         kproc->rproc->ops->prepare = NULL;
1171         kproc->rproc->ops->unprepare = NULL;
1172         kproc->rproc->ops->start = NULL;
1173         kproc->rproc->ops->stop = NULL;
1174         kproc->rproc->ops->attach = k3_r5_rproc_attach;
1175         kproc->rproc->ops->detach = k3_r5_rproc_detach;
1176         kproc->rproc->ops->get_loaded_rsc_table =
1177                         k3_r5_get_loaded_rsc_table;
1178     } else if (!c_state) {
1179         dev_info(cdev, "configured R5F for remoteproc mode\n");
1180         ret = 0;
1181     } else {
1182         dev_err(cdev, "mismatched mode: local_reset = %s, module_reset = %s, core_state = %s\n",
1183             !ret ? "deasserted" : "asserted",
1184             c_state ? "deasserted" : "asserted",
1185             halted ? "halted" : "unhalted");
1186         ret = -EINVAL;
1187     }
1188 
1189     /* fixup TCMs, cluster & core flags to actual values in IPC-only mode */
1190     if (ret > 0) {
1191         if (core == core0)
1192             cluster->mode = mode;
1193         core->atcm_enable = atcm_enable;
1194         core->btcm_enable = btcm_enable;
1195         core->loczrama = loczrama;
1196         core->mem[0].dev_addr = loczrama ? 0 : K3_R5_TCM_DEV_ADDR;
1197         core->mem[1].dev_addr = loczrama ? K3_R5_TCM_DEV_ADDR : 0;
1198     }
1199 
1200     return ret;
1201 }
1202 
1203 static int k3_r5_cluster_rproc_init(struct platform_device *pdev)
1204 {
1205     struct k3_r5_cluster *cluster = platform_get_drvdata(pdev);
1206     struct device *dev = &pdev->dev;
1207     struct k3_r5_rproc *kproc;
1208     struct k3_r5_core *core, *core1;
1209     struct device *cdev;
1210     const char *fw_name;
1211     struct rproc *rproc;
1212     int ret, ret1;
1213 
1214     core1 = list_last_entry(&cluster->cores, struct k3_r5_core, elem);
1215     list_for_each_entry(core, &cluster->cores, elem) {
1216         cdev = core->dev;
1217         ret = rproc_of_parse_firmware(cdev, 0, &fw_name);
1218         if (ret) {
1219             dev_err(dev, "failed to parse firmware-name property, ret = %d\n",
1220                 ret);
1221             goto out;
1222         }
1223 
1224         rproc = rproc_alloc(cdev, dev_name(cdev), &k3_r5_rproc_ops,
1225                     fw_name, sizeof(*kproc));
1226         if (!rproc) {
1227             ret = -ENOMEM;
1228             goto out;
1229         }
1230 
1231         /* K3 R5s have a Region Address Translator (RAT) but no MMU */
1232         rproc->has_iommu = false;
1233         /* error recovery is not supported at present */
1234         rproc->recovery_disabled = true;
1235 
1236         kproc = rproc->priv;
1237         kproc->cluster = cluster;
1238         kproc->core = core;
1239         kproc->dev = cdev;
1240         kproc->rproc = rproc;
1241         core->rproc = rproc;
1242 
1243         ret = k3_r5_rproc_configure_mode(kproc);
1244         if (ret < 0)
1245             goto err_config;
1246         if (ret)
1247             goto init_rmem;
1248 
1249         ret = k3_r5_rproc_configure(kproc);
1250         if (ret) {
1251             dev_err(dev, "initial configure failed, ret = %d\n",
1252                 ret);
1253             goto err_config;
1254         }
1255 
1256 init_rmem:
1257         k3_r5_adjust_tcm_sizes(kproc);
1258 
1259         ret = k3_r5_reserved_mem_init(kproc);
1260         if (ret) {
1261             dev_err(dev, "reserved memory init failed, ret = %d\n",
1262                 ret);
1263             goto err_config;
1264         }
1265 
1266         ret = rproc_add(rproc);
1267         if (ret) {
1268             dev_err(dev, "rproc_add failed, ret = %d\n", ret);
1269             goto err_add;
1270         }
1271 
1272         /* create only one rproc in lockstep mode or single-cpu mode */
1273         if (cluster->mode == CLUSTER_MODE_LOCKSTEP ||
1274             cluster->mode == CLUSTER_MODE_SINGLECPU)
1275             break;
1276     }
1277 
1278     return 0;
1279 
1280 err_split:
1281     if (rproc->state == RPROC_ATTACHED) {
1282         ret1 = rproc_detach(rproc);
1283         if (ret1) {
1284             dev_err(kproc->dev, "failed to detach rproc, ret = %d\n",
1285                 ret1);
1286             return ret1;
1287         }
1288     }
1289 
1290     rproc_del(rproc);
1291 err_add:
1292     k3_r5_reserved_mem_exit(kproc);
1293 err_config:
1294     rproc_free(rproc);
1295     core->rproc = NULL;
1296 out:
1297     /* undo core0 upon any failures on core1 in split-mode */
1298     if (cluster->mode == CLUSTER_MODE_SPLIT && core == core1) {
1299         core = list_prev_entry(core, elem);
1300         rproc = core->rproc;
1301         kproc = rproc->priv;
1302         goto err_split;
1303     }
1304     return ret;
1305 }
1306 
1307 static void k3_r5_cluster_rproc_exit(void *data)
1308 {
1309     struct k3_r5_cluster *cluster = platform_get_drvdata(data);
1310     struct k3_r5_rproc *kproc;
1311     struct k3_r5_core *core;
1312     struct rproc *rproc;
1313     int ret;
1314 
1315     /*
1316      * lockstep mode and single-cpu modes have only one rproc associated
1317      * with first core, whereas split-mode has two rprocs associated with
1318      * each core, and requires that core1 be powered down first
1319      */
1320     core = (cluster->mode == CLUSTER_MODE_LOCKSTEP ||
1321         cluster->mode == CLUSTER_MODE_SINGLECPU) ?
1322         list_first_entry(&cluster->cores, struct k3_r5_core, elem) :
1323         list_last_entry(&cluster->cores, struct k3_r5_core, elem);
1324 
1325     list_for_each_entry_from_reverse(core, &cluster->cores, elem) {
1326         rproc = core->rproc;
1327         kproc = rproc->priv;
1328 
1329         if (rproc->state == RPROC_ATTACHED) {
1330             ret = rproc_detach(rproc);
1331             if (ret) {
1332                 dev_err(kproc->dev, "failed to detach rproc, ret = %d\n", ret);
1333                 return;
1334             }
1335         }
1336 
1337         rproc_del(rproc);
1338 
1339         k3_r5_reserved_mem_exit(kproc);
1340 
1341         rproc_free(rproc);
1342         core->rproc = NULL;
1343     }
1344 }
1345 
1346 static int k3_r5_core_of_get_internal_memories(struct platform_device *pdev,
1347                            struct k3_r5_core *core)
1348 {
1349     static const char * const mem_names[] = {"atcm", "btcm"};
1350     struct device *dev = &pdev->dev;
1351     struct resource *res;
1352     int num_mems;
1353     int i;
1354 
1355     num_mems = ARRAY_SIZE(mem_names);
1356     core->mem = devm_kcalloc(dev, num_mems, sizeof(*core->mem), GFP_KERNEL);
1357     if (!core->mem)
1358         return -ENOMEM;
1359 
1360     for (i = 0; i < num_mems; i++) {
1361         res = platform_get_resource_byname(pdev, IORESOURCE_MEM,
1362                            mem_names[i]);
1363         if (!res) {
1364             dev_err(dev, "found no memory resource for %s\n",
1365                 mem_names[i]);
1366             return -EINVAL;
1367         }
1368         if (!devm_request_mem_region(dev, res->start,
1369                          resource_size(res),
1370                          dev_name(dev))) {
1371             dev_err(dev, "could not request %s region for resource\n",
1372                 mem_names[i]);
1373             return -EBUSY;
1374         }
1375 
1376         /*
1377          * TCMs are designed in general to support RAM-like backing
1378          * memories. So, map these as Normal Non-Cached memories. This
1379          * also avoids/fixes any potential alignment faults due to
1380          * unaligned data accesses when using memcpy() or memset()
1381          * functions (normally seen with device type memory).
1382          */
1383         core->mem[i].cpu_addr = devm_ioremap_wc(dev, res->start,
1384                             resource_size(res));
1385         if (!core->mem[i].cpu_addr) {
1386             dev_err(dev, "failed to map %s memory\n", mem_names[i]);
1387             return -ENOMEM;
1388         }
1389         core->mem[i].bus_addr = res->start;
1390 
1391         /*
1392          * TODO:
1393          * The R5F cores can place ATCM & BTCM anywhere in its address
1394          * based on the corresponding Region Registers in the System
1395          * Control coprocessor. For now, place ATCM and BTCM at
1396          * addresses 0 and 0x41010000 (same as the bus address on AM65x
1397          * SoCs) based on loczrama setting
1398          */
1399         if (!strcmp(mem_names[i], "atcm")) {
1400             core->mem[i].dev_addr = core->loczrama ?
1401                             0 : K3_R5_TCM_DEV_ADDR;
1402         } else {
1403             core->mem[i].dev_addr = core->loczrama ?
1404                             K3_R5_TCM_DEV_ADDR : 0;
1405         }
1406         core->mem[i].size = resource_size(res);
1407 
1408         dev_dbg(dev, "memory %5s: bus addr %pa size 0x%zx va %pK da 0x%x\n",
1409             mem_names[i], &core->mem[i].bus_addr,
1410             core->mem[i].size, core->mem[i].cpu_addr,
1411             core->mem[i].dev_addr);
1412     }
1413     core->num_mems = num_mems;
1414 
1415     return 0;
1416 }
1417 
1418 static int k3_r5_core_of_get_sram_memories(struct platform_device *pdev,
1419                        struct k3_r5_core *core)
1420 {
1421     struct device_node *np = pdev->dev.of_node;
1422     struct device *dev = &pdev->dev;
1423     struct device_node *sram_np;
1424     struct resource res;
1425     int num_sram;
1426     int i, ret;
1427 
1428     num_sram = of_property_count_elems_of_size(np, "sram", sizeof(phandle));
1429     if (num_sram <= 0) {
1430         dev_dbg(dev, "device does not use reserved on-chip memories, num_sram = %d\n",
1431             num_sram);
1432         return 0;
1433     }
1434 
1435     core->sram = devm_kcalloc(dev, num_sram, sizeof(*core->sram), GFP_KERNEL);
1436     if (!core->sram)
1437         return -ENOMEM;
1438 
1439     for (i = 0; i < num_sram; i++) {
1440         sram_np = of_parse_phandle(np, "sram", i);
1441         if (!sram_np)
1442             return -EINVAL;
1443 
1444         if (!of_device_is_available(sram_np)) {
1445             of_node_put(sram_np);
1446             return -EINVAL;
1447         }
1448 
1449         ret = of_address_to_resource(sram_np, 0, &res);
1450         of_node_put(sram_np);
1451         if (ret)
1452             return -EINVAL;
1453 
1454         core->sram[i].bus_addr = res.start;
1455         core->sram[i].dev_addr = res.start;
1456         core->sram[i].size = resource_size(&res);
1457         core->sram[i].cpu_addr = devm_ioremap_wc(dev, res.start,
1458                              resource_size(&res));
1459         if (!core->sram[i].cpu_addr) {
1460             dev_err(dev, "failed to parse and map sram%d memory at %pad\n",
1461                 i, &res.start);
1462             return -ENOMEM;
1463         }
1464 
1465         dev_dbg(dev, "memory sram%d: bus addr %pa size 0x%zx va %pK da 0x%x\n",
1466             i, &core->sram[i].bus_addr,
1467             core->sram[i].size, core->sram[i].cpu_addr,
1468             core->sram[i].dev_addr);
1469     }
1470     core->num_sram = num_sram;
1471 
1472     return 0;
1473 }
1474 
1475 static
1476 struct ti_sci_proc *k3_r5_core_of_get_tsp(struct device *dev,
1477                       const struct ti_sci_handle *sci)
1478 {
1479     struct ti_sci_proc *tsp;
1480     u32 temp[2];
1481     int ret;
1482 
1483     ret = of_property_read_u32_array(dev_of_node(dev), "ti,sci-proc-ids",
1484                      temp, 2);
1485     if (ret < 0)
1486         return ERR_PTR(ret);
1487 
1488     tsp = devm_kzalloc(dev, sizeof(*tsp), GFP_KERNEL);
1489     if (!tsp)
1490         return ERR_PTR(-ENOMEM);
1491 
1492     tsp->dev = dev;
1493     tsp->sci = sci;
1494     tsp->ops = &sci->ops.proc_ops;
1495     tsp->proc_id = temp[0];
1496     tsp->host_id = temp[1];
1497 
1498     return tsp;
1499 }
1500 
1501 static int k3_r5_core_of_init(struct platform_device *pdev)
1502 {
1503     struct device *dev = &pdev->dev;
1504     struct device_node *np = dev_of_node(dev);
1505     struct k3_r5_core *core;
1506     int ret;
1507 
1508     if (!devres_open_group(dev, k3_r5_core_of_init, GFP_KERNEL))
1509         return -ENOMEM;
1510 
1511     core = devm_kzalloc(dev, sizeof(*core), GFP_KERNEL);
1512     if (!core) {
1513         ret = -ENOMEM;
1514         goto err;
1515     }
1516 
1517     core->dev = dev;
1518     /*
1519      * Use SoC Power-on-Reset values as default if no DT properties are
1520      * used to dictate the TCM configurations
1521      */
1522     core->atcm_enable = 0;
1523     core->btcm_enable = 1;
1524     core->loczrama = 1;
1525 
1526     ret = of_property_read_u32(np, "ti,atcm-enable", &core->atcm_enable);
1527     if (ret < 0 && ret != -EINVAL) {
1528         dev_err(dev, "invalid format for ti,atcm-enable, ret = %d\n",
1529             ret);
1530         goto err;
1531     }
1532 
1533     ret = of_property_read_u32(np, "ti,btcm-enable", &core->btcm_enable);
1534     if (ret < 0 && ret != -EINVAL) {
1535         dev_err(dev, "invalid format for ti,btcm-enable, ret = %d\n",
1536             ret);
1537         goto err;
1538     }
1539 
1540     ret = of_property_read_u32(np, "ti,loczrama", &core->loczrama);
1541     if (ret < 0 && ret != -EINVAL) {
1542         dev_err(dev, "invalid format for ti,loczrama, ret = %d\n", ret);
1543         goto err;
1544     }
1545 
1546     core->ti_sci = devm_ti_sci_get_by_phandle(dev, "ti,sci");
1547     if (IS_ERR(core->ti_sci)) {
1548         ret = PTR_ERR(core->ti_sci);
1549         if (ret != -EPROBE_DEFER) {
1550             dev_err(dev, "failed to get ti-sci handle, ret = %d\n",
1551                 ret);
1552         }
1553         core->ti_sci = NULL;
1554         goto err;
1555     }
1556 
1557     ret = of_property_read_u32(np, "ti,sci-dev-id", &core->ti_sci_id);
1558     if (ret) {
1559         dev_err(dev, "missing 'ti,sci-dev-id' property\n");
1560         goto err;
1561     }
1562 
1563     core->reset = devm_reset_control_get_exclusive(dev, NULL);
1564     if (IS_ERR_OR_NULL(core->reset)) {
1565         ret = PTR_ERR_OR_ZERO(core->reset);
1566         if (!ret)
1567             ret = -ENODEV;
1568         if (ret != -EPROBE_DEFER) {
1569             dev_err(dev, "failed to get reset handle, ret = %d\n",
1570                 ret);
1571         }
1572         goto err;
1573     }
1574 
1575     core->tsp = k3_r5_core_of_get_tsp(dev, core->ti_sci);
1576     if (IS_ERR(core->tsp)) {
1577         ret = PTR_ERR(core->tsp);
1578         dev_err(dev, "failed to construct ti-sci proc control, ret = %d\n",
1579             ret);
1580         goto err;
1581     }
1582 
1583     ret = k3_r5_core_of_get_internal_memories(pdev, core);
1584     if (ret) {
1585         dev_err(dev, "failed to get internal memories, ret = %d\n",
1586             ret);
1587         goto err;
1588     }
1589 
1590     ret = k3_r5_core_of_get_sram_memories(pdev, core);
1591     if (ret) {
1592         dev_err(dev, "failed to get sram memories, ret = %d\n", ret);
1593         goto err;
1594     }
1595 
1596     ret = ti_sci_proc_request(core->tsp);
1597     if (ret < 0) {
1598         dev_err(dev, "ti_sci_proc_request failed, ret = %d\n", ret);
1599         goto err;
1600     }
1601 
1602     platform_set_drvdata(pdev, core);
1603     devres_close_group(dev, k3_r5_core_of_init);
1604 
1605     return 0;
1606 
1607 err:
1608     devres_release_group(dev, k3_r5_core_of_init);
1609     return ret;
1610 }
1611 
1612 /*
1613  * free the resources explicitly since driver model is not being used
1614  * for the child R5F devices
1615  */
1616 static void k3_r5_core_of_exit(struct platform_device *pdev)
1617 {
1618     struct k3_r5_core *core = platform_get_drvdata(pdev);
1619     struct device *dev = &pdev->dev;
1620     int ret;
1621 
1622     ret = ti_sci_proc_release(core->tsp);
1623     if (ret)
1624         dev_err(dev, "failed to release proc, ret = %d\n", ret);
1625 
1626     platform_set_drvdata(pdev, NULL);
1627     devres_release_group(dev, k3_r5_core_of_init);
1628 }
1629 
1630 static void k3_r5_cluster_of_exit(void *data)
1631 {
1632     struct k3_r5_cluster *cluster = platform_get_drvdata(data);
1633     struct platform_device *cpdev;
1634     struct k3_r5_core *core, *temp;
1635 
1636     list_for_each_entry_safe_reverse(core, temp, &cluster->cores, elem) {
1637         list_del(&core->elem);
1638         cpdev = to_platform_device(core->dev);
1639         k3_r5_core_of_exit(cpdev);
1640     }
1641 }
1642 
1643 static int k3_r5_cluster_of_init(struct platform_device *pdev)
1644 {
1645     struct k3_r5_cluster *cluster = platform_get_drvdata(pdev);
1646     struct device *dev = &pdev->dev;
1647     struct device_node *np = dev_of_node(dev);
1648     struct platform_device *cpdev;
1649     struct device_node *child;
1650     struct k3_r5_core *core;
1651     int ret;
1652 
1653     for_each_available_child_of_node(np, child) {
1654         cpdev = of_find_device_by_node(child);
1655         if (!cpdev) {
1656             ret = -ENODEV;
1657             dev_err(dev, "could not get R5 core platform device\n");
1658             of_node_put(child);
1659             goto fail;
1660         }
1661 
1662         ret = k3_r5_core_of_init(cpdev);
1663         if (ret) {
1664             dev_err(dev, "k3_r5_core_of_init failed, ret = %d\n",
1665                 ret);
1666             put_device(&cpdev->dev);
1667             of_node_put(child);
1668             goto fail;
1669         }
1670 
1671         core = platform_get_drvdata(cpdev);
1672         put_device(&cpdev->dev);
1673         list_add_tail(&core->elem, &cluster->cores);
1674     }
1675 
1676     return 0;
1677 
1678 fail:
1679     k3_r5_cluster_of_exit(pdev);
1680     return ret;
1681 }
1682 
1683 static int k3_r5_probe(struct platform_device *pdev)
1684 {
1685     struct device *dev = &pdev->dev;
1686     struct device_node *np = dev_of_node(dev);
1687     struct k3_r5_cluster *cluster;
1688     const struct k3_r5_soc_data *data;
1689     int ret;
1690     int num_cores;
1691 
1692     data = of_device_get_match_data(&pdev->dev);
1693     if (!data) {
1694         dev_err(dev, "SoC-specific data is not defined\n");
1695         return -ENODEV;
1696     }
1697 
1698     cluster = devm_kzalloc(dev, sizeof(*cluster), GFP_KERNEL);
1699     if (!cluster)
1700         return -ENOMEM;
1701 
1702     cluster->dev = dev;
1703     /*
1704      * default to most common efuse configurations - Split-mode on AM64x
1705      * and LockStep-mode on all others
1706      */
1707     cluster->mode = data->single_cpu_mode ?
1708                 CLUSTER_MODE_SPLIT : CLUSTER_MODE_LOCKSTEP;
1709     cluster->soc_data = data;
1710     INIT_LIST_HEAD(&cluster->cores);
1711 
1712     ret = of_property_read_u32(np, "ti,cluster-mode", &cluster->mode);
1713     if (ret < 0 && ret != -EINVAL) {
1714         dev_err(dev, "invalid format for ti,cluster-mode, ret = %d\n",
1715             ret);
1716         return ret;
1717     }
1718 
1719     num_cores = of_get_available_child_count(np);
1720     if (num_cores != 2) {
1721         dev_err(dev, "MCU cluster requires both R5F cores to be enabled, num_cores = %d\n",
1722             num_cores);
1723         return -ENODEV;
1724     }
1725 
1726     platform_set_drvdata(pdev, cluster);
1727 
1728     ret = devm_of_platform_populate(dev);
1729     if (ret) {
1730         dev_err(dev, "devm_of_platform_populate failed, ret = %d\n",
1731             ret);
1732         return ret;
1733     }
1734 
1735     ret = k3_r5_cluster_of_init(pdev);
1736     if (ret) {
1737         dev_err(dev, "k3_r5_cluster_of_init failed, ret = %d\n", ret);
1738         return ret;
1739     }
1740 
1741     ret = devm_add_action_or_reset(dev, k3_r5_cluster_of_exit, pdev);
1742     if (ret)
1743         return ret;
1744 
1745     ret = k3_r5_cluster_rproc_init(pdev);
1746     if (ret) {
1747         dev_err(dev, "k3_r5_cluster_rproc_init failed, ret = %d\n",
1748             ret);
1749         return ret;
1750     }
1751 
1752     ret = devm_add_action_or_reset(dev, k3_r5_cluster_rproc_exit, pdev);
1753     if (ret)
1754         return ret;
1755 
1756     return 0;
1757 }
1758 
1759 static const struct k3_r5_soc_data am65_j721e_soc_data = {
1760     .tcm_is_double = false,
1761     .tcm_ecc_autoinit = false,
1762     .single_cpu_mode = false,
1763 };
1764 
1765 static const struct k3_r5_soc_data j7200_j721s2_soc_data = {
1766     .tcm_is_double = true,
1767     .tcm_ecc_autoinit = true,
1768     .single_cpu_mode = false,
1769 };
1770 
1771 static const struct k3_r5_soc_data am64_soc_data = {
1772     .tcm_is_double = true,
1773     .tcm_ecc_autoinit = true,
1774     .single_cpu_mode = true,
1775 };
1776 
1777 static const struct of_device_id k3_r5_of_match[] = {
1778     { .compatible = "ti,am654-r5fss", .data = &am65_j721e_soc_data, },
1779     { .compatible = "ti,j721e-r5fss", .data = &am65_j721e_soc_data, },
1780     { .compatible = "ti,j7200-r5fss", .data = &j7200_j721s2_soc_data, },
1781     { .compatible = "ti,am64-r5fss",  .data = &am64_soc_data, },
1782     { .compatible = "ti,j721s2-r5fss",  .data = &j7200_j721s2_soc_data, },
1783     { /* sentinel */ },
1784 };
1785 MODULE_DEVICE_TABLE(of, k3_r5_of_match);
1786 
1787 static struct platform_driver k3_r5_rproc_driver = {
1788     .probe = k3_r5_probe,
1789     .driver = {
1790         .name = "k3_r5_rproc",
1791         .of_match_table = k3_r5_of_match,
1792     },
1793 };
1794 
1795 module_platform_driver(k3_r5_rproc_driver);
1796 
1797 MODULE_LICENSE("GPL v2");
1798 MODULE_DESCRIPTION("TI K3 R5F remote processor driver");
1799 MODULE_AUTHOR("Suman Anna <s-anna@ti.com>");