iPXE
Functions | Variables
usb_settings.c File Reference

USB device settings. More...

#include <stdio.h>
#include <string.h>
#include <errno.h>
#include <ipxe/usb.h>
#include <ipxe/settings.h>
#include <ipxe/init.h>

Go to the source code of this file.

Functions

 FILE_LICENCE (GPL2_OR_LATER_OR_UBDL)
 
static int usb_settings_applies (struct settings *settings __unused, const struct setting *setting)
 Check applicability of USB device setting. More...
 
static int usb_settings_fetch (struct settings *settings __unused, struct setting *setting, void *data, size_t len)
 Fetch value of USB device setting. More...
 
static void usb_settings_init (void)
 Initialise USB device settings. More...
 
struct init_fn usb_settings_init_fn __init_fn (INIT_NORMAL)
 USB device settings initialiser. More...
 

Variables

static const struct settings_scope usb_settings_scope
 USB device settings scope. More...
 
static struct settings_operations usb_settings_operations
 USB device settings operations. More...
 
static struct settings usb_settings
 USB device settings. More...
 

Detailed Description

USB device settings.

Definition in file usb_settings.c.

Function Documentation

◆ FILE_LICENCE()

FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL  )

◆ usb_settings_applies()

static int usb_settings_applies ( struct settings *settings  __unused,
const struct setting setting 
)
static

Check applicability of USB device setting.

Parameters
settingsSettings block
settingSetting
Return values
appliesSetting applies within this settings block

Definition at line 49 of file usb_settings.c.

50  {
51 
52  return ( setting->scope == &usb_settings_scope );
53 }
A setting.
Definition: settings.h:23
const struct settings_scope * scope
Setting scope (or NULL)
Definition: settings.h:49
static const struct settings_scope usb_settings_scope
USB device settings scope.
Definition: usb_settings.c:40

References setting::scope, and usb_settings_scope.

◆ usb_settings_fetch()

static int usb_settings_fetch ( struct settings *settings  __unused,
struct setting setting,
void *  data,
size_t  len 
)
static

Fetch value of USB device setting.

Parameters
settingsSettings block
settingSetting to fetch
dataBuffer to fill with setting data
lenLength of buffer
Return values
lenLength of setting data, or negative error

Definition at line 64 of file usb_settings.c.

66  {
67  uint8_t *dst = data;
68  const uint8_t *src;
69  const uint8_t *desc;
70  struct usb_bus *bus;
71  struct usb_device *usb;
72  int tag_direction;
73  unsigned int tag_busdev;
74  unsigned int tag_offset;
75  unsigned int tag_len;
76  unsigned int index;
77  int rc;
78 
79  /* Extract parameters from tag */
80  tag_direction = ( ( setting->tag & ( 1 << 31 ) ) ? +1 : -1 );
81  tag_busdev = ( ( setting->tag >> 16 ) & 0x7fff );
82  tag_offset = ( ( setting->tag >> 8 ) & 0xff );
83  tag_len = ( ( setting->tag >> 0 ) & 0xff );
84 
85  /* Locate USB device */
86  bus = find_usb_bus ( USB_BUS ( tag_busdev ) );
87  if ( ! bus )
88  return -ENODEV;
89  usb = find_usb ( bus, USB_DEV ( tag_busdev ) );
90  if ( ! usb )
91  return -ENODEV;
92  desc = ( ( const uint8_t * ) &usb->device );
93 
94  /* Following the usage of SMBIOS settings tags, a <length> of
95  * zero indicates that the byte at <offset> contains a string
96  * index. An <offset> of zero indicates that the <length>
97  * contains a literal string index.
98  *
99  * Since the byte at offset zero can never contain a string
100  * index, and a literal string index can never be zero, the
101  * combination of both <length> and <offset> being zero
102  * indicates that the entire structure is to be read.
103  *
104  * By default we reverse the byte direction since USB values
105  * are little-endian and iPXE settings are big-endian. We
106  * invert this default when reading the entire structure.
107  */
108  if ( ( tag_len == 0 ) && ( tag_offset == 0 ) ) {
109  tag_len = sizeof ( usb->device );
110  tag_direction = -tag_direction;
111  } else if ( ( tag_len == 0 ) || ( tag_offset == 0 ) ) {
112  index = tag_len;
113  if ( ( ! index ) && ( tag_offset < sizeof ( usb->device ) ) )
114  index = desc[tag_offset];
115  if ( ( rc = usb_get_string_descriptor ( usb, index, 0, data,
116  len ) ) < 0 ) {
117  return rc;
118  }
119  if ( ! setting->type )
120  setting->type = &setting_type_string;
121  return rc;
122  }
123 
124  /* Limit length */
125  if ( tag_offset > sizeof ( usb->device ) ) {
126  tag_len = 0;
127  } else if ( ( tag_offset + tag_len ) > sizeof ( usb->device ) ) {
128  tag_len = ( sizeof ( usb->device ) - tag_offset );
129  }
130 
131  /* Copy data, reversing endianness if applicable */
132  dst = data;
133  src = ( desc + tag_offset );
134  if ( tag_direction < 0 )
135  src += ( tag_len - 1 );
136  if ( len > tag_len )
137  len = tag_len;
138  for ( ; len-- ; src += tag_direction, dst++ )
139  *dst = *src;
140 
141  /* Set type to ":hexraw" if not already specified */
142  if ( ! setting->type )
143  setting->type = &setting_type_hexraw;
144 
145  return tag_len;
146 }
#define USB_BUS(busdev)
Extract USB bus address.
Definition: usb.h:66
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
struct usb_bus * find_usb_bus(unsigned int address)
Find USB bus by address.
Definition: usb.c:2219
struct usb_device * find_usb(struct usb_bus *bus, unsigned int address)
Find USB device by address.
Definition: usb.c:1734
long index
Definition: bigint.h:62
uint64_t tag
Setting tag, if applicable.
Definition: settings.h:43
struct ena_llq_option desc
Descriptor counts.
Definition: ena.h:20
static const void * src
Definition: string.h:47
ring len
Length.
Definition: dwmac.h:231
const struct setting_type * type
Setting type.
Definition: settings.h:36
A USB device.
Definition: usb.h:722
#define ENODEV
No such device.
Definition: errno.h:509
unsigned char uint8_t
Definition: stdint.h:10
struct usb_device_descriptor device
Device descriptor.
Definition: usb.h:734
A setting.
Definition: settings.h:23
uint8_t data[48]
Additional event data.
Definition: ena.h:22
A USB bus.
Definition: usb.h:965
uint8_t bus
Bus.
Definition: edd.h:14
int usb_get_string_descriptor(struct usb_device *usb, unsigned int index, unsigned int language, char *buf, size_t len)
Get USB string descriptor.
Definition: usb.c:915
#define USB_DEV(busdev)
Extract USB device address.
Definition: usb.h:69

References bus, data, desc, usb_device::device, ENODEV, find_usb(), find_usb_bus(), index, len, rc, src, setting::tag, setting::type, USB_BUS, USB_DEV, and usb_get_string_descriptor().

◆ usb_settings_init()

static void usb_settings_init ( void  )
static

Initialise USB device settings.

Definition at line 164 of file usb_settings.c.

164  {
165  int rc;
166 
167  if ( ( rc = register_settings ( &usb_settings, NULL, "usb" ) ) != 0 ) {
168  DBG ( "USB could not register settings: %s\n",
169  strerror ( rc ) );
170  return;
171  }
172 }
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
char * strerror(int errno)
Retrieve string representation of error number.
Definition: strerror.c:78
int register_settings(struct settings *settings, struct settings *parent, const char *name)
Register settings block.
Definition: settings.c:475
#define DBG(...)
Print a debugging message.
Definition: compiler.h:498
#define NULL
NULL pointer (VOID *)
Definition: Base.h:321
static struct settings usb_settings
USB device settings.
Definition: usb_settings.c:155

References DBG, NULL, rc, register_settings(), strerror(), and usb_settings.

◆ __init_fn()

struct init_fn usb_settings_init_fn __init_fn ( INIT_NORMAL  )

USB device settings initialiser.

Variable Documentation

◆ usb_settings_scope

const struct settings_scope usb_settings_scope
static

USB device settings scope.

Definition at line 40 of file usb_settings.c.

Referenced by usb_settings_applies().

◆ usb_settings_operations

struct settings_operations usb_settings_operations
static
Initial value:
= {
}
static int usb_settings_applies(struct settings *settings __unused, const struct setting *setting)
Check applicability of USB device setting.
Definition: usb_settings.c:49
static int usb_settings_fetch(struct settings *settings __unused, struct setting *setting, void *data, size_t len)
Fetch value of USB device setting.
Definition: usb_settings.c:64

USB device settings operations.

Definition at line 149 of file usb_settings.c.

◆ usb_settings

struct settings usb_settings
static
Initial value:
= {
.refcnt = NULL,
.default_scope = &usb_settings_scope,
}
struct list_head siblings
Sibling settings blocks.
Definition: settings.h:140
static struct settings_operations usb_settings_operations
USB device settings operations.
Definition: usb_settings.c:149
struct list_head children
Child settings blocks.
Definition: settings.h:142
#define LIST_HEAD_INIT(list)
Initialise a static list head.
Definition: list.h:30
static const struct settings_scope usb_settings_scope
USB device settings scope.
Definition: usb_settings.c:40
#define NULL
NULL pointer (VOID *)
Definition: Base.h:321
static struct settings usb_settings
USB device settings.
Definition: usb_settings.c:155

USB device settings.

Definition at line 155 of file usb_settings.c.

Referenced by usb_settings_init().