bcm_kona_smc.c 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. /*
  2. * Copyright (C) 2013 Broadcom Corporation
  3. *
  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.
  7. *
  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.
  12. */
  13. #include <stdarg.h>
  14. #include <linux/smp.h>
  15. #include <linux/io.h>
  16. #include <linux/ioport.h>
  17. #include <asm/cacheflush.h>
  18. #include <linux/of_address.h>
  19. #include "bcm_kona_smc.h"
  20. struct secure_bridge_data {
  21. void __iomem *bounce; /* virtual address */
  22. u32 __iomem buffer_addr; /* physical address */
  23. int initialized;
  24. } bridge_data;
  25. struct bcm_kona_smc_data {
  26. unsigned service_id;
  27. unsigned arg0;
  28. unsigned arg1;
  29. unsigned arg2;
  30. unsigned arg3;
  31. };
  32. static const struct of_device_id bcm_kona_smc_ids[] __initconst = {
  33. {.compatible = "brcm,kona-smc"},
  34. {.compatible = "bcm,kona-smc"}, /* deprecated name */
  35. {},
  36. };
  37. /* Map in the bounce area */
  38. int __init bcm_kona_smc_init(void)
  39. {
  40. struct device_node *node;
  41. /* Read buffer addr and size from the device tree node */
  42. node = of_find_matching_node(NULL, bcm_kona_smc_ids);
  43. if (!node)
  44. return -ENODEV;
  45. /* Don't care about size or flags of the DT node */
  46. bridge_data.buffer_addr =
  47. be32_to_cpu(*of_get_address(node, 0, NULL, NULL));
  48. BUG_ON(!bridge_data.buffer_addr);
  49. bridge_data.bounce = of_iomap(node, 0);
  50. BUG_ON(!bridge_data.bounce);
  51. bridge_data.initialized = 1;
  52. pr_info("Kona Secure API initialized\n");
  53. return 0;
  54. }
  55. /* __bcm_kona_smc() should only run on CPU 0, with pre-emption disabled */
  56. static void __bcm_kona_smc(void *info)
  57. {
  58. struct bcm_kona_smc_data *data = info;
  59. u32 *args = bridge_data.bounce;
  60. int rc = 0;
  61. /* Must run on CPU 0 */
  62. BUG_ON(smp_processor_id() != 0);
  63. /* Check map in the bounce area */
  64. BUG_ON(!bridge_data.initialized);
  65. /* Copy one 32 bit word into the bounce area */
  66. args[0] = data->arg0;
  67. args[1] = data->arg1;
  68. args[2] = data->arg2;
  69. args[3] = data->arg3;
  70. /* Flush caches for input data passed to Secure Monitor */
  71. if (data->service_id != SSAPI_BRCM_START_VC_CORE)
  72. flush_cache_all();
  73. /* Trap into Secure Monitor */
  74. rc = bcm_kona_smc_asm(data->service_id, bridge_data.buffer_addr);
  75. if (rc != SEC_ROM_RET_OK)
  76. pr_err("Secure Monitor call failed (0x%x)!\n", rc);
  77. }
  78. unsigned bcm_kona_smc(unsigned service_id, unsigned arg0, unsigned arg1,
  79. unsigned arg2, unsigned arg3)
  80. {
  81. struct bcm_kona_smc_data data;
  82. data.service_id = service_id;
  83. data.arg0 = arg0;
  84. data.arg1 = arg1;
  85. data.arg2 = arg2;
  86. data.arg3 = arg3;
  87. /*
  88. * Due to a limitation of the secure monitor, we must use the SMP
  89. * infrastructure to forward all secure monitor calls to Core 0.
  90. */
  91. if (get_cpu() != 0)
  92. smp_call_function_single(0, __bcm_kona_smc, (void *)&data, 1);
  93. else
  94. __bcm_kona_smc(&data);
  95. put_cpu();
  96. return 0;
  97. }