summaryrefslogtreecommitdiff
path: root/drivers/remoteproc
diff options
context:
space:
mode:
authorArnaud Pouliquen <arnaud.pouliquen@foss.st.com>2022-09-21 15:50:41 +0200
committerMathieu Poirier <mathieu.poirier@linaro.org>2022-09-21 11:14:02 -0600
commitfd28f879e6274d477378362d848b42747ecb27eb (patch)
tree690f5eb4ea8ae5ba357edeebc820118c1d0fda71 /drivers/remoteproc
parent7d7f8fe4e399519cc9ac68a475fec6d3a996341b (diff)
remoteproc: core: Introduce rproc_rvdev_add_device function
In preparation of the migration of the management of rvdev in remoteproc_virtio.c, this patch spins off a new function to manage the remoteproc virtio device creation. The rproc_rvdev_add_device will be moved to remoteproc_virtio.c. The rproc_vdev_data structure is introduced to provide information for the rvdev creation. This structure allows to manage the rvdev and vrings allocation in the rproc_rvdev_add_device function. Signed-off-by: Arnaud Pouliquen <arnaud.pouliquen@foss.st.com> Link: https://lore.kernel.org/r/20220921135044.917140-2-arnaud.pouliquen@foss.st.com Signed-off-by: Mathieu Poirier <mathieu.poirier@linaro.org>
Diffstat (limited to 'drivers/remoteproc')
-rw-r--r--drivers/remoteproc/remoteproc_core.c147
-rw-r--r--drivers/remoteproc/remoteproc_internal.h15
2 files changed, 98 insertions, 64 deletions
diff --git a/drivers/remoteproc/remoteproc_core.c b/drivers/remoteproc/remoteproc_core.c
index f5ba3b305aaf..f8dd8c526299 100644
--- a/drivers/remoteproc/remoteproc_core.c
+++ b/drivers/remoteproc/remoteproc_core.c
@@ -486,75 +486,23 @@ static int copy_dma_range_map(struct device *to, struct device *from)
return 0;
}
-/**
- * rproc_handle_vdev() - handle a vdev fw resource
- * @rproc: the remote processor
- * @ptr: the vring resource descriptor
- * @offset: offset of the resource entry
- * @avail: size of available data (for sanity checking the image)
- *
- * This resource entry requests the host to statically register a virtio
- * device (vdev), and setup everything needed to support it. It contains
- * everything needed to make it possible: the virtio device id, virtio
- * device features, vrings information, virtio config space, etc...
- *
- * Before registering the vdev, the vrings are allocated from non-cacheable
- * physically contiguous memory. Currently we only support two vrings per
- * remote processor (temporary limitation). We might also want to consider
- * doing the vring allocation only later when ->find_vqs() is invoked, and
- * then release them upon ->del_vqs().
- *
- * Note: @da is currently not really handled correctly: we dynamically
- * allocate it using the DMA API, ignoring requested hard coded addresses,
- * and we don't take care of any required IOMMU programming. This is all
- * going to be taken care of when the generic iommu-based DMA API will be
- * merged. Meanwhile, statically-addressed iommu-based firmware images should
- * use RSC_DEVMEM resource entries to map their required @da to the physical
- * address of their base CMA region (ouch, hacky!).
- *
- * Return: 0 on success, or an appropriate error code otherwise
- */
-static int rproc_handle_vdev(struct rproc *rproc, void *ptr,
- int offset, int avail)
+static struct rproc_vdev *
+rproc_rvdev_add_device(struct rproc *rproc, struct rproc_vdev_data *rvdev_data)
{
- struct fw_rsc_vdev *rsc = ptr;
- struct device *dev = &rproc->dev;
struct rproc_vdev *rvdev;
- size_t rsc_size;
- int i, ret;
+ struct fw_rsc_vdev *rsc = rvdev_data->rsc;
char name[16];
-
- /* make sure resource isn't truncated */
- rsc_size = struct_size(rsc, vring, rsc->num_of_vrings);
- if (size_add(rsc_size, rsc->config_len) > avail) {
- dev_err(dev, "vdev rsc is truncated\n");
- return -EINVAL;
- }
-
- /* make sure reserved bytes are zeroes */
- if (rsc->reserved[0] || rsc->reserved[1]) {
- dev_err(dev, "vdev rsc has non zero reserved bytes\n");
- return -EINVAL;
- }
-
- dev_dbg(dev, "vdev rsc: id %d, dfeatures 0x%x, cfg len %d, %d vrings\n",
- rsc->id, rsc->dfeatures, rsc->config_len, rsc->num_of_vrings);
-
- /* we currently support only two vrings per rvdev */
- if (rsc->num_of_vrings > ARRAY_SIZE(rvdev->vring)) {
- dev_err(dev, "too many vrings: %d\n", rsc->num_of_vrings);
- return -EINVAL;
- }
+ int i, ret;
rvdev = kzalloc(sizeof(*rvdev), GFP_KERNEL);
if (!rvdev)
- return -ENOMEM;
+ return ERR_PTR(-ENOMEM);
kref_init(&rvdev->refcount);
- rvdev->id = rsc->id;
+ rvdev->id = rvdev_data->id;
rvdev->rproc = rproc;
- rvdev->index = rproc->nb_vdev++;
+ rvdev->index = rvdev_data->index;
/* Initialise vdev subdevice */
snprintf(name, sizeof(name), "vdev%dbuffer", rvdev->index);
@@ -566,7 +514,7 @@ static int rproc_handle_vdev(struct rproc *rproc, void *ptr,
ret = device_register(&rvdev->dev);
if (ret) {
put_device(&rvdev->dev);
- return ret;
+ return ERR_PTR(ret);
}
ret = copy_dma_range_map(&rvdev->dev, rproc->dev.parent);
@@ -579,7 +527,7 @@ static int rproc_handle_vdev(struct rproc *rproc, void *ptr,
ret = dma_coerce_mask_and_coherent(&rvdev->dev,
dma_get_mask(rproc->dev.parent));
if (ret) {
- dev_warn(dev,
+ dev_warn(&rvdev->dev,
"Failed to set DMA mask %llx. Trying to continue... (%pe)\n",
dma_get_mask(rproc->dev.parent), ERR_PTR(ret));
}
@@ -592,7 +540,7 @@ static int rproc_handle_vdev(struct rproc *rproc, void *ptr,
}
/* remember the resource offset*/
- rvdev->rsc_offset = offset;
+ rvdev->rsc_offset = rvdev_data->rsc_offset;
/* allocate the vring resources */
for (i = 0; i < rsc->num_of_vrings; i++) {
@@ -608,14 +556,14 @@ static int rproc_handle_vdev(struct rproc *rproc, void *ptr,
rproc_add_subdev(rproc, &rvdev->subdev);
- return 0;
+ return rvdev;
unwind_vring_allocations:
for (i--; i >= 0; i--)
rproc_free_vring(&rvdev->vring[i]);
free_rvdev:
device_unregister(&rvdev->dev);
- return ret;
+ return ERR_PTR(ret);
}
void rproc_vdev_release(struct kref *ref)
@@ -636,6 +584,77 @@ void rproc_vdev_release(struct kref *ref)
}
/**
+ * rproc_handle_vdev() - handle a vdev fw resource
+ * @rproc: the remote processor
+ * @ptr: the vring resource descriptor
+ * @offset: offset of the resource entry
+ * @avail: size of available data (for sanity checking the image)
+ *
+ * This resource entry requests the host to statically register a virtio
+ * device (vdev), and setup everything needed to support it. It contains
+ * everything needed to make it possible: the virtio device id, virtio
+ * device features, vrings information, virtio config space, etc...
+ *
+ * Before registering the vdev, the vrings are allocated from non-cacheable
+ * physically contiguous memory. Currently we only support two vrings per
+ * remote processor (temporary limitation). We might also want to consider
+ * doing the vring allocation only later when ->find_vqs() is invoked, and
+ * then release them upon ->del_vqs().
+ *
+ * Note: @da is currently not really handled correctly: we dynamically
+ * allocate it using the DMA API, ignoring requested hard coded addresses,
+ * and we don't take care of any required IOMMU programming. This is all
+ * going to be taken care of when the generic iommu-based DMA API will be
+ * merged. Meanwhile, statically-addressed iommu-based firmware images should
+ * use RSC_DEVMEM resource entries to map their required @da to the physical
+ * address of their base CMA region (ouch, hacky!).
+ *
+ * Return: 0 on success, or an appropriate error code otherwise
+ */
+static int rproc_handle_vdev(struct rproc *rproc, void *ptr,
+ int offset, int avail)
+{
+ struct fw_rsc_vdev *rsc = ptr;
+ struct device *dev = &rproc->dev;
+ struct rproc_vdev *rvdev;
+ size_t rsc_size;
+ struct rproc_vdev_data rvdev_data;
+
+ /* make sure resource isn't truncated */
+ rsc_size = struct_size(rsc, vring, rsc->num_of_vrings);
+ if (size_add(rsc_size, rsc->config_len) > avail) {
+ dev_err(dev, "vdev rsc is truncated\n");
+ return -EINVAL;
+ }
+
+ /* make sure reserved bytes are zeroes */
+ if (rsc->reserved[0] || rsc->reserved[1]) {
+ dev_err(dev, "vdev rsc has non zero reserved bytes\n");
+ return -EINVAL;
+ }
+
+ dev_dbg(dev, "vdev rsc: id %d, dfeatures 0x%x, cfg len %d, %d vrings\n",
+ rsc->id, rsc->dfeatures, rsc->config_len, rsc->num_of_vrings);
+
+ /* we currently support only two vrings per rvdev */
+ if (rsc->num_of_vrings > ARRAY_SIZE(rvdev->vring)) {
+ dev_err(dev, "too many vrings: %d\n", rsc->num_of_vrings);
+ return -EINVAL;
+ }
+
+ rvdev_data.id = rsc->id;
+ rvdev_data.index = rproc->nb_vdev++;
+ rvdev_data.rsc_offset = offset;
+ rvdev_data.rsc = rsc;
+
+ rvdev = rproc_rvdev_add_device(rproc, &rvdev_data);
+ if (IS_ERR(rvdev))
+ return PTR_ERR(rvdev);
+
+ return 0;
+}
+
+/**
* rproc_handle_trace() - handle a shared trace buffer resource
* @rproc: the remote processor
* @ptr: the trace resource descriptor
diff --git a/drivers/remoteproc/remoteproc_internal.h b/drivers/remoteproc/remoteproc_internal.h
index 72d4d3d7d94d..07c503de0f95 100644
--- a/drivers/remoteproc/remoteproc_internal.h
+++ b/drivers/remoteproc/remoteproc_internal.h
@@ -24,6 +24,21 @@ struct rproc_debug_trace {
struct rproc_mem_entry trace_mem;
};
+/**
+ * struct rproc_vdev_data - remoteproc virtio device data
+ * @rsc_offset: offset of the vdev's resource entry
+ * @id: virtio device id (as in virtio_ids.h)
+ * @index: vdev position versus other vdev declared in resource table
+ * @rsc: pointer to the vdev resource entry. Valid only during vdev init as
+ * the resource can be cached by rproc.
+ */
+struct rproc_vdev_data {
+ u32 rsc_offset;
+ unsigned int id;
+ u32 index;
+ struct fw_rsc_vdev *rsc;
+};
+
/* from remoteproc_core.c */
void rproc_release(struct kref *kref);
irqreturn_t rproc_vq_interrupt(struct rproc *rproc, int vq_id);