Skip to contentSkip to conversation

board_f: Add mach specific DMA address check function.

PATCH Superseded Christoph Muellner 5 participants 20 messages May 7, 2019 – Aug 22, 2019

Subsystems (3)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/3 board_f: Add mach specific DMA address check function.

From: Christoph Müllner <[email protected]>

Some machines have limited DMA engines, which cannot deal with arbitrary addresses. This patch introduces a function to model these restrictions on a machine level.

---

 common/board_f.c | 5 +++++
 include/init.h   | 2 ++
 2 files changed, 7 insertions(+)
common/board_f.c +5 -0
index 7ef20f2042..fed3c24373 100644
@@ -1053,3 +1053,8 @@ void board_init_f_r(void)
 	hang();
 }
 #endif /* CONFIG_X86 */
+
+__weak int mach_addr_is_dmaable(unsigned long addr)
+{
+	return 1;
+}
include/init.h +2 -0
index afc953d51e..18210a1489 100644
@@ -125,6 +125,8 @@ int misc_init_f(void);
 int embedded_dtb_select(void);
 #endif
 
+int mach_addr_is_dmaable(unsigned long addr);
+
 /* common/init/board_init.c */
 extern ulong monitor_flash_len;
 
Signature · 1 line
2.11.0
#1 lore raw

PATCH 2/3 bouncebuf: Add DMA validation check to addr_aligned().

Currently addr_aligned() performs an alignment and a length check to validate the DMA address. However, some machines have stricter restrictions of DMA-able addresses.

This patch adds a call to mach_addr_is_dmaable() to honor this machine specific restrictions.

---

 common/bouncebuf.c | 6 ++++++
 1 file changed, 6 insertions(+)
common/bouncebuf.c +6 -0
index a7098e2caf..26ddf30ea2 100644
@@ -26,6 +26,12 @@ static int addr_aligned(struct bounce_buffer *state)
 		return 0;
 	}
 
+	/* Check if valid DMA address. */
+	if (!mach_addr_is_dmaable((ulong)state->user_buffer)) {
+		debug("Buffer address is not DMA-able\n");
+		return 0;
+	}
+
 	/* Aligned */
 	return 1;
 }
Signature · 1 line
2.11.0
#2 lore raw

PATCH 2/3 bouncebuf: Add DMA validation check to addr_aligned().

Quoted 18 lines · Christoph Muellner

Currently addr_aligned() performs an alignment and a length check to validate the DMA address. However, some machines have stricter restrictions of DMA-able addresses.

This patch adds a call to mach_addr_is_dmaable() to honor this machine specific restrictions.

---

 common/bouncebuf.c | 6 ++++++
 1 file changed, 6 insertions(+)
common/bouncebuf.c +0 -0
index a7098e2caf..26ddf30ea2 100644

common/bouncebuf.c static int addr_aligned(struct bounce_buffer *state) · line 30

Quoted 5 lines
common/bouncebuf.c +2 -0
@@ -26,6 +26,12 @@ static int addr_aligned(struct bounce_buffer *state)
 		return 0;
 	}
 
+	/* Check if valid DMA address. */
+	if (!mach_addr_is_dmaable((ulong)state->user_buffer)) {

Is the cast necessary ?

Quoted 8 lines
common/bouncebuf.c +4 -0
+		debug("Buffer address is not DMA-able\n");
+		return 0;
+	}
+
 	/* Aligned */
 	return 1;
 }
Signature · 2 lines
Best regards,
Marek Vasut
#3 lore raw

PATCH 2/3 bouncebuf: Add DMA validation check to addr_aligned().

Quoted 22 lines · Marek Vasut
Quoted 21 lines · Christoph Muellner

Currently addr_aligned() performs an alignment and a length check to validate the DMA address. However, some machines have stricter restrictions of DMA-able addresses.

This patch adds a call to mach_addr_is_dmaable() to honor this machine specific restrictions.

---

 common/bouncebuf.c | 6 ++++++
 1 file changed, 6 insertions(+)
common/bouncebuf.c +0 -0
index a7098e2caf..26ddf30ea2 100644
@@ -26,6 +26,12 @@ static int addr_aligned(struct bounce_buffer *state)
 		return 0;
 	}
 
Quoted 4 lines

common/bouncebuf.c static int addr_aligned(struct bounce_buffer *state) · line 30

Quoted 2 lines
common/bouncebuf.c +2 -0
+	/* Check if valid DMA address. */
+	if (!mach_addr_is_dmaable((ulong)state->user_buffer)) {

Is the cast necessary ?

Of course not.
Will be fixed in v2.

Thanks!

Quoted 11 lines
Quoted 9 lines
common/bouncebuf.c +4 -0
+		debug("Buffer address is not DMA-able\n");
+		return 0;
+	}
+
 	/* Aligned */
 	return 1;
 }
#4 lore raw

PATCH 2/3 bouncebuf: Add DMA validation check to addr_aligned().

Quoted 30 lines · Christoph Müllner
Quoted 22 lines · Marek Vasut
Quoted 21 lines · Christoph Muellner

Currently addr_aligned() performs an alignment and a length check to validate the DMA address. However, some machines have stricter restrictions of DMA-able addresses.

This patch adds a call to mach_addr_is_dmaable() to honor this machine specific restrictions.

---

 common/bouncebuf.c | 6 ++++++
 1 file changed, 6 insertions(+)
common/bouncebuf.c +0 -0
index a7098e2caf..26ddf30ea2 100644
@@ -26,6 +26,12 @@ static int addr_aligned(struct bounce_buffer *state)
 		return 0;
 	}
 
Quoted 4 lines

common/bouncebuf.c static int addr_aligned(struct bounce_buffer *state) · line 30

Quoted 2 lines
common/bouncebuf.c +2 -0
+	/* Check if valid DMA address. */
+	if (!mach_addr_is_dmaable((ulong)state->user_buffer)) {

Is the cast necessary ?

Quoted 4 lines

Of course not.
Will be fixed in v2.

Thanks!

I take that back.
The cast is needed.
(And also done several times in this file)

Otherwise you will get:

common/bouncebuf.c: In function ‘addr_aligned’:
common/bouncebuf.c:35:33: warning: passing argument 1 of ‘mach_addr_is_dmaable’ makes integer from pointer without a cast [-Wint-conversion]

  if (!mach_addr_is_dmaable(state->user_buffer)) {
                            ~~~~~^~~~~~~~~~~~~
In file included from include/common.h:64,
                 from common/bouncebuf.c:8:
include/init.h:128:40: note: expected ‘long unsigned int’ but argument is of type ‘void *’
 int mach_addr_is_dmaable(unsigned long addr);
                          ~~~~~~~~~~~~~~^~~~
Quoted 17 lines
Quoted 12 lines

common/bouncebuf.c static int addr_aligned(struct bounce_buffer *state) · line 37

Quoted 10 lines
common/bouncebuf.c +4 -0
+		debug("Buffer address is not DMA-able\n");
+		return 0;
+	}
+
 	/* Aligned */
 	return 1;
 }

_______________________________________________
U-Boot mailing list
U-Boot at lists.denx.de
https://lists.denx.de/listinfo/u-boot

#5 lore raw

PATCH 2/3 bouncebuf: Add DMA validation check to addr_aligned().

Quoted 46 lines · Christoph Müllner
Quoted 30 lines · Christoph Müllner
Quoted 22 lines · Marek Vasut
Quoted 21 lines · Christoph Muellner

Currently addr_aligned() performs an alignment and a length check to validate the DMA address. However, some machines have stricter restrictions of DMA-able addresses.

This patch adds a call to mach_addr_is_dmaable() to honor this machine specific restrictions.

---

 common/bouncebuf.c | 6 ++++++
 1 file changed, 6 insertions(+)
common/bouncebuf.c +0 -0
index a7098e2caf..26ddf30ea2 100644
@@ -26,6 +26,12 @@ static int addr_aligned(struct bounce_buffer *state)
 		return 0;
 	}
 
Quoted 4 lines

common/bouncebuf.c static int addr_aligned(struct bounce_buffer *state) · line 30

Quoted 2 lines
common/bouncebuf.c +2 -0
+	/* Check if valid DMA address. */
+	if (!mach_addr_is_dmaable((ulong)state->user_buffer)) {

Is the cast necessary ?

Quoted 4 lines

Of course not.
Will be fixed in v2.

Thanks!

I take that back.
The cast is needed.
(And also done several times in this file)

Otherwise you will get:

common/bouncebuf.c: In function ‘addr_aligned’:
common/bouncebuf.c:35:33: warning: passing argument 1 of ‘mach_addr_is_dmaable’ makes integer from pointer without a cast [-Wint-conversion]

Quoted 7 lines
  if (!mach_addr_is_dmaable(state->user_buffer)) {
                            ~~~~~^~~~~~~~~~~~~
In file included from include/common.h:64,
                 from common/bouncebuf.c:8:
include/init.h:128:40: note: expected ‘long unsigned int’ but argument is of type ‘void *’
 int mach_addr_is_dmaable(unsigned long addr);
                          ~~~~~~~~~~~~~~^~~~

Shouldn't the function use void __iomem * in the first place ?

Signature · 2 lines
Best regards,
Marek Vasut
#6 lore raw

PATCH 2/3 bouncebuf: Add DMA validation check to addr_aligned().

Quoted 55 lines · Marek Vasut
Quoted 46 lines · Christoph Müllner
Quoted 30 lines · Christoph Müllner
Quoted 22 lines · Marek Vasut
Quoted 21 lines · Christoph Muellner

Currently addr_aligned() performs an alignment and a length check to validate the DMA address. However, some machines have stricter restrictions of DMA-able addresses.

This patch adds a call to mach_addr_is_dmaable() to honor this machine specific restrictions.

---

 common/bouncebuf.c | 6 ++++++
 1 file changed, 6 insertions(+)
common/bouncebuf.c +0 -0
index a7098e2caf..26ddf30ea2 100644
@@ -26,6 +26,12 @@ static int addr_aligned(struct bounce_buffer *state)
 		return 0;
 	}
 
Quoted 4 lines

common/bouncebuf.c static int addr_aligned(struct bounce_buffer *state) · line 30

Quoted 2 lines
common/bouncebuf.c +2 -0
+	/* Check if valid DMA address. */
+	if (!mach_addr_is_dmaable((ulong)state->user_buffer)) {

Is the cast necessary ?

Quoted 4 lines

Of course not.
Will be fixed in v2.

Thanks!

I take that back.
The cast is needed.
(And also done several times in this file)

Otherwise you will get:

common/bouncebuf.c: In function ‘addr_aligned’:
common/bouncebuf.c:35:33: warning: passing argument 1 of ‘mach_addr_is_dmaable’ makes integer from pointer without a cast [-Wint-conversion]

Quoted 7 lines
  if (!mach_addr_is_dmaable(state->user_buffer)) {
                            ~~~~~^~~~~~~~~~~~~
In file included from include/common.h:64,
                 from common/bouncebuf.c:8:
include/init.h:128:40: note: expected ‘long unsigned int’ but argument is of type ‘void *’
 int mach_addr_is_dmaable(unsigned long addr);
                          ~~~~~~~~~~~~~~^~~~
Quoted 1 line

Shouldn't the function use void __iomem * in the first place ?

IMHO Matter of taste.
If you prefer it this way, then I can change.
Doing grep "unsigned long addr" gave me enough confidence to use that. But I leave this up to you.

#7 lore raw

PATCH 2/3 bouncebuf: Add DMA validation check to addr_aligned().

Quoted 58 lines · Christoph Müllner
Quoted 55 lines · Marek Vasut
Quoted 53 lines · Christoph Müllner
Quoted 30 lines · Christoph Müllner
Quoted 22 lines · Marek Vasut
Quoted 21 lines · Christoph Muellner

Currently addr_aligned() performs an alignment and a length check to validate the DMA address. However, some machines have stricter restrictions of DMA-able addresses.

This patch adds a call to mach_addr_is_dmaable() to honor this machine specific restrictions.

---

 common/bouncebuf.c | 6 ++++++
 1 file changed, 6 insertions(+)
common/bouncebuf.c +0 -0
index a7098e2caf..26ddf30ea2 100644
@@ -26,6 +26,12 @@ static int addr_aligned(struct bounce_buffer *state)
 		return 0;
 	}
 
Quoted 4 lines

common/bouncebuf.c static int addr_aligned(struct bounce_buffer *state) · line 30

Quoted 2 lines
common/bouncebuf.c +2 -0
+	/* Check if valid DMA address. */
+	if (!mach_addr_is_dmaable((ulong)state->user_buffer)) {

Is the cast necessary ?

Quoted 4 lines

Of course not.
Will be fixed in v2.

Thanks!

I take that back.
The cast is needed.
(And also done several times in this file)

Otherwise you will get:

common/bouncebuf.c: In function ‘addr_aligned’:
common/bouncebuf.c:35:33: warning: passing argument 1 of ‘mach_addr_is_dmaable’ makes integer from pointer without a cast [-Wint-conversion]

  if (!mach_addr_is_dmaable(state->user_buffer)) {
                            ~~~~~^~~~~~~~~~~~~
In file included from include/common.h:64,
                 from common/bouncebuf.c:8:
include/init.h:128:40: note: expected ‘long unsigned int’ but argument is of type ‘void *’
 int mach_addr_is_dmaable(unsigned long addr);
                          ~~~~~~~~~~~~~~^~~~
Quoted 6 lines
Quoted 1 line

Shouldn't the function use void __iomem * in the first place ?

IMHO Matter of taste.
If you prefer it this way, then I can change.
Doing grep "unsigned long addr" gave me enough confidence to use that. But I leave this up to you.

At least that's what Linux uses for mapped addresses.

Signature · 2 lines
Best regards,
Marek Vasut
#8 lore raw

PATCH 2/3 bouncebuf: Add DMA validation check to addr_aligned().

Quoted 59 lines · Marek Vasut
Quoted 58 lines · Christoph Müllner
Quoted 55 lines · Marek Vasut
Quoted 53 lines · Christoph Müllner
Quoted 30 lines · Christoph Müllner
Quoted 22 lines · Marek Vasut
Quoted 21 lines · Christoph Muellner

Currently addr_aligned() performs an alignment and a length check to validate the DMA address. However, some machines have stricter restrictions of DMA-able addresses.

This patch adds a call to mach_addr_is_dmaable() to honor this machine specific restrictions.

---

 common/bouncebuf.c | 6 ++++++
 1 file changed, 6 insertions(+)
common/bouncebuf.c +0 -0
index a7098e2caf..26ddf30ea2 100644
@@ -26,6 +26,12 @@ static int addr_aligned(struct bounce_buffer *state)
 		return 0;
 	}
 
Quoted 4 lines

common/bouncebuf.c static int addr_aligned(struct bounce_buffer *state) · line 30

Quoted 2 lines
common/bouncebuf.c +2 -0
+	/* Check if valid DMA address. */
+	if (!mach_addr_is_dmaable((ulong)state->user_buffer)) {

Is the cast necessary ?

Quoted 4 lines

Of course not.
Will be fixed in v2.

Thanks!

I take that back.
The cast is needed.
(And also done several times in this file)

Otherwise you will get:

common/bouncebuf.c: In function ‘addr_aligned’:
common/bouncebuf.c:35:33: warning: passing argument 1 of ‘mach_addr_is_dmaable’ makes integer from pointer without a cast [-Wint-conversion]

  if (!mach_addr_is_dmaable(state->user_buffer)) {
                            ~~~~~^~~~~~~~~~~~~
In file included from include/common.h:64,
                 from common/bouncebuf.c:8:
include/init.h:128:40: note: expected ‘long unsigned int’ but argument is of type ‘void *’
 int mach_addr_is_dmaable(unsigned long addr);
                          ~~~~~~~~~~~~~~^~~~
Quoted 8 lines
Quoted 6 lines
Quoted 1 line

Shouldn't the function use void __iomem * in the first place ?

IMHO Matter of taste.
If you prefer it this way, then I can change.
Doing grep "unsigned long addr" gave me enough confidence to use that. But I leave this up to you.

At least that's what Linux uses for mapped addresses.

In Linux two versions of that function are needed: one for phys_addr_t and one for void *. The linear mapping in U-Boot allows to combine both.
Therefore I see it as a matter of taste.

I will change this to "void __iomem *" and cast to uintptr_t in the rk3399 implementation of that function in a v2 series.

#9 lore raw

PATCH 2/3 bouncebuf: Add DMA validation check to addr_aligned().

Quoted 69 lines · Christoph Müllner
Quoted 66 lines · Marek Vasut
Quoted 64 lines · Christoph Müllner
Quoted 55 lines · Marek Vasut
Quoted 46 lines · Christoph Müllner
Quoted 30 lines · Christoph Müllner
Quoted 22 lines · Marek Vasut
Quoted 21 lines · Christoph Muellner

Currently addr_aligned() performs an alignment and a length check to validate the DMA address. However, some machines have stricter restrictions of DMA-able addresses.

This patch adds a call to mach_addr_is_dmaable() to honor this machine specific restrictions.

---

 common/bouncebuf.c | 6 ++++++
 1 file changed, 6 insertions(+)
common/bouncebuf.c +0 -0
index a7098e2caf..26ddf30ea2 100644
@@ -26,6 +26,12 @@ static int addr_aligned(struct bounce_buffer *state)
 		return 0;
 	}
 
Quoted 4 lines

common/bouncebuf.c static int addr_aligned(struct bounce_buffer *state) · line 30

Quoted 2 lines
common/bouncebuf.c +2 -0
+	/* Check if valid DMA address. */
+	if (!mach_addr_is_dmaable((ulong)state->user_buffer)) {

Is the cast necessary ?

Quoted 4 lines

Of course not.
Will be fixed in v2.

Thanks!

I take that back.
The cast is needed.
(And also done several times in this file)

Otherwise you will get:

common/bouncebuf.c: In function ‘addr_aligned’:
common/bouncebuf.c:35:33: warning: passing argument 1 of ‘mach_addr_is_dmaable’ makes integer from pointer without a cast [-Wint-conversion]

Quoted 7 lines
  if (!mach_addr_is_dmaable(state->user_buffer)) {
                            ~~~~~^~~~~~~~~~~~~
In file included from include/common.h:64,
                 from common/bouncebuf.c:8:
include/init.h:128:40: note: expected ‘long unsigned int’ but argument is of type ‘void *’
 int mach_addr_is_dmaable(unsigned long addr);
                          ~~~~~~~~~~~~~~^~~~
Quoted 1 line

Shouldn't the function use void __iomem * in the first place ?

IMHO Matter of taste.
If you prefer it this way, then I can change.
Doing grep "unsigned long addr" gave me enough confidence to use that. But I leave this up to you.

Quoted 8 lines
Quoted 1 line

At least that's what Linux uses for mapped addresses.

In Linux two versions of that function are needed: one for phys_addr_t and one for void *. The linear mapping in U-Boot allows to combine both.
Therefore I see it as a matter of taste.

I will change this to "void __iomem *" and cast to uintptr_t in the rk3399 implementation of that function in a v2 series.

Wait for more feedback please. Maybe someone has a more compelling argument for one or the other.

Signature · 2 lines
Best regards,
Marek Vasut
#10 lore raw

PATCH 2/3 bouncebuf: Add DMA validation check to addr_aligned().

Quoted 76 lines · Marek Vasut
Quoted 75 lines · Christoph Müllner
Quoted 59 lines · Marek Vasut
Quoted 58 lines · Christoph Müllner
Quoted 55 lines · Marek Vasut
Quoted 53 lines · Christoph Müllner
Quoted 30 lines · Christoph Müllner
Quoted 22 lines · Marek Vasut
Quoted 21 lines · Christoph Muellner

Currently addr_aligned() performs an alignment and a length check to validate the DMA address. However, some machines have stricter restrictions of DMA-able addresses.

This patch adds a call to mach_addr_is_dmaable() to honor this machine specific restrictions.

---

 common/bouncebuf.c | 6 ++++++
 1 file changed, 6 insertions(+)
common/bouncebuf.c +0 -0
index a7098e2caf..26ddf30ea2 100644
@@ -26,6 +26,12 @@ static int addr_aligned(struct bounce_buffer *state)
 		return 0;
 	}
 
Quoted 4 lines

common/bouncebuf.c static int addr_aligned(struct bounce_buffer *state) · line 30

Quoted 2 lines
common/bouncebuf.c +2 -0
+	/* Check if valid DMA address. */
+	if (!mach_addr_is_dmaable((ulong)state->user_buffer)) {

Is the cast necessary ?

Quoted 4 lines

Of course not.
Will be fixed in v2.

Thanks!

I take that back.
The cast is needed.
(And also done several times in this file)

Otherwise you will get:

common/bouncebuf.c: In function ‘addr_aligned’:
common/bouncebuf.c:35:33: warning: passing argument 1 of ‘mach_addr_is_dmaable’ makes integer from pointer without a cast [-Wint-conversion]

  if (!mach_addr_is_dmaable(state->user_buffer)) {
                            ~~~~~^~~~~~~~~~~~~
In file included from include/common.h:64,
                 from common/bouncebuf.c:8:
include/init.h:128:40: note: expected ‘long unsigned int’ but argument is of type ‘void *’
 int mach_addr_is_dmaable(unsigned long addr);
                          ~~~~~~~~~~~~~~^~~~
Quoted 8 lines
Quoted 6 lines
Quoted 1 line

Shouldn't the function use void __iomem * in the first place ?

IMHO Matter of taste.
If you prefer it this way, then I can change.
Doing grep "unsigned long addr" gave me enough confidence to use that. But I leave this up to you.

At least that's what Linux uses for mapped addresses.

In Linux two versions of that function are needed: one for phys_addr_t and one for void *. The linear mapping in U-Boot allows to combine both.
Therefore I see it as a matter of taste.

Quoted 5 lines
Quoted 2 lines

I will change this to "void __iomem *" and cast to uintptr_t in the rk3399 implementation of that function in a v2 series.

Wait for more feedback please. Maybe someone has a more compelling argument for one or the other.

Too late, but I have no fear from a v3.

#11 lore raw

PATCH 2/3 bouncebuf: Add DMA validation check to addr_aligned().

In reply to Christoph Muellner

Hi Christoph,

Quoted 5 lines · Christoph Muellner

Currently addr_aligned() performs an alignment and a length check to validate the DMA address. However, some machines have stricter restrictions of DMA-able addresses.

Quoted 8 lines

This patch adds a call to mach_addr_is_dmaable() to honor this machine specific restrictions.

---

 common/bouncebuf.c | 6 ++++++
 1 file changed, 6 insertions(+)

I feel like this should be handled with DM. Can we add a new method to the DMA uclass to check an address? If not provided by the DMA driver, we can assume the address is OK.

Regards,
Simon

#12 lore raw

PATCH 2/3 bouncebuf: Add DMA validation check to addr_aligned().【请注意,邮件由[email protected]代发】 addr_aligned().

Hi Simon,

Quoted 11 lines · Simon Glass

Hi Christoph,

Quoted 7 lines · Christoph Muellner

Currently addr_aligned() performs an alignment and a length check to validate the DMA address. However, some machines have stricter restrictions of DMA-able addresses.

This patch adds a call to mach_addr_is_dmaable() to honor this machine specific restrictions.

Quoted 8 lines
Quoted 5 lines

---

 common/bouncebuf.c | 6 ++++++
 1 file changed, 6 insertions(+)

I feel like this should be handled with DM. Can we add a new method to the DMA uclass to check an address? If not provided by the DMA driver, we can assume the address is OK.

The DMA in MMC controller which is not stand alone, do not using the driver of DMA uclass, so I'm afraid this is not able to using DMA uclass for this address check.

Thanks,
- Kever

Quoted 7 lines

Regards,
Simon
_______________________________________________
U-Boot mailing list
U-Boot at lists.denx.de
https://lists.denx.de/listinfo/u-boot

maintainer
#13 lore raw

PATCH 2/3 bouncebuf: Add DMA validation check to addr_aligned().【请注意,邮件由[email protected]代发】 addr_aligned().

Hi Simon,

Am Dienstag, 4. Juni 2019, 05:23:14 CEST schrieb Kever Yang:

Quoted 15 lines · Simon Glass
Quoted 14 lines
Quoted 12 lines · Christoph Muellner

Currently addr_aligned() performs an alignment and a length check to validate the DMA address. However, some machines have stricter restrictions of DMA-able addresses.

This patch adds a call to mach_addr_is_dmaable() to honor this machine specific restrictions.

---

 common/bouncebuf.c | 6 ++++++
 1 file changed, 6 insertions(+)
Quoted 7 lines
Quoted 3 lines

I feel like this should be handled with DM. Can we add a new method to the DMA uclass to check an address? If not provided by the DMA driver, we can assume the address is OK.

The DMA in MMC controller which is not stand alone, do not using the driver of DMA uclass, so I'm afraid this is not able to using DMA uclass for this address check.

were you able to consider Kever's response?

The issue bites us for example when the mmc-driver with its internal dma does transfer atf loadables to the socs sram. There is no system dma controller involved but so far we're experiencing this on _all_ Rockchip socs that need multiple parts of the ATF be written to different memory locations. (the sram code is obviously needed for suspend/resume).

Thanks
Heiko

#14 lore raw

PATCH 2/3 bouncebuf: Add DMA validation check to addr_aligned().【请注意,邮件由[email protected]代发】 addr_aligned().

Hi,

Quoted 27 lines · Heiko Stübner

Hi Simon,

Am Dienstag, 4. Juni 2019, 05:23:14 CEST schrieb Kever Yang:

Quoted 15 lines · Simon Glass
Quoted 14 lines
Quoted 12 lines · Christoph Muellner

Currently addr_aligned() performs an alignment and a length check to validate the DMA address. However, some machines have stricter restrictions of DMA-able addresses.

This patch adds a call to mach_addr_is_dmaable() to honor this machine specific restrictions.

---

 common/bouncebuf.c | 6 ++++++
 1 file changed, 6 insertions(+)
Quoted 7 lines
Quoted 3 lines

I feel like this should be handled with DM. Can we add a new method to the DMA uclass to check an address? If not provided by the DMA driver, we can assume the address is OK.

The DMA in MMC controller which is not stand alone, do not using the driver of DMA uclass, so I'm afraid this is not able to using DMA uclass for this address check.

Quoted 7 lines

were you able to consider Kever's response?

The issue bites us for example when the mmc-driver with its internal dma does transfer atf loadables to the socs sram. There is no system dma controller involved but so far we're experiencing this on _all_ Rockchip socs that need multiple parts of the ATF be written to different memory locations. (the sram code is obviously needed for suspend/resume).

I don't really understand the thing about the internal MMC DMA controller.

Is it not possible to call a DMA driver to validate an address, or to allocate an address? It isn't necessary to use the driver for a transfer.

But if this is related to DMA, then it seems to me that the DMA uclass should support the functionality, perhaps with a new method?

Regards,
Simon

maintainer
#15 lore raw

PATCH 2/3 bouncebuf: Add DMA validation check to addr_aligned().【请注意,邮件由[email protected]代发】 addr_aligned().

Hi Simon,

Am Samstag, 6. Juli 2019, 19:16:29 CEST schrieb Simon Glass:

Quoted 27 lines · Heiko Stübner
Quoted 26 lines

Am Dienstag, 4. Juni 2019, 05:23:14 CEST schrieb Kever Yang:

Quoted 15 lines · Simon Glass
Quoted 14 lines
Quoted 12 lines · Christoph Muellner

Currently addr_aligned() performs an alignment and a length check to validate the DMA address. However, some machines have stricter restrictions of DMA-able addresses.

This patch adds a call to mach_addr_is_dmaable() to honor this machine specific restrictions.

---

 common/bouncebuf.c | 6 ++++++
 1 file changed, 6 insertions(+)
Quoted 7 lines
Quoted 3 lines

I feel like this should be handled with DM. Can we add a new method to the DMA uclass to check an address? If not provided by the DMA driver, we can assume the address is OK.

The DMA in MMC controller which is not stand alone, do not using the driver of DMA uclass, so I'm afraid this is not able to using DMA uclass for this address check.

were you able to consider Kever's response?

Quoted 7 lines
Quoted 5 lines

The issue bites us for example when the mmc-driver with its internal dma does transfer atf loadables to the socs sram. There is no system dma controller involved but so far we're experiencing this on _all_ Rockchip socs that need multiple parts of the ATF be written to different memory locations. (the sram code is obviously needed for suspend/resume).

I don't really understand the thing about the internal MMC DMA controller.

The dw_mmc IP block can either be connected to a system-level dma controller (like a pl330 on for example the rk3188)
or have its own completely separate dma-controller _inside_ the dw-mmc ip-block itself (I think all newer Rockchip socs for example).

Quoted 3 lines

Is it not possible to call a DMA driver to validate an address, or to allocate an address? It isn't necessary to use the driver for a transfer.

For the internal-dma case, there really is no separate dma-driver involved, all is contained in dw-mmc.

On rk3288 on the kernel-side we also "just" blocked off the offending memory area due to all other approaches being cumbersome, with multiple IP blocks all bringing their own dma-controllers circumventing the system-level ones.

Quoted 2 lines

But if this is related to DMA, then it seems to me that the DMA uclass should support the functionality, perhaps with a new method?

So something like

	int dma_address_is_allowed(void *address);

which then calls into a system-specific function (or valus from Kconfig)? Or do you have something different in mind?

Thanks
Heiko

maintainer
#16 lore raw

PATCH 2/3 bouncebuf: Add DMA validation check to addr_aligned().【请注意,邮件由[email protected]代发】 addr_aligned().

Hi Simon,

just pulling up this thread again, as it would be great if we could resolve how to proceed here.

The important points regarding your questions are below.

Am Samstag, 6. Juli 2019, 20:04:52 CEST schrieb Heiko Stuebner:

Quoted 53 lines

Am Samstag, 6. Juli 2019, 19:16:29 CEST schrieb Simon Glass:

Quoted 27 lines · Heiko Stübner
Quoted 26 lines

Am Dienstag, 4. Juni 2019, 05:23:14 CEST schrieb Kever Yang:

Quoted 15 lines · Simon Glass
Quoted 14 lines
Quoted 12 lines · Christoph Muellner

Currently addr_aligned() performs an alignment and a length check to validate the DMA address. However, some machines have stricter restrictions of DMA-able addresses.

This patch adds a call to mach_addr_is_dmaable() to honor this machine specific restrictions.

---

 common/bouncebuf.c | 6 ++++++
 1 file changed, 6 insertions(+)
Quoted 7 lines
Quoted 3 lines

I feel like this should be handled with DM. Can we add a new method to the DMA uclass to check an address? If not provided by the DMA driver, we can assume the address is OK.

The DMA in MMC controller which is not stand alone, do not using the driver of DMA uclass, so I'm afraid this is not able to using DMA uclass for this address check.

were you able to consider Kever's response?

Quoted 7 lines
Quoted 5 lines

The issue bites us for example when the mmc-driver with its internal dma does transfer atf loadables to the socs sram. There is no system dma controller involved but so far we're experiencing this on _all_ Rockchip socs that need multiple parts of the ATF be written to different memory locations. (the sram code is obviously needed for suspend/resume).

I don't really understand the thing about the internal MMC DMA controller.

The dw_mmc IP block can either be connected to a system-level dma controller (like a pl330 on for example the rk3188)
or have its own completely separate dma-controller _inside_ the dw-mmc ip-block itself (I think all newer Rockchip socs for example).

Quoted 3 lines

Is it not possible to call a DMA driver to validate an address, or to allocate an address? It isn't necessary to use the driver for a transfer.

For the internal-dma case, there really is no separate dma-driver involved, all is contained in dw-mmc.

On rk3288 on the kernel-side we also "just" blocked off the offending memory area due to all other approaches being cumbersome, with multiple IP blocks all bringing their own dma-controllers circumventing the system-level ones.

Quoted 7 lines
Quoted 2 lines

But if this is related to DMA, then it seems to me that the DMA uclass should support the functionality, perhaps with a new method?

So something like

	int dma_address_is_allowed(void *address);

which then calls into a system-specific function (or valus from Kconfig)? Or do you have something different in mind?

Thanks
Heiko

#17 lore raw

PATCH 3/3 rk3399: Add restriction for DMA-able addresses.

In reply to Christoph Muellner

Patches on the U-Boot mailing list from Rockchip engineers indicate, that the RK3399's DMA engines are not able to use addresses in high-memory (above 0xf8000000).

This patch models this restriction in an RK3399 specific mach_addr_is_dmaable() function.

---

 arch/arm/mach-rockchip/rk3399/rk3399.c | 11 +++++++++++
 1 file changed, 11 insertions(+)
arch/arm/mach-rockchip/rk3399/rk3399.c +11 -0
index a7ccd4f3ed..15b03726eb 100644
@@ -109,3 +109,14 @@ void board_debug_uart_init(void)
 #endif
 }
 #endif
+
+int mach_addr_is_dmaable(unsigned long addr)
+{
+	/*
+	 * The RK3399 cannot cope with high-memory DMA target/sources.
+	 */
+	if (addr < 0xf8000000UL)
+		return 1;
+
+	return 0;
+}
Signature · 1 line
2.11.0
#18 lore raw

PATCH 3/3 rk3399: Add restriction for DMA-able addresses.

Hi Christoph,

Quoted 18 lines · Christoph Muellner

Patches on the U-Boot mailing list from Rockchip engineers indicate, that the RK3399's DMA engines are not able to use addresses in high-memory (above 0xf8000000).

This patch models this restriction in an RK3399 specific mach_addr_is_dmaable() function.

---

 arch/arm/mach-rockchip/rk3399/rk3399.c | 11 +++++++++++
 1 file changed, 11 insertions(+)
arch/arm/mach-rockchip/rk3399/rk3399.c +0 -0
index a7ccd4f3ed..15b03726eb 100644

arch/arm/mach-rockchip/rk3399/rk3399.c void board_debug_uart_init(void) · line 118

Quoted 10 lines
arch/arm/mach-rockchip/rk3399/rk3399.c +7 -0
@@ -109,3 +109,14 @@ void board_debug_uart_init(void)
 #endif
 }
 #endif
+
+int mach_addr_is_dmaable(unsigned long addr)
+{
+	/*
+	 * The RK3399 cannot cope with high-memory DMA target/sources.
+	 */
+	if (addr < 0xf8000000UL)

You'd better use SDRAM_MAX_SIZE instead of hard code, and this can re-used on all Rockchip platform.

Thanks,
- Kever

Quoted 4 lines
arch/arm/mach-rockchip/rk3399/rk3399.c +4 -0
+		return 1;
+
+	return 0;
+}
#19 lore raw

PATCH 1/3 board_f: Add mach specific DMA address check function.

In reply to Christoph Muellner

Hi Christoph,

Quoted 8 lines · Christoph Muellner

From: Christoph Müllner <[email protected]>

Some machines have limited DMA engines, which cannot deal with arbitrary addresses. This patch introduces a function to model these restrictions on a machine level.

Do you need all these two signed-off ?

Thanks,
- Kever

Quoted 32 lines

---

 common/board_f.c | 5 +++++
 include/init.h   | 2 ++
 2 files changed, 7 insertions(+)
common/board_f.c +5 -0
index 7ef20f2042..fed3c24373 100644
@@ -1053,3 +1053,8 @@ void board_init_f_r(void)
 	hang();
 }
 #endif /* CONFIG_X86 */
+
+__weak int mach_addr_is_dmaable(unsigned long addr)
+{
+	return 1;
+}
include/init.h +2 -0
index afc953d51e..18210a1489 100644
@@ -125,6 +125,8 @@ int misc_init_f(void);
 int embedded_dtb_select(void);
 #endif
 
+int mach_addr_is_dmaable(unsigned long addr);
+
 /* common/init/board_init.c */
 extern ulong monitor_flash_len;