iPXE
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)
 FILE_SECBOOT (PERMITTED)
static int usb_settings_applies (struct settings *settings __unused, const struct setting *setting)
 Check applicability of USB device setting.
static int usb_settings_fetch (struct settings *settings __unused, struct setting *setting, void *data, size_t len)
 Fetch value of USB device setting.
static void usb_settings_init (void)
 Initialise USB device settings.
struct init_fn usb_settings_init_fn __init_fn (INIT_NORMAL)
 USB device settings initialiser.

Variables

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

Detailed Description

USB device settings.

Definition in file usb_settings.c.

Function Documentation

◆ FILE_LICENCE()

FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL )

◆ FILE_SECBOOT()

FILE_SECBOOT ( PERMITTED )

◆ usb_settings_applies()

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 50 of file usb_settings.c.

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

References __unused, setting::scope, and usb_settings_scope.

◆ usb_settings_fetch()

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 65 of file usb_settings.c.

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

References __unused, 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()

void usb_settings_init ( void )
static

Initialise USB device settings.

Definition at line 165 of file usb_settings.c.

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

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

Referenced by __init_fn().

◆ __init_fn()

struct init_fn usb_settings_init_fn __init_fn ( INIT_NORMAL )

USB device settings initialiser.

References __init_fn, INIT_NORMAL, and usb_settings_init().

Variable Documentation

◆ usb_settings_scope

const struct settings_scope usb_settings_scope
static

USB device settings scope.

Definition at line 41 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.
static int usb_settings_fetch(struct settings *settings __unused, struct setting *setting, void *data, size_t len)
Fetch value of USB device setting.

USB device settings operations.

Definition at line 150 of file usb_settings.c.

150 {
151 .applies = usb_settings_applies,
152 .fetch = usb_settings_fetch,
153};

◆ usb_settings

struct settings usb_settings
static
Initial value:
= {
.refcnt = NULL,
.siblings = LIST_HEAD_INIT ( usb_settings.siblings ),
.children = LIST_HEAD_INIT ( usb_settings.children ),
.default_scope = &usb_settings_scope,
}
#define LIST_HEAD_INIT(list)
Initialise a static list head.
Definition list.h:31
static struct settings_operations usb_settings_operations
USB device settings operations.

USB device settings.

Definition at line 156 of file usb_settings.c.

156 {
157 .refcnt = NULL,
158 .siblings = LIST_HEAD_INIT ( usb_settings.siblings ),
159 .children = LIST_HEAD_INIT ( usb_settings.children ),
161 .default_scope = &usb_settings_scope,
162};

Referenced by REQUIRE_OBJECT(), and usb_settings_init().