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