dev/pci: simplify PCI VPD access functions
authorStefan Eßer <se@FreeBSD.org>
Wed, 21 Jun 2023 17:36:39 +0000 (19:36 +0200)
committerStefan Eßer <se@FreeBSD.org>
Wed, 21 Jun 2023 17:36:39 +0000 (19:36 +0200)
commit586164cc095105f82ffd87997c3aa78f5e21a90c
tree98963e709590adcf86e84a5104d125e367d3251d
parente5c7aa5c703e268a80331be3a587449995563770
dev/pci: simplify PCI VPD access functions

This update contains a rewrite of the VPD parser based on the
definition of the structure of the VPD data (ident, R/O resource
data, optional R/W data, end tag).

The parser it replaces was based on a state machine, with the tags
and the parsed data controlling the state changes. The flexibility
of this parser is actually not required, and it has caused kernel
panics when operating on malformed data.

Analysis of the VPD code to make it more robust lead me to believe
that it was easier to write a "strict" parser than to restrict the
flexible state machine to detect and reject non-well-formed data.
A number of restrictions had already been added, but they make the
state machine ever more complex and harder to understand.

This updated parser has been verified to return identical parsed data
as the current implementation for the example VPD data given in the
PCI standard and in some actual PCIe VPD data.

It is strict in the sense that it detects and rejects any deviation
from a well-formed VPD structure.

PR: 272018
Approved by: kib
MFC after: 4 weeks
Differential Revision: https://reviews.freebsd.org/D34268
sys/dev/pci/pci.c