diff options
-rw-r--r-- | drivers/remoteproc/remoteproc_core.c | 52 |
1 files changed, 12 insertions, 40 deletions
diff --git a/drivers/remoteproc/remoteproc_core.c b/drivers/remoteproc/remoteproc_core.c index 29387df4bfc9..b8228c628b0c 100644 --- a/drivers/remoteproc/remoteproc_core.c +++ b/drivers/remoteproc/remoteproc_core.c | |||
@@ -673,16 +673,21 @@ free_carv: | |||
673 | * A lookup table for resource handlers. The indices are defined in | 673 | * A lookup table for resource handlers. The indices are defined in |
674 | * enum fw_resource_type. | 674 | * enum fw_resource_type. |
675 | */ | 675 | */ |
676 | static rproc_handle_resource_t rproc_handle_rsc[] = { | 676 | static rproc_handle_resource_t rproc_loading_handlers[RSC_LAST] = { |
677 | [RSC_CARVEOUT] = (rproc_handle_resource_t)rproc_handle_carveout, | 677 | [RSC_CARVEOUT] = (rproc_handle_resource_t)rproc_handle_carveout, |
678 | [RSC_DEVMEM] = (rproc_handle_resource_t)rproc_handle_devmem, | 678 | [RSC_DEVMEM] = (rproc_handle_resource_t)rproc_handle_devmem, |
679 | [RSC_TRACE] = (rproc_handle_resource_t)rproc_handle_trace, | 679 | [RSC_TRACE] = (rproc_handle_resource_t)rproc_handle_trace, |
680 | [RSC_VDEV] = NULL, /* VDEVs were handled upon registrarion */ | 680 | [RSC_VDEV] = NULL, /* VDEVs were handled upon registrarion */ |
681 | }; | 681 | }; |
682 | 682 | ||
683 | static rproc_handle_resource_t rproc_vdev_handler[RSC_LAST] = { | ||
684 | [RSC_VDEV] = (rproc_handle_resource_t)rproc_handle_vdev, | ||
685 | }; | ||
686 | |||
683 | /* handle firmware resource entries before booting the remote processor */ | 687 | /* handle firmware resource entries before booting the remote processor */ |
684 | static int | 688 | static int rproc_handle_resources(struct rproc *rproc, |
685 | rproc_handle_boot_rsc(struct rproc *rproc, struct resource_table *table, int len) | 689 | struct resource_table *table, int len, |
690 | rproc_handle_resource_t handlers[RSC_LAST]) | ||
686 | { | 691 | { |
687 | struct device *dev = &rproc->dev; | 692 | struct device *dev = &rproc->dev; |
688 | rproc_handle_resource_t handler; | 693 | rproc_handle_resource_t handler; |
@@ -707,7 +712,7 @@ rproc_handle_boot_rsc(struct rproc *rproc, struct resource_table *table, int len | |||
707 | continue; | 712 | continue; |
708 | } | 713 | } |
709 | 714 | ||
710 | handler = rproc_handle_rsc[hdr->type]; | 715 | handler = handlers[hdr->type]; |
711 | if (!handler) | 716 | if (!handler) |
712 | continue; | 717 | continue; |
713 | 718 | ||
@@ -719,40 +724,6 @@ rproc_handle_boot_rsc(struct rproc *rproc, struct resource_table *table, int len | |||
719 | return ret; | 724 | return ret; |
720 | } | 725 | } |
721 | 726 | ||
722 | /* handle firmware resource entries while registering the remote processor */ | ||
723 | static int | ||
724 | rproc_handle_virtio_rsc(struct rproc *rproc, struct resource_table *table, int len) | ||
725 | { | ||
726 | struct device *dev = &rproc->dev; | ||
727 | int ret = 0, i; | ||
728 | |||
729 | for (i = 0; i < table->num; i++) { | ||
730 | int offset = table->offset[i]; | ||
731 | struct fw_rsc_hdr *hdr = (void *)table + offset; | ||
732 | int avail = len - offset - sizeof(*hdr); | ||
733 | struct fw_rsc_vdev *vrsc; | ||
734 | |||
735 | /* make sure table isn't truncated */ | ||
736 | if (avail < 0) { | ||
737 | dev_err(dev, "rsc table is truncated\n"); | ||
738 | return -EINVAL; | ||
739 | } | ||
740 | |||
741 | dev_dbg(dev, "%s: rsc type %d\n", __func__, hdr->type); | ||
742 | |||
743 | if (hdr->type != RSC_VDEV) | ||
744 | continue; | ||
745 | |||
746 | vrsc = (struct fw_rsc_vdev *)hdr->data; | ||
747 | |||
748 | ret = rproc_handle_vdev(rproc, vrsc, avail); | ||
749 | if (ret) | ||
750 | break; | ||
751 | } | ||
752 | |||
753 | return ret; | ||
754 | } | ||
755 | |||
756 | /** | 727 | /** |
757 | * rproc_resource_cleanup() - clean up and free all acquired resources | 728 | * rproc_resource_cleanup() - clean up and free all acquired resources |
758 | * @rproc: rproc handle | 729 | * @rproc: rproc handle |
@@ -832,7 +803,8 @@ static int rproc_fw_boot(struct rproc *rproc, const struct firmware *fw) | |||
832 | } | 803 | } |
833 | 804 | ||
834 | /* handle fw resources which are required to boot rproc */ | 805 | /* handle fw resources which are required to boot rproc */ |
835 | ret = rproc_handle_boot_rsc(rproc, table, tablesz); | 806 | ret = rproc_handle_resources(rproc, table, tablesz, |
807 | rproc_loading_handlers); | ||
836 | if (ret) { | 808 | if (ret) { |
837 | dev_err(dev, "Failed to process resources: %d\n", ret); | 809 | dev_err(dev, "Failed to process resources: %d\n", ret); |
838 | goto clean_up; | 810 | goto clean_up; |
@@ -887,7 +859,7 @@ static void rproc_fw_config_virtio(const struct firmware *fw, void *context) | |||
887 | goto out; | 859 | goto out; |
888 | 860 | ||
889 | /* look for virtio devices and register them */ | 861 | /* look for virtio devices and register them */ |
890 | ret = rproc_handle_virtio_rsc(rproc, table, tablesz); | 862 | ret = rproc_handle_resources(rproc, table, tablesz, rproc_vdev_handler); |
891 | if (ret) | 863 | if (ret) |
892 | goto out; | 864 | goto out; |
893 | 865 | ||