]> git.kernelconcepts.de Git - karo-tx-uboot.git/blob - board/esd/cpci750/cpci750.c
* Code cleanup, mostly for GCC-3.3.x
[karo-tx-uboot.git] / board / esd / cpci750 / cpci750.c
1 /*
2  * (C) Copyright 2001
3  * Josh Huber <huber@mclx.com>, Mission Critical Linux, Inc.
4  *
5  * See file CREDITS for list of people who contributed to this
6  * project.
7  *
8  * This program is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU General Public License as
10  * published by the Free Software Foundation; either version 2 of
11  * the License, or (at your option) any later version.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with this program; if not, write to the Free Software
20  * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
21  * MA 02111-1307 USA
22  *
23  * modifications for the DB64360 eval board based by Ingo.Assmus@keymile.com
24  * modifications for the cpci750 by reinhard.arlt@esd-electronics.com
25  */
26
27 /*
28  * cpci750.c - main board support/init for the esd cpci750.
29  */
30
31 #include <common.h>
32 #include <74xx_7xx.h>
33 #include "../../Marvell/include/memory.h"
34 #include "../../Marvell/include/pci.h"
35 #include "../../Marvell/include/mv_gen_reg.h"
36 #include <net.h>
37
38 #include "eth.h"
39 #include "mpsc.h"
40 #include "i2c.h"
41 #include "64360.h"
42 #include "mv_regs.h"
43
44 #undef  DEBUG
45 /*#define       DEBUG */
46
47 #ifdef CONFIG_PCI
48 #define MAP_PCI
49 #endif /* of CONFIG_PCI */
50
51 #ifdef DEBUG
52 #define DP(x) x
53 #else
54 #define DP(x)
55 #endif
56
57 extern void flush_data_cache (void);
58 extern void invalidate_l1_instruction_cache (void);
59
60 /* ------------------------------------------------------------------------- */
61
62 /* this is the current GT register space location */
63 /* it starts at CFG_DFL_GT_REGS but moves later to CFG_GT_REGS */
64
65 /* Unfortunately, we cant change it while we are in flash, so we initialize it
66  * to the "final" value. This means that any debug_led calls before
67  * board_early_init_f wont work right (like in cpu_init_f).
68  * See also my_remap_gt_regs below. (NTL)
69  */
70
71 void board_prebootm_init (void);
72 unsigned int INTERNAL_REG_BASE_ADDR = CFG_GT_REGS;
73 int display_mem_map (void);
74
75 /* ------------------------------------------------------------------------- */
76
77 /*
78  * This is a version of the GT register space remapping function that
79  * doesn't touch globals (meaning, it's ok to run from flash.)
80  *
81  * Unfortunately, this has the side effect that a writable
82  * INTERNAL_REG_BASE_ADDR is impossible. Oh well.
83  */
84
85 void my_remap_gt_regs (u32 cur_loc, u32 new_loc)
86 {
87         u32 temp;
88
89         /* check and see if it's already moved */
90
91 /* original ppcboot 1.1.6 source
92
93         temp = in_le32((u32 *)(new_loc + INTERNAL_SPACE_DECODE));
94         if ((temp & 0xffff) == new_loc >> 20)
95                 return;
96
97         temp = (in_le32((u32 *)(cur_loc + INTERNAL_SPACE_DECODE)) &
98                 0xffff0000) | (new_loc >> 20);
99
100         out_le32((u32 *)(cur_loc + INTERNAL_SPACE_DECODE), temp);
101
102         while (GTREGREAD(INTERNAL_SPACE_DECODE) != temp);
103 original ppcboot 1.1.6 source end */
104
105         temp = in_le32 ((u32 *) (new_loc + INTERNAL_SPACE_DECODE));
106         if ((temp & 0xffff) == new_loc >> 16)
107                 return;
108
109         temp = (in_le32 ((u32 *) (cur_loc + INTERNAL_SPACE_DECODE)) &
110                 0xffff0000) | (new_loc >> 16);
111
112         out_le32 ((u32 *) (cur_loc + INTERNAL_SPACE_DECODE), temp);
113
114         while (GTREGREAD (INTERNAL_SPACE_DECODE) != temp);
115 }
116
117 #ifdef CONFIG_PCI
118
119 static void gt_pci_config (void)
120 {
121         unsigned int stat;
122         unsigned int val = 0x00fff864;  /* DINK32: BusNum 23:16,  DevNum 15:11, FuncNum 10:8, RegNum 7:2 */
123
124         /* In PCIX mode devices provide their own bus and device numbers. We query the Discovery II's
125          * config registers by writing ones to the bus and device.
126          * We then update the Virtual register with the correct value for the bus and device.
127          */
128         if ((GTREGREAD (PCI_0_MODE) & (BIT4 | BIT5)) != 0) {    /*if  PCI-X */
129                 GT_REG_WRITE (PCI_0_CONFIG_ADDR, BIT31 | val);
130
131                 GT_REG_READ (PCI_0_CONFIG_DATA_VIRTUAL_REG, &stat);
132
133                 GT_REG_WRITE (PCI_0_CONFIG_ADDR, BIT31 | val);
134                 GT_REG_WRITE (PCI_0_CONFIG_DATA_VIRTUAL_REG,
135                               (stat & 0xffff0000) | CFG_PCI_IDSEL);
136
137         }
138         if ((GTREGREAD (PCI_1_MODE) & (BIT4 | BIT5)) != 0) {    /*if  PCI-X */
139                 GT_REG_WRITE (PCI_1_CONFIG_ADDR, BIT31 | val);
140                 GT_REG_READ (PCI_1_CONFIG_DATA_VIRTUAL_REG, &stat);
141
142                 GT_REG_WRITE (PCI_1_CONFIG_ADDR, BIT31 | val);
143                 GT_REG_WRITE (PCI_1_CONFIG_DATA_VIRTUAL_REG,
144                               (stat & 0xffff0000) | CFG_PCI_IDSEL);
145         }
146
147         /* Enable master */
148         PCI_MASTER_ENABLE (0, SELF);
149         PCI_MASTER_ENABLE (1, SELF);
150
151         /* Enable PCI0/1 Mem0 and IO 0 disable all others */
152         GT_REG_READ (BASE_ADDR_ENABLE, &stat);
153         stat |= (1 << 11) | (1 << 12) | (1 << 13) | (1 << 16) | (1 << 17) | (1
154                                                                              <<
155                                                                              18);
156         stat &= ~((1 << 9) | (1 << 10) | (1 << 14) | (1 << 15));
157         GT_REG_WRITE (BASE_ADDR_ENABLE, stat);
158
159         /* ronen- add write to pci remap registers for 64460.
160            in 64360 when writing to pci base go and overide remap automaticaly,
161            in 64460 it doesn't */
162         GT_REG_WRITE (PCI_0_IO_BASE_ADDR, CFG_PCI0_IO_SPACE >> 16);
163         GT_REG_WRITE (PCI_0I_O_ADDRESS_REMAP, CFG_PCI0_IO_SPACE_PCI >> 16);
164         GT_REG_WRITE (PCI_0_IO_SIZE, (CFG_PCI0_IO_SIZE - 1) >> 16);
165
166         GT_REG_WRITE (PCI_0_MEMORY0_BASE_ADDR, CFG_PCI0_MEM_BASE >> 16);
167         GT_REG_WRITE (PCI_0MEMORY0_ADDRESS_REMAP, CFG_PCI0_MEM_BASE >> 16);
168         GT_REG_WRITE (PCI_0_MEMORY0_SIZE, (CFG_PCI0_MEM_SIZE - 1) >> 16);
169
170         GT_REG_WRITE (PCI_1_IO_BASE_ADDR, CFG_PCI1_IO_SPACE >> 16);
171         GT_REG_WRITE (PCI_1I_O_ADDRESS_REMAP, CFG_PCI1_IO_SPACE_PCI >> 16);
172         GT_REG_WRITE (PCI_1_IO_SIZE, (CFG_PCI1_IO_SIZE - 1) >> 16);
173
174         GT_REG_WRITE (PCI_1_MEMORY0_BASE_ADDR, CFG_PCI1_MEM_BASE >> 16);
175         GT_REG_WRITE (PCI_1MEMORY0_ADDRESS_REMAP, CFG_PCI1_MEM_BASE >> 16);
176         GT_REG_WRITE (PCI_1_MEMORY0_SIZE, (CFG_PCI1_MEM_SIZE - 1) >> 16);
177
178         /* PCI interface settings */
179         /* Timeout set to retry forever */
180         GT_REG_WRITE (PCI_0TIMEOUT_RETRY, 0x0);
181         GT_REG_WRITE (PCI_1TIMEOUT_RETRY, 0x0);
182
183         /* ronen - enable only CS0 and Internal reg!! */
184         GT_REG_WRITE (PCI_0BASE_ADDRESS_REGISTERS_ENABLE, 0xfffffdfe);
185         GT_REG_WRITE (PCI_1BASE_ADDRESS_REGISTERS_ENABLE, 0xfffffdfe);
186
187 /*ronen update the pci internal registers base address.*/
188 #ifdef MAP_PCI
189         for (stat = 0; stat <= PCI_HOST1; stat++)
190                 pciWriteConfigReg (stat,
191                                    PCI_INTERNAL_REGISTERS_MEMORY_MAPPED_BASE_ADDRESS,
192                                    SELF, CFG_GT_REGS);
193 #endif
194
195 }
196 #endif
197
198 /* Setup CPU interface paramaters */
199 static void gt_cpu_config (void)
200 {
201         cpu_t cpu = get_cpu_type ();
202         ulong tmp;
203
204         /* cpu configuration register */
205         tmp = GTREGREAD (CPU_CONFIGURATION);
206
207         /* set the SINGLE_CPU bit  see MV64360 P.399 */
208 #ifndef CFG_GT_DUAL_CPU         /* SINGLE_CPU seems to cause JTAG problems */
209         tmp |= CPU_CONF_SINGLE_CPU;
210 #endif
211
212         tmp &= ~CPU_CONF_AACK_DELAY_2;
213
214         tmp |= CPU_CONF_DP_VALID;
215         tmp |= CPU_CONF_AP_VALID;
216
217         tmp |= CPU_CONF_PIPELINE;
218
219         GT_REG_WRITE (CPU_CONFIGURATION, tmp);  /* Marvell (VXWorks) writes 0x20220FF */
220
221         /* CPU master control register */
222         tmp = GTREGREAD (CPU_MASTER_CONTROL);
223
224         tmp |= CPU_MAST_CTL_ARB_EN;
225
226         if ((cpu == CPU_7400) ||
227             (cpu == CPU_7410) || (cpu == CPU_7455) || (cpu == CPU_7450)) {
228
229                 tmp |= CPU_MAST_CTL_CLEAN_BLK;
230                 tmp |= CPU_MAST_CTL_FLUSH_BLK;
231
232         } else {
233                 /* cleanblock must be cleared for CPUs
234                  * that do not support this command (603e, 750)
235                  * see Res#1 */
236                 tmp &= ~CPU_MAST_CTL_CLEAN_BLK;
237                 tmp &= ~CPU_MAST_CTL_FLUSH_BLK;
238         }
239         GT_REG_WRITE (CPU_MASTER_CONTROL, tmp);
240 }
241
242 /*
243  * board_early_init_f.
244  *
245  * set up gal. device mappings, etc.
246  */
247 int board_early_init_f (void)
248 {
249
250         /*
251          * set up the GT the way the kernel wants it
252          * the call to move the GT register space will obviously
253          * fail if it has already been done, but we're going to assume
254          * that if it's not at the power-on location, it's where we put
255          * it last time. (huber)
256          */
257
258         my_remap_gt_regs (CFG_DFL_GT_REGS, CFG_GT_REGS);
259
260         /* No PCI in first release of Port To_do: enable it. */
261 #ifdef CONFIG_PCI
262         gt_pci_config ();
263 #endif
264         /* mask all external interrupt sources */
265         GT_REG_WRITE (CPU_INTERRUPT_MASK_REGISTER_LOW, 0);
266         GT_REG_WRITE (CPU_INTERRUPT_MASK_REGISTER_HIGH, 0);
267         /* new in MV6436x */
268         GT_REG_WRITE (CPU_INTERRUPT_1_MASK_REGISTER_LOW, 0);
269         GT_REG_WRITE (CPU_INTERRUPT_1_MASK_REGISTER_HIGH, 0);
270         /* --------------------- */
271         GT_REG_WRITE (PCI_0INTERRUPT_CAUSE_MASK_REGISTER_LOW, 0);
272         GT_REG_WRITE (PCI_0INTERRUPT_CAUSE_MASK_REGISTER_HIGH, 0);
273         GT_REG_WRITE (PCI_1INTERRUPT_CAUSE_MASK_REGISTER_LOW, 0);
274         GT_REG_WRITE (PCI_1INTERRUPT_CAUSE_MASK_REGISTER_HIGH, 0);
275         /* does not exist in MV6436x
276            GT_REG_WRITE(CPU_INT_0_MASK, 0);
277            GT_REG_WRITE(CPU_INT_1_MASK, 0);
278            GT_REG_WRITE(CPU_INT_2_MASK, 0);
279            GT_REG_WRITE(CPU_INT_3_MASK, 0);
280            --------------------- */
281
282
283         /* ----- DEVICE BUS SETTINGS ------ */
284
285         /*
286          * EVB
287          * 0 - SRAM   ????
288          * 1 - RTC      ????
289          * 2 - UART     ????
290          * 3 - Flash    checked 32Bit Intel Strata
291          * boot - BootCS checked 8Bit 29LV040B
292          *
293          */
294
295         /*
296          * the dual 7450 module requires burst access to the boot
297          * device, so the serial rom copies the boot device to the
298          * on-board sram on the eval board, and updates the correct
299          * registers to boot from the sram. (device0)
300          */
301
302         memoryMapDeviceSpace (DEVICE0, CFG_DEV0_SPACE, CFG_DEV0_SIZE);
303         memoryMapDeviceSpace (DEVICE1, CFG_DEV1_SPACE, CFG_DEV1_SIZE);
304         memoryMapDeviceSpace (DEVICE2, CFG_DEV2_SPACE, CFG_DEV2_SIZE);
305         memoryMapDeviceSpace (DEVICE3, CFG_DEV3_SPACE, CFG_DEV3_SIZE);
306
307
308         /* configure device timing */
309         GT_REG_WRITE (DEVICE_BANK0PARAMETERS, CFG_DEV0_PAR);
310         GT_REG_WRITE (DEVICE_BANK1PARAMETERS, CFG_DEV1_PAR);
311         GT_REG_WRITE (DEVICE_BANK2PARAMETERS, CFG_DEV2_PAR);
312         GT_REG_WRITE (DEVICE_BANK3PARAMETERS, CFG_DEV3_PAR);
313
314 #ifdef CFG_32BIT_BOOT_PAR       /* set port parameters for Flash device module access */
315         /* detect if we are booting from the 32 bit flash */
316         if (GTREGREAD (DEVICE_BOOT_BANK_PARAMETERS) & (0x3 << 20)) {
317                 /* 32 bit boot flash */
318                 GT_REG_WRITE (DEVICE_BANK3PARAMETERS, CFG_8BIT_BOOT_PAR);
319                 GT_REG_WRITE (DEVICE_BOOT_BANK_PARAMETERS,
320                               CFG_32BIT_BOOT_PAR);
321         } else {
322                 /* 8 bit boot flash */
323                 GT_REG_WRITE (DEVICE_BANK3PARAMETERS, CFG_32BIT_BOOT_PAR);
324                 GT_REG_WRITE (DEVICE_BOOT_BANK_PARAMETERS, CFG_8BIT_BOOT_PAR);
325         }
326 #else
327         /* 8 bit boot flash only */
328 /*      GT_REG_WRITE(DEVICE_BOOT_BANK_PARAMETERS, CFG_8BIT_BOOT_PAR);*/
329 #endif
330
331
332         gt_cpu_config ();
333
334         /* MPP setup */
335         GT_REG_WRITE (MPP_CONTROL0, CFG_MPP_CONTROL_0);
336         GT_REG_WRITE (MPP_CONTROL1, CFG_MPP_CONTROL_1);
337         GT_REG_WRITE (MPP_CONTROL2, CFG_MPP_CONTROL_2);
338         GT_REG_WRITE (MPP_CONTROL3, CFG_MPP_CONTROL_3);
339
340         GT_REG_WRITE (GPP_LEVEL_CONTROL, CFG_GPP_LEVEL_CONTROL);
341         DEBUG_LED0_ON ();
342         DEBUG_LED1_ON ();
343         DEBUG_LED2_ON ();
344
345         return 0;
346 }
347
348 /* various things to do after relocation */
349
350 int misc_init_r ()
351 {
352         icache_enable ();
353 #ifdef CFG_L2
354         l2cache_enable ();
355 #endif
356 #ifdef CONFIG_MPSC
357
358         mpsc_sdma_init ();
359         mpsc_init2 ();
360 #endif
361
362 #if 0
363         /* disable the dcache and MMU */
364         dcache_lock ();
365 #endif
366         return 0;
367 }
368
369 void after_reloc (ulong dest_addr, gd_t * gd)
370 {
371
372   memoryMapDeviceSpace (BOOT_DEVICE, CFG_BOOT_SPACE, CFG_BOOT_SIZE);
373
374   display_mem_map ();
375   /* now, jump to the main ppcboot board init code */
376   board_init_r (gd, dest_addr);
377   /* NOTREACHED */
378 }
379
380 /* ------------------------------------------------------------------------- */
381
382 /*
383  * Check Board Identity:
384  *
385  * right now, assume borad type. (there is just one...after all)
386  */
387
388 int checkboard (void)
389 {
390         int l_type = 0;
391
392         printf ("BOARD: %s\n", CFG_BOARD_NAME);
393         return (l_type);
394 }
395
396 /* utility functions */
397 void debug_led (int led, int mode)
398 {
399 }
400
401 int display_mem_map (void)
402 {
403         int i, j;
404         unsigned int base, size, width;
405
406         /* SDRAM */
407         printf ("SD (DDR) RAM\n");
408         for (i = 0; i <= BANK3; i++) {
409                 base = memoryGetBankBaseAddress (i);
410                 size = memoryGetBankSize (i);
411                 if (size != 0) {
412                         printf ("BANK%d: base - 0x%08x\tsize - %dM bytes\n",
413                                 i, base, size >> 20);
414                 }
415         }
416 #ifdef CONFIG_PCI
417         /* CPU's PCI windows */
418         for (i = 0; i <= PCI_HOST1; i++) {
419                 printf ("\nCPU's PCI %d windows\n", i);
420                 base = pciGetSpaceBase (i, PCI_IO);
421                 size = pciGetSpaceSize (i, PCI_IO);
422                 printf ("      IO: base - 0x%08x\tsize - %dM bytes\n", base,
423                         size >> 20);
424                 for (j = 0;
425                      j <=
426                      PCI_REGION0
427                      /*ronen currently only first PCI MEM is used 3 */ ;
428                      j++) {
429                         base = pciGetSpaceBase (i, j);
430                         size = pciGetSpaceSize (i, j);
431                         printf ("MEMORY %d: base - 0x%08x\tsize - %dM bytes\n", j, base, size >> 20);
432                 }
433         }
434 #endif /* of CONFIG_PCI */
435         /* Devices */
436         printf ("\nDEVICES\n");
437         for (i = 0; i <= DEVICE3; i++) {
438                 base = memoryGetDeviceBaseAddress (i);
439                 size = memoryGetDeviceSize (i);
440                 width = memoryGetDeviceWidth (i) * 8;
441                 printf ("DEV %d:  base - 0x%08x  size - %dM bytes\twidth - %d bits", i, base, size >> 20, width);
442                 if (i == 0)
443                         printf ("\t- FLASH\n");
444                 else if (i == 1)
445                         printf ("\t- FLASH\n");
446                 else if (i == 2)
447                         printf ("\t- FLASH\n");
448                 else
449                         printf ("\t- RTC/REGS/CAN\n");
450         }
451
452         /* Bootrom */
453         base = memoryGetDeviceBaseAddress (BOOT_DEVICE);        /* Boot */
454         size = memoryGetDeviceSize (BOOT_DEVICE);
455         width = memoryGetDeviceWidth (BOOT_DEVICE) * 8;
456         printf (" BOOT:  base - 0x%08x  size - %dM bytes\twidth - %d bits\t- FLASH\n",
457                 base, size >> 20, width);
458         return (0);
459 }
460
461 /* DRAM check routines copied from gw8260 */
462
463 #if defined (CFG_DRAM_TEST)
464
465 /*********************************************************************/
466 /* NAME:  move64() -  moves a double word (64-bit)                   */
467 /*                                                                   */
468 /* DESCRIPTION:                                                      */
469 /*   this function performs a double word move from the data at      */
470 /*   the source pointer to the location at the destination pointer.  */
471 /*                                                                   */
472 /* INPUTS:                                                           */
473 /*   unsigned long long *src  - pointer to data to move              */
474 /*                                                                   */
475 /* OUTPUTS:                                                          */
476 /*   unsigned long long *dest - pointer to locate to move data       */
477 /*                                                                   */
478 /* RETURNS:                                                          */
479 /*   None                                                            */
480 /*                                                                   */
481 /* RESTRICTIONS/LIMITATIONS:                                         */
482 /*   May cloober fr0.                                                */
483 /*                                                                   */
484 /*********************************************************************/
485 static void move64 (unsigned long long *src, unsigned long long *dest)
486 {
487         asm ("lfd  0, 0(3)\n\t" /* fpr0   =  *scr       */
488              "stfd 0, 0(4)"     /* *dest  =  fpr0       */
489       : : : "fr0");             /* Clobbers fr0         */
490         return;
491 }
492
493
494 #if defined (CFG_DRAM_TEST_DATA)
495
496 unsigned long long pattern[] = {
497         0xaaaaaaaaaaaaaaaaLL,
498         0xccccccccccccccccLL,
499         0xf0f0f0f0f0f0f0f0LL,
500         0xff00ff00ff00ff00LL,
501         0xffff0000ffff0000LL,
502         0xffffffff00000000LL,
503         0x00000000ffffffffLL,
504         0x0000ffff0000ffffLL,
505         0x00ff00ff00ff00ffLL,
506         0x0f0f0f0f0f0f0f0fLL,
507         0x3333333333333333LL,
508         0x5555555555555555LL,
509 };
510
511 /*********************************************************************/
512 /* NAME:  mem_test_data() -  test data lines for shorts and opens    */
513 /*                                                                   */
514 /* DESCRIPTION:                                                      */
515 /*   Tests data lines for shorts and opens by forcing adjacent data  */
516 /*   to opposite states. Because the data lines could be routed in   */
517 /*   an arbitrary manner the must ensure test patterns ensure that   */
518 /*   every case is tested. By using the following series of binary   */
519 /*   patterns every combination of adjacent bits is test regardless  */
520 /*   of routing.                                                     */
521 /*                                                                   */
522 /*     ...101010101010101010101010                                   */
523 /*     ...110011001100110011001100                                   */
524 /*     ...111100001111000011110000                                   */
525 /*     ...111111110000000011111111                                   */
526 /*                                                                   */
527 /*   Carrying this out, gives us six hex patterns as follows:        */
528 /*                                                                   */
529 /*     0xaaaaaaaaaaaaaaaa                                            */
530 /*     0xcccccccccccccccc                                            */
531 /*     0xf0f0f0f0f0f0f0f0                                            */
532 /*     0xff00ff00ff00ff00                                            */
533 /*     0xffff0000ffff0000                                            */
534 /*     0xffffffff00000000                                            */
535 /*                                                                   */
536 /*   The number test patterns will always be given by:               */
537 /*                                                                   */
538 /*   log(base 2)(number data bits) = log2 (64) = 6                   */
539 /*                                                                   */
540 /*   To test for short and opens to other signals on our boards. we  */
541 /*   simply                                                          */
542 /*   test with the 1's complemnt of the paterns as well.             */
543 /*                                                                   */
544 /* OUTPUTS:                                                          */
545 /*   Displays failing test pattern                                   */
546 /*                                                                   */
547 /* RETURNS:                                                          */
548 /*   0 -  Passed test                                                */
549 /*   1 -  Failed test                                                */
550 /*                                                                   */
551 /* RESTRICTIONS/LIMITATIONS:                                         */
552 /*  Assumes only one one SDRAM bank                                  */
553 /*                                                                   */
554 /*********************************************************************/
555 int mem_test_data (void)
556 {
557         unsigned long long *pmem = (unsigned long long *) CFG_MEMTEST_START;
558         unsigned long long temp64;
559         int num_patterns = sizeof (pattern) / sizeof (pattern[0]);
560         int i;
561         unsigned int hi, lo;
562
563         for (i = 0; i < num_patterns; i++) {
564                 move64 (&(pattern[i]), pmem);
565                 move64 (pmem, &temp64);
566
567                 /* hi = (temp64>>32) & 0xffffffff;          */
568                 /* lo = temp64 & 0xffffffff;                */
569                 /* printf("\ntemp64 = 0x%08x%08x", hi, lo); */
570
571                 hi = (pattern[i] >> 32) & 0xffffffff;
572                 lo = pattern[i] & 0xffffffff;
573                 /* printf("\npattern[%d] = 0x%08x%08x", i, hi, lo);  */
574
575                 if (temp64 != pattern[i]) {
576                         printf ("\n   Data Test Failed, pattern 0x%08x%08x",
577                                 hi, lo);
578                         return 1;
579                 }
580         }
581
582         return 0;
583 }
584 #endif /* CFG_DRAM_TEST_DATA */
585
586 #if defined (CFG_DRAM_TEST_ADDRESS)
587 /*********************************************************************/
588 /* NAME:  mem_test_address() -  test address lines                   */
589 /*                                                                   */
590 /* DESCRIPTION:                                                      */
591 /*   This function performs a test to verify that each word im       */
592 /*   memory is uniquly addressable. The test sequence is as follows: */
593 /*                                                                   */
594 /*   1) write the address of each word to each word.                 */
595 /*   2) verify that each location equals its address                 */
596 /*                                                                   */
597 /* OUTPUTS:                                                          */
598 /*   Displays failing test pattern and address                       */
599 /*                                                                   */
600 /* RETURNS:                                                          */
601 /*   0 -  Passed test                                                */
602 /*   1 -  Failed test                                                */
603 /*                                                                   */
604 /* RESTRICTIONS/LIMITATIONS:                                         */
605 /*                                                                   */
606 /*                                                                   */
607 /*********************************************************************/
608 int mem_test_address (void)
609 {
610         volatile unsigned int *pmem =
611                 (volatile unsigned int *) CFG_MEMTEST_START;
612         const unsigned int size = (CFG_MEMTEST_END - CFG_MEMTEST_START) / 4;
613         unsigned int i;
614
615         /* write address to each location */
616         for (i = 0; i < size; i++) {
617                 pmem[i] = i;
618         }
619
620         /* verify each loaction */
621         for (i = 0; i < size; i++) {
622                 if (pmem[i] != i) {
623                         printf ("\n   Address Test Failed at 0x%x", i);
624                         return 1;
625                 }
626         }
627         return 0;
628 }
629 #endif /* CFG_DRAM_TEST_ADDRESS */
630
631 #if defined (CFG_DRAM_TEST_WALK)
632 /*********************************************************************/
633 /* NAME:   mem_march() -  memory march                               */
634 /*                                                                   */
635 /* DESCRIPTION:                                                      */
636 /*   Marches up through memory. At each location verifies rmask if   */
637 /*   read = 1. At each location write wmask if  write = 1. Displays  */
638 /*   failing address and pattern.                                    */
639 /*                                                                   */
640 /* INPUTS:                                                           */
641 /*   volatile unsigned long long * base - start address of test      */
642 /*   unsigned int size - number of dwords(64-bit) to test            */
643 /*   unsigned long long rmask - read verify mask                     */
644 /*   unsigned long long wmask - wrtie verify mask                    */
645 /*   short read - verifies rmask if read = 1                         */
646 /*   short write  - writes wmask if write = 1                        */
647 /*                                                                   */
648 /* OUTPUTS:                                                          */
649 /*   Displays failing test pattern and address                       */
650 /*                                                                   */
651 /* RETURNS:                                                          */
652 /*   0 -  Passed test                                                */
653 /*   1 -  Failed test                                                */
654 /*                                                                   */
655 /* RESTRICTIONS/LIMITATIONS:                                         */
656 /*                                                                   */
657 /*                                                                   */
658 /*********************************************************************/
659 int mem_march (volatile unsigned long long *base,
660                unsigned int size,
661                unsigned long long rmask,
662                unsigned long long wmask, short read, short write)
663 {
664         unsigned int i;
665         unsigned long long temp;
666         unsigned int hitemp, lotemp, himask, lomask;
667
668         for (i = 0; i < size; i++) {
669                 if (read != 0) {
670                         /* temp = base[i]; */
671                         move64 ((unsigned long long *) &(base[i]), &temp);
672                         if (rmask != temp) {
673                                 hitemp = (temp >> 32) & 0xffffffff;
674                                 lotemp = temp & 0xffffffff;
675                                 himask = (rmask >> 32) & 0xffffffff;
676                                 lomask = rmask & 0xffffffff;
677
678                                 printf ("\n Walking one's test failed: address = 0x%08x," "\n\texpected 0x%08x%08x, found 0x%08x%08x", i << 3, himask, lomask, hitemp, lotemp);
679                                 return 1;
680                         }
681                 }
682                 if (write != 0) {
683                         /*  base[i] = wmask; */
684                         move64 (&wmask, (unsigned long long *) &(base[i]));
685                 }
686         }
687         return 0;
688 }
689 #endif /* CFG_DRAM_TEST_WALK */
690
691 /*********************************************************************/
692 /* NAME:   mem_test_walk() -  a simple walking ones test             */
693 /*                                                                   */
694 /* DESCRIPTION:                                                      */
695 /*   Performs a walking ones through entire physical memory. The     */
696 /*   test uses as series of memory marches, mem_march(), to verify   */
697 /*   and write the test patterns to memory. The test sequence is as  */
698 /*   follows:                                                        */
699 /*     1) march writing 0000...0001                                  */
700 /*     2) march verifying 0000...0001  , writing  0000...0010        */
701 /*     3) repeat step 2 shifting masks left 1 bit each time unitl    */
702 /*         the write mask equals 1000...0000                         */
703 /*     4) march verifying 1000...0000                                */
704 /*   The test fails if any of the memory marches return a failure.   */
705 /*                                                                   */
706 /* OUTPUTS:                                                          */
707 /*   Displays which pass on the memory test is executing             */
708 /*                                                                   */
709 /* RETURNS:                                                          */
710 /*   0 -  Passed test                                                */
711 /*   1 -  Failed test                                                */
712 /*                                                                   */
713 /* RESTRICTIONS/LIMITATIONS:                                         */
714 /*                                                                   */
715 /*                                                                   */
716 /*********************************************************************/
717 int mem_test_walk (void)
718 {
719         unsigned long long mask;
720         volatile unsigned long long *pmem =
721                 (volatile unsigned long long *) CFG_MEMTEST_START;
722         const unsigned long size = (CFG_MEMTEST_END - CFG_MEMTEST_START) / 8;
723
724         unsigned int i;
725
726         mask = 0x01;
727
728         printf ("Initial Pass");
729         mem_march (pmem, size, 0x0, 0x1, 0, 1);
730
731         printf ("\b\b\b\b\b\b\b\b\b\b\b\b");
732         printf ("               ");
733         printf ("         ");
734         printf ("\b\b\b\b\b\b\b\b\b\b\b\b");
735
736         for (i = 0; i < 63; i++) {
737                 printf ("Pass %2d", i + 2);
738                 if (mem_march (pmem, size, mask, mask << 1, 1, 1) != 0) {
739                         /*printf("mask: 0x%x, pass: %d, ", mask, i); */
740                         return 1;
741                 }
742                 mask = mask << 1;
743                 printf ("\b\b\b\b\b\b\b");
744         }
745
746         printf ("Last Pass");
747         if (mem_march (pmem, size, 0, mask, 0, 1) != 0) {
748                 /* printf("mask: 0x%x", mask); */
749                 return 1;
750         }
751         printf ("\b\b\b\b\b\b\b\b\b");
752         printf ("            ");
753         printf ("\b\b\b\b\b\b\b\b\b");
754
755         return 0;
756 }
757
758 /*********************************************************************/
759 /* NAME:    testdram() -  calls any enabled memory tests             */
760 /*                                                                   */
761 /* DESCRIPTION:                                                      */
762 /*   Runs memory tests if the environment test variables are set to  */
763 /*   'y'.                                                            */
764 /*                                                                   */
765 /* INPUTS:                                                           */
766 /*   testdramdata    - If set to 'y', data test is run.              */
767 /*   testdramaddress - If set to 'y', address test is run.           */
768 /*   testdramwalk    - If set to 'y', walking ones test is run       */
769 /*                                                                   */
770 /* OUTPUTS:                                                          */
771 /*   None                                                            */
772 /*                                                                   */
773 /* RETURNS:                                                          */
774 /*   0 -  Passed test                                                */
775 /*   1 -  Failed test                                                */
776 /*                                                                   */
777 /* RESTRICTIONS/LIMITATIONS:                                         */
778 /*                                                                   */
779 /*                                                                   */
780 /*********************************************************************/
781 int testdram (void)
782 {
783         char *s;
784         int rundata    = 0;
785         int runaddress = 0;
786         int runwalk    = 0;
787
788 #ifdef CFG_DRAM_TEST_DATA
789         s = getenv ("testdramdata");
790         rundata = (s && (*s == 'y')) ? 1 : 0;
791 #endif
792 #ifdef CFG_DRAM_TEST_ADDRESS
793         s = getenv ("testdramaddress");
794         runaddress = (s && (*s == 'y')) ? 1 : 0;
795 #endif
796 #ifdef CFG_DRAM_TEST_WALK
797         s = getenv ("testdramwalk");
798         runwalk = (s && (*s == 'y')) ? 1 : 0;
799 #endif
800
801         if ((rundata == 1) || (runaddress == 1) || (runwalk == 1)) {
802                 printf ("Testing RAM from 0x%08x to 0x%08x ...  (don't panic... that will take a moment !!!!)\n", CFG_MEMTEST_START, CFG_MEMTEST_END);
803         }
804 #ifdef CFG_DRAM_TEST_DATA
805         if (rundata == 1) {
806                 printf ("Test DATA ...  ");
807                 if (mem_test_data () == 1) {
808                         printf ("failed \n");
809                         return 1;
810                 } else
811                         printf ("ok \n");
812         }
813 #endif
814 #ifdef CFG_DRAM_TEST_ADDRESS
815         if (runaddress == 1) {
816                 printf ("Test ADDRESS ...  ");
817                 if (mem_test_address () == 1) {
818                         printf ("failed \n");
819                         return 1;
820                 } else
821                         printf ("ok \n");
822         }
823 #endif
824 #ifdef CFG_DRAM_TEST_WALK
825         if (runwalk == 1) {
826                 printf ("Test WALKING ONEs ...  ");
827                 if (mem_test_walk () == 1) {
828                         printf ("failed \n");
829                         return 1;
830                 } else
831                         printf ("ok \n");
832         }
833 #endif
834         if ((rundata == 1) || (runaddress == 1) || (runwalk == 1)) {
835                 printf ("passed\n");
836         }
837         return 0;
838
839 }
840 #endif /* CFG_DRAM_TEST */
841
842 /* ronen - the below functions are used by the bootm function           */
843 /*  - we map the base register to fbe00000 (same mapping as in the LSP) */
844 /*  - we turn off the RX gig dmas - to prevent the dma from overunning  */
845 /*    the kernel data areas.                                            */
846 /*  - we diable and invalidate the icache and dcache.                   */
847 void my_remap_gt_regs_bootm (u32 cur_loc, u32 new_loc)
848 {
849         u32 temp;
850
851         temp = in_le32 ((u32 *) (new_loc + INTERNAL_SPACE_DECODE));
852         if ((temp & 0xffff) == new_loc >> 16)
853                 return;
854
855         temp = (in_le32 ((u32 *) (cur_loc + INTERNAL_SPACE_DECODE)) &
856                 0xffff0000) | (new_loc >> 16);
857
858         out_le32 ((u32 *) (cur_loc + INTERNAL_SPACE_DECODE), temp);
859
860         while ((WORD_SWAP (*((volatile unsigned int *) (NONE_CACHEABLE |
861                                                         new_loc |
862                                                         (INTERNAL_SPACE_DECODE)))))
863                != temp);
864
865 }
866
867 void board_prebootm_init ()
868 {
869
870 /* change window size of PCI1 IO in order tp prevent overlaping with REG BASE. */
871                 GT_REG_WRITE (PCI_1_IO_SIZE, (_64K - 1) >> 16);
872
873 /* Stop GigE Rx DMA engines */
874         GT_REG_WRITE (MV64360_ETH_RECEIVE_QUEUE_COMMAND_REG (0), 0x0000ff00);
875 /*      GT_REG_WRITE (MV64360_ETH_RECEIVE_QUEUE_COMMAND_REG (1), 0x0000ff00); */
876 /*      GV_REG_WRITE (MV64360_ETH_RECEIVE_QUEUE_COMMAND_REG (2), 0x0000ff00); */
877
878 /* Relocate MV64360 internal regs */
879         my_remap_gt_regs_bootm (CFG_GT_REGS, CFG_DFL_GT_REGS);
880
881         icache_disable ();
882         invalidate_l1_instruction_cache ();
883         flush_data_cache ();
884         dcache_disable ();
885 }