From: AceVest Date: Sat, 31 May 2014 04:19:15 +0000 (+0800) Subject: can receive irq after each cmd write to ide X-Git-Tag: 0.3.0~57 X-Git-Url: http://zhaoyanbai.com/repos/named-checkzone.html?a=commitdiff_plain;h=6aef1195ec4bec3c2657f7fb1dfc9b71f8073bb7;p=kernel.git can receive irq after each cmd write to ide --- diff --git a/drivers/ide.c b/drivers/ide.c index 3b87bde..05a60eb 100644 --- a/drivers/ide.c +++ b/drivers/ide.c @@ -30,72 +30,6 @@ typedef struct _hd_drv hd_drive_t hdrv; - -void ide_read_identify() -{ - unsigned char *buf = (unsigned char *) alloc_one_page(0); - - // Select Drive - outb_p(0xA0, REG_DEVSEL(0)); - - //outb_p(0x00, REG_CTL(0)); - - outb(0, REG_NSECTOR(0)); // High - outb(1, REG_NSECTOR(0)); // Low - - outb(0, REG_LBAL(0)); - outb(1, REG_LBAL(0)); - - outb(0, REG_LBAM(0)); - outb(0, REG_LBAM(0)); - - outb(0, REG_LBAH(0)); - outb(0, REG_LBAH(0)); - - outb_p(HD_CMD_IDENTIFY, REG_CMD(0)); - - while(1) { - u8_t status = inb(REG_STATUS(0)); - printk("status %02x\n", status); - if(status & HD_STATUS_ERR) { - printk("Hard Disk Error.\n"); - break; - } - if(!(status & HD_STATUS_BSY) && (status & HD_STATUS_DRQ)) { - break; - } - int i = 1000000000; - while(i--); - } - - insw(REG_DATA(0), buf, 256); - - int i; - for(i=0; i<32; i+=2) - { - unsigned char *p; - unsigned char c; -#if 1 - p = buf+ATA_IDENT_SERIAL; - c = p[i + 1]; - p[i+1] = p[i]; - p[i] = c; -#endif - - p = buf + ATA_IDENT_MODEL; - c = p[i + 1]; - p[i+1] = p[i]; - p[i] = c; - } - - buf[ATA_IDENT_SERIAL+32] = 0; - buf[ATA_IDENT_MODEL+32] = 0; - - printk("Hard Disk SN: %s Model: %s\n", buf + ATA_IDENT_SERIAL, buf + ATA_IDENT_MODEL); - - free_pages((unsigned long)buf); -} - unsigned int iobase; typedef struct prd { @@ -106,6 +40,7 @@ typedef struct prd } prd_t; #define PRD_CNT 1 +#define USE_DMA 0 prd_t hd_prd_tbl[PRD_CNT] __attribute__((aligned(64*1024))); unsigned long prdt_phys = 0; void ide_pci_init(pci_device_t *pci) @@ -121,10 +56,10 @@ void ide_pci_init(pci_device_t *pci) printk(" ide pci Base IO Address Register %08x\n", v); iobase = v & 0xFFFC; -#if 1 - v = inw(iobase+0); +#if USE_DMA + v = inb(iobase+0); printk(" ide bus master ide command register primary %04x\n", v); - v = inw(iobase+2); + v = inb(iobase+2); printk(" ide bus master ide status register primary %04x\n", v); #endif @@ -137,8 +72,7 @@ void ide_pci_init(pci_device_t *pci) } printk("\n"); -#if 1 - +#if USE_DMA prd_t *p = (prd_t *) va2pa(hd_prd_tbl); printk("iobase %04x hd_prd_tbl %08x physical %08x sizeof prd %d\n", iobase, hd_prd_tbl, p, sizeof(prd_t)); p->addr = 0; @@ -160,7 +94,7 @@ void ide_pci_init(pci_device_t *pci) void ide_hd_out(Dev dev, u32 nsect, u64 sect_nr, u32 cmd) { -#if 1 +#if USE_DMA outb(0x00, iobase); //outl(prdt_phys, iobase+4); @@ -178,29 +112,33 @@ void ide_hd_out(Dev dev, u32 nsect, u64 sect_nr, u32 cmd) unsigned long long sect_nr = 0; unsigned int nsect = 1; - outb_p(0x00, REG_CTL(dev)); - outb(0xE0, REG_DEVSEL(dev)); + outb(0x00, REG_CTL(dev)); + outb(0x40, REG_DEVSEL(dev)); outb(0, REG_NSECTOR(dev)); // High - outb((u8)nsect, REG_NSECTOR(dev)); // Low - outb((u8)((sect_nr>>24)&0xFF), REG_LBAL(dev)); - outb((u8)((sect_nr>> 0)&0xFF), REG_LBAL(dev)); - outb((u8)((sect_nr>>32)&0xFF), REG_LBAM(dev)); - outb((u8)((sect_nr>> 8)&0xFF), REG_LBAM(dev)); - outb((u8)((sect_nr>>40)&0xFF), REG_LBAH(dev)); - outb((u8)((sect_nr>>16)&0xFF), REG_LBAH(dev)); - - outb(0x25, REG_CMD(dev)); + outb((u8)nsect, REG_NSECTOR(dev)); // Low + outb((u8)((sect_nr>> 0)&0xFF), REG_LBAL(dev)); + outb((u8)((sect_nr>> 8)&0xFF), REG_LBAM(dev)); + outb((u8)((sect_nr>>16)&0xFF), REG_LBAH(dev)); + outb(0x24, REG_CMD(dev)); } } void dump_pci_ide(); + +void ide_status() +{ + u8_t idest = inb(REG_STATUS(0)); + u8_t pcist = inb(iobase+2); + printk(" ide status %02x pci status %02x\n", idest, pcist); + +} void ide_debug() { u32 device; @@ -231,9 +169,9 @@ void dump_pci_controller(unsigned int vendor, unsigned int device) void dump_pci_ide() { - //dump_pci_controller(PCI_VENDORID_INTEL, 0x7010); dump_pci_controller(PCI_VENDORID_INTEL, 0x2922); dump_pci_controller(PCI_VENDORID_INTEL, 0x2829); + //dump_pci_controller(PCI_VENDORID_INTEL, 0x7000); } void ide_irq() @@ -242,9 +180,20 @@ void ide_irq() #if 1 unsigned short *p = (unsigned short *) (0+510); printk("||----------------- %s:%d status %04x SIG: %04x\n", __func__, __LINE__, sa, *p); + u8_t v = inb(iobase+2); + printk(" irq pci ide status register primary %02x\n", v); + v |= 0x04; + printk(" irq pci ide status before write %02x\n", v); + //outb(v, iobase+2); + v = inb(iobase+2); + printk(" irq pci ide status after write %02x\n", v); outb(0x00, iobase); - unsigned short v = inw(iobase+2); - printk(" irq ide status register primary %04x\n", v); + + char buf[1024]; + memset(buf, 0xEE, 1024); + insw(REG_DATA(0), buf, 512>>1); + unsigned short *s = (unsigned short *) (buf+510); + printk("insw %04x\n", *s); #else char buf[1024]; memset(buf, 0xEE, 1024); @@ -269,7 +218,7 @@ void ide_irq() void ide_init() { pci_device_t *pci = 0; - dump_pci_ide(); + //dump_pci_ide(); #if 0 pci = pci_find_device(PCI_VENDORID_INTEL, 0x7010); // qemu if(pci == 0) diff --git a/drivers/keyboard.c b/drivers/keyboard.c index 37ef2e0..c77ef68 100644 --- a/drivers/keyboard.c +++ b/drivers/keyboard.c @@ -36,6 +36,7 @@ static struct extern void reboot(); extern void poweroff(); extern void ide_debug(); +extern void ide_status(); void kbd_handler(unsigned int irq, pt_regs_t * regs, void *dev_id) { unsigned char scan_code; @@ -46,9 +47,12 @@ void kbd_handler(unsigned int irq, pt_regs_t * regs, void *dev_id) printk("%02x", scan_code); - if(scan_code == 0x13) + if(scan_code == 0x13) // r ide_debug(); + if(scan_code == 0x1F) + ide_status(); + if(count < KBD_BUF_SIZE) { count++; diff --git a/include/i8259.h b/include/i8259.h index 2959123..af6f0a0 100644 --- a/include/i8259.h +++ b/include/i8259.h @@ -31,7 +31,7 @@ #define PIC_CASCADE_IR 0x2 //The IR2 on Master Connect to Slave. -#define PIC_AEOI 1 +#define PIC_AEOI 0 extern void init_i8259(); extern void mask_i8259(); diff --git a/scripts/qemu b/scripts/qemu index 301d552..ed2d680 100644 --- a/scripts/qemu +++ b/scripts/qemu @@ -1 +1 @@ -qemu-system-i386 -device ahci,id=ahci -drive if=none,file=/root/kernel/HD.IMG,format=raw,id=sata -device ide-drive,drive=sata,bus=ahci.0 +qemu-system-i386 -device ich9-ahci,id=ahci -drive if=none,file=/root/kernel/HD.IMG,format=raw,id=sata -device ide-drive,drive=sata,bus=ahci.0