NDIS_STATUS sdioConfigProperty(IN PDEVICE_EXTENSION prDevExt, IN SD_REQUEST_FUNCTION eRequestFunction, IN SDBUS_PROPERTY eProperty, OUT PUINT_8 aucBuffer, IN UINT_32 u4BufLen) { PSDBUS_REQUEST_PACKET prSDRP = NULL; NDIS_STATUS rStatus; /* retrieve the function number from the bus driver */ prSDRP = ExAllocatePoolWithTag(NonPagedPool, sizeof(SDBUS_REQUEST_PACKET), 'SDIO'); if (!prSDRP) return STATUS_INSUFFICIENT_RESOURCES; RtlZeroMemory(prSDRP, sizeof(SDBUS_REQUEST_PACKET)); prSDRP->RequestFunction = eRequestFunction; prSDRP->Parameters.GetSetProperty.Property = eProperty; prSDRP->Parameters.GetSetProperty.Buffer = aucBuffer; prSDRP->Parameters.GetSetProperty.Length = u4BufLen; rStatus = SdBusSubmitRequest(prDevExt->BusInterface.Context, prSDRP); ExFreePool(prSDRP); if (!NT_SUCCESS(rStatus)) ERRORLOG(("SdBusSubmitRequest fail, status:%x\n", rStatus)); return rStatus; }
NTSTATUS SdioReadWriteBuffer( IN WDFDEVICE Device, IN ULONG Function, IN PMDL Mdl, IN ULONG Address, IN ULONG Length, IN BOOLEAN WriteToDevice, OUT PULONG BytesRead ) { PFDO_DATA fdoData; SDBUS_REQUEST_PACKET sdrp; SD_RW_EXTENDED_ARGUMENT extendedArgument; NTSTATUS status; const SDCMD_DESCRIPTOR ReadIoExtendedDesc = {SDCMD_IO_RW_EXTENDED, SDCC_STANDARD, SDTD_READ, SDTT_SINGLE_BLOCK, SDRT_5}; const SDCMD_DESCRIPTOR WriteIoExtendedDesc = {SDCMD_IO_RW_EXTENDED, SDCC_STANDARD, SDTD_WRITE, SDTT_SINGLE_BLOCK, SDRT_5}; //PAGED_CODE(); fdoData = MarsFdoGetData(Device); RtlZeroMemory(&sdrp, sizeof(SDBUS_REQUEST_PACKET)); sdrp.RequestFunction = SDRF_DEVICE_COMMAND; sdrp.Parameters.DeviceCommand.Mdl = Mdl; extendedArgument.u.AsULONG = 0; extendedArgument.u.bits.Function = Function; extendedArgument.u.bits.OpCode = 1; // increment address extendedArgument.u.bits.BlockMode = fdoData->BlockMode; extendedArgument.u.bits.Address = Address; if (WriteToDevice) { extendedArgument.u.bits.WriteToDevice = 1; sdrp.Parameters.DeviceCommand.CmdDesc = WriteIoExtendedDesc; } else { sdrp.Parameters.DeviceCommand.CmdDesc = ReadIoExtendedDesc; } if (fdoData->BlockMode == 1) { sdrp.Parameters.DeviceCommand.CmdDesc.TransferType = SDTT_MULTI_BLOCK_NO_CMD12; } sdrp.Parameters.DeviceCommand.Argument = extendedArgument.u.AsULONG; sdrp.Parameters.DeviceCommand.Length = Length; // // Send the IO request down to the bus driver // status = SdBusSubmitRequest(fdoData->BusInterface.Context, &sdrp); *BytesRead = (ULONG)sdrp.Information; return status; }
NTSTATUS SdioGetProperty( IN WDFDEVICE Device, IN SDBUS_PROPERTY Property, IN PVOID Buffer, IN ULONG Length ) { PFDO_DATA fdoData; SDBUS_REQUEST_PACKET sdrp; fdoData = MarsFdoGetData(Device); RtlZeroMemory(&sdrp, sizeof(SDBUS_REQUEST_PACKET)); sdrp.RequestFunction = SDRF_GET_PROPERTY; sdrp.Parameters.GetSetProperty.Property = Property; sdrp.Parameters.GetSetProperty.Buffer = Buffer; sdrp.Parameters.GetSetProperty.Length = Length; return SdBusSubmitRequest(fdoData->BusInterface.Context, &sdrp); }
/*----------------------------------------------------------------------------*/ BOOL kalDevRegRead(IN P_GLUE_INFO_T prGlueInfo, IN UINT_32 u4Register, OUT PUINT_32 pu4Value) { PDEVICE_EXTENSION prDevExt = &prGlueInfo->rHifInfo.dx; PSDBUS_REQUEST_PACKET prSDRP = (PSDBUS_REQUEST_PACKET) NULL; SD_RW_EXTENDED_ARGUMENT rSdIoArgument; PMDL prMdl = (PMDL) NULL; UINT_32 u4Length; NDIS_STATUS rStatus; const SDCMD_DESCRIPTOR rReadIoExtendedDesc = { SDCMD_IO_RW_EXTENDED, SDCC_STANDARD, SDTD_READ, SDTT_SINGLE_BLOCK, SDRT_5 }; ASSERT(prGlueInfo); ASSERT(pu4Value); /* First get a MDL to map the data. This code assumes the * caller passed a buffer to nonpaged pool. */ u4Length = 4; prMdl = IoAllocateMdl(pu4Value, u4Length, FALSE, FALSE, NULL); if (!prMdl) { ERRORLOG(("IoAllocateMdl prMdl fail!\n")); return FALSE; } MmBuildMdlForNonPagedPool(prMdl); /* Now allocate a request packet for the arguments of the command */ prSDRP = ExAllocatePoolWithTag(NonPagedPool, sizeof(SDBUS_REQUEST_PACKET), 'SDIO'); if (!prSDRP) { IoFreeMdl(prMdl); ERRORLOG(("ExAllocatePool prSDRP fail!\n")); return FALSE; } RtlZeroMemory(prSDRP, sizeof(SDBUS_REQUEST_PACKET)); prSDRP->RequestFunction = SDRF_DEVICE_COMMAND; prSDRP->Parameters.DeviceCommand.CmdDesc = rReadIoExtendedDesc; /* Set up the argument and command descriptor */ rSdIoArgument.u.AsULONG = 0; /* NOTE(Kevin): This will be ignored when using a device command */ rSdIoArgument.u.bits.Count = u4Length; rSdIoArgument.u.bits.Address = u4Register; rSdIoArgument.u.bits.OpCode = 1; /* Function # must be initialized by SdBus GetProperty call */ rSdIoArgument.u.bits.Function = prDevExt->FunctionNumber; /* Submit the request */ rSdIoArgument.u.bits.WriteToDevice = 0; prSDRP->Parameters.DeviceCommand.Argument = rSdIoArgument.u.AsULONG; prSDRP->Parameters.DeviceCommand.Mdl = prMdl; prSDRP->Parameters.DeviceCommand.Length = u4Length; /* unit in bytes */ rStatus = SdBusSubmitRequest(prDevExt->BusInterface.Context, prSDRP); IoFreeMdl(prMdl); ExFreePool(prSDRP); if (NT_SUCCESS(rStatus)) { return TRUE; } else { ERRORLOG(("MCR RD FAIL!, addr: %#08lx, status: %x\n", u4Register, rStatus)); return FALSE; } } /* end of kalDevRegRead() */
/*----------------------------------------------------------------------------*/ BOOLEAN sdioCmd53BlockWrite(PDEVICE_EXTENSION prDx, UINT_16 u2Port, PUCHAR pucBuffer, UINT_16 u4ByteCount) { PSDBUS_REQUEST_PACKET prSDRP = (PSDBUS_REQUEST_PACKET) NULL; SD_RW_EXTENDED_ARGUMENT rSdIoArgument; PMDL prMdl = (PMDL) NULL; NDIS_STATUS rStatus; const SDCMD_DESCRIPTOR rReadWriteIoExtendedDesc = { SDCMD_IO_RW_EXTENDED, SDCC_STANDARD, SDTD_WRITE, SDTT_MULTI_BLOCK_NO_CMD12, SDRT_5 }; ASSERT(prDx); ASSERT(pucBuffer); /* First get a MDL to map the data. This code assumes the * caller passed a buffer to nonpaged pool. */ prMdl = IoAllocateMdl(pucBuffer, u4ByteCount, FALSE, FALSE, NULL); if (!prMdl) { ERRORLOG(("IoAllocateMdl prMdl fail!\n")); return FALSE; } MmBuildMdlForNonPagedPool(prMdl); /* Now allocate a request packet for the arguments of the command */ prSDRP = ExAllocatePoolWithTag(NonPagedPool, sizeof(SDBUS_REQUEST_PACKET), 'SDIO'); if (!prSDRP) { IoFreeMdl(prMdl); ERRORLOG(("ExAllocatePool prSDRP fail!\n")); return FALSE; } RtlZeroMemory(prSDRP, sizeof(SDBUS_REQUEST_PACKET)); prSDRP->RequestFunction = SDRF_DEVICE_COMMAND; prSDRP->Parameters.DeviceCommand.CmdDesc = rReadWriteIoExtendedDesc; /* Set up the argument and command descriptor */ rSdIoArgument.u.AsULONG = 0; rSdIoArgument.u.bits.Count = u4ByteCount; /* Will be ignored when submitting a device command. */ rSdIoArgument.u.bits.Address = u2Port; rSdIoArgument.u.bits.OpCode = 0; rSdIoArgument.u.bits.BlockMode = 1; /* NOTE(Kevin): Block Mode in XP SP2 test fail and crash. */ /* Function # must be initialized by SdBus GetProperty call */ rSdIoArgument.u.bits.Function = prDx->FunctionNumber; /* Submit the request */ rSdIoArgument.u.bits.WriteToDevice = 1; prSDRP->Parameters.DeviceCommand.Argument = rSdIoArgument.u.AsULONG; prSDRP->Parameters.DeviceCommand.Mdl = prMdl; prSDRP->Parameters.DeviceCommand.Length = u4ByteCount; rStatus = SdBusSubmitRequest(prDx->BusInterface.Context, prSDRP); IoFreeMdl(prMdl); ExFreePool(prSDRP); if (NT_SUCCESS(rStatus)) { return TRUE; } else { ERRORLOG(("CMD53 BLOCK WR FAIL!, addr: %#04x, status: %x\n", u2Port, rStatus)); return FALSE; } } /* end of sdioCmd53BlockWrite() */
/*----------------------------------------------------------------------------*/ BOOLEAN sdioCmd52ByteReadWrite(PDEVICE_EXTENSION prDx, UINT_32 u4Address, PUCHAR pucData, UCHAR ucFuncNo, SD_TRANSFER_DIRECTION rRwFlag) { PSDBUS_REQUEST_PACKET prSDRP = (PSDBUS_REQUEST_PACKET) NULL; SD_RW_DIRECT_ARGUMENT rSdIoArgument; NDIS_STATUS rStatus; const SDCMD_DESCRIPTOR rReadWriteIoDirectDesc = { SDCMD_IO_RW_DIRECT, SDCC_STANDARD, rRwFlag, SDTT_CMD_ONLY, SDRT_5 }; ASSERT(prDx); ASSERT(pucData); prSDRP = ExAllocatePoolWithTag(NonPagedPool, sizeof(SDBUS_REQUEST_PACKET), 'SDIO'); if (!prSDRP) { ERRORLOG(("ExAllocatePool prSDRP fail!\n")); return FALSE; } RtlZeroMemory(prSDRP, sizeof(SDBUS_REQUEST_PACKET)); prSDRP->RequestFunction = SDRF_DEVICE_COMMAND; prSDRP->Parameters.DeviceCommand.CmdDesc = rReadWriteIoDirectDesc; /* Set up the argument and command descriptor */ rSdIoArgument.u.AsULONG = 0; rSdIoArgument.u.bits.Address = u4Address; /* Function # must be initialized by SdBus GetProperty call */ rSdIoArgument.u.bits.Function = ucFuncNo; /* Submit the request */ if (rRwFlag == SDTD_WRITE) { rSdIoArgument.u.bits.WriteToDevice = 1; rSdIoArgument.u.bits.Data = *pucData; } prSDRP->Parameters.DeviceCommand.Argument = rSdIoArgument.u.AsULONG; rStatus = SdBusSubmitRequest(prDx->BusInterface.Context, prSDRP); if (rRwFlag == SDTD_READ) *pucData = prSDRP->ResponseData.AsUCHAR[0]; ExFreePool(prSDRP); if (NT_SUCCESS(rStatus)) { return TRUE; } else { if (rRwFlag == SDTD_READ) ERRORLOG(("CMD52 RD FAIL!, status:%x\n", rStatus)); else ERRORLOG(("CMD52 WR FAIL!, status:%x\n", rStatus)); return FALSE; } } /* end of sdioCmd52ByteReadWrite() */
NTSTATUS SdioReadWriteByte( IN WDFDEVICE Device, IN ULONG Function, IN PUCHAR Data, IN ULONG Address, IN BOOLEAN WriteToDevice ) /*++ --*/ { PFDO_DATA fdoData; NTSTATUS status; SDBUS_REQUEST_PACKET sdrp; SD_RW_DIRECT_ARGUMENT directArgument; const SDCMD_DESCRIPTOR ReadIoDirectDesc = {SDCMD_IO_RW_DIRECT, SDCC_STANDARD, SDTD_READ, SDTT_CMD_ONLY, SDRT_5}; const SDCMD_DESCRIPTOR WriteIoDirectDesc = {SDCMD_IO_RW_DIRECT, SDCC_STANDARD, SDTD_WRITE, SDTT_CMD_ONLY, SDRT_5}; // // get an SD request packet // fdoData = MarsFdoGetData(Device); RtlZeroMemory(&sdrp, sizeof(SDBUS_REQUEST_PACKET)); sdrp.RequestFunction = SDRF_DEVICE_COMMAND; directArgument.u.AsULONG = 0; directArgument.u.bits.Function = Function; directArgument.u.bits.Address = Address; if (WriteToDevice) { directArgument.u.bits.WriteToDevice = 1; directArgument.u.bits.Data = *Data; sdrp.Parameters.DeviceCommand.CmdDesc = WriteIoDirectDesc; } else { sdrp.Parameters.DeviceCommand.CmdDesc = ReadIoDirectDesc; } sdrp.Parameters.DeviceCommand.Argument = directArgument.u.AsULONG; // // Send the IO request down to the bus driver // status = SdBusSubmitRequest(fdoData->BusInterface.Context, &sdrp); if (NT_SUCCESS(status) && !WriteToDevice) { *Data = sdrp.ResponseData.AsUCHAR[0]; } return status; }