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 */ |
---|
14 | struct pci_access_drv pci_access_ops; |
---|
15 | |
---|
16 | /* Read a 8-bit register over configuration space */ |
---|
17 | int 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 */ |
---|
23 | int 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 */ |
---|
29 | int 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 */ |
---|
35 | int 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 */ |
---|
41 | int 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 */ |
---|
47 | int 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 | |
---|
52 | void 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 */ |
---|
63 | int 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 | } |
---|