diff options
| -rw-r--r-- | drivers/remoteproc/remoteproc_core.c | 4 | ||||
| -rw-r--r-- | drivers/remoteproc/remoteproc_elf_loader.c | 30 | ||||
| -rw-r--r-- | drivers/remoteproc/remoteproc_internal.h | 59 | ||||
| -rw-r--r-- | include/linux/remoteproc.h | 2 |
4 files changed, 79 insertions, 16 deletions
diff --git a/drivers/remoteproc/remoteproc_core.c b/drivers/remoteproc/remoteproc_core.c index c68b3bb567f4..f4d6f7bb91fd 100644 --- a/drivers/remoteproc/remoteproc_core.c +++ b/drivers/remoteproc/remoteproc_core.c | |||
| @@ -172,6 +172,7 @@ void *rproc_da_to_va(struct rproc *rproc, u64 da, int len) | |||
| 172 | 172 | ||
| 173 | return ptr; | 173 | return ptr; |
| 174 | } | 174 | } |
| 175 | EXPORT_SYMBOL(rproc_da_to_va); | ||
| 175 | 176 | ||
| 176 | int rproc_alloc_vring(struct rproc_vdev *rvdev, int i) | 177 | int rproc_alloc_vring(struct rproc_vdev *rvdev, int i) |
| 177 | { | 178 | { |
| @@ -1150,6 +1151,9 @@ struct rproc *rproc_alloc(struct device *dev, const char *name, | |||
| 1150 | 1151 | ||
| 1151 | atomic_set(&rproc->power, 0); | 1152 | atomic_set(&rproc->power, 0); |
| 1152 | 1153 | ||
| 1154 | /* Set ELF as the default fw_ops handler */ | ||
| 1155 | rproc->fw_ops = &rproc_elf_fw_ops; | ||
| 1156 | |||
| 1153 | mutex_init(&rproc->lock); | 1157 | mutex_init(&rproc->lock); |
| 1154 | 1158 | ||
| 1155 | idr_init(&rproc->notifyids); | 1159 | idr_init(&rproc->notifyids); |
diff --git a/drivers/remoteproc/remoteproc_elf_loader.c b/drivers/remoteproc/remoteproc_elf_loader.c index 2c6fe6ad2d95..6eebd01ea985 100644 --- a/drivers/remoteproc/remoteproc_elf_loader.c +++ b/drivers/remoteproc/remoteproc_elf_loader.c | |||
| @@ -33,14 +33,14 @@ | |||
| 33 | #include "remoteproc_internal.h" | 33 | #include "remoteproc_internal.h" |
| 34 | 34 | ||
| 35 | /** | 35 | /** |
| 36 | * rproc_fw_sanity_check() - Sanity Check ELF firmware image | 36 | * rproc_elf_sanity_check() - Sanity Check ELF firmware image |
| 37 | * @rproc: the remote processor handle | 37 | * @rproc: the remote processor handle |
| 38 | * @fw: the ELF firmware image | 38 | * @fw: the ELF firmware image |
| 39 | * | 39 | * |
| 40 | * Make sure this fw image is sane. | 40 | * Make sure this fw image is sane. |
| 41 | */ | 41 | */ |
| 42 | int | 42 | static int |
| 43 | rproc_fw_sanity_check(struct rproc *rproc, const struct firmware *fw) | 43 | rproc_elf_sanity_check(struct rproc *rproc, const struct firmware *fw) |
| 44 | { | 44 | { |
| 45 | const char *name = rproc->firmware; | 45 | const char *name = rproc->firmware; |
| 46 | struct device *dev = &rproc->dev; | 46 | struct device *dev = &rproc->dev; |
| @@ -100,7 +100,7 @@ rproc_fw_sanity_check(struct rproc *rproc, const struct firmware *fw) | |||
| 100 | } | 100 | } |
| 101 | 101 | ||
| 102 | /** | 102 | /** |
| 103 | * rproc_get_boot_addr() - Get rproc's boot address. | 103 | * rproc_elf_get_boot_addr() - Get rproc's boot address. |
| 104 | * @rproc: the remote processor handle | 104 | * @rproc: the remote processor handle |
| 105 | * @fw: the ELF firmware image | 105 | * @fw: the ELF firmware image |
| 106 | * | 106 | * |
| @@ -110,7 +110,8 @@ rproc_fw_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 | */ |
| 113 | u32 rproc_get_boot_addr(struct rproc *rproc, const struct firmware *fw) | 113 | static |
| 114 | u32 rproc_elf_get_boot_addr(struct rproc *rproc, const struct firmware *fw) | ||
| 114 | { | 115 | { |
| 115 | struct elf32_hdr *ehdr = (struct elf32_hdr *)fw->data; | 116 | struct elf32_hdr *ehdr = (struct elf32_hdr *)fw->data; |
| 116 | 117 | ||
| @@ -118,7 +119,7 @@ u32 rproc_get_boot_addr(struct rproc *rproc, const struct firmware *fw) | |||
| 118 | } | 119 | } |
| 119 | 120 | ||
| 120 | /** | 121 | /** |
| 121 | * rproc_load_segments() - load firmware segments to memory | 122 | * rproc_elf_load_segments() - load firmware segments to memory |
| 122 | * @rproc: remote processor which will be booted using these fw segments | 123 | * @rproc: remote processor which will be booted using these fw segments |
| 123 | * @fw: the ELF firmware image | 124 | * @fw: the ELF firmware image |
| 124 | * | 125 | * |
| @@ -141,8 +142,8 @@ u32 rproc_get_boot_addr(struct rproc *rproc, const struct firmware *fw) | |||
| 141 | * directly allocate memory for every segment/resource. This is not yet | 142 | * directly allocate memory for every segment/resource. This is not yet |
| 142 | * supported, though. | 143 | * supported, though. |
| 143 | */ | 144 | */ |
| 144 | int | 145 | static int |
| 145 | rproc_load_segments(struct rproc *rproc, const struct firmware *fw) | 146 | rproc_elf_load_segments(struct rproc *rproc, const struct firmware *fw) |
| 146 | { | 147 | { |
| 147 | struct device *dev = &rproc->dev; | 148 | struct device *dev = &rproc->dev; |
| 148 | struct elf32_hdr *ehdr; | 149 | struct elf32_hdr *ehdr; |
| @@ -208,7 +209,7 @@ rproc_load_segments(struct rproc *rproc, const struct firmware *fw) | |||
| 208 | } | 209 | } |
| 209 | 210 | ||
| 210 | /** | 211 | /** |
| 211 | * rproc_find_rsc_table() - find the resource table | 212 | * rproc_elf_find_rsc_table() - find the resource table |
| 212 | * @rproc: the rproc handle | 213 | * @rproc: the rproc handle |
| 213 | * @fw: the ELF firmware image | 214 | * @fw: the ELF firmware image |
| 214 | * @tablesz: place holder for providing back the table size | 215 | * @tablesz: place holder for providing back the table size |
| @@ -222,8 +223,8 @@ rproc_load_segments(struct rproc *rproc, const struct firmware *fw) | |||
| 222 | * size into @tablesz. If a valid table isn't found, NULL is returned | 223 | * size into @tablesz. If a valid table isn't found, NULL is returned |
| 223 | * (and @tablesz isn't set). | 224 | * (and @tablesz isn't set). |
| 224 | */ | 225 | */ |
| 225 | struct resource_table * | 226 | static struct resource_table * |
| 226 | rproc_find_rsc_table(struct rproc *rproc, const struct firmware *fw, | 227 | rproc_elf_find_rsc_table(struct rproc *rproc, const struct firmware *fw, |
| 227 | int *tablesz) | 228 | int *tablesz) |
| 228 | { | 229 | { |
| 229 | struct elf32_hdr *ehdr; | 230 | struct elf32_hdr *ehdr; |
| @@ -285,3 +286,10 @@ rproc_find_rsc_table(struct rproc *rproc, const struct firmware *fw, | |||
| 285 | 286 | ||
| 286 | return table; | 287 | return table; |
| 287 | } | 288 | } |
| 289 | |||
| 290 | const struct rproc_fw_ops rproc_elf_fw_ops = { | ||
| 291 | .load = rproc_elf_load_segments, | ||
| 292 | .find_rsc_table = rproc_elf_find_rsc_table, | ||
| 293 | .sanity_check = rproc_elf_sanity_check, | ||
| 294 | .get_boot_addr = rproc_elf_get_boot_addr | ||
| 295 | }; | ||
diff --git a/drivers/remoteproc/remoteproc_internal.h b/drivers/remoteproc/remoteproc_internal.h index a44e1926e4c3..a690ebe7aa51 100644 --- a/drivers/remoteproc/remoteproc_internal.h +++ b/drivers/remoteproc/remoteproc_internal.h | |||
| @@ -25,6 +25,23 @@ | |||
| 25 | 25 | ||
| 26 | struct rproc; | 26 | struct rproc; |
| 27 | 27 | ||
| 28 | /** | ||
| 29 | * struct rproc_fw_ops - firmware format specific operations. | ||
| 30 | * @find_rsc_table: finds the resource table inside the firmware image | ||
| 31 | * @load: load firmeware to memory, where the remote processor | ||
| 32 | * expects to find it | ||
| 33 | * @sanity_check: sanity check the fw image | ||
| 34 | * @get_boot_addr: get boot address to entry point specified in firmware | ||
| 35 | */ | ||
| 36 | struct rproc_fw_ops { | ||
| 37 | struct resource_table *(*find_rsc_table) (struct rproc *rproc, | ||
| 38 | const struct firmware *fw, | ||
| 39 | int *tablesz); | ||
| 40 | int (*load)(struct rproc *rproc, const struct firmware *fw); | ||
| 41 | int (*sanity_check)(struct rproc *rproc, const struct firmware *fw); | ||
| 42 | u32 (*get_boot_addr)(struct rproc *rproc, const struct firmware *fw); | ||
| 43 | }; | ||
| 44 | |||
| 28 | /* from remoteproc_core.c */ | 45 | /* from remoteproc_core.c */ |
| 29 | void rproc_release(struct kref *kref); | 46 | void rproc_release(struct kref *kref); |
| 30 | irqreturn_t rproc_vq_interrupt(struct rproc *rproc, int vq_id); | 47 | irqreturn_t rproc_vq_interrupt(struct rproc *rproc, int vq_id); |
| @@ -47,11 +64,43 @@ int rproc_alloc_vring(struct rproc_vdev *rvdev, int i); | |||
| 47 | 64 | ||
| 48 | void *rproc_da_to_va(struct rproc *rproc, u64 da, int len); | 65 | void *rproc_da_to_va(struct rproc *rproc, u64 da, int len); |
| 49 | 66 | ||
| 67 | static inline | ||
| 68 | int rproc_fw_sanity_check(struct rproc *rproc, const struct firmware *fw) | ||
| 69 | { | ||
| 70 | if (rproc->fw_ops->sanity_check) | ||
| 71 | return rproc->fw_ops->sanity_check(rproc, fw); | ||
| 72 | |||
| 73 | return 0; | ||
| 74 | } | ||
| 75 | |||
| 76 | static inline | ||
| 77 | u32 rproc_get_boot_addr(struct rproc *rproc, const struct firmware *fw) | ||
| 78 | { | ||
| 79 | if (rproc->fw_ops->get_boot_addr) | ||
| 80 | return rproc->fw_ops->get_boot_addr(rproc, fw); | ||
| 81 | |||
| 82 | return 0; | ||
| 83 | } | ||
| 84 | |||
| 85 | static inline | ||
| 86 | int rproc_load_segments(struct rproc *rproc, const struct firmware *fw) | ||
| 87 | { | ||
| 88 | if (rproc->fw_ops->load) | ||
| 89 | return rproc->fw_ops->load(rproc, fw); | ||
| 90 | |||
| 91 | return -EINVAL; | ||
| 92 | } | ||
| 93 | |||
| 94 | static inline | ||
| 50 | struct resource_table *rproc_find_rsc_table(struct rproc *rproc, | 95 | struct resource_table *rproc_find_rsc_table(struct rproc *rproc, |
| 51 | const struct firmware *fw, | 96 | const struct firmware *fw, int *tablesz) |
| 52 | int *tablesz); | 97 | { |
| 53 | int rproc_load_segments(struct rproc *rproc, const struct firmware *fw); | 98 | if (rproc->fw_ops->find_rsc_table) |
| 54 | int rproc_fw_sanity_check(struct rproc *rproc, const struct firmware *fw); | 99 | return rproc->fw_ops->find_rsc_table(rproc, fw, tablesz); |
| 55 | u32 rproc_get_boot_addr(struct rproc *rproc, const struct firmware *fw); | 100 | |
| 101 | return NULL; | ||
| 102 | } | ||
| 103 | |||
| 104 | extern const struct rproc_fw_ops rproc_elf_fw_ops; | ||
| 56 | 105 | ||
| 57 | #endif /* REMOTEPROC_INTERNAL_H */ | 106 | #endif /* REMOTEPROC_INTERNAL_H */ |
diff --git a/include/linux/remoteproc.h b/include/linux/remoteproc.h index eea3ac86b2b7..131b53957b9f 100644 --- a/include/linux/remoteproc.h +++ b/include/linux/remoteproc.h | |||
| @@ -369,6 +369,7 @@ enum rproc_state { | |||
| 369 | * @priv: private data which belongs to the platform-specific rproc module | 369 | * @priv: private data which belongs to the platform-specific rproc module |
| 370 | * @ops: platform-specific start/stop rproc handlers | 370 | * @ops: platform-specific start/stop rproc handlers |
| 371 | * @dev: virtual device for refcounting and common remoteproc behavior | 371 | * @dev: virtual device for refcounting and common remoteproc behavior |
| 372 | * @fw_ops: firmware-specific handlers | ||
| 372 | * @power: refcount of users who need this rproc powered up | 373 | * @power: refcount of users who need this rproc powered up |
| 373 | * @state: state of the device | 374 | * @state: state of the device |
| 374 | * @lock: lock which protects concurrent manipulations of the rproc | 375 | * @lock: lock which protects concurrent manipulations of the rproc |
| @@ -391,6 +392,7 @@ struct rproc { | |||
| 391 | void *priv; | 392 | void *priv; |
| 392 | const struct rproc_ops *ops; | 393 | const struct rproc_ops *ops; |
| 393 | struct device dev; | 394 | struct device dev; |
| 395 | const struct rproc_fw_ops *fw_ops; | ||
| 394 | atomic_t power; | 396 | atomic_t power; |
| 395 | unsigned int state; | 397 | unsigned int state; |
| 396 | struct mutex lock; | 398 | struct mutex lock; |
