From patchwork Wed Jul 8 00:53:52 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dmitry Kozlyuk X-Patchwork-Id: 73481 X-Patchwork-Delegate: thomas@monjalon.net Return-Path: X-Original-To: patchwork@inbox.dpdk.org Delivered-To: patchwork@inbox.dpdk.org Received: from dpdk.org (dpdk.org [92.243.14.124]) by inbox.dpdk.org (Postfix) with ESMTP id 73C7AA00BE; Wed, 8 Jul 2020 02:54:20 +0200 (CEST) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id EF24B1DD31; Wed, 8 Jul 2020 02:54:17 +0200 (CEST) Received: from mail-lf1-f49.google.com (mail-lf1-f49.google.com [209.85.167.49]) by dpdk.org (Postfix) with ESMTP id 09BAA1DCFE for ; Wed, 8 Jul 2020 02:54:13 +0200 (CEST) Received: by mail-lf1-f49.google.com with SMTP id o4so25900844lfi.7 for ; Tue, 07 Jul 2020 17:54:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=vv/p3hiG61PjzDvtM8llR7UP/N4ZMnzJB1B1s57Uapg=; b=YTNLhpdcUgfICD1d4IIQ6jlawUWmP743Nn8IH5Wbboq6iPcPIHlbVmT+TG1IUbo/9B C7P/kCu8Z9kTT6YevLwUkhhDT4/UyC3O0ww1gA/OupA9/1WzUa6kxkgflXi1XMEMkHya bhuhQhW1/eDSYLZDr4+98TgYD05C5DzbuPmdtSnNoa6Gow46r3Id53ogApJt5teSUuQD 6/nQnpT4vb54TjUKY+3glxfjgp5TcPQyIE5Tt+fVYbEpJ+NWuUxepSc7guWXuKpPpXSR m1MdcyPYludn5W3FuHIKt6G8VuwP2nSVcanXU+t8QRy+T/9sJKzqSmsKQ93Y8JjAzfWq B+OA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=vv/p3hiG61PjzDvtM8llR7UP/N4ZMnzJB1B1s57Uapg=; b=esMRg1MgGp/vDjCOoaQWrfy4KaScWCfw+Qcrg+Mfwx45zKQyDPEwtrIP3rGlughJt8 krMGQPaT2K4FP8rrj7aW/BSQvM4l6f5nPJNpbgPiPDGLF09agsp/MnRgJlcqvgvqEjor 0WY6Veucxd4OCo9KhKgE2Fbjfwzk8PRencUqmxjkD1zAJVloFAnK7eidzsE4DC+FuXJ2 VSpqUx3pSpl/0S3nM7ix163ApXw/Xv/6jsjlZ8wr1X9nb9HWxrEF3c0bmty7x6rDmUbK 9hhrf/mPI1OeY6wdbReRzUiYN118ruml1v37jaEaFIaWiE3fms1Nf5YGrQv10iL6tLF2 Xk1Q== X-Gm-Message-State: AOAM532CeQV8Hu3bJctj6flnsDpYPv3o9OASJCKU3XKmmm6B87Cs3KBI wapoQKOhkIsuQYcuI00ep9an8AGhNGvPVQ== X-Google-Smtp-Source: ABdhPJwRuuGPQxMWYdyZ9Z443WJN+hOLCPVm6JTU1IoeG1qLRsi42gfwAyaxkpjRmVA/WDgk3ldLqQ== X-Received: by 2002:ac2:5a5e:: with SMTP id r30mr34881003lfn.30.1594169652171; Tue, 07 Jul 2020 17:54:12 -0700 (PDT) Received: from localhost.localdomain (broadband-37-110-65-23.ip.moscow.rt.ru. [37.110.65.23]) by smtp.gmail.com with ESMTPSA id h22sm515986ljg.1.2020.07.07.17.54.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 07 Jul 2020 17:54:11 -0700 (PDT) From: Dmitry Kozlyuk To: dev@dpdk.org Cc: Neil Horman , Bruce Richardson , Thomas Monjalon , robin.jarry@6wind.com, Jie Zhou , Tal Shnaiderman , Dmitry Kozlyuk Date: Wed, 8 Jul 2020 03:53:52 +0300 Message-Id: <20200708005355.7102-2-dmitry.kozliuk@gmail.com> X-Mailer: git-send-email 2.25.4 In-Reply-To: <20200708005355.7102-1-dmitry.kozliuk@gmail.com> References: <20200702000232.10761-1-dmitry.kozliuk@gmail.com> <20200708005355.7102-1-dmitry.kozliuk@gmail.com> MIME-Version: 1.0 Subject: [dpdk-dev] [PATCH v3 1/4] pmdinfogen: add Python implementation X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Sender: "dev" Using a high-level, interpreted language simplifies maintenance and build process. Furthermore, ELF handling is delegated to pyelftools package. Original logic is kept, the copyright recognizes that. Signed-off-by: Dmitry Kozlyuk --- buildtools/pmdinfogen.py | 194 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 194 insertions(+) create mode 100755 buildtools/pmdinfogen.py diff --git a/buildtools/pmdinfogen.py b/buildtools/pmdinfogen.py new file mode 100755 index 000000000..c32654a4a --- /dev/null +++ b/buildtools/pmdinfogen.py @@ -0,0 +1,194 @@ +#!/usr/bin/env python3 +# SPDX-License-Identifier: BSD-3-Clause +# Copyright (c) 2016 Neil Horman +# Copyright (c) 2020 Dmitry Kozlyuk + +import argparse +import ctypes +import json +import sys +import tempfile + +from elftools.elf.elffile import ELFFile +from elftools.elf.sections import SymbolTableSection + + +class ELFSymbol: + def __init__(self, image, symbol): + self._image = image + self._symbol = symbol + + @property + def size(self): + return self._symbol["st_size"] + + @property + def value(self): + data = self._image._image.get_section(self._symbol["st_shndx"]).data() + base = self._symbol["st_value"] + return data[base : base + self.size] + + @property + def string_value(self): + value = self.value + if len(value): + return value[:-1].decode() + return "" + + +class ELFImage: + def __init__(self, data): + self._image = ELFFile(data) + self._symtab = self._image.get_section_by_name(".symtab") + if not isinstance(self._symtab, SymbolTableSection): + raise Exception(".symtab section is not a symbol table") + + @property + def is_big_endian(self): + return not self._image.little_endian + + def find_by_name(self, name): + symbol = self._symtab.get_symbol_by_name(name) + if symbol: + return ELFSymbol(self, symbol[0]) + + def find_by_prefix(self, prefix): + for i in range(self._symtab.num_symbols()): + symbol = self._symtab.get_symbol(i) + if symbol.name.startswith(prefix): + yield ELFSymbol(self, symbol) + + +def define_rte_pci_id(is_big_endian): + base_type = ctypes.LittleEndianStructure + if is_big_endian: + base_type = ctypes.BigEndianStructure + + class rte_pci_id(base_type): + _pack_ = True + _fields_ = [ + ("class_id", ctypes.c_uint32), + ("vendor_id", ctypes.c_uint16), + ("device_id", ctypes.c_uint16), + ("subsystem_vendor_id", ctypes.c_uint16), + ("subsystem_device_id", ctypes.c_uint16), + ] + + return rte_pci_id + + +class Driver: + OPTIONS = [ + ("params", "_param_string_export"), + ("kmod", "_kmod_dep_export"), + ] + + def __init__(self, name, options): + self.name = name + for key, value in options.items(): + setattr(self, key, value) + self.pci_ids = [] + + @classmethod + def load(cls, image, symbol): + name = symbol.string_value + + options = {} + for key, suffix in cls.OPTIONS: + option_symbol = image.find_by_name("__%s%s" % (name, suffix)) + if option_symbol: + value = option_symbol.string_value + options[key] = value + + driver = cls(name, options) + + pci_table_name_symbol = image.find_by_name("__%s_pci_tbl_export" % name) + if pci_table_name_symbol: + driver._load_pci_ids(image, pci_table_name_symbol) + + return driver + + def _load_pci_ids(self, image, table_name_symbol): + table_name = table_name_symbol.string_value + table_symbol = image.find_by_name(table_name) + if not table_symbol: + raise Exception("PCI table declared but not defined: %d" % table_name) + + rte_pci_id = define_rte_pci_id(image.is_big_endian) + + pci_id_size = ctypes.sizeof(rte_pci_id) + if table_symbol.size % pci_id_size != 0: + raise Exception( + "PCI table size (%d) is not a multiple of rte_pci_id size (%d)" + % (table_symbol.size, pci_id_size) + ) + + pci_ids_desc = rte_pci_id * (table_symbol.size // pci_id_size) + pci_ids = pci_ids_desc.from_buffer_copy(table_symbol.value) + for pci_id in pci_ids: + if not pci_id.device_id: + break + self.pci_ids.append( + [ + pci_id.vendor_id, + pci_id.device_id, + pci_id.subsystem_vendor_id, + pci_id.subsystem_device_id, + ] + ) + + def dump(self, file): + dumped = json.dumps(self.__dict__) + escaped = dumped.replace('"', '\\"') + print( + 'const char %s_pmd_info[] __attribute__((used)) = "PMD_INFO_STRING= %s";' + % (self.name, escaped), + file=file, + ) + + +def load_drivers(image): + drivers = [] + for symbol in image.find_by_prefix("this_pmd_name"): + drivers.append(Driver.load(image, symbol)) + return drivers + + +def dump_drivers(drivers, file): + # Keep legacy order of definitions. + for driver in reversed(drivers): + driver.dump(file) + + +def parse_args(): + parser = argparse.ArgumentParser() + parser.add_argument("input", help="input object file path or '-' for stdin") + parser.add_argument("output", help="output C file path or '-' for stdout") + return parser.parse_args() + + +def open_input(path): + if path == "-": + temp = tempfile.TemporaryFile() + temp.write(sys.stdin.buffer.read()) + return temp + return open(path, "rb") + + +def open_output(path): + if path == "-": + return sys.stdout + return open(path, "w") + + +def main(): + args = parse_args() + infile = open_input(args.input) + image = ELFImage(infile) + drivers = load_drivers(image) + output = open_output(args.output) + dump_drivers(drivers, output) + + +if __name__ == "__main__": + main() From patchwork Wed Jul 8 00:53:53 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dmitry Kozlyuk X-Patchwork-Id: 73482 X-Patchwork-Delegate: thomas@monjalon.net Return-Path: X-Original-To: patchwork@inbox.dpdk.org Delivered-To: patchwork@inbox.dpdk.org Received: from dpdk.org (dpdk.org [92.243.14.124]) by inbox.dpdk.org (Postfix) with ESMTP id 24F5BA00BE; Wed, 8 Jul 2020 02:54:27 +0200 (CEST) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id A88AA1DD48; Wed, 8 Jul 2020 02:54:20 +0200 (CEST) Received: from mail-lj1-f195.google.com (mail-lj1-f195.google.com [209.85.208.195]) by dpdk.org (Postfix) with ESMTP id 4FEA01DD11 for ; Wed, 8 Jul 2020 02:54:14 +0200 (CEST) Received: by mail-lj1-f195.google.com with SMTP id f5so36334811ljj.10 for ; Tue, 07 Jul 2020 17:54:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=S80P6Jny2RG5HDhbqjgpDbYyO3/J3JYhYBKK+KpjIE8=; b=Qv1I9Efdp9QszICF7rBDiFwhcQ7p/YIexfbvRV4tGbwHKorzqCWO+L26f+yxGIcbZX N23j65koqK+AhBOlfQTu/FzkBUrP9Y6meI9O9EfZCVg4erBaOn6Jdl5J4hDnfbuMBFaP 2dA9Fok93YRec7Kn5/TYGZUEFcZHa0CsIIY/kqTJ/NG9Q9fBZ2QVk0FLV1W7ZrGq4aaY 3vEChVpfaMMagQjPrXmIATLw1j3LfPl91XLpB3L0JgStYrveXkdDSadQUvlu001ZQmM3 V3Ee0a29osAQjOJIog9GHk/8PRu/gpATzyI63rW+zLKUZdwbyAIS4S0M5GUqLoL1MUol G9TA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=S80P6Jny2RG5HDhbqjgpDbYyO3/J3JYhYBKK+KpjIE8=; b=VG22VG58+N3tVGYX7GVpV+uGH1mp/CJ2ahncHeRcYgd5iuow586lGiS3exm095G/7x qosWO66T5GThcx5DpOsH6ffNcDXt0Auiqww40PLAFYCpXMDWdaB3K/VelR1qLf9p8xb8 NFlEDjGPXTN2iuBut+KfrYt84aDT6ZFC3Geca5nsBq7+ZJLXqSj2sRGh6RR9PC/IIDhM Kc0dteIeKMrypdLIyxB5CNlE9oN7G+ooptm25k+3qHin0etT2QDVQlIRRXUt1iaJgXS0 kXtkHKON/EfwWfeudqaW/o0K79z9ffCX+jADpH/XOasZ4qDFveE90KHbHhPyf5v5x9PC rfsw== X-Gm-Message-State: AOAM5339II0Rs02kGWNZqr1gRNMrHnCF2ofed8ptLYXZ6KDiaFE6YoJJ Ck9C6unjmxZbk8XjMGhAzGhIhWu1hld63w== X-Google-Smtp-Source: ABdhPJxX2ejPovzgN9H2t5zDC0uo4VW9T5bEFgQOUjjCPLye7fgjanH4QoGg2O9UZQRMoR6oyg+t9A== X-Received: by 2002:a2e:9c95:: with SMTP id x21mr24964797lji.234.1594169653467; Tue, 07 Jul 2020 17:54:13 -0700 (PDT) Received: from localhost.localdomain (broadband-37-110-65-23.ip.moscow.rt.ru. [37.110.65.23]) by smtp.gmail.com with ESMTPSA id h22sm515986ljg.1.2020.07.07.17.54.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 07 Jul 2020 17:54:12 -0700 (PDT) From: Dmitry Kozlyuk To: dev@dpdk.org Cc: Neil Horman , Bruce Richardson , Thomas Monjalon , robin.jarry@6wind.com, Jie Zhou , Tal Shnaiderman , Dmitry Kozlyuk , Aaron Conole , Michael Santana Date: Wed, 8 Jul 2020 03:53:53 +0300 Message-Id: <20200708005355.7102-3-dmitry.kozliuk@gmail.com> X-Mailer: git-send-email 2.25.4 In-Reply-To: <20200708005355.7102-1-dmitry.kozliuk@gmail.com> References: <20200702000232.10761-1-dmitry.kozliuk@gmail.com> <20200708005355.7102-1-dmitry.kozliuk@gmail.com> MIME-Version: 1.0 Subject: [dpdk-dev] [PATCH v3 2/4] build: use Python pmdinfogen X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Sender: "dev" Like for other build scripts, use Python interpreter to run pmdinfogen. Adjust wrapper script accordingly and also don't suppress stderr from ar and pmdinfogen. Add python3-pyelftools to CI configuration. Signed-off-by: Dmitry Kozlyuk --- .travis.yml | 2 +- GNUmakefile | 2 +- buildtools/Makefile | 9 --------- buildtools/gen-pmdinfo-cfile.sh | 6 +++--- buildtools/meson.build | 1 + drivers/meson.build | 2 +- meson.build | 1 - mk/internal/rte.compile-pre.mk | 2 +- mk/rte.sdkinstall.mk | 2 -- 9 files changed, 8 insertions(+), 19 deletions(-) delete mode 100644 buildtools/Makefile diff --git a/.travis.yml b/.travis.yml index 14f812423..28b559a25 100644 --- a/.travis.yml +++ b/.travis.yml @@ -14,7 +14,7 @@ addons: apt: update: true packages: &required_packages - - [libnuma-dev, python3-setuptools, python3-wheel, python3-pip, ninja-build] + - [libnuma-dev, python3-setuptools, python3-wheel, python3-pip, python3-pyelftools, ninja-build] - [libbsd-dev, libpcap-dev, libibverbs-dev, libcrypto++-dev, libfdt-dev, libjansson-dev] _aarch64_packages: &aarch64_packages diff --git a/GNUmakefile b/GNUmakefile index e8de422df..242d30d2e 100644 --- a/GNUmakefile +++ b/GNUmakefile @@ -12,6 +12,6 @@ export RTE_SDK # directory list # -ROOTDIRS-y := buildtools lib kernel drivers app +ROOTDIRS-y := lib kernel drivers app include $(RTE_SDK)/mk/rte.sdkroot.mk diff --git a/buildtools/Makefile b/buildtools/Makefile deleted file mode 100644 index 7f76fd7d6..000000000 --- a/buildtools/Makefile +++ /dev/null @@ -1,9 +0,0 @@ -# SPDX-License-Identifier: BSD-3-Clause -# Copyright(c) 2016 Neil Horman -# All rights reserved. - -include $(RTE_SDK)/mk/rte.vars.mk - -DIRS-y += pmdinfogen - -include $(RTE_SDK)/mk/rte.subdir.mk diff --git a/buildtools/gen-pmdinfo-cfile.sh b/buildtools/gen-pmdinfo-cfile.sh index 43059cf36..109ee461e 100755 --- a/buildtools/gen-pmdinfo-cfile.sh +++ b/buildtools/gen-pmdinfo-cfile.sh @@ -4,11 +4,11 @@ arfile=$1 output=$2 -pmdinfogen=$3 +shift 2 +pmdinfogen=$* # The generated file must not be empty if compiled in pedantic mode echo 'static __attribute__((unused)) const char *generator = "'$0'";' > $output for ofile in `ar t $arfile` ; do - ar p $arfile $ofile | $pmdinfogen - - >> $output 2> /dev/null + ar p $arfile $ofile | $pmdinfogen - - >> $output done -exit 0 diff --git a/buildtools/meson.build b/buildtools/meson.build index 04808dabc..3a64b28b7 100644 --- a/buildtools/meson.build +++ b/buildtools/meson.build @@ -17,3 +17,4 @@ else endif map_to_win_cmd = py3 + files('map_to_win.py') sphinx_wrapper = py3 + files('call-sphinx-build.py') +pmdinfogen = py3 + files('pmdinfogen.py') diff --git a/drivers/meson.build b/drivers/meson.build index 161cfda04..3c4d4b700 100644 --- a/drivers/meson.build +++ b/drivers/meson.build @@ -119,7 +119,7 @@ foreach class:dpdk_driver_classes command: [pmdinfo, tmp_lib.full_path(), '@OUTPUT@', pmdinfogen], output: out_filename, - depends: [pmdinfogen, tmp_lib]) + depends: [tmp_lib]) endif # now build the static driver diff --git a/meson.build b/meson.build index 61d9a4f5f..a6e8c09c2 100644 --- a/meson.build +++ b/meson.build @@ -45,7 +45,6 @@ subdir('buildtools') subdir('config') # build libs and drivers -subdir('buildtools/pmdinfogen') subdir('lib') subdir('drivers') diff --git a/mk/internal/rte.compile-pre.mk b/mk/internal/rte.compile-pre.mk index df05b5576..bb2ab0725 100644 --- a/mk/internal/rte.compile-pre.mk +++ b/mk/internal/rte.compile-pre.mk @@ -59,7 +59,7 @@ endif CHECK_SYMBOLS_SCRIPT = $(RTE_SDK)/buildtools/check-symbols.sh CHECK_SYMBOLS = $(CHECK_SYMBOLS_SCRIPT) $(SRCDIR)/$(EXPORT_MAP) $@ -PMDINFO_GEN = $(RTE_SDK_BIN)/app/dpdk-pmdinfogen $@ $@.pmd.c +PMDINFO_GEN = $(RTE_SDK)/buildtools/pmdinfogen.py $@ $@.pmd.c PMDINFO_CC = $(CC) $(CPPFLAGS) $(CFLAGS) $(EXTRA_CFLAGS) -c -o $@.pmd.o $@.pmd.c PMDINFO_LD = $(CROSS)ld -r $(filter-out -export-dynamic,$(LDFLAGS)) -o $@.o $@.pmd.o $@ PMDINFO_TO_O = if grep -q 'RTE_PMD_REGISTER_.*(.*)' $<; then \ diff --git a/mk/rte.sdkinstall.mk b/mk/rte.sdkinstall.mk index 32bed5d95..875a64f04 100644 --- a/mk/rte.sdkinstall.mk +++ b/mk/rte.sdkinstall.mk @@ -98,7 +98,6 @@ install-runtime: $(Q)cp $(CP_FLAGS) $O/lib/* $(DESTDIR)$(libdir) $(Q)$(call rte_mkdir, $(DESTDIR)$(bindir)) $(Q)tar -cf - -C $O --exclude 'app/*.map' \ - --exclude app/dpdk-pmdinfogen \ --exclude 'app/cmdline*' --exclude app/test \ --exclude app/testacl --exclude app/testpipeline app | \ tar -xf - -C $(DESTDIR)$(bindir) $(TAR_X_FLAGS) @@ -134,7 +133,6 @@ install-sdk: $(Q)cp $(CP_FLAGS) $(RTE_SDK)/buildtools $(DESTDIR)$(sdkdir) $(Q)$(call rte_mkdir, $(DESTDIR)$(targetdir)/app) $(Q)cp $(CP_FLAGS) $O/.config $(DESTDIR)$(targetdir) - $(Q)cp $(CP_FLAGS) $O/app/dpdk-pmdinfogen $(DESTDIR)$(targetdir)/app $(Q)$(call rte_symlink, $(DESTDIR)$(includedir), $(DESTDIR)$(targetdir)/include) $(Q)$(call rte_symlink, $(DESTDIR)$(libdir), $(DESTDIR)$(targetdir)/lib) From patchwork Wed Jul 8 00:53:54 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dmitry Kozlyuk X-Patchwork-Id: 73483 X-Patchwork-Delegate: thomas@monjalon.net Return-Path: X-Original-To: patchwork@inbox.dpdk.org Delivered-To: patchwork@inbox.dpdk.org Received: from dpdk.org (dpdk.org [92.243.14.124]) by inbox.dpdk.org (Postfix) with ESMTP id 3E1BBA00BE; Wed, 8 Jul 2020 02:54:35 +0200 (CEST) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id 6E5C51DD65; Wed, 8 Jul 2020 02:54:22 +0200 (CEST) Received: from mail-lj1-f196.google.com (mail-lj1-f196.google.com [209.85.208.196]) by dpdk.org (Postfix) with ESMTP id 6CC6F1DD15 for ; Wed, 8 Jul 2020 02:54:15 +0200 (CEST) Received: by mail-lj1-f196.google.com with SMTP id q4so16472940lji.2 for ; Tue, 07 Jul 2020 17:54:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=1+v3DraxAk+R/FdDJjf7vMV9ncMFhD0gTbJShGvK9m4=; b=n8lCTNaDE/zW5aDZ4AExIr8VvxW5+pqdeu1KgO1+u1Aqt+G8JltIXstu21Epyd+/t3 nWxf/SkNnP2808ByNBOwKEBG5DTF3tSNo1g4HZbukSlIWjFyQz2I7kfaCyO/46OOxrPg DurALma9pmj76YugiptOCRU0+nOJwnVSpsxSegRYVx0Um686DGk2C/E8A2l7Rxlaq4qr ZuERSEvIk2KrEkTNIeKWNWCIo6o6p0ihO/Epb8MSj8JQC7P9aEYGoyDKfQvnNyj6ZYEZ BM0m+67FQME8se1gdW3KDCp8KfxTTjTivOWJWHWTzXJszNpogtNS5zSOyxt5UlTO/0YJ f/8A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=1+v3DraxAk+R/FdDJjf7vMV9ncMFhD0gTbJShGvK9m4=; b=HOtekFv4MGbzZmSBm34YOQPfcwzdUbUwar+4JMxEiLOXaAEb6PCR6sFNq9Oq0YWLwD iKwTYawWkGY9P1Kfd57ovsCEkzFmz5UH7LeaWWZAlfDwsfNDmZ1ZQgAXGwaQRKDKlmtn a9Idwmo516pl+XhTOK0Ww5IJLgOcg1CdLNb58qMe3/InFhT8oTzDuDwBtyEXRbxrVtvZ OtIbhObZLP3eWucvCb3rlfsv7s9LY5UKxqaUL4RcjW9EDOzbsW87zNBdrFZ5sk1Sovsf 1p7O5fhc99w0l6oKRQca3Q9TbUUAqyHu1VdPdsM/r+qKNRXFrXCmTYfAQ18f0Kf2Q5Zx BI8w== X-Gm-Message-State: AOAM530dyCv8kXJnQ+2Z1VrKoYDPGm6qHYGlyGMboluAQ6ixG6Ikrtfv vOeQOYv4B9kHgE8cgYwL+6ea5IXJZxmgrw== X-Google-Smtp-Source: ABdhPJyXkhwxlNbJDIYBThbEkEURzN3jWGrWq+S42Ptz/iowLyobP0osMh4Cn+T4JijUPBo2QKI7Vw== X-Received: by 2002:a2e:91da:: with SMTP id u26mr26556037ljg.311.1594169654713; Tue, 07 Jul 2020 17:54:14 -0700 (PDT) Received: from localhost.localdomain (broadband-37-110-65-23.ip.moscow.rt.ru. [37.110.65.23]) by smtp.gmail.com with ESMTPSA id h22sm515986ljg.1.2020.07.07.17.54.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 07 Jul 2020 17:54:14 -0700 (PDT) From: Dmitry Kozlyuk To: dev@dpdk.org Cc: Neil Horman , Bruce Richardson , Thomas Monjalon , robin.jarry@6wind.com, Jie Zhou , Tal Shnaiderman , Dmitry Kozlyuk , John McNamara , Marko Kovacevic Date: Wed, 8 Jul 2020 03:53:54 +0300 Message-Id: <20200708005355.7102-4-dmitry.kozliuk@gmail.com> X-Mailer: git-send-email 2.25.4 In-Reply-To: <20200708005355.7102-1-dmitry.kozliuk@gmail.com> References: <20200702000232.10761-1-dmitry.kozliuk@gmail.com> <20200708005355.7102-1-dmitry.kozliuk@gmail.com> MIME-Version: 1.0 Subject: [dpdk-dev] [PATCH v3 3/4] doc/linux_gsg: require pyelftools for pmdinfogen X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Sender: "dev" The package is available on all major distributions. FreeBSD has no system requirements section in its GSG, Windows currently neither uses pmdinfogen not is supported by it. Signed-off-by: Dmitry Kozlyuk --- doc/guides/linux_gsg/sys_reqs.rst | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/doc/guides/linux_gsg/sys_reqs.rst b/doc/guides/linux_gsg/sys_reqs.rst index a124656bc..ef2037ca7 100644 --- a/doc/guides/linux_gsg/sys_reqs.rst +++ b/doc/guides/linux_gsg/sys_reqs.rst @@ -56,6 +56,12 @@ Compilation of the DPDK * If the packaged version is below the minimum version, the latest versions can be installed from Python's "pip" repository: ``pip3 install meson ninja`` +* ``pyelftools`` (version 0.22+) + + * For RHEL/Fedora systems it can be installed using ``dnf install python-pyelftools`` + + * For Ubuntu/Debian it can be installed using ``apt install python3-pyelftools`` + * Library for handling NUMA (Non Uniform Memory Access). * ``numactl-devel`` in RHEL/Fedora; From patchwork Wed Jul 8 00:53:55 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dmitry Kozlyuk X-Patchwork-Id: 73484 X-Patchwork-Delegate: thomas@monjalon.net Return-Path: X-Original-To: patchwork@inbox.dpdk.org Delivered-To: patchwork@inbox.dpdk.org Received: from dpdk.org (dpdk.org [92.243.14.124]) by inbox.dpdk.org (Postfix) with ESMTP id 83978A00BE; Wed, 8 Jul 2020 02:54:44 +0200 (CEST) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id BA36B1DDE3; Wed, 8 Jul 2020 02:54:27 +0200 (CEST) Received: from mail-lj1-f193.google.com (mail-lj1-f193.google.com [209.85.208.193]) by dpdk.org (Postfix) with ESMTP id 046EA1DD24 for ; Wed, 8 Jul 2020 02:54:17 +0200 (CEST) Received: by mail-lj1-f193.google.com with SMTP id h19so52226762ljg.13 for ; Tue, 07 Jul 2020 17:54:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=a4bhgi4G12aEsQhMIrMv6klfYT8qyYi+7mB7mOXfy64=; b=CFGEliVVZKAi/1y66X0gOghHI96HNsxsjcXHrVarkf/CyTiMRQ3oBPnCKqSd4Ffe7V E2ZG2xpFjdXAd4CXA996XYLsTFCwEQ1OoXKvm7mv4b1yOWhKXJFPCbEe15SmS/NAVBlh ledgDG27MJRNYIO4xA3atDM9ZCRVXx3gM1SBEwybWfae+CEC7UPk7xY9yw/L0fY2ZhGM +7CDyD2oqvtXo9VCaFmp3HwBgzyXCvcTCY55aJV5Ewl3geRfEP69XITe3zQdaZwS0D33 wp/FzjdYkjkcMOs7Yi0UoT/vcI6DQDcxDWf83EYRPPpqhiRGpTyUZbm0CwDlw3KSKewp ZDWw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=a4bhgi4G12aEsQhMIrMv6klfYT8qyYi+7mB7mOXfy64=; b=uWGFlbnTvP2TwPojYbZzD5CAPoAm4H7SZukMxgV11LgLQQOjtzA6HrNik9oA/cYhkx w3BrSIDui7VE/mT5lgNMbvoij6SgpPThHPtVJwZzA1sYRlAeKVDininblUrcraaNzf5N fiXzWkW9WO2NeDLU0PB926f8MMh5c2WsWRThQgypVjUQE3eym1BPiWs01ySgxhwCdBNS 5sM5AalScAH48FXWhGN4HtnrYnf42DscEdwpHlBB8oFtI2sUz1ufYJeIzHBkbxGm4NnO SpEhwtz5UU4pqVRxjgedFVT3J4VMRqonC9BGJ/oZiNPEMKxhl4GOiPIAwSvzPgwjvLI6 uMuQ== X-Gm-Message-State: AOAM533tOpPAK6eQAyJXWI3qb5/V/Y997cxV33zsfk97RBPm7AzoSYg6 AhOuKGS3p183DbwVA89A4q4CtBNaDimQ0Q== X-Google-Smtp-Source: ABdhPJweKvD3zV1r0ByhGOOGUVUGKzA6JPJ90aRSEqOQWGtMhiuf3zz3KHgYRDcqM5jZ4VDWmUA//w== X-Received: by 2002:a2e:9a4d:: with SMTP id k13mr10406628ljj.283.1594169655921; Tue, 07 Jul 2020 17:54:15 -0700 (PDT) Received: from localhost.localdomain (broadband-37-110-65-23.ip.moscow.rt.ru. [37.110.65.23]) by smtp.gmail.com with ESMTPSA id h22sm515986ljg.1.2020.07.07.17.54.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 07 Jul 2020 17:54:15 -0700 (PDT) From: Dmitry Kozlyuk To: dev@dpdk.org Cc: Neil Horman , Bruce Richardson , Thomas Monjalon , robin.jarry@6wind.com, Jie Zhou , Tal Shnaiderman , Dmitry Kozlyuk Date: Wed, 8 Jul 2020 03:53:55 +0300 Message-Id: <20200708005355.7102-5-dmitry.kozliuk@gmail.com> X-Mailer: git-send-email 2.25.4 In-Reply-To: <20200708005355.7102-1-dmitry.kozliuk@gmail.com> References: <20200702000232.10761-1-dmitry.kozliuk@gmail.com> <20200708005355.7102-1-dmitry.kozliuk@gmail.com> MIME-Version: 1.0 Subject: [dpdk-dev] [PATCH v3 4/4] pmdinfogen: remove C implementation X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Sender: "dev" Delete the files no longer used in build process. Keep Neil Horman maintainer of the entire "Driver information" section, only adjust paths. Signed-off-by: Dmitry Kozlyuk --- MAINTAINERS | 2 +- buildtools/pmdinfogen/Makefile | 20 -- buildtools/pmdinfogen/meson.build | 14 - buildtools/pmdinfogen/pmdinfogen.c | 456 ----------------------------- buildtools/pmdinfogen/pmdinfogen.h | 119 -------- 5 files changed, 1 insertion(+), 610 deletions(-) delete mode 100644 buildtools/pmdinfogen/Makefile delete mode 100644 buildtools/pmdinfogen/meson.build delete mode 100644 buildtools/pmdinfogen/pmdinfogen.c delete mode 100644 buildtools/pmdinfogen/pmdinfogen.h diff --git a/MAINTAINERS b/MAINTAINERS index 6ba02d73a..93d209101 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -157,7 +157,7 @@ F: lib/*/*.map Driver information M: Neil Horman -F: buildtools/pmdinfogen/ +F: buildtools/pmdinfogen.py F: usertools/dpdk-pmdinfo.py F: doc/guides/tools/pmdinfo.rst diff --git a/buildtools/pmdinfogen/Makefile b/buildtools/pmdinfogen/Makefile deleted file mode 100644 index a97a7648f..000000000 --- a/buildtools/pmdinfogen/Makefile +++ /dev/null @@ -1,20 +0,0 @@ -# SPDX-License-Identifier: BSD-3-Clause -# Copyright(c) 2016 Neil Horman -# All rights reserved. - -include $(RTE_SDK)/mk/rte.vars.mk - -# -# library name -# -HOSTAPP = dpdk-pmdinfogen - -# -# all sources are stored in SRCS-y -# -SRCS-y += pmdinfogen.c - -HOST_CFLAGS += $(HOST_WERROR_FLAGS) -g -HOST_CFLAGS += -I$(RTE_OUTPUT)/include - -include $(RTE_SDK)/mk/rte.hostapp.mk diff --git a/buildtools/pmdinfogen/meson.build b/buildtools/pmdinfogen/meson.build deleted file mode 100644 index 670528fac..000000000 --- a/buildtools/pmdinfogen/meson.build +++ /dev/null @@ -1,14 +0,0 @@ -# SPDX-License-Identifier: BSD-3-Clause -# Copyright(c) 2017 Intel Corporation - -if is_windows - subdir_done() -endif - -pmdinfogen_inc = [global_inc] -pmdinfogen_inc += include_directories('../../lib/librte_eal/include') -pmdinfogen_inc += include_directories('../../lib/librte_pci') -pmdinfogen = executable('pmdinfogen', - 'pmdinfogen.c', - include_directories: pmdinfogen_inc, - native: true) diff --git a/buildtools/pmdinfogen/pmdinfogen.c b/buildtools/pmdinfogen/pmdinfogen.c deleted file mode 100644 index a68d1ea99..000000000 --- a/buildtools/pmdinfogen/pmdinfogen.c +++ /dev/null @@ -1,456 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0 - * Postprocess pmd object files to export hw support - * - * Copyright 2016 Neil Horman - * Based in part on modpost.c from the linux kernel - */ - -#include -#include -#include -#include -#include -#include -#include - -#include -#include "pmdinfogen.h" - -#ifdef RTE_ARCH_64 -#define ADDR_SIZE 64 -#else -#define ADDR_SIZE 32 -#endif - -static int use_stdin, use_stdout; - -static const char *sym_name(struct elf_info *elf, Elf_Sym *sym) -{ - if (sym) - return elf->strtab + sym->st_name; - else - return "(unknown)"; -} - -static void *grab_file(const char *filename, unsigned long *size) -{ - struct stat st; - void *map = MAP_FAILED; - int fd = -1; - - if (!use_stdin) { - fd = open(filename, O_RDONLY); - if (fd < 0) - return NULL; - } else { - /* from stdin, use a temporary file to mmap */ - FILE *infile; - char buffer[1024]; - int n; - - infile = tmpfile(); - if (infile == NULL) { - perror("tmpfile"); - return NULL; - } - fd = dup(fileno(infile)); - fclose(infile); - if (fd < 0) - return NULL; - - n = read(STDIN_FILENO, buffer, sizeof(buffer)); - while (n > 0) { - if (write(fd, buffer, n) != n) - goto failed; - n = read(STDIN_FILENO, buffer, sizeof(buffer)); - } - } - - if (fstat(fd, &st)) - goto failed; - - *size = st.st_size; - map = mmap(NULL, *size, PROT_READ|PROT_WRITE, MAP_PRIVATE, fd, 0); - -failed: - close(fd); - if (map == MAP_FAILED) - return NULL; - return map; -} - -/** - * Return a copy of the next line in a mmap'ed file. - * spaces in the beginning of the line is trimmed away. - * Return a pointer to a static buffer. - **/ -static void release_file(void *file, unsigned long size) -{ - munmap(file, size); -} - - -static void *get_sym_value(struct elf_info *info, const Elf_Sym *sym) -{ - return RTE_PTR_ADD(info->hdr, - info->sechdrs[sym->st_shndx].sh_offset + sym->st_value); -} - -static Elf_Sym *find_sym_in_symtab(struct elf_info *info, - const char *name, Elf_Sym *last) -{ - Elf_Sym *idx; - if (last) - idx = last+1; - else - idx = info->symtab_start; - - for (; idx < info->symtab_stop; idx++) { - const char *n = sym_name(info, idx); - if (!strncmp(n, name, strlen(name))) - return idx; - } - return NULL; -} - -static int parse_elf(struct elf_info *info, const char *filename) -{ - unsigned int i; - Elf_Ehdr *hdr; - Elf_Shdr *sechdrs; - Elf_Sym *sym; - int endian; - unsigned int symtab_idx = ~0U, symtab_shndx_idx = ~0U; - - hdr = grab_file(filename, &info->size); - if (!hdr) { - perror(filename); - exit(1); - } - info->hdr = hdr; - if (info->size < sizeof(*hdr)) { - /* file too small, assume this is an empty .o file */ - return 0; - } - /* Is this a valid ELF file? */ - if ((hdr->e_ident[EI_MAG0] != ELFMAG0) || - (hdr->e_ident[EI_MAG1] != ELFMAG1) || - (hdr->e_ident[EI_MAG2] != ELFMAG2) || - (hdr->e_ident[EI_MAG3] != ELFMAG3)) { - /* Not an ELF file - silently ignore it */ - return 0; - } - - if (!hdr->e_ident[EI_DATA]) { - /* Unknown endian */ - return 0; - } - - endian = hdr->e_ident[EI_DATA]; - - /* Fix endianness in ELF header */ - hdr->e_type = TO_NATIVE(endian, 16, hdr->e_type); - hdr->e_machine = TO_NATIVE(endian, 16, hdr->e_machine); - hdr->e_version = TO_NATIVE(endian, 32, hdr->e_version); - hdr->e_entry = TO_NATIVE(endian, ADDR_SIZE, hdr->e_entry); - hdr->e_phoff = TO_NATIVE(endian, ADDR_SIZE, hdr->e_phoff); - hdr->e_shoff = TO_NATIVE(endian, ADDR_SIZE, hdr->e_shoff); - hdr->e_flags = TO_NATIVE(endian, 32, hdr->e_flags); - hdr->e_ehsize = TO_NATIVE(endian, 16, hdr->e_ehsize); - hdr->e_phentsize = TO_NATIVE(endian, 16, hdr->e_phentsize); - hdr->e_phnum = TO_NATIVE(endian, 16, hdr->e_phnum); - hdr->e_shentsize = TO_NATIVE(endian, 16, hdr->e_shentsize); - hdr->e_shnum = TO_NATIVE(endian, 16, hdr->e_shnum); - hdr->e_shstrndx = TO_NATIVE(endian, 16, hdr->e_shstrndx); - - sechdrs = RTE_PTR_ADD(hdr, hdr->e_shoff); - info->sechdrs = sechdrs; - - /* Check if file offset is correct */ - if (hdr->e_shoff > info->size) { - fprintf(stderr, "section header offset=%lu in file '%s' " - "is bigger than filesize=%lu\n", - (unsigned long)hdr->e_shoff, - filename, info->size); - return 0; - } - - if (hdr->e_shnum == SHN_UNDEF) { - /* - * There are more than 64k sections, - * read count from .sh_size. - */ - info->num_sections = - TO_NATIVE(endian, ADDR_SIZE, sechdrs[0].sh_size); - } else { - info->num_sections = hdr->e_shnum; - } - if (hdr->e_shstrndx == SHN_XINDEX) - info->secindex_strings = - TO_NATIVE(endian, 32, sechdrs[0].sh_link); - else - info->secindex_strings = hdr->e_shstrndx; - - /* Fix endianness in section headers */ - for (i = 0; i < info->num_sections; i++) { - sechdrs[i].sh_name = - TO_NATIVE(endian, 32, sechdrs[i].sh_name); - sechdrs[i].sh_type = - TO_NATIVE(endian, 32, sechdrs[i].sh_type); - sechdrs[i].sh_flags = - TO_NATIVE(endian, 32, sechdrs[i].sh_flags); - sechdrs[i].sh_addr = - TO_NATIVE(endian, ADDR_SIZE, sechdrs[i].sh_addr); - sechdrs[i].sh_offset = - TO_NATIVE(endian, ADDR_SIZE, sechdrs[i].sh_offset); - sechdrs[i].sh_size = - TO_NATIVE(endian, ADDR_SIZE, sechdrs[i].sh_size); - sechdrs[i].sh_link = - TO_NATIVE(endian, 32, sechdrs[i].sh_link); - sechdrs[i].sh_info = - TO_NATIVE(endian, 32, sechdrs[i].sh_info); - sechdrs[i].sh_addralign = - TO_NATIVE(endian, ADDR_SIZE, sechdrs[i].sh_addralign); - sechdrs[i].sh_entsize = - TO_NATIVE(endian, ADDR_SIZE, sechdrs[i].sh_entsize); - } - /* Find symbol table. */ - for (i = 1; i < info->num_sections; i++) { - int nobits = sechdrs[i].sh_type == SHT_NOBITS; - - if (!nobits && sechdrs[i].sh_offset > info->size) { - fprintf(stderr, "%s is truncated. " - "sechdrs[i].sh_offset=%lu > sizeof(*hrd)=%zu\n", - filename, (unsigned long)sechdrs[i].sh_offset, - sizeof(*hdr)); - return 0; - } - - if (sechdrs[i].sh_type == SHT_SYMTAB) { - unsigned int sh_link_idx; - symtab_idx = i; - info->symtab_start = RTE_PTR_ADD(hdr, - sechdrs[i].sh_offset); - info->symtab_stop = RTE_PTR_ADD(hdr, - sechdrs[i].sh_offset + sechdrs[i].sh_size); - sh_link_idx = sechdrs[i].sh_link; - info->strtab = RTE_PTR_ADD(hdr, - sechdrs[sh_link_idx].sh_offset); - } - - /* 32bit section no. table? ("more than 64k sections") */ - if (sechdrs[i].sh_type == SHT_SYMTAB_SHNDX) { - symtab_shndx_idx = i; - info->symtab_shndx_start = RTE_PTR_ADD(hdr, - sechdrs[i].sh_offset); - info->symtab_shndx_stop = RTE_PTR_ADD(hdr, - sechdrs[i].sh_offset + sechdrs[i].sh_size); - } - } - if (!info->symtab_start) - fprintf(stderr, "%s has no symtab?\n", filename); - else { - /* Fix endianness in symbols */ - for (sym = info->symtab_start; sym < info->symtab_stop; sym++) { - sym->st_shndx = TO_NATIVE(endian, 16, sym->st_shndx); - sym->st_name = TO_NATIVE(endian, 32, sym->st_name); - sym->st_value = TO_NATIVE(endian, ADDR_SIZE, sym->st_value); - sym->st_size = TO_NATIVE(endian, ADDR_SIZE, sym->st_size); - } - } - - if (symtab_shndx_idx != ~0U) { - Elf32_Word *p; - if (symtab_idx != sechdrs[symtab_shndx_idx].sh_link) - fprintf(stderr, - "%s: SYMTAB_SHNDX has bad sh_link: %u!=%u\n", - filename, sechdrs[symtab_shndx_idx].sh_link, - symtab_idx); - /* Fix endianness */ - for (p = info->symtab_shndx_start; p < info->symtab_shndx_stop; - p++) - *p = TO_NATIVE(endian, 32, *p); - } - - return 1; -} - -static void parse_elf_finish(struct elf_info *info) -{ - struct pmd_driver *tmp, *idx = info->drivers; - release_file(info->hdr, info->size); - while (idx) { - tmp = idx->next; - free(idx); - idx = tmp; - } -} - -struct opt_tag { - const char *suffix; - const char *json_id; -}; - -static const struct opt_tag opt_tags[] = { - {"_param_string_export", "params"}, - {"_kmod_dep_export", "kmod"}, -}; - -static int complete_pmd_entry(struct elf_info *info, struct pmd_driver *drv) -{ - const char *tname; - int i; - char tmpsymname[128]; - Elf_Sym *tmpsym; - - drv->name = get_sym_value(info, drv->name_sym); - - for (i = 0; i < PMD_OPT_MAX; i++) { - memset(tmpsymname, 0, 128); - sprintf(tmpsymname, "__%s%s", drv->name, opt_tags[i].suffix); - tmpsym = find_sym_in_symtab(info, tmpsymname, NULL); - if (!tmpsym) - continue; - drv->opt_vals[i] = get_sym_value(info, tmpsym); - } - - memset(tmpsymname, 0, 128); - sprintf(tmpsymname, "__%s_pci_tbl_export", drv->name); - - tmpsym = find_sym_in_symtab(info, tmpsymname, NULL); - - - /* - * If this returns NULL, then this is a PMD_VDEV, because - * it has no pci table reference - */ - if (!tmpsym) { - drv->pci_tbl = NULL; - return 0; - } - - tname = get_sym_value(info, tmpsym); - tmpsym = find_sym_in_symtab(info, tname, NULL); - if (!tmpsym) - return -ENOENT; - - drv->pci_tbl = (struct rte_pci_id *)get_sym_value(info, tmpsym); - if (!drv->pci_tbl) - return -ENOENT; - - return 0; -} - -static int locate_pmd_entries(struct elf_info *info) -{ - Elf_Sym *last = NULL; - struct pmd_driver *new; - - info->drivers = NULL; - - do { - new = calloc(sizeof(struct pmd_driver), 1); - if (new == NULL) { - fprintf(stderr, "Failed to calloc memory\n"); - return -1; - } - new->name_sym = find_sym_in_symtab(info, "this_pmd_name", last); - last = new->name_sym; - if (!new->name_sym) - free(new); - else { - if (complete_pmd_entry(info, new)) { - fprintf(stderr, - "Failed to complete pmd entry\n"); - free(new); - } else { - new->next = info->drivers; - info->drivers = new; - } - } - } while (last); - - return 0; -} - -static void output_pmd_info_string(struct elf_info *info, char *outfile) -{ - FILE *ofd; - struct pmd_driver *drv; - struct rte_pci_id *pci_ids; - int idx = 0; - - if (use_stdout) - ofd = stdout; - else { - ofd = fopen(outfile, "w+"); - if (!ofd) { - fprintf(stderr, "Unable to open output file\n"); - return; - } - } - - drv = info->drivers; - - while (drv) { - fprintf(ofd, "const char %s_pmd_info[] __attribute__((used)) = " - "\"PMD_INFO_STRING= {", - drv->name); - fprintf(ofd, "\\\"name\\\" : \\\"%s\\\", ", drv->name); - - for (idx = 0; idx < PMD_OPT_MAX; idx++) { - if (drv->opt_vals[idx]) - fprintf(ofd, "\\\"%s\\\" : \\\"%s\\\", ", - opt_tags[idx].json_id, - drv->opt_vals[idx]); - } - - pci_ids = drv->pci_tbl; - fprintf(ofd, "\\\"pci_ids\\\" : ["); - - while (pci_ids && pci_ids->device_id) { - fprintf(ofd, "[%d, %d, %d, %d]", - pci_ids->vendor_id, pci_ids->device_id, - pci_ids->subsystem_vendor_id, - pci_ids->subsystem_device_id); - pci_ids++; - if (pci_ids->device_id) - fprintf(ofd, ","); - else - fprintf(ofd, " "); - } - fprintf(ofd, "]}\";\n"); - drv = drv->next; - } - - fclose(ofd); -} - -int main(int argc, char **argv) -{ - struct elf_info info = {0}; - int rc = 1; - - if (argc < 3) { - fprintf(stderr, - "usage: %s \n", - basename(argv[0])); - exit(127); - } - use_stdin = !strcmp(argv[1], "-"); - use_stdout = !strcmp(argv[2], "-"); - parse_elf(&info, argv[1]); - - if (locate_pmd_entries(&info) < 0) - exit(1); - - if (info.drivers) { - output_pmd_info_string(&info, argv[2]); - rc = 0; - } else { - fprintf(stderr, "No drivers registered\n"); - } - - parse_elf_finish(&info); - exit(rc); -} diff --git a/buildtools/pmdinfogen/pmdinfogen.h b/buildtools/pmdinfogen/pmdinfogen.h deleted file mode 100644 index 93930e454..000000000 --- a/buildtools/pmdinfogen/pmdinfogen.h +++ /dev/null @@ -1,119 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0 - * Postprocess pmd object files to export hw support - * - * Copyright 2016 Neil Horman - * Based in part on modpost.c from the linux kernel - */ - -#include -#include -#include -#include -#include -#include -#include -#ifdef __linux__ -#include -#else -#include -#endif -#include -#include -#include -#include - -/* 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 = le##width##toh(x); \ -else \ - ___x = be##width##toh(x); \ - ___x; \ -}) - -#define TO_NATIVE(fend, width, x) CONVERT_NATIVE(fend, width, x) - -enum opt_params { - PMD_PARAM_STRING = 0, - PMD_KMOD_DEP, - 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; -};