remoteproc: Support custom firmware handlers
Firmware handling is made customizable. This is done by creating a separate ops structure for the firmware functions that depends on a particular firmware format (such as ELF). The ELF functions are default used unless the HW driver explicitly injects another firmware handler by updating rproc->fw_ops. The function rproc_da_to_va() is exported, as custom firmware handlers may need to use this function. Signed-off-by: Sjur Brændeland <sjur.brandeland@stericsson.com> [ohad: namespace fixes, whitespace fixes, style fixes] Signed-off-by: Ohad Ben-Cohen <ohad@wizery.com>wifi-calibration
parent
72854fb042
commit
4afc89d66c
|
@ -172,6 +172,7 @@ void *rproc_da_to_va(struct rproc *rproc, u64 da, int len)
|
||||||
|
|
||||||
return ptr;
|
return ptr;
|
||||||
}
|
}
|
||||||
|
EXPORT_SYMBOL(rproc_da_to_va);
|
||||||
|
|
||||||
int rproc_alloc_vring(struct rproc_vdev *rvdev, int i)
|
int rproc_alloc_vring(struct rproc_vdev *rvdev, int i)
|
||||||
{
|
{
|
||||||
|
@ -1150,6 +1151,9 @@ struct rproc *rproc_alloc(struct device *dev, const char *name,
|
||||||
|
|
||||||
atomic_set(&rproc->power, 0);
|
atomic_set(&rproc->power, 0);
|
||||||
|
|
||||||
|
/* Set ELF as the default fw_ops handler */
|
||||||
|
rproc->fw_ops = &rproc_elf_fw_ops;
|
||||||
|
|
||||||
mutex_init(&rproc->lock);
|
mutex_init(&rproc->lock);
|
||||||
|
|
||||||
idr_init(&rproc->notifyids);
|
idr_init(&rproc->notifyids);
|
||||||
|
|
|
@ -33,14 +33,14 @@
|
||||||
#include "remoteproc_internal.h"
|
#include "remoteproc_internal.h"
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* rproc_fw_sanity_check() - Sanity Check ELF firmware image
|
* rproc_elf_sanity_check() - Sanity Check ELF firmware image
|
||||||
* @rproc: the remote processor handle
|
* @rproc: the remote processor handle
|
||||||
* @fw: the ELF firmware image
|
* @fw: the ELF firmware image
|
||||||
*
|
*
|
||||||
* Make sure this fw image is sane.
|
* Make sure this fw image is sane.
|
||||||
*/
|
*/
|
||||||
int
|
static int
|
||||||
rproc_fw_sanity_check(struct rproc *rproc, const struct firmware *fw)
|
rproc_elf_sanity_check(struct rproc *rproc, const struct firmware *fw)
|
||||||
{
|
{
|
||||||
const char *name = rproc->firmware;
|
const char *name = rproc->firmware;
|
||||||
struct device *dev = &rproc->dev;
|
struct device *dev = &rproc->dev;
|
||||||
|
@ -100,7 +100,7 @@ rproc_fw_sanity_check(struct rproc *rproc, const struct firmware *fw)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* rproc_get_boot_addr() - Get rproc's boot address.
|
* rproc_elf_get_boot_addr() - Get rproc's boot address.
|
||||||
* @rproc: the remote processor handle
|
* @rproc: the remote processor handle
|
||||||
* @fw: the ELF firmware image
|
* @fw: the ELF firmware image
|
||||||
*
|
*
|
||||||
|
@ -110,7 +110,8 @@ rproc_fw_sanity_check(struct rproc *rproc, const struct firmware *fw)
|
||||||
* Note that the boot address is not a configurable property of all remote
|
* Note that the boot address is not a configurable property of all remote
|
||||||
* processors. Some will always boot at a specific hard-coded address.
|
* processors. Some will always boot at a specific hard-coded address.
|
||||||
*/
|
*/
|
||||||
u32 rproc_get_boot_addr(struct rproc *rproc, const struct firmware *fw)
|
static
|
||||||
|
u32 rproc_elf_get_boot_addr(struct rproc *rproc, const struct firmware *fw)
|
||||||
{
|
{
|
||||||
struct elf32_hdr *ehdr = (struct elf32_hdr *)fw->data;
|
struct elf32_hdr *ehdr = (struct elf32_hdr *)fw->data;
|
||||||
|
|
||||||
|
@ -118,7 +119,7 @@ u32 rproc_get_boot_addr(struct rproc *rproc, const struct firmware *fw)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* rproc_load_segments() - load firmware segments to memory
|
* rproc_elf_load_segments() - load firmware segments to memory
|
||||||
* @rproc: remote processor which will be booted using these fw segments
|
* @rproc: remote processor which will be booted using these fw segments
|
||||||
* @fw: the ELF firmware image
|
* @fw: the ELF firmware image
|
||||||
*
|
*
|
||||||
|
@ -141,8 +142,8 @@ u32 rproc_get_boot_addr(struct rproc *rproc, const struct firmware *fw)
|
||||||
* directly allocate memory for every segment/resource. This is not yet
|
* directly allocate memory for every segment/resource. This is not yet
|
||||||
* supported, though.
|
* supported, though.
|
||||||
*/
|
*/
|
||||||
int
|
static int
|
||||||
rproc_load_segments(struct rproc *rproc, const struct firmware *fw)
|
rproc_elf_load_segments(struct rproc *rproc, const struct firmware *fw)
|
||||||
{
|
{
|
||||||
struct device *dev = &rproc->dev;
|
struct device *dev = &rproc->dev;
|
||||||
struct elf32_hdr *ehdr;
|
struct elf32_hdr *ehdr;
|
||||||
|
@ -208,7 +209,7 @@ rproc_load_segments(struct rproc *rproc, const struct firmware *fw)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* rproc_find_rsc_table() - find the resource table
|
* rproc_elf_find_rsc_table() - find the resource table
|
||||||
* @rproc: the rproc handle
|
* @rproc: the rproc handle
|
||||||
* @fw: the ELF firmware image
|
* @fw: the ELF firmware image
|
||||||
* @tablesz: place holder for providing back the table size
|
* @tablesz: place holder for providing back the table size
|
||||||
|
@ -222,8 +223,8 @@ rproc_load_segments(struct rproc *rproc, const struct firmware *fw)
|
||||||
* size into @tablesz. If a valid table isn't found, NULL is returned
|
* size into @tablesz. If a valid table isn't found, NULL is returned
|
||||||
* (and @tablesz isn't set).
|
* (and @tablesz isn't set).
|
||||||
*/
|
*/
|
||||||
struct resource_table *
|
static struct resource_table *
|
||||||
rproc_find_rsc_table(struct rproc *rproc, const struct firmware *fw,
|
rproc_elf_find_rsc_table(struct rproc *rproc, const struct firmware *fw,
|
||||||
int *tablesz)
|
int *tablesz)
|
||||||
{
|
{
|
||||||
struct elf32_hdr *ehdr;
|
struct elf32_hdr *ehdr;
|
||||||
|
@ -285,3 +286,10 @@ rproc_find_rsc_table(struct rproc *rproc, const struct firmware *fw,
|
||||||
|
|
||||||
return table;
|
return table;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const struct rproc_fw_ops rproc_elf_fw_ops = {
|
||||||
|
.load = rproc_elf_load_segments,
|
||||||
|
.find_rsc_table = rproc_elf_find_rsc_table,
|
||||||
|
.sanity_check = rproc_elf_sanity_check,
|
||||||
|
.get_boot_addr = rproc_elf_get_boot_addr
|
||||||
|
};
|
||||||
|
|
|
@ -25,6 +25,23 @@
|
||||||
|
|
||||||
struct rproc;
|
struct rproc;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* struct rproc_fw_ops - firmware format specific operations.
|
||||||
|
* @find_rsc_table: finds the resource table inside the firmware image
|
||||||
|
* @load: load firmeware to memory, where the remote processor
|
||||||
|
* expects to find it
|
||||||
|
* @sanity_check: sanity check the fw image
|
||||||
|
* @get_boot_addr: get boot address to entry point specified in firmware
|
||||||
|
*/
|
||||||
|
struct rproc_fw_ops {
|
||||||
|
struct resource_table *(*find_rsc_table) (struct rproc *rproc,
|
||||||
|
const struct firmware *fw,
|
||||||
|
int *tablesz);
|
||||||
|
int (*load)(struct rproc *rproc, const struct firmware *fw);
|
||||||
|
int (*sanity_check)(struct rproc *rproc, const struct firmware *fw);
|
||||||
|
u32 (*get_boot_addr)(struct rproc *rproc, const struct firmware *fw);
|
||||||
|
};
|
||||||
|
|
||||||
/* from remoteproc_core.c */
|
/* from remoteproc_core.c */
|
||||||
void rproc_release(struct kref *kref);
|
void rproc_release(struct kref *kref);
|
||||||
irqreturn_t rproc_vq_interrupt(struct rproc *rproc, int vq_id);
|
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);
|
||||||
|
|
||||||
void *rproc_da_to_va(struct rproc *rproc, u64 da, int len);
|
void *rproc_da_to_va(struct rproc *rproc, u64 da, int len);
|
||||||
|
|
||||||
|
static inline
|
||||||
|
int rproc_fw_sanity_check(struct rproc *rproc, const struct firmware *fw)
|
||||||
|
{
|
||||||
|
if (rproc->fw_ops->sanity_check)
|
||||||
|
return rproc->fw_ops->sanity_check(rproc, fw);
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
static inline
|
||||||
|
u32 rproc_get_boot_addr(struct rproc *rproc, const struct firmware *fw)
|
||||||
|
{
|
||||||
|
if (rproc->fw_ops->get_boot_addr)
|
||||||
|
return rproc->fw_ops->get_boot_addr(rproc, fw);
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
static inline
|
||||||
|
int rproc_load_segments(struct rproc *rproc, const struct firmware *fw)
|
||||||
|
{
|
||||||
|
if (rproc->fw_ops->load)
|
||||||
|
return rproc->fw_ops->load(rproc, fw);
|
||||||
|
|
||||||
|
return -EINVAL;
|
||||||
|
}
|
||||||
|
|
||||||
|
static inline
|
||||||
struct resource_table *rproc_find_rsc_table(struct rproc *rproc,
|
struct resource_table *rproc_find_rsc_table(struct rproc *rproc,
|
||||||
const struct firmware *fw,
|
const struct firmware *fw, int *tablesz)
|
||||||
int *tablesz);
|
{
|
||||||
int rproc_load_segments(struct rproc *rproc, const struct firmware *fw);
|
if (rproc->fw_ops->find_rsc_table)
|
||||||
int rproc_fw_sanity_check(struct rproc *rproc, const struct firmware *fw);
|
return rproc->fw_ops->find_rsc_table(rproc, fw, tablesz);
|
||||||
u32 rproc_get_boot_addr(struct rproc *rproc, const struct firmware *fw);
|
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
extern const struct rproc_fw_ops rproc_elf_fw_ops;
|
||||||
|
|
||||||
#endif /* REMOTEPROC_INTERNAL_H */
|
#endif /* REMOTEPROC_INTERNAL_H */
|
||||||
|
|
|
@ -369,6 +369,7 @@ enum rproc_state {
|
||||||
* @priv: private data which belongs to the platform-specific rproc module
|
* @priv: private data which belongs to the platform-specific rproc module
|
||||||
* @ops: platform-specific start/stop rproc handlers
|
* @ops: platform-specific start/stop rproc handlers
|
||||||
* @dev: virtual device for refcounting and common remoteproc behavior
|
* @dev: virtual device for refcounting and common remoteproc behavior
|
||||||
|
* @fw_ops: firmware-specific handlers
|
||||||
* @power: refcount of users who need this rproc powered up
|
* @power: refcount of users who need this rproc powered up
|
||||||
* @state: state of the device
|
* @state: state of the device
|
||||||
* @lock: lock which protects concurrent manipulations of the rproc
|
* @lock: lock which protects concurrent manipulations of the rproc
|
||||||
|
@ -391,6 +392,7 @@ struct rproc {
|
||||||
void *priv;
|
void *priv;
|
||||||
const struct rproc_ops *ops;
|
const struct rproc_ops *ops;
|
||||||
struct device dev;
|
struct device dev;
|
||||||
|
const struct rproc_fw_ops *fw_ops;
|
||||||
atomic_t power;
|
atomic_t power;
|
||||||
unsigned int state;
|
unsigned int state;
|
||||||
struct mutex lock;
|
struct mutex lock;
|
||||||
|
|
Loading…
Reference in New Issue