2#ifndef PEDIGREE_PCI_PROBE_BARS_H
3#define PEDIGREE_PCI_PROBE_BARS_H
7enum class ProbeResult { Success, DecodeDisableFailed, RestoreFailed };
9 ProbeResult result = ProbeResult::Success;
11 uint32_t masks[6] = {};
14template <
class Bus,
class Device,
class Header>
17 const uint8_t headerType = header.header_type & 0x7f;
20 if (header.vendor == 0x8086 && header.device == 0x1c4f && header.class_code == 6 &&
21 header.subclass == 1 && headerType == 0)
24 result.count = headerType == 0 ? 6 : headerType == 1 ? 2 : headerType == 2 ? 1 : 0;
26 if (!pci.updateCommand(device, 3, 0)) {
27 result.result = ProbeResult::DecodeDisableFailed;
31 for (
unsigned i = 0; i < result.count; ++i) {
32 const uint8_t offset = 4 + i;
33 pci.writeConfigSpace(device, offset, 0xffffffffU);
34 result.masks[i] = pci.readConfigSpace(device, offset);
35 pci.writeConfigSpace(device, offset, header.bar[i]);
36 if (pci.readConfigSpace(device, offset) != header.bar[i]) {
41 if (!restored || !pci.updateCommand(device, 3, header.command & 3)) {
42 (void)pci.updateCommand(device, 7, 0);
43 result.result = ProbeResult::RestoreFailed;