]> git.karo-electronics.de Git - karo-tx-redboot.git/blob - packages/hal/arm/xscale/grg/v2_0/include/hal_platform_setup.h
352c545d55528b4f80a0b43be17ce3bfaef6d72e
[karo-tx-redboot.git] / packages / hal / arm / xscale / grg / v2_0 / include / hal_platform_setup.h
1 #ifndef CYGONCE_HAL_PLATFORM_SETUP_H
2 #define CYGONCE_HAL_PLATFORM_SETUP_H
3
4 /*=============================================================================
5 //
6 //      hal_platform_setup.h
7 //
8 //      Platform specific support for HAL (assembly code)
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, 2004 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):    msalter
47 // Contributors: msalter
48 // Date:         2003-02-06
49 // Purpose:      Intel XScale GRG specific support routines
50 // Description: 
51 // Usage:        #include <cyg/hal/hal_platform_setup.h>
52 //     Only used by "vectors.S"         
53 //
54 //####DESCRIPTIONEND####
55 //
56 //===========================================================================*/
57
58 #include <pkgconf/system.h>             // System-wide configuration info
59 #include CYGBLD_HAL_VARIANT_H           // Variant specific configuration
60 #include CYGBLD_HAL_PLATFORM_H          // Platform specific configuration
61 #include <cyg/hal/hal_ixp425.h>         // Variant specific hardware definitions
62 #include <cyg/hal/hal_mmu.h>            // MMU definitions
63 #include <cyg/hal/hal_mm.h>             // more MMU definitions
64 #include <cyg/hal/grg.h>                // Platform specific hardware definitions
65
66 // ------------------------------------------------------------------------
67 // Convenience macros for setting up page table
68 // 
69 .macro IXP_MAP_SDRAM va, c, b, x, p
70     XSCALE_MMU_SECTION SDRAM_PHYS_BASE>>20, \va>>20, SDRAM_SIZE>>20, \c, \b, 3, \x, \p
71 .endm
72
73 .macro IXP_MAP_EXP_V n, va, sz, c, b, x, p
74     XSCALE_MMU_SECTION (0x500 + ((IXP425_EXP_CS_SIZE * \n) >> 20)), \va>>20, \sz>>20, \c, \b, 3, \x, \p
75 .endm
76
77 .macro IXP_MAP_EXP n, sz, c, b, x, p
78     IXP_MAP_EXP_V \n, (0x50000000 + (IXP425_EXP_CS_SIZE * \n)), \sz, \c, \b, \x, \p
79 .endm
80
81 .macro IXP_MAP_IO addr, sz
82     XSCALE_MMU_SECTION \addr>>20, \addr>>20, \sz>>20, 0, 0, 3, 0, 0
83 .endm
84
85 #if defined(CYG_HAL_STARTUP_ROM)
86 #define PLATFORM_SETUP1  _platform_setup1
87 #define CYGHWR_HAL_ARM_HAS_MMU
88
89 // ------------------------------------------------------------------------
90 // Define macro used to diddle the LEDs during early initialization.
91 // Can use r0+r1.  Argument in \x.
92 #define CYGHWR_LED_MACRO
93
94 // Delay a bit
95 .macro DELAY cycles, reg0
96 #if 0
97     ldr     \reg0, =\cycles
98     subs    \reg0, \reg0, #1
99     subne   pc,  pc, #0xc
100 #endif
101 .endm
102
103 // ------------------------------------------------------------------------
104 // This macro represents the initial startup code for the platform        
105         .macro _platform_setup1
106
107 #ifdef CYGHWR_HAL_ARM_BIGENDIAN
108         // set big-endian
109         mrc     p15, 0, r0, c1, c0, 0
110         orr     r0, r0, #0x80
111         mcr     p15, 0, r0, c1, c0, 0
112         CPWAIT  r0
113 #endif
114
115         ldr     r0,=(CPSR_IRQ_DISABLE|CPSR_FIQ_DISABLE|CPSR_SUPERVISOR_MODE)
116         msr     cpsr, r0
117
118         // invalidate I & D caches & BTB
119         mcr     p15, 0, r0, c7, c7, 0
120         CPWAIT  r0
121
122         // invalidate I & Data TLB
123         mcr     p15, 0, r0, c8, c7, 0
124         CPWAIT r0
125
126         // drain write and fill buffers
127         mcr     p15, 0, r0, c7, c10, 4
128         CPWAIT  r0
129
130         // disable write buffer coalescing
131         mrc     p15, 0, r0, c1, c0, 1
132         orr     r0, r0, #1
133         mcr     p15, 0, r0, c1, c0, 1
134         CPWAIT  r0
135                 
136         // Setup chip selects
137         ldr     r1, =IXP425_EXP_CFG_BASE
138 #ifdef IXP425_EXP_CS0_INIT
139         ldr     r0, =IXP425_EXP_CS0_INIT
140         str     r0, [r1, #IXP425_EXP_CS0]
141 #endif
142 #ifdef IXP425_EXP_CS1_INIT
143         ldr     r0, =IXP425_EXP_CS1_INIT
144         str     r0, [r1, #IXP425_EXP_CS1]
145 #endif
146 #ifdef IXP425_EXP_CS2_INIT
147         ldr     r0, =IXP425_EXP_CS2_INIT
148         str     r0, [r1, #IXP425_EXP_CS2]
149 #endif
150 #ifdef IXP425_EXP_CS3_INIT
151         ldr     r0, =IXP425_EXP_CS3_INIT
152         str     r0, [r1, #IXP425_EXP_CS3]
153 #endif
154 #ifdef IXP425_EXP_CS4_INIT
155         ldr     r0, =IXP425_EXP_CS4_INIT
156         str     r0, [r1, #IXP425_EXP_CS4]
157 #endif
158 #ifdef IXP425_EXP_CS5_INIT
159         ldr     r0, =IXP425_EXP_CS5_INIT
160         str     r0, [r1, #IXP425_EXP_CS5]
161 #endif
162 #ifdef IXP425_EXP_CS6_INIT
163         ldr     r0, =IXP425_EXP_CS6_INIT
164         str     r0, [r1, #IXP425_EXP_CS6]
165 #endif
166 #ifdef IXP425_EXP_CS7_INIT
167         ldr     r0, =IXP425_EXP_CS7_INIT
168         str     r0, [r1, #IXP425_EXP_CS7]
169 #endif
170
171         // Enable the Icache
172         mrc     p15, 0, r0, c1, c0, 0
173         orr     r0, r0, #MMU_Control_I
174         mcr     p15, 0, r0, c1, c0, 0
175         CPWAIT  r0
176
177         // Setup SDRAM controller
178
179         ldr     r0, =IXP425_SDRAM_CFG_BASE
180
181         ldr     r1, =IXP425_SDRAM_CONFIG_INIT
182         str     r1, [r0, #IXP425_SDRAM_CONFIG]
183
184         // disable refresh cycles
185         mov     r1, #0
186         str     r1, [r0, #IXP425_SDRAM_REFRESH]
187
188         // send nop command
189         mov     r1, #SDRAM_IR_NOP
190         str     r1, [r0, #IXP425_SDRAM_IR]
191         DELAY   0x10000, r1
192         
193         // set SDRAM internal refresh val
194         ldr     r1, =IXP425_SDRAM_REFRESH_CNT
195         str     r1, [r0, #IXP425_SDRAM_REFRESH]
196         DELAY   0x10000, r1
197
198         // send precharge-all command to close all open banks
199         mov     r1, #SDRAM_IR_PRECHARGE
200         str     r1, [r0, #IXP425_SDRAM_IR]
201         DELAY   0x10000, r1
202
203         // provide 8 auto-refresh cycles
204         mov     r1, #SDRAM_IR_AUTO_REFRESH
205         mov     r2, #8
206   1:
207         str     r1, [r0, #IXP425_SDRAM_IR]
208         DELAY   0x800, r3
209         subs    r2, r2, #1
210         bne     1b
211
212         // set mode register in sdram
213         mov     r1, #IXP425_SDRAM_SET_MODE_CMD
214         str     r1, [r0, #IXP425_SDRAM_IR]
215         DELAY   0x10000, r1
216
217         // start normal operation
218         mov     r1, #SDRAM_IR_NORMAL
219         str     r1, [r0, #IXP425_SDRAM_IR]
220         DELAY   0x10000, r1
221
222         // Enable byte swapping control via page table P bit.    
223         ldr     r2, =IXP425_EXP_CFG_BASE
224         ldr     r1, [r2, #IXP425_EXP_CNFG1]
225         orr     r1, r1, #EXP_CNFG1_BYTE_SWAP_EN
226         str     r1, [r2, #IXP425_EXP_CNFG1]
227
228         // value to load into pc to jump to real runtime address
229         ldr     r0, =1f
230
231         // Setup EXP_CNFG0 value to switch EXP bus out of low memory
232         ldr     r2, =IXP425_EXP_CFG_BASE
233         ldr     r1, [r2, #IXP425_EXP_CNFG0]
234         bic     r1, r1, #EXP_CNFG0_MEM_MAP
235
236         b       icache_boundary
237         .p2align 5
238 icache_boundary:
239         // Here is where we switch from boot address (0x000000000) to the
240         // actual flash runtime address. We align to cache boundary so we
241         // execute from cache during the switchover. Cachelines are 8 words.
242         str     r1, [r2, #IXP425_EXP_CNFG0]    // make the EXP bus switch
243         nop
244         nop
245         nop
246         nop
247         mov     pc, r0
248         nop
249                             // display FFFF and loop forever.
250     0:  b       0b
251     1:
252
253         // Build mmu tables into RAM so page table walks by the cpu
254         // don't interfere with FLASH programming.
255         mov     r1, #SDRAM_PHYS_BASE
256         orr     r1, r1, #0x4000         // RAM tables
257         add     r2, r1, #0x4000         // End of tables
258
259         // First clear table
260         mov     r0, #0
261     1:
262         str     r0, [r1], #4
263         cmp     r1, r2
264         bne     1b
265
266         // Build section mappings
267         IXP_MAP_SDRAM   SDRAM_BASE,           1, 0, 0, 0   // Cached SDRAM
268         IXP_MAP_SDRAM   SDRAM_ALIAS_BASE,     1, 0, 0, 0   // Cached SDRAM alias
269         IXP_MAP_SDRAM   SDRAM_UNCACHED_BASE,  0, 0, 0, 0   // Uncached SDRAM
270         IXP_MAP_SDRAM   SDRAM_DC_BASE,        1, 0, 0, 1   // Cached data coherent SDRAM
271
272         IXP_MAP_EXP 0, IXDP_FLASH_SIZE,       1, 0, 0, 0   // Flash
273         IXP_MAP_EXP 4, (1 << 20),             0, 0, 0, 0   // NPE use
274         IXP_MAP_EXP 5, (1 << 20),             0, 0, 0, 0   // NPE use
275
276         IXP_MAP_EXP_V 0, IXDP_FLASH_DC_BASE, IXDP_FLASH_SIZE, 1, 0, 0, 1  // data coherent flash
277
278         IXP_MAP_IO      IXP425_PCI_WINDOW_BASE,  IXP425_PCI_WINDOW_SIZE
279         IXP_MAP_IO      IXP425_QMGR_BASE,        IXP425_QMGR_SIZE
280         IXP_MAP_IO      IXP425_PCI_CFG_BASE,     IXP425_PCI_CFG_SIZE
281         IXP_MAP_IO      IXP425_EXP_CFG_BASE,     IXP425_EXP_CFG_SIZE
282         IXP_MAP_IO      IXP425_MISC_CFG_BASE,    IXP425_MISC_CFG_SIZE
283         IXP_MAP_IO      IXP425_SDRAM_CFG_BASE,   IXP425_SDRAM_CFG_SIZE
284
285         mcr     p15, 0, r0, c7, c10, 4  // drain the write & fill buffers
286         CPWAIT  r0
287
288         // Set the TTB register to DRAM mmu_table
289         ldr     r0, =(SDRAM_PHYS_BASE | 0x4000) // RAM tables
290         mcr     p15, 0, r0, c2, c0, 0           // load page table pointer
291         CPWAIT  r0
292
293         // enable permission checks in all domains
294         ldr     r0, =0x55555555
295         mcr     p15, 0, r0, c3, c0, 0
296         CPWAIT  r0
297
298         // enable mmu
299         mrc     p15, 0, r0, c1, c0, 0
300         orr     r0, r0, #MMU_Control_M
301         orr     r0, r0, #MMU_Control_R
302         mcr     p15, 0, r0, c1, c0, 0
303         CPWAIT  r0
304
305         // enable D cache
306         mrc     p15, 0, r0, c1, c0, 0
307         orr     r0, r0, #MMU_Control_C
308         mcr     p15, 0, r0, c1, c0, 0
309         CPWAIT  r0
310
311         // Enable branch target buffer
312         mrc     p15, 0, r0, c1, c0, 0
313         orr     r0, r0, #MMU_Control_BTB
314         mcr     p15, 0, r0, c1, c0, 0
315         CPWAIT  r0
316
317         mcr     p15, 0, r0, c7, c10, 4  // drain the write & fill buffers
318         CPWAIT  r0
319
320         mcr     p15, 0, r0, c7, c7, 0   // flush Icache, Dcache and BTB
321         CPWAIT  r0
322
323         mcr     p15, 0, r0, c8, c7, 0   // flush instuction and data TLBs
324         CPWAIT  r0
325
326         mcr     p15, 0, r0, c7, c10, 4  // drain the write & fill buffers
327         CPWAIT r0       
328         
329         // save SDRAM size
330         ldr     r1, =hal_dram_size  /* [see hal_intr.h] */
331         mov     r8, #SDRAM_SIZE
332         str     r8, [r1]
333
334         .endm    // _platform_setup1
335
336 #else // defined(CYG_HAL_STARTUP_ROM)
337 #define PLATFORM_SETUP1
338 #endif
339
340 #define PLATFORM_VECTORS         _platform_vectors
341         .macro  _platform_vectors
342         .endm                                        
343
344 /*---------------------------------------------------------------------------*/
345 /* end of hal_platform_setup.h                                               */
346 #endif /* CYGONCE_HAL_PLATFORM_SETUP_H */