|
/* surfConfPciDevice.c */
/*
* 函数功能:
***********
* 已知该类PCI设备的Vendor号,Device号和索引号myIndex,查找出该类PCI设备的MEMORY地址
* 和IO地址,以及中断级,并添加第一个MEMORY的物理地址到虚拟地址的映射。
*
* 调用实例:
***********
* 如果有4块该类PCI设备,则调用四次函数,索引号从0~3,如下:
for (myIndex=0; myIndex<4; myIndex++)
{
myStatus = surfConfPciDevice(vendorId, devId, myIndex);
}
*/
/*
modification history
--------------------
21aug03,ghb 添加函数功能及调用说明。
*/
#include <vxWorks.h>
#include <stdio.h>
#include <sysLib.h>
#include <stdlib.h>
#include <config.h>
#include <drv/pci/pciConfigLib.h>
#include <vmLib.h>
#ifndef PCI_DEV_MMU_MSK
#define PCI_DEV_MMU_MSK (~(VM_PAGE_SIZE - 1)) /* Mask MMU page */
#endif /* PCI_DEV_MMU_MSK */
/* 外部函数原型 */
extern STATUS sysMmuMapAdd
(
void * address,
UINT length,
UINT initialStateMask,
UINT initialState
);
/**********************************************************************************
* surfConfPciDevice
*
* 已知该类PCI设备的Vendor号,Device号和索引号myIndex,查找出该类PCI设备的MEMORY地址
* 和IO地址,以及中断级,并添加第一个MEMORY的物理地址到虚拟地址的映射。
*
* Parameter:
* vendorId:该类PCI设备的Vendor号
* devId:该类PCI设备的Device号
* myIndex:该类PCI设备的索引号
*
* Return:
* OK:查找并映射成功
* ERROR: 查找或映射不成功
*
*/
STATUS surfConfPciDevice(int vendorId, int devId, int myIndex)
{
int busno, devno, funcno;
int membaseCsr0, membaseCsr1, iobaseCsr;
unsigned char irq;
STATUS myStatus;
/* 查找PCI设备 */
myStatus = pciFindDevice(vendorId, devId, myIndex,
(int *)&busno, (int *)&devno, (int *)&funcno);
if (myStatus == OK) /* 找到该类PCI设备 */
{
pciConfigInLong (busno, devno, funcno, PCI_CFG_BASE_ADDRESS_0, &membaseCsr0);
pciConfigInLong (busno, devno, funcno, PCI_CFG_BASE_ADDRESS_1, &membaseCsr1);
pciConfigInLong (busno, devno, funcno, PCI_CFG_BASE_ADDRESS_2, &iobaseCsr);
/* pciConfigInByte (busno, devno, funcno, PCI_CFG_DEV_INT_LINE, &irq);*/
membaseCsr0 = membaseCsr0 & (~0x0000000f)/*PCI_MEMBASE_MASK*/;
membaseCsr1 = membaseCsr1 & (~0x0000000f)/*PCI_MEMBASE_MASK*/;
/* iobaseCsr = iobaseCsr & PCI_IOBASE_MASK;*/
printf("\nbusno=%d, devno=%d, funcno=%d, membaseCsr0=%x, membaseCsr1=%x, iobaseCsr=%d\n",
busno, devno, funcno, membaseCsr0, membaseCsr1, iobaseCsr);
#ifdef INCLUDE_MMU_BASIC
if (sysMmuMapAdd((void *)(membaseCsr0 & PCI_DEV_MMU_MSK), 0x200000,
VM_STATE_MASK_VALID | VM_STATE_MASK_WRITABLE |
VM_STATE_MASK_CACHEABLE,
VM_STATE_VALID | VM_STATE_WRITABLE |
VM_STATE_CACHEABLE_NOT) == ERROR)
{
printf("\nGHB_VRAM error\n");
return ERROR;
};
#endif /* INCLUDE_MMU_BASIC */
/* 最后一个参数' | PCI_CMD_MASTER_ENABLE'好像可有可无,没有影响 */
pciConfigOutWord (busno, devno, funcno,
PCI_CFG_COMMAND, PCI_CMD_IO_ENABLE |
PCI_CMD_MEM_ENABLE | PCI_CMD_MASTER_ENABLE);
return OK;
}
else
{
printf("\nFind VRAM device error\n");
return ERROR;
}
}