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");
48 while (res_addr <= PCI_VPD_ADDR_MASK)
50 if (!read_vpd(d, res_addr, &tag, 1, &csum))
54 if (res_addr > PCI_VPD_ADDR_MASK + 1 - 3)
56 if (!read_vpd(d, res_addr + 1, buf, 2, &csum))
58 res_len = buf[0] + (buf[1] << 8);
67 if (res_len > PCI_VPD_ADDR_MASK + 1 - res_addr)
79 printf("\t\tProduct Name: ");
80 while (part_pos < res_len)
82 part_len = res_len - part_pos;
83 if (part_len > sizeof(buf))
84 part_len = sizeof(buf);
85 if (!read_vpd(d, res_addr + part_pos, buf, part_len, &csum))
87 print_vpd_string(buf, part_len);
95 printf("\t\t%s fields:\n",
96 (tag == 0x90) ? "Read-only" : "Read/write");
98 while (part_pos + 3 <= res_len)
102 if (!read_vpd(d, res_addr + part_pos, buf, 3, &csum))
108 if (part_len > res_len - part_pos)
111 /* Only read the first byte of the RV field because the
112 * remaining bytes are not included in the checksum. */
113 read_len = (key[0] == 'R' && key[1] == 'V') ? 1 : part_len;
114 if (!read_vpd(d, res_addr + part_pos, buf, read_len, &csum))
117 if ((key[0] == 'E' && key[1] == 'C') ||
118 (key[0] == 'P' && key[1] == 'N') ||
119 (key[0] == 'S' && key[1] == 'N') ||
123 /* Alphanumeric content */
124 printf("\t\t\t%c%c: ", key[0], key[1]);
125 print_vpd_string(buf, part_len);
128 else if (key[0] == 'R' && key[1] == 'V')
130 /* Reserved and checksum */
131 printf("\t\t\tRV: checksum %s, %d byte(s) reserved\n",
132 csum ? "bad" : "good", part_len - 1);
134 else if (key[0] == 'R' && key[1] == 'W')
136 /* Read-write area */
137 printf("\t\t\tRW: %d byte(s) free\n", part_len);
141 /* Binary or unknown content */
143 printf("\t\t\t%c%c:", key[0], key[1]);
144 for (i = 0; i < part_len; i++)
145 printf(" %02x", buf[i]);
149 part_pos += part_len;
154 printf("\t\tUnknown %s resource type %02x\n",
155 (tag & 0x80) ? "large" : "small", tag & ~0x80);
163 printf("\t\tNot readable\n");
165 printf("\t\tNo end tag found\n");