📄 ide-dma.c
字号:
* and then set up the DMA transfer registers for a device * that follows generic IDE PCI DMA behaviour. Controllers can * override this function if they need to * * Returns 0 on success. If a PIO fallback is required then 1 * is returned. */int ide_dma_setup(ide_drive_t *drive){ ide_hwif_t *hwif = drive->hwif; struct request *rq = HWGROUP(drive)->rq; unsigned int reading; u8 dma_stat; if (rq_data_dir(rq)) reading = 0; else reading = 1 << 3; /* fall back to pio! */ if (!ide_build_dmatable(drive, rq)) { ide_map_sg(drive, rq); return 1; } /* PRD table */ if (hwif->mmio) writel(hwif->dmatable_dma, (void __iomem *)hwif->dma_prdtable); else outl(hwif->dmatable_dma, hwif->dma_prdtable); /* specify r/w */ hwif->OUTB(reading, hwif->dma_command); /* read dma_status for INTR & ERROR flags */ dma_stat = hwif->INB(hwif->dma_status); /* clear INTR & ERROR flags */ hwif->OUTB(dma_stat|6, hwif->dma_status); drive->waiting_for_dma = 1; return 0;}EXPORT_SYMBOL_GPL(ide_dma_setup);static void ide_dma_exec_cmd(ide_drive_t *drive, u8 command){ /* issue cmd to drive */ ide_execute_command(drive, command, &ide_dma_intr, 2*WAIT_CMD, dma_timer_expiry);}void ide_dma_start(ide_drive_t *drive){ ide_hwif_t *hwif = HWIF(drive); u8 dma_cmd = hwif->INB(hwif->dma_command); /* Note that this is done *after* the cmd has * been issued to the drive, as per the BM-IDE spec. * The Promise Ultra33 doesn't work correctly when * we do this part before issuing the drive cmd. */ /* start DMA */ hwif->OUTB(dma_cmd|1, hwif->dma_command); hwif->dma = 1; wmb();}EXPORT_SYMBOL_GPL(ide_dma_start);/* returns 1 on error, 0 otherwise */int __ide_dma_end (ide_drive_t *drive){ ide_hwif_t *hwif = HWIF(drive); u8 dma_stat = 0, dma_cmd = 0; drive->waiting_for_dma = 0; /* get dma_command mode */ dma_cmd = hwif->INB(hwif->dma_command); /* stop DMA */ hwif->OUTB(dma_cmd&~1, hwif->dma_command); /* get DMA status */ dma_stat = hwif->INB(hwif->dma_status); /* clear the INTR & ERROR bits */ hwif->OUTB(dma_stat|6, hwif->dma_status); /* purge DMA mappings */ ide_destroy_dmatable(drive); /* verify good DMA status */ hwif->dma = 0; wmb(); return (dma_stat & 7) != 4 ? (0x10 | dma_stat) : 0;}EXPORT_SYMBOL(__ide_dma_end);/* returns 1 if dma irq issued, 0 otherwise */static int __ide_dma_test_irq(ide_drive_t *drive){ ide_hwif_t *hwif = HWIF(drive); u8 dma_stat = hwif->INB(hwif->dma_status); /* return 1 if INTR asserted */ if ((dma_stat & 4) == 4) return 1; if (!drive->waiting_for_dma) printk(KERN_WARNING "%s: (%s) called while not waiting\n", drive->name, __FUNCTION__); return 0;}#elsestatic inline int config_drive_for_dma(ide_drive_t *drive) { return 0; }#endif /* CONFIG_BLK_DEV_IDEDMA_PCI */int __ide_dma_bad_drive (ide_drive_t *drive){ struct hd_driveid *id = drive->id; int blacklist = ide_in_drive_list(id, drive_blacklist); if (blacklist) { printk(KERN_WARNING "%s: Disabling (U)DMA for %s (blacklisted)\n", drive->name, id->model); return blacklist; } return 0;}EXPORT_SYMBOL(__ide_dma_bad_drive);static const u8 xfer_mode_bases[] = { XFER_UDMA_0, XFER_MW_DMA_0, XFER_SW_DMA_0,};static unsigned int ide_get_mode_mask(ide_drive_t *drive, u8 base, u8 req_mode){ struct hd_driveid *id = drive->id; ide_hwif_t *hwif = drive->hwif; unsigned int mask = 0; switch(base) { case XFER_UDMA_0: if ((id->field_valid & 4) == 0) break; if (hwif->udma_filter) mask = hwif->udma_filter(drive); else mask = hwif->ultra_mask; mask &= id->dma_ultra; /* * avoid false cable warning from eighty_ninty_three() */ if (req_mode > XFER_UDMA_2) { if ((mask & 0x78) && (eighty_ninty_three(drive) == 0)) mask &= 0x07; } break; case XFER_MW_DMA_0: if ((id->field_valid & 2) == 0) break; if (hwif->mdma_filter) mask = hwif->mdma_filter(drive); else mask = hwif->mwdma_mask; mask &= id->dma_mword; break; case XFER_SW_DMA_0: if (id->field_valid & 2) { mask = id->dma_1word & hwif->swdma_mask; } else if (id->tDMA) { /* * ide_fix_driveid() doesn't convert ->tDMA to the * CPU endianness so we need to do it here */ u8 mode = le16_to_cpu(id->tDMA); /* * if the mode is valid convert it to the mask * (the maximum allowed mode is XFER_SW_DMA_2) */ if (mode <= 2) mask = ((2 << mode) - 1) & hwif->swdma_mask; } break; default: BUG(); break; } return mask;}/** * ide_find_dma_mode - compute DMA speed * @drive: IDE device * @req_mode: requested mode * * Checks the drive/host capabilities and finds the speed to use for * the DMA transfer. The speed is then limited by the requested mode. * * Returns 0 if the drive/host combination is incapable of DMA transfers * or if the requested mode is not a DMA mode. */u8 ide_find_dma_mode(ide_drive_t *drive, u8 req_mode){ ide_hwif_t *hwif = drive->hwif; unsigned int mask; int x, i; u8 mode = 0; if (drive->media != ide_disk) { if (hwif->host_flags & IDE_HFLAG_NO_ATAPI_DMA) return 0; } for (i = 0; i < ARRAY_SIZE(xfer_mode_bases); i++) { if (req_mode < xfer_mode_bases[i]) continue; mask = ide_get_mode_mask(drive, xfer_mode_bases[i], req_mode); x = fls(mask) - 1; if (x >= 0) { mode = xfer_mode_bases[i] + x; break; } } if (hwif->chipset == ide_acorn && mode == 0) { /* * is this correct? */ if (ide_dma_good_drive(drive) && drive->id->eide_dma_time < 150) mode = XFER_MW_DMA_1; } mode = min(mode, req_mode); printk(KERN_INFO "%s: %s mode selected\n", drive->name, mode ? ide_xfer_verbose(mode) : "no DMA"); return mode;}EXPORT_SYMBOL_GPL(ide_find_dma_mode);static int ide_tune_dma(ide_drive_t *drive){ u8 speed; if (noautodma || drive->nodma || (drive->id->capability & 1) == 0) return 0; /* consult the list of known "bad" drives */ if (__ide_dma_bad_drive(drive)) return 0; if (ide_id_dma_bug(drive)) return 0; if (drive->hwif->host_flags & IDE_HFLAG_TRUST_BIOS_FOR_DMA) return config_drive_for_dma(drive); speed = ide_max_dma_mode(drive); if (!speed) return 0; if (drive->hwif->host_flags & IDE_HFLAG_NO_SET_MODE) return 0; if (ide_set_dma_mode(drive, speed)) return 0; return 1;}static int ide_dma_check(ide_drive_t *drive){ ide_hwif_t *hwif = drive->hwif; int vdma = (hwif->host_flags & IDE_HFLAG_VDMA)? 1 : 0; if (!vdma && ide_tune_dma(drive)) return 0; /* TODO: always do PIO fallback */ if (hwif->host_flags & IDE_HFLAG_TRUST_BIOS_FOR_DMA) return -1; ide_set_max_pio(drive); return vdma ? 0 : -1;}int ide_id_dma_bug(ide_drive_t *drive){ struct hd_driveid *id = drive->id; if (id->field_valid & 4) { if ((id->dma_ultra >> 8) && (id->dma_mword >> 8)) goto err_out; } else if (id->field_valid & 2) { if ((id->dma_mword >> 8) && (id->dma_1word >> 8)) goto err_out; } return 0;err_out: printk(KERN_ERR "%s: bad DMA info in identify block\n", drive->name); return 1;}int ide_set_dma(ide_drive_t *drive){ ide_hwif_t *hwif = drive->hwif; int rc; rc = ide_dma_check(drive); switch(rc) { case -1: /* DMA needs to be disabled */ hwif->dma_off_quietly(drive); return -1; case 0: /* DMA needs to be enabled */ return hwif->ide_dma_on(drive); case 1: /* DMA setting cannot be changed */ break; default: BUG(); break; } return rc;}#ifdef CONFIG_BLK_DEV_IDEDMA_PCIvoid ide_dma_lost_irq (ide_drive_t *drive){ printk("%s: DMA interrupt recovery\n", drive->name);}EXPORT_SYMBOL(ide_dma_lost_irq);void ide_dma_timeout (ide_drive_t *drive){ ide_hwif_t *hwif = HWIF(drive); printk(KERN_ERR "%s: timeout waiting for DMA\n", drive->name); if (hwif->ide_dma_test_irq(drive)) return; hwif->ide_dma_end(drive);}EXPORT_SYMBOL(ide_dma_timeout);static void ide_release_dma_engine(ide_hwif_t *hwif){ if (hwif->dmatable_cpu) { pci_free_consistent(hwif->pci_dev, PRD_ENTRIES * PRD_BYTES, hwif->dmatable_cpu, hwif->dmatable_dma); hwif->dmatable_cpu = NULL; }}static int ide_release_iomio_dma(ide_hwif_t *hwif){ release_region(hwif->dma_base, 8); if (hwif->extra_ports) release_region(hwif->extra_base, hwif->extra_ports); return 1;}/* * Needed for allowing full modular support of ide-driver */int ide_release_dma(ide_hwif_t *hwif){ ide_release_dma_engine(hwif); if (hwif->mmio) return 1; else return ide_release_iomio_dma(hwif);}static int ide_allocate_dma_engine(ide_hwif_t *hwif){ hwif->dmatable_cpu = pci_alloc_consistent(hwif->pci_dev, PRD_ENTRIES * PRD_BYTES, &hwif->dmatable_dma); if (hwif->dmatable_cpu) return 0; printk(KERN_ERR "%s: -- Error, unable to allocate DMA table.\n", hwif->cds->name); return 1;}static int ide_mapped_mmio_dma(ide_hwif_t *hwif, unsigned long base, unsigned int ports){ printk(KERN_INFO " %s: MMIO-DMA ", hwif->name); return 0;}static int ide_iomio_dma(ide_hwif_t *hwif, unsigned long base, unsigned int ports){ printk(KERN_INFO " %s: BM-DMA at 0x%04lx-0x%04lx", hwif->name, base, base + ports - 1); if (!request_region(base, ports, hwif->name)) { printk(" -- Error, ports in use.\n"); return 1; } if (hwif->cds->extra) { hwif->extra_base = base + (hwif->channel ? 8 : 16); if (!hwif->mate || !hwif->mate->extra_ports) { if (!request_region(hwif->extra_base, hwif->cds->extra, hwif->cds->name)) { printk(" -- Error, extra ports in use.\n"); release_region(base, ports); return 1; } hwif->extra_ports = hwif->cds->extra; } } return 0;}static int ide_dma_iobase(ide_hwif_t *hwif, unsigned long base, unsigned int ports){ if (hwif->mmio) return ide_mapped_mmio_dma(hwif, base,ports); return ide_iomio_dma(hwif, base, ports);}void ide_setup_dma(ide_hwif_t *hwif, unsigned long base, unsigned num_ports){ if (ide_dma_iobase(hwif, base, num_ports)) return; if (ide_allocate_dma_engine(hwif)) { ide_release_dma(hwif); return; } hwif->dma_base = base; if (hwif->mate) hwif->dma_master = hwif->channel ? hwif->mate->dma_base : base; else hwif->dma_master = base; if (!(hwif->dma_command)) hwif->dma_command = hwif->dma_base; if (!(hwif->dma_vendor1)) hwif->dma_vendor1 = (hwif->dma_base + 1); if (!(hwif->dma_status)) hwif->dma_status = (hwif->dma_base + 2); if (!(hwif->dma_vendor3)) hwif->dma_vendor3 = (hwif->dma_base + 3); if (!(hwif->dma_prdtable)) hwif->dma_prdtable = (hwif->dma_base + 4); if (!hwif->dma_off_quietly) hwif->dma_off_quietly = &ide_dma_off_quietly; if (!hwif->dma_host_off) hwif->dma_host_off = &ide_dma_host_off; if (!hwif->ide_dma_on) hwif->ide_dma_on = &__ide_dma_on; if (!hwif->dma_host_on) hwif->dma_host_on = &ide_dma_host_on; if (!hwif->dma_setup) hwif->dma_setup = &ide_dma_setup; if (!hwif->dma_exec_cmd) hwif->dma_exec_cmd = &ide_dma_exec_cmd; if (!hwif->dma_start) hwif->dma_start = &ide_dma_start; if (!hwif->ide_dma_end) hwif->ide_dma_end = &__ide_dma_end; if (!hwif->ide_dma_test_irq) hwif->ide_dma_test_irq = &__ide_dma_test_irq; if (!hwif->dma_timeout) hwif->dma_timeout = &ide_dma_timeout; if (!hwif->dma_lost_irq) hwif->dma_lost_irq = &ide_dma_lost_irq; if (hwif->chipset != ide_trm290) { u8 dma_stat = hwif->INB(hwif->dma_status); printk(", BIOS settings: %s:%s, %s:%s", hwif->drives[0].name, (dma_stat & 0x20) ? "DMA" : "pio", hwif->drives[1].name, (dma_stat & 0x40) ? "DMA" : "pio"); } printk("\n"); BUG_ON(!hwif->dma_master);}EXPORT_SYMBOL_GPL(ide_setup_dma);#endif /* CONFIG_BLK_DEV_IDEDMA_PCI */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -