summaryrefslogtreecommitdiffhomepage
path: root/Private/HALKit/AMD64/PCI/Iterator.cpp
blob: 35d0916a14100f2f960d1ff947a1a50c7dc41b3d (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
/*
 *	========================================================
 *
 *	HCore
 * 	Copyright 2024 Mahrouss Logic, all rights reserved.
 *
 * 	========================================================
 */

#include <KernelKit/PCI/Iterator.hpp>

#define PCI_ITERATOR_FIND_AND_UNWRAP(DEV, SZ) \
  if (DEV.Leak()) return DEV.Leak();

namespace HCore::PCI {
Iterator::Iterator(const Types::PciDeviceKind &type) {
  // probe devices.
  for (int bus = 0; bus < ME_BUS_COUNT; ++bus) {
    for (int device = 0; device < ME_DEVICE_COUNT; ++device) {
      for (int function = 0; function < ME_FUNCTION_COUNT; ++function) {
        Device dev(bus, device, function, 0);

        if (dev.Class() == (UChar)type) {
          m_Devices[bus].Leak().Leak() = dev;
        }
      }
    }
  }
}

Iterator::~Iterator() {}

Ref<PCI::Device> Iterator::operator[](const Size &sz) {
  PCI_ITERATOR_FIND_AND_UNWRAP(m_Devices[sz], sz);
  return {};
}
}  // namespace HCore::PCI