diff mbox series

remoteproc: add optional hook for resource checking

Message ID bc9f1dd8-92b1-4839-86c9-ac9e544648ec@maurer.systems (mailing list archive)
State New
Headers show
Series remoteproc: add optional hook for resource checking | expand

Commit Message

Simon Maurer Jan. 22, 2025, 3:59 p.m. UTC
This optional hook gives the remoteproc driver the opportunity to check
the resource table after parsing and to replace the allocator in
the carveouts before resource allocation. This is needed for RemoteProc
over PCIe where the carveouts are already mapped by the driver.

Signed-off-by: Simon Maurer <mail@maurer.systems>
---
  drivers/remoteproc/remoteproc_core.c | 6 ++++++
  include/linux/remoteproc.h           | 3 +++
  2 files changed, 9 insertions(+)

firmware image
   * @get_loaded_rsc_table: get resource table installed in memory
   *			  by external entity
@@ -394,6 +396,7 @@ struct rproc_ops {
  	int (*parse_fw)(struct rproc *rproc, const struct firmware *fw);
  	int (*handle_rsc)(struct rproc *rproc, u32 rsc_type, void *rsc,
  			  int offset, int avail);
+	int (*check_rsc)(struct rproc *rproc);
  	struct resource_table *(*find_loaded_rsc_table)(
  				struct rproc *rproc, const struct firmware *fw);
  	struct resource_table *(*get_loaded_rsc_table)(

Comments

Simon Maurer Jan. 22, 2025, 6:53 p.m. UTC | #1
The last patch would be the first step for RemoteProc over PCIe. I use a
Xilinx Zynq 7000 PCIe card as my remote CPU and a x86 PC as the the
host. Both vrings and RPMSG-buffer are in the remote (PCIe-Card) SRAM.
So the RPMSG-buffer isn't actually DMA memory, but the SRAM on the Zynq
is mapped in a PCIe-bar. I'm working now on a patch, that transfers the
ownership of the RPMSG-buffer form virtio_rpmsg_bus to
remoteproc_virtio. So instead of virtio_rpmsg_bus calling
dma_alloc_coherent for buffer allocation, it would call
virtio_get_shm_region to get TX/RX buffers and on rpmsg_remove it would
call virtio_release_shm_regions (new in virtio_config_ops), analogue to
find_vqs/del_vqs.
Thoughts?
Mathieu Poirier Jan. 27, 2025, 4:27 p.m. UTC | #2
On Wed, 22 Jan 2025 at 11:53, Simon Maurer <mail@maurer.systems> wrote:
>
> The last patch would be the first step for RemoteProc over PCIe. I use a
> Xilinx Zynq 7000 PCIe card as my remote CPU and a x86 PC as the the
> host. Both vrings and RPMSG-buffer are in the remote (PCIe-Card) SRAM.
> So the RPMSG-buffer isn't actually DMA memory, but the SRAM on the Zynq
> is mapped in a PCIe-bar. I'm working now on a patch, that transfers the
> ownership of the RPMSG-buffer form virtio_rpmsg_bus to
> remoteproc_virtio. So instead of virtio_rpmsg_bus calling
> dma_alloc_coherent for buffer allocation, it would call
> virtio_get_shm_region to get TX/RX buffers and on rpmsg_remove it would
> call virtio_release_shm_regions (new in virtio_config_ops), analogue to
> find_vqs/del_vqs.
> Thoughts?
>

Hi Simon,

I don't know anything about the Zynq 7000 but I assume it needs to be
explicitly told to act as an endpoint rather than a PCI bus master.
I can't say much about the above without looking at real code so I
will wait for your patches before spending more time on the design you
are putting forward.

As for your patch adding a new operation to the rproc_ops structure,
please include in the submission for the work you presented above.  It
can't be merged without an actual customer.

Thanks,
Mathieu
diff mbox series

Patch

diff --git a/drivers/remoteproc/remoteproc_core.c 
b/drivers/remoteproc/remoteproc_core.c
index c2cf0d277729..3129c5d68770 100644
--- a/drivers/remoteproc/remoteproc_core.c
+++ b/drivers/remoteproc/remoteproc_core.c
@@ -1423,6 +1423,12 @@  static int rproc_fw_boot(struct rproc *rproc, 
const struct firmware *fw)
  		goto clean_up_resources;
  	}

+	if (rproc->ops->check_rsc) {
+		ret = rproc->ops->check_rsc(rproc);
+		if (ret)
+			goto clean_up_resources;
+	}
+
  	/* Allocate carveout resources associated to rproc */
  	ret = rproc_alloc_registered_carveouts(rproc);
  	if (ret) {
diff --git a/include/linux/remoteproc.h b/include/linux/remoteproc.h
index b4795698d8c2..6d7d35d24dad 100644
--- a/include/linux/remoteproc.h
+++ b/include/linux/remoteproc.h
@@ -371,6 +371,8 @@  enum rsc_handling_status {
   * @handle_rsc:	optional platform hook to handle vendor resources. 
Should return
   *		RSC_HANDLED if resource was handled, RSC_IGNORED if not handled
   *		and a negative value on error
+ * @hcheck_rsc:	optional platform hook to check resources before 
allocation.
+ *		Should return 0 if resources are OK and a negative value on error
   * @find_loaded_rsc_table: find the loaded resource table from