@@ -505,6 +505,9 @@ EHCI_OpenInterruptEndpoint(IN PEHCI_EXTENSION EhciExtension,
505505 return MP_STATUS_SUCCESS ;
506506}
507507
508+ #define ROUND_DOWN (n , align ) (((ULONG)n) & ~((align) - 1l))
509+ #define ROUND_UP (n , align ) ROUND_DOWN(((ULONG)n) + (align) - 1, (align))
510+
508511MPSTATUS
509512NTAPI
510513EHCI_OpenHsIsoEndpoint (IN PEHCI_EXTENSION EhciExtension ,
@@ -516,7 +519,7 @@ EHCI_OpenHsIsoEndpoint(IN PEHCI_EXTENSION EhciExtension,
516519 ULONG ItdCount ;
517520 PEHCI_HCD_ITD ITD ;
518521 ULONG ix ;
519-
522+ ULONG Size ;
520523 DPRINT ("EHCI_OpenHsIsoEndpoint: EhciEndpoint - %p\n" , EhciEndpoint );
521524
522525 RtlCopyMemory (& EhciEndpoint -> EndpointProperties ,
@@ -528,7 +531,7 @@ EHCI_OpenHsIsoEndpoint(IN PEHCI_EXTENSION EhciExtension,
528531
529532 /* Calculate iTD count and pointers */
530533 ItdCount = EndpointProperties -> BufferLength / sizeof (EHCI_HCD_ITD );
531-
534+
532535 if (ItdCount == 0 )
533536 {
534537 return MP_STATUS_NO_RESOURCES ;
@@ -541,6 +544,7 @@ EHCI_OpenHsIsoEndpoint(IN PEHCI_EXTENSION EhciExtension,
541544 EhciEndpoint -> MaxITDs = ItdCount ;
542545 EhciEndpoint -> RemainITDs = ItdCount ;
543546
547+ Size = ROUND_UP (sizeof (EHCI_HCD_ITD ), 32 );
544548 /* Initialize all iTDs in the buffer */
545549 for (ix = 0 ; ix < ItdCount ; ix ++ )
546550 {
@@ -554,7 +558,7 @@ EHCI_OpenHsIsoEndpoint(IN PEHCI_EXTENSION EhciExtension,
554558 ITD -> EhciEndpoint = EhciEndpoint ;
555559 ITD -> EhciTransfer = NULL ;
556560
557- FirstItdPA += sizeof ( EHCI_HCD_ITD ) ;
561+ FirstItdPA += Size ;
558562 }
559563
560564 /* Initialize isochronous endpoint specific fields */
@@ -592,7 +596,7 @@ EHCI_OpenIsoEndpoint(IN PEHCI_EXTENSION EhciExtension,
592596
593597 /* Calculate siTD count and pointers */
594598 SitdCount = EndpointProperties -> BufferLength / sizeof (EHCI_HCD_SITD );
595-
599+
596600 if (SitdCount == 0 )
597601 {
598602 return MP_STATUS_NO_RESOURCES ;
@@ -2636,7 +2640,7 @@ EHCI_SubmitIsoTransfer(IN PVOID ehciExtension,
26362640
26372641 MaxPacketSize = EhciEndpoint -> EndpointProperties .MaxPacketSize ;
26382642 TransferLength = TransferParameters -> TransferBufferLength ;
2639-
2643+
26402644 /* For ISO transfers, we'll need to use the DMA buffer from the endpoint
26412645 * or extract from isoParameters - simplified for now */
26422646 BufferPA = EhciEndpoint -> DmaBufferPA ;
@@ -2677,12 +2681,12 @@ EHCI_SubmitIsoTransfer(IN PVOID ehciExtension,
26772681 /* Link iTD into the frame list */
26782682 LinkPointer .AsULONG = HcResourcesVA -> PeriodicFrameList [FrameIndex ];
26792683 ITD -> HwTD .NextLink = LinkPointer ;
2680-
2684+
26812685 LinkPointer .AsULONG = ITD -> PhysicalAddress ;
26822686 LinkPointer .Type = EHCI_LINK_TYPE_iTD ;
26832687 LinkPointer .Terminate = 0 ;
26842688 LinkPointer .Reserved = 0 ;
2685-
2689+
26862690 HcResourcesVA -> PeriodicFrameList [FrameIndex ] = LinkPointer .AsULONG ;
26872691
26882692 /* Store scheduling information for later cleanup */
@@ -2730,7 +2734,7 @@ EHCI_AbortIsoTransfer(IN PEHCI_EXTENSION EhciExtension,
27302734 ULONG ix ;
27312735
27322736 DPRINT ("EHCI_AbortIsoTransfer: Aborting high-speed ISO transfer\n" );
2733-
2737+
27342738 /* Find iTDs belonging to this transfer and abort them */
27352739 ITD = EhciEndpoint -> FirstITD ;
27362740 for (ix = 0 ; ix < EhciEndpoint -> MaxITDs ; ix ++ )
@@ -2775,7 +2779,7 @@ EHCI_AbortIsoTransfer(IN PEHCI_EXTENSION EhciExtension,
27752779 {
27762780 /* Abort full-speed/low-speed isochronous transfer using siTD */
27772781 DPRINT ("EHCI_AbortIsoTransfer: Aborting full/low-speed ISO transfer\n" );
2778-
2782+
27792783 /* TODO: Implement siTD abort logic similar to iTD */
27802784 }
27812785
@@ -4054,7 +4058,7 @@ EHCI_InitializeITD(IN PEHCI_EXTENSION EhciExtension,
40544058 ITD -> HwTD .Buffer [0 ].AsULONG = BufferPhysicalAddress & ~0xFFF ;
40554059 ITD -> HwTD .Buffer [0 ].DeviceAddress = DeviceAddress ;
40564060 ITD -> HwTD .Buffer [0 ].EndpointNumber = EndpointNumber ;
4057-
4061+
40584062 /* Setup buffer 1 with additional info */
40594063 ITD -> HwTD .Buffer [1 ].MaximumPacketSize = EndpointProperties -> MaxPacketSize ;
40604064 ITD -> HwTD .Buffer [1 ].Direction = Direction ;
@@ -4109,7 +4113,7 @@ EHCI_ProcessCompletedITD(IN PEHCI_EXTENSION EhciExtension,
41094113 /* Check for errors */
41104114 if (Status & 0x8 ) /* Transaction Error */
41114115 {
4112- DPRINT1 ("EHCI_ProcessCompletedITD: Transaction %d error, status 0x%x\n" ,
4116+ DPRINT1 ("EHCI_ProcessCompletedITD: Transaction %d error, status 0x%x\n" ,
41134117 TransactionIndex , Status );
41144118 EhciTransfer -> USBDStatus = USBD_STATUS_ERROR ;
41154119 }
@@ -4166,7 +4170,7 @@ EHCI_UnlinkITDFromFrameList(IN PEHCI_EXTENSION EhciExtension,
41664170
41674171 /* Search and unlink from frame list - simplified version */
41684172 CurrentLink = (EHCI_LINK_POINTER * )& HcResourcesVA -> PeriodicFrameList [FrameIndex ];
4169-
4173+
41704174 if ((CurrentLink -> AsULONG & LINK_POINTER_MASK ) == TargetPhysicalAddress &&
41714175 CurrentLink -> Type == EHCI_LINK_TYPE_iTD )
41724176 {
@@ -4215,14 +4219,14 @@ EHCI_CheckIsoBandwidth(IN PEHCI_EXTENSION EhciExtension,
42154219 {
42164220 /* High-speed: bandwidth per microframe */
42174221 RequiredBandwidth = MaxPacketSize ;
4218-
4222+
42194223 /* Add overhead and safety margin */
42204224 RequiredBandwidth += 64 ; /* Protocol overhead */
4221-
4225+
42224226 /* Simple check: ensure we don't exceed 80% of frame time */
42234227 if (RequiredBandwidth > (188 * 8 * 80 / 100 )) /* 80% of max HS bandwidth */
42244228 {
4225- DPRINT1 ("EHCI_CheckIsoBandwidth: High-speed bandwidth requirement too high: %d\n" ,
4229+ DPRINT1 ("EHCI_CheckIsoBandwidth: High-speed bandwidth requirement too high: %d\n" ,
42264230 RequiredBandwidth );
42274231 return FALSE;
42284232 }
@@ -4231,14 +4235,14 @@ EHCI_CheckIsoBandwidth(IN PEHCI_EXTENSION EhciExtension,
42314235 {
42324236 /* Full/Low-speed: bandwidth per frame */
42334237 RequiredBandwidth = MaxPacketSize ;
4234-
4238+
42354239 /* Add split transaction overhead */
42364240 RequiredBandwidth += 128 ; /* Split transaction overhead */
4237-
4241+
42384242 /* Simple check: ensure we don't exceed 90% of frame time for FS */
42394243 if (RequiredBandwidth > (1023 * 90 / 100 )) /* 90% of max FS bandwidth per frame */
42404244 {
4241- DPRINT1 ("EHCI_CheckIsoBandwidth: Full-speed bandwidth requirement too high: %d\n" ,
4245+ DPRINT1 ("EHCI_CheckIsoBandwidth: Full-speed bandwidth requirement too high: %d\n" ,
42424246 RequiredBandwidth );
42434247 return FALSE;
42444248 }
0 commit comments