ChangeSet 1.738.5.16, 2002/10/11 15:02:46-07:00, randy.dunlap@verizon.net [PATCH] "nousb" for in-kernel USB Here's the updated "nousb" patch for vanilla 2.5.41. It applies with 2 small offsets to 2.5.41-bk3. diff -Nru a/drivers/usb/core/hcd-pci.c b/drivers/usb/core/hcd-pci.c --- a/drivers/usb/core/hcd-pci.c Sun Oct 13 17:09:27 2002 +++ b/drivers/usb/core/hcd-pci.c Sun Oct 13 17:09:27 2002 @@ -62,6 +62,9 @@ int retval, region; char buf [8], *bufp = buf; + if (usb_disabled()) + return -ENODEV; + if (!id || !(driver = (struct hc_driver *) id->driver_data)) return -EINVAL; diff -Nru a/drivers/usb/core/usb.c b/drivers/usb/core/usb.c --- a/drivers/usb/core/usb.c Sun Oct 13 17:09:27 2002 +++ b/drivers/usb/core/usb.c Sun Oct 13 17:09:27 2002 @@ -50,6 +50,9 @@ extern void usb_major_cleanup(void); +int nousb; /* Disable USB when built into kernel image */ + /* Not honored on modular build */ + static int generic_probe (struct device *dev) { @@ -167,6 +170,9 @@ { int retval = 0; + if (nousb) + return -ENODEV; + new_driver->driver.name = (char *)new_driver->name; new_driver->driver.bus = &usb_bus_type; new_driver->driver.probe = usb_device_probe; @@ -1338,11 +1344,37 @@ .hotplug = usb_hotplug, }; +#ifndef MODULE + +static int __init usb_setup_disable(char *str) +{ + nousb = 1; + return 1; +} + +/* format to disable USB on kernel command line is: nousb */ +__setup("nousb", usb_setup_disable); + +#endif + +/* + * for external read access to + */ +int usb_disabled(void) +{ + return nousb; +} + /* * Init */ static int __init usb_init(void) { + if (nousb) { + info("USB support disabled\n"); + return 0; + } + bus_register(&usb_bus_type); usb_major_init(); usbfs_init(); @@ -1358,6 +1390,10 @@ */ static void __exit usb_exit(void) { + /* This will matter if shutdown/reboot does exitcalls. */ + if (nousb) + return; + remove_driver(&usb_generic_driver); usb_major_cleanup(); usbfs_cleanup(); @@ -1377,6 +1413,7 @@ EXPORT_SYMBOL(usb_register); EXPORT_SYMBOL(usb_deregister); +EXPORT_SYMBOL(usb_disabled); EXPORT_SYMBOL(usb_device_probe); EXPORT_SYMBOL(usb_device_remove); diff -Nru a/drivers/usb/host/ehci-hcd.c b/drivers/usb/host/ehci-hcd.c --- a/drivers/usb/host/ehci-hcd.c Sun Oct 13 17:09:27 2002 +++ b/drivers/usb/host/ehci-hcd.c Sun Oct 13 17:09:27 2002 @@ -985,6 +985,9 @@ static int __init init (void) { dbg (DRIVER_INFO); + if (usb_disabled()) + return -ENODEV; + dbg ("block sizes: qh %Zd qtd %Zd itd %Zd sitd %Zd", sizeof (struct ehci_qh), sizeof (struct ehci_qtd), sizeof (struct ehci_itd), sizeof (struct ehci_sitd)); diff -Nru a/drivers/usb/host/hc_sl811.c b/drivers/usb/host/hc_sl811.c --- a/drivers/usb/host/hc_sl811.c Sun Oct 13 17:09:27 2002 +++ b/drivers/usb/host/hc_sl811.c Sun Oct 13 17:09:27 2002 @@ -1321,6 +1321,9 @@ int ret; DBGFUNC ("Enter hci_hcd_init\n"); + if (usb_disabled()) + return -ENODEV; + ret = hc_found_hci (base_addr, data_reg_addr, irq); return ret; diff -Nru a/drivers/usb/host/ohci-pci.c b/drivers/usb/host/ohci-pci.c --- a/drivers/usb/host/ohci-pci.c Sun Oct 13 17:09:27 2002 +++ b/drivers/usb/host/ohci-pci.c Sun Oct 13 17:09:27 2002 @@ -365,6 +365,9 @@ static int __init ohci_hcd_pci_init (void) { dbg (DRIVER_INFO " (PCI)"); + if (usb_disabled()) + return -ENODEV; + dbg ("block sizes: ed %d td %d", sizeof (struct ed), sizeof (struct td)); return pci_module_init (&ohci_pci_driver); diff -Nru a/drivers/usb/host/ohci-sa1111.c b/drivers/usb/host/ohci-sa1111.c --- a/drivers/usb/host/ohci-sa1111.c Sun Oct 13 17:09:27 2002 +++ b/drivers/usb/host/ohci-sa1111.c Sun Oct 13 17:09:27 2002 @@ -23,6 +23,8 @@ #error "This file is SA-1111 bus glue. CONFIG_SA1111 must be defined." #endif +extern int usb_disabled(void); + /*-------------------------------------------------------------------------*/ static void sa1111_start_hc(struct sa1111_dev *dev) @@ -354,6 +356,9 @@ struct sa1111_dev *dev = SA1111_DEV(_dev); struct usb_hcd *hcd = NULL; int ret; + + if (usb_disabled()) + return -ENODEV; ret = usb_hcd_sa1111_probe(&ohci_sa1111_hc_driver, &hcd, dev); diff -Nru a/drivers/usb/host/uhci-hcd.c b/drivers/usb/host/uhci-hcd.c --- a/drivers/usb/host/uhci-hcd.c Sun Oct 13 17:09:27 2002 +++ b/drivers/usb/host/uhci-hcd.c Sun Oct 13 17:09:27 2002 @@ -2484,6 +2484,9 @@ info(DRIVER_DESC " " DRIVER_VERSION); + if (usb_disabled()) + return -ENODEV; + if (debug) { errbuf = kmalloc(ERRBUF_LEN, GFP_KERNEL); if (!errbuf) diff -Nru a/include/linux/usb.h b/include/linux/usb.h --- a/include/linux/usb.h Sun Oct 13 17:09:27 2002 +++ b/include/linux/usb.h Sun Oct 13 17:09:27 2002 @@ -670,6 +670,7 @@ extern int usb_device_probe(struct device *dev); extern int usb_device_remove(struct device *dev); +extern int usb_disabled(void); /* -------------------------------------------------------------------------- */