From aa4e10d677dfe14c7e3132595558bcbf2fc25aca Mon Sep 17 00:00:00 2001
From: Phil Elwell <phil@raspberrypi.com>
Date: Mon, 26 Jul 2021 11:05:18 +0100
Subject: [PATCH] overlays: Set CMA to 512MB on Pi 4 for vc4

Pi 4s have at least 1GB, and there are advantages to having more CMA
available (HEVC works out of the box, support for more complex video
setups, etc.) without significant disadvantages.

Can be overridden by appending a parameter to the dtoverlay line, e.g.
dtoverlay=vc4-fkms-v3d,cma-256

Signed-off-by: Phil Elwell <phil@raspberrypi.com>
---
 arch/arm/boot/dts/overlays/Makefile           |  1 +
 arch/arm/boot/dts/overlays/README             | 17 +++++++
 arch/arm/boot/dts/overlays/overlay_map.dts    |  9 ++++
 .../dts/overlays/upstream-pi4-overlay.dts     |  2 +-
 .../dts/overlays/vc4-fkms-v3d-pi4-overlay.dts | 44 +++++++++++++++++++
 .../dts/overlays/vc4-kms-v3d-pi4-overlay.dts  |  6 ++-
 6 files changed, 77 insertions(+), 2 deletions(-)
 create mode 100644 arch/arm/boot/dts/overlays/vc4-fkms-v3d-pi4-overlay.dts

--- a/arch/arm/boot/dts/overlays/Makefile
+++ b/arch/arm/boot/dts/overlays/Makefile
@@ -220,6 +220,7 @@ dtbo-$(CONFIG_ARCH_BCM2835) += \
 	upstream.dtbo \
 	upstream-pi4.dtbo \
 	vc4-fkms-v3d.dtbo \
+	vc4-fkms-v3d-pi4.dtbo \
 	vc4-kms-dpi-at056tn53v1.dtbo \
 	vc4-kms-dsi-7inch.dtbo \
 	vc4-kms-dsi-lt070me05000.dtbo \
--- a/arch/arm/boot/dts/overlays/README
+++ b/arch/arm/boot/dts/overlays/README
@@ -3268,6 +3268,23 @@ Params: cma-512                 CMA is 5
         cma-default             Use upstream's default value
 
 
+Name:   vc4-fkms-v3d-pi4
+Info:   Enable Eric Anholt's DRM VC4 V3D driver on top of the dispmanx
+        display stack.
+Load:   dtoverlay=vc4-fkms-v3d-pi4,<param>
+Params: cma-512                 CMA is 512MB (needs 1GB)
+        cma-448                 CMA is 448MB (needs 1GB)
+        cma-384                 CMA is 384MB (needs 1GB)
+        cma-320                 CMA is 320MB (needs 1GB)
+        cma-256                 CMA is 256MB (needs 1GB)
+        cma-192                 CMA is 192MB (needs 1GB)
+        cma-128                 CMA is 128MB
+        cma-96                  CMA is 96MB
+        cma-64                  CMA is 64MB
+        cma-size                CMA size in bytes, 4MB aligned
+        cma-default             Use upstream's default value
+
+
 Name:   vc4-kms-dpi-at056tn53v1
 Info:   Enable an Innolux 5.6in VGA TFT connected to DPI interface under KMS.
         Requires vc4-kms-v3d to be loaded.
--- a/arch/arm/boot/dts/overlays/overlay_map.dts
+++ b/arch/arm/boot/dts/overlays/overlay_map.dts
@@ -138,6 +138,15 @@
 		bcm2711;
 	};
 
+	vc4-fkms-v3d {
+		bcm2835;
+		bcm2711 = "vc4-fkms-v3d-pi4";
+	};
+
+	vc4-fkms-v3d-pi4 {
+		bcm2711;
+	};
+
 	vc4-kms-v3d {
 		bcm2835;
 		bcm2711 = "vc4-kms-v3d-pi4";
--- a/arch/arm/boot/dts/overlays/upstream-pi4-overlay.dts
+++ b/arch/arm/boot/dts/overlays/upstream-pi4-overlay.dts
@@ -6,7 +6,7 @@
 #include <dt-bindings/clock/bcm2835.h>
 
 / {
-	compatible = "brcm,bcm2835";
+	compatible = "brcm,bcm2711";
 	fragment@0 {
 		target = <&ddc0>;
 		__overlay__ {
--- /dev/null
+++ b/arch/arm/boot/dts/overlays/vc4-fkms-v3d-pi4-overlay.dts
@@ -0,0 +1,44 @@
+/*
+ * vc4-fkms-v3d-overlay.dts
+ */
+
+/dts-v1/;
+/plugin/;
+
+#include "cma-overlay.dts"
+
+&frag0 {
+       size = <(512*1024*1024)>;
+};
+
+/ {
+	compatible = "brcm,bcm2711";
+
+	fragment@1 {
+		target = <&fb>;
+		__overlay__  {
+			status = "disabled";
+		};
+	};
+
+	fragment@2 {
+		target = <&firmwarekms>;
+		__overlay__  {
+			status = "okay";
+		};
+	};
+
+	fragment@3 {
+		target = <&v3d>;
+		__overlay__  {
+			status = "okay";
+		};
+	};
+
+	fragment@4 {
+		target = <&vc4>;
+		__overlay__  {
+			status = "okay";
+		};
+	};
+};
--- a/arch/arm/boot/dts/overlays/vc4-kms-v3d-pi4-overlay.dts
+++ b/arch/arm/boot/dts/overlays/vc4-kms-v3d-pi4-overlay.dts
@@ -9,8 +9,12 @@
 
 #include "cma-overlay.dts"
 
+&frag0 {
+       size = <(512*1024*1024)>;
+};
+
 / {
-	compatible = "brcm,bcm2835";
+	compatible = "brcm,bcm2711";
 
 	fragment@1 {
 		target = <&ddc0>;
