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#define REVISION "Revision: 7.00alpha2"
127#define VERSION "Id: ide.c 7.00a2 20020906"
128
129#undef REALLY_SLOW_IO
130
131#define _IDE_C
132
133#include <linux/config.h>
134#include <linux/module.h>
135#include <linux/types.h>
136#include <linux/string.h>
137#include <linux/kernel.h>
138#include <linux/timer.h>
139#include <linux/mm.h>
140#include <linux/interrupt.h>
141#include <linux/major.h>
142#include <linux/errno.h>
143#include <linux/genhd.h>
144#include <linux/blkpg.h>
145#include <linux/slab.h>
146#include <linux/init.h>
147#include <linux/pci.h>
148#include <linux/delay.h>
149#include <linux/ide.h>
150#include <linux/devfs_fs_kernel.h>
151#include <linux/completion.h>
152#include <linux/reboot.h>
153#include <linux/cdrom.h>
154#include <linux/seq_file.h>
155#include <linux/device.h>
156#include <linux/bitops.h>
157
158#include <asm/byteorder.h>
159#include <asm/irq.h>
160#include <asm/uaccess.h>
161#include <asm/io.h>
162
163
164
165#define IDE_DEFAULT_MAX_FAILURES 1
166
167static const u8 ide_hwif_to_major[] = { IDE0_MAJOR, IDE1_MAJOR,
168 IDE2_MAJOR, IDE3_MAJOR,
169 IDE4_MAJOR, IDE5_MAJOR,
170 IDE6_MAJOR, IDE7_MAJOR,
171 IDE8_MAJOR, IDE9_MAJOR };
172
173static int idebus_parameter;
174static int system_bus_speed;
175static int initializing;
176
177DECLARE_MUTEX(ide_cfg_sem);
178 __cacheline_aligned_in_smp DEFINE_SPINLOCK(ide_lock);
179
180#ifdef CONFIG_BLK_DEV_IDEPCI
181static int ide_scan_direction;
182#endif
183
184#ifdef CONFIG_IDEDMA_AUTO
185int noautodma = 0;
186#else
187int noautodma = 1;
188#endif
189
190EXPORT_SYMBOL(noautodma);
191
192
193
194
195ide_hwif_t ide_hwifs[MAX_HWIFS];
196
197EXPORT_SYMBOL(ide_hwifs);
198
199extern ide_driver_t idedefault_driver;
200static void setup_driver_defaults(ide_driver_t *driver);
201
202
203
204
205static void init_hwif_data(ide_hwif_t *hwif, unsigned int index)
206{
207 unsigned int unit;
208
209
210 memset(hwif, 0, sizeof(ide_hwif_t));
211
212
213 hwif->index = index;
214 hwif->major = ide_hwif_to_major[index];
215
216 hwif->name[0] = 'i';
217 hwif->name[1] = 'd';
218 hwif->name[2] = 'e';
219 hwif->name[3] = '0' + index;
220
221 hwif->bus_state = BUSSTATE_ON;
222
223 hwif->atapi_dma = 0;
224 hwif->ultra_mask = 0x80;
225 hwif->mwdma_mask = 0x80;
226 hwif->swdma_mask = 0x80;
227
228 sema_init(&hwif->gendev_rel_sem, 0);
229
230 default_hwif_iops(hwif);
231 default_hwif_transport(hwif);
232 for (unit = 0; unit < MAX_DRIVES; ++unit) {
233 ide_drive_t *drive = &hwif->drives[unit];
234
235 drive->media = ide_disk;
236 drive->select.all = (unit<<4)|0xa0;
237 drive->hwif = hwif;
238 drive->ctl = 0x08;
239 drive->ready_stat = READY_STAT;
240 drive->bad_wstat = BAD_W_STAT;
241 drive->special.b.recalibrate = 1;
242 drive->special.b.set_geometry = 1;
243 drive->name[0] = 'h';
244 drive->name[1] = 'd';
245 drive->name[2] = 'a' + (index * MAX_DRIVES) + unit;
246 drive->max_failures = IDE_DEFAULT_MAX_FAILURES;
247 drive->using_dma = 0;
248 drive->is_flash = 0;
249 drive->driver = &idedefault_driver;
250 drive->vdma = 0;
251 INIT_LIST_HEAD(&drive->list);
252 sema_init(&drive->gendev_rel_sem, 0);
253 }
254}
255
256static void init_hwif_default(ide_hwif_t *hwif, unsigned int index)
257{
258 hw_regs_t hw;
259
260 memset(&hw, 0, sizeof(hw_regs_t));
261
262 ide_init_hwif_ports(&hw, ide_default_io_base(index), 0, &hwif->irq);
263
264 memcpy(&hwif->hw, &hw, sizeof(hw));
265 memcpy(hwif->io_ports, hw.io_ports, sizeof(hw.io_ports));
266
267 hwif->noprobe = !hwif->io_ports[IDE_DATA_OFFSET];
268#ifdef CONFIG_BLK_DEV_HD
269 if (hwif->io_ports[IDE_DATA_OFFSET] == HD_DATA)
270 hwif->noprobe = 1;
271#endif
272}
273
274extern void ide_arm_init(void);
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293#define MAGIC_COOKIE 0x12345678
294static void __init init_ide_data (void)
295{
296 ide_hwif_t *hwif;
297 unsigned int index;
298 static unsigned long magic_cookie = MAGIC_COOKIE;
299
300 if (magic_cookie != MAGIC_COOKIE)
301 return;
302 magic_cookie = 0;
303
304 setup_driver_defaults(&idedefault_driver);
305
306
307 for (index = 0; index < MAX_HWIFS; ++index) {
308 hwif = &ide_hwifs[index];
309 init_hwif_data(hwif, index);
310 init_hwif_default(hwif, index);
311#if !defined(CONFIG_PPC32) || !defined(CONFIG_PCI)
312 hwif->irq = hwif->hw.irq =
313 ide_init_default_irq(hwif->io_ports[IDE_DATA_OFFSET]);
314#endif
315 }
316#ifdef CONFIG_IDE_ARM
317 initializing = 1;
318 ide_arm_init();
319 initializing = 0;
320#endif
321}
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336static int ide_system_bus_speed(void)
337{
338#ifdef CONFIG_PCI
339 static struct pci_device_id pci_default[] = {
340 { PCI_DEVICE(PCI_ANY_ID, PCI_ANY_ID) },
341 { }
342 };
343#else
344#define pci_default 0
345#endif
346
347 if (!system_bus_speed) {
348 if (idebus_parameter) {
349
350 system_bus_speed = idebus_parameter;
351 } else if (pci_dev_present(pci_default)) {
352
353 system_bus_speed = 33;
354 } else {
355
356 system_bus_speed = 50;
357 }
358 printk(KERN_INFO "ide: Assuming %dMHz system bus speed "
359 "for PIO modes%s\n", system_bus_speed,
360 idebus_parameter ? "" : "; override with idebus=xx");
361 }
362 return system_bus_speed;
363}
364
365static int ide_open (struct inode * inode, struct file * filp)
366{
367 return -ENXIO;
368}
369
370
371
372
373
374
375static DEFINE_SPINLOCK(drives_lock);
376static DEFINE_SPINLOCK(drivers_lock);
377static LIST_HEAD(drivers);
378
379
380
381static void *m_start(struct seq_file *m, loff_t *pos)
382{
383 struct list_head *p;
384 loff_t l = *pos;
385 spin_lock(&drivers_lock);
386 list_for_each(p, &drivers)
387 if (!l--)
388 return list_entry(p, ide_driver_t, drivers);
389 return NULL;
390}
391
392static void *m_next(struct seq_file *m, void *v, loff_t *pos)
393{
394 struct list_head *p = ((ide_driver_t *)v)->drivers.next;
395 (*pos)++;
396 return p==&drivers ? NULL : list_entry(p, ide_driver_t, drivers);
397}
398
399static void m_stop(struct seq_file *m, void *v)
400{
401 spin_unlock(&drivers_lock);
402}
403
404static int show_driver(struct seq_file *m, void *v)
405{
406 ide_driver_t *driver = v;
407 seq_printf(m, "%s version %s\n", driver->name, driver->version);
408 return 0;
409}
410
411struct seq_operations ide_drivers_op = {
412 .start = m_start,
413 .next = m_next,
414 .stop = m_stop,
415 .show = show_driver
416};
417
418#ifdef CONFIG_PROC_FS
419struct proc_dir_entry *proc_ide_root;
420
421static ide_proc_entry_t generic_subdriver_entries[] = {
422 { "capacity", S_IFREG|S_IRUGO, proc_ide_read_capacity, NULL },
423 { NULL, 0, NULL, NULL }
424};
425#endif
426
427static struct resource* hwif_request_region(ide_hwif_t *hwif,
428 unsigned long addr, int num)
429{
430 struct resource *res = request_region(addr, num, hwif->name);
431
432 if (!res)
433 printk(KERN_ERR "%s: I/O resource 0x%lX-0x%lX not free.\n",
434 hwif->name, addr, addr+num-1);
435 return res;
436}
437
438
439
440
441
442
443
444
445
446
447
448int ide_hwif_request_regions(ide_hwif_t *hwif)
449{
450 unsigned long addr;
451 unsigned int i;
452
453 if (hwif->mmio == 2)
454 return 0;
455 BUG_ON(hwif->mmio == 1);
456 addr = hwif->io_ports[IDE_CONTROL_OFFSET];
457 if (addr && !hwif_request_region(hwif, addr, 1))
458 goto control_region_busy;
459 hwif->straight8 = 0;
460 addr = hwif->io_ports[IDE_DATA_OFFSET];
461 if ((addr | 7) == hwif->io_ports[IDE_STATUS_OFFSET]) {
462 if (!hwif_request_region(hwif, addr, 8))
463 goto data_region_busy;
464 hwif->straight8 = 1;
465 return 0;
466 }
467 for (i = IDE_DATA_OFFSET; i <= IDE_STATUS_OFFSET; i++) {
468 addr = hwif->io_ports[i];
469 if (!hwif_request_region(hwif, addr, 1)) {
470 while (--i)
471 release_region(addr, 1);
472 goto data_region_busy;
473 }
474 }
475 return 0;
476
477data_region_busy:
478 addr = hwif->io_ports[IDE_CONTROL_OFFSET];
479 if (addr)
480 release_region(addr, 1);
481control_region_busy:
482
483 return -EBUSY;
484}
485
486
487
488
489
490
491
492
493
494
495
496
497
498void ide_hwif_release_regions(ide_hwif_t *hwif)
499{
500 u32 i = 0;
501
502 if (hwif->mmio == 2)
503 return;
504 if (hwif->io_ports[IDE_CONTROL_OFFSET])
505 release_region(hwif->io_ports[IDE_CONTROL_OFFSET], 1);
506 if (hwif->straight8) {
507 release_region(hwif->io_ports[IDE_DATA_OFFSET], 8);
508 return;
509 }
510 for (i = IDE_DATA_OFFSET; i <= IDE_STATUS_OFFSET; i++)
511 if (hwif->io_ports[i])
512 release_region(hwif->io_ports[i], 1);
513}
514
515
516
517
518
519
520
521
522
523
524static void ide_hwif_restore(ide_hwif_t *hwif, ide_hwif_t *tmp_hwif)
525{
526 hwif->hwgroup = tmp_hwif->hwgroup;
527
528 hwif->gendev.parent = tmp_hwif->gendev.parent;
529
530 hwif->proc = tmp_hwif->proc;
531
532 hwif->major = tmp_hwif->major;
533 hwif->straight8 = tmp_hwif->straight8;
534 hwif->bus_state = tmp_hwif->bus_state;
535
536 hwif->atapi_dma = tmp_hwif->atapi_dma;
537 hwif->ultra_mask = tmp_hwif->ultra_mask;
538 hwif->mwdma_mask = tmp_hwif->mwdma_mask;
539 hwif->swdma_mask = tmp_hwif->swdma_mask;
540
541 hwif->chipset = tmp_hwif->chipset;
542 hwif->hold = tmp_hwif->hold;
543
544#ifdef CONFIG_BLK_DEV_IDEPCI
545 hwif->pci_dev = tmp_hwif->pci_dev;
546 hwif->cds = tmp_hwif->cds;
547#endif
548
549 hwif->tuneproc = tmp_hwif->tuneproc;
550 hwif->speedproc = tmp_hwif->speedproc;
551 hwif->selectproc = tmp_hwif->selectproc;
552 hwif->reset_poll = tmp_hwif->reset_poll;
553 hwif->pre_reset = tmp_hwif->pre_reset;
554 hwif->resetproc = tmp_hwif->resetproc;
555 hwif->intrproc = tmp_hwif->intrproc;
556 hwif->maskproc = tmp_hwif->maskproc;
557 hwif->quirkproc = tmp_hwif->quirkproc;
558 hwif->busproc = tmp_hwif->busproc;
559
560 hwif->ata_input_data = tmp_hwif->ata_input_data;
561 hwif->ata_output_data = tmp_hwif->ata_output_data;
562 hwif->atapi_input_bytes = tmp_hwif->atapi_input_bytes;
563 hwif->atapi_output_bytes = tmp_hwif->atapi_output_bytes;
564
565 hwif->dma_setup = tmp_hwif->dma_setup;
566 hwif->dma_exec_cmd = tmp_hwif->dma_exec_cmd;
567 hwif->dma_start = tmp_hwif->dma_start;
568 hwif->ide_dma_end = tmp_hwif->ide_dma_end;
569 hwif->ide_dma_check = tmp_hwif->ide_dma_check;
570 hwif->ide_dma_on = tmp_hwif->ide_dma_on;
571 hwif->ide_dma_off_quietly = tmp_hwif->ide_dma_off_quietly;
572 hwif->ide_dma_test_irq = tmp_hwif->ide_dma_test_irq;
573 hwif->ide_dma_host_on = tmp_hwif->ide_dma_host_on;
574 hwif->ide_dma_host_off = tmp_hwif->ide_dma_host_off;
575 hwif->ide_dma_lostirq = tmp_hwif->ide_dma_lostirq;
576 hwif->ide_dma_timeout = tmp_hwif->ide_dma_timeout;
577
578 hwif->OUTB = tmp_hwif->OUTB;
579 hwif->OUTBSYNC = tmp_hwif->OUTBSYNC;
580 hwif->OUTW = tmp_hwif->OUTW;
581 hwif->OUTL = tmp_hwif->OUTL;
582 hwif->OUTSW = tmp_hwif->OUTSW;
583 hwif->OUTSL = tmp_hwif->OUTSL;
584
585 hwif->INB = tmp_hwif->INB;
586 hwif->INW = tmp_hwif->INW;
587 hwif->INL = tmp_hwif->INL;
588 hwif->INSW = tmp_hwif->INSW;
589 hwif->INSL = tmp_hwif->INSL;
590
591 hwif->sg_max_nents = tmp_hwif->sg_max_nents;
592
593 hwif->mmio = tmp_hwif->mmio;
594 hwif->rqsize = tmp_hwif->rqsize;
595 hwif->no_lba48 = tmp_hwif->no_lba48;
596
597#ifndef CONFIG_BLK_DEV_IDECS
598 hwif->irq = tmp_hwif->irq;
599#endif
600
601 hwif->dma_base = tmp_hwif->dma_base;
602 hwif->dma_master = tmp_hwif->dma_master;
603 hwif->dma_command = tmp_hwif->dma_command;
604 hwif->dma_vendor1 = tmp_hwif->dma_vendor1;
605 hwif->dma_status = tmp_hwif->dma_status;
606 hwif->dma_vendor3 = tmp_hwif->dma_vendor3;
607 hwif->dma_prdtable = tmp_hwif->dma_prdtable;
608
609 hwif->dma_extra = tmp_hwif->dma_extra;
610 hwif->config_data = tmp_hwif->config_data;
611 hwif->select_data = tmp_hwif->select_data;
612 hwif->autodma = tmp_hwif->autodma;
613 hwif->udma_four = tmp_hwif->udma_four;
614 hwif->no_dsc = tmp_hwif->no_dsc;
615
616 hwif->hwif_data = tmp_hwif->hwif_data;
617}
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641void ide_unregister(unsigned int index)
642{
643 ide_drive_t *drive;
644 ide_hwif_t *hwif, *g;
645 static ide_hwif_t tmp_hwif;
646 ide_hwgroup_t *hwgroup;
647 int irq_count = 0, unit, i;
648
649 BUG_ON(index >= MAX_HWIFS);
650
651 BUG_ON(in_interrupt());
652 BUG_ON(irqs_disabled());
653 down(&ide_cfg_sem);
654 spin_lock_irq(&ide_lock);
655 hwif = &ide_hwifs[index];
656 if (!hwif->present)
657 goto abort;
658 for (unit = 0; unit < MAX_DRIVES; ++unit) {
659 drive = &hwif->drives[unit];
660 if (!drive->present)
661 continue;
662 if (drive->usage || DRIVER(drive)->busy)
663 goto abort;
664 drive->dead = 1;
665 }
666 hwif->present = 0;
667
668 spin_unlock_irq(&ide_lock);
669
670 for (unit = 0; unit < MAX_DRIVES; ++unit) {
671 drive = &hwif->drives[unit];
672 if (!drive->present)
673 continue;
674 DRIVER(drive)->cleanup(drive);
675 }
676
677 destroy_proc_ide_interface(hwif);
678
679 hwgroup = hwif->hwgroup;
680
681
682
683 g = hwgroup->hwif;
684 do {
685 if (g->irq == hwif->irq)
686 ++irq_count;
687 g = g->next;
688 } while (g != hwgroup->hwif);
689 if (irq_count == 1)
690 free_irq(hwif->irq, hwgroup);
691
692 spin_lock_irq(&ide_lock);
693
694
695
696
697
698 ide_hwif_release_regions(hwif);
699
700
701
702
703
704 for (i = 0; i < MAX_DRIVES; ++i) {
705 drive = &hwif->drives[i];
706 if (drive->devfs_name[0] != '\0') {
707 devfs_remove(drive->devfs_name);
708 drive->devfs_name[0] = '\0';
709 }
710 if (!drive->present)
711 continue;
712 if (drive == drive->next) {
713
714 BUG_ON(hwgroup->drive != drive);
715 hwgroup->drive = NULL;
716 } else {
717 ide_drive_t *walk;
718
719 walk = hwgroup->drive;
720 while (walk->next != drive)
721 walk = walk->next;
722 walk->next = drive->next;
723 if (hwgroup->drive == drive) {
724 hwgroup->drive = drive->next;
725 hwgroup->hwif = HWIF(hwgroup->drive);
726 }
727 }
728 BUG_ON(hwgroup->drive == drive);
729 if (drive->id != NULL) {
730 kfree(drive->id);
731 drive->id = NULL;
732 }
733 drive->present = 0;
734
735 spin_unlock_irq(&ide_lock);
736 blk_cleanup_queue(drive->queue);
737 device_unregister(&drive->gendev);
738 down(&drive->gendev_rel_sem);
739 spin_lock_irq(&ide_lock);
740 drive->queue = NULL;
741 }
742 if (hwif->next == hwif) {
743 BUG_ON(hwgroup->hwif != hwif);
744 kfree(hwgroup);
745 } else {
746
747
748
749
750 g = hwgroup->hwif;
751 while (g->next != hwif)
752 g = g->next;
753 g->next = hwif->next;
754 if (hwgroup->hwif == hwif) {
755
756
757
758
759 BUG_ON(hwgroup->drive != NULL);
760 hwgroup->hwif = g;
761 }
762 BUG_ON(hwgroup->hwif == hwif);
763 }
764
765
766 spin_unlock_irq(&ide_lock);
767 device_unregister(&hwif->gendev);
768 down(&hwif->gendev_rel_sem);
769
770
771
772
773 blk_unregister_region(MKDEV(hwif->major, 0), MAX_DRIVES<<PARTN_BITS);
774 for (i = 0; i < MAX_DRIVES; i++) {
775 struct gendisk *disk = hwif->drives[i].disk;
776 hwif->drives[i].disk = NULL;
777 put_disk(disk);
778 }
779 kfree(hwif->sg_table);
780 unregister_blkdev(hwif->major, hwif->name);
781 spin_lock_irq(&ide_lock);
782
783 if (hwif->dma_base) {
784 (void) ide_release_dma(hwif);
785
786 hwif->dma_base = 0;
787 hwif->dma_master = 0;
788 hwif->dma_command = 0;
789 hwif->dma_vendor1 = 0;
790 hwif->dma_status = 0;
791 hwif->dma_vendor3 = 0;
792 hwif->dma_prdtable = 0;
793 }
794
795
796 tmp_hwif = *hwif;
797
798
799 init_hwif_data(hwif, index);
800 init_hwif_default(hwif, index);
801
802 ide_hwif_restore(hwif, &tmp_hwif);
803
804abort:
805 spin_unlock_irq(&ide_lock);
806 up(&ide_cfg_sem);
807}
808
809EXPORT_SYMBOL(ide_unregister);
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827void ide_setup_ports ( hw_regs_t *hw,
828 unsigned long base, int *offsets,
829 unsigned long ctrl, unsigned long intr,
830 ide_ack_intr_t *ack_intr,
831
832
833
834 int irq)
835{
836 int i;
837
838 for (i = 0; i < IDE_NR_PORTS; i++) {
839 if (offsets[i] == -1) {
840 switch(i) {
841 case IDE_CONTROL_OFFSET:
842 hw->io_ports[i] = ctrl;
843 break;
844#if defined(CONFIG_AMIGA) || defined(CONFIG_MAC)
845 case IDE_IRQ_OFFSET:
846 hw->io_ports[i] = intr;
847 break;
848#endif
849 default:
850 hw->io_ports[i] = 0;
851 break;
852 }
853 } else {
854 hw->io_ports[i] = base + offsets[i];
855 }
856 }
857 hw->irq = irq;
858 hw->dma = NO_DMA;
859 hw->ack_intr = ack_intr;
860
861
862
863}
864
865
866
867
868
869
870
871
872
873
874
875
876
877int ide_register_hw_with_fixup(hw_regs_t *hw, ide_hwif_t **hwifp, void(*fixup)(ide_hwif_t *hwif))
878{
879 int index, retry = 1;
880 ide_hwif_t *hwif;
881
882 do {
883 for (index = 0; index < MAX_HWIFS; ++index) {
884 hwif = &ide_hwifs[index];
885 if (hwif->hw.io_ports[IDE_DATA_OFFSET] == hw->io_ports[IDE_DATA_OFFSET])
886 goto found;
887 }
888 for (index = 0; index < MAX_HWIFS; ++index) {
889 hwif = &ide_hwifs[index];
890 if (hwif->hold)
891 continue;
892 if ((!hwif->present && !hwif->mate && !initializing) ||
893 (!hwif->hw.io_ports[IDE_DATA_OFFSET] && initializing))
894 goto found;
895 }
896 for (index = 0; index < MAX_HWIFS; index++)
897 ide_unregister(index);
898 } while (retry--);
899 return -1;
900found:
901 if (hwif->present)
902 ide_unregister(index);
903 else if (!hwif->hold) {
904 init_hwif_data(hwif, index);
905 init_hwif_default(hwif, index);
906 }
907 if (hwif->present)
908 return -1;
909 memcpy(&hwif->hw, hw, sizeof(*hw));
910 memcpy(hwif->io_ports, hwif->hw.io_ports, sizeof(hwif->hw.io_ports));
911 hwif->irq = hw->irq;
912 hwif->noprobe = 0;
913 hwif->chipset = hw->chipset;
914
915 if (!initializing) {
916 probe_hwif_init_with_fixup(hwif, fixup);
917 create_proc_ide_interfaces();
918 }
919
920 if (hwifp)
921 *hwifp = hwif;
922
923 return (initializing || hwif->present) ? index : -1;
924}
925
926EXPORT_SYMBOL(ide_register_hw_with_fixup);
927
928int ide_register_hw(hw_regs_t *hw, ide_hwif_t **hwifp)
929{
930 return ide_register_hw_with_fixup(hw, hwifp, NULL);
931}
932
933EXPORT_SYMBOL(ide_register_hw);
934
935
936
937
938
939DECLARE_MUTEX(ide_setting_sem);
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967int ide_add_setting (ide_drive_t *drive, const char *name, int rw, int read_ioctl, int write_ioctl, int data_type, int min, int max, int mul_factor, int div_factor, void *data, ide_procset_t *set)
968{
969 ide_settings_t **p = (ide_settings_t **) &drive->settings, *setting = NULL;
970
971 down(&ide_setting_sem);
972 while ((*p) && strcmp((*p)->name, name) < 0)
973 p = &((*p)->next);
974 if ((setting = kmalloc(sizeof(*setting), GFP_KERNEL)) == NULL)
975 goto abort;
976 memset(setting, 0, sizeof(*setting));
977 if ((setting->name = kmalloc(strlen(name) + 1, GFP_KERNEL)) == NULL)
978 goto abort;
979 strcpy(setting->name, name);
980 setting->rw = rw;
981 setting->read_ioctl = read_ioctl;
982 setting->write_ioctl = write_ioctl;
983 setting->data_type = data_type;
984 setting->min = min;
985 setting->max = max;
986 setting->mul_factor = mul_factor;
987 setting->div_factor = div_factor;
988 setting->data = data;
989 setting->set = set;
990
991 setting->next = *p;
992 if (drive->driver != &idedefault_driver)
993 setting->auto_remove = 1;
994 *p = setting;
995 up(&ide_setting_sem);
996 return 0;
997abort:
998 up(&ide_setting_sem);
999 if (setting)
1000 kfree(setting);
1001 return -1;
1002}
1003
1004EXPORT_SYMBOL(ide_add_setting);
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015static void __ide_remove_setting (ide_drive_t *drive, char *name)
1016{
1017 ide_settings_t **p, *setting;
1018
1019 p = (ide_settings_t **) &drive->settings;
1020
1021 while ((*p) && strcmp((*p)->name, name))
1022 p = &((*p)->next);
1023 if ((setting = (*p)) == NULL)
1024 return;
1025
1026 (*p) = setting->next;
1027
1028 kfree(setting->name);
1029 kfree(setting);
1030}
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042static ide_settings_t *ide_find_setting_by_ioctl (ide_drive_t *drive, int cmd)
1043{
1044 ide_settings_t *setting = drive->settings;
1045
1046 while (setting) {
1047 if (setting->read_ioctl == cmd || setting->write_ioctl == cmd)
1048 break;
1049 setting = setting->next;
1050 }
1051
1052 return setting;
1053}
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065ide_settings_t *ide_find_setting_by_name (ide_drive_t *drive, char *name)
1066{
1067 ide_settings_t *setting = drive->settings;
1068
1069 while (setting) {
1070 if (strcmp(setting->name, name) == 0)
1071 break;
1072 setting = setting->next;
1073 }
1074 return setting;
1075}
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086static void auto_remove_settings (ide_drive_t *drive)
1087{
1088 ide_settings_t *setting;
1089repeat:
1090 setting = drive->settings;
1091 while (setting) {
1092 if (setting->auto_remove) {
1093 __ide_remove_setting(drive, setting->name);
1094 goto repeat;
1095 }
1096 setting = setting->next;
1097 }
1098}
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113int ide_read_setting (ide_drive_t *drive, ide_settings_t *setting)
1114{
1115 int val = -EINVAL;
1116 unsigned long flags;
1117
1118 if ((setting->rw & SETTING_READ)) {
1119 spin_lock_irqsave(&ide_lock, flags);
1120 switch(setting->data_type) {
1121 case TYPE_BYTE:
1122 val = *((u8 *) setting->data);
1123 break;
1124 case TYPE_SHORT:
1125 val = *((u16 *) setting->data);
1126 break;
1127 case TYPE_INT:
1128 case TYPE_INTA:
1129 val = *((u32 *) setting->data);
1130 break;
1131 }
1132 spin_unlock_irqrestore(&ide_lock, flags);
1133 }
1134 return val;
1135}
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146int ide_spin_wait_hwgroup (ide_drive_t *drive)
1147{
1148 ide_hwgroup_t *hwgroup = HWGROUP(drive);
1149 unsigned long timeout = jiffies + (3 * HZ);
1150
1151 spin_lock_irq(&ide_lock);
1152
1153 while (hwgroup->busy) {
1154 unsigned long lflags;
1155 spin_unlock_irq(&ide_lock);
1156 local_irq_set(lflags);
1157 if (time_after(jiffies, timeout)) {
1158 local_irq_restore(lflags);
1159 printk(KERN_ERR "%s: channel busy\n", drive->name);
1160 return -EBUSY;
1161 }
1162 local_irq_restore(lflags);
1163 spin_lock_irq(&ide_lock);
1164 }
1165 return 0;
1166}
1167
1168EXPORT_SYMBOL(ide_spin_wait_hwgroup);
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188int ide_write_setting (ide_drive_t *drive, ide_settings_t *setting, int val)
1189{
1190 int i;
1191 u32 *p;
1192
1193 if (!capable(CAP_SYS_ADMIN))
1194 return -EACCES;
1195 if (!(setting->rw & SETTING_WRITE))
1196 return -EPERM;
1197 if (val < setting->min || val > setting->max)
1198 return -EINVAL;
1199 if (setting->set)
1200 return setting->set(drive, val);
1201 if (ide_spin_wait_hwgroup(drive))
1202 return -EBUSY;
1203 switch (setting->data_type) {
1204 case TYPE_BYTE:
1205 *((u8 *) setting->data) = val;
1206 break;
1207 case TYPE_SHORT:
1208 *((u16 *) setting->data) = val;
1209 break;
1210 case TYPE_INT:
1211 *((u32 *) setting->data) = val;
1212 break;
1213 case TYPE_INTA:
1214 p = (u32 *) setting->data;
1215 for (i = 0; i < 1 << PARTN_BITS; i++, p++)
1216 *p = val;
1217 break;
1218 }
1219 spin_unlock_irq(&ide_lock);
1220 return 0;
1221}
1222
1223static int set_io_32bit(ide_drive_t *drive, int arg)
1224{
1225 drive->io_32bit = arg;
1226#ifdef CONFIG_BLK_DEV_DTC2278
1227 if (HWIF(drive)->chipset == ide_dtc2278)
1228 HWIF(drive)->drives[!drive->select.b.unit].io_32bit = arg;
1229#endif
1230 return 0;
1231}
1232
1233static int set_using_dma (ide_drive_t *drive, int arg)
1234{
1235#ifdef CONFIG_BLK_DEV_IDEDMA
1236 if (!drive->id || !(drive->id->capability & 1))
1237 return -EPERM;
1238 if (HWIF(drive)->ide_dma_check == NULL)
1239 return -EPERM;
1240 if (arg) {
1241 if (HWIF(drive)->ide_dma_check(drive)) return -EIO;
1242 if (HWIF(drive)->ide_dma_on(drive)) return -EIO;
1243 } else {
1244 if (__ide_dma_off(drive))
1245 return -EIO;
1246 }
1247 return 0;
1248#else
1249 return -EPERM;
1250#endif
1251}
1252
1253static int set_pio_mode (ide_drive_t *drive, int arg)
1254{
1255 struct request rq;
1256
1257 if (!HWIF(drive)->tuneproc)
1258 return -ENOSYS;
1259 if (drive->special.b.set_tune)
1260 return -EBUSY;
1261 ide_init_drive_cmd(&rq);
1262 drive->tune_req = (u8) arg;
1263 drive->special.b.set_tune = 1;
1264 (void) ide_do_drive_cmd(drive, &rq, ide_wait);
1265 return 0;
1266}
1267
1268static int set_xfer_rate (ide_drive_t *drive, int arg)
1269{
1270 int err = ide_wait_cmd(drive,
1271 WIN_SETFEATURES, (u8) arg,
1272 SETFEATURES_XFER, 0, NULL);
1273
1274 if (!err && arg) {
1275 ide_set_xfer_rate(drive, (u8) arg);
1276 ide_driveid_update(drive);
1277 }
1278 return err;
1279}
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290void ide_add_generic_settings (ide_drive_t *drive)
1291{
1292
1293
1294
1295 ide_add_setting(drive, "io_32bit", drive->no_io_32bit ? SETTING_READ : SETTING_RW, HDIO_GET_32BIT, HDIO_SET_32BIT, TYPE_BYTE, 0, 1 + (SUPPORT_VLB_SYNC << 1), 1, 1, &drive->io_32bit, set_io_32bit);
1296 ide_add_setting(drive, "keepsettings", SETTING_RW, HDIO_GET_KEEPSETTINGS, HDIO_SET_KEEPSETTINGS, TYPE_BYTE, 0, 1, 1, 1, &drive->keep_settings, NULL);
1297 ide_add_setting(drive, "nice1", SETTING_RW, -1, -1, TYPE_BYTE, 0, 1, 1, 1, &drive->nice1, NULL);
1298 ide_add_setting(drive, "pio_mode", SETTING_WRITE, -1, HDIO_SET_PIO_MODE, TYPE_BYTE, 0, 255, 1, 1, NULL, set_pio_mode);
1299 ide_add_setting(drive, "unmaskirq", drive->no_unmask ? SETTING_READ : SETTING_RW, HDIO_GET_UNMASKINTR, HDIO_SET_UNMASKINTR, TYPE_BYTE, 0, 1, 1, 1, &drive->unmask, NULL);
1300 ide_add_setting(drive, "using_dma", SETTING_RW, HDIO_GET_DMA, HDIO_SET_DMA, TYPE_BYTE, 0, 1, 1, 1, &drive->using_dma, set_using_dma);
1301 ide_add_setting(drive, "init_speed", SETTING_RW, -1, -1, TYPE_BYTE, 0, 70, 1, 1, &drive->init_speed, NULL);
1302 ide_add_setting(drive, "current_speed", SETTING_RW, -1, -1, TYPE_BYTE, 0, 70, 1, 1, &drive->current_speed, set_xfer_rate);
1303 ide_add_setting(drive, "number", SETTING_RW, -1, -1, TYPE_BYTE, 0, 3, 1, 1, &drive->dn, NULL);
1304}
1305
1306
1307
1308
1309
1310
1311
1312
1313int system_bus_clock (void)
1314{
1315 return((int) ((!system_bus_speed) ? ide_system_bus_speed() : system_bus_speed ));
1316}
1317
1318EXPORT_SYMBOL(system_bus_clock);
1319
1320
1321
1322
1323
1324
1325int ide_replace_subdriver (ide_drive_t *drive, const char *driver)
1326{
1327 if (!drive->present || drive->usage || drive->dead)
1328 goto abort;
1329 if (DRIVER(drive)->cleanup(drive))
1330 goto abort;
1331 strlcpy(drive->driver_req, driver, sizeof(drive->driver_req));
1332 if (ata_attach(drive)) {
1333 spin_lock(&drives_lock);
1334 list_del_init(&drive->list);
1335 spin_unlock(&drives_lock);
1336 drive->driver_req[0] = 0;
1337 ata_attach(drive);
1338 } else {
1339 drive->driver_req[0] = 0;
1340 }
1341 if (DRIVER(drive)!= &idedefault_driver && !strcmp(DRIVER(drive)->name, driver))
1342 return 0;
1343abort:
1344 return 1;
1345}
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363int ata_attach(ide_drive_t *drive)
1364{
1365 struct list_head *p;
1366 spin_lock(&drivers_lock);
1367 list_for_each(p, &drivers) {
1368 ide_driver_t *driver = list_entry(p, ide_driver_t, drivers);
1369 if (!try_module_get(driver->owner))
1370 continue;
1371 spin_unlock(&drivers_lock);
1372 if (driver->attach(drive) == 0) {
1373 module_put(driver->owner);
1374 drive->gendev.driver = &driver->gen_driver;
1375 return 0;
1376 }
1377 spin_lock(&drivers_lock);
1378 module_put(driver->owner);
1379 }
1380 drive->gendev.driver = &idedefault_driver.gen_driver;
1381 spin_unlock(&drivers_lock);
1382 if(idedefault_driver.attach(drive) != 0)
1383 panic("ide: default attach failed");
1384 return 1;
1385}
1386
1387static int generic_ide_suspend(struct device *dev, pm_message_t state)
1388{
1389 ide_drive_t *drive = dev->driver_data;
1390 struct request rq;
1391 struct request_pm_state rqpm;
1392 ide_task_t args;
1393
1394 memset(&rq, 0, sizeof(rq));
1395 memset(&rqpm, 0, sizeof(rqpm));
1396 memset(&args, 0, sizeof(args));
1397 rq.flags = REQ_PM_SUSPEND;
1398 rq.special = &args;
1399 rq.pm = &rqpm;
1400 rqpm.pm_step = ide_pm_state_start_suspend;
1401 rqpm.pm_state = state;
1402
1403 return ide_do_drive_cmd(drive, &rq, ide_wait);
1404}
1405
1406static int generic_ide_resume(struct device *dev)
1407{
1408 ide_drive_t *drive = dev->driver_data;
1409 struct request rq;
1410 struct request_pm_state rqpm;
1411 ide_task_t args;
1412
1413 memset(&rq, 0, sizeof(rq));
1414 memset(&rqpm, 0, sizeof(rqpm));
1415 memset(&args, 0, sizeof(args));
1416 rq.flags = REQ_PM_RESUME;
1417 rq.special = &args;
1418 rq.pm = &rqpm;
1419 rqpm.pm_step = ide_pm_state_start_resume;
1420 rqpm.pm_state = 0;
1421
1422 return ide_do_drive_cmd(drive, &rq, ide_head_wait);
1423}
1424
1425int generic_ide_ioctl(struct file *file, struct block_device *bdev,
1426 unsigned int cmd, unsigned long arg)
1427{
1428 ide_drive_t *drive = bdev->bd_disk->private_data;
1429 ide_settings_t *setting;
1430 int err = 0;
1431 void __user *p = (void __user *)arg;
1432
1433 down(&ide_setting_sem);
1434 if ((setting = ide_find_setting_by_ioctl(drive, cmd)) != NULL) {
1435 if (cmd == setting->read_ioctl) {
1436 err = ide_read_setting(drive, setting);
1437 up(&ide_setting_sem);
1438 return err >= 0 ? put_user(err, (long __user *)arg) : err;
1439 } else {
1440 if (bdev != bdev->bd_contains)
1441 err = -EINVAL;
1442 else
1443 err = ide_write_setting(drive, setting, arg);
1444 up(&ide_setting_sem);
1445 return err;
1446 }
1447 }
1448 up(&ide_setting_sem);
1449
1450 switch (cmd) {
1451 case HDIO_GETGEO:
1452 {
1453 struct hd_geometry geom;
1454 if (!p || (drive->media != ide_disk && drive->media != ide_floppy)) return -EINVAL;
1455 geom.heads = drive->bios_head;
1456 geom.sectors = drive->bios_sect;
1457 geom.cylinders = (u16)drive->bios_cyl;
1458 geom.start = get_start_sect(bdev);
1459 if (copy_to_user(p, &geom, sizeof(struct hd_geometry)))
1460 return -EFAULT;
1461 return 0;
1462 }
1463
1464 case HDIO_OBSOLETE_IDENTITY:
1465 case HDIO_GET_IDENTITY:
1466 if (bdev != bdev->bd_contains)
1467 return -EINVAL;
1468 if (drive->id_read == 0)
1469 return -ENOMSG;
1470 if (copy_to_user(p, drive->id, (cmd == HDIO_GET_IDENTITY) ? sizeof(*drive->id) : 142))
1471 return -EFAULT;
1472 return 0;
1473
1474 case HDIO_GET_NICE:
1475 return put_user(drive->dsc_overlap << IDE_NICE_DSC_OVERLAP |
1476 drive->atapi_overlap << IDE_NICE_ATAPI_OVERLAP |
1477 drive->nice0 << IDE_NICE_0 |
1478 drive->nice1 << IDE_NICE_1 |
1479 drive->nice2 << IDE_NICE_2,
1480 (long __user *) arg);
1481
1482#ifdef CONFIG_IDE_TASK_IOCTL
1483 case HDIO_DRIVE_TASKFILE:
1484 if (!capable(CAP_SYS_ADMIN) || !capable(CAP_SYS_RAWIO))
1485 return -EACCES;
1486 switch(drive->media) {
1487 case ide_disk:
1488 return ide_taskfile_ioctl(drive, cmd, arg);
1489 default:
1490 return -ENOMSG;
1491 }
1492#endif
1493
1494 case HDIO_DRIVE_CMD:
1495 if (!capable(CAP_SYS_RAWIO))
1496 return -EACCES;
1497 return ide_cmd_ioctl(drive, cmd, arg);
1498
1499 case HDIO_DRIVE_TASK:
1500 if (!capable(CAP_SYS_RAWIO))
1501 return -EACCES;
1502 return ide_task_ioctl(drive, cmd, arg);
1503
1504 case HDIO_SCAN_HWIF:
1505 {
1506 hw_regs_t hw;
1507 int args[3];
1508 if (!capable(CAP_SYS_RAWIO)) return -EACCES;
1509 if (copy_from_user(args, p, 3 * sizeof(int)))
1510 return -EFAULT;
1511 memset(&hw, 0, sizeof(hw));
1512 ide_init_hwif_ports(&hw, (unsigned long) args[0],
1513 (unsigned long) args[1], NULL);
1514 hw.irq = args[2];
1515 if (ide_register_hw(&hw, NULL) == -1)
1516 return -EIO;
1517 return 0;
1518 }
1519 case HDIO_UNREGISTER_HWIF:
1520 if (!capable(CAP_SYS_RAWIO)) return -EACCES;
1521
1522 ide_unregister(arg);
1523 return 0;
1524 case HDIO_SET_NICE:
1525 if (!capable(CAP_SYS_ADMIN)) return -EACCES;
1526 if (arg != (arg & ((1 << IDE_NICE_DSC_OVERLAP) | (1 << IDE_NICE_1))))
1527 return -EPERM;
1528 drive->dsc_overlap = (arg >> IDE_NICE_DSC_OVERLAP) & 1;
1529 if (drive->dsc_overlap && !DRIVER(drive)->supports_dsc_overlap) {
1530 drive->dsc_overlap = 0;
1531 return -EPERM;
1532 }
1533 drive->nice1 = (arg >> IDE_NICE_1) & 1;
1534 return 0;
1535 case HDIO_DRIVE_RESET:
1536 {
1537 unsigned long flags;
1538 if (!capable(CAP_SYS_ADMIN)) return -EACCES;
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548 spin_lock_irqsave(&ide_lock, flags);
1549
1550 ide_abort(drive, "drive reset");
1551
1552 if(HWGROUP(drive)->handler)
1553 BUG();
1554
1555
1556
1557
1558 HWGROUP(drive)->busy = 1;
1559 spin_unlock_irqrestore(&ide_lock, flags);
1560 (void) ide_do_reset(drive);
1561
1562 return 0;
1563 }
1564
1565 case CDROMEJECT:
1566 case CDROMCLOSETRAY:
1567 return scsi_cmd_ioctl(file, bdev->bd_disk, cmd, p);
1568
1569 case HDIO_GET_BUSSTATE:
1570 if (!capable(CAP_SYS_ADMIN))
1571 return -EACCES;
1572 if (put_user(HWIF(drive)->bus_state, (long __user *)arg))
1573 return -EFAULT;
1574 return 0;
1575
1576 case HDIO_SET_BUSSTATE:
1577 if (!capable(CAP_SYS_ADMIN))
1578 return -EACCES;
1579 if (HWIF(drive)->busproc)
1580 return HWIF(drive)->busproc(drive, (int)arg);
1581 return -EOPNOTSUPP;
1582 default:
1583 return -EINVAL;
1584 }
1585}
1586
1587EXPORT_SYMBOL(generic_ide_ioctl);
1588
1589
1590
1591
1592
1593static int __init stridx (const char *s, char c)
1594{
1595 char *i = strchr(s, c);
1596 return (i && c) ? i - s : -1;
1597}
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611static int __init match_parm (char *s, const char *keywords[], int vals[], int max_vals)
1612{
1613 static const char *decimal = "0123456789";
1614 static const char *hex = "0123456789abcdef";
1615 int i, n;
1616
1617 if (*s++ == '=') {
1618
1619
1620
1621
1622 if (keywords != NULL) {
1623 for (i = 0; *keywords != NULL; ++i) {
1624 if (!strcmp(s, *keywords++))
1625 return -(i+1);
1626 }
1627 }
1628
1629
1630
1631
1632
1633
1634 for (n = 0; (i = stridx(decimal, *s)) >= 0;) {
1635 vals[n] = i;
1636 while ((i = stridx(decimal, *++s)) >= 0)
1637 vals[n] = (vals[n] * 10) + i;
1638 if (*s == 'x' && !vals[n]) {
1639 while ((i = stridx(hex, *++s)) >= 0)
1640 vals[n] = (vals[n] * 0x10) + i;
1641 }
1642 if (++n == max_vals)
1643 break;
1644 if (*s == ',' || *s == ';')
1645 ++s;
1646 }
1647 if (!*s)
1648 return n;
1649 }
1650 return 0;
1651}
1652
1653#ifdef CONFIG_BLK_DEV_ALI14XX
1654static int __initdata probe_ali14xx;
1655extern int ali14xx_init(void);
1656#endif
1657#ifdef CONFIG_BLK_DEV_UMC8672
1658static int __initdata probe_umc8672;
1659extern int umc8672_init(void);
1660#endif
1661#ifdef CONFIG_BLK_DEV_DTC2278
1662static int __initdata probe_dtc2278;
1663extern int dtc2278_init(void);
1664#endif
1665#ifdef CONFIG_BLK_DEV_HT6560B
1666static int __initdata probe_ht6560b;
1667extern int ht6560b_init(void);
1668#endif
1669#ifdef CONFIG_BLK_DEV_QD65XX
1670static int __initdata probe_qd65xx;
1671extern int qd65xx_init(void);
1672#endif
1673
1674static int __initdata is_chipset_set[MAX_HWIFS];
1675
1676
1677
1678
1679
1680
1681
1682static int __init ide_setup(char *s)
1683{
1684 int i, vals[3];
1685 ide_hwif_t *hwif;
1686 ide_drive_t *drive;
1687 unsigned int hw, unit;
1688 const char max_drive = 'a' + ((MAX_HWIFS * MAX_DRIVES) - 1);
1689 const char max_hwif = '0' + (MAX_HWIFS - 1);
1690
1691
1692 if (strncmp(s,"hd",2) == 0 && s[2] == '=')
1693 return 0;
1694
1695 if (strncmp(s,"ide",3) && strncmp(s,"idebus",6) && strncmp(s,"hd",2))
1696 return 0;
1697
1698 printk(KERN_INFO "ide_setup: %s", s);
1699 init_ide_data ();
1700
1701#ifdef CONFIG_BLK_DEV_IDEDOUBLER
1702 if (!strcmp(s, "ide=doubler")) {
1703 extern int ide_doubler;
1704
1705 printk(" : Enabled support for IDE doublers\n");
1706 ide_doubler = 1;
1707 return 1;
1708 }
1709#endif
1710
1711 if (!strcmp(s, "ide=nodma")) {
1712 printk(" : Prevented DMA\n");
1713 noautodma = 1;
1714 return 1;
1715 }
1716
1717#ifdef CONFIG_BLK_DEV_IDEPCI
1718 if (!strcmp(s, "ide=reverse")) {
1719 ide_scan_direction = 1;
1720 printk(" : Enabled support for IDE inverse scan order.\n");
1721 return 1;
1722 }
1723#endif
1724
1725
1726
1727
1728 if (s[0] == 'h' && s[1] == 'd' && s[2] >= 'a' && s[2] <= max_drive) {
1729 const char *hd_words[] = {
1730 "none", "noprobe", "nowerr", "cdrom", "serialize",
1731 "autotune", "noautotune", "minus8", "swapdata", "bswap",
1732 "minus11", "remap", "remap63", "scsi", NULL };
1733 unit = s[2] - 'a';
1734 hw = unit / MAX_DRIVES;
1735 unit = unit % MAX_DRIVES;
1736 hwif = &ide_hwifs[hw];
1737 drive = &hwif->drives[unit];
1738 if (strncmp(s + 4, "ide-", 4) == 0) {
1739 strlcpy(drive->driver_req, s + 4, sizeof(drive->driver_req));
1740 goto done;
1741 }
1742 switch (match_parm(&s[3], hd_words, vals, 3)) {
1743 case -1:
1744 case -2:
1745 drive->noprobe = 1;
1746 goto done;
1747 case -3:
1748 drive->bad_wstat = BAD_R_STAT;
1749 hwif->noprobe = 0;
1750 goto done;
1751 case -4:
1752 drive->present = 1;
1753 drive->media = ide_cdrom;
1754 hwif->noprobe = 0;
1755 goto done;
1756 case -5:
1757 printk(" -- USE \"ide%d=serialize\" INSTEAD", hw);
1758 goto do_serialize;
1759 case -6:
1760 drive->autotune = IDE_TUNE_AUTO;
1761 goto obsolete_option;
1762 case -7:
1763 drive->autotune = IDE_TUNE_NOAUTO;
1764 goto obsolete_option;
1765 case -9:
1766 case -10:
1767 drive->bswap = 1;
1768 goto done;
1769 case -12:
1770 drive->remap_0_to_1 = 1;
1771 goto done;
1772 case -13:
1773 drive->sect0 = 63;
1774 goto done;
1775 case -14:
1776 drive->scsi = 1;
1777 goto done;
1778 case 3:
1779 drive->media = ide_disk;
1780 drive->cyl = drive->bios_cyl = vals[0];
1781 drive->head = drive->bios_head = vals[1];
1782 drive->sect = drive->bios_sect = vals[2];
1783 drive->present = 1;
1784 drive->forced_geom = 1;
1785 hwif->noprobe = 0;
1786 goto done;
1787 default:
1788 goto bad_option;
1789 }
1790 }
1791
1792 if (s[0] != 'i' || s[1] != 'd' || s[2] != 'e')
1793 goto bad_option;
1794
1795
1796
1797 if (s[3] == 'b' && s[4] == 'u' && s[5] == 's') {
1798 if (match_parm(&s[6], NULL, vals, 1) != 1)
1799 goto bad_option;
1800 if (vals[0] >= 20 && vals[0] <= 66) {
1801 idebus_parameter = vals[0];
1802 } else
1803 printk(" -- BAD BUS SPEED! Expected value from 20 to 66");
1804 goto done;
1805 }
1806
1807
1808
1809 if (s[3] >= '0' && s[3] <= max_hwif) {
1810
1811
1812
1813
1814 static const char *ide_words[] = {
1815 "noprobe", "serialize", "autotune", "noautotune",
1816 "reset", "dma", "ata66", "minus8", "minus9",
1817 "minus10", "four", "qd65xx", "ht6560b", "cmd640_vlb",
1818 "dtc2278", "umc8672", "ali14xx", NULL };
1819 hw = s[3] - '0';
1820 hwif = &ide_hwifs[hw];
1821 i = match_parm(&s[4], ide_words, vals, 3);
1822
1823
1824
1825
1826
1827 if ((i >= -18 && i <= -11) || (i > 0 && i <= 3)) {
1828
1829 if (is_chipset_set[hw])
1830 goto bad_option;
1831 if (i > -18 && i <= -11) {
1832
1833 if (hw != 0)
1834 goto bad_hwif;
1835
1836 if (is_chipset_set[hw+1])
1837 goto bad_option;
1838 }
1839 is_chipset_set[hw] = 1;
1840 printk("\n");
1841 }
1842
1843 switch (i) {
1844#ifdef CONFIG_BLK_DEV_ALI14XX
1845 case -17:
1846 probe_ali14xx = 1;
1847 goto done;
1848#endif
1849#ifdef CONFIG_BLK_DEV_UMC8672
1850 case -16:
1851 probe_umc8672 = 1;
1852 goto done;
1853#endif
1854#ifdef CONFIG_BLK_DEV_DTC2278
1855 case -15:
1856 probe_dtc2278 = 1;
1857 goto done;
1858#endif
1859#ifdef CONFIG_BLK_DEV_CMD640
1860 case -14:
1861 {
1862 extern int cmd640_vlb;
1863 cmd640_vlb = 1;
1864 goto done;
1865 }
1866#endif
1867#ifdef CONFIG_BLK_DEV_HT6560B
1868 case -13:
1869 probe_ht6560b = 1;
1870 goto done;
1871#endif
1872#ifdef CONFIG_BLK_DEV_QD65XX
1873 case -12:
1874 probe_qd65xx = 1;
1875 goto done;
1876#endif
1877#ifdef CONFIG_BLK_DEV_4DRIVES
1878 case -11:
1879 {
1880 ide_hwif_t *mate = &ide_hwifs[hw^1];
1881 mate->drives[0].select.all ^= 0x20;
1882 mate->drives[1].select.all ^= 0x20;
1883 hwif->chipset = mate->chipset = ide_4drives;
1884 mate->irq = hwif->irq;
1885 memcpy(mate->io_ports, hwif->io_ports, sizeof(hwif->io_ports));
1886 goto do_serialize;
1887 }
1888#endif
1889 case -10:
1890 case -9:
1891 case -8:
1892 goto bad_option;
1893 case -7:
1894#ifdef CONFIG_BLK_DEV_IDEPCI
1895 hwif->udma_four = 1;
1896 goto obsolete_option;
1897#else
1898 goto bad_hwif;
1899#endif
1900 case -6:
1901 hwif->autodma = 1;
1902 goto obsolete_option;
1903 case -5:
1904 hwif->reset = 1;
1905 goto obsolete_option;
1906 case -4:
1907 hwif->drives[0].autotune = IDE_TUNE_NOAUTO;
1908 hwif->drives[1].autotune = IDE_TUNE_NOAUTO;
1909 goto obsolete_option;
1910 case -3:
1911 hwif->drives[0].autotune = IDE_TUNE_AUTO;
1912 hwif->drives[1].autotune = IDE_TUNE_AUTO;
1913 goto obsolete_option;
1914 case -2:
1915 do_serialize:
1916 hwif->mate = &ide_hwifs[hw^1];
1917 hwif->mate->mate = hwif;
1918 hwif->serialized = hwif->mate->serialized = 1;
1919 goto obsolete_option;
1920
1921 case -1:
1922 hwif->noprobe = 1;
1923 goto done;
1924
1925 case 1:
1926 vals[1] = vals[0] + 0x206;
1927 case 2:
1928 vals[2] = 0;
1929 case 3:
1930 hwif->hw.irq = vals[2];
1931 ide_init_hwif_ports(&hwif->hw, (unsigned long) vals[0], (unsigned long) vals[1], &hwif->irq);
1932 memcpy(hwif->io_ports, hwif->hw.io_ports, sizeof(hwif->io_ports));
1933 hwif->irq = vals[2];
1934 hwif->noprobe = 0;
1935 hwif->chipset = ide_forced;
1936 goto obsolete_option;
1937
1938 case 0: goto bad_option;
1939 default:
1940 printk(" -- SUPPORT NOT CONFIGURED IN THIS KERNEL\n");
1941 return 1;
1942 }
1943 }
1944bad_option:
1945 printk(" -- BAD OPTION\n");
1946 return 1;
1947obsolete_option:
1948 printk(" -- OBSOLETE OPTION, WILL BE REMOVED SOON!\n");
1949 return 1;
1950bad_hwif:
1951 printk("-- NOT SUPPORTED ON ide%d", hw);
1952done:
1953 printk("\n");
1954 return 1;
1955}
1956
1957extern void pnpide_init(void);
1958extern void h8300_ide_init(void);
1959
1960
1961
1962
1963static void __init probe_for_hwifs (void)
1964{
1965#ifdef CONFIG_BLK_DEV_IDEPCI
1966 ide_scan_pcibus(ide_scan_direction);
1967#endif
1968
1969#ifdef CONFIG_ETRAX_IDE
1970 {
1971 extern void init_e100_ide(void);
1972 init_e100_ide();
1973 }
1974#endif
1975#ifdef CONFIG_BLK_DEV_CMD640
1976 {
1977 extern void ide_probe_for_cmd640x(void);
1978 ide_probe_for_cmd640x();
1979 }
1980#endif
1981#ifdef CONFIG_BLK_DEV_IDE_PMAC
1982 {
1983 extern void pmac_ide_probe(void);
1984 pmac_ide_probe();
1985 }
1986#endif
1987#ifdef CONFIG_BLK_DEV_GAYLE
1988 {
1989 extern void gayle_init(void);
1990 gayle_init();
1991 }
1992#endif
1993#ifdef CONFIG_BLK_DEV_FALCON_IDE
1994 {
1995 extern void falconide_init(void);
1996 falconide_init();
1997 }
1998#endif
1999#ifdef CONFIG_BLK_DEV_MAC_IDE
2000 {
2001 extern void macide_init(void);
2002 macide_init();
2003 }
2004#endif
2005#ifdef CONFIG_BLK_DEV_Q40IDE
2006 {
2007 extern void q40ide_init(void);
2008 q40ide_init();
2009 }
2010#endif
2011#ifdef CONFIG_BLK_DEV_BUDDHA
2012 {
2013 extern void buddha_init(void);
2014 buddha_init();
2015 }
2016#endif
2017#ifdef CONFIG_BLK_DEV_IDEPNP
2018 pnpide_init();
2019#endif
2020#ifdef CONFIG_H8300
2021 h8300_ide_init();
2022#endif
2023}
2024
2025static ide_startstop_t default_do_request (ide_drive_t *drive, struct request *rq, sector_t block)
2026{
2027 ide_end_request(drive, 0, 0);
2028 return ide_stopped;
2029}
2030
2031static int default_end_request (ide_drive_t *drive, int uptodate, int nr_sects)
2032{
2033 return ide_end_request(drive, uptodate, nr_sects);
2034}
2035
2036static ide_startstop_t
2037default_error(ide_drive_t *drive, struct request *rq, u8 stat, u8 err)
2038{
2039 return __ide_error(drive, rq, stat, err);
2040}
2041
2042static void default_pre_reset (ide_drive_t *drive)
2043{
2044}
2045
2046static sector_t default_capacity (ide_drive_t *drive)
2047{
2048 return 0x7fffffff;
2049}
2050
2051static ide_startstop_t default_special (ide_drive_t *drive)
2052{
2053 special_t *s = &drive->special;
2054
2055 s->all = 0;
2056 drive->mult_req = 0;
2057 return ide_stopped;
2058}
2059
2060static ide_startstop_t default_abort(ide_drive_t *drive, struct request *rq)
2061{
2062 return __ide_abort(drive, rq);
2063}
2064
2065static ide_startstop_t default_start_power_step(ide_drive_t *drive,
2066 struct request *rq)
2067{
2068 rq->pm->pm_step = ide_pm_state_completed;
2069 return ide_stopped;
2070}
2071
2072static void setup_driver_defaults (ide_driver_t *d)
2073{
2074 BUG_ON(d->attach == NULL || d->cleanup == NULL);
2075
2076 if (d->do_request == NULL) d->do_request = default_do_request;
2077 if (d->end_request == NULL) d->end_request = default_end_request;
2078 if (d->error == NULL) d->error = default_error;
2079 if (d->abort == NULL) d->abort = default_abort;
2080 if (d->pre_reset == NULL) d->pre_reset = default_pre_reset;
2081 if (d->capacity == NULL) d->capacity = default_capacity;
2082 if (d->special == NULL) d->special = default_special;
2083 if (d->start_power_step == NULL)
2084 d->start_power_step = default_start_power_step;
2085}
2086
2087int ide_register_subdriver(ide_drive_t *drive, ide_driver_t *driver)
2088{
2089 unsigned long flags;
2090
2091 BUG_ON(!drive->driver);
2092
2093 spin_lock_irqsave(&ide_lock, flags);
2094 if (!drive->present || drive->driver != &idedefault_driver ||
2095 drive->usage || drive->dead) {
2096 spin_unlock_irqrestore(&ide_lock, flags);
2097 return 1;
2098 }
2099 drive->driver = driver;
2100 spin_unlock_irqrestore(&ide_lock, flags);
2101 spin_lock(&drives_lock);
2102 list_add_tail(&drive->list, &driver->drives);
2103 spin_unlock(&drives_lock);
2104
2105 if ((drive->autotune == IDE_TUNE_DEFAULT) ||
2106 (drive->autotune == IDE_TUNE_AUTO)) {
2107
2108 drive->dsc_overlap = (drive->next != drive && driver->supports_dsc_overlap);
2109 drive->nice1 = 1;
2110 }
2111#ifdef CONFIG_PROC_FS
2112 if (drive->driver != &idedefault_driver) {
2113 ide_add_proc_entries(drive->proc, generic_subdriver_entries, drive);
2114 ide_add_proc_entries(drive->proc, driver->proc, drive);
2115 }
2116#endif
2117 return 0;
2118}
2119
2120EXPORT_SYMBOL(ide_register_subdriver);
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136int ide_unregister_subdriver (ide_drive_t *drive)
2137{
2138 unsigned long flags;
2139
2140 down(&ide_setting_sem);
2141 spin_lock_irqsave(&ide_lock, flags);
2142 if (drive->usage || drive->driver == &idedefault_driver || DRIVER(drive)->busy) {
2143 spin_unlock_irqrestore(&ide_lock, flags);
2144 up(&ide_setting_sem);
2145 return 1;
2146 }
2147#ifdef CONFIG_PROC_FS
2148 ide_remove_proc_entries(drive->proc, DRIVER(drive)->proc);
2149 ide_remove_proc_entries(drive->proc, generic_subdriver_entries);
2150#endif
2151 auto_remove_settings(drive);
2152 drive->driver = &idedefault_driver;
2153 spin_unlock_irqrestore(&ide_lock, flags);
2154 up(&ide_setting_sem);
2155 spin_lock(&drives_lock);
2156 list_del_init(&drive->list);
2157 spin_unlock(&drives_lock);
2158
2159 return 0;
2160}
2161
2162EXPORT_SYMBOL(ide_unregister_subdriver);
2163
2164static int ide_drive_remove(struct device * dev)
2165{
2166 ide_drive_t * drive = container_of(dev,ide_drive_t,gendev);
2167 DRIVER(drive)->cleanup(drive);
2168 return 0;
2169}
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182int ide_register_driver(ide_driver_t *driver)
2183{
2184 struct list_head list;
2185 struct list_head *list_loop;
2186 struct list_head *tmp_storage;
2187
2188 setup_driver_defaults(driver);
2189
2190 spin_lock(&drivers_lock);
2191 list_add(&driver->drivers, &drivers);
2192 spin_unlock(&drivers_lock);
2193
2194 INIT_LIST_HEAD(&list);
2195 spin_lock(&drives_lock);
2196 list_splice_init(&idedefault_driver.drives, &list);
2197 spin_unlock(&drives_lock);
2198
2199 list_for_each_safe(list_loop, tmp_storage, &list) {
2200 ide_drive_t *drive = container_of(list_loop, ide_drive_t, list);
2201 list_del_init(&drive->list);
2202 if (drive->present)
2203 ata_attach(drive);
2204 }
2205 driver->gen_driver.name = (char *) driver->name;
2206 driver->gen_driver.bus = &ide_bus_type;
2207 driver->gen_driver.remove = ide_drive_remove;
2208 return driver_register(&driver->gen_driver);
2209}
2210
2211EXPORT_SYMBOL(ide_register_driver);
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224void ide_unregister_driver(ide_driver_t *driver)
2225{
2226 ide_drive_t *drive;
2227
2228 spin_lock(&drivers_lock);
2229 list_del(&driver->drivers);
2230 spin_unlock(&drivers_lock);
2231
2232 driver_unregister(&driver->gen_driver);
2233
2234 while(!list_empty(&driver->drives)) {
2235 drive = list_entry(driver->drives.next, ide_drive_t, list);
2236 if (driver->cleanup(drive)) {
2237 printk(KERN_ERR "%s: cleanup_module() called while still busy\n", drive->name);
2238 BUG();
2239 }
2240 ata_attach(drive);
2241 }
2242}
2243
2244EXPORT_SYMBOL(ide_unregister_driver);
2245
2246struct block_device_operations ide_fops[] = {{
2247 .owner = THIS_MODULE,
2248 .open = ide_open,
2249}};
2250
2251EXPORT_SYMBOL(ide_fops);
2252
2253
2254
2255
2256
2257EXPORT_SYMBOL(ide_lock);
2258
2259struct bus_type ide_bus_type = {
2260 .name = "ide",
2261 .suspend = generic_ide_suspend,
2262 .resume = generic_ide_resume,
2263};
2264
2265
2266
2267
2268static int __init ide_init(void)
2269{
2270 printk(KERN_INFO "Uniform Multi-Platform E-IDE driver " REVISION "\n");
2271 devfs_mk_dir("ide");
2272 system_bus_speed = ide_system_bus_speed();
2273
2274 bus_register(&ide_bus_type);
2275
2276 init_ide_data();
2277
2278#ifdef CONFIG_PROC_FS
2279 proc_ide_root = proc_mkdir("ide", NULL);
2280#endif
2281
2282#ifdef CONFIG_BLK_DEV_ALI14XX
2283 if (probe_ali14xx)
2284 (void)ali14xx_init();
2285#endif
2286#ifdef CONFIG_BLK_DEV_UMC8672
2287 if (probe_umc8672)
2288 (void)umc8672_init();
2289#endif
2290#ifdef CONFIG_BLK_DEV_DTC2278
2291 if (probe_dtc2278)
2292 (void)dtc2278_init();
2293#endif
2294#ifdef CONFIG_BLK_DEV_HT6560B
2295 if (probe_ht6560b)
2296 (void)ht6560b_init();
2297#endif
2298#ifdef CONFIG_BLK_DEV_QD65XX
2299 if (probe_qd65xx)
2300 (void)qd65xx_init();
2301#endif
2302
2303 initializing = 1;
2304
2305 probe_for_hwifs();
2306 initializing = 0;
2307
2308#ifdef CONFIG_PROC_FS
2309 proc_ide_create();
2310#endif
2311 return 0;
2312}
2313
2314#ifdef MODULE
2315static char *options = NULL;
2316module_param(options, charp, 0);
2317MODULE_LICENSE("GPL");
2318
2319static void __init parse_options (char *line)
2320{
2321 char *next = line;
2322
2323 if (line == NULL || !*line)
2324 return;
2325 while ((line = next) != NULL) {
2326 if ((next = strchr(line,' ')) != NULL)
2327 *next++ = 0;
2328 if (!ide_setup(line))
2329 printk (KERN_INFO "Unknown option '%s'\n", line);
2330 }
2331}
2332
2333int init_module (void)
2334{
2335 parse_options(options);
2336 return ide_init();
2337}
2338
2339void cleanup_module (void)
2340{
2341 int index;
2342
2343 for (index = 0; index < MAX_HWIFS; ++index)
2344 ide_unregister(index);
2345
2346#ifdef CONFIG_PROC_FS
2347 proc_ide_destroy();
2348#endif
2349 devfs_remove("ide");
2350
2351 bus_unregister(&ide_bus_type);
2352}
2353
2354#else
2355
2356__setup("", ide_setup);
2357
2358module_init(ide_init);
2359
2360#endif
2361