iPXE
Functions | Variables
efi_usb.c File Reference

EFI USB I/O PROTOCOL. More...

#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include <errno.h>
#include <assert.h>
#include <ipxe/efi/efi.h>
#include <ipxe/efi/efi_path.h>
#include <ipxe/efi/efi_driver.h>
#include <ipxe/efi/efi_null.h>
#include <ipxe/efi/efi_usb.h>
#include <ipxe/usb.h>

Go to the source code of this file.

Functions

 FILE_LICENCE (GPL2_OR_LATER_OR_UBDL)
 
static const char * efi_usb_direction_name (EFI_USB_DATA_DIRECTION direction)
 Transcribe data direction (for debugging) More...
 
static VOID EFIAPI efi_usb_timer (EFI_EVENT event __unused, VOID *context)
 Poll USB bus (from endpoint event timer) More...
 
static int efi_usb_mtu (struct efi_usb_interface *usbintf, unsigned int endpoint)
 Get endpoint MTU. More...
 
static int efi_usb_is_open (struct efi_usb_interface *usbintf, unsigned int endpoint)
 Check if endpoint is open. More...
 
static int efi_usb_open (struct efi_usb_interface *usbintf, unsigned int endpoint, unsigned int attributes, unsigned int interval, struct usb_endpoint_driver_operations *driver)
 Open endpoint. More...
 
static void efi_usb_close (struct efi_usb_endpoint *usbep)
 Close endpoint. More...
 
static void efi_usb_close_all (struct efi_usb_interface *usbintf)
 Close all endpoints. More...
 
static void efi_usb_free_all (struct efi_usb_interface *usbintf)
 Free all endpoints. More...
 
static void efi_usb_sync_complete (struct usb_endpoint *ep, struct io_buffer *iobuf __unused, int rc)
 Complete synchronous transfer. More...
 
static int efi_usb_sync_transfer (struct efi_usb_interface *usbintf, unsigned int endpoint, unsigned int attributes, unsigned int timeout, void *data, size_t *len)
 Perform synchronous transfer. More...
 
static void efi_usb_async_complete (struct usb_endpoint *ep, struct io_buffer *iobuf, int rc)
 Complete asynchronous transfer. More...
 
static int efi_usb_async_start (struct efi_usb_interface *usbintf, unsigned int endpoint, unsigned int interval, size_t len, EFI_ASYNC_USB_TRANSFER_CALLBACK callback, void *context)
 Start asynchronous transfer. More...
 
static void efi_usb_async_stop (struct efi_usb_interface *usbintf, unsigned int endpoint)
 Stop asynchronous transfer. More...
 
static EFI_STATUS EFIAPI efi_usb_control_transfer (EFI_USB_IO_PROTOCOL *usbio, EFI_USB_DEVICE_REQUEST *packet, EFI_USB_DATA_DIRECTION direction, UINT32 timeout, VOID *data, UINTN len, UINT32 *status)
 Perform control transfer. More...
 
static EFI_STATUS EFIAPI efi_usb_bulk_transfer (EFI_USB_IO_PROTOCOL *usbio, UINT8 endpoint, VOID *data, UINTN *len, UINTN timeout, UINT32 *status)
 Perform bulk transfer. More...
 
static EFI_STATUS EFIAPI efi_usb_sync_interrupt_transfer (EFI_USB_IO_PROTOCOL *usbio, UINT8 endpoint, VOID *data, UINTN *len, UINTN timeout, UINT32 *status)
 Perform synchronous interrupt transfer. More...
 
static EFI_STATUS EFIAPI efi_usb_async_interrupt_transfer (EFI_USB_IO_PROTOCOL *usbio, UINT8 endpoint, BOOLEAN start, UINTN interval, UINTN len, EFI_ASYNC_USB_TRANSFER_CALLBACK callback, VOID *context)
 Perform asynchronous interrupt transfer. More...
 
static EFI_STATUS EFIAPI efi_usb_isochronous_transfer (EFI_USB_IO_PROTOCOL *usbio, UINT8 endpoint, VOID *data, UINTN len, UINT32 *status)
 Perform synchronous isochronous transfer. More...
 
static EFI_STATUS EFIAPI efi_usb_async_isochronous_transfer (EFI_USB_IO_PROTOCOL *usbio, UINT8 endpoint, VOID *data, UINTN len, EFI_ASYNC_USB_TRANSFER_CALLBACK callback, VOID *context)
 Perform asynchronous isochronous transfers. More...
 
static EFI_STATUS EFIAPI efi_usb_get_device_descriptor (EFI_USB_IO_PROTOCOL *usbio, EFI_USB_DEVICE_DESCRIPTOR *efidesc)
 Get device descriptor. More...
 
static EFI_STATUS EFIAPI efi_usb_get_config_descriptor (EFI_USB_IO_PROTOCOL *usbio, EFI_USB_CONFIG_DESCRIPTOR *efidesc)
 Get configuration descriptor. More...
 
static EFI_STATUS EFIAPI efi_usb_get_interface_descriptor (EFI_USB_IO_PROTOCOL *usbio, EFI_USB_INTERFACE_DESCRIPTOR *efidesc)
 Get interface descriptor. More...
 
static EFI_STATUS EFIAPI efi_usb_get_endpoint_descriptor (EFI_USB_IO_PROTOCOL *usbio, UINT8 index, EFI_USB_ENDPOINT_DESCRIPTOR *efidesc)
 Get endpoint descriptor. More...
 
static EFI_STATUS EFIAPI efi_usb_get_string_descriptor (EFI_USB_IO_PROTOCOL *usbio, UINT16 language, UINT8 index, CHAR16 **string)
 Get string descriptor. More...
 
static EFI_STATUS EFIAPI efi_usb_get_supported_languages (EFI_USB_IO_PROTOCOL *usbio, UINT16 **languages, UINT16 *len)
 Get supported languages. More...
 
static EFI_STATUS EFIAPI efi_usb_port_reset (EFI_USB_IO_PROTOCOL *usbio)
 Reset port. More...
 
static int efi_usb_install (struct efi_usb_device *usbdev, unsigned int interface)
 Install interface. More...
 
static void efi_usb_uninstall (struct efi_usb_interface *usbintf)
 Uninstall interface. More...
 
static void efi_usb_uninstall_all (struct efi_usb_device *efiusb)
 Uninstall all interfaces. More...
 
static int efi_usb_probe (struct usb_function *func, struct usb_configuration_descriptor *config)
 Probe device. More...
 
static void efi_usb_remove (struct usb_function *func)
 Remove device. More...
 

Variables

static struct usb_endpoint_driver_operations efi_usb_sync_driver
 Synchronous endpoint operations. More...
 
static struct usb_endpoint_driver_operations efi_usb_async_driver
 Asynchronous endpoint operations. More...
 
static EFI_USB_IO_PROTOCOL efi_usb_io_protocol
 USB I/O protocol. More...
 
static struct usb_device_id efi_usb_ids []
 USB I/O protocol device IDs. More...
 
struct usb_driver usbio_driver __usb_fallback_driver
 USB I/O protocol driver. More...
 

Detailed Description

EFI USB I/O PROTOCOL.

Definition in file efi_usb.c.

Function Documentation

◆ FILE_LICENCE()

FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL  )

◆ efi_usb_direction_name()

static const char* efi_usb_direction_name ( EFI_USB_DATA_DIRECTION  direction)
static

Transcribe data direction (for debugging)

Parameters
directionData direction
Return values
textTranscribed data direction

Definition at line 51 of file efi_usb.c.

51  {
52 
53  switch ( direction ) {
54  case EfiUsbDataIn: return "in";
55  case EfiUsbDataOut: return "out";
56  case EfiUsbNoData: return "none";
57  default: return "<UNKNOWN>";
58  }
59 }
uint8_t direction
Direction.
Definition: ena.h:14

References direction, EfiUsbDataIn, EfiUsbDataOut, and EfiUsbNoData.

Referenced by efi_usb_control_transfer().

◆ efi_usb_timer()

static VOID EFIAPI efi_usb_timer ( EFI_EVENT event  __unused,
VOID context 
)
static

Poll USB bus (from endpoint event timer)

Parameters
eventEFI event
contextEFI USB endpoint

Definition at line 74 of file efi_usb.c.

75  {
76  struct efi_usb_endpoint *usbep = context;
77  struct usb_function *func = usbep->usbintf->usbdev->func;
78 
79  /* Poll bus */
80  usb_poll ( func->usb->port->hub->bus );
81 
82  /* Refill endpoint */
83  if ( usbep->ep.open )
84  usb_refill ( &usbep->ep );
85 }
struct usb_function * func
The underlying USB function.
Definition: efi_usb.h:21
int open
Endpoint is open.
Definition: usb.h:404
int usb_refill(struct usb_endpoint *ep)
Refill endpoint.
Definition: usb.c:710
struct usb_port * port
USB port.
Definition: usb.h:712
void * context
Asynchronous callback context.
Definition: efi_usb.h:71
struct efi_usb_interface * usbintf
EFI USB device interface.
Definition: efi_usb.h:59
static void usb_poll(struct usb_bus *bus)
Poll USB bus.
Definition: usb.h:1051
An EFI USB device endpoint.
Definition: efi_usb.h:57
struct usb_device * usb
USB device.
Definition: usb.h:663
struct usb_endpoint ep
USB endpoint.
Definition: efi_usb.h:61
struct usb_hub * hub
USB hub.
Definition: usb.h:800
A USB function.
Definition: usb.h:659
struct efi_usb_device * usbdev
Containing USB device.
Definition: efi_usb.h:37
struct usb_bus * bus
USB bus.
Definition: usb.h:830

References usb_hub::bus, efi_usb_endpoint::context, efi_usb_endpoint::ep, efi_usb_device::func, usb_port::hub, usb_endpoint::open, usb_device::port, usb_function::usb, usb_poll(), usb_refill(), efi_usb_interface::usbdev, and efi_usb_endpoint::usbintf.

Referenced by efi_usb_open().

◆ efi_usb_mtu()

static int efi_usb_mtu ( struct efi_usb_interface usbintf,
unsigned int  endpoint 
)
static

Get endpoint MTU.

Parameters
usbintfEFI USB interface
endpointEndpoint address
Return values
mtuEndpoint MTU, or negative error

Definition at line 94 of file efi_usb.c.

95  {
96  struct efi_usb_device *usbdev = usbintf->usbdev;
98  struct usb_endpoint_descriptor *desc;
99 
100  /* Locate cached interface descriptor */
101  interface = usb_interface_descriptor ( usbdev->config,
102  usbintf->interface,
103  usbintf->alternate );
104  if ( ! interface ) {
105  DBGC ( usbdev, "USBDEV %s alt %d has no interface descriptor\n",
106  usbintf->name, usbintf->alternate );
107  return -ENOENT;
108  }
109 
110  /* Locate and copy cached endpoint descriptor */
111  for_each_interface_descriptor ( desc, usbdev->config, interface ) {
112  if ( ( desc->header.type == USB_ENDPOINT_DESCRIPTOR ) &&
113  ( desc->endpoint == endpoint ) )
114  return USB_ENDPOINT_MTU ( le16_to_cpu ( desc->sizes ) );
115  }
116 
117  DBGC ( usbdev, "USBDEV %s alt %d ep %02x has no descriptor\n",
118  usbintf->name, usbintf->alternate, endpoint );
119  return -ENOENT;
120 }
unsigned int alternate
Alternate setting.
Definition: efi_usb.h:44
char name[32]
Name.
Definition: efi_usb.h:35
#define DBGC(...)
Definition: compiler.h:505
#define ENOENT
No such file or directory.
Definition: errno.h:514
#define for_each_interface_descriptor(desc, config, interface)
Iterate over all configuration descriptors within an interface descriptor.
Definition: usb.h:379
uint8_t endpoint
Endpoint address.
Definition: usb.h:253
An EFI USB device.
Definition: efi_usb.h:17
A USB interface descriptor.
Definition: usb.h:230
An object interface.
Definition: interface.h:124
struct ib_cm_path alternate
Alternate path.
Definition: ib_mad.h:42
uint8_t type
Descriptor type.
Definition: usb.h:162
struct usb_configuration_descriptor * config
Configuration descriptor.
Definition: efi_usb.h:23
Standard Endpoint Descriptor USB 2.0 spec, Section 9.6.6.
Definition: Usb.h:163
#define le16_to_cpu(value)
Definition: byteswap.h:112
A USB endpoint descriptor.
Definition: usb.h:249
struct usb_descriptor_header header
Descriptor header.
Definition: usb.h:251
#define USB_ENDPOINT_MTU(sizes)
USB endpoint MTU.
Definition: usb.h:293
uint16_t sizes
Maximum packet size and burst size.
Definition: usb.h:257
struct efi_usb_device * usbdev
Containing USB device.
Definition: efi_usb.h:37
uint8_t interface
Interface number.
Definition: usb.h:234

References alternate, usb_interface_descriptor::alternate, DBGC, usb_endpoint_descriptor::endpoint, ENOENT, for_each_interface_descriptor, usb_endpoint_descriptor::header, usb_interface_descriptor::interface, le16_to_cpu, usb_interface_descriptor::name, usb_endpoint_descriptor::sizes, usb_descriptor_header::type, USB_ENDPOINT_MTU, and efi_usb_interface::usbdev.

Referenced by efi_usb_open().

◆ efi_usb_is_open()

static int efi_usb_is_open ( struct efi_usb_interface usbintf,
unsigned int  endpoint 
)
static

Check if endpoint is open.

Parameters
usbintfEFI USB interface
endpointEndpoint address
Return values
is_openEndpoint is open

Definition at line 129 of file efi_usb.c.

130  {
131  unsigned int index = USB_ENDPOINT_IDX ( endpoint );
132  struct efi_usb_endpoint *usbep = usbintf->endpoint[index];
133 
134  return ( usbep && usbep->ep.open );
135 }
int open
Endpoint is open.
Definition: usb.h:404
struct efi_usb_endpoint * endpoint[32]
Opened endpoints.
Definition: efi_usb.h:53
struct efi_usb_interface * usbintf
EFI USB device interface.
Definition: efi_usb.h:59
An EFI USB device endpoint.
Definition: efi_usb.h:57
#define USB_ENDPOINT_IDX(address)
Construct endpoint index from endpoint address.
Definition: usb.h:513
struct usb_endpoint ep
USB endpoint.
Definition: efi_usb.h:61
uint64_t index
Index of the first segment within the content.
Definition: pccrc.h:21

References efi_usb_interface::endpoint, efi_usb_endpoint::ep, index, usb_endpoint::open, USB_ENDPOINT_IDX, and efi_usb_endpoint::usbintf.

Referenced by efi_usb_async_start(), efi_usb_async_stop(), and efi_usb_sync_transfer().

◆ efi_usb_open()

static int efi_usb_open ( struct efi_usb_interface usbintf,
unsigned int  endpoint,
unsigned int  attributes,
unsigned int  interval,
struct usb_endpoint_driver_operations driver 
)
static

Open endpoint.

Parameters
usbintfEFI USB interface
endpointEndpoint address
attributesEndpoint attributes
intervalInterval (in milliseconds)
driverDriver operations
Return values
rcReturn status code

Definition at line 147 of file efi_usb.c.

150  {
152  struct efi_usb_device *usbdev = usbintf->usbdev;
153  struct efi_usb_endpoint *usbep;
154  unsigned int index = USB_ENDPOINT_IDX ( endpoint );
155  int mtu;
156  EFI_STATUS efirc;
157  int rc;
158 
159  /* Allocate structure, if needed. Once allocated, we leave
160  * the endpoint structure in place until the device is
161  * removed, to work around external UEFI code that closes the
162  * endpoint at illegal times.
163  */
164  usbep = usbintf->endpoint[index];
165  if ( ! usbep ) {
166  usbep = zalloc ( sizeof ( *usbep ) );
167  if ( ! usbep ) {
168  rc = -ENOMEM;
169  goto err_alloc;
170  }
171  usbep->usbintf = usbintf;
172  usbintf->endpoint[index] = usbep;
173  }
174 
175  /* Get endpoint MTU */
176  mtu = efi_usb_mtu ( usbintf, endpoint );
177  if ( mtu < 0 ) {
178  rc = mtu;
179  goto err_mtu;
180  }
181 
182  /* Allocate and initialise structure */
183  usb_endpoint_init ( &usbep->ep, usbdev->func->usb, driver );
184  usb_endpoint_describe ( &usbep->ep, endpoint, attributes, mtu, 0,
185  ( interval << 3 /* microframes */ ) );
186 
187  /* Open endpoint */
188  if ( ( rc = usb_endpoint_open ( &usbep->ep ) ) != 0 ) {
189  DBGC ( usbdev, "USBDEV %s %s could not open: %s\n",
190  usbintf->name, usb_endpoint_name ( &usbep->ep ),
191  strerror ( rc ) );
192  goto err_open;
193  }
194  DBGC ( usbdev, "USBDEV %s %s opened\n",
195  usbintf->name, usb_endpoint_name ( &usbep->ep ) );
196 
197  /* Create event */
198  if ( ( efirc = bs->CreateEvent ( ( EVT_TIMER | EVT_NOTIFY_SIGNAL ),
199  TPL_CALLBACK, efi_usb_timer, usbep,
200  &usbep->event ) ) != 0 ) {
201  rc = -EEFI ( efirc );
202  DBGC ( usbdev, "USBDEV %s %s could not create event: %s\n",
203  usbintf->name, usb_endpoint_name ( &usbep->ep ),
204  strerror ( rc ) );
205  goto err_event;
206  }
207 
208  return 0;
209 
210  bs->CloseEvent ( usbep->event );
211  err_event:
212  usb_endpoint_close ( &usbep->ep );
213  err_open:
214  err_mtu:
215  err_alloc:
216  return rc;
217 }
EFI_BOOT_SERVICES * BootServices
A pointer to the EFI Boot Services Table.
Definition: UefiSpec.h:2000
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
#define EEFI(efirc)
Convert an EFI status code to an iPXE status code.
Definition: efi.h:162
static void usb_endpoint_describe(struct usb_endpoint *ep, unsigned int address, unsigned int attributes, size_t mtu, unsigned int burst, unsigned int interval)
Describe USB endpoint.
Definition: usb.h:543
char name[32]
Name.
Definition: efi_usb.h:35
struct usb_function * func
The underlying USB function.
Definition: efi_usb.h:21
static VOID EFIAPI efi_usb_timer(EFI_EVENT event __unused, VOID *context)
Poll USB bus (from endpoint event timer)
Definition: efi_usb.c:74
#define DBGC(...)
Definition: compiler.h:505
int usb_endpoint_open(struct usb_endpoint *ep)
Open USB endpoint.
Definition: usb.c:293
EFI_CLOSE_EVENT CloseEvent
Definition: UefiSpec.h:1864
An EFI USB device.
Definition: efi_usb.h:17
void usb_endpoint_close(struct usb_endpoint *ep)
Close USB endpoint.
Definition: usb.c:399
struct efi_usb_endpoint * endpoint[32]
Opened endpoints.
Definition: efi_usb.h:53
#define ENOMEM
Not enough space.
Definition: errno.h:534
EFI_EVENT event
Asynchronous timer event.
Definition: efi_usb.h:67
EFI_CREATE_EVENT CreateEvent
Definition: UefiSpec.h:1860
struct efi_usb_interface * usbintf
EFI USB device interface.
Definition: efi_usb.h:59
char * strerror(int errno)
Retrieve string representation of error number.
Definition: strerror.c:78
An EFI USB device endpoint.
Definition: efi_usb.h:57
void * zalloc(size_t size)
Allocate cleared memory.
Definition: malloc.c:624
EFI Boot Services Table.
Definition: UefiSpec.h:1836
#define TPL_CALLBACK
Definition: UefiSpec.h:591
#define EVT_NOTIFY_SIGNAL
Definition: UefiSpec.h:394
struct usb_device * usb
USB device.
Definition: usb.h:663
static void usb_endpoint_init(struct usb_endpoint *ep, struct usb_device *usb, struct usb_endpoint_driver_operations *driver)
Initialise USB endpoint.
Definition: usb.h:525
#define USB_ENDPOINT_IDX(address)
Construct endpoint index from endpoint address.
Definition: usb.h:513
const char * usb_endpoint_name(struct usb_endpoint *ep)
Get USB endpoint name (for debugging)
Definition: usb.c:220
struct usb_endpoint ep
USB endpoint.
Definition: efi_usb.h:61
static int efi_usb_mtu(struct efi_usb_interface *usbintf, unsigned int endpoint)
Get endpoint MTU.
Definition: efi_usb.c:94
uint32_t mtu
Maximum MTU.
Definition: ena.h:28
RETURN_STATUS EFI_STATUS
Function return status for EFI API.
Definition: UefiBaseType.h:35
EFI_SYSTEM_TABLE * efi_systab
uint64_t index
Index of the first segment within the content.
Definition: pccrc.h:21
struct efi_usb_device * usbdev
Containing USB device.
Definition: efi_usb.h:37
#define EVT_TIMER
Definition: UefiSpec.h:391

References EFI_SYSTEM_TABLE::BootServices, EFI_BOOT_SERVICES::CloseEvent, EFI_BOOT_SERVICES::CreateEvent, DBGC, EEFI, efi_systab, efi_usb_mtu(), efi_usb_timer(), efi_usb_interface::endpoint, ENOMEM, efi_usb_endpoint::ep, efi_usb_endpoint::event, EVT_NOTIFY_SIGNAL, EVT_TIMER, efi_usb_device::func, index, mtu, efi_usb_interface::name, rc, strerror(), TPL_CALLBACK, usb_function::usb, usb_endpoint_close(), usb_endpoint_describe(), USB_ENDPOINT_IDX, usb_endpoint_init(), usb_endpoint_name(), usb_endpoint_open(), efi_usb_interface::usbdev, efi_usb_endpoint::usbintf, and zalloc().

Referenced by efi_usb_async_start(), and efi_usb_sync_transfer().

◆ efi_usb_close()

static void efi_usb_close ( struct efi_usb_endpoint usbep)
static

Close endpoint.

Parameters
usbepEFI USB endpoint

Definition at line 224 of file efi_usb.c.

224  {
226  struct efi_usb_interface *usbintf = usbep->usbintf;
227  struct efi_usb_device *usbdev = usbintf->usbdev;
228  unsigned int index = USB_ENDPOINT_IDX ( usbep->ep.address );
229 
230  /* Sanity check */
231  assert ( usbintf->endpoint[index] == usbep );
232 
233  /* Cancel timer (if applicable) and close event */
234  bs->SetTimer ( usbep->event, TimerCancel, 0 );
235  bs->CloseEvent ( usbep->event );
236 
237  /* Close endpoint */
238  usb_endpoint_close ( &usbep->ep );
239  DBGC ( usbdev, "USBDEV %s %s closed\n",
240  usbintf->name, usb_endpoint_name ( &usbep->ep ) );
241 }
EFI_BOOT_SERVICES * BootServices
A pointer to the EFI Boot Services Table.
Definition: UefiSpec.h:2000
char name[32]
Name.
Definition: efi_usb.h:35
#define DBGC(...)
Definition: compiler.h:505
EFI_CLOSE_EVENT CloseEvent
Definition: UefiSpec.h:1864
EFI_SET_TIMER SetTimer
Definition: UefiSpec.h:1861
An EFI USB device.
Definition: efi_usb.h:17
void usb_endpoint_close(struct usb_endpoint *ep)
Close USB endpoint.
Definition: usb.c:399
struct efi_usb_endpoint * endpoint[32]
Opened endpoints.
Definition: efi_usb.h:53
An EFI USB device interface.
Definition: efi_usb.h:33
An event's timer settings is to be cancelled and not trigger time is to be set/.
Definition: UefiSpec.h:485
assert((readw(&hdr->flags) &(GTF_reading|GTF_writing))==0)
EFI_EVENT event
Asynchronous timer event.
Definition: efi_usb.h:67
struct efi_usb_interface * usbintf
EFI USB device interface.
Definition: efi_usb.h:59
EFI Boot Services Table.
Definition: UefiSpec.h:1836
#define USB_ENDPOINT_IDX(address)
Construct endpoint index from endpoint address.
Definition: usb.h:513
const char * usb_endpoint_name(struct usb_endpoint *ep)
Get USB endpoint name (for debugging)
Definition: usb.c:220
struct usb_endpoint ep
USB endpoint.
Definition: efi_usb.h:61
EFI_SYSTEM_TABLE * efi_systab
uint64_t index
Index of the first segment within the content.
Definition: pccrc.h:21
struct efi_usb_device * usbdev
Containing USB device.
Definition: efi_usb.h:37
unsigned int address
Endpoint address.
Definition: usb.h:393

References usb_endpoint::address, assert(), EFI_SYSTEM_TABLE::BootServices, EFI_BOOT_SERVICES::CloseEvent, DBGC, efi_systab, efi_usb_interface::endpoint, efi_usb_endpoint::ep, efi_usb_endpoint::event, index, efi_usb_interface::name, EFI_BOOT_SERVICES::SetTimer, TimerCancel, usb_endpoint_close(), USB_ENDPOINT_IDX, usb_endpoint_name(), efi_usb_interface::usbdev, and efi_usb_endpoint::usbintf.

Referenced by efi_usb_async_start(), efi_usb_close_all(), and efi_usb_sync_transfer().

◆ efi_usb_close_all()

static void efi_usb_close_all ( struct efi_usb_interface usbintf)
static

Close all endpoints.

Parameters
usbintfEFI USB interface

Definition at line 248 of file efi_usb.c.

248  {
249  struct efi_usb_endpoint *usbep;
250  unsigned int i;
251 
252  for ( i = 0 ; i < ( sizeof ( usbintf->endpoint ) /
253  sizeof ( usbintf->endpoint[0] ) ) ; i++ ) {
254  usbep = usbintf->endpoint[i];
255  if ( usbep && usbep->ep.open )
256  efi_usb_close ( usbep );
257  }
258 }
static void efi_usb_close(struct efi_usb_endpoint *usbep)
Close endpoint.
Definition: efi_usb.c:224
int open
Endpoint is open.
Definition: usb.h:404
struct efi_usb_endpoint * endpoint[32]
Opened endpoints.
Definition: efi_usb.h:53
struct efi_usb_interface * usbintf
EFI USB device interface.
Definition: efi_usb.h:59
An EFI USB device endpoint.
Definition: efi_usb.h:57
struct usb_endpoint ep
USB endpoint.
Definition: efi_usb.h:61

References efi_usb_close(), efi_usb_interface::endpoint, efi_usb_endpoint::ep, usb_endpoint::open, and efi_usb_endpoint::usbintf.

Referenced by efi_usb_control_transfer(), efi_usb_install(), and efi_usb_uninstall().

◆ efi_usb_free_all()

static void efi_usb_free_all ( struct efi_usb_interface usbintf)
static

Free all endpoints.

Parameters
usbintfEFI USB interface

Definition at line 265 of file efi_usb.c.

265  {
266  struct efi_usb_endpoint *usbep;
267  unsigned int i;
268 
269  for ( i = 0 ; i < ( sizeof ( usbintf->endpoint ) /
270  sizeof ( usbintf->endpoint[0] ) ) ; i++ ) {
271  usbep = usbintf->endpoint[i];
272  if ( usbep ) {
273  assert ( ! usbep->ep.open );
274  free ( usbep );
275  usbintf->endpoint[i] = NULL;
276  }
277  }
278 }
int open
Endpoint is open.
Definition: usb.h:404
struct efi_usb_endpoint * endpoint[32]
Opened endpoints.
Definition: efi_usb.h:53
assert((readw(&hdr->flags) &(GTF_reading|GTF_writing))==0)
struct efi_usb_interface * usbintf
EFI USB device interface.
Definition: efi_usb.h:59
static void(* free)(struct refcnt *refcnt))
Definition: refcnt.h:54
An EFI USB device endpoint.
Definition: efi_usb.h:57
struct usb_endpoint ep
USB endpoint.
Definition: efi_usb.h:61
#define NULL
NULL pointer (VOID *)
Definition: Base.h:362

References assert(), efi_usb_interface::endpoint, efi_usb_endpoint::ep, free, NULL, usb_endpoint::open, and efi_usb_endpoint::usbintf.

Referenced by efi_usb_install(), and efi_usb_uninstall().

◆ efi_usb_sync_complete()

static void efi_usb_sync_complete ( struct usb_endpoint ep,
struct io_buffer *iobuf  __unused,
int  rc 
)
static

Complete synchronous transfer.

Parameters
epUSB endpoint
iobufI/O buffer
rcCompletion status code

Definition at line 287 of file efi_usb.c.

288  {
289  struct efi_usb_endpoint *usbep =
290  container_of ( ep, struct efi_usb_endpoint, ep );
291 
292  /* Record completion status */
293  usbep->rc = rc;
294 }
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
#define container_of(ptr, type, field)
Get containing structure.
Definition: stddef.h:35
int rc
Most recent synchronous completion status.
Definition: efi_usb.h:64
An EFI USB device endpoint.
Definition: efi_usb.h:57
struct usb_endpoint ep
USB endpoint.
Definition: efi_usb.h:61

References container_of, efi_usb_endpoint::ep, efi_usb_endpoint::rc, and rc.

◆ efi_usb_sync_transfer()

static int efi_usb_sync_transfer ( struct efi_usb_interface usbintf,
unsigned int  endpoint,
unsigned int  attributes,
unsigned int  timeout,
void *  data,
size_t len 
)
static

Perform synchronous transfer.

Parameters
usbintfUSB endpoint
endpointEndpoint address
attributesEndpoint attributes
timeoutTimeout (in milliseconds)
dataData buffer
lenLength of data buffer
Return values
rcReturn status code

Definition at line 312 of file efi_usb.c.

316  {
317  struct efi_usb_device *usbdev = usbintf->usbdev;
318  struct efi_usb_endpoint *usbep;
319  struct io_buffer *iobuf;
320  unsigned int index = USB_ENDPOINT_IDX ( endpoint );
321  unsigned int i;
322  int rc;
323 
324  /* Open endpoint, if applicable */
325  if ( ( ! efi_usb_is_open ( usbintf, endpoint ) ) &&
326  ( ( rc = efi_usb_open ( usbintf, endpoint, attributes, 0,
327  &efi_usb_sync_driver ) ) != 0 ) ) {
328  goto err_open;
329  }
330  usbep = usbintf->endpoint[index];
331 
332  /* Allocate and construct I/O buffer */
333  iobuf = alloc_iob ( *len );
334  if ( ! iobuf ) {
335  rc = -ENOMEM;
336  goto err_alloc;
337  }
338  iob_put ( iobuf, *len );
339  if ( ! ( endpoint & USB_ENDPOINT_IN ) )
340  memcpy ( iobuf->data, data, *len );
341 
342  /* Initialise completion status */
343  usbep->rc = -EINPROGRESS;
344 
345  /* Enqueue transfer */
346  if ( ( rc = usb_stream ( &usbep->ep, iobuf, 0 ) ) != 0 ) {
347  DBGC ( usbdev, "USBDEV %s %s could not enqueue: %s\n",
348  usbintf->name, usb_endpoint_name ( &usbep->ep ),
349  strerror ( rc ) );
350  goto err_stream;
351  }
352 
353  /* Wait for completion */
354  rc = -ETIMEDOUT;
355  for ( i = 0 ; ( ( timeout == 0 ) || ( i < timeout ) ) ; i++ ) {
356 
357  /* Poll bus */
358  usb_poll ( usbdev->func->usb->port->hub->bus );
359 
360  /* Check for completion */
361  if ( usbep->rc != -EINPROGRESS ) {
362  rc = usbep->rc;
363  break;
364  }
365 
366  /* Delay */
367  mdelay ( 1 );
368  }
369 
370  /* Check for errors */
371  if ( rc != 0 ) {
372  DBGC ( usbdev, "USBDEV %s %s failed: %s\n", usbintf->name,
373  usb_endpoint_name ( &usbep->ep ), strerror ( rc ) );
374  goto err_completion;
375  }
376 
377  /* Copy completion to data buffer, if applicable */
378  assert ( iob_len ( iobuf ) <= *len );
379  if ( endpoint & USB_ENDPOINT_IN )
380  memcpy ( data, iobuf->data, iob_len ( iobuf ) );
381  *len = iob_len ( iobuf );
382 
383  /* Free I/O buffer */
384  free_iob ( iobuf );
385 
386  /* Leave endpoint open */
387  return 0;
388 
389  err_completion:
390  err_stream:
391  free_iob ( iobuf );
392  err_alloc:
393  efi_usb_close ( usbep );
394  err_open:
395  return EFIRC ( rc );
396 }
static void efi_usb_close(struct efi_usb_endpoint *usbep)
Close endpoint.
Definition: efi_usb.c:224
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
#define iob_put(iobuf, len)
Definition: iobuf.h:120
char name[32]
Name.
Definition: efi_usb.h:35
struct usb_function * func
The underlying USB function.
Definition: efi_usb.h:21
static struct usb_endpoint_driver_operations efi_usb_sync_driver
Synchronous endpoint operations.
Definition: efi_usb.c:297
void free_iob(struct io_buffer *iobuf)
Free I/O buffer.
Definition: iobuf.c:146
#define DBGC(...)
Definition: compiler.h:505
int usb_stream(struct usb_endpoint *ep, struct io_buffer *iobuf, int terminate)
Enqueue USB stream transfer.
Definition: usb.c:545
An EFI USB device.
Definition: efi_usb.h:17
struct io_buffer * alloc_iob(size_t len)
Allocate I/O buffer.
Definition: iobuf.c:129
struct efi_usb_endpoint * endpoint[32]
Opened endpoints.
Definition: efi_usb.h:53
#define ENOMEM
Not enough space.
Definition: errno.h:534
void * memcpy(void *dest, const void *src, size_t len) __nonnull
struct usb_port * port
USB port.
Definition: usb.h:712
assert((readw(&hdr->flags) &(GTF_reading|GTF_writing))==0)
int rc
Most recent synchronous completion status.
Definition: efi_usb.h:64
static int efi_usb_is_open(struct efi_usb_interface *usbintf, unsigned int endpoint)
Check if endpoint is open.
Definition: efi_usb.c:129
#define EINPROGRESS
Operation in progress.
Definition: errno.h:418
static void usb_poll(struct usb_bus *bus)
Poll USB bus.
Definition: usb.h:1051
#define USB_ENDPOINT_IN
Endpoint direction is in.
Definition: usb.h:510
char * strerror(int errno)
Retrieve string representation of error number.
Definition: strerror.c:78
static int efi_usb_open(struct efi_usb_interface *usbintf, unsigned int endpoint, unsigned int attributes, unsigned int interval, struct usb_endpoint_driver_operations *driver)
Open endpoint.
Definition: efi_usb.c:147
An EFI USB device endpoint.
Definition: efi_usb.h:57
static size_t iob_len(struct io_buffer *iobuf)
Calculate length of data in an I/O buffer.
Definition: iobuf.h:155
struct usb_device * usb
USB device.
Definition: usb.h:663
#define USB_ENDPOINT_IDX(address)
Construct endpoint index from endpoint address.
Definition: usb.h:513
const char * usb_endpoint_name(struct usb_endpoint *ep)
Get USB endpoint name (for debugging)
Definition: usb.c:220
struct usb_endpoint ep
USB endpoint.
Definition: efi_usb.h:61
void mdelay(unsigned long msecs)
Delay for a fixed number of milliseconds.
Definition: timer.c:78
uint32_t len
Length.
Definition: ena.h:14
void * data
Start of data.
Definition: iobuf.h:48
struct usb_hub * hub
USB hub.
Definition: usb.h:800
void timeout(int)
struct arbelprm_port_state_change_st data
Message.
Definition: arbel.h:12
uint64_t index
Index of the first segment within the content.
Definition: pccrc.h:21
struct efi_usb_device * usbdev
Containing USB device.
Definition: efi_usb.h:37
struct usb_bus * bus
USB bus.
Definition: usb.h:830
#define ETIMEDOUT
Connection timed out.
Definition: errno.h:669
#define EFIRC(rc)
Convert an iPXE status code to an EFI status code.
Definition: efi.h:154
A persistent I/O buffer.
Definition: iobuf.h:33

References alloc_iob(), assert(), usb_hub::bus, data, io_buffer::data, DBGC, efi_usb_close(), efi_usb_is_open(), efi_usb_open(), efi_usb_sync_driver, EFIRC, EINPROGRESS, efi_usb_interface::endpoint, ENOMEM, efi_usb_endpoint::ep, ETIMEDOUT, free_iob(), efi_usb_device::func, usb_port::hub, index, iob_len(), iob_put, len, mdelay(), memcpy(), efi_usb_interface::name, usb_device::port, efi_usb_endpoint::rc, rc, strerror(), timeout(), usb_function::usb, USB_ENDPOINT_IDX, USB_ENDPOINT_IN, usb_endpoint_name(), usb_poll(), usb_stream(), and efi_usb_interface::usbdev.

Referenced by efi_usb_bulk_transfer(), and efi_usb_sync_interrupt_transfer().

◆ efi_usb_async_complete()

static void efi_usb_async_complete ( struct usb_endpoint ep,
struct io_buffer iobuf,
int  rc 
)
static

Complete asynchronous transfer.

Parameters
epUSB endpoint
iobufI/O buffer
rcCompletion status code

Definition at line 405 of file efi_usb.c.

406  {
407  struct efi_usb_endpoint *usbep =
408  container_of ( ep, struct efi_usb_endpoint, ep );
409  UINT32 status;
410 
411  /* Ignore packets cancelled when the endpoint closes */
412  if ( ! ep->open )
413  goto drop;
414 
415  /* Construct status */
416  status = ( ( rc == 0 ) ? 0 : EFI_USB_ERR_SYSTEM );
417 
418  /* Report completion, if applicable */
419  if ( usbep->callback ) {
420  usbep->callback ( iobuf->data, iob_len ( iobuf ),
421  usbep->context, status );
422  }
423 
424  drop:
425  /* Recycle or free I/O buffer */
426  if ( usbep->ep.open ) {
427  usb_recycle ( &usbep->ep, iobuf );
428  } else {
429  free_iob ( iobuf );
430  }
431 }
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
void free_iob(struct io_buffer *iobuf)
Free I/O buffer.
Definition: iobuf.c:146
unsigned int UINT32
Definition: ProcessorBind.h:56
int open
Endpoint is open.
Definition: usb.h:404
#define EFI_USB_ERR_SYSTEM
Definition: UsbIo.h:70
uint8_t status
Status.
Definition: ena.h:16
static void usb_recycle(struct usb_endpoint *ep, struct io_buffer *iobuf)
Recycle I/O buffer.
Definition: usb.h:618
#define container_of(ptr, type, field)
Get containing structure.
Definition: stddef.h:35
void * context
Asynchronous callback context.
Definition: efi_usb.h:71
EFI_ASYNC_USB_TRANSFER_CALLBACK callback
Asynchronous callback handler.
Definition: efi_usb.h:69
An EFI USB device endpoint.
Definition: efi_usb.h:57
static size_t iob_len(struct io_buffer *iobuf)
Calculate length of data in an I/O buffer.
Definition: iobuf.h:155
struct usb_endpoint ep
USB endpoint.
Definition: efi_usb.h:61
void * data
Start of data.
Definition: iobuf.h:48

References efi_usb_endpoint::callback, container_of, efi_usb_endpoint::context, io_buffer::data, EFI_USB_ERR_SYSTEM, efi_usb_endpoint::ep, free_iob(), iob_len(), usb_endpoint::open, rc, status, and usb_recycle().

◆ efi_usb_async_start()

static int efi_usb_async_start ( struct efi_usb_interface usbintf,
unsigned int  endpoint,
unsigned int  interval,
size_t  len,
EFI_ASYNC_USB_TRANSFER_CALLBACK  callback,
void *  context 
)
static

Start asynchronous transfer.

Parameters
usbintfEFI USB interface
endpointEndpoint address
intervalInterval (in milliseconds)
lenTransfer length
callbackCallback function
contextContext for callback function
Return values
rcReturn status code

Definition at line 449 of file efi_usb.c.

453  {
455  struct efi_usb_device *usbdev = usbintf->usbdev;
456  struct efi_usb_endpoint *usbep;
457  unsigned int index = USB_ENDPOINT_IDX ( endpoint );
458  EFI_STATUS efirc;
459  int rc;
460 
461  /* Close endpoint, if applicable */
462  if ( efi_usb_is_open ( usbintf, endpoint ) )
464 
465  /* Open endpoint */
466  if ( ( rc = efi_usb_open ( usbintf, endpoint,
467  USB_ENDPOINT_ATTR_INTERRUPT, interval,
468  &efi_usb_async_driver ) ) != 0 )
469  goto err_open;
470  usbep = usbintf->endpoint[index];
471 
472  /* Record callback parameters */
473  usbep->callback = callback;
474  usbep->context = context;
475 
476  /* Prefill endpoint */
477  usb_refill_init ( &usbep->ep, 0, len, EFI_USB_ASYNC_FILL );
478  if ( ( rc = usb_prefill ( &usbep->ep ) ) != 0 ) {
479  DBGC ( usbdev, "USBDEV %s %s could not prefill: %s\n",
480  usbintf->name, usb_endpoint_name ( &usbep->ep ),
481  strerror ( rc ) );
482  goto err_prefill;
483  }
484 
485  /* Start timer */
486  if ( ( efirc = bs->SetTimer ( usbep->event, TimerPeriodic,
487  ( interval * 10000 ) ) ) != 0 ) {
488  rc = -EEFI ( efirc );
489  DBGC ( usbdev, "USBDEV %s %s could not set timer: %s\n",
490  usbintf->name, usb_endpoint_name ( &usbep->ep ),
491  strerror ( rc ) );
492  goto err_timer;
493  }
494 
495  return 0;
496 
497  bs->SetTimer ( usbep->event, TimerCancel, 0 );
498  err_timer:
499  err_prefill:
500  usbep->callback = NULL;
501  usbep->context = NULL;
502  efi_usb_close ( usbep );
503  err_open:
504  return rc;
505 }
EFI_BOOT_SERVICES * BootServices
A pointer to the EFI Boot Services Table.
Definition: UefiSpec.h:2000
static void efi_usb_close(struct efi_usb_endpoint *usbep)
Close endpoint.
Definition: efi_usb.c:224
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
#define EFI_USB_ASYNC_FILL
Asynchronous transfer fill level.
Definition: efi_usb.h:78
#define EEFI(efirc)
Convert an EFI status code to an iPXE status code.
Definition: efi.h:162
An event is to be signaled periodically at a specified interval from the current time.
Definition: UefiSpec.h:489
char name[32]
Name.
Definition: efi_usb.h:35
#define DBGC(...)
Definition: compiler.h:505
static struct usb_endpoint_driver_operations efi_usb_async_driver
Asynchronous endpoint operations.
Definition: efi_usb.c:434
int usb_prefill(struct usb_endpoint *ep)
Prefill endpoint recycled buffer list.
Definition: usb.c:619
EFI_SET_TIMER SetTimer
Definition: UefiSpec.h:1861
An EFI USB device.
Definition: efi_usb.h:17
struct efi_usb_endpoint * endpoint[32]
Opened endpoints.
Definition: efi_usb.h:53
An event's timer settings is to be cancelled and not trigger time is to be set/.
Definition: UefiSpec.h:485
EFI_EVENT event
Asynchronous timer event.
Definition: efi_usb.h:67
static void usb_refill_init(struct usb_endpoint *ep, size_t reserve, size_t len, unsigned int max)
Initialise USB endpoint refill.
Definition: usb.h:602
void * context
Asynchronous callback context.
Definition: efi_usb.h:71
struct efi_usb_interface * usbintf
EFI USB device interface.
Definition: efi_usb.h:59
EFI_ASYNC_USB_TRANSFER_CALLBACK callback
Asynchronous callback handler.
Definition: efi_usb.h:69
static int efi_usb_is_open(struct efi_usb_interface *usbintf, unsigned int endpoint)
Check if endpoint is open.
Definition: efi_usb.c:129
#define USB_ENDPOINT_ATTR_INTERRUPT
Interrupt endpoint transfer type.
Definition: usb.h:278
char * strerror(int errno)
Retrieve string representation of error number.
Definition: strerror.c:78
static int efi_usb_open(struct efi_usb_interface *usbintf, unsigned int endpoint, unsigned int attributes, unsigned int interval, struct usb_endpoint_driver_operations *driver)
Open endpoint.
Definition: efi_usb.c:147
An EFI USB device endpoint.
Definition: efi_usb.h:57
EFI Boot Services Table.
Definition: UefiSpec.h:1836
#define USB_ENDPOINT_IDX(address)
Construct endpoint index from endpoint address.
Definition: usb.h:513
const char * usb_endpoint_name(struct usb_endpoint *ep)
Get USB endpoint name (for debugging)
Definition: usb.c:220
struct usb_endpoint ep
USB endpoint.
Definition: efi_usb.h:61
uint32_t len
Length.
Definition: ena.h:14
RETURN_STATUS EFI_STATUS
Function return status for EFI API.
Definition: UefiBaseType.h:35
EFI_SYSTEM_TABLE * efi_systab
uint64_t index
Index of the first segment within the content.
Definition: pccrc.h:21
struct efi_usb_device * usbdev
Containing USB device.
Definition: efi_usb.h:37
#define NULL
NULL pointer (VOID *)
Definition: Base.h:362

References EFI_SYSTEM_TABLE::BootServices, efi_usb_endpoint::callback, efi_usb_endpoint::context, DBGC, EEFI, efi_systab, efi_usb_async_driver, EFI_USB_ASYNC_FILL, efi_usb_close(), efi_usb_is_open(), efi_usb_open(), efi_usb_interface::endpoint, efi_usb_endpoint::ep, efi_usb_endpoint::event, index, len, efi_usb_interface::name, NULL, rc, EFI_BOOT_SERVICES::SetTimer, strerror(), TimerCancel, TimerPeriodic, USB_ENDPOINT_ATTR_INTERRUPT, USB_ENDPOINT_IDX, usb_endpoint_name(), usb_prefill(), usb_refill_init(), efi_usb_interface::usbdev, and efi_usb_endpoint::usbintf.

Referenced by efi_usb_async_interrupt_transfer().

◆ efi_usb_async_stop()

static void efi_usb_async_stop ( struct efi_usb_interface usbintf,
unsigned int  endpoint 
)
static

Stop asynchronous transfer.

Parameters
usbintfEFI USB interface
endpointEndpoint address

Definition at line 513 of file efi_usb.c.

514  {
516  struct efi_usb_endpoint *usbep;
517  unsigned int index = USB_ENDPOINT_IDX ( endpoint );
518 
519  /* Do nothing if endpoint is already closed */
520  if ( ! efi_usb_is_open ( usbintf, endpoint ) )
521  return;
522  usbep = usbintf->endpoint[index];
523 
524  /* Stop timer */
525  bs->SetTimer ( usbep->event, TimerCancel, 0 );
526 
527  /* Clear callback parameters */
528  usbep->callback = NULL;
529  usbep->context = NULL;
530 }
EFI_BOOT_SERVICES * BootServices
A pointer to the EFI Boot Services Table.
Definition: UefiSpec.h:2000
EFI_SET_TIMER SetTimer
Definition: UefiSpec.h:1861
struct efi_usb_endpoint * endpoint[32]
Opened endpoints.
Definition: efi_usb.h:53
An event's timer settings is to be cancelled and not trigger time is to be set/.
Definition: UefiSpec.h:485
EFI_EVENT event
Asynchronous timer event.
Definition: efi_usb.h:67
void * context
Asynchronous callback context.
Definition: efi_usb.h:71
struct efi_usb_interface * usbintf
EFI USB device interface.
Definition: efi_usb.h:59
EFI_ASYNC_USB_TRANSFER_CALLBACK callback
Asynchronous callback handler.
Definition: efi_usb.h:69
static int efi_usb_is_open(struct efi_usb_interface *usbintf, unsigned int endpoint)
Check if endpoint is open.
Definition: efi_usb.c:129
An EFI USB device endpoint.
Definition: efi_usb.h:57
EFI Boot Services Table.
Definition: UefiSpec.h:1836
#define USB_ENDPOINT_IDX(address)
Construct endpoint index from endpoint address.
Definition: usb.h:513
EFI_SYSTEM_TABLE * efi_systab
uint64_t index
Index of the first segment within the content.
Definition: pccrc.h:21
#define NULL
NULL pointer (VOID *)
Definition: Base.h:362

References EFI_SYSTEM_TABLE::BootServices, efi_usb_endpoint::callback, efi_usb_endpoint::context, efi_systab, efi_usb_is_open(), efi_usb_interface::endpoint, efi_usb_endpoint::event, index, NULL, EFI_BOOT_SERVICES::SetTimer, TimerCancel, USB_ENDPOINT_IDX, and efi_usb_endpoint::usbintf.

Referenced by efi_usb_async_interrupt_transfer().

◆ efi_usb_control_transfer()

static EFI_STATUS EFIAPI efi_usb_control_transfer ( EFI_USB_IO_PROTOCOL usbio,
EFI_USB_DEVICE_REQUEST packet,
EFI_USB_DATA_DIRECTION  direction,
UINT32  timeout,
VOID data,
UINTN  len,
UINT32 status 
)
static

Perform control transfer.

Parameters
usbioUSB I/O protocol
packetSetup packet
directionData direction
timeoutTimeout (in milliseconds)
dataData buffer
lenLength of data
Return values
statusTransfer status
efircEFI status code

Definition at line 552 of file efi_usb.c.

556  {
557  struct efi_usb_interface *usbintf =
559  struct efi_usb_device *usbdev = usbintf->usbdev;
560  unsigned int request = ( packet->RequestType |
561  USB_REQUEST_TYPE ( packet->Request ) );
562  unsigned int value = le16_to_cpu ( packet->Value );
563  unsigned int index = le16_to_cpu ( packet->Index );
564  struct efi_saved_tpl tpl;
565  int rc;
566 
567  DBGC2 ( usbdev, "USBDEV %s control %04x:%04x:%04x:%04x %s %dms "
568  "%p+%zx\n", usbintf->name, request, value, index,
569  le16_to_cpu ( packet->Length ),
571  ( ( size_t ) len ) );
572 
573  /* Raise TPL */
574  efi_raise_tpl ( &tpl );
575 
576  /* Clear status */
577  *status = 0;
578 
579  /* Block attempts to change the device configuration, since
580  * this is logically impossible to do given the constraints of
581  * the EFI_USB_IO_PROTOCOL design.
582  */
583  if ( ( request == USB_SET_CONFIGURATION ) &&
584  ( value != usbdev->config->config ) ) {
585  DBGC ( usbdev, "USBDEV %s cannot set configuration %d: not "
586  "logically possible\n", usbintf->name, index );
587  rc = -ENOTSUP;
588  goto err_change_config;
589  }
590 
591  /* If we are selecting a new alternate setting then close all
592  * open endpoints.
593  */
594  if ( ( request == USB_SET_INTERFACE ) &&
595  ( value != usbintf->alternate ) )
596  efi_usb_close_all ( usbintf );
597 
598  /* Issue control transfer */
599  if ( ( rc = usb_control ( usbdev->func->usb, request, value, index,
600  data, len ) ) != 0 ) {
601  DBGC ( usbdev, "USBDEV %s control %04x:%04x:%04x:%04x %p+%zx "
602  "failed: %s\n", usbintf->name, request, value, index,
603  le16_to_cpu ( packet->Length ), data, ( ( size_t ) len ),
604  strerror ( rc ) );
606  goto err_control;
607  }
608 
609  /* Update alternate setting, if applicable */
610  if ( request == USB_SET_INTERFACE ) {
611  usbintf->alternate = value;
612  DBGC ( usbdev, "USBDEV %s alt %d selected\n",
613  usbintf->name, usbintf->alternate );
614  }
615 
616  err_control:
617  err_change_config:
618  efi_restore_tpl ( &tpl );
619  return EFIRC ( rc );
620 }
UINT8 Request
Definition: Usb.h:101
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
unsigned int alternate
Alternate setting.
Definition: efi_usb.h:44
static void efi_usb_close_all(struct efi_usb_interface *usbintf)
Close all endpoints.
Definition: efi_usb.c:248
char name[32]
Name.
Definition: efi_usb.h:35
struct usb_function * func
The underlying USB function.
Definition: efi_usb.h:21
void efi_raise_tpl(struct efi_saved_tpl *tpl)
Raise task priority level to internal level.
Definition: efi_init.c:394
#define DBGC(...)
Definition: compiler.h:505
uint8_t direction
Direction.
Definition: ena.h:14
An EFI USB device.
Definition: efi_usb.h:17
int usb_control(struct usb_device *usb, unsigned int request, unsigned int value, unsigned int index, void *data, size_t len)
Issue USB control transaction.
Definition: usb.c:783
#define ENOTSUP
Operation not supported.
Definition: errno.h:589
#define EFI_USB_ERR_SYSTEM
Definition: UsbIo.h:70
uint8_t status
Status.
Definition: ena.h:16
An EFI USB device interface.
Definition: efi_usb.h:33
#define container_of(ptr, type, field)
Get containing structure.
Definition: stddef.h:35
static const char * efi_usb_direction_name(EFI_USB_DATA_DIRECTION direction)
Transcribe data direction (for debugging)
Definition: efi_usb.c:51
pseudo_bit_t value[0x00020]
Definition: arbel.h:13
UINT8 RequestType
Definition: Usb.h:100
#define USB_SET_INTERFACE
Set interface.
Definition: usb.h:138
char * strerror(int errno)
Retrieve string representation of error number.
Definition: strerror.c:78
UINT16 Length
Definition: Usb.h:104
struct usb_configuration_descriptor * config
Configuration descriptor.
Definition: efi_usb.h:23
struct usb_device * usb
USB device.
Definition: usb.h:663
#define le16_to_cpu(value)
Definition: byteswap.h:112
EFI_USB_IO_PROTOCOL usbio
USB I/O protocol.
Definition: efi_usb.h:48
#define USB_REQUEST_TYPE(type)
Construct USB request type.
Definition: usb.h:107
An EFI saved task priority level.
Definition: efi.h:67
uint32_t len
Length.
Definition: ena.h:14
uint8_t config
Configuration value.
Definition: usb.h:203
#define DBGC2(...)
Definition: compiler.h:522
u8 request[0]
List of IEs requested.
Definition: ieee80211.h:16
void timeout(int)
struct arbelprm_port_state_change_st data
Message.
Definition: arbel.h:12
uint64_t index
Index of the first segment within the content.
Definition: pccrc.h:21
struct efi_usb_device * usbdev
Containing USB device.
Definition: efi_usb.h:37
#define USB_SET_CONFIGURATION
Set configuration.
Definition: usb.h:131
void efi_restore_tpl(struct efi_saved_tpl *tpl)
Restore task priority level.
Definition: efi_init.c:410
UINT16 Value
Definition: Usb.h:102
#define EFIRC(rc)
Convert an iPXE status code to an EFI status code.
Definition: efi.h:154
UINT16 Index
Definition: Usb.h:103

References efi_usb_interface::alternate, efi_usb_device::config, usb_configuration_descriptor::config, container_of, data, DBGC, DBGC2, direction, efi_raise_tpl(), efi_restore_tpl(), efi_usb_close_all(), efi_usb_direction_name(), EFI_USB_ERR_SYSTEM, EFIRC, ENOTSUP, efi_usb_device::func, index, USB_DEVICE_REQUEST::Index, le16_to_cpu, len, USB_DEVICE_REQUEST::Length, efi_usb_interface::name, rc, request, USB_DEVICE_REQUEST::Request, USB_DEVICE_REQUEST::RequestType, status, strerror(), timeout(), usb_function::usb, usb_control(), USB_REQUEST_TYPE, USB_SET_CONFIGURATION, USB_SET_INTERFACE, efi_usb_interface::usbdev, efi_usb_interface::usbio, value, and USB_DEVICE_REQUEST::Value.

◆ efi_usb_bulk_transfer()

static EFI_STATUS EFIAPI efi_usb_bulk_transfer ( EFI_USB_IO_PROTOCOL usbio,
UINT8  endpoint,
VOID data,
UINTN len,
UINTN  timeout,
UINT32 status 
)
static

Perform bulk transfer.

Parameters
usbioUSB I/O protocol
endpointEndpoint address
dataData buffer
lenLength of data
timeoutTimeout (in milliseconds)
Return values
statusTransfer status
efircEFI status code

Definition at line 634 of file efi_usb.c.

635  {
636  struct efi_usb_interface *usbintf =
638  struct efi_usb_device *usbdev = usbintf->usbdev;
639  size_t actual = *len;
640  struct efi_saved_tpl tpl;
641  int rc;
642 
643  DBGC2 ( usbdev, "USBDEV %s bulk %s %p+%zx %dms\n", usbintf->name,
644  ( ( endpoint & USB_ENDPOINT_IN ) ? "IN" : "OUT" ), data,
645  ( ( size_t ) *len ), ( ( unsigned int ) timeout ) );
646 
647  /* Raise TPL */
648  efi_raise_tpl ( &tpl );
649 
650  /* Clear status */
651  *status = 0;
652 
653  /* Perform synchronous transfer */
654  if ( ( rc = efi_usb_sync_transfer ( usbintf, endpoint,
656  data, &actual ) ) != 0 ) {
657  /* Assume that any error represents a timeout */
659  goto err_transfer;
660  }
661 
662  err_transfer:
663  efi_restore_tpl ( &tpl );
664  return EFIRC ( rc );
665 }
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
char name[32]
Name.
Definition: efi_usb.h:35
void efi_raise_tpl(struct efi_saved_tpl *tpl)
Raise task priority level to internal level.
Definition: efi_init.c:394
#define USB_ENDPOINT_ATTR_BULK
Bulk endpoint transfer type.
Definition: usb.h:275
An EFI USB device.
Definition: efi_usb.h:17
uint8_t status
Status.
Definition: ena.h:16
An EFI USB device interface.
Definition: efi_usb.h:33
#define container_of(ptr, type, field)
Get containing structure.
Definition: stddef.h:35
#define USB_ENDPOINT_IN
Endpoint direction is in.
Definition: usb.h:510
#define EFI_USB_ERR_TIMEOUT
Definition: UsbIo.h:68
static int efi_usb_sync_transfer(struct efi_usb_interface *usbintf, unsigned int endpoint, unsigned int attributes, unsigned int timeout, void *data, size_t *len)
Perform synchronous transfer.
Definition: efi_usb.c:312
EFI_USB_IO_PROTOCOL usbio
USB I/O protocol.
Definition: efi_usb.h:48
An EFI saved task priority level.
Definition: efi.h:67
uint32_t len
Length.
Definition: ena.h:14
#define DBGC2(...)
Definition: compiler.h:522
void timeout(int)
struct arbelprm_port_state_change_st data
Message.
Definition: arbel.h:12
struct efi_usb_device * usbdev
Containing USB device.
Definition: efi_usb.h:37
void efi_restore_tpl(struct efi_saved_tpl *tpl)
Restore task priority level.
Definition: efi_init.c:410
#define EFIRC(rc)
Convert an iPXE status code to an EFI status code.
Definition: efi.h:154

References container_of, data, DBGC2, efi_raise_tpl(), efi_restore_tpl(), EFI_USB_ERR_TIMEOUT, efi_usb_sync_transfer(), EFIRC, len, efi_usb_interface::name, rc, status, timeout(), USB_ENDPOINT_ATTR_BULK, USB_ENDPOINT_IN, efi_usb_interface::usbdev, and efi_usb_interface::usbio.

◆ efi_usb_sync_interrupt_transfer()

static EFI_STATUS EFIAPI efi_usb_sync_interrupt_transfer ( EFI_USB_IO_PROTOCOL usbio,
UINT8  endpoint,
VOID data,
UINTN len,
UINTN  timeout,
UINT32 status 
)
static

Perform synchronous interrupt transfer.

Parameters
usbioUSB I/O protocol
endpointEndpoint address
dataData buffer
lenLength of data
timeoutTimeout (in milliseconds)
Return values
statusTransfer status
efircEFI status code

Definition at line 679 of file efi_usb.c.

681  {
682  struct efi_usb_interface *usbintf =
684  struct efi_usb_device *usbdev = usbintf->usbdev;
685  size_t actual = *len;
686  struct efi_saved_tpl tpl;
687  int rc;
688 
689  DBGC2 ( usbdev, "USBDEV %s sync intr %s %p+%zx %dms\n", usbintf->name,
690  ( ( endpoint & USB_ENDPOINT_IN ) ? "IN" : "OUT" ), data,
691  ( ( size_t ) *len ), ( ( unsigned int ) timeout ) );
692 
693  /* Raise TPL */
694  efi_raise_tpl ( &tpl );
695 
696  /* Clear status */
697  *status = 0;
698 
699  /* Perform synchronous transfer */
700  if ( ( rc = efi_usb_sync_transfer ( usbintf, endpoint,
702  timeout, data, &actual ) ) != 0 ) {
703  /* Assume that any error represents a timeout */
705  goto err_transfer;
706  }
707 
708  err_transfer:
709  efi_restore_tpl ( &tpl );
710  return EFIRC ( rc );
711 }
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
char name[32]
Name.
Definition: efi_usb.h:35
void efi_raise_tpl(struct efi_saved_tpl *tpl)
Raise task priority level to internal level.
Definition: efi_init.c:394
An EFI USB device.
Definition: efi_usb.h:17
uint8_t status
Status.
Definition: ena.h:16
An EFI USB device interface.
Definition: efi_usb.h:33
#define container_of(ptr, type, field)
Get containing structure.
Definition: stddef.h:35
#define USB_ENDPOINT_IN
Endpoint direction is in.
Definition: usb.h:510
#define USB_ENDPOINT_ATTR_INTERRUPT
Interrupt endpoint transfer type.
Definition: usb.h:278
#define EFI_USB_ERR_TIMEOUT
Definition: UsbIo.h:68
static int efi_usb_sync_transfer(struct efi_usb_interface *usbintf, unsigned int endpoint, unsigned int attributes, unsigned int timeout, void *data, size_t *len)
Perform synchronous transfer.
Definition: efi_usb.c:312
EFI_USB_IO_PROTOCOL usbio
USB I/O protocol.
Definition: efi_usb.h:48
An EFI saved task priority level.
Definition: efi.h:67
uint32_t len
Length.
Definition: ena.h:14
#define DBGC2(...)
Definition: compiler.h:522
void timeout(int)
struct arbelprm_port_state_change_st data
Message.
Definition: arbel.h:12
struct efi_usb_device * usbdev
Containing USB device.
Definition: efi_usb.h:37
void efi_restore_tpl(struct efi_saved_tpl *tpl)
Restore task priority level.
Definition: efi_init.c:410
#define EFIRC(rc)
Convert an iPXE status code to an EFI status code.
Definition: efi.h:154

References container_of, data, DBGC2, efi_raise_tpl(), efi_restore_tpl(), EFI_USB_ERR_TIMEOUT, efi_usb_sync_transfer(), EFIRC, len, efi_usb_interface::name, rc, status, timeout(), USB_ENDPOINT_ATTR_INTERRUPT, USB_ENDPOINT_IN, efi_usb_interface::usbdev, and efi_usb_interface::usbio.

◆ efi_usb_async_interrupt_transfer()

static EFI_STATUS EFIAPI efi_usb_async_interrupt_transfer ( EFI_USB_IO_PROTOCOL usbio,
UINT8  endpoint,
BOOLEAN  start,
UINTN  interval,
UINTN  len,
EFI_ASYNC_USB_TRANSFER_CALLBACK  callback,
VOID context 
)
static

Perform asynchronous interrupt transfer.

Parameters
usbioUSB I/O protocol
endpointEndpoint address
startStart (rather than stop) transfer
intervalPolling interval (in milliseconds)
lenData length
callbackCallback function
contextContext for callback function
Return values
efircEFI status code

Definition at line 726 of file efi_usb.c.

729  {
730  struct efi_usb_interface *usbintf =
732  struct efi_usb_device *usbdev = usbintf->usbdev;
733  struct efi_saved_tpl tpl;
734  int rc;
735 
736  DBGC2 ( usbdev, "USBDEV %s async intr %s len %#zx int %d %p/%p\n",
737  usbintf->name,
738  ( ( endpoint & USB_ENDPOINT_IN ) ? "IN" : "OUT" ),
739  ( ( size_t ) len ), ( ( unsigned int ) interval ),
740  callback, context );
741 
742  /* Raise TPL */
743  efi_raise_tpl ( &tpl );
744 
745  /* Start/stop transfer as applicable */
746  if ( start ) {
747 
748  /* Start new transfer */
749  if ( ( rc = efi_usb_async_start ( usbintf, endpoint, interval,
750  len, callback,
751  context ) ) != 0 )
752  goto err_start;
753 
754  } else {
755 
756  /* Stop transfer */
757  efi_usb_async_stop ( usbintf, endpoint );
758 
759  /* Success */
760  rc = 0;
761 
762  }
763 
764  err_start:
765  efi_restore_tpl ( &tpl );
766  return EFIRC ( rc );
767 }
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
char name[32]
Name.
Definition: efi_usb.h:35
void efi_raise_tpl(struct efi_saved_tpl *tpl)
Raise task priority level to internal level.
Definition: efi_init.c:394
static void efi_usb_async_stop(struct efi_usb_interface *usbintf, unsigned int endpoint)
Stop asynchronous transfer.
Definition: efi_usb.c:513
An EFI USB device.
Definition: efi_usb.h:17
uint32_t start
Starting offset.
Definition: netvsc.h:12
An EFI USB device interface.
Definition: efi_usb.h:33
#define container_of(ptr, type, field)
Get containing structure.
Definition: stddef.h:35
static int efi_usb_async_start(struct efi_usb_interface *usbintf, unsigned int endpoint, unsigned int interval, size_t len, EFI_ASYNC_USB_TRANSFER_CALLBACK callback, void *context)
Start asynchronous transfer.
Definition: efi_usb.c:449
#define USB_ENDPOINT_IN
Endpoint direction is in.
Definition: usb.h:510
EFI_USB_IO_PROTOCOL usbio
USB I/O protocol.
Definition: efi_usb.h:48
An EFI saved task priority level.
Definition: efi.h:67
uint32_t len
Length.
Definition: ena.h:14
#define DBGC2(...)
Definition: compiler.h:522
struct efi_usb_device * usbdev
Containing USB device.
Definition: efi_usb.h:37
void efi_restore_tpl(struct efi_saved_tpl *tpl)
Restore task priority level.
Definition: efi_init.c:410
#define EFIRC(rc)
Convert an iPXE status code to an EFI status code.
Definition: efi.h:154

References container_of, DBGC2, efi_raise_tpl(), efi_restore_tpl(), efi_usb_async_start(), efi_usb_async_stop(), EFIRC, len, efi_usb_interface::name, rc, start, USB_ENDPOINT_IN, efi_usb_interface::usbdev, and efi_usb_interface::usbio.

◆ efi_usb_isochronous_transfer()

static EFI_STATUS EFIAPI efi_usb_isochronous_transfer ( EFI_USB_IO_PROTOCOL usbio,
UINT8  endpoint,
VOID data,
UINTN  len,
UINT32 status 
)
static

Perform synchronous isochronous transfer.

Parameters
usbioUSB I/O protocol
endpointEndpoint address
dataData buffer
lenLength of data
Return values
statusTransfer status
efircEFI status code

Definition at line 780 of file efi_usb.c.

781  {
782  struct efi_usb_interface *usbintf =
784  struct efi_usb_device *usbdev = usbintf->usbdev;
785 
786  DBGC2 ( usbdev, "USBDEV %s sync iso %s %p+%zx\n", usbintf->name,
787  ( ( endpoint & USB_ENDPOINT_IN ) ? "IN" : "OUT" ), data,
788  ( ( size_t ) len ) );
789 
790  /* Clear status */
791  *status = 0;
792 
793  /* Not supported */
794  return EFI_UNSUPPORTED;
795 }
#define EFI_UNSUPPORTED
Enumeration of EFI_STATUS.
Definition: UefiBaseType.h:123
char name[32]
Name.
Definition: efi_usb.h:35
An EFI USB device.
Definition: efi_usb.h:17
uint8_t status
Status.
Definition: ena.h:16
An EFI USB device interface.
Definition: efi_usb.h:33
#define container_of(ptr, type, field)
Get containing structure.
Definition: stddef.h:35
#define USB_ENDPOINT_IN
Endpoint direction is in.
Definition: usb.h:510
EFI_USB_IO_PROTOCOL usbio
USB I/O protocol.
Definition: efi_usb.h:48
uint32_t len
Length.
Definition: ena.h:14
#define DBGC2(...)
Definition: compiler.h:522
struct arbelprm_port_state_change_st data
Message.
Definition: arbel.h:12
struct efi_usb_device * usbdev
Containing USB device.
Definition: efi_usb.h:37

References container_of, data, DBGC2, EFI_UNSUPPORTED, len, efi_usb_interface::name, status, USB_ENDPOINT_IN, efi_usb_interface::usbdev, and efi_usb_interface::usbio.

◆ efi_usb_async_isochronous_transfer()

static EFI_STATUS EFIAPI efi_usb_async_isochronous_transfer ( EFI_USB_IO_PROTOCOL usbio,
UINT8  endpoint,
VOID data,
UINTN  len,
EFI_ASYNC_USB_TRANSFER_CALLBACK  callback,
VOID context 
)
static

Perform asynchronous isochronous transfers.

Parameters
usbioUSB I/O protocol
endpointEndpoint address
dataData buffer
lenLength of data
callbackCallback function
contextContext for callback function
Return values
statusTransfer status
efircEFI status code

Definition at line 810 of file efi_usb.c.

813  {
814  struct efi_usb_interface *usbintf =
816  struct efi_usb_device *usbdev = usbintf->usbdev;
817 
818  DBGC2 ( usbdev, "USBDEV %s async iso %s %p+%zx %p/%p\n", usbintf->name,
819  ( ( endpoint & USB_ENDPOINT_IN ) ? "IN" : "OUT" ), data,
820  ( ( size_t ) len ), callback, context );
821 
822  /* Not supported */
823  return EFI_UNSUPPORTED;
824 }
#define EFI_UNSUPPORTED
Enumeration of EFI_STATUS.
Definition: UefiBaseType.h:123
char name[32]
Name.
Definition: efi_usb.h:35
An EFI USB device.
Definition: efi_usb.h:17
An EFI USB device interface.
Definition: efi_usb.h:33
#define container_of(ptr, type, field)
Get containing structure.
Definition: stddef.h:35
#define USB_ENDPOINT_IN
Endpoint direction is in.
Definition: usb.h:510
EFI_USB_IO_PROTOCOL usbio
USB I/O protocol.
Definition: efi_usb.h:48
uint32_t len
Length.
Definition: ena.h:14
#define DBGC2(...)
Definition: compiler.h:522
struct arbelprm_port_state_change_st data
Message.
Definition: arbel.h:12
struct efi_usb_device * usbdev
Containing USB device.
Definition: efi_usb.h:37

References container_of, data, DBGC2, EFI_UNSUPPORTED, len, efi_usb_interface::name, USB_ENDPOINT_IN, efi_usb_interface::usbdev, and efi_usb_interface::usbio.

◆ efi_usb_get_device_descriptor()

static EFI_STATUS EFIAPI efi_usb_get_device_descriptor ( EFI_USB_IO_PROTOCOL usbio,
EFI_USB_DEVICE_DESCRIPTOR efidesc 
)
static

Get device descriptor.

Parameters
usbioUSB I/O protocol
Return values
efidescEFI device descriptor
efircEFI status code

Definition at line 834 of file efi_usb.c.

835  {
836  struct efi_usb_interface *usbintf =
838  struct efi_usb_device *usbdev = usbintf->usbdev;
839 
840  DBGC2 ( usbdev, "USBDEV %s get device descriptor\n", usbintf->name );
841 
842  /* Copy cached device descriptor */
843  memcpy ( efidesc, &usbdev->func->usb->device, sizeof ( *efidesc ) );
844 
845  return 0;
846 }
char name[32]
Name.
Definition: efi_usb.h:35
struct usb_function * func
The underlying USB function.
Definition: efi_usb.h:21
An EFI USB device.
Definition: efi_usb.h:17
An EFI USB device interface.
Definition: efi_usb.h:33
void * memcpy(void *dest, const void *src, size_t len) __nonnull
#define container_of(ptr, type, field)
Get containing structure.
Definition: stddef.h:35
struct usb_device_descriptor device
Device descriptor.
Definition: usb.h:720
struct usb_device * usb
USB device.
Definition: usb.h:663
EFI_USB_IO_PROTOCOL usbio
USB I/O protocol.
Definition: efi_usb.h:48
#define DBGC2(...)
Definition: compiler.h:522
struct efi_usb_device * usbdev
Containing USB device.
Definition: efi_usb.h:37

References container_of, DBGC2, usb_device::device, efi_usb_device::func, memcpy(), efi_usb_interface::name, usb_function::usb, efi_usb_interface::usbdev, and efi_usb_interface::usbio.

◆ efi_usb_get_config_descriptor()

static EFI_STATUS EFIAPI efi_usb_get_config_descriptor ( EFI_USB_IO_PROTOCOL usbio,
EFI_USB_CONFIG_DESCRIPTOR efidesc 
)
static

Get configuration descriptor.

Parameters
usbioUSB I/O protocol
Return values
efidescEFI interface descriptor
efircEFI status code

Definition at line 856 of file efi_usb.c.

857  {
858  struct efi_usb_interface *usbintf =
860  struct efi_usb_device *usbdev = usbintf->usbdev;
861 
862  DBGC2 ( usbdev, "USBDEV %s get configuration descriptor\n",
863  usbintf->name );
864 
865  /* Copy cached configuration descriptor */
866  memcpy ( efidesc, usbdev->config, sizeof ( *efidesc ) );
867 
868  return 0;
869 }
char name[32]
Name.
Definition: efi_usb.h:35
An EFI USB device.
Definition: efi_usb.h:17
An EFI USB device interface.
Definition: efi_usb.h:33
void * memcpy(void *dest, const void *src, size_t len) __nonnull
#define container_of(ptr, type, field)
Get containing structure.
Definition: stddef.h:35
struct usb_configuration_descriptor * config
Configuration descriptor.
Definition: efi_usb.h:23
EFI_USB_IO_PROTOCOL usbio
USB I/O protocol.
Definition: efi_usb.h:48
#define DBGC2(...)
Definition: compiler.h:522
struct efi_usb_device * usbdev
Containing USB device.
Definition: efi_usb.h:37

References efi_usb_device::config, container_of, DBGC2, memcpy(), efi_usb_interface::name, efi_usb_interface::usbdev, and efi_usb_interface::usbio.

◆ efi_usb_get_interface_descriptor()

static EFI_STATUS EFIAPI efi_usb_get_interface_descriptor ( EFI_USB_IO_PROTOCOL usbio,
EFI_USB_INTERFACE_DESCRIPTOR efidesc 
)
static

Get interface descriptor.

Parameters
usbioUSB I/O protocol
Return values
efidescEFI interface descriptor
efircEFI status code

Definition at line 879 of file efi_usb.c.

880  {
881  struct efi_usb_interface *usbintf =
883  struct efi_usb_device *usbdev = usbintf->usbdev;
884  struct usb_interface_descriptor *desc;
885 
886  DBGC2 ( usbdev, "USBDEV %s get interface descriptor\n", usbintf->name );
887 
888  /* Locate cached interface descriptor */
889  desc = usb_interface_descriptor ( usbdev->config, usbintf->interface,
890  usbintf->alternate );
891  if ( ! desc ) {
892  DBGC ( usbdev, "USBDEV %s alt %d has no interface descriptor\n",
893  usbintf->name, usbintf->alternate );
894  return -ENOENT;
895  }
896 
897  /* Copy cached interface descriptor */
898  memcpy ( efidesc, desc, sizeof ( *efidesc ) );
899 
900  return 0;
901 }
unsigned int alternate
Alternate setting.
Definition: efi_usb.h:44
char name[32]
Name.
Definition: efi_usb.h:35
#define DBGC(...)
Definition: compiler.h:505
#define ENOENT
No such file or directory.
Definition: errno.h:514
An EFI USB device.
Definition: efi_usb.h:17
An EFI USB device interface.
Definition: efi_usb.h:33
void * memcpy(void *dest, const void *src, size_t len) __nonnull
A USB interface descriptor.
Definition: usb.h:230
#define container_of(ptr, type, field)
Get containing structure.
Definition: stddef.h:35
struct usb_interface_descriptor * usb_interface_descriptor(struct usb_configuration_descriptor *config, unsigned int interface, unsigned int alternate)
Locate USB interface descriptor.
Definition: usb.c:143
unsigned int interface
Interface number.
Definition: efi_usb.h:42
struct usb_configuration_descriptor * config
Configuration descriptor.
Definition: efi_usb.h:23
EFI_USB_IO_PROTOCOL usbio
USB I/O protocol.
Definition: efi_usb.h:48
#define DBGC2(...)
Definition: compiler.h:522
struct efi_usb_device * usbdev
Containing USB device.
Definition: efi_usb.h:37

References efi_usb_interface::alternate, efi_usb_device::config, container_of, DBGC, DBGC2, ENOENT, efi_usb_interface::interface, memcpy(), efi_usb_interface::name, usb_interface_descriptor(), efi_usb_interface::usbdev, and efi_usb_interface::usbio.

◆ efi_usb_get_endpoint_descriptor()

static EFI_STATUS EFIAPI efi_usb_get_endpoint_descriptor ( EFI_USB_IO_PROTOCOL usbio,
UINT8  index,
EFI_USB_ENDPOINT_DESCRIPTOR efidesc 
)
static

Get endpoint descriptor.

Parameters
usbioUSB I/O protocol
addressEndpoint index
Return values
efidescEFI interface descriptor
efircEFI status code

Definition at line 912 of file efi_usb.c.

913  {
914  struct efi_usb_interface *usbintf =
916  struct efi_usb_device *usbdev = usbintf->usbdev;
918  struct usb_endpoint_descriptor *desc;
919 
920  DBGC2 ( usbdev, "USBDEV %s get endpoint %d descriptor\n",
921  usbintf->name, index );
922 
923  /* Locate cached interface descriptor */
924  interface = usb_interface_descriptor ( usbdev->config,
925  usbintf->interface,
926  usbintf->alternate );
927  if ( ! interface ) {
928  DBGC ( usbdev, "USBDEV %s alt %d has no interface descriptor\n",
929  usbintf->name, usbintf->alternate );
930  return -ENOENT;
931  }
932 
933  /* Locate and copy cached endpoint descriptor */
934  for_each_interface_descriptor ( desc, usbdev->config, interface ) {
935  if ( ( desc->header.type == USB_ENDPOINT_DESCRIPTOR ) &&
936  ( index-- == 0 ) ) {
937  memcpy ( efidesc, desc, sizeof ( *efidesc ) );
938  return 0;
939  }
940  }
941  return -ENOENT;
942 }
unsigned int alternate
Alternate setting.
Definition: efi_usb.h:44
char name[32]
Name.
Definition: efi_usb.h:35
#define DBGC(...)
Definition: compiler.h:505
#define ENOENT
No such file or directory.
Definition: errno.h:514
#define for_each_interface_descriptor(desc, config, interface)
Iterate over all configuration descriptors within an interface descriptor.
Definition: usb.h:379
An EFI USB device.
Definition: efi_usb.h:17
An EFI USB device interface.
Definition: efi_usb.h:33
void * memcpy(void *dest, const void *src, size_t len) __nonnull
A USB interface descriptor.
Definition: usb.h:230
#define container_of(ptr, type, field)
Get containing structure.
Definition: stddef.h:35
An object interface.
Definition: interface.h:124
struct ib_cm_path alternate
Alternate path.
Definition: ib_mad.h:42
uint8_t type
Descriptor type.
Definition: usb.h:162
struct usb_configuration_descriptor * config
Configuration descriptor.
Definition: efi_usb.h:23
Standard Endpoint Descriptor USB 2.0 spec, Section 9.6.6.
Definition: Usb.h:163
EFI_USB_IO_PROTOCOL usbio
USB I/O protocol.
Definition: efi_usb.h:48
A USB endpoint descriptor.
Definition: usb.h:249
#define DBGC2(...)
Definition: compiler.h:522
struct usb_descriptor_header header
Descriptor header.
Definition: usb.h:251
uint64_t index
Index of the first segment within the content.
Definition: pccrc.h:21
struct efi_usb_device * usbdev
Containing USB device.
Definition: efi_usb.h:37
uint8_t interface
Interface number.
Definition: usb.h:234

References alternate, usb_interface_descriptor::alternate, container_of, DBGC, DBGC2, ENOENT, for_each_interface_descriptor, usb_endpoint_descriptor::header, index, usb_interface_descriptor::interface, memcpy(), efi_usb_interface::name, usb_interface_descriptor::name, usb_descriptor_header::type, efi_usb_interface::usbdev, and efi_usb_interface::usbio.

◆ efi_usb_get_string_descriptor()

static EFI_STATUS EFIAPI efi_usb_get_string_descriptor ( EFI_USB_IO_PROTOCOL usbio,
UINT16  language,
UINT8  index,
CHAR16 **  string 
)
static

Get string descriptor.

Parameters
usbioUSB I/O protocol
languageLanguage ID
indexString index
Return values
stringString
efircEFI status code

Definition at line 954 of file efi_usb.c.

955  {
957  struct efi_usb_interface *usbintf =
959  struct efi_usb_device *usbdev = usbintf->usbdev;
961  struct efi_saved_tpl tpl;
962  VOID *buffer;
963  size_t len;
964  EFI_STATUS efirc;
965  int rc;
966 
967  DBGC2 ( usbdev, "USBDEV %s get string %d:%d descriptor\n",
968  usbintf->name, language, index );
969 
970  /* Raise TPL */
971  efi_raise_tpl ( &tpl );
972 
973  /* Read descriptor header */
974  if ( ( rc = usb_get_descriptor ( usbdev->func->usb, 0,
976  language, &header,
977  sizeof ( header ) ) ) != 0 ) {
978  DBGC ( usbdev, "USBDEV %s could not get string %d:%d "
979  "descriptor header: %s\n", usbintf->name, language,
980  index, strerror ( rc ) );
981  goto err_get_header;
982  }
983  len = header.len;
984  if ( len < sizeof ( header ) ) {
985  DBGC ( usbdev, "USBDEV %s underlength string %d:%d\n",
986  usbintf->name, language, index );
987  rc = -EINVAL;
988  goto err_len;
989  }
990 
991  /* Allocate buffer */
992  if ( ( efirc = bs->AllocatePool ( EfiBootServicesData, len,
993  &buffer ) ) != 0 ) {
994  rc = -EEFI ( efirc );
995  goto err_alloc;
996  }
997 
998  /* Read whole descriptor */
999  if ( ( rc = usb_get_descriptor ( usbdev->func->usb, 0,
1001  language, buffer, len ) ) != 0 ) {
1002  DBGC ( usbdev, "USBDEV %s could not get string %d:%d "
1003  "descriptor: %s\n", usbintf->name, language,
1004  index, strerror ( rc ) );
1005  goto err_get_descriptor;
1006  }
1007 
1008  /* Shuffle down and terminate string */
1009  memmove ( buffer, ( buffer + sizeof ( header ) ),
1010  ( len - sizeof ( header ) ) );
1011  memset ( ( buffer + len - sizeof ( header ) ), 0, sizeof ( **string ) );
1012 
1013  /* Restore TPL */
1014  efi_restore_tpl ( &tpl );
1015 
1016  /* Return allocated string */
1017  *string = buffer;
1018  return 0;
1019 
1020  err_get_descriptor:
1021  bs->FreePool ( buffer );
1022  err_alloc:
1023  err_len:
1024  err_get_header:
1025  efi_restore_tpl ( &tpl );
1026  return EFIRC ( rc );
1027 }
EFI_BOOT_SERVICES * BootServices
A pointer to the EFI Boot Services Table.
Definition: UefiSpec.h:2000
#define EINVAL
Invalid argument.
Definition: errno.h:428
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
#define EEFI(efirc)
Convert an EFI status code to an iPXE status code.
Definition: efi.h:162
char name[32]
Name.
Definition: efi_usb.h:35
struct usb_function * func
The underlying USB function.
Definition: efi_usb.h:21
#define USB_STRING_DESCRIPTOR
A USB string descriptor.
Definition: usb.h:224
void efi_raise_tpl(struct efi_saved_tpl *tpl)
Raise task priority level to internal level.
Definition: efi_init.c:394
#define DBGC(...)
Definition: compiler.h:505
uint32_t buffer
Buffer index (or NETVSC_RNDIS_NO_BUFFER)
Definition: netvsc.h:16
An EFI USB device.
Definition: efi_usb.h:17
An EFI USB device interface.
Definition: efi_usb.h:33
#define container_of(ptr, type, field)
Get containing structure.
Definition: stddef.h:35
char * strerror(int errno)
Retrieve string representation of error number.
Definition: strerror.c:78
EFI Boot Services Table.
Definition: UefiSpec.h:1836
struct usb_device * usb
USB device.
Definition: usb.h:663
#define VOID
Undeclared type.
Definition: Base.h:319
EFI_FREE_POOL FreePool
Definition: UefiSpec.h:1855
void * memmove(void *dest, const void *src, size_t len) __nonnull
A USB descriptor header.
Definition: usb.h:158
EFI_USB_IO_PROTOCOL usbio
USB I/O protocol.
Definition: efi_usb.h:48
An EFI saved task priority level.
Definition: efi.h:67
uint32_t len
Length.
Definition: ena.h:14
#define DBGC2(...)
Definition: compiler.h:522
RETURN_STATUS EFI_STATUS
Function return status for EFI API.
Definition: UefiBaseType.h:35
struct ena_aq_header header
Header.
Definition: ena.h:12
EFI_SYSTEM_TABLE * efi_systab
static int usb_get_descriptor(struct usb_device *usb, unsigned int type, unsigned int desc, unsigned int index, unsigned int language, struct usb_descriptor_header *data, size_t len)
Get USB descriptor.
Definition: usb.h:1156
uint64_t index
Index of the first segment within the content.
Definition: pccrc.h:21
The data portions of a loaded Boot Serves Driver, and the default data allocation type used by a Boot...
struct efi_usb_device * usbdev
Containing USB device.
Definition: efi_usb.h:37
void efi_restore_tpl(struct efi_saved_tpl *tpl)
Restore task priority level.
Definition: efi_init.c:410
#define EFIRC(rc)
Convert an iPXE status code to an EFI status code.
Definition: efi.h:154
EFI_ALLOCATE_POOL AllocatePool
Definition: UefiSpec.h:1854
void * memset(void *dest, int character, size_t len) __nonnull

References EFI_BOOT_SERVICES::AllocatePool, EFI_SYSTEM_TABLE::BootServices, buffer, container_of, DBGC, DBGC2, EEFI, efi_raise_tpl(), efi_restore_tpl(), efi_systab, EfiBootServicesData, EFIRC, EINVAL, EFI_BOOT_SERVICES::FreePool, efi_usb_device::func, header, index, len, memmove(), memset(), efi_usb_interface::name, rc, strerror(), usb_function::usb, usb_get_descriptor(), USB_STRING_DESCRIPTOR, efi_usb_interface::usbdev, efi_usb_interface::usbio, and VOID.

◆ efi_usb_get_supported_languages()

static EFI_STATUS EFIAPI efi_usb_get_supported_languages ( EFI_USB_IO_PROTOCOL usbio,
UINT16 **  languages,
UINT16 len 
)
static

Get supported languages.

Parameters
usbioUSB I/O protocol
Return values
languagesLanguage ID table
lenLength of language ID table
efircEFI status code

Definition at line 1038 of file efi_usb.c.

1039  {
1040  struct efi_usb_interface *usbintf =
1042  struct efi_usb_device *usbdev = usbintf->usbdev;
1043 
1044  DBGC2 ( usbdev, "USBDEV %s get supported languages\n", usbintf->name );
1045 
1046  /* Return cached supported languages */
1047  *languages = usbdev->lang;
1048  *len = usbdev->lang_len;
1049 
1050  return 0;
1051 }
uint16_t * lang
Supported languages.
Definition: efi_usb.h:25
size_t lang_len
Length of supported languages.
Definition: efi_usb.h:27
char name[32]
Name.
Definition: efi_usb.h:35
An EFI USB device.
Definition: efi_usb.h:17
An EFI USB device interface.
Definition: efi_usb.h:33
#define container_of(ptr, type, field)
Get containing structure.
Definition: stddef.h:35
EFI_USB_IO_PROTOCOL usbio
USB I/O protocol.
Definition: efi_usb.h:48
uint32_t len
Length.
Definition: ena.h:14
#define DBGC2(...)
Definition: compiler.h:522
struct efi_usb_device * usbdev
Containing USB device.
Definition: efi_usb.h:37

References container_of, DBGC2, efi_usb_device::lang, efi_usb_device::lang_len, len, efi_usb_interface::name, efi_usb_interface::usbdev, and efi_usb_interface::usbio.

◆ efi_usb_port_reset()

static EFI_STATUS EFIAPI efi_usb_port_reset ( EFI_USB_IO_PROTOCOL usbio)
static

Reset port.

Parameters
usbioUSB I/O protocol
Return values
efircEFI status code

Definition at line 1060 of file efi_usb.c.

1060  {
1061  struct efi_usb_interface *usbintf =
1063  struct efi_usb_device *usbdev = usbintf->usbdev;
1064 
1065  DBGC2 ( usbdev, "USBDEV %s reset port\n", usbintf->name );
1066 
1067  /* This is logically impossible to do, since resetting the
1068  * port may destroy state belonging to other
1069  * EFI_USB_IO_PROTOCOL instances belonging to the same USB
1070  * device. (This is yet another artifact of the incredibly
1071  * poor design of the EFI_USB_IO_PROTOCOL.)
1072  */
1073  return EFI_INVALID_PARAMETER;
1074 }
char name[32]
Name.
Definition: efi_usb.h:35
An EFI USB device.
Definition: efi_usb.h:17
An EFI USB device interface.
Definition: efi_usb.h:33
#define container_of(ptr, type, field)
Get containing structure.
Definition: stddef.h:35
#define EFI_INVALID_PARAMETER
Enumeration of EFI_STATUS.
Definition: UefiBaseType.h:122
EFI_USB_IO_PROTOCOL usbio
USB I/O protocol.
Definition: efi_usb.h:48
#define DBGC2(...)
Definition: compiler.h:522
struct efi_usb_device * usbdev
Containing USB device.
Definition: efi_usb.h:37

References container_of, DBGC2, EFI_INVALID_PARAMETER, efi_usb_interface::name, efi_usb_interface::usbdev, and efi_usb_interface::usbio.

◆ efi_usb_install()

static int efi_usb_install ( struct efi_usb_device usbdev,
unsigned int  interface 
)
static

Install interface.

Parameters
usbdevEFI USB device
interfaceInterface number
Return values
rcReturn status code

Definition at line 1107 of file efi_usb.c.

1108  {
1110  struct usb_function *func = usbdev->func;
1111  struct efi_usb_interface *usbintf;
1112  int leak = 0;
1113  EFI_STATUS efirc;
1114  int rc;
1115 
1116  /* Allocate and initialise structure */
1117  usbintf = zalloc ( sizeof ( *usbintf ) );
1118  if ( ! usbintf ) {
1119  rc = -ENOMEM;
1120  goto err_alloc;
1121  }
1122  snprintf ( usbintf->name, sizeof ( usbintf->name ), "%s[%d]",
1123  usbdev->name, interface );
1124  usbintf->usbdev = usbdev;
1125  usbintf->interface = interface;
1126  memcpy ( &usbintf->usbio, &efi_usb_io_protocol,
1127  sizeof ( usbintf->usbio ) );
1128 
1129  /* Construct device path */
1130  usbintf->path = efi_usb_path ( func );
1131  if ( ! usbintf->path ) {
1132  rc = -ENODEV;
1133  goto err_path;
1134  }
1135 
1136  /* Add to list of interfaces */
1137  list_add_tail ( &usbintf->list, &usbdev->interfaces );
1138 
1139  /* Install protocols */
1140  if ( ( efirc = bs->InstallMultipleProtocolInterfaces (
1141  &usbintf->handle,
1142  &efi_usb_io_protocol_guid, &usbintf->usbio,
1144  NULL ) ) != 0 ) {
1145  rc = -EEFI ( efirc );
1146  DBGC ( usbdev, "USBDEV %s could not install protocols: %s\n",
1147  usbintf->name, strerror ( rc ) );
1148  goto err_install_protocol;
1149  }
1150 
1151  DBGC ( usbdev, "USBDEV %s installed as %s\n",
1152  usbintf->name, efi_handle_name ( usbintf->handle ) );
1153  return 0;
1154 
1155  if ( ( efirc = bs->UninstallMultipleProtocolInterfaces (
1156  usbintf->handle,
1157  &efi_usb_io_protocol_guid, &usbintf->usbio,
1159  NULL ) ) != 0 ) {
1160  DBGC ( usbdev, "USBDEV %s could not uninstall: %s\n",
1161  usbintf->name, strerror ( -EEFI ( efirc ) ) );
1162  leak = 1;
1163  }
1164  efi_nullify_usbio ( &usbintf->usbio );
1165  err_install_protocol:
1166  efi_usb_close_all ( usbintf );
1167  efi_usb_free_all ( usbintf );
1168  list_del ( &usbintf->list );
1169  if ( ! leak )
1170  free ( usbintf->path );
1171  err_path:
1172  if ( ! leak )
1173  free ( usbintf );
1174  err_alloc:
1175  if ( leak ) {
1176  DBGC ( usbdev, "USBDEV %s nullified and leaked\n",
1177  usbintf->name );
1178  }
1179  return rc;
1180 }
EFI_BOOT_SERVICES * BootServices
A pointer to the EFI Boot Services Table.
Definition: UefiSpec.h:2000
static EFI_USB_IO_PROTOCOL efi_usb_io_protocol
USB I/O protocol.
Definition: efi_usb.c:1077
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
#define EEFI(efirc)
Convert an EFI status code to an iPXE status code.
Definition: efi.h:162
static void efi_usb_close_all(struct efi_usb_interface *usbintf)
Close all endpoints.
Definition: efi_usb.c:248
char name[32]
Name.
Definition: efi_usb.h:35
struct usb_function * func
The underlying USB function.
Definition: efi_usb.h:21
const char * name
Name.
Definition: efi_usb.h:19
EFI_DEVICE_PATH_PROTOCOL * path
Device path.
Definition: efi_usb.h:50
#define DBGC(...)
Definition: compiler.h:505
EFI_INSTALL_MULTIPLE_PROTOCOL_INTERFACES InstallMultipleProtocolInterfaces
Definition: UefiSpec.h:1915
#define list_del(list)
Delete an entry from a list.
Definition: list.h:119
#define ENOMEM
Not enough space.
Definition: errno.h:534
An EFI USB device interface.
Definition: efi_usb.h:33
void * memcpy(void *dest, const void *src, size_t len) __nonnull
An object interface.
Definition: interface.h:124
void efi_nullify_usbio(EFI_USB_IO_PROTOCOL *usbio)
Nullify USB I/O protocol.
Definition: efi_null.c:669
#define list_add_tail(new, head)
Add a new entry to the tail of a list.
Definition: list.h:93
struct list_head interfaces
List of interfaces.
Definition: efi_usb.h:29
const char * efi_handle_name(EFI_HANDLE handle)
Get name of an EFI handle.
Definition: efi_debug.c:722
unsigned int interface
Interface number.
Definition: efi_usb.h:42
char * strerror(int errno)
Retrieve string representation of error number.
Definition: strerror.c:78
EFI_GUID efi_usb_io_protocol_guid
USB I/O protocol GUID.
Definition: efi_guid.c:296
static void(* free)(struct refcnt *refcnt))
Definition: refcnt.h:54
EFI_DEVICE_PATH_PROTOCOL * efi_usb_path(struct usb_function *func)
Construct EFI device path for USB function.
Definition: efi_path.c:435
void * zalloc(size_t size)
Allocate cleared memory.
Definition: malloc.c:624
EFI Boot Services Table.
Definition: UefiSpec.h:1836
EFI_UNINSTALL_MULTIPLE_PROTOCOL_INTERFACES UninstallMultipleProtocolInterfaces
Definition: UefiSpec.h:1916
#define ENODEV
No such device.
Definition: errno.h:509
static void efi_usb_free_all(struct efi_usb_interface *usbintf)
Free all endpoints.
Definition: efi_usb.c:265
EFI_GUID efi_device_path_protocol_guid
Device path protocol GUID.
Definition: efi_guid.c:132
EFI_USB_IO_PROTOCOL usbio
USB I/O protocol.
Definition: efi_usb.h:48
struct list_head list
List of interfaces.
Definition: efi_usb.h:39
RETURN_STATUS EFI_STATUS
Function return status for EFI API.
Definition: UefiBaseType.h:35
EFI_HANDLE handle
EFI handle.
Definition: efi_usb.h:46
int snprintf(char *buf, size_t size, const char *fmt,...)
Write a formatted string to a buffer.
Definition: vsprintf.c:382
EFI_SYSTEM_TABLE * efi_systab
A USB function.
Definition: usb.h:659
struct efi_usb_device * usbdev
Containing USB device.
Definition: efi_usb.h:37
#define NULL
NULL pointer (VOID *)
Definition: Base.h:362

References EFI_SYSTEM_TABLE::BootServices, DBGC, EEFI, efi_device_path_protocol_guid, efi_handle_name(), efi_nullify_usbio(), efi_systab, efi_usb_close_all(), efi_usb_free_all(), efi_usb_io_protocol, efi_usb_io_protocol_guid, efi_usb_path(), ENODEV, ENOMEM, free, efi_usb_device::func, efi_usb_interface::handle, EFI_BOOT_SERVICES::InstallMultipleProtocolInterfaces, efi_usb_interface::interface, efi_usb_device::interfaces, efi_usb_interface::list, list_add_tail, list_del, memcpy(), efi_usb_device::name, efi_usb_interface::name, NULL, efi_usb_interface::path, rc, snprintf(), strerror(), EFI_BOOT_SERVICES::UninstallMultipleProtocolInterfaces, efi_usb_interface::usbdev, efi_usb_interface::usbio, and zalloc().

Referenced by efi_usb_probe().

◆ efi_usb_uninstall()

static void efi_usb_uninstall ( struct efi_usb_interface usbintf)
static

Uninstall interface.

Parameters
usbintfEFI USB interface

Definition at line 1187 of file efi_usb.c.

1187  {
1189  struct efi_usb_device *usbdev = usbintf->usbdev;
1190  int leak = efi_shutdown_in_progress;
1191  EFI_STATUS efirc;
1192 
1193  DBGC ( usbdev, "USBDEV %s uninstalling %s\n",
1194  usbintf->name, efi_handle_name ( usbintf->handle ) );
1195 
1196  /* Disconnect controllers. This should not be necessary, but
1197  * seems to be required on some platforms to avoid failures
1198  * when uninstalling protocols.
1199  */
1200  if ( ! efi_shutdown_in_progress )
1201  bs->DisconnectController ( usbintf->handle, NULL, NULL );
1202 
1203  /* Uninstall protocols */
1204  if ( ( ! efi_shutdown_in_progress ) &&
1205  ( ( efirc = bs->UninstallMultipleProtocolInterfaces (
1206  usbintf->handle,
1207  &efi_usb_io_protocol_guid, &usbintf->usbio,
1209  NULL ) ) != 0 ) ) {
1210  DBGC ( usbdev, "USBDEV %s could not uninstall: %s\n",
1211  usbintf->name, strerror ( -EEFI ( efirc ) ) );
1212  leak = 1;
1213  }
1214  efi_nullify_usbio ( &usbintf->usbio );
1215 
1216  /* Close and free all endpoints */
1217  efi_usb_close_all ( usbintf );
1218  efi_usb_free_all ( usbintf );
1219 
1220  /* Remove from list of interfaces */
1221  list_del ( &usbintf->list );
1222 
1223  /* Free device path */
1224  if ( ! leak )
1225  free ( usbintf->path );
1226 
1227  /* Free interface */
1228  if ( ! leak )
1229  free ( usbintf );
1230 
1231  /* Report leakage, if applicable */
1232  if ( leak && ( ! efi_shutdown_in_progress ) ) {
1233  DBGC ( usbdev, "USBDEV %s nullified and leaked\n",
1234  usbintf->name );
1235  }
1236 }
EFI_BOOT_SERVICES * BootServices
A pointer to the EFI Boot Services Table.
Definition: UefiSpec.h:2000
#define EEFI(efirc)
Convert an EFI status code to an iPXE status code.
Definition: efi.h:162
static void efi_usb_close_all(struct efi_usb_interface *usbintf)
Close all endpoints.
Definition: efi_usb.c:248
char name[32]
Name.
Definition: efi_usb.h:35
EFI_DEVICE_PATH_PROTOCOL * path
Device path.
Definition: efi_usb.h:50
#define DBGC(...)
Definition: compiler.h:505
An EFI USB device.
Definition: efi_usb.h:17
#define list_del(list)
Delete an entry from a list.
Definition: list.h:119
void efi_nullify_usbio(EFI_USB_IO_PROTOCOL *usbio)
Nullify USB I/O protocol.
Definition: efi_null.c:669
const char * efi_handle_name(EFI_HANDLE handle)
Get name of an EFI handle.
Definition: efi_debug.c:722
char * strerror(int errno)
Retrieve string representation of error number.
Definition: strerror.c:78
EFI_GUID efi_usb_io_protocol_guid
USB I/O protocol GUID.
Definition: efi_guid.c:296
static void(* free)(struct refcnt *refcnt))
Definition: refcnt.h:54
EFI Boot Services Table.
Definition: UefiSpec.h:1836
EFI_UNINSTALL_MULTIPLE_PROTOCOL_INTERFACES UninstallMultipleProtocolInterfaces
Definition: UefiSpec.h:1916
static void efi_usb_free_all(struct efi_usb_interface *usbintf)
Free all endpoints.
Definition: efi_usb.c:265
EFI_GUID efi_device_path_protocol_guid
Device path protocol GUID.
Definition: efi_guid.c:132
EFI_USB_IO_PROTOCOL usbio
USB I/O protocol.
Definition: efi_usb.h:48
struct list_head list
List of interfaces.
Definition: efi_usb.h:39
RETURN_STATUS EFI_STATUS
Function return status for EFI API.
Definition: UefiBaseType.h:35
EFI_HANDLE handle
EFI handle.
Definition: efi_usb.h:46
EFI_SYSTEM_TABLE * efi_systab
struct efi_usb_device * usbdev
Containing USB device.
Definition: efi_usb.h:37
#define NULL
NULL pointer (VOID *)
Definition: Base.h:362
int efi_shutdown_in_progress
EFI shutdown is in progress.
Definition: efi_init.c:57
EFI_DISCONNECT_CONTROLLER DisconnectController
Definition: UefiSpec.h:1900

References EFI_SYSTEM_TABLE::BootServices, DBGC, EFI_BOOT_SERVICES::DisconnectController, EEFI, efi_device_path_protocol_guid, efi_handle_name(), efi_nullify_usbio(), efi_shutdown_in_progress, efi_systab, efi_usb_close_all(), efi_usb_free_all(), efi_usb_io_protocol_guid, free, efi_usb_interface::handle, efi_usb_interface::list, list_del, efi_usb_interface::name, NULL, efi_usb_interface::path, strerror(), EFI_BOOT_SERVICES::UninstallMultipleProtocolInterfaces, efi_usb_interface::usbdev, and efi_usb_interface::usbio.

Referenced by efi_usb_uninstall_all().

◆ efi_usb_uninstall_all()

static void efi_usb_uninstall_all ( struct efi_usb_device efiusb)
static

Uninstall all interfaces.

Parameters
usbdevEFI USB device

Definition at line 1243 of file efi_usb.c.

1243  {
1244  struct efi_usb_interface *usbintf;
1245 
1246  /* Uninstall all interfaces */
1247  while ( ( usbintf = list_first_entry ( &efiusb->interfaces,
1248  struct efi_usb_interface,
1249  list ) ) ) {
1250  efi_usb_uninstall ( usbintf );
1251  }
1252 }
#define list_first_entry(list, type, member)
Get the container of the first entry in a list.
Definition: list.h:333
An EFI USB device interface.
Definition: efi_usb.h:33
struct list_head interfaces
List of interfaces.
Definition: efi_usb.h:29
static void efi_usb_uninstall(struct efi_usb_interface *usbintf)
Uninstall interface.
Definition: efi_usb.c:1187
struct list_head list
List of interfaces.
Definition: efi_usb.h:39

References efi_usb_uninstall(), efi_usb_device::interfaces, efi_usb_interface::list, and list_first_entry.

Referenced by efi_usb_probe(), and efi_usb_remove().

◆ efi_usb_probe()

static int efi_usb_probe ( struct usb_function func,
struct usb_configuration_descriptor config 
)
static

Probe device.

Parameters
funcUSB function
configConfiguration descriptor
Return values
rcReturn status code

Definition at line 1261 of file efi_usb.c.

1262  {
1264  struct usb_device *usb = func->usb;
1265  struct efi_usb_device *usbdev;
1266  struct efi_usb_interface *usbintf;
1268  struct usb_descriptor_header *lang;
1269  size_t config_len;
1270  size_t lang_len;
1271  unsigned int i;
1272  int rc;
1273 
1274  /* Get configuration length */
1275  config_len = le16_to_cpu ( config->len );
1276 
1277  /* Get supported languages descriptor header */
1278  if ( ( rc = usb_get_descriptor ( usb, 0, USB_STRING_DESCRIPTOR, 0, 0,
1279  &header, sizeof ( header ) ) ) != 0 ) {
1280  /* Assume no strings are present */
1281  header.len = 0;
1282  }
1283  lang_len = ( ( header.len >= sizeof ( header ) ) ?
1284  ( header.len - sizeof ( header ) ) : 0 );
1285 
1286  /* Allocate and initialise structure */
1287  usbdev = zalloc ( sizeof ( *usbdev ) + config_len +
1288  sizeof ( *lang ) + lang_len );
1289  if ( ! usbdev ) {
1290  rc = -ENOMEM;
1291  goto err_alloc;
1292  }
1293  usb_func_set_drvdata ( func, usbdev );
1294  usbdev->name = func->name;
1295  usbdev->func = func;
1296  usbdev->config = ( ( ( void * ) usbdev ) + sizeof ( *usbdev ) );
1297  memcpy ( usbdev->config, config, config_len );
1298  lang = ( ( ( void * ) usbdev->config ) + config_len );
1299  usbdev->lang = ( ( ( void * ) lang ) + sizeof ( *lang ) );
1300  usbdev->lang_len = lang_len;
1301  INIT_LIST_HEAD ( &usbdev->interfaces );
1302 
1303  /* Get supported languages descriptor, if applicable */
1304  if ( lang_len &&
1306  0, 0, lang, header.len ) ) != 0 ) ) {
1307  DBGC ( usbdev, "USBDEV %s could not get supported languages: "
1308  "%s\n", usbdev->name, strerror ( rc ) );
1309  goto err_get_languages;
1310  }
1311 
1312  /* Install interfaces */
1313  for ( i = 0 ; i < func->desc.count ; i++ ) {
1314  if ( ( rc = efi_usb_install ( usbdev,
1315  func->interface[i] ) ) != 0 )
1316  goto err_install;
1317  }
1318 
1319  /* Connect any external drivers */
1320  list_for_each_entry ( usbintf, &usbdev->interfaces, list )
1321  bs->ConnectController ( usbintf->handle, NULL, NULL, TRUE );
1322 
1323  return 0;
1324 
1325  err_install:
1326  efi_usb_uninstall_all ( usbdev );
1327  assert ( list_empty ( &usbdev->interfaces ) );
1328  err_get_languages:
1329  free ( usbdev );
1330  err_alloc:
1331  return rc;
1332 }
uint16_t * lang
Supported languages.
Definition: efi_usb.h:25
EFI_BOOT_SERVICES * BootServices
A pointer to the EFI Boot Services Table.
Definition: UefiSpec.h:2000
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
size_t lang_len
Length of supported languages.
Definition: efi_usb.h:27
uint8_t interface[0]
List of interface numbers.
Definition: usb.h:682
const char * name
Name.
Definition: usb.h:661
struct usb_function * func
The underlying USB function.
Definition: efi_usb.h:21
unsigned int count
Number of interfaces.
Definition: usb.h:650
#define USB_STRING_DESCRIPTOR
A USB string descriptor.
Definition: usb.h:224
const char * name
Name.
Definition: efi_usb.h:19
#define DBGC(...)
Definition: compiler.h:505
An EFI USB device.
Definition: efi_usb.h:17
#define list_empty(list)
Test whether a list is empty.
Definition: list.h:136
#define ENOMEM
Not enough space.
Definition: errno.h:534
An EFI USB device interface.
Definition: efi_usb.h:33
void * memcpy(void *dest, const void *src, size_t len) __nonnull
assert((readw(&hdr->flags) &(GTF_reading|GTF_writing))==0)
#define list_for_each_entry(pos, head, member)
Iterate over entries in a list.
Definition: list.h:420
static void usb_func_set_drvdata(struct usb_function *func, void *priv)
Set USB function driver private data.
Definition: usb.h:692
struct list_head interfaces
List of interfaces.
Definition: efi_usb.h:29
A USB device.
Definition: usb.h:708
char * strerror(int errno)
Retrieve string representation of error number.
Definition: strerror.c:78
static void(* free)(struct refcnt *refcnt))
Definition: refcnt.h:54
void * zalloc(size_t size)
Allocate cleared memory.
Definition: malloc.c:624
EFI Boot Services Table.
Definition: UefiSpec.h:1836
EFI_CONNECT_CONTROLLER ConnectController
Definition: UefiSpec.h:1899
struct usb_configuration_descriptor * config
Configuration descriptor.
Definition: efi_usb.h:23
static void efi_usb_uninstall_all(struct efi_usb_device *efiusb)
Uninstall all interfaces.
Definition: efi_usb.c:1243
struct usb_device * usb
USB device.
Definition: usb.h:663
#define le16_to_cpu(value)
Definition: byteswap.h:112
#define TRUE
Definition: tlan.h:46
A USB descriptor header.
Definition: usb.h:158
#define INIT_LIST_HEAD(list)
Initialise a list head.
Definition: list.h:45
static int efi_usb_install(struct efi_usb_device *usbdev, unsigned int interface)
Install interface.
Definition: efi_usb.c:1107
EFI_HANDLE handle
EFI handle.
Definition: efi_usb.h:46
struct ena_aq_header header
Header.
Definition: ena.h:12
uint16_t len
Total length.
Definition: usb.h:199
struct usb_function_descriptor desc
Function descriptor.
Definition: usb.h:665
EFI_SYSTEM_TABLE * efi_systab
static int usb_get_descriptor(struct usb_device *usb, unsigned int type, unsigned int desc, unsigned int index, unsigned int language, struct usb_descriptor_header *data, size_t len)
Get USB descriptor.
Definition: usb.h:1156
#define NULL
NULL pointer (VOID *)
Definition: Base.h:362

References assert(), EFI_SYSTEM_TABLE::BootServices, efi_usb_device::config, EFI_BOOT_SERVICES::ConnectController, usb_function_descriptor::count, DBGC, usb_function::desc, efi_systab, efi_usb_install(), efi_usb_uninstall_all(), ENOMEM, free, efi_usb_device::func, efi_usb_interface::handle, header, INIT_LIST_HEAD, usb_function::interface, efi_usb_device::interfaces, efi_usb_device::lang, efi_usb_device::lang_len, le16_to_cpu, usb_configuration_descriptor::len, list_empty, list_for_each_entry, memcpy(), efi_usb_device::name, usb_function::name, NULL, rc, strerror(), TRUE, usb_function::usb, usb_func_set_drvdata(), usb_get_descriptor(), USB_STRING_DESCRIPTOR, and zalloc().

◆ efi_usb_remove()

static void efi_usb_remove ( struct usb_function func)
static

Remove device.

Parameters
funcUSB function

Definition at line 1339 of file efi_usb.c.

1339  {
1340  struct efi_usb_device *usbdev = usb_func_get_drvdata ( func );
1341 
1342  /* Uninstall all interfaces */
1343  efi_usb_uninstall_all ( usbdev );
1344  assert ( list_empty ( &usbdev->interfaces ) );
1345 
1346  /* Free device */
1347  free ( usbdev );
1348 }
static void * usb_func_get_drvdata(struct usb_function *func)
Get USB function driver private data.
Definition: usb.h:703
struct usb_function * func
The underlying USB function.
Definition: efi_usb.h:21
An EFI USB device.
Definition: efi_usb.h:17
#define list_empty(list)
Test whether a list is empty.
Definition: list.h:136
assert((readw(&hdr->flags) &(GTF_reading|GTF_writing))==0)
struct list_head interfaces
List of interfaces.
Definition: efi_usb.h:29
static void(* free)(struct refcnt *refcnt))
Definition: refcnt.h:54
static void efi_usb_uninstall_all(struct efi_usb_device *efiusb)
Uninstall all interfaces.
Definition: efi_usb.c:1243

References assert(), efi_usb_uninstall_all(), free, efi_usb_device::func, efi_usb_device::interfaces, list_empty, and usb_func_get_drvdata().

Variable Documentation

◆ efi_usb_sync_driver

struct usb_endpoint_driver_operations efi_usb_sync_driver
static
Initial value:
= {
.complete = efi_usb_sync_complete,
}
static void efi_usb_sync_complete(struct usb_endpoint *ep, struct io_buffer *iobuf __unused, int rc)
Complete synchronous transfer.
Definition: efi_usb.c:287

Synchronous endpoint operations.

Definition at line 297 of file efi_usb.c.

Referenced by efi_usb_sync_transfer().

◆ efi_usb_async_driver

struct usb_endpoint_driver_operations efi_usb_async_driver
static
Initial value:
= {
}
static void efi_usb_async_complete(struct usb_endpoint *ep, struct io_buffer *iobuf, int rc)
Complete asynchronous transfer.
Definition: efi_usb.c:405

Asynchronous endpoint operations.

Definition at line 434 of file efi_usb.c.

Referenced by efi_usb_async_start().

◆ efi_usb_io_protocol

EFI_USB_IO_PROTOCOL efi_usb_io_protocol
static
Initial value:
= {
.UsbControlTransfer = efi_usb_control_transfer,
.UsbBulkTransfer = efi_usb_bulk_transfer,
.UsbAsyncInterruptTransfer = efi_usb_async_interrupt_transfer,
.UsbSyncInterruptTransfer = efi_usb_sync_interrupt_transfer,
.UsbIsochronousTransfer = efi_usb_isochronous_transfer,
.UsbAsyncIsochronousTransfer = efi_usb_async_isochronous_transfer,
.UsbGetDeviceDescriptor = efi_usb_get_device_descriptor,
.UsbGetConfigDescriptor = efi_usb_get_config_descriptor,
.UsbGetInterfaceDescriptor = efi_usb_get_interface_descriptor,
.UsbGetEndpointDescriptor = efi_usb_get_endpoint_descriptor,
.UsbGetStringDescriptor = efi_usb_get_string_descriptor,
.UsbGetSupportedLanguages = efi_usb_get_supported_languages,
.UsbPortReset = efi_usb_port_reset,
}
static EFI_STATUS EFIAPI efi_usb_get_interface_descriptor(EFI_USB_IO_PROTOCOL *usbio, EFI_USB_INTERFACE_DESCRIPTOR *efidesc)
Get interface descriptor.
Definition: efi_usb.c:879
static EFI_STATUS EFIAPI efi_usb_get_config_descriptor(EFI_USB_IO_PROTOCOL *usbio, EFI_USB_CONFIG_DESCRIPTOR *efidesc)
Get configuration descriptor.
Definition: efi_usb.c:856
static EFI_STATUS EFIAPI efi_usb_sync_interrupt_transfer(EFI_USB_IO_PROTOCOL *usbio, UINT8 endpoint, VOID *data, UINTN *len, UINTN timeout, UINT32 *status)
Perform synchronous interrupt transfer.
Definition: efi_usb.c:679
static EFI_STATUS EFIAPI efi_usb_port_reset(EFI_USB_IO_PROTOCOL *usbio)
Reset port.
Definition: efi_usb.c:1060
static EFI_STATUS EFIAPI efi_usb_control_transfer(EFI_USB_IO_PROTOCOL *usbio, EFI_USB_DEVICE_REQUEST *packet, EFI_USB_DATA_DIRECTION direction, UINT32 timeout, VOID *data, UINTN len, UINT32 *status)
Perform control transfer.
Definition: efi_usb.c:552
static EFI_STATUS EFIAPI efi_usb_async_isochronous_transfer(EFI_USB_IO_PROTOCOL *usbio, UINT8 endpoint, VOID *data, UINTN len, EFI_ASYNC_USB_TRANSFER_CALLBACK callback, VOID *context)
Perform asynchronous isochronous transfers.
Definition: efi_usb.c:810
static EFI_STATUS EFIAPI efi_usb_get_string_descriptor(EFI_USB_IO_PROTOCOL *usbio, UINT16 language, UINT8 index, CHAR16 **string)
Get string descriptor.
Definition: efi_usb.c:954
static EFI_STATUS EFIAPI efi_usb_get_endpoint_descriptor(EFI_USB_IO_PROTOCOL *usbio, UINT8 index, EFI_USB_ENDPOINT_DESCRIPTOR *efidesc)
Get endpoint descriptor.
Definition: efi_usb.c:912
static EFI_STATUS EFIAPI efi_usb_isochronous_transfer(EFI_USB_IO_PROTOCOL *usbio, UINT8 endpoint, VOID *data, UINTN len, UINT32 *status)
Perform synchronous isochronous transfer.
Definition: efi_usb.c:780
static EFI_STATUS EFIAPI efi_usb_get_device_descriptor(EFI_USB_IO_PROTOCOL *usbio, EFI_USB_DEVICE_DESCRIPTOR *efidesc)
Get device descriptor.
Definition: efi_usb.c:834
static EFI_STATUS EFIAPI efi_usb_bulk_transfer(EFI_USB_IO_PROTOCOL *usbio, UINT8 endpoint, VOID *data, UINTN *len, UINTN timeout, UINT32 *status)
Perform bulk transfer.
Definition: efi_usb.c:634
static EFI_STATUS EFIAPI efi_usb_get_supported_languages(EFI_USB_IO_PROTOCOL *usbio, UINT16 **languages, UINT16 *len)
Get supported languages.
Definition: efi_usb.c:1038
static EFI_STATUS EFIAPI efi_usb_async_interrupt_transfer(EFI_USB_IO_PROTOCOL *usbio, UINT8 endpoint, BOOLEAN start, UINTN interval, UINTN len, EFI_ASYNC_USB_TRANSFER_CALLBACK callback, VOID *context)
Perform asynchronous interrupt transfer.
Definition: efi_usb.c:726

USB I/O protocol.

Definition at line 1077 of file efi_usb.c.

Referenced by efi_usb_install().

◆ efi_usb_ids

struct usb_device_id efi_usb_ids[]
static
Initial value:
= {
{
.name = "usbio",
.vendor = USB_ANY_ID,
.product = USB_ANY_ID,
},
}
#define USB_ANY_ID
Match-anything ID.
Definition: usb.h:1347

USB I/O protocol device IDs.

Definition at line 1351 of file efi_usb.c.

◆ __usb_fallback_driver

struct usb_driver usbio_driver __usb_fallback_driver
Initial value:
= {
.ids = efi_usb_ids,
.id_count = ( sizeof ( efi_usb_ids ) / sizeof ( efi_usb_ids[0] ) ),
.probe = efi_usb_probe,
.remove = efi_usb_remove,
}
static void efi_usb_remove(struct usb_function *func)
Remove device.
Definition: efi_usb.c:1339
static struct usb_device_id efi_usb_ids[]
USB I/O protocol device IDs.
Definition: efi_usb.c:1351
static int efi_usb_probe(struct usb_function *func, struct usb_configuration_descriptor *config)
Probe device.
Definition: efi_usb.c:1261
#define USB_CLASS_ID(base, subclass, protocol)
Construct USB class ID.
Definition: usb.h:1363
#define USB_ANY_ID
Match-anything ID.
Definition: usb.h:1347
Fallback driver (has no effect on overall score)
Definition: usb.h:1423

USB I/O protocol driver.

Definition at line 1360 of file efi_usb.c.