]> Zhao Yanbai Git Server - kernel.git/commitdiff
authoracevest <zhaoyanbai@126.com>
Fri, 27 Nov 2026 10:52:54 +0000 (18:52 +0800)
committeracevest <zhaoyanbai@126.com>
Fri, 27 Nov 2026 10:52:54 +0000 (18:52 +0800)
19 files changed:
boot/cmdline.c
drivers/ata.c
drivers/block.c
fs/buffer.c
fs/device.c [new file with mode: 0644]
fs/ext2.c
fs/file.c
fs/super.c
fs/vfs.h
include/buffer.h
include/device.h [new file with mode: 0644]
include/disk.h
include/system.h
include/types.h
kernel/ap.c
kernel/setup.c
kernel/task_disk.c
kernel/task_ide.c [deleted file]
kernel/task_init.c

index 3133e7d..8a78a9b 100644 (file)
@@ -34,20 +34,20 @@ void parse_cmdline(const char* cmdline) {
     system.cmdline = cmdline;
     printk("cmdline: %s\n", system.cmdline);
 
-    get_value("root", value);
+    // get_value("root", value);
 
-    assert(strlen(value) >= 4);
+    // assert(strlen(value) >= 4);
 
-    assert(value[0] == 'h' && value[1] == 'd');
-    assert(value[2] >= 'a' && value[2] <= 'd');
+    // assert(value[0] == 'h' && value[1] == 'd');
+    // assert(value[2] >= 'a' && value[2] <= 'd');
 
-    int disk_drvid = value[2] - 'a';
+    // int disk_drvid = value[2] - 'a';
 
-    uint32_t partid = atoi(value + 3);
-    assert(partid >= 1);
+    // uint32_t partid = atoi(value + 3);
+    // assert(partid >= 1);
 
-    system.root_dev = MAKE_DISK_DEV(disk_drvid, partid);
-    printk("root device %s [0x%08x]\n", value, system.root_dev);
+    // system.root_dev = MAKE_DISK_DEV(disk_drvid, partid);
+    // printk("root device %s [0x%08x]\n", value, system.root_dev);
 
     get_value("delay", value);
     system.delay = atoi(value);
index 5602e22..0434cfe 100644 (file)
@@ -338,7 +338,11 @@ void ide_ata_init(uint16_t* identify) {
 
 void ide_disk_read(dev_t dev, uint32_t sect_nr, uint32_t count, bbuffer_t* b) {
     disk_request_t r;
+#if 0
     r.dev = dev;
+#else
+    assert(0);
+#endif
     r.command = DISK_REQ_READ;
     r.pos = sect_nr;
     r.count = count;
@@ -352,7 +356,11 @@ void tmp_ide_disk_read(dev_t dev, uint32_t sect_nr, uint32_t count, char* buf) {
     int retry = 3;
     while (retry--) {
         disk_request_t r;
+#if 0
         r.dev = dev;
+#else
+        assert(0);
+#endif
         r.command = DISK_REQ_READ;
         r.pos = sect_nr;
         r.count = count;
index 39246c9..a70ef3b 100644 (file)
 #include <fs.h>
 #include <ide.h>
 
-void ide_disk_read(dev_t dev, uint32_t sect_nr, uint32_t count, bbuffer_t* b);
-void block_read(bbuffer_t* b) {
-    assert(b != NULL);
-    assert(b->data != NULL);
-    assert(b->page != NULL);
-    assert(DEV_MAJOR(b->dev) == DEV_MAJOR_DISK);
-    assert(b->block_size != 0);
-
-    ide_disk_read(b->dev, (b->block * b->block_size) / 512, b->block_size / 512, b);
-}
+// void ide_disk_read(dev_t dev, uint32_t sect_nr, uint32_t count, bbuffer_t* b);
+// void block_read(bbuffer_t* b) {
+//     assert(b != NULL);
+//     assert(b->data != NULL);
+//     assert(b->page != NULL);
+//     assert(DEV_MAJOR(b->dev) == DEV_MAJOR_DISK);
+//     assert(b->block_size != 0);
+
+//     ide_disk_read(b->dev, (b->block * b->block_size) / 512, b->block_size / 512, b);
+// }
+
+
+int block_read(block_device_t* bdev, uint64_t byte_offset, uint32_t byte_count, void *data) {
+    // 根据dev找到对应的block driver
+    assert(bdev != NULL);
+    assert(byte_offset >= 0);
+    assert(byte_count >= 0);
+    if (byte_count > 0) {
+        assert(data != NULL);
+    }
+    assert(bdev->device.class == DEVICE_CLASS_BLOCK);
+
+    assert(bdev->ops != NULL);
 
-#include <ext2.h>
-// 读hda1 的 super block
-void ata_read_ext2_sb() {
-    // 初始默认blocksize = 1024
-    // 则ext2_superblock应该在第1个block的offset为0的位置
-    // ext2_superblock默认大小1024
-
-    const int block = 0;
-    const int offset = 1024;
-    const int size = 4096;
-    bbuffer_t* bb = bread(system.root_dev, block, size);
-
-    ext2_sb_t* p = (ext2_sb_t*)(bb->data + offset);
-    printk("inodes count %u inodes per group %u free %u\n", p->s_inodes_count, p->s_inodes_per_group,
-           p->s_free_inodes_count);
-    printk("blocks count %u blocks per group %u free %u magic %04x\n", p->s_blocks_count, p->s_blocks_per_group,
-           p->s_free_blocks_count, p->s_magic);
-    printk("first ino %u inode size %u first data block %u\n", p->s_first_ino, p->s_inode_size, p->s_first_data_block);
-    printk("log block size %u write time %u\n", p->s_log_block_size, p->s_wtime);
-    char volume_name[16 + 1];
-    strncpy(volume_name, p->s_volume_name, 16);
-    volume_name[16] = 0;
-    printk("volume %s\n", volume_name);
+    int ret = bdev->ops->read(bdev, byte_offset, byte_count, data);
+
+    return ret;
 }
+
+// #include <ext2.h>
+// // 读hda1 的 super block
+// void ata_read_ext2_sb() {
+//     // 初始默认blocksize = 1024
+//     // 则ext2_superblock应该在第1个block的offset为0的位置
+//     // ext2_superblock默认大小1024
+
+//     const int offset = 1024;
+    
+// #if 0
+//     const int block = 0;
+//     const int offset = 1024;
+//     const int size = 4096;
+//     bbuffer_t* bb = bread(system.root_dev, block, size);
+// #else
+//     bbuffer_t* bb = NULL;
+//     assert(0);
+// #endif
+
+//     ext2_sb_t* p = (ext2_sb_t*)(bb->data + offset);
+//     printk("inodes count %u inodes per group %u free %u\n", p->s_inodes_count, p->s_inodes_per_group,
+//            p->s_free_inodes_count);
+//     printk("blocks count %u blocks per group %u free %u magic %04x\n", p->s_blocks_count, p->s_blocks_per_group,
+//            p->s_free_blocks_count, p->s_magic);
+//     printk("first ino %u inode size %u first data block %u\n", p->s_first_ino, p->s_inode_size, p->s_first_data_block);
+//     printk("log block size %u write time %u\n", p->s_log_block_size, p->s_wtime);
+//     char volume_name[16 + 1];
+//     strncpy(volume_name, p->s_volume_name, 16);
+//     volume_name[16] = 0;
+//     printk("volume %s\n", volume_name);
+// }
index dcd8c31..f3c891a 100644 (file)
@@ -18,8 +18,17 @@ list_head_t block_buffer_hash_table[BLOCK_BUFFER_HASH_TABLE_SIZE] = {
     0,
 };
 
-int hashfn(dev_t dev, uint32_t block) {
-    return ((dev) ^ block) % BLOCK_BUFFER_HASH_TABLE_SIZE;
+int hashfn(block_device_t *bdev, uint32_t block) {
+    dev_t dev = bdev->device.id;
+    uint64_t dividend = ((uint64_t)(dev)) ^ ((uint64_t)(block));
+    uint64_t divisor = BLOCK_BUFFER_HASH_TABLE_SIZE;
+
+    uint64_t quotient = 0;
+    uint64_t remainder = 0;
+    udiv64(dividend, divisor, &quotient, &remainder);
+
+    return (int)remainder;
+    // return ((dev) ^ block) % BLOCK_BUFFER_HASH_TABLE_SIZE;
 }
 
 typedef struct bbuffer_store {
@@ -52,15 +61,15 @@ bbuffer_store_t* getstore(uint32_t size) {
     return s;
 }
 
-bbuffer_t* get_from_hash_table(dev_t dev, uint64_t block, uint32_t size) {
+bbuffer_t* get_from_hash_table(block_device_t *bdev, uint64_t block, uint32_t size) {
     list_head_t* p = 0;
     bbuffer_t* b = 0;
 
-    uint32_t hash = hashfn(dev, block);
+    uint32_t hash = hashfn(bdev, block);
     assert(hash < BLOCK_BUFFER_HASH_TABLE_SIZE);
     list_for_each(p, block_buffer_hash_table + hash) {
         bbuffer_t* t = list_entry(p, bbuffer_t, node);
-        if (t->dev != dev) {
+        if (t->bdev != bdev) {
             continue;
         }
 
@@ -89,19 +98,18 @@ bbuffer_t* get_from_hash_table(dev_t dev, uint64_t block, uint32_t size) {
     return NULL;
 }
 
-bbuffer_t* getblk(dev_t dev, uint64_t block, uint32_t size) {
+bbuffer_t* getblk(block_device_t *bdev, uint64_t block, uint32_t size) {
     uint32_t iflags;
-    assert(size == 1024 || size == 2048 || size == 4096);
 
-    // 暂时先只支持hard disk
-    assert(DEV_MAJOR(dev) == DEV_MAJOR_DISK);
+    assert(bdev != NULL);
+    assert(size == 1024 || size == 2048 || size == 4096);
 
     int retry = 0;
 again:
     irq_save(iflags);
 
     // 先尝试从hash里分配
-    bbuffer_t* b = get_from_hash_table(dev, block, size);
+    bbuffer_t* b = get_from_hash_table(bdev, block, size);
     if (NULL != b) {
         return b;
     }
@@ -146,7 +154,7 @@ again:
     // 找到了
     b->block = block;
     b->block_size = size;
-    b->dev = dev;
+    b->bdev = bdev;
     atomic_set(&(b->ref_count), 1);
     b->uptodate = 0;
 
@@ -168,26 +176,34 @@ void brelse(bbuffer_t* b) {
     // waitq_wakeup_all(&s->waitq);
 }
 
-bbuffer_t* bread(dev_t dev, uint64_t block, uint32_t size) {
-    bbuffer_t* b = getblk(dev, block, size);
+bbuffer_t* bread(block_device_t* bdev, uint64_t block, uint32_t size) {
+    // bbuffer_t* b = getblk(bdev->device, block, size);
 
-    assert(b != NULL);
+    // assert(b != NULL);
 
-    if (b->uptodate == 1) {
-        return b;
-    }
+    // if (b->uptodate == 1) {
+    //     return b;
+    // }
 
-    // READ
-    void block_read(bbuffer_t * b);
-    block_read(b);
+    // // READ
+    // // void block_read(bbuffer_t * b);
+    // // block_read(b);
+    // int block_read(block_device_t* bdev, uint64_t byte_offset, uint32_t byte_count, void *data);
+    // int ret = bdev->ops->read(bdev, block * size, size, b->data);
+    // if(0 != ret) {
+    //     return NULL;
+    // }
+    // // TODO: call block_read
+    // assert(0);
 
-    // 等待I/O结束
-    completion_wait(&b->io_done);
-    if (b->uptodate == 1) {
-        return b;
-    }
 
-    brelse(b);
+    // // 等待I/O结束
+    // completion_wait(&b->io_done);
+    // if (b->uptodate == 1) {
+    //     return b;
+    // }
+
+    // brelse(b);
 
     return NULL;
 }
@@ -234,7 +250,7 @@ void init_buffer() {
             atomic_set(&(b->ref_count), 0);
             // b->data = data + (page_left_space - blocksize);
             b->data = data + (PAGE_SIZE - page_left_space);
-            b->dev = 0;
+            b->bdev = NULL;
             b->page = page;
             b->uptodate = 0;
             completion_init(&b->io_done);
diff --git a/fs/device.c b/fs/device.c
new file mode 100644 (file)
index 0000000..d58b65d
--- /dev/null
@@ -0,0 +1,57 @@
+/*
+ * ------------------------------------------------------------------------
+ *   File Name: device.c
+ *      Author: Zhao Yanbai
+ *              2026-08-31 16:35:02 Monday CST
+ * Description: none
+ * ------------------------------------------------------------------------
+ */
+
+
+#include <device.h>
+#include <system.h>
+#include <irq.h>
+
+
+dev_t alloc_device_id() {
+
+    static dev_t __next_device_id = 100;
+
+    unsigned long flags;
+    irq_save(flags);
+    dev_t id = __next_device_id;
+    __next_device_id++;
+    irq_restore(flags);
+    return id;
+}
+
+
+static list_head_t __device_list = LIST_HEAD_INIT(__device_list);
+
+
+int register_device(device_t *device) {
+    int ret = 0;
+
+    assert(device != NULL);
+
+    device->id = alloc_device_id();
+
+    unsigned long flags;
+    irq_save(flags);
+    list_add_tail(&device->list, &__device_list);
+    irq_restore(flags);
+
+    return ret;
+}
+
+
+
+dev_t device_id(device_t *device){
+    assert(device != NULL);
+    return device->id;
+}
+
+device_t *device_from_id(dev_t id) {
+    assert(0); // TODO implement
+    return NULL;
+}
\ No newline at end of file
index f6093a0..d66c03d 100644 (file)
--- a/fs/ext2.c
+++ b/fs/ext2.c
@@ -35,11 +35,17 @@ struct {
 extern void blk_rw(dev_t dev, u64_t offset, u32_t scnt, char* buf);
 extern void kmem_cache_free(kmem_cache_t* cache, void* addr);
 
+#if 0
 #define BLKRW(blkid, blkcnt, buf)                                                                   \
     do {                                                                                            \
         blk_rw(system.root_dev, 1ULL * (blkid) * EXT2_BLOCK_SIZE, (blkcnt) * EXT2_BLOCK_SIZE, buf); \
     } while (0)
-
+#else
+#define BLKRW(blkid, blkcnt, buf)   \
+    do {                            \
+        assert(0);                  \
+    } while (0)
+#endif
 kmem_cache_t* ext2_block_cache;
 kmem_cache_t* ext2_inode_cache;
 
index 396ddec..1417133 100644 (file)
--- a/fs/file.c
+++ b/fs/file.c
@@ -98,6 +98,8 @@ page_t* get_cached_page(address_space_t* mapping, uint32_t index) {
         page = alloc_one_page(0);
         assert(page != NULL);
 
+        memset(page2va(page), 0, PAGE_SIZE);
+
         page->index = index;
         page->mapping = mapping;
 
index e3faf48..862e470 100644 (file)
@@ -32,9 +32,10 @@ static superblock_t* alloc_super(fs_type_t* type) {
     return s;
 }
 
-static uint32_t __minor = 0;
+
+
 int set_anonymous_super(superblock_t* s, void* data) {
-    s->sb_dev = MAKE_DEV(0, ++__minor);
+    s->sb_bdev = NULL;
     return 0;
 }
 
index dc42c6e..88fdb69 100644 (file)
--- a/fs/vfs.h
+++ b/fs/vfs.h
@@ -14,6 +14,7 @@
 #include <page.h>
 #include <sync.h>
 #include <types.h>
+#include <system.h>
 
 typedef struct qstr {
     const char* name;
@@ -92,7 +93,8 @@ typedef struct superblock {
     list_head_t sb_list;
     list_head_t sb_instance;
 
-    dev_t sb_dev;
+    // dev_t sb_dev;
+    block_device_t* sb_bdev;
 } superblock_t;
 
 struct address_space_operations {
@@ -133,8 +135,9 @@ struct inode {
     // 缓存的pages
     list_head_t i_pages;
 
-    dev_t i_dev;   // inode存储在该设备上
-    dev_t i_rdev;  // inode所代表的设备号
+    // dev_t i_dev;   // inode存储在该设备上
+    // dev_t i_rdev;  // inode所代表的设备号
+    
 
     loff_t i_size;
 
index 7ce713b..a4b1f50 100644 (file)
@@ -19,7 +19,8 @@ typedef struct bbuffer {
     uint32_t block;  // block number
     void* data;      //
     atomic_t ref_count;
-    dev_t dev;
+    // dev_t dev;
+    block_device_t* bdev;
     page_t* page;
     list_head_t node;
     completion_t io_done;
@@ -27,6 +28,6 @@ typedef struct bbuffer {
     uint16_t uptodate : 1;
 } bbuffer_t;
 
-bbuffer_t* bread(dev_t dev, uint64_t block, uint32_t size);
+bbuffer_t* bread(block_device_t* bdev, uint64_t block, uint32_t size);
 
 void brelse(bbuffer_t* b);
diff --git a/include/device.h b/include/device.h
new file mode 100644 (file)
index 0000000..15e3b7e
--- /dev/null
@@ -0,0 +1,73 @@
+/*
+ * ------------------------------------------------------------------------
+ *   File Name: device.h
+ *      Author: Zhao Yanbai
+ *              2026-08-31 09:41:21 Monday CST
+ * Description: none
+ * ------------------------------------------------------------------------
+ */
+
+#pragma once
+
+#include <types.h>
+#include <list.h>
+
+
+typedef struct device device_t;
+typedef struct block_device block_device_t;
+typedef struct character_device character_device_t;
+
+
+struct device {
+    const char *name;
+    dev_t id;
+
+    list_head_t list;
+
+    enum {
+        DEVICE_CLASS_NONE = 0,
+        DEVICE_CLASS_BLOCK,
+        DEVICE_CLASS_CHARACTER,
+    } class;
+
+    union {
+        block_device_t *block_device;
+        character_device_t *character_device;
+    };
+};
+
+
+typedef struct block_device_ops block_device_ops_t;
+
+struct block_device_ops {
+    //
+    int (*read)(block_device_t *bdev, uint64_t byte_offset, uint32_t byte_count, void *data);
+};
+
+struct block_device {
+    device_t device;
+
+
+    block_device_ops_t *ops;
+
+    // 设备总大小
+    uint64_t size;
+
+    // 设备块大小
+    // 通常为512字节
+    uint32_t logical_block_size;
+
+    void *private;
+};
+
+
+struct character_device {
+    device_t device;
+};
+
+dev_t alloc_device_id();
+
+int register_device(device_t *device);
+
+dev_t device_id(device_t *device);
+device_t *device_from_id(dev_t id);
\ No newline at end of file
index a3e35f8..d2eb7aa 100644 (file)
@@ -20,7 +20,8 @@ typedef enum {
 } disk_request_cmd_t;
 
 typedef struct disk_request {
-    dev_t dev;
+    // dev_t dev;
+    block_device_t* bdev;
     uint64_t pos;    // 扇区号
     uint16_t count;  // 扇区数
     void* buf;       // 到的缓冲区
index 1cd8597..a07c08f 100644 (file)
@@ -42,6 +42,7 @@
 #include "printk.h"
 #include "types.h"
 #include <apic.h>
+#include <device.h>
 
 #define likely(x) __builtin_expect(!!(x), 1)
 #define unlikely(x) __builtin_expect(!!(x), 0)
@@ -112,8 +113,6 @@ typedef struct pt_regs {
     u16 ss, _ss;
 } __attribute__((packed)) pt_regs_t;
 
-typedef uint32_t dev_t;
-
 typedef struct system {
     u32 mmap_addr;
     u32 mmap_size;  // Byte
@@ -148,7 +147,7 @@ typedef struct system {
 
     void* rsdt_addr;
 
-    dev_t root_dev;
+    block_device_t* root_dev;
 
     //
     uint32_t ap_cpuid;
index 7c02bf7..62af978 100644 (file)
@@ -56,8 +56,8 @@ typedef unsigned long vaddr_t;
 typedef int64_t loff_t;
 typedef int32_t off_t;
 
-typedef uint32_t dev_t;
 typedef uint32_t umode_t;
+typedef unsigned int dev_t;
 
 typedef unsigned long pid_t;
 typedef unsigned long mode_t;
index bf70d43..194c6f5 100644 (file)
@@ -414,20 +414,20 @@ void print_all_tasks() {
     }
 }
 
-#include <ide.h>
-extern ide_pci_controller_t ide_pci_controller[];
-void ide_stat_print(ide_pci_controller_t* ide_ctrl) {
-    assert(ide_ctrl != NULL);
-    assert(ide_ctrl >= ide_pci_controller);
-    assert(ide_ctrl < (ide_pci_controller + NR_IDE_CONTROLLER));
-    int r = atomic_read(&(ide_ctrl->request_cnt));
-    int i = atomic_read(&(ide_ctrl->irq_cnt));
-    int c = atomic_read(&(ide_ctrl->consumed_cnt));
-    int channel = ide_ctrl->channel;
-    ap_printlxy(MPL_IDE0 + channel, MPO_IDE, "IDE%d req %u irq %u consumed %u", channel, r, i, c);
-}
-
-void print_all_ides() {
-    ide_stat_print(&ide_pci_controller[0]);
-    ide_stat_print(&ide_pci_controller[1]);
-}
+// #include <ide.h>
+// extern ide_pci_controller_t ide_pci_controller[];
+// void ide_stat_print(ide_pci_controller_t* ide_ctrl) {
+//     assert(ide_ctrl != NULL);
+//     assert(ide_ctrl >= ide_pci_controller);
+//     assert(ide_ctrl < (ide_pci_controller + NR_IDE_CONTROLLER));
+//     int r = atomic_read(&(ide_ctrl->request_cnt));
+//     int i = atomic_read(&(ide_ctrl->irq_cnt));
+//     int c = atomic_read(&(ide_ctrl->consumed_cnt));
+//     int channel = ide_ctrl->channel;
+//     ap_printlxy(MPL_IDE0 + channel, MPO_IDE, "IDE%d req %u irq %u consumed %u", channel, r, i, c);
+// }
+
+// void print_all_ides() {
+//     ide_stat_print(&ide_pci_controller[0]);
+//     ide_stat_print(&ide_pci_controller[1]);
+// }
index 4b062ff..85233e6 100644 (file)
@@ -152,10 +152,6 @@ void setup_kernel() {
 
     hpet_init_timer0(101);
 
-#if !DISABLE_IDE
-    void ide_init();
-    ide_init();
-#endif
     void init_ahci();
     init_ahci();
 
index 7e21e3d..a69367b 100644 (file)
@@ -51,9 +51,9 @@ int send_disk_request(disk_request_t* req) {
 }
 
 void disk_request(disk_request_t* req) {
-    int minor = DEV_MINOR(req->dev);
-    printk("disk_request dev %x minor %d\n", req->dev, minor);
-    assert(minor == 0);  // 先简单支持
+    // int minor = DEV_MINOR(req->dev);
+    printk("disk_request dev %x:%s\n", req->bdev->device.id, req->bdev->device.name);
+    // assert(minor == 0);  // 先简单支持
     assert(req->command == DISK_REQ_READ);
 
     sata_device_t* sata = &sata_devices[0];
diff --git a/kernel/task_ide.c b/kernel/task_ide.c
deleted file mode 100644 (file)
index 614d04f..0000000
+++ /dev/null
@@ -1,179 +0,0 @@
-/*
- * ------------------------------------------------------------------------
- *   File Name: task_disk.c
- *      Author: Zhao Yanbai
- *              2021-11-15 12:19:00 Monday CST
- * Description: none
- * ------------------------------------------------------------------------
- */
-
-#include <sync.h>
-#include <disk.h>
-#include <ide.h>
-#include <sched.h>
-
-#if 0
-void ata_read_identify(int drv, int disable_intr);
-void ata_pio_read_data(int drvid, int sect_cnt, void* dst);
-void ata_dma_read_ext(int drv, uint64_t pos, uint16_t count, void* dest);
-
-int send_disk_request(disk_request_t* r) {
-#if DISABLE_IDE
-    return 0;
-#endif
-    if (NULL == r) {
-        panic("null disk request");
-    }
-
-    ide_drive_t* drv = ide_get_drive(r->dev);
-
-    assert(drv->present == 1);
-
-    // 这个用来让task_disk唤醒自己
-    semaphore_init(&r->sem, 0);
-
-    r->ret = 0;
-
-    // 校验pos,和pos+count是否大于硬盘返回的最大LBA48
-    // ...
-
-    // 校验buffer是否跨64K
-    // 先不处理
-
-#if 1
-    {
-        const uint32_t size = r->count * 512;
-        const uint32_t _64K = 1 << 16;
-        assert(((((uint32_t)r->buf) & (_64K - 1)) + size) <= _64K);
-    }
-#else
-    if (((uint32_t)r->buf & 0xFFFF0000) != (((uint32_t)(r->buf + r->count * 512 - 1)) & 0xFFFF0000)) {
-        printk("dma read addr %08x count %d\n", r->buf, r->count);
-        panic("disk DMA read cross 64K");
-    }
-#endif
-
-    mutex_lock(&drv->ide_pci_controller->request_mutex);
-    atomic_inc(&drv->ide_pci_controller->request_cnt);
-    list_add_tail(&r->list, &drv->ide_pci_controller->request_queue.list);
-    mutex_unlock(&drv->ide_pci_controller->request_mutex);
-
-    // 唤醒task_disk
-    up(&drv->ide_pci_controller->request_queue.sem);
-
-    // 等待被task_disk唤醒
-    down(&r->sem);
-
-    return r->ret;
-}
-
-void disk_task_entry(void* arg) {
-    int r_cnt = 0;
-    while (1) {
-        int channel = (int)arg;
-        ide_pci_controller_t* ide_ctrl = ide_pci_controller + channel;
-
-#if 1
-        // 为了在DEBUG时看到RUN
-        int cnt = 2;
-        for (int i = 0; i < cnt; i++) {
-            asm("hlt;");
-        }
-#endif
-
-        // printk("wait request for hard disk channel %d\n", channel);
-        down(&ide_ctrl->request_queue.sem);
-        // printk("hard disk channel %d\n", channel);
-
-        mutex_lock(&ide_ctrl->request_mutex);
-        disk_request_t* r;
-        r = list_first_entry(&ide_ctrl->request_queue.list, disk_request_t, list);
-        if (NULL == r) {
-            panic("no disk request");
-        }
-
-        list_del(&r->list);
-        atomic_inc(&ide_ctrl->consumed_cnt);
-        mutex_unlock(&ide_ctrl->request_mutex);
-
-        ide_drive_t* drv = ide_get_drive(r->dev);
-        int drvid = drv->drvid;
-        if (drv->present == 0) {
-            panic("disk not present");
-        }
-        assert(drv->present == 1);
-
-        int part_id = DEV_MINOR((r->dev)) & 0xFF;
-        assert(part_id < MAX_DISK_PARTIONS);
-        assert(MAKE_DISK_DEV(drvid, part_id) == r->dev);
-
-        uint64_t pos = r->pos + drv->partions[part_id].lba_start;
-        // printk("pos %lu partid %d lba end %lu\n", pos, part_id, drv->partions[part_id].lba_end);
-        // assert(pos < drv->partions[part_id].lba_end);
-        if ((pos >= drv->partions[part_id].lba_end)) {
-            printk("pos %lu partid %d lba %lu %lu\n", pos, part_id, drv->partions[part_id].lba_start,
-                   drv->partions[part_id].lba_end);
-            panic("INVARG");
-        }
-
-        const bool pio_mode = false;
-        completion_init(&ide_ctrl->intr_complete);
-
-        switch (r->command) {
-        case DISK_REQ_IDENTIFY:
-            printk("try to read disk drive %u identify\n", drvid);
-            assert(r->count == 1);
-            ata_read_identify(drvid, 0);
-            break;
-        case DISK_REQ_READ:
-            assert(r->count > 0);
-            assert(r->buf != NULL || r->bb->data != NULL);
-            // printk("DISK READ drvid %u pos %u count %u bb %x\n", drvid, (uint32_t)pos, r->count, r->bb);
-            if (pio_mode) {
-                int ata_pio_read_ext(int drvid, uint64_t pos, uint16_t count, int timeout, void* dest);
-                if (r->bb != 0) {
-                    ata_pio_read_ext(drvid, pos, r->count, 100, r->bb->data);
-                } else {
-                    ata_pio_read_ext(drvid, pos, r->count, 100, r->buf);
-                }
-            } else {
-                if (r->bb != 0) {
-                    ata_dma_read_ext(drvid, pos, r->count, r->bb->data);
-                } else {
-                    ata_dma_read_ext(drvid, pos, r->count, r->buf);
-                }
-            }
-            break;
-        default:
-            panic("invalid disk request command");
-            break;
-        }
-
-        int ret = 0;
-        if (!pio_mode) {
-            // 等待硬盘中断
-            completion_wail(&ide_ctrl->intr_complete);
-
-            if ((ide_ctrl->status & (ATA_STATUS_BSY | ATA_STATUS_BSY | ATA_STATUS_WF)) != 0) {
-                printk("IDE status %02X error for drv %u pos %lu count %u\n", ide_ctrl->status, drvid, pos, r->count);
-                ret = -1;
-            }
-        }
-
-        // 读数据
-        if (DISK_REQ_IDENTIFY == r->command) {
-            ata_pio_read_data(drvid, 1, r->buf);
-        }
-
-        if (r->bb != 0) {
-            r->bb->uptodate = 1;
-            completion_complete(&r->bb->io_done);
-        }
-
-        r->ret = ret;
-
-        // 唤醒等待该请求的进程
-        up(&(r->sem));
-    }
-}
-#endif
index e71eaa8..2423ee5 100644 (file)
@@ -66,7 +66,7 @@ void taskA_entry() {
         memset(disk_buf1, 0, 512);
 
         disk_request_t r;
-        r.dev = MAKE_DISK_DEV(0, 0);
+        // r.bdev = &sata_devices[0].bdev;
         r.command = DISK_REQ_READ;
         r.pos = sect_nr;
         r.count = 1;
@@ -175,28 +175,8 @@ void init_task_entry() {
     void init_rootfs();
     init_rootfs();
 
-#if !DISABLE_IDE
-#if 1
-    kernel_task("ide/0", disk_task_entry, (void*)0);
-
-    void ide_read_partions();
-    ide_read_partions();
-
-    void ata_read_ext2_sb();
-    ata_read_ext2_sb();
-#endif
-#endif
-
-#if 0
-    extern int ide_read_partions_done;
-    while(!ide_read_partions_done) {
-           printk("wait for hard disk partition table done\n");
-           sysc_wait(1);
-    }
-#endif
 
 #if 1
-
     kernel_task("disk", disk_task_entry, NULL);
     kernel_task("user", user_task_entry, NULL);
     kernel_task("tskA", taskA_entry, NULL);