All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] mtd: spi-nor-core: Implement spi_nor_read_sfdp_dma_unsafe() for sfdp parse
@ 2022-06-03  7:01 Vaishnav Achath
  2022-06-28 10:01 ` Pratyush Yadav
  2022-07-10  5:37 ` Jagan Teki
  0 siblings, 2 replies; 5+ messages in thread
From: Vaishnav Achath @ 2022-06-03  7:01 UTC (permalink / raw)
  To: u-boot, jagan, vigneshr; +Cc: p.yadav, vaishnav.a

During SFDP header parse and BFPT parse, structures in stack are used
to perform spi_nor_read_sfdp() which expects a dma-safe buffer.

This commit introduces spi_nor_read_sfdp_dma_unsafe() to wrap
spi_nor_read_sfdp() using a kmalloc'ed bounce buffer which is
the same implementation in Linux (drivers/mtd/spi-nor/sfdp.c).

Signed-off-by: Vaishnav Achath <vaishnav.a@ti.com>
---
 drivers/mtd/spi/spi-nor-core.c | 34 ++++++++++++++++++++++++++++++++--
 1 file changed, 32 insertions(+), 2 deletions(-)

diff --git a/drivers/mtd/spi/spi-nor-core.c b/drivers/mtd/spi/spi-nor-core.c
index 3b7c817c02..90d05da1d8 100644
--- a/drivers/mtd/spi/spi-nor-core.c
+++ b/drivers/mtd/spi/spi-nor-core.c
@@ -2022,6 +2022,36 @@ read_err:
 	return ret;
 }
 
+/**
+ * spi_nor_read_sfdp_dma_unsafe() - read Serial Flash Discoverable Parameters.
+ * @nor:	pointer to a 'struct spi_nor'
+ * @addr:	offset in the SFDP area to start reading data from
+ * @len:	number of bytes to read
+ * @buf:	buffer where the SFDP data are copied into
+ *
+ * Wrap spi_nor_read_sfdp() using a kmalloc'ed bounce buffer as @buf is now not
+ * guaranteed to be dma-safe.
+ *
+ * Return: -ENOMEM if kmalloc() fails, the return code of spi_nor_read_sfdp()
+ *          otherwise.
+ */
+static int spi_nor_read_sfdp_dma_unsafe(struct spi_nor *nor, u32 addr,
+					size_t len, void *buf)
+{
+	void *dma_safe_buf;
+	int ret;
+
+	dma_safe_buf = kmalloc(len, GFP_KERNEL);
+	if (!dma_safe_buf)
+		return -ENOMEM;
+
+	ret = spi_nor_read_sfdp(nor, addr, len, dma_safe_buf);
+	memcpy(buf, dma_safe_buf, len);
+	kfree(dma_safe_buf);
+
+	return ret;
+}
+
 /* Fast Read settings. */
 
 static void
@@ -2195,7 +2225,7 @@ static int spi_nor_parse_bfpt(struct spi_nor *nor,
 		    bfpt_header->length * sizeof(u32));
 	addr = SFDP_PARAM_HEADER_PTP(bfpt_header);
 	memset(&bfpt, 0, sizeof(bfpt));
-	err = spi_nor_read_sfdp(nor,  addr, len, &bfpt);
+	err = spi_nor_read_sfdp_dma_unsafe(nor,  addr, len, &bfpt);
 	if (err < 0)
 		return err;
 
@@ -2480,7 +2510,7 @@ static int spi_nor_parse_sfdp(struct spi_nor *nor,
 	int i, err;
 
 	/* Get the SFDP header. */
-	err = spi_nor_read_sfdp(nor, 0, sizeof(header), &header);
+	err = spi_nor_read_sfdp_dma_unsafe(nor, 0, sizeof(header), &header);
 	if (err < 0)
 		return err;
 
-- 
2.17.1


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

* Re: [PATCH] mtd: spi-nor-core: Implement spi_nor_read_sfdp_dma_unsafe() for sfdp parse
  2022-06-03  7:01 [PATCH] mtd: spi-nor-core: Implement spi_nor_read_sfdp_dma_unsafe() for sfdp parse Vaishnav Achath
@ 2022-06-28 10:01 ` Pratyush Yadav
  2022-07-10  5:37 ` Jagan Teki
  1 sibling, 0 replies; 5+ messages in thread
From: Pratyush Yadav @ 2022-06-28 10:01 UTC (permalink / raw)
  To: Vaishnav Achath; +Cc: u-boot, jagan, vigneshr

On 03/06/22 12:31PM, Vaishnav Achath wrote:
> During SFDP header parse and BFPT parse, structures in stack are used
> to perform spi_nor_read_sfdp() which expects a dma-safe buffer.
> 
> This commit introduces spi_nor_read_sfdp_dma_unsafe() to wrap
> spi_nor_read_sfdp() using a kmalloc'ed bounce buffer which is
> the same implementation in Linux (drivers/mtd/spi-nor/sfdp.c).
> 
> Signed-off-by: Vaishnav Achath <vaishnav.a@ti.com>

Reviewed-by: Pratyush Yadav <p.yadav@ti.com>

-- 
Regards,
Pratyush Yadav
Texas Instruments Inc.

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

* Re: [PATCH] mtd: spi-nor-core: Implement spi_nor_read_sfdp_dma_unsafe() for sfdp parse
  2022-06-03  7:01 [PATCH] mtd: spi-nor-core: Implement spi_nor_read_sfdp_dma_unsafe() for sfdp parse Vaishnav Achath
  2022-06-28 10:01 ` Pratyush Yadav
@ 2022-07-10  5:37 ` Jagan Teki
  2023-12-12 14:04   ` Tom Rini
  1 sibling, 1 reply; 5+ messages in thread
From: Jagan Teki @ 2022-07-10  5:37 UTC (permalink / raw)
  To: Vaishnav Achath; +Cc: u-boot, vigneshr, p.yadav

On Fri, Jun 3, 2022 at 12:31 PM Vaishnav Achath <vaishnav.a@ti.com> wrote:
>
> During SFDP header parse and BFPT parse, structures in stack are used
> to perform spi_nor_read_sfdp() which expects a dma-safe buffer.
>
> This commit introduces spi_nor_read_sfdp_dma_unsafe() to wrap
> spi_nor_read_sfdp() using a kmalloc'ed bounce buffer which is
> the same implementation in Linux (drivers/mtd/spi-nor/sfdp.c).
>
> Signed-off-by: Vaishnav Achath <vaishnav.a@ti.com>
> ---

Applied to u-boot-spi/master

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

* Re: [PATCH] mtd: spi-nor-core: Implement spi_nor_read_sfdp_dma_unsafe() for sfdp parse
  2022-07-10  5:37 ` Jagan Teki
@ 2023-12-12 14:04   ` Tom Rini
  2023-12-12 17:19     ` Jagan Teki
  0 siblings, 1 reply; 5+ messages in thread
From: Tom Rini @ 2023-12-12 14:04 UTC (permalink / raw)
  To: Jagan Teki; +Cc: Vaishnav Achath, u-boot, vigneshr, p.yadav

[-- Attachment #1: Type: text/plain, Size: 647 bytes --]

On Sun, Jul 10, 2022 at 11:07:41AM +0530, Jagan Teki wrote:
> On Fri, Jun 3, 2022 at 12:31 PM Vaishnav Achath <vaishnav.a@ti.com> wrote:
> >
> > During SFDP header parse and BFPT parse, structures in stack are used
> > to perform spi_nor_read_sfdp() which expects a dma-safe buffer.
> >
> > This commit introduces spi_nor_read_sfdp_dma_unsafe() to wrap
> > spi_nor_read_sfdp() using a kmalloc'ed bounce buffer which is
> > the same implementation in Linux (drivers/mtd/spi-nor/sfdp.c).
> >
> > Signed-off-by: Vaishnav Achath <vaishnav.a@ti.com>
> > ---
> 
> Applied to u-boot-spi/master

Where did this end up? Thanks.

-- 
Tom

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 659 bytes --]

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

* Re: [PATCH] mtd: spi-nor-core: Implement spi_nor_read_sfdp_dma_unsafe() for sfdp parse
  2023-12-12 14:04   ` Tom Rini
@ 2023-12-12 17:19     ` Jagan Teki
  0 siblings, 0 replies; 5+ messages in thread
From: Jagan Teki @ 2023-12-12 17:19 UTC (permalink / raw)
  To: Tom Rini; +Cc: Vaishnav Achath, u-boot, vigneshr, p.yadav

On Tue, Dec 12, 2023 at 7:34 PM Tom Rini <trini@konsulko.com> wrote:
>
> On Sun, Jul 10, 2022 at 11:07:41AM +0530, Jagan Teki wrote:
> > On Fri, Jun 3, 2022 at 12:31 PM Vaishnav Achath <vaishnav.a@ti.com> wrote:
> > >
> > > During SFDP header parse and BFPT parse, structures in stack are used
> > > to perform spi_nor_read_sfdp() which expects a dma-safe buffer.
> > >
> > > This commit introduces spi_nor_read_sfdp_dma_unsafe() to wrap
> > > spi_nor_read_sfdp() using a kmalloc'ed bounce buffer which is
> > > the same implementation in Linux (drivers/mtd/spi-nor/sfdp.c).
> > >
> > > Signed-off-by: Vaishnav Achath <vaishnav.a@ti.com>
> > > ---
> >
> > Applied to u-boot-spi/master
>
> Where did this end up? Thanks.

I have CI, will send PR. soon.

Jagan.

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

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

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-06-03  7:01 [PATCH] mtd: spi-nor-core: Implement spi_nor_read_sfdp_dma_unsafe() for sfdp parse Vaishnav Achath
2022-06-28 10:01 ` Pratyush Yadav
2022-07-10  5:37 ` Jagan Teki
2023-12-12 14:04   ` Tom Rini
2023-12-12 17:19     ` Jagan Teki

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.