Lines Matching +full:am654 +full:- +full:r5fss

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>
18 #include <linux/omap-mailbox.h>
32 /* R5 TI-SCI Processor Configuration Flags */
46 /* R5 TI-SCI Processor Control Flags */
49 /* R5 TI-SCI Processor Status Flags */
58 * struct k3_r5_mem - internal memory structure
76 * Single-CPU mode : AM64x SoCs only
85 * struct k3_r5_soc_data - match data to handle SoC variations
87 * @tcm_ecc_autoinit: flag to denote the auto-initialization of TCMs for ECC
88 * @single_cpu_mode: flag to denote if SoC/IP supports Single-CPU mode
97 * struct k3_r5_cluster - K3 R5F Cluster structure
99 * @mode: Mode to configure the Cluster - Split or LockStep
101 * @soc_data: SoC-specific feature data for a R5FSS
111 * struct k3_r5_core - K3 R5 core structure
116 * @sram: on-chip SRAM memory regions data
118 * @num_sram: number of on-chip SRAM memory regions
120 * @tsp: TI-SCI processor control handle
121 * @ti_sci: TI-SCI handle
122 * @ti_sci_id: TI-SCI device identifier
145 * struct k3_r5_rproc - K3 remote processor state
167 * k3_r5_rproc_mbox_callback() - inbound mailbox message handler
176 * In addition to virtqueue indices, we also have some out-of-band values
184 struct device *dev = kproc->rproc->dev.parent; in k3_r5_rproc_mbox_callback()
185 const char *name = kproc->rproc->name; in k3_r5_rproc_mbox_callback()
205 if (msg > kproc->rproc->max_notifyid) { in k3_r5_rproc_mbox_callback()
210 if (rproc_vq_interrupt(kproc->rproc, msg) == IRQ_NONE) in k3_r5_rproc_mbox_callback()
218 struct k3_r5_rproc *kproc = rproc->priv; in k3_r5_rproc_kick()
219 struct device *dev = rproc->dev.parent; in k3_r5_rproc_kick()
224 ret = mbox_send_message(kproc->mbox, (void *)msg); in k3_r5_rproc_kick()
234 ret = reset_control_assert(core->reset); in k3_r5_split_reset()
236 dev_err(core->dev, "local-reset assert failed, ret = %d\n", in k3_r5_split_reset()
241 ret = core->ti_sci->ops.dev_ops.put_device(core->ti_sci, in k3_r5_split_reset()
242 core->ti_sci_id); in k3_r5_split_reset()
244 dev_err(core->dev, "module-reset assert failed, ret = %d\n", in k3_r5_split_reset()
246 if (reset_control_deassert(core->reset)) in k3_r5_split_reset()
247 dev_warn(core->dev, "local-reset deassert back failed\n"); in k3_r5_split_reset()
257 ret = core->ti_sci->ops.dev_ops.get_device(core->ti_sci, in k3_r5_split_release()
258 core->ti_sci_id); in k3_r5_split_release()
260 dev_err(core->dev, "module-reset deassert failed, ret = %d\n", in k3_r5_split_release()
265 ret = reset_control_deassert(core->reset); in k3_r5_split_release()
267 dev_err(core->dev, "local-reset deassert failed, ret = %d\n", in k3_r5_split_release()
269 if (core->ti_sci->ops.dev_ops.put_device(core->ti_sci, in k3_r5_split_release()
270 core->ti_sci_id)) in k3_r5_split_release()
271 dev_warn(core->dev, "module-reset assert back failed\n"); in k3_r5_split_release()
283 list_for_each_entry(core, &cluster->cores, elem) { in k3_r5_lockstep_reset()
284 ret = reset_control_assert(core->reset); in k3_r5_lockstep_reset()
286 dev_err(core->dev, "local-reset assert failed, ret = %d\n", in k3_r5_lockstep_reset()
294 list_for_each_entry(core, &cluster->cores, elem) { in k3_r5_lockstep_reset()
295 ret = core->ti_sci->ops.dev_ops.put_device(core->ti_sci, in k3_r5_lockstep_reset()
296 core->ti_sci_id); in k3_r5_lockstep_reset()
298 dev_err(core->dev, "module-reset assert failed, ret = %d\n", in k3_r5_lockstep_reset()
307 list_for_each_entry_continue_reverse(core, &cluster->cores, elem) { in k3_r5_lockstep_reset()
308 if (core->ti_sci->ops.dev_ops.put_device(core->ti_sci, in k3_r5_lockstep_reset()
309 core->ti_sci_id)) in k3_r5_lockstep_reset()
310 dev_warn(core->dev, "module-reset assert back failed\n"); in k3_r5_lockstep_reset()
312 core = list_last_entry(&cluster->cores, struct k3_r5_core, elem); in k3_r5_lockstep_reset()
314 list_for_each_entry_from_reverse(core, &cluster->cores, elem) { in k3_r5_lockstep_reset()
315 if (reset_control_deassert(core->reset)) in k3_r5_lockstep_reset()
316 dev_warn(core->dev, "local-reset deassert back failed\n"); in k3_r5_lockstep_reset()
328 list_for_each_entry_reverse(core, &cluster->cores, elem) { in k3_r5_lockstep_release()
329 ret = core->ti_sci->ops.dev_ops.get_device(core->ti_sci, in k3_r5_lockstep_release()
330 core->ti_sci_id); in k3_r5_lockstep_release()
332 dev_err(core->dev, "module-reset deassert failed, ret = %d\n", in k3_r5_lockstep_release()
340 list_for_each_entry_reverse(core, &cluster->cores, elem) { in k3_r5_lockstep_release()
341 ret = reset_control_deassert(core->reset); in k3_r5_lockstep_release()
343 dev_err(core->dev, "module-reset deassert failed, ret = %d\n", in k3_r5_lockstep_release()
352 list_for_each_entry_continue(core, &cluster->cores, elem) { in k3_r5_lockstep_release()
353 if (reset_control_assert(core->reset)) in k3_r5_lockstep_release()
354 dev_warn(core->dev, "local-reset assert back failed\n"); in k3_r5_lockstep_release()
356 core = list_first_entry(&cluster->cores, struct k3_r5_core, elem); in k3_r5_lockstep_release()
358 list_for_each_entry_from(core, &cluster->cores, elem) { in k3_r5_lockstep_release()
359 if (core->ti_sci->ops.dev_ops.put_device(core->ti_sci, in k3_r5_lockstep_release()
360 core->ti_sci_id)) in k3_r5_lockstep_release()
361 dev_warn(core->dev, "module-reset assert back failed\n"); in k3_r5_lockstep_release()
369 return ti_sci_proc_set_control(core->tsp, in k3_r5_core_halt()
375 return ti_sci_proc_set_control(core->tsp, in k3_r5_core_run()
381 struct k3_r5_rproc *kproc = rproc->priv; in k3_r5_rproc_request_mbox()
382 struct mbox_client *client = &kproc->client; in k3_r5_rproc_request_mbox()
383 struct device *dev = kproc->dev; in k3_r5_rproc_request_mbox()
386 client->dev = dev; in k3_r5_rproc_request_mbox()
387 client->tx_done = NULL; in k3_r5_rproc_request_mbox()
388 client->rx_callback = k3_r5_rproc_mbox_callback; in k3_r5_rproc_request_mbox()
389 client->tx_block = false; in k3_r5_rproc_request_mbox()
390 client->knows_txdone = false; in k3_r5_rproc_request_mbox()
392 kproc->mbox = mbox_request_channel(client, 0); in k3_r5_rproc_request_mbox()
393 if (IS_ERR(kproc->mbox)) { in k3_r5_rproc_request_mbox()
394 ret = -EBUSY; in k3_r5_rproc_request_mbox()
396 PTR_ERR(kproc->mbox)); in k3_r5_rproc_request_mbox()
401 * Ping the remote processor, this is only for sanity-sake for now; in k3_r5_rproc_request_mbox()
407 ret = mbox_send_message(kproc->mbox, (void *)RP_MBOX_ECHO_REQUEST); in k3_r5_rproc_request_mbox()
410 mbox_free_channel(kproc->mbox); in k3_r5_rproc_request_mbox()
419 * execution from DDR requires the initial boot-strapping code to be run
425 * The Single-CPU mode on applicable SoCs (eg: AM64x) only uses Core0 to
435 struct k3_r5_rproc *kproc = rproc->priv; in k3_r5_rproc_prepare()
436 struct k3_r5_cluster *cluster = kproc->cluster; in k3_r5_rproc_prepare()
437 struct k3_r5_core *core = kproc->core; in k3_r5_rproc_prepare()
438 struct device *dev = kproc->dev; in k3_r5_rproc_prepare()
444 ret = ti_sci_proc_get_status(core->tsp, &boot_vec, &cfg, &ctrl, &stat); in k3_r5_rproc_prepare()
449 /* Re-use LockStep-mode reset logic for Single-CPU mode */ in k3_r5_rproc_prepare()
450 ret = (cluster->mode == CLUSTER_MODE_LOCKSTEP || in k3_r5_rproc_prepare()
451 cluster->mode == CLUSTER_MODE_SINGLECPU) ? in k3_r5_rproc_prepare()
460 * Newer IP revisions like on J7200 SoCs support h/w auto-initialization in k3_r5_rproc_prepare()
463 * auto-init, but account for it in case it is disabled in k3_r5_rproc_prepare()
465 if (cluster->soc_data->tcm_ecc_autoinit && !mem_init_dis) { in k3_r5_rproc_prepare()
476 memset(core->mem[0].cpu_addr, 0x00, core->mem[0].size); in k3_r5_rproc_prepare()
479 memset(core->mem[1].cpu_addr, 0x00, core->mem[1].size); in k3_r5_rproc_prepare()
493 * The Single-CPU mode on applicable SoCs (eg: AM64x) combines the TCMs from
495 * both cores, but with only Core0 unhalted. This function re-uses the same
502 struct k3_r5_rproc *kproc = rproc->priv; in k3_r5_rproc_unprepare()
503 struct k3_r5_cluster *cluster = kproc->cluster; in k3_r5_rproc_unprepare()
504 struct k3_r5_core *core = kproc->core; in k3_r5_rproc_unprepare()
505 struct device *dev = kproc->dev; in k3_r5_rproc_unprepare()
508 /* Re-use LockStep-mode reset logic for Single-CPU mode */ in k3_r5_rproc_unprepare()
509 ret = (cluster->mode == CLUSTER_MODE_LOCKSTEP || in k3_r5_rproc_unprepare()
510 cluster->mode == CLUSTER_MODE_SINGLECPU) ? in k3_r5_rproc_unprepare()
525 * unhalt both the cores to start the execution - Core1 needs to be unhalted
526 * first followed by Core0. The Split-mode requires that Core0 to be maintained
530 * The Single-CPU mode on applicable SoCs (eg: AM64x) only uses Core0 to execute
532 * flow as Split-mode for this. This callback is invoked only in remoteproc
537 struct k3_r5_rproc *kproc = rproc->priv; in k3_r5_rproc_start()
538 struct k3_r5_cluster *cluster = kproc->cluster; in k3_r5_rproc_start()
539 struct device *dev = kproc->dev; in k3_r5_rproc_start()
548 boot_addr = rproc->bootaddr; in k3_r5_rproc_start()
553 core = kproc->core; in k3_r5_rproc_start()
554 ret = ti_sci_proc_set_config(core->tsp, boot_addr, 0, 0); in k3_r5_rproc_start()
559 if (cluster->mode == CLUSTER_MODE_LOCKSTEP) { in k3_r5_rproc_start()
560 list_for_each_entry_reverse(core, &cluster->cores, elem) { in k3_r5_rproc_start()
574 list_for_each_entry_continue(core, &cluster->cores, elem) { in k3_r5_rproc_start()
576 dev_warn(core->dev, "core halt back failed\n"); in k3_r5_rproc_start()
579 mbox_free_channel(kproc->mbox); in k3_r5_rproc_start()
590 * performed first on Core0 followed by Core1. The Split-mode requires that
594 * The Single-CPU mode on applicable SoCs (eg: AM64x) only uses Core0 to execute
596 * flow as Split-mode for this.
601 * be done here, but is preferred to be done in the .unprepare() ops - this
609 struct k3_r5_rproc *kproc = rproc->priv; in k3_r5_rproc_stop()
610 struct k3_r5_cluster *cluster = kproc->cluster; in k3_r5_rproc_stop()
611 struct k3_r5_core *core = kproc->core; in k3_r5_rproc_stop()
615 if (cluster->mode == CLUSTER_MODE_LOCKSTEP) { in k3_r5_rproc_stop()
616 list_for_each_entry(core, &cluster->cores, elem) { in k3_r5_rproc_stop()
629 mbox_free_channel(kproc->mbox); in k3_r5_rproc_stop()
634 list_for_each_entry_from_reverse(core, &cluster->cores, elem) { in k3_r5_rproc_stop()
636 dev_warn(core->dev, "core run back failed\n"); in k3_r5_rproc_stop()
643 * Attach to a running R5F remote processor (IPC-only mode)
646 * processor is already booted, so there is no need to issue any TI-SCI
647 * commands to boot the R5F cores in IPC-only mode. This callback is invoked
648 * only in IPC-only mode.
652 struct k3_r5_rproc *kproc = rproc->priv; in k3_r5_rproc_attach()
653 struct device *dev = kproc->dev; in k3_r5_rproc_attach()
660 dev_info(dev, "R5F core initialized in IPC-only mode\n"); in k3_r5_rproc_attach()
665 * Detach from a running R5F remote processor (IPC-only mode)
669 * will be left in booted state in IPC-only mode. This callback is invoked
670 * only in IPC-only mode.
674 struct k3_r5_rproc *kproc = rproc->priv; in k3_r5_rproc_detach()
675 struct device *dev = kproc->dev; in k3_r5_rproc_detach()
677 mbox_free_channel(kproc->mbox); in k3_r5_rproc_detach()
678 dev_info(dev, "R5F core deinitialized in IPC-only mode\n"); in k3_r5_rproc_detach()
684 * to provide the resource table for the booted R5F in IPC-only mode. The K3 R5F
685 * firmwares follow a design-by-contract approach and are expected to have the
690 * IPC-only mode.
695 struct k3_r5_rproc *kproc = rproc->priv; in k3_r5_get_loaded_rsc_table()
696 struct device *dev = kproc->dev; in k3_r5_get_loaded_rsc_table()
698 if (!kproc->rmem[0].cpu_addr) { in k3_r5_get_loaded_rsc_table()
699 dev_err(dev, "memory-region #1 does not exist, loaded rsc table can't be found"); in k3_r5_get_loaded_rsc_table()
700 return ERR_PTR(-ENOMEM); in k3_r5_get_loaded_rsc_table()
704 * NOTE: The resource table size is currently hard-coded to a maximum in k3_r5_get_loaded_rsc_table()
708 * the hard-coded value suffices to support the IPC-only mode. in k3_r5_get_loaded_rsc_table()
711 return (struct resource_table *)kproc->rmem[0].cpu_addr; in k3_r5_get_loaded_rsc_table()
724 struct k3_r5_rproc *kproc = rproc->priv; in k3_r5_rproc_da_to_va()
725 struct k3_r5_core *core = kproc->core; in k3_r5_rproc_da_to_va()
736 for (i = 0; i < core->num_mems; i++) { in k3_r5_rproc_da_to_va()
737 bus_addr = core->mem[i].bus_addr; in k3_r5_rproc_da_to_va()
738 dev_addr = core->mem[i].dev_addr; in k3_r5_rproc_da_to_va()
739 size = core->mem[i].size; in k3_r5_rproc_da_to_va()
741 /* handle R5-view addresses of TCMs */ in k3_r5_rproc_da_to_va()
743 offset = da - dev_addr; in k3_r5_rproc_da_to_va()
744 va = core->mem[i].cpu_addr + offset; in k3_r5_rproc_da_to_va()
748 /* handle SoC-view addresses of TCMs */ in k3_r5_rproc_da_to_va()
750 offset = da - bus_addr; in k3_r5_rproc_da_to_va()
751 va = core->mem[i].cpu_addr + offset; in k3_r5_rproc_da_to_va()
756 /* handle any SRAM regions using SoC-view addresses */ in k3_r5_rproc_da_to_va()
757 for (i = 0; i < core->num_sram; i++) { in k3_r5_rproc_da_to_va()
758 dev_addr = core->sram[i].dev_addr; in k3_r5_rproc_da_to_va()
759 size = core->sram[i].size; in k3_r5_rproc_da_to_va()
762 offset = da - dev_addr; in k3_r5_rproc_da_to_va()
763 va = core->sram[i].cpu_addr + offset; in k3_r5_rproc_da_to_va()
769 for (i = 0; i < kproc->num_rmems; i++) { in k3_r5_rproc_da_to_va()
770 dev_addr = kproc->rmem[i].dev_addr; in k3_r5_rproc_da_to_va()
771 size = kproc->rmem[i].size; in k3_r5_rproc_da_to_va()
774 offset = da - dev_addr; in k3_r5_rproc_da_to_va()
775 va = kproc->rmem[i].cpu_addr + offset; in k3_r5_rproc_da_to_va()
795 * Each R5FSS has a cluster-level setting for configuring the processor
796 * subsystem either in a safety/fault-tolerant LockStep mode or a performance
797 * oriented Split mode on most SoCs. A fewer SoCs support a non-safety mode
799 * called Single-CPU mode. Each R5F core has a number of settings to either
805 * This function is used to pre-configure these settings for each R5F core, and
811 * once (in LockStep mode or Single-CPU modes) or twice (in Split mode). Support
812 * for LockStep-mode is dictated by an eFUSE register bit, and the config
815 * supports a Single-CPU mode. All cluster level settings like Cluster mode and
823 * This is overcome by switching to Split-mode initially and then programming
829 struct k3_r5_cluster *cluster = kproc->cluster; in k3_r5_rproc_configure()
830 struct device *dev = kproc->dev; in k3_r5_rproc_configure()
839 core0 = list_first_entry(&cluster->cores, struct k3_r5_core, elem); in k3_r5_rproc_configure()
840 if (cluster->mode == CLUSTER_MODE_LOCKSTEP || in k3_r5_rproc_configure()
841 cluster->mode == CLUSTER_MODE_SINGLECPU) { in k3_r5_rproc_configure()
844 core = kproc->core; in k3_r5_rproc_configure()
847 ret = ti_sci_proc_get_status(core->tsp, &boot_vec, &cfg, &ctrl, in k3_r5_rproc_configure()
855 /* check if only Single-CPU mode is supported on applicable SoCs */ in k3_r5_rproc_configure()
856 if (cluster->soc_data->single_cpu_mode) { in k3_r5_rproc_configure()
859 if (single_cpu && cluster->mode == CLUSTER_MODE_SPLIT) { in k3_r5_rproc_configure()
860 dev_err(cluster->dev, "split-mode not permitted, force configuring for single-cpu mode\n"); in k3_r5_rproc_configure()
861 cluster->mode = CLUSTER_MODE_SINGLECPU; in k3_r5_rproc_configure()
868 if (!lockstep_en && cluster->mode == CLUSTER_MODE_LOCKSTEP) { in k3_r5_rproc_configure()
869 dev_err(cluster->dev, "lockstep mode not permitted, force configuring for split-mode\n"); in k3_r5_rproc_configure()
870 cluster->mode = CLUSTER_MODE_SPLIT; in k3_r5_rproc_configure()
878 if (cluster->soc_data->single_cpu_mode) { in k3_r5_rproc_configure()
880 * Single-CPU configuration bit can only be configured in k3_r5_rproc_configure()
885 if (cluster->mode == CLUSTER_MODE_SINGLECPU) in k3_r5_rproc_configure()
889 * LockStep configuration bit is Read-only on Split-mode in k3_r5_rproc_configure()
899 if (core->atcm_enable) in k3_r5_rproc_configure()
904 if (core->btcm_enable) in k3_r5_rproc_configure()
909 if (core->loczrama) in k3_r5_rproc_configure()
914 if (cluster->mode == CLUSTER_MODE_LOCKSTEP) { in k3_r5_rproc_configure()
920 list_for_each_entry(temp, &cluster->cores, elem) { in k3_r5_rproc_configure()
929 ret = ti_sci_proc_set_config(temp->tsp, boot_vec, in k3_r5_rproc_configure()
937 ret = ti_sci_proc_set_config(core->tsp, boot_vec, in k3_r5_rproc_configure()
944 ret = ti_sci_proc_set_config(core->tsp, boot_vec, in k3_r5_rproc_configure()
954 struct device *dev = kproc->dev; in k3_r5_reserved_mem_init()
961 num_rmems = of_property_count_elems_of_size(np, "memory-region", in k3_r5_reserved_mem_init()
966 return -EINVAL; in k3_r5_reserved_mem_init()
971 return -EINVAL; in k3_r5_reserved_mem_init()
982 num_rmems--; in k3_r5_reserved_mem_init()
983 kproc->rmem = kcalloc(num_rmems, sizeof(*kproc->rmem), GFP_KERNEL); in k3_r5_reserved_mem_init()
984 if (!kproc->rmem) { in k3_r5_reserved_mem_init()
985 ret = -ENOMEM; in k3_r5_reserved_mem_init()
991 rmem_np = of_parse_phandle(np, "memory-region", i + 1); in k3_r5_reserved_mem_init()
993 ret = -EINVAL; in k3_r5_reserved_mem_init()
1000 ret = -EINVAL; in k3_r5_reserved_mem_init()
1005 kproc->rmem[i].bus_addr = rmem->base; in k3_r5_reserved_mem_init()
1009 * the 32-bit processor addresses to 64-bit bus addresses. The in k3_r5_reserved_mem_init()
1011 * is currently not supported, so 64-bit address regions are not in k3_r5_reserved_mem_init()
1013 * addresses/supported memory regions are restricted to 32-bit in k3_r5_reserved_mem_init()
1016 kproc->rmem[i].dev_addr = (u32)rmem->base; in k3_r5_reserved_mem_init()
1017 kproc->rmem[i].size = rmem->size; in k3_r5_reserved_mem_init()
1018 kproc->rmem[i].cpu_addr = ioremap_wc(rmem->base, rmem->size); in k3_r5_reserved_mem_init()
1019 if (!kproc->rmem[i].cpu_addr) { in k3_r5_reserved_mem_init()
1021 i + 1, &rmem->base, &rmem->size); in k3_r5_reserved_mem_init()
1022 ret = -ENOMEM; in k3_r5_reserved_mem_init()
1027 i + 1, &kproc->rmem[i].bus_addr, in k3_r5_reserved_mem_init()
1028 kproc->rmem[i].size, kproc->rmem[i].cpu_addr, in k3_r5_reserved_mem_init()
1029 kproc->rmem[i].dev_addr); in k3_r5_reserved_mem_init()
1031 kproc->num_rmems = num_rmems; in k3_r5_reserved_mem_init()
1036 for (i--; i >= 0; i--) in k3_r5_reserved_mem_init()
1037 iounmap(kproc->rmem[i].cpu_addr); in k3_r5_reserved_mem_init()
1038 kfree(kproc->rmem); in k3_r5_reserved_mem_init()
1048 for (i = 0; i < kproc->num_rmems; i++) in k3_r5_reserved_mem_exit()
1049 iounmap(kproc->rmem[i].cpu_addr); in k3_r5_reserved_mem_exit()
1050 kfree(kproc->rmem); in k3_r5_reserved_mem_exit()
1052 of_reserved_mem_device_release(kproc->dev); in k3_r5_reserved_mem_exit()
1056 * Each R5F core within a typical R5FSS instance has a total of 64 KB of TCMs,
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
1061 * otherwise been unusable (Eg: LockStep-mode on J7200 SoCs, Single-CPU mode on
1070 struct k3_r5_cluster *cluster = kproc->cluster; in k3_r5_adjust_tcm_sizes()
1071 struct k3_r5_core *core = kproc->core; in k3_r5_adjust_tcm_sizes()
1072 struct device *cdev = core->dev; in k3_r5_adjust_tcm_sizes()
1075 if (cluster->mode == CLUSTER_MODE_LOCKSTEP || in k3_r5_adjust_tcm_sizes()
1076 cluster->mode == CLUSTER_MODE_SINGLECPU || in k3_r5_adjust_tcm_sizes()
1077 !cluster->soc_data->tcm_is_double) in k3_r5_adjust_tcm_sizes()
1080 core0 = list_first_entry(&cluster->cores, struct k3_r5_core, elem); in k3_r5_adjust_tcm_sizes()
1082 WARN_ON(core->mem[0].size != SZ_64K); in k3_r5_adjust_tcm_sizes()
1083 WARN_ON(core->mem[1].size != SZ_64K); in k3_r5_adjust_tcm_sizes()
1085 core->mem[0].size /= 2; in k3_r5_adjust_tcm_sizes()
1086 core->mem[1].size /= 2; in k3_r5_adjust_tcm_sizes()
1089 core->mem[0].size, core->mem[1].size); in k3_r5_adjust_tcm_sizes()
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
1101 * In IPC-only mode, the driver state flags for ATCM, BTCM and LOCZRAMA settings
1108 struct k3_r5_cluster *cluster = kproc->cluster; in k3_r5_rproc_configure_mode()
1109 struct k3_r5_core *core = kproc->core; in k3_r5_rproc_configure_mode()
1110 struct device *cdev = core->dev; in k3_r5_rproc_configure_mode()
1119 core0 = list_first_entry(&cluster->cores, struct k3_r5_core, elem); in k3_r5_rproc_configure_mode()
1121 ret = core->ti_sci->ops.dev_ops.is_on(core->ti_sci, core->ti_sci_id, in k3_r5_rproc_configure_mode()
1133 ret = reset_control_status(core->reset); in k3_r5_rproc_configure_mode()
1140 ret = ti_sci_proc_get_status(core->tsp, &boot_vec, &cfg, &ctrl, in k3_r5_rproc_configure_mode()
1150 if (cluster->soc_data->single_cpu_mode) { in k3_r5_rproc_configure_mode()
1160 * IPC-only mode detection requires both local and module resets to in k3_r5_rproc_configure_mode()
1166 dev_info(cdev, "configured R5F for IPC-only mode\n"); in k3_r5_rproc_configure_mode()
1167 kproc->rproc->state = RPROC_DETACHED; in k3_r5_rproc_configure_mode()
1169 /* override rproc ops with only required IPC-only mode ops */ in k3_r5_rproc_configure_mode()
1170 kproc->rproc->ops->prepare = NULL; in k3_r5_rproc_configure_mode()
1171 kproc->rproc->ops->unprepare = NULL; in k3_r5_rproc_configure_mode()
1172 kproc->rproc->ops->start = NULL; in k3_r5_rproc_configure_mode()
1173 kproc->rproc->ops->stop = NULL; in k3_r5_rproc_configure_mode()
1174 kproc->rproc->ops->attach = k3_r5_rproc_attach; in k3_r5_rproc_configure_mode()
1175 kproc->rproc->ops->detach = k3_r5_rproc_detach; in k3_r5_rproc_configure_mode()
1176 kproc->rproc->ops->get_loaded_rsc_table = in k3_r5_rproc_configure_mode()
1186 ret = -EINVAL; in k3_r5_rproc_configure_mode()
1189 /* fixup TCMs, cluster & core flags to actual values in IPC-only mode */ in k3_r5_rproc_configure_mode()
1192 cluster->mode = mode; in k3_r5_rproc_configure_mode()
1193 core->atcm_enable = atcm_enable; in k3_r5_rproc_configure_mode()
1194 core->btcm_enable = btcm_enable; in k3_r5_rproc_configure_mode()
1195 core->loczrama = loczrama; in k3_r5_rproc_configure_mode()
1196 core->mem[0].dev_addr = loczrama ? 0 : K3_R5_TCM_DEV_ADDR; in k3_r5_rproc_configure_mode()
1197 core->mem[1].dev_addr = loczrama ? K3_R5_TCM_DEV_ADDR : 0; in k3_r5_rproc_configure_mode()
1206 struct device *dev = &pdev->dev; in k3_r5_cluster_rproc_init()
1214 core1 = list_last_entry(&cluster->cores, struct k3_r5_core, elem); in k3_r5_cluster_rproc_init()
1215 list_for_each_entry(core, &cluster->cores, elem) { in k3_r5_cluster_rproc_init()
1216 cdev = core->dev; in k3_r5_cluster_rproc_init()
1219 dev_err(dev, "failed to parse firmware-name property, ret = %d\n", in k3_r5_cluster_rproc_init()
1227 ret = -ENOMEM; in k3_r5_cluster_rproc_init()
1232 rproc->has_iommu = false; in k3_r5_cluster_rproc_init()
1234 rproc->recovery_disabled = true; in k3_r5_cluster_rproc_init()
1236 kproc = rproc->priv; in k3_r5_cluster_rproc_init()
1237 kproc->cluster = cluster; in k3_r5_cluster_rproc_init()
1238 kproc->core = core; in k3_r5_cluster_rproc_init()
1239 kproc->dev = cdev; in k3_r5_cluster_rproc_init()
1240 kproc->rproc = rproc; in k3_r5_cluster_rproc_init()
1241 core->rproc = rproc; in k3_r5_cluster_rproc_init()
1272 /* create only one rproc in lockstep mode or single-cpu mode */ in k3_r5_cluster_rproc_init()
1273 if (cluster->mode == CLUSTER_MODE_LOCKSTEP || in k3_r5_cluster_rproc_init()
1274 cluster->mode == CLUSTER_MODE_SINGLECPU) in k3_r5_cluster_rproc_init()
1281 if (rproc->state == RPROC_ATTACHED) { in k3_r5_cluster_rproc_init()
1284 dev_err(kproc->dev, "failed to detach rproc, ret = %d\n", in k3_r5_cluster_rproc_init()
1295 core->rproc = NULL; in k3_r5_cluster_rproc_init()
1297 /* undo core0 upon any failures on core1 in split-mode */ in k3_r5_cluster_rproc_init()
1298 if (cluster->mode == CLUSTER_MODE_SPLIT && core == core1) { in k3_r5_cluster_rproc_init()
1300 rproc = core->rproc; in k3_r5_cluster_rproc_init()
1301 kproc = rproc->priv; in k3_r5_cluster_rproc_init()
1316 * lockstep mode and single-cpu modes have only one rproc associated in k3_r5_cluster_rproc_exit()
1317 * with first core, whereas split-mode has two rprocs associated with in k3_r5_cluster_rproc_exit()
1320 core = (cluster->mode == CLUSTER_MODE_LOCKSTEP || in k3_r5_cluster_rproc_exit()
1321 cluster->mode == CLUSTER_MODE_SINGLECPU) ? in k3_r5_cluster_rproc_exit()
1322 list_first_entry(&cluster->cores, struct k3_r5_core, elem) : in k3_r5_cluster_rproc_exit()
1323 list_last_entry(&cluster->cores, struct k3_r5_core, elem); in k3_r5_cluster_rproc_exit()
1325 list_for_each_entry_from_reverse(core, &cluster->cores, elem) { in k3_r5_cluster_rproc_exit()
1326 rproc = core->rproc; in k3_r5_cluster_rproc_exit()
1327 kproc = rproc->priv; in k3_r5_cluster_rproc_exit()
1329 if (rproc->state == RPROC_ATTACHED) { in k3_r5_cluster_rproc_exit()
1332 dev_err(kproc->dev, "failed to detach rproc, ret = %d\n", ret); in k3_r5_cluster_rproc_exit()
1342 core->rproc = NULL; in k3_r5_cluster_rproc_exit()
1350 struct device *dev = &pdev->dev; in k3_r5_core_of_get_internal_memories()
1356 core->mem = devm_kcalloc(dev, num_mems, sizeof(*core->mem), GFP_KERNEL); in k3_r5_core_of_get_internal_memories()
1357 if (!core->mem) in k3_r5_core_of_get_internal_memories()
1358 return -ENOMEM; in k3_r5_core_of_get_internal_memories()
1366 return -EINVAL; in k3_r5_core_of_get_internal_memories()
1368 if (!devm_request_mem_region(dev, res->start, in k3_r5_core_of_get_internal_memories()
1373 return -EBUSY; in k3_r5_core_of_get_internal_memories()
1377 * TCMs are designed in general to support RAM-like backing in k3_r5_core_of_get_internal_memories()
1378 * memories. So, map these as Normal Non-Cached memories. This in k3_r5_core_of_get_internal_memories()
1383 core->mem[i].cpu_addr = devm_ioremap_wc(dev, res->start, in k3_r5_core_of_get_internal_memories()
1385 if (!core->mem[i].cpu_addr) { in k3_r5_core_of_get_internal_memories()
1387 return -ENOMEM; in k3_r5_core_of_get_internal_memories()
1389 core->mem[i].bus_addr = res->start; in k3_r5_core_of_get_internal_memories()
1400 core->mem[i].dev_addr = core->loczrama ? in k3_r5_core_of_get_internal_memories()
1403 core->mem[i].dev_addr = core->loczrama ? in k3_r5_core_of_get_internal_memories()
1406 core->mem[i].size = resource_size(res); in k3_r5_core_of_get_internal_memories()
1409 mem_names[i], &core->mem[i].bus_addr, in k3_r5_core_of_get_internal_memories()
1410 core->mem[i].size, core->mem[i].cpu_addr, in k3_r5_core_of_get_internal_memories()
1411 core->mem[i].dev_addr); in k3_r5_core_of_get_internal_memories()
1413 core->num_mems = num_mems; in k3_r5_core_of_get_internal_memories()
1421 struct device_node *np = pdev->dev.of_node; in k3_r5_core_of_get_sram_memories()
1422 struct device *dev = &pdev->dev; in k3_r5_core_of_get_sram_memories()
1430 dev_dbg(dev, "device does not use reserved on-chip memories, num_sram = %d\n", in k3_r5_core_of_get_sram_memories()
1435 core->sram = devm_kcalloc(dev, num_sram, sizeof(*core->sram), GFP_KERNEL); in k3_r5_core_of_get_sram_memories()
1436 if (!core->sram) in k3_r5_core_of_get_sram_memories()
1437 return -ENOMEM; in k3_r5_core_of_get_sram_memories()
1442 return -EINVAL; in k3_r5_core_of_get_sram_memories()
1446 return -EINVAL; in k3_r5_core_of_get_sram_memories()
1452 return -EINVAL; in k3_r5_core_of_get_sram_memories()
1454 core->sram[i].bus_addr = res.start; in k3_r5_core_of_get_sram_memories()
1455 core->sram[i].dev_addr = res.start; in k3_r5_core_of_get_sram_memories()
1456 core->sram[i].size = resource_size(&res); in k3_r5_core_of_get_sram_memories()
1457 core->sram[i].cpu_addr = devm_ioremap_wc(dev, res.start, in k3_r5_core_of_get_sram_memories()
1459 if (!core->sram[i].cpu_addr) { in k3_r5_core_of_get_sram_memories()
1462 return -ENOMEM; in k3_r5_core_of_get_sram_memories()
1466 i, &core->sram[i].bus_addr, in k3_r5_core_of_get_sram_memories()
1467 core->sram[i].size, core->sram[i].cpu_addr, in k3_r5_core_of_get_sram_memories()
1468 core->sram[i].dev_addr); in k3_r5_core_of_get_sram_memories()
1470 core->num_sram = num_sram; in k3_r5_core_of_get_sram_memories()
1483 ret = of_property_read_u32_array(dev_of_node(dev), "ti,sci-proc-ids", in k3_r5_core_of_get_tsp()
1490 return ERR_PTR(-ENOMEM); in k3_r5_core_of_get_tsp()
1492 tsp->dev = dev; in k3_r5_core_of_get_tsp()
1493 tsp->sci = sci; in k3_r5_core_of_get_tsp()
1494 tsp->ops = &sci->ops.proc_ops; in k3_r5_core_of_get_tsp()
1495 tsp->proc_id = temp[0]; in k3_r5_core_of_get_tsp()
1496 tsp->host_id = temp[1]; in k3_r5_core_of_get_tsp()
1503 struct device *dev = &pdev->dev; in k3_r5_core_of_init()
1509 return -ENOMEM; in k3_r5_core_of_init()
1513 ret = -ENOMEM; in k3_r5_core_of_init()
1517 core->dev = dev; in k3_r5_core_of_init()
1519 * Use SoC Power-on-Reset values as default if no DT properties are in k3_r5_core_of_init()
1522 core->atcm_enable = 0; in k3_r5_core_of_init()
1523 core->btcm_enable = 1; in k3_r5_core_of_init()
1524 core->loczrama = 1; in k3_r5_core_of_init()
1526 ret = of_property_read_u32(np, "ti,atcm-enable", &core->atcm_enable); in k3_r5_core_of_init()
1527 if (ret < 0 && ret != -EINVAL) { in k3_r5_core_of_init()
1528 dev_err(dev, "invalid format for ti,atcm-enable, ret = %d\n", in k3_r5_core_of_init()
1533 ret = of_property_read_u32(np, "ti,btcm-enable", &core->btcm_enable); in k3_r5_core_of_init()
1534 if (ret < 0 && ret != -EINVAL) { in k3_r5_core_of_init()
1535 dev_err(dev, "invalid format for ti,btcm-enable, ret = %d\n", in k3_r5_core_of_init()
1540 ret = of_property_read_u32(np, "ti,loczrama", &core->loczrama); in k3_r5_core_of_init()
1541 if (ret < 0 && ret != -EINVAL) { in k3_r5_core_of_init()
1546 core->ti_sci = devm_ti_sci_get_by_phandle(dev, "ti,sci"); in k3_r5_core_of_init()
1547 if (IS_ERR(core->ti_sci)) { in k3_r5_core_of_init()
1548 ret = PTR_ERR(core->ti_sci); in k3_r5_core_of_init()
1549 if (ret != -EPROBE_DEFER) { in k3_r5_core_of_init()
1550 dev_err(dev, "failed to get ti-sci handle, ret = %d\n", in k3_r5_core_of_init()
1553 core->ti_sci = NULL; in k3_r5_core_of_init()
1557 ret = of_property_read_u32(np, "ti,sci-dev-id", &core->ti_sci_id); in k3_r5_core_of_init()
1559 dev_err(dev, "missing 'ti,sci-dev-id' property\n"); in k3_r5_core_of_init()
1563 core->reset = devm_reset_control_get_exclusive(dev, NULL); in k3_r5_core_of_init()
1564 if (IS_ERR_OR_NULL(core->reset)) { in k3_r5_core_of_init()
1565 ret = PTR_ERR_OR_ZERO(core->reset); in k3_r5_core_of_init()
1567 ret = -ENODEV; in k3_r5_core_of_init()
1568 if (ret != -EPROBE_DEFER) { in k3_r5_core_of_init()
1575 core->tsp = k3_r5_core_of_get_tsp(dev, core->ti_sci); in k3_r5_core_of_init()
1576 if (IS_ERR(core->tsp)) { in k3_r5_core_of_init()
1577 ret = PTR_ERR(core->tsp); in k3_r5_core_of_init()
1578 dev_err(dev, "failed to construct ti-sci proc control, ret = %d\n", in k3_r5_core_of_init()
1596 ret = ti_sci_proc_request(core->tsp); in k3_r5_core_of_init()
1619 struct device *dev = &pdev->dev; in k3_r5_core_of_exit()
1622 ret = ti_sci_proc_release(core->tsp); in k3_r5_core_of_exit()
1636 list_for_each_entry_safe_reverse(core, temp, &cluster->cores, elem) { in k3_r5_cluster_of_exit()
1637 list_del(&core->elem); in k3_r5_cluster_of_exit()
1638 cpdev = to_platform_device(core->dev); in k3_r5_cluster_of_exit()
1646 struct device *dev = &pdev->dev; in k3_r5_cluster_of_init()
1656 ret = -ENODEV; in k3_r5_cluster_of_init()
1666 put_device(&cpdev->dev); in k3_r5_cluster_of_init()
1672 put_device(&cpdev->dev); in k3_r5_cluster_of_init()
1673 list_add_tail(&core->elem, &cluster->cores); in k3_r5_cluster_of_init()
1685 struct device *dev = &pdev->dev; in k3_r5_probe()
1692 data = of_device_get_match_data(&pdev->dev); in k3_r5_probe()
1694 dev_err(dev, "SoC-specific data is not defined\n"); in k3_r5_probe()
1695 return -ENODEV; in k3_r5_probe()
1700 return -ENOMEM; in k3_r5_probe()
1702 cluster->dev = dev; in k3_r5_probe()
1704 * default to most common efuse configurations - Split-mode on AM64x in k3_r5_probe()
1705 * and LockStep-mode on all others in k3_r5_probe()
1707 cluster->mode = data->single_cpu_mode ? in k3_r5_probe()
1709 cluster->soc_data = data; in k3_r5_probe()
1710 INIT_LIST_HEAD(&cluster->cores); in k3_r5_probe()
1712 ret = of_property_read_u32(np, "ti,cluster-mode", &cluster->mode); in k3_r5_probe()
1713 if (ret < 0 && ret != -EINVAL) { in k3_r5_probe()
1714 dev_err(dev, "invalid format for ti,cluster-mode, ret = %d\n", in k3_r5_probe()
1723 return -ENODEV; in k3_r5_probe()
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, },
1799 MODULE_AUTHOR("Suman Anna <s-anna@ti.com>");