📄 uhci_bb.asm
字号:
TITLE UHCI_BB.ASM -- Universal Host Controller Interface Boot Block Code
;***************************************************************************;
;***************************************************************************;
;** **;
;** (C)Copyright 1985-2002, American Megatrends, Inc. **;
;** **;
;** All Rights Reserved. **;
;** **;
;** 6145-F Northbelt Pkwy, Norcross, GA 30071 **;
;** **;
;** Phone (770)-246-8600 **;
;** **;
;***************************************************************************;
;***************************************************************************;
;***************************************************************************;
; $Header: /BIOS/Corebin/800/Modules/USB2/Template/Core/UHCI_BB.ASM 2 11/17/02 8:10p Sivagarn $
;
; $Revision: 2 $
;
; $Date: 11/17/02 8:10p $
;***************************************************************************;
; Revision History
; ----------------
; $Log: /BIOS/Corebin/800/Modules/USB2/Template/Core/UHCI_BB.ASM $
;
; 2 11/17/02 8:10p Sivagarn
; - Code to include/exclude code for USB keyboard support in the boot
; block is added based on the flag "USB_BB_DEV_KBD"
;
; 1 10/14/02 8:40p Sivagarn
; * USB boot block related files are added
;
;***************************************************************************;
;----------------------------------------------------------------------------
; Global options are defined here
;----------------------------------------------------------------------------
OPTION PROC:PRIVATE
;----------------------------------------------------------------------------
;----------------------------------------------------------------------------
; Macro and equate files are included here
;----------------------------------------------------------------------------
INCLUDE equates.equ
INCLUDE usb.equ
INCLUDE uhci.equ
INCLUDE mbiosequ.equ
;----------------------------------------------------------------------------
;;; Build flag adjustments
IFNDEF MKF_USB_BB_DEV_KBD
MKF_USB_BB_DEV_KBD EQU 0
ENDIF ;; IFNDEF MKF_USB_BB_DEV_KBD
;----------------------------------------------------------------------------
; External data definitions are defined here
;----------------------------------------------------------------------------
EXTERN dGlobalDataArea:DWORD
EXTERN CurrentHC:HCStruc
EXTERN CurrentDevice:DeviceInfo
EXTERN bLastBulkCommandStalled:BYTE
;----------------------------------------------------------------------------
;----------------------------------------------------------------------------
; External function definitions are defined here
;----------------------------------------------------------------------------
USBBB_InitAsyncList PROTO NEAR SYSCALL
USBBB_EnableHC PROTO NEAR SYSCALL
USBBB_DisableHC PROTO NEAR SYSCALL
USBBB_GetDeviceType PROTO NEAR SYSCALL
USBBB_CopyDeviceRequest PROTO NEAR SYSCALL
IF MKF_USB_BB_DEV_KBD
USBBB_ProcessKeyboardData PROTO NEAR SYSCALL
USBBB_CaptureHCInterrupt PROTO NEAR SYSCALL
ENDIF ; IF MKF_USB_BB_DEV_KBD
USBMBB_GetBulkEndPointInfo PROTO NEAR SYSCALL
USBMBB_UpdateBulkDataSync PROTO NEAR SYSCALL
fixed_delay_far PROTO FAR SYSCALL
read_pci_dword_far PROTO FAR SYSCALL
write_pci_dword_far PROTO FAR SYSCALL
;----------------------------------------------------------------------------
;----------------------------------------------------------------------------
; Public function definitions are defined here
;----------------------------------------------------------------------------
;----------------------------------------------------------------------------
;----------------------------------------------------------------------------
; Function prototype definitions are here
;----------------------------------------------------------------------------
;----------------------------------------------------------------------------
;----------------------------------------------------------------------------
; D A T A S E G M E N T
;----------------------------------------------------------------------------
USB_DSEG SEGMENT PARA PUBLIC 'DATA'
ALIGN 16
PUBLIC QHControl
QHControl UHCI_QH <?>
ALIGN 16
PUBLIC TDControlSetup
TDControlSetup UHCI_TD <?>
TDControlStatus UHCI_TD <?>
TDData UHCI_TD (MAX_CONTROL_DATA_SIZE / 8) DUP (<?>)
IF MKF_USB_BB_DEV_KBD
TDKeyboard UHCI_TD <?>
ENDIF ;; IF MKF_USB_BB_DEV_KBD
USB_DSEG ENDS
;----------------------------------------------------------------------------
; D A T A S E G M E N T
;----------------------------------------------------------------------------
USB_DATA SEGMENT PARA PUBLIC 'DATA'
USB_DATA ENDS
;----------------------------------------------------------------------------
;----------------------------------------------------------------------------
; C O D E S E G M E N T
;----------------------------------------------------------------------------
USB_CSEG SEGMENT WORD USE16 PUBLIC 'CODE'
ASSUME CS:USB_CSEG
ASSUME DS:USB_DSEG
.586p
PUBLIC _UHCI_BB_ASM_START
_UHCI_BB_ASM_START LABEL BYTE
Public UHCIBB_HCHeader
UHCIBB_HCHeader LABEL BBHCDHeader
DW USB_UHCI ; Module type
DW UHCIBB_InitializeHC ; Initializes the host controller
DW UHCIBB_StopHC ; UHCI stop controller routine
DW UHCIBB_EnablePort ; Enables the root hub port
DW UHCIBB_DisablePort ; Disables the root hub port
DW UHCIBB_ControlTransfer ; Performs a control transfer
DW UHCIBB_BulkTransfer ; Performs a bulk transfer
DW UHCIBB_InterruptTransfer ; Performs an interrupt transfer
DW UHCIBB_ProcessInterrupt ; Interrupt service routine
DW UHCIBB_DeactivateKeyboardPolling; De-activates polling for a device
DW UHCIBB_ActivateKeyboardPolling ; Activates polling for a device
;<AMI_PHDR_START>
;----------------------------------------------------------------------------
; Procedure: UHCIBB_InitializeHC
;
; Description: This function starts the UHCI controller and returns number
; of ports present in the controller
;
; Input: DS USB global data area
;
; Output: ZR On error
; NZ On successful completion
; CL Number of ports in the HC
;
; Modified: Nothing
;
;----------------------------------------------------------------------------
;<AMI_PHDR_END>
UHCIBB_InitializeHC PROC NEAR PUBLIC
push eax
push ebx
push dx
; Update the necessary global variables regarding UHCI host controller
; Fill number of ports supported by the host controller
mov CurrentHC.bNumPorts, 2
mov CurrentHC.wAsyncListSize, UHCI_FRAME_LIST_SIZE
; Set the max bulk data size
mov CurrentHC.dMaxBulkDataSize, MAX_UHCI_BULK_DATA_SIZE
; Initialize the frame list pointers
mov eax, OFFSET QHControl
add eax, dGlobalDataArea
or eax, UHCI_QUEUE_HEAD
call USBBB_InitAsyncList
; Set the base address and enable the HC
mov ebx, MKF_USB_BB_IO_BASE
mov ah, USB_IO_BASE_ADDRESS
call USBBB_EnableHC
; Reset the HC
call UHCIBB_ResetHC
; Enable the TD schedules
call UHCIBB_StartTDSchedule
; Program the frame list base address register
mov dx, (MKF_USB_BB_IO_BASE + UHCI_FRAME_LIST_BASE)
mov eax, USB_DATA
shl eax, 4
out dx, eax
; Start the host controller and set the configured flag in the host
; controller to signal that it is up and running under BIOS control.
mov dx, (MKF_USB_BB_IO_BASE + UHCI_COMMAND_REG)
mov ax, (UHC_HOST_CONTROLLER_RUN OR UHC_CONFIGURE_FLAG OR \
UHC_MAX_PACKET_64_BYTE)
out dx, ax
mov cl, CurrentHC.bNumPorts
; Successful completion. Clear zero flag
or sp, sp
pop dx
pop ebx
pop eax
ret
UHCIBB_InitializeHC ENDP
;<AMI_PHDR_START>
;----------------------------------------------------------------------------
; Procedure: UHCIBB_EnablePort
;
; Description: This function enables the root hub port specified
;
; Input: DS USB global data area
; CL Port number
;
; Output: ZR On error
; NZ On successful completion
; AX Port status
;
; Modified: Nothing
;
;----------------------------------------------------------------------------
;<AMI_PHDR_END>
UHCIBB_EnablePort PROC NEAR PUBLIC
push bx
push cx
push dx
; Form the return value (Port status) in BX
xor bx, bx
mov dx, (MKF_USB_BB_IO_BASE + (UHCI_PORT1_CONTROL - 2))
movzx ax, cl
shl ax, 1 ; Multiply by 2
add dx, ax
in ax, dx
test al, UHC_CONNECT_STATUS
jz UBEP_Exit
; Some device present
; Set device connected status flag
or bx, USB_PORT_STAT_DEV_CONNECTED
; Assume full speed and set the flag
or bx, USB_PORT_STAT_DEV_FULLSPEED
test ax, UHC_LOW_SPEED_ATTACHED
jz UBEP_DevSpeedFound ; Br if high speed device
; Device is not a full speed device it is low speed device
; Reset full speed
and bx, (NOT USB_PORT_STAT_DEV_FULLSPEED)
; Set low speed flag
or bx, USB_PORT_STAT_DEV_LOWSPEED
UBEP_DevSpeedFound:
; Clear the port status
in ax, dx
jcxz SHORT $+2
jcxz SHORT $+2
out dx, ax
; Enable the root hub port
mov dx, MKF_USB_BB_IO_BASE
movzx ax, cl ; Port number
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 cx, ((10 * 1000) / 15) ; 10ms delay
call fixed_delay_far
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 cx, ((1 * 1000) / 15) ; 1ms delay
call fixed_delay_far
; 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 cx, ((100 * 1000) / 15) ; 100ms delay
call fixed_delay_far
; Successful completion. Clear zero flag
or sp, sp
UBEP_Exit:
mov ax, bx ; return value
pop dx
pop cx
pop bx
ret
UHCIBB_EnablePort ENDP
;<AMI_PHDR_START>
;----------------------------------------------------------------------------
; Procedure: UHCIBB_DisablePort
;
; Description: This function enables the root hub port specified
;
; Input: DS USB global data area
; CL Port number
;
; Output: ZR On error
; NZ On successful completion
;
; Modified: Nothing
;
;----------------------------------------------------------------------------
;<AMI_PHDR_END>
UHCIBB_DisablePort PROC NEAR PUBLIC
push ax
push dx
mov dx, MKF_USB_BB_IO_BASE
movzx ax, cl
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
UHCIBB_DisablePort ENDP
;<AMI_PHDR_START>
;----------------------------------------------------------------------------
; Procedure: UHCIBB_StopHC
;
; Description: This function stops the UHCI controller.
;
; Input: DS USB data area
;
; Output: None
;
; Modified: Nothing
;
;----------------------------------------------------------------------------
;<AMI_PHDR_END>
UHCIBB_StopHC PROC NEAR PUBLIC
push ax
push bx
push dx
; Stop the host controller
; Check whether HC is stopped
mov dx, (MKF_USB_BB_IO_BASE + UHCI_COMMAND_REG)
in al, dx
test al, UHC_HOST_CONTROLLER_RUN
jz UBSH_HCStopped
; Stop the HC by programming the HC run bit
and al, NOT UHC_HOST_CONTROLLER_RUN
out dx, al
; Wait for the HC to stop
push cx
mov cx, ((10 * 1000) / 15) ; 10ms delay
call fixed_delay_far
pop cx
; Clear the halted bit
mov al, UHC_HC_HALTED
out dx, al
UBSH_HCStopped:
; Reset the host controller
call UHCIBB_ResetHC
; Disable the host controller
call USBBB_DisableHC
pop dx
pop bx
pop ax
ret
UHCIBB_StopHC ENDP
;<AMI_PHDR_START>
;----------------------------------------------------------------------------
; Procedure: UHCIBB_ResetHC
;
; Description: This function resets the UHCI host controller
;
; Input: USB Data Area
;
; Output: None
;
; Modified: Nothing
;
;----------------------------------------------------------------------------
;<AMI_PHDR_END>
UHCIBB_ResetHC PROC NEAR PUBLIC
push ax
push cx
push dx
; Reset the host controller
mov dx, (MKF_USB_BB_IO_BASE + UHCI_COMMAND_REG)
mov al, UHC_GLOBAL_RESET
out dx, al
; Wait for 100ms
mov cx, ((100 * 1000) / 15) ; 100ms delay
call fixed_delay_FAR
; Reset the UHCI command register
xor al, al
out dx, al
pop dx
pop cx
pop ax
ret
UHCIBB_ResetHC ENDP
;<AMI_PHDR_START>
;----------------------------------------------------------------------------
; Procedure: UHCIBB_StartTDSchedule
;
; Description: This function starts the standard TD schedules for the
; USB host controller
;
; Input: USB Data Area
;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -