public inbox for kvm@vger.kernel.org
 help / color / mirror / Atom feed
From: Gregory CLEMENT <gregory.clement@bootlin.com>
To: Eric Auger <eric.auger@redhat.com>,
	Alex Williamson <alex.williamson@redhat.com>,
	linux-kernel@vger.kernel.org, kvm@vger.kernel.org
Cc: "Thomas Petazzoni" <thomas.petazzoni@bootlin.com>,
	"Antoine Tenart" <antoine.tenart@bootlin.com>,
	"Miquèl Raynal" <miquel.raynal@bootlin.com>,
	"Maxime Chevallier" <maxime.chevallier@bootlin.com>,
	"Nadav Haklai" <nadavh@marvell.com>,
	"Gregory CLEMENT" <gregory.clement@bootlin.com>
Subject: [PATCH] vfio: platform: reset: add support for XHCI reset hook
Date: Thu, 11 Jul 2019 16:31:59 +0200	[thread overview]
Message-ID: <20190711143159.21961-1-gregory.clement@bootlin.com> (raw)

The VFIO reset hook is called every time a platform device is passed
to a guest or removed from a guest.

When the XHCI device is unbound from the host, the host driver
disables the XHCI clocks/phys/regulators so when the device is passed
to the guest it becomes dis-functional.

This initial implementation uses the VFIO reset hook to enable the
XHCI clocks/phys on behalf of the guest.

Ported from Marvell LSP code originally written by Yehuda Yitschak

Signed-off-by: Gregory CLEMENT <gregory.clement@bootlin.com>
---
 drivers/vfio/platform/reset/Kconfig           |  8 +++
 drivers/vfio/platform/reset/Makefile          |  2 +
 .../vfio/platform/reset/vfio_platform_xhci.c  | 60 +++++++++++++++++++
 3 files changed, 70 insertions(+)
 create mode 100644 drivers/vfio/platform/reset/vfio_platform_xhci.c

diff --git a/drivers/vfio/platform/reset/Kconfig b/drivers/vfio/platform/reset/Kconfig
index 392e3c09def0..14f620fd250d 100644
--- a/drivers/vfio/platform/reset/Kconfig
+++ b/drivers/vfio/platform/reset/Kconfig
@@ -22,3 +22,11 @@ config VFIO_PLATFORM_BCMFLEXRM_RESET
 	  Enables the VFIO platform driver to handle reset for Broadcom FlexRM
 
 	  If you don't know what to do here, say N.
+
+config VFIO_PLATFORM_XHCI_RESET
+	tristate "VFIO support for USB XHCI reset"
+	depends on VFIO_PLATFORM
+	help
+	  Enables the VFIO platform driver to handle reset for USB XHCI
+
+	  If you don't know what to do here, say N.
diff --git a/drivers/vfio/platform/reset/Makefile b/drivers/vfio/platform/reset/Makefile
index 7294c5ea122e..d84c4d3dc041 100644
--- a/drivers/vfio/platform/reset/Makefile
+++ b/drivers/vfio/platform/reset/Makefile
@@ -1,7 +1,9 @@
 # SPDX-License-Identifier: GPL-2.0
 vfio-platform-calxedaxgmac-y := vfio_platform_calxedaxgmac.o
 vfio-platform-amdxgbe-y := vfio_platform_amdxgbe.o
+vfio-platform-xhci-y := vfio_platform_xhci.o
 
 obj-$(CONFIG_VFIO_PLATFORM_CALXEDAXGMAC_RESET) += vfio-platform-calxedaxgmac.o
 obj-$(CONFIG_VFIO_PLATFORM_AMDXGBE_RESET) += vfio-platform-amdxgbe.o
 obj-$(CONFIG_VFIO_PLATFORM_BCMFLEXRM_RESET) += vfio_platform_bcmflexrm.o
+obj-$(CONFIG_VFIO_PLATFORM_XHCI_RESET) += vfio-platform-xhci.o
diff --git a/drivers/vfio/platform/reset/vfio_platform_xhci.c b/drivers/vfio/platform/reset/vfio_platform_xhci.c
new file mode 100644
index 000000000000..7b75a04402ee
--- /dev/null
+++ b/drivers/vfio/platform/reset/vfio_platform_xhci.c
@@ -0,0 +1,60 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * VFIO platform driver specialized for XHCI reset
+ *
+ * Copyright 2016 Marvell Semiconductors, Inc.
+ *
+ */
+
+#include <linux/clk.h>
+#include <linux/device.h>
+#include <linux/init.h>
+#include <linux/io.h>
+#include <linux/kernel.h>
+#include <linux/module.h>
+#include <linux/of.h>
+#include <linux/phy/phy.h>
+#include <linux/usb/phy.h>
+
+#include "../vfio_platform_private.h"
+
+#define MAX_XHCI_CLOCKS		4
+#define MAX_XHCI_PHYS		2
+
+int vfio_platform_xhci_reset(struct vfio_platform_device *vdev)
+{
+	struct device *dev = vdev->device;
+	struct device_node *np = dev->of_node;
+	struct usb_phy *usb_phy;
+	struct clk *clk;
+	int ret, i;
+
+	/*
+	 * Compared to the native driver, no need to handle the
+	 * deferred case, because the resources are already
+	 * there
+	 */
+	for (i = 0; i < MAX_XHCI_CLOCKS; i++) {
+		clk = of_clk_get(np, i);
+		if (!IS_ERR(clk)) {
+			ret = clk_prepare_enable(clk);
+			if (ret)
+				return -ENODEV;
+		}
+	}
+
+	usb_phy = devm_usb_get_phy_by_phandle(dev, "usb-phy", 0);
+	if (!IS_ERR(usb_phy)) {
+		ret = usb_phy_init(usb_phy);
+		if (ret)
+			return -ENODEV;
+	}
+
+	return 0;
+}
+
+module_vfio_reset_handler("generic-xhci", vfio_platform_xhci_reset);
+
+MODULE_AUTHOR("Yehuda Yitschak");
+MODULE_DESCRIPTION("Reset support for XHCI vfio platform device");
+MODULE_LICENSE("GPL");
-- 
2.20.1


             reply	other threads:[~2019-07-11 14:32 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-07-11 14:31 Gregory CLEMENT [this message]
2019-07-12  7:03 ` [PATCH] vfio: platform: reset: add support for XHCI reset hook Auger Eric
2019-07-15 15:03   ` Gregory CLEMENT

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20190711143159.21961-1-gregory.clement@bootlin.com \
    --to=gregory.clement@bootlin.com \
    --cc=alex.williamson@redhat.com \
    --cc=antoine.tenart@bootlin.com \
    --cc=eric.auger@redhat.com \
    --cc=kvm@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=maxime.chevallier@bootlin.com \
    --cc=miquel.raynal@bootlin.com \
    --cc=nadavh@marvell.com \
    --cc=thomas.petazzoni@bootlin.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox