?? hal_atapi.c
字號:
/************************************************************************Source file name : hal_atapi.cDescription: HAL Layer implementation of the ATA/ATAPI driver for the 5512/18 ATA Host InterfaceCOPYRIGHT (C) STMicroelectronics 2000************************************************************************//*Includes-------------------------------------------------------------*/#include <stdio.h>#include <string.h>#include "stsys.h"#include "stlite.h"#include "statapi.h"#include "hal_atapi.h"#include "ata.h"#if defined(ATAPI_GPDMA)#if defined(HDDI_5514_CUT_3)#error Use of GPDMA with 5514 cut 3 HDDI is not supported.#endif#include "stgpdma.h"#endif#include "sttbx.h"/*---------------HW specific ---------------------------*/#define ATA_HRD_RST_ASSERT 0x0#define ATA_HRD_RST_DEASSERT 0x1#ifdef BMDMA_ENABLE/* BMDMA details */#define BLOCK_MOVE_INT_LEVEL 6#define BLOCK_MOVE_INTERRUPT 15#define BMDMA_SrcAddress 0x20026000#define BMDMA_DestAddress 0x20026004#define BMDMA_Count 0x20026008#define BMDMA_IntEn 0x2002600C#define BMDMA_Status 0x20026010#define BMDMA_IntAck 0x20026014#endif/*Exported macros ----------------*//*Private Types--------------------------------------------------------*/BOOL Verbose = FALSE;BOOL Trace = FALSE;U32 intcount = 0;U32 inttrace[15];/*Private Constants----------------------------------------------------*/static STATAPI_PioTiming_t CurrentPioTiming;static STATAPI_DmaTiming_t CurrentDmaTiming;static const STATAPI_Capability_t CurrentCapabilities = { STATAPI_EMI_PIO4, 1 << STATAPI_PIO_MODE_4, (1 << STATAPI_DMA_UDMA_MODE_4) | (1 << STATAPI_DMA_UDMA_MODE_2) | (1 << STATAPI_DMA_UDMA_MODE_0) | (1 << STATAPI_DMA_MWDMA_MODE_0) | (1 << STATAPI_DMA_MWDMA_MODE_2) };#if defined (ST_5512) static const U32 RegsMasks[12]={ (aCS1 | nCS0 | aDA2 | aDA1 | nDA0), (nCS1 | aCS0 | nDA2 | nDA1 | nDA0), (nCS1 | aCS0 | nDA2 | nDA1 | aDA0), (nCS1 | aCS0 | nDA2 | nDA1 | aDA0), (nCS1 | aCS0 | nDA2 | aDA1 | nDA0), (nCS1 | aCS0 | nDA2 | aDA1 | aDA0), (nCS1 | aCS0 | aDA2 | nDA1 | nDA0), (nCS1 | aCS0 | aDA2 | nDA1 | aDA0), (nCS1 | aCS0 | aDA2 | aDA1 | nDA0), (nCS1 | aCS0 | aDA2 | aDA1 | aDA0), (nCS1 | aCS0 | aDA2 | aDA1 | aDA0), (aCS1 | nCS0 | aDA2 | aDA1 | nDA0) };#elif defined (ST_5508) | defined (ST_5518) static const U32 RegsMasks[12]={(0x1c0000), (0x200000), (0x220000), (0x220000), (0x240000), (0x260000), (0x280000), (0x2a0000), (0x2c0000), (0x2e0000), (0x2e0000), (0x1c0000) }; #elif defined(ST_5514)/* Not actually masks in this case; offsets from base address for the * relevant registers */static const U32 RegsMasks[12]={ (0x38), (0x40), (0x44), (0x44), (0x48), (0x4c), (0x50), (0x54), (0x58), (0x5c), (0x5c), (0x38) };#endif /*Private Variables----------------------------------------------------*/static hal_Handle_t *The_HalHandle_p;/* Need to know what mode we should be in */static STATAPI_DmaMode_t CurrentDmaMode;static STATAPI_PioMode_t CurrentPioMode;#ifdef ST_5514/* Simplifies switch in DmaDataBlock */static BOOL DMAIsUDMA = FALSE;#endif/*Private Macros-------------------------------------------------------*//*Private functions prototypes-----------------------------------------*/static void ata_InterruptHandler (void);void SetPIOTiming(volatile U32 *Base, STATAPI_PioTiming_t *Timing);#ifdef BMDMA_ENABLEstatic void ata_BlockMoveIntHandler (void);#endif/*Functions------------------------------------------------------------*//************************************************************************Name: hal_InitDescription: This function initializes the structures needed to manage the silicon Basically it allocates the hal handle and installs the interrupt handlerParameters:************************************************************************/BOOL hal_Init (const STATAPI_InitParams_t *params_p, hal_Handle_t **HalHndl_p){#if defined(ATAPI_GPDMA) STGPDMA_OpenParams_t GPDMA_Open; ST_ErrorCode_t error = ST_NO_ERROR;#endif /* Allocate handle */ *HalHndl_p = (hal_Handle_t*) memory_allocate (params_p->DriverPartition,sizeof (hal_Handle_t)); if(*HalHndl_p == NULL) return TRUE; /*We keep our internal-hal handle copy, for future checking*/ The_HalHandle_p = *HalHndl_p; (*HalHndl_p)->BaseAddress = params_p->BaseAddress; (*HalHndl_p)->HWResetAddress = params_p->HW_ResetAddress; (*HalHndl_p)->InterruptNumber = params_p->InterruptNumber; (*HalHndl_p)->InterruptLevel = params_p->InterruptLevel; (*HalHndl_p)->DriverPartition = params_p->DriverPartition; #ifdef BMDMA_ENABLE /* create interrupt semaphore */ semaphore_init_fifo_timeout(&(*HalHndl_p)->BMDMA_IntSemaphore, 0); /* install the interrupt handler */ if (interrupt_install(BLOCK_MOVE_INTERRUPT, BLOCK_MOVE_INT_LEVEL, (void(*)(void*))ata_BlockMoveIntHandler, NULL) != 0) { /* Error: clean and exit */ semaphore_delete(&(*HalHndl_p)->BMDMA_IntSemaphore); memory_deallocate((*HalHndl_p)->DriverPartition,*HalHndl_p); return TRUE; } interrupt_enable (BLOCK_MOVE_INT_LEVEL);#endif #if ATAPI_USING_INTERRUPTS /* create interrupt semaphore */ semaphore_init_fifo_timeout(&(*HalHndl_p)->InterruptSemaphore,0); /* install the interrupt handler */ if (interrupt_install((*HalHndl_p)->InterruptNumber, (*HalHndl_p)->InterruptLevel, (void(*)(void*))ata_InterruptHandler, NULL) != 0) { /* Error: clean and exit */ semaphore_delete(&(*HalHndl_p)->InterruptSemaphore); memory_deallocate((*HalHndl_p)->DriverPartition,*HalHndl_p); *HalHndl_p = NULL; return TRUE; } /* Enable interrupts in the host */ interrupt_enable ((*HalHndl_p)->InterruptLevel);#endif#if defined(ATAPI_GPDMA) error = STGPDMA_Open(params_p->GPDMADeviceName, &GPDMA_Open, &(*HalHndl_p)->GPDMAHandle); if (error != ST_NO_ERROR) { /* Clean and exit. I don't really feel we can disable that * entire interrupt level, we don't know what else is there. */ interrupt_uninstall((*HalHndl_p)->InterruptNumber, (*HalHndl_p)->InterruptLevel); semaphore_delete(&(*HalHndl_p)->InterruptSemaphore); memory_deallocate((*HalHndl_p)->DriverPartition, *HalHndl_p); *HalHndl_p = NULL; return TRUE; }#endif return FALSE;} /* hal_Init*//************************************************************************Name: hal_TermDescription: This function deallocates all the variables created by the init functionParameters: HalHdl pointer to the main structure************************************************************************/BOOL hal_Term (hal_Handle_t *HalHndl_p){#ifdef BMDMA_ENABLE /* Delete interrupt semaphore*/ semaphore_delete(&(HalHndl_p->BMDMA_IntSemaphore)); /* uninstall the interrupt handler*/ if (interrupt_uninstall (BLOCK_MOVE_INTERRUPT, BLOCK_MOVE_INT_LEVEL) != 0) { return TRUE; }#endif #if ATAPI_USING_INTERRUPTS /*Delete interrupt semaphore*/ semaphore_delete(&HalHndl_p->InterruptSemaphore); /*unistall the int. handler*/ if (interrupt_uninstall (HalHndl_p->InterruptNumber, HalHndl_p->InterruptLevel) != 0) { return TRUE; }#endif#if defined(ATAPI_GPDMA) /* If we get an error, what can we do? */ STGPDMA_Close(HalHndl_p->GPDMAHandle);#endif /* Deallocate handle */ memory_deallocate (HalHndl_p->DriverPartition, HalHndl_p); The_HalHandle_p = NULL; return FALSE; }/*end hal_Term*//************************************************************************Name: hal_RegOutByteDescription: This function works as interface to the ATA registers of the device, allowing the user to write data in these registers. No bus acquisition procedure is done. User must manage this Parameters: HalHndl Handle of the HAL (for the base address) regNo register number data data value to write to register*********************************************************************/void hal_RegOutByte (hal_Handle_t *HalHndl_p, ATA_Register_t regNo, U8 data){ DU8 *addr; addr = (DU8 *)((U32)HalHndl_p->BaseAddress | RegsMasks[regNo]) ; *addr = data;}/************************************************************************ Name: hal_RegInByteDescription: This function works as interface to the ATA registers of the device, allowing the user to read data in these registers. No bus acquisition procedure is done. User must manage this Parameters: HalHndl Handle of the HAL (for the base address) regNo register number************************************************************************/U8 hal_RegInByte (hal_Handle_t *HalHndl_p, ATA_Register_t regNo){ DU8 *addr; addr = (DU8 *)((U32)HalHndl_p->BaseAddress | RegsMasks[regNo]); return (U8)(*addr);}/************************************************************************Name: hal_RegOutWordDescription: This function works as an interface to the device's ATA DATA register allowing the user to WRITE data in this register. No bus acquisition procedure is done. User must manage this Parameters: HalHndl Handle of the HAL (for the base address) data data value to write to register*********************************************************************/void hal_RegOutWord (hal_Handle_t *HalHndl_p, U16 data){ DU16 *addr; addr = (DU16 *)((U32)HalHndl_p->BaseAddress | RegsMasks[ATA_REG_DATA]) ; *addr = data;}/************************************************************************Name: hal_RegInWordDescription: This function works as interface to the device's ATA DATA register allowing the user to READ data in these registers. No bus acquisition procedure is done. User must manage this Parameters: HalHndl Handle of the HAL (for the base address)************************************************************************/U16 hal_RegInWord (hal_Handle_t *HalHndl_p){ DU16 *addr; addr = (DU16 *)((U32)HalHndl_p->BaseAddress | RegsMasks[ATA_REG_DATA]); return (U16)(*addr);}/************************************************************************Name: hal_GetCapabilites Description: This function returns the capabilities of the current host hardware interface.Parameters: HalHndl Handle of the HAL (for the base address) Capabilites pointer to a previously allocated structure to fill with the return valuesReturns: FALSE All OK TRUE Something wrong ************************************************************************/BOOL hal_GetCapabilities (hal_Handle_t *HalHndl_p, STATAPI_Capability_t *Capabilities){ /* Checking the handle and the output parameter */ if ((HalHndl_p == The_HalHandle_p) && (Capabilities != NULL)) { Capabilities->SupportedPioModes = CurrentCapabilities.SupportedPioModes; Capabilities->SupportedDmaModes = CurrentCapabilities.SupportedDmaModes; Capabilities->DeviceType = CurrentCapabilities.DeviceType; } else { return TRUE; } return FALSE;}/************************************************************************Name: hal_EnableIntsDescription: Enable interrupts in the device Parameters: HalHndl Handle of the HAL (for the base address)************************************************************************/void hal_EnableInts (hal_Handle_t *HalHndl_p){ /* Clear nIEN bit */ hal_RegOutByte (HalHndl_p, ATA_REG_CONTROL, nIEN_CLEARED);}/************************************************************************Name:hal_DisableIntsDescription: Disable interrupts in the device Parameters: HalHndl Handle of the HAL (for the base address)************************************************************************/void hal_DisableInts (hal_Handle_t *HalHndl_p){ /* Set nIEN bit */
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -