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
|
// MIT License, Copyright (c) 2021 Marvin Borner
#include <acpi.h>
#include <lib.h>
#include <pnc.h>
/**
* General SDP
*/
static u8 acpi_sdp_verify(struct sdp_header *header)
{
u8 sum = 0;
for (u32 i = 0; i < sizeof(struct rsdp); i++)
sum += (u8)(((u8 *)header)[i]);
return sum == 0;
}
/**
* General SDT
*/
static u8 acpi_sdt_verify(struct sdt_header *header)
{
u8 sum = 0;
for (u32 i = 0; i < header->length; i++)
sum += (u8)(((u8 *)header)[i]);
return sum == 0;
}
static void *acpi_sdt_find(struct rsdt *rsdt, const char *signature)
{
u32 entries = (rsdt->header.length - sizeof(rsdt->header)) / 4;
for (u32 i = 0; i < entries; i++) {
struct sdt_header *header = (struct sdt_header *)rsdt->sdt_pointer[i];
if (memcmp(header->signature, signature, 4) == 0) {
if (acpi_sdt_verify(header))
return header;
else
break;
}
}
return NULL;
}
/**
* RSDP - points to RSDT
*/
static struct rsdp *acpi_rsdp_find(void)
{
// Main BIOS area
for (u32 i = 0xe0000; i < 0xfffff; i++)
if (memcmp((u32 *)i, RSDP_MAGIC, 8) == 0)
return (struct rsdp *)i;
// Or first KB of EBDA?
u8 *ebda = (void *)(*((u16 *)0x40e) << 4);
for (u16 i = 0; i < 1024; i += 16)
if (memcmp(ebda + i, RSDP_MAGIC, 8) == 0)
return (struct rsdp *)(ebda + i);
return NULL;
}
/**
* Probe
*/
void acpi_probe(void)
{
struct rsdp *rsdp = acpi_rsdp_find();
assert(rsdp && rsdp->header.revision == 0 && acpi_sdp_verify(&rsdp->header));
struct rsdt *rsdt = rsdp->rsdt;
assert(rsdt && memcmp(rsdt->header.signature, RSDT_MAGIC, 4) == 0 &&
acpi_sdt_verify(&rsdt->header));
struct madt *madt = acpi_sdt_find(rsdt, MADT_MAGIC);
struct fadt *fadt = acpi_sdt_find(rsdt, FADT_MAGIC);
struct hpet *hpet = acpi_sdt_find(rsdt, HPET_MAGIC);
// TODO!
UNUSED(madt);
UNUSED(fadt);
UNUSED(hpet);
}
|