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 # sometimes, flash devices take a while to initialize. in fact, the kernel
53 # intentionally waits 5 seconds for a device to 'settle'. some take even longer
54 # to show up. if there are any mass storage devices on the system, try to
55 # delay until they come online, up to a max delay of 30s.
57 # the way this will be done is to look for files in /sys/devices that are named
58 # 'bInterfaceClass', these will be a list of the usb devices on the system, and
59 # their primary usb device interface class ids. The base directory these files
60 # exist in will be the full path to the /sys/device entry for that device.
61 # for each mass storage devices (they have an interface class value of 08),
62 # we wait for a new symbolic link named 'driver' to exist in that directory,
63 # indicating the kernel loaded a driver for that device.
65 # usb interface class id for mass storage
66 INTERFACE_CLASS_MASS_STORAGE="08"
68 # how long to wait in seconds before continuing on if devices
72 # low long in seconds to wait between checks
73 PER_CHECK_USB_WAIT_TIME=5
76 # find out if the device identified by the /sys dir has a module
77 # loaded for it. check for a symlink in the dir named driver.
78 function does_device_dir_have_driver()
80 if [[ -h "$1/driver" ]]; then
88 for interface_class_file in `/bin/find /sys/devices -name 'bInterfaceClass'`; do
89 interface_class=`cat $interface_class_file`
90 if [[ "$interface_class" == $INTERFACE_CLASS_MASS_STORAGE ]]; then
91 wait_dev_list="$wait_dev_list "`/bin/dirname $interface_class_file`
95 if [[ -n "$wait_dev_list" ]]; then
96 echo "pl_hwinit: found USB mass storage device(s). Attempting to wait"
97 echo "pl_hwinit: up to $MAX_USB_WAIT_TIME seconds for them to come online."
101 while [[ $total_wait_time < $MAX_USB_WAIT_TIME ]]; do
103 total_wait_time=$(($total_wait_time+$PER_CHECK_USB_WAIT_TIME))
105 echo "pl_hwinit: waiting $PER_CHECK_USB_WAIT_TIME seconds."
106 sleep $PER_CHECK_USB_WAIT_TIME
109 for device_dir in $wait_dev_list; do
110 does_device_dir_have_driver $device_dir
111 if [[ "$?" -eq 0 ]]; then
116 if [[ $all_devices_online -eq 1 ]]; then
118 echo "pl_hwinit: looks like the devices are now online."
121 echo "pl_hwinit: not all devices online yet, waiting..."
125 if [[ $success -eq 1 ]]; then
126 echo "pl_hwinit: Succesfully waited for USB mass storage devices"
127 echo "pl_hwinit: to come online."
129 echo "pl_hwinit: One or more USB mass storage devices did not"
130 echo "pl_hwinit: initialize in time. Continuing anyway."
134 echo "pl_hwinit: loading floppy device driver"
135 /sbin/modprobe floppy