fix polling of some USB hubs

git-svn-id: svn://kolibrios.org@4227 a494cfbc-eb01-0410-851d-a64ba20cac60
This commit is contained in:
CleverMouse 2013-11-14 10:16:38 +00:00
parent d4a48eed94
commit 79585a5d9b

View File

@ -105,6 +105,9 @@ ConfigPipe dd ?
StatusPipe dd ? StatusPipe dd ?
NumPorts dd ? NumPorts dd ?
; Number of downstream ports; from 1 to 255. ; Number of downstream ports; from 1 to 255.
MaxPacketSize dd ?
; Maximum packet size for interrupt endpoint.
; Usually equals ceil((1+NumPorts)/8), but some hubs give additional bytes.
Actions dd ? Actions dd ?
; Bitfield with HUB_* constants. ; Bitfield with HUB_* constants.
PoweredOnTime dd ? PoweredOnTime dd ?
@ -250,10 +253,11 @@ end virtual
; the pointer is in edx. ; the pointer is in edx.
; 2. Allocate memory for the hub descriptor. ; 2. Allocate memory for the hub descriptor.
; Maximum length (assuming 255 downstream ports) is 40 bytes. ; Maximum length (assuming 255 downstream ports) is 40 bytes.
; Allocate 4 extra bytes to keep wMaxPacketSize.
; 2a. Save registers. ; 2a. Save registers.
push edx push edx
; 2b. Call the allocator. ; 2b. Call the allocator.
movi eax, 40 movi eax, 44
call malloc call malloc
; 2c. Restore registers. ; 2c. Restore registers.
pop ecx pop ecx
@ -267,7 +271,11 @@ end virtual
movzx eax, [ecx+usb_endpoint_descr.bEndpointAddress] movzx eax, [ecx+usb_endpoint_descr.bEndpointAddress]
movzx edx, [ecx+usb_endpoint_descr.bInterval] movzx edx, [ecx+usb_endpoint_descr.bInterval]
movzx ecx, [ecx+usb_endpoint_descr.wMaxPacketSize] movzx ecx, [ecx+usb_endpoint_descr.wMaxPacketSize]
test ecx, (1 shl 11) - 1
jz .free
push ecx
stdcall usb_open_pipe, ebx, eax, ecx, INTERRUPT_PIPE, edx stdcall usb_open_pipe, ebx, eax, ecx, INTERRUPT_PIPE, edx
pop ecx
; If failed, free the memory allocated in step 2, ; If failed, free the memory allocated in step 2,
; say something to the debug board and return error. ; say something to the debug board and return error.
test eax, eax test eax, eax
@ -275,6 +283,8 @@ end virtual
; 4. Send control query for the hub descriptor, ; 4. Send control query for the hub descriptor,
; pass status pipe as a callback parameter, ; pass status pipe as a callback parameter,
; allow short packets. ; allow short packets.
and ecx, (1 shl 11) - 1
mov [esi+40], ecx
mov dword [esi], 0xA0 + \ ; class-specific request mov dword [esi], 0xA0 + \ ; class-specific request
(USB_GET_DESCRIPTOR shl 8) + \ (USB_GET_DESCRIPTOR shl 8) + \
(0 shl 16) + \ ; descriptor index 0 (0 shl 16) + \ ; descriptor index 0
@ -352,8 +362,9 @@ end if
cmp [length], edx cmp [length], edx
jb .invalid jb .invalid
; 5. Allocate the memory for usb_hub structure. ; 5. Allocate the memory for usb_hub structure.
; Total size of variable-length data is ALIGN_UP(2*(floor(NumPorts/8)+1),4)+8*NumPorts. ; Total size of variable-length data is ALIGN_UP(floor(NumPorts/8)+1+MaxPacketSize,4)+8*NumPorts.
lea edx, [sizeof.usb_hub+(edx-sizeof.usb_hub_descr)*2+3] add edx, [eax+40]
add edx, sizeof.usb_hub - sizeof.usb_hub_descr + 3
and edx, not 3 and edx, not 3
lea eax, [edx+ecx*8] lea eax, [edx+ecx*8]
push ecx edx push ecx edx
@ -374,6 +385,8 @@ end if
mov [ebx+usb_hub.StatusPipe], eax mov [ebx+usb_hub.StatusPipe], eax
push esi edi push esi edi
mov esi, [buffer] mov esi, [buffer]
mov eax, [esi+40]
mov [ebx+usb_hub.MaxPacketSize], eax
; The following commands load bNbrPorts, wHubCharacteristics, bPwrOn2PwrGood. ; The following commands load bNbrPorts, wHubCharacteristics, bPwrOn2PwrGood.
mov edx, dword [esi+usb_hub_descr.bNbrPorts] mov edx, dword [esi+usb_hub_descr.bNbrPorts]
mov dl, 0 mov dl, 0
@ -487,11 +500,8 @@ endp
; Called when initial configuration is done and when a previous notification ; Called when initial configuration is done and when a previous notification
; has been processed. ; has been processed.
proc usb_hub_wait_change proc usb_hub_wait_change
mov ecx, [eax+usb_hub.NumPorts]
shr ecx, 3
inc ecx
stdcall usb_normal_transfer_async, [eax+usb_hub.StatusPipe], \ stdcall usb_normal_transfer_async, [eax+usb_hub.StatusPipe], \
[eax+usb_hub.StatusChangePtr], ecx, usb_hub_changed, eax, 1 [eax+usb_hub.StatusChangePtr], [eax+usb_hub.MaxPacketSize], usb_hub_changed, eax, 1
ret ret
endp endp
@ -513,6 +523,7 @@ proc usb_hub_changed stdcall, pipe:dword, status:dword, buffer:dword, length:dwo
shr ecx, 3 shr ecx, 3
inc ecx inc ecx
sub ecx, [length] sub ecx, [length]
jbe .restart
push eax edi push eax edi
mov edi, [buffer] mov edi, [buffer]
add edi, [length] add edi, [length]