iPXE
pcivpd.h
Go to the documentation of this file.
1 #ifndef _IPXE_PCIVPD_H
2 #define _IPXE_PCIVPD_H
3 
4 /**
5  * @file
6  *
7  * PCI Vital Product Data
8  *
9  */
10 
11 FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
12 
13 #include <stdint.h>
14 #include <byteswap.h>
15 #include <ipxe/isapnp.h>
16 #include <ipxe/pci.h>
17 
18 /** PCI VPD address register */
19 #define PCI_VPD_ADDRESS 0x02
20 
21 /** PCI VPD write flag */
22 #define PCI_VPD_FLAG 0x8000
23 
24 /** PCI VPD data register */
25 #define PCI_VPD_DATA 0x04
26 
27 /** A PCI VPD field */
28 struct pci_vpd_field {
29  /** Keyword */
31  /** Length */
33 } __attribute__ (( packed ));
34 
35 /** Maximum PCI VPD field length */
36 #define PCI_VPD_MAX_LEN 0xff
37 
38 /** Construct PCI VPD field descriptor
39  *
40  * @v tag ISAPnP tag
41  * @v keyword1 First character of keyword
42  * @v keyword2 Second character of keyword
43  * @ret field VPD field descriptor
44  */
45 #define PCI_VPD_FIELD( tag, keyword1, keyword2 ) \
46  ( ( (tag) << 16 ) | ( (keyword2) << 8 ) | ( (keyword1) << 0 ) )
47 
48 /** Construct PCI VPD whole-tag field descriptor
49  *
50  * @v tag ISAPnP tag
51  * @ret field VPD field descriptor
52  */
53 #define PCI_VPD_WHOLE_TAG_FIELD( tag ) PCI_VPD_FIELD ( (tag), '\0', '\0' )
54 
55 /** Extract PCI VPD ISAPnP tag
56  *
57  * @v field VPD field descriptor
58  * @ret tag ISAPnP tag
59  */
60 #define PCI_VPD_TAG( field ) ( (field) >> 16 )
61 
62 /** Extract PCI VPD keyword
63  *
64  * @v field VPD field descriptor
65  * @ret keyword Keyword
66  */
67 #define PCI_VPD_KEYWORD( field ) ( cpu_to_le16 ( (field) & 0xffff ) )
68 
69 /** PCI VPD field debug message format */
70 #define PCI_VPD_FIELD_FMT "%c%c"
71 
72 /** PCI VPD field debug message arguments */
73 #define PCI_VPD_FIELD_ARGS( field ) \
74  ( (field) >> 0 ), ( (field) >> 8 )
75 
76 /** PCI VPD Read-Only field tag */
77 #define PCI_VPD_TAG_RO 0x90
78 
79 /** PCI VPD Read-Write field tag */
80 #define PCI_VPD_TAG_RW 0x91
81 
82 /** PCI VPD Card Name field descriptor */
83 #define PCI_VPD_FIELD_NAME PCI_VPD_WHOLE_TAG_FIELD ( ISAPNP_TAG_ANSISTR )
84 
85 /** PCI VPD Part Number field descriptor */
86 #define PCI_VPD_FIELD_PN PCI_VPD_FIELD ( PCI_VPD_TAG_RO, 'P', 'N' )
87 
88 /** PCI VPD Engineering Change Level field descriptor */
89 #define PCI_VPD_FIELD_EC PCI_VPD_FIELD ( PCI_VPD_TAG_RO, 'E', 'C' )
90 
91 /** PCI VPD Fabric Geography field descriptor */
92 #define PCI_VPD_FIELD_FG PCI_VPD_FIELD ( PCI_VPD_TAG_RO, 'F', 'G' )
93 
94 /** PCI VPD Location field descriptor */
95 #define PCI_VPD_FIELD_LC PCI_VPD_FIELD ( PCI_VPD_TAG_RO, 'L', 'C' )
96 
97 /** PCI VPD Manufacturer ID field descriptor */
98 #define PCI_VPD_FIELD_MN PCI_VPD_FIELD ( PCI_VPD_TAG_RO, 'M', 'N' )
99 
100 /** PCI VPD PCI Geography field descriptor */
101 #define PCI_VPD_FIELD_PG PCI_VPD_FIELD ( PCI_VPD_TAG_RO, 'P', 'G' )
102 
103 /** PCI VPD Serial Number field descriptor */
104 #define PCI_VPD_FIELD_SN PCI_VPD_FIELD ( PCI_VPD_TAG_RO, 'S', 'N' )
105 
106 /** PCI VPD Extended Capability field descriptor */
107 #define PCI_VPD_FIELD_CP PCI_VPD_FIELD ( PCI_VPD_TAG_RO, 'C', 'P' )
108 
109 /** PCI VPD Checksum and Reserved field descriptor */
110 #define PCI_VPD_FIELD_RV PCI_VPD_FIELD ( PCI_VPD_TAG_RO, 'R', 'V' )
111 
112 /** PCI VPD Asset Tag field descriptor */
113 #define PCI_VPD_FIELD_YA PCI_VPD_FIELD ( PCI_VPD_TAG_RW, 'Y', 'A' )
114 
115 /** PCI VPD Remaining Read/Write Area field descriptor */
116 #define PCI_VPD_FIELD_RW PCI_VPD_FIELD ( PCI_VPD_TAG_RW, 'R', 'W' )
117 
118 /** Maximum wait for PCI VPD (in ms) */
119 #define PCI_VPD_MAX_WAIT_MS 100
120 
121 /** PCI VPD cache */
123  /** Address */
124  int address;
125  /** Data */
127 };
128 
129 /** PCI VPD */
130 struct pci_vpd {
131  /** PCI device */
132  struct pci_device *pci;
133  /** VPD capability offset */
134  int cap;
135  /** Read cache */
137 };
138 
139 /**
140  * Check for presence of PCI VPD
141  *
142  * @v vpd PCI VPD
143  * @ret is_present VPD is present
144  */
145 static inline __attribute__ (( always_inline )) int
146 pci_vpd_is_present ( struct pci_vpd *vpd ) {
147  return ( vpd->cap != 0 );
148 }
149 
150 /**
151  * Check if PCI VPD read cache is valid
152  *
153  * @v vpd PCI VPD
154  * @ret is_valid Read cache is valid
155  */
156 static inline __attribute__ (( always_inline )) int
158  return ( vpd->cache.address >= 0 );
159 }
160 
161 /**
162  * Invalidate PCI VPD read cache
163  *
164  * @v vpd PCI VPD
165  */
166 static inline __attribute__ (( always_inline )) void
168  vpd->cache.address = -1;
169 }
170 
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 );
180 
181 #endif /* _IPXE_PCIVPD_H */
#define __attribute__(x)
Definition: compiler.h:10
unsigned short uint16_t
Definition: stdint.h:11
int pci_vpd_init(struct pci_vpd *vpd, struct pci_device *pci)
Initialise PCI Vital Product Data.
Definition: pcivpd.c:48
int pci_vpd_write(struct pci_vpd *vpd, unsigned int address, const void *buf, size_t len)
Write PCI VPD.
Definition: pcivpd.c:225
uint64_t address
Base address.
Definition: ena.h:24
A PCI VPD field.
Definition: pcivpd.h:28
static int pci_vpd_is_present(struct pci_vpd *vpd)
Check for presence of PCI VPD.
Definition: pcivpd.h:146
int pci_vpd_find(struct pci_vpd *vpd, unsigned int field, unsigned int *address, size_t *len)
Locate PCI VPD field.
Definition: pcivpd.c:353
static void pci_vpd_invalidate_cache(struct pci_vpd *vpd)
Invalidate PCI VPD read cache.
Definition: pcivpd.h:167
int cap
VPD capability offset.
Definition: pcivpd.h:134
int address
Address.
Definition: pcivpd.h:124
int pci_vpd_read(struct pci_vpd *vpd, unsigned int address, void *buf, size_t len)
Read PCI VPD.
Definition: pcivpd.c:183
static int pci_vpd_cache_is_valid(struct pci_vpd *vpd)
Check if PCI VPD read cache is valid.
Definition: pcivpd.h:157
uint32_t data
Data.
Definition: pcivpd.h:126
PCI VPD cache.
Definition: pcivpd.h:122
FILE_LICENCE(GPL2_OR_LATER_OR_UBDL)
uint8_t len
Length.
Definition: pcivpd.h:32
struct pci_vpd_cache cache
Read cache.
Definition: pcivpd.h:136
PCI bus.
A PCI device.
Definition: pci.h:206
unsigned char uint8_t
Definition: stdint.h:10
uint16_t keyword
Keyword.
Definition: pcivpd.h:30
unsigned int uint32_t
Definition: stdint.h:12
int pci_vpd_resize(struct pci_vpd *vpd, unsigned int field, size_t len, unsigned int *address)
Resize VPD field.
Definition: pcivpd.c:411
uint32_t len
Length.
Definition: ena.h:14
struct pci_device * pci
PCI device.
Definition: pcivpd.h:132
PCI VPD.
Definition: pcivpd.h:130