- Stephen Rothwell: APM updates
[davej-history.git] / include / linux / ide.h
blob23866ce797a73220961cf5f80f6cc78288b17783
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 <linux/devfs_fs_kernel.h>
17 #include <asm/hdreg.h>
20 * This is the multiple IDE interface driver, as evolved from hd.c.
21 * It supports up to four IDE interfaces, on one or more IRQs (usually 14 & 15).
22 * There can be up to two drives per interface, as per the ATA-2 spec.
24 * Primary i/f: ide0: major=3; (hda) minor=0; (hdb) minor=64
25 * Secondary i/f: ide1: major=22; (hdc or hd1a) minor=0; (hdd or hd1b) minor=64
26 * Tertiary i/f: ide2: major=33; (hde) minor=0; (hdf) minor=64
27 * Quaternary i/f: ide3: major=34; (hdg) minor=0; (hdh) minor=64
30 /******************************************************************************
31 * IDE driver configuration options (play with these as desired):
33 * REALLY_SLOW_IO can be defined in ide.c and ide-cd.c, if necessary
35 #undef REALLY_FAST_IO /* define if ide ports are perfect */
36 #define INITIAL_MULT_COUNT 0 /* off=0; on=2,4,8,16,32, etc.. */
38 #ifndef SUPPORT_SLOW_DATA_PORTS /* 1 to support slow data ports */
39 #define SUPPORT_SLOW_DATA_PORTS 1 /* 0 to reduce kernel size */
40 #endif
41 #ifndef SUPPORT_VLB_SYNC /* 1 to support weird 32-bit chips */
42 #define SUPPORT_VLB_SYNC 1 /* 0 to reduce kernel size */
43 #endif
44 #ifndef DISK_RECOVERY_TIME /* off=0; on=access_delay_time */
45 #define DISK_RECOVERY_TIME 0 /* for hardware that needs it */
46 #endif
47 #ifndef OK_TO_RESET_CONTROLLER /* 1 needed for good error recovery */
48 #define OK_TO_RESET_CONTROLLER 1 /* 0 for use with AH2372A/B interface */
49 #endif
50 #ifndef FANCY_STATUS_DUMPS /* 1 for human-readable drive errors */
51 #define FANCY_STATUS_DUMPS 1 /* 0 to reduce kernel size */
52 #endif
54 #ifdef CONFIG_BLK_DEV_CMD640
55 #if 0 /* change to 1 when debugging cmd640 problems */
56 void cmd640_dump_regs (void);
57 #define CMD640_DUMP_REGS cmd640_dump_regs() /* for debugging cmd640 chipset */
58 #endif
59 #endif /* CONFIG_BLK_DEV_CMD640 */
61 #ifndef DISABLE_IRQ_NOSYNC
62 #define DISABLE_IRQ_NOSYNC 0
63 #endif
66 * IDE_DRIVE_CMD is used to implement many features of the hdparm utility
68 #define IDE_DRIVE_CMD 99 /* (magic) undef to reduce kernel size*/
71 * IDE_DRIVE_TASK is used to implement many features needed for raw tasks
73 #define IDE_DRIVE_TASK 98
74 #define IDE_DRIVE_CMD_AEB 98
77 * "No user-serviceable parts" beyond this point :)
78 *****************************************************************************/
80 typedef unsigned char byte; /* used everywhere */
83 * Probably not wise to fiddle with these
85 #define ERROR_MAX 8 /* Max read/write errors per sector */
86 #define ERROR_RESET 3 /* Reset controller every 4th retry */
87 #define ERROR_RECAL 1 /* Recalibrate every 2nd retry */
90 * Ensure that various configuration flags have compatible settings
92 #ifdef REALLY_SLOW_IO
93 #undef REALLY_FAST_IO
94 #endif
96 #define HWIF(drive) ((ide_hwif_t *)((drive)->hwif))
97 #define HWGROUP(drive) ((ide_hwgroup_t *)(HWIF(drive)->hwgroup))
100 * Definitions for accessing IDE controller registers
102 #define IDE_NR_PORTS (10)
104 #define IDE_DATA_OFFSET (0)
105 #define IDE_ERROR_OFFSET (1)
106 #define IDE_NSECTOR_OFFSET (2)
107 #define IDE_SECTOR_OFFSET (3)
108 #define IDE_LCYL_OFFSET (4)
109 #define IDE_HCYL_OFFSET (5)
110 #define IDE_SELECT_OFFSET (6)
111 #define IDE_STATUS_OFFSET (7)
112 #define IDE_CONTROL_OFFSET (8)
113 #define IDE_IRQ_OFFSET (9)
115 #define IDE_FEATURE_OFFSET IDE_ERROR_OFFSET
116 #define IDE_COMMAND_OFFSET IDE_STATUS_OFFSET
118 #define IDE_DATA_REG (HWIF(drive)->io_ports[IDE_DATA_OFFSET])
119 #define IDE_ERROR_REG (HWIF(drive)->io_ports[IDE_ERROR_OFFSET])
120 #define IDE_NSECTOR_REG (HWIF(drive)->io_ports[IDE_NSECTOR_OFFSET])
121 #define IDE_SECTOR_REG (HWIF(drive)->io_ports[IDE_SECTOR_OFFSET])
122 #define IDE_LCYL_REG (HWIF(drive)->io_ports[IDE_LCYL_OFFSET])
123 #define IDE_HCYL_REG (HWIF(drive)->io_ports[IDE_HCYL_OFFSET])
124 #define IDE_SELECT_REG (HWIF(drive)->io_ports[IDE_SELECT_OFFSET])
125 #define IDE_STATUS_REG (HWIF(drive)->io_ports[IDE_STATUS_OFFSET])
126 #define IDE_CONTROL_REG (HWIF(drive)->io_ports[IDE_CONTROL_OFFSET])
127 #define IDE_IRQ_REG (HWIF(drive)->io_ports[IDE_IRQ_OFFSET])
129 #define IDE_FEATURE_REG IDE_ERROR_REG
130 #define IDE_COMMAND_REG IDE_STATUS_REG
131 #define IDE_ALTSTATUS_REG IDE_CONTROL_REG
132 #define IDE_IREASON_REG IDE_NSECTOR_REG
133 #define IDE_BCOUNTL_REG IDE_LCYL_REG
134 #define IDE_BCOUNTH_REG IDE_HCYL_REG
136 #ifdef REALLY_FAST_IO
137 #define OUT_BYTE(b,p) outb((b),(p))
138 #define IN_BYTE(p) (byte)inb(p)
139 #else
140 #define OUT_BYTE(b,p) outb_p((b),(p))
141 #define IN_BYTE(p) (byte)inb_p(p)
142 #endif /* REALLY_FAST_IO */
144 #define GET_ERR() IN_BYTE(IDE_ERROR_REG)
145 #define GET_STAT() IN_BYTE(IDE_STATUS_REG)
146 #define GET_ALTSTAT() IN_BYTE(IDE_CONTROL_REG)
147 #define OK_STAT(stat,good,bad) (((stat)&((good)|(bad)))==(good))
148 #define BAD_R_STAT (BUSY_STAT | ERR_STAT)
149 #define BAD_W_STAT (BAD_R_STAT | WRERR_STAT)
150 #define BAD_STAT (BAD_R_STAT | DRQ_STAT)
151 #define DRIVE_READY (READY_STAT | SEEK_STAT)
152 #define DATA_READY (DRQ_STAT)
155 * Some more useful definitions
157 #define IDE_MAJOR_NAME "hd" /* the same for all i/f; see also genhd.c */
158 #define MAJOR_NAME IDE_MAJOR_NAME
159 #define PARTN_BITS 6 /* number of minor dev bits for partitions */
160 #define PARTN_MASK ((1<<PARTN_BITS)-1) /* a useful bit mask */
161 #define MAX_DRIVES 2 /* per interface; 2 assumed by lots of code */
162 #define SECTOR_WORDS (512 / 4) /* number of 32bit words per sector */
163 #define IDE_LARGE_SEEK(b1,b2,t) (((b1) > (b2) + (t)) || ((b2) > (b1) + (t)))
164 #define IDE_MIN(a,b) ((a)<(b) ? (a):(b))
165 #define IDE_MAX(a,b) ((a)>(b) ? (a):(b))
168 * Timeouts for various operations:
170 #define WAIT_DRQ (5*HZ/100) /* 50msec - spec allows up to 20ms */
171 #if defined(CONFIG_APM) || defined(CONFIG_APM_MODULE)
172 #define WAIT_READY (5*HZ) /* 5sec - some laptops are very slow */
173 #else
174 #define WAIT_READY (3*HZ/100) /* 30msec - should be instantaneous */
175 #endif /* CONFIG_APM || CONFIG_APM_MODULE */
176 #define WAIT_PIDENTIFY (10*HZ) /* 10sec - should be less than 3ms (?)
177 if all ATAPI CD is closed at boot */
178 #define WAIT_WORSTCASE (30*HZ) /* 30sec - worst case when spinning up */
179 #define WAIT_CMD (10*HZ) /* 10sec - maximum wait for an IRQ to happen */
180 #define WAIT_MIN_SLEEP (2*HZ/100) /* 20msec - minimum sleep time */
182 #define SELECT_DRIVE(hwif,drive) \
184 if (hwif->selectproc) \
185 hwif->selectproc(drive); \
186 OUT_BYTE((drive)->select.all, hwif->io_ports[IDE_SELECT_OFFSET]); \
189 #define SELECT_INTERRUPT(hwif,drive) \
191 if (hwif->intrproc) \
192 hwif->intrproc(drive); \
193 else \
194 OUT_BYTE((drive)->ctl|2, hwif->io_ports[IDE_CONTROL_OFFSET]); \
197 #define SELECT_MASK(hwif,drive,mask) \
199 if (hwif->maskproc) \
200 hwif->maskproc(drive,mask); \
203 #define SELECT_READ_WRITE(hwif,drive,func) \
205 if (hwif->rwproc) \
206 hwif->rwproc(drive,func); \
209 #define QUIRK_LIST(hwif,drive) \
211 if (hwif->quirkproc) \
212 (drive)->quirk_list = hwif->quirkproc(drive); \
215 #define IDE_DEBUG(lineno) \
216 printk("%s,%s,line=%d\n", __FILE__, __FUNCTION__, (lineno))
219 * Check for an interrupt and acknowledge the interrupt status
221 struct hwif_s;
222 typedef int (ide_ack_intr_t)(struct hwif_s *);
224 #ifndef NO_DMA
225 #define NO_DMA 255
226 #endif
229 * Structure to hold all information about the location of this port
231 typedef struct hw_regs_s {
232 ide_ioreg_t io_ports[IDE_NR_PORTS]; /* task file registers */
233 int irq; /* our irq number */
234 int dma; /* our dma entry */
235 ide_ack_intr_t *ack_intr; /* acknowledge interrupt */
236 void *priv; /* interface specific data */
237 } hw_regs_t;
240 * Register new hardware with ide
242 int ide_register_hw(hw_regs_t *hw, struct hwif_s **hwifp);
245 * Set up hw_regs_t structure before calling ide_register_hw (optional)
247 void ide_setup_ports( hw_regs_t *hw,
248 ide_ioreg_t base,
249 int *offsets,
250 ide_ioreg_t ctrl,
251 ide_ioreg_t intr,
252 ide_ack_intr_t *ack_intr,
253 int irq);
255 #include <asm/ide.h>
258 * Now for the data we need to maintain per-drive: ide_drive_t
261 #define ide_scsi 0x21
262 #define ide_disk 0x20
263 #define ide_optical 0x7
264 #define ide_cdrom 0x5
265 #define ide_tape 0x1
266 #define ide_floppy 0x0
268 typedef union {
269 unsigned all : 8; /* all of the bits together */
270 struct {
271 unsigned set_geometry : 1; /* respecify drive geometry */
272 unsigned recalibrate : 1; /* seek to cyl 0 */
273 unsigned set_multmode : 1; /* set multmode count */
274 unsigned set_tune : 1; /* tune interface for drive */
275 unsigned reserved : 4; /* unused */
276 } b;
277 } special_t;
279 typedef struct ide_drive_s {
280 request_queue_t queue; /* request queue */
281 struct ide_drive_s *next; /* circular list of hwgroup drives */
282 unsigned long sleep; /* sleep until this time */
283 unsigned long service_start; /* time we started last request */
284 unsigned long service_time; /* service time of last request */
285 unsigned long timeout; /* max time to wait for irq */
286 special_t special; /* special action flags */
287 byte keep_settings; /* restore settings after drive reset */
288 byte using_dma; /* disk is using dma for read/write */
289 byte waiting_for_dma; /* dma currently in progress */
290 byte unmask; /* flag: okay to unmask other irqs */
291 byte slow; /* flag: slow data port */
292 byte bswap; /* flag: byte swap data */
293 byte dsc_overlap; /* flag: DSC overlap */
294 byte nice1; /* flag: give potential excess bandwidth */
295 unsigned present : 1; /* drive is physically present */
296 unsigned noprobe : 1; /* from: hdx=noprobe */
297 unsigned busy : 1; /* currently doing revalidate_disk() */
298 unsigned removable : 1; /* 1 if need to do check_media_change */
299 unsigned forced_geom : 1; /* 1 if hdx=c,h,s was given at boot */
300 unsigned no_unmask : 1; /* disallow setting unmask bit */
301 unsigned no_io_32bit : 1; /* disallow enabling 32bit I/O */
302 unsigned nobios : 1; /* flag: do not probe bios for drive */
303 unsigned revalidate : 1; /* request revalidation */
304 unsigned atapi_overlap : 1; /* flag: ATAPI overlap (not supported) */
305 unsigned nice0 : 1; /* flag: give obvious excess bandwidth */
306 unsigned nice2 : 1; /* flag: give a share in our own bandwidth */
307 unsigned doorlocking : 1; /* flag: for removable only: door lock/unlock works */
308 unsigned autotune : 2; /* 1=autotune, 2=noautotune, 0=default */
309 unsigned remap_0_to_1 : 2; /* 0=remap if ezdrive, 1=remap, 2=noremap */
310 unsigned ata_flash : 1; /* 1=present, 0=default */
311 byte scsi; /* 0=default, 1=skip current ide-subdriver for ide-scsi emulation */
312 byte media; /* disk, cdrom, tape, floppy, ... */
313 select_t select; /* basic drive/head select reg value */
314 byte ctl; /* "normal" value for IDE_CONTROL_REG */
315 byte ready_stat; /* min status value for drive ready */
316 byte mult_count; /* current multiple sector setting */
317 byte mult_req; /* requested multiple sector setting */
318 byte tune_req; /* requested drive tuning setting */
319 byte io_32bit; /* 0=16-bit, 1=32-bit, 2/3=32bit+sync */
320 byte bad_wstat; /* used for ignoring WRERR_STAT */
321 byte nowerr; /* used for ignoring WRERR_STAT */
322 byte sect0; /* offset of first sector for DM6:DDO */
323 byte usage; /* current "open()" count for drive */
324 byte head; /* "real" number of heads */
325 byte sect; /* "real" sectors per track */
326 byte bios_head; /* BIOS/fdisk/LILO number of heads */
327 byte bios_sect; /* BIOS/fdisk/LILO sectors per track */
328 unsigned int bios_cyl; /* BIOS/fdisk/LILO number of cyls */
329 unsigned int cyl; /* "real" number of cyls */
330 unsigned long capacity; /* total number of sectors */
331 unsigned int drive_data; /* for use by tuneproc/selectproc as needed */
332 void *hwif; /* actually (ide_hwif_t *) */
333 wait_queue_head_t wqueue; /* used to wait for drive in open() */
334 struct hd_driveid *id; /* drive model identification info */
335 struct hd_struct *part; /* drive partition table */
336 char name[4]; /* drive name, such as "hda" */
337 void *driver; /* (ide_driver_t *) */
338 void *driver_data; /* extra driver data */
339 devfs_handle_t de; /* directory for device */
340 struct proc_dir_entry *proc; /* /proc/ide/ directory entry */
341 void *settings; /* /proc/ide/ drive settings */
342 char driver_req[10]; /* requests specific driver */
343 int last_lun; /* last logical unit */
344 int forced_lun; /* if hdxlun was given at boot */
345 int lun; /* logical unit */
346 int crc_count; /* crc counter to reduce drive speed */
347 byte quirk_list; /* drive is considered quirky if set for a specific host */
348 byte suspend_reset; /* drive suspend mode flag, soft-reset recovers */
349 byte init_speed; /* transfer rate set at boot */
350 byte current_speed; /* current transfer rate set */
351 byte dn; /* now wide spread use */
352 } ide_drive_t;
355 * An ide_dmaproc_t() initiates/aborts DMA read/write operations on a drive.
357 * The caller is assumed to have selected the drive and programmed the drive's
358 * sector address using CHS or LBA. All that remains is to prepare for DMA
359 * and then issue the actual read/write DMA/PIO command to the drive.
361 * Returns 0 if all went well.
362 * Returns 1 if DMA read/write could not be started, in which case the caller
363 * should either try again later, or revert to PIO for the current request.
365 typedef enum { ide_dma_read, ide_dma_write, ide_dma_begin,
366 ide_dma_end, ide_dma_check, ide_dma_on,
367 ide_dma_off, ide_dma_off_quietly, ide_dma_test_irq,
368 ide_dma_bad_drive, ide_dma_good_drive,
369 ide_dma_verbose, ide_dma_retune,
370 ide_dma_lostirq, ide_dma_timeout
371 } ide_dma_action_t;
373 typedef int (ide_dmaproc_t)(ide_dma_action_t, ide_drive_t *);
376 * An ide_tuneproc_t() is used to set the speed of an IDE interface
377 * to a particular PIO mode. The "byte" parameter is used
378 * to select the PIO mode by number (0,1,2,3,4,5), and a value of 255
379 * indicates that the interface driver should "auto-tune" the PIO mode
380 * according to the drive capabilities in drive->id;
382 * Not all interface types support tuning, and not all of those
383 * support all possible PIO settings. They may silently ignore
384 * or round values as they see fit.
386 typedef void (ide_tuneproc_t) (ide_drive_t *, byte);
387 typedef int (ide_speedproc_t) (ide_drive_t *, byte);
390 * This is used to provide support for strange interfaces
392 typedef void (ide_selectproc_t) (ide_drive_t *);
393 typedef void (ide_resetproc_t) (ide_drive_t *);
394 typedef int (ide_quirkproc_t) (ide_drive_t *);
395 typedef void (ide_intrproc_t) (ide_drive_t *);
396 typedef void (ide_maskproc_t) (ide_drive_t *, int);
397 typedef void (ide_rw_proc_t) (ide_drive_t *, ide_dma_action_t);
400 * hwif_chipset_t is used to keep track of the specific hardware
401 * chipset used by each IDE interface, if known.
403 typedef enum { ide_unknown, ide_generic, ide_pci,
404 ide_cmd640, ide_dtc2278, ide_ali14xx,
405 ide_qd6580, ide_umc8672, ide_ht6560b,
406 ide_pdc4030, ide_rz1000, ide_trm290,
407 ide_cmd646, ide_cy82c693, ide_4drives,
408 ide_pmac
409 } hwif_chipset_t;
411 #ifdef CONFIG_BLK_DEV_IDEPCI
412 typedef struct ide_pci_devid_s {
413 unsigned short vid;
414 unsigned short did;
415 } ide_pci_devid_t;
417 #define IDE_PCI_DEVID_NULL ((ide_pci_devid_t){0,0})
418 #define IDE_PCI_DEVID_EQ(a,b) (a.vid == b.vid && a.did == b.did)
419 #endif /* CONFIG_BLK_DEV_IDEPCI */
421 typedef struct hwif_s {
422 struct hwif_s *next; /* for linked-list in ide_hwgroup_t */
423 void *hwgroup; /* actually (ide_hwgroup_t *) */
424 ide_ioreg_t io_ports[IDE_NR_PORTS]; /* task file registers */
425 hw_regs_t hw; /* Hardware info */
426 ide_drive_t drives[MAX_DRIVES]; /* drive info */
427 struct gendisk *gd; /* gendisk structure */
428 ide_tuneproc_t *tuneproc; /* routine to tune PIO mode for drives */
429 ide_speedproc_t *speedproc; /* routine to retune DMA modes for drives */
430 ide_selectproc_t *selectproc; /* tweaks hardware to select drive */
431 ide_resetproc_t *resetproc; /* routine to reset controller after a disk reset */
432 ide_intrproc_t *intrproc; /* special interrupt handling for shared pci interrupts */
433 ide_maskproc_t *maskproc; /* special host masking for drive selection */
434 ide_quirkproc_t *quirkproc; /* check host's drive quirk list */
435 ide_rw_proc_t *rwproc; /* adjust timing based upon rq->cmd direction */
436 ide_dmaproc_t *dmaproc; /* dma read/write/abort routine */
437 unsigned int *dmatable_cpu; /* dma physical region descriptor table (cpu view) */
438 dma_addr_t dmatable_dma; /* dma physical region descriptor table (dma view) */
439 struct scatterlist *sg_table; /* Scatter-gather list used to build the above */
440 int sg_nents; /* Current number of entries in it */
441 int sg_dma_direction; /* dma transfer direction */
442 struct hwif_s *mate; /* other hwif from same PCI chip */
443 unsigned long dma_base; /* base addr for dma ports */
444 unsigned dma_extra; /* extra addr for dma ports */
445 unsigned long config_data; /* for use by chipset-specific code */
446 unsigned long select_data; /* for use by chipset-specific code */
447 struct proc_dir_entry *proc; /* /proc/ide/ directory entry */
448 int irq; /* our irq number */
449 byte major; /* our major number */
450 char name[6]; /* name of interface, eg. "ide0" */
451 byte index; /* 0 for ide0; 1 for ide1; ... */
452 hwif_chipset_t chipset; /* sub-module for tuning.. */
453 unsigned noprobe : 1; /* don't probe for this interface */
454 unsigned present : 1; /* this interface exists */
455 unsigned serialized : 1; /* serialized operation with mate hwif */
456 unsigned sharing_irq: 1; /* 1 = sharing irq with another hwif */
457 unsigned reset : 1; /* reset after probe */
458 unsigned autodma : 1; /* automatically try to enable DMA at boot */
459 unsigned udma_four : 1; /* 1=ATA-66 capable, 0=default */
460 byte channel; /* for dual-port chips: 0=primary, 1=secondary */
461 #ifdef CONFIG_BLK_DEV_IDEPCI
462 struct pci_dev *pci_dev; /* for pci chipsets */
463 ide_pci_devid_t pci_devid; /* for pci chipsets: {VID,DID} */
464 #endif /* CONFIG_BLK_DEV_IDEPCI */
465 #if (DISK_RECOVERY_TIME > 0)
466 unsigned long last_time; /* time when previous rq was done */
467 #endif
468 byte straight8; /* Alan's straight 8 check */
469 void *hwif_data; /* extra hwif data */
470 } ide_hwif_t;
474 * Status returned from various ide_ functions
476 typedef enum {
477 ide_stopped, /* no drive operation was started */
478 ide_started /* a drive operation was started, and a handler was set */
479 } ide_startstop_t;
482 * internal ide interrupt handler type
484 typedef ide_startstop_t (ide_handler_t)(ide_drive_t *);
487 * when ide_timer_expiry fires, invoke a handler of this type
488 * to decide what to do.
490 typedef int (ide_expiry_t)(ide_drive_t *);
492 typedef struct hwgroup_s {
493 ide_handler_t *handler;/* irq handler, if active */
494 volatile int busy; /* BOOL: protects all fields below */
495 int sleeping; /* BOOL: wake us up on timer expiry */
496 ide_drive_t *drive; /* current drive */
497 ide_hwif_t *hwif; /* ptr to current hwif in linked-list */
498 struct request *rq; /* current request */
499 struct timer_list timer; /* failsafe timer */
500 struct request wrq; /* local copy of current write rq */
501 unsigned long poll_timeout; /* timeout value during long polls */
502 ide_expiry_t *expiry; /* queried upon timeouts */
503 } ide_hwgroup_t;
506 * configurable drive settings
509 #define TYPE_INT 0
510 #define TYPE_INTA 1
511 #define TYPE_BYTE 2
512 #define TYPE_SHORT 3
514 #define SETTING_READ (1 << 0)
515 #define SETTING_WRITE (1 << 1)
516 #define SETTING_RW (SETTING_READ | SETTING_WRITE)
518 typedef int (ide_procset_t)(ide_drive_t *, int);
519 typedef struct ide_settings_s {
520 char *name;
521 int rw;
522 int read_ioctl;
523 int write_ioctl;
524 int data_type;
525 int min;
526 int max;
527 int mul_factor;
528 int div_factor;
529 void *data;
530 ide_procset_t *set;
531 int auto_remove;
532 struct ide_settings_s *next;
533 } ide_settings_t;
535 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);
536 void ide_remove_setting(ide_drive_t *drive, char *name);
537 ide_settings_t *ide_find_setting_by_name(ide_drive_t *drive, char *name);
538 int ide_read_setting(ide_drive_t *t, ide_settings_t *setting);
539 int ide_write_setting(ide_drive_t *drive, ide_settings_t *setting, int val);
540 void ide_add_generic_settings(ide_drive_t *drive);
543 * /proc/ide interface
545 typedef struct {
546 const char *name;
547 mode_t mode;
548 read_proc_t *read_proc;
549 write_proc_t *write_proc;
550 } ide_proc_entry_t;
552 #ifdef CONFIG_PROC_FS
553 void proc_ide_create(void);
554 void proc_ide_destroy(void);
555 void destroy_proc_ide_drives(ide_hwif_t *);
556 void create_proc_ide_interfaces(void);
557 void ide_add_proc_entries(struct proc_dir_entry *dir, ide_proc_entry_t *p, void *data);
558 void ide_remove_proc_entries(struct proc_dir_entry *dir, ide_proc_entry_t *p);
559 read_proc_t proc_ide_read_capacity;
560 read_proc_t proc_ide_read_geometry;
563 * Standard exit stuff:
565 #define PROC_IDE_READ_RETURN(page,start,off,count,eof,len) \
567 len -= off; \
568 if (len < count) { \
569 *eof = 1; \
570 if (len <= 0) \
571 return 0; \
572 } else \
573 len = count; \
574 *start = page + off; \
575 return len; \
577 #else
578 #define PROC_IDE_READ_RETURN(page,start,off,count,eof,len) return 0;
579 #endif
582 * Subdrivers support.
584 #define IDE_SUBDRIVER_VERSION 1
586 typedef int (ide_cleanup_proc)(ide_drive_t *);
587 typedef ide_startstop_t (ide_do_request_proc)(ide_drive_t *, struct request *, unsigned long);
588 typedef void (ide_end_request_proc)(byte, ide_hwgroup_t *);
589 typedef int (ide_ioctl_proc)(ide_drive_t *, struct inode *, struct file *, unsigned int, unsigned long);
590 typedef int (ide_open_proc)(struct inode *, struct file *, ide_drive_t *);
591 typedef void (ide_release_proc)(struct inode *, struct file *, ide_drive_t *);
592 typedef int (ide_check_media_change_proc)(ide_drive_t *);
593 typedef void (ide_revalidate_proc)(ide_drive_t *);
594 typedef void (ide_pre_reset_proc)(ide_drive_t *);
595 typedef unsigned long (ide_capacity_proc)(ide_drive_t *);
596 typedef ide_startstop_t (ide_special_proc)(ide_drive_t *);
597 typedef void (ide_setting_proc)(ide_drive_t *);
599 typedef struct ide_driver_s {
600 const char *name;
601 const char *version;
602 byte media;
603 unsigned busy : 1;
604 unsigned supports_dma : 1;
605 unsigned supports_dsc_overlap : 1;
606 ide_cleanup_proc *cleanup;
607 ide_do_request_proc *do_request;
608 ide_end_request_proc *end_request;
609 ide_ioctl_proc *ioctl;
610 ide_open_proc *open;
611 ide_release_proc *release;
612 ide_check_media_change_proc *media_change;
613 ide_revalidate_proc *revalidate;
614 ide_pre_reset_proc *pre_reset;
615 ide_capacity_proc *capacity;
616 ide_special_proc *special;
617 ide_proc_entry_t *proc;
618 } ide_driver_t;
620 #define DRIVER(drive) ((ide_driver_t *)((drive)->driver))
623 * IDE modules.
625 #define IDE_CHIPSET_MODULE 0 /* not supported yet */
626 #define IDE_PROBE_MODULE 1
627 #define IDE_DRIVER_MODULE 2
629 typedef int (ide_module_init_proc)(void);
631 typedef struct ide_module_s {
632 int type;
633 ide_module_init_proc *init;
634 void *info;
635 struct ide_module_s *next;
636 } ide_module_t;
639 * ide_hwifs[] is the master data structure used to keep track
640 * of just about everything in ide.c. Whenever possible, routines
641 * should be using pointers to a drive (ide_drive_t *) or
642 * pointers to a hwif (ide_hwif_t *), rather than indexing this
643 * structure directly (the allocation/layout may change!).
646 #ifndef _IDE_C
647 extern ide_hwif_t ide_hwifs[]; /* master data repository */
648 extern ide_module_t *ide_modules;
649 extern ide_module_t *ide_probe;
650 #endif
653 * We need blk.h, but we replace its end_request by our own version.
655 #define IDE_DRIVER /* Toggle some magic bits in blk.h */
656 #define LOCAL_END_REQUEST /* Don't generate end_request in blk.h */
657 #include <linux/blk.h>
659 void ide_end_request(byte uptodate, ide_hwgroup_t *hwgroup);
662 * This is used for (nearly) all data transfers from/to the IDE interface
663 * FIXME for 2.5, to a pointer pass verses memcpy........
665 void ide_input_data (ide_drive_t *drive, void *buffer, unsigned int wcount);
666 void ide_output_data (ide_drive_t *drive, void *buffer, unsigned int wcount);
669 * This is used for (nearly) all ATAPI data transfers from/to the IDE interface
670 * FIXME for 2.5, to a pointer pass verses memcpy........
672 void atapi_input_bytes (ide_drive_t *drive, void *buffer, unsigned int bytecount);
673 void atapi_output_bytes (ide_drive_t *drive, void *buffer, unsigned int bytecount);
676 * This is used on exit from the driver, to designate the next irq handler
677 * and also to start the safety timer.
679 void ide_set_handler (ide_drive_t *drive, ide_handler_t *handler, unsigned int timeout, ide_expiry_t *expiry);
682 * Error reporting, in human readable form (luxurious, but a memory hog).
684 byte ide_dump_status (ide_drive_t *drive, const char *msg, byte stat);
687 * ide_error() takes action based on the error returned by the controller.
688 * The caller should return immediately after invoking this.
690 ide_startstop_t ide_error (ide_drive_t *drive, const char *msg, byte stat);
693 * Issue a simple drive command
694 * The drive must be selected beforehand.
696 void ide_cmd(ide_drive_t *drive, byte cmd, byte nsect, ide_handler_t *handler);
699 * ide_fixstring() cleans up and (optionally) byte-swaps a text string,
700 * removing leading/trailing blanks and compressing internal blanks.
701 * It is primarily used to tidy up the model name/number fields as
702 * returned by the WIN_[P]IDENTIFY commands.
704 void ide_fixstring (byte *s, const int bytecount, const int byteswap);
707 * This routine busy-waits for the drive status to be not "busy".
708 * It then checks the status for all of the "good" bits and none
709 * of the "bad" bits, and if all is okay it returns 0. All other
710 * cases return 1 after doing "*startstop = ide_error()", and the
711 * caller should return the updated value of "startstop" in this case.
712 * "startstop" is unchanged when the function returns 0;
714 int ide_wait_stat (ide_startstop_t *startstop, ide_drive_t *drive, byte good, byte bad, unsigned long timeout);
716 int ide_wait_noerr (ide_drive_t *drive, byte good, byte bad, unsigned long timeout);
719 * This routine is called from the partition-table code in genhd.c
720 * to "convert" a drive to a logical geometry with fewer than 1024 cyls.
722 int ide_xlate_1024 (kdev_t, int, int, const char *);
725 * Convert kdev_t structure into ide_drive_t * one.
727 ide_drive_t *get_info_ptr (kdev_t i_rdev);
730 * Return the current idea about the total capacity of this drive.
732 unsigned long current_capacity (ide_drive_t *drive);
735 * Start a reset operation for an IDE interface.
736 * The caller should return immediately after invoking this.
738 ide_startstop_t ide_do_reset (ide_drive_t *);
741 * This function is intended to be used prior to invoking ide_do_drive_cmd().
743 void ide_init_drive_cmd (struct request *rq);
746 * "action" parameter type for ide_do_drive_cmd() below.
748 typedef enum {
749 ide_wait, /* insert rq at end of list, and wait for it */
750 ide_next, /* insert rq immediately after current request */
751 ide_preempt, /* insert rq in front of current request */
752 ide_end /* insert rq at end of list, but don't wait for it */
753 } ide_action_t;
756 * This function issues a special IDE device request
757 * onto the request queue.
759 * If action is ide_wait, then the rq is queued at the end of the
760 * request queue, and the function sleeps until it has been processed.
761 * This is for use when invoked from an ioctl handler.
763 * If action is ide_preempt, then the rq is queued at the head of
764 * the request queue, displacing the currently-being-processed
765 * request and this function returns immediately without waiting
766 * for the new rq to be completed. This is VERY DANGEROUS, and is
767 * intended for careful use by the ATAPI tape/cdrom driver code.
769 * If action is ide_next, then the rq is queued immediately after
770 * the currently-being-processed-request (if any), and the function
771 * returns without waiting for the new rq to be completed. As above,
772 * This is VERY DANGEROUS, and is intended for careful use by the
773 * ATAPI tape/cdrom driver code.
775 * If action is ide_end, then the rq is queued at the end of the
776 * request queue, and the function returns immediately without waiting
777 * for the new rq to be completed. This is again intended for careful
778 * use by the ATAPI tape/cdrom driver code.
780 int ide_do_drive_cmd (ide_drive_t *drive, struct request *rq, ide_action_t action);
783 * Clean up after success/failure of an explicit drive cmd.
784 * stat/err are used only when (HWGROUP(drive)->rq->cmd == IDE_DRIVE_CMD).
786 void ide_end_drive_cmd (ide_drive_t *drive, byte stat, byte err);
789 * Issue ATA command and wait for completion.
791 int ide_wait_cmd (ide_drive_t *drive, int cmd, int nsect, int feature, int sectors, byte *buf);
792 int ide_wait_cmd_task (ide_drive_t *drive, byte *buf);
794 void ide_delay_50ms (void);
795 int system_bus_clock(void);
797 byte ide_auto_reduce_xfer (ide_drive_t *drive);
798 int ide_driveid_update (ide_drive_t *drive);
799 int ide_ata66_check (ide_drive_t *drive, byte cmd, byte nsect, byte feature);
800 int ide_config_drive_speed (ide_drive_t *drive, byte speed);
801 byte eighty_ninty_three (ide_drive_t *drive);
802 int set_transfer (ide_drive_t *drive, byte cmd, byte nsect, byte feature);
805 * ide_system_bus_speed() returns what we think is the system VESA/PCI
806 * bus speed (in MHz). This is used for calculating interface PIO timings.
807 * The default is 40 for known PCI systems, 50 otherwise.
808 * The "idebus=xx" parameter can be used to override this value.
810 int ide_system_bus_speed (void);
813 * ide_multwrite() transfers a block of up to mcount sectors of data
814 * to a drive as part of a disk multwrite operation.
816 int ide_multwrite (ide_drive_t *drive, unsigned int mcount);
819 * ide_stall_queue() can be used by a drive to give excess bandwidth back
820 * to the hwgroup by sleeping for timeout jiffies.
822 void ide_stall_queue (ide_drive_t *drive, unsigned long timeout);
825 * ide_get_queue() returns the queue which corresponds to a given device.
827 request_queue_t *ide_get_queue (kdev_t dev);
830 * CompactFlash cards and their brethern pretend to be removable hard disks,
831 * but they never have a slave unit, and they don't have doorlock mechanisms.
832 * This test catches them, and is invoked elsewhere when setting appropriate config bits.
834 int drive_is_flashcard (ide_drive_t *drive);
836 int ide_spin_wait_hwgroup (ide_drive_t *drive);
837 void ide_timer_expiry (unsigned long data);
838 void ide_intr (int irq, void *dev_id, struct pt_regs *regs);
839 void do_ide_request (request_queue_t * q);
840 void ide_init_subdrivers (void);
842 #ifndef _IDE_C
843 extern struct block_device_operations ide_fops[];
844 extern ide_proc_entry_t generic_subdriver_entries[];
845 #endif
847 #ifdef _IDE_C
848 #ifdef CONFIG_BLK_DEV_IDE
849 int ideprobe_init (void);
850 #endif /* CONFIG_BLK_DEV_IDE */
851 #ifdef CONFIG_BLK_DEV_IDEDISK
852 int idedisk_init (void);
853 #endif /* CONFIG_BLK_DEV_IDEDISK */
854 #ifdef CONFIG_BLK_DEV_IDECD
855 int ide_cdrom_init (void);
856 #endif /* CONFIG_BLK_DEV_IDECD */
857 #ifdef CONFIG_BLK_DEV_IDETAPE
858 int idetape_init (void);
859 #endif /* CONFIG_BLK_DEV_IDETAPE */
860 #ifdef CONFIG_BLK_DEV_IDEFLOPPY
861 int idefloppy_init (void);
862 #endif /* CONFIG_BLK_DEV_IDEFLOPPY */
863 #ifdef CONFIG_BLK_DEV_IDESCSI
864 int idescsi_init (void);
865 #endif /* CONFIG_BLK_DEV_IDESCSI */
866 #endif /* _IDE_C */
868 int ide_register_module (ide_module_t *module);
869 void ide_unregister_module (ide_module_t *module);
870 ide_drive_t *ide_scan_devices (byte media, const char *name, ide_driver_t *driver, int n);
871 int ide_register_subdriver (ide_drive_t *drive, ide_driver_t *driver, int version);
872 int ide_unregister_subdriver (ide_drive_t *drive);
873 int ide_replace_subdriver(ide_drive_t *drive, const char *driver);
875 #ifdef CONFIG_BLK_DEV_IDEPCI
876 #define ON_BOARD 1
877 #define NEVER_BOARD 0
878 #ifdef CONFIG_BLK_DEV_OFFBOARD
879 # define OFF_BOARD ON_BOARD
880 #else /* CONFIG_BLK_DEV_OFFBOARD */
881 # define OFF_BOARD NEVER_BOARD
882 #endif /* CONFIG_BLK_DEV_OFFBOARD */
884 unsigned long ide_find_free_region (unsigned short size) __init;
885 void ide_scan_pcibus (int scan_direction) __init;
886 #endif
887 #ifdef CONFIG_BLK_DEV_IDEDMA
888 #define BAD_DMA_DRIVE 0
889 #define GOOD_DMA_DRIVE 1
890 int ide_build_dmatable (ide_drive_t *drive, ide_dma_action_t func);
891 void ide_destroy_dmatable (ide_drive_t *drive);
892 ide_startstop_t ide_dma_intr (ide_drive_t *drive);
893 int check_drive_lists (ide_drive_t *drive, int good_bad);
894 int report_drive_dmaing (ide_drive_t *drive);
895 int ide_dmaproc (ide_dma_action_t func, ide_drive_t *drive);
896 int ide_release_dma (ide_hwif_t *hwif);
897 void ide_setup_dma (ide_hwif_t *hwif, unsigned long dmabase, unsigned int num_ports) __init;
898 unsigned long ide_get_or_set_dma_base (ide_hwif_t *hwif, int extra, const char *name) __init;
899 #endif
901 void hwif_unregister (ide_hwif_t *hwif);
903 #endif /* _IDE_H */