소스 검색

9.640u-irq: add new api 'set_irq': only need two arguments

rain 5 년 전
부모
커밋
76d5567123
8개의 변경된 파일과 44개의 추가작업 그리고 206개의 파일을 삭제
  1. 2 0
      LINES
  2. 4 0
      README.md
  3. 1 0
      include/kernel/int.h
  4. 14 0
      kernel/int.c
  5. 11 0
      kernel/irq.c
  6. 0 0
      lines
  7. 1 202
      modules/ahci.c
  8. 11 4
      modules/ide.c

+ 2 - 0
LINES

@@ -41,3 +41,5 @@
 2021-8-19 9.085: 9085 lines, 59 files, rain
 2021-8-21 9.389: 9389 lines, 59 files, rain
 2021-8-22 9.808: 9808 lines, 63 files, rain
+2021-8-23 9.640: 9640 lines, 63 files, rain
+

+ 4 - 0
README.md

@@ -165,3 +165,7 @@ source software, you can get its source code from <https://gitee.com/pengruiyang
 &nbsp;&nbsp;&nbsp;&nbsp;now ide driver is working, and we fixed a bug about the irq: 
 &nbsp;&nbsp;&nbsp;&nbsp;that the slave-irq's EOI not send. 
 
+9.640u-int:  
+&nbsp;&nbsp;&nbsp;&nbsp;now we use another mode to `register_irq`: a new api that `set_irq`. 
+&nbsp;&nbsp;&nbsp;&nbsp;`set_irq` just need 2 arguments, it's simplier, and faster. 
+

+ 1 - 0
include/kernel/int.h

@@ -75,6 +75,7 @@ void irq0x2e_interrupt(void);
 void irq0x2f_interrupt(void);
 
 void register_irq(int, void *, const void *);
+void set_irq(int, const void *);
 void unregister_irq(int);
 
 /* kernel/timer.S */

+ 14 - 0
kernel/int.c

@@ -97,6 +97,20 @@ int int_init(void) {
 
 	register_irq(0x00, irq0x20_interrupt, do_timer);
 	register_irq(0x01, irq0x21_interrupt, do_keyboard);
+	register_irq(0x02, irq0x22_interrupt, NULL);
+	register_irq(0x03, irq0x23_interrupt, NULL);
+	register_irq(0x04, irq0x24_interrupt, NULL);
+	register_irq(0x05, irq0x25_interrupt, NULL);
+	register_irq(0x06, irq0x26_interrupt, NULL);
+	register_irq(0x07, irq0x27_interrupt, NULL);
+	register_irq(0x08, irq0x28_interrupt, NULL);
+	register_irq(0x09, irq0x29_interrupt, NULL);
+	register_irq(0x0a, irq0x2a_interrupt, NULL);
+	register_irq(0x0b, irq0x2b_interrupt, NULL);
+	register_irq(0x0c, irq0x2c_interrupt, NULL);
+	register_irq(0x0d, irq0x2d_interrupt, NULL);
+	register_irq(0x0e, irq0x2e_interrupt, NULL);
+	register_irq(0x0f, irq0x2f_interrupt, NULL);
 
 	set_sys_gate(idt_table + 0x80, 1, &syscall);
 

+ 11 - 0
kernel/irq.c

@@ -57,6 +57,16 @@ build_irq(0x2f);
 
 struct irq_entry irq_table[MAX_IRQ_NR];
 
+void set_irq(int nr, const void *handler) {
+	schk_init();
+
+	irq_table[nr].handler = handler;
+
+	schk_leave();
+
+	return;
+}
+
 
 void register_irq(int nr, void *entry, const void *handler) {
 	schk_init();
@@ -88,6 +98,7 @@ void register_irq(int nr, void *entry, const void *handler) {
 	return;
 }
 
+
 void unregister_irq(int nr) {
 	schk_init();
 

+ 0 - 0
lines


+ 1 - 202
modules/ahci.c

@@ -40,71 +40,11 @@
 #include <lib/string.h>
 
 
-volatile struct ahci_hba_mem *hba;
-
 
 errno_t ahci_init(struct pci_header0 *hdr) {
 	schk_init();
 
-	register_irq(10, irq0x2a_interrupt, do_ahci_intr);
-	register_irq(14, irq0x2e_interrupt, do_ahci_intr);
-	register_irq(15, irq0x2f_interrupt, do_ahci_intr);
-
-	ahci_info("PCI BAR0: \t%q\n", hdr->bar0);
-	ahci_info("PCI BAR1: \t%q\n", hdr->bar1);
-	ahci_info("PCI BAR2: \t%q\n", hdr->bar2);
-	ahci_info("PCI BAR3: \t%q\n", hdr->bar3);
-	ahci_info("PCI BAR4: \t%q\n", hdr->bar4);
-	ahci_info("PCI BAR5: \t%q\n", hdr->bar5);
-
-	hba = (struct ahci_hba_mem *) mapping((void *) (__uint64_t) hdr->bar5, PATT_DEVMM);
-
-	ahci_info("AHCI HBA MEM maps to %q. \n", hba);
-
-	ahci_info("AHCI IRQ number: %b. \n", hdr->irqnr);
-	ahci_info("AHCI total ports: %d. \n", hba->cap & HBA_MEM_CAP_MASK);
-
-	if (hba->global_ctl & HBA_MEM_GHC_AHCI_ENABLE) 
-		ahci_info("AHCI is already in the AHCI mode. \n");
-
-	else 
-		ahci_info("AHCI is in the IDE mode. \n");
-
-	hba->global_ctl = 0x80000002;
-
-	ahci_info("AHCI BIOS-handoff: %d\n", hba->bios_handoff);
-
-	int i, nrdevs = 0;
-
-	for (i = 0; i <= (hba->cap & HBA_MEM_CAP_MASK); i++) {
-		/* if (bitmap_read(ports_impled, i) == 0) return; */
-		if (!(hba->ports_impled & (1 << i))) 
-			continue;
-
-		ahci_info("found ahci device %d on port %d. \n", nrdevs++, i);
-
-		volatile struct ahci_cmd_header *cmdlist = kmalloc(&devpool, 
-				sizeof(struct ahci_cmd_header));
-
-		memset(cmdlist, 0x00, sizeof(struct ahci_cmd_header));
-
-		/* well, that needs a physical address, I think... */
-		hba->ports[i].cmd_list = (__uint64_t) mm_vphy((void *) cmdlist);
-
-		volatile struct ahci_cmd_table *cmdtable = kmalloc(&devpool, 
-				sizeof(struct ahci_cmd_table));
-
-		memset(cmdtable, 0x00, sizeof(struct ahci_cmd_table));
-
-		cmdlist->cmd_table = (__uint64_t) mm_vphy((void *) cmdlist);
-
-	}
-
-	hba->ports[0].cmd = hba->ports[0].cmd | 0x10000003;
-	hba->ports[0].sata_ctl = 0x04;
-
-	ahci_info("SATA error: %x. \n", hba->ports[0].sata_error);
-	ahci_info("interrupt status: %x\n", hba->ports[0].int_status);
+	ahci_info("ahci initialized. \n");
 
 	schk_leave();
 
@@ -112,144 +52,3 @@ errno_t ahci_init(struct pci_header0 *hdr) {
 }
 
 
-static void wait_controller_ready(volatile struct ahci_hba_port *port) {
-	schk_init();
-
-	while (port->sata_status & ATASTAT_BUSY && !(port->sata_status & ATASTAT_ERR));
-
-	ahci_info("wait_controller_ready: controller is now ready. \n");
-
-	schk_leave();
-
-	return;
-}
-
-
-int ahci_rw_sect(volatile struct ahci_hba_port *port, int atacmd, char *buffer, __uint64_t lba) {
-	schk_init();
-
-	volatile char *devbuf = kmalloc(&devpool, 512);
-
-	wait_controller_ready(port);
-
-	if (atacmd == ATACMD_WR || atacmd == ATACMD_WR48) 
-		memcpy(devbuf, buffer, 512);
-
-	ahci_info("ahci_rw: rw port %q %d with buffer %q, command %d...\n", 
-			port, lba, buffer, atacmd);
-
-	port->sata_error = port->sata_error;
-
-	volatile struct ahci_cmd_header *cmdhdr = (struct ahci_cmd_header *) port->cmd_list;
-
-	ahci_info("ahci_rw: command list: %q. \n", mm_vphy((void *) cmdhdr));
-
-	memset(cmdhdr, 0x00, sizeof(struct ahci_cmd_header));
-
-	cmdhdr->config = 	(4 << CMDHDR_CFG_CFISLEN_SHIFT) | 
-				CMDHDR_CFG_CLEAR_R_OK | 
-				(0 << CMDHDR_CFG_PORTML_SHIFT) |
-				(1 << CMDHDR_CFG_PRDTLEN_SHIFT);
-
-	if (atacmd == ATACMD_WR || atacmd == ATACMD_WR48) 
-		cmdhdr->config |= CMDHDR_CFG_WRITE;
-
-	cmdhdr->transfered = 0;
-
-	volatile struct ahci_cmd_table *cmdtable = kmalloc(&devpool, sizeof(struct ahci_cmd_table));
-
-	ahci_info("ahci_rw: command table: %q. \n", mm_vphy((void *) cmdtable));
-
-	memset(cmdtable, 0x00, sizeof(struct ahci_cmd_table));
-
-	cmdhdr->cmd_table = (__uint64_t) mm_vphy((void *) cmdtable);
-
-	volatile struct fis_h2d *cmd_fis = kmalloc(&devpool, sizeof(struct fis_h2d));
-
-	ahci_info("ahci_rw: command fis: %q. \n", mm_vphy((void *) cmd_fis));
-
-	memset(cmd_fis, 0x00, sizeof(struct fis_h2d));
-
-	/* FIS_TYPE_H2D_FIS */
-	cmd_fis->fis_type = 0x27;
-	cmd_fis->config = 0 | FISH2D_CMD;
-	cmd_fis->command = atacmd;
-
-	cmd_fis->lba0 = lba & 0xff;
-	cmd_fis->lba1 = (lba >> 8) & 0xff;
-	cmd_fis->lba2 = (lba >> 16) & 0xff;
-
-	cmd_fis->lba3 = (lba >> 24) & 0xff;
-	cmd_fis->lba4 = (lba >> 32) & 0xff;
-	cmd_fis->lba5 = (lba >> 40) & 0xff;
-
-	cmd_fis->dev = 0xe0;
-	cmd_fis->nsectors = 1;
-
-	memcpy(cmdtable->cmd_fis, cmd_fis, sizeof(struct fis_h2d));
-	cmdtable->prdts[0].buf = (__uint64_t) mm_vphy((void *) devbuf);
-	cmdtable->prdts[0].size = 511u | PRDT_SIZE_INTR;
-
-	port->int_enable = 0xffffffff;
-	port->int_status = 0xffffffff;
-	port->cmd_issue = 1;
-	port->sata_active = 1;
-
-	/* interrupt enable */
-	port->sata_ctl = 0x00;
-
-	/* wait it complete */
-
-	ahci_info("waiting device complete...\n");
-
-	ahci_info("sata error: %q. \n", port->sata_error);
-	ahci_info("sata status: %q. \n", port->sata_status);
-
-	for (;;) {
-		/* task file error */
-		if (port->cmd_issue & (1 << 30)) {
-			ahci_info("ahci_rw_sect: controller error. \n");
-			goto panic;
-		}
-
-		if (!(port->cmd_issue & 1)) 
-			/* complete */
-			break;
-	}
-
-	if (port->sata_status & ATASTAT_ERR) {
-		ahci_info("ahci_rw_sect: controller error. \n");
-
-		ahci_info("sata error: %q\n", port->sata_status);
-
-		goto panic;
-	}
-
-	int i;
-
-	for (i = 0; i < 512 / 8; i++) 
-		printk(yellow, "%x", devbuf[i]);
-
-
-	ahci_info("\nAHCI request completed. \n");
-	port->cmd &= ~1;
-
-	if (atacmd == ATACMD_RD || atacmd == ATACMD_RD48) 
-		memcpy(buffer, devbuf, 512);
-
-panic:
-	kfree(&devpool, (void *) cmd_fis, sizeof(struct fis_h2d));
-	kfree(&devpool, (void *) cmdtable, sizeof(struct ahci_cmd_table));
-	kfree(&devpool, (void *) devbuf, 512);
-
-	schk_leave();
-
-	return 0;
-}
-
-
-void do_ahci_intr(void) {
-	ahci_info("AHCI interrupt. \n");
-
-	return;
-}

+ 11 - 4
modules/ide.c

@@ -103,8 +103,8 @@ errno_t ide_init(struct pci_header0 *hdr) {
 	ide_info("hda port: %w  hda control port: %w\n", hd0_base, hd0_ctl);
 	ide_info("hdb port: %w  hdb control port: %w\n", hd1_base, hd1_ctl);
 
-	register_irq(0x0e, irq0x2e_interrupt, do_ide_intr);
-	register_irq(0x0f, irq0x2f_interrupt, do_ide_intr);
+	set_irq(0x0e, do_ide_intr);
+	set_irq(0x0f, do_ide_intr);
 
 	ide_intr = do_ide_id;
 	intr_dev = HD0;
@@ -144,9 +144,14 @@ errno_t ide_init(struct pci_header0 *hdr) {
 
 	ide_info("ide_init: id completed. \n");
 
-	memset(buffer, 0x12, 512);
+	ide_cmdout(HD0, BLKREAD, buffer, 1, 0x00000000);
 
-	ide_cmdout(HD0, BLKWRITE, buffer, 1, 0x00000000);
+	while (ide_intr) hlt();
+
+	int i;
+
+	for (i = 0; i < 512; i++) 
+		printk(white, "%b", buffer[i]);
 
 	schk_leave();
 
@@ -198,6 +203,7 @@ void do_ide_write(void) {
 }
 
 
+
 int ide_cmdout(int dev, int cmd, char *buffer, int nsect, __uint64_t lba) {
 	if (nsect > 255) 
 		panic("ide_cmdout: bad nsect. ");
@@ -233,3 +239,4 @@ int ide_cmdout(int dev, int cmd, char *buffer, int nsect, __uint64_t lba) {
 	return 0;
 }
 
+