2 * This file is part of the coreboot project.
4 * Copyright (C) 2009 One Laptop per Child, Association, Inc.
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; version 2 of the License.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
20 void WaitMicroSec(UINTN MicroSeconds)
24 for (i = 0; i < 1024 * MicroSeconds; i++) {
25 __asm__ volatile ("nop\n\t");
31 /*===================================================================
32 Function : via_write_phys()
39 ===================================================================*/
41 void via_write_phys(volatile u32 addr, volatile u32 value)
44 ptr = (volatile u32 *)addr;
45 *ptr = (volatile u32)value;
48 /*===================================================================
49 Function : via_read_phys()
55 ===================================================================*/
57 u32 via_read_phys(volatile u32 addr)
60 y = *(volatile u32 *)addr;
64 /*===================================================================
71 ===================================================================*/
73 u32 DimmRead(volatile u32 x)
76 y = *(volatile u32 *)x;
81 /*===================================================================
82 Function : DramBaseTest()
83 Precondition : this function used to verify memory
89 Purpose :write into and read out to verify if dram is correct
91 ===================================================================*/
92 BOOLEAN DramBaseTest(u32 BaseAdd, u32 Length,
93 DRAM_TEST_MODE Mode, BOOLEAN PrintFlag)
96 u32 Data, Address, Address2;
99 //decide the test mode is continous or step
100 if (Mode == EXTENSIVE) {
101 //the test mode is continuos and must test each unit
104 } else if (Mode == SPARE) {
105 // the test mode is step and test some unit
107 TestCount = TESTCOUNT;
109 PRINT_DEBUG_MEM("the test mode is error\r");
113 //write each test unit the value with TEST_PATTERN
114 for (Address = BaseAdd; Address < BaseAdd + Length; Address += TestSpan) {
115 for (i = 0; i < TestCount; i++)
116 via_write_phys(Address + i * 4, TEST_PATTERN);
118 if ((u32) Address % 0x10000000 == 0) {
119 PRINT_DEBUG_MEM("Write in Addr =");
120 PRINT_DEBUG_MEM_HEX32(Address);
121 PRINT_DEBUG_MEM("\r");
126 //compare each test unit with the value of TEST_PATTERN
127 //and write it with compliment of TEST_PATTERN
128 for (Address = BaseAdd; Address < BaseAdd + Length; Address += TestSpan) {
129 for (i = 0; i < TestCount; i++) {
130 Data = via_read_phys(Address + i * 4);
131 via_write_phys(Address + i * 4, (u32) (~TEST_PATTERN));
132 if (Data != TEST_PATTERN) {
133 PRINT_DEBUG_MEM("TEST_PATTERN ERROR !!!!! ");
134 Address2 = Address + i * 4;
135 PRINT_DEBUG_MEM_HEX32(Address2);
136 PRINT_DEBUG_MEM(" : ");
137 PRINT_DEBUG_MEM_HEX32(Data);
138 PRINT_DEBUG_MEM(" \r");
143 if ((u32) Address % 0x10000000 == 0) {
144 PRINT_DEBUG_MEM("Write in Addr =");
145 PRINT_DEBUG_MEM_HEX32(Address);
146 PRINT_DEBUG_MEM("\r");
151 //compare each test unit with the value of ~TEST_PATTERN
152 for (Address = BaseAdd; Address < BaseAdd + Length; Address += TestSpan) {
153 for (i = (u8) (TestCount); i > 0; i--) {
154 Data = via_read_phys(Address + (i - 1) * 4);
155 if (Data != ~TEST_PATTERN) {
157 PRINT_DEBUG_MEM("~TEST_PATTERN ERROR !!!!! ");
158 Address2 = Address + (i - 1) * 4;
159 PRINT_DEBUG_MEM_HEX32(Address2);
160 PRINT_DEBUG_MEM(" : ");
161 PRINT_DEBUG_MEM_HEX32(Data);
162 PRINT_DEBUG_MEM(" \r");
171 /*===================================================================
172 Function : DumpRegisters()
181 ===================================================================*/
183 void DumpRegisters(INTN DevNum, INTN FuncNum)
189 //pci_write_config8(PCI_DEV(0, DevNum, FuncNum), 0xA1, ByteVal);
190 PRINT_DEBUG_MEM("\rDev %02x Fun %02x\r");
192 ("\r 00 01 02 03 04 05 06 07 08 09 0a 0b 0c 0d 0e 0f\r");
194 ("---------------------------------------------------\r");
195 for (i = 0; i < 0x10; i++) {
196 PRINT_DEBUG_MEM_HEX32(i);
197 for (j = 0; j < 0x10; j++) {
199 pci_read_config8(PCI_DEV(0, DevNum, FuncNum),
201 PRINT_DEBUG_MEM_HEX8(ByteVal);
202 PRINT_DEBUG_MEM(" ");
205 PRINT_DEBUG_MEM("\r");
210 /*===================================================================
211 Function : dumpnorth()
219 ===================================================================*/
221 void dumpnorth(u8 Func)
225 PRINT_DEBUG_MEM("Dump North!!!\r");
226 for (r = 0; r < 32; r++) {
227 for (c = (u16) (r << 3); c < (r << 3) + 8; c++) {
229 ByteVal = pci_read_config8(PCI_DEV(0, 0, Func), c);
230 PRINT_DEBUG_MEM_HEX16(c);
231 PRINT_DEBUG_MEM("= ");
232 PRINT_DEBUG_MEM_HEX8(ByteVal);
234 PRINT_DEBUG_MEM("\r");