* better
[mascara-docs.git] / i386 / linux-2.3.21 / include / linux / ide.h
blob3ebe6c211bdded933392cd0f4f29421d7af3377d
1 #ifndef _IDE_H
2 #define _IDE_H
3 /*
4 * linux/include/linux/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 FANCY_STATUS_DUMPS /* 1 for human-readable drive errors */
50 #define FANCY_STATUS_DUMPS 1 /* 0 to reduce kernel size */
51 #endif
53 #ifdef CONFIG_BLK_DEV_CMD640
54 #if 0 /* change to 1 when debugging cmd640 problems */
55 void cmd640_dump_regs (void);
56 #define CMD640_DUMP_REGS cmd640_dump_regs() /* for debugging cmd640 chipset */
57 #endif
58 #endif /* CONFIG_BLK_DEV_CMD640 */
61 * IDE_DRIVE_CMD is used to implement many features of the hdparm utility
63 #define IDE_DRIVE_CMD 99 /* (magic) undef to reduce kernel size*/
66 * "No user-serviceable parts" beyond this point :)
67 *****************************************************************************/
69 typedef unsigned char byte; /* used everywhere */
72 * Probably not wise to fiddle with these
74 #define ERROR_MAX 8 /* Max read/write errors per sector */
75 #define ERROR_RESET 3 /* Reset controller every 4th retry */
76 #define ERROR_RECAL 1 /* Recalibrate every 2nd retry */
79 * Ensure that various configuration flags have compatible settings
81 #ifdef REALLY_SLOW_IO
82 #undef REALLY_FAST_IO
83 #endif
85 #define HWIF(drive) ((ide_hwif_t *)((drive)->hwif))
86 #define HWGROUP(drive) ((ide_hwgroup_t *)(HWIF(drive)->hwgroup))
89 * Definitions for accessing IDE controller registers
91 #define IDE_NR_PORTS (10)
93 #define IDE_DATA_OFFSET (0)
94 #define IDE_ERROR_OFFSET (1)
95 #define IDE_NSECTOR_OFFSET (2)
96 #define IDE_SECTOR_OFFSET (3)
97 #define IDE_LCYL_OFFSET (4)
98 #define IDE_HCYL_OFFSET (5)
99 #define IDE_SELECT_OFFSET (6)
100 #define IDE_STATUS_OFFSET (7)
101 #define IDE_CONTROL_OFFSET (8)
102 #define IDE_IRQ_OFFSET (9)
104 #define IDE_FEATURE_OFFSET IDE_ERROR_OFFSET
105 #define IDE_COMMAND_OFFSET IDE_STATUS_OFFSET
107 #define IDE_DATA_REG (HWIF(drive)->io_ports[IDE_DATA_OFFSET])
108 #define IDE_ERROR_REG (HWIF(drive)->io_ports[IDE_ERROR_OFFSET])
109 #define IDE_NSECTOR_REG (HWIF(drive)->io_ports[IDE_NSECTOR_OFFSET])
110 #define IDE_SECTOR_REG (HWIF(drive)->io_ports[IDE_SECTOR_OFFSET])
111 #define IDE_LCYL_REG (HWIF(drive)->io_ports[IDE_LCYL_OFFSET])
112 #define IDE_HCYL_REG (HWIF(drive)->io_ports[IDE_HCYL_OFFSET])
113 #define IDE_SELECT_REG (HWIF(drive)->io_ports[IDE_SELECT_OFFSET])
114 #define IDE_STATUS_REG (HWIF(drive)->io_ports[IDE_STATUS_OFFSET])
115 #define IDE_CONTROL_REG (HWIF(drive)->io_ports[IDE_CONTROL_OFFSET])
116 #define IDE_IRQ_REG (HWIF(drive)->io_ports[IDE_IRQ_OFFSET])
118 #define IDE_FEATURE_REG IDE_ERROR_REG
119 #define IDE_COMMAND_REG IDE_STATUS_REG
120 #define IDE_ALTSTATUS_REG IDE_CONTROL_REG
121 #define IDE_IREASON_REG IDE_NSECTOR_REG
122 #define IDE_BCOUNTL_REG IDE_LCYL_REG
123 #define IDE_BCOUNTH_REG IDE_HCYL_REG
125 #ifdef REALLY_FAST_IO
126 #define OUT_BYTE(b,p) outb((b),(p))
127 #define IN_BYTE(p) (byte)inb(p)
128 #else
129 #define OUT_BYTE(b,p) outb_p((b),(p))
130 #define IN_BYTE(p) (byte)inb_p(p)
131 #endif /* REALLY_FAST_IO */
133 #define GET_ERR() IN_BYTE(IDE_ERROR_REG)
134 #define GET_STAT() IN_BYTE(IDE_STATUS_REG)
135 #define OK_STAT(stat,good,bad) (((stat)&((good)|(bad)))==(good))
136 #define BAD_R_STAT (BUSY_STAT | ERR_STAT)
137 #define BAD_W_STAT (BAD_R_STAT | WRERR_STAT)
138 #define BAD_STAT (BAD_R_STAT | DRQ_STAT)
139 #define DRIVE_READY (READY_STAT | SEEK_STAT)
140 #define DATA_READY (DRQ_STAT)
143 * Some more useful definitions
145 #define IDE_MAJOR_NAME "ide" /* the same for all i/f; see also genhd.c */
146 #define MAJOR_NAME IDE_MAJOR_NAME
147 #define PARTN_BITS 6 /* number of minor dev bits for partitions */
148 #define PARTN_MASK ((1<<PARTN_BITS)-1) /* a useful bit mask */
149 #define MAX_DRIVES 2 /* per interface; 2 assumed by lots of code */
150 #define SECTOR_WORDS (512 / 4) /* number of 32bit words per sector */
151 #define IDE_LARGE_SEEK(b1,b2,t) (((b1) > (b2) + (t)) || ((b2) > (b1) + (t)))
152 #define IDE_MIN(a,b) ((a)<(b) ? (a):(b))
153 #define IDE_MAX(a,b) ((a)>(b) ? (a):(b))
156 * Timeouts for various operations:
158 #define WAIT_DRQ (5*HZ/100) /* 50msec - spec allows up to 20ms */
159 #ifdef CONFIG_APM
160 #define WAIT_READY (5*HZ) /* 5sec - some laptops are very slow */
161 #else
162 #define WAIT_READY (3*HZ/100) /* 30msec - should be instantaneous */
163 #endif /* CONFIG_APM */
164 #define WAIT_PIDENTIFY (10*HZ) /* 10sec - should be less than 3ms (?)
165 if all ATAPI CD is closed at boot */
166 #define WAIT_WORSTCASE (30*HZ) /* 30sec - worst case when spinning up */
167 #define WAIT_CMD (10*HZ) /* 10sec - maximum wait for an IRQ to happen */
168 #define WAIT_MIN_SLEEP (2*HZ/100) /* 20msec - minimum sleep time */
170 #define SELECT_DRIVE(hwif,drive) \
172 if (hwif->selectproc) \
173 hwif->selectproc(drive); \
174 OUT_BYTE((drive)->select.all, hwif->io_ports[IDE_SELECT_OFFSET]); \
178 * Check for an interrupt and acknowledge the interrupt status
180 struct hwif_s;
181 typedef int (ide_ack_intr_t)(struct hwif_s *);
184 * Structure to hold all information about the location of this port
186 typedef struct hw_regs_s {
187 ide_ioreg_t io_ports[IDE_NR_PORTS]; /* task file registers */
188 int irq; /* our irq number */
189 ide_ack_intr_t *ack_intr; /* acknowledge interrupt */
190 void *priv; /* interface specific data */
191 } hw_regs_t;
194 * Register new hardware with ide
196 int ide_register_hw(hw_regs_t *hw, struct hwif_s **hwifp);
199 * Set up hw_regs_t structure before calling ide_register_hw (optional)
201 void ide_setup_ports( hw_regs_t *hw,
202 ide_ioreg_t base,
203 int *offsets,
204 ide_ioreg_t ctrl,
205 ide_ioreg_t intr,
206 ide_ack_intr_t *ack_intr,
207 int irq);
209 #include <asm/ide.h>
212 * Now for the data we need to maintain per-drive: ide_drive_t
215 #define ide_scsi 0x21
216 #define ide_disk 0x20
217 #define ide_optical 0x7
218 #define ide_cdrom 0x5
219 #define ide_tape 0x1
220 #define ide_floppy 0x0
222 typedef union {
223 unsigned all : 8; /* all of the bits together */
224 struct {
225 unsigned set_geometry : 1; /* respecify drive geometry */
226 unsigned recalibrate : 1; /* seek to cyl 0 */
227 unsigned set_multmode : 1; /* set multmode count */
228 unsigned set_tune : 1; /* tune interface for drive */
229 unsigned reserved : 4; /* unused */
230 } b;
231 } special_t;
233 typedef struct ide_drive_s {
234 struct request *queue; /* request queue */
235 struct ide_drive_s *next; /* circular list of hwgroup drives */
236 unsigned long sleep; /* sleep until this time */
237 unsigned long service_start; /* time we started last request */
238 unsigned long service_time; /* service time of last request */
239 special_t special; /* special action flags */
240 byte keep_settings; /* restore settings after drive reset */
241 byte using_dma; /* disk is using dma for read/write */
242 byte waiting_for_dma; /* dma currently in progress */
243 byte unmask; /* flag: okay to unmask other irqs */
244 byte slow; /* flag: slow data port */
245 byte bswap; /* flag: byte swap data */
246 byte dsc_overlap; /* flag: DSC overlap */
247 byte nice1; /* flag: give potential excess bandwidth */
248 unsigned present : 1; /* drive is physically present */
249 unsigned noprobe : 1; /* from: hdx=noprobe */
250 unsigned busy : 1; /* currently doing revalidate_disk() */
251 unsigned removable : 1; /* 1 if need to do check_media_change */
252 unsigned forced_geom : 1; /* 1 if hdx=c,h,s was given at boot */
253 unsigned no_unmask : 1; /* disallow setting unmask bit */
254 unsigned no_io_32bit : 1; /* disallow enabling 32bit I/O */
255 unsigned nobios : 1; /* flag: do not probe bios for drive */
256 unsigned revalidate : 1; /* request revalidation */
257 unsigned atapi_overlap : 1; /* flag: ATAPI overlap (not supported) */
258 unsigned nice0 : 1; /* flag: give obvious excess bandwidth */
259 unsigned nice2 : 1; /* flag: give a share in our own bandwidth */
260 unsigned doorlocking : 1; /* flag: for removable only: door lock/unlock works */
261 unsigned autotune : 2; /* 1=autotune, 2=noautotune, 0=default */
262 unsigned remap_0_to_1 : 2; /* 0=remap if ezdrive, 1=remap, 2=noremap */
263 unsigned ata_flash : 1; /* 1=present, 0=default */
264 byte media; /* disk, cdrom, tape, floppy, ... */
265 select_t select; /* basic drive/head select reg value */
266 byte ctl; /* "normal" value for IDE_CONTROL_REG */
267 byte ready_stat; /* min status value for drive ready */
268 byte mult_count; /* current multiple sector setting */
269 byte mult_req; /* requested multiple sector setting */
270 byte tune_req; /* requested drive tuning setting */
271 byte io_32bit; /* 0=16-bit, 1=32-bit, 2/3=32bit+sync */
272 byte bad_wstat; /* used for ignoring WRERR_STAT */
273 byte nowerr; /* used for ignoring WRERR_STAT */
274 byte sect0; /* offset of first sector for DM6:DDO */
275 byte usage; /* current "open()" count for drive */
276 byte head; /* "real" number of heads */
277 byte sect; /* "real" sectors per track */
278 byte bios_head; /* BIOS/fdisk/LILO number of heads */
279 byte bios_sect; /* BIOS/fdisk/LILO sectors per track */
280 unsigned int bios_cyl; /* BIOS/fdisk/LILO number of cyls */
281 unsigned int cyl; /* "real" number of cyls */
282 unsigned long capacity; /* total number of sectors */
283 unsigned int drive_data; /* for use by tuneproc/selectproc as needed */
284 void *hwif; /* actually (ide_hwif_t *) */
285 wait_queue_head_t wqueue; /* used to wait for drive in open() */
286 struct hd_driveid *id; /* drive model identification info */
287 struct hd_struct *part; /* drive partition table */
288 char name[4]; /* drive name, such as "hda" */
289 void *driver; /* (ide_driver_t *) */
290 void *driver_data; /* extra driver data */
291 struct proc_dir_entry *proc; /* /proc/ide/ directory entry */
292 void *settings; /* /proc/ide/ drive settings */
293 char driver_req[10]; /* requests specific driver */
294 #if 1
295 struct thresholds_s *smart_thresholds;
296 struct values_s *smart_values;
297 #else
298 thresholds_t smart_thresholds;
299 values_t smart_values;
300 #endif
301 } ide_drive_t;
304 * An ide_dmaproc_t() initiates/aborts DMA read/write operations on a drive.
306 * The caller is assumed to have selected the drive and programmed the drive's
307 * sector address using CHS or LBA. All that remains is to prepare for DMA
308 * and then issue the actual read/write DMA/PIO command to the drive.
310 * Returns 0 if all went well.
311 * Returns 1 if DMA read/write could not be started, in which case the caller
312 * should either try again later, or revert to PIO for the current request.
314 typedef enum { ide_dma_read, ide_dma_write, ide_dma_begin,
315 ide_dma_end, ide_dma_check, ide_dma_on,
316 ide_dma_off, ide_dma_off_quietly, ide_dma_test_irq,
317 ide_dma_bad_drive, ide_dma_good_drive,
318 ide_dma_lostirq, ide_dma_timeout
319 } ide_dma_action_t;
321 typedef int (ide_dmaproc_t)(ide_dma_action_t, ide_drive_t *);
325 * An ide_tuneproc_t() is used to set the speed of an IDE interface
326 * to a particular PIO mode. The "byte" parameter is used
327 * to select the PIO mode by number (0,1,2,3,4,5), and a value of 255
328 * indicates that the interface driver should "auto-tune" the PIO mode
329 * according to the drive capabilities in drive->id;
331 * Not all interface types support tuning, and not all of those
332 * support all possible PIO settings. They may silently ignore
333 * or round values as they see fit.
335 typedef void (ide_tuneproc_t)(ide_drive_t *, byte);
338 * This is used to provide support for strange interfaces
340 typedef void (ide_selectproc_t) (ide_drive_t *);
343 * hwif_chipset_t is used to keep track of the specific hardware
344 * chipset used by each IDE interface, if known.
346 typedef enum { ide_unknown, ide_generic, ide_pci,
347 ide_cmd640, ide_dtc2278, ide_ali14xx,
348 ide_qd6580, ide_umc8672, ide_ht6560b,
349 ide_pdc4030, ide_rz1000, ide_trm290,
350 ide_cmd646, ide_cy82c693, ide_4drives
351 } hwif_chipset_t;
353 typedef struct ide_pci_devid_s {
354 unsigned short vid;
355 unsigned short did;
356 } ide_pci_devid_t;
358 #define IDE_PCI_DEVID_NULL ((ide_pci_devid_t){0,0})
359 #define IDE_PCI_DEVID_EQ(a,b) (a.vid == b.vid && a.did == b.did)
361 typedef struct hwif_s {
362 struct hwif_s *next; /* for linked-list in ide_hwgroup_t */
363 void *hwgroup; /* actually (ide_hwgroup_t *) */
364 ide_ioreg_t io_ports[IDE_NR_PORTS]; /* task file registers */
365 hw_regs_t hw; /* Hardware info */
366 ide_drive_t drives[MAX_DRIVES]; /* drive info */
367 struct gendisk *gd; /* gendisk structure */
368 ide_tuneproc_t *tuneproc; /* routine to tune PIO mode for drives */
369 ide_selectproc_t *selectproc; /* tweaks hardware to select drive */
370 ide_dmaproc_t *dmaproc; /* dma read/write/abort routine */
371 unsigned long *dmatable; /* dma physical region descriptor table */
372 struct hwif_s *mate; /* other hwif from same PCI chip */
373 unsigned long dma_base; /* base addr for dma ports */
374 unsigned dma_extra; /* extra addr for dma ports */
375 unsigned long config_data; /* for use by chipset-specific code */
376 unsigned long select_data; /* for use by chipset-specific code */
377 struct proc_dir_entry *proc; /* /proc/ide/ directory entry */
378 int irq; /* our irq number */
379 byte major; /* our major number */
380 char name[6]; /* name of interface, eg. "ide0" */
381 byte index; /* 0 for ide0; 1 for ide1; ... */
382 hwif_chipset_t chipset; /* sub-module for tuning.. */
383 unsigned noprobe : 1; /* don't probe for this interface */
384 unsigned present : 1; /* this interface exists */
385 unsigned serialized : 1; /* serialized operation with mate hwif */
386 unsigned sharing_irq: 1; /* 1 = sharing irq with another hwif */
387 unsigned reset : 1; /* reset after probe */
388 unsigned autodma : 1; /* automatically try to enable DMA at boot */
389 unsigned udma_four : 1; /* 1=ATA-66 capable, 0=default */
390 byte channel; /* for dual-port chips: 0=primary, 1=secondary */
391 struct pci_dev *pci_dev; /* for pci chipsets */
392 ide_pci_devid_t pci_devid; /* for pci chipsets: {VID,DID} */
393 #if (DISK_RECOVERY_TIME > 0)
394 unsigned long last_time; /* time when previous rq was done */
395 #endif
396 } ide_hwif_t;
399 * internal ide interrupt handler type
401 typedef void (ide_handler_t)(ide_drive_t *);
403 typedef struct hwgroup_s {
404 spinlock_t spinlock; /* protects "busy" and "handler" */
405 ide_handler_t *handler;/* irq handler, if active */
406 int busy; /* BOOL: protects all fields below */
407 ide_drive_t *drive; /* current drive */
408 ide_hwif_t *hwif; /* ptr to current hwif in linked-list */
409 struct request *rq; /* current request */
410 struct timer_list timer; /* failsafe timer */
411 struct request wrq; /* local copy of current write rq */
412 unsigned long poll_timeout; /* timeout value during long polls */
413 } ide_hwgroup_t;
416 * configurable drive settings
419 #define TYPE_INT 0
420 #define TYPE_INTA 1
421 #define TYPE_BYTE 2
422 #define TYPE_SHORT 3
424 #define SETTING_READ (1 << 0)
425 #define SETTING_WRITE (1 << 1)
426 #define SETTING_RW (SETTING_READ | SETTING_WRITE)
428 typedef int (ide_procset_t)(ide_drive_t *, int);
429 typedef struct ide_settings_s {
430 char *name;
431 int rw;
432 int read_ioctl;
433 int write_ioctl;
434 int data_type;
435 int min;
436 int max;
437 int mul_factor;
438 int div_factor;
439 void *data;
440 ide_procset_t *set;
441 int auto_remove;
442 struct ide_settings_s *next;
443 } ide_settings_t;
445 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);
446 void ide_remove_setting(ide_drive_t *drive, char *name);
447 ide_settings_t *ide_find_setting_by_name(ide_drive_t *drive, char *name);
448 int ide_read_setting(ide_drive_t *t, ide_settings_t *setting);
449 int ide_write_setting(ide_drive_t *drive, ide_settings_t *setting, int val);
450 void ide_add_generic_settings(ide_drive_t *drive);
453 * /proc/ide interface
455 typedef struct {
456 const char *name;
457 mode_t mode;
458 read_proc_t *read_proc;
459 write_proc_t *write_proc;
460 } ide_proc_entry_t;
462 #ifdef CONFIG_PROC_FS
463 void proc_ide_create(void);
464 void proc_ide_destroy(void);
465 void destroy_proc_ide_drives(ide_hwif_t *);
466 void create_proc_ide_interfaces(void);
467 void ide_add_proc_entries(struct proc_dir_entry *dir, ide_proc_entry_t *p, void *data);
468 void ide_remove_proc_entries(struct proc_dir_entry *dir, ide_proc_entry_t *p);
469 read_proc_t proc_ide_read_capacity;
470 read_proc_t proc_ide_read_geometry;
473 * Standard exit stuff:
475 #define PROC_IDE_READ_RETURN(page,start,off,count,eof,len) \
477 len -= off; \
478 if (len < count) { \
479 *eof = 1; \
480 if (len <= 0) \
481 return 0; \
482 } else \
483 len = count; \
484 *start = page + off; \
485 return len; \
487 #else
488 #define PROC_IDE_READ_RETURN(page,start,off,count,eof,len) return 0;
489 #endif
492 * Subdrivers support.
494 #define IDE_SUBDRIVER_VERSION 1
496 typedef int (ide_cleanup_proc)(ide_drive_t *);
497 typedef void (ide_do_request_proc)(ide_drive_t *, struct request *, unsigned long);
498 typedef void (ide_end_request_proc)(byte, ide_hwgroup_t *);
499 typedef int (ide_ioctl_proc)(ide_drive_t *, struct inode *, struct file *, unsigned int, unsigned long);
500 typedef int (ide_open_proc)(struct inode *, struct file *, ide_drive_t *);
501 typedef void (ide_release_proc)(struct inode *, struct file *, ide_drive_t *);
502 typedef int (ide_check_media_change_proc)(ide_drive_t *);
503 typedef void (ide_pre_reset_proc)(ide_drive_t *);
504 typedef unsigned long (ide_capacity_proc)(ide_drive_t *);
505 typedef void (ide_special_proc)(ide_drive_t *);
506 typedef void (ide_setting_proc)(ide_drive_t *);
508 typedef struct ide_driver_s {
509 const char *name;
510 const char *version;
511 byte media;
512 unsigned busy : 1;
513 unsigned supports_dma : 1;
514 unsigned supports_dsc_overlap : 1;
515 ide_cleanup_proc *cleanup;
516 ide_do_request_proc *do_request;
517 ide_end_request_proc *end_request;
518 ide_ioctl_proc *ioctl;
519 ide_open_proc *open;
520 ide_release_proc *release;
521 ide_check_media_change_proc *media_change;
522 ide_pre_reset_proc *pre_reset;
523 ide_capacity_proc *capacity;
524 ide_special_proc *special;
525 ide_proc_entry_t *proc;
526 } ide_driver_t;
528 #define DRIVER(drive) ((ide_driver_t *)((drive)->driver))
531 * IDE modules.
533 #define IDE_CHIPSET_MODULE 0 /* not supported yet */
534 #define IDE_PROBE_MODULE 1
535 #define IDE_DRIVER_MODULE 2
537 typedef int (ide_module_init_proc)(void);
539 typedef struct ide_module_s {
540 int type;
541 ide_module_init_proc *init;
542 void *info;
543 struct ide_module_s *next;
544 } ide_module_t;
547 * ide_hwifs[] is the master data structure used to keep track
548 * of just about everything in ide.c. Whenever possible, routines
549 * should be using pointers to a drive (ide_drive_t *) or
550 * pointers to a hwif (ide_hwif_t *), rather than indexing this
551 * structure directly (the allocation/layout may change!).
554 #ifndef _IDE_C
555 extern ide_hwif_t ide_hwifs[]; /* master data repository */
556 extern ide_module_t *ide_modules;
557 #endif
560 * We need blk.h, but we replace its end_request by our own version.
562 #define IDE_DRIVER /* Toggle some magic bits in blk.h */
563 #define LOCAL_END_REQUEST /* Don't generate end_request in blk.h */
564 #include <linux/blk.h>
566 void ide_end_request(byte uptodate, ide_hwgroup_t *hwgroup);
569 * This is used for (nearly) all data transfers from/to the IDE interface
571 void ide_input_data (ide_drive_t *drive, void *buffer, unsigned int wcount);
572 void ide_output_data (ide_drive_t *drive, void *buffer, unsigned int wcount);
575 * This is used for (nearly) all ATAPI data transfers from/to the IDE interface
577 void atapi_input_bytes (ide_drive_t *drive, void *buffer, unsigned int bytecount);
578 void atapi_output_bytes (ide_drive_t *drive, void *buffer, unsigned int bytecount);
581 * This is used on exit from the driver, to designate the next irq handler
582 * and also to start the safety timer.
584 void ide_set_handler (ide_drive_t *drive, ide_handler_t *handler, unsigned int timeout);
587 * Error reporting, in human readable form (luxurious, but a memory hog).
589 byte ide_dump_status (ide_drive_t *drive, const char *msg, byte stat);
592 * ide_error() takes action based on the error returned by the controller.
593 * The calling function must return afterwards, to restart the request.
595 void ide_error (ide_drive_t *drive, const char *msg, byte stat);
598 * Issue a simple drive command
599 * The drive must be selected beforehand.
601 void ide_cmd(ide_drive_t *drive, byte cmd, byte nsect, ide_handler_t *handler);
604 * ide_fixstring() cleans up and (optionally) byte-swaps a text string,
605 * removing leading/trailing blanks and compressing internal blanks.
606 * It is primarily used to tidy up the model name/number fields as
607 * returned by the WIN_[P]IDENTIFY commands.
609 void ide_fixstring (byte *s, const int bytecount, const int byteswap);
612 * This routine busy-waits for the drive status to be not "busy".
613 * It then checks the status for all of the "good" bits and none
614 * of the "bad" bits, and if all is okay it returns 0. All other
615 * cases return 1 after invoking ide_error() -- caller should return.
618 int ide_wait_stat (ide_drive_t *drive, byte good, byte bad, unsigned long timeout);
621 * This routine is called from the partition-table code in genhd.c
622 * to "convert" a drive to a logical geometry with fewer than 1024 cyls.
624 int ide_xlate_1024 (kdev_t, int, int, const char *);
627 * Convert kdev_t structure into ide_drive_t * one.
629 ide_drive_t *get_info_ptr (kdev_t i_rdev);
632 * Return the current idea about the total capacity of this drive.
634 unsigned long current_capacity (ide_drive_t *drive);
637 * Start a reset operation for an IDE interface.
638 * The caller should return immediately after invoking this.
640 void ide_do_reset (ide_drive_t *);
643 * This function is intended to be used prior to invoking ide_do_drive_cmd().
645 void ide_init_drive_cmd (struct request *rq);
648 * "action" parameter type for ide_do_drive_cmd() below.
650 typedef enum
651 {ide_wait, /* insert rq at end of list, and wait for it */
652 ide_next, /* insert rq immediately after current request */
653 ide_preempt, /* insert rq in front of current request */
654 ide_end} /* insert rq at end of list, but don't wait for it */
655 ide_action_t;
658 * This function issues a special IDE device request
659 * onto the request queue.
661 * If action is ide_wait, then the rq is queued at the end of the
662 * request queue, and the function sleeps until it has been processed.
663 * This is for use when invoked from an ioctl handler.
665 * If action is ide_preempt, then the rq is queued at the head of
666 * the request queue, displacing the currently-being-processed
667 * request and this function returns immediately without waiting
668 * for the new rq to be completed. This is VERY DANGEROUS, and is
669 * intended for careful use by the ATAPI tape/cdrom driver code.
671 * If action is ide_next, then the rq is queued immediately after
672 * the currently-being-processed-request (if any), and the function
673 * returns without waiting for the new rq to be completed. As above,
674 * This is VERY DANGEROUS, and is intended for careful use by the
675 * ATAPI tape/cdrom driver code.
677 * If action is ide_end, then the rq is queued at the end of the
678 * request queue, and the function returns immediately without waiting
679 * for the new rq to be completed. This is again intended for careful
680 * use by the ATAPI tape/cdrom driver code.
682 int ide_do_drive_cmd (ide_drive_t *drive, struct request *rq, ide_action_t action);
685 * Clean up after success/failure of an explicit drive cmd.
686 * stat/err are used only when (HWGROUP(drive)->rq->cmd == IDE_DRIVE_CMD).
688 void ide_end_drive_cmd (ide_drive_t *drive, byte stat, byte err);
691 * Issue ATA command and wait for completion.
693 int ide_wait_cmd (ide_drive_t *drive, int cmd, int nsect, int feature, int sectors, byte *buf);
695 void ide_delay_50ms (void);
696 int ide_config_drive_speed (ide_drive_t *drive, byte speed);
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 #if MAX_HWIFS > 8
757 void do_ide8_request (void);
758 #endif
759 #if MAX_HWIFS > 9
760 void do_ide9_request (void);
761 #endif
762 void ide_init_subdrivers (void);
764 #ifndef _IDE_C
765 extern struct file_operations ide_fops[];
766 extern ide_proc_entry_t generic_subdriver_entries[];
767 #endif
769 #ifdef _IDE_C
770 #ifdef CONFIG_BLK_DEV_IDE
771 int ideprobe_init (void);
772 #endif /* CONFIG_BLK_DEV_IDE */
773 #ifdef CONFIG_BLK_DEV_IDEDISK
774 int idedisk_init (void);
775 #endif /* CONFIG_BLK_DEV_IDEDISK */
776 #ifdef CONFIG_BLK_DEV_IDECD
777 int ide_cdrom_init (void);
778 #endif /* CONFIG_BLK_DEV_IDECD */
779 #ifdef CONFIG_BLK_DEV_IDETAPE
780 int idetape_init (void);
781 #endif /* CONFIG_BLK_DEV_IDETAPE */
782 #ifdef CONFIG_BLK_DEV_IDEFLOPPY
783 int idefloppy_init (void);
784 #endif /* CONFIG_BLK_DEV_IDEFLOPPY */
785 #ifdef CONFIG_BLK_DEV_IDESCSI
786 int idescsi_init (void);
787 #endif /* CONFIG_BLK_DEV_IDESCSI */
788 #endif /* _IDE_C */
790 int ide_register_module (ide_module_t *module);
791 void ide_unregister_module (ide_module_t *module);
792 ide_drive_t *ide_scan_devices (byte media, const char *name, ide_driver_t *driver, int n);
793 int ide_register_subdriver (ide_drive_t *drive, ide_driver_t *driver, int version);
794 int ide_unregister_subdriver (ide_drive_t *drive);
795 int ide_replace_subdriver(ide_drive_t *drive, const char *driver);
797 #ifdef CONFIG_BLK_DEV_IDEPCI
798 #define ON_BOARD 1
799 #define NEVER_BOARD 0
800 #ifdef CONFIG_BLK_DEV_OFFBOARD
801 # define OFF_BOARD ON_BOARD
802 #else /* CONFIG_BLK_DEV_OFFBOARD */
803 # define OFF_BOARD NEVER_BOARD
804 #endif /* CONFIG_BLK_DEV_OFFBOARD */
805 unsigned long ide_find_free_region (unsigned short size) __init;
806 void ide_scan_pcibus (void) __init;
807 #endif
808 #ifdef CONFIG_BLK_DEV_IDEDMA
809 #define BAD_DMA_DRIVE 0
810 #define GOOD_DMA_DRIVE 1
811 int ide_build_dmatable (ide_drive_t *drive, ide_dma_action_t func);
812 void ide_dma_intr (ide_drive_t *drive);
813 int check_drive_lists (ide_drive_t *drive, int good_bad);
814 int ide_dmaproc (ide_dma_action_t func, ide_drive_t *drive);
815 int ide_release_dma (ide_hwif_t *hwif);
816 void ide_setup_dma (ide_hwif_t *hwif, unsigned long dmabase, unsigned int num_ports) __init;
817 unsigned long ide_get_or_set_dma_base (ide_hwif_t *hwif, int extra, const char *name) __init;
818 #endif
820 #endif /* _IDE_H */