summaryrefslogtreecommitdiff
path: root/MdeModulePkg/Bus/Usb/UsbBusDxe/UsbHub.h
blob: af4897a74b5dd61b6cb3e9be82c7d56eb6abc6cf (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
/** @file

    The definition for USB hub.

Copyright (c) 2007, Intel Corporation
All rights reserved. This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License
which accompanies this distribution.  The full text of the license may be found at
http://opensource.org/licenses/bsd-license.php

THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.

**/

#ifndef _USB_HUB_H_
#define _USB_HUB_H_

#include <IndustryStandard/Usb.h>

#define USB_ENDPOINT_ADDR(EpAddr) ((EpAddr) & 0x7F)
#define USB_ENDPOINT_TYPE(Desc)   ((Desc)->Attributes & USB_ENDPOINT_TYPE_MASK)

typedef enum {
  USB_DESC_TYPE_HUB           = 0x29,

  //
  // Hub class control transfer target
  //
  USB_HUB_TARGET_HUB          = 0,
  USB_HUB_TARGET_PORT         = 3,

  //
  // HUB class specific contrl transfer request type
  //
  USB_HUB_REQ_GET_STATUS      = 0,
  USB_HUB_REQ_CLEAR_FEATURE   = 1,
  USB_HUB_REQ_SET_FEATURE     = 3,
  USB_HUB_REQ_GET_DESC        = 6,
  USB_HUB_REQ_SET_DESC        = 7,
  USB_HUB_REQ_CLEAR_TT        = 8,
  USB_HUB_REQ_RESET_TT        = 9,
  USB_HUB_REQ_GET_TT_STATE    = 10,
  USB_HUB_REQ_STOP_TT         = 11,


  //
  // USB hub class feature selector
  //
  USB_HUB_C_HUB_LOCAL_POWER   = 0,
  USB_HUB_C_HUB_OVER_CURRENT  = 1,
  USB_HUB_PORT_CONNECTION     = 0,
  USB_HUB_PORT_ENABLE         = 1,
  USB_HUB_PORT_SUSPEND        = 2,
  USB_HUB_PORT_OVER_CURRENT   = 3,
  USB_HUB_PORT_RESET          = 4,
  USB_HUB_PORT_POWER          = 8,
  USB_HUB_PORT_LOW_SPEED      = 9,
  USB_HUB_C_PORT_CONNECT      = 16,
  USB_HUB_C_PORT_ENABLE       = 17,
  USB_HUB_C_PORT_SUSPEND      = 18,
  USB_HUB_C_PORT_OVER_CURRENT = 19,
  USB_HUB_C_PORT_RESET        = 20,
  USB_HUB_PORT_TEST           = 21,
  USB_HUB_PORT_INDICATOR      = 22,

  //
  // USB hub power control method. In gang power control
  //
  USB_HUB_GANG_POWER_CTRL     = 0,
  USB_HUB_PORT_POWER_CTRL     = 0x01,

  //
  // USB hub status bits
  //
  USB_HUB_STAT_LOCAL_POWER    = 0x01,
  USB_HUB_STAT_OVER_CURRENT   = 0x02,
  USB_HUB_STAT_C_LOCAL_POWER  = 0x01,
  USB_HUB_STAT_C_OVER_CURRENT = 0x02,

  USB_HUB_CLASS_CODE          = 0x09,
  USB_HUB_SUBCLASS_CODE       = 0x00,

  //
  // Host software return timeout if port status doesn't change 
  // after 500ms(LOOP * STALL = 100 * 5ms), set by experience
  //
  USB_WAIT_PORT_STS_CHANGE_LOOP   = 100
}USB_HUB_FLAGS_VALUE;

#pragma pack(1)
//
// Hub descriptor, the last two fields are of variable lenght.
//
typedef struct {
  UINT8           Length;
  UINT8           DescType;
  UINT8           NumPorts;
  UINT16          HubCharacter;
  UINT8           PwrOn2PwrGood;
  UINT8           HubContrCurrent;
  UINT8           Filler[16];
} EFI_USB_HUB_DESCRIPTOR;
#pragma pack()


typedef struct {
  UINT16                ChangedBit;
  EFI_USB_PORT_FEATURE  Feature;
} USB_CHANGE_FEATURE_MAP;


/**
  Clear the transaction translate buffer if full/low
  speed control/bulk transfer failed and the transfer
  uses this hub as translator.Remember to clear the TT
  buffer of transaction translator, not that of the
  parent.

  @param  UsbDev                The Usb device.
  @param  Port                  The port of the hub.
  @param  DevAddr               Address of the failed transaction.
  @param  EpNum                 The endpoint number of the failed transaction.
  @param  EpType                The type of failed transaction.

  @retval EFI_SUCCESS           The TT buffer is cleared.
  @retval Others                Failed to clear the TT buffer.

**/
EFI_STATUS
UsbHubCtrlClearTTBuffer (
  IN USB_DEVICE           *UsbDev,
  IN UINT8                Port,
  IN UINT16               DevAddr,
  IN UINT16               EpNum,
  IN UINT16               EpType
  );


/**
  Test whether the interface is a hub interface.

  @param  UsbIf                 The interface to test.

  @retval TRUE                  The interface is a hub interface.
  @retval FALSE                 The interface isn't a hub interface.

**/
BOOLEAN
UsbIsHubInterface (
  IN USB_INTERFACE        *UsbIf
  );


/**
  Ack the hub change bits. If these bits are not ACKed, Hub will
  always return changed bit map from its interrupt endpoint.

  @param  UsbDev                The Usb device.

  @retval EFI_SUCCESS           The hub change status is ACKed.
  @retval Others                Failed to ACK the hub status.

**/
EFI_STATUS
UsbHubAckHubStatus (
  IN  USB_DEVICE         *UsbDev
  );

extern USB_HUB_API        mUsbHubApi;
extern USB_HUB_API        mUsbRootHubApi;
#endif