summaryrefslogtreecommitdiffhomepage
path: root/src/kernel/HALKit/AMD64/PCI/Iterator.cpp
blob: 1f8562d25f6f141351c2312c989ab232761ef10c (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
// Copyright 2024-2025, Amlal El Mahrouss (amlal@nekernel.org)
// Licensed under the Apache License, Version 2.0 (see LICENSE file)
// Official repository: https://github.com/ne-foss-org/nekernel

#include <KernelKit/PCI/Iterator.h>

namespace Kernel::PCI {
Iterator::Iterator(const Types::PciDeviceKind type, UInt32 bar) {
  // probe devices.
  for (Int32 bus = 0; bus < NE_BUS_COUNT; ++bus) {
    for (Int32 device = 0; device < NE_DEVICE_COUNT; ++device) {
      for (Int32 function = 0; function < NE_FUNCTION_COUNT; ++function) {
        Device dev(bus, device, function, bar);

        if (dev.Class() == type) {
          fDevices[bus] = dev;
        }
      }
    }
  }
}

Iterator::~Iterator() {}

Ref<PCI::Device> Iterator::operator[](const Size& at) {
  return fDevices[at];
}
}  // namespace Kernel::PCI