📄 pci1.c
字号:
//==========================================================================
//
// pci1.c
//
// Test PCI library API
//
//==========================================================================
//####ECOSGPLCOPYRIGHTBEGIN####
// -------------------------------------------
// This file is part of eCos, the Embedded Configurable Operating System.
// Copyright (C) 1998, 1999, 2000, 2001, 2002 Red Hat, Inc.
//
// eCos is free software; you can redistribute it and/or modify it under
// the terms of the GNU General Public License as published by the Free
// Software Foundation; either version 2 or (at your option) any later version.
//
// eCos is distributed in the hope that it will be useful, but WITHOUT ANY
// WARRANTY; without even the implied warranty of MERCHANTABILITY or
// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
// for more details.
//
// You should have received a copy of the GNU General Public License along
// with eCos; if not, write to the Free Software Foundation, Inc.,
// 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
//
// As a special exception, if other files instantiate templates or use macros
// or inline functions from this file, or you compile this file and link it
// with other works to produce a work based on this file, this file does not
// by itself cause the resulting work to be covered by the GNU General Public
// License. However the source code for this file must still be made available
// in accordance with section (3) of the GNU General Public License.
//
// This exception does not invalidate any other reasons why a work based on
// this file might be covered by the GNU General Public License.
//
// Alternative licenses for eCos may be arranged by contacting Red Hat, Inc.
// at http://sources.redhat.com/ecos/ecos-license/
// -------------------------------------------
//####ECOSGPLCOPYRIGHTEND####
//==========================================================================
//#####DESCRIPTIONBEGIN####
//
// Author(s): jskov
// Contributors: jskov
// Date: 1999-03-17
// Description: Simple test that:
// Checks API (compile time)
// Prints out information about found PCI devices.
// Allocates resources to devices (but does not enable
// them).
//####DESCRIPTIONEND####
#include <pkgconf/system.h>
#include <cyg/infra/diag.h> // diag_printf
#include <cyg/infra/testcase.h> // test macros
#include <cyg/infra/cyg_ass.h> // assertion macros
// Package requirements
#if defined(CYGPKG_IO_PCI) && defined(CYGPKG_KERNEL) && defined(CYGPKG_ISOINFRA)
#include <pkgconf/kernel.h>
#include <pkgconf/io_pci.h>
#include <cyg/io/pci.h>
#include <cyg/hal/hal_arch.h>
#include <string.h>
// Package option requirements
#if defined(CYGFUN_KERNEL_API_C) && defined(CYG_PCI_PRESENT)
#include <cyg/kernel/kapi.h>
// If the target has limited memory resources, undef the below to
// avoid inclusion of the big PCI code tables.
//
// The header file is created from http://www.yourvote.com/pci
// maintained by Jim Boemler (jboemler@halcyon.com).
//
// If you have PCI devices not listed in this list, please consider
// registering the codes in the database.
#define USE_PCI_CODE_LIST
#ifdef USE_PCI_CODE_LIST
#include "pcihdr.h"
#endif
// You may want to use this code to do some simple testing of the
// devices on the PCI bus. By enabling the below definition, the
// devices will get PCI IO and MEM access activated after configuration
// so you can play with IO registers and display/set contents of MEM.
#define nENABLE_PCI_DEVICES
unsigned char stack[CYGNUM_HAL_STACK_SIZE_TYPICAL];
cyg_thread thread_data;
cyg_handle_t thread_handle;
void pci_scan( void );
cyg_bool
pci_api_test(int dummy)
{
cyg_pci_device dev_info;
cyg_pci_device_id devid = CYG_PCI_NULL_DEVID;
cyg_bool ret;
CYG_PCI_ADDRESS64 mem_base = 0;
CYG_PCI_ADDRESS32 io_base = 0;
CYG_ADDRWORD vec;
cyg_uint8 var_uint8;
cyg_uint16 var_uint16;
cyg_uint32 var_uint32;
// Always return...
if (dummy)
return true;
CYG_TEST_FAIL_FINISH("Not reached");
// PCI library API
cyg_pci_init();
cyg_pci_get_device_info (devid, &dev_info);
cyg_pci_set_device_info (devid, &dev_info);
ret = cyg_pci_find_device(0, 0, &devid);
ret |= cyg_pci_find_class(0, &devid);
ret |= cyg_pci_find_next(devid, &devid);
ret |= cyg_pci_configure_device(&dev_info);
cyg_pci_set_memory_base(mem_base);
cyg_pci_set_io_base(io_base);
ret |= cyg_pci_allocate_memory(&dev_info, 0, &mem_base);
ret |= cyg_pci_allocate_io(&dev_info, 0, &io_base);
ret |= cyg_pci_translate_interrupt(&dev_info, &vec);
cyg_pci_read_config_uint8(devid, 0, &var_uint8);
cyg_pci_read_config_uint16(devid, 0, &var_uint16);
cyg_pci_read_config_uint32(devid, 0, &var_uint32);
cyg_pci_write_config_uint8(devid, 0, var_uint8);
cyg_pci_write_config_uint16(devid, 0, var_uint16);
cyg_pci_write_config_uint32(devid, 0, var_uint32);
return ret;
}
void
pci_test( void )
{
cyg_pci_device dev_info;
cyg_pci_device_id devid;
CYG_ADDRWORD irq;
int i;
#ifdef USE_PCI_CODE_LIST
cyg_bool no_match = false;
cyg_uint16 vendor, device;
cyg_uint8 bc, sc, pi;
PCI_VENTABLE* vtbl;
PCI_DEVTABLE* dtbl;
PCI_CLASSCODETABLE* ctbl;
#endif
pci_api_test(1);
cyg_pci_init();
diag_printf( "========== Finding and configuring devices\n" );
if (cyg_pci_find_next(CYG_PCI_NULL_DEVID, &devid)) {
do {
// Get device info
cyg_pci_get_device_info(devid, &dev_info);
// Print stuff
diag_printf("Found device on bus %d, devfn 0x%02x:\n",
CYG_PCI_DEV_GET_BUS(devid),
CYG_PCI_DEV_GET_DEVFN(devid));
if (dev_info.command & CYG_PCI_CFG_COMMAND_ACTIVE) {
diag_printf(" Note that board is active. Probed"
" sizes and CPU addresses invalid!\n");
}
// Configure the device
if (cyg_pci_configure_device(&dev_info)) {
diag_printf(" Device configuration succeeded\n");
#ifdef ENABLE_PCI_DEVICES
{
cyg_uint16 cmd;
// Don't use cyg_pci_set_device_info since it clears
// some of the fields we want to print out below.
cyg_pci_read_config_uint16(dev_info.devid,
CYG_PCI_CFG_COMMAND, &cmd);
cmd |= CYG_PCI_CFG_COMMAND_IO|CYG_PCI_CFG_COMMAND_MEMORY;
cyg_pci_write_config_uint16(dev_info.devid,
CYG_PCI_CFG_COMMAND, cmd);
}
diag_printf(" **** Device IO and MEM access enabled\n");
#endif
} else {
diag_printf(" Device configuration failed");
if (dev_info.command & CYG_PCI_CFG_COMMAND_ACTIVE)
diag_printf(" - device already enabled\n");
else
diag_printf(" - resource problem\n");
}
diag_printf(" Vendor 0x%04x", dev_info.vendor);
#ifdef USE_PCI_CODE_LIST
vendor = dev_info.vendor;
vtbl = PciVenTable;
for (i = 0; i < PCI_VENTABLE_LEN; i++, vtbl++)
if (vendor == vtbl->VenId)
break;
if (i < PCI_VENTABLE_LEN) {
diag_printf(" [%s][%s]", vtbl->VenShort, vtbl->VenFull);
} else {
diag_printf(" [UNKNOWN]");
no_match = true;
}
#endif
diag_printf("\n Device 0x%04x", dev_info.device);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -