diff options
author | Alex Elder <elder@linaro.org> | 2014-04-21 17:53:04 -0400 |
---|---|---|
committer | Matt Porter <mporter@linaro.org> | 2014-04-25 08:51:32 -0400 |
commit | c64756cca2fb4da96fcc71e376d712297aedc4a2 (patch) | |
tree | 14d8e483b7e6e2b27f406bceeffb050a903eb442 /arch/arm/mach-bcm | |
parent | 5c4cee2fe8de7c14e60502b02e7c3bc7acba0530 (diff) |
ARM: bcm: clean up SMC code
This patch just does some simple cleanup in "bcm_kona_smc.c":
- Get rid of the secure_bridge_data structure. Instead, just
define two globals that record the physical and virtual
addresses of the SMC arguments buffer. Use "buffer" instead
of "bounce" in their names. Drop of the erroneous __iomem
annotation for the physical address.
- Get rid of the initialized flag and just use a non-null buffer
address to indicate that.
- Get the size of the memory region when fetching the SMC
arguments buffer location from the device tree. Use it to
call ioremap() directly rather than requiring of_iomap() to
go look it up again.
- Do some additional validation on that memory region size.
- Flush caches unconditionally in __bcm_kona_smc(); nothing
supplies SSAPI_BRCM_START_VC_CORE as a service id.
- Drop a needless initialization of "rc" in __bcm_kona_smc().
It also deletes most of the content of "bcm_kona_smc.h" because it's
never actually used and is of questionable value anyway.
Signed-off-by: Alex Elder <elder@linaro.org>
Reviewed-by: Tim Kryger <tim.kryger@linaro.org>
Reviewed-by: Markus Mayer <markus.mayer@linaro.org>
Reviewed-by: Matt Porter <mporter@linaro.org>
Signed-off-by: Matt Porter <mporter@linaro.org>
Diffstat (limited to 'arch/arm/mach-bcm')
-rw-r--r-- | arch/arm/mach-bcm/bcm_kona_smc.c | 45 | ||||
-rw-r--r-- | arch/arm/mach-bcm/bcm_kona_smc.h | 46 |
2 files changed, 24 insertions, 67 deletions
diff --git a/arch/arm/mach-bcm/bcm_kona_smc.c b/arch/arm/mach-bcm/bcm_kona_smc.c index ddc2f17217ee..0d2bfe2bcfa8 100644 --- a/arch/arm/mach-bcm/bcm_kona_smc.c +++ b/arch/arm/mach-bcm/bcm_kona_smc.c | |||
@@ -21,11 +21,8 @@ | |||
21 | 21 | ||
22 | #include "bcm_kona_smc.h" | 22 | #include "bcm_kona_smc.h" |
23 | 23 | ||
24 | struct secure_bridge_data { | 24 | static u32 bcm_smc_buffer_phys; /* physical address */ |
25 | void __iomem *bounce; /* virtual address */ | 25 | static void __iomem *bcm_smc_buffer; /* virtual address */ |
26 | u32 __iomem buffer_addr; /* physical address */ | ||
27 | int initialized; | ||
28 | } bridge_data; | ||
29 | 26 | ||
30 | struct bcm_kona_smc_data { | 27 | struct bcm_kona_smc_data { |
31 | unsigned service_id; | 28 | unsigned service_id; |
@@ -41,31 +38,37 @@ static const struct of_device_id bcm_kona_smc_ids[] __initconst = { | |||
41 | {}, | 38 | {}, |
42 | }; | 39 | }; |
43 | 40 | ||
44 | /* Map in the bounce area */ | 41 | /* Map in the args buffer area */ |
45 | int __init bcm_kona_smc_init(void) | 42 | int __init bcm_kona_smc_init(void) |
46 | { | 43 | { |
47 | struct device_node *node; | 44 | struct device_node *node; |
48 | const __be32 *prop_val; | 45 | const __be32 *prop_val; |
46 | u64 prop_size = 0; | ||
47 | unsigned long buffer_size; | ||
48 | u32 buffer_phys; | ||
49 | 49 | ||
50 | /* Read buffer addr and size from the device tree node */ | 50 | /* Read buffer addr and size from the device tree node */ |
51 | node = of_find_matching_node(NULL, bcm_kona_smc_ids); | 51 | node = of_find_matching_node(NULL, bcm_kona_smc_ids); |
52 | if (!node) | 52 | if (!node) |
53 | return -ENODEV; | 53 | return -ENODEV; |
54 | 54 | ||
55 | /* Don't care about size or flags of the DT node */ | 55 | prop_val = of_get_address(node, 0, &prop_size, NULL); |
56 | prop_val = of_get_address(node, 0, NULL, NULL); | ||
57 | if (!prop_val) | 56 | if (!prop_val) |
58 | return -EINVAL; | 57 | return -EINVAL; |
59 | 58 | ||
60 | bridge_data.buffer_addr = be32_to_cpu(*prop_val); | 59 | /* We assume space for four 32-bit arguments */ |
61 | if (!bridge_data.buffer_addr) | 60 | if (prop_size < 4 * sizeof(u32) || prop_size > (u64)ULONG_MAX) |
62 | return -EINVAL; | 61 | return -EINVAL; |
62 | buffer_size = (unsigned long)prop_size; | ||
63 | 63 | ||
64 | bridge_data.bounce = of_iomap(node, 0); | 64 | buffer_phys = be32_to_cpup(prop_val); |
65 | if (!bridge_data.bounce) | 65 | if (!buffer_phys) |
66 | return -ENOMEM; | 66 | return -EINVAL; |
67 | 67 | ||
68 | bridge_data.initialized = 1; | 68 | bcm_smc_buffer = ioremap(buffer_phys, buffer_size); |
69 | if (!bcm_smc_buffer) | ||
70 | return -ENOMEM; | ||
71 | bcm_smc_buffer_phys = buffer_phys; | ||
69 | 72 | ||
70 | pr_info("Kona Secure API initialized\n"); | 73 | pr_info("Kona Secure API initialized\n"); |
71 | 74 | ||
@@ -76,14 +79,11 @@ int __init bcm_kona_smc_init(void) | |||
76 | static void __bcm_kona_smc(void *info) | 79 | static void __bcm_kona_smc(void *info) |
77 | { | 80 | { |
78 | struct bcm_kona_smc_data *data = info; | 81 | struct bcm_kona_smc_data *data = info; |
79 | u32 *args = bridge_data.bounce; | 82 | u32 *args = bcm_smc_buffer; |
80 | int rc = 0; | 83 | int rc; |
81 | 84 | ||
82 | /* Must run on CPU 0 */ | ||
83 | BUG_ON(smp_processor_id() != 0); | 85 | BUG_ON(smp_processor_id() != 0); |
84 | 86 | BUG_ON(!args); | |
85 | /* Check map in the bounce area */ | ||
86 | BUG_ON(!bridge_data.initialized); | ||
87 | 87 | ||
88 | /* Copy the four 32 bit argument values into the bounce area */ | 88 | /* Copy the four 32 bit argument values into the bounce area */ |
89 | writel_relaxed(data->arg0, args++); | 89 | writel_relaxed(data->arg0, args++); |
@@ -92,11 +92,10 @@ static void __bcm_kona_smc(void *info) | |||
92 | writel(data->arg3, args); | 92 | writel(data->arg3, args); |
93 | 93 | ||
94 | /* Flush caches for input data passed to Secure Monitor */ | 94 | /* Flush caches for input data passed to Secure Monitor */ |
95 | if (data->service_id != SSAPI_BRCM_START_VC_CORE) | 95 | flush_cache_all(); |
96 | flush_cache_all(); | ||
97 | 96 | ||
98 | /* Trap into Secure Monitor */ | 97 | /* Trap into Secure Monitor */ |
99 | rc = bcm_kona_smc_asm(data->service_id, bridge_data.buffer_addr); | 98 | rc = bcm_kona_smc_asm(data->service_id, bcm_smc_buffer_phys); |
100 | 99 | ||
101 | if (rc != SEC_ROM_RET_OK) | 100 | if (rc != SEC_ROM_RET_OK) |
102 | pr_err("Secure Monitor call failed (0x%x)!\n", rc); | 101 | pr_err("Secure Monitor call failed (0x%x)!\n", rc); |
diff --git a/arch/arm/mach-bcm/bcm_kona_smc.h b/arch/arm/mach-bcm/bcm_kona_smc.h index d098a7e76744..629e64a89982 100644 --- a/arch/arm/mach-bcm/bcm_kona_smc.h +++ b/arch/arm/mach-bcm/bcm_kona_smc.h | |||
@@ -15,54 +15,12 @@ | |||
15 | #define BCM_KONA_SMC_H | 15 | #define BCM_KONA_SMC_H |
16 | 16 | ||
17 | #include <linux/types.h> | 17 | #include <linux/types.h> |
18 | #define FLAGS (SEC_ROM_ICACHE_ENABLE_MASK | SEC_ROM_DCACHE_ENABLE_MASK | \ | ||
19 | SEC_ROM_IRQ_ENABLE_MASK | SEC_ROM_FIQ_ENABLE_MASK) | ||
20 | 18 | ||
21 | /*! | 19 | /* Broadcom Secure Service API service IDs, return codes, and exit codes */ |
22 | * Definitions for IRQ & FIQ Mask for ARM | 20 | #define SSAPI_ENABLE_L2_CACHE 0x01000002 |
23 | */ | ||
24 | |||
25 | #define FIQ_IRQ_MASK 0xC0 | ||
26 | #define FIQ_MASK 0x40 | ||
27 | #define IRQ_MASK 0x80 | ||
28 | |||
29 | /*! | ||
30 | * Secure Mode FLAGs | ||
31 | */ | ||
32 | |||
33 | /* When set, enables ICache within the secure mode */ | ||
34 | #define SEC_ROM_ICACHE_ENABLE_MASK 0x00000001 | ||
35 | |||
36 | /* When set, enables DCache within the secure mode */ | ||
37 | #define SEC_ROM_DCACHE_ENABLE_MASK 0x00000002 | ||
38 | |||
39 | /* When set, enables IRQ within the secure mode */ | ||
40 | #define SEC_ROM_IRQ_ENABLE_MASK 0x00000004 | ||
41 | |||
42 | /* When set, enables FIQ within the secure mode */ | ||
43 | #define SEC_ROM_FIQ_ENABLE_MASK 0x00000008 | ||
44 | |||
45 | /* When set, enables Unified L2 cache within the secure mode */ | ||
46 | #define SEC_ROM_UL2_CACHE_ENABLE_MASK 0x00000010 | ||
47 | |||
48 | /* Broadcom Secure Service API Service IDs */ | ||
49 | #define SSAPI_DORMANT_ENTRY_SERV 0x01000000 | ||
50 | #define SSAPI_PUBLIC_OTP_SERV 0x01000001 | ||
51 | #define SSAPI_ENABLE_L2_CACHE 0x01000002 | ||
52 | #define SSAPI_DISABLE_L2_CACHE 0x01000003 | ||
53 | #define SSAPI_WRITE_SCU_STATUS 0x01000004 | ||
54 | #define SSAPI_WRITE_PWR_GATE 0x01000005 | ||
55 | |||
56 | /* Broadcom Secure Service API Return Codes */ | ||
57 | #define SEC_ROM_RET_OK 0x00000001 | 21 | #define SEC_ROM_RET_OK 0x00000001 |
58 | #define SEC_ROM_RET_FAIL 0x00000009 | ||
59 | |||
60 | #define SSAPI_RET_FROM_INT_SERV 0x4 | ||
61 | #define SEC_EXIT_NORMAL 0x1 | 22 | #define SEC_EXIT_NORMAL 0x1 |
62 | 23 | ||
63 | #define SSAPI_ROW_AES 0x0E000006 | ||
64 | #define SSAPI_BRCM_START_VC_CORE 0x0E000008 | ||
65 | |||
66 | #ifndef __ASSEMBLY__ | 24 | #ifndef __ASSEMBLY__ |
67 | extern int __init bcm_kona_smc_init(void); | 25 | extern int __init bcm_kona_smc_init(void); |
68 | 26 | ||