📄 uhci.asm
字号:
in al, dx
test al, UHC_HOST_CONTROLLER_RUN
jz UDI_HCStopped
; Stop the HC by programming the HC run bit
and al, NOT UHC_HOST_CONTROLLER_RUN
out dx, al
; Wait till halted bit is set
mov bx, 1024 ; Wait for one second
sub dx, UHCI_COMMAND_REG
UDI_CheckStatusAgain:
add dx, UHCI_STATUS_REG
in al, dx
test al, UHC_HC_HALTED
jnz UDI_HCHalted
mov ax, ((1 * 1000) / 15) ; 1ms delay
call USBMisc_FixedDelay
dec bx
jnz UDI_CheckStatusAgain
; ZR flag set
jmp SHORT UDI_Exit ; Return with error
UDI_HCHalted:
; Clear the halted bit
mov al, UHC_HC_HALTED
out dx, al
UDI_HCStopped:
; Clear zero flag
or sp, sp
UDI_Exit:
pop dx
pop cx
pop bx
pop ax
ret
UHCI_DisableInterrupts ENDP
;<AMI_PHDR_START>
;----------------------------------------------------------------------------
; Procedure: UHCI_EnableInterrupts
;
; Description: This function disables the HC interrupts by setting the
; stop bit in the controller
;
; Input: SI Pointer to the HCStruc structure
; DS USB_DSEG
;
; Output: ZR On error
; NZ On success
;
; Modified: Nothing
;
; Referrals: HCStruc
;
;----------------------------------------------------------------------------
;<AMI_PHDR_END>
UHCI_EnableInterrupts PROC NEAR SYSCALL
push ax
push dx
; Get this controllers IO port address
mov dx, WORD PTR (HCStruc PTR [si]).dBaseAddress
add dx, UHCI_COMMAND_REG
in al, dx
or al, UHC_HOST_CONTROLLER_RUN
jcxz SHORT $+2
jcxz SHORT $+2
jcxz SHORT $+2
out dx, al
pop dx
pop ax
ret
UHCI_EnableInterrupts ENDP
;<AMI_PHDR_START>
;----------------------------------------------------------------------------
; Procedure: UHCI_MoveDataArea
;
; Description: This function moves the data area of the host controller
; without restarting the host controller again.
;
; Input: BX - HCStruc structure
; ESI - 32bit absolute data area address
; EDI - Size of the data area in bytes
; DS = ES = usbdseg
;
; Output: CY = On error
; NC = On success
; ESI - 32 absolute address of remaining data area
; EDI - Remaining data area size in bytes
;
; Modified: Nothing
;
; Referrals: None
;
;----------------------------------------------------------------------------
;<AMI_PHDR_END>
UHCI_MoveDataArea PROC NEAR
ret
UHCI_MoveDataArea ENDP
;<AMI_PHDR_START>
;----------------------------------------------------------------------------
; Procedure: UHCI_GetRootHubStatus
;
; Description: This function returns the port connect status for the
; root hub port
;
; Input: SI Pointer to HCStruc of the host controller
; AL Port in the HC whose status is requested
;
; Output: AL Port status flags (see USB_PORT_STAT_XX equates)
;
; Modified: AL
;----------------------------------------------------------------------------
;<AMI_PHDR_END>
UHCI_GetRootHubStatus PROC NEAR SYSCALL
push bx
push dx
movzx ax, al
shl ax, 1 ; AX - 2/4 for port 1/2
add ax, (UHCI_PORT1_CONTROL - 2)
; Read hub status
mov dx, WORD PTR (HCStruc PTR [si]).dBaseAddress
add dx, ax
in ax, dx
xor bl, bl ; Init the output values
test al, UHC_CONNECT_STATUS
jz UGRHS_ChkSpeed ; Br if no device present
; Set device connected status flag
or bl, USB_PORT_STAT_DEV_CONNECTED
UGRHS_ChkSpeed:
; Assume full speed and set the flag
or bl, USB_PORT_STAT_DEV_FULLSPEED
test ax, UHC_LOW_SPEED_ATTACHED
jz UGRHS_ChkConnect ; Br if high speed device
; Device is not a full speed device it is low speed device
; Reset full speed
and bl, (NOT USB_PORT_STAT_DEV_FULLSPEED)
; Set low speed flag
or bl, USB_PORT_STAT_DEV_LOWSPEED
UGRHS_ChkConnect:
test ax, UHC_CONNECT_STATUS_CHANGE
jz UGRHS_Exit ; Br if connect status not changed
; Set connect status change flag
or bl, USB_PORT_STAT_DEV_CONNECT_CHANGED
UGRHS_Exit:
mov al, bl
pop dx
pop bx
ret
UHCI_GetRootHubStatus ENDP
;<AMI_PHDR_START>
;----------------------------------------------------------------------------
; Procedure: UHCI_EnableRootHub
;
; Description: This function enables the root hub port specified
;
; Input: SI Pointer to HCStruc of the host controller
; AL Port in the HC whose status is requested
; DS USB data area
;
; Output: ZR On error
; NZ On success
;
; Modified: Nothing
;
;----------------------------------------------------------------------------
;<AMI_PHDR_END>
UHCI_EnableRootHub PROC NEAR SYSCALL USES DX SI
push ax
push dx
mov dx, WORD PTR (HCStruc PTR [si]).dBaseAddress
movzx ax, al
shl ax, 1 ; AX - 2/4 for port 1/2
add ax, (UHCI_PORT1_CONTROL - 2)
; DX - Port address
; Read root hub port control register
add dx, ax
in ax, dx
; Set enable and reset bits
or ax, (UHC_PORT_ENABLE OR UHC_PORT_RESET)
jcxz SHORT $+2
jcxz SHORT $+2
jcxz SHORT $+2
out dx, ax
; Delay for 10ms
mov ax, ((10 * 1000) / 15) ; 10ms delay
call USBMisc_FixedDelay
in ax, dx
and ax, NOT UHC_PORT_RESET ; Clear reset bit
or ax, UHC_PORT_ENABLE ; Set enable bit
jcxz SHORT $+2
jcxz SHORT $+2
jcxz SHORT $+2
out dx, ax
; Delay 1ms
mov ax, ((1 * 1000) / 15) ; 1ms delay
call USBMisc_FixedDelay
; Enable the port
in ax, dx
or ax, UHC_PORT_ENABLE ; Set enable bit
jcxz SHORT $+2
jcxz SHORT $+2
jcxz SHORT $+2
out dx, ax
; Delay 100ms
mov ax, ((100 * 1000) / 15) ; 100ms delay
call USBMisc_FixedDelay
pop dx
pop ax
or sp, sp ; Clear zero flag
ret
UHCI_EnableRootHub Endp
;<AMI_PHDR_START>
;----------------------------------------------------------------------------
; Procedure: UHCI_DisableRootHub
;
; Description: This function starts the UHCI controller. The necessary
; memory for running the controller should be provided
; as input.
;
; Input: SI Pointer to HCStruc of the host controller
; AL Port in the HC whose status is requested
; DS USB Data Area
;
; Output: ZR On error
; NZ On success
;
; Modified: Nothing
;
;----------------------------------------------------------------------------
;<AMI_PHDR_END>
UHCI_DisableRootHub PROC NEAR SYSCALL
push ax
push dx
mov dx, WORD PTR (HCStruc PTR [si]).dBaseAddress
movzx ax, al
shl ax, 1 ; AX - 2/4 for port 1/2
add ax, (UHCI_PORT1_CONTROL - 2)
; DX - Port address
; Read root hub port control register
add dx, ax
in ax, dx
; Reset enable
and ax, (NOT UHC_PORT_ENABLE)
jcxz SHORT $+2
jcxz SHORT $+2
jcxz SHORT $+2
out dx, ax
pop dx
pop ax
or sp, sp ; Clear zero flag
ret
UHCI_DisableRootHub Endp
;<AMI_PHDR_START>
;----------------------------------------------------------------------------
; Procedure: UHCI_FillCntrlXferFields
;
; Description: This function fills the data needed for the control transfer
; in the TD provided
;
; Input: BX DeviceInfo structure (if available else 0)
; DI Pointer to the TD
;
; Output: Nothing
;
; Modified: None
;----------------------------------------------------------------------------
;<AMI_PHDR_END>
UHCI_FillCntrlXferFields PROC NEAR
push eax
movzx eax, (DeviceInfo PTR [bx]).bEndPointSpeed
; AL = 11/01/10 for HI/LO/FULL
and al, 1 ; Mask off MSb
shl eax, 26
or eax, (UHCI_TD_INTERRUPT_ON_COMPLETE OR UHCI_TD_THREE_ERRORS OR UHCI_TD_ACTIVE)
mov (UHCI_TD PTR [di]).ControlStatus, eax
xor eax, eax
mov (UHCI_TD PTR [di]).CSReloadValue, eax
mov (UHCI_TD PTR [di]).pCallback, offset cs:UHCI_ControlTDCallback
mov (UHCI_TD PTR [di]).ActiveFlag, TRUE
pop eax
ret
UHCI_FillCntrlXferFields ENDP
;<AMI_PHDR_START>
;----------------------------------------------------------------------------
; Procedure: UHCI_ControlTransfer
;
; Description: This function executes a device request command transaction
; on the USB. One setup packet is generated containing the
; device request parameters supplied by the caller. The setup
; packet may be followed by data in or data out packets
; containing data sent from the host to the device
; or vice-versa. This function will not return until the
; request either completes successfully or completes in error
; (due to time out, etc.)
;
; Input: BX DeviceInfo structure (if available else 0)
; The temp data area in the BX contains the following data:
; wRequest Request type (low byte)
; Bit 7 : Data direction
; 0 = Host sending data to device
; 1 = Device sending data to host
; Bit 6-5 : Type
; 00 = Standard USB request
; 01 = Class specific
; 10 = Vendor specific
; 11 = Reserved
; Bit 4-0 : Recipient
; 00000 = Device
; 00001 = Interface
; 00010 = Endpoint
; 00100 - 11111 = Reserved
; Request code, a one byte code describing
; the actual device request to be executed
; (ex: Get Configuration, Set Address etc)
; wIndex wIndex request parameter (meaning varies)
; wValue wValue request parameter (meaning varies)
; fpBuffer Buffer containing data to be sent to the
; device or buffer to be used to receive data
; wLength wLength request parameter, number of bytes
; of data to be transferred in or out
; of the host controller
;
; Output: AX 0xFFFF SUCCESS
; AX 0 ERROR
;
; Modified: AX
;
; Referrals: None
;
; Notes: Endpoint is always assumed as 0 for control transfer
;
;----------------------------------------------------------------------------
;<AMI_PHDR_END>
UHCI_ControlTransfer PROC NEAR SYSCALL PUBLIC
LOCAL pSetup:NEAR, pStatus:NEAR, dTemp:DWORD, bDatToggle:BYTE,
wRetStatus:WORD, pDataTD:NEAR, wLength:WORD
push es
pushad
; Set return status as failure
xor ax, ax
mov wRetStatus, ax
; Initialize local variables
mov pDataTD, ax
mov pSetup, ax
mov pStatus, ax
;;; mov ax, (DeviceInfo PTR [bx]).CntrlXfer.wLength ;;xiao
mov wLength, ax
; Change Seg:Off in fpBuffer to 32 bit absolute address
call USBMiscGetFarBufferAddress ; BX DevInfo
; Return value in EDX
; Allocate TDs for control setup and control status packets
mov al, 2
call USBMem_Alloc
jz UCT_Exit
mov pSetup, ax
add ax, SIZE UHCI_TD
mov pStatus, ax
; Build the device request in the data area of the control setup TD
mov di, pSetup
add di, UHCI_TD.DataArea
call USBMiscFormDeviceRequest ; BX DeviceInfo structure
; dTemp will contain the device address and endpoint shifted and ready to go
; into the TDs' token field.
xor eax, eax ; EAX[3:0] = Endpoint (00-0Fh)
;; shl eax, 7 ; EAX[10:7] = Endpoint (00-0Fh)
or al, (DeviceInfo PTR [bx]).bDeviceAddress
; EAX[10:0] = Dev. Addr & Endpoint
shl eax, 8 ; EAX[18:8] = Dev. Addr & Endpoint
mov dTemp, eax
; Fill in various fields in the control setup TD.
; The LinkPointer field will point to the control data TD if data will
; be sent/received or to the control status TD if no data is expected.
; The ControlStatus field will be set to active and interrupt on complete.
; The Token field will contain the packet size (size of DeviceRequest
; struc), the device address, endpoint, and a setup PID.
; The BufferPointer field will point to the TD's DataArea buffer which
; was just initialized to contain a DeviceRequest struc.
; The CSReloadValue field will contain 0 because this is a "one shot" packet.
; The pCallback will be set to point to the UHCI_ControlTDCallback routine.
; The ActiveFlag field will be set to TRUE.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -