spl_atf.c 3.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. /*
  2. * Reference to the ARM TF Project,
  3. * plat/arm/common/arm_bl2_setup.c
  4. * Portions copyright (c) 2013-2016, ARM Limited and Contributors. All rights
  5. * reserved.
  6. * Copyright (C) 2016 Rockchip Electronic Co.,Ltd
  7. * Written by Kever Yang <kever.yang@rock-chips.com>
  8. *
  9. * SPDX-License-Identifier: BSD-3-Clause
  10. */
  11. #include <common.h>
  12. #include <atf_common.h>
  13. #include <errno.h>
  14. #include <spl.h>
  15. static struct bl2_to_bl31_params_mem bl31_params_mem;
  16. static struct bl31_params *bl2_to_bl31_params;
  17. /**
  18. * bl2_plat_get_bl31_params() - prepare params for bl31.
  19. *
  20. * This function assigns a pointer to the memory that the platform has kept
  21. * aside to pass platform specific and trusted firmware related information
  22. * to BL31. This memory is allocated by allocating memory to
  23. * bl2_to_bl31_params_mem structure which is a superset of all the
  24. * structure whose information is passed to BL31
  25. * NOTE: This function should be called only once and should be done
  26. * before generating params to BL31
  27. *
  28. * @return bl31 params structure pointer
  29. */
  30. struct bl31_params *bl2_plat_get_bl31_params(void)
  31. {
  32. struct entry_point_info *bl33_ep_info;
  33. /*
  34. * Initialise the memory for all the arguments that needs to
  35. * be passed to BL31
  36. */
  37. memset(&bl31_params_mem, 0, sizeof(struct bl2_to_bl31_params_mem));
  38. /* Assign memory for TF related information */
  39. bl2_to_bl31_params = &bl31_params_mem.bl31_params;
  40. SET_PARAM_HEAD(bl2_to_bl31_params, ATF_PARAM_BL31, ATF_VERSION_1, 0);
  41. /* Fill BL31 related information */
  42. SET_PARAM_HEAD(bl2_to_bl31_params->bl31_image_info,
  43. ATF_PARAM_IMAGE_BINARY, ATF_VERSION_1, 0);
  44. /* Fill BL32 related information if it exists */
  45. #ifdef BL32_BASE
  46. bl2_to_bl31_params->bl32_ep_info = &bl31_params_mem.bl32_ep_info;
  47. SET_PARAM_HEAD(bl2_to_bl31_params->bl32_ep_info, ATF_PARAM_EP,
  48. ATF_VERSION_1, 0);
  49. bl2_to_bl31_params->bl32_image_info = &bl31_params_mem.bl32_image_info;
  50. SET_PARAM_HEAD(bl2_to_bl31_params->bl32_image_info,
  51. ATF_PARAM_IMAGE_BINARY, ATF_VERSION_1, 0);
  52. #endif /* BL32_BASE */
  53. /* Fill BL33 related information */
  54. bl2_to_bl31_params->bl33_ep_info = &bl31_params_mem.bl33_ep_info;
  55. bl33_ep_info = &bl31_params_mem.bl33_ep_info;
  56. SET_PARAM_HEAD(bl33_ep_info, ATF_PARAM_EP, ATF_VERSION_1,
  57. ATF_EP_NON_SECURE);
  58. /* BL33 expects to receive the primary CPU MPID (through x0) */
  59. bl33_ep_info->args.arg0 = 0xffff & read_mpidr();
  60. bl33_ep_info->pc = CONFIG_SYS_TEXT_BASE;
  61. bl33_ep_info->spsr = SPSR_64(MODE_EL2, MODE_SP_ELX,
  62. DISABLE_ALL_EXECPTIONS);
  63. bl2_to_bl31_params->bl33_image_info = &bl31_params_mem.bl33_image_info;
  64. SET_PARAM_HEAD(bl2_to_bl31_params->bl33_image_info,
  65. ATF_PARAM_IMAGE_BINARY, ATF_VERSION_1, 0);
  66. return bl2_to_bl31_params;
  67. }
  68. void raw_write_daif(unsigned int daif)
  69. {
  70. __asm__ __volatile__("msr DAIF, %0\n\t" : : "r" (daif) : "memory");
  71. }
  72. void bl31_entry(void)
  73. {
  74. struct bl31_params *bl31_params;
  75. void (*entry)(struct bl31_params *params, void *plat_params) = NULL;
  76. bl31_params = bl2_plat_get_bl31_params();
  77. entry = (void *)CONFIG_SPL_ATF_TEXT_BASE;
  78. raw_write_daif(SPSR_EXCEPTION_MASK);
  79. dcache_disable();
  80. entry(bl31_params, NULL);
  81. }