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
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
|
/*++
Copyright (c) 2006, 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.
Module Name:
usbbus.h
Abstract:
Header file for USB bus driver Interface
Revision History
--*/
#ifndef _EFI_USB_BUS_H
#define _EFI_USB_BUS_H
#include <IndustryStandard/usb.h>
#include "Hub.h"
#include "Usbutil.h"
//#ifdef EFI_DEBUG
extern UINTN gUSBDebugLevel;
extern UINTN gUSBErrorLevel;
//#endif
#define MICROSECOND 10000
#define ONESECOND (1000 * MICROSECOND)
#define BUSPOLLING_PERIOD ONESECOND
//
// We define some maximun value here
//
#define USB_MAXCONFIG 8
#define USB_MAXALTSETTING 4
#define USB_MAXINTERFACES 32
#define USB_MAXENDPOINTS 16
#define USB_MAXSTRINGS 16
#define USB_MAXLANID 16
#define USB_MAXCHILDREN 8
#define USB_MAXCONTROLLERS 4
#define USB_IO_CONTROLLER_SIGNATURE EFI_SIGNATURE_32 ('u', 's', 'b', 'd')
typedef struct {
LIST_ENTRY Link;
UINT16 StringIndex;
CHAR16 *String;
} STR_LIST_ENTRY;
typedef struct {
LIST_ENTRY Link;
UINT16 Toggle;
EFI_USB_ENDPOINT_DESCRIPTOR EndpointDescriptor;
} ENDPOINT_DESC_LIST_ENTRY;
typedef struct {
LIST_ENTRY Link;
EFI_USB_INTERFACE_DESCRIPTOR InterfaceDescriptor;
LIST_ENTRY EndpointDescListHead;
} INTERFACE_DESC_LIST_ENTRY;
typedef struct {
LIST_ENTRY Link;
EFI_USB_CONFIG_DESCRIPTOR CongfigDescriptor;
LIST_ENTRY InterfaceDescListHead;
UINTN ActiveInterface;
} CONFIG_DESC_LIST_ENTRY;
//
// Forward declaring
//
struct usb_io_device;
//
// This is used to form the USB Controller Handle
//
typedef struct usb_io_controller_device {
UINTN Signature;
EFI_HANDLE Handle;
EFI_USB_IO_PROTOCOL UsbIo;
EFI_DEVICE_PATH_PROTOCOL *DevicePath;
EFI_HANDLE HostController;
UINT8 CurrentConfigValue;
UINT8 InterfaceNumber;
struct usb_io_device *UsbDevice;
BOOLEAN IsUsbHub;
BOOLEAN IsManagedByDriver;
//
// Fields specified for USB Hub
//
EFI_EVENT HubNotify;
UINT8 HubEndpointAddress;
UINT8 StatusChangePort;
UINT8 DownstreamPorts;
UINT8 ParentPort;
struct usb_io_controller_device *Parent;
struct usb_io_device *Children[USB_MAXCHILDREN];
} USB_IO_CONTROLLER_DEVICE;
#define USB_IO_CONTROLLER_DEVICE_FROM_USB_IO_THIS(a) \
CR(a, USB_IO_CONTROLLER_DEVICE, UsbIo, USB_IO_CONTROLLER_SIGNATURE)
//
// This is used to keep the topology of USB bus
//
struct _usb_bus_controller_device;
typedef struct usb_io_device {
UINT8 DeviceAddress;
BOOLEAN IsConfigured;
BOOLEAN IsSlowDevice;
EFI_USB_DEVICE_DESCRIPTOR DeviceDescriptor;
LIST_ENTRY ConfigDescListHead;
CONFIG_DESC_LIST_ENTRY *ActiveConfig;
UINT16 LangID[USB_MAXLANID];
struct _usb_bus_controller_device *BusController;
//
// Track the controller handle
//
UINT8 NumOfControllers;
USB_IO_CONTROLLER_DEVICE *UsbController[USB_MAXCONTROLLERS];
} USB_IO_DEVICE;
//
// Usb Bus Controller device strcuture
//
#define EFI_USB_BUS_PROTOCOL_GUID \
{ 0x2B2F68CC, 0x0CD2, 0x44cf, { 0x8E, 0x8B, 0xBB, 0xA2, 0x0B, 0x1B, 0x5B, 0x75 } }
typedef struct _EFI_USB_BUS_PROTOCOL {
UINT64 Reserved;
} EFI_USB_BUS_PROTOCOL;
#define USB_BUS_DEVICE_SIGNATURE EFI_SIGNATURE_32 ('u', 'b', 'u', 's')
typedef struct _usb_bus_controller_device {
UINTN Signature;
EFI_USB_BUS_PROTOCOL BusIdentify;
EFI_USB_HC_PROTOCOL *UsbHCInterface;
EFI_DEVICE_PATH_PROTOCOL *DevicePath;
UINT8 AddressPool[16];
USB_IO_DEVICE *Root;
} USB_BUS_CONTROLLER_DEVICE;
#define USB_BUS_CONTROLLER_DEVICE_FROM_THIS(a) \
CR(a, USB_BUS_CONTROLLER_DEVICE, BusIdentify, USB_BUS_DEVICE_SIGNATURE)
//
// Global Variables
//
extern EFI_DRIVER_BINDING_PROTOCOL gUsbBusDriverBinding;
extern EFI_COMPONENT_NAME_PROTOCOL gUsbBusComponentName;
extern EFI_GUID gUSBBusDriverGuid;
//
// Usb Device Configuration functions
//
BOOLEAN
IsHub (
IN USB_IO_CONTROLLER_DEVICE *Dev
);
EFI_STATUS
UsbGetStringtable (
IN USB_IO_DEVICE *UsbIoDevice
);
EFI_STATUS
UsbGetAllConfigurations (
IN USB_IO_DEVICE *UsbIoDevice
);
EFI_STATUS
UsbSetConfiguration (
IN USB_IO_DEVICE *Dev,
IN UINTN ConfigurationValue
);
EFI_STATUS
UsbSetDefaultConfiguration (
IN USB_IO_DEVICE *Dev
);
//
// Device Deconfiguration functions
//
VOID
UsbDestroyAllConfiguration (
IN USB_IO_DEVICE *UsbIoDevice
);
EFI_STATUS
DoHubConfig (
IN USB_IO_CONTROLLER_DEVICE *HubIoDevice
);
VOID
GetDeviceEndPointMaxPacketLength (
IN EFI_USB_IO_PROTOCOL *UsbIo,
IN UINT8 EndpointAddr,
OUT UINT8 *MaxPacketLength
);
VOID
GetDataToggleBit (
IN EFI_USB_IO_PROTOCOL *UsbIo,
IN UINT8 EndpointAddr,
OUT UINT8 *DataToggle
);
VOID
SetDataToggleBit (
IN EFI_USB_IO_PROTOCOL *UsbIo,
IN UINT8 EndpointAddr,
IN UINT8 DataToggle
);
INTERFACE_DESC_LIST_ENTRY *
FindInterfaceListEntry (
IN EFI_USB_IO_PROTOCOL *This
);
ENDPOINT_DESC_LIST_ENTRY *
FindEndPointListEntry (
IN EFI_USB_IO_PROTOCOL *This,
IN UINT8 EndPointAddress
);
EFI_STATUS
IsDeviceDisconnected (
IN USB_IO_CONTROLLER_DEVICE *UsbIoController,
IN OUT BOOLEAN *Disconnected
);
EFI_STATUS
UsbDeviceDeConfiguration (
IN USB_IO_DEVICE *UsbIoDevice
);
#endif
|