* @brief 获取 CPU 时钟频率 * @return Expected 时钟频率 * @pre fdt_header_ 不为空 */
| 171 | * @pre fdt_header_ 不为空 |
| 172 | */ |
| 173 | [[nodiscard]] auto GetTimebaseFrequency() const -> Expected<uint32_t> { |
| 174 | assert(fdt_header_ != nullptr && "fdt_header_ is null"); |
| 175 | |
| 176 | return FindNode("/cpus").and_then([this](int offset) -> Expected<uint32_t> { |
| 177 | int len = 0; |
| 178 | const auto* prop = reinterpret_cast<const uint32_t*>( |
| 179 | fdt_getprop(fdt_header_, offset, "timebase-frequency", &len)); |
| 180 | if (prop == nullptr) { |
| 181 | return std::unexpected(Error(ErrorCode::kFdtPropertyNotFound)); |
| 182 | } |
| 183 | |
| 184 | if (len != sizeof(uint32_t)) { |
| 185 | return std::unexpected(Error(ErrorCode::kFdtInvalidPropertySize)); |
| 186 | } |
| 187 | |
| 188 | return fdt32_to_cpu(*prop); |
| 189 | }); |
| 190 | } |
| 191 | |
| 192 | /** |
| 193 | * @brief 获取 GIC 信息 |