2 * The PCI Utilities -- Show Vital Product Data
4 * Copyright (c) 2008 Solarflare Communications
6 * Written by Ben Hutchings <bhutchings@solarflare.com>
7 * Improved by Martin Mares <mj@ucw.cz>
9 * Can be freely distributed and used under the terms of the GNU GPL.
17 * The list of all known VPD items and their formats.
18 * Technically, this belongs to the pci.ids file, but the VPD does not seem
19 * to be developed any longer, so we have chosen the easier way.
29 static const struct vpd_item {
34 { 'C','P', F_BINARY, "Extended capability" },
35 { 'E','C', F_TEXT, "Engineering changes" },
36 { 'M','N', F_BINARY, "Manufacture ID" },
37 { 'P','N', F_TEXT, "Part number" },
38 { 'R','V', F_RESVD, "Reserved" },
39 { 'R','W', F_RDWR, "Read-write area" },
40 { 'S','N', F_TEXT, "Serial number" },
41 { 'Y','A', F_TEXT, "Asset tag" },
42 { 'V', 0 , F_TEXT, "Vendor specific" },
43 { 'Y', 0 , F_TEXT, "System specific" },
44 { 0, 0 , F_BINARY, "Unknown" }
48 print_vpd_string(const byte *buf, word len)
56 ; /* Cards with null-terminated strings have been observed */
57 else if (ch < 32 || ch == 127)
58 printf("\\x%02x", ch);
65 print_vpd_binary(const byte *buf, word len)
68 for (i = 0; i < len; i++)
72 printf("%02x", buf[i]);
77 read_vpd(struct device *d, int pos, byte *buf, int len, byte *csum)
79 if (!pci_read_vpd(d->dev, pos, buf, len))
87 cap_vpd(struct device *d)
89 word res_addr = 0, res_len, part_pos, part_len;
94 printf("Vital Product Data\n");
98 while (res_addr <= PCI_VPD_ADDR_MASK)
100 if (!read_vpd(d, res_addr, &tag, 1, &csum))
104 if (res_addr > PCI_VPD_ADDR_MASK + 1 - 3)
106 if (!read_vpd(d, res_addr + 1, buf, 2, &csum))
108 res_len = buf[0] + (buf[1] << 8);
117 if (res_len > PCI_VPD_ADDR_MASK + 1 - res_addr)
129 printf("\t\tProduct Name: ");
130 while (part_pos < res_len)
132 part_len = res_len - part_pos;
133 if (part_len > sizeof(buf))
134 part_len = sizeof(buf);
135 if (!read_vpd(d, res_addr + part_pos, buf, part_len, &csum))
137 print_vpd_string(buf, part_len);
138 part_pos += part_len;
145 printf("\t\t%s fields:\n",
146 (tag == 0x90) ? "Read-only" : "Read/write");
148 while (part_pos + 3 <= res_len)
151 const struct vpd_item *item;
154 if (!read_vpd(d, res_addr + part_pos, buf, 3, &csum))
160 if (part_len > res_len - part_pos)
163 /* Is this item known? */
164 for (item=vpd_items; item->id1 && item->id1 != id1 ||
165 item->id2 && item->id2 != id2; item++)
168 /* Only read the first byte of the RV field because the
169 * remaining bytes are not included in the checksum. */
170 read_len = (item->format == F_RESVD) ? 1 : part_len;
171 if (!read_vpd(d, res_addr + part_pos, buf, read_len, &csum))
174 printf("\t\t\t[%c%c] %s: ", id1, id2, item->name);
176 switch (item->format)
179 print_vpd_string(buf, part_len);
183 print_vpd_binary(buf, part_len);
187 printf("checksum %s, %d byte(s) reserved\n", csum ? "bad" : "good", part_len - 1);
190 printf("%d byte(s) free\n", part_len);
194 part_pos += part_len;
199 printf("\t\tUnknown %s resource type %02x\n",
200 (tag & 0x80) ? "large" : "small", tag & ~0x80);
208 printf("\t\tNot readable\n");
210 printf("\t\tNo end tag found\n");