BarryServer : Git

All the code for all my projects
// BarryServer : Git / Nucleus / commit / e4c4dfe6cc8f70e0d4919a434e62f1d061477add / kernel

// Related

Nucleus

Barry Driver core e4c4dfe (3 years, 2 months ago)
diff --git a/kernel/acpi/acpi.h b/kernel/acpi/acpi.h
index 0c39b19..13d79a7 100644
--- a/kernel/acpi/acpi.h
+++ b/kernel/acpi/acpi.h
@@ -16,5 +16,6 @@ struct SDTHeader {
 
 void init_table(struct SDTHeader *table);
 void init_acpi(void *ebda);
+void init_pci(void);
 
 #endif
diff --git a/kernel/pci/pci.c b/kernel/acpi/pci.c
similarity index 77%
rename from kernel/pci/pci.c
rename to kernel/acpi/pci.c
index 408aeb8..b7c74c1 100644
--- a/kernel/pci/pci.c
+++ b/kernel/acpi/pci.c
@@ -1,13 +1,18 @@
 /*
- *
+ * This file controls the PCI interface.  It contains utility functions for
+ * accessing PCI configuration space.  It scans all devices connected to the
+ * system and tries to initialise them.
  */
 
 #include <stdint.h>
 #include <io.h>
-#include "pci.h"
+#include <nucleus/pci.h>
 
-const uint16_t CONFIG_ADDRESS = 0xCF8;
-const uint16_t CONFIG_DATA = 0xCFC;
+/* PCI Configuration Ports */
+enum PCIConfigPort {
+	CONFIG_ADDRESS = 0xCF8,
+	CONFIG_DATA = 0xCFC,
+};
 
 /* Make a PCI Address */
 static inline uint32_t
@@ -69,18 +74,11 @@ pci_write_dword(int bus, int dev, int func, int off, uint32_t value)
 void
 init_pci(void)
 {
-	uint16_t bus, slot, func;
-	uint16_t vendor, device;
-	uint8_t class, subclass;
-	uint32_t dev;
+	uint16_t bus, dev, func;
 	/* This is one massive iteration */
 	for (bus = 0; bus < 256; bus++)
-	for (slot = 0; slot < 32; slot++)
+	for (dev = 0; dev < 32; dev++)
 	for (func = 0; func < 8; func++)
-	if ((vendor = pci_read_word(bus, slot, func, 0)) != 0xFFFF) {
-		device = pci_read_word(bus, slot, func, 2);
-		/* do something */
-//		kprintf("PCI(%d,%d,%d) = %#.4x:%#.4x",
-//		        bus, slot, func, vendor, device);
-	}
+	if (pci_read_word(bus, dev, func, 0) != 0xFFFF)
+		init_pci_device(bus, dev, func);
 }
diff --git a/kernel/main.c b/kernel/main.c
index 0b45511..7d37563 100644
--- a/kernel/main.c
+++ b/kernel/main.c
@@ -13,7 +13,6 @@
 #include "multiboot.h"
 #include "desc.h"
 #include "acpi/acpi.h"
-#include "pci/pci.h"
 
 extern char _bss[], _end[];
 
diff --git a/kernel/pci/pci.h b/kernel/pci/pci.h
deleted file mode 100644
index b61dec3..0000000
--- a/kernel/pci/pci.h
+++ /dev/null
@@ -1,15 +0,0 @@
-#ifndef KERNEL_PCI_H
-#define KERNEL_PCI_H
-
-#include <stdint.h>
-
-uint8_t pci_read_byte(int bus, int dev, int func, int off);
-uint16_t pci_read_word(int bus, int dev, int func, int off);
-uint32_t pci_read_dword(int bus, int dev, int func, int off);
-void pci_write_byte(int bus, int dev, int func, int off, uint8_t value);
-void pci_write_word(int bus, int dev, int func, int off, uint16_t value);
-void pci_write_dword(int bus, int dev, int func, int off, uint32_t value);
-
-void init_pci(void);
-
-#endif