From 8b3892d7b5fdafa0847df2d55008ef51af9679b5 Mon Sep 17 00:00:00 2001 From: Dezhi Kong Date: Fri, 19 Mar 2021 16:23:10 +0800 Subject: [PATCH] ion: add fb heap for hw-fb [1/1] PD#SWPL-45003 Problem: hw-fb may alloc fail from cma heap, which will result in display messed up Solution: add a separate ion fb heap only used for HW_FB Verify: sm1-newton-ac214 g12a-franklin-u212 Change-Id: I154fe5c61ad1c92cfc652234a093090284c4d2f3 Signed-off-by: Dezhi Kong --- arch/arm64/boot/dts/amlogic/g12a_pxp.dts | 7 + .../boot/dts/amlogic/g12a_s905d2_skt.dts | 7 + .../dts/amlogic/g12a_s905d2_skt_buildroot.dts | 7 + .../boot/dts/amlogic/g12a_s905d2_u200.dts | 7 + .../boot/dts/amlogic/g12a_s905d2_u200_1g.dts | 7 + .../amlogic/g12a_s905d2_u200_buildroot.dts | 7 + .../g12a_s905d2_u200_buildroot_vccktest.dts | 7 + .../g12a_s905d2_u200_drm_buildroot.dts | 7 + .../boot/dts/amlogic/g12a_s905d2_u202.dts | 7 + .../boot/dts/amlogic/g12a_s905d2_u202_1g.dts | 7 + .../boot/dts/amlogic/g12a_s905x2_u211.dts | 7 + .../boot/dts/amlogic/g12a_s905x2_u211_1g.dts | 7 + .../dts/amlogic/g12a_s905x2_u211_512m.dts | 7 + .../amlogic/g12a_s905x2_u211_buildroot.dts | 7 + .../boot/dts/amlogic/g12a_s905x2_u212.dts | 7 + .../boot/dts/amlogic/g12a_s905x2_u212_1g.dts | 7 + .../amlogic/g12a_s905x2_u212_buildroot.dts | 7 + .../g12a_s905x2_u212_drm_buildroot.dts | 7 + .../boot/dts/amlogic/g12a_s905x2_u215.dts | 7 + .../boot/dts/amlogic/g12a_s905y2_deadpool.dts | 7 + .../boot/dts/amlogic/g12a_s905y2_u220.dts | 7 + .../boot/dts/amlogic/g12a_s905y2_u221.dts | 7 + .../boot/dts/amlogic/g12a_s905y2_u223_lp.dts | 7 + arch/arm64/boot/dts/amlogic/mesong12a.dtsi | 3 +- .../boot/dts/amlogic/mesong12a_deadpool.dtsi | 3 +- arch/arm64/boot/dts/amlogic/mesong12b.dtsi | 2 +- arch/arm64/boot/dts/amlogic/mesonsm1.dtsi | 3 +- arch/arm64/boot/dts/amlogic/sm1_pxp.dts | 7 + .../boot/dts/amlogic/sm1_s905c1_ac232.dts | 7 + .../boot/dts/amlogic/sm1_s905d3_ac200.dts | 7 + .../amlogic/sm1_s905d3_ac200_buildroot.dts | 7 + .../sm1_s905d3_ac200_drm_buildroot.dts | 7 + .../boot/dts/amlogic/sm1_s905d3_ac202.dts | 7 + .../boot/dts/amlogic/sm1_s905d3_ac202_1g.dts | 7 + .../arm64/boot/dts/amlogic/sm1_s905d3_skt.dts | 7 + .../boot/dts/amlogic/sm1_s905x3_ac212.dts | 7 + .../boot/dts/amlogic/sm1_s905x3_ac213.dts | 7 + .../amlogic/sm1_s905x3_ac213_buildroot.dts | 7 + .../sm1_s905x3_ac213_drm_buildroot.dts | 7 + .../boot/dts/amlogic/sm1_s905x3_ac214.dts | 7 + .../amlogic/sm1_s905x3_ac214_buildroot.dts | 7 + .../sm1_s905x3_ac214_drm_buildroot.dts | 7 + .../boot/dts/amlogic/sm1_s905x3_ac215.dts | 7 + .../boot/dts/amlogic/sm1_s905y3_ac223.dts | 7 + .../boot/dts/amlogic/sm1_s905y3_deadpool.dts | 9 +- .../amlogic/media/common/ion_dev/dev_ion.c | 119 ++++++++++--- .../amlogic/media/common/ion_dev/meson_ion.h | 2 +- drivers/staging/android/ion/Makefile | 2 +- drivers/staging/android/ion/ion_fb_heap.c | 163 ++++++++++++++++++ drivers/staging/android/ion/ion_heap.c | 14 +- drivers/staging/android/ion/ion_priv.h | 8 + drivers/staging/android/ion/ion_secure_heap.c | 159 +++++++++++++++++ 52 files changed, 732 insertions(+), 35 deletions(-) create mode 100644 drivers/staging/android/ion/ion_fb_heap.c create mode 100644 drivers/staging/android/ion/ion_secure_heap.c diff --git a/arch/arm64/boot/dts/amlogic/g12a_pxp.dts b/arch/arm64/boot/dts/amlogic/g12a_pxp.dts index 835eaaf8f2d2..6ea6951c3ade 100644 --- a/arch/arm64/boot/dts/amlogic/g12a_pxp.dts +++ b/arch/arm64/boot/dts/amlogic/g12a_pxp.dts @@ -72,6 +72,13 @@ size = <0x0 0x8000000>; alignment = <0x0 0x400000>; }; + ion_fb_reserved:linux,ion-fb { + compatible = "amlogic, ion-fb-mem"; + reusable; + /* 1920x1080x4x3 round up 4M align */ + size = <0x0 0x1c00000>; + alignment = <0x0 0x400000>; + }; //di_reserved:linux,di { //compatible = "amlogic, di-mem"; diff --git a/arch/arm64/boot/dts/amlogic/g12a_s905d2_skt.dts b/arch/arm64/boot/dts/amlogic/g12a_s905d2_skt.dts index 24f091d2a16f..833ff4e32caa 100644 --- a/arch/arm64/boot/dts/amlogic/g12a_s905d2_skt.dts +++ b/arch/arm64/boot/dts/amlogic/g12a_s905d2_skt.dts @@ -89,6 +89,13 @@ size = <0x0 0x8000000>; alignment = <0x0 0x400000>; }; + ion_fb_reserved:linux,ion-fb { + compatible = "amlogic, ion-fb-mem"; + reusable; + /* 1920x1080x4x3 round up 4M align */ + size = <0x0 0x1c00000>; + alignment = <0x0 0x400000>; + }; //di_reserved:linux,di { //compatible = "amlogic, di-mem"; /* buffer_size = 3621952(yuv422 8bit) */ diff --git a/arch/arm64/boot/dts/amlogic/g12a_s905d2_skt_buildroot.dts b/arch/arm64/boot/dts/amlogic/g12a_s905d2_skt_buildroot.dts index 23e7685d5e14..648bcac95951 100644 --- a/arch/arm64/boot/dts/amlogic/g12a_s905d2_skt_buildroot.dts +++ b/arch/arm64/boot/dts/amlogic/g12a_s905d2_skt_buildroot.dts @@ -80,6 +80,13 @@ size = <0x0 0x8000000>; alignment = <0x0 0x400000>; }; + ion_fb_reserved:linux,ion-fb { + compatible = "amlogic, ion-fb-mem"; + reusable; + /* 1920x1080x4x3 round up 4M align */ + size = <0x0 0x0000000>; + alignment = <0x0 0x400000>; + }; //di_reserved:linux,di { //compatible = "amlogic, di-mem"; /* buffer_size = 3621952(yuv422 8bit) */ diff --git a/arch/arm64/boot/dts/amlogic/g12a_s905d2_u200.dts b/arch/arm64/boot/dts/amlogic/g12a_s905d2_u200.dts index 3345ea38a142..8c227464abe5 100644 --- a/arch/arm64/boot/dts/amlogic/g12a_s905d2_u200.dts +++ b/arch/arm64/boot/dts/amlogic/g12a_s905d2_u200.dts @@ -90,6 +90,13 @@ size = <0x0 0x8000000>; alignment = <0x0 0x400000>; }; + ion_fb_reserved:linux,ion-fb { + compatible = "amlogic, ion-fb-mem"; + reusable; + /* 1920x1080x4x3 round up 4M align */ + size = <0x0 0x1c00000>; + alignment = <0x0 0x400000>; + }; //di_reserved:linux,di { //compatible = "amlogic, di-mem"; /* buffer_size = 3621952(yuv422 8bit) */ diff --git a/arch/arm64/boot/dts/amlogic/g12a_s905d2_u200_1g.dts b/arch/arm64/boot/dts/amlogic/g12a_s905d2_u200_1g.dts index ae87a57ec600..d779630ddc95 100644 --- a/arch/arm64/boot/dts/amlogic/g12a_s905d2_u200_1g.dts +++ b/arch/arm64/boot/dts/amlogic/g12a_s905d2_u200_1g.dts @@ -89,6 +89,13 @@ size = <0x0 0x8000000>; alignment = <0x0 0x400000>; }; + ion_fb_reserved:linux,ion-fb { + compatible = "amlogic, ion-fb-mem"; + reusable; + /* 1920x1080x4x3 round up 4M align */ + size = <0x0 0x1c00000>; + alignment = <0x0 0x400000>; + }; //di_reserved:linux,di { //compatible = "amlogic, di-mem"; /* buffer_size = 3621952(yuv422 8bit) */ diff --git a/arch/arm64/boot/dts/amlogic/g12a_s905d2_u200_buildroot.dts b/arch/arm64/boot/dts/amlogic/g12a_s905d2_u200_buildroot.dts index 91a21cd8ad76..c508bfa6a616 100644 --- a/arch/arm64/boot/dts/amlogic/g12a_s905d2_u200_buildroot.dts +++ b/arch/arm64/boot/dts/amlogic/g12a_s905d2_u200_buildroot.dts @@ -79,6 +79,13 @@ size = <0x0 0x8000000>; alignment = <0x0 0x400000>; }; + ion_fb_reserved:linux,ion-fb { + compatible = "amlogic, ion-fb-mem"; + reusable; + /* 1920x1080x4x3 round up 4M align */ + size = <0x0 0x0000000>; + alignment = <0x0 0x400000>; + }; //di_reserved:linux,di { //compatible = "amlogic, di-mem"; /* buffer_size = 3621952(yuv422 8bit) */ diff --git a/arch/arm64/boot/dts/amlogic/g12a_s905d2_u200_buildroot_vccktest.dts b/arch/arm64/boot/dts/amlogic/g12a_s905d2_u200_buildroot_vccktest.dts index d8e6c99c84e2..6524fff3a137 100644 --- a/arch/arm64/boot/dts/amlogic/g12a_s905d2_u200_buildroot_vccktest.dts +++ b/arch/arm64/boot/dts/amlogic/g12a_s905d2_u200_buildroot_vccktest.dts @@ -78,6 +78,13 @@ size = <0x0 0x8000000>; alignment = <0x0 0x400000>; }; + ion_fb_reserved:linux,ion-fb { + compatible = "amlogic, ion-fb-mem"; + reusable; + /* 1920x1080x4x3 round up 4M align */ + size = <0x0 0x0000000>; + alignment = <0x0 0x400000>; + }; //di_reserved:linux,di { //compatible = "amlogic, di-mem"; /* buffer_size = 3621952(yuv422 8bit) */ diff --git a/arch/arm64/boot/dts/amlogic/g12a_s905d2_u200_drm_buildroot.dts b/arch/arm64/boot/dts/amlogic/g12a_s905d2_u200_drm_buildroot.dts index c1fb6235dcda..805f0abf9c85 100644 --- a/arch/arm64/boot/dts/amlogic/g12a_s905d2_u200_drm_buildroot.dts +++ b/arch/arm64/boot/dts/amlogic/g12a_s905d2_u200_drm_buildroot.dts @@ -80,6 +80,13 @@ alignment = <0x0 0x400000>; no-kernel-map; }; + ion_fb_reserved:linux,ion-fb { + compatible = "amlogic, ion-fb-mem"; + reusable; + /* 1920x1080x4x3 round up 4M align */ + size = <0x0 0x0000000>; + alignment = <0x0 0x400000>; + }; //di_reserved:linux,di { //compatible = "amlogic, di-mem"; /* buffer_size = 3621952(yuv422 8bit) */ diff --git a/arch/arm64/boot/dts/amlogic/g12a_s905d2_u202.dts b/arch/arm64/boot/dts/amlogic/g12a_s905d2_u202.dts index 3178f066a421..f120dd640245 100644 --- a/arch/arm64/boot/dts/amlogic/g12a_s905d2_u202.dts +++ b/arch/arm64/boot/dts/amlogic/g12a_s905d2_u202.dts @@ -90,6 +90,13 @@ size = <0x0 0x8000000>; alignment = <0x0 0x400000>; }; + ion_fb_reserved:linux,ion-fb { + compatible = "amlogic, ion-fb-mem"; + reusable; + /* 1920x1080x4x3 round up 4M align */ + size = <0x0 0x1c00000>; + alignment = <0x0 0x400000>; + }; //di_reserved:linux,di { //compatible = "amlogic, di-mem"; /* buffer_size = 3621952(yuv422 8bit) */ diff --git a/arch/arm64/boot/dts/amlogic/g12a_s905d2_u202_1g.dts b/arch/arm64/boot/dts/amlogic/g12a_s905d2_u202_1g.dts index f78381b7a859..d28d80cb6d18 100644 --- a/arch/arm64/boot/dts/amlogic/g12a_s905d2_u202_1g.dts +++ b/arch/arm64/boot/dts/amlogic/g12a_s905d2_u202_1g.dts @@ -89,6 +89,13 @@ size = <0x0 0x8000000>; alignment = <0x0 0x400000>; }; + ion_fb_reserved:linux,ion-fb { + compatible = "amlogic, ion-fb-mem"; + reusable; + /* 1920x1080x4x3 round up 4M align */ + size = <0x0 0x1c00000>; + alignment = <0x0 0x400000>; + }; //di_reserved:linux,di { //compatible = "amlogic, di-mem"; /* buffer_size = 3621952(yuv422 8bit) */ diff --git a/arch/arm64/boot/dts/amlogic/g12a_s905x2_u211.dts b/arch/arm64/boot/dts/amlogic/g12a_s905x2_u211.dts index 8189207680ac..a18c7aab1fb5 100644 --- a/arch/arm64/boot/dts/amlogic/g12a_s905x2_u211.dts +++ b/arch/arm64/boot/dts/amlogic/g12a_s905x2_u211.dts @@ -88,6 +88,13 @@ size = <0x0 0x8000000>; alignment = <0x0 0x400000>; }; + ion_fb_reserved:linux,ion-fb { + compatible = "amlogic, ion-fb-mem"; + reusable; + /* 1920x1080x4x3 round up 4M align */ + size = <0x0 0x1c00000>; + alignment = <0x0 0x400000>; + }; //di_reserved:linux,di { //compatible = "amlogic, di-mem"; /* buffer_size = 3621952(yuv422 8bit) */ diff --git a/arch/arm64/boot/dts/amlogic/g12a_s905x2_u211_1g.dts b/arch/arm64/boot/dts/amlogic/g12a_s905x2_u211_1g.dts index 0497f61fdee2..4c3144681a81 100644 --- a/arch/arm64/boot/dts/amlogic/g12a_s905x2_u211_1g.dts +++ b/arch/arm64/boot/dts/amlogic/g12a_s905x2_u211_1g.dts @@ -89,6 +89,13 @@ size = <0x0 0x8000000>; alignment = <0x0 0x400000>; }; + ion_fb_reserved:linux,ion-fb { + compatible = "amlogic, ion-fb-mem"; + reusable; + /* 1920x1080x4x3 round up 4M align */ + size = <0x0 0x1c00000>; + alignment = <0x0 0x400000>; + }; //di_reserved:linux,di { //compatible = "amlogic, di-mem"; /* buffer_size = 3621952(yuv422 8bit) */ diff --git a/arch/arm64/boot/dts/amlogic/g12a_s905x2_u211_512m.dts b/arch/arm64/boot/dts/amlogic/g12a_s905x2_u211_512m.dts index f709085a25f8..2348bc323d78 100644 --- a/arch/arm64/boot/dts/amlogic/g12a_s905x2_u211_512m.dts +++ b/arch/arm64/boot/dts/amlogic/g12a_s905x2_u211_512m.dts @@ -87,6 +87,13 @@ size = <0x0 0x4000000>; alignment = <0x0 0x400000>; }; + ion_fb_reserved:linux,ion-fb { + compatible = "amlogic, ion-fb-mem"; + reusable; + /* 1920x1080x4x3 round up 4M align */ + size = <0x0 0x1c00000>; + alignment = <0x0 0x400000>; + }; //di_reserved:linux,di { //compatible = "amlogic, di-mem"; /* buffer_size = 3621952(yuv422 8bit) */ diff --git a/arch/arm64/boot/dts/amlogic/g12a_s905x2_u211_buildroot.dts b/arch/arm64/boot/dts/amlogic/g12a_s905x2_u211_buildroot.dts index 0c6d713e062e..8f424fe722cd 100644 --- a/arch/arm64/boot/dts/amlogic/g12a_s905x2_u211_buildroot.dts +++ b/arch/arm64/boot/dts/amlogic/g12a_s905x2_u211_buildroot.dts @@ -79,6 +79,13 @@ size = <0x0 0x8000000>; alignment = <0x0 0x400000>; }; + ion_fb_reserved:linux,ion-fb { + compatible = "amlogic, ion-fb-mem"; + reusable; + /* 1920x1080x4x3 round up 4M align */ + size = <0x0 0x0000000>; + alignment = <0x0 0x400000>; + }; //di_reserved:linux,di { //compatible = "amlogic, di-mem"; /* buffer_size = 3621952(yuv422 8bit) */ diff --git a/arch/arm64/boot/dts/amlogic/g12a_s905x2_u212.dts b/arch/arm64/boot/dts/amlogic/g12a_s905x2_u212.dts index 5facc00af93f..57c7d0f674e0 100644 --- a/arch/arm64/boot/dts/amlogic/g12a_s905x2_u212.dts +++ b/arch/arm64/boot/dts/amlogic/g12a_s905x2_u212.dts @@ -88,6 +88,13 @@ size = <0x0 0x8000000>; alignment = <0x0 0x400000>; }; + ion_fb_reserved:linux,ion-fb { + compatible = "amlogic, ion-fb-mem"; + reusable; + /* 1920x1080x4x3 round up 4M align */ + size = <0x0 0x1c00000>; + alignment = <0x0 0x400000>; + }; //di_reserved:linux,di { //compatible = "amlogic, di-mem"; /* buffer_size = 3621952(yuv422 8bit) */ diff --git a/arch/arm64/boot/dts/amlogic/g12a_s905x2_u212_1g.dts b/arch/arm64/boot/dts/amlogic/g12a_s905x2_u212_1g.dts index ddc34d373259..397ccfcbb940 100644 --- a/arch/arm64/boot/dts/amlogic/g12a_s905x2_u212_1g.dts +++ b/arch/arm64/boot/dts/amlogic/g12a_s905x2_u212_1g.dts @@ -89,6 +89,13 @@ size = <0x0 0x4C00000>; alignment = <0x0 0x400000>; }; + ion_fb_reserved:linux,ion-fb { + compatible = "amlogic, ion-fb-mem"; + reusable; + /* 1920x1080x4x3 round up 4M align */ + size = <0x0 0x1c00000>; + alignment = <0x0 0x400000>; + }; //di_reserved:linux,di { //compatible = "amlogic, di-mem"; /* buffer_size = 3621952(yuv422 8bit) */ diff --git a/arch/arm64/boot/dts/amlogic/g12a_s905x2_u212_buildroot.dts b/arch/arm64/boot/dts/amlogic/g12a_s905x2_u212_buildroot.dts index 99b3457060c0..6d419f665f0a 100644 --- a/arch/arm64/boot/dts/amlogic/g12a_s905x2_u212_buildroot.dts +++ b/arch/arm64/boot/dts/amlogic/g12a_s905x2_u212_buildroot.dts @@ -78,6 +78,13 @@ size = <0x0 0x8000000>; alignment = <0x0 0x400000>; }; + ion_fb_reserved:linux,ion-fb { + compatible = "amlogic, ion-fb-mem"; + reusable; + /* 1920x1080x4x3 round up 4M align */ + size = <0x0 0x0000000>; + alignment = <0x0 0x400000>; + }; //di_reserved:linux,di { //compatible = "amlogic, di-mem"; /* buffer_size = 3621952(yuv422 8bit) */ diff --git a/arch/arm64/boot/dts/amlogic/g12a_s905x2_u212_drm_buildroot.dts b/arch/arm64/boot/dts/amlogic/g12a_s905x2_u212_drm_buildroot.dts index bfdb4b973e69..d1e71a1ace91 100644 --- a/arch/arm64/boot/dts/amlogic/g12a_s905x2_u212_drm_buildroot.dts +++ b/arch/arm64/boot/dts/amlogic/g12a_s905x2_u212_drm_buildroot.dts @@ -80,6 +80,13 @@ alignment = <0x0 0x400000>; no-kernel-map; }; + ion_fb_reserved:linux,ion-fb { + compatible = "amlogic, ion-fb-mem"; + reusable; + /* 1920x1080x4x3 round up 4M align */ + size = <0x0 0x0000000>; + alignment = <0x0 0x400000>; + }; //di_reserved:linux,di { //compatible = "amlogic, di-mem"; /* buffer_size = 3621952(yuv422 8bit) */ diff --git a/arch/arm64/boot/dts/amlogic/g12a_s905x2_u215.dts b/arch/arm64/boot/dts/amlogic/g12a_s905x2_u215.dts index 0932cd547650..c3767fecd1eb 100644 --- a/arch/arm64/boot/dts/amlogic/g12a_s905x2_u215.dts +++ b/arch/arm64/boot/dts/amlogic/g12a_s905x2_u215.dts @@ -88,6 +88,13 @@ size = <0x0 0x8000000>; alignment = <0x0 0x400000>; }; + ion_fb_reserved:linux,ion-fb { + compatible = "amlogic, ion-fb-mem"; + reusable; + /* 1920x1080x4x3 round up 4M align */ + size = <0x0 0x1c00000>; + alignment = <0x0 0x400000>; + }; //di_reserved:linux,di { //compatible = "amlogic, di-mem"; /* buffer_size = 3621952(yuv422 8bit) */ diff --git a/arch/arm64/boot/dts/amlogic/g12a_s905y2_deadpool.dts b/arch/arm64/boot/dts/amlogic/g12a_s905y2_deadpool.dts index 46ce7a23626a..94347f68c550 100644 --- a/arch/arm64/boot/dts/amlogic/g12a_s905y2_deadpool.dts +++ b/arch/arm64/boot/dts/amlogic/g12a_s905y2_deadpool.dts @@ -87,6 +87,13 @@ size = <0x0 0x8000000>; alignment = <0x0 0x400000>; }; + ion_fb_reserved:linux,ion-fb { + compatible = "amlogic, ion-fb-mem"; + reusable; + /* 1920x1080x4x3 round up 4M align */ + size = <0x0 0x1c00000>; + alignment = <0x0 0x400000>; + }; //di_reserved:linux,di { //compatible = "amlogic, di-mem"; /* buffer_size = 3621952(yuv422 8bit) */ diff --git a/arch/arm64/boot/dts/amlogic/g12a_s905y2_u220.dts b/arch/arm64/boot/dts/amlogic/g12a_s905y2_u220.dts index 65606e908715..77ea13905fdb 100644 --- a/arch/arm64/boot/dts/amlogic/g12a_s905y2_u220.dts +++ b/arch/arm64/boot/dts/amlogic/g12a_s905y2_u220.dts @@ -87,6 +87,13 @@ size = <0x0 0x8000000>; alignment = <0x0 0x400000>; }; + ion_fb_reserved:linux,ion-fb { + compatible = "amlogic, ion-fb-mem"; + reusable; + /* 1920x1080x4x3 round up 4M align */ + size = <0x0 0x1c00000>; + alignment = <0x0 0x400000>; + }; //di_reserved:linux,di { //compatible = "amlogic, di-mem"; /* buffer_size = 3621952(yuv422 8bit) */ diff --git a/arch/arm64/boot/dts/amlogic/g12a_s905y2_u221.dts b/arch/arm64/boot/dts/amlogic/g12a_s905y2_u221.dts index 34f1fada1441..b90368cb13e9 100644 --- a/arch/arm64/boot/dts/amlogic/g12a_s905y2_u221.dts +++ b/arch/arm64/boot/dts/amlogic/g12a_s905y2_u221.dts @@ -78,6 +78,13 @@ size = <0x0 0x8000000>; alignment = <0x0 0x400000>; }; + ion_fb_reserved:linux,ion-fb { + compatible = "amlogic, ion-fb-mem"; + reusable; + /* 1920x1080x4x3 round up 4M align */ + size = <0x0 0x1c00000>; + alignment = <0x0 0x400000>; + }; //di_reserved:linux,di { //compatible = "amlogic, di-mem"; /* buffer_size = 3621952(yuv422 8bit) */ diff --git a/arch/arm64/boot/dts/amlogic/g12a_s905y2_u223_lp.dts b/arch/arm64/boot/dts/amlogic/g12a_s905y2_u223_lp.dts index a650d23f9d37..091125d61b45 100644 --- a/arch/arm64/boot/dts/amlogic/g12a_s905y2_u223_lp.dts +++ b/arch/arm64/boot/dts/amlogic/g12a_s905y2_u223_lp.dts @@ -78,6 +78,13 @@ size = <0x0 0x8000000>; alignment = <0x0 0x400000>; }; + ion_fb_reserved:linux,ion-fb { + compatible = "amlogic, ion-fb-mem"; + reusable; + /* 1920x1080x4x3 round up 4M align */ + size = <0x0 0x1c00000>; + alignment = <0x0 0x400000>; + }; //di_reserved:linux,di { //compatible = "amlogic, di-mem"; /* buffer_size = 3621952(yuv422 8bit) */ diff --git a/arch/arm64/boot/dts/amlogic/mesong12a.dtsi b/arch/arm64/boot/dts/amlogic/mesong12a.dtsi index 53611a96181f..e61dc5598bde 100644 --- a/arch/arm64/boot/dts/amlogic/mesong12a.dtsi +++ b/arch/arm64/boot/dts/amlogic/mesong12a.dtsi @@ -808,7 +808,8 @@ ion_dev { compatible = "amlogic, ion_dev"; - memory-region = <&ion_cma_reserved>; + memory-region = <&ion_cma_reserved + &ion_fb_reserved>; };/* end of ion_dev*/ audiobus: audiobus@0xff642000 { diff --git a/arch/arm64/boot/dts/amlogic/mesong12a_deadpool.dtsi b/arch/arm64/boot/dts/amlogic/mesong12a_deadpool.dtsi index 85682afe649e..213d4eb13603 100644 --- a/arch/arm64/boot/dts/amlogic/mesong12a_deadpool.dtsi +++ b/arch/arm64/boot/dts/amlogic/mesong12a_deadpool.dtsi @@ -793,7 +793,8 @@ ion_dev { compatible = "amlogic, ion_dev"; - memory-region = <&ion_cma_reserved>; + memory-region = <&ion_cma_reserved + &ion_fb_reserved>; };/* end of ion_dev*/ audiobus: audiobus@0xff642000 { diff --git a/arch/arm64/boot/dts/amlogic/mesong12b.dtsi b/arch/arm64/boot/dts/amlogic/mesong12b.dtsi index 369bcc45224f..fd12f75f6207 100644 --- a/arch/arm64/boot/dts/amlogic/mesong12b.dtsi +++ b/arch/arm64/boot/dts/amlogic/mesong12b.dtsi @@ -1,5 +1,5 @@ /* - * arch/arm64/boot/dts/amlogic/mesong12a.dtsi + * arch/arm64/boot/dts/amlogic/mesong12b.dtsi * * Copyright (C) 2017 Amlogic, Inc. All rights reserved. * diff --git a/arch/arm64/boot/dts/amlogic/mesonsm1.dtsi b/arch/arm64/boot/dts/amlogic/mesonsm1.dtsi index 839fc918a1b7..d569de470d03 100644 --- a/arch/arm64/boot/dts/amlogic/mesonsm1.dtsi +++ b/arch/arm64/boot/dts/amlogic/mesonsm1.dtsi @@ -813,7 +813,8 @@ ion_dev { compatible = "amlogic, ion_dev"; - memory-region = <&ion_cma_reserved>; + memory-region = <&ion_cma_reserved + &ion_fb_reserved>; };/* end of ion_dev*/ audiobus: audiobus@0xFF660000 { diff --git a/arch/arm64/boot/dts/amlogic/sm1_pxp.dts b/arch/arm64/boot/dts/amlogic/sm1_pxp.dts index 6c3778c77bf9..d8da28e6cce0 100644 --- a/arch/arm64/boot/dts/amlogic/sm1_pxp.dts +++ b/arch/arm64/boot/dts/amlogic/sm1_pxp.dts @@ -73,6 +73,13 @@ size = <0x0 0x3000000>; alignment = <0x0 0x400000>; }; + ion_fb_reserved:linux,ion-fb { + compatible = "amlogic, ion-fb-mem"; + reusable; + /* 1920x1080x4x3 round up 4M align */ + size = <0x0 0x1c00000>; + alignment = <0x0 0x400000>; + }; //di_reserved:linux,di { //compatible = "amlogic, di-mem"; diff --git a/arch/arm64/boot/dts/amlogic/sm1_s905c1_ac232.dts b/arch/arm64/boot/dts/amlogic/sm1_s905c1_ac232.dts index 741a0fd6a5a9..a2529ce54670 100644 --- a/arch/arm64/boot/dts/amlogic/sm1_s905c1_ac232.dts +++ b/arch/arm64/boot/dts/amlogic/sm1_s905c1_ac232.dts @@ -89,6 +89,13 @@ size = <0x0 0x8000000>; alignment = <0x0 0x400000>; }; + ion_fb_reserved:linux,ion-fb { + compatible = "amlogic, ion-fb-mem"; + reusable; + /* 1920x1080x4x3 round up 4M align */ + size = <0x0 0x1c00000>; + alignment = <0x0 0x400000>; + }; //di_reserved:linux,di { //compatible = "amlogic, di-mem"; /* buffer_size = 3621952(yuv422 8bit) */ diff --git a/arch/arm64/boot/dts/amlogic/sm1_s905d3_ac200.dts b/arch/arm64/boot/dts/amlogic/sm1_s905d3_ac200.dts index 9e2eeee17c8c..9aae0e76c978 100644 --- a/arch/arm64/boot/dts/amlogic/sm1_s905d3_ac200.dts +++ b/arch/arm64/boot/dts/amlogic/sm1_s905d3_ac200.dts @@ -89,6 +89,13 @@ size = <0x0 0x8000000>; alignment = <0x0 0x400000>; }; + ion_fb_reserved:linux,ion-fb { + compatible = "amlogic, ion-fb-mem"; + reusable; + /* 1920x1080x4x3 round up 4M align */ + size = <0x0 0x1c00000>; + alignment = <0x0 0x400000>; + }; //di_reserved:linux,di { //compatible = "amlogic, di-mem"; /* buffer_size = 3621952(yuv422 8bit) */ diff --git a/arch/arm64/boot/dts/amlogic/sm1_s905d3_ac200_buildroot.dts b/arch/arm64/boot/dts/amlogic/sm1_s905d3_ac200_buildroot.dts index 23ebfbbca23e..dc976411d42d 100644 --- a/arch/arm64/boot/dts/amlogic/sm1_s905d3_ac200_buildroot.dts +++ b/arch/arm64/boot/dts/amlogic/sm1_s905d3_ac200_buildroot.dts @@ -79,6 +79,13 @@ size = <0x0 0x8000000>; alignment = <0x0 0x400000>; }; + ion_fb_reserved:linux,ion-fb { + compatible = "amlogic, ion-fb-mem"; + reusable; + /* 1920x1080x4x3 round up 4M align */ + size = <0x0 0x0000000>; + alignment = <0x0 0x400000>; + }; //di_reserved:linux,di { //compatible = "amlogic, di-mem"; /* buffer_size = 3621952(yuv422 8bit) */ diff --git a/arch/arm64/boot/dts/amlogic/sm1_s905d3_ac200_drm_buildroot.dts b/arch/arm64/boot/dts/amlogic/sm1_s905d3_ac200_drm_buildroot.dts index 53af4b5cc3d7..0d0eeff7c503 100644 --- a/arch/arm64/boot/dts/amlogic/sm1_s905d3_ac200_drm_buildroot.dts +++ b/arch/arm64/boot/dts/amlogic/sm1_s905d3_ac200_drm_buildroot.dts @@ -81,6 +81,13 @@ alignment = <0x0 0x400000>; no-kernel-map; }; + ion_fb_reserved:linux,ion-fb { + compatible = "amlogic, ion-fb-mem"; + reusable; + /* 1920x1080x4x3 round up 4M align */ + size = <0x0 0x0000000>; + alignment = <0x0 0x400000>; + }; //di_reserved:linux,di { //compatible = "amlogic, di-mem"; /* buffer_size = 3621952(yuv422 8bit) */ diff --git a/arch/arm64/boot/dts/amlogic/sm1_s905d3_ac202.dts b/arch/arm64/boot/dts/amlogic/sm1_s905d3_ac202.dts index 966ed110b84c..15c611b3ebbf 100644 --- a/arch/arm64/boot/dts/amlogic/sm1_s905d3_ac202.dts +++ b/arch/arm64/boot/dts/amlogic/sm1_s905d3_ac202.dts @@ -89,6 +89,13 @@ size = <0x0 0x8000000>; alignment = <0x0 0x400000>; }; + ion_fb_reserved:linux,ion-fb { + compatible = "amlogic, ion-fb-mem"; + reusable; + /* 1920x1080x4x3 round up 4M align */ + size = <0x0 0x1c00000>; + alignment = <0x0 0x400000>; + }; //di_reserved:linux,di { //compatible = "amlogic, di-mem"; /* buffer_size = 3621952(yuv422 8bit) */ diff --git a/arch/arm64/boot/dts/amlogic/sm1_s905d3_ac202_1g.dts b/arch/arm64/boot/dts/amlogic/sm1_s905d3_ac202_1g.dts index bc38874cd75d..906f7a9cce9c 100644 --- a/arch/arm64/boot/dts/amlogic/sm1_s905d3_ac202_1g.dts +++ b/arch/arm64/boot/dts/amlogic/sm1_s905d3_ac202_1g.dts @@ -90,6 +90,13 @@ size = <0x0 0x3000000>; alignment = <0x0 0x400000>; }; + ion_fb_reserved:linux,ion-fb { + compatible = "amlogic, ion-fb-mem"; + reusable; + /* 1920x1080x4x3 round up 4M align */ + size = <0x0 0x1c00000>; + alignment = <0x0 0x400000>; + }; //di_reserved:linux,di { //compatible = "amlogic, di-mem"; /* buffer_size = 3621952(yuv422 8bit) */ diff --git a/arch/arm64/boot/dts/amlogic/sm1_s905d3_skt.dts b/arch/arm64/boot/dts/amlogic/sm1_s905d3_skt.dts index 920ea3259b27..2521742521b3 100644 --- a/arch/arm64/boot/dts/amlogic/sm1_s905d3_skt.dts +++ b/arch/arm64/boot/dts/amlogic/sm1_s905d3_skt.dts @@ -89,6 +89,13 @@ size = <0x0 0x8000000>; alignment = <0x0 0x400000>; }; + ion_fb_reserved:linux,ion-fb { + compatible = "amlogic, ion-fb-mem"; + reusable; + /* 1920x1080x4x3 round up 4M align */ + size = <0x0 0x1c00000>; + alignment = <0x0 0x400000>; + }; //di_reserved:linux,di { //compatible = "amlogic, di-mem"; /* buffer_size = 3621952(yuv422 8bit) */ diff --git a/arch/arm64/boot/dts/amlogic/sm1_s905x3_ac212.dts b/arch/arm64/boot/dts/amlogic/sm1_s905x3_ac212.dts index 8bbbdeb971ad..0e76fbb7f233 100644 --- a/arch/arm64/boot/dts/amlogic/sm1_s905x3_ac212.dts +++ b/arch/arm64/boot/dts/amlogic/sm1_s905x3_ac212.dts @@ -89,6 +89,13 @@ size = <0x0 0x8000000>; alignment = <0x0 0x400000>; }; + ion_fb_reserved:linux,ion-fb { + compatible = "amlogic, ion-fb-mem"; + reusable; + /* 1920x1080x4x3 round up 4M align */ + size = <0x0 0x1c00000>; + alignment = <0x0 0x400000>; + }; //di_reserved:linux,di { //compatible = "amlogic, di-mem"; /* buffer_size = 3621952(yuv422 8bit) */ diff --git a/arch/arm64/boot/dts/amlogic/sm1_s905x3_ac213.dts b/arch/arm64/boot/dts/amlogic/sm1_s905x3_ac213.dts index ec29848f3ae5..7456d1333e62 100644 --- a/arch/arm64/boot/dts/amlogic/sm1_s905x3_ac213.dts +++ b/arch/arm64/boot/dts/amlogic/sm1_s905x3_ac213.dts @@ -89,6 +89,13 @@ size = <0x0 0x8000000>; alignment = <0x0 0x400000>; }; + ion_fb_reserved:linux,ion-fb { + compatible = "amlogic, ion-fb-mem"; + reusable; + /* 1920x1080x4x3 round up 4M align */ + size = <0x0 0x1c00000>; + alignment = <0x0 0x400000>; + }; //di_reserved:linux,di { //compatible = "amlogic, di-mem"; /* buffer_size = 3621952(yuv422 8bit) */ diff --git a/arch/arm64/boot/dts/amlogic/sm1_s905x3_ac213_buildroot.dts b/arch/arm64/boot/dts/amlogic/sm1_s905x3_ac213_buildroot.dts index f2265537f3b9..c34a3a5945be 100644 --- a/arch/arm64/boot/dts/amlogic/sm1_s905x3_ac213_buildroot.dts +++ b/arch/arm64/boot/dts/amlogic/sm1_s905x3_ac213_buildroot.dts @@ -79,6 +79,13 @@ size = <0x0 0x8000000>; alignment = <0x0 0x400000>; }; + ion_fb_reserved:linux,ion-fb { + compatible = "amlogic, ion-fb-mem"; + reusable; + /* 1920x1080x4x3 round up 4M align */ + size = <0x0 0x0000000>; + alignment = <0x0 0x400000>; + }; //di_reserved:linux,di { //compatible = "amlogic, di-mem"; /* buffer_size = 3621952(yuv422 8bit) */ diff --git a/arch/arm64/boot/dts/amlogic/sm1_s905x3_ac213_drm_buildroot.dts b/arch/arm64/boot/dts/amlogic/sm1_s905x3_ac213_drm_buildroot.dts index 4720efe6a426..3bbf19968473 100644 --- a/arch/arm64/boot/dts/amlogic/sm1_s905x3_ac213_drm_buildroot.dts +++ b/arch/arm64/boot/dts/amlogic/sm1_s905x3_ac213_drm_buildroot.dts @@ -81,6 +81,13 @@ alignment = <0x0 0x400000>; no-kernel-map; }; + ion_fb_reserved:linux,ion-fb { + compatible = "amlogic, ion-fb-mem"; + reusable; + /* 1920x1080x4x3 round up 4M align */ + size = <0x0 0x0000000>; + alignment = <0x0 0x400000>; + }; //di_reserved:linux,di { //compatible = "amlogic, di-mem"; /* buffer_size = 3621952(yuv422 8bit) */ diff --git a/arch/arm64/boot/dts/amlogic/sm1_s905x3_ac214.dts b/arch/arm64/boot/dts/amlogic/sm1_s905x3_ac214.dts index e1b5406c201f..6f48f0180538 100644 --- a/arch/arm64/boot/dts/amlogic/sm1_s905x3_ac214.dts +++ b/arch/arm64/boot/dts/amlogic/sm1_s905x3_ac214.dts @@ -89,6 +89,13 @@ size = <0x0 0x8000000>; alignment = <0x0 0x400000>; }; + ion_fb_reserved:linux,ion-fb { + compatible = "amlogic, ion-fb-mem"; + reusable; + /* 1920x1080x4x3 round up 4M align */ + size = <0x0 0x1c00000>; + alignment = <0x0 0x400000>; + }; //di_reserved:linux,di { //compatible = "amlogic, di-mem"; /* buffer_size = 3621952(yuv422 8bit) */ diff --git a/arch/arm64/boot/dts/amlogic/sm1_s905x3_ac214_buildroot.dts b/arch/arm64/boot/dts/amlogic/sm1_s905x3_ac214_buildroot.dts index b1bfdbc69279..92784f157b67 100644 --- a/arch/arm64/boot/dts/amlogic/sm1_s905x3_ac214_buildroot.dts +++ b/arch/arm64/boot/dts/amlogic/sm1_s905x3_ac214_buildroot.dts @@ -79,6 +79,13 @@ size = <0x0 0x8000000>; alignment = <0x0 0x400000>; }; + ion_fb_reserved:linux,ion-fb { + compatible = "amlogic, ion-fb-mem"; + reusable; + /* 1920x1080x4x3 round up 4M align */ + size = <0x0 0x0000000>; + alignment = <0x0 0x400000>; + }; //di_reserved:linux,di { //compatible = "amlogic, di-mem"; /* buffer_size = 3621952(yuv422 8bit) */ diff --git a/arch/arm64/boot/dts/amlogic/sm1_s905x3_ac214_drm_buildroot.dts b/arch/arm64/boot/dts/amlogic/sm1_s905x3_ac214_drm_buildroot.dts index 2231bea1e659..2b448057832f 100644 --- a/arch/arm64/boot/dts/amlogic/sm1_s905x3_ac214_drm_buildroot.dts +++ b/arch/arm64/boot/dts/amlogic/sm1_s905x3_ac214_drm_buildroot.dts @@ -81,6 +81,13 @@ alignment = <0x0 0x400000>; no-kernel-map; }; + ion_fb_reserved:linux,ion-fb { + compatible = "amlogic, ion-fb-mem"; + reusable; + /* 1920x1080x4x3 round up 4M align */ + size = <0x0 0x0000000>; + alignment = <0x0 0x400000>; + }; //di_reserved:linux,di { //compatible = "amlogic, di-mem"; /* buffer_size = 3621952(yuv422 8bit) */ diff --git a/arch/arm64/boot/dts/amlogic/sm1_s905x3_ac215.dts b/arch/arm64/boot/dts/amlogic/sm1_s905x3_ac215.dts index 2babfcb224ef..afc527b73504 100644 --- a/arch/arm64/boot/dts/amlogic/sm1_s905x3_ac215.dts +++ b/arch/arm64/boot/dts/amlogic/sm1_s905x3_ac215.dts @@ -89,6 +89,13 @@ size = <0x0 0x8000000>; alignment = <0x0 0x400000>; }; + ion_fb_reserved:linux,ion-fb { + compatible = "amlogic, ion-fb-mem"; + reusable; + /* 1920x1080x4x3 round up 4M align */ + size = <0x0 0x1c00000>; + alignment = <0x0 0x400000>; + }; //di_reserved:linux,di { //compatible = "amlogic, di-mem"; /* buffer_size = 3621952(yuv422 8bit) */ diff --git a/arch/arm64/boot/dts/amlogic/sm1_s905y3_ac223.dts b/arch/arm64/boot/dts/amlogic/sm1_s905y3_ac223.dts index 12cd4a48cd8b..0bb64b6c9efe 100644 --- a/arch/arm64/boot/dts/amlogic/sm1_s905y3_ac223.dts +++ b/arch/arm64/boot/dts/amlogic/sm1_s905y3_ac223.dts @@ -89,6 +89,13 @@ size = <0x0 0x8000000>; alignment = <0x0 0x400000>; }; + ion_fb_reserved:linux,ion-fb { + compatible = "amlogic, ion-fb-mem"; + reusable; + /* 1920x1080x4x3 round up 4M align */ + size = <0x0 0x1c00000>; + alignment = <0x0 0x400000>; + }; //di_reserved:linux,di { //compatible = "amlogic, di-mem"; /* buffer_size = 3621952(yuv422 8bit) */ diff --git a/arch/arm64/boot/dts/amlogic/sm1_s905y3_deadpool.dts b/arch/arm64/boot/dts/amlogic/sm1_s905y3_deadpool.dts index bcea3b885f0c..f243707e3e81 100644 --- a/arch/arm64/boot/dts/amlogic/sm1_s905y3_deadpool.dts +++ b/arch/arm64/boot/dts/amlogic/sm1_s905y3_deadpool.dts @@ -88,6 +88,13 @@ size = <0x0 0x8000000>; alignment = <0x0 0x400000>; }; + ion_fb_reserved:linux,ion-fb { + compatible = "amlogic, ion-fb-mem"; + reusable; + /* 1920x1080x4x3 round up 4M align */ + size = <0x0 0x1c00000>; + alignment = <0x0 0x400000>; + }; //di_reserved:linux,di { //compatible = "amlogic, di-mem"; /* buffer_size = 3621952(yuv422 8bit) */ @@ -1804,4 +1811,4 @@ &dummy_venc { status = "okay"; -}; \ No newline at end of file +}; diff --git a/drivers/amlogic/media/common/ion_dev/dev_ion.c b/drivers/amlogic/media/common/ion_dev/dev_ion.c index e740dc788d4f..42be0771e19e 100644 --- a/drivers/amlogic/media/common/ion_dev/dev_ion.c +++ b/drivers/amlogic/media/common/ion_dev/dev_ion.c @@ -32,15 +32,9 @@ MODULE_DESCRIPTION("AMLOGIC ION driver"); MODULE_LICENSE("GPL"); MODULE_AUTHOR("Amlogic SH"); -static unsigned int debug = 2; -module_param(debug, uint, 0644); -MODULE_PARM_DESC(debug, "activates debug info"); - -#define dprintk(level, fmt, arg...) \ - do { \ - if (debug > level) \ - pr_debug("ion-dev: " fmt, ## arg); \ - } while (0) +#define ION_INFO(fmt, args...) pr_info("ion-dev: " fmt "", ## args) +#define ION_DEBUG(fmt, args...) pr_debug("ion-dev: debug: " fmt "", ## args) +#define ION_ERR(fmt, args...) pr_err("ion-dev: error: " fmt "", ## args) /* * TODO instead with enum ion_heap_type from ion.h @@ -63,12 +57,12 @@ struct ion_client *meson_ion_client_create(unsigned int heap_mask, * */ if (idev == NULL) { - dprintk(0, "create error"); + ION_DEBUG("create error"); return ERR_PTR(-EPROBE_DEFER); } if (IS_ERR(idev)) { - dprintk(0, "idev error"); + ION_DEBUG("idev error"); return (struct ion_client *)idev; } @@ -116,10 +110,10 @@ int meson_ion_share_fd_to_phys(struct ion_client *client, } ret = ion_phys(client, handle, addr, (size_t *)len); - pr_debug("ion_phys ret=%d, phys=0x%lx\n", ret, *addr); + ION_DEBUG("ion_phys ret=%d, phys=0x%lx\n", ret, *addr); ion_free(client, handle); if (ret < 0) { - pr_err("ion_get_phys error, ret=%d\n", ret); + ION_ERR("ion_get_phys error, ret=%d\n", ret); return ret; } @@ -143,16 +137,16 @@ static int meson_ion_get_phys( } handle = ion_import_dma_buf_fd(client, data.handle); if (IS_ERR_OR_NULL(handle)) { - dprintk(0, "EINVAL, client=%p, share_fd=%d\n", + ION_DEBUG("EINVAL, client=%p, share_fd=%d\n", client, data.handle); return PTR_ERR(handle); } ret = ion_phys(client, handle, &addr, (size_t *)&len); - dprintk(1, "ret=%d, phys=0x%lX\n", ret, addr); + ION_DEBUG("ret=%d, phys=0x%lX\n", ret, addr); ion_free(client, handle); if (ret < 0) { - dprintk(0, "meson_ion_get_phys error, ret=%d\n", ret); + ION_DEBUG("meson_ion_get_phys error, ret=%d\n", ret); return ret; } @@ -183,6 +177,9 @@ int dev_ion_probe(struct platform_device *pdev) { int err = 0; int i; +#ifdef CONFIG_AMLOGIC_TEE + unsigned int handle; +#endif my_ion_heap[num_heaps].type = ION_HEAP_TYPE_SYSTEM; my_ion_heap[num_heaps].id = ION_HEAP_TYPE_SYSTEM; @@ -208,7 +205,15 @@ int dev_ion_probe(struct platform_device *pdev) /* init reserved memory */ err = of_reserved_mem_device_init(&pdev->dev); if (err != 0) - dprintk(1, "failed get reserved memory\n"); + ION_INFO("failed get reserved memory\n"); + err = of_reserved_mem_device_init_by_idx(&pdev->dev, + pdev->dev.of_node, 1); + if (err != 0) + ION_INFO("failed get fb memory\n"); + err = of_reserved_mem_device_init_by_idx(&pdev->dev, + pdev->dev.of_node, 2); + if (err != 0) + ION_INFO("failed get secure memory\n"); heaps = kcalloc(num_heaps, sizeof(struct ion_heap *), GFP_KERNEL); if (!heaps) return -ENOMEM; @@ -229,15 +234,27 @@ int dev_ion_probe(struct platform_device *pdev) err = PTR_ERR(heaps[i]); goto failed; } +#ifdef CONFIG_AMLOGIC_TEE + if (my_ion_heap[i].type == ION_HEAP_TYPE_CUSTOM && + my_ion_heap[i].id == ION_HEAP_ID_SECURE && + my_ion_heap[i].base && + my_ion_heap[i].size) { + tee_protect_mem_by_type(TEE_MEM_TYPE_GPU, + (u32)my_ion_heap[i].base, + (u32)my_ion_heap[i].size, + &handle); + ION_INFO("tee protect gpu mem done\n"); + } +#endif ion_device_add_heap(idev, heaps[i]); - dprintk(2, "add heap type:%d id:%d\n", + ION_INFO("add heap type:%d id:%d\n", my_ion_heap[i].type, my_ion_heap[i].id); } - dprintk(1, "%s, create %d heaps\n", __func__, num_heaps); + ION_INFO("%s, create %d heaps\n", __func__, num_heaps); return 0; failed: - dprintk(0, "ion heap create failed\n"); + ION_ERR("ion heap create failed\n"); kfree(heaps); heaps = NULL; panic(0); @@ -275,19 +292,15 @@ static struct platform_driver ion_driver = { */ static int ion_dev_mem_init(struct reserved_mem *rmem, struct device *dev) { - my_ion_heap[num_heaps].type = ION_HEAP_TYPE_CARVEOUT; my_ion_heap[num_heaps].id = ION_HEAP_TYPE_CARVEOUT; my_ion_heap[num_heaps].name = "carveout_ion"; my_ion_heap[num_heaps].base = (ion_phys_addr_t) rmem->base; my_ion_heap[num_heaps].size = rmem->size; - - pr_info("ion_dev_mem_init size=%pa\n", &rmem->size); + ION_INFO("ion_dev_mem_init size=%pa\n", &rmem->size); num_heaps++; return 0; - - } static const struct reserved_mem_ops rmem_ion_dev_ops = { @@ -308,11 +321,65 @@ static int __init ion_dev_mem_setup(struct reserved_mem *rmem) #else rmem->ops = &rmem_ion_dev_ops; #endif - pr_debug("ion_dev mem setup\n"); + ION_DEBUG("ion_dev mem setup\n"); + + return 0; +} + +static int ion_secure_mem_init(struct reserved_mem *rmem, struct device *dev) +{ + my_ion_heap[num_heaps].type = ION_HEAP_TYPE_CUSTOM; + my_ion_heap[num_heaps].id = ION_HEAP_ID_SECURE; + my_ion_heap[num_heaps].name = "secure_ion"; + my_ion_heap[num_heaps].base = (ion_phys_addr_t)rmem->base; + my_ion_heap[num_heaps].size = rmem->size; + ION_INFO("ion secure_mem_init size=0x%pa, paddr=0x%pa\n", + &rmem->size, &rmem->base); + num_heaps++; + return 0; +} + +static const struct reserved_mem_ops rmem_ion_secure_ops = { + .device_init = ion_secure_mem_init, +}; +static int __init ion_secure_mem_setup(struct reserved_mem *rmem) +{ + rmem->ops = &rmem_ion_secure_ops; + ION_DEBUG("ion secure mem setup\n"); return 0; } +static int ion_fb_mem_init(struct reserved_mem *rmem, struct device *dev) +{ + my_ion_heap[num_heaps].type = ION_HEAP_TYPE_CUSTOM; + my_ion_heap[num_heaps].id = ION_HEAP_ID_FB; + my_ion_heap[num_heaps].name = "fb_ion"; + my_ion_heap[num_heaps].base = (ion_phys_addr_t)rmem->base; + my_ion_heap[num_heaps].size = rmem->size; + ION_INFO("ion fb_mem_init size=0x%pa, paddr=0x%pa\n", + &rmem->size, &rmem->base); + num_heaps++; + return 0; +} + +static const struct reserved_mem_ops rmem_ion_fb_ops = { + .device_init = ion_fb_mem_init, +}; + +static int __init ion_fb_mem_setup(struct reserved_mem *rmem) +{ + rmem->ops = &rmem_ion_fb_ops; + ION_DEBUG("ion fb mem setup\n"); + return 0; +} + +RESERVEDMEM_OF_DECLARE(ion_fb_mem, "amlogic, ion-fb-mem", + ion_fb_mem_setup); + +RESERVEDMEM_OF_DECLARE(ion_secure_mem, "amlogic, ion-secure-mem", + ion_secure_mem_setup); + RESERVEDMEM_OF_DECLARE(ion_dev_mem, "amlogic, idev-mem", ion_dev_mem_setup); /* * reserved memory initialize end diff --git a/drivers/amlogic/media/common/ion_dev/meson_ion.h b/drivers/amlogic/media/common/ion_dev/meson_ion.h index d89a27c1f86f..6410e0a5d440 100644 --- a/drivers/amlogic/media/common/ion_dev/meson_ion.h +++ b/drivers/amlogic/media/common/ion_dev/meson_ion.h @@ -20,6 +20,7 @@ #include #include +#include /** * CUSTOM IOCTL - CMD @@ -57,5 +58,4 @@ int meson_ion_share_fd_to_phys(struct ion_client *client, int ion_phys(struct ion_client *client, struct ion_handle *handle, ion_phys_addr_t *addr, size_t *len); - #endif diff --git a/drivers/staging/android/ion/Makefile b/drivers/staging/android/ion/Makefile index 9fc31203cf19..232a204f8b32 100644 --- a/drivers/staging/android/ion/Makefile +++ b/drivers/staging/android/ion/Makefile @@ -1,6 +1,6 @@ obj-$(CONFIG_ION) += ion.o ion-ioctl.o ion_heap.o \ ion_page_pool.o ion_system_heap.o \ - ion_carveout_heap.o ion_chunk_heap.o ion_cma_heap.o ion_codec_mm_heap.o + ion_carveout_heap.o ion_chunk_heap.o ion_cma_heap.o ion_codec_mm_heap.o ion_secure_heap.o ion_fb_heap.o obj-$(CONFIG_ION_TEST) += ion_test.o ifdef CONFIG_COMPAT obj-$(CONFIG_ION) += compat_ion.o diff --git a/drivers/staging/android/ion/ion_fb_heap.c b/drivers/staging/android/ion/ion_fb_heap.c new file mode 100644 index 000000000000..ea6c19fb35ab --- /dev/null +++ b/drivers/staging/android/ion/ion_fb_heap.c @@ -0,0 +1,163 @@ +/* + * drivers/staging/android/ion/ion_fb_heap.c + * + * Copyright (C) 2021 amlogic, Inc. + * + * This software is licensed under the terms of the GNU General Public + * License version 2, as published by the Free Software Foundation, and + * may be copied, distributed, and modified under those terms. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + */ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "ion.h" +#include "ion_priv.h" + +#define ION_FB_ALLOCATE_FAIL -1 +#define ION_FLAG_EXTEND_MESON_HEAP BIT(30) + +struct ion_fb_heap { + struct ion_heap heap; + struct gen_pool *pool; + ion_phys_addr_t base; +}; + +static ion_phys_addr_t ion_fb_allocate(struct ion_heap *heap, + unsigned long size, + unsigned long align) +{ + struct ion_fb_heap *fb_heap = + container_of(heap, struct ion_fb_heap, heap); + unsigned long offset = gen_pool_alloc(fb_heap->pool, size); + + if (!offset) + return ION_FB_ALLOCATE_FAIL; + + return offset; +} + +static void ion_fb_free(struct ion_heap *heap, ion_phys_addr_t addr, + unsigned long size) +{ + struct ion_fb_heap *fb_heap = + container_of(heap, struct ion_fb_heap, heap); + + if (addr == ION_FB_ALLOCATE_FAIL) + return; + gen_pool_free(fb_heap->pool, addr, size); +} + +static int ion_fb_heap_allocate(struct ion_heap *heap, + struct ion_buffer *buffer, + unsigned long size, unsigned long align, + unsigned long flags) +{ + struct sg_table *table; + ion_phys_addr_t paddr; + int ret; + + if (align > PAGE_SIZE) + return -EINVAL; + + if (!(flags & ION_FLAG_EXTEND_MESON_HEAP)) + return -ENOMEM; + + table = kmalloc(sizeof(*table), GFP_KERNEL); + if (!table) + return -ENOMEM; + ret = sg_alloc_table(table, 1, GFP_KERNEL); + if (ret) + goto err_free; + + paddr = ion_fb_allocate(heap, size, align); + if (paddr == ION_FB_ALLOCATE_FAIL) { + ret = -ENOMEM; + goto err_free_table; + } + + sg_set_page(table->sgl, pfn_to_page(PFN_DOWN(paddr)), size, 0); + buffer->sg_table = table; + + return 0; + +err_free_table: + sg_free_table(table); +err_free: + kfree(table); + return ret; +} + +static void ion_fb_heap_free(struct ion_buffer *buffer) +{ + struct ion_heap *heap = buffer->heap; + struct sg_table *table = buffer->sg_table; + struct page *page = sg_page(table->sgl); + ion_phys_addr_t paddr = PFN_PHYS(page_to_pfn(page)); + + ion_fb_free(heap, paddr, buffer->size); + sg_free_table(table); + kfree(table); +} + +static struct ion_heap_ops fb_heap_ops = { + .allocate = ion_fb_heap_allocate, + .free = ion_fb_heap_free, + .map_user = ion_heap_map_user, + .map_kernel = ion_heap_map_kernel, + .unmap_kernel = ion_heap_unmap_kernel, +}; + +struct ion_heap *ion_fb_heap_create(struct ion_platform_heap *heap_data) +{ + struct ion_fb_heap *fb_heap; + int ret; + struct page *page; + size_t size; + + page = pfn_to_page(PFN_DOWN(heap_data->base)); + size = heap_data->size; + + ion_pages_sync_for_device(NULL, page, size, DMA_BIDIRECTIONAL); + + ret = ion_heap_pages_zero(page, size, pgprot_writecombine(PAGE_KERNEL)); + if (ret) + return ERR_PTR(ret); + fb_heap = kzalloc(sizeof(*fb_heap), GFP_KERNEL); + if (!fb_heap) + return ERR_PTR(-ENOMEM); + + fb_heap->pool = gen_pool_create(PAGE_SHIFT, -1); + if (!fb_heap->pool) { + kfree(fb_heap); + return ERR_PTR(-ENOMEM); + } + fb_heap->base = heap_data->base; + gen_pool_add(fb_heap->pool, fb_heap->base, heap_data->size, -1); + fb_heap->heap.ops = &fb_heap_ops; + fb_heap->heap.type = ION_HEAP_TYPE_CUSTOM; + fb_heap->heap.flags = ION_HEAP_FLAG_DEFER_FREE; + + return &fb_heap->heap; +} + +void ion_fb_heap_destroy(struct ion_heap *heap) +{ + struct ion_fb_heap *fb_heap = + container_of(heap, struct ion_fb_heap, heap); + + gen_pool_destroy(fb_heap->pool); + kfree(fb_heap); + fb_heap = NULL; +} diff --git a/drivers/staging/android/ion/ion_heap.c b/drivers/staging/android/ion/ion_heap.c index 668ca6aa6046..c41aa46f1f0e 100644 --- a/drivers/staging/android/ion/ion_heap.c +++ b/drivers/staging/android/ion/ion_heap.c @@ -337,7 +337,12 @@ struct ion_heap *ion_heap_create(struct ion_platform_heap *heap_data) heap = ion_cma_heap_create(heap_data); break; case ION_HEAP_TYPE_CUSTOM: - heap = ion_codec_mm_heap_create(heap_data); + if (heap_data->id == ION_HEAP_ID_FB) + heap = ion_fb_heap_create(heap_data); + else if (heap_data->id == ION_HEAP_ID_SECURE) + heap = ion_secure_heap_create(heap_data); + else + heap = ion_codec_mm_heap_create(heap_data); break; default: pr_err("%s: Invalid heap type %d\n", __func__, @@ -381,7 +386,12 @@ void ion_heap_destroy(struct ion_heap *heap) ion_cma_heap_destroy(heap); break; case ION_HEAP_TYPE_CUSTOM: - ion_codec_mm_heap_destroy(heap); + if (heap->id == ION_HEAP_ID_FB) + ion_fb_heap_destroy(heap); + else if (heap->id == ION_HEAP_ID_SECURE) + ion_secure_heap_destroy(heap); + else + ion_codec_mm_heap_destroy(heap); break; default: pr_err("%s: Invalid heap type %d\n", __func__, diff --git a/drivers/staging/android/ion/ion_priv.h b/drivers/staging/android/ion/ion_priv.h index 314e6bdff6dd..c1ad18b37146 100644 --- a/drivers/staging/android/ion/ion_priv.h +++ b/drivers/staging/android/ion/ion_priv.h @@ -400,6 +400,14 @@ void ion_cma_heap_destroy(struct ion_heap *); struct ion_heap *ion_codec_mm_heap_create(struct ion_platform_heap *heap_data); void ion_codec_mm_heap_destroy(struct ion_heap *heap); +#define ION_HEAP_ID_SECURE (ION_HEAP_TYPE_CUSTOM + 2) +struct ion_heap *ion_secure_heap_create(struct ion_platform_heap *heap_data); +void ion_secure_heap_destroy(struct ion_heap *heap); + +#define ION_HEAP_ID_FB (ION_HEAP_TYPE_CUSTOM + 1) +struct ion_heap *ion_fb_heap_create(struct ion_platform_heap *heap_data); +void ion_fb_heap_destroy(struct ion_heap *heap); + /** * functions for creating and destroying a heap pool -- allows you * to keep a pool of pre allocated memory to use from your heap. Keeping diff --git a/drivers/staging/android/ion/ion_secure_heap.c b/drivers/staging/android/ion/ion_secure_heap.c new file mode 100644 index 000000000000..6e908c9d1295 --- /dev/null +++ b/drivers/staging/android/ion/ion_secure_heap.c @@ -0,0 +1,159 @@ +/* + * drivers/staging/android/ion/ion_secure_heap.c + * + * Copyright (C) 2019 amlogic, Inc. + * + * This software is licensed under the terms of the GNU General Public + * License version 2, as published by the Free Software Foundation, and + * may be copied, distributed, and modified under those terms. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + */ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "ion.h" +#include "ion_priv.h" + +#define ION_SECURE_ALLOCATE_FAIL -1 + +struct ion_secure_heap { + struct ion_heap heap; + struct gen_pool *pool; + ion_phys_addr_t base; +}; + +static ion_phys_addr_t ion_secure_allocate(struct ion_heap *heap, + unsigned long size, + unsigned long align) +{ + struct ion_secure_heap *secure_heap = + container_of(heap, struct ion_secure_heap, heap); + unsigned long offset = gen_pool_alloc(secure_heap->pool, size); + + if (!offset) + return ION_SECURE_ALLOCATE_FAIL; + + return offset; +} + +static void ion_secure_free(struct ion_heap *heap, ion_phys_addr_t addr, + unsigned long size) +{ + struct ion_secure_heap *secure_heap = + container_of(heap, struct ion_secure_heap, heap); + + if (addr == ION_SECURE_ALLOCATE_FAIL) + return; + gen_pool_free(secure_heap->pool, addr, size); +} + +static int ion_secure_heap_allocate(struct ion_heap *heap, + struct ion_buffer *buffer, + unsigned long size, unsigned long align, + unsigned long flags) +{ + struct sg_table *table; + ion_phys_addr_t paddr; + int ret; + + if (align > PAGE_SIZE) + return -EINVAL; + + table = kmalloc(sizeof(*table), GFP_KERNEL); + if (!table) + return -ENOMEM; + ret = sg_alloc_table(table, 1, GFP_KERNEL); + if (ret) + goto err_free; + + paddr = ion_secure_allocate(heap, size, align); + if (paddr == ION_SECURE_ALLOCATE_FAIL) { + ret = -ENOMEM; + goto err_free_table; + } + + sg_set_page(table->sgl, pfn_to_page(PFN_DOWN(paddr)), size, 0); + buffer->sg_table = table; + + return 0; + +err_free_table: + sg_free_table(table); +err_free: + kfree(table); + return ret; +} + +static void ion_secure_heap_free(struct ion_buffer *buffer) +{ + struct ion_heap *heap = buffer->heap; + struct sg_table *table = buffer->sg_table; + struct page *page = sg_page(table->sgl); + ion_phys_addr_t paddr = PFN_PHYS(page_to_pfn(page)); + + ion_secure_free(heap, paddr, buffer->size); + sg_free_table(table); + kfree(table); +} + +static struct ion_heap_ops secure_heap_ops = { + .allocate = ion_secure_heap_allocate, + .free = ion_secure_heap_free, + .map_user = ion_heap_map_user, + .map_kernel = ion_heap_map_kernel, + .unmap_kernel = ion_heap_unmap_kernel, +}; + +struct ion_heap *ion_secure_heap_create(struct ion_platform_heap *heap_data) +{ + struct ion_secure_heap *secure_heap; + int ret; + struct page *page; + size_t size; + + page = pfn_to_page(PFN_DOWN(heap_data->base)); + size = heap_data->size; + + ion_pages_sync_for_device(NULL, page, size, DMA_BIDIRECTIONAL); + + ret = ion_heap_pages_zero(page, size, pgprot_writecombine(PAGE_KERNEL)); + if (ret) + return ERR_PTR(ret); + secure_heap = kzalloc(sizeof(*secure_heap), GFP_KERNEL); + if (!secure_heap) + return ERR_PTR(-ENOMEM); + + secure_heap->pool = gen_pool_create(PAGE_SHIFT, -1); + if (!secure_heap->pool) { + kfree(secure_heap); + return ERR_PTR(-ENOMEM); + } + secure_heap->base = heap_data->base; + gen_pool_add(secure_heap->pool, secure_heap->base, heap_data->size, -1); + secure_heap->heap.ops = &secure_heap_ops; + secure_heap->heap.type = ION_HEAP_TYPE_CUSTOM; + secure_heap->heap.flags = ION_HEAP_FLAG_DEFER_FREE; + + return &secure_heap->heap; +} + +void ion_secure_heap_destroy(struct ion_heap *heap) +{ + struct ion_secure_heap *secure_heap = + container_of(heap, struct ion_secure_heap, heap); + + gen_pool_destroy(secure_heap->pool); + kfree(secure_heap); + secure_heap = NULL; +} -- 2.20.1