Lines Matching +full:sci +full:- +full:reset
1 // SPDX-License-Identifier: GPL-2.0-only
3 * TI K3 Cortex-M4 Remote Processor(s) driver
5 * Copyright (C) 2021-2024 Texas Instruments Incorporated - https://www.ti.com/
16 #include <linux/reset.h>
27 * struct k3_m4_rproc_mem - internal memory structure
41 * struct k3_m4_rproc_mem_data - memory definitions for a remote processor
51 * struct k3_m4_rproc - k3 remote processor driver structure
57 * @reset: reset control handle
58 * @tsp: TI-SCI processor control handle
59 * @ti_sci: TI-SCI handle
60 * @ti_sci_id: TI-SCI device identifier
70 struct reset_control *reset; member
79 * k3_m4_rproc_mbox_callback() - inbound mailbox message handler
88 * In addition to virtqueue indices, we also have some out-of-band values
94 struct device *dev = client->dev; in k3_m4_rproc_mbox_callback()
106 dev_err(dev, "K3 rproc %s crashed\n", rproc->name); in k3_m4_rproc_mbox_callback()
109 dev_info(dev, "received echo reply from %s\n", rproc->name); in k3_m4_rproc_mbox_callback()
115 if (msg > rproc->max_notifyid) { in k3_m4_rproc_mbox_callback()
128 * through a simulated GPIO (a bit in an IPC interrupt-triggering register),
133 struct k3_m4_rproc *kproc = rproc->priv; in k3_m4_rproc_kick()
134 struct device *dev = kproc->dev; in k3_m4_rproc_kick()
143 ret = mbox_send_message(kproc->mbox, (void *)(uintptr_t)msg); in k3_m4_rproc_kick()
151 struct device *dev = kproc->dev; in k3_m4_rproc_ping_mbox()
155 * Ping the remote processor, this is only for sanity-sake for now; in k3_m4_rproc_ping_mbox()
161 ret = mbox_send_message(kproc->mbox, (void *)RP_MBOX_ECHO_REQUEST); in k3_m4_rproc_ping_mbox()
171 * The M4 cores have a local reset that affects only the CPU, and a
172 * generic module reset that powers on the device and allows the internal
173 * memories to be accessed while the local reset is asserted. This function is
174 * used to release the global reset on remote cores to allow loading into the
181 struct k3_m4_rproc *kproc = rproc->priv; in k3_m4_rproc_prepare()
182 struct device *dev = kproc->dev; in k3_m4_rproc_prepare()
185 /* If the core is running already no need to deassert the module reset */ in k3_m4_rproc_prepare()
186 if (rproc->state == RPROC_DETACHED) in k3_m4_rproc_prepare()
190 * Ensure the local reset is asserted so the core doesn't in k3_m4_rproc_prepare()
191 * execute bogus code when the module reset is released. in k3_m4_rproc_prepare()
193 ret = reset_control_assert(kproc->reset); in k3_m4_rproc_prepare()
195 dev_err(dev, "could not assert local reset\n"); in k3_m4_rproc_prepare()
199 ret = reset_control_status(kproc->reset); in k3_m4_rproc_prepare()
201 dev_err(dev, "local reset still not asserted\n"); in k3_m4_rproc_prepare()
205 ret = kproc->ti_sci->ops.dev_ops.get_device(kproc->ti_sci, in k3_m4_rproc_prepare()
206 kproc->ti_sci_id); in k3_m4_rproc_prepare()
208 dev_err(dev, "could not deassert module-reset for internal RAM loading\n"); in k3_m4_rproc_prepare()
218 * global reset on applicable cores. This completes the second portion of
220 * .stop() callback through the local reset, and the .unprepare() ops is invoked
222 * reset.
226 struct k3_m4_rproc *kproc = rproc->priv; in k3_m4_rproc_unprepare()
227 struct device *dev = kproc->dev; in k3_m4_rproc_unprepare()
230 /* If the core is going to be detached do not assert the module reset */ in k3_m4_rproc_unprepare()
231 if (rproc->state == RPROC_ATTACHED) in k3_m4_rproc_unprepare()
234 ret = kproc->ti_sci->ops.dev_ops.put_device(kproc->ti_sci, in k3_m4_rproc_unprepare()
235 kproc->ti_sci_id); in k3_m4_rproc_unprepare()
237 dev_err(dev, "module-reset assert failed\n"); in k3_m4_rproc_unprepare()
246 * to provide the resource table for a booted remote processor in IPC-only
247 * mode. The remote processor firmwares follow a design-by-contract approach
257 struct k3_m4_rproc *kproc = rproc->priv; in k3_m4_get_loaded_rsc_table()
258 struct device *dev = kproc->dev; in k3_m4_get_loaded_rsc_table()
260 if (!kproc->rmem[0].cpu_addr) { in k3_m4_get_loaded_rsc_table()
261 dev_err(dev, "memory-region #1 does not exist, loaded rsc table can't be found"); in k3_m4_get_loaded_rsc_table()
262 return ERR_PTR(-ENOMEM); in k3_m4_get_loaded_rsc_table()
266 * NOTE: The resource table size is currently hard-coded to a maximum in k3_m4_get_loaded_rsc_table()
270 * the hard-coded value suffices to support the IPC-only mode. in k3_m4_get_loaded_rsc_table()
273 return (__force struct resource_table *)kproc->rmem[0].cpu_addr; in k3_m4_get_loaded_rsc_table()
280 * processor, or at the SoC-level bus address. Both these addresses need to be
287 struct k3_m4_rproc *kproc = rproc->priv; in k3_m4_rproc_da_to_va()
297 for (i = 0; i < kproc->num_mems; i++) { in k3_m4_rproc_da_to_va()
298 bus_addr = kproc->mem[i].bus_addr; in k3_m4_rproc_da_to_va()
299 dev_addr = kproc->mem[i].dev_addr; in k3_m4_rproc_da_to_va()
300 size = kproc->mem[i].size; in k3_m4_rproc_da_to_va()
302 /* handle M4-view addresses */ in k3_m4_rproc_da_to_va()
304 offset = da - dev_addr; in k3_m4_rproc_da_to_va()
305 va = kproc->mem[i].cpu_addr + offset; in k3_m4_rproc_da_to_va()
309 /* handle SoC-view addresses */ in k3_m4_rproc_da_to_va()
311 offset = da - bus_addr; in k3_m4_rproc_da_to_va()
312 va = kproc->mem[i].cpu_addr + offset; in k3_m4_rproc_da_to_va()
318 for (i = 0; i < kproc->num_rmems; i++) { in k3_m4_rproc_da_to_va()
319 dev_addr = kproc->rmem[i].dev_addr; in k3_m4_rproc_da_to_va()
320 size = kproc->rmem[i].size; in k3_m4_rproc_da_to_va()
323 offset = da - dev_addr; in k3_m4_rproc_da_to_va()
324 va = kproc->rmem[i].cpu_addr + offset; in k3_m4_rproc_da_to_va()
337 struct device *dev = &pdev->dev; in k3_m4_rproc_of_get_memories()
343 kproc->mem = devm_kcalloc(kproc->dev, num_mems, in k3_m4_rproc_of_get_memories()
344 sizeof(*kproc->mem), GFP_KERNEL); in k3_m4_rproc_of_get_memories()
345 if (!kproc->mem) in k3_m4_rproc_of_get_memories()
346 return -ENOMEM; in k3_m4_rproc_of_get_memories()
354 return -EINVAL; in k3_m4_rproc_of_get_memories()
356 if (!devm_request_mem_region(dev, res->start, in k3_m4_rproc_of_get_memories()
361 return -EBUSY; in k3_m4_rproc_of_get_memories()
364 kproc->mem[i].cpu_addr = devm_ioremap_wc(dev, res->start, in k3_m4_rproc_of_get_memories()
366 if (!kproc->mem[i].cpu_addr) { in k3_m4_rproc_of_get_memories()
369 return -ENOMEM; in k3_m4_rproc_of_get_memories()
371 kproc->mem[i].bus_addr = res->start; in k3_m4_rproc_of_get_memories()
372 kproc->mem[i].dev_addr = mem_addrs[i]; in k3_m4_rproc_of_get_memories()
373 kproc->mem[i].size = resource_size(res); in k3_m4_rproc_of_get_memories()
376 mem_names[i], &kproc->mem[i].bus_addr, in k3_m4_rproc_of_get_memories()
377 kproc->mem[i].size, kproc->mem[i].cpu_addr, in k3_m4_rproc_of_get_memories()
378 kproc->mem[i].dev_addr); in k3_m4_rproc_of_get_memories()
380 kproc->num_mems = num_mems; in k3_m4_rproc_of_get_memories()
394 struct device *dev = kproc->dev; in k3_m4_reserved_mem_init()
395 struct device_node *np = dev->of_node; in k3_m4_reserved_mem_init()
401 num_rmems = of_property_count_elems_of_size(np, "memory-region", in k3_m4_reserved_mem_init()
406 return -EINVAL; in k3_m4_reserved_mem_init()
411 return -EINVAL; in k3_m4_reserved_mem_init()
424 num_rmems--; in k3_m4_reserved_mem_init()
425 kproc->rmem = devm_kcalloc(dev, num_rmems, sizeof(*kproc->rmem), GFP_KERNEL); in k3_m4_reserved_mem_init()
426 if (!kproc->rmem) in k3_m4_reserved_mem_init()
427 return -ENOMEM; in k3_m4_reserved_mem_init()
431 rmem_np = of_parse_phandle(np, "memory-region", i + 1); in k3_m4_reserved_mem_init()
433 return -EINVAL; in k3_m4_reserved_mem_init()
438 return -EINVAL; in k3_m4_reserved_mem_init()
442 kproc->rmem[i].bus_addr = rmem->base; in k3_m4_reserved_mem_init()
443 /* 64-bit address regions currently not supported */ in k3_m4_reserved_mem_init()
444 kproc->rmem[i].dev_addr = (u32)rmem->base; in k3_m4_reserved_mem_init()
445 kproc->rmem[i].size = rmem->size; in k3_m4_reserved_mem_init()
446 kproc->rmem[i].cpu_addr = devm_ioremap_wc(dev, rmem->base, rmem->size); in k3_m4_reserved_mem_init()
447 if (!kproc->rmem[i].cpu_addr) { in k3_m4_reserved_mem_init()
449 i + 1, &rmem->base, &rmem->size); in k3_m4_reserved_mem_init()
450 return -ENOMEM; in k3_m4_reserved_mem_init()
454 i + 1, &kproc->rmem[i].bus_addr, in k3_m4_reserved_mem_init()
455 kproc->rmem[i].size, kproc->rmem[i].cpu_addr, in k3_m4_reserved_mem_init()
456 kproc->rmem[i].dev_addr); in k3_m4_reserved_mem_init()
458 kproc->num_rmems = num_rmems; in k3_m4_reserved_mem_init()
479 struct k3_m4_rproc *kproc = rproc->priv; in k3_m4_rproc_start()
480 struct device *dev = kproc->dev; in k3_m4_rproc_start()
487 ret = reset_control_deassert(kproc->reset); in k3_m4_rproc_start()
489 dev_err(dev, "local-reset deassert failed, ret = %d\n", ret); in k3_m4_rproc_start()
499 * This function puts the M4 processor into reset, and finishes processing
504 struct k3_m4_rproc *kproc = rproc->priv; in k3_m4_rproc_stop()
505 struct device *dev = kproc->dev; in k3_m4_rproc_stop()
508 ret = reset_control_assert(kproc->reset); in k3_m4_rproc_stop()
510 dev_err(dev, "local-reset assert failed, ret = %d\n", ret); in k3_m4_rproc_stop()
518 * Attach to a running M4 remote processor (IPC-only mode)
521 * TI-SCI commands to boot the M4 core. This callback is used only in IPC-only
526 struct k3_m4_rproc *kproc = rproc->priv; in k3_m4_rproc_attach()
537 * Detach from a running M4 remote processor (IPC-only mode)
541 * run its booted firmware. This callback is invoked only in IPC-only mode.
562 struct device *dev = &pdev->dev; in k3_m4_rproc_probe()
572 return dev_err_probe(dev, ret, "failed to parse firmware-name property\n"); in k3_m4_rproc_probe()
577 return -ENOMEM; in k3_m4_rproc_probe()
579 rproc->has_iommu = false; in k3_m4_rproc_probe()
580 rproc->recovery_disabled = true; in k3_m4_rproc_probe()
581 kproc = rproc->priv; in k3_m4_rproc_probe()
582 kproc->dev = dev; in k3_m4_rproc_probe()
585 kproc->ti_sci = devm_ti_sci_get_by_phandle(dev, "ti,sci"); in k3_m4_rproc_probe()
586 if (IS_ERR(kproc->ti_sci)) in k3_m4_rproc_probe()
587 return dev_err_probe(dev, PTR_ERR(kproc->ti_sci), in k3_m4_rproc_probe()
588 "failed to get ti-sci handle\n"); in k3_m4_rproc_probe()
590 ret = of_property_read_u32(dev->of_node, "ti,sci-dev-id", &kproc->ti_sci_id); in k3_m4_rproc_probe()
592 return dev_err_probe(dev, ret, "missing 'ti,sci-dev-id' property\n"); in k3_m4_rproc_probe()
594 kproc->reset = devm_reset_control_get_exclusive(dev, NULL); in k3_m4_rproc_probe()
595 if (IS_ERR(kproc->reset)) in k3_m4_rproc_probe()
596 return dev_err_probe(dev, PTR_ERR(kproc->reset), "failed to get reset\n"); in k3_m4_rproc_probe()
598 kproc->tsp = ti_sci_proc_of_get_tsp(dev, kproc->ti_sci); in k3_m4_rproc_probe()
599 if (IS_ERR(kproc->tsp)) in k3_m4_rproc_probe()
600 return dev_err_probe(dev, PTR_ERR(kproc->tsp), in k3_m4_rproc_probe()
601 "failed to construct ti-sci proc control\n"); in k3_m4_rproc_probe()
603 ret = ti_sci_proc_request(kproc->tsp); in k3_m4_rproc_probe()
606 ret = devm_add_action_or_reset(dev, k3_m4_release_tsp, kproc->tsp); in k3_m4_rproc_probe()
618 ret = kproc->ti_sci->ops.dev_ops.is_on(kproc->ti_sci, kproc->ti_sci_id, in k3_m4_rproc_probe()
624 /* configure devices for either remoteproc or IPC-only mode */ in k3_m4_rproc_probe()
626 rproc->state = RPROC_DETACHED; in k3_m4_rproc_probe()
627 dev_info(dev, "configured M4F for IPC-only mode\n"); in k3_m4_rproc_probe()
632 kproc->client.dev = dev; in k3_m4_rproc_probe()
633 kproc->client.tx_done = NULL; in k3_m4_rproc_probe()
634 kproc->client.rx_callback = k3_m4_rproc_mbox_callback; in k3_m4_rproc_probe()
635 kproc->client.tx_block = false; in k3_m4_rproc_probe()
636 kproc->client.knows_txdone = false; in k3_m4_rproc_probe()
637 kproc->mbox = mbox_request_channel(&kproc->client, 0); in k3_m4_rproc_probe()
638 if (IS_ERR(kproc->mbox)) in k3_m4_rproc_probe()
639 return dev_err_probe(dev, PTR_ERR(kproc->mbox), in k3_m4_rproc_probe()
651 { .compatible = "ti,am64-m4fss", },
659 .name = "k3-m4-rproc",