iPXE
acpi.h
Go to the documentation of this file.
1#ifndef _IPXE_ACPI_H
2#define _IPXE_ACPI_H
3
4/** @file
5 *
6 * ACPI data structures
7 *
8 */
9
10FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
11FILE_SECBOOT ( PERMITTED );
12
13#include <stdint.h>
14#include <byteswap.h>
15#include <ipxe/refcnt.h>
16#include <ipxe/list.h>
17#include <ipxe/interface.h>
18#include <ipxe/tables.h>
19#include <ipxe/api.h>
20#include <config/general.h>
21
22/** An ACPI generic address structure */
24 /** Address space type */
26 /** Register bit width */
28 /** Register bit offset */
30 /** Access size */
32 /** Address */
34} __attribute__ (( packed ));
35
36/** A memory address space type */
37#define ACPI_ADDRESS_TYPE_MEM 0x00
38
39/** An I/O address space type */
40#define ACPI_ADDRESS_TYPE_IO 0x01
41
42/** A bus number address space type */
43#define ACPI_ADDRESS_TYPE_BUS 0x02
44
45/** An ACPI small resource descriptor header */
47 /** Tag byte */
49} __attribute__ (( packed ));
50
51/** ACPI small resource length mask */
52#define ACPI_SMALL_LEN_MASK 0x03
53
54/** An ACPI end resource descriptor */
55#define ACPI_END_RESOURCE 0x78
56
57/** An ACPI end resource descriptor */
59 /** Header */
61 /** Checksum */
63} __attribute__ (( packed ));
64
65/** An ACPI large resource descriptor header */
67 /** Tag byte */
69 /** Length of data items */
71} __attribute__ (( packed ));
72
73/** ACPI large resource flag */
74#define ACPI_LARGE 0x80
75
76/** An ACPI QWORD address space resource descriptor */
77#define ACPI_QWORD_ADDRESS_SPACE_RESOURCE 0x8a
78
79/** An ACPI QWORD address space resource descriptor */
81 /** Header */
83 /** Resource type */
85 /** General flags */
87 /** Type-specific flags */
89 /** Granularity */
91 /** Minimum address */
93 /** Maximum address */
95 /** Translation offset */
97 /** Length */
99} __attribute__ (( packed ));
100
101/** An ACPI resource descriptor */
103 /** Tag byte */
105 /** Small resource descriptor */
107 /** End resource descriptor */
109 /** Large resource descriptor */
111 /** QWORD address space resource descriptor */
113};
114
115/**
116 * Get ACPI resource tag
117 *
118 * @v res ACPI resource descriptor
119 * @ret tag Resource tag
120 */
121static inline unsigned int acpi_resource_tag ( union acpi_resource *res ) {
122
123 return ( ( res->tag & ACPI_LARGE ) ?
124 res->tag : ( res->tag & ~ACPI_SMALL_LEN_MASK ) );
125}
126
127/**
128 * Get length of ACPI small resource descriptor
129 *
130 * @v res Small resource descriptor
131 * @ret len Length of descriptor
132 */
133static inline size_t acpi_small_len ( struct acpi_small_resource *res ) {
134
135 return ( sizeof ( *res ) + ( res->tag & ACPI_SMALL_LEN_MASK ) );
136}
137
138/**
139 * Get length of ACPI large resource descriptor
140 *
141 * @v res Large resource descriptor
142 * @ret len Length of descriptor
143 */
144static inline size_t acpi_large_len ( struct acpi_large_resource *res ) {
145
146 return ( sizeof ( *res ) + le16_to_cpu ( res->len ) );
147}
148
149/**
150 * Get length of ACPI resource descriptor
151 *
152 * @v res ACPI resource descriptor
153 * @ret len Length of descriptor
154 */
155static inline size_t acpi_resource_len ( union acpi_resource *res ) {
156
157 return ( ( res->tag & ACPI_LARGE ) ?
158 acpi_large_len ( &res->large ) :
159 acpi_small_len ( &res->small ) );
160}
161
162/**
163 * Get next ACPI resource descriptor
164 *
165 * @v res ACPI resource descriptor
166 * @ret next Next ACPI resource descriptor
167 */
168static inline union acpi_resource *
170
171 return ( ( ( void * ) res ) + acpi_resource_len ( res ) );
172}
173
174/**
175 * An ACPI description header
176 *
177 * This is the structure common to the start of all ACPI system
178 * description tables.
179 */
181 /** ACPI signature (4 ASCII characters) */
183 /** Length of table, in bytes, including header */
185 /** ACPI Specification minor version number */
187 /** To make sum of entire table == 0 */
189 /** OEM identification */
190 char oem_id[6];
191 /** OEM table identification */
193 /** OEM revision number */
195 /** ASL compiler vendor ID */
197 /** ASL compiler revision number */
199} __attribute__ (( packed ));
200
201/**
202 * Transcribe ACPI table signature (for debugging)
203 *
204 * @v signature ACPI table signature
205 * @ret name ACPI table signature name
206 */
207static inline const char * acpi_name ( uint32_t signature ) {
208 static union {
210 char name[5];
211 } u;
212
213 u.signature = cpu_to_le32 ( signature );
214 return u.name;
215}
216
217/**
218 * Build ACPI signature
219 *
220 * @v a First character of ACPI signature
221 * @v b Second character of ACPI signature
222 * @v c Third character of ACPI signature
223 * @v d Fourth character of ACPI signature
224 * @ret signature ACPI signature
225 */
226#define ACPI_SIGNATURE( a, b, c, d ) \
227 ( ( (a) << 0 ) | ( (b) << 8 ) | ( (c) << 16 ) | ( (d) << 24 ) )
228
229/** Root System Description Pointer signature */
230#define RSDP_SIGNATURE { 'R', 'S', 'D', ' ', 'P', 'T', 'R', ' ' }
231
232/** Root System Description Pointer */
233struct acpi_rsdp {
234 /** Signature */
235 char signature[8];
236 /** To make sum of entire table == 0 */
238 /** OEM identification */
239 char oem_id[6];
240 /** Revision */
242 /** Physical address of RSDT */
244} __attribute__ (( packed ));
245
246/** Root System Description Table (RSDT) signature */
247#define RSDT_SIGNATURE ACPI_SIGNATURE ( 'R', 'S', 'D', 'T' )
248
249/** ACPI Root System Description Table (RSDT) */
250struct acpi_rsdt {
251 /** ACPI header */
253 /** ACPI table entries */
255} __attribute__ (( packed ));
256
257/** Fixed ACPI Description Table (FADT) signature */
258#define FADT_SIGNATURE ACPI_SIGNATURE ( 'F', 'A', 'C', 'P' )
259
260/** Fixed ACPI Description Table (FADT) */
261struct acpi_fadt {
262 /** ACPI header */
264 /** Physical address of FACS */
266 /** Physical address of DSDT */
268 /** Unused by iPXE */
270 /** PM1a Control Register Block */
272 /** PM1b Control Register Block */
274 /** PM2 Control Register Block */
276 /** PM Timer Control Register Block */
278} __attribute__ (( packed ));
279
280/** ACPI PM1 Control Register (within PM1a_CNT_BLK or PM1A_CNT_BLK) */
281#define ACPI_PM1_CNT 0
282#define ACPI_PM1_CNT_SLP_TYP(x) ( (x) << 10 ) /**< Sleep type */
283#define ACPI_PM1_CNT_SLP_EN ( 1 << 13 ) /**< Sleep enable */
284
285/** ACPI PM Timer Register (within PM_TMR_BLK) */
286#define ACPI_PM_TMR 0
287
288/** Differentiated System Description Table (DSDT) signature */
289#define DSDT_SIGNATURE ACPI_SIGNATURE ( 'D', 'S', 'D', 'T' )
290
291/** Secondary System Description Table (SSDT) signature */
292#define SSDT_SIGNATURE ACPI_SIGNATURE ( 'S', 'S', 'D', 'T' )
293
294/** An ACPI descriptor (used to construct ACPI tables) */
296 /** Reference count of containing object */
297 struct refcnt *refcnt;
298 /** Table model */
300 /** List of ACPI descriptors for this model */
302};
303
304/**
305 * Initialise ACPI descriptor
306 *
307 * @v desc ACPI descriptor
308 * @v model Table model
309 * @v refcnt Reference count
310 */
311static inline __attribute__ (( always_inline )) void
312acpi_init ( struct acpi_descriptor *desc, struct acpi_model *model,
313 struct refcnt *refcnt ) {
314
315 desc->refcnt = refcnt;
316 desc->model = model;
317 INIT_LIST_HEAD ( &desc->list );
318}
319
320/** An ACPI table model */
322 /** List of descriptors */
324 /**
325 * Check if ACPI descriptor is complete
326 *
327 * @v desc ACPI descriptor
328 * @ret rc Return status code
329 */
330 int ( * complete ) ( struct acpi_descriptor *desc );
331 /**
332 * Install ACPI tables
333 *
334 * @v install Installation method
335 * @ret rc Return status code
336 */
337 int ( * install ) ( int ( * install ) ( struct acpi_header *acpi ) );
338};
339
340/** ACPI models */
341#define ACPI_MODELS __table ( struct acpi_model, "acpi_models" )
342
343/** Declare an ACPI model */
344#define __acpi_model __table_entry ( ACPI_MODELS, 01 )
345
346/**
347 * Calculate static inline ACPI API function name
348 *
349 * @v _prefix Subsystem prefix
350 * @v _api_func API function
351 * @ret _subsys_func Subsystem API function
352 */
353#define ACPI_INLINE( _subsys, _api_func ) \
354 SINGLE_API_INLINE ( ACPI_PREFIX_ ## _subsys, _api_func )
355
356/**
357 * Provide an ACPI API implementation
358 *
359 * @v _prefix Subsystem prefix
360 * @v _api_func API function
361 * @v _func Implementing function
362 */
363#define PROVIDE_ACPI( _subsys, _api_func, _func ) \
364 PROVIDE_SINGLE_API ( ACPI_PREFIX_ ## _subsys, _api_func, _func )
365
366/**
367 * Provide a static inline ACPI API implementation
368 *
369 * @v _prefix Subsystem prefix
370 * @v _api_func API function
371 */
372#define PROVIDE_ACPI_INLINE( _subsys, _api_func ) \
373 PROVIDE_SINGLE_API_INLINE ( ACPI_PREFIX_ ## _subsys, _api_func )
374
375extern const struct acpi_header * acpi_find_via_rsdt ( uint32_t signature,
376 unsigned int index );
377
378/* Include all architecture-independent ACPI API headers */
379#include <ipxe/null_acpi.h>
380#include <ipxe/efi/efi_acpi.h>
382
383/* Include all architecture-dependent ACPI API headers */
384#include <bits/acpi.h>
385
386/**
387 * Locate ACPI root system description table
388 *
389 * @ret rsdt ACPI root system description table, or NULL
390 */
391const struct acpi_rsdt * acpi_find_rsdt ( void );
392
393/**
394 * Locate ACPI table
395 *
396 * @v signature Requested table signature
397 * @v index Requested index of table with this signature
398 * @ret table Table, or NULL if not found
399 */
400const struct acpi_header * acpi_find ( uint32_t signature,
401 unsigned int index );
402
403extern struct acpi_descriptor *
405#define acpi_describe_TYPE( object_type ) \
406 typeof ( struct acpi_descriptor * ( object_type ) )
407
408extern const struct acpi_header * ( * acpi_finder ) ( uint32_t signature,
409 unsigned int index );
410
411extern void acpi_fix_checksum ( struct acpi_header *acpi );
412extern const struct acpi_header * acpi_table ( uint32_t signature,
413 unsigned int index );
414extern int acpi_extract ( uint32_t signature, void *data,
415 int ( * extract ) ( const struct acpi_header *zsdt,
416 size_t len, size_t offset,
417 void *data ) );
418extern void * acpi_ioremap ( struct acpi_address *address, size_t len );
419extern void acpi_add ( struct acpi_descriptor *desc );
420extern void acpi_del ( struct acpi_descriptor *desc );
421extern int acpi_install ( int ( * install ) ( struct acpi_header *acpi ) );
422
423#endif /* _IPXE_ACPI_H */
u8 signature
CPU signature.
Definition CIB_PRM.h:7
iPXE internal APIs
unsigned short uint16_t
Definition stdint.h:11
unsigned int uint32_t
Definition stdint.h:12
unsigned long long uint64_t
Definition stdint.h:13
unsigned char uint8_t
Definition stdint.h:10
x86-specific ACPI API implementations
long index
Definition bigint.h:65
const char * name
Definition ath9k_hw.c:1986
uint16_t offset
Offset to command line.
Definition bzimage.h:3
union @104331263140136355135267063077374276003064103115 u
ring len
Length.
Definition dwmac.h:226
iPXE ACPI API for EFI
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
uint64_t address
Base address.
Definition ena.h:13
struct ena_llq_option desc
Descriptor counts.
Definition ena.h:9
General configuration.
#define FILE_LICENCE(_licence)
Declare a particular licence as applying to a file.
Definition compiler.h:896
#define FILE_SECBOOT(_status)
Declare a file's UEFI Secure Boot permission status.
Definition compiler.h:926
#define le16_to_cpu(value)
Definition byteswap.h:113
#define cpu_to_le32(value)
Definition byteswap.h:108
#define __attribute__(x)
Definition compiler.h:10
static const char * acpi_name(uint32_t signature)
Transcribe ACPI table signature (for debugging)
Definition acpi.h:207
const struct acpi_header * acpi_table(uint32_t signature, unsigned int index)
Locate ACPI table.
Definition acpi.c:93
static size_t acpi_small_len(struct acpi_small_resource *res)
Get length of ACPI small resource descriptor.
Definition acpi.h:133
const struct acpi_rsdt * acpi_find_rsdt(void)
Locate ACPI root system description table.
void acpi_del(struct acpi_descriptor *desc)
Remove ACPI descriptor.
Definition acpi.c:307
int acpi_install(int(*install)(struct acpi_header *acpi))
Install ACPI tables.
Definition acpi.c:344
void acpi_add(struct acpi_descriptor *desc)
Add ACPI descriptor.
Definition acpi.c:295
void acpi_fix_checksum(struct acpi_header *acpi)
Fix up ACPI table checksum.
Definition acpi.c:80
static unsigned int acpi_resource_tag(union acpi_resource *res)
Get ACPI resource tag.
Definition acpi.h:121
const struct acpi_header * acpi_find_via_rsdt(uint32_t signature, unsigned int index)
Locate ACPI table via RSDT.
Definition acpi.c:106
#define ACPI_LARGE
ACPI large resource flag.
Definition acpi.h:74
#define ACPI_SMALL_LEN_MASK
ACPI small resource length mask.
Definition acpi.h:52
struct acpi_descriptor * acpi_describe(struct interface *interface)
Get object's ACPI descriptor.
Definition acpi.c:321
static size_t acpi_resource_len(union acpi_resource *res)
Get length of ACPI resource descriptor.
Definition acpi.h:155
static void acpi_init(struct acpi_descriptor *desc, struct acpi_model *model, struct refcnt *refcnt)
Initialise ACPI descriptor.
Definition acpi.h:312
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.
Definition acpi.c:228
static size_t acpi_large_len(struct acpi_large_resource *res)
Get length of ACPI large resource descriptor.
Definition acpi.h:144
const struct acpi_header * acpi_find(uint32_t signature, unsigned int index)
Locate ACPI table.
Definition rsdp.h:27
static union acpi_resource * acpi_resource_next(union acpi_resource *res)
Get next ACPI resource descriptor.
Definition acpi.h:169
void * acpi_ioremap(struct acpi_address *address, size_t len)
Map an ACPI generic address.
Definition acpi.c:270
Object interfaces.
iPXE ACPI API for Linux
Linked lists.
#define INIT_LIST_HEAD(list)
Initialise a list head.
Definition list.h:46
Standard do-nothing ACPI interface.
Reference counting.
An ACPI generic address structure.
Definition acpi.h:23
uint8_t type
Address space type.
Definition acpi.h:25
uint8_t offset
Register bit offset.
Definition acpi.h:29
uint64_t address
Address.
Definition acpi.h:33
uint8_t access
Access size.
Definition acpi.h:31
uint8_t width
Register bit width.
Definition acpi.h:27
An ACPI descriptor (used to construct ACPI tables)
Definition acpi.h:295
struct refcnt * refcnt
Reference count of containing object.
Definition acpi.h:297
struct acpi_model * model
Table model.
Definition acpi.h:299
struct list_head list
List of ACPI descriptors for this model.
Definition acpi.h:301
An ACPI end resource descriptor.
Definition acpi.h:58
uint8_t checksum
Checksum.
Definition acpi.h:62
struct acpi_small_resource hdr
Header.
Definition acpi.h:60
Fixed ACPI Description Table (FADT)
Definition acpi.h:261
uint32_t pm_tmr_blk
PM Timer Control Register Block.
Definition acpi.h:277
uint32_t dsdt
Physical address of DSDT.
Definition acpi.h:267
uint8_t unused[20]
Unused by iPXE.
Definition acpi.h:269
struct acpi_header acpi
ACPI header.
Definition acpi.h:263
uint32_t pm1a_cnt_blk
PM1a Control Register Block.
Definition acpi.h:271
uint32_t pm1b_cnt_blk
PM1b Control Register Block.
Definition acpi.h:273
uint32_t facs
Physical address of FACS.
Definition acpi.h:265
uint32_t pm2_cnt_blk
PM2 Control Register Block.
Definition acpi.h:275
An ACPI description header.
Definition acpi.h:180
uint32_t signature
ACPI signature (4 ASCII characters)
Definition acpi.h:182
uint32_t asl_compiler_revision
ASL compiler revision number.
Definition acpi.h:198
uint32_t length
Length of table, in bytes, including header.
Definition acpi.h:184
char asl_compiler_id[4]
ASL compiler vendor ID.
Definition acpi.h:196
uint8_t checksum
To make sum of entire table == 0.
Definition acpi.h:188
char oem_id[6]
OEM identification.
Definition acpi.h:190
uint8_t revision
ACPI Specification minor version number.
Definition acpi.h:186
uint32_t oem_revision
OEM revision number.
Definition acpi.h:194
char oem_table_id[8]
OEM table identification.
Definition acpi.h:192
An ACPI large resource descriptor header.
Definition acpi.h:66
uint8_t tag
Tag byte.
Definition acpi.h:68
uint16_t len
Length of data items.
Definition acpi.h:70
An ACPI table model.
Definition acpi.h:321
int(* complete)(struct acpi_descriptor *desc)
Check if ACPI descriptor is complete.
Definition acpi.h:330
int(* install)(int(*install)(struct acpi_header *acpi))
Install ACPI tables.
Definition acpi.h:337
struct list_head descs
List of descriptors.
Definition acpi.h:323
An ACPI QWORD address space resource descriptor.
Definition acpi.h:80
uint64_t granularity
Granularity.
Definition acpi.h:90
uint64_t min
Minimum address.
Definition acpi.h:92
struct acpi_large_resource hdr
Header.
Definition acpi.h:82
uint8_t general
General flags.
Definition acpi.h:86
uint8_t type
Resource type.
Definition acpi.h:84
uint8_t specific
Type-specific flags.
Definition acpi.h:88
uint64_t offset
Translation offset.
Definition acpi.h:96
uint64_t max
Maximum address.
Definition acpi.h:94
Root System Description Pointer.
Definition acpi.h:233
uint32_t rsdt
Physical address of RSDT.
Definition acpi.h:243
char signature[8]
Signature.
Definition acpi.h:235
uint8_t checksum
To make sum of entire table == 0.
Definition acpi.h:237
char oem_id[6]
OEM identification.
Definition acpi.h:239
uint8_t revision
Revision.
Definition acpi.h:241
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
An ACPI small resource descriptor header.
Definition acpi.h:46
uint8_t tag
Tag byte.
Definition acpi.h:48
An object interface.
Definition interface.h:125
A doubly-linked list entry (or list head)
Definition list.h:19
A reference counter.
Definition refcnt.h:27
Linker tables.
An ACPI resource descriptor.
Definition acpi.h:102
struct acpi_large_resource large
Large resource descriptor.
Definition acpi.h:110
struct acpi_small_resource small
Small resource descriptor.
Definition acpi.h:106
struct acpi_end_resource end
End resource descriptor.
Definition acpi.h:108
struct acpi_qword_address_space_resource qword
QWORD address space resource descriptor.
Definition acpi.h:112
uint8_t tag
Tag byte.
Definition acpi.h:104