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

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [rtos/] [ecos-3.0/] [packages/] [hal/] [arm/] [ebsa285/] [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 
46
// Contributors: hmt, jskov
47
// Date:         1999-08-09
48
// Purpose:      Intel EBSA285 PCI IO support macros
49
// Description: 
50
// Usage:        #include <cyg/hal/plf_io.h>
51
//
52
// Note:         Based on information in 
53
//               "21285 Core Logic for SA-110 Microprocessor"
54
//####DESCRIPTIONEND####
55
//
56
//=============================================================================
57
 
58
#include <pkgconf/hal_arm_ebsa285.h>
59
 
60
#include <cyg/hal/hal_ebsa285.h>
61
 
62
#include <cyg/hal/hal_io.h>             // IO macros
63
#include <cyg/hal/hal_platform_ints.h>  // Interrupt vectors
64
 
65
// Memory map is 1-1
66
#define CYGARC_PHYSICAL_ADDRESS(_x_) (_x_)
67
 
68
// The PCI resources required by the EBSA are hardcoded to the lowest
69
// addresses in the PCI address space, thus:
70
// PCI Memory Space
71
#define EBSA_SDRAM_PCI_ADDR   0
72
#define EBSA_SDRAM_PCI_SIZE   (CYGHWR_HAL_ARM_EBSA285_PCI_MEM_MAP_SIZE)
73
#define EBSA_CSR_MEM_PCI_ADDR (EBSA_SDRAM_PCI_SIZE)
74
#define EBSA_CSR_MEM_PCI_SIZE 0x80
75
// PCI IO Space
76
#define EBSA_CSR_IO_PCI_ADDR  0
77
#define EBSA_CSR_IO_PCI_SIZE  0x80
78
 
79
// Incidentally I now understand why it's necessary to force PCI reset
80
// (2000-08-07) - with RedBoot in ROM, the RAM app was unconditionally
81
// reinitializing the PCI bus when it was already initialized, without
82
// resetting it.  We cannot play the same game here as with
83
// hal_platform_setup.h - I tried - because otherwise the net cannot
84
// re-initialize itself; the scan for devices fails.
85
 
86
// Initialize the PCI bus.
87
#define HAL_PCI_INIT()                                                   \
88
    CYG_MACRO_START                                                      \
89
    cyg_uint32 __tmp, __tmp2;                                            \
90
                                                                         \
91
    /* Assert PCI_reset                                               */ \
92
    HAL_READ_UINT32(SA110_CONTROL, __tmp);                               \
93
    __tmp &= ~SA110_CONTROL_RST_I;                                       \
94
    HAL_WRITE_UINT32(SA110_CONTROL, __tmp);                              \
95
                                                                         \
96
    /* Disable PCI Outbound interrupts                                */ \
97
    /* (according to 7-14 SA110_OUT_INT_MASK is not accessible        */ \
98
    /* by SA-100)                                                     */ \
99
    HAL_WRITE_UINT32(SA110_OUT_INT_STATUS,                               \
100
                     SA110_OUT_INT_STATUS_DOORBELL_INT                   \
101
                     |SA110_OUT_INT_STATUS_OUTBOUND_INT);                \
102
                                                                         \
103
    /* Disable Doorbells                                              */ \
104
    HAL_WRITE_UINT32(SA110_DOORBELL_PCI_MASK, 0);                        \
105
    HAL_WRITE_UINT32(SA110_DOORBELL_SA_MASK, 0);                         \
106
                                                                         \
107
    /* Map high PCI address bits to 0                                 */ \
108
    HAL_WRITE_UINT32(SA110_PCI_ADDR_EXT, 0);                             \
109
                                                                         \
110
    /* Interrupt ID to 1                                              */ \
111
    HAL_WRITE_UINT16(SA110_PCI_CFG_INT_LINE, 0x0100);                    \
112
                                                                         \
113
    /* Remove PCI_reset                                               */ \
114
    HAL_READ_UINT32(SA110_CONTROL, __tmp);                               \
115
    __tmp |= SA110_CONTROL_RST_I;                                        \
116
    HAL_WRITE_UINT32(SA110_CONTROL, __tmp);                              \
117
                                                                         \
118
    /* Open a window to SDRAM from PCI address space                  */ \
119
    HAL_WRITE_UINT32(SA110_SDRAM_BASE_ADDRESS_MASK,                      \
120
           ((CYGHWR_HAL_ARM_EBSA285_PCI_MEM_MAP_SIZE-1) & 0xfffc0000));  \
121
    HAL_WRITE_UINT32(SA110_SDRAM_BASE_ADDRESS_OFFSET,                    \
122
             CYGHWR_HAL_ARM_EBSA285_PCI_MEM_MAP_BASE);                   \
123
                                                                         \
124
    /* Only init PCI if central function is set and */                   \
125
    /* standalone bit is cleared                    */                   \
126
    HAL_READ_UINT32(SA110_CONTROL, __tmp);                               \
127
    HAL_READ_UINT32(SA110_XBUS_XCS2, __tmp2);                            \
128
    if ((__tmp & SA110_CONTROL_CFN) == SA110_CONTROL_CFN                 \
129
        && (__tmp2 & SA110_XBUS_XCS2_PCI_DISABLE) == 0) {                \
130
                                                                         \
131
        /* Don't respond to any commands                              */ \
132
        HAL_WRITE_UINT16(SA110_PCI_CFG_COMMAND, 0);                      \
133
                                                                         \
134
        /* Set up default addresses for board's resources.            */ \
135
        HAL_WRITE_UINT32(SA110_PCI_CFG_CSR_MEM_BAR,                      \
136
                         EBSA_CSR_MEM_PCI_ADDR);                         \
137
        HAL_WRITE_UINT32(SA110_PCI_CFG_CSR_IO_BAR, EBSA_CSR_IO_PCI_ADDR);\
138
        HAL_WRITE_UINT32(SA110_PCI_CFG_SDRAM_BAR, EBSA_SDRAM_PCI_ADDR);  \
139
                                                                         \
140
        /* Respond to I/O space & Memory transactions.                */ \
141
        HAL_WRITE_UINT32(SA110_PCI_CFG_COMMAND,                          \
142
                         CYG_PCI_CFG_COMMAND_INVALIDATE                  \
143
                         |CYG_PCI_CFG_COMMAND_IO                         \
144
                         |CYG_PCI_CFG_COMMAND_MEMORY                     \
145
                         |CYG_PCI_CFG_COMMAND_MASTER);                   \
146
    }                                                                    \
147
    /* Signal PCI_init_complete                                       */ \
148
    HAL_READ_UINT32(SA110_CONTROL, __tmp);                               \
149
    __tmp |= SA110_CONTROL_INIT_COMPLETE;                                \
150
    HAL_WRITE_UINT32(SA110_CONTROL, __tmp);                              \
151
                                                                         \
152
    CYG_MACRO_END
153
 
154
 
155
// Compute address necessary to access PCI config space for the given
156
// bus and device.
157
#define HAL_PCI_CONFIG_ADDRESS( __bus, __devfn, __offset )               \
158
    ({                                                                   \
159
    cyg_uint32 __addr;                                                   \
160
    cyg_uint32 __dev = CYG_PCI_DEV_GET_DEV(__devfn);                     \
161
    if (0 == __bus) {                                                    \
162
        if (0 == __dev) {                                                \
163
            /* Access self via CSR base */                               \
164
            __addr = SA110_CONTROL_STATUS_BASE;                          \
165
        } else {                                                         \
166
            /* Page 3-17, table 3-5: bits 15-11 generate PCI address */  \
167
            __addr = SA110_PCI_CONFIG0_BASE | 0x00c00000 | (__dev << 11);\
168
        }                                                                \
169
    } else {                                                             \
170
        __addr = SA110_PCI_CONFIG1_BASE | (__bus << 16) | (__dev << 11); \
171
    }                                                                    \
172
    __addr |= CYG_PCI_DEV_GET_FN(__devfn) << 8;                          \
173
    __addr |= __offset;                                                  \
174
    __addr;                                                              \
175
    })
176
 
177
// Read a value from the PCI configuration space of the appropriate
178
// size at an address composed from the bus, devfn and offset.
179
#define HAL_PCI_CFG_READ_UINT8( __bus, __devfn, __offset, __val )  \
180
    HAL_READ_UINT8(HAL_PCI_CONFIG_ADDRESS(__bus, __devfn, __offset), __val)
181
 
182
#define HAL_PCI_CFG_READ_UINT16( __bus, __devfn, __offset, __val ) \
183
    HAL_READ_UINT16(HAL_PCI_CONFIG_ADDRESS(__bus, __devfn, __offset), __val)
184
 
185
#define HAL_PCI_CFG_READ_UINT32( __bus, __devfn, __offset, __val ) \
186
    HAL_READ_UINT32(HAL_PCI_CONFIG_ADDRESS(__bus, __devfn, __offset), __val)
187
 
188
// Write a value to the PCI configuration space of the appropriate
189
// size at an address composed from the bus, devfn and offset.
190
#define HAL_PCI_CFG_WRITE_UINT8( __bus, __devfn, __offset, __val )  \
191
    HAL_WRITE_UINT8(HAL_PCI_CONFIG_ADDRESS(__bus, __devfn, __offset), __val)
192
 
193
#define HAL_PCI_CFG_WRITE_UINT16( __bus, __devfn, __offset, __val ) \
194
    HAL_WRITE_UINT16(HAL_PCI_CONFIG_ADDRESS(__bus, __devfn, __offset), __val)
195
 
196
#define HAL_PCI_CFG_WRITE_UINT32( __bus, __devfn, __offset, __val ) \
197
    HAL_WRITE_UINT32(HAL_PCI_CONFIG_ADDRESS(__bus, __devfn, __offset), __val)
198
 
199
//-----------------------------------------------------------------------------
200
// Resources
201
 
202
// Map PCI device resources starting from these addresses in PCI space.
203
#define HAL_PCI_ALLOC_BASE_MEMORY (EBSA_SDRAM_PCI_SIZE+EBSA_CSR_MEM_PCI_SIZE)
204
#define HAL_PCI_ALLOC_BASE_IO     (EBSA_CSR_IO_PCI_SIZE)
205
 
206
// This is where the PCI spaces are mapped in the CPU's address space.
207
#define HAL_PCI_PHYSICAL_MEMORY_BASE    0x80000000
208
#define HAL_PCI_PHYSICAL_IO_BASE        0x7c000000
209
 
210
// Translate the PCI interrupt requested by the device (INTA#, INTB#,
211
// INTC# or INTD#) to the associated CPU interrupt (i.e., HAL vector).
212
#define HAL_PCI_TRANSLATE_INTERRUPT( __bus, __devfn, __vec, __valid)          \
213
    CYG_MACRO_START                                                           \
214
    cyg_uint8 __req;                                                          \
215
    HAL_PCI_CFG_READ_UINT8(__bus, __devfn, CYG_PCI_CFG_INT_PIN, __req);       \
216
    if (0 != __req) {                                                         \
217
        /* Interrupt assignment as 21285 sees them. (From                 */  \
218
        /* EBSA285 Eval Board Reference Manual, 3.4 Interrupt Assignment) */  \
219
        CYG_ADDRWORD __translation[4] = {                                     \
220
            CYGNUM_HAL_INTERRUPT_IRQ_IN_1,  /* INTC# */                       \
221
            CYGNUM_HAL_INTERRUPT_IRQ_IN_0,  /* INTB# */                       \
222
            CYGNUM_HAL_INTERRUPT_PCI_IRQ,   /* INTA# */                       \
223
            CYGNUM_HAL_INTERRUPT_IRQ_IN_3}; /* INTD# */                       \
224
                                                                              \
225
        /* The PCI lines from the different slots are wired like this  */     \
226
        /* on the PCI backplane:                                       */     \
227
        /*                pin6A     pin7B    pin7A   pin8B             */     \
228
        /* System Slot    INTA#     INTB#    INTC#   INTD#             */     \
229
        /* I/O Slot 1     INTB#     INTC#    INTD#   INTA#             */     \
230
        /* I/O Slot 2     INTC#     INTD#    INTA#   INTB#             */     \
231
        /* I/O Slot 3     INTD#     INTA#    INTB#   INTC#             */     \
232
        /* I/O Slot 4     INTA#     INTB#    INTC#   INTD#             */     \
233
        /*                                                             */     \
234
        /* (From PCI Development Backplane, 3.2.2 Interrupts)          */     \
235
        /*                                                             */     \
236
        /* Devsel signals are wired to, resulting in device IDs:       */     \
237
        /* I/O Slot 1     AD19 / dev 8       [(8+1)&3 = 1]             */     \
238
        /* I/O Slot 2     AD18 / dev 7       [(7+1)&3 = 0]             */     \
239
        /* I/O Slot 3     AD17 / dev 6       [(6+1)&3 = 3]             */     \
240
        /* I/O Slot 4     AD16 / dev 5       [(5+1)&3 = 2]             */     \
241
        /*                                                             */     \
242
        /* (From PCI Development Backplane, 3.2.1 General)             */     \
243
        /*                                                             */     \
244
        /* The observant reader will notice that the array does not    */     \
245
        /* match the table of how interrupts are wired. The array      */     \
246
        /* does however match observed behavior of the hardware:       */     \
247
        /*                                                             */     \
248
        /* Observed interrupts with an Intel ethernet card             */     \
249
        /* put in the slots in turn and set to generate interrupts:    */     \
250
        /*  slot 1/intA# (dev 8): caused host INTB#                    */     \
251
        /*  slot 2/intA# (dev 7): caused host INTC#                    */     \
252
        /*  slot 3/intA# (dev 6): caused host INTD#                    */     \
253
        /*  slot 4/intA# (dev 5): caused host INTA#                    */     \
254
                                                                              \
255
        __vec = __translation[((__req+CYG_PCI_DEV_GET_DEV(__devfn))&3)];      \
256
        __valid = true;                                                       \
257
    } else {                                                                  \
258
        /* Device will not generate interrupt requests. */                    \
259
        __valid = false;                                                      \
260
    }                                                                         \
261
    CYG_MACRO_END
262
 
263
//-----------------------------------------------------------------------------
264
// end of plf_io.h
265
#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.