diff options
author | Ohad Ben-Cohen <ohad@wizery.com> | 2012-01-31 16:07:27 +0200 |
---|---|---|
committer | Ohad Ben-Cohen <ohad@wizery.com> | 2012-02-22 18:28:49 +0200 |
commit | e12bc14b88d44e5c1456dccb59ff58103f6c6edc (patch) | |
tree | c7df21efc8f6f3649a35c16b01e90c16ce51d49a /drivers/remoteproc | |
parent | cf59d3e9a715fd2b6ff96e4a3a130fceded09a64 (diff) | |
download | linux-e12bc14b88d44e5c1456dccb59ff58103f6c6edc.tar.gz linux-e12bc14b88d44e5c1456dccb59ff58103f6c6edc.tar.bz2 linux-e12bc14b88d44e5c1456dccb59ff58103f6c6edc.zip |
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); typedef int (*rproc_handle_resources_t)(struct rproc *rproc, struct fw_resource *rsc, int len); +typedef int (*rproc_handle_resource_t)(struct rproc *rproc, + struct fw_resource *rsc); /* * This is the IOMMU fault handler we register with the IOMMU API @@ -658,44 +660,43 @@ free_mapping: return ret; } +/* + * A lookup table for resource handlers. The indices are defined in + * enum fw_resource_type. + */ +static rproc_handle_resource_t rproc_handle_rsc[] = { + [RSC_CARVEOUT] = rproc_handle_carveout, + [RSC_DEVMEM] = rproc_handle_devmem, + [RSC_TRACE] = rproc_handle_trace, + [RSC_VRING] = rproc_handle_vring, + [RSC_VIRTIO_DEV] = NULL, /* handled early upon registration */ +}; + /* handle firmware resource entries before booting the remote processor */ static int rproc_handle_boot_rsc(struct rproc *rproc, struct fw_resource *rsc, int len) { struct device *dev = rproc->dev; + rproc_handle_resource_t handler; int ret = 0; - while (len >= sizeof(*rsc)) { + for (; len >= sizeof(*rsc); rsc++, len -= sizeof(*rsc)) { dev_dbg(dev, "rsc: type %d, da 0x%llx, pa 0x%llx, len 0x%x, " "id %d, name %s, flags %x\n", rsc->type, rsc->da, rsc->pa, rsc->len, rsc->id, rsc->name, rsc->flags); - switch (rsc->type) { - case RSC_CARVEOUT: - ret = rproc_handle_carveout(rproc, rsc); - break; - case RSC_DEVMEM: - ret = rproc_handle_devmem(rproc, rsc); - break; - case RSC_TRACE: - ret = rproc_handle_trace(rproc, rsc); - break; - case RSC_VRING: - ret = rproc_handle_vring(rproc, rsc); - break; - case RSC_VIRTIO_DEV: - /* this one is handled early upon registration */ - break; - default: + if (rsc->type >= RSC_LAST) { dev_warn(dev, "unsupported resource %d\n", rsc->type); - break; + continue; } + handler = rproc_handle_rsc[rsc->type]; + if (!handler) + continue; + + ret = handler(rproc, rsc); if (ret) break; - - rsc++; - len -= sizeof(*rsc); } return ret; |