virt-dt.c 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  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 <log.h>
  20. #include <stdio_dev.h>
  21. #include <linux/ctype.h>
  22. #include <linux/types.h>
  23. #include <linux/libfdt.h>
  24. #include <fdt_support.h>
  25. #include <asm/armv7.h>
  26. #include <asm/psci.h>
  27. int armv7_apply_memory_carveout(u64 *start, u64 *size)
  28. {
  29. #ifdef CONFIG_ARMV7_SECURE_RESERVE_SIZE
  30. if (*start + *size < CONFIG_ARMV7_SECURE_BASE ||
  31. *start >= (u64)CONFIG_ARMV7_SECURE_BASE +
  32. CONFIG_ARMV7_SECURE_RESERVE_SIZE)
  33. return 0;
  34. /* carveout must be at the beginning or the end of the bank */
  35. if (*start == CONFIG_ARMV7_SECURE_BASE ||
  36. *start + *size == (u64)CONFIG_ARMV7_SECURE_BASE +
  37. CONFIG_ARMV7_SECURE_RESERVE_SIZE) {
  38. if (*size < CONFIG_ARMV7_SECURE_RESERVE_SIZE) {
  39. debug("Secure monitor larger than RAM bank!?\n");
  40. return -EINVAL;
  41. }
  42. *size -= CONFIG_ARMV7_SECURE_RESERVE_SIZE;
  43. if (*start == CONFIG_ARMV7_SECURE_BASE)
  44. *start += CONFIG_ARMV7_SECURE_RESERVE_SIZE;
  45. return 0;
  46. }
  47. debug("Secure monitor not located at beginning or end of RAM bank\n");
  48. return -EINVAL;
  49. #else /* !CONFIG_ARMV7_SECURE_RESERVE_SIZE */
  50. return 0;
  51. #endif
  52. }
  53. int psci_update_dt(void *fdt)
  54. {
  55. #ifdef CONFIG_ARMV7_NONSEC
  56. if (!armv7_boot_nonsec())
  57. return 0;
  58. #endif
  59. #ifndef CONFIG_ARMV7_SECURE_BASE
  60. /* secure code lives in RAM, keep it alive */
  61. fdt_add_mem_rsv(fdt, (unsigned long)__secure_start,
  62. __secure_end - __secure_start);
  63. #endif
  64. return fdt_psci(fdt);
  65. }