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

📄 mfmhd.c

📁 MIZI Research, Inc.发布的嵌入式Linux内核源码
💻 C
📖 第 1 页 / 共 3 页
字号:
/* * linux/arch/arm/drivers/block/mfmhd.c * * Copyright (C) 1995, 1996 Russell King, Dave Alan Gilbert (gilbertd@cs.man.ac.uk) * * MFM hard drive code [experimental] *//* * Change list: * *  3/2/96:DAG: Started a change list :-) *              Set the hardsect_size pointers up since we are running 256 byte *                sectors *              Added DMA code, put it into the rw_intr *              Moved RCAL out of generic interrupt code - don't want to do it *                while DMA'ing - its now in individual handlers. *              Took interrupt handlers off task queue lists and called *                directly - not sure of implications. * * 18/2/96:DAG: Well its reading OK I think, well enough for image file code *              to find the image file; but now I've discovered that I actually *              have to put some code in for image files. * *              Added stuff for image files; seems to work, but I've not *              got a multisegment image file (I don't think!). *              Put in a hack (yep a real hack) for multiple cylinder reads. *              Not convinced its working. * *  5/4/96:DAG: Added asm/hardware.h and use IOC_ macros *              Rewrote dma code in mfm.S (again!) - now takes a word at a time *              from main RAM for speed; still doesn't feel speedy! * * 20/4/96:DAG: After rewriting mfm.S a heck of a lot of times and speeding *              things up, I've finally figured out why its so damn slow. *              Linux is only reading a block at a time, and so you never *              get more than 1K per disc revoloution ~=60K/second. * * 27/4/96:DAG: On Russell's advice I change ll_rw_blk.c to ask it to *              join adjacent blocks together. Everything falls flat on its *              face. *              Four hours of debugging later; I hadn't realised that *              ll_rw_blk would be so generous as to join blocks whose *              results aren't going into consecutive buffers. *  *              OK; severe rehacking of mfm_rw_interrupt; now end_request's *              as soon as its DMA'd each request.  Odd thing is that *              we are sometimes getting interrupts where we are not transferring *              any data; why? Is that what happens when you miss? I doubt *              it; are we too fast? No - its just at command ends. Got 240K/s *              better than before, but RiscOS hits 480K/s * * 25/6/96:RMK: Fixed init code to allow the MFM podule to work.  Increased the *              number of errors for my Miniscribe drive (8425). * * 30/6/96:DAG: Russell suggested that a check drive 0 might turn the LEDs off *              - so in request_done just before it clears Busy it sends a *              check drive 0 - and the LEDs go off!!!! * *              Added test for mainboard controller. - Removes need for separate *              define. * * 13/7/96:DAG: Changed hardware sectore size to 512 in attempt to make *              IM drivers work. * 21/7/96:DAG: Took out old image file stuff (accessing it now produces an IO *              error.) * * 17/8/96:DAG: Ran through indent -kr -i8; evil - all my nice 2 character indents *              gone :-( Hand modified afterwards. *		Took out last remains of the older image map system. * * 22/9/96:DAG:	Changed mfm.S so it will carry on DMA'ing til; BSY is dropped *		Changed mfm_rw_intr so that it doesn't follow the error *		code until BSY is dropped. Nope - still broke. Problem *		may revolve around when it reads the results for the error *		number? * *16/11/96:DAG:	Modified for 2.0.18; request_irq changed * *17/12/96:RMK: Various cleanups, reorganisation, and the changes for new IO system. *		Improved probe for onboard MFM chip - it was hanging on my A5k. *		Added autodetect CHS code such that we don't rely on the presence *		of an ADFS boot block.  Added ioport resource manager calls so *		that we don't clash with already-running hardware (eg. RiscPC Ether *		card slots if someone tries this)! * * 17/1/97:RMK:	Upgraded to 2.1 kernels. * *  4/3/98:RMK:	Changed major number to 21. * * 27/6/98:RMK:	Changed asm/delay.h to linux/delay.h for mdelay(). *//* * Possible enhancements: *  Multi-thread the code so that it is possible that while one drive *  is seeking, the other one can be reading data/seeking as well. *  This would be a performance boost with dual drive systems. */#include <linux/module.h>#include <linux/config.h>#include <linux/sched.h>#include <linux/fs.h>#include <linux/interrupt.h>#include <linux/kernel.h>#include <linux/timer.h>#include <linux/tqueue.h>#include <linux/mm.h>#include <linux/errno.h>#include <linux/genhd.h>#include <linux/major.h>#include <linux/ioport.h>#include <linux/delay.h>#define MAJOR_NR	MFM_ACORN_MAJOR#include <linux/blk.h>#include <linux/blkpg.h>#include <asm/system.h>#include <asm/io.h>#include <asm/irq.h>#include <asm/uaccess.h>#include <asm/dma.h>#include <asm/hardware.h>#include <asm/ecard.h>#include <asm/hardware/ioc.h>/* * This sort of stuff should be in a header file shared with ide.c, hd.c, xd.c etc */#ifndef HDIO_GETGEO#define HDIO_GETGEO 0x301struct hd_geometry {	unsigned char heads;	unsigned char sectors;	unsigned short cylinders;	unsigned long start;};#endif/* * Configuration section * * This is the maximum number of drives that we accept */#define MFM_MAXDRIVES 2/* * Linux I/O address of onboard MFM controller or 0 to disable this */#define ONBOARD_MFM_ADDRESS ((0x002d0000 >> 2) | 0x80000000)/* * Uncomment this to enable debugging in the MFM driver... */#ifndef DEBUG/*#define DEBUG */#endif/* * List of card types that we recognise */static const card_ids mfm_cids[] = {	{ MANU_ACORN, PROD_ACORN_MFM },	{ 0xffff, 0xffff }};/* * End of configuration */ /* * This structure contains all information to do with a particular physical * device. */struct mfm_info {	unsigned char sectors;	unsigned char heads;	unsigned short cylinders;	unsigned short lowcurrent;	unsigned short precomp;#define NO_TRACK -1#define NEED_1_RECAL -2#define NEED_2_RECAL -3		 int cylinder;	unsigned int access_count;	unsigned int busy;	struct {		char recal;		char report;		char abort;	} errors;} mfm_info[MFM_MAXDRIVES];#define MFM_DRV_INFO mfm_info[raw_cmd.dev]static struct hd_struct mfm[MFM_MAXDRIVES << 6];static int mfm_sizes[MFM_MAXDRIVES << 6];static int mfm_blocksizes[MFM_MAXDRIVES << 6];static int mfm_sectsizes[MFM_MAXDRIVES << 6];static DECLARE_WAIT_QUEUE_HEAD(mfm_wait_open);/* Stuff from the assembly routines */extern unsigned int hdc63463_baseaddress;	/* Controller base address */extern unsigned int hdc63463_irqpolladdress;	/* Address to read to test for int */extern unsigned int hdc63463_irqpollmask;	/* Mask for irq register */extern unsigned int hdc63463_dataptr;	/* Pointer to kernel data space to DMA */extern int hdc63463_dataleft;	/* Number of bytes left to transfer */static int lastspecifieddrive;static unsigned Busy;static unsigned int PartFragRead;	/* The number of sectors which have been read					   during a partial read split over two					   cylinders.  If 0 it means a partial					   read did not occur. */static unsigned int PartFragRead_RestartBlock;	/* Where to restart on a split access */static unsigned int PartFragRead_SectorsLeft;	/* Where to restart on a split access */static int Sectors256LeftInCurrent;	/* i.e. 256 byte sectors left in current */static int SectorsLeftInRequest;	/* i.e. blocks left in the thing mfm_request was called for */static int Copy_Sector;		/* The 256 byte sector we are currently at - fragments need to know 				   where to take over */static char *Copy_buffer;static void mfm_seek(void);static void mfm_rerequest(void);static void mfm_request(void);static int mfm_reread_partitions(kdev_t dev);static void mfm_specify (void);static void issue_request(int dev, unsigned int block, unsigned int nsect,			  struct request *req);static unsigned int mfm_addr;		/* Controller address */static unsigned int mfm_IRQPollLoc;	/* Address to read for IRQ information */static unsigned int mfm_irqenable;	/* Podule IRQ enable location */static unsigned char mfm_irq;		/* Interrupt number */static int mfm_drives = 0;		/* drives available */static int mfm_status = 0;		/* interrupt status */static int *errors;static struct rawcmd {	unsigned int dev;	unsigned int cylinder;	unsigned int head;	unsigned int sector;	unsigned int cmdtype;	unsigned int cmdcode;	unsigned char cmddata[16];	unsigned int cmdlen;} raw_cmd;static unsigned char result[16];static struct cont {	void (*interrupt) (void);	/* interrupt handler */	void (*error) (void);	/* error handler */	void (*redo) (void);	/* redo handler */	void (*done) (int st);	/* done handler */} *cont = NULL;#if 0static struct tq_struct mfm_tq = {0, 0, (void (*)(void *)) NULL, 0};#endifint number_mfm_drives = 1;/* ------------------------------------------------------------------------------------------ *//* * From the HD63463 data sheet from Hitachi Ltd. */#define MFM_COMMAND (mfm_addr + 0)#define MFM_DATAOUT (mfm_addr + 1)#define MFM_STATUS  (mfm_addr + 8)#define MFM_DATAIN  (mfm_addr + 9)#define CMD_ABT		0xF0	/* Abort */#define CMD_SPC		0xE8	/* Specify */#define CMD_TST		0xE0	/* Test */#define CMD_RCLB	0xC8	/* Recalibrate */#define CMD_SEK		0xC0	/* Seek */#define CMD_WFS		0xAB	/* Write Format Skew */#define CMD_WFM		0xA3	/* Write Format */#define CMD_MTB		0x90	/* Memory to buffer */#define CMD_CMPD	0x88	/* Compare data */#define CMD_WD		0x87	/* Write data */#define CMD_RED		0x70	/* Read erroneous data */#define CMD_RIS		0x68	/* Read ID skew */#define CMD_FID		0x61	/* Find ID */#define CMD_RID		0x60	/* Read ID */#define CMD_BTM		0x50	/* Buffer to memory */#define CMD_CKD		0x48	/* Check data */#define CMD_RD		0x40	/* Read data */#define CMD_OPBW	0x38	/* Open buffer write */#define CMD_OPBR	0x30	/* Open buffer read */#define CMD_CKV		0x28	/* Check drive */#define CMD_CKE		0x20	/* Check ECC */#define CMD_POD		0x18	/* Polling disable */#define CMD_POL		0x10	/* Polling enable */#define CMD_RCAL	0x08	/* Recall */#define STAT_BSY	0x8000	/* Busy */#define STAT_CPR	0x4000	/* Command Parameter Rejection */#define STAT_CED	0x2000	/* Command end */#define STAT_SED	0x1000	/* Seek end */#define STAT_DER	0x0800	/* Drive error */#define STAT_ABN	0x0400	/* Abnormal end */#define STAT_POL	0x0200	/* Polling *//* ------------------------------------------------------------------------------------------ */#ifdef DEBUGstatic void console_printf(const char *fmt,...){	static char buffer[2048];	/* Arbitary! */	extern void console_print(const char *);	unsigned long flags;	va_list ap;	save_flags_cli(flags);	va_start(ap, fmt);	vsprintf(buffer, fmt, ap);	console_print(buffer);	va_end(fmt);	restore_flags(flags);};	/* console_printf */#define DBG(x...) console_printf(x)#else#define DBG(x...)#endifstatic void print_status(void){	char *error;	static char *errors[] = {         "no error",	 "command aborted",	 "invalid command",	 "parameter error",	 "not initialised",	 "rejected TEST",	 "no useld",	 "write fault",	 "not ready",	 "no scp",	 "in seek",	 "invalid NCA",	 "invalid step rate",	 "seek error",	 "over run",	 "invalid PHA",	 "data field EEC error",	 "data field CRC error",	 "error corrected",	 "data field fatal error",	 "no data am",	 "not hit",	 "ID field CRC error",	 "time over",	 "no ID am",	 "not writable"	};	if (result[1] < 0x65)		error = errors[result[1] >> 2];	else		error = "unknown";	printk("(");	if (mfm_status & STAT_BSY) printk("BSY ");	if (mfm_status & STAT_CPR) printk("CPR ");	if (mfm_status & STAT_CED) printk("CED ");	if (mfm_status & STAT_SED) printk("SED ");	if (mfm_status & STAT_DER) printk("DER ");	if (mfm_status & STAT_ABN) printk("ABN ");	if (mfm_status & STAT_POL) printk("POL ");	printk(") SSB = %X (%s)\n", result[1], error);}/* ------------------------------------------------------------------------------------- */static void issue_command(int command, unsigned char *cmdb, int len){	int status;#ifdef DEBUG	int i;	console_printf("issue_command: %02X: ", command);	for (i = 0; i < len; i++)		console_printf("%02X ", cmdb[i]);	console_printf("\n");#endif	do {		status = inw(MFM_STATUS);	} while (status & (STAT_BSY | STAT_POL));	DBG("issue_command: status after pol/bsy loop: %02X:\n ", status >> 8);	if (status & (STAT_CPR | STAT_CED | STAT_SED | STAT_DER | STAT_ABN)) {		outw(CMD_RCAL, MFM_COMMAND);		while (inw(MFM_STATUS) & STAT_BSY);	}	status = inw(MFM_STATUS);	DBG("issue_command: status before parameter issue: %02X:\n ", status >> 8);	while (len > 0) {		outw(cmdb[1] | (cmdb[0] << 8), MFM_DATAOUT);		len -= 2;		cmdb += 2;	}	status = inw(MFM_STATUS);	DBG("issue_command: status before command issue: %02X:\n ", status >> 8);	outw(command, MFM_COMMAND);	status = inw(MFM_STATUS);	DBG("issue_command: status immediatly after command issue: %02X:\n ", status >> 8);}static void wait_for_completion(void){	while ((mfm_status = inw(MFM_STATUS)) & STAT_BSY);}static void wait_for_command_end(void){	int i;	while (!((mfm_status = inw(MFM_STATUS)) & STAT_CED));	for (i = 0; i < 16;) {		int in;		in = inw(MFM_DATAIN);		result[i++] = in >> 8;		result[i++] = in;	}	outw (CMD_RCAL, MFM_COMMAND);}/* ------------------------------------------------------------------------------------- */static void mfm_rw_intr(void){	int old_status;		/* Holds status on entry, we read to see if the command just finished */#ifdef DEBUG	console_printf("mfm_rw_intr...dataleft=%d\n", hdc63463_dataleft);	print_status();#endif  /* Now don't handle the error until BSY drops */	if ((mfm_status & (STAT_DER | STAT_ABN)) && ((mfm_status&STAT_BSY)==0)) {		/* Something has gone wrong - let's try that again */		outw(CMD_RCAL, MFM_COMMAND);	/* Clear interrupt condition */		if (cont) {			DBG("mfm_rw_intr: DER/ABN err\n");			cont->error();			cont->redo();		};		return;	};	/* OK so what ever happend its not an error, now I reckon we are left between	   a choice of command end or some data which is ready to be collected */	/* I think we have to transfer data while the interrupt line is on and its	   not any other type of interrupt */	if (CURRENT->cmd == WRITE) {		extern void hdc63463_writedma(void);		if ((hdc63463_dataleft <= 0) && (!(mfm_status & STAT_CED))) {			printk("mfm_rw_intr: Apparent DMA write request when no more to DMA\n");			if (cont) {				cont->error();				cont->redo();			};			return;		};		hdc63463_writedma();	} else {		extern void hdc63463_readdma(void);		if ((hdc63463_dataleft <= 0) && (!(mfm_status & STAT_CED))) {			printk("mfm_rw_intr: Apparent DMA read request when no more to DMA\n");			if (cont) {				cont->error();				cont->redo();			};			return;		};		DBG("Going to try read dma..............status=0x%x, buffer=%p\n", mfm_status, hdc63463_dataptr);		hdc63463_readdma();	};			/* Read */	if (hdc63463_dataptr != ((unsigned int) Copy_buffer + 256)) {		/* If we didn't actually manage to get any data on this interrupt - but why? We got the interrupt */		/* Ah - well looking at the status its just when we get command end; so no problem */		/*console_printf("mfm: dataptr mismatch. dataptr=0x%08x Copy_buffer+256=0x%08p\n",		   hdc63463_dataptr,Copy_buffer+256);		   print_status(); */	} else {		Sectors256LeftInCurrent--;		Copy_buffer += 256;		Copy_Sector++;		/* We have come to the end of this request */		if (!Sectors256LeftInCurrent) {

⌨️ 快捷键说明

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