omap-secure.c 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  1. /*
  2. * OMAP Secure API infrastructure.
  3. *
  4. * Copyright (C) 2011 Texas Instruments, Inc.
  5. * Santosh Shilimkar <santosh.shilimkar@ti.com>
  6. * Copyright (C) 2012 Ivaylo Dimitrov <freemangordon@abv.bg>
  7. * Copyright (C) 2013 Pali Rohár <pali.rohar@gmail.com>
  8. *
  9. *
  10. * This program is free software,you can redistribute it and/or modify
  11. * it under the terms of the GNU General Public License version 2 as
  12. * published by the Free Software Foundation.
  13. */
  14. #include <linux/kernel.h>
  15. #include <linux/init.h>
  16. #include <linux/io.h>
  17. #include <linux/memblock.h>
  18. #include <asm/cacheflush.h>
  19. #include <asm/memblock.h>
  20. #include "omap-secure.h"
  21. static phys_addr_t omap_secure_memblock_base;
  22. /**
  23. * omap_sec_dispatcher: Routine to dispatch low power secure
  24. * service routines
  25. * @idx: The HAL API index
  26. * @flag: The flag indicating criticality of operation
  27. * @nargs: Number of valid arguments out of four.
  28. * @arg1, arg2, arg3 args4: Parameters passed to secure API
  29. *
  30. * Return the non-zero error value on failure.
  31. */
  32. u32 omap_secure_dispatcher(u32 idx, u32 flag, u32 nargs, u32 arg1, u32 arg2,
  33. u32 arg3, u32 arg4)
  34. {
  35. u32 ret;
  36. u32 param[5];
  37. param[0] = nargs;
  38. param[1] = arg1;
  39. param[2] = arg2;
  40. param[3] = arg3;
  41. param[4] = arg4;
  42. /*
  43. * Secure API needs physical address
  44. * pointer for the parameters
  45. */
  46. flush_cache_all();
  47. outer_clean_range(__pa(param), __pa(param + 5));
  48. ret = omap_smc2(idx, flag, __pa(param));
  49. return ret;
  50. }
  51. /* Allocate the memory to save secure ram */
  52. int __init omap_secure_ram_reserve_memblock(void)
  53. {
  54. u32 size = OMAP_SECURE_RAM_STORAGE;
  55. size = ALIGN(size, SECTION_SIZE);
  56. omap_secure_memblock_base = arm_memblock_steal(size, SECTION_SIZE);
  57. return 0;
  58. }
  59. phys_addr_t omap_secure_ram_mempool_base(void)
  60. {
  61. return omap_secure_memblock_base;
  62. }
  63. /**
  64. * rx51_secure_dispatcher: Routine to dispatch secure PPA API calls
  65. * @idx: The PPA API index
  66. * @process: Process ID
  67. * @flag: The flag indicating criticality of operation
  68. * @nargs: Number of valid arguments out of four.
  69. * @arg1, arg2, arg3 args4: Parameters passed to secure API
  70. *
  71. * Return the non-zero error value on failure.
  72. *
  73. * NOTE: rx51_secure_dispatcher differs from omap_secure_dispatcher because
  74. * it calling omap_smc3() instead omap_smc2() and param[0] is nargs+1
  75. */
  76. u32 rx51_secure_dispatcher(u32 idx, u32 process, u32 flag, u32 nargs,
  77. u32 arg1, u32 arg2, u32 arg3, u32 arg4)
  78. {
  79. u32 ret;
  80. u32 param[5];
  81. param[0] = nargs+1; /* RX-51 needs number of arguments + 1 */
  82. param[1] = arg1;
  83. param[2] = arg2;
  84. param[3] = arg3;
  85. param[4] = arg4;
  86. /*
  87. * Secure API needs physical address
  88. * pointer for the parameters
  89. */
  90. local_irq_disable();
  91. local_fiq_disable();
  92. flush_cache_all();
  93. outer_clean_range(__pa(param), __pa(param + 5));
  94. ret = omap_smc3(idx, process, flag, __pa(param));
  95. flush_cache_all();
  96. local_fiq_enable();
  97. local_irq_enable();
  98. return ret;
  99. }
  100. /**
  101. * rx51_secure_update_aux_cr: Routine to modify the contents of Auxiliary Control Register
  102. * @set_bits: bits to set in ACR
  103. * @clr_bits: bits to clear in ACR
  104. *
  105. * Return the non-zero error value on failure.
  106. */
  107. u32 rx51_secure_update_aux_cr(u32 set_bits, u32 clear_bits)
  108. {
  109. u32 acr;
  110. /* Read ACR */
  111. asm volatile ("mrc p15, 0, %0, c1, c0, 1" : "=r" (acr));
  112. acr &= ~clear_bits;
  113. acr |= set_bits;
  114. return rx51_secure_dispatcher(RX51_PPA_WRITE_ACR,
  115. 0,
  116. FLAG_START_CRITICAL,
  117. 1, acr, 0, 0, 0);
  118. }
  119. /**
  120. * rx51_secure_rng_call: Routine for HW random generator
  121. */
  122. u32 rx51_secure_rng_call(u32 ptr, u32 count, u32 flag)
  123. {
  124. return rx51_secure_dispatcher(RX51_PPA_HWRNG,
  125. 0,
  126. NO_FLAG,
  127. 3, ptr, count, flag, 0);
  128. }