fw_dynamic.h 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. /*
  2. * SPDX-License-Identifier: BSD-2-Clause
  3. *
  4. * Copyright (c) 2019 Western Digital Corporation or its affiliates.
  5. *
  6. * Authors:
  7. * Anup Patel <anup.patel@wdc.com>
  8. */
  9. #ifndef __FW_DYNAMIC_H__
  10. #define __FW_DYNAMIC_H__
  11. #include <sbi/riscv_asm.h>
  12. /* clang-format off */
  13. /** Offset of magic member in fw_dynamic_info */
  14. #define FW_DYNAMIC_INFO_MAGIC_OFFSET (0 * __SIZEOF_LONG__)
  15. /** Offset of version member in fw_dynamic_info */
  16. #define FW_DYNAMIC_INFO_VERSION_OFFSET (1 * __SIZEOF_LONG__)
  17. /** Offset of next_addr member in fw_dynamic_info (version >= 1) */
  18. #define FW_DYNAMIC_INFO_NEXT_ADDR_OFFSET (2 * __SIZEOF_LONG__)
  19. /** Offset of next_mode member in fw_dynamic_info (version >= 1) */
  20. #define FW_DYNAMIC_INFO_NEXT_MODE_OFFSET (3 * __SIZEOF_LONG__)
  21. /** Offset of options member in fw_dynamic_info (version >= 1) */
  22. #define FW_DYNAMIC_INFO_OPTIONS_OFFSET (4 * __SIZEOF_LONG__)
  23. /** Offset of boot_hart member in fw_dynamic_info (version >= 2) */
  24. #define FW_DYNAMIC_INFO_BOOT_HART_OFFSET (5 * __SIZEOF_LONG__)
  25. /** Expected value of info magic ('OSBI' ascii string in hex) */
  26. #define FW_DYNAMIC_INFO_MAGIC_VALUE 0x4942534f
  27. /** Maximum supported info version */
  28. #define FW_DYNAMIC_INFO_VERSION_2 0x2
  29. #define FW_DYNAMIC_INFO_VERSION_MAX FW_DYNAMIC_INFO_VERSION_2
  30. /** Possible next mode values */
  31. #define FW_DYNAMIC_INFO_NEXT_MODE_U 0x0
  32. #define FW_DYNAMIC_INFO_NEXT_MODE_S 0x1
  33. #define FW_DYNAMIC_INFO_NEXT_MODE_M 0x3
  34. /* clang-format on */
  35. #ifndef __ASSEMBLER__
  36. #include <sbi/sbi_types.h>
  37. /** Representation dynamic info passed by previous booting stage */
  38. struct fw_dynamic_info {
  39. /** Info magic */
  40. unsigned long magic;
  41. /** Info version */
  42. unsigned long version;
  43. /** Next booting stage address */
  44. unsigned long next_addr;
  45. /** Next booting stage mode */
  46. unsigned long next_mode;
  47. /** Options for OpenSBI library */
  48. unsigned long options;
  49. /**
  50. * Preferred boot HART id
  51. *
  52. * It is possible that the previous booting stage uses same link
  53. * address as the FW_DYNAMIC firmware. In this case, the relocation
  54. * lottery mechanism can potentially overwrite the previous booting
  55. * stage while other HARTs are still running in the previous booting
  56. * stage leading to boot-time crash. To avoid this boot-time crash,
  57. * the previous booting stage can specify last HART that will jump
  58. * to the FW_DYNAMIC firmware as the preferred boot HART.
  59. *
  60. * To avoid specifying a preferred boot HART, the previous booting
  61. * stage can set it to -1UL which will force the FW_DYNAMIC firmware
  62. * to use the relocation lottery mechanism.
  63. */
  64. unsigned long boot_hart;
  65. } __packed;
  66. /**
  67. * Prevent modification of struct fw_dynamic_info from affecting
  68. * FW_DYNAMIC_INFO_xxx_OFFSET
  69. */
  70. _Static_assert(
  71. offsetof(struct fw_dynamic_info, magic)
  72. == FW_DYNAMIC_INFO_MAGIC_OFFSET,
  73. "struct fw_dynamic_info definition has changed, please redefine "
  74. "FW_DYNAMIC_INFO_MAGIC_OFFSET");
  75. _Static_assert(
  76. offsetof(struct fw_dynamic_info, version)
  77. == FW_DYNAMIC_INFO_VERSION_OFFSET,
  78. "struct fw_dynamic_info definition has changed, please redefine "
  79. "FW_DYNAMIC_INFO_VERSION_OFFSET");
  80. _Static_assert(
  81. offsetof(struct fw_dynamic_info, next_addr)
  82. == FW_DYNAMIC_INFO_NEXT_ADDR_OFFSET,
  83. "struct fw_dynamic_info definition has changed, please redefine "
  84. "FW_DYNAMIC_INFO_NEXT_ADDR_OFFSET");
  85. _Static_assert(
  86. offsetof(struct fw_dynamic_info, next_mode)
  87. == FW_DYNAMIC_INFO_NEXT_MODE_OFFSET,
  88. "struct fw_dynamic_info definition has changed, please redefine "
  89. "FW_DYNAMIC_INFO_NEXT_MODE_OFFSET");
  90. _Static_assert(
  91. offsetof(struct fw_dynamic_info, options)
  92. == FW_DYNAMIC_INFO_OPTIONS_OFFSET,
  93. "struct fw_dynamic_info definition has changed, please redefine "
  94. "FW_DYNAMIC_INFO_OPTIONS_OFFSET");
  95. _Static_assert(
  96. offsetof(struct fw_dynamic_info, boot_hart)
  97. == FW_DYNAMIC_INFO_BOOT_HART_OFFSET,
  98. "struct fw_dynamic_info definition has changed, please redefine "
  99. "FW_DYNAMIC_INFO_BOOT_HART_OFFSET");
  100. #endif
  101. #endif