virt-dt.c 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. /*
  2. * Copyright (C) 2013 - ARM Ltd
  3. * Author: Marc Zyngier <marc.zyngier@arm.com>
  4. *
  5. * This program is free software; you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License version 2 as
  7. * published by the Free Software Foundation.
  8. *
  9. * This program is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. * GNU General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU General Public License
  15. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  16. */
  17. #include <common.h>
  18. #include <errno.h>
  19. #include <stdio_dev.h>
  20. #include <linux/ctype.h>
  21. #include <linux/types.h>
  22. #include <asm/global_data.h>
  23. #include <libfdt.h>
  24. #include <fdt_support.h>
  25. #include <asm/armv7.h>
  26. #include <asm/psci.h>
  27. static int fdt_psci(void *fdt)
  28. {
  29. #ifdef CONFIG_ARMV7_PSCI
  30. int nodeoff;
  31. int tmp;
  32. nodeoff = fdt_path_offset(fdt, "/cpus");
  33. if (nodeoff < 0) {
  34. printf("couldn't find /cpus\n");
  35. return nodeoff;
  36. }
  37. /* add 'enable-method = "psci"' to each cpu node */
  38. for (tmp = fdt_first_subnode(fdt, nodeoff);
  39. tmp >= 0;
  40. tmp = fdt_next_subnode(fdt, tmp)) {
  41. const struct fdt_property *prop;
  42. int len;
  43. prop = fdt_get_property(fdt, tmp, "device_type", &len);
  44. if (!prop)
  45. continue;
  46. if (len < 4)
  47. continue;
  48. if (strcmp(prop->data, "cpu"))
  49. continue;
  50. fdt_setprop_string(fdt, tmp, "enable-method", "psci");
  51. }
  52. nodeoff = fdt_path_offset(fdt, "/psci");
  53. if (nodeoff < 0) {
  54. nodeoff = fdt_path_offset(fdt, "/");
  55. if (nodeoff < 0)
  56. return nodeoff;
  57. nodeoff = fdt_add_subnode(fdt, nodeoff, "psci");
  58. if (nodeoff < 0)
  59. return nodeoff;
  60. }
  61. tmp = fdt_setprop_string(fdt, nodeoff, "compatible", "arm,psci");
  62. if (tmp)
  63. return tmp;
  64. tmp = fdt_setprop_string(fdt, nodeoff, "method", "smc");
  65. if (tmp)
  66. return tmp;
  67. tmp = fdt_setprop_u32(fdt, nodeoff, "cpu_suspend", ARM_PSCI_FN_CPU_SUSPEND);
  68. if (tmp)
  69. return tmp;
  70. tmp = fdt_setprop_u32(fdt, nodeoff, "cpu_off", ARM_PSCI_FN_CPU_OFF);
  71. if (tmp)
  72. return tmp;
  73. tmp = fdt_setprop_u32(fdt, nodeoff, "cpu_on", ARM_PSCI_FN_CPU_ON);
  74. if (tmp)
  75. return tmp;
  76. tmp = fdt_setprop_u32(fdt, nodeoff, "migrate", ARM_PSCI_FN_MIGRATE);
  77. if (tmp)
  78. return tmp;
  79. #endif
  80. return 0;
  81. }
  82. int armv7_apply_memory_carveout(u64 *start, u64 *size)
  83. {
  84. #ifdef CONFIG_ARMV7_SECURE_RESERVE_SIZE
  85. if (*start + *size < CONFIG_ARMV7_SECURE_BASE ||
  86. *start >= (u64)CONFIG_ARMV7_SECURE_BASE +
  87. CONFIG_ARMV7_SECURE_RESERVE_SIZE)
  88. return 0;
  89. /* carveout must be at the beginning or the end of the bank */
  90. if (*start == CONFIG_ARMV7_SECURE_BASE ||
  91. *start + *size == (u64)CONFIG_ARMV7_SECURE_BASE +
  92. CONFIG_ARMV7_SECURE_RESERVE_SIZE) {
  93. if (*size < CONFIG_ARMV7_SECURE_RESERVE_SIZE) {
  94. debug("Secure monitor larger than RAM bank!?\n");
  95. return -EINVAL;
  96. }
  97. *size -= CONFIG_ARMV7_SECURE_RESERVE_SIZE;
  98. if (*start == CONFIG_ARMV7_SECURE_BASE)
  99. *start += CONFIG_ARMV7_SECURE_RESERVE_SIZE;
  100. return 0;
  101. }
  102. debug("Secure monitor not located at beginning or end of RAM bank\n");
  103. return -EINVAL;
  104. #else /* !CONFIG_ARMV7_SECURE_RESERVE_SIZE */
  105. return 0;
  106. #endif
  107. }
  108. int psci_update_dt(void *fdt)
  109. {
  110. #ifdef CONFIG_ARMV7_NONSEC
  111. if (!armv7_boot_nonsec())
  112. return 0;
  113. #endif
  114. #ifndef CONFIG_ARMV7_SECURE_BASE
  115. /* secure code lives in RAM, keep it alive */
  116. fdt_add_mem_rsv(fdt, (unsigned long)__secure_start,
  117. __secure_end - __secure_start);
  118. #endif
  119. return fdt_psci(fdt);
  120. }