4 * linux/include/linux/ide.h
6 * Copyright (C) 1994-1998 Linus Torvalds & authors
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 */
41 #ifndef SUPPORT_VLB_SYNC /* 1 to support weird 32-bit chips */
42 #define SUPPORT_VLB_SYNC 1 /* 0 to reduce kernel size */
44 #ifndef DISK_RECOVERY_TIME /* off=0; on=access_delay_time */
45 #define DISK_RECOVERY_TIME 0 /* for hardware that needs it */
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 */
50 #ifndef FANCY_STATUS_DUMPS /* 1 for human-readable drive errors */
51 #define FANCY_STATUS_DUMPS 1 /* 0 to reduce kernel size */
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 */
59 #endif /* CONFIG_BLK_DEV_CMD640 */
62 * IDE_DRIVE_CMD is used to implement many features of the hdparm utility
64 #define IDE_DRIVE_CMD 99 /* (magic) undef to reduce kernel size*/
67 * "No user-serviceable parts" beyond this point :)
68 *****************************************************************************/
70 typedef unsigned char byte
; /* used everywhere */
73 * Probably not wise to fiddle with these
75 #define ERROR_MAX 8 /* Max read/write errors per sector */
76 #define ERROR_RESET 3 /* Reset controller every 4th retry */
77 #define ERROR_RECAL 1 /* Recalibrate every 2nd retry */
80 * Ensure that various configuration flags have compatible settings
86 #define HWIF(drive) ((ide_hwif_t *)((drive)->hwif))
87 #define HWGROUP(drive) ((ide_hwgroup_t *)(HWIF(drive)->hwgroup))
90 * Definitions for accessing IDE controller registers
92 #define IDE_NR_PORTS (10)
94 #define IDE_DATA_OFFSET (0)
95 #define IDE_ERROR_OFFSET (1)
96 #define IDE_NSECTOR_OFFSET (2)
97 #define IDE_SECTOR_OFFSET (3)
98 #define IDE_LCYL_OFFSET (4)
99 #define IDE_HCYL_OFFSET (5)
100 #define IDE_SELECT_OFFSET (6)
101 #define IDE_STATUS_OFFSET (7)
102 #define IDE_CONTROL_OFFSET (8)
103 #define IDE_IRQ_OFFSET (9)
105 #define IDE_FEATURE_OFFSET IDE_ERROR_OFFSET
106 #define IDE_COMMAND_OFFSET IDE_STATUS_OFFSET
108 #define IDE_DATA_REG (HWIF(drive)->io_ports[IDE_DATA_OFFSET])
109 #define IDE_ERROR_REG (HWIF(drive)->io_ports[IDE_ERROR_OFFSET])
110 #define IDE_NSECTOR_REG (HWIF(drive)->io_ports[IDE_NSECTOR_OFFSET])
111 #define IDE_SECTOR_REG (HWIF(drive)->io_ports[IDE_SECTOR_OFFSET])
112 #define IDE_LCYL_REG (HWIF(drive)->io_ports[IDE_LCYL_OFFSET])
113 #define IDE_HCYL_REG (HWIF(drive)->io_ports[IDE_HCYL_OFFSET])
114 #define IDE_SELECT_REG (HWIF(drive)->io_ports[IDE_SELECT_OFFSET])
115 #define IDE_STATUS_REG (HWIF(drive)->io_ports[IDE_STATUS_OFFSET])
116 #define IDE_CONTROL_REG (HWIF(drive)->io_ports[IDE_CONTROL_OFFSET])
117 #define IDE_IRQ_REG (HWIF(drive)->io_ports[IDE_IRQ_OFFSET])
119 #define IDE_FEATURE_REG IDE_ERROR_REG
120 #define IDE_COMMAND_REG IDE_STATUS_REG
121 #define IDE_ALTSTATUS_REG IDE_CONTROL_REG
122 #define IDE_IREASON_REG IDE_NSECTOR_REG
123 #define IDE_BCOUNTL_REG IDE_LCYL_REG
124 #define IDE_BCOUNTH_REG IDE_HCYL_REG
126 #ifdef REALLY_FAST_IO
127 #define OUT_BYTE(b,p) outb((b),(p))
128 #define IN_BYTE(p) (byte)inb(p)
130 #define OUT_BYTE(b,p) outb_p((b),(p))
131 #define IN_BYTE(p) (byte)inb_p(p)
132 #endif /* REALLY_FAST_IO */
134 #define GET_ERR() IN_BYTE(IDE_ERROR_REG)
135 #define GET_STAT() IN_BYTE(IDE_STATUS_REG)
136 #define OK_STAT(stat,good,bad) (((stat)&((good)|(bad)))==(good))
137 #define BAD_R_STAT (BUSY_STAT | ERR_STAT)
138 #define BAD_W_STAT (BAD_R_STAT | WRERR_STAT)
139 #define BAD_STAT (BAD_R_STAT | DRQ_STAT)
140 #define DRIVE_READY (READY_STAT | SEEK_STAT)
141 #define DATA_READY (DRQ_STAT)
144 * Some more useful definitions
146 #define IDE_MAJOR_NAME "hd" /* the same for all i/f; see also genhd.c */
147 #define MAJOR_NAME IDE_MAJOR_NAME
148 #define PARTN_BITS 6 /* number of minor dev bits for partitions */
149 #define PARTN_MASK ((1<<PARTN_BITS)-1) /* a useful bit mask */
150 #define MAX_DRIVES 2 /* per interface; 2 assumed by lots of code */
151 #define SECTOR_WORDS (512 / 4) /* number of 32bit words per sector */
152 #define IDE_LARGE_SEEK(b1,b2,t) (((b1) > (b2) + (t)) || ((b2) > (b1) + (t)))
153 #define IDE_MIN(a,b) ((a)<(b) ? (a):(b))
154 #define IDE_MAX(a,b) ((a)>(b) ? (a):(b))
157 * Timeouts for various operations:
159 #define WAIT_DRQ (5*HZ/100) /* 50msec - spec allows up to 20ms */
160 #if defined(CONFIG_APM) || defined(CONFIG_APM_MODULE)
161 #define WAIT_READY (5*HZ) /* 5sec - some laptops are very slow */
163 #define WAIT_READY (3*HZ/100) /* 30msec - should be instantaneous */
164 #endif /* CONFIG_APM || CONFIG_APM_MODULE */
165 #define WAIT_PIDENTIFY (10*HZ) /* 10sec - should be less than 3ms (?)
166 if all ATAPI CD is closed at boot */
167 #define WAIT_WORSTCASE (30*HZ) /* 30sec - worst case when spinning up */
168 #define WAIT_CMD (10*HZ) /* 10sec - maximum wait for an IRQ to happen */
169 #define WAIT_MIN_SLEEP (2*HZ/100) /* 20msec - minimum sleep time */
171 #define SELECT_DRIVE(hwif,drive) \
173 if (hwif->selectproc) \
174 hwif->selectproc(drive); \
175 OUT_BYTE((drive)->select.all, hwif->io_ports[IDE_SELECT_OFFSET]); \
179 * Check for an interrupt and acknowledge the interrupt status
182 typedef int (ide_ack_intr_t
)(struct hwif_s
*);
189 * Structure to hold all information about the location of this port
191 typedef struct hw_regs_s
{
192 ide_ioreg_t io_ports
[IDE_NR_PORTS
]; /* task file registers */
193 int irq
; /* our irq number */
194 int dma
; /* our dma entry */
195 ide_ack_intr_t
*ack_intr
; /* acknowledge interrupt */
196 void *priv
; /* interface specific data */
200 * Register new hardware with ide
202 int ide_register_hw(hw_regs_t
*hw
, struct hwif_s
**hwifp
);
205 * Set up hw_regs_t structure before calling ide_register_hw (optional)
207 void ide_setup_ports( hw_regs_t
*hw
,
212 ide_ack_intr_t
*ack_intr
,
218 * Now for the data we need to maintain per-drive: ide_drive_t
221 #define ide_scsi 0x21
222 #define ide_disk 0x20
223 #define ide_optical 0x7
224 #define ide_cdrom 0x5
226 #define ide_floppy 0x0
229 unsigned all
: 8; /* all of the bits together */
231 unsigned set_geometry
: 1; /* respecify drive geometry */
232 unsigned recalibrate
: 1; /* seek to cyl 0 */
233 unsigned set_multmode
: 1; /* set multmode count */
234 unsigned set_tune
: 1; /* tune interface for drive */
235 unsigned reserved
: 4; /* unused */
239 typedef struct ide_drive_s
{
240 request_queue_t queue
; /* request queue */
241 struct ide_drive_s
*next
; /* circular list of hwgroup drives */
242 unsigned long sleep
; /* sleep until this time */
243 unsigned long service_start
; /* time we started last request */
244 unsigned long service_time
; /* service time of last request */
245 unsigned long timeout
; /* max time to wait for irq */
246 special_t special
; /* special action flags */
247 byte keep_settings
; /* restore settings after drive reset */
248 byte using_dma
; /* disk is using dma for read/write */
249 byte waiting_for_dma
; /* dma currently in progress */
250 byte unmask
; /* flag: okay to unmask other irqs */
251 byte slow
; /* flag: slow data port */
252 byte bswap
; /* flag: byte swap data */
253 byte dsc_overlap
; /* flag: DSC overlap */
254 byte nice1
; /* flag: give potential excess bandwidth */
255 unsigned present
: 1; /* drive is physically present */
256 unsigned noprobe
: 1; /* from: hdx=noprobe */
257 unsigned busy
: 1; /* currently doing revalidate_disk() */
258 unsigned removable
: 1; /* 1 if need to do check_media_change */
259 unsigned forced_geom
: 1; /* 1 if hdx=c,h,s was given at boot */
260 unsigned no_unmask
: 1; /* disallow setting unmask bit */
261 unsigned no_io_32bit
: 1; /* disallow enabling 32bit I/O */
262 unsigned nobios
: 1; /* flag: do not probe bios for drive */
263 unsigned revalidate
: 1; /* request revalidation */
264 unsigned atapi_overlap
: 1; /* flag: ATAPI overlap (not supported) */
265 unsigned nice0
: 1; /* flag: give obvious excess bandwidth */
266 unsigned nice2
: 1; /* flag: give a share in our own bandwidth */
267 unsigned doorlocking
: 1; /* flag: for removable only: door lock/unlock works */
268 unsigned autotune
: 2; /* 1=autotune, 2=noautotune, 0=default */
269 unsigned remap_0_to_1
: 2; /* 0=remap if ezdrive, 1=remap, 2=noremap */
270 unsigned ata_flash
: 1; /* 1=present, 0=default */
271 byte scsi
; /* 0=default, 1=skip current ide-subdriver for ide-scsi emulation */
272 byte media
; /* disk, cdrom, tape, floppy, ... */
273 select_t select
; /* basic drive/head select reg value */
274 byte ctl
; /* "normal" value for IDE_CONTROL_REG */
275 byte ready_stat
; /* min status value for drive ready */
276 byte mult_count
; /* current multiple sector setting */
277 byte mult_req
; /* requested multiple sector setting */
278 byte tune_req
; /* requested drive tuning setting */
279 byte io_32bit
; /* 0=16-bit, 1=32-bit, 2/3=32bit+sync */
280 byte bad_wstat
; /* used for ignoring WRERR_STAT */
281 byte nowerr
; /* used for ignoring WRERR_STAT */
282 byte sect0
; /* offset of first sector for DM6:DDO */
283 byte usage
; /* current "open()" count for drive */
284 byte head
; /* "real" number of heads */
285 byte sect
; /* "real" sectors per track */
286 byte bios_head
; /* BIOS/fdisk/LILO number of heads */
287 byte bios_sect
; /* BIOS/fdisk/LILO sectors per track */
288 unsigned int bios_cyl
; /* BIOS/fdisk/LILO number of cyls */
289 unsigned int cyl
; /* "real" number of cyls */
290 unsigned long capacity
; /* total number of sectors */
291 unsigned int drive_data
; /* for use by tuneproc/selectproc as needed */
292 void *hwif
; /* actually (ide_hwif_t *) */
293 wait_queue_head_t wqueue
; /* used to wait for drive in open() */
294 struct hd_driveid
*id
; /* drive model identification info */
295 struct hd_struct
*part
; /* drive partition table */
296 char name
[4]; /* drive name, such as "hda" */
297 void *driver
; /* (ide_driver_t *) */
298 void *driver_data
; /* extra driver data */
299 devfs_handle_t de
; /* directory for device */
300 struct proc_dir_entry
*proc
; /* /proc/ide/ directory entry */
301 void *settings
; /* /proc/ide/ drive settings */
302 char driver_req
[10]; /* requests specific driver */
304 struct thresholds_s
*smart_thresholds
;
305 struct values_s
*smart_values
;
307 thresholds_t smart_thresholds
;
308 values_t smart_values
;
310 int last_lun
; /* last logical unit */
311 int forced_lun
; /* if hdxlun was given at boot */
315 * An ide_dmaproc_t() initiates/aborts DMA read/write operations on a drive.
317 * The caller is assumed to have selected the drive and programmed the drive's
318 * sector address using CHS or LBA. All that remains is to prepare for DMA
319 * and then issue the actual read/write DMA/PIO command to the drive.
321 * Returns 0 if all went well.
322 * Returns 1 if DMA read/write could not be started, in which case the caller
323 * should either try again later, or revert to PIO for the current request.
325 typedef enum { ide_dma_read
, ide_dma_write
, ide_dma_begin
,
326 ide_dma_end
, ide_dma_check
, ide_dma_on
,
327 ide_dma_off
, ide_dma_off_quietly
, ide_dma_test_irq
,
328 ide_dma_bad_drive
, ide_dma_good_drive
,
329 ide_dma_lostirq
, ide_dma_timeout
332 typedef int (ide_dmaproc_t
)(ide_dma_action_t
, ide_drive_t
*);
335 * An ide_tuneproc_t() is used to set the speed of an IDE interface
336 * to a particular PIO mode. The "byte" parameter is used
337 * to select the PIO mode by number (0,1,2,3,4,5), and a value of 255
338 * indicates that the interface driver should "auto-tune" the PIO mode
339 * according to the drive capabilities in drive->id;
341 * Not all interface types support tuning, and not all of those
342 * support all possible PIO settings. They may silently ignore
343 * or round values as they see fit.
345 typedef void (ide_tuneproc_t
)(ide_drive_t
*, byte
);
348 * This is used to provide support for strange interfaces
350 typedef void (ide_selectproc_t
) (ide_drive_t
*);
351 typedef void (ide_resetproc_t
) (ide_drive_t
*);
354 * hwif_chipset_t is used to keep track of the specific hardware
355 * chipset used by each IDE interface, if known.
357 typedef enum { ide_unknown
, ide_generic
, ide_pci
,
358 ide_cmd640
, ide_dtc2278
, ide_ali14xx
,
359 ide_qd6580
, ide_umc8672
, ide_ht6560b
,
360 ide_pdc4030
, ide_rz1000
, ide_trm290
,
361 ide_cmd646
, ide_cy82c693
, ide_4drives
,
365 #ifdef CONFIG_BLK_DEV_IDEPCI
366 typedef struct ide_pci_devid_s
{
371 #define IDE_PCI_DEVID_NULL ((ide_pci_devid_t){0,0})
372 #define IDE_PCI_DEVID_EQ(a,b) (a.vid == b.vid && a.did == b.did)
373 #endif /* CONFIG_BLK_DEV_IDEPCI */
375 typedef struct hwif_s
{
376 struct hwif_s
*next
; /* for linked-list in ide_hwgroup_t */
377 void *hwgroup
; /* actually (ide_hwgroup_t *) */
378 ide_ioreg_t io_ports
[IDE_NR_PORTS
]; /* task file registers */
379 hw_regs_t hw
; /* Hardware info */
380 ide_drive_t drives
[MAX_DRIVES
]; /* drive info */
381 struct gendisk
*gd
; /* gendisk structure */
382 ide_tuneproc_t
*tuneproc
; /* routine to tune PIO mode for drives */
383 ide_selectproc_t
*selectproc
; /* tweaks hardware to select drive */
384 ide_resetproc_t
*resetproc
; /* routine to reset controller after a disk reset */
385 ide_dmaproc_t
*dmaproc
; /* dma read/write/abort routine */
386 unsigned int *dmatable_cpu
; /* dma physical region descriptor table (cpu view) */
387 u32 dmatable_dma
; /* dma physical region descriptor table (dma view) */
388 struct scatterlist
*sg_table
; /* Scatter-gather list used to build the above */
389 int sg_nents
; /* Current number of entries in it */
390 int sg_dma_direction
; /* dma transfer direction */
391 struct hwif_s
*mate
; /* other hwif from same PCI chip */
392 unsigned long dma_base
; /* base addr for dma ports */
393 unsigned dma_extra
; /* extra addr for dma ports */
394 unsigned long config_data
; /* for use by chipset-specific code */
395 unsigned long select_data
; /* for use by chipset-specific code */
396 struct proc_dir_entry
*proc
; /* /proc/ide/ directory entry */
397 int irq
; /* our irq number */
398 byte major
; /* our major number */
399 char name
[6]; /* name of interface, eg. "ide0" */
400 byte index
; /* 0 for ide0; 1 for ide1; ... */
401 hwif_chipset_t chipset
; /* sub-module for tuning.. */
402 unsigned noprobe
: 1; /* don't probe for this interface */
403 unsigned present
: 1; /* this interface exists */
404 unsigned serialized
: 1; /* serialized operation with mate hwif */
405 unsigned sharing_irq
: 1; /* 1 = sharing irq with another hwif */
406 unsigned reset
: 1; /* reset after probe */
407 unsigned autodma
: 1; /* automatically try to enable DMA at boot */
408 unsigned udma_four
: 1; /* 1=ATA-66 capable, 0=default */
409 byte channel
; /* for dual-port chips: 0=primary, 1=secondary */
410 #ifdef CONFIG_BLK_DEV_IDEPCI
411 struct pci_dev
*pci_dev
; /* for pci chipsets */
412 ide_pci_devid_t pci_devid
; /* for pci chipsets: {VID,DID} */
413 #endif /* CONFIG_BLK_DEV_IDEPCI */
414 #if (DISK_RECOVERY_TIME > 0)
415 unsigned long last_time
; /* time when previous rq was done */
420 * Status returned from various ide_ functions
423 ide_stopped
, /* no drive operation was started */
424 ide_started
/* a drive operation was started, and a handler was set */
428 * internal ide interrupt handler type
430 typedef ide_startstop_t (ide_handler_t
)(ide_drive_t
*);
433 * when ide_timer_expiry fires, invoke a handler of this type
434 * to decide what to do.
436 typedef int (ide_expiry_t
)(ide_drive_t
*);
438 typedef struct hwgroup_s
{
439 ide_handler_t
*handler
;/* irq handler, if active */
440 volatile int busy
; /* BOOL: protects all fields below */
441 int sleeping
; /* BOOL: wake us up on timer expiry */
442 ide_drive_t
*drive
; /* current drive */
443 ide_hwif_t
*hwif
; /* ptr to current hwif in linked-list */
444 struct request
*rq
; /* current request */
445 struct timer_list timer
; /* failsafe timer */
446 struct request wrq
; /* local copy of current write rq */
447 unsigned long poll_timeout
; /* timeout value during long polls */
448 ide_expiry_t
*expiry
; /* queried upon timeouts */
452 * configurable drive settings
460 #define SETTING_READ (1 << 0)
461 #define SETTING_WRITE (1 << 1)
462 #define SETTING_RW (SETTING_READ | SETTING_WRITE)
464 typedef int (ide_procset_t
)(ide_drive_t
*, int);
465 typedef struct ide_settings_s
{
478 struct ide_settings_s
*next
;
481 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
);
482 void ide_remove_setting(ide_drive_t
*drive
, char *name
);
483 ide_settings_t
*ide_find_setting_by_name(ide_drive_t
*drive
, char *name
);
484 int ide_read_setting(ide_drive_t
*t
, ide_settings_t
*setting
);
485 int ide_write_setting(ide_drive_t
*drive
, ide_settings_t
*setting
, int val
);
486 void ide_add_generic_settings(ide_drive_t
*drive
);
489 * /proc/ide interface
494 read_proc_t
*read_proc
;
495 write_proc_t
*write_proc
;
498 #ifdef CONFIG_PROC_FS
499 void proc_ide_create(void);
500 void proc_ide_destroy(void);
501 void destroy_proc_ide_drives(ide_hwif_t
*);
502 void create_proc_ide_interfaces(void);
503 void ide_add_proc_entries(struct proc_dir_entry
*dir
, ide_proc_entry_t
*p
, void *data
);
504 void ide_remove_proc_entries(struct proc_dir_entry
*dir
, ide_proc_entry_t
*p
);
505 read_proc_t proc_ide_read_capacity
;
506 read_proc_t proc_ide_read_geometry
;
509 * Standard exit stuff:
511 #define PROC_IDE_READ_RETURN(page,start,off,count,eof,len) \
520 *start = page + off; \
524 #define PROC_IDE_READ_RETURN(page,start,off,count,eof,len) return 0;
528 * Subdrivers support.
530 #define IDE_SUBDRIVER_VERSION 1
532 typedef int (ide_cleanup_proc
)(ide_drive_t
*);
533 typedef ide_startstop_t (ide_do_request_proc
)(ide_drive_t
*, struct request
*, unsigned long);
534 typedef void (ide_end_request_proc
)(byte
, ide_hwgroup_t
*);
535 typedef int (ide_ioctl_proc
)(ide_drive_t
*, struct inode
*, struct file
*, unsigned int, unsigned long);
536 typedef int (ide_open_proc
)(struct inode
*, struct file
*, ide_drive_t
*);
537 typedef void (ide_release_proc
)(struct inode
*, struct file
*, ide_drive_t
*);
538 typedef int (ide_check_media_change_proc
)(ide_drive_t
*);
539 typedef void (ide_pre_reset_proc
)(ide_drive_t
*);
540 typedef unsigned long (ide_capacity_proc
)(ide_drive_t
*);
541 typedef ide_startstop_t (ide_special_proc
)(ide_drive_t
*);
542 typedef void (ide_setting_proc
)(ide_drive_t
*);
544 typedef struct ide_driver_s
{
549 unsigned supports_dma
: 1;
550 unsigned supports_dsc_overlap
: 1;
551 ide_cleanup_proc
*cleanup
;
552 ide_do_request_proc
*do_request
;
553 ide_end_request_proc
*end_request
;
554 ide_ioctl_proc
*ioctl
;
556 ide_release_proc
*release
;
557 ide_check_media_change_proc
*media_change
;
558 ide_pre_reset_proc
*pre_reset
;
559 ide_capacity_proc
*capacity
;
560 ide_special_proc
*special
;
561 ide_proc_entry_t
*proc
;
564 #define DRIVER(drive) ((ide_driver_t *)((drive)->driver))
569 #define IDE_CHIPSET_MODULE 0 /* not supported yet */
570 #define IDE_PROBE_MODULE 1
571 #define IDE_DRIVER_MODULE 2
573 typedef int (ide_module_init_proc
)(void);
575 typedef struct ide_module_s
{
577 ide_module_init_proc
*init
;
579 struct ide_module_s
*next
;
583 * ide_hwifs[] is the master data structure used to keep track
584 * of just about everything in ide.c. Whenever possible, routines
585 * should be using pointers to a drive (ide_drive_t *) or
586 * pointers to a hwif (ide_hwif_t *), rather than indexing this
587 * structure directly (the allocation/layout may change!).
591 extern ide_hwif_t ide_hwifs
[]; /* master data repository */
592 extern ide_module_t
*ide_modules
;
593 extern ide_module_t
*ide_probe
;
597 * We need blk.h, but we replace its end_request by our own version.
599 #define IDE_DRIVER /* Toggle some magic bits in blk.h */
600 #define LOCAL_END_REQUEST /* Don't generate end_request in blk.h */
601 #include <linux/blk.h>
603 void ide_end_request(byte uptodate
, ide_hwgroup_t
*hwgroup
);
606 * This is used for (nearly) all data transfers from/to the IDE interface
608 void ide_input_data (ide_drive_t
*drive
, void *buffer
, unsigned int wcount
);
609 void ide_output_data (ide_drive_t
*drive
, void *buffer
, unsigned int wcount
);
612 * This is used for (nearly) all ATAPI data transfers from/to the IDE interface
614 void atapi_input_bytes (ide_drive_t
*drive
, void *buffer
, unsigned int bytecount
);
615 void atapi_output_bytes (ide_drive_t
*drive
, void *buffer
, unsigned int bytecount
);
618 * This is used on exit from the driver, to designate the next irq handler
619 * and also to start the safety timer.
621 void ide_set_handler (ide_drive_t
*drive
, ide_handler_t
*handler
, unsigned int timeout
, ide_expiry_t
*expiry
);
624 * Error reporting, in human readable form (luxurious, but a memory hog).
626 byte
ide_dump_status (ide_drive_t
*drive
, const char *msg
, byte stat
);
629 * ide_error() takes action based on the error returned by the controller.
630 * The caller should return immediately after invoking this.
632 ide_startstop_t
ide_error (ide_drive_t
*drive
, const char *msg
, byte stat
);
635 * Issue a simple drive command
636 * The drive must be selected beforehand.
638 void ide_cmd(ide_drive_t
*drive
, byte cmd
, byte nsect
, ide_handler_t
*handler
);
641 * ide_fixstring() cleans up and (optionally) byte-swaps a text string,
642 * removing leading/trailing blanks and compressing internal blanks.
643 * It is primarily used to tidy up the model name/number fields as
644 * returned by the WIN_[P]IDENTIFY commands.
646 void ide_fixstring (byte
*s
, const int bytecount
, const int byteswap
);
649 * This routine busy-waits for the drive status to be not "busy".
650 * It then checks the status for all of the "good" bits and none
651 * of the "bad" bits, and if all is okay it returns 0. All other
652 * cases return 1 after doing "*startstop = ide_error()", and the
653 * caller should return the updated value of "startstop" in this case.
654 * "startstop" is unchanged when the function returns 0;
656 int ide_wait_stat (ide_startstop_t
*startstop
, ide_drive_t
*drive
, byte good
, byte bad
, unsigned long timeout
);
658 int ide_wait_noerr (ide_drive_t
*drive
, byte good
, byte bad
, unsigned long timeout
);
661 * This routine is called from the partition-table code in genhd.c
662 * to "convert" a drive to a logical geometry with fewer than 1024 cyls.
664 int ide_xlate_1024 (kdev_t
, int, int, const char *);
667 * Convert kdev_t structure into ide_drive_t * one.
669 ide_drive_t
*get_info_ptr (kdev_t i_rdev
);
672 * Return the current idea about the total capacity of this drive.
674 unsigned long current_capacity (ide_drive_t
*drive
);
677 * Start a reset operation for an IDE interface.
678 * The caller should return immediately after invoking this.
680 ide_startstop_t
ide_do_reset (ide_drive_t
*);
683 * This function is intended to be used prior to invoking ide_do_drive_cmd().
685 void ide_init_drive_cmd (struct request
*rq
);
688 * "action" parameter type for ide_do_drive_cmd() below.
691 ide_wait
, /* insert rq at end of list, and wait for it */
692 ide_next
, /* insert rq immediately after current request */
693 ide_preempt
, /* insert rq in front of current request */
694 ide_end
/* insert rq at end of list, but don't wait for it */
698 * This function issues a special IDE device request
699 * onto the request queue.
701 * If action is ide_wait, then the rq is queued at the end of the
702 * request queue, and the function sleeps until it has been processed.
703 * This is for use when invoked from an ioctl handler.
705 * If action is ide_preempt, then the rq is queued at the head of
706 * the request queue, displacing the currently-being-processed
707 * request and this function returns immediately without waiting
708 * for the new rq to be completed. This is VERY DANGEROUS, and is
709 * intended for careful use by the ATAPI tape/cdrom driver code.
711 * If action is ide_next, then the rq is queued immediately after
712 * the currently-being-processed-request (if any), and the function
713 * returns without waiting for the new rq to be completed. As above,
714 * This is VERY DANGEROUS, and is intended for careful use by the
715 * ATAPI tape/cdrom driver code.
717 * If action is ide_end, then the rq is queued at the end of the
718 * request queue, and the function returns immediately without waiting
719 * for the new rq to be completed. This is again intended for careful
720 * use by the ATAPI tape/cdrom driver code.
722 int ide_do_drive_cmd (ide_drive_t
*drive
, struct request
*rq
, ide_action_t action
);
725 * Clean up after success/failure of an explicit drive cmd.
726 * stat/err are used only when (HWGROUP(drive)->rq->cmd == IDE_DRIVE_CMD).
728 void ide_end_drive_cmd (ide_drive_t
*drive
, byte stat
, byte err
);
731 * Issue ATA command and wait for completion.
733 int ide_wait_cmd (ide_drive_t
*drive
, int cmd
, int nsect
, int feature
, int sectors
, byte
*buf
);
735 void ide_delay_50ms (void);
737 int ide_driveid_update (ide_drive_t
*drive
);
738 int ide_ata66_check (ide_drive_t
*drive
, int cmd
, int nsect
, int feature
);
739 int ide_config_drive_speed (ide_drive_t
*drive
, byte speed
);
740 int set_transfer (ide_drive_t
*drive
, int cmd
, int nsect
, int feature
);
743 * ide_system_bus_speed() returns what we think is the system VESA/PCI
744 * bus speed (in MHz). This is used for calculating interface PIO timings.
745 * The default is 40 for known PCI systems, 50 otherwise.
746 * The "idebus=xx" parameter can be used to override this value.
748 int ide_system_bus_speed (void);
751 * ide_multwrite() transfers a block of up to mcount sectors of data
752 * to a drive as part of a disk multwrite operation.
754 int ide_multwrite (ide_drive_t
*drive
, unsigned int mcount
);
757 * ide_stall_queue() can be used by a drive to give excess bandwidth back
758 * to the hwgroup by sleeping for timeout jiffies.
760 void ide_stall_queue (ide_drive_t
*drive
, unsigned long timeout
);
763 * ide_get_queue() returns the queue which corresponds to a given device.
765 request_queue_t
*ide_get_queue (kdev_t dev
);
768 * CompactFlash cards and their brethern pretend to be removable hard disks,
769 * but they never have a slave unit, and they don't have doorlock mechanisms.
770 * This test catches them, and is invoked elsewhere when setting appropriate config bits.
772 int drive_is_flashcard (ide_drive_t
*drive
);
774 int ide_spin_wait_hwgroup(ide_drive_t
*drive
, unsigned long *flags
);
775 void ide_timer_expiry (unsigned long data
);
776 void ide_intr (int irq
, void *dev_id
, struct pt_regs
*regs
);
777 void do_ide0_request (request_queue_t
* q
);
779 void do_ide1_request (request_queue_t
* q
);
782 void do_ide2_request (request_queue_t
* q
);
785 void do_ide3_request (request_queue_t
* q
);
788 void do_ide4_request (request_queue_t
* q
);
791 void do_ide5_request (request_queue_t
* q
);
794 void do_ide6_request (request_queue_t
* q
);
797 void do_ide7_request (request_queue_t
* q
);
800 void do_ide8_request (request_queue_t
* q
);
803 void do_ide9_request (request_queue_t
* q
);
805 void ide_init_subdrivers (void);
808 extern struct block_device_operations ide_fops
[];
809 extern ide_proc_entry_t generic_subdriver_entries
[];
813 #ifdef CONFIG_BLK_DEV_IDE
814 int ideprobe_init (void);
815 #endif /* CONFIG_BLK_DEV_IDE */
816 #ifdef CONFIG_BLK_DEV_IDEDISK
817 int idedisk_init (void);
818 #endif /* CONFIG_BLK_DEV_IDEDISK */
819 #ifdef CONFIG_BLK_DEV_IDECD
820 int ide_cdrom_init (void);
821 #endif /* CONFIG_BLK_DEV_IDECD */
822 #ifdef CONFIG_BLK_DEV_IDETAPE
823 int idetape_init (void);
824 #endif /* CONFIG_BLK_DEV_IDETAPE */
825 #ifdef CONFIG_BLK_DEV_IDEFLOPPY
826 int idefloppy_init (void);
827 #endif /* CONFIG_BLK_DEV_IDEFLOPPY */
828 #ifdef CONFIG_BLK_DEV_IDESCSI
829 int idescsi_init (void);
830 #endif /* CONFIG_BLK_DEV_IDESCSI */
833 int ide_register_module (ide_module_t
*module
);
834 void ide_unregister_module (ide_module_t
*module
);
835 ide_drive_t
*ide_scan_devices (byte media
, const char *name
, ide_driver_t
*driver
, int n
);
836 int ide_register_subdriver (ide_drive_t
*drive
, ide_driver_t
*driver
, int version
);
837 int ide_unregister_subdriver (ide_drive_t
*drive
);
838 int ide_replace_subdriver(ide_drive_t
*drive
, const char *driver
);
840 #ifdef CONFIG_BLK_DEV_IDEPCI
842 #define NEVER_BOARD 0
843 #ifdef CONFIG_BLK_DEV_OFFBOARD
844 # define OFF_BOARD ON_BOARD
845 #else /* CONFIG_BLK_DEV_OFFBOARD */
846 # define OFF_BOARD NEVER_BOARD
847 #endif /* CONFIG_BLK_DEV_OFFBOARD */
849 unsigned long ide_find_free_region (unsigned short size
) __init
;
850 void ide_scan_pcibus (int scan_direction
) __init
;
852 #ifdef CONFIG_BLK_DEV_IDEDMA
853 #define BAD_DMA_DRIVE 0
854 #define GOOD_DMA_DRIVE 1
855 int ide_build_dmatable (ide_drive_t
*drive
, ide_dma_action_t func
);
856 void ide_destroy_dmatable (ide_drive_t
*drive
);
857 ide_startstop_t
ide_dma_intr (ide_drive_t
*drive
);
858 int check_drive_lists (ide_drive_t
*drive
, int good_bad
);
859 int ide_dmaproc (ide_dma_action_t func
, ide_drive_t
*drive
);
860 int ide_release_dma (ide_hwif_t
*hwif
);
861 void ide_setup_dma (ide_hwif_t
*hwif
, unsigned long dmabase
, unsigned int num_ports
) __init
;
862 unsigned long ide_get_or_set_dma_base (ide_hwif_t
*hwif
, int extra
, const char *name
) __init
;
865 void hwif_unregister (ide_hwif_t
*hwif
);