📄 icside.c
字号:
/* * linux/drivers/ide/arm/icside.c * * Copyright (c) 1996-2003 Russell King. * * Changelog: * 08-Jun-1996 RMK Created * 12-Sep-1997 RMK Added interrupt enable/disable * 17-Apr-1999 RMK Added support for V6 EASI * 22-May-1999 RMK Added support for V6 DMA */#include <linux/config.h>#include <linux/string.h>#include <linux/module.h>#include <linux/ioport.h>#include <linux/slab.h>#include <linux/blkdev.h>#include <linux/errno.h>#include <linux/hdreg.h>#include <linux/ide.h>#include <linux/pci.h>#include <linux/init.h>#include <asm/dma.h>#include <asm/ecard.h>#include <asm/io.h>#define ICS_IDENT_OFFSET 0x8a0#define ICS_ARCIN_V5_INTRSTAT 0x000#define ICS_ARCIN_V5_INTROFFSET 0x001#define ICS_ARCIN_V5_IDEOFFSET 0xa00#define ICS_ARCIN_V5_IDEALTOFFSET 0xae0#define ICS_ARCIN_V5_IDESTEPPING 4#define ICS_ARCIN_V6_IDEOFFSET_1 0x800#define ICS_ARCIN_V6_INTROFFSET_1 0x880#define ICS_ARCIN_V6_INTRSTAT_1 0x8a4#define ICS_ARCIN_V6_IDEALTOFFSET_1 0x8e0#define ICS_ARCIN_V6_IDEOFFSET_2 0xc00#define ICS_ARCIN_V6_INTROFFSET_2 0xc80#define ICS_ARCIN_V6_INTRSTAT_2 0xca4#define ICS_ARCIN_V6_IDEALTOFFSET_2 0xce0#define ICS_ARCIN_V6_IDESTEPPING 4struct cardinfo { unsigned int dataoffset; unsigned int ctrloffset; unsigned int stepping;};static struct cardinfo icside_cardinfo_v5 = { ICS_ARCIN_V5_IDEOFFSET, ICS_ARCIN_V5_IDEALTOFFSET, ICS_ARCIN_V5_IDESTEPPING};static struct cardinfo icside_cardinfo_v6_1 = { ICS_ARCIN_V6_IDEOFFSET_1, ICS_ARCIN_V6_IDEALTOFFSET_1, ICS_ARCIN_V6_IDESTEPPING};static struct cardinfo icside_cardinfo_v6_2 = { ICS_ARCIN_V6_IDEOFFSET_2, ICS_ARCIN_V6_IDEALTOFFSET_2, ICS_ARCIN_V6_IDESTEPPING};struct icside_state { unsigned int channel; unsigned int enabled; unsigned long irq_port; unsigned long slot_port; unsigned int type; ide_hwif_t *hwif[2];};#define ICS_TYPE_A3IN 0#define ICS_TYPE_A3USER 1#define ICS_TYPE_V6 3#define ICS_TYPE_V5 15#define ICS_TYPE_NOTYPE ((unsigned int)-1)/* ---------------- Version 5 PCB Support Functions --------------------- *//* Prototype: icside_irqenable_arcin_v5 (struct expansion_card *ec, int irqnr) * Purpose : enable interrupts from card */static void icside_irqenable_arcin_v5 (struct expansion_card *ec, int irqnr){ struct icside_state *state = ec->irq_data; unsigned int base = state->irq_port; outb(0, base + ICS_ARCIN_V5_INTROFFSET);}/* Prototype: icside_irqdisable_arcin_v5 (struct expansion_card *ec, int irqnr) * Purpose : disable interrupts from card */static void icside_irqdisable_arcin_v5 (struct expansion_card *ec, int irqnr){ struct icside_state *state = ec->irq_data; unsigned int base = state->irq_port; inb(base + ICS_ARCIN_V5_INTROFFSET);}static const expansioncard_ops_t icside_ops_arcin_v5 = { .irqenable = icside_irqenable_arcin_v5, .irqdisable = icside_irqdisable_arcin_v5,};/* ---------------- Version 6 PCB Support Functions --------------------- *//* Prototype: icside_irqenable_arcin_v6 (struct expansion_card *ec, int irqnr) * Purpose : enable interrupts from card */static void icside_irqenable_arcin_v6 (struct expansion_card *ec, int irqnr){ struct icside_state *state = ec->irq_data; unsigned int base = state->irq_port; state->enabled = 1; switch (state->channel) { case 0: outb(0, base + ICS_ARCIN_V6_INTROFFSET_1); inb(base + ICS_ARCIN_V6_INTROFFSET_2); break; case 1: outb(0, base + ICS_ARCIN_V6_INTROFFSET_2); inb(base + ICS_ARCIN_V6_INTROFFSET_1); break; }}/* Prototype: icside_irqdisable_arcin_v6 (struct expansion_card *ec, int irqnr) * Purpose : disable interrupts from card */static void icside_irqdisable_arcin_v6 (struct expansion_card *ec, int irqnr){ struct icside_state *state = ec->irq_data; state->enabled = 0; inb (state->irq_port + ICS_ARCIN_V6_INTROFFSET_1); inb (state->irq_port + ICS_ARCIN_V6_INTROFFSET_2);}/* Prototype: icside_irqprobe(struct expansion_card *ec) * Purpose : detect an active interrupt from card */static int icside_irqpending_arcin_v6(struct expansion_card *ec){ struct icside_state *state = ec->irq_data; return inb(state->irq_port + ICS_ARCIN_V6_INTRSTAT_1) & 1 || inb(state->irq_port + ICS_ARCIN_V6_INTRSTAT_2) & 1;}static const expansioncard_ops_t icside_ops_arcin_v6 = { .irqenable = icside_irqenable_arcin_v6, .irqdisable = icside_irqdisable_arcin_v6, .irqpending = icside_irqpending_arcin_v6,};/* * Handle routing of interrupts. This is called before * we write the command to the drive. */static void icside_maskproc(ide_drive_t *drive, int mask){ ide_hwif_t *hwif = HWIF(drive); struct icside_state *state = hwif->hwif_data; unsigned long flags; local_irq_save(flags); state->channel = hwif->channel; if (state->enabled && !mask) { switch (hwif->channel) { case 0: outb(0, state->irq_port + ICS_ARCIN_V6_INTROFFSET_1); inb(state->irq_port + ICS_ARCIN_V6_INTROFFSET_2); break; case 1: outb(0, state->irq_port + ICS_ARCIN_V6_INTROFFSET_2); inb(state->irq_port + ICS_ARCIN_V6_INTROFFSET_1); break; } } else { inb(state->irq_port + ICS_ARCIN_V6_INTROFFSET_2); inb(state->irq_port + ICS_ARCIN_V6_INTROFFSET_1); } local_irq_restore(flags);}#ifdef CONFIG_BLK_DEV_IDEDMA_ICS/* * SG-DMA support. * * Similar to the BM-DMA, but we use the RiscPCs IOMD DMA controllers. * There is only one DMA controller per card, which means that only * one drive can be accessed at one time. NOTE! We do not enforce that * here, but we rely on the main IDE driver spotting that both * interfaces use the same IRQ, which should guarantee this. */#define NR_ENTRIES 256#define TABLE_SIZE (NR_ENTRIES * 8)static void ide_build_sglist(ide_drive_t *drive, struct request *rq){ ide_hwif_t *hwif = HWIF(drive); struct scatterlist *sg = hwif->sg_table; struct buffer_head *bh; int nents = 0; BUG_ON(hwif->sg_dma_active); if (rq->cmd == IDE_DRIVE_TASKFILE) { ide_task_t *args = rq->special; if (args->command_type == IDE_DRIVE_TASK_RAW_WRITE) hwif->sg_dma_direction = PCI_DMA_FROMDEVICE; else hwif->sg_dma_direction = PCI_DMA_TODEVICE; memset(sg, 0, sizeof(*sg)); sg->address = rq->buffer; sg->length = rq->nr_sectors * SECTOR_SIZE; nents = 1; } else { if (rq->cmd == READ) hwif->sg_dma_direction = PCI_DMA_FROMDEVICE; else hwif->sg_dma_direction = PCI_DMA_TODEVICE; bh = rq->bh; do { unsigned long lastend; memset(sg, 0, sizeof(*sg)); sg->page = bh->b_page; lastend = bh_phys(bh); do { lastend += bh->b_size; sg->length += bh->b_size; bh = bh->b_reqnext; if (bh == NULL) break; } while (lastend == bh_phys(bh)); sg++; nents++; } while (bh != NULL); } nents = pci_map_sg(NULL, sg, nents, hwif->sg_dma_direction); hwif->sg_nents = nents;}/* * Configure the IOMD to give the appropriate timings for the transfer * mode being requested. We take the advice of the ATA standards, and * calculate the cycle time based on the transfer mode, and the EIDE * MW DMA specs that the drive provides in the IDENTIFY command. * * We have the following IOMD DMA modes to choose from: * * Type Active Recovery Cycle * A 250 (250) 312 (550) 562 (800) * B 187 250 437 * C 125 (125) 125 (375) 250 (500) * D 62 125 187 * * (figures in brackets are actual measured timings) * * However, we also need to take care of the read/write active and * recovery timings: * * Read Write * Mode Active -- Recovery -- Cycle IOMD type * MW0 215 50 215 480 A * MW1 80 50 50 150 C * MW2 70 25 25 120 C */static int icside_set_speed(ide_drive_t *drive, u8 xfer_mode){ int on = 0, cycle_time = 0, use_dma_info = 0; /* * Limit the transfer speed to MW_DMA_2. */ if (xfer_mode > XFER_MW_DMA_2) xfer_mode = XFER_MW_DMA_2; switch (xfer_mode) { case XFER_MW_DMA_2: cycle_time = 250; use_dma_info = 1; break; case XFER_MW_DMA_1: cycle_time = 250; use_dma_info = 1; break; case XFER_MW_DMA_0: cycle_time = 480; break; case XFER_SW_DMA_2: case XFER_SW_DMA_1: case XFER_SW_DMA_0: cycle_time = 480; break; } /* * If we're going to be doing MW_DMA_1 or MW_DMA_2, we should * take care to note the values in the ID... */ if (use_dma_info && drive->id->eide_dma_time > cycle_time) cycle_time = drive->id->eide_dma_time; drive->drive_data = cycle_time; if (cycle_time && ide_config_drive_speed(drive, xfer_mode) == 0) on = 1; else drive->drive_data = 480; printk("%s: %s selected (peak %dMB/s)\n", drive->name, ide_xfer_verbose(xfer_mode), 2000 / drive->drive_data); drive->current_speed = xfer_mode; return on;}/* * The following is a sick duplication from ide-dma.c ;( * * This should be defined in one place only. */struct drive_list_entry { const char * id_model; const char * id_firmware;};static const struct drive_list_entry drive_whitelist [] = { { "Micropolis 2112A", "ALL" }, { "CONNER CTMA 4000", "ALL" }, { "CONNER CTT8000-A", "ALL" }, { "ST34342A", "ALL" }, { NULL, NULL }};static const struct drive_list_entry drive_blacklist [] = { { "WDC AC11000H", "ALL" }, { "WDC AC22100H", "ALL" }, { "WDC AC32500H", "ALL" }, { "WDC AC33100H", "ALL" }, { "WDC AC31600H", "ALL" }, { "WDC AC32100H", "24.09P07" }, { "WDC AC23200L", "21.10N21" }, { "Compaq CRD-8241B", "ALL" }, { "CRD-8400B", "ALL" }, { "CRD-8480B", "ALL" }, { "CRD-8480C", "ALL" }, { "CRD-8482B", "ALL" }, { "CRD-84", "ALL" }, { "SanDisk SDP3B", "ALL" }, { "SanDisk SDP3B-64", "ALL" }, { "SANYO CD-ROM CRD", "ALL" }, { "HITACHI CDR-8", "ALL" }, { "HITACHI CDR-8335", "ALL" }, { "HITACHI CDR-8435", "ALL" }, { "Toshiba CD-ROM XM-6202B", "ALL" }, { "CD-532E-A", "ALL" }, { "E-IDE CD-ROM CR-840", "ALL" }, { "CD-ROM Drive/F5A", "ALL" }, { "RICOH CD-R/RW MP7083A", "ALL" }, { "WPI CDD-820", "ALL" }, { "SAMSUNG CD-ROM SC-148C", "ALL" }, { "SAMSUNG CD-ROM SC-148F", "ALL" }, { "SAMSUNG CD-ROM SC", "ALL" }, { "SanDisk SDP3B-64", "ALL" }, { "SAMSUNG CD-ROM SN-124", "ALL" }, { "PLEXTOR CD-R PX-W8432T", "ALL" }, { "ATAPI CD-ROM DRIVE 40X MAXIMUM", "ALL" }, { "_NEC DV5800A", "ALL" }, { NULL, NULL }};static intin_drive_list(struct hd_driveid *id, const struct drive_list_entry *drive_table){ for ( ; drive_table->id_model ; drive_table++) if ((!strcmp(drive_table->id_model, id->model)) && ((!strstr(drive_table->id_firmware, id->fw_rev)) || (!strcmp(drive_table->id_firmware, "ALL")))) return 1; return 0;}static int icside_dma_host_off(ide_drive_t *drive){ return 0;}static int icside_dma_off_quietly(ide_drive_t *drive){ drive->using_dma = 0; return icside_dma_host_off(drive);}static int icside_dma_off(ide_drive_t *drive){ printk("%s: DMA disabled\n", drive->name); return icside_dma_off_quietly(drive);}static int icside_dma_host_on(ide_drive_t *drive){ return 0;}static int icside_dma_on(ide_drive_t *drive){ drive->using_dma = 1; return icside_dma_host_on(drive);}static int icside_dma_check(ide_drive_t *drive){ struct hd_driveid *id = drive->id; ide_hwif_t *hwif = HWIF(drive); int xfer_mode = XFER_PIO_2; int on; if (!id || !(id->capability & 1) || !hwif->autodma) goto out; /* * Consult the list of known "bad" drives */ if (in_drive_list(id, drive_blacklist)) { printk("%s: Disabling DMA for %s (blacklisted)\n", drive->name, id->model); goto out; } /* * Enable DMA on any drive that has multiword DMA */ if (id->field_valid & 2) { if (id->dma_mword & 4) { xfer_mode = XFER_MW_DMA_2; } else if (id->dma_mword & 2) { xfer_mode = XFER_MW_DMA_1; } else if (id->dma_mword & 1) { xfer_mode = XFER_MW_DMA_0; } goto out; } /* * Consult the list of known "good" drives */ if (in_drive_list(id, drive_whitelist)) { if (id->eide_dma_time > 150) goto out; xfer_mode = XFER_MW_DMA_1; }out: on = icside_set_speed(drive, xfer_mode); if (on) return icside_dma_on(drive); else return icside_dma_off(drive);}static int icside_dma_end(ide_drive_t *drive){ ide_hwif_t *hwif = HWIF(drive); drive->waiting_for_dma = 0; disable_dma(hwif->hw.dma); /* Teardown mappings after DMA has completed. */ pci_unmap_sg(NULL, hwif->sg_table, hwif->sg_nents, hwif->sg_dma_direction); hwif->sg_dma_active = 0; return get_dma_residue(hwif->hw.dma) != 0;}static int icside_dma_begin(ide_drive_t *drive){ ide_hwif_t *hwif = HWIF(drive); /* We can not enable DMA on both channels simultaneously. */ BUG_ON(dma_channel_active(hwif->hw.dma)); enable_dma(hwif->hw.dma); return 0;}static int icside_dma_count(ide_drive_t *drive){ return icside_dma_begin(drive);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -