Show a patch.

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

{
    "id": 73550,
    "url": "https://patches.dpdk.org/api/patches/73550/",
    "web_url": "https://patches.dpdk.org/patch/73550/",
    "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": "<20200708212335.25338-2-dmitry.kozliuk@gmail.com>",
    "date": "2020-07-08T21:23:32",
    "name": "[v4,1/4] pmdinfogen: add Python implementation",
    "commit_ref": null,
    "pull_url": null,
    "state": "superseded",
    "archived": false,
    "hash": "f4548161e957d66a5040347b5e46e32217a067cd",
    "submitter": {
        "id": 1581,
        "url": "https://patches.dpdk.org/api/people/1581/",
        "name": "Dmitry Kozlyuk",
        "email": "dmitry.kozliuk@gmail.com"
    },
    "delegate": {
        "id": 24651,
        "url": "https://patches.dpdk.org/api/users/24651/",
        "username": "dmarchand",
        "first_name": "David",
        "last_name": "Marchand",
        "email": "david.marchand@redhat.com"
    },
    "mbox": "https://patches.dpdk.org/patch/73550/mbox/",
    "series": [
        {
            "id": 10898,
            "url": "https://patches.dpdk.org/api/series/10898/",
            "web_url": "https://patches.dpdk.org/project/dpdk/list/?series=10898",
            "date": "2020-07-08T21:23:31",
            "name": "pmdinfogen: rewrite in Python",
            "version": 4,
            "mbox": "https://patches.dpdk.org/series/10898/mbox/"
        }
    ],
    "comments": "https://patches.dpdk.org/api/patches/73550/comments/",
    "check": "fail",
    "checks": "https://patches.dpdk.org/api/patches/73550/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 ABdhPJwHuTvaPI5VXGAwNbup+GjTFK0zEA8TKD9YyjzK/dUpkghRev8fXjr5W2BOv6704d9192uHlw==",
        "Message-Id": "<20200708212335.25338-2-dmitry.kozliuk@gmail.com>",
        "X-Mailer": "git-send-email 2.25.4",
        "X-Gm-Message-State": "AOAM530hos4YT/HOrXUsQPYd3MVRD+wIn2YB2IhMSR+IdSCsutJ/PMon\n S0p9F5Kb7Nna+knWZWulsmpY0opIfMGDTA==",
        "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=3bllpsdI4Jnd2wPech0s6a7AdDU3EzwRkyW9b5R736I=;\n b=ULEh5/837daANp1mWXeq+2i3LSqIWfxarxfDJLast9xAXyGEahARPfrAgklfiK+NLK\n Rp6OTnHORp3X5bdNMwTOEiYbWh6LrhKrPl1dlDm1xIR+fxEpWFchG0mGLHzRLDB7QEnS\n CP2t42ruHsGfQSlA+rtt8d3vzSNYUqdsHcqaXtsuF7f5v189QBNTKtksx5DWI7ecGh6L\n nfvH2KHcwVHVQy6ebzHEFuoAr093X8+ji7ybD6Ha1OSVwcsKYlYcKffSciKZcS4k7v+7\n O3Vq9ORKo8MwKOZzdpzY809AmlTYbrdn+feBtxHN/0aNRHnzJ9/YCeGW1Dqco+nTnGrA\n Ovig==",
        "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 164E0A0526;\n\tWed,  8 Jul 2020 23:23:55 +0200 (CEST)",
            "from [92.243.14.124] (localhost [127.0.0.1])\n\tby dpdk.org (Postfix) with ESMTP id C29D21DED4;\n\tWed,  8 Jul 2020 23:23:51 +0200 (CEST)",
            "from mail-lf1-f53.google.com (mail-lf1-f53.google.com\n [209.85.167.53]) by dpdk.org (Postfix) with ESMTP id 2CEB91DD79\n for <dev@dpdk.org>; Wed,  8 Jul 2020 23:23:48 +0200 (CEST)",
            "by mail-lf1-f53.google.com with SMTP id g2so27717134lfb.0\n for <dev@dpdk.org>; Wed, 08 Jul 2020 14:23:48 -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 u9sm230590ljk.44.2020.07.08.14.23.45\n (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);\n Wed, 08 Jul 2020 14:23:46 -0700 (PDT)"
        ],
        "Subject": "[dpdk-dev] [PATCH v4 1/4] pmdinfogen: add Python implementation",
        "In-Reply-To": "<20200708212335.25338-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:a19:ccc5:: with SMTP id\n c188mr37880691lfg.163.1594243427177;\n Wed, 08 Jul 2020 14:23:47 -0700 (PDT)",
        "Content-Transfer-Encoding": "8bit",
        "MIME-Version": "1.0",
        "References": "<20200708005355.7102-1-dmitry.kozliuk@gmail.com>\n <20200708212335.25338-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": "Thu,  9 Jul 2020 00:23:32 +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=3bllpsdI4Jnd2wPech0s6a7AdDU3EzwRkyW9b5R736I=;\n b=of85t0LxFxpRoie6ByFYYntHdPrVWKck0KUiD7KzjOXI8QUQskldpnGcnueuKbA5MU\n +zEq/F79xXVnv2igSFvxvAYvG9fdLL5zLrlGfyACk/XXFFURLsedKslnSwb+BjtK7RJ/\n JK3wpDSDUxgAdlQq15OwAtSMtWEuNfzc6GHmqHXx3hthM+metVncSI88utHFJYhGJZLw\n f3Vq+MkLL8OyuMQLRjGsZKKu3kzOztJs+Ug0HeYZEIgeL2bmB0eZTtekMKG1CRTyDXKg\n S/aeUF4raq82wZKGR69jeaa6luYfYphV8IhUVvfuqrHAJdBAkBHzSTANd+hHlA1w80sU\n uPag=="
    },
    "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 | 188 +++++++++++++++++++++++++++++++++++++++\n 1 file changed, 188 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..a9c2643a4\n--- /dev/null\n+++ b/buildtools/pmdinfogen.py\n@@ -0,0 +1,188 @@\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+        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": [
        "v4",
        "1/4"
    ]
}