📄 nwatadrv.c
字号:
prdEntry->address = (char *)((unsigned int)(addr) + PCI2DRAM_BASE_ADRS);
numBytes = 0x10000 - ((int)addr & 0xFFFF);
if (numBytes > count) {
prdEntry->bits.count = count;
prdEntry->bits.EOT = 1;
break;
} else {
prdEntry->bits.count = numBytes;
prdEntry->bits.EOT = 0;
}
count -= numBytes;
addr += numBytes;
prdEntry++;
}
#endif
// set the prd list address
//logMsg("the busMasterRegs = %x \n", busMasterRegs[ctrl],2,3,4,5,6);
tempData1 = (unsigned int)((unsigned int)&prdTable[ctrl][0] + PCI2DRAM_BASE_ADRS)& 0xfffffffc;
*((volatile unsigned int *)(busMasterRegs[ctrl] + BM_PRD_ADDR)) = (tempData1 | 0x02);
tempData2 = *((volatile unsigned int *)(busMasterRegs[ctrl] + BM_PRD_ADDR));
//logMsg("the prd tempData1 = %x, tempData2 = %x \n",tempData1,tempData2,3,4,5,6);
// set the read/write control:
if ( dir == O_WRONLY)
rwControl[ctrl] = BM_CR_MASK_WRITE; // ATA Write DMA
else
rwControl[ctrl] = BM_CR_MASK_READ; // ATA Read DMA
return OK;
}
//***********************************************************
//
// ataDmaConfig() - configure/setup for Read/Write DMA
//
// The caller must call this function before attempting
// to use any ATA or ATAPI commands in PCI DMA mode.
//
//***********************************************************
int ataDmaConfig(int ctrl,UINT32 regAddr )
{
// save the address of the bus master (SFF-8038) regs
busMasterRegs[ctrl] = regAddr;
ATA_IO_BYTE_WRITE(busMasterRegs[ctrl]+BM_STATUS_REG,BM_SR_MASK_DRV0 | BM_SR_MASK_INT);
// the bus master must be setup now
// read the BM status reg and save the upper 3 bits.
statReg[ctrl] = ATA_IO_BYTE_READ( busMasterRegs[ctrl] + BM_STATUS_REG );
statReg[ctrl] = statReg[ctrl] & 0xe0;
return 0;
}
/* add by wangb 2005-10-18 14:08 */
unsigned char atpRDByt(UINT32 ioAdrs)
{
UINT8 data;
data = *((volatile UINT8 *)(ioAdrs));
return (data);
}
void atpWRByt(UINT32 ioAdrs, UINT8 byte)
{
*((volatile UINT8 *)(ioAdrs))=byte;
}
void sysInWordString
(
ULONG ioAddr,
UINT16 * bufPtr,
int nWords
)
{
int loopCtr;
for (loopCtr = 0; loopCtr < nWords; loopCtr++)
*bufPtr++ = (*(UINT32 *)ioAddr)&0xffff;
}
void sysOutWordString
(
ULONG ioAddr,
UINT16 * bufPtr,
int nWords
)
{
int loopCtr;
for (loopCtr = 0; loopCtr < nWords; loopCtr++)
*(UINT32 *)ioAddr = *bufPtr++;
}
void sysInLongString(
ULONG ioAddr,
ULONG * bufPtr,
int nLongs
)
{
int loopCtr;
for (loopCtr = 0; loopCtr < nLongs; loopCtr++)
*bufPtr++ = *(UINT32 *)ioAddr;
}
void sysOutLongString(ULONG ioAddr,ULONG * bufPtr,int nLongs)
{
int loopCtr;
for (loopCtr = 0; loopCtr < nLongs; loopCtr++)
*(UINT32 *)ioAddr = *bufPtr++;
}
STATUS sysIntEnablePIC(int intNum)
{
/*intEnable (intNum);quy del int 2006-3-24 8:31*/
return OK;
}
STATUS ataRW_App(int ctrl,int drive,int startBlk,int nSecs,void* pBuf,int direction)
{
ATA_CTRL *pCtrl = &ataCtrl[ctrl];
ATA_TYPE *pType = &ataTypes[ctrl][drive];
ATA_DEV ataDev;
BLK_DEV *pBlkdev = &ataDev.blkDev;
if ((ctrl >= ATA_MAX_CTRLS) || (drive >= ATA_MAX_DRIVES) ||
!ataDrvInstalled || !pCtrl->installed)
return (ERROR);
if(!pBuf)
{
printf("pBuf is NULL.\n");
return(ERROR);
}
pBlkdev->bd_nBlocks = pType->cylinders * pType->heads * pType->sectors;
pBlkdev->bd_bytesPerBlk = pType->bytes;
pBlkdev->bd_blksPerTrack = pType->sectors;
pBlkdev->bd_nHeads = pType->heads;
pBlkdev->bd_removable = FALSE;
pBlkdev->bd_retry = 1;
pBlkdev->bd_mode = O_RDWR;
pBlkdev->bd_readyChanged = TRUE;
pBlkdev->bd_blkRd = ataBlkRd;
pBlkdev->bd_blkWrt = ataBlkWrt;
pBlkdev->bd_reset = ataReset;
pBlkdev->bd_ioctl = ataIoctl;
pBlkdev->bd_statusChk = ataStatus;
ataDev.ctrl = ctrl;
ataDev.drive = drive;
ataDev.blkOffset = 0;
//printf("pType->cylinders=%d;pType->heads = %d;pType->sectors =%d \n", pType->cylinders,pType->heads,pType->sectors);
return (ataBlkRW (&ataDev, startBlk, nSecs, pBuf,
direction));
}
/* here is my end */
/******************************************************************************
*
* nwAtaInit - intialize the hard disk driver
*
* This routine is called from usrConfig.c to initialize the hard drive.
*/
STATUS nwAtaInit (void)
{
int ix;
ATA_RESOURCE *pAtaResource;
int isHaveIde;
if (0 == sysAtaDevIdGet())
return(ERROR);/* not found ata briage */
isHaveIde = 0;
for (ix = 0; ix < ATA_MAX_CTRLS; ix++)
{
pAtaResource = &ataResources[ix];
if (pAtaResource->ctrlType == IDE_LOCAL)
if(ataDrv (ix, pAtaResource->drives, pAtaResource->intVector,
pAtaResource->intLevel, pAtaResource->configType,
pAtaResource->semTimeout, pAtaResource->wdgTimeout)!=ERROR)
isHaveIde++;
}
if(isHaveIde)
return(OK);
else
return(ERROR);
}
/******************************************************************************
*
* nwStartDma - start the ide work on dma mode
*
* This routine is called from usrAtaDriverInit.c to set the ide start working.
*/
static void nwStartDma(void)
{
char *pTempData = NULL;
pTempData = (char *)malloc(1024);
memset(pTempData, 0, 1024);
ataRW(0,0,2,3,200, pTempData, 2, O_RDONLY);
free(pTempData);
}
/*====================================================================
函数名 : usrAtaGetHDisknKByte
功能 :获取ata硬盘的大小,以kbyte为单位。
算法实现 :(可选项)
引用全局变量:无
输入参数说明:无
返回值说明 :返回ata硬盘的大小,以kbyte为单位.
----------------------------------------------------------------------
修改记录 :
日 期 版本 修改人 修改内容
====================================================================*/
UINT32 nwAtaGetHDisknKByte
(
int ctrl, /* 0: primary address, 1: secondary address */
int drive /* drive number of hard disk (0 or 1) */
)
{
return g_dwAtaHDAllBlocks[ctrl][drive]/1024*512;
}
/*====================================================================
函数名 : ata_app_Scandisk
功能 :初始化ata(atp865)驱动
算法实现 :(可选项)
引用全局变量:无
输入参数说明:无
返回值说明 :成功返回OK,如果失败返回ERROR.
----------------------------------------------------------------------
修改记录 :
日 期 版本 修改人 修改内容
====================================================================*/
STATUS ata_app_Scandisk(void)
{
#ifdef INCLUDE_ATA_HD
/*del by youyan
sysAtaPciInit();
end of del by youyan */
if (0 == sysAtaDevIdGet()) /* not found ata briage */
{
printf("ata_app_Scandisk: NO ATA-PCI Bridge .\n");
return ERROR;
}
if(nwAtaInit()!=ERROR)
{
int i,j;
printf("Found ATA Device(S).\n");
for(i=0;i<ATA_MAX_CTRLS;i++)
{
for(j=0;j<ATA_MAX_DRIVES;j++)
{
if(ataLbaTotalSecs[i][j]>0)
{
printf("Disk Cap sector is:%d about %d G\n",ataLbaTotalSecs[i][j],(((ataLbaTotalSecs[i][j]/(1024*1024))*512)/1024));
}
}
}
return OK;
}
else
{
printf("NO ATA Device(S).\n");
return ERROR;
}
#endif
}
/*
功能:
获得磁盘容量
参数:
ctrl为IDE总线号0, 1, 2, ….., m
drive为主从磁盘编号, 0=master disk, 1=slave disk
返回值:
如果磁盘存在返回磁盘的容量(以1M=1024*1024为单位), 失败返回0
*/
unsigned int ata_app_Getdiskcap(int ctrl, int drive)
{
ATA_CTRL *pCtrl = &ataCtrl[ctrl];
if((ctrl >= ATA_MAX_CTRLS) || (drive > ATA_MAX_DRIVES))
{
printf("ctrl Or drive Parameters ERROR.\n");
return (ERROR);
}
if(!pCtrl->installed)
return(0);
if(ataLbaTotalSecs[ctrl][drive] > 0)
{
/*以兆单位返回*/
return((ataLbaTotalSecs[ctrl][drive]/(1024*1024))*512);
/*以G单位返回
return(((ataLbaTotalSecs[i][j]/(1024*1024))*512)/1024);
*/
}
else
return(ERROR);
}
/*
功能:
获得磁盘状态
参数:
ctrl为IDE总线号0, 1, 2, ….., m
drive为主从磁盘编号, 0=master disk, 1=slave disk
返回值:
-1=error, 0=standby, 1=active
*/
int ata_app_Getdiskstate(int ctrl, int drive)
{
ATA_CTRL *pCtrl;
ATA_DRIVE *pDrive;
if((ctrl >= ATA_MAX_CTRLS) || (drive > ATA_MAX_DRIVES))
{
printf("ctrl Or drive Parameters ERROR.\n");
return (ERROR);
}
if(!ataLbaTotalSecs[ctrl][drive])
{
printf("No Found Device(s) Info.\n");
return(ERROR);
}
pCtrl = &ataCtrl[ctrl];
pDrive = &pCtrl->drive[drive];
return(pDrive->status);
}
/*
功能:
获得磁盘详细信息
参数:
ctrl为IDE总线号0, 1, 2, ….., m
drive为主从磁盘编号, 0=master disk, 1=slave disk
pInfo 指向ATA_APP_DISK_INFO的指针
返回值:
成功返回OK, 失败返回ERROR
*/
STATUS ata_app_Getdiskdetail(int ctrl, int drive, ATA_APP_DISK_INFO* pInfo)
{
ATA_PARAM *pParam;
ATA_CTRL *pCtrl;
ATA_DRIVE *pDrive;
if((ctrl >= ATA_MAX_CTRLS) || (drive > ATA_MAX_DRIVES))
{
printf("ctrl Or drive Parameters ERROR.\n");
return (ERROR);
}
if(!pInfo)
{
printf("pInfo is NULL.\n");
return(ERROR);
}
if(!ataLbaTotalSecs[ctrl][drive])
{
printf("No Found Device(s) Info.\n");
return(ERROR);
}
pCtrl = &ataCtrl[ctrl];
pDrive = &pCtrl->drive[drive];
pParam = &pDrive->param;
memset(pInfo,0,sizeof(ATA_APP_DISK_INFO));
pInfo->iCtrl = ctrl;
pInfo->iDrive = drive;
pInfo->iInstalled = 1;
pInfo->iDiskState = pDrive->status;
pInfo->iTotalSecs = ataLbaTotalSecs[ctrl][drive];
pInfo->iMTotalBytes = ataLbaTotalSecs[ctrl][drive]/(1024*1024)*512;
memcpy(pInfo->cSerial,pParam->serial,sizeof(pInfo->cSerial));
memcpy(pInfo->cModel,pParam->model,sizeof(pInfo->cModel));
return(OK);
}
/*
功能:
磁盘多扇区读写函数
参数:
ctrl为IDE总线号0, 1, 2, ….., m
drive为主从磁盘编号, 0=master disk, 1=slave disk
startBlk为起始扇区编号
nSecs 为读/写扇区的数量
pBuf 为读/写缓冲区
direction 为读/写方向标记, 0=read, 1=write
返回值:
如果读写成功返回OK, 失败返回ERROR
*/
STATUS ata_app_rw(int ctrl, int drive, int startBlk, int nSecs, void* pBuf, int direction)
{
return(ataRW_App(ctrl,drive,startBlk,nSecs,pBuf,direction));
}
/*
功能:
设置磁盘状态
参数:
ctrl为IDE总线号0, 1, 2, ….., m
drive为主从磁盘编号, 0=master disk, 1=slave disk
istate为磁盘状态, 0=standby, 1=active
返回值:
如果设置成功返回OK, 失败返回ERROR
*/
STATUS ata_app_Setdiskstate(int ctrl, int drive, int istate)
{
ATA_CTRL *pCtrl;
ATA_DRIVE *pDrive;
if((ctrl >= ATA_MAX_CTRLS) || (drive > ATA_MAX_DRIVES))
{
printf("ctrl Or drive Parameters ERROR.\n");
return (ERROR);
}
if((ATA_STANDBY_MODE==istate) || (ATA_ACTIVE_MODE == istate))
{
pCtrl = &ataCtrl[ctrl];
pDrive = &pCtrl->drive[drive];
if(pDrive->status == istate)
return(OK);
pDrive->status = istate;
ataWait(ctrl, ATA_STAT_BUSY);
ATA_IO_BYTE_WRITE(pCtrl->sdh, ATA_SDH_LBA | (drive << 4));
if(ATA_STANDBY_MODE == istate)
{
ATA_IO_BYTE_WRITE(pCtrl->command, IDE_CMD_STNBY);
}
else
{
ATA_IO_BYTE_WRITE(pCtrl->command, IDE_CMD_IDLE);
}
return(OK);
}
else
{
printf("istate Parameter is ERROR.\n");
return(ERROR);
}
}
/*获取系统磁盘个数
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -