Lines Matching refs: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()
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()
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()
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()
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()
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()
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()
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()
545 static int rproc_handle_trace(struct rproc *rproc, void *ptr, in rproc_handle_trace() argument
550 struct device *dev = &rproc->dev; in rproc_handle_trace()
573 trace->rproc = rproc; in rproc_handle_trace()
576 snprintf(name, sizeof(name), "trace%d", rproc->num_traces); in rproc_handle_trace()
579 trace->tfile = rproc_create_trace_file(name, rproc, trace); in rproc_handle_trace()
581 list_add_tail(&trace->node, &rproc->traces); in rproc_handle_trace()
583 rproc->num_traces++; in rproc_handle_trace()
619 static int rproc_handle_devmem(struct rproc *rproc, void *ptr, in rproc_handle_devmem() argument
624 struct device *dev = &rproc->dev; in rproc_handle_devmem()
628 if (!rproc->domain) in rproc_handle_devmem()
646 ret = iommu_map(rproc->domain, rsc->da, rsc->pa, rsc->len, rsc->flags); in rproc_handle_devmem()
661 list_add_tail(&mapping->node, &rproc->mappings); in rproc_handle_devmem()
683 static int rproc_alloc_carveout(struct rproc *rproc, in rproc_alloc_carveout() argument
687 struct device *dev = &rproc->dev; in rproc_alloc_carveout()
703 if (mem->da != FW_RSC_ADDR_ANY && !rproc->domain) { in rproc_alloc_carveout()
732 if (mem->da != FW_RSC_ADDR_ANY && rproc->domain) { in rproc_alloc_carveout()
739 ret = iommu_map(rproc->domain, mem->da, dma, mem->len, in rproc_alloc_carveout()
755 list_add_tail(&mapping->node, &rproc->mappings); in rproc_alloc_carveout()
791 static int rproc_release_carveout(struct rproc *rproc, in rproc_release_carveout() argument
794 struct device *dev = &rproc->dev; in rproc_release_carveout()
822 static int rproc_handle_carveout(struct rproc *rproc, in rproc_handle_carveout() argument
827 struct device *dev = &rproc->dev; in rproc_handle_carveout()
847 carveout = rproc_find_carveout_by_name(rproc, rsc->name); in rproc_handle_carveout()
856 if (rproc_check_carveout_da(rproc, carveout, rsc->da, rsc->len)) in rproc_handle_carveout()
877 rproc_add_carveout(rproc, carveout); in rproc_handle_carveout()
890 void rproc_add_carveout(struct rproc *rproc, struct rproc_mem_entry *mem) in rproc_add_carveout() argument
892 list_add_tail(&mem->node, &rproc->carveouts); in rproc_add_carveout()
916 int (*alloc)(struct rproc *, struct rproc_mem_entry *), in rproc_mem_entry_init() argument
917 int (*release)(struct rproc *, struct rproc_mem_entry *), in rproc_mem_entry_init() argument
1018 static int rproc_handle_resources(struct rproc *rproc, in rproc_handle_resources() argument
1021 struct device *dev = &rproc->dev; in rproc_handle_resources()
1025 if (!rproc->table_ptr) in rproc_handle_resources()
1028 for (i = 0; i < rproc->table_ptr->num; i++) { in rproc_handle_resources()
1029 int offset = rproc->table_ptr->offset[i]; in rproc_handle_resources()
1030 struct fw_rsc_hdr *hdr = (void *)rproc->table_ptr + offset; in rproc_handle_resources()
1031 int avail = rproc->table_sz - offset - sizeof(*hdr); in rproc_handle_resources()
1044 ret = rproc_handle_rsc(rproc, hdr->type, rsc, in rproc_handle_resources()
1065 ret = handler(rproc, rsc, offset + sizeof(*hdr), avail); in rproc_handle_resources()
1073 static int rproc_prepare_subdevices(struct rproc *rproc) in rproc_prepare_subdevices() argument
1078 list_for_each_entry(subdev, &rproc->subdevs, node) { in rproc_prepare_subdevices()
1089 list_for_each_entry_continue_reverse(subdev, &rproc->subdevs, node) { in rproc_prepare_subdevices()
1097 static int rproc_start_subdevices(struct rproc *rproc) in rproc_start_subdevices() argument
1102 list_for_each_entry(subdev, &rproc->subdevs, node) { in rproc_start_subdevices()
1113 list_for_each_entry_continue_reverse(subdev, &rproc->subdevs, node) { in rproc_start_subdevices()
1121 static void rproc_stop_subdevices(struct rproc *rproc, bool crashed) in rproc_stop_subdevices() argument
1125 list_for_each_entry_reverse(subdev, &rproc->subdevs, node) { in rproc_stop_subdevices()
1131 static void rproc_unprepare_subdevices(struct rproc *rproc) in rproc_unprepare_subdevices() argument
1135 list_for_each_entry_reverse(subdev, &rproc->subdevs, node) { in rproc_unprepare_subdevices()
1152 static int rproc_alloc_registered_carveouts(struct rproc *rproc) in rproc_alloc_registered_carveouts() argument
1156 struct device *dev = &rproc->dev; in rproc_alloc_registered_carveouts()
1160 list_for_each_entry_safe(entry, tmp, &rproc->carveouts, node) { in rproc_alloc_registered_carveouts()
1162 ret = entry->alloc(rproc, entry); in rproc_alloc_registered_carveouts()
1172 rsc = (void *)rproc->table_ptr + entry->rsc_offset; in rproc_alloc_registered_carveouts()
1219 void rproc_resource_cleanup(struct rproc *rproc) in rproc_resource_cleanup() argument
1224 struct device *dev = &rproc->dev; in rproc_resource_cleanup()
1227 list_for_each_entry_safe(trace, ttmp, &rproc->traces, node) { in rproc_resource_cleanup()
1229 rproc->num_traces--; in rproc_resource_cleanup()
1235 list_for_each_entry_safe(entry, tmp, &rproc->mappings, node) { in rproc_resource_cleanup()
1238 unmapped = iommu_unmap(rproc->domain, entry->da, entry->len); in rproc_resource_cleanup()
1250 list_for_each_entry_safe(entry, tmp, &rproc->carveouts, node) { in rproc_resource_cleanup()
1252 entry->release(rproc, entry); in rproc_resource_cleanup()
1258 list_for_each_entry_safe(rvdev, rvtmp, &rproc->rvdevs, node) in rproc_resource_cleanup()
1261 rproc_coredump_cleanup(rproc); in rproc_resource_cleanup()
1265 static int rproc_start(struct rproc *rproc, const struct firmware *fw) in rproc_start() argument
1268 struct device *dev = &rproc->dev; in rproc_start()
1272 ret = rproc_load_segments(rproc, fw); in rproc_start()
1286 loaded_table = rproc_find_loaded_rsc_table(rproc, fw); in rproc_start()
1288 memcpy(loaded_table, rproc->cached_table, rproc->table_sz); in rproc_start()
1289 rproc->table_ptr = loaded_table; in rproc_start()
1292 ret = rproc_prepare_subdevices(rproc); in rproc_start()
1295 rproc->name, ret); in rproc_start()
1300 ret = rproc->ops->start(rproc); in rproc_start()
1302 dev_err(dev, "can't start rproc %s: %d\n", rproc->name, ret); in rproc_start()
1307 ret = rproc_start_subdevices(rproc); in rproc_start()
1310 rproc->name, ret); in rproc_start()
1314 rproc->state = RPROC_RUNNING; in rproc_start()
1316 dev_info(dev, "remote processor %s is now up\n", rproc->name); in rproc_start()
1321 rproc->ops->stop(rproc); in rproc_start()
1323 rproc_unprepare_subdevices(rproc); in rproc_start()
1325 rproc->table_ptr = rproc->cached_table; in rproc_start()
1330 static int __rproc_attach(struct rproc *rproc) in __rproc_attach() argument
1332 struct device *dev = &rproc->dev; in __rproc_attach()
1335 ret = rproc_prepare_subdevices(rproc); in __rproc_attach()
1338 rproc->name, ret); in __rproc_attach()
1343 ret = rproc_attach_device(rproc); in __rproc_attach()
1346 rproc->name, ret); in __rproc_attach()
1351 ret = rproc_start_subdevices(rproc); in __rproc_attach()
1354 rproc->name, ret); in __rproc_attach()
1358 rproc->state = RPROC_ATTACHED; in __rproc_attach()
1360 dev_info(dev, "remote processor %s is now attached\n", rproc->name); in __rproc_attach()
1365 rproc->ops->stop(rproc); in __rproc_attach()
1367 rproc_unprepare_subdevices(rproc); in __rproc_attach()
1375 static int rproc_fw_boot(struct rproc *rproc, const struct firmware *fw) in rproc_fw_boot() argument
1377 struct device *dev = &rproc->dev; in rproc_fw_boot()
1378 const char *name = rproc->firmware; in rproc_fw_boot()
1381 ret = rproc_fw_sanity_check(rproc, fw); in rproc_fw_boot()
1391 ret = rproc_enable_iommu(rproc); in rproc_fw_boot()
1398 ret = rproc_prepare_device(rproc); in rproc_fw_boot()
1400 dev_err(dev, "can't prepare rproc %s: %d\n", rproc->name, ret); in rproc_fw_boot()
1404 rproc->bootaddr = rproc_get_boot_addr(rproc, fw); in rproc_fw_boot()
1407 ret = rproc_parse_fw(rproc, fw); in rproc_fw_boot()
1412 rproc->max_notifyid = -1; in rproc_fw_boot()
1415 rproc->nb_vdev = 0; in rproc_fw_boot()
1418 ret = rproc_handle_resources(rproc, rproc_loading_handlers); in rproc_fw_boot()
1425 ret = rproc_alloc_registered_carveouts(rproc); in rproc_fw_boot()
1432 ret = rproc_start(rproc, fw); in rproc_fw_boot()
1439 rproc_resource_cleanup(rproc); in rproc_fw_boot()
1440 kfree(rproc->cached_table); in rproc_fw_boot()
1441 rproc->cached_table = NULL; in rproc_fw_boot()
1442 rproc->table_ptr = NULL; in rproc_fw_boot()
1445 rproc_unprepare_device(rproc); in rproc_fw_boot()
1447 rproc_disable_iommu(rproc); in rproc_fw_boot()
1451 static int rproc_set_rsc_table(struct rproc *rproc) in rproc_set_rsc_table() argument
1454 struct device *dev = &rproc->dev; in rproc_set_rsc_table()
1458 table_ptr = rproc_get_loaded_rsc_table(rproc, &table_sz); in rproc_set_rsc_table()
1480 if (rproc->ops->detach) { in rproc_set_rsc_table()
1481 rproc->clean_table = kmemdup(table_ptr, table_sz, GFP_KERNEL); in rproc_set_rsc_table()
1482 if (!rproc->clean_table) in rproc_set_rsc_table()
1485 rproc->clean_table = NULL; in rproc_set_rsc_table()
1488 rproc->cached_table = NULL; in rproc_set_rsc_table()
1489 rproc->table_ptr = table_ptr; in rproc_set_rsc_table()
1490 rproc->table_sz = table_sz; in rproc_set_rsc_table()
1495 static int rproc_reset_rsc_table_on_detach(struct rproc *rproc) in rproc_reset_rsc_table_on_detach() argument
1500 if (!rproc->table_ptr) in rproc_reset_rsc_table_on_detach()
1508 if (WARN_ON(!rproc->clean_table)) in rproc_reset_rsc_table_on_detach()
1512 table_ptr = rproc->table_ptr; in rproc_reset_rsc_table_on_detach()
1521 rproc->cached_table = kmemdup(rproc->table_ptr, in rproc_reset_rsc_table_on_detach()
1522 rproc->table_sz, GFP_KERNEL); in rproc_reset_rsc_table_on_detach()
1523 if (!rproc->cached_table) in rproc_reset_rsc_table_on_detach()
1530 rproc->table_ptr = rproc->cached_table; in rproc_reset_rsc_table_on_detach()
1537 memcpy(table_ptr, rproc->clean_table, rproc->table_sz); in rproc_reset_rsc_table_on_detach()
1543 kfree(rproc->clean_table); in rproc_reset_rsc_table_on_detach()
1548 static int rproc_reset_rsc_table_on_stop(struct rproc *rproc) in rproc_reset_rsc_table_on_stop() argument
1551 if (!rproc->table_ptr) in rproc_reset_rsc_table_on_stop()
1559 if (rproc->cached_table) in rproc_reset_rsc_table_on_stop()
1569 rproc->cached_table = kmemdup(rproc->table_ptr, in rproc_reset_rsc_table_on_stop()
1570 rproc->table_sz, GFP_KERNEL); in rproc_reset_rsc_table_on_stop()
1571 if (!rproc->cached_table) in rproc_reset_rsc_table_on_stop()
1578 kfree(rproc->clean_table); in rproc_reset_rsc_table_on_stop()
1585 rproc->table_ptr = rproc->cached_table; in rproc_reset_rsc_table_on_stop()
1593 static int rproc_attach(struct rproc *rproc) in rproc_attach() argument
1595 struct device *dev = &rproc->dev; in rproc_attach()
1602 ret = rproc_enable_iommu(rproc); in rproc_attach()
1609 ret = rproc_prepare_device(rproc); in rproc_attach()
1611 dev_err(dev, "can't prepare rproc %s: %d\n", rproc->name, ret); in rproc_attach()
1615 ret = rproc_set_rsc_table(rproc); in rproc_attach()
1622 rproc->max_notifyid = -1; in rproc_attach()
1625 rproc->nb_vdev = 0; in rproc_attach()
1632 ret = rproc_handle_resources(rproc, rproc_loading_handlers); in rproc_attach()
1639 ret = rproc_alloc_registered_carveouts(rproc); in rproc_attach()
1646 ret = __rproc_attach(rproc); in rproc_attach()
1653 rproc_resource_cleanup(rproc); in rproc_attach()
1656 rproc_unprepare_device(rproc); in rproc_attach()
1658 rproc_disable_iommu(rproc); in rproc_attach()
1672 struct rproc *rproc = context; in rproc_auto_boot_callback() local
1674 rproc_boot(rproc); in rproc_auto_boot_callback()
1679 static int rproc_trigger_auto_boot(struct rproc *rproc) in rproc_trigger_auto_boot() argument
1689 if (rproc->state == RPROC_DETACHED) in rproc_trigger_auto_boot()
1690 return rproc_boot(rproc); in rproc_trigger_auto_boot()
1697 rproc->firmware, &rproc->dev, GFP_KERNEL, in rproc_trigger_auto_boot()
1698 rproc, rproc_auto_boot_callback); in rproc_trigger_auto_boot()
1700 dev_err(&rproc->dev, "request_firmware_nowait err: %d\n", ret); in rproc_trigger_auto_boot()
1705 static int rproc_stop(struct rproc *rproc, bool crashed) in rproc_stop() argument
1707 struct device *dev = &rproc->dev; in rproc_stop()
1711 if (!rproc->ops->stop) in rproc_stop()
1715 rproc_stop_subdevices(rproc, crashed); in rproc_stop()
1718 ret = rproc_reset_rsc_table_on_stop(rproc); in rproc_stop()
1726 ret = rproc->ops->stop(rproc); in rproc_stop()
1732 rproc_unprepare_subdevices(rproc); in rproc_stop()
1734 rproc->state = RPROC_OFFLINE; in rproc_stop()
1736 dev_info(dev, "stopped remote processor %s\n", rproc->name); in rproc_stop()
1744 static int __rproc_detach(struct rproc *rproc) in __rproc_detach() argument
1746 struct device *dev = &rproc->dev; in __rproc_detach()
1750 if (!rproc->ops->detach) in __rproc_detach()
1754 rproc_stop_subdevices(rproc, false); in __rproc_detach()
1757 ret = rproc_reset_rsc_table_on_detach(rproc); in __rproc_detach()
1764 ret = rproc->ops->detach(rproc); in __rproc_detach()
1770 rproc_unprepare_subdevices(rproc); in __rproc_detach()
1772 rproc->state = RPROC_DETACHED; in __rproc_detach()
1774 dev_info(dev, "detached remote processor %s\n", rproc->name); in __rproc_detach()
1779 static int rproc_attach_recovery(struct rproc *rproc) in rproc_attach_recovery() argument
1783 ret = __rproc_detach(rproc); in rproc_attach_recovery()
1787 return __rproc_attach(rproc); in rproc_attach_recovery()
1790 static int rproc_boot_recovery(struct rproc *rproc) in rproc_boot_recovery() argument
1793 struct device *dev = &rproc->dev; in rproc_boot_recovery()
1796 ret = rproc_stop(rproc, true); in rproc_boot_recovery()
1801 rproc->ops->coredump(rproc); in rproc_boot_recovery()
1804 ret = request_firmware(&firmware_p, rproc->firmware, dev); in rproc_boot_recovery()
1811 ret = rproc_start(rproc, firmware_p); in rproc_boot_recovery()
1830 int rproc_trigger_recovery(struct rproc *rproc) in rproc_trigger_recovery() argument
1832 struct device *dev = &rproc->dev; in rproc_trigger_recovery()
1835 ret = mutex_lock_interruptible(&rproc->lock); in rproc_trigger_recovery()
1840 if (rproc->state != RPROC_CRASHED) in rproc_trigger_recovery()
1843 dev_err(dev, "recovering %s\n", rproc->name); in rproc_trigger_recovery()
1845 if (rproc_has_feature(rproc, RPROC_FEAT_ATTACH_ON_RECOVERY)) in rproc_trigger_recovery()
1846 ret = rproc_attach_recovery(rproc); in rproc_trigger_recovery()
1848 ret = rproc_boot_recovery(rproc); in rproc_trigger_recovery()
1851 mutex_unlock(&rproc->lock); in rproc_trigger_recovery()
1864 struct rproc *rproc = container_of(work, struct rproc, crash_handler); in rproc_crash_handler_work() local
1865 struct device *dev = &rproc->dev; in rproc_crash_handler_work()
1869 mutex_lock(&rproc->lock); in rproc_crash_handler_work()
1871 if (rproc->state == RPROC_CRASHED) { in rproc_crash_handler_work()
1873 mutex_unlock(&rproc->lock); in rproc_crash_handler_work()
1877 if (rproc->state == RPROC_OFFLINE) { in rproc_crash_handler_work()
1879 mutex_unlock(&rproc->lock); in rproc_crash_handler_work()
1883 rproc->state = RPROC_CRASHED; in rproc_crash_handler_work()
1884 dev_err(dev, "handling crash #%u in %s\n", ++rproc->crash_cnt, in rproc_crash_handler_work()
1885 rproc->name); in rproc_crash_handler_work()
1887 mutex_unlock(&rproc->lock); in rproc_crash_handler_work()
1889 if (!rproc->recovery_disabled) in rproc_crash_handler_work()
1890 rproc_trigger_recovery(rproc); in rproc_crash_handler_work()
1893 pm_relax(rproc->dev.parent); in rproc_crash_handler_work()
1907 int rproc_boot(struct rproc *rproc) in rproc_boot() argument
1913 if (!rproc) { in rproc_boot()
1918 dev = &rproc->dev; in rproc_boot()
1920 ret = mutex_lock_interruptible(&rproc->lock); in rproc_boot()
1922 dev_err(dev, "can't lock rproc %s: %d\n", rproc->name, ret); in rproc_boot()
1926 if (rproc->state == RPROC_DELETED) { in rproc_boot()
1928 dev_err(dev, "can't boot deleted rproc %s\n", rproc->name); in rproc_boot()
1933 if (atomic_inc_return(&rproc->power) > 1) { in rproc_boot()
1938 if (rproc->state == RPROC_DETACHED) { in rproc_boot()
1939 dev_info(dev, "attaching to %s\n", rproc->name); in rproc_boot()
1941 ret = rproc_attach(rproc); in rproc_boot()
1943 dev_info(dev, "powering up %s\n", rproc->name); in rproc_boot()
1946 ret = request_firmware(&firmware_p, rproc->firmware, dev); in rproc_boot()
1952 ret = rproc_fw_boot(rproc, firmware_p); in rproc_boot()
1959 atomic_dec(&rproc->power); in rproc_boot()
1961 mutex_unlock(&rproc->lock); in rproc_boot()
1987 int rproc_shutdown(struct rproc *rproc) in rproc_shutdown() argument
1989 struct device *dev = &rproc->dev; in rproc_shutdown()
1992 ret = mutex_lock_interruptible(&rproc->lock); in rproc_shutdown()
1994 dev_err(dev, "can't lock rproc %s: %d\n", rproc->name, ret); in rproc_shutdown()
1998 if (rproc->state != RPROC_RUNNING && in rproc_shutdown()
1999 rproc->state != RPROC_ATTACHED) { in rproc_shutdown()
2005 if (!atomic_dec_and_test(&rproc->power)) in rproc_shutdown()
2008 ret = rproc_stop(rproc, false); in rproc_shutdown()
2010 atomic_inc(&rproc->power); in rproc_shutdown()
2015 rproc_resource_cleanup(rproc); in rproc_shutdown()
2018 rproc_unprepare_device(rproc); in rproc_shutdown()
2020 rproc_disable_iommu(rproc); in rproc_shutdown()
2023 kfree(rproc->cached_table); in rproc_shutdown()
2024 rproc->cached_table = NULL; in rproc_shutdown()
2025 rproc->table_ptr = NULL; in rproc_shutdown()
2027 mutex_unlock(&rproc->lock); in rproc_shutdown()
2052 int rproc_detach(struct rproc *rproc) in rproc_detach() argument
2054 struct device *dev = &rproc->dev; in rproc_detach()
2057 ret = mutex_lock_interruptible(&rproc->lock); in rproc_detach()
2059 dev_err(dev, "can't lock rproc %s: %d\n", rproc->name, ret); in rproc_detach()
2063 if (rproc->state != RPROC_ATTACHED) { in rproc_detach()
2069 if (!atomic_dec_and_test(&rproc->power)) { in rproc_detach()
2074 ret = __rproc_detach(rproc); in rproc_detach()
2076 atomic_inc(&rproc->power); in rproc_detach()
2081 rproc_resource_cleanup(rproc); in rproc_detach()
2084 rproc_unprepare_device(rproc); in rproc_detach()
2086 rproc_disable_iommu(rproc); in rproc_detach()
2089 kfree(rproc->cached_table); in rproc_detach()
2090 rproc->cached_table = NULL; in rproc_detach()
2091 rproc->table_ptr = NULL; in rproc_detach()
2093 mutex_unlock(&rproc->lock); in rproc_detach()
2111 struct rproc *rproc_get_by_phandle(phandle phandle) in rproc_get_by_phandle()
2113 struct rproc *rproc = NULL, *r; in rproc_get_by_phandle() local
2129 rproc = r; in rproc_get_by_phandle()
2130 get_device(&rproc->dev); in rproc_get_by_phandle()
2138 return rproc; in rproc_get_by_phandle()
2141 struct rproc *rproc_get_by_phandle(phandle phandle) in rproc_get_by_phandle()
2166 int rproc_set_firmware(struct rproc *rproc, const char *fw_name) in rproc_set_firmware() argument
2172 if (!rproc || !fw_name) in rproc_set_firmware()
2175 dev = rproc->dev.parent; in rproc_set_firmware()
2177 ret = mutex_lock_interruptible(&rproc->lock); in rproc_set_firmware()
2179 dev_err(dev, "can't lock rproc %s: %d\n", rproc->name, ret); in rproc_set_firmware()
2183 if (rproc->state != RPROC_OFFLINE) { in rproc_set_firmware()
2202 kfree_const(rproc->firmware); in rproc_set_firmware()
2203 rproc->firmware = p; in rproc_set_firmware()
2206 mutex_unlock(&rproc->lock); in rproc_set_firmware()
2211 static int rproc_validate(struct rproc *rproc) in rproc_validate() argument
2213 switch (rproc->state) { in rproc_validate()
2219 if (!rproc->ops->start) in rproc_validate()
2227 if (!rproc->ops->attach) in rproc_validate()
2234 if (rproc->cached_table) in rproc_validate()
2268 int rproc_add(struct rproc *rproc) in rproc_add() argument
2270 struct device *dev = &rproc->dev; in rproc_add()
2273 ret = rproc_validate(rproc); in rproc_add()
2278 ret = rproc_char_device_add(rproc); in rproc_add()
2288 dev_info(dev, "%s is available\n", rproc->name); in rproc_add()
2291 rproc_create_debug_dir(rproc); in rproc_add()
2294 if (rproc->auto_boot) { in rproc_add()
2295 ret = rproc_trigger_auto_boot(rproc); in rproc_add()
2302 list_add_rcu(&rproc->node, &rproc_list); in rproc_add()
2308 rproc_delete_debug_dir(rproc); in rproc_add()
2311 rproc_char_device_remove(rproc); in rproc_add()
2316 static void devm_rproc_remove(void *rproc) in devm_rproc_remove() argument
2318 rproc_del(rproc); in devm_rproc_remove()
2331 int devm_rproc_add(struct device *dev, struct rproc *rproc) in devm_rproc_add() argument
2335 err = rproc_add(rproc); in devm_rproc_add()
2339 return devm_add_action_or_reset(dev, devm_rproc_remove, rproc); in devm_rproc_add()
2354 struct rproc *rproc = container_of(dev, struct rproc, dev); in rproc_type_release() local
2356 dev_info(&rproc->dev, "releasing %s\n", rproc->name); in rproc_type_release()
2358 idr_destroy(&rproc->notifyids); in rproc_type_release()
2360 if (rproc->index >= 0) in rproc_type_release()
2361 ida_free(&rproc_dev_index, rproc->index); in rproc_type_release()
2363 kfree_const(rproc->firmware); in rproc_type_release()
2364 kfree_const(rproc->name); in rproc_type_release()
2365 kfree(rproc->ops); in rproc_type_release()
2366 kfree(rproc); in rproc_type_release()
2374 static int rproc_alloc_firmware(struct rproc *rproc, in rproc_alloc_firmware() argument
2391 rproc->firmware = p; in rproc_alloc_firmware()
2396 static int rproc_alloc_ops(struct rproc *rproc, const struct rproc_ops *ops) in rproc_alloc_ops() argument
2398 rproc->ops = kmemdup(ops, sizeof(*ops), GFP_KERNEL); in rproc_alloc_ops()
2399 if (!rproc->ops) in rproc_alloc_ops()
2403 if (!rproc->ops->coredump) in rproc_alloc_ops()
2404 rproc->ops->coredump = rproc_coredump; in rproc_alloc_ops()
2406 if (rproc->ops->load) in rproc_alloc_ops()
2410 rproc->ops->load = rproc_elf_load_segments; in rproc_alloc_ops()
2411 rproc->ops->parse_fw = rproc_elf_load_rsc_table; in rproc_alloc_ops()
2412 rproc->ops->find_loaded_rsc_table = rproc_elf_find_loaded_rsc_table; in rproc_alloc_ops()
2413 rproc->ops->sanity_check = rproc_elf_sanity_check; in rproc_alloc_ops()
2414 rproc->ops->get_boot_addr = rproc_elf_get_boot_addr; in rproc_alloc_ops()
2442 struct rproc *rproc_alloc(struct device *dev, const char *name, in rproc_alloc()
2446 struct rproc *rproc; in rproc_alloc() local
2451 rproc = kzalloc(sizeof(struct rproc) + len, GFP_KERNEL); in rproc_alloc()
2452 if (!rproc) in rproc_alloc()
2455 rproc->priv = &rproc[1]; in rproc_alloc()
2456 rproc->auto_boot = true; in rproc_alloc()
2457 rproc->elf_class = ELFCLASSNONE; in rproc_alloc()
2458 rproc->elf_machine = EM_NONE; in rproc_alloc()
2460 device_initialize(&rproc->dev); in rproc_alloc()
2461 rproc->dev.parent = dev; in rproc_alloc()
2462 rproc->dev.type = &rproc_type; in rproc_alloc()
2463 rproc->dev.class = &rproc_class; in rproc_alloc()
2464 rproc->dev.driver_data = rproc; in rproc_alloc()
2465 idr_init(&rproc->notifyids); in rproc_alloc()
2467 rproc->name = kstrdup_const(name, GFP_KERNEL); in rproc_alloc()
2468 if (!rproc->name) in rproc_alloc()
2471 if (rproc_alloc_firmware(rproc, name, firmware)) in rproc_alloc()
2474 if (rproc_alloc_ops(rproc, ops)) in rproc_alloc()
2478 rproc->index = ida_alloc(&rproc_dev_index, GFP_KERNEL); in rproc_alloc()
2479 if (rproc->index < 0) { in rproc_alloc()
2480 dev_err(dev, "ida_alloc failed: %d\n", rproc->index); in rproc_alloc()
2484 dev_set_name(&rproc->dev, "remoteproc%d", rproc->index); in rproc_alloc()
2486 atomic_set(&rproc->power, 0); in rproc_alloc()
2488 mutex_init(&rproc->lock); in rproc_alloc()
2490 INIT_LIST_HEAD(&rproc->carveouts); in rproc_alloc()
2491 INIT_LIST_HEAD(&rproc->mappings); in rproc_alloc()
2492 INIT_LIST_HEAD(&rproc->traces); in rproc_alloc()
2493 INIT_LIST_HEAD(&rproc->rvdevs); in rproc_alloc()
2494 INIT_LIST_HEAD(&rproc->subdevs); in rproc_alloc()
2495 INIT_LIST_HEAD(&rproc->dump_segments); in rproc_alloc()
2497 INIT_WORK(&rproc->crash_handler, rproc_crash_handler_work); in rproc_alloc()
2499 rproc->state = RPROC_OFFLINE; in rproc_alloc()
2501 return rproc; in rproc_alloc()
2504 put_device(&rproc->dev); in rproc_alloc()
2518 void rproc_free(struct rproc *rproc) in rproc_free() argument
2520 put_device(&rproc->dev); in rproc_free()
2533 void rproc_put(struct rproc *rproc) in rproc_put() argument
2535 module_put(rproc->dev.parent->driver->owner); in rproc_put()
2536 put_device(&rproc->dev); in rproc_put()
2555 int rproc_del(struct rproc *rproc) in rproc_del() argument
2557 if (!rproc) in rproc_del()
2561 rproc_shutdown(rproc); in rproc_del()
2563 mutex_lock(&rproc->lock); in rproc_del()
2564 rproc->state = RPROC_DELETED; in rproc_del()
2565 mutex_unlock(&rproc->lock); in rproc_del()
2567 rproc_delete_debug_dir(rproc); in rproc_del()
2571 list_del_rcu(&rproc->node); in rproc_del()
2577 device_del(&rproc->dev); in rproc_del()
2578 rproc_char_device_remove(rproc); in rproc_del()
2586 rproc_free(*(struct rproc **)res); in devm_rproc_free()
2602 struct rproc *devm_rproc_alloc(struct device *dev, const char *name, in devm_rproc_alloc()
2606 struct rproc **ptr, *rproc; in devm_rproc_alloc() local
2612 rproc = rproc_alloc(dev, name, ops, firmware, len); in devm_rproc_alloc()
2613 if (rproc) { in devm_rproc_alloc()
2614 *ptr = rproc; in devm_rproc_alloc()
2620 return rproc; in devm_rproc_alloc()
2631 void rproc_add_subdev(struct rproc *rproc, struct rproc_subdev *subdev) in rproc_add_subdev() argument
2633 list_add_tail(&subdev->node, &rproc->subdevs); in rproc_add_subdev()
2642 void rproc_remove_subdev(struct rproc *rproc, struct rproc_subdev *subdev) in rproc_remove_subdev() argument
2654 struct rproc *rproc_get_by_child(struct device *dev) in rproc_get_by_child()
2676 void rproc_report_crash(struct rproc *rproc, enum rproc_crash_type type) in rproc_report_crash() argument
2678 if (!rproc) { in rproc_report_crash()
2684 pm_stay_awake(rproc->dev.parent); in rproc_report_crash()
2686 dev_err(&rproc->dev, "crash detected in %s: type %s\n", in rproc_report_crash()
2687 rproc->name, rproc_crash_to_string(type)); in rproc_report_crash()
2689 queue_work(rproc_recovery_wq, &rproc->crash_handler); in rproc_report_crash()
2697 struct rproc *rproc; in rproc_panic_handler() local
2701 list_for_each_entry_rcu(rproc, &rproc_list, node) { in rproc_panic_handler()
2702 if (!rproc->ops->panic) in rproc_panic_handler()
2705 if (rproc->state != RPROC_RUNNING && in rproc_panic_handler()
2706 rproc->state != RPROC_ATTACHED) in rproc_panic_handler()
2709 d = rproc->ops->panic(rproc); in rproc_panic_handler()