⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 libata-sff.c

📁 linux 内核源代码
💻 C
📖 第 1 页 / 共 2 页
字号:
/* *  libata-sff.c - helper library for PCI IDE BMDMA * *  Maintained by:  Jeff Garzik <jgarzik@pobox.com> *    		    Please ALWAYS copy linux-ide@vger.kernel.org *		    on emails. * *  Copyright 2003-2006 Red Hat, Inc.  All rights reserved. *  Copyright 2003-2006 Jeff Garzik * * *  This program is free software; you can redistribute it and/or modify *  it under the terms of the GNU General Public License as published by *  the Free Software Foundation; either version 2, or (at your option) *  any later version. * *  This program is distributed in the hope that it will be useful, *  but WITHOUT ANY WARRANTY; without even the implied warranty of *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the *  GNU General Public License for more details. * *  You should have received a copy of the GNU General Public License *  along with this program; see the file COPYING.  If not, write to *  the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. * * *  libata documentation is available via 'make {ps|pdf}docs', *  as Documentation/DocBook/libata.* * *  Hardware documentation available from http://www.t13.org/ and *  http://www.sata-io.org/ * */#include <linux/kernel.h>#include <linux/pci.h>#include <linux/libata.h>#include "libata.h"/** *	ata_irq_on - Enable interrupts on a port. *	@ap: Port on which interrupts are enabled. * *	Enable interrupts on a legacy IDE device using MMIO or PIO, *	wait for idle, clear any pending interrupts. * *	LOCKING: *	Inherited from caller. */u8 ata_irq_on(struct ata_port *ap){	struct ata_ioports *ioaddr = &ap->ioaddr;	u8 tmp;	ap->ctl &= ~ATA_NIEN;	ap->last_ctl = ap->ctl;	iowrite8(ap->ctl, ioaddr->ctl_addr);	tmp = ata_wait_idle(ap);	ap->ops->irq_clear(ap);	return tmp;}/** *	ata_tf_load - send taskfile registers to host controller *	@ap: Port to which output is sent *	@tf: ATA taskfile register set * *	Outputs ATA taskfile to standard ATA host controller. * *	LOCKING: *	Inherited from caller. */void ata_tf_load(struct ata_port *ap, const struct ata_taskfile *tf){	struct ata_ioports *ioaddr = &ap->ioaddr;	unsigned int is_addr = tf->flags & ATA_TFLAG_ISADDR;	if (tf->ctl != ap->last_ctl) {		iowrite8(tf->ctl, ioaddr->ctl_addr);		ap->last_ctl = tf->ctl;		ata_wait_idle(ap);	}	if (is_addr && (tf->flags & ATA_TFLAG_LBA48)) {		iowrite8(tf->hob_feature, ioaddr->feature_addr);		iowrite8(tf->hob_nsect, ioaddr->nsect_addr);		iowrite8(tf->hob_lbal, ioaddr->lbal_addr);		iowrite8(tf->hob_lbam, ioaddr->lbam_addr);		iowrite8(tf->hob_lbah, ioaddr->lbah_addr);		VPRINTK("hob: feat 0x%X nsect 0x%X, lba 0x%X 0x%X 0x%X\n",			tf->hob_feature,			tf->hob_nsect,			tf->hob_lbal,			tf->hob_lbam,			tf->hob_lbah);	}	if (is_addr) {		iowrite8(tf->feature, ioaddr->feature_addr);		iowrite8(tf->nsect, ioaddr->nsect_addr);		iowrite8(tf->lbal, ioaddr->lbal_addr);		iowrite8(tf->lbam, ioaddr->lbam_addr);		iowrite8(tf->lbah, ioaddr->lbah_addr);		VPRINTK("feat 0x%X nsect 0x%X lba 0x%X 0x%X 0x%X\n",			tf->feature,			tf->nsect,			tf->lbal,			tf->lbam,			tf->lbah);	}	if (tf->flags & ATA_TFLAG_DEVICE) {		iowrite8(tf->device, ioaddr->device_addr);		VPRINTK("device 0x%X\n", tf->device);	}	ata_wait_idle(ap);}/** *	ata_exec_command - issue ATA command to host controller *	@ap: port to which command is being issued *	@tf: ATA taskfile register set * *	Issues ATA command, with proper synchronization with interrupt *	handler / other threads. * *	LOCKING: *	spin_lock_irqsave(host lock) */void ata_exec_command(struct ata_port *ap, const struct ata_taskfile *tf){	DPRINTK("ata%u: cmd 0x%X\n", ap->print_id, tf->command);	iowrite8(tf->command, ap->ioaddr.command_addr);	ata_pause(ap);}/** *	ata_tf_read - input device's ATA taskfile shadow registers *	@ap: Port from which input is read *	@tf: ATA taskfile register set for storing input * *	Reads ATA taskfile registers for currently-selected device *	into @tf. * *	LOCKING: *	Inherited from caller. */void ata_tf_read(struct ata_port *ap, struct ata_taskfile *tf){	struct ata_ioports *ioaddr = &ap->ioaddr;	tf->command = ata_chk_status(ap);	tf->feature = ioread8(ioaddr->error_addr);	tf->nsect = ioread8(ioaddr->nsect_addr);	tf->lbal = ioread8(ioaddr->lbal_addr);	tf->lbam = ioread8(ioaddr->lbam_addr);	tf->lbah = ioread8(ioaddr->lbah_addr);	tf->device = ioread8(ioaddr->device_addr);	if (tf->flags & ATA_TFLAG_LBA48) {		iowrite8(tf->ctl | ATA_HOB, ioaddr->ctl_addr);		tf->hob_feature = ioread8(ioaddr->error_addr);		tf->hob_nsect = ioread8(ioaddr->nsect_addr);		tf->hob_lbal = ioread8(ioaddr->lbal_addr);		tf->hob_lbam = ioread8(ioaddr->lbam_addr);		tf->hob_lbah = ioread8(ioaddr->lbah_addr);		iowrite8(tf->ctl, ioaddr->ctl_addr);		ap->last_ctl = tf->ctl;	}}/** *	ata_check_status - Read device status reg & clear interrupt *	@ap: port where the device is * *	Reads ATA taskfile status register for currently-selected device *	and return its value. This also clears pending interrupts *      from this device * *	LOCKING: *	Inherited from caller. */u8 ata_check_status(struct ata_port *ap){	return ioread8(ap->ioaddr.status_addr);}/** *	ata_altstatus - Read device alternate status reg *	@ap: port where the device is * *	Reads ATA taskfile alternate status register for *	currently-selected device and return its value. * *	Note: may NOT be used as the check_altstatus() entry in *	ata_port_operations. * *	LOCKING: *	Inherited from caller. */u8 ata_altstatus(struct ata_port *ap){	if (ap->ops->check_altstatus)		return ap->ops->check_altstatus(ap);	return ioread8(ap->ioaddr.altstatus_addr);}/** *	ata_bmdma_setup - Set up PCI IDE BMDMA transaction *	@qc: Info associated with this ATA transaction. * *	LOCKING: *	spin_lock_irqsave(host lock) */void ata_bmdma_setup(struct ata_queued_cmd *qc){	struct ata_port *ap = qc->ap;	unsigned int rw = (qc->tf.flags & ATA_TFLAG_WRITE);	u8 dmactl;	/* load PRD table addr. */	mb();	/* make sure PRD table writes are visible to controller */	iowrite32(ap->prd_dma, ap->ioaddr.bmdma_addr + ATA_DMA_TABLE_OFS);	/* specify data direction, triple-check start bit is clear */	dmactl = ioread8(ap->ioaddr.bmdma_addr + ATA_DMA_CMD);	dmactl &= ~(ATA_DMA_WR | ATA_DMA_START);	if (!rw)		dmactl |= ATA_DMA_WR;	iowrite8(dmactl, ap->ioaddr.bmdma_addr + ATA_DMA_CMD);	/* issue r/w command */	ap->ops->exec_command(ap, &qc->tf);}/** *	ata_bmdma_start - Start a PCI IDE BMDMA transaction *	@qc: Info associated with this ATA transaction. * *	LOCKING: *	spin_lock_irqsave(host lock) */void ata_bmdma_start(struct ata_queued_cmd *qc){	struct ata_port *ap = qc->ap;	u8 dmactl;	/* start host DMA transaction */	dmactl = ioread8(ap->ioaddr.bmdma_addr + ATA_DMA_CMD);	iowrite8(dmactl | ATA_DMA_START, ap->ioaddr.bmdma_addr + ATA_DMA_CMD);	/* Strictly, one may wish to issue an ioread8() here, to	 * flush the mmio write.  However, control also passes	 * to the hardware at this point, and it will interrupt	 * us when we are to resume control.  So, in effect,	 * we don't care when the mmio write flushes.	 * Further, a read of the DMA status register _immediately_	 * following the write may not be what certain flaky hardware	 * is expected, so I think it is best to not add a readb()	 * without first all the MMIO ATA cards/mobos.	 * Or maybe I'm just being paranoid.	 *	 * FIXME: The posting of this write means I/O starts are	 * unneccessarily delayed for MMIO	 */}/** *	ata_bmdma_irq_clear - Clear PCI IDE BMDMA interrupt. *	@ap: Port associated with this ATA transaction. * *	Clear interrupt and error flags in DMA status register. * *	May be used as the irq_clear() entry in ata_port_operations. * *	LOCKING: *	spin_lock_irqsave(host lock) */void ata_bmdma_irq_clear(struct ata_port *ap){	void __iomem *mmio = ap->ioaddr.bmdma_addr;	if (!mmio)		return;	iowrite8(ioread8(mmio + ATA_DMA_STATUS), mmio + ATA_DMA_STATUS);}/** *	ata_bmdma_status - Read PCI IDE BMDMA status *	@ap: Port associated with this ATA transaction. * *	Read and return BMDMA status register. * *	May be used as the bmdma_status() entry in ata_port_operations. * *	LOCKING: *	spin_lock_irqsave(host lock) */u8 ata_bmdma_status(struct ata_port *ap){	return ioread8(ap->ioaddr.bmdma_addr + ATA_DMA_STATUS);}/** *	ata_bmdma_stop - Stop PCI IDE BMDMA transfer *	@qc: Command we are ending DMA for * *	Clears the ATA_DMA_START flag in the dma control register * *	May be used as the bmdma_stop() entry in ata_port_operations. * *	LOCKING: *	spin_lock_irqsave(host lock) */void ata_bmdma_stop(struct ata_queued_cmd *qc){	struct ata_port *ap = qc->ap;	void __iomem *mmio = ap->ioaddr.bmdma_addr;	/* clear start/stop bit */	iowrite8(ioread8(mmio + ATA_DMA_CMD) & ~ATA_DMA_START,		 mmio + ATA_DMA_CMD);	/* one-PIO-cycle guaranteed wait, per spec, for HDMA1:0 transition */	ata_altstatus(ap);        /* dummy read */}/** *	ata_bmdma_freeze - Freeze BMDMA controller port *	@ap: port to freeze * *	Freeze BMDMA controller port. * *	LOCKING: *	Inherited from caller. */void ata_bmdma_freeze(struct ata_port *ap){	struct ata_ioports *ioaddr = &ap->ioaddr;	ap->ctl |= ATA_NIEN;	ap->last_ctl = ap->ctl;	iowrite8(ap->ctl, ioaddr->ctl_addr);	/* Under certain circumstances, some controllers raise IRQ on	 * ATA_NIEN manipulation.  Also, many controllers fail to mask	 * previously pending IRQ on ATA_NIEN assertion.  Clear it.	 */	ata_chk_status(ap);	ap->ops->irq_clear(ap);}/** *	ata_bmdma_thaw - Thaw BMDMA controller port *	@ap: port to thaw * *	Thaw BMDMA controller port. * *	LOCKING: *	Inherited from caller. */void ata_bmdma_thaw(struct ata_port *ap){	/* clear & re-enable interrupts */	ata_chk_status(ap);	ap->ops->irq_clear(ap);	ap->ops->irq_on(ap);}/** *	ata_bmdma_drive_eh - Perform EH with given methods for BMDMA controller *	@ap: port to handle error for *	@prereset: prereset method (can be NULL) *	@softreset: softreset method (can be NULL) *	@hardreset: hardreset method (can be NULL) *	@postreset: postreset method (can be NULL) * *	Handle error for ATA BMDMA controller.  It can handle both *	PATA and SATA controllers.  Many controllers should be able to *	use this EH as-is or with some added handling before and *	after. * *	This function is intended to be used for constructing *	->error_handler callback by low level drivers. * *	LOCKING: *	Kernel thread context (may sleep) */void ata_bmdma_drive_eh(struct ata_port *ap, ata_prereset_fn_t prereset,			ata_reset_fn_t softreset, ata_reset_fn_t hardreset,			ata_postreset_fn_t postreset){	struct ata_queued_cmd *qc;	unsigned long flags;	int thaw = 0;	qc = __ata_qc_from_tag(ap, ap->link.active_tag);	if (qc && !(qc->flags & ATA_QCFLAG_FAILED))		qc = NULL;	/* reset PIO HSM and stop DMA engine */	spin_lock_irqsave(ap->lock, flags);	ap->hsm_task_state = HSM_ST_IDLE;	if (qc && (qc->tf.protocol == ATA_PROT_DMA ||		   qc->tf.protocol == ATA_PROT_ATAPI_DMA)) {		u8 host_stat;		host_stat = ap->ops->bmdma_status(ap);		/* BMDMA controllers indicate host bus error by		 * setting DMA_ERR bit and timing out.  As it wasn't		 * really a timeout event, adjust error mask and		 * cancel frozen state.		 */		if (qc->err_mask == AC_ERR_TIMEOUT && (host_stat & ATA_DMA_ERR)) {			qc->err_mask = AC_ERR_HOST_BUS;			thaw = 1;		}		ap->ops->bmdma_stop(qc);	}	ata_altstatus(ap);	ata_chk_status(ap);	ap->ops->irq_clear(ap);	spin_unlock_irqrestore(ap->lock, flags);	if (thaw)		ata_eh_thaw_port(ap);	/* PIO and DMA engines have been stopped, perform recovery */	ata_do_eh(ap, prereset, softreset, hardreset, postreset);}

⌨️ 快捷键说明

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