Skip to contentSkip to conversation

ARM: dts: sun8i: h3: orangepi-pc: Add CMA reserved memory node

PATCH In review Dmitry Osipenko 3 participants 6 messages Sep 14, 2022 – Oct 13, 2022

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 ARM: dts: sun8i: h3: orangepi-pc: Add CMA reserved memory node

Add 256MB CMA node to the Orange Pi PC board. This fixes memory allocation failures for Cedrus video decoder on trying to play a 1080p video with gstreamer.

---
 arch/arm/boot/dts/sun8i-h3-orangepi-pc.dts | 14 ++++++++++++++
 1 file changed, 14 insertions(+)
arch/arm/boot/dts/sun8i-h3-orangepi-pc.dts +14 -0
index b96e015f54ee..e655346a9fb4 100644
@@ -60,6 +60,20 @@ chosen {
 		stdout-path = "serial0:115200n8";
 	};
 
+	reserved-memory {
+		#address-cells = <1>;
+		#size-cells = <1>;
+		ranges;
+
+		linux,cma@40000000 {
+			compatible = "shared-dma-pool";
+			alloc-ranges = <0x40000000 0x40000000>;
+			size = <0x10000000>; /* 256MiB */
+			linux,cma-default;
+			reusable;
+		};
+	};
+
 	connector {
 		compatible = "hdmi-connector";
 		type = "a";
Signature · 1 line
2.37.3
#1 lore raw

Hi Dmitry,

Quoted 22 lines · Dmitry Osipenko

Add 256MB CMA node to the Orange Pi PC board. This fixes memory allocation failures for Cedrus video decoder on trying to play a 1080p video with gstreamer.

---
 arch/arm/boot/dts/sun8i-h3-orangepi-pc.dts | 14 ++++++++++++++
 1 file changed, 14 insertions(+)
arch/arm/boot/dts/sun8i-h3-orangepi-pc.dts +4 -0
index b96e015f54ee..e655346a9fb4 100644
@@ -60,6 +60,20 @@ chosen {
                stdout-path = "serial0:115200n8";
        };
 
+       reserved-memory {
+               #address-cells = <1>;
+               #size-cells = <1>;
+               ranges;

arch/arm/boot/dts/sun8i-h3-orangepi-pc.dts chosen { · line 76

Quoted 10 lines
arch/arm/boot/dts/sun8i-h3-orangepi-pc.dts +10 -0
+
+               linux,cma@40000000 {
+                       compatible = "shared-dma-pool";
+                       alloc-ranges = <0x40000000 0x40000000>;
+                       size = <0x10000000>; /* 256MiB */
+                       linux,cma-default;
+                       reusable;
+               };
+       };
+

This change seems legit for all H3 boards and could be moved to the H3 dtsi, no?

Regards,
Clement

Quoted 7 lines
arch/arm/boot/dts/sun8i-h3-orangepi-pc.dts +0 -1
        connector {
                compatible = "hdmi-connector";
                type = "a";
--

2.37.3

maintainer
#2 lore raw

Dne sreda, 14. september 2022 ob 17:33:27 CEST je Clément Péron napisal(a):

Quoted 35 lines

Hi Dmitry,

On Wed, 14 Sept 2022 at 17:12, Dmitry Osipenko

Quoted 30 lines · <[email protected]> wrote:

Add 256MB CMA node to the Orange Pi PC board. This fixes memory allocation failures for Cedrus video decoder on trying to play a 1080p video with gstreamer.

---

 arch/arm/boot/dts/sun8i-h3-orangepi-pc.dts | 14 ++++++++++++++
 1 file changed, 14 insertions(+)
(quoted diff) +0 -0

b/arch/arm/boot/dts/sun8i-h3-orangepi-pc.dts index b96e015f54ee..e655346a9fb4 100644

arch/arm/boot/dts/sun8i-h3-orangepi-pc.dts +9 -0
@@ -60,6 +60,20 @@ chosen {
 
                stdout-path = "serial0:115200n8";
 
        };
 
+       reserved-memory {
+               #address-cells = <1>;
+               #size-cells = <1>;
+               ranges;
+
+               linux,cma@40000000 {
+                       compatible = "shared-dma-pool";
+                       alloc-ranges = <0x40000000 0x40000000>;
+                       size = <0x10000000>; /* 256MiB */
Quoted 8 lines

arch/arm/boot/dts/sun8i-h3-orangepi-pc.dts chosen { · line 76

Quoted 5 lines
arch/arm/boot/dts/sun8i-h3-orangepi-pc.dts +5 -0
+                       linux,cma-default;
+                       reusable;
+               };
+       };
+

This change seems legit for all H3 boards and could be moved to the H3 dtsi, no?

That's true. However, there is a reason why this node doesn't exist. One or two H2+ boards (which use H3 dtsi) have only 256 MiB of RAM, so this can't work with them. A few H3 boards have 512 MiB of RAM, so you eat basically half of the RAM with that. Additionally, contrary to A20 and similar SoCs, which have such node, Cedrus can address whole RAM, so this is not strictly needed. It's better to leave this decision to distribution. Some don't care about Cedrus and some do a lot. Default size can be set via kernel config and it can be overriden by kernel argument if necessary.

Best regards,
Jernej

Quoted 11 lines

Regards,
Clement

Quoted 7 lines
arch/arm/boot/dts/sun8i-h3-orangepi-pc.dts +0 -0
        connector {
        
                compatible = "hdmi-connector";
                type = "a";

--
2.37.3

#3 lore raw

Hi,

Quoted 45 lines · Jernej Škrabec

Dne sreda, 14. september 2022 ob 17:33:27 CEST je Clément Péron napisal(a):

Quoted 35 lines

Hi Dmitry,

On Wed, 14 Sept 2022 at 17:12, Dmitry Osipenko

Quoted 30 lines · <[email protected]> wrote:

Add 256MB CMA node to the Orange Pi PC board. This fixes memory allocation failures for Cedrus video decoder on trying to play a 1080p video with gstreamer.

---

 arch/arm/boot/dts/sun8i-h3-orangepi-pc.dts | 14 ++++++++++++++
 1 file changed, 14 insertions(+)
(quoted diff) +0 -0

b/arch/arm/boot/dts/sun8i-h3-orangepi-pc.dts index b96e015f54ee..e655346a9fb4 100644

arch/arm/boot/dts/sun8i-h3-orangepi-pc.dts +9 -0
@@ -60,6 +60,20 @@ chosen {
 
                stdout-path = "serial0:115200n8";
 
        };
 
+       reserved-memory {
+               #address-cells = <1>;
+               #size-cells = <1>;
+               ranges;
+
+               linux,cma@40000000 {
+                       compatible = "shared-dma-pool";
+                       alloc-ranges = <0x40000000 0x40000000>;
+                       size = <0x10000000>; /* 256MiB */
Quoted 8 lines

arch/arm/boot/dts/sun8i-h3-orangepi-pc.dts chosen { · line 76

Quoted 5 lines
arch/arm/boot/dts/sun8i-h3-orangepi-pc.dts +5 -0
+                       linux,cma-default;
+                       reusable;
+               };
+       };
+

This change seems legit for all H3 boards and could be moved to the H3 dtsi, no?

Quoted 4 lines

That's true. However, there is a reason why this node doesn't exist. One or two H2+ boards (which use H3 dtsi) have only 256 MiB of RAM, so this can't work with them. A few H3 boards have 512 MiB of RAM, so you eat basically half of the RAM with that.

It's a "reusable" CMA, hence it won't be eaten. System is free to use the reusable CMA. In practice, CMA may get populated with a pinned pages over time, hence system will work fine, but CMA will get fragmented and this may cause problems for a larger CMA allocations.

The main problem with 512M boards should be that they may not have a suitable area for 256M CMA because it should be only either a low or high part of the memory that might be busy at a boot time, and then kernel will fail to boot.

Quoted 5 lines

Additionally, contrary to A20 and similar SoCs, which
have such node, Cedrus can address whole RAM, so this is not strictly needed. It's better to leave this decision to distribution. Some don't care about Cedrus and some do a lot. Default size can be set via kernel config and it can be overriden by kernel argument if necessary.

In my experience generic distributions usually don't care about particular boards/devices. They ship a multiplatform kernel using default config that has 64M for CMA and Cedrus doesn't work well with that.

BTW, the sunxi_defconfig doesn't specify CMA size at all, so it defaults to 16M.

Signature · 2 lines
Best regards,
Dmitry
maintainer
#4 lore raw

Hi,

Dne četrtek, 15. september 2022 ob 11:01:36 CEST je Dmitry Osipenko napisal(a):

Quoted 4 lines

Hi,

Quoted 1 line · Jernej Škrabec

Dne sreda, 14. september 2022 ob 17:33:27 CEST je Clément Péron

napisal(a):

Quoted 67 lines
Quoted 45 lines
Quoted 36 lines

Hi Dmitry,

On Wed, 14 Sept 2022 at 17:12, Dmitry Osipenko

Quoted 31 lines · <[email protected]> wrote:

Add 256MB CMA node to the Orange Pi PC board. This fixes memory allocation
failures for Cedrus video decoder on trying to play a 1080p video with gstreamer.

---

 arch/arm/boot/dts/sun8i-h3-orangepi-pc.dts | 14 ++++++++++++++
 1 file changed, 14 insertions(+)
(quoted diff) +0 -0

b/arch/arm/boot/dts/sun8i-h3-orangepi-pc.dts index b96e015f54ee..e655346a9fb4 100644

arch/arm/boot/dts/sun8i-h3-orangepi-pc.dts +9 -0
@@ -60,6 +60,20 @@ chosen {
 
                stdout-path = "serial0:115200n8";
 
        };
 
+       reserved-memory {
+               #address-cells = <1>;
+               #size-cells = <1>;
+               ranges;
+
+               linux,cma@40000000 {
+                       compatible = "shared-dma-pool";
+                       alloc-ranges = <0x40000000 0x40000000>;
+                       size = <0x10000000>; /* 256MiB */
Quoted 8 lines

arch/arm/boot/dts/sun8i-h3-orangepi-pc.dts chosen { · line 76

Quoted 5 lines
arch/arm/boot/dts/sun8i-h3-orangepi-pc.dts +5 -0
+                       linux,cma-default;
+                       reusable;
+               };
+       };
+

This change seems legit for all H3 boards and could be moved to the H3 dtsi, no?

Quoted 5 lines

That's true. However, there is a reason why this node doesn't exist. One or
two H2+ boards (which use H3 dtsi) have only 256 MiB of RAM, so this can't work with them. A few H3 boards have 512 MiB of RAM, so you eat basically half of the RAM with that.

It's a "reusable" CMA, hence it won't be eaten. System is free to use the reusable CMA. In practice, CMA may get populated with a pinned pages over time, hence system will work fine, but CMA will get fragmented and this may cause problems for a larger CMA allocations.

The main problem with 512M boards should be that they may not have a suitable area for 256M CMA because it should be only either a low or high part of the memory that might be busy at a boot time, and then kernel will fail to boot.

Quoted 5 lines

Additionally, contrary to A20 and similar SoCs, which
have such node, Cedrus can address whole RAM, so this is not strictly needed. It's better to leave this decision to distribution. Some don't care about Cedrus and some do a lot. Default size can be set via kernel config and it can be overriden by kernel argument if necessary.

Quoted 3 lines

In my experience generic distributions usually don't care about particular boards/devices. They ship a multiplatform kernel using default config that has 64M for CMA and Cedrus doesn't work well with that.

It still can be overriden using cma= kernel argument.

Quoted 3 lines

BTW, the sunxi_defconfig doesn't specify CMA size at all, so it defaults to 16M.

That can be easily changed, someone just need to send patch. Historically, from A20 times, default choice for CMA size was 96 MiB. Good choice, and in my opinion also maximum, is 128 MiB. That's enough for 1080p. 256 MiB is really only needed for 4k content, which only H3 and its variants support, from what I can tell.

Best regards,
Jernej

#5 lore raw
Quoted 76 lines · Jernej Škrabec

Hi,

Dne četrtek, 15. september 2022 ob 11:01:36 CEST je Dmitry Osipenko napisal(a):

Quoted 4 lines

Hi,

Quoted 1 line · Jernej Škrabec

Dne sreda, 14. september 2022 ob 17:33:27 CEST je Clément Péron

napisal(a):

Quoted 67 lines
Quoted 45 lines
Quoted 36 lines

Hi Dmitry,

On Wed, 14 Sept 2022 at 17:12, Dmitry Osipenko

Quoted 31 lines · <[email protected]> wrote:

Add 256MB CMA node to the Orange Pi PC board. This fixes memory allocation
failures for Cedrus video decoder on trying to play a 1080p video with gstreamer.

---

 arch/arm/boot/dts/sun8i-h3-orangepi-pc.dts | 14 ++++++++++++++
 1 file changed, 14 insertions(+)
(quoted diff) +0 -0

b/arch/arm/boot/dts/sun8i-h3-orangepi-pc.dts index b96e015f54ee..e655346a9fb4 100644

arch/arm/boot/dts/sun8i-h3-orangepi-pc.dts +9 -0
@@ -60,6 +60,20 @@ chosen {
 
                stdout-path = "serial0:115200n8";
 
        };
 
+       reserved-memory {
+               #address-cells = <1>;
+               #size-cells = <1>;
+               ranges;
+
+               linux,cma@40000000 {
+                       compatible = "shared-dma-pool";
+                       alloc-ranges = <0x40000000 0x40000000>;
+                       size = <0x10000000>; /* 256MiB */
Quoted 8 lines

arch/arm/boot/dts/sun8i-h3-orangepi-pc.dts chosen { · line 76

Quoted 5 lines
arch/arm/boot/dts/sun8i-h3-orangepi-pc.dts +5 -0
+                       linux,cma-default;
+                       reusable;
+               };
+       };
+

This change seems legit for all H3 boards and could be moved to the H3 dtsi, no?

Quoted 5 lines

That's true. However, there is a reason why this node doesn't exist. One or
two H2+ boards (which use H3 dtsi) have only 256 MiB of RAM, so this can't work with them. A few H3 boards have 512 MiB of RAM, so you eat basically half of the RAM with that.

It's a "reusable" CMA, hence it won't be eaten. System is free to use the reusable CMA. In practice, CMA may get populated with a pinned pages over time, hence system will work fine, but CMA will get fragmented and this may cause problems for a larger CMA allocations.

The main problem with 512M boards should be that they may not have a suitable area for 256M CMA because it should be only either a low or high part of the memory that might be busy at a boot time, and then kernel will fail to boot.

Quoted 5 lines

Additionally, contrary to A20 and similar SoCs, which
have such node, Cedrus can address whole RAM, so this is not strictly needed. It's better to leave this decision to distribution. Some don't care about Cedrus and some do a lot. Default size can be set via kernel config and it can be overriden by kernel argument if necessary.

Quoted 5 lines
Quoted 3 lines

In my experience generic distributions usually don't care about particular boards/devices. They ship a multiplatform kernel using default config that has 64M for CMA and Cedrus doesn't work well with that.

It still can be overriden using cma= kernel argument.

The point of the DT change is to make system usable out-of-the-box for casual (non kernel developer) users.

Quoted 8 lines
Quoted 2 lines

BTW, the sunxi_defconfig doesn't specify CMA size at all, so it defaults to 16M.

That can be easily changed, someone just need to send patch. Historically, from A20 times, default choice for CMA size was 96 MiB. Good choice, and in my opinion also maximum, is 128 MiB. That's enough for 1080p. 256 MiB is really only needed for 4k content, which only H3 and its variants support, from what I can tell.

128M wasn't enough for playing 1080p h265 big_bug_bunny. Practically it doesn't matter how big CMA area is, as long as it's "shared".

In my experience 256M CMA is a good choice for devices with 1G RAM. Bigger CMA may cause problems for initrd, depending on a bootlaoder version.

Signature · 2 lines
Best regards,
Dmitry