trusted_foundations.c 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. /*
  2. * Trusted Foundations support for ARM CPUs
  3. *
  4. * Copyright (c) 2013, NVIDIA Corporation.
  5. *
  6. * This program is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation; either version 2 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful, but WITHOUT
  12. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13. * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
  14. * more details.
  15. */
  16. #include <linux/kernel.h>
  17. #include <linux/init.h>
  18. #include <linux/of.h>
  19. #include <asm/firmware.h>
  20. #include <asm/trusted_foundations.h>
  21. #define TF_SET_CPU_BOOT_ADDR_SMC 0xfffff200
  22. #define TF_CPU_PM 0xfffffffc
  23. #define TF_CPU_PM_S3 0xffffffe3
  24. #define TF_CPU_PM_S2 0xffffffe6
  25. #define TF_CPU_PM_S2_NO_MC_CLK 0xffffffe5
  26. #define TF_CPU_PM_S1 0xffffffe4
  27. #define TF_CPU_PM_S1_NOFLUSH_L2 0xffffffe7
  28. static unsigned long cpu_boot_addr;
  29. static void __naked tf_generic_smc(u32 type, u32 arg1, u32 arg2)
  30. {
  31. asm volatile(
  32. ".arch_extension sec\n\t"
  33. "stmfd sp!, {r4 - r11, lr}\n\t"
  34. __asmeq("%0", "r0")
  35. __asmeq("%1", "r1")
  36. __asmeq("%2", "r2")
  37. "mov r3, #0\n\t"
  38. "mov r4, #0\n\t"
  39. "smc #0\n\t"
  40. "ldmfd sp!, {r4 - r11, pc}"
  41. :
  42. : "r" (type), "r" (arg1), "r" (arg2)
  43. : "memory");
  44. }
  45. static int tf_set_cpu_boot_addr(int cpu, unsigned long boot_addr)
  46. {
  47. cpu_boot_addr = boot_addr;
  48. tf_generic_smc(TF_SET_CPU_BOOT_ADDR_SMC, cpu_boot_addr, 0);
  49. return 0;
  50. }
  51. static int tf_prepare_idle(void)
  52. {
  53. tf_generic_smc(TF_CPU_PM, TF_CPU_PM_S1_NOFLUSH_L2, cpu_boot_addr);
  54. return 0;
  55. }
  56. static const struct firmware_ops trusted_foundations_ops = {
  57. .set_cpu_boot_addr = tf_set_cpu_boot_addr,
  58. .prepare_idle = tf_prepare_idle,
  59. };
  60. void register_trusted_foundations(struct trusted_foundations_platform_data *pd)
  61. {
  62. /*
  63. * we are not using version information for now since currently
  64. * supported SMCs are compatible with all TF releases
  65. */
  66. register_firmware_ops(&trusted_foundations_ops);
  67. }
  68. void of_register_trusted_foundations(void)
  69. {
  70. struct device_node *node;
  71. struct trusted_foundations_platform_data pdata;
  72. int err;
  73. node = of_find_compatible_node(NULL, NULL, "tlm,trusted-foundations");
  74. if (!node)
  75. return;
  76. err = of_property_read_u32(node, "tlm,version-major",
  77. &pdata.version_major);
  78. if (err != 0)
  79. panic("Trusted Foundation: missing version-major property\n");
  80. err = of_property_read_u32(node, "tlm,version-minor",
  81. &pdata.version_minor);
  82. if (err != 0)
  83. panic("Trusted Foundation: missing version-minor property\n");
  84. register_trusted_foundations(&pdata);
  85. }