1 |
786 |
skrzyp |
//==========================================================================
|
2 |
|
|
//
|
3 |
|
|
// ppc405_pci.c
|
4 |
|
|
//
|
5 |
|
|
// HAL variant support code for PCI on PowerPC 405GP
|
6 |
|
|
//
|
7 |
|
|
//==========================================================================
|
8 |
|
|
// ####ECOSGPLCOPYRIGHTBEGIN####
|
9 |
|
|
// -------------------------------------------
|
10 |
|
|
// This file is part of eCos, the Embedded Configurable Operating System.
|
11 |
|
|
// Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003, 2004 Free Software Foundation, Inc.
|
12 |
|
|
//
|
13 |
|
|
// eCos is free software; you can redistribute it and/or modify it under
|
14 |
|
|
// the terms of the GNU General Public License as published by the Free
|
15 |
|
|
// Software Foundation; either version 2 or (at your option) any later
|
16 |
|
|
// version.
|
17 |
|
|
//
|
18 |
|
|
// eCos is distributed in the hope that it will be useful, but WITHOUT
|
19 |
|
|
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
20 |
|
|
// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
21 |
|
|
// for more details.
|
22 |
|
|
//
|
23 |
|
|
// You should have received a copy of the GNU General Public License
|
24 |
|
|
// along with eCos; if not, write to the Free Software Foundation, Inc.,
|
25 |
|
|
// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
26 |
|
|
//
|
27 |
|
|
// As a special exception, if other files instantiate templates or use
|
28 |
|
|
// macros or inline functions from this file, or you compile this file
|
29 |
|
|
// and link it with other works to produce a work based on this file,
|
30 |
|
|
// this file does not by itself cause the resulting work to be covered by
|
31 |
|
|
// the GNU General Public License. However the source code for this file
|
32 |
|
|
// must still be made available in accordance with section (3) of the GNU
|
33 |
|
|
// General Public License v2.
|
34 |
|
|
//
|
35 |
|
|
// This exception does not invalidate any other reasons why a work based
|
36 |
|
|
// on this file might be covered by the GNU General Public License.
|
37 |
|
|
// -------------------------------------------
|
38 |
|
|
// ####ECOSGPLCOPYRIGHTEND####
|
39 |
|
|
//==========================================================================
|
40 |
|
|
//#####DESCRIPTIONBEGIN####
|
41 |
|
|
//
|
42 |
|
|
// Author(s): Gary Thomas <gary@mlbassoc.com>
|
43 |
|
|
// Contributors:
|
44 |
|
|
// Date: 2003-09-02
|
45 |
|
|
// Purpose: HAL PCI support
|
46 |
|
|
// Description: Implementations of HAL PCI interfaces
|
47 |
|
|
//
|
48 |
|
|
//####DESCRIPTIONEND####
|
49 |
|
|
//
|
50 |
|
|
//========================================================================*/
|
51 |
|
|
|
52 |
|
|
#define CYGARC_HAL_COMMON_EXPORT_CPU_MACROS
|
53 |
|
|
#include <pkgconf/hal.h>
|
54 |
|
|
#include <pkgconf/system.h>
|
55 |
|
|
#include CYGBLD_HAL_PLATFORM_H
|
56 |
|
|
|
57 |
|
|
#include <cyg/infra/cyg_type.h> // base types
|
58 |
|
|
#include <cyg/infra/cyg_trac.h> // tracing macros
|
59 |
|
|
#include <cyg/infra/cyg_ass.h> // assertion macros
|
60 |
|
|
#include <cyg/infra/diag.h> // diag_printf() and friends
|
61 |
|
|
|
62 |
|
|
#include <cyg/hal/hal_io.h> // IO macros
|
63 |
|
|
#include <cyg/hal/hal_arch.h> // Register state info
|
64 |
|
|
#include <cyg/hal/hal_diag.h>
|
65 |
|
|
#include <cyg/hal/hal_intr.h> // Interrupt names
|
66 |
|
|
#include <cyg/hal/hal_cache.h>
|
67 |
|
|
#include <cyg/hal/ppc_regs.h> // Hardware definitions
|
68 |
|
|
#include <cyg/hal/hal_if.h> // calling interface API
|
69 |
|
|
|
70 |
|
|
#include <pkgconf/io_pci.h>
|
71 |
|
|
#include <cyg/io/pci_hw.h>
|
72 |
|
|
#include <cyg/io/pci.h>
|
73 |
|
|
|
74 |
|
|
// PCI support
|
75 |
|
|
|
76 |
|
|
externC void
|
77 |
|
|
hal_ppc405_pci_init(void)
|
78 |
|
|
{
|
79 |
|
|
static int _init = 0;
|
80 |
|
|
cyg_uint8 next_bus;
|
81 |
|
|
cyg_uint32 cmd_state, bridge_state;
|
82 |
|
|
|
83 |
|
|
if (_init) return;
|
84 |
|
|
_init = 1;
|
85 |
|
|
|
86 |
|
|
// Configure PCI bridge
|
87 |
|
|
HAL_WRITE_UINT32LE(PCIL0_PMM0PCILA, 0);
|
88 |
|
|
HAL_WRITE_UINT32LE(PCIL0_PMM0PCIHA, 0);
|
89 |
|
|
HAL_WRITE_UINT32LE(PCIL0_PMM0LA, HAL_PCI_PHYSICAL_MEMORY_BASE);
|
90 |
|
|
HAL_WRITE_UINT32LE(PCIL0_PMM0MA, ~(0x10000000-1) | 0x00000001);
|
91 |
|
|
HAL_PCI_CFG_WRITE_UINT32(0, CYG_PCI_DEV_MAKE_DEVFN(0,0), CYG_PCI_CFG_BAR_1, 0);
|
92 |
|
|
HAL_WRITE_UINT32LE(PCIL0_PTM1LA, 0);
|
93 |
|
|
HAL_WRITE_UINT32LE(PCIL0_PTM1MS, ~(0x10000000-1) | 0x00000001);
|
94 |
|
|
// Indicate that the bridge has been configured
|
95 |
|
|
HAL_PCI_CFG_READ_UINT32(0, CYG_PCI_DEV_MAKE_DEVFN(0,0), 0x60, bridge_state);
|
96 |
|
|
bridge_state |= 0x0001;
|
97 |
|
|
HAL_PCI_CFG_WRITE_UINT32(0, CYG_PCI_DEV_MAKE_DEVFN(0,0), 0x60, bridge_state);
|
98 |
|
|
// Setup for bus mastering
|
99 |
|
|
HAL_PCI_CFG_READ_UINT32(0, CYG_PCI_DEV_MAKE_DEVFN(0,0),
|
100 |
|
|
CYG_PCI_CFG_COMMAND, cmd_state);
|
101 |
|
|
cyg_pci_init();
|
102 |
|
|
if ((cmd_state & CYG_PCI_CFG_COMMAND_MEMORY) == 0) {
|
103 |
|
|
#if defined(CYGPKG_IO_PCI_DEBUG)
|
104 |
|
|
diag_printf("Configure PCI bus\n");
|
105 |
|
|
#endif
|
106 |
|
|
HAL_PCI_CFG_WRITE_UINT32(0, CYG_PCI_DEV_MAKE_DEVFN(0,0),
|
107 |
|
|
CYG_PCI_CFG_COMMAND,
|
108 |
|
|
CYG_PCI_CFG_COMMAND_MEMORY |
|
109 |
|
|
CYG_PCI_CFG_COMMAND_MASTER |
|
110 |
|
|
CYG_PCI_CFG_COMMAND_PARITY |
|
111 |
|
|
CYG_PCI_CFG_COMMAND_SERR);
|
112 |
|
|
|
113 |
|
|
// Setup latency timer field
|
114 |
|
|
HAL_PCI_CFG_WRITE_UINT8(0, CYG_PCI_DEV_MAKE_DEVFN(0,0),
|
115 |
|
|
CYG_PCI_CFG_LATENCY_TIMER, 32);
|
116 |
|
|
|
117 |
|
|
// Configure PCI bus.
|
118 |
|
|
next_bus = 1;
|
119 |
|
|
cyg_pci_configure_bus(0, &next_bus);
|
120 |
|
|
}
|
121 |
|
|
#if defined(CYGSEM_HAL_POWERPC_PPC405_PCI_SHOW_BUS)
|
122 |
|
|
if (1) {
|
123 |
|
|
cyg_uint8 req;
|
124 |
|
|
cyg_uint8 devfn;
|
125 |
|
|
cyg_pci_device_id devid;
|
126 |
|
|
cyg_pci_device dev_info;
|
127 |
|
|
int i;
|
128 |
|
|
|
129 |
|
|
devid = CYG_PCI_DEV_MAKE_ID(next_bus-1, 0) | CYG_PCI_NULL_DEVFN;
|
130 |
|
|
while (cyg_pci_find_next(devid, &devid)) {
|
131 |
|
|
devfn = CYG_PCI_DEV_GET_DEVFN(devid);
|
132 |
|
|
cyg_pci_get_device_info(devid, &dev_info);
|
133 |
|
|
HAL_PCI_CFG_READ_UINT8(0, devfn, CYG_PCI_CFG_INT_PIN, req);
|
134 |
|
|
|
135 |
|
|
diag_printf("\n");
|
136 |
|
|
diag_printf("Bus: %d", CYG_PCI_DEV_GET_BUS(devid));
|
137 |
|
|
diag_printf(", PCI Device: %d", CYG_PCI_DEV_GET_DEV(devfn));
|
138 |
|
|
diag_printf(", PCI Func: %d\n", CYG_PCI_DEV_GET_FN(devfn));
|
139 |
|
|
diag_printf(" Vendor Id: 0x%04X", dev_info.vendor);
|
140 |
|
|
diag_printf(", Device Id: 0x%04X", dev_info.device);
|
141 |
|
|
diag_printf(", Command: 0x%04X", dev_info.command);
|
142 |
|
|
diag_printf(", IRQ: %d\n", req);
|
143 |
|
|
for (i = 0; i < dev_info.num_bars; i++) {
|
144 |
|
|
diag_printf(" BAR[%d] 0x%08x /", i, dev_info.base_address[i]);
|
145 |
|
|
diag_printf(" probed size 0x%08x / CPU addr 0x%08x\n",
|
146 |
|
|
dev_info.base_size[i], dev_info.base_map[i]);
|
147 |
|
|
}
|
148 |
|
|
}
|
149 |
|
|
}
|
150 |
|
|
#endif
|
151 |
|
|
}
|
152 |
|
|
|
153 |
|
|
externC void
|
154 |
|
|
hal_ppc405_pci_translate_interrupt(int bus, int devfn, int *vec, int *valid)
|
155 |
|
|
{
|
156 |
|
|
cyg_uint8 req;
|
157 |
|
|
cyg_uint8 dev = CYG_PCI_DEV_GET_DEV(devfn);
|
158 |
|
|
|
159 |
|
|
if ((dev >= CYG_PCI_MIN_DEV) && (dev < CYG_PCI_MAX_DEV)) {
|
160 |
|
|
HAL_PCI_CFG_READ_UINT8(bus, devfn, CYG_PCI_CFG_INT_PIN, req);
|
161 |
|
|
if (0 != req) {
|
162 |
|
|
#ifdef CYG_PCI_IRQ_MAP
|
163 |
|
|
char pci_irq_table[][4] = CYG_PCI_IRQ_MAP;
|
164 |
|
|
#else
|
165 |
|
|
#error "Need platform defined IRQ map"
|
166 |
|
|
#endif
|
167 |
|
|
*vec = pci_irq_table[dev-CYG_PCI_MIN_DEV][req-1];
|
168 |
|
|
*valid = (*vec != -1);
|
169 |
|
|
} else {
|
170 |
|
|
/* Device will not generate interrupt requests. */
|
171 |
|
|
*valid = false;
|
172 |
|
|
}
|
173 |
|
|
#if defined(CYGPKG_IO_PCI_DEBUG)
|
174 |
|
|
diag_printf("Int - dev: %d, req: %d, vector: %d\n", dev, req, *vec);
|
175 |
|
|
#endif
|
176 |
|
|
} else {
|
177 |
|
|
*valid = false; // Invalid device
|
178 |
|
|
}
|
179 |
|
|
}
|
180 |
|
|
|
181 |
|
|
// PCI configuration space access
|
182 |
|
|
#define _EXT_ENABLE 0x80000000 // Could be 0x80000000
|
183 |
|
|
|
184 |
|
|
static __inline__ cyg_uint32
|
185 |
|
|
_cfg_addr(int bus, int devfn, int offset)
|
186 |
|
|
{
|
187 |
|
|
return _EXT_ENABLE | (bus << 16) | (devfn << 8) | (offset << 0);
|
188 |
|
|
}
|
189 |
|
|
|
190 |
|
|
externC cyg_uint8
|
191 |
|
|
hal_ppc405_pci_cfg_read_uint8(int bus, int devfn, int offset)
|
192 |
|
|
{
|
193 |
|
|
cyg_uint32 cfg_addr;
|
194 |
|
|
cyg_uint8 cfg_val = (cyg_uint8) 0xFF;
|
195 |
|
|
|
196 |
|
|
#ifdef CYGPKG_IO_PCI_DEBUG
|
197 |
|
|
diag_printf("%s(bus=%x, devfn=%x, offset=%x) = ", __FUNCTION__, bus, devfn, offset);
|
198 |
|
|
#endif // CYGPKG_IO_PCI_DEBUG
|
199 |
|
|
cfg_addr = _cfg_addr(bus, devfn, offset);
|
200 |
|
|
HAL_WRITE_UINT32LE(PCIC0_CFGADDR, cfg_addr);
|
201 |
|
|
HAL_READ_UINT8LE(PCIC0_CFGDATA|(offset & 0x03), cfg_val);
|
202 |
|
|
#ifdef CYGPKG_IO_PCI_DEBUG
|
203 |
|
|
diag_printf("%x\n", cfg_val);
|
204 |
|
|
#endif // CYGPKG_IO_PCI_DEBUG
|
205 |
|
|
return cfg_val;
|
206 |
|
|
}
|
207 |
|
|
|
208 |
|
|
externC cyg_uint16
|
209 |
|
|
hal_ppc405_pci_cfg_read_uint16(int bus, int devfn, int offset)
|
210 |
|
|
{
|
211 |
|
|
cyg_uint32 cfg_addr;
|
212 |
|
|
cyg_uint16 cfg_val = (cyg_uint16) 0xFFFF;
|
213 |
|
|
|
214 |
|
|
#ifdef CYGPKG_IO_PCI_DEBUG
|
215 |
|
|
diag_printf("%s(bus=%x, devfn=%x, offset=%x) = ", __FUNCTION__, bus, devfn, offset);
|
216 |
|
|
#endif // CYGPKG_IO_PCI_DEBUG
|
217 |
|
|
cfg_addr = _cfg_addr(bus, devfn, offset);
|
218 |
|
|
HAL_WRITE_UINT32LE(PCIC0_CFGADDR, cfg_addr);
|
219 |
|
|
HAL_READ_UINT16LE(PCIC0_CFGDATA|(offset & 0x03), cfg_val);
|
220 |
|
|
#ifdef CYGPKG_IO_PCI_DEBUG
|
221 |
|
|
diag_printf("%x\n", cfg_val);
|
222 |
|
|
#endif // CYGPKG_IO_PCI_DEBUG
|
223 |
|
|
return cfg_val;
|
224 |
|
|
}
|
225 |
|
|
|
226 |
|
|
externC cyg_uint32
|
227 |
|
|
hal_ppc405_pci_cfg_read_uint32(int bus, int devfn, int offset)
|
228 |
|
|
{
|
229 |
|
|
cyg_uint32 cfg_addr;
|
230 |
|
|
cyg_uint32 cfg_val = (cyg_uint32) 0xFFFFFFFF;
|
231 |
|
|
|
232 |
|
|
#ifdef CYGPKG_IO_PCI_DEBUG
|
233 |
|
|
diag_printf("%s(bus=%x, devfn=%x, offset=%x) = ", __FUNCTION__, bus, devfn, offset);
|
234 |
|
|
#endif // CYGPKG_IO_PCI_DEBUG
|
235 |
|
|
cfg_addr = _cfg_addr(bus, devfn, offset);
|
236 |
|
|
HAL_WRITE_UINT32LE(PCIC0_CFGADDR, cfg_addr);
|
237 |
|
|
HAL_READ_UINT32LE(PCIC0_CFGDATA, cfg_val);
|
238 |
|
|
#ifdef CYGPKG_IO_PCI_DEBUG
|
239 |
|
|
diag_printf("%x\n", cfg_val);
|
240 |
|
|
#endif // CYGPKG_IO_PCI_DEBUG
|
241 |
|
|
return cfg_val;
|
242 |
|
|
}
|
243 |
|
|
|
244 |
|
|
externC void
|
245 |
|
|
hal_ppc405_pci_cfg_write_uint8(int bus, int devfn, int offset, cyg_uint8 cfg_val)
|
246 |
|
|
{
|
247 |
|
|
cyg_uint32 cfg_addr;
|
248 |
|
|
|
249 |
|
|
#ifdef CYGPKG_IO_PCI_DEBUG
|
250 |
|
|
diag_printf("%s(bus=%x, devfn=%x, offset=%x, val=%x)\n", __FUNCTION__, bus, devfn, offset, cfg_val);
|
251 |
|
|
#endif // CYGPKG_IO_PCI_DEBUG
|
252 |
|
|
cfg_addr = _cfg_addr(bus, devfn, offset);
|
253 |
|
|
HAL_WRITE_UINT32LE(PCIC0_CFGADDR, cfg_addr);
|
254 |
|
|
HAL_WRITE_UINT8LE(PCIC0_CFGDATA|(offset & 0x03), cfg_val);
|
255 |
|
|
}
|
256 |
|
|
|
257 |
|
|
externC void
|
258 |
|
|
hal_ppc405_pci_cfg_write_uint16(int bus, int devfn, int offset, cyg_uint16 cfg_val)
|
259 |
|
|
{
|
260 |
|
|
cyg_uint32 cfg_addr;
|
261 |
|
|
|
262 |
|
|
#ifdef CYGPKG_IO_PCI_DEBUG
|
263 |
|
|
diag_printf("%s(bus=%x, devfn=%x, offset=%x, val=%x)\n", __FUNCTION__, bus, devfn, offset, cfg_val);
|
264 |
|
|
#endif // CYGPKG_IO_PCI_DEBUG
|
265 |
|
|
cfg_addr = _cfg_addr(bus, devfn, offset);
|
266 |
|
|
HAL_WRITE_UINT32LE(PCIC0_CFGADDR, cfg_addr);
|
267 |
|
|
HAL_WRITE_UINT16LE(PCIC0_CFGDATA|(offset & 0x03), cfg_val);
|
268 |
|
|
}
|
269 |
|
|
|
270 |
|
|
externC void
|
271 |
|
|
hal_ppc405_pci_cfg_write_uint32(int bus, int devfn, int offset, cyg_uint32 cfg_val)
|
272 |
|
|
{
|
273 |
|
|
cyg_uint32 cfg_addr;
|
274 |
|
|
|
275 |
|
|
#ifdef CYGPKG_IO_PCI_DEBUG
|
276 |
|
|
diag_printf("%s(bus=%x, devfn=%x, offset=%x, val=%x)\n", __FUNCTION__, bus, devfn, offset, cfg_val);
|
277 |
|
|
#endif // CYGPKG_IO_PCI_DEBUG
|
278 |
|
|
cfg_addr = _cfg_addr(bus, devfn, offset);
|
279 |
|
|
HAL_WRITE_UINT32LE(PCIC0_CFGADDR, cfg_addr);
|
280 |
|
|
HAL_WRITE_UINT32LE(PCIC0_CFGDATA, cfg_val);
|
281 |
|
|
}
|
282 |
|
|
|
283 |
|
|
/*------------------------------------------------------------------------*/
|
284 |
|
|
// EOF ppc405_pci.c
|