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