2023-02-21 13:36:20 +00:00
|
|
|
#include "acpi.h"
|
2023-09-11 21:23:38 +00:00
|
|
|
#include "../../CoreLib/Memory.h"
|
|
|
|
#include "../memory/VirtualMemoryManager.h"
|
|
|
|
|
2023-02-21 13:36:20 +00:00
|
|
|
RSDPDescriptor* ACPI::rsd_ptr;
|
2023-02-26 23:32:16 +00:00
|
|
|
RSCPDescriptor20* ACPI::rsd2_ptr;
|
2023-02-21 13:36:20 +00:00
|
|
|
RSDT* ACPI::rsd_table;
|
|
|
|
|
2023-09-11 21:23:38 +00:00
|
|
|
const int KERNEL_OFFSET = 0xC0000000;
|
2023-02-21 13:36:20 +00:00
|
|
|
|
|
|
|
void ACPI::initialize(){
|
|
|
|
// Find the Root System Description Pointer
|
|
|
|
ACPI::rsd_ptr = FindRSD();
|
2023-02-26 23:32:16 +00:00
|
|
|
printf("RSD address: 0x%x\n", ACPI::rsd_ptr);
|
2023-09-11 21:23:38 +00:00
|
|
|
printRSD(rsd_ptr);
|
2023-02-21 13:36:20 +00:00
|
|
|
|
2023-02-26 23:32:16 +00:00
|
|
|
|
|
|
|
if( rsd_ptr->Revision == 0 ){
|
2023-09-11 21:23:38 +00:00
|
|
|
// Using version 1.0 of the ACPI specification
|
2023-02-26 23:32:16 +00:00
|
|
|
int sum = rsd_ptr->Checksum;
|
|
|
|
for (int i =0; i < sizeof(RSDPDescriptor) ; i++) {
|
|
|
|
sum += ((char*)rsd_ptr)[i];
|
|
|
|
}
|
|
|
|
|
|
|
|
printf(" 0x%x sum\n", sum);
|
|
|
|
if(sum & 0xfff0)
|
|
|
|
printf("valid rsd!\n");
|
|
|
|
else
|
|
|
|
printf("invalid rsd\n");
|
|
|
|
|
2023-09-11 21:23:38 +00:00
|
|
|
printf("rsdp: 0x%x\n", rsd_ptr);
|
|
|
|
|
|
|
|
printf("0x%x address\n", (rsd_ptr->RsdtAddress));
|
|
|
|
Immediate_Map(rsd_ptr->RsdtAddress + KERNEL_OFFSET, rsd_ptr->RsdtAddress);
|
|
|
|
|
|
|
|
RSDT* rootSystemDescriptionTable = (RSDT*)(rsd_ptr->RsdtAddress + KERNEL_OFFSET);
|
|
|
|
//printf("0x%x Root System Descriptor address\n", rootSystemDescriptionTable);
|
|
|
|
// checksum it, but we'll ignore it for now
|
|
|
|
printf("signature ");
|
|
|
|
for (int i = 0; i < 4; i++) {
|
|
|
|
kterm_put( rootSystemDescriptionTable->h.Signature[i]);
|
|
|
|
}
|
|
|
|
kterm_put('\n');
|
|
|
|
|
|
|
|
|
|
|
|
int entries = (rootSystemDescriptionTable->h.Length - sizeof (rootSystemDescriptionTable->h)) /4;
|
|
|
|
printf("%d num entries\n", entries);
|
|
|
|
for( int i = 0; i < entries; i++){
|
|
|
|
ACPISDTHeader* h = (ACPISDTHeader*) rootSystemDescriptionTable->PointerToSDT + i ;
|
|
|
|
if(strncmp(h->Signature, "FACP", 4)){
|
|
|
|
printf("Found FACP Entry!\n");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-02-26 23:32:16 +00:00
|
|
|
|
|
|
|
} else{
|
|
|
|
// parse it as of version2.0
|
2023-09-11 21:23:38 +00:00
|
|
|
printf("rsd2_ptr\n");
|
2023-02-26 23:32:16 +00:00
|
|
|
ACPI::rsd2_ptr = (RSCPDescriptor20*)rsd_ptr;
|
2023-02-21 13:36:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2023-02-26 23:32:16 +00:00
|
|
|
/*
|
2023-02-21 13:36:20 +00:00
|
|
|
auto tableHeader = &rootSystemDescriptionTable->h;
|
|
|
|
|
|
|
|
// do checksum
|
|
|
|
sum = 0;
|
|
|
|
|
|
|
|
for(int i = 0; i < tableHeader->Length; i ++) {
|
|
|
|
sum += ((char*) tableHeader)[i];
|
|
|
|
}
|
|
|
|
|
|
|
|
if( sum != 0)
|
2023-02-26 23:32:16 +00:00
|
|
|
printf("Table invalid!");*/
|
2023-02-21 13:36:20 +00:00
|
|
|
}
|