22 #include <linux/module.h>
23 #include <linux/types.h>
24 #include <linux/pci.h>
27 #include <linux/kernel.h>
35 #define DRV_NAME "SGIIOC4"
38 #define IOC4_CMD_OFFSET 0x100
39 #define IOC4_CTRL_OFFSET 0x120
40 #define IOC4_DMA_OFFSET 0x140
41 #define IOC4_INTR_OFFSET 0x0
43 #define IOC4_TIMING 0x00
44 #define IOC4_DMA_PTR_L 0x01
45 #define IOC4_DMA_PTR_H 0x02
46 #define IOC4_DMA_ADDR_L 0x03
47 #define IOC4_DMA_ADDR_H 0x04
48 #define IOC4_BC_DEV 0x05
49 #define IOC4_BC_MEM 0x06
50 #define IOC4_DMA_CTRL 0x07
51 #define IOC4_DMA_END_ADDR 0x08
54 #define IOC4_S_DMA_START 0x01
55 #define IOC4_S_DMA_STOP 0x02
56 #define IOC4_S_DMA_DIR 0x04
57 #define IOC4_S_DMA_ACTIVE 0x08
58 #define IOC4_S_DMA_ERROR 0x10
59 #define IOC4_ATA_MEMERR 0x02
62 #define IOC4_DMA_WRITE 0x04
63 #define IOC4_DMA_READ 0x00
66 #define IOC4_INTR_REG 0x03
67 #define IOC4_INTR_SET 0x05
68 #define IOC4_INTR_CLEAR 0x07
70 #define IOC4_IDE_CACHELINE_SIZE 128
71 #define IOC4_CMD_CTL_BLK_SIZE 0x20
72 #define IOC4_SUPPORTED_FIRMWARE_REV 46
88 #define IOC4_PRD_BYTES 16
89 #define IOC4_PRD_ENTRIES (PAGE_SIZE / (4 * IOC4_PRD_BYTES))
92 static void sgiioc4_init_hwif_ports(
struct ide_hw *
hw,
94 unsigned long ctrl_port,
95 unsigned long irq_port)
101 for (i = 0; i <= 7; i++)
129 if (intr_reg & 0x03) {
137 u8 stat = sgiioc4_read_status(hwif);
140 stat = sgiioc4_read_status(hwif);
141 while ((stat &
ATA_BUSY) && (count++ < 100)) {
143 stat = sgiioc4_read_status(hwif);
146 if (intr_reg & 0x02) {
149 u32 pci_err_addr_low, pci_err_addr_high,
159 "status-cmd reg is 0x%x\n",
160 __func__, drive->
name, pci_stat_cmd_reg);
162 __func__, drive->
name,
163 pci_err_addr_high, pci_err_addr_low);
165 pci_write_config_dword(dev,
PCI_COMMAND, 0x00000146);
207 unsigned long dma_base = hwif->
dma_base;
209 unsigned long *ending_dma = ide_get_hwifdata(hwif);
211 writel(IOC4_S_DMA_STOP, (
void __iomem *)(dma_base + IOC4_DMA_CTRL * 4));
213 ioc4_dma = sgiioc4_ide_dma_stop(hwif, dma_base);
215 if (ioc4_dma & IOC4_S_DMA_STOP) {
217 "%s(%s): IOC4 DMA STOP bit is still 1 :"
218 "ioc4_dma_reg 0x%x\n",
219 __func__, drive->
name, ioc4_dma);
228 while ((
cnt++ < 200) && (!valid)) {
229 for (num = 0; num < 16; num++) {
230 if (ending_dma[num]) {
246 if ((bc_dev & 0x01FF) || (bc_mem & 0x1FF)) {
247 if (bc_dev > bc_mem + 8) {
249 "%s(%s): WARNING!! byte_count_dev %d "
250 "!= byte_count_mem %d\n",
251 __func__, drive->
name, bc_dev, bc_mem);
263 static int sgiioc4_dma_test_irq(
ide_drive_t *drive)
265 return sgiioc4_checkirq(drive->
hwif);
268 static void sgiioc4_dma_host_set(
ide_drive_t *drive,
int on)
271 sgiioc4_clearirq(drive);
278 sgiioc4_dma_end(drive);
280 sgiioc4_clearirq(drive);
283 static void sgiioc4_dma_lost_irq(
ide_drive_t *drive)
285 sgiioc4_resetproc(drive);
295 if (!(reg & ATA_BUSY)) {
296 unsigned long other_ir = port - 0x110;
300 if (intr_reg & 0x03) {
322 "already in use\n", __func__, hwif->
name,
323 dma_base, dma_base + num_ports - 1);
336 goto dma_pci_alloc_failure;
341 ide_set_hwifdata(hwif, pad);
348 __func__, hwif->
name);
351 dma_pci_alloc_failure:
358 static void sgiioc4_configure_for_dma(
int dma_direction,
ide_drive_t *drive)
362 unsigned long dma_base = hwif->
dma_base;
363 unsigned long ioc4_dma_addr = dma_base + IOC4_DMA_CTRL * 4;
370 "transfer was still active\n", __func__, drive->
name);
372 ioc4_dma = sgiioc4_ide_dma_stop(hwif, dma_base);
374 if (ioc4_dma & IOC4_S_DMA_STOP)
376 "still 1\n", __func__, drive->
name);
382 "previous transfer, status 0x%x\n",
383 __func__, drive->
name, ioc4_dma);
385 ioc4_dma = sgiioc4_ide_dma_stop(hwif, dma_base);
387 if (ioc4_dma & IOC4_S_DMA_STOP)
389 "still 1\n", __func__, drive->
name);
419 unsigned int count = 0,
i = cmd->
sg_nents;
431 "%s: DMA table too small\n",
436 0x10000 - (cur_addr & 0xffff);
438 if (bcount > cur_len)
478 if (sgiioc4_build_dmatable(drive, cmd) == 0)
489 sgiioc4_configure_for_dma(ddir, drive);
494 static const struct ide_tp_ops sgiioc4_tp_ops = {
496 .read_status = sgiioc4_read_status,
509 .set_dma_mode = sgiioc4_set_dma_mode,
511 .resetproc = sgiioc4_resetproc,
514 static const struct ide_dma_ops sgiioc4_dma_ops = {
515 .dma_host_set = sgiioc4_dma_host_set,
516 .dma_setup = sgiioc4_dma_setup,
517 .dma_start = sgiioc4_dma_start,
518 .dma_end = sgiioc4_dma_end,
519 .dma_test_irq = sgiioc4_dma_test_irq,
520 .dma_lost_irq = sgiioc4_dma_lost_irq,
526 .init_dma = ide_dma_sgiioc4,
527 .tp_ops = &sgiioc4_tp_ops,
528 .port_ops = &sgiioc4_port_ops,
529 .dma_ops = &sgiioc4_dma_ops,
537 unsigned long cmd_base, irqport;
538 unsigned long bar0, cmd_phys_base,
ctl;
546 if (virt_base ==
NULL) {
559 "already in use\n",
DRV_NAME, pci_name(dev),
562 goto req_mem_rgn_err;
567 sgiioc4_init_hwif_ports(&
hw, cmd_base, ctl, irqport);
593 "firmware is obsolete - please upgrade to "
594 "revision46 or higher\n",
599 ret = sgiioc4_ide_setup_pci_device(dev);
613 return pci_init_sgiioc4(idd->
idd_pdev);
617 .is_name =
"IOC4_ide",
622 static int __init ioc4_ide_init(
void)