summaryrefslogtreecommitdiff
path: root/kernel/include
diff options
context:
space:
mode:
authorFreya Murphy <freya@freyacat.org>2025-04-03 23:05:46 -0400
committerFreya Murphy <freya@freyacat.org>2025-04-03 23:05:46 -0400
commitd604f8e93fffc7db05cfe09b16fa1252c8470bc1 (patch)
tree3e2183d5414706b5ffbee8ffaf9f255a646eec85 /kernel/include
parentfmt (diff)
downloadcomus-d604f8e93fffc7db05cfe09b16fa1252c8470bc1.tar.gz
comus-d604f8e93fffc7db05cfe09b16fa1252c8470bc1.tar.bz2
comus-d604f8e93fffc7db05cfe09b16fa1252c8470bc1.zip
pci
Diffstat (limited to 'kernel/include')
-rw-r--r--kernel/include/comus/drivers.h17
-rw-r--r--kernel/include/comus/drivers/pci.h72
2 files changed, 89 insertions, 0 deletions
diff --git a/kernel/include/comus/drivers.h b/kernel/include/comus/drivers.h
new file mode 100644
index 0000000..3a38d3b
--- /dev/null
+++ b/kernel/include/comus/drivers.h
@@ -0,0 +1,17 @@
+/**
+ * @file drivers.h
+ *
+ * @author Freya Murphy <freya@freyacat.org>
+ *
+ * Entrypoint for initalizing all devices
+ */
+
+#ifndef DRIVERS_H_
+#define DRIVERS_H_
+
+/**
+ * Initalize all supported drivers
+ */
+void drivers_init(void);
+
+#endif /* drivers.h */
diff --git a/kernel/include/comus/drivers/pci.h b/kernel/include/comus/drivers/pci.h
new file mode 100644
index 0000000..34bcdda
--- /dev/null
+++ b/kernel/include/comus/drivers/pci.h
@@ -0,0 +1,72 @@
+/**
+ * @file pci.h
+ *
+ * @author Freya Murphy <freya@freyacaat.org>
+ * @author Tristan Miller <trimill@trimillxyz.org>
+ *
+ * PCI driver
+ */
+
+#ifndef PCI_H_
+#define PCI_H_
+
+#include <stdbool.h>
+#include <stddef.h>
+#include <stdint.h>
+
+// common
+#define PCI_VENDOR_W 0x00
+#define PCI_DEVICE_W 0x02
+#define PCI_COMMAND_W 0x04
+#define PCI_STATUS_W 0x06
+#define PCI_REVISION_B 0x08
+#define PCI_PROG_IF_B 0x09
+#define PCI_SUBCLASS_B 0x0A
+#define PCI_CLASS_B 0x0B
+#define PCI_CACHE_SIZE_B 0x0C
+#define PCI_LATENCY_TIMER_B 0x0D
+#define PCI_HEADER_TYPE_B 0x0E
+#define PCI_BIST_B 0x0F
+
+// header type 0
+#define PCI_BAR0_D 0x10
+#define PCI_BAR1_D 0x14
+#define PCI_BAR2_D 0x18
+#define PCI_BAR3_D 0x1C
+#define PCI_BAR4_D 0x20
+#define PCI_BAR5_D 0x24
+#define PCI_CARDBUS_CIS_D 0x28
+#define PCI_SUBSYSTEM_VENDOR_W 0x2C
+#define PCI_SUBSYSTEM_W 0x2E
+#define PCI_EXPANSION_ROM_D 0x30
+#define PCI_CAP_PTR_B 0x34
+#define PCI_INT_LINE_B 0x3C
+#define PCI_INT_PIN_B 0x3D
+#define PCI_MIN_GRANT_B 0x3E
+#define PCI_MAX_LATENCY_B 0x3F
+
+struct pci_device {
+ uint8_t bus : 8;
+ uint8_t device : 5;
+ uint8_t function : 3;
+};
+
+/**
+ * Load the PCI driver
+ */
+void pci_init(void);
+
+bool pci_findby_class(struct pci_device *dest, uint8_t class, uint8_t subclass,
+ size_t *offset);
+bool pci_findby_id(struct pci_device *dest, uint16_t device, uint16_t vendor,
+ size_t *offset);
+
+uint32_t pci_rcfg_d(struct pci_device dev, uint8_t offset);
+uint16_t pci_rcfg_w(struct pci_device dev, uint8_t offset);
+uint8_t pci_rcfg_b(struct pci_device dev, uint8_t offset);
+
+void pci_wcfg_d(struct pci_device dev, uint8_t offset, uint32_t dword);
+void pci_wcfg_w(struct pci_device dev, uint8_t offset, uint16_t word);
+void pci_wcfg_b(struct pci_device dev, uint8_t offset, uint8_t byte);
+
+#endif /* pci.h */