compat/nes: Adding pci_zalloc_consistent backport
[compat-rdma/compat.git] / compat / compat-2.6.34.c
1 /*
2  * Copyright 2012    Luis R. Rodriguez <mcgrof@do-not-panic.com>
3  *
4  * This program is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License version 2 as
6  * published by the Free Software Foundation.
7  *
8  * Compatibility file for Linux wireless for kernels 2.6.34.
9  */
10
11 #include <linux/pci.h>
12 #include <linux/export.h>
13
14 int pci_vpd_find_tag(const u8 *buf, unsigned int off, unsigned int len, u8 rdt)
15 {
16         int i;
17
18         for (i = off; i < len; ) {
19                 u8 val = buf[i];
20
21                 if (val & PCI_VPD_LRDT) {
22                         /* Don't return success of the tag isn't complete */
23                         if (i + PCI_VPD_LRDT_TAG_SIZE > len)
24                                 break;
25
26                         if (val == rdt)
27                                 return i;
28
29                         i += PCI_VPD_LRDT_TAG_SIZE +
30                              pci_vpd_lrdt_size(&buf[i]);
31                 } else {
32                         u8 tag = val & ~PCI_VPD_SRDT_LEN_MASK;
33
34                         if (tag == rdt)
35                                 return i;
36
37                         if (tag == PCI_VPD_SRDT_END)
38                                 break;
39
40                         i += PCI_VPD_SRDT_TAG_SIZE +
41                              pci_vpd_srdt_size(&buf[i]);
42                 }
43         }
44
45         return -ENOENT;
46 }
47 EXPORT_SYMBOL_GPL(pci_vpd_find_tag);
48
49 int pci_vpd_find_info_keyword(const u8 *buf, unsigned int off,
50                               unsigned int len, const char *kw)
51 {
52         int i;
53
54         for (i = off; i + PCI_VPD_INFO_FLD_HDR_SIZE <= off + len;) {
55                 if (buf[i + 0] == kw[0] &&
56                     buf[i + 1] == kw[1])
57                         return i;
58
59                 i += PCI_VPD_INFO_FLD_HDR_SIZE +
60                      pci_vpd_info_field_size(&buf[i]);
61         }
62
63         return -ENOENT;
64 }
65 EXPORT_SYMBOL_GPL(pci_vpd_find_info_keyword);