📄 usbbb.asm
字号:
mov (DeviceInfo PTR [si]).CntrlXfer.wRequest, USB_RQ_GET_CLASS_DESCRIPTOR
mov (DeviceInfo PTR [si]).CntrlXfer.wValue, DESC_TYPE_CLASS_HUB
mov (DeviceInfo PTR [si]).CntrlXfer.wIndex, 0
mov bx, CurrentHC.pHCDPointer
; Issue the HCD control transfer call
call (BBHCDHEADER PTR CS:[bx]).pHCDControlTransfer
pop bx
pop eax
ret
USBBB_GetHubDescriptor ENDP
;<AMI_PHDR_START>
;----------------------------------------------------------------------------
; Procedure: USBBB_EnableHubPort
;
; Description: This procedure will power up and enable the specified port
; in the USB hub or in the USB host controller root hub
;
; Input: CL Port that has to be powered-up and enabled
; SI Pointer to the device information structure
;
; Output: ZR Error during port enable
; NZ Port successfully enabled
; AX Port connect status
;
; Modified: Nothing
;
;----------------------------------------------------------------------------
;<AMI_PHDR_END>
USBBB_EnableHubPort PROC NEAR PUBLIC
push bx
push cx
push dx
; Check whether the call is for hub or root hub
cmp bCurrentHubDeviceEntry, 0FFh
je UBEHP0_RootHub
; Power up the hub port
movzx ax, cl
mov (DeviceInfo PTR [si]).CntrlXfer.wIndex, ax ; Port number
mov (DeviceInfo PTR [si]).CntrlXfer.wValue, HUB_FEATURE_PORT_POWER
mov (DeviceInfo PTR [si]).CntrlXfer.wRequest, HUB_RQ_SET_PORT_FEATURE
call USBBB_IssueControlXferWithoutData
jz UBEHP0_Exit
; Delay the amount of time specified in the PowerOnDelay field of
; the hub descriptor.
push cx
movzx cx, (DeviceInfo PTR [si]).bHubPowerOnDelay
shl cx, 1 ; In ms
add cx, 30 ; Add 30 ms to the normal time
shl cx, 6 ; multiply by 64 (in 15us)
call fixed_delay_far
pop cx
; Reset the hub port
;; movzx ax, cl
;; mov (DeviceInfo PTR [si]).CntrlXfer.wIndex, ax ; Port number
mov (DeviceInfo PTR [si]).CntrlXfer.wValue, HUB_FEATURE_PORT_RESET
mov (DeviceInfo PTR [si]).CntrlXfer.wRequest, HUB_RQ_SET_PORT_FEATURE
call USBBB_IssueControlXferWithoutData
jz UBEHP0_Exit
mov bx, 10
UBEHP0_WaitReset:
dec bx
jz UBEHP0_PortResetDone
; Wait till reset is completed
push cx
mov cx, (10 * 1000)/15 ; 10 ms
call fixed_delay_far
pop cx
; CL Ports number
call USBBB_HubGetPortStatusFromDevice
test ax, HUB_PORT_STATUS_RESET
jnz UBEHP0_WaitReset ; Branch if hub has not completed
UBEHP0_PortResetDone:
; Clear the hub port reset status
movzx ax, cl
mov (DeviceInfo PTR [si]).CntrlXfer.wIndex, ax ; Port number
mov (DeviceInfo PTR [si]).CntrlXfer.wValue, HUB_FEATURE_PORT_RESET_CHANGE
mov (DeviceInfo PTR [si]).CntrlXfer.wRequest, HUB_RQ_CLEAR_PORT_FEATURE
call USBBB_IssueControlXferWithoutData
jz UBEHP0_Exit
; Get the hub port status
call USBBB_HubGetPortStatusFromDevice
; AX Status returned from the hub
xor dx, dx
; Check the device present status in the hub
test ax, HUB_PORT_STATUS_DEVICE_PRESENT
jz UBEHP0_Exit
; Device present set appropriate flag
; Assume it as low speed device
or dx, (USB_PORT_STAT_DEV_CONNECTED + USB_PORT_STAT_DEV_LOWSPEED)
; Check the device speed status
test ax, HUB_PORT_STATUS_LOW_SPEED
jnz UBEHP0_CheckStatusChange ; Yes.It is a low speed dev.
; It is either a full speed of high speed device
; Assume it as a high speed device
and dx, NOT USB_PORT_STAT_DEV_SPEED_MASK
or dx, USB_PORT_STAT_DEV_HISPEED
; Check the device speed status
test ax, HUB_PORT_STATUS_HIGH_SPEED
jnz UBEHP0_CheckStatusChange ; Yes.It is a high speed dev.
; No. It is a full speed device
and dx, NOT USB_PORT_STAT_DEV_SPEED_MASK
or dx, USB_PORT_STAT_DEV_FULLSPEED
UBEHP0_CheckStatusChange:
; Clear any status change bits that are set (connect change, enable change,
; suspend change, over-current change, reset change).
; Perform control transfer with device request as HUB_RQ_GET_PORT_STATUS,
; wIndex = Port number, wValue = 0, fpBuffer = DS:DI and wlength = 4
mov cx, HUB_FEATURE_PORT_CONNECT_CHANGE
mov bx, WORD PTR dTempHubPortStatus+2 ; AX = Status change bits
and bx, (HUB_PORT_STATUS_CHANGE_CONNECT OR \
HUB_PORT_STATUS_CHANGE_ENABLE OR \
HUB_PORT_STATUS_CHANGE_SUSPEND OR \
HUB_PORT_STATUS_CHANGE_OVERCURRENT OR \
HUB_PORT_STATUS_CHANGE_RESET)
mov (DeviceInfo PTR [si]).CntrlXfer.wRequest, HUB_RQ_CLEAR_PORT_FEATURE
UBEHP0_StatusClearNext:
mov ax, cx
sub ax, 16 ; Starts from 16
bt bx, ax ; CF = BX bit ax
jnc UBEHP0_CheckNextFeature
; Set wValue
mov (DeviceInfo PTR [si]).CntrlXfer.wValue, cx
call USBBB_IssueControlXferWithoutData
; ZR - on error, NZ on success
;; jz UBEHP0_Exit
UBEHP0_CheckNextFeature:
inc cx
cmp cx, HUB_FEATURE_PORT_RESET_CHANGE
jbe UBEHP0_StatusClearNext ;Br if not past last feature/status bit
mov ax, dx
or sp, sp ; Clear zero flag
jmp SHORT UBEHP0_Exit
UBEHP0_RootHub:
mov bx, CurrentHC.pHCDPointer
call (BBHCDHEADER PTR CS:[bx]).pHCDEnablePort
UBEHP0_Exit:
pushf
mov cx, (500 * 1000)/15 ; 500 ms
call fixed_delay_far
popf
pop dx
pop cx
pop bx
ret
USBBB_EnableHubPort ENDP
;<AMI_PHDR_START>
;----------------------------------------------------------------------------
; Procedure: USBBB_DisableHubPort
;
; Description: This procedure will power up and disable the specified port
; in the USB hub or in the USB host controller root hub
;
; Input: CL Port that has to be disabled and powered down
; SI Pointer to the device information structure
;
; Output: ZR Error during port disable
; NZ Port successfully disabled
;
; Modified: Nothing
;
;----------------------------------------------------------------------------
;<AMI_PHDR_END>
USBBB_DisableHubPort PROC NEAR PUBLIC
push bx
; Check whether the call is for hub or root hub
cmp bCurrentHubDeviceEntry, 0FFh
je UBDHP_RootHub
; Disable the port
movzx ax, cl
mov (DeviceInfo PTR [si]).CntrlXfer.wIndex, ax ; Port number
mov (DeviceInfo PTR [si]).CntrlXfer.wValue, HUB_FEATURE_PORT_ENABLE
mov (DeviceInfo PTR [si]).CntrlXfer.wRequest, HUB_RQ_CLEAR_PORT_FEATURE
call USBBB_IssueControlXferWithoutData
jz UBDHP_Exit
; Powered down the port
mov (DeviceInfo PTR [si]).CntrlXfer.wValue, HUB_FEATURE_PORT_POWER
call USBBB_IssueControlXferWithoutData
jmp SHORT UBDHP_Exit
UBDHP_RootHub:
mov bx, CurrentHC.pHCDPointer
call (BBHCDHEADER PTR CS:[bx]).pHCDDisablePort
UBDHP_Exit:
pop bx
ret
USBBB_DisableHubPort ENDP
;<AMI_PHDR_START>
;----------------------------------------------------------------------------
; Procedure: USBBB_HubGetPortStatusFromDevice
;
; Description: This routine gets the status information of the hub
;
; Input: CL Port whose status has to be returned
; SI Pointer to the device information structure
;
;
; Output: AX Hub port status
;
; Modified: EAX
;
;----------------------------------------------------------------------------
;<AMI_PHDR_END>
USBBB_HubGetPortStatusFromDevice PROC NEAR PUBLIC
push bx
push edi
xor eax, eax
mov edi, eax
mov (DeviceInfo PTR [si]).CntrlXfer.wValue, ax
mov dTempHubPortStatus, eax
mov al, cl
mov (DeviceInfo PTR [si]).CntrlXfer.wIndex, ax
lea di, dTempHubPortStatus
; Set DS for the far pointer
mov ax, ds
shl eax, 4
add eax, edi
mov (DeviceInfo PTR [si]).CntrlXfer.fpBuffer, eax
; Set data length
mov (DeviceInfo PTR [si]).CntrlXfer.wLength, 4
; Set request type
mov (DeviceInfo PTR [si]).CntrlXfer.wRequest, HUB_RQ_GET_PORT_STATUS
mov bx, CurrentHC.pHCDPointer
; Perform control transfer with device request as HUB_RQ_GET_PORT_STATUS,
; wIndex = Port number, wValue = 0, fpBuffer = DS:DI and wlength = 4
call (BBHCDHEADER PTR CS:[bx]).pHCDControlTransfer
; ZR - on error, NZ on success
pushf
mov ax, WORD PTR dTempHubPortStatus ; AX[Bit0]=Connect status,
; AX[BIT9]=Speed
popf
pop edi
pop bx
ret
USBBB_HubGetPortStatusFromDevice ENDP
;<AMI_PHDR_START>
;----------------------------------------------------------------------------
; Procedure: USBBB_IssueControlXferWithoutData
;
; Description: This procedure will issue and control transfer call by
; setting the buffer and length to NULL. It is assumed that all
; the values are set appropriately
;
; Input: SI Pointer to the device information structure
;
; Output: ZR/NZ depends on control transfer status
;
; Modified: Nothing
;
;----------------------------------------------------------------------------
;<AMI_PHDR_END>
USBBB_IssueControlXferWithoutData PROC NEAR PUBLIC
push eax
push bx
; Set buffer address & length to 0
xor eax, eax
mov (DeviceInfo PTR [si]).CntrlXfer.wLength, ax
mov (DeviceInfo PTR [si]).CntrlXfer.fpBuffer, eax
mov bx, CurrentHC.pHCDPointer
; Issue the HCD control transfer call
call (BBHCDHEADER PTR CS:[bx]).pHCDControlTransfer
pop bx
pop eax
ret
USBBB_IssueControlXferWithoutData ENDP
;<AMI_PHDR_START>
;----------------------------------------------------------------------------
; Procedure: USBBB_FindHCDriver
;
; Description: This procedure will find the suitabl host controller driver
; for the device
;
; Input: DS:bHCType Host controller type
;
; Output: ZR Error. Suitable driver not found
; NZ Success. Suitable driver for this HC is found and
; the pointer value is updated in the variable
; pHCDPointer
;
; Modified: Nothing
;
;----------------------------------------------------------------------------
;<AMI_PHDR_END>
USBBB_FindHCDriver PROC NEAR PUBLIC
push ax
push bx
push si
mov bx, OFFSET BBHCDriverTable
UBFHD_CheckNextDriver:
mov ax, WORD PTR CS:[bx]
or ax, ax
jz UBFHD_End
mov si, ax
mov al, CurrentHC.bHCType
cmp BYTE PTR CS:[si], al
je UBFHD_DriverFound
add bx, 2
jmp SHORT UBFHD_CheckNextDriver
UBFHD_DriverFound:
mov CurrentHC.pHCDPointer, si
or sp, sp ; Clear the zero flag
UBFHD_End:
pop si
pop bx
pop ax
ret
USBBB_FindHCDriver ENDP
;<AMI_PHDR_START>
;----------------------------------------------------------------------------
; Procedure: USBBB_InitAsyncList
;
; Description: This function will initialize the asynchronous frame list
; pointers for the host controller with the value provided
;
; Input: EAX Value to initialize with
;
; Output: Nothing
;
; Modified: Nothing
;
;----------------------------------------------------------------------------
;<AMI_PHDR_END>
USBBB_InitAsyncList PROC NEAR PUBLIC
push cx
push di
push es
; Point data area to the frame list start
push USB_DATA
pop es
xor di, di
mov cx, CurrentHC.wAsyncListSize
cld
rep stosd
pop es
pop di
pop cx
ret
USBBB_InitAsyncList ENDP
;<AMI_PHDR_START>
;----------------------------------------------------------------------------
; Procedure: USBBB_DisableHC
;
; Description: This function will disable the USB host controller by
; programming the HC PCI configuration space
;
; Input: None
;
; Output: None
;
; Modified: Nothing
;
;----------------------------------------------------------------------------
;<AMI_PHDR_END>
USBBB_DisableHC PROC NEAR PUBLIC
push ax
push ebx
push dx
mov dx, CurrentHC.wBusDevFuncNum
; Disable the memory/IO decoding & bus mastering
mov ax, (PCI_REG_PCICMD SHL 8) + BIT2 + BIT1 + BIT0
call read_pci_FAR
and al, NOT (BIT2 + BIT1 + BIT0)
call write_pci_FAR
; Write 0 to the memory base address register
xor ebx, ebx
mov ah, PCI_REG_MEMBASE
call write_pci_dword_FAR
; Program the IRQ line to 0
mov ax, (PCI_REG_INTLINE SHL 8) + 0
call write_pci_FAR
pop dx
pop ebx
pop ax
ret
USBBB_DisableHC ENDP
;<AMI_PHDR_START>
;----------------------------------------------------------------------------
; Procedure: USBBB_EnableHC
;
; Description: This function will enable the USB host controller and
; programs the base address register
;
; Input: EBX Base address to program
; AH Register to program
;
; Output: Nothing
;
; Modified: Nothing
;
;----------------------------------------------------------------------------
;<AMI_PHDR_END>
USBBB_EnableHC PROC NEAR PUBLIC
push ax
push ebx
push cx
push dx
mov dx, CurrentHC.wBusDevFuncNum
; Write the memory base address into the memory base address register
; EBX Base address to be programmed
; AH Register offset in which the above value will be programmed
call write_pci_dword_FAR
; Program the IRQ
mov ax, (PCI_REG_INTLINE SHL 8) + MKF_USB_BB_IRQ
call write_pci_FAR
; Route the IRQ by programming the IRQ value into the LPC bridge
push dx
mov bx, pHCInfoStrucPtr
mov al, MKF_USB_BB_IRQ
and al, (HC_INFO_STRUC PTR CS:[bx]).bIRQMask
mov cl, (HC_INFO_STRUC PTR CS:[bx]).bIRQShiftValue
shl al, cl
mov dx, MKF_USB_BB_IRQ_ROUTER_PCI_ADDRESS
mov ah, (HC_INFO_STRUC PTR CS:[bx]).bRoutingRegister
call write_pci_FAR
pop dx
; Enable the memory/IO decoding & bus mastering
mov ax, (PCI_REG_PCICMD SHL 8) + BIT2 + BIT1 + BIT0
call write_pci_FAR
pop dx
pop cx
pop ebx
pop ax
ret
USBBB_EnableHC ENDP
;<AMI_PHDR_START>
;----------------------------------------------------------------------------
; Procedure: USBBB_CheckNonCompliantDevice
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -