2 * The PCI Utilities -- Show Vital Product Data
4 * Copyright (c) 2008 Ben Hutchings <bhutchings@solarflare.com>
6 * Can be freely distributed and used under the terms of the GNU GPL.
14 print_vpd_string(const byte *buf, word len)
21 else if (ch < 32 || ch == 127)
22 printf("\\x%02x", ch);
29 read_vpd(struct device *d, int pos, byte *buf, int len, byte *csum)
31 if (!pci_read_vpd(d->dev, pos, buf, len))
39 cap_vpd(struct device *d)
41 word res_addr = 0, res_len, part_pos, part_len;
42 byte key[2], buf[256];
46 printf("Vital Product Data\n");
50 while (res_addr <= PCI_VPD_ADDR_MASK)
52 if (!read_vpd(d, res_addr, &tag, 1, &csum))
56 if (res_addr > PCI_VPD_ADDR_MASK + 1 - 3)
58 if (!read_vpd(d, res_addr + 1, buf, 2, &csum))
60 res_len = buf[0] + (buf[1] << 8);
69 if (res_len > PCI_VPD_ADDR_MASK + 1 - res_addr)
81 printf("\t\tProduct Name: ");
82 while (part_pos < res_len)
84 part_len = res_len - part_pos;
85 if (part_len > sizeof(buf))
86 part_len = sizeof(buf);
87 if (!read_vpd(d, res_addr + part_pos, buf, part_len, &csum))
89 print_vpd_string(buf, part_len);
97 printf("\t\t%s fields:\n",
98 (tag == 0x90) ? "Read-only" : "Read/write");
100 while (part_pos + 3 <= res_len)
104 if (!read_vpd(d, res_addr + part_pos, buf, 3, &csum))
110 if (part_len > res_len - part_pos)
113 /* Only read the first byte of the RV field because the
114 * remaining bytes are not included in the checksum. */
115 read_len = (key[0] == 'R' && key[1] == 'V') ? 1 : part_len;
116 if (!read_vpd(d, res_addr + part_pos, buf, read_len, &csum))
119 if ((key[0] == 'E' && key[1] == 'C') ||
120 (key[0] == 'P' && key[1] == 'N') ||
121 (key[0] == 'S' && key[1] == 'N') ||
125 /* Alphanumeric content */
126 printf("\t\t\t%c%c: ", key[0], key[1]);
127 print_vpd_string(buf, part_len);
130 else if (key[0] == 'R' && key[1] == 'V')
132 /* Reserved and checksum */
133 printf("\t\t\tRV: checksum %s, %d byte(s) reserved\n",
134 csum ? "bad" : "good", part_len - 1);
136 else if (key[0] == 'R' && key[1] == 'W')
138 /* Read-write area */
139 printf("\t\t\tRW: %d byte(s) free\n", part_len);
143 /* Binary or unknown content */
145 printf("\t\t\t%c%c:", key[0], key[1]);
146 for (i = 0; i < part_len; i++)
147 printf(" %02x", buf[i]);
151 part_pos += part_len;
156 printf("\t\tUnknown %s resource type %02x\n",
157 (tag & 0x80) ? "large" : "small", tag & ~0x80);
165 printf("\t\tNot readable\n");
167 printf("\t\tNo end tag found\n");