📄 sdbus.cpp
字号:
fRet = SD_API_SUCCESS(status);
}
else
SetLastError(SD_API_STATUS_INVALID_PARAMETER);
break;
case IOCTL_BUS_SD_IO_DISCONNECT_INTERRUPT:
if (pBufIn && dwLenIn>=sizeof(SD_DEVICE_HANDLE) ) {
HANDLE hDevice = *(HANDLE *)pBufIn;
CSDDevice * pDevice = GetDeviceByDevice (hDevice);
if (pDevice) {
pDevice->SDIOConnectDisconnectInterrupt(NULL,FALSE);
pDevice->DeRef();
}
fRet = TRUE;
}
else
SetLastError(SD_API_STATUS_INVALID_PARAMETER);
break;
case IOCTL_BUS_SD_GETCLIENT_FUNCTION:
if (pBufOut && dwLenOut>=sizeof(SDCARD_API_FUNCTIONS)) {
SD_API_STATUS status= SDGetClientFunctions((SDCARD_API_FUNCTIONS *)pBufOut);
SetLastError(status);
fRet = SD_API_SUCCESS(status);
if (fRet && pdwActualOut) {
*pdwActualOut = sizeof(SDCARD_API_FUNCTIONS) ;
}
}
else
SetLastError(SD_API_STATUS_INVALID_PARAMETER);
break;
*/
default:
fRet = DefaultBusDriver::IOControl(dwCode, pBufIn, dwLenIn, pBufOut,
dwLenOut, pdwActualOut);
break;
};
return fRet;
}
PVOID CSDHostContainer::AllocateBusRequest(size_t stSize)
{
PVOID pReturn = NULL;
if (g_pSdContainer != NULL ) {
pReturn = g_pSdContainer->AllocateBusRequestImp(stSize);
#ifdef DEBUG
if (pReturn){
memset(pReturn,0xcc,stSize);
}
#endif
}
return pReturn;
}
void CSDHostContainer::FreeBusRequestImp(CSDBusRequest *pBusRequest)
{
if (pBusRequest) {
CSDHostContainerClass::Lock();
PFREE_BUS_REQUEST_SPACE pBusRequestFreeSpace = (PFREE_BUS_REQUEST_SPACE)pBusRequest;
pBusRequestFreeSpace -- ; // move back to the header.
if (pBusRequestFreeSpace->dwFreeSpaceTag== BUS_REQUEST_FREE_SPACE_TAG) {
if (pBusRequestFreeSpace->dwSpaceSize != m_dwMinSize) { // Size has chnaged. So delete it directory.
DEBUGMSG(SDCARD_ZONE_WARN,(L"free space because size changed.%x ",pBusRequestFreeSpace) );
free(pBusRequestFreeSpace);
}
else {
pBusRequestFreeSpace->pNextFreeTransfer = m_pFreeBusRequestSpace;
m_pFreeBusRequestSpace = pBusRequestFreeSpace;
}
}
else {// trashed point. Do know what to do except free it direct free it
ASSERT(FALSE);
DEBUGMSG(SDCARD_ZONE_ERROR,(L"DeleteTransfer detect garbage pointer %x ",pBusRequestFreeSpace) );
free(pBusRequestFreeSpace);
}
CSDHostContainerClass::Unlock();
}
}
void CSDHostContainer::FreeBusRequest(CSDBusRequest *pBusRequest)
{
if (pBusRequest) {
if (g_pSdContainer != NULL ) {
g_pSdContainer->FreeBusRequestImp(pBusRequest);
}
else { // this is best we can do.
PFREE_BUS_REQUEST_SPACE pBusRequestFreeSpace = (PFREE_BUS_REQUEST_SPACE)pBusRequest;
pBusRequestFreeSpace -- ; // move back to the header.
free(pBusRequestFreeSpace);
}
}
}
void CSDHostContainer::DeleteAllTransferSpace()
{
CSDHostContainerClass::Lock();
while (m_pFreeBusRequestSpace) {
PFREE_BUS_REQUEST_SPACE pRequestNextFreeSpace = m_pFreeBusRequestSpace->pNextFreeTransfer;
free(m_pFreeBusRequestSpace);
m_pFreeBusRequestSpace = pRequestNextFreeSpace;
}
CSDHostContainerClass::Unlock();
}
PVOID CSDHostContainer::DriverInit(LPCTSTR pszActiveKey)
{
if (g_pSdContainer == NULL ) {
CSDHostContainer * pHostContainer = new CSDHostContainer(pszActiveKey);
if (pHostContainer!=NULL && !pHostContainer->Init()) { // Failed during inti.
delete pHostContainer;
pHostContainer = NULL;
}
g_pSdContainer = pHostContainer;
return ((PVOID)g_pSdContainer);
}
else {
DEBUGMSG(SDCARD_ZONE_ERROR, (TEXT("SDBusDriver: Init called more than once\n")));
return NULL;
}
}
VOID CSDHostContainer::DriverDeInit(PVOID pContent)
{
if (g_pSdContainer && g_pSdContainer == pContent ) {
delete g_pSdContainer;
g_pSdContainer = NULL;
}
else
DEBUGMSG(SDCARD_ZONE_ERROR, (TEXT("SDBusDriver: DeInit called with wrong content\n")));
};
DWORD CSDHostContainer::RegValueDWORD(LPTSTR lpRegName,DWORD dwDefault)
{
DWORD dwReturn = dwDefault;
if (g_pSdContainer ) {
if (!g_pSdContainer->GetDeviceKey().GetRegValue(lpRegName,(LPBYTE)&dwReturn, sizeof(dwReturn))) {
dwReturn = dwDefault;
}
}
return dwReturn;
}
LPCTSTR CSDHostContainer::GetSubBusNamePrefix()
{
if (m_szSubBusNamePrefix[0])
return m_szSubBusNamePrefix;
else
return SD_SUB_BUSNAME_DEFAULT;
}
///////////////////////////////////////////////////////////////////////////////
// SDHCDAllocateContext - Allocate an HCD Context
//
// Input: NumberOfSlots - Number of slots
// Output:
// ppExternalHCContext - caller supplied storage for the host context
// Return: SD_API_STATUS
// Notes:
// Host controller drivers must allocate an HC context for the bus driver.
// When a host controller driver is unloaded it must free this context
// returns SD_API_STATUS
///////////////////////////////////////////////////////////////////////////////
SD_API_STATUS CSDHostContainer::SDHCDAllocateContext__X(DWORD NumberOfSlots,
PSDCARD_HC_CONTEXT *ppExternalHCContext)
{
// check parameters, at least one slot must be allocated
if ((ppExternalHCContext == NULL) || (NumberOfSlots == 0)) {
DEBUGMSG(SDCARD_ZONE_ERROR, (TEXT("SDHCDAllocateContext: invalid parameter \n")));
return SD_API_STATUS_INVALID_PARAMETER;
}
CSDHost * pNewHost = new CSDHost(NumberOfSlots);
if (pNewHost && pNewHost->Init() && InsertSDHost(pNewHost)) {
*ppExternalHCContext = pNewHost;
return SD_API_STATUS_SUCCESS ;
}
else {
if (pNewHost)
delete pNewHost;
}
return SD_API_STATUS_INVALID_PARAMETER;
};
///////////////////////////////////////////////////////////////////////////////
// SDHCDRegisterHostController - Register a host controller with the bus driver
//
// Input: pExternalHCContext - Allocated Host controller context
//
// Output:
// Return: SD_API_STATUS
// Notes:
//
// the caller must allocate a host controller context and
// initialize the various parameters
//
///////////////////////////////////////////////////////////////////////////////
SD_API_STATUS CSDHostContainer::SDHCDRegisterHostController__X(PSDCARD_HC_CONTEXT pExternalHCContext)
{
CSDHost * pHost = GetSDHost((CSDHost *)pExternalHCContext);
SD_API_STATUS status = SD_API_STATUS_UNSUCCESSFUL ;
if (pHost) {
if (pExternalHCContext->dwVersion > SDCARD_HC_BUS_INTERFACE_VERSION) {
DEBUGMSG(SDCARD_ZONE_ERROR,
(TEXT("SDBusDriver: Host controller interface version (%x) does not match bus driver (%x)\n"),
pExternalHCContext->dwVersion, SDCARD_HC_BUS_INTERFACE_VERSION));
}
else {
BOOL fRet = pHost->Attach();
ASSERT(fRet);
status = pHost->InitHandler();
}
pHost->DeRef();
}
ASSERT(SD_API_SUCCESS(status));
return status;
}
///////////////////////////////////////////////////////////////////////////////
// SDHCDDeregisterHostController - Deregister a host controller
//
// Input: pExternalHCContext - Host controller context that was previously registered
//
// Output:
// Return: SD_API_STATUS
// Notes:
// A host controller must call this api before deleting the HC context
//
///////////////////////////////////////////////////////////////////////////////
SD_API_STATUS CSDHostContainer::SDHCDDeregisterHostController__X(PSDCARD_HC_CONTEXT pExternalHCContext)
{
SD_API_STATUS status = SD_API_STATUS_UNSUCCESSFUL;
CSDHost * psdHost = GetSDHost((CSDHost *)pExternalHCContext);
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.
///////////////////////////////////////////////////////////////////////////////
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -