📄 usbmisc.asm
字号:
TITLE USBMISC.ASM -- USB Miscellanous Routines File
;***************************************************************************;
;***************************************************************************;
;** **;
;** (C)Copyright 1985-2003, 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/USBMISC.ASM 15 3/25/03 5:31p Sivagarn $
;
; $Revision: 15 $
;
; $Date: 3/25/03 5:31p $
;***************************************************************************;
; Revision History
; ----------------
; $Log: /BIOS/Corebin/800/Modules/USB2/Template/Core/USBMISC.ASM $
;
; 15 3/25/03 5:31p Sivagarn
; Routine "USBKBD_ConvertLinearToPhysical" is moved from USBKBD.ASM file
; to in this file with the name change "USBMisc_ConvertLinearToPhysical".
;
; 14 3/17/03 5:54p Sivagarn
; - Byte flag 'bUSBInitFlag' is changed to double word 'dUSBInitFlag'
; - Build error when 'USB_DEV_MASS' token is disabled is fixed by
; adding
;
; appropriate IF-ENDIF
;
; 13 1/27/03 8:48p Sivagarn
; - Removed the build error generator that is used to break the build
; process when the data area is not enough. It is not effective in most
; of the critical cases. Now an external DOS executable checks these
; conditions effectively
;
; 12 1/09/03 6:28p Sivagarn
; - Hand-over in progress flag is added. This flag is enabled during
; shutting down of USB EHCI handler from OHCI handover call. When this
; flag is set further devices are not enumerated. This fixes the bug in
; loading Windows XP when USB 2.0 MO drive is connected
;
; 11 1/06/03 5:33p Sivagarn
; - Function 'USBMisc_DisableUnsupportedHC' is modified to set data
; segment. This enables the routine to be called from other eModules.
; This feature was added to disable EHCI HC from ACPI_Enable call.
;
; 10 12/19/02 5:59p Sivagarn
; New routine is added to stop EHCI host controllers when OHCI host
; controllers are stopped by the OS through ownership hand-over call
;
; 9 12/17/02 3:38p Sivagarn
; - Changed copyright message year to 2003
; - Support for specifying 32bit linear buffer address in mass
; transaction is added
; - Bug in 'USBMiscIssueBulkTransfer' routine regarding short packets is
; fixed
;
; 8 11/27/02 6:16p Sivagarn
; - All the compatibility related code (between different versions of
; chipset template and core) in the other files are moved to this file
;
; 7 11/17/02 8:08p Sivagarn
; - Absolute access to CPU SMRAM dump area is changed to use
; SMI_BSPDUMPSEG
;
; 6 10/29/02 6:50p Sivagarn
; - Build error when USB_MODE is set to 1 is fixed
; - Error while initializing off-board (on-slot) PCI USB host controllers
; is resolved
;
; 5 10/14/02 9:02p Sivagarn
; * Code cleanup
; * Internal PCI access routines are removed and core access routines
; are used instead
;
; 4 9/18/02 6:55p Sivagarn
; Bug in getting correct DeviceInfo structure during security sensor bulk
; transfer is corrected
;
; 3 9/18/02 6:26p Sivagarn
; The condition of the beep flag is reversed
;
; 2 9/18/02 11:59a Sivagarn
; Changed the beep flag name from INIT_FLAG_BEEP_DISABLE to
; INIT_FLAG_BEEP_ENABLE
;
; 1 9/15/02 5:39p Sivagarn
; Initial AMIUSB 2.20 check-in
;
;***************************************************************************;
;----------------------------------------------------------------------------
; Global options are defined here
;----------------------------------------------------------------------------
OPTION PROC:PRIVATE
;----------------------------------------------------------------------------
;----------------------------------------------------------------------------
; Macro and equate files are included here
;----------------------------------------------------------------------------
INCLUDE equates.equ
INCLUDE usbflag.equ
INCLUDE usb.equ
INCLUDE mbiosequ.equ
;----------------------------------------------------------------------------
; External data
EXTERN dUSBInitFlag:DWORD
EXTERN USBAcquiredByOS:BYTE
EXTERN HCTable:NEAR
EXTERN bHandOverInProgress:BYTE
IF MKF_USB_DEV_MASS
EXTERN stMassXactStruc:MASS_XACT_STRUC
ENDIF
;----------------------------------------------------------------------------
; External function definitions are defined here
;----------------------------------------------------------------------------
fixed_delay_FAR PROTO FAR SYSCALL
read_pci_dword_far PROTO FAR SYSCALL
write_pci_dword_far PROTO FAR SYSCALL
USBVerifyUSBClassCode PROTO NEAR SYSCALL
EXTERN USBHCPCIInfoTableStart:NEAR
EXTERN USBHCPCIInfoTableEnd:NEAR
IF MKF_USB_MODE NE 2
EXTERN USBOEMHCPCITableStart:NEAR
EXTERN USBOEMHCPCITableEnd:NEAR
ENDIF
;----------------------------------------------------------------------------
; Public function definitions are defined here
;----------------------------------------------------------------------------
;----------------------------------------------------------------------------
; Function prototype definitions are here
;----------------------------------------------------------------------------
USBMisc_AddHCPCIInfo PROTO NEAR SYSCALL
USBMem_Alloc PROTO NEAR SYSCALL ; AL - bNumBlocks
USBMem_Free PROTO NEAR SYSCALL ; AL - bNumBlocks, BX - wMemBlock
USBMem_LocateFreeBlocks PROTO NEAR SYSCALL ; CL - bNumBlocks
USBMem_ChangeBlockStatus PROTO NEAR SYSCALL
; SI - wStartBlock, CL - bNumBlocks, CH - bOperation
USBGetDataSegment PROTO NEAR SYSCALL
IF MKF_USB_OHCI OR MKF_USB_EHCI
IF MKF_USB_MODE EQ 1
USBPortPrepareMemoryMapBelow1MB PROTO NEAR SYSCALL
USBPortRestoreMemoryMapBelow1MB PROTO NEAR SYSCALL
ENDIF
USBMiscCheckAndUpdateBaseAddress PROTO NEAR SYSCALL
USBMiscRestoreBaseAddress PROTO NEAR SYSCALL
ENDIF
;----------------------------------------------------------------------------
; D A T A S E G M E N T
;----------------------------------------------------------------------------
USB_DSEG SEGMENT WORD USE16 PUBLIC 'DATA'
;<AMI_THDR_START>
;-----------------------------------------------------------------------------
;
; Name: USBHCInfoTableStart - Stores PCI Bus/Dev/Fun information for
; all the USB HCs found. Sorted in required order.
;
; Type: Core Information Table
;
; Description: This table contains PCI Bus/Device/Function number (WORD) for
; USB Host Controllers:
; Bits 8..15 - Bus Number
; 3..7 - Device Number
; 0..2 - Function Number
;
;---------------------------------------------------------------------------
;<AMI_THDR_END>
PUBLIC USBHCInfoTableStart
USBHCInfoTableStart LABEL HCPCIInfo
EHCPCIInfoTable HCPCIInfo MKF_USB_EHCI dup (<?>)
UHCPCIInfoTable HCPCIInfo MKF_USB_UHCI dup (<?>)
OHCPCIInfoTable HCPCIInfo MKF_USB_OHCI dup (<?>)
PUBLIC USBHCInfoTableEnd
USBHCInfoTableEnd LABEL HCPCIInfo
;----------------------------------------------------------------------------
PUBLIC MemoryBlockStatus
MemoryBlockStatus DB USB_MEM_STATUS_DATA_SIZE dup (?)
Public USBDataAreaEnd
USBDataAreaEnd LABEL BYTE
USB_DSEG ENDS
IF MKF_USB_MODE NE 2
;----------------------------------------------------------------------------
; C O D E S E G M E N T
;----------------------------------------------------------------------------
IF MKF_USB_MODE EQ 1
USB_CSEG SEGMENT WORD USE16 PUBLIC 'CODE'
ASSUME cs:USB_CSEG
ENDIF
IF MKF_USB_MODE EQ 3
RUN_CSEG SEGMENT WORD USE16 PUBLIC 'CODE'
ASSUME cs:RUN_CSEG
ENDIF
ASSUME ds:USB_DSEG
ASSUME es:USB_DSEG
.586p
; IRQ Mode
;<AMI_PHDR_START>
;----------------------------------------------------------------------------
; Procedure: USBMiscFindIRQInService
;
; Description: This routine reads interrupt controller register to find
; out IRQ number currently in-service.
;
; Input: Nothing
;
; Output: AX - IRQ number
;
; Modified: AX
;
; Referrals:
;
;----------------------------------------------------------------------------
;<AMI_PHDR_END>
INTR_CNTRLR_MASTER_PORT EQU 020h
INTR_CNTRLR_SLAVE_PORT EQU 0A0h
READ_IN_SERVICE_REGISTER EQU 00Bh
USBMiscFindIRQInService PROC NEAR SYSCALL PUBLIC
push cx
push dx
xor ax, ax
; Find out the IRQ number we are servicing now
mov dx, INTR_CNTRLR_MASTER_PORT
mov al, READ_IN_SERVICE_REGISTER
out dx, al
jcxz short $+2
in al, dx
or al, al
jz UWFIIS_Leave ; No IRQ generated even IRQ2
; Find the IRQ number
bsf cx, ax
mov ax, cx ; AX - IRQ number
cmp ax, 2
jne UWFIIS_Leave
; It is the cascading IRQ. Check for correct IRQ number from slave
mov dx, INTR_CNTRLR_SLAVE_PORT
mov al, READ_IN_SERVICE_REGISTER
out dx, al
jcxz short $+2
in al, dx
or al, al
jz UWFIIS_Leave ; No IRQ generated even IRQ2
; Find the IRQ number
bsf cx, ax
mov ax, cx ; AX - IRQ number
add ax, 8
UWFIIS_Leave:
pop dx
pop cx
ret
USBMiscFindIRQInService ENDP
IF MKF_USB_MODE EQ 1
USB_CSEG ENDS
ENDIF
IF MKF_USB_MODE EQ 3
RUN_CSEG ENDS
ENDIF
ENDIF ; MKF_USB_MODE NE 2
;----------------------------------------------------------------------------
; 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
ASSUME es:USB_DSEG
.586p
PUBLIC _USBMISC_ASM_START
_USBMISC_ASM_START LABEL BYTE
;<AMI_PHDR_START>
;----------------------------------------------------------------------------
; Procedure: USBMiscScanPCIBusDeviceTable
;
; Description: This routine verifies whether the PCI device address provided
; is a valid USB host controller. If so it adds it to the
; corresponding list of host controllers
;
; Input: DS USB Data Area
; BX HC bus, device and function number table start
; SI Table end pointer
; CX = 000h Do not scan the multi-function devices
; = 0FFFFh Scan for multiple HC in the same address
;
;
; Output: None
;
; Modified: Nothing
;
; Notes: USB data area has to be initialized
;
;----------------------------------------------------------------------------
;<AMI_PHDR_END>
USBMiscScanPCIBusDeviceTable PROC NEAR SYSCALL PUBLIC
pusha
; Search for USB Host Controllers from the SB table
UMSPBDT_Search:
cmp bx, si
jae UMSPBDT_Exit
; Get PCI address
mov dx, WORD PTR cs:[bx]
push ebx
; Skip searching from function 0 if CX = 0
jcxz UMSPBDT_SearchNextFunction
and dl, 0F8h ; Start from function 0
UMSPBDT_SearchNextFunction:
push cx
; Read PCI Device Vendor ID
mov ah, PCI_REG_VENDID
call read_pci_dword_far
cmp ebx, -1
je UMSPBDT_TryNextFunction
; PCI Device found - verify whether it is USB HC
; DX - PCI address
mov ax, dx
call USBVerifyUSBClassCode
or ax, ax
je UMSPBDT_TryNextFunction ; Not a USB HC. Leave!
; Some USB HC found (type in AX) - add it
cmp ax, USB_UHCI
jnz UMSPBDT_NotUHCI
mov di, OFFSET UHCPCIInfoTable
mov cx, MKF_USB_UHCI
jmp SHORT UMSPBDT_AddHC
UMSPBDT_NotUHCI:
cmp ax, USB_OHCI
jnz UMSPBDT_NotOHCI
mov di, OFFSET OHCPCIInfoTable
mov cx, MKF_USB_OHCI
jmp SHORT UMSPBDT_AddHC
UMSPBDT_NotOHCI:
cmp ax, USB_EHCI
jnz UMSPBDT_TryNextFunction
mov di, OFFSET EHCPCIInfoTable
mov cx, MKF_USB_EHCI
UMSPBDT_AddHC:
; DI - Controller address table
; CX - Number of controller in this group (OHCI/EHCI/UHCI)
; DX - Current controllers address
call USBMisc_AddHCPCIInfo
UMSPBDT_TryNextFunction:
pop cx
; Check the value in CX
jcxz UMSPBDT_TryNextDevice
; Scan next function only if multi-function bit is set (for func 0)
mov ax, dx
and ax, 07h
jnz UMSPBDT_NotFunc0
; Check for multi-function device
; Read PCI Device Vendor ID
mov ah, PCI_REG_LINE_SIZE
call read_pci_dword_far
shr ebx, 16
test bx, MULTI_FUNC_BIT
jz UMSPBDT_TryNextDevice ; Not a multi-func device
UMSPBDT_NotFunc0:
; Try next function
inc dx
test dx, 07h
jnz UMSPBDT_SearchNextFunction
UMSPBDT_TryNextDevice:
pop ebx
add bx, 2 ; Next entry
or cx, cx
jnz UMSPBDT_Search
; Adjust for the structure
add bx, (SIZE HC_INFO_STRUC - 2)
jmp UMSPBDT_Search
UMSPBDT_Exit:
popa
ret
USBMiscScanPCIBusDeviceTable ENDP
;<AMI_PHDR_START>
;----------------------------------------------------------------------------
; Procedure: USBMiscFindHC
;
; Description: This routine checks for USB host controllers defined in and
; fills the HC lookup table accordingly.
;
; Input: DS USB Data Area
;
; Output: None
;
; Modified: Nothing
;
; Notes: USB data area has to be initialized
;
;----------------------------------------------------------------------------
;<AMI_PHDR_END>
USBMiscFindHC PROC NEAR SYSCALL PUBLIC USES CX BX AX SI
mov bx, OFFSET USBHCInfoTableStart
; Set bAvailable fields to TRUE
mov cx, MKF_USB_MAX_HC
UMFH_SetAvailable:
mov (HCPCIInfo PTR [bx]).bAvailable, TRUE
add bx, SIZE HCPCIInfo
loop UMFH_SetAvailable
; Search for USB Host Controllers from the SB table
mov bx, OFFSET USBHCPCIInfoTableStart
mov si, OFFSET USBHCPCIInfoTableEnd
xor cx, cx ; Do not scan for multiple HCs
call USBMiscScanPCIBusDeviceTable
IF MKF_USB_MODE NE 2
; Search for USB Host Controllers from the board table
mov bx, OFFSET USBOEMHCPCITableStart
mov si, OFFSET USBOEMHCPCITableEnd
dec cx ; = 0FFh Scan for multiple HCs
call USBMiscScanPCIBusDeviceTable
ENDIF
; Scanning complete
ret
USBMiscFindHC ENDP
;<AMI_PHDR_START>
;----------------------------------------------------------------------------
; Procedure: USBMisc_AddHCPCIInfo
;
; Description: This routine adds PCI bus/device/function information into
; HC lookup tables.
;
; Input: DI OFFSET of the corresponding HC PCI table
; CX Max number of controllers of wHCType (user defined)
; DX Entry to be added to the table
; DS USB data area
;
; Output: None
;
; Modified: Nothing
;
; Referrals:
;
;----------------------------------------------------------------------------
;<AMI_PHDR_END>
USBMisc_AddHCPCIInfo PROC NEAR SYSCALL
push ax
push cx
push di
or cx, cx
jz UAHP_Exit
sub di, SIZE HCPCIInfo
UAHP_Next:
add di, SIZE HCPCIInfo
cmp (HCPCIInfo PTR [di]).bAvailable, TRUE
loopne UAHP_Next
jne UAHP_Exit ; No room for the new entry
; Available entry found - fill it in and exit
mov (HCPCIInfo PTR [di]).wBusDevFun, dx
mov (HCPCIInfo PTR [di]).bAvailable, FALSE
UAHP_Exit:
pop di
pop cx
pop ax
ret
USBMisc_AddHCPCIInfo ENDP
;<AMI_PHDR_START>
;----------------------------------------------------------------------------
; Procedure: USBMisc_FixedDelay
;
; Description: This routine waits for specified number of 15us
;
; Input: AX Count in 15us granularity
;
; Output: Nothing
;
; Modified: Nothing
;
;----------------------------------------------------------------------------
;<AMI_PHDR_END>
USBMisc_FixedDelay PROC NEAR SYSCALL PUBLIC
push cx
mov cx, ax
call fixed_delay_FAR
pop cx
ret
USBMisc_FixedDelay ENDP
;<AMI_PHDR_START>
;----------------------------------------------------------------------------
; Procedure: USBMisc_SpeakerBeep
;
; Description: This function is used to generate sound with particular
; frequency for particular duration of time
; ;
; Input: BL Frequency at which to beep
; CX Time duration (units of 15microsec)
;
; Output: Nothing
;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -