From mboxrd@z Thu Jan 1 00:00:00 1970 From: Greg KH Date: Thu, 22 Jan 2004 22:40:46 +0000 Subject: Re: how to determine physical bus of a device and find it there Message-Id: <20040122224046.GL15458@kroah.com> List-Id: References: <20040120025230.GA26199@vrfy.org> In-Reply-To: <20040120025230.GA26199@vrfy.org> MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit To: linux-hotplug@vger.kernel.org On Tue, Jan 20, 2004 at 03:52:30AM +0100, Kay Sievers wrote: > > Hi, > I want to collect all possible attributes of a device with the udevinfo > program. This issue is also still unresolved with udev. > > We need to determine the device on its physical bus not only the logical. > Here is a example for a usb-storage device with its logical 'scsi' and > physical 'usb' bus: > > First I look in the hotplug provided directory and I find: > > /sys/block/sda > > SYSFS_dev="8:0" > SYSFS_range="16" > SYSFS_size="31360" > SYSFS_stat=" 12 0 96 87 0 0 0 0 0 87 87" > > then following the "device" link, I get on the scsi bus > /sys/devices/pci0000:00/0000:00:1d.0/usb1/1-1/1-1:1.0/host5/5:0:0:0 > > SYSFS_detach_state="0" > SYSFS_type="0" > SYSFS_vendor="SMSC " > SYSFS_device_blocked="0" > SYSFS_queue_depth="1" > SYSFS_scsi_level="3" > SYSFS_model="USB 2 HS-CF" > SYSFS_rev="1.25" > SYSFS_online="1" > > but the really interesting attributes are on the usb bus: > /sys/devices/pci0000:00/0000:00:1d.0/usb1/1-1': > > SYSFS_detach_state="0" > SYSFS_bNumConfigurations="1" > SYSFS_bNumInterfaces=" 1" > SYSFS_bConfigurationValue="1" > SYSFS_bmAttributes="80" > SYSFS_bMaxPower=" 48mA" > SYSFS_idVendor="0424" > SYSFS_idProduct="20fc" > SYSFS_bcdDevice="0125" > SYSFS_bDeviceClass="00" > SYSFS_bDeviceSubClass="00" > SYSFS_bDeviceProtocol="00" > SYSFS_speed="12" > SYSFS_manufacturer="SMSC" > SYSFS_product="USB 2 Flash Media Device" > SYSFS_serial="0305037000C2" > > > So, how do I reliable get there? We need to set up a "stack" (for lack of a better word) of sysfs devices. We can now do this with some libsysfs calls. So for your example, we would create the following device "stack" - class device "scsi" located at /sys/block/sda - main device structure on bus "scsi" at /sys/devices/pci0000:00/0000:00:1d.0/usb1/1-1/1-1:1.0/host5/5:0:0:0 - device of bus type "scsi host" at /sys/devices/pci0000:00/0000:00:1d.0/usb1/1-1/1-1:1.0/host5 - device of bus type "usb" at /sys/devices/pci0000:00/0000:00:1d.0/usb1/1-1/1-1:1.0 - device of bus type "usb" at /sys/devices/pci0000:00/0000:00:1d.0/usb1/1-1 - device of bus type "usb" at /sys/devices/pci0000:00/0000:00:1d.0/usb1 - device of bus type "pci" at /sys/devices/pci0000:00/0000:00:1d.0 - device of bus type "pci" at /sys/devices/pci0000:00 Note that the first usb device we find is really a usb interface device, not the main usb device itself. That is going to mess with some people's minds until they realize that usb drivers bind to usb interfaces, not the the device itself (a usb device may have lots of usb interfaces, all with different drivers, like a speaker with a audio and a hid driver bound to different interfaces.) So what udev needs to do is look at each device along that "stack" in order to get a match. If a user specifies a idProduct sysfs file that is on the usb device at /sys/devices/pci0000:00/0000:00:1d.0/usb1/1-1/1-1:1.0 we should be able to match that up with this scsi block device, if so asked. It would also "solve" the problem where someone wanted to specify the idProduct and idVendor for a usb printer, but udev couldn't find it. Does that make more sense now? thanks, greg k-h ------------------------------------------------------- The SF.Net email is sponsored by EclipseCon 2004 Premiere Conference on Open Tools Development and Integration See the breadth of Eclipse activity. February 3-5 in Anaheim, CA. http://www.eclipsecon.org/osdn _______________________________________________ Linux-hotplug-devel mailing list http://linux-hotplug.sourceforge.net Linux-hotplug-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/linux-hotplug-devel