iPXE
acpi.h
Go to the documentation of this file.
00001 #ifndef _IPXE_ACPI_H
00002 #define _IPXE_ACPI_H
00003 
00004 /** @file
00005  *
00006  * ACPI data structures
00007  *
00008  */
00009 
00010 FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
00011 
00012 #include <stdint.h>
00013 #include <byteswap.h>
00014 #include <ipxe/refcnt.h>
00015 #include <ipxe/list.h>
00016 #include <ipxe/interface.h>
00017 #include <ipxe/uaccess.h>
00018 #include <ipxe/tables.h>
00019 #include <ipxe/api.h>
00020 #include <config/general.h>
00021 
00022 /**
00023  * An ACPI description header
00024  *
00025  * This is the structure common to the start of all ACPI system
00026  * description tables.
00027  */
00028 struct acpi_header {
00029         /** ACPI signature (4 ASCII characters) */
00030         uint32_t signature;
00031         /** Length of table, in bytes, including header */
00032         uint32_t length;
00033         /** ACPI Specification minor version number */
00034         uint8_t revision;
00035         /** To make sum of entire table == 0 */
00036         uint8_t checksum;
00037         /** OEM identification */
00038         char oem_id[6];
00039         /** OEM table identification */
00040         char oem_table_id[8];
00041         /** OEM revision number */
00042         uint32_t oem_revision;
00043         /** ASL compiler vendor ID */
00044         char asl_compiler_id[4];
00045         /** ASL compiler revision number */
00046         uint32_t asl_compiler_revision;
00047 } __attribute__ (( packed ));
00048 
00049 /**
00050  * Transcribe ACPI table signature (for debugging)
00051  *
00052  * @v signature         ACPI table signature
00053  * @ret name            ACPI table signature name
00054  */
00055 static inline const char * acpi_name ( uint32_t signature ) {
00056         static union {
00057                 uint32_t signature;
00058                 char name[5];
00059         } u;
00060 
00061         u.signature = cpu_to_le32 ( signature );
00062         return u.name;
00063 }
00064 
00065 /**
00066  * Build ACPI signature
00067  *
00068  * @v a                 First character of ACPI signature
00069  * @v b                 Second character of ACPI signature
00070  * @v c                 Third character of ACPI signature
00071  * @v d                 Fourth character of ACPI signature
00072  * @ret signature       ACPI signature
00073  */
00074 #define ACPI_SIGNATURE( a, b, c, d ) \
00075         ( ( (a) << 0 ) | ( (b) << 8 ) | ( (c) << 16 ) | ( (d) << 24 ) )
00076 
00077 /** Root System Description Pointer signature */
00078 #define RSDP_SIGNATURE { 'R', 'S', 'D', ' ', 'P', 'T', 'R', ' ' }
00079 
00080 /** Root System Description Pointer */
00081 struct acpi_rsdp {
00082         /** Signature */
00083         char signature[8];
00084         /** To make sum of entire table == 0 */
00085         uint8_t checksum;
00086         /** OEM identification */
00087         char oem_id[6];
00088         /** Revision */
00089         uint8_t revision;
00090         /** Physical address of RSDT */
00091         uint32_t rsdt;
00092 } __attribute__ (( packed ));
00093 
00094 /** Root System Description Table (RSDT) signature */
00095 #define RSDT_SIGNATURE ACPI_SIGNATURE ( 'R', 'S', 'D', 'T' )
00096 
00097 /** ACPI Root System Description Table (RSDT) */
00098 struct acpi_rsdt {
00099         /** ACPI header */
00100         struct acpi_header acpi;
00101         /** ACPI table entries */
00102         uint32_t entry[0];
00103 } __attribute__ (( packed ));
00104 
00105 /** Fixed ACPI Description Table (FADT) signature */
00106 #define FADT_SIGNATURE ACPI_SIGNATURE ( 'F', 'A', 'C', 'P' )
00107 
00108 /** Fixed ACPI Description Table (FADT) */
00109 struct acpi_fadt {
00110         /** ACPI header */
00111         struct acpi_header acpi;
00112         /** Physical address of FACS */
00113         uint32_t facs;
00114         /** Physical address of DSDT */
00115         uint32_t dsdt;
00116         /** Unused by iPXE */
00117         uint8_t unused[20];
00118         /** PM1a Control Register Block */
00119         uint32_t pm1a_cnt_blk;
00120         /** PM1b Control Register Block */
00121         uint32_t pm1b_cnt_blk;
00122         /** PM2 Control Register Block */
00123         uint32_t pm2_cnt_blk;
00124         /** PM Timer Control Register Block */
00125         uint32_t pm_tmr_blk;
00126 } __attribute__ (( packed ));
00127 
00128 /** ACPI PM1 Control Register (within PM1a_CNT_BLK or PM1A_CNT_BLK) */
00129 #define ACPI_PM1_CNT 0
00130 #define ACPI_PM1_CNT_SLP_TYP(x) ( (x) << 10 )   /**< Sleep type */
00131 #define ACPI_PM1_CNT_SLP_EN ( 1 << 13 )         /**< Sleep enable */
00132 
00133 /** ACPI PM Timer Register (within PM_TMR_BLK) */
00134 #define ACPI_PM_TMR 0
00135 
00136 /** Differentiated System Description Table (DSDT) signature */
00137 #define DSDT_SIGNATURE ACPI_SIGNATURE ( 'D', 'S', 'D', 'T' )
00138 
00139 /** Secondary System Description Table (SSDT) signature */
00140 #define SSDT_SIGNATURE ACPI_SIGNATURE ( 'S', 'S', 'D', 'T' )
00141 
00142 /** An ACPI descriptor (used to construct ACPI tables) */
00143 struct acpi_descriptor {
00144         /** Reference count of containing object */
00145         struct refcnt *refcnt;
00146         /** Table model */
00147         struct acpi_model *model;
00148         /** List of ACPI descriptors for this model */
00149         struct list_head list;
00150 };
00151 
00152 /**
00153  * Initialise ACPI descriptor
00154  *
00155  * @v desc              ACPI descriptor
00156  * @v model             Table model
00157  * @v refcnt            Reference count
00158  */
00159 static inline __attribute__ (( always_inline )) void
00160 acpi_init ( struct acpi_descriptor *desc, struct acpi_model *model,
00161             struct refcnt *refcnt ) {
00162 
00163         desc->refcnt = refcnt;
00164         desc->model = model;
00165         INIT_LIST_HEAD ( &desc->list );
00166 }
00167 
00168 /** An ACPI table model */
00169 struct acpi_model {
00170         /** List of descriptors */
00171         struct list_head descs;
00172         /**
00173          * Check if ACPI descriptor is complete
00174          *
00175          * @v desc              ACPI descriptor
00176          * @ret rc              Return status code
00177          */
00178         int ( * complete ) ( struct acpi_descriptor *desc );
00179         /**
00180          * Install ACPI tables
00181          *
00182          * @v install           Installation method
00183          * @ret rc              Return status code
00184          */
00185         int ( * install ) ( int ( * install ) ( struct acpi_header *acpi ) );
00186 };
00187 
00188 /** ACPI models */
00189 #define ACPI_MODELS __table ( struct acpi_model, "acpi_models" )
00190 
00191 /** Declare an ACPI model */
00192 #define __acpi_model __table_entry ( ACPI_MODELS, 01 )
00193 
00194 /**
00195  * Calculate static inline ACPI API function name
00196  *
00197  * @v _prefix           Subsystem prefix
00198  * @v _api_func         API function
00199  * @ret _subsys_func    Subsystem API function
00200  */
00201 #define ACPI_INLINE( _subsys, _api_func ) \
00202         SINGLE_API_INLINE ( ACPI_PREFIX_ ## _subsys, _api_func )
00203 
00204 /**
00205  * Provide an ACPI API implementation
00206  *
00207  * @v _prefix           Subsystem prefix
00208  * @v _api_func         API function
00209  * @v _func             Implementing function
00210  */
00211 #define PROVIDE_ACPI( _subsys, _api_func, _func ) \
00212         PROVIDE_SINGLE_API ( ACPI_PREFIX_ ## _subsys, _api_func, _func )
00213 
00214 /**
00215  * Provide a static inline ACPI API implementation
00216  *
00217  * @v _prefix           Subsystem prefix
00218  * @v _api_func         API function
00219  */
00220 #define PROVIDE_ACPI_INLINE( _subsys, _api_func ) \
00221         PROVIDE_SINGLE_API_INLINE ( ACPI_PREFIX_ ## _subsys, _api_func )
00222 
00223 /* Include all architecture-independent ACPI API headers */
00224 #include <ipxe/null_acpi.h>
00225 #include <ipxe/efi/efi_acpi.h>
00226 
00227 /* Include all architecture-dependent ACPI API headers */
00228 #include <bits/acpi.h>
00229 
00230 /**
00231  * Locate ACPI root system description table
00232  *
00233  * @ret rsdt            ACPI root system description table, or UNULL
00234  */
00235 userptr_t acpi_find_rsdt ( void );
00236 
00237 extern struct acpi_descriptor *
00238 acpi_describe ( struct interface *interface );
00239 #define acpi_describe_TYPE( object_type )                               \
00240         typeof ( struct acpi_descriptor * ( object_type ) )
00241 
00242 extern void acpi_fix_checksum ( struct acpi_header *acpi );
00243 extern userptr_t acpi_find ( uint32_t signature, unsigned int index );
00244 extern int acpi_sx ( uint32_t signature );
00245 extern void acpi_add ( struct acpi_descriptor *desc );
00246 extern void acpi_del ( struct acpi_descriptor *desc );
00247 extern int acpi_install ( int ( * install ) ( struct acpi_header *acpi ) );
00248 
00249 #endif /* _IPXE_ACPI_H */