numam-dpdk/buildtools/pmdinfogen/pmdinfogen.h
Neil Horman 98b0fdb0ff pmdinfogen: add buildtools and pmdinfogen utility
pmdinfogen is a tool used to parse object files and build json strings for
use in later determining hardware support in a dso or application binary.
pmdinfo looks for the non-exported symbol names this_pmd_name<n> and
this_pmd_tbl<n> (where n is a integer counter).  It records the name of
each of these tuples, using the later to find the symbolic name of the
pci_table for physical devices that the object supports.  With this
information, it outputs a C file with a single line of the form:

static char *<pmd_name>_driver_info[] __attribute__((used)) = " \
	PMD_DRIVER_INFO=<json string>";

Where <pmd_name> is the arbitrary name of the pmd, and <json_string> is the
json encoded string that hold relevant pmd information, including the pmd
name, type and optional array of pci device/vendor ids that the driver
supports.

This c file is suitable for compiling to object code, then relocatably
linking into the parent file from which the C was generated.  This creates
an entry in the string table of the object that can inform a later tool
about hardware support.

Signed-off-by: Neil Horman <nhorman@tuxdriver.com>
Acked-by: Panu Matilainen <pmatilai@redhat.com>
Acked-by: Remy Horton <remy.horton@intel.com>
2016-07-06 22:34:39 +02:00

121 lines
3.0 KiB
C

/* Postprocess pmd object files to export hw support
*
* Copyright 2016 Neil Horman <nhorman@tuxdriver.com>
* Based in part on modpost.c from the linux kernel
*
* This software may be used and distributed according to the terms
* of the GNU General Public License V2, incorporated herein by reference.
*
*/
#include <stdio.h>
#include <stdlib.h>
#include <stdarg.h>
#include <string.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/mman.h>
#include <fcntl.h>
#include <unistd.h>
#include <elf.h>
#include <rte_config.h>
#include <rte_pci.h>
#include <rte_byteorder.h>
/* On BSD-alike OSes elf.h defines these according to host's word size */
#undef ELF_ST_BIND
#undef ELF_ST_TYPE
#undef ELF_R_SYM
#undef ELF_R_TYPE
/*
* Define ELF64_* to ELF_*, the latter being defined in both 32 and 64 bit
* flavors in elf.h. This makes our code a bit more generic between arches
* and allows us to support 32 bit code in the future should we ever want to
*/
#ifdef RTE_ARCH_64
#define Elf_Ehdr Elf64_Ehdr
#define Elf_Shdr Elf64_Shdr
#define Elf_Sym Elf64_Sym
#define Elf_Addr Elf64_Addr
#define Elf_Sword Elf64_Sxword
#define Elf_Section Elf64_Half
#define ELF_ST_BIND ELF64_ST_BIND
#define ELF_ST_TYPE ELF64_ST_TYPE
#define Elf_Rel Elf64_Rel
#define Elf_Rela Elf64_Rela
#define ELF_R_SYM ELF64_R_SYM
#define ELF_R_TYPE ELF64_R_TYPE
#else
#define Elf_Ehdr Elf32_Ehdr
#define Elf_Shdr Elf32_Shdr
#define Elf_Sym Elf32_Sym
#define Elf_Addr Elf32_Addr
#define Elf_Sword Elf32_Sxword
#define Elf_Section Elf32_Half
#define ELF_ST_BIND ELF32_ST_BIND
#define ELF_ST_TYPE ELF32_ST_TYPE
#define Elf_Rel Elf32_Rel
#define Elf_Rela Elf32_Rela
#define ELF_R_SYM ELF32_R_SYM
#define ELF_R_TYPE ELF32_R_TYPE
#endif
/*
* Note, it seems odd that we have both a CONVERT_NATIVE and a TO_NATIVE macro
* below. We do this because the values passed to TO_NATIVE may themselves be
* macros and need both macros here to get expanded. Specifically its the width
* variable we are concerned with, because it needs to get expanded prior to
* string concatenation
*/
#define CONVERT_NATIVE(fend, width, x) ({ \
typeof(x) ___x; \
if ((fend) == ELFDATA2LSB) \
___x = rte_le_to_cpu_##width(x); \
else \
___x = rte_be_to_cpu_##width(x); \
___x; \
})
#define TO_NATIVE(fend, width, x) CONVERT_NATIVE(fend, width, x)
enum opt_params {
PMD_PARAM_STRING = 0,
PMD_OPT_MAX
};
struct pmd_driver {
Elf_Sym *name_sym;
const char *name;
struct rte_pci_id *pci_tbl;
struct pmd_driver *next;
const char *opt_vals[PMD_OPT_MAX];
};
struct elf_info {
unsigned long size;
Elf_Ehdr *hdr;
Elf_Shdr *sechdrs;
Elf_Sym *symtab_start;
Elf_Sym *symtab_stop;
char *strtab;
/* support for 32bit section numbers */
unsigned int num_sections; /* max_secindex + 1 */
unsigned int secindex_strings;
/* if Nth symbol table entry has .st_shndx = SHN_XINDEX,
* take shndx from symtab_shndx_start[N] instead
*/
Elf32_Word *symtab_shndx_start;
Elf32_Word *symtab_shndx_stop;
struct pmd_driver *drivers;
};