source: rtems/c/src/lib/libbsp/i386/shared/pci/pci_io.c @ 364866d

Last change on this file since 364866d was 364866d, checked in by Joel Sherrill <joel@…>, on Mar 16, 2016 at 12:36:41 AM

pc386: Do not include rtems/pci.h from bsp.h. Add bsp/bspimpl.h

Start to migrate private symbols to bsp/bspimpl.h.

  • Property mode set to 100644
File size: 4.7 KB
Line 
1/**
2 * @file
3 *
4 * PCI Support when Configuration Space is in I/O
5 */
6
7/*
8 *  COPYRIGHT (c) 2016.
9 *  On-Line Applications Research Corporation (OAR).
10 *
11 *  The license and distribution terms for this file may be
12 *  found in the file LICENSE in this distribution or at
13 *  http://www.rtems.org/license/LICENSE.
14 */
15
16#include <rtems.h>
17#include <bsp.h>
18#include <bsp/bspimpl.h>
19
20static int pci_io_initialized = 0;
21
22/*
23 * Forward reference. Initialized at bottom.
24 */
25static const pci_config_access_functions pci_io_indirect_functions;
26
27/*
28 * Detects presense of PCI Configuration is in I/O space. If so, return
29 * pointer to accessor methods.
30 *
31 * NOTE: TBD to determine if (a) PCI Bus exists and (b) this is the
32 *       access method.
33 */
34const pci_config_access_functions *pci_io_initialize(void)
35{
36  pci_io_initialized = 1;
37
38  printk( "PCI I/O Support Initialized\n" );
39
40  return &pci_io_indirect_functions;
41}
42
43/*
44 * Build PCI Address
45 */
46static inline uint32_t pci_io_build_address(
47  uint16_t  bus,
48  uint16_t  slot,
49  uint16_t  function,
50  uint16_t  offset
51)
52{
53  uint32_t bus_u32      = (uint32_t)bus;
54  uint32_t slot_u32     = (uint32_t)slot;
55  uint32_t function_u32 = (uint32_t)function;
56  uint32_t address;
57
58  /*
59   * create configuration address as per figure at
60   *   http://wiki.osdev.org/PCI#Configuration_Space_Access_Mechanism_.231
61   */
62  address  = (uint32_t) 0x80000000;  /* Bit  31    - Enable Bit */
63                                     /* Bits 30-24 - Reserved */
64  address |= bus_u32 << 16;          /* Bits 23-16 - Bus Number */
65  address |= slot_u32 << 11;         /* Bits 15-11 - Device/Slot Number */
66  address |= function_u32 << 8;      /* Bits 10-8  - Function Number */
67  address |= offset & 0xfc;          /* Bits 7-2   - Offset/Register Number */
68                                     /* Bits 1-0   - Reserved 0 */
69  return address;
70}
71
72static int BSP_pci_read_config_byte(
73  unsigned char bus,
74  unsigned char slot,
75  unsigned char function,
76  unsigned char offset,
77  unsigned char *value
78)
79{
80  uint32_t address;
81  uint32_t tmp;
82
83  address = pci_io_build_address( bus, slot, function, offset );
84
85  /* write out the address */
86  outport_long(0xCF8, address);
87
88  /* read in the data */
89  inport_long(0xCFC, tmp);
90
91  /* (offset & 3) * 8) = 0 will choose the first byte of the 32 bits register */
92  *value = (uint16_t)(tmp >> ((offset & 3) * 8)) & 0xff;
93  return PCIBIOS_SUCCESSFUL;
94}
95
96static int BSP_pci_read_config_word(
97  unsigned char bus,
98  unsigned char slot,
99  unsigned char function,
100  unsigned char offset,
101  unsigned short *value
102)
103{
104  uint32_t address;
105  uint32_t tmp;
106
107  address = pci_io_build_address( bus, slot, function, offset );
108
109  /* write out the address */
110  outport_long(0xCF8, address);
111
112  /* read in the data */
113  inport_long(0xCFC, tmp);
114
115  /* (offset & 2) * 8) = 0 will choose the first word of the 32 bits register */
116  *value = (uint16_t)(tmp >> ((offset & 2) * 8)) & 0xffff;
117  return PCIBIOS_SUCCESSFUL;
118}
119
120static int BSP_pci_read_config_dword(
121  unsigned char bus,
122  unsigned char slot,
123  unsigned char function,
124  unsigned char offset,
125  uint32_t     *value
126)
127{
128  uint32_t address;
129  uint32_t tmp;
130
131  address = pci_io_build_address( bus, slot, function, offset );
132
133  /* write out the address */
134  outport_long(0xCF8, address);
135
136  /* read in the data */
137  inport_long(0xCFC, tmp);
138
139  *value = tmp;
140  return PCIBIOS_SUCCESSFUL;
141}
142
143static int BSP_pci_write_config_byte(
144  unsigned char bus,
145  unsigned char slot,
146  unsigned char function,
147  unsigned char offset,
148  unsigned char value
149)
150{
151  uint32_t address;
152
153  address = pci_io_build_address( bus, slot, function, offset );
154
155  /* write out the address */
156  outport_long(0xCF8, address);
157
158  /* read in the data */
159  outport_byte(0xCFC, value);
160
161  return PCIBIOS_SUCCESSFUL;
162}
163
164static int BSP_pci_write_config_word(
165  unsigned char bus,
166  unsigned char slot,
167  unsigned char function,
168  unsigned char offset,
169  unsigned short value
170)
171{
172  uint32_t address;
173
174  address = pci_io_build_address( bus, slot, function, offset );
175
176  /* write out the address */
177  outport_long(0xCF8, address);
178
179  /* read in the data */
180  outport_word(0xCFC, value);
181
182  return PCIBIOS_SUCCESSFUL;
183}
184
185static int BSP_pci_write_config_dword(
186  unsigned char bus,
187  unsigned char slot,
188  unsigned char function,
189  unsigned char offset,
190  uint32_t      value
191)
192{
193  uint32_t address;
194
195  address = pci_io_build_address( bus, slot, function, offset );
196
197  /* write out the address */
198  outport_long(0xCF8, address);
199
200  /* read in the data */
201  outport_long(0xCFC, value);
202
203  return PCIBIOS_SUCCESSFUL;
204}
205
206static const pci_config_access_functions pci_io_indirect_functions = {
207  BSP_pci_read_config_byte,
208  BSP_pci_read_config_word,
209  BSP_pci_read_config_dword,
210  BSP_pci_write_config_byte,
211  BSP_pci_write_config_word,
212  BSP_pci_write_config_dword
213};
Note: See TracBrowser for help on using the repository browser.