source: rtems/cpukit/libpci/pci_access.c @ e53daed

4.11
Last change on this file since e53daed was e53daed, checked in by Daniel Hellstrom <daniel@…>, on Apr 9, 2015 at 2:09:42 PM

LIBPCI: updated license to rtems.org

  • Property mode set to 100644
File size: 1.8 KB
Line 
1/*  PCI Access Library
2 *
3 *  COPYRIGHT (c) 2010 Cobham Gaisler AB.
4 *
5 *  The license and distribution terms for this file may be
6 *  found in the file LICENSE in this distribution or at
7 *  http://www.rtems.org/license/LICENSE.
8 */
9
10#include <pci.h>
11#include <pci/access.h>
12
13/* Access Routines valid after a PCI-Access-Driver has registered */
14struct pci_access_drv pci_access_ops = {
15        .cfg = {.read8 = 0},
16};
17
18/* Read a 8-bit register over configuration space */
19int pci_cfg_r8(pci_dev_t dev, int ofs, uint8_t *data)
20{
21        return pci_access_ops.cfg.read8(dev, ofs, data);
22}
23
24/* Read a 16-bit register over configuration space */
25int pci_cfg_r16(pci_dev_t dev, int ofs, uint16_t *data)
26{
27        return pci_access_ops.cfg.read16(dev, ofs, data);
28}
29
30/* Read a 32-bit register over configuration space */
31int pci_cfg_r32(pci_dev_t dev, int ofs, uint32_t *data)
32{
33        return pci_access_ops.cfg.read32(dev, ofs, data);
34}
35
36/* Write a 8-bit register over configuration space */
37int pci_cfg_w8(pci_dev_t dev, int ofs, uint8_t data)
38{
39        return pci_access_ops.cfg.write8(dev, ofs, data);
40}
41
42/* Write a 16-bit register over configuration space */
43int pci_cfg_w16(pci_dev_t dev, int ofs, uint16_t data)
44{
45        return pci_access_ops.cfg.write16(dev, ofs, data);
46}
47
48/* Write a 32-bit register over configuration space */
49int pci_cfg_w32(pci_dev_t dev, int ofs, uint32_t data)
50{
51        return pci_access_ops.cfg.write32(dev, ofs, data);
52}
53
54void pci_modify_cmdsts(pci_dev_t dev, uint32_t mask, uint32_t val)
55{
56        uint32_t data;
57
58        pci_cfg_r32(dev, PCIR_COMMAND, &data);
59        data &= ~mask;
60        data |= val;
61        pci_cfg_w32(dev, PCIR_COMMAND, data);
62}
63
64/* Register a driver for handling access to PCI */
65int pci_access_drv_register(struct pci_access_drv *drv)
66{
67        if (pci_access_ops.cfg.read8)
68                return -1; /* Already registered a driver.. */
69
70        pci_access_ops = *drv;
71
72        return 0;
73}
Note: See TracBrowser for help on using the repository browser.