2 * Copyright (C) 2013 Broadcom Corporation
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License as
6 * published by the Free Software Foundation version 2.
8 * This program is distributed "as is" WITHOUT ANY WARRANTY of any
9 * kind, whether express or implied; without even the implied warranty
10 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
15 #include <linux/smp.h>
17 #include <linux/ioport.h>
19 #include <asm/cacheflush.h>
20 #include <linux/of_address.h>
22 #include "bcm_kona_smc.h"
24 struct secure_bridge_data
{
25 void __iomem
*bounce
; /* virtual address */
26 u32 __iomem buffer_addr
; /* physical address */
30 struct bcm_kona_smc_data
{
38 static const struct of_device_id bcm_kona_smc_ids
[] __initconst
= {
39 {.compatible
= "bcm,kona-smc"},
43 /* Map in the bounce area */
44 void __init
bcm_kona_smc_init(void)
46 struct device_node
*node
;
48 /* Read buffer addr and size from the device tree node */
49 node
= of_find_matching_node(NULL
, bcm_kona_smc_ids
);
52 /* Don't care about size or flags of the DT node */
53 bridge_data
.buffer_addr
=
54 be32_to_cpu(*of_get_address(node
, 0, NULL
, NULL
));
55 BUG_ON(!bridge_data
.buffer_addr
);
57 bridge_data
.bounce
= of_iomap(node
, 0);
58 BUG_ON(!bridge_data
.bounce
);
60 bridge_data
.initialized
= 1;
62 pr_info("Secure API initialized!\n");
65 /* __bcm_kona_smc() should only run on CPU 0, with pre-emption disabled */
66 static void __bcm_kona_smc(void *info
)
68 struct bcm_kona_smc_data
*data
= info
;
69 u32
*args
= bridge_data
.bounce
;
72 /* Must run on CPU 0 */
73 BUG_ON(smp_processor_id() != 0);
75 /* Check map in the bounce area */
76 BUG_ON(!bridge_data
.initialized
);
78 /* Copy one 32 bit word into the bounce area */
84 /* Flush caches for input data passed to Secure Monitor */
85 if (data
->service_id
!= SSAPI_BRCM_START_VC_CORE
)
88 /* Trap into Secure Monitor */
89 rc
= bcm_kona_smc_asm(data
->service_id
, bridge_data
.buffer_addr
);
91 if (rc
!= SEC_ROM_RET_OK
)
92 pr_err("Secure Monitor call failed (0x%x)!\n", rc
);
95 unsigned bcm_kona_smc(unsigned service_id
, unsigned arg0
, unsigned arg1
,
96 unsigned arg2
, unsigned arg3
)
98 struct bcm_kona_smc_data data
;
100 data
.service_id
= service_id
;
107 * Due to a limitation of the secure monitor, we must use the SMP
108 * infrastructure to forward all secure monitor calls to Core 0.
111 smp_call_function_single(0, __bcm_kona_smc
, (void *)&data
, 1);
113 __bcm_kona_smc(&data
);