pre-2.3.4..
[davej-history.git] / include / linux / ide.h
bloba06b9f0da4d3ded3c8508ec607c549ec0cbcadc0
1 #ifndef _IDE_H
2 #define _IDE_H
3 /*
4 * linux/drivers/block/ide.h
6 * Copyright (C) 1994-1998 Linus Torvalds & authors
7 */
9 #include <linux/config.h>
10 #include <linux/init.h>
11 #include <linux/ioport.h>
12 #include <linux/hdreg.h>
13 #include <linux/hdsmart.h>
14 #include <linux/blkdev.h>
15 #include <linux/proc_fs.h>
16 #include <asm/hdreg.h>
19 * This is the multiple IDE interface driver, as evolved from hd.c.
20 * It supports up to four IDE interfaces, on one or more IRQs (usually 14 & 15).
21 * There can be up to two drives per interface, as per the ATA-2 spec.
23 * Primary i/f: ide0: major=3; (hda) minor=0; (hdb) minor=64
24 * Secondary i/f: ide1: major=22; (hdc or hd1a) minor=0; (hdd or hd1b) minor=64
25 * Tertiary i/f: ide2: major=33; (hde) minor=0; (hdf) minor=64
26 * Quaternary i/f: ide3: major=34; (hdg) minor=0; (hdh) minor=64
29 /******************************************************************************
30 * IDE driver configuration options (play with these as desired):
32 * REALLY_SLOW_IO can be defined in ide.c and ide-cd.c, if necessary
34 #undef REALLY_FAST_IO /* define if ide ports are perfect */
35 #define INITIAL_MULT_COUNT 0 /* off=0; on=2,4,8,16,32, etc.. */
37 #ifndef SUPPORT_SLOW_DATA_PORTS /* 1 to support slow data ports */
38 #define SUPPORT_SLOW_DATA_PORTS 1 /* 0 to reduce kernel size */
39 #endif
40 #ifndef SUPPORT_VLB_SYNC /* 1 to support weird 32-bit chips */
41 #define SUPPORT_VLB_SYNC 1 /* 0 to reduce kernel size */
42 #endif
43 #ifndef DISK_RECOVERY_TIME /* off=0; on=access_delay_time */
44 #define DISK_RECOVERY_TIME 0 /* for hardware that needs it */
45 #endif
46 #ifndef OK_TO_RESET_CONTROLLER /* 1 needed for good error recovery */
47 #define OK_TO_RESET_CONTROLLER 1 /* 0 for use with AH2372A/B interface */
48 #endif
49 #ifndef FAKE_FDISK_FOR_EZDRIVE /* 1 to help linux fdisk with EZDRIVE */
50 #define FAKE_FDISK_FOR_EZDRIVE 1 /* 0 to reduce kernel size */
51 #endif
52 #ifndef FANCY_STATUS_DUMPS /* 1 for human-readable drive errors */
53 #define FANCY_STATUS_DUMPS 1 /* 0 to reduce kernel size */
54 #endif
56 #ifdef CONFIG_BLK_DEV_CMD640
57 #if 0 /* change to 1 when debugging cmd640 problems */
58 void cmd640_dump_regs (void);
59 #define CMD640_DUMP_REGS cmd640_dump_regs() /* for debugging cmd640 chipset */
60 #endif
61 #endif /* CONFIG_BLK_DEV_CMD640 */
64 * IDE_DRIVE_CMD is used to implement many features of the hdparm utility
66 #define IDE_DRIVE_CMD 99 /* (magic) undef to reduce kernel size*/
69 * "No user-serviceable parts" beyond this point :)
70 *****************************************************************************/
72 typedef unsigned char byte; /* used everywhere */
75 * Probably not wise to fiddle with these
77 #define ERROR_MAX 8 /* Max read/write errors per sector */
78 #define ERROR_RESET 3 /* Reset controller every 4th retry */
79 #define ERROR_RECAL 1 /* Recalibrate every 2nd retry */
82 * Ensure that various configuration flags have compatible settings
84 #ifdef REALLY_SLOW_IO
85 #undef REALLY_FAST_IO
86 #endif
88 #define HWIF(drive) ((ide_hwif_t *)((drive)->hwif))
89 #define HWGROUP(drive) ((ide_hwgroup_t *)(HWIF(drive)->hwgroup))
92 * Definitions for accessing IDE controller registers
94 #define IDE_NR_PORTS (10)
96 #define IDE_DATA_OFFSET (0)
97 #define IDE_ERROR_OFFSET (1)
98 #define IDE_NSECTOR_OFFSET (2)
99 #define IDE_SECTOR_OFFSET (3)
100 #define IDE_LCYL_OFFSET (4)
101 #define IDE_HCYL_OFFSET (5)
102 #define IDE_SELECT_OFFSET (6)
103 #define IDE_STATUS_OFFSET (7)
104 #define IDE_CONTROL_OFFSET (8)
105 #define IDE_IRQ_OFFSET (9)
107 #define IDE_FEATURE_OFFSET IDE_ERROR_OFFSET
108 #define IDE_COMMAND_OFFSET IDE_STATUS_OFFSET
110 #define IDE_DATA_REG (HWIF(drive)->io_ports[IDE_DATA_OFFSET])
111 #define IDE_ERROR_REG (HWIF(drive)->io_ports[IDE_ERROR_OFFSET])
112 #define IDE_NSECTOR_REG (HWIF(drive)->io_ports[IDE_NSECTOR_OFFSET])
113 #define IDE_SECTOR_REG (HWIF(drive)->io_ports[IDE_SECTOR_OFFSET])
114 #define IDE_LCYL_REG (HWIF(drive)->io_ports[IDE_LCYL_OFFSET])
115 #define IDE_HCYL_REG (HWIF(drive)->io_ports[IDE_HCYL_OFFSET])
116 #define IDE_SELECT_REG (HWIF(drive)->io_ports[IDE_SELECT_OFFSET])
117 #define IDE_STATUS_REG (HWIF(drive)->io_ports[IDE_STATUS_OFFSET])
118 #define IDE_CONTROL_REG (HWIF(drive)->io_ports[IDE_CONTROL_OFFSET])
119 #define IDE_IRQ_REG (HWIF(drive)->io_ports[IDE_IRQ_OFFSET])
121 #define IDE_FEATURE_REG IDE_ERROR_REG
122 #define IDE_COMMAND_REG IDE_STATUS_REG
123 #define IDE_ALTSTATUS_REG IDE_CONTROL_REG
124 #define IDE_IREASON_REG IDE_NSECTOR_REG
125 #define IDE_BCOUNTL_REG IDE_LCYL_REG
126 #define IDE_BCOUNTH_REG IDE_HCYL_REG
128 #ifdef REALLY_FAST_IO
129 #define OUT_BYTE(b,p) outb((b),(p))
130 #define IN_BYTE(p) (byte)inb(p)
131 #else
132 #define OUT_BYTE(b,p) outb_p((b),(p))
133 #define IN_BYTE(p) (byte)inb_p(p)
134 #endif /* REALLY_FAST_IO */
136 #define GET_ERR() IN_BYTE(IDE_ERROR_REG)
137 #define GET_STAT() IN_BYTE(IDE_STATUS_REG)
138 #define OK_STAT(stat,good,bad) (((stat)&((good)|(bad)))==(good))
139 #define BAD_R_STAT (BUSY_STAT | ERR_STAT)
140 #define BAD_W_STAT (BAD_R_STAT | WRERR_STAT)
141 #define BAD_STAT (BAD_R_STAT | DRQ_STAT)
142 #define DRIVE_READY (READY_STAT | SEEK_STAT)
143 #define DATA_READY (DRQ_STAT)
146 * Some more useful definitions
148 #define IDE_MAJOR_NAME "ide" /* the same for all i/f; see also genhd.c */
149 #define MAJOR_NAME IDE_MAJOR_NAME
150 #define PARTN_BITS 6 /* number of minor dev bits for partitions */
151 #define PARTN_MASK ((1<<PARTN_BITS)-1) /* a useful bit mask */
152 #define MAX_DRIVES 2 /* per interface; 2 assumed by lots of code */
153 #define SECTOR_WORDS (512 / 4) /* number of 32bit words per sector */
154 #define IDE_LARGE_SEEK(b1,b2,t) (((b1) > (b2) + (t)) || ((b2) > (b1) + (t)))
155 #define IDE_MIN(a,b) ((a)<(b) ? (a):(b))
156 #define IDE_MAX(a,b) ((a)>(b) ? (a):(b))
159 * Timeouts for various operations:
161 #define WAIT_DRQ (5*HZ/100) /* 50msec - spec allows up to 20ms */
162 #ifdef CONFIG_APM
163 #define WAIT_READY (5*HZ) /* 5sec - some laptops are very slow */
164 #else
165 #define WAIT_READY (3*HZ/100) /* 30msec - should be instantaneous */
166 #endif /* CONFIG_APM */
167 #define WAIT_PIDENTIFY (10*HZ) /* 10sec - should be less than 3ms (?)
168 if all ATAPI CD is closed at boot */
169 #define WAIT_WORSTCASE (30*HZ) /* 30sec - worst case when spinning up */
170 #define WAIT_CMD (10*HZ) /* 10sec - maximum wait for an IRQ to happen */
171 #define WAIT_MIN_SLEEP (2*HZ/100) /* 20msec - minimum sleep time */
173 #define SELECT_DRIVE(hwif,drive) \
175 if (hwif->selectproc) \
176 hwif->selectproc(drive); \
177 OUT_BYTE((drive)->select.all, hwif->io_ports[IDE_SELECT_OFFSET]); \
181 * Check for an interrupt and acknowledge the interrupt status
183 struct hwif_s;
184 typedef int (ide_ack_intr_t)(struct hwif_s *);
187 * Structure to hold all information about the location of this port
189 typedef struct hw_regs_s {
190 ide_ioreg_t io_ports[IDE_NR_PORTS]; /* task file registers */
191 int irq; /* our irq number */
192 ide_ack_intr_t *ack_intr; /* acknowledge interrupt */
193 void *priv; /* interface specific data */
194 } hw_regs_t;
197 * Register new hardware with ide
199 int ide_register_hw(hw_regs_t *hw, struct hwif_s **hwifp);
202 * Set up hw_regs_t structure before calling ide_register_hw (optional)
204 void ide_setup_ports( hw_regs_t *hw,
205 ide_ioreg_t base,
206 int *offsets,
207 ide_ioreg_t ctrl,
208 ide_ioreg_t intr,
209 ide_ack_intr_t *ack_intr,
210 int irq);
212 #include <asm/ide.h>
215 * Now for the data we need to maintain per-drive: ide_drive_t
218 #define ide_scsi 0x21
219 #define ide_disk 0x20
220 #define ide_optical 0x7
221 #define ide_cdrom 0x5
222 #define ide_tape 0x1
223 #define ide_floppy 0x0
225 typedef union {
226 unsigned all : 8; /* all of the bits together */
227 struct {
228 unsigned set_geometry : 1; /* respecify drive geometry */
229 unsigned recalibrate : 1; /* seek to cyl 0 */
230 unsigned set_multmode : 1; /* set multmode count */
231 unsigned set_tune : 1; /* tune interface for drive */
232 unsigned reserved : 4; /* unused */
233 } b;
234 } special_t;
236 typedef struct ide_drive_s {
237 struct request *queue; /* request queue */
238 struct ide_drive_s *next; /* circular list of hwgroup drives */
239 unsigned long sleep; /* sleep until this time */
240 unsigned long service_start; /* time we started last request */
241 unsigned long service_time; /* service time of last request */
242 special_t special; /* special action flags */
243 byte keep_settings; /* restore settings after drive reset */
244 byte using_dma; /* disk is using dma for read/write */
245 byte waiting_for_dma; /* dma currently in progress */
246 byte unmask; /* flag: okay to unmask other irqs */
247 byte slow; /* flag: slow data port */
248 byte bswap; /* flag: byte swap data */
249 byte dsc_overlap; /* flag: DSC overlap */
250 byte nice1; /* flag: give potential excess bandwidth */
251 unsigned present : 1; /* drive is physically present */
252 unsigned noprobe : 1; /* from: hdx=noprobe */
253 unsigned busy : 1; /* currently doing revalidate_disk() */
254 unsigned removable : 1; /* 1 if need to do check_media_change */
255 unsigned forced_geom : 1; /* 1 if hdx=c,h,s was given at boot */
256 unsigned no_unmask : 1; /* disallow setting unmask bit */
257 unsigned no_io_32bit : 1; /* disallow enabling 32bit I/O */
258 unsigned nobios : 1; /* flag: do not probe bios for drive */
259 unsigned revalidate : 1; /* request revalidation */
260 unsigned atapi_overlap : 1; /* flag: ATAPI overlap (not supported) */
261 unsigned nice0 : 1; /* flag: give obvious excess bandwidth */
262 unsigned nice2 : 1; /* flag: give a share in our own bandwidth */
263 unsigned doorlocking : 1; /* flag: for removable only: door lock/unlock works */
264 unsigned autotune : 2; /* 1=autotune, 2=noautotune, 0=default */
265 #if FAKE_FDISK_FOR_EZDRIVE
266 unsigned remap_0_to_1 : 1; /* flag: partitioned with ezdrive */
267 #endif /* FAKE_FDISK_FOR_EZDRIVE */
268 byte media; /* disk, cdrom, tape, floppy, ... */
269 select_t select; /* basic drive/head select reg value */
270 byte ctl; /* "normal" value for IDE_CONTROL_REG */
271 byte ready_stat; /* min status value for drive ready */
272 byte mult_count; /* current multiple sector setting */
273 byte mult_req; /* requested multiple sector setting */
274 byte tune_req; /* requested drive tuning setting */
275 byte io_32bit; /* 0=16-bit, 1=32-bit, 2/3=32bit+sync */
276 byte bad_wstat; /* used for ignoring WRERR_STAT */
277 byte nowerr; /* used for ignoring WRERR_STAT */
278 byte sect0; /* offset of first sector for DM6:DDO */
279 byte usage; /* current "open()" count for drive */
280 byte head; /* "real" number of heads */
281 byte sect; /* "real" sectors per track */
282 byte bios_head; /* BIOS/fdisk/LILO number of heads */
283 byte bios_sect; /* BIOS/fdisk/LILO sectors per track */
284 unsigned short bios_cyl; /* BIOS/fdisk/LILO number of cyls */
285 unsigned short cyl; /* "real" number of cyls */
286 unsigned int drive_data; /* for use by tuneproc/selectproc as needed */
287 void *hwif; /* actually (ide_hwif_t *) */
288 wait_queue_head_t wqueue; /* used to wait for drive in open() */
289 struct hd_driveid *id; /* drive model identification info */
290 struct hd_struct *part; /* drive partition table */
291 char name[4]; /* drive name, such as "hda" */
292 void *driver; /* (ide_driver_t *) */
293 void *driver_data; /* extra driver data */
294 struct proc_dir_entry *proc; /* /proc/ide/ directory entry */
295 void *settings; /* /proc/ide/ drive settings */
296 char driver_req[10]; /* requests specific driver */
297 #if 1
298 struct thresholds_s *smart_thresholds;
299 struct values_s *smart_values;
300 #else
301 thresholds_t smart_thresholds;
302 values_t smart_values;
303 #endif
304 } ide_drive_t;
307 * An ide_dmaproc_t() initiates/aborts DMA read/write operations on a drive.
309 * The caller is assumed to have selected the drive and programmed the drive's
310 * sector address using CHS or LBA. All that remains is to prepare for DMA
311 * and then issue the actual read/write DMA/PIO command to the drive.
313 * Returns 0 if all went well.
314 * Returns 1 if DMA read/write could not be started, in which case the caller
315 * should either try again later, or revert to PIO for the current request.
317 typedef enum { ide_dma_read, ide_dma_write, ide_dma_begin,
318 ide_dma_end, ide_dma_check, ide_dma_on,
319 ide_dma_off, ide_dma_off_quietly, ide_dma_test_irq,
320 ide_dma_bad_drive, ide_dma_good_drive
321 } ide_dma_action_t;
323 typedef int (ide_dmaproc_t)(ide_dma_action_t, ide_drive_t *);
327 * An ide_tuneproc_t() is used to set the speed of an IDE interface
328 * to a particular PIO mode. The "byte" parameter is used
329 * to select the PIO mode by number (0,1,2,3,4,5), and a value of 255
330 * indicates that the interface driver should "auto-tune" the PIO mode
331 * according to the drive capabilities in drive->id;
333 * Not all interface types support tuning, and not all of those
334 * support all possible PIO settings. They may silently ignore
335 * or round values as they see fit.
337 typedef void (ide_tuneproc_t)(ide_drive_t *, byte);
340 * This is used to provide support for strange interfaces
342 typedef void (ide_selectproc_t) (ide_drive_t *);
345 * hwif_chipset_t is used to keep track of the specific hardware
346 * chipset used by each IDE interface, if known.
348 typedef enum { ide_unknown, ide_generic, ide_pci,
349 ide_cmd640, ide_dtc2278, ide_ali14xx,
350 ide_qd6580, ide_umc8672, ide_ht6560b,
351 ide_pdc4030, ide_rz1000, ide_trm290,
352 ide_cmd646, ide_cy82c693, ide_4drives
353 } hwif_chipset_t;
355 typedef struct ide_pci_devid_s {
356 unsigned short vid;
357 unsigned short did;
358 } ide_pci_devid_t;
360 #define IDE_PCI_DEVID_NULL ((ide_pci_devid_t){0,0})
361 #define IDE_PCI_DEVID_EQ(a,b) (a.vid == b.vid && a.did == b.did)
363 typedef struct hwif_s {
364 struct hwif_s *next; /* for linked-list in ide_hwgroup_t */
365 void *hwgroup; /* actually (ide_hwgroup_t *) */
366 ide_ioreg_t io_ports[IDE_NR_PORTS]; /* task file registers */
367 hw_regs_t hw; /* Hardware info */
368 ide_drive_t drives[MAX_DRIVES]; /* drive info */
369 struct gendisk *gd; /* gendisk structure */
370 ide_tuneproc_t *tuneproc; /* routine to tune PIO mode for drives */
371 ide_selectproc_t *selectproc; /* tweaks hardware to select drive */
372 ide_dmaproc_t *dmaproc; /* dma read/write/abort routine */
373 unsigned long *dmatable; /* dma physical region descriptor table */
374 struct hwif_s *mate; /* other hwif from same PCI chip */
375 unsigned long dma_base; /* base addr for dma ports */
376 unsigned dma_extra; /* extra addr for dma ports */
377 unsigned long config_data; /* for use by chipset-specific code */
378 unsigned long select_data; /* for use by chipset-specific code */
379 struct proc_dir_entry *proc; /* /proc/ide/ directory entry */
380 int irq; /* our irq number */
381 byte major; /* our major number */
382 char name[6]; /* name of interface, eg. "ide0" */
383 byte index; /* 0 for ide0; 1 for ide1; ... */
384 hwif_chipset_t chipset; /* sub-module for tuning.. */
385 unsigned noprobe : 1; /* don't probe for this interface */
386 unsigned present : 1; /* this interface exists */
387 unsigned serialized : 1; /* serialized operation with mate hwif */
388 unsigned sharing_irq: 1; /* 1 = sharing irq with another hwif */
389 unsigned reset : 1; /* reset after probe */
390 unsigned autodma : 1; /* automatically try to enable DMA at boot */
391 byte channel; /* for dual-port chips: 0=primary, 1=secondary */
392 struct pci_dev *pci_dev; /* for pci chipsets */
393 ide_pci_devid_t pci_devid; /* for pci chipsets: {VID,DID} */
394 #if (DISK_RECOVERY_TIME > 0)
395 unsigned long last_time; /* time when previous rq was done */
396 #endif
397 } ide_hwif_t;
400 * internal ide interrupt handler type
402 typedef void (ide_handler_t)(ide_drive_t *);
404 typedef struct hwgroup_s {
405 spinlock_t spinlock; /* protects "busy" and "handler" */
406 ide_handler_t *handler;/* irq handler, if active */
407 int busy; /* BOOL: protects all fields below */
408 ide_drive_t *drive; /* current drive */
409 ide_hwif_t *hwif; /* ptr to current hwif in linked-list */
410 struct request *rq; /* current request */
411 struct timer_list timer; /* failsafe timer */
412 struct request wrq; /* local copy of current write rq */
413 unsigned long poll_timeout; /* timeout value during long polls */
414 } ide_hwgroup_t;
417 * configurable drive settings
420 #define TYPE_INT 0
421 #define TYPE_INTA 1
422 #define TYPE_BYTE 2
423 #define TYPE_SHORT 3
425 #define SETTING_READ (1 << 0)
426 #define SETTING_WRITE (1 << 1)
427 #define SETTING_RW (SETTING_READ | SETTING_WRITE)
429 typedef int (ide_procset_t)(ide_drive_t *, int);
430 typedef struct ide_settings_s {
431 char *name;
432 int rw;
433 int read_ioctl;
434 int write_ioctl;
435 int data_type;
436 int min;
437 int max;
438 int mul_factor;
439 int div_factor;
440 void *data;
441 ide_procset_t *set;
442 int auto_remove;
443 struct ide_settings_s *next;
444 } ide_settings_t;
446 void ide_add_setting(ide_drive_t *drive, const char *name, int rw, int read_ioctl, int write_ioctl, int data_type, int min, int max, int mul_factor, int div_factor, void *data, ide_procset_t *set);
447 void ide_remove_setting(ide_drive_t *drive, char *name);
448 ide_settings_t *ide_find_setting_by_name(ide_drive_t *drive, char *name);
449 int ide_read_setting(ide_drive_t *t, ide_settings_t *setting);
450 int ide_write_setting(ide_drive_t *drive, ide_settings_t *setting, int val);
451 void ide_add_generic_settings(ide_drive_t *drive);
454 * /proc/ide interface
456 typedef struct {
457 const char *name;
458 mode_t mode;
459 read_proc_t *read_proc;
460 write_proc_t *write_proc;
461 } ide_proc_entry_t;
463 #ifdef CONFIG_PROC_FS
464 void proc_ide_create(void);
465 void proc_ide_destroy(void);
466 void ide_add_proc_entries(struct proc_dir_entry *dir, ide_proc_entry_t *p, void *data);
467 void ide_remove_proc_entries(struct proc_dir_entry *dir, ide_proc_entry_t *p);
468 read_proc_t proc_ide_read_capacity;
469 read_proc_t proc_ide_read_geometry;
472 * Standard exit stuff:
474 #define PROC_IDE_READ_RETURN(page,start,off,count,eof,len) \
476 len -= off; \
477 if (len < count) { \
478 *eof = 1; \
479 if (len <= 0) \
480 return 0; \
481 } else \
482 len = count; \
483 *start = page + off; \
484 return len; \
486 #else
487 #define PROC_IDE_READ_RETURN(page,start,off,count,eof,len) return 0;
488 #endif
491 * Subdrivers support.
493 #define IDE_SUBDRIVER_VERSION 1
495 typedef int (ide_cleanup_proc)(ide_drive_t *);
496 typedef void (ide_do_request_proc)(ide_drive_t *, struct request *, unsigned long);
497 typedef void (ide_end_request_proc)(byte, ide_hwgroup_t *);
498 typedef int (ide_ioctl_proc)(ide_drive_t *, struct inode *, struct file *, unsigned int, unsigned long);
499 typedef int (ide_open_proc)(struct inode *, struct file *, ide_drive_t *);
500 typedef void (ide_release_proc)(struct inode *, struct file *, ide_drive_t *);
501 typedef int (ide_check_media_change_proc)(ide_drive_t *);
502 typedef void (ide_pre_reset_proc)(ide_drive_t *);
503 typedef unsigned long (ide_capacity_proc)(ide_drive_t *);
504 typedef void (ide_special_proc)(ide_drive_t *);
505 typedef void (ide_setting_proc)(ide_drive_t *);
507 typedef struct ide_driver_s {
508 const char *name;
509 const char *version;
510 byte media;
511 unsigned busy : 1;
512 unsigned supports_dma : 1;
513 unsigned supports_dsc_overlap : 1;
514 ide_cleanup_proc *cleanup;
515 ide_do_request_proc *do_request;
516 ide_end_request_proc *end_request;
517 ide_ioctl_proc *ioctl;
518 ide_open_proc *open;
519 ide_release_proc *release;
520 ide_check_media_change_proc *media_change;
521 ide_pre_reset_proc *pre_reset;
522 ide_capacity_proc *capacity;
523 ide_special_proc *special;
524 ide_proc_entry_t *proc;
525 } ide_driver_t;
527 #define DRIVER(drive) ((ide_driver_t *)((drive)->driver))
530 * IDE modules.
532 #define IDE_CHIPSET_MODULE 0 /* not supported yet */
533 #define IDE_PROBE_MODULE 1
534 #define IDE_DRIVER_MODULE 2
536 typedef int (ide_module_init_proc)(void);
538 typedef struct ide_module_s {
539 int type;
540 ide_module_init_proc *init;
541 void *info;
542 struct ide_module_s *next;
543 } ide_module_t;
546 * ide_hwifs[] is the master data structure used to keep track
547 * of just about everything in ide.c. Whenever possible, routines
548 * should be using pointers to a drive (ide_drive_t *) or
549 * pointers to a hwif (ide_hwif_t *), rather than indexing this
550 * structure directly (the allocation/layout may change!).
553 #ifndef _IDE_C
554 extern ide_hwif_t ide_hwifs[]; /* master data repository */
555 extern ide_module_t *ide_modules;
556 #endif
559 * We need blk.h, but we replace its end_request by our own version.
561 #define IDE_DRIVER /* Toggle some magic bits in blk.h */
562 #define LOCAL_END_REQUEST /* Don't generate end_request in blk.h */
563 #include <linux/blk.h>
565 void ide_end_request(byte uptodate, ide_hwgroup_t *hwgroup);
568 * This is used for (nearly) all data transfers from/to the IDE interface
570 void ide_input_data (ide_drive_t *drive, void *buffer, unsigned int wcount);
571 void ide_output_data (ide_drive_t *drive, void *buffer, unsigned int wcount);
574 * This is used for (nearly) all ATAPI data transfers from/to the IDE interface
576 void atapi_input_bytes (ide_drive_t *drive, void *buffer, unsigned int bytecount);
577 void atapi_output_bytes (ide_drive_t *drive, void *buffer, unsigned int bytecount);
580 * This is used on exit from the driver, to designate the next irq handler
581 * and also to start the safety timer.
583 void ide_set_handler (ide_drive_t *drive, ide_handler_t *handler, unsigned int timeout);
586 * Error reporting, in human readable form (luxurious, but a memory hog).
588 byte ide_dump_status (ide_drive_t *drive, const char *msg, byte stat);
591 * ide_error() takes action based on the error returned by the controller.
592 * The calling function must return afterwards, to restart the request.
594 void ide_error (ide_drive_t *drive, const char *msg, byte stat);
597 * Issue a simple drive command
598 * The drive must be selected beforehand.
600 void ide_cmd(ide_drive_t *drive, byte cmd, byte nsect, ide_handler_t *handler);
603 * ide_fixstring() cleans up and (optionally) byte-swaps a text string,
604 * removing leading/trailing blanks and compressing internal blanks.
605 * It is primarily used to tidy up the model name/number fields as
606 * returned by the WIN_[P]IDENTIFY commands.
608 void ide_fixstring (byte *s, const int bytecount, const int byteswap);
611 * This routine busy-waits for the drive status to be not "busy".
612 * It then checks the status for all of the "good" bits and none
613 * of the "bad" bits, and if all is okay it returns 0. All other
614 * cases return 1 after invoking ide_error() -- caller should return.
617 int ide_wait_stat (ide_drive_t *drive, byte good, byte bad, unsigned long timeout);
620 * This routine is called from the partition-table code in genhd.c
621 * to "convert" a drive to a logical geometry with fewer than 1024 cyls.
623 * The second parameter, "xparm", determines exactly how the translation
624 * will be handled:
625 * 0 = convert to CHS with fewer than 1024 cyls
626 * using the same method as Ontrack DiskManager.
627 * 1 = same as "0", plus offset everything by 63 sectors.
628 * -1 = similar to "0", plus redirect sector 0 to sector 1.
629 * >1 = convert to a CHS geometry with "xparm" heads.
631 * Returns 0 if the translation was not possible, if the device was not
632 * an IDE disk drive, or if a geometry was "forced" on the commandline.
633 * Returns 1 if the geometry translation was successful.
635 int ide_xlate_1024 (kdev_t, int, const char *);
638 * Start a reset operation for an IDE interface.
639 * The caller should return immediately after invoking this.
641 void ide_do_reset (ide_drive_t *);
644 * This function is intended to be used prior to invoking ide_do_drive_cmd().
646 void ide_init_drive_cmd (struct request *rq);
649 * "action" parameter type for ide_do_drive_cmd() below.
651 typedef enum
652 {ide_wait, /* insert rq at end of list, and wait for it */
653 ide_next, /* insert rq immediately after current request */
654 ide_preempt, /* insert rq in front of current request */
655 ide_end} /* insert rq at end of list, but don't wait for it */
656 ide_action_t;
659 * This function issues a special IDE device request
660 * onto the request queue.
662 * If action is ide_wait, then the rq is queued at the end of the
663 * request queue, and the function sleeps until it has been processed.
664 * This is for use when invoked from an ioctl handler.
666 * If action is ide_preempt, then the rq is queued at the head of
667 * the request queue, displacing the currently-being-processed
668 * request and this function returns immediately without waiting
669 * for the new rq to be completed. This is VERY DANGEROUS, and is
670 * intended for careful use by the ATAPI tape/cdrom driver code.
672 * If action is ide_next, then the rq is queued immediately after
673 * the currently-being-processed-request (if any), and the function
674 * returns without waiting for the new rq to be completed. As above,
675 * This is VERY DANGEROUS, and is intended for careful use by the
676 * ATAPI tape/cdrom driver code.
678 * If action is ide_end, then the rq is queued at the end of the
679 * request queue, and the function returns immediately without waiting
680 * for the new rq to be completed. This is again intended for careful
681 * use by the ATAPI tape/cdrom driver code.
683 int ide_do_drive_cmd (ide_drive_t *drive, struct request *rq, ide_action_t action);
686 * Clean up after success/failure of an explicit drive cmd.
687 * stat/err are used only when (HWGROUP(drive)->rq->cmd == IDE_DRIVE_CMD).
689 void ide_end_drive_cmd (ide_drive_t *drive, byte stat, byte err);
692 * Issue ATA command and wait for completion.
694 int ide_wait_cmd (ide_drive_t *drive, int cmd, int nsect, int feature, int sectors, byte *buf);
696 void ide_delay_50ms (void);
699 * ide_system_bus_speed() returns what we think is the system VESA/PCI
700 * bus speed (in MHz). This is used for calculating interface PIO timings.
701 * The default is 40 for known PCI systems, 50 otherwise.
702 * The "idebus=xx" parameter can be used to override this value.
704 int ide_system_bus_speed (void);
707 * ide_multwrite() transfers a block of up to mcount sectors of data
708 * to a drive as part of a disk multwrite operation.
710 void ide_multwrite (ide_drive_t *drive, unsigned int mcount);
713 * ide_stall_queue() can be used by a drive to give excess bandwidth back
714 * to the hwgroup by sleeping for timeout jiffies.
716 void ide_stall_queue (ide_drive_t *drive, unsigned long timeout);
719 * ide_get_queue() returns the queue which corresponds to a given device.
721 struct request **ide_get_queue (kdev_t dev);
724 * CompactFlash cards and their brethern pretend to be removable hard disks,
725 * but they never have a slave unit, and they don't have doorlock mechanisms.
726 * This test catches them, and is invoked elsewhere when setting appropriate config bits.
728 int drive_is_flashcard (ide_drive_t *drive);
730 int ide_spin_wait_hwgroup(ide_drive_t *drive, unsigned long *flags);
731 void ide_timer_expiry (unsigned long data);
732 void ide_intr (int irq, void *dev_id, struct pt_regs *regs);
733 void ide_geninit (struct gendisk *gd);
734 void do_ide0_request (void);
735 #if MAX_HWIFS > 1
736 void do_ide1_request (void);
737 #endif
738 #if MAX_HWIFS > 2
739 void do_ide2_request (void);
740 #endif
741 #if MAX_HWIFS > 3
742 void do_ide3_request (void);
743 #endif
744 #if MAX_HWIFS > 4
745 void do_ide4_request (void);
746 #endif
747 #if MAX_HWIFS > 5
748 void do_ide5_request (void);
749 #endif
750 #if MAX_HWIFS > 6
751 void do_ide6_request (void);
752 #endif
753 #if MAX_HWIFS > 7
754 void do_ide7_request (void);
755 #endif
756 void ide_init_subdrivers (void);
758 #ifndef _IDE_C
759 extern struct file_operations ide_fops[];
760 #endif
762 #ifdef _IDE_C
763 #ifdef CONFIG_BLK_DEV_IDE
764 int ideprobe_init (void);
765 #endif /* CONFIG_BLK_DEV_IDE */
766 #ifdef CONFIG_BLK_DEV_IDEDISK
767 int idedisk_init (void);
768 #endif /* CONFIG_BLK_DEV_IDEDISK */
769 #ifdef CONFIG_BLK_DEV_IDECD
770 int ide_cdrom_init (void);
771 #endif /* CONFIG_BLK_DEV_IDECD */
772 #ifdef CONFIG_BLK_DEV_IDETAPE
773 int idetape_init (void);
774 #endif /* CONFIG_BLK_DEV_IDETAPE */
775 #ifdef CONFIG_BLK_DEV_IDEFLOPPY
776 int idefloppy_init (void);
777 #endif /* CONFIG_BLK_DEV_IDEFLOPPY */
778 #ifdef CONFIG_BLK_DEV_IDESCSI
779 int idescsi_init (void);
780 #endif /* CONFIG_BLK_DEV_IDESCSI */
781 #endif /* _IDE_C */
783 int ide_register_module (ide_module_t *module);
784 void ide_unregister_module (ide_module_t *module);
785 ide_drive_t *ide_scan_devices (byte media, const char *name, ide_driver_t *driver, int n);
786 int ide_register_subdriver (ide_drive_t *drive, ide_driver_t *driver, int version);
787 int ide_unregister_subdriver (ide_drive_t *drive);
788 int ide_replace_subdriver(ide_drive_t *drive, const char *driver);
790 #ifdef CONFIG_BLK_DEV_IDEPCI
791 #define ON_BOARD 1
792 #define NEVER_BOARD 0
793 #ifdef CONFIG_BLK_DEV_OFFBOARD
794 # define OFF_BOARD ON_BOARD
795 #else /* CONFIG_BLK_DEV_OFFBOARD */
796 # define OFF_BOARD NEVER_BOARD
797 #endif /* CONFIG_BLK_DEV_OFFBOARD */
798 unsigned long ide_find_free_region (unsigned short size) __init;
799 void ide_scan_pcibus (void) __init;
800 #endif
801 #ifdef CONFIG_BLK_DEV_IDEDMA
802 #define BAD_DMA_DRIVE 0
803 #define GOOD_DMA_DRIVE 1
804 int ide_build_dmatable (ide_drive_t *drive, ide_dma_action_t func);
805 void ide_dma_intr (ide_drive_t *drive);
806 int check_drive_lists (ide_drive_t *drive, int good_bad);
807 int ide_dmaproc (ide_dma_action_t func, ide_drive_t *drive);
808 int ide_release_dma (ide_hwif_t *hwif);
809 void ide_setup_dma (ide_hwif_t *hwif, unsigned long dmabase, unsigned int num_ports) __init;
810 unsigned long ide_get_or_set_dma_base (ide_hwif_t *hwif, int extra, const char *name) __init;
811 #endif
813 /* This is too ugly to live! */
814 #ifdef CONFIG_BLK_DEV_PDC4030
815 #include "pdc4030.h"
816 #define IS_PDC4030_DRIVE (HWIF(drive)->chipset == ide_pdc4030)
817 #else
818 #define IS_PDC4030_DRIVE (0) /* auto-NULLs out pdc4030 code */
819 #endif /* CONFIG_BLK_DEV_PDC4030 */
821 #endif /* _IDE_H */