]> Zhao Yanbai Git Server - kernel.git/commitdiff
初步添加扫描AHCI的SATA设备代码
authoracevest <zhaoyanbai@126.com>
Wed, 31 Dec 2025 12:34:15 +0000 (20:34 +0800)
committeracevest <zhaoyanbai@126.com>
Wed, 31 Dec 2025 12:34:15 +0000 (20:34 +0800)
drivers/ide.c
drivers/sata.c [new file with mode: 0644]
kernel/setup.c

index f96715bd16befda7ef89505304065fdd49bdc7b9..2ab964f4b375c37c5c52f2d1ead72d7ebb67f739 100644 (file)
@@ -177,7 +177,7 @@ void ide_pci_init(pci_device_t *pci) {
            pci->vendor, pci->classcode);
 
     for (int i = 0; i < 6; i++) {
-        printd("ide pci BAR%u value 0x%08X\n", i, pci->bars[i]);
+        printd("  ide pci BAR%u value 0x%08X\n", i, pci->bars[i]);
         if (pci->bars[i] != 0) {
             assert((pci->bars[i] & 0x1) == 0x1);
         }
@@ -202,7 +202,7 @@ void ide_pci_init(pci_device_t *pci) {
         atomic_set(&ide_pci_controller[i].consumed_cnt, 0);
 
         iobase += i * 8;  // secondary channel 需要加8
-        printd("ide pci Base IO Address Register %08x\n", iobase);
+        printd("  ide pci Base IO Address Register %08x\n", iobase);
         ide_pci_controller[i].bus_iobase = iobase;
         ide_pci_controller[i].bus_cmd = iobase + PCI_IDE_CMD;
         ide_pci_controller[i].bus_status = iobase + PCI_IDE_STATUS;
diff --git a/drivers/sata.c b/drivers/sata.c
new file mode 100644 (file)
index 0000000..f3d6d3f
--- /dev/null
@@ -0,0 +1,39 @@
+/*
+ * ------------------------------------------------------------------------
+ *   File Name: sata.c
+ *      Author: Zhao Yanbai
+ *              2025-12-31 20:29:10 Wednesday CST
+ * Description: none
+ * ------------------------------------------------------------------------
+ */
+
+#include <pci.h>
+#include <system.h>
+
+
+void init_sata() {
+    pci_device_t *pci = pci_find_device_by_classcode(0x0106);
+    if (pci == NULL) {
+        printk("can not find pci classcode: %08x", 0x0106);
+        panic("can not find sata controller");
+    }
+    // progif
+    // 0x01 AHCI
+    //
+    // 另外读取 BAR5 的 CAP 寄存器,如果 CAP 寄存器的 31 位为 1,则表示支持 AHCI 模式。
+
+    if (pci->progif == 0x01) {
+        printk("AHCI mode supported\n");
+    } else {
+        printk("AHCI mode not supported\n");
+    }
+
+    printk("found sata pci progif %02x %03d:%02d.%d #%02d %04X:%04X\n", pci->progif, pci->bus, pci->dev, pci->devfn, pci->intr_line, pci->vendor, pci->device);
+    for (int i = 0; i < 6; i++) {
+        printk("  sata pci BAR%u value 0x%08X\n", i, pci->bars[i]);
+        // if (pci->bars[i] != 0) {
+        //     assert((pci->bars[i] & 0x1) == 0x1);
+        // }
+    }
+
+}
index c75f3018d31d671faad8b7be8b4c52100d9025f8..f224520ca13706f9a2c797c9b5448ceee724a296 100644 (file)
@@ -140,4 +140,7 @@ void setup_kernel() {
 
     void ide_init();
     ide_init();
+
+    void init_sata();
+    init_sata();
 }