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

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [rtos/] [ecos-3.0/] [packages/] [hal/] [mn10300/] [asb2305/] [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):    dhowells
46
// Contributors: dmoseley
47
// Date:         2001-05-17
48
// Purpose:      ASB2305 platform IO support
49
// Description:
50
// Usage:        #include <cyg/hal/plf_io.h>
51
//
52
//####DESCRIPTIONEND####
53
//
54
//=============================================================================
55
 
56
#include <pkgconf/hal.h>
57
#ifndef __ASSEMBLER__
58
#include <cyg/hal/hal_intr.h>
59
#endif
60
 
61
#ifdef __ASSEMBLER__
62
#define HAL_REG_8(x)              x
63
#define HAL_REG_16(x)             x
64
#define HAL_REG_32(x)             x
65
#else
66
#define HAL_REG_8(x)              (volatile cyg_uint8*)(x)
67
#define HAL_REG_16(x)             (volatile cyg_uint16*)(x)
68
#define HAL_REG_32(x)             (volatile cyg_uint32*)(x)
69
#endif
70
 
71
# define CYGARC_UNCACHED_ADDRESS(x) ((x)|0x20000000)
72
 
73
//-----------------------------------------------------------------------------
74
 
75
/* ASB GPIO Registers */
76
#define HAL_GPIO_BASE                           0xDB000000
77
 
78
#define HAL_GPIO_0_MODE_OFFSET                  0x0000
79
#define HAL_GPIO_0_IN_OFFSET                    0x0004
80
#define HAL_GPIO_0_OUT_OFFSET                   0x0008
81
#define HAL_GPIO_1_MODE_OFFSET                  0x0100
82
#define HAL_GPIO_1_IN_OFFSET                    0x0104
83
#define HAL_GPIO_1_OUT_OFFSET                   0x0108
84
#define HAL_GPIO_2_MODE_OFFSET                  0x0200
85
#define HAL_GPIO_2_IN_OFFSET                    0x0204
86
#define HAL_GPIO_2_OUT_OFFSET                   0x0208
87
#define HAL_GPIO_3_MODE_OFFSET                  0x0300
88
#define HAL_GPIO_3_IN_OFFSET                    0x0304
89
#define HAL_GPIO_3_OUT_OFFSET                   0x0308
90
#define HAL_GPIO_4_MODE_OFFSET                  0x0400
91
#define HAL_GPIO_4_IN_OFFSET                    0x0404
92
#define HAL_GPIO_4_OUT_OFFSET                   0x0408
93
#define HAL_GPIO_5_MODE_OFFSET                  0x0500
94
#define HAL_GPIO_5_IN_OFFSET                    0x0504
95
#define HAL_GPIO_5_OUT_OFFSET                   0x0508
96
 
97
#define HAL_GPIO_0_MODE                         HAL_REG_16 (HAL_GPIO_BASE + HAL_GPIO_0_MODE_OFFSET)
98
#define HAL_GPIO_0_IN                           HAL_REG_8  (HAL_GPIO_BASE + HAL_GPIO_0_IN_OFFSET)
99
#define HAL_GPIO_0_OUT                          HAL_REG_8  (HAL_GPIO_BASE + HAL_GPIO_0_OUT_OFFSET)
100
#define HAL_GPIO_1_MODE                         HAL_REG_16 (HAL_GPIO_BASE + HAL_GPIO_1_MODE_OFFSET)
101
#define HAL_GPIO_1_IN                           HAL_REG_8  (HAL_GPIO_BASE + HAL_GPIO_1_IN_OFFSET)
102
#define HAL_GPIO_1_OUT                          HAL_REG_8  (HAL_GPIO_BASE + HAL_GPIO_1_OUT_OFFSET)
103
#define HAL_GPIO_2_MODE                         HAL_REG_16 (HAL_GPIO_BASE + HAL_GPIO_2_MODE_OFFSET)
104
#define HAL_GPIO_2_IN                           HAL_REG_8  (HAL_GPIO_BASE + HAL_GPIO_2_IN_OFFSET)
105
#define HAL_GPIO_2_OUT                          HAL_REG_8  (HAL_GPIO_BASE + HAL_GPIO_2_OUT_OFFSET)
106
#define HAL_GPIO_3_MODE                         HAL_REG_16 (HAL_GPIO_BASE + HAL_GPIO_3_MODE_OFFSET)
107
#define HAL_GPIO_3_IN                           HAL_REG_8  (HAL_GPIO_BASE + HAL_GPIO_3_IN_OFFSET)
108
#define HAL_GPIO_3_OUT                          HAL_REG_8  (HAL_GPIO_BASE + HAL_GPIO_3_OUT_OFFSET)
109
#define HAL_GPIO_4_MODE                         HAL_REG_16 (HAL_GPIO_BASE + HAL_GPIO_4_MODE_OFFSET)
110
#define HAL_GPIO_4_IN                           HAL_REG_8  (HAL_GPIO_BASE + HAL_GPIO_4_IN_OFFSET)
111
#define HAL_GPIO_4_OUT                          HAL_REG_8  (HAL_GPIO_BASE + HAL_GPIO_4_OUT_OFFSET)
112
#define HAL_GPIO_5_MODE                         HAL_REG_16 (HAL_GPIO_BASE + HAL_GPIO_5_MODE_OFFSET)
113
#define HAL_GPIO_5_IN                           HAL_REG_8  (HAL_GPIO_BASE + HAL_GPIO_5_IN_OFFSET)
114
#define HAL_GPIO_5_OUT                          HAL_REG_8  (HAL_GPIO_BASE + HAL_GPIO_5_OUT_OFFSET)
115
 
116
//-----------------------------------------------------------------------------
117
#define HAL_LED_ADDRESS                         0xA6F90000
118
#define HAL_GPIO_MODE_ALL_OUTPUT                0x5555
119
 
120
 
121
#ifdef __ASSEMBLER__
122
 
123
#  include <cyg/hal/platform.inc>
124
#  define DEBUG_DISPLAY(hexdig)   hal_diag_led hexdig
125
#  define DEBUG_DELAY()                                        \
126
     mov        0x20000, d0;                                       \
127
0:        sub    1, d0;                                             \
128
     bne    0b;                                                \
129
     nop
130
 
131
#else
132
 
133
extern cyg_uint8 cyg_hal_plf_led_val(CYG_WORD hexdig);
134
#  define DEBUG_DISPLAY(hexdig) HAL_WRITE_UINT8(HAL_LED_ADDRESS, cyg_hal_plf_led_val(hexdig))
135
#  define DEBUG_DELAY()                                        \
136
   {                                                           \
137
     volatile int i = 0x80000;                                 \
138
     while (--i) ;                                             \
139
   }
140
 
141
#endif
142
 
143
//-----------------------------------------------------------------------------
144
// PCI access stuff
145
 
146
// Compute address necessary to access PCI config space for the given
147
// bus and device.
148
#define HAL_PCI_CONFIG_ADDRESS( __bus, __devfn, __offset )              \
149
 (0x80000000 | ((__bus) << 16) | ((__devfn) << 8) | ((__offset) & ~3))
150
 
151
// Read a value from the PCI configuration space of the appropriate
152
// size at an address composed from the bus, devfn and offset.
153
#define HAL_PCI_CFG_READ_UINT8( __bus, __devfn, __offset, __val )                               \
154
do {                                                                                            \
155
        if ((__bus)==0 && (__devfn)==0) {                                                 \
156
                HAL_READ_UINT8(0xBE040000+(__offset),(__val));                                  \
157
        }                                                                                       \
158
        else {                                                                                  \
159
                HAL_WRITE_UINT32(0xBFFFFFF8,HAL_PCI_CONFIG_ADDRESS(__bus, __devfn, __offset));  \
160
                HAL_READ_UINT8(0xBFFFFFFC + ((__offset)&3),(__val));                            \
161
        }                                                                                       \
162
} while(0)
163
 
164
#define HAL_PCI_CFG_READ_UINT16( __bus, __devfn, __offset, __val )                              \
165
do {                                                                                            \
166
        if ((__bus)==0 && (__devfn)==0) {                                                 \
167
                HAL_READ_UINT16(0xBE040000+(__offset),(__val));                                 \
168
        }                                                                                       \
169
        else {                                                                                  \
170
                HAL_WRITE_UINT32(0xBFFFFFF8,HAL_PCI_CONFIG_ADDRESS(__bus, __devfn, __offset));  \
171
                HAL_READ_UINT16(0xBFFFFFFC + ((__offset)&2),(__val));                           \
172
        }                                                                                       \
173
} while(0)
174
 
175
#define HAL_PCI_CFG_READ_UINT32( __bus, __devfn, __offset, __val )                              \
176
do {                                                                                            \
177
        if ((__bus)==0 && (__devfn)==0) {                                                 \
178
                HAL_READ_UINT32(0xBE040000+(__offset),(__val));                                 \
179
        }                                                                                       \
180
        else {                                                                                  \
181
                HAL_WRITE_UINT32(0xBFFFFFF8,HAL_PCI_CONFIG_ADDRESS(__bus, __devfn, __offset));  \
182
                HAL_READ_UINT32(0xBFFFFFFC,(__val));                                            \
183
        }                                                                                       \
184
} while(0)
185
 
186
// Write a value to the PCI configuration space of the appropriate
187
// size at an address composed from the bus, devfn and offset.
188
#define HAL_PCI_CFG_WRITE_UINT8( __bus, __devfn, __offset, __val )                              \
189
do {                                                                                            \
190
        if ((__bus)==0 && (__devfn)==0) {                                                 \
191
                HAL_WRITE_UINT8(0xBE040000+(__offset),(__val));                                 \
192
        }                                                                                       \
193
        else {                                                                                  \
194
                HAL_WRITE_UINT32(0xBFFFFFF8,HAL_PCI_CONFIG_ADDRESS(__bus, __devfn, __offset));  \
195
                HAL_WRITE_UINT8(0xBFFFFFFC + ((__offset)&3),(__val));                           \
196
        }                                                                                       \
197
} while(0)
198
 
199
#define HAL_PCI_CFG_WRITE_UINT16( __bus, __devfn, __offset, __val )                             \
200
do {                                                                                            \
201
        if ((__bus)==0 && (__devfn)==0) {                                                 \
202
                HAL_WRITE_UINT16(0xBE040000+(__offset),(__val));                                \
203
        }                                                                                       \
204
        else {                                                                                  \
205
                HAL_WRITE_UINT32(0xBFFFFFF8,HAL_PCI_CONFIG_ADDRESS(__bus, __devfn, __offset));  \
206
                HAL_WRITE_UINT16(0xBFFFFFFC + ((__offset)&2),(__val));                          \
207
        }                                                                                       \
208
} while(0)
209
 
210
#define HAL_PCI_CFG_WRITE_UINT32( __bus, __devfn, __offset, __val )                             \
211
do {                                                                                            \
212
        if ((__bus)==0 && (__devfn)==0) {                                                 \
213
                HAL_WRITE_UINT32(0xBE040000+(__offset),(__val));                                \
214
        }                                                                                       \
215
        else {                                                                                  \
216
                HAL_WRITE_UINT32(0xBFFFFFF8,HAL_PCI_CONFIG_ADDRESS(__bus, __devfn, __offset));  \
217
                HAL_WRITE_UINT32(0xBFFFFFFC,(__val));                                           \
218
        }                                                                                       \
219
} while(0)
220
 
221
// Initialize the PCI bus.
222
#define HAL_PCI_INIT()                                                                            \
223
do {                                                                                              \
224
        cyg_uint32 devfn;                                                                         \
225
        cyg_uint16 word;                                                                          \
226
                                                                                                  \
227
        /* we need to set up the bridge _now_ or we won't be able to access the */                \
228
        /* PCI config registers */                                                                \
229
        HAL_PCI_CFG_READ_UINT32(0,0,CYG_PCI_CFG_COMMAND,word);                                      \
230
        word |= CYG_PCI_CFG_COMMAND_SERR | CYG_PCI_CFG_COMMAND_PARITY;                            \
231
        word |= CYG_PCI_CFG_COMMAND_MEMORY | CYG_PCI_CFG_COMMAND_IO | CYG_PCI_CFG_COMMAND_MASTER; \
232
        HAL_PCI_CFG_WRITE_UINT32(0,0,CYG_PCI_CFG_COMMAND,word);                                     \
233
                                                                                                  \
234
        HAL_PCI_CFG_WRITE_UINT16(0,0,CYG_PCI_CFG_STATUS,  0xF800);                          \
235
        HAL_PCI_CFG_WRITE_UINT8 (0,0,CYG_PCI_CFG_LATENCY_TIMER,   0x10);                            \
236
        HAL_PCI_CFG_WRITE_UINT32(0,0,CYG_PCI_CFG_BAR_0,           0x80000000);                      \
237
        HAL_PCI_CFG_WRITE_UINT8 (0,0,CYG_PCI_CFG_INT_LINE,        1);                               \
238
        HAL_PCI_CFG_WRITE_UINT32(0,0,0x48,                        0x98000000);                      \
239
        HAL_PCI_CFG_WRITE_UINT8 (0,0,0x41,                        0x00);                            \
240
        HAL_PCI_CFG_WRITE_UINT8 (0,0,0x42,                        0x01);                            \
241
        HAL_PCI_CFG_WRITE_UINT8 (0,0,0x44,                        0x01);                            \
242
        HAL_PCI_CFG_WRITE_UINT32(0,0,0x50,                        0x00000001);                      \
243
        HAL_PCI_CFG_WRITE_UINT32(0,0,0x58,                        0x00000002);                      \
244
        HAL_PCI_CFG_WRITE_UINT32(0,0,0x5C,                        0x00000001);                      \
245
                                                                                                  \
246
        /* we also need to set up the PCI-PCI bridge (no BIOS, you see) */                        \
247
        devfn = 3<<3 | 0;                                                                          \
248
                                                                                                  \
249
        /* IO: 0x00010000-0x0001ffff */                                                           \
250
        HAL_PCI_CFG_WRITE_UINT8 (0,devfn,CYG_PCI_CFG_IO_BASE,            0x01);                    \
251
        HAL_PCI_CFG_WRITE_UINT16(0,devfn,CYG_PCI_CFG_IO_BASE_UPPER16,    0x0001);                  \
252
        HAL_PCI_CFG_WRITE_UINT8 (0,devfn,CYG_PCI_CFG_IO_LIMIT,           0xF1);                    \
253
        HAL_PCI_CFG_WRITE_UINT16(0,devfn,CYG_PCI_CFG_IO_LIMIT_UPPER16,   0x0001);                  \
254
                                                                                                  \
255
        HAL_PCI_CFG_READ_UINT32(0,0,CYG_PCI_CFG_COMMAND,word);                                      \
256
        word |= CYG_PCI_CFG_COMMAND_SERR | CYG_PCI_CFG_COMMAND_PARITY;                            \
257
        word |= CYG_PCI_CFG_COMMAND_MEMORY | CYG_PCI_CFG_COMMAND_IO | CYG_PCI_CFG_COMMAND_MASTER; \
258
        HAL_PCI_CFG_WRITE_UINT32(0,0,CYG_PCI_CFG_COMMAND,word);                                     \
259
        HAL_PCI_CFG_WRITE_UINT16(0,devfn,CYG_PCI_CFG_MEM_BASE,           0x1000);                  \
260
        HAL_PCI_CFG_WRITE_UINT16(0,devfn,CYG_PCI_CFG_MEM_LIMIT,          0x1000);                  \
261
} while(0)
262
 
263
 
264
//-----------------------------------------------------------------------------
265
// Resources
266
 
267
// Map PCI device resources starting from these addresses in PCI space.
268
#define HAL_PCI_ALLOC_BASE_MEMORY 0x10000000
269
#define HAL_PCI_ALLOC_BASE_IO     0x1000
270
 
271
// This is where the PCI spaces are mapped in the CPU's address space.
272
#define HAL_PCI_PHYSICAL_MEMORY_BASE    0x80000000
273
#define HAL_PCI_PHYSICAL_IO_BASE        0xBE000000
274
 
275
// Translate the PCI interrupt requested by the device (INTA#, INTB#,
276
// INTC# or INTD#) to the associated CPU interrupt (i.e., HAL vector).
277
#define HAL_PCI_TRANSLATE_INTERRUPT( __bus, __devfn, __vec, __valid)          \
278
    CYG_MACRO_START                                                           \
279
    cyg_uint8 __req;                                                          \
280
    HAL_PCI_CFG_READ_UINT8(__bus, __devfn, CYG_PCI_CFG_INT_PIN, __req);       \
281
    if (0 != __req) {                                                         \
282
        /* Interrupt assignment as 21285 sees them. (From                 */  \
283
        /* EBSA285 Eval Board Reference Manual, 3.4 Interrupt Assignment) */  \
284
        CYG_ADDRWORD __translation[4] = {                                     \
285
            CYGNUM_HAL_INTERRUPT_RESERVED_170,  /* INTC# */                   \
286
            CYGNUM_HAL_INTERRUPT_RESERVED_169,  /* INTB# */                   \
287
            CYGNUM_HAL_INTERRUPT_EXTERNAL_1,    /* INTA# */                   \
288
            CYGNUM_HAL_INTERRUPT_RESERVED_171}; /* INTD# */                   \
289
                                                                              \
290
        /* The PCI lines from the different slots are wired like this  */     \
291
        /* on the PCI backplane:                                       */     \
292
        /*                pin6A     pin7B    pin7A   pin8B             */     \
293
        /* System Slot    INTA#     INTB#    INTC#   INTD#             */     \
294
        /* I/O Slot 1     INTB#     INTC#    INTD#   INTA#             */     \
295
        /* I/O Slot 2     INTC#     INTD#    INTA#   INTB#             */     \
296
        /* I/O Slot 3     INTD#     INTA#    INTB#   INTC#             */     \
297
        /* I/O Slot 4     INTA#     INTB#    INTC#   INTD#             */     \
298
        /*                                                             */     \
299
        /* (From PCI Development Backplane, 3.2.2 Interrupts)          */     \
300
        /*                                                             */     \
301
        /* Devsel signals are wired to, resulting in device IDs:       */     \
302
        /* I/O Slot 1     AD19 / dev 8       [(8+1)&3 = 1]             */     \
303
        /* I/O Slot 2     AD18 / dev 7       [(7+1)&3 = 0]             */     \
304
        /* I/O Slot 3     AD17 / dev 6       [(6+1)&3 = 3]             */     \
305
        /* I/O Slot 4     AD16 / dev 5       [(5+1)&3 = 2]             */     \
306
        /*                                                             */     \
307
        /* (From PCI Development Backplane, 3.2.1 General)             */     \
308
        /*                                                             */     \
309
        /* The observant reader will notice that the array does not    */     \
310
        /* match the table of how interrupts are wired. The array      */     \
311
        /* does however match observed behavior of the hardware:       */     \
312
        /*                                                             */     \
313
        /* Observed interrupts with an Intel ethernet card             */     \
314
        /* put in the slots in turn and set to generate interrupts:    */     \
315
        /*  slot 1/intA# (dev 8): caused host INTB#                    */     \
316
        /*  slot 2/intA# (dev 7): caused host INTC#                    */     \
317
        /*  slot 3/intA# (dev 6): caused host INTD#                    */     \
318
        /*  slot 4/intA# (dev 5): caused host INTA#                    */     \
319
                                                                              \
320
        __vec = __translation[((__req+CYG_PCI_DEV_GET_DEV(__devfn))&3)];      \
321
        __valid = true;                                                       \
322
    } else {                                                                  \
323
        /* Device will not generate interrupt requests. */                    \
324
        __valid = false;                                                      \
325
    }                                                                         \
326
    CYG_MACRO_END
327
 
328
 
329
//-----------------------------------------------------------------------------
330
// Bus address translation macros
331
#define HAL_PCI_CPU_TO_BUS(__cpu_addr, __bus_addr)            \
332
    CYG_MACRO_START                                           \
333
    (__bus_addr) = (CYG_ADDRESS)((cyg_uint32)(__cpu_addr)&~0x20000000);   \
334
    CYG_MACRO_END
335
 
336
#define HAL_PCI_BUS_TO_CPU(__bus_addr, __cpu_addr)        \
337
    CYG_MACRO_START                                       \
338
    (__cpu_addr) = CYGARC_UNCACHED_ADDRESS(__bus_addr);   \
339
    CYG_MACRO_END
340
 
341
//-----------------------------------------------------------------------------
342
// end of plf_io.h
343
#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.