From: Michael Tretter <m.tretter@pengutronix.de>
To: barebox@lists.infradead.org
Cc: lst@pengutronix.de
Subject: [PATCH v2 2/3] firmware: zynqmp-fpga: avoid additional buffer for size argument
Date: Thu, 19 Aug 2021 10:12:50 +0200 [thread overview]
Message-ID: <20210819081251.726840-3-m.tretter@pengutronix.de> (raw)
In-Reply-To: <20210819081251.726840-1-m.tretter@pengutronix.de>
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>
---
drivers/firmware/zynqmp-fpga.c | 37 +++++++++++++++-------------------
1 file changed, 16 insertions(+), 21 deletions(-)
diff --git a/drivers/firmware/zynqmp-fpga.c b/drivers/firmware/zynqmp-fpga.c
index 736d1950fa5e..667910479aa7 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);
--
2.30.2
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
next prev parent reply other threads:[~2021-08-19 8:14 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-08-19 8:12 [PATCH v2 0/3] firmware: zynqmp-fpga: fix fpga loading with optimized string functions Michael Tretter
2021-08-19 8:12 ` [PATCH v2 1/3] firmware: zynqmp-fpga: initialize flags at function start Michael Tretter
2021-08-19 8:12 ` Michael Tretter [this message]
2021-08-19 8:12 ` [PATCH v2 3/3] firmware: zynqmp-fpga: do not use DMA coherent memory for bitstream Michael Tretter
2021-08-23 13:51 ` [PATCH v2 0/3] firmware: zynqmp-fpga: fix fpga loading with optimized string functions Sascha Hauer
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20210819081251.726840-3-m.tretter@pengutronix.de \
--to=m.tretter@pengutronix.de \
--cc=barebox@lists.infradead.org \
--cc=lst@pengutronix.de \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox