]> git.proxmox.com Git - mirror_ubuntu-jammy-kernel.git/blob - drivers/ide/ide.c
c2fb5c964a518cf4b4d52c4a5aaed6a5c2e8ba72
[mirror_ubuntu-jammy-kernel.git] / drivers / ide / ide.c
1 /*
2 * Copyright (C) 1994-1998 Linus Torvalds & authors (see below)
3 * Copyrifht (C) 2003-2005, 2007 Bartlomiej Zolnierkiewicz
4 */
5
6 /*
7 * Mostly written by Mark Lord <mlord@pobox.com>
8 * and Gadi Oxman <gadio@netvision.net.il>
9 * and Andre Hedrick <andre@linux-ide.org>
10 *
11 * See linux/MAINTAINERS for address of current maintainer.
12 *
13 * This is the multiple IDE interface driver, as evolved from hd.c.
14 * It supports up to MAX_HWIFS IDE interfaces, on one or more IRQs
15 * (usually 14 & 15).
16 * There can be up to two drives per interface, as per the ATA-2 spec.
17 *
18 * ...
19 *
20 * From hd.c:
21 * |
22 * | It traverses the request-list, using interrupts to jump between functions.
23 * | As nearly all functions can be called within interrupts, we may not sleep.
24 * | Special care is recommended. Have Fun!
25 * |
26 * | modified by Drew Eckhardt to check nr of hd's from the CMOS.
27 * |
28 * | Thanks to Branko Lankester, lankeste@fwi.uva.nl, who found a bug
29 * | in the early extended-partition checks and added DM partitions.
30 * |
31 * | Early work on error handling by Mika Liljeberg (liljeber@cs.Helsinki.FI).
32 * |
33 * | IRQ-unmask, drive-id, multiple-mode, support for ">16 heads",
34 * | and general streamlining by Mark Lord (mlord@pobox.com).
35 *
36 * October, 1994 -- Complete line-by-line overhaul for linux 1.1.x, by:
37 *
38 * Mark Lord (mlord@pobox.com) (IDE Perf.Pkg)
39 * Delman Lee (delman@ieee.org) ("Mr. atdisk2")
40 * Scott Snyder (snyder@fnald0.fnal.gov) (ATAPI IDE cd-rom)
41 *
42 * This was a rewrite of just about everything from hd.c, though some original
43 * code is still sprinkled about. Think of it as a major evolution, with
44 * inspiration from lots of linux users, esp. hamish@zot.apana.org.au
45 */
46
47 #define _IDE_C /* Tell ide.h it's really us */
48
49 #include <linux/module.h>
50 #include <linux/types.h>
51 #include <linux/string.h>
52 #include <linux/kernel.h>
53 #include <linux/timer.h>
54 #include <linux/mm.h>
55 #include <linux/interrupt.h>
56 #include <linux/major.h>
57 #include <linux/errno.h>
58 #include <linux/genhd.h>
59 #include <linux/blkpg.h>
60 #include <linux/slab.h>
61 #include <linux/init.h>
62 #include <linux/pci.h>
63 #include <linux/delay.h>
64 #include <linux/ide.h>
65 #include <linux/completion.h>
66 #include <linux/reboot.h>
67 #include <linux/cdrom.h>
68 #include <linux/seq_file.h>
69 #include <linux/device.h>
70 #include <linux/bitops.h>
71
72 #include <asm/byteorder.h>
73 #include <asm/irq.h>
74 #include <asm/uaccess.h>
75 #include <asm/io.h>
76
77
78 /* default maximum number of failures */
79 #define IDE_DEFAULT_MAX_FAILURES 1
80
81 struct class *ide_port_class;
82
83 static const u8 ide_hwif_to_major[] = { IDE0_MAJOR, IDE1_MAJOR,
84 IDE2_MAJOR, IDE3_MAJOR,
85 IDE4_MAJOR, IDE5_MAJOR,
86 IDE6_MAJOR, IDE7_MAJOR,
87 IDE8_MAJOR, IDE9_MAJOR };
88
89 static int idebus_parameter; /* holds the "idebus=" parameter */
90 static int system_bus_speed; /* holds what we think is VESA/PCI bus speed */
91
92 DEFINE_MUTEX(ide_cfg_mtx);
93 __cacheline_aligned_in_smp DEFINE_SPINLOCK(ide_lock);
94
95 int noautodma = 0;
96
97 #ifdef CONFIG_BLK_DEV_IDEACPI
98 int ide_noacpi = 0;
99 int ide_noacpitfs = 1;
100 int ide_noacpionboot = 1;
101 #endif
102
103 /*
104 * This is declared extern in ide.h, for access by other IDE modules:
105 */
106 ide_hwif_t ide_hwifs[MAX_HWIFS]; /* master data repository */
107
108 EXPORT_SYMBOL(ide_hwifs);
109
110 static void ide_port_init_devices_data(ide_hwif_t *);
111
112 /*
113 * Do not even *think* about calling this!
114 */
115 void ide_init_port_data(ide_hwif_t *hwif, unsigned int index)
116 {
117 /* bulk initialize hwif & drive info with zeros */
118 memset(hwif, 0, sizeof(ide_hwif_t));
119
120 /* fill in any non-zero initial values */
121 hwif->index = index;
122 hwif->major = ide_hwif_to_major[index];
123
124 hwif->name[0] = 'i';
125 hwif->name[1] = 'd';
126 hwif->name[2] = 'e';
127 hwif->name[3] = '0' + index;
128
129 hwif->bus_state = BUSSTATE_ON;
130
131 init_completion(&hwif->gendev_rel_comp);
132
133 default_hwif_iops(hwif);
134 default_hwif_transport(hwif);
135
136 ide_port_init_devices_data(hwif);
137 }
138 EXPORT_SYMBOL_GPL(ide_init_port_data);
139
140 static void ide_port_init_devices_data(ide_hwif_t *hwif)
141 {
142 int unit;
143
144 for (unit = 0; unit < MAX_DRIVES; ++unit) {
145 ide_drive_t *drive = &hwif->drives[unit];
146 u8 j = (hwif->index * MAX_DRIVES) + unit;
147
148 memset(drive, 0, sizeof(*drive));
149
150 drive->media = ide_disk;
151 drive->select.all = (unit<<4)|0xa0;
152 drive->hwif = hwif;
153 drive->ctl = 0x08;
154 drive->ready_stat = READY_STAT;
155 drive->bad_wstat = BAD_W_STAT;
156 drive->special.b.recalibrate = 1;
157 drive->special.b.set_geometry = 1;
158 drive->name[0] = 'h';
159 drive->name[1] = 'd';
160 drive->name[2] = 'a' + j;
161 drive->max_failures = IDE_DEFAULT_MAX_FAILURES;
162
163 INIT_LIST_HEAD(&drive->list);
164 init_completion(&drive->gendev_rel_comp);
165 }
166 }
167
168
169 /*
170 * init_ide_data() sets reasonable default values into all fields
171 * of all instances of the hwifs and drives, but only on the first call.
172 * Subsequent calls have no effect (they don't wipe out anything).
173 *
174 * This routine is normally called at driver initialization time,
175 * but may also be called MUCH earlier during kernel "command-line"
176 * parameter processing. As such, we cannot depend on any other parts
177 * of the kernel (such as memory allocation) to be functioning yet.
178 *
179 * This is too bad, as otherwise we could dynamically allocate the
180 * ide_drive_t structs as needed, rather than always consuming memory
181 * for the max possible number (MAX_HWIFS * MAX_DRIVES) of them.
182 *
183 * FIXME: We should stuff the setup data into __init and copy the
184 * relevant hwifs/allocate them properly during boot.
185 */
186 #define MAGIC_COOKIE 0x12345678
187 static void __init init_ide_data (void)
188 {
189 unsigned int index;
190 static unsigned long magic_cookie = MAGIC_COOKIE;
191 hw_regs_t hw;
192
193 if (magic_cookie != MAGIC_COOKIE)
194 return; /* already initialized */
195 magic_cookie = 0;
196
197 /* Initialise all interface structures */
198 for (index = 0; index < MAX_HWIFS; ++index) {
199 ide_hwif_t *hwif = &ide_hwifs[index];
200 unsigned long io_addr = ide_default_io_base(index);
201 unsigned long ctl_addr = ide_default_io_ctl(io_addr);
202
203 ide_init_port_data(hwif, index);
204
205 #ifdef CONFIG_IDE_ARCH_OBSOLETE_INIT
206 memset(&hw, 0, sizeof(hw));
207 ide_std_init_ports(&hw, io_addr, ctl_addr);
208 memcpy(hwif->io_ports, hw.io_ports, sizeof(hw.io_ports));
209 #endif
210 hwif->noprobe = !hwif->io_ports[IDE_DATA_OFFSET];
211 #if !defined(CONFIG_PPC32) || defined(CONFIG_PPLUS) || !defined(CONFIG_PCI)
212 hwif->irq =
213 ide_init_default_irq(hwif->io_ports[IDE_DATA_OFFSET]);
214 #endif
215 }
216 }
217
218 /**
219 * ide_system_bus_speed - guess bus speed
220 *
221 * ide_system_bus_speed() returns what we think is the system VESA/PCI
222 * bus speed (in MHz). This is used for calculating interface PIO timings.
223 * The default is 40 for known PCI systems, 50 otherwise.
224 * The "idebus=xx" parameter can be used to override this value.
225 * The actual value to be used is computed/displayed the first time
226 * through. Drivers should only use this as a last resort.
227 *
228 * Returns a guessed speed in MHz.
229 */
230
231 static int ide_system_bus_speed(void)
232 {
233 #ifdef CONFIG_PCI
234 static struct pci_device_id pci_default[] = {
235 { PCI_DEVICE(PCI_ANY_ID, PCI_ANY_ID) },
236 { }
237 };
238 #else
239 #define pci_default 0
240 #endif /* CONFIG_PCI */
241
242 /* user supplied value */
243 if (idebus_parameter)
244 return idebus_parameter;
245
246 /* safe default value for PCI or VESA and PCI*/
247 return pci_dev_present(pci_default) ? 33 : 50;
248 }
249
250 ide_hwif_t * ide_find_port(unsigned long base)
251 {
252 ide_hwif_t *hwif;
253 int i;
254
255 for (i = 0; i < MAX_HWIFS; i++) {
256 hwif = &ide_hwifs[i];
257 if (hwif->io_ports[IDE_DATA_OFFSET] == base)
258 goto found;
259 }
260
261 for (i = 0; i < MAX_HWIFS; i++) {
262 hwif = &ide_hwifs[i];
263 if (hwif->chipset == ide_unknown)
264 goto found;
265 }
266
267 hwif = NULL;
268 found:
269 return hwif;
270 }
271
272 EXPORT_SYMBOL_GPL(ide_find_port);
273
274 static struct resource* hwif_request_region(ide_hwif_t *hwif,
275 unsigned long addr, int num)
276 {
277 struct resource *res = request_region(addr, num, hwif->name);
278
279 if (!res)
280 printk(KERN_ERR "%s: I/O resource 0x%lX-0x%lX not free.\n",
281 hwif->name, addr, addr+num-1);
282 return res;
283 }
284
285 /**
286 * ide_hwif_request_regions - request resources for IDE
287 * @hwif: interface to use
288 *
289 * Requests all the needed resources for an interface.
290 * Right now core IDE code does this work which is deeply wrong.
291 * MMIO leaves it to the controller driver,
292 * PIO will migrate this way over time.
293 */
294
295 int ide_hwif_request_regions(ide_hwif_t *hwif)
296 {
297 unsigned long addr;
298 unsigned int i;
299
300 if (hwif->mmio)
301 return 0;
302 addr = hwif->io_ports[IDE_CONTROL_OFFSET];
303 if (addr && !hwif_request_region(hwif, addr, 1))
304 goto control_region_busy;
305 hwif->straight8 = 0;
306 addr = hwif->io_ports[IDE_DATA_OFFSET];
307 if ((addr | 7) == hwif->io_ports[IDE_STATUS_OFFSET]) {
308 if (!hwif_request_region(hwif, addr, 8))
309 goto data_region_busy;
310 hwif->straight8 = 1;
311 return 0;
312 }
313 for (i = IDE_DATA_OFFSET; i <= IDE_STATUS_OFFSET; i++) {
314 addr = hwif->io_ports[i];
315 if (!hwif_request_region(hwif, addr, 1)) {
316 while (--i)
317 release_region(addr, 1);
318 goto data_region_busy;
319 }
320 }
321 return 0;
322
323 data_region_busy:
324 addr = hwif->io_ports[IDE_CONTROL_OFFSET];
325 if (addr)
326 release_region(addr, 1);
327 control_region_busy:
328 /* If any errors are return, we drop the hwif interface. */
329 return -EBUSY;
330 }
331
332 /**
333 * ide_hwif_release_regions - free IDE resources
334 *
335 * Note that we only release the standard ports,
336 * and do not even try to handle any extra ports
337 * allocated for weird IDE interface chipsets.
338 *
339 * Note also that we don't yet handle mmio resources here. More
340 * importantly our caller should be doing this so we need to
341 * restructure this as a helper function for drivers.
342 */
343
344 void ide_hwif_release_regions(ide_hwif_t *hwif)
345 {
346 u32 i = 0;
347
348 if (hwif->mmio)
349 return;
350 if (hwif->io_ports[IDE_CONTROL_OFFSET])
351 release_region(hwif->io_ports[IDE_CONTROL_OFFSET], 1);
352 if (hwif->straight8) {
353 release_region(hwif->io_ports[IDE_DATA_OFFSET], 8);
354 return;
355 }
356 for (i = IDE_DATA_OFFSET; i <= IDE_STATUS_OFFSET; i++)
357 if (hwif->io_ports[i])
358 release_region(hwif->io_ports[i], 1);
359 }
360
361 void ide_remove_port_from_hwgroup(ide_hwif_t *hwif)
362 {
363 ide_hwgroup_t *hwgroup = hwif->hwgroup;
364
365 spin_lock_irq(&ide_lock);
366 /*
367 * Remove us from the hwgroup, and free
368 * the hwgroup if we were the only member
369 */
370 if (hwif->next == hwif) {
371 BUG_ON(hwgroup->hwif != hwif);
372 kfree(hwgroup);
373 } else {
374 /* There is another interface in hwgroup.
375 * Unlink us, and set hwgroup->drive and ->hwif to
376 * something sane.
377 */
378 ide_hwif_t *g = hwgroup->hwif;
379
380 while (g->next != hwif)
381 g = g->next;
382 g->next = hwif->next;
383 if (hwgroup->hwif == hwif) {
384 /* Chose a random hwif for hwgroup->hwif.
385 * It's guaranteed that there are no drives
386 * left in the hwgroup.
387 */
388 BUG_ON(hwgroup->drive != NULL);
389 hwgroup->hwif = g;
390 }
391 BUG_ON(hwgroup->hwif == hwif);
392 }
393 spin_unlock_irq(&ide_lock);
394 }
395
396 /* Called with ide_lock held. */
397 static void __ide_port_unregister_devices(ide_hwif_t *hwif)
398 {
399 int i;
400
401 for (i = 0; i < MAX_DRIVES; i++) {
402 ide_drive_t *drive = &hwif->drives[i];
403
404 if (drive->present) {
405 spin_unlock_irq(&ide_lock);
406 device_unregister(&drive->gendev);
407 wait_for_completion(&drive->gendev_rel_comp);
408 spin_lock_irq(&ide_lock);
409 }
410 }
411 }
412
413 void ide_port_unregister_devices(ide_hwif_t *hwif)
414 {
415 mutex_lock(&ide_cfg_mtx);
416 spin_lock_irq(&ide_lock);
417 __ide_port_unregister_devices(hwif);
418 hwif->present = 0;
419 ide_port_init_devices_data(hwif);
420 spin_unlock_irq(&ide_lock);
421 mutex_unlock(&ide_cfg_mtx);
422 }
423 EXPORT_SYMBOL_GPL(ide_port_unregister_devices);
424
425 /**
426 * ide_unregister - free an IDE interface
427 * @index: index of interface (will change soon to a pointer)
428 *
429 * Perform the final unregister of an IDE interface. At the moment
430 * we don't refcount interfaces so this will also get split up.
431 *
432 * Locking:
433 * The caller must not hold the IDE locks
434 * The drive present/vanishing is not yet properly locked
435 * Take care with the callbacks. These have been split to avoid
436 * deadlocking the IDE layer. The shutdown callback is called
437 * before we take the lock and free resources. It is up to the
438 * caller to be sure there is no pending I/O here, and that
439 * the interface will not be reopened (present/vanishing locking
440 * isn't yet done BTW). After we commit to the final kill we
441 * call the cleanup callback with the ide locks held.
442 *
443 * Unregister restores the hwif structures to the default state.
444 * This is raving bonkers.
445 */
446
447 void ide_unregister(unsigned int index)
448 {
449 ide_hwif_t *hwif, *g;
450 ide_hwgroup_t *hwgroup;
451 int irq_count = 0;
452
453 BUG_ON(index >= MAX_HWIFS);
454
455 BUG_ON(in_interrupt());
456 BUG_ON(irqs_disabled());
457 mutex_lock(&ide_cfg_mtx);
458 spin_lock_irq(&ide_lock);
459 hwif = &ide_hwifs[index];
460 if (!hwif->present)
461 goto abort;
462 __ide_port_unregister_devices(hwif);
463 hwif->present = 0;
464
465 spin_unlock_irq(&ide_lock);
466
467 ide_proc_unregister_port(hwif);
468
469 hwgroup = hwif->hwgroup;
470 /*
471 * free the irq if we were the only hwif using it
472 */
473 g = hwgroup->hwif;
474 do {
475 if (g->irq == hwif->irq)
476 ++irq_count;
477 g = g->next;
478 } while (g != hwgroup->hwif);
479 if (irq_count == 1)
480 free_irq(hwif->irq, hwgroup);
481
482 ide_remove_port_from_hwgroup(hwif);
483
484 device_unregister(hwif->portdev);
485 device_unregister(&hwif->gendev);
486 wait_for_completion(&hwif->gendev_rel_comp);
487
488 /*
489 * Remove us from the kernel's knowledge
490 */
491 blk_unregister_region(MKDEV(hwif->major, 0), MAX_DRIVES<<PARTN_BITS);
492 kfree(hwif->sg_table);
493 unregister_blkdev(hwif->major, hwif->name);
494 spin_lock_irq(&ide_lock);
495
496 if (hwif->dma_base)
497 (void)ide_release_dma(hwif);
498
499 ide_hwif_release_regions(hwif);
500
501 /* restore hwif data to pristine status */
502 ide_init_port_data(hwif, index);
503
504 abort:
505 spin_unlock_irq(&ide_lock);
506 mutex_unlock(&ide_cfg_mtx);
507 }
508
509 EXPORT_SYMBOL(ide_unregister);
510
511 void ide_init_port_hw(ide_hwif_t *hwif, hw_regs_t *hw)
512 {
513 memcpy(hwif->io_ports, hw->io_ports, sizeof(hwif->io_ports));
514 hwif->irq = hw->irq;
515 hwif->noprobe = 0;
516 hwif->chipset = hw->chipset;
517 hwif->gendev.parent = hw->dev;
518 hwif->ack_intr = hw->ack_intr;
519 }
520 EXPORT_SYMBOL_GPL(ide_init_port_hw);
521
522 /*
523 * Locks for IDE setting functionality
524 */
525
526 DEFINE_MUTEX(ide_setting_mtx);
527
528 EXPORT_SYMBOL_GPL(ide_setting_mtx);
529
530 /**
531 * ide_spin_wait_hwgroup - wait for group
532 * @drive: drive in the group
533 *
534 * Wait for an IDE device group to go non busy and then return
535 * holding the ide_lock which guards the hwgroup->busy status
536 * and right to use it.
537 */
538
539 int ide_spin_wait_hwgroup (ide_drive_t *drive)
540 {
541 ide_hwgroup_t *hwgroup = HWGROUP(drive);
542 unsigned long timeout = jiffies + (3 * HZ);
543
544 spin_lock_irq(&ide_lock);
545
546 while (hwgroup->busy) {
547 unsigned long lflags;
548 spin_unlock_irq(&ide_lock);
549 local_irq_set(lflags);
550 if (time_after(jiffies, timeout)) {
551 local_irq_restore(lflags);
552 printk(KERN_ERR "%s: channel busy\n", drive->name);
553 return -EBUSY;
554 }
555 local_irq_restore(lflags);
556 spin_lock_irq(&ide_lock);
557 }
558 return 0;
559 }
560
561 EXPORT_SYMBOL(ide_spin_wait_hwgroup);
562
563 int set_io_32bit(ide_drive_t *drive, int arg)
564 {
565 if (drive->no_io_32bit)
566 return -EPERM;
567
568 if (arg < 0 || arg > 1 + (SUPPORT_VLB_SYNC << 1))
569 return -EINVAL;
570
571 if (ide_spin_wait_hwgroup(drive))
572 return -EBUSY;
573
574 drive->io_32bit = arg;
575
576 spin_unlock_irq(&ide_lock);
577
578 return 0;
579 }
580
581 static int set_ksettings(ide_drive_t *drive, int arg)
582 {
583 if (arg < 0 || arg > 1)
584 return -EINVAL;
585
586 if (ide_spin_wait_hwgroup(drive))
587 return -EBUSY;
588 drive->keep_settings = arg;
589 spin_unlock_irq(&ide_lock);
590
591 return 0;
592 }
593
594 int set_using_dma(ide_drive_t *drive, int arg)
595 {
596 #ifdef CONFIG_BLK_DEV_IDEDMA
597 ide_hwif_t *hwif = drive->hwif;
598 int err = -EPERM;
599
600 if (arg < 0 || arg > 1)
601 return -EINVAL;
602
603 if (!drive->id || !(drive->id->capability & 1))
604 goto out;
605
606 if (hwif->dma_host_set == NULL)
607 goto out;
608
609 err = -EBUSY;
610 if (ide_spin_wait_hwgroup(drive))
611 goto out;
612 /*
613 * set ->busy flag, unlock and let it ride
614 */
615 hwif->hwgroup->busy = 1;
616 spin_unlock_irq(&ide_lock);
617
618 err = 0;
619
620 if (arg) {
621 if (ide_set_dma(drive))
622 err = -EIO;
623 } else
624 ide_dma_off(drive);
625
626 /*
627 * lock, clear ->busy flag and unlock before leaving
628 */
629 spin_lock_irq(&ide_lock);
630 hwif->hwgroup->busy = 0;
631 spin_unlock_irq(&ide_lock);
632 out:
633 return err;
634 #else
635 if (arg < 0 || arg > 1)
636 return -EINVAL;
637
638 return -EPERM;
639 #endif
640 }
641
642 int set_pio_mode(ide_drive_t *drive, int arg)
643 {
644 struct request rq;
645
646 if (arg < 0 || arg > 255)
647 return -EINVAL;
648
649 if (drive->hwif->set_pio_mode == NULL)
650 return -ENOSYS;
651
652 if (drive->special.b.set_tune)
653 return -EBUSY;
654
655 ide_init_drive_cmd(&rq);
656 rq.cmd_type = REQ_TYPE_ATA_TASKFILE;
657
658 drive->tune_req = (u8) arg;
659 drive->special.b.set_tune = 1;
660 (void) ide_do_drive_cmd(drive, &rq, ide_wait);
661 return 0;
662 }
663
664 static int set_unmaskirq(ide_drive_t *drive, int arg)
665 {
666 if (drive->no_unmask)
667 return -EPERM;
668
669 if (arg < 0 || arg > 1)
670 return -EINVAL;
671
672 if (ide_spin_wait_hwgroup(drive))
673 return -EBUSY;
674 drive->unmask = arg;
675 spin_unlock_irq(&ide_lock);
676
677 return 0;
678 }
679
680 /**
681 * system_bus_clock - clock guess
682 *
683 * External version of the bus clock guess used by very old IDE drivers
684 * for things like VLB timings. Should not be used.
685 */
686
687 int system_bus_clock (void)
688 {
689 return system_bus_speed;
690 }
691
692 EXPORT_SYMBOL(system_bus_clock);
693
694 static int generic_ide_suspend(struct device *dev, pm_message_t mesg)
695 {
696 ide_drive_t *drive = dev->driver_data;
697 ide_hwif_t *hwif = HWIF(drive);
698 struct request rq;
699 struct request_pm_state rqpm;
700 ide_task_t args;
701 int ret;
702
703 /* Call ACPI _GTM only once */
704 if (!(drive->dn % 2))
705 ide_acpi_get_timing(hwif);
706
707 memset(&rq, 0, sizeof(rq));
708 memset(&rqpm, 0, sizeof(rqpm));
709 memset(&args, 0, sizeof(args));
710 rq.cmd_type = REQ_TYPE_PM_SUSPEND;
711 rq.special = &args;
712 rq.data = &rqpm;
713 rqpm.pm_step = ide_pm_state_start_suspend;
714 if (mesg.event == PM_EVENT_PRETHAW)
715 mesg.event = PM_EVENT_FREEZE;
716 rqpm.pm_state = mesg.event;
717
718 ret = ide_do_drive_cmd(drive, &rq, ide_wait);
719 /* only call ACPI _PS3 after both drivers are suspended */
720 if (!ret && (((drive->dn % 2) && hwif->drives[0].present
721 && hwif->drives[1].present)
722 || !hwif->drives[0].present
723 || !hwif->drives[1].present))
724 ide_acpi_set_state(hwif, 0);
725 return ret;
726 }
727
728 static int generic_ide_resume(struct device *dev)
729 {
730 ide_drive_t *drive = dev->driver_data;
731 ide_hwif_t *hwif = HWIF(drive);
732 struct request rq;
733 struct request_pm_state rqpm;
734 ide_task_t args;
735 int err;
736
737 /* Call ACPI _STM only once */
738 if (!(drive->dn % 2)) {
739 ide_acpi_set_state(hwif, 1);
740 ide_acpi_push_timing(hwif);
741 }
742
743 ide_acpi_exec_tfs(drive);
744
745 memset(&rq, 0, sizeof(rq));
746 memset(&rqpm, 0, sizeof(rqpm));
747 memset(&args, 0, sizeof(args));
748 rq.cmd_type = REQ_TYPE_PM_RESUME;
749 rq.special = &args;
750 rq.data = &rqpm;
751 rqpm.pm_step = ide_pm_state_start_resume;
752 rqpm.pm_state = PM_EVENT_ON;
753
754 err = ide_do_drive_cmd(drive, &rq, ide_head_wait);
755
756 if (err == 0 && dev->driver) {
757 ide_driver_t *drv = to_ide_driver(dev->driver);
758
759 if (drv->resume)
760 drv->resume(drive);
761 }
762
763 return err;
764 }
765
766 int generic_ide_ioctl(ide_drive_t *drive, struct file *file, struct block_device *bdev,
767 unsigned int cmd, unsigned long arg)
768 {
769 unsigned long flags;
770 ide_driver_t *drv;
771 void __user *p = (void __user *)arg;
772 int err = 0, (*setfunc)(ide_drive_t *, int);
773 u8 *val;
774
775 switch (cmd) {
776 case HDIO_GET_32BIT: val = &drive->io_32bit; goto read_val;
777 case HDIO_GET_KEEPSETTINGS: val = &drive->keep_settings; goto read_val;
778 case HDIO_GET_UNMASKINTR: val = &drive->unmask; goto read_val;
779 case HDIO_GET_DMA: val = &drive->using_dma; goto read_val;
780 case HDIO_SET_32BIT: setfunc = set_io_32bit; goto set_val;
781 case HDIO_SET_KEEPSETTINGS: setfunc = set_ksettings; goto set_val;
782 case HDIO_SET_PIO_MODE: setfunc = set_pio_mode; goto set_val;
783 case HDIO_SET_UNMASKINTR: setfunc = set_unmaskirq; goto set_val;
784 case HDIO_SET_DMA: setfunc = set_using_dma; goto set_val;
785 }
786
787 switch (cmd) {
788 case HDIO_OBSOLETE_IDENTITY:
789 case HDIO_GET_IDENTITY:
790 if (bdev != bdev->bd_contains)
791 return -EINVAL;
792 if (drive->id_read == 0)
793 return -ENOMSG;
794 if (copy_to_user(p, drive->id, (cmd == HDIO_GET_IDENTITY) ? sizeof(*drive->id) : 142))
795 return -EFAULT;
796 return 0;
797
798 case HDIO_GET_NICE:
799 return put_user(drive->dsc_overlap << IDE_NICE_DSC_OVERLAP |
800 drive->atapi_overlap << IDE_NICE_ATAPI_OVERLAP |
801 drive->nice1 << IDE_NICE_1,
802 (long __user *) arg);
803 #ifdef CONFIG_IDE_TASK_IOCTL
804 case HDIO_DRIVE_TASKFILE:
805 if (!capable(CAP_SYS_ADMIN) || !capable(CAP_SYS_RAWIO))
806 return -EACCES;
807 switch(drive->media) {
808 case ide_disk:
809 return ide_taskfile_ioctl(drive, cmd, arg);
810 default:
811 return -ENOMSG;
812 }
813 #endif /* CONFIG_IDE_TASK_IOCTL */
814
815 case HDIO_DRIVE_CMD:
816 if (!capable(CAP_SYS_RAWIO))
817 return -EACCES;
818 return ide_cmd_ioctl(drive, cmd, arg);
819
820 case HDIO_DRIVE_TASK:
821 if (!capable(CAP_SYS_RAWIO))
822 return -EACCES;
823 return ide_task_ioctl(drive, cmd, arg);
824 case HDIO_SET_NICE:
825 if (!capable(CAP_SYS_ADMIN)) return -EACCES;
826 if (arg != (arg & ((1 << IDE_NICE_DSC_OVERLAP) | (1 << IDE_NICE_1))))
827 return -EPERM;
828 drive->dsc_overlap = (arg >> IDE_NICE_DSC_OVERLAP) & 1;
829 drv = *(ide_driver_t **)bdev->bd_disk->private_data;
830 if (drive->dsc_overlap && !drv->supports_dsc_overlap) {
831 drive->dsc_overlap = 0;
832 return -EPERM;
833 }
834 drive->nice1 = (arg >> IDE_NICE_1) & 1;
835 return 0;
836 case HDIO_DRIVE_RESET:
837 if (!capable(CAP_SYS_ADMIN))
838 return -EACCES;
839
840 /*
841 * Abort the current command on the
842 * group if there is one, taking
843 * care not to allow anything else
844 * to be queued and to die on the
845 * spot if we miss one somehow
846 */
847
848 spin_lock_irqsave(&ide_lock, flags);
849
850 if (HWGROUP(drive)->resetting) {
851 spin_unlock_irqrestore(&ide_lock, flags);
852 return -EBUSY;
853 }
854
855 ide_abort(drive, "drive reset");
856
857 BUG_ON(HWGROUP(drive)->handler);
858
859 /* Ensure nothing gets queued after we
860 drop the lock. Reset will clear the busy */
861
862 HWGROUP(drive)->busy = 1;
863 spin_unlock_irqrestore(&ide_lock, flags);
864 (void) ide_do_reset(drive);
865
866 return 0;
867 case HDIO_GET_BUSSTATE:
868 if (!capable(CAP_SYS_ADMIN))
869 return -EACCES;
870 if (put_user(HWIF(drive)->bus_state, (long __user *)arg))
871 return -EFAULT;
872 return 0;
873
874 case HDIO_SET_BUSSTATE:
875 if (!capable(CAP_SYS_ADMIN))
876 return -EACCES;
877 return -EOPNOTSUPP;
878 default:
879 return -EINVAL;
880 }
881
882 read_val:
883 mutex_lock(&ide_setting_mtx);
884 spin_lock_irqsave(&ide_lock, flags);
885 err = *val;
886 spin_unlock_irqrestore(&ide_lock, flags);
887 mutex_unlock(&ide_setting_mtx);
888 return err >= 0 ? put_user(err, (long __user *)arg) : err;
889
890 set_val:
891 if (bdev != bdev->bd_contains)
892 err = -EINVAL;
893 else {
894 if (!capable(CAP_SYS_ADMIN))
895 err = -EACCES;
896 else {
897 mutex_lock(&ide_setting_mtx);
898 err = setfunc(drive, arg);
899 mutex_unlock(&ide_setting_mtx);
900 }
901 }
902 return err;
903 }
904
905 EXPORT_SYMBOL(generic_ide_ioctl);
906
907 /*
908 * stridx() returns the offset of c within s,
909 * or -1 if c is '\0' or not found within s.
910 */
911 static int __init stridx (const char *s, char c)
912 {
913 char *i = strchr(s, c);
914 return (i && c) ? i - s : -1;
915 }
916
917 /*
918 * match_parm() does parsing for ide_setup():
919 *
920 * 1. the first char of s must be '='.
921 * 2. if the remainder matches one of the supplied keywords,
922 * the index (1 based) of the keyword is negated and returned.
923 * 3. if the remainder is a series of no more than max_vals numbers
924 * separated by commas, the numbers are saved in vals[] and a
925 * count of how many were saved is returned. Base10 is assumed,
926 * and base16 is allowed when prefixed with "0x".
927 * 4. otherwise, zero is returned.
928 */
929 static int __init match_parm (char *s, const char *keywords[], int vals[], int max_vals)
930 {
931 static const char *decimal = "0123456789";
932 static const char *hex = "0123456789abcdef";
933 int i, n;
934
935 if (*s++ == '=') {
936 /*
937 * Try matching against the supplied keywords,
938 * and return -(index+1) if we match one
939 */
940 if (keywords != NULL) {
941 for (i = 0; *keywords != NULL; ++i) {
942 if (!strcmp(s, *keywords++))
943 return -(i+1);
944 }
945 }
946 /*
947 * Look for a series of no more than "max_vals"
948 * numeric values separated by commas, in base10,
949 * or base16 when prefixed with "0x".
950 * Return a count of how many were found.
951 */
952 for (n = 0; (i = stridx(decimal, *s)) >= 0;) {
953 vals[n] = i;
954 while ((i = stridx(decimal, *++s)) >= 0)
955 vals[n] = (vals[n] * 10) + i;
956 if (*s == 'x' && !vals[n]) {
957 while ((i = stridx(hex, *++s)) >= 0)
958 vals[n] = (vals[n] * 0x10) + i;
959 }
960 if (++n == max_vals)
961 break;
962 if (*s == ',' || *s == ';')
963 ++s;
964 }
965 if (!*s)
966 return n;
967 }
968 return 0; /* zero = nothing matched */
969 }
970
971 extern int probe_ali14xx;
972 extern int probe_umc8672;
973 extern int probe_dtc2278;
974 extern int probe_ht6560b;
975 extern int probe_qd65xx;
976 extern int cmd640_vlb;
977
978 static int __initdata is_chipset_set;
979
980 /*
981 * ide_setup() gets called VERY EARLY during initialization,
982 * to handle kernel "command line" strings beginning with "hdx=" or "ide".
983 *
984 * Remember to update Documentation/ide/ide.txt if you change something here.
985 */
986 static int __init ide_setup(char *s)
987 {
988 int i, vals[3];
989 ide_hwif_t *hwif;
990 ide_drive_t *drive;
991 unsigned int hw, unit;
992 const char max_drive = 'a' + ((MAX_HWIFS * MAX_DRIVES) - 1);
993 const char max_hwif = '0' + (MAX_HWIFS - 1);
994
995
996 if (strncmp(s,"hd",2) == 0 && s[2] == '=') /* hd= is for hd.c */
997 return 0; /* driver and not us */
998
999 if (strncmp(s,"ide",3) && strncmp(s,"idebus",6) && strncmp(s,"hd",2))
1000 return 0;
1001
1002 printk(KERN_INFO "ide_setup: %s", s);
1003 init_ide_data ();
1004
1005 #ifdef CONFIG_BLK_DEV_IDEDOUBLER
1006 if (!strcmp(s, "ide=doubler")) {
1007 extern int ide_doubler;
1008
1009 printk(" : Enabled support for IDE doublers\n");
1010 ide_doubler = 1;
1011 return 1;
1012 }
1013 #endif /* CONFIG_BLK_DEV_IDEDOUBLER */
1014
1015 if (!strcmp(s, "ide=nodma")) {
1016 printk(" : Prevented DMA\n");
1017 noautodma = 1;
1018 goto obsolete_option;
1019 }
1020
1021 #ifdef CONFIG_BLK_DEV_IDEACPI
1022 if (!strcmp(s, "ide=noacpi")) {
1023 //printk(" : Disable IDE ACPI support.\n");
1024 ide_noacpi = 1;
1025 return 1;
1026 }
1027 if (!strcmp(s, "ide=acpigtf")) {
1028 //printk(" : Enable IDE ACPI _GTF support.\n");
1029 ide_noacpitfs = 0;
1030 return 1;
1031 }
1032 if (!strcmp(s, "ide=acpionboot")) {
1033 //printk(" : Call IDE ACPI methods on boot.\n");
1034 ide_noacpionboot = 0;
1035 return 1;
1036 }
1037 #endif /* CONFIG_BLK_DEV_IDEACPI */
1038
1039 /*
1040 * Look for drive options: "hdx="
1041 */
1042 if (s[0] == 'h' && s[1] == 'd' && s[2] >= 'a' && s[2] <= max_drive) {
1043 const char *hd_words[] = {
1044 "none", "noprobe", "nowerr", "cdrom", "nodma",
1045 "autotune", "noautotune", "-8", "-9", "-10",
1046 "noflush", "remap", "remap63", "scsi", NULL };
1047 unit = s[2] - 'a';
1048 hw = unit / MAX_DRIVES;
1049 unit = unit % MAX_DRIVES;
1050 hwif = &ide_hwifs[hw];
1051 drive = &hwif->drives[unit];
1052 if (strncmp(s + 4, "ide-", 4) == 0) {
1053 strlcpy(drive->driver_req, s + 4, sizeof(drive->driver_req));
1054 goto obsolete_option;
1055 }
1056 switch (match_parm(&s[3], hd_words, vals, 3)) {
1057 case -1: /* "none" */
1058 case -2: /* "noprobe" */
1059 drive->noprobe = 1;
1060 goto done;
1061 case -3: /* "nowerr" */
1062 drive->bad_wstat = BAD_R_STAT;
1063 hwif->noprobe = 0;
1064 goto done;
1065 case -4: /* "cdrom" */
1066 drive->present = 1;
1067 drive->media = ide_cdrom;
1068 /* an ATAPI device ignores DRDY */
1069 drive->ready_stat = 0;
1070 hwif->noprobe = 0;
1071 goto done;
1072 case -5: /* nodma */
1073 drive->nodma = 1;
1074 goto done;
1075 case -6: /* "autotune" */
1076 drive->autotune = IDE_TUNE_AUTO;
1077 goto obsolete_option;
1078 case -7: /* "noautotune" */
1079 drive->autotune = IDE_TUNE_NOAUTO;
1080 goto obsolete_option;
1081 case -11: /* noflush */
1082 drive->noflush = 1;
1083 goto done;
1084 case -12: /* "remap" */
1085 drive->remap_0_to_1 = 1;
1086 goto obsolete_option;
1087 case -13: /* "remap63" */
1088 drive->sect0 = 63;
1089 goto obsolete_option;
1090 case -14: /* "scsi" */
1091 drive->scsi = 1;
1092 goto obsolete_option;
1093 case 3: /* cyl,head,sect */
1094 drive->media = ide_disk;
1095 drive->ready_stat = READY_STAT;
1096 drive->cyl = drive->bios_cyl = vals[0];
1097 drive->head = drive->bios_head = vals[1];
1098 drive->sect = drive->bios_sect = vals[2];
1099 drive->present = 1;
1100 drive->forced_geom = 1;
1101 hwif->noprobe = 0;
1102 goto done;
1103 default:
1104 goto bad_option;
1105 }
1106 }
1107
1108 if (s[0] != 'i' || s[1] != 'd' || s[2] != 'e')
1109 goto bad_option;
1110 /*
1111 * Look for bus speed option: "idebus="
1112 */
1113 if (s[3] == 'b' && s[4] == 'u' && s[5] == 's') {
1114 if (match_parm(&s[6], NULL, vals, 1) != 1)
1115 goto bad_option;
1116 if (vals[0] >= 20 && vals[0] <= 66) {
1117 idebus_parameter = vals[0];
1118 } else
1119 printk(" -- BAD BUS SPEED! Expected value from 20 to 66");
1120 goto done;
1121 }
1122 /*
1123 * Look for interface options: "idex="
1124 */
1125 if (s[3] >= '0' && s[3] <= max_hwif) {
1126 /*
1127 * Be VERY CAREFUL changing this: note hardcoded indexes below
1128 * (-8, -9, -10) are reserved to ease the hardcoding.
1129 */
1130 static const char *ide_words[] = {
1131 "noprobe", "serialize", "minus3", "minus4",
1132 "reset", "minus6", "ata66", "minus8", "minus9",
1133 "minus10", "four", "qd65xx", "ht6560b", "cmd640_vlb",
1134 "dtc2278", "umc8672", "ali14xx", NULL };
1135
1136 hw = s[3] - '0';
1137 hwif = &ide_hwifs[hw];
1138 i = match_parm(&s[4], ide_words, vals, 3);
1139
1140 /*
1141 * Cryptic check to ensure chipset not already set for hwif.
1142 * Note: we can't depend on hwif->chipset here.
1143 */
1144 if (i >= -18 && i <= -11) {
1145 /* chipset already specified */
1146 if (is_chipset_set)
1147 goto bad_option;
1148 /* these drivers are for "ide0=" only */
1149 if (hw != 0)
1150 goto bad_hwif;
1151 is_chipset_set = 1;
1152 printk("\n");
1153 }
1154
1155 switch (i) {
1156 #ifdef CONFIG_BLK_DEV_ALI14XX
1157 case -17: /* "ali14xx" */
1158 probe_ali14xx = 1;
1159 goto obsolete_option;
1160 #endif
1161 #ifdef CONFIG_BLK_DEV_UMC8672
1162 case -16: /* "umc8672" */
1163 probe_umc8672 = 1;
1164 goto obsolete_option;
1165 #endif
1166 #ifdef CONFIG_BLK_DEV_DTC2278
1167 case -15: /* "dtc2278" */
1168 probe_dtc2278 = 1;
1169 goto obsolete_option;
1170 #endif
1171 #ifdef CONFIG_BLK_DEV_CMD640
1172 case -14: /* "cmd640_vlb" */
1173 cmd640_vlb = 1;
1174 goto obsolete_option;
1175 #endif
1176 #ifdef CONFIG_BLK_DEV_HT6560B
1177 case -13: /* "ht6560b" */
1178 probe_ht6560b = 1;
1179 goto obsolete_option;
1180 #endif
1181 #ifdef CONFIG_BLK_DEV_QD65XX
1182 case -12: /* "qd65xx" */
1183 probe_qd65xx = 1;
1184 goto obsolete_option;
1185 #endif
1186 #ifdef CONFIG_BLK_DEV_4DRIVES
1187 case -11: /* "four" drives on one set of ports */
1188 {
1189 ide_hwif_t *mate = &ide_hwifs[hw^1];
1190 mate->drives[0].select.all ^= 0x20;
1191 mate->drives[1].select.all ^= 0x20;
1192 hwif->chipset = mate->chipset = ide_4drives;
1193 mate->irq = hwif->irq;
1194 memcpy(mate->io_ports, hwif->io_ports, sizeof(hwif->io_ports));
1195 hwif->mate = mate;
1196 mate->mate = hwif;
1197 hwif->serialized = mate->serialized = 1;
1198 goto obsolete_option;
1199 }
1200 #endif /* CONFIG_BLK_DEV_4DRIVES */
1201 case -10: /* minus10 */
1202 case -9: /* minus9 */
1203 case -8: /* minus8 */
1204 case -6:
1205 case -4:
1206 case -3:
1207 goto bad_option;
1208 case -7: /* ata66 */
1209 #ifdef CONFIG_BLK_DEV_IDEPCI
1210 /*
1211 * Use ATA_CBL_PATA40_SHORT so drive side
1212 * cable detection is also overriden.
1213 */
1214 hwif->cbl = ATA_CBL_PATA40_SHORT;
1215 goto obsolete_option;
1216 #else
1217 goto bad_hwif;
1218 #endif
1219 case -5: /* "reset" */
1220 hwif->reset = 1;
1221 goto obsolete_option;
1222 case -2: /* "serialize" */
1223 hwif->mate = &ide_hwifs[hw^1];
1224 hwif->mate->mate = hwif;
1225 hwif->serialized = hwif->mate->serialized = 1;
1226 goto obsolete_option;
1227
1228 case -1: /* "noprobe" */
1229 hwif->noprobe = 1;
1230 goto obsolete_option;
1231 case 0:
1232 case 1:
1233 case 2:
1234 case 3:
1235 goto bad_option;
1236 default:
1237 printk(" -- SUPPORT NOT CONFIGURED IN THIS KERNEL\n");
1238 return 1;
1239 }
1240 }
1241 bad_option:
1242 printk(" -- BAD OPTION\n");
1243 return 1;
1244 obsolete_option:
1245 printk(" -- OBSOLETE OPTION, WILL BE REMOVED SOON!\n");
1246 return 1;
1247 bad_hwif:
1248 printk("-- NOT SUPPORTED ON ide%d", hw);
1249 done:
1250 printk("\n");
1251 return 1;
1252 }
1253
1254 EXPORT_SYMBOL(ide_lock);
1255
1256 static int ide_bus_match(struct device *dev, struct device_driver *drv)
1257 {
1258 return 1;
1259 }
1260
1261 static char *media_string(ide_drive_t *drive)
1262 {
1263 switch (drive->media) {
1264 case ide_disk:
1265 return "disk";
1266 case ide_cdrom:
1267 return "cdrom";
1268 case ide_tape:
1269 return "tape";
1270 case ide_floppy:
1271 return "floppy";
1272 case ide_optical:
1273 return "optical";
1274 default:
1275 return "UNKNOWN";
1276 }
1277 }
1278
1279 static ssize_t media_show(struct device *dev, struct device_attribute *attr, char *buf)
1280 {
1281 ide_drive_t *drive = to_ide_device(dev);
1282 return sprintf(buf, "%s\n", media_string(drive));
1283 }
1284
1285 static ssize_t drivename_show(struct device *dev, struct device_attribute *attr, char *buf)
1286 {
1287 ide_drive_t *drive = to_ide_device(dev);
1288 return sprintf(buf, "%s\n", drive->name);
1289 }
1290
1291 static ssize_t modalias_show(struct device *dev, struct device_attribute *attr, char *buf)
1292 {
1293 ide_drive_t *drive = to_ide_device(dev);
1294 return sprintf(buf, "ide:m-%s\n", media_string(drive));
1295 }
1296
1297 static ssize_t model_show(struct device *dev, struct device_attribute *attr,
1298 char *buf)
1299 {
1300 ide_drive_t *drive = to_ide_device(dev);
1301 return sprintf(buf, "%s\n", drive->id->model);
1302 }
1303
1304 static ssize_t firmware_show(struct device *dev, struct device_attribute *attr,
1305 char *buf)
1306 {
1307 ide_drive_t *drive = to_ide_device(dev);
1308 return sprintf(buf, "%s\n", drive->id->fw_rev);
1309 }
1310
1311 static ssize_t serial_show(struct device *dev, struct device_attribute *attr,
1312 char *buf)
1313 {
1314 ide_drive_t *drive = to_ide_device(dev);
1315 return sprintf(buf, "%s\n", drive->id->serial_no);
1316 }
1317
1318 static struct device_attribute ide_dev_attrs[] = {
1319 __ATTR_RO(media),
1320 __ATTR_RO(drivename),
1321 __ATTR_RO(modalias),
1322 __ATTR_RO(model),
1323 __ATTR_RO(firmware),
1324 __ATTR(serial, 0400, serial_show, NULL),
1325 __ATTR_NULL
1326 };
1327
1328 static int ide_uevent(struct device *dev, struct kobj_uevent_env *env)
1329 {
1330 ide_drive_t *drive = to_ide_device(dev);
1331
1332 add_uevent_var(env, "MEDIA=%s", media_string(drive));
1333 add_uevent_var(env, "DRIVENAME=%s", drive->name);
1334 add_uevent_var(env, "MODALIAS=ide:m-%s", media_string(drive));
1335 return 0;
1336 }
1337
1338 static int generic_ide_probe(struct device *dev)
1339 {
1340 ide_drive_t *drive = to_ide_device(dev);
1341 ide_driver_t *drv = to_ide_driver(dev->driver);
1342
1343 return drv->probe ? drv->probe(drive) : -ENODEV;
1344 }
1345
1346 static int generic_ide_remove(struct device *dev)
1347 {
1348 ide_drive_t *drive = to_ide_device(dev);
1349 ide_driver_t *drv = to_ide_driver(dev->driver);
1350
1351 if (drv->remove)
1352 drv->remove(drive);
1353
1354 return 0;
1355 }
1356
1357 static void generic_ide_shutdown(struct device *dev)
1358 {
1359 ide_drive_t *drive = to_ide_device(dev);
1360 ide_driver_t *drv = to_ide_driver(dev->driver);
1361
1362 if (dev->driver && drv->shutdown)
1363 drv->shutdown(drive);
1364 }
1365
1366 struct bus_type ide_bus_type = {
1367 .name = "ide",
1368 .match = ide_bus_match,
1369 .uevent = ide_uevent,
1370 .probe = generic_ide_probe,
1371 .remove = generic_ide_remove,
1372 .shutdown = generic_ide_shutdown,
1373 .dev_attrs = ide_dev_attrs,
1374 .suspend = generic_ide_suspend,
1375 .resume = generic_ide_resume,
1376 };
1377
1378 EXPORT_SYMBOL_GPL(ide_bus_type);
1379
1380 static void ide_port_class_release(struct device *portdev)
1381 {
1382 ide_hwif_t *hwif = dev_get_drvdata(portdev);
1383
1384 put_device(&hwif->gendev);
1385 }
1386
1387 /*
1388 * This is gets invoked once during initialization, to set *everything* up
1389 */
1390 static int __init ide_init(void)
1391 {
1392 int ret;
1393
1394 printk(KERN_INFO "Uniform Multi-Platform E-IDE driver\n");
1395 system_bus_speed = ide_system_bus_speed();
1396
1397 printk(KERN_INFO "ide: Assuming %dMHz system bus speed "
1398 "for PIO modes%s\n", system_bus_speed,
1399 idebus_parameter ? "" : "; override with idebus=xx");
1400
1401 ret = bus_register(&ide_bus_type);
1402 if (ret < 0) {
1403 printk(KERN_WARNING "IDE: bus_register error: %d\n", ret);
1404 return ret;
1405 }
1406
1407 ide_port_class = class_create(THIS_MODULE, "ide_port");
1408 if (IS_ERR(ide_port_class)) {
1409 ret = PTR_ERR(ide_port_class);
1410 goto out_port_class;
1411 }
1412 ide_port_class->dev_release = ide_port_class_release;
1413
1414 init_ide_data();
1415
1416 proc_ide_create();
1417
1418 return 0;
1419
1420 out_port_class:
1421 bus_unregister(&ide_bus_type);
1422
1423 return ret;
1424 }
1425
1426 #ifdef MODULE
1427 static char *options = NULL;
1428 module_param(options, charp, 0);
1429 MODULE_LICENSE("GPL");
1430
1431 static void __init parse_options (char *line)
1432 {
1433 char *next = line;
1434
1435 if (line == NULL || !*line)
1436 return;
1437 while ((line = next) != NULL) {
1438 if ((next = strchr(line,' ')) != NULL)
1439 *next++ = 0;
1440 if (!ide_setup(line))
1441 printk (KERN_INFO "Unknown option '%s'\n", line);
1442 }
1443 }
1444
1445 int __init init_module (void)
1446 {
1447 parse_options(options);
1448 return ide_init();
1449 }
1450
1451 void __exit cleanup_module (void)
1452 {
1453 int index;
1454
1455 for (index = 0; index < MAX_HWIFS; ++index)
1456 ide_unregister(index);
1457
1458 proc_ide_destroy();
1459
1460 class_destroy(ide_port_class);
1461
1462 bus_unregister(&ide_bus_type);
1463 }
1464
1465 #else /* !MODULE */
1466
1467 __setup("", ide_setup);
1468
1469 module_init(ide_init);
1470
1471 #endif /* MODULE */