aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--drivers/remoteproc/remoteproc_core.c45
-rw-r--r--include/linux/remoteproc.h7
2 files changed, 30 insertions, 22 deletions
diff --git a/drivers/remoteproc/remoteproc_core.c b/drivers/remoteproc/remoteproc_core.c
index 567a3c59b4af..729911b67a9a 100644
--- a/drivers/remoteproc/remoteproc_core.c
+++ b/drivers/remoteproc/remoteproc_core.c
@@ -64,6 +64,8 @@ static DEFINE_KLIST(rprocs, klist_rproc_get, klist_rproc_put);
64 64
65typedef int (*rproc_handle_resources_t)(struct rproc *rproc, 65typedef int (*rproc_handle_resources_t)(struct rproc *rproc,
66 struct fw_resource *rsc, int len); 66 struct fw_resource *rsc, int len);
67typedef int (*rproc_handle_resource_t)(struct rproc *rproc,
68 struct fw_resource *rsc);
67 69
68/* 70/*
69 * This is the IOMMU fault handler we register with the IOMMU API 71 * This is the IOMMU fault handler we register with the IOMMU API
@@ -658,44 +660,43 @@ free_mapping:
658 return ret; 660 return ret;
659} 661}
660 662
663/*
664 * A lookup table for resource handlers. The indices are defined in
665 * enum fw_resource_type.
666 */
667static rproc_handle_resource_t rproc_handle_rsc[] = {
668 [RSC_CARVEOUT] = rproc_handle_carveout,
669 [RSC_DEVMEM] = rproc_handle_devmem,
670 [RSC_TRACE] = rproc_handle_trace,
671 [RSC_VRING] = rproc_handle_vring,
672 [RSC_VIRTIO_DEV] = NULL, /* handled early upon registration */
673};
674
661/* handle firmware resource entries before booting the remote processor */ 675/* handle firmware resource entries before booting the remote processor */
662static int 676static int
663rproc_handle_boot_rsc(struct rproc *rproc, struct fw_resource *rsc, int len) 677rproc_handle_boot_rsc(struct rproc *rproc, struct fw_resource *rsc, int len)
664{ 678{
665 struct device *dev = rproc->dev; 679 struct device *dev = rproc->dev;
680 rproc_handle_resource_t handler;
666 int ret = 0; 681 int ret = 0;
667 682
668 while (len >= sizeof(*rsc)) { 683 for (; len >= sizeof(*rsc); rsc++, len -= sizeof(*rsc)) {
669 dev_dbg(dev, "rsc: type %d, da 0x%llx, pa 0x%llx, len 0x%x, " 684 dev_dbg(dev, "rsc: type %d, da 0x%llx, pa 0x%llx, len 0x%x, "
670 "id %d, name %s, flags %x\n", rsc->type, rsc->da, 685 "id %d, name %s, flags %x\n", rsc->type, rsc->da,
671 rsc->pa, rsc->len, rsc->id, rsc->name, rsc->flags); 686 rsc->pa, rsc->len, rsc->id, rsc->name, rsc->flags);
672 687
673 switch (rsc->type) { 688 if (rsc->type >= RSC_LAST) {
674 case RSC_CARVEOUT:
675 ret = rproc_handle_carveout(rproc, rsc);
676 break;
677 case RSC_DEVMEM:
678 ret = rproc_handle_devmem(rproc, rsc);
679 break;
680 case RSC_TRACE:
681 ret = rproc_handle_trace(rproc, rsc);
682 break;
683 case RSC_VRING:
684 ret = rproc_handle_vring(rproc, rsc);
685 break;
686 case RSC_VIRTIO_DEV:
687 /* this one is handled early upon registration */
688 break;
689 default:
690 dev_warn(dev, "unsupported resource %d\n", rsc->type); 689 dev_warn(dev, "unsupported resource %d\n", rsc->type);
691 break; 690 continue;
692 } 691 }
693 692
693 handler = rproc_handle_rsc[rsc->type];
694 if (!handler)
695 continue;
696
697 ret = handler(rproc, rsc);
694 if (ret) 698 if (ret)
695 break; 699 break;
696
697 rsc++;
698 len -= sizeof(*rsc);
699 } 700 }
700 701
701 return ret; 702 return ret;
diff --git a/include/linux/remoteproc.h b/include/linux/remoteproc.h
index b52f78413c5c..ada4cb063dfe 100644
--- a/include/linux/remoteproc.h
+++ b/include/linux/remoteproc.h
@@ -103,6 +103,7 @@ struct fw_resource {
103 * the virtio device features, 'pa' holds the virtio guest 103 * the virtio device features, 'pa' holds the virtio guest
104 * features, 'len' holds the virtio status, and 'flags' holds 104 * features, 'len' holds the virtio status, and 'flags' holds
105 * the virtio id (currently only VIRTIO_ID_RPMSG is supported). 105 * the virtio id (currently only VIRTIO_ID_RPMSG is supported).
106 * @RSC_LAST: just keep this one at the end
106 * 107 *
107 * Most of the resource entries share the basic idea of address/length 108 * Most of the resource entries share the basic idea of address/length
108 * negotiation with the host: the firmware usually asks (on behalf of the 109 * negotiation with the host: the firmware usually asks (on behalf of the
@@ -115,6 +116,11 @@ struct fw_resource {
115 * will contain the expected device addresses (today we actually only support 116 * will contain the expected device addresses (today we actually only support
116 * this scheme, as there aren't yet any use cases for dynamically allocated 117 * this scheme, as there aren't yet any use cases for dynamically allocated
117 * device addresses). 118 * device addresses).
119 *
120 * Please note that these values are used as indices to the rproc_handle_rsc
121 * lookup table, so please keep them sane. Moreover, @RSC_LAST is used to
122 * check the validity of an index before the lookup table is accessed, so
123 * please update it as needed.
118 */ 124 */
119enum fw_resource_type { 125enum fw_resource_type {
120 RSC_CARVEOUT = 0, 126 RSC_CARVEOUT = 0,
@@ -122,6 +128,7 @@ enum fw_resource_type {
122 RSC_TRACE = 2, 128 RSC_TRACE = 2,
123 RSC_VRING = 3, 129 RSC_VRING = 3,
124 RSC_VIRTIO_DEV = 4, 130 RSC_VIRTIO_DEV = 4,
131 RSC_LAST = 5,
125}; 132};
126 133
127/** 134/**