omap-secure.c 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. /*
  2. * OMAP Secure API infrastructure.
  3. *
  4. * Copyright (C) 2011 Texas Instruments, Inc.
  5. * Santosh Shilimkar <santosh.shilimkar@ti.com>
  6. *
  7. *
  8. * This program is free software,you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License version 2 as
  10. * published by the Free Software Foundation.
  11. */
  12. #include <linux/kernel.h>
  13. #include <linux/init.h>
  14. #include <linux/io.h>
  15. #include <linux/memblock.h>
  16. #include <asm/cacheflush.h>
  17. #include <mach/omap-secure.h>
  18. static phys_addr_t omap_secure_memblock_base;
  19. /**
  20. * omap_sec_dispatcher: Routine to dispatch low power secure
  21. * service routines
  22. * @idx: The HAL API index
  23. * @flag: The flag indicating criticality of operation
  24. * @nargs: Number of valid arguments out of four.
  25. * @arg1, arg2, arg3 args4: Parameters passed to secure API
  26. *
  27. * Return the non-zero error value on failure.
  28. */
  29. u32 omap_secure_dispatcher(u32 idx, u32 flag, u32 nargs, u32 arg1, u32 arg2,
  30. u32 arg3, u32 arg4)
  31. {
  32. u32 ret;
  33. u32 param[5];
  34. param[0] = nargs;
  35. param[1] = arg1;
  36. param[2] = arg2;
  37. param[3] = arg3;
  38. param[4] = arg4;
  39. /*
  40. * Secure API needs physical address
  41. * pointer for the parameters
  42. */
  43. flush_cache_all();
  44. outer_clean_range(__pa(param), __pa(param + 5));
  45. ret = omap_smc2(idx, flag, __pa(param));
  46. return ret;
  47. }
  48. /* Allocate the memory to save secure ram */
  49. int __init omap_secure_ram_reserve_memblock(void)
  50. {
  51. phys_addr_t paddr;
  52. u32 size = OMAP_SECURE_RAM_STORAGE;
  53. size = ALIGN(size, SZ_1M);
  54. paddr = memblock_alloc(size, SZ_1M);
  55. if (!paddr) {
  56. pr_err("%s: failed to reserve %x bytes\n",
  57. __func__, size);
  58. return -ENOMEM;
  59. }
  60. memblock_free(paddr, size);
  61. memblock_remove(paddr, size);
  62. omap_secure_memblock_base = paddr;
  63. return 0;
  64. }
  65. phys_addr_t omap_secure_ram_mempool_base(void)
  66. {
  67. return omap_secure_memblock_base;
  68. }