diff options
Diffstat (limited to 'drivers/acpi')
| -rw-r--r-- | drivers/acpi/acpi.cpp | 61 | ||||
| -rw-r--r-- | drivers/acpi/acpi.h | 163 |
2 files changed, 224 insertions, 0 deletions
diff --git a/drivers/acpi/acpi.cpp b/drivers/acpi/acpi.cpp new file mode 100644 index 0000000..25dad9d --- /dev/null +++ b/drivers/acpi/acpi.cpp @@ -0,0 +1,61 @@ +#include "acpi.h" + + +const char *Rsdp::signatureString = "RSD PTR "; +const uint8 Rsdp::validFieldRevision = 2; +const memAddr Rsdp::romAreaStart = 0xe0000; +const memAddr Rsdp::romAreaEnd = 0xfffff; +const memAddr Rsdp::ebdaAreaStart = 0x80000; +const memAddr Rsdp::ebdaAreaEnd = 0x803ff; +const uint8 Rsdp::checksunFieldSize = 20; +// Entry **Rsdt::entries = nullptr; + +Rsdt *Rsdp::getRsdt() const +{ + Rsdt *rsdtPtr = (Rsdt *)(rsdtAddress); + if(rsdtPtr == nullptr or checksumCheck()) return nullptr; + else return rsdtPtr; +}; + +Xsdt *Rsdp::getXsdt() const +{ + Xsdt *xsdtPtr = (Xsdt *)(xsdtAddress); + if(xsdtPtr == nullptr or checksumCheck()) return nullptr; + else return xsdtPtr; +}; + + +const uint32 DescHeader::getLength() const +{ + return length; +}; + +const Entry *Rsdt::getEntry(uint8 index) +{ + uint32 entriesAmount = (header.getLength() - sizeof(DescHeader)) / Entry::size; + + if(index >= entriesAmount + or entries == nullptr + or header.checksumCheck()) return nullptr; + else return ((const Entry **)&entries)[index]; +}; + +uint8 Rsdp::checksumCheck() const +{ + uint8 check = 0; + for(uint32 offset = 0; offset < checksunFieldSize; offset++) + { + check += *(uint8 *)((memAddr)this + offset); + } + return check; +}; + +uint8 DescHeader::checksumCheck() const +{ + uint8 check = 0; + for(uint32 offset = 0; offset < length; offset++) + { + check += *(uint8 *)((memAddr)this + offset); + } + return check; +}; diff --git a/drivers/acpi/acpi.h b/drivers/acpi/acpi.h new file mode 100644 index 0000000..069c954 --- /dev/null +++ b/drivers/acpi/acpi.h @@ -0,0 +1,163 @@ +#include <types.h> +#include <StringOperations.h> + + +typedef decltype(nullptr) nulltype; + +class Gas +{ + private: + const uint8 addressSpaceId; + const uint8 registerBitWidth; + const uint8 registerBitOffset; + const uint8 accessSize; + const uint64 address; + public: + Gas(); + Gas(const Gas &) = default; +}; + +class DescHeader +{ + private: + const char signature[4]; + const uint32 length; + const uint8 revision; + const uint8 checksum; + const char oemId[6]; + const uint64 oemTableId; + const uint32 oemRevision; + const uint32 creatorId; + const uint32 creatorRevision; + public: + DescHeader() = delete; + DescHeader(const DescHeader &) = delete; + const uint32 getLength() const; + uint8 checksumCheck() const; +} __attribute__((packed)); + + +class Entry +{ + public: + // In bytes + static const uint8 size = 4; + protected: + const DescHeader header; + public: + Entry() = delete; + Entry(const Entry &) = delete; +} __attribute__((packed)); + +class FadtEntry : public Entry +{ + private: + const uint32 firmwareCtrl; + const uint32 dsdt; + const uint8 reserved; + const uint8 preferredPmProfile; + const uint16 sciInt; + const uint32 smiCmd; + const uint8 acpiEnable; + const uint8 acpiDisable; + const uint8 s4biosReq; + const uint8 pstateCnt; + const uint32 pm1AEvtBlk; + const uint32 pm1BEvtBlk; + const uint32 pm1ACntBlk; + const uint32 pm1BCntBlk; + const uint32 pm2CntBlk; + const uint32 pmTmrBlk; + const uint32 gpe0Blk; + const uint32 gpe1Blk; + const uint8 pm1EvtLen; + const uint8 pm1CntLen; + const uint8 pm2CntLen; + const uint8 pmTmrLen; + const uint8 gpe0BlkLen; + const uint8 gpe1BlkLen; + const uint8 gpe1Base; + const uint8 cstCnt; + const uint16 pLvl2Lat; + const uint16 pLvl3Lat; + const uint16 flushSize; + const uint16 flushStride; + const uint8 dutyOffset; + const uint8 dutyWidth; + const uint8 dayAlrm; + const uint8 monAlrm; + const uint8 century; + const uint16 iapcBootArch; + const uint8 reservedTwo; + const uint32 flags; + const Gas resetReg; + const uint8 resetValue; + const uint16 armBootArch; + const uint8 minorRevision; + const uint64 xFirmwareCtrl; + const uint64 xDsdt; + const Gas xPm1AEvtBlk; + const Gas xPm1BEvtBlk; + const Gas xPm1ACntBlk; + const Gas xPm1BCntBlk; + const Gas xPm2CntBlk; + const Gas xPmTmrBlk; + const Gas xGpe0Blk; + const Gas xGpe1Blk; + const Gas sleepControlReg; + const Gas sleepStatusReg; + const uint64 hypervisorVendorIdentity; + public: + FadtEntry() = delete; + FadtEntry(const FadtEntry &) = delete; +} __attribute__((packed)); + +class Rsdt +{ + private: + const DescHeader header; + const Entry **entries; + public: + Rsdt() = delete; + Rsdt(const Rsdt &) = delete; + const Entry *getEntry(uint8 index); +} __attribute__((packed, aligned(sizeof(uint32)))); + +class Xsdt +{ + private: + const DescHeader header; + const uint64 firstEntryAddr; + public: + Xsdt() = delete; + Xsdt(const Xsdt &) = delete; +} __attribute__((packed)); + +class Rsdp +{ + public: + const static uint8 validFieldRevision; + // RSDP memory address areas in IA-PC systems + const static char *signatureString; + const static memAddr romAreaStart; + const static memAddr romAreaEnd; + const static memAddr ebdaAreaStart; + const static memAddr ebdaAreaEnd; + private: + const static uint8 checksunFieldSize; + const char signature[8]; + const uint8 checksum; + const char oemId[6]; + const uint8 revision; + const uint32 rsdtAddress; + const uint32 length; + const uint32 xsdtAddress; + const uint8 extendedChecksum; + const char reserved[3]; + public: + Rsdp() = delete; + Rsdp(const Rsdp &) = delete; + Rsdt *getRsdt() const; + Xsdt *getXsdt() const; + uint8 checksumCheck() const; +}; |
