iPXE
acpi_settings.c
Go to the documentation of this file.
1/*
2 * Copyright (C) 2017 Michael Brown <mbrown@fensystems.co.uk>.
3 *
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License as
6 * published by the Free Software Foundation; either version 2 of the
7 * License, or any later version.
8 *
9 * This program is distributed in the hope that it will be useful, but
10 * WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
17 * 02110-1301, USA.
18 *
19 * You can also choose to distribute this program under the terms of
20 * the Unmodified Binary Distribution Licence (as given in the file
21 * COPYING.UBDL), provided that you have satisfied its requirements.
22 */
23
24FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
25FILE_SECBOOT ( PERMITTED );
26
27/**
28 * @file
29 *
30 * ACPI settings
31 *
32 */
33
34#include <string.h>
35#include <errno.h>
36#include <ipxe/init.h>
37#include <ipxe/settings.h>
38#include <ipxe/acpi.h>
39
40/** ACPI settings scope */
42
43/**
44 * Check applicability of ACPI setting
45 *
46 * @v settings Settings block
47 * @v setting Setting
48 * @ret applies Setting applies within this settings block
49 */
51 const struct setting *setting ) {
52
53 return ( setting->scope == &acpi_settings_scope );
54}
55
56/**
57 * Fetch value of ACPI setting
58 *
59 * @v settings Settings block
60 * @v setting Setting to fetch
61 * @v data Buffer to fill with setting data
62 * @v len Length of buffer
63 * @ret len Length of setting data, or negative error
64 */
66 struct setting *setting,
67 void *data, size_t len ) {
68 const struct acpi_header *acpi;
69 const uint8_t *src;
70 uint8_t *dst;
71 uint32_t tag_high;
72 uint32_t tag_low;
73 uint32_t tag_signature;
74 unsigned int tag_index;
75 size_t tag_offset;
76 size_t tag_len;
77 size_t offset;
78 size_t max_len;
79 int delta;
80 unsigned int i;
81
82 /* Parse settings tag */
83 tag_high = ( setting->tag >> 32 );
84 tag_low = setting->tag;
85 tag_signature = bswap_32 ( tag_high );
86 tag_index = ( ( tag_low >> 24 ) & 0xff );
87 tag_offset = ( ( tag_low >> 8 ) & 0xffff );
88 tag_len = ( ( tag_low >> 0 ) & 0xff );
89 DBGC ( settings, "ACPI %s.%d offset %#zx length %#zx\n",
90 acpi_name ( tag_signature ), tag_index, tag_offset, tag_len );
91
92 /* Locate ACPI table */
93 acpi = acpi_table ( tag_signature, tag_index );
94 if ( ! acpi )
95 return -ENOENT;
96
97 /* Calculate starting offset and maximum available length */
98 max_len = le32_to_cpu ( acpi->length );
99 if ( tag_offset > max_len )
100 return -ENOENT;
101 offset = tag_offset;
102 max_len -= offset;
103
104 /* Restrict to requested length, if specified */
105 if ( tag_len && ( tag_len < max_len ) )
106 max_len = tag_len;
107
108 /* Invert endianness for numeric settings */
109 if ( setting->type && setting->type->numerate ) {
110 offset += ( max_len - 1 );
111 delta = -1;
112 } else {
113 delta = +1;
114 }
115
116 /* Read data */
117 src = ( ( ( const void * ) acpi ) + offset );
118 dst = data;
119 for ( i = 0 ; ( ( i < max_len ) && ( i < len ) ) ; i++ ) {
120 *(dst++) = *src;
121 src += 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}
130
131/** ACPI settings operations */
133 .applies = acpi_settings_applies,
134 .fetch = acpi_settings_fetch,
135};
136
137/** ACPI settings */
138static struct settings acpi_settings = {
139 .refcnt = NULL,
140 .siblings = LIST_HEAD_INIT ( acpi_settings.siblings ),
141 .children = LIST_HEAD_INIT ( acpi_settings.children ),
143 .default_scope = &acpi_settings_scope,
144};
145
146/** Initialise ACPI settings */
147static void acpi_settings_init ( void ) {
148 int rc;
149
151 "acpi" ) ) != 0 ) {
152 DBG ( "ACPI could not register settings: %s\n",
153 strerror ( rc ) );
154 return;
155 }
156}
157
158/** ACPI settings initialiser */
159struct init_fn acpi_settings_init_fn __init_fn ( INIT_NORMAL ) = {
160 .name = "acpi",
161 .initialise = acpi_settings_init,
162};
#define NULL
NULL pointer (VOID *)
Definition Base.h:322
const struct acpi_header * acpi_table(uint32_t signature, unsigned int index)
Locate ACPI table.
Definition acpi.c:93
static const struct settings_scope acpi_settings_scope
ACPI settings scope.
static int acpi_settings_applies(struct settings *settings __unused, const struct setting *setting)
Check applicability of ACPI setting.
static struct settings acpi_settings
ACPI settings.
static int acpi_settings_fetch(struct settings *settings, struct setting *setting, void *data, size_t len)
Fetch value of ACPI setting.
static void acpi_settings_init(void)
Initialise ACPI settings.
static struct settings_operations acpi_settings_operations
ACPI settings operations.
struct arbelprm_rc_send_wqe rc
Definition arbel.h:3
unsigned int uint32_t
Definition stdint.h:12
unsigned char uint8_t
Definition stdint.h:10
static const void * src
Definition string.h:48
uint16_t offset
Offset to command line.
Definition bzimage.h:3
ring len
Length.
Definition dwmac.h:226
static EFI_ACPI_TABLE_PROTOCOL * acpi
ACPI table protocol protocol.
Definition efi_block.c:67
uint8_t data[48]
Additional event data.
Definition ena.h:11
Error codes.
#define __unused
Declare a variable or data structure as unused.
Definition compiler.h:573
#define DBGC(...)
Definition compiler.h:505
#define DBG(...)
Print a debugging message.
Definition compiler.h:498
#define INIT_NORMAL
Normal initialisation.
Definition init.h:32
#define FILE_LICENCE(_licence)
Declare a particular licence as applying to a file.
Definition compiler.h:896
#define ENOENT
No such file or directory.
Definition errno.h:515
#define FILE_SECBOOT(_status)
Declare a file's UEFI Secure Boot permission status.
Definition compiler.h:926
#define bswap_32(value)
Definition byteswap.h:71
#define le32_to_cpu(value)
Definition byteswap.h:114
ACPI data structures.
static const char * acpi_name(uint32_t signature)
Transcribe ACPI table signature (for debugging)
Definition acpi.h:207
Configuration settings.
String functions.
#define __init_fn(init_order)
Declare an initialisation functon.
Definition init.h:24
#define LIST_HEAD_INIT(list)
Initialise a static list head.
Definition list.h:31
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
An ACPI description header.
Definition acpi.h:180
An initialisation function.
Definition init.h:15
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:238
A setting.
Definition settings.h:24
const struct settings_scope * scope
Setting scope (or NULL)
Definition settings.h:50
const struct setting_type * type
Setting type.
Definition settings.h:37
uint64_t tag
Setting tag, if applicable.
Definition settings.h:44
Settings block operations.
Definition settings.h:86
A setting scope.
Definition settings.h:177
A settings block.
Definition settings.h:133