-
Notifications
You must be signed in to change notification settings - Fork 389
Expand file tree
/
Copy pathacpi.hpp
More file actions
142 lines (122 loc) · 3.21 KB
/
acpi.hpp
File metadata and controls
142 lines (122 loc) · 3.21 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
// This file is a part of the IncludeOS unikernel - www.includeos.org
//
// Copyright 2015 Oslo and Akershus University College of Applied Sciences
// and Alfred Bratterud
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#pragma once
#ifndef X86_ACPI_HPP
#define X86_ACPI_HPP
#include <cstdint>
#include <cstddef>
#include <vector>
#include <smp_utils>
#ifdef INCLUDEOS_SMP_ENABLE
#include <mutex>
#endif
namespace x86 {
struct SDTHeader;
class ACPI {
public:
struct LAPIC {
uint8_t type;
uint8_t length;
uint8_t cpu;
uint8_t id;
uint32_t flags;
};
struct IOAPIC {
uint8_t type;
uint8_t length;
uint8_t id;
uint8_t reserved;
uint32_t addr_base;
uint32_t intr_base;
};
struct override_t {
uint8_t type;
uint8_t length;
uint8_t bus_source;
uint8_t irq_source;
uint32_t global_intr;
uint16_t flags;
} __attribute__((packed));
struct nmi_t {
uint8_t type;
uint8_t length;
uint8_t cpu;
uint16_t flags;
uint8_t lint;
} __attribute__((packed));
typedef std::pmr::vector<LAPIC> lapic_list;
typedef std::pmr::vector<IOAPIC> ioapic_list;
typedef std::pmr::vector<override_t> override_list;
typedef std::pmr::vector<nmi_t> nmi_list;
static void init() {
get().discover();
}
static uint64_t time();
static ACPI& get() {
#ifdef INCLUDEOS_SMP_ENABLE
static Spinlock lock;
std::lock_guard<Spinlock> guard(lock);
#endif
static ACPI acpi;
return acpi;
}
static const auto& get_cpus() {
return get().lapics;
}
static const auto& get_ioapics() {
return get().ioapics;
}
static const auto& get_overrides() {
return get().overrides;
}
static const auto& get_nmis() {
return get().nmis;
}
uint8_t cmos_century() const noexcept {
return century;
}
static void reboot();
[[noreturn]] static void shutdown();
private:
void discover();
uint8_t checksum(const char*, size_t) const noexcept;
void begin(const void* addr);
void walk_sdts(SDTHeader* addr);
void walk_madt(const char* addr);
void walk_facp(const char* addr);
uintptr_t hpet_base;
uintptr_t apic_base;
ioapic_list ioapics;
lapic_list lapics;
override_list overrides;
nmi_list nmis;
// shutdown related
void acpi_shutdown();
uint32_t* SMI_CMD;
uint8_t ACPI_ENABLE;
uint8_t ACPI_DISABLE;
uint32_t PM1a_CNT;
uint32_t PM1b_CNT;
uint16_t SLP_TYPa;
uint16_t SLP_TYPb;
uint16_t SLP_EN;
uint16_t SCI_EN;
uint8_t PM1_CNT_LEN;
uint8_t century;
};
}
#endif