@@ -720,6 +720,42 @@ static int rproc_handle_carveout(struct rproc *rproc,
return ret;
}
+/**
+ * rproc_handle_rproc_mem() - handle remote processor memory
+ * @rproc: rproc handle
+ * @rsc: the resource entry
+ * @avail: size of available data (for image validation)
+ *
+ * This function will handle declare the remote procesor's memory
+ * as DMA memory of the remoteproc, and then, the host can use it
+ * as shared memory, e.g. vrings ahre shared buffers.
+ */
+static int rproc_handle_rproc_mem(struct rproc *rproc,
+ struct fw_rsc_rproc_mem *rsc,
+ int offset, int avail)
+{
+ struct device *dev = &rproc->dev;
+ int ret;
+
+ if (sizeof(*rsc) > avail) {
+ dev_err(dev, "rproc_mem rsc is truncated\n");
+ return -EINVAL;
+ }
+
+ if (rsc->pa == FW_RSC_ADDR_ANY) {
+ dev_err(dev, "not able to declare rproc mem, pa is 0x%x\n",
+ rsc->pa);
+ return -EINVAL;
+ }
+ ret = dma_declare_coherent_memory(dev->parent, rsc->pa,
+ rsc->pa, rsc->len, DMA_MEMORY_MAP);
+ if (!ret) {
+ dev_err(dev, "failed to declare rproc mem as DMA mem.\n");
+ return -ENOMEM;
+ }
+ return 0;
+}
+
/*
* A lookup table for resource handlers. The indices are defined in
* enum fw_resource_type.
@@ -729,6 +765,7 @@ static int rproc_handle_carveout(struct rproc *rproc,
[RSC_DEVMEM] = (rproc_handle_resource_t)rproc_handle_devmem,
[RSC_TRACE] = (rproc_handle_resource_t)rproc_handle_trace,
[RSC_VDEV] = (rproc_handle_resource_t)rproc_handle_vdev,
+ [RSC_RPROC_MEM] = (rproc_handle_resource_t)rproc_handle_rproc_mem,
};
/* handle firmware resource entries before booting the remote processor */