mm: change secmon reserved memory to CMA

PD#143278: change secmon reserved memory to CMA

Change-Id: Ia09a9a1b578f1a10e81d9431f829c723c68811d9
Signed-off-by: Tao Zeng <tao.zeng@amlogic.com>
This commit is contained in:
Tao Zeng
2017-05-04 09:44:35 +08:00
committed by Jianxin Pan
parent 98454da295
commit 940abdab8c
12 changed files with 91 additions and 61 deletions

View File

@@ -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 {

View File

@@ -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";

View File

@@ -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";

View File

@@ -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";

View File

@@ -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";

View File

@@ -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";

View File

@@ -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";

View File

@@ -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";

View File

@@ -99,6 +99,7 @@
memory-region = <&secmon_reserved>;
in_base_func = <0x82000020>;
out_base_func = <0x82000021>;
reserve_mem_size = <0x00300000>;
};
cpu_iomap {

View File

@@ -167,6 +167,7 @@
memory-region = <&secmon_reserved>;
in_base_func = <0x82000020>;
out_base_func = <0x82000021>;
reserve_mem_size = <0x00300000>;
};
securitykey {

View File

@@ -280,6 +280,7 @@
memory-region = <&secmon_reserved>;
in_base_func = <0x82000020>;
out_base_func = <0x82000021>;
reserve_mem_size = <0x00300000>;
};
securitykey {

View File

@@ -24,6 +24,7 @@
#include <linux/of_reserved_mem.h>
#include <linux/io.h>
#include <linux/platform_device.h>
#include <linux/dma-contiguous.h>
#include <asm/compiler.h>
#ifndef CONFIG_ARM64
#include <asm/opcodes-sec.h>
@@ -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);