source: rtems/cpukit/libpci/pci_access_func.c @ 358b8543

4.115
Last change on this file since 358b8543 was a31845f7, checked in by Daniel Hellstrom <daniel@…>, on 11/28/11 at 09:11:10

LIBPCI: added PCI layer to cpukit/libpci

  • Property mode set to 100644
File size: 1.5 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
13/* Get PCI I/O or Configuration space access function */
14static int pci_ioc_func(int wr, int size, void **func, void **ops)
15{
16        int ofs;
17
18        ofs = 0;
19        if (wr)
20                ofs += 3;
21        if (size == 4)
22                size = 3;
23        ofs += (size & 0x3) - 1;
24        if (ops[ofs] == NULL)
25                return -1;
26        if (func)
27                *func = ops[ofs];
28        return 0;
29}
30
31/* Get Registers-over-Memory Space access function */
32static int pci_memreg_func(int wr, int size, void **func, int endian)
33{
34        void **ops;
35        int ofs = 0;
36
37        ops = (void **)pci_access_ops.memreg;
38        if (!ops)
39                return -1;
40
41        if (size == 2)
42                ofs += 2;
43        else if (size == 4)
44                ofs += 6;
45
46        if (size != 1 && endian == PCI_BIG_ENDIAN)
47                ofs += 2;
48
49        if (wr)
50                ofs += 1;
51
52        if (ops[ofs] == NULL)
53                return -1;
54        if (func)
55                *func = ops[ofs];
56        return 0;
57}
58
59/* Get function pointer from Host/BSP driver definitions */
60int pci_access_func(int wr, int size, void **func, int endian, int type)
61{
62        switch (type) {
63        default:
64        case 2: /* Memory Space - not implemented */
65                return -1;
66        case 1: /* I/O space */
67                return pci_ioc_func(wr, size, func, (void**)&pci_access_ops.cfg);
68        case 3: /* Registers over Memory space */
69                return pci_memreg_func(wr, size, func, endian);
70        case 4: /* Configuration space */
71                return pci_ioc_func(wr, size, func, (void**)&pci_access_ops.io);
72        }
73}
Note: See TracBrowser for help on using the repository browser.