Skip to content

Instantly share code, notes, and snippets.

@nonakap
Created September 11, 2015 17:01
Show Gist options
  • Select an option

  • Save nonakap/3386f083e64a3b2abc5a to your computer and use it in GitHub Desktop.

Select an option

Save nonakap/3386f083e64a3b2abc5a to your computer and use it in GitHub Desktop.
NetBSD PCI Configuration Space Dump script
#!/bin/sh
if [ $# -eq 0 ]; then
echo "Usage: $0 <machine name>"
exit 127
fi
tmpfile=`mktemp -q /tmp/${0##*/}.XXXXXX`
if [ $? -ne 0 ]; then
echo "$0: Can't create temp file, exiting..."
exit 1
fi
trap '{ /bin/rm -f ${tmpfile}; }' 1 2 3 15
pciinfodir=.
pciinfo=${pciinfodir}/pciinfo-$1.txt
dmesg > "${pciinfo}"
echo >> "${pciinfo}"
echo >> "${pciinfo}"
echo "##### PCI device List:" >> "${pciinfo}"
pcictl /dev/pci0 list >> "${pciinfo}"
pcictl /dev/pci0 list | \
awk 'BEGIN { FS = "[:]" } { print $1, $2, $3, $4 }' > ${tmpfile}
( while read bus dev func name ; do
echo >> "${pciinfo}"
echo >> "${pciinfo}"
echo "##### PCI configuration Space: ${bus}:${dev}:${func} ${name}" \
>> "${pciinfo}"
bus=`echo ${bus} | sed -e 's/^0*\([0-9][0-9]*\)/\1/'`
dev=`echo ${dev} | sed -e 's/^0*\([0-9][0-9]*\)/\1/'`
func=`echo ${func} | sed -e 's/^0*\([0-9][0-9]*\)/\1/'`
pcictl /dev/pci0 dump -b ${bus} -d ${dev} -f ${func} >> "${pciinfo}"
done ) < ${tmpfile}
/bin/rm -f ${tmpfile}
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment