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

📄 sgiioc4.c

📁 linux-2.6.15.6
💻 C
📖 第 1 页 / 共 2 页
字号:
/* * Copyright (c) 2003 Silicon Graphics, Inc.  All Rights Reserved. * * This program is free software; you can redistribute it and/or modify it * under the terms of version 2 of the GNU General Public License * as published by the Free Software Foundation. * * This program is distributed in the hope that it would be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * * You should have received a copy of the GNU General Public * License along with this program; if not, write the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston MA 02111-1307, USA. * * Contact information:  Silicon Graphics, Inc., 1600 Amphitheatre Pkwy, * Mountain View, CA  94043, or: * * http://www.sgi.com * * For further information regarding this notice, see: * * http://oss.sgi.com/projects/GenInfo/NoticeExplan */#include <linux/module.h>#include <linux/types.h>#include <linux/pci.h>#include <linux/delay.h>#include <linux/hdreg.h>#include <linux/init.h>#include <linux/kernel.h>#include <linux/timer.h>#include <linux/mm.h>#include <linux/ioport.h>#include <linux/blkdev.h>#include <linux/ioc4.h>#include <asm/io.h>#include <linux/ide.h>/* IOC4 Specific Definitions */#define IOC4_CMD_OFFSET		0x100#define IOC4_CTRL_OFFSET	0x120#define IOC4_DMA_OFFSET		0x140#define IOC4_INTR_OFFSET	0x0#define IOC4_TIMING		0x00#define IOC4_DMA_PTR_L		0x01#define IOC4_DMA_PTR_H		0x02#define IOC4_DMA_ADDR_L		0x03#define IOC4_DMA_ADDR_H		0x04#define IOC4_BC_DEV		0x05#define IOC4_BC_MEM		0x06#define	IOC4_DMA_CTRL		0x07#define	IOC4_DMA_END_ADDR	0x08/* Bits in the IOC4 Control/Status Register */#define	IOC4_S_DMA_START	0x01#define	IOC4_S_DMA_STOP		0x02#define	IOC4_S_DMA_DIR		0x04#define	IOC4_S_DMA_ACTIVE	0x08#define	IOC4_S_DMA_ERROR	0x10#define	IOC4_ATA_MEMERR		0x02/* Read/Write Directions */#define	IOC4_DMA_WRITE		0x04#define	IOC4_DMA_READ		0x00/* Interrupt Register Offsets */#define IOC4_INTR_REG		0x03#define	IOC4_INTR_SET		0x05#define	IOC4_INTR_CLEAR		0x07#define IOC4_IDE_CACHELINE_SIZE	128#define IOC4_CMD_CTL_BLK_SIZE	0x20#define IOC4_SUPPORTED_FIRMWARE_REV 46typedef struct {	u32 timing_reg0;	u32 timing_reg1;	u32 low_mem_ptr;	u32 high_mem_ptr;	u32 low_mem_addr;	u32 high_mem_addr;	u32 dev_byte_count;	u32 mem_byte_count;	u32 status;} ioc4_dma_regs_t;/* Each Physical Region Descriptor Entry size is 16 bytes (2 * 64 bits) *//* IOC4 has only 1 IDE channel */#define IOC4_PRD_BYTES       16#define IOC4_PRD_ENTRIES     (PAGE_SIZE /(4*IOC4_PRD_BYTES))static voidsgiioc4_init_hwif_ports(hw_regs_t * hw, unsigned long data_port,			unsigned long ctrl_port, unsigned long irq_port){	unsigned long reg = data_port;	int i;	/* Registers are word (32 bit) aligned */	for (i = IDE_DATA_OFFSET; i <= IDE_STATUS_OFFSET; i++)		hw->io_ports[i] = reg + i * 4;	if (ctrl_port)		hw->io_ports[IDE_CONTROL_OFFSET] = ctrl_port;	if (irq_port)		hw->io_ports[IDE_IRQ_OFFSET] = irq_port;}static voidsgiioc4_maskproc(ide_drive_t * drive, int mask){	ide_hwif_t *hwif = HWIF(drive);	hwif->OUTB(mask ? (drive->ctl | 2) : (drive->ctl & ~2),		   IDE_CONTROL_REG);}static intsgiioc4_checkirq(ide_hwif_t * hwif){	u8 intr_reg =	    hwif->INL(hwif->io_ports[IDE_IRQ_OFFSET] + IOC4_INTR_REG * 4);	if (intr_reg & 0x03)		return 1;	return 0;}static intsgiioc4_clearirq(ide_drive_t * drive){	u32 intr_reg;	ide_hwif_t *hwif = HWIF(drive);	unsigned long other_ir =	    hwif->io_ports[IDE_IRQ_OFFSET] + (IOC4_INTR_REG << 2);	/* Code to check for PCI error conditions */	intr_reg = hwif->INL(other_ir);	if (intr_reg & 0x03) { /* Valid IOC4-IDE interrupt */		/*		 * Using hwif->INB to read the IDE_STATUS_REG has a side effect		 * of clearing the interrupt.  The first read should clear it		 * if it is set.  The second read should return a "clear" status		 * if it got cleared.  If not, then spin for a bit trying to		 * clear it.		 */		u8 stat = hwif->INB(IDE_STATUS_REG);		int count = 0;		stat = hwif->INB(IDE_STATUS_REG);		while ((stat & 0x80) && (count++ < 100)) {			udelay(1);			stat = hwif->INB(IDE_STATUS_REG);		}		if (intr_reg & 0x02) {			/* Error when transferring DMA data on PCI bus */			u32 pci_err_addr_low, pci_err_addr_high,			    pci_stat_cmd_reg;			pci_err_addr_low =				hwif->INL(hwif->io_ports[IDE_IRQ_OFFSET]);			pci_err_addr_high =				hwif->INL(hwif->io_ports[IDE_IRQ_OFFSET] + 4);			pci_read_config_dword(hwif->pci_dev, PCI_COMMAND,					      &pci_stat_cmd_reg);			printk(KERN_ERR			       "%s(%s) : PCI Bus Error when doing DMA:"				   " status-cmd reg is 0x%x\n",			       __FUNCTION__, drive->name, pci_stat_cmd_reg);			printk(KERN_ERR			       "%s(%s) : PCI Error Address is 0x%x%x\n",			       __FUNCTION__, drive->name,			       pci_err_addr_high, pci_err_addr_low);			/* Clear the PCI Error indicator */			pci_write_config_dword(hwif->pci_dev, PCI_COMMAND,					       0x00000146);		}		/* Clear the Interrupt, Error bits on the IOC4 */		hwif->OUTL(0x03, other_ir);		intr_reg = hwif->INL(other_ir);	}	return intr_reg & 3;}static void sgiioc4_ide_dma_start(ide_drive_t * drive){	ide_hwif_t *hwif = HWIF(drive);	unsigned int reg = hwif->INL(hwif->dma_base + IOC4_DMA_CTRL * 4);	unsigned int temp_reg = reg | IOC4_S_DMA_START;	hwif->OUTL(temp_reg, hwif->dma_base + IOC4_DMA_CTRL * 4);}static u32sgiioc4_ide_dma_stop(ide_hwif_t *hwif, u64 dma_base){	u32	ioc4_dma;	int	count;	count = 0;	ioc4_dma = hwif->INL(dma_base + IOC4_DMA_CTRL * 4);	while ((ioc4_dma & IOC4_S_DMA_STOP) && (count++ < 200)) {		udelay(1);		ioc4_dma = hwif->INL(dma_base + IOC4_DMA_CTRL * 4);	}	return ioc4_dma;}/* Stops the IOC4 DMA Engine */static intsgiioc4_ide_dma_end(ide_drive_t * drive){	u32 ioc4_dma, bc_dev, bc_mem, num, valid = 0, cnt = 0;	ide_hwif_t *hwif = HWIF(drive);	u64 dma_base = hwif->dma_base;	int dma_stat = 0;	unsigned long *ending_dma = (unsigned long *) hwif->dma_base2;	hwif->OUTL(IOC4_S_DMA_STOP, dma_base + IOC4_DMA_CTRL * 4);	ioc4_dma = sgiioc4_ide_dma_stop(hwif, dma_base);	if (ioc4_dma & IOC4_S_DMA_STOP) {		printk(KERN_ERR		       "%s(%s): IOC4 DMA STOP bit is still 1 :"		       "ioc4_dma_reg 0x%x\n",		       __FUNCTION__, drive->name, ioc4_dma);		dma_stat = 1;	}	/*	 * The IOC4 will DMA 1's to the ending dma area to indicate that	 * previous data DMA is complete.  This is necessary because of relaxed	 * ordering between register reads and DMA writes on the Altix.	 */	while ((cnt++ < 200) && (!valid)) {		for (num = 0; num < 16; num++) {			if (ending_dma[num]) {				valid = 1;				break;			}		}		udelay(1);	}	if (!valid) {		printk(KERN_ERR "%s(%s) : DMA incomplete\n", __FUNCTION__,		       drive->name);		dma_stat = 1;	}	bc_dev = hwif->INL(dma_base + IOC4_BC_DEV * 4);	bc_mem = hwif->INL(dma_base + IOC4_BC_MEM * 4);	if ((bc_dev & 0x01FF) || (bc_mem & 0x1FF)) {		if (bc_dev > bc_mem + 8) {			printk(KERN_ERR			       "%s(%s): WARNING!! byte_count_dev %d "			       "!= byte_count_mem %d\n",			       __FUNCTION__, drive->name, bc_dev, bc_mem);		}	}	drive->waiting_for_dma = 0;	ide_destroy_dmatable(drive);	return dma_stat;}static intsgiioc4_ide_dma_check(ide_drive_t * drive){	if (ide_config_drive_speed(drive, XFER_MW_DMA_2) != 0) {		printk(KERN_INFO		       "Couldnot set %s in Multimode-2 DMA mode | "			   "Drive %s using PIO instead\n",		       drive->name, drive->name);		drive->using_dma = 0;	} else		drive->using_dma = 1;	return 0;}static intsgiioc4_ide_dma_on(ide_drive_t * drive){	drive->using_dma = 1;	return HWIF(drive)->ide_dma_host_on(drive);}static intsgiioc4_ide_dma_off_quietly(ide_drive_t * drive){	drive->using_dma = 0;	return HWIF(drive)->ide_dma_host_off(drive);}/* returns 1 if dma irq issued, 0 otherwise */static intsgiioc4_ide_dma_test_irq(ide_drive_t * drive){	return sgiioc4_checkirq(HWIF(drive));}static intsgiioc4_ide_dma_host_on(ide_drive_t * drive){	if (drive->using_dma)		return 0;	return 1;}static intsgiioc4_ide_dma_host_off(ide_drive_t * drive){	sgiioc4_clearirq(drive);	return 0;}static intsgiioc4_ide_dma_lostirq(ide_drive_t * drive){	HWIF(drive)->resetproc(drive);	return __ide_dma_lostirq(drive);}static voidsgiioc4_resetproc(ide_drive_t * drive){	sgiioc4_ide_dma_end(drive);	sgiioc4_clearirq(drive);}static u8sgiioc4_INB(unsigned long port){	u8 reg = (u8) inb(port);	if ((port & 0xFFF) == 0x11C) {	/* Status register of IOC4 */		if (reg & 0x51) {	/* Not busy...check for interrupt */			unsigned long other_ir = port - 0x110;			unsigned int intr_reg = (u32) inl(other_ir);			/* Clear the Interrupt, Error bits on the IOC4 */			if (intr_reg & 0x03) {				outl(0x03, other_ir);				intr_reg = (u32) inl(other_ir);			}		}	}	return reg;}/* Creates a dma map for the scatter-gather list entries */static void __devinitide_dma_sgiioc4(ide_hwif_t * hwif, unsigned long dma_base){	int num_ports = sizeof (ioc4_dma_regs_t);	printk(KERN_INFO "%s: BM-DMA at 0x%04lx-0x%04lx\n", hwif->name,	       dma_base, dma_base + num_ports - 1);

⌨️ 快捷键说明

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