:: limine / common / lib / acpi.h 5.6 KB raw

1
#ifndef LIB__ACPI_H__
2
#define LIB__ACPI_H__
3
4
#include <stdint.h>
5
#include <stddef.h>
6
#include <sys/cpu.h>
7
8
#define EBDA (ebda_get())
9
10
#if defined (BIOS)
11
static inline uintptr_t ebda_get(void) {
12
    uintptr_t ebda = (uintptr_t)mminw(0x40e) << 4;
13
14
    // Sanity checks
15
    if (ebda < 0x80000 || ebda >= 0xa0000) {
16
        ebda = 0x80000;
17
    }
18
19
    return ebda;
20
}
21
#endif
22
23
struct sdt {
24
    char     signature[4];
25
    uint32_t length;
26
    uint8_t  rev;
27
    uint8_t  checksum;
28
    char     oem_id[6];
29
    char     oem_table_id[8];
30
    uint32_t oem_rev;
31
    char     creator_id[4];
32
    uint32_t creator_rev;
33
} __attribute__((packed));
34
35
struct rsdp {
36
    char     signature[8];
37
    uint8_t  checksum;
38
    char     oem_id[6];
39
    uint8_t  rev;
40
    uint32_t rsdt_addr;
41
    // Revision 2 only after this comment
42
    uint32_t length;
43
    uint64_t xsdt_addr;
44
    uint8_t  ext_checksum;
45
    uint8_t  reserved[3];
46
} __attribute__((packed));
47
48
struct rsdt {
49
    struct sdt header;
50
    char ptrs_start[];
51
} __attribute__((packed));
52
53
struct smbios_entry_point_32 {
54
    char anchor_str[4];
55
    /// This value summed with all the values of the table.
56
    uint8_t checksum;
57
    /// Length of the entry point table.
58
    uint8_t length;
59
    /// Major version of SMBIOS.
60
    uint8_t major_version;
61
    /// Minor version of SMBIOS.
62
    uint8_t minor_version;
63
    /// Size of the largest SMBIOS structure, in bytes, and encompasses the
64
    /// structure’s formatted area and text strings
65
    uint16_t max_structure_size;
66
    uint8_t entry_point_revision;
67
    char formatted_area[5];
68
69
    char intermediate_anchor_str[5];
70
    /// Checksum for values from intermediate anchor str to the
71
    /// end of table.
72
    uint8_t intermediate_checksum;
73
    /// Total length of SMBIOS Structure Table, pointed to by the structure
74
    /// table address, in bytes.
75
    uint16_t table_length;
76
    /// 32-bit physical starting address of the read-only SMBIOS Structure
77
    /// Table.
78
    uint32_t table_address;
79
    /// Total number of structures present in the SMBIOS Structure Table.
80
    uint16_t number_of_structures;
81
    /// Indicates compliance with a revision of this specification.
82
    uint8_t bcd_revision;
83
} __attribute__((packed));
84
85
struct smbios_entry_point_64 {
86
    char anchor_str[5];
87
    /// This value summed with all the values of the table.
88
    uint8_t checksum;
89
    /// Length of the entry point table.
90
    uint8_t length;
91
    /// Major version of SMBIOS.
92
    uint8_t major_version;
93
    /// Minor version of SMBIOS.
94
    uint8_t minor_version;
95
    uint8_t docrev;
96
    uint8_t entry_point_revision;
97
    uint8_t reserved;
98
    /// Size of the SMBIOS Structure Table, in bytes.
99
    uint32_t table_maximum_size;
100
    /// 64-bit physical starting address of the read-only SMBIOS Structure
101
    /// Table.
102
    uint64_t table_address;
103
} __attribute__((packed));
104
105
struct madt {
106
    struct sdt header;
107
    uint32_t local_controller_addr;
108
    uint32_t flags;
109
    char     madt_entries_begin[];
110
} __attribute__((packed));
111
112
struct madt_header {
113
    uint8_t type;
114
    uint8_t length;
115
} __attribute__((packed));
116
117
struct madt_lapic {
118
    struct madt_header header;
119
    uint8_t  acpi_processor_uid;
120
    uint8_t  lapic_id;
121
    uint32_t flags;
122
} __attribute__((packed));
123
124
struct madt_x2apic {
125
    struct madt_header header;
126
    uint8_t  reserved[2];
127
    uint32_t x2apic_id;
128
    uint32_t flags;
129
    uint32_t acpi_processor_uid;
130
} __attribute__((packed));
131
132
struct madt_io_apic {
133
    uint8_t type;
134
    uint8_t length;
135
    uint8_t apic_id;
136
    uint8_t reserved;
137
    uint32_t address;
138
    uint32_t gsib;
139
} __attribute__((packed));
140
141
struct madt_lapic_nmi {
142
    struct madt_header header;   // type=4, length=6
143
    uint8_t  acpi_processor_uid; // 0xff = all processors
144
    uint16_t flags;              // MPS INTI flags
145
    uint8_t  lint;               // 0 or 1
146
} __attribute__((packed));
147
148
struct madt_x2apic_nmi {
149
    struct madt_header header;   // type=0x0a, length=12
150
    uint16_t flags;              // MPS INTI flags
151
    uint32_t acpi_processor_uid; // 0xffffffff = all processors
152
    uint8_t  lint;               // 0 or 1
153
    uint8_t  reserved[3];
154
} __attribute__((packed));
155
156
struct madt_gicc {
157
    struct madt_header header;
158
    uint8_t  reserved1[2];
159
    uint32_t iface_no;
160
    uint32_t acpi_uid;
161
    uint32_t flags;
162
    uint32_t parking_ver;
163
    uint32_t perf_gsiv;
164
    uint64_t parking_addr;
165
    uint64_t gicc_base_addr;
166
    uint64_t gicv_base_addr;
167
    uint64_t gich_base_addr;
168
    uint32_t vgic_maint_gsiv;
169
    uint64_t gicr_base_addr;
170
    uint64_t mpidr;
171
    uint8_t  power_eff_class;
172
    uint8_t  reserved2;
173
    uint16_t spe_overflow_gsiv;
174
} __attribute__((packed));
175
176
// Reference: https://github.com/riscv-non-isa/riscv-acpi/issues/15
177
struct madt_riscv_intc {
178
    struct madt_header header;
179
    uint8_t version;
180
    uint8_t reserved;
181
    uint32_t flags;
182
    uint64_t hartid;
183
    uint32_t acpi_processor_uid;
184
} __attribute__((packed));
185
186
#define MADT_RISCV_INTC_ENABLED        ((uint32_t)1 << 0)
187
#define MADT_RISCV_INTC_ONLINE_CAPABLE ((uint32_t)1 << 1)
188
189
struct madt_core_pic {
190
    struct madt_header header;
191
    uint8_t  version;
192
    uint32_t acpi_processor_uid;
193
    uint32_t core_id;
194
    uint32_t flags;
195
} __attribute__((packed));
196
197
#define MADT_CORE_PIC_ENABLED        ((uint32_t)1 << 0)
198
#define MADT_CORE_PIC_ONLINE_CAPABLE ((uint32_t)1 << 1)
199
200
uint8_t acpi_checksum(void *ptr, size_t size);
201
void   *acpi_get_rsdp(void);
202
203
void   *acpi_get_rsdp_v1(void);
204
void   *acpi_get_rsdp_v2(void);
205
206
void   *acpi_get_table(const char *signature, int index);
207
void    acpi_get_smbios(void **smbios32, void **smbios64);
208
209
void acpi_map_tables(void);
210
void smbios_map_tables(void);
211
212
#if defined (UEFI)
213
void efi_map_runtime_entries(void);
214
#endif
215
216
#endif
tab: 248 wrap: offon