diff --git a/arch/arm64/boot/dts/amlogic/axg_pxp.dts b/arch/arm64/boot/dts/amlogic/axg_pxp.dts index f9fe61a489e8..3e9899dfebe2 100644 --- a/arch/arm64/boot/dts/amlogic/axg_pxp.dts +++ b/arch/arm64/boot/dts/amlogic/axg_pxp.dts @@ -41,9 +41,11 @@ ranges; /* global autoconfigured region for contiguous allocations */ secmon_reserved:linux,secmon { - compatible = "amlogic, aml_secmon_memory"; - reg = <0x0 0x10000000 0x0 0x200000>; - no-map; + compatible = "shared-dma-pool"; + reusable; + size = <0x0 0x400000>; + alignment = <0x0 0x400000>; + alloc-ranges = <0x0 0x05000000 0x0 0x400000>; }; secos_reserved:linux,secos { diff --git a/arch/arm64/boot/dts/amlogic/gxl_p212_1g.dts b/arch/arm64/boot/dts/amlogic/gxl_p212_1g.dts index 7c0734aeec78..490c248dee4c 100644 --- a/arch/arm64/boot/dts/amlogic/gxl_p212_1g.dts +++ b/arch/arm64/boot/dts/amlogic/gxl_p212_1g.dts @@ -50,9 +50,11 @@ ranges; /* global autoconfigured region for contiguous allocations */ secmon_reserved:linux,secmon { - compatible = "amlogic, aml_secmon_memory"; - reg = <0x0 0x10000000 0x0 0x200000>; - no-map; + compatible = "shared-dma-pool"; + reusable; + size = <0x0 0x400000>; + alignment = <0x0 0x400000>; + alloc-ranges = <0x0 0x05000000 0x0 0x400000>; }; secos_reserved:linux,secos { status = "disable"; diff --git a/arch/arm64/boot/dts/amlogic/gxl_p212_2g.dts b/arch/arm64/boot/dts/amlogic/gxl_p212_2g.dts index 947123274579..59cd4893dbec 100644 --- a/arch/arm64/boot/dts/amlogic/gxl_p212_2g.dts +++ b/arch/arm64/boot/dts/amlogic/gxl_p212_2g.dts @@ -51,9 +51,11 @@ ranges; /* global autoconfigured region for contiguous allocations */ secmon_reserved:linux,secmon { - compatible = "amlogic, aml_secmon_memory"; - reg = <0x0 0x10000000 0x0 0x200000>; - no-map; + compatible = "shared-dma-pool"; + reusable; + size = <0x0 0x400000>; + alignment = <0x0 0x400000>; + alloc-ranges = <0x0 0x05000000 0x0 0x400000>; }; secos_reserved:linux,secos { status = "disable"; diff --git a/arch/arm64/boot/dts/amlogic/gxl_p400_2g.dts b/arch/arm64/boot/dts/amlogic/gxl_p400_2g.dts index bef11679777f..9e85528d2672 100644 --- a/arch/arm64/boot/dts/amlogic/gxl_p400_2g.dts +++ b/arch/arm64/boot/dts/amlogic/gxl_p400_2g.dts @@ -47,9 +47,11 @@ ranges; /* global autoconfigured region for contiguous allocations */ secmon_reserved:linux,secmon { - compatible = "amlogic, aml_secmon_memory"; - reg = <0x0 0x10000000 0x0 0x200000>; - no-map; + compatible = "shared-dma-pool"; + reusable; + size = <0x0 0x400000>; + alignment = <0x0 0x400000>; + alloc-ranges = <0x0 0x05000000 0x0 0x400000>; }; secos_reserved:linux,secos { status = "disable"; diff --git a/arch/arm64/boot/dts/amlogic/gxl_p401_2g.dts b/arch/arm64/boot/dts/amlogic/gxl_p401_2g.dts index 29bce089f897..3f7299ae5909 100644 --- a/arch/arm64/boot/dts/amlogic/gxl_p401_2g.dts +++ b/arch/arm64/boot/dts/amlogic/gxl_p401_2g.dts @@ -47,9 +47,11 @@ ranges; /* global autoconfigured region for contiguous allocations */ secmon_reserved:linux,secmon { - compatible = "amlogic, aml_secmon_memory"; - reg = <0x0 0x10000000 0x0 0x200000>; - no-map; + compatible = "shared-dma-pool"; + reusable; + size = <0x0 0x400000>; + alignment = <0x0 0x400000>; + alloc-ranges = <0x0 0x05000000 0x0 0x400000>; }; secos_reserved:linux,secos { status = "disable"; diff --git a/arch/arm64/boot/dts/amlogic/gxl_skt.dts b/arch/arm64/boot/dts/amlogic/gxl_skt.dts index 529330a7882a..a8486f3ec2ee 100644 --- a/arch/arm64/boot/dts/amlogic/gxl_skt.dts +++ b/arch/arm64/boot/dts/amlogic/gxl_skt.dts @@ -50,9 +50,11 @@ ranges; /* global autoconfigured region for contiguous allocations */ secmon_reserved:linux,secmon { - compatible = "amlogic, aml_secmon_memory"; - reg = <0x0 0x10000000 0x0 0x200000>; - no-map; + compatible = "shared-dma-pool"; + reusable; + size = <0x0 0x400000>; + alignment = <0x0 0x400000>; + alloc-ranges = <0x0 0x05000000 0x0 0x400000>; }; secos_reserved:linux,secos { status = "disable"; diff --git a/arch/arm64/boot/dts/amlogic/gxm_q200_2g.dts b/arch/arm64/boot/dts/amlogic/gxm_q200_2g.dts index c688429bae46..f4a496d34fb1 100644 --- a/arch/arm64/boot/dts/amlogic/gxm_q200_2g.dts +++ b/arch/arm64/boot/dts/amlogic/gxm_q200_2g.dts @@ -50,9 +50,11 @@ ranges; /* global autoconfigured region for contiguous allocations */ secmon_reserved:linux,secmon { - compatible = "amlogic, aml_secmon_memory"; - reg = <0x0 0x10000000 0x0 0x200000>; - no-map; + compatible = "shared-dma-pool"; + reusable; + size = <0x0 0x400000>; + alignment = <0x0 0x400000>; + alloc-ranges = <0x0 0x05000000 0x0 0x400000>; }; secos_reserved:linux,secos { status = "disable"; diff --git a/arch/arm64/boot/dts/amlogic/gxm_skt.dts b/arch/arm64/boot/dts/amlogic/gxm_skt.dts index bbe1112cef68..d42ca2a561aa 100644 --- a/arch/arm64/boot/dts/amlogic/gxm_skt.dts +++ b/arch/arm64/boot/dts/amlogic/gxm_skt.dts @@ -51,9 +51,11 @@ ranges; /* global autoconfigured region for contiguous allocations */ secmon_reserved:linux,secmon { - compatible = "amlogic, aml_secmon_memory"; - reg = <0x0 0x10000000 0x0 0x200000>; - no-map; + compatible = "shared-dma-pool"; + reusable; + size = <0x0 0x400000>; + alignment = <0x0 0x400000>; + alloc-ranges = <0x0 0x05000000 0x0 0x400000>; }; secos_reserved:linux,secos { status = "disable"; diff --git a/arch/arm64/boot/dts/amlogic/mesonaxg.dtsi b/arch/arm64/boot/dts/amlogic/mesonaxg.dtsi index 4a6597ed7578..ae42ba9fc5ec 100644 --- a/arch/arm64/boot/dts/amlogic/mesonaxg.dtsi +++ b/arch/arm64/boot/dts/amlogic/mesonaxg.dtsi @@ -99,6 +99,7 @@ memory-region = <&secmon_reserved>; in_base_func = <0x82000020>; out_base_func = <0x82000021>; + reserve_mem_size = <0x00300000>; }; cpu_iomap { diff --git a/arch/arm64/boot/dts/amlogic/mesongxl.dtsi b/arch/arm64/boot/dts/amlogic/mesongxl.dtsi index b040ba1f74cd..956e10c1996a 100644 --- a/arch/arm64/boot/dts/amlogic/mesongxl.dtsi +++ b/arch/arm64/boot/dts/amlogic/mesongxl.dtsi @@ -167,6 +167,7 @@ memory-region = <&secmon_reserved>; in_base_func = <0x82000020>; out_base_func = <0x82000021>; + reserve_mem_size = <0x00300000>; }; securitykey { diff --git a/arch/arm64/boot/dts/amlogic/mesongxm.dtsi b/arch/arm64/boot/dts/amlogic/mesongxm.dtsi index cd0f2133f40c..171a6478bde7 100644 --- a/arch/arm64/boot/dts/amlogic/mesongxm.dtsi +++ b/arch/arm64/boot/dts/amlogic/mesongxm.dtsi @@ -280,6 +280,7 @@ memory-region = <&secmon_reserved>; in_base_func = <0x82000020>; out_base_func = <0x82000021>; + reserve_mem_size = <0x00300000>; }; securitykey { diff --git a/drivers/amlogic/secmon/secmon.c b/drivers/amlogic/secmon/secmon.c index aa4f2f414844..84085109313f 100644 --- a/drivers/amlogic/secmon/secmon.c +++ b/drivers/amlogic/secmon/secmon.c @@ -24,6 +24,7 @@ #include #include #include +#include #include #ifndef CONFIG_ARM64 #include @@ -45,12 +46,18 @@ static DEFINE_MUTEX(sharemem_mutex); #ifdef CONFIG_ARM64 static long get_sharemem_info(unsigned int function_id) { - asm volatile( - __asmeq("%0", "x0") - "smc #0\n" - : "+r" (function_id)); + long ret; - return function_id; + asm volatile( + "mov x0, %[function_id] \n" + "smc #0 \n" + "mov %[ret], x0 \n" + : [ret] "=r" (ret) + : [function_id] "r" (function_id) + : "memory", "cc", "x0" + ); + + return ret; } #else static long get_sharemem_info(unsigned int function_id) @@ -66,11 +73,15 @@ static long get_sharemem_info(unsigned int function_id) return r0; } #endif + +#define RESERVE_MEM_SIZE 0x300000 static int secmon_probe(struct platform_device *pdev) { struct device_node *np = pdev->dev.of_node; unsigned int id; int ret; + int mem_size; + struct page *page; if (!of_property_read_u32(np, "in_base_func", &id)) phy_in_base = get_sharemem_info(id); @@ -78,9 +89,39 @@ static int secmon_probe(struct platform_device *pdev) if (!of_property_read_u32(np, "out_base_func", &id)) phy_out_base = get_sharemem_info(id); + if (of_property_read_u32(np, "reserve_mem_size", &mem_size)) { + pr_err("can't get reserve_mem_size, use default value\n"); + mem_size = RESERVE_MEM_SIZE; + } else + pr_debug("reserve_mem_size:0x%x\n", mem_size); + ret = of_reserved_mem_device_init(&pdev->dev); - if (ret == 0) - pr_info("probe done\n"); + if (ret) { + pr_info("reserve memory init fail:%d\n", ret); + return ret; + } + + page = dma_alloc_from_contiguous(&pdev->dev, mem_size >> PAGE_SHIFT, 0); + if (!page) { + pr_err("alloc page failed, ret:%p\n", page); + return -ENOMEM; + } + pr_debug("get page:%p, %lx\n", page, page_to_pfn(page)); + + sharemem_in_base = ioremap_cache(phy_in_base, IN_SIZE); + if (!sharemem_in_base) { + pr_info("secmon share mem in buffer remap fail!\n"); + return -ENOMEM; + } + sharemem_out_base = ioremap_cache(phy_out_base, OUT_SIZE); + if (!sharemem_out_base) { + pr_info("secmon share mem out buffer remap fail!\n"); + return -ENOMEM; + } + pr_info("share in base: 0x%lx, share out base: 0x%lx\n", + (long)sharemem_in_base, (long)sharemem_out_base); + pr_info("phy_in_base: 0x%lx, phy_out_base: 0x%lx\n", + phy_in_base, phy_out_base); return ret; } @@ -122,33 +163,3 @@ void __iomem *get_secmon_sharemem_output_base(void) { return sharemem_out_base; } - -static int secmon_mem_device_init(struct reserved_mem *rmem, struct device *dev) -{ - sharemem_in_base = ioremap_cache(phy_in_base, IN_SIZE); - if (!sharemem_in_base) { - pr_info("secmon share mem in buffer remap fail!\n"); - return -ENOMEM; - } - sharemem_out_base = ioremap_cache(phy_out_base, OUT_SIZE); - if (!sharemem_out_base) { - pr_info("secmon share mem out buffer remap fail!\n"); - return -ENOMEM; - } - pr_info("share in base: 0x%lx, share out base: 0x%lx\n", - (long)sharemem_in_base, (long)sharemem_out_base); - return 0; -} -static const struct reserved_mem_ops rmem_secmon_ops = { - .device_init = secmon_mem_device_init, -}; -static int __init secmon_mem_setup(struct reserved_mem *rmem) -{ - rmem->ops = &rmem_secmon_ops; - pr_debug("share mem setup\n"); - - return 0; -} - -RESERVEDMEM_OF_DECLARE(secmonmem, "amlogic, aml_secmon_memory", - secmon_mem_setup);