ehci.h
来自「winNT技术操作系统,国外开放的原代码和LIUX一样」· C头文件 代码 · 共 808 行 · 第 1/2 页
H
808 行
/*
* Copyright (c) 2001-2002 by David Brownell
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the
* Free Software Foundation; either version 2 of the License, or (at your
* option) any later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#ifndef __EHCI_H__
#define __EHCI_H__
#define EHCI_QH_SIZE sizeof( EHCI_QH )
#define EHCI_ITD_SIZE sizeof( EHCI_ITD )
#define EHCI_SITD_SIZE sizeof( EHCI_SITD )
#define EHCI_FSTN_SIZE sizeof( EHCI_FSTN )
#define EHCI_QTD_SIZE sizeof( EHCI_QTD )
#define INIT_LIST_FLAG_TYPE 0x0f
#define INIT_LIST_FLAG_ITD 0x00
#define INIT_LIST_FLAG_QH 0x01
#define INIT_LIST_FLAG_SITD 0x02
#define INIT_LIST_FLAG_FSTN 0x03
#define INIT_LIST_FLAG_QTD 0x04
#define EHCI_MAX_SIZE_TRANSFER 0x100000 // 1 MB per transfer
#define EHCI_MAX_ELEMS_POOL 1024
#define EHCI_MAX_LISTS_POOL 0x08
#define EHCI_MAX_QHS_LIST 256 // 4 pages
#define EHCI_MAX_ITDS_LIST ( PAGE_SIZE / EHCI_ITD_SIZE * 2 ) // 2 pages
#define EHCI_MAX_SITDS_LIST ( PAGE_SIZE / EHCI_SITD_SIZE )// 1 page
#define EHCI_MAX_FSTNS_LIST ( PAGE_SIZE / EHCI_FSTN_SIZE )// 1 page
#define EHCI_MAX_QTDS_LIST 256 // 4 pages
#define EHCI_PTR_TERM 0x01
#define EHCI_NAK_RL_COUNT 0x04
#define EHCI_QTD_MAX_TRANS_SIZE 20480
#define PHYS_PART_TYPE_MASK 0x01f
#define PHYS_PART_ADDR_MASK ( ~PHYS_PART_TYPE_MASK )
typedef struct _EHCI_ELEM_LINKS
{
LIST_ENTRY elem_link; // link for one urb request
LIST_ENTRY sched_link; // to shadow link of schedule
struct _EHCI_ELEM_POOL* pool_link;
struct _EHCI_ELEM_LIST* list_link; // opaque to client, which list this td belongs to
PVOID phys_part; // point to EHCI_XXX, the lower 5 bits is used to indicate the type of the element
PURB purb;
} EHCI_ELEM_LINKS, *PEHCI_ELEM_LINKS;
typedef struct _INIT_ELEM_LIST_CONTEXT
{
PADAPTER_OBJECT padapter;
struct _EHCI_ELEM_POOL *pool;
} INIT_ELEM_LIST_CONTEXT, *PINIT_ELEM_LIST_CONTEXT;
typedef VOID ( *PDESTROY_ELEM_LIST )( struct _EHCI_ELEM_LIST* plist );
typedef PLIST_ENTRY ( *PGET_LIST_HEAD )( struct _EHCI_ELEM_LIST* plist );
typedef LONG ( *PGET_TOTAL_COUNT )( struct _EHCI_ELEM_LIST* plist );
typedef LONG ( *PGET_ELEM_SIZE )( struct _EHCI_ELEM_LIST* plist );
typedef LONG ( *PGET_LINK_OFFSET )( struct _EHCI_ELEM_LIST* plist );
typedef LONG ( *PADD_REF )( struct _EHCI_ELEM_LIST* plist );
typedef LONG ( *PRELEASE_REF )( struct _EHCI_ELEM_LIST* plist );
typedef LONG ( *PGET_REF )( struct _EHCI_ELEM_LIST* plist );
typedef struct _EHCI_ELEM_LIST
{
PDESTROY_ELEM_LIST destroy_list;
PGET_LIST_HEAD get_list_head;
PGET_TOTAL_COUNT get_total_count;
PGET_ELEM_SIZE get_elem_size;
PGET_LINK_OFFSET get_link_offset;
PADD_REF add_ref;
PRELEASE_REF release_ref;
PGET_REF get_ref;
// private area
LONG flags; // contails element's type info
LONG total_count;
LONG elem_size;
LIST_HEAD free_list; // chains of all the elements
struct _EHCI_ELEM_POOL *parent_pool;
LONG reference;
// used to represent the physical memory
PPHYSICAL_ADDRESS phys_addrs; // array of non-contigous memory
PBYTE *phys_bufs;
PEHCI_ELEM_LINKS elem_head_buf;
PADAPTER_OBJECT padapter;
} EHCI_ELEM_LIST, *PEHCI_ELEM_LIST;
BOOLEAN elem_pool_init_pool( struct _EHCI_ELEM_POOL* pool, LONG flags, PVOID context);
VOID elem_pool_destroy_pool ( struct _EHCI_ELEM_POOL* pool );
PEHCI_ELEM_LINKS elem_pool_alloc_elem ( struct _EHCI_ELEM_POOL* pool );
VOID elem_pool_free_elem ( PEHCI_ELEM_LINKS elem_link );
LONG elem_pool_get_total_count ( struct _EHCI_ELEM_POOL* pool );
BOOLEAN elem_pool_is_empty ( struct _EHCI_ELEM_POOL* pool );
LONG elem_pool_get_free_count ( struct _EHCI_ELEM_POOL* pool );
LONG elem_pool_get_link_offset ( struct _EHCI_ELEM_POOL* pool );
PEHCI_ELEM_LINKS elem_pool_alloc_elems ( struct _EHCI_ELEM_POOL* pool, LONG count );
BOOLEAN elem_pool_free_elems( PEHCI_ELEM_LINKS elem_chains );
LONG elem_pool_get_type( struct _EHCI_ELEM_POOL* pool );
// the following are private functions
BOOLEAN elem_pool_expand_pool( struct _EHCI_ELEM_POOL* pool, LONG elem_count );
BOOLEAN elem_pool_collect_garbage( struct _EHCI_ELEM_POOL* pool );
// lock operations
BOOLEAN elem_pool_lock( struct _EHCI_ELEM_POOL* pool, BOOLEAN at_dpc );
BOOLEAN elem_pool_unlock( struct _EHCI_ELEM_POOL* pool, BOOLEAN at_dpc );
// helper
LONG get_elem_phys_part_size( ULONG type );
typedef struct _EHCI_ELEM_POOL
{
LONG flags;
LONG free_count; // free count of all the lists currently allocated
LONG link_offset; // a cache for elem_list->get_link_offset
LONG list_count; // lists currently allocated
PEHCI_ELEM_LIST elem_lists[ EHCI_MAX_LISTS_POOL ];
} EHCI_ELEM_POOL, *PEHCI_ELEM_POOL;
/*-------------------------------------------------------------------------*/
#define QTD_NEXT(dma) cpu_to_le32((u32)dma)
/*
* EHCI Specification 0.95 Section 3.5
* QTD: describe data transfer components (buffer, direction, ...)
* See Fig 3-6 "Queue Element Transfer Descriptor Block Diagram".
*
* These are associated only with "QH" (Queue Head) structures,
* used with control, bulk, and interrupt transfers.
*/
#define QTD_TOGGLE (1 << 31) /* data toggle */
#define QTD_LENGTH(tok) (((tok)>>16) & 0x7fff)
#define QTD_IOC (1 << 15) /* interrupt on complete */
#define QTD_CERR(tok) (((tok)>>10) & 0x3)
#define QTD_PID(tok) (((tok)>>8) & 0x3)
#define QTD_STS_ACTIVE (1 << 7) /* HC may execute this */
#define QTD_STS_HALT (1 << 6) /* halted on error */
#define QTD_STS_DBE (1 << 5) /* data buffer error (in HC) */
#define QTD_STS_BABBLE (1 << 4) /* device was babbling (qtd halted) */
#define QTD_STS_XACT (1 << 3) /* device gave illegal response */
#define QTD_STS_MMF (1 << 2) /* incomplete split transaction */
#define QTD_STS_STS (1 << 1) /* split transaction state */
#define QTD_STS_PING (1 << 0) /* issue PING? */
#define QTD_ANY_ERROR ( QTD_STS_HALT | QTD_STS_DBE | QTD_STS_XACT | QTD_STS_MMF | QTD_STS_BABBLE )
#define QTD_PID_SETUP 0x02
#define QTD_PID_IN 0x01
#define QTD_PID_OUT 0x00
#pragma pack( push, usb_align, 1 )
typedef struct _EHCI_QTD_CONTENT
{
// DWORD 0
ULONG terminal : 1;
ULONG reserved : 4;
ULONG next_qtd : 27;
// DWORD 1
ULONG alt_terminal : 1;
ULONG reserved1 : 4;
ULONG alt_qtd : 27;
// DWORD 2
ULONG status : 8;
ULONG pid : 2;
ULONG err_count : 2;
ULONG cur_page : 3;
ULONG ioc : 1;
ULONG bytes_to_transfer : 15;
ULONG data_toggle : 1;
// DWORD 3
ULONG cur_offset : 12;
ULONG page0 : 20;
// DWORD 4-
ULONG pages[ 4 ];
} EHCI_QTD_CONTENT, *PEHCI_QTD_CONTENT;
typedef struct _EHCI_QTD
{
/* first part defined by EHCI spec */
ULONG hw_next; /* see EHCI 3.5.1 */
ULONG hw_alt_next; /* see EHCI 3.5.2 */
ULONG hw_token; /* see EHCI 3.5.3 */
ULONG hw_buf [5]; /* see EHCI 3.5.4 */
/* the rest is HCD-private */
PEHCI_ELEM_LINKS elem_head_link;
ULONG phys_addr; /* qtd address */
USHORT bytes_to_transfer; /* the bytes_to_transfer in hw_token will drop to zero when completed*/
USHORT reserved2;
ULONG reserved[ 5 ];
} EHCI_QTD, *PEHCI_QTD; //__attribute__ ((aligned (32)));
#define QTD_MASK cpu_to_le32 (~0x1f) /* mask NakCnt+T in qh->hw_alt_next */
/*-------------------------------------------------------------------------*/
/* type tag from {qh,itd,sitd,fstn}->hw_next */
#define Q_NEXT_TYPE(dma) ((dma) & __constant_cpu_to_le32 (3 << 1))
/* values for that type tag */
#define Q_TYPE_ITD (0 << 1)
#define Q_TYPE_QH (1 << 1)
#define Q_TYPE_SITD (2 << 1)
#define Q_TYPE_FSTN (3 << 1)
/* next async queue entry, or pointer to interrupt/periodic QH */
#define QH_NEXT(dma) (cpu_to_le32(((u32)dma)&~0x01f)|Q_TYPE_QH)
/* for periodic/async schedules and qtd lists, mark end of list */
#define EHCI_LIST_END __constant_cpu_to_le32(1) /* "null pointer" to hw */
/*-------------------------------------------------------------------------*/
/*
* EHCI Specification 0.95 Section 3.6
* QH: describes control/bulk/interrupt endpoints
* See Fig 3-7 "Queue Head Structure Layout".
*
* These appear in both the async and (for interrupt) periodic schedules.
*/
#define QH_HEAD 0x00008000
#define QH_STATE_LINKED 1 /* HC sees this */
#define QH_STATE_UNLINK 2 /* HC may still see this */
#define QH_STATE_IDLE 3 /* HC doesn't see this */
#define QH_STATE_UNLINK_WAIT 4 /* LINKED and on reclaim q */
#define QH_STATE_COMPLETING 5 /* don't touch token.HALT */
#define NO_FRAME ((unsigned short)~0) /* pick new start */
typedef struct _EHCI_QH_CONTENT
{
// DWORD 0
ULONG terminal : 1;
ULONG ptr_type : 2;
ULONG reserved : 2;
ULONG next_link : 27;
// DWORD 1
ULONG dev_addr : 7;
ULONG inactive : 1;
ULONG endp_addr : 4;
ULONG endp_spd : 2;
ULONG data_toggle : 1;
ULONG is_async_head : 1;
ULONG max_packet_size : 11;
ULONG is_ctrl_endp : 1;
ULONG reload_counter : 4;
// DWORD 2
ULONG s_mask : 8;
ULONG c_mask : 8;
ULONG hub_addr : 7;
ULONG port_idx : 7;
ULONG mult : 2;
// DWORD 3
ULONG cur_qtd_ptr;
// overlay
EHCI_QTD_CONTENT cur_qtd;
} EHCI_QH_CONTENT, *PEHCI_QH_CONTENT;
typedef struct _EHCI_QH
{
/* first part defined by EHCI spec */
ULONG hw_next; /* see EHCI 3.6.1 */
ULONG hw_info1; /* see EHCI 3.6.2 */
ULONG hw_info2; /* see EHCI 3.6.2 */
ULONG hw_current; /* qtd list - see EHCI 3.6.4 */
/* qtd overlay (hardware parts of a struct ehci_qtd) */
ULONG hw_qtd_next;
ULONG hw_alt_next;
ULONG hw_token;
ULONG hw_buf [5];
/* the rest is HCD-private */
PEHCI_ELEM_LINKS elem_head_link;
ULONG phys_addr; /* address of qh */
ULONG reserved[ 2 ];
} EHCI_QH, *PEHCI_QH; // __attribute__ ((aligned (32)));
/*-------------------------------------------------------------------------*/
/*
* EHCI Specification 0.95 Section 3.3
* Fig 3-4 "Isochronous Transaction Descriptor (iTD)"
*
* Schedule records for high speed iso xfers
*/
#define EHCI_ISOC_ACTIVE (1<<31) /* activate transfer this slot */
#define EHCI_ISOC_BUF_ERR (1<<30) /* Data buffer error */
#define EHCI_ISOC_BABBLE (1<<29) /* babble detected */
#define EHCI_ISOC_XACTERR (1<<28) /* XactErr - transaction error */
#define EHCI_ITD_LENGTH(tok) (((tok)>>16) & 0x7fff)
#define EHCI_ITD_IOC (1 << 15) /* interrupt on complete */
#define ITD_STS_ACTIVE 8
#define ITD_STS_BUFERR 4
#define ITD_STS_BABBLE 2
#define ITD_STS_XACTERR 1
#define ITD_ANY_ERROR ( ITD_STS_BUFERR | ITD_STS_BABBLE | ITD_STS_XACTERR )
typedef struct _EHCI_ITD_STATUS_SLOT
{
ULONG offset : 12;
ULONG page_sel : 3;
ULONG ioc : 1;
ULONG trans_length : 12;
ULONG status : 4;
} EHCI_ITD_STATUS_SLOT, *PEHCI_ITD_STATUS_SLOT;
typedef struct _EHCI_ITD_CONTENT
{
// DWORD 0;
ULONG terminal : 1;
ULONG ptr_type : 2;
ULONG reserved : 2;
ULONG next_link : 27;
// DWORD 1-8;
EHCI_ITD_STATUS_SLOT status_slot[ 8 ];
// DWORD 9;
ULONG dev_addr : 7;
ULONG reserved1 : 1;
ULONG endp_num : 4;
ULONG page0 : 20;
// DWORD 10;
ULONG max_packet_size : 11;
ULONG io_dir : 1;
ULONG page1 : 20;
// DWORD 11;
ULONG mult : 2;
ULONG reserved2 : 10;
ULONG page2 : 20;
// DWORD 12-;
ULONG pages[ 4 ];
} EHCI_ITD_CONTENT, *PEHCI_ITD_CONTENT;
typedef struct _EHCI_ITD {
/* first part defined by EHCI spec */
ULONG hw_next; /* see EHCI 3.3.1 */
ULONG hw_transaction [8]; /* see EHCI 3.3.2 */
ULONG hw_bufp [7]; /* see EHCI 3.3.3 */
/* the rest is EHCI-private */
PEHCI_ELEM_LINKS elem_head_link;
ULONG phys_addr; /* for this itd */
ULONG buf_phys_addr; /* buffer address */
ULONG reserved[ 5 ];
} EHCI_ITD, *PEHCI_ITD; // __attribute__ ((aligned (32)));
/*-------------------------------------------------------------------------*/
/*
* EHCI Specification 0.95 Section 3.4
* siTD, aka split-transaction isochronous Transfer Descriptor
* ... describe low/full speed iso xfers through TT in hubs
* see Figure 3-5 "Split-transaction Isochronous Transaction Descriptor (siTD)
*/
#define SITD_STS_ACTIVE 0x80
#define SITD_STS_ERR 0x40 // error from device
#define SITD_STS_DBE 0x20 // data buffer error
#define SITD_STS_BABBLE 0x10 // data more than expected
#define SITD_STS_XACTERR 0x08 // general error on hc
#define SITD_STS_MISSFRM 0x04 // missd micro frames
#define SITD_STS_SC 0x02 // state is whether start-split( 0 ) or complete-split( 1 )
#define SITD_STS_RESERVED 0x01
#define SITD_ANY_ERROR ( SITD_STS_ERR | SITD_STS_DBE | SITD_STS_BABBLE | SITD_STS_XACTERR | SITD_STS_MISSFRM )
typedef struct _EHCI_SITD_CONTENT
{
// DWORD 0;
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?