zephyrproject-rtos / zephyr

Primary Git Repository for the Zephyr Project. Zephyr is a new generation, scalable, optimized, secure RTOS for multiple hardware architectures.
https://docs.zephyrproject.org
Apache License 2.0
10.42k stars 6.39k forks source link

fpga: allow bitstream to be supplied chunk-wise using callback #56506

Open arbrauns opened 1 year ago

arbrauns commented 1 year ago

Is your enhancement proposal related to a problem? Please describe. Currently, fpga_load() expects the entire bitstream to be stored in a contiguous memory region. Because bitstream files tend to be quite large and sparse, it is tempting to 1) store them on external, non-memory-mapped storage and/or 2) compress them. With the current FPGA driver, the entire bitstream would have to be loaded into memory first, which would defeat the purpose and might not be possible at all.

Describe the solution you'd like If possible, FPGA drivers should allow the bitstream to be loaded in chunks by calling a supplied callback. This callback can then load data from external storage and/or uncompress the bitstream. The API would look something like the following:

// @param offset The current byte position within the bitstream (sum of all previous chunk lengths)
// @param buf Destination for buffer address containing bitstream data
//
// @retval 0 if the end of bitstream has been reached
// @retval >0 the number of bytes stored in the buffer pointed to by buf
// @retval negative errno code on failure
typedef int (*fpga_load_callback)(size_t offset, uint8_t **buf);

static inline int fpga_load_chunked(const struct device *dev, fpga_load_callback cb);

For this to be supported, the hardware has to support pauses during the programming process (while the callback produces more data).

Describe alternatives you've considered None.

cc @tgorochowik @kgugala as code owners

tgorochowik commented 1 year ago

Sounds good! It wasn't needed for our use-case but I can see how that could be useful.

Feel free to propose a PR with the changes! Make sure the new callback is optional so that current drivers continue to work without any modifications

zephyrbot commented 6 months ago

Hi @cfriedt,

This issue, marked as an Enhancement, was opened a while ago and did not get any traction. It was just assigned to you based on the labels. If you don't consider yourself the right person to address this issue, please re-assing it to the right person.

Please take a moment to review if the issue is still relevant to the project. If it is, please provide feedback and direction on how to move forward. If it is not, has already been addressed, is a duplicate, or is no longer relevant, please close it with a short comment explaining the reason.

@arbrauns you are also encouraged to help moving this issue forward by providing additional information and confirming this request/issue is still relevant to you.

Thanks!