OpenCores
URL https://opencores.org/ocsvn/openrisc/openrisc/trunk

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [rtos/] [ecos-3.0/] [packages/] [hal/] [mips/] [vrc437x/] [current/] [include/] [plf_io.h] - Blame information for rev 786

Details | Compare with Previous | View Log

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

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.