1
0

pci 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. #!/bin/rc
  2. # pci [-bv] - dump pci configuration
  3. rfork e
  4. fn verbose {
  5. if (! test -f /lib/pci)
  6. echo $0: no /lib/pci >[1=2]
  7. awk '
  8. function lower(s) {
  9. gsub(/A/, "a", s)
  10. gsub(/B/, "b", s)
  11. gsub(/C/, "c", s)
  12. gsub(/D/, "d", s)
  13. gsub(/E/, "e", s)
  14. gsub(/F/, "f", s)
  15. return s
  16. }
  17. BEGIN{
  18. file="/lib/pci"
  19. FS="\t"
  20. while(getline <file > 0){
  21. if(/^;/) continue
  22. if(/^[0-9a-fA-F]/){
  23. vid=lower($1)
  24. vendor[vid] = $2
  25. }
  26. if(/^ [0-9a-fA-F]/){
  27. did=lower($2)
  28. id[vid "/" did] = $3
  29. }
  30. }
  31. FS = " "
  32. }
  33. {
  34. print $0
  35. vid = $4
  36. sub(/\/.*/, "", vid)
  37. if(vid in vendor){
  38. s = vendor[vid]
  39. if($4 in id)
  40. s = s " " id[$4]
  41. print "\t" s
  42. }
  43. }
  44. '
  45. }
  46. fn usage {
  47. echo usage: $1 '[-bv]' >[1=2]
  48. exit usage
  49. }
  50. filter=cat
  51. bridges=yes
  52. done=0
  53. while (~ $done 0 && ! ~ $#* 0 && ~ $1 -*) {
  54. if (~ $1 -*b*)
  55. bridges=no
  56. if (~ $1 -*v*)
  57. filter=verbose
  58. switch ($1) {
  59. case --
  60. done = 1 # no break in rc, alas
  61. case -*[~bv]*
  62. usage $0
  63. }
  64. shift
  65. }
  66. if (! ~ $#* 0)
  67. usage $0
  68. builtin cd '#$/pci' && grep . *ctl | {
  69. if (~ $bridges no)
  70. sed /:06/d
  71. if not
  72. cat
  73. } |
  74. sed '
  75. s/ctl:/: /
  76. t noop
  77. : noop
  78. s/: 01/: disk 01/
  79. s/: 02/: net 02/
  80. s/: 03/: vid 03/
  81. s/: 04/: aud 04/
  82. s/: 05/: mem 05/
  83. s/: 06/: brg 06/
  84. s/: 07/: ser 07/
  85. s/: 0c\.03/: usb 0c.03/
  86. s/: 0c\.05/: smb 0c.05/
  87. s/: 0d/: rad 0d/
  88. s/: 10/: cryp 10/
  89. t
  90. s/ / --- /
  91. ' | $filter