pciutils: add new readpci utility
PATCH v2 1/1 pciutils: add new readpci utility
Add the new utility 'readpci' in order to allow users to read and write the register address space located in the BAR designator + offset.
The reason that this app is better than what is generally available on the internet (there are several) is that this app integrates with the libpci and further benefits from pciutils-like arguments and device specifications.
help output:
$ sudo ./readpci -h ./readpci: invalid option -- 'h' Usage: ./readpci [options] [device] (/usr/local/share/pci.ids.gz)
Options:
-w <value> Value to write to the address -W <value> Value to write to the address (no read) -a <value> Register address -b <value> BAR to access other than BAR 0 -m Access MSI-X BAR instead of BAR 0 -D PCI debugging -q Quiet mode, no banner -v Enable more verbose output
Device:
-d [<vendor>]:[<device>] Show selected devices
-s [[[[<domain>]:]<bus>]:][<slot>][.[<func>]] Show devices in selected slots
basic usage to read a register:
$ sudo ./readpci -s 17:0.0 -a 0xb8000 17:00.0 (8086:1592) - Device 8086:1592 0xb8000 == 0x00000001
This program was originally written by Shannon Nelson, and extended by me.
Limitations
===========
Currently the utility only allows reading or writing one 32 bit value at a time, on one device only.
Future options
==============
- Implement machine readable output
- Implement multiple register reads (ranges)
- Implement multiple device match (same register multiple devices of a match)
This change also contains a tiny Makefile optimization to allow overriding the compiler at build time on the command line, which made it easier to test with multiple compilers.
---
v2: addressed comments from Bjorn Helgaas, enhanced the man page, and extended verbose mode printing to output the final address, and a 32 bit value for the address value printing. I left the renaming discussion to another patch, as the readpci name may not be final.
--- .gitignore | 1 + Makefile | 19 +-- readpci.c | 345 ++++++++++++++++++++++++++++++++++++++++++++++++++++ readpci.man | 96 +++++++++++++++ 4 files changed, 454 insertions(+), 7 deletions(-)
.gitignore +1 -0
@@ -6,5 +6,6 @@ lspci setpci example +readpci update-pciids pci.ids.gz
Makefile +12 -7
@@ -47,9 +47,9 @@ INSTALL=install DIRINSTALL=install -d STRIP=-s ifdef CROSS_COMPILE -CC=$(CROSS_COMPILE)gcc +CC:=$(CROSS_COMPILE)gcc else -CC=cc +CC:=cc endif AR=$(CROSS_COMPILE)ar RANLIB=$(CROSS_COMPILE)ranlib
@@ -64,7 +64,7 @@ PCIINC_INS=lib/config.h lib/header.h lib/pci.h lib/types.h export -all: lib/$(PCILIB) lspci$(EXEEXT) setpci$(EXEEXT) example$(EXEEXT) lspci.8 setpci.8 pcilib.7 pci.ids.5 update-pciids update-pciids.8 $(PCI_IDS) +all: lib/$(PCILIB) lspci$(EXEEXT) setpci$(EXEEXT) readpci$(EXEEXT) example$(EXEEXT) lspci.8 setpci.8 readpci.8 pcilib.7 pci.ids.5 update-pciids update-pciids.8 $(PCI_IDS) lib/$(PCILIB): $(PCIINC) force $(MAKE) -C lib all
@@ -103,6 +103,10 @@ update-pciids: update-pciids.sh sed <$< >$@ "s@^DEST=.*@DEST=$(IDSDIR)/$(PCI_IDS)@;s@^PCI_COMPRESSED_IDS=.*@PCI_COMPRESSED_IDS=$(PCI_COMPRESSED_IDS)@" chmod +x $@ +# add the readpci executable +readpci$(EXEEXT): readpci.o lib/$(PCILIB) +readpci.o: readpci.c pciutils.h $(PCIINC) + # The example of use of libpci example$(EXEEXT): example.o lib/$(PCILIB) example.o: example.c $(PCIINC)
@@ -123,7 +127,7 @@ TAGS: clean: rm -f `find . -name "*~" -o -name "*.[oa]" -o -name "\#*\#" -o -name TAGS -o -name core -o -name "*.orig"` - rm -f update-pciids lspci$(EXEEXT) setpci$(EXEEXT) example$(EXEEXT) lib/config.* *.[578] pci.ids.gz lib/*.pc lib/*.so lib/*.so.* tags + rm -f update-pciids lspci$(EXEEXT) setpci$(EXEEXT) readpci$(EXEEXT) example$(EXEEXT) lib/config.* *.[578] pci.ids.gz lib/*.pc lib/*.so lib/*.so.* tags rm -rf maint/dist distclean: clean
@@ -133,9 +137,10 @@ install: all $(DIRINSTALL) -m 755 $(DESTDIR)$(BINDIR) $(DESTDIR)$(SBINDIR) $(DESTDIR)$(IDSDIR) $(DESTDIR)$(MANDIR)/man8 $(DESTDIR)$(MANDIR)/man7 $(DESTDIR)/$(MANDIR)/man5 $(INSTALL) -c -m 755 $(STRIP) lspci$(EXEEXT) $(DESTDIR)$(LSPCIDIR) $(INSTALL) -c -m 755 $(STRIP) setpci$(EXEEXT) $(DESTDIR)$(SBINDIR) + $(INSTALL) -c -m 755 $(STRIP) readpci$(EXEEXT) $(DESTDIR)$(SBINDIR) $(INSTALL) -c -m 755 update-pciids $(DESTDIR)$(SBINDIR) $(INSTALL) -c -m 644 $(PCI_IDS) $(DESTDIR)$(IDSDIR) - $(INSTALL) -c -m 644 lspci.8 setpci.8 update-pciids.8 $(DESTDIR)$(MANDIR)/man8 + $(INSTALL) -c -m 644 lspci.8 setpci.8 readpci.8 update-pciids.8 $(DESTDIR)$(MANDIR)/man8 $(INSTALL) -c -m 644 pcilib.7 $(DESTDIR)$(MANDIR)/man7 $(INSTALL) -c -m 644 pci.ids.5 $(DESTDIR)$(MANDIR)/man5 ifeq ($(SHARED),yes)
@@ -169,9 +174,9 @@ endif endif uninstall: all - rm -f $(DESTDIR)$(SBINDIR)/lspci$(EXEEXT) $(DESTDIR)$(SBINDIR)/setpci$(EXEEXT) $(DESTDIR)$(SBINDIR)/update-pciids + rm -f $(DESTDIR)$(SBINDIR)/lspci$(EXEEXT) $(DESTDIR)$(SBINDIR)/setpci$(EXEEXT) $(DESTDIR)$(SBINDIR)/readpci$(EXEEXT) $(DESTDIR)$(SBINDIR)/update-pciids rm -f $(DESTDIR)$(IDSDIR)/$(PCI_IDS) - rm -f $(DESTDIR)$(MANDIR)/man8/lspci.8 $(DESTDIR)$(MANDIR)/man8/setpci.8 $(DESTDIR)$(MANDIR)/man8/update-pciids.8 + rm -f $(DESTDIR)$(MANDIR)/man8/lspci.8 $(DESTDIR)$(MANDIR)/man8/setpci.8 $(DESTDIR)$(MANDIR)/man8/readpci.8 $(DESTDIR)$(MANDIR)/man8/update-pciids.8 rm -f $(DESTDIR)$(MANDIR)/man7/pcilib.7 rm -f $(DESTDIR)$(MANDIR)/man5/pci.ids.5 rm -f $(DESTDIR)$(LIBDIR)/$(PCILIB)
readpci.c new file +345 -0
345 lines not on this page · raw message
readpci.man new file +96 -0
96 lines not on this page · raw message
base-commit: 0478e1f3928bfaa34eb910ba2cbaf1dda8f84aab
Signature · 1 line
2.31.1
Hello!
Quoted 7 lines
Add the new utility 'readpci' in order to allow users to read and write the register address space located in the BAR designator + offset.
The reason that this app is better than what is generally available on the internet (there are several) is that this app integrates with the libpci and further benefits from pciutils-like arguments and device specifications.
I do not think we need a separate utility for that – let's extend setpci instead.
The register syntax already supports directly addressed configuration space, capabilities and extended capabilities, so let us add memory-mapped regions. All the rest (specifying offset and access width) is already there.
Also, what do we do on non-Linux systems? mmap of memory-mapped regions is certainly not available everywhere. So the proper way is to add an API for that to libpci, even if it will be implemented only on Linux at first.
Are there some architectures where MMIO in user space requires some kind of magic to avoid cache coherency issues?
Martin