ia64/xen-unstable

view tools/firmware/hvmloader/tests.c @ 19709:011948e1b5a7

hvmloader: Scan for gpxe-capable NICs until one is found.

Signed-off-by: Akio Takebe <takebe_akio@jp.fujitsu.com>
Signed-off-by: Keir Fraser <keir.fraser@citrix.com>
author Keir Fraser <keir.fraser@citrix.com>
date Wed Jun 03 16:12:34 2009 +0100 (2009-06-03)
parents 2ec019301ad8
children
line source
1 /*
2 * tests.c: HVM environment tests.
3 *
4 * Copyright (c) 2008, Citrix Systems, Inc.
5 *
6 * Authors:
7 * Keir Fraser <keir.fraser@citrix.com>
8 *
9 * This program is free software; you can redistribute it and/or modify it
10 * under the terms and conditions of the GNU General Public License,
11 * version 2, as published by the Free Software Foundation.
12 *
13 * This program is distributed in the hope it will be useful, but WITHOUT
14 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
15 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
16 * more details.
17 *
18 * You should have received a copy of the GNU General Public License along with
19 * this program; if not, write to the Free Software Foundation, Inc., 59 Temple
20 * Place - Suite 330, Boston, MA 02111-1307 USA.
21 */
23 #include "util.h"
25 /*
26 * Memory layout during tests:
27 * 4MB to 8MB is cleared.
28 * Page directory resides at 8MB.
29 * 4 page table pages reside at 8MB+4kB to 8MB+20kB.
30 * Pagetables identity-map 0-16MB, except 4kB at va 6MB maps to pa 5MB.
31 */
32 #define PD_START (8ul << 20)
33 #define PT_START (PD_START + 4096)
35 static void setup_paging(void)
36 {
37 uint32_t *pd = (uint32_t *)PD_START;
38 uint32_t *pt = (uint32_t *)PT_START;
39 uint32_t i;
41 /* Identity map 0-16MB. */
42 for ( i = 0; i < 4; i++ )
43 pd[i] = (unsigned long)pt + (i<<12) + 3;
44 for ( i = 0; i < (4*1024); i++ )
45 pt[i] = (i << 12) + 3;
47 /* Page at virtual 6MB maps to physical 5MB. */
48 pt[6u<<8] -= 0x100000u;
49 }
51 static void start_paging(void)
52 {
53 asm volatile (
54 "mov %%eax,%%cr3; mov %%cr0,%%eax; "
55 "orl $0x80000000,%%eax; mov %%eax,%%cr0; "
56 "jmp 1f; 1:"
57 : : "a" (PD_START) : "memory" );
58 }
60 static void stop_paging(void)
61 {
62 asm volatile (
63 "mov %%cr0,%%eax; andl $0x7fffffff,%%eax; mov %%eax,%%cr0; "
64 "jmp 1f; 1:"
65 : : : "eax", "memory" );
66 }
68 /*
69 * rep_io_test: Tests REP INSB both forwards and backwards (EF.DF={0,1}) across
70 * a discontiguous page boundary.
71 */
72 static int rep_io_test(void)
73 {
74 uint32_t *p;
75 uint32_t i, p0, p1, p2;
76 int okay = 1;
78 static const struct {
79 unsigned long addr;
80 uint32_t expected;
81 } check[] = {
82 { 0x00500000, 0x987654ff },
83 { 0x00500ffc, 0xff000000 },
84 { 0x005ffffc, 0xff000000 },
85 { 0x00601000, 0x000000ff },
86 { 0, 0 }
87 };
89 start_paging();
91 /* Phys 5MB = 0xdeadbeef */
92 *(uint32_t *)0x500000ul = 0xdeadbeef;
94 /* Phys 5MB = 0x98765432 */
95 *(uint32_t *)0x600000ul = 0x98765432;
97 /* Phys 0x5fffff = Phys 0x500000 = 0xff (byte) */
98 asm volatile (
99 "rep insb"
100 : "=d" (p0), "=c" (p1), "=D" (p2)
101 : "0" (0x5f), "1" (2), "2" (0x5ffffful) : "memory" );
103 /* Phys 0x500fff = Phys 0x601000 = 0xff (byte) */
104 asm volatile (
105 "std ; rep insb ; cld"
106 : "=d" (p0), "=c" (p1), "=D" (p2)
107 : "0" (0x5f), "1" (2), "2" (0x601000ul) : "memory" );
109 stop_paging();
111 i = 0;
112 for ( p = (uint32_t *)0x400000ul; p < (uint32_t *)0x700000ul; p++ )
113 {
114 uint32_t expected = 0;
115 if ( check[i].addr == (unsigned long)p )
116 {
117 expected = check[i].expected;
118 i++;
119 }
120 if ( *p != expected )
121 {
122 printf("Bad value at 0x%08lx: saw %08x expected %08x\n",
123 (unsigned long)p, *p, expected);
124 okay = 0;
125 }
126 }
128 return okay;
129 }
131 void perform_tests(void)
132 {
133 int i, passed;
135 static struct {
136 int (* const test)(void);
137 const char *description;
138 } tests[] = {
139 { rep_io_test, "REP INSB across page boundaries" },
140 { NULL, NULL }
141 };
143 printf("Testing HVM environment:\n");
145 passed = 0;
146 for ( i = 0; tests[i].test; i++ )
147 {
148 printf(" - %s ... ", tests[i].description);
149 memset((char *)(4ul << 20), 0, 4ul << 20);
150 setup_paging();
151 if ( (*tests[i].test)() )
152 {
153 printf("passed\n");
154 passed++;
155 }
156 else
157 {
158 printf("failed\n");
159 }
160 }
162 printf("Passed %d/%d tests\n", passed, i);
163 BUG_ON(passed != i);
164 }