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

📄 usbhub.asm

📁 dos下的USB源码(包括UHCI
💻 ASM
📖 第 1 页 / 共 2 页
字号:
	TITLE	USBHUB.ASM -- USB Hub Protocol Handler

;***************************************************************************;
;***************************************************************************;
;**                                                                       **;
;**           (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/USBHUB.ASM 3     12/17/02 3:17p Sivagarn $
;
; $Revision: 3 $
;
; $Date: 12/17/02 3:17p $
;***************************************************************************;
; Revision History
; ----------------
; $Log: /BIOS/Corebin/800/Modules/USB2/Template/Core/USBHUB.ASM $
; 
; 3     12/17/02 3:17p Sivagarn
; - Changed copyright message year to 2003
; - An equate is added to reverse the hub port scan order (used for
; debugging only)
; 
; 2     10/14/02 8:57p Sivagarn
;  * Code cleanup
;  * Structure fields are updated
; 
; 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

;;; Enabled reverse port scan order
;;;USB_HUB_REVERSE_PORT_SCAN_ORDER		EQU	0
;----------------------------------------------------------------------------
;		External data definitions are defined here
;----------------------------------------------------------------------------
	EXTERN	bUSBDeviceList:BYTE
;----------------------------------------------------------------------------

;----------------------------------------------------------------------------
;		External function definitions are defined here
;----------------------------------------------------------------------------
USBCheckPortChange		PROTO NEAR SYSCALL
USBStopDevice			PROTO NEAR SYSCALL
USBGetDeviceInfoFromDevAddr	PROTO NEAR SYSCALL

USBMem_Alloc			PROTO NEAR SYSCALL
				; AL - bNumBlocks
USBMem_Free			PROTO NEAR SYSCALL
				; AL - bNumBlocks, BX - wMemBlock

USBActivateDevicePolling	PROTO NEAR SYSCALL

USBMisc_FixedDelay		PROTO NEAR SYSCALL
				; AX - wCount

USBIssueControlTransfer			PROTO NEAR SYSCALL
USBIssueControlTransferWithoutData	PROTO NEAR SYSCALL

;----------------------------------------------------------------------------

;----------------------------------------------------------------------------
;		Public function definitions are defined here
;----------------------------------------------------------------------------
;----------------------------------------------------------------------------

;----------------------------------------------------------------------------
;		Function prototype definitions are here
;----------------------------------------------------------------------------
USBHub_DisablePort	PROTO NEAR SYSCALL
USBHub_GetPortStatus	PROTO NEAR SYSCALL
USBHub_ProcessHubData	PROTO NEAR SYSCALL
USBHub_EnablePort	PROTO NEAR SYSCALL
;----------------------------------------------------------------------------

;----------------------------------------------------------------------------
;		External data definitions are done here
;----------------------------------------------------------------------------
	EXTERN	bEnumFlag:BYTE
;----------------------------------------------------------------------------

;----------------------------------------------------------------------------
;	D A T A   S E G M E N T
;----------------------------------------------------------------------------
USB_DSEG 	SEGMENT 	WORD PUBLIC 'DATA'
		PUBLIC wHubPortStatus
wHubPortStatus		DW		?

dTempHubPortStatus	DD		?
USB_DSEG 	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	_USBHUB_ASM_START
_USBHUB_ASM_START	LABEL		BYTE

	PUBLIC	USBHubDeviceHeader
USBHubDeviceHeader		LABEL		USB_DEV_HDR
	DB	BIOS_DEV_TYPE_HUB
	DW	0				; Init
	DW	OFFSET USBHubCheckForHub	; Identify
	DW	OFFSET USBHubConfigureHub	; Configure
	DW	OFFSET USBHubDisconnect		; Disconnect

;<AMI_PHDR_START>
;----------------------------------------------------------------------------
; Procedure:	USBHubCheckForHub
;
; Description:	This routine checks for hub type device from the
;		interface data provided
;
; Input: 	DL+	USB base class code
;		DH	USB sub-class code
;		DL	USB protocol code
;
; Output: 	AX	BIOS_DEV_TYPE_HUB type on success or 0FFH on error
;
; Modified:	AX
;
;----------------------------------------------------------------------------
;<AMI_PHDR_END>

USBHubCheckForHub	PROC NEAR SYSCALL PUBLIC 

	push	edx
	mov	ax, 0FFh		; Device type unknown

	shr	edx, 8
; Check the BaseClass for hub
	cmp	dh, BASE_CLASS_HUB
	jne	UHCFH_Done	;Br if this interface is not a Hub device

	mov	ax, BIOS_DEV_TYPE_HUB
UHCFH_Done:
	pop	edx
	ret
USBHubCheckForHub		ENDP

;<AMI_PHDR_START>
;----------------------------------------------------------------------------
; Procedure:	USBHubConfigureHub
;
; Description:	This function checks an interface descriptor of a device
;		to see if it describes a USB hub.  If the device is a hub,
;		then it is configured and initialized.
;
; Input: 	BX	Device information structure pointer
;		DI	Pointer to the descriptor structure
;		CX	End offset of the device descriptor
;
; Output: 	ZR	On error
;		NZ	On success
;			BX - New DeviceInfo structure
;
; Modified:	BX
;
; Referrals:	HCStruc
;
;----------------------------------------------------------------------------
;<AMI_PHDR_END>

USBHubConfigureHub	PROC NEAR SYSCALL PUBLIC

	push	eax
	push	ebx
	push	cx
	push	si
	push	di

; Set the BiosDeviceType field in DeviceTableEntry[0].  This serves as a flag
; that indicates a usable interface has been found in the current
; configuration. This is needed so we can check for other usable interfaces
; in the current configuration (i.e. composite device), but not try to search
; in other configurations.

	mov     (DeviceInfo PTR [bx]).bDeviceType, BIOS_DEV_TYPE_HUB
	mov     (DeviceInfo PTR [bx]).pDeviceCallback, \
					OFFSET cs:USBHub_ProcessHubData

	mov	(DeviceInfo PTR [bx]).pDevDriverPtr, \
					OFFSET USBHubDeviceHeader

; Allocate memory for getting hub descriptor
	mov	ax, (MAX_CONTROL_DATA_SIZE / USB_MEM_BLK_SIZE)
	call	USBMem_Alloc
	jz	UHCH_Done

; Set the buffer pointer
	mov	dx, ax
	push	ds
	push	ax
	pop	eax
	mov	(DeviceInfo PTR [bx]).CntrlXfer.fpBuffer, eax

	xor	ax, ax
	mov	(DeviceInfo PTR [bx]).CntrlXfer.wIndex, ax

; Set data length
	mov	(DeviceInfo PTR [bx]).CntrlXfer.wLength, (MAX_CONTROL_DATA_SIZE - 1)

; Set request type
	mov	(DeviceInfo PTR [bx]).CntrlXfer.wRequest, USB_RQ_GET_CLASS_DESCRIPTOR

; Set wValue
	mov	(DeviceInfo PTR [bx]).CntrlXfer.wValue, DESC_TYPE_CLASS_HUB
; Invoke the control transfer function in the HCD
; BX - pDevInfo
	call	USBIssueControlTransfer		; Retries
	; ZR - on error, NZ on success
	jz	UHCH_FreeAndExit	; Free buffer and exit

	mov	di, dx
	mov	al, (HubDescriptor ptr [di]).bNumPorts
					; AL = # of ports on hub
	mov	(DeviceInfo PTR [bx]).bHubNumPorts, al

	mov	al, (HubDescriptor ptr [di]).bPowerOnDelay
					; AL = Port power on delay
	mov	(DeviceInfo PTR [bx]).bHubPowerOnDelay, al
					; Hub's ports have not been enumerated

; Turn on power to all of the hub's ports by setting its port power features.
; This is needed because hubs cannot detect a device attach until port power
; is turned on.

	movzx	cx, (DeviceInfo PTR [bx]).bHubNumPorts	

; The following initialization is needed for one shot only
; Set request type & wValue
	mov	eax, (HUB_RQ_SET_PORT_FEATURE SHL 16) + HUB_FEATURE_PORT_POWER
UHCH_NextPort:

; Set wIndex in EBX+
	push	cx
	push	bx
	pop	ebx
; Invoke the control transfer function in the HCD
; BX	Pointer to device info structure
; BX+	wIndex
; AX	wValue
; AX+	wRequest
	call	USBIssueControlTransferWithoutData	; Retries
	; ZR - on error, NZ on success
; Error is not processed here

	loop	UHCH_NextPort		; Branch if still more ports to power on

; Delay the amount of time specified in the PowerOnDelay field of
; the hub descriptor.
	movzx	ax, (DeviceInfo PTR [bx]).bHubPowerOnDelay
	shl	ax, 1			; In ms
	add	ax, 30			; Add 30 ms to the normal time
	shl	ax, 6			; multiply by 64 (in 15us)
	call	USBMisc_FixedDelay


; Send device wakeup command to the hub
	movzx	ebx, bx			; Clear EBX+
	mov	eax, (USB_RQ_SET_FEATURE SHL 16) + USB_FSEL_DEV_REMOTE_WAKEUP
	call	USBIssueControlTransferWithoutData

	xor	ax, ax
	mov	(DeviceInfo PTR [bx]).pPollTDPtr, ax
	mov	(DeviceInfo PTR [bx]).pPollEDPtr, ax		;; For OHCI

	or	(DeviceInfo PTR [bx]).bFlag, (DEV_INFO_VALID_STRUC OR DEV_INFO_DEV_PRESENT)

; Free the allocated buffer
	mov	al, (MAX_CONTROL_DATA_SIZE / USB_MEM_BLK_SIZE)
	xchg	bx, dx
	call	USBMem_Free
	xchg	dx, bx			; Restore BX

; Enable enumeration
	mov	bEnumFlag, FALSE

	mov	si, (DeviceInfo PTR [bx]).pHCStrucPtr

; Check for new devices behind the hub
	mov	wHubPortStatus, 0FFFFh
	lea	di, wHubPortStatus
; BX	Device Info
; SI	HCStruc pointer
; DI	Pointer to the data buffer
	call	USBHub_ProcessHubData

; Disable enumeration
	mov	bEnumFlag, TRUE

; Start polling the new device's interrupt endpoint.
; BX - DeviceInfo structure
	call	USBActivateDevicePolling
	jmp	SHORT UHCH_Done

UHCH_FreeAndExit:
; Free the allocated buffer
	mov	al, (MAX_CONTROL_DATA_SIZE / USB_MEM_BLK_SIZE)
	xchg	bx, dx
	call	USBMem_Free

UHCH_Done:
	pop	di
	pop	si
	pop	cx
	pop	ebx
	pop	eax
	ret
USBHubConfigureHub	Endp

;<AMI_PHDR_START>
;----------------------------------------------------------------------------
; Procedure:	USBHubDisconnect
;
; Description:	This routine disconnects the hub by disconnecting all the
;		devices behind it
;
; Input: 	BX	Device info structure pointer
;
; Output: 	Nothing
;
; Modified:	Nothing
;
;----------------------------------------------------------------------------
;<AMI_PHDR_END>

USBHubDisconnect	PROC NEAR SYSCALL PUBLIC

	LOCAL	bTemp1:BYTE, bTemp2:BYTE

	push	ax
	push	dx
	push	si

; Load the register with device info and HCStruc pointers
	mov	si, (DeviceInfo PTR [bx]).pHCStrucPtr

; A hub device is being disconnected.  For each of the hub's ports disconnect
; any child device connected.
	mov	dh, (DeviceInfo PTR [bx]).bDeviceAddress
	mov	dl, 1		; bTemp2 = Port number

UDD_DisconnectNextPort:

; Disconnect device and its children
; DH - Hub number
; DL - Port number
; SI - HCStruc pointer
	call	USBStopDevice
	inc	dl		; Next port

	cmp	dl, (DeviceInfo PTR [bx]).bHubNumPorts
	jbe	UDD_DisconnectNextPort	;Br if still more ports to disconnect

	and	(DeviceInfo PTR [bx]).bFlag, NOT (DEV_INFO_VALID_STRUC OR DEV_INFO_DEV_PRESENT)

	pop	si
	pop	dx
	pop	ax
	ret
USBHubDisconnect	ENDP

;<AMI_PHDR_START>
;----------------------------------------------------------------------------
; Procedure:	USBHubGetPortStatusFromDevice
;
; Description:	This routine gets the status information of the hub
;
; Input: 	BX	Device info structure pointer
;		DH	Hub device address
;		DL	Hub port number
;		AX	Hub port status
;
; Output: 	AX	Hub port status
;
; Modified:	AX
;
;----------------------------------------------------------------------------
;<AMI_PHDR_END>

USBHubGetPortStatusFromDevice		PROC	NEAR

	push	di

	lea	di, dTempHubPortStatus
	xor	eax, eax
	mov	(DeviceInfo PTR [bx]).CntrlXfer.wValue, ax
	mov	dTempHubPortStatus, eax

	mov	al, dl
	mov	(DeviceInfo PTR [bx]).CntrlXfer.wIndex, ax

; Set DS for the far pointer
	push	ds
	push	di
	pop	eax
	mov	(DeviceInfo PTR [bx]).CntrlXfer.fpBuffer, eax

; Set data length
	mov	(DeviceInfo PTR [bx]).CntrlXfer.wLength, 4

; Set request type
	mov	(DeviceInfo PTR [bx]).CntrlXfer.wRequest, HUB_RQ_GET_PORT_STATUS

; BX - pDevInfo
; Perform control transfer with device request as HUB_RQ_GET_PORT_STATUS,

⌨️ 快捷键说明

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