]> Zhao Yanbai Git Server - kernel.git/commitdiff
clean ide code
authorAceVest <zhaoyanbai@126.com>
Sun, 6 Jul 2014 16:20:29 +0000 (00:20 +0800)
committerAceVest <zhaoyanbai@126.com>
Sun, 6 Jul 2014 16:20:29 +0000 (00:20 +0800)
drivers/ide.c
drivers/vga.c
kernel/printk.c
kernel/wait.c

index dbbd68532cf38475c6082b8211a746da90e19ce2..a9a25869bafcd0c240bb8b6639840a9fe9f4e741 100644 (file)
 #include <wait.h>
 #include <string.h>
 
-DECLARE_MUTEX(mutex);
-void ide_cmd_out(dev_t dev, u32 sect_cnt, u64 sect_nr, u32 cmd);
-
-unsigned int HD_CHL0_CMD_BASE = 0x1F0;
-unsigned int HD_CHL1_CMD_BASE = 0x170;
-
-unsigned int HD_CHL0_CTL_BASE = 0x3F6;
-unsigned int HD_CHL1_CTL_BASE = 0x376;
-
 typedef struct _ide_drv
 {
     pci_device_t *pci;
@@ -48,8 +39,6 @@ typedef struct _ide_drv
     part_t  part[MAX_SUPPORT_PARTITION_CNT];
 } ide_drive_t;
 
-ide_drive_t drv;
-
 typedef struct prd
 {
     unsigned int addr;
@@ -66,8 +55,52 @@ typedef struct {
     wait_queue_head_t wait;
 } ide_request_t;
 
+typedef void (*ide_intr_func_t)();
+
+void ide_default_intr();
+
+ide_drive_t drv;
+DECLARE_MUTEX(mutex);
 ide_request_t ide_request;
 
+ide_intr_func_t ide_intr_func = ide_default_intr;
+
+unsigned char *dma_data = 0;
+
+unsigned int HD_CHL0_CMD_BASE = 0x1F0;
+unsigned int HD_CHL1_CMD_BASE = 0x170;
+
+unsigned int HD_CHL0_CTL_BASE = 0x3F6;
+unsigned int HD_CHL1_CTL_BASE = 0x376;
+
+void ide_printd()
+{
+    printd(MPL_IDE, "ide pio_cnt %d dma_cnt %d irq_cnt %d", drv.pio_cnt,  drv.dma_cnt, drv.irq_cnt);
+}
+
+void ide_cmd_out(dev_t dev, u32 sect_cnt, u64 sect_nr, u32 cmd)
+{
+    drv.pio_cnt++;
+    drv.read_mode = cmd;
+
+    ide_printd();
+
+    outb(0x00,                      REG_CTL(dev));
+    outb(0x40|0x00,                 REG_DEVSEL(dev));
+
+    outb((u8)((sect_cnt>>8)&0xFF),  REG_NSECTOR(dev));    // High
+    outb((u8)((sect_nr>>24)&0xFF),  REG_LBAL(dev));
+    outb((u8)((sect_nr>>32)&0xFF),  REG_LBAM(dev));
+    outb((u8)((sect_nr>>40)&0xFF),  REG_LBAH(dev));
+
+    outb((u8)((sect_cnt>>0)&0xFF),  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(cmd,                       REG_CMD(dev));
+}
+
 void ide_do_read(u64_t lba, u32_t scnt, char *buf)
 {
     bool finish = false;
@@ -109,12 +142,9 @@ void ide_do_read(u64_t lba, u32_t scnt, char *buf)
     del_wait_queue(&r->wait, &wait);
 }
 
-unsigned char *data = 0;
 
 unsigned int sys_clock();
 
-bool ide_init_inted = false;
-
 void ide_pci_init(pci_device_t *pci)
 {
     unsigned int v;
@@ -154,57 +184,6 @@ void ide_pci_init(pci_device_t *pci)
 }
 
 
-void ide_printd()
-{
-    printd(MPL_IDE, "ide pio_cnt %d dma_cnt %d irq_cnt %d", drv.pio_cnt,  drv.dma_cnt, drv.irq_cnt);
-}
-
-void ide_cmd_out(dev_t dev, u32 sect_cnt, u64 sect_nr, u32 cmd)
-{
-    ide_init_inted = false;
-
-    drv.pio_cnt++;
-    drv.read_mode = cmd;
-
-    ide_printd();
-
-    outb(0x00,                      REG_CTL(dev));
-    outb(0x40|0x00,                 REG_DEVSEL(dev));
-
-    outb((u8)((sect_cnt>>8)&0xFF),  REG_NSECTOR(dev));    // High
-    outb((u8)((sect_nr>>24)&0xFF),  REG_LBAL(dev));
-    outb((u8)((sect_nr>>32)&0xFF),  REG_LBAM(dev));
-    outb((u8)((sect_nr>>40)&0xFF),  REG_LBAH(dev));
-
-    outb((u8)((sect_cnt>>0)&0xFF),  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(cmd,                       REG_CMD(dev));
-}
-
-void ide_wait_ready()
-{
-    u32 retires = 100;
-    
-    do
-    {
-        int drq_retires = 100000;
-        while(!hd_drq(dev) && --drq_retires)
-            /* do nothing */;
-
-        if(drq_retires != 0)
-            break;
-    }while(--retires);
-
-    if(retires == 0)
-        panic("hard disk is not ready");
-}
-
-
-void dump_pci_ide();
-
 void ide_status()
 {
     u8_t idest = inb(REG_STATUS(0));
@@ -212,13 +191,12 @@ void ide_status()
     printk(" ide status %02x pci status %02x\n", idest, pcist);
 }
 
-
 void ide_debug()
 {
     u32    device;
     u32    nsect = 1;
     u32    retires = 100;
-    u32    sect_nr = 0;
+    u64    sect_nr = 0;
     int count=SECT_SIZE;
 
     nsect    = (count + SECT_SIZE -1)/SECT_SIZE;
@@ -260,11 +238,12 @@ void ide_default_intr()
     if(drv.read_mode == HD_CMD_READ_EXT)
     {
         insl(REG_DATA(0), ide_request.buf, ((ide_request.scnt*SECT_SIZE)>>2));
+        sig = *((u16_t *) (ide_request.buf+510));
     }
 
     if(drv.read_mode == HD_CMD_READ_DMA)
     {
-        sig = *((u16_t *) (data+510));
+        sig = *((u16_t *) (dma_data+510));
     }
 
     ide_printd();
@@ -280,8 +259,6 @@ void ide_default_intr()
     up(&mutex);
 }
 
-typedef void (*ide_intr_func_t)();
-ide_intr_func_t ide_intr_func = ide_default_intr;
 
 void ide_irq()
 {
@@ -300,14 +277,13 @@ unsigned long gprdt = 0;
 
 void ide_dma_pci_lba48()
 {
-    ide_init_inted = false;
     drv.dma_cnt ++;
     drv.read_mode = HD_CMD_READ_DMA;
 #if 1
     memset((void *)&prd, 0, sizeof(prd));
     unsigned long addr = alloc_one_page(0);
-    data = (char *) addr;
-    memset(data, 0xBB, 512);
+    dma_data = (char *) addr;
+    memset(dma_data, 0xBB, 512);
     prd.addr = va2pa(addr);
     prd.cnt  = 512;
     prd.eot  = 1;
index 6f422cd1a9a233e328a39ce1b7d085f1d8dc6f03..51c52c0015c528dc312f63fcb1c176eeeec128b8 100644 (file)
@@ -187,20 +187,6 @@ void __vga_switch(unsigned int offset)
     outb((offset)&0xFF,         VGA_CRTC_DATA);
 }
 
-int bvga = 0;
-void vga_init()
-{
-    unsigned int i;
-    for(i=1; i<VGA_MAX_SCREEN_CNT; ++i)
-    {
-        memset(vga_screen + i, 0, sizeof(vga_screen_t));
-        vga_screen[i].id    = i;
-        vga_screen[i].base  = (vga_char_t *) (VIDEO_ADDR + i*MAX_LINES_PER_SCREEN*BYTES_PER_LINE);
-        memset(vga_screen[i].base, 0, MAX_LINES_PER_SCREEN*BYTES_PER_LINE);
-    }
-    bvga = 1;
-}
-
 void vga_switch(unsigned int nr)
 {
     if(nr >= VGA_MAX_SCREEN_CNT)
@@ -231,19 +217,46 @@ void vga_dbg_toggle()
     __vga_switch(offset);
 }
 
+unsigned char vga_dbg_color = 0x1F;
+
+void vga_dbg_clear()
+{
+    int i;
+    int line;
+    for(line=0; line<MAX_LINES_PER_SCREEN; ++line)
+    {
+        vga_char_t * const pv = (vga_char_t * const) (VIDEO_ADDR + (VIDEO_DBG_LINE + line) * BYTES_PER_LINE);
+        for(i=0; i<CHARS_PER_LINE; ++i)
+            pv[i] = vga_char(0, vga_dbg_color);
+    }
+}
 
-void vga_dbg_puts(unsigned int line, const char *buf, unsigned char color)
+void vga_dbg_puts(unsigned int line, const char *buf)
 {
     int i;
     char *p = (char *) buf;
     vga_char_t * const pv = (vga_char_t * const) (VIDEO_ADDR + (VIDEO_DBG_LINE + line) * BYTES_PER_LINE);
 
     for(i=0; i<CHARS_PER_LINE; ++i)
-        pv[i] = vga_char(0, color);
+        pv[i] = vga_char(0, vga_dbg_color);
 
     for(i=0; *p; ++i, ++p)
     {
-        color = 0x1F;
-        pv[i] = vga_char(*p, color);
+        pv[i] = vga_char(*p, vga_dbg_color);
+    }
+}
+
+void vga_init()
+{
+    unsigned int i;
+    for(i=1; i<VGA_MAX_SCREEN_CNT; ++i)
+    {
+        memset(vga_screen + i, 0, sizeof(vga_screen_t));
+        vga_screen[i].id    = i;
+        vga_screen[i].base  = (vga_char_t *) (VIDEO_ADDR + i*MAX_LINES_PER_SCREEN*BYTES_PER_LINE);
+        memset(vga_screen[i].base, 0, MAX_LINES_PER_SCREEN*BYTES_PER_LINE);
     }
+
+    vga_dbg_clear();   
 }
+
index 3830e237993ac2c4ed0f244f7a720f9c9c1f5759..7e9e5c6bbc0c278ed1730bfc9802214d0021f5dd 100644 (file)
@@ -36,12 +36,14 @@ int printk(const char *fmtstr, ...)
     return 0;
 }
 
-char plbuf[1024];
+//char plbuf[1024];
 int printl(const char *fmtstr, ...)
 {
+    char *plbuf = (char *)kmalloc(1024, 0);
     char *args = (char*)(((char*)&fmtstr)+4);
     vsprintf(pkbuf, fmtstr, args);
     vga_puts(3, pkbuf, 0x4);
+    kfree(plbuf);
     return 0;
 }
 
index 66daa6cef928f466ca237e99ce447976b7a68694..92f15a9182941191058f1071c9f534dfe2f5eef7 100644 (file)
@@ -59,7 +59,7 @@ int debug_wait_queue_get()
 
     while(1)
     {
-        printk("pid %d is going to wait\n", sysc_getpid());
+        printl("pid %d is going to wait\n", sysc_getpid());
         task->state = TASK_WAIT;
 
         disable_irq();
@@ -72,10 +72,10 @@ int debug_wait_queue_get()
             break;
 
         schedule();
-        printk("pid %d is running\n", sysc_getpid());
+        printl("pid %d is running\n", sysc_getpid());
     }
 
-    printk("pid %d is really running\n", sysc_getpid());
+    printl("pid %d is really running\n", sysc_getpid());
     task->state = TASK_RUNNING;
     del_wait_queue(&debug_wq, &wait);