This source file includes following definitions.
- read_timer
- ide_set_recovery_timer
- init_ide_data
- do_vlb_sync
- ide_input_data
- ide_output_data
- ide_set_handler
- lba_capacity_is_ok
- current_capacity
- ide_geninit
- ide_alloc
- init_gendisk
- reset_ihandler
- start_reset_timer
- reset_handler
- ide_do_reset
- end_drive_cmd
- ide_dump_status
- try_to_flush_leftover_data
- ide_error
- read_intr
- write_intr
- multwrite
- multwrite_intr
- ide_cmd
- set_multmode_intr
- set_geometry_intr
- recal_intr
- drive_cmd_intr
- do_special
- ide_wait_stat
- do_rw_disk
- do_request
- ide_do_request
- do_hwgroup_request
- do_ide0_request
- do_ide1_request
- do_ide2_request
- do_ide3_request
- timer_expiry
- unexpected_intr
- ide_intr
- get_info_ptr
- write_fs_long
- do_drive_cmd
- ide_open
- ide_release
- revalidate_disk
- ide_ioctl
- ide_check_media_change
- fixstring
- do_identify
- delay_10ms
- try_to_identify
- do_probe
- probe_for_drive
- probe_for_drives
- stridx
- match_parm
- ide_setup
- ide_xlate_1024
- probe_cmos_for_drives
- init_irq
- sub22
- try_to_init_dtc2278
- 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
118
119
120
121
122
123
124
125
126
127
128 #include <linux/config.h>
129 #include <linux/types.h>
130 #include <linux/string.h>
131 #include <linux/kernel.h>
132 #include <linux/delay.h>
133 #include <linux/timer.h>
134 #include <linux/mm.h>
135 #include <linux/ioport.h>
136 #include <linux/interrupt.h>
137 #include <linux/major.h>
138 #include <linux/blkdev.h>
139 #include <linux/errno.h>
140 #include <linux/hdreg.h>
141 #include <linux/genhd.h>
142 #include <asm/byteorder.h>
143 #include <asm/irq.h>
144
145 #include "ide.h"
146
147 static ide_hwif_t ide_hwifs[MAX_HWIFS];
148 static ide_hwgroup_t *irq_to_hwgroup [16];
149 static const byte ide_hwif_to_major[MAX_HWIFS] = {IDE0_MAJOR, IDE1_MAJOR, IDE2_MAJOR, IDE3_MAJOR};
150
151 static const unsigned short default_io_base[MAX_HWIFS] = {0x1f0, 0x170, 0x1e8, 0x168};
152 static const byte default_irqs[MAX_HWIFS] = {14, 15, 11, 10};
153 static int single_threaded = 0;
154
155 #if SUPPORT_DTC2278
156 static unsigned int probe_dtc2278 = 0;
157 #endif
158
159 #if (DISK_RECOVERY_TIME > 0)
160
161
162
163
164 static unsigned long read_timer(void)
165 {
166 unsigned long t, flags;
167 int i;
168
169 save_flags(flags);
170 cli();
171 t = jiffies * 11932;
172 outb_p(0, 0x43);
173 i = inb_p(0x40);
174 i |= inb(0x40) << 8;
175 restore_flags(flags);
176 return (t - i);
177 }
178
179 void ide_set_recovery_timer (ide_hwif_t *hwif)
180 {
181 hwif->last_time = read_timer();
182 }
183 #endif
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199 static void init_ide_data (void)
200 {
201 unsigned int h, unit;
202 static unsigned long magic_cookie = 0x12345678;
203
204 if (magic_cookie != 0x12345678)
205 return;
206 magic_cookie = 0;
207
208 for (h = 0; h < 16; ++h)
209 irq_to_hwgroup[h] = NULL;
210
211 for (h = 0; h < MAX_HWIFS; ++h) {
212 ide_hwif_t *hwif = &ide_hwifs[h];
213
214 hwif->noprobe = (h > 1);
215 hwif->hwgroup = NULL;
216 hwif->io_base = default_io_base[h];
217 hwif->ctl_port = hwif->io_base ? hwif->io_base + 0x206 : 0x000;
218 #ifdef CONFIG_BLK_DEV_HD
219 if (hwif->io_base == HD_DATA)
220 hwif->noprobe = 1;
221 #endif
222 hwif->gd = NULL;
223 hwif->irq = 0;
224 hwif->major = ide_hwif_to_major[h];
225 hwif->name[0] = 'i';
226 hwif->name[1] = 'd';
227 hwif->name[2] = 'e';
228 hwif->name[3] = '0' + h;
229 hwif->name[4] = '\0';
230 hwif->present = 0;
231 hwif->next = NULL;
232 hwif->reset_timeout = 0;
233
234 for (unit = 0; unit < MAX_DRIVES; ++unit) {
235 ide_drive_t *drive = &hwif->drives[unit];
236
237
238 byte *p = ((byte *) drive) + sizeof(ide_drive_t);
239 do {
240 *--p = 0;
241 } while (p > (byte *) drive);
242
243
244 drive->select.all = (unit<<4)|0xa0;
245 drive->hwif = hwif;
246 drive->ctl = 0x08;
247 drive->ready_stat = READY_STAT;
248 drive->bad_wstat = BAD_W_STAT;
249 drive->special.b.recalibrate = 1;
250 drive->special.b.set_geometry = 1;
251 drive->name[0] = 'h';
252 drive->name[1] = 'd';
253 drive->name[2] = 'a' + (h * MAX_DRIVES) + unit;
254 }
255 }
256 }
257
258 #ifdef __i386__
259 #define VLB_SYNC 1
260
261 static inline void do_vlb_sync (unsigned short port) {
262 unsigned int _v;
263 __asm__ __volatile__ (
264 "inb %w1,%b0\n\t"
265 "inb %w1,%b0\n\t"
266 "inb %w1,%b0"
267 : "=&a" (_v)
268 : "d" (port) );
269 }
270 #endif
271
272
273
274
275 void ide_input_data (ide_drive_t *drive, void *buffer, unsigned int wcount)
276 {
277 if (drive->vlb_32bit) {
278 #ifdef VLB_SYNC
279 if (drive->vlb_sync) {
280 cli();
281 do_vlb_sync(IDE_NSECTOR_REG);
282 insl(IDE_DATA_REG, buffer, wcount);
283 if (drive->unmask)
284 sti();
285 } else
286 #endif
287 insl(IDE_DATA_REG, buffer, wcount);
288 } else
289 insw(IDE_DATA_REG, buffer, wcount<<1);
290 }
291
292
293
294
295 void ide_output_data (ide_drive_t *drive, void *buffer, unsigned int wcount)
296 {
297 if (drive->vlb_32bit) {
298 #ifdef VLB_SYNC
299 if (drive->vlb_sync) {
300 cli();
301 do_vlb_sync(IDE_NSECTOR_REG);
302 outsl(IDE_DATA_REG, buffer, wcount);
303 if (drive->unmask)
304 sti();
305 } else
306 #endif
307 outsl(IDE_DATA_REG, buffer, wcount);
308 } else
309 outsw(IDE_DATA_REG, buffer, wcount<<1);
310 }
311
312
313
314
315
316
317
318
319 void ide_set_handler (ide_drive_t *drive, ide_handler_t *handler)
320 {
321 ide_hwgroup_t *hwgroup = HWGROUP(drive);
322 #ifdef DEBUG
323 if (hwgroup->handler != NULL)
324 printk("%s: ide_set_handler: old handler not null\n", drive->name);
325 #endif
326 hwgroup->handler = handler;
327 hwgroup->timer.expires = jiffies + WAIT_CMD;
328 add_timer(&(hwgroup->timer));
329 }
330
331
332
333
334
335
336
337
338 static int lba_capacity_is_ok (struct hd_driveid *id)
339 {
340 unsigned long lba_sects = id->lba_capacity;
341 unsigned long chs_sects = id->cyls * id->heads * id->sectors;
342 unsigned long _10_percent = chs_sects / 10;
343
344
345 if ((lba_sects - chs_sects) < _10_percent)
346 return 1;
347
348
349 lba_sects = (lba_sects << 16) | (lba_sects >> 16);
350 if ((lba_sects - chs_sects) < _10_percent) {
351 id->lba_capacity = lba_sects;
352 return 1;
353 }
354 return 0;
355 }
356
357
358
359
360
361 static unsigned long current_capacity (ide_drive_t *drive)
362 {
363 struct hd_driveid *id = drive->id;
364 unsigned long capacity;
365
366 if (!drive->present)
367 return 0;
368 if (drive->media != disk)
369 return 0x1fffff;
370
371 if (id != NULL && (id->capability & 2) && lba_capacity_is_ok(id)) {
372 drive->select.b.lba = 1;
373 capacity = id->lba_capacity;
374 } else {
375 drive->select.b.lba = 0;
376 capacity = drive->cyl * drive->head * drive->sect;
377 }
378 return (capacity - drive->sect0);
379 }
380
381
382
383
384
385 static void ide_geninit (struct gendisk *gd)
386 {
387 unsigned int unit;
388 ide_hwif_t *hwif = gd->real_devices;
389
390 for (unit = 0; unit < gd->nr_real; ++unit) {
391 ide_drive_t *drive = &hwif->drives[unit];
392 drive->part[0].nr_sects = current_capacity(drive);
393 if (!drive->present || drive->media != disk) {
394 drive->part[0].start_sect = -1;
395 }
396 }
397
398
399
400
401
402
403 gd->real_devices = hwif->drives[0].name;
404 }
405
406
407
408
409 static unsigned long init_mem_start = 0uL;
410
411 static inline void *ide_alloc (unsigned long bytecount)
412 {
413 unsigned long p = init_mem_start;
414 if (!p) panic("ide: ide_alloc() not valid now\n");
415 init_mem_start += (bytecount + 3uL) & ~3uL;
416 return (void *) p;
417 }
418
419
420
421
422
423
424
425 static void init_gendisk (ide_hwif_t *hwif)
426 {
427 struct gendisk *gd;
428 unsigned int unit, units, minors;
429 int *bs;
430
431
432 for (units = MAX_DRIVES; units > 0; --units) {
433 if (hwif->drives[units-1].present)
434 break;
435 }
436 minors = units * (1<<PARTN_BITS);
437 gd = ide_alloc(sizeof(struct gendisk));
438 gd->sizes = ide_alloc(minors * sizeof(int));
439 gd->part = ide_alloc(minors * sizeof(struct hd_struct));
440 bs = ide_alloc(minors*sizeof(int));
441
442
443 blksize_size[hwif->major] = bs;
444 for (unit = 0; unit < minors; ++unit)
445 *bs++ = BLOCK_SIZE;
446
447 for (unit = 0; unit < units; ++unit)
448 hwif->drives[unit].part = &gd->part[unit << PARTN_BITS];
449
450 gd->major = hwif->major;
451 gd->major_name = IDE_MAJOR_NAME;
452 gd->minor_shift = PARTN_BITS;
453 gd->max_p = 1<<PARTN_BITS;
454 gd->max_nr = units;
455 gd->nr_real = units;
456 gd->init = ide_geninit;
457 gd->real_devices= hwif;
458
459 gd->next = gendisk_head;
460 hwif->gd = gendisk_head = gd;
461 }
462
463 static void unexpected_intr (int, ide_hwgroup_t *);
464
465
466
467
468
469
470
471 static void reset_ihandler (ide_drive_t *drive)
472 {
473 unexpected_intr (HWIF(drive)->irq, HWGROUP(drive));
474 }
475
476
477
478
479
480 static void start_reset_timer (ide_hwif_t *hwif)
481 {
482 ide_hwgroup_t *hwgroup = hwif->hwgroup;
483
484 hwif->reset_timeout = jiffies + WAIT_WORSTCASE;
485 hwgroup->handler = &reset_ihandler;
486 hwgroup->timer.expires = jiffies + (HZ/20);
487 add_timer(&(hwgroup->timer));
488 }
489
490
491
492
493
494
495
496
497
498 static int reset_handler (ide_hwgroup_t *hwgroup)
499 {
500 ide_hwif_t *hwif = hwgroup->hwif;
501 ide_drive_t *drive = hwgroup->drive;
502 byte tmp;
503
504 if (!OK_STAT(tmp=GET_STAT(), 0, BUSY_STAT)) {
505 if (jiffies < hwif->reset_timeout) {
506 start_reset_timer (hwif);
507 return 1;
508 }
509 printk("%s: reset timed-out, status=0x%02x\n", hwif->name, tmp);
510 } else {
511 printk("%s: reset: ", hwif->name);
512 if ((tmp = GET_ERR()) == 1)
513 printk("success\n");
514 else {
515 printk("master: ");
516 switch (tmp & 0x7f) {
517 case 1: printk("passed");
518 break;
519 case 2: printk("formatter device error");
520 break;
521 case 3: printk("sector buffer error");
522 break;
523 case 4: printk("ECC circuitry error");
524 break;
525 case 5: printk("controlling MPU error");
526 break;
527 default:printk("error (0x%02x?)", tmp);
528 }
529 if (tmp & 0x80)
530 printk("; slave: failed");
531 printk("\n");
532 }
533 }
534 hwgroup->handler = NULL;
535 hwif->reset_timeout = 0;
536 return 0;
537 }
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555 static int ide_do_reset (ide_drive_t *drive)
556 {
557 unsigned int unit;
558 unsigned long flags;
559 ide_hwif_t *hwif = HWIF(drive);
560
561 save_flags(flags);
562 cli();
563
564
565
566
567
568 for (unit = 0; unit < MAX_DRIVES; ++unit) {
569 ide_drive_t *rdrive = &hwif->drives[unit];
570 rdrive->special.b.set_geometry = 1;
571 rdrive->special.b.recalibrate = 1;
572 rdrive->special.b.set_multmode = 0;
573 if (OK_TO_RESET_CONTROLLER)
574 rdrive->mult_count = 0;
575 if (!rdrive->keep_settings) {
576 rdrive->mult_req = 0;
577 rdrive->unmask = 0;
578 }
579 if (rdrive->mult_req != rdrive->mult_count)
580 rdrive->special.b.set_multmode = 1;
581 }
582
583 #if OK_TO_RESET_CONTROLLER
584
585
586
587
588
589
590
591
592 OUT_BYTE(drive->ctl|6,IDE_CONTROL_REG);
593 udelay(5);
594 OUT_BYTE(drive->ctl|2,IDE_CONTROL_REG);
595 hwif->reset_timeout = jiffies + WAIT_WORSTCASE;
596 start_reset_timer (hwif);
597 #endif
598
599 restore_flags (flags);
600 return OK_TO_RESET_CONTROLLER;
601 }
602
603
604
605
606 static void end_drive_cmd (ide_drive_t *drive, byte stat, byte err)
607 {
608 unsigned long flags;
609 struct request *rq = HWGROUP(drive)->rq;
610 byte *args = (byte *) rq->buffer;
611
612 rq->errors = !OK_STAT(stat,READY_STAT,BAD_STAT);
613 if (args) {
614 args[0] = stat;
615 args[1] = err;
616 args[2] = IN_BYTE(IDE_NSECTOR_REG);
617 }
618 save_flags(flags);
619 cli();
620 up(rq->sem);
621 HWGROUP(drive)->rq = NULL;
622 restore_flags(flags);
623 }
624
625
626
627
628 byte ide_dump_status (ide_drive_t *drive, const char *msg, byte stat)
629 {
630 unsigned long flags;
631 byte err = 0;
632
633 save_flags (flags);
634 sti();
635 printk("%s: %s: status=0x%02x", drive->name, msg, stat);
636 #if FANCY_STATUS_DUMPS
637 if (drive->media == disk) {
638 printk(" { ");
639 if (stat & BUSY_STAT)
640 printk("Busy ");
641 else {
642 if (stat & READY_STAT) printk("DriveReady ");
643 if (stat & WRERR_STAT) printk("WriteFault ");
644 if (stat & SEEK_STAT) printk("SeekComplete ");
645 if (stat & DRQ_STAT) printk("DataRequest ");
646 if (stat & ECC_STAT) printk("CorrectedError ");
647 if (stat & INDEX_STAT) printk("Index ");
648 if (stat & ERR_STAT) printk("Error ");
649 }
650 printk("}");
651 }
652 #endif
653 printk("\n");
654 if ((stat & (BUSY_STAT|ERR_STAT)) == ERR_STAT) {
655 err = GET_ERR();
656 printk("%s: %s: error=0x%02x", drive->name, msg, err);
657 #if FANCY_STATUS_DUMPS
658 if (drive->media == disk) {
659 printk(" { ");
660 if (err & BBD_ERR) printk("BadSector ");
661 if (err & ECC_ERR) printk("UncorrectableError ");
662 if (err & ID_ERR) printk("SectorIdNotFound ");
663 if (err & ABRT_ERR) printk("DriveStatusError ");
664 if (err & TRK0_ERR) printk("TrackZeroNotFound ");
665 if (err & MARK_ERR) printk("AddrMarkNotFound ");
666 printk("}");
667 if (err & (BBD_ERR|ECC_ERR|ID_ERR|MARK_ERR)) {
668 byte cur = IN_BYTE(IDE_SELECT_REG);
669 if (cur & 0x40) {
670 printk(", LBAsect=%ld", (unsigned long)
671 ((cur&0xf)<<24)
672 |(IN_BYTE(IDE_HCYL_REG)<<16)
673 |(IN_BYTE(IDE_LCYL_REG)<<8)
674 | IN_BYTE(IDE_SECTOR_REG));
675 } else {
676 printk(", CHS=%d/%d/%d",
677 (IN_BYTE(IDE_HCYL_REG)<<8) +
678 IN_BYTE(IDE_LCYL_REG),
679 cur & 0xf,
680 IN_BYTE(IDE_SECTOR_REG));
681 }
682 if (HWGROUP(drive)->rq)
683 printk(", sector=%ld", HWGROUP(drive)->rq->sector);
684 }
685 }
686 #endif
687 printk("\n");
688 }
689 restore_flags (flags);
690 return err;
691 }
692
693
694
695
696
697
698
699
700 static void try_to_flush_leftover_data (ide_drive_t *drive)
701 {
702 int i = (drive->mult_count ? drive->mult_count : 1) * SECTOR_WORDS;
703
704 while (i > 0) {
705 unsigned long buffer[16];
706 unsigned int wcount = (i > 16) ? 16 : i;
707 i -= wcount;
708 ide_input_data (drive, buffer, wcount);
709 }
710 }
711
712
713
714
715
716
717
718
719 int ide_error (ide_drive_t *drive, const char *msg, byte stat)
720 {
721 struct request *rq;
722 byte err;
723
724 err = ide_dump_status(drive, msg, stat);
725 if ((rq = HWGROUP(drive)->rq) == NULL || drive == NULL)
726 return 0;
727 #ifdef IDE_DRIVE_CMD
728 if (rq->cmd == IDE_DRIVE_CMD) {
729 end_drive_cmd(drive, stat, err);
730 return 0;
731 }
732 #endif
733 if (stat & BUSY_STAT) {
734 rq->errors |= ERROR_RESET;
735 } else {
736 if (drive->media == disk && (stat & ERR_STAT)) {
737
738 if (err & BBD_ERR)
739 rq->errors = ERROR_MAX;
740 else if (err & TRK0_ERR)
741 rq->errors |= ERROR_RECAL;
742 }
743 if ((stat & DRQ_STAT) && rq->cmd != WRITE)
744 try_to_flush_leftover_data(drive);
745 }
746 if (GET_STAT() & (BUSY_STAT|DRQ_STAT))
747 rq->errors |= ERROR_RESET;
748
749 if (rq->errors >= ERROR_MAX)
750 ide_end_request(0, HWGROUP(drive));
751 else {
752 if ((rq->errors & ERROR_RESET) == ERROR_RESET) {
753 ++rq->errors;
754 return ide_do_reset(drive);
755 } else if ((rq->errors & ERROR_RECAL) == ERROR_RECAL)
756 drive->special.b.recalibrate = 1;
757 ++rq->errors;
758 }
759 return 0;
760 }
761
762
763
764
765 static void read_intr (ide_drive_t *drive)
766 {
767 byte stat;
768 int i;
769 unsigned int msect, nsect;
770 struct request *rq;
771
772 if (!OK_STAT(stat=GET_STAT(),DATA_READY,BAD_R_STAT)) {
773 sti();
774 if (!ide_error(drive, "read_intr", stat))
775 IDE_DO_REQUEST;
776 return;
777 }
778 msect = drive->mult_count;
779 read_next:
780 rq = HWGROUP(drive)->rq;
781 if (msect) {
782 if ((nsect = rq->current_nr_sectors) > msect)
783 nsect = msect;
784 msect -= nsect;
785 } else
786 nsect = 1;
787 ide_input_data(drive, rq->buffer, nsect * SECTOR_WORDS);
788 #ifdef DEBUG
789 printk("%s: read: sectors(%ld-%ld), buffer=0x%08lx, remaining=%ld\n",
790 drive->name, rq->sector, rq->sector+nsect-1,
791 (unsigned long) rq->buffer+(nsect<<9), rq->nr_sectors-nsect);
792 #endif
793 rq->sector += nsect;
794 rq->buffer += nsect<<9;
795 rq->errors = 0;
796 i = (rq->nr_sectors -= nsect);
797 if ((rq->current_nr_sectors -= nsect) <= 0)
798 ide_end_request(1, HWGROUP(drive));
799 if (i > 0) {
800 if (msect)
801 goto read_next;
802 ide_set_handler (drive, &read_intr);
803 return;
804 }
805 IDE_DO_REQUEST;
806 }
807
808
809
810
811 static void write_intr (ide_drive_t *drive)
812 {
813 byte stat;
814 int i;
815 struct request *rq = HWGROUP(drive)->rq;
816
817 if (OK_STAT(stat=GET_STAT(),DRIVE_READY,drive->bad_wstat)) {
818 #ifdef DEBUG
819 printk("%s: write: sector %ld, buffer=0x%08lx, remaining=%ld\n",
820 drive->name, rq->sector, (unsigned long) rq->buffer,
821 rq->nr_sectors-1);
822 #endif
823 if ((rq->nr_sectors == 1) ^ ((stat & DRQ_STAT) != 0)) {
824 rq->sector++;
825 rq->buffer += 512;
826 rq->errors = 0;
827 i = --rq->nr_sectors;
828 --rq->current_nr_sectors;
829 if (rq->current_nr_sectors <= 0)
830 ide_end_request(1, HWGROUP(drive));
831 if (i > 0) {
832 ide_output_data (drive, rq->buffer, SECTOR_WORDS);
833 ide_set_handler (drive, &write_intr);
834 return;
835 }
836 IDE_DO_REQUEST;
837 return;
838 }
839 }
840 sti();
841 if (!ide_error(drive, "write_intr", stat))
842 IDE_DO_REQUEST;
843 }
844
845
846
847
848
849 static void multwrite (ide_drive_t *drive)
850 {
851 struct request *rq = &HWGROUP(drive)->wrq;
852 unsigned int mcount = drive->mult_count;
853
854 do {
855 unsigned int nsect = rq->current_nr_sectors;
856 if (nsect > mcount)
857 nsect = mcount;
858 mcount -= nsect;
859
860 ide_output_data(drive, rq->buffer, nsect<<7);
861 #ifdef DEBUG
862 printk("%s: multwrite: sector %ld, buffer=0x%08lx, count=%d, remaining=%ld\n",
863 drive->name, rq->sector, (unsigned long) rq->buffer,
864 nsect, rq->nr_sectors - nsect);
865 #endif
866 if ((rq->nr_sectors -= nsect) <= 0)
867 break;
868 if ((rq->current_nr_sectors -= nsect) == 0) {
869 if ((rq->bh = rq->bh->b_reqnext) != NULL) {
870 rq->current_nr_sectors = rq->bh->b_size>>9;
871 rq->buffer = rq->bh->b_data;
872 } else {
873 panic("%s: buffer list corrupted\n", drive->name);
874 break;
875 }
876 } else {
877 rq->buffer += nsect << 9;
878 }
879 } while (mcount);
880 }
881
882
883
884
885 static void multwrite_intr (ide_drive_t *drive)
886 {
887 byte stat;
888 int i;
889 struct request *rq = &HWGROUP(drive)->wrq;
890
891 if (OK_STAT(stat=GET_STAT(),DRIVE_READY,drive->bad_wstat)) {
892 if (stat & DRQ_STAT) {
893 if (rq->nr_sectors) {
894 multwrite(drive);
895 ide_set_handler (drive, &multwrite_intr);
896 return;
897 }
898 } else {
899 if (!rq->nr_sectors) {
900 rq = HWGROUP(drive)->rq;
901 for (i = rq->nr_sectors; i > 0;){
902 i -= rq->current_nr_sectors;
903 ide_end_request(1, HWGROUP(drive));
904 }
905 IDE_DO_REQUEST;
906 return;
907 }
908 }
909 }
910 sti();
911 if (!ide_error(drive, "multwrite_intr", stat))
912 IDE_DO_REQUEST;
913 }
914
915
916
917
918
919 static inline void ide_cmd(ide_drive_t *drive, byte cmd, byte nsect, ide_handler_t *handler)
920 {
921 ide_set_handler (drive, handler);
922 OUT_BYTE(drive->ctl,IDE_CONTROL_REG);
923 OUT_BYTE(nsect,IDE_NSECTOR_REG);
924 OUT_BYTE(cmd,IDE_COMMAND_REG);
925 }
926
927 static void set_multmode_intr (ide_drive_t *drive)
928 {
929 byte stat = GET_STAT();
930
931 sti();
932 if (OK_STAT(stat,READY_STAT,BAD_STAT)) {
933 drive->mult_count = drive->mult_req;
934 } else {
935 drive->mult_req = drive->mult_count = 0;
936 drive->special.b.recalibrate = 1;
937 (void) ide_dump_status(drive, "set_multmode", stat);
938 }
939 IDE_DO_REQUEST;
940 }
941
942 static void set_geometry_intr (ide_drive_t *drive)
943 {
944 byte stat = GET_STAT();
945
946 sti();
947 if (!OK_STAT(stat,READY_STAT,BAD_STAT))
948 if (ide_error(drive, "set_geometry_intr", stat))
949 return;
950 IDE_DO_REQUEST;
951 }
952
953 static void recal_intr (ide_drive_t *drive)
954 {
955 byte stat = GET_STAT();
956
957 sti();
958 if (!OK_STAT(stat,READY_STAT,BAD_STAT))
959 if (ide_error(drive, "recal_intr", stat))
960 return;
961 IDE_DO_REQUEST;
962 }
963
964 static void drive_cmd_intr (ide_drive_t *drive)
965 {
966 byte stat = GET_STAT();
967
968 sti();
969 if (OK_STAT(stat,READY_STAT,BAD_STAT))
970 end_drive_cmd (drive, stat, GET_ERR());
971 else if (ide_error(drive, "drive_cmd", stat))
972 return;
973 IDE_DO_REQUEST;
974 }
975
976 static void do_special (ide_drive_t *drive)
977 {
978 special_t *s = &drive->special;
979 #ifdef DEBUG
980 printk("%s: do_special: 0x%02x\n", drive->name, s->all);
981 #endif
982 if (s->b.set_geometry) {
983 s->b.set_geometry = 0;
984 if (drive->media == disk) {
985 OUT_BYTE(drive->sect,IDE_SECTOR_REG);
986 OUT_BYTE(drive->cyl,IDE_LCYL_REG);
987 OUT_BYTE(drive->cyl>>8,IDE_HCYL_REG);
988 OUT_BYTE(((drive->head-1)|drive->select.all)&0xBF,IDE_SELECT_REG);
989 ide_cmd(drive, WIN_SPECIFY, drive->sect, &set_geometry_intr);
990 }
991 } else if (s->b.recalibrate) {
992 s->b.recalibrate = 0;
993 if (drive->media == disk) {
994 ide_cmd(drive, WIN_RESTORE, drive->sect, &recal_intr);
995 }
996 } else if (s->b.set_multmode) {
997 s->b.set_multmode = 0;
998 if (drive->media == disk) {
999 if (drive->id && drive->mult_req > drive->id->max_multsect)
1000 drive->mult_req = drive->id->max_multsect;
1001 ide_cmd(drive, WIN_SETMULT, drive->mult_req, &set_multmode_intr);
1002 } else
1003 drive->mult_req = 0;
1004 } else if (s->all) {
1005 s->all = 0;
1006 printk("%s: bad special flag: 0x%02x\n", drive->name, s->all);
1007 }
1008 }
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021 int ide_wait_stat (ide_drive_t *drive, byte good, byte bad, unsigned long timeout)
1022 {
1023 byte stat;
1024
1025 udelay(1);
1026 if (GET_STAT() & BUSY_STAT) {
1027 unsigned long flags;
1028 save_flags(flags);
1029 sti();
1030 timeout += jiffies;
1031 while (GET_STAT() & BUSY_STAT) {
1032 if (jiffies > timeout) {
1033 restore_flags(flags);
1034 (void) ide_error(drive, "status timeout", GET_STAT());
1035 return 1;
1036 }
1037 }
1038 restore_flags(flags);
1039 udelay(1);
1040 }
1041 if (OK_STAT(stat=GET_STAT(), good, bad))
1042 return 0;
1043 (void) ide_error(drive, "status error", stat);
1044 return 1;
1045 }
1046
1047 static inline void do_rw_disk (ide_drive_t *drive, struct request *rq, unsigned long block)
1048 {
1049 OUT_BYTE(drive->ctl,IDE_CONTROL_REG);
1050 OUT_BYTE(rq->nr_sectors,IDE_NSECTOR_REG);
1051 if (drive->select.b.lba) {
1052 #ifdef DEBUG
1053 printk("%s: %sing: LBAsect=%ld, sectors=%ld, buffer=0x%08lx\n",
1054 drive->name, (rq->cmd==READ)?"read":"writ",
1055 block, rq->nr_sectors, (unsigned long) rq->buffer);
1056 #endif
1057 OUT_BYTE(block,IDE_SECTOR_REG);
1058 OUT_BYTE(block>>=8,IDE_LCYL_REG);
1059 OUT_BYTE(block>>=8,IDE_HCYL_REG);
1060 OUT_BYTE(((block>>8)&0x0f)|drive->select.all,IDE_SELECT_REG);
1061 } else {
1062 unsigned int sect,head,cyl,track;
1063 track = block / drive->sect;
1064 sect = block % drive->sect + 1;
1065 OUT_BYTE(sect,IDE_SECTOR_REG);
1066 head = track % drive->head;
1067 cyl = track / drive->head;
1068 OUT_BYTE(cyl,IDE_LCYL_REG);
1069 OUT_BYTE(cyl>>8,IDE_HCYL_REG);
1070 OUT_BYTE(head|drive->select.all,IDE_SELECT_REG);
1071 #ifdef DEBUG
1072 printk("%s: %sing: CHS=%d/%d/%d, sectors=%ld, buffer=0x%08lx\n",
1073 drive->name, (rq->cmd==READ)?"read":"writ", cyl,
1074 head, sect, rq->nr_sectors, (unsigned long) rq->buffer);
1075 #endif
1076 }
1077 if (rq->cmd == READ) {
1078 ide_set_handler(drive, &read_intr);
1079 OUT_BYTE(drive->mult_count ? WIN_MULTREAD : WIN_READ, IDE_COMMAND_REG);
1080 return;
1081 }
1082 if (rq->cmd == WRITE) {
1083 OUT_BYTE(drive->mult_count ? WIN_MULTWRITE : WIN_WRITE, IDE_COMMAND_REG);
1084 if (ide_wait_stat(drive, DATA_READY, drive->bad_wstat, WAIT_DRQ)) {
1085 printk("%s: no DRQ after issuing %s\n", drive->name,
1086 drive->mult_count ? "MULTWRITE" : "WRITE");
1087 return;
1088 }
1089 if (!drive->unmask)
1090 cli();
1091 if (drive->mult_count) {
1092 HWGROUP(drive)->wrq = *rq;
1093 ide_set_handler (drive, &multwrite_intr);
1094 multwrite(drive);
1095 } else {
1096 ide_set_handler (drive, &write_intr);
1097 ide_output_data(drive, rq->buffer, SECTOR_WORDS);
1098 }
1099 return;
1100 }
1101 #ifdef IDE_DRIVE_CMD
1102 if (rq->cmd == IDE_DRIVE_CMD) {
1103 byte *args = rq->buffer;
1104 if (args) {
1105 printk("%s: DRIVE_CMD cmd=0x%02x sc=0x%02x fr=0x%02x\n",
1106 drive->name, args[0], args[1], args[2]);
1107 OUT_BYTE(args[2],IDE_FEATURE_REG);
1108 ide_cmd(drive, args[0], args[1], &drive_cmd_intr);
1109 return;
1110 } else {
1111 #ifdef DEBUG
1112 printk("%s: DRIVE_CMD (null)\n", drive->name);
1113 #endif
1114 end_drive_cmd(drive, GET_STAT(), GET_ERR());
1115 return;
1116 }
1117 }
1118 #endif
1119 printk("%s: bad command: %d\n", drive->name, rq->cmd);
1120 ide_end_request(0, HWGROUP(drive));
1121 }
1122
1123 static inline void do_request (ide_hwif_t *hwif, struct request *rq)
1124 {
1125 unsigned int minor, unit;
1126 unsigned long block, blockend;
1127 ide_drive_t *drive;
1128
1129 sti();
1130 #ifdef DEBUG
1131 printk("%s: ide_do_request: current=0x%08lx\n", hwif->name, (unsigned long) rq);
1132 #endif
1133 minor = MINOR(rq->dev);
1134 unit = minor >> PARTN_BITS;
1135 if (MAJOR(rq->dev) != hwif->major || unit >= MAX_DRIVES) {
1136 printk("%s: bad device number: 0x%04x\n", hwif->name, rq->dev);
1137 goto kill_rq;
1138 }
1139 drive = &hwif->drives[unit];
1140 if (rq->bh && !rq->bh->b_lock) {
1141 printk("%s: block not locked\n", drive->name);
1142 goto kill_rq;
1143 }
1144 block = rq->sector;
1145 blockend = block + rq->nr_sectors;
1146 if ((blockend < block) || (blockend > drive->part[minor&PARTN_MASK].nr_sects)) {
1147 printk("%s: bad access: block=%ld, count=%ld\n",
1148 drive->name, block, rq->nr_sectors);
1149 goto kill_rq;
1150 }
1151 block += drive->part[minor&PARTN_MASK].start_sect + drive->sect0;
1152 #if (DISK_RECOVERY_TIME > 0)
1153 while ((read_timer() - hwif->last_time) < DISK_RECOVERY_TIME);
1154 #endif
1155 OUT_BYTE(drive->select.all,IDE_SELECT_REG);
1156 if (ide_wait_stat(drive, drive->ready_stat, BUSY_STAT|DRQ_STAT, WAIT_READY)) {
1157 printk("%s: drive not ready for command\n", drive->name);
1158 return;
1159
1160 }
1161 ((ide_hwgroup_t *)hwif->hwgroup)->drive = drive;
1162 if (!drive->special.all) {
1163 #ifdef CONFIG_BLK_DEV_IDECD
1164 switch (drive->media) {
1165 case disk:
1166 do_rw_disk (drive, rq, block);
1167 return;
1168 case cdrom:
1169 ide_do_rw_cdrom (drive, block);
1170 return;
1171 default:
1172 printk("%s: media type %d not supported\n",
1173 drive->name, drive->media);
1174 goto kill_rq;
1175 }
1176 #else
1177 do_rw_disk (drive, rq, block);
1178 return;
1179 #endif;
1180 }
1181 do_special(drive);
1182 return;
1183 kill_rq:
1184 ide_end_request(0, hwif->hwgroup);
1185 }
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202 void ide_do_request (ide_hwgroup_t *hwgroup)
1203 {
1204 cli();
1205
1206 if (hwgroup->handler != NULL) {
1207 printk("%s: EEeekk!! handler not NULL in ide_do_request()\n", hwgroup->hwif->name);
1208 return;
1209 }
1210 do {
1211 ide_hwif_t *hwif = hwgroup->hwif;
1212 struct request *rq;
1213 if ((rq = hwgroup->rq) == NULL) {
1214 hwgroup->drive = NULL;
1215 do {
1216 rq = blk_dev[hwif->major].current_request;
1217 if (rq != NULL && rq->dev != -1)
1218 goto got_rq;
1219 } while ((hwif = hwif->next) != hwgroup->hwif);
1220 return;
1221 }
1222 got_rq:
1223 blk_dev[hwif->major].current_request = rq->next;
1224 do_request(hwgroup->hwif = hwif, hwgroup->rq = rq);
1225 cli();
1226 } while (hwgroup->handler == NULL);
1227 }
1228
1229 static void do_hwgroup_request (ide_hwgroup_t *hwgroup)
1230 {
1231 if (hwgroup->handler == NULL) {
1232 ide_hwif_t *hgif = hwgroup->hwif;
1233 ide_hwif_t *hwif = hgif;
1234 do {
1235 disable_irq(hwif->irq);
1236 } while ((hwif = hwif->next) != hgif);
1237 ide_do_request (hwgroup);
1238 do {
1239 enable_irq(hwif->irq);
1240 } while ((hwif = hwif->next) != hgif);
1241 }
1242 }
1243
1244 static void do_ide0_request (void)
1245 {
1246 do_hwgroup_request (ide_hwifs[0].hwgroup);
1247 }
1248
1249 static void do_ide1_request (void)
1250 {
1251 do_hwgroup_request (ide_hwifs[1].hwgroup);
1252 }
1253
1254 static void do_ide2_request (void)
1255 {
1256 do_hwgroup_request (ide_hwifs[2].hwgroup);
1257 }
1258
1259 static void do_ide3_request (void)
1260 {
1261 do_hwgroup_request (ide_hwifs[3].hwgroup);
1262 }
1263
1264 static void timer_expiry (unsigned long data)
1265 {
1266 ide_hwgroup_t *hwgroup = (ide_hwgroup_t *) data;
1267 ide_drive_t *drive = hwgroup->drive;
1268 unsigned long flags;
1269
1270 save_flags(flags);
1271 cli();
1272
1273 if (hwgroup->hwif->reset_timeout != 0) {
1274 if (!reset_handler(hwgroup))
1275 do_hwgroup_request (hwgroup);
1276 } else if (hwgroup->handler == NULL) {
1277 sti();
1278 printk("%s: marginal timeout\n", drive->name);
1279 } else {
1280 hwgroup->handler = NULL;
1281 if (!ide_error(drive, "irq timeout", GET_STAT()))
1282 do_hwgroup_request (hwgroup);
1283 }
1284 restore_flags(flags);
1285 }
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297 static void unexpected_intr (int irq, ide_hwgroup_t *hwgroup)
1298 {
1299 byte stat;
1300 unsigned int unit;
1301 ide_hwif_t *hwif = hwgroup->hwif;
1302 unsigned long flags;
1303
1304 save_flags(flags);
1305 cli();
1306
1307
1308
1309
1310 if (hwif->reset_timeout != 0) {
1311 if (!reset_handler(hwgroup))
1312 do_hwgroup_request (hwgroup);
1313 restore_flags(flags);
1314 return;
1315 }
1316
1317
1318
1319
1320 do {
1321 if (hwif->irq == irq) {
1322 for (unit = 0; unit < MAX_DRIVES; ++unit) {
1323 ide_drive_t *drive = &hwif->drives[unit];
1324 if (!drive->present)
1325 continue;
1326 if (!OK_STAT(stat=GET_STAT(), drive->ready_stat, BAD_STAT))
1327 (void) ide_dump_status(drive, "unexpected_intr", stat);
1328 if ((stat & DRQ_STAT))
1329 try_to_flush_leftover_data(drive);
1330 }
1331 }
1332 } while ((hwif = hwif->next) != hwgroup->hwif);
1333 restore_flags(flags);
1334 }
1335
1336
1337
1338
1339 static void ide_intr (int irq, struct pt_regs *regs)
1340 {
1341 ide_hwgroup_t *hwgroup = irq_to_hwgroup[irq];
1342 ide_handler_t *handler;
1343 if (irq != hwgroup->hwif->irq) {
1344 #ifdef DEBUG
1345 printk("ide_intr: expected ira %d, got irq %d instead\n",
1346 hwgroup->hwif->irq, irq);
1347 #endif
1348 unexpected_intr(irq, hwgroup);
1349 } else if ((handler = hwgroup->handler) != NULL) {
1350 ide_drive_t *drive = hwgroup->drive;
1351 hwgroup->handler = NULL;
1352 del_timer(&(hwgroup->timer));
1353 if (drive->unmask)
1354 sti();
1355 handler(drive);
1356 } else {
1357 sti();
1358 unexpected_intr(irq, hwgroup);
1359 }
1360 cli();
1361 }
1362
1363 static ide_drive_t *get_info_ptr (int i_rdev)
1364 {
1365 int major = MAJOR(i_rdev);
1366 unsigned int h;
1367
1368 for (h = 0; h < MAX_HWIFS; ++h) {
1369 ide_hwif_t *hwif = &ide_hwifs[h];
1370 if (hwif->present && major == hwif->major) {
1371 unsigned unit = DEVICE_NR(i_rdev);
1372 if (unit < MAX_DRIVES) {
1373 ide_drive_t *drive = &hwif->drives[unit];
1374 if (drive->present)
1375 return drive;
1376 }
1377 break;
1378 }
1379 }
1380 return NULL;
1381 }
1382
1383 #ifdef IDE_DRIVE_CMD
1384 static int write_fs_long (unsigned long useraddr, long value)
1385 {
1386 int err;
1387
1388 if (NULL == (long *)useraddr)
1389 return -EINVAL;
1390 if ((err = verify_area(VERIFY_WRITE, (long *)useraddr, sizeof(long))))
1391 return err;
1392 put_user((unsigned)value, (long *) useraddr);
1393 return 0;
1394 }
1395
1396
1397
1398
1399
1400
1401
1402 static int do_drive_cmd(int rdev, char *args)
1403 {
1404 unsigned long flags;
1405 unsigned int major = MAJOR(rdev);
1406 struct request rq, *cur_rq;
1407 struct blk_dev_struct *bdev;
1408 struct semaphore sem = MUTEX_LOCKED;
1409
1410
1411 rq.buffer = args;
1412 rq.cmd = IDE_DRIVE_CMD;
1413 rq.errors = 0;
1414 rq.sector = 0;
1415 rq.nr_sectors = 0;
1416 rq.current_nr_sectors = 0;
1417 rq.sem = &sem;
1418 rq.bh = NULL;
1419 rq.bhtail = NULL;
1420 rq.next = NULL;
1421 rq.dev = rdev;
1422 bdev = &blk_dev[major];
1423
1424 save_flags(flags);
1425 cli();
1426 cur_rq = bdev->current_request;
1427 if (cur_rq == NULL) {
1428 bdev->current_request = &rq;
1429 bdev->request_fn();
1430 } else {
1431 while (cur_rq->next != NULL)
1432 cur_rq = cur_rq->next;
1433 cur_rq->next = &rq;
1434 }
1435
1436 down(&sem);
1437 restore_flags(flags);
1438 return rq.errors ? -EIO : 0;
1439 }
1440 #endif
1441
1442 static int ide_open(struct inode * inode, struct file * filp)
1443 {
1444 ide_drive_t *drive;
1445 unsigned long flags;
1446
1447 if ((drive = get_info_ptr(inode->i_rdev)) == NULL)
1448 return -ENODEV;
1449 save_flags(flags);
1450 cli();
1451 while (drive->busy)
1452 sleep_on(&drive->wqueue);
1453 drive->usage++;
1454 restore_flags(flags);
1455 #ifdef CONFIG_BLK_DEV_IDECD
1456 if (drive->media == cdrom)
1457 return ide_cdrom_open (inode, filp, drive);
1458 #endif
1459 if (drive->removeable) {
1460 check_disk_change(inode->i_rdev);
1461 #ifdef IDE_DRIVE_CMD
1462 {
1463 byte door_lock[] = {WIN_DOORLOCK,0,0,0};
1464 do_drive_cmd(inode->i_rdev, door_lock);
1465 }
1466 #endif
1467 }
1468 return 0;
1469 }
1470
1471
1472
1473
1474
1475 static void ide_release(struct inode * inode, struct file * file)
1476 {
1477 ide_drive_t *drive;
1478
1479 if ((drive = get_info_ptr(inode->i_rdev)) != NULL) {
1480 sync_dev(inode->i_rdev);
1481 drive->usage--;
1482 #ifdef CONFIG_BLK_DEV_IDECD
1483 if (drive->media == cdrom)
1484 ide_cdrom_release (inode, file, drive);
1485 else
1486 #endif
1487 if (drive->removeable) {
1488 invalidate_buffers(inode->i_rdev);
1489 #ifdef IDE_DRIVE_CMD
1490 {
1491 byte door_unlock[] = {WIN_DOORUNLOCK,0,0,0};
1492 do_drive_cmd(inode->i_rdev, door_unlock);
1493 }
1494 #endif
1495 }
1496 }
1497 }
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507 static int revalidate_disk(dev_t i_rdev)
1508 {
1509 ide_drive_t *drive;
1510 unsigned int p, major, minor;
1511 long flags;
1512
1513 if ((drive = get_info_ptr(i_rdev)) == NULL)
1514 return -ENODEV;
1515
1516 major = MAJOR(i_rdev);
1517 minor = drive->select.b.unit << PARTN_BITS;
1518 save_flags(flags);
1519 cli();
1520 if (drive->busy || (drive->usage > 1)) {
1521 restore_flags(flags);
1522 return -EBUSY;
1523 };
1524 drive->busy = 1;
1525 restore_flags(flags);
1526
1527 for (p = 0; p < (1<<PARTN_BITS); ++p) {
1528 sync_dev (major | (minor + p));
1529 invalidate_inodes (major | (minor + p));
1530 invalidate_buffers (major | (minor + p));
1531 drive->part[p].start_sect = 0;
1532 drive->part[p].nr_sects = 0;
1533 };
1534
1535 drive->part[0].nr_sects = current_capacity(drive);
1536 resetup_one_dev(HWIF(drive)->gd, drive->select.b.unit);
1537
1538 drive->busy = 0;
1539 wake_up(&drive->wqueue);
1540 return 0;
1541 }
1542
1543 static int ide_ioctl (struct inode *inode, struct file *file,
1544 unsigned int cmd, unsigned long arg)
1545 {
1546 struct hd_geometry *loc = (struct hd_geometry *) arg;
1547 int err;
1548 ide_drive_t *drive;
1549 unsigned long flags;
1550
1551 if (!inode || !inode->i_rdev)
1552 return -EINVAL;
1553 if ((drive = get_info_ptr(inode->i_rdev)) == NULL)
1554 return -ENODEV;
1555 switch (cmd) {
1556 case HDIO_GETGEO:
1557 if (!loc || drive->media != disk) return -EINVAL;
1558 err = verify_area(VERIFY_WRITE, loc, sizeof(*loc));
1559 if (err) return err;
1560 put_user(drive->bios_head, (byte *) &loc->heads);
1561 put_user(drive->bios_sect, (byte *) &loc->sectors);
1562 put_user(drive->bios_cyl, (unsigned short *) &loc->cylinders);
1563 put_user((unsigned)drive->part[inode->i_rdev&PARTN_MASK].start_sect,
1564 (unsigned long *) &loc->start);
1565 return 0;
1566
1567 case BLKFLSBUF:
1568 if(!suser()) return -EACCES;
1569 fsync_dev(inode->i_rdev);
1570 invalidate_buffers(inode->i_rdev);
1571 return 0;
1572
1573 case BLKRASET:
1574 if(!suser()) return -EACCES;
1575 if(arg > 0xff) return -EINVAL;
1576 read_ahead[MAJOR(inode->i_rdev)] = arg;
1577 return 0;
1578
1579 case BLKRAGET:
1580 return write_fs_long(arg, read_ahead[MAJOR(inode->i_rdev)]);
1581
1582 case BLKGETSIZE:
1583 return write_fs_long(arg, drive->part[inode->i_rdev&PARTN_MASK].nr_sects);
1584 case BLKRRPART:
1585 return revalidate_disk(inode->i_rdev);
1586
1587 case HDIO_GET_KEEPSETTINGS:
1588 return write_fs_long(arg, drive->keep_settings);
1589
1590 case HDIO_GET_UNMASKINTR:
1591 return write_fs_long(arg, drive->unmask);
1592
1593 case HDIO_GET_CHIPSET:
1594 return write_fs_long(arg, drive->chipset);
1595
1596 case HDIO_GET_MULTCOUNT:
1597 return write_fs_long(arg, drive->mult_count);
1598
1599 case HDIO_GET_IDENTITY:
1600 if (!arg || (inode->i_rdev & PARTN_MASK))
1601 return -EINVAL;
1602 if (drive->id == NULL)
1603 return -ENOMSG;
1604 err = verify_area(VERIFY_WRITE, (char *)arg, sizeof(*drive->id));
1605 if (err) return err;
1606 memcpy_tofs((char *)arg, (char *)drive->id, sizeof(*drive->id));
1607 return 0;
1608
1609 case HDIO_GET_NOWERR:
1610 return write_fs_long(arg, drive->bad_wstat == BAD_R_STAT);
1611
1612 case HDIO_SET_KEEPSETTINGS:
1613 case HDIO_SET_UNMASKINTR:
1614 case HDIO_SET_NOWERR:
1615 if (arg > 1)
1616 return -EINVAL;
1617 case HDIO_SET_CHIPSET:
1618 if (!suser())
1619 return -EACCES;
1620 if ((inode->i_rdev & PARTN_MASK))
1621 return -EINVAL;
1622 save_flags(flags);
1623 cli();
1624 switch (cmd) {
1625 case HDIO_SET_KEEPSETTINGS:
1626 drive->keep_settings = arg;
1627 break;
1628 case HDIO_SET_UNMASKINTR:
1629 drive->unmask = arg;
1630 break;
1631 case HDIO_SET_NOWERR:
1632 drive->bad_wstat = arg ? BAD_R_STAT : BAD_W_STAT;
1633 break;
1634 case HDIO_SET_CHIPSET:
1635 drive->chipset = arg;
1636 drive->vlb_32bit = (arg & 1);
1637 drive->vlb_sync = (arg & 2) >> 1;
1638 #ifndef VLB_SYNC
1639 if (drive->vlb_sync)
1640 printk("%s: VLB_SYNC not supported by this kernel\n", drive->name);
1641 #endif
1642 break;
1643 }
1644 restore_flags(flags);
1645 return 0;
1646
1647 case HDIO_SET_MULTCOUNT:
1648 if (!suser()) return -EACCES;
1649 if (inode->i_rdev & PARTN_MASK)
1650 return -EINVAL;
1651 if ((drive->id != NULL) && (arg > drive->id->max_multsect))
1652 return -EINVAL;
1653 save_flags(flags);
1654 cli();
1655 if (drive->special.b.set_multmode) {
1656 restore_flags(flags);
1657 return -EBUSY;
1658 }
1659 drive->mult_req = arg;
1660 drive->special.b.set_multmode = 1;
1661 restore_flags(flags);
1662 #ifndef IDE_DRIVE_CMD
1663 return 0;
1664 #else
1665 do_drive_cmd (inode->i_rdev, NULL);
1666 return (drive->mult_count == arg) ? 0 : -EIO;
1667
1668 case HDIO_DRIVE_CMD:
1669 {
1670 unsigned long args;
1671
1672 if (NULL == (long *) arg)
1673 err = do_drive_cmd(inode->i_rdev,NULL);
1674 else {
1675 if (!(err = verify_area(VERIFY_READ,(long *)arg,sizeof(long))))
1676 {
1677 args = get_user((long *)arg);
1678 if (!(err = verify_area(VERIFY_WRITE,(long *)arg,sizeof(long)))) {
1679 err = do_drive_cmd(inode->i_rdev,(char *)&args);
1680 put_user(args,(long *)arg);
1681 }
1682 }
1683 }
1684 return err;
1685 }
1686 #endif
1687
1688 RO_IOCTLS(inode->i_rdev, arg);
1689
1690 default:
1691 #ifdef CONFIG_BLK_DEV_IDECD
1692 if (drive->media == cdrom)
1693 return ide_cdrom_ioctl(drive, inode, file, cmd, arg);
1694 #endif
1695 return -EPERM;
1696 }
1697 }
1698
1699 static int ide_check_media_change (dev_t i_rdev)
1700 {
1701 ide_drive_t *drive;
1702
1703 if ((drive = get_info_ptr(i_rdev)) == NULL)
1704 return -ENODEV;
1705 #ifdef CONFIG_BLK_DEV_IDECD
1706 if (drive->media == cdrom)
1707 return ide_cdrom_check_media_change (drive);
1708 #endif
1709 if (drive->removeable)
1710 return 1;
1711 return 0;
1712 }
1713
1714 static void fixstring (byte *s, const int bytecount, const int byteswap)
1715 {
1716 byte *p = s, *end = &s[bytecount & ~1];
1717
1718 if (byteswap) {
1719
1720 for (p = end ; p != s;) {
1721 unsigned short *pp = (unsigned short *) (p -= 2);
1722 *pp = ntohs(*pp);
1723 }
1724 }
1725
1726
1727 while (s != end && *s == ' ')
1728 ++s;
1729
1730
1731 while (s != end && *s) {
1732 if (*s++ != ' ' || (s != end && *s && *s != ' '))
1733 *p++ = *(s-1);
1734 }
1735
1736
1737 while (p != end)
1738 *p++ = '\0';
1739 }
1740
1741 static void do_identify (ide_drive_t *drive, byte cmd)
1742 {
1743 int bswap;
1744 struct hd_driveid *id;
1745 unsigned long capacity, check;
1746
1747 id = drive->id = ide_alloc(SECTOR_WORDS*4);
1748 ide_input_data(drive, id, SECTOR_WORDS);
1749 sti();
1750
1751
1752
1753
1754 if ((id->model[0] == 'P' && id->model[1] == 'M')
1755 || (id->model[0] == 'S' && id->model[1] == 'K')) {
1756 printk("%s: EATA SCSI HBA %.10s\n", drive->name, id->model);
1757 drive->present = 0;
1758 return;
1759 }
1760
1761
1762
1763
1764
1765 bswap = 1;
1766 if (cmd == WIN_PIDENTIFY) {
1767 if ((id->model[0] == 'N' && id->model[1] == 'E')
1768 || (id->model[0] == 'F' && id->model[1] == 'X')
1769 || (id->model[0] == 'P' && id->model[1] == 'i'))
1770 bswap = 0;
1771 }
1772 fixstring (id->model, sizeof(id->model), bswap);
1773 fixstring (id->fw_rev, sizeof(id->fw_rev), bswap);
1774 fixstring (id->serial_no, sizeof(id->serial_no), bswap);
1775
1776
1777
1778
1779 if (cmd == WIN_PIDENTIFY) {
1780 #ifdef CONFIG_BLK_DEV_IDECD
1781 byte type = (id->config >> 8) & 0x0f;
1782 #endif
1783 printk("%s: %s, ATAPI, ", drive->name, id->model);
1784 drive->media = cdrom;
1785 #ifdef CONFIG_BLK_DEV_IDECD
1786 if (type == 0 || type == 5)
1787 printk("CDROM drive\n");
1788 else
1789 printk("UNKNOWN device\n");
1790 drive->present = 1;
1791 drive->removeable = 1;
1792 #else
1793 printk("not supported by this kernel\n");
1794 #endif
1795 return;
1796 }
1797
1798
1799 if (id->config & (1<<7)) {
1800 if (id->model[0] != 'W' || id->model[1] != 'D')
1801 drive->removeable = 1;
1802 }
1803
1804 drive->media = disk;
1805
1806 if (!drive->present) {
1807 drive->present = 1;
1808 drive->cyl = drive->bios_cyl = id->cyls;
1809 drive->head = drive->bios_head = id->heads;
1810 drive->sect = drive->bios_sect = id->sectors;
1811 }
1812
1813 if ((id->field_valid & 1) && id->cur_cyls && id->cur_heads
1814 && (id->cur_heads <= 16) && id->cur_sectors)
1815 {
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826 drive->cyl = id->cur_cyls;
1827 drive->head = id->cur_heads;
1828 drive->sect = id->cur_sectors;
1829
1830
1831 capacity = drive->cyl * drive->head * drive->sect;
1832 check = (id->cur_capacity0 << 16) | id->cur_capacity1;
1833 if (check == capacity) {
1834
1835 id->cur_capacity0 = (capacity >> 0) & 0xffff;
1836 id->cur_capacity1 = (capacity >> 16) & 0xffff;
1837 }
1838 }
1839
1840 if ((!drive->head || drive->head > 16) && id->heads && id->heads <= 16) {
1841 drive->cyl = id->cyls;
1842 drive->head = id->heads;
1843 drive->sect = id->sectors;
1844 }
1845
1846 if (drive->sect == drive->bios_sect && drive->head == drive->bios_head) {
1847 if (drive->cyl > drive->bios_cyl)
1848 drive->bios_cyl = drive->cyl;
1849 }
1850
1851 (void) current_capacity (drive);
1852
1853 printk ("%s: %.40s, %ldMB w/%dKB Cache, %sCHS=%d/%d/%d",
1854 drive->name, id->model, current_capacity(drive)/2048L, id->buf_size/2,
1855 drive->select.b.lba ? "LBA, " : "",
1856 drive->bios_cyl, drive->bios_head, drive->bios_sect);
1857
1858 drive->mult_count = 0;
1859 if (id->max_multsect) {
1860 drive->mult_req = INITIAL_MULT_COUNT;
1861 if (drive->mult_req > id->max_multsect)
1862 drive->mult_req = id->max_multsect;
1863 if (drive->mult_req || ((id->multsect_valid & 1) && id->multsect))
1864 drive->special.b.set_multmode = 1;
1865 printk(", MaxMult=%d", id->max_multsect);
1866 }
1867 printk("\n");
1868 }
1869
1870
1871
1872
1873
1874 static void delay_10ms (void)
1875 {
1876 unsigned long timer = jiffies + (HZ + 99)/100 + 1;
1877 while (timer > jiffies);
1878 }
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890 static int try_to_identify (ide_drive_t *drive, byte cmd)
1891 {
1892 int hd_status, rc;
1893 unsigned long timeout;
1894 int irqs = 0;
1895
1896 if (!HWIF(drive)->irq) {
1897 probe_irq_off(probe_irq_on());
1898 irqs = probe_irq_on();
1899 OUT_BYTE(drive->ctl,IDE_CONTROL_REG);
1900 }
1901
1902 delay_10ms();
1903 if ((IN_BYTE(IDE_ALTSTATUS_REG) ^ IN_BYTE(IDE_STATUS_REG)) & ~INDEX_STAT) {
1904 printk("%s: probing with STATUS instead of ALTSTATUS\n", drive->name);
1905 hd_status = IDE_STATUS_REG;
1906 } else
1907 hd_status = IDE_ALTSTATUS_REG;
1908
1909 OUT_BYTE(cmd,IDE_COMMAND_REG);
1910 timeout = ((cmd == WIN_IDENTIFY) ? WAIT_WORSTCASE : WAIT_PIDENTIFY) / 2;
1911 timeout += jiffies;
1912 do {
1913 if (jiffies > timeout) {
1914 if (!HWIF(drive)->irq)
1915 (void) probe_irq_off(irqs);
1916 return 1;
1917 }
1918 delay_10ms();
1919 } while (IN_BYTE(hd_status) & BUSY_STAT);
1920
1921 delay_10ms();
1922 if (OK_STAT(GET_STAT(),DRQ_STAT,BAD_R_STAT)) {
1923 cli();
1924 do_identify(drive, cmd);
1925 rc = 0;
1926 } else
1927 rc = 2;
1928 if (!HWIF(drive)->irq) {
1929 irqs = probe_irq_off(irqs);
1930 if (irqs > 0)
1931 HWIF(drive)->irq = irqs;
1932 else
1933 printk("%s: IRQ probe failed (%d)\n", drive->name, irqs);
1934 }
1935 return rc;
1936 }
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954 static int do_probe (ide_drive_t *drive, byte cmd)
1955 {
1956 int rc;
1957
1958 #ifdef CONFIG_BLK_DEV_IDECD
1959 if (drive->present) {
1960 if ((drive->media == disk) ^ (cmd == WIN_IDENTIFY))
1961 return 4;
1962 }
1963 #endif
1964 #ifdef DEBUG
1965 printk("probing for %s: present=%d, type=%s, probetype=%s\n",
1966 drive->name, drive->present, drive->media ? "cdrom":"disk",
1967 (cmd == WIN_IDENTIFY) ? "ATA" : "ATAPI");
1968 #endif
1969 OUT_BYTE(drive->select.all,IDE_SELECT_REG);
1970 delay_10ms();
1971 if (IN_BYTE(IDE_SELECT_REG) != drive->select.all && !drive->present) {
1972 OUT_BYTE(0xa0,IDE_SELECT_REG);
1973 return 3;
1974 }
1975
1976 if (OK_STAT(GET_STAT(),READY_STAT,BUSY_STAT)
1977 || drive->present || cmd == WIN_PIDENTIFY)
1978 {
1979 if ((rc = try_to_identify(drive,cmd)))
1980 rc = try_to_identify(drive,cmd);
1981 if (rc == 1)
1982 printk("%s: no response (status = 0x%02x)\n", drive->name, GET_STAT());
1983 (void) GET_STAT();
1984 } else {
1985 rc = 3;
1986 }
1987 if (drive->select.b.unit != 0) {
1988 OUT_BYTE(0xa0,IDE_SELECT_REG);
1989 delay_10ms();
1990 (void) GET_STAT();
1991 }
1992 return rc;
1993 }
1994
1995
1996
1997
1998
1999
2000
2001 static byte probe_for_drive (ide_drive_t *drive)
2002 {
2003 if (drive->noprobe)
2004 return drive->present;
2005 if (do_probe(drive, WIN_IDENTIFY) >= 2) {
2006 #ifdef CONFIG_BLK_DEV_IDECD
2007 (void) do_probe(drive, WIN_PIDENTIFY);
2008 #endif
2009 }
2010 if (!drive->present)
2011 return 0;
2012 if (drive->id == NULL) {
2013 if (drive->media == disk) {
2014 printk ("%s: non-IDE drive, CHS=%d/%d/%d\n",
2015 drive->name, drive->cyl, drive->head, drive->sect);
2016 }
2017 #ifdef CONFIG_BLK_DEV_IDECD
2018 else if (drive->media == cdrom) {
2019 printk("%s: ATAPI cdrom (?)\n", drive->name);
2020 }
2021 #endif
2022 else {
2023 drive->present = 0;
2024 return 1;
2025 }
2026 }
2027 if (drive->media == disk && !drive->select.b.lba) {
2028 if (!drive->head || drive->head > 16) {
2029 printk("%s: INVALID GEOMETRY: %d PHYSICAL HEADS?\n",
2030 drive->name, drive->head);
2031 drive->present = 0;
2032 }
2033 }
2034 return 1;
2035 }
2036
2037
2038
2039
2040
2041 static void probe_for_drives (ide_hwif_t *hwif)
2042 {
2043 unsigned int unit;
2044
2045 if (check_region(hwif->io_base,8) || check_region(hwif->ctl_port,1)) {
2046 int msgout = 0;
2047 for (unit = 0; unit < MAX_DRIVES; ++unit) {
2048 ide_drive_t *drive = &hwif->drives[unit];
2049 if (drive->present) {
2050 drive->present = 0;
2051 printk("%s: ERROR, PORTS ALREADY IN USE\n", drive->name);
2052 msgout = 1;
2053 }
2054 }
2055 if (!msgout)
2056 printk("%s: ports already in use, skipping probe\n", hwif->name);
2057 } else {
2058 unsigned long flags;
2059 save_flags(flags);
2060
2061 #if (MAX_DRIVES > 2)
2062 printk("%s: probing for first 2 of %d possible drives\n", hwif->name, MAX_DRIVES);
2063 #endif
2064 sti();
2065
2066
2067
2068
2069 for (unit = 0; unit < 2; ++unit)
2070 (void) probe_for_drive(&hwif->drives[unit]);
2071 for (unit = 0; unit < MAX_DRIVES; ++unit) {
2072 ide_drive_t *drive = &hwif->drives[unit];
2073 if (drive->present) {
2074 hwif->present = 1;
2075 request_region(hwif->io_base, 8, hwif->name);
2076 request_region(hwif->ctl_port, 1, hwif->name);
2077 #ifdef CONFIG_BLK_DEV_IDECD
2078 if (drive->media == cdrom)
2079 ide_cdrom_setup(drive);
2080 #endif
2081 break;
2082 }
2083 }
2084 restore_flags(flags);
2085 }
2086 }
2087
2088
2089
2090
2091
2092 static int stridx (const char *s, char c)
2093 {
2094 char *i = strchr(s, c);
2095 return (i && c) ? i - s : -1;
2096 }
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110 static int match_parm (char *s, const char *keywords[], int vals[], int max_vals)
2111 {
2112 static const char *decimal = "0123456789";
2113 static const char *hex = "0123456789abcdef";
2114 int i, n;
2115
2116 if (*s++ == '=') {
2117
2118
2119
2120
2121 for (i = 0; *keywords != NULL; ++i) {
2122 if (!strcmp(s, *keywords++))
2123 return -(i+1);
2124 }
2125
2126
2127
2128
2129
2130
2131 for (n = 0; (i = stridx(decimal, *s)) >= 0;) {
2132 vals[n] = i;
2133 while ((i = stridx(decimal, *++s)) >= 0)
2134 vals[n] = (vals[n] * 10) + i;
2135 if (*s == 'x' && !vals[n]) {
2136 while ((i = stridx(hex, *++s)) >= 0)
2137 vals[n] = (vals[n] * 0x10) + i;
2138 }
2139 if (++n == max_vals)
2140 break;
2141 if (*s == ',')
2142 ++s;
2143 }
2144 if (!*s)
2145 return n;
2146 }
2147 return 0;
2148 }
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175 void ide_setup (char *s)
2176 {
2177 int vals[3];
2178 ide_drive_t *drive;
2179 unsigned int unit, hwif;
2180 const char max_drive = 'a' + ((MAX_HWIFS * MAX_DRIVES) - 1);
2181 const char max_hwif = '0' + (MAX_HWIFS - 1);
2182
2183 printk("ide_setup: %s", s);
2184 init_ide_data ();
2185 if (s[0] == 'h' && s[1] == 'd' && s[2] >= 'a' && s[2] <= max_drive) {
2186 const char *hd_words[] = {"noprobe", "nowerr", "cdrom", "serialize", NULL};
2187 unit = s[2] - 'a';
2188 hwif = unit / MAX_DRIVES;
2189 unit = unit % MAX_DRIVES;
2190 drive = &ide_hwifs[hwif].drives[unit];
2191 switch (match_parm(&s[3], hd_words, vals, 3)) {
2192 case -1:
2193 drive->noprobe = 1;
2194 goto done;
2195 case -2:
2196 drive->bad_wstat = BAD_R_STAT;
2197 ide_hwifs[hwif].noprobe = 0;
2198 goto done;
2199 case -3:
2200 drive->present = 1;
2201 drive->media = cdrom;
2202 ide_hwifs[hwif].noprobe = 0;
2203 goto done;
2204 case -4:
2205 printk(" -- USE ""ide%c=serialize"" INSTEAD", '0'+hwif);
2206 goto do_serialize;
2207 case 3:
2208 drive->media = disk;
2209 drive->cyl = drive->bios_cyl = vals[0];
2210 drive->head = drive->bios_head = vals[1];
2211 drive->sect = drive->bios_sect = vals[2];
2212 drive->present = 1;
2213 ide_hwifs[hwif].noprobe = 0;
2214 goto done;
2215 default:
2216 goto bad_option;
2217 }
2218 }
2219 if (s[0] == 'i' && s[1] == 'd' && s[2] == 'e' && s[3] >= '0' && s[3] <= max_hwif) {
2220 const char *ide_words[] = {"dtc2278", "serialize", "noprobe", NULL};
2221 hwif = s[3] - '0';
2222 switch (match_parm(&s[4], ide_words, vals, 3)) {
2223 #if SUPPORT_DTC2278
2224 case -1:
2225 if (hwif > 1) goto bad_hwif;
2226 probe_dtc2278 = 1;
2227 ide_hwifs[hwif].noprobe = 0;
2228 goto done;
2229 #endif
2230 case -2:
2231 do_serialize:
2232 if (hwif > 1) goto bad_hwif;
2233 single_threaded = 1;
2234 ide_hwifs[hwif].noprobe = 0;
2235 goto done;
2236 case -3:
2237 ide_hwifs[hwif].noprobe = 1;
2238 goto done;
2239 case 1:
2240 vals[1] = vals[0] + 0x206;
2241 case 2:
2242 vals[2] = 0;
2243 case 3:
2244 ide_hwifs[hwif].io_base = vals[0];
2245 ide_hwifs[hwif].ctl_port = vals[1];
2246 ide_hwifs[hwif].irq = vals[2];
2247 ide_hwifs[hwif].noprobe = 0;
2248 goto done;
2249 }
2250 }
2251 bad_option:
2252 printk(" -- BAD OPTION\n");
2253 return;
2254 bad_hwif:
2255 printk("-- NOT SUPPORTED ON ide%d", hwif);
2256 done:
2257 printk("\n");
2258 }
2259
2260
2261
2262
2263
2264
2265 int ide_xlate_1024 (dev_t i_rdev, int need_offset, const char *msg)
2266 {
2267 ide_drive_t *drive;
2268 static const byte head_vals[] = {4, 8, 16, 32, 64, 128, 255, 0};
2269 const byte *heads = head_vals;
2270 unsigned long tracks;
2271
2272 if ((drive = get_info_ptr(i_rdev)) == NULL || drive->id == NULL)
2273 return 0;
2274
2275 drive->cyl = drive->bios_cyl = drive->id->cyls;
2276 drive->head = drive->bios_head = drive->id->heads;
2277 drive->sect = drive->bios_sect = drive->id->sectors;
2278 drive->special.b.set_geometry = 1;
2279
2280 tracks = drive->bios_cyl * drive->bios_head * drive->bios_sect / 63;
2281 drive->bios_sect = 63;
2282 while (drive->bios_cyl >= 1024) {
2283 drive->bios_head = *heads;
2284 drive->bios_cyl = tracks / drive->bios_head;
2285 if (0 == *++heads)
2286 break;
2287 }
2288 if (need_offset) {
2289 drive->sect0 = 63;
2290 drive->bios_cyl = (tracks - 1) / drive->bios_head;
2291 }
2292 drive->part[0].nr_sects = current_capacity(drive);
2293 printk("%s [+%d,%d/%d/%d]", msg, drive->sect0, drive->bios_cyl, drive->bios_head, drive->bios_sect);
2294 return 1;
2295 }
2296
2297
2298
2299
2300
2301
2302
2303
2304
2305
2306
2307
2308
2309 static void probe_cmos_for_drives (ide_hwif_t *hwif)
2310 {
2311 #ifdef __i386__
2312 extern struct drive_info_struct drive_info;
2313 byte cmos_disks, *BIOS = (byte *) &drive_info;
2314 int unit;
2315
2316 outb_p(0x12,0x70);
2317 cmos_disks = inb_p(0x71);
2318
2319 for (unit = 0; unit < MAX_DRIVES; ++unit) {
2320 ide_drive_t *drive = &hwif->drives[unit];
2321 if ((cmos_disks & (0xf0 >> (unit*4))) && !drive->present) {
2322 drive->cyl = drive->bios_cyl = *(unsigned short *)BIOS;
2323 drive->head = drive->bios_head = * (BIOS+2);
2324 drive->sect = drive->bios_sect = * (BIOS+14);
2325 drive->wpcom = (*(unsigned short *)(BIOS+5))>>2;
2326 drive->ctl = *(BIOS+8);
2327 drive->wpcom = 0;
2328 drive->media = disk;
2329 drive->present = 1;
2330 }
2331 BIOS += 16;
2332 }
2333 #endif
2334 }
2335
2336
2337
2338
2339
2340
2341
2342
2343
2344
2345 static int init_irq (ide_hwif_t *hwif)
2346 {
2347 unsigned long flags;
2348 ide_hwgroup_t *hwgroup;
2349
2350
2351
2352
2353 save_flags(flags);
2354 cli();
2355 if (request_irq(hwif->irq, ide_intr, SA_INTERRUPT, hwif->name)) {
2356 restore_flags(flags);
2357 printk(" -- FAILED!");
2358 return 1;
2359 }
2360
2361
2362
2363
2364 if ((hwgroup = irq_to_hwgroup[hwif->irq]) == NULL) {
2365 hwgroup = ide_alloc(sizeof(ide_hwgroup_t));
2366 irq_to_hwgroup[hwif->irq] = hwgroup;
2367 hwgroup->hwif = hwif->next = hwif;
2368 hwgroup->rq = NULL;
2369 hwgroup->handler = NULL;
2370 hwgroup->drive = NULL;
2371 init_timer(&hwgroup->timer);
2372 hwgroup->timer.function = &timer_expiry;
2373 hwgroup->timer.data = (unsigned long) hwgroup;
2374 } else {
2375 hwif->next = hwgroup->hwif->next;
2376 hwgroup->hwif->next = hwif;
2377 }
2378 hwif->hwgroup = hwgroup;
2379
2380 restore_flags(flags);
2381
2382 printk("%s at 0x%03x-0x%03x,0x%03x on irq %d", hwif->name,
2383 hwif->io_base, hwif->io_base + 7, hwif->ctl_port, hwif->irq);
2384 if (hwgroup->hwif != hwif) {
2385 char *name = hwgroup->hwif->name;
2386 if (hwgroup->hwif->irq == hwif->irq)
2387 printk(" (shared with %s)", name);
2388 else
2389 printk(" (serialized with %s)", name);
2390 }
2391 printk("\n");
2392 return 0;
2393 }
2394
2395 static struct file_operations ide_fops = {
2396 NULL,
2397 block_read,
2398 block_write,
2399 NULL,
2400 NULL,
2401 ide_ioctl,
2402 NULL,
2403 ide_open,
2404 ide_release,
2405 block_fsync
2406 ,NULL,
2407 ide_check_media_change,
2408 revalidate_disk
2409 };
2410
2411
2412 #if SUPPORT_DTC2278
2413
2414
2415
2416
2417
2418
2419
2420
2421
2422
2423
2424 static void sub22 (char b, char c)
2425 {
2426 int i;
2427
2428 for(i = 0; i < 3; ++i) {
2429 inb(0x3f6);
2430 outb_p(b,0xb0);
2431 inb(0x3f6);
2432 outb_p(c,0xb4);
2433 inb(0x3f6);
2434 if(inb(0xb4) == c) {
2435 outb_p(7,0xb0);
2436 inb(0x3f6);
2437 return;
2438 }
2439 }
2440 }
2441
2442 static void try_to_init_dtc2278 (void)
2443 {
2444
2445 cli();
2446 sub22(1,0xc3);
2447 sub22(0,0xa0);
2448 sti();
2449
2450
2451
2452 outb_p(4,0xb0);
2453 inb(0x3f6);
2454 outb_p(0x20,0xb4);
2455 inb(0x3f6);
2456 }
2457 #endif
2458
2459
2460
2461
2462 unsigned long ide_init (unsigned long mem_start, unsigned long mem_end)
2463 {
2464 int h;
2465
2466 init_mem_start = (mem_start + 3uL) & ~3uL;
2467 init_ide_data ();
2468
2469
2470
2471 #if SUPPORT_DTC2278
2472 if (probe_dtc2278)
2473 try_to_init_dtc2278();
2474 #endif
2475 for (h = 0; h < MAX_HWIFS; ++h) {
2476 ide_hwif_t *hwif = &ide_hwifs[h];
2477 if (!hwif->noprobe) {
2478 if (hwif->io_base == HD_DATA)
2479 probe_cmos_for_drives (hwif);
2480 probe_for_drives (hwif);
2481 }
2482 if (hwif->present) {
2483 if (!hwif->irq) {
2484 if (!(hwif->irq = default_irqs[h])) {
2485 printk("%s: DISABLED, NO IRQ\n", hwif->name);
2486 hwif->present = 0;
2487 continue;
2488 }
2489 }
2490 #ifdef CONFIG_BLK_DEV_HD
2491 if (hwif->irq == HD_IRQ && hwif->io_base != HD_DATA) {
2492 printk("%s: CANNOT SHARE IRQ WITH OLD HARDDISK DRIVER (hd.c)\n", hwif->name);
2493 hwif->present = 0;
2494 }
2495 #endif
2496 }
2497 }
2498
2499
2500
2501
2502 for (h = MAX_HWIFS-1; h >= 0; --h) {
2503 void (*rfn)(void);
2504 ide_hwif_t *hwif = &ide_hwifs[h];
2505 if (!hwif->present)
2506 continue;
2507 hwif->present = 0;
2508 if (h == 0 && single_threaded) {
2509 if (ide_hwifs[1].present) {
2510 if (irq_to_hwgroup[hwif->irq] != NULL) {
2511 printk("%s: SERIALIZE BUG!\n", hwif->name);
2512 continue;
2513 }
2514 irq_to_hwgroup[hwif->irq] = irq_to_hwgroup[ide_hwifs[1].irq];
2515 }
2516 }
2517 switch (hwif->major) {
2518 case IDE0_MAJOR: rfn = &do_ide0_request; break;
2519 case IDE1_MAJOR: rfn = &do_ide1_request; break;
2520 case IDE2_MAJOR: rfn = &do_ide2_request; break;
2521 case IDE3_MAJOR: rfn = &do_ide3_request; break;
2522 default:
2523 printk("%s: request_fn NOT DEFINED\n", hwif->name);
2524 continue;
2525 }
2526 if (register_blkdev (hwif->major, hwif->name, &ide_fops)) {
2527 printk("%s: UNABLE TO GET MAJOR NUMBER %d\n", hwif->name, hwif->major);
2528 } else if (init_irq (hwif)) {
2529 printk("%s: UNABLE TO GET IRQ %d\n", hwif->name, hwif->irq);
2530 (void) unregister_blkdev (hwif->major, hwif->name);
2531 } else {
2532 init_gendisk(hwif);
2533 blk_dev[hwif->major].request_fn = rfn;
2534 read_ahead[hwif->major] = 8;
2535 hwif->present = 1;
2536 }
2537 }
2538 mem_start = init_mem_start;
2539 init_mem_start = 0uL;
2540 return mem_start;
2541 }