From 5ffefbe9456217f4dbeb655137fc040605ba89c0 Mon Sep 17 00:00:00 2001 From: Vadim Galyant Date: Sat, 9 Dec 2017 17:15:40 +0900 Subject: [PATCH] [USBPORT] Add USB2_GetCMASK(). --- drivers/usb/usbport/usb2.c | 73 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 73 insertions(+) diff --git a/drivers/usb/usbport/usb2.c b/drivers/usb/usbport/usb2.c index d9742388545..d234c7e3904 100644 --- a/drivers/usb/usbport/usb2.c +++ b/drivers/usb/usbport/usb2.c @@ -564,6 +564,79 @@ USB2_GetSMASK(IN PUSB2_TT_ENDPOINT TtEndpoint) return SMask; } +UCHAR +NTAPI +USB2_GetCMASK(IN PUSB2_TT_ENDPOINT TtEndpoint) +{ + ULONG NumCompletes; + ULONG TransferType; + ULONG DeviceSpeed; + ULONG Direction; + UCHAR Result; + UCHAR MicroFrameCS; + UCHAR HcFrame; + UCHAR HcMicroFrame; + UCHAR MaskCS = 0; + static const UCHAR CMASKS[USB2_MICROFRAMES] = { + 0x1C, 0x38, 0x70, 0xE0, 0xC1, 0x83, 0x07, 0x0E + }; + + TransferType = TtEndpoint->TtEndpointParams.TransferType; + DeviceSpeed = TtEndpoint->TtEndpointParams.DeviceSpeed; + Direction = TtEndpoint->TtEndpointParams.Direction; + + if (DeviceSpeed == UsbHighSpeed) + { + return 0; + } + + if (TransferType == USBPORT_TRANSFER_TYPE_INTERRUPT) + { + USB2_ConvertFrame(TtEndpoint->StartFrame, + TtEndpoint->StartMicroframe, + &HcFrame, + &HcMicroFrame); + + Result = CMASKS[HcMicroFrame]; + } + else + { + if (Direction == USBPORT_TRANSFER_DIRECTION_OUT) + { + return 0; + } + + USB2_ConvertFrame(TtEndpoint->StartFrame, + TtEndpoint->StartMicroframe, + &HcFrame, + &HcMicroFrame); + + NumCompletes = TtEndpoint->Nums.NumCompletes; + + for (MicroFrameCS = HcMicroFrame + 2; + MicroFrameCS < USB2_MICROFRAMES; + MicroFrameCS++) + { + MaskCS |= (1 << MicroFrameCS); + NumCompletes--; + + if (!NumCompletes) + { + return MaskCS; + } + } + + for (; NumCompletes; NumCompletes--) + { + MaskCS |= (1 << (MicroFrameCS - USB2_MICROFRAMES)); + } + + Result = MaskCS; + } + + return Result; +} + BOOLEAN NTAPI USB2_DeallocateEndpointBudget(IN PUSB2_TT_ENDPOINT TtEndpoint,