📄 icside.c
字号:
/* * linux/drivers/ide/arm/icside.c * * Copyright (c) 1996,1997 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>#include "ide-noise.h"/* * FIXME: We want to drop the the MACRO CRAP! * * ec->iops->in{b/w/l} * ec->iops->in{b/w/l}_p * ec->iops->out{b/w/l} * ec->iops->out{b/w/l}_p * * the new core supports clean MMIO calls and other goodies *//* * Maximum number of interfaces per card */#define MAX_IFS 2#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};static const card_ids icside_cids[] = { { MANU_ICS, PROD_ICS_IDE }, { MANU_ICS2, PROD_ICS2_IDE }, { 0xffff, 0xffff }};typedef enum { ics_if_unknown, ics_if_arcin_v5, ics_if_arcin_v6} iftype_t;/* ---------------- 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){ unsigned int memc_port = (unsigned int)ec->irq_data; outb(0, memc_port + 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){ unsigned int memc_port = (unsigned int)ec->irq_data; inb(memc_port + ICS_ARCIN_V5_INTROFFSET);}static const expansioncard_ops_t icside_ops_arcin_v5 = { icside_irqenable_arcin_v5, icside_irqdisable_arcin_v5, NULL, NULL, NULL, NULL};/* ---------------- 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){ unsigned int ide_base_port = (unsigned int)ec->irq_data; outb(0, ide_base_port + ICS_ARCIN_V6_INTROFFSET_1); outb(0, ide_base_port + ICS_ARCIN_V6_INTROFFSET_2);}/* 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){ unsigned int ide_base_port = (unsigned int)ec->irq_data; inb(ide_base_port + ICS_ARCIN_V6_INTROFFSET_1); inb(ide_base_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){ unsigned int ide_base_port = (unsigned int)ec->irq_data; return inb(ide_base_port + ICS_ARCIN_V6_INTRSTAT_1) & 1 || inb(ide_base_port + ICS_ARCIN_V6_INTRSTAT_2) & 1;}static const expansioncard_ops_t icside_ops_arcin_v6 = { icside_irqenable_arcin_v6, icside_irqdisable_arcin_v6, icside_irqpending_arcin_v6, NULL, NULL, NULL};/* Prototype: icside_identifyif (struct expansion_card *ec) * Purpose : identify IDE interface type * Notes : checks the description string */static iftype_t __init icside_identifyif (struct expansion_card *ec){ unsigned int addr; iftype_t iftype; int id = 0; iftype = ics_if_unknown; addr = ecard_address (ec, ECARD_IOC, ECARD_FAST) + ICS_IDENT_OFFSET; id = inb(addr) & 1; id |= (inb(addr + 1) & 1) << 1; id |= (inb(addr + 2) & 1) << 2; id |= (inb(addr + 3) & 1) << 3; switch (id) { case 0: /* A3IN */ printk("icside: A3IN unsupported\n"); break; case 1: /* A3USER */ printk("icside: A3USER unsupported\n"); break; case 3: /* ARCIN V6 */ printk(KERN_DEBUG "icside: detected ARCIN V6 in slot %d\n", ec->slot_no); iftype = ics_if_arcin_v6; break; case 15:/* ARCIN V5 (no id) */ printk(KERN_DEBUG "icside: detected ARCIN V5 in slot %d\n", ec->slot_no); iftype = ics_if_arcin_v5; break; default:/* we don't know - complain very loudly */ printk("icside: ***********************************\n"); printk("icside: *** UNKNOWN ICS INTERFACE id=%d ***\n", id); printk("icside: ***********************************\n"); printk("icside: please report this to linux@arm.linux.org.uk\n"); printk("icside: defaulting to ARCIN V5\n"); iftype = ics_if_arcin_v5; break; } return iftype;}#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 int ide_build_sglist(ide_hwif_t *hwif, struct request *rq){ struct buffer_head *bh; struct scatterlist *sg = hwif->sg_table; int nents = 0; if (rq->cmd == READ) hwif->sg_dma_direction = PCI_DMA_FROMDEVICE; else hwif->sg_dma_direction = PCI_DMA_TODEVICE; bh = rq->bh; do { unsigned char *virt_addr = bh->b_data; unsigned int size = bh->b_size; while ((bh = bh->b_reqnext) != NULL) { if ((virt_addr + size) != (unsigned char *)bh->b_data) break; size += bh->b_size; } memset(&sg[nents], 0, sizeof(*sg)); sg[nents].address = virt_addr; sg[nents].length = size; nents++; } while (bh != NULL); return pci_map_sg(NULL, sg, nents, hwif->sg_dma_direction);}static inticside_build_dmatable(ide_drive_t *drive, int ddir){ return HWIF(drive)->sg_nents = ide_build_sglist(HWIF(drive), HWGROUP(drive)->rq, ddir);}/* Teardown mappings after DMA has completed. */static void icside_destroy_dmatable(ide_drive_t *drive){ struct scatterlist *sg = HWIF(drive)->sg_table; int nents = HWIF(drive)->sg_nents; pci_unmap_sg(NULL, sg, nents, HWIF(drive)->sg_dma_direction);}static inticside_config_if(ide_drive_t *drive, int xfer_mode){ int func = ide_dma_off; switch (xfer_mode) { case XFER_MW_DMA_2: /* * The cycle time is limited to 250ns by the r/w * pulse width (90ns), however we should still * have a maximum burst transfer rate of 8MB/s. */ drive->drive_data = 250; break; case XFER_MW_DMA_1: drive->drive_data = 250; break; case XFER_MW_DMA_0: drive->drive_data = 480; break; default: drive->drive_data = 0; break; } if (!drive->init_speed) drive->init_speed = (u8) xfer_mode; if (drive->drive_data && ide_config_drive_speed(drive, (u8) xfer_mode) == 0) func = ide_dma_on; 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 = (u8) xfer_mode; return func;}static inticside_set_speed(ide_drive_t *drive, u8 speed){ return icside_config_if(drive, speed);}/* * dma_intr() is the handler for disk read/write DMA interrupts */static ide_startstop_t icside_dmaintr(ide_drive_t *drive){ u8 dma_stat = HWIF(drive)->ide_dma_end(drive); /* get drive status */ u8 stat = HWIF(drive)->INB(IDE_STATUS_REG); int i; if (OK_STAT(stat,DRIVE_READY,drive->bad_wstat|DRQ_STAT)) { if (!dma_stat) { struct request *rq = HWGROUP(drive)->rq; rq = HWGROUP(drive)->rq; for (i = rq->nr_sectors; i > 0;) { i -= rq->current_nr_sectors; DRIVER(drive)->end_request(drive, 1); } return ide_stopped; } printk("%s: dma_intr: bad DMA status (dma_stat=%x)\n", drive->name, dma_stat); } return DRIVER(drive)->error(drive, "dma_intr", stat);}/* * The following is a sick duplication from ide-dma.c ;( * * This should be defined in one place only. */struct drive_list_entry { char * id_model; char * id_firmware;};static struct drive_list_entry drive_whitelist [] = { { "Micropolis 2112A", "ALL" }, { "CONNER CTMA 4000", "ALL" }, { "CONNER CTT8000-A", "ALL" }, { "ST34342A", "ALL" }, { NULL, 0 }};static 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, 0 }};static int in_drive_list(struct hd_driveid *id, 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;}/* * For both Blacklisted and Whitelisted drives. * This is setup to be called as an extern for future support * to other special driver code. */int check_drive_good_lists (ide_drive_t *drive){ struct hd_driveid *id = drive->id; return in_drive_list(id, drive_whitelist);}int check_drive_bad_lists (ide_drive_t *drive){ struct hd_driveid *id = drive->id; int blacklist = in_drive_list(id, drive_blacklist); if (blacklist)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -