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

📄 tyspci.c

📁 vxworks下面的pci初始化函数的所有的重构
💻 C
📖 第 1 页 / 共 5 页
字号:
	    printf("pciAutoFuncConfig: MemSpace found at BAR[%d]\n",
		    baI);
	    sizeMask = (1 << 4);	    }	/* Loop until we find a bit set or until we run out of bits */	for (; sizeMask; sizeMask <<= 1)	    {	    /* is this bit set? if not, keep looking */	    if (readVar & sizeMask)		{		baI += tysAutoRegConfig (pSystem, pPciFunc, baseAddr, sizeMask,
					addrInfo);		break;		}	    }	}    }













LOCAL void tysAutoDevConfig
    (    PCI_SYSTEM * pSystem,  /* PCI system info */    UINT bus,		/* Current bus number	   */    PCI_LOC **ppPciList,	/* Pointer to function list */    UINT *nSize		/* Number of remaining funcs */    )    {    PCI_LOC *pPciFunc;	/* Pointer to PCI function	   */    UINT nextBus;		/* Bus where function is located   */    short pciClass;		/* Class field of function	   */    /* Process each function within the list */    while (*nSize > 0)	{	/* Setup local variables */	pPciFunc = *ppPciList;	nextBus = pPciFunc->bus;	/* Decrease recursion depth if this function is on a parent bus */	if (nextBus < bus)	    {	    return;	    }	/* Allocate and assign space to functions on this bus */	tysAutoFuncConfig (pSystem, pPciFunc);
	(*nSize)--;	(*ppPciList)++;	/* Increase recursion depth if this function is a PCI-PCI bridge */	pciConfigInWord (pPciFunc->bus, pPciFunc->device, pPciFunc->function,			 PCI_CFG_SUBCLASS, &pciClass);

	  printf("in the sysautodevconfig pciClass=0x%x\n",pciClass);
	switch (pciClass)	    {	    case (( PCI_CLASS_BRIDGE_CTLR << 8) + PCI_SUBCLASS_P2P_BRIDGE ):		/* PCI-PCI bridge functions increase recursion depth */		tysAutoBusConfig (pSystem, pPciFunc, ppPciList, nSize);
		break;	    default:		/* Maintain current recursion depth */		break;	    }	}    }



LOCAL UINT tysAutoBusProbe
    (    PCI_SYSTEM * pSystem,	/* PCI system information	*/    UINT priBus,		/* Primary PCI bus		*/    UINT secBus,		/* Secondary PCI bus		*/    PCI_LOC*  pPciLoc,	/* PCI address of this bridge	*/    PCI_LOC** ppPciList,	/* Pointer to next PCI location	*/				/* entry pointer		*/    int * pListSize		/* number of PCI_LOC entries    */    )    {    UINT subBus = 0xff;	/* Highest subordinate PCI bus	*/    UCHAR offset = 0;   /* Interrupt routing offset for this bus*/    /* Disable I/O, Mem, and upstream transactions / reset status bits */    pciAutoDevReset (pPciLoc);    /* Set the bus numbers, subordinate bus is 0xff */    tysAutoBusNumberSet (pPciLoc, priBus, secBus, 0xff);
    printf("pciAutoBusProbe: using bridge [%d,%d,%d,0x%02x]\n",
		pPciLoc->bus,
		pPciLoc->device,
		pPciLoc->function,
		pPciLoc->attribute
		);
    /* Probe all devices on this bus */    printf("pciAutoBusProbe: calling pciAutoDevProbe on bus [%d]\n",
	    secBus);
    /*     * compute the route offset for this bridge: if this is the      * first Pci-To-Pci Bridge to be discovered, then its contribution     * is null, otherwise it depends on its location on the bus and     * on the contribution of all of the upper Pci-To-Pci Bridges.     */    pPciLoc->offset += (secBus > 1) ? (pPciLoc->device % 4) : 0;    offset = pPciLoc->offset;    printf("pciAutoBusProbe: int route offset for bridge is [%d]\n",
              offset);
    subBus = tysAutoDevProbe (pSystem, secBus, offset, (pPciLoc->attribute),
	    ppPciList, pListSize);    /* Set the range assignment to cover the correct range of busses */    printf("pciAutoBusProbe: post-config subordinate bus as [%d]\n",
		    subBus);
    tysAutoBusNumberSet (pPciLoc, priBus, secBus, subBus);
    /* Return the highest subordinate bus */    return subBus;    }




LOCAL UINT tysAutoDevProbe
    (    PCI_SYSTEM * pSystem,	/* PCI system info			*/    UINT bus,			/* current bus number to probe		*/    UCHAR offset,		/* bridge contrib to int vector xlation */    UCHAR inheritAttrib,	/* attributes inherited from bridge 	*/    PCI_LOC **ppPciList,	/* Pointer to next PCI location entry	*/    int * pListSize		/* Number of PCI_LOC's currently in list*/    )    {    PCI_LOC pciLoc;		/* PCI bus/device/function structure	*/    short pciclass;		/* PCI class/subclass contents		*/    UINT dev_vend;		/* Device/Vendor identifier		*/    int device;			/* Device location			*/    int function;		/* Function location			*/    int subBus;			/* Highest subordinate PCI bus		*/    UCHAR btemp;		/* Temporary holding area		*/    /* Initialize variables */    bzero ((char *)&pciLoc, sizeof (PCI_LOC));    pciLoc.bus = bus;    subBus = bus;    /* if attributes indicate a host bus, then set equal to pciLoc.attrib */    /* Locate each active function on the current bus */    for (device = 0; device < PCI_MAX_DEV; device++)	{	pciLoc.device = device;	/* Check each function until an unused one is detected */	for (function = 0; function < PCI_MAX_FUNC; function++)	    {	    pciLoc.function = function;	    /* Check for a valid device/vendor number */	    pciConfigInLong (pciLoc.bus, pciLoc.device, pciLoc.function,			     PCI_CFG_VENDOR_ID, &dev_vend);                 
	    /* If function 0 then check next dev else check next function */	    if ( ((dev_vend & 0x0000ffff) == tys_CONFIG_ABSENT_F) || 
		 ((dev_vend & 0x0000ffff) == tys_CONFIG_ABSENT_0) )
		{		if (function == 0)		    {		    break;	/* non-existent device, goto next device */		    }		else		    {		    continue;  /* function empty, try the next function */		    }		}            /* store the translation offset for the int routing */            pciLoc.offset = offset;	    pciLoc.attribute = 0;	    /* Check to see if this function belongs to a PCI-PCI bridge */	    pciConfigInWord (pciLoc.bus, pciLoc.device, pciLoc.function,	                     PCI_CFG_SUBCLASS, &pciclass);                printf("PCI_CFG_SUBCLASS=0x%x\n",pciclass);
	    /* Set Bridge device attributes for this device */	    switch(pciclass) 		{		/* PCI Host Bridge */		case ((PCI_CLASS_BRIDGE_CTLR << 8) + PCI_SUBCLASS_HOST_PCI_BRIDGE):		    pciLoc.attribute |= ( PCI_AUTO_ATTR_DEV_EXCLUDE |					  PCI_AUTO_ATTR_BUS_HOST );
			   printf("this is the bridge!\n");
		    break;		/* ISA Bridge */		case ((PCI_CLASS_BRIDGE_CTLR << 8) + PCI_SUBCLASS_ISA_BRIDGE):		    pciLoc.attribute |= PCI_AUTO_ATTR_BUS_ISA;		    break;		/* Display Device */		case (PCI_CLASS_DISPLAY_CTLR << 8):		    pciLoc.attribute |= PCI_AUTO_ATTR_DEV_DISPLAY;		    break;		/* PCI-to-PCI Bridge */		case ((PCI_CLASS_BRIDGE_CTLR << 8) + PCI_SUBCLASS_P2P_BRIDGE):		    /* Setup and probe this bridge device */		    pciLoc.attribute |= PCI_AUTO_ATTR_BUS_PCI;		    /* Check for 32 bit I/O addressability */		    pciConfigInByte (pciLoc.bus, pciLoc.device, pciLoc.function,				     PCI_CFG_IO_BASE, &btemp);		    if ((btemp & 0x0F) == 0x01)			{			pciConfigInByte (pciLoc.bus, 					 pciLoc.device, pciLoc.function,					 PCI_CFG_IO_LIMIT, &btemp);			if ((btemp & 0x0F) == 0x01)			    {			    pciLoc.attribute |= PCI_AUTO_ATTR_BUS_4GB_IO;			    printf("pciAutoDevProbe: br 4GB I/O \n");
			    }			}		    break;		default:		    /* Mask off all but bus attribute bits to inherit */		    inheritAttrib &=   ( PCI_AUTO_ATTR_BUS_4GB_IO |					 PCI_AUTO_ATTR_BUS_PREFETCH );		    /* devices inherit bus attributes from their bridge */		    pciLoc.attribute |= inheritAttrib;		    break;	    }	    /* Add this function to the PCI function list */	    if (*pListSize < PCI_AUTO_MAX_FUNCTIONS)		{		memcpy (*ppPciList, &pciLoc, sizeof (PCI_LOC));		(*ppPciList)++;		(*pListSize)++;		}	    /* If the device is a PCI-to-PCI bridge, then scan behind it */	    if (pciLoc.attribute & PCI_AUTO_ATTR_BUS_PCI)		{		printf("pciAutoDevProbe: scanning bus[%d]\n",
		    (subBus+1));
		subBus = tysAutoBusProbe (pSystem, bus, subBus+1, &pciLoc,
					    ppPciList, pListSize);		}	    /* Proceed to next device if this is a single function device */	    if (function == 0)		{		pciConfigInByte (pciLoc.bus, pciLoc.device, pciLoc.function,				 PCI_CFG_HEADER_TYPE, &btemp);
               printf("in the tysautodevpro func btemp=0x%x",btemp);
		
		if ((btemp & PCI_HEADER_MULTI_FUNC) == 0)		    {		    break; /* No more functions - proceed to next PCI device */		    }		}	    }	}    return (subBus);    }


LOCAL void tysAutoFuncConfigAll
    (    PCI_SYSTEM * pSystem,	/* PCI system info */    PCI_LOC *pPciList,		/* input: Pointer to first function   */    UINT nSize			/* input: Number of functions to init */    )    {    PCI_LOC *pPciFunc;		/* Pointer to next function */    UINT nLoop;			/* Loop control variable    */    UINT nEnd;			/* End of function list     */    /* Disable all devices before we initialize any */    /* Allocate and assign PCI space to each device */    pPciFunc = pPciList;    nEnd = nSize;   tysAutoDevConfig (pSystem, pPciList->bus, &pPciFunc, &nEnd);
    /* Enable each device on the device list */    pPciFunc = pPciList;    for (nLoop = 0; nLoop < nSize; nLoop++)        {        tysAutoFuncEnable (pSystem, pPciFunc);
        pPciFunc++;        }    }

LOCAL PCI_LOC * tysAutoListCreate
    (    PCI_SYSTEM * pSystem,    int *pListSize    )    {    PCI_LOC  pciLoc;		/* PCI bus/device/function structure */    PCI_LOC *pPciList;    PCI_LOC *pRetPciList;   /* Initialize the list pointer in preparation for probing */#if defined(PCI_AUTO_STATIC_LIST)    pPciList = pciAutoLocalFuncList;    pRetPciList = pPciList;#else    pPciList = malloc(sizeof(PCI_LOC) *  PCI_AUTO_MAX_FUNCTIONS);    if (pPciList == NULL)	{	return NULL;	}    pRetPciList = pPciList;#endif    lastPciListSize = 0;    *pListSize = 0;    /* Begin the scanning process at [0,0,0] */    pciLoc.bus = (UINT8)0;    pciLoc.device = (UINT8)0;    pciLoc.function = (UINT8)0;    /*     * Note that the host bridge is assumed to support 32-bit I/O addressing     * (PCI_AUTO_ATTR_BUS_4GB_IO) and prefetchable memory     * (PCI_AUTO_ATTR_BUS_PREFETCH)     */    tysMaxBus = tysAutoDevProbe (pSystem, pciLoc.bus, (UCHAR)0,
				(UCHAR)( PCI_AUTO_ATTR_BUS_4GB_IO |					 PCI_AUTO_ATTR_BUS_PREFETCH),				 &pPciList, pListSize);    pSystem->maxBus = tysMaxBus;
    return (pRetPciList);    }


void tysAutoConfig
    (    PCI_SYSTEM * pSystem	/* PCI system to configure */    )    {    PCI_LOC* pPciList;		/* Pointer to PCI include list	*/    int listSize;		/* Size of PCI include list	*/    /* Input parameter sanity checking */    if (pSystem == NULL)	{	return;	}    /*     * Probe all PCI busses dynamically creating a function list     * of all functions found. Excluded devices are skipped over.     */    pPciList = tysAutoListCreate (pSystem, &listSize);
   tysAutoFuncConfigAll (pSystem, pPciList, listSize);
    lastPciListSize = listSize;    pLastPciList = pPciList;        /* If the function list is malloc'ed at runtime, then release it */#if defined(PCI_AUTO_RECLAIM_LIST)#   if defined(PCI_AUTO_STATIC_LIST)#       error "Can't do PCI_AUTO_RECLAIM_LIST with PCI_AUTO_STATIC_LIST"#   endif    free(pPciList);    lastPciListSize = 0;    pLastPciList = NULL;#endif    }


void tysconfig (void)
{
sysParams.pciMem32 		= PCI_MEM_ADRS;    
sysParams.pciMem32Size 	= PCI_MEM_SIZE;

 sysParams.pciMemIo32 	= PCI_MEMIO_ADRS;    
 sysParams.pciMemIo32Size 	= PCI_MEMIO_SIZE;

 sysParams.pciIo32 		= PCI_IO_ADRS;    
 sysParams.pciIo32Size 	= PCI_IO_SIZE;

sysParams.maxBus 		= 0;   
sysParams.cacheSize 	= ( _CACHE_ALIGN_SIZE / 4 );   
sysParams.maxLatency 	= PCI_LAT_TIMER;

sysParams.autoIntRouting 	= TRUE;    /* Device inclusion and interrupt routing routines */   
sysParams.includeRtn 	= sysPciAutoconfigInclude;   
sysParams.intAssignRtn 	= sysPciAutoconfigIntrAssign;


sysParams.bridgePreConfigInit =			sysPciAutoconfigPreEnumBridgeInit;    
sysParams.bridgePostConfigInit =			sysPciAutoconfigPostEnumBridgeInit;


tysAutoConfig (&sysParams);


printf("tysconfig end \n");

}


 void root(void)
 {
 	
 	  STATUS result;      
	  UINT32 immrVal = (UINT32)vxImmrGet();
          unsigned  char temp;
          UINT8 temp8;
          UINT16 temp16; 
          UINT32 temp32;
		  
         UINT32 readresult;


⌨️ 快捷键说明

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