blob: d54ddaffc1ecbc4dbe51fc382430773d79f1d9d6 [file] [log] [blame]
Stefan Roese1eac2a72006-11-29 15:42:37 +01001/*
2 * (C) Copyright 2006
3 * Stefan Roese, DENX Software Engineering, sr@denx.de.
4 *
5 * Based on original work by
6 * Roel Loeffen, (C) Copyright 2006 Prodrive B.V.
7 * Josh Huber, (C) Copyright 2001 Mission Critical Linux, Inc.
8 *
9 * See file CREDITS for list of people who contributed to this
10 * project.
11 *
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License as
14 * published by the Free Software Foundation; either version 2 of
15 * the License, or (at your option) any later version.
16 *
17 * This program is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
21 *
22 * You should have received a copy of the GNU General Public License
23 * along with this program; if not, write to the Free Software
24 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
25 * MA 02111-1307 USA
26 *
27 * modifications for the DB64360 eval board based by Ingo.Assmus@keymile.com
28 * modifications for the cpci750 by reinhard.arlt@esd-electronics.com
29 * modifications for the P3M750 by roel.loeffen@prodrive.nl
30 */
31
32/*
33 * p3m750.c - main board support/init for the Prodrive p3m750/p3m7448.
34 */
35
36#include <common.h>
37#include <74xx_7xx.h>
38#include "../../Marvell/include/memory.h"
39#include "../../Marvell/include/pci.h"
40#include "../../Marvell/include/mv_gen_reg.h"
41#include <net.h>
42#include <i2c.h>
43
44#include "eth.h"
45#include "mpsc.h"
46#include "64460.h"
47#include "mv_regs.h"
Stefan Roese0057d752007-01-18 11:54:52 +010048#include "p3mx.h"
Stefan Roese1eac2a72006-11-29 15:42:37 +010049
50DECLARE_GLOBAL_DATA_PTR;
51
52#undef DEBUG
53/*#define DEBUG */
54
55#ifdef CONFIG_PCI
56#define MAP_PCI
57#endif /* of CONFIG_PCI */
58
59#ifdef DEBUG
60#define DP(x) x
61#else
62#define DP(x)
63#endif
64
65extern void flush_data_cache (void);
66extern void invalidate_l1_instruction_cache (void);
67extern flash_info_t flash_info[];
68
69/* ------------------------------------------------------------------------- */
70
71/* this is the current GT register space location */
72/* it starts at CFG_DFL_GT_REGS but moves later to CFG_GT_REGS */
73
74/* Unfortunately, we cant change it while we are in flash, so we initialize it
75 * to the "final" value. This means that any debug_led calls before
76 * board_early_init_f wont work right (like in cpu_init_f).
77 * See also my_remap_gt_regs below. (NTL)
78 */
79
80void board_prebootm_init (void);
81unsigned int INTERNAL_REG_BASE_ADDR = CFG_GT_REGS;
82int display_mem_map (void);
Stefan Roese0057d752007-01-18 11:54:52 +010083void set_led(int);
Stefan Roese1eac2a72006-11-29 15:42:37 +010084
85/* ------------------------------------------------------------------------- */
86
87/*
88 * This is a version of the GT register space remapping function that
89 * doesn't touch globals (meaning, it's ok to run from flash.)
90 *
91 * Unfortunately, this has the side effect that a writable
92 * INTERNAL_REG_BASE_ADDR is impossible. Oh well.
93 */
94
95void my_remap_gt_regs (u32 cur_loc, u32 new_loc)
96{
97 u32 temp;
98
99 /* check and see if it's already moved */
100 temp = in_le32 ((u32 *) (new_loc + INTERNAL_SPACE_DECODE));
101 if ((temp & 0xffff) == new_loc >> 16)
102 return;
103
104 temp = (in_le32 ((u32 *) (cur_loc + INTERNAL_SPACE_DECODE)) &
105 0xffff0000) | (new_loc >> 16);
106
107 out_le32 ((u32 *) (cur_loc + INTERNAL_SPACE_DECODE), temp);
108
109 while (GTREGREAD (INTERNAL_SPACE_DECODE) != temp);
110}
111
112#ifdef CONFIG_PCI
113
114static void gt_pci_config (void)
115{
116 unsigned int stat;
117 unsigned int val = 0x00fff864; /* DINK32: BusNum 23:16, DevNum 15:11, */
118 /* FuncNum 10:8, RegNum 7:2 */
119
120 /*
121 * In PCIX mode devices provide their own bus and device numbers.
122 * We query the Discovery II's
123 * config registers by writing ones to the bus and device.
124 * We then update the Virtual register with the correct value for the
125 * bus and device.
126 */
127 if ((GTREGREAD (PCI_0_MODE) & (BIT4 | BIT5)) != 0) { /* if PCI-X */
128 GT_REG_WRITE (PCI_0_CONFIG_ADDR, BIT31 | val);
129
130 GT_REG_READ (PCI_0_CONFIG_DATA_VIRTUAL_REG, &stat);
131
132 GT_REG_WRITE (PCI_0_CONFIG_ADDR, BIT31 | val);
133 GT_REG_WRITE (PCI_0_CONFIG_DATA_VIRTUAL_REG,
134 (stat & 0xffff0000) | CFG_PCI_IDSEL);
135
136 }
137 if ((GTREGREAD (PCI_1_MODE) & (BIT4 | BIT5)) != 0) { /* if PCI-X */
138 GT_REG_WRITE (PCI_1_CONFIG_ADDR, BIT31 | val);
139 GT_REG_READ (PCI_1_CONFIG_DATA_VIRTUAL_REG, &stat);
140
141 GT_REG_WRITE (PCI_1_CONFIG_ADDR, BIT31 | val);
142 GT_REG_WRITE (PCI_1_CONFIG_DATA_VIRTUAL_REG,
143 (stat & 0xffff0000) | CFG_PCI_IDSEL);
144 }
145
146 /* Enable master */
147 PCI_MASTER_ENABLE (0, SELF);
148 PCI_MASTER_ENABLE (1, SELF);
149
150 /* Enable PCI0/1 Mem0 and IO 0 disable all others */
151 GT_REG_READ (BASE_ADDR_ENABLE, &stat);
152 stat |= (1 << 11) | (1 << 12) | (1 << 13) | (1 << 16) | (1 << 17) |
153 (1 << 18);
154 stat &= ~((1 << 9) | (1 << 10) | (1 << 14) | (1 << 15));
155 GT_REG_WRITE (BASE_ADDR_ENABLE, stat);
156
157 /* ronen:
158 * add write to pci remap registers for 64460.
159 * in 64360 when writing to pci base go and overide remap automaticaly,
160 * in 64460 it doesn't
161 */
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:
188 * update the pci internal registers base address.
189 */
190#ifdef MAP_PCI
191 for (stat = 0; stat <= PCI_HOST1; stat++)
192 pciWriteConfigReg (stat,
193 PCI_INTERNAL_REGISTERS_MEMORY_MAPPED_BASE_ADDRESS,
194 SELF, CFG_GT_REGS);
195#endif
196
197}
198#endif
199
200/* Setup CPU interface paramaters */
201static void gt_cpu_config (void)
202{
203 cpu_t cpu = get_cpu_type ();
204 ulong tmp;
205
206 /* cpu configuration register */
207 tmp = GTREGREAD (CPU_CONFIGURATION);
208 /* set the SINGLE_CPU bit see MV64460 */
209#ifndef CFG_GT_DUAL_CPU /* SINGLE_CPU seems to cause JTAG problems */
210 tmp |= CPU_CONF_SINGLE_CPU;
211#endif
212 tmp &= ~CPU_CONF_AACK_DELAY_2;
213 tmp |= CPU_CONF_DP_VALID;
214 tmp |= CPU_CONF_AP_VALID;
215 tmp |= CPU_CONF_PIPELINE;
216 GT_REG_WRITE (CPU_CONFIGURATION, tmp); /* Marvell (VXWorks) writes 0x20220FF */
217
218 /* CPU master control register */
219 tmp = GTREGREAD (CPU_MASTER_CONTROL);
220 tmp |= CPU_MAST_CTL_ARB_EN;
221
222 if ((cpu == CPU_7400) ||
223 (cpu == CPU_7410) || (cpu == CPU_7455) || (cpu == CPU_7450)) {
224
225 tmp |= CPU_MAST_CTL_CLEAN_BLK;
226 tmp |= CPU_MAST_CTL_FLUSH_BLK;
227
228 } else {
229 /* cleanblock must be cleared for CPUs
230 * that do not support this command (603e, 750)
231 * see Res#1 */
232 tmp &= ~CPU_MAST_CTL_CLEAN_BLK;
233 tmp &= ~CPU_MAST_CTL_FLUSH_BLK;
234 }
235 GT_REG_WRITE (CPU_MASTER_CONTROL, tmp);
236}
237
238/*
239 * board_early_init_f.
240 *
241 * set up gal. device mappings, etc.
242 */
243int board_early_init_f (void)
244{
245 /* set up the GT the way the kernel wants it
246 * the call to move the GT register space will obviously
247 * fail if it has already been done, but we're going to assume
248 * that if it's not at the power-on location, it's where we put
249 * it last time. (huber)
250 */
Stefan Roese1eac2a72006-11-29 15:42:37 +0100251 my_remap_gt_regs (CFG_DFL_GT_REGS, CFG_GT_REGS);
252
253#ifdef CONFIG_PCI
254 gt_pci_config ();
255#endif
256 /* mask all external interrupt sources */
257 GT_REG_WRITE (CPU_INTERRUPT_MASK_REGISTER_LOW, 0);
258 GT_REG_WRITE (CPU_INTERRUPT_MASK_REGISTER_HIGH, 0);
259 /* new in >MV6436x */
260 GT_REG_WRITE (CPU_INTERRUPT_1_MASK_REGISTER_LOW, 0);
261 GT_REG_WRITE (CPU_INTERRUPT_1_MASK_REGISTER_HIGH, 0);
262 /* --------------------- */
263 GT_REG_WRITE (PCI_0INTERRUPT_CAUSE_MASK_REGISTER_LOW, 0);
264 GT_REG_WRITE (PCI_0INTERRUPT_CAUSE_MASK_REGISTER_HIGH, 0);
265 GT_REG_WRITE (PCI_1INTERRUPT_CAUSE_MASK_REGISTER_LOW, 0);
266 GT_REG_WRITE (PCI_1INTERRUPT_CAUSE_MASK_REGISTER_HIGH, 0);
267
268 /* Device and Boot bus settings
269 */
270 memoryMapDeviceSpace(DEVICE0, 0, 0);
271 GT_REG_WRITE(DEVICE_BANK0PARAMETERS, 0);
272 memoryMapDeviceSpace(DEVICE1, 0, 0);
273 GT_REG_WRITE(DEVICE_BANK1PARAMETERS, 0);
274 memoryMapDeviceSpace(DEVICE2, 0, 0);
275 GT_REG_WRITE(DEVICE_BANK2PARAMETERS, 0);
276 memoryMapDeviceSpace(DEVICE3, 0, 0);
277 GT_REG_WRITE(DEVICE_BANK3PARAMETERS, 0);
278
279 GT_REG_WRITE(DEVICE_BOOT_BANK_PARAMETERS, CFG_BOOT_PAR);
280
281 gt_cpu_config();
282
283 /* MPP setup */
284 GT_REG_WRITE (MPP_CONTROL0, CFG_MPP_CONTROL_0);
285 GT_REG_WRITE (MPP_CONTROL1, CFG_MPP_CONTROL_1);
286 GT_REG_WRITE (MPP_CONTROL2, CFG_MPP_CONTROL_2);
287 GT_REG_WRITE (MPP_CONTROL3, CFG_MPP_CONTROL_3);
288
289 GT_REG_WRITE (GPP_LEVEL_CONTROL, CFG_GPP_LEVEL_CONTROL);
290
Stefan Roese0057d752007-01-18 11:54:52 +0100291 set_led(LED_RED);
292
Stefan Roese1eac2a72006-11-29 15:42:37 +0100293 return 0;
294}
295
296/* various things to do after relocation */
297
298int misc_init_r ()
299{
300 u8 val;
301
302 icache_enable ();
303#ifdef CFG_L2
304 l2cache_enable ();
305#endif
306#ifdef CONFIG_MPSC
307 mpsc_sdma_init ();
308 mpsc_init2 ();
309#endif
310
311 /*
312 * Enable trickle changing in RTC upon powerup
313 * No diode, 250 ohm series resistor
314 */
315 val = 0xa5;
316 i2c_write(CFG_I2C_RTC_ADDR, 8, 1, &val, 1);
317
318 return 0;
319}
320
321int board_early_init_r(void)
322{
323 /* now relocate the debug serial driver */
324 mpsc_putchar += gd->reloc_off;
325 mpsc_getchar += gd->reloc_off;
326 mpsc_test_char += gd->reloc_off;
327
328 return 0;
329}
330
331void after_reloc (ulong dest_addr, gd_t * gd)
332{
333 memoryMapDeviceSpace (BOOT_DEVICE, CFG_BOOT_SPACE, CFG_BOOT_SIZE);
334
335/* display_mem_map(); */
336
337 /* now, jump to the main U-Boot board init code */
Stefan Roese0057d752007-01-18 11:54:52 +0100338 set_led(LED_GREEN);
Stefan Roese1eac2a72006-11-29 15:42:37 +0100339 board_init_r (gd, dest_addr);
340 /* NOTREACHED */
341}
342
343/*
344 * Check Board Identity:
345 * right now, assume borad type. (there is just one...after all)
346 */
347
348int checkboard (void)
349{
350 char *s = getenv("serial#");
351
352 printf("Board: %s", CFG_BOARD_NAME);
353
354 if (s != NULL) {
355 puts(", serial# ");
356 puts(s);
357 }
358 putc('\n');
359
360 return (0);
361}
362
Stefan Roese0057d752007-01-18 11:54:52 +0100363void set_led(int col)
Stefan Roese1eac2a72006-11-29 15:42:37 +0100364{
Stefan Roese0057d752007-01-18 11:54:52 +0100365 int tmp;
366 int on_pin;
367 int off_pin;
368
369 /* Program Mpp[22] as Gpp[22]
370 * Program Mpp[23] as Gpp[23]
371 */
372 tmp = GTREGREAD(MPP_CONTROL2);
373 tmp &= 0x00ffffff;
374 GT_REG_WRITE(MPP_CONTROL2,tmp);
375
376 /* Program Gpp[22] and Gpp[23] as output
377 */
378 tmp = GTREGREAD(GPP_IO_CONTROL);
379 tmp |= 0x00C00000;
380 GT_REG_WRITE(GPP_IO_CONTROL, tmp);
381
382 /* Program Gpp[22] and Gpp[23] as active high
383 */
384 tmp = GTREGREAD(GPP_LEVEL_CONTROL);
385 tmp &= 0xff3fffff;
386 GT_REG_WRITE(GPP_LEVEL_CONTROL, tmp);
387
388 switch(col) {
389 default:
390 case LED_OFF :
391 on_pin = 0;
392 off_pin = ((1 << 23) | (1 << 22));
393 break;
394 case LED_RED :
395 on_pin = (1 << 23);
396 off_pin = (1 << 22);
397 break;
398 case LED_GREEN :
399 on_pin = (1 << 22);
400 off_pin = (1 << 23);
401 break;
402 case LED_ORANGE :
403 on_pin = ((1 << 23) | (1 << 22));
404 off_pin = 0;
405 break;
406 }
407
408 /* Set output Gpp[22] and Gpp[23]
409 */
410 tmp = GTREGREAD(GPP_VALUE);
411 tmp |= on_pin;
412 tmp &= ~off_pin;
413 GT_REG_WRITE(GPP_VALUE, tmp);
Stefan Roese1eac2a72006-11-29 15:42:37 +0100414}
415
416int display_mem_map (void)
417{
Stefan Roese0057d752007-01-18 11:54:52 +0100418 int i;
Stefan Roese1eac2a72006-11-29 15:42:37 +0100419 unsigned int base, size, width;
Stefan Roese0057d752007-01-18 11:54:52 +0100420#ifdef CONFIG_PCI
421 int j;
422#endif
Stefan Roese1eac2a72006-11-29 15:42:37 +0100423
424 /* SDRAM */
425 printf ("SD (DDR) RAM\n");
426 for (i = 0; i <= BANK3; i++) {
427 base = memoryGetBankBaseAddress (i);
428 size = memoryGetBankSize (i);
429 if (size != 0)
430 printf ("BANK%d: base - 0x%08x\tsize - %dM bytes\n",
431 i, base, size >> 20);
432 }
433#ifdef CONFIG_PCI
434 /* CPU's PCI windows */
435 for (i = 0; i <= PCI_HOST1; i++) {
436 printf ("\nCPU's PCI %d windows\n", i);
437 base = pciGetSpaceBase (i, PCI_IO);
438 size = pciGetSpaceSize (i, PCI_IO);
439 printf (" IO: base - 0x%08x\tsize - %dM bytes\n", base,
440 size >> 20);
441 /* ronen currently only first PCI MEM is used 3 */
442 for (j = 0; j <= PCI_REGION0; j++) {
443 base = pciGetSpaceBase (i, j);
444 size = pciGetSpaceSize (i, j);
445 printf ("MEMORY %d: base - 0x%08x\tsize - %dM bytes\n",
446 j, base, size >> 20);
447 }
448 }
449#endif /* of CONFIG_PCI */
450
451 /* Bootrom */
452 base = memoryGetDeviceBaseAddress (BOOT_DEVICE); /* Boot */
453 size = memoryGetDeviceSize (BOOT_DEVICE);
454 width = memoryGetDeviceWidth (BOOT_DEVICE) * 8;
455 printf (" BOOT: base - 0x%08x size - %dM bytes\twidth - %d bits\t- FLASH\n",
456 base, size >> 20, width);
457
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/*********************************************************************/
485static 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
496unsigned long long pattern[] = {
497 0xaaaaaaaaaaaaaaaaULL,
498 0xccccccccccccccccULL,
499 0xf0f0f0f0f0f0f0f0ULL,
500 0xff00ff00ff00ff00ULL,
501 0xffff0000ffff0000ULL,
502 0xffffffff00000000ULL,
503 0x00000000ffffffffULL,
504 0x0000ffff0000ffffULL,
505 0x00ff00ff00ff00ffULL,
506 0x0f0f0f0f0f0f0f0fULL,
507 0x3333333333333333ULL,
508 0x5555555555555555ULL
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/*********************************************************************/
555int mem_test_data (void)
556{
557 unsigned long long *pmem = (unsigned long long *) CFG_MEMTEST_START;
558 unsigned long long temp64 = 0;
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/*********************************************************************/
608int 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 /* verify each loaction */
620 for (i = 0; i < size; i++) {
621 if (pmem[i] != i) {
622 printf ("\n Address Test Failed at 0x%x", i);
623 return 1;
624 }
625 }
626 return 0;
627}
628#endif /* CFG_DRAM_TEST_ADDRESS */
629
630#if defined (CFG_DRAM_TEST_WALK)
631/*********************************************************************/
632/* NAME: mem_march() - memory march */
633/* */
634/* DESCRIPTION: */
635/* Marches up through memory. At each location verifies rmask if */
636/* read = 1. At each location write wmask if write = 1. Displays */
637/* failing address and pattern. */
638/* */
639/* INPUTS: */
640/* volatile unsigned long long * base - start address of test */
641/* unsigned int size - number of dwords(64-bit) to test */
642/* unsigned long long rmask - read verify mask */
643/* unsigned long long wmask - wrtie verify mask */
644/* short read - verifies rmask if read = 1 */
645/* short write - writes wmask if write = 1 */
646/* */
647/* OUTPUTS: */
648/* Displays failing test pattern and address */
649/* */
650/* RETURNS: */
651/* 0 - Passed test */
652/* 1 - Failed test */
653/* */
654/* RESTRICTIONS/LIMITATIONS: */
655/* */
656/* */
657/*********************************************************************/
658int mem_march (volatile unsigned long long *base,
659 unsigned int size,
660 unsigned long long rmask,
661 unsigned long long wmask, short read, short write)
662{
663 unsigned int i;
664 unsigned long long temp = 0;
665 unsigned int hitemp, lotemp, himask, lomask;
666
667 for (i = 0; i < size; i++) {
668 if (read != 0) {
669 /* temp = base[i]; */
670 move64 ((unsigned long long *) &(base[i]), &temp);
671 if (rmask != temp) {
672 hitemp = (temp >> 32) & 0xffffffff;
673 lotemp = temp & 0xffffffff;
674 himask = (rmask >> 32) & 0xffffffff;
675 lomask = rmask & 0xffffffff;
676
677 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);
678 return 1;
679 }
680 }
681 if (write != 0) {
682 /* base[i] = wmask; */
683 move64 (&wmask, (unsigned long long *) &(base[i]));
684 }
685 }
686 return 0;
687}
688#endif /* CFG_DRAM_TEST_WALK */
689
690/*********************************************************************/
691/* NAME: mem_test_walk() - a simple walking ones test */
692/* */
693/* DESCRIPTION: */
694/* Performs a walking ones through entire physical memory. The */
695/* test uses as series of memory marches, mem_march(), to verify */
696/* and write the test patterns to memory. The test sequence is as */
697/* follows: */
698/* 1) march writing 0000...0001 */
699/* 2) march verifying 0000...0001 , writing 0000...0010 */
700/* 3) repeat step 2 shifting masks left 1 bit each time unitl */
701/* the write mask equals 1000...0000 */
702/* 4) march verifying 1000...0000 */
703/* The test fails if any of the memory marches return a failure. */
704/* */
705/* OUTPUTS: */
706/* Displays which pass on the memory test is executing */
707/* */
708/* RETURNS: */
709/* 0 - Passed test */
710/* 1 - Failed test */
711/* */
712/* RESTRICTIONS/LIMITATIONS: */
713/* */
714/* */
715/*********************************************************************/
716int mem_test_walk (void)
717{
718 unsigned long long mask;
719 volatile unsigned long long *pmem =
720 (volatile unsigned long long *) CFG_MEMTEST_START;
721 const unsigned long size = (CFG_MEMTEST_END - CFG_MEMTEST_START) / 8;
722
723 unsigned int i;
724
725 mask = 0x01;
726
727 printf ("Initial Pass");
728 mem_march (pmem, size, 0x0, 0x1, 0, 1);
729
730 printf ("\b\b\b\b\b\b\b\b\b\b\b\b");
731 printf (" ");
732 printf (" ");
733 printf ("\b\b\b\b\b\b\b\b\b\b\b\b");
734
735 for (i = 0; i < 63; i++) {
736 printf ("Pass %2d", i + 2);
737 if (mem_march (pmem, size, mask, mask << 1, 1, 1) != 0) {
738 /*printf("mask: 0x%x, pass: %d, ", mask, i); */
739 return 1;
740 }
741 mask = mask << 1;
742 printf ("\b\b\b\b\b\b\b");
743 }
744
745 printf ("Last Pass");
746 if (mem_march (pmem, size, 0, mask, 0, 1) != 0) {
747 /* printf("mask: 0x%x", mask); */
748 return 1;
749 }
750 printf ("\b\b\b\b\b\b\b\b\b");
751 printf (" ");
752 printf ("\b\b\b\b\b\b\b\b\b");
753
754 return 0;
755}
756
757/*********************************************************************/
758/* NAME: testdram() - calls any enabled memory tests */
759/* */
760/* DESCRIPTION: */
761/* Runs memory tests if the environment test variables are set to */
762/* 'y'. */
763/* */
764/* INPUTS: */
765/* testdramdata - If set to 'y', data test is run. */
766/* testdramaddress - If set to 'y', address test is run. */
767/* testdramwalk - If set to 'y', walking ones test is run */
768/* */
769/* OUTPUTS: */
770/* None */
771/* */
772/* RETURNS: */
773/* 0 - Passed test */
774/* 1 - Failed test */
775/* */
776/* RESTRICTIONS/LIMITATIONS: */
777/* */
778/* */
779/*********************************************************************/
780int testdram (void)
781{
782 char *s;
783 int rundata = 0;
784 int runaddress = 0;
785 int runwalk = 0;
786
787#ifdef CFG_DRAM_TEST_DATA
788 s = getenv ("testdramdata");
789 rundata = (s && (*s == 'y')) ? 1 : 0;
790#endif
791#ifdef CFG_DRAM_TEST_ADDRESS
792 s = getenv ("testdramaddress");
793 runaddress = (s && (*s == 'y')) ? 1 : 0;
794#endif
795#ifdef CFG_DRAM_TEST_WALK
796 s = getenv ("testdramwalk");
797 runwalk = (s && (*s == 'y')) ? 1 : 0;
798#endif
799
800 if ((rundata == 1) || (runaddress == 1) || (runwalk == 1))
801 printf ("Testing RAM from 0x%08x to 0x%08x ... "
802 "(don't panic... that will take a moment !!!!)\n",
803 CFG_MEMTEST_START, CFG_MEMTEST_END);
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 return 0;
837
838}
839#endif /* CFG_DRAM_TEST */
840
841/* ronen - the below functions are used by the bootm function */
842/* - we map the base register to fbe00000 (same mapping as in the LSP) */
843/* - we turn off the RX gig dmas - to prevent the dma from overunning */
844/* the kernel data areas. */
845/* - we diable and invalidate the icache and dcache. */
846void my_remap_gt_regs_bootm (u32 cur_loc, u32 new_loc)
847{
848 u32 temp;
849
850 temp = in_le32 ((u32 *) (new_loc + INTERNAL_SPACE_DECODE));
851 if ((temp & 0xffff) == new_loc >> 16)
852 return;
853
854 temp = (in_le32 ((u32 *) (cur_loc + INTERNAL_SPACE_DECODE)) &
855 0xffff0000) | (new_loc >> 16);
856
857 out_le32 ((u32 *) (cur_loc + INTERNAL_SPACE_DECODE), temp);
858
859 while ((WORD_SWAP (*((volatile unsigned int *) (NONE_CACHEABLE |
860 new_loc |
861 (INTERNAL_SPACE_DECODE)))))
862 != temp);
863
864}