source: rtems/cpukit/libpci/pci_access.c @ 91df5a69

Last change on this file since 91df5a69 was 91df5a69, checked in by Daniel Hellstrom <daniel@…>, on Jan 2, 2015 at 12:17:18 PM

libpci: code cleanup

  • 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
16/* Read a 8-bit register over configuration space */
17int pci_cfg_r8(pci_dev_t dev, int ofs, uint8_t *data)
18{
19        return pci_access_ops.cfg.read8(dev, ofs, data);
20}
21
22/* Read a 16-bit register over configuration space */
23int pci_cfg_r16(pci_dev_t dev, int ofs, uint16_t *data)
24{
25        return pci_access_ops.cfg.read16(dev, ofs, data);
26}
27
28/* Read a 32-bit register over configuration space */
29int pci_cfg_r32(pci_dev_t dev, int ofs, uint32_t *data)
30{
31        return pci_access_ops.cfg.read32(dev, ofs, data);
32}
33
34/* Write a 8-bit register over configuration space */
35int pci_cfg_w8(pci_dev_t dev, int ofs, uint8_t data)
36{
37        return pci_access_ops.cfg.write8(dev, ofs, data);
38}
39
40/* Write a 16-bit register over configuration space */
41int pci_cfg_w16(pci_dev_t dev, int ofs, uint16_t data)
42{
43        return pci_access_ops.cfg.write16(dev, ofs, data);
44}
45
46/* Write a 32-bit register over configuration space */
47int pci_cfg_w32(pci_dev_t dev, int ofs, uint32_t data)
48{
49        return pci_access_ops.cfg.write32(dev, ofs, data);
50}
51
52void pci_modify_cmdsts(pci_dev_t dev, uint32_t mask, uint32_t val)
53{
54        uint32_t data;
55
56        pci_cfg_r32(dev, PCIR_COMMAND, &data);
57        data &= ~mask;
58        data |= val;
59        pci_cfg_w32(dev, PCIR_COMMAND, data);
60}
61
62/* Register a driver for handling access to PCI */
63int pci_access_drv_register(struct pci_access_drv *drv)
64{
65        if (pci_access_ops.cfg.read8)
66                return -1; /* Already registered a driver.. */
67
68        pci_access_ops = *drv;
69
70        return 0;
71}
Note: See TracBrowser for help on using the repository browser.