Skip to content

Commit

Permalink
恢复硬盘中断处理逻辑
Browse files Browse the repository at this point in the history
  • Loading branch information
acevest committed Sep 24, 2024
1 parent f928dd9 commit 6f5ceab
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 17 deletions.
31 changes: 15 additions & 16 deletions drivers/ide.c
Original file line number Diff line number Diff line change
Expand Up @@ -115,35 +115,34 @@ void ide_irq_bh_handler(void *arg) {

ide_pci_controller_t *ide_ctrl = ide_pci_controller + channel;

int r = atomic_read(&(ide_ctrl->request_cnt));
int i = atomic_read(&(ide_ctrl->irq_cnt));
int c = atomic_read(&(ide_ctrl->consumed_cnt));

printlxy(MPL_IDE0 + channel, MPO_IDE, "IDE%d req %u irq %u consumed %u", channel, r, i, c);
}

void ide_irq_handler(unsigned int irq, pt_regs_t *regs, void *devid) {
// printk("ide irq %d handler pci status: 0x%02x\n", irq, ata_pci_bus_status());
int channel = irq == ide_pci_controller[0].irq_line ? 0 : 1;

const int drvid = (channel << 1); // 虚拟一个
ide_pci_controller_t *ide_ctrl = ide_pci_controller + channel;
// 读相关status寄存器
const int drvid = (channel << 1); // 虚拟一个drvid
ide_ctrl->status = inb(REG_STATUS(drvid));
ide_ctrl->pci_status = inb(ide_ctrl->bus_status);

//
atomic_inc(&ide_ctrl->irq_cnt);

ata_dma_stop(channel);
//
int r = atomic_read(&(ide_ctrl->request_cnt));
int i = atomic_read(&(ide_ctrl->irq_cnt));
int c = atomic_read(&(ide_ctrl->consumed_cnt));
printlxy(MPL_IDE0 + channel, MPO_IDE, "IDE%d req %u irq %u consumed %u", channel, r, i, c);

// 之前这里是用up()来唤醒磁盘任务
// 但在中断的底半处理,不应该切换任务,因为会引起irq里的reenter问题,导致不能再进底半处理,也无法切换任务
// 所以就移除了up()里的 schedule()
// 后来就改用完成量来通知磁盘任务,就不存在这个问题了

// complete会唤醒进程,但不会立即重新调度进程
complete(&ide_ctrl->intr_complete);
}

void ide_irq_handler(unsigned int irq, pt_regs_t *regs, void *devid) {
// printk("ide irq %d handler pci status: 0x%02x\n", irq, ata_pci_bus_status());
int channel = irq == ide_pci_controller[0].irq_line ? 0 : 1;

ata_dma_stop(channel);

// 纯debug打印
add_irq_bh_handler(ide_irq_bh_handler, (void *)channel);
}

Expand Down
2 changes: 1 addition & 1 deletion kernel/task_disk.c
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ void disk_task_entry(void *arg) {
int channel = (int)arg;
ide_pci_controller_t *ide_ctrl = ide_pci_controller + channel;

#if 0
#if 1
// 为了在DEBUG时看到RUN
int cnt = 2;
for (int i = 0; i < cnt; i++) {
Expand Down

0 comments on commit 6f5ceab

Please sign in to comment.