1*3f2dd94aSFrançois Tigeot /*
2*3f2dd94aSFrançois Tigeot * Copyright (c) 2020 François Tigeot <ftigeot@wolfpond.org>
3*3f2dd94aSFrançois Tigeot * All rights reserved.
4*3f2dd94aSFrançois Tigeot *
5*3f2dd94aSFrançois Tigeot * Redistribution and use in source and binary forms, with or without
6*3f2dd94aSFrançois Tigeot * modification, are permitted provided that the following conditions
7*3f2dd94aSFrançois Tigeot * are met:
8*3f2dd94aSFrançois Tigeot * 1. Redistributions of source code must retain the above copyright
9*3f2dd94aSFrançois Tigeot * notice unmodified, this list of conditions, and the following
10*3f2dd94aSFrançois Tigeot * disclaimer.
11*3f2dd94aSFrançois Tigeot * 2. Redistributions in binary form must reproduce the above copyright
12*3f2dd94aSFrançois Tigeot * notice, this list of conditions and the following disclaimer in the
13*3f2dd94aSFrançois Tigeot * documentation and/or other materials provided with the distribution.
14*3f2dd94aSFrançois Tigeot *
15*3f2dd94aSFrançois Tigeot * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
16*3f2dd94aSFrançois Tigeot * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
17*3f2dd94aSFrançois Tigeot * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
18*3f2dd94aSFrançois Tigeot * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
19*3f2dd94aSFrançois Tigeot * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
20*3f2dd94aSFrançois Tigeot * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
21*3f2dd94aSFrançois Tigeot * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
22*3f2dd94aSFrançois Tigeot * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23*3f2dd94aSFrançois Tigeot * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
24*3f2dd94aSFrançois Tigeot * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25*3f2dd94aSFrançois Tigeot */
26*3f2dd94aSFrançois Tigeot
27*3f2dd94aSFrançois Tigeot #include <linux/pci.h>
28*3f2dd94aSFrançois Tigeot
29*3f2dd94aSFrançois Tigeot int
pcie_capability_read_dword(struct pci_dev * dev,int pos,u32 * dst)30*3f2dd94aSFrançois Tigeot pcie_capability_read_dword(struct pci_dev *dev, int pos, u32 *dst)
31*3f2dd94aSFrançois Tigeot {
32*3f2dd94aSFrançois Tigeot if (pos & 3)
33*3f2dd94aSFrançois Tigeot return -EINVAL;
34*3f2dd94aSFrançois Tigeot
35*3f2dd94aSFrançois Tigeot if (!pcie_capability_reg_implemented(dev, pos))
36*3f2dd94aSFrançois Tigeot return -EINVAL;
37*3f2dd94aSFrançois Tigeot
38*3f2dd94aSFrançois Tigeot return pci_read_config_dword(dev, pci_pcie_cap(dev) + pos, dst);
39*3f2dd94aSFrançois Tigeot }
40