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

📄 ehci.asm

📁 dos下的USB源码(包括UHCI
💻 ASM
📖 第 1 页 / 共 5 页
字号:
; Program the HC BIOS owned bit and return the legacy
; support register offset
	mov	al, 0		; Reset HC BIOS owned semaphore
	call	EHCIProgramLegacyRegisters
; ERROR CONDITION IS NOT HANDLED
; AH	Legacy register start offset

; Program chipset to disable USB interrupts
	mov	bx, (HCStruc PTR [si]).wBusDevFuncNum
	mov	ax, ((USB_DISABLE_INTERRUPT SHL 8) + USB_EHCI)
	call	USBPort_ProgramHardwareInterrupt

; Clear the frame list pointers
	mov	eax, EHCI_TERMINATE	; Value to initialize with
	call	USBMiscInitFrameList	; SI	HCStruc pointer

; Disable TD schedule and free the data structures

; First free the QTDs & QHs allocated
	mov	bx, (HCStruc PTR [si]).pDescriptorPtr
	push	bx
	mov	bx, (EHCIDescriptors PTR [bx]).QH8ms
				; Save the value to be freed later
	push	bx
	mov	bx, (EHCIDescriptors PTR [bx]).QHControl
	mov	al, ((2 * USB_EHCI_QH_SIZE_BLK) + (4 * USB_EHCI_QTD_SIZE_BLK))
	call	USBMem_Free
	pop	bx
; Free the scheduling QHs
	mov	al,((2 * USB_EHCI_QH_SIZE_BLK) + (0 * USB_EHCI_QTD_SIZE_BLK))
	call	USBMem_Free
	pop	bx
; Free the pDescriptor pointer
	mov	al, USB_EHCI_DESCRIPTOR_SIZE_BLK
	call	USBMem_Free

IF	MKF_EHCI_ASYNC_BELL_SUPPORT
; Free the Async transfer QH
	mov	bx, pQHAsyncXfer
	mov	al, USB_EHCI_QH_SIZE_BLK
	call	USBMem_Free
ENDIF	; IF	MKF_EHCI_ASYNC_BELL_SUPPORT

esExit:
; Set the HC state to stopped
	and	(HCStruc PTR [si]).bHCFlag, NOT HC_STATE_RUNNING

	RESTORE_FS_EDI
	pop	dx
	pop	bx
	pop	ax
	ret
EHCIStop	ENDP

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

EHCIMoveDataArea	PROC		NEAR

	ret
EHCIMoveDataArea	ENDP



;<AMI_PHDR_START>
;----------------------------------------------------------------------------
; Procedure:	EHCIDisableInterrupts
;
; Description:	This function disables the HC interrupts
;
; Input: 	SI	Pointer to the HCStruc structure
;        	DS	USB Data Area
;
; Output: 	ZR	On error
;		NZ	On success
;
; Modified:	None
;
; Referrals:	HCStruc
;
;----------------------------------------------------------------------------
;<AMI_PHDR_END>

EHCIDisableInterrupts	PROC	NEAR SYSCALL

	push	eax

	EHCI_SET_FS_EDI

; Disable interrupt generation
	EHCI_DWORD_RESET_MEM	si, EHCI_USBINTR, (EHCI_USBINT_EN OR EHCI_PCDINT_EN)

; Stop periodic and asynchoronous schedule
; SI	HCStruc pointer
	call	EHCIStopAsyncSchedule
	call	EHCIStopPeriodicSchedule

	RESTORE_FS_EDI

	or	sp, sp		; Clear the zero flag
	pop	eax
	ret

EHCIDisableInterrupts	ENDP


;<AMI_PHDR_START>
;----------------------------------------------------------------------------
; Procedure:	EHCIEnableInterrupts
;
; Description:	This function enables the HC interrupts
;
; Input: 	SI	Pointer to the HCStruc structure
;        	DS	USB data area
;
; Output: 	ZR	On error
;		NZ	On success
;
; Modified:	None
;
; Referrals:	HCStruc
;
;----------------------------------------------------------------------------
;<AMI_PHDR_END>

EHCIEnableInterrupts	PROC	NEAR SYSCALL
	push	eax

	EHCI_SET_FS_EDI

; Start periodic and asynchoronous schedule
	call	EHCIStartAsyncSchedule
	call	EHCIStartPeriodicSchedule


; Enable interrupt generation
	EHCI_DWORD_SET_MEM	si, EHCI_USBINTR, (EHCI_USBINT_EN OR EHCI_PCDINT_EN)

	RESTORE_FS_EDI

	or	sp, sp		; Clear the zero flag
	pop	eax
	ret

EHCIEnableInterrupts	ENDP

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

EHCIGetRootHubStatus	PROC NEAR SYSCALL PUBLIC

	push	ebx
	push	cx
	push	dx

	EHCI_SET_FS_EDI

; Get the correct root hub port register offset
	movzx	ebx, al
	dec	bx
	shl	bl, 2	; 4*(PortNumber-1)
	add	bx, EHCI_PORTSC

; Reset all port status bits
	xor	dl, dl

	; Read the status of the port
	EHCI_DWORD_READ_MEM	si, ebx

; Check the connect status change bit
	test	al, EHCI_CONNECTSTATUSCHANGE
	jz	egpsCheckDevicePresence

; Set connect status change flag
	or	dl, USB_PORT_STAT_DEV_CONNECT_CHANGED

egpsCheckDevicePresence:
	test	al, EHCI_CURRENTCONNECTSTATUS
	jz	egpsExit		; Br if no device present

; Check whether we need to ignore connect status change
	cmp	bIgnoreConnectStsChng, TRUE
	je	egpsIgnoreCntStsChng


; Device present. Check whether there is connect status change
	test	al, EHCI_CONNECTSTATUSCHANGE
	jz	egpsExit		; No. Leave without getting speed.

egpsIgnoreCntStsChng:
; Detect the high-speed device.
; In case of low-speed or full-speed change the ownership to a
; companion 1.1 controller (if any)

; High speed device detection algorithm:
; 1. Clear connect change bit
; 2. Read LineStatus
; 3. If D+ de-asserted go to 10 (low-speed device connected)
; 4. Reset and disable the port
; 5. If PortEnable bit == 0 go to 10 (full-speed device connected)
; 6. Indicate the high-speed device is connected and go to 8
; 7. Change the port ownership by setting PortOwner bit to 1
; 8. Device detection is complete

; Clear connect change bit
	or	al, EHCI_CONNECTSTATUSCHANGE
	EHCI_DWORD_WRITE_MEM	si, ebx, eax

; Analyze Line Status
	test	eax, EHCI_DPLUSBIT
	jz	egpsReleaseOwnership	; Low-speed device connected

; Reset and disable the port
	and	al, NOT EHCI_PORTENABLE
	or	ax, EHCI_PORTRESET
	EHCI_DWORD_WRITE_MEM	si, ebx, eax

	; Wait til port disable is complete (Tdrstr=50ms Ref 7.1.7.5)
	push	ax
	mov	ax, ((50 * 1000) / 15)	; 50ms delay
	call	USBMisc_FixedDelay
	pop	ax
							; of USB Spec 2.0
	and	ax, NOT EHCI_PORTRESET
	EHCI_DWORD_WRITE_MEM	si, ebx, eax		; Terminate reset

	mov	cx, 10					; 10 ms total for
egpsWaitForResetIsComplete:				; EHCI_PORTRESET to de-assert
	mov	ax, ((1 * 1000) / 15)	; 1ms delay
	call	USBMisc_FixedDelay

	EHCI_DWORD_READ_MEM	si, ebx
	test	ax, EHCI_PORTRESET
	loopnz	egpsWaitForResetIsComplete
	jnz	egpsPortResetFailed			; Br if port is not reset

; Port reset is complete, now within 2ms HC must set the Port Enable bit in
; case High-Speed Device is connected
	mov	ax, ((2 * 1000) / 15)	; 2ms delay
	call	USBMisc_FixedDelay

	EHCI_DWORD_READ_MEM	si, ebx
	test	eax, EHCI_PORTENABLE
	jz	egpsReleaseOwnership			; Full-speed device connected

; Report the high-speed device connection and exit
	mov	dl, USB_PORT_STAT_DEV_HISPEED OR \
				USB_PORT_STAT_DEV_CONNECT_CHANGED OR \
				USB_PORT_STAT_DEV_CONNECTED
	jmp	SHORT egpsExit

egpsReleaseOwnership:
	EHCI_DWORD_READ_MEM	si, ebx
	or	eax, (EHCI_PORTOWNER + EHCI_CONNECTSTATUSCHANGE)
	EHCI_DWORD_WRITE_MEM	si, ebx, eax

	mov	ax, ((10 * 1000) / 15)	; 10ms delay
	call	USBMisc_FixedDelay

	xor	dx, dx
	jmp	SHORT egpsExit

egpsPortResetFailed:
	mov	ax, USB_ERR_PORT_RESET_FAILED
	call	USBLogError
	xor	dx, dx

egpsExit:
	EHCI_DWORD_SET_MEM	si, ebx, EHCI_CONNECTSTATUSCHANGE

	mov	ax, dx		; Return status

	RESTORE_FS_EDI

	pop	dx
	pop	cx
	pop	ebx
	ret
EHCIGetRootHubStatus	ENDP

;<AMI_PHDR_START>
;----------------------------------------------------------------------------
; Procedure:	EHCIReleasePort
;
; Description:	This function releases the ownership of particular port to
;		USB 1.1 device
;
; Input: 	SI	Host controller's HCStruc structure
;		AL	Port that has to be released
;        	DS	USB data area
;
; Output: 	None
;
; Modified:	Nothing
;
; Referrals:	HCDHeader, HCStruc
;
;----------------------------------------------------------------------------
;<AMI_PHDR_END>

EHCIReleasePort		PROC NEAR PUBLIC USES EAX EBX CX DX

	EHCI_SET_FS_EDI

; Get the correct root hub port register offset
	movzx	ebx, al
	dec	bx
	shl	bl, 2	; 4*(PortNumber-1)
	add	bx, EHCI_PORTSC

	mov	cx, 3
erd_TryAgain:
; Release the device - ownership
	EHCI_DWORD_READ_MEM	si, ebx
	or	eax, (EHCI_PORTOWNER + EHCI_CONNECTSTATUSCHANGE)
	EHCI_DWORD_WRITE_MEM	si, ebx, eax

	mov	ax, ((10 * 1000) / 15)	; 10ms delay
	call	USBMisc_FixedDelay

	EHCI_DWORD_READ_MEM	si, ebx
	test	eax, EHCI_PORTOWNER
	loopz	erd_TryAgain	; Not released try again

	RESTORE_FS_EDI
	ret
EHCIReleasePort		ENDP

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

EHCIDisableRootHub	PROC	NEAR SYSCALL PUBLIC

	push	ax
	push	ebx

	EHCI_SET_FS_EDI

; Get the correct root hub port register offset
	movzx	ebx, al
	dec	bx
	shl	bl, 2	; 4*(PortNumber-1)
	add	bx, EHCI_PORTSC


	EHCI_DWORD_RESET_MEM	si, ebx, EHCI_PORTENABLE

	; Wait til port disable is complete (Tdrstr=50ms Ref 7.1.7.5)
	mov	ax, ((50 * 1000) / 15)	; 50ms delay
	call	USBMisc_FixedDelay

	RESTORE_FS_EDI

	or	sp, sp		; Clear zero flag indicating success
	pop	ebx
	pop	ax
	ret

EHCIDisableRootHub	ENDP


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

EHCIEnableRootHub	PROC NEAR SYSCALL PUBLIC

; Software can only enable the EHCI root hub ports by port RESET.  HC will
; enable the port only if it is a high speed device
	or	sp, sp		; Clear zero flag indicating success
	ret

EHCIEnableRootHub	ENDP

;<AMI_PHDR_START>
;----------------------------------------------------------------------------
; Procedure:	EHCI_GetHiSpeedHubPortNumber
;
; Description:	This function gets the hi-speed hub's device and port number
;		to which this low speed device is connected.  It parses
;		through its parents until it finds the correct device. This
;		information is used for split transaction
;
; Input: 	BX	Device info pointer of the device
;
; Output: 	AX	Device/port number of the hi-speed hub
;
; Modified:	AX
;
; Notes:	This low/full speed device may be behind different hubs as

⌨️ 快捷键说明

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