From: Ahmad Fatoum <a.fatoum@pengutronix.de>
To: barebox@lists.infradead.org
Cc: Adrian Negreanu <adrian.negreanu@nxp.com>,
Ahmad Fatoum <a.fatoum@pengutronix.de>
Subject: [PATCH 03/11] firmware: qemu_fw_cfg: add support for seeking
Date: Thu, 13 Mar 2025 11:17:20 +0100 [thread overview]
Message-ID: <20250313101728.3546902-4-a.fatoum@pengutronix.de> (raw)
In-Reply-To: <20250313101728.3546902-1-a.fatoum@pengutronix.de>
Seeks were so far not possible and resulted in an -EINVAL if the accesses
weren't consecutive.
Implement it properly using FW_CFG_DMA_CTL_SKIP.
Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
drivers/firmware/qemu_fw_cfg.c | 44 ++++++++++++++++++++--------------
1 file changed, 26 insertions(+), 18 deletions(-)
diff --git a/drivers/firmware/qemu_fw_cfg.c b/drivers/firmware/qemu_fw_cfg.c
index 26770da908ce..33c1617a61e4 100644
--- a/drivers/firmware/qemu_fw_cfg.c
+++ b/drivers/firmware/qemu_fw_cfg.c
@@ -70,6 +70,7 @@ static int fw_cfg_ioctl(struct cdev *cdev, unsigned int request, void *buf)
switch (request) {
case FW_CFG_SELECT:
fw_cfg->sel = *(u16 *)buf;
+ fw_cfg->next_read_offset = 0;
break;
default:
ret = -ENOTTY;
@@ -87,10 +88,8 @@ static int fw_cfg_ioctl(struct cdev *cdev, unsigned int request, void *buf)
while (*remaining >= sizeof(type)) { \
val = __raw_read##type((fw_cfg)->reg_data); \
*remaining -= sizeof(type); \
- if (*address) { \
- put_unaligned(val, (type *)*address); \
- *address += sizeof(type); \
- } \
+ put_unaligned(val, (type *)*address); \
+ *address += sizeof(type); \
} \
} while(0)
@@ -123,11 +122,27 @@ static void fw_cfg_data_read(struct fw_cfg *fw_cfg, void *address, size_t remain
fw_cfg_data_read_sized(fw_cfg, &remaining, &address, u8);
}
+static void fw_cfg_do_dma(struct fw_cfg *fw_cfg, dma_addr_t address,
+ u32 count, u32 control)
+{
+ struct fw_cfg_dma_access __iomem *acc = fw_cfg->acc_virt;
+
+ acc->address = cpu_to_be64(address);
+ acc->length = cpu_to_be32(count);
+ acc->control = cpu_to_be32(control);
+
+ iowrite64be(fw_cfg->acc_dma, fw_cfg->reg_dma);
+
+ while (ioread32be(&acc->control) & ~FW_CFG_DMA_CTL_ERROR)
+ ;
+}
+
static ssize_t fw_cfg_read(struct cdev *cdev, void *buf, size_t count,
loff_t pos, unsigned long flags)
{
struct fw_cfg *fw_cfg = to_fw_cfg(cdev);
unsigned rdsize = FIELD_GET(O_RWSIZE_MASK, flags);
+ u32 selector = FW_CFG_DMA_CTL_SELECT | fw_cfg->sel << 16;
if (!pos || pos != fw_cfg->next_read_offset) {
fw_cfg_select(fw_cfg);
@@ -145,8 +160,9 @@ static ssize_t fw_cfg_read(struct cdev *cdev, void *buf, size_t count,
rdsize = 1;
}
- while (pos-- > fw_cfg->next_read_offset)
- fw_cfg_data_read(fw_cfg, NULL, count, rdsize);
+ if (pos != fw_cfg->next_read_offset)
+ fw_cfg_do_dma(fw_cfg, DMA_ERROR_CODE, pos,
+ FW_CFG_DMA_CTL_SKIP | selector);
fw_cfg_data_read(fw_cfg, buf, count, rdsize);
@@ -159,14 +175,10 @@ static ssize_t fw_cfg_write(struct cdev *cdev, const void *buf, size_t count,
{
struct fw_cfg *fw_cfg = to_fw_cfg(cdev);
struct device *dev = cdev->dev;
- struct fw_cfg_dma_access __iomem *acc = fw_cfg->acc_virt;
void *dma_buf;
dma_addr_t mapping;
int ret = 0;
- if (pos != 0)
- return -EINVAL;
-
dma_buf = dma_alloc(count);
if (!dma_buf)
return -ENOMEM;
@@ -181,15 +193,11 @@ static ssize_t fw_cfg_write(struct cdev *cdev, const void *buf, size_t count,
fw_cfg->next_read_offset = 0;
- acc->address = cpu_to_be64(mapping);
- acc->length = cpu_to_be32(count);
- acc->control = cpu_to_be32(FW_CFG_DMA_CTL_WRITE |
- FW_CFG_DMA_CTL_SELECT | fw_cfg->sel << 16);
+ fw_cfg_do_dma(fw_cfg, DMA_ERROR_CODE, pos, FW_CFG_DMA_CTL_SKIP |
+ FW_CFG_DMA_CTL_SELECT | fw_cfg->sel << 16);
- iowrite64be(fw_cfg->acc_dma, fw_cfg->reg_dma);
-
- while (ioread32be(&acc->control) & ~FW_CFG_DMA_CTL_ERROR)
- ;
+ fw_cfg_do_dma(fw_cfg, mapping, count, FW_CFG_DMA_CTL_WRITE |
+ FW_CFG_DMA_CTL_SELECT | fw_cfg->sel << 16);
dma_unmap_single(dev, mapping, count, DMA_FROM_DEVICE);
free_buf:
--
2.39.5
next prev parent reply other threads:[~2025-03-13 10:18 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-03-13 10:17 [PATCH 00/11] firmware: qemu_fw_cfg: implement file system Ahmad Fatoum
2025-03-13 10:17 ` [PATCH 01/11] video: ramfb: fix frame buffer screen size Ahmad Fatoum
2025-03-13 10:17 ` [PATCH 02/11] firmware: qemu_fw_cfg: drop duplicate definitions Ahmad Fatoum
2025-03-13 10:17 ` Ahmad Fatoum [this message]
2025-03-13 10:17 ` [PATCH 04/11] firmware: qemu_fw_cfg: rename from /dev/fw_cfg0 to /dev/fw_cfg Ahmad Fatoum
2025-03-13 10:17 ` [PATCH 05/11] fs: add qemu_fw_cfg file system Ahmad Fatoum
2025-03-13 10:17 ` [PATCH 06/11] firmware: qemu_fw_cfg: register at device initcall level Ahmad Fatoum
2025-03-13 10:17 ` [PATCH 07/11] video: ramfb: use new qemu fw_cfg FS Ahmad Fatoum
2025-03-13 10:17 ` [PATCH 08/11] libfile: give copy_file a flags parameter Ahmad Fatoum
2025-03-13 10:17 ` [PATCH 09/11] libfile: pass copy_file flags through copy_recursive Ahmad Fatoum
2025-03-13 10:17 ` [PATCH 10/11] libfile: add support for not clobbering files in copy_file Ahmad Fatoum
2025-03-13 10:17 ` [PATCH 11/11] fs: qemu_fw_cfg: support populating environment via QEMU fw_cfg Ahmad Fatoum
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=20250313101728.3546902-4-a.fatoum@pengutronix.de \
--to=a.fatoum@pengutronix.de \
--cc=adrian.negreanu@nxp.com \
--cc=barebox@lists.infradead.org \
/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