This source file includes following definitions.
- read_timer
- start_ide_timer
- do_ide_reset
- end_drive_cmd
- dump_status
- ide_error
- read_intr
- write_intr
- multwrite
- multwrite_intr
- ide_cmd
- set_multmode_intr
- set_geometry_intr
- recal_intr
- drive_cmd_intr
- timer_expiry
- ide0_timer_expiry
- ide1_timer_expiry
- do_special
- wait_stat
- do_rw_disk
- do_request
- do_ide0_request
- do_ide1_request
- do_ide0_request
- do_shared_request
- unexpected_intr
- ide0_intr
- ide1_intr
- ide_intr
- ide_shared_intr
- get_info_ptr
- ide_open
- ide_release
- revalidate_disk
- do_drive_cmd
- write_fs_long
- ide_ioctl
- ide_check_media_change
- fixstring
- lba_capacity_is_ok
- do_identify
- delay_10ms
- try_to_identify
- do_probe
- probe_for_drive
- probe_for_drives
- ide_setup
- hda_setup
- hdb_setup
- hdc_setup
- hdd_setup
- probe_cmos_for_drives
- init_ide_data
- setup_irq
- ide_geninit
- ide0_geninit
- ide1_geninit
- ide_init
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117 #include <linux/config.h>
118 #include <linux/errno.h>
119 #include <linux/signal.h>
120 #include <linux/sched.h>
121 #include <linux/timer.h>
122 #include <linux/fs.h>
123 #include <linux/kernel.h>
124 #include <linux/hdreg.h>
125 #include <linux/genhd.h>
126 #include <linux/malloc.h>
127 #include <linux/string.h>
128 #include <linux/delay.h>
129 #include <linux/major.h>
130 #include <linux/ioport.h>
131 #include <linux/interrupt.h>
132 #include <linux/blkdev.h>
133 #include <asm/bitops.h>
134 #include <asm/irq.h>
135 #include <asm/segment.h>
136 #include <asm/system.h>
137
138
139
140
141 #define REALLY_SLOW_IO
142 #include <asm/io.h>
143
144 #undef REALLY_FAST_IO
145 #define INITIAL_MULT_COUNT 0
146 #ifndef VLB_32BIT_IDE
147 #define VLB_32BIT_IDE 0
148 #endif
149 #ifndef DISK_RECOVERY_TIME
150 #define DISK_RECOVERY_TIME 0
151 #endif
152 #ifndef OK_TO_RESET_CONTROLLER
153 #define OK_TO_RESET_CONTROLLER 1
154 #endif
155 #ifndef SUPPORT_TWO_INTERFACES
156 #define SUPPORT_TWO_INTERFACES 1
157 #endif
158 #ifndef OPTIMIZE_IRQS
159 #define OPTIMIZE_IRQS 1
160 #endif
161 #ifndef SUPPORT_SHARING_IRQ
162 #define SUPPORT_SHARING_IRQ 1
163 #endif
164 #ifndef FANCY_STATUS_DUMPS
165 #define FANCY_STATUS_DUMPS 1
166 #endif
167 #define PROBE_FOR_IRQS 1
168 #define DEFAULT_IDE0_IRQ 14
169 #define DEFAULT_IDE1_IRQ 15
170
171
172 #define IDE_DRIVE_CMD 99
173
174
175
176
177
178
179
180
181
182 #ifndef IDE0_TIMER
183 #define IDE0_TIMER HD_TIMER
184 #define IDE1_TIMER HD_TIMER2
185 #endif
186
187
188
189
190 #ifdef REALLY_SLOW_IO
191 #undef REALLY_FAST_IO
192 #endif
193 #ifdef CONFIG_BLK_DEV_HD
194 #undef SUPPORT_TWO_INTERFACES
195 #define SUPPORT_TWO_INTERFACES 0
196 #endif
197 #if SUPPORT_TWO_INTERFACES
198 #define HWIF hwif
199 #define DEV_HWIF (dev->hwif)
200 #else
201 #undef OPTIMIZE_IRQS
202 #define OPTIMIZE_IRQS 0
203 #undef SUPPORT_SHARING_IRQ
204 #define SUPPORT_SHARING_IRQ 0
205 #ifdef CONFIG_BLK_DEV_HD
206 #define HWIF 1
207 #else
208 #define HWIF 0
209 #endif
210 #define DEV_HWIF HWIF
211 #endif
212
213
214
215
216 typedef unsigned char byte;
217 #define IDE_PORT(p,hwif) ((p)^((hwif)<<7))
218
219 #ifdef REALLY_FAST_IO
220 #define OUT_BYTE(b,p) outb((b),IDE_PORT(p,DEV_HWIF))
221 #define IN_BYTE(p,hwif) (byte)inb(IDE_PORT(p,hwif))
222 #else
223 #define OUT_BYTE(b,p) outb_p((b),IDE_PORT(p,DEV_HWIF))
224 #define IN_BYTE(p,hwif) (byte)inb_p(IDE_PORT(p,hwif))
225 #endif
226
227 #if VLB_32BIT_IDE
228 #define OUT_SECTORS(b,n) outsl(IDE_PORT(HD_DATA,DEV_HWIF),(b),(n)<<7)
229 #define IN_SECTORS(b,n) insl(IDE_PORT(HD_DATA,DEV_HWIF),(b),(n)<<7)
230 #else
231 #define OUT_SECTORS(b,n) outsw(IDE_PORT(HD_DATA,DEV_HWIF),(b),(n)<<8)
232 #define IN_SECTORS(b,n) insw(IDE_PORT(HD_DATA,DEV_HWIF),(b),(n)<<8)
233 #endif
234
235 #define GET_ERR(hwif) IN_BYTE(HD_ERROR,hwif)
236 #define GET_STAT(hwif) IN_BYTE(HD_STATUS,hwif)
237 #define OK_STAT(stat,good,bad) (((stat)&((good)|(bad)))==(good))
238 #define BAD_RW_STAT (BUSY_STAT | ERR_STAT | WRERR_STAT)
239 #define BAD_STAT (BAD_RW_STAT | DRQ_STAT)
240 #define DRIVE_READY (READY_STAT | SEEK_STAT)
241 #define DATA_READY (DRIVE_READY | DRQ_STAT)
242
243
244
245
246 #define BIOS_SECTORS(dev) (dev->bios_head*dev->bios_sect*dev->bios_cyl)
247 #define HD_NAME "hd"
248 #define PARTN_BITS 6
249 #define PARTN_MASK ((1<<PARTN_BITS)-1)
250 #define MAX_DRIVES 2
251
252
253
254
255 #define WAIT_DRQ 5
256 #define WAIT_READY 3
257 #define WAIT_PIDENTIFY 100
258 #define WAIT_WORSTCASE 3000
259 #define WAIT_CMD 1000
260
261
262
263
264
265
266
267
268 typedef enum {disk, cdrom} dev_type;
269
270 typedef union {
271 unsigned all : 8;
272 struct {
273 unsigned set_geometry : 1;
274 unsigned recalibrate : 1;
275 unsigned set_multmode : 1;
276 unsigned reserved : 5;
277 } b;
278 } special_t;
279
280 typedef union {
281 unsigned all : 8;
282 struct {
283 unsigned head : 4;
284 unsigned drive : 1;
285 unsigned bit5 : 1;
286 unsigned lba : 1;
287 unsigned bit7 : 1;
288 } b;
289 } select_t;
290
291 typedef struct {
292 byte hwif;
293 byte unmask;
294 dev_type type : 1;
295 unsigned present : 1;
296 unsigned dont_probe : 1;
297 unsigned keep_settings : 1;
298 unsigned busy : 1;
299 unsigned reserved0 : 3;
300 special_t special;
301 select_t select;
302 byte mult_count, reserved1, reserved2;
303 byte usage, mult_req, wpcom, ctl;
304 byte head, sect, bios_head, bios_sect;
305 unsigned short cyl, bios_cyl;
306 const char *name;
307 struct hd_driveid *id;
308 struct wait_queue *wqueue;
309 } ide_dev_t;
310
311
312
313
314 static const byte ide_major [2] = {IDE0_MAJOR,IDE1_MAJOR};
315 static byte ide_irq [2] = {DEFAULT_IDE0_IRQ,DEFAULT_IDE1_IRQ};
316 static struct hd_struct ide_hd [2][MAX_DRIVES<<PARTN_BITS] = {{{0,0},},};
317 static int ide_sizes [2][MAX_DRIVES<<PARTN_BITS] = {{0,},};
318 static int ide_blksizes [2][MAX_DRIVES<<PARTN_BITS] = {{0,},};
319 static unsigned long ide_capacity [2][MAX_DRIVES] = {{0,},};
320 static ide_dev_t ide_dev [2][MAX_DRIVES] = {{{0,},},};
321 static ide_dev_t *ide_cur_dev [2] = {NULL,NULL};
322 static void (*ide_handler[2])(ide_dev_t *) = {NULL,NULL};
323 static struct request *ide_cur_rq [2] = {NULL,NULL};
324 static struct request ide_write_rq [2];
325 static const int ide_timer [2] = {IDE0_TIMER,IDE1_TIMER};
326 static const int ide_timerbit[2] = {(1<<IDE0_TIMER),(1<<IDE1_TIMER)};
327 static const char *ide_name [2] = {"ide0", "ide1"};
328 static const char *ide_devname [2][MAX_DRIVES] =
329 {{HD_NAME "a", HD_NAME "b"}, {HD_NAME "c", HD_NAME "d"}};
330 static const char *unsupported = " not supported by this kernel\n";
331
332 #if SUPPORT_SHARING_IRQ
333 static byte sharing_single_irq = 0;
334 static volatile byte current_hwif = 0;
335 #endif
336
337
338
339
340 static void ide0_geninit(void), ide1_geninit(void);
341 static struct gendisk ide_gendisk [2] =
342 {{
343 IDE0_MAJOR,
344 HD_NAME,
345 PARTN_BITS,
346 1 << PARTN_BITS,
347 MAX_DRIVES,
348 ide0_geninit,
349 ide_hd[0],
350 ide_sizes[0],
351 0,
352 ide_dev[0],
353 NULL
354 },{
355 IDE1_MAJOR,
356 HD_NAME,
357 PARTN_BITS,
358 1 << PARTN_BITS,
359 MAX_DRIVES,
360 ide1_geninit,
361 ide_hd[1],
362 ide_sizes[1],
363 0,
364 ide_dev[1],
365 NULL
366 }};
367
368
369
370
371 #define IDE_DRIVER
372 #include "blk.h"
373
374
375
376
377 #if (DISK_RECOVERY_TIME > 0)
378 static unsigned long ide_lastreq[] = {0,0};
379 #define SET_DISK_RECOVERY_TIMER ide_lastreq[DEV_HWIF] = read_timer();
380 static unsigned long read_timer(void)
381 {
382 unsigned long t, flags;
383 int i;
384
385 save_flags(flags);
386 cli();
387 t = jiffies * 11932;
388 outb_p(0, 0x43);
389 i = inb_p(0x40);
390 i |= inb(0x40) << 8;
391 restore_flags(flags);
392 return (t - i);
393 }
394 #else
395 #define SET_DISK_RECOVERY_TIMER
396 #endif
397
398
399
400
401 static void do_request (byte hwif);
402 #define DO_REQUEST {SET_DISK_RECOVERY_TIMER do_request(DEV_HWIF);}
403
404
405
406
407
408
409
410
411
412
413 #define WAIT_STAT(dev,good,bad,timeout,msg,label) \
414 { \
415 byte stat; \
416 udelay(1); \
417 if (GET_STAT(DEV_HWIF) & BUSY_STAT) { \
418 unsigned long timer = jiffies + timeout; \
419 do { \
420 if ((GET_STAT(DEV_HWIF) & BUSY_STAT) == 0) \
421 break; \
422 } while (timer > jiffies); \
423 } \
424 udelay(1); \
425 if (!OK_STAT(stat=GET_STAT(DEV_HWIF), good, bad)) { \
426 ide_error(dev, msg " error", stat); \
427 goto label; \
428 } \
429 }
430
431
432
433
434 static inline void start_ide_timer (byte hwif)
435 {
436 if (ide_handler[HWIF] != NULL) {
437 timer_table[ide_timer[HWIF]].expires = jiffies + WAIT_CMD;
438 timer_active |= ide_timerbit[HWIF];
439 }
440 }
441
442 static void do_ide_reset (ide_dev_t *dev)
443 {
444 byte tmp;
445 unsigned long timer, flags;
446
447 save_flags(flags);
448 sti();
449 for (tmp = 0; tmp < MAX_DRIVES; tmp++) {
450 ide_dev_t *rdev = &ide_dev[DEV_HWIF][tmp];
451 rdev->special.b.set_geometry = 1;
452 rdev->special.b.recalibrate = 1;
453 rdev->special.b.set_multmode = 0;
454 if (OK_TO_RESET_CONTROLLER)
455 rdev->mult_count = 0;
456 if (!rdev->keep_settings) {
457 rdev->mult_req = 0;
458 rdev->unmask = 0;
459 }
460 if (rdev->mult_req != rdev->mult_count)
461 rdev->special.b.set_multmode = 1;
462 }
463
464 #if OK_TO_RESET_CONTROLLER
465 cli();
466 OUT_BYTE(dev->ctl|6,HD_CMD);
467 udelay(10);
468 OUT_BYTE(dev->ctl|2,HD_CMD);
469 udelay(10);
470 sti();
471 for (timer = jiffies + WAIT_WORSTCASE; timer > jiffies;) {
472 if ((GET_STAT(DEV_HWIF) & BUSY_STAT) == 0)
473 break;
474 }
475 printk("%s: do_ide_reset: ", ide_name[DEV_HWIF]);
476
477 if (!OK_STAT(tmp=GET_STAT(DEV_HWIF), 0, BUSY_STAT)) {
478 printk("timed-out, status=0x%02x\n", tmp);
479 } else {
480 if ((tmp = GET_ERR(DEV_HWIF)) == 1)
481 printk("success\n");
482 else {
483 printk("%s: ", ide_devname[DEV_HWIF][0]);
484 switch (tmp & 0x7f) {
485 case 1: printk("passed");
486 break;
487 case 2: printk("formatter device error");
488 break;
489 case 3: printk("sector buffer error");
490 break;
491 case 4: printk("ECC circuitry error");
492 break;
493 case 5: printk("controlling MPU error");
494 break;
495 default:printk("error (0x%02x?)", tmp);
496 }
497 if (tmp & 0x80)
498 printk("; %s: error", ide_devname[DEV_HWIF][1]);
499 printk("\n");
500 }
501 }
502 #endif
503 restore_flags(flags);
504 }
505
506
507
508
509 static void end_drive_cmd (ide_dev_t *dev, byte stat, byte err)
510 {
511 unsigned long flags;
512 struct request *rq = ide_cur_rq[DEV_HWIF];
513 byte *args = (byte *) rq->buffer;
514
515 rq->errors = !OK_STAT(stat,READY_STAT,BAD_STAT);
516 if (args) {
517 args[0] = stat;
518 args[1] = err;
519 args[2] = IN_BYTE(HD_NSECTOR,DEV_HWIF);
520 }
521 save_flags(flags);
522 cli();
523 up(rq->sem);
524 ide_cur_rq[DEV_HWIF] = NULL;
525 restore_flags(flags);
526 }
527
528
529
530
531 static byte dump_status (byte hwif, const char *msg, byte stat)
532 {
533 unsigned long flags;
534 byte err = 0;
535 ide_dev_t *dev = ide_cur_dev[HWIF];
536 const char *name = dev ? dev->name : ide_name[HWIF];
537
538 save_flags (flags);
539 sti();
540 printk("%s: %s: status=0x%02x", name, msg, stat);
541 #if FANCY_STATUS_DUMPS
542 if (dev && dev->type == disk) {
543 printk(" { ");
544 if (stat & BUSY_STAT)
545 printk("Busy ");
546 else {
547 if (stat & READY_STAT) printk("DriveReady ");
548 if (stat & WRERR_STAT) printk("WriteFault ");
549 if (stat & SEEK_STAT) printk("SeekComplete ");
550 if (stat & DRQ_STAT) printk("DataRequest ");
551 if (stat & ECC_STAT) printk("CorrectedError ");
552 if (stat & INDEX_STAT) printk("Index ");
553 if (stat & ERR_STAT) printk("Error ");
554 }
555 printk("}");
556 }
557 #endif
558 printk("\n");
559 if ((stat & (BUSY_STAT|ERR_STAT)) == ERR_STAT) {
560 err = GET_ERR(HWIF);
561 printk("%s: %s: error=0x%02x", name, msg, err);
562 #if FANCY_STATUS_DUMPS
563 if (dev && dev->type == disk) {
564 printk(" { ");
565 if (err & BBD_ERR) printk("BadSector ");
566 if (err & ECC_ERR) printk("UncorrectableError ");
567 if (err & ID_ERR) printk("SectorIdNotFound ");
568 if (err & ABRT_ERR) printk("DriveStatusError ");
569 if (err & TRK0_ERR) printk("TrackZeroNotFound ");
570 if (err & MARK_ERR) printk("AddrMarkNotFound ");
571 printk("}");
572 if (err & (BBD_ERR|ECC_ERR|ID_ERR|MARK_ERR)) {
573 byte cur = IN_BYTE(HD_CURRENT,HWIF);
574 if (cur & 0x40) {
575 printk(", LBAsect=%ld", (unsigned long)
576 ((cur&0xf)<<24)
577 |(IN_BYTE(HD_HCYL,HWIF)<<16)
578 |(IN_BYTE(HD_LCYL,HWIF)<<8)
579 | IN_BYTE(HD_SECTOR,HWIF));
580 } else {
581 printk(", CHS=%d/%d/%d",
582 (IN_BYTE(HD_HCYL,HWIF)<<8) +
583 IN_BYTE(HD_LCYL,HWIF),
584 cur & 0xf,
585 IN_BYTE(HD_SECTOR,HWIF));
586 }
587 if (ide_cur_rq[HWIF])
588 printk(", sector=%ld", ide_cur_rq[HWIF]->sector);
589 }
590 }
591 #endif
592 printk("\n");
593 }
594 restore_flags (flags);
595 return err;
596 }
597
598
599
600
601 #define ERROR_MAX 8
602 #define ERROR_RESET 3
603 #define ERROR_RECAL 1
604 static void ide_error (ide_dev_t *dev, const char *msg, byte stat)
605 {
606 struct request *rq;
607 byte err;
608
609 err = dump_status(DEV_HWIF, msg, stat);
610 if ((rq = ide_cur_rq[DEV_HWIF]) == NULL || dev == NULL)
611 return;
612 #ifdef IDE_DRIVE_CMD
613 if (rq->cmd == IDE_DRIVE_CMD) {
614 end_drive_cmd(dev, stat, err);
615 return;
616 }
617 #endif
618 if (stat & BUSY_STAT) {
619 rq->errors |= ERROR_RESET;
620 } else {
621 if (dev->type == disk && (stat & ERR_STAT)) {
622
623 if (err & BBD_ERR)
624 rq->errors = ERROR_MAX;
625 else if (err & TRK0_ERR)
626 rq->errors |= ERROR_RECAL;
627 }
628 if ((stat & DRQ_STAT) && rq->cmd == READ) {
629 int i = dev->mult_count ? dev->mult_count<<8 : 1<<8;
630 while (i-- > 0)
631 (void) IN_BYTE(HD_DATA, dev->hwif);
632 }
633 }
634 if (GET_STAT(dev->hwif) & (BUSY_STAT|DRQ_STAT))
635 rq->errors |= ERROR_RESET;
636
637 if (rq->errors >= ERROR_MAX)
638 end_request(0, DEV_HWIF);
639 else {
640 if ((rq->errors & ERROR_RESET) == ERROR_RESET)
641 do_ide_reset(dev);
642 else if ((rq->errors & ERROR_RECAL) == ERROR_RECAL)
643 dev->special.b.recalibrate = 1;
644 ++rq->errors;
645 }
646 }
647
648 static void read_intr (ide_dev_t *dev)
649 {
650 byte stat;
651 int i;
652 unsigned int msect, nsect;
653 struct request *rq;
654
655 if (!OK_STAT(stat=GET_STAT(DEV_HWIF),DATA_READY,BAD_RW_STAT)) {
656 sti();
657 ide_error(dev, "read_intr", stat);
658 DO_REQUEST;
659 return;
660 }
661 msect = dev->mult_count;
662 read_next:
663 rq = ide_cur_rq[DEV_HWIF];
664 if (msect) {
665 if ((nsect = rq->current_nr_sectors) > msect)
666 nsect = msect;
667 msect -= nsect;
668 } else
669 nsect = 1;
670 IN_SECTORS(rq->buffer,nsect);
671 #ifdef DEBUG
672 printk("%s: read: sectors(%ld-%ld), buffer=0x%08lx, remaining=%ld\n",
673 dev->name, rq->sector, rq->sector+nsect-1,
674 (unsigned long) rq->buffer+(nsect<<9), rq->nr_sectors-nsect);
675 #endif
676 rq->sector += nsect;
677 rq->buffer += nsect<<9;
678 rq->errors = 0;
679 i = (rq->nr_sectors -= nsect);
680 if ((rq->current_nr_sectors -= nsect) <= 0)
681 end_request(1, DEV_HWIF);
682 if (i > 0) {
683 if (msect)
684 goto read_next;
685 ide_handler[DEV_HWIF] = &read_intr;
686 return;
687 }
688
689 DO_REQUEST;
690 }
691
692 static void write_intr (ide_dev_t *dev)
693 {
694 byte stat;
695 int i;
696 struct request *rq = ide_cur_rq[DEV_HWIF];
697
698 if (OK_STAT(stat=GET_STAT(DEV_HWIF),DRIVE_READY,BAD_RW_STAT)) {
699 #ifdef DEBUG
700 printk("%s: write: sector %ld, buffer=0x%08lx, remaining=%ld\n",
701 dev->name, rq->sector, (unsigned long) rq->buffer,
702 rq->nr_sectors-1);
703 #endif
704 if ((rq->nr_sectors == 1) ^ ((stat & DRQ_STAT) != 0)) {
705 rq->sector++;
706 rq->buffer += 512;
707 rq->errors = 0;
708 i = --rq->nr_sectors;
709 --rq->current_nr_sectors;
710 if (rq->current_nr_sectors <= 0)
711 end_request(1, DEV_HWIF);
712 if (i > 0) {
713 ide_handler[DEV_HWIF] = &write_intr;
714 OUT_SECTORS(rq->buffer,1);
715 return;
716 }
717 DO_REQUEST;
718 return;
719 }
720 }
721 sti();
722 ide_error(dev, "write_intr", stat);
723 DO_REQUEST;
724 }
725
726 static void multwrite (ide_dev_t *dev)
727 {
728 struct request *rq = &ide_write_rq[DEV_HWIF];
729 unsigned int mcount = dev->mult_count;
730
731 do {
732 unsigned int nsect = rq->current_nr_sectors;
733 if (nsect > mcount)
734 nsect = mcount;
735 mcount -= nsect;
736
737 OUT_SECTORS(rq->buffer,nsect);
738 #ifdef DEBUG
739 printk("%s: multwrite: sector %ld, buffer=0x%08lx, count=%d, remaining=%ld\n",
740 dev->name, rq->sector, (unsigned long) rq->buffer,
741 nsect, rq->nr_sectors - nsect);
742 #endif
743 if ((rq->nr_sectors -= nsect) <= 0)
744 break;
745 if ((rq->current_nr_sectors -= nsect) == 0) {
746 if ((rq->bh = rq->bh->b_reqnext) != NULL) {
747 rq->current_nr_sectors = rq->bh->b_size>>9;
748 rq->buffer = rq->bh->b_data;
749 } else {
750 panic("%s: buffer list corrupted\n", dev->name);
751 break;
752 }
753 } else {
754 rq->buffer += nsect << 9;
755 }
756 } while (mcount);
757 }
758
759 static void multwrite_intr (ide_dev_t *dev)
760 {
761 byte stat;
762 int i;
763 struct request *rq = &ide_write_rq[DEV_HWIF];
764
765 if (OK_STAT(stat=GET_STAT(DEV_HWIF),DRIVE_READY,BAD_RW_STAT)) {
766 if (stat & DRQ_STAT) {
767 if (rq->nr_sectors) {
768 if (dev->mult_count)
769 multwrite(dev);
770 ide_handler[DEV_HWIF] = &multwrite_intr;
771 return;
772 }
773 } else {
774 if (!rq->nr_sectors) {
775 rq = ide_cur_rq[DEV_HWIF];
776 for (i = rq->nr_sectors; i > 0;){
777 i -= rq->current_nr_sectors;
778 end_request(1, DEV_HWIF);
779 }
780 DO_REQUEST;
781 return;
782 }
783 }
784 }
785 sti();
786 ide_error(dev, "multwrite_intr", stat);
787 DO_REQUEST;
788 }
789
790
791
792
793
794 static inline void ide_cmd(ide_dev_t *dev, byte cmd, byte nsect,
795 void (*handler)(ide_dev_t *dev))
796 {
797 OUT_BYTE(dev->ctl,HD_CMD);
798 OUT_BYTE(nsect,HD_NSECTOR);
799 OUT_BYTE(cmd,HD_COMMAND);
800 ide_handler[DEV_HWIF] = handler;
801 }
802
803 static void set_multmode_intr (ide_dev_t *dev)
804 {
805 byte stat = GET_STAT(DEV_HWIF);
806
807 sti();
808 if (!OK_STAT(stat,READY_STAT,BAD_STAT)) {
809 dev->mult_req = dev->mult_count = 0;
810 dev->special.b.recalibrate = 1;
811 (void) dump_status(DEV_HWIF, "set_multmode", stat);
812 } else {
813 if ((dev->mult_count = dev->mult_req))
814 printk (" %s: enabled %d-sector multiple mode\n",
815 dev->name, dev->mult_count);
816 else
817 printk (" %s: disabled multiple mode\n", dev->name);
818 }
819 DO_REQUEST;
820 }
821
822 static void set_geometry_intr (ide_dev_t *dev)
823 {
824 byte stat = GET_STAT(DEV_HWIF);
825
826 sti();
827 if (!OK_STAT(stat,READY_STAT,BAD_STAT))
828 ide_error(dev, "set_geometry_intr", stat);
829 DO_REQUEST;
830 }
831
832 static void recal_intr (ide_dev_t *dev)
833 {
834 byte stat = GET_STAT(DEV_HWIF);
835
836 sti();
837 if (!OK_STAT(stat,READY_STAT,BAD_STAT))
838 ide_error(dev, "recal_intr", stat);
839 DO_REQUEST;
840 }
841
842 static void drive_cmd_intr (ide_dev_t *dev)
843 {
844 byte stat = GET_STAT(DEV_HWIF);
845
846 sti();
847 if (!OK_STAT(stat,READY_STAT,BAD_STAT))
848 ide_error(dev, "drive_cmd", stat);
849 else
850 end_drive_cmd (dev, stat, GET_ERR(DEV_HWIF));
851 DO_REQUEST;
852 }
853
854 static void timer_expiry (byte hwif)
855 {
856 unsigned long flags;
857
858 save_flags(flags);
859 cli();
860
861 if (ide_handler[HWIF] == NULL || (timer_active & ide_timerbit[HWIF])) {
862
863 sti();
864 printk("%s: marginal timeout\n", ide_name[HWIF]);
865 } else {
866 ide_handler[HWIF] = NULL;
867 disable_irq(ide_irq[HWIF]);
868 sti();
869 ide_error(ide_cur_dev[HWIF], "timeout", GET_STAT(HWIF));
870 do_request(HWIF);
871 #if SUPPORT_SHARING_IRQ
872 if (sharing_single_irq)
873 hwif = current_hwif;
874 #endif
875 cli();
876 start_ide_timer(HWIF);
877 enable_irq(ide_irq[HWIF]);
878 }
879 restore_flags(flags);
880 }
881
882 static void ide0_timer_expiry (void)
883 {
884 timer_expiry (0);
885 }
886
887 static void ide1_timer_expiry (void)
888 {
889 timer_expiry (1);
890 }
891
892 static int do_special (ide_dev_t *dev)
893 {
894 special_t *s = &dev->special;
895 #ifdef DEBUG
896 printk("%s: do_special: 0x%02x\n", dev->name, s->all);
897 #endif
898 if (s->b.set_geometry) {
899 s->b.set_geometry = 0;
900 if (dev->type == disk) {
901 OUT_BYTE(dev->sect,HD_SECTOR);
902 OUT_BYTE(dev->cyl,HD_LCYL);
903 OUT_BYTE(dev->cyl>>8,HD_HCYL);
904 OUT_BYTE(((dev->head-1)|dev->select.all)&0xBF,HD_CURRENT);
905 ide_cmd(dev, WIN_SPECIFY, dev->sect, &set_geometry_intr);
906 }
907 } else if (s->b.recalibrate) {
908 s->b.recalibrate = 0;
909 if (dev->type == disk)
910 ide_cmd(dev,WIN_RESTORE,dev->sect,&recal_intr);
911 } else if (s->b.set_multmode) {
912 if (dev->type == disk) {
913 if (dev->id && dev->mult_req > dev->id->max_multsect)
914 dev->mult_req = dev->id->max_multsect;
915 ide_cmd(dev,WIN_SETMULT,dev->mult_req,&set_multmode_intr);
916 } else {
917 dev->mult_req = 0;
918 printk("%s: multmode not supported by this device\n", dev->name);
919 }
920 s->b.set_multmode = 0;
921 } else {
922 if (s->all) {
923 printk("%s: bad special flag: 0x%02x\n", dev->name, s->all);
924 s->all = 0;
925 }
926 }
927 return (ide_handler[DEV_HWIF] == NULL) ? 1 : 0;
928 }
929
930 #ifdef CONFIG_BLK_DEV_IDECD
931 static byte wait_stat (ide_dev_t *dev, byte good, byte bad, unsigned long timeout)
932 {
933 unsigned long flags;
934
935 save_flags(flags);
936 sti();
937 WAIT_STAT(dev, good, bad, timeout, "status", error);
938 restore_flags(flags);
939 return 0;
940 error:
941 restore_flags(flags);
942 return 1;
943 }
944
945 #include "ide-cd.c"
946 #endif
947
948 static inline int do_rw_disk (ide_dev_t *dev, struct request *rq, unsigned long block)
949 {
950 OUT_BYTE(dev->ctl,HD_CMD);
951 OUT_BYTE(rq->nr_sectors,HD_NSECTOR);
952 if (dev->select.b.lba) {
953 #ifdef DEBUG
954 printk("%s: %sing: LBAsect=%ld, sectors=%ld, buffer=0x%08lx\n",
955 dev->name, (rq->cmd==READ)?"read":"writ",
956 block, rq->nr_sectors, (unsigned long) rq->buffer);
957 #endif
958 OUT_BYTE(block,HD_SECTOR);
959 OUT_BYTE(block>>=8,HD_LCYL);
960 OUT_BYTE(block>>=8,HD_HCYL);
961 OUT_BYTE(((block>>8)&0x0f)|dev->select.all,HD_CURRENT);
962 } else {
963 unsigned int sect,head,cyl,track;
964 track = block / dev->sect;
965 sect = block % dev->sect + 1;
966 OUT_BYTE(sect,HD_SECTOR);
967 head = track % dev->head;
968 cyl = track / dev->head;
969 OUT_BYTE(cyl,HD_LCYL);
970 OUT_BYTE(cyl>>8,HD_HCYL);
971 OUT_BYTE(head|dev->select.all,HD_CURRENT);
972 #ifdef DEBUG
973 printk("%s: %sing: CHS=%d/%d/%d, sectors=%ld, buffer=0x%08lx\n",
974 dev->name, (rq->cmd==READ)?"read":"writ", cyl,
975 head, sect, rq->nr_sectors, (unsigned long) rq->buffer);
976 #endif
977 }
978 if (rq->cmd == READ) {
979 OUT_BYTE(dev->mult_count ? WIN_MULTREAD : WIN_READ, HD_COMMAND);
980 ide_handler[DEV_HWIF] = &read_intr;
981 return 0;
982 }
983 if (rq->cmd == WRITE) {
984 OUT_BYTE(dev->wpcom,HD_PRECOMP);
985 OUT_BYTE(dev->mult_count ? WIN_MULTWRITE : WIN_WRITE, HD_COMMAND);
986 WAIT_STAT(dev, DATA_READY, BAD_RW_STAT, WAIT_DRQ, "DRQ", error);
987 if (!dev->unmask)
988 cli();
989 if (dev->mult_count) {
990 ide_write_rq[DEV_HWIF] = *rq;
991 multwrite(dev);
992 ide_handler[DEV_HWIF] = &multwrite_intr;
993 } else {
994 OUT_SECTORS(rq->buffer,1);
995 ide_handler[DEV_HWIF] = &write_intr;
996 }
997 return 0;
998 }
999 #ifdef IDE_DRIVE_CMD
1000 if (rq->cmd == IDE_DRIVE_CMD) {
1001 byte *args = rq->buffer;
1002 if (args) {
1003 OUT_BYTE(args[2],HD_FEATURE);
1004 ide_cmd(dev, args[0], args[1], &drive_cmd_intr);
1005 printk("%s: DRIVE_CMD cmd=0x%02x sc=0x%02x fr=0x%02x\n",
1006 dev->name, args[0], args[1], args[2]);
1007 return 0;
1008 } else {
1009 #ifdef DEBUG
1010 printk("%s: DRIVE_CMD (null)\n", dev->name);
1011 #endif
1012 end_drive_cmd(dev,GET_STAT(DEV_HWIF),GET_ERR(DEV_HWIF));
1013 return 1;
1014 }
1015 }
1016 #endif
1017 printk("%s: bad command: %d\n", dev->name, rq->cmd);
1018 end_request(0, DEV_HWIF);
1019 error:
1020 return 1;
1021 }
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034 static void do_request (byte hwif)
1035 {
1036 unsigned int minor, drive;
1037 unsigned long block, blockend;
1038 struct request *rq;
1039 ide_dev_t *dev;
1040 repeat:
1041 sti();
1042 #if SUPPORT_SHARING_IRQ
1043 current_hwif = hwif;
1044 #endif
1045 if ((rq = ide_cur_rq[HWIF]) == NULL) {
1046 rq = blk_dev[ide_major[HWIF]].current_request;
1047 if ((rq == NULL) || (rq->dev < 0)) {
1048 #if SUPPORT_SHARING_IRQ
1049 if (sharing_single_irq) {
1050 if ((dev = ide_cur_dev[hwif]))
1051 OUT_BYTE(dev->ctl|2,HD_CMD);
1052 rq = blk_dev[ide_major[hwif^=1]].current_request;
1053 if ((rq != NULL) && (rq->dev >= 0))
1054 goto repeat;
1055 }
1056 #endif
1057 return;
1058 }
1059 blk_dev[ide_major[HWIF]].current_request = rq->next;
1060 ide_cur_rq[HWIF] = rq;
1061 }
1062 #ifdef DEBUG
1063 printk("%s: do_request: current=0x%08lx\n",ide_name[HWIF],(unsigned long)rq);
1064 #endif
1065 minor = MINOR(rq->dev);
1066 drive = minor >> PARTN_BITS;
1067 ide_cur_dev[HWIF] = dev = &ide_dev[HWIF][drive];
1068 if ((MAJOR(rq->dev) != ide_major[HWIF]) || (drive >= MAX_DRIVES)) {
1069 printk("%s: bad device number: 0x%04x\n", ide_name[HWIF], rq->dev);
1070 end_request(0, HWIF);
1071 goto repeat;
1072 }
1073 if (rq->bh && !rq->bh->b_lock) {
1074 printk("%s: block not locked\n", ide_name[HWIF]);
1075 end_request(0, HWIF);
1076 goto repeat;
1077 }
1078 block = rq->sector;
1079 blockend = block + rq->nr_sectors;
1080 if ((blockend < block) || (blockend > ide_hd[HWIF][minor].nr_sects)) {
1081 printk("%s: bad access: block=%ld, count=%ld\n",
1082 dev->name, block, rq->nr_sectors);
1083 end_request(0, HWIF);
1084 goto repeat;
1085 }
1086 block += ide_hd[HWIF][minor].start_sect;
1087 #if (DISK_RECOVERY_TIME > 0)
1088 while ((read_timer() - ide_lastreq[HWIF]) < DISK_RECOVERY_TIME);
1089 #endif
1090 OUT_BYTE(dev->select.all,HD_CURRENT);
1091 #ifdef CONFIG_BLK_DEV_IDECD
1092 WAIT_STAT(dev, (dev->type == cdrom) ? 0 : READY_STAT,
1093 BUSY_STAT|DRQ_STAT, WAIT_READY, "DRDY", repeat);
1094 #else
1095 WAIT_STAT(dev, READY_STAT, BUSY_STAT|DRQ_STAT, WAIT_READY, "DRDY", repeat);
1096 #endif
1097 if (!dev->special.all) {
1098 #ifdef CONFIG_BLK_DEV_IDECD
1099 if (dev->type == disk) {
1100 #endif
1101 if (do_rw_disk(dev, rq, block))
1102 goto repeat;
1103 #ifdef CONFIG_BLK_DEV_IDECD
1104 } else {
1105 if (do_rw_cdrom(dev, block))
1106 goto repeat;
1107 }
1108 #endif
1109 } else {
1110 if (do_special(dev))
1111 goto repeat;
1112 }
1113 }
1114
1115
1116
1117
1118
1119
1120 #define DO_IDE_REQUEST(hwif) \
1121 { \
1122 if (ide_handler[hwif] == NULL) { \
1123 disable_irq(ide_irq[hwif]); \
1124 do_request(hwif); \
1125 cli(); \
1126 start_ide_timer(hwif); \
1127 enable_irq(ide_irq[hwif]); \
1128 } \
1129 }
1130
1131 #if SUPPORT_TWO_INTERFACES
1132 static void do_ide0_request (void)
1133 {
1134 DO_IDE_REQUEST(0);
1135 }
1136
1137 static void do_ide1_request (void)
1138 {
1139 DO_IDE_REQUEST(1);
1140 }
1141 #else
1142 #define do_ide1_request do_ide0_request
1143 static void do_ide0_request (void)
1144 {
1145 DO_IDE_REQUEST(HWIF);
1146 }
1147 #endif
1148
1149 #if SUPPORT_SHARING_IRQ
1150 static void do_shared_request (void)
1151 {
1152 DO_IDE_REQUEST(current_hwif);
1153 }
1154 #endif
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166 static void unexpected_intr (byte hwif)
1167 {
1168 byte stat;
1169
1170 if (!OK_STAT(stat=GET_STAT(HWIF), DRIVE_READY, BAD_STAT))
1171 (void) dump_status(HWIF, "unexpected_intr", stat);
1172 #if SUPPORT_SHARING_IRQ
1173 if (sharing_single_irq) {
1174 if (!OK_STAT(stat=GET_STAT(hwif^1), DRIVE_READY, BAD_STAT))
1175 (void) dump_status(hwif^1, "unexpected_intr", stat);
1176 }
1177 #endif
1178 }
1179
1180
1181
1182
1183
1184
1185 #define IDE_INTR(hwif) \
1186 { \
1187 ide_dev_t *dev; \
1188 void (*handler)(ide_dev_t *); \
1189 \
1190 timer_active &= ~ide_timerbit[hwif]; \
1191 if ((handler = ide_handler[hwif]) != NULL) { \
1192 ide_handler[hwif] = NULL; \
1193 dev = ide_cur_dev[hwif]; \
1194 if (dev->unmask) \
1195 sti(); \
1196 handler(dev); \
1197 } else \
1198 unexpected_intr(hwif); \
1199 cli(); \
1200 start_ide_timer(hwif); \
1201 }
1202
1203 #if OPTIMIZE_IRQS
1204
1205
1206 static void ide0_intr (int irq, struct pt_regs *regs)
1207 {
1208 IDE_INTR(0);
1209 }
1210
1211
1212 static void ide1_intr (int irq, struct pt_regs *regs)
1213 {
1214 IDE_INTR(1);
1215 }
1216
1217 #else
1218
1219 #define ide0_intr ide_intr
1220 #define ide1_intr ide_intr
1221
1222
1223 static void ide_intr (int irq, struct pt_regs *regs)
1224 {
1225 #if SUPPORT_TWO_INTERFACES
1226 byte hwif = (irq != ide_irq[0]);
1227 #endif
1228 IDE_INTR(HWIF);
1229 }
1230
1231 #endif
1232
1233 #if SUPPORT_SHARING_IRQ
1234
1235 static void ide_shared_intr (int irq, struct pt_regs * regs)
1236 {
1237 IDE_INTR(current_hwif);
1238 }
1239 #endif
1240
1241 static ide_dev_t *get_info_ptr (int i_rdev)
1242 {
1243 unsigned int drive = DEVICE_NR(i_rdev);
1244 ide_dev_t *dev;
1245
1246 if (drive < MAX_DRIVES) {
1247 switch (MAJOR(i_rdev)) {
1248 case IDE0_MAJOR: dev = &ide_dev[0][drive];
1249 if (dev->present) return dev;
1250 break;
1251 case IDE1_MAJOR: dev = &ide_dev[1][drive];
1252 if (dev->present) return dev;
1253 break;
1254 }
1255 }
1256 return NULL;
1257 }
1258
1259 static int ide_open(struct inode * inode, struct file * filp)
1260 {
1261 ide_dev_t *dev;
1262 unsigned long flags;
1263
1264 if ((dev = get_info_ptr(inode->i_rdev)) == NULL)
1265 return -ENODEV;
1266 save_flags(flags);
1267 cli();
1268 while (dev->busy)
1269 sleep_on(&dev->wqueue);
1270 dev->usage++;
1271 restore_flags(flags);
1272 #ifdef CONFIG_BLK_DEV_IDECD
1273 if (dev->type == cdrom)
1274 return cdrom_open (inode, filp, dev);
1275 #endif
1276 return 0;
1277 }
1278
1279
1280
1281
1282
1283 static void ide_release(struct inode * inode, struct file * file)
1284 {
1285 ide_dev_t *dev;
1286
1287 if ((dev = get_info_ptr(inode->i_rdev)) != NULL) {
1288 sync_dev(inode->i_rdev);
1289 dev->usage--;
1290 #ifdef CONFIG_BLK_DEV_IDECD
1291 if (dev->type == cdrom)
1292 cdrom_release (inode, file, dev);
1293 #endif
1294 }
1295 }
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305 static int revalidate_disk(int i_rdev)
1306 {
1307 unsigned int i, major, start, drive = DEVICE_NR(i_rdev);
1308 ide_dev_t *dev;
1309 struct gendisk *gd;
1310 long flags;
1311
1312 if ((dev = get_info_ptr(i_rdev)) == NULL)
1313 return -ENODEV;
1314
1315 save_flags(flags);
1316 cli();
1317 if (dev->busy || (dev->usage > 1)) {
1318 restore_flags(flags);
1319 return -EBUSY;
1320 };
1321 dev->busy = 1;
1322 restore_flags(flags);
1323
1324 gd = &ide_gendisk[DEV_HWIF];
1325 major = ide_major[DEV_HWIF] << 8;
1326 start = drive << PARTN_BITS;
1327
1328 for (i = 0; i < (1<<PARTN_BITS); i++) {
1329 unsigned int minor = start + i;
1330 sync_dev (major | minor);
1331 invalidate_inodes (major | minor);
1332 invalidate_buffers (major | minor);
1333 gd->part[minor].start_sect = 0;
1334 gd->part[minor].nr_sects = 0;
1335 };
1336
1337 gd->part[start].nr_sects = ide_capacity[DEV_HWIF][drive];
1338 resetup_one_dev(gd, drive);
1339
1340 dev->busy = 0;
1341 wake_up(&dev->wqueue);
1342 return 0;
1343 }
1344
1345 #ifdef IDE_DRIVE_CMD
1346
1347
1348
1349
1350
1351
1352 static int do_drive_cmd(int dev, char *args)
1353 {
1354 unsigned long flags;
1355 unsigned int major = MAJOR(dev);
1356 struct request rq, *cur_rq;
1357 struct blk_dev_struct *bdev;
1358 struct semaphore sem = MUTEX_LOCKED;
1359
1360
1361 rq.buffer = args;
1362 rq.cmd = IDE_DRIVE_CMD;
1363 rq.errors = 0;
1364 rq.sector = 0;
1365 rq.nr_sectors = 0;
1366 rq.current_nr_sectors = 0;
1367 rq.sem = &sem;
1368 rq.bh = NULL;
1369 rq.bhtail = NULL;
1370 rq.next = NULL;
1371 rq.dev = dev;
1372 bdev = &blk_dev[major];
1373
1374 save_flags(flags);
1375 cli();
1376 cur_rq = bdev->current_request;
1377 if (cur_rq == NULL) {
1378 bdev->current_request = &rq;
1379 bdev->request_fn();
1380 } else {
1381 while (cur_rq->next != NULL)
1382 cur_rq = cur_rq->next;
1383 cur_rq->next = &rq;
1384 }
1385
1386 down(&sem);
1387 restore_flags(flags);
1388 return rq.errors ? -EIO : 0;
1389 }
1390 #endif
1391
1392 static int write_fs_long (unsigned long useraddr, long value)
1393 {
1394 int err;
1395
1396 if (NULL == (long *)useraddr)
1397 return -EINVAL;
1398 if ((err = verify_area(VERIFY_WRITE, (long *)useraddr, sizeof(long))))
1399 return err;
1400 put_fs_long((unsigned)value, (long *) useraddr);
1401 return 0;
1402 }
1403
1404 static int ide_ioctl (struct inode *inode, struct file *file,
1405 unsigned int cmd, unsigned long arg)
1406 {
1407 struct hd_geometry *loc = (struct hd_geometry *) arg;
1408 int err;
1409 ide_dev_t *dev;
1410 unsigned long flags;
1411
1412 if (!inode || !inode->i_rdev)
1413 return -EINVAL;
1414 if ((dev = get_info_ptr(inode->i_rdev)) == NULL)
1415 return -ENODEV;
1416 switch (cmd) {
1417 case HDIO_GETGEO:
1418 if (!loc || dev->type != disk) return -EINVAL;
1419 err = verify_area(VERIFY_WRITE, loc, sizeof(*loc));
1420 if (err) return err;
1421 put_fs_byte(dev->bios_head,
1422 (char *) &loc->heads);
1423 put_fs_byte(dev->bios_sect,
1424 (char *) &loc->sectors);
1425 put_fs_word(dev->bios_cyl,
1426 (short *) &loc->cylinders);
1427 put_fs_long((unsigned)ide_hd[DEV_HWIF][MINOR(inode->i_rdev)].start_sect,
1428 (long *) &loc->start);
1429 return 0;
1430
1431 case BLKFLSBUF:
1432 if(!suser()) return -EACCES;
1433 fsync_dev(inode->i_rdev);
1434 invalidate_buffers(inode->i_rdev);
1435 return 0;
1436
1437 case BLKRASET:
1438 if(!suser()) return -EACCES;
1439 if(arg > 0xff) return -EINVAL;
1440 read_ahead[MAJOR(inode->i_rdev)] = arg;
1441 return 0;
1442
1443 case BLKRAGET:
1444 return write_fs_long(arg, read_ahead[MAJOR(inode->i_rdev)]);
1445
1446 case BLKGETSIZE:
1447 return write_fs_long(arg, ide_hd[DEV_HWIF][MINOR(inode->i_rdev)].nr_sects);
1448 case BLKRRPART:
1449 return revalidate_disk(inode->i_rdev);
1450
1451 case HDIO_GET_KEEPSETTINGS:
1452 return write_fs_long(arg, dev->keep_settings);
1453
1454 case HDIO_GET_UNMASKINTR:
1455 return write_fs_long(arg, dev->unmask);
1456
1457 case HDIO_GET_MULTCOUNT:
1458 return write_fs_long(arg, dev->mult_count);
1459
1460 case HDIO_GET_IDENTITY:
1461 if (!arg || (MINOR(inode->i_rdev) & PARTN_MASK))
1462 return -EINVAL;
1463 if (dev->id == NULL)
1464 return -ENOMSG;
1465 err = verify_area(VERIFY_WRITE, (char *)arg, sizeof(*dev->id));
1466 if (err) return err;
1467 memcpy_tofs((char *)arg, (char *)dev->id, sizeof(*dev->id));
1468 return 0;
1469
1470 case HDIO_SET_KEEPSETTINGS:
1471 if (!suser()) return -EACCES;
1472 if ((arg > 1) || (MINOR(inode->i_rdev) & PARTN_MASK))
1473 return -EINVAL;
1474 save_flags(flags);
1475 cli();
1476 dev->keep_settings = arg;
1477 restore_flags(flags);
1478 return 0;
1479
1480 case HDIO_SET_UNMASKINTR:
1481 if (!suser()) return -EACCES;
1482 if ((arg > 1) || (MINOR(inode->i_rdev) & PARTN_MASK))
1483 return -EINVAL;
1484 save_flags(flags);
1485 cli();
1486 dev->unmask = arg;
1487 restore_flags(flags);
1488 return 0;
1489
1490 case HDIO_SET_MULTCOUNT:
1491 if (!suser()) return -EACCES;
1492 if (MINOR(inode->i_rdev) & PARTN_MASK)
1493 return -EINVAL;
1494 if ((dev->id != NULL) && (arg > dev->id->max_multsect))
1495 return -EINVAL;
1496 save_flags(flags);
1497 cli();
1498 if (dev->special.b.set_multmode) {
1499 restore_flags(flags);
1500 return -EBUSY;
1501 }
1502 dev->mult_req = arg;
1503 dev->special.b.set_multmode = 1;
1504 restore_flags(flags);
1505 #ifdef IDE_DRIVE_CMD
1506 do_drive_cmd (inode->i_rdev, NULL);
1507 return (dev->mult_count == arg) ? 0 : -EIO;
1508 #else
1509 return 0;
1510 #endif
1511
1512 #ifdef IDE_DRIVE_CMD
1513 case HDIO_DRIVE_CMD:
1514 {
1515 unsigned long args;
1516
1517 if (NULL == (long *) arg)
1518 err = do_drive_cmd(inode->i_rdev,NULL);
1519 else {
1520 if (!(err = verify_area(VERIFY_WRITE,(long *)arg,sizeof(long))))
1521 {
1522 args = get_fs_long((long *)arg);
1523 err = do_drive_cmd(inode->i_rdev,(char *)&args);
1524 put_fs_long(args,(long *)arg);
1525 }
1526 }
1527 return err;
1528 }
1529 #endif
1530
1531 RO_IOCTLS(inode->i_rdev, arg);
1532
1533 default:
1534 #ifdef CONFIG_BLK_DEV_IDECD
1535 if (dev->type == cdrom)
1536 return ide_cdrom_ioctl(dev, inode, file, cmd, arg);
1537 #endif
1538 return -EPERM;
1539 }
1540 }
1541
1542 #ifdef CONFIG_BLK_DEV_IDECD
1543 static int ide_check_media_change (dev_t full_dev)
1544 {
1545 ide_dev_t *dev;
1546
1547 if ((dev = get_info_ptr(full_dev)) == NULL)
1548 return -ENODEV;
1549 if (dev->type != cdrom)
1550 return 0;
1551 return cdrom_check_media_change (dev);
1552 }
1553 #endif
1554
1555
1556 static void fixstring (byte *s, int bytecount, int byteswap)
1557 {
1558 byte *p, *end = &s[bytecount &= ~1];
1559
1560 if (byteswap) {
1561
1562 for (p = end ; p != s;) {
1563 unsigned short *pp = (unsigned short *) (p -= 2);
1564 *pp = (*pp >> 8) | (*pp << 8);
1565 }
1566 }
1567 p = s;
1568
1569
1570 while (s != end && *s == ' ')
1571 ++s;
1572
1573
1574 while (s != end && *s) {
1575 if (*s++ != ' ' || (s != end && *s && *s != ' '))
1576 *p++ = *(s-1);
1577 }
1578
1579
1580 while (p != end)
1581 *p++ = '\0';
1582 }
1583
1584 static int lba_capacity_is_ok (struct hd_driveid *id)
1585
1586
1587
1588
1589 {
1590 unsigned long lba_sects = id->lba_capacity;
1591 unsigned long chs_sects = id->cyls * id->heads * id->sectors;
1592 unsigned long _10_percent = chs_sects / 10;
1593
1594
1595 if ((lba_sects - chs_sects) < _10_percent)
1596 return 1;
1597
1598
1599 lba_sects = (lba_sects << 16) | (lba_sects >> 16);
1600 if ((lba_sects - chs_sects) < _10_percent) {
1601 id->lba_capacity = lba_sects;
1602 return 1;
1603 }
1604 return 0;
1605 }
1606
1607 static unsigned long probe_mem_start;
1608
1609 static void do_identify (ide_dev_t *dev, byte cmd)
1610 {
1611 int bswap;
1612 struct hd_driveid *id;
1613 unsigned long capacity, check;
1614
1615 id = dev->id = (struct hd_driveid *) probe_mem_start;
1616 probe_mem_start += 512;
1617 IN_SECTORS(id,1);
1618 sti();
1619
1620
1621
1622
1623
1624 bswap = 1;
1625 if (cmd == WIN_PIDENTIFY) {
1626 if ((id->model[0] == 'N' && id->model[1] == 'E')
1627 || (id->model[0] == 'F' && id->model[1] == 'X'))
1628 bswap = 0;
1629 }
1630 fixstring (id->model, sizeof(id->model), bswap);
1631 fixstring (id->fw_rev, sizeof(id->fw_rev), bswap);
1632 fixstring (id->serial_no, sizeof(id->serial_no), bswap);
1633
1634
1635
1636
1637 if (cmd == WIN_PIDENTIFY) {
1638 #ifdef CONFIG_BLK_DEV_IDECD
1639 byte type = (id->config >> 8) & 0x0f;
1640 #endif
1641 printk("%s: %s, ATAPI,", dev->name, id->model);
1642 #ifdef CONFIG_BLK_DEV_IDECD
1643 if (type == 0 || type == 5)
1644 printk(" CDROM drive\n");
1645 else
1646 printk(" UNKNOWN device\n");
1647 dev->type = cdrom;
1648 dev->present = 1;
1649 #else
1650 printk(unsupported);
1651 #endif
1652 return;
1653 }
1654
1655 dev->type = disk;
1656
1657 if (!dev->present) {
1658 dev->present = 1;
1659 dev->cyl = dev->bios_cyl = id->cyls;
1660 dev->head = dev->bios_head = id->heads;
1661 dev->sect = dev->bios_sect = id->sectors;
1662 }
1663
1664 if ((id->field_valid & 1) && id->cur_cyls && id->cur_heads
1665 && (id->cur_heads <= 16) && id->cur_sectors)
1666 {
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677 dev->cyl = id->cur_cyls;
1678 dev->head = id->cur_heads;
1679 dev->sect = id->cur_sectors;
1680 capacity = dev->cyl * dev->head * dev->sect;
1681
1682
1683 check = (id->cur_capacity0 << 16) | id->cur_capacity1;
1684 if (check == capacity)
1685 *((int *)&id->cur_capacity0) = capacity;
1686 }
1687
1688 if ((!dev->head || dev->head > 16) && id->heads && id->heads <= 16) {
1689 dev->cyl = id->cyls;
1690 dev->head = id->heads;
1691 dev->sect = id->sectors;
1692 }
1693
1694 if (dev->sect == dev->bios_sect && dev->head == dev->bios_head) {
1695 if (dev->cyl > dev->bios_cyl)
1696 dev->bios_cyl = dev->cyl;
1697 }
1698
1699 if ((id->capability & 2) && lba_capacity_is_ok(id)) {
1700 dev->select.b.lba = 1;
1701 capacity = id->lba_capacity;
1702 } else {
1703 capacity = dev->cyl * dev->head * dev->sect;
1704 }
1705
1706 ide_capacity[DEV_HWIF][dev->select.b.drive] = capacity;
1707 printk ("%s: %.40s, %ldMB w/%dKB Cache, %sCHS=%d/%d/%d",
1708 dev->name, id->model, capacity/2048L, id->buf_size/2,
1709 dev->select.b.lba ? "LBA, " : "",
1710 dev->bios_cyl, dev->bios_head, dev->bios_sect);
1711
1712 dev->mult_count = 0;
1713 if (id->max_multsect) {
1714 dev->mult_req = INITIAL_MULT_COUNT;
1715 if (dev->mult_req > id->max_multsect)
1716 dev->mult_req = id->max_multsect;
1717 if (dev->mult_req || ((id->multsect_valid & 1) && id->multsect))
1718 dev->special.b.set_multmode = 1;
1719 printk(", MaxMult=%d", id->max_multsect);
1720 }
1721 printk("\n");
1722 }
1723
1724 static void delay_10ms (void)
1725 {
1726 unsigned long timer = jiffies + 2;
1727 while (timer > jiffies);
1728 }
1729
1730
1731 static int try_to_identify (ide_dev_t *dev, byte cmd)
1732
1733
1734
1735
1736
1737 {
1738 int hd_status, rc;
1739 unsigned long timeout;
1740 #if PROBE_FOR_IRQS
1741 int irqs = 0;
1742 static byte irq_probed[2] = {0,0};
1743 #endif
1744
1745 OUT_BYTE(dev->ctl|2,HD_CMD);
1746 #if PROBE_FOR_IRQS
1747 if (!irq_probed[DEV_HWIF]) {
1748 irqs = probe_irq_on();
1749 OUT_BYTE(dev->ctl,HD_CMD);
1750 }
1751 #endif
1752 delay_10ms();
1753 if ((IN_BYTE(HD_ALTSTATUS,DEV_HWIF) ^ IN_BYTE(HD_STATUS,DEV_HWIF)) & ~INDEX_STAT) {
1754 hd_status = HD_STATUS;
1755 printk("%s: probing with STATUS instead of ALTSTATUS\n", dev->name);
1756 } else
1757 hd_status = HD_ALTSTATUS;
1758 OUT_BYTE(cmd,HD_COMMAND);
1759 timeout = ((cmd == WIN_IDENTIFY) ? WAIT_WORSTCASE : WAIT_PIDENTIFY) / 2;
1760 timeout += jiffies;
1761 do {
1762 if (jiffies > timeout) {
1763 #if PROBE_FOR_IRQS
1764 if (!irq_probed[DEV_HWIF])
1765 (void) probe_irq_off(irqs);
1766 #endif
1767 return 1;
1768 }
1769 delay_10ms();
1770 } while (IN_BYTE(hd_status,DEV_HWIF) & BUSY_STAT);
1771 delay_10ms();
1772 if (OK_STAT(GET_STAT(DEV_HWIF),DRQ_STAT,BAD_RW_STAT)) {
1773 cli();
1774 do_identify(dev, cmd);
1775 rc = 0;
1776 } else
1777 rc = 2;
1778 #if PROBE_FOR_IRQS
1779 if (!irq_probed[DEV_HWIF]) {
1780 irqs = probe_irq_off(irqs);
1781 if (irqs > 0) {
1782 irq_probed[DEV_HWIF] = 1;
1783 ide_irq[DEV_HWIF] = irqs;
1784 } else
1785 printk("%s: IRQ probe failed (%d)\n", dev->name, irqs);
1786 }
1787 #endif
1788 return rc;
1789 }
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801 static int do_probe (ide_dev_t *dev, byte cmd)
1802
1803
1804
1805
1806
1807
1808
1809 {
1810 int rc;
1811
1812 #ifdef CONFIG_BLK_DEV_IDECD
1813 if (dev->present) {
1814 if ((dev->type == disk) ^ (cmd == WIN_IDENTIFY))
1815 return 4;
1816 }
1817 #endif
1818 #if DEBUG
1819 printk("probing for %s: present=%d, type=%s, probetype=%s\n",
1820 dev->name, dev->present, dev->type ? "cdrom":"disk",
1821 (cmd == WIN_IDENTIFY) ? "ATA" : "ATAPI");
1822 #endif
1823 OUT_BYTE(dev->select.all,HD_CURRENT);
1824 delay_10ms();
1825 if (IN_BYTE(HD_CURRENT,DEV_HWIF) != dev->select.all && !dev->present) {
1826 OUT_BYTE(0xa0,HD_CURRENT);
1827 return 3;
1828 }
1829
1830 if (OK_STAT(GET_STAT(DEV_HWIF),READY_STAT,BUSY_STAT)
1831 || dev->present || cmd == WIN_PIDENTIFY)
1832 {
1833 if ((rc = try_to_identify(dev, cmd)))
1834 rc = try_to_identify(dev, cmd);
1835 if (rc == 1)
1836 printk("%s: no response (status = 0x%02x)\n",
1837 dev->name, GET_STAT(DEV_HWIF));
1838 OUT_BYTE(dev->ctl|2,HD_CMD);
1839 delay_10ms();
1840 (void) GET_STAT(DEV_HWIF);
1841 } else {
1842 rc = 3;
1843 }
1844 if (dev->select.b.drive == 1) {
1845 OUT_BYTE(0xa0,HD_CURRENT);
1846 delay_10ms();
1847 OUT_BYTE(dev->ctl|2,HD_CMD);
1848 delay_10ms();
1849 (void) GET_STAT(DEV_HWIF);
1850 }
1851 return rc;
1852 }
1853
1854 static byte probe_for_drive (ide_dev_t *dev)
1855
1856
1857
1858
1859 {
1860 if (dev->dont_probe)
1861 return dev->present;
1862 if (do_probe(dev, WIN_IDENTIFY) >= 2) {
1863 #ifdef CONFIG_BLK_DEV_IDECD
1864 (void) do_probe(dev, WIN_PIDENTIFY);
1865 #endif
1866 }
1867 if (!dev->present)
1868 return 0;
1869 if (dev->id == NULL) {
1870 if (dev->type == disk) {
1871 printk ("%s: non-IDE device, CHS=%d/%d/%d\n",
1872 dev->name, dev->cyl, dev->head, dev->sect);
1873 }
1874 #ifdef CONFIG_BLK_DEV_IDECD
1875 else if (dev->type == cdrom) {
1876 printk("%s: ATAPI cdrom (?)\n", dev->name);
1877 }
1878 #endif
1879 else {
1880 dev->present = 0;
1881 return 1;
1882 }
1883 }
1884 #ifdef CONFIG_BLK_DEV_IDECD
1885 if (dev->type == cdrom)
1886 cdrom_setup(dev);
1887 #endif
1888 if (dev->type == disk && !dev->select.b.lba) {
1889 if (!dev->head || dev->head > 16) {
1890 printk("%s: cannot handle disk with %d physical heads\n",
1891 dev->name, dev->head);
1892 dev->present = 0;
1893 }
1894 }
1895 return 1;
1896 }
1897
1898 static void probe_for_drives (byte hwif)
1899 {
1900 ide_dev_t *devs = &ide_dev[HWIF][0];
1901
1902 if (check_region(IDE_PORT(HD_DATA,HWIF),8)
1903 || check_region(IDE_PORT(HD_CMD,HWIF),1))
1904 {
1905 if (devs[0].present || devs[1].present)
1906 printk("ERROR: ");
1907 printk("%s: port(s) already in use\n", ide_name[HWIF]);
1908 devs[0].present = 0;
1909 devs[1].present = 0;
1910 } else {
1911 unsigned long flags;
1912 save_flags(flags);
1913 sti();
1914
1915
1916 if (probe_for_drive(&devs[0]) || devs[1].present)
1917 (void) probe_for_drive(&devs[1]);
1918 #if PROBE_FOR_IRQS
1919 (void) probe_irq_off(probe_irq_on());
1920 #endif
1921 if (devs[0].present || devs[1].present) {
1922 request_region(IDE_PORT(HD_DATA,HWIF),8,ide_name[HWIF]);
1923 request_region(IDE_PORT(HD_CMD,HWIF),1,ide_name[HWIF]);
1924 }
1925 restore_flags(flags);
1926 }
1927 }
1928
1929 static int next_drive = 0;
1930
1931 void ide_setup(char *str, int *ints)
1932 {
1933 ide_dev_t *dev;
1934 const char *p[] = {"cyls","heads","sects","wpcom","irq"};
1935 int i, hwif, drive = next_drive++;
1936 #ifdef CONFIG_BLK_DEV_HD
1937 extern void hd_setup(char *, int *);
1938
1939 if (drive < 2) {
1940 hd_setup (str, ints);
1941 return;
1942 }
1943 #endif
1944 hwif = (drive > 1);
1945 printk("%s: ", ide_name[hwif]);
1946 if (drive > 3) {
1947 printk("too many drives defined\n");
1948 return;
1949 }
1950 drive = drive & 1;
1951 printk("%s: ", ide_devname[hwif][drive]);
1952 if (!SUPPORT_TWO_INTERFACES && hwif != HWIF) {
1953 printk(unsupported);
1954 return;
1955 }
1956 dev = &ide_dev[hwif][drive];
1957 if (dev->present)
1958 printk("(redefined) ");
1959 if (ints[0] == 0) {
1960 if (!strcmp(str,"noprobe")) {
1961 printk("noprobe\n");
1962 dev->dont_probe = 1;
1963 return;
1964 }
1965 #ifdef CONFIG_BLK_DEV_IDECD
1966 if (!strcmp(str,"cdrom")) {
1967 printk("cdrom\n");
1968 dev->present = 1;
1969 dev->type = cdrom;
1970 return;
1971 }
1972 #endif
1973 }
1974 if (ints[0] < 3 || ints[0] > 5) {
1975 printk("bad parms, expected: cyls,heads,sects[,wpcom[,irq]]\n");
1976 } else {
1977 for (i=0; i++ < ints[0];)
1978 printk("%s=%d%c",p[i-1],ints[i],i<ints[0]?',':'\n');
1979 dev->type = disk;
1980 dev->cyl = dev->bios_cyl = ints[1];
1981 dev->head = dev->bios_head = ints[2];
1982 dev->ctl = (ints[2] > 8 ? 8 : 0);
1983 dev->sect = dev->bios_sect = ints[3];
1984 dev->wpcom = (ints[0] >= 4) ? ints[4] : 0;
1985 if (ints[0] >= 5)
1986 ide_irq[HWIF] = ints[5];
1987 ide_capacity[HWIF][drive] = BIOS_SECTORS(dev);
1988 dev->present = 1;
1989 }
1990 }
1991
1992 void hda_setup(char *str, int *ints)
1993 {
1994 next_drive = 0;
1995 ide_setup (str, ints);
1996 }
1997
1998 void hdb_setup(char *str, int *ints)
1999 {
2000 next_drive = 1;
2001 ide_setup (str, ints);
2002 }
2003
2004 void hdc_setup(char *str, int *ints)
2005 {
2006 next_drive = 2;
2007 ide_setup (str, ints);
2008 }
2009
2010 void hdd_setup(char *str, int *ints)
2011 {
2012 next_drive = 3;
2013 ide_setup (str, ints);
2014 }
2015
2016 #ifndef CONFIG_BLK_DEV_HD
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029 extern struct drive_info_struct drive_info;
2030 static void probe_cmos_for_drives (void)
2031 {
2032 byte drive, cmos_disks, *BIOS = (byte *) &drive_info;
2033
2034 outb_p(0x12,0x70);
2035 cmos_disks = inb_p(0x71);
2036
2037 for (drive = 0; drive < MAX_DRIVES; drive++) {
2038 ide_dev_t *dev = &ide_dev[0][drive];
2039 if ((cmos_disks & (0xf0 >> (drive*4))) && !dev->present) {
2040 dev->cyl = dev->bios_cyl = *(unsigned short *)BIOS;
2041 dev->head = dev->bios_head = * (BIOS+2);
2042 dev->sect = dev->bios_sect = * (BIOS+14);
2043 dev->wpcom = (*(unsigned short *)(BIOS+5))>>2;
2044 dev->ctl = *(BIOS+8);
2045 dev->wpcom = 0;
2046 dev->type = disk;
2047 dev->present = 1;
2048 ide_capacity[0][drive] = BIOS_SECTORS(dev);
2049 }
2050 BIOS += 16;
2051 }
2052 }
2053 #endif
2054
2055 static void init_ide_data (byte hwif)
2056 {
2057 int drive;
2058
2059 for (drive = 0; drive < (MAX_DRIVES<<PARTN_BITS); drive++)
2060 ide_blksizes[hwif][drive] = 1024;
2061 blksize_size[ide_major[hwif]] = ide_blksizes[hwif];
2062
2063
2064 for (drive = 0; drive < MAX_DRIVES; drive++) {
2065 ide_dev_t *dev = &ide_dev[hwif][drive];
2066 dev->select.all = (drive<<4)|0xa0;
2067 dev->hwif = hwif;
2068 dev->unmask = 0;
2069 dev->busy = 0;
2070 dev->mult_count = 0;
2071 dev->mult_req = 0;
2072 dev->usage = 0;
2073 dev->id = NULL;
2074 dev->ctl = 0x08;
2075 dev->wqueue = NULL;
2076 dev->special.all = 0;
2077 dev->special.b.recalibrate = 1;
2078 dev->special.b.set_geometry = 1;
2079 dev->keep_settings = 0;
2080 ide_hd[hwif][drive<<PARTN_BITS].start_sect = 0;
2081 dev->name = ide_devname[hwif][drive];
2082 }
2083 }
2084
2085
2086
2087
2088
2089
2090
2091 static byte setup_irq (byte hwif)
2092 {
2093 static byte rc = 0;
2094 unsigned long flags;
2095 const char *msg = "", *primary_secondary[] = {"primary", "secondary"};
2096 void (*handler)(int, struct pt_regs *) = HWIF ? &ide1_intr : &ide0_intr;
2097
2098 #if SUPPORT_SHARING_IRQ
2099 if (sharing_single_irq) {
2100 if (HWIF != 0 && !rc) {
2101 msg = " (shared with ide0)";
2102 goto done;
2103 }
2104 handler = &ide_shared_intr;
2105 }
2106 #endif
2107 save_flags(flags);
2108 cli();
2109 if ((rc = request_irq(ide_irq[HWIF],handler,SA_INTERRUPT,ide_name[HWIF])))
2110 msg = ": FAILED! unable to allocate IRQ";
2111 restore_flags(flags);
2112 #if SUPPORT_SHARING_IRQ
2113 done:
2114 #endif
2115 printk("%s: %s interface on irq %d%s\n",
2116 ide_name[HWIF], primary_secondary[HWIF], ide_irq[HWIF], msg);
2117 return rc;
2118 }
2119
2120 static void ide_geninit(byte hwif)
2121 {
2122 static int drive;
2123
2124 for (drive = 0; drive < MAX_DRIVES; drive++) {
2125 ide_dev_t *dev = &ide_dev[HWIF][drive];
2126 if (dev->present) {
2127 ide_hd[HWIF][drive<<PARTN_BITS].nr_sects = ide_capacity[HWIF][drive];
2128
2129 if (dev->type == cdrom)
2130 ide_hd[HWIF][drive<<PARTN_BITS].start_sect = -1;
2131 }
2132 }
2133 }
2134
2135 static void ide0_geninit(void)
2136 {
2137 ide_geninit(0);
2138 }
2139
2140 static void ide1_geninit(void)
2141 {
2142 ide_geninit(1);
2143 }
2144
2145 static struct file_operations ide_fops = {
2146 NULL,
2147 block_read,
2148 block_write,
2149 NULL,
2150 NULL,
2151 ide_ioctl,
2152 NULL,
2153 ide_open,
2154 ide_release,
2155 block_fsync
2156 #ifdef CONFIG_BLK_DEV_IDECD
2157 ,NULL,
2158 ide_check_media_change,
2159 NULL
2160 #endif CONFIG_BLK_DEV_IDECD
2161 };
2162
2163
2164
2165
2166 unsigned long ide_init (unsigned long mem_start, unsigned long mem_end)
2167 {
2168 byte hwif;
2169
2170 for (hwif = 0; hwif < 2; hwif++) {
2171 init_ide_data (hwif);
2172 if (SUPPORT_TWO_INTERFACES || hwif == HWIF) {
2173 if (hwif == 0)
2174 #ifdef CONFIG_BLK_DEV_HD
2175 continue;
2176 #else
2177 probe_cmos_for_drives ();
2178 #endif
2179 probe_mem_start = (mem_start + 3uL) & ~3uL;
2180 probe_for_drives (hwif);
2181 mem_start = probe_mem_start;
2182 }
2183 }
2184
2185
2186 ide_gendisk[0].nr_real = ide_dev[0][0].present + ide_dev[0][1].present;
2187 ide_gendisk[1].nr_real = ide_dev[1][0].present + ide_dev[1][1].present;
2188 if (ide_gendisk[1].nr_real && (ide_irq[0] == ide_irq[1])) {
2189 if (!ide_gendisk[0].nr_real) {
2190 ide_irq[0] = 0;
2191 } else {
2192 #if SUPPORT_SHARING_IRQ
2193 sharing_single_irq = 1;
2194 #else
2195 printk("%s: ide irq-sharing%s", ide_name[1], unsupported);
2196 return mem_start;
2197 #endif
2198 }
2199 }
2200 #ifdef CONFIG_BLK_DEV_HD
2201 #if SUPPORT_SHARING_IRQ
2202 if (ide_irq[1] == 14 || sharing_single_irq) {
2203 #else
2204 if (ide_irq[1] == 14) {
2205 #endif
2206 printk("%s: irq-sharing not possible with old harddisk driver (hd.c)\n", ide_name[1]);
2207 return mem_start;
2208 }
2209 #endif
2210
2211 for (hwif = 2; hwif-- > 0;) {
2212 if (ide_gendisk[hwif].nr_real != 0 && !setup_irq(hwif)) {
2213 const char *name = ide_name[HWIF];
2214 unsigned int major = ide_major[HWIF];
2215 if (register_blkdev(major, name, &ide_fops)) {
2216 printk("%s: unable to get major number %d\n", name, major);
2217 } else {
2218 timer_table[ide_timer[HWIF]].fn
2219 = HWIF ? ide1_timer_expiry : ide0_timer_expiry;
2220 #if SUPPORT_SHARING_IRQ
2221 if (sharing_single_irq)
2222 blk_dev[major].request_fn = &do_shared_request;
2223 else
2224 #endif
2225 blk_dev[major].request_fn =
2226 HWIF ? &do_ide1_request : &do_ide0_request;
2227 read_ahead[major] = 8;
2228 ide_gendisk[HWIF].next = gendisk_head;
2229 gendisk_head = &ide_gendisk[HWIF];
2230 }
2231 }
2232 }
2233 return mem_start;
2234 }