blob: 70fba57d610326f684ea2b97b07369cd4e8678a6 [file] [log] [blame]
Bjorn Helgaas7328c8f2018-01-26 11:45:16 -06001// SPDX-License-Identifier: GPL-2.0
Matt Carlsonb55ac1b2010-02-26 14:04:41 +00002/*
3 * File: vpd.c
4 * Purpose: Provide PCI VPD support
5 *
6 * Copyright (C) 2010 Broadcom Corporation.
7 */
8
9#include <linux/pci.h>
Paul Gortmaker363c75d2011-05-27 09:37:25 -040010#include <linux/export.h>
Matt Carlsonb55ac1b2010-02-26 14:04:41 +000011
12int pci_vpd_find_tag(const u8 *buf, unsigned int off, unsigned int len, u8 rdt)
13{
14 int i;
15
16 for (i = off; i < len; ) {
17 u8 val = buf[i];
18
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;
23
24 if (val == rdt)
25 return i;
26
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;
31
32 if (tag == rdt)
33 return i;
34
35 if (tag == PCI_VPD_SRDT_END)
36 break;
37
38 i += PCI_VPD_SRDT_TAG_SIZE +
39 pci_vpd_srdt_size(&buf[i]);
40 }
41 }
42
43 return -ENOENT;
44}
45EXPORT_SYMBOL_GPL(pci_vpd_find_tag);
Matt Carlson4067a852010-02-26 14:04:43 +000046
47int pci_vpd_find_info_keyword(const u8 *buf, unsigned int off,
48 unsigned int len, const char *kw)
49{
50 int i;
51
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;
56
57 i += PCI_VPD_INFO_FLD_HDR_SIZE +
58 pci_vpd_info_field_size(&buf[i]);
59 }
60
61 return -ENOENT;
62}
63EXPORT_SYMBOL_GPL(pci_vpd_find_info_keyword);