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