?? syspci.c
字號:
/* sysPci.c - pxa270 PCI autoconfig support *//* Copyright 2002 Wind River Systems, Inc. All Rights Reserved *//*modification history--------------------01a,21may02,scm written.*//* TODO - Fill in this file with I/O addresses and related constants for the pxa270 BSP. Anything with "pxa270" as a prefix needs to examined and re-named to id the BSP (i.e. iq80321, iq80310, etc.) *//*DESCRIPTIONThis module contains the "non-generic" or "board specific" PCI-PCIbridge initialization code.*//* includes */#include "vxWorks.h"#include "config.h"#include "stdio.h"#include "logLib.h"#include "taskLib.h"#include "end.h"#ifdef INCLUDE_PCI/* defines *//* global */IMPORT END_TBL_ENTRY endDevTbl[];END_TBL_ENTRY *pendDevTbl = endDevTbl;/* include */#include "drv/pci/pciConfigLib.h"#include "drv/pci/pciConfigLib.c"#ifdef INCLUDE_SHOW_ROUTINES#include "drv/pci/pciConfigShow.c" /* display of PCI config space */#endiftypedef struct{ UINT32 pciVend; UINT32 pciDevice;}SYS_PCI_IDENT;/* local *//* forward declarations */LOCAL UINT32 sysPciEncode (UINT32 bus, UINT32 dev, UINT32 func);STATUS sysPciCfgWrite (int bus, int dev, int func, int offset, int size, UINT32 data);STATUS sysPciCfgRead (int bus, int dev, int func, int offset, int size, void *data);STATUS sysPciFindDevices (SYS_PCI_IDENT * pDeviceList, int index, int * pBusNo, int * pDeviceNo, UINT16 * pVendorId, UINT16 * pDeviceId);void sysPciInit (void);void sysPciInit2 (void);void sysPciAbortsClear(void);/********************************************************************************* sysPciEncode - encode parameters for the Configuration Address Register** This routine packs three parameters into one integer for accessing the* Configuration Address Register** RETURNS: integer encoded version of bus, device, and function numbers.*/LOCAL UINT32 sysPciEncode ( UINT32 bus, UINT32 dev, UINT32 func ) { if(bus == 0) { return (( 1 << ((dev & 0x1f) + 16)) | ((dev & 0x1f) << 11) | ((func & 7) << 8)); } return (((bus & 0xff) << 16) | ((dev & 0x1f) << 11) | ((func & 7) << 8) | 1); }/********************************************************************************* sysPciCfgWrite - write to one PCI configuration register location of the* specified size (1, 2 or 4 bytes).** This routine writes one PCI configuration space location** RETURNS: OK or ERROR**/STATUS sysPciCfgWrite( int bus, int dev, int func, int offset, int size, UINT32 data ) { volatile UINT32 pciDevice; int lockKey; STATUS rc; unsigned short dus; unsigned char duc;/* * TODO - * supply correct OCCAR & OCCDR reg definitions for pxa270 */ pciDevice = sysPciEncode(bus,dev,func); /* write cfg space data */ switch(size) { case 4: lockKey = intLock(); *((volatile UINT32 *)(pxa270_OCCAR_REG)) = (pciDevice | (offset & ~3)); rc = vxMemProbe ((char *)pxa270_OCCDR_REG, VX_WRITE, 4, (char *)&data); intUnlock(lockKey); break; case 2: dus = (unsigned short)data; lockKey = intLock(); *((volatile UINT32 *)(pxa270_OCCAR_REG)) = (pciDevice | (offset & ~3)); rc = vxMemProbe ((char *)pxa270_OCCDR_REG, VX_WRITE, 2, (char *)&dus); intUnlock(lockKey); break; default: duc = (unsigned char)data; lockKey = intLock(); *((volatile UINT32 *)(pxa270_OCCAR_REG)) = (pciDevice | (offset & ~3)); rc = vxMemProbe ((char *)pxa270_OCCDR_REG, VX_WRITE, 1, (char *)&duc); intUnlock(lockKey); } return rc; }/********************************************************************************* sysPciCfgRead - reads one PCI configuration space register location of the* specified size (1, 2 or 4 bytes).** This routine reads one PCI configuration register location** RETURNS : OK or ERROR*/STATUS sysPciCfgRead( int bus, int dev, int func, int offset, int size, void *data ) { volatile UINT32 pciDevice; int lockKey; STATUS rc;/* * TODO - * supply correct OCCAR & OCCDR reg definitions for pxa270 */ pciDevice = sysPciEncode(bus,dev,func); /* read cfg space data */ switch(size) { case 4: lockKey = intLock(); *((volatile UINT32 *)(pxa270_OCCAR_REG)) = (pciDevice | (offset & ~3)); rc = vxMemProbe ((char *)pxa270_OCCDR_REG, VX_READ, 4, (char *)data); intUnlock(lockKey); break; case 2: lockKey = intLock(); *((volatile UINT32 *)(pxa270_OCCAR_REG)) = (pciDevice | (offset & ~3)); rc = vxMemProbe ((char *)pxa270_OCCDR_REG, VX_READ, 2, (char *)data); intUnlock(lockKey); break; default: lockKey = intLock(); *((volatile UINT32 *)(pxa270_OCCAR_REG)) = (pciDevice | (offset & ~3)); rc = vxMemProbe ((char *)pxa270_OCCDR_REG, VX_READ, 1, (char *)data); intUnlock(lockKey); } return rc;}/********************************************************************************* sysPciFindDevice - find the nth device with the given device & vendor ID** This routine finds the nth device with the given device & vendor ID.** RETURNS:* OK, or ERROR if the deviceId and vendorId didn't match.*/STATUS sysPciFindDevices( SYS_PCI_IDENT * pDeviceList,/* ptr to array vend/device ID */ int index, /* desired instance of device */ int * pBusNo, /* bus number */ int * pDeviceNo, /* device number */ UINT16 * pVendorId, /* vendor ID */ UINT16 * pDeviceId /* device ID */ ) { STATUS status = ERROR; int bus,dev,func=0; UINT32 devId,vendId; SYS_PCI_IDENT * pDev; for(bus = 0; bus < PCI_MAX_BUS; ++bus) { for(dev = 0;dev < PCI_MAX_DEV; ++dev) { pciConfigInLong(bus,dev,func,PCI_CFG_VENDOR_ID,&vendId); if((vendId & 0x0000ffff) != 0x0000FFFF) { devId = (vendId >> 16) & 0xffff; vendId &= 0x0000FFFF; pDev = pDeviceList; while(pDev->pciVend && pDev->pciDevice) { if(vendId == pDev->pciVend && devId == pDev->pciDevice && index-- == 0) { *pBusNo = bus; *pDeviceNo = dev; *pVendorId = (UINT16)vendId; *pDeviceId = (UINT16)devId; return OK; } ++pDev; } } } } return status; }/***************************************************************************** sysPciInit - PCI Configuration LIbrary Initialization*** RETURNS: None** NOMANUAL*/void sysPciInit(void) { /* PCI Configuration Library Initialization MECHANISM_0 */ pciConfigLibInit(PCI_MECHANISM_0,(int)sysPciCfgRead,(int)sysPciCfgWrite,0); return; }/***************************************************************************** sysPciInit2 - Second PCI Initialization*** RETURNS: None** NOMANUAL*/void sysPciInit2(void) { sysPciAbortsClear(); }/***************************************************************************** sysPciAbortsClear - Clear Target Aborts in PCI status Register*** RETURNS: None** NOMANUAL*/void sysPciAbortsClear(void) { UINT32 tmp;/* * TODO - * ATU Status Register -clear, * ATU Interrupt Status Register -clear */ }#endif /* INCLUDE_PCI */
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -