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

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [rtos/] [ecos-3.0/] [packages/] [io/] [pci/] [current/] [tests/] [pci2.c] - Blame information for rev 825

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 786 skrzyp
//==========================================================================
2
//
3
//        pci2.c
4
//
5
//        Test PCI library's resource allocation.
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):     jskov
43
// Contributors:  jskov
44
// Date:          1999-03-17
45
// Description: Simple test that prints out information about found
46
//              PCI devices. Entirely passive - no configuration happens.
47
// 
48
//####DESCRIPTIONEND####
49
 
50
#include <pkgconf/system.h>
51
 
52
#include <cyg/infra/diag.h>             // diag_printf
53
#include <cyg/infra/testcase.h>         // test macros
54
#include <cyg/infra/cyg_ass.h>          // assertion macros
55
 
56
// Package requirements
57
#if defined(CYGPKG_IO_PCI) && defined(CYGPKG_KERNEL)
58
 
59
#include <pkgconf/kernel.h>
60
#include <pkgconf/io_pci.h>
61
#include <cyg/io/pci.h>
62
#include <cyg/hal/hal_arch.h>
63
 
64
// Package option requirements
65
#if defined(CYGFUN_KERNEL_API_C) && defined(CYG_PCI_PRESENT)
66
 
67
#include <cyg/kernel/kapi.h>
68
 
69
unsigned char stack[CYGNUM_HAL_STACK_SIZE_TYPICAL];
70
cyg_thread thread_data;
71
cyg_handle_t thread_handle;
72
 
73
void
74
pci_test( void )
75
{
76
    cyg_pci_device dev_info;
77
    CYG_PCI_ADDRESS64 mem_base;
78
    CYG_PCI_ADDRESS64 mem_assigned_addr;
79
    CYG_PCI_ADDRESS32 io_base;
80
    CYG_PCI_ADDRESS32 io_assigned_addr;
81
 
82
    // Verify that space type requests are checked.
83
    dev_info.base_size[0] = CYG_PCI_CFG_BAR_SPACE_IO;
84
    CYG_TEST_CHECK(!cyg_pci_allocate_memory_priv(&dev_info, 0, &mem_base,
85
                                                 &mem_assigned_addr),
86
                   "cyg_pci_allocate_memory_priv accepted IO request");
87
    dev_info.base_size[0] = CYG_PCI_CFG_BAR_SPACE_MEM;
88
    CYG_TEST_CHECK(!cyg_pci_allocate_io_priv(&dev_info, 0, &io_base,
89
                                             &io_assigned_addr),
90
                   "cyg_pci_allocate_io_priv accepted MEM request");
91
 
92
    // Check allocation and alignment of IO space
93
    io_base = 0x0000;
94
    // Size 4
95
    dev_info.base_size[0] = CYG_PCI_CFG_BAR_SPACE_IO | 0xfffffffc;
96
    CYG_TEST_CHECK(cyg_pci_allocate_io_priv(&dev_info, 0, &io_base,
97
                                            &io_assigned_addr),
98
                   "cyg_pci_allocate_io_priv(4) failed");
99
    CYG_TEST_CHECK(0x0004 == io_base,
100
                   "cyg_pci_allocate_io_priv(4) size failed");
101
    CYG_TEST_CHECK(0x0000 == io_assigned_addr,
102
                   "cyg_pci_allocate_io_priv(4) align failed");
103
    // Size 8 (alignment required)
104
    dev_info.base_size[0] = CYG_PCI_CFG_BAR_SPACE_IO | 0xfffffff8;
105
    CYG_TEST_CHECK(cyg_pci_allocate_io_priv(&dev_info, 0, &io_base,
106
                                            &io_assigned_addr),
107
                   "cyg_pci_allocate_io_priv(8) failed");
108
    CYG_TEST_CHECK(0x0010 == io_base,
109
                   "cyg_pci_allocate_io_priv(8) size failed");
110
    CYG_TEST_CHECK(0x0008 == io_assigned_addr,
111
                   "cyg_pci_allocate_io_priv(8) align failed");
112
    // Size 16 (no alignment required)
113
    dev_info.base_size[0] = CYG_PCI_CFG_BAR_SPACE_IO | 0xfffffff0;
114
    CYG_TEST_CHECK(cyg_pci_allocate_io_priv(&dev_info, 0, &io_base,
115
                                            &io_assigned_addr),
116
                   "cyg_pci_allocate_io_priv(16) failed");
117
    CYG_TEST_CHECK(0x0020 == io_base,
118
                   "cyg_pci_allocate_io_priv(16) size failed");
119
    CYG_TEST_CHECK(0x0010 == io_assigned_addr,
120
                   "cyg_pci_allocate_io_priv(16) align failed");
121
    // Size 64 (alignment required)
122
    dev_info.base_size[0] = CYG_PCI_CFG_BAR_SPACE_IO | 0xffffffc0;
123
    CYG_TEST_CHECK(cyg_pci_allocate_io_priv(&dev_info, 0, &io_base,
124
                                            &io_assigned_addr),
125
                   "cyg_pci_allocate_io_priv(64) failed");
126
    CYG_TEST_CHECK(0x0080 == io_base,
127
                   "cyg_pci_allocate_io_priv(64) size failed");
128
    CYG_TEST_CHECK(0x0040 == io_assigned_addr,
129
                   "cyg_pci_allocate_io_priv(64) align failed");
130
    // Size 256 (alignment required)
131
    dev_info.base_size[0] = CYG_PCI_CFG_BAR_SPACE_IO | 0xffffff00;
132
    CYG_TEST_CHECK(cyg_pci_allocate_io_priv(&dev_info, 0, &io_base,
133
                                            &io_assigned_addr),
134
                   "cyg_pci_allocate_io_priv(256) failed");
135
    CYG_TEST_CHECK(0x0200 == io_base,
136
                   "cyg_pci_allocate_io_priv(256) size failed");
137
    CYG_TEST_CHECK(0x0100 == io_assigned_addr,
138
                   "cyg_pci_allocate_io_priv(256) align failed");
139
 
140
    // Check allocation and alignment of MEM space
141
    mem_base = 0x00000000;
142
    // Size 16 (no alignment required)
143
    dev_info.base_size[0] = CYG_PCI_CFG_BAR_SPACE_MEM | 0xfffffff0;
144
    CYG_TEST_CHECK(cyg_pci_allocate_memory_priv(&dev_info, 0, &mem_base,
145
                                                &mem_assigned_addr),
146
                   "cyg_pci_allocate_memory_priv(16) failed");
147
    CYG_TEST_CHECK(0x00000010 == mem_base,
148
                   "cyg_pci_allocate_memory_priv(16) size failed");
149
    CYG_TEST_CHECK(0x00000000 == mem_assigned_addr,
150
                   "cyg_pci_allocate_memory_priv(16) align failed");
151
    // Size 64 (alignment required - <1MB)
152
    dev_info.base_size[0] = (CYG_PCI_CFG_BAR_SPACE_MEM
153
                             | CYG_PRI_CFG_BAR_MEM_TYPE_1M
154
                             | 0xffffffc0);
155
    CYG_TEST_CHECK(cyg_pci_allocate_memory_priv(&dev_info, 0, &mem_base,
156
                                                &mem_assigned_addr),
157
                   "cyg_pci_allocate_memory_priv(64/<1MB) failed");
158
    CYG_TEST_CHECK(0x00000080 == mem_base,
159
                   "cyg_pci_allocate_memory_priv(64/<1MB) size failed");
160
    CYG_TEST_CHECK(0x00000040 == mem_assigned_addr,
161
                   "cyg_pci_allocate_memory_priv(64/<1MB) align failed");
162
    // Size 1MB (alignment required)
163
    dev_info.base_size[0] = CYG_PCI_CFG_BAR_SPACE_MEM | 0xfff00000;
164
    CYG_TEST_CHECK(cyg_pci_allocate_memory_priv(&dev_info, 0, &mem_base,
165
                                                &mem_assigned_addr),
166
                   "cyg_pci_allocate_memory_priv(1MB) failed");
167
    CYG_TEST_CHECK(0x00200000 == mem_base,
168
                   "cyg_pci_allocate_memory_priv(1MB) size failed");
169
    CYG_TEST_CHECK(0x00100000 == mem_assigned_addr,
170
                   "cyg_pci_allocate_memory_priv(1MB) align failed");
171
    // Size 16MB (alignment required)
172
    dev_info.base_size[0] = CYG_PCI_CFG_BAR_SPACE_MEM | 0xff000000;
173
    CYG_TEST_CHECK(cyg_pci_allocate_memory_priv(&dev_info, 0, &mem_base,
174
                                                &mem_assigned_addr),
175
                   "cyg_pci_allocate_memory_priv(16MB) failed");
176
    CYG_TEST_CHECK(0x02000000 == mem_base,
177
                   "cyg_pci_allocate_memory_priv(16MB) size failed");
178
    CYG_TEST_CHECK(0x01000000 == mem_assigned_addr,
179
                   "cyg_pci_allocate_memory_priv(16MB) align failed");
180
    // Size 32 (no alignment required - <1MB - FAILS!)
181
    // Note: When more clever allocation has been made for the bottom
182
    // 1MB of PCI memory space, this test needs to be made more elaborate.
183
    dev_info.base_size[0] = (CYG_PCI_CFG_BAR_SPACE_MEM
184
                             | CYG_PRI_CFG_BAR_MEM_TYPE_1M
185
                             | 0xffffffe0);
186
    CYG_TEST_CHECK(!cyg_pci_allocate_memory_priv(&dev_info, 0, &mem_base,
187
                                                 &mem_assigned_addr),
188
                 "cyg_pci_allocate_memory_priv(32/<1MB) unexpectedly worked!");
189
 
190
    // TBD: Check 64bit MEM allocation.
191
 
192
    CYG_TEST_PASS_FINISH("pci2 test OK");
193
}
194
 
195
void
196
cyg_start(void)
197
{
198
    CYG_TEST_INIT();
199
    cyg_thread_create(10,                   // Priority - just a number
200
                      (cyg_thread_entry_t*)pci_test,         // entry
201
                      0,                    // 
202
                      "pci_thread",     // Name
203
                      &stack[0],            // Stack
204
                      CYGNUM_HAL_STACK_SIZE_TYPICAL,           // Size
205
                      &thread_handle,       // Handle
206
                      &thread_data          // Thread data structure
207
        );
208
    cyg_thread_resume(thread_handle);
209
    cyg_scheduler_start();
210
}
211
 
212
#else // CYGFUN_KERNEL_API_C && CYG_PCI_PRESENT
213
#define N_A_MSG "Needs kernel C API & PCI platform support"
214
#endif
215
 
216
#else // CYGPKG_IO_PCI && CYGPKG_KERNEL
217
#define N_A_MSG "Needs IO/PCI and Kernel"
218
#endif
219
 
220
#ifdef N_A_MSG
221
void
222
cyg_start( void )
223
{
224
    CYG_TEST_INIT();
225
    CYG_TEST_NA( N_A_MSG);
226
}
227
#endif // N_A_MSG
228
 
229
// EOF pci1.c

powered by: WebSVN 2.1.0

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