driverfs support for USB
PATCH 1/1 driverfs support for USB
Hi,
Here's a first cut at adding driverfs support to the USB core code. This patch is against 2.5.3-pre5. I've tested this out with the ehci-hcd and uhci drivers, and everything seems to work ok (it doesn't oops for me anymore :)
Right now all devices show up under the pci usb controller directory, just like usbfs works. I'll be changing things so that hubs are iobus structures too, which should allow us to show the topology of the trees correctly (unless Pat changes all devices to be iobusses too :)
Pat,
You need to export the put_device and put_iobus functions. The end of this patch has that fix. Also, put_iobus doesn't seem to remove the directory that iobus_register created (but a later call to iobus_register() seems to place everything in the same place again.) Is this the correct thing that should be happening?
Just to show what this looks like, here is what driverfs looks like on my box right now (device pci0/pci1/usb/002 is a hub that device 003 is hanging off of).
[greg@soap x]$ tree
.
`-- root
`-- pci0
|-- 00:00.0
| |-- power
| `-- status
|-- 00:01.0
| |-- power
| `-- status
|-- 00:1e.0
| |-- power
| `-- status
|-- 00:1f.0
| |-- power
| `-- status
|-- 00:1f.1
| |-- power
| `-- status
|-- 00:1f.2
| |-- power
| `-- status
|-- 00:1f.3
| |-- power
| `-- status
|-- 00:1f.5
| |-- power
| `-- status
|-- pci1
| |-- 01:08.0
| | |-- power
| | `-- status
| |-- 01:0d.2
| | |-- power
| | `-- status
| `-- usb
| |-- 002
| | |-- power
| | `-- status
| `-- 003
| |-- power
| `-- status
|-- pci2
| `-- 02:00.0
| |-- power
| `-- status
`-- usb
`-- 002
|-- power
`-- statusIf anyone has any problems or fixes to this patch, please let me know.
thanks,
greg k-h
drivers/usb/hcd.c +6 -0
@@ -666,6 +666,12 @@if ((retval = driver->start (hcd)) <0 )usb_hcd_pci_remove (dev); +/* initialize the iobus info for this usb pci device */ + bus->iobus.self = &dev->dev; + bus->iobus.parent = bus->iobus.self->parent; +strcpy (bus->iobus.bus_id,"usb" ); +iobus_register (&bus->iobus); +return retval; }EXPORT_SYMBOL (usb_hcd_pci_probe);
drivers/usb/hub.c +9 -1
@@ -722,8 +722,16 @@ dev->bus->busnum, dev->devpath, dev->devnum);/* Run it through the hoops (find a driver, etc) */ -if (!usb_new_device (dev)) +if (!usb_new_device (dev)) { +/* put the device in the global device tree */ + dev->dev.parent = &dev->bus->iobus; +sprintf (&dev->dev.name[0 ],"USB device %04x:%04x" , + dev->descriptor.idVendor, + dev->descriptor.idProduct); +sprintf (&dev->dev.bus_id[0 ],"%03d" , dev->devnum); +device_register (&dev->dev); goto done; + }/* Free the configuration if there was an error */ usb_free_dev (dev);
drivers/usb/uhci.c +6 -0
@@ -2843,6 +2847,12 @@ retval = -ENOMEM ; goto err_start_root_hub; } + +/* initialize the iobus info for this usb pci device */ + bus->iobus.self = &dev->dev; + bus->iobus.parent = bus->iobus.self->parent; +strcpy (bus->iobus.bus_id,"usb" ); +iobus_register (&bus->iobus);return 0 ;
drivers/usb/usb-ohci.c +7 -0
@@ -2508,6 +2508,13 @@#ifdef DEBUG ohci_dump (ohci,1 );#endif + +/* initialize the iobus info for this usb pci device */ + ohci->bus->iobus.self = &dev->dev; + ohci->bus->iobus.parent = ohci->bus->iobus.self->parent; +strcpy (ohci->bus->iobus.bus_id,"usb" ); +iobus_register (&ohci->bus->iobus); +return 0 ; }
drivers/usb/usb-uhci.c +6 -0
@@ -3015,6 +3027,12 @@//chain new uhci device into global list pci_set_drvdata (dev, s); devs=s; + +/* initialize the iobus info for this usb pci device */ + bus->iobus.self = &dev->dev; + bus->iobus.parent = bus->iobus.self->parent; +strcpy (bus->iobus.bus_id,"usb" ); +iobus_register (&bus->iobus);return 0 ; }
drivers/usb/usb.c +2 -0
@@ -502,6 +503,7 @@up (&usb_bus_list_lock);usbfs_remove_bus (bus); +put_iobus (&bus->iobus);clear_bit (bus->busnum, busmap.busmap);
@@ -1924,6 +1926,7 @@if (dev->devnum >0 ) {clear_bit (dev->devnum, &dev->bus->devmap.devicemap);usbfs_remove_device (dev); +put_device (&dev->dev); }/* Free up the device itself */
include/linux/usb.h +6 -0
@@ -1,6 +1,8 @@#ifndef __LINUX_USB_H#define __LINUX_USB_H +#include <linux/device.h> +/* USB constants */ /*
@@ -935,6 +938,8 @@struct dentry *dentry;/* usbfs dentry entry for the bus */ atomic_t refcnt; + +struct iobus iobus;/* Generic device interface */ };extern struct usb_bus *usb_alloc_bus (struct usb_operations *);
@@ -1037,6 +1042,8 @@struct usb_device *parent;struct usb_bus *bus;/* Bus we're part of */ +struct device dev;/* Generic device interface */ +struct usb_device_descriptor descriptor;/* Descriptor */ struct usb_config_descriptor *config;/* All of the configs */ struct usb_config_descriptor *actconfig;/* the active configuration */
kernel/device.c +3 -1
@@ -308,7 +308,7 @@ }/** -* iobus_unregister - remove bus and children from device tree +* put_iobus - remove bus and children from device tree * @bus: pointer to bus structure * * Remove device from parent's list of children and decrement
@@ -521,7 +521,9 @@__setup ("device=" ,device_setup);EXPORT_SYMBOL (device_register); +EXPORT_SYMBOL (put_device);EXPORT_SYMBOL (device_create_file);EXPORT_SYMBOL (device_remove_file);EXPORT_SYMBOL (iobus_register); +EXPORT_SYMBOL (put_iobus);EXPORT_SYMBOL (device_driver_init);
Hi there.
Quoted 11 lines · Greg KH
Hi,
Here's a first cut at adding driverfs support to the USB core code. This patch is against 2.5.3-pre5. I've tested this out with the ehci-hcd and uhci drivers, and everything seems to work ok (it doesn't oops for me anymore :)
Right now all devices show up under the pci usb controller directory, just like usbfs works. I'll be changing things so that hubs are iobus structures too, which should allow us to show the topology of the trees correctly (unless Pat changes all devices to be iobusses too :)
This looks good; thanks. A couple of things:
- For the record, in order to register a device in the device tree, it must know it's parent and have a unique, non-NULL ->bus_id. (Unique only for the on which it resides).
For an iobus to be registered, it must have a unique, non-NULL bus_id. If possible, it should know its parent and self. If an iobus is an orphan, it gets adopted by the system root. If it doesn't know it's self, well it has identity problems, but nothing fatal. :)
- You're naming every usb iobus 'usb'. Is it possible for there to be more than one usb controller on the same bus?
Quoted 6 lines
Pat,
You need to export theput_deviceandput_iobusfunctions. The end of this patch has that fix. Also,put_iobusdoesn't seem to remove the directory thatiobus_registercreated (but a later call toiobus_register()seems to place everything in the same place again.) Is this the correct thing that should be happening?
Thanks for catching that. It's fixed in my tree. I have a couple of other changes pending with Linus, so I'm waiting for him to release -pre6 to sync before I send him anything else :)
-pat
Hi!
Quoted 41 lines
.
--- root--- pci0 |-- 00:00.0 | |-- power | --- status |-- 00:01.0 | |-- power | --- status |-- 00:1e.0 | |-- power | --- status |-- 00:1f.0 | |-- power | --- status |-- 00:1f.1 | |-- power | --- status |-- 00:1f.2 | |-- power | --- status |-- 00:1f.3 | |-- power | --- status |-- 00:1f.5 | |-- power | --- status |-- pci1 | |-- 01:08.0 | | |-- power | | --- status | |-- 01:0d.2 | | |-- power | | --- status | --- usb | |-- 002 | | |-- power | | --- status | --- 003 | |-- power | --- status
Quoted 8 lines
|-- pci2
| --- 02:00.0
| |-- power
| --- status
--- usb
--- 002
|-- power
--- statusShould not usb bus hang off some pci device (uhci/ohci?)
Pavel
Signature · 2 lines
Philips Velo 1: 1"x4"x8", 300gram, 60, 12MB, 40bogomips, linux, mutt, details at http://atrey.karlin.mff.cuni.cz/~pavel/velo/index.html.
Quoted 18 lines · Pavel Machek
Hi!
Quoted 15 lines
.
|-- pci1 | |-- 01:08.0 | | |-- power | | --- status | |-- 01:0d.2 | | |-- power | | --- status | --- usb | |-- 002 | | |-- power | | --- status | --- 003 | |-- power | --- status
Quoted 1 line
Should not usb bus hang off some pci device (uhci/ohci?)
You are correct, The "usb" device should hang off of the actual pci device that is the USB host controller. But due to the current split between iobus and devices in the device core code, a usb bus has to attach to the pci bus, which places it in the tree like you see here.
So to be correct the above portion of the tree should look something like:
|-- pci1
| |-- 01:08.0
| | |-- power
| | --- status
| |-- 01:0d.2
| |-- power
| |-- status
| --- usb
| |-- 002
| |-- power
| |-- status
| --- 003
| |-- power
| --- statusIt's still a work in progress :)
thanks,
greg k-h