Commit af358dcd authored by Randy Dunlap's avatar Randy Dunlap Committed by Linus Torvalds

[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.
parent 9a583d70
...@@ -62,6 +62,9 @@ int usb_hcd_pci_probe (struct pci_dev *dev, const struct pci_device_id *id) ...@@ -62,6 +62,9 @@ int usb_hcd_pci_probe (struct pci_dev *dev, const struct pci_device_id *id)
int retval, region; int retval, region;
char buf [8], *bufp = buf; char buf [8], *bufp = buf;
if (usb_disabled())
return -ENODEV;
if (!id || !(driver = (struct hc_driver *) id->driver_data)) if (!id || !(driver = (struct hc_driver *) id->driver_data))
return -EINVAL; return -EINVAL;
......
...@@ -50,6 +50,9 @@ extern int usb_major_init(void); ...@@ -50,6 +50,9 @@ extern int usb_major_init(void);
extern void usb_major_cleanup(void); 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) static int generic_probe (struct device *dev)
{ {
...@@ -167,6 +170,9 @@ int usb_register(struct usb_driver *new_driver) ...@@ -167,6 +170,9 @@ int usb_register(struct usb_driver *new_driver)
{ {
int retval = 0; int retval = 0;
if (nousb)
return -ENODEV;
new_driver->driver.name = (char *)new_driver->name; new_driver->driver.name = (char *)new_driver->name;
new_driver->driver.bus = &usb_bus_type; new_driver->driver.bus = &usb_bus_type;
new_driver->driver.probe = usb_device_probe; new_driver->driver.probe = usb_device_probe;
...@@ -1338,11 +1344,37 @@ struct bus_type usb_bus_type = { ...@@ -1338,11 +1344,37 @@ struct bus_type usb_bus_type = {
.hotplug = usb_hotplug, .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 <nousb>
*/
int usb_disabled(void)
{
return nousb;
}
/* /*
* Init * Init
*/ */
static int __init usb_init(void) static int __init usb_init(void)
{ {
if (nousb) {
info("USB support disabled\n");
return 0;
}
bus_register(&usb_bus_type); bus_register(&usb_bus_type);
usb_major_init(); usb_major_init();
usbfs_init(); usbfs_init();
...@@ -1358,6 +1390,10 @@ static int __init usb_init(void) ...@@ -1358,6 +1390,10 @@ static int __init usb_init(void)
*/ */
static void __exit usb_exit(void) static void __exit usb_exit(void)
{ {
/* This will matter if shutdown/reboot does exitcalls. */
if (nousb)
return;
remove_driver(&usb_generic_driver); remove_driver(&usb_generic_driver);
usb_major_cleanup(); usb_major_cleanup();
usbfs_cleanup(); usbfs_cleanup();
...@@ -1377,6 +1413,7 @@ EXPORT_SYMBOL(usb_epnum_to_ep_desc); ...@@ -1377,6 +1413,7 @@ EXPORT_SYMBOL(usb_epnum_to_ep_desc);
EXPORT_SYMBOL(usb_register); EXPORT_SYMBOL(usb_register);
EXPORT_SYMBOL(usb_deregister); EXPORT_SYMBOL(usb_deregister);
EXPORT_SYMBOL(usb_disabled);
EXPORT_SYMBOL(usb_device_probe); EXPORT_SYMBOL(usb_device_probe);
EXPORT_SYMBOL(usb_device_remove); EXPORT_SYMBOL(usb_device_remove);
......
...@@ -985,6 +985,9 @@ MODULE_LICENSE ("GPL"); ...@@ -985,6 +985,9 @@ MODULE_LICENSE ("GPL");
static int __init init (void) static int __init init (void)
{ {
dbg (DRIVER_INFO); dbg (DRIVER_INFO);
if (usb_disabled())
return -ENODEV;
dbg ("block sizes: qh %Zd qtd %Zd itd %Zd sitd %Zd", dbg ("block sizes: qh %Zd qtd %Zd itd %Zd sitd %Zd",
sizeof (struct ehci_qh), sizeof (struct ehci_qtd), sizeof (struct ehci_qh), sizeof (struct ehci_qtd),
sizeof (struct ehci_itd), sizeof (struct ehci_sitd)); sizeof (struct ehci_itd), sizeof (struct ehci_sitd));
......
...@@ -1321,6 +1321,9 @@ static int __init hci_hcd_init (void) ...@@ -1321,6 +1321,9 @@ static int __init hci_hcd_init (void)
int ret; int ret;
DBGFUNC ("Enter hci_hcd_init\n"); DBGFUNC ("Enter hci_hcd_init\n");
if (usb_disabled())
return -ENODEV;
ret = hc_found_hci (base_addr, data_reg_addr, irq); ret = hc_found_hci (base_addr, data_reg_addr, irq);
return ret; return ret;
......
...@@ -365,6 +365,9 @@ static struct pci_driver ohci_pci_driver = { ...@@ -365,6 +365,9 @@ static struct pci_driver ohci_pci_driver = {
static int __init ohci_hcd_pci_init (void) static int __init ohci_hcd_pci_init (void)
{ {
dbg (DRIVER_INFO " (PCI)"); dbg (DRIVER_INFO " (PCI)");
if (usb_disabled())
return -ENODEV;
dbg ("block sizes: ed %d td %d", dbg ("block sizes: ed %d td %d",
sizeof (struct ed), sizeof (struct td)); sizeof (struct ed), sizeof (struct td));
return pci_module_init (&ohci_pci_driver); return pci_module_init (&ohci_pci_driver);
......
...@@ -23,6 +23,8 @@ ...@@ -23,6 +23,8 @@
#error "This file is SA-1111 bus glue. CONFIG_SA1111 must be defined." #error "This file is SA-1111 bus glue. CONFIG_SA1111 must be defined."
#endif #endif
extern int usb_disabled(void);
/*-------------------------------------------------------------------------*/ /*-------------------------------------------------------------------------*/
static void sa1111_start_hc(struct sa1111_dev *dev) static void sa1111_start_hc(struct sa1111_dev *dev)
...@@ -355,6 +357,9 @@ static int ohci_hcd_sa1111_drv_probe(struct device *_dev) ...@@ -355,6 +357,9 @@ static int ohci_hcd_sa1111_drv_probe(struct device *_dev)
struct usb_hcd *hcd = NULL; struct usb_hcd *hcd = NULL;
int ret; int ret;
if (usb_disabled())
return -ENODEV;
ret = usb_hcd_sa1111_probe(&ohci_sa1111_hc_driver, &hcd, dev); ret = usb_hcd_sa1111_probe(&ohci_sa1111_hc_driver, &hcd, dev);
if (ret == 0) if (ret == 0)
......
...@@ -2484,6 +2484,9 @@ static int __init uhci_hcd_init(void) ...@@ -2484,6 +2484,9 @@ static int __init uhci_hcd_init(void)
info(DRIVER_DESC " " DRIVER_VERSION); info(DRIVER_DESC " " DRIVER_VERSION);
if (usb_disabled())
return -ENODEV;
if (debug) { if (debug) {
errbuf = kmalloc(ERRBUF_LEN, GFP_KERNEL); errbuf = kmalloc(ERRBUF_LEN, GFP_KERNEL);
if (!errbuf) if (!errbuf)
......
...@@ -670,6 +670,7 @@ extern void usb_deregister_dev(int num_minors, int start_minor); ...@@ -670,6 +670,7 @@ extern void usb_deregister_dev(int num_minors, int start_minor);
extern int usb_device_probe(struct device *dev); extern int usb_device_probe(struct device *dev);
extern int usb_device_remove(struct device *dev); extern int usb_device_remove(struct device *dev);
extern int usb_disabled(void);
/* -------------------------------------------------------------------------- */ /* -------------------------------------------------------------------------- */
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment