summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMichael Tretter <m.tretter@pengutronix.de>2021-08-19 10:12:50 +0200
committerSascha Hauer <s.hauer@pengutronix.de>2021-08-23 15:51:36 +0200
commit52bc1b99afbf4acced704ce67130455ee0f882a7 (patch)
tree59ada8d9f7886ad1afc10ae019144640bd1da896
parent3b1ac08954d4518e019331fb34ba9b0677055145 (diff)
downloadbarebox-52bc1b99afbf4acced704ce67130455ee0f882a7.tar.gz
barebox-52bc1b99afbf4acced704ce67130455ee0f882a7.tar.xz
firmware: zynqmp-fpga: avoid additional buffer for size argument
There are two different APIs for loading an FPGA via the pmu-fw as indicated by the ZYNQMP_PM_FEATURE_SIZE_NOT_NEEDED feature flag. The pmu-fw expects as second argument either the size of the bitstream or a pointer to the size of the bitstream. The driver allocates a separate buffer for the size, which results in the allocation of a 4k page for storing a 32 bit value. Allocate some more memory for the bitstream and append the size of the bitstream at the end of the bitstream to avoid the additional memory allocation. Add a comment to explain the surprising size of the allocation. Signed-off-by: Michael Tretter <m.tretter@pengutronix.de> Link: https://lore.barebox.org/20210819081251.726840-3-m.tretter@pengutronix.de Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
-rw-r--r--drivers/firmware/zynqmp-fpga.c37
1 files changed, 16 insertions, 21 deletions
diff --git a/drivers/firmware/zynqmp-fpga.c b/drivers/firmware/zynqmp-fpga.c
index 736d1950fa..667910479a 100644
--- a/drivers/firmware/zynqmp-fpga.c
+++ b/drivers/firmware/zynqmp-fpga.c
@@ -197,8 +197,8 @@ static void zynqmp_fpga_show_header(const struct device_d *dev,
static int fpgamgr_program_finish(struct firmware_handler *fh)
{
struct fpgamgr *mgr = container_of(fh, struct fpgamgr, fh);
- char *buf_aligned;
- u32 *buf_size = NULL;
+ u32 *buf_aligned;
+ u32 buf_size;
u32 *body;
size_t body_length;
int header_length = 0;
@@ -234,17 +234,14 @@ static int fpgamgr_program_finish(struct firmware_handler *fh)
goto err_free;
}
- if (!(mgr->features & ZYNQMP_PM_FEATURE_SIZE_NOT_NEEDED)) {
- buf_size = dma_alloc_coherent(sizeof(*buf_size),
- DMA_ADDRESS_BROKEN);
- if (!buf_size) {
- status = -ENOBUFS;
- goto err_free;
- }
- *buf_size = body_length;
- }
-
- buf_aligned = dma_alloc_coherent(body_length, DMA_ADDRESS_BROKEN);
+ /*
+ * The PMU FW variants without the ZYNQMP_PM_FEATURE_SIZE_NOT_NEEDED
+ * feature expect a pointer to the bitstream size, which is stored in
+ * memory. Allocate some extra space at the end of the buffer for the
+ * bitstream size.
+ */
+ buf_aligned = dma_alloc_coherent(body_length + sizeof(buf_size),
+ DMA_ADDRESS_BROKEN);
if (!buf_aligned) {
status = -ENOBUFS;
goto err_free;
@@ -259,20 +256,18 @@ static int fpgamgr_program_finish(struct firmware_handler *fh)
addr = (u64)buf_aligned;
- if (!(mgr->features & ZYNQMP_PM_FEATURE_SIZE_NOT_NEEDED) && buf_size) {
- status = mgr->eemi_ops->fpga_load(addr,
- (u32)(uintptr_t)buf_size,
- flags);
- dma_free_coherent(buf_size, 0, sizeof(*buf_size));
+ if (mgr->features & ZYNQMP_PM_FEATURE_SIZE_NOT_NEEDED) {
+ buf_size = body_length;
} else {
- status = mgr->eemi_ops->fpga_load(addr, (u32)(body_length),
- flags);
+ buf_aligned[body_length / sizeof(*buf_aligned)] = body_length;
+ buf_size = addr + body_length;
}
+ status = mgr->eemi_ops->fpga_load(addr, buf_size, flags);
if (status < 0)
dev_err(&mgr->dev, "unable to load fpga\n");
- dma_free_coherent(buf_aligned, 0, body_length);
+ dma_free_coherent(buf_aligned, 0, body_length + sizeof(buf_size));
err_free:
free(mgr->buf);