MCPcopy Create free account
hub / github.com/Simple-XX/SimpleKernel / GetRegProperty

Method GetRegProperty

src/include/kernel_fdt.hpp:734–750  ·  view source on GitHub ↗

* @brief 获取 reg 属性(返回第一个 reg 条目) * @param offset 节点偏移量 * @return Expected > base 和 size * @post 返回第一个 对,而非最后一个 */

Source from the content-addressed store, hash-verified

732 * @post 返回第一个 <base, size> 对,而非最后一个
733 */
734 [[nodiscard]] auto GetRegProperty(int offset) const
735 -> Expected<std::pair<uint64_t, size_t>> {
736 int len = 0;
737 const auto* prop = fdt_get_property(fdt_header_, offset, "reg", &len);
738 if (prop == nullptr) {
739 return std::unexpected(Error(ErrorCode::kFdtPropertyNotFound));
740 }
741
742 const auto* reg = reinterpret_cast<const uint64_t*>(prop->data);
743 if (static_cast<size_t>(len) < 2 * sizeof(uint64_t)) {
744 return std::unexpected(Error(ErrorCode::kFdtInvalidPropertySize));
745 }
746
747 uint64_t base = fdt64_to_cpu(reg[0]);
748 size_t size = fdt64_to_cpu(reg[1]);
749 return std::pair{base, size};
750 }
751
752 /**
753 * @brief 按 device_type 统计节点数量

Callers

nothing calls this directly

Calls 1

ErrorClass · 0.85

Tested by

no test coverage detected