Add option -W that allows to write into a BAR region.
Also, add an option -R that allows to read from a BAR region that works similar to -r that reads from the PCI config space.
Differential D55915
pciconf: Add option to write into a BAR region Authored by timo.voelker_fh-muenster.de on Mar 18 2026, 1:34 PM. Tags None Referenced Files
Details Add option -W that allows to write into a BAR region. Also, add an option -R that allows to read from a BAR region that works similar to -r that reads from the PCI config space. For example, a VirtIO PCI device % pciconf -lb pci0:0:10:0
virtio_pci0@pci0:0:10:0: class=0x020000 rev=0x00 hdr=0x00 vendor=0x1af4 device=0x1000 subvendor=0x1af4 subdevice=0x0001
bar [10] = type I/O Port, range 32, base 0, size 32, enabled
bar [18] = type Memory, range 32, base 0xe1852000, size 8192, enabledThe second 4 bytes of BAR 0x18 specifies the device's features based on the first 4 bytes. % sudo pciconf -D pci0:0:10:0 0x18 0x0 2 | hexdump -C 00000000 01 00 00 00 01 00 00 00 |........| By writing a 0 in the first 4 bytes the device changes the second 4 bytes. % sudo pciconf -W pci0:0:10:0 0x18 0 0 % sudo pciconf -D pci0:0:10:0 0x18 0x0 2 | hexdump -C 00000000 00 00 00 00 a3 dd 2f 00 |....../.|
Diff Detail
Event TimelineComment Actions I think rather than trying to overload -B, it would be better to just use a different getopt() letter for this mode. I would suggest using -R for reading from a BAR but keep 'D' as an alias for backwards compatibility, and using -W for writing into a BAR. Comment Actions You only write a single value into the specified offset, right? Comment Actions I thought about that too but decided against it because:
After I saw that -b is already overloaded, I decided to use -B. As a compromise, I could add a -W and leave the rest as it is (no -R). What do you think? Comment Actions In my use case, I only had to write a single value. Do you know use cases where a series of values needs to be written to a BAR region? I tried to make it similar to -w (write to config space). This is the man page part about -w:
Do you find this more clear? If so, I could try to write the part of -Bw more like that. If not, we should change that too. Comment Actions Yes
A selector is the device specification, basically 'pci:b:f:d' for pciconf. Comment Actions OK. This is the synopsis: pciconf -Bw [-b | -h | -x] device bar offset value and this is the current text:
How about this?
OK, my question was misleading. I mean, why is selector underlined? It is not a pciconf argument. The name of the argument it refers to is device. Shouldn't end the sentence like that:
Comment Actions Ok
I think this was some kind of typo. There are several instances of it in the man page. I suggest providing a preparational patch that would fix this first. Comment Actions I'm fine with just -W. It's mostly the overloading of -B to set a mode I was not a fan of (where as -b never sets a mode, it is just a modifier). At this point, one might argue that pciconf should move to a pciconf [global options] <command> [command-specific options> somewhat similar to procstat, etc. but I'm not sure it's worth the work to do that. Comment Actions A small manpage fix, the rest looks OK.
Comment Actions Thanks for fixing the command line usage as I had asked. In general this looks good. There are some style things most of which are just broken in the existing code. I will try to fix those in the existing code in a separate review so there is a better pattern to copy from in the future.
Comment Actions Yes, this looks good to me. I'm about to land my style fixes change and can land this one next. Do you have a git commit I can cherry-pick? Alternatively, is "Timo Völker <timo.voelker_fh@muenster.de>" the correct author identity to use for the commit? Comment Actions I don't have a public git commit with these changes.
Almost, it's "Timo Völker <timo.voelker@fh-muenster.de>". | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||