📄 syspci.c
字号:
/* sysPci.c - Wind River SBC8240/8245 PCI support *//* Copyright 1984-2001 Wind River Systems, Inc. All Rights Reserved *//*modification history--------------------01a,07sep01,g_h (based on version 01b, of ppmc750/sysBusPci.c).*//*DESCRIPTIONThis module contains the "non-generic" or "board specific" PCI-PCIbridge code.*//* includes */#include "vxWorks.h"#include "logLib.h"#include "taskLib.h"#include "config.h"#ifdef INCLUDE_PCI/* include */#include "drv/pci/pciConfigLib.h"#include "pci/pciConfigLib.c" /* PCI config space access */#ifdef INCLUDE_SHOW_ROUTINES#include "pci/pciConfigShow.c" /* display of PCI config space */#endif /* INCLUDE_SHOW_ROUTINES *//* defines *//* typedefs *//* local */LOCAL ULONG sysPciConfAddr = PCI8240_PRIMARY_CAR;LOCAL ULONG sysPciConfData = PCI8240_PRIMARY_CDR;/* forward declarations */LOCAL ULONG sys824xRegRead (ULONG regNum);LOCAL void sys824xRegWrite (ULONG offset, ULONG data, int width);LOCAL STATUS sysPciSpecialCycle (int busNo, UINT32 message);LOCAL STATUS sysPciConfigRead (int busNo, int deviceNo, int funcNo, int offset, int width, void * pData);LOCAL STATUS sysPciConfigWrite (int busNo, int deviceNo, int funcNo, int offset, int width, ULONG data);STATUS sysPciInit (void);/************************************************************************* sys824xRegRead - read a 32-bit address MPC8240 CI register** Read a 32-bit address MPC8240/8245 PCI register and returns* a 32 bit value.** RETURNS: The contents of the specified MPC8240/8245 PCI register.** SEE ALSO: sys824xRegWrite()*/LOCAL ULONG sys824xRegRead ( ULONG regNum ) { ULONG temp; PCI_OUT_LONG (sysPciConfAddr, pciConfigBdfPack (0, 0, 0) | (regNum & 0xfc) | 0x80000000); temp = PCI_IN_LONG (sysPciConfData); return temp; }/************************************************************************* sys824xRegWrite - write a 32-bit MPC8240/8245 PCI register** write a 32-bit address MPC8240/8245 PCI register.** RETURNS: N/A** SEE ALSO: sys824xRegRead()*/LOCAL void sys824xRegWrite ( ULONG offset, ULONG data, int width /* width to write */ ) { switch (width) { case 1: /* byte */ PCI_OUT_LONG (sysPciConfAddr, pciConfigBdfPack (0, 0, 0) | (offset & 0xfc) | 0x80000000); PCI_OUT_BYTE ((sysPciConfData + (offset & 0x3)), data); break; case 2: /* word */ PCI_OUT_LONG (sysPciConfAddr, pciConfigBdfPack (0, 0, 0) | (offset & 0xfc) | 0x80000000); PCI_OUT_WORD ((sysPciConfData + (offset & 0x2)), data); break; case 4: /* long */ PCI_OUT_LONG (sysPciConfAddr, pciConfigBdfPack (0, 0, 0) | (offset & 0xfc) | 0x80000000); PCI_OUT_LONG (sysPciConfData, data); break; default: return; } }/************************************************************************* sysPciSpecialCycle - generate a special cycle with a message** This routine generates a special cycle with a message.** NOMANUAL** RETURNS: OK*/LOCAL STATUS sysPciSpecialCycle ( int busNo, UINT32 message ) { int deviceNo = 0x0000001f; int funcNo = 0x00000007; PCI_OUT_LONG (sysPciConfAddr, pciConfigBdfPack (busNo, deviceNo, funcNo) | 0x80000000); PCI_OUT_LONG (sysPciConfData, message); return (OK); }/************************************************************************* sysPciConfigRead - read from the PCI configuration space** This routine reads either a byte, word or a long word specified by* the argument <width>, from the PCI configuration space* This routine works around a problem in the hardware which hangs* PCI bus if device no 12 is accessed from the PCI configuration space.** RETURNS: OK, or ERROR if this library is not initialized** SEE ALSO: sysPciConfigWrite()*/LOCAL STATUS sysPciConfigRead ( int busNo, /* bus number */ int deviceNo, /* device number */ int funcNo, /* function number */ int offset, /* offset into the configuration space */ int width, /* width to be read */ void * pData /* data read from the offset */ ) { UINT8 retValByte = 0; UINT16 retValWord = 0; UINT32 retValLong = 0; STATUS retStat = ERROR; ULONG tmp; if ((busNo == 0) && (deviceNo == 12)) return (ERROR); tmp = sys824xRegRead (0xc0); sys824xRegWrite (0xc0,0,4); switch (width) { case 1: /* byte */ PCI_OUT_LONG (sysPciConfAddr, pciConfigBdfPack (busNo, deviceNo, funcNo) | (offset & 0xfc) | 0x80000000); retValByte = PCI_IN_BYTE (sysPciConfData + (offset & 0x3)); *((UINT8 *)pData) = retValByte; retStat = OK; break; case 2: /* word */ PCI_OUT_LONG (sysPciConfAddr, pciConfigBdfPack (busNo, deviceNo, funcNo) | (offset & 0xfc) | 0x80000000); retValWord = PCI_IN_WORD (sysPciConfData + (offset & 0x2)); *((UINT16 *)pData) = retValWord; retStat = OK; break; case 4: /* long */ PCI_OUT_LONG (sysPciConfAddr, pciConfigBdfPack (busNo, deviceNo, funcNo) | (offset & 0xfc) | 0x80000000); retValLong = PCI_IN_LONG (sysPciConfData); *((UINT32 *)pData) = retValLong; retStat = OK; break; default: retStat = ERROR; break; } sys824xRegWrite (0xc1,0xff,1); sys824xRegWrite (0xc5,0xff,1); sys824xRegWrite (0x06,0xff00,2); sys824xRegWrite (0xc0,tmp,1); return retStat; }/************************************************************************* sysPciConfigWrite - write to the PCI configuration space** This routine writes either a byte, word or a long word specified by* the argument <width>, to the PCI configuration space* This routine works around a problem in the hardware which hangs* PCI bus if device no 12 is accessed from the PCI configuration space.** RETURNS: OK, or ERROR if this library is not initialized** SEE ALSO: sysPciConfigRead()*/LOCAL STATUS sysPciConfigWrite ( int busNo, /* bus number */ int deviceNo, /* device number */ int funcNo, /* function number */ int offset, /* offset into the configuration space */ int width, /* width to write */ ULONG data /* data to write */ ) { if ((busNo == 0) && (deviceNo == 12)) return (ERROR); switch (width) { case 1: /* byte */ PCI_OUT_LONG (sysPciConfAddr, pciConfigBdfPack (busNo, deviceNo, funcNo) | (offset & 0xfc) | 0x80000000); PCI_OUT_BYTE ((sysPciConfData + (offset & 0x3)), data); break; case 2: /* word */ PCI_OUT_LONG (sysPciConfAddr, pciConfigBdfPack (busNo, deviceNo, funcNo) | (offset & 0xfc) | 0x80000000); PCI_OUT_WORD ((sysPciConfData + (offset & 0x2)), data); break; case 4: /* long */ PCI_OUT_LONG (sysPciConfAddr, pciConfigBdfPack (busNo, deviceNo, funcNo) | (offset & 0xfc) | 0x80000000); PCI_OUT_LONG (sysPciConfData, data); break; default: return (ERROR); } return (OK); }/************************************************************************* sysPciInit - PCI Configuration Library Initialization* * This routine initialize the PCI configuration library.** RETURNS: None*/STATUS sysPciInit ( void ) { STATUS retVal; retVal = pciConfigLibInit (PCI_MECHANISM_0, (ULONG) sysPciConfigRead, (ULONG) sysPciConfigWrite, (ULONG) sysPciSpecialCycle); return retVal; }#endif /* INCLUDE_PCI */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -