Commit 2deb41b2 authored by Linus Torvalds's avatar Linus Torvalds

Merge tag 'rproc-v4.16' of git://github.com/andersson/remoteproc

Pull remoteproc updates from Bjorn Andersson:
 "This contains a few bug fixes and a cleanup up of the resource-table
  handling in the framework, which removes the need for drivers with no
  resource table to provide a fake one"

* tag 'rproc-v4.16' of git://github.com/andersson/remoteproc:
  remoteproc: Reset table_ptr on stop
  remoteproc: Drop dangling find_rsc_table dummies
  remoteproc: Move resource table load logic to find
  remoteproc: Don't handle empty resource table
  remoteproc: Merge rproc_ops and rproc_fw_ops
  remoteproc: Clone rproc_ops in rproc_alloc()
  remoteproc: Cache resource table size
  remoteproc: Remove depricated crash completion
  virtio_remoteproc: correct put_device virtio_device.dev
parents 67fb3b92 0a8b81cb
...@@ -85,11 +85,6 @@ static int adsp_load(struct rproc *rproc, const struct firmware *fw) ...@@ -85,11 +85,6 @@ static int adsp_load(struct rproc *rproc, const struct firmware *fw)
adsp->mem_region, adsp->mem_phys, adsp->mem_size); adsp->mem_region, adsp->mem_phys, adsp->mem_size);
} }
static const struct rproc_fw_ops adsp_fw_ops = {
.find_rsc_table = qcom_mdt_find_rsc_table,
.load = adsp_load,
};
static int adsp_start(struct rproc *rproc) static int adsp_start(struct rproc *rproc)
{ {
struct qcom_adsp *adsp = (struct qcom_adsp *)rproc->priv; struct qcom_adsp *adsp = (struct qcom_adsp *)rproc->priv;
...@@ -182,6 +177,7 @@ static const struct rproc_ops adsp_ops = { ...@@ -182,6 +177,7 @@ static const struct rproc_ops adsp_ops = {
.start = adsp_start, .start = adsp_start,
.stop = adsp_stop, .stop = adsp_stop,
.da_to_va = adsp_da_to_va, .da_to_va = adsp_da_to_va,
.load = adsp_load,
}; };
static irqreturn_t adsp_wdog_interrupt(int irq, void *dev) static irqreturn_t adsp_wdog_interrupt(int irq, void *dev)
...@@ -344,8 +340,6 @@ static int adsp_probe(struct platform_device *pdev) ...@@ -344,8 +340,6 @@ static int adsp_probe(struct platform_device *pdev)
return -ENOMEM; return -ENOMEM;
} }
rproc->fw_ops = &adsp_fw_ops;
adsp = (struct qcom_adsp *)rproc->priv; adsp = (struct qcom_adsp *)rproc->priv;
adsp->dev = &pdev->dev; adsp->dev = &pdev->dev;
adsp->rproc = rproc; adsp->rproc = rproc;
......
...@@ -32,25 +32,6 @@ ...@@ -32,25 +32,6 @@
static BLOCKING_NOTIFIER_HEAD(ssr_notifiers); static BLOCKING_NOTIFIER_HEAD(ssr_notifiers);
/**
* qcom_mdt_find_rsc_table() - provide dummy resource table for remoteproc
* @rproc: remoteproc handle
* @fw: firmware header
* @tablesz: outgoing size of the table
*
* Returns a dummy table.
*/
struct resource_table *qcom_mdt_find_rsc_table(struct rproc *rproc,
const struct firmware *fw,
int *tablesz)
{
static struct resource_table table = { .ver = 1, };
*tablesz = sizeof(table);
return &table;
}
EXPORT_SYMBOL_GPL(qcom_mdt_find_rsc_table);
static int glink_subdev_probe(struct rproc_subdev *subdev) static int glink_subdev_probe(struct rproc_subdev *subdev)
{ {
struct qcom_rproc_glink *glink = to_glink_subdev(subdev); struct qcom_rproc_glink *glink = to_glink_subdev(subdev);
......
...@@ -27,10 +27,6 @@ struct qcom_rproc_ssr { ...@@ -27,10 +27,6 @@ struct qcom_rproc_ssr {
const char *name; const char *name;
}; };
struct resource_table *qcom_mdt_find_rsc_table(struct rproc *rproc,
const struct firmware *fw,
int *tablesz);
void qcom_add_glink_subdev(struct rproc *rproc, struct qcom_rproc_glink *glink); void qcom_add_glink_subdev(struct rproc *rproc, struct qcom_rproc_glink *glink);
void qcom_remove_glink_subdev(struct rproc *rproc, struct qcom_rproc_glink *glink); void qcom_remove_glink_subdev(struct rproc *rproc, struct qcom_rproc_glink *glink);
......
...@@ -303,16 +303,6 @@ static void q6v5_clk_disable(struct device *dev, ...@@ -303,16 +303,6 @@ static void q6v5_clk_disable(struct device *dev,
clk_disable_unprepare(clks[i]); clk_disable_unprepare(clks[i]);
} }
static struct resource_table *q6v5_find_rsc_table(struct rproc *rproc,
const struct firmware *fw,
int *tablesz)
{
static struct resource_table table = { .ver = 1, };
*tablesz = sizeof(table);
return &table;
}
static int q6v5_xfer_mem_ownership(struct q6v5 *qproc, int *current_perm, static int q6v5_xfer_mem_ownership(struct q6v5 *qproc, int *current_perm,
bool remote_owner, phys_addr_t addr, bool remote_owner, phys_addr_t addr,
size_t size) size_t size)
...@@ -342,11 +332,6 @@ static int q6v5_load(struct rproc *rproc, const struct firmware *fw) ...@@ -342,11 +332,6 @@ static int q6v5_load(struct rproc *rproc, const struct firmware *fw)
return 0; return 0;
} }
static const struct rproc_fw_ops q6v5_fw_ops = {
.find_rsc_table = q6v5_find_rsc_table,
.load = q6v5_load,
};
static int q6v5_rmb_pbl_wait(struct q6v5 *qproc, int ms) static int q6v5_rmb_pbl_wait(struct q6v5 *qproc, int ms)
{ {
unsigned long timeout; unsigned long timeout;
...@@ -931,6 +916,7 @@ static const struct rproc_ops q6v5_ops = { ...@@ -931,6 +916,7 @@ static const struct rproc_ops q6v5_ops = {
.start = q6v5_start, .start = q6v5_start,
.stop = q6v5_stop, .stop = q6v5_stop,
.da_to_va = q6v5_da_to_va, .da_to_va = q6v5_da_to_va,
.load = q6v5_load,
}; };
static irqreturn_t q6v5_wdog_interrupt(int irq, void *dev) static irqreturn_t q6v5_wdog_interrupt(int irq, void *dev)
...@@ -1150,8 +1136,6 @@ static int q6v5_probe(struct platform_device *pdev) ...@@ -1150,8 +1136,6 @@ static int q6v5_probe(struct platform_device *pdev)
return -ENOMEM; return -ENOMEM;
} }
rproc->fw_ops = &q6v5_fw_ops;
qproc = (struct q6v5 *)rproc->priv; qproc = (struct q6v5 *)rproc->priv;
qproc->dev = &pdev->dev; qproc->dev = &pdev->dev;
qproc->rproc = rproc; qproc->rproc = rproc;
......
...@@ -156,11 +156,6 @@ static int wcnss_load(struct rproc *rproc, const struct firmware *fw) ...@@ -156,11 +156,6 @@ static int wcnss_load(struct rproc *rproc, const struct firmware *fw)
wcnss->mem_region, wcnss->mem_phys, wcnss->mem_size); wcnss->mem_region, wcnss->mem_phys, wcnss->mem_size);
} }
static const struct rproc_fw_ops wcnss_fw_ops = {
.find_rsc_table = qcom_mdt_find_rsc_table,
.load = wcnss_load,
};
static void wcnss_indicate_nv_download(struct qcom_wcnss *wcnss) static void wcnss_indicate_nv_download(struct qcom_wcnss *wcnss)
{ {
u32 val; u32 val;
...@@ -313,6 +308,7 @@ static const struct rproc_ops wcnss_ops = { ...@@ -313,6 +308,7 @@ static const struct rproc_ops wcnss_ops = {
.start = wcnss_start, .start = wcnss_start,
.stop = wcnss_stop, .stop = wcnss_stop,
.da_to_va = wcnss_da_to_va, .da_to_va = wcnss_da_to_va,
.load = wcnss_load,
}; };
static irqreturn_t wcnss_wdog_interrupt(int irq, void *dev) static irqreturn_t wcnss_wdog_interrupt(int irq, void *dev)
...@@ -492,8 +488,6 @@ static int wcnss_probe(struct platform_device *pdev) ...@@ -492,8 +488,6 @@ static int wcnss_probe(struct platform_device *pdev)
return -ENOMEM; return -ENOMEM;
} }
rproc->fw_ops = &wcnss_fw_ops;
wcnss = (struct qcom_wcnss *)rproc->priv; wcnss = (struct qcom_wcnss *)rproc->priv;
wcnss->dev = &pdev->dev; wcnss->dev = &pdev->dev;
wcnss->rproc = rproc; wcnss->rproc = rproc;
......
...@@ -732,17 +732,20 @@ static rproc_handle_resource_t rproc_loading_handlers[RSC_LAST] = { ...@@ -732,17 +732,20 @@ static rproc_handle_resource_t rproc_loading_handlers[RSC_LAST] = {
}; };
/* handle firmware resource entries before booting the remote processor */ /* handle firmware resource entries before booting the remote processor */
static int rproc_handle_resources(struct rproc *rproc, int len, static int rproc_handle_resources(struct rproc *rproc,
rproc_handle_resource_t handlers[RSC_LAST]) rproc_handle_resource_t handlers[RSC_LAST])
{ {
struct device *dev = &rproc->dev; struct device *dev = &rproc->dev;
rproc_handle_resource_t handler; rproc_handle_resource_t handler;
int ret = 0, i; int ret = 0, i;
if (!rproc->table_ptr)
return 0;
for (i = 0; i < rproc->table_ptr->num; i++) { for (i = 0; i < rproc->table_ptr->num; i++) {
int offset = rproc->table_ptr->offset[i]; int offset = rproc->table_ptr->offset[i];
struct fw_rsc_hdr *hdr = (void *)rproc->table_ptr + offset; struct fw_rsc_hdr *hdr = (void *)rproc->table_ptr + offset;
int avail = len - offset - sizeof(*hdr); int avail = rproc->table_sz - offset - sizeof(*hdr);
void *rsc = (void *)hdr + sizeof(*hdr); void *rsc = (void *)hdr + sizeof(*hdr);
/* make sure table isn't truncated */ /* make sure table isn't truncated */
...@@ -849,16 +852,9 @@ static void rproc_resource_cleanup(struct rproc *rproc) ...@@ -849,16 +852,9 @@ static void rproc_resource_cleanup(struct rproc *rproc)
static int rproc_start(struct rproc *rproc, const struct firmware *fw) static int rproc_start(struct rproc *rproc, const struct firmware *fw)
{ {
struct resource_table *table, *loaded_table; struct resource_table *loaded_table;
struct device *dev = &rproc->dev; struct device *dev = &rproc->dev;
int ret, tablesz; int ret;
/* look for the resource table */
table = rproc_find_rsc_table(rproc, fw, &tablesz);
if (!table) {
dev_err(dev, "Resource table look up failed\n");
return -EINVAL;
}
/* load the ELF segments to memory */ /* load the ELF segments to memory */
ret = rproc_load_segments(rproc, fw); ret = rproc_load_segments(rproc, fw);
...@@ -877,7 +873,7 @@ static int rproc_start(struct rproc *rproc, const struct firmware *fw) ...@@ -877,7 +873,7 @@ static int rproc_start(struct rproc *rproc, const struct firmware *fw)
*/ */
loaded_table = rproc_find_loaded_rsc_table(rproc, fw); loaded_table = rproc_find_loaded_rsc_table(rproc, fw);
if (loaded_table) { if (loaded_table) {
memcpy(loaded_table, rproc->cached_table, tablesz); memcpy(loaded_table, rproc->cached_table, rproc->table_sz);
rproc->table_ptr = loaded_table; rproc->table_ptr = loaded_table;
} }
...@@ -911,8 +907,7 @@ static int rproc_fw_boot(struct rproc *rproc, const struct firmware *fw) ...@@ -911,8 +907,7 @@ static int rproc_fw_boot(struct rproc *rproc, const struct firmware *fw)
{ {
struct device *dev = &rproc->dev; struct device *dev = &rproc->dev;
const char *name = rproc->firmware; const char *name = rproc->firmware;
struct resource_table *table; int ret;
int ret, tablesz;
ret = rproc_fw_sanity_check(rproc, fw); ret = rproc_fw_sanity_check(rproc, fw);
if (ret) if (ret)
...@@ -931,32 +926,17 @@ static int rproc_fw_boot(struct rproc *rproc, const struct firmware *fw) ...@@ -931,32 +926,17 @@ static int rproc_fw_boot(struct rproc *rproc, const struct firmware *fw)
} }
rproc->bootaddr = rproc_get_boot_addr(rproc, fw); rproc->bootaddr = rproc_get_boot_addr(rproc, fw);
ret = -EINVAL;
/* look for the resource table */ /* load resource table */
table = rproc_find_rsc_table(rproc, fw, &tablesz); ret = rproc_load_rsc_table(rproc, fw);
if (!table) { if (ret)
dev_err(dev, "Failed to find resource table\n"); goto disable_iommu;
goto clean_up;
}
/*
* Create a copy of the resource table. When a virtio device starts
* and calls vring_new_virtqueue() the address of the allocated vring
* will be stored in the cached_table. Before the device is started,
* cached_table will be copied into device memory.
*/
rproc->cached_table = kmemdup(table, tablesz, GFP_KERNEL);
if (!rproc->cached_table)
goto clean_up;
rproc->table_ptr = rproc->cached_table;
/* reset max_notifyid */ /* reset max_notifyid */
rproc->max_notifyid = -1; rproc->max_notifyid = -1;
/* handle fw resources which are required to boot rproc */ /* handle fw resources which are required to boot rproc */
ret = rproc_handle_resources(rproc, tablesz, rproc_loading_handlers); ret = rproc_handle_resources(rproc, rproc_loading_handlers);
if (ret) { if (ret) {
dev_err(dev, "Failed to process resources: %d\n", ret); dev_err(dev, "Failed to process resources: %d\n", ret);
goto clean_up_resources; goto clean_up_resources;
...@@ -970,11 +950,10 @@ static int rproc_fw_boot(struct rproc *rproc, const struct firmware *fw) ...@@ -970,11 +950,10 @@ static int rproc_fw_boot(struct rproc *rproc, const struct firmware *fw)
clean_up_resources: clean_up_resources:
rproc_resource_cleanup(rproc); rproc_resource_cleanup(rproc);
clean_up:
kfree(rproc->cached_table); kfree(rproc->cached_table);
rproc->cached_table = NULL; rproc->cached_table = NULL;
rproc->table_ptr = NULL; rproc->table_ptr = NULL;
disable_iommu:
rproc_disable_iommu(rproc); rproc_disable_iommu(rproc);
return ret; return ret;
} }
...@@ -1021,6 +1000,9 @@ static int rproc_stop(struct rproc *rproc) ...@@ -1021,6 +1000,9 @@ static int rproc_stop(struct rproc *rproc)
/* remove any subdevices for the remote processor */ /* remove any subdevices for the remote processor */
rproc_remove_subdevices(rproc); rproc_remove_subdevices(rproc);
/* the installed resource table is no longer accessible */
rproc->table_ptr = rproc->cached_table;
/* power off the remote processor */ /* power off the remote processor */
ret = rproc->ops->stop(rproc); ret = rproc->ops->stop(rproc);
if (ret) { if (ret) {
...@@ -1028,10 +1010,6 @@ static int rproc_stop(struct rproc *rproc) ...@@ -1028,10 +1010,6 @@ static int rproc_stop(struct rproc *rproc)
return ret; return ret;
} }
/* if in crash state, unlock crash handler */
if (rproc->state == RPROC_CRASHED)
complete_all(&rproc->crash_comp);
rproc->state = RPROC_OFFLINE; rproc->state = RPROC_OFFLINE;
dev_info(dev, "stopped remote processor %s\n", rproc->name); dev_info(dev, "stopped remote processor %s\n", rproc->name);
...@@ -1057,8 +1035,6 @@ int rproc_trigger_recovery(struct rproc *rproc) ...@@ -1057,8 +1035,6 @@ int rproc_trigger_recovery(struct rproc *rproc)
dev_err(dev, "recovering %s\n", rproc->name); dev_err(dev, "recovering %s\n", rproc->name);
init_completion(&rproc->crash_comp);
ret = mutex_lock_interruptible(&rproc->lock); ret = mutex_lock_interruptible(&rproc->lock);
if (ret) if (ret)
return ret; return ret;
...@@ -1067,9 +1043,6 @@ int rproc_trigger_recovery(struct rproc *rproc) ...@@ -1067,9 +1043,6 @@ int rproc_trigger_recovery(struct rproc *rproc)
if (ret) if (ret)
goto unlock_mutex; goto unlock_mutex;
/* wait until there is no more rproc users */
wait_for_completion(&rproc->crash_comp);
/* load firmware */ /* load firmware */
ret = request_firmware(&firmware_p, rproc->firmware, dev); ret = request_firmware(&firmware_p, rproc->firmware, dev);
if (ret < 0) { if (ret < 0) {
...@@ -1357,6 +1330,7 @@ static void rproc_type_release(struct device *dev) ...@@ -1357,6 +1330,7 @@ static void rproc_type_release(struct device *dev)
ida_simple_remove(&rproc_dev_index, rproc->index); ida_simple_remove(&rproc_dev_index, rproc->index);
kfree(rproc->firmware); kfree(rproc->firmware);
kfree(rproc->ops);
kfree(rproc); kfree(rproc);
} }
...@@ -1421,9 +1395,15 @@ struct rproc *rproc_alloc(struct device *dev, const char *name, ...@@ -1421,9 +1395,15 @@ struct rproc *rproc_alloc(struct device *dev, const char *name,
return NULL; return NULL;
} }
rproc->ops = kmemdup(ops, sizeof(*ops), GFP_KERNEL);
if (!rproc->ops) {
kfree(p);
kfree(rproc);
return NULL;
}
rproc->firmware = p; rproc->firmware = p;
rproc->name = name; rproc->name = name;
rproc->ops = ops;
rproc->priv = &rproc[1]; rproc->priv = &rproc[1];
rproc->auto_boot = true; rproc->auto_boot = true;
...@@ -1445,8 +1425,14 @@ struct rproc *rproc_alloc(struct device *dev, const char *name, ...@@ -1445,8 +1425,14 @@ 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 */ /* Default to ELF loader if no load function is specified */
rproc->fw_ops = &rproc_elf_fw_ops; if (!rproc->ops->load) {
rproc->ops->load = rproc_elf_load_segments;
rproc->ops->load_rsc_table = rproc_elf_load_rsc_table;
rproc->ops->find_loaded_rsc_table = rproc_elf_find_loaded_rsc_table;
rproc->ops->sanity_check = rproc_elf_sanity_check;
rproc->ops->get_boot_addr = rproc_elf_get_boot_addr;
}
mutex_init(&rproc->lock); mutex_init(&rproc->lock);
...@@ -1459,7 +1445,6 @@ struct rproc *rproc_alloc(struct device *dev, const char *name, ...@@ -1459,7 +1445,6 @@ struct rproc *rproc_alloc(struct device *dev, const char *name,
INIT_LIST_HEAD(&rproc->subdevs); INIT_LIST_HEAD(&rproc->subdevs);
INIT_WORK(&rproc->crash_handler, rproc_crash_handler_work); INIT_WORK(&rproc->crash_handler, rproc_crash_handler_work);
init_completion(&rproc->crash_comp);
rproc->state = RPROC_OFFLINE; rproc->state = RPROC_OFFLINE;
......
...@@ -39,8 +39,7 @@ ...@@ -39,8 +39,7 @@
* *
* Make sure this fw image is sane. * Make sure this fw image is sane.
*/ */
static int int rproc_elf_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;
...@@ -98,6 +97,7 @@ rproc_elf_sanity_check(struct rproc *rproc, const struct firmware *fw) ...@@ -98,6 +97,7 @@ rproc_elf_sanity_check(struct rproc *rproc, const struct firmware *fw)
return 0; return 0;
} }
EXPORT_SYMBOL(rproc_elf_sanity_check);
/** /**
* rproc_elf_get_boot_addr() - Get rproc's boot address. * rproc_elf_get_boot_addr() - Get rproc's boot address.
...@@ -110,13 +110,13 @@ rproc_elf_sanity_check(struct rproc *rproc, const struct firmware *fw) ...@@ -110,13 +110,13 @@ rproc_elf_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.
*/ */
static
u32 rproc_elf_get_boot_addr(struct rproc *rproc, const struct firmware *fw) 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;
return ehdr->e_entry; return ehdr->e_entry;
} }
EXPORT_SYMBOL(rproc_elf_get_boot_addr);
/** /**
* rproc_elf_load_segments() - load firmware segments to memory * rproc_elf_load_segments() - load firmware segments to memory
...@@ -142,8 +142,7 @@ u32 rproc_elf_get_boot_addr(struct rproc *rproc, const struct firmware *fw) ...@@ -142,8 +142,7 @@ u32 rproc_elf_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.
*/ */
static int int rproc_elf_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;
...@@ -207,6 +206,7 @@ rproc_elf_load_segments(struct rproc *rproc, const struct firmware *fw) ...@@ -207,6 +206,7 @@ rproc_elf_load_segments(struct rproc *rproc, const struct firmware *fw)
return ret; return ret;
} }
EXPORT_SYMBOL(rproc_elf_load_segments);
static struct elf32_shdr * static struct elf32_shdr *
find_table(struct device *dev, struct elf32_hdr *ehdr, size_t fw_size) find_table(struct device *dev, struct elf32_hdr *ehdr, size_t fw_size)
...@@ -268,41 +268,49 @@ find_table(struct device *dev, struct elf32_hdr *ehdr, size_t fw_size) ...@@ -268,41 +268,49 @@ find_table(struct device *dev, struct elf32_hdr *ehdr, size_t fw_size)
} }
/** /**
* rproc_elf_find_rsc_table() - find the resource table * rproc_elf_load_rsc_table() - load 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
* *
* This function finds the resource table inside the remote processor's * This function finds the resource table inside the remote processor's
* firmware. It is used both upon the registration of @rproc (in order * firmware, load it into the @cached_table and update @table_ptr.
* to look for and register the supported virito devices), and when the
* @rproc is booted.
* *
* Returns the pointer to the resource table if it is found, and write its * Return: 0 on success, negative errno on failure.
* size into @tablesz. If a valid table isn't found, NULL is returned
* (and @tablesz isn't set).
*/ */
static struct resource_table * int rproc_elf_load_rsc_table(struct rproc *rproc, const struct firmware *fw)
rproc_elf_find_rsc_table(struct rproc *rproc, const struct firmware *fw,
int *tablesz)
{ {
struct elf32_hdr *ehdr; struct elf32_hdr *ehdr;
struct elf32_shdr *shdr; struct elf32_shdr *shdr;
struct device *dev = &rproc->dev; struct device *dev = &rproc->dev;
struct resource_table *table = NULL; struct resource_table *table = NULL;
const u8 *elf_data = fw->data; const u8 *elf_data = fw->data;
size_t tablesz;
ehdr = (struct elf32_hdr *)elf_data; ehdr = (struct elf32_hdr *)elf_data;
shdr = find_table(dev, ehdr, fw->size); shdr = find_table(dev, ehdr, fw->size);
if (!shdr) if (!shdr)
return NULL; return -EINVAL;
table = (struct resource_table *)(elf_data + shdr->sh_offset); table = (struct resource_table *)(elf_data + shdr->sh_offset);
*tablesz = shdr->sh_size; tablesz = shdr->sh_size;
/*
* Create a copy of the resource table. When a virtio device starts
* and calls vring_new_virtqueue() the address of the allocated vring
* will be stored in the cached_table. Before the device is started,
* cached_table will be copied into device memory.
*/
rproc->cached_table = kmemdup(table, tablesz, GFP_KERNEL);
if (!rproc->cached_table)
return -ENOMEM;
return table; rproc->table_ptr = rproc->cached_table;
rproc->table_sz = tablesz;
return 0;
} }
EXPORT_SYMBOL(rproc_elf_load_rsc_table);
/** /**
* rproc_elf_find_loaded_rsc_table() - find the loaded resource table * rproc_elf_find_loaded_rsc_table() - find the loaded resource table
...@@ -315,8 +323,8 @@ rproc_elf_find_rsc_table(struct rproc *rproc, const struct firmware *fw, ...@@ -315,8 +323,8 @@ rproc_elf_find_rsc_table(struct rproc *rproc, const struct firmware *fw,
* Returns the pointer to the resource table if it is found or NULL otherwise. * Returns the pointer to the resource table if it is found or NULL otherwise.
* If the table wasn't loaded yet the result is unspecified. * If the table wasn't loaded yet the result is unspecified.
*/ */
static struct resource_table * struct resource_table *rproc_elf_find_loaded_rsc_table(struct rproc *rproc,
rproc_elf_find_loaded_rsc_table(struct rproc *rproc, const struct firmware *fw) const struct firmware *fw)
{ {
struct elf32_hdr *ehdr = (struct elf32_hdr *)fw->data; struct elf32_hdr *ehdr = (struct elf32_hdr *)fw->data;
struct elf32_shdr *shdr; struct elf32_shdr *shdr;
...@@ -327,11 +335,4 @@ rproc_elf_find_loaded_rsc_table(struct rproc *rproc, const struct firmware *fw) ...@@ -327,11 +335,4 @@ rproc_elf_find_loaded_rsc_table(struct rproc *rproc, const struct firmware *fw)
return rproc_da_to_va(rproc, shdr->sh_addr, shdr->sh_size); return rproc_da_to_va(rproc, shdr->sh_addr, shdr->sh_size);
} }
EXPORT_SYMBOL(rproc_elf_find_loaded_rsc_table);
const struct rproc_fw_ops rproc_elf_fw_ops = {
.load = rproc_elf_load_segments,
.find_rsc_table = rproc_elf_find_rsc_table,
.find_loaded_rsc_table = rproc_elf_find_loaded_rsc_table,
.sanity_check = rproc_elf_sanity_check,
.get_boot_addr = rproc_elf_get_boot_addr
};
...@@ -25,26 +25,6 @@ ...@@ -25,26 +25,6 @@
struct rproc; struct rproc;
/**
* struct rproc_fw_ops - firmware format specific operations.
* @find_rsc_table: find the resource table inside the firmware image
* @find_loaded_rsc_table: find the loaded resouce table
* @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);
struct resource_table *(*find_loaded_rsc_table)(
struct rproc *rproc, const struct firmware *fw);
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);
...@@ -74,11 +54,18 @@ int rproc_alloc_vring(struct rproc_vdev *rvdev, int i); ...@@ -74,11 +54,18 @@ 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);
int rproc_trigger_recovery(struct rproc *rproc); int rproc_trigger_recovery(struct rproc *rproc);
int rproc_elf_sanity_check(struct rproc *rproc, const struct firmware *fw);
u32 rproc_elf_get_boot_addr(struct rproc *rproc, const struct firmware *fw);
int rproc_elf_load_segments(struct rproc *rproc, const struct firmware *fw);
int rproc_elf_load_rsc_table(struct rproc *rproc, const struct firmware *fw);
struct resource_table *rproc_elf_find_loaded_rsc_table(struct rproc *rproc,
const struct firmware *fw);
static inline static inline
int rproc_fw_sanity_check(struct rproc *rproc, const struct firmware *fw) int rproc_fw_sanity_check(struct rproc *rproc, const struct firmware *fw)
{ {
if (rproc->fw_ops->sanity_check) if (rproc->ops->sanity_check)
return rproc->fw_ops->sanity_check(rproc, fw); return rproc->ops->sanity_check(rproc, fw);
return 0; return 0;
} }
...@@ -86,8 +73,8 @@ int rproc_fw_sanity_check(struct rproc *rproc, const struct firmware *fw) ...@@ -86,8 +73,8 @@ int rproc_fw_sanity_check(struct rproc *rproc, const struct firmware *fw)
static inline static inline
u32 rproc_get_boot_addr(struct rproc *rproc, const struct firmware *fw) u32 rproc_get_boot_addr(struct rproc *rproc, const struct firmware *fw)
{ {
if (rproc->fw_ops->get_boot_addr) if (rproc->ops->get_boot_addr)
return rproc->fw_ops->get_boot_addr(rproc, fw); return rproc->ops->get_boot_addr(rproc, fw);
return 0; return 0;
} }
...@@ -95,33 +82,29 @@ u32 rproc_get_boot_addr(struct rproc *rproc, const struct firmware *fw) ...@@ -95,33 +82,29 @@ u32 rproc_get_boot_addr(struct rproc *rproc, const struct firmware *fw)
static inline static inline
int rproc_load_segments(struct rproc *rproc, const struct firmware *fw) int rproc_load_segments(struct rproc *rproc, const struct firmware *fw)
{ {
if (rproc->fw_ops->load) if (rproc->ops->load)
return rproc->fw_ops->load(rproc, fw); return rproc->ops->load(rproc, fw);
return -EINVAL; return -EINVAL;
} }
static inline static inline int rproc_load_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)
{ {
if (rproc->fw_ops->find_rsc_table) if (rproc->ops->load_rsc_table)
return rproc->fw_ops->find_rsc_table(rproc, fw, tablesz); return rproc->ops->load_rsc_table(rproc, fw);
return NULL; return 0;
} }
static inline static inline
struct resource_table *rproc_find_loaded_rsc_table(struct rproc *rproc, struct resource_table *rproc_find_loaded_rsc_table(struct rproc *rproc,
const struct firmware *fw) const struct firmware *fw)
{ {
if (rproc->fw_ops->find_loaded_rsc_table) if (rproc->ops->find_loaded_rsc_table)
return rproc->fw_ops->find_loaded_rsc_table(rproc, fw); return rproc->ops->find_loaded_rsc_table(rproc, fw);
return NULL; return NULL;
} }
extern const struct rproc_fw_ops rproc_elf_fw_ops;
#endif /* REMOTEPROC_INTERNAL_H */ #endif /* REMOTEPROC_INTERNAL_H */
...@@ -327,7 +327,7 @@ int rproc_add_virtio_dev(struct rproc_vdev *rvdev, int id) ...@@ -327,7 +327,7 @@ int rproc_add_virtio_dev(struct rproc_vdev *rvdev, int id)
ret = register_virtio_device(vdev); ret = register_virtio_device(vdev);
if (ret) { if (ret) {
put_device(&rproc->dev); put_device(&vdev->dev);
dev_err(dev, "failed to register vdev: %d\n", ret); dev_err(dev, "failed to register vdev: %d\n", ret);
goto out; goto out;
} }
......
...@@ -204,27 +204,9 @@ static const struct rproc_ops slim_rproc_ops = { ...@@ -204,27 +204,9 @@ static const struct rproc_ops slim_rproc_ops = {
.start = slim_rproc_start, .start = slim_rproc_start,
.stop = slim_rproc_stop, .stop = slim_rproc_stop,
.da_to_va = slim_rproc_da_to_va, .da_to_va = slim_rproc_da_to_va,
}; .get_boot_addr = rproc_elf_get_boot_addr,
.load = rproc_elf_load_segments,
/* .sanity_check = rproc_elf_sanity_check,
* Firmware handler operations: sanity, boot address, load ...
*/
static struct resource_table empty_rsc_tbl = {
.ver = 1,
.num = 0,
};
static struct resource_table *slim_rproc_find_rsc_table(struct rproc *rproc,
const struct firmware *fw,
int *tablesz)
{
*tablesz = sizeof(empty_rsc_tbl);
return &empty_rsc_tbl;
}
static struct rproc_fw_ops slim_rproc_fw_ops = {
.find_rsc_table = slim_rproc_find_rsc_table,
}; };
/** /**
...@@ -249,7 +231,6 @@ struct st_slim_rproc *st_slim_rproc_alloc(struct platform_device *pdev, ...@@ -249,7 +231,6 @@ struct st_slim_rproc *st_slim_rproc_alloc(struct platform_device *pdev,
struct rproc *rproc; struct rproc *rproc;
struct resource *res; struct resource *res;
int err, i; int err, i;
const struct rproc_fw_ops *elf_ops;
if (!fw_name) if (!fw_name)
return ERR_PTR(-EINVAL); return ERR_PTR(-EINVAL);
...@@ -267,13 +248,6 @@ struct st_slim_rproc *st_slim_rproc_alloc(struct platform_device *pdev, ...@@ -267,13 +248,6 @@ struct st_slim_rproc *st_slim_rproc_alloc(struct platform_device *pdev,
slim_rproc = rproc->priv; slim_rproc = rproc->priv;
slim_rproc->rproc = rproc; slim_rproc->rproc = rproc;
elf_ops = rproc->fw_ops;
/* Use some generic elf ops */
slim_rproc_fw_ops.load = elf_ops->load;
slim_rproc_fw_ops.sanity_check = elf_ops->sanity_check;
rproc->fw_ops = &slim_rproc_fw_ops;
/* get imem and dmem */ /* get imem and dmem */
for (i = 0; i < ARRAY_SIZE(mem_names); i++) { for (i = 0; i < ARRAY_SIZE(mem_names); i++) {
res = platform_get_resource_byname(pdev, IORESOURCE_MEM, res = platform_get_resource_byname(pdev, IORESOURCE_MEM,
......
...@@ -324,6 +324,7 @@ struct rproc_mem_entry { ...@@ -324,6 +324,7 @@ struct rproc_mem_entry {
}; };
struct rproc; struct rproc;
struct firmware;
/** /**
* struct rproc_ops - platform-specific device handlers * struct rproc_ops - platform-specific device handlers
...@@ -331,12 +332,24 @@ struct rproc; ...@@ -331,12 +332,24 @@ struct rproc;
* @stop: power off the device * @stop: power off the device
* @kick: kick a virtqueue (virtqueue id given as a parameter) * @kick: kick a virtqueue (virtqueue id given as a parameter)
* @da_to_va: optional platform hook to perform address translations * @da_to_va: optional platform hook to perform address translations
* @load_rsc_table: load resource table from firmware image
* @find_loaded_rsc_table: find the loaded resouce table
* @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_ops { struct rproc_ops {
int (*start)(struct rproc *rproc); int (*start)(struct rproc *rproc);
int (*stop)(struct rproc *rproc); int (*stop)(struct rproc *rproc);
void (*kick)(struct rproc *rproc, int vqid); void (*kick)(struct rproc *rproc, int vqid);
void * (*da_to_va)(struct rproc *rproc, u64 da, int len); void * (*da_to_va)(struct rproc *rproc, u64 da, int len);
int (*load_rsc_table)(struct rproc *rproc, const struct firmware *fw);
struct resource_table *(*find_loaded_rsc_table)(
struct rproc *rproc, const struct firmware *fw);
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);
}; };
/** /**
...@@ -390,7 +403,6 @@ enum rproc_crash_type { ...@@ -390,7 +403,6 @@ enum rproc_crash_type {
* @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
...@@ -406,11 +418,11 @@ enum rproc_crash_type { ...@@ -406,11 +418,11 @@ enum rproc_crash_type {
* @index: index of this rproc device * @index: index of this rproc device
* @crash_handler: workqueue for handling a crash * @crash_handler: workqueue for handling a crash
* @crash_cnt: crash counter * @crash_cnt: crash counter
* @crash_comp: completion used to sync crash handler and the rproc reload
* @recovery_disabled: flag that state if recovery was disabled * @recovery_disabled: flag that state if recovery was disabled
* @max_notifyid: largest allocated notify id. * @max_notifyid: largest allocated notify id.
* @table_ptr: pointer to the resource table in effect * @table_ptr: pointer to the resource table in effect
* @cached_table: copy of the resource table * @cached_table: copy of the resource table
* @table_sz: size of @cached_table
* @has_iommu: flag to indicate if remote processor is behind an MMU * @has_iommu: flag to indicate if remote processor is behind an MMU
*/ */
struct rproc { struct rproc {
...@@ -419,9 +431,8 @@ struct rproc { ...@@ -419,9 +431,8 @@ struct rproc {
const char *name; const char *name;
char *firmware; char *firmware;
void *priv; void *priv;
const struct rproc_ops *ops; 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;
...@@ -437,11 +448,11 @@ struct rproc { ...@@ -437,11 +448,11 @@ struct rproc {
int index; int index;
struct work_struct crash_handler; struct work_struct crash_handler;
unsigned int crash_cnt; unsigned int crash_cnt;
struct completion crash_comp;
bool recovery_disabled; bool recovery_disabled;
int max_notifyid; int max_notifyid;
struct resource_table *table_ptr; struct resource_table *table_ptr;
struct resource_table *cached_table; struct resource_table *cached_table;
size_t table_sz;
bool has_iommu; bool has_iommu;
bool auto_boot; bool auto_boot;
}; };
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment