From: Guan-Yu Lin <guanyulin@google.com>
To: gregkh@linuxfoundation.org, mathias.nyman@intel.com,
stern@rowland.harvard.edu, royluo@google.com, hadess@hadess.net,
benjamin.tissoires@redhat.com, heikki.krogerus@linux.intel.com,
oneukum@suse.com, grundler@chromium.org, yajun.deng@linux.dev,
dianders@chromium.org
Cc: linux-kernel@vger.kernel.org, linux-usb@vger.kernel.org,
badhri@google.com, albertccwang@google.com, pumahsu@google.com,
Guan-Yu Lin <guanyulin@google.com>
Subject: [PATCH] [RFC] usb: host: Allow userspace to control usb suspend flows
Date: Tue, 30 Jan 2024 06:47:13 +0000 [thread overview]
Message-ID: <20240130064819.1362642-1-guanyulin@google.com> (raw)
In a system with sub-system engaged, the controllers are controlled by
both the main processor and the co-processor. Chances are when the main
processor decides to suspend the USB device, the USB device might still
be used by the co-processor. In this scenario, we need a way to let
system know whether it can suspend the USB device or not. We introduce a
new sysfs entry "deprecate_device_pm" to allow userspace to control the
device power management functionality on demand. As the userspace should
possess the information of both the main processor and the co-processor,
it should be able to address the conflict mentioned above.
Signed-off-by: Guan-Yu Lin <guanyulin@google.com>
---
Documentation/ABI/testing/sysfs-bus-usb | 10 +++++++++
drivers/usb/core/driver.c | 18 ++++++++++++++++
drivers/usb/core/sysfs.c | 28 +++++++++++++++++++++++++
drivers/usb/host/xhci-plat.c | 20 ++++++++++++++++++
include/linux/usb.h | 4 ++++
5 files changed, 80 insertions(+)
diff --git a/Documentation/ABI/testing/sysfs-bus-usb b/Documentation/ABI/testing/sysfs-bus-usb
index 2b7108e21977..3f3d6c14201f 100644
--- a/Documentation/ABI/testing/sysfs-bus-usb
+++ b/Documentation/ABI/testing/sysfs-bus-usb
@@ -19,6 +19,16 @@ Description:
would be authorized by default.
The value can be 1 or 0. It's by default 1.
+What: /sys/bus/usb/devices/usbX/deprecate_device_pm
+Date: January 2024
+Contact: Guan-Yu Lin <guanyulin@google.com>
+Description:
+ Deprecates the device power management functionality of USB devices
+ and their host contorller under this usb bus. The modification of
+ this entry should be done when the system is active to ensure the
+ correctness of system power state transitions.
+ The value can be 1 or 0. It's by default 0.
+
What: /sys/bus/usb/device/.../authorized
Date: July 2008
KernelVersion: 2.6.26
diff --git a/drivers/usb/core/driver.c b/drivers/usb/core/driver.c
index e02ba15f6e34..e03cf972160d 100644
--- a/drivers/usb/core/driver.c
+++ b/drivers/usb/core/driver.c
@@ -1569,6 +1569,15 @@ int usb_suspend(struct device *dev, pm_message_t msg)
struct usb_device *udev = to_usb_device(dev);
int r;
+ /*
+ * Skip the entire suspend process under the same usb bus if its sysfs
+ * entry `deprecate_device_pm` is set.
+ */
+ if (udev->bus->deprecate_device_pm) {
+ dev_vdbg(&udev->dev, "deprecating dev_pm_ops: %s\n", __func__);
+ return 0;
+ }
+
unbind_no_pm_drivers_interfaces(udev);
/* From now on we are sure all drivers support suspend/resume
@@ -1605,6 +1614,15 @@ int usb_resume(struct device *dev, pm_message_t msg)
struct usb_device *udev = to_usb_device(dev);
int status;
+ /*
+ * Skip the entire resume process under the same usb bus if its sysfs
+ * entry `deprecate_device_pm` is set.
+ */
+ if (udev->bus->deprecate_device_pm) {
+ dev_vdbg(&udev->dev, "deprecating dev_pm_ops: %s\n", __func__);
+ return 0;
+ }
+
/* For all calls, take the device back to full power and
* tell the PM core in case it was autosuspended previously.
* Unbind the interfaces that will need rebinding later,
diff --git a/drivers/usb/core/sysfs.c b/drivers/usb/core/sysfs.c
index 5d21718afb05..b4520e5c8974 100644
--- a/drivers/usb/core/sysfs.c
+++ b/drivers/usb/core/sysfs.c
@@ -68,6 +68,33 @@ static ssize_t bMaxPower_show(struct device *dev,
}
static DEVICE_ATTR_RO(bMaxPower);
+static ssize_t deprecate_device_pm_show(struct device *dev,
+ struct device_attribute *attr, char *buf)
+{
+ struct usb_device *udev;
+
+ udev = to_usb_device(dev);
+ return sysfs_emit(buf, "%d\n", !!(udev->bus->deprecate_device_pm));
+}
+
+static ssize_t deprecate_device_pm_store(struct device *dev,
+ struct device_attribute *attr,
+ const char *buf, size_t count)
+{
+ struct usb_device *udev = to_usb_device(dev);
+ int val, rc;
+
+ if (sscanf(buf, "%d", &val) != 1 || val < 0 || val > 1)
+ return -EINVAL;
+ rc = usb_lock_device_interruptible(udev);
+ if (rc < 0)
+ return -EINTR;
+ udev->bus->deprecate_device_pm = !!(val);
+ usb_unlock_device(udev);
+ return count;
+}
+static DEVICE_ATTR_RW(deprecate_device_pm);
+
static ssize_t configuration_show(struct device *dev,
struct device_attribute *attr, char *buf)
{
@@ -984,6 +1011,7 @@ static DEVICE_ATTR_RW(interface_authorized_default);
static struct attribute *usb_bus_attrs[] = {
&dev_attr_authorized_default.attr,
&dev_attr_interface_authorized_default.attr,
+ &dev_attr_deprecate_device_pm.attr,
NULL,
};
diff --git a/drivers/usb/host/xhci-plat.c b/drivers/usb/host/xhci-plat.c
index f04fde19f551..bc05d83d1c0b 100644
--- a/drivers/usb/host/xhci-plat.c
+++ b/drivers/usb/host/xhci-plat.c
@@ -442,6 +442,15 @@ static int xhci_plat_suspend(struct device *dev)
struct xhci_hcd *xhci = hcd_to_xhci(hcd);
int ret;
+ /*
+ * Skip the entire suspend process under the same usb bus if its sysfs
+ * entry `deprecate_device_pm` is set.
+ */
+ if (hcd->self.deprecate_device_pm) {
+ dev_vdbg(dev, "deprecating dev_pm_ops: %s\n", __func__);
+ return 0;
+ }
+
if (pm_runtime_suspended(dev))
pm_runtime_resume(dev);
@@ -507,6 +516,17 @@ static int xhci_plat_resume_common(struct device *dev, struct pm_message pmsg)
static int xhci_plat_resume(struct device *dev)
{
+ struct usb_hcd *hcd = dev_get_drvdata(dev);
+
+ /*
+ * Skip the entire resume process under the same usb bus if its sysfs
+ * entry `deprecate_device_pm` is set.
+ */
+ if (hcd->self.deprecate_device_pm) {
+ dev_vdbg(dev, "deprecating dev_pm_ops: %s\n", __func__);
+ return 0;
+ }
+
return xhci_plat_resume_common(dev, PMSG_RESUME);
}
diff --git a/include/linux/usb.h b/include/linux/usb.h
index 9e52179872a5..1a1873104663 100644
--- a/include/linux/usb.h
+++ b/include/linux/usb.h
@@ -465,6 +465,10 @@ struct usb_bus {
* the ep queue on a short transfer
* with the URB_SHORT_NOT_OK flag set.
*/
+ unsigned deprecate_device_pm:1; /* Deprecates the device power management
+ * functionality of USB devices on this
+ * bus and their hcd.
+ */
unsigned no_sg_constraint:1; /* no sg constraint */
unsigned sg_tablesize; /* 0 or largest number of sg list entries */
--
2.43.0.429.g432eaa2c6b-goog
next reply other threads:[~2024-01-30 6:49 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-01-30 6:47 Guan-Yu Lin [this message]
2024-01-30 16:41 ` [PATCH] [RFC] usb: host: Allow userspace to control usb suspend flows Greg KH
2024-02-01 7:22 ` Guan-Yu Lin
2024-01-30 17:12 ` Alan Stern
2024-02-01 9:02 ` Guan-Yu Lin
2024-02-01 9:38 ` Oliver Neukum
2024-02-01 16:00 ` Guan-Yu Lin
2024-02-01 18:06 ` Greg KH
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=20240130064819.1362642-1-guanyulin@google.com \
--to=guanyulin@google.com \
--cc=albertccwang@google.com \
--cc=badhri@google.com \
--cc=benjamin.tissoires@redhat.com \
--cc=dianders@chromium.org \
--cc=gregkh@linuxfoundation.org \
--cc=grundler@chromium.org \
--cc=hadess@hadess.net \
--cc=heikki.krogerus@linux.intel.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-usb@vger.kernel.org \
--cc=mathias.nyman@intel.com \
--cc=oneukum@suse.com \
--cc=pumahsu@google.com \
--cc=royluo@google.com \
--cc=stern@rowland.harvard.edu \
--cc=yajun.deng@linux.dev \
/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