summaryrefslogtreecommitdiffstats
path: root/src/drivers/usb
diff options
context:
space:
mode:
authorMichael Brown2015-03-18 12:57:41 +0100
committerMichael Brown2015-03-18 13:35:16 +0100
commitec0e2a7bd77c3021bb492ccb78855482312bca4b (patch)
treef85917e04a3dfbf112b5fceee3bb46940f1ece91 /src/drivers/usb
parent[usb] Add config/usb.h for USB configuration options (diff)
downloadipxe-ec0e2a7bd77c3021bb492ccb78855482312bca4b.tar.gz
ipxe-ec0e2a7bd77c3021bb492ccb78855482312bca4b.tar.xz
ipxe-ec0e2a7bd77c3021bb492ccb78855482312bca4b.zip
[xhci] Do not release ownership back to BIOS when booting an OS
xHCI (and EHCI) nominally provide a mechanism for releasing ownership of the host controller back to the BIOS, which can then potentially restore legacy USB keyboard functionality. This is a rarely used code path, since most operating systems claim ownership and never attempt to later return to the BIOS. On some systems (observed with a Lenovo X1 Carbon), this code path leads to obscure and interesting bugs: if the xHCI and EHCI controllers are both claimed and later released back to the BIOS, then a subsequent call to INT 16,0305 to set the keyboard repeat rate to a non-default value will lock the system. Obscure though this sequence of operations may sound, it is exactly what happens when using iPXE to boot a Linux kernel via a USB network card. There is old and probably unwanted code in Linux's arch/x86/boot/main.c which sets the keyboard repeat rate (with the accompanying comment "Set keyboard repeat rate (why?)"). When booting Linux via a USB network card on a Lenovo X1 Carbon, the system therefore locks up immediately after jumping to the kernel's entry point. Work around this problem by preventing the release of ownership back to the BIOS if it is known that we are shutting down to boot an OS. This should allow legacy USB keyboard functionality to be restored if the user chooses to exit iPXE, while avoiding the rarely used code paths (and corresponding BIOS bugs) if the user chooses instead to boot an OS. Signed-off-by: Michael Brown <mcb30@ipxe.org>
Diffstat (limited to 'src/drivers/usb')
-rw-r--r--src/drivers/usb/xhci.c27
1 files changed, 27 insertions, 0 deletions
diff --git a/src/drivers/usb/xhci.c b/src/drivers/usb/xhci.c
index 6306e158..a71d1278 100644
--- a/src/drivers/usb/xhci.c
+++ b/src/drivers/usb/xhci.c
@@ -34,6 +34,7 @@ FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
#include <ipxe/umalloc.h>
#include <ipxe/pci.h>
#include <ipxe/usb.h>
+#include <ipxe/init.h>
#include <ipxe/profile.h>
#include "xhci.h"
@@ -521,6 +522,9 @@ static inline void xhci_dump_port ( struct xhci_device *xhci,
******************************************************************************
*/
+/** Prevent the release of ownership back to BIOS */
+static int xhci_legacy_prevent_release;
+
/**
* Initialise USB legacy support
*
@@ -610,6 +614,12 @@ static void xhci_legacy_release ( struct xhci_device *xhci ) {
if ( ! xhci->legacy )
return;
+ /* Do nothing if releasing ownership is prevented */
+ if ( xhci_legacy_prevent_release ) {
+ DBGC ( xhci, "XHCI %p not releasing ownership to BIOS\n", xhci);
+ return;
+ }
+
/* Release ownership */
writeb ( 0, xhci->cap + xhci->legacy + XHCI_USBLEGSUP_OS );
DBGC ( xhci, "XHCI %p released ownership to BIOS\n", xhci );
@@ -3190,3 +3200,20 @@ struct pci_driver xhci_driver __pci_driver = {
.probe = xhci_probe,
.remove = xhci_remove,
};
+
+/**
+ * Prepare for exit
+ *
+ * @v booting System is shutting down for OS boot
+ */
+static void xhci_shutdown ( int booting ) {
+ /* If we are shutting down to boot an OS, then prevent the
+ * release of ownership back to BIOS.
+ */
+ xhci_legacy_prevent_release = booting;
+}
+
+/** Startup/shutdown function */
+struct startup_fn xhci_startup __startup_fn ( STARTUP_LATE ) = {
+ .shutdown = xhci_shutdown,
+};