usrusbpcilib.c

来自「IXP425的BSP代码」· C语言 代码 · 共 667 行 · 第 1/2 页

C
667
字号
/* usrUsbPciLib.c - USB specific PCI Functions *//* Copyright 1999-2000 Wind River Systems, Inc. *//*Modification history--------------------01a,10feb00,wef	 written *//*DESCRIPTIONThis file defines platform-independent functions accessing PCI bus capabilities.  These functions allow PCI device drivers to be written independent of the underlying O/S's PCI access mechanisms.The name of each function in this group begins with "usb" to represent"Device Driver Services."*//* Includes */#include "string.h"#include "vxWorks.h"#include "sysLib.h"#include "cacheLib.h"#include "iv.h"#include "intLib.h"#include "drv/pci/pciConfigLib.h"	    /* VxWorks PCI funcs *//* PLATFORM-DEPENDENT INCLUDES/DEFINITIONS */#if	CPU == PPC604/* Power PC 604 (e.g., mcp750) *//* This is messy.  There is no standard vxWorks function to in/out fromPCI I/O address space.	So, we need to bring in some constants from theactual hardware-specific build. */#include "mv2600.h"/* Mappings for I/O and memory address translation (values from mv2600.h) */#define PCI_IO_OFFSET	    CPU_PCI_ISA_IO_ADRS#define PCI_MEM_OFFSET	    PCI2DRAM_BASE_ADRS	#define PCI_MEMIO_OFFSET    (CPU_PCI_MEM_ADRS - PCI_MEM_ADRS)/* The mcp750 doesn't define sysInWord, sysInLong, sysOutWord, and * sysOutLong.	It includes the following entry points instead for which * there is no vxWorks function prototype.  We include the following * definitions in order to suppress compiler warnings. *//* Map the "standard" vxworks I/O functions to the mcp750 equivalents */#define sysInWord(p)	sysIn16(p)#define sysInLong(p)	sysIn32(p)#define sysOutWord(p,d) sysOut16(p,d)#define sysOutLong(p,d) sysOut32(p,d)/* Interrupt enable/disable */#ifdef	MCP750#define INTERRUPT_BASE	ISA_INTERRUPT_BASE#else	#define INTERRUPT_BASE	EXT_INTERRUPT_BASE#endif#define IVEC(i)		INUM_TO_IVEC ((int) ((i) + INTERRUPT_BASE))#define INT_CONNECT(intNo, func, param) \    intConnect (IVEC (intNo), (VOIDFUNCPTR) func, (int) param)#define INT_DISCONNECT(intNo, func, param)#define INT_ENABLE(i)	intEnable ((i) + INTERRUPT_BASE)#define INT_DISABLE(i)	intDisable ((i) + INTERRUPT_BASE)#elif	    CPU == PENTIUM/* Pentium (e.g, PC Pentium) */#include "drv/pci/pciIntLib.h"/* Mappings for I/O and memory address translation */#define PCI_IO_OFFSET	    0#define PCI_MEM_OFFSET	    0#define PCI_MEMIO_OFFSET    0/* Interrupt enable/disable */#define INTERRUPT_BASE	0x20#define IVEC(i)		INUM_TO_IVEC ((int) ((i) + INTERRUPT_BASE))#define INT_CONNECT(intNo, func, param) \    pciIntConnect (IVEC (intNo), (VOIDFUNCPTR) func, (int) param)#define INT_DISCONNECT(intNo, func, param) \    pciIntDisconnect (IVEC (intNo), (VOIDFUNCPTR) func)#define INT_ENABLE(i)	sysIntEnablePIC (i)#define INT_DISABLE(i)	sysIntDisablePIC (i)/* Unknown platform */#else#error	"Unknown platform.  Must create platform mapping in usbPciLib.c."#endif	/* #if CPU == xxxx *//* more includes */#include "usb/usbPlatform.h"		/* Basic definitions */#include "usb/usbPciLib.h"	    /* Our API *//* defines *//* Map I/O functions to underlying system functions. */#define OUR_PCI_IN_BYTE(a)	sysInByte ((a) + PCI_IO_OFFSET)#define OUR_PCI_IN_WORD(a)	sysInWord ((a) + PCI_IO_OFFSET)#define OUR_PCI_IN_DWORD(a)	sysInLong ((a) + PCI_IO_OFFSET)#define OUR_PCI_OUT_BYTE(a,v)	sysOutByte ((a) + PCI_IO_OFFSET, (v))#define OUR_PCI_OUT_WORD(a,v)	sysOutWord ((a) + PCI_IO_OFFSET, (v))#define OUR_PCI_OUT_DWORD(a,v)	sysOutLong ((a) + PCI_IO_OFFSET, (v))/* code tracks usage count for interrupts 0..MAX_INT_NO-1. */#define MAX_INT_NO		16/* locals */LOCAL UINT16 intUsage [MAX_INT_NO] = {0};/***************************************************************************** usbPciClassFind - Locates PCI devices by class.** A caller uses this function to locate a PCI device by its PCI class.* The caller must specify the <pciClass>, <subClass>, and <pgmIf> for the* device being sought.	The function returns the first matching device* for <index> = 0, the second for <index> = 1, and so forth.  The* bus number, device number, and function number for the matching device * are returned in the <pBusNo>, <pDeviceNo>, and <pFuncNo> buffers provided * by the caller. *** RETURNS: TRUE if matching device found, FALSE if device not found.*/BOOL usbPciClassFind    (    UINT8 pciClass,		/* PCI device class */    UINT8 subClass,		/* PCI device sub-class */    UINT8 pgmIf,		/* Programming interface */    UINT16 index,		/* Caller wants nth matching dev */    pUINT8 pBusNo,		/* Bus number of matching dev */    pUINT8 pDeviceNo,		/* Device number of matching dev */    pUINT8 pFuncNo		/* Function number of matching dev */    )    {    int intBusNo;		/* VxWorks returns "int" values */    int intDeviceNo;    int intFuncNo;        /* Use the VxWorks PCI config. library to find a device within the    specified class. */    if (pciFindClass ((pciClass << 16) | (subClass << 8) | pgmIf, index,	&intBusNo, &intDeviceNo, &intFuncNo) != OK)	{	return FALSE;	}    else	{	if (pBusNo) *pBusNo = (UINT8) intBusNo;	if (pDeviceNo) *pDeviceNo = (UINT8) intDeviceNo;	if (pFuncNo) *pFuncNo = (UINT8) intFuncNo;	}    return TRUE;    }/***************************************************************************** usbPciByteGet - Returns a UINT8 configuration value** This function returns the UINT8 value at offset <regOffset> from * the PCI configuration space of the device identified by <busNo>, * <deviceNo>, and <funcNo>.** RETURNS: UINT8 value read from device configuration space*/UINT8 usbPciByteGet     (    UINT8 busNo,		/* Bus number of device */    UINT8 deviceNo,		/* Device number of device */    UINT8 funcNo,		/* Function number of device */    UINT16 regOffset		/* Offset into PCI config space */    )    {    UINT8 value;    if (pciConfigInByte (busNo, deviceNo, funcNo, regOffset, &value) != OK)	return 0;    return value;    }/***************************************************************************** usbPciWordGet - Returns a UINT16 configuration value** This function returns the UINT16 value at offset <regOffset> from * the PCI configuration space of the device identified by <busNo>, * <deviceNo>, and <funcNo>.** NOTE: This function adjusts for big vs. little endian environments.** RETURNS: UINT16 value read from device configuration space*/UINT32 usbPciWordGet    (    UINT8 busNo,		/* Bus number of device */    UINT8 deviceNo,		/* Device number of device */    UINT8 funcNo,		/* Function number of device */    UINT16 regOffset		/* Offset into PCI config space */    )    {    UINT16 value;    if (pciConfigInWord (busNo, deviceNo, funcNo, regOffset, &value) != OK)	return 0;    return value;    }/***************************************************************************** usbPciDwordGet - Returns a UINT32 configuration value** This function returns the UINT32 value at offset <regOffset> from * the PCI configuration space of the device identified by <busNo>, * <deviceNo>, and <funcNo>.** NOTE: This function adjusts for big vs. little endian environments.** RETURNS: UINT32 value read from device configuration space*/UINT32 usbPciDwordGet    (    UINT8 busNo,		/* Bus number of device */    UINT8 deviceNo,		/* Device number of device */    UINT8 funcNo,		/* Function number of device */    UINT16 regOffset		/* Offset into PCI config space */    )    {    UINT32 value;    if (pciConfigInLong (busNo, deviceNo, funcNo, regOffset, &value) != OK)	return 0;    return value;    }/***************************************************************************** usbPciConfigHeaderGet - Reads a device's PCI configuration header** This function reads the PCI configuration header for the device* identified by <busNo>, <deviceNo>, and <funcNo>.  The configuration* header is stored in the <pCfgHdr> buffer provided by the caller.** This function initializes the <pCfgHdr> structure to zeros.  Any * fields which cannot be read from the device's configuration header * will remain zero upon return.	 This function does not attempt to read* fields defined as "reserved" in the PCI configuration header.** RETURNS: N/A*/VOID usbPciConfigHeaderGet    (    UINT8 busNo,		/* Bus number of device */    UINT8 deviceNo,		/* Device number of device */    UINT8 funcNo,		/* Function number of device */    pPCI_CFG_HEADER pCfgHdr	/* Buffer provided by caller */    )    {    int i;    /* Do nothing if CfgHdr is NULL */    if (pCfgHdr == NULL)	return;    /* Initialize the buffer to zeros. */    memset (pCfgHdr, 0, sizeof (*pCfgHdr));    /* Read and store each field in the PCI configuration header. */    pCfgHdr->vendorId	= usbPciWordGet (busNo, deviceNo, funcNo, PCI_CFG_VENDOR_ID);    pCfgHdr->deviceId	= usbPciWordGet (busNo, deviceNo, funcNo, PCI_CFG_DEVICE_ID);    pCfgHdr->command	= usbPciWordGet (busNo, deviceNo, funcNo, PCI_CFG_COMMAND);    pCfgHdr->status	= usbPciWordGet (busNo, deviceNo, funcNo, PCI_CFG_STATUS);    pCfgHdr->revisionId = usbPciByteGet (busNo, deviceNo, funcNo, PCI_CFG_REVISION);    pCfgHdr->pgmIf	= usbPciByteGet (busNo, deviceNo, funcNo, PCI_CFG_PROGRAMMING_IF);

⌨️ 快捷键说明

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