Lines Matching full:rproc
51 typedef int (*rproc_handle_resource_t)(struct rproc *rproc,
54 static int rproc_alloc_carveout(struct rproc *rproc,
56 static int rproc_release_carveout(struct rproc *rproc,
88 struct rproc *rproc = token; in rproc_iommu_fault() local
92 rproc_report_crash(rproc, RPROC_MMUFAULT); in rproc_iommu_fault()
101 static int rproc_enable_iommu(struct rproc *rproc) in rproc_enable_iommu() argument
104 struct device *dev = rproc->dev.parent; in rproc_enable_iommu()
107 if (!rproc->has_iommu) { in rproc_enable_iommu()
118 iommu_set_fault_handler(domain, rproc_iommu_fault, rproc); in rproc_enable_iommu()
126 rproc->domain = domain; in rproc_enable_iommu()
135 static void rproc_disable_iommu(struct rproc *rproc) in rproc_disable_iommu() argument
137 struct iommu_domain *domain = rproc->domain; in rproc_disable_iommu()
138 struct device *dev = rproc->dev.parent; in rproc_disable_iommu()
166 * @rproc: handle of a remote processor
187 * Note: phys_to_virt(iommu_iova_to_phys(rproc->domain, da)) will work too,
194 void *rproc_da_to_va(struct rproc *rproc, u64 da, size_t len, bool *is_iomem) in rproc_da_to_va() argument
199 if (rproc->ops->da_to_va) { in rproc_da_to_va()
200 ptr = rproc->ops->da_to_va(rproc, da, len, is_iomem); in rproc_da_to_va()
205 list_for_each_entry(carveout, &rproc->carveouts, node) { in rproc_da_to_va()
235 * @rproc: handle of a remote processor
240 * (physically contiguous memory regions) before rproc firmware loading and
253 rproc_find_carveout_by_name(struct rproc *rproc, const char *name, ...) in rproc_find_carveout_by_name() argument
266 list_for_each_entry(carveout, &rproc->carveouts, node) { in rproc_find_carveout_by_name()
279 * @rproc: handle of a remote processor
291 static int rproc_check_carveout_da(struct rproc *rproc, in rproc_check_carveout_da() argument
294 struct device *dev = &rproc->dev; in rproc_check_carveout_da()
328 struct rproc *rproc = rvdev->rproc; in rproc_alloc_vring() local
329 struct device *dev = &rproc->dev; in rproc_alloc_vring()
339 rsc = (void *)rproc->table_ptr + rvdev->rsc_offset; in rproc_alloc_vring()
342 mem = rproc_find_carveout_by_name(rproc, "vdev%dvring%d", rvdev->index, in rproc_alloc_vring()
345 if (rproc_check_carveout_da(rproc, mem, rsc->vring[i].da, size)) in rproc_alloc_vring()
360 rproc_add_carveout(rproc, mem); in rproc_alloc_vring()
364 * Assign an rproc-wide unique index for this vring in rproc_alloc_vring()
368 ret = idr_alloc(&rproc->notifyids, rvring, 0, 0, GFP_KERNEL); in rproc_alloc_vring()
376 if (notifyid > rproc->max_notifyid) in rproc_alloc_vring()
377 rproc->max_notifyid = notifyid; in rproc_alloc_vring()
381 /* Let the rproc know the notifyid of this vring.*/ in rproc_alloc_vring()
389 struct rproc *rproc = rvdev->rproc; in rproc_parse_vring() local
390 struct device *dev = &rproc->dev; in rproc_parse_vring()
413 struct rproc *rproc = rvring->rvdev->rproc; in rproc_free_vring() local
417 idr_remove(&rproc->notifyids, rvring->notifyid); in rproc_free_vring()
422 * such and as per rproc_stop(), rproc->table_ptr points to the cached in rproc_free_vring()
423 * resource table (rproc->cached_table). The cached resource table is in rproc_free_vring()
430 if (rproc->table_ptr) { in rproc_free_vring()
431 rsc = (void *)rproc->table_ptr + rvring->rvdev->rsc_offset; in rproc_free_vring()
437 void rproc_add_rvdev(struct rproc *rproc, struct rproc_vdev *rvdev) in rproc_add_rvdev() argument
439 if (rvdev && rproc) in rproc_add_rvdev()
440 list_add_tail(&rvdev->node, &rproc->rvdevs); in rproc_add_rvdev()
450 * @rproc: the remote processor
476 static int rproc_handle_vdev(struct rproc *rproc, void *ptr, in rproc_handle_vdev() argument
480 struct device *dev = &rproc->dev; in rproc_handle_vdev()
509 rvdev_data.index = rproc->nb_vdev++; in rproc_handle_vdev()
514 * When there is more than one remote processor, rproc->nb_vdev number is in rproc_handle_vdev()
515 * same for each separate instances of "rproc". If rvdev_data.index is used in rproc_handle_vdev()
519 pdev = platform_device_register_data(dev, "rproc-virtio", PLATFORM_DEVID_AUTO, &rvdev_data, in rproc_handle_vdev()
522 dev_err(dev, "failed to create rproc-virtio device\n"); in rproc_handle_vdev()
531 * @rproc: the remote processor
546 static int rproc_handle_trace(struct rproc *rproc, void *ptr, in rproc_handle_trace() argument
551 struct device *dev = &rproc->dev; in rproc_handle_trace()
573 /* set pointer on rproc device */ in rproc_handle_trace()
574 trace->rproc = rproc; in rproc_handle_trace()
577 snprintf(name, sizeof(name), "trace%d", rproc->num_traces); in rproc_handle_trace()
580 trace->tfile = rproc_create_trace_file(name, rproc, trace); in rproc_handle_trace()
582 list_add_tail(&trace->node, &rproc->traces); in rproc_handle_trace()
584 rproc->num_traces++; in rproc_handle_trace()
594 * @rproc: remote processor handle
620 static int rproc_handle_devmem(struct rproc *rproc, void *ptr, in rproc_handle_devmem() argument
625 struct device *dev = &rproc->dev; in rproc_handle_devmem()
629 if (!rproc->domain) in rproc_handle_devmem()
647 ret = iommu_map(rproc->domain, rsc->da, rsc->pa, rsc->len, rsc->flags, in rproc_handle_devmem()
663 list_add_tail(&mapping->node, &rproc->mappings); in rproc_handle_devmem()
677 * @rproc: rproc handle
685 static int rproc_alloc_carveout(struct rproc *rproc, in rproc_alloc_carveout() argument
689 struct device *dev = &rproc->dev; in rproc_alloc_carveout()
705 if (mem->da != FW_RSC_ADDR_ANY && !rproc->domain) { in rproc_alloc_carveout()
734 if (mem->da != FW_RSC_ADDR_ANY && rproc->domain) { in rproc_alloc_carveout()
741 ret = iommu_map(rproc->domain, mem->da, dma, mem->len, in rproc_alloc_carveout()
757 list_add_tail(&mapping->node, &rproc->mappings); in rproc_alloc_carveout()
785 * @rproc: rproc handle
789 * rproc_alloc_carveout() function by @rproc.
793 static int rproc_release_carveout(struct rproc *rproc, in rproc_release_carveout() argument
796 struct device *dev = &rproc->dev; in rproc_release_carveout()
805 * @rproc: rproc handle
819 * needed to map it (in case @rproc is using an IOMMU). Reducing the TLB
824 static int rproc_handle_carveout(struct rproc *rproc, in rproc_handle_carveout() argument
829 struct device *dev = &rproc->dev; in rproc_handle_carveout()
849 carveout = rproc_find_carveout_by_name(rproc, rsc->name); in rproc_handle_carveout()
858 if (rproc_check_carveout_da(rproc, carveout, rsc->da, rsc->len)) in rproc_handle_carveout()
879 rproc_add_carveout(rproc, carveout); in rproc_handle_carveout()
886 * @rproc: rproc handle
889 * This function registers specified memory entry in @rproc carveouts list.
892 void rproc_add_carveout(struct rproc *rproc, struct rproc_mem_entry *mem) in rproc_add_carveout() argument
894 list_add_tail(&mem->node, &rproc->carveouts); in rproc_add_carveout()
918 int (*alloc)(struct rproc *, struct rproc_mem_entry *), in rproc_mem_entry_init() argument
919 int (*release)(struct rproc *, struct rproc_mem_entry *), in rproc_mem_entry_init() argument
987 * @dev: pointer on device struct representing a rproc
1020 static int rproc_handle_resources(struct rproc *rproc, in rproc_handle_resources() argument
1023 struct device *dev = &rproc->dev; in rproc_handle_resources()
1027 if (!rproc->table_ptr) in rproc_handle_resources()
1030 for (i = 0; i < rproc->table_ptr->num; i++) { in rproc_handle_resources()
1031 int offset = rproc->table_ptr->offset[i]; in rproc_handle_resources()
1032 struct fw_rsc_hdr *hdr = (void *)rproc->table_ptr + offset; in rproc_handle_resources()
1033 int avail = rproc->table_sz - offset - sizeof(*hdr); in rproc_handle_resources()
1046 ret = rproc_handle_rsc(rproc, hdr->type, rsc, in rproc_handle_resources()
1067 ret = handler(rproc, rsc, offset + sizeof(*hdr), avail); in rproc_handle_resources()
1075 static int rproc_prepare_subdevices(struct rproc *rproc) in rproc_prepare_subdevices() argument
1080 list_for_each_entry(subdev, &rproc->subdevs, node) { in rproc_prepare_subdevices()
1091 list_for_each_entry_continue_reverse(subdev, &rproc->subdevs, node) { in rproc_prepare_subdevices()
1099 static int rproc_start_subdevices(struct rproc *rproc) in rproc_start_subdevices() argument
1104 list_for_each_entry(subdev, &rproc->subdevs, node) { in rproc_start_subdevices()
1115 list_for_each_entry_continue_reverse(subdev, &rproc->subdevs, node) { in rproc_start_subdevices()
1123 static void rproc_stop_subdevices(struct rproc *rproc, bool crashed) in rproc_stop_subdevices() argument
1127 list_for_each_entry_reverse(subdev, &rproc->subdevs, node) { in rproc_stop_subdevices()
1133 static void rproc_unprepare_subdevices(struct rproc *rproc) in rproc_unprepare_subdevices() argument
1137 list_for_each_entry_reverse(subdev, &rproc->subdevs, node) { in rproc_unprepare_subdevices()
1146 * @rproc: the remote processor handle
1154 static int rproc_alloc_registered_carveouts(struct rproc *rproc) in rproc_alloc_registered_carveouts() argument
1158 struct device *dev = &rproc->dev; in rproc_alloc_registered_carveouts()
1162 list_for_each_entry_safe(entry, tmp, &rproc->carveouts, node) { in rproc_alloc_registered_carveouts()
1164 ret = entry->alloc(rproc, entry); in rproc_alloc_registered_carveouts()
1174 rsc = (void *)rproc->table_ptr + entry->rsc_offset; in rproc_alloc_registered_carveouts()
1216 * @rproc: rproc handle
1218 * This function will free all resources acquired for @rproc, and it
1219 * is called whenever @rproc either shuts down or fails to boot.
1221 void rproc_resource_cleanup(struct rproc *rproc) in rproc_resource_cleanup() argument
1226 struct device *dev = &rproc->dev; in rproc_resource_cleanup()
1229 list_for_each_entry_safe(trace, ttmp, &rproc->traces, node) { in rproc_resource_cleanup()
1231 rproc->num_traces--; in rproc_resource_cleanup()
1237 list_for_each_entry_safe(entry, tmp, &rproc->mappings, node) { in rproc_resource_cleanup()
1240 unmapped = iommu_unmap(rproc->domain, entry->da, entry->len); in rproc_resource_cleanup()
1252 list_for_each_entry_safe(entry, tmp, &rproc->carveouts, node) { in rproc_resource_cleanup()
1254 entry->release(rproc, entry); in rproc_resource_cleanup()
1260 list_for_each_entry_safe(rvdev, rvtmp, &rproc->rvdevs, node) in rproc_resource_cleanup()
1263 rproc_coredump_cleanup(rproc); in rproc_resource_cleanup()
1267 static int rproc_start(struct rproc *rproc, const struct firmware *fw) in rproc_start() argument
1270 struct device *dev = &rproc->dev; in rproc_start()
1274 ret = rproc_load_segments(rproc, fw); in rproc_start()
1281 * The starting device has been given the rproc->cached_table as the in rproc_start()
1288 loaded_table = rproc_find_loaded_rsc_table(rproc, fw); in rproc_start()
1290 memcpy(loaded_table, rproc->cached_table, rproc->table_sz); in rproc_start()
1291 rproc->table_ptr = loaded_table; in rproc_start()
1294 ret = rproc_prepare_subdevices(rproc); in rproc_start()
1297 rproc->name, ret); in rproc_start()
1302 ret = rproc->ops->start(rproc); in rproc_start()
1304 dev_err(dev, "can't start rproc %s: %d\n", rproc->name, ret); in rproc_start()
1309 ret = rproc_start_subdevices(rproc); in rproc_start()
1312 rproc->name, ret); in rproc_start()
1316 rproc->state = RPROC_RUNNING; in rproc_start()
1318 dev_info(dev, "remote processor %s is now up\n", rproc->name); in rproc_start()
1323 rproc->ops->stop(rproc); in rproc_start()
1325 rproc_unprepare_subdevices(rproc); in rproc_start()
1327 rproc->table_ptr = rproc->cached_table; in rproc_start()
1332 static int __rproc_attach(struct rproc *rproc) in __rproc_attach() argument
1334 struct device *dev = &rproc->dev; in __rproc_attach()
1337 ret = rproc_prepare_subdevices(rproc); in __rproc_attach()
1340 rproc->name, ret); in __rproc_attach()
1345 ret = rproc_attach_device(rproc); in __rproc_attach()
1347 dev_err(dev, "can't attach to rproc %s: %d\n", in __rproc_attach()
1348 rproc->name, ret); in __rproc_attach()
1353 ret = rproc_start_subdevices(rproc); in __rproc_attach()
1356 rproc->name, ret); in __rproc_attach()
1360 rproc->state = RPROC_ATTACHED; in __rproc_attach()
1362 dev_info(dev, "remote processor %s is now attached\n", rproc->name); in __rproc_attach()
1367 rproc->ops->stop(rproc); in __rproc_attach()
1369 rproc_unprepare_subdevices(rproc); in __rproc_attach()
1377 static int rproc_fw_boot(struct rproc *rproc, const struct firmware *fw) in rproc_fw_boot() argument
1379 struct device *dev = &rproc->dev; in rproc_fw_boot()
1380 const char *name = rproc->firmware; in rproc_fw_boot()
1383 ret = rproc_fw_sanity_check(rproc, fw); in rproc_fw_boot()
1390 * if enabling an IOMMU isn't relevant for this rproc, this is in rproc_fw_boot()
1393 ret = rproc_enable_iommu(rproc); in rproc_fw_boot()
1399 /* Prepare rproc for firmware loading if needed */ in rproc_fw_boot()
1400 ret = rproc_prepare_device(rproc); in rproc_fw_boot()
1402 dev_err(dev, "can't prepare rproc %s: %d\n", rproc->name, ret); in rproc_fw_boot()
1406 rproc->bootaddr = rproc_get_boot_addr(rproc, fw); in rproc_fw_boot()
1409 ret = rproc_parse_fw(rproc, fw); in rproc_fw_boot()
1414 rproc->max_notifyid = -1; in rproc_fw_boot()
1417 rproc->nb_vdev = 0; in rproc_fw_boot()
1419 /* handle fw resources which are required to boot rproc */ in rproc_fw_boot()
1420 ret = rproc_handle_resources(rproc, rproc_loading_handlers); in rproc_fw_boot()
1426 /* Allocate carveout resources associated to rproc */ in rproc_fw_boot()
1427 ret = rproc_alloc_registered_carveouts(rproc); in rproc_fw_boot()
1434 ret = rproc_start(rproc, fw); in rproc_fw_boot()
1441 rproc_resource_cleanup(rproc); in rproc_fw_boot()
1442 kfree(rproc->cached_table); in rproc_fw_boot()
1443 rproc->cached_table = NULL; in rproc_fw_boot()
1444 rproc->table_ptr = NULL; in rproc_fw_boot()
1447 rproc_unprepare_device(rproc); in rproc_fw_boot()
1449 rproc_disable_iommu(rproc); in rproc_fw_boot()
1453 static int rproc_set_rsc_table(struct rproc *rproc) in rproc_set_rsc_table() argument
1456 struct device *dev = &rproc->dev; in rproc_set_rsc_table()
1460 table_ptr = rproc_get_loaded_rsc_table(rproc, &table_sz); in rproc_set_rsc_table()
1482 if (rproc->ops->detach) { in rproc_set_rsc_table()
1483 rproc->clean_table = kmemdup(table_ptr, table_sz, GFP_KERNEL); in rproc_set_rsc_table()
1484 if (!rproc->clean_table) in rproc_set_rsc_table()
1487 rproc->clean_table = NULL; in rproc_set_rsc_table()
1490 rproc->cached_table = NULL; in rproc_set_rsc_table()
1491 rproc->table_ptr = table_ptr; in rproc_set_rsc_table()
1492 rproc->table_sz = table_sz; in rproc_set_rsc_table()
1497 static int rproc_reset_rsc_table_on_detach(struct rproc *rproc) in rproc_reset_rsc_table_on_detach() argument
1502 if (!rproc->table_ptr) in rproc_reset_rsc_table_on_detach()
1510 if (WARN_ON(!rproc->clean_table)) in rproc_reset_rsc_table_on_detach()
1514 table_ptr = rproc->table_ptr; in rproc_reset_rsc_table_on_detach()
1523 rproc->cached_table = kmemdup(rproc->table_ptr, in rproc_reset_rsc_table_on_detach()
1524 rproc->table_sz, GFP_KERNEL); in rproc_reset_rsc_table_on_detach()
1525 if (!rproc->cached_table) in rproc_reset_rsc_table_on_detach()
1532 rproc->table_ptr = rproc->cached_table; in rproc_reset_rsc_table_on_detach()
1539 memcpy(table_ptr, rproc->clean_table, rproc->table_sz); in rproc_reset_rsc_table_on_detach()
1545 kfree(rproc->clean_table); in rproc_reset_rsc_table_on_detach()
1550 static int rproc_reset_rsc_table_on_stop(struct rproc *rproc) in rproc_reset_rsc_table_on_stop() argument
1553 if (!rproc->table_ptr) in rproc_reset_rsc_table_on_stop()
1561 if (rproc->cached_table) in rproc_reset_rsc_table_on_stop()
1571 rproc->cached_table = kmemdup(rproc->table_ptr, in rproc_reset_rsc_table_on_stop()
1572 rproc->table_sz, GFP_KERNEL); in rproc_reset_rsc_table_on_stop()
1573 if (!rproc->cached_table) in rproc_reset_rsc_table_on_stop()
1580 kfree(rproc->clean_table); in rproc_reset_rsc_table_on_stop()
1587 rproc->table_ptr = rproc->cached_table; in rproc_reset_rsc_table_on_stop()
1595 static int rproc_attach(struct rproc *rproc) in rproc_attach() argument
1597 struct device *dev = &rproc->dev; in rproc_attach()
1601 * if enabling an IOMMU isn't relevant for this rproc, this is in rproc_attach()
1604 ret = rproc_enable_iommu(rproc); in rproc_attach()
1611 ret = rproc_prepare_device(rproc); in rproc_attach()
1613 dev_err(dev, "can't prepare rproc %s: %d\n", rproc->name, ret); in rproc_attach()
1617 ret = rproc_set_rsc_table(rproc); in rproc_attach()
1624 rproc->max_notifyid = -1; in rproc_attach()
1627 rproc->nb_vdev = 0; in rproc_attach()
1632 * we expect the platform driver to properly set rproc->table_ptr. in rproc_attach()
1634 ret = rproc_handle_resources(rproc, rproc_loading_handlers); in rproc_attach()
1640 /* Allocate carveout resources associated to rproc */ in rproc_attach()
1641 ret = rproc_alloc_registered_carveouts(rproc); in rproc_attach()
1648 ret = __rproc_attach(rproc); in rproc_attach()
1655 rproc_resource_cleanup(rproc); in rproc_attach()
1658 rproc_unprepare_device(rproc); in rproc_attach()
1660 rproc_disable_iommu(rproc); in rproc_attach()
1674 struct rproc *rproc = context; in rproc_auto_boot_callback() local
1676 rproc_boot(rproc); in rproc_auto_boot_callback()
1681 static int rproc_trigger_auto_boot(struct rproc *rproc) in rproc_trigger_auto_boot() argument
1691 if (rproc->state == RPROC_DETACHED) in rproc_trigger_auto_boot()
1692 return rproc_boot(rproc); in rproc_trigger_auto_boot()
1699 rproc->firmware, &rproc->dev, GFP_KERNEL, in rproc_trigger_auto_boot()
1700 rproc, rproc_auto_boot_callback); in rproc_trigger_auto_boot()
1702 dev_err(&rproc->dev, "request_firmware_nowait err: %d\n", ret); in rproc_trigger_auto_boot()
1707 static int rproc_stop(struct rproc *rproc, bool crashed) in rproc_stop() argument
1709 struct device *dev = &rproc->dev; in rproc_stop()
1713 if (!rproc->ops->stop) in rproc_stop()
1717 rproc_stop_subdevices(rproc, crashed); in rproc_stop()
1720 ret = rproc_reset_rsc_table_on_stop(rproc); in rproc_stop()
1728 ret = rproc->ops->stop(rproc); in rproc_stop()
1730 dev_err(dev, "can't stop rproc: %d\n", ret); in rproc_stop()
1734 rproc_unprepare_subdevices(rproc); in rproc_stop()
1736 rproc->state = RPROC_OFFLINE; in rproc_stop()
1738 dev_info(dev, "stopped remote processor %s\n", rproc->name); in rproc_stop()
1746 static int __rproc_detach(struct rproc *rproc) in __rproc_detach() argument
1748 struct device *dev = &rproc->dev; in __rproc_detach()
1752 if (!rproc->ops->detach) in __rproc_detach()
1756 rproc_stop_subdevices(rproc, false); in __rproc_detach()
1759 ret = rproc_reset_rsc_table_on_detach(rproc); in __rproc_detach()
1766 ret = rproc->ops->detach(rproc); in __rproc_detach()
1768 dev_err(dev, "can't detach from rproc: %d\n", ret); in __rproc_detach()
1772 rproc_unprepare_subdevices(rproc); in __rproc_detach()
1774 rproc->state = RPROC_DETACHED; in __rproc_detach()
1776 dev_info(dev, "detached remote processor %s\n", rproc->name); in __rproc_detach()
1781 static int rproc_attach_recovery(struct rproc *rproc) in rproc_attach_recovery() argument
1785 ret = __rproc_detach(rproc); in rproc_attach_recovery()
1789 return __rproc_attach(rproc); in rproc_attach_recovery()
1792 static int rproc_boot_recovery(struct rproc *rproc) in rproc_boot_recovery() argument
1795 struct device *dev = &rproc->dev; in rproc_boot_recovery()
1798 ret = rproc_stop(rproc, true); in rproc_boot_recovery()
1803 rproc->ops->coredump(rproc); in rproc_boot_recovery()
1806 ret = request_firmware(&firmware_p, rproc->firmware, dev); in rproc_boot_recovery()
1813 ret = rproc_start(rproc, firmware_p); in rproc_boot_recovery()
1822 * @rproc: the remote processor
1832 int rproc_trigger_recovery(struct rproc *rproc) in rproc_trigger_recovery() argument
1834 struct device *dev = &rproc->dev; in rproc_trigger_recovery()
1837 ret = mutex_lock_interruptible(&rproc->lock); in rproc_trigger_recovery()
1842 if (rproc->state != RPROC_CRASHED) in rproc_trigger_recovery()
1845 dev_err(dev, "recovering %s\n", rproc->name); in rproc_trigger_recovery()
1847 if (rproc_has_feature(rproc, RPROC_FEAT_ATTACH_ON_RECOVERY)) in rproc_trigger_recovery()
1848 ret = rproc_attach_recovery(rproc); in rproc_trigger_recovery()
1850 ret = rproc_boot_recovery(rproc); in rproc_trigger_recovery()
1853 mutex_unlock(&rproc->lock); in rproc_trigger_recovery()
1866 struct rproc *rproc = container_of(work, struct rproc, crash_handler); in rproc_crash_handler_work() local
1867 struct device *dev = &rproc->dev; in rproc_crash_handler_work()
1871 mutex_lock(&rproc->lock); in rproc_crash_handler_work()
1873 if (rproc->state == RPROC_CRASHED) { in rproc_crash_handler_work()
1875 mutex_unlock(&rproc->lock); in rproc_crash_handler_work()
1879 if (rproc->state == RPROC_OFFLINE) { in rproc_crash_handler_work()
1881 mutex_unlock(&rproc->lock); in rproc_crash_handler_work()
1885 rproc->state = RPROC_CRASHED; in rproc_crash_handler_work()
1886 dev_err(dev, "handling crash #%u in %s\n", ++rproc->crash_cnt, in rproc_crash_handler_work()
1887 rproc->name); in rproc_crash_handler_work()
1889 mutex_unlock(&rproc->lock); in rproc_crash_handler_work()
1891 if (!rproc->recovery_disabled) in rproc_crash_handler_work()
1892 rproc_trigger_recovery(rproc); in rproc_crash_handler_work()
1895 pm_relax(rproc->dev.parent); in rproc_crash_handler_work()
1900 * @rproc: handle of a remote processor
1909 int rproc_boot(struct rproc *rproc) in rproc_boot() argument
1915 if (!rproc) { in rproc_boot()
1916 pr_err("invalid rproc handle\n"); in rproc_boot()
1920 dev = &rproc->dev; in rproc_boot()
1922 ret = mutex_lock_interruptible(&rproc->lock); in rproc_boot()
1924 dev_err(dev, "can't lock rproc %s: %d\n", rproc->name, ret); in rproc_boot()
1928 if (rproc->state == RPROC_DELETED) { in rproc_boot()
1930 dev_err(dev, "can't boot deleted rproc %s\n", rproc->name); in rproc_boot()
1934 /* skip the boot or attach process if rproc is already powered up */ in rproc_boot()
1935 if (atomic_inc_return(&rproc->power) > 1) { in rproc_boot()
1940 if (rproc->state == RPROC_DETACHED) { in rproc_boot()
1941 dev_info(dev, "attaching to %s\n", rproc->name); in rproc_boot()
1943 ret = rproc_attach(rproc); in rproc_boot()
1945 dev_info(dev, "powering up %s\n", rproc->name); in rproc_boot()
1948 ret = request_firmware(&firmware_p, rproc->firmware, dev); in rproc_boot()
1954 ret = rproc_fw_boot(rproc, firmware_p); in rproc_boot()
1961 atomic_dec(&rproc->power); in rproc_boot()
1963 mutex_unlock(&rproc->lock); in rproc_boot()
1970 * @rproc: the remote processor
1974 * In case @rproc is still being used by an additional user(s), then
1982 * - we're not decrementing the rproc's refcount, only the power refcount.
1983 * which means that the @rproc handle stays valid even after rproc_shutdown()
1989 int rproc_shutdown(struct rproc *rproc) in rproc_shutdown() argument
1991 struct device *dev = &rproc->dev; in rproc_shutdown()
1994 ret = mutex_lock_interruptible(&rproc->lock); in rproc_shutdown()
1996 dev_err(dev, "can't lock rproc %s: %d\n", rproc->name, ret); in rproc_shutdown()
2000 if (rproc->state != RPROC_RUNNING && in rproc_shutdown()
2001 rproc->state != RPROC_ATTACHED) { in rproc_shutdown()
2007 if (!atomic_dec_and_test(&rproc->power)) in rproc_shutdown()
2010 ret = rproc_stop(rproc, false); in rproc_shutdown()
2012 atomic_inc(&rproc->power); in rproc_shutdown()
2017 rproc_resource_cleanup(rproc); in rproc_shutdown()
2020 rproc_unprepare_device(rproc); in rproc_shutdown()
2022 rproc_disable_iommu(rproc); in rproc_shutdown()
2025 kfree(rproc->cached_table); in rproc_shutdown()
2026 rproc->cached_table = NULL; in rproc_shutdown()
2027 rproc->table_ptr = NULL; in rproc_shutdown()
2028 rproc->table_sz = 0; in rproc_shutdown()
2030 mutex_unlock(&rproc->lock); in rproc_shutdown()
2039 * @rproc: the remote processor
2043 * In case @rproc is still being used by an additional user(s), then
2055 int rproc_detach(struct rproc *rproc) in rproc_detach() argument
2057 struct device *dev = &rproc->dev; in rproc_detach()
2060 ret = mutex_lock_interruptible(&rproc->lock); in rproc_detach()
2062 dev_err(dev, "can't lock rproc %s: %d\n", rproc->name, ret); in rproc_detach()
2066 if (rproc->state != RPROC_ATTACHED) { in rproc_detach()
2072 if (!atomic_dec_and_test(&rproc->power)) { in rproc_detach()
2077 ret = __rproc_detach(rproc); in rproc_detach()
2079 atomic_inc(&rproc->power); in rproc_detach()
2084 rproc_resource_cleanup(rproc); in rproc_detach()
2087 rproc_unprepare_device(rproc); in rproc_detach()
2089 rproc_disable_iommu(rproc); in rproc_detach()
2092 kfree(rproc->cached_table); in rproc_detach()
2093 rproc->cached_table = NULL; in rproc_detach()
2094 rproc->table_ptr = NULL; in rproc_detach()
2096 mutex_unlock(&rproc->lock); in rproc_detach()
2103 * @phandle: phandle to the rproc
2105 * Finds an rproc handle using the remote processor's phandle, and then
2106 * return a handle to the rproc.
2109 * use rproc_put() to decrement it back once rproc isn't needed anymore.
2111 * Return: rproc handle on success, and NULL on failure
2114 struct rproc *rproc_get_by_phandle(phandle phandle) in rproc_get_by_phandle()
2116 struct rproc *rproc = NULL, *r; in rproc_get_by_phandle() local
2152 rproc = r; in rproc_get_by_phandle()
2153 get_device(&rproc->dev); in rproc_get_by_phandle()
2161 return rproc; in rproc_get_by_phandle()
2164 struct rproc *rproc_get_by_phandle(phandle phandle) in rproc_get_by_phandle()
2173 * @rproc: rproc handle to which the new firmware is being assigned
2189 int rproc_set_firmware(struct rproc *rproc, const char *fw_name) in rproc_set_firmware() argument
2195 if (!rproc || !fw_name) in rproc_set_firmware()
2198 dev = rproc->dev.parent; in rproc_set_firmware()
2200 ret = mutex_lock_interruptible(&rproc->lock); in rproc_set_firmware()
2202 dev_err(dev, "can't lock rproc %s: %d\n", rproc->name, ret); in rproc_set_firmware()
2206 if (rproc->state != RPROC_OFFLINE) { in rproc_set_firmware()
2225 kfree_const(rproc->firmware); in rproc_set_firmware()
2226 rproc->firmware = p; in rproc_set_firmware()
2229 mutex_unlock(&rproc->lock); in rproc_set_firmware()
2234 static int rproc_validate(struct rproc *rproc) in rproc_validate() argument
2236 switch (rproc->state) { in rproc_validate()
2242 if (!rproc->ops->start) in rproc_validate()
2250 if (!rproc->ops->attach) in rproc_validate()
2257 if (rproc->cached_table) in rproc_validate()
2273 * @rproc: the remote processor handle to register
2275 * Registers @rproc with the remoteproc framework, after it has been
2278 * This is called by the platform-specific rproc implementation, whenever
2282 * context, which will look for virtio devices supported by the rproc's
2291 int rproc_add(struct rproc *rproc) in rproc_add() argument
2293 struct device *dev = &rproc->dev; in rproc_add()
2296 ret = rproc_validate(rproc); in rproc_add()
2301 ret = rproc_char_device_add(rproc); in rproc_add()
2311 dev_info(dev, "%s is available\n", rproc->name); in rproc_add()
2314 rproc_create_debug_dir(rproc); in rproc_add()
2316 /* if rproc is marked always-on, request it to boot */ in rproc_add()
2317 if (rproc->auto_boot) { in rproc_add()
2318 ret = rproc_trigger_auto_boot(rproc); in rproc_add()
2325 list_add_rcu(&rproc->node, &rproc_list); in rproc_add()
2331 rproc_delete_debug_dir(rproc); in rproc_add()
2334 rproc_char_device_remove(rproc); in rproc_add()
2339 static void devm_rproc_remove(void *rproc) in devm_rproc_remove() argument
2341 rproc_del(rproc); in devm_rproc_remove()
2347 * @rproc: the remote processor handle to register
2349 * This function performs like rproc_add() but the registered rproc device will
2354 int devm_rproc_add(struct device *dev, struct rproc *rproc) in devm_rproc_add() argument
2358 err = rproc_add(rproc); in devm_rproc_add()
2362 return devm_add_action_or_reset(dev, devm_rproc_remove, rproc); in devm_rproc_add()
2368 * @dev: the rproc's device
2377 struct rproc *rproc = container_of(dev, struct rproc, dev); in rproc_type_release() local
2379 dev_info(&rproc->dev, "releasing %s\n", rproc->name); in rproc_type_release()
2381 idr_destroy(&rproc->notifyids); in rproc_type_release()
2383 if (rproc->index >= 0) in rproc_type_release()
2384 ida_free(&rproc_dev_index, rproc->index); in rproc_type_release()
2386 kfree_const(rproc->firmware); in rproc_type_release()
2387 kfree_const(rproc->name); in rproc_type_release()
2388 kfree(rproc->ops); in rproc_type_release()
2389 kfree(rproc); in rproc_type_release()
2397 static int rproc_alloc_firmware(struct rproc *rproc, in rproc_alloc_firmware() argument
2409 p = kasprintf(GFP_KERNEL, "rproc-%s-fw", name); in rproc_alloc_firmware()
2414 rproc->firmware = p; in rproc_alloc_firmware()
2419 static int rproc_alloc_ops(struct rproc *rproc, const struct rproc_ops *ops) in rproc_alloc_ops() argument
2421 rproc->ops = kmemdup(ops, sizeof(*ops), GFP_KERNEL); in rproc_alloc_ops()
2422 if (!rproc->ops) in rproc_alloc_ops()
2426 if (!rproc->ops->coredump) in rproc_alloc_ops()
2427 rproc->ops->coredump = rproc_coredump; in rproc_alloc_ops()
2429 if (rproc->ops->load) in rproc_alloc_ops()
2433 rproc->ops->load = rproc_elf_load_segments; in rproc_alloc_ops()
2434 rproc->ops->parse_fw = rproc_elf_load_rsc_table; in rproc_alloc_ops()
2435 rproc->ops->find_loaded_rsc_table = rproc_elf_find_loaded_rsc_table; in rproc_alloc_ops()
2436 rproc->ops->sanity_check = rproc_elf_sanity_check; in rproc_alloc_ops()
2437 rproc->ops->get_boot_addr = rproc_elf_get_boot_addr; in rproc_alloc_ops()
2448 * @len: length of private data needed by the rproc driver (in bytes)
2453 * This function should be used by rproc implementations during initialization
2456 * After creating an rproc handle using this function, and when ready,
2460 * Note: _never_ directly deallocate @rproc, even if it was not registered
2463 * Return: new rproc pointer on success, and NULL on failure
2465 struct rproc *rproc_alloc(struct device *dev, const char *name, in rproc_alloc()
2469 struct rproc *rproc; in rproc_alloc() local
2474 rproc = kzalloc(sizeof(struct rproc) + len, GFP_KERNEL); in rproc_alloc()
2475 if (!rproc) in rproc_alloc()
2478 rproc->priv = &rproc[1]; in rproc_alloc()
2479 rproc->auto_boot = true; in rproc_alloc()
2480 rproc->elf_class = ELFCLASSNONE; in rproc_alloc()
2481 rproc->elf_machine = EM_NONE; in rproc_alloc()
2483 device_initialize(&rproc->dev); in rproc_alloc()
2484 rproc->dev.parent = dev; in rproc_alloc()
2485 rproc->dev.type = &rproc_type; in rproc_alloc()
2486 rproc->dev.class = &rproc_class; in rproc_alloc()
2487 rproc->dev.driver_data = rproc; in rproc_alloc()
2488 idr_init(&rproc->notifyids); in rproc_alloc()
2491 rproc->index = ida_alloc(&rproc_dev_index, GFP_KERNEL); in rproc_alloc()
2492 if (rproc->index < 0) { in rproc_alloc()
2493 dev_err(dev, "ida_alloc failed: %d\n", rproc->index); in rproc_alloc()
2497 rproc->name = kstrdup_const(name, GFP_KERNEL); in rproc_alloc()
2498 if (!rproc->name) in rproc_alloc()
2501 if (rproc_alloc_firmware(rproc, name, firmware)) in rproc_alloc()
2504 if (rproc_alloc_ops(rproc, ops)) in rproc_alloc()
2507 dev_set_name(&rproc->dev, "remoteproc%d", rproc->index); in rproc_alloc()
2509 atomic_set(&rproc->power, 0); in rproc_alloc()
2511 mutex_init(&rproc->lock); in rproc_alloc()
2513 INIT_LIST_HEAD(&rproc->carveouts); in rproc_alloc()
2514 INIT_LIST_HEAD(&rproc->mappings); in rproc_alloc()
2515 INIT_LIST_HEAD(&rproc->traces); in rproc_alloc()
2516 INIT_LIST_HEAD(&rproc->rvdevs); in rproc_alloc()
2517 INIT_LIST_HEAD(&rproc->subdevs); in rproc_alloc()
2518 INIT_LIST_HEAD(&rproc->dump_segments); in rproc_alloc()
2520 INIT_WORK(&rproc->crash_handler, rproc_crash_handler_work); in rproc_alloc()
2522 rproc->state = RPROC_OFFLINE; in rproc_alloc()
2524 return rproc; in rproc_alloc()
2527 put_device(&rproc->dev); in rproc_alloc()
2534 * @rproc: the remote processor handle
2536 * This function decrements the rproc dev refcount.
2538 * If no one holds any reference to rproc anymore, then its refcount would
2541 void rproc_free(struct rproc *rproc) in rproc_free() argument
2543 put_device(&rproc->dev); in rproc_free()
2548 * rproc_put() - release rproc reference
2549 * @rproc: the remote processor handle
2551 * This function decrements the rproc dev refcount.
2553 * If no one holds any reference to rproc anymore, then its refcount would
2556 void rproc_put(struct rproc *rproc) in rproc_put() argument
2558 if (rproc->dev.parent->driver) in rproc_put()
2559 module_put(rproc->dev.parent->driver->owner); in rproc_put()
2561 module_put(rproc->dev.parent->parent->driver->owner); in rproc_put()
2563 put_device(&rproc->dev); in rproc_put()
2569 * @rproc: rproc handle to unregister
2571 * This function should be called when the platform specific rproc
2572 * implementation decides to remove the rproc device. it should
2576 * After rproc_del() returns, @rproc isn't freed yet, because
2580 * Return: 0 on success and -EINVAL if @rproc isn't valid
2582 int rproc_del(struct rproc *rproc) in rproc_del() argument
2584 if (!rproc) in rproc_del()
2587 /* TODO: make sure this works with rproc->power > 1 */ in rproc_del()
2588 rproc_shutdown(rproc); in rproc_del()
2590 mutex_lock(&rproc->lock); in rproc_del()
2591 rproc->state = RPROC_DELETED; in rproc_del()
2592 mutex_unlock(&rproc->lock); in rproc_del()
2594 rproc_delete_debug_dir(rproc); in rproc_del()
2596 /* the rproc is downref'ed as soon as it's removed from the klist */ in rproc_del()
2598 list_del_rcu(&rproc->node); in rproc_del()
2604 device_del(&rproc->dev); in rproc_del()
2605 rproc_char_device_remove(rproc); in rproc_del()
2613 rproc_free(*(struct rproc **)res); in devm_rproc_free()
2622 * @len: length of private data needed by the rproc driver (in bytes)
2624 * This function performs like rproc_alloc() but the acquired rproc device will
2627 * Return: new rproc instance, or NULL on failure
2629 struct rproc *devm_rproc_alloc(struct device *dev, const char *name, in devm_rproc_alloc()
2633 struct rproc **ptr, *rproc; in devm_rproc_alloc() local
2639 rproc = rproc_alloc(dev, name, ops, firmware, len); in devm_rproc_alloc()
2640 if (rproc) { in devm_rproc_alloc()
2641 *ptr = rproc; in devm_rproc_alloc()
2647 return rproc; in devm_rproc_alloc()
2653 * @rproc: rproc handle to add the subdevice to
2658 void rproc_add_subdev(struct rproc *rproc, struct rproc_subdev *subdev) in rproc_add_subdev() argument
2660 list_add_tail(&subdev->node, &rproc->subdevs); in rproc_add_subdev()
2666 * @rproc: rproc handle to remove the subdevice from
2669 void rproc_remove_subdev(struct rproc *rproc, struct rproc_subdev *subdev) in rproc_remove_subdev() argument
2676 * rproc_get_by_child() - acquire rproc handle of @dev's ancestor
2679 * Return: the ancestor rproc instance, or NULL if not found
2681 struct rproc *rproc_get_by_child(struct device *dev) in rproc_get_by_child()
2693 * rproc_report_crash() - rproc crash reporter function
2694 * @rproc: remote processor
2703 void rproc_report_crash(struct rproc *rproc, enum rproc_crash_type type) in rproc_report_crash() argument
2705 if (!rproc) { in rproc_report_crash()
2706 pr_err("NULL rproc pointer\n"); in rproc_report_crash()
2711 pm_stay_awake(rproc->dev.parent); in rproc_report_crash()
2713 dev_err(&rproc->dev, "crash detected in %s: type %s\n", in rproc_report_crash()
2714 rproc->name, rproc_crash_to_string(type)); in rproc_report_crash()
2716 queue_work(rproc_recovery_wq, &rproc->crash_handler); in rproc_report_crash()
2724 struct rproc *rproc; in rproc_panic_handler() local
2728 list_for_each_entry_rcu(rproc, &rproc_list, node) { in rproc_panic_handler()
2729 if (!rproc->ops->panic) in rproc_panic_handler()
2732 if (rproc->state != RPROC_RUNNING && in rproc_panic_handler()
2733 rproc->state != RPROC_ATTACHED) in rproc_panic_handler()
2736 d = rproc->ops->panic(rproc); in rproc_panic_handler()