iPXE
Functions | Variables
acpi_settings.c File Reference

ACPI settings. More...

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

Go to the source code of this file.

Functions

 FILE_LICENCE (GPL2_OR_LATER_OR_UBDL)
 
static int acpi_settings_applies (struct settings *settings __unused, const struct setting *setting)
 Check applicability of ACPI setting. More...
 
static int acpi_settings_fetch (struct settings *settings, struct setting *setting, void *data, size_t len)
 Fetch value of ACPI setting. More...
 
static void acpi_settings_init (void)
 Initialise ACPI settings. More...
 
struct init_fn acpi_settings_init_fn __init_fn (INIT_NORMAL)
 ACPI settings initialiser. More...
 

Variables

static const struct settings_scope acpi_settings_scope
 ACPI settings scope. More...
 
static struct settings_operations acpi_settings_operations
 ACPI settings operations. More...
 
static struct settings acpi_settings
 ACPI settings. More...
 

Detailed Description

ACPI settings.

Definition in file acpi_settings.c.

Function Documentation

◆ FILE_LICENCE()

FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL  )

◆ acpi_settings_applies()

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

Check applicability of ACPI setting.

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

Definition at line 49 of file acpi_settings.c.

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

References acpi_settings_scope, and setting::scope.

◆ acpi_settings_fetch()

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

Fetch value of ACPI 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 acpi_settings.c.

66  {
67  struct acpi_header acpi;
68  uint32_t tag_high;
69  uint32_t tag_low;
70  uint32_t tag_signature;
71  unsigned int tag_index;
72  size_t tag_offset;
73  size_t tag_len;
74  userptr_t table;
75  size_t offset;
76  size_t max_len;
77  int delta;
78  unsigned int i;
79 
80  /* Parse settings tag */
81  tag_high = ( setting->tag >> 32 );
82  tag_low = setting->tag;
83  tag_signature = bswap_32 ( tag_high );
84  tag_index = ( ( tag_low >> 24 ) & 0xff );
85  tag_offset = ( ( tag_low >> 8 ) & 0xffff );
86  tag_len = ( ( tag_low >> 0 ) & 0xff );
87  DBGC ( settings, "ACPI %s.%d offset %#zx length %#zx\n",
88  acpi_name ( tag_signature ), tag_index, tag_offset, tag_len );
89 
90  /* Locate ACPI table */
91  table = acpi_table ( tag_signature, tag_index );
92  if ( ! table )
93  return -ENOENT;
94 
95  /* Read table header */
96  copy_from_user ( &acpi, table, 0, sizeof ( acpi ) );
97 
98  /* Calculate starting offset and maximum available length */
99  max_len = le32_to_cpu ( acpi.length );
100  if ( tag_offset > max_len )
101  return -ENOENT;
102  offset = tag_offset;
103  max_len -= offset;
104 
105  /* Restrict to requested length, if specified */
106  if ( tag_len && ( tag_len < max_len ) )
107  max_len = tag_len;
108 
109  /* Invert endianness for numeric settings */
110  if ( setting->type && setting->type->numerate ) {
111  offset += ( max_len - 1 );
112  delta = -1;
113  } else {
114  delta = +1;
115  }
116 
117  /* Read data */
118  for ( i = 0 ; ( ( i < max_len ) && ( i < len ) ) ; i++ ) {
119  copy_from_user ( data, table, offset, 1 );
120  data++;
121  offset += delta;
122  }
123 
124  /* Set type if not already specified */
125  if ( ! setting->type )
126  setting->type = &setting_type_hexraw;
127 
128  return max_len;
129 }
#define le32_to_cpu(value)
Definition: byteswap.h:113
uint16_t max_len
Maximum length (in bytes)
Definition: ntlm.h:18
static __always_inline void copy_from_user(void *dest, userptr_t src, off_t src_off, size_t len)
Copy data from user buffer.
Definition: uaccess.h:337
#define DBGC(...)
Definition: compiler.h:505
userptr_t acpi_table(uint32_t signature, unsigned int index)
Locate ACPI table.
Definition: acpi.c:98
#define ENOENT
No such file or directory.
Definition: errno.h:514
uint64_t tag
Setting tag, if applicable.
Definition: settings.h:43
static EFI_ACPI_TABLE_PROTOCOL * acpi
ACPI table protocol protocol.
Definition: efi_block.c:65
static userptr_t size_t offset
Offset of the first segment within the content.
Definition: deflate.h:259
const struct setting_type * type
Setting type.
Definition: settings.h:36
#define bswap_32(value)
Definition: byteswap.h:70
int(* numerate)(const struct setting_type *type, const void *raw, size_t raw_len, unsigned long *value)
Convert setting value to number.
Definition: settings.h:237
A settings block.
Definition: settings.h:132
An ACPI description header.
Definition: acpi.h:163
unsigned int uint32_t
Definition: stdint.h:12
A setting.
Definition: settings.h:23
uint32_t len
Length.
Definition: ena.h:14
static const char * acpi_name(uint32_t signature)
Transcribe ACPI table signature (for debugging)
Definition: acpi.h:190
uint8_t data[48]
Additional event data.
Definition: ena.h:22
unsigned long userptr_t
A pointer to a user buffer.
Definition: uaccess.h:33

References acpi, acpi_name(), acpi_table(), bswap_32, copy_from_user(), data, DBGC, ENOENT, le32_to_cpu, len, max_len, setting_type::numerate, offset, setting::tag, and setting::type.

◆ acpi_settings_init()

static void acpi_settings_init ( void  )
static

Initialise ACPI settings.

Definition at line 147 of file acpi_settings.c.

147  {
148  int rc;
149 
150  if ( ( rc = register_settings ( &acpi_settings, NULL,
151  "acpi" ) ) != 0 ) {
152  DBG ( "ACPI could not register settings: %s\n",
153  strerror ( rc ) );
154  return;
155  }
156 }
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 acpi_settings
ACPI settings.

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

◆ __init_fn()

struct init_fn acpi_settings_init_fn __init_fn ( INIT_NORMAL  )

ACPI settings initialiser.

Variable Documentation

◆ acpi_settings_scope

const struct settings_scope acpi_settings_scope
static

ACPI settings scope.

Definition at line 40 of file acpi_settings.c.

Referenced by acpi_settings_applies().

◆ acpi_settings_operations

struct settings_operations acpi_settings_operations
static
Initial value:
= {
}
static int acpi_settings_fetch(struct settings *settings, struct setting *setting, void *data, size_t len)
Fetch value of ACPI setting.
Definition: acpi_settings.c:64
static int acpi_settings_applies(struct settings *settings __unused, const struct setting *setting)
Check applicability of ACPI setting.
Definition: acpi_settings.c:49

ACPI settings operations.

Definition at line 132 of file acpi_settings.c.

◆ acpi_settings

struct settings acpi_settings
static
Initial value:
= {
.refcnt = NULL,
.default_scope = &acpi_settings_scope,
}
static struct settings_operations acpi_settings_operations
ACPI settings operations.
struct list_head siblings
Sibling settings blocks.
Definition: settings.h:140
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 acpi_settings_scope
ACPI settings scope.
Definition: acpi_settings.c:40
#define NULL
NULL pointer (VOID *)
Definition: Base.h:321
static struct settings acpi_settings
ACPI settings.

ACPI settings.

Definition at line 138 of file acpi_settings.c.

Referenced by acpi_settings_init().