bcm_kona_smc.c 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  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 = "bcm,kona-smc"},
  34. {},
  35. };
  36. /* Map in the bounce area */
  37. void __init bcm_kona_smc_init(void)
  38. {
  39. struct device_node *node;
  40. /* Read buffer addr and size from the device tree node */
  41. node = of_find_matching_node(NULL, bcm_kona_smc_ids);
  42. BUG_ON(!node);
  43. /* Don't care about size or flags of the DT node */
  44. bridge_data.buffer_addr =
  45. be32_to_cpu(*of_get_address(node, 0, NULL, NULL));
  46. BUG_ON(!bridge_data.buffer_addr);
  47. bridge_data.bounce = of_iomap(node, 0);
  48. BUG_ON(!bridge_data.bounce);
  49. bridge_data.initialized = 1;
  50. pr_info("Secure API initialized!\n");
  51. }
  52. /* __bcm_kona_smc() should only run on CPU 0, with pre-emption disabled */
  53. static void __bcm_kona_smc(void *info)
  54. {
  55. struct bcm_kona_smc_data *data = info;
  56. u32 *args = bridge_data.bounce;
  57. int rc = 0;
  58. /* Must run on CPU 0 */
  59. BUG_ON(smp_processor_id() != 0);
  60. /* Check map in the bounce area */
  61. BUG_ON(!bridge_data.initialized);
  62. /* Copy one 32 bit word into the bounce area */
  63. args[0] = data->arg0;
  64. args[1] = data->arg1;
  65. args[2] = data->arg2;
  66. args[3] = data->arg3;
  67. /* Flush caches for input data passed to Secure Monitor */
  68. if (data->service_id != SSAPI_BRCM_START_VC_CORE)
  69. flush_cache_all();
  70. /* Trap into Secure Monitor */
  71. rc = bcm_kona_smc_asm(data->service_id, bridge_data.buffer_addr);
  72. if (rc != SEC_ROM_RET_OK)
  73. pr_err("Secure Monitor call failed (0x%x)!\n", rc);
  74. }
  75. unsigned bcm_kona_smc(unsigned service_id, unsigned arg0, unsigned arg1,
  76. unsigned arg2, unsigned arg3)
  77. {
  78. struct bcm_kona_smc_data data;
  79. data.service_id = service_id;
  80. data.arg0 = arg0;
  81. data.arg1 = arg1;
  82. data.arg2 = arg2;
  83. data.arg3 = arg3;
  84. /*
  85. * Due to a limitation of the secure monitor, we must use the SMP
  86. * infrastructure to forward all secure monitor calls to Core 0.
  87. */
  88. if (get_cpu() != 0)
  89. smp_call_function_single(0, __bcm_kona_smc, (void *)&data, 1);
  90. else
  91. __bcm_kona_smc(&data);
  92. put_cpu();
  93. return 0;
  94. }