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

4.11
Last change on this file since a31845f7 was a31845f7, checked in by Daniel Hellstrom <daniel@…>, on Nov 28, 2011 at 9:11:10 AM

LIBPCI: added PCI layer to cpukit/libpci

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