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

Method ForEachNode

src/include/kernel_fdt.hpp:365–435  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

363 */
364 template <typename Callback>
365 [[nodiscard]] auto ForEachNode(Callback&& callback) const -> Expected<void> {
366 assert(fdt_header_ != nullptr && "fdt_header_ is null");
367
368 int offset = -1;
369 int depth = 0;
370
371 while (true) {
372 offset = fdt_next_node(fdt_header_, offset, &depth);
373 if (offset < 0) {
374 if (offset == -FDT_ERR_NOTFOUND) {
375 break;
376 }
377 return std::unexpected(Error(ErrorCode::kFdtParseFailed));
378 }
379
380 const char* node_name = fdt_get_name(fdt_header_, offset, nullptr);
381 if (node_name == nullptr) {
382 continue;
383 }
384
385 int status_len = 0;
386 const auto* status_prop =
387 fdt_get_property(fdt_header_, offset, "status", &status_len);
388 if (status_prop != nullptr) {
389 const char* status = reinterpret_cast<const char*>(status_prop->data);
390 if (strcmp(status, "okay") != 0 && strcmp(status, "ok") != 0) {
391 continue;
392 }
393 }
394
395 const char* compatible_data = nullptr;
396 size_t compatible_len = 0;
397 int compat_len = 0;
398 const auto* compat_prop =
399 fdt_get_property(fdt_header_, offset, "compatible", &compat_len);
400 if (compat_prop != nullptr && compat_len > 0) {
401 compatible_data = reinterpret_cast<const char*>(compat_prop->data);
402 compatible_len = static_cast<size_t>(compat_len);
403 }
404
405 uint64_t mmio_base = 0;
406 size_t mmio_size = 0;
407 int reg_len = 0;
408 const auto* reg_prop =
409 fdt_get_property(fdt_header_, offset, "reg", &reg_len);
410 if (reg_prop != nullptr &&
411 static_cast<size_t>(reg_len) >= 2 * sizeof(uint64_t)) {
412 const auto* reg = reinterpret_cast<const uint64_t*>(reg_prop->data);
413 mmio_base = fdt64_to_cpu(reg[0]);
414 mmio_size = fdt64_to_cpu(reg[1]);
415 }
416
417 uint32_t irq = 0;
418 int irq_len = 0;
419 const auto* irq_prop =
420 fdt_get_property(fdt_header_, offset, "interrupts", &irq_len);
421 if (irq_prop != nullptr &&
422 static_cast<size_t>(irq_len) >= sizeof(uint32_t)) {

Callers 1

TEST_FFunction · 0.80

Calls 2

ErrorClass · 0.85
strcmpFunction · 0.85

Tested by 1

TEST_FFunction · 0.64