Home | History | Annotate | Line # | Download | only in pbsdboot
disptest.c revision 1.2
      1 /*	$NetBSD: disptest.c,v 1.2 1999/09/26 02:42:50 takemura Exp $	*/
      2 
      3 /*-
      4  * Copyright (c) 1999 Shin Takemura.
      5  * All rights reserved.
      6  *
      7  * This software is part of the PocketBSD.
      8  *
      9  * Redistribution and use in source and binary forms, with or without
     10  * modification, are permitted provided that the following conditions
     11  * are met:
     12  * 1. Redistributions of source code must retain the above copyright
     13  *    notice, this list of conditions and the following disclaimer.
     14  * 2. Redistributions in binary form must reproduce the above copyright
     15  *    notice, this list of conditions and the following disclaimer in the
     16  *    documentation and/or other materials provided with the distribution.
     17  * 3. All advertising materials mentioning features or use of this software
     18  *    must display the following acknowledgement:
     19  *	This product includes software developed by the PocketBSD project
     20  *	and its contributors.
     21  * 4. Neither the name of the project nor the names of its contributors
     22  *    may be used to endorse or promote products derived from this software
     23  *    without specific prior written permission.
     24  *
     25  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
     26  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     27  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     28  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
     29  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     30  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     31  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     32  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     33  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     34  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     35  * SUCH DAMAGE.
     36  *
     37  */
     38 #include <pbsdboot.h>
     39 
     40 #define ARRAYSIZEOF(a)	(sizeof(a)/sizeof(*(a)))
     41 
     42 static struct area {
     43   long start, end;
     44 } targets[] = {
     45 	{ 0x0a000000, 0x0b000000 },
     46 	{ 0x10000000, 0x14000000 },
     47 };
     48 int ntargets = ARRAYSIZEOF(targets);
     49 
     50 void
     51 flush_XX()
     52 {
     53   static volatile unsigned char tmp[1024*64];
     54   int i, s;
     55 
     56   for (i = 0; i < ARRAYSIZEOF(tmp); i++) {
     57 	  s += tmp[i];
     58   }
     59 }
     60 
     61 static void
     62 gpio_test()
     63 {
     64 #define GIUBASE 0xab000000
     65 #define GIUOFFSET 0x0100
     66 	volatile unsigned short *giusell;
     67 	volatile unsigned short *giuselh;
     68 	volatile unsigned short *giupiodl;
     69 	volatile unsigned short *giupiodh;
     70 	unsigned short sell = 0;
     71 	unsigned short selh = 0;
     72 	unsigned short piodl = 0;
     73 	unsigned short piodh = 0;
     74 	int res, i;
     75 	unsigned short regs[16];
     76 	unsigned short prev_regs[16];
     77 
     78 	unsigned char* p = (char*)VirtualAlloc(0, 1024, MEM_RESERVE,
     79 				      PAGE_NOACCESS);
     80 	res = VirtualCopy((LPVOID)p, (LPVOID)(GIUBASE >> 8), 1024,
     81 			  PAGE_READWRITE|PAGE_NOCACHE|PAGE_PHYSICAL);
     82 	if (!res) {
     83 		win_printf(TEXT("VirtualCopy() failed."));
     84 	}
     85 
     86 	for (i = 0; i < 16; i++) {
     87 		prev_regs[i] = ~0;
     88 	}
     89 
     90 	giusell = (unsigned short*)(p + GIUOFFSET + 0);
     91 	giuselh = (unsigned short*)(p + GIUOFFSET + 2);
     92 	giupiodl = (unsigned short*)(p + GIUOFFSET + 4);
     93 	giupiodh = (unsigned short*)(p + GIUOFFSET + 6);
     94 
     95 	while (1) {
     96 		sell = *giusell;
     97 		selh = *giuselh;
     98 		*giusell = sell;
     99 		*giuselh = selh;
    100 
    101 		piodl = *giupiodl;
    102 		piodh = *giupiodh;
    103 		*giupiodl = piodl;
    104 		*giupiodh = piodh;
    105 		for (i = 0; i < 16; i++) {
    106 			regs[i] = *(unsigned short*)(p + GIUOFFSET + i * 2);
    107 		}
    108 		for (i = 0; i < 16; i++) {
    109 			if (i != 3 && i != 5 && regs[i] != prev_regs[i]) {
    110 				win_printf(TEXT("IOSEL=%04x%04x "),
    111 					   regs[1], regs[0]);
    112 				win_printf(TEXT("PIOD=%04x%04x "),
    113 					   regs[3], regs[2]);
    114 				win_printf(TEXT("STAT=%04x%04x "),
    115 					   regs[5], regs[4]);
    116 				win_printf(TEXT("(%04x%04x) "),
    117 					   regs[5]&regs[7], regs[4]&regs[6]);
    118 				win_printf(TEXT("EN=%04x%04x "),
    119 					   regs[7], regs[6]);
    120 				win_printf(TEXT("TYP=%04x%04x "),
    121 					   regs[9], regs[8]);
    122 				win_printf(TEXT("ALSEL=%04x%04x "),
    123 					   regs[11], regs[10]);
    124 				win_printf(TEXT("HTSEL=%04x%04x "),
    125 					   regs[13], regs[12]);
    126 				win_printf(TEXT("PODAT=%04x%04x "),
    127 					   regs[15], regs[14]);
    128 				win_printf(TEXT("\n"));
    129 				for (i = 0; i < 16; i++) {
    130 					prev_regs[i] = regs[i];
    131 				}
    132 				break;
    133 			}
    134 		}
    135 	}
    136 }
    137 
    138 static void
    139 serial_test()
    140 {
    141 #if 1
    142 #  define SIUADDR 0xac000000
    143 #  define REGOFFSET 0x0
    144 #else
    145 #  define SIUADDR 0xab000000
    146 #  define REGOFFSET 0x1a0
    147 #endif
    148 #define REGSIZE 32
    149 	int i, changed, res;
    150 	unsigned char regs[REGSIZE], prev_regs[REGSIZE];
    151 	unsigned char* p = (char*)VirtualAlloc(0, 1024, MEM_RESERVE,
    152 				      PAGE_NOACCESS);
    153 
    154 	for (i = 0; i < ARRAYSIZEOF(prev_regs); i++) {
    155 		prev_regs[i] = ~0;
    156 	}
    157 
    158 	res = VirtualCopy((LPVOID)p, (LPVOID)(SIUADDR >> 8), 1024,
    159 			  PAGE_READWRITE|PAGE_NOCACHE|PAGE_PHYSICAL);
    160 	if (!res) {
    161 		win_printf(TEXT("VirtualCopy() failed."));
    162 	}
    163 
    164 	while (1) {
    165 		flush_XX();
    166 
    167 		for (i = 0; i < ARRAYSIZEOF(regs); i++) {
    168 			regs[i] = p[REGOFFSET + i];
    169 		}
    170 
    171 		changed = 0;
    172 		for (i = 0; i < ARRAYSIZEOF(regs); i++) {
    173 			if (regs[i] != prev_regs[i]) {
    174 				changed++;
    175 			}
    176 			prev_regs[i] = regs[i];
    177 		}
    178 		if (changed) {
    179 			win_printf(TEXT("SIU regs: "));
    180 			for (i = 0; i < ARRAYSIZEOF(regs); i++) {
    181 				win_printf(TEXT("%02x "), regs[i]);
    182 			}
    183 			win_printf(TEXT("\n"));
    184 		}
    185 	}
    186 
    187 	VirtualFree(p, 0, MEM_RELEASE);
    188 }
    189 
    190 static long
    191 checksum(char* addr, int size)
    192 {
    193 	long sum = 0;
    194 	int i;
    195 
    196 	for (i = 0; i < size; i++) {
    197 		sum += *addr++ * i;
    198 	}
    199 	return (sum);
    200 }
    201 
    202 static int
    203 examine(char* addr, int size)
    204 {
    205 	long random_data[256];
    206 	long dijest;
    207 	int i;
    208 
    209 	for (i = 0; i < ARRAYSIZEOF(random_data); i++) {
    210 		random_data[i] = Random();
    211 	}
    212 	if (sizeof(random_data) < size) {
    213 		size = sizeof(random_data);
    214 	}
    215 	memcpy(addr, (char*)random_data, size);
    216 	dijest= checksum((char*)random_data, size);
    217 
    218 	return (dijest == checksum(addr, size));
    219 }
    220 
    221 void
    222 display_search()
    223 {
    224 	int step = 0x10000;
    225 	int i;
    226 	long addr;
    227 
    228 	for (i = 0; i < ntargets; i++) {
    229 		int prevres = -1;
    230 		for (addr = targets[i].start;
    231 		     addr < targets[i].end;
    232 		     addr += step) {
    233 			int res;
    234 			char* p = (char*)VirtualAlloc(0, step, MEM_RESERVE,
    235 						      PAGE_NOACCESS);
    236 			res = VirtualCopy((LPVOID)p, (LPVOID)(addr >> 8), step,
    237 				   PAGE_READWRITE|PAGE_NOCACHE|PAGE_PHYSICAL);
    238 			if (!res) {
    239 				win_printf(TEXT("VirtualCopy() failed."));
    240 			}
    241 			res = examine(p, step);
    242 			VirtualFree(p, 0, MEM_RELEASE);
    243 			if (res != prevres && prevres != -1) {
    244 				if (res) {
    245 					win_printf(TEXT("0x%x "), addr);
    246 				} else {
    247 					win_printf(TEXT("- 0x%x\n"), addr);
    248 				}
    249 			} else
    250 			if (res && prevres == -1) {
    251 				win_printf(TEXT("0x%x "), addr);
    252 			}
    253 			prevres = res;
    254 		}
    255 		if (prevres) {
    256 			win_printf(TEXT("\n"));
    257 		}
    258 	}
    259 }
    260 
    261 void
    262 display_draw()
    263 {
    264 	long addr = 0x13000000;
    265 	int size = 0x40000;
    266 	char* p;
    267 	int i, j, res;
    268 	int x, y;
    269 
    270 	p = (char*)VirtualAlloc(0, size, MEM_RESERVE,
    271 				PAGE_NOACCESS);
    272 	res = VirtualCopy((LPVOID)p, (LPVOID)(addr >> 8), size,
    273 			  PAGE_READWRITE|PAGE_NOCACHE|PAGE_PHYSICAL);
    274 	if (!res) {
    275 		win_printf(TEXT("VirtualCopy() failed."));
    276 	}
    277 
    278 	for (i = 0; i < 10000; i++) {
    279 		p[i] = i;
    280 	}
    281 	for (x = 0; x < 640; x += 10) {
    282 		for (y = 0; y < 240; y += 1) {
    283 		        p[1024 * y + x] = (char)0xff;
    284 		}
    285 	}
    286 	for (y = 0; y < 240; y += 10) {
    287 		for (x = 0; x < 640; x += 1) {
    288 		        p[1024 * y + x] = (char)0xff;
    289 		}
    290 	}
    291 	for (i = 0; i < 16; i++) {
    292 		for (j = 0; j < 16; j++) {
    293 			for (x = i * 32; x < i * 32 + 32; x++) {
    294 				for (y = j * 15; y < j * 15 + 15; y++) {
    295 					p[1024 * y + x] = j * 16 + i;
    296 				}
    297 			}
    298 		}
    299 	}
    300 
    301 	VirtualFree(p, 0, MEM_RELEASE);
    302 }
    303 
    304 #define PCIC_IDENT		0x00
    305 #define	PCIC_REG_INDEX		0
    306 #define	PCIC_REG_DATA		1
    307 #define PCIC_IDENT_EXPECTED	0x83
    308 
    309 void
    310 pcic_search()
    311 {
    312 	long addr;
    313 	int window_size = 0x10000;
    314 	int i;
    315 
    316 	for (addr = 0x14000000; addr < 0x18000000; addr += window_size) {
    317 		int res;
    318 		unsigned char* p;
    319 		p = (char*)VirtualAlloc(0, window_size, MEM_RESERVE,
    320 					PAGE_NOACCESS);
    321 		res = VirtualCopy((LPVOID)p, (LPVOID)(addr >> 8), window_size,
    322 				  PAGE_READWRITE|PAGE_NOCACHE|PAGE_PHYSICAL);
    323 		if (!res) {
    324 			win_printf(TEXT("VirtualCopy() failed."));
    325 		}
    326 
    327 		for (i = 0; i < window_size; i += 2) {
    328 			p[i + PCIC_REG_INDEX] = PCIC_IDENT;
    329 			if (p[i + PCIC_REG_DATA] == PCIC_IDENT_EXPECTED) {
    330 				win_printf(TEXT("pcic is found at 0x%x\n"),
    331 					   addr + i);
    332 			}
    333 		}
    334 
    335 		VirtualFree(p, 0, MEM_RELEASE);
    336 	}
    337 }
    338 
    339 void
    340 hardware_test()
    341 {
    342 	int do_gpio_test = 0;
    343 	int do_serial_test = 0;
    344 	int do_display_draw = 0;
    345 	int do_display_search = 0;
    346 	int do_pcic_search = 0;
    347 
    348 	if (do_gpio_test) {
    349 		gpio_test();
    350 	}
    351 	if (do_serial_test) {
    352 		serial_test();
    353 	}
    354 	if (do_display_draw) {
    355 		display_draw();
    356 	}
    357 	if (do_display_search) {
    358 		display_search();
    359 	}
    360 	if (do_pcic_search) {
    361 		pcic_search();
    362 	}
    363 }
    364