BarryServer : Git

All the code for all my projects
// BarryServer : Git / Nucleus / commit / e4c4dfe6cc8f70e0d4919a434e62f1d061477add / drivers / devices.c

// Related

Nucleus

Barry Driver core e4c4dfe (3 years, 2 months ago)
diff --git a/drivers/devices.c b/drivers/devices.c
new file mode 100644
index 0000000..19ec2e5
--- /dev/null
+++ b/drivers/devices.c
@@ -0,0 +1,63 @@
+/*
+ * This is the main file of the PCI driver core.  It contains the PCI Device
+ * database and controls device initialisation.
+ */
+
+#include <stdint.h>
+#include <stddef.h>
+#include <nucleus/pci.h>
+#include <nucleus/panic.h>
+
+/* Structure for a Device */
+struct Device {
+	uint16_t vendor, device;
+	char *name;
+	void (*init)(uint8_t, uint8_t, uint8_t);
+};
+
+void pci_init_ide(uint8_t bus, uint8_t dev, uint8_t func);
+
+/* Device database */
+struct Device devices[] = {
+	/* Intel system devices */
+	{0x8086, 0x1237, "Intel i440FX Chipset", NULL},
+	{0x8086, 0x7000, "Intel PIIX3 PCI-to-ISA Bridge (Triton II)", NULL},
+	{0x8086, 0x7010, "Intel PIIX3 IDE Interface (Triton II)", pci_init_ide},
+	{0x8086, 0x7020, "Intel PIIX3 USB (Natoma/Triton II)", NULL},
+	{0x8086, 0x7113, "Intel PIIX4/4E/4M Power Management Controller", NULL},
+
+	/* Network devices */
+	{0x10EC, 0x8139, "Realtek RTL8139 10/100 NIC", NULL},
+	{0x8086, 0x100E, "Intel Pro 1000/MT NIC", NULL},
+
+	/* Virtual devices */
+	{0x1B36, 0x000D, "QEMU XHCI Host Adapter", NULL},
+	{0x1234, 0x1111, "QEMU/Bochs VBE Framebuffer", NULL},
+};
+
+/* Initialise a PCI device */
+void
+init_pci_device(int bus, int dev, int func)
+{
+	uint32_t d;
+	uint16_t vendor, device;
+
+	vendor = pci_read_word(bus, dev, func, 0);
+	device = pci_read_word(bus, dev, func, 2);
+
+	/* Lookup device details */
+	for (d = 0; d < sizeof(devices) / sizeof(struct Device); d++) {
+		if (devices[d].vendor != vendor
+		 || devices[d].device != device)
+			continue;
+		kprintf("PCI(%d,%d,%d) \"%s\"", bus, dev, func,
+		        devices[d].name);
+		if (devices[d].init)
+			devices[d].init(bus, dev, func);
+		return;
+	}
+
+	/* No match */
+	kprintf("PCI(%d,%d,%d) = %#.4x:%#.4x", bus, dev, func,
+	        vendor, device);
+}