Show a patch.

GET /api/patches/73481/
HTTP 200 OK
Allow: GET, PUT, PATCH, HEAD, OPTIONS
Content-Type: application/json
Vary: Accept

{
    "id": 73481,
    "url": "https://patches.dpdk.org/api/patches/73481/",
    "web_url": "https://patches.dpdk.org/patch/73481/",
    "project": {
        "id": 1,
        "url": "https://patches.dpdk.org/api/projects/1/",
        "name": "DPDK",
        "link_name": "dpdk",
        "list_id": "dev.dpdk.org",
        "list_email": "dev@dpdk.org",
        "web_url": "http://core.dpdk.org",
        "scm_url": "git://dpdk.org/dpdk",
        "webscm_url": "http://git.dpdk.org/dpdk"
    },
    "msgid": "<20200708005355.7102-2-dmitry.kozliuk@gmail.com>",
    "date": "2020-07-08T00:53:52",
    "name": "[v3,1/4] pmdinfogen: add Python implementation",
    "commit_ref": null,
    "pull_url": null,
    "state": "superseded",
    "archived": true,
    "hash": "e23e6995cd96506337e2405abf43960d3b66badb",
    "submitter": {
        "id": 1581,
        "url": "https://patches.dpdk.org/api/people/1581/",
        "name": "Dmitry Kozlyuk",
        "email": "dmitry.kozliuk@gmail.com"
    },
    "delegate": {
        "id": 1,
        "url": "https://patches.dpdk.org/api/users/1/",
        "username": "tmonjalo",
        "first_name": "Thomas",
        "last_name": "Monjalon",
        "email": "thomas@monjalon.net"
    },
    "mbox": "https://patches.dpdk.org/patch/73481/mbox/",
    "series": [
        {
            "id": 10868,
            "url": "https://patches.dpdk.org/api/series/10868/",
            "web_url": "https://patches.dpdk.org/project/dpdk/list/?series=10868",
            "date": "2020-07-08T00:53:51",
            "name": "pmdinfogen: rewrite in Python",
            "version": 3,
            "mbox": "https://patches.dpdk.org/series/10868/mbox/"
        }
    ],
    "comments": "https://patches.dpdk.org/api/patches/73481/comments/",
    "check": "fail",
    "checks": "https://patches.dpdk.org/api/patches/73481/checks/",
    "tags": {},
    "headers": {
        "List-Archive": "<http://mails.dpdk.org/archives/dev/>",
        "Return-Path": "<dev-bounces@dpdk.org>",
        "To": "dev@dpdk.org",
        "X-Google-Smtp-Source": "\n ABdhPJwRuuGPQxMWYdyZ9Z443WJN+hOLCPVm6JTU1IoeG1qLRsi42gfwAyaxkpjRmVA/WDgk3ldLqQ==",
        "Message-Id": "<20200708005355.7102-2-dmitry.kozliuk@gmail.com>",
        "X-Mailer": "git-send-email 2.25.4",
        "X-Gm-Message-State": "AOAM532CeQV8Hu3bJctj6flnsDpYPv3o9OASJCKU3XKmmm6B87Cs3KBI\n wapoQKOhkIsuQYcuI00ep9an8AGhNGvPVQ==",
        "DKIM-Signature": "v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025;\n h=from:to:cc:subject:date:message-id:in-reply-to:references\n :mime-version:content-transfer-encoding;\n bh=vv/p3hiG61PjzDvtM8llR7UP/N4ZMnzJB1B1s57Uapg=;\n b=YTNLhpdcUgfICD1d4IIQ6jlawUWmP743Nn8IH5Wbboq6iPcPIHlbVmT+TG1IUbo/9B\n C7P/kCu8Z9kTT6YevLwUkhhDT4/UyC3O0ww1gA/OupA9/1WzUa6kxkgflXi1XMEMkHya\n bhuhQhW1/eDSYLZDr4+98TgYD05C5DzbuPmdtSnNoa6Gow46r3Id53ogApJt5teSUuQD\n 6/nQnpT4vb54TjUKY+3glxfjgp5TcPQyIE5Tt+fVYbEpJ+NWuUxepSc7guWXuKpPpXSR\n m1MdcyPYludn5W3FuHIKt6G8VuwP2nSVcanXU+t8QRy+T/9sJKzqSmsKQ93Y8JjAzfWq\n B+OA==",
        "List-Subscribe": "<https://mails.dpdk.org/listinfo/dev>,\n <mailto:dev-request@dpdk.org?subject=subscribe>",
        "X-BeenThere": "dev@dpdk.org",
        "Received": [
            "from dpdk.org (dpdk.org [92.243.14.124])\n\tby inbox.dpdk.org (Postfix) with ESMTP id 73C7AA00BE;\n\tWed,  8 Jul 2020 02:54:20 +0200 (CEST)",
            "from [92.243.14.124] (localhost [127.0.0.1])\n\tby dpdk.org (Postfix) with ESMTP id EF24B1DD31;\n\tWed,  8 Jul 2020 02:54:17 +0200 (CEST)",
            "from mail-lf1-f49.google.com (mail-lf1-f49.google.com\n [209.85.167.49]) by dpdk.org (Postfix) with ESMTP id 09BAA1DCFE\n for <dev@dpdk.org>; Wed,  8 Jul 2020 02:54:13 +0200 (CEST)",
            "by mail-lf1-f49.google.com with SMTP id o4so25900844lfi.7\n for <dev@dpdk.org>; Tue, 07 Jul 2020 17:54:12 -0700 (PDT)",
            "from localhost.localdomain (broadband-37-110-65-23.ip.moscow.rt.ru.\n [37.110.65.23])\n by smtp.gmail.com with ESMTPSA id h22sm515986ljg.1.2020.07.07.17.54.10\n (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);\n Tue, 07 Jul 2020 17:54:11 -0700 (PDT)"
        ],
        "Subject": "[dpdk-dev] [PATCH v3 1/4] pmdinfogen: add Python implementation",
        "In-Reply-To": "<20200708005355.7102-1-dmitry.kozliuk@gmail.com>",
        "List-Id": "DPDK patches and discussions <dev.dpdk.org>",
        "List-Unsubscribe": "<https://mails.dpdk.org/options/dev>,\n <mailto:dev-request@dpdk.org?subject=unsubscribe>",
        "List-Post": "<mailto:dev@dpdk.org>",
        "Cc": "Neil Horman <nhorman@tuxdriver.com>,\n Bruce Richardson <bruce.richardson@intel.com>,\n Thomas Monjalon <thomas@monjalon.net>, robin.jarry@6wind.com,\n Jie Zhou <jizh@microsoft.com>, Tal Shnaiderman <talshn@mellanox.com>,\n Dmitry Kozlyuk <dmitry.kozliuk@gmail.com>",
        "Precedence": "list",
        "From": "Dmitry Kozlyuk <dmitry.kozliuk@gmail.com>",
        "X-Received": "by 2002:ac2:5a5e:: with SMTP id r30mr34881003lfn.30.1594169652171;\n Tue, 07 Jul 2020 17:54:12 -0700 (PDT)",
        "Content-Transfer-Encoding": "8bit",
        "MIME-Version": "1.0",
        "References": "<20200702000232.10761-1-dmitry.kozliuk@gmail.com>\n <20200708005355.7102-1-dmitry.kozliuk@gmail.com>",
        "X-Original-To": "patchwork@inbox.dpdk.org",
        "Sender": "\"dev\" <dev-bounces@dpdk.org>",
        "Errors-To": "dev-bounces@dpdk.org",
        "List-Help": "<mailto:dev-request@dpdk.org?subject=help>",
        "Delivered-To": "patchwork@inbox.dpdk.org",
        "Date": "Wed,  8 Jul 2020 03:53:52 +0300",
        "X-Mailman-Version": "2.1.15",
        "X-Google-DKIM-Signature": "v=1; a=rsa-sha256; c=relaxed/relaxed;\n d=1e100.net; s=20161025;\n h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to\n :references:mime-version:content-transfer-encoding;\n bh=vv/p3hiG61PjzDvtM8llR7UP/N4ZMnzJB1B1s57Uapg=;\n b=esMRg1MgGp/vDjCOoaQWrfy4KaScWCfw+Qcrg+Mfwx45zKQyDPEwtrIP3rGlughJt8\n krMGQPaT2K4FP8rrj7aW/BSQvM4l6f5nPJNpbgPiPDGLF09agsp/MnRgJlcqvgvqEjor\n 0WY6Veucxd4OCo9KhKgE2Fbjfwzk8PRencUqmxjkD1zAJVloFAnK7eidzsE4DC+FuXJ2\n VSpqUx3pSpl/0S3nM7ix163ApXw/Xv/6jsjlZ8wr1X9nb9HWxrEF3c0bmty7x6rDmUbK\n 9hhrf/mPI1OeY6wdbReRzUiYN118ruml1v37jaEaFIaWiE3fms1Nf5YGrQv10iL6tLF2\n Xk1Q=="
    },
    "content": "Using a high-level, interpreted language simplifies maintenance and\nbuild process. Furthermore, ELF handling is delegated to pyelftools\npackage. Original logic is kept, the copyright recognizes that.\n\nSigned-off-by: Dmitry Kozlyuk <dmitry.kozliuk@gmail.com>\n---\n buildtools/pmdinfogen.py | 194 +++++++++++++++++++++++++++++++++++++++\n 1 file changed, 194 insertions(+)\n create mode 100755 buildtools/pmdinfogen.py",
    "diff": "diff --git a/buildtools/pmdinfogen.py b/buildtools/pmdinfogen.py\nnew file mode 100755\nindex 000000000..c32654a4a\n--- /dev/null\n+++ b/buildtools/pmdinfogen.py\n@@ -0,0 +1,194 @@\n+#!/usr/bin/env python3\n+# SPDX-License-Identifier: BSD-3-Clause\n+# Copyright (c) 2016 Neil Horman <nhorman@tuxdriver.com>\n+# Copyright (c) 2020 Dmitry Kozlyuk <dmitry.kozliuk@gmail.com>\n+\n+import argparse\n+import ctypes\n+import json\n+import sys\n+import tempfile\n+\n+from elftools.elf.elffile import ELFFile\n+from elftools.elf.sections import SymbolTableSection\n+\n+\n+class ELFSymbol:\n+    def __init__(self, image, symbol):\n+        self._image = image\n+        self._symbol = symbol\n+\n+    @property\n+    def size(self):\n+        return self._symbol[\"st_size\"]\n+\n+    @property\n+    def value(self):\n+        data = self._image._image.get_section(self._symbol[\"st_shndx\"]).data()\n+        base = self._symbol[\"st_value\"]\n+        return data[base : base + self.size]\n+\n+    @property\n+    def string_value(self):\n+        value = self.value\n+        if len(value):\n+            return value[:-1].decode()\n+        return \"\"\n+\n+\n+class ELFImage:\n+    def __init__(self, data):\n+        self._image = ELFFile(data)\n+        self._symtab = self._image.get_section_by_name(\".symtab\")\n+        if not isinstance(self._symtab, SymbolTableSection):\n+            raise Exception(\".symtab section is not a symbol table\")\n+\n+    @property\n+    def is_big_endian(self):\n+        return not self._image.little_endian\n+\n+    def find_by_name(self, name):\n+        symbol = self._symtab.get_symbol_by_name(name)\n+        if symbol:\n+            return ELFSymbol(self, symbol[0])\n+\n+    def find_by_prefix(self, prefix):\n+        for i in range(self._symtab.num_symbols()):\n+            symbol = self._symtab.get_symbol(i)\n+            if symbol.name.startswith(prefix):\n+                yield ELFSymbol(self, symbol)\n+\n+\n+def define_rte_pci_id(is_big_endian):\n+    base_type = ctypes.LittleEndianStructure\n+    if is_big_endian:\n+        base_type = ctypes.BigEndianStructure\n+\n+    class rte_pci_id(base_type):\n+        _pack_ = True\n+        _fields_ = [\n+            (\"class_id\", ctypes.c_uint32),\n+            (\"vendor_id\", ctypes.c_uint16),\n+            (\"device_id\", ctypes.c_uint16),\n+            (\"subsystem_vendor_id\", ctypes.c_uint16),\n+            (\"subsystem_device_id\", ctypes.c_uint16),\n+        ]\n+\n+    return rte_pci_id\n+\n+\n+class Driver:\n+    OPTIONS = [\n+        (\"params\", \"_param_string_export\"),\n+        (\"kmod\", \"_kmod_dep_export\"),\n+    ]\n+\n+    def __init__(self, name, options):\n+        self.name = name\n+        for key, value in options.items():\n+            setattr(self, key, value)\n+        self.pci_ids = []\n+\n+    @classmethod\n+    def load(cls, image, symbol):\n+        name = symbol.string_value\n+\n+        options = {}\n+        for key, suffix in cls.OPTIONS:\n+            option_symbol = image.find_by_name(\"__%s%s\" % (name, suffix))\n+            if option_symbol:\n+                value = option_symbol.string_value\n+                options[key] = value\n+\n+        driver = cls(name, options)\n+\n+        pci_table_name_symbol = image.find_by_name(\"__%s_pci_tbl_export\" % name)\n+        if pci_table_name_symbol:\n+            driver._load_pci_ids(image, pci_table_name_symbol)\n+\n+        return driver\n+\n+    def _load_pci_ids(self, image, table_name_symbol):\n+        table_name = table_name_symbol.string_value\n+        table_symbol = image.find_by_name(table_name)\n+        if not table_symbol:\n+            raise Exception(\"PCI table declared but not defined: %d\" % table_name)\n+\n+        rte_pci_id = define_rte_pci_id(image.is_big_endian)\n+\n+        pci_id_size = ctypes.sizeof(rte_pci_id)\n+        if table_symbol.size % pci_id_size != 0:\n+            raise Exception(\n+                \"PCI table size (%d) is not a multiple of rte_pci_id size (%d)\"\n+                % (table_symbol.size, pci_id_size)\n+            )\n+\n+        pci_ids_desc = rte_pci_id * (table_symbol.size // pci_id_size)\n+        pci_ids = pci_ids_desc.from_buffer_copy(table_symbol.value)\n+        for pci_id in pci_ids:\n+            if not pci_id.device_id:\n+                break\n+            self.pci_ids.append(\n+                [\n+                    pci_id.vendor_id,\n+                    pci_id.device_id,\n+                    pci_id.subsystem_vendor_id,\n+                    pci_id.subsystem_device_id,\n+                ]\n+            )\n+\n+    def dump(self, file):\n+        dumped = json.dumps(self.__dict__)\n+        escaped = dumped.replace('\"', '\\\\\"')\n+        print(\n+            'const char %s_pmd_info[] __attribute__((used)) = \"PMD_INFO_STRING= %s\";'\n+            % (self.name, escaped),\n+            file=file,\n+        )\n+\n+\n+def load_drivers(image):\n+    drivers = []\n+    for symbol in image.find_by_prefix(\"this_pmd_name\"):\n+        drivers.append(Driver.load(image, symbol))\n+    return drivers\n+\n+\n+def dump_drivers(drivers, file):\n+    # Keep legacy order of definitions.\n+    for driver in reversed(drivers):\n+        driver.dump(file)\n+\n+\n+def parse_args():\n+    parser = argparse.ArgumentParser()\n+    parser.add_argument(\"input\", help=\"input object file path or '-' for stdin\")\n+    parser.add_argument(\"output\", help=\"output C file path or '-' for stdout\")\n+    return parser.parse_args()\n+\n+\n+def open_input(path):\n+    if path == \"-\":\n+        temp = tempfile.TemporaryFile()\n+        temp.write(sys.stdin.buffer.read())\n+        return temp\n+    return open(path, \"rb\")\n+\n+\n+def open_output(path):\n+    if path == \"-\":\n+        return sys.stdout\n+    return open(path, \"w\")\n+\n+\n+def main():\n+    args = parse_args()\n+    infile = open_input(args.input)\n+    image = ELFImage(infile)\n+    drivers = load_drivers(image)\n+    output = open_output(args.output)\n+    dump_drivers(drivers, output)\n+\n+\n+if __name__ == \"__main__\":\n+    main()\n",
    "prefixes": [
        "v3",
        "1/4"
    ]
}