Linux 4.16.11
[linux/fpc-iii.git] / drivers / pci / vpd.c
blob70fba57d610326f684ea2b97b07369cd4e8678a6
1 // SPDX-License-Identifier: GPL-2.0
2 /*
3 * File: vpd.c
4 * Purpose: Provide PCI VPD support
6 * Copyright (C) 2010 Broadcom Corporation.
7 */
9 #include <linux/pci.h>
10 #include <linux/export.h>
12 int pci_vpd_find_tag(const u8 *buf, unsigned int off, unsigned int len, u8 rdt)
14 int i;
16 for (i = off; i < len; ) {
17 u8 val = buf[i];
19 if (val & PCI_VPD_LRDT) {
20 /* Don't return success of the tag isn't complete */
21 if (i + PCI_VPD_LRDT_TAG_SIZE > len)
22 break;
24 if (val == rdt)
25 return i;
27 i += PCI_VPD_LRDT_TAG_SIZE +
28 pci_vpd_lrdt_size(&buf[i]);
29 } else {
30 u8 tag = val & ~PCI_VPD_SRDT_LEN_MASK;
32 if (tag == rdt)
33 return i;
35 if (tag == PCI_VPD_SRDT_END)
36 break;
38 i += PCI_VPD_SRDT_TAG_SIZE +
39 pci_vpd_srdt_size(&buf[i]);
43 return -ENOENT;
45 EXPORT_SYMBOL_GPL(pci_vpd_find_tag);
47 int pci_vpd_find_info_keyword(const u8 *buf, unsigned int off,
48 unsigned int len, const char *kw)
50 int i;
52 for (i = off; i + PCI_VPD_INFO_FLD_HDR_SIZE <= off + len;) {
53 if (buf[i + 0] == kw[0] &&
54 buf[i + 1] == kw[1])
55 return i;
57 i += PCI_VPD_INFO_FLD_HDR_SIZE +
58 pci_vpd_info_field_size(&buf[i]);
61 return -ENOENT;
63 EXPORT_SYMBOL_GPL(pci_vpd_find_info_keyword);