📄 sdbus.cpp
字号:
if (psdHost) {
CSDHost * psdRemovedHost = RemoveSDHostBy(psdHost->GetIndex());
ASSERT(psdRemovedHost!=NULL);
BOOL fRet = psdHost->Detach();
ASSERT(fRet);
status = psdHost->DeinitHandler();
psdHost->DeRef();
}
else {
ASSERT(FALSE);
}
return status;
}
///////////////////////////////////////////////////////////////////////////////
// SDHCDDeleteContext - Delete an HCD context
//
// Input: pExternalHCContext - Host Context to delete
// Output:
// Return:
// Notes:
///////////////////////////////////////////////////////////////////////////////
VOID CSDHostContainer::SDHCDDeleteContext__X(PSDCARD_HC_CONTEXT pExternalHCContext)
{
CSDHost * psdHost = GetSDHost((CSDHost *)pExternalHCContext);
if (psdHost) {
ASSERT(FALSE); // This should not happens because it has been deleted from container.
CSDHost * psdRemovedHost = RemoveSDHostBy(psdHost->GetIndex());
ASSERT(psdRemovedHost!=NULL);
psdHost->DeRef();
}
}
///////////////////////////////////////////////////////////////////////////////
// SDHCDIndicateSlotStateChange - indicate a change in the SD Slot
//
// Input: pExternalHCContext - Host controller context that was previously registered
// SlotNumber - Slot Number
// Event - new event
// Output:
// Return: SD_API_STATUS
// Notes:
// A host controller driver calls this api when the slot changes state (i.e.
// device insertion/deletion).
///////////////////////////////////////////////////////////////////////////////
VOID CSDHostContainer::SDHCDIndicateSlotStateChange__X(PSDCARD_HC_CONTEXT pExternalHCContext,
DWORD SlotNumber,
SD_SLOT_EVENT Event)
{
CSDHost * psdHost = GetSDHost((CSDHost *)pExternalHCContext);
if (psdHost ) {
if ((CSDHost *) pExternalHCContext == psdHost ) {
CSDSlot * psdSlot = psdHost->GetSlot(SlotNumber) ;
if (psdHost->IsAttached() && psdSlot) {
psdSlot->SlotStateChange(Event);
}
}
else {
ASSERT(FALSE);
}
psdHost->DeRef();
}
}
///////////////////////////////////////////////////////////////////////////////
// SDHCDPowerUpDown - Indicate a power up/down event
//
// Input: pHCContext - host controller context
// PowerUp - set to TRUE if powering up
// SlotKeepPower - set to TRUE if the slot maintains power to the
// slot during power down
// Output:
// Return:
// Notes: This function notifies the bus driver of a power up/down event.
// The host controller driver can indicate to the bus driver that power
// can be maintained for the slot. If power is removed, the bus driver
// will unload the device driver on the next power up event.
// This function can only be called from the host controller's XXX_PowerOn
// and XXX_PowerOff function.
///////////////////////////////////////////////////////////////////////////////
VOID CSDHostContainer::SDHCDPowerUpDown__X(PSDCARD_HC_CONTEXT pExternalHCContext,
BOOL PowerUp,
BOOL SlotKeepPower,
DWORD SlotIndex)
{
CSDHost * psdHost = GetSDHost((CSDHost *)pExternalHCContext) ;
if (psdHost ) {
CSDSlot * psdSlot = psdHost->GetSlot(SlotIndex) ;
if (psdHost->IsAttached() && psdSlot) {
if (PowerUp){
psdSlot->PowerUp();
} else {
psdSlot->PowerDown(SlotKeepPower);
}
}
psdHost->DeRef();
}
else {
RETAILMSG(1, (TEXT("SDBusDriver: Passed invalid SDCARD_HC_CONTEXT \n")));
DEBUGCHK(FALSE);
return;
}
}
///////////////////////////////////////////////////////////////////////////////
// SDHCDIndicateBusRequestComplete - indicate to the bus driver that
// the request is complete
// Input: pExternalHCContext - host controller context
// pRequest - the request to indicate
// Status - the ending status of the request
// Output:
// Return:
// Notes:
//
//
///////////////////////////////////////////////////////////////////////////////
VOID CSDHostContainer::SDHCDIndicateBusRequestComplete__X(PSDCARD_HC_CONTEXT pExternalHCContext,
PSD_BUS_REQUEST pRequest,
SD_API_STATUS Status)
{
CSDBusRequest * pBusRequest = (CSDBusRequest *) pRequest;
DWORD dwSDHCIndex = MAXDWORD;
DWORD dwSlotIndex = MAXDWORD;
BOOL fResult = FALSE;
if (pBusRequest) {
__try {
dwSDHCIndex = pBusRequest->GetDevice().GetSlot().GetHost().GetIndex();
dwSlotIndex = pBusRequest->GetDevice().GetSlot().GetSlotIndex();
}
__except(EXCEPTION_EXECUTE_HANDLER) {
}
}
CSDHost * psdHost = GetSDHost( dwSDHCIndex ) ;
if (psdHost && (PSDCARD_HC_CONTEXT)psdHost == pExternalHCContext) {
CSDSlot * psdSlot = psdHost->GetSlot(dwSlotIndex) ;
if (psdSlot) {
fResult = psdSlot->CompleteRequestFromHC(pBusRequest, Status);
}
}
ASSERT(fResult);
if (psdHost ) {
psdHost->DeRef();
}
}
///////////////////////////////////////////////////////////////////////////////
// SDHCDGetAndLockCurrentRequest - get the current request in the host controller
// slot and lock it to keep it from being cancelable
// Input: pExternalHCContext - host controller context
// SlotIndex - the slot number
// Output:
// Return: current bus request
// Notes:
// This function retrieves the current request and marks the
// request as NON-cancelable. To return the request back to the
// cancelable state the caller must call SDHCDUnlockRequest()
// This function returns the current request which can be NULL if
// the request was previously marked cancelable and the host controller's
// cancelIo Handler completed the request
///////////////////////////////////////////////////////////////////////////////
PSD_BUS_REQUEST CSDHostContainer::SDHCDGetAndLockCurrentRequest__X(PSDCARD_HC_CONTEXT pExternalHCContext, DWORD SlotIndex)
{
DWORD dwSDHCIndex = MAXDWORD;
CSDBusRequest * pBusRequest = NULL;
if (pExternalHCContext) {
__try {
dwSDHCIndex =( (CSDHost *) pExternalHCContext)->GetIndex();
}
__except(EXCEPTION_EXECUTE_HANDLER) {
}
}
CSDHost * psdHost = GetSDHost( dwSDHCIndex ) ;
if (psdHost && (PSDCARD_HC_CONTEXT)psdHost == pExternalHCContext) {
CSDSlot * psdSlot = psdHost->GetSlot(SlotIndex) ;
if (psdSlot) {
pBusRequest = psdSlot->SDHCGetAndLockCurrentRequest_I();
}
}
//ASSERT(pBusRequest);
if (psdHost ) {
psdHost->DeRef();
}
return (pBusRequest!=NULL? (PSD_BUS_REQUEST)pBusRequest: NULL);
}
///////////////////////////////////////////////////////////////////////////////
// SDHCDUnlockRequest - Unlock a request that was previous locked
//
// Input: pHCContext - host controller context
// pRequest - the request to lock
// Output:
// Return:
// Notes: This function unlocks the request that was returned from the
// function SDHCDGetAndLockCurrentRequest()
//
// This request can now be cancelled from any thread context
///////////////////////////////////////////////////////////////////////////////
VOID CSDHostContainer::SDHCDUnlockRequest__X(PSDCARD_HC_CONTEXT pExternalHCContext,PSD_BUS_REQUEST pRequest)
{
DWORD dwSDHCIndex = MAXDWORD;
DWORD dwSlotIndex = MAXDWORD;
BOOL fSuccess = FALSE;
if (pExternalHCContext) {
__try {
dwSDHCIndex =( (CSDHost *) pExternalHCContext)->GetIndex();
dwSlotIndex = ((CSDBusRequest *)pRequest)->GetDevice().GetSlot().GetSlotIndex();
}
__except(EXCEPTION_EXECUTE_HANDLER) {
}
}
CSDHost * psdHost = GetSDHost( dwSDHCIndex ) ;
if (psdHost && (PSDCARD_HC_CONTEXT)psdHost == pExternalHCContext) {
CSDSlot * psdSlot = psdHost->GetSlot(dwSlotIndex) ;
if (psdSlot) {
psdSlot->SDHCDUnlockRequest_I(pRequest) ;
fSuccess = TRUE;
}
}
if (psdHost ) {
psdHost->DeRef();
}
ASSERT(fSuccess);
}
///////////////////////////////////////////////////////////////////////////////
// SDRegisterClient__X - register a client device
// Input: hDevice - device handle
// pDeviceContext - device specific context allocated by driver
// pInfo - registration information
//
// Output:
// Notes:
// returns SD_API_STATUS_SUCCESS
///////////////////////////////////////////////////////////////////////////////
SD_API_STATUS SDRegisterClient__X(HANDLE hDevice,PVOID pDeviceContext, PSDCARD_CLIENT_REGISTRATION_INFO pInfo)
{
SD_API_STATUS status = SD_API_STATUS_INVALID_PARAMETER; // intermediate status
CSDDevice * pDevice = CSDHostContainer::GetDeviceByDevice(hDevice);
if (pDevice) {
__try {
status = pDevice->RegisterClient(NULL,pDeviceContext, pInfo);
}
__except (SDProcessException(GetExceptionInformation())) {
status = SD_API_STATUS_ACCESS_VIOLATION;
}
pDevice->DeRef();
}
DEBUGMSG(SDCARD_ZONE_ERROR && !SD_API_SUCCESS(status), (TEXT("SDRegisterClient: Failed to register client 0x%08X \n"),status));
return status;
}
///////////////////////////////////////////////////////////////////////////////
// SDSynchronousBusRequest__X - send an SD Bus request synchronously
// Input: hDevice - device handle
// Command - command to send
// Argument - argument for command
// TransferClass - Command only, or associated with read/write data
// ResponseType - expected response
// pResponse - buffer to hold response (OPTIONAL)
// NumBlocks - number of blocks
// BlockSize - block size
// pBuffer - block buffer
// Flags - bus request flags
//
// Output: pResponse - caller allocated storage for the return response
// Return: SD_API_STATUS
// Notes:
// This function provides a synchronous (blocking) call to perform a
// bus request.
///////////////////////////////////////////////////////////////////////////////
SD_API_STATUS SDSynchronousBusRequest__X(SD_DEVICE_HANDLE hDevice,
UCHAR Command,
DWORD Argument,
SD_TRANSFER_CLASS TransferClass,
SD_RESPONSE_TYPE ResponseType,
PSD_COMMAND_RESPONSE pResponse,
ULONG NumBlocks,
ULONG BlockSize,
PUCHAR pBuffer,
DWORD Flags,
DWORD cbSize, PPHYS_BUFF_LIST pPhysBuffList)
{
SD_API_STATUS status = SD_API_STATUS_INVALID_PARAMETER; // intermediate status
CSDDevice * pDevice = CSDHostContainer::GetDeviceByDevice((HANDLE)hDevice);
if (pDevice) {
__try {
#ifdef _FOR_MOVI_NAND_
/**
* Description : If moviNAND use Multi block r/w, we must use pre-define.
* Open-end can cause wrong operation
*/
if ( Flags == SD_MOVINAND_PRE_DEFINE )
{
SD_COMMAND_RESPONSE ResponseValue = {ResponseR1,{0}};
status = pDevice->SDSynchronousBusRequest_I(MMC_CMD_SET_BLOCK_LENGTH,NumBlocks,SD_COMMAND,ResponseR1,&ResponseValue,0,0,NULL,0,cbSize,pPhysBuffList);
}
#endif
status = pDevice->SDSynchronousBusRequest_I(Command,Argument,TransferClass,ResponseType,pResponse,NumBlocks,BlockSize,pBuffer,Flags,cbSize,pPhysBuffList);
}
__except (SDProcessException(GetExceptionInformation())) {
status = SD_API_STATUS_ACCESS_VIOLATION;
}
pDevice->DeRef();
}
DEBUGMSG(SDCARD_ZONE_ERROR && !SD_API_SUCCESS(status), (TEXT("SDSynchronousBusRequest__X: Failed status 0x%08X \n"),st
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -