From 51adb0197c7ac4668cd924cb710c96748490f6a1 Mon Sep 17 00:00:00 2001 From: acevest Date: Tue, 16 Nov 2021 12:27:24 +0800 Subject: [PATCH] =?utf8?q?ata=E7=94=A8=E4=B8=AD=E6=96=AD+waitqueue?= =?utf8?q?=E8=AF=BB=E4=BF=A1=E6=81=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- drivers/ata.c | 17 +++++++++++------ drivers/ide.c | 16 +++++----------- drivers/ide.h | 5 +++++ 3 files changed, 21 insertions(+), 17 deletions(-) diff --git a/drivers/ata.c b/drivers/ata.c index d2dc346..ec365c4 100644 --- a/drivers/ata.c +++ b/drivers/ata.c @@ -10,9 +10,12 @@ #include #include #include +#include #include #include #include +#include + extern ide_pci_controller_t ide_pci_controller; #define ATA_TIMEOUT 10 // 10次时钟中断 @@ -43,24 +46,26 @@ void ata_test(uint64_t nr) { u16 identify[256]; void ata_send_read_identify_cmd(int dev) {} void ata_read_identify(int dev) { // 这里所用的dev是逻辑编号 ATA0、ATA1下的Master、Salve的dev分别为0,1,2,3 + + DECLARE_WAIT_QUEUE_HEAD(wq_head); + DECLARE_WAIT_QUEUE(wait, current); + add_wait_queue(&wq_head, &wait); + ide_pci_controller.task = current; + outb(0x00, REG_CTL(dev)); outb(0x00 | ((dev & 0x01) << 4), REG_DEVICE(dev)); // 根据文档P113,这里不用指定bit5, bit7,直接指示DRIVE就行 unsigned long flags; irq_save(flags); - void add_to_ide_wait_queue(); - add_to_ide_wait_queue(); - + current->state = TASK_WAIT; outb(ATA_CMD_IDENTIFY, REG_CMD(dev)); irq_restore(flags); schedule(); - printk("asfdasdfasd----\n"); - - // sleep_on_ide(); + del_wait_queue(&wq_head, &wait); insw(REG_DATA(dev), identify, SECT_SIZE / sizeof(u16)); diff --git a/drivers/ide.c b/drivers/ide.c index b399fc2..14e6cbe 100644 --- a/drivers/ide.c +++ b/drivers/ide.c @@ -13,7 +13,7 @@ #include // #include -// #include +#include // #include // #include // #include @@ -538,18 +538,10 @@ DECLARE_WAIT_QUEUE_HEAD(ide_wait_queue_head); void sleep_on_ide() { sleep_on(&ide_wait_queue_head); } -wait_queue_t iwait; -// DECLARE_WAIT_QUEUE(wait, current); -void add_to_ide_wait_queue() { - iwait.task = current; - iwait.task_list.prev = &iwait.task_list; - iwait.task_list.next = &iwait.task_list; - list_add_tail(&iwait.task_list, &ide_wait_queue_head.task_list); -} - extern void *mbr_buf; uint8_t ata_pci_bus_status(); extern ide_pci_controller_t ide_pci_controller; + void ide_irq_handler(unsigned int irq, pt_regs_t *regs, void *devid) { printk("ide irq handler %d \n", irq); @@ -568,7 +560,9 @@ void ide_irq_handler(unsigned int irq, pt_regs_t *regs, void *devid) { } #endif - wake_up(&ide_wait_queue_head); + // wake_up(&ide_wait_queue_head); + + ide_pci_controller.task->state = TASK_RUNNING; } void ide_init() { diff --git a/drivers/ide.h b/drivers/ide.h index 803ff55..62979d1 100644 --- a/drivers/ide.h +++ b/drivers/ide.h @@ -11,6 +11,7 @@ #include #include +#include // extern unsigned int HD_CHL0_CMD_BASE; // extern unsigned int HD_CHL1_CMD_BASE; @@ -173,6 +174,10 @@ typedef struct _ide_pci_controller { unsigned int bus_prdt; prdte_t *prdt; + + // 这里应该改成一个请求链表 + // 先简单实现 + task_union *task; } ide_pci_controller_t; void sleep_on_ide(); \ No newline at end of file -- 2.44.0