2 * Copyright (C) 1994-1998 Linus Torvalds & authors (see below)
6 * Mostly written by Mark Lord <mlord@pobox.com>
7 * and Gadi Oxman <gadio@netvision.net.il>
8 * and Andre Hedrick <andre@linux-ide.org>
10 * See linux/MAINTAINERS for address of current maintainer.
12 * This is the multiple IDE interface driver, as evolved from hd.c.
13 * It supports up to MAX_HWIFS IDE interfaces, on one or more IRQs
15 * There can be up to two drives per interface, as per the ATA-2 spec.
21 * | It traverses the request-list, using interrupts to jump between functions.
22 * | As nearly all functions can be called within interrupts, we may not sleep.
23 * | Special care is recommended. Have Fun!
25 * | modified by Drew Eckhardt to check nr of hd's from the CMOS.
27 * | Thanks to Branko Lankester, lankeste@fwi.uva.nl, who found a bug
28 * | in the early extended-partition checks and added DM partitions.
30 * | Early work on error handling by Mika Liljeberg (liljeber@cs.Helsinki.FI).
32 * | IRQ-unmask, drive-id, multiple-mode, support for ">16 heads",
33 * | and general streamlining by Mark Lord (mlord@pobox.com).
35 * October, 1994 -- Complete line-by-line overhaul for linux 1.1.x, by:
37 * Mark Lord (mlord@pobox.com) (IDE Perf.Pkg)
38 * Delman Lee (delman@ieee.org) ("Mr. atdisk2")
39 * Scott Snyder (snyder@fnald0.fnal.gov) (ATAPI IDE cd-rom)
41 * This was a rewrite of just about everything from hd.c, though some original
42 * code is still sprinkled about. Think of it as a major evolution, with
43 * inspiration from lots of linux users, esp. hamish@zot.apana.org.au
46 #define REVISION "Revision: 7.00alpha2"
48 #define _IDE_C /* Tell ide.h it's really us */
50 #include <linux/module.h>
51 #include <linux/types.h>
52 #include <linux/string.h>
53 #include <linux/kernel.h>
54 #include <linux/timer.h>
56 #include <linux/interrupt.h>
57 #include <linux/major.h>
58 #include <linux/errno.h>
59 #include <linux/genhd.h>
60 #include <linux/blkpg.h>
61 #include <linux/slab.h>
62 #include <linux/init.h>
63 #include <linux/pci.h>
64 #include <linux/delay.h>
65 #include <linux/ide.h>
66 #include <linux/completion.h>
67 #include <linux/reboot.h>
68 #include <linux/cdrom.h>
69 #include <linux/seq_file.h>
70 #include <linux/device.h>
71 #include <linux/bitops.h>
73 #include <asm/byteorder.h>
75 #include <asm/uaccess.h>
79 /* default maximum number of failures */
80 #define IDE_DEFAULT_MAX_FAILURES 1
82 static const u8 ide_hwif_to_major
[] = { IDE0_MAJOR
, IDE1_MAJOR
,
83 IDE2_MAJOR
, IDE3_MAJOR
,
84 IDE4_MAJOR
, IDE5_MAJOR
,
85 IDE6_MAJOR
, IDE7_MAJOR
,
86 IDE8_MAJOR
, IDE9_MAJOR
};
88 static int idebus_parameter
; /* holds the "idebus=" parameter */
89 static int system_bus_speed
; /* holds what we think is VESA/PCI bus speed */
91 DEFINE_MUTEX(ide_cfg_mtx
);
92 __cacheline_aligned_in_smp
DEFINE_SPINLOCK(ide_lock
);
94 #ifdef CONFIG_IDEPCI_PCIBUS_ORDER
95 int ide_scan_direction
; /* THIS was formerly 2.2.x pci=reverse */
100 #ifdef CONFIG_BLK_DEV_IDEACPI
102 int ide_noacpitfs
= 1;
103 int ide_noacpionboot
= 1;
107 * This is declared extern in ide.h, for access by other IDE modules:
109 ide_hwif_t ide_hwifs
[MAX_HWIFS
]; /* master data repository */
111 EXPORT_SYMBOL(ide_hwifs
);
114 * Do not even *think* about calling this!
116 void ide_init_port_data(ide_hwif_t
*hwif
, unsigned int index
)
120 /* bulk initialize hwif & drive info with zeros */
121 memset(hwif
, 0, sizeof(ide_hwif_t
));
123 /* fill in any non-zero initial values */
125 hwif
->major
= ide_hwif_to_major
[index
];
130 hwif
->name
[3] = '0' + index
;
132 hwif
->bus_state
= BUSSTATE_ON
;
134 init_completion(&hwif
->gendev_rel_comp
);
136 default_hwif_iops(hwif
);
137 default_hwif_transport(hwif
);
138 for (unit
= 0; unit
< MAX_DRIVES
; ++unit
) {
139 ide_drive_t
*drive
= &hwif
->drives
[unit
];
141 drive
->media
= ide_disk
;
142 drive
->select
.all
= (unit
<<4)|0xa0;
145 drive
->ready_stat
= READY_STAT
;
146 drive
->bad_wstat
= BAD_W_STAT
;
147 drive
->special
.b
.recalibrate
= 1;
148 drive
->special
.b
.set_geometry
= 1;
149 drive
->name
[0] = 'h';
150 drive
->name
[1] = 'd';
151 drive
->name
[2] = 'a' + (index
* MAX_DRIVES
) + unit
;
152 drive
->max_failures
= IDE_DEFAULT_MAX_FAILURES
;
153 drive
->using_dma
= 0;
155 INIT_LIST_HEAD(&drive
->list
);
156 init_completion(&drive
->gendev_rel_comp
);
159 EXPORT_SYMBOL_GPL(ide_init_port_data
);
161 static void init_hwif_default(ide_hwif_t
*hwif
, unsigned int index
)
165 memset(&hw
, 0, sizeof(hw_regs_t
));
167 ide_init_hwif_ports(&hw
, ide_default_io_base(index
), 0, &hwif
->irq
);
169 memcpy(hwif
->io_ports
, hw
.io_ports
, sizeof(hw
.io_ports
));
171 hwif
->noprobe
= !hwif
->io_ports
[IDE_DATA_OFFSET
];
172 #ifdef CONFIG_BLK_DEV_HD
173 if (hwif
->io_ports
[IDE_DATA_OFFSET
] == HD_DATA
)
174 hwif
->noprobe
= 1; /* may be overridden by ide_setup() */
179 * init_ide_data() sets reasonable default values into all fields
180 * of all instances of the hwifs and drives, but only on the first call.
181 * Subsequent calls have no effect (they don't wipe out anything).
183 * This routine is normally called at driver initialization time,
184 * but may also be called MUCH earlier during kernel "command-line"
185 * parameter processing. As such, we cannot depend on any other parts
186 * of the kernel (such as memory allocation) to be functioning yet.
188 * This is too bad, as otherwise we could dynamically allocate the
189 * ide_drive_t structs as needed, rather than always consuming memory
190 * for the max possible number (MAX_HWIFS * MAX_DRIVES) of them.
192 * FIXME: We should stuff the setup data into __init and copy the
193 * relevant hwifs/allocate them properly during boot.
195 #define MAGIC_COOKIE 0x12345678
196 static void __init
init_ide_data (void)
200 static unsigned long magic_cookie
= MAGIC_COOKIE
;
202 if (magic_cookie
!= MAGIC_COOKIE
)
203 return; /* already initialized */
206 /* Initialise all interface structures */
207 for (index
= 0; index
< MAX_HWIFS
; ++index
) {
208 hwif
= &ide_hwifs
[index
];
209 ide_init_port_data(hwif
, index
);
210 init_hwif_default(hwif
, index
);
211 #if !defined(CONFIG_PPC32) || !defined(CONFIG_PCI)
213 ide_init_default_irq(hwif
->io_ports
[IDE_DATA_OFFSET
]);
219 * ide_system_bus_speed - guess bus speed
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.
228 * Returns a guessed speed in MHz.
231 static int ide_system_bus_speed(void)
234 static struct pci_device_id pci_default
[] = {
235 { PCI_DEVICE(PCI_ANY_ID
, PCI_ANY_ID
) },
239 #define pci_default 0
240 #endif /* CONFIG_PCI */
242 if (!system_bus_speed
) {
243 if (idebus_parameter
) {
244 /* user supplied value */
245 system_bus_speed
= idebus_parameter
;
246 } else if (pci_dev_present(pci_default
)) {
247 /* safe default value for PCI */
248 system_bus_speed
= 33;
250 /* safe default value for VESA and PCI */
251 system_bus_speed
= 50;
253 printk(KERN_INFO
"ide: Assuming %dMHz system bus speed "
254 "for PIO modes%s\n", system_bus_speed
,
255 idebus_parameter
? "" : "; override with idebus=xx");
257 return system_bus_speed
;
260 ide_hwif_t
* ide_find_port(unsigned long base
)
265 for (i
= 0; i
< MAX_HWIFS
; i
++) {
266 hwif
= &ide_hwifs
[i
];
267 if (hwif
->io_ports
[IDE_DATA_OFFSET
] == base
)
271 for (i
= 0; i
< MAX_HWIFS
; i
++) {
272 hwif
= &ide_hwifs
[i
];
273 if (hwif
->io_ports
[IDE_DATA_OFFSET
] == 0)
282 EXPORT_SYMBOL_GPL(ide_find_port
);
284 static struct resource
* hwif_request_region(ide_hwif_t
*hwif
,
285 unsigned long addr
, int num
)
287 struct resource
*res
= request_region(addr
, num
, hwif
->name
);
290 printk(KERN_ERR
"%s: I/O resource 0x%lX-0x%lX not free.\n",
291 hwif
->name
, addr
, addr
+num
-1);
296 * ide_hwif_request_regions - request resources for IDE
297 * @hwif: interface to use
299 * Requests all the needed resources for an interface.
300 * Right now core IDE code does this work which is deeply wrong.
301 * MMIO leaves it to the controller driver,
302 * PIO will migrate this way over time.
305 int ide_hwif_request_regions(ide_hwif_t
*hwif
)
312 addr
= hwif
->io_ports
[IDE_CONTROL_OFFSET
];
313 if (addr
&& !hwif_request_region(hwif
, addr
, 1))
314 goto control_region_busy
;
316 addr
= hwif
->io_ports
[IDE_DATA_OFFSET
];
317 if ((addr
| 7) == hwif
->io_ports
[IDE_STATUS_OFFSET
]) {
318 if (!hwif_request_region(hwif
, addr
, 8))
319 goto data_region_busy
;
323 for (i
= IDE_DATA_OFFSET
; i
<= IDE_STATUS_OFFSET
; i
++) {
324 addr
= hwif
->io_ports
[i
];
325 if (!hwif_request_region(hwif
, addr
, 1)) {
327 release_region(addr
, 1);
328 goto data_region_busy
;
334 addr
= hwif
->io_ports
[IDE_CONTROL_OFFSET
];
336 release_region(addr
, 1);
338 /* If any errors are return, we drop the hwif interface. */
343 * ide_hwif_release_regions - free IDE resources
345 * Note that we only release the standard ports,
346 * and do not even try to handle any extra ports
347 * allocated for weird IDE interface chipsets.
349 * Note also that we don't yet handle mmio resources here. More
350 * importantly our caller should be doing this so we need to
351 * restructure this as a helper function for drivers.
354 void ide_hwif_release_regions(ide_hwif_t
*hwif
)
360 if (hwif
->io_ports
[IDE_CONTROL_OFFSET
])
361 release_region(hwif
->io_ports
[IDE_CONTROL_OFFSET
], 1);
362 if (hwif
->straight8
) {
363 release_region(hwif
->io_ports
[IDE_DATA_OFFSET
], 8);
366 for (i
= IDE_DATA_OFFSET
; i
<= IDE_STATUS_OFFSET
; i
++)
367 if (hwif
->io_ports
[i
])
368 release_region(hwif
->io_ports
[i
], 1);
372 * ide_hwif_restore - restore hwif to template
373 * @hwif: hwif to update
374 * @tmp_hwif: template
376 * Restore hwif to a previous state by copying most settings
380 static void ide_hwif_restore(ide_hwif_t
*hwif
, ide_hwif_t
*tmp_hwif
)
382 hwif
->hwgroup
= tmp_hwif
->hwgroup
;
384 hwif
->gendev
.parent
= tmp_hwif
->gendev
.parent
;
386 hwif
->proc
= tmp_hwif
->proc
;
388 hwif
->major
= tmp_hwif
->major
;
389 hwif
->straight8
= tmp_hwif
->straight8
;
390 hwif
->bus_state
= tmp_hwif
->bus_state
;
392 hwif
->host_flags
= tmp_hwif
->host_flags
;
394 hwif
->pio_mask
= tmp_hwif
->pio_mask
;
396 hwif
->ultra_mask
= tmp_hwif
->ultra_mask
;
397 hwif
->mwdma_mask
= tmp_hwif
->mwdma_mask
;
398 hwif
->swdma_mask
= tmp_hwif
->swdma_mask
;
400 hwif
->cbl
= tmp_hwif
->cbl
;
402 hwif
->chipset
= tmp_hwif
->chipset
;
403 hwif
->hold
= tmp_hwif
->hold
;
405 hwif
->dev
= tmp_hwif
->dev
;
407 #ifdef CONFIG_BLK_DEV_IDEPCI
408 hwif
->cds
= tmp_hwif
->cds
;
411 hwif
->set_pio_mode
= tmp_hwif
->set_pio_mode
;
412 hwif
->set_dma_mode
= tmp_hwif
->set_dma_mode
;
413 hwif
->mdma_filter
= tmp_hwif
->mdma_filter
;
414 hwif
->udma_filter
= tmp_hwif
->udma_filter
;
415 hwif
->selectproc
= tmp_hwif
->selectproc
;
416 hwif
->reset_poll
= tmp_hwif
->reset_poll
;
417 hwif
->pre_reset
= tmp_hwif
->pre_reset
;
418 hwif
->resetproc
= tmp_hwif
->resetproc
;
419 hwif
->maskproc
= tmp_hwif
->maskproc
;
420 hwif
->quirkproc
= tmp_hwif
->quirkproc
;
421 hwif
->busproc
= tmp_hwif
->busproc
;
423 hwif
->ata_input_data
= tmp_hwif
->ata_input_data
;
424 hwif
->ata_output_data
= tmp_hwif
->ata_output_data
;
425 hwif
->atapi_input_bytes
= tmp_hwif
->atapi_input_bytes
;
426 hwif
->atapi_output_bytes
= tmp_hwif
->atapi_output_bytes
;
428 hwif
->dma_host_set
= tmp_hwif
->dma_host_set
;
429 hwif
->dma_setup
= tmp_hwif
->dma_setup
;
430 hwif
->dma_exec_cmd
= tmp_hwif
->dma_exec_cmd
;
431 hwif
->dma_start
= tmp_hwif
->dma_start
;
432 hwif
->ide_dma_end
= tmp_hwif
->ide_dma_end
;
433 hwif
->ide_dma_test_irq
= tmp_hwif
->ide_dma_test_irq
;
434 hwif
->ide_dma_clear_irq
= tmp_hwif
->ide_dma_clear_irq
;
435 hwif
->dma_lost_irq
= tmp_hwif
->dma_lost_irq
;
436 hwif
->dma_timeout
= tmp_hwif
->dma_timeout
;
438 hwif
->OUTB
= tmp_hwif
->OUTB
;
439 hwif
->OUTBSYNC
= tmp_hwif
->OUTBSYNC
;
440 hwif
->OUTW
= tmp_hwif
->OUTW
;
441 hwif
->OUTSW
= tmp_hwif
->OUTSW
;
442 hwif
->OUTSL
= tmp_hwif
->OUTSL
;
444 hwif
->INB
= tmp_hwif
->INB
;
445 hwif
->INW
= tmp_hwif
->INW
;
446 hwif
->INSW
= tmp_hwif
->INSW
;
447 hwif
->INSL
= tmp_hwif
->INSL
;
449 hwif
->sg_max_nents
= tmp_hwif
->sg_max_nents
;
451 hwif
->mmio
= tmp_hwif
->mmio
;
452 hwif
->rqsize
= tmp_hwif
->rqsize
;
454 #ifndef CONFIG_BLK_DEV_IDECS
455 hwif
->irq
= tmp_hwif
->irq
;
458 hwif
->dma_base
= tmp_hwif
->dma_base
;
459 hwif
->dma_command
= tmp_hwif
->dma_command
;
460 hwif
->dma_vendor1
= tmp_hwif
->dma_vendor1
;
461 hwif
->dma_status
= tmp_hwif
->dma_status
;
462 hwif
->dma_vendor3
= tmp_hwif
->dma_vendor3
;
463 hwif
->dma_prdtable
= tmp_hwif
->dma_prdtable
;
465 hwif
->config_data
= tmp_hwif
->config_data
;
466 hwif
->select_data
= tmp_hwif
->select_data
;
467 hwif
->extra_base
= tmp_hwif
->extra_base
;
468 hwif
->extra_ports
= tmp_hwif
->extra_ports
;
470 hwif
->hwif_data
= tmp_hwif
->hwif_data
;
474 * ide_unregister - free an IDE interface
475 * @index: index of interface (will change soon to a pointer)
477 * Perform the final unregister of an IDE interface. At the moment
478 * we don't refcount interfaces so this will also get split up.
481 * The caller must not hold the IDE locks
482 * The drive present/vanishing is not yet properly locked
483 * Take care with the callbacks. These have been split to avoid
484 * deadlocking the IDE layer. The shutdown callback is called
485 * before we take the lock and free resources. It is up to the
486 * caller to be sure there is no pending I/O here, and that
487 * the interface will not be reopened (present/vanishing locking
488 * isn't yet done BTW). After we commit to the final kill we
489 * call the cleanup callback with the ide locks held.
491 * Unregister restores the hwif structures to the default state.
492 * This is raving bonkers.
495 void ide_unregister(unsigned int index
)
498 ide_hwif_t
*hwif
, *g
;
499 static ide_hwif_t tmp_hwif
; /* protected by ide_cfg_mtx */
500 ide_hwgroup_t
*hwgroup
;
501 int irq_count
= 0, unit
;
503 BUG_ON(index
>= MAX_HWIFS
);
505 BUG_ON(in_interrupt());
506 BUG_ON(irqs_disabled());
507 mutex_lock(&ide_cfg_mtx
);
508 spin_lock_irq(&ide_lock
);
509 hwif
= &ide_hwifs
[index
];
512 for (unit
= 0; unit
< MAX_DRIVES
; ++unit
) {
513 drive
= &hwif
->drives
[unit
];
516 spin_unlock_irq(&ide_lock
);
517 device_unregister(&drive
->gendev
);
518 wait_for_completion(&drive
->gendev_rel_comp
);
519 spin_lock_irq(&ide_lock
);
523 spin_unlock_irq(&ide_lock
);
525 ide_proc_unregister_port(hwif
);
527 hwgroup
= hwif
->hwgroup
;
529 * free the irq if we were the only hwif using it
533 if (g
->irq
== hwif
->irq
)
536 } while (g
!= hwgroup
->hwif
);
538 free_irq(hwif
->irq
, hwgroup
);
540 spin_lock_irq(&ide_lock
);
542 * Note that we only release the standard ports,
543 * and do not even try to handle any extra ports
544 * allocated for weird IDE interface chipsets.
546 ide_hwif_release_regions(hwif
);
549 * Remove us from the hwgroup, and free
550 * the hwgroup if we were the only member
552 if (hwif
->next
== hwif
) {
553 BUG_ON(hwgroup
->hwif
!= hwif
);
556 /* There is another interface in hwgroup.
557 * Unlink us, and set hwgroup->drive and ->hwif to
561 while (g
->next
!= hwif
)
563 g
->next
= hwif
->next
;
564 if (hwgroup
->hwif
== hwif
) {
565 /* Chose a random hwif for hwgroup->hwif.
566 * It's guaranteed that there are no drives
567 * left in the hwgroup.
569 BUG_ON(hwgroup
->drive
!= NULL
);
572 BUG_ON(hwgroup
->hwif
== hwif
);
575 /* More messed up locking ... */
576 spin_unlock_irq(&ide_lock
);
577 device_unregister(&hwif
->gendev
);
578 wait_for_completion(&hwif
->gendev_rel_comp
);
581 * Remove us from the kernel's knowledge
583 blk_unregister_region(MKDEV(hwif
->major
, 0), MAX_DRIVES
<<PARTN_BITS
);
584 kfree(hwif
->sg_table
);
585 unregister_blkdev(hwif
->major
, hwif
->name
);
586 spin_lock_irq(&ide_lock
);
588 if (hwif
->dma_base
) {
589 (void) ide_release_dma(hwif
);
592 hwif
->dma_command
= 0;
593 hwif
->dma_vendor1
= 0;
594 hwif
->dma_status
= 0;
595 hwif
->dma_vendor3
= 0;
596 hwif
->dma_prdtable
= 0;
598 hwif
->extra_base
= 0;
599 hwif
->extra_ports
= 0;
602 /* copy original settings */
605 /* restore hwif data to pristine status */
606 ide_init_port_data(hwif
, index
);
607 init_hwif_default(hwif
, index
);
609 ide_hwif_restore(hwif
, &tmp_hwif
);
612 spin_unlock_irq(&ide_lock
);
613 mutex_unlock(&ide_cfg_mtx
);
616 EXPORT_SYMBOL(ide_unregister
);
620 * ide_setup_ports - set up IDE interface ports
621 * @hw: register descriptions
622 * @base: base register
623 * @offsets: table of register offsets
624 * @ctrl: control register
626 * @irq: interrupt lie
628 * Setup hw_regs_t structure described by parameters. You
629 * may set up the hw structure yourself OR use this routine to
630 * do it for you. This is basically a helper
634 void ide_setup_ports ( hw_regs_t
*hw
,
635 unsigned long base
, int *offsets
,
636 unsigned long ctrl
, unsigned long intr
,
637 ide_ack_intr_t
*ack_intr
,
639 * ide_io_ops_t *iops,
645 memset(hw
, 0, sizeof(hw_regs_t
));
646 for (i
= 0; i
< IDE_NR_PORTS
; i
++) {
647 if (offsets
[i
] == -1) {
649 case IDE_CONTROL_OFFSET
:
650 hw
->io_ports
[i
] = ctrl
;
652 #if defined(CONFIG_AMIGA) || defined(CONFIG_MAC)
654 hw
->io_ports
[i
] = intr
;
656 #endif /* (CONFIG_AMIGA) || (CONFIG_MAC) */
662 hw
->io_ports
[i
] = base
+ offsets
[i
];
666 hw
->ack_intr
= ack_intr
;
672 void ide_init_port_hw(ide_hwif_t
*hwif
, hw_regs_t
*hw
)
674 memcpy(hwif
->io_ports
, hw
->io_ports
, sizeof(hwif
->io_ports
));
677 hwif
->chipset
= hw
->chipset
;
678 hwif
->gendev
.parent
= hw
->dev
;
679 hwif
->ack_intr
= hw
->ack_intr
;
681 EXPORT_SYMBOL_GPL(ide_init_port_hw
);
684 * ide_register_hw - register IDE interface
685 * @hw: hardware registers
686 * @quirkproc: quirkproc function
687 * @hwifp: pointer to returned hwif
689 * Register an IDE interface, specifying exactly the registers etc.
691 * Returns -1 on error.
694 int ide_register_hw(hw_regs_t
*hw
, void (*quirkproc
)(ide_drive_t
*),
697 int index
, retry
= 1;
699 u8 idx
[4] = { 0xff, 0xff, 0xff, 0xff };
702 for (index
= 0; index
< MAX_HWIFS
; ++index
) {
703 hwif
= &ide_hwifs
[index
];
704 if (hwif
->io_ports
[IDE_DATA_OFFSET
] == hw
->io_ports
[IDE_DATA_OFFSET
])
707 for (index
= 0; index
< MAX_HWIFS
; ++index
) {
708 hwif
= &ide_hwifs
[index
];
711 if (!hwif
->present
&& hwif
->mate
== NULL
)
714 for (index
= 0; index
< MAX_HWIFS
; index
++)
715 ide_unregister(index
);
720 ide_unregister(index
);
721 else if (!hwif
->hold
) {
722 ide_init_port_data(hwif
, index
);
723 init_hwif_default(hwif
, index
);
728 ide_init_port_hw(hwif
, hw
);
729 hwif
->quirkproc
= quirkproc
;
738 return hwif
->present
? index
: -1;
741 EXPORT_SYMBOL(ide_register_hw
);
744 * Locks for IDE setting functionality
747 DEFINE_MUTEX(ide_setting_mtx
);
749 EXPORT_SYMBOL_GPL(ide_setting_mtx
);
752 * ide_spin_wait_hwgroup - wait for group
753 * @drive: drive in the group
755 * Wait for an IDE device group to go non busy and then return
756 * holding the ide_lock which guards the hwgroup->busy status
757 * and right to use it.
760 int ide_spin_wait_hwgroup (ide_drive_t
*drive
)
762 ide_hwgroup_t
*hwgroup
= HWGROUP(drive
);
763 unsigned long timeout
= jiffies
+ (3 * HZ
);
765 spin_lock_irq(&ide_lock
);
767 while (hwgroup
->busy
) {
768 unsigned long lflags
;
769 spin_unlock_irq(&ide_lock
);
770 local_irq_set(lflags
);
771 if (time_after(jiffies
, timeout
)) {
772 local_irq_restore(lflags
);
773 printk(KERN_ERR
"%s: channel busy\n", drive
->name
);
776 local_irq_restore(lflags
);
777 spin_lock_irq(&ide_lock
);
782 EXPORT_SYMBOL(ide_spin_wait_hwgroup
);
784 int set_io_32bit(ide_drive_t
*drive
, int arg
)
786 if (drive
->no_io_32bit
)
789 if (arg
< 0 || arg
> 1 + (SUPPORT_VLB_SYNC
<< 1))
792 if (ide_spin_wait_hwgroup(drive
))
795 drive
->io_32bit
= arg
;
796 #ifdef CONFIG_BLK_DEV_DTC2278
797 if (HWIF(drive
)->chipset
== ide_dtc2278
)
798 HWIF(drive
)->drives
[!drive
->select
.b
.unit
].io_32bit
= arg
;
799 #endif /* CONFIG_BLK_DEV_DTC2278 */
801 spin_unlock_irq(&ide_lock
);
806 static int set_ksettings(ide_drive_t
*drive
, int arg
)
808 if (arg
< 0 || arg
> 1)
811 if (ide_spin_wait_hwgroup(drive
))
813 drive
->keep_settings
= arg
;
814 spin_unlock_irq(&ide_lock
);
819 int set_using_dma(ide_drive_t
*drive
, int arg
)
821 #ifdef CONFIG_BLK_DEV_IDEDMA
822 ide_hwif_t
*hwif
= drive
->hwif
;
825 if (arg
< 0 || arg
> 1)
828 if (!drive
->id
|| !(drive
->id
->capability
& 1))
831 if (hwif
->dma_host_set
== NULL
)
835 if (ide_spin_wait_hwgroup(drive
))
838 * set ->busy flag, unlock and let it ride
840 hwif
->hwgroup
->busy
= 1;
841 spin_unlock_irq(&ide_lock
);
846 if (ide_set_dma(drive
))
852 * lock, clear ->busy flag and unlock before leaving
854 spin_lock_irq(&ide_lock
);
855 hwif
->hwgroup
->busy
= 0;
856 spin_unlock_irq(&ide_lock
);
860 if (arg
< 0 || arg
> 1)
867 int set_pio_mode(ide_drive_t
*drive
, int arg
)
871 if (arg
< 0 || arg
> 255)
874 if (drive
->hwif
->set_pio_mode
== NULL
)
877 if (drive
->special
.b
.set_tune
)
880 ide_init_drive_cmd(&rq
);
881 rq
.cmd_type
= REQ_TYPE_ATA_TASKFILE
;
883 drive
->tune_req
= (u8
) arg
;
884 drive
->special
.b
.set_tune
= 1;
885 (void) ide_do_drive_cmd(drive
, &rq
, ide_wait
);
889 static int set_unmaskirq(ide_drive_t
*drive
, int arg
)
891 if (drive
->no_unmask
)
894 if (arg
< 0 || arg
> 1)
897 if (ide_spin_wait_hwgroup(drive
))
900 spin_unlock_irq(&ide_lock
);
906 * system_bus_clock - clock guess
908 * External version of the bus clock guess used by very old IDE drivers
909 * for things like VLB timings. Should not be used.
912 int system_bus_clock (void)
914 return((int) ((!system_bus_speed
) ? ide_system_bus_speed() : system_bus_speed
));
917 EXPORT_SYMBOL(system_bus_clock
);
919 static int generic_ide_suspend(struct device
*dev
, pm_message_t mesg
)
921 ide_drive_t
*drive
= dev
->driver_data
;
922 ide_hwif_t
*hwif
= HWIF(drive
);
924 struct request_pm_state rqpm
;
928 /* Call ACPI _GTM only once */
929 if (!(drive
->dn
% 2))
930 ide_acpi_get_timing(hwif
);
932 memset(&rq
, 0, sizeof(rq
));
933 memset(&rqpm
, 0, sizeof(rqpm
));
934 memset(&args
, 0, sizeof(args
));
935 rq
.cmd_type
= REQ_TYPE_PM_SUSPEND
;
938 rqpm
.pm_step
= ide_pm_state_start_suspend
;
939 if (mesg
.event
== PM_EVENT_PRETHAW
)
940 mesg
.event
= PM_EVENT_FREEZE
;
941 rqpm
.pm_state
= mesg
.event
;
943 ret
= ide_do_drive_cmd(drive
, &rq
, ide_wait
);
944 /* only call ACPI _PS3 after both drivers are suspended */
945 if (!ret
&& (((drive
->dn
% 2) && hwif
->drives
[0].present
946 && hwif
->drives
[1].present
)
947 || !hwif
->drives
[0].present
948 || !hwif
->drives
[1].present
))
949 ide_acpi_set_state(hwif
, 0);
953 static int generic_ide_resume(struct device
*dev
)
955 ide_drive_t
*drive
= dev
->driver_data
;
956 ide_hwif_t
*hwif
= HWIF(drive
);
958 struct request_pm_state rqpm
;
962 /* Call ACPI _STM only once */
963 if (!(drive
->dn
% 2)) {
964 ide_acpi_set_state(hwif
, 1);
965 ide_acpi_push_timing(hwif
);
968 ide_acpi_exec_tfs(drive
);
970 memset(&rq
, 0, sizeof(rq
));
971 memset(&rqpm
, 0, sizeof(rqpm
));
972 memset(&args
, 0, sizeof(args
));
973 rq
.cmd_type
= REQ_TYPE_PM_RESUME
;
976 rqpm
.pm_step
= ide_pm_state_start_resume
;
977 rqpm
.pm_state
= PM_EVENT_ON
;
979 err
= ide_do_drive_cmd(drive
, &rq
, ide_head_wait
);
981 if (err
== 0 && dev
->driver
) {
982 ide_driver_t
*drv
= to_ide_driver(dev
->driver
);
991 int generic_ide_ioctl(ide_drive_t
*drive
, struct file
*file
, struct block_device
*bdev
,
992 unsigned int cmd
, unsigned long arg
)
996 void __user
*p
= (void __user
*)arg
;
997 int err
= 0, (*setfunc
)(ide_drive_t
*, int);
1001 case HDIO_GET_32BIT
: val
= &drive
->io_32bit
; goto read_val
;
1002 case HDIO_GET_KEEPSETTINGS
: val
= &drive
->keep_settings
; goto read_val
;
1003 case HDIO_GET_UNMASKINTR
: val
= &drive
->unmask
; goto read_val
;
1004 case HDIO_GET_DMA
: val
= &drive
->using_dma
; goto read_val
;
1005 case HDIO_SET_32BIT
: setfunc
= set_io_32bit
; goto set_val
;
1006 case HDIO_SET_KEEPSETTINGS
: setfunc
= set_ksettings
; goto set_val
;
1007 case HDIO_SET_PIO_MODE
: setfunc
= set_pio_mode
; goto set_val
;
1008 case HDIO_SET_UNMASKINTR
: setfunc
= set_unmaskirq
; goto set_val
;
1009 case HDIO_SET_DMA
: setfunc
= set_using_dma
; goto set_val
;
1013 case HDIO_OBSOLETE_IDENTITY
:
1014 case HDIO_GET_IDENTITY
:
1015 if (bdev
!= bdev
->bd_contains
)
1017 if (drive
->id_read
== 0)
1019 if (copy_to_user(p
, drive
->id
, (cmd
== HDIO_GET_IDENTITY
) ? sizeof(*drive
->id
) : 142))
1024 return put_user(drive
->dsc_overlap
<< IDE_NICE_DSC_OVERLAP
|
1025 drive
->atapi_overlap
<< IDE_NICE_ATAPI_OVERLAP
|
1026 drive
->nice0
<< IDE_NICE_0
|
1027 drive
->nice1
<< IDE_NICE_1
|
1028 drive
->nice2
<< IDE_NICE_2
,
1029 (long __user
*) arg
);
1031 #ifdef CONFIG_IDE_TASK_IOCTL
1032 case HDIO_DRIVE_TASKFILE
:
1033 if (!capable(CAP_SYS_ADMIN
) || !capable(CAP_SYS_RAWIO
))
1035 switch(drive
->media
) {
1037 return ide_taskfile_ioctl(drive
, cmd
, arg
);
1041 #endif /* CONFIG_IDE_TASK_IOCTL */
1043 case HDIO_DRIVE_CMD
:
1044 if (!capable(CAP_SYS_RAWIO
))
1046 return ide_cmd_ioctl(drive
, cmd
, arg
);
1048 case HDIO_DRIVE_TASK
:
1049 if (!capable(CAP_SYS_RAWIO
))
1051 return ide_task_ioctl(drive
, cmd
, arg
);
1053 case HDIO_SCAN_HWIF
:
1057 if (!capable(CAP_SYS_RAWIO
)) return -EACCES
;
1058 if (copy_from_user(args
, p
, 3 * sizeof(int)))
1060 memset(&hw
, 0, sizeof(hw
));
1061 ide_init_hwif_ports(&hw
, (unsigned long) args
[0],
1062 (unsigned long) args
[1], NULL
);
1064 if (ide_register_hw(&hw
, NULL
, NULL
) == -1)
1068 case HDIO_UNREGISTER_HWIF
:
1069 if (!capable(CAP_SYS_RAWIO
)) return -EACCES
;
1070 /* (arg > MAX_HWIFS) checked in function */
1071 ide_unregister(arg
);
1074 if (!capable(CAP_SYS_ADMIN
)) return -EACCES
;
1075 if (arg
!= (arg
& ((1 << IDE_NICE_DSC_OVERLAP
) | (1 << IDE_NICE_1
))))
1077 drive
->dsc_overlap
= (arg
>> IDE_NICE_DSC_OVERLAP
) & 1;
1078 drv
= *(ide_driver_t
**)bdev
->bd_disk
->private_data
;
1079 if (drive
->dsc_overlap
&& !drv
->supports_dsc_overlap
) {
1080 drive
->dsc_overlap
= 0;
1083 drive
->nice1
= (arg
>> IDE_NICE_1
) & 1;
1085 case HDIO_DRIVE_RESET
:
1087 unsigned long flags
;
1088 if (!capable(CAP_SYS_ADMIN
)) return -EACCES
;
1091 * Abort the current command on the
1092 * group if there is one, taking
1093 * care not to allow anything else
1094 * to be queued and to die on the
1095 * spot if we miss one somehow
1098 spin_lock_irqsave(&ide_lock
, flags
);
1100 if (HWGROUP(drive
)->resetting
) {
1101 spin_unlock_irqrestore(&ide_lock
, flags
);
1105 ide_abort(drive
, "drive reset");
1107 BUG_ON(HWGROUP(drive
)->handler
);
1109 /* Ensure nothing gets queued after we
1110 drop the lock. Reset will clear the busy */
1112 HWGROUP(drive
)->busy
= 1;
1113 spin_unlock_irqrestore(&ide_lock
, flags
);
1114 (void) ide_do_reset(drive
);
1119 case HDIO_GET_BUSSTATE
:
1120 if (!capable(CAP_SYS_ADMIN
))
1122 if (put_user(HWIF(drive
)->bus_state
, (long __user
*)arg
))
1126 case HDIO_SET_BUSSTATE
:
1127 if (!capable(CAP_SYS_ADMIN
))
1129 if (HWIF(drive
)->busproc
)
1130 return HWIF(drive
)->busproc(drive
, (int)arg
);
1137 mutex_lock(&ide_setting_mtx
);
1138 spin_lock_irqsave(&ide_lock
, flags
);
1140 spin_unlock_irqrestore(&ide_lock
, flags
);
1141 mutex_unlock(&ide_setting_mtx
);
1142 return err
>= 0 ? put_user(err
, (long __user
*)arg
) : err
;
1145 if (bdev
!= bdev
->bd_contains
)
1148 if (!capable(CAP_SYS_ADMIN
))
1151 mutex_lock(&ide_setting_mtx
);
1152 err
= setfunc(drive
, arg
);
1153 mutex_unlock(&ide_setting_mtx
);
1159 EXPORT_SYMBOL(generic_ide_ioctl
);
1162 * stridx() returns the offset of c within s,
1163 * or -1 if c is '\0' or not found within s.
1165 static int __init
stridx (const char *s
, char c
)
1167 char *i
= strchr(s
, c
);
1168 return (i
&& c
) ? i
- s
: -1;
1172 * match_parm() does parsing for ide_setup():
1174 * 1. the first char of s must be '='.
1175 * 2. if the remainder matches one of the supplied keywords,
1176 * the index (1 based) of the keyword is negated and returned.
1177 * 3. if the remainder is a series of no more than max_vals numbers
1178 * separated by commas, the numbers are saved in vals[] and a
1179 * count of how many were saved is returned. Base10 is assumed,
1180 * and base16 is allowed when prefixed with "0x".
1181 * 4. otherwise, zero is returned.
1183 static int __init
match_parm (char *s
, const char *keywords
[], int vals
[], int max_vals
)
1185 static const char *decimal
= "0123456789";
1186 static const char *hex
= "0123456789abcdef";
1191 * Try matching against the supplied keywords,
1192 * and return -(index+1) if we match one
1194 if (keywords
!= NULL
) {
1195 for (i
= 0; *keywords
!= NULL
; ++i
) {
1196 if (!strcmp(s
, *keywords
++))
1201 * Look for a series of no more than "max_vals"
1202 * numeric values separated by commas, in base10,
1203 * or base16 when prefixed with "0x".
1204 * Return a count of how many were found.
1206 for (n
= 0; (i
= stridx(decimal
, *s
)) >= 0;) {
1208 while ((i
= stridx(decimal
, *++s
)) >= 0)
1209 vals
[n
] = (vals
[n
] * 10) + i
;
1210 if (*s
== 'x' && !vals
[n
]) {
1211 while ((i
= stridx(hex
, *++s
)) >= 0)
1212 vals
[n
] = (vals
[n
] * 0x10) + i
;
1214 if (++n
== max_vals
)
1216 if (*s
== ',' || *s
== ';')
1222 return 0; /* zero = nothing matched */
1225 extern int probe_ali14xx
;
1226 extern int probe_umc8672
;
1227 extern int probe_dtc2278
;
1228 extern int probe_ht6560b
;
1229 extern int probe_qd65xx
;
1230 extern int cmd640_vlb
;
1232 static int __initdata is_chipset_set
[MAX_HWIFS
];
1235 * ide_setup() gets called VERY EARLY during initialization,
1236 * to handle kernel "command line" strings beginning with "hdx=" or "ide".
1238 * Remember to update Documentation/ide.txt if you change something here.
1240 static int __init
ide_setup(char *s
)
1245 unsigned int hw
, unit
;
1246 const char max_drive
= 'a' + ((MAX_HWIFS
* MAX_DRIVES
) - 1);
1247 const char max_hwif
= '0' + (MAX_HWIFS
- 1);
1250 if (strncmp(s
,"hd",2) == 0 && s
[2] == '=') /* hd= is for hd.c */
1251 return 0; /* driver and not us */
1253 if (strncmp(s
,"ide",3) && strncmp(s
,"idebus",6) && strncmp(s
,"hd",2))
1256 printk(KERN_INFO
"ide_setup: %s", s
);
1259 #ifdef CONFIG_BLK_DEV_IDEDOUBLER
1260 if (!strcmp(s
, "ide=doubler")) {
1261 extern int ide_doubler
;
1263 printk(" : Enabled support for IDE doublers\n");
1267 #endif /* CONFIG_BLK_DEV_IDEDOUBLER */
1269 if (!strcmp(s
, "ide=nodma")) {
1270 printk(" : Prevented DMA\n");
1272 goto obsolete_option
;
1275 #ifdef CONFIG_IDEPCI_PCIBUS_ORDER
1276 if (!strcmp(s
, "ide=reverse")) {
1277 ide_scan_direction
= 1;
1278 printk(" : Enabled support for IDE inverse scan order.\n");
1283 #ifdef CONFIG_BLK_DEV_IDEACPI
1284 if (!strcmp(s
, "ide=noacpi")) {
1285 //printk(" : Disable IDE ACPI support.\n");
1289 if (!strcmp(s
, "ide=acpigtf")) {
1290 //printk(" : Enable IDE ACPI _GTF support.\n");
1294 if (!strcmp(s
, "ide=acpionboot")) {
1295 //printk(" : Call IDE ACPI methods on boot.\n");
1296 ide_noacpionboot
= 0;
1299 #endif /* CONFIG_BLK_DEV_IDEACPI */
1302 * Look for drive options: "hdx="
1304 if (s
[0] == 'h' && s
[1] == 'd' && s
[2] >= 'a' && s
[2] <= max_drive
) {
1305 const char *hd_words
[] = {
1306 "none", "noprobe", "nowerr", "cdrom", "nodma",
1307 "autotune", "noautotune", "-8", "-9", "-10",
1308 "noflush", "remap", "remap63", "scsi", NULL
};
1310 hw
= unit
/ MAX_DRIVES
;
1311 unit
= unit
% MAX_DRIVES
;
1312 hwif
= &ide_hwifs
[hw
];
1313 drive
= &hwif
->drives
[unit
];
1314 if (strncmp(s
+ 4, "ide-", 4) == 0) {
1315 strlcpy(drive
->driver_req
, s
+ 4, sizeof(drive
->driver_req
));
1318 switch (match_parm(&s
[3], hd_words
, vals
, 3)) {
1319 case -1: /* "none" */
1320 case -2: /* "noprobe" */
1323 case -3: /* "nowerr" */
1324 drive
->bad_wstat
= BAD_R_STAT
;
1327 case -4: /* "cdrom" */
1329 drive
->media
= ide_cdrom
;
1330 /* an ATAPI device ignores DRDY */
1331 drive
->ready_stat
= 0;
1334 case -5: /* nodma */
1337 case -6: /* "autotune" */
1338 drive
->autotune
= IDE_TUNE_AUTO
;
1339 goto obsolete_option
;
1340 case -7: /* "noautotune" */
1341 drive
->autotune
= IDE_TUNE_NOAUTO
;
1342 goto obsolete_option
;
1343 case -11: /* noflush */
1346 case -12: /* "remap" */
1347 drive
->remap_0_to_1
= 1;
1349 case -13: /* "remap63" */
1352 case -14: /* "scsi" */
1355 case 3: /* cyl,head,sect */
1356 drive
->media
= ide_disk
;
1357 drive
->ready_stat
= READY_STAT
;
1358 drive
->cyl
= drive
->bios_cyl
= vals
[0];
1359 drive
->head
= drive
->bios_head
= vals
[1];
1360 drive
->sect
= drive
->bios_sect
= vals
[2];
1362 drive
->forced_geom
= 1;
1370 if (s
[0] != 'i' || s
[1] != 'd' || s
[2] != 'e')
1373 * Look for bus speed option: "idebus="
1375 if (s
[3] == 'b' && s
[4] == 'u' && s
[5] == 's') {
1376 if (match_parm(&s
[6], NULL
, vals
, 1) != 1)
1378 if (vals
[0] >= 20 && vals
[0] <= 66) {
1379 idebus_parameter
= vals
[0];
1381 printk(" -- BAD BUS SPEED! Expected value from 20 to 66");
1385 * Look for interface options: "idex="
1387 if (s
[3] >= '0' && s
[3] <= max_hwif
) {
1389 * Be VERY CAREFUL changing this: note hardcoded indexes below
1390 * (-8, -9, -10) are reserved to ease the hardcoding.
1392 static const char *ide_words
[] = {
1393 "noprobe", "serialize", "minus3", "minus4",
1394 "reset", "minus6", "ata66", "minus8", "minus9",
1395 "minus10", "four", "qd65xx", "ht6560b", "cmd640_vlb",
1396 "dtc2278", "umc8672", "ali14xx", NULL
};
1401 hwif
= &ide_hwifs
[hw
];
1402 i
= match_parm(&s
[4], ide_words
, vals
, 3);
1405 * Cryptic check to ensure chipset not already set for hwif.
1406 * Note: we can't depend on hwif->chipset here.
1408 if ((i
>= -18 && i
<= -11) || (i
> 0 && i
<= 3)) {
1409 /* chipset already specified */
1410 if (is_chipset_set
[hw
])
1412 if (i
> -18 && i
<= -11) {
1413 /* these drivers are for "ide0=" only */
1416 /* chipset already specified for 2nd port */
1417 if (is_chipset_set
[hw
+1])
1420 is_chipset_set
[hw
] = 1;
1425 #ifdef CONFIG_BLK_DEV_ALI14XX
1426 case -17: /* "ali14xx" */
1430 #ifdef CONFIG_BLK_DEV_UMC8672
1431 case -16: /* "umc8672" */
1435 #ifdef CONFIG_BLK_DEV_DTC2278
1436 case -15: /* "dtc2278" */
1440 #ifdef CONFIG_BLK_DEV_CMD640
1441 case -14: /* "cmd640_vlb" */
1445 #ifdef CONFIG_BLK_DEV_HT6560B
1446 case -13: /* "ht6560b" */
1450 #ifdef CONFIG_BLK_DEV_QD65XX
1451 case -12: /* "qd65xx" */
1455 #ifdef CONFIG_BLK_DEV_4DRIVES
1456 case -11: /* "four" drives on one set of ports */
1458 ide_hwif_t
*mate
= &ide_hwifs
[hw
^1];
1459 mate
->drives
[0].select
.all
^= 0x20;
1460 mate
->drives
[1].select
.all
^= 0x20;
1461 hwif
->chipset
= mate
->chipset
= ide_4drives
;
1462 mate
->irq
= hwif
->irq
;
1463 memcpy(mate
->io_ports
, hwif
->io_ports
, sizeof(hwif
->io_ports
));
1466 hwif
->serialized
= mate
->serialized
= 1;
1467 goto obsolete_option
;
1469 #endif /* CONFIG_BLK_DEV_4DRIVES */
1470 case -10: /* minus10 */
1471 case -9: /* minus9 */
1472 case -8: /* minus8 */
1477 case -7: /* ata66 */
1478 #ifdef CONFIG_BLK_DEV_IDEPCI
1480 * Use ATA_CBL_PATA40_SHORT so drive side
1481 * cable detection is also overriden.
1483 hwif
->cbl
= ATA_CBL_PATA40_SHORT
;
1484 goto obsolete_option
;
1488 case -5: /* "reset" */
1490 goto obsolete_option
;
1491 case -2: /* "serialize" */
1492 hwif
->mate
= &ide_hwifs
[hw
^1];
1493 hwif
->mate
->mate
= hwif
;
1494 hwif
->serialized
= hwif
->mate
->serialized
= 1;
1495 goto obsolete_option
;
1497 case -1: /* "noprobe" */
1502 vals
[1] = vals
[0] + 0x206; /* default ctl */
1503 case 2: /* base,ctl */
1504 vals
[2] = 0; /* default irq = probe for it */
1505 case 3: /* base,ctl,irq */
1506 memset(&hwregs
, 0, sizeof(hwregs
));
1507 ide_init_hwif_ports(&hwregs
, vals
[0], vals
[1], &hwif
->irq
);
1508 memcpy(hwif
->io_ports
, hwregs
.io_ports
, sizeof(hwif
->io_ports
));
1509 hwif
->irq
= vals
[2];
1511 hwif
->chipset
= ide_forced
;
1512 goto obsolete_option
;
1514 case 0: goto bad_option
;
1516 printk(" -- SUPPORT NOT CONFIGURED IN THIS KERNEL\n");
1521 printk(" -- BAD OPTION\n");
1524 printk(" -- OBSOLETE OPTION, WILL BE REMOVED SOON!\n");
1527 printk("-- NOT SUPPORTED ON ide%d", hw
);
1533 EXPORT_SYMBOL(ide_lock
);
1535 static int ide_bus_match(struct device
*dev
, struct device_driver
*drv
)
1540 static char *media_string(ide_drive_t
*drive
)
1542 switch (drive
->media
) {
1558 static ssize_t
media_show(struct device
*dev
, struct device_attribute
*attr
, char *buf
)
1560 ide_drive_t
*drive
= to_ide_device(dev
);
1561 return sprintf(buf
, "%s\n", media_string(drive
));
1564 static ssize_t
drivename_show(struct device
*dev
, struct device_attribute
*attr
, char *buf
)
1566 ide_drive_t
*drive
= to_ide_device(dev
);
1567 return sprintf(buf
, "%s\n", drive
->name
);
1570 static ssize_t
modalias_show(struct device
*dev
, struct device_attribute
*attr
, char *buf
)
1572 ide_drive_t
*drive
= to_ide_device(dev
);
1573 return sprintf(buf
, "ide:m-%s\n", media_string(drive
));
1576 static ssize_t
model_show(struct device
*dev
, struct device_attribute
*attr
,
1579 ide_drive_t
*drive
= to_ide_device(dev
);
1580 return sprintf(buf
, "%s\n", drive
->id
->model
);
1583 static ssize_t
firmware_show(struct device
*dev
, struct device_attribute
*attr
,
1586 ide_drive_t
*drive
= to_ide_device(dev
);
1587 return sprintf(buf
, "%s\n", drive
->id
->fw_rev
);
1590 static ssize_t
serial_show(struct device
*dev
, struct device_attribute
*attr
,
1593 ide_drive_t
*drive
= to_ide_device(dev
);
1594 return sprintf(buf
, "%s\n", drive
->id
->serial_no
);
1597 static struct device_attribute ide_dev_attrs
[] = {
1599 __ATTR_RO(drivename
),
1600 __ATTR_RO(modalias
),
1602 __ATTR_RO(firmware
),
1603 __ATTR(serial
, 0400, serial_show
, NULL
),
1607 static int ide_uevent(struct device
*dev
, struct kobj_uevent_env
*env
)
1609 ide_drive_t
*drive
= to_ide_device(dev
);
1611 add_uevent_var(env
, "MEDIA=%s", media_string(drive
));
1612 add_uevent_var(env
, "DRIVENAME=%s", drive
->name
);
1613 add_uevent_var(env
, "MODALIAS=ide:m-%s", media_string(drive
));
1617 static int generic_ide_probe(struct device
*dev
)
1619 ide_drive_t
*drive
= to_ide_device(dev
);
1620 ide_driver_t
*drv
= to_ide_driver(dev
->driver
);
1622 return drv
->probe
? drv
->probe(drive
) : -ENODEV
;
1625 static int generic_ide_remove(struct device
*dev
)
1627 ide_drive_t
*drive
= to_ide_device(dev
);
1628 ide_driver_t
*drv
= to_ide_driver(dev
->driver
);
1636 static void generic_ide_shutdown(struct device
*dev
)
1638 ide_drive_t
*drive
= to_ide_device(dev
);
1639 ide_driver_t
*drv
= to_ide_driver(dev
->driver
);
1641 if (dev
->driver
&& drv
->shutdown
)
1642 drv
->shutdown(drive
);
1645 struct bus_type ide_bus_type
= {
1647 .match
= ide_bus_match
,
1648 .uevent
= ide_uevent
,
1649 .probe
= generic_ide_probe
,
1650 .remove
= generic_ide_remove
,
1651 .shutdown
= generic_ide_shutdown
,
1652 .dev_attrs
= ide_dev_attrs
,
1653 .suspend
= generic_ide_suspend
,
1654 .resume
= generic_ide_resume
,
1657 EXPORT_SYMBOL_GPL(ide_bus_type
);
1660 * This is gets invoked once during initialization, to set *everything* up
1662 static int __init
ide_init(void)
1666 printk(KERN_INFO
"Uniform Multi-Platform E-IDE driver " REVISION
"\n");
1667 system_bus_speed
= ide_system_bus_speed();
1669 ret
= bus_register(&ide_bus_type
);
1671 printk(KERN_WARNING
"IDE: bus_register error: %d\n", ret
);
1683 static char *options
= NULL
;
1684 module_param(options
, charp
, 0);
1685 MODULE_LICENSE("GPL");
1687 static void __init
parse_options (char *line
)
1691 if (line
== NULL
|| !*line
)
1693 while ((line
= next
) != NULL
) {
1694 if ((next
= strchr(line
,' ')) != NULL
)
1696 if (!ide_setup(line
))
1697 printk (KERN_INFO
"Unknown option '%s'\n", line
);
1701 int __init
init_module (void)
1703 parse_options(options
);
1707 void __exit
cleanup_module (void)
1711 for (index
= 0; index
< MAX_HWIFS
; ++index
)
1712 ide_unregister(index
);
1716 bus_unregister(&ide_bus_type
);
1721 __setup("", ide_setup
);
1723 module_init(ide_init
);