db64460.c 27 KB

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