david/ipxe
david
/
ipxe
Archived
1
0
Fork 0

[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>
This commit is contained in:
Michael Brown 2015-03-18 11:57:41 +00:00
parent e1feb7bcab
commit ec0e2a7bd7
1 changed files with 27 additions and 0 deletions

View File

@ -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,
};