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 static u32 bcm_smc_buffer_phys; /* physical address */
25 static void __iomem *bcm_smc_buffer; /* virtual address */
27 struct bcm_kona_smc_data {
35 static const struct of_device_id bcm_kona_smc_ids[] __initconst = {
36 {.compatible = "brcm,kona-smc"},
37 {.compatible = "bcm,kona-smc"}, /* deprecated name */
41 /* Map in the args buffer area */
42 int __init bcm_kona_smc_init(void)
44 struct device_node *node;
45 const __be32 *prop_val;
47 unsigned long buffer_size;
50 /* Read buffer addr and size from the device tree node */
51 node = of_find_matching_node(NULL, bcm_kona_smc_ids);
55 prop_val = of_get_address(node, 0, &prop_size, NULL);
59 /* We assume space for four 32-bit arguments */
60 if (prop_size < 4 * sizeof(u32) || prop_size > (u64)ULONG_MAX)
62 buffer_size = (unsigned long)prop_size;
64 buffer_phys = be32_to_cpup(prop_val);
68 bcm_smc_buffer = ioremap(buffer_phys, buffer_size);
71 bcm_smc_buffer_phys = buffer_phys;
73 pr_info("Kona Secure API initialized\n");
78 /* __bcm_kona_smc() should only run on CPU 0, with pre-emption disabled */
79 static void __bcm_kona_smc(void *info)
81 struct bcm_kona_smc_data *data = info;
82 u32 *args = bcm_smc_buffer;
85 BUG_ON(smp_processor_id() != 0);
88 /* Copy the four 32 bit argument values into the bounce area */
89 writel_relaxed(data->arg0, args++);
90 writel_relaxed(data->arg1, args++);
91 writel_relaxed(data->arg2, args++);
92 writel(data->arg3, args);
94 /* Flush caches for input data passed to Secure Monitor */
97 /* Trap into Secure Monitor */
98 rc = bcm_kona_smc_asm(data->service_id, bcm_smc_buffer_phys);
100 if (rc != SEC_ROM_RET_OK)
101 pr_err("Secure Monitor call failed (0x%x)!\n", rc);
104 unsigned bcm_kona_smc(unsigned service_id, unsigned arg0, unsigned arg1,
105 unsigned arg2, unsigned arg3)
107 struct bcm_kona_smc_data data;
109 data.service_id = service_id;
116 * Due to a limitation of the secure monitor, we must use the SMP
117 * infrastructure to forward all secure monitor calls to Core 0.
120 smp_call_function_single(0, __bcm_kona_smc, (void *)&data, 1);
122 __bcm_kona_smc(&data);