public inbox for u-boot@lists.denx.de
 help / color / mirror / Atom feed
* [PATCH 1/2] drivers/mtd/nvmxip: Rework the read accessor to support 32bit systems
@ 2023-08-13 21:46 Marek Vasut
  2023-08-13 21:46 ` [PATCH 2/2] configs: sandbox: test: dm: blk: Enable NVMXIP QSPI and update test Marek Vasut
                   ` (2 more replies)
  0 siblings, 3 replies; 20+ messages in thread
From: Marek Vasut @ 2023-08-13 21:46 UTC (permalink / raw)
  To: u-boot; +Cc: Marek Vasut, Abdellatif El Khlifi, Simon Glass

Get rid of nvmxip_mmio_rawread() and just implement the readl()/readq()
reader loop within nvmxip_blk_read(). Cast the destination buffer as
needed and increment the read by either 4 or 8 bytes depending on if
this is systemd with 32bit or 64bit physical address.

Signed-off-by: Marek Vasut <marek.vasut+renesas@mailbox.org>
---
Cc: Abdellatif El Khlifi <abdellatif.elkhlifi@arm.com>
Cc: Simon Glass <sjg@chromium.org>
---
 drivers/mtd/nvmxip/nvmxip.c | 38 ++++++++++++-------------------------
 1 file changed, 12 insertions(+), 26 deletions(-)

diff --git a/drivers/mtd/nvmxip/nvmxip.c b/drivers/mtd/nvmxip/nvmxip.c
index a359e3b4822..0bd98d64275 100644
--- a/drivers/mtd/nvmxip/nvmxip.c
+++ b/drivers/mtd/nvmxip/nvmxip.c
@@ -15,23 +15,6 @@
 #include <linux/errno.h>
 #include "nvmxip.h"
 
-/**
- * nvmxip_mmio_rawread() - read from the XIP flash
- * @address:	address of the data
- * @value:	pointer to where storing the value read
- *
- * Read raw data from the XIP flash.
- *
- * Return:
- *
- * Always return 0.
- */
-static int nvmxip_mmio_rawread(const phys_addr_t address, u64 *value)
-{
-	*value = readq(address);
-	return 0;
-}
-
 /**
  * nvmxip_blk_read() - block device read operation
  * @dev:	the block device
@@ -49,15 +32,14 @@ static ulong nvmxip_blk_read(struct udevice *dev, lbaint_t blknr, lbaint_t blkcn
 {
 	struct nvmxip_plat *plat = dev_get_plat(dev->parent);
 	struct blk_desc *desc = dev_get_uclass_plat(dev);
-	/* number of the u64 words to read */
-	u32 qwords = (blkcnt * desc->blksz) / sizeof(u64);
+	/* number of bytes to read */
+	u32 size = blkcnt * desc->blksz;
 	/* physical address of the first block to read */
 	phys_addr_t blkaddr = plat->phys_base + blknr * desc->blksz;
-	u64 *virt_blkaddr;
-	u64 *pdst = buffer;
+	void *virt_blkaddr;
 	uint qdata_idx;
 
-	if (!pdst)
+	if (!buffer)
 		return -EINVAL;
 
 	log_debug("[%s]: reading from blknr: %lu , blkcnt: %lu\n", dev->name, blknr, blkcnt);
@@ -66,12 +48,16 @@ static ulong nvmxip_blk_read(struct udevice *dev, lbaint_t blknr, lbaint_t blkcn
 
 	/* assumption: the data is virtually contiguous */
 
-	for (qdata_idx = 0 ; qdata_idx < qwords ; qdata_idx++)
-		nvmxip_mmio_rawread((phys_addr_t)(virt_blkaddr + qdata_idx), pdst++);
-
+#if IS_ENABLED(CONFIG_PHYS_64BIT)
+	for (qdata_idx = 0 ; qdata_idx < size; qdata_idx += sizeof(u64))
+		*(u64 *)(buffer + qdata_idx) = readq(virt_blkaddr + qdata_idx);
+#else
+	for (qdata_idx = 0 ; qdata_idx < size; qdata_idx += sizeof(u32))
+		*(u32 *)(buffer + qdata_idx) = readl(virt_blkaddr + qdata_idx);
+#endif
 	log_debug("[%s]:     src[0]: 0x%llx , dst[0]: 0x%llx , src[-1]: 0x%llx , dst[-1]: 0x%llx\n",
 		  dev->name,
-		  *virt_blkaddr,
+		  *(u64 *)virt_blkaddr,
 		  *(u64 *)buffer,
 		  *(u64 *)((u8 *)virt_blkaddr + desc->blksz * blkcnt - sizeof(u64)),
 		  *(u64 *)((u8 *)buffer + desc->blksz * blkcnt - sizeof(u64)));
-- 
2.40.1


^ permalink raw reply related	[flat|nested] 20+ messages in thread

end of thread, other threads:[~2023-10-20 12:12 UTC | newest]

Thread overview: 20+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-08-13 21:46 [PATCH 1/2] drivers/mtd/nvmxip: Rework the read accessor to support 32bit systems Marek Vasut
2023-08-13 21:46 ` [PATCH 2/2] configs: sandbox: test: dm: blk: Enable NVMXIP QSPI and update test Marek Vasut
2023-08-14 22:42   ` Simon Glass
2023-08-14 22:45     ` Marek Vasut
2023-08-15 16:43       ` [PATCH] nvmxip: add sandbox support Abdellatif El Khlifi
2023-08-15 18:39         ` Simon Glass
2023-08-16 11:05           ` [PATCH v2 1/2] log: select physical address formatting in a generic way Abdellatif El Khlifi
2023-08-16 11:05             ` [PATCH v2 2/2] nvmxip: add sandbox support Abdellatif El Khlifi
2023-08-16 11:18               ` Marek Vasut
2023-08-16 16:39                 ` Abdellatif El Khlifi
2023-08-16 21:47                   ` Marek Vasut
2023-08-16 11:13             ` [PATCH v2 1/2] log: select physical address formatting in a generic way Marek Vasut
2023-08-16 14:39               ` Simon Glass
2023-08-16 15:23                 ` Marek Vasut
2023-10-20 12:12             ` Abdellatif El Khlifi
2023-08-15 20:44         ` [PATCH] nvmxip: add sandbox support Marek Vasut
2023-08-15 17:08       ` [PATCH 2/2] configs: sandbox: test: dm: blk: Enable NVMXIP QSPI and update test Abdellatif El Khlifi
2023-08-13 23:55 ` [PATCH 1/2] drivers/mtd/nvmxip: Rework the read accessor to support 32bit systems Marek Vasut
2023-08-19  0:23 ` Marek Vasut
2023-08-21 11:34   ` Abdellatif El Khlifi

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox