summaryrefslogtreecommitdiff
path: root/MdePkg/Include/Protocol/UsbIo.h
blob: 8f24f1a98c989f0e7e7749997be7cbe73f6ada41 (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
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
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
/** @file
  EFI Usb I/O Protocol as defined in UEFI specification.
  This protocol is used by code, typically drivers, running in the EFI 
  boot services environment to access USB devices like USB keyboards, 
  mice and mass storage devices. In particular, functions for managing devices 
  on USB buses are defined here.
  
  Copyright (c) 2006 - 2008, 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_IO_H__
#define __USB_IO_H__

#include <IndustryStandard/Usb.h>

//
// Global ID for the USB I/O Protocol
//
#define EFI_USB_IO_PROTOCOL_GUID \
  { \
    0x2B2F68D6, 0x0CD2, 0x44cf, {0x8E, 0x8B, 0xBB, 0xA2, 0x0B, 0x1B, 0x5B, 0x75 } \
  }

typedef struct _EFI_USB_IO_PROTOCOL   EFI_USB_IO_PROTOCOL;

//
// Related Definition for EFI USB I/O protocol
//

//
// USB standard descriptors and reqeust
//
typedef USB_DEVICE_REQUEST        EFI_USB_DEVICE_REQUEST;
typedef USB_DEVICE_DESCRIPTOR     EFI_USB_DEVICE_DESCRIPTOR;
typedef USB_CONFIG_DESCRIPTOR     EFI_USB_CONFIG_DESCRIPTOR;
typedef USB_INTERFACE_DESCRIPTOR  EFI_USB_INTERFACE_DESCRIPTOR;
typedef USB_ENDPOINT_DESCRIPTOR   EFI_USB_ENDPOINT_DESCRIPTOR;

//
// USB data transfer direction
//
typedef enum {
  EfiUsbDataIn,
  EfiUsbDataOut,
  EfiUsbNoData
} EFI_USB_DATA_DIRECTION;

//
// USB Transfer Results
//
#define EFI_USB_NOERROR             0x00
#define EFI_USB_ERR_NOTEXECUTE      0x01
#define EFI_USB_ERR_STALL           0x02
#define EFI_USB_ERR_BUFFER          0x04
#define EFI_USB_ERR_BABBLE          0x08
#define EFI_USB_ERR_NAK             0x10
#define EFI_USB_ERR_CRC             0x20
#define EFI_USB_ERR_TIMEOUT         0x40
#define EFI_USB_ERR_BITSTUFF        0x80
#define EFI_USB_ERR_SYSTEM          0x100

/**
  Async USB transfer callback routine.

  @param  Data                  Data received or sent via the USB Asynchronous Transfer, if the
                                transfer completed successfully.
  @param  DataLength            The length of Data received or sent via the Asynchronous
                                Transfer, if transfer successfully completes.
  @param  Context               Data passed from UsbAsyncInterruptTransfer() request.
  @param  Status                Indicates the result of the asynchronous transfer.

  @retval EFI_SUCCESS           The asynchronous USB transfer request has been successfully executed.
  @retval EFI_DEVICE_ERROR      The asynchronous USB transfer request failed.

**/
typedef
EFI_STATUS
(EFIAPI *EFI_ASYNC_USB_TRANSFER_CALLBACK)(
  IN VOID         *Data,
  IN UINTN        DataLength,
  IN VOID         *Context,
  IN UINT32       Status
  );

//
// Prototype for EFI USB I/O protocol
//


/**
  This function is used to manage a USB device with a control transfer pipe. A control transfer is
  typically used to perform device initialization and configuration.

  @param  This                  A pointer to the EFI_USB_IO_PROTOCOL instance.
  @param  Request               A pointer to the USB device request that will be sent to the USB
                                device.
  @param  Direction             Indicates the data direction.
  @param  Timeout               Indicating the transfer should be completed within this time frame.
                                The units are in milliseconds.
  @param  Data                  A pointer to the buffer of data that will be transmitted to USB
                                device or received from USB device.
  @param  DataLength            The size, in bytes, of the data buffer specified by Data.
  @param  Status                A pointer to the result of the USB transfer.

  @retval EFI_SUCCESS           The control transfer has been successfully executed.
  @retval EFI_DEVICE_ERROR      The transfer failed. The transfer status is returned in Status.
  @retval EFI_INVALID_PARAMETE  One or more parameters are invalid.
  @retval EFI_OUT_OF_RESOURCES  The request could not be completed due to a lack of resources.
  @retval EFI_TIMEOUT           The control transfer fails due to timeout.

**/
typedef
EFI_STATUS
(EFIAPI *EFI_USB_IO_CONTROL_TRANSFER)(
  IN EFI_USB_IO_PROTOCOL                        *This,
  IN EFI_USB_DEVICE_REQUEST                     *Request,
  IN EFI_USB_DATA_DIRECTION                     Direction,
  IN UINT32                                     Timeout,
  IN OUT VOID                                   *Data OPTIONAL,
  IN UINTN                                      DataLength  OPTIONAL,
  OUT UINT32                                    *Status
  );

/**
  This function is used to manage a USB device with the bulk transfer pipe. Bulk Transfers are
  typically used to transfer large amounts of data to/from USB devices.

  @param  This                  A pointer to the EFI_USB_IO_PROTOCOL instance.
  @param  DeviceEndpoint        A pointer to the USB device request that will be sent to the USB
                                device.
  @param  Data                  A pointer to the buffer of data that will be transmitted to USB
                                device or received from USB device.
  @param  DataLength            The size, in bytes, of the data buffer specified by Data.
  @param  Timeout               Indicating the transfer should be completed within this time frame.
                                The units are in milliseconds.
  @param  Status                This parameter indicates the USB transfer status.

  @retval EFI_SUCCESS           The bulk transfer has been successfully executed.
  @retval EFI_DEVICE_ERROR      The transfer failed. The transfer status is returned in Status.
  @retval EFI_INVALID_PARAMETE  One or more parameters are invalid.
  @retval EFI_OUT_OF_RESOURCES  The request could not be submitted due to a lack of resources.
  @retval EFI_TIMEOUT           The control transfer fails due to timeout.

**/
typedef
EFI_STATUS
(EFIAPI *EFI_USB_IO_BULK_TRANSFER)(
  IN EFI_USB_IO_PROTOCOL            *This,
  IN UINT8                          DeviceEndpoint,
  IN OUT VOID                       *Data,
  IN OUT UINTN                      *DataLength,
  IN UINTN                          Timeout,
  OUT UINT32                        *Status
  );

/**
  This function is used to manage a USB device with an interrupt transfer pipe. An Asynchronous
  Interrupt Transfer is typically used to query a device's status at a fixed rate. For example,
  keyboard, mouse, and hub devices use this type of transfer to query their interrupt endpoints at
  a fixed rate.

  @param  This                  A pointer to the EFI_USB_IO_PROTOCOL instance.
  @param  DeviceEndpoint        A pointer to the USB device request that will be sent to the USB
                                device.
  @param  IsNewTransfer         If TRUE, a new transfer will be submitted to USB controller. If
                                FALSE, the interrupt transfer is deleted from the device's interrupt
                                transfer queue.
  @param  PollingInterval       Indicates the periodic rate, in milliseconds, that the transfer is to be
                                executed.
  @param  DataLength            Specifies the length, in bytes, of the data to be received from the
                                USB device.
  @param  InterruptCallback     The Callback function. This function is called if the asynchronous
                                interrupt transfer is completed.
  @param  Context               Data passed to the InterruptCallback function.

  @retval EFI_SUCCESS           The asynchronous USB transfer request transfer has been successfully executed.
  @retval EFI_DEVICE_ERROR      The asynchronous USB transfer request failed.

**/
typedef
EFI_STATUS
(EFIAPI *EFI_USB_IO_ASYNC_INTERRUPT_TRANSFER)(
  IN EFI_USB_IO_PROTOCOL                                 *This,
  IN UINT8                                               DeviceEndpoint,
  IN BOOLEAN                                             IsNewTransfer,
  IN UINTN                                               PollingInterval    OPTIONAL,
  IN UINTN                                               DataLength         OPTIONAL,
  IN EFI_ASYNC_USB_TRANSFER_CALLBACK                     InterruptCallBack  OPTIONAL,
  IN VOID                                                *Context OPTIONAL
  );

/**
  This function is used to manage a USB device with an interrupt transfer pipe.

  @param  This                  A pointer to the EFI_USB_IO_PROTOCOL instance.
  @param  DeviceEndpoint        A pointer to the USB device request that will be sent to the USB
                                device.
  @param  Data                  A pointer to the buffer of data that will be transmitted to USB
                                device or received from USB device.
  @param  DataLength            On input, then size, in bytes, of the buffer Data. On output, the
                                amount of data actually transferred.
  @param  Timeout               The time out, in seconds, for this transfer.
  @param  Status                This parameter indicates the USB transfer status.

  @retval EFI_SUCCESS           The sync interrupt transfer has been successfully executed.
  @retval EFI_INVALID_PARAMETER One or more parameters are invalid.
  @retval EFI_DEVICE_ERROR      The sync interrupt transfer request failed.
  @retval EFI_OUT_OF_RESOURCES  The request could not be submitted due to a lack of resources.
  @retval EFI_TIMEOUT           The transfer fails due to timeout.
**/
typedef
EFI_STATUS
(EFIAPI *EFI_USB_IO_SYNC_INTERRUPT_TRANSFER)(
  IN EFI_USB_IO_PROTOCOL            *This,
  IN     UINT8                      DeviceEndpoint,
  IN OUT VOID                       *Data,
  IN OUT UINTN                      *DataLength,
  IN     UINTN                      Timeout,
  OUT    UINT32                     *Status
  );

/**
  This function is used to manage a USB device with an isochronous transfer pipe. An Isochronous
  transfer is typically used to transfer streaming data.

  @param  This                  A pointer to the EFI_USB_IO_PROTOCOL instance.
  @param  DeviceEndpoint        A pointer to the USB device request that will be sent to the USB
                                device.
  @param  Data                  A pointer to the buffer of data that will be transmitted to USB
                                device or received from USB device.
  @param  DataLength            The size, in bytes, of the data buffer specified by Data.
  @param  Status                This parameter indicates the USB transfer status.

  @retval EFI_SUCCESS           The isochronous transfer has been successfully executed.
  @retval EFI_INVALID_PARAMETER The parameter DeviceEndpoint is not valid.
  @retval EFI_DEVICE_ERROR      The transfer failed due to the reason other than timeout, The error status
                                is returned in Status.
  @retval EFI_OUT_OF_RESOURCES  The request could not be submitted due to a lack of resources.
  @retval EFI_TIMEOUT           The transfer fails due to timeout.
**/
typedef
EFI_STATUS
(EFIAPI *EFI_USB_IO_ISOCHRONOUS_TRANSFER)(
  IN EFI_USB_IO_PROTOCOL            *This,
  IN     UINT8                      DeviceEndpoint,
  IN OUT VOID                       *Data,
  IN     UINTN                      DataLength,
  OUT    UINT32                     *Status
  );

/**
  This function is used to manage a USB device with an isochronous transfer pipe. An Isochronous
  transfer is typically used to transfer streaming data.

  @param  This                  A pointer to the EFI_USB_IO_PROTOCOL instance.
  @param  DeviceEndpoint        A pointer to the USB device request that will be sent to the USB
                                device.
  @param  Data                  A pointer to the buffer of data that will be transmitted to USB
                                device or received from USB device.
  @param  DataLength            The size, in bytes, of the data buffer specified by Data.
  @param  IsochronousCallback   The IsochronousCallback() function.
  @param  Context               Data passed to the IsochronousCallback() function.

  @retval EFI_SUCCESS           The asynchronous isochronous transfer has been successfully submitted
                                to the system.
  @retval EFI_INVALID_PARAMETER The parameter DeviceEndpoint is not valid.
  @retval EFI_OUT_OF_RESOURCES  The request could not be submitted due to a lack of resources.

**/
typedef
EFI_STATUS
(EFIAPI *EFI_USB_IO_ASYNC_ISOCHRONOUS_TRANSFER)(
  IN EFI_USB_IO_PROTOCOL              *This,
  IN UINT8                            DeviceEndpoint,
  IN OUT VOID                         *Data,
  IN     UINTN                        DataLength,
  IN EFI_ASYNC_USB_TRANSFER_CALLBACK  IsochronousCallBack,
  IN VOID                             *Context OPTIONAL
  );

/**
  Resets and reconfigures the USB controller. This function will work for all USB devices except
  USB Hub Controllers.

  @param  This                  A pointer to the EFI_USB_IO_PROTOCOL instance.

  @retval EFI_SUCCESS           The USB controller was reset.
  @retval EFI_INVALID_PARAMETER If the controller specified by This is a USB hub.
  @retval EFI_DEVICE_ERROR      An error occurred during the reconfiguration process.

**/
typedef
EFI_STATUS
(EFIAPI *EFI_USB_IO_PORT_RESET)(
  IN EFI_USB_IO_PROTOCOL    *This
  );

/**
  Retrieves the USB Device Descriptor.

  @param  This                  A pointer to the EFI_USB_IO_PROTOCOL instance.
  @param  DeviceDescriptor      A pointer to the caller allocated USB Device Descriptor.

  @retval EFI_SUCCESS           The device descriptor was retrieved successfully.
  @retval EFI_INVALID_PARAMETER DeviceDescriptor is NULL.
  @retval EFI_NOT_FOUND         The device descriptor was not found. The device may not be configured.

**/
typedef
EFI_STATUS
(EFIAPI *EFI_USB_IO_GET_DEVICE_DESCRIPTOR)(
  IN EFI_USB_IO_PROTOCOL            *This,
  OUT EFI_USB_DEVICE_DESCRIPTOR     *DeviceDescriptor
  );

/**
  Retrieves the USB Device Descriptor.

  @param  This                    A pointer to the EFI_USB_IO_PROTOCOL instance.
  @param  ConfigurationDescriptor A pointer to the caller allocated USB Active Configuration
                                  Descriptor.
  @retval EFI_SUCCESS             The active configuration descriptor was retrieved successfully.
  @retval EFI_INVALID_PARAMETER   ConfigurationDescriptor is NULL.
  @retval EFI_NOT_FOUND           An active configuration descriptor cannot be found. The device may not
                                  be configured.

**/
typedef
EFI_STATUS
(EFIAPI *EFI_USB_IO_GET_CONFIG_DESCRIPTOR)(
  IN EFI_USB_IO_PROTOCOL            *This,
  OUT EFI_USB_CONFIG_DESCRIPTOR     *ConfigurationDescriptor
  );

/**
  Retrieves the Interface Descriptor for a USB Device Controller. As stated earlier, an interface
  within a USB device is equivalently to a USB Controller within the current configuration.

  @param  This                    A pointer to the EFI_USB_IO_PROTOCOL instance.
  @param  InterfaceDescriptor     A pointer to the caller allocated USB Interface Descriptor within
                                  the configuration setting.
  @retval EFI_SUCCESS             The interface descriptor retrieved successfully.
  @retval EFI_INVALID_PARAMETER   InterfaceDescriptor is NULL.
  @retval EFI_NOT_FOUND           The interface descriptor cannot be found. The device may not be
                                  correctly configured.

**/
typedef
EFI_STATUS
(EFIAPI *EFI_USB_IO_GET_INTERFACE_DESCRIPTOR)(
  IN EFI_USB_IO_PROTOCOL            *This,
  OUT EFI_USB_INTERFACE_DESCRIPTOR  *InterfaceDescriptor
  );

/**
  Retrieves an Endpoint Descriptor within a USB Controller.

  @param  This                    A pointer to the EFI_USB_IO_PROTOCOL instance.
  @param  EndpointIndex           Indicates which endpoint descriptor to retrieve.
  @param  EndpointDescriptor      A pointer to the caller allocated USB Endpoint Descriptor of
                                  a USB controller.

  @retval EFI_SUCCESS             The endpoint descriptor was retrieved successfully.
  @retval EFI_INVALID_PARAMETER   One or more parameters are invalid.
  @retval EFI_NOT_FOUND           The endpoint descriptor cannot be found. The device may not be
                                  correctly configured.

**/
typedef
EFI_STATUS
(EFIAPI *EFI_USB_IO_GET_ENDPOINT_DESCRIPTOR)(
  IN EFI_USB_IO_PROTOCOL            *This,
  IN  UINT8                         EndpointIndex,
  OUT EFI_USB_ENDPOINT_DESCRIPTOR   *EndpointDescriptor
  );

/**
  Retrieves a Unicode string stored in a USB Device.

  @param  This                    A pointer to the EFI_USB_IO_PROTOCOL instance.
  @param  LangID                  The Language ID for the string being retrieved.
  @param  StringID                The ID of the string being retrieved.
  @param  String                  A pointer to a buffer allocated by this function with
                                  AllocatePool() to store the string.

  @retval EFI_SUCCESS             The string was retrieved successfully.
  @retval EFI_NOT_FOUND           The string specified by LangID and StringID was not found.
  @retval EFI_OUT_OF_RESOURCES    There are not enough resources to allocate the return buffer String.

**/
typedef
EFI_STATUS
(EFIAPI *EFI_USB_IO_GET_STRING_DESCRIPTOR)(
  IN EFI_USB_IO_PROTOCOL            *This,
  IN  UINT16                        LangID,
  IN  UINT8                         StringID,
  OUT CHAR16                        **String
  );

/**
  Retrieves all the language ID codes that the USB device supports.

  @param  This                    A pointer to the EFI_USB_IO_PROTOCOL instance.
  @param  LangIDTable             Language ID for the string the caller wants to get.
  @param  TableSize               The size, in bytes, of the table LangIDTable.

  @retval EFI_SUCCESS             The support languages were retrieved successfully.

**/
typedef
EFI_STATUS
(EFIAPI *EFI_USB_IO_GET_SUPPORTED_LANGUAGE)(
  IN EFI_USB_IO_PROTOCOL            *This,
  OUT UINT16                        **LangIDTable,
  OUT UINT16                        *TableSize
  );

/**  
  @par Protocol Description:
  The EFI_USB_IO_PROTOCOL provides four basic transfers types described 
  in the USB 1.1 Specification. These include control transfer, interrupt 
  transfer, bulk transfer and isochronous transfer. The EFI_USB_IO_PROTOCOL 
  also provides some basic USB device/controller management and configuration 
  interfaces. A USB device driver uses the services of this protocol to manage USB devices.  

  @param UsbControlTransfer 
  Accesses the USB Device through USB Control Transfer Pipe. 

  @param UsbBulkTransfer
  Accesses the USB Device through USB Bulk Transfer Pipe. 

  @param UsbAsyncInterruptTransfer
  Non-block USB interrupt transfer. 

  @param UsbSyncInterruptTransfer
  Accesses the USB Device through USB Synchronous
  Interrupt Transfer Pipe. 

  @param UsbIsochronousTransfer
  Accesses the USB Device through USB Isochronous Transfer Pipe. 

  @param UsbAsyncIsochronousTransfer
  Nonblock USB isochronous transfer. 

  @param UsbGetDeviceDescriptor
  Retrieves the device descriptor of a USB device. 

  @param UsbGetConfigDescriptor
  Retrieves the activated configuration descriptor of a USB device. 

  @param UsbGetInterfaceDescriptor
  Retrieves the interface descriptor of a USB Controller. 

  @param UsbGetEndpointDescriptor
  Retrieves the endpoint descriptor of a USB Controller. 

  @param UsbGetStringDescriptor
  Retrieves the string descriptor inside a USB Device. 

  @param UsbGetSupportedLanguages
  Retrieves the array of languages that the USB device supports. 

  @param UsbPortReset
  Resets and reconfigures the USB controller. 
**/
struct _EFI_USB_IO_PROTOCOL {
  //
  // IO transfer
  //
  EFI_USB_IO_CONTROL_TRANSFER           UsbControlTransfer;
  EFI_USB_IO_BULK_TRANSFER              UsbBulkTransfer;
  EFI_USB_IO_ASYNC_INTERRUPT_TRANSFER   UsbAsyncInterruptTransfer;
  EFI_USB_IO_SYNC_INTERRUPT_TRANSFER    UsbSyncInterruptTransfer;
  EFI_USB_IO_ISOCHRONOUS_TRANSFER       UsbIsochronousTransfer;
  EFI_USB_IO_ASYNC_ISOCHRONOUS_TRANSFER UsbAsyncIsochronousTransfer;

  //
  // Common device request
  //
  EFI_USB_IO_GET_DEVICE_DESCRIPTOR      UsbGetDeviceDescriptor;
  EFI_USB_IO_GET_CONFIG_DESCRIPTOR      UsbGetConfigDescriptor;
  EFI_USB_IO_GET_INTERFACE_DESCRIPTOR   UsbGetInterfaceDescriptor;
  EFI_USB_IO_GET_ENDPOINT_DESCRIPTOR    UsbGetEndpointDescriptor;
  EFI_USB_IO_GET_STRING_DESCRIPTOR      UsbGetStringDescriptor;
  EFI_USB_IO_GET_SUPPORTED_LANGUAGE     UsbGetSupportedLanguages;

  //
  // Reset controller's parent port
  //
  EFI_USB_IO_PORT_RESET                 UsbPortReset;
};

extern EFI_GUID gEfiUsbIoProtocolGuid;

#endif