From: acevest Date: Fri, 10 May 2024 05:54:23 +0000 (+0800) Subject: IDE代码优化 X-Git-Url: http://zhaoyanbai.com/repos/%22http:/www.isc.org/icons/zlib_tech.html?a=commitdiff_plain;h=6df9a0e571cd66abf7ed738ec21dda0f941ca238;p=kernel.git IDE代码优化 --- diff --git a/drivers/ide.c b/drivers/ide.c index f7dab9e..091ae31 100644 --- a/drivers/ide.c +++ b/drivers/ide.c @@ -40,7 +40,13 @@ void ide_pci_init(pci_device_t *pci) { printd("PCI %03d:%02d.%d %02X #%02d %04X:%04X\n", pci->bus, pci->dev, pci->devfn, pci->progif, pci->intr_line, pci->vendor, pci->classcode); - uint32_t iobase = pci_read_config_long(pci_cmd(pci, PCI_BAR4)); + for (int i = 0; i < 6; i++) { + printd("ide pci BAR%u value 0x%08X\n", i, pci->bars[i]); + } + + // BAR4开始有16个端口,有2组,每组8个,分别控制Primary和Secondary通道的DMA + // BAR5: SATA AHCI Base Address + uint32_t iobase = pci->bars[4]; for (int i = 0; i < NR_IDE_CONTROLLER; i++) { INIT_MUTEX(&ide_pci_controller[i].request_mutex); @@ -55,6 +61,9 @@ void ide_pci_init(pci_device_t *pci) { iobase += i * 8; // secondary channel 需要加8 printd("ide pci Base IO Address Register %08x\n", iobase); + // 虽然iobase是uint32_t,但在PC机上最多有65536个端口,也就是有效位数为16bit + // 所以这里用0xFFFC或0xFFFFFFFC其实都可以 + iobase &= 0xFFFC; // 最低为0是内存地址为1是端口地址 ide_pci_controller[i].bus_iobase = iobase; ide_pci_controller[i].bus_cmd = iobase + PCI_IDE_CMD; @@ -62,13 +71,6 @@ void ide_pci_init(pci_device_t *pci) { ide_pci_controller[i].bus_prdt = iobase + PCI_IDE_PRDT; ide_pci_controller[i].prdt = (prdte_t *)alloc_one_page(0); - printd("BARS: "); - for (int j = 0; j < BARS_CNT; ++j) { - printd("%08x ", pci->bars[j]); - pci->bars[j] &= (~1UL); - } - printd("\n"); - ide_pci_controller[i].pci = pci; }