1
0

pci 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  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. # DMG 06/02/2016 Make pci(8) recognize virtio devices
  69. # source: http://git.qemu.org/?p=qemu.git;a=blob;f=include/hw/pci/pci.h
  70. # devices with vendor code 0x1af4 are QEMU own virtio devices.
  71. # useful device codes below:
  72. # 0x1000: virtio network card
  73. # 0x1001: virtio block device
  74. # 0x1002: virtio balloon
  75. # 0x1003: virtio console
  76. # 0x1004: virtio SCSI
  77. # 0x1005: virtio RNG (random numbers generator)
  78. # 0x1009: virtio 9P transport
  79. # based on this information, the translation table below is amended
  80. # to show these devices in the pci (8) output.
  81. builtin cd '#$/pci' && grep . *ctl | {
  82. if (~ $bridges no)
  83. sed /:06/d
  84. if not
  85. cat
  86. } |
  87. sed '
  88. s/ctl:/: /
  89. t noop
  90. : noop
  91. s/: (02\..*\ 1af4\/1000)/: virtio-net \1/
  92. s/: (01\..*\ 1af4\/1001)/: virtio-disk \1/
  93. s/: (00\..*\ 1af4\/1002)/: virtio-balloon \1/
  94. s/: (07\..*\ 1af4\/1003)/: virtio-console \1/
  95. s/: (01\..*\ 1af4\/1004)/: virtio-scsi \1/
  96. s/: (00\..*\ 1af4\/1005)/: virtio-rng \1/
  97. s/: (00\..*\ 1af4\/1009)/: virtio-9p \1/
  98. s/: 01/: disk 01/
  99. s/: 02/: net 02/
  100. s/: 03/: vid 03/
  101. s/: 04/: aud 04/
  102. s/: 05/: mem 05/
  103. s/: 06/: brg 06/
  104. s/: 07/: ser 07/
  105. s/: 0c\.03/: usb 0c.03/
  106. s/: 0c\.05/: smb 0c.05/
  107. s/: 0d/: rad 0d/
  108. s/: 10/: cryp 10/
  109. t
  110. s/ / --- /
  111. ' | $filter