The Pedigree Project  0.1
Acpi.h
1 /*
2  * Copyright (c) 2008-2014, Pedigree Developers
3  *
4  * Please see the CONTRIB file in the root of the source tree for a full
5  * list of contributors.
6  *
7  * Permission to use, copy, modify, and distribute this software for any
8  * purpose with or without fee is hereby granted, provided that the above
9  * copyright notice and this permission notice appear in all copies.
10  *
11  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
12  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
13  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
14  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
15  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
16  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
17  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
18  */
19 
20 #ifndef KERNEL_MACHINE_X86_COMMON_ACPI_H
21 #define KERNEL_MACHINE_X86_COMMON_ACPI_H
22 
23 #if defined(ACPI)
24 
25 #include "../../core/processor/x86_common/Multiprocessor.h"
26 #include "pedigree/kernel/compiler.h"
27 #include "pedigree/kernel/processor/MemoryRegion.h"
28 #include "pedigree/kernel/processor/types.h"
29 #include "pedigree/kernel/utilities/Vector.h"
30 #include "pedigree/kernel/utilities/new"
31 
36 class Acpi
37 {
38  public:
40  inline static Acpi &instance()
41  {
42  return m_Instance;
43  }
44 
47  void initialise() INITIALISATION_ONLY;
48 
49 #if defined(APIC)
50  inline bool validApicInfo() const
51  {
52  return m_bValidApicInfo;
53  }
54  inline uint64_t getLocalApicAddress() const
55  {
56  return m_LocalApicAddress;
57  }
59  getIoApicList() const
60  {
61  return m_IoApics;
62  }
63 
64 #if defined(MULTIPROCESSOR)
65  inline bool validProcessorInfo() const
66  {
67  return m_bValidProcessorInfo;
68  }
70  getProcessorList() const
71  {
72  return m_Processors;
73  }
74 #endif
75 #endif
76 
77  private:
79  Acpi() INITIALISATION_ONLY;
82  Acpi(const Acpi &);
85  Acpi &operator=(const Acpi &);
87  inline ~Acpi()
88  {
89  }
90 
91  struct RsdtPointer
92  {
93  // ACPI 1.0+
94  uint64_t signature;
95  uint8_t checksum;
96  char oemId[6];
97  uint8_t revision;
98  uint32_t rsdtAddress;
99 
100  // ACPI 2.0+
101  uint32_t length;
102  uint64_t xsdtAddress;
103  uint8_t extendedChecksum;
104  uint8_t reserved[3];
105  } PACKED;
106 
107  struct SystemDescriptionTableHeader
108  {
109  uint32_t signature;
110  uint32_t length;
111  uint8_t revision;
112  uint8_t checksum;
113  char oemId[6];
114  char oemTableId[8];
115  uint32_t oemRevision;
116  uint32_t creatorId;
117  uint32_t creatorRevision;
118  } PACKED;
119 
120  struct FixedACPIDescriptionTable
121  {
122  SystemDescriptionTableHeader header;
123 
124  uint32_t firmwareControl;
125  uint32_t dsdt;
126  uint8_t interruptModel;
127  uint8_t reserved0;
128  uint16_t sciInterrupt;
129  uint32_t smiCommandPort;
130  uint8_t acpiEnableCommand;
131  uint8_t acpiDisableCommand;
132  uint8_t s4BiosCommand;
133  uint8_t reserved1;
134  uint32_t pm1aEventBlock;
135  uint32_t pm1bEventBlock;
136  uint32_t pm1aControlBlock;
137  uint32_t pm1bControlBlock;
138  uint32_t pm2ControlBlock;
139  uint32_t pmTimerBlock;
140  uint32_t gpe0Block;
141  uint32_t gpe1Block;
142  uint8_t pm1EventLength;
143  uint8_t pm1ControlLength;
144  uint8_t pm2ControlLength;
145  uint8_t pmTimerLength;
146  uint8_t gpe0BlockLength;
147  uint8_t gpe1BlockLength;
148  uint8_t gpe1Base;
149  uint8_t reserved2;
150  uint16_t pmLevel2Latency;
151  uint16_t pmLevel3Latency;
152  uint16_t flushSize;
153  uint16_t flushStride;
154  uint8_t dutyOffset;
155  uint8_t dutyWidth;
156  uint8_t cmosDayAlarmIndex;
157  uint8_t cmosMonthAlarmIndex;
158  uint8_t cmosCenturyIndex;
159  uint8_t reserved3[3];
160  uint32_t flags;
161  } PACKED;
162 
163  struct ProcessorLocalApic
164  {
165  uint8_t processorId;
166  uint8_t apicId;
167  uint32_t flags;
168  } PACKED;
169 
170  struct IoApic
171  {
172  uint8_t apicId;
173  uint8_t reserved;
174  uint32_t address;
175  uint32_t globalSystemInterruptBase;
176  } PACKED;
177 
178  struct InterruptSourceOverride
179  {
180  uint8_t bus;
181  uint8_t source;
182  uint8_t globalSystemInterrupt;
183  uint16_t flags;
184  } PACKED;
185 
186  void parseFixedACPIDescriptionTable() INITIALISATION_ONLY;
187 #if defined(APIC)
188  void parseMultipleApicDescriptionTable() INITIALISATION_ONLY;
189 #endif
190  bool find() INITIALISATION_ONLY;
191  RsdtPointer *find(void *pMemory, size_t sMemory) INITIALISATION_ONLY;
192  bool checksum(const RsdtPointer *pRdstPointer) INITIALISATION_ONLY;
193  bool
194  checksum(const SystemDescriptionTableHeader *pHeader) INITIALISATION_ONLY;
195 
196  bool m_bValid;
197  RsdtPointer *m_pRsdtPointer;
198  MemoryRegion m_AcpiMemoryRegion;
199  SystemDescriptionTableHeader *m_pRsdt;
200  FixedACPIDescriptionTable *m_pFacp;
201 
202 #if defined(APIC)
203  SystemDescriptionTableHeader *m_pApic;
204 
205  bool m_bValidApicInfo;
206  bool m_bHasPICs;
207  uint64_t m_LocalApicAddress;
209 
210 #if defined(MULTIPROCESSOR)
211  bool m_bValidProcessorInfo;
213 #endif
214 #endif
215 
216  static Acpi m_Instance;
217 };
218 
221 #endif
222 
223 #endif
A vector / dynamic array.
Special memory entity in the kernel's virtual address space.
Definition: MemoryRegion.h:35