home *** CD-ROM | disk | FTP | other *** search
/ PC Plus SuperCD (UK) 1999 May / pcp151c.iso / misc / src / install / pci-probing / makepciids < prev    next >
Encoding:
Text File  |  1998-01-06  |  2.3 KB  |  90 lines

  1. #/bin/bash
  2. #
  3. # given a good-video.lst or good-eth-scsi.lst, make C source to contain
  4. # the information in a C structure.
  5. #
  6. # assume input file from stdin
  7. # assume that pci.h in /usr/include/linux will work with pci.c which
  8. # the good list was genereated from
  9. #
  10.  
  11. #
  12. # see if they specified a pci.h to use, otherwise try /usr/include/linux/pci.h
  13. #
  14. if [ "$1" = "" ]; then
  15.    pcihin=/usr/include/linux/pci.h
  16. else
  17.    pcihin=$1
  18. fi
  19.  
  20.  
  21. #
  22. # filter pci.h and store in temp file
  23. #
  24. pcihfile=/tmp/pci_h$$
  25. trap 'rm -f $pcihfile; exit' INT TERM
  26.  
  27. sed -n '/\#define/p' < $pcihin > $pcihfile
  28.  
  29. #
  30. # now make template for C code
  31. #
  32. ctemplate=/tmp/pci-ids.h$$
  33.  
  34. trap 'rm -f $ctemplate; exit' INT TERM
  35.  
  36. cat > $ctemplate << EOF
  37. #include "$pcihfile"
  38.  
  39. #define DEVICE(vid,did,name) \
  40.    {PCI_VENDOR_ID_##vid, PCI_DEVICE_ID_##did, (name)}
  41.  
  42. /* This is an automatically generated file by makepciids. */
  43.  
  44. /* some PCI ids map to multiple modules (!!) */
  45. /* we just stick in an mulitple entries for the PCI id, with different */
  46. /* module name for each one. Code just search for ALL matches to a     */
  47. /* given PCI id to get all the modules that might(!) work              */
  48. struct pci_module_map {
  49.     unsigned short    vendor;     /* PCI vendor id */
  50.     unsigned short    device;     /* PCI device id */
  51.     const char      *name;      /* PCI human readable name */
  52.     const char      *module;    /* module to load */
  53. };
  54.  
  55.  
  56. EOF
  57.  
  58. #
  59. # now make the rest of the file
  60. #
  61.  
  62. #
  63. # scsi, eth, and video
  64. #
  65. echo "struct pci_module_map scsi_pci_ids[] = {" >> $ctemplate
  66. cat good-scsi.lst >> $ctemplate
  67. echo "};" >> $ctemplate
  68. echo "int scsi_num_ids=sizeof(scsi_pci_ids)/sizeof(struct pci_module_map);" >> $ctemplate
  69. echo "" >> $ctemplate
  70. echo "struct pci_module_map eth_pci_ids[] = {" >> $ctemplate
  71. cat good-eth.lst >> $ctemplate
  72. echo "};" >> $ctemplate
  73. echo "int eth_num_ids=sizeof(eth_pci_ids)/sizeof(struct pci_module_map);" >> $ctemplate
  74. echo "" >> $ctemplate
  75. echo "struct pci_module_map video_pci_ids[] = {" >> $ctemplate
  76. cat good-video.lst >> $ctemplate
  77. echo "};" >> $ctemplate
  78. echo "int video_num_ids=sizeof(video_pci_ids)/sizeof(struct pci_module_map);" >> $ctemplate
  79. echo "" >> $ctemplate
  80. echo "/* END of automatically generated text */" >> $ctemplate
  81.  
  82. #
  83. # now make the C code
  84. #
  85. /lib/cpp -P -C $ctemplate | uniq > pci-ids-temp.h
  86.  
  87. rm -f $ctemplate
  88. rm -f $pcihfile
  89. exit
  90.