|  | #!/bin/bash | 
|  | # pci [-bv] - dump pci configuration | 
|  | prog=$0 | 
|  | verbose() { | 
|  | if [[ ! -f /lib/pci ]]; then | 
|  | echo $0: no /lib/pci >&2 | 
|  | fi | 
|  | awk ' | 
|  |  | 
|  | function lower(s) { | 
|  | gsub(/A/, "a", s) | 
|  | gsub(/B/, "b", s) | 
|  | gsub(/C/, "c", s) | 
|  | gsub(/D/, "d", s) | 
|  | gsub(/E/, "e", s) | 
|  | gsub(/F/, "f", s) | 
|  | return s | 
|  | } | 
|  | BEGIN{ | 
|  | file="/lib/pci" | 
|  | FS="\t" | 
|  | while(getline <file > 0){ | 
|  | if(/^;/) continue | 
|  | if(/^[0-9a-fA-F]/){ | 
|  | vid=lower($1) | 
|  | vendor[vid] = $2 | 
|  | } | 
|  | if(/^	[0-9a-fA-F]/){ | 
|  | did=lower($2) | 
|  | id[vid "/" did] = $3 | 
|  | } | 
|  | } | 
|  | FS = " " | 
|  | } | 
|  |  | 
|  | { | 
|  | print $0 | 
|  | vid = $4 | 
|  | sub(/\/.*/, "", vid) | 
|  | if(vid in vendor){ | 
|  | s = vendor[vid] | 
|  | if($4 in id) | 
|  | s = s " " id[$4] | 
|  | print "\t" s | 
|  | } | 
|  | } | 
|  | ' | 
|  | } | 
|  |  | 
|  | usage() { | 
|  | echo "usage: ${prog} [-bv]" >&2 | 
|  | exit 1 | 
|  | } | 
|  |  | 
|  | filter=none | 
|  | bridges=yes | 
|  | while getopts "bv" opt; do | 
|  | case $opt in | 
|  | b) bridges=no;; | 
|  | v) filter=verbose;; | 
|  | *) usage $0 ;; | 
|  | esac | 
|  | done | 
|  | shift $((OPTIND-1)) | 
|  | if [[ $# -ne 0 ]]; then | 
|  | usage $0 | 
|  | fi | 
|  |  | 
|  | maybebridges() { | 
|  | if [[ "${bridges}" == "no" ]]; then | 
|  | sed '/:06/d' | 
|  | else | 
|  | cat | 
|  | fi | 
|  | } | 
|  |  | 
|  | maybefilter() { | 
|  | if [[ "${filter}" = "verbose" ]]; then | 
|  | verbose | 
|  | else | 
|  | cat | 
|  | fi | 
|  | } | 
|  |  | 
|  | # DMG 06/02/2016 Make pci(8) recognize virtio devices | 
|  | # source: http://git.qemu.org/?p=qemu.git;a=blob;f=include/hw/pci/pci.h | 
|  | # devices with vendor code 0x1af4 are QEMU own virtio devices. | 
|  | # useful device codes below: | 
|  | # 0x1000: virtio network card | 
|  | # 0x1001: virtio block device | 
|  | # 0x1002: virtio balloon | 
|  | # 0x1003: virtio console | 
|  | # 0x1004: virtio SCSI | 
|  | # 0x1005: virtio RNG (random numbers generator) | 
|  | # 0x1009: virtio 9P transport | 
|  | # based on this information, the translation table below is amended | 
|  | # to show these devices in the pci (8) output. | 
|  |  | 
|  | grep -a . '#pci/pci'/*ctl | maybebridges | sed ' | 
|  | s/^.pci\/// | 
|  | s/ctl:/:	/ | 
|  | t noop | 
|  | : noop | 
|  | s/:	\(02\..*\ 1af4\/1000\)/:	virtio-net     \1/ | 
|  | s/:	\(01\..*\ 1af4\/1001\)/:	virtio-disk    \1/ | 
|  | s/:	\(00\..*\ 1af4\/1002\)/:	virtio-balloon \1/ | 
|  | s/:	\(07\..*\ 1af4\/1003\)/:	virtio-console \1/ | 
|  | s/:	\(01\..*\ 1af4\/1004\)/:	virtio-scsi    \1/ | 
|  | s/:	\(00\..*\ 1af4\/1005\)/:	virtio-rng     \1/ | 
|  | s/:	\(00\..*\ 1af4\/1009\)/:	virtio-9p      \1/ | 
|  | s/:	01/:	disk  01/ | 
|  | s/:	02/:	net   02/ | 
|  | s/:	03/:	vid   03/ | 
|  | s/:	04/:	aud   04/ | 
|  | s/:	05/:	mem   05/ | 
|  | s/:	06/:	brg   06/ | 
|  | s/:	07/:	ser   07/ | 
|  | s/:	0c\.03/:	usb   0c.03/ | 
|  | s/:	0c\.05/:	smb   0c.05/ | 
|  | s/:	0d/:	rad   0d/ | 
|  | s/:	10/:	cryp  10/ | 
|  | t | 
|  | s/	/	---  / | 
|  | ' | maybefilter |