Commit ba7290e0 authored by Sjur Brændeland's avatar Sjur Brændeland Committed by Ohad Ben-Cohen

remoteproc: calculate max_notifyid by counting vrings

Simplify handling of max_notifyid by simply counting the
number of vrings.
Signed-off-by: default avatarSjur Brændeland <sjur.brandeland@stericsson.com>
Acked-by: default avatarIdo Yariv <ido@wizery.com>
[small terminology changes]
Signed-off-by: default avatarOhad Ben-Cohen <ohad@wizery.com>
parent 232fcdbb
...@@ -224,9 +224,6 @@ int rproc_alloc_vring(struct rproc_vdev *rvdev, int i) ...@@ -224,9 +224,6 @@ int rproc_alloc_vring(struct rproc_vdev *rvdev, int i)
} }
notifyid = ret; notifyid = ret;
/* Store largest notifyid */
rproc->max_notifyid = max(rproc->max_notifyid, notifyid);
dev_dbg(dev, "vring%d: va %p dma %llx size %x idr %d\n", i, va, dev_dbg(dev, "vring%d: va %p dma %llx size %x idr %d\n", i, va,
(unsigned long long)dma, size, notifyid); (unsigned long long)dma, size, notifyid);
...@@ -268,25 +265,13 @@ rproc_parse_vring(struct rproc_vdev *rvdev, struct fw_rsc_vdev *rsc, int i) ...@@ -268,25 +265,13 @@ rproc_parse_vring(struct rproc_vdev *rvdev, struct fw_rsc_vdev *rsc, int i)
return 0; return 0;
} }
static int rproc_max_notifyid(int id, void *p, void *data)
{
int *maxid = data;
*maxid = max(*maxid, id);
return 0;
}
void rproc_free_vring(struct rproc_vring *rvring) void rproc_free_vring(struct rproc_vring *rvring)
{ {
int size = PAGE_ALIGN(vring_size(rvring->len, rvring->align)); int size = PAGE_ALIGN(vring_size(rvring->len, rvring->align));
struct rproc *rproc = rvring->rvdev->rproc; struct rproc *rproc = rvring->rvdev->rproc;
int maxid = 0;
dma_free_coherent(rproc->dev.parent, size, rvring->va, rvring->dma); dma_free_coherent(rproc->dev.parent, size, rvring->va, rvring->dma);
idr_remove(&rproc->notifyids, rvring->notifyid); idr_remove(&rproc->notifyids, rvring->notifyid);
/* Find the largest remaining notifyid */
idr_for_each(&rproc->notifyids, rproc_max_notifyid, &maxid);
rproc->max_notifyid = maxid;
} }
/** /**
...@@ -669,6 +654,15 @@ static int rproc_handle_carveout(struct rproc *rproc, ...@@ -669,6 +654,15 @@ static int rproc_handle_carveout(struct rproc *rproc,
return ret; return ret;
} }
static int rproc_count_vrings(struct rproc *rproc, struct fw_rsc_vdev *rsc,
int avail)
{
/* Summarize the number of notification IDs */
rproc->max_notifyid += rsc->num_of_vrings;
return 0;
}
/* /*
* A lookup table for resource handlers. The indices are defined in * A lookup table for resource handlers. The indices are defined in
* enum fw_resource_type. * enum fw_resource_type.
...@@ -684,6 +678,10 @@ static rproc_handle_resource_t rproc_vdev_handler[RSC_LAST] = { ...@@ -684,6 +678,10 @@ static rproc_handle_resource_t rproc_vdev_handler[RSC_LAST] = {
[RSC_VDEV] = (rproc_handle_resource_t)rproc_handle_vdev, [RSC_VDEV] = (rproc_handle_resource_t)rproc_handle_vdev,
}; };
static rproc_handle_resource_t rproc_count_vrings_handler[RSC_LAST] = {
[RSC_VDEV] = (rproc_handle_resource_t)rproc_count_vrings,
};
/* 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, static int rproc_handle_resources(struct rproc *rproc,
struct resource_table *table, int len, struct resource_table *table, int len,
...@@ -858,6 +856,11 @@ static void rproc_fw_config_virtio(const struct firmware *fw, void *context) ...@@ -858,6 +856,11 @@ static void rproc_fw_config_virtio(const struct firmware *fw, void *context)
if (!table) if (!table)
goto out; goto out;
/* count the number of notify-ids */
rproc->max_notifyid = -1;
ret = rproc_handle_resources(rproc, table, tablesz,
rproc_count_vrings_handler);
/* look for virtio devices and register them */ /* look for virtio devices and register them */
ret = rproc_handle_resources(rproc, table, tablesz, rproc_vdev_handler); ret = rproc_handle_resources(rproc, table, tablesz, rproc_vdev_handler);
if (ret) if (ret)
......
...@@ -213,7 +213,7 @@ static int sproc_start(struct rproc *rproc) ...@@ -213,7 +213,7 @@ static int sproc_start(struct rproc *rproc)
} }
/* Subscribe to notifications */ /* Subscribe to notifications */
for (i = 0; i < rproc->max_notifyid; i++) { for (i = 0; i <= rproc->max_notifyid; i++) {
err = sproc->mdev->ops.kick_subscribe(sproc->mdev, i); err = sproc->mdev->ops.kick_subscribe(sproc->mdev, i);
if (err) { if (err) {
sproc_err(sproc, sproc_err(sproc,
......
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