iPXE
Macros | Functions
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. More...
 

Functions

 FILE_LICENCE (GPL2_OR_LATER_OR_UBDL)
 
 typeof (acpi_finder=acpi_find)
 ACPI table finder. More...
 
void acpi_fix_checksum (struct acpi_header *acpi)
 Fix up ACPI table checksum. More...
 
const struct acpi_headeracpi_table (uint32_t signature, unsigned int index)
 Locate ACPI table. More...
 
const struct acpi_headeracpi_find_via_rsdt (uint32_t signature, unsigned int index)
 Locate ACPI table via RSDT. More...
 
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. More...
 
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. More...
 
void * acpi_ioremap (struct acpi_address *address, size_t len)
 Map an ACPI generic address. More...
 
void acpi_add (struct acpi_descriptor *desc)
 Add ACPI descriptor. More...
 
void acpi_del (struct acpi_descriptor *desc)
 Remove ACPI descriptor. More...
 
struct acpi_descriptoracpi_describe (struct interface *intf)
 Get object's ACPI descriptor. More...
 
int acpi_install (int(*install)(struct acpi_header *acpi))
 Install ACPI tables. More...
 

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 41 of file acpi.c.

Function Documentation

◆ FILE_LICENCE()

FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL  )

◆ 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 47 of file acpi.c.

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

References acpi, 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 79 of file acpi.c.

79  {
80 
81  /* Update checksum */
82  acpi->checksum -= acpi_checksum ( acpi );
83 }
static EFI_ACPI_TABLE_PROTOCOL * acpi
ACPI table protocol protocol.
Definition: efi_block.c:66

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 92 of file acpi.c.

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

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 105 of file acpi.c.

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

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, signature, and acpi_header::signature.

Referenced by acpi_find().

◆ acpi_zsdt()

static int acpi_zsdt ( const struct acpi_header zsdt,
uint32_t  signature,
void *  data,
int(*)(const struct acpi_header *zsdt, size_t len, size_t offset, void *data extract 
)
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 184 of file acpi.c.

188  {
189  uint32_t buf;
190  size_t offset;
191  size_t len;
192  int rc;
193 
194  /* Read table header */
195  len = le32_to_cpu ( zsdt->length );
196 
197  /* Locate signature */
198  for ( offset = sizeof ( *zsdt ) ;
199  ( ( offset + sizeof ( buf ) /* signature */ ) < len ) ;
200  offset++ ) {
201 
202  /* Check signature */
203  memcpy ( &buf, ( ( ( const void * ) zsdt ) + offset ),
204  sizeof ( buf ) );
205  if ( buf != cpu_to_le32 ( signature ) )
206  continue;
207  DBGC ( zsdt, "DSDT/SSDT %#08lx found %s at offset %#zx\n",
208  virt_to_phys ( zsdt ), acpi_name ( signature ),
209  offset );
210 
211  /* Attempt to extract data */
212  if ( ( rc = extract ( zsdt, len, offset, data ) ) == 0 )
213  return 0;
214  }
215 
216  return -ENOENT;
217 }
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
#define le32_to_cpu(value)
Definition: byteswap.h:113
#define DBGC(...)
Definition: compiler.h:505
#define ENOENT
No such file or directory.
Definition: errno.h:514
void * memcpy(void *dest, const void *src, size_t len) __nonnull
uint32_t length
Length of table, in bytes, including header.
Definition: acpi.h:183
ring len
Length.
Definition: dwmac.h:231
#define cpu_to_le32(value)
Definition: byteswap.h:107
unsigned int uint32_t
Definition: stdint.h:12
static const char * acpi_name(uint32_t signature)
Transcribe ACPI table signature (for debugging)
Definition: acpi.h:206
uint8_t data[48]
Additional event data.
Definition: ena.h:22
uint16_t offset
Offset to command line.
Definition: bzimage.h:8
u8 signature
CPU signature.
Definition: CIB_PRM.h:35

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(*)(const struct acpi_header *zsdt, size_t len, size_t offset, void *data extract 
)

Extract value from DSDT/SSDT.

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

Definition at line 227 of file acpi.c.

230  {
231  const struct acpi_fadt *fadt;
232  const struct acpi_header *dsdt;
233  const struct acpi_header *ssdt;
234  unsigned int i;
235  int rc;
236 
237  /* Try DSDT first */
238  fadt = container_of ( acpi_table ( FADT_SIGNATURE, 0 ),
239  struct acpi_fadt, acpi );
240  if ( fadt ) {
241  dsdt = phys_to_virt ( fadt->dsdt );
242  if ( ( rc = acpi_zsdt ( dsdt, signature, data,
243  extract ) ) == 0 )
244  return 0;
245  }
246 
247  /* Try all SSDTs */
248  for ( i = 0 ; ; i++ ) {
249  ssdt = acpi_table ( SSDT_SIGNATURE, i );
250  if ( ! ssdt )
251  break;
252  if ( ( rc = acpi_zsdt ( ssdt, signature, data,
253  extract ) ) == 0 )
254  return 0;
255  }
256 
257  DBGC ( colour, "ACPI could not find \"%s\"\n",
258  acpi_name ( signature ) );
259  return -ENOENT;
260 }
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
#define DBGC(...)
Definition: compiler.h:505
#define SSDT_SIGNATURE
Secondary System Description Table (SSDT) signature.
Definition: acpi.h:291
#define ENOENT
No such file or directory.
Definition: errno.h:514
const struct acpi_header * acpi_table(uint32_t signature, unsigned int index)
Locate ACPI table.
Definition: acpi.c:92
#define container_of(ptr, type, field)
Get containing structure.
Definition: stddef.h:35
#define colour
Colour for debug messages.
Definition: acpi.c:41
Fixed ACPI Description Table (FADT)
Definition: acpi.h:260
static EFI_ACPI_TABLE_PROTOCOL * acpi
ACPI table protocol protocol.
Definition: efi_block.c:66
#define FADT_SIGNATURE
Fixed ACPI Description Table (FADT) signature.
Definition: acpi.h:257
An ACPI description header.
Definition: acpi.h:179
uint32_t dsdt
Physical address of DSDT.
Definition: acpi.h:266
static const char * acpi_name(uint32_t signature)
Transcribe ACPI table signature (for debugging)
Definition: acpi.h:206
uint8_t data[48]
Additional event data.
Definition: ena.h:22
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:184
u8 signature
CPU signature.
Definition: CIB_PRM.h:35

References acpi, acpi_name(), acpi_table(), acpi_zsdt(), colour, container_of, data, DBGC, acpi_fadt::dsdt, ENOENT, FADT_SIGNATURE, 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 269 of file acpi.c.

269  {
270  physaddr_t base = le64_to_cpu ( address->address );
271 
272  switch ( address->type ) {
274  return ioremap ( base, len );
276  return ( ( void * ) base );
277  default:
278  return NULL;
279  }
280 }
uint32_t base
Base.
Definition: librm.h:138
uint64_t address
Base address.
Definition: ena.h:24
#define ACPI_ADDRESS_TYPE_IO
An I/O address space type.
Definition: acpi.h:39
ring len
Length.
Definition: dwmac.h:231
unsigned long physaddr_t
Definition: stdint.h:20
#define ACPI_ADDRESS_TYPE_MEM
A memory address space type.
Definition: acpi.h:36
void * ioremap(unsigned long bus_addr, size_t len)
Map bus address as an I/O address.
#define le64_to_cpu(value)
Definition: byteswap.h:114
#define NULL
NULL pointer (VOID *)
Definition: Base.h:321

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 294 of file acpi.c.

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

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 306 of file acpi.c.

306  {
307 
308  /* Remove from list of descriptors */
309  list_check_contains_entry ( desc, &desc->model->descs, list );
310  list_del ( &desc->list );
311  ref_put ( desc->refcnt );
312 }
#define list_del(list)
Delete an entry from a list.
Definition: list.h:119
struct ena_llq_option desc
Descriptor counts.
Definition: ena.h:20
#define list_check_contains_entry(entry, head, member)
Check list contains a specified entry.
Definition: list.h:549
#define ref_put(refcnt)
Drop reference to object.
Definition: refcnt.h:106

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 320 of file acpi.c.

320  {
321  struct interface *dest;
322  acpi_describe_TYPE ( void * ) *op =
324  void *object = intf_object ( dest );
325  struct acpi_descriptor *desc;
326 
327  if ( op ) {
328  desc = op ( object );
329  } else {
330  desc = NULL;
331  }
332 
333  intf_put ( dest );
334  return desc;
335 }
void * intf_object(struct interface *intf)
Get pointer to object containing object interface.
Definition: interface.c:159
struct interface * intf
Original interface.
Definition: interface.h:158
struct ena_llq_option desc
Descriptor counts.
Definition: ena.h:20
An object interface.
Definition: interface.h:124
struct acpi_descriptor * acpi_describe(struct interface *intf)
Get object's ACPI descriptor.
Definition: acpi.c:320
#define acpi_describe_TYPE(object_type)
Definition: acpi.h:404
static uint16_t struct vmbus_xfer_pages_operations * op
Definition: netvsc.h:327
An ACPI descriptor (used to construct ACPI tables)
Definition: acpi.h:294
void intf_put(struct interface *intf)
Decrement reference count on an object interface.
Definition: interface.c:149
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" return dest
Definition: string.h:150
#define NULL
NULL pointer (VOID *)
Definition: Base.h:321
#define intf_get_dest_op(intf, type, dest)
Get object interface destination and operation method.
Definition: interface.h:269

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(*)(struct acpi_header *acpi install)

Install ACPI tables.

Parameters
installTable installation method
Return values
rcReturn status code

Definition at line 343 of file acpi.c.

343  {
344  struct acpi_model *model;
345  int rc;
346 
347  for_each_table_entry ( model, ACPI_MODELS ) {
348  if ( ( rc = model->install ( install ) ) != 0 )
349  return rc;
350  }
351 
352  return 0;
353 }
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
int(* install)(int(*install)(struct acpi_header *acpi))
Install ACPI tables.
Definition: acpi.h:336
An ACPI table model.
Definition: acpi.h:320
#define for_each_table_entry(pointer, table)
Iterate through all entries within a linker table.
Definition: tables.h:385
#define ACPI_MODELS
ACPI models.
Definition: acpi.h:340

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

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