Pyrogenesis  trunk
acpi.h
Go to the documentation of this file.
1 /* Copyright (c) 2010 Wildfire Games
2  *
3  * Permission is hereby granted, free of charge, to any person obtaining
4  * a copy of this software and associated documentation files (the
5  * "Software"), to deal in the Software without restriction, including
6  * without limitation the rights to use, copy, modify, merge, publish,
7  * distribute, sublicense, and/or sell copies of the Software, and to
8  * permit persons to whom the Software is furnished to do so, subject to
9  * the following conditions:
10  *
11  * The above copyright notice and this permission notice shall be included
12  * in all copies or substantial portions of the Software.
13  *
14  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
17  * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
18  * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
19  * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
20  * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
21  */
22 
23 /*
24  * minimal subset of ACPI
25  */
26 
27 #ifndef INCLUDED_ACPI
28 #define INCLUDED_ACPI
29 
30 #pragma pack(push, 1)
31 
32 // common header for all ACPI tables
33 struct AcpiTable
34 {
35  char signature[4];
36  u32 size; // table size [bytes], including header
38  u8 checksum; // to make sum of entire table == 0
39  char oemId[6];
40  char oemTableId[8];
42  char creatorId[4];
44 };
45 
47 {
48  // (these are not generally powers-of-two - some values have been omitted.)
53 };
54 
55 // address of a struct or register
57 {
63 };
64 
65 struct FADT // signature is FACP!
66 {
68  u8 unused1[40];
70  u8 unused2[16];
71  u16 c2Latency; // [us]
72  u16 c3Latency; // [us]
73  u8 unused3[5];
75  u8 unused4[6];
77  // (ACPI4 defines additional fields after this)
78 
79  bool IsDutyCycleSupported() const
80  {
81  return dutyWidth != 0;
82  }
83 
84  bool IsC2Supported() const
85  {
86  return c2Latency <= 100; // magic value specified by ACPI
87  }
88 
89  bool IsC3Supported() const
90  {
91  return c3Latency <= 1000; // see above
92  }
93 };
94 
95 #pragma pack(pop)
96 
97 /**
98  * @param signature e.g. "RSDT"
99  * @return pointer to internal storage (valid until acpi_Shutdown())
100  *
101  * note: the first call may be slow, e.g. if a kernel-mode driver is
102  * loaded. subsequent requests will be faster since tables are cached.
103  **/
104 LIB_API const AcpiTable* acpi_GetTable(const char* signature);
105 
106 /**
107  * invalidates all pointers returned by acpi_GetTable.
108  **/
109 LIB_API void acpi_Shutdown();
110 
111 #endif // #ifndef INCLUDED_ACPI
LIB_API void acpi_Shutdown()
invalidates all pointers returned by acpi_GetTable.
Definition: acpi.cpp:346
u8 registerBitOffset
Definition: acpi.h:60
u16 c2Latency
Definition: acpi.h:71
u32 creatorRevision
Definition: acpi.h:43
Definition: acpi.h:51
uint16_t u16
Definition: types.h:38
u8 addressSpaceId
Definition: acpi.h:58
u8 accessSize
Definition: acpi.h:61
char oemId[6]
Definition: acpi.h:39
u16 c3Latency
Definition: acpi.h:72
u64 address
Definition: acpi.h:62
Definition: acpi.h:56
char signature[4]
Definition: acpi.h:35
LIB_API const AcpiTable * acpi_GetTable(const char *signature)
Definition: acpi.cpp:362
uint8_t u8
Definition: types.h:37
u32 size
Definition: acpi.h:36
uint64_t u64
Definition: types.h:40
u32 flags
Definition: acpi.h:76
bool IsC3Supported() const
Definition: acpi.h:89
AcpiAddressSpace
Definition: acpi.h:46
u32 oemRevision
Definition: acpi.h:41
Definition: acpi.h:49
uint32_t u32
Definition: types.h:39
u32 pmTimerPortAddress
Definition: acpi.h:69
u8 dutyWidth
Definition: acpi.h:74
char creatorId[4]
Definition: acpi.h:42
u8 checksum
Definition: acpi.h:38
Definition: acpi.h:52
bool IsC2Supported() const
Definition: acpi.h:84
Definition: acpi.h:50
u8 revision
Definition: acpi.h:37
Definition: acpi.h:33
bool IsDutyCycleSupported() const
Definition: acpi.h:79
Definition: acpi.h:65
char oemTableId[8]
Definition: acpi.h:40
AcpiTable header
Definition: acpi.h:67
u8 registerBitWidth
Definition: acpi.h:59