diff options
author | Ohad Ben-Cohen <ohad@wizery.com> | 2012-01-31 09:07:27 -0500 |
---|---|---|
committer | Ohad Ben-Cohen <ohad@wizery.com> | 2012-02-22 11:28:49 -0500 |
commit | e12bc14b88d44e5c1456dccb59ff58103f6c6edc (patch) | |
tree | c7df21efc8f6f3649a35c16b01e90c16ce51d49a /drivers/remoteproc | |
parent | cf59d3e9a715fd2b6ff96e4a3a130fceded09a64 (diff) |
remoteproc: s/big switch/lookup table/
A lookup table would be easier to extend, and the resulting
code is a bit cleaner.
Reported-by: Grant Likely <grant.likely@secretlab.ca>
Signed-off-by: Ohad Ben-Cohen <ohad@wizery.com>
Diffstat (limited to 'drivers/remoteproc')
-rw-r--r-- | drivers/remoteproc/remoteproc_core.c | 45 |
1 files changed, 23 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 | ||
65 | typedef int (*rproc_handle_resources_t)(struct rproc *rproc, | 65 | typedef int (*rproc_handle_resources_t)(struct rproc *rproc, |
66 | struct fw_resource *rsc, int len); | 66 | struct fw_resource *rsc, int len); |
67 | typedef 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 | */ | ||
667 | static 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 */ |
662 | static int | 676 | static int |
663 | rproc_handle_boot_rsc(struct rproc *rproc, struct fw_resource *rsc, int len) | 677 | rproc_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; |