nfp.h 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292
  1. /* NFP ELF support for BFD.
  2. Copyright (C) 2017-2022 Free Software Foundation, Inc.
  3. Contributed by Francois H. Theron <francois.theron@netronome.com>
  4. This file is part of BFD, the Binary File Descriptor library.
  5. This program is free software; you can redistribute it and/or modify
  6. it under the terms of the GNU General Public License as published by
  7. the Free Software Foundation; either version 3 of the License, or
  8. (at your option) any later version.
  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. You should have received a copy of the GNU General Public License
  14. along with this program; if not, write to the Free Software Foundation,
  15. Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA. */
  16. #ifndef _ELF_NFP_H
  17. #define _ELF_NFP_H
  18. #include "bfd.h"
  19. #include "elf/common.h"
  20. #include "elf/reloc-macros.h"
  21. #include <stdint.h>
  22. #ifdef __cplusplus
  23. extern "C"
  24. {
  25. #endif
  26. #define ET_NFP_PARTIAL_REL (ET_LOPROC + ET_REL)
  27. #define ET_NFP_PARTIAL_EXEC (ET_LOPROC + ET_EXEC)
  28. /* NFP e_flags - chip family
  29. Valid values for FAMILY are:
  30. 0x3200 - NFP-32xx
  31. 0x6000 - NFP-6xxx/NFP-4xxx. */
  32. #define EF_NFP_MACH(ef_nfp) (((ef_nfp) >> 8) & 0xFFFF)
  33. #define EF_NFP_SET_MACH(nfp_fam) (((nfp_fam) & 0xFFFF) << 8)
  34. #define E_NFP_MACH_3200 0x3200
  35. #define E_NFP_MACH_6000 0x6000
  36. #define NFP_3200_CPPTGT_MSF0 1
  37. #define NFP_3200_CPPTGT_QDR 2
  38. #define NFP_3200_CPPTGT_MSF1 3
  39. #define NFP_3200_CPPTGT_HASH 4
  40. #define NFP_3200_CPPTGT_MU 7
  41. #define NFP_3200_CPPTGT_GS 8
  42. #define NFP_3200_CPPTGT_PCIE 9
  43. #define NFP_3200_CPPTGT_ARM 10
  44. #define NFP_3200_CPPTGT_CRYPTO 12
  45. #define NFP_3200_CPPTGT_CAP 13
  46. #define NFP_3200_CPPTGT_CT 14
  47. #define NFP_3200_CPPTGT_CLS 15
  48. #define NFP_6000_CPPTGT_NBI 1
  49. #define NFP_6000_CPPTGT_VQDR 2
  50. #define NFP_6000_CPPTGT_ILA 6
  51. #define NFP_6000_CPPTGT_MU 7
  52. #define NFP_6000_CPPTGT_PCIE 9
  53. #define NFP_6000_CPPTGT_ARM 10
  54. #define NFP_6000_CPPTGT_CRYPTO 12
  55. #define NFP_6000_CPPTGT_CTXPB 14
  56. #define NFP_6000_CPPTGT_CLS 15
  57. /* NFP Section types
  58. MECONFIG - NFP-32xx only, ME CSR configurations
  59. INITREG - A generic register initialisation section (chip or ME CSRs/GPRs)
  60. UDEBUG - Legacy-style debug data section. */
  61. #define SHT_NFP_MECONFIG (SHT_LOPROC + 1)
  62. #define SHT_NFP_INITREG (SHT_LOPROC + 2)
  63. #define SHT_NFP_UDEBUG SHT_LOUSER
  64. /* NFP SECTION flags
  65. ELF-64 sh_flags is 64-bit, but there is no info on what the upper 32 bits
  66. are expected to be used for, it is not marked reserved either.
  67. We'll use them for NFP-specific flags since we don't use ELF-32.
  68. INIT - Sections that are loaded and executed before the final text
  69. microcode. Non-code INIT sections are loaded first, then other
  70. memory secions, then INIT2 sections, then INIT-code sections.
  71. INIT2 - Sections that are loaded before INIT-code sections, used for
  72. transient configuration before executing INIT-code section
  73. microcode.
  74. SCS - The number of additional ME codestores being shared with the group's
  75. base ME of the section, e.g. 0 for no SCS, 1 for dual and 3 for
  76. quad. If this is 0 it is possible that stagger-style SCS codestore
  77. sections are being used. For stagger-style each section is simply
  78. loaded directly to the ME it is assigned to. If these flags are
  79. used, virtual address space loading will be used - one large section
  80. loaded to the group's base ME will be packed across shared MEs by
  81. hardware. This is not available on all ME versions.
  82. NFP_ELF_SHF_GET_SCS (val) returns the number of additional codestores
  83. being shared with the group's base ME, e.g. 0 for no SCS,
  84. 1 for dual SCS, 3 for quad SCS. */
  85. #define SHF_NFP_INIT 0x80000000
  86. #define SHF_NFP_INIT2 0x40000000
  87. #define SHF_NFP_SCS(shf) (((shf) >> 32) & 0xFF)
  88. #define SHF_NFP_SET_SCS(v) (((BFD_HOST_U_64_BIT)((v) & 0xFF)) << 32)
  89. /* NFP Section Info
  90. For PROGBITS and NOBITS sections:
  91. MEMTYPE - the memory type
  92. DOMAIN - The island ID and ME number where the data will be loaded.
  93. For NFP-32xx, this is an island number or linear ME number.
  94. For NFP-6xxx, DOMAIN<15:8> == island ID, DOMAIN<7:0> is 0 based
  95. ME number (if applicable).
  96. For INITREG sections:
  97. ISLAND - island ID (if it's a ME target, ME numbers are in the
  98. section data)
  99. CPPTGT - CPP Target ID
  100. CPPACTRD - CPP Read Action
  101. CPPTOKRD - CPP Read Token
  102. CPPACTWR - CPP Write Action
  103. CPPTOKWR - CPP Write Token
  104. ORDER - Controls the order in which the loader processes sections with
  105. the same info fields. */
  106. #define SHI_NFP_DOMAIN(shi) (((shi) >> 16) & 0xFFFF)
  107. #define SHI_NFP_MEMTYPE(shi) ( (shi) & 0xFFFF)
  108. #define SHI_NFP_SET_DOMAIN(v) (((v) & 0xFFFF) << 16)
  109. #define SHI_NFP_SET_MEMTYPE(v) ( (v) & 0xFFFF)
  110. #define SHI_NFP_IREG_ISLAND(shi) (((shi) >> 26) & 0x3F)
  111. #define SHI_NFP_IREG_CPPTGT(shi) (((shi) >> 22) & 0xF)
  112. #define SHI_NFP_IREG_CPPACTRD(shi) (((shi) >> 17) & 0x1F)
  113. #define SHI_NFP_IREG_CPPTOKRD(shi) (((shi) >> 15) & 0x3)
  114. #define SHI_NFP_IREG_CPPACTWR(shi) (((shi) >> 10) & 0x1F)
  115. #define SHI_NFP_IREG_CPPTOKWR(shi) (((shi) >> 8) & 0x3)
  116. #define SHI_NFP_IREG_ORDER(shi) ( (shi) & 0xFF)
  117. #define SHI_NFP_SET_IREG_ISLAND(v) (((v) & 0x3F) << 26)
  118. #define SHI_NFP_SET_IREG_CPPTGT(v) (((v) & 0xF) << 22)
  119. #define SHI_NFP_SET_IREG_CPPACTRD(v) (((v) & 0x1F) << 17)
  120. #define SHI_NFP_SET_IREG_CPPTOKRD(v) (((v) & 0x3) << 15)
  121. #define SHI_NFP_SET_IREG_CPPACTWR(v) (((v) & 0x1F) << 10)
  122. #define SHI_NFP_SET_IREG_CPPTOKWR(v) (((v) & 0x3) << 8)
  123. #define SHI_NFP_SET_IREG_ORDER(v) ( (v) & 0xFF)
  124. /* CtXpb/reflect_read_sig_init/reflect_write_sig_init
  125. identifies Init-CSR sections for ME CSRs. */
  126. #define SHI_NFP_6000_IS_IREG_MECSR(shi) ( \
  127. SHI_NFP_IREG_CPPTGT (shi) == NFP_6000_CPPTGT_CTXPB \
  128. && SHI_NFP_IREG_CPPACTRD (shi) == 2 \
  129. && SHI_NFP_IREG_CPPTOKRD (shi) == 1 \
  130. && SHI_NFP_IREG_CPPACTWR (shi) == 3 \
  131. && SHI_NFP_IREG_CPPTOKWR (shi) == 1 \
  132. )
  133. /* Transient INITREG sections will be validated against the target
  134. but will not be kept - validate, write or read and discard.
  135. They will still be handled last (in order). */
  136. #define SHI_NFP_IREG_ORDER_TRANSIENT 0xFF
  137. /* Below are some extra macros to translate SHI fields in more specific
  138. contexts.
  139. For NFP-32xx, DOMAIN is set to a global linear ME number (0 to 39).
  140. An NFP-32xx has 8 MEs per island and up to 5 islands. */
  141. #define SHI_NFP_3200_ISLAND(shi) ((SHI_NFP_DOMAIN (shi) >> 3) & 0x7)
  142. #define SHI_NFP_3200_MENUM(shi) ( SHI_NFP_DOMAIN (shi) & 0x7)
  143. #define SHI_NFP_SET_3200_ISLAND(v) SHI_NFP_SET_DOMAIN (((v) & 0x7) << 3)
  144. #define SHI_NFP_SET_3200_MENUM(v) SHI_NFP_SET_DOMAIN ( (v) & 0x7)
  145. #define SHI_NFP_ISLAND(shi) ((SHI_NFP_DOMAIN (shi) >> 8) & 0xFF)
  146. #define SHI_NFP_MENUM(shi) ( SHI_NFP_DOMAIN (shi) & 0xFF)
  147. #define SHI_NFP_SET_ISLAND(shi) SHI_NFP_SET_DOMAIN (((shi) & 0xFF) << 8)
  148. #define SHI_NFP_SET_MENUM(shi) SHI_NFP_SET_DOMAIN ( (shi) & 0xFF)
  149. #define SHI_NFP_MEMTYPE_NONE 0
  150. #define SHI_NFP_MEMTYPE_USTORE 1
  151. #define SHI_NFP_MEMTYPE_LMEM 2
  152. #define SHI_NFP_MEMTYPE_CLS 3
  153. #define SHI_NFP_MEMTYPE_DRAM 4
  154. #define SHI_NFP_MEMTYPE_MU 4
  155. #define SHI_NFP_MEMTYPE_SRAM 5
  156. #define SHI_NFP_MEMTYPE_GS 6
  157. #define SHI_NFP_MEMTYPE_PPC_LMEM 7
  158. #define SHI_NFP_MEMTYPE_PPC_SMEM 8
  159. #define SHI_NFP_MEMTYPE_EMU_CACHE 9
  160. /* VTP_FORCE is for use by the NFP Linker+Loader only. */
  161. #define NFP_IREG_VTP_FORCE 0
  162. #define NFP_IREG_VTP_CONST 1
  163. #define NFP_IREG_VTP_REQUIRED 2
  164. #define NFP_IREG_VTP_VOLATILE_INIT 3
  165. #define NFP_IREG_VTP_VOLATILE_NOINIT 4
  166. #define NFP_IREG_VTP_INVALID 5
  167. /* Init-CSR entry w0 fields:
  168. NLW - Not Last Word
  169. CTX - ME context number (if applicable)
  170. VTP - Value type
  171. COH - CPP Offset High 8 bits. */
  172. #define NFP_IREG_ENTRY_WO_NLW(w0) (((w0) >> 31) & 0x1)
  173. #define NFP_IREG_ENTRY_WO_CTX(w0) (((w0) >> 28) & 0x7)
  174. #define NFP_IREG_ENTRY_WO_VTP(w0) (((w0) >> 25) & 0x7)
  175. #define NFP_IREG_ENTRY_WO_COH(w0) (((w0) >> 0) & 0xFF)
  176. typedef struct
  177. {
  178. uint32_t w0;
  179. uint32_t cpp_offset_lo;
  180. uint32_t val;
  181. uint32_t mask;
  182. } Elf_Nfp_InitRegEntry;
  183. typedef struct
  184. {
  185. uint32_t ctx_enables;
  186. uint32_t entry;
  187. uint32_t misc_control;
  188. uint32_t reserved;
  189. } Elf_Nfp_MeConfig;
  190. /* Relocations. */
  191. START_RELOC_NUMBERS (elf_nfp3200_reloc_type)
  192. RELOC_NUMBER (R_NFP3200_NOTYPE, 0)
  193. RELOC_NUMBER (R_NFP3200_W32LE, 1)
  194. RELOC_NUMBER (R_NFP3200_SRC8_A, 2)
  195. RELOC_NUMBER (R_NFP3200_SRC8_B, 3)
  196. RELOC_NUMBER (R_NFP3200_IMMED8_I, 4)
  197. RELOC_NUMBER (R_NFP3200_SC, 5)
  198. RELOC_NUMBER (R_NFP3200_IMMED_LO16_I_A, 6)
  199. RELOC_NUMBER (R_NFP3200_IMMED_LO16_I_B, 7)
  200. RELOC_NUMBER (R_NFP3200_SRC7_B, 8)
  201. RELOC_NUMBER (R_NFP3200_SRC7_A, 9)
  202. RELOC_NUMBER (R_NFP3200_SRC8_I_B, 10)
  203. RELOC_NUMBER (R_NFP3200_SRC8_I_A, 11)
  204. RELOC_NUMBER (R_NFP3200_IMMED_HI16_I_A, 12)
  205. RELOC_NUMBER (R_NFP3200_IMMED_HI16_I_B, 13)
  206. RELOC_NUMBER (R_NFP3200_RSVD_0, 14)
  207. RELOC_NUMBER (R_NFP3200_RSVD_1, 15)
  208. RELOC_NUMBER (R_NFP3200_RSVD_2, 16)
  209. RELOC_NUMBER (R_NFP3200_RSVD_3, 17)
  210. RELOC_NUMBER (R_NFP3200_RSVD_4, 18)
  211. RELOC_NUMBER (R_NFP3200_RSVD_5, 19)
  212. RELOC_NUMBER (R_NFP3200_RSVD_6, 20)
  213. RELOC_NUMBER (R_NFP3200_W64LE, 21)
  214. RELOC_NUMBER (R_NFP3200_W32BE, 22)
  215. RELOC_NUMBER (R_NFP3200_W64BE, 23)
  216. RELOC_NUMBER (R_NFP3200_W32LE_AND, 24)
  217. RELOC_NUMBER (R_NFP3200_W32BE_AND, 25)
  218. RELOC_NUMBER (R_NFP3200_W32LE_OR, 26)
  219. RELOC_NUMBER (R_NFP3200_W32BE_OR, 27)
  220. RELOC_NUMBER (R_NFP3200_W64LE_AND, 28)
  221. RELOC_NUMBER (R_NFP3200_W64BE_AND, 29)
  222. RELOC_NUMBER (R_NFP3200_W64LE_OR, 30)
  223. RELOC_NUMBER (R_NFP3200_W64BE_OR, 31)
  224. END_RELOC_NUMBERS (R_NFP3200_MAX)
  225. START_RELOC_NUMBERS (elf_nfp_reloc_type)
  226. RELOC_NUMBER (R_NFP_NOTYPE, 0)
  227. RELOC_NUMBER (R_NFP_W32LE, 1)
  228. RELOC_NUMBER (R_NFP_SRC8_A, 2)
  229. RELOC_NUMBER (R_NFP_SRC8_B, 3)
  230. RELOC_NUMBER (R_NFP_IMMED8_I, 4)
  231. RELOC_NUMBER (R_NFP_SC, 5)
  232. RELOC_NUMBER (R_NFP_IMMED_LO16_I_A, 6)
  233. RELOC_NUMBER (R_NFP_IMMED_LO16_I_B, 7)
  234. RELOC_NUMBER (R_NFP_SRC7_B, 8)
  235. RELOC_NUMBER (R_NFP_SRC7_A, 9)
  236. RELOC_NUMBER (R_NFP_SRC8_I_B, 10)
  237. RELOC_NUMBER (R_NFP_SRC8_I_A, 11)
  238. RELOC_NUMBER (R_NFP_IMMED_HI16_I_A, 12)
  239. RELOC_NUMBER (R_NFP_IMMED_HI16_I_B, 13)
  240. RELOC_NUMBER (R_NFP_W64LE, 14)
  241. RELOC_NUMBER (R_NFP_SH_INFO, 15)
  242. RELOC_NUMBER (R_NFP_W32BE, 16)
  243. RELOC_NUMBER (R_NFP_W64BE, 17)
  244. RELOC_NUMBER (R_NFP_W32_29_24, 18)
  245. RELOC_NUMBER (R_NFP_W32LE_AND, 19)
  246. RELOC_NUMBER (R_NFP_W32BE_AND, 20)
  247. RELOC_NUMBER (R_NFP_W32LE_OR, 21)
  248. RELOC_NUMBER (R_NFP_W32BE_OR, 22)
  249. RELOC_NUMBER (R_NFP_W64LE_AND, 23)
  250. RELOC_NUMBER (R_NFP_W64BE_AND, 24)
  251. RELOC_NUMBER (R_NFP_W64LE_OR, 25)
  252. RELOC_NUMBER (R_NFP_W64BE_OR, 26)
  253. END_RELOC_NUMBERS (R_NFP_MAX)
  254. #ifdef __cplusplus
  255. }
  256. #endif
  257. #endif /* _ELF_NFP_H */