Lines Matching full:rproc

50 typedef int (*rproc_handle_resource_t)(struct rproc *rproc,
53 static int rproc_alloc_carveout(struct rproc *rproc,
55 static int rproc_release_carveout(struct rproc *rproc,
87 struct rproc *rproc = token; in rproc_iommu_fault() local
91 rproc_report_crash(rproc, RPROC_MMUFAULT); in rproc_iommu_fault()
100 static int rproc_enable_iommu(struct rproc *rproc) in rproc_enable_iommu() argument
103 struct device *dev = rproc->dev.parent; in rproc_enable_iommu()
106 if (!rproc->has_iommu) { in rproc_enable_iommu()
117 iommu_set_fault_handler(domain, rproc_iommu_fault, rproc); in rproc_enable_iommu()
125 rproc->domain = domain; in rproc_enable_iommu()
134 static void rproc_disable_iommu(struct rproc *rproc) in rproc_disable_iommu() argument
136 struct iommu_domain *domain = rproc->domain; in rproc_disable_iommu()
137 struct device *dev = rproc->dev.parent; in rproc_disable_iommu()
165 * @rproc: handle of a remote processor
186 * Note: phys_to_virt(iommu_iova_to_phys(rproc->domain, da)) will work too,
193 void *rproc_da_to_va(struct rproc *rproc, u64 da, size_t len, bool *is_iomem) in rproc_da_to_va() argument
198 if (rproc->ops->da_to_va) { in rproc_da_to_va()
199 ptr = rproc->ops->da_to_va(rproc, da, len, is_iomem); in rproc_da_to_va()
204 list_for_each_entry(carveout, &rproc->carveouts, node) { in rproc_da_to_va()
234 * @rproc: handle of a remote processor
239 * (physically contiguous memory regions) before rproc firmware loading and
252 rproc_find_carveout_by_name(struct rproc *rproc, const char *name, ...) in rproc_find_carveout_by_name() argument
265 list_for_each_entry(carveout, &rproc->carveouts, node) { in rproc_find_carveout_by_name()
278 * @rproc: handle of a remote processor
290 static int rproc_check_carveout_da(struct rproc *rproc, in rproc_check_carveout_da() argument
293 struct device *dev = &rproc->dev; in rproc_check_carveout_da()
327 struct rproc *rproc = rvdev->rproc; in rproc_alloc_vring() local
328 struct device *dev = &rproc->dev; in rproc_alloc_vring()
338 rsc = (void *)rproc->table_ptr + rvdev->rsc_offset; in rproc_alloc_vring()
341 mem = rproc_find_carveout_by_name(rproc, "vdev%dvring%d", rvdev->index, in rproc_alloc_vring()
344 if (rproc_check_carveout_da(rproc, mem, rsc->vring[i].da, size)) in rproc_alloc_vring()
359 rproc_add_carveout(rproc, mem); in rproc_alloc_vring()
363 * Assign an rproc-wide unique index for this vring in rproc_alloc_vring()
367 ret = idr_alloc(&rproc->notifyids, rvring, 0, 0, GFP_KERNEL); in rproc_alloc_vring()
375 if (notifyid > rproc->max_notifyid) in rproc_alloc_vring()
376 rproc->max_notifyid = notifyid; in rproc_alloc_vring()
380 /* Let the rproc know the notifyid of this vring.*/ in rproc_alloc_vring()
388 struct rproc *rproc = rvdev->rproc; in rproc_parse_vring() local
389 struct device *dev = &rproc->dev; in rproc_parse_vring()
412 struct rproc *rproc = rvring->rvdev->rproc; in rproc_free_vring() local
416 idr_remove(&rproc->notifyids, rvring->notifyid); in rproc_free_vring()
421 * such and as per rproc_stop(), rproc->table_ptr points to the cached in rproc_free_vring()
422 * resource table (rproc->cached_table). The cached resource table is in rproc_free_vring()
429 if (rproc->table_ptr) { in rproc_free_vring()
430 rsc = (void *)rproc->table_ptr + rvring->rvdev->rsc_offset; in rproc_free_vring()
436 void rproc_add_rvdev(struct rproc *rproc, struct rproc_vdev *rvdev) in rproc_add_rvdev() argument
438 if (rvdev && rproc) in rproc_add_rvdev()
439 list_add_tail(&rvdev->node, &rproc->rvdevs); in rproc_add_rvdev()
449 * @rproc: the remote processor
475 static int rproc_handle_vdev(struct rproc *rproc, void *ptr, in rproc_handle_vdev() argument
479 struct device *dev = &rproc->dev; in rproc_handle_vdev()
508 rvdev_data.index = rproc->nb_vdev++; in rproc_handle_vdev()
512 pdev = platform_device_register_data(dev, "rproc-virtio", rvdev_data.index, &rvdev_data, in rproc_handle_vdev()
515 dev_err(dev, "failed to create rproc-virtio device\n"); in rproc_handle_vdev()
524 * @rproc: the remote processor
539 static int rproc_handle_trace(struct rproc *rproc, void *ptr, in rproc_handle_trace() argument
544 struct device *dev = &rproc->dev; in rproc_handle_trace()
566 /* set pointer on rproc device */ in rproc_handle_trace()
567 trace->rproc = rproc; in rproc_handle_trace()
570 snprintf(name, sizeof(name), "trace%d", rproc->num_traces); in rproc_handle_trace()
573 trace->tfile = rproc_create_trace_file(name, rproc, trace); in rproc_handle_trace()
575 list_add_tail(&trace->node, &rproc->traces); in rproc_handle_trace()
577 rproc->num_traces++; in rproc_handle_trace()
587 * @rproc: remote processor handle
613 static int rproc_handle_devmem(struct rproc *rproc, void *ptr, in rproc_handle_devmem() argument
618 struct device *dev = &rproc->dev; in rproc_handle_devmem()
622 if (!rproc->domain) in rproc_handle_devmem()
640 ret = iommu_map(rproc->domain, rsc->da, rsc->pa, rsc->len, rsc->flags); in rproc_handle_devmem()
655 list_add_tail(&mapping->node, &rproc->mappings); in rproc_handle_devmem()
669 * @rproc: rproc handle
677 static int rproc_alloc_carveout(struct rproc *rproc, in rproc_alloc_carveout() argument
681 struct device *dev = &rproc->dev; in rproc_alloc_carveout()
697 if (mem->da != FW_RSC_ADDR_ANY && !rproc->domain) { in rproc_alloc_carveout()
726 if (mem->da != FW_RSC_ADDR_ANY && rproc->domain) { in rproc_alloc_carveout()
733 ret = iommu_map(rproc->domain, mem->da, dma, mem->len, in rproc_alloc_carveout()
749 list_add_tail(&mapping->node, &rproc->mappings); in rproc_alloc_carveout()
777 * @rproc: rproc handle
781 * rproc_alloc_carveout() function by @rproc.
785 static int rproc_release_carveout(struct rproc *rproc, in rproc_release_carveout() argument
788 struct device *dev = &rproc->dev; in rproc_release_carveout()
797 * @rproc: rproc handle
811 * needed to map it (in case @rproc is using an IOMMU). Reducing the TLB
816 static int rproc_handle_carveout(struct rproc *rproc, in rproc_handle_carveout() argument
821 struct device *dev = &rproc->dev; in rproc_handle_carveout()
841 carveout = rproc_find_carveout_by_name(rproc, rsc->name); in rproc_handle_carveout()
850 if (rproc_check_carveout_da(rproc, carveout, rsc->da, rsc->len)) in rproc_handle_carveout()
871 rproc_add_carveout(rproc, carveout); in rproc_handle_carveout()
878 * @rproc: rproc handle
881 * This function registers specified memory entry in @rproc carveouts list.
884 void rproc_add_carveout(struct rproc *rproc, struct rproc_mem_entry *mem) in rproc_add_carveout() argument
886 list_add_tail(&mem->node, &rproc->carveouts); in rproc_add_carveout()
910 int (*alloc)(struct rproc *, struct rproc_mem_entry *), in rproc_mem_entry_init() argument
911 int (*release)(struct rproc *, struct rproc_mem_entry *), in rproc_mem_entry_init() argument
979 * @dev: pointer on device struct representing a rproc
1012 static int rproc_handle_resources(struct rproc *rproc, in rproc_handle_resources() argument
1015 struct device *dev = &rproc->dev; in rproc_handle_resources()
1019 if (!rproc->table_ptr) in rproc_handle_resources()
1022 for (i = 0; i < rproc->table_ptr->num; i++) { in rproc_handle_resources()
1023 int offset = rproc->table_ptr->offset[i]; in rproc_handle_resources()
1024 struct fw_rsc_hdr *hdr = (void *)rproc->table_ptr + offset; in rproc_handle_resources()
1025 int avail = rproc->table_sz - offset - sizeof(*hdr); in rproc_handle_resources()
1038 ret = rproc_handle_rsc(rproc, hdr->type, rsc, in rproc_handle_resources()
1059 ret = handler(rproc, rsc, offset + sizeof(*hdr), avail); in rproc_handle_resources()
1067 static int rproc_prepare_subdevices(struct rproc *rproc) in rproc_prepare_subdevices() argument
1072 list_for_each_entry(subdev, &rproc->subdevs, node) { in rproc_prepare_subdevices()
1083 list_for_each_entry_continue_reverse(subdev, &rproc->subdevs, node) { in rproc_prepare_subdevices()
1091 static int rproc_start_subdevices(struct rproc *rproc) in rproc_start_subdevices() argument
1096 list_for_each_entry(subdev, &rproc->subdevs, node) { in rproc_start_subdevices()
1107 list_for_each_entry_continue_reverse(subdev, &rproc->subdevs, node) { in rproc_start_subdevices()
1115 static void rproc_stop_subdevices(struct rproc *rproc, bool crashed) in rproc_stop_subdevices() argument
1119 list_for_each_entry_reverse(subdev, &rproc->subdevs, node) { in rproc_stop_subdevices()
1125 static void rproc_unprepare_subdevices(struct rproc *rproc) in rproc_unprepare_subdevices() argument
1129 list_for_each_entry_reverse(subdev, &rproc->subdevs, node) { in rproc_unprepare_subdevices()
1138 * @rproc: the remote processor handle
1146 static int rproc_alloc_registered_carveouts(struct rproc *rproc) in rproc_alloc_registered_carveouts() argument
1150 struct device *dev = &rproc->dev; in rproc_alloc_registered_carveouts()
1154 list_for_each_entry_safe(entry, tmp, &rproc->carveouts, node) { in rproc_alloc_registered_carveouts()
1156 ret = entry->alloc(rproc, entry); in rproc_alloc_registered_carveouts()
1166 rsc = (void *)rproc->table_ptr + entry->rsc_offset; in rproc_alloc_registered_carveouts()
1208 * @rproc: rproc handle
1210 * This function will free all resources acquired for @rproc, and it
1211 * is called whenever @rproc either shuts down or fails to boot.
1213 void rproc_resource_cleanup(struct rproc *rproc) in rproc_resource_cleanup() argument
1218 struct device *dev = &rproc->dev; in rproc_resource_cleanup()
1221 list_for_each_entry_safe(trace, ttmp, &rproc->traces, node) { in rproc_resource_cleanup()
1223 rproc->num_traces--; in rproc_resource_cleanup()
1229 list_for_each_entry_safe(entry, tmp, &rproc->mappings, node) { in rproc_resource_cleanup()
1232 unmapped = iommu_unmap(rproc->domain, entry->da, entry->len); in rproc_resource_cleanup()
1244 list_for_each_entry_safe(entry, tmp, &rproc->carveouts, node) { in rproc_resource_cleanup()
1246 entry->release(rproc, entry); in rproc_resource_cleanup()
1252 list_for_each_entry_safe(rvdev, rvtmp, &rproc->rvdevs, node) in rproc_resource_cleanup()
1255 rproc_coredump_cleanup(rproc); in rproc_resource_cleanup()
1259 static int rproc_start(struct rproc *rproc, const struct firmware *fw) in rproc_start() argument
1262 struct device *dev = &rproc->dev; in rproc_start()
1266 ret = rproc_load_segments(rproc, fw); in rproc_start()
1273 * The starting device has been given the rproc->cached_table as the in rproc_start()
1280 loaded_table = rproc_find_loaded_rsc_table(rproc, fw); in rproc_start()
1282 memcpy(loaded_table, rproc->cached_table, rproc->table_sz); in rproc_start()
1283 rproc->table_ptr = loaded_table; in rproc_start()
1286 ret = rproc_prepare_subdevices(rproc); in rproc_start()
1289 rproc->name, ret); in rproc_start()
1294 ret = rproc->ops->start(rproc); in rproc_start()
1296 dev_err(dev, "can't start rproc %s: %d\n", rproc->name, ret); in rproc_start()
1301 ret = rproc_start_subdevices(rproc); in rproc_start()
1304 rproc->name, ret); in rproc_start()
1308 rproc->state = RPROC_RUNNING; in rproc_start()
1310 dev_info(dev, "remote processor %s is now up\n", rproc->name); in rproc_start()
1315 rproc->ops->stop(rproc); in rproc_start()
1317 rproc_unprepare_subdevices(rproc); in rproc_start()
1319 rproc->table_ptr = rproc->cached_table; in rproc_start()
1324 static int __rproc_attach(struct rproc *rproc) in __rproc_attach() argument
1326 struct device *dev = &rproc->dev; in __rproc_attach()
1329 ret = rproc_prepare_subdevices(rproc); in __rproc_attach()
1332 rproc->name, ret); in __rproc_attach()
1337 ret = rproc_attach_device(rproc); in __rproc_attach()
1339 dev_err(dev, "can't attach to rproc %s: %d\n", in __rproc_attach()
1340 rproc->name, ret); in __rproc_attach()
1345 ret = rproc_start_subdevices(rproc); in __rproc_attach()
1348 rproc->name, ret); in __rproc_attach()
1352 rproc->state = RPROC_ATTACHED; in __rproc_attach()
1354 dev_info(dev, "remote processor %s is now attached\n", rproc->name); in __rproc_attach()
1359 rproc->ops->stop(rproc); in __rproc_attach()
1361 rproc_unprepare_subdevices(rproc); in __rproc_attach()
1369 static int rproc_fw_boot(struct rproc *rproc, const struct firmware *fw) in rproc_fw_boot() argument
1371 struct device *dev = &rproc->dev; in rproc_fw_boot()
1372 const char *name = rproc->firmware; in rproc_fw_boot()
1375 ret = rproc_fw_sanity_check(rproc, fw); in rproc_fw_boot()
1382 * if enabling an IOMMU isn't relevant for this rproc, this is in rproc_fw_boot()
1385 ret = rproc_enable_iommu(rproc); in rproc_fw_boot()
1391 /* Prepare rproc for firmware loading if needed */ in rproc_fw_boot()
1392 ret = rproc_prepare_device(rproc); in rproc_fw_boot()
1394 dev_err(dev, "can't prepare rproc %s: %d\n", rproc->name, ret); in rproc_fw_boot()
1398 rproc->bootaddr = rproc_get_boot_addr(rproc, fw); in rproc_fw_boot()
1401 ret = rproc_parse_fw(rproc, fw); in rproc_fw_boot()
1406 rproc->max_notifyid = -1; in rproc_fw_boot()
1409 rproc->nb_vdev = 0; in rproc_fw_boot()
1411 /* handle fw resources which are required to boot rproc */ in rproc_fw_boot()
1412 ret = rproc_handle_resources(rproc, rproc_loading_handlers); in rproc_fw_boot()
1418 /* Allocate carveout resources associated to rproc */ in rproc_fw_boot()
1419 ret = rproc_alloc_registered_carveouts(rproc); in rproc_fw_boot()
1426 ret = rproc_start(rproc, fw); in rproc_fw_boot()
1433 rproc_resource_cleanup(rproc); in rproc_fw_boot()
1434 kfree(rproc->cached_table); in rproc_fw_boot()
1435 rproc->cached_table = NULL; in rproc_fw_boot()
1436 rproc->table_ptr = NULL; in rproc_fw_boot()
1439 rproc_unprepare_device(rproc); in rproc_fw_boot()
1441 rproc_disable_iommu(rproc); in rproc_fw_boot()
1445 static int rproc_set_rsc_table(struct rproc *rproc) in rproc_set_rsc_table() argument
1448 struct device *dev = &rproc->dev; in rproc_set_rsc_table()
1452 table_ptr = rproc_get_loaded_rsc_table(rproc, &table_sz); in rproc_set_rsc_table()
1474 if (rproc->ops->detach) { in rproc_set_rsc_table()
1475 rproc->clean_table = kmemdup(table_ptr, table_sz, GFP_KERNEL); in rproc_set_rsc_table()
1476 if (!rproc->clean_table) in rproc_set_rsc_table()
1479 rproc->clean_table = NULL; in rproc_set_rsc_table()
1482 rproc->cached_table = NULL; in rproc_set_rsc_table()
1483 rproc->table_ptr = table_ptr; in rproc_set_rsc_table()
1484 rproc->table_sz = table_sz; in rproc_set_rsc_table()
1489 static int rproc_reset_rsc_table_on_detach(struct rproc *rproc) in rproc_reset_rsc_table_on_detach() argument
1494 if (!rproc->table_ptr) in rproc_reset_rsc_table_on_detach()
1502 if (WARN_ON(!rproc->clean_table)) in rproc_reset_rsc_table_on_detach()
1506 table_ptr = rproc->table_ptr; in rproc_reset_rsc_table_on_detach()
1515 rproc->cached_table = kmemdup(rproc->table_ptr, in rproc_reset_rsc_table_on_detach()
1516 rproc->table_sz, GFP_KERNEL); in rproc_reset_rsc_table_on_detach()
1517 if (!rproc->cached_table) in rproc_reset_rsc_table_on_detach()
1524 rproc->table_ptr = rproc->cached_table; in rproc_reset_rsc_table_on_detach()
1531 memcpy(table_ptr, rproc->clean_table, rproc->table_sz); in rproc_reset_rsc_table_on_detach()
1537 kfree(rproc->clean_table); in rproc_reset_rsc_table_on_detach()
1542 static int rproc_reset_rsc_table_on_stop(struct rproc *rproc) in rproc_reset_rsc_table_on_stop() argument
1545 if (!rproc->table_ptr) in rproc_reset_rsc_table_on_stop()
1553 if (rproc->cached_table) in rproc_reset_rsc_table_on_stop()
1563 rproc->cached_table = kmemdup(rproc->table_ptr, in rproc_reset_rsc_table_on_stop()
1564 rproc->table_sz, GFP_KERNEL); in rproc_reset_rsc_table_on_stop()
1565 if (!rproc->cached_table) in rproc_reset_rsc_table_on_stop()
1572 kfree(rproc->clean_table); in rproc_reset_rsc_table_on_stop()
1579 rproc->table_ptr = rproc->cached_table; in rproc_reset_rsc_table_on_stop()
1587 static int rproc_attach(struct rproc *rproc) in rproc_attach() argument
1589 struct device *dev = &rproc->dev; in rproc_attach()
1593 * if enabling an IOMMU isn't relevant for this rproc, this is in rproc_attach()
1596 ret = rproc_enable_iommu(rproc); in rproc_attach()
1603 ret = rproc_prepare_device(rproc); in rproc_attach()
1605 dev_err(dev, "can't prepare rproc %s: %d\n", rproc->name, ret); in rproc_attach()
1609 ret = rproc_set_rsc_table(rproc); in rproc_attach()
1616 rproc->max_notifyid = -1; in rproc_attach()
1619 rproc->nb_vdev = 0; in rproc_attach()
1624 * we expect the platform driver to properly set rproc->table_ptr. in rproc_attach()
1626 ret = rproc_handle_resources(rproc, rproc_loading_handlers); in rproc_attach()
1632 /* Allocate carveout resources associated to rproc */ in rproc_attach()
1633 ret = rproc_alloc_registered_carveouts(rproc); in rproc_attach()
1640 ret = __rproc_attach(rproc); in rproc_attach()
1647 rproc_resource_cleanup(rproc); in rproc_attach()
1650 rproc_unprepare_device(rproc); in rproc_attach()
1652 rproc_disable_iommu(rproc); in rproc_attach()
1666 struct rproc *rproc = context; in rproc_auto_boot_callback() local
1668 rproc_boot(rproc); in rproc_auto_boot_callback()
1673 static int rproc_trigger_auto_boot(struct rproc *rproc) in rproc_trigger_auto_boot() argument
1683 if (rproc->state == RPROC_DETACHED) in rproc_trigger_auto_boot()
1684 return rproc_boot(rproc); in rproc_trigger_auto_boot()
1691 rproc->firmware, &rproc->dev, GFP_KERNEL, in rproc_trigger_auto_boot()
1692 rproc, rproc_auto_boot_callback); in rproc_trigger_auto_boot()
1694 dev_err(&rproc->dev, "request_firmware_nowait err: %d\n", ret); in rproc_trigger_auto_boot()
1699 static int rproc_stop(struct rproc *rproc, bool crashed) in rproc_stop() argument
1701 struct device *dev = &rproc->dev; in rproc_stop()
1705 if (!rproc->ops->stop) in rproc_stop()
1709 rproc_stop_subdevices(rproc, crashed); in rproc_stop()
1712 ret = rproc_reset_rsc_table_on_stop(rproc); in rproc_stop()
1720 ret = rproc->ops->stop(rproc); in rproc_stop()
1722 dev_err(dev, "can't stop rproc: %d\n", ret); in rproc_stop()
1726 rproc_unprepare_subdevices(rproc); in rproc_stop()
1728 rproc->state = RPROC_OFFLINE; in rproc_stop()
1730 dev_info(dev, "stopped remote processor %s\n", rproc->name); in rproc_stop()
1738 static int __rproc_detach(struct rproc *rproc) in __rproc_detach() argument
1740 struct device *dev = &rproc->dev; in __rproc_detach()
1744 if (!rproc->ops->detach) in __rproc_detach()
1748 rproc_stop_subdevices(rproc, false); in __rproc_detach()
1751 ret = rproc_reset_rsc_table_on_detach(rproc); in __rproc_detach()
1758 ret = rproc->ops->detach(rproc); in __rproc_detach()
1760 dev_err(dev, "can't detach from rproc: %d\n", ret); in __rproc_detach()
1764 rproc_unprepare_subdevices(rproc); in __rproc_detach()
1766 rproc->state = RPROC_DETACHED; in __rproc_detach()
1768 dev_info(dev, "detached remote processor %s\n", rproc->name); in __rproc_detach()
1773 static int rproc_attach_recovery(struct rproc *rproc) in rproc_attach_recovery() argument
1777 ret = __rproc_detach(rproc); in rproc_attach_recovery()
1781 return __rproc_attach(rproc); in rproc_attach_recovery()
1784 static int rproc_boot_recovery(struct rproc *rproc) in rproc_boot_recovery() argument
1787 struct device *dev = &rproc->dev; in rproc_boot_recovery()
1790 ret = rproc_stop(rproc, true); in rproc_boot_recovery()
1795 rproc->ops->coredump(rproc); in rproc_boot_recovery()
1798 ret = request_firmware(&firmware_p, rproc->firmware, dev); in rproc_boot_recovery()
1805 ret = rproc_start(rproc, firmware_p); in rproc_boot_recovery()
1814 * @rproc: the remote processor
1824 int rproc_trigger_recovery(struct rproc *rproc) in rproc_trigger_recovery() argument
1826 struct device *dev = &rproc->dev; in rproc_trigger_recovery()
1829 ret = mutex_lock_interruptible(&rproc->lock); in rproc_trigger_recovery()
1834 if (rproc->state != RPROC_CRASHED) in rproc_trigger_recovery()
1837 dev_err(dev, "recovering %s\n", rproc->name); in rproc_trigger_recovery()
1839 if (rproc_has_feature(rproc, RPROC_FEAT_ATTACH_ON_RECOVERY)) in rproc_trigger_recovery()
1840 ret = rproc_attach_recovery(rproc); in rproc_trigger_recovery()
1842 ret = rproc_boot_recovery(rproc); in rproc_trigger_recovery()
1845 mutex_unlock(&rproc->lock); in rproc_trigger_recovery()
1858 struct rproc *rproc = container_of(work, struct rproc, crash_handler); in rproc_crash_handler_work() local
1859 struct device *dev = &rproc->dev; in rproc_crash_handler_work()
1863 mutex_lock(&rproc->lock); in rproc_crash_handler_work()
1865 if (rproc->state == RPROC_CRASHED || rproc->state == RPROC_OFFLINE) { in rproc_crash_handler_work()
1867 mutex_unlock(&rproc->lock); in rproc_crash_handler_work()
1871 rproc->state = RPROC_CRASHED; in rproc_crash_handler_work()
1872 dev_err(dev, "handling crash #%u in %s\n", ++rproc->crash_cnt, in rproc_crash_handler_work()
1873 rproc->name); in rproc_crash_handler_work()
1875 mutex_unlock(&rproc->lock); in rproc_crash_handler_work()
1877 if (!rproc->recovery_disabled) in rproc_crash_handler_work()
1878 rproc_trigger_recovery(rproc); in rproc_crash_handler_work()
1880 pm_relax(rproc->dev.parent); in rproc_crash_handler_work()
1885 * @rproc: handle of a remote processor
1894 int rproc_boot(struct rproc *rproc) in rproc_boot() argument
1900 if (!rproc) { in rproc_boot()
1901 pr_err("invalid rproc handle\n"); in rproc_boot()
1905 dev = &rproc->dev; in rproc_boot()
1907 ret = mutex_lock_interruptible(&rproc->lock); in rproc_boot()
1909 dev_err(dev, "can't lock rproc %s: %d\n", rproc->name, ret); in rproc_boot()
1913 if (rproc->state == RPROC_DELETED) { in rproc_boot()
1915 dev_err(dev, "can't boot deleted rproc %s\n", rproc->name); in rproc_boot()
1919 /* skip the boot or attach process if rproc is already powered up */ in rproc_boot()
1920 if (atomic_inc_return(&rproc->power) > 1) { in rproc_boot()
1925 if (rproc->state == RPROC_DETACHED) { in rproc_boot()
1926 dev_info(dev, "attaching to %s\n", rproc->name); in rproc_boot()
1928 ret = rproc_attach(rproc); in rproc_boot()
1930 dev_info(dev, "powering up %s\n", rproc->name); in rproc_boot()
1933 ret = request_firmware(&firmware_p, rproc->firmware, dev); in rproc_boot()
1939 ret = rproc_fw_boot(rproc, firmware_p); in rproc_boot()
1946 atomic_dec(&rproc->power); in rproc_boot()
1948 mutex_unlock(&rproc->lock); in rproc_boot()
1955 * @rproc: the remote processor
1959 * In case @rproc is still being used by an additional user(s), then
1967 * - we're not decrementing the rproc's refcount, only the power refcount.
1968 * which means that the @rproc handle stays valid even after rproc_shutdown()
1974 int rproc_shutdown(struct rproc *rproc) in rproc_shutdown() argument
1976 struct device *dev = &rproc->dev; in rproc_shutdown()
1979 ret = mutex_lock_interruptible(&rproc->lock); in rproc_shutdown()
1981 dev_err(dev, "can't lock rproc %s: %d\n", rproc->name, ret); in rproc_shutdown()
1985 if (rproc->state != RPROC_RUNNING && in rproc_shutdown()
1986 rproc->state != RPROC_ATTACHED) { in rproc_shutdown()
1992 if (!atomic_dec_and_test(&rproc->power)) in rproc_shutdown()
1995 ret = rproc_stop(rproc, false); in rproc_shutdown()
1997 atomic_inc(&rproc->power); in rproc_shutdown()
2002 rproc_resource_cleanup(rproc); in rproc_shutdown()
2005 rproc_unprepare_device(rproc); in rproc_shutdown()
2007 rproc_disable_iommu(rproc); in rproc_shutdown()
2010 kfree(rproc->cached_table); in rproc_shutdown()
2011 rproc->cached_table = NULL; in rproc_shutdown()
2012 rproc->table_ptr = NULL; in rproc_shutdown()
2014 mutex_unlock(&rproc->lock); in rproc_shutdown()
2023 * @rproc: the remote processor
2027 * In case @rproc is still being used by an additional user(s), then
2039 int rproc_detach(struct rproc *rproc) in rproc_detach() argument
2041 struct device *dev = &rproc->dev; in rproc_detach()
2044 ret = mutex_lock_interruptible(&rproc->lock); in rproc_detach()
2046 dev_err(dev, "can't lock rproc %s: %d\n", rproc->name, ret); in rproc_detach()
2050 if (rproc->state != RPROC_ATTACHED) { in rproc_detach()
2056 if (!atomic_dec_and_test(&rproc->power)) { in rproc_detach()
2061 ret = __rproc_detach(rproc); in rproc_detach()
2063 atomic_inc(&rproc->power); in rproc_detach()
2068 rproc_resource_cleanup(rproc); in rproc_detach()
2071 rproc_unprepare_device(rproc); in rproc_detach()
2073 rproc_disable_iommu(rproc); in rproc_detach()
2076 kfree(rproc->cached_table); in rproc_detach()
2077 rproc->cached_table = NULL; in rproc_detach()
2078 rproc->table_ptr = NULL; in rproc_detach()
2080 mutex_unlock(&rproc->lock); in rproc_detach()
2087 * @phandle: phandle to the rproc
2089 * Finds an rproc handle using the remote processor's phandle, and then
2090 * return a handle to the rproc.
2093 * use rproc_put() to decrement it back once rproc isn't needed anymore.
2095 * Return: rproc handle on success, and NULL on failure
2098 struct rproc *rproc_get_by_phandle(phandle phandle) in rproc_get_by_phandle()
2100 struct rproc *rproc = NULL, *r; in rproc_get_by_phandle() local
2116 rproc = r; in rproc_get_by_phandle()
2117 get_device(&rproc->dev); in rproc_get_by_phandle()
2125 return rproc; in rproc_get_by_phandle()
2128 struct rproc *rproc_get_by_phandle(phandle phandle) in rproc_get_by_phandle()
2137 * @rproc: rproc handle to which the new firmware is being assigned
2153 int rproc_set_firmware(struct rproc *rproc, const char *fw_name) in rproc_set_firmware() argument
2159 if (!rproc || !fw_name) in rproc_set_firmware()
2162 dev = rproc->dev.parent; in rproc_set_firmware()
2164 ret = mutex_lock_interruptible(&rproc->lock); in rproc_set_firmware()
2166 dev_err(dev, "can't lock rproc %s: %d\n", rproc->name, ret); in rproc_set_firmware()
2170 if (rproc->state != RPROC_OFFLINE) { in rproc_set_firmware()
2189 kfree_const(rproc->firmware); in rproc_set_firmware()
2190 rproc->firmware = p; in rproc_set_firmware()
2193 mutex_unlock(&rproc->lock); in rproc_set_firmware()
2198 static int rproc_validate(struct rproc *rproc) in rproc_validate() argument
2200 switch (rproc->state) { in rproc_validate()
2206 if (!rproc->ops->start) in rproc_validate()
2214 if (!rproc->ops->attach) in rproc_validate()
2221 if (rproc->cached_table) in rproc_validate()
2237 * @rproc: the remote processor handle to register
2239 * Registers @rproc with the remoteproc framework, after it has been
2242 * This is called by the platform-specific rproc implementation, whenever
2246 * context, which will look for virtio devices supported by the rproc's
2255 int rproc_add(struct rproc *rproc) in rproc_add() argument
2257 struct device *dev = &rproc->dev; in rproc_add()
2260 ret = rproc_validate(rproc); in rproc_add()
2265 ret = rproc_char_device_add(rproc); in rproc_add()
2275 dev_info(dev, "%s is available\n", rproc->name); in rproc_add()
2278 rproc_create_debug_dir(rproc); in rproc_add()
2280 /* if rproc is marked always-on, request it to boot */ in rproc_add()
2281 if (rproc->auto_boot) { in rproc_add()
2282 ret = rproc_trigger_auto_boot(rproc); in rproc_add()
2289 list_add_rcu(&rproc->node, &rproc_list); in rproc_add()
2295 rproc_delete_debug_dir(rproc); in rproc_add()
2298 rproc_char_device_remove(rproc); in rproc_add()
2303 static void devm_rproc_remove(void *rproc) in devm_rproc_remove() argument
2305 rproc_del(rproc); in devm_rproc_remove()
2311 * @rproc: the remote processor handle to register
2313 * This function performs like rproc_add() but the registered rproc device will
2318 int devm_rproc_add(struct device *dev, struct rproc *rproc) in devm_rproc_add() argument
2322 err = rproc_add(rproc); in devm_rproc_add()
2326 return devm_add_action_or_reset(dev, devm_rproc_remove, rproc); in devm_rproc_add()
2332 * @dev: the rproc's device
2341 struct rproc *rproc = container_of(dev, struct rproc, dev); in rproc_type_release() local
2343 dev_info(&rproc->dev, "releasing %s\n", rproc->name); in rproc_type_release()
2345 idr_destroy(&rproc->notifyids); in rproc_type_release()
2347 if (rproc->index >= 0) in rproc_type_release()
2348 ida_free(&rproc_dev_index, rproc->index); in rproc_type_release()
2350 kfree_const(rproc->firmware); in rproc_type_release()
2351 kfree_const(rproc->name); in rproc_type_release()
2352 kfree(rproc->ops); in rproc_type_release()
2353 kfree(rproc); in rproc_type_release()
2361 static int rproc_alloc_firmware(struct rproc *rproc, in rproc_alloc_firmware() argument
2373 p = kasprintf(GFP_KERNEL, "rproc-%s-fw", name); in rproc_alloc_firmware()
2378 rproc->firmware = p; in rproc_alloc_firmware()
2383 static int rproc_alloc_ops(struct rproc *rproc, const struct rproc_ops *ops) in rproc_alloc_ops() argument
2385 rproc->ops = kmemdup(ops, sizeof(*ops), GFP_KERNEL); in rproc_alloc_ops()
2386 if (!rproc->ops) in rproc_alloc_ops()
2390 if (!rproc->ops->coredump) in rproc_alloc_ops()
2391 rproc->ops->coredump = rproc_coredump; in rproc_alloc_ops()
2393 if (rproc->ops->load) in rproc_alloc_ops()
2397 rproc->ops->load = rproc_elf_load_segments; in rproc_alloc_ops()
2398 rproc->ops->parse_fw = rproc_elf_load_rsc_table; in rproc_alloc_ops()
2399 rproc->ops->find_loaded_rsc_table = rproc_elf_find_loaded_rsc_table; in rproc_alloc_ops()
2400 rproc->ops->sanity_check = rproc_elf_sanity_check; in rproc_alloc_ops()
2401 rproc->ops->get_boot_addr = rproc_elf_get_boot_addr; in rproc_alloc_ops()
2412 * @len: length of private data needed by the rproc driver (in bytes)
2417 * This function should be used by rproc implementations during initialization
2420 * After creating an rproc handle using this function, and when ready,
2424 * Note: _never_ directly deallocate @rproc, even if it was not registered
2427 * Return: new rproc pointer on success, and NULL on failure
2429 struct rproc *rproc_alloc(struct device *dev, const char *name, in rproc_alloc()
2433 struct rproc *rproc; in rproc_alloc() local
2438 rproc = kzalloc(sizeof(struct rproc) + len, GFP_KERNEL); in rproc_alloc()
2439 if (!rproc) in rproc_alloc()
2442 rproc->priv = &rproc[1]; in rproc_alloc()
2443 rproc->auto_boot = true; in rproc_alloc()
2444 rproc->elf_class = ELFCLASSNONE; in rproc_alloc()
2445 rproc->elf_machine = EM_NONE; in rproc_alloc()
2447 device_initialize(&rproc->dev); in rproc_alloc()
2448 rproc->dev.parent = dev; in rproc_alloc()
2449 rproc->dev.type = &rproc_type; in rproc_alloc()
2450 rproc->dev.class = &rproc_class; in rproc_alloc()
2451 rproc->dev.driver_data = rproc; in rproc_alloc()
2452 idr_init(&rproc->notifyids); in rproc_alloc()
2454 rproc->name = kstrdup_const(name, GFP_KERNEL); in rproc_alloc()
2455 if (!rproc->name) in rproc_alloc()
2458 if (rproc_alloc_firmware(rproc, name, firmware)) in rproc_alloc()
2461 if (rproc_alloc_ops(rproc, ops)) in rproc_alloc()
2465 rproc->index = ida_alloc(&rproc_dev_index, GFP_KERNEL); in rproc_alloc()
2466 if (rproc->index < 0) { in rproc_alloc()
2467 dev_err(dev, "ida_alloc failed: %d\n", rproc->index); in rproc_alloc()
2471 dev_set_name(&rproc->dev, "remoteproc%d", rproc->index); in rproc_alloc()
2473 atomic_set(&rproc->power, 0); in rproc_alloc()
2475 mutex_init(&rproc->lock); in rproc_alloc()
2477 INIT_LIST_HEAD(&rproc->carveouts); in rproc_alloc()
2478 INIT_LIST_HEAD(&rproc->mappings); in rproc_alloc()
2479 INIT_LIST_HEAD(&rproc->traces); in rproc_alloc()
2480 INIT_LIST_HEAD(&rproc->rvdevs); in rproc_alloc()
2481 INIT_LIST_HEAD(&rproc->subdevs); in rproc_alloc()
2482 INIT_LIST_HEAD(&rproc->dump_segments); in rproc_alloc()
2484 INIT_WORK(&rproc->crash_handler, rproc_crash_handler_work); in rproc_alloc()
2486 rproc->state = RPROC_OFFLINE; in rproc_alloc()
2488 return rproc; in rproc_alloc()
2491 put_device(&rproc->dev); in rproc_alloc()
2498 * @rproc: the remote processor handle
2500 * This function decrements the rproc dev refcount.
2502 * If no one holds any reference to rproc anymore, then its refcount would
2505 void rproc_free(struct rproc *rproc) in rproc_free() argument
2507 put_device(&rproc->dev); in rproc_free()
2512 * rproc_put() - release rproc reference
2513 * @rproc: the remote processor handle
2515 * This function decrements the rproc dev refcount.
2517 * If no one holds any reference to rproc anymore, then its refcount would
2520 void rproc_put(struct rproc *rproc) in rproc_put() argument
2522 module_put(rproc->dev.parent->driver->owner); in rproc_put()
2523 put_device(&rproc->dev); in rproc_put()
2529 * @rproc: rproc handle to unregister
2531 * This function should be called when the platform specific rproc
2532 * implementation decides to remove the rproc device. it should
2536 * After rproc_del() returns, @rproc isn't freed yet, because
2540 * Return: 0 on success and -EINVAL if @rproc isn't valid
2542 int rproc_del(struct rproc *rproc) in rproc_del() argument
2544 if (!rproc) in rproc_del()
2547 /* TODO: make sure this works with rproc->power > 1 */ in rproc_del()
2548 rproc_shutdown(rproc); in rproc_del()
2550 mutex_lock(&rproc->lock); in rproc_del()
2551 rproc->state = RPROC_DELETED; in rproc_del()
2552 mutex_unlock(&rproc->lock); in rproc_del()
2554 rproc_delete_debug_dir(rproc); in rproc_del()
2556 /* the rproc is downref'ed as soon as it's removed from the klist */ in rproc_del()
2558 list_del_rcu(&rproc->node); in rproc_del()
2564 device_del(&rproc->dev); in rproc_del()
2565 rproc_char_device_remove(rproc); in rproc_del()
2573 rproc_free(*(struct rproc **)res); in devm_rproc_free()
2582 * @len: length of private data needed by the rproc driver (in bytes)
2584 * This function performs like rproc_alloc() but the acquired rproc device will
2587 * Return: new rproc instance, or NULL on failure
2589 struct rproc *devm_rproc_alloc(struct device *dev, const char *name, in devm_rproc_alloc()
2593 struct rproc **ptr, *rproc; in devm_rproc_alloc() local
2599 rproc = rproc_alloc(dev, name, ops, firmware, len); in devm_rproc_alloc()
2600 if (rproc) { in devm_rproc_alloc()
2601 *ptr = rproc; in devm_rproc_alloc()
2607 return rproc; in devm_rproc_alloc()
2613 * @rproc: rproc handle to add the subdevice to
2618 void rproc_add_subdev(struct rproc *rproc, struct rproc_subdev *subdev) in rproc_add_subdev() argument
2620 list_add_tail(&subdev->node, &rproc->subdevs); in rproc_add_subdev()
2626 * @rproc: rproc handle to remove the subdevice from
2629 void rproc_remove_subdev(struct rproc *rproc, struct rproc_subdev *subdev) in rproc_remove_subdev() argument
2636 * rproc_get_by_child() - acquire rproc handle of @dev's ancestor
2639 * Return: the ancestor rproc instance, or NULL if not found
2641 struct rproc *rproc_get_by_child(struct device *dev) in rproc_get_by_child()
2653 * rproc_report_crash() - rproc crash reporter function
2654 * @rproc: remote processor
2663 void rproc_report_crash(struct rproc *rproc, enum rproc_crash_type type) in rproc_report_crash() argument
2665 if (!rproc) { in rproc_report_crash()
2666 pr_err("NULL rproc pointer\n"); in rproc_report_crash()
2671 pm_stay_awake(rproc->dev.parent); in rproc_report_crash()
2673 dev_err(&rproc->dev, "crash detected in %s: type %s\n", in rproc_report_crash()
2674 rproc->name, rproc_crash_to_string(type)); in rproc_report_crash()
2676 queue_work(rproc_recovery_wq, &rproc->crash_handler); in rproc_report_crash()
2684 struct rproc *rproc; in rproc_panic_handler() local
2688 list_for_each_entry_rcu(rproc, &rproc_list, node) { in rproc_panic_handler()
2689 if (!rproc->ops->panic) in rproc_panic_handler()
2692 if (rproc->state != RPROC_RUNNING && in rproc_panic_handler()
2693 rproc->state != RPROC_ATTACHED) in rproc_panic_handler()
2696 d = rproc->ops->panic(rproc); in rproc_panic_handler()