📄 xd.c
字号:
/* * This file contains the driver for an XT hard disk controller * (at least the DTC 5150X) for Linux. * * Author: Pat Mackinlay, pat@it.com.au * Date: 29/09/92 * * Revised: 01/01/93, ... * * Ref: DTC 5150X Controller Specification (thanks to Kevin Fowler, * kevinf@agora.rain.com) * Also thanks to: Salvador Abreu, Dave Thaler, Risto Kankkunen and * Wim Van Dorst. * * Revised: 04/04/94 by Risto Kankkunen * Moved the detection code from xd_init() to xd_geninit() as it needed * interrupts enabled and Linus didn't want to enable them in that first * phase. xd_geninit() is the place to do these kinds of things anyway, * he says. * * Modularized: 04/10/96 by Todd Fries, tfries@umr.edu * * Revised: 13/12/97 by Andrzej Krzysztofowicz, ankry@mif.pg.gda.pl * Fixed some problems with disk initialization and module initiation. * Added support for manual geometry setting (except Seagate controllers) * in form: * xd_geo=<cyl_xda>,<head_xda>,<sec_xda>[,<cyl_xdb>,<head_xdb>,<sec_xdb>] * Recovered DMA access. Abridged messages. Added support for DTC5051CX, * WD1002-27X & XEBEC controllers. Driver uses now some jumper settings. * Extended ioctl() support. * * Bugfix: 15/02/01, Paul G. - inform queue layer of tiny xd_maxsect. * */#include <linux/module.h>#include <linux/errno.h>#include <linux/interrupt.h>#include <linux/mm.h>#include <linux/fs.h>#include <linux/kernel.h>#include <linux/timer.h>#include <linux/genhd.h>#include <linux/hdreg.h>#include <linux/ioport.h>#include <linux/init.h>#include <linux/wait.h>#include <linux/blkdev.h>#include <linux/blkpg.h>#include <linux/delay.h>#include <asm/system.h>#include <asm/io.h>#include <asm/uaccess.h>#include <asm/dma.h>#include "xd.h"static void __init do_xd_setup (int *integers);#ifdef MODULEstatic int xd[5] = { -1,-1,-1,-1, };#endif#define XD_DONT_USE_DMA 0 /* Initial value. may be overriden using "nodma" module option */#define XD_INIT_DISK_DELAY (30) /* 30 ms delay during disk initialization *//* Above may need to be increased if a problem with the 2nd drive detection (ST11M controller) or resetting a controller (WD) appears */static XD_INFO xd_info[XD_MAXDRIVES];/* If you try this driver and find that your card is not detected by the driver at bootup, you need to add your BIOS signature and details to the following list of signatures. A BIOS signature is a string embedded into the first few bytes of your controller's on-board ROM BIOS. To find out what yours is, use something like MS-DOS's DEBUG command. Run DEBUG, and then you can examine your BIOS signature with: d xxxx:0000 where xxxx is the segment of your controller (like C800 or D000 or something). On the ASCII dump at the right, you should be able to see a string mentioning the manufacturer's copyright etc. Add this string into the table below. The parameters in the table are, in order: offset ; this is the offset (in bytes) from the start of your ROM where the signature starts signature ; this is the actual text of the signature xd_?_init_controller ; this is the controller init routine used by your controller xd_?_init_drive ; this is the drive init routine used by your controller The controllers directly supported at the moment are: DTC 5150x, WD 1004A27X, ST11M/R and override. If your controller is made by the same manufacturer as one of these, try using the same init routines as they do. If that doesn't work, your best bet is to use the "override" routines. These routines use a "portable" method of getting the disk's geometry, and may work with your card. If none of these seem to work, try sending me some email and I'll see what I can do <grin>. NOTE: You can now specify your XT controller's parameters from the command line in the form xd=TYPE,IRQ,IO,DMA. The driver should be able to detect your drive's geometry from this info. (eg: xd=0,5,0x320,3 is the "standard"). */#include <asm/page.h>#define xd_dma_mem_alloc(size) __get_dma_pages(GFP_KERNEL,get_order(size))#define xd_dma_mem_free(addr, size) free_pages(addr, get_order(size))static char *xd_dma_buffer;static XD_SIGNATURE xd_sigs[] __initdata = { { 0x0000,"Override geometry handler",NULL,xd_override_init_drive,"n unknown" }, /* Pat Mackinlay, pat@it.com.au */ { 0x0008,"[BXD06 (C) DTC 17-MAY-1985]",xd_dtc_init_controller,xd_dtc5150cx_init_drive," DTC 5150CX" }, /* Andrzej Krzysztofowicz, ankry@mif.pg.gda.pl */ { 0x000B,"CRD18A Not an IBM rom. (C) Copyright Data Technology Corp. 05/31/88",xd_dtc_init_controller,xd_dtc_init_drive," DTC 5150X" }, /* Todd Fries, tfries@umr.edu */ { 0x000B,"CXD23A Not an IBM ROM (C)Copyright Data Technology Corp 12/03/88",xd_dtc_init_controller,xd_dtc_init_drive," DTC 5150X" }, /* Pat Mackinlay, pat@it.com.au */ { 0x0008,"07/15/86(C) Copyright 1986 Western Digital Corp.",xd_wd_init_controller,xd_wd_init_drive," Western Dig. 1002-27X" }, /* Andrzej Krzysztofowicz, ankry@mif.pg.gda.pl */ { 0x0008,"06/24/88(C) Copyright 1988 Western Digital Corp.",xd_wd_init_controller,xd_wd_init_drive," Western Dig. WDXT-GEN2" }, /* Dan Newcombe, newcombe@aa.csc.peachnet.edu */ { 0x0015,"SEAGATE ST11 BIOS REVISION",xd_seagate_init_controller,xd_seagate_init_drive," Seagate ST11M/R" }, /* Salvador Abreu, spa@fct.unl.pt */ { 0x0010,"ST11R BIOS",xd_seagate_init_controller,xd_seagate_init_drive," Seagate ST11M/R" }, /* Risto Kankkunen, risto.kankkunen@cs.helsinki.fi */ { 0x0010,"ST11 BIOS v1.7",xd_seagate_init_controller,xd_seagate_init_drive," Seagate ST11R" }, /* Alan Hourihane, alanh@fairlite.demon.co.uk */ { 0x1000,"(c)Copyright 1987 SMS",xd_omti_init_controller,xd_omti_init_drive,"n OMTI 5520" }, /* Dirk Melchers, dirk@merlin.nbg.sub.org */ { 0x0006,"COPYRIGHT XEBEC (C) 1984",xd_xebec_init_controller,xd_xebec_init_drive," XEBEC" }, /* Andrzej Krzysztofowicz, ankry@mif.pg.gda.pl */ { 0x0008,"(C) Copyright 1984 Western Digital Corp", xd_wd_init_controller, xd_wd_init_drive," Western Dig. 1002s-wx2" }, { 0x0008,"(C) Copyright 1986 Western Digital Corporation", xd_wd_init_controller, xd_wd_init_drive," 1986 Western Digital" }, /* jfree@sovereign.org */};static unsigned int xd_bases[] __initdata ={ 0xC8000, 0xCA000, 0xCC000, 0xCE000, 0xD0000, 0xD2000, 0xD4000, 0xD6000, 0xD8000, 0xDA000, 0xDC000, 0xDE000, 0xE0000};static DEFINE_SPINLOCK(xd_lock);static struct gendisk *xd_gendisk[2];static struct block_device_operations xd_fops = { .owner = THIS_MODULE, .ioctl = xd_ioctl,};static DECLARE_WAIT_QUEUE_HEAD(xd_wait_int);static u_char xd_drives, xd_irq = 5, xd_dma = 3, xd_maxsectors;static u_char xd_override __initdata = 0, xd_type __initdata = 0;static u_short xd_iobase = 0x320;static int xd_geo[XD_MAXDRIVES*3] __initdata = { 0, };static volatile int xdc_busy;static struct timer_list xd_watchdog_int;static volatile u_char xd_error;static int nodma = XD_DONT_USE_DMA;static struct request_queue *xd_queue;/* xd_init: register the block device number and set up pointer tables */static int __init xd_init(void){ u_char i,controller; unsigned int address; int err;#ifdef MODULE { u_char count = 0; for (i = 4; i > 0; i--) if (((xd[i] = xd[i-1]) >= 0) && !count) count = i; if ((xd[0] = count)) do_xd_setup(xd); }#endif init_timer (&xd_watchdog_int); xd_watchdog_int.function = xd_watchdog; if (!xd_dma_buffer) xd_dma_buffer = (char *)xd_dma_mem_alloc(xd_maxsectors * 0x200); if (!xd_dma_buffer) { printk(KERN_ERR "xd: Out of memory.\n"); return -ENOMEM; } err = -EBUSY; if (register_blkdev(XT_DISK_MAJOR, "xd")) goto out1; err = -ENOMEM; xd_queue = blk_init_queue(do_xd_request, &xd_lock); if (!xd_queue) goto out1a; if (xd_detect(&controller,&address)) { printk("Detected a%s controller (type %d) at address %06x\n", xd_sigs[controller].name,controller,address); if (!request_region(xd_iobase,4,"xd")) { printk("xd: Ports at 0x%x are not available\n", xd_iobase); goto out2; } if (controller) xd_sigs[controller].init_controller(address); xd_drives = xd_initdrives(xd_sigs[controller].init_drive); printk("Detected %d hard drive%s (using IRQ%d & DMA%d)\n", xd_drives,xd_drives == 1 ? "" : "s",xd_irq,xd_dma); } err = -ENODEV; if (!xd_drives) goto out3; for (i = 0; i < xd_drives; i++) { XD_INFO *p = &xd_info[i]; struct gendisk *disk = alloc_disk(64); if (!disk) goto Enomem; p->unit = i; disk->major = XT_DISK_MAJOR; disk->first_minor = i<<6; sprintf(disk->disk_name, "xd%c", i+'a'); sprintf(disk->devfs_name, "xd/target%d", i); disk->fops = &xd_fops; disk->private_data = p; disk->queue = xd_queue; set_capacity(disk, p->heads * p->cylinders * p->sectors); printk(" %s: CHS=%d/%d/%d\n", disk->disk_name, p->cylinders, p->heads, p->sectors); xd_gendisk[i] = disk; } err = -EBUSY; if (request_irq(xd_irq,xd_interrupt_handler, 0, "XT hard disk", NULL)) { printk("xd: unable to get IRQ%d\n",xd_irq); goto out4; } if (request_dma(xd_dma,"xd")) { printk("xd: unable to get DMA%d\n",xd_dma); goto out5; } /* xd_maxsectors depends on controller - so set after detection */ blk_queue_max_sectors(xd_queue, xd_maxsectors); for (i = 0; i < xd_drives; i++) add_disk(xd_gendisk[i]); return 0;out5: free_irq(xd_irq, NULL);out4: for (i = 0; i < xd_drives; i++) put_disk(xd_gendisk[i]);out3: release_region(xd_iobase,4);out2: blk_cleanup_queue(xd_queue);out1a: unregister_blkdev(XT_DISK_MAJOR, "xd");out1: if (xd_dma_buffer) xd_dma_mem_free((unsigned long)xd_dma_buffer, xd_maxsectors * 0x200); return err;Enomem: err = -ENOMEM; while (i--) put_disk(xd_gendisk[i]); goto out3;}/* xd_detect: scan the possible BIOS ROM locations for the signature strings */static u_char __init xd_detect (u_char *controller, unsigned int *address){ int i, j; if (xd_override) { *controller = xd_type; *address = 0; return(1); } for (i = 0; i < (sizeof(xd_bases) / sizeof(xd_bases[0])); i++) { void __iomem *p = ioremap(xd_bases[i], 0x2000); if (!p) continue; for (j = 1; j < (sizeof(xd_sigs) / sizeof(xd_sigs[0])); j++) { const char *s = xd_sigs[j].string; if (check_signature(p + xd_sigs[j].offset, s, strlen(s))) { *controller = j; xd_type = j; *address = xd_bases[i]; iounmap(p); return 1; } } iounmap(p); } return 0;}/* do_xd_request: handle an incoming request */static void do_xd_request (request_queue_t * q){ struct request *req; if (xdc_busy) return; while ((req = elv_next_request(q)) != NULL) { unsigned block = req->sector; unsigned count = req->nr_sectors; int rw = rq_data_dir(req); XD_INFO *disk = req->rq_disk->private_data; int res = 0; int retry; if (!(req->flags & REQ_CMD)) { end_request(req, 0); continue; } if (block + count > get_capacity(req->rq_disk)) { end_request(req, 0); continue; } if (rw != READ && rw != WRITE) { printk("do_xd_request: unknown request\n"); end_request(req, 0); continue; } for (retry = 0; (retry < XD_RETRIES) && !res; retry++) res = xd_readwrite(rw, disk, req->buffer, block, count); end_request(req, res); /* wrap up, 0 = fail, 1 = success */ }}/* xd_ioctl: handle device ioctl's */static int xd_ioctl (struct inode *inode,struct file *file,u_int cmd,u_long arg){ XD_INFO *p = inode->i_bdev->bd_disk->private_data; switch (cmd) { case HDIO_GETGEO: { struct hd_geometry g; struct hd_geometry __user *geom= (void __user *)arg; g.heads = p->heads; g.sectors = p->sectors; g.cylinders = p->cylinders; g.start = get_start_sect(inode->i_bdev); return copy_to_user(geom, &g, sizeof(g)) ? -EFAULT : 0; } case HDIO_SET_DMA: if (!capable(CAP_SYS_ADMIN)) return -EACCES; if (xdc_busy) return -EBUSY; nodma = !arg; if (nodma && xd_dma_buffer) { xd_dma_mem_free((unsigned long)xd_dma_buffer, xd_maxsectors * 0x200); xd_dma_buffer = NULL; } else if (!nodma && !xd_dma_buffer) { xd_dma_buffer = (char *)xd_dma_mem_alloc(xd_maxsectors * 0x200); if (!xd_dma_buffer) { nodma = XD_DONT_USE_DMA; return -ENOMEM; } } return 0; case HDIO_GET_DMA: return put_user(!nodma, (long __user *) arg); case HDIO_GET_MULTCOUNT: return put_user(xd_maxsectors, (long __user *) arg); default: return -EINVAL;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -