aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@linux-foundation.org>2018-02-05 13:07:40 -0500
committerLinus Torvalds <torvalds@linux-foundation.org>2018-02-05 13:07:40 -0500
commit2deb41b245320f0eefb535a5c8ea19ed66b33c04 (patch)
treed61cba8a2efc8cd9e90494d488e706980a2e9734
parent67fb3b92b0f92a161e25370d437ae4ba08089e75 (diff)
parent0a8b81cb2e413eff4cd9aeac7ef415150b699fb4 (diff)
Merge tag 'rproc-v4.16' of git://github.com/andersson/remoteproc
Pull remoteproc updates from Bjorn Andersson: "This contains a few bug fixes and a cleanup up of the resource-table handling in the framework, which removes the need for drivers with no resource table to provide a fake one" * tag 'rproc-v4.16' of git://github.com/andersson/remoteproc: remoteproc: Reset table_ptr on stop remoteproc: Drop dangling find_rsc_table dummies remoteproc: Move resource table load logic to find remoteproc: Don't handle empty resource table remoteproc: Merge rproc_ops and rproc_fw_ops remoteproc: Clone rproc_ops in rproc_alloc() remoteproc: Cache resource table size remoteproc: Remove depricated crash completion virtio_remoteproc: correct put_device virtio_device.dev
-rw-r--r--drivers/remoteproc/qcom_adsp_pil.c8
-rw-r--r--drivers/remoteproc/qcom_common.c19
-rw-r--r--drivers/remoteproc/qcom_common.h4
-rw-r--r--drivers/remoteproc/qcom_q6v5_pil.c18
-rw-r--r--drivers/remoteproc/qcom_wcnss.c8
-rw-r--r--drivers/remoteproc/remoteproc_core.c83
-rw-r--r--drivers/remoteproc/remoteproc_elf_loader.c59
-rw-r--r--drivers/remoteproc/remoteproc_internal.h57
-rw-r--r--drivers/remoteproc/remoteproc_virtio.c2
-rw-r--r--drivers/remoteproc/st_slim_rproc.c32
-rw-r--r--include/linux/remoteproc.h21
11 files changed, 107 insertions, 204 deletions
diff --git a/drivers/remoteproc/qcom_adsp_pil.c b/drivers/remoteproc/qcom_adsp_pil.c
index 3f6af54dbc96..373c167892d7 100644
--- a/drivers/remoteproc/qcom_adsp_pil.c
+++ b/drivers/remoteproc/qcom_adsp_pil.c
@@ -85,11 +85,6 @@ static int adsp_load(struct rproc *rproc, const struct firmware *fw)
85 adsp->mem_region, adsp->mem_phys, adsp->mem_size); 85 adsp->mem_region, adsp->mem_phys, adsp->mem_size);
86} 86}
87 87
88static const struct rproc_fw_ops adsp_fw_ops = {
89 .find_rsc_table = qcom_mdt_find_rsc_table,
90 .load = adsp_load,
91};
92
93static int adsp_start(struct rproc *rproc) 88static int adsp_start(struct rproc *rproc)
94{ 89{
95 struct qcom_adsp *adsp = (struct qcom_adsp *)rproc->priv; 90 struct qcom_adsp *adsp = (struct qcom_adsp *)rproc->priv;
@@ -182,6 +177,7 @@ static const struct rproc_ops adsp_ops = {
182 .start = adsp_start, 177 .start = adsp_start,
183 .stop = adsp_stop, 178 .stop = adsp_stop,
184 .da_to_va = adsp_da_to_va, 179 .da_to_va = adsp_da_to_va,
180 .load = adsp_load,
185}; 181};
186 182
187static irqreturn_t adsp_wdog_interrupt(int irq, void *dev) 183static irqreturn_t adsp_wdog_interrupt(int irq, void *dev)
@@ -344,8 +340,6 @@ static int adsp_probe(struct platform_device *pdev)
344 return -ENOMEM; 340 return -ENOMEM;
345 } 341 }
346 342
347 rproc->fw_ops = &adsp_fw_ops;
348
349 adsp = (struct qcom_adsp *)rproc->priv; 343 adsp = (struct qcom_adsp *)rproc->priv;
350 adsp->dev = &pdev->dev; 344 adsp->dev = &pdev->dev;
351 adsp->rproc = rproc; 345 adsp->rproc = rproc;
diff --git a/drivers/remoteproc/qcom_common.c b/drivers/remoteproc/qcom_common.c
index e9b5f2a98c4d..00602499713f 100644
--- a/drivers/remoteproc/qcom_common.c
+++ b/drivers/remoteproc/qcom_common.c
@@ -32,25 +32,6 @@
32 32
33static BLOCKING_NOTIFIER_HEAD(ssr_notifiers); 33static BLOCKING_NOTIFIER_HEAD(ssr_notifiers);
34 34
35/**
36 * qcom_mdt_find_rsc_table() - provide dummy resource table for remoteproc
37 * @rproc: remoteproc handle
38 * @fw: firmware header
39 * @tablesz: outgoing size of the table
40 *
41 * Returns a dummy table.
42 */
43struct resource_table *qcom_mdt_find_rsc_table(struct rproc *rproc,
44 const struct firmware *fw,
45 int *tablesz)
46{
47 static struct resource_table table = { .ver = 1, };
48
49 *tablesz = sizeof(table);
50 return &table;
51}
52EXPORT_SYMBOL_GPL(qcom_mdt_find_rsc_table);
53
54static int glink_subdev_probe(struct rproc_subdev *subdev) 35static int glink_subdev_probe(struct rproc_subdev *subdev)
55{ 36{
56 struct qcom_rproc_glink *glink = to_glink_subdev(subdev); 37 struct qcom_rproc_glink *glink = to_glink_subdev(subdev);
diff --git a/drivers/remoteproc/qcom_common.h b/drivers/remoteproc/qcom_common.h
index 832e20271664..728be9834d8b 100644
--- a/drivers/remoteproc/qcom_common.h
+++ b/drivers/remoteproc/qcom_common.h
@@ -27,10 +27,6 @@ struct qcom_rproc_ssr {
27 const char *name; 27 const char *name;
28}; 28};
29 29
30struct resource_table *qcom_mdt_find_rsc_table(struct rproc *rproc,
31 const struct firmware *fw,
32 int *tablesz);
33
34void qcom_add_glink_subdev(struct rproc *rproc, struct qcom_rproc_glink *glink); 30void qcom_add_glink_subdev(struct rproc *rproc, struct qcom_rproc_glink *glink);
35void qcom_remove_glink_subdev(struct rproc *rproc, struct qcom_rproc_glink *glink); 31void qcom_remove_glink_subdev(struct rproc *rproc, struct qcom_rproc_glink *glink);
36 32
diff --git a/drivers/remoteproc/qcom_q6v5_pil.c b/drivers/remoteproc/qcom_q6v5_pil.c
index 8a3fa2bcc9f6..b4e5e725848d 100644
--- a/drivers/remoteproc/qcom_q6v5_pil.c
+++ b/drivers/remoteproc/qcom_q6v5_pil.c
@@ -303,16 +303,6 @@ static void q6v5_clk_disable(struct device *dev,
303 clk_disable_unprepare(clks[i]); 303 clk_disable_unprepare(clks[i]);
304} 304}
305 305
306static struct resource_table *q6v5_find_rsc_table(struct rproc *rproc,
307 const struct firmware *fw,
308 int *tablesz)
309{
310 static struct resource_table table = { .ver = 1, };
311
312 *tablesz = sizeof(table);
313 return &table;
314}
315
316static int q6v5_xfer_mem_ownership(struct q6v5 *qproc, int *current_perm, 306static int q6v5_xfer_mem_ownership(struct q6v5 *qproc, int *current_perm,
317 bool remote_owner, phys_addr_t addr, 307 bool remote_owner, phys_addr_t addr,
318 size_t size) 308 size_t size)
@@ -342,11 +332,6 @@ static int q6v5_load(struct rproc *rproc, const struct firmware *fw)
342 return 0; 332 return 0;
343} 333}
344 334
345static const struct rproc_fw_ops q6v5_fw_ops = {
346 .find_rsc_table = q6v5_find_rsc_table,
347 .load = q6v5_load,
348};
349
350static int q6v5_rmb_pbl_wait(struct q6v5 *qproc, int ms) 335static int q6v5_rmb_pbl_wait(struct q6v5 *qproc, int ms)
351{ 336{
352 unsigned long timeout; 337 unsigned long timeout;
@@ -931,6 +916,7 @@ static const struct rproc_ops q6v5_ops = {
931 .start = q6v5_start, 916 .start = q6v5_start,
932 .stop = q6v5_stop, 917 .stop = q6v5_stop,
933 .da_to_va = q6v5_da_to_va, 918 .da_to_va = q6v5_da_to_va,
919 .load = q6v5_load,
934}; 920};
935 921
936static irqreturn_t q6v5_wdog_interrupt(int irq, void *dev) 922static irqreturn_t q6v5_wdog_interrupt(int irq, void *dev)
@@ -1150,8 +1136,6 @@ static int q6v5_probe(struct platform_device *pdev)
1150 return -ENOMEM; 1136 return -ENOMEM;
1151 } 1137 }
1152 1138
1153 rproc->fw_ops = &q6v5_fw_ops;
1154
1155 qproc = (struct q6v5 *)rproc->priv; 1139 qproc = (struct q6v5 *)rproc->priv;
1156 qproc->dev = &pdev->dev; 1140 qproc->dev = &pdev->dev;
1157 qproc->rproc = rproc; 1141 qproc->rproc = rproc;
diff --git a/drivers/remoteproc/qcom_wcnss.c b/drivers/remoteproc/qcom_wcnss.c
index c7686393d505..3f0609236a76 100644
--- a/drivers/remoteproc/qcom_wcnss.c
+++ b/drivers/remoteproc/qcom_wcnss.c
@@ -156,11 +156,6 @@ static int wcnss_load(struct rproc *rproc, const struct firmware *fw)
156 wcnss->mem_region, wcnss->mem_phys, wcnss->mem_size); 156 wcnss->mem_region, wcnss->mem_phys, wcnss->mem_size);
157} 157}
158 158
159static const struct rproc_fw_ops wcnss_fw_ops = {
160 .find_rsc_table = qcom_mdt_find_rsc_table,
161 .load = wcnss_load,
162};
163
164static void wcnss_indicate_nv_download(struct qcom_wcnss *wcnss) 159static void wcnss_indicate_nv_download(struct qcom_wcnss *wcnss)
165{ 160{
166 u32 val; 161 u32 val;
@@ -313,6 +308,7 @@ static const struct rproc_ops wcnss_ops = {
313 .start = wcnss_start, 308 .start = wcnss_start,
314 .stop = wcnss_stop, 309 .stop = wcnss_stop,
315 .da_to_va = wcnss_da_to_va, 310 .da_to_va = wcnss_da_to_va,
311 .load = wcnss_load,
316}; 312};
317 313
318static irqreturn_t wcnss_wdog_interrupt(int irq, void *dev) 314static irqreturn_t wcnss_wdog_interrupt(int irq, void *dev)
@@ -492,8 +488,6 @@ static int wcnss_probe(struct platform_device *pdev)
492 return -ENOMEM; 488 return -ENOMEM;
493 } 489 }
494 490
495 rproc->fw_ops = &wcnss_fw_ops;
496
497 wcnss = (struct qcom_wcnss *)rproc->priv; 491 wcnss = (struct qcom_wcnss *)rproc->priv;
498 wcnss->dev = &pdev->dev; 492 wcnss->dev = &pdev->dev;
499 wcnss->rproc = rproc; 493 wcnss->rproc = rproc;
diff --git a/drivers/remoteproc/remoteproc_core.c b/drivers/remoteproc/remoteproc_core.c
index eab14b414bf0..4170dfbd93bd 100644
--- a/drivers/remoteproc/remoteproc_core.c
+++ b/drivers/remoteproc/remoteproc_core.c
@@ -732,17 +732,20 @@ static rproc_handle_resource_t rproc_loading_handlers[RSC_LAST] = {
732}; 732};
733 733
734/* handle firmware resource entries before booting the remote processor */ 734/* handle firmware resource entries before booting the remote processor */
735static int rproc_handle_resources(struct rproc *rproc, int len, 735static int rproc_handle_resources(struct rproc *rproc,
736 rproc_handle_resource_t handlers[RSC_LAST]) 736 rproc_handle_resource_t handlers[RSC_LAST])
737{ 737{
738 struct device *dev = &rproc->dev; 738 struct device *dev = &rproc->dev;
739 rproc_handle_resource_t handler; 739 rproc_handle_resource_t handler;
740 int ret = 0, i; 740 int ret = 0, i;
741 741
742 if (!rproc->table_ptr)
743 return 0;
744
742 for (i = 0; i < rproc->table_ptr->num; i++) { 745 for (i = 0; i < rproc->table_ptr->num; i++) {
743 int offset = rproc->table_ptr->offset[i]; 746 int offset = rproc->table_ptr->offset[i];
744 struct fw_rsc_hdr *hdr = (void *)rproc->table_ptr + offset; 747 struct fw_rsc_hdr *hdr = (void *)rproc->table_ptr + offset;
745 int avail = len - offset - sizeof(*hdr); 748 int avail = rproc->table_sz - offset - sizeof(*hdr);
746 void *rsc = (void *)hdr + sizeof(*hdr); 749 void *rsc = (void *)hdr + sizeof(*hdr);
747 750
748 /* make sure table isn't truncated */ 751 /* make sure table isn't truncated */
@@ -849,16 +852,9 @@ static void rproc_resource_cleanup(struct rproc *rproc)
849 852
850static int rproc_start(struct rproc *rproc, const struct firmware *fw) 853static int rproc_start(struct rproc *rproc, const struct firmware *fw)
851{ 854{
852 struct resource_table *table, *loaded_table; 855 struct resource_table *loaded_table;
853 struct device *dev = &rproc->dev; 856 struct device *dev = &rproc->dev;
854 int ret, tablesz; 857 int ret;
855
856 /* look for the resource table */
857 table = rproc_find_rsc_table(rproc, fw, &tablesz);
858 if (!table) {
859 dev_err(dev, "Resource table look up failed\n");
860 return -EINVAL;
861 }
862 858
863 /* load the ELF segments to memory */ 859 /* load the ELF segments to memory */
864 ret = rproc_load_segments(rproc, fw); 860 ret = rproc_load_segments(rproc, fw);
@@ -877,7 +873,7 @@ static int rproc_start(struct rproc *rproc, const struct firmware *fw)
877 */ 873 */
878 loaded_table = rproc_find_loaded_rsc_table(rproc, fw); 874 loaded_table = rproc_find_loaded_rsc_table(rproc, fw);
879 if (loaded_table) { 875 if (loaded_table) {
880 memcpy(loaded_table, rproc->cached_table, tablesz); 876 memcpy(loaded_table, rproc->cached_table, rproc->table_sz);
881 rproc->table_ptr = loaded_table; 877 rproc->table_ptr = loaded_table;
882 } 878 }
883 879
@@ -911,8 +907,7 @@ static int rproc_fw_boot(struct rproc *rproc, const struct firmware *fw)
911{ 907{
912 struct device *dev = &rproc->dev; 908 struct device *dev = &rproc->dev;
913 const char *name = rproc->firmware; 909 const char *name = rproc->firmware;
914 struct resource_table *table; 910 int ret;
915 int ret, tablesz;
916 911
917 ret = rproc_fw_sanity_check(rproc, fw); 912 ret = rproc_fw_sanity_check(rproc, fw);
918 if (ret) 913 if (ret)
@@ -931,32 +926,17 @@ static int rproc_fw_boot(struct rproc *rproc, const struct firmware *fw)
931 } 926 }
932 927
933 rproc->bootaddr = rproc_get_boot_addr(rproc, fw); 928 rproc->bootaddr = rproc_get_boot_addr(rproc, fw);
934 ret = -EINVAL;
935 929
936 /* look for the resource table */ 930 /* load resource table */
937 table = rproc_find_rsc_table(rproc, fw, &tablesz); 931 ret = rproc_load_rsc_table(rproc, fw);
938 if (!table) { 932 if (ret)
939 dev_err(dev, "Failed to find resource table\n"); 933 goto disable_iommu;
940 goto clean_up;
941 }
942
943 /*
944 * Create a copy of the resource table. When a virtio device starts
945 * and calls vring_new_virtqueue() the address of the allocated vring
946 * will be stored in the cached_table. Before the device is started,
947 * cached_table will be copied into device memory.
948 */
949 rproc->cached_table = kmemdup(table, tablesz, GFP_KERNEL);
950 if (!rproc->cached_table)
951 goto clean_up;
952
953 rproc->table_ptr = rproc->cached_table;
954 934
955 /* reset max_notifyid */ 935 /* reset max_notifyid */
956 rproc->max_notifyid = -1; 936 rproc->max_notifyid = -1;
957 937
958 /* handle fw resources which are required to boot rproc */ 938 /* handle fw resources which are required to boot rproc */
959 ret = rproc_handle_resources(rproc, tablesz, rproc_loading_handlers); 939 ret = rproc_handle_resources(rproc, rproc_loading_handlers);
960 if (ret) { 940 if (ret) {
961 dev_err(dev, "Failed to process resources: %d\n", ret); 941 dev_err(dev, "Failed to process resources: %d\n", ret);
962 goto clean_up_resources; 942 goto clean_up_resources;
@@ -970,11 +950,10 @@ static int rproc_fw_boot(struct rproc *rproc, const struct firmware *fw)
970 950
971clean_up_resources: 951clean_up_resources:
972 rproc_resource_cleanup(rproc); 952 rproc_resource_cleanup(rproc);
973clean_up:
974 kfree(rproc->cached_table); 953 kfree(rproc->cached_table);
975 rproc->cached_table = NULL; 954 rproc->cached_table = NULL;
976 rproc->table_ptr = NULL; 955 rproc->table_ptr = NULL;
977 956disable_iommu:
978 rproc_disable_iommu(rproc); 957 rproc_disable_iommu(rproc);
979 return ret; 958 return ret;
980} 959}
@@ -1021,6 +1000,9 @@ static int rproc_stop(struct rproc *rproc)
1021 /* remove any subdevices for the remote processor */ 1000 /* remove any subdevices for the remote processor */
1022 rproc_remove_subdevices(rproc); 1001 rproc_remove_subdevices(rproc);
1023 1002
1003 /* the installed resource table is no longer accessible */
1004 rproc->table_ptr = rproc->cached_table;
1005
1024 /* power off the remote processor */ 1006 /* power off the remote processor */
1025 ret = rproc->ops->stop(rproc); 1007 ret = rproc->ops->stop(rproc);
1026 if (ret) { 1008 if (ret) {
@@ -1028,10 +1010,6 @@ static int rproc_stop(struct rproc *rproc)
1028 return ret; 1010 return ret;
1029 } 1011 }
1030 1012
1031 /* if in crash state, unlock crash handler */
1032 if (rproc->state == RPROC_CRASHED)
1033 complete_all(&rproc->crash_comp);
1034
1035 rproc->state = RPROC_OFFLINE; 1013 rproc->state = RPROC_OFFLINE;
1036 1014
1037 dev_info(dev, "stopped remote processor %s\n", rproc->name); 1015 dev_info(dev, "stopped remote processor %s\n", rproc->name);
@@ -1057,8 +1035,6 @@ int rproc_trigger_recovery(struct rproc *rproc)
1057 1035
1058 dev_err(dev, "recovering %s\n", rproc->name); 1036 dev_err(dev, "recovering %s\n", rproc->name);
1059 1037
1060 init_completion(&rproc->crash_comp);
1061
1062 ret = mutex_lock_interruptible(&rproc->lock); 1038 ret = mutex_lock_interruptible(&rproc->lock);
1063 if (ret) 1039 if (ret)
1064 return ret; 1040 return ret;
@@ -1067,9 +1043,6 @@ int rproc_trigger_recovery(struct rproc *rproc)
1067 if (ret) 1043 if (ret)
1068 goto unlock_mutex; 1044 goto unlock_mutex;
1069 1045
1070 /* wait until there is no more rproc users */
1071 wait_for_completion(&rproc->crash_comp);
1072
1073 /* load firmware */ 1046 /* load firmware */
1074 ret = request_firmware(&firmware_p, rproc->firmware, dev); 1047 ret = request_firmware(&firmware_p, rproc->firmware, dev);
1075 if (ret < 0) { 1048 if (ret < 0) {
@@ -1357,6 +1330,7 @@ static void rproc_type_release(struct device *dev)
1357 ida_simple_remove(&rproc_dev_index, rproc->index); 1330 ida_simple_remove(&rproc_dev_index, rproc->index);
1358 1331
1359 kfree(rproc->firmware); 1332 kfree(rproc->firmware);
1333 kfree(rproc->ops);
1360 kfree(rproc); 1334 kfree(rproc);
1361} 1335}
1362 1336
@@ -1421,9 +1395,15 @@ struct rproc *rproc_alloc(struct device *dev, const char *name,
1421 return NULL; 1395 return NULL;
1422 } 1396 }
1423 1397
1398 rproc->ops = kmemdup(ops, sizeof(*ops), GFP_KERNEL);
1399 if (!rproc->ops) {
1400 kfree(p);
1401 kfree(rproc);
1402 return NULL;
1403 }
1404
1424 rproc->firmware = p; 1405 rproc->firmware = p;
1425 rproc->name = name; 1406 rproc->name = name;
1426 rproc->ops = ops;
1427 rproc->priv = &rproc[1]; 1407 rproc->priv = &rproc[1];
1428 rproc->auto_boot = true; 1408 rproc->auto_boot = true;
1429 1409
@@ -1445,8 +1425,14 @@ struct rproc *rproc_alloc(struct device *dev, const char *name,
1445 1425
1446 atomic_set(&rproc->power, 0); 1426 atomic_set(&rproc->power, 0);
1447 1427
1448 /* Set ELF as the default fw_ops handler */ 1428 /* Default to ELF loader if no load function is specified */
1449 rproc->fw_ops = &rproc_elf_fw_ops; 1429 if (!rproc->ops->load) {
1430 rproc->ops->load = rproc_elf_load_segments;
1431 rproc->ops->load_rsc_table = rproc_elf_load_rsc_table;
1432 rproc->ops->find_loaded_rsc_table = rproc_elf_find_loaded_rsc_table;
1433 rproc->ops->sanity_check = rproc_elf_sanity_check;
1434 rproc->ops->get_boot_addr = rproc_elf_get_boot_addr;
1435 }
1450 1436
1451 mutex_init(&rproc->lock); 1437 mutex_init(&rproc->lock);
1452 1438
@@ -1459,7 +1445,6 @@ struct rproc *rproc_alloc(struct device *dev, const char *name,
1459 INIT_LIST_HEAD(&rproc->subdevs); 1445 INIT_LIST_HEAD(&rproc->subdevs);
1460 1446
1461 INIT_WORK(&rproc->crash_handler, rproc_crash_handler_work); 1447 INIT_WORK(&rproc->crash_handler, rproc_crash_handler_work);
1462 init_completion(&rproc->crash_comp);
1463 1448
1464 rproc->state = RPROC_OFFLINE; 1449 rproc->state = RPROC_OFFLINE;
1465 1450
diff --git a/drivers/remoteproc/remoteproc_elf_loader.c b/drivers/remoteproc/remoteproc_elf_loader.c
index c523983a4aec..b17d72ec8603 100644
--- a/drivers/remoteproc/remoteproc_elf_loader.c
+++ b/drivers/remoteproc/remoteproc_elf_loader.c
@@ -39,8 +39,7 @@
39 * 39 *
40 * Make sure this fw image is sane. 40 * Make sure this fw image is sane.
41 */ 41 */
42static int 42int rproc_elf_sanity_check(struct rproc *rproc, const struct firmware *fw)
43rproc_elf_sanity_check(struct rproc *rproc, const struct firmware *fw)
44{ 43{
45 const char *name = rproc->firmware; 44 const char *name = rproc->firmware;
46 struct device *dev = &rproc->dev; 45 struct device *dev = &rproc->dev;
@@ -98,6 +97,7 @@ rproc_elf_sanity_check(struct rproc *rproc, const struct firmware *fw)
98 97
99 return 0; 98 return 0;
100} 99}
100EXPORT_SYMBOL(rproc_elf_sanity_check);
101 101
102/** 102/**
103 * rproc_elf_get_boot_addr() - Get rproc's boot address. 103 * rproc_elf_get_boot_addr() - Get rproc's boot address.
@@ -110,13 +110,13 @@ rproc_elf_sanity_check(struct rproc *rproc, const struct firmware *fw)
110 * Note that the boot address is not a configurable property of all remote 110 * Note that the boot address is not a configurable property of all remote
111 * processors. Some will always boot at a specific hard-coded address. 111 * processors. Some will always boot at a specific hard-coded address.
112 */ 112 */
113static
114u32 rproc_elf_get_boot_addr(struct rproc *rproc, const struct firmware *fw) 113u32 rproc_elf_get_boot_addr(struct rproc *rproc, const struct firmware *fw)
115{ 114{
116 struct elf32_hdr *ehdr = (struct elf32_hdr *)fw->data; 115 struct elf32_hdr *ehdr = (struct elf32_hdr *)fw->data;
117 116
118 return ehdr->e_entry; 117 return ehdr->e_entry;
119} 118}
119EXPORT_SYMBOL(rproc_elf_get_boot_addr);
120 120
121/** 121/**
122 * rproc_elf_load_segments() - load firmware segments to memory 122 * rproc_elf_load_segments() - load firmware segments to memory
@@ -142,8 +142,7 @@ u32 rproc_elf_get_boot_addr(struct rproc *rproc, const struct firmware *fw)
142 * directly allocate memory for every segment/resource. This is not yet 142 * directly allocate memory for every segment/resource. This is not yet
143 * supported, though. 143 * supported, though.
144 */ 144 */
145static int 145int rproc_elf_load_segments(struct rproc *rproc, const struct firmware *fw)
146rproc_elf_load_segments(struct rproc *rproc, const struct firmware *fw)
147{ 146{
148 struct device *dev = &rproc->dev; 147 struct device *dev = &rproc->dev;
149 struct elf32_hdr *ehdr; 148 struct elf32_hdr *ehdr;
@@ -207,6 +206,7 @@ rproc_elf_load_segments(struct rproc *rproc, const struct firmware *fw)
207 206
208 return ret; 207 return ret;
209} 208}
209EXPORT_SYMBOL(rproc_elf_load_segments);
210 210
211static struct elf32_shdr * 211static struct elf32_shdr *
212find_table(struct device *dev, struct elf32_hdr *ehdr, size_t fw_size) 212find_table(struct device *dev, struct elf32_hdr *ehdr, size_t fw_size)
@@ -268,41 +268,49 @@ find_table(struct device *dev, struct elf32_hdr *ehdr, size_t fw_size)
268} 268}
269 269
270/** 270/**
271 * rproc_elf_find_rsc_table() - find the resource table 271 * rproc_elf_load_rsc_table() - load the resource table
272 * @rproc: the rproc handle 272 * @rproc: the rproc handle
273 * @fw: the ELF firmware image 273 * @fw: the ELF firmware image
274 * @tablesz: place holder for providing back the table size
275 * 274 *
276 * This function finds the resource table inside the remote processor's 275 * This function finds the resource table inside the remote processor's
277 * firmware. It is used both upon the registration of @rproc (in order 276 * firmware, load it into the @cached_table and update @table_ptr.
278 * to look for and register the supported virito devices), and when the
279 * @rproc is booted.
280 * 277 *
281 * Returns the pointer to the resource table if it is found, and write its 278 * Return: 0 on success, negative errno on failure.
282 * size into @tablesz. If a valid table isn't found, NULL is returned
283 * (and @tablesz isn't set).
284 */ 279 */
285static struct resource_table * 280int rproc_elf_load_rsc_table(struct rproc *rproc, const struct firmware *fw)
286rproc_elf_find_rsc_table(struct rproc *rproc, const struct firmware *fw,
287 int *tablesz)
288{ 281{
289 struct elf32_hdr *ehdr; 282 struct elf32_hdr *ehdr;
290 struct elf32_shdr *shdr; 283 struct elf32_shdr *shdr;
291 struct device *dev = &rproc->dev; 284 struct device *dev = &rproc->dev;
292 struct resource_table *table = NULL; 285 struct resource_table *table = NULL;
293 const u8 *elf_data = fw->data; 286 const u8 *elf_data = fw->data;
287 size_t tablesz;
294 288
295 ehdr = (struct elf32_hdr *)elf_data; 289 ehdr = (struct elf32_hdr *)elf_data;
296 290
297 shdr = find_table(dev, ehdr, fw->size); 291 shdr = find_table(dev, ehdr, fw->size);
298 if (!shdr) 292 if (!shdr)
299 return NULL; 293 return -EINVAL;
300 294
301 table = (struct resource_table *)(elf_data + shdr->sh_offset); 295 table = (struct resource_table *)(elf_data + shdr->sh_offset);
302 *tablesz = shdr->sh_size; 296 tablesz = shdr->sh_size;
297
298 /*
299 * Create a copy of the resource table. When a virtio device starts
300 * and calls vring_new_virtqueue() the address of the allocated vring
301 * will be stored in the cached_table. Before the device is started,
302 * cached_table will be copied into device memory.
303 */
304 rproc->cached_table = kmemdup(table, tablesz, GFP_KERNEL);
305 if (!rproc->cached_table)
306 return -ENOMEM;
303 307
304 return table; 308 rproc->table_ptr = rproc->cached_table;
309 rproc->table_sz = tablesz;
310
311 return 0;
305} 312}
313EXPORT_SYMBOL(rproc_elf_load_rsc_table);
306 314
307/** 315/**
308 * rproc_elf_find_loaded_rsc_table() - find the loaded resource table 316 * rproc_elf_find_loaded_rsc_table() - find the loaded resource table
@@ -315,8 +323,8 @@ rproc_elf_find_rsc_table(struct rproc *rproc, const struct firmware *fw,
315 * Returns the pointer to the resource table if it is found or NULL otherwise. 323 * Returns the pointer to the resource table if it is found or NULL otherwise.
316 * If the table wasn't loaded yet the result is unspecified. 324 * If the table wasn't loaded yet the result is unspecified.
317 */ 325 */
318static struct resource_table * 326struct resource_table *rproc_elf_find_loaded_rsc_table(struct rproc *rproc,
319rproc_elf_find_loaded_rsc_table(struct rproc *rproc, const struct firmware *fw) 327 const struct firmware *fw)
320{ 328{
321 struct elf32_hdr *ehdr = (struct elf32_hdr *)fw->data; 329 struct elf32_hdr *ehdr = (struct elf32_hdr *)fw->data;
322 struct elf32_shdr *shdr; 330 struct elf32_shdr *shdr;
@@ -327,11 +335,4 @@ rproc_elf_find_loaded_rsc_table(struct rproc *rproc, const struct firmware *fw)
327 335
328 return rproc_da_to_va(rproc, shdr->sh_addr, shdr->sh_size); 336 return rproc_da_to_va(rproc, shdr->sh_addr, shdr->sh_size);
329} 337}
330 338EXPORT_SYMBOL(rproc_elf_find_loaded_rsc_table);
331const struct rproc_fw_ops rproc_elf_fw_ops = {
332 .load = rproc_elf_load_segments,
333 .find_rsc_table = rproc_elf_find_rsc_table,
334 .find_loaded_rsc_table = rproc_elf_find_loaded_rsc_table,
335 .sanity_check = rproc_elf_sanity_check,
336 .get_boot_addr = rproc_elf_get_boot_addr
337};
diff --git a/drivers/remoteproc/remoteproc_internal.h b/drivers/remoteproc/remoteproc_internal.h
index c1077bec5d0b..55a2950c5cb7 100644
--- a/drivers/remoteproc/remoteproc_internal.h
+++ b/drivers/remoteproc/remoteproc_internal.h
@@ -25,26 +25,6 @@
25 25
26struct rproc; 26struct rproc;
27 27
28/**
29 * struct rproc_fw_ops - firmware format specific operations.
30 * @find_rsc_table: find the resource table inside the firmware image
31 * @find_loaded_rsc_table: find the loaded resouce table
32 * @load: load firmeware to memory, where the remote processor
33 * expects to find it
34 * @sanity_check: sanity check the fw image
35 * @get_boot_addr: get boot address to entry point specified in firmware
36 */
37struct rproc_fw_ops {
38 struct resource_table *(*find_rsc_table)(struct rproc *rproc,
39 const struct firmware *fw,
40 int *tablesz);
41 struct resource_table *(*find_loaded_rsc_table)(
42 struct rproc *rproc, const struct firmware *fw);
43 int (*load)(struct rproc *rproc, const struct firmware *fw);
44 int (*sanity_check)(struct rproc *rproc, const struct firmware *fw);
45 u32 (*get_boot_addr)(struct rproc *rproc, const struct firmware *fw);
46};
47
48/* from remoteproc_core.c */ 28/* from remoteproc_core.c */
49void rproc_release(struct kref *kref); 29void rproc_release(struct kref *kref);
50irqreturn_t rproc_vq_interrupt(struct rproc *rproc, int vq_id); 30irqreturn_t rproc_vq_interrupt(struct rproc *rproc, int vq_id);
@@ -74,11 +54,18 @@ int rproc_alloc_vring(struct rproc_vdev *rvdev, int i);
74void *rproc_da_to_va(struct rproc *rproc, u64 da, int len); 54void *rproc_da_to_va(struct rproc *rproc, u64 da, int len);
75int rproc_trigger_recovery(struct rproc *rproc); 55int rproc_trigger_recovery(struct rproc *rproc);
76 56
57int rproc_elf_sanity_check(struct rproc *rproc, const struct firmware *fw);
58u32 rproc_elf_get_boot_addr(struct rproc *rproc, const struct firmware *fw);
59int rproc_elf_load_segments(struct rproc *rproc, const struct firmware *fw);
60int rproc_elf_load_rsc_table(struct rproc *rproc, const struct firmware *fw);
61struct resource_table *rproc_elf_find_loaded_rsc_table(struct rproc *rproc,
62 const struct firmware *fw);
63
77static inline 64static inline
78int rproc_fw_sanity_check(struct rproc *rproc, const struct firmware *fw) 65int rproc_fw_sanity_check(struct rproc *rproc, const struct firmware *fw)
79{ 66{
80 if (rproc->fw_ops->sanity_check) 67 if (rproc->ops->sanity_check)
81 return rproc->fw_ops->sanity_check(rproc, fw); 68 return rproc->ops->sanity_check(rproc, fw);
82 69
83 return 0; 70 return 0;
84} 71}
@@ -86,8 +73,8 @@ int rproc_fw_sanity_check(struct rproc *rproc, const struct firmware *fw)
86static inline 73static inline
87u32 rproc_get_boot_addr(struct rproc *rproc, const struct firmware *fw) 74u32 rproc_get_boot_addr(struct rproc *rproc, const struct firmware *fw)
88{ 75{
89 if (rproc->fw_ops->get_boot_addr) 76 if (rproc->ops->get_boot_addr)
90 return rproc->fw_ops->get_boot_addr(rproc, fw); 77 return rproc->ops->get_boot_addr(rproc, fw);
91 78
92 return 0; 79 return 0;
93} 80}
@@ -95,33 +82,29 @@ u32 rproc_get_boot_addr(struct rproc *rproc, const struct firmware *fw)
95static inline 82static inline
96int rproc_load_segments(struct rproc *rproc, const struct firmware *fw) 83int rproc_load_segments(struct rproc *rproc, const struct firmware *fw)
97{ 84{
98 if (rproc->fw_ops->load) 85 if (rproc->ops->load)
99 return rproc->fw_ops->load(rproc, fw); 86 return rproc->ops->load(rproc, fw);
100 87
101 return -EINVAL; 88 return -EINVAL;
102} 89}
103 90
104static inline 91static inline int rproc_load_rsc_table(struct rproc *rproc,
105struct resource_table *rproc_find_rsc_table(struct rproc *rproc, 92 const struct firmware *fw)
106 const struct firmware *fw,
107 int *tablesz)
108{ 93{
109 if (rproc->fw_ops->find_rsc_table) 94 if (rproc->ops->load_rsc_table)
110 return rproc->fw_ops->find_rsc_table(rproc, fw, tablesz); 95 return rproc->ops->load_rsc_table(rproc, fw);
111 96
112 return NULL; 97 return 0;
113} 98}
114 99
115static inline 100static inline
116struct resource_table *rproc_find_loaded_rsc_table(struct rproc *rproc, 101struct resource_table *rproc_find_loaded_rsc_table(struct rproc *rproc,
117 const struct firmware *fw) 102 const struct firmware *fw)
118{ 103{
119 if (rproc->fw_ops->find_loaded_rsc_table) 104 if (rproc->ops->find_loaded_rsc_table)
120 return rproc->fw_ops->find_loaded_rsc_table(rproc, fw); 105 return rproc->ops->find_loaded_rsc_table(rproc, fw);
121 106
122 return NULL; 107 return NULL;
123} 108}
124 109
125extern const struct rproc_fw_ops rproc_elf_fw_ops;
126
127#endif /* REMOTEPROC_INTERNAL_H */ 110#endif /* REMOTEPROC_INTERNAL_H */
diff --git a/drivers/remoteproc/remoteproc_virtio.c b/drivers/remoteproc/remoteproc_virtio.c
index 294634836b32..b0633fd4c041 100644
--- a/drivers/remoteproc/remoteproc_virtio.c
+++ b/drivers/remoteproc/remoteproc_virtio.c
@@ -327,7 +327,7 @@ int rproc_add_virtio_dev(struct rproc_vdev *rvdev, int id)
327 327
328 ret = register_virtio_device(vdev); 328 ret = register_virtio_device(vdev);
329 if (ret) { 329 if (ret) {
330 put_device(&rproc->dev); 330 put_device(&vdev->dev);
331 dev_err(dev, "failed to register vdev: %d\n", ret); 331 dev_err(dev, "failed to register vdev: %d\n", ret);
332 goto out; 332 goto out;
333 } 333 }
diff --git a/drivers/remoteproc/st_slim_rproc.c b/drivers/remoteproc/st_slim_rproc.c
index 6cfd862f945b..1ffb1f0c43d6 100644
--- a/drivers/remoteproc/st_slim_rproc.c
+++ b/drivers/remoteproc/st_slim_rproc.c
@@ -204,27 +204,9 @@ static const struct rproc_ops slim_rproc_ops = {
204 .start = slim_rproc_start, 204 .start = slim_rproc_start,
205 .stop = slim_rproc_stop, 205 .stop = slim_rproc_stop,
206 .da_to_va = slim_rproc_da_to_va, 206 .da_to_va = slim_rproc_da_to_va,
207}; 207 .get_boot_addr = rproc_elf_get_boot_addr,
208 208 .load = rproc_elf_load_segments,
209/* 209 .sanity_check = rproc_elf_sanity_check,
210 * Firmware handler operations: sanity, boot address, load ...
211 */
212
213static struct resource_table empty_rsc_tbl = {
214 .ver = 1,
215 .num = 0,
216};
217
218static struct resource_table *slim_rproc_find_rsc_table(struct rproc *rproc,
219 const struct firmware *fw,
220 int *tablesz)
221{
222 *tablesz = sizeof(empty_rsc_tbl);
223 return &empty_rsc_tbl;
224}
225
226static struct rproc_fw_ops slim_rproc_fw_ops = {
227 .find_rsc_table = slim_rproc_find_rsc_table,
228}; 210};
229 211
230/** 212/**
@@ -249,7 +231,6 @@ struct st_slim_rproc *st_slim_rproc_alloc(struct platform_device *pdev,
249 struct rproc *rproc; 231 struct rproc *rproc;
250 struct resource *res; 232 struct resource *res;
251 int err, i; 233 int err, i;
252 const struct rproc_fw_ops *elf_ops;
253 234
254 if (!fw_name) 235 if (!fw_name)
255 return ERR_PTR(-EINVAL); 236 return ERR_PTR(-EINVAL);
@@ -267,13 +248,6 @@ struct st_slim_rproc *st_slim_rproc_alloc(struct platform_device *pdev,
267 slim_rproc = rproc->priv; 248 slim_rproc = rproc->priv;
268 slim_rproc->rproc = rproc; 249 slim_rproc->rproc = rproc;
269 250
270 elf_ops = rproc->fw_ops;
271 /* Use some generic elf ops */
272 slim_rproc_fw_ops.load = elf_ops->load;
273 slim_rproc_fw_ops.sanity_check = elf_ops->sanity_check;
274
275 rproc->fw_ops = &slim_rproc_fw_ops;
276
277 /* get imem and dmem */ 251 /* get imem and dmem */
278 for (i = 0; i < ARRAY_SIZE(mem_names); i++) { 252 for (i = 0; i < ARRAY_SIZE(mem_names); i++) {
279 res = platform_get_resource_byname(pdev, IORESOURCE_MEM, 253 res = platform_get_resource_byname(pdev, IORESOURCE_MEM,
diff --git a/include/linux/remoteproc.h b/include/linux/remoteproc.h
index 44e630eb3d94..728d421fffe9 100644
--- a/include/linux/remoteproc.h
+++ b/include/linux/remoteproc.h
@@ -324,6 +324,7 @@ struct rproc_mem_entry {
324}; 324};
325 325
326struct rproc; 326struct rproc;
327struct firmware;
327 328
328/** 329/**
329 * struct rproc_ops - platform-specific device handlers 330 * struct rproc_ops - platform-specific device handlers
@@ -331,12 +332,24 @@ struct rproc;
331 * @stop: power off the device 332 * @stop: power off the device
332 * @kick: kick a virtqueue (virtqueue id given as a parameter) 333 * @kick: kick a virtqueue (virtqueue id given as a parameter)
333 * @da_to_va: optional platform hook to perform address translations 334 * @da_to_va: optional platform hook to perform address translations
335 * @load_rsc_table: load resource table from firmware image
336 * @find_loaded_rsc_table: find the loaded resouce table
337 * @load: load firmeware to memory, where the remote processor
338 * expects to find it
339 * @sanity_check: sanity check the fw image
340 * @get_boot_addr: get boot address to entry point specified in firmware
334 */ 341 */
335struct rproc_ops { 342struct rproc_ops {
336 int (*start)(struct rproc *rproc); 343 int (*start)(struct rproc *rproc);
337 int (*stop)(struct rproc *rproc); 344 int (*stop)(struct rproc *rproc);
338 void (*kick)(struct rproc *rproc, int vqid); 345 void (*kick)(struct rproc *rproc, int vqid);
339 void * (*da_to_va)(struct rproc *rproc, u64 da, int len); 346 void * (*da_to_va)(struct rproc *rproc, u64 da, int len);
347 int (*load_rsc_table)(struct rproc *rproc, const struct firmware *fw);
348 struct resource_table *(*find_loaded_rsc_table)(
349 struct rproc *rproc, const struct firmware *fw);
350 int (*load)(struct rproc *rproc, const struct firmware *fw);
351 int (*sanity_check)(struct rproc *rproc, const struct firmware *fw);
352 u32 (*get_boot_addr)(struct rproc *rproc, const struct firmware *fw);
340}; 353};
341 354
342/** 355/**
@@ -390,7 +403,6 @@ enum rproc_crash_type {
390 * @priv: private data which belongs to the platform-specific rproc module 403 * @priv: private data which belongs to the platform-specific rproc module
391 * @ops: platform-specific start/stop rproc handlers 404 * @ops: platform-specific start/stop rproc handlers
392 * @dev: virtual device for refcounting and common remoteproc behavior 405 * @dev: virtual device for refcounting and common remoteproc behavior
393 * @fw_ops: firmware-specific handlers
394 * @power: refcount of users who need this rproc powered up 406 * @power: refcount of users who need this rproc powered up
395 * @state: state of the device 407 * @state: state of the device
396 * @lock: lock which protects concurrent manipulations of the rproc 408 * @lock: lock which protects concurrent manipulations of the rproc
@@ -406,11 +418,11 @@ enum rproc_crash_type {
406 * @index: index of this rproc device 418 * @index: index of this rproc device
407 * @crash_handler: workqueue for handling a crash 419 * @crash_handler: workqueue for handling a crash
408 * @crash_cnt: crash counter 420 * @crash_cnt: crash counter
409 * @crash_comp: completion used to sync crash handler and the rproc reload
410 * @recovery_disabled: flag that state if recovery was disabled 421 * @recovery_disabled: flag that state if recovery was disabled
411 * @max_notifyid: largest allocated notify id. 422 * @max_notifyid: largest allocated notify id.
412 * @table_ptr: pointer to the resource table in effect 423 * @table_ptr: pointer to the resource table in effect
413 * @cached_table: copy of the resource table 424 * @cached_table: copy of the resource table
425 * @table_sz: size of @cached_table
414 * @has_iommu: flag to indicate if remote processor is behind an MMU 426 * @has_iommu: flag to indicate if remote processor is behind an MMU
415 */ 427 */
416struct rproc { 428struct rproc {
@@ -419,9 +431,8 @@ struct rproc {
419 const char *name; 431 const char *name;
420 char *firmware; 432 char *firmware;
421 void *priv; 433 void *priv;
422 const struct rproc_ops *ops; 434 struct rproc_ops *ops;
423 struct device dev; 435 struct device dev;
424 const struct rproc_fw_ops *fw_ops;
425 atomic_t power; 436 atomic_t power;
426 unsigned int state; 437 unsigned int state;
427 struct mutex lock; 438 struct mutex lock;
@@ -437,11 +448,11 @@ struct rproc {
437 int index; 448 int index;
438 struct work_struct crash_handler; 449 struct work_struct crash_handler;
439 unsigned int crash_cnt; 450 unsigned int crash_cnt;
440 struct completion crash_comp;
441 bool recovery_disabled; 451 bool recovery_disabled;
442 int max_notifyid; 452 int max_notifyid;
443 struct resource_table *table_ptr; 453 struct resource_table *table_ptr;
444 struct resource_table *cached_table; 454 struct resource_table *cached_table;
455 size_t table_sz;
445 bool has_iommu; 456 bool has_iommu;
446 bool auto_boot; 457 bool auto_boot;
447}; 458};