⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 idpcidevices.c

📁 Vxworks下的C例子程序
💻 C
📖 第 1 页 / 共 2 页
字号:
/* IDpciDevices *//* From: Darnold, Joel R <jrdarno@sandia.gov>   *//* Show information on PCI devices including vendor and parameters *//* See PCIvenCodes.txt for additional information */#include "vxWorks.h"#include "stdio.h"#include "sysLib.h"#include "drv/pci/pciLocalBus.h"#include "drv/pci/pciIomapLib.h"#include "MyPCI.h"STATUS pciDevConfig    (    int		pciBusNo,		/* PCI bus number */    int		pciDevNo,		/* PCI device number */    int		pciFuncNo,		/* PCI function number */    ULONG       devIoBaseAdrs,          /* device IO base address */    ULONG       devMemBaseAdrs,         /* device memory base address */    ULONG       command                 /* command to issue */    );struct ID_PCI_DEVICES	{	int PciVenId;	int PciDevId;	char VendorName[20];	char DeviceName[40];	};/* externs */IMPORT int pciLibInitDone;IMPORT int pciLibInitStatus;IMPORT int pciConfigMech;STATUS IDpciDevices(int busNo){	int i=0;	int deviceNo;	int devices;	union {		int classCode;		char array[4];		} u;	struct pciHeaderDevice DeviceInfo;=20	struct ID_PCI_DEVICES IDpciDevices[NUM_IDS_DEFINED];	IDpciDevices[i].PciVenId = MOTOROLA_VEN_ID;	IDpciDevices[i].PciDevId = RAVEN_DEV_ID;	sprintf(IDpciDevices[i].VendorName,"Motorola");	sprintf(IDpciDevices[i].DeviceName,"Raven MPC/PCI Bridge");	i++;	IDpciDevices[i].PciVenId = SYMPHONY_VEN_ID;	IDpciDevices[i].PciDevId = W83C533_DEV_ID;	sprintf(IDpciDevices[i].VendorName,"Symphony");	sprintf(IDpciDevices[i].DeviceName,"W83C533 PCI/ISA Bridge");	i++;	IDpciDevices[i].PciVenId = TUNDRA_VEN_ID;	IDpciDevices[i].PciDevId = CA91C042_DEV_ID;	sprintf(IDpciDevices[i].VendorName,"Tundra");	sprintf(IDpciDevices[i].DeviceName,"CA91C042 Universe PCI/VME Bridge");	i++;	IDpciDevices[i].PciVenId = DEC_VEN_ID;	IDpciDevices[i].PciDevId = _21140_DEV_ID;	sprintf(IDpciDevices[i].VendorName,"Digital");	sprintf(IDpciDevices[i].DeviceName,"21140 Ethernet");	i++;	IDpciDevices[i].PciVenId = PLX_VEN_ID;	IDpciDevices[i].PciDevId = PCI9050_DEV_ID;	sprintf(IDpciDevices[i].VendorName,"PLX Technology");	sprintf(IDpciDevices[i].DeviceName,"PCI9050 PCI Interface (CLIB)");	i++;	IDpciDevices[i].PciVenId = PENTEK_VEN_ID;	IDpciDevices[i].PciDevId = _7110_DEV_ID;	sprintf(IDpciDevices[i].VendorName,"Pentek");	sprintf(IDpciDevices[i].DeviceName,"7110 C44 DSP PMC Module");	if (pciLibInitStatus != OK)			/* sanity check */		return (ERROR);	printf ("Scanning function 0 of each PCI device on bus %d\n", busNo);	printf ("Using configuration mechanism %d\n", pciConfigMech);	printf ("bus    dev    func   venID  devID  class description\n");	if (pciConfigMech == PCI_MECHANISM_1)		devices = 0x1f;	else		devices = 0x0f;	for (deviceNo=0; deviceNo < devices; deviceNo++)	{		pciConfigInWord (busNo, deviceNo, 0, PCI_CFG_VENDOR_ID, &DeviceInfo.vendorId);		pciConfigInWord (busNo, deviceNo, 0, PCI_CFG_DEVICE_ID, &DeviceInfo.deviceId);		pciConfigInByte (busNo, deviceNo, 0, PCI_CFG_PROGRAMMING_IF,&u.array[3]);		pciConfigInByte (busNo, deviceNo, 0, PCI_CFG_SUBCLASS, &u.array[2]);		pciConfigInByte (busNo, deviceNo, 0, PCI_CFG_CLASS, &u.array[1]);		u.array[0] = 0;	/* There are two ways to find out an empty device.	 *   1. check Master Abort bit after the access.	 *   2. check whether the read value is 0xffff.	 * Since I didn't see the Master Abort bit of the host/PCI bridge	 * changing, I use the second method.	 */		if ((unsigned short)DeviceInfo.vendorId != 0xffff)		{			pciConfigInWord (busNo, deviceNo, 0, PCI_CFG_VENDOR_ID, &DeviceInfo.vendorId);			pciConfigInWord (busNo, deviceNo, 0, PCI_CFG_DEVICE_ID, &DeviceInfo.deviceId);			pciConfigInWord (busNo, deviceNo, 0, PCI_CFG_COMMAND, &DeviceInfo.command);			pciConfigInWord (busNo, deviceNo, 0, PCI_CFG_STATUS, &DeviceInfo.status);			pciConfigInByte (busNo, deviceNo, 0, PCI_CFG_REVISION, &DeviceInfo.revisionId);			pciConfigInByte (busNo, deviceNo, 0, PCI_CFG_PROGRAMMING_IF, &DeviceInfo.classCode);			pciConfigInByte (busNo, deviceNo, 0, PCI_CFG_SUBCLASS, &DeviceInfo.progIf);			pciConfigInByte (busNo, deviceNo, 0, PCI_CFG_CLASS, &DeviceInfo.cacheLine);			pciConfigInByte (busNo, deviceNo, 0, PCI_CFG_CACHE_LINE_SIZE, &DeviceInfo.cacheLine);			pciConfigInByte (busNo, deviceNo, 0, PCI_CFG_LATENCY_TIMER, &DeviceInfo.latency);			pciConfigInByte (busNo, deviceNo, 0, PCI_CFG_HEADER_TYPE, &DeviceInfo.headerType);			pciConfigInByte (busNo, deviceNo, 0, PCI_CFG_BIST, &DeviceInfo.bist);			pciConfigInLong (busNo, deviceNo, 0, PCI_CFG_BASE_ADDRESS_0, &DeviceInfo.base0);			pciConfigInLong (busNo, deviceNo, 0, PCI_CFG_BASE_ADDRESS_1, &DeviceInfo.base1);			pciConfigInLong (busNo, deviceNo, 0, PCI_CFG_BASE_ADDRESS_2, &DeviceInfo.base2);			pciConfigInLong (busNo, deviceNo, 0, PCI_CFG_BASE_ADDRESS_3, &DeviceInfo.base3);			pciConfigInLong (busNo, deviceNo, 0, PCI_CFG_BASE_ADDRESS_4, &DeviceInfo.base4);			pciConfigInLong (busNo, deviceNo, 0, PCI_CFG_BASE_ADDRESS_5, &DeviceInfo.base5);			pciConfigInLong (busNo, deviceNo, 0, PCI_CFG_CIS, &DeviceInfo.cis);			pciConfigInWord (busNo, deviceNo, 0, PCI_CFG_SUB_VENDER_ID, &DeviceInfo.subVendorId);			pciConfigInWord (busNo, deviceNo, 0, PCI_CFG_SUB_SYSTEM_ID, &DeviceInfo.subSystemId);			pciConfigInLong (busNo, deviceNo, 0, PCI_CFG_EXPANSION_ROM, &DeviceInfo.romBase);			pciConfigInLong (busNo, deviceNo, 0, PCI_CFG_RESERVED_0, &DeviceInfo.reserved0);			pciConfigInLong (busNo, deviceNo, 0, PCI_CFG_RESERVED_1, &DeviceInfo.reserved1);			pciConfigInByte (busNo, deviceNo, 0, PCI_CFG_DEV_INT_LINE, &DeviceInfo.intLine);			pciConfigInByte (busNo, deviceNo, 0, PCI_CFG_DEV_INT_PIN, &DeviceInfo.intPin);			pciConfigInByte (busNo, deviceNo, 0, PCI_CFG_MIN_GRANT, &DeviceInfo.minGrant);			pciConfigInByte (busNo, deviceNo, 0, PCI_CFG_MAX_LATENCY, &DeviceInfo.maxLatency);/*			printf("Found device VendorID %x DeviceID %x\n",DeviceInfo.vendorId,DeviceInfo.deviceId); */			for(i=0; i<NUM_IDS_DEFINED; i++)			{				if(((unsigned short)DeviceInfo.vendorId==(unsigned short)IDpciDevices[i].PciVenId) &&=20					((unsigned short)DeviceInfo.deviceId==(unsigned short)IDpciDevices[i].PciDevId))				{					printf ("%.5x  %.5x  %.5x  %.5x  %.5x  %.5x < %s %s >\n",						busNo, deviceNo, 0,(unsigned short)DeviceInfo.vendorId,						(unsigned short)DeviceInfo.deviceId, u.classCode,						IDpciDevices[i].VendorName,IDpciDevices[i].DeviceName);				}			}			printf("vendorId    0x%.5x\n",(unsigned short)DeviceInfo.vendorId);	/* vendor ID */			printf("deviceId    0x%.5x\n",(unsigned short)DeviceInfo.deviceId);	/* device ID */			printf("command     0x%.5x\n",(unsigned short)DeviceInfo.command);	/* command register */			printf("status      0x%.5x\n",(unsigned short)DeviceInfo.status);	/* status register */			printf("revisionrId 0x%.3x\n",(unsigned char )DeviceInfo.revisionId);	/* revision ID */			printf("classCode   0x%.3x\n",(unsigned char )DeviceInfo.classCode);	/* class code */			printf("subClass    0x%.3x\n",(unsigned char )DeviceInfo.subClass);	/* sub class code */			printf("progIf      0x%.3x\n",(unsigned char )DeviceInfo.progIf);	/* programming interface */			printf("cacheLine   0x%.3x\n",(unsigned char )DeviceInfo.cacheLine);	/* cache line */			printf("latency     0x%.3x\n",(unsigned char )DeviceInfo.latency);	/* latency time */			printf("headerType  0x%.3x\n",(unsigned char )DeviceInfo.headerType);	/* header type */			printf("bist        0x%.3x\n",(unsigned char )DeviceInfo.bist);		/* BIST */			printf("base0       0x%.8x\n",(unsigned int  )DeviceInfo.base0);	/* base address 0 */			printf("base1       0x%.8x\n",(unsigned int  )DeviceInfo.base1);	/* base address 1 */			printf("base2       0x%.8x\n",(unsigned int  )DeviceInfo.base2);	/* base address 2 */			printf("base3       0x%.8x\n",(unsigned int  )DeviceInfo.base3);	/* base address 3 */			printf("base4       0x%.8x\n",(unsigned int  )DeviceInfo.base4);	/* base address 4 */			printf("base5       0x%.8x\n",(unsigned int  )DeviceInfo.base5);	/* base address 5 */			printf("cis         0x%.8x\n",(unsigned int  )DeviceInfo.cis);		/* cardBus CIS pointer */			printf("subVendorId 0x%.5x\n",(unsigned short)DeviceInfo.subVendorId);	/* sub system vendor ID */			printf("subSystemId 0x%.5x\n",(unsigned short)DeviceInfo.subSystemId);	/* sub system ID */			printf("romBase     0x%.8x\n",(unsigned int  )DeviceInfo.romBase);	/* expansion ROM base address */			printf("reserved0   0x%.8x\n",(unsigned int  )DeviceInfo.reserved0);	/* reserved */			printf("reserved1   0x%.8x\n",(unsigned int  )DeviceInfo.reserved1);	/* reserved */			printf("intLine     0x%.3x\n",(unsigned char )DeviceInfo.intLine);	/* interrupt line */			printf("intPin      0x%.3x\n",(unsigned char )DeviceInfo.intPin);	/* interrupt pin */			printf("minGrant    0x%.3x\n",(unsigned char )DeviceInfo.minGrant);	/* min Grant */			printf("maxLatency  0x%.3x\n",(unsigned char )DeviceInfo.maxLatency);	/* max Latency */		}	}	return (OK);}/* This routine writes data to PLX's local configuration      *//* registers.  The data is written as little endian so we do  *//* a 32 bit endian swap before we write the data              *//* Remember.... eprom data requires no data swappage          */void PciDevWriteLocCfgReg(int PCIBase,int RegAddress, int Data){		int SwapData=0;		SwapData = (Data & 0xff) << 24;		SwapData |= (Data & 0xff00) << 8;		SwapData |= (Data & 0xff0000) >> 8;		SwapData |= (Data & 0xff000000) >> 24;		*(volatile int *)(PCIBase+RegAddress) = SwapData;}int PciDevReadLocCfgReg(int PCIBase, int RegAddress){		int SwapData=0,Data;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -