aboutsummaryrefslogtreecommitdiff
path: root/kapi/src/acpi.cpp
blob: aa0066db2ec8ac9436c5d31ac0ac0091a33b300e (plain)
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
#include "kapi/acpi.hpp"

#include "kapi/memory.hpp"

#include <kstd/units>

#include <algorithm>
#include <bit>
#include <cstddef>
#include <cstdint>
#include <span>
#include <string_view>

namespace kapi::acpi
{

  namespace
  {
    constexpr auto validate_checksum(std::span<std::byte const> data) -> bool
    {
      auto sum = std::ranges::fold_left(
          data, std::uint8_t{}, [](std::uint8_t acc, auto byte) { return static_cast<std::uint8_t>(byte) + acc; });
      return sum == 0;
    }
  }  // namespace

  auto root_system_description_pointer::oem_id() const noexcept -> std::string_view
  {
    return {m_oem_id.data(), m_oem_id.size()};
  }

  auto root_system_description_pointer::revision() const noexcept -> std::uint8_t
  {
    return m_revision;
  }

  auto root_system_description_pointer::signature() const noexcept -> std::string_view
  {
    return {m_signature.data(), m_signature.size()};
  }

  auto root_system_description_pointer::table_address() const noexcept -> memory::physical_address
  {
    auto raw = std::bit_cast<std::uint32_t>(m_rsdt_address);
    return memory::physical_address{static_cast<std::uintptr_t>(raw)};
  }

  auto root_system_description_pointer::validate() const noexcept -> bool
  {
    return validate_checksum({reinterpret_cast<std::byte const *>(this), sizeof(root_system_description_pointer)});
  }

  auto extended_system_description_pointer::length() const noexcept -> kstd::units::bytes
  {
    return kstd::units::bytes{m_length};
  }

  auto extended_system_description_pointer::table_address() const noexcept -> memory::physical_address
  {
    return memory::physical_address{std::bit_cast<std::uintptr_t>(m_xsdt_address)};
  }

  auto extended_system_description_pointer::validate() const noexcept -> bool
  {
    return validate_checksum({reinterpret_cast<std::byte const *>(this), m_length});
  }

};  // namespace kapi::acpi