memory.c 49 KB

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