ion: add fb heap for hw-fb [1/1]
authorDezhi Kong <dezhi.kong@amlogic.com>
Fri, 19 Mar 2021 08:23:10 +0000 (16:23 +0800)
committerChristian Hoffmann <chrmhoffmann@gmail.com>
Sun, 12 Feb 2023 08:13:11 +0000 (09:13 +0100)
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 <dezhi.kong@amlogic.com>
52 files changed:
arch/arm64/boot/dts/amlogic/g12a_pxp.dts
arch/arm64/boot/dts/amlogic/g12a_s905d2_skt.dts
arch/arm64/boot/dts/amlogic/g12a_s905d2_skt_buildroot.dts
arch/arm64/boot/dts/amlogic/g12a_s905d2_u200.dts
arch/arm64/boot/dts/amlogic/g12a_s905d2_u200_1g.dts
arch/arm64/boot/dts/amlogic/g12a_s905d2_u200_buildroot.dts
arch/arm64/boot/dts/amlogic/g12a_s905d2_u200_buildroot_vccktest.dts
arch/arm64/boot/dts/amlogic/g12a_s905d2_u200_drm_buildroot.dts
arch/arm64/boot/dts/amlogic/g12a_s905d2_u202.dts
arch/arm64/boot/dts/amlogic/g12a_s905d2_u202_1g.dts
arch/arm64/boot/dts/amlogic/g12a_s905x2_u211.dts
arch/arm64/boot/dts/amlogic/g12a_s905x2_u211_1g.dts
arch/arm64/boot/dts/amlogic/g12a_s905x2_u211_512m.dts
arch/arm64/boot/dts/amlogic/g12a_s905x2_u211_buildroot.dts
arch/arm64/boot/dts/amlogic/g12a_s905x2_u212.dts
arch/arm64/boot/dts/amlogic/g12a_s905x2_u212_1g.dts
arch/arm64/boot/dts/amlogic/g12a_s905x2_u212_buildroot.dts
arch/arm64/boot/dts/amlogic/g12a_s905x2_u212_drm_buildroot.dts
arch/arm64/boot/dts/amlogic/g12a_s905x2_u215.dts
arch/arm64/boot/dts/amlogic/g12a_s905y2_deadpool.dts
arch/arm64/boot/dts/amlogic/g12a_s905y2_u220.dts
arch/arm64/boot/dts/amlogic/g12a_s905y2_u221.dts
arch/arm64/boot/dts/amlogic/g12a_s905y2_u223_lp.dts
arch/arm64/boot/dts/amlogic/mesong12a.dtsi
arch/arm64/boot/dts/amlogic/mesong12a_deadpool.dtsi
arch/arm64/boot/dts/amlogic/mesong12b.dtsi
arch/arm64/boot/dts/amlogic/mesonsm1.dtsi
arch/arm64/boot/dts/amlogic/sm1_pxp.dts
arch/arm64/boot/dts/amlogic/sm1_s905c1_ac232.dts
arch/arm64/boot/dts/amlogic/sm1_s905d3_ac200.dts
arch/arm64/boot/dts/amlogic/sm1_s905d3_ac200_buildroot.dts
arch/arm64/boot/dts/amlogic/sm1_s905d3_ac200_drm_buildroot.dts
arch/arm64/boot/dts/amlogic/sm1_s905d3_ac202.dts
arch/arm64/boot/dts/amlogic/sm1_s905d3_ac202_1g.dts
arch/arm64/boot/dts/amlogic/sm1_s905d3_skt.dts
arch/arm64/boot/dts/amlogic/sm1_s905x3_ac212.dts
arch/arm64/boot/dts/amlogic/sm1_s905x3_ac213.dts
arch/arm64/boot/dts/amlogic/sm1_s905x3_ac213_buildroot.dts
arch/arm64/boot/dts/amlogic/sm1_s905x3_ac213_drm_buildroot.dts
arch/arm64/boot/dts/amlogic/sm1_s905x3_ac214.dts
arch/arm64/boot/dts/amlogic/sm1_s905x3_ac214_buildroot.dts
arch/arm64/boot/dts/amlogic/sm1_s905x3_ac214_drm_buildroot.dts
arch/arm64/boot/dts/amlogic/sm1_s905x3_ac215.dts
arch/arm64/boot/dts/amlogic/sm1_s905y3_ac223.dts
arch/arm64/boot/dts/amlogic/sm1_s905y3_deadpool.dts
drivers/amlogic/media/common/ion_dev/dev_ion.c
drivers/amlogic/media/common/ion_dev/meson_ion.h
drivers/staging/android/ion/Makefile
drivers/staging/android/ion/ion_fb_heap.c [new file with mode: 0644]
drivers/staging/android/ion/ion_heap.c
drivers/staging/android/ion/ion_priv.h
drivers/staging/android/ion/ion_secure_heap.c [new file with mode: 0644]

index 835eaaf8f2d2d622b644f4e37c21d8a71c05ff8f..6ea6951c3ade3b1c8c8127ed77ddb574903ebaf2 100644 (file)
                        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";
index 24f091d2a16f4440f9e890dd9112fd3591ff4489..833ff4e32caa8b9cd122b7643f4bd8f19309256e 100644 (file)
                        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) */
index 23e7685d5e14250d1803c9a002ed36103bb238ef..648bcac95951430ce53cedea9adc67d3af138754 100644 (file)
                        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) */
index 3345ea38a142a6a505ed55bfdaf12ee70c8e6672..8c227464abe55f19004d650bffaf96ed13a94c26 100644 (file)
                        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) */
index ae87a57ec60088626680d0f35e00509596139014..d779630ddc95f9867365e85349597db6a17de4fb 100644 (file)
                        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) */
index 91a21cd8ad76ea252437d68793623d85c60de7b5..c508bfa6a6160d01a0b521ab0ce29b281f39522a 100644 (file)
                        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) */
index d8e6c99c84e241e3558adea6ea9501c03fda5dc4..6524fff3a13784715c9c2af64298655c93cf4150 100644 (file)
                        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) */
index c1fb6235dcdadb46874424e73c3d05535050b4b2..805f0abf9c85719aaaf6890b277c39fa7ecd7fdf 100644 (file)
                        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) */
index 3178f066a421d8f0450096491da2284ba22df03d..f120dd640245ba33d018a83096fdc9ef720df4e3 100644 (file)
                        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) */
index f78381b7a85929cf145f5bb783b545214aa67ebb..d28d80cb6d18c699a5b02d9cff97e0b95fa0562f 100644 (file)
                        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) */
index 8189207680ace361789bbd65b75c57e301e4daca..a18c7aab1fb50c610f8e956f8559df7f2b69036c 100644 (file)
                        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) */
index 0497f61fdee2f35ca4c61155ad927f74736a3f71..4c3144681a8161015c05570fc91079acf9917c2f 100644 (file)
                        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) */
index f709085a25f82092c30f2207f3a80e1acb6f6549..2348bc323d780c05b0a3567f65561eca81659e47 100644 (file)
                        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) */
index 0c6d713e062e73e3cf874b6451f441442ad60760..8f424fe722cd9388cbfc008349e5b53b4e0ba9cf 100644 (file)
                        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) */
index 5facc00af93f6cea93b1ffb4bab55b3116407287..57c7d0f674e099e2fcffbae667fdee44291c25e6 100644 (file)
                        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) */
index ddc34d37325918b05334a7e9a2d881c21c4347fa..397ccfcbb940abf7bfb4630727849a1f0ea9facc 100644 (file)
                        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) */
index 99b3457060c072529c669c7ea34b018311b5a4fe..6d419f665f0a6769f2c18836a291b053c3c86b01 100644 (file)
                        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) */
index bfdb4b973e696708536c895b19ade299f1ba6de4..d1e71a1ace91fce37c8c71fe42cc2658bb49146e 100644 (file)
                        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) */
index 0932cd547650d7b4cb1443cf701e6324d87f44c8..c3767fecd1eb75429a605628ab95207040d09482 100644 (file)
                        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) */
index 46ce7a23626a931938909a191c395bafd8ec6d48..94347f68c5501e99117d66afa894002da49fefbd 100644 (file)
                        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) */
index 65606e9087156cea1a88126691477188b9da62d3..77ea13905fdb38cdbf6530cf656e73bca582febc 100644 (file)
                        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) */
index 34f1fada144121202fbfb3cd1ade525a07e20112..b90368cb13e9623bf4670f759d828fbe4d79c8cc 100644 (file)
                        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) */
index a650d23f9d37f295dfc985386f6e98442924bf68..091125d61b452010918880c46298c23d4a10930f 100644 (file)
                        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) */
index 53611a96181f8bea7ebfe21126bafb4dbe851f3c..e61dc5598bde0312aeacc0dfc630b6a9e39a6c0f 100644 (file)
 
                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 {
index 85682afe649eb54aa9979c5cab5bd98716c30e9d..213d4eb13603a4004092ffa6021ef58d9427d6dc 100644 (file)
 
                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 {
index 369bcc45224fa844eeccf30ca6309ec7296fc3f5..fd12f75f62078ee9628204ca36387178c5ed1200 100644 (file)
@@ -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.
  *
index 839fc918a1b79a72b1968d96e0e6e30cc6c49805..d569de470d033ed82d0fd7a738c4b75d32f005e8 100644 (file)
 
                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 {
index 6c3778c77bf9ef11e1e9cdd8d8ab886646b4b097..d8da28e6cce0057d615c097fc3016e9ba341a9b9 100644 (file)
                        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";
index 741a0fd6a5a97bde18bdb3fc17b145df135cbd62..a2529ce546709cf2d8ccf2aa4eb75ea9f1137355 100644 (file)
                        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) */
index 9e2eeee17c8c627846c0e7f995928e6abfab84f6..9aae0e76c978c4ad76ce8bf7a48248bda9373545 100644 (file)
                        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) */
index 23ebfbbca23ec68f3646133ae2734c214b88a4b4..dc976411d42dcdea46e9c3011a55394c66eb7efe 100644 (file)
                        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) */
index 53af4b5cc3d7a84bfe2438b843371992e6824b2f..0d0eeff7c50304a2075b40d52af5f143f7e3384c 100644 (file)
                        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) */
index 966ed110b84c9d4647a37acf0e20ec80ae1935a0..15c611b3ebbf05ef3bef259619739f5b4259dbca 100644 (file)
                        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) */
index bc38874cd75d7e224b019e9761994482937f2769..906f7a9cce9cabce1bad48f0865cec532629ab2d 100644 (file)
                        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) */
index 920ea3259b27afd60e294bef4c26e075afa3d5d8..2521742521b337dd04f7aa10b4a0025318cc6b29 100644 (file)
                        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) */
index 8bbbdeb971add98d4a4d50c30d38c5648d8070db..0e76fbb7f233b5c90b090bfe54a4df250d3d438b 100644 (file)
                        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) */
index ec29848f3ae5633f75edf28214e0d641585fad14..7456d1333e62877675476ac88c70d3def2adbf42 100644 (file)
                        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) */
index f2265537f3b96e83a83ca26bd629a858fcdaa9c3..c34a3a5945be2d5cc56e76c4eee81bf99ea12e74 100644 (file)
                        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) */
index 4720efe6a4269bc03fd7bd614a3eb4b131ad64a6..3bbf1996847394d84cc687be07670982152ea180 100644 (file)
                        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) */
index e1b5406c201f80622345696359881f6579db57c0..6f48f0180538f6e0011a4be40870c31f736679c3 100644 (file)
                        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) */
index b1bfdbc692799667a716e3227290183590ba7da8..92784f157b6720eaadfd5eff53906d01ff9ba719 100644 (file)
                        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) */
index 2231bea1e659836f8b60f556f0da40d9da2b1449..2b448057832fe5589d580ba0ad821f57930aa806 100644 (file)
                        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) */
index 2babfcb224ef4b31c898e64d3d6aa64257100bbd..afc527b73504067b5a156414c23469e486388c62 100644 (file)
                        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) */
index 12cd4a48cd8b0bcf66a94734fd55835b27cc9b6e..0bb64b6c9efe114a9f7bbb8a14aa70f7b6a99340 100644 (file)
                        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) */
index bcea3b885f0c070da9f2bfcc77d4af6d8cf9b777..f243707e3e81674fa109df3eb28a0430f4e78491 100644 (file)
                        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) */
 
 &dummy_venc {
        status = "okay";
-};
\ No newline at end of file
+};
index e740dc788d4f5a96165dd10ad40e7508c00ae86d..42be0771e19ed2be5e5c799bad4054a1c04ab9b1 100644 (file)
@@ -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
index d89a27c1f86ff53455a48b96e744e2b978f781b5..6410e0a5d440eb5259c871b2f5bd308dfdd399cc 100644 (file)
@@ -20,6 +20,7 @@
 
 #include <linux/types.h>
 #include <ion/ion.h>
+#include <linux/amlogic/tee.h>
 
 /**
  * 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
index 9fc31203cf1979d39c055a449147c713f5184e96..232a204f8b320b9a5c4fe0a03542bf60a1097b67 100644 (file)
@@ -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 (file)
index 0000000..ea6c19f
--- /dev/null
@@ -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 <linux/spinlock.h>
+#include <linux/dma-mapping.h>
+#include <linux/err.h>
+#include <linux/genalloc.h>
+#include <linux/io.h>
+#include <linux/mm.h>
+#include <linux/scatterlist.h>
+#include <linux/slab.h>
+#include <linux/vmalloc.h>
+#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;
+}
index 668ca6aa6046eb8d189d378770648bd60b0722d0..c41aa46f1f0ecf80be676ebc86287fdc45bea897 100644 (file)
@@ -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__,
index 314e6bdff6dd7d6be833983e4184a1dad818f1b6..c1ad18b371466628bdbbfa9d551ae8f9a66ae6e8 100644 (file)
@@ -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 (file)
index 0000000..6e908c9
--- /dev/null
@@ -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 <linux/spinlock.h>
+#include <linux/dma-mapping.h>
+#include <linux/err.h>
+#include <linux/genalloc.h>
+#include <linux/io.h>
+#include <linux/mm.h>
+#include <linux/scatterlist.h>
+#include <linux/slab.h>
+#include <linux/vmalloc.h>
+#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;
+}