home *** CD-ROM | disk | FTP | other *** search
/ HAKERIS 11 / HAKERIS 11.ISO / linux / system / LinuxConsole 0.4 / linuxconsole0.4install-en.iso / linuxconsole0.4.lcm / etc / hotplug / pci.agent < prev    next >
Encoding:
Text File  |  2004-03-26  |  3.9 KB  |  170 lines

  1. #!/bin/bash
  2. #
  3. # PCI-specific hotplug policy agent.
  4. #
  5. # This should handle 2.4.* PCI (including Cardbus)  hotplugging,
  6. # with a consistent framework for adding device and driver specific
  7. # treatments.
  8. #
  9. # Kernel Cardbus/PCI params are:
  10. #    
  11. #    ACTION=%s [add or remove]
  12. #    PCI_CLASS=%06X
  13. #    PCI_ID=%04X:%04X
  14. #    PCI_SLOT_NAME=%s
  15. #    PCI_SUBSYS_ID=%04X:%04X
  16. #
  17. # If /proc is mounted, /proc/bus/pci/$PCI_SLOT_NAME is almost the name
  18. # of the binary device descriptor file ... just change ':' to '/'.
  19. #
  20. # On systems using Linux 2.4.* kernels, be sure to use the right
  21. # modutils (2.4.1+).
  22. #
  23. #
  24. # HISTORY:
  25. #
  26. # 26-Feb-2001    Cleanup, support comments (Gioele Barabucci)
  27. # 13-Jan-2001    Initial version of "new" hotplug agent; needs
  28. #        retesting.
  29. # 17-Jan-2001    Update to latest kernel syntax (Dan Zink)
  30. # 15-Feb-2001    Remove use of "<<" (Adam Richter)
  31. #
  32. # $Id: pci.agent,v 1.11 2001/09/07 15:57:39 dbrownell Exp $
  33. #
  34.  
  35. cd /etc/hotplug
  36. . hotplug.functions
  37.  
  38. # generated by modutils, for current 2.4.x kernels
  39. MAP_CURRENT=$MODULE_DIR/modules.pcimap
  40.  
  41. # accumulates list of modules we may care about
  42. DRIVERS=
  43.  
  44. if [ "$PCI_CLASS" = ""  -o "$PCI_CLASS" = "" ]; then
  45.     mesg Bad PCI agent invocation
  46.     exit 1
  47. fi
  48.  
  49. #
  50. # Each modules.usbmap format line corresponds to one entry in a
  51. # MODULE_DEVICE_TABLE(pci,...) declaration in a kernel file.
  52. #
  53. # Think of it as a database column with up to three "match specs"
  54. # to associate kernel modules with particular devices or classes
  55. # of device.  The match specs provide a reasonably good filtering
  56. # mechanism, but some driver probe() routines need to provide
  57. # extra filtering.
  58. #
  59.  
  60. # inputs to the match algorithm, from kernel by way of /sbin/hotplug
  61. declare -i pci_class
  62. declare -i pci_id_vendor pci_id_device
  63. declare -i pci_subid_vendor pci_subid_device
  64.  
  65. pci_convert_vars ()
  66. {
  67.     if [ "$AWK" = "" ]; then
  68.     mesg "can't find awk!"
  69.     exit 1
  70.     fi
  71.  
  72.     pci_class=0x$PCI_CLASS
  73.  
  74.     set `echo $PCI_ID | $AWK -F: '{print "0x" $1, "0x" $2 }'` ''
  75.     pci_id_vendor=$1
  76.     pci_id_device=$2
  77.  
  78.     set `echo $PCI_SUBSYS_ID | $AWK -F: '{print "0x" $1, "0x" $2 }'` ''
  79.     pci_subid_vendor=$1
  80.     pci_subid_device=$2
  81. }
  82.  
  83. declare -i PCI_ANY
  84. PCI_ANY=0xffffffff
  85.  
  86.  
  87. #
  88. # stdin is "modules.pcimap" syntax
  89. # on return, ONE matching module was added to $DRIVERS
  90. #
  91. pci_map_modules ()
  92. {
  93.     # convert the usb_device_id fields to integers as we read them 
  94.     local module ignored
  95.     declare -i vendor device
  96.     declare -i subvendor subdevice
  97.     declare -i class class_mask
  98.     declare -i class_temp
  99.  
  100.     # comment line lists (current) pci_device_id field names
  101.     read ignored
  102.  
  103.     # look at each pci_device_id entry
  104.     # collect one match in $DRIVERS
  105.     while read module vendor device subvendor subdevice class class_mask ignored
  106.     do
  107.     # comments are lines that start with "#" ...
  108.     # be careful, they still get parsed by bash!
  109.     case "$module" in
  110.     \#*) continue ;;
  111.     esac
  112.  
  113.     : checkmatch $module
  114.  
  115.     : vendor $vendor $pci_id_vendor
  116.     if [ $vendor -ne $PCI_ANY -a $vendor -ne $pci_id_vendor ]; then
  117.         continue
  118.     fi
  119.     : device $device $pci_id_device
  120.     if [ $device -ne $PCI_ANY -a $device -ne $pci_id_device ]; then
  121.         continue
  122.     fi
  123.     : sub-vendor $subvendor $pci_subid_vendor
  124.     if [ $subvendor -ne $PCI_ANY -a $subvendor -ne $pci_subid_vendor ]; then
  125.         continue
  126.     fi
  127.     : sub-device $subdevice $pci_subid_device
  128.     if [ $subdevice -ne $PCI_ANY -a $subdevice -ne $pci_subid_device ]; then
  129.         continue
  130.     fi
  131.  
  132.     class_temp="$pci_class & $class_mask"
  133.     if [ $class_temp -eq $class ]; then
  134.         DRIVERS="$module $DRIVERS"
  135.         : drivers $DRIVERS
  136.         break
  137.     fi
  138.     done
  139. }
  140.  
  141.  
  142. #
  143. # What to do with this PCI hotplug event?
  144. #
  145. case $ACTION in
  146.  
  147. add)
  148.     pci_convert_vars
  149.  
  150.     LABEL="PCI slot $PCI_SLOT_NAME"
  151.  
  152.     # on 2.4 systems, modutils maintains MAP_CURRENT
  153.     if [ -r $MAP_CURRENT ]; then
  154.         load_drivers pci $MAP_CURRENT "$LABEL"
  155.     fi
  156.  
  157.     if [ "$DRIVERS" == "" ]; then
  158.     mesg "... no modules for $LABEL"
  159.     exit 2
  160.     fi
  161.  
  162.     ;;
  163.  
  164. *)
  165.     debug_mesg PCI $ACTION event not supported
  166.     exit 1
  167.     ;;
  168.  
  169. esac
  170.