forked from CosmosOS/Cosmos
-
Notifications
You must be signed in to change notification settings - Fork 0
/
PCI.cs
82 lines (76 loc) · 2.77 KB
/
PCI.cs
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Cosmos.Debug.Kernel;
namespace Cosmos.HAL
{
public class PCI
{
private static List<PCIDevice> devices;
internal static Debugger mDebugger = new Debugger("HAL", "PCI");
public static void Setup()
{
EnumerateDevices();
}
public static PCIDevice GetDevice(ushort VendorID, ushort DeviceID)
{
for (int i = 0; i < devices.Count; i++)
{
if (devices[i].VendorID == VendorID && devices[i].DeviceID == DeviceID)
return devices[i];
}
return null;
}
private static void EnumerateDevices()
{
devices = new List<PCIDevice>();
//EnumerateBus(0, 0);
}
private static void EnumerateBus(uint xBus, uint step)
{
for (uint xDevice = 0; xDevice < 32; xDevice++)
{
PCIDevice xPCIDevice = new PCIDevice(xBus, xDevice, 0x00);
if (xPCIDevice.DeviceExists)
{
if (xPCIDevice.HeaderType == PCIDevice.PCIHeaderType.Bridge)
{
for (uint xFunction = 0; xFunction < 8; xFunction++)
{
xPCIDevice = new PCIDevice(xBus, xDevice, xFunction);
if (xPCIDevice.DeviceExists)
AddDevice(new PCIDeviceBridge(xBus, xDevice, xFunction), step);
}
}
else if (xPCIDevice.HeaderType == PCIDevice.PCIHeaderType.Cardbus)
{
AddDevice(new PCIDeviceCardbus(xBus, xDevice, 0x00), step);
}
else
{
AddDevice(new PCIDeviceNormal(xBus, xDevice, 0x00), step);
}
}
}
}
private static void AddDevice(PCIDevice device, uint step)
{
Console.WriteLine("Adding PCIDevice");
string str = "";
for (int i = 0; i < step; i++)
{
str += " ";
}
var xText = str + device.bus + ":" + device.slot + ":" + device.function + " " + PCIDevice.DeviceClass.GetString(device);
mDebugger.Send(xText);
Console.WriteLine(xText);
devices.Add(device);
if (device is PCIDeviceBridge)
{
var xDevice = device as PCIDeviceBridge;
EnumerateBus((xDevice).SecondaryBusNumber, step + 1);
}
}
}
}