📄 usbmisc.asm
字号:
and al, 0F8h ; Mask off lower 3 bits
; Get the appropriate directory table entry
mov esi, DWORD PTR ES:[esi+eax] ; It is a 64 bit value but we use only 32bit
; Get the page directory entry
and si, 0F000h
pop eax
push eax
shr eax, (21 - 3) ; Get bits 29-21 and multiply by 8
and eax, (01FFh SHL 3) ; Get only 9 bits
mov esi, DWORD PTR ES:[esi+eax]
; ESI Page directory entry
; Check the PS flag
test esi, BIT7
jz ukcltp_Ext4KPages ; 0 indicates 4K page size
; 4M or 2M pages
; 4Mbyte page size
and si, 0F000h
pop eax
and eax, 001FFFFFh ; 21bits
add eax, esi
jmp ukcltp_Exit
ukcltp_Ext4KPages:
; Get the page table entry
and si, 0F000h
pop eax
push eax
shr eax, (12 - 3) ; Get bits 20-12 and multiply by 8
and eax, (01FFh SHL 3) ; Get only 9 bits
mov esi, DWORD PTR ES:[esi+eax] ; It is a 64 bit value but we use only 32 bit
; ESI Page Table Entry
jmp SHORT ukcltp_Get4KPage
ukcltp_PAENotEnabled:
; Paging enabled (protected mode is also enabled otherwise we will not be here)
; Get the physical 32bit address from the paging table
; EAX 32bit logical address of the instruction pointer
; Get the CR3 (Page directory base register)
mov esi, DWORD PTR FS:[SMRAM_CPU_DUMP_CR3]
and esi, 0FFFFF800h
; ESI Points to the page directory
push eax
shr eax, 20
and al, 0FCh ; Mask off lower 2 bits
; Get the appropriate page directory entry
mov esi, DWORD PTR ES:[esi+eax]
; ESI Page directory entry
; Find the appropriate page size from PSE(CR4) and PS(Page Directory Entry) bits
; If PSE = 0 then the page size is 4K
test BYTE PTR FS:[SMRAM_CPU_DUMP_CR4], BIT4
jz ukcltp_4KPages
; PSE = 1 then page size depends on PS (page size)
test esi, BIT7
jz ukcltp_4KPages ; 0 indicates 4K page size
jmp Short ukcltp_4MPages ; 1 indicates 4M page size
ukcltp_4KPages:
; Get the page table entry
and si, 0F000h
pop eax
push eax
shr eax, 10
and eax, (0000003FFh SHL 2)
mov esi, DWORD PTR ES:[esi+eax]
; ESI Page Table Entry
ukcltp_Get4KPage:
; Get the physical address from the page table
and si, 0F000h
pop eax
and ax, 00FFFh
or si, ax
mov eax, esi ; EAX Physical address
jmp SHORT ukcltp_Exit
ukcltp_4MPages:
; Assume 4Mbyte page size
and si, 0F000h
pop eax
and eax, 003FFFFFh
add eax, esi
ukcltp_Exit:
pop esi
ret
USBMisc_ConvertLinearToPhysical ENDP
ENDIF
IF MKF_USB_DEV_MASS
;<AMI_PHDR_START>
;----------------------------------------------------------------------------
; Procedure: USBMiscIssueBulkTransfer
;
; Description: This function executes a bulk transaction on the USB. The
; transfer may be either DATA_IN or DATA_OUT packets containing
; data sent from the host to the device or vice-versa. This
; function wil not return until the request either completes
; successfully or completes with error (due to time out, etc.)
; Size of data can be upto 64K
;
; Input: SI DeviceInfo structure (if available else 0)
; DL Transfer direction
; Bit 7 : Data direction
; 0 Host sending data to device
; 1 Device sending data to host
; Bit 6-0 : Reserved
; ES:DI/ Buffer containing data to be sent to the device or
; EDI buffer to be used to receive data. Value in
; Segment:Offset format
; ECX dwLength request parameter, number of bytes of data
; to be transferred in or out of the host controller
;
; Output: EAX Amount of data transferred
;
; Modified: EAX
;
;----------------------------------------------------------------------------
;<AMI_PHDR_END>
USBMiscIssueBulkTransfer PROC NEAR SYSCALL PUBLIC
LOCAL dwByteXfer:DWORD, dTemp:DWORD
push ebx
push ecx
push edx
push edi
; Load registers with input variables
mov dwByteXfer, 0
; Initialize local variables
mov dTemp, ecx
; Address is in EDI not in ES:DI
test stMassXactStruc.wMiscFlag, USBM_XACT_FLAG_32BIT_DATA_BUFFER
jnz UBT_NextTransfer
IF MKF_USB_MODE GE 2
; Change Seg:Off in fpBuffer to 32 bit absolute address
call USBMiscConvertProtAddrToPhyAddr
jnz UBT_NextTransfer ; Address translated
ENDIF
; Else translate the address
mov ax, es
movzx eax, ax
shl eax, 4
movzx edi, di
add edi, eax
UBT_NextTransfer:
mov bx, (DeviceInfo PTR [si]).pHCStrucPtr
; Send/receive maximum MAX_UHCI_BULK_DATA_SIZE data only
cmp ecx, (HCStruc PTR [bx]).dMaxBulkDataSize
jbe UBT_SizeOkay
mov cx, WORD PTR (HCStruc PTR [bx]).dMaxBulkDataSize
UBT_SizeOkay:
; SI Device info structure pointer
; EDI Far pointer to the buffer
; CX Size of data to be transferred
; DL Transfer direction
push bx
mov bx, (HCStruc PTR [bx]).pHCDPointer
mov ax, (HCDHEADER PTR cs:[bx]).pHCDBulkTransfer
pop bx
call ax
or ax, ax
jz UBT_Exit ; Nothing transferred (may be error)
movzx eax, ax
; Adjust total amount of data transferred
add dwByteXfer, eax
; Check whether the size requested is same as the size transferred
cmp ax, cx
jb UBT_Exit ; Tranfer completed
; Adjust loop variables
; Adjust amount of data to be transferred
sub dTemp, eax
; Adjust the buffer pointer
add edi, eax
mov ecx, dTemp
or ecx, ecx
jnz UBT_NextTransfer
UBT_Exit:
mov eax, dwByteXfer
pop edi
pop edx
pop ecx
pop ebx
ret
USBMiscIssueBulkTransfer ENDP
ENDIF
;<AMI_PHDR_START>
;----------------------------------------------------------------------------
; Procedure: USBPeriodicInterruptHandler
;
; Description: This routine is called every 16ms from the respective
; host controller
;
; Input: SI Pointer to the HCStruc structure
;
; Output: Nothing
;
; Modified: Nothing
;
;----------------------------------------------------------------------------
;<AMI_PHDR_END>
USBPeriodicInterruptHandler PROC NEAR PUBLIC
IF MKF_USB_DEV_KBD
EXTERN USBKBDPeriodicInterruptHandler:NEAR
call USBKBDPeriodicInterruptHandler
ENDIF
ret
USBPeriodicInterruptHandler ENDP
;<AMI_PHDR_START>
;----------------------------------------------------------------------------
; Procedure: USBMisc_StopUnsupportedHC
;
; Description: This routine is called, from host controllers that supports
; OS handover functionality, when the OS want the BIOS to
; hand-over the host controllers to the OS. This routine
; will stop HC that does not support this functionality.
;
; Input: None
;
; Output: None
;
; Modified: Nothing
;
;----------------------------------------------------------------------------
;<AMI_PHDR_END>
USBMisc_StopUnsupportedHC PROC FAR SYSCALL PUBLIC
pusha
push ds
; Get and set the data segment address
xor ax, ax ; Get current segment
call USBGetDataSegment
jz umsuh_Exit
; DS - USB data segment
; Currently this host controller stops only the EHCI host controllers
; Find the EHCI host controller HCStruc
mov si, OFFSET HCTable
mov cx, MKF_USB_MAX_HC
umsuh_TryNextHC:
cmp (HCStruc PTR [si]).bHCType, USB_EHCI
jne umsuh_PrepareForLoop
; Structure found. Check whether the controller is running
test (HCStruc PTR [si]).bHCFlag, HC_STATE_RUNNING
jz umsuh_PrepareForLoop ; No. It is stopped
; Controller is running. Invoke the stop call
mov bx, (HCStruc PTR [si]).pHCDPointer
mov bHandOverInProgress, TRUE
call (HCDHEADER PTR cs:[bx]).pHCDStop
jmp SHORT umsuh_Exit
umsuh_PrepareForLoop:
add si, SIZE HCStruc
loop umsuh_TryNextHC
umsuh_Exit:
pop ds
popa
ret
USBMisc_StopUnsupportedHC ENDP
PUBLIC _USBMISC_COMPATIBILITY_CODE_START
_USBMISC_COMPATIBILITY_CODE_START LABEL BYTE
; Compatibility code for different versions of chipset code can be found here
IFNDEF MKF_USB_CSP_TEMPLATE_VERSION
MKF_USB_CSP_TEMPLATE_VERSION EQU 0
ENDIF
;<AMI_THDR_START>
;----------------------------------------------------------------------------
; Name: DeviceDriverTable - USB Device Driver Table
;
; Type: Driver Header Table
;
; Description: This is the table of header addresses
;
;----------------------------------------------------------------------------
;<AMI_THDR_END>
PUBLIC DeviceDriverTable
DeviceDriverTable LABEL WORD
IF MKF_USB_DEV_KBD
EXTERN USBKBDDeviceHeader:USB_DEV_HDR
DW OFFSET USBKBDDeviceHeader
IF MKF_USB_DEV_MOUSE
EXTERN USBMouseDeviceHeader:USB_DEV_HDR
DW OFFSET USBMouseDeviceHeader
ENDIF
ENDIF
IF MKF_USB_DEV_HUB
EXTERN USBHUBDeviceHeader:USB_DEV_HDR
DW OFFSET USBHUBDeviceHeader
ENDIF
IF MKF_USB_DEV_MASS
EXTERN USBMassDeviceHeader:USB_DEV_HDR
DW OFFSET USBMassDeviceHeader
ENDIF
IF MKF_USB_CSP_TEMPLATE_VERSION LE 3
IFDEF MKF_USB_DEV_SECURITY
IF MKF_USB_DEV_SECURITY
EXTERN USBSecureDeviceHeader:USB_DEV_HDR
DW OFFSET USBSecureDeviceHeader
ENDIF ;; IF MKF_USB_DEV_SECURITY
ENDIF ;; IFDEF MKF_USB_DEV_SECURITY
ELSE ;; IF MKF_USB_CSP_TEMPLATE_VERSION LE 3
aExtraDeviceDriverTable LABEL WORD
; Free entries for future devices
WORD 0
WORD 0
WORD 0
WORD 0
WORD 0
ENDIF ;; IF MKF_USB_CSP_TEMPLATE_VERSION LE 3
WORD 0
;<AMI_PHDR_START>
;----------------------------------------------------------------------------
; Procedure: USBMiscFillDeviceDriverTable
;
; Description: This routine invokes an eLink to fill the device driver
; table. The device driver routines that hooked the eLink
; will fill their entry point address into the table.
;
; Input: None
;
; Output: None
;
; Modified: Nothing
;
;----------------------------------------------------------------------------
;<AMI_PHDR_END>
USBMiscFillDeviceDriverTable PROC NEAR SYSCALL PUBLIC
push bx
push es
IF MKF_USB_CSP_TEMPLATE_VERSION GE 4
push cs
pop es
mov bx, OFFSET aExtraDeviceDriverTable
; Invoke the eLink
EXTERN farUSBFillDeviceDriverTable:FAR
call farUSBFillDeviceDriverTable
ENDIF ;; IF MKF_USB_CSP_TEMPLATE_VERSION LE 3
pop es
pop bx
ret
USBMiscFillDeviceDriverTable ENDP
EXTERN Q_USB_LEGACY_ENABLE:ABS
IF MKF_USB_DEV_KBD
EXTERN Q_USB_LEGACY_KEYBOARD:ABS
IF MKF_USB_KBC_EMULATION
EXTERN Q_USB_6460_EMULATION:ABS
ENDIF
IF MKF_USB_DEV_MOUSE
EXTERN Q_USB_LEGACY_MOUSE:ABS
ENDIF
ENDIF
EXTERN Q_USB_BEEP:ABS
IF MKF_USB_DEV_MASS
EXTERN Q_USB_LEGACY_STORAGE:ABS
ENDIF
IF MKF_USB_EHCI
EXTERN Q_USB_HISPEED_SUPPORT:ABS
ENDIF
PUBLIC USBCmosQuestionInitTable
USBCmosQuestionInitTable LABEL USB_CMOS_INIT_STRUC
USB_CMOS_INIT_STRUC <Q_USB_LEGACY_ENABLE, USB_LEGACY_ENABLED_BIT>
IF MKF_USB_DEV_KBD
USB_CMOS_INIT_STRUC <Q_USB_LEGACY_KEYBOARD, USB_LEGACY_KEYBOARD_BIT>
IF MKF_USB_KBC_EMULATION
USB_CMOS_INIT_STRUC <Q_USB_6460_EMULATION, USB_PORT_TRAPPING_BIT>
ENDIF
IF MKF_USB_DEV_MOUSE
USB_CMOS_INIT_STRUC <Q_USB_LEGACY_MOUSE, USB_LEGACY_MOUSE_BIT>
ENDIF
ENDIF
IF MKF_USB_DEV_MASS
USB_CMOS_INIT_STRUC <Q_USB_LEGACY_STORAGE, USB_LEGACY_STORAGE_BIT>
ENDIF
USB_CMOS_INIT_STRUC <Q_USB_BEEP, INIT_FLAG_BEEP_ENABLE>
IF MKF_USB_EHCI
USB_CMOS_INIT_STRUC <Q_USB_HISPEED_SUPPORT, USB_HISPEED_SUPPORT>
ENDIF
PUBLIC USBCmosQuestionInitTableEnd
USBCmosQuestionInitTableEnd LABEL USB_CMOS_INIT_STRUC
IF MKF_USB_CSP_TEMPLATE_VERSION LE 3
;<AMI_THDR_START>
;----------------------------------------------------------------------------
; Name: HCDriverTable - Host Controller Driver Table
;
; Type: Driver Header Table
;
; Description: This is the table of header addresses
;
;----------------------------------------------------------------------------
;<AMI_THDR_END>
HCDriverTable LABEL WORD
IF MKF_USB_UHCI
EXTERN UHCI_HCHeader:HCDHEADER
DW OFFSET UHCI_HCHeader
ENDIF
IF MKF_USB_OHCI
EXTERN OHCI_HCHeader:HCDHEADER
DW OFFSET OHCI_HCHeader
ENDIF
IF MKF_USB_EHCI
EXTERN EHCI_HCHeader:HCDHEADER
DW OFFSET EHCI_HCHeader
ENDIF
DW 0
;<AMI_PHDR_START>
;----------------------------------------------------------------------------
; Procedure: farUSBFindHCDriver
;
; Description: This routine looks for the HCDriver structure by searching
; for the host controller type
;
; Input: AL Host controller type
;
; Output: AX - Pointer to the HCDriver structure. 0 on error
;
; Modified: AX
;
; Referrals: HCDriver
;
;----------------------------------------------------------------------------
;<AMI_PHDR_END>
farUSBFindHCDriver PROC FAR SYSCALL PUBLIC USES BX CX SI
mov si, OFFSET HCDriverTable
mov cx, MAX_NUM_HC_MODULES
UFHD_ProceedCheck:
cmp (HCDriver PTR cs:[si]).pHCAddress, 0 ; Valid entry ?
jz UFHD_DriverErrorExit
mov bx, (HCDriver PTR cs:[si]).pHCAddress ; HCD header
cmp (HCDHEADER PTR cs:[bx]).bHCDType, al ; HCD type okay ?
je UFHD_ExitLoop ; Driver found
; Check next structure
add si, SIZE HCDriver
loop UFHD_ProceedCheck
UFHD_DriverErrorExit:
xor bx, bx
UFHD_ExitLoop:
mov ax, bx
or ax, ax
ret
farUSBFindHCDriver ENDP
;<AMI_PHDR_START>
;----------------------------------------------------------------------------
; Procedure: farUSBExtAPIHandler
;
; Description: This routine substitutes the eLink that is available from
; the chipset template version 0004 if the template version
; is less than 4. This routine just return invalid error
; code for all the API request.
;
; Input: AL Function number
; ES:BX URP_STRUC pointer
;
; Output: AL Return code
;
; Modified: AX
;
; Referrals: UsbApiTable, URP_STRUC
;
;----------------------------------------------------------------------------
;<AMI_PHDR_END>
farUSBExtAPIHandler PROC FAR SYSCALL PUBLIC
; Invalid function number. Set the error code
mov al, USBAPI_INVALID_FUNCTION
ret
farUSBExtAPIHandler ENDP
ENDIF ;; IF MKF_USB_CSP_TEMPLATE_VERSION LE 3
PUBLIC _USBMISC_COMPATIBILITY_CODE_END
_USBMISC_COMPATIBILITY_CODE_END LABEL BYTE
PUBLIC _USBMISC_ASM_END
_USBMISC_ASM_END LABEL BYTE
USB_CSEG ENDS
SMI_BSPDUMPSEG SEGMENT PARA PUBLIC 'DATA'
SMI_BSPDUMPSEG ENDS
END
;***************************************************************************;
;***************************************************************************;
;** **;
;** (C)Copyright 1985-2003, American Megatrends, Inc. **;
;** **;
;** All Rights Reserved. **;
;** **;
;** 6145-F Northbelt Pkwy, Norcross, GA 30071 **;
;** **;
;** Phone (770)-246-8600 **;
;** **;
;***************************************************************************;
;***************************************************************************;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -