The Pedigree Project 0.1
mach_pc/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#include <config.h>
23
24#if ACPI
25
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
32#include "../../core/processor/x86_common/Multiprocessor.h"
33#include "AcpiDmar.h"
34#include "AcpiPciRouting.h"
35
36class Device;
37
42class Acpi {
43 public:
45 inline static Acpi& instance() {
46 return m_Instance;
47 }
48
51 void initialise() INITIALISATION_ONLY;
52
53 bool supportsPowerOff() const;
54 struct PowerManagement {
55 bool (*prepare)(bool powerOff);
56 const char* (*powerOff)();
57 void (*reset)();
58 };
60 EXPORTED_PUBLIC void setPowerManagement(const PowerManagement* provider);
61 bool prepareShutdown(bool powerOff);
62 const char* powerOff();
63 void reset();
64
65 uint8_t getRtcCenturyIndex() const {
66 return m_bValid ? m_pFacp->cmosCenturyIndex : 0;
67 }
68
69 bool getPmTimerPort(uint16_t& port, uint32_t& mask) const;
70
71 bool pciConfigurationAddress(uint8_t bus, uint64_t& address) const;
72 bool pciBusRange(uint8_t& first, uint8_t& last) const;
73 bool pciInterruptRoute(uint8_t slot, uint8_t pin, AcpiPciRouting::Route& route) const;
74 bool pciInterruptRoute(Device* device, uint8_t pin, AcpiPciRouting::Route& route) const;
75 using PciInterruptRouter = bool (*)(Device*, uint8_t, AcpiPciRouting::Route&);
76 EXPORTED_PUBLIC void setPciInterruptRouter(PciInterruptRouter router);
77 bool hasPciInterruptRouter() const;
78 bool isaIrqsForGsi(uint32_t gsi, uint16_t& irqs) const;
79
80 const AcpiDmar::Info* dmarInfo() const {
81 return m_bValid && m_DmarPresent ? &m_DmarInfo : nullptr;
82 }
83
84#if MULTIPROCESSOR
85 inline bool validApicInfo() const {
86 return m_bValidApicInfo;
87 }
88 inline uint64_t getLocalApicAddress() const {
89 return m_LocalApicAddress;
90 }
91 inline const Vector<Multiprocessor::IoApicInformation*>& getIoApicList() const {
92 return m_IoApics;
93 }
94
95 inline bool validProcessorInfo() const {
96 return m_bValidProcessorInfo;
97 }
98 inline const Vector<Multiprocessor::ProcessorInformation*>& getProcessorList() const {
99 return m_Processors;
100 }
101#endif
102
103 private:
105 Acpi() INITIALISATION_ONLY;
108 Acpi(const Acpi&);
111 Acpi& operator=(const Acpi&);
113 inline ~Acpi() {}
114
115 struct RsdtPointer {
116 // ACPI 1.0+
117 uint64_t signature;
118 uint8_t checksum;
119 char oemId[6];
120 uint8_t revision;
121 uint32_t rsdtAddress;
122
123 // ACPI 2.0+
124 uint32_t length;
125 uint64_t xsdtAddress;
126 uint8_t extendedChecksum;
127 uint8_t reserved[3];
128 } PACKED;
129
130 struct SystemDescriptionTableHeader {
131 uint32_t signature;
132 uint32_t length;
133 uint8_t revision;
134 uint8_t checksum;
135 char oemId[6];
136 char oemTableId[8];
137 uint32_t oemRevision;
138 uint32_t creatorId;
139 uint32_t creatorRevision;
140 } PACKED;
141
142 struct PciConfigurationRange {
143 uint64_t base;
144 uint16_t segment;
145 uint8_t firstBus;
146 uint8_t lastBus;
147 uint32_t reserved;
148 } PACKED;
149
150 struct FixedACPIDescriptionTable {
151 SystemDescriptionTableHeader header;
152
153 uint32_t firmwareControl;
154 uint32_t dsdt;
155 uint8_t interruptModel;
156 uint8_t reserved0;
157 uint16_t sciInterrupt;
158 uint32_t smiCommandPort;
159 uint8_t acpiEnableCommand;
160 uint8_t acpiDisableCommand;
161 uint8_t s4BiosCommand;
162 uint8_t reserved1;
163 uint32_t pm1aEventBlock;
164 uint32_t pm1bEventBlock;
165 uint32_t pm1aControlBlock;
166 uint32_t pm1bControlBlock;
167 uint32_t pm2ControlBlock;
168 uint32_t pmTimerBlock;
169 uint32_t gpe0Block;
170 uint32_t gpe1Block;
171 uint8_t pm1EventLength;
172 uint8_t pm1ControlLength;
173 uint8_t pm2ControlLength;
174 uint8_t pmTimerLength;
175 uint8_t gpe0BlockLength;
176 uint8_t gpe1BlockLength;
177 uint8_t gpe1Base;
178 uint8_t reserved2;
179 uint16_t pmLevel2Latency;
180 uint16_t pmLevel3Latency;
181 uint16_t flushSize;
182 uint16_t flushStride;
183 uint8_t dutyOffset;
184 uint8_t dutyWidth;
185 uint8_t cmosDayAlarmIndex;
186 uint8_t cmosMonthAlarmIndex;
187 uint8_t cmosCenturyIndex;
188 uint8_t reserved3[3];
189 uint32_t flags;
190 } PACKED;
191
192 struct ProcessorLocalApic {
193 uint8_t processorId;
194 uint8_t apicId;
195 uint32_t flags;
196 } PACKED;
197
198 struct IoApic {
199 uint8_t apicId;
200 uint8_t reserved;
201 uint32_t address;
202 uint32_t globalSystemInterruptBase;
203 } PACKED;
204
205 struct InterruptSourceOverride {
206 uint8_t bus;
207 uint8_t source;
208 uint32_t globalSystemInterrupt;
209 uint16_t flags;
210 } PACKED;
211
212 void parseFixedACPIDescriptionTable() INITIALISATION_ONLY;
213 void initialisePowerManagement() INITIALISATION_ONLY;
214#if MULTIPROCESSOR
215 void parseMultipleApicDescriptionTable() INITIALISATION_ONLY;
216#endif
217 bool find() INITIALISATION_ONLY;
218 bool checksum(const RsdtPointer* pRdstPointer) INITIALISATION_ONLY;
219 bool checksum(const SystemDescriptionTableHeader* pHeader) INITIALISATION_ONLY;
220
221 bool m_bValid;
222 RsdtPointer* m_pRsdtPointer;
223 MemoryRegion m_AcpiMemoryRegion;
224 SystemDescriptionTableHeader* m_pRsdt;
225 FixedACPIDescriptionTable* m_pFacp;
226 Vector<PciConfigurationRange> m_PciConfigurationRanges;
227 AcpiDmar::Info m_DmarInfo;
228 AcpiPciRouting::Route m_PciInterruptRoutes[32][4];
229 bool m_PciInterruptRoutesPresent = false;
230 PciInterruptRouter m_PciInterruptRouter = nullptr;
231 uint32_t m_IsaGsis[16] = {};
232 uint16_t m_IsaOverrides = 0;
233 bool m_IsaRoutingValid = true;
234 Vector<uint32_t> m_NmiGsis;
235 bool m_DmarPresent = false;
236 bool m_DmarSeen = false;
237 bool m_PowerOffValid = false;
238 const PowerManagement* m_PowerManagement = nullptr;
239 uint8_t m_SleepTypeA = 0;
240 uint8_t m_SleepTypeB = 0;
241 uint16_t m_ResetPort = 0;
242 uint8_t m_ResetValue = 0;
243
244#if MULTIPROCESSOR
245 SystemDescriptionTableHeader* m_pApic;
246
247 bool m_bValidApicInfo;
248 bool m_bHasPICs;
249 uint64_t m_LocalApicAddress;
251
252 bool m_bValidProcessorInfo;
254#endif
255
256 static EXPORTED_PUBLIC Acpi m_Instance;
257};
258
261#endif
262
263#endif
Special memory entity in the kernel's virtual address space.
A vector / dynamic array.
Definition Vector.h:33