Lines Matching +full:reset +full:- +full:mode
1 // SPDX-License-Identifier: GPL-2.0-only
5 * Copyright (C) 2017-2022 Texas Instruments Incorporated - https://www.ti.com/
6 * Suman Anna <s-anna@ti.com>
9 #include <linux/dma-mapping.h>
19 #include <linux/omap-mailbox.h>
23 #include <linux/reset.h>
33 /* R5 TI-SCI Processor Configuration Flags */
47 /* R5 TI-SCI Processor Control Flags */
50 /* R5 TI-SCI Processor Status Flags */
59 * struct k3_r5_mem - internal memory structure
73 * All cluster mode values are not applicable on all SoCs. The following
75 * Split mode : AM65x, J721E, J7200 and AM64x SoCs
76 * LockStep mode : AM65x, J721E and J7200 SoCs
77 * Single-CPU mode : AM64x SoCs only
78 * Single-Core mode : AM62x, AM62A SoCs
88 * struct k3_r5_soc_data - match data to handle SoC variations
90 * @tcm_ecc_autoinit: flag to denote the auto-initialization of TCMs for ECC
91 * @single_cpu_mode: flag to denote if SoC/IP supports Single-CPU mode
102 * struct k3_r5_cluster - K3 R5F Cluster structure
104 * @mode: Mode to configure the Cluster - Split or LockStep
107 * @soc_data: SoC-specific feature data for a R5FSS
111 enum cluster_mode mode; member
118 * struct k3_r5_core - K3 R5 core structure
123 * @sram: on-chip SRAM memory regions data
125 * @num_sram: number of on-chip SRAM memory regions
126 * @reset: reset control handle
127 * @tsp: TI-SCI processor control handle
128 * @ti_sci: TI-SCI handle
129 * @ti_sci_id: TI-SCI device identifier
133 * @released_from_reset: flag to signal when core is out of reset
143 struct reset_control *reset; member
154 * struct k3_r5_rproc - K3 remote processor state
176 * k3_r5_rproc_mbox_callback() - inbound mailbox message handler
185 * In addition to virtqueue indices, we also have some out-of-band values
193 struct device *dev = kproc->rproc->dev.parent; in k3_r5_rproc_mbox_callback()
194 const char *name = kproc->rproc->name; in k3_r5_rproc_mbox_callback()
198 if (kproc->rproc->state == RPROC_DETACHED) in k3_r5_rproc_mbox_callback()
218 if (msg > kproc->rproc->max_notifyid) { in k3_r5_rproc_mbox_callback()
223 if (rproc_vq_interrupt(kproc->rproc, msg) == IRQ_NONE) in k3_r5_rproc_mbox_callback()
231 struct k3_r5_rproc *kproc = rproc->priv; in k3_r5_rproc_kick()
232 struct device *dev = rproc->dev.parent; in k3_r5_rproc_kick()
237 if (kproc->rproc->state == RPROC_DETACHED) in k3_r5_rproc_kick()
241 ret = mbox_send_message(kproc->mbox, (void *)msg); in k3_r5_rproc_kick()
251 ret = reset_control_assert(core->reset); in k3_r5_split_reset()
253 dev_err(core->dev, "local-reset assert failed, ret = %d\n", in k3_r5_split_reset()
258 ret = core->ti_sci->ops.dev_ops.put_device(core->ti_sci, in k3_r5_split_reset()
259 core->ti_sci_id); in k3_r5_split_reset()
261 dev_err(core->dev, "module-reset assert failed, ret = %d\n", in k3_r5_split_reset()
263 if (reset_control_deassert(core->reset)) in k3_r5_split_reset()
264 dev_warn(core->dev, "local-reset deassert back failed\n"); in k3_r5_split_reset()
274 ret = core->ti_sci->ops.dev_ops.get_device(core->ti_sci, in k3_r5_split_release()
275 core->ti_sci_id); in k3_r5_split_release()
277 dev_err(core->dev, "module-reset deassert failed, ret = %d\n", in k3_r5_split_release()
282 ret = reset_control_deassert(core->reset); in k3_r5_split_release()
284 dev_err(core->dev, "local-reset deassert failed, ret = %d\n", in k3_r5_split_release()
286 if (core->ti_sci->ops.dev_ops.put_device(core->ti_sci, in k3_r5_split_release()
287 core->ti_sci_id)) in k3_r5_split_release()
288 dev_warn(core->dev, "module-reset assert back failed\n"); in k3_r5_split_release()
299 /* assert local reset on all applicable cores */ in k3_r5_lockstep_reset()
300 list_for_each_entry(core, &cluster->cores, elem) { in k3_r5_lockstep_reset()
301 ret = reset_control_assert(core->reset); in k3_r5_lockstep_reset()
303 dev_err(core->dev, "local-reset assert failed, ret = %d\n", in k3_r5_lockstep_reset()
311 list_for_each_entry(core, &cluster->cores, elem) { in k3_r5_lockstep_reset()
312 ret = core->ti_sci->ops.dev_ops.put_device(core->ti_sci, in k3_r5_lockstep_reset()
313 core->ti_sci_id); in k3_r5_lockstep_reset()
315 dev_err(core->dev, "module-reset assert failed, ret = %d\n", in k3_r5_lockstep_reset()
324 list_for_each_entry_continue_reverse(core, &cluster->cores, elem) { in k3_r5_lockstep_reset()
325 if (core->ti_sci->ops.dev_ops.put_device(core->ti_sci, in k3_r5_lockstep_reset()
326 core->ti_sci_id)) in k3_r5_lockstep_reset()
327 dev_warn(core->dev, "module-reset assert back failed\n"); in k3_r5_lockstep_reset()
329 core = list_last_entry(&cluster->cores, struct k3_r5_core, elem); in k3_r5_lockstep_reset()
331 list_for_each_entry_from_reverse(core, &cluster->cores, elem) { in k3_r5_lockstep_reset()
332 if (reset_control_deassert(core->reset)) in k3_r5_lockstep_reset()
333 dev_warn(core->dev, "local-reset deassert back failed\n"); in k3_r5_lockstep_reset()
345 list_for_each_entry_reverse(core, &cluster->cores, elem) { in k3_r5_lockstep_release()
346 ret = core->ti_sci->ops.dev_ops.get_device(core->ti_sci, in k3_r5_lockstep_release()
347 core->ti_sci_id); in k3_r5_lockstep_release()
349 dev_err(core->dev, "module-reset deassert failed, ret = %d\n", in k3_r5_lockstep_release()
356 /* deassert local reset on all applicable cores */ in k3_r5_lockstep_release()
357 list_for_each_entry_reverse(core, &cluster->cores, elem) { in k3_r5_lockstep_release()
358 ret = reset_control_deassert(core->reset); in k3_r5_lockstep_release()
360 dev_err(core->dev, "module-reset deassert failed, ret = %d\n", in k3_r5_lockstep_release()
369 list_for_each_entry_continue(core, &cluster->cores, elem) { in k3_r5_lockstep_release()
370 if (reset_control_assert(core->reset)) in k3_r5_lockstep_release()
371 dev_warn(core->dev, "local-reset assert back failed\n"); in k3_r5_lockstep_release()
373 core = list_first_entry(&cluster->cores, struct k3_r5_core, elem); in k3_r5_lockstep_release()
375 list_for_each_entry_from(core, &cluster->cores, elem) { in k3_r5_lockstep_release()
376 if (core->ti_sci->ops.dev_ops.put_device(core->ti_sci, in k3_r5_lockstep_release()
377 core->ti_sci_id)) in k3_r5_lockstep_release()
378 dev_warn(core->dev, "module-reset assert back failed\n"); in k3_r5_lockstep_release()
386 return ti_sci_proc_set_control(core->tsp, in k3_r5_core_halt()
392 return ti_sci_proc_set_control(core->tsp, in k3_r5_core_run()
398 struct k3_r5_rproc *kproc = rproc->priv; in k3_r5_rproc_request_mbox()
399 struct mbox_client *client = &kproc->client; in k3_r5_rproc_request_mbox()
400 struct device *dev = kproc->dev; in k3_r5_rproc_request_mbox()
403 client->dev = dev; in k3_r5_rproc_request_mbox()
404 client->tx_done = NULL; in k3_r5_rproc_request_mbox()
405 client->rx_callback = k3_r5_rproc_mbox_callback; in k3_r5_rproc_request_mbox()
406 client->tx_block = false; in k3_r5_rproc_request_mbox()
407 client->knows_txdone = false; in k3_r5_rproc_request_mbox()
409 kproc->mbox = mbox_request_channel(client, 0); in k3_r5_rproc_request_mbox()
410 if (IS_ERR(kproc->mbox)) in k3_r5_rproc_request_mbox()
411 return dev_err_probe(dev, PTR_ERR(kproc->mbox), in k3_r5_rproc_request_mbox()
415 * Ping the remote processor, this is only for sanity-sake for now; in k3_r5_rproc_request_mbox()
421 ret = mbox_send_message(kproc->mbox, (void *)RP_MBOX_ECHO_REQUEST); in k3_r5_rproc_request_mbox()
424 mbox_free_channel(kproc->mbox); in k3_r5_rproc_request_mbox()
432 * The R5F cores have controls for both a reset and a halt/run. The code
433 * execution from DDR requires the initial boot-strapping code to be run
439 * The Single-CPU mode on applicable SoCs (eg: AM64x) only uses Core0 to
443 * cluster in this mode. The function uses the same reset logic as LockStep
444 * mode for this (though the behavior is agnostic of the reset release order).
445 * This callback is invoked only in remoteproc mode.
449 struct k3_r5_rproc *kproc = rproc->priv; in k3_r5_rproc_prepare()
450 struct k3_r5_cluster *cluster = kproc->cluster; in k3_r5_rproc_prepare()
451 struct k3_r5_core *core = kproc->core; in k3_r5_rproc_prepare()
452 struct device *dev = kproc->dev; in k3_r5_rproc_prepare()
458 ret = ti_sci_proc_get_status(core->tsp, &boot_vec, &cfg, &ctrl, &stat); in k3_r5_rproc_prepare()
463 /* Re-use LockStep-mode reset logic for Single-CPU mode */ in k3_r5_rproc_prepare()
464 ret = (cluster->mode == CLUSTER_MODE_LOCKSTEP || in k3_r5_rproc_prepare()
465 cluster->mode == CLUSTER_MODE_SINGLECPU) ? in k3_r5_rproc_prepare()
474 * Newer IP revisions like on J7200 SoCs support h/w auto-initialization in k3_r5_rproc_prepare()
477 * auto-init, but account for it in case it is disabled in k3_r5_rproc_prepare()
479 if (cluster->soc_data->tcm_ecc_autoinit && !mem_init_dis) { in k3_r5_rproc_prepare()
490 memset(core->mem[0].cpu_addr, 0x00, core->mem[0].size); in k3_r5_rproc_prepare()
493 memset(core->mem[1].cpu_addr, 0x00, core->mem[1].size); in k3_r5_rproc_prepare()
502 * or Split mode). This completes the second portion of powering down the R5F
507 * The Single-CPU mode on applicable SoCs (eg: AM64x) combines the TCMs from
509 * both cores, but with only Core0 unhalted. This function re-uses the same
510 * reset assert logic as LockStep mode for this mode (though the behavior is
511 * agnostic of the reset assert order). This callback is invoked only in
512 * remoteproc mode.
516 struct k3_r5_rproc *kproc = rproc->priv; in k3_r5_rproc_unprepare()
517 struct k3_r5_cluster *cluster = kproc->cluster; in k3_r5_rproc_unprepare()
518 struct k3_r5_core *core = kproc->core; in k3_r5_rproc_unprepare()
519 struct device *dev = kproc->dev; in k3_r5_rproc_unprepare()
522 /* Re-use LockStep-mode reset logic for Single-CPU mode */ in k3_r5_rproc_unprepare()
523 ret = (cluster->mode == CLUSTER_MODE_LOCKSTEP || in k3_r5_rproc_unprepare()
524 cluster->mode == CLUSTER_MODE_SINGLECPU) ? in k3_r5_rproc_unprepare()
538 * mode requires the boot vector to be configured only for Core0, and then
539 * unhalt both the cores to start the execution - Core1 needs to be unhalted
540 * first followed by Core0. The Split-mode requires that Core0 to be maintained
544 * The Single-CPU mode on applicable SoCs (eg: AM64x) only uses Core0 to execute
546 * flow as Split-mode for this. This callback is invoked only in remoteproc
547 * mode.
551 struct k3_r5_rproc *kproc = rproc->priv; in k3_r5_rproc_start()
552 struct k3_r5_cluster *cluster = kproc->cluster; in k3_r5_rproc_start()
553 struct device *dev = kproc->dev; in k3_r5_rproc_start()
558 boot_addr = rproc->bootaddr; in k3_r5_rproc_start()
562 /* boot vector need not be programmed for Core1 in LockStep mode */ in k3_r5_rproc_start()
563 core = kproc->core; in k3_r5_rproc_start()
564 ret = ti_sci_proc_set_config(core->tsp, boot_addr, 0, 0); in k3_r5_rproc_start()
569 if (cluster->mode == CLUSTER_MODE_LOCKSTEP) { in k3_r5_rproc_start()
570 list_for_each_entry_reverse(core, &cluster->cores, elem) { in k3_r5_rproc_start()
577 core0 = list_first_entry(&cluster->cores, struct k3_r5_core, in k3_r5_rproc_start()
579 if (core != core0 && core0->rproc->state == RPROC_OFFLINE) { in k3_r5_rproc_start()
582 return -EPERM; in k3_r5_rproc_start()
589 core->released_from_reset = true; in k3_r5_rproc_start()
590 wake_up_interruptible(&cluster->core_transition); in k3_r5_rproc_start()
596 list_for_each_entry_continue(core, &cluster->cores, elem) { in k3_r5_rproc_start()
598 dev_warn(core->dev, "core halt back failed\n"); in k3_r5_rproc_start()
609 * of the start function. The LockStep mode requires each operation to be
610 * performed first on Core0 followed by Core1. The Split-mode requires that
614 * The Single-CPU mode on applicable SoCs (eg: AM64x) only uses Core0 to execute
616 * flow as Split-mode for this.
620 * deasserting the reset the subsequent time. The asserting of reset can
621 * be done here, but is preferred to be done in the .unprepare() ops - this
625 * only in remoteproc mode.
629 struct k3_r5_rproc *kproc = rproc->priv; in k3_r5_rproc_stop()
630 struct k3_r5_cluster *cluster = kproc->cluster; in k3_r5_rproc_stop()
631 struct device *dev = kproc->dev; in k3_r5_rproc_stop()
632 struct k3_r5_core *core1, *core = kproc->core; in k3_r5_rproc_stop()
636 if (cluster->mode == CLUSTER_MODE_LOCKSTEP) { in k3_r5_rproc_stop()
637 list_for_each_entry(core, &cluster->cores, elem) { in k3_r5_rproc_stop()
646 core1 = list_last_entry(&cluster->cores, struct k3_r5_core, in k3_r5_rproc_stop()
648 if (core != core1 && core1->rproc->state != RPROC_OFFLINE) { in k3_r5_rproc_stop()
651 ret = -EPERM; in k3_r5_rproc_stop()
663 list_for_each_entry_from_reverse(core, &cluster->cores, elem) { in k3_r5_rproc_stop()
665 dev_warn(core->dev, "core run back failed\n"); in k3_r5_rproc_stop()
672 * Attach to a running R5F remote processor (IPC-only mode)
676 * no need to issue any TI-SCI commands to boot the R5F cores in IPC-only mode.
677 * This callback is invoked only in IPC-only mode and exists because
683 * Detach from a running R5F remote processor (IPC-only mode)
686 * left in booted state in IPC-only mode. This callback is invoked only in
687 * IPC-only mode and exists for sanity sake.
693 * to provide the resource table for the booted R5F in IPC-only mode. The K3 R5F
694 * firmwares follow a design-by-contract approach and are expected to have the
699 * IPC-only mode.
704 struct k3_r5_rproc *kproc = rproc->priv; in k3_r5_get_loaded_rsc_table()
705 struct device *dev = kproc->dev; in k3_r5_get_loaded_rsc_table()
707 if (!kproc->rmem[0].cpu_addr) { in k3_r5_get_loaded_rsc_table()
708 dev_err(dev, "memory-region #1 does not exist, loaded rsc table can't be found"); in k3_r5_get_loaded_rsc_table()
709 return ERR_PTR(-ENOMEM); in k3_r5_get_loaded_rsc_table()
713 * NOTE: The resource table size is currently hard-coded to a maximum in k3_r5_get_loaded_rsc_table()
717 * the hard-coded value suffices to support the IPC-only mode. in k3_r5_get_loaded_rsc_table()
720 return (struct resource_table *)kproc->rmem[0].cpu_addr; in k3_r5_get_loaded_rsc_table()
733 struct k3_r5_rproc *kproc = rproc->priv; in k3_r5_rproc_da_to_va()
734 struct k3_r5_core *core = kproc->core; in k3_r5_rproc_da_to_va()
745 for (i = 0; i < core->num_mems; i++) { in k3_r5_rproc_da_to_va()
746 bus_addr = core->mem[i].bus_addr; in k3_r5_rproc_da_to_va()
747 dev_addr = core->mem[i].dev_addr; in k3_r5_rproc_da_to_va()
748 size = core->mem[i].size; in k3_r5_rproc_da_to_va()
750 /* handle R5-view addresses of TCMs */ in k3_r5_rproc_da_to_va()
752 offset = da - dev_addr; in k3_r5_rproc_da_to_va()
753 va = core->mem[i].cpu_addr + offset; in k3_r5_rproc_da_to_va()
757 /* handle SoC-view addresses of TCMs */ in k3_r5_rproc_da_to_va()
759 offset = da - bus_addr; in k3_r5_rproc_da_to_va()
760 va = core->mem[i].cpu_addr + offset; in k3_r5_rproc_da_to_va()
765 /* handle any SRAM regions using SoC-view addresses */ in k3_r5_rproc_da_to_va()
766 for (i = 0; i < core->num_sram; i++) { in k3_r5_rproc_da_to_va()
767 dev_addr = core->sram[i].dev_addr; in k3_r5_rproc_da_to_va()
768 size = core->sram[i].size; in k3_r5_rproc_da_to_va()
771 offset = da - dev_addr; in k3_r5_rproc_da_to_va()
772 va = core->sram[i].cpu_addr + offset; in k3_r5_rproc_da_to_va()
778 for (i = 0; i < kproc->num_rmems; i++) { in k3_r5_rproc_da_to_va()
779 dev_addr = kproc->rmem[i].dev_addr; in k3_r5_rproc_da_to_va()
780 size = kproc->rmem[i].size; in k3_r5_rproc_da_to_va()
783 offset = da - dev_addr; in k3_r5_rproc_da_to_va()
784 va = kproc->rmem[i].cpu_addr + offset; in k3_r5_rproc_da_to_va()
804 * Each R5FSS has a cluster-level setting for configuring the processor
805 * subsystem either in a safety/fault-tolerant LockStep mode or a performance
806 * oriented Split mode on most SoCs. A fewer SoCs support a non-safety mode
807 * as an alternate for LockStep mode that exercises only a single R5F core
808 * called Single-CPU mode. Each R5F core has a number of settings to either
814 * This function is used to pre-configure these settings for each R5F core, and
820 * once (in LockStep mode or Single-CPU modes) or twice (in Split mode). Support
821 * for LockStep-mode is dictated by an eFUSE register bit, and the config
823 * cluster mode. Another eFUSE register bit dictates if the R5F cluster only
824 * supports a Single-CPU mode. All cluster level settings like Cluster mode and
825 * TEINIT (exception handling state dictating ARM or Thumb mode) can only be set
828 * The function behavior is different based on the cluster mode. The R5F cores
829 * are configured independently as per their individual settings in Split mode.
830 * They are identically configured in LockStep mode using the primary Core0
831 * settings. However, some individual settings cannot be set in LockStep mode.
832 * This is overcome by switching to Split-mode initially and then programming
834 * LockStep mode.
838 struct k3_r5_cluster *cluster = kproc->cluster; in k3_r5_rproc_configure()
839 struct device *dev = kproc->dev; in k3_r5_rproc_configure()
848 core0 = list_first_entry(&cluster->cores, struct k3_r5_core, elem); in k3_r5_rproc_configure()
849 if (cluster->mode == CLUSTER_MODE_LOCKSTEP || in k3_r5_rproc_configure()
850 cluster->mode == CLUSTER_MODE_SINGLECPU || in k3_r5_rproc_configure()
851 cluster->mode == CLUSTER_MODE_SINGLECORE) { in k3_r5_rproc_configure()
854 core = kproc->core; in k3_r5_rproc_configure()
857 ret = ti_sci_proc_get_status(core->tsp, &boot_vec, &cfg, &ctrl, in k3_r5_rproc_configure()
868 /* Override to single CPU mode if set in status flag */ in k3_r5_rproc_configure()
869 if (single_cpu && cluster->mode == CLUSTER_MODE_SPLIT) { in k3_r5_rproc_configure()
870 dev_err(cluster->dev, "split-mode not permitted, force configuring for single-cpu mode\n"); in k3_r5_rproc_configure()
871 cluster->mode = CLUSTER_MODE_SINGLECPU; in k3_r5_rproc_configure()
874 /* Override to split mode if lockstep enable bit is not set in status flag */ in k3_r5_rproc_configure()
875 if (!lockstep_en && cluster->mode == CLUSTER_MODE_LOCKSTEP) { in k3_r5_rproc_configure()
876 dev_err(cluster->dev, "lockstep mode not permitted, force configuring for split-mode\n"); in k3_r5_rproc_configure()
877 cluster->mode = CLUSTER_MODE_SPLIT; in k3_r5_rproc_configure()
880 /* always enable ARM mode and set boot vector to 0 */ in k3_r5_rproc_configure()
885 * Single-CPU configuration bit can only be configured in k3_r5_rproc_configure()
890 if (cluster->mode == CLUSTER_MODE_SINGLECPU || in k3_r5_rproc_configure()
891 cluster->mode == CLUSTER_MODE_SINGLECORE) { in k3_r5_rproc_configure()
895 * LockStep configuration bit is Read-only on Split-mode in k3_r5_rproc_configure()
905 if (core->atcm_enable) in k3_r5_rproc_configure()
910 if (core->btcm_enable) in k3_r5_rproc_configure()
915 if (core->loczrama) in k3_r5_rproc_configure()
920 if (cluster->mode == CLUSTER_MODE_LOCKSTEP) { in k3_r5_rproc_configure()
926 list_for_each_entry(temp, &cluster->cores, elem) { in k3_r5_rproc_configure()
935 ret = ti_sci_proc_set_config(temp->tsp, boot_vec, in k3_r5_rproc_configure()
943 ret = ti_sci_proc_set_config(core->tsp, boot_vec, in k3_r5_rproc_configure()
950 ret = ti_sci_proc_set_config(core->tsp, boot_vec, in k3_r5_rproc_configure()
960 struct device *dev = kproc->dev; in k3_r5_reserved_mem_init()
967 num_rmems = of_property_count_elems_of_size(np, "memory-region", in k3_r5_reserved_mem_init()
972 return -EINVAL; in k3_r5_reserved_mem_init()
977 return -EINVAL; in k3_r5_reserved_mem_init()
988 num_rmems--; in k3_r5_reserved_mem_init()
989 kproc->rmem = kcalloc(num_rmems, sizeof(*kproc->rmem), GFP_KERNEL); in k3_r5_reserved_mem_init()
990 if (!kproc->rmem) { in k3_r5_reserved_mem_init()
991 ret = -ENOMEM; in k3_r5_reserved_mem_init()
997 rmem_np = of_parse_phandle(np, "memory-region", i + 1); in k3_r5_reserved_mem_init()
999 ret = -EINVAL; in k3_r5_reserved_mem_init()
1006 ret = -EINVAL; in k3_r5_reserved_mem_init()
1011 kproc->rmem[i].bus_addr = rmem->base; in k3_r5_reserved_mem_init()
1015 * the 32-bit processor addresses to 64-bit bus addresses. The in k3_r5_reserved_mem_init()
1017 * is currently not supported, so 64-bit address regions are not in k3_r5_reserved_mem_init()
1019 * addresses/supported memory regions are restricted to 32-bit in k3_r5_reserved_mem_init()
1022 kproc->rmem[i].dev_addr = (u32)rmem->base; in k3_r5_reserved_mem_init()
1023 kproc->rmem[i].size = rmem->size; in k3_r5_reserved_mem_init()
1024 kproc->rmem[i].cpu_addr = ioremap_wc(rmem->base, rmem->size); in k3_r5_reserved_mem_init()
1025 if (!kproc->rmem[i].cpu_addr) { in k3_r5_reserved_mem_init()
1027 i + 1, &rmem->base, &rmem->size); in k3_r5_reserved_mem_init()
1028 ret = -ENOMEM; in k3_r5_reserved_mem_init()
1033 i + 1, &kproc->rmem[i].bus_addr, in k3_r5_reserved_mem_init()
1034 kproc->rmem[i].size, kproc->rmem[i].cpu_addr, in k3_r5_reserved_mem_init()
1035 kproc->rmem[i].dev_addr); in k3_r5_reserved_mem_init()
1037 kproc->num_rmems = num_rmems; in k3_r5_reserved_mem_init()
1042 for (i--; i >= 0; i--) in k3_r5_reserved_mem_init()
1043 iounmap(kproc->rmem[i].cpu_addr); in k3_r5_reserved_mem_init()
1044 kfree(kproc->rmem); in k3_r5_reserved_mem_init()
1054 for (i = 0; i < kproc->num_rmems; i++) in k3_r5_reserved_mem_exit()
1055 iounmap(kproc->rmem[i].cpu_addr); in k3_r5_reserved_mem_exit()
1056 kfree(kproc->rmem); in k3_r5_reserved_mem_exit()
1058 of_reserved_mem_device_release(kproc->dev); in k3_r5_reserved_mem_exit()
1064 * cores are usable in Split-mode, but only the Core0 TCMs can be used in
1065 * LockStep-mode. The newer revisions of the R5FSS IP maximizes these TCMs by
1067 * otherwise been unusable (Eg: LockStep-mode on J7200 SoCs, Single-CPU mode on
1072 * half the original size in Split mode.
1076 struct k3_r5_cluster *cluster = kproc->cluster; in k3_r5_adjust_tcm_sizes()
1077 struct k3_r5_core *core = kproc->core; in k3_r5_adjust_tcm_sizes()
1078 struct device *cdev = core->dev; in k3_r5_adjust_tcm_sizes()
1081 if (cluster->mode == CLUSTER_MODE_LOCKSTEP || in k3_r5_adjust_tcm_sizes()
1082 cluster->mode == CLUSTER_MODE_SINGLECPU || in k3_r5_adjust_tcm_sizes()
1083 cluster->mode == CLUSTER_MODE_SINGLECORE || in k3_r5_adjust_tcm_sizes()
1084 !cluster->soc_data->tcm_is_double) in k3_r5_adjust_tcm_sizes()
1087 core0 = list_first_entry(&cluster->cores, struct k3_r5_core, elem); in k3_r5_adjust_tcm_sizes()
1089 WARN_ON(core->mem[0].size != SZ_64K); in k3_r5_adjust_tcm_sizes()
1090 WARN_ON(core->mem[1].size != SZ_64K); in k3_r5_adjust_tcm_sizes()
1092 core->mem[0].size /= 2; in k3_r5_adjust_tcm_sizes()
1093 core->mem[1].size /= 2; in k3_r5_adjust_tcm_sizes()
1096 core->mem[0].size, core->mem[1].size); in k3_r5_adjust_tcm_sizes()
1101 * This function checks and configures a R5F core for IPC-only or remoteproc
1102 * mode. The driver is configured to be in IPC-only mode for a R5F core when
1103 * the core has been loaded and started by a bootloader. The IPC-only mode is
1104 * detected by querying the System Firmware for reset, power on and halt status
1108 * In IPC-only mode, the driver state flags for ATCM, BTCM and LOCZRAMA settings
1109 * and cluster mode parsed originally from kernel DT are updated to reflect the
1115 struct k3_r5_cluster *cluster = kproc->cluster; in k3_r5_rproc_configure_mode()
1116 struct k3_r5_core *core = kproc->core; in k3_r5_rproc_configure_mode()
1117 struct device *cdev = core->dev; in k3_r5_rproc_configure_mode()
1123 enum cluster_mode mode = cluster->mode; in k3_r5_rproc_configure_mode() local
1126 core0 = list_first_entry(&cluster->cores, struct k3_r5_core, elem); in k3_r5_rproc_configure_mode()
1128 ret = core->ti_sci->ops.dev_ops.is_on(core->ti_sci, core->ti_sci_id, in k3_r5_rproc_configure_mode()
1131 dev_err(cdev, "failed to get initial state, mode cannot be determined, ret = %d\n", in k3_r5_rproc_configure_mode()
1140 ret = reset_control_status(core->reset); in k3_r5_rproc_configure_mode()
1142 dev_err(cdev, "failed to get initial local reset status, ret = %d\n", in k3_r5_rproc_configure_mode()
1148 * Skip the waiting mechanism for sequential power-on of cores if the in k3_r5_rproc_configure_mode()
1151 core->released_from_reset = c_state; in k3_r5_rproc_configure_mode()
1153 ret = ti_sci_proc_get_status(core->tsp, &boot_vec, &cfg, &ctrl, in k3_r5_rproc_configure_mode()
1166 if (single_cpu && mode != CLUSTER_MODE_SINGLECORE) in k3_r5_rproc_configure_mode()
1167 mode = CLUSTER_MODE_SINGLECPU; in k3_r5_rproc_configure_mode()
1169 mode = CLUSTER_MODE_LOCKSTEP; in k3_r5_rproc_configure_mode()
1174 * IPC-only mode detection requires both local and module resets to in k3_r5_rproc_configure_mode()
1175 * be deasserted and R5F core to be unhalted. Local reset status is in k3_r5_rproc_configure_mode()
1176 * irrelevant if module reset is asserted (POR value has local reset in k3_r5_rproc_configure_mode()
1177 * deasserted), and is deemed as remoteproc mode in k3_r5_rproc_configure_mode()
1180 dev_info(cdev, "configured R5F for IPC-only mode\n"); in k3_r5_rproc_configure_mode()
1181 kproc->rproc->state = RPROC_DETACHED; in k3_r5_rproc_configure_mode()
1183 /* override rproc ops with only required IPC-only mode ops */ in k3_r5_rproc_configure_mode()
1184 kproc->rproc->ops->prepare = NULL; in k3_r5_rproc_configure_mode()
1185 kproc->rproc->ops->unprepare = NULL; in k3_r5_rproc_configure_mode()
1186 kproc->rproc->ops->start = NULL; in k3_r5_rproc_configure_mode()
1187 kproc->rproc->ops->stop = NULL; in k3_r5_rproc_configure_mode()
1188 kproc->rproc->ops->attach = k3_r5_rproc_attach; in k3_r5_rproc_configure_mode()
1189 kproc->rproc->ops->detach = k3_r5_rproc_detach; in k3_r5_rproc_configure_mode()
1190 kproc->rproc->ops->get_loaded_rsc_table = in k3_r5_rproc_configure_mode()
1193 dev_info(cdev, "configured R5F for remoteproc mode\n"); in k3_r5_rproc_configure_mode()
1196 dev_err(cdev, "mismatched mode: local_reset = %s, module_reset = %s, core_state = %s\n", in k3_r5_rproc_configure_mode()
1200 ret = -EINVAL; in k3_r5_rproc_configure_mode()
1203 /* fixup TCMs, cluster & core flags to actual values in IPC-only mode */ in k3_r5_rproc_configure_mode()
1206 cluster->mode = mode; in k3_r5_rproc_configure_mode()
1207 core->atcm_enable = atcm_enable; in k3_r5_rproc_configure_mode()
1208 core->btcm_enable = btcm_enable; in k3_r5_rproc_configure_mode()
1209 core->loczrama = loczrama; in k3_r5_rproc_configure_mode()
1210 core->mem[0].dev_addr = loczrama ? 0 : K3_R5_TCM_DEV_ADDR; in k3_r5_rproc_configure_mode()
1211 core->mem[1].dev_addr = loczrama ? K3_R5_TCM_DEV_ADDR : 0; in k3_r5_rproc_configure_mode()
1220 struct device *dev = &pdev->dev; in k3_r5_cluster_rproc_init()
1228 core1 = list_last_entry(&cluster->cores, struct k3_r5_core, elem); in k3_r5_cluster_rproc_init()
1229 list_for_each_entry(core, &cluster->cores, elem) { in k3_r5_cluster_rproc_init()
1230 cdev = core->dev; in k3_r5_cluster_rproc_init()
1233 dev_err(dev, "failed to parse firmware-name property, ret = %d\n", in k3_r5_cluster_rproc_init()
1241 ret = -ENOMEM; in k3_r5_cluster_rproc_init()
1246 rproc->has_iommu = false; in k3_r5_cluster_rproc_init()
1248 rproc->recovery_disabled = true; in k3_r5_cluster_rproc_init()
1250 kproc = rproc->priv; in k3_r5_cluster_rproc_init()
1251 kproc->cluster = cluster; in k3_r5_cluster_rproc_init()
1252 kproc->core = core; in k3_r5_cluster_rproc_init()
1253 kproc->dev = cdev; in k3_r5_cluster_rproc_init()
1254 kproc->rproc = rproc; in k3_r5_cluster_rproc_init()
1255 core->rproc = rproc; in k3_r5_cluster_rproc_init()
1290 /* create only one rproc in lockstep, single-cpu or in k3_r5_cluster_rproc_init()
1291 * single core mode in k3_r5_cluster_rproc_init()
1293 if (cluster->mode == CLUSTER_MODE_LOCKSTEP || in k3_r5_cluster_rproc_init()
1294 cluster->mode == CLUSTER_MODE_SINGLECPU || in k3_r5_cluster_rproc_init()
1295 cluster->mode == CLUSTER_MODE_SINGLECORE) in k3_r5_cluster_rproc_init()
1308 ret = wait_event_interruptible_timeout(cluster->core_transition, in k3_r5_cluster_rproc_init()
1309 core->released_from_reset, in k3_r5_cluster_rproc_init()
1314 rproc->name); in k3_r5_cluster_rproc_init()
1322 if (rproc->state == RPROC_ATTACHED) { in k3_r5_cluster_rproc_init()
1325 dev_err(kproc->dev, "failed to detach rproc, ret = %d\n", in k3_r5_cluster_rproc_init()
1337 core->rproc = NULL; in k3_r5_cluster_rproc_init()
1339 /* undo core0 upon any failures on core1 in split-mode */ in k3_r5_cluster_rproc_init()
1340 if (cluster->mode == CLUSTER_MODE_SPLIT && core == core1) { in k3_r5_cluster_rproc_init()
1342 rproc = core->rproc; in k3_r5_cluster_rproc_init()
1343 kproc = rproc->priv; in k3_r5_cluster_rproc_init()
1358 * lockstep mode and single-cpu modes have only one rproc associated in k3_r5_cluster_rproc_exit()
1359 * with first core, whereas split-mode has two rprocs associated with in k3_r5_cluster_rproc_exit()
1362 core = (cluster->mode == CLUSTER_MODE_LOCKSTEP || in k3_r5_cluster_rproc_exit()
1363 cluster->mode == CLUSTER_MODE_SINGLECPU) ? in k3_r5_cluster_rproc_exit()
1364 list_first_entry(&cluster->cores, struct k3_r5_core, elem) : in k3_r5_cluster_rproc_exit()
1365 list_last_entry(&cluster->cores, struct k3_r5_core, elem); in k3_r5_cluster_rproc_exit()
1367 list_for_each_entry_from_reverse(core, &cluster->cores, elem) { in k3_r5_cluster_rproc_exit()
1368 rproc = core->rproc; in k3_r5_cluster_rproc_exit()
1369 kproc = rproc->priv; in k3_r5_cluster_rproc_exit()
1371 if (rproc->state == RPROC_ATTACHED) { in k3_r5_cluster_rproc_exit()
1374 dev_err(kproc->dev, "failed to detach rproc, ret = %d\n", ret); in k3_r5_cluster_rproc_exit()
1379 mbox_free_channel(kproc->mbox); in k3_r5_cluster_rproc_exit()
1386 core->rproc = NULL; in k3_r5_cluster_rproc_exit()
1394 struct device *dev = &pdev->dev; in k3_r5_core_of_get_internal_memories()
1400 core->mem = devm_kcalloc(dev, num_mems, sizeof(*core->mem), GFP_KERNEL); in k3_r5_core_of_get_internal_memories()
1401 if (!core->mem) in k3_r5_core_of_get_internal_memories()
1402 return -ENOMEM; in k3_r5_core_of_get_internal_memories()
1410 return -EINVAL; in k3_r5_core_of_get_internal_memories()
1412 if (!devm_request_mem_region(dev, res->start, in k3_r5_core_of_get_internal_memories()
1417 return -EBUSY; in k3_r5_core_of_get_internal_memories()
1421 * TCMs are designed in general to support RAM-like backing in k3_r5_core_of_get_internal_memories()
1422 * memories. So, map these as Normal Non-Cached memories. This in k3_r5_core_of_get_internal_memories()
1427 core->mem[i].cpu_addr = devm_ioremap_wc(dev, res->start, in k3_r5_core_of_get_internal_memories()
1429 if (!core->mem[i].cpu_addr) { in k3_r5_core_of_get_internal_memories()
1431 return -ENOMEM; in k3_r5_core_of_get_internal_memories()
1433 core->mem[i].bus_addr = res->start; in k3_r5_core_of_get_internal_memories()
1444 core->mem[i].dev_addr = core->loczrama ? in k3_r5_core_of_get_internal_memories()
1447 core->mem[i].dev_addr = core->loczrama ? in k3_r5_core_of_get_internal_memories()
1450 core->mem[i].size = resource_size(res); in k3_r5_core_of_get_internal_memories()
1453 mem_names[i], &core->mem[i].bus_addr, in k3_r5_core_of_get_internal_memories()
1454 core->mem[i].size, core->mem[i].cpu_addr, in k3_r5_core_of_get_internal_memories()
1455 core->mem[i].dev_addr); in k3_r5_core_of_get_internal_memories()
1457 core->num_mems = num_mems; in k3_r5_core_of_get_internal_memories()
1465 struct device_node *np = pdev->dev.of_node; in k3_r5_core_of_get_sram_memories()
1466 struct device *dev = &pdev->dev; in k3_r5_core_of_get_sram_memories()
1474 dev_dbg(dev, "device does not use reserved on-chip memories, num_sram = %d\n", in k3_r5_core_of_get_sram_memories()
1479 core->sram = devm_kcalloc(dev, num_sram, sizeof(*core->sram), GFP_KERNEL); in k3_r5_core_of_get_sram_memories()
1480 if (!core->sram) in k3_r5_core_of_get_sram_memories()
1481 return -ENOMEM; in k3_r5_core_of_get_sram_memories()
1486 return -EINVAL; in k3_r5_core_of_get_sram_memories()
1490 return -EINVAL; in k3_r5_core_of_get_sram_memories()
1496 return -EINVAL; in k3_r5_core_of_get_sram_memories()
1498 core->sram[i].bus_addr = res.start; in k3_r5_core_of_get_sram_memories()
1499 core->sram[i].dev_addr = res.start; in k3_r5_core_of_get_sram_memories()
1500 core->sram[i].size = resource_size(&res); in k3_r5_core_of_get_sram_memories()
1501 core->sram[i].cpu_addr = devm_ioremap_wc(dev, res.start, in k3_r5_core_of_get_sram_memories()
1503 if (!core->sram[i].cpu_addr) { in k3_r5_core_of_get_sram_memories()
1506 return -ENOMEM; in k3_r5_core_of_get_sram_memories()
1510 i, &core->sram[i].bus_addr, in k3_r5_core_of_get_sram_memories()
1511 core->sram[i].size, core->sram[i].cpu_addr, in k3_r5_core_of_get_sram_memories()
1512 core->sram[i].dev_addr); in k3_r5_core_of_get_sram_memories()
1514 core->num_sram = num_sram; in k3_r5_core_of_get_sram_memories()
1527 ret = of_property_read_u32_array(dev_of_node(dev), "ti,sci-proc-ids", in k3_r5_core_of_get_tsp()
1534 return ERR_PTR(-ENOMEM); in k3_r5_core_of_get_tsp()
1536 tsp->dev = dev; in k3_r5_core_of_get_tsp()
1537 tsp->sci = sci; in k3_r5_core_of_get_tsp()
1538 tsp->ops = &sci->ops.proc_ops; in k3_r5_core_of_get_tsp()
1539 tsp->proc_id = temp[0]; in k3_r5_core_of_get_tsp()
1540 tsp->host_id = temp[1]; in k3_r5_core_of_get_tsp()
1547 struct device *dev = &pdev->dev; in k3_r5_core_of_init()
1553 return -ENOMEM; in k3_r5_core_of_init()
1557 ret = -ENOMEM; in k3_r5_core_of_init()
1561 core->dev = dev; in k3_r5_core_of_init()
1563 * Use SoC Power-on-Reset values as default if no DT properties are in k3_r5_core_of_init()
1566 core->atcm_enable = 0; in k3_r5_core_of_init()
1567 core->btcm_enable = 1; in k3_r5_core_of_init()
1568 core->loczrama = 1; in k3_r5_core_of_init()
1570 ret = of_property_read_u32(np, "ti,atcm-enable", &core->atcm_enable); in k3_r5_core_of_init()
1571 if (ret < 0 && ret != -EINVAL) { in k3_r5_core_of_init()
1572 dev_err(dev, "invalid format for ti,atcm-enable, ret = %d\n", in k3_r5_core_of_init()
1577 ret = of_property_read_u32(np, "ti,btcm-enable", &core->btcm_enable); in k3_r5_core_of_init()
1578 if (ret < 0 && ret != -EINVAL) { in k3_r5_core_of_init()
1579 dev_err(dev, "invalid format for ti,btcm-enable, ret = %d\n", in k3_r5_core_of_init()
1584 ret = of_property_read_u32(np, "ti,loczrama", &core->loczrama); in k3_r5_core_of_init()
1585 if (ret < 0 && ret != -EINVAL) { in k3_r5_core_of_init()
1590 core->ti_sci = devm_ti_sci_get_by_phandle(dev, "ti,sci"); in k3_r5_core_of_init()
1591 if (IS_ERR(core->ti_sci)) { in k3_r5_core_of_init()
1592 ret = PTR_ERR(core->ti_sci); in k3_r5_core_of_init()
1593 if (ret != -EPROBE_DEFER) { in k3_r5_core_of_init()
1594 dev_err(dev, "failed to get ti-sci handle, ret = %d\n", in k3_r5_core_of_init()
1597 core->ti_sci = NULL; in k3_r5_core_of_init()
1601 ret = of_property_read_u32(np, "ti,sci-dev-id", &core->ti_sci_id); in k3_r5_core_of_init()
1603 dev_err(dev, "missing 'ti,sci-dev-id' property\n"); in k3_r5_core_of_init()
1607 core->reset = devm_reset_control_get_exclusive(dev, NULL); in k3_r5_core_of_init()
1608 if (IS_ERR_OR_NULL(core->reset)) { in k3_r5_core_of_init()
1609 ret = PTR_ERR_OR_ZERO(core->reset); in k3_r5_core_of_init()
1611 ret = -ENODEV; in k3_r5_core_of_init()
1612 if (ret != -EPROBE_DEFER) { in k3_r5_core_of_init()
1613 dev_err(dev, "failed to get reset handle, ret = %d\n", in k3_r5_core_of_init()
1619 core->tsp = k3_r5_core_of_get_tsp(dev, core->ti_sci); in k3_r5_core_of_init()
1620 if (IS_ERR(core->tsp)) { in k3_r5_core_of_init()
1621 ret = PTR_ERR(core->tsp); in k3_r5_core_of_init()
1622 dev_err(dev, "failed to construct ti-sci proc control, ret = %d\n", in k3_r5_core_of_init()
1640 ret = ti_sci_proc_request(core->tsp); in k3_r5_core_of_init()
1663 struct device *dev = &pdev->dev; in k3_r5_core_of_exit()
1666 ret = ti_sci_proc_release(core->tsp); in k3_r5_core_of_exit()
1680 list_for_each_entry_safe_reverse(core, temp, &cluster->cores, elem) { in k3_r5_cluster_of_exit()
1681 list_del(&core->elem); in k3_r5_cluster_of_exit()
1682 cpdev = to_platform_device(core->dev); in k3_r5_cluster_of_exit()
1690 struct device *dev = &pdev->dev; in k3_r5_cluster_of_init()
1700 ret = -ENODEV; in k3_r5_cluster_of_init()
1710 put_device(&cpdev->dev); in k3_r5_cluster_of_init()
1716 put_device(&cpdev->dev); in k3_r5_cluster_of_init()
1717 list_add_tail(&core->elem, &cluster->cores); in k3_r5_cluster_of_init()
1729 struct device *dev = &pdev->dev; in k3_r5_probe()
1736 data = of_device_get_match_data(&pdev->dev); in k3_r5_probe()
1738 dev_err(dev, "SoC-specific data is not defined\n"); in k3_r5_probe()
1739 return -ENODEV; in k3_r5_probe()
1744 return -ENOMEM; in k3_r5_probe()
1746 cluster->dev = dev; in k3_r5_probe()
1747 cluster->soc_data = data; in k3_r5_probe()
1748 INIT_LIST_HEAD(&cluster->cores); in k3_r5_probe()
1749 init_waitqueue_head(&cluster->core_transition); in k3_r5_probe()
1751 ret = of_property_read_u32(np, "ti,cluster-mode", &cluster->mode); in k3_r5_probe()
1752 if (ret < 0 && ret != -EINVAL) { in k3_r5_probe()
1753 dev_err(dev, "invalid format for ti,cluster-mode, ret = %d\n", in k3_r5_probe()
1758 if (ret == -EINVAL) { in k3_r5_probe()
1760 * default to most common efuse configurations - Split-mode on AM64x in k3_r5_probe()
1761 * and LockStep-mode on all others in k3_r5_probe()
1762 * default to most common efuse configurations - in k3_r5_probe()
1763 * Split-mode on AM64x in k3_r5_probe()
1765 * LockStep-mode on all others in k3_r5_probe()
1767 if (!data->is_single_core) in k3_r5_probe()
1768 cluster->mode = data->single_cpu_mode ? in k3_r5_probe()
1771 cluster->mode = CLUSTER_MODE_SINGLECORE; in k3_r5_probe()
1774 if ((cluster->mode == CLUSTER_MODE_SINGLECPU && !data->single_cpu_mode) || in k3_r5_probe()
1775 (cluster->mode == CLUSTER_MODE_SINGLECORE && !data->is_single_core)) { in k3_r5_probe()
1776 dev_err(dev, "Cluster mode = %d is not supported on this SoC\n", cluster->mode); in k3_r5_probe()
1777 return -EINVAL; in k3_r5_probe()
1781 if (num_cores != 2 && !data->is_single_core) { in k3_r5_probe()
1784 return -ENODEV; in k3_r5_probe()
1787 if (num_cores != 1 && data->is_single_core) { in k3_r5_probe()
1790 return -ENODEV; in k3_r5_probe()
1855 { .compatible = "ti,am654-r5fss", .data = &am65_j721e_soc_data, },
1856 { .compatible = "ti,j721e-r5fss", .data = &am65_j721e_soc_data, },
1857 { .compatible = "ti,j7200-r5fss", .data = &j7200_j721s2_soc_data, },
1858 { .compatible = "ti,am64-r5fss", .data = &am64_soc_data, },
1859 { .compatible = "ti,am62-r5fss", .data = &am62_soc_data, },
1860 { .compatible = "ti,j721s2-r5fss", .data = &j7200_j721s2_soc_data, },
1877 MODULE_AUTHOR("Suman Anna <s-anna@ti.com>");