scc_pata.c
来自「linux 内核源代码」· C语言 代码 · 共 788 行 · 第 1/2 页
C
788 行
continue; } if (reg & INTSTS_RERR) { printk(KERN_WARNING "%s: Response Error\n", SCC_PATA_NAME); out_be32((void __iomem *)intsts_port, INTSTS_RERR|INTSTS_BMSINT); out_be32((void __iomem *)hwif->dma_command, in_be32((void __iomem *)hwif->dma_command) & ~QCHCD_IOS_SS); continue; } if (reg & INTSTS_ICERR) { out_be32((void __iomem *)hwif->dma_command, in_be32((void __iomem *)hwif->dma_command) & ~QCHCD_IOS_SS); printk(KERN_WARNING "%s: Illegal Configuration\n", SCC_PATA_NAME); out_be32((void __iomem *)intsts_port, INTSTS_ICERR|INTSTS_BMSINT); continue; } if (reg & INTSTS_BMSINT) { printk(KERN_WARNING "%s: Internal Bus Error\n", SCC_PATA_NAME); out_be32((void __iomem *)intsts_port, INTSTS_BMSINT); ide_do_reset(drive); continue; } if (reg & INTSTS_BMHE) { out_be32((void __iomem *)intsts_port, INTSTS_BMHE); continue; } if (reg & INTSTS_ACTEINT) { out_be32((void __iomem *)intsts_port, INTSTS_ACTEINT); continue; } if (reg & INTSTS_IOIRQS) { out_be32((void __iomem *)intsts_port, INTSTS_IOIRQS); continue; } break; } dma_stat = __ide_dma_end(drive); if (data_loss) dma_stat |= 2; /* emulate DMA error (to retry command) */ return dma_stat;}/* returns 1 if dma irq issued, 0 otherwise */static int scc_dma_test_irq(ide_drive_t *drive){ ide_hwif_t *hwif = HWIF(drive); u32 int_stat = in_be32((void __iomem *)hwif->dma_base + 0x014); /* SCC errata A252,A308 workaround: Step4 */ if ((in_be32((void __iomem *)IDE_ALTSTATUS_REG) & ERR_STAT) && (int_stat & INTSTS_INTRQ)) return 1; /* SCC errata A308 workaround: Step5 (polling IOIRQS) */ if (int_stat & INTSTS_IOIRQS) return 1; if (!drive->waiting_for_dma) printk(KERN_WARNING "%s: (%s) called while not waiting\n", drive->name, __FUNCTION__); return 0;}static u8 scc_udma_filter(ide_drive_t *drive){ ide_hwif_t *hwif = drive->hwif; u8 mask = hwif->ultra_mask; /* errata A308 workaround: limit non ide_disk drive to UDMA4 */ if ((drive->media != ide_disk) && (mask & 0xE0)) { printk(KERN_INFO "%s: limit %s to UDMA4\n", SCC_PATA_NAME, drive->name); mask = ATA_UDMA4; } return mask;}/** * setup_mmio_scc - map CTRL/BMID region * @dev: PCI device we are configuring * @name: device name * */static int setup_mmio_scc (struct pci_dev *dev, const char *name){ unsigned long ctl_base = pci_resource_start(dev, 0); unsigned long dma_base = pci_resource_start(dev, 1); unsigned long ctl_size = pci_resource_len(dev, 0); unsigned long dma_size = pci_resource_len(dev, 1); void __iomem *ctl_addr; void __iomem *dma_addr; int i; for (i = 0; i < MAX_HWIFS; i++) { if (scc_ports[i].ctl == 0) break; } if (i >= MAX_HWIFS) return -ENOMEM; if (!request_mem_region(ctl_base, ctl_size, name)) { printk(KERN_WARNING "%s: IDE controller MMIO ports not available.\n", SCC_PATA_NAME); goto fail_0; } if (!request_mem_region(dma_base, dma_size, name)) { printk(KERN_WARNING "%s: IDE controller MMIO ports not available.\n", SCC_PATA_NAME); goto fail_1; } if ((ctl_addr = ioremap(ctl_base, ctl_size)) == NULL) goto fail_2; if ((dma_addr = ioremap(dma_base, dma_size)) == NULL) goto fail_3; pci_set_master(dev); scc_ports[i].ctl = (unsigned long)ctl_addr; scc_ports[i].dma = (unsigned long)dma_addr; pci_set_drvdata(dev, (void *) &scc_ports[i]); return 1; fail_3: iounmap(ctl_addr); fail_2: release_mem_region(dma_base, dma_size); fail_1: release_mem_region(ctl_base, ctl_size); fail_0: return -ENOMEM;}/** * init_setup_scc - set up an SCC PATA Controller * @dev: PCI device * @d: IDE port info * * Perform the initial set up for this device. */static int __devinit init_setup_scc(struct pci_dev *dev, const struct ide_port_info *d){ unsigned long ctl_base; unsigned long dma_base; unsigned long cckctrl_port; unsigned long intmask_port; unsigned long mode_port; unsigned long ecmode_port; unsigned long dma_status_port; u32 reg = 0; struct scc_ports *ports; int rc; rc = setup_mmio_scc(dev, d->name); if (rc < 0) { return rc; } ports = pci_get_drvdata(dev); ctl_base = ports->ctl; dma_base = ports->dma; cckctrl_port = ctl_base + 0xff0; intmask_port = dma_base + 0x010; mode_port = ctl_base + 0x024; ecmode_port = ctl_base + 0xf00; dma_status_port = dma_base + 0x004; /* controller initialization */ reg = 0; out_be32((void*)cckctrl_port, reg); reg |= CCKCTRL_ATACLKOEN; out_be32((void*)cckctrl_port, reg); reg |= CCKCTRL_LCLKEN | CCKCTRL_OCLKEN; out_be32((void*)cckctrl_port, reg); reg |= CCKCTRL_CRST; out_be32((void*)cckctrl_port, reg); for (;;) { reg = in_be32((void*)cckctrl_port); if (reg & CCKCTRL_CRST) break; udelay(5000); } reg |= CCKCTRL_ATARESET; out_be32((void*)cckctrl_port, reg); out_be32((void*)ecmode_port, ECMODE_VALUE); out_be32((void*)mode_port, MODE_JCUSFEN); out_be32((void*)intmask_port, INTMASK_MSK); return ide_setup_pci_device(dev, d);}/** * init_mmio_iops_scc - set up the iops for MMIO * @hwif: interface to set up * */static void __devinit init_mmio_iops_scc(ide_hwif_t *hwif){ struct pci_dev *dev = hwif->pci_dev; struct scc_ports *ports = pci_get_drvdata(dev); unsigned long dma_base = ports->dma; ide_set_hwifdata(hwif, ports); hwif->INB = scc_ide_inb; hwif->INW = scc_ide_inw; hwif->INSW = scc_ide_insw; hwif->INSL = scc_ide_insl; hwif->OUTB = scc_ide_outb; hwif->OUTBSYNC = scc_ide_outbsync; hwif->OUTW = scc_ide_outw; hwif->OUTSW = scc_ide_outsw; hwif->OUTSL = scc_ide_outsl; hwif->io_ports[IDE_DATA_OFFSET] = dma_base + 0x20; hwif->io_ports[IDE_ERROR_OFFSET] = dma_base + 0x24; hwif->io_ports[IDE_NSECTOR_OFFSET] = dma_base + 0x28; hwif->io_ports[IDE_SECTOR_OFFSET] = dma_base + 0x2c; hwif->io_ports[IDE_LCYL_OFFSET] = dma_base + 0x30; hwif->io_ports[IDE_HCYL_OFFSET] = dma_base + 0x34; hwif->io_ports[IDE_SELECT_OFFSET] = dma_base + 0x38; hwif->io_ports[IDE_STATUS_OFFSET] = dma_base + 0x3c; hwif->io_ports[IDE_CONTROL_OFFSET] = dma_base + 0x40; hwif->irq = hwif->pci_dev->irq; hwif->dma_base = dma_base; hwif->config_data = ports->ctl; hwif->mmio = 1;}/** * init_iops_scc - set up iops * @hwif: interface to set up * * Do the basic setup for the SCC hardware interface * and then do the MMIO setup. */static void __devinit init_iops_scc(ide_hwif_t *hwif){ struct pci_dev *dev = hwif->pci_dev; hwif->hwif_data = NULL; if (pci_get_drvdata(dev) == NULL) return; init_mmio_iops_scc(hwif);}/** * init_hwif_scc - set up hwif * @hwif: interface to set up * * We do the basic set up of the interface structure. The SCC * requires several custom handlers so we override the default * ide DMA handlers appropriately. */static void __devinit init_hwif_scc(ide_hwif_t *hwif){ struct scc_ports *ports = ide_get_hwifdata(hwif); ports->hwif_id = hwif->index; hwif->dma_command = hwif->dma_base; hwif->dma_status = hwif->dma_base + 0x04; hwif->dma_prdtable = hwif->dma_base + 0x08; /* PTERADD */ out_be32((void __iomem *)(hwif->dma_base + 0x018), hwif->dmatable_dma); hwif->dma_setup = scc_dma_setup; hwif->ide_dma_end = scc_ide_dma_end; hwif->set_pio_mode = scc_set_pio_mode; hwif->set_dma_mode = scc_set_dma_mode; hwif->ide_dma_test_irq = scc_dma_test_irq; hwif->udma_filter = scc_udma_filter; if (in_be32((void __iomem *)(hwif->config_data + 0xff0)) & CCKCTRL_ATACLKOEN) hwif->ultra_mask = ATA_UDMA6; /* 133MHz */ else hwif->ultra_mask = ATA_UDMA5; /* 100MHz */ /* we support 80c cable only. */ hwif->cbl = ATA_CBL_PATA80;}#define DECLARE_SCC_DEV(name_str) \ { \ .name = name_str, \ .init_iops = init_iops_scc, \ .init_hwif = init_hwif_scc, \ .host_flags = IDE_HFLAG_SINGLE | \ IDE_HFLAG_BOOTABLE, \ .pio_mask = ATA_PIO4, \ }static const struct ide_port_info scc_chipsets[] __devinitdata = { /* 0 */ DECLARE_SCC_DEV("sccIDE"),};/** * scc_init_one - pci layer discovery entry * @dev: PCI device * @id: ident table entry * * Called by the PCI code when it finds an SCC PATA controller. * We then use the IDE PCI generic helper to do most of the work. */static int __devinit scc_init_one(struct pci_dev *dev, const struct pci_device_id *id){ return init_setup_scc(dev, &scc_chipsets[id->driver_data]);}/** * scc_remove - pci layer remove entry * @dev: PCI device * * Called by the PCI code when it removes an SCC PATA controller. */static void __devexit scc_remove(struct pci_dev *dev){ struct scc_ports *ports = pci_get_drvdata(dev); ide_hwif_t *hwif = &ide_hwifs[ports->hwif_id]; unsigned long ctl_base = pci_resource_start(dev, 0); unsigned long dma_base = pci_resource_start(dev, 1); unsigned long ctl_size = pci_resource_len(dev, 0); unsigned long dma_size = pci_resource_len(dev, 1); if (hwif->dmatable_cpu) { pci_free_consistent(hwif->pci_dev, PRD_ENTRIES * PRD_BYTES, hwif->dmatable_cpu, hwif->dmatable_dma); hwif->dmatable_cpu = NULL; } ide_unregister(hwif->index); hwif->chipset = ide_unknown; iounmap((void*)ports->dma); iounmap((void*)ports->ctl); release_mem_region(dma_base, dma_size); release_mem_region(ctl_base, ctl_size); memset(ports, 0, sizeof(*ports));}static const struct pci_device_id scc_pci_tbl[] = { { PCI_VDEVICE(TOSHIBA_2, PCI_DEVICE_ID_TOSHIBA_SCC_ATA), 0 }, { 0, },};MODULE_DEVICE_TABLE(pci, scc_pci_tbl);static struct pci_driver driver = { .name = "SCC IDE", .id_table = scc_pci_tbl, .probe = scc_init_one, .remove = scc_remove,};static int scc_ide_init(void){ return ide_pci_register_driver(&driver);}module_init(scc_ide_init);/* -- No exit code?static void scc_ide_exit(void){ ide_pci_unregister_driver(&driver);}module_exit(scc_ide_exit); */MODULE_DESCRIPTION("PCI driver module for Toshiba SCC IDE");MODULE_LICENSE("GPL");
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?