107163879Schristos /* NFP ELF support for BFD. 2*1424dfb3Schristos Copyright (C) 2017-2020 Free Software Foundation, Inc. 307163879Schristos Contributed by Francois H. Theron <francois.theron@netronome.com> 407163879Schristos 507163879Schristos This file is part of BFD, the Binary File Descriptor library. 607163879Schristos 707163879Schristos This program is free software; you can redistribute it and/or modify 807163879Schristos it under the terms of the GNU General Public License as published by 907163879Schristos the Free Software Foundation; either version 3 of the License, or 1007163879Schristos (at your option) any later version. 1107163879Schristos 1207163879Schristos This program is distributed in the hope that it will be useful, 1307163879Schristos but WITHOUT ANY WARRANTY; without even the implied warranty of 1407163879Schristos MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 1507163879Schristos GNU General Public License for more details. 1607163879Schristos 1707163879Schristos You should have received a copy of the GNU General Public License 1807163879Schristos along with this program; if not, write to the Free Software Foundation, 1907163879Schristos Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA. */ 2007163879Schristos 2107163879Schristos #ifndef _ELF_NFP_H 2207163879Schristos #define _ELF_NFP_H 2307163879Schristos 2407163879Schristos #include "bfd.h" 2507163879Schristos #include "elf/common.h" 2607163879Schristos #include "elf/reloc-macros.h" 2707163879Schristos #include "bfd_stdint.h" 2807163879Schristos 2907163879Schristos #ifdef __cplusplus 3007163879Schristos extern "C" 3107163879Schristos { 3207163879Schristos #endif 3307163879Schristos 3407163879Schristos #define ET_NFP_PARTIAL_REL (ET_LOPROC + ET_REL) 3507163879Schristos #define ET_NFP_PARTIAL_EXEC (ET_LOPROC + ET_EXEC) 3607163879Schristos 3707163879Schristos /* NFP e_flags - chip family 3807163879Schristos Valid values for FAMILY are: 3907163879Schristos 0x3200 - NFP-32xx 4007163879Schristos 0x6000 - NFP-6xxx/NFP-4xxx. */ 4107163879Schristos #define EF_NFP_MACH(ef_nfp) (((ef_nfp) >> 8) & 0xFFFF) 4207163879Schristos #define EF_NFP_SET_MACH(nfp_fam) (((nfp_fam) & 0xFFFF) << 8) 4307163879Schristos 4407163879Schristos #define E_NFP_MACH_3200 0x3200 4507163879Schristos #define E_NFP_MACH_6000 0x6000 4607163879Schristos 4707163879Schristos #define NFP_3200_CPPTGT_MSF0 1 4807163879Schristos #define NFP_3200_CPPTGT_QDR 2 4907163879Schristos #define NFP_3200_CPPTGT_MSF1 3 5007163879Schristos #define NFP_3200_CPPTGT_HASH 4 5107163879Schristos #define NFP_3200_CPPTGT_MU 7 5207163879Schristos #define NFP_3200_CPPTGT_GS 8 5307163879Schristos #define NFP_3200_CPPTGT_PCIE 9 5407163879Schristos #define NFP_3200_CPPTGT_ARM 10 5507163879Schristos #define NFP_3200_CPPTGT_CRYPTO 12 5607163879Schristos #define NFP_3200_CPPTGT_CAP 13 5707163879Schristos #define NFP_3200_CPPTGT_CT 14 5807163879Schristos #define NFP_3200_CPPTGT_CLS 15 5907163879Schristos 6007163879Schristos #define NFP_6000_CPPTGT_NBI 1 6107163879Schristos #define NFP_6000_CPPTGT_VQDR 2 6207163879Schristos #define NFP_6000_CPPTGT_ILA 6 6307163879Schristos #define NFP_6000_CPPTGT_MU 7 6407163879Schristos #define NFP_6000_CPPTGT_PCIE 9 6507163879Schristos #define NFP_6000_CPPTGT_ARM 10 6607163879Schristos #define NFP_6000_CPPTGT_CRYPTO 12 6707163879Schristos #define NFP_6000_CPPTGT_CTXPB 14 6807163879Schristos #define NFP_6000_CPPTGT_CLS 15 6907163879Schristos 7007163879Schristos /* NFP Section types 7107163879Schristos MECONFIG - NFP-32xx only, ME CSR configurations 7207163879Schristos INITREG - A generic register initialisation section (chip or ME CSRs/GPRs) 7307163879Schristos UDEBUG - Legacy-style debug data section. */ 7407163879Schristos #define SHT_NFP_MECONFIG (SHT_LOPROC + 1) 7507163879Schristos #define SHT_NFP_INITREG (SHT_LOPROC + 2) 7607163879Schristos #define SHT_NFP_UDEBUG SHT_LOUSER 7707163879Schristos 7807163879Schristos /* NFP SECTION flags 7907163879Schristos ELF-64 sh_flags is 64-bit, but there is no info on what the upper 32 bits 8007163879Schristos are expected to be used for, it is not marked reserved either. 8107163879Schristos We'll use them for NFP-specific flags since we don't use ELF-32. 8207163879Schristos 8307163879Schristos INIT - Sections that are loaded and executed before the final text 8407163879Schristos microcode. Non-code INIT sections are loaded first, then other 8507163879Schristos memory secions, then INIT2 sections, then INIT-code sections. 8607163879Schristos INIT2 - Sections that are loaded before INIT-code sections, used for 8707163879Schristos transient configuration before executing INIT-code section 8807163879Schristos microcode. 8907163879Schristos SCS - The number of additional ME codestores being shared with the group's 9007163879Schristos base ME of the section, e.g. 0 for no SCS, 1 for dual and 3 for 9107163879Schristos quad. If this is 0 it is possible that stagger-style SCS codestore 9207163879Schristos sections are being used. For stagger-style each section is simply 9307163879Schristos loaded directly to the ME it is assigned to. If these flags are 9407163879Schristos used, virtual address space loading will be used - one large section 9507163879Schristos loaded to the group's base ME will be packed across shared MEs by 9607163879Schristos hardware. This is not available on all ME versions. 9707163879Schristos 9807163879Schristos NFP_ELF_SHF_GET_SCS (val) returns the number of additional codestores 9907163879Schristos being shared with the group's base ME, e.g. 0 for no SCS, 10007163879Schristos 1 for dual SCS, 3 for quad SCS. */ 10107163879Schristos 10207163879Schristos #define SHF_NFP_INIT 0x80000000 10307163879Schristos #define SHF_NFP_INIT2 0x40000000 10407163879Schristos #define SHF_NFP_SCS(shf) (((shf) >> 32) & 0xFF) 10507163879Schristos #define SHF_NFP_SET_SCS(v) (((BFD_HOST_U_64_BIT)((v) & 0xFF)) << 32) 10607163879Schristos 10707163879Schristos /* NFP Section Info 10807163879Schristos For PROGBITS and NOBITS sections: 10907163879Schristos MEMTYPE - the memory type 11007163879Schristos DOMAIN - The island ID and ME number where the data will be loaded. 11107163879Schristos For NFP-32xx, this is an island number or linear ME number. 11207163879Schristos For NFP-6xxx, DOMAIN<15:8> == island ID, DOMAIN<7:0> is 0 based 11307163879Schristos ME number (if applicable). 11407163879Schristos For INITREG sections: 11507163879Schristos ISLAND - island ID (if it's a ME target, ME numbers are in the 11607163879Schristos section data) 11707163879Schristos CPPTGT - CPP Target ID 11807163879Schristos CPPACTRD - CPP Read Action 11907163879Schristos CPPTOKRD - CPP Read Token 12007163879Schristos CPPACTWR - CPP Write Action 12107163879Schristos CPPTOKWR - CPP Write Token 12207163879Schristos ORDER - Controls the order in which the loader processes sections with 12307163879Schristos the same info fields. */ 12407163879Schristos 12507163879Schristos #define SHI_NFP_DOMAIN(shi) (((shi) >> 16) & 0xFFFF) 12607163879Schristos #define SHI_NFP_MEMTYPE(shi) ( (shi) & 0xFFFF) 12707163879Schristos #define SHI_NFP_SET_DOMAIN(v) (((v) & 0xFFFF) << 16) 12807163879Schristos #define SHI_NFP_SET_MEMTYPE(v) ( (v) & 0xFFFF) 12907163879Schristos 13007163879Schristos #define SHI_NFP_IREG_ISLAND(shi) (((shi) >> 26) & 0x3F) 13107163879Schristos #define SHI_NFP_IREG_CPPTGT(shi) (((shi) >> 22) & 0xF) 13207163879Schristos #define SHI_NFP_IREG_CPPACTRD(shi) (((shi) >> 17) & 0x1F) 13307163879Schristos #define SHI_NFP_IREG_CPPTOKRD(shi) (((shi) >> 15) & 0x3) 13407163879Schristos #define SHI_NFP_IREG_CPPACTWR(shi) (((shi) >> 10) & 0x1F) 13507163879Schristos #define SHI_NFP_IREG_CPPTOKWR(shi) (((shi) >> 8) & 0x3) 13607163879Schristos #define SHI_NFP_IREG_ORDER(shi) ( (shi) & 0xFF) 13707163879Schristos #define SHI_NFP_SET_IREG_ISLAND(v) (((v) & 0x3F) << 26) 13807163879Schristos #define SHI_NFP_SET_IREG_CPPTGT(v) (((v) & 0xF) << 22) 13907163879Schristos #define SHI_NFP_SET_IREG_CPPACTRD(v) (((v) & 0x1F) << 17) 14007163879Schristos #define SHI_NFP_SET_IREG_CPPTOKRD(v) (((v) & 0x3) << 15) 14107163879Schristos #define SHI_NFP_SET_IREG_CPPACTWR(v) (((v) & 0x1F) << 10) 14207163879Schristos #define SHI_NFP_SET_IREG_CPPTOKWR(v) (((v) & 0x3) << 8) 14307163879Schristos #define SHI_NFP_SET_IREG_ORDER(v) ( (v) & 0xFF) 14407163879Schristos 14507163879Schristos /* CtXpb/reflect_read_sig_init/reflect_write_sig_init 14607163879Schristos identifies Init-CSR sections for ME CSRs. */ 14707163879Schristos #define SHI_NFP_6000_IS_IREG_MECSR(shi) ( \ 14807163879Schristos SHI_NFP_IREG_CPPTGT (shi) == NFP_6000_CPPTGT_CTXPB \ 14907163879Schristos && SHI_NFP_IREG_CPPACTRD (shi) == 2 \ 15007163879Schristos && SHI_NFP_IREG_CPPTOKRD (shi) == 1 \ 15107163879Schristos && SHI_NFP_IREG_CPPACTWR (shi) == 3 \ 15207163879Schristos && SHI_NFP_IREG_CPPTOKWR (shi) == 1 \ 15307163879Schristos ) 15407163879Schristos 15507163879Schristos /* Transient INITREG sections will be validated against the target 15607163879Schristos but will not be kept - validate, write or read and discard. 15707163879Schristos They will still be handled last (in order). */ 15807163879Schristos #define SHI_NFP_IREG_ORDER_TRANSIENT 0xFF 15907163879Schristos 16007163879Schristos /* Below are some extra macros to translate SHI fields in more specific 16107163879Schristos contexts. 16207163879Schristos 16307163879Schristos For NFP-32xx, DOMAIN is set to a global linear ME number (0 to 39). 16407163879Schristos An NFP-32xx has 8 MEs per island and up to 5 islands. */ 16507163879Schristos 16607163879Schristos #define SHI_NFP_3200_ISLAND(shi) ((SHI_NFP_DOMAIN (shi) >> 3) & 0x7) 16707163879Schristos #define SHI_NFP_3200_MENUM(shi) ( SHI_NFP_DOMAIN (shi) & 0x7) 16807163879Schristos #define SHI_NFP_SET_3200_ISLAND(v) SHI_NFP_SET_DOMAIN (((v) & 0x7) << 3) 16907163879Schristos #define SHI_NFP_SET_3200_MENUM(v) SHI_NFP_SET_DOMAIN ( (v) & 0x7) 17007163879Schristos 17107163879Schristos #define SHI_NFP_ISLAND(shi) ((SHI_NFP_DOMAIN (shi) >> 8) & 0xFF) 17207163879Schristos #define SHI_NFP_MENUM(shi) ( SHI_NFP_DOMAIN (shi) & 0xFF) 17307163879Schristos #define SHI_NFP_SET_ISLAND(shi) SHI_NFP_SET_DOMAIN (((shi) & 0xFF) << 8) 17407163879Schristos #define SHI_NFP_SET_MENUM(shi) SHI_NFP_SET_DOMAIN ( (shi) & 0xFF) 17507163879Schristos 17607163879Schristos #define SHI_NFP_MEMTYPE_NONE 0 17707163879Schristos #define SHI_NFP_MEMTYPE_USTORE 1 17807163879Schristos #define SHI_NFP_MEMTYPE_LMEM 2 17907163879Schristos #define SHI_NFP_MEMTYPE_CLS 3 18007163879Schristos #define SHI_NFP_MEMTYPE_DRAM 4 18107163879Schristos #define SHI_NFP_MEMTYPE_MU 4 18207163879Schristos #define SHI_NFP_MEMTYPE_SRAM 5 18307163879Schristos #define SHI_NFP_MEMTYPE_GS 6 18407163879Schristos #define SHI_NFP_MEMTYPE_PPC_LMEM 7 18507163879Schristos #define SHI_NFP_MEMTYPE_PPC_SMEM 8 18607163879Schristos #define SHI_NFP_MEMTYPE_EMU_CACHE 9 18707163879Schristos 18807163879Schristos /* VTP_FORCE is for use by the NFP Linker+Loader only. */ 18907163879Schristos #define NFP_IREG_VTP_FORCE 0 19007163879Schristos #define NFP_IREG_VTP_CONST 1 19107163879Schristos #define NFP_IREG_VTP_REQUIRED 2 19207163879Schristos #define NFP_IREG_VTP_VOLATILE_INIT 3 19307163879Schristos #define NFP_IREG_VTP_VOLATILE_NOINIT 4 19407163879Schristos #define NFP_IREG_VTP_INVALID 5 19507163879Schristos 19607163879Schristos /* Init-CSR entry w0 fields: 19707163879Schristos NLW - Not Last Word 19807163879Schristos CTX - ME context number (if applicable) 19907163879Schristos VTP - Value type 20007163879Schristos COH - CPP Offset High 8 bits. */ 20107163879Schristos #define NFP_IREG_ENTRY_WO_NLW(w0) (((w0) >> 31) & 0x1) 20207163879Schristos #define NFP_IREG_ENTRY_WO_CTX(w0) (((w0) >> 28) & 0x7) 20307163879Schristos #define NFP_IREG_ENTRY_WO_VTP(w0) (((w0) >> 25) & 0x7) 20407163879Schristos #define NFP_IREG_ENTRY_WO_COH(w0) (((w0) >> 0) & 0xFF) 20507163879Schristos 20607163879Schristos typedef struct 20707163879Schristos { 20807163879Schristos uint32_t w0; 20907163879Schristos uint32_t cpp_offset_lo; 21007163879Schristos uint32_t val; 21107163879Schristos uint32_t mask; 21207163879Schristos } Elf_Nfp_InitRegEntry; 21307163879Schristos 21407163879Schristos typedef struct 21507163879Schristos { 21607163879Schristos uint32_t ctx_enables; 21707163879Schristos uint32_t entry; 21807163879Schristos uint32_t misc_control; 21907163879Schristos uint32_t reserved; 22007163879Schristos } Elf_Nfp_MeConfig; 22107163879Schristos 22207163879Schristos /* Relocations. */ 22307163879Schristos START_RELOC_NUMBERS (elf_nfp3200_reloc_type) 22407163879Schristos RELOC_NUMBER (R_NFP3200_NOTYPE, 0) 22507163879Schristos RELOC_NUMBER (R_NFP3200_W32LE, 1) 22607163879Schristos RELOC_NUMBER (R_NFP3200_SRC8_A, 2) 22707163879Schristos RELOC_NUMBER (R_NFP3200_SRC8_B, 3) 22807163879Schristos RELOC_NUMBER (R_NFP3200_IMMED8_I, 4) 22907163879Schristos RELOC_NUMBER (R_NFP3200_SC, 5) 23007163879Schristos RELOC_NUMBER (R_NFP3200_IMMED_LO16_I_A, 6) 23107163879Schristos RELOC_NUMBER (R_NFP3200_IMMED_LO16_I_B, 7) 23207163879Schristos RELOC_NUMBER (R_NFP3200_SRC7_B, 8) 23307163879Schristos RELOC_NUMBER (R_NFP3200_SRC7_A, 9) 23407163879Schristos RELOC_NUMBER (R_NFP3200_SRC8_I_B, 10) 23507163879Schristos RELOC_NUMBER (R_NFP3200_SRC8_I_A, 11) 23607163879Schristos RELOC_NUMBER (R_NFP3200_IMMED_HI16_I_A, 12) 23707163879Schristos RELOC_NUMBER (R_NFP3200_IMMED_HI16_I_B, 13) 23807163879Schristos RELOC_NUMBER (R_NFP3200_RSVD_0, 14) 23907163879Schristos RELOC_NUMBER (R_NFP3200_RSVD_1, 15) 24007163879Schristos RELOC_NUMBER (R_NFP3200_RSVD_2, 16) 24107163879Schristos RELOC_NUMBER (R_NFP3200_RSVD_3, 17) 24207163879Schristos RELOC_NUMBER (R_NFP3200_RSVD_4, 18) 24307163879Schristos RELOC_NUMBER (R_NFP3200_RSVD_5, 19) 24407163879Schristos RELOC_NUMBER (R_NFP3200_RSVD_6, 20) 24507163879Schristos RELOC_NUMBER (R_NFP3200_W64LE, 21) 24607163879Schristos RELOC_NUMBER (R_NFP3200_W32BE, 22) 24707163879Schristos RELOC_NUMBER (R_NFP3200_W64BE, 23) 24807163879Schristos RELOC_NUMBER (R_NFP3200_W32LE_AND, 24) 24907163879Schristos RELOC_NUMBER (R_NFP3200_W32BE_AND, 25) 25007163879Schristos RELOC_NUMBER (R_NFP3200_W32LE_OR, 26) 25107163879Schristos RELOC_NUMBER (R_NFP3200_W32BE_OR, 27) 25207163879Schristos RELOC_NUMBER (R_NFP3200_W64LE_AND, 28) 25307163879Schristos RELOC_NUMBER (R_NFP3200_W64BE_AND, 29) 25407163879Schristos RELOC_NUMBER (R_NFP3200_W64LE_OR, 30) 25507163879Schristos RELOC_NUMBER (R_NFP3200_W64BE_OR, 31) 25607163879Schristos END_RELOC_NUMBERS (R_NFP3200_MAX) 25707163879Schristos 25807163879Schristos START_RELOC_NUMBERS (elf_nfp_reloc_type) 25907163879Schristos RELOC_NUMBER (R_NFP_NOTYPE, 0) 26007163879Schristos RELOC_NUMBER (R_NFP_W32LE, 1) 26107163879Schristos RELOC_NUMBER (R_NFP_SRC8_A, 2) 26207163879Schristos RELOC_NUMBER (R_NFP_SRC8_B, 3) 26307163879Schristos RELOC_NUMBER (R_NFP_IMMED8_I, 4) 26407163879Schristos RELOC_NUMBER (R_NFP_SC, 5) 26507163879Schristos RELOC_NUMBER (R_NFP_IMMED_LO16_I_A, 6) 26607163879Schristos RELOC_NUMBER (R_NFP_IMMED_LO16_I_B, 7) 26707163879Schristos RELOC_NUMBER (R_NFP_SRC7_B, 8) 26807163879Schristos RELOC_NUMBER (R_NFP_SRC7_A, 9) 26907163879Schristos RELOC_NUMBER (R_NFP_SRC8_I_B, 10) 27007163879Schristos RELOC_NUMBER (R_NFP_SRC8_I_A, 11) 27107163879Schristos RELOC_NUMBER (R_NFP_IMMED_HI16_I_A, 12) 27207163879Schristos RELOC_NUMBER (R_NFP_IMMED_HI16_I_B, 13) 27307163879Schristos RELOC_NUMBER (R_NFP_W64LE, 14) 27407163879Schristos RELOC_NUMBER (R_NFP_SH_INFO, 15) 27507163879Schristos RELOC_NUMBER (R_NFP_W32BE, 16) 27607163879Schristos RELOC_NUMBER (R_NFP_W64BE, 17) 27707163879Schristos RELOC_NUMBER (R_NFP_W32_29_24, 18) 27807163879Schristos RELOC_NUMBER (R_NFP_W32LE_AND, 19) 27907163879Schristos RELOC_NUMBER (R_NFP_W32BE_AND, 20) 28007163879Schristos RELOC_NUMBER (R_NFP_W32LE_OR, 21) 28107163879Schristos RELOC_NUMBER (R_NFP_W32BE_OR, 22) 28207163879Schristos RELOC_NUMBER (R_NFP_W64LE_AND, 23) 28307163879Schristos RELOC_NUMBER (R_NFP_W64BE_AND, 24) 28407163879Schristos RELOC_NUMBER (R_NFP_W64LE_OR, 25) 28507163879Schristos RELOC_NUMBER (R_NFP_W64BE_OR, 26) 28607163879Schristos END_RELOC_NUMBERS (R_NFP_MAX) 28707163879Schristos 28807163879Schristos #ifdef __cplusplus 28907163879Schristos } 29007163879Schristos #endif 29107163879Schristos 29207163879Schristos #endif /* _ELF_NFP_H */ 293