On Wed, Oct 20, 2021 at 11:30:31AM +0300, Dmitrii Shcherbakov wrote: > Add support for deserializing the binary PCI/PCIe VPD format and storing > results in memory. > > The VPD format is specified in "I.3. VPD Definitions" in PCI specs > (2.2+) and "6.28.1 VPD Format" PCIe 4.0. As section 6.28 in PCIe 4.0 > notes, the PCI Local Bus and PCIe VPD formats are binary compatible > and PCIe 4.0 merely started incorporating what was already present in > PCI specs. > > Linux kernel exposes a binary blob in the VPD format via sysfs since > v2.6.26 (commit 94e6108803469a37ee1e3c92dafdd1d59298602f) which requires > a parser to interpret. > > Signed-off-by: Dmitrii Shcherbakov <dmitrii.shcherba...@canonical.com> > --- > build-aux/syntax-check.mk | 4 +- > po/POTFILES.in | 1 + > src/libvirt_private.syms | 18 + > src/util/meson.build | 1 + > src/util/virpcivpd.c | 754 +++++++++++++++++++++++++++++++++++ > src/util/virpcivpd.h | 76 ++++ > src/util/virpcivpdpriv.h | 83 ++++ > tests/meson.build | 1 + > tests/testutils.c | 35 ++ > tests/testutils.h | 4 + > tests/virpcivpdtest.c | 809 ++++++++++++++++++++++++++++++++++++++ > 11 files changed, 1784 insertions(+), 2 deletions(-) > create mode 100644 src/util/virpcivpd.c > create mode 100644 src/util/virpcivpd.h > create mode 100644 src/util/virpcivpdpriv.h > create mode 100644 tests/virpcivpdtest.c
> +size_t > +virPCIVPDReadVPDBytes(int vpdFileFd, uint8_t *buf, size_t count, off_t > offset, uint8_t *csum) > +{ > + ssize_t numRead = pread(vpdFileFd, buf, count, offset); > + > + if (numRead == -1) { > + VIR_DEBUG("Unable to read %zu bytes at offset %ld from fd: %d", > count, offset, vpdFileFd); %ld isn't portable to 32-bit, so we need %zd here. > + } else if (numRead) { > + /* > + * Update the checksum for every byte read. Per the PCI(e) specs > + * the checksum is correct if the sum of all bytes in VPD from > + * VPD address 0 up to and including the VPD-R RV field's first > + * data byte is zero. > + */ > + while (count--) { > + *csum += *buf; > + buf++; > + } > + } > + return numRead; > +} Regards, Daniel -- |: https://berrange.com -o- https://www.flickr.com/photos/dberrange :| |: https://libvirt.org -o- https://fstop138.berrange.com :| |: https://entangle-photo.org -o- https://www.instagram.com/dberrange :|