?? sddevinf.cpp
字號:
// Erase Group Mult fields
eraseGroupSize = (UCHAR)GET_BIT_SLICE_FROM_CSD(pCSD,MMC_CSD_ER_GRP_SIZE_BIT_SLICE,
MMC_CSD_ER_GRP_SIZE_SLICE_SIZE);
eraseGroupMult = (UCHAR)GET_BIT_SLICE_FROM_CSD(pCSD,MMC_CSD_ER_GRP_MULT_BIT_SLICE,
MMC_CSD_ER_GRP_MULT_SLICE_SIZE);
pParsedCSD->EraseSectorSize = (eraseGroupSize+1)*(eraseGroupMult+1);
pParsedCSD->WPGroupSize = (UCHAR)GET_BIT_SLICE_FROM_CSD(pCSD,MMC_CSD_WP_GROUP_SIZE_BIT_SLICE,
MMC_CSD_WP_GROUP_SIZE_SLICE_SIZE);
pParsedCSD->WPGroupSize++;
} else {
// Erase by block size enabled
pParsedCSD->EraseBlockEnable = GET_BIT_SLICE_FROM_CSD(pCSD,SD_CSD_ERASE_BL_ENABLE_BIT_SLICE,
SD_CSD_ERASE_BL_ENABLE_SLICE_SIZE)
? TRUE:FALSE;
// Erase Sector Size
pParsedCSD->EraseSectorSize = (UCHAR)GET_BIT_SLICE_FROM_CSD(pCSD,SD_CSD_ERASE_SECT_SIZE_BIT_SLICE,
SD_CSD_ERASE_SECT_SIZE_SLICE_SIZE);
pParsedCSD->EraseSectorSize++;
// Write Protect Group Size
pParsedCSD->WPGroupSize = (UCHAR)GET_BIT_SLICE_FROM_CSD(pCSD,SD_CSD_WP_GROUP_SIZE_BIT_SLICE,
SD_CSD_WP_GROUP_SIZE_SLICE_SIZE);
pParsedCSD->WPGroupSize++;
}
memcpy(pParsedCSD->RawCSDRegister, m_CachedRegisters.CSD, SD_CSD_REGISTER_SIZE );
DumpParsedCSDRegisters(pParsedCSD);
return SD_API_STATUS_SUCCESS;
}
SD_API_STATUS CSDDevice::InfoQueryRCA(PVOID pCardInfo, ULONG cbCardInfo)
{
PREFAST_DEBUGCHK(pCardInfo);
DEBUGCHK(cbCardInfo == sizeof(SD_CARD_RCA));
memcpy(pCardInfo, &m_RelativeAddress, sizeof(SD_CARD_RCA));
return SD_API_STATUS_SUCCESS;
}
SD_API_STATUS CSDDevice::InfoQueryCardInterface(PVOID pCardInfo,ULONG cbCardInfo)
{
PREFAST_DEBUGCHK(pCardInfo);
DEBUGCHK(cbCardInfo == sizeof(SD_CARD_INTERFACE_EX));
m_CardInterfaceEx.InterfaceModeEx.bit.sdHighCapacity = (IsHighCapacitySDMemory()?1: 0);
*(PSD_CARD_INTERFACE_EX)pCardInfo = m_CardInterfaceEx;
return SD_API_STATUS_SUCCESS;
}
SD_API_STATUS CSDDevice::InfoQueryStatus(
PVOID pCardInfo,
ULONG cbCardInfo
)
{
DEBUGCHK(pCardInfo);
DEBUGCHK(cbCardInfo == sizeof(SD_CARD_STATUS));
// get the card status
return GetCardStatus((SD_CARD_STATUS *)pCardInfo);
}
SD_API_STATUS CSDDevice::InfoQuerySDIOInfo(PVOID pCardInfo, ULONG cbCardInfo )
{
PREFAST_DEBUGCHK(pCardInfo);
DEBUGCHK(cbCardInfo == sizeof(SDIO_CARD_INFO));
if (Device_SD_IO != m_DeviceType || m_FuncionIndex==0) {
ASSERT(FALSE);
return SD_API_STATUS_INVALID_PARAMETER;
}
SD_API_STATUS status = SD_API_STATUS_INVALID_PARAMETER;
CSDDevice * device0 = m_sdSlot.GetFunctionDevice(0);
if (device0) {
__try {
((PSDIO_CARD_INFO)pCardInfo)->FunctionNumber = m_SDCardInfo.SDIOInformation.Function;
((PSDIO_CARD_INFO)pCardInfo)->DeviceCode = m_SDCardInfo.SDIOInformation.DeviceCode;
((PSDIO_CARD_INFO)pCardInfo)->CISPointer = m_SDCardInfo.SDIOInformation.CISPointer;
((PSDIO_CARD_INFO)pCardInfo)->CSAPointer = m_SDCardInfo.SDIOInformation.CSAPointer;
DEBUGCHK(device0->m_SDCardInfo.SDIOInformation.pCommonInformation != NULL);
((PSDIO_CARD_INFO)pCardInfo)->CardCapability =
device0->m_SDCardInfo.SDIOInformation.pCommonInformation->CardCapability;
status = SD_API_STATUS_SUCCESS;
}
__except(SDProcessException(GetExceptionInformation())) {
status = SD_API_STATUS_INVALID_PARAMETER;
}
device0->DeRef();
}
else {
ASSERT(FALSE);
}
return status;
}
SD_API_STATUS CSDDevice::InfoQueryHostInterface(PVOID pCardInfo,ULONG cbCardInfo )
{
PREFAST_DEBUGCHK(pCardInfo);
DEBUGCHK(cbCardInfo == sizeof(SD_CARD_INTERFACE));
PSD_CARD_INTERFACE pCardCapabilities = (PSD_CARD_INTERFACE)pCardInfo;
// fetch the max clock rate
pCardCapabilities->ClockRate = m_sdSlot.MaxClockRate;
// work out the best interface the HC can provide
if( m_sdSlot.Capabilities & SD_SLOT_SD_4BIT_CAPABLE ) {
pCardCapabilities->InterfaceMode = SD_INTERFACE_SD_4BIT;
} else {
pCardCapabilities->InterfaceMode = SD_INTERFACE_SD_MMC_1BIT;
}
// write protect is meaningless for a capability query, set to FALSE
pCardCapabilities->WriteProtected = FALSE;
return SD_API_STATUS_SUCCESS;
}
SD_API_STATUS CSDDevice::InfoQueryBlockCaps(PVOID pCardInfo,ULONG cbCardInfo )
{
DEBUGCHK(pCardInfo);
DEBUGCHK(cbCardInfo == sizeof(SD_HOST_BLOCK_CAPABILITY));
SD_HOST_BLOCK_CAPABILITY sdHostBLockCap = *(PSD_HOST_BLOCK_CAPABILITY)pCardInfo;
// send the requested block transfer size to the HC, if the HC is
// unable to support the requested block size it will return the
// next supported block size smaller than that requested
SD_API_STATUS status = m_sdSlot.GetHost().SlotOptionHandler(m_sdSlot.GetSlotIndex(),
SDHCDQueryBlockCapability,
&sdHostBLockCap,
sizeof(SD_HOST_BLOCK_CAPABILITY));
if (SD_API_SUCCESS(status)) {
*(PSD_HOST_BLOCK_CAPABILITY)pCardInfo = sdHostBLockCap;
}
return status;
}
///////////////////////////////////////////////////////////////////////////////
// SDCardInfoQuery__X - Obtain Card information
// Input: hHandle - SD Device Handle
// InfoType - information to get
// StructureSize - size of info structure
// Output: pCardInfo - Information specific structure
// Return: SD_API_STATUS code
// Notes: pCardInfo must point to sufficient memory for the informtion type
///////////////////////////////////////////////////////////////////////////////
SD_API_STATUS CSDDevice::SDCardInfoQuery_I( IN SD_INFO_TYPE InfoType,
OUT PVOID pCardInfo,
IN ULONG StructureSize)
{
DEBUGMSG(SDCARD_ZONE_FUNC, (TEXT("SDCard: +SDCardInfoQuery\n")));
SD_API_STATUS status = SD_API_STATUS_INVALID_PARAMETER;
__try {
switch (InfoType) {
case SD_INFO_REGISTER_OCR:
break;
case SD_INFO_REGISTER_CID:
if (StructureSize>=sizeof(SD_PARSED_REGISTER_CID) && pCardInfo!=NULL) {
status = InfoQueryCID(pCardInfo, StructureSize);
}
break;
case SD_INFO_REGISTER_CSD:
if (StructureSize>=sizeof(SD_PARSED_REGISTER_CSD) && pCardInfo!=NULL ) {
status = InfoQueryCSD(pCardInfo, StructureSize);
}
break;
case SD_INFO_REGISTER_RCA:
if (StructureSize>=sizeof(SD_CARD_RCA) && pCardInfo!=NULL) {
status = InfoQueryRCA(pCardInfo, StructureSize);
}
break;
case SD_INFO_REGISTER_IO_OCR:
break;
case SD_INFO_CARD_INTERFACE:
if (StructureSize>=sizeof(SD_CARD_INTERFACE) && pCardInfo!=NULL) {
SD_CARD_INTERFACE_EX sdCardInterfacEx;
status = InfoQueryCardInterface(&sdCardInterfacEx, sizeof(sdCardInterfacEx));
if (SD_API_SUCCESS(status)) {
*(PSD_CARD_INTERFACE)pCardInfo = ConvertFromEx(sdCardInterfacEx);
}
}
break;
case SD_INFO_CARD_INTERFACE_EX:
if (StructureSize>=sizeof(SD_CARD_INTERFACE_EX) && pCardInfo!=NULL) {
status = InfoQueryCardInterface((PSD_CARD_INTERFACE_EX)pCardInfo, sizeof(SD_CARD_INTERFACE_EX));
}
break;
case SD_INFO_CARD_STATUS:
if (StructureSize>=sizeof(SD_CARD_STATUS)&& pCardInfo!=NULL) {
status = InfoQueryStatus(pCardInfo, StructureSize);
}
break;
case SD_INFO_SDIO:
if ( StructureSize>=sizeof(SDIO_CARD_INFO) && pCardInfo!=NULL) {
status = InfoQuerySDIOInfo(pCardInfo, StructureSize);
}
break;
case SD_INFO_HOST_IF_CAPABILITIES:
if ( StructureSize>=sizeof(SD_CARD_INTERFACE) && pCardInfo!=NULL) {
status = InfoQueryHostInterface(pCardInfo, StructureSize);
}
break;
case SD_INFO_HOST_BLOCK_CAPABILITY:
if (StructureSize >= sizeof(SD_HOST_BLOCK_CAPABILITY) && pCardInfo!=NULL) {
status = InfoQueryBlockCaps(pCardInfo, StructureSize);
}
break;
case SD_INFO_HIGH_CAPACITY_SUPPORT:
if (StructureSize>= sizeof(DWORD) && pCardInfo!=NULL) {
SD_CARD_INTERFACE_EX sdCardInterfacEx;
status = InfoQueryCardInterface(&sdCardInterfacEx, sizeof(sdCardInterfacEx));
if (SD_API_SUCCESS(status)) {
*(PDWORD)pCardInfo = sdCardInterfacEx.InterfaceModeEx.bit.sdHighCapacity;
}
};
break;
case SD_INFO_SWITCH_FUNCTION:
if (StructureSize>= sizeof(SD_CARD_SWITCH_FUNCTION) && pCardInfo!=NULL) {
status =SwitchFunction((PSD_CARD_SWITCH_FUNCTION)pCardInfo, TRUE);
}
break;
}
}__except(SDProcessException(GetExceptionInformation())) {
status = SD_API_STATUS_ACCESS_VIOLATION;
};
DEBUGMSG(SDCARD_ZONE_FUNC, (TEXT("SDCard: -SDCardInfoQuery status = %x\n"),status));
return status;
}
// Shifts pbInput down by dwBitOffset.
static
VOID
ShiftBytes(PBYTE pbInput, ULONG cbInput, DWORD dwBitOffset, PBYTE pbOutput)
{
PREFAST_DEBUGCHK(pbInput);
PREFAST_DEBUGCHK(pbOutput);
DWORD dwByteIndex = dwBitOffset / 8;
dwBitOffset %= 8;
DWORD dwRemainderShift = 8 - dwBitOffset;
// Only copy 4 bytes max.
DWORD dwEndIndex = min(dwByteIndex + sizeof(DWORD), cbInput);
DWORD dwCurrOutputIndex = 0;
while (dwByteIndex < dwEndIndex) {
DEBUGCHK(dwCurrOutputIndex < sizeof(DWORD));
DEBUGCHK(dwByteIndex < cbInput);
pbOutput[dwCurrOutputIndex] = pbInput[dwByteIndex] >> dwBitOffset;
++dwByteIndex;
if (dwByteIndex != cbInput) {
BYTE bTemp = pbInput[dwByteIndex];
bTemp <<= dwRemainderShift;
pbOutput[dwCurrOutputIndex] |= bTemp;
}
++dwCurrOutputIndex;
}
}
///////////////////////////////////////////////////////////////////////////////
// GetBitSlice - Get a bit slice from a stream of bytes
// Input: pBuffer - buffer containing data stream
// cbBuffer - size of buffer in bytes
// dwBitOffset - bit offset from start of buffer
// ucBitCount - number of bits (less than or equal to 32)
// Output:
//
// Return: returns a DWORD contain the bit slice shifted to fill the least significant bits
// Notes: will raise an SEH exception if integer overflow occurs
///////////////////////////////////////////////////////////////////////////////
DWORD CSDDevice::GetBitSlice(PUCHAR pBuffer, ULONG cbBuffer, DWORD dwBitOffset, UCHAR ucBitCount)
{
UCHAR rgbShifted[4] = { 0 };
if (ucBitCount > 32) {
DEBUG_CHECK(FALSE, (TEXT("GetBitSlice: invalid number of bits \n")));
return 0;
}
typedef SafeInt<DWORD> SafeDW;
// Exception will be raised on the next line if there is an overflow.
if ( (SafeDW(dwBitOffset) + SafeDW(ucBitCount)) > (SafeDW(cbBuffer) * 8) ) {
DEBUG_CHECK(FALSE, (TEXT("GetBitSlice: invalid bit offset given the number of bits \n")));
return 0;
}
// Shift the pBuffer down by dwBitOffset bits.
ShiftBytes(pBuffer, cbBuffer, dwBitOffset, rgbShifted);
DWORD dwUsedBytes; // How many bytes have valid data.
if (ucBitCount % 8 == 0) {
// Return a byte multiple.
dwUsedBytes = ucBitCount / 8;
}
else {
// Clear the last used byte of upper bits.
DWORD dwLastByteIndex = (ucBitCount - 1) / 8;
DWORD dwRemainderShift = 8 - (ucBitCount % 8);
rgbShifted[dwLastByteIndex] <<= dwRemainderShift;
rgbShifted[dwLastByteIndex] >>= dwRemainderShift;
dwUsedBytes = dwLastByteIndex + 1;
}
// Clear the unused bytes.
if (dwUsedBytes != sizeof(rgbShifted)) {
memset(rgbShifted + dwUsedBytes, 0, sizeof(rgbShifted) - dwUsedBytes);
}
DWORD dwRet;
memcpy(&dwRet, rgbShifted, sizeof(dwRet));
return dwRet;
}
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -