OpenCores
URL https://opencores.org/ocsvn/openrisc/openrisc/trunk

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [rtos/] [ecos-3.0/] [packages/] [hal/] [arm/] [sa11x0/] [var/] [current/] [tests/] [mmap_test.c] - Blame information for rev 786

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 786 skrzyp
//==========================================================================
2
//
3
//        mmap_test.c
4
//
5
//        Memory mapping test for ARM SA11x0 platforms
6
//
7
//==========================================================================
8
// ####ECOSGPLCOPYRIGHTBEGIN####                                            
9
// -------------------------------------------                              
10
// This file is part of eCos, the Embedded Configurable Operating System.   
11
// Copyright (C) 1998, 1999, 2000, 2001, 2002 Free Software Foundation, Inc.
12
//
13
// eCos is free software; you can redistribute it and/or modify it under    
14
// the terms of the GNU General Public License as published by the Free     
15
// Software Foundation; either version 2 or (at your option) any later      
16
// version.                                                                 
17
//
18
// eCos is distributed in the hope that it will be useful, but WITHOUT      
19
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or    
20
// FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License    
21
// for more details.                                                        
22
//
23
// You should have received a copy of the GNU General Public License        
24
// along with eCos; if not, write to the Free Software Foundation, Inc.,    
25
// 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.            
26
//
27
// As a special exception, if other files instantiate templates or use      
28
// macros or inline functions from this file, or you compile this file      
29
// and link it with other works to produce a work based on this file,       
30
// this file does not by itself cause the resulting work to be covered by   
31
// the GNU General Public License. However the source code for this file    
32
// must still be made available in accordance with section (3) of the GNU   
33
// General Public License v2.                                               
34
//
35
// This exception does not invalidate any other reasons why a work based    
36
// on this file might be covered by the GNU General Public License.         
37
// -------------------------------------------                              
38
// ####ECOSGPLCOPYRIGHTEND####                                              
39
//==========================================================================
40
//#####DESCRIPTIONBEGIN####
41
//
42
// Author(s):     hmt
43
// Contributors:  hmt
44
// Date:          2000-01-04
45
// Description:   Basic test of MMAP macros and functions
46
//                
47
//####DESCRIPTIONEND####
48
 
49
#include <pkgconf/system.h>
50
 
51
#include <cyg/infra/testcase.h>
52
 
53
#include <cyg/hal/hal_intr.h>
54
#include <cyg/hal/hal_cache.h>
55
 
56
extern int diag_printf( char *, ... );
57
 
58
static int staticmem = 0;
59
 
60
static void somefunc( void )
61
{
62
    staticmem++;
63
}
64
 
65
static int vpcount = 0, uncachedcount = 0, loopcount = 0;
66
 
67
externC void
68
#ifdef CYGPKG_KERNEL
69
cyg_user_start( void )
70
#else
71
cyg_start( void )
72
#endif
73
{
74
    int stackmem = 127;
75
 
76
    unsigned int p1, p2, v1, v2;
77
 
78
    CYG_TEST_INIT();
79
    CYG_TEST_INFO( "Starting MMap test" );
80
 
81
    // First check the pagesize macro for various objects.
82
    p1 = 0;
83
    HAL_MM_PAGESIZE( &stackmem, p1 );
84
    CYG_TEST_CHECK( SZ_1M == p1, "Pagesize bad for stackmem" );
85
 
86
    p1 = 1;
87
    HAL_MM_PAGESIZE( &staticmem, p1 );
88
    CYG_TEST_CHECK( SZ_1M == p1, "Pagesize bad for staticmem" );
89
 
90
    p1 = 2;
91
    HAL_MM_PAGESIZE( &somefunc, p1 );
92
    CYG_TEST_CHECK( SZ_1M == p1, "Pagesize bad for somefunc" );
93
 
94
    CYG_TEST_PASS( "Pagesize macro OK" );
95
 
96
    // Test the macros with directly quoted "&thing" input args,
97
    // with things being static, on-stack, and code area:
98
 
99
    HAL_VIRT_TO_PHYS_ADDRESS( &stackmem, p2 );
100
    HAL_PHYS_TO_VIRT_ADDRESS( p2, v2 );
101
    CYG_TEST_CHECK( (unsigned int)(&stackmem) == v2,
102
                    "Stackmem translation failed" );
103
 
104
    HAL_VIRT_TO_PHYS_ADDRESS( &staticmem, p2 );
105
    HAL_PHYS_TO_VIRT_ADDRESS( p2, v2 );
106
    CYG_TEST_CHECK( (unsigned int)(&staticmem) == v2,
107
                    "Staticmem translation failed" );
108
 
109
    HAL_VIRT_TO_PHYS_ADDRESS( &somefunc, p2 );
110
    HAL_PHYS_TO_VIRT_ADDRESS( p2, v2 );
111
    CYG_TEST_CHECK( (unsigned int)(&somefunc) == v2,
112
                    "Somefunc translation failed" );
113
 
114
 
115
    // Test the macros with variable pointer input args:
116
 
117
    v1 = (unsigned int)&stackmem;
118
    HAL_VIRT_TO_PHYS_ADDRESS( v1, p2 );
119
    HAL_PHYS_TO_VIRT_ADDRESS( p2, v2 );
120
    CYG_TEST_CHECK( v1 == v2,
121
                    "Ptr-to-stackmem translation failed" );
122
 
123
    v1 = (unsigned int)&staticmem;
124
    HAL_VIRT_TO_PHYS_ADDRESS( v1, p2 );
125
    HAL_PHYS_TO_VIRT_ADDRESS( p2, v2 );
126
    CYG_TEST_CHECK( v1 == v2,
127
                    "Ptr-to-staticmem translation failed" );
128
 
129
    v1 = (unsigned int)&somefunc;
130
    HAL_VIRT_TO_PHYS_ADDRESS( v1, p2 );
131
    HAL_PHYS_TO_VIRT_ADDRESS( p2, v2 );
132
    CYG_TEST_CHECK( v1 == v2,
133
                    "Ptr-to-somefunc translation failed" );
134
 
135
 
136
    // Test the UNCACHED address macros similarly:
137
 
138
    v1 = (unsigned int)&stackmem;
139
    HAL_VIRT_TO_UNCACHED_ADDRESS( v1, p2 );
140
    CYG_TEST_CHECK( v1 != p2, "Stack mem already uncached!" );
141
    *(int *)v1 = 17;
142
    HAL_DCACHE_STORE( v1, 4 );
143
    CYG_TEST_CHECK( *(int *)p2 == 17, "Uncached stack data not 17" );
144
    *(int *)v1 = 23;
145
    HAL_DCACHE_STORE( v1, 4 );
146
    CYG_TEST_CHECK( *(int *)p2 == 23, "Uncached stack data not 23" );
147
 
148
    v1 = (unsigned int)&staticmem;
149
    HAL_VIRT_TO_UNCACHED_ADDRESS( v1, p2 );
150
    CYG_TEST_CHECK( v1 != p2, "Static mem already uncached!" );
151
    *(int *)v1 = 117;
152
    HAL_DCACHE_STORE( v1, 4 );
153
    CYG_TEST_CHECK( *(int *)p2 == 117, "Uncached static data not 117" );
154
    *(int *)v1 = 123;
155
    HAL_DCACHE_STORE( v1, 4 );
156
    CYG_TEST_CHECK( *(int *)p2 == 123, "Uncached static data not 123" );
157
 
158
#ifdef CYG_HAL_STARTUP_RAM // then somefunc is in RAM, and this is valid
159
    v1 = (unsigned int)&somefunc;
160
    HAL_VIRT_TO_UNCACHED_ADDRESS( v1, p2 );
161
    CYG_TEST_CHECK( v1 != p2, "Somefunc already uncached!" );
162
    CYG_TEST_CHECK( *(int *)p2 == *(int *)v1, "Uncached instruction not the same" );
163
#else
164
    CYG_TEST_INFO( "Skipping code cachability test, not RAM start" );
165
#endif
166
 
167
    // Now check via the routines that actually read the MMAP table:
168
 
169
    v1 = (unsigned int)&stackmem;
170
    p1 = hal_virt_to_phys_address( v1 );
171
    HAL_VIRT_TO_PHYS_ADDRESS( v1, p2 );
172
    CYG_TEST_CHECK( p1 == p2, "Physical address of stackmem mismatch" );
173
    v1 = hal_phys_to_virt_address( p2 );
174
    HAL_PHYS_TO_VIRT_ADDRESS( p2, v2 );
175
    CYG_TEST_CHECK( &stackmem == (int *)v1,
176
                    "Func : Virtual address of stackmem wrong" );
177
    CYG_TEST_CHECK( &stackmem == (int *)v2,
178
                    "Macro: Virtual address of stackmem wrong" );
179
 
180
    v1 = (unsigned int)&staticmem;
181
    p1 = hal_virt_to_phys_address( v1 );
182
    HAL_VIRT_TO_PHYS_ADDRESS( v1, p2 );
183
    CYG_TEST_CHECK( p1 == p2, "Physical address of staticmem mismatch" );
184
    v1 = hal_phys_to_virt_address( p2 );
185
    HAL_PHYS_TO_VIRT_ADDRESS( p2, v2 );
186
    CYG_TEST_CHECK( &staticmem == (int *)v1,
187
                    "Func : Virtual address of staticmem wrong" );
188
    CYG_TEST_CHECK( &staticmem == (int *)v2,
189
                    "Macro: Virtual address of staticmem wrong" );
190
 
191
    v1 = (unsigned int)&somefunc;
192
    p1 = hal_virt_to_phys_address( v1 );
193
    HAL_VIRT_TO_PHYS_ADDRESS( v1, p2 );
194
    CYG_TEST_CHECK( p1 == p2, "Physical address of somefunc mismatch" );
195
    v1 = hal_phys_to_virt_address( p2 );
196
    HAL_PHYS_TO_VIRT_ADDRESS( p2, v2 );
197
    CYG_TEST_CHECK( (unsigned int)&somefunc ==v1,
198
                    "Func : Virtual address of somefunc wrong" );
199
    CYG_TEST_CHECK( (unsigned int)&somefunc == v2,
200
                    "Macro: Virtual address of somefunc wrong" );
201
 
202
 
203
    // And check the uncached-address version of the routines that actually
204
    // read the MMAP table:
205
 
206
    v1 = (unsigned int)&stackmem;
207
    p1 = hal_virt_to_uncached_address( v1 );
208
    HAL_VIRT_TO_UNCACHED_ADDRESS( v1, p2 );
209
    CYG_TEST_CHECK( p1 == p2, "Uncached address of stackmem mismatch" );
210
 
211
    v1 = (unsigned int)&staticmem;
212
    p1 = hal_virt_to_uncached_address( v1 );
213
    HAL_VIRT_TO_UNCACHED_ADDRESS( v1, p2 );
214
    CYG_TEST_CHECK( p1 == p2, "Uncached address of staticmem mismatch" );
215
 
216
#ifdef CYG_HAL_STARTUP_RAM // then somefunc is in RAM, and this is valid
217
    v1 = (unsigned int)&somefunc;
218
    p1 = hal_virt_to_uncached_address( v1 );
219
    HAL_VIRT_TO_UNCACHED_ADDRESS( v1, p2 );
220
    CYG_TEST_CHECK( p1 == p2, "Uncached address of somefunc mismatch" );
221
#else
222
    CYG_TEST_INFO( "Skipping code cachability test 2, not RAM start" );
223
#endif
224
 
225
    CYG_TEST_PASS( "Initial explicit tests AOK" );
226
 
227
    // ---------------------------------------------------------------
228
    // 
229
    // We have now tested the macros and routines for some example objects
230
    // that we know are in RAM and which therefore should be dual-mapped.
231
    //
232
    // We can now whizz through all of the address space, checking as we go
233
    // that sensible things happen.  We must NOT use the addresses in
234
    // question, just pass them through the macros and routines.
235
 
236
    // Start from some random address,
237
    //    go up until we have covered all of memory
238
    //        increment by about 0.8 of a Mb,
239
    for ( v1 = 0x12345; v1 ; v1 += 0xffff7 ) {
240
        unsigned int v3;
241
 
242
        loopcount++;
243
 
244
        p1 = hal_virt_to_phys_address( v1 );
245
        HAL_VIRT_TO_PHYS_ADDRESS( v1, p2 );
246
        if ( p1 ) {
247
            vpcount++;
248
            // Then there is a physical address for this virtual address
249
            if (p1 != p2) diag_printf("v1: %p, p1: %p, p2: %p\n", v1, p1, p2);
250
            CYG_TEST_CHECK( p1 == p2,
251
                            "Scan: truly mapped physical address mismatch" );
252
 
253
            v3 = hal_phys_to_virt_address( p2 );
254
            HAL_PHYS_TO_VIRT_ADDRESS( p2, v2 );
255
            if (v2 != v3) diag_printf("v1: %p, p1: %p, v2: %p, v3: %p\n", v1, p1, v2, v3);
256
            CYG_TEST_CHECK( v3 == v2,
257
                            "Scan: backmapped virtual address mismatch" );
258
            // But the virtual address might be elsewhere, ie. a cached
259
            // nonphysical address.
260
            if ( v3 != v1 ) {
261
                // Then it is [also] elsewhere, apparently.  Check that its
262
                // otherness maps right back to this physical address.
263
                p1 = hal_virt_to_phys_address( v2 );
264
                if (p1 != p2) diag_printf("v1: %p, p1: %p, p2: %p\n", v1, p1, p2);
265
                CYG_TEST_CHECK( p1 == p2,
266
                                "Scan: phys(virt(phys(x))) mismatch" );
267
            }
268
        }
269
 
270
        p1 = hal_virt_to_uncached_address( v1 );
271
        HAL_VIRT_TO_UNCACHED_ADDRESS( v1, p2 );
272
        if ( p1 ) {
273
            uncachedcount++;
274
            // Then there is an uncached address for this virtual address
275
            if (p1 != p2) diag_printf("v1: %p, p1: %p, p2: %p\n", v1, p1, p2);
276
            CYG_TEST_CHECK( p1 == p2, "Uncached address of stackmem mismatch" );
277
        }
278
 
279
        if ( v1 > 0xfff00000u )
280
            break;
281
    }
282
 
283
    diag_printf( "INFO:<%d addresses tested>\n", loopcount );
284
    diag_printf( "INFO:<%d virt-phys mappings checked>\n", vpcount );
285
    diag_printf( "INFO:<%d uncachable addresses checked>\n", uncachedcount );
286
 
287
    CYG_TEST_PASS( "MMap memory scan test OK" );
288
 
289
    // ---------------------------------------------------------------
290
    CYG_TEST_EXIT( "Done" );
291
}
292
 
293
// EOF mmap_test.c

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.