iPXE
acpi.c File Reference

ACPI support functions. More...

#include <string.h>
#include <errno.h>
#include <byteswap.h>
#include <ipxe/uaccess.h>
#include <ipxe/iomap.h>
#include <ipxe/acpi.h>
#include <ipxe/interface.h>

Go to the source code of this file.

Macros

#define colour   FADT_SIGNATURE
 Colour for debug messages.

Functions

 FILE_LICENCE (GPL2_OR_LATER_OR_UBDL)
 FILE_SECBOOT (PERMITTED)
 typeof (acpi_finder=acpi_find)
 ACPI table finder.
void acpi_fix_checksum (struct acpi_header *acpi)
 Fix up ACPI table checksum.
const struct acpi_headeracpi_table (uint32_t signature, unsigned int index)
 Locate ACPI table.
const struct acpi_headeracpi_find_via_rsdt (uint32_t signature, unsigned int index)
 Locate ACPI table via RSDT.
static int acpi_zsdt (const struct acpi_header *zsdt, uint32_t signature, void *data, int(*extract)(const struct acpi_header *zsdt, size_t len, size_t offset, void *data))
 Extract value from DSDT/SSDT.
int acpi_extract (uint32_t signature, void *data, int(*extract)(const struct acpi_header *zsdt, size_t len, size_t offset, void *data))
 Extract value from DSDT/SSDT.
void * acpi_ioremap (struct acpi_address *address, size_t len)
 Map an ACPI generic address.
void acpi_add (struct acpi_descriptor *desc)
 Add ACPI descriptor.
void acpi_del (struct acpi_descriptor *desc)
 Remove ACPI descriptor.
struct acpi_descriptoracpi_describe (struct interface *intf)
 Get object's ACPI descriptor.
int acpi_install (int(*install)(struct acpi_header *acpi))
 Install ACPI tables.

Detailed Description

ACPI support functions.

Definition in file acpi.c.

Macro Definition Documentation

◆ colour

#define colour   FADT_SIGNATURE

Colour for debug messages.

Definition at line 42 of file acpi.c.

Referenced by acpi_extract(), acpi_extract_sx(), acpi_find_via_rsdt(), acpi_poweroff(), acpimac_decode_base16(), acpimac_extract(), ansicol_background(), ansicol_define(), ansicol_foreground(), ansicol_set(), cachedhcp_apply(), cachedhcp_init(), cachedhcp_record(), cachedhcp_recycle(), cachedhcp_shutdown(), cachedhcp_startup_late(), cmdline_init(), cmdline_strip(), colour_content(), colour_exec(), COMMAND(), cpuid_instruction_supported(), cpuid_supported(), efi_allocate_pages_wrapper(), efi_allocate_pool_wrapper(), efi_check_event_wrapper(), efi_close_event_wrapper(), efi_close_protocol_wrapper(), efi_cmdline_init(), efi_connect_controller_wrapper(), efi_create_event_ex_wrapper(), efi_create_event_wrapper(), efi_disconnect_controller_wrapper(), efi_dump_image(), efi_exit_boot_services_wrapper(), efi_exit_wrapper(), efi_free_pages_wrapper(), efi_free_pool_wrapper(), efi_get_memory_map_wrapper(), efi_get_next_monotonic_count_wrapper(), efi_get_next_variable_name_wrapper(), efi_get_time_wrapper(), efi_get_variable_wrapper(), efi_get_wakeup_time_wrapper(), efi_handle_protocol_wrapper(), efi_install_configuration_table_wrapper(), efi_install_multiple_protocol_interfaces_wrapper(), efi_install_protocol_interface_wrapper(), efi_load_image_wrapper(), efi_locate_device_path_wrapper(), efi_locate_handle_buffer_wrapper(), efi_locate_handle_wrapper(), efi_locate_protocol_wrapper(), efi_open_protocol_information_wrapper(), efi_open_protocol_wrapper(), efi_protocols_per_handle_wrapper(), efi_raise_tpl_wrapper(), efi_register_protocol_notify_wrapper(), efi_reinstall_protocol_interface_wrapper(), efi_reset_system_wrapper(), efi_restore_tpl_wrapper(), efi_set_time_wrapper(), efi_set_timer_wrapper(), efi_set_variable_wrapper(), efi_set_wakeup_time_wrapper(), efi_set_watchdog_timer_wrapper(), efi_signal_event_wrapper(), efi_stall_wrapper(), efi_start_image_wrapper(), efi_tick_shutdown(), efi_tick_startup(), efi_udelay(), efi_uninstall_multiple_protocol_interfaces_wrapper(), efi_uninstall_protocol_interface_wrapper(), efi_unload_image_wrapper(), efi_unwrap(), efi_wait_for_event_wrapper(), efi_wrap_systab(), fdtcon_default(), initialise(), initrd_init(), rdrand_entropy_enable(), rdrand_get_noise(), rdtsc_probe(), shutdown(), and startup().

Function Documentation

◆ FILE_LICENCE()

FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL )

◆ FILE_SECBOOT()

FILE_SECBOOT ( PERMITTED )

◆ typeof()

typeof ( acpi_finder = acpi_find)

ACPI table finder.

May be overridden at link time to inject tables for testing. Compute ACPI table checksum

Parameters
acpiAny ACPI table header
Return values
checksum0 if checksum is good

Definition at line 48 of file acpi.c.

63 {
64 const uint8_t *byte = ( ( const void * ) acpi );
65 size_t len = le32_to_cpu ( acpi->length );
66 uint8_t sum = 0;
67
68 /* Compute checksum */
69 while ( len-- )
70 sum += *(byte++);
71
72 return sum;
73}
unsigned char uint8_t
Definition stdint.h:10
ring len
Length.
Definition dwmac.h:226
static EFI_ACPI_TABLE_PROTOCOL * acpi
ACPI table protocol protocol.
Definition efi_block.c:67
#define le32_to_cpu(value)
Definition byteswap.h:114

References acpi, acpi_find(), acpi_finder, le32_to_cpu, and len.

Referenced by aes_entry_column(), ar9002_hw_proc_txdesc(), ar9003_hw_proc_txdesc(), arbel_create_recv_wq(), arbel_fill_mlx_send_wqe(), arbel_fill_rc_send_wqe(), arbel_fill_ud_send_wqe(), asn1_built(), asn1_enter_bits(), dhcpv6_iaaddr(), dhcpv6_rx(), dns_question(), dns_resolv(), dns_xfer_deliver(), draw_setting_row(), ecam_find(), efi_ifr_string(), efi_nullify_pxe(), efi_nullify_snp(), efi_path_uri(), efi_pxe_ip_filter(), efi_pxe_ip_sockaddr(), efisig_asn1(), exanic_transmit(), fc_fill_sockaddr(), fcoe_deliver(), fcoe_fip_rx_els_response(), gve_describe(), hash_df(), hermon_fill_eth_send_wqe(), hermon_fill_mlx_send_wqe(), hermon_fill_rc_send_wqe(), hermon_fill_ud_send_wqe(), hv_wait_for_message(), ib_sbft_install(), ibft_install(), int13_extended_rw(), int13_get_extended_parameters(), int13_load_eltorito(), interrupt_dump(), ipv6conf_rx_router_advertisement(), jme_poll(), list_test_exec(), md4_final(), md5_final(), meme820(), natsemi_create_ring(), ncm_in_complete(), ncm_out_transmit(), ndp_rx_neighbour(), ndp_rx_neighbour_advertisement_ll_target(), ndp_rx_neighbour_solicitation_ll_source(), ndp_rx_router_advertisement(), ndp_rx_router_advertisement_ll_source(), ntlm_response(), peerblk_parse_block(), peerblk_parse_useless(), peerblk_retrieval_open(), peerdist_info_v1_block(), pxebs_list(), select_setting_row(), sha1_final(), sha256_final(), sha512_final(), spcr_console(), tls_client_hello(), tls_send_certificate(), tls_send_client_key_exchange_dhe(), usb_describe(), and usb_get_mtu().

◆ acpi_fix_checksum()

void acpi_fix_checksum ( struct acpi_header * acpi)

Fix up ACPI table checksum.

Parameters
acpiACPI table header

Definition at line 80 of file acpi.c.

80 {
81
82 /* Update checksum */
83 acpi->checksum -= acpi_checksum ( acpi );
84}

References acpi.

Referenced by efi_block_install(), and int13_install().

◆ acpi_table()

const struct acpi_header * acpi_table ( uint32_t signature,
unsigned int index )

Locate ACPI table.

Parameters
signatureRequested table signature
indexRequested index of table with this signature
Return values
tableTable, or NULL if not found

Definition at line 93 of file acpi.c.

94 {
95
96 return ( *acpi_finder ) ( signature, index );
97}
u8 signature
CPU signature.
Definition CIB_PRM.h:7
long index
Definition bigint.h:65
const struct acpi_header *(* acpi_finder)(uint32_t signature, unsigned int index)

References acpi_finder, index, and signature.

Referenced by acpi_extract(), acpi_poweroff(), acpi_settings_fetch(), acpi_timer_probe(), ecam_find(), and spcr_console().

◆ acpi_find_via_rsdt()

const struct acpi_header * acpi_find_via_rsdt ( uint32_t signature,
unsigned int index )

Locate ACPI table via RSDT.

Parameters
signatureRequested table signature
indexRequested index of table with this signature
Return values
tableTable, or NULL if not found

Definition at line 106 of file acpi.c.

107 {
108 const struct acpi_rsdt *rsdt;
109 const struct acpi_header *table;
110 size_t len;
111 unsigned int count;
112 unsigned int i;
113
114 /* Locate RSDT */
115 rsdt = acpi_find_rsdt();
116 if ( ! rsdt ) {
117 DBG ( "RSDT not found\n" );
118 return NULL;
119 }
120
121 /* Read RSDT header */
122 if ( rsdt->acpi.signature != cpu_to_le32 ( RSDT_SIGNATURE ) ) {
123 DBGC ( colour, "RSDT %#08lx has invalid signature:\n",
124 virt_to_phys ( rsdt ) );
125 DBGC_HDA ( colour, virt_to_phys ( rsdt ), &rsdt->acpi,
126 sizeof ( rsdt->acpi ) );
127 return NULL;
128 }
129 len = le32_to_cpu ( rsdt->acpi.length );
130 if ( len < sizeof ( rsdt->acpi ) ) {
131 DBGC ( colour, "RSDT %#08lx has invalid length:\n",
132 virt_to_phys ( rsdt ) );
133 DBGC_HDA ( colour, virt_to_phys ( rsdt ), &rsdt->acpi,
134 sizeof ( rsdt->acpi ) );
135 return NULL;
136 }
137
138 /* Calculate number of entries */
139 count = ( ( len - sizeof ( rsdt->acpi ) ) /
140 sizeof ( rsdt->entry[0] ) );
141
142 /* Search through entries */
143 for ( i = 0 ; i < count ; i++ ) {
144
145 /* Read table header */
146 table = phys_to_virt ( rsdt->entry[i] );
147
148 /* Check table signature */
149 if ( table->signature != cpu_to_le32 ( signature ) )
150 continue;
151
152 /* Check index */
153 if ( index-- )
154 continue;
155
156 /* Check table integrity */
157 if ( acpi_checksum ( table ) != 0 ) {
158 DBGC ( colour, "RSDT %#08lx found %s with bad "
159 "checksum at %#08lx\n", virt_to_phys ( rsdt ),
161 virt_to_phys ( table ) );
162 break;
163 }
164
165 DBGC ( colour, "RSDT %#08lx found %s at %#08lx\n",
166 virt_to_phys ( rsdt ), acpi_name ( signature ),
167 virt_to_phys ( table ) );
168 return table;
169 }
170
171 DBGC ( colour, "RSDT %#08lx could not find %s\n",
172 virt_to_phys ( rsdt ), acpi_name ( signature ) );
173 return NULL;
174}
#define NULL
NULL pointer (VOID *)
Definition Base.h:322
#define colour
Colour for debug messages.
Definition acpi.c:42
#define DBGC(...)
Definition compiler.h:505
#define DBG(...)
Print a debugging message.
Definition compiler.h:498
#define DBGC_HDA(...)
Definition compiler.h:506
static unsigned int count
Number of entries.
Definition dwmac.h:220
#define cpu_to_le32(value)
Definition byteswap.h:108
static const char * acpi_name(uint32_t signature)
Transcribe ACPI table signature (for debugging)
Definition acpi.h:207
#define RSDT_SIGNATURE
Root System Description Table (RSDT) signature.
Definition acpi.h:247
const struct acpi_rsdt * acpi_find_rsdt(void)
Locate ACPI root system description table.
An ACPI description header.
Definition acpi.h:180
uint32_t signature
ACPI signature (4 ASCII characters)
Definition acpi.h:182
uint32_t length
Length of table, in bytes, including header.
Definition acpi.h:184
ACPI Root System Description Table (RSDT)
Definition acpi.h:250
struct acpi_header acpi
ACPI header.
Definition acpi.h:252
uint32_t entry[0]
ACPI table entries.
Definition acpi.h:254

References acpi_rsdt::acpi, acpi_find_rsdt(), acpi_name(), colour, count, cpu_to_le32, DBG, DBGC, DBGC_HDA, acpi_rsdt::entry, index, le32_to_cpu, len, acpi_header::length, NULL, RSDT_SIGNATURE, acpi_header::signature, and signature.

Referenced by acpi_find().

◆ acpi_zsdt()

int acpi_zsdt ( const struct acpi_header * zsdt,
uint32_t signature,
void * data,
int(* extract )(const struct acpi_header *zsdt, size_t len, size_t offset, void *data) )
static

Extract value from DSDT/SSDT.

Parameters
zsdtDSDT or SSDT
signatureSignature (e.g. "_S5_")
dataData buffer
extractExtraction method
Return values
rcReturn status code

Definition at line 185 of file acpi.c.

189 {
190 uint32_t buf;
191 size_t offset;
192 size_t len;
193 int rc;
194
195 /* Read table header */
196 len = le32_to_cpu ( zsdt->length );
197
198 /* Locate signature */
199 for ( offset = sizeof ( *zsdt ) ;
200 ( ( offset + sizeof ( buf ) /* signature */ ) < len ) ;
201 offset++ ) {
202
203 /* Check signature */
204 memcpy ( &buf, ( ( ( const void * ) zsdt ) + offset ),
205 sizeof ( buf ) );
206 if ( buf != cpu_to_le32 ( signature ) )
207 continue;
208 DBGC ( zsdt, "DSDT/SSDT %#08lx found %s at offset %#zx\n",
209 virt_to_phys ( zsdt ), acpi_name ( signature ),
210 offset );
211
212 /* Attempt to extract data */
213 if ( ( rc = extract ( zsdt, len, offset, data ) ) == 0 )
214 return 0;
215 }
216
217 return -ENOENT;
218}
struct arbelprm_rc_send_wqe rc
Definition arbel.h:3
unsigned int uint32_t
Definition stdint.h:12
uint16_t offset
Offset to command line.
Definition bzimage.h:3
uint8_t data[48]
Additional event data.
Definition ena.h:11
#define ENOENT
No such file or directory.
Definition errno.h:515
void * memcpy(void *dest, const void *src, size_t len) __nonnull

References acpi_name(), cpu_to_le32, data, DBGC, ENOENT, le32_to_cpu, len, acpi_header::length, memcpy(), offset, rc, and signature.

Referenced by acpi_extract().

◆ acpi_extract()

int acpi_extract ( uint32_t signature,
void * data,
int(* extract )(const struct acpi_header *zsdt, size_t len, size_t offset, void *data) )

Extract value from DSDT/SSDT.

Parameters
signatureSignature (e.g. "_S5_")
dataData buffer
extractExtraction method
Return values
rcReturn status code

Definition at line 228 of file acpi.c.

231 {
232 const struct acpi_fadt *fadt;
233 const struct acpi_header *dsdt;
234 const struct acpi_header *ssdt;
235 unsigned int i;
236 int rc;
237
238 /* Try DSDT first */
239 fadt = container_of ( acpi_table ( FADT_SIGNATURE, 0 ),
240 struct acpi_fadt, acpi );
241 if ( fadt ) {
242 dsdt = phys_to_virt ( fadt->dsdt );
243 if ( ( rc = acpi_zsdt ( dsdt, signature, data,
244 extract ) ) == 0 )
245 return 0;
246 }
247
248 /* Try all SSDTs */
249 for ( i = 0 ; ; i++ ) {
250 ssdt = acpi_table ( SSDT_SIGNATURE, i );
251 if ( ! ssdt )
252 break;
253 if ( ( rc = acpi_zsdt ( ssdt, signature, data,
254 extract ) ) == 0 )
255 return 0;
256 }
257
258 DBGC ( colour, "ACPI could not find \"%s\"\n",
259 acpi_name ( signature ) );
260 return -ENOENT;
261}
const struct acpi_header * acpi_table(uint32_t signature, unsigned int index)
Locate ACPI table.
Definition acpi.c:93
static int acpi_zsdt(const struct acpi_header *zsdt, uint32_t signature, void *data, int(*extract)(const struct acpi_header *zsdt, size_t len, size_t offset, void *data))
Extract value from DSDT/SSDT.
Definition acpi.c:185
#define FADT_SIGNATURE
Fixed ACPI Description Table (FADT) signature.
Definition acpi.h:258
#define SSDT_SIGNATURE
Secondary System Description Table (SSDT) signature.
Definition acpi.h:292
#define container_of(ptr, type, field)
Get containing structure.
Definition stddef.h:36
Fixed ACPI Description Table (FADT)
Definition acpi.h:261
uint32_t dsdt
Physical address of DSDT.
Definition acpi.h:267

References acpi, acpi_name(), acpi_table(), acpi_zsdt(), colour, container_of, data, DBGC, acpi_fadt::dsdt, ENOENT, FADT_SIGNATURE, len, offset, rc, signature, and SSDT_SIGNATURE.

Referenced by acpi_mac(), and acpi_poweroff().

◆ acpi_ioremap()

void * acpi_ioremap ( struct acpi_address * address,
size_t len )

Map an ACPI generic address.

Parameters
addressGeneric address
lenLength of region
Return values
io_addrI/O address, or NULL on error

Definition at line 270 of file acpi.c.

270 {
271 physaddr_t base = le64_to_cpu ( address->address );
272
273 switch ( address->type ) {
275 return ioremap ( base, len );
277 return ( ( void * ) base );
278 default:
279 return NULL;
280 }
281}
unsigned long physaddr_t
Definition stdint.h:20
uint64_t address
Base address.
Definition ena.h:13
#define le64_to_cpu(value)
Definition byteswap.h:115
#define ACPI_ADDRESS_TYPE_MEM
A memory address space type.
Definition acpi.h:37
#define ACPI_ADDRESS_TYPE_IO
An I/O address space type.
Definition acpi.h:40
void * ioremap(unsigned long bus_addr, size_t len)
Map bus address as an I/O address.
uint32_t base
Base.
Definition librm.h:3

References ACPI_ADDRESS_TYPE_IO, ACPI_ADDRESS_TYPE_MEM, address, base, ioremap(), le64_to_cpu, len, and NULL.

Referenced by spcr_16550().

◆ acpi_add()

void acpi_add ( struct acpi_descriptor * desc)

Add ACPI descriptor.

Parameters
descACPI descriptor

Definition at line 295 of file acpi.c.

295 {
296
297 /* Add to list of descriptors */
298 ref_get ( desc->refcnt );
299 list_add_tail ( &desc->list, &desc->model->descs );
300}
struct ena_llq_option desc
Descriptor counts.
Definition ena.h:9
#define list_add_tail(new, head)
Add a new entry to the tail of a list.
Definition list.h:94
#define ref_get(refcnt)
Get additional reference to object.
Definition refcnt.h:93

References desc, list_add_tail, and ref_get.

Referenced by sanpath_open().

◆ acpi_del()

void acpi_del ( struct acpi_descriptor * desc)

Remove ACPI descriptor.

Parameters
descACPI descriptor

Definition at line 307 of file acpi.c.

307 {
308
309 /* Remove from list of descriptors */
310 list_check_contains_entry ( desc, &desc->model->descs, list );
311 list_del ( &desc->list );
312 ref_put ( desc->refcnt );
313}
#define list_del(list)
Delete an entry from a list.
Definition list.h:120
#define list_check_contains_entry(entry, head, member)
Check list contains a specified entry.
Definition list.h:550
#define ref_put(refcnt)
Drop reference to object.
Definition refcnt.h:107

References desc, list_check_contains_entry, list_del, and ref_put.

Referenced by sandev_undescribe(), and sanpath_open().

◆ acpi_describe()

struct acpi_descriptor * acpi_describe ( struct interface * intf)

Get object's ACPI descriptor.

Parameters
intfInterface
Return values
descACPI descriptor, or NULL

Definition at line 321 of file acpi.c.

321 {
322 struct interface *dest;
323 acpi_describe_TYPE ( void * ) *op =
325 void *object = intf_object ( dest );
326 struct acpi_descriptor *desc;
327
328 if ( op ) {
329 desc = op ( object );
330 } else {
331 desc = NULL;
332 }
333
334 intf_put ( dest );
335 return desc;
336}
struct acpi_descriptor * acpi_describe(struct interface *intf)
Get object's ACPI descriptor.
Definition acpi.c:321
if(len >=6 *4) __asm__ __volatile__("movsl" if(len >=5 *4) __asm__ __volatile__("movsl" if(len >=4 *4) __asm__ __volatile__("movsl" if(len >=3 *4) __asm__ __volatile__("movsl" if(len >=2 *4) __asm__ __volatile__("movsl" if(len >=1 *4) __asm__ __volatile__("movsl" if((len % 4) >=2) __asm__ __volatile__("movsw" if((len % 2) >=1) __asm__ __volatile__("movsb" retur dest)
Definition string.h:151
#define acpi_describe_TYPE(object_type)
Definition acpi.h:405
void * intf_object(struct interface *intf)
Get pointer to object containing object interface.
Definition interface.c:160
void intf_put(struct interface *intf)
Decrement reference count on an object interface.
Definition interface.c:150
#define intf_get_dest_op(intf, type, dest)
Get object interface destination and operation method.
Definition interface.h:270
static uint16_t struct vmbus_xfer_pages_operations * op
Definition netvsc.h:327
An ACPI descriptor (used to construct ACPI tables)
Definition acpi.h:295
An object interface.
Definition interface.h:125
struct interface * intf
Original interface.
Definition interface.h:159

References acpi_describe(), acpi_describe_TYPE, desc, dest, interface::intf, intf_get_dest_op, intf_object(), intf_put(), NULL, and op.

Referenced by acpi_describe(), and sanpath_open().

◆ acpi_install()

int acpi_install ( int(* install )(struct acpi_header *acpi))

Install ACPI tables.

Parameters
installTable installation method
Return values
rcReturn status code

Definition at line 344 of file acpi.c.

344 {
345 struct acpi_model *model;
346 int rc;
347
349 if ( ( rc = model->install ( install ) ) != 0 )
350 return rc;
351 }
352
353 return 0;
354}
#define ACPI_MODELS
ACPI models.
Definition acpi.h:341
An ACPI table model.
Definition acpi.h:321
int(* install)(int(*install)(struct acpi_header *acpi))
Install ACPI tables.
Definition acpi.h:337
#define for_each_table_entry(pointer, table)
Iterate through all entries within a linker table.
Definition tables.h:386

References acpi, ACPI_MODELS, for_each_table_entry, acpi_model::install, and rc.

Referenced by dummy_san_describe(), efi_block_describe(), and int13_describe().