icside.c

来自「linux 内核源代码」· C语言 代码 · 共 747 行 · 第 1/2 页

C
747
字号
/* * linux/drivers/ide/arm/icside.c * * Copyright (c) 1996-2004 Russell King. * * Please note that this platform does not support 32-bit IDE IO. */#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/dma-mapping.h>#include <linux/device.h>#include <linux/init.h>#include <linux/scatterlist.h>#include <linux/io.h>#include <asm/dma.h>#include <asm/ecard.h>#define ICS_IDENT_OFFSET		0x2280#define ICS_ARCIN_V5_INTRSTAT		0x0000#define ICS_ARCIN_V5_INTROFFSET		0x0004#define ICS_ARCIN_V5_IDEOFFSET		0x2800#define ICS_ARCIN_V5_IDEALTOFFSET	0x2b80#define ICS_ARCIN_V5_IDESTEPPING	6#define ICS_ARCIN_V6_IDEOFFSET_1	0x2000#define ICS_ARCIN_V6_INTROFFSET_1	0x2200#define ICS_ARCIN_V6_INTRSTAT_1		0x2290#define ICS_ARCIN_V6_IDEALTOFFSET_1	0x2380#define ICS_ARCIN_V6_IDEOFFSET_2	0x3000#define ICS_ARCIN_V6_INTROFFSET_2	0x3200#define ICS_ARCIN_V6_INTRSTAT_2		0x3290#define ICS_ARCIN_V6_IDEALTOFFSET_2	0x3380#define ICS_ARCIN_V6_IDESTEPPING	6struct cardinfo {	unsigned int dataoffset;	unsigned int ctrloffset;	unsigned int stepping;};static struct cardinfo icside_cardinfo_v5 = {	.dataoffset	= ICS_ARCIN_V5_IDEOFFSET,	.ctrloffset	= ICS_ARCIN_V5_IDEALTOFFSET,	.stepping	= ICS_ARCIN_V5_IDESTEPPING,};static struct cardinfo icside_cardinfo_v6_1 = {	.dataoffset	= ICS_ARCIN_V6_IDEOFFSET_1,	.ctrloffset	= ICS_ARCIN_V6_IDEALTOFFSET_1,	.stepping	= ICS_ARCIN_V6_IDESTEPPING,};static struct cardinfo icside_cardinfo_v6_2 = {	.dataoffset	= ICS_ARCIN_V6_IDEOFFSET_2,	.ctrloffset	= ICS_ARCIN_V6_IDEALTOFFSET_2,	.stepping	= ICS_ARCIN_V6_IDESTEPPING,};struct icside_state {	unsigned int channel;	unsigned int enabled;	void __iomem *irq_port;	void __iomem *ioc_base;	unsigned int type;	/* parent device... until the IDE core gets one of its own */	struct device *dev;	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;	writeb(0, state->irq_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){	struct icside_state *state = ec->irq_data;	readb(state->irq_port + 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;	void __iomem *base = state->irq_port;	state->enabled = 1;	switch (state->channel) {	case 0:		writeb(0, base + ICS_ARCIN_V6_INTROFFSET_1);		readb(base + ICS_ARCIN_V6_INTROFFSET_2);		break;	case 1:		writeb(0, base + ICS_ARCIN_V6_INTROFFSET_2);		readb(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;	readb(state->irq_port + ICS_ARCIN_V6_INTROFFSET_1);	readb(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 readb(state->irq_port + ICS_ARCIN_V6_INTRSTAT_1) & 1 ||	       readb(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:			writeb(0, state->irq_port + ICS_ARCIN_V6_INTROFFSET_1);			readb(state->irq_port + ICS_ARCIN_V6_INTROFFSET_2);			break;		case 1:			writeb(0, state->irq_port + ICS_ARCIN_V6_INTROFFSET_2);			readb(state->irq_port + ICS_ARCIN_V6_INTROFFSET_1);			break;		}	} else {		readb(state->irq_port + ICS_ARCIN_V6_INTROFFSET_2);		readb(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. */static void icside_build_sglist(ide_drive_t *drive, struct request *rq){	ide_hwif_t *hwif = drive->hwif;	struct icside_state *state = hwif->hwif_data;	struct scatterlist *sg = hwif->sg_table;	ide_map_sg(drive, rq);	if (rq_data_dir(rq) == READ)		hwif->sg_dma_direction = DMA_FROM_DEVICE;	else		hwif->sg_dma_direction = DMA_TO_DEVICE;	hwif->sg_nents = dma_map_sg(state->dev, sg, hwif->sg_nents,				    hwif->sg_dma_direction);}/* * 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 void icside_set_dma_mode(ide_drive_t *drive, const u8 xfer_mode){	int cycle_time, use_dma_info = 0;	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;	default:		return;	}	/*	 * 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;	printk("%s: %s selected (peak %dMB/s)\n", drive->name,		ide_xfer_verbose(xfer_mode), 2000 / drive->drive_data);}static void icside_dma_host_off(ide_drive_t *drive){}static void icside_dma_off_quietly(ide_drive_t *drive){	drive->using_dma = 0;}static void icside_dma_host_on(ide_drive_t *drive){}static int icside_dma_on(ide_drive_t *drive){	drive->using_dma = 1;	return 0;}static int icside_dma_end(ide_drive_t *drive){	ide_hwif_t *hwif = HWIF(drive);	struct icside_state *state = hwif->hwif_data;	drive->waiting_for_dma = 0;	disable_dma(ECARD_DEV(state->dev)->dma);	/* Teardown mappings after DMA has completed. */	dma_unmap_sg(state->dev, hwif->sg_table, hwif->sg_nents,		     hwif->sg_dma_direction);	return get_dma_residue(ECARD_DEV(state->dev)->dma) != 0;}static void icside_dma_start(ide_drive_t *drive){	ide_hwif_t *hwif = HWIF(drive);	struct icside_state *state = hwif->hwif_data;	/* We can not enable DMA on both channels simultaneously. */	BUG_ON(dma_channel_active(ECARD_DEV(state->dev)->dma));	enable_dma(ECARD_DEV(state->dev)->dma);}static int icside_dma_setup(ide_drive_t *drive){	ide_hwif_t *hwif = HWIF(drive);	struct icside_state *state = hwif->hwif_data;	struct request *rq = hwif->hwgroup->rq;	unsigned int dma_mode;	if (rq_data_dir(rq))		dma_mode = DMA_MODE_WRITE;	else		dma_mode = DMA_MODE_READ;	/*	 * We can not enable DMA on both channels.	 */	BUG_ON(dma_channel_active(ECARD_DEV(state->dev)->dma));	icside_build_sglist(drive, rq);	/*	 * Ensure that we have the right interrupt routed.	 */	icside_maskproc(drive, 0);	/*	 * Route the DMA signals to the correct interface.	 */	writeb(hwif->select_data, hwif->config_data);	/*	 * Select the correct timing for this drive.	 */	set_dma_speed(ECARD_DEV(state->dev)->dma, drive->drive_data);	/*	 * Tell the DMA engine about the SG table and	 * data direction.

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?