memory.c 49 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390
  1. /*
  2. * Copyright - Galileo technology.
  3. *
  4. * See file CREDITS for list of people who contributed to this
  5. * project.
  6. *
  7. * This program is free software; you can redistribute it and/or
  8. * modify it under the terms of the GNU General Public License as
  9. * published by the Free Software Foundation; either version 2 of
  10. * the License, or (at your option) any later version.
  11. *
  12. * This program is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License
  18. * along with this program; if not, write to the Free Software
  19. * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
  20. * MA 02111-1307 USA
  21. */
  22. /*
  23. *
  24. * written or collected and sometimes rewritten by
  25. * Ingo Assmus <ingo.assmus@keymile.com>
  26. *
  27. */
  28. #include <common.h>
  29. #include "../include/core.h"
  30. #include "../include/memory.h"
  31. /*******************************************************************************
  32. * memoryGetBankBaseAddress - Returns the base address of a memory bank.
  33. * DESCRIPTION:
  34. * This function returns the base address of one of the SDRAM’s memory
  35. * banks. There are 4 memory banks and each one represents one DIMM side.
  36. * INPUT:
  37. * MEMORY_BANK bank - Selects one of the four banks as defined in Memory.h.
  38. * OUTPUT:
  39. * None.
  40. * RETURN:
  41. * 32 bit Memory bank base address.
  42. *******************************************************************************/
  43. static unsigned long memoryGetBankRegOffset (MEMORY_BANK bank)
  44. {
  45. switch (bank) {
  46. case BANK0:
  47. return SCS_0_LOW_DECODE_ADDRESS;
  48. case BANK1:
  49. return SCS_1_LOW_DECODE_ADDRESS;
  50. case BANK2:
  51. return SCS_2_LOW_DECODE_ADDRESS;
  52. case BANK3:
  53. return SCS_3_LOW_DECODE_ADDRESS;
  54. }
  55. return SCS_0_LOW_DECODE_ADDRESS; /* default value */
  56. }
  57. unsigned int memoryGetBankBaseAddress (MEMORY_BANK bank)
  58. {
  59. unsigned int base;
  60. unsigned int regOffset = memoryGetBankRegOffset (bank);
  61. GT_REG_READ (regOffset, &base);
  62. base = base << 16; /* MV6436x */
  63. return base;
  64. }
  65. /*******************************************************************************
  66. * memoryGetDeviceBaseAddress - Returns the base address of a device.
  67. * DESCRIPTION:
  68. * This function returns the base address of a device on the system. There
  69. * are 5 possible devices (0 - 4 and one boot device) as defined in
  70. * gtMemory.h. Each of the device parameters is maped to one of the CS
  71. * (Devices chip selects) base address register.
  72. * INPUT:
  73. * device - Selects one of the five devices as defined in Memory.h.
  74. * OUTPUT:
  75. * None.
  76. * RETURN:
  77. * 32 bit Device base address.
  78. *
  79. *******************************************************************************/
  80. static unsigned int memoryGetDeviceRegOffset (DEVICE device)
  81. {
  82. switch (device) {
  83. case DEVICE0:
  84. return CS_0_LOW_DECODE_ADDRESS;
  85. case DEVICE1:
  86. return CS_1_LOW_DECODE_ADDRESS;
  87. case DEVICE2:
  88. return CS_2_LOW_DECODE_ADDRESS;
  89. case DEVICE3:
  90. return CS_3_LOW_DECODE_ADDRESS;
  91. case BOOT_DEVICE:
  92. return BOOTCS_LOW_DECODE_ADDRESS;
  93. }
  94. return CS_0_LOW_DECODE_ADDRESS; /* default value */
  95. }
  96. unsigned int memoryGetDeviceBaseAddress (DEVICE device)
  97. {
  98. unsigned int regBase;
  99. unsigned int regOffset = memoryGetDeviceRegOffset (device);
  100. GT_REG_READ (regOffset, &regBase);
  101. regBase = regBase << 16; /* MV6436x */
  102. return regBase;
  103. }
  104. /*******************************************************************************
  105. * MemoryGetPciBaseAddr - Returns the base address of a PCI window.
  106. * DESCRIPTION:
  107. * This function returns the base address of a PCI window. There are 5
  108. * possible PCI windows (memory 0 - 3 and one for I/O) for each PCI
  109. * interface as defined in gtMemory.h, used by the CPU's address decoding
  110. * mechanism.
  111. * New in MV6436x
  112. * INPUT:
  113. * pciWindow - Selects one of the PCI windows as defined in Memory.h.
  114. * OUTPUT:
  115. * None.
  116. * RETURN:
  117. * 32 bit PCI window base address.
  118. *******************************************************************************/
  119. unsigned int MemoryGetPciBaseAddr (PCI_MEM_WINDOW pciWindow)
  120. {
  121. unsigned int baseAddrReg, base;
  122. switch (pciWindow) {
  123. case PCI_0_IO:
  124. baseAddrReg = PCI_0I_O_LOW_DECODE_ADDRESS; /*PCI_0_IO_BASE_ADDR; */
  125. break;
  126. case PCI_0_MEM0:
  127. baseAddrReg = PCI_0MEMORY0_LOW_DECODE_ADDRESS; /*PCI_0_MEMORY0_BASE_ADDR; */
  128. break;
  129. case PCI_0_MEM1:
  130. baseAddrReg = PCI_0MEMORY1_LOW_DECODE_ADDRESS; /*PCI_0_MEMORY1_BASE_ADDR; */
  131. break;
  132. case PCI_0_MEM2:
  133. baseAddrReg = PCI_0MEMORY2_LOW_DECODE_ADDRESS; /*PCI_0_MEMORY2_BASE_ADDR; */
  134. break;
  135. case PCI_0_MEM3:
  136. baseAddrReg = PCI_0MEMORY3_LOW_DECODE_ADDRESS; /*PCI_0_MEMORY3_BASE_ADDR; */
  137. break;
  138. #ifdef INCLUDE_PCI_1
  139. case PCI_1_IO:
  140. baseAddrReg = PCI_1I_O_LOW_DECODE_ADDRESS; /*PCI_1_IO_BASE_ADDR; */
  141. break;
  142. case PCI_1_MEM0:
  143. baseAddrReg = PCI_1MEMORY0_LOW_DECODE_ADDRESS; /*PCI_1_MEMORY0_BASE_ADDR; */
  144. break;
  145. case PCI_1_MEM1:
  146. baseAddrReg = PCI_1MEMORY1_LOW_DECODE_ADDRESS; /*PCI_1_MEMORY1_BASE_ADDR; */
  147. break;
  148. case PCI_1_MEM2:
  149. baseAddrReg = PCI_1MEMORY2_LOW_DECODE_ADDRESS; /*PCI_1_MEMORY2_BASE_ADDR; */
  150. break;
  151. case PCI_1_MEM3:
  152. baseAddrReg = PCI_1MEMORY3_LOW_DECODE_ADDRESS; /*PCI_1_MEMORY3_BASE_ADDR; */
  153. break;
  154. #endif /* INCLUDE_PCI_1 */
  155. default:
  156. return 0xffffffff;
  157. }
  158. GT_REG_READ (baseAddrReg, &base);
  159. return (base << 16);
  160. }
  161. /*******************************************************************************
  162. * memoryGetBankSize - Returns the size of a memory bank.
  163. * DESCRIPTION:
  164. * This function returns the size of memory bank as described in
  165. * 'gtMemoryGetBankBaseAddress' function.
  166. * INPUT:
  167. * bank - Selects one of the four banks as defined in Memory.h.
  168. * OUTPUT:
  169. * None.
  170. * RETURN:
  171. * 32 bit size memory bank size or 0 for a closed or non populated bank.
  172. *
  173. *******************************************************************************/
  174. unsigned int memoryGetBankSize (MEMORY_BANK bank)
  175. {
  176. unsigned int sizeReg, size;
  177. MEMORY_WINDOW window;
  178. switch (bank) {
  179. case BANK0:
  180. sizeReg = SCS_0_HIGH_DECODE_ADDRESS; /* CS_0_SIZE; */
  181. window = CS_0_WINDOW;
  182. break;
  183. case BANK1:
  184. sizeReg = SCS_1_HIGH_DECODE_ADDRESS; /* CS_1_SIZE; */
  185. window = CS_1_WINDOW;
  186. break;
  187. case BANK2:
  188. sizeReg = SCS_2_HIGH_DECODE_ADDRESS; /* CS_2_SIZE; */
  189. window = CS_2_WINDOW;
  190. break;
  191. case BANK3:
  192. sizeReg = SCS_3_HIGH_DECODE_ADDRESS; /* CS_3_SIZE; */
  193. window = CS_3_WINDOW;
  194. break;
  195. default:
  196. return 0;
  197. break;
  198. }
  199. /* If the window is closed, a size of 0 is returned */
  200. if (MemoryGetMemWindowStatus (window) != MEM_WINDOW_ENABLED)
  201. return 0;
  202. GT_REG_READ (sizeReg, &size);
  203. size = ((size << 16) | 0xffff) + 1;
  204. return size;
  205. }
  206. /*******************************************************************************
  207. * memoryGetDeviceSize - Returns the size of a device memory space.
  208. * DESCRIPTION:
  209. * This function returns the memory space size of a given device.
  210. * INPUT:
  211. * device - Selects one of the five devices as defined in Memory.h.
  212. * OUTPUT:
  213. * None.
  214. * RETURN:
  215. * 32 bit size of a device memory space.
  216. *******************************************************************************/
  217. unsigned int memoryGetDeviceSize (DEVICE device)
  218. {
  219. unsigned int sizeReg, size;
  220. MEMORY_WINDOW window;
  221. switch (device) {
  222. case DEVICE0:
  223. sizeReg = CS_0_HIGH_DECODE_ADDRESS; /*DEV_CS0_SIZE; */
  224. window = DEVCS_0_WINDOW;
  225. break;
  226. case DEVICE1:
  227. sizeReg = CS_1_HIGH_DECODE_ADDRESS; /*DEV_CS1_SIZE; */
  228. window = DEVCS_1_WINDOW;
  229. break;
  230. case DEVICE2:
  231. sizeReg = CS_2_HIGH_DECODE_ADDRESS; /*DEV_CS2_SIZE; */
  232. window = DEVCS_2_WINDOW;
  233. break;
  234. case DEVICE3:
  235. sizeReg = CS_3_HIGH_DECODE_ADDRESS; /*DEV_CS3_SIZE; */
  236. window = DEVCS_3_WINDOW;
  237. break;
  238. case BOOT_DEVICE:
  239. sizeReg = BOOTCS_HIGH_DECODE_ADDRESS; /*BOOTCS_SIZE; */
  240. window = BOOT_CS_WINDOW;
  241. break;
  242. default:
  243. return 0;
  244. break;
  245. }
  246. /* If the window is closed, a size of 0 is returned */
  247. if (MemoryGetMemWindowStatus (window) != MEM_WINDOW_ENABLED)
  248. return 0;
  249. GT_REG_READ (sizeReg, &size);
  250. size = ((size << 16) | 0xffff) + 1;
  251. return size;
  252. }
  253. /*******************************************************************************
  254. * MemoryGetPciWindowSize - Returns the size of a PCI memory window.
  255. * DESCRIPTION:
  256. * This function returns the size of a PCI window.
  257. * INPUT:
  258. * pciWindow - Selects one of the PCI memory windows as defined in
  259. * Memory.h.
  260. * OUTPUT:
  261. * None.
  262. * RETURN:
  263. * 32 bit size of a PCI memory window.
  264. *******************************************************************************/
  265. unsigned int MemoryGetPciWindowSize (PCI_MEM_WINDOW pciWindow)
  266. {
  267. unsigned int sizeReg, size;
  268. switch (pciWindow) {
  269. case PCI_0_IO:
  270. sizeReg = PCI_0I_O_HIGH_DECODE_ADDRESS; /*PCI_0_IO_SIZE; */
  271. break;
  272. case PCI_0_MEM0:
  273. sizeReg = PCI_0MEMORY0_HIGH_DECODE_ADDRESS; /*PCI_0_MEMORY0_SIZE; */
  274. break;
  275. case PCI_0_MEM1:
  276. sizeReg = PCI_0MEMORY1_HIGH_DECODE_ADDRESS; /*PCI_0_MEMORY1_SIZE; */
  277. break;
  278. case PCI_0_MEM2:
  279. sizeReg = PCI_0MEMORY2_HIGH_DECODE_ADDRESS; /*PCI_0_MEMORY2_SIZE; */
  280. break;
  281. case PCI_0_MEM3:
  282. sizeReg = PCI_0MEMORY3_HIGH_DECODE_ADDRESS; /*PCI_0_MEMORY3_SIZE; */
  283. break;
  284. #ifdef INCLUDE_PCI_1
  285. case PCI_1_IO:
  286. sizeReg = PCI_1I_O_HIGH_DECODE_ADDRESS; /*PCI_1_IO_SIZE; */
  287. break;
  288. case PCI_1_MEM0:
  289. sizeReg = PCI_1MEMORY0_HIGH_DECODE_ADDRESS; /*PCI_1_MEMORY0_SIZE; */
  290. break;
  291. case PCI_1_MEM1:
  292. sizeReg = PCI_1MEMORY1_HIGH_DECODE_ADDRESS; /*PCI_1_MEMORY1_SIZE; */
  293. break;
  294. case PCI_1_MEM2:
  295. sizeReg = PCI_1MEMORY2_HIGH_DECODE_ADDRESS; /*PCI_1_MEMORY2_SIZE; */
  296. break;
  297. case PCI_1_MEM3:
  298. sizeReg = PCI_1MEMORY3_HIGH_DECODE_ADDRESS; /*PCI_1_MEMORY3_SIZE; */
  299. break;
  300. #endif /* INCLUDE_PCI_1 */
  301. default:
  302. return 0x0;
  303. }
  304. /* If the memory window is disabled, retrun size = 0 */
  305. if (MemoryGetMemWindowStatus (PCI_0_IO_WINDOW << pciWindow)
  306. == MEM_WINDOW_DISABLED)
  307. return 0;
  308. GT_REG_READ (sizeReg, &size);
  309. size = ((size << 16) | 0xffff) + 1;
  310. return size;
  311. }
  312. /*******************************************************************************
  313. * memoryGetDeviceWidth - Returns the width of a given device.
  314. * DESCRIPTION:
  315. * The MV's device interface supports up to 32 Bit wide devices. A device
  316. * can have a 1, 2, 4 or 8 Bytes data width. This function returns the
  317. * width of a device as defined by the user or the operating system.
  318. * INPUT:
  319. * device - Selects one of the five devices as defined in Memory.h.
  320. * OUTPUT:
  321. * None.
  322. * RETURN:
  323. * Device width in Bytes (1,2,4 or 8), 0 if error had occurred.
  324. *******************************************************************************/
  325. unsigned int memoryGetDeviceWidth (DEVICE device)
  326. {
  327. unsigned int width;
  328. unsigned int regValue;
  329. GT_REG_READ (DEVICE_BANK0PARAMETERS + device * 4, &regValue);
  330. width = (regValue & (BIT20 | BIT21)) >> 20;
  331. return (BIT0 << width);
  332. }
  333. /*******************************************************************************
  334. * memoryMapBank - Set new base address and size for one of the memory
  335. * banks.
  336. *
  337. * DESCRIPTION:
  338. * The CPU interface address decoding map consists of 21 address windows
  339. * for the different devices (e.g. CS[3:0] ,PCI0 Mem 0/1/2/3...). Each
  340. * window can have a minimum of 1Mbytes of address space, and up to 4Gbyte
  341. * space. Each address window is defined by two registers - base and size.
  342. * The CPU address is compared with the values in the various CPU windows
  343. * until a match is found and the address is than targeted to that window.
  344. * This function sets new base and size for one the memory banks
  345. * (CS0 - CS3). It is the programmer`s responsibility to make sure that
  346. * there are no conflicts with other memory spaces. When two memory spaces
  347. * overlap, the MV’s behavior is not defined .If a bank needs to be closed,
  348. * set the ’bankLength’ parameter size to 0x0.
  349. *
  350. * INPUT:
  351. * bank - One of the memory banks (CS0-CS3) as defined in gtMemory.h.
  352. * bankBase - The memory bank base address.
  353. * bankLength - The memory bank size. This function will decrement the
  354. * 'bankLength' parameter by one and then check if the size is
  355. * valid. A valid size must be programed from LSB to MSB as
  356. * sequence of ‘1’s followed by sequence of ‘0’s.
  357. * To close a memory window simply set the size to 0.
  358. * NOTE!!!
  359. * The size must be in 64Kbyte granularity.
  360. * The base address must be aligned to the size.
  361. * OUTPUT:
  362. * None.
  363. * RETURN:
  364. * False for invalid size, true otherwise.
  365. *
  366. * CAUTION: PCI_functions must be implemented later To_do !!!!!!!!!!!!!!!!!
  367. *
  368. *******************************************************************************/
  369. bool memoryMapBank (MEMORY_BANK bank, unsigned int bankBase,
  370. unsigned int bankLength)
  371. {
  372. unsigned int newBase, newSize, baseReg, sizeReg, temp, rShift;
  373. /* PCI_INTERNAL_BAR pciBAR; */
  374. switch (bank) {
  375. case BANK0:
  376. baseReg = SCS_0_LOW_DECODE_ADDRESS; /*CS_0_BASE_ADDR; */
  377. sizeReg = SCS_0_HIGH_DECODE_ADDRESS; /*CS_0_SIZE; */
  378. /* pciBAR = PCI_CS0_BAR; */
  379. break;
  380. case BANK1:
  381. baseReg = SCS_1_LOW_DECODE_ADDRESS; /*CS_1_BASE_ADDR; */
  382. sizeReg = SCS_1_HIGH_DECODE_ADDRESS; /*CS_1_SIZE; */
  383. /* pciBAR = SCS_0_HIGH_DECODE_ADDRESS; */ /*PCI_CS1_BAR; */
  384. break;
  385. case BANK2:
  386. baseReg = SCS_2_LOW_DECODE_ADDRESS; /*CS_2_BASE_ADDR; */
  387. sizeReg = SCS_2_HIGH_DECODE_ADDRESS; /*CS_2_SIZE; */
  388. /* pciBAR = PCI_CS2_BAR;*/
  389. break;
  390. case BANK3:
  391. baseReg = SCS_3_LOW_DECODE_ADDRESS; /*CS_3_BASE_ADDR; */
  392. sizeReg = SCS_3_HIGH_DECODE_ADDRESS; /*CS_3_SIZE; */
  393. /* pciBAR = PCI_CS3_BAR; */
  394. break;
  395. default:
  396. return false;
  397. }
  398. /* If the size is 0, the window will be disabled */
  399. if (bankLength == 0) {
  400. MemoryDisableWindow (CS_0_WINDOW << bank);
  401. /* Disable the BAR from the PCI slave side */
  402. /* gtPci0DisableInternalBAR(pciBAR); */
  403. /* gtPci1DisableInternalBAR(pciBAR); */
  404. return true;
  405. }
  406. /* The base address must be aligned to the size */
  407. if ((bankBase % bankLength) != 0) {
  408. return false;
  409. }
  410. if (bankLength >= MINIMUM_MEM_BANK_SIZE) {
  411. newBase = bankBase >> 16;
  412. newSize = bankLength >> 16;
  413. /* Checking that the size is a sequence of '1' followed by a
  414. sequence of '0' starting from LSB to MSB. */
  415. temp = newSize - 1;
  416. for (rShift = 0; rShift < 16; rShift++) {
  417. temp = temp >> rShift;
  418. if ((temp & 0x1) == 0) { /* Either we got to the last '1' */
  419. /* or the size is not valid */
  420. if (temp > 0x0)
  421. return false;
  422. else
  423. break;
  424. }
  425. }
  426. #ifdef DEBUG
  427. {
  428. unsigned int oldBase, oldSize;
  429. GT_REG_READ (baseReg, &oldBase);
  430. GT_REG_READ (sizeReg + 8, &oldSize);
  431. printf ("b%d Base:%x Size:%x -> Base:%x Size:%x\n",
  432. bank, oldBase, oldSize, newBase, newSize);
  433. }
  434. #endif
  435. /* writing the new values */
  436. GT_REG_WRITE (baseReg, newBase);
  437. GT_REG_WRITE (sizeReg, newSize - 1);
  438. /* Enable back the window */
  439. MemoryEnableWindow (CS_0_WINDOW << bank);
  440. /* Enable the BAR from the PCI slave side */
  441. /* gtPci0EnableInternalBAR(pciBAR); */
  442. /* gtPci1EnableInternalBAR(pciBAR); */
  443. return true;
  444. }
  445. return false;
  446. }
  447. /*******************************************************************************
  448. * memoryMapDeviceSpace - Set new base address and size for one of the device
  449. * windows.
  450. *
  451. * DESCRIPTION:
  452. * The CPU interface address decoding map consists of 21 address windows
  453. * for the different devices (e.g. CS[3:0] ,PCI0 Mem 0/1/2/3...). Each
  454. * window can have a minimum of 1Mbytes of address space, and up to 4Gbyte
  455. * space. Each address window is defined by two registers - base and size.
  456. * The CPU address is compared with the values in the various CPU windows
  457. * until a match is found and the address is than targeted to that window.
  458. * This function sets new base and size for one the device windows
  459. * (DEV_CS0 - DEV_CS3). It is the programmer`s responsibility to make sure
  460. * that there are no conflicts with other memory spaces. When two memory
  461. * spaces overlap, the MV’s behavior is not defined .If a device window
  462. * needs to be closed, set the 'deviceLength' parameter size to 0x0.
  463. *
  464. * INPUT:
  465. * device - One of the device windows (DEV_CS0-DEV_CS3) as
  466. * defined in gtMemory.h.
  467. * deviceBase - The device window base address.
  468. * deviceLength - The device window size. This function will decrement
  469. * the 'deviceLength' parameter by one and then
  470. * check if the size is valid. A valid size must be
  471. * programed from LSB to MSB as sequence of ‘1’s
  472. * followed by sequence of ‘0’s.
  473. * To close a memory window simply set the size to 0.
  474. *
  475. * NOTE!!!
  476. * The size must be in 64Kbyte granularity.
  477. * The base address must be aligned to the size.
  478. *
  479. * OUTPUT:
  480. * None.
  481. *
  482. * RETURN:
  483. * False for invalid size, true otherwise.
  484. *
  485. * CAUTION: PCI_functions must be implemented later To_do !!!!!!!!!!!!!!!!!
  486. *
  487. *******************************************************************************/
  488. bool memoryMapDeviceSpace (DEVICE device, unsigned int deviceBase,
  489. unsigned int deviceLength)
  490. {
  491. unsigned int newBase, newSize, baseReg, sizeReg, temp, rShift;
  492. /* PCI_INTERNAL_BAR pciBAR;*/
  493. switch (device) {
  494. case DEVICE0:
  495. baseReg = CS_0_LOW_DECODE_ADDRESS; /*DEV_CS0_BASE_ADDR; */
  496. sizeReg = CS_0_HIGH_DECODE_ADDRESS; /*DEV_CS0_SIZE; */
  497. /* pciBAR = PCI_DEV_CS0_BAR; */
  498. break;
  499. case DEVICE1:
  500. baseReg = CS_1_LOW_DECODE_ADDRESS; /*DEV_CS1_BASE_ADDR; */
  501. sizeReg = CS_1_HIGH_DECODE_ADDRESS; /*DEV_CS1_SIZE; */
  502. /* pciBAR = PCI_DEV_CS1_BAR; */
  503. break;
  504. case DEVICE2:
  505. baseReg = CS_2_LOW_DECODE_ADDRESS; /*DEV_CS2_BASE_ADDR; */
  506. sizeReg = CS_2_HIGH_DECODE_ADDRESS; /*DEV_CS2_SIZE; */
  507. /* pciBAR = PCI_DEV_CS2_BAR; */
  508. break;
  509. case DEVICE3:
  510. baseReg = CS_3_LOW_DECODE_ADDRESS; /*DEV_CS3_BASE_ADDR; */
  511. sizeReg = CS_3_HIGH_DECODE_ADDRESS; /*DEV_CS3_SIZE; */
  512. /* pciBAR = PCI_DEV_CS3_BAR; */
  513. break;
  514. case BOOT_DEVICE:
  515. baseReg = BOOTCS_LOW_DECODE_ADDRESS; /*BOOTCS_BASE_ADDR; */
  516. sizeReg = BOOTCS_HIGH_DECODE_ADDRESS; /*BOOTCS_SIZE; */
  517. /* pciBAR = PCI_BOOT_CS_BAR; */
  518. break;
  519. default:
  520. return false;
  521. }
  522. if (deviceLength == 0) {
  523. MemoryDisableWindow (DEVCS_0_WINDOW << device);
  524. /* Disable the BAR from the PCI slave side */
  525. /* gtPci0DisableInternalBAR(pciBAR); */
  526. /* gtPci1DisableInternalBAR(pciBAR); */
  527. return true;
  528. }
  529. /* The base address must be aligned to the size */
  530. if ((deviceBase % deviceLength) != 0) {
  531. return false;
  532. }
  533. if (deviceLength >= MINIMUM_DEVICE_WINDOW_SIZE) {
  534. newBase = deviceBase >> 16;
  535. newSize = deviceLength >> 16;
  536. /* Checking that the size is a sequence of '1' followed by a
  537. sequence of '0' starting from LSB to MSB. */
  538. temp = newSize - 1;
  539. for (rShift = 0; rShift < 16; rShift++) {
  540. temp = temp >> rShift;
  541. if ((temp & 0x1) == 0) { /* Either we got to the last '1' */
  542. /* or the size is not valid */
  543. if (temp > 0x0)
  544. return false;
  545. else
  546. break;
  547. }
  548. }
  549. /* writing the new values */
  550. GT_REG_WRITE (baseReg, newBase);
  551. GT_REG_WRITE (sizeReg, newSize - 1);
  552. MemoryEnableWindow (DEVCS_0_WINDOW << device);
  553. /* Enable the BAR from the PCI slave side */
  554. /* gtPci0EnableInternalBAR(pciBAR); */
  555. /* gtPci1EnableInternalBAR(pciBAR); */
  556. return true;
  557. }
  558. return false;
  559. }
  560. /*******************************************************************************
  561. * MemorySetPciWindow - Set new base address and size for one of the PCI
  562. * windows.
  563. *
  564. * DESCRIPTION:
  565. * The CPU interface address decoding map consists of 21 address windows
  566. * for the different devices (e.g. CS[3:0] ,PCI0 Mem 0/1/2/3...). Each
  567. * window can have a minimum of 1Mbytes of address space, and up to 4Gbyte
  568. * space. Each address window is defined by two registers - base and size.
  569. * The CPU address is compared with the values in the various CPU windows
  570. * until a match is found and the address is than targeted to that window.
  571. * This function sets new base and size for one the PCI windows
  572. * (PCI memory0/1/2..). It is the programmer`s responsibility to make sure
  573. * that there are no conflicts with other memory spaces. When two memory
  574. * spaces overlap, the MV’s behavior is not defined .If a PCI window
  575. * needs to be closed, set the 'pciWindowSize' parameter size to 0x0.
  576. *
  577. * INPUT:
  578. * pciWindow - One of the PCI windows as defined in gtMemory.h.
  579. * pciWindowBase - The PCI window base address.
  580. * pciWindowSize - The PCI window size. This function will decrement the
  581. * 'pciWindowSize' parameter by one and then check if the
  582. * size is valid. A valid size must be programed from LSB
  583. * to MSB as sequence of ‘1’s followed by sequence of ‘0’s.
  584. * To close a memory window simply set the size to 0.
  585. *
  586. * NOTE!!!
  587. * The size must be in 64Kbyte granularity.
  588. * The base address must be aligned to the size.
  589. *
  590. * OUTPUT:
  591. * None.
  592. *
  593. * RETURN:
  594. * False for invalid size, true otherwise.
  595. *
  596. *******************************************************************************/
  597. bool memorySetPciWindow (PCI_MEM_WINDOW pciWindow, unsigned int pciWindowBase,
  598. unsigned int pciWindowSize)
  599. {
  600. unsigned int currentLow, baseAddrReg, sizeReg, temp, rShift;
  601. switch (pciWindow) {
  602. case PCI_0_IO:
  603. baseAddrReg = PCI_1I_O_LOW_DECODE_ADDRESS; /*PCI_0_IO_BASE_ADDR; */
  604. sizeReg = PCI_0I_O_HIGH_DECODE_ADDRESS; /*PCI_0_IO_SIZE; */
  605. break;
  606. case PCI_0_MEM0:
  607. baseAddrReg = PCI_0MEMORY0_LOW_DECODE_ADDRESS; /*PCI_0_MEMORY0_BASE_ADDR; */
  608. sizeReg = PCI_0MEMORY0_HIGH_DECODE_ADDRESS; /*PCI_0_MEMORY0_SIZE; */
  609. break;
  610. case PCI_0_MEM1:
  611. baseAddrReg = PCI_0MEMORY1_LOW_DECODE_ADDRESS; /*PCI_0_MEMORY1_BASE_ADDR; */
  612. sizeReg = PCI_0MEMORY1_HIGH_DECODE_ADDRESS; /*PCI_0_MEMORY1_SIZE; */
  613. break;
  614. case PCI_0_MEM2:
  615. baseAddrReg = PCI_0MEMORY2_LOW_DECODE_ADDRESS; /*PCI_0_MEMORY2_BASE_ADDR; */
  616. sizeReg = PCI_0MEMORY2_HIGH_DECODE_ADDRESS; /*PCI_0_MEMORY2_SIZE; */
  617. break;
  618. case PCI_0_MEM3:
  619. baseAddrReg = PCI_0MEMORY3_LOW_DECODE_ADDRESS; /*PCI_0_MEMORY3_BASE_ADDR; */
  620. sizeReg = PCI_0MEMORY3_HIGH_DECODE_ADDRESS; /*PCI_0_MEMORY3_SIZE; */
  621. break;
  622. #ifdef INCLUDE_PCI_1
  623. case PCI_1_IO:
  624. baseAddrReg = PCI_1I_O_LOW_DECODE_ADDRESS; /*PCI_1_IO_BASE_ADDR; */
  625. sizeReg = PCI_1I_O_HIGH_DECODE_ADDRESS; /*PCI_1_IO_SIZE; */
  626. break;
  627. case PCI_1_MEM0:
  628. baseAddrReg = PCI_1MEMORY0_LOW_DECODE_ADDRESS; /*PCI_1_MEMORY0_BASE_ADDR; */
  629. sizeReg = PCI_1MEMORY0_HIGH_DECODE_ADDRESS; /*PCI_1_MEMORY0_SIZE; */
  630. break;
  631. case PCI_1_MEM1:
  632. baseAddrReg = PCI_1MEMORY1_LOW_DECODE_ADDRESS; /*PCI_1_MEMORY1_BASE_ADDR; */
  633. sizeReg = PCI_1MEMORY1_HIGH_DECODE_ADDRESS; /*PCI_1_MEMORY1_SIZE; */
  634. break;
  635. case PCI_1_MEM2:
  636. baseAddrReg = PCI_1MEMORY2_LOW_DECODE_ADDRESS; /*PCI_1_MEMORY2_BASE_ADDR; */
  637. sizeReg = PCI_1MEMORY2_HIGH_DECODE_ADDRESS; /*PCI_1_MEMORY2_SIZE; */
  638. break;
  639. case PCI_1_MEM3:
  640. baseAddrReg = PCI_1MEMORY3_LOW_DECODE_ADDRESS; /*PCI_1_MEMORY3_BASE_ADDR; */
  641. sizeReg = PCI_1MEMORY3_HIGH_DECODE_ADDRESS; /*PCI_1_MEMORY3_SIZE; */
  642. break;
  643. #endif /* INCLUDE_PCI_1 */
  644. default:
  645. return false;
  646. }
  647. if (pciWindowSize == 0) {
  648. MemoryDisableWindow (PCI_0_IO_WINDOW << pciWindow);
  649. return true;
  650. }
  651. /* The base address must be aligned to the size */
  652. if ((pciWindowBase % pciWindowSize) != 0) {
  653. return false;
  654. }
  655. if (pciWindowSize >= MINIMUM_PCI_WINDOW_SIZE) {
  656. pciWindowBase >>= 16;
  657. pciWindowSize >>= 16;
  658. /* Checking that the size is a sequence of '1' followed by a
  659. sequence of '0' starting from LSB to MSB. */
  660. temp = pciWindowSize - 1;
  661. for (rShift = 0; rShift < 16; rShift++) {
  662. temp = temp >> rShift;
  663. if ((temp & 0x1) == 0) { /* Either we got to the last '1' */
  664. /* or the size is not valid */
  665. if (temp > 0x0)
  666. return false;
  667. else
  668. break;
  669. }
  670. }
  671. GT_REG_WRITE (sizeReg, pciWindowSize - 1);
  672. GT_REG_READ (baseAddrReg, &currentLow);
  673. pciWindowBase =
  674. (pciWindowBase & 0xfffff) | (currentLow & 0xfff00000);
  675. GT_REG_WRITE (baseAddrReg, pciWindowBase);
  676. MemoryEnableWindow (PCI_0_IO_WINDOW << pciWindow);
  677. return true;
  678. }
  679. return false;
  680. }
  681. /*******************************************************************************
  682. * memoryMapInternalRegistersSpace - Sets new base address for the internal
  683. * registers memory space.
  684. *
  685. * DESCRIPTION:
  686. * This function set new base address for the internal register’s memory
  687. * space (the size is fixed and cannot be modified). The function does not
  688. * handle overlapping with other memory spaces, it is the programer's
  689. * responsibility to ensure that overlapping does not occur.
  690. * When two memory spaces overlap, the MV’s behavior is not defined.
  691. *
  692. * INPUT:
  693. * internalRegBase - new base address for the internal register’s memory
  694. * space.
  695. *
  696. * OUTPUT:
  697. * None.
  698. *
  699. * RETURN:
  700. * true on success, false on failure
  701. *
  702. *******************************************************************************/
  703. /********************************************************************
  704. * memoryMapInternalRegistersSpace - Sets new base address for the internals
  705. * registers.
  706. *
  707. * INPUTS: unsigned int internalRegBase - The new base address.
  708. * RETURNS: true on success, false on failure
  709. *********************************************************************/
  710. bool memoryMapInternalRegistersSpace (unsigned int internalRegBase)
  711. {
  712. unsigned int currentValue;
  713. unsigned int internalValue = internalRegBase;
  714. internalRegBase = (internalRegBase >> 16);
  715. GT_REG_READ (INTERNAL_SPACE_DECODE, &currentValue);
  716. internalRegBase = (currentValue & 0xff000000) | internalRegBase;
  717. GT_REG_WRITE (INTERNAL_SPACE_DECODE, internalRegBase);
  718. /* initializing also the global variable 'internalRegBaseAddr' */
  719. /* gtInternalRegBaseAddr = internalValue; */
  720. INTERNAL_REG_BASE_ADDR = internalValue;
  721. return true;
  722. }
  723. /*******************************************************************************
  724. * memoryGetInternalRegistersSpace - Returns the internal registers Base
  725. * address.
  726. *
  727. * DESCRIPTION:
  728. * This function returns the base address of the internal register’s
  729. * memory space .
  730. *
  731. * INPUT:
  732. * None.
  733. *
  734. * OUTPUT:
  735. * None.
  736. *
  737. * RETURN:
  738. * 32 bit base address of the internal register’s memory space.
  739. *
  740. *******************************************************************************/
  741. unsigned int memoryGetInternalRegistersSpace (void)
  742. {
  743. unsigned int currentValue = 0;
  744. GT_REG_READ (INTERNAL_SPACE_DECODE, &currentValue);
  745. return ((currentValue & 0x000fffff) << 16);
  746. }
  747. /*******************************************************************************
  748. * gtMemoryGetInternalSramBaseAddr - Returns the integrated SRAM base address.
  749. *
  750. * DESCRIPTION:
  751. * The Atlantis incorporate integrated 2Mbit SRAM for general use. This
  752. * funcnion return the SRAM's base address.
  753. * INPUT:
  754. * None.
  755. * OUTPUT:
  756. * None.
  757. * RETURN:
  758. * 32 bit SRAM's base address.
  759. *
  760. *******************************************************************************/
  761. unsigned int memoryGetInternalSramBaseAddr (void)
  762. {
  763. return ((GTREGREAD (INTEGRATED_SRAM_BASE_ADDR) & 0xfffff) << 16);
  764. }
  765. /*******************************************************************************
  766. * gtMemorySetInternalSramBaseAddr - Set the integrated SRAM base address.
  767. *
  768. * DESCRIPTION:
  769. * The Atlantis incorporate integrated 2Mbit SRAM for general use. This
  770. * function sets a new base address to the SRAM .
  771. * INPUT:
  772. * sramBaseAddress - The SRAM's base address.
  773. * OUTPUT:
  774. * None.
  775. * RETURN:
  776. * None.
  777. *
  778. *******************************************************************************/
  779. void gtMemorySetInternalSramBaseAddr (unsigned int sramBaseAddress)
  780. {
  781. GT_REG_WRITE (INTEGRATED_SRAM_BASE_ADDR, sramBaseAddress >> 16);
  782. }
  783. /*******************************************************************************
  784. * memorySetProtectRegion - Set protection mode for one of the 8 regions.
  785. *
  786. * DESCRIPTION:
  787. * The CPU interface supports configurable access protection. This includes
  788. * up to eight address ranges defined to a different protection type :
  789. * whether the address range is cacheable or not, whether it is writable or
  790. * not , and whether it is accessible or not. A Low and High registers
  791. * define each window while the minimum address range of each window is
  792. * 1Mbyte. An address driven by the CPU, in addition to the address
  793. * decoding and remapping process, is compared against the eight Access
  794. * Protection Low/High registers , if an address matches one of the windows
  795. * , the MV device checks the transaction type against the protection bits
  796. * defined in CPU Access Protection register, to determine if the access is
  797. * allowed. This function set a protection mode to one of the 8 possible
  798. * regions.
  799. * NOTE:
  800. * The CPU address windows are restricted to a size of 2 power n and the
  801. * start address must be aligned to the window size. For example, if using
  802. * a 16 MB window, the start address bits [23:0] must be 0.The MV's
  803. * internal registers space is not protected, even if the access protection
  804. * windows contain this space.
  805. *
  806. * INPUT:
  807. * region - selects which region to be configured. The values defined in
  808. * gtMemory.h:
  809. *
  810. * - MEM_REGION0
  811. * - MEM_REGION1
  812. * - etc.
  813. *
  814. * memAccess - Allows or forbids access (read or write ) to the region. The
  815. * values defined in gtMemory.h:
  816. *
  817. * - MEM_ACCESS_ALLOWED
  818. * - MEM_ACCESS_FORBIDEN
  819. *
  820. * memWrite - CPU write protection to the region. The values defined in
  821. * gtMemory.h:
  822. *
  823. * - MEM_WRITE_ALLOWED
  824. * - MEM_WRITE_FORBIDEN
  825. *
  826. * cacheProtection - Defines whether caching the region is allowed or not.
  827. * The values defined in gtMemory.h:
  828. *
  829. * - MEM_CACHE_ALLOWED
  830. * - MEM_CACHE_FORBIDEN
  831. *
  832. * baseAddress - the region's base Address.
  833. * regionSize - The region's size. This function will decrement the
  834. * 'regionSize' parameter by one and then check if the size
  835. * is valid. A valid size must be programed from LSB to MSB
  836. * as sequence of ‘1’s followed by sequence of ‘0’s.
  837. * To close a memory window simply set the size to 0.
  838. *
  839. * NOTE!!!
  840. * The size must be in 64Kbyte granularity.
  841. * The base address must be aligned to the size.
  842. *
  843. * OUTPUT:
  844. * None.
  845. *
  846. * RETURN:
  847. * False for invalid size, true otherwise.
  848. *
  849. *******************************************************************************/
  850. bool memorySetProtectRegion (MEMORY_PROTECT_WINDOW window,
  851. MEMORY_ACCESS memAccess,
  852. MEMORY_ACCESS_WRITE memWrite,
  853. MEMORY_CACHE_PROTECT cacheProtection,
  854. unsigned int baseAddress, unsigned int size)
  855. {
  856. unsigned int dataForReg, temp, rShift;
  857. if (size == 0) {
  858. GT_REG_WRITE ((CPU_PROTECT_WINDOW_0_SIZE + 0x10 * window),
  859. 0x0);
  860. return true;
  861. }
  862. /* The base address must be aligned to the size. */
  863. if (baseAddress % size != 0) {
  864. return false;
  865. }
  866. if (size >= MINIMUM_ACCESS_WIN_SIZE) {
  867. baseAddress = ((baseAddress >> 16) & 0xfffff);
  868. dataForReg = baseAddress | ((memAccess << 20) & BIT20) |
  869. ((memWrite << 21) & BIT21) | ((cacheProtection << 22)
  870. & BIT22) | BIT31;
  871. GT_REG_WRITE (CPU_PROTECT_WINDOW_0_BASE_ADDR + 0x10 * window,
  872. dataForReg);
  873. size >>= 16;
  874. /* Checking that the size is a sequence of '1' followed by a
  875. sequence of '0' starting from LSB to MSB. */
  876. temp = size - 1;
  877. for (rShift = 0; rShift < 16; rShift++) {
  878. temp = temp >> rShift;
  879. if ((temp & 0x1) == 0) { /* Either we got to the last '1' */
  880. /* or the size is not valid */
  881. if (temp > 0x0)
  882. return false;
  883. else
  884. break;
  885. }
  886. }
  887. GT_REG_WRITE ((CPU_PROTECT_WINDOW_0_SIZE + 0x10 * window),
  888. size - 1);
  889. return true;
  890. }
  891. return false;
  892. }
  893. /*******************************************************************************
  894. * gtMemoryDisableProtectRegion - Disable a protected window.
  895. *
  896. * DESCRIPTION:
  897. * This function disable a protected window set by
  898. * 'gtMemorySetProtectRegion' function.
  899. *
  900. * INPUT:
  901. * window - one of the 4 windows ( defined in gtMemory.h ).
  902. *
  903. * OUTPUT:
  904. * None.
  905. *
  906. * RETURN:
  907. * None.
  908. *
  909. *******************************************************************************/
  910. void memoryDisableProtectRegion (MEMORY_PROTECT_WINDOW window)
  911. {
  912. RESET_REG_BITS (((CPU_PROTECT_WINDOW_0_BASE_ADDR) + (0x10 * window)),
  913. BIT31);
  914. }
  915. /*******************************************************************************
  916. * memorySetPciRemapValue - Set a remap value to a PCI memory space target.
  917. *
  918. * DESCRIPTION:
  919. * In addition to the address decoding mechanism, the CPU has an address
  920. * remapping mechanism to be used by every PCI decoding window. Each PCI
  921. * window can be remaped to a desired address target according to the remap
  922. * value within the remap register. The address remapping is useful when a
  923. * CPU address range must be reallocated to a different location on the
  924. * PCI bus. Also, it enables CPU access to a PCI agent located above the
  925. * 4Gbyte space. On system boot, each of the PCI memory spaces is maped to
  926. * a defualt value (see CPU interface section in the MV spec for the
  927. * default values). The remap mechanism does not always produce the desired
  928. * address on the PCI bus because of the remap mechanism way of working
  929. * (to fully understand why, please see the 'Address Remapping' section in
  930. * the MV's spec). Therefor, this function sets a desired remap value to
  931. * one of the PCI memory windows and return the effective address that
  932. * should be used when exiting the PCI memory window. You should ALWAYS use
  933. * the returned value by this function when remapping a PCI window and
  934. * exiting it. If for example the base address of PCI0 memory 0 is
  935. * 0x90000000, the size is 0x03ffffff and the remap value is 0x11000000,
  936. * the function will return the value of 0x91000000 that MUST
  937. * be used to exit this memory window in order to achive the deisred
  938. * remapping.
  939. *
  940. * INPUT:
  941. * memoryWindow - One of the PCI memory windows as defined in Memory.h
  942. * remapValueLow - The low remap value.
  943. * remapValueHigh - The high remap value.
  944. * OUTPUT:
  945. * None.
  946. *
  947. * RETURN:
  948. * The effective base address to exit the PCI, or 0xffffffff if one of the
  949. * parameters is erroneous or the effective base address is higher the top
  950. * decode value.
  951. *
  952. *******************************************************************************/
  953. unsigned int memorySetPciRemapValue (PCI_MEM_WINDOW memoryWindow,
  954. unsigned int remapValueHigh,
  955. unsigned int remapValueLow)
  956. {
  957. unsigned int pciMemWindowBaseAddrReg = 0, baseAddrValue = 0;
  958. unsigned int pciMemWindowSizeReg = 0, windowSizeValue = 0;
  959. unsigned int effectiveBaseAddress, remapRegLow, remapRegHigh;
  960. /* Initializing the base and size variables of the PCI
  961. memory windows */
  962. switch (memoryWindow) {
  963. case PCI_0_IO:
  964. pciMemWindowBaseAddrReg = PCI_0_IO_BASE_ADDR;
  965. pciMemWindowSizeReg = PCI_0_IO_SIZE;
  966. remapRegLow = PCI_0_IO_ADDR_REMAP;
  967. remapRegHigh = PCI_0_IO_ADDR_REMAP;
  968. break;
  969. case PCI_0_MEM0:
  970. pciMemWindowBaseAddrReg = PCI_0_MEMORY0_BASE_ADDR;
  971. pciMemWindowSizeReg = PCI_0_MEMORY0_SIZE;
  972. remapRegLow = PCI_0_MEMORY0_LOW_ADDR_REMAP;
  973. remapRegHigh = PCI_0_MEMORY0_HIGH_ADDR_REMAP;
  974. break;
  975. case PCI_0_MEM1:
  976. pciMemWindowBaseAddrReg = PCI_0_MEMORY1_BASE_ADDR;
  977. pciMemWindowSizeReg = PCI_0_MEMORY1_SIZE;
  978. remapRegLow = PCI_0_MEMORY1_LOW_ADDR_REMAP;
  979. remapRegHigh = PCI_0_MEMORY1_HIGH_ADDR_REMAP;
  980. break;
  981. case PCI_0_MEM2:
  982. pciMemWindowBaseAddrReg = PCI_0_MEMORY2_BASE_ADDR;
  983. pciMemWindowSizeReg = PCI_0_MEMORY2_SIZE;
  984. remapRegLow = PCI_0_MEMORY2_LOW_ADDR_REMAP;
  985. remapRegHigh = PCI_0_MEMORY2_HIGH_ADDR_REMAP;
  986. break;
  987. case PCI_0_MEM3:
  988. pciMemWindowBaseAddrReg = PCI_0_MEMORY3_BASE_ADDR;
  989. pciMemWindowSizeReg = PCI_0_MEMORY3_SIZE;
  990. remapRegLow = PCI_0_MEMORY3_LOW_ADDR_REMAP;
  991. remapRegHigh = PCI_0_MEMORY3_HIGH_ADDR_REMAP;
  992. break;
  993. #ifdef INCLUDE_PCI_1
  994. case PCI_1_IO:
  995. pciMemWindowBaseAddrReg = PCI_1_IO_BASE_ADDR;
  996. pciMemWindowSizeReg = PCI_1_IO_SIZE;
  997. remapRegLow = PCI_1_IO_ADDR_REMAP;
  998. remapRegHigh = PCI_1_IO_ADDR_REMAP;
  999. break;
  1000. case PCI_1_MEM0:
  1001. pciMemWindowBaseAddrReg = PCI_1_MEMORY0_BASE_ADDR;
  1002. pciMemWindowSizeReg = PCI_1_MEMORY0_SIZE;
  1003. remapRegLow = PCI_1_MEMORY0_LOW_ADDR_REMAP;
  1004. remapRegHigh = PCI_1_MEMORY0_HIGH_ADDR_REMAP;
  1005. break;
  1006. case PCI_1_MEM1:
  1007. pciMemWindowBaseAddrReg = PCI_1_MEMORY1_BASE_ADDR;
  1008. pciMemWindowSizeReg = PCI_1_MEMORY1_SIZE;
  1009. remapRegLow = PCI_1_MEMORY1_LOW_ADDR_REMAP;
  1010. remapRegHigh = PCI_1_MEMORY1_HIGH_ADDR_REMAP;
  1011. break;
  1012. case PCI_1_MEM2:
  1013. pciMemWindowBaseAddrReg = PCI_1_MEMORY1_BASE_ADDR;
  1014. pciMemWindowSizeReg = PCI_1_MEMORY1_SIZE;
  1015. remapRegLow = PCI_1_MEMORY1_LOW_ADDR_REMAP;
  1016. remapRegHigh = PCI_1_MEMORY1_HIGH_ADDR_REMAP;
  1017. break;
  1018. case PCI_1_MEM3:
  1019. pciMemWindowBaseAddrReg = PCI_1_MEMORY3_BASE_ADDR;
  1020. pciMemWindowSizeReg = PCI_1_MEMORY3_SIZE;
  1021. remapRegLow = PCI_1_MEMORY3_LOW_ADDR_REMAP;
  1022. remapRegHigh = PCI_1_MEMORY3_HIGH_ADDR_REMAP;
  1023. break;
  1024. #endif /* INCLUDE_PCI_1 */
  1025. default:
  1026. /* Retrun an invalid effective base address */
  1027. return 0xffffffff;
  1028. }
  1029. /* Writing the remap value to the remap regisers */
  1030. GT_REG_WRITE (remapRegHigh, remapValueHigh);
  1031. GT_REG_WRITE (remapRegLow, remapValueLow >> 16);
  1032. /* Reading the values from the base address and size registers */
  1033. baseAddrValue = GTREGREAD (pciMemWindowBaseAddrReg) & 0xfffff;
  1034. windowSizeValue = GTREGREAD (pciMemWindowSizeReg) & 0xffff;
  1035. /* Start calculating the effective Base Address */
  1036. effectiveBaseAddress = baseAddrValue << 16;
  1037. /* The effective base address will be combined from the chopped (if any)
  1038. remap value (according to the size value and remap mechanism) and the
  1039. window's base address */
  1040. effectiveBaseAddress |=
  1041. (((windowSizeValue << 16) | 0xffff) & remapValueLow);
  1042. /* If the effectiveBaseAddress exceed the window boundaries return an
  1043. invalid value. */
  1044. if (effectiveBaseAddress >
  1045. ((baseAddrValue << 16) + ((windowSizeValue << 16) | 0xffff)))
  1046. return 0xffffffff;
  1047. return effectiveBaseAddress;
  1048. }
  1049. /********************************************************************
  1050. * memorySetRegionSnoopMode - This function modifys one of the 4 regions which
  1051. * supports Cache Coherency.
  1052. *
  1053. *
  1054. * Inputs: SNOOP_REGION region - One of the four regions.
  1055. * SNOOP_TYPE snoopType - There is four optional Types:
  1056. * 1. No Snoop.
  1057. * 2. Snoop to WT region.
  1058. * 3. Snoop to WB region.
  1059. * 4. Snoop & Invalidate to WB region.
  1060. * unsigned int baseAddress - Base Address of this region.
  1061. * unsigned int topAddress - Top Address of this region.
  1062. * Returns: false if one of the parameters is wrong and true else
  1063. *********************************************************************/
  1064. /* evb6260 code */
  1065. #if 0
  1066. bool memorySetRegionSnoopMode(MEMORY_SNOOP_REGION region,
  1067. MEMORY_SNOOP_TYPE snoopType,
  1068. unsigned int baseAddress,
  1069. unsigned int regionLength)
  1070. {
  1071. unsigned int snoopXbaseAddress;
  1072. unsigned int snoopXtopAddress;
  1073. unsigned int data;
  1074. unsigned int snoopHigh = baseAddress + regionLength;
  1075. if( (region > MEM_SNOOP_REGION3) || (snoopType > MEM_SNOOP_WB) )
  1076. return false;
  1077. snoopXbaseAddress = SNOOP_BASE_ADDRESS_0 + 0x10 * region;
  1078. snoopXtopAddress = SNOOP_TOP_ADDRESS_0 + 0x10 * region;
  1079. if(regionLength == 0) /* closing the region */
  1080. {
  1081. GT_REG_WRITE(snoopXbaseAddress,0x0000ffff);
  1082. GT_REG_WRITE(snoopXtopAddress,0);
  1083. return true;
  1084. }
  1085. baseAddress = baseAddress & 0xffff0000;
  1086. data = (baseAddress >> 16) | snoopType << 16;
  1087. GT_REG_WRITE(snoopXbaseAddress,data);
  1088. snoopHigh = (snoopHigh & 0xfff00000) >> 20;
  1089. GT_REG_WRITE(snoopXtopAddress,snoopHigh - 1);
  1090. return true;
  1091. }
  1092. #endif
  1093. /********************************************************************
  1094. * memoryRemapAddress - This fubction used for address remapping.
  1095. *
  1096. *
  1097. * Inputs: regOffset: remap register
  1098. * remapValue :
  1099. * Returns: false if one of the parameters is erroneous,true otherwise.
  1100. *
  1101. * Not needed function To_do !!!!
  1102. *********************************************************************/
  1103. bool memoryRemapAddress (unsigned int remapReg, unsigned int remapValue)
  1104. {
  1105. unsigned int valueForReg;
  1106. valueForReg = (remapValue & 0xfff00000) >> 20;
  1107. GT_REG_WRITE (remapReg, valueForReg);
  1108. return true;
  1109. }
  1110. /*******************************************************************************
  1111. * memoryGetDeviceParam - Extract the device parameters from the device bank
  1112. * parameters register.
  1113. *
  1114. * DESCRIPTION:
  1115. * To allow interfacing with very slow devices and fast synchronous SRAMs,
  1116. * each device can be programed to different timing parameters. Each bank
  1117. * has its own parameters register. Bank width can be programmed to 8, 16,
  1118. * or 32-bits. Bank timing parameters can be programmed to support
  1119. * different device types (e.g. Sync Burst SRAM, Flash , ROM, I/O
  1120. * Controllers). The MV allows you to set timing parameters and width for
  1121. * each device through parameters register .
  1122. * This function extracts the parameters described from the Device Bank
  1123. * parameters register and fills the given 'deviceParam' (defined in
  1124. * gtMemory.h) structure with the read data.
  1125. *
  1126. * INPUT:
  1127. * deviceParam - pointer to a structure DEVICE_PARAM (defined in
  1128. * Memory.h).For details about each structure field please
  1129. * see the device timing parameter section in the MV
  1130. * datasheet.
  1131. * deviceNum - Select on of the five device banks (defined in
  1132. * Memory.h) :
  1133. *
  1134. * - DEVICE0
  1135. * - DEVICE1
  1136. * - DEVICE2
  1137. * - etc.
  1138. *
  1139. * OUTPUT:
  1140. * None.
  1141. *
  1142. * RETURN:
  1143. * false if one of the parameters is erroneous,true otherwise.
  1144. *
  1145. *******************************************************************************/
  1146. /********************************************************************
  1147. * memoryGetDeviceParam - This function used for getting device parameters from
  1148. * DEVICE BANK PARAMETERS REGISTER
  1149. *
  1150. *
  1151. * Inputs: - deviceParam: STRUCT with paramiters for DEVICE BANK
  1152. * PARAMETERS REGISTER
  1153. * - deviceNum : number of device
  1154. * Returns: false if one of the parameters is erroneous,true otherwise.
  1155. *********************************************************************/
  1156. bool memoryGetDeviceParam (DEVICE_PARAM * deviceParam, DEVICE deviceNum)
  1157. {
  1158. unsigned int valueOfReg;
  1159. unsigned int calcData;
  1160. if (deviceNum > 4)
  1161. return false;
  1162. GT_REG_READ (DEVICE_BANK0PARAMETERS + 4 * deviceNum, &valueOfReg);
  1163. calcData = (0x7 & valueOfReg) + ((BIT22 & valueOfReg) >> 19);
  1164. deviceParam->turnOff = calcData; /* Turn Off */
  1165. calcData = ((0x78 & valueOfReg) >> 3) + ((BIT23 & valueOfReg) >> 19);
  1166. deviceParam->acc2First = calcData; /* Access To First */
  1167. calcData = ((0x780 & valueOfReg) >> 7) + ((BIT24 & valueOfReg) >> 20);
  1168. deviceParam->acc2Next = calcData; /* Access To Next */
  1169. calcData =
  1170. ((0x3800 & valueOfReg) >> 11) + ((BIT25 & valueOfReg) >> 22);
  1171. deviceParam->ale2Wr = calcData; /* Ale To Write */
  1172. calcData = ((0x1c000 & valueOfReg) >> 14) +
  1173. ((BIT26 & valueOfReg) >> 23);
  1174. deviceParam->wrLow = calcData; /* Write Active */
  1175. calcData = ((0xe0000 & valueOfReg) >> 17) +
  1176. ((BIT27 & valueOfReg) >> 24);
  1177. deviceParam->wrHigh = calcData; /* Write High */
  1178. calcData = ((0x300000 & valueOfReg) >> 20);
  1179. deviceParam->deviceWidth = (BIT0 << calcData); /* In bytes */
  1180. calcData = ((0x30000000 & valueOfReg) >> 28);
  1181. deviceParam->badrSkew = calcData; /* Cycles gap between BAdr
  1182. toggle to read data sample. */
  1183. calcData = ((0x40000000 & valueOfReg) >> 30);
  1184. deviceParam->DPEn = calcData; /* Data Parity enable */
  1185. return true;
  1186. }
  1187. /*******************************************************************************
  1188. * memorySetDeviceParam - Set new parameters for a device.
  1189. *
  1190. *
  1191. * DESCRIPTION:
  1192. * To allow interfacing with very slow devices and fast synchronous SRAMs,
  1193. * each device can be programed to different timing parameters. Each bank
  1194. * has its own parameters register. Bank width can be programmed to 8, 16,
  1195. * or 32-bits. Bank timing parameters can be programmed to support
  1196. * different device types (e.g. Sync Burst SRAM, Flash , ROM, I/O
  1197. * Controllers). The MV allows you to set timing parameters and width for
  1198. * each device through parameters register. This function set new
  1199. * parameters to a device Bank from the delivered structure 'deviceParam'
  1200. * (defined in gtMemory.h). The structure must be initialized with data
  1201. * prior to the use of these function.
  1202. *
  1203. * INPUT:
  1204. * deviceParam - pointer to a structure DEVICE_PARAM (defined in
  1205. * Memory.h).For details about each structure field please
  1206. * see the device timing parameter section in the MV
  1207. * datasheet.
  1208. * deviceNum - Select on of the five device banks (defined in
  1209. * Memory.h) :
  1210. *
  1211. * - DEVICE0
  1212. * - DEVICE1
  1213. * - DEVICE2
  1214. * - etc.
  1215. *
  1216. * OUTPUT:
  1217. * None.
  1218. *
  1219. * RETURN:
  1220. * false if one of the parameters is erroneous,true otherwise.
  1221. *
  1222. *******************************************************************************/
  1223. /********************************************************************
  1224. * memorySetDeviceParam - This function used for setting device parameters to
  1225. * DEVICE BANK PARAMETERS REGISTER
  1226. *
  1227. *
  1228. * Inputs: - deviceParam: STRUCT for store paramiters from DEVICE BANK
  1229. * PARAMETERS REGISTER
  1230. * - deviceNum : number of device
  1231. * Returns: false if one of the parameters is erroneous,true otherwise.
  1232. *********************************************************************/
  1233. bool memorySetDeviceParam (DEVICE_PARAM * deviceParam, DEVICE deviceNum)
  1234. {
  1235. unsigned int valueForReg;
  1236. if ((deviceParam->turnOff > 0x7) || (deviceParam->acc2First > 0xf) ||
  1237. (deviceParam->acc2Next > 0xf) || (deviceParam->ale2Wr > 0x7) ||
  1238. (deviceParam->wrLow > 0x7) || (deviceParam->wrHigh > 0x7) ||
  1239. (deviceParam->badrSkew > 0x2) || (deviceParam->DPEn > 0x1)) {
  1240. return false;
  1241. }
  1242. valueForReg = (((deviceParam->turnOff) & 0x7) |
  1243. (((deviceParam->turnOff) & 0x8) << 19) |
  1244. (((deviceParam->acc2First) & 0xf) << 3) |
  1245. (((deviceParam->acc2First) & 0x10) << 19) |
  1246. (((deviceParam->acc2Next) & 0xf) << 7) |
  1247. (((deviceParam->acc2Next) & 0x10) << 20) |
  1248. (((deviceParam->ale2Wr) & 0x7) << 11) |
  1249. (((deviceParam->ale2Wr) & 0xf) << 22) |
  1250. (((deviceParam->wrLow) & 0x7) << 14) |
  1251. (((deviceParam->wrLow) & 0xf) << 23) |
  1252. (((deviceParam->wrHigh) & 0x7) << 17) |
  1253. (((deviceParam->wrHigh) & 0xf) << 24) |
  1254. (((deviceParam->badrSkew) & 0x3) << 28) |
  1255. (((deviceParam->DPEn) & 0x1) << 30));
  1256. /* insert the device width: */
  1257. switch (deviceParam->deviceWidth) {
  1258. case 1:
  1259. valueForReg = valueForReg | _8BIT;
  1260. break;
  1261. case 2:
  1262. valueForReg = valueForReg | _16BIT;
  1263. break;
  1264. case 4:
  1265. valueForReg = valueForReg | _32BIT;
  1266. break;
  1267. default:
  1268. valueForReg = valueForReg | _8BIT;
  1269. break;
  1270. }
  1271. GT_REG_WRITE (DEVICE_BANK0PARAMETERS + 4 * deviceNum, valueForReg);
  1272. return true;
  1273. }
  1274. /*******************************************************************************
  1275. * MemoryDisableWindow - Disable a memory space by the disable bit.
  1276. * DESCRIPTION:
  1277. * This function disables one of the 21 availiable windows dedicated for
  1278. * the CPU decoding mechanism. Its possible to combine several windows with
  1279. * the OR command.
  1280. * INPUT:
  1281. * window - One or more of the memory windows (defined in gtMemory.h).
  1282. * OUTPUT:
  1283. * None.
  1284. * RETURN:
  1285. * None.
  1286. *******************************************************************************/
  1287. void MemoryDisableWindow (MEMORY_WINDOW window)
  1288. {
  1289. SET_REG_BITS (BASE_ADDR_ENABLE, window);
  1290. }
  1291. /*******************************************************************************
  1292. * MemoryEnableWindow - Enable a memory space that was disabled by
  1293. * 'MemoryDisableWindow'.
  1294. * DESCRIPTION:
  1295. * This function enables one of the 21 availiable windows dedicated for the
  1296. * CPU decoding mechanism. Its possible to combine several windows with the
  1297. * OR command.
  1298. * INPUT:
  1299. * window - One or more of the memory windows (defined in gtMemory.h).
  1300. * OUTPUT:
  1301. * None.
  1302. * RETURN:
  1303. * None.
  1304. *******************************************************************************/
  1305. void MemoryEnableWindow (MEMORY_WINDOW window)
  1306. {
  1307. RESET_REG_BITS (BASE_ADDR_ENABLE, window);
  1308. }
  1309. /*******************************************************************************
  1310. * MemoryGetMemWindowStatus - This function check whether the memory window is
  1311. * disabled or not.
  1312. * DESCRIPTION:
  1313. * This function checks if the given memory window is closed .
  1314. * INPUT:
  1315. * window - One or more of the memory windows (defined in gtMemory.h).
  1316. * OUTPUT:
  1317. * None.
  1318. * RETURN:
  1319. * True for a closed window, false otherwise .
  1320. *******************************************************************************/
  1321. MEMORY_WINDOW_STATUS MemoryGetMemWindowStatus (MEMORY_WINDOW window)
  1322. {
  1323. if (GTREGREAD (BASE_ADDR_ENABLE) & window)
  1324. return MEM_WINDOW_DISABLED;
  1325. return MEM_WINDOW_ENABLED;
  1326. }