Iros
 
Loading...
Searching...
No Matches
system_tables.h
Go to the documentation of this file.
1#pragma once
2
4#include "di/util/prelude.h"
7
8namespace iris::acpi {
9auto validate_acpi_checksum(di::Span<byte const> data) -> bool;
10
37
41struct [[gnu::packed]] SDTHeader {
51
52 auto as_bytes() const -> di::Span<byte const> {
53 return di::Span { reinterpret_cast<byte const*>(this), this->length };
54 }
55
56 auto validate(usize min_length) const -> bool {
57 if (this->length < min_length) {
58 return false;
59 }
60 return validate_acpi_checksum(this->as_bytes());
61 }
62};
63
67struct [[gnu::packed]] RSDT : SDTHeader {
68 auto entries() const -> di::Span<u32 const> {
69 return di::Span { reinterpret_cast<u32 const*>(this + 1), (this->length - sizeof(SDTHeader)) / sizeof(u32) };
70 }
71};
72
102
109
111 return reinterpret_cast<InterruptControllerStructureHeader const*>(reinterpret_cast<byte const*>(this) +
112 this->length);
113 }
114
115 auto validate(usize min_length) const -> bool { return this->length >= min_length; }
116};
117
131
141
148struct [[gnu::packed]] MPSInterruptFlags {
149 enum class Polarity {
154 };
155
156 enum class TriggerMode {
158 Edge = 1,
160 Level = 3,
161 };
162
163 auto polarity() const -> Polarity { return Polarity(value & 0b11); }
164 auto trigger_mode() const -> TriggerMode { return TriggerMode((value & 0b1100) >> 2); }
165
167};
168
179
189
191 : public di::container::IteratorBase<InterruptControllerStructureIterator, di::ForwardIteratorTag,
192 InterruptControllerStructureHeader, isize> {
193public:
195
198 : m_current(current), m_end(end) {}
199
200 auto operator*() const -> InterruptControllerStructureHeader const& { return *m_current; }
201 auto operator->() const -> InterruptControllerStructureHeader const* { return m_current; }
202
203 auto validate(usize min_size) const -> bool {
204 auto const* readable_end = reinterpret_cast<byte const*>(m_current) + min_size;
205 return m_current->validate(min_size) && m_current->next() <= m_end &&
206 di::to_uintptr(readable_end) <= di::to_uintptr(m_end);
207 }
208
209 void advance_one() { m_current = m_current->next(); }
210
211 auto begin() const -> InterruptControllerStructureIterator { return *this; }
213 return InterruptControllerStructureIterator { m_end, m_end };
214 }
215
216private:
218 -> bool {
219 return a.m_current == b.m_current;
220 }
221
222 InterruptControllerStructureHeader const* m_current { nullptr };
223 InterruptControllerStructureHeader const* m_end { nullptr };
224};
225
229struct [[gnu::packed]] MADT : SDTHeader {
230 enum class Flags : u32 {
232 };
233
236
239 reinterpret_cast<InterruptControllerStructureHeader const*>(this + 1),
240 reinterpret_cast<InterruptControllerStructureHeader const*>(this->as_bytes().end())
241 };
242 }
243};
244
245template<usize N>
246constexpr auto byte_array_to_string_view(di::Array<byte, N> const& array) {
247 return di::TransparentStringView { reinterpret_cast<char const*>(array.data()), array.size() };
248}
249}
Definition span_forward_declaration.h:10
auto end() const -> InterruptControllerStructureIterator
Definition system_tables.h:212
auto validate(usize min_size) const -> bool
Definition system_tables.h:203
void advance_one()
Definition system_tables.h:209
friend auto operator==(InterruptControllerStructureIterator const &a, InterruptControllerStructureIterator const &b) -> bool
Definition system_tables.h:217
auto operator->() const -> InterruptControllerStructureHeader const *
Definition system_tables.h:201
auto begin() const -> InterruptControllerStructureIterator
Definition system_tables.h:211
InterruptControllerStructureIterator(InterruptControllerStructureHeader const *current, InterruptControllerStructureHeader const *end)
Definition system_tables.h:196
auto operator*() const -> InterruptControllerStructureHeader const &
Definition system_tables.h:200
string::StringViewImpl< string::TransparentEncoding > TransparentStringView
Definition string_view.h:13
size_t usize
Definition integers.h:33
__UINT64_TYPE__ u64
Definition integers.h:12
__UINT8_TYPE__ u8
Definition integers.h:9
__UINT32_TYPE__ u32
Definition integers.h:11
__UINT16_TYPE__ u16
Definition integers.h:10
Definition zstring_parser.h:9
constexpr auto as_bytes
Definition as_bytes.h:16
constexpr auto to_uintptr
Definition to_uintptr.h:13
constexpr auto end
Definition end.h:47
Definition acpi.cpp:11
constexpr auto byte_array_to_string_view(di::Array< byte, N > const &array)
Definition system_tables.h:246
InterruptControllerStructureType
Interrupt Controller Structure Type.
Definition system_tables.h:76
@ InterruptSourceOverride
Definition system_tables.h:79
@ LocalApicNmi
Definition system_tables.h:81
@ CorePic
Definition system_tables.h:94
@ IoSapic
Definition system_tables.h:83
@ ExtendIoPic
Definition system_tables.h:97
@ BridgeIoPic
Definition system_tables.h:99
@ GIGInterruptTranslationService
Definition system_tables.h:92
@ LegacyPic
Definition system_tables.h:95
@ MsiPic
Definition system_tables.h:98
@ MultiprocessorWakeup
Definition system_tables.h:93
@ LocalApicAddressOverride
Definition system_tables.h:82
@ LocalX2ApicNmi
Definition system_tables.h:87
@ LocalApic
Definition system_tables.h:77
@ GicDistrutor
Definition system_tables.h:89
@ NmiSource
Definition system_tables.h:80
@ PlatformInterruptSources
Definition system_tables.h:85
@ LocalSapic
Definition system_tables.h:84
@ LocalX2Apic
Definition system_tables.h:86
@ GicRedistributor
Definition system_tables.h:91
@ IoApic
Definition system_tables.h:78
@ LowPinCountPic
Definition system_tables.h:100
@ GicMsiFrame
Definition system_tables.h:90
@ HyperTransportPic
Definition system_tables.h:96
@ GicCpuInterface
Definition system_tables.h:88
auto validate_acpi_checksum(di::Span< byte const > data) -> bool
Definition acpi.cpp:20
Definition iterator_base.h:14
Definition span_fixed_size.h:37
constexpr auto data() -> T *
Definition array.h:75
constexpr auto size() const
Definition array.h:85
Interrupt Controller Structure Header.
Definition system_tables.h:106
auto next() const -> InterruptControllerStructureHeader const *
Definition system_tables.h:110
InterruptControllerStructureType type
Definition system_tables.h:107
u8 length
Definition system_tables.h:108
auto validate(usize min_length) const -> bool
Definition system_tables.h:115
Interrupt Source Override Structure.
Definition system_tables.h:173
u8 source
Definition system_tables.h:175
u32 global_system_interrupt
Definition system_tables.h:176
u8 bus
Definition system_tables.h:174
MPSInterruptFlags flags
Definition system_tables.h:177
I/O APIC Structure.
Definition system_tables.h:135
u8 io_apic_id
Definition system_tables.h:136
u32 global_system_interrupt_base
Definition system_tables.h:139
u32 io_apic_address
Definition system_tables.h:138
u8 reserved
Definition system_tables.h:137
Local APIC NMI Structure.
Definition system_tables.h:184
u8 local_apic_lint
Definition system_tables.h:187
MPSInterruptFlags flags
Definition system_tables.h:186
u8 apic_processor_uid
Definition system_tables.h:185
Multiple APIC Description Table.
Definition system_tables.h:229
Flags flags
Definition system_tables.h:235
auto interrupt_controller_structures() const -> InterruptControllerStructureIterator
Definition system_tables.h:237
Flags
Definition system_tables.h:230
@ PcAtCompatible
Definition system_tables.h:231
u32 local_apic_address
Definition system_tables.h:234
MPS Interrupt Flags.
Definition system_tables.h:148
Polarity
Definition system_tables.h:149
@ ActiveLow
Definition system_tables.h:153
@ BusDefined
Definition system_tables.h:150
@ ActiveHigh
Definition system_tables.h:151
@ Reserved
Definition system_tables.h:152
u16 value
Definition system_tables.h:166
auto trigger_mode() const -> TriggerMode
Definition system_tables.h:164
auto polarity() const -> Polarity
Definition system_tables.h:163
TriggerMode
Definition system_tables.h:156
@ Level
Definition system_tables.h:160
@ Edge
Definition system_tables.h:158
Processor Local APIC Structure.
Definition system_tables.h:121
Flags
Definition system_tables.h:122
@ Enabled
Definition system_tables.h:123
@ OnlineCapable
Definition system_tables.h:124
Flags flags
Definition system_tables.h:129
u8 apic_id
Definition system_tables.h:128
u8 processor_id
Definition system_tables.h:127
Root System Description Pointer.
Definition system_tables.h:14
u8 checksum
Definition system_tables.h:18
di::Array< byte, 3 > reserved
Definition system_tables.h:30
u8 extended_checksum
Definition system_tables.h:29
u32 length
Definition system_tables.h:27
u8 revision
Definition system_tables.h:20
auto validate_v1() const -> bool
Definition system_tables.h:33
di::Array< byte, 6 > oem_id
Definition system_tables.h:19
u64 xsdt_address
Definition system_tables.h:28
di::Array< byte, 8 > signature
Definition system_tables.h:17
u32 rsdt_address
Definition system_tables.h:21
Root System Description Table.
Definition system_tables.h:67
auto entries() const -> di::Span< u32 const >
Definition system_tables.h:68
System Description Table Header.
Definition system_tables.h:41
auto as_bytes() const -> di::Span< byte const >
Definition system_tables.h:52
u8 revision
Definition system_tables.h:44
auto validate(usize min_length) const -> bool
Definition system_tables.h:56
u8 checksum
Definition system_tables.h:45
di::Array< byte, 6 > oem_id
Definition system_tables.h:46
u32 creator_id
Definition system_tables.h:49
u32 length
Definition system_tables.h:43
di::Array< byte, 8 > oem_table_id
Definition system_tables.h:47
u32 oem_revision
Definition system_tables.h:48
di::Array< byte, 4 > signature
Definition system_tables.h:42
u32 creator_revision
Definition system_tables.h:50