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

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [rtos/] [ecos-2.0/] [packages/] [hal/] [arm/] [sa11x0/] [var/] [v2_0/] [tests/] [mmap_test.c] - Blame information for rev 174

Details | Compare with Previous | View Log

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

powered by: WebSVN 2.1.0

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