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

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [rtos/] [ecos-3.0/] [packages/] [io/] [pci/] [current/] [tests/] [pci1.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
//        pci1.c
4
//
5
//        Test PCI library API
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:
46
//                  Checks API (compile time)
47
//                  Prints out information about found PCI devices.
48
//                  Allocates resources to devices (but does not enable
49
//                  them).
50
//####DESCRIPTIONEND####
51
 
52
#include <pkgconf/system.h>
53
 
54
#include <cyg/infra/diag.h>             // diag_printf
55
#include <cyg/infra/testcase.h>         // test macros
56
#include <cyg/infra/cyg_ass.h>          // assertion macros
57
 
58
// Package requirements
59
#if defined(CYGPKG_IO_PCI) && defined(CYGPKG_KERNEL) && defined(CYGPKG_ISOINFRA)
60
 
61
#include <pkgconf/kernel.h>
62
#include <pkgconf/io_pci.h>
63
#include <cyg/io/pci.h>
64
#include <cyg/hal/hal_arch.h>
65
#include <string.h>
66
 
67
// Package option requirements
68
#if defined(CYGFUN_KERNEL_API_C) && defined(CYG_PCI_PRESENT)
69
 
70
#include <cyg/kernel/kapi.h>
71
 
72
// If the target has limited memory resources, undef the below to
73
// avoid inclusion of the big PCI code tables.
74
//
75
// The header file is created from http://www.yourvote.com/pci
76
// maintained by Jim Boemler (jboemler@halcyon.com).
77
//
78
// If you have PCI devices not listed in this list, please consider
79
// registering the codes in the database.
80
#define USE_PCI_CODE_LIST
81
 
82
#ifdef USE_PCI_CODE_LIST
83
#include "pcihdr.h"
84
#endif
85
 
86
// You may want to use this code to do some simple testing of the
87
// devices on the PCI bus. By enabling the below definition, the
88
// devices will get PCI IO and MEM access activated after configuration
89
// so you can play with IO registers and display/set contents of MEM.
90
#define nENABLE_PCI_DEVICES
91
 
92
unsigned char stack[CYGNUM_HAL_STACK_SIZE_TYPICAL];
93
cyg_thread thread_data;
94
cyg_handle_t thread_handle;
95
 
96
void pci_scan( void );
97
 
98
cyg_bool
99
pci_api_test(int dummy)
100
{
101
    cyg_pci_device dev_info;
102
    cyg_pci_device_id devid = CYG_PCI_NULL_DEVID;
103
    cyg_bool ret;
104
    CYG_PCI_ADDRESS64 mem_base = 0;
105
    CYG_PCI_ADDRESS32 io_base = 0;
106
    CYG_ADDRWORD vec;
107
    cyg_uint8 var_uint8;
108
    cyg_uint16 var_uint16;
109
    cyg_uint32 var_uint32;
110
 
111
 
112
    // Always return...
113
    if (dummy)
114
        return true;
115
 
116
    CYG_TEST_FAIL_FINISH("Not reached");
117
 
118
    // PCI library API
119
    cyg_pci_init();
120
 
121
    cyg_pci_get_device_info (devid, &dev_info);
122
    cyg_pci_set_device_info (devid, &dev_info);
123
 
124
    ret = cyg_pci_find_device(0, 0, &devid);
125
    ret |= cyg_pci_find_class(0, &devid);
126
    ret |= cyg_pci_find_next(devid, &devid);
127
 
128
    ret |= cyg_pci_configure_device(&dev_info);
129
 
130
    cyg_pci_set_memory_base(mem_base);
131
    cyg_pci_set_io_base(io_base);
132
 
133
    ret |= cyg_pci_allocate_memory(&dev_info, 0, &mem_base);
134
    ret |= cyg_pci_allocate_io(&dev_info, 0, &io_base);
135
 
136
    ret |= cyg_pci_translate_interrupt(&dev_info, &vec);
137
 
138
    cyg_pci_read_config_uint8(devid, 0, &var_uint8);
139
    cyg_pci_read_config_uint16(devid, 0, &var_uint16);
140
    cyg_pci_read_config_uint32(devid, 0, &var_uint32);
141
 
142
    cyg_pci_write_config_uint8(devid, 0, var_uint8);
143
    cyg_pci_write_config_uint16(devid, 0, var_uint16);
144
    cyg_pci_write_config_uint32(devid, 0, var_uint32);
145
 
146
    return ret;
147
}
148
 
149
void
150
pci_test( void )
151
{
152
    cyg_pci_device dev_info;
153
    cyg_pci_device_id devid;
154
    CYG_ADDRWORD irq;
155
    int i;
156
#ifdef USE_PCI_CODE_LIST
157
    cyg_bool no_match = false;
158
    cyg_uint16 vendor, device;
159
    cyg_uint8  bc, sc, pi;
160
    PCI_VENTABLE* vtbl;
161
    PCI_DEVTABLE* dtbl;
162
    PCI_CLASSCODETABLE* ctbl;
163
#endif
164
 
165
    pci_api_test(1);
166
 
167
    cyg_pci_init();
168
 
169
    diag_printf( "========== Finding and configuring devices\n" );
170
 
171
    if (cyg_pci_find_next(CYG_PCI_NULL_DEVID, &devid)) {
172
        do {
173
            // Get device info
174
            cyg_pci_get_device_info(devid, &dev_info);
175
 
176
 
177
            // Print stuff
178
            diag_printf("Found device on bus %d, devfn 0x%02x:\n",
179
                        CYG_PCI_DEV_GET_BUS(devid),
180
                        CYG_PCI_DEV_GET_DEVFN(devid));
181
 
182
            if (dev_info.command & CYG_PCI_CFG_COMMAND_ACTIVE) {
183
                diag_printf(" Note that board is active. Probed"
184
                            " sizes and CPU addresses invalid!\n");
185
            }
186
 
187
            // Configure the device
188
            if (cyg_pci_configure_device(&dev_info)) {
189
                diag_printf(" Device configuration succeeded\n");
190
#ifdef ENABLE_PCI_DEVICES
191
                {
192
                    cyg_uint16 cmd;
193
 
194
                    // Don't use cyg_pci_set_device_info since it clears
195
                    // some of the fields we want to print out below.
196
                    cyg_pci_read_config_uint16(dev_info.devid,
197
                                               CYG_PCI_CFG_COMMAND, &cmd);
198
                    cmd |= CYG_PCI_CFG_COMMAND_IO|CYG_PCI_CFG_COMMAND_MEMORY;
199
                    cyg_pci_write_config_uint16(dev_info.devid,
200
                                                CYG_PCI_CFG_COMMAND, cmd);
201
                }
202
                diag_printf(" **** Device IO and MEM access enabled\n");
203
#endif
204
            } else {
205
                diag_printf(" Device configuration failed");
206
                if (dev_info.command & CYG_PCI_CFG_COMMAND_ACTIVE)
207
                    diag_printf(" - device already enabled\n");
208
                else
209
                    diag_printf(" - resource problem\n");
210
            }
211
 
212
            diag_printf(" Vendor    0x%04x", dev_info.vendor);
213
#ifdef USE_PCI_CODE_LIST
214
            vendor = dev_info.vendor;
215
            vtbl = PciVenTable;
216
            for (i = 0; i < PCI_VENTABLE_LEN; i++, vtbl++)
217
                if (vendor == vtbl->VenId)
218
                    break;
219
 
220
            if (i < PCI_VENTABLE_LEN) {
221
                diag_printf(" [%s][%s]", vtbl->VenShort, vtbl->VenFull);
222
            } else {
223
                diag_printf(" [UNKNOWN]");
224
                no_match = true;
225
            }
226
#endif
227
            diag_printf("\n Device    0x%04x", dev_info.device);
228
#ifdef USE_PCI_CODE_LIST
229
            device = dev_info.device;
230
            dtbl = PciDevTable;
231
            for (i = 0; i < PCI_DEVTABLE_LEN; i++, dtbl++)
232
                if (vendor == dtbl->VenId && device == dtbl->DevId)
233
                    break;
234
 
235
            if (i < PCI_DEVTABLE_LEN) {
236
                diag_printf(" [%s][%s]", dtbl->Chip, dtbl->ChipDesc);
237
            } else {
238
                diag_printf(" [UNKNOWN]");
239
                no_match = true;
240
            }
241
#endif
242
 
243
            diag_printf("\n Command   0x%04x, Status 0x%04x\n",
244
                        dev_info.command, dev_info.status);
245
 
246
            diag_printf(" Class/Rev 0x%08x", dev_info.class_rev);
247
#ifdef USE_PCI_CODE_LIST
248
            bc = (dev_info.class_rev >> 24) & 0xff;
249
            sc = (dev_info.class_rev >> 16) & 0xff;
250
            pi = (dev_info.class_rev >>  8) & 0xff;
251
            ctbl = PciClassCodeTable;
252
            for (i = 0; i < PCI_CLASSCODETABLE_LEN; i++, ctbl++)
253
                if (bc == ctbl->BaseClass
254
                    && sc == ctbl->SubClass
255
                    && pi == ctbl->ProgIf)
256
                    break;
257
 
258
            if (i < PCI_CLASSCODETABLE_LEN) {
259
                diag_printf(" [%s][%s][%s]", ctbl->BaseDesc,
260
                            ctbl->SubDesc, ctbl->ProgDesc);
261
            } else {
262
                diag_printf(" [UNKNOWN]");
263
                no_match = true;
264
            }
265
#endif
266
            diag_printf("\n Header 0x%02x\n", dev_info.header_type);
267
 
268
            diag_printf(" SubVendor 0x%04x, Sub ID 0x%04x\n",
269
                        dev_info.header.normal.sub_vendor,
270
                        dev_info.header.normal.sub_id);
271
 
272
 
273
            for(i = 0; i < CYG_PCI_MAX_BAR; i++) {
274
                diag_printf(" BAR[%d]    0x%08x /", i, dev_info.base_address[i]);
275
                diag_printf(" probed size 0x%08x / CPU addr 0x%08x\n",
276
                            dev_info.base_size[i], dev_info.base_map[i]);
277
            }
278
 
279
            if (cyg_pci_translate_interrupt(&dev_info, &irq))
280
                diag_printf(" Wired to HAL vector %d\n", irq);
281
            else
282
                diag_printf(" Does not generate interrupts.\n");
283
 
284
        } while (cyg_pci_find_next(devid, &devid));
285
 
286
 
287
#ifdef USE_PCI_CODE_LIST
288
        diag_printf("\nStrings in [] are from the PCI Code List at http://www.yourvote.com/pci\n");
289
        if (no_match) {
290
            diag_printf("It seems that some of the device information has not been registered in\n");
291
            diag_printf("the PCI Code List. Please consider improving the database by registering\n");
292
            diag_printf("the [UNKNOWN] information for your devices. Thanks.\n");
293
        }
294
#endif
295
    } else {
296
        diag_printf("No PCI devices found.");
297
    }
298
 
299
    pci_scan();
300
 
301
    CYG_TEST_PASS_FINISH("pci1 test OK");
302
}
303
 
304
void
305
pci_scan( void )
306
{
307
    cyg_pci_device dev_info;
308
    cyg_pci_device_id devid;
309
    CYG_ADDRWORD irq;
310
    int i;
311
#ifdef USE_PCI_CODE_LIST
312
    cyg_bool no_match = false;
313
    cyg_uint16 vendor, device;
314
    cyg_uint8  bc, sc, pi;
315
    PCI_VENTABLE* vtbl;
316
    PCI_DEVTABLE* dtbl;
317
    PCI_CLASSCODETABLE* ctbl;
318
#endif
319
 
320
    diag_printf( "========== Scanning initialized devices\n" );
321
 
322
    if (cyg_pci_find_next(CYG_PCI_NULL_DEVID, &devid)) {
323
        do {
324
            // Since we are NOT about to configure the device, set the
325
            // devinfo record so we don't mistake garbage for data.
326
            memset( &dev_info, 0xAAAAAAAAu, sizeof( dev_info ) );
327
 
328
            // Get device info
329
            cyg_pci_get_device_info(devid, &dev_info);
330
 
331
            // Print stuff
332
            diag_printf("Found device on bus %d, devfn 0x%02x:\n",
333
                        CYG_PCI_DEV_GET_BUS(devid),
334
                        CYG_PCI_DEV_GET_DEVFN(devid));
335
 
336
            if (dev_info.command & CYG_PCI_CFG_COMMAND_ACTIVE) {
337
                diag_printf(" Note that board is active. Probed"
338
                            " sizes and CPU addresses invalid!\n");
339
            }
340
 
341
            diag_printf(" Vendor    0x%04x", dev_info.vendor);
342
#ifdef USE_PCI_CODE_LIST
343
            vendor = dev_info.vendor;
344
            vtbl = PciVenTable;
345
            for (i = 0; i < PCI_VENTABLE_LEN; i++, vtbl++)
346
                if (vendor == vtbl->VenId)
347
                    break;
348
 
349
            if (i < PCI_VENTABLE_LEN) {
350
                diag_printf(" [%s][%s]", vtbl->VenShort, vtbl->VenFull);
351
            } else {
352
                diag_printf(" [UNKNOWN]");
353
                no_match = true;
354
            }
355
#endif
356
            diag_printf("\n Device    0x%04x", dev_info.device);
357
#ifdef USE_PCI_CODE_LIST
358
            device = dev_info.device;
359
            dtbl = PciDevTable;
360
            for (i = 0; i < PCI_DEVTABLE_LEN; i++, dtbl++)
361
                if (vendor == dtbl->VenId && device == dtbl->DevId)
362
                    break;
363
 
364
            if (i < PCI_DEVTABLE_LEN) {
365
                diag_printf(" [%s][%s]", dtbl->Chip, dtbl->ChipDesc);
366
            } else {
367
                diag_printf(" [UNKNOWN]");
368
                no_match = true;
369
            }
370
#endif
371
 
372
            diag_printf("\n Command   0x%04x, Status 0x%04x\n",
373
                        dev_info.command, dev_info.status);
374
 
375
            diag_printf(" Class/Rev 0x%08x", dev_info.class_rev);
376
#ifdef USE_PCI_CODE_LIST
377
            bc = (dev_info.class_rev >> 24) & 0xff;
378
            sc = (dev_info.class_rev >> 16) & 0xff;
379
            pi = (dev_info.class_rev >>  8) & 0xff;
380
            ctbl = PciClassCodeTable;
381
            for (i = 0; i < PCI_CLASSCODETABLE_LEN; i++, ctbl++)
382
                if (bc == ctbl->BaseClass
383
                    && sc == ctbl->SubClass
384
                    && pi == ctbl->ProgIf)
385
                    break;
386
 
387
            if (i < PCI_CLASSCODETABLE_LEN) {
388
                diag_printf(" [%s][%s][%s]", ctbl->BaseDesc,
389
                            ctbl->SubDesc, ctbl->ProgDesc);
390
            } else {
391
                diag_printf(" [UNKNOWN]");
392
                no_match = true;
393
            }
394
#endif
395
            diag_printf("\n Header 0x%02x\n", dev_info.header_type);
396
 
397
            diag_printf(" SubVendor 0x%04x, Sub ID 0x%04x\n",
398
                        dev_info.header.normal.sub_vendor,
399
                        dev_info.header.normal.sub_id);
400
 
401
 
402
            for(i = 0; i < CYG_PCI_MAX_BAR; i++) {
403
                diag_printf(" BAR[%d]    0x%08x /", i, dev_info.base_address[i]);
404
                diag_printf(" probed size 0x%08x / CPU addr 0x%08x\n",
405
                            dev_info.base_size[i], dev_info.base_map[i]);
406
            }
407
 
408
            if (cyg_pci_translate_interrupt(&dev_info, &irq))
409
                diag_printf(" Wired to HAL vector %d\n", irq);
410
            else
411
                diag_printf(" Does not generate interrupts.\n");
412
 
413
        } while (cyg_pci_find_next(devid, &devid));
414
    } else {
415
        diag_printf("No PCI devices found.");
416
    }
417
}
418
 
419
void
420
cyg_start(void)
421
{
422
    CYG_TEST_INIT();
423
    cyg_thread_create(10,                   // Priority - just a number
424
                      (cyg_thread_entry_t*)pci_test,         // entry
425
                      0,                    // 
426
                      "pci_thread",     // Name
427
                      &stack[0],            // Stack
428
                      CYGNUM_HAL_STACK_SIZE_TYPICAL,           // Size
429
                      &thread_handle,       // Handle
430
                      &thread_data          // Thread data structure
431
        );
432
    cyg_thread_resume(thread_handle);
433
    cyg_scheduler_start();
434
}
435
 
436
#else // CYGFUN_KERNEL_API_C && CYG_PCI_PRESENT
437
#define N_A_MSG "Needs kernel C API & PCI platform support"
438
#endif
439
 
440
#else // CYGPKG_IO_PCI && CYGPKG_KERNEL
441
#define N_A_MSG "Needs IO/PCI, ISOINFRA, and Kernel"
442
#endif
443
 
444
#ifdef N_A_MSG
445
void
446
cyg_start( void )
447
{
448
    CYG_TEST_INIT();
449
    CYG_TEST_NA( N_A_MSG);
450
}
451
#endif // N_A_MSG
452
 
453
// EOF pci1.c

powered by: WebSVN 2.1.0

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