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

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [rtos/] [ecos-2.0/] [packages/] [io/] [pci/] [v2_0/] [tests/] [pci2.c] - Blame information for rev 584

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

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

powered by: WebSVN 2.1.0

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