get:
Show a patch.

patch:
Update a patch.

put:
Update a patch.

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

{
    "id": 1197158,
    "url": "http://patchwork.ozlabs.org/api/patches/1197158/?format=api",
    "web_url": "http://patchwork.ozlabs.org/project/intel-wired-lan/patch/2B0E3F215D1AB84DA946C8BEE234CCC97B3014A3@ORSMSX101.amr.corp.intel.com/",
    "project": {
        "id": 46,
        "url": "http://patchwork.ozlabs.org/api/projects/46/?format=api",
        "name": "Intel Wired Ethernet development",
        "link_name": "intel-wired-lan",
        "list_id": "intel-wired-lan.osuosl.org",
        "list_email": "intel-wired-lan@osuosl.org",
        "web_url": "",
        "scm_url": "",
        "webscm_url": "",
        "list_archive_url": "",
        "list_archive_url_format": "",
        "commit_url_format": ""
    },
    "msgid": "<2B0E3F215D1AB84DA946C8BEE234CCC97B3014A3@ORSMSX101.amr.corp.intel.com>",
    "list_archive_url": null,
    "date": "2019-11-19T04:07:15",
    "name": "virtual-bus[v4]: Implementation of Virtual Bus",
    "commit_ref": null,
    "pull_url": null,
    "state": "superseded",
    "archived": false,
    "hash": "89cf3d8ae7c2d90a336f0f955d30cbd9daa53bbd",
    "submitter": {
        "id": 64529,
        "url": "http://patchwork.ozlabs.org/api/people/64529/?format=api",
        "name": "Dave Ertman",
        "email": "david.m.ertman@intel.com"
    },
    "delegate": {
        "id": 68,
        "url": "http://patchwork.ozlabs.org/api/users/68/?format=api",
        "username": "jtkirshe",
        "first_name": "Jeff",
        "last_name": "Kirsher",
        "email": "jeffrey.t.kirsher@intel.com"
    },
    "mbox": "http://patchwork.ozlabs.org/project/intel-wired-lan/patch/2B0E3F215D1AB84DA946C8BEE234CCC97B3014A3@ORSMSX101.amr.corp.intel.com/mbox/",
    "series": [
        {
            "id": 143685,
            "url": "http://patchwork.ozlabs.org/api/series/143685/?format=api",
            "web_url": "http://patchwork.ozlabs.org/project/intel-wired-lan/list/?series=143685",
            "date": "2019-11-19T04:07:15",
            "name": "virtual-bus[v4]: Implementation of Virtual Bus",
            "version": 1,
            "mbox": "http://patchwork.ozlabs.org/series/143685/mbox/"
        }
    ],
    "comments": "http://patchwork.ozlabs.org/api/patches/1197158/comments/",
    "check": "pending",
    "checks": "http://patchwork.ozlabs.org/api/patches/1197158/checks/",
    "tags": {},
    "related": [],
    "headers": {
        "Return-Path": "<intel-wired-lan-bounces@osuosl.org>",
        "X-Original-To": [
            "incoming@patchwork.ozlabs.org",
            "intel-wired-lan@lists.osuosl.org"
        ],
        "Delivered-To": [
            "patchwork-incoming@bilbo.ozlabs.org",
            "intel-wired-lan@lists.osuosl.org"
        ],
        "Authentication-Results": [
            "ozlabs.org; spf=pass (sender SPF authorized)\n\tsmtp.mailfrom=osuosl.org (client-ip=140.211.166.133;\n\thelo=hemlock.osuosl.org;\n\tenvelope-from=intel-wired-lan-bounces@osuosl.org;\n\treceiver=<UNKNOWN>)",
            "ozlabs.org;\n\tdmarc=fail (p=none dis=none) header.from=intel.com"
        ],
        "Received": [
            "from hemlock.osuosl.org (smtp2.osuosl.org [140.211.166.133])\n\t(using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256\n\tbits)) (No client certificate requested)\n\tby ozlabs.org (Postfix) with ESMTPS id 47HC2v1Kftz9sRC\n\tfor <incoming@patchwork.ozlabs.org>;\n\tTue, 19 Nov 2019 15:07:32 +1100 (AEDT)",
            "from localhost (localhost [127.0.0.1])\n\tby hemlock.osuosl.org (Postfix) with ESMTP id 1656C8797A;\n\tTue, 19 Nov 2019 04:07:30 +0000 (UTC)",
            "from hemlock.osuosl.org ([127.0.0.1])\n\tby localhost (.osuosl.org [127.0.0.1]) (amavisd-new, port 10024)\n\twith ESMTP id 8w+Lz2e1QqV5; Tue, 19 Nov 2019 04:07:24 +0000 (UTC)",
            "from ash.osuosl.org (ash.osuosl.org [140.211.166.34])\n\tby hemlock.osuosl.org (Postfix) with ESMTP id 30F838792F;\n\tTue, 19 Nov 2019 04:07:24 +0000 (UTC)",
            "from fraxinus.osuosl.org (smtp4.osuosl.org [140.211.166.137])\n\tby ash.osuosl.org (Postfix) with ESMTP id 016341BF2B0\n\tfor <intel-wired-lan@lists.osuosl.org>;\n\tTue, 19 Nov 2019 04:07:23 +0000 (UTC)",
            "from localhost (localhost [127.0.0.1])\n\tby fraxinus.osuosl.org (Postfix) with ESMTP id F0FAB86398\n\tfor <intel-wired-lan@lists.osuosl.org>;\n\tTue, 19 Nov 2019 04:07:22 +0000 (UTC)",
            "from fraxinus.osuosl.org ([127.0.0.1])\n\tby localhost (.osuosl.org [127.0.0.1]) (amavisd-new, port 10024)\n\twith ESMTP id gfgSb_jphza9 for <intel-wired-lan@lists.osuosl.org>;\n\tTue, 19 Nov 2019 04:07:17 +0000 (UTC)",
            "from mga17.intel.com (mga17.intel.com [192.55.52.151])\n\tby fraxinus.osuosl.org (Postfix) with ESMTPS id E79C385F3D\n\tfor <intel-wired-lan@lists.osuosl.org>;\n\tTue, 19 Nov 2019 04:07:16 +0000 (UTC)",
            "from fmsmga004.fm.intel.com ([10.253.24.48])\n\tby fmsmga107.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384;\n\t18 Nov 2019 20:07:14 -0800",
            "from orsmsx103.amr.corp.intel.com ([10.22.225.130])\n\tby fmsmga004.fm.intel.com with ESMTP; 18 Nov 2019 20:07:16 -0800",
            "from orsmsx156.amr.corp.intel.com (10.22.240.22) by\n\tORSMSX103.amr.corp.intel.com (10.22.225.130) with Microsoft SMTP\n\tServer (TLS) id 14.3.439.0; Mon, 18 Nov 2019 20:07:16 -0800",
            "from orsmsx101.amr.corp.intel.com ([169.254.8.229]) by\n\tORSMSX156.amr.corp.intel.com ([169.254.8.101]) with mapi id\n\t14.03.0439.000; Mon, 18 Nov 2019 20:07:15 -0800"
        ],
        "X-Virus-Scanned": [
            "amavisd-new at osuosl.org",
            "amavisd-new at osuosl.org"
        ],
        "X-Greylist": "domain auto-whitelisted by SQLgrey-1.7.6",
        "X-Amp-Result": "SKIPPED(no attachment in message)",
        "X-Amp-File-Uploaded": "False",
        "X-ExtLoop1": "1",
        "X-IronPort-AV": "E=Sophos;i=\"5.68,322,1569308400\"; d=\"scan'208\";a=\"231397554\"",
        "From": "\"Ertman, David M\" <david.m.ertman@intel.com>",
        "To": "\"'intel-wired-lan@lists.osuosl.org'\" <intel-wired-lan@lists.osuosl.org>, \n\t\"Kirsher, Jeffrey T\" <jeffrey.t.kirsher@intel.com>, \"Patil, Kiran\"\n\t<kiran.patil@intel.com>",
        "Thread-Topic": "virtual-bus[v4]: Implementation of Virtual Bus",
        "Thread-Index": "AdWejsx8GQqdDhAwRmONv45220IUFg==",
        "Date": "Tue, 19 Nov 2019 04:07:15 +0000",
        "Message-ID": "<2B0E3F215D1AB84DA946C8BEE234CCC97B3014A3@ORSMSX101.amr.corp.intel.com>",
        "Accept-Language": "en-US",
        "Content-Language": "en-US",
        "X-MS-Has-Attach": "",
        "X-MS-TNEF-Correlator": "",
        "dlp-product": "dlpe-windows",
        "dlp-version": "11.2.0.6",
        "dlp-reaction": "no-action",
        "x-originating-ip": "[10.22.254.139]",
        "MIME-Version": "1.0",
        "Subject": "[Intel-wired-lan] virtual-bus[v4]: Implementation of Virtual Bus",
        "X-BeenThere": "intel-wired-lan@osuosl.org",
        "X-Mailman-Version": "2.1.29",
        "Precedence": "list",
        "List-Id": "Intel Wired Ethernet Linux Kernel Driver Development\n\t<intel-wired-lan.osuosl.org>",
        "List-Unsubscribe": "<https://lists.osuosl.org/mailman/options/intel-wired-lan>, \n\t<mailto:intel-wired-lan-request@osuosl.org?subject=unsubscribe>",
        "List-Archive": "<http://lists.osuosl.org/pipermail/intel-wired-lan/>",
        "List-Post": "<mailto:intel-wired-lan@osuosl.org>",
        "List-Help": "<mailto:intel-wired-lan-request@osuosl.org?subject=help>",
        "List-Subscribe": "<https://lists.osuosl.org/mailman/listinfo/intel-wired-lan>, \n\t<mailto:intel-wired-lan-request@osuosl.org?subject=subscribe>",
        "Content-Type": "text/plain; charset=\"us-ascii\"",
        "Content-Transfer-Encoding": "7bit",
        "Errors-To": "intel-wired-lan-bounces@osuosl.org",
        "Sender": "\"Intel-wired-lan\" <intel-wired-lan-bounces@osuosl.org>"
    },
    "content": "virtual-bus[v4]: Implementation of Virtual Bus\n\nFrom: Dave Ertman <david.m.ertman@intel.com>\n\nThis is the initial implementation of the virtual bus,\nvirtbus_device and virtbus_driver.  The virtual bus is\na software based bus intended to support registering\nvirtbus_devices and virtbus_drivers and provide matching\nbetween them and probing of the registered drivers.\n\nThe primary purpose of the virtual bus is to provide\nmatching services to allow the use of a container_of\nto get access to a piece of desired data.  This will\nallow two separate kernel objects to match up and\nstart communication.\n\nThe bus will support probe/remove shutdown and\nsuspend/resume callbacks.\n\nKconfig and Makefile alterations are included\n\nSigned-off-by: Dave Ertman <david.m.ertman@intel.com>\nSigned-off-by: Kiran Patil <kiran.patil@intel.com>\n---\n .../selftests/virtual_bus/virtual_bus_dev/Makefile |    7 +\n .../virtual_bus/virtual_bus_dev/virtual_bus_dev.c  |   60 ++++++++++\n .../selftests/virtual_bus/virtual_bus_drv/Makefile |    7 +\n .../virtual_bus/virtual_bus_drv/virtual_bus_drv.c  |  115 ++++++++++++++++++++\n 4 files changed, 189 insertions(+)\n create mode 100644 tools/testing/selftests/virtual_bus/virtual_bus_dev/Makefile\n create mode 100644 tools/testing/selftests/virtual_bus/virtual_bus_dev/virtual_bus_dev.c\n create mode 100644 tools/testing/selftests/virtual_bus/virtual_bus_drv/Makefile\n create mode 100644 tools/testing/selftests/virtual_bus/virtual_bus_drv/virtual_bus_drv.c",
    "diff": "diff --git a/Documentation/driver-api/virtual_bus.rst b/Documentation/driver-api/virtual_bus.rst\nnew file mode 100644\nindex 000000000000..db8c34fcafe8\n--- /dev/null\n+++ b/Documentation/driver-api/virtual_bus.rst\n@@ -0,0 +1,76 @@\n+===============================\n+Virtual Bus Devices and Drivers\n+===============================\n+\n+See <linux/virtual_bus.h> for the models for virtbus_device and virtbus_driver.\n+This bus is meant to be a lightweight software based bus to attach generic\n+devices and drivers to so that a chunk of data can be passed between them.\n+\n+One use case example is an rdma driver needing to connect with several\n+different types of PCI LAN devices to be able to request resources from\n+them (queue sets).  Each LAN driver that supports rdma will register a\n+virtbus_device on the virtual bus for each physical function.  The rdma\n+driver will register as a virtbus_driver on the virtual bus to be\n+matched up with multiple virtbus_devices and receive a pointer to a\n+struct containing the callbacks that the PCI LAN drivers support for\n+registering with them.\n+\n+Sections in this document:\n+        Virtbus devices\n+        Virtbus drivers\n+        Device Enumeration\n+        Device naming and driver binding\n+        Virtual Bus API entry points\n+\n+Virtbus devices\n+~~~~~~~~~~~~~~~\n+Virtbus_devices are lightweight objects that support the minimal device\n+functionality.  Devices will accept a name, and then an automatically\n+generated index is concatenated onto it for the virtbus_device->name.\n+\n+The virtbus_driver and virtbus_device creators need to both have access\n+to a predefined virtbus_device_object struct that will look like the\n+following:\n+     struct virtbus_object {\n+          struct virtbus_device vdev;\n+          struct foo_type foo;\n+     }\n+\n+Then when the virtbus_driver's probe is called with the virtbus_device\n+as a parameter, it can do a container_of on the virtbus_device to get\n+to the struct foo_type foo that it cares about.\n+\n+Virtbus drivers\n+~~~~~~~~~~~~~~~\n+Virtbus drivers register with the virtual bus to be matched with virtbus\n+devices.  They expect to be registered with a probe and remove callback,\n+and also support shutdown, suspend, and resume callbacks.  They otherwise\n+follow the standard driver behavior of having discovery and enumeration\n+handled in the bus infrastructure.\n+\n+Virtbus drivers register themselves with the API entry point virtbus_drv_reg\n+and unregister with virtbus_drv_unreg.\n+\n+Device Enumeration\n+~~~~~~~~~~~~~~~~~~\n+Enumeration is handled automatically by the bus infrastructure via the\n+ida_simple methods.\n+\n+Device naming and driver binding\n+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n+The virtbus_device.dev.name is the canonical name for the device. It is\n+built from two other parts:\n+\n+        - virtbus_device.name (also used for matching).\n+        - virtbus_device.id (generated automatically from ida_simple calls)\n+\n+This allows for multiple virtbus_devices with the same name, which will all\n+be matched to the same virtbus_driver. Driver binding is performed by the\n+driver core, invoking driver probe() after finding a match between device and driver.\n+\n+Virtual Bus API entry points\n+~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n+int virtbus_dev_register(struct virtbus_device *vdev)\n+void virtbus_dev_unregister(struct virtbus_device *vdev)\n+int virtbus_drv_register(struct virtbus_driver *vdrv, struct module *owner)\n+void virtbus_drv_unregister(struct virtbus_driver *vdrv)\ndiff --git a/drivers/bus/Kconfig b/drivers/bus/Kconfig\nindex 6b331061d34b..c2f9029abed6 100644\n--- a/drivers/bus/Kconfig\n+++ b/drivers/bus/Kconfig\n@@ -193,4 +193,16 @@ config DA8XX_MSTPRI\n \n source \"drivers/bus/fsl-mc/Kconfig\"\n \n+config VIRTUAL_BUS\n+       tristate \"lightweight Virtual Bus\"\n+       depends on PM\n+       help\n+         Provides a software bus for virtbus_devices to be added to it\n+         and virtbus_drivers to be registered on it.  Will create a match\n+         between the driver and device, then call the driver's probe with\n+         the virtbus_device's struct.\n+         One example is the irdma driver needing to connect with various\n+         PCI LAN drivers to request resources (queues) to be able to perform\n+         its function.\n+\n endmenu\ndiff --git a/drivers/bus/Makefile b/drivers/bus/Makefile\nindex 16b43d3468c6..0b0ba53cbe5b 100644\n--- a/drivers/bus/Makefile\n+++ b/drivers/bus/Makefile\n@@ -33,3 +33,4 @@ obj-$(CONFIG_UNIPHIER_SYSTEM_BUS)\t+= uniphier-system-bus.o\n obj-$(CONFIG_VEXPRESS_CONFIG)\t+= vexpress-config.o\n \n obj-$(CONFIG_DA8XX_MSTPRI)\t+= da8xx-mstpri.o\n+obj-$(CONFIG_VIRTUAL_BUS)\t+= virtual_bus.o\ndiff --git a/drivers/bus/virtual_bus.c b/drivers/bus/virtual_bus.c\nnew file mode 100644\nindex 000000000000..6bc986659e4b\n--- /dev/null\n+++ b/drivers/bus/virtual_bus.c\n@@ -0,0 +1,295 @@\n+// SPDX-License-Identifier: GPL-2.0\n+/*\n+ * virtual_bus.c - lightweight software based bus for virtual devices\n+ *\n+ * Copyright (c) 2019-20 Intel Corporation\n+ *\n+ * Please see Documentation/driver-api/virtual_bus.rst for\n+ * more information\n+ */\n+\n+#include <linux/string.h>\n+#include <linux/virtual_bus.h>\n+#include <linux/of_irq.h>\n+#include <linux/module.h>\n+#include <linux/init.h>\n+#include <linux/pm_runtime.h>\n+#include <linux/pm_domain.h>\n+#include <linux/acpi.h>\n+#include <linux/device.h>\n+\n+MODULE_LICENSE(\"GPL v2\");\n+MODULE_DESCRIPTION(\"Lightweight Virtual Bus\");\n+MODULE_AUTHOR(\"David Ertman <david.m.ertman@intel.com>\");\n+MODULE_AUTHOR(\"Kiran Patil <kiran.patil@intel.com>\");\n+\n+static DEFINE_IDA(virtbus_dev_ida);\n+\n+static const\n+struct virtbus_dev_id *virtbus_match_id(const struct virtbus_dev_id *id,\n+\t\t\t\t\tstruct virtbus_device *vdev)\n+{\n+\twhile (id->name[0]) {\n+\t\tif (!strcmp(vdev->name, id->name)) {\n+\t\t\tvdev->matched_element = id;\n+\t\t\treturn id;\n+\t\t}\n+\t\tid++;\n+\t}\n+\treturn NULL;\n+}\n+\n+#define to_virtbus_dev(x)\t(container_of((x), struct virtbus_device, dev))\n+#define to_virtbus_drv(x)\t(container_of((x), struct virtbus_driver, \\\n+\t\t\t\t driver))\n+\n+/**\n+ * virtbus_match - bind virtbus device to virtbus driver\n+ * @dev: device\n+ * @drv: driver\n+ *\n+ * Virtbus device IDs are always in \"<name>.<instance>\" format.\n+ * Instances are automatically selected through an ida_simple_get so\n+ * are positive integers. Names are taken from the device name field.\n+ * Driver IDs are simple <name>.  Need to extract the name from the\n+ * Virtual Device compare to name of the driver.\n+ */\n+static int virtbus_match(struct device *dev, struct device_driver *drv)\n+{\n+\tstruct virtbus_driver *vdrv = to_virtbus_drv(drv);\n+\tstruct virtbus_device *vdev = to_virtbus_dev(dev);\n+\n+\tif (vdrv->id_table)\n+\t\treturn virtbus_match_id(vdrv->id_table, vdev) != NULL;\n+\n+\treturn !strcmp(vdev->name, drv->name);\n+}\n+\n+/**\n+ * virtbus_probe - call probe of the virtbus_drv\n+ * @dev: device struct\n+ */\n+static int virtbus_probe(struct device *dev)\n+{\n+\tif (dev->driver->probe)\n+\t\treturn dev->driver->probe(dev);\n+\n+\treturn 0;\n+}\n+\n+static int virtbus_remove(struct device *dev)\n+{\n+\tif (dev->driver->remove)\n+\t\treturn dev->driver->remove(dev);\n+\n+\treturn 0;\n+}\n+\n+static void virtbus_shutdown(struct device *dev)\n+{\n+\tif (dev->driver->shutdown)\n+\t\tdev->driver->shutdown(dev);\n+}\n+\n+static int virtbus_suspend(struct device *dev, pm_message_t state)\n+{\n+\tif (dev->driver->suspend)\n+\t\treturn dev->driver->suspend(dev, state);\n+\n+\treturn 0;\n+}\n+\n+static int virtbus_resume(struct device *dev)\n+{\n+\tif (dev->driver->resume)\n+\t\treturn dev->driver->resume(dev);\n+\n+\treturn 0;\n+}\n+\n+struct bus_type virtual_bus_type = {\n+\t.name = \"virtbus\",\n+\t.match = virtbus_match,\n+\t.probe = virtbus_probe,\n+\t.remove = virtbus_remove,\n+\t.shutdown = virtbus_shutdown,\n+\t.suspend = virtbus_suspend,\n+\t.resume = virtbus_resume,\n+};\n+\n+/**\n+ * virtbus_dev_register - add a virtual bus device\n+ * @vdev: virtual bus device to add\n+ */\n+int virtbus_dev_register(struct virtbus_device *vdev)\n+{\n+\tint ret;\n+\n+\tdevice_initialize(&vdev->dev);\n+\n+\tvdev->dev.bus = &virtual_bus_type;\n+\t/* All device IDs are automatically allocated */\n+\tret = ida_simple_get(&virtbus_dev_ida, 0, 0, GFP_KERNEL);\n+\tif (ret < 0)\n+\t\treturn ret;\n+\n+\tvdev->id = ret;\n+\tdev_set_name(&vdev->dev, \"%s.%d\", vdev->name, vdev->id);\n+\n+\tdev_dbg(&vdev->dev, \"Registering virtbus device '%s'\\n\",\n+\t\tdev_name(&vdev->dev));\n+\n+\tret = device_add(&vdev->dev);\n+\tif (ret)\n+\t\tgoto device_add_err;\n+\n+\treturn 0;\n+\n+device_add_err:\n+\t/* Error adding virtual device */\n+\tput_device(&vdev->dev);\n+\tida_simple_remove(&virtbus_dev_ida, vdev->id);\n+\n+\treturn ret;\n+}\n+EXPORT_SYMBOL_GPL(virtbus_dev_register);\n+\n+/**\n+ * virtbus_dev_unregister - remove a virtual bus device\n+ * vdev: virtual bus device we are removing\n+ */\n+void virtbus_dev_unregister(struct virtbus_device *vdev)\n+{\n+\tput_device(&vdev->dev);\n+}\n+EXPORT_SYMBOL_GPL(virtbus_dev_unregister);\n+\n+struct virtbus_object {\n+\tstruct virtbus_device vdev;\n+\tchar name[];\n+};\n+\n+/**\n+ * virtbus_dev_release - Destroy a virtbus device\n+ * @vdev: virtual device to release\n+ *\n+ * Note that the vdev->data which is separately allocated needs to be\n+ * separately freed on it own.\n+ */\n+static void virtbus_dev_release(struct device *dev)\n+{\n+\tstruct virtbus_object *vo = container_of(dev, struct virtbus_object,\n+\t\t\t\t\t\t vdev.dev);\n+\n+\tida_simple_remove(&virtbus_dev_ida, vo->vdev.id);\n+\tkfree(vo);\n+}\n+\n+static int virtbus_drv_probe(struct device *_dev)\n+{\n+\tstruct virtbus_driver *vdrv = to_virtbus_drv(_dev->driver);\n+\tstruct virtbus_device *vdev = to_virtbus_dev(_dev);\n+\tint ret;\n+\n+\tret = dev_pm_domain_attach(_dev, true);\n+\tif (ret) {\n+\t\tdev_warn(_dev, \"Failed to attatch to PM Domain : %d\\n\", ret);\n+\t\treturn ret;\n+\t}\n+\n+\tif (vdrv->probe) {\n+\t\tret = vdrv->probe(vdev);\n+\t\tif (ret)\n+\t\t\tdev_pm_domain_detach(_dev, true);\n+\t}\n+\n+\treturn ret;\n+}\n+\n+static int virtbus_drv_remove(struct device *_dev)\n+{\n+\tstruct virtbus_driver *vdrv = to_virtbus_drv(_dev->driver);\n+\tstruct virtbus_device *vdev = to_virtbus_dev(_dev);\n+\tint ret = 0;\n+\n+\tif (vdrv->remove)\n+\t\tret = vdrv->remove(vdev);\n+\n+\tdev_pm_domain_detach(_dev, true);\n+\n+\treturn ret;\n+}\n+\n+static void virtbus_drv_shutdown(struct device *_dev)\n+{\n+\tstruct virtbus_driver *vdrv = to_virtbus_drv(_dev->driver);\n+\tstruct virtbus_device *vdev = to_virtbus_dev(_dev);\n+\n+\tif (vdrv->shutdown)\n+\t\tvdrv->shutdown(vdev);\n+}\n+\n+static int virtbus_drv_suspend(struct device *_dev, pm_message_t state)\n+{\n+\tstruct virtbus_driver *vdrv = to_virtbus_drv(_dev->driver);\n+\tstruct virtbus_device *vdev = to_virtbus_dev(_dev);\n+\n+\tif (vdrv->suspend)\n+\t\treturn vdrv->suspend(vdev, state);\n+\n+\treturn 0;\n+}\n+\n+static int virtbus_drv_resume(struct device *_dev)\n+{\n+\tstruct virtbus_driver *vdrv = to_virtbus_drv(_dev->driver);\n+\tstruct virtbus_device *vdev = to_virtbus_dev(_dev);\n+\n+\tif (vdrv->resume)\n+\t\treturn vdrv->resume(vdev);\n+\n+\treturn 0;\n+}\n+\n+/**\n+ * __virtbus_drv_register - register a driver for virtual bus devices\n+ * @vdrv: virtbus_driver structure\n+ * @owner: owning module/driver\n+ */\n+int __virtbus_drv_register(struct virtbus_driver *vdrv, struct module *owner)\n+{\n+\tvdrv->driver.owner = owner;\n+\tvdrv->driver.bus = &virtual_bus_type;\n+\tvdrv->driver.probe = virtbus_drv_probe;\n+\tvdrv->driver.remove = virtbus_drv_remove;\n+\tvdrv->driver.shutdown = virtbus_drv_shutdown;\n+\tvdrv->driver.suspend = virtbus_drv_suspend;\n+\tvdrv->driver.resume = virtbus_drv_resume;\n+\n+\treturn driver_register(&vdrv->driver);\n+}\n+EXPORT_SYMBOL_GPL(__virtbus_drv_register);\n+\n+/**\n+ * virtbus_drv_unregister - unregister a driver for virtual bus devices\n+ * @drv: virtbus_driver structure\n+ */\n+void virtbus_drv_unregister(struct virtbus_driver *vdrv)\n+{\n+\tdriver_unregister(&vdrv->driver);\n+}\n+EXPORT_SYMBOL_GPL(virtbus_drv_unregister);\n+\n+static int __init virtual_bus_init(void)\n+{\n+\treturn bus_register(&virtual_bus_type);\n+}\n+\n+static void __exit virtual_bus_exit(void)\n+{\n+\tbus_unregister(&virtual_bus_type);\n+\tida_destroy(&virtbus_dev_ida);\n+}\n+\n+module_init(virtual_bus_init);\n+module_exit(virtual_bus_exit);\ndiff --git a/include/linux/mod_devicetable.h b/include/linux/mod_devicetable.h\nindex 5714fd35a83c..e19214f84c98 100644\n--- a/include/linux/mod_devicetable.h\n+++ b/include/linux/mod_devicetable.h\n@@ -821,4 +821,12 @@ struct wmi_device_id {\n \tconst void *context;\n };\n \n+#define VIRTBUS_NAME_SIZE 20\n+#define VIRTBUS_MODULE_PREFIX \"virtbus:\"\n+\n+struct virtbus_dev_id {\n+\tchar name[VIRTBUS_NAME_SIZE];\n+\tkernel_ulong_t driver_data;\n+};\n+\n #endif /* LINUX_MOD_DEVICETABLE_H */\ndiff --git a/include/linux/virtual_bus.h b/include/linux/virtual_bus.h\nnew file mode 100644\nindex 000000000000..fe4725b1e6b1\n--- /dev/null\n+++ b/include/linux/virtual_bus.h\n@@ -0,0 +1,45 @@\n+/* SPDX-License-Identifier: GPL-2.0-only */\n+/*\n+ * virtual_bus.h - lightweight software bus\n+ *\n+ * Copyright (c) 2019-20 Intel Corporation\n+ *\n+ * Please see Documentation/driver-api/virtual_bus.rst for more information\n+ */\n+\n+#ifndef _VIRTUAL_BUS_H_\n+#define _VIRTUAL_BUS_H_\n+\n+#include <linux/device.h>\n+\n+struct virtbus_device {\n+\tconst char *name;\n+\tint id;\n+\tconst struct virtbus_dev_id *matched_element;\n+\tstruct device dev;\n+};\n+\n+/* If the driver uses a id_table to match with virtbus_devices, then the\n+ * memory for the table is expected to remain allocated for the duration\n+ * of the pairing between driver and device.  The pointer for the matching\n+ * element will be copied to the dev_id field of the virtbus_device.\n+ */\n+struct virtbus_driver {\n+\tint (*probe)(struct virtbus_device *);\n+\tint (*remove)(struct virtbus_device *);\n+\tvoid (*shutdown)(struct virtbus_device *);\n+\tint (*suspend)(struct virtbus_device *, pm_message_t);\n+\tint (*resume)(struct virtbus_device *);\n+\tstruct device_driver driver;\n+\tconst struct virtbus_dev_id *id_table;\n+};\n+\n+int virtbus_dev_register(struct virtbus_device *vdev);\n+void virtbus_dev_unregister(struct virtbus_device *vdev);\n+int __virtbus_drv_register(struct virtbus_driver *vdrv, struct module *owner);\n+void virtbus_drv_unregister(struct virtbus_driver *vdrv);\n+\n+#define virtbus_drv_register(vdrv) \\\n+\t__virtbus_drv_register(vdrv, THIS_MODULE)\n+\n+#endif /* _VIRTUAL_BUS_H_ */\ndiff --git a/scripts/mod/devicetable-offsets.c b/scripts/mod/devicetable-offsets.c\nindex 054405b90ba4..9a6099bf90c8 100644\n--- a/scripts/mod/devicetable-offsets.c\n+++ b/scripts/mod/devicetable-offsets.c\n@@ -231,5 +231,8 @@ int main(void)\n \tDEVID(wmi_device_id);\n \tDEVID_FIELD(wmi_device_id, guid_string);\n \n+\tDEVID(virtbus_dev_id);\n+\tDEVID_FIELD(virtbus_dev_id, name);\n+\n \treturn 0;\n }\ndiff --git a/scripts/mod/file2alias.c b/scripts/mod/file2alias.c\nindex c91eba751804..713fdfe010b0 100644\n--- a/scripts/mod/file2alias.c\n+++ b/scripts/mod/file2alias.c\n@@ -1335,6 +1335,13 @@ static int do_wmi_entry(const char *filename, void *symval, char *alias)\n \treturn 1;\n }\n \n+static int do_virtbus_entry(const char *filename, void *symval, char *alias)\n+{\n+\tDEF_FIELD_ADDR(symval, virtbus_dev_id, name);\n+\tsprintf(alias, VIRTBUS_MODULE_PREFIX \"%s\", *name);\n+\treturn 1;\n+}\n+\n /* Does namelen bytes of name exactly match the symbol? */\n static bool sym_is(const char *name, unsigned namelen, const char *symbol)\n {\n@@ -1407,6 +1414,7 @@ static const struct devtable devtable[] = {\n \t{\"typec\", SIZE_typec_device_id, do_typec_entry},\n \t{\"tee\", SIZE_tee_client_device_id, do_tee_entry},\n \t{\"wmi\", SIZE_wmi_device_id, do_wmi_entry},\n+\t{\"virtbus\", SIZE_virtbus_dev_id, do_virtbus_entry},\n };\n \n /* Create MODULE_ALIAS() statements.\ndiff --git a/tools/testing/selftests/virtual_bus/virtual_bus_dev/Makefile b/tools/testing/selftests/virtual_bus/virtual_bus_dev/Makefile\nnew file mode 100644\nindex 000000000000..ddd5088eb26b\n--- /dev/null\n+++ b/tools/testing/selftests/virtual_bus/virtual_bus_dev/Makefile\n@@ -0,0 +1,7 @@\n+obj-m += virtual_bus_dev.o\n+\n+all:\n+\tmake -C /lib/modules/$(shell uname -r)/build M=$(PWD) modules\n+\n+clean:\n+\tmake -C /lib/modules/$(shell uname -r)/build M=$(PWD) clean\ndiff --git a/tools/testing/selftests/virtual_bus/virtual_bus_dev/virtual_bus_dev.c b/tools/testing/selftests/virtual_bus/virtual_bus_dev/virtual_bus_dev.c\nnew file mode 100644\nindex 000000000000..2a91813e22db\n--- /dev/null\n+++ b/tools/testing/selftests/virtual_bus/virtual_bus_dev/virtual_bus_dev.c\n@@ -0,0 +1,60 @@\n+#include <linux/init.h>\n+#include <linux/module.h>\n+#include <linux/module.h>\n+#include <linux/virtual_bus.h>\n+#include <linux/string.h>\n+#include <linux/slab.h>\n+\n+MODULE_LICENSE(\"GPL v2\");\n+MODULE_AUTHOR(\"Dave Ertman\");\n+MODULE_DESCRIPTION(\"Test to create a device on virtual bus\");\n+MODULE_VERSION(\"1.0\");\n+\n+struct virtbus_data {\n+\tint numb;\n+};\n+\n+struct virtbus_object {\n+\tstruct virtbus_device vdev;\n+\tstruct virtbus_data vd;\n+};\n+\n+static struct virtbus_object vo = {\n+\t.vdev = {\n+\t\t.name = \"virtual_bus_dev\",\n+\t\t},\n+\t.vd = {\n+\t\t.numb = 789,\n+\t},\n+};\n+\n+static int __init test_dev_init(void)\n+{\n+\tint ret = 0;\n+\n+\tprintk(KERN_INFO \"Loading Virtual Bus Test Device\\n\");\n+\n+\tprintk(KERN_ERR \"Virtbus Device values:\\n\\t%s\\n\\t%d\\n\", vo.vdev.name,\n+\t       vo.vd.numb);\n+\n+\tret = virtbus_dev_register(&vo.vdev);\n+\tif(ret) {\n+\t\tprintk(KERN_ERR \"FAILED TO ADD VIRTBUS DEVICE %d\\n\", ret);\n+\t\treturn ret;\n+\t}\n+\n+\tprintk(KERN_INFO \"Virtual Device created\\n\");\n+\treturn ret;\n+}\n+\n+static void __exit test_dev_exit(void)\n+{\n+\tprintk(KERN_INFO \"Exiting Virtual Bus Test Device\");\n+\n+\tvirtbus_dev_unregister(&vo.vdev);\n+\n+\tprintk(KERN_INFO \"Virtual Bus Test Device removed\\n\");\n+}\n+\n+module_init(test_dev_init);\n+module_exit(test_dev_exit);\ndiff --git a/tools/testing/selftests/virtual_bus/virtual_bus_drv/Makefile b/tools/testing/selftests/virtual_bus/virtual_bus_drv/Makefile\nnew file mode 100644\nindex 000000000000..a4b7467f7878\n--- /dev/null\n+++ b/tools/testing/selftests/virtual_bus/virtual_bus_drv/Makefile\n@@ -0,0 +1,7 @@\n+obj-m += virtual_bus_drv.o\n+\n+all:\n+\tmake -C /lib/modules/$(shell uname -r)/build M=$(PWD) modules\n+\n+clean:\n+\tmake -C /lib/modules/$(shell uname -r)/build M=$(PWD) clean\ndiff --git a/tools/testing/selftests/virtual_bus/virtual_bus_drv/virtual_bus_drv.c b/tools/testing/selftests/virtual_bus/virtual_bus_drv/virtual_bus_drv.c\nnew file mode 100644\nindex 000000000000..13e2e3d686ab\n--- /dev/null\n+++ b/tools/testing/selftests/virtual_bus/virtual_bus_drv/virtual_bus_drv.c\n@@ -0,0 +1,115 @@\n+#include <linux/init.h>\n+#include <linux/module.h>\n+#include <linux/module.h>\n+#include <linux/virtual_bus.h>\n+#include <linux/string.h>\n+#include <linux/slab.h>\n+#include <linux/mod_devicetable.h>\n+\n+MODULE_LICENSE(\"GPL\");\n+MODULE_AUTHOR(\"Dave Ertman\");\n+MODULE_DESCRIPTION(\"Test to register a driver on virtual bus\");\n+MODULE_VERSION(\"1.0\");\n+\n+struct virtbus_data {\n+\tint numb;\n+};\n+\n+struct virtbus_object {\n+\tstruct virtbus_device vdev;\n+\tstruct virtbus_data vd;\n+};\n+\n+static int td_probe(struct virtbus_device *vdev)\n+{\n+\tstruct virtbus_object *vo;\n+\n+\tprintk(KERN_ERR \"VIRTBUS DRIVER PROBED\\n\");\n+\n+\tvo = container_of(vdev, struct virtbus_object, vdev);\n+\n+\tif (vdev->matched_element) {\n+\t\tprintk(KERN_ERR \"DEV_ID->DATA 0x%08x\\n\",\n+\t\t\t(uint)vdev->matched_element->driver_data);\n+\t\tif (vdev->matched_element->driver_data == 1)\n+\t\t\tprintk(KERN_ERR \"NUMB: %d\\n\",\n+\t\t\t       vo->vd.numb);\n+\t} else {\n+\t\tprintk(KERN_ERR \"MATCHED_ELEMENT->DATA is NULL\\n\");\n+\t}\n+\n+\treturn 0;\n+}\n+\n+static int td_remove(struct virtbus_device *vdev)\n+{\n+\tprintk(KERN_ERR \"VIRTBUS DRIVER REMOVED\\n\");\n+\treturn 0;\n+}\n+\n+static void td_shutdown(struct virtbus_device *vdev)\n+{\n+\tprintk(KERN_ERR \"VIRTBUS DRIVER SHUTDOWN\\n\");\n+}\n+\n+static const struct virtbus_dev_id vdev_id_table[] = {\n+\n+\t{\n+\t\t.name = \"NOT THE NAME\",\n+\t\t.driver_data = 0x00000000,\n+\t},\n+\t{\n+\t\t.name = \"virtual_bus_dev\",\n+\t\t.driver_data = 0x00000001,\n+\t},\n+\t{\n+\t\t.name = \"ice_rdma\",\n+\t\t.driver_data = 0x00000002,\n+\t},\n+\t{\n+\t\t.name = \"YET AGAIN NOT NAME\",\n+\t\t.driver_data = 0x00000003,\n+\t},\n+};\n+\n+static struct virtbus_driver vdrv = {\n+\t.probe = td_probe,\n+\t.remove = td_remove,\n+\t.shutdown = td_shutdown,\n+\t.driver = {\n+\t\t.name = \"virtual_bus_dev\",\n+\t},\n+};\n+\n+static int __init test_drv_init(void)\n+{\n+\tint ret;\n+\n+\tprintk(KERN_INFO \"Registering Virtual Bus Test Driver\\n\");\n+\n+\t/* To do a simple match, leave the id_table as NULL */\n+\tvdrv.id_table = &vdev_id_table[0];\n+\n+\tprintk(KERN_ERR \"name of 0 is %s\\n\", vdrv.id_table->name);\n+\n+\tret = virtbus_drv_register(&vdrv);\n+\n+\tif (!ret)\n+\t\tprintk(KERN_INFO \"Virtual Driver registered\\n\");\n+\telse\n+\t\tprintk(KERN_INFO \"Virtual Driver FAILED!!\\n\");\n+\n+\treturn ret;\n+}\n+\n+static void __exit test_drv_exit(void)\n+{\n+\tprintk(KERN_INFO \"Exiting Virtual Bus Test Driver\");\n+\n+\tvirtbus_drv_unregister(&vdrv);\n+\n+\tprintk(KERN_INFO \"Virtual Bus Test Driver removed\\n\");\n+}\n+\n+module_init(test_drv_init);\n+module_exit(test_drv_exit);\n",
    "prefixes": []
}