The Pedigree Project 0.1
PciVirtualFunctions.h
1/* Copyright (c) 2026, Pedigree Developers. SPDX-License-Identifier: ISC */
2#ifndef PEDIGREE_PCI_VIRTUAL_FUNCTIONS_H
3#define PEDIGREE_PCI_VIRTUAL_FUNCTIONS_H
4
5#include "pedigree/kernel/compiler.h"
6#include "pedigree/kernel/machine/PciSriov.h"
7
8class Device;
9
21class EXPORTED_PUBLIC PciVirtualFunctions {
22 public:
23 explicit PciVirtualFunctions(Device* pf);
25
26 bool enable(size_t count);
27 Device* function(size_t index) const;
28 size_t count() const;
29 bool disable();
30 static bool bar(Device* vf, uint8_t index, uint64_t& pciBase, uint64_t& bytes);
31
32 private:
34 PciVirtualFunctions& operator=(const PciVirtualFunctions&) = delete;
35
36 void reclaim();
37
38 // The current VT-d backend has eight requester-domain slots. Other devices
39 // may occupy some of them; attach failure rolls the whole group back.
40 static constexpr size_t MaxFunctions = 8;
41 Device* m_Pf;
42 Device* m_Functions[MaxFunctions] = {};
43 bool m_Present[MaxFunctions] = {};
44 bool m_Reserved[6] = {};
45 size_t m_PlannedCount = 0;
46 size_t m_Count = 0;
47 uint16_t m_Offset = 0;
48 uint16_t m_NextCapability = 0;
49 PciSriov::State m_Original;
50 PciSriov::Geometry m_Bars;
51 bool m_Touched = false;
52 bool m_EnableAttempted = false;
53};
54
55#endif