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