1 |
27 |
unneback |
#ifndef CYGONCE_PLF_IO_H
|
2 |
|
|
#define CYGONCE_PLF_IO_H
|
3 |
|
|
|
4 |
|
|
//=============================================================================
|
5 |
|
|
//
|
6 |
|
|
// plf_io.h
|
7 |
|
|
//
|
8 |
|
|
// Platform specific IO support
|
9 |
|
|
//
|
10 |
|
|
//=============================================================================
|
11 |
|
|
//####ECOSGPLCOPYRIGHTBEGIN####
|
12 |
|
|
// -------------------------------------------
|
13 |
|
|
// This file is part of eCos, the Embedded Configurable Operating System.
|
14 |
|
|
// Copyright (C) 1998, 1999, 2000, 2001, 2002 Red Hat, Inc.
|
15 |
|
|
//
|
16 |
|
|
// eCos is free software; you can redistribute it and/or modify it under
|
17 |
|
|
// the terms of the GNU General Public License as published by the Free
|
18 |
|
|
// Software Foundation; either version 2 or (at your option) any later version.
|
19 |
|
|
//
|
20 |
|
|
// eCos is distributed in the hope that it will be useful, but WITHOUT ANY
|
21 |
|
|
// WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
22 |
|
|
// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
23 |
|
|
// for more details.
|
24 |
|
|
//
|
25 |
|
|
// You should have received a copy of the GNU General Public License along
|
26 |
|
|
// with eCos; if not, write to the Free Software Foundation, Inc.,
|
27 |
|
|
// 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
|
28 |
|
|
//
|
29 |
|
|
// As a special exception, if other files instantiate templates or use macros
|
30 |
|
|
// or inline functions from this file, or you compile this file and link it
|
31 |
|
|
// with other works to produce a work based on this file, this file does not
|
32 |
|
|
// by itself cause the resulting work to be covered by the GNU General Public
|
33 |
|
|
// License. However the source code for this file must still be made available
|
34 |
|
|
// in accordance with section (3) of the GNU General Public License.
|
35 |
|
|
//
|
36 |
|
|
// This exception does not invalidate any other reasons why a work based on
|
37 |
|
|
// this file might be covered by the GNU General Public License.
|
38 |
|
|
//
|
39 |
|
|
// Alternative licenses for eCos may be arranged by contacting Red Hat, Inc.
|
40 |
|
|
// at http://sources.redhat.com/ecos/ecos-license/
|
41 |
|
|
// -------------------------------------------
|
42 |
|
|
//####ECOSGPLCOPYRIGHTEND####
|
43 |
|
|
//=============================================================================
|
44 |
|
|
//#####DESCRIPTIONBEGIN####
|
45 |
|
|
//
|
46 |
|
|
// Author(s): hmt, jskov, nickg
|
47 |
|
|
// Contributors: hmt, jskov, nickg
|
48 |
|
|
// Date: 1999-08-09
|
49 |
|
|
// Purpose: VRC4373 PCI IO support macros
|
50 |
|
|
// Description:
|
51 |
|
|
// Usage: #include <cyg/hal/plf_io.h>
|
52 |
|
|
//
|
53 |
|
|
// Note: Based on information in
|
54 |
|
|
// "VRC4373 System Controller Data Sheet"
|
55 |
|
|
//####DESCRIPTIONEND####
|
56 |
|
|
//
|
57 |
|
|
//=============================================================================
|
58 |
|
|
|
59 |
|
|
#include <pkgconf/hal.h>
|
60 |
|
|
|
61 |
|
|
#include <cyg/hal/hal_io.h> // IO macros
|
62 |
|
|
#include <cyg/hal/hal_intr.h> // Interrupt vectors
|
63 |
|
|
|
64 |
|
|
//-----------------------------------------------------------------------------
|
65 |
|
|
// PCI access registers
|
66 |
|
|
|
67 |
|
|
#define HAL_PCI_ADDRESS_WINDOW_1 0xAF000014
|
68 |
|
|
#define HAL_PCI_ADDRESS_WINDOW_2 0xAF000018
|
69 |
|
|
#define HAL_PCI_IO_WINDOW 0xAF000024
|
70 |
|
|
#define HAL_PCI_CONFIG_SPACE_DATA 0xAF000028
|
71 |
|
|
#define HAL_PCI_CONFIG_SPACE_ADDR 0xAF00002C
|
72 |
|
|
#define HAL_PCI_ENABLE_REG 0xAF000074
|
73 |
|
|
|
74 |
|
|
//-----------------------------------------------------------------------------
|
75 |
|
|
// Mappings for PCI memory and IO spaces
|
76 |
|
|
|
77 |
|
|
// This is where the PCI spaces are mapped in the CPU's (virtual)
|
78 |
|
|
// address space.
|
79 |
|
|
#define HAL_PCI_PHYSICAL_IO_BASE 0xA0000000
|
80 |
|
|
#define HAL_PCI_PHYSICAL_MEMORY_BASE 0xBC100000
|
81 |
|
|
|
82 |
|
|
//-----------------------------------------------------------------------------
|
83 |
|
|
|
84 |
|
|
// Initialize the PCI bus.
|
85 |
|
|
externC void cyg_hal_plf_pci_init(void);
|
86 |
|
|
#define HAL_PCI_INIT() cyg_hal_plf_pci_init()
|
87 |
|
|
|
88 |
|
|
// Compute address necessary to access PCI config space for the given
|
89 |
|
|
// bus and device.
|
90 |
|
|
#define HAL_PCI_CONFIG_ADDRESS( __bus, __devfn, __offset ) \
|
91 |
|
|
({ \
|
92 |
|
|
cyg_uint32 __addr; \
|
93 |
|
|
cyg_uint32 __dev = CYG_PCI_DEV_GET_DEV(__devfn); \
|
94 |
|
|
if (0 == __bus) { \
|
95 |
|
|
__addr = (1 << (__dev+16)); \
|
96 |
|
|
} else { \
|
97 |
|
|
/* We need better info about how to form type 1 addresses */ \
|
98 |
|
|
__addr = 0x800000000 | (__bus << 16) | (__dev << 11); \
|
99 |
|
|
} \
|
100 |
|
|
__addr |= CYG_PCI_DEV_GET_FN(__devfn) << 8; \
|
101 |
|
|
__addr |= (__offset)&~3; \
|
102 |
|
|
__addr; \
|
103 |
|
|
})
|
104 |
|
|
|
105 |
|
|
// The following function allows us to read locations in the PCI config
|
106 |
|
|
// space that we are not sure contains a valid device. Support in platform.S
|
107 |
|
|
// catches and fixes any bus errors caused.
|
108 |
|
|
externC CYG_WORD32 hal_pci_config_read(CYG_ADDRESS addr);
|
109 |
|
|
#define HAL_PCI_CONFIG_READ( __addr, __val ) __val = hal_pci_config_read(__addr)
|
110 |
|
|
|
111 |
|
|
// Read a value from the PCI configuration space of the appropriate
|
112 |
|
|
// size at an address composed from the bus, devfn and offset.
|
113 |
|
|
// We can only make 32 bit accesses to the PCI config data register, hence
|
114 |
|
|
// all the shifing and masking in these macros.
|
115 |
|
|
// Note that we may only use HAL_PCI_CONFIG_READ() here.
|
116 |
|
|
#define HAL_PCI_CFG_READ_UINT8( __bus, __devfn, __offset, __val ) \
|
117 |
|
|
CYG_MACRO_START \
|
118 |
|
|
CYG_WORD32 _val_; \
|
119 |
|
|
CYG_WORD32 _offset_ = __offset & 3; \
|
120 |
|
|
HAL_WRITE_UINT32(HAL_PCI_CONFIG_SPACE_ADDR, \
|
121 |
|
|
HAL_PCI_CONFIG_ADDRESS(__bus, __devfn, __offset)); \
|
122 |
|
|
HAL_PCI_CONFIG_READ(HAL_PCI_CONFIG_SPACE_DATA, _val_); \
|
123 |
|
|
__val = (CYG_BYTE)((_val_>>(_offset_*8))&0xFF); \
|
124 |
|
|
CYG_MACRO_END
|
125 |
|
|
|
126 |
|
|
#define HAL_PCI_CFG_READ_UINT16( __bus, __devfn, __offset, __val ) \
|
127 |
|
|
CYG_MACRO_START \
|
128 |
|
|
CYG_WORD32 _val_; \
|
129 |
|
|
CYG_WORD32 _offset_ = __offset & 2; \
|
130 |
|
|
HAL_WRITE_UINT32(HAL_PCI_CONFIG_SPACE_ADDR, \
|
131 |
|
|
HAL_PCI_CONFIG_ADDRESS(__bus, __devfn, __offset)); \
|
132 |
|
|
HAL_PCI_CONFIG_READ(HAL_PCI_CONFIG_SPACE_DATA, _val_); \
|
133 |
|
|
__val = (CYG_WORD16)((_val_>>(_offset_*8))&0xFFFF); \
|
134 |
|
|
CYG_MACRO_END
|
135 |
|
|
|
136 |
|
|
#define HAL_PCI_CFG_READ_UINT32( __bus, __devfn, __offset, __val ) \
|
137 |
|
|
CYG_MACRO_START \
|
138 |
|
|
CYG_WORD32 _val_; \
|
139 |
|
|
HAL_WRITE_UINT32(HAL_PCI_CONFIG_SPACE_ADDR, \
|
140 |
|
|
HAL_PCI_CONFIG_ADDRESS(__bus, __devfn, __offset)); \
|
141 |
|
|
HAL_PCI_CONFIG_READ(HAL_PCI_CONFIG_SPACE_DATA, _val_); \
|
142 |
|
|
__val = (CYG_WORD32)_val_; \
|
143 |
|
|
CYG_MACRO_END
|
144 |
|
|
|
145 |
|
|
// Write a value to the PCI configuration space of the appropriate
|
146 |
|
|
// size at an address composed from the bus, devfn and offset.
|
147 |
|
|
// We can only make 32 bit accesses to the PCI config data register, hence
|
148 |
|
|
// all the shifing and masking in these macros.
|
149 |
|
|
// Note that we do not need to use HAL_PCI_CONFIG_READ() here since we
|
150 |
|
|
// should not be writing to config space locations that we do not already
|
151 |
|
|
// know are valid.
|
152 |
|
|
#define HAL_PCI_CFG_WRITE_UINT8( __bus, __devfn, __offset, __val ) \
|
153 |
|
|
CYG_MACRO_START \
|
154 |
|
|
CYG_WORD32 _val_; \
|
155 |
|
|
CYG_WORD32 _offset_ = __offset & 3; \
|
156 |
|
|
HAL_WRITE_UINT32(HAL_PCI_CONFIG_SPACE_ADDR, \
|
157 |
|
|
HAL_PCI_CONFIG_ADDRESS(__bus, __devfn, __offset)); \
|
158 |
|
|
HAL_READ_UINT32(HAL_PCI_CONFIG_SPACE_DATA, _val_); \
|
159 |
|
|
_val_ &= ~(0xFF<<(_offset_*8)); \
|
160 |
|
|
_val_ |= (__val)<<(_offset_*8); \
|
161 |
|
|
HAL_WRITE_UINT32(HAL_PCI_CONFIG_SPACE_DATA, _val_); \
|
162 |
|
|
CYG_MACRO_END
|
163 |
|
|
|
164 |
|
|
#define HAL_PCI_CFG_WRITE_UINT16( __bus, __devfn, __offset, __val ) \
|
165 |
|
|
CYG_MACRO_START \
|
166 |
|
|
CYG_WORD32 _val_; \
|
167 |
|
|
CYG_WORD32 _offset_ = __offset & 2; \
|
168 |
|
|
HAL_WRITE_UINT32(HAL_PCI_CONFIG_SPACE_ADDR, \
|
169 |
|
|
HAL_PCI_CONFIG_ADDRESS(__bus, __devfn, __offset)); \
|
170 |
|
|
HAL_READ_UINT32(HAL_PCI_CONFIG_SPACE_DATA, _val_); \
|
171 |
|
|
_val_ &= ~(0xFFFF<<(_offset_*8)); \
|
172 |
|
|
_val_ |= (__val)<<(_offset_*8); \
|
173 |
|
|
HAL_WRITE_UINT32(HAL_PCI_CONFIG_SPACE_DATA, _val_); \
|
174 |
|
|
CYG_MACRO_END
|
175 |
|
|
|
176 |
|
|
#define HAL_PCI_CFG_WRITE_UINT32( __bus, __devfn, __offset, __val ) \
|
177 |
|
|
CYG_MACRO_START \
|
178 |
|
|
HAL_WRITE_UINT32(HAL_PCI_CONFIG_SPACE_ADDR, \
|
179 |
|
|
HAL_PCI_CONFIG_ADDRESS(__bus, __devfn, __offset)); \
|
180 |
|
|
HAL_WRITE_UINT32(HAL_PCI_CONFIG_SPACE_DATA, __val); \
|
181 |
|
|
CYG_MACRO_END
|
182 |
|
|
|
183 |
|
|
|
184 |
|
|
//-----------------------------------------------------------------------------
|
185 |
|
|
// Resources
|
186 |
|
|
|
187 |
|
|
// Map PCI device resources starting from these addresses in PCI space.
|
188 |
|
|
#define HAL_PCI_ALLOC_BASE_MEMORY 0
|
189 |
|
|
#define HAL_PCI_ALLOC_BASE_IO 0x0c000000
|
190 |
|
|
|
191 |
|
|
// Translate the PCI interrupt requested by the device (INTA#, INTB#,
|
192 |
|
|
// INTC# or INTD#) to the associated CPU interrupt (i.e., HAL vector).
|
193 |
|
|
// We don't actually know what the mappings are at present for this
|
194 |
|
|
// board. The following is therefore just a temporary guess until
|
195 |
|
|
// we can find out.
|
196 |
|
|
|
197 |
|
|
#define HAL_PCI_TRANSLATE_INTERRUPT( __bus, __devfn, __vec, __valid) \
|
198 |
|
|
CYG_MACRO_START \
|
199 |
|
|
cyg_uint8 __req; \
|
200 |
|
|
HAL_PCI_CFG_READ_UINT8(__bus, __devfn, CYG_PCI_CFG_INT_PIN, __req); \
|
201 |
|
|
if (0 != __req) { \
|
202 |
|
|
CYG_ADDRWORD __translation[4] = { \
|
203 |
|
|
CYGNUM_HAL_INTERRUPT_PCI_INTA, /* INTA# */ \
|
204 |
|
|
CYGNUM_HAL_INTERRUPT_PCI_INTB, /* INTB# */ \
|
205 |
|
|
CYGNUM_HAL_INTERRUPT_PCI_INTC, /* INTC# */ \
|
206 |
|
|
CYGNUM_HAL_INTERRUPT_PCI_INTD };/* INTD# */ \
|
207 |
|
|
\
|
208 |
|
|
__vec = __translation[(((__req-1)+CYG_PCI_DEV_GET_DEV(__devfn))&3)]; \
|
209 |
|
|
\
|
210 |
|
|
__valid = true; \
|
211 |
|
|
} else { \
|
212 |
|
|
/* Device will not generate interrupt requests. */ \
|
213 |
|
|
__valid = false; \
|
214 |
|
|
} \
|
215 |
|
|
CYG_MACRO_END
|
216 |
|
|
|
217 |
|
|
// Ignore all devices on not on bus 0 since those all seem to map to the
|
218 |
|
|
// Nile II controller itself.
|
219 |
|
|
#define HAL_PCI_IGNORE_DEVICE(__bus, __dev, __fn) \
|
220 |
|
|
((__bus) != 0)
|
221 |
|
|
|
222 |
|
|
//-----------------------------------------------------------------------------
|
223 |
|
|
// end of plf_io.h
|
224 |
|
|
#endif // CYGONCE_PLF_IO_H
|