⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ohci_bb.asm

📁 dos下的USB源码(包括UHCI
💻 ASM
📖 第 1 页 / 共 4 页
字号:
	TITLE	OHCI.ASM -- Open Host Controller Interface 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/OHCI_BB.ASM 3     02/12/02 5:09p Tonylo $
;
; $Revision: 3 $
;
; $Date: 02/12/02 5:09p $
;***************************************************************************;
; Revision History
; ----------------
; $Log: /BIOS/Corebin/800/Modules/USB2/Template/Core/OHCI_BB.ASM $
; 
; 3     02/12/02 5:09p Tonylo
; USB003 - Bug fixed for OHCI BootBlock Flash doesn't work.
; 
; 
; 2     11/17/02 8:12p Sivagarn
; - Boot block support for OHCI controller is added
; 
; 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 ohci.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 done 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_CopyDeviceRequest		PROTO	NEAR SYSCALL
USBMBB_GetBulkEndPointInfo	PROTO	NEAR SYSCALL
USBMBB_UpdateBulkDataSync	PROTO	NEAR SYSCALL
IF	MKF_USB_BB_DEV_KBD
USBBB_CaptureHCInterrupt	PROTO	NEAR SYSCALL
USBBB_ProcessKeyboardData	PROTO	NEAR SYSCALL
ENDIF	;; IF	MKF_USB_BB_DEV_KBD

fixed_delay_far			PROTO FAR SYSCALL
write_pci_dword_FAR		PROTO FAR SYSCALL
;----------------------------------------------------------------------------

;----------------------------------------------------------------------------
;		Function prototype definitions are here
;----------------------------------------------------------------------------
;----------------------------------------------------------------------------

;----------------------------------------------------------------------------
;	D A T A   S E G M E N T
;----------------------------------------------------------------------------
USB_DSEG 	SEGMENT 	PARA PUBLIC 'DATA'

ALIGN 16
EDControl		OHCI_ED		< ? >
EDInterrupt		OHCI_ED		< ? >
IF	MKF_USB_BB_DEV_KBD
EDKeyboard		OHCI_ED		< ? >
TDKeyboard		OHCI_TD		< ? >
ENDIF	;; IF	MKF_USB_BB_DEV_KBD
GTDControlSetup		OHCI_TD		< ? >
GTDControlStatus	OHCI_TD		< ? >
GTDData			OHCI_TD		< ? >

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	_OHCI_BB_ASM_START
_OHCI_BB_ASM_START		LABEL		BYTE

	PUBLIC	OHCIBB_HCHeader
OHCIBB_HCHeader		LABEL	BBHCDHeader
	WORD	USB_OHCI			; Module type
	WORD	OHCIBB_InitializeHC		; Initializes the host controller
	WORD	OHCIBB_StopHC			; OHCI stop controller routine
	WORD	OHCIBB_EnablePort		; Enables the root hub port
	WORD	OHCIBB_DisablePort		; Disables the root hub port
	WORD	OHCIBB_ControlTransfer		; Performs a control transfer
	WORD	OHCIBB_BulkTransfer		; Performs a bulk transfer
	WORD	OHCIBB_InterruptTransfer	; Performs an interrupt transfer
	WORD	OHCIBB_ProcessInterrupt		; Interrupt service routine
	WORD	OHCIBB_DeactivateKeyboardPolling; De-activates polling for a device
	WORD	OHCIBB_ActivateKeyboardPolling	; Activates polling for a device


;<AMI_PHDR_START>
;----------------------------------------------------------------------------
; Procedure:	OHCIBB_InitializeHC
;
; Description:	This function starts the OHCI 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>

OHCIBB_InitializeHC	PROC NEAR PUBLIC 
	push	fs
	push	ebx
;X	push	cx	;(USB003-) CX register was used for Port Counts
	push	dx
	push	si
	push	edi


; Update the necessary global variables regarding OHCI host controller
	mov	CurrentHC.wAsyncListSize, OHCI_FRAME_LIST_SIZE

; Set the max bulk data size
	mov	CurrentHC.dMaxBulkDataSize, MAX_OHCI_BULK_DATA_SIZE

; Initialize the frame list pointers
	xor	eax, eax
	call	USBBB_InitAsyncList

;(USB003-)>
;These codes was for Intel chipset only, Remove for generic
comment ~			
;;;;;;;;;;;;;;;;;DEBUGGING
	mov	dx, 00F0h
	mov	ebx, 20010100h
	mov	ah, 18h
	call	write_pci_dword_FAR

	mov	ebx, 02800007h
	mov	ah, 04h
	call	write_pci_dword_FAR
;;;;;;;;;;;;;;;;;DEBUGGING
end comment ~
;<(USB003-)

; Set the base address and enable the HC
	mov	ebx, MKF_USB_BB_MEM_BASE
	mov	ah, USB_MEM_BASE_ADDRESS
	call	USBBB_EnableHC

; Set FS:DI to point to the memory base address of the HC
; EBX	Memory base address
	shr	ebx, 4
	mov	fs, bx
	xor	di, di	

; Reset the HC
	call	OHCIBB_ResetHC

; Get the number of ports supported by the host controller (Offset 48h)
	mov	eax, DWORD PTR FS:[di+OHCI_RH_DESCRIPTOR_A]
	mov	CurrentHC.bNumPorts, al

; Enable per port power switching & No over-current indication bits
; EAX - HcRhDescriptorA register value
	and	ax, NOT (BIT8 + BIT9)	; Clear bit 9:8 in EAX
	or	ax, (BIT8 + BIT12)
	mov	DWORD PTR FS:[di+OHCI_RH_DESCRIPTOR_A], eax

; Make USB device as removable & set power switching state to per port mode
	mov	DWORD PTR FS:[di+OHCI_RH_DESCRIPTOR_B], 0FFFF0000h

; Enable the ED schedules
	call	OHCIBB_StartEDSchedule

; Program the frame list base address register
	mov	eax, USB_DATA
	shl	eax, 4
	mov	DWORD PTR FS:[di+OHCI_HCCA_REG], eax

; Set the periodic start time = 2A27h (10% off from HcFmInterval-2EDFh)
	mov	DWORD PTR FS:[di+OHCI_PERIODIC_START], 2A27h

; Set the operational bit in the host controller so that power can be applied
; to the ports.
	mov	DWORD PTR FS:[di+OHCI_CONTROL_REG], USBOPERATIONAL	; StartHC

; Enable global port power so that new devices can be detected.
	mov	DWORD PTR FS:[di+OHCI_RH_STATUS], SET_GLOBAL_POWER	; Enable global power

; Set the HcFrameInterval register
; FSLargestDataPacket = (FrameInterval-210) * 6/7 ==> 2778h
; where FrameInterval = 2EDFh
	mov	DWORD PTR FS:[di+OHCI_FRAME_INTERVAL], 27782EDFh

; Start the host controller for control list only (no periodic list)
	mov	DWORD PTR FS:[di+OHCI_CONTROL_REG], (CONTROL_LIST_ENABLE OR BULK_LIST_ENABLE OR USBOPERATIONAL)
; Start the host controller for periodic list and control list.
	or	DWORD PTR FS:[di+OHCI_CONTROL_REG], PERIODIC_LIST_ENABLE

	mov	cl, CurrentHC.bNumPorts

; Successful completion. Clear zero flag
	or	sp, sp
	pop	edi
	pop	si
	pop	dx
;X	pop	cx	;(USB003-) CX register was used for Port Counts 
	pop	ebx
	pop	fs
	ret

OHCIBB_InitializeHC	ENDP

;<AMI_PHDR_START>
;----------------------------------------------------------------------------
; Procedure:	OHCIBB_EnablePort
;
; Description:	This function enables the root hub port specified in CL
;
; 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>

OHCIBB_EnablePort	PROC NEAR PUBLIC 

	push	bx
	push	cx
	push	di
	push	fs

; Set FS:DI to point to the memory base address of the HC
	call	OHCIBB_SetFS_DI

; Form the return value (Port status) in BX
	xor	bx, bx

; Get the correct root hub port register offset
	push	bx
	mov	bl, cl
	shl	bl, 2
	add	bx, (OHCI_RH_PORT1_STATUS - 4)
	add	di, bx
	pop	bx

; Enable individual port's power
	mov	DWORD PTR FS:[di], SET_PORT_POWER

; Delay to make sure the power to the port is stabilised
	mov	cx, ((10 * 1000) / 15)	; 10ms delay
	call	fixed_delay_far

; Enable the root hub port
	mov	DWORD PTR FS:[di], SET_PORT_ENABLE

; Wait for port enable to stabilize (10ms delay)
	mov	cx, ((10 * 1000) / 15)	; 10ms delay
	call	fixed_delay_far

; Reset the port
	mov	DWORD PTR FS:[di], SET_PORT_RESET

; Wait for reset to complete
OBEP_WaitForReset:
	mov	eax, DWORD PTR FS:[di]
	test	eax, PORT_RESET_STATUS
	jnz	OBEP_WaitForReset

; Clear the reset status change status
	mov	DWORD PTR FS:[di], PORT_RESET_STATUS_CHANGE

; Wait for devices connected to the port to stabilize (10ms delay)
	mov	cx, ((10 * 1000) / 15)	; 10ms delay
	call	fixed_delay_far

; Read the port status
	mov	eax, DWORD PTR FS:[di]
	test	eax, CURRENT_CONNECT_STATUS
	jz	OBEP_ChkSpeed		; Br if no device present
	or	bl, USB_PORT_STAT_DEV_CONNECTED	; Set connect status bit
OBEP_ChkSpeed:
; Assume full speed and set the flag
	or	bl, USB_PORT_STAT_DEV_FULLSPEED
	test	eax, LOW_SPEED_DEVICE_ATTACHED
	jz	OBEP_ChkConnect	; Br if full speed device
; Reset full speed
	and	bl, (NOT USB_PORT_STAT_DEV_FULLSPEED)

; Set low speed flag
	or	bl, USB_PORT_STAT_DEV_LOWSPEED

OBEP_ChkConnect:
	test	eax, CONNECT_STATUS_CHANGE
	jz	OBEP_Done		; Br if connect status not changed

; Set connect status change flag
	or	bl, USB_PORT_STAT_DEV_CONNECT_CHANGED
OBEP_Done:

; Successful completion. Clear zero flag
	or	sp, sp
UBEP_Exit:
	mov	ax, bx		; return value

	pop	fs
	pop	di
	pop	cx
	pop	bx
	ret

OHCIBB_EnablePort	ENDP

;<AMI_PHDR_START>
;----------------------------------------------------------------------------
; Procedure:	OHCIBB_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>

OHCIBB_DisablePort	PROC NEAR PUBLIC 

	push	ax
	push	bx
	push	di
	push	fs

; Set FS:DI to point to the memory base address of the HC
	call	OHCIBB_SetFS_DI

	xor	bx, bx
; Get the correct root hub port register offset
	mov	bl, cl
	shl	bl, 2
	add	bx, (OHCI_RH_PORT1_STATUS - 4)

	mov	DWORD PTR FS:[DI+BX], CLEAR_PORT_ENABLE

	pop	fs
	pop	di
	pop	bx
	pop	ax
	or	sp, sp		; Clear zero flag
	ret
OHCIBB_DisablePort	ENDP

;<AMI_PHDR_START>
;----------------------------------------------------------------------------
; Procedure:	OHCIBB_StopHC
;
; Description:	This function stops the OHCI controller.
;
; Input: 	DS	USB Data Area
;
; Output: 	None
;
; Modified:	Nothing
;
;----------------------------------------------------------------------------
;<AMI_PHDR_END>

OHCIBB_StopHC		PROC NEAR PUBLIC

	push	di
	push	fs

; Set FS:DI to point to the memory base address of the HC
	call	OHCIBB_SetFS_DI

; Reset the host controller
	call	OHCIBB_ResetHC

	pop	fs
	pop	di
	ret
OHCIBB_StopHC		ENDP

;<AMI_PHDR_START>
;----------------------------------------------------------------------------
; Procedure:	OHCIBB_SetFS_DI
;
; Description:	This function sets the memory base address in FS:DI
;
; Input: 	None
;
; Output: 	FS:DI	Pointer to mem base address
;
; Modified:	FS, DI
;
;----------------------------------------------------------------------------
;<AMI_PHDR_END>

OHCIBB_SetFS_DI		PROC NEAR 
	push	eax

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -