Commit | Line | Data |
---|---|---|
ba9456ac SS |
1 | /* |
2 | * OMAP Secure API infrastructure. | |
3 | * | |
4 | * Copyright (C) 2011 Texas Instruments, Inc. | |
5 | * Santosh Shilimkar <santosh.shilimkar@ti.com> | |
6 | * | |
7 | * | |
8 | * This program is free software,you can redistribute it and/or modify | |
9 | * it under the terms of the GNU General Public License version 2 as | |
10 | * published by the Free Software Foundation. | |
11 | */ | |
12 | ||
13 | #include <linux/kernel.h> | |
14 | #include <linux/init.h> | |
15 | #include <linux/io.h> | |
259ee57a | 16 | #include <linux/memblock.h> |
ba9456ac SS |
17 | |
18 | #include <asm/cacheflush.h> | |
19 | ||
20 | #include <mach/omap-secure.h> | |
21 | ||
259ee57a SS |
22 | static phys_addr_t omap_secure_memblock_base; |
23 | ||
ba9456ac SS |
24 | /** |
25 | * omap_sec_dispatcher: Routine to dispatch low power secure | |
26 | * service routines | |
27 | * @idx: The HAL API index | |
28 | * @flag: The flag indicating criticality of operation | |
29 | * @nargs: Number of valid arguments out of four. | |
30 | * @arg1, arg2, arg3 args4: Parameters passed to secure API | |
31 | * | |
32 | * Return the non-zero error value on failure. | |
33 | */ | |
34 | u32 omap_secure_dispatcher(u32 idx, u32 flag, u32 nargs, u32 arg1, u32 arg2, | |
35 | u32 arg3, u32 arg4) | |
36 | { | |
37 | u32 ret; | |
38 | u32 param[5]; | |
39 | ||
40 | param[0] = nargs; | |
41 | param[1] = arg1; | |
42 | param[2] = arg2; | |
43 | param[3] = arg3; | |
44 | param[4] = arg4; | |
45 | ||
46 | /* | |
47 | * Secure API needs physical address | |
48 | * pointer for the parameters | |
49 | */ | |
50 | flush_cache_all(); | |
51 | outer_clean_range(__pa(param), __pa(param + 5)); | |
52 | ret = omap_smc2(idx, flag, __pa(param)); | |
53 | ||
54 | return ret; | |
55 | } | |
259ee57a SS |
56 | |
57 | /* Allocate the memory to save secure ram */ | |
58 | int __init omap_secure_ram_reserve_memblock(void) | |
59 | { | |
60 | phys_addr_t paddr; | |
61 | u32 size = OMAP_SECURE_RAM_STORAGE; | |
62 | ||
63 | size = ALIGN(size, SZ_1M); | |
64 | paddr = memblock_alloc(size, SZ_1M); | |
65 | if (!paddr) { | |
66 | pr_err("%s: failed to reserve %x bytes\n", | |
67 | __func__, size); | |
68 | return -ENOMEM; | |
69 | } | |
70 | memblock_free(paddr, size); | |
71 | memblock_remove(paddr, size); | |
72 | ||
73 | omap_secure_memblock_base = paddr; | |
74 | ||
75 | return 0; | |
76 | } | |
77 | ||
78 | phys_addr_t omap_secure_ram_mempool_base(void) | |
79 | { | |
80 | return omap_secure_memblock_base; | |
81 | } |