3 pci_table=/etc/pl_pcitable
5 loaded_module_list=/tmp/loadedmodules
7 echo "pl_hwinit: loading applicable modules"
9 echo > $loaded_module_list
11 # this will contain lines of device_id:vendor_id (no 0x)
12 system_devices=$(lspci -n | cut -d " " -f4)
14 for device in $system_devices; do
16 # now vendor_id and device_id are broken apart
17 vendor_id=$(echo $device | cut -d ":" -f1)
18 device_id=$(echo $device | cut -d ":" -f2)
20 # either exactly match vendor:device, or a vendor:ffff (let the module
21 # figure out if it can be used for this device), or ffff:device
22 # (not sure if this is legal, but shows up in the pci map)
23 mods=$(grep -i "\($vendor_id:ffff\|$vendor_id:$device_id\|ffff:$device_id\)" \
24 $pci_table | cut -d " " -f1)
26 for module in $mods; do
27 if [ -n "$module" ]; then
28 echo "pl_hwinit: found and loading module $module"
29 /sbin/modprobe $module
30 echo $module >> $loaded_module_list
35 # just in case, look for any modules that are ffff:ffff and load them
36 mods=$(grep -i "ffff:ffff" $pci_table | cut -d " " -f1)
37 for module in $mods; do
38 if [ -n "$module" ]; then
39 echo "pl_hwinit: found and loading wild module $module"
40 /sbin/modprobe $module
44 # sd_mod won't get loaded automatically
45 echo "pl_hwinit: loading sd_mod"
48 # load usb_storage to support node conf files on flash disks
49 echo "pl_hwinit: loading usb_storage"
50 /sbin/modprobe usb_storage
52 echo "pl_hwinit: loading floppy device driver"
55 # always wait a bit between loading the usb drivers, and checking /sys/
56 # for usb devices (this isn't necessarily for waiting for mass storage files,
58 echo "pl_hwinit: waiting for usb system to initialize."
61 # sometimes, flash devices take a while to initialize. in fact, the kernel
62 # intentionally waits 5 seconds for a device to 'settle'. some take even longer
63 # to show up. if there are any mass storage devices on the system, try to
64 # delay until they come online, up to a max delay of 30s.
66 # the way this will be done is to look for files in /sys/devices that are named
67 # 'bInterfaceClass', these will be a list of the usb devices on the system, and
68 # their primary usb device interface class ids. The base directory these files
69 # exist in will be the full path to the /sys/device entry for that device.
70 # for each mass storage devices (they have an interface class value of 08),
71 # we wait for a new symbolic link named 'driver' to exist in that directory,
72 # indicating the kernel loaded a driver for that device.
74 # usb interface class id for mass storage
75 INTERFACE_CLASS_MASS_STORAGE="08"
77 # how long to wait in seconds before continuing on if devices
81 # low long in seconds to wait between checks
82 PER_CHECK_USB_WAIT_TIME=5
85 # find out if the device identified by the /sys dir has a module
86 # loaded for it. check for a symlink in the dir named driver.
87 function does_device_dir_have_driver()
89 if [[ -h "$1/driver" ]]; then
97 for interface_class_file in `/bin/find /sys/devices -name 'bInterfaceClass'`; do
98 interface_class=`cat $interface_class_file`
99 if [[ "$interface_class" == $INTERFACE_CLASS_MASS_STORAGE ]]; then
100 wait_dev_list="$wait_dev_list "`/bin/dirname $interface_class_file`
104 if [[ -n "$wait_dev_list" ]]; then
105 echo "pl_hwinit: found USB mass storage device(s). Attempting to wait"
106 echo "pl_hwinit: up to $MAX_USB_WAIT_TIME seconds for them to come online."
110 while [[ $total_wait_time < $MAX_USB_WAIT_TIME ]]; do
112 total_wait_time=$(($total_wait_time+$PER_CHECK_USB_WAIT_TIME))
114 echo "pl_hwinit: waiting $PER_CHECK_USB_WAIT_TIME seconds."
115 /bin/sleep $PER_CHECK_USB_WAIT_TIME
118 for device_dir in $wait_dev_list; do
119 does_device_dir_have_driver $device_dir
120 if [[ "$?" -eq 0 ]]; then
125 if [[ $all_devices_online -eq 1 ]]; then
127 echo "pl_hwinit: looks like the devices are now online."
130 echo "pl_hwinit: not all devices online yet, waiting..."
134 if [[ $success -eq 1 ]]; then
135 echo "pl_hwinit: Succesfully waited for USB mass storage devices"
136 echo "pl_hwinit: to come online."
138 echo "pl_hwinit: One or more USB mass storage devices did not"
139 echo "pl_hwinit: initialize in time. Continuing anyway."