aboutsummaryrefslogtreecommitdiff
path: root/src/kernel/include
diff options
context:
space:
mode:
authorAlex Auvolat <alex.auvolat@ens.fr>2015-02-24 11:06:48 +0100
committerAlex Auvolat <alex.auvolat@ens.fr>2015-02-24 11:06:48 +0100
commit91c5969cdddf2241418082998e76bdbb836ed03e (patch)
treea4597e44f36f6fc3406e0dd2671d265bce3a7d53 /src/kernel/include
parent9ba449a6e5f9db20923fb9802eefe0f090ba5fff (diff)
downloadkogata-91c5969cdddf2241418082998e76bdbb836ed03e.tar.gz
kogata-91c5969cdddf2241418082998e76bdbb836ed03e.zip
PCI enumeration ; rename dev:/ to io:/
Diffstat (limited to 'src/kernel/include')
-rw-r--r--src/kernel/include/dev/ata.h7
-rw-r--r--src/kernel/include/dev/pci.h63
-rw-r--r--src/kernel/include/idt.h32
-rw-r--r--src/kernel/include/sys.h10
4 files changed, 96 insertions, 16 deletions
diff --git a/src/kernel/include/dev/ata.h b/src/kernel/include/dev/ata.h
new file mode 100644
index 0000000..c0a4bff
--- /dev/null
+++ b/src/kernel/include/dev/ata.h
@@ -0,0 +1,7 @@
+#pragma once
+
+#include <vfs.h>
+
+
+
+/* vim: set ts=4 sw=4 tw=0 noet :*/
diff --git a/src/kernel/include/dev/pci.h b/src/kernel/include/dev/pci.h
new file mode 100644
index 0000000..9fe0f3b
--- /dev/null
+++ b/src/kernel/include/dev/pci.h
@@ -0,0 +1,63 @@
+#pragma once
+
+#include <sys.h>
+
+#define PCI_MAX_DEVICES 32
+
+// IRQs 9, 10 and 11 are controlled by the PCI driver
+// By default all devices are remapped to IRQ 9
+// For specific devices other IRQs may be mapped
+#define PCI_IRQ_DEFAULT 9
+#define PCI_IRQ_STORAGE 10
+#define PCI_IRQ_NETWORK 11
+#define PCI_IRQ_DISABLE 0xFF
+
+#define PCI_CONFIG_DEVICE_ID 0x02
+#define PCI_CONFIG_VENDOR_ID 0x00
+#define PCI_CONFIG_CLASS 0x0B
+#define PCI_CONFIG_SUBCLASS 0x0A
+#define PCI_CONFIG_HEADER_TYPE 0x0E
+#define PCI_CONFIG_SECONDARY_BUS 0x19
+#define PCI_CONFIG_INTERRUPT_LINE 0x3C
+
+// base classes
+#define PCI_BC_STORAGE 0x01
+#define PCI_BC_BRIDGE 0x06
+
+// sub-classes
+#define PCI_SC_IDE 0x01
+#define PCI_SC_PCI_TO_PCI 0x04
+
+typedef void (*pci_irq_handler_t)();
+
+typedef struct {
+ uint8_t bus;
+ uint8_t slot;
+ uint8_t func;
+
+ uint16_t device_id;
+ uint16_t vendor_id;
+
+ uint8_t base_class;
+ uint8_t sub_class;
+
+ uint8_t irq;
+ pci_irq_handler_t irq_handler;
+} pci_device_t;
+
+extern pci_device_t pci_devices[PCI_MAX_DEVICES];
+
+void pci_setup(); // does scan and sets up IRQs
+
+void pci_set_irq(int dev_id, uint8_t irq); // irq = 0xFF disables the IRQ for this device
+
+uint32_t pci_read_config_long(int dev_id, uint8_t offset);
+uint16_t pci_read_config_word(int dev_id, uint8_t offset);
+uint8_t pci_read_config_byte(int dev_id, uint8_t offset);
+
+void pci_write_config_long(int dev_id, uint8_t offset, uint32_t l);
+void pci_write_config_word(int dev_id, uint8_t offset, uint16_t w);
+void pci_write_config_byte(int dev_id, uint8_t offset, uint8_t b);
+
+
+/* vim: set ts=4 sw=4 tw=0 noet :*/
diff --git a/src/kernel/include/idt.h b/src/kernel/include/idt.h
index 8e84cea..d9dd927 100644
--- a/src/kernel/include/idt.h
+++ b/src/kernel/include/idt.h
@@ -8,22 +8,22 @@
#include <config.h>
-#define IRQ0 0
-#define IRQ1 1
-#define IRQ2 2
-#define IRQ3 3
-#define IRQ4 4
-#define IRQ5 5
-#define IRQ6 6
-#define IRQ7 7
-#define IRQ8 8
-#define IRQ9 9
-#define IRQ10 10
-#define IRQ11 11
-#define IRQ12 12
-#define IRQ13 13
-#define IRQ14 14
-#define IRQ15 15
+#define IRQ0 0 // PIT
+#define IRQ1 1 // PCKBD
+#define IRQ2 2 // not used
+#define IRQ3 3 // COM2
+#define IRQ4 4 // COM1
+#define IRQ5 5 // LPT2
+#define IRQ6 6 // Floppy
+#define IRQ7 7 // LPT1
+#define IRQ8 8 // CMOS RTC
+#define IRQ9 9 // free -> PCI IRQ
+#define IRQ10 10 // free -> PCI IRQ
+#define IRQ11 11 // free -> PCI IRQ
+#define IRQ12 12 // PS2 mouse
+#define IRQ13 13 // FPU
+#define IRQ14 14 // Primary ATA HD
+#define IRQ15 15 // Secondary ATA HD
#define EX_DIVIDE_ERROR 0 // No error code
#define EX_DEBUG 1 // No error code
diff --git a/src/kernel/include/sys.h b/src/kernel/include/sys.h
index 29735fa..365e709 100644
--- a/src/kernel/include/sys.h
+++ b/src/kernel/include/sys.h
@@ -11,6 +11,10 @@ static inline void outw(uint16_t port, uint16_t value) {
asm volatile("outw %1, %0" : : "dN"(port), "a"(value));
}
+static inline void outl(uint16_t port, uint32_t value) {
+ asm volatile("outl %1, %0" : : "dN"(port), "a"(value));
+}
+
static inline uint8_t inb(uint16_t port) {
uint8_t ret;
asm volatile("inb %1, %0" : "=a"(ret) : "dN"(port));
@@ -23,6 +27,12 @@ static inline uint16_t inw(uint16_t port) {
return ret;
}
+static inline uint32_t inl(uint16_t port) {
+ uint32_t ret;
+ asm volatile("inl %1, %0" : "=a"(ret) : "dN"(port));
+ return ret;
+}
+
static inline void invlpg(void* addr) {
asm volatile("invlpg (%0)" : : "r"(addr) : "memory");
}