7 * PCI Vital Product Data
11 FILE_LICENCE ( GPL2_OR_LATER );
15 #include <ipxe/isapnp.h>
18 /** PCI VPD address register */
19 #define PCI_VPD_ADDRESS 0x02
21 /** PCI VPD write flag */
22 #define PCI_VPD_FLAG 0x8000
24 /** PCI VPD data register */
25 #define PCI_VPD_DATA 0x04
27 /** A PCI VPD field */
28 struct pci_vpd_field {
33 } __attribute__ (( packed ));
35 /** Maximum PCI VPD field length */
36 #define PCI_VPD_MAX_LEN 0xff
38 /** Construct PCI VPD field descriptor
41 * @v keyword1 First character of keyword
42 * @v keyword2 Second character of keyword
43 * @ret field VPD field descriptor
45 #define PCI_VPD_FIELD( tag, keyword1, keyword2 ) \
46 ( ( (tag) << 16 ) | ( (keyword2) << 8 ) | ( (keyword1) << 0 ) )
48 /** Construct PCI VPD whole-tag field descriptor
51 * @ret field VPD field descriptor
53 #define PCI_VPD_WHOLE_TAG_FIELD( tag ) PCI_VPD_FIELD ( (tag), '\0', '\0' )
55 /** Extract PCI VPD ISAPnP tag
57 * @v field VPD field descriptor
60 #define PCI_VPD_TAG( field ) ( (field) >> 16 )
62 /** Extract PCI VPD keyword
64 * @v field VPD field descriptor
65 * @ret keyword Keyword
67 #define PCI_VPD_KEYWORD( field ) ( cpu_to_le16 ( (field) & 0xffff ) )
69 /** PCI VPD field debug message format */
70 #define PCI_VPD_FIELD_FMT "%c%c"
72 /** PCI VPD field debug message arguments */
73 #define PCI_VPD_FIELD_ARGS( field ) \
74 ( (field) >> 0 ), ( (field) >> 8 )
76 /** PCI VPD Read-Only field tag */
77 #define PCI_VPD_TAG_RO 0x90
79 /** PCI VPD Read-Write field tag */
80 #define PCI_VPD_TAG_RW 0x91
82 /** PCI VPD Card Name field descriptor */
83 #define PCI_VPD_FIELD_NAME PCI_VPD_WHOLE_TAG_FIELD ( ISAPNP_TAG_ANSISTR )
85 /** PCI VPD Part Number field descriptor */
86 #define PCI_VPD_FIELD_PN PCI_VPD_FIELD ( PCI_VPD_TAG_RO, 'P', 'N' )
88 /** PCI VPD Engineering Change Level field descriptor */
89 #define PCI_VPD_FIELD_EC PCI_VPD_FIELD ( PCI_VPD_TAG_RO, 'E', 'C' )
91 /** PCI VPD Fabric Geography field descriptor */
92 #define PCI_VPD_FIELD_FG PCI_VPD_FIELD ( PCI_VPD_TAG_RO, 'F', 'G' )
94 /** PCI VPD Location field descriptor */
95 #define PCI_VPD_FIELD_LC PCI_VPD_FIELD ( PCI_VPD_TAG_RO, 'L', 'C' )
97 /** PCI VPD Manufacturer ID field descriptor */
98 #define PCI_VPD_FIELD_MN PCI_VPD_FIELD ( PCI_VPD_TAG_RO, 'M', 'N' )
100 /** PCI VPD PCI Geography field descriptor */
101 #define PCI_VPD_FIELD_PG PCI_VPD_FIELD ( PCI_VPD_TAG_RO, 'P', 'G' )
103 /** PCI VPD Serial Number field descriptor */
104 #define PCI_VPD_FIELD_SN PCI_VPD_FIELD ( PCI_VPD_TAG_RO, 'S', 'N' )
106 /** PCI VPD Extended Capability field descriptor */
107 #define PCI_VPD_FIELD_CP PCI_VPD_FIELD ( PCI_VPD_TAG_RO, 'C', 'P' )
109 /** PCI VPD Checksum and Reserved field descriptor */
110 #define PCI_VPD_FIELD_RV PCI_VPD_FIELD ( PCI_VPD_TAG_RO, 'R', 'V' )
112 /** PCI VPD Asset Tag field descriptor */
113 #define PCI_VPD_FIELD_YA PCI_VPD_FIELD ( PCI_VPD_TAG_RW, 'Y', 'A' )
115 /** PCI VPD Remaining Read/Write Area field descriptor */
116 #define PCI_VPD_FIELD_RW PCI_VPD_FIELD ( PCI_VPD_TAG_RW, 'R', 'W' )
118 /** Maximum wait for PCI VPD (in ms) */
119 #define PCI_VPD_MAX_WAIT_MS 100
122 struct pci_vpd_cache {
132 struct pci_device *pci;
133 /** VPD capability offset */
136 struct pci_vpd_cache cache;
140 * Check for presence of PCI VPD
143 * @ret is_present VPD is present
145 static inline __attribute__ (( always_inline )) int
146 pci_vpd_is_present ( struct pci_vpd *vpd ) {
147 return ( vpd->cap != 0 );
151 * Check if PCI VPD read cache is valid
154 * @ret is_valid Read cache is valid
156 static inline __attribute__ (( always_inline )) int
157 pci_vpd_cache_is_valid ( struct pci_vpd *vpd ) {
158 return ( vpd->cache.address >= 0 );
162 * Invalidate PCI VPD read cache
166 static inline __attribute__ (( always_inline )) void
167 pci_vpd_invalidate_cache ( struct pci_vpd *vpd ) {
168 vpd->cache.address = -1;
171 extern int pci_vpd_init ( struct pci_vpd *vpd, struct pci_device *pci );
172 extern int pci_vpd_read ( struct pci_vpd *vpd, unsigned int address,
173 void *buf, size_t len );
174 extern int pci_vpd_write ( struct pci_vpd *vpd, unsigned int address,
175 const void *buf, size_t len );
176 extern int pci_vpd_find ( struct pci_vpd *vpd, unsigned int field,
177 unsigned int *address, size_t *len );
178 extern int pci_vpd_resize ( struct pci_vpd *vpd, unsigned int field,
179 size_t len, unsigned int *address );
181 #endif /* _IPXE_PCIVPD_H */