www.pudn.com > MPC8241BSP.rar > pciAddrAlloc.c


#include "vxWorks.h" 
#include "logLib.h" 
#include "taskLib.h" 
#include "string.h" 
#include "dllLib.h" 
#include "config.h" 
 
#include "drv/pci/pciConfigLib.h" 
#if 0 
#include "drv/pci/pciAutoConfigLib.h" 
#else 
#include "./pci/pciAutoConfigLib.h" 
#endif 
 
    	 
STATUS pciDeviceAddrAlloc 
	( 
    OTHER_DEVICE * pci9030,      /*must be &otherdev*/ 
    UINT size,                   /*size you want to alloc*/ 
    UINT baseAddr,               /*base-address register address */ 
    UINT devicenum               /*device number*/ 
    ) 
   { 
    UINT addr; 
    UINT baseaddr_mask; 
    UINT * pBase; 
    UINT * pAvail; 
        UINT32 alignedBase; 
    UINT32 sizeAdj; 
    STATUS retStat = ERROR; 
     
	/*logMsg("pciAutoMemAlloc: PF Mem requested" 
		"\n", 0, 0, 0, 0, 0, 0);*/ 
 
	pBase = &(pci9030->pciMem32); 
	pAvail = &(pci9030->pciMem32Size); 
 
	if (*pAvail > 0) 
	    { 
	    retStat = pciAutoAddrAlign (*pBase, 
					(*pBase + *pAvail), 
					size, 
					&alignedBase); 
	    } 
 
	if (retStat == ERROR) 
	    { 
 
	    /* If no PF memory available, then try conventional */ 
		 
	    /*logMsg("pciAutoMemAlloc: No PF Mem available" 
		    "Trying MemIO\n", 0, 0, 0, 0, 0, 0);*/ 
		    return ERROR; 
 
	    } 
	   /* PCI_AUTO_DEBUG_MSG("pciAutoMemAlloc: \n", 0, 0, 0, 0, 0, 0); 
    PCI_AUTO_DEBUG_MSG("  Pre: pBase[0x%08x], pAvail[0x%08x]\n", 
	    (int)(*pBase), (int)(*pAvail), 0, 0, 0, 0);*/ 
 
    addr  = alignedBase; 
    sizeAdj = (alignedBase - *pBase) + size; 
    *pBase  += sizeAdj; 
    *pAvail -= sizeAdj; 
 
  /* PCI_AUTO_DEBUG_MSG("pciAutoRegConfig:[0x%08x] written to BAR[0x%08x]\n", 
		addr, baseAddr, 0, 0, 0, 0); 
    PCI_AUTO_DEBUG_MSG("  Post: pBase[0x%08x], pAvail[0x%08x]\n", 
	    (int)(*pBase), (int)(*pAvail), 0, 0, 0, 0);*/ 
 
   baseaddr_mask = 0xFFFFFFF0; 
   pciConfigModifyLong (0, devicenum,  
				0, baseAddr,  
				baseaddr_mask, addr); 
        return OK; 
   	} 
   	 
/* move by zoutl 2003-3-14 10:21 */   	 
STATUS pciAddrAlloc( 
    UINT size,                   /*size you want to alloc*/ 
    UINT offset,               /*base-address register address */ 
    UINT devicenum               /*device number*/ 
    ) 
    { 
        if(pciDeviceAddrAlloc(&otherdev,size,offset,devicenum)==OK) 
            return OK; 
        else 
            return ERROR; 
    	}